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

Need control of simplify #132

Closed
klaff opened this issue Mar 18, 2021 · 2 comments
Closed

Need control of simplify #132

klaff opened this issue Mar 18, 2021 · 2 comments

Comments

@klaff
Copy link

klaff commented Mar 18, 2021

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
Copy link
Member

shashi commented Mar 22, 2021

Related to JuliaSymbolics/SymbolicUtils.jl#231

@karlwessel
Copy link
Contributor

This has been fixed at some point, with the latest Symbolics.jl I get

julia> using Symbolics

julia> @variables a b c
3-element Vector{Num}:
 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))
1 / (1 / b + 1 / c + 1 / a)

julia> simplify(ex1)
(a*b*c) / (a*b + a*c + b*c)

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))*(b + c))

julia> simplify(ex2)
(a*b*c) / (a*b + a*c + b*c)

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

4 participants