I am using the Symbolics package and having trouble figuring out how to simplify expressions. Note that \sqrt{3} and 3/\sqrt{3} are equal, but I can’t seem to get that. For example:
julia> using Symbolics
julia> a = sqrt(Num(3))
sqrt(3)
julia> a == 3/a
sqrt(3) == (3 / sqrt(3)) # this isn't helpful
julia> a - 3/a
sqrt(3) + -3 / sqrt(3)
julia> iszero(ans)
false # this is incorrect
Looks like a bug, isequal(a, 3 / a) should return true or at least realize it can’t do the computation. isequal((3/a)^2, 3) also fails, but isequal(simplify((3/a)^2), 3) succeeds.
For my project, I’ve swapped out Symbolics for PySym. So I’m set, but I would have thought Symbolics should be able to do this sort of simplification without modifications.
Yeah this is something Symbolics is not very good at. I think we can handle some of the trivial cases here (e.g. 3 / sqrt(3), 3x^2 * y / sqrt(3)) so I’ll set a bot on the problem. My only concern is if it will have a measurable runtime impact on / which is already pretty slow in SymbolicUtils. Benchmarks will tell.
SymJ.jl is pretty cool though, I’d definitely recommend giving it a shot. I’m also setting a bot on comparing some things I’m curious about, mainly design decisions that it has a different opinion on. If it gets registered, I think it might be a good backend for some of the polynomial expansion algorithms that Symbolics isn’t good at.
Also, the two expressions not comparing isequal is not really a bug. Symbolics’ expression canonicalization does leave a lot to be desired, but expressions only compare isequal if their tree structures (and corresponding types/shapes) are identical.