-
Notifications
You must be signed in to change notification settings - Fork 156
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
simplify
returns incorrect result
#1373
Comments
Ooof that's not good. @shashi do you have an idea for where to start looking for this? |
I did some digging and I think it has something to do with concrete (non-symbolic) prefactors in the numerator and denominator at the same time. The following examples should be equivalent, apart from global factors: using SymbolicUtils
@syms a x
> 1e-2x/(1e-2*a^3) - x/a^2 |> simplify
(0.01x - 0.01a*x) / (0.01(a^3))
> # we multiply the whole thing by 1e-7 and suddenly get 0
> 1e-9x/(1e-2*a^3) - 1e-7x/a^2 |> simplify
0
> # we do not get zero if we only have two concrete numbers in the expression
> x/(1e-2*a^3) - 1e2x/a^2 |> simplify
(x - a*x) / (0.01(a^3))
> 1e2x/(a^3) - 1e2x/a^2 |> simplify
(100.0x - 100.0a*x) / (a^3)
> # what about 4 concrete prefactors
> 1e-9x/(1e-2*a^3) - 1e-9x/(1e-2*a^2) |> simplify
0 I think this might at least narrow it down to the fraction cancellation logic, where concrete numbers are involved in both numerator and denominator in one fraction and at least one of them in the other fraction in an addition. |
I detected the problem initially on SymbolicUtils 1.5.1, so it seems it has existed for quite some time. |
Ok even more confident it is about fractions:
|
even more digging: it is also related to the order of magnitude somehow of the concrete prefactors and both terms having polynomial expressions in the denominator: > 1e-9/1e-2a^2 - 1e-6/a^3 |> simplify
0
> 1e-9/1e-2a^2 - 1e-5/a^3 |> simplify # also completely wrong but it somehow only discards the part that is 1e-7
-1.0000000000000001e-7 / (0.01(a^3))
> 1e-7/1e-2a^2 - 1e-7/a |> simplify # also wrong
1.0e-7 / (0.01(a^2))
> 1e-7/1e-2a^2 - 1e-5/a |> simplify # OK
(1.0e-7 - 1.0000000000000001e-7a) / (0.01(a^2))
> 1e-9/1e-2a^2 - 1e-5a^1/2 |> simplify # OK
-5.0e-6a + 1.0e-9 / (0.01(a^2))
> 1e-9/1e-2a^2 - 1e-7a^1/2 |> simplify # OK
-5.0e-8a + 1.0e-9 / (0.01(a^2))
> 1e-9a^2/1e-2 - 1e-5a^1/2 |> simplify # OK
-5.0e-6a + 1.0000000000000001e-7(a^2) |
I ran into the following issue on Symbolics#master:
even though the expression is clearly not zero. As an example, compare
A bit longer story: I encountered this problem when using
Symbolics.hessian(...; simplify=true)
. I goteven though the second derivative of
ex
with respect toph
should be non-zeroThe example above is actually the slightly simpler case
The text was updated successfully, but these errors were encountered: