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
Comparing two operations that contain log
sometimes leads to TypeError exception
#22020
Comments
The problem comes from Lines 661 to 669 in 5331d05
where all free symbols are replaced by zeros on line 666 and numerically evaluated,which results in |
This doesn't happen in Sympy 1.6.2 but does in 1.8. Is it not a regression then? |
To elaborate, in 1.6.2 instead of getting an error, the >>> import sympy
>>> from sympy.parsing.sympy_parser import parse_expr
>>> x = parse_expr("log((2*V/3-V)/C)/-(R+r)*C")
>>> x
C*log(-V/(3*C))/(-R - r)
>>> y = parse_expr("log((2*V/3-V)/C)/-(R+r)*2")
>>> y
2*log(-V/(3*C))/(-R - r)
>>> x.equals(y)
>>> print(x.equals(y))
None |
I'd say it is, yes. This code has not been touched in the last seven years, so probably something with the numerical evaluation has changed so that oo is returned rather than throwing a ZeroDivisionError. |
Added a fix in #22022. Hopefully it doesn't break anything else.
|
One could of course discuss how Lines 678 to 679 in c181470
equals as there should be no more free symbols in it (or rather one should probably have a look at how that case is dealt with in equals ).
|
The underlying problem is:
|
Better fix in #22024 |
This originally comes from PrairieLearn/PrairieLearn#4793, but it seems the problem is in sympy. We weren't able to narrow it down much further, other than to identify that this is specific to
log
(other functions like square root don't seem to have this problem).In essence, two expressions can lead to an exception when being compared if the
log
expression is multiplied by a variable instead of a fixed coefficient.The text was updated successfully, but these errors were encountered: