JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.35k stars 151 forks source link

Need control of simplify #132

Open klaff opened 3 years ago

klaff commented 3 years ago
julia> @variables a b c
(a, b, c)

julia> par(x,y) = 1/(1/x+1/y)
par (generic function with 1 method)

julia> ex1 = par(a, par(b,c))
(a^-1 + ((b^-1 + c^-1)^-1)^-1)^-1

julia> simplify(ex1)
(a^-1 + b^-1 + c^-1)^-1

julia> par2(x,y) = x*y/(x+y)
par2 (generic function with 1 method)

julia> ex2 = par2(a, par2(b, c))
a*b*c*((a + b*c*((b + c)^-1))^-1)*((b + c)^-1)

julia> simplify(ex2)
a*b*c*((a + b*c*((b + c)^-1))^-1)*((b + c)^-1)

ex1 and ex2 can be simplified to the same expression but do not.

Also, it seems that a faster version might be ex3 = a*b*c/(a*b+a*c+b*c), so it would be nice to be able to control or direct the simplification process.

This exploration was done in consideration of more complicated expressions representing circuit impedances by phasor representation, in which for example the impedance of an inductor would be represented by im*2π*f*L. The par and par2 are two forms of the same formula for computing impedances in parallel.

┆Issue is synchronized with this Trello card by Unito

shashi commented 3 years ago

Related to https://github.com/JuliaSymbolics/SymbolicUtils.jl/pull/231