Simplify with Symbolics.jl

Hi,

How can I simplify this simple expression?

julia> using Symbolics

julia> @variables x, y, z
3-element Vector{Num}:
 x
 y
 z

julia> simplify( cos(x)^2*cos(y)^2*cos(z)^2 + cos(x)^2*sin(y)^2*cos(z)^2 )
(cos(x)^2)*(cos(y)^2)*(cos(z)^2) + (cos(x)^2)*(sin(y)^2)*(cos(z)^2)

I would like to get the expected answer (cos(x)^2)*(cos(z)^2).

This happens only when cos(y)^2 + sin(y)^2 is not the first or the last part of its homogeneous factors.
In other words this happens when the (inverse) distributive law is needed on both left and right sides.

For example, when cos^2 + sin^2 is in the first or last part of the terms, simplify works well (below example)

julia> simplify( cos(x)^2*cos(y)^2*cos(z)^2 + sin(x)^2*cos(y)^2*cos(z)^2 )
(cos(y)^2)*(cos(z)^2)

julia> simplify( cos(x)^2*cos(y)^2*cos(z)^2 + cos(x)^2*sin(y)^2*cos(z)^2 )
(cos(x)^2)*(cos(y)^2)*(cos(z)^2) + (cos(x)^2)*(sin(y)^2)*(cos(z)^2)

julia> simplify( cos(x)^2*cos(y)^2*cos(z)^2 + cos(x)^2*cos(y)^2*sin(z)^2 )
(cos(x)^2)*(cos(y)^2)

Is there a variant (or keyword or anything) of simplify that can solve this problem?

1 Like

Open an issue. Seems like it’s just missing something.

1 Like

I will. Thanks, Chris!