mathics-core icon indicating copy to clipboard operation
mathics-core copied to clipboard

Unevaluated

Open mmatera opened this issue 3 years ago • 12 comments

In #58 I tried to fix this issue:

In WMA

In[1]:= F[a, Unevaluated[a]]
Out[1]:=F[a, Unevaluated[a]]

In Mathics

In[1]:= F[a, Unevaluated[a]]
Out[1]:=F[Unevaluated[a], Unevaluated[a]]

This happens because as now Symbols are singletons, the old mechanism of setting a property does not work anymore. In #58, I tried to fix this using a table. However, this does not work in general, if F has the attributes Orderless or Flat, because the order is lost.

mmatera avatar Jan 20 '22 22:01 mmatera

This feels more of the kind of confusion we've been having. A Lisp or WL Symbol is unique. In other words the name "a" is unique. What is meant by a in the expression Unevaluated[a] is a symbolic variable (or maybe "symbolic value") whose name is Lisp/WL Symbol a. Note that the a in Unevaluated[a] is no different than the a in a + 5. Both are expressions. The difference is that Unevaluated has a property that indicates for any variable just use its name.

Often people shorten "symbolic variable" to "symbol".

Possibly Mathics' Symbol class should be renamed to Variable or maybe SymbolicValue which consists of a name ("Symbol") and a binding value ("Definition"?) or a indication that the binding is "unbound" . And in the process, a new Symbol class should be added that matches Lisp/WL Symbol in that stricter narrower definition.

Unfortunately the name "Symbol" has been used to mean both the a Symbol name (but SymbolName is another WL function) as well as a symbolic variable/value. Variables can be unbound, or bound. Variables also have a scope attached to them.

rocky avatar Jan 21 '22 00:01 rocky

@rocky, in WL there are no "symbolic variables" (in the sense of something that has at some point a value), just Symbols, and lists of rules (organized as Definitions) associated with the symbols.

mmatera avatar Jan 21 '22 16:01 mmatera

https://www.ibm.com/docs/en/zos/2.3.0?topic=variables-what-is-symbolic-variable https://www.mathworks.com/matlabcentral/answers/320690-what-are-symbolic-variables

mmatera avatar Jan 21 '22 17:01 mmatera

@mmatera By "symbolic variable" I mean unbound variable.

rocky avatar Jan 21 '22 19:01 rocky

An unbound symbol is what Lisp calls a Symbol. And saying a Symbol is unbound implies that a Symbol can be bound. I suspect that this is the missing concept, variable binding, in Mathics.

rocky avatar Nov 21 '22 14:11 rocky

In WMA, bindings are given through the ownvalues associated with the symbol. Is it possible in LISP to set something like

In[1]:=a:=1/;x>0;
In[2]:=a:= 0;
In[3]:=a
In[4]:=0
Out[4]=0
In[5]:= x=1; a
Out[5]=1   

In that case, how this would work here using that concept?

mmatera avatar Nov 21 '22 17:11 mmatera

the getter function for variable "a" would be a lambda function that returns 1 if x is greater than 0.

Is this how #628 works?

rocky avatar Nov 21 '22 19:11 rocky

Nop. It was just to narrow the idea about what would be here a "bounded variable". #628 avoids to monkey patch a symbol by changing the expression Unevaluated[symb] by a wrapper surrounding symb, which produces the right behavior under sort and flat. I can add a more detailed explanation about how the wrapper works, or add more examples/tests.

Otherwise, just keep this here as a draft, like several other PRs, until we have a clearer picture, and then check against the tests a fix from another approach. The effort here was put in localizing the change just in the method we need to fix in order to get the right behaviour.

mmatera avatar Nov 21 '22 19:11 mmatera

Yes, let's keep this as a draft.

rocky avatar Nov 21 '22 19:11 rocky