Ask Your Question
0

simplify trig, abs, and sqrt expression

asked 2012-06-05 13:32:00 +0100

calc314 gravatar image

updated 2012-06-05 15:31:31 +0100

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-06-06 20:03:34 +0100

Eviatar Bach gravatar image

updated 2012-06-06 20:21:25 +0100

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()
edit flag offensive delete link more

Comments

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

calc314 gravatar imagecalc314 ( 2012-06-06 22:37:25 +0100 )edit

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

Eviatar Bach gravatar imageEviatar Bach ( 2012-06-09 18:30:29 +0100 )edit
0

answered 2012-06-05 22:40:33 +0100

daniel.e2718 gravatar image

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.

edit flag offensive delete link more

Comments

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!

calc314 gravatar imagecalc314 ( 2012-06-06 09:53:42 +0100 )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.

Eviatar Bach gravatar imageEviatar Bach ( 2012-06-06 19:49:42 +0100 )edit

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

daniel.e2718 gravatar imagedaniel.e2718 ( 2012-06-07 17:37:38 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-06-05 13:32:00 +0100

Seen: 6,321 times

Last updated: Jun 06 '12