Skip to content

Mathics DownValues[f]//FullForm is different from Mathematica's #1209

Description

@aravindh-krishnamoorthy

This is an implementation detail and I'm not sure if this must be fixed. In any case, Rubi seems to make assumptions on Mathematica's internal representation of DownValues of SetDelayed rules.

Description

In Mathematica, DownValues are SetDelayed[lhs, Condition[rhs, cond]] whereas in Mathics, they are SetDelayed[Condition[lhs, cond], rhs] as shown below.

In Mathematica,

In[1]:= f[A_, x_] := x /; x == 2;
In[2]:= DownValues[f] // FullForm
Out[2]//FullForm= {RuleDelayed[HoldPattern[f[Pattern[A,Blank[]],Pattern[x,Blank[]]]],Condition[x,Equal[x,2]]]}

On the other hand, in Mathics:

In[1]:= f[A_, x_] := x /; x == 2;
In[2]:= DownValues[f] // FullForm
Out[2]//FullForm= {RuleDelayed[HoldPattern[Condition[f[Pattern[A, Blank[]], Pattern[x, Blank[]]], Equal[x, 2]]], x]}

How to Reproduce

See above.

Output Given

Out[2]//FullForm= {RuleDelayed[HoldPattern[Condition[f[Pattern[A, Blank[]], Pattern[x, Blank[]]], Equal[x, 2]]], x]}

Expected behavior

The following, if compatibility with Mathematica in this is desired:

Out[2]//FullForm= {RuleDelayed[HoldPattern[f[Pattern[A,Blank[]],Pattern[x,Blank[]]]],Condition[x,Equal[x,2]]]}

Your Environment

Mathics 7.0.1dev0
on CPython 3.11.10 | packaged by conda-forge | (main, Oct 16 2024, 01:27:36) [GCC 13.3.0]
using SymPy 1.13.3, mpmath 1.3.0, numpy 2.1.3, cython Not installed

Workarounds

Conversion Mathics $\leftrightarrow$ Mathematica can be performed using these rules:

dvMathicsToMath = RuleDelayed[Verbatim[HoldPattern][Verbatim[Condition][lhs_,cond_]],rhs_] :> RuleDelayed[HoldPattern[lhs],Condition[rhs,cond]];
dvMathToMathics = RuleDelayed[Verbatim[HoldPattern][lhs_], Verbatim[Condition][rhs_,cond_]] :> RuleDelayed[HoldPattern[Condition[lhs,cond]],rhs];

Priority

Low. Non-blocking.

Additional context

N/A

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AssignmentSome problem or difference between the way Mathics3 assignment and WMA works

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions