-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Two similar Set[]
patterns matching differently in Mathics3 and wolframscript
#1233
Comments
Set[]
patterns matching differently in Mathics3 and wolframscript
To me there is this vague sense that when one rule has more restrictions than another, when it matches it should be take precedence over a more general rule. But is this what is going on? Or maybe the order of execution of the So I also wonder where this kind of thing is spelled out. Is this something that I should ask on Mathematica Stack Overflow for an explanation? |
See: A "left-hand-side" without a "pattern member" can be matched with "equals" and can always be tried before the rules which contain patterns (and the "equals rules" can therefore be stored in a tree or hash map internally). This is used in the From the website
So if complicated rules are used it's not clear to me how the rules are ordered (and also important "which rules are equivalent", so that an existing rule could be replaced by a new rule) . |
@axkr - thanks - this is very informative. In a language like Python or Java, there would be a lint program that would warn about such behavior and might solicit the user to make a change or facilitate making the change. I suppose Mathics3 could have a flag or mode where we provide something like this. For example, as I have done in Combinatorica, if one of the cases is a Block or a Module, one can always turn the Condition into an If statement inside the Module/BLock. |
In Mathics we just store all the patterns, sorted using a "pattern sort" criteria. Maybe what we need to change is some detail in how the sorting is done. |
Maybe, but note that the WMA reference cited also says that WMA sometimes uses the order in which Rules were given. So we have to be sensitive to this too. |
Description
These two Set assignments, when they exist together, seem to match differently in Mathics3 than in wolframscript:
How to Reproduce
In mathics:
In wolframscript:
What's going on, and why?
Expected behavior
The wolframscript behavior
Workarounds
In combinatoria V0.9 basically the two Set statements were combined into one Set statement with an explicit
If
test.Additional context
Noticed in getting Combinatorical V0.9's
Partitions[]
function working.The text was updated successfully, but these errors were encountered: