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

mathematica_code gives wrong output with Max #15344

Closed
ajdunlap opened this Issue Oct 4, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@ajdunlap
Copy link
Contributor

ajdunlap commented Oct 4, 2018

If I run the code

x = symbols('x')
mathematica_code(Max(x,2))

then I would expect the output 'Max[x,2]' which is valid Mathematica code but instead I get 'Max(2, x)' which is not valid Mathematica code.

@jldohmann

This comment has been minimized.

Copy link

jldohmann commented Oct 5, 2018

Hi, I'm new (to the project and development in general, but I'm a long time Mathematica user) and have been looking into this problem.

The mathematica.py file goes thru a table of known functions (of which neither Mathematica Max or Min functions are in) that are specified with lowercase capitalization, so it might be that doing mathematica_code(Max(x,2)) is just yielding the unevaluated expression of mathematica_code. But there is a problem when I do mathematica_code(max(x,2)) I get an error occurring in the Relational class in core/relational.py

Still checking it out, though.

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Oct 5, 2018

max (lowercase m) is the Python builtin which tries to compare the items directly and give a result. Since x and 2 cannot be compared, you get an error. Max is the SymPy version that can return unevaluated results.

@ajdunlap

This comment has been minimized.

Copy link
Contributor

ajdunlap commented Oct 5, 2018

I tried to fix it by modifying the mathematica printer; see above pull request. I am also new to the codebase though.

skirpichev added a commit to skirpichev/diofant that referenced this issue Oct 6, 2018

Add regression test
Here used a different implementation of Min/Max printing,
coming from sympy/sympy#15345.

Closes sympy/sympy#15344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment