# Trig simplification of implicit functions fails

I'd like to use Sage to verify my solutions to Lagrangian equations of motion for a double pendulum. However, Sage seems unable to handle some basic substitutions needed to make sense of this relatively simple problem.

For example, this all works fine:

var('z')
r = cos(z)**2 + sin(z)**2
assert r.simplify_trig() == 1


However, when z is a function of time, things break down entirely:

var('x,y,t,z')
θ1 = function('θ1')(t)
θ2 = function('θ2')(t)
K = sin(θ1)**2 + cos(θ1)**2
assert K.simplify_trig() == 1


Specifically, K.simplify_trig() throws:

TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

I would also expect

assert K.substitute_function(θ1, z) == cos(z)^2 + sin(z)^2


However K.substitute_function(θ1, z) just gives me K unchanged.

Seems related, but I'm still stumped: ask.sagemath.org/question/7856/lagranian-mechanics/

edit retag close merge delete

Sort by » oldest newest most voted

As for your first question, this is due to the fact that simplification is done by maxima and maxima is not able to deal with unicode symbolic variables. A suggestion is to reserve unicode characters to the Python names and keep ascii strings for symbols:

sage: θ1 = function('theta_1')(t)


Then maxima will be able to handle it correctly, and if you still want to display them with greek letters, you can to

%display latex


so that when you type:

sage: θ1


the output will be $\theta_1(t)$

As fot the second question, you can do:

sage: K.substitute({θ1:z})
cos(z)^2 + sin(z)^2

sage: K = K.substitute({θ1:z})
sage: K
cos(z)^2 + sin(z)^2
sage: K.full_simplify()
1

more