# simplify trig, abs, and sqrt expression

I'm computing the Frenet frame for a helix. Sage does not seem to want to simplify expressions like $\sqrt{|r^2 \sin(\theta)|^2+|r^2 \cos(\theta)^2|}$ without using simplify_full followed by simplify_trig. My code is below. What I've done is not elegant. Can anyone suggest a cleaner approach?

var('r,theta,x,y,t,R')
assume(r>0)
assume(R>0)
assume(t,'real')
f(t) = (R*cos(t),R*sin(t),t)
tangent=diff(f(t),t)
normal=diff(tangent,t)
binormal=tangent.cross_product(normal)
norm_of_tangent=tangent.norm().simplify_full().simplify_trig()
norm_of_normal=normal.norm().simplify_full().simplify_trig()
norm_of_binormal=binormal.norm().simplify_full().simplify_trig()
F=matrix([tangent/norm_of_tangent,normal/norm_of_normal,binormal/norm_of_binormal]).transpose()
F


The result is:

[-R*sin(t)/sqrt(R^2 + 1), -cos(t), sin(t)/sqrt(R^2 + 1)]
[R*cos(t)/sqrt(R^2 + 1), -sin(t), -cos(t)/sqrt(R^2 + 1)]
[1/sqrt(R^2 + 1), 0, (R^2*sin(t)^2 + R^2*cos(t)^2)/(sqrt(R^2 + 1)*R)]

edit retag close merge delete

Sort by » oldest newest most voted

Here's a function you can use which will keep simplifying until it can't any longer:

def simp(f):
old = f
new = old.simplify_full()
while 1:
if hash(new) == hash(old):
return old
else:
old = new
new = new.simplify_full()

more

This is a great idea. Seems like this would be a nice option to have built into Sage in a future version!

( 2012-06-06 15:37:25 -0500 )edit

Thanks. I opened up a trac ticket for this: http://trac.sagemath.org/sage_trac/ticket/13099

( 2012-06-09 11:30:29 -0500 )edit

I'm not sure what the question here is, exactly... but simply defining a function should be easy enough.

def simp(f):
return f.simplify_full().simplify_trig()


'simp' isn't used by sage, so that could be your "master simplify" function if you want.

more

I see now that I wasn't very clear. I just wanted to know whether this was the simplest approach to simplifying the square root, absolute value, and trig expression that I mentioned. Using the simplify command twice seemed a bit awkward, and I figured there had to be a slick way around that. Of course, I do realize that automated simplification is difficult, and any CAS might have difficulty doing something like this in one step. Thanks for looking at it!

( 2012-06-06 02:53:42 -0500 )edit

It occurs to me that it would be easy to add an option to simplify_full that would keep simplifying until the expression stopped changing (see my answer). Of course, this would make trivial simplifications take twice as long, but if it's just an option it wouldn't matter.

( 2012-06-06 12:49:42 -0500 )edit

Perhaps a parameter? simplify_full(expression, **loop=True**)

( 2012-06-07 10:37:38 -0500 )edit