Eric Hester
Eric Hester

Reputation: 51

Julia Symbolics can't simplify derivative expressions

I am using the Symbolics package in Julia, and it seems to not be simplifying derivatives of expressions.

E.g.:

@variables r
Dr = Differential(r)
simplify(expand_derivatives(Dr((2/r)^2)))

results in

(-4(2 / (r^2))) / r

If I instead create the derivative expression by hand, then simplify works great

simplify((-4*(2 / (r^2))) / r)

gives

-8 / (r^3)

as expected.

Why doesn't simplify work correctly on expressions created from differentiation?

Upvotes: 3

Views: 622

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42234

Use expand=true. Set up code:

using Symbolics
@variables r
Dr = Differential(r)

And now:

julia> simplify(expand_derivatives(Dr((2/r)^2)); expand=true)
-8 / (r^3)

Note that simplify((-4(2 / (r^2))) / r) worked because (-4(2 / (r^2))) / r was simplified before reaching that function:

julia> -4(2 / (r^2)) / r
-8 / (r^3)

Upvotes: 2

Related Questions