-
Notifications
You must be signed in to change notification settings - Fork 157
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
Trivial simplification not happening. #494
Trivial simplification not happening. #494
Comments
Same thing here. SymPy produces a very short expression, but Symbolics doesn't do obvious simplifications, especially with fractions. Codelet K = 3
@variables h[1:K] c[1:K] eps rho
q(h) = (h + eps) / (1 + eps * K)
ELBO = (
sum(q(h[k]) * c[k] for k in 1:K)
- sum(q(h[k]) * log(q(h[k])) for k in 1:K)
- sum(log(h[k]) for k in 1:K) / rho
)
hess = Symbolics.hessian(ELBO, collect(h), simplify=true)
end Output in Jupyter Lab:What's up with SymPy simplifies this nicely: Versions
|
Did you try calling |
@ChrisRackauckas, for my case, the Hessian becomes even more complicated. |
That's fun. |
It seems like |
How the original example now works: julia> using Symbolics
julia> @variables θ, n, x̄;
julia> expr = n*log(1/(2*θ^3)) - 1/θ * n * x̄;
julia> Symbolics.derivative(expr, θ)
(n*x̄) / (θ^2) - 6n*(θ^2)*(1 / (4(θ^6)))*((1 / (2(θ^3)))^-1)
julia> simplify(ans)
(n*x̄ - 3.0n*θ) / (θ^2) Thanks a lot for the quick and effective solution! |
I differentiated an expression. The result had a couple of glaring simplifications that Symbolics.jl does not seem to be able to see:
In this final expression, there are 5 powers of theta that can be cancelled. This is something I expect a
simplify
command to do.But the worst offender has to be
((1 / (2(θ^3)))^-1)
, which is equal to2(θ^3)
.I have no idea how to fix it, but as I consider it an issue, I though I should report it.
The text was updated successfully, but these errors were encountered: