Symbolics.jl icon indicating copy to clipboard operation
Symbolics.jl copied to clipboard

How to expand an expression?

Open GiggleLiu opened this issue 6 years ago • 1 comments

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.

GiggleLiu avatar Mar 20 '19 14:03 GiggleLiu

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

MasonProtter avatar Mar 20 '19 15:03 MasonProtter