MasonProtter / Symbolics.jl

A symbolic math library written in Julia modelled off scmutils
MIT License
108 stars 15 forks source link

How to expand an expression? #17

Open GiggleLiu opened 5 years ago

GiggleLiu commented 5 years ago

Great tool!

I wonder how to expand the following expression as 4 * x + 2 * y?

julia> @sym x y;
julia> ex = x+x+2(y+x)
(2 * x + y) * 2

Also, is it possible to simplify the following expression as max(x, y)?

julia> max(max(x, y),x)
max(max(x, y), x)

Or where can I start to add support to these expression simplification rules? An minimum example would be enough, thanks.

MasonProtter commented 5 years ago

Hello, thanks for taking an interest!

Your first question would probably require a function like the Expand function in Mathematica which expands all products and positive integer exponents. We could call it expand or something.

Your second question requires a new simplification rule for max. If you want to try your hand at this, I'd stick the rule in the file simplification.jl and then you just have to add it somewhere in this list here: https://github.com/MasonProtter/Symbolics.jl/blob/master/src/Simplification.jl#L88