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

simplify returns incorrect result #1373

Open
devmotion opened this issue Nov 22, 2024 · 1 comment
Open

simplify returns incorrect result #1373

devmotion opened this issue Nov 22, 2024 · 1 comment

Comments

@devmotion
Copy link
Contributor

I ran into the following issue on Symbolics#master:

julia> using Symbolics

julia> ex = (1.1540262529490819e-7(5.011872336272725e-8 + a)*(10^(-x))) / (2.511886431509582e-15((a + 10^(-x))^2)) + (-2.302585092994046(5.011872336272725e-8 + a)*(10^(-x))) / (5.011872336272725e-8(a + 10^(-x)));

julia> Symbolics.simplify(ex)
0

even though the expression is clearly not zero. As an example, compare

julia> Symbolics.substitute(ex, Dict(x => 1.0, a => 1.0))
-379691.03250567336

A bit longer story: I encountered this problem when using Symbolics.hessian(...; simplify=true). I got

julia> using Symbolics

julia> @variables t Ka ktr ph(t) tr1(t);

julia> D = Differential(t);

julia> ex = 10^(-ph)/(10^(-ph) + Ka) / (10^(-7.3) / (10^(-7.3) + Ka)) - ktr * tr1;

julia> Symbolics.hessian(ex, [ph, tr1]; simplify=true)
2×2 Matrix{Num}:
 0  0
 0  0

even though the second derivative of ex with respect to ph should be non-zero

julia> Symbolics.hessian(ex, [ph, tr1])
2×2 Matrix{Num}:
 (-2.65724e-7(5.01187e-8 + Ka)*(10^(-2ph(t)))) / (2.51189e-15((Ka + 10^(-ph(t)))^2)) + (5.3019(5.01187e-8 + Ka)*(10^(-ph(t)))) / (5.01187e-8(Ka + 10^(-ph(t)))) + 1.15403e-7(10^(-ph(t)))*((-2.30259(5.01187e-8 + Ka)*(10^(-ph(t)))) / (2.51189e-15((Ka + 10^(-ph(t)))^2))) + 1.15403e-7((-2.30259(5.01187e-8 + Ka)*(10^(-ph(t)))) / (2.51189e-15((Ka + 10^(-ph(t)))^2)) + 1.15677e-14(Ka + 10^(-ph(t)))*(10^(-ph(t)))*(((5.01187e-8 + Ka)*(10^(-ph(t)))) / (6.30957e-30((Ka + 10^(-ph(t)))^4))))*(10^(-ph(t)))    0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              0     0

The example above is actually the slightly simpler case

julia> Symbolics.derivative(ex, ph; simplify=true)
0

julia> Symbolics.derivative(ex, ph)
(-2.302585092994046(5.011872336272725e-8 + Ka)*(10^(-ph(t)))) / (5.011872336272725e-8(Ka + 10^(-ph(t)))) + 1.1540262529490819e-7(((5.011872336272725e-8 + Ka)*(10^(-ph(t)))) / (2.511886431509582e-15((Ka + 10^(-ph(t)))^2)))*(10^(-ph(t)))
@ChrisRackauckas
Copy link
Member

Ooof that's not good. @shashi do you have an idea for where to start looking for this?

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

No branches or pull requests

2 participants