Skip to content
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

Key Invariance not ensured #16763

Open
napyonsen opened this issue May 1, 2019 · 2 comments
Open

Key Invariance not ensured #16763

napyonsen opened this issue May 1, 2019 · 2 comments
Labels

Comments

@napyonsen
Copy link

"Every well-formed SymPy expression must either have empty args or satisfy expr == expr.func(*expr.args)."
However,
following returns false.
expr = r"(90-1)*2"
sym = latex2sympy(expr)
sym2 = sym.func(*sym.args)
print sym == sym2 // false

What is well-formed anyway?

@oscarbenjamin
Copy link
Contributor

oscarbenjamin commented May 6, 2019

What exactly is sym in the above?

I don't know what version of SymPy you are using but I don't have a latex2sympy function on master. I guess that it is returning something unevaluated like

In [5]: e = Mul(Add(90, -1, evaluate=False), 2, evaluate=False)                                                                   

In [6]: e                                                                                                                         
Out[6]: 2(-1 + 90)

In [7]: e.doit()                                                                                                                  
Out[7]: 178

In [8]: e.func(*e.args)                                                                                                           
Out[8]: -2 + 180

In [9]: e.func(*e.args, evaluate=False)                                                                                           
Out[9]: 2(-1 + 90)

The invariant that x==x.func(*x.args) does depend on whether or not x was created with evaluate=True or evaluate=False.

@napyonsen
Copy link
Author

napyonsen commented May 7, 2019

latex2sympy is a third party function which is adopted into sympy in recent versions as "parse_latex". It converts latex expression to sympy.
Your point is correct. Exact identiity should be "x==x.func(*x.args, evaluate=False)".
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants