Playing with Symbolics
like so:
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)
julia>
ex1
and ex2
are equivalent expressions but don’t simplify to the same expression. Are there tools coming to let one guide what simplify
is doing?
P.S. I did build_function
s from both of these and the function derived from ex2
computes slightly faster, although not as fast as if I make one from a manually created ex3
as follows:
julia> ex3 = a*b*c/(a*b+a*c+b*c)
a*b*c*((a*b + a*c + b*c)^-1)