-
-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Description
In WMA, rules of the form pat:>Condition[a,cond] are treated as Condition[pat, cond]:>a when applied to an expression. Mathics-core does not reproduce this behavior. Notice that this does not happen with ->.
Now, when Mathics execute a (Delayed) assignment instruction f[x_]:= g[x], the rule f[x_]:>g[x] is stored into the definition of f. On the other hand, for conditional assignments like f[x_]:=x/;x==2, in Mathics, we reformat the rule to obtain the right result. Now, if we fix the logic in handling these kind of rules, we can then replace the behavior of the assignment.
How to Reproduce
For example WMA, if we apply the rule f[x_]:>x/;x==2 to the expression f[3], the interpreter understands the same as we apply the rule f[x_]/;x==2:>x, i.e., check that f[3] matches with the pattern f[x_], and then if x satisfies the condition. If it does, replaces the expression by the replacement (in this case, 2).
In Mathics, the interpreter understands that f[x_]:>x/;x==2 matches with f[3], and then f[3]/. f[x_]/;x==2:>x results in 3/;3==2.
Your Environment
This is independent on the environment.
Workarounds
Put the Condition expression in the pattern instead of the replacement.
Priority
Low?
Additional context
This also affects how expressions are stored in Assignements (Set, SetDelayed, etc...)