Ask Your Question

simplify trig, abs, and sqrt expression

asked 2012-06-05 06:32:00 -0500

calc314 gravatar image

updated 2012-06-05 08:31:31 -0500

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?

f(t) = (R*cos(t),R*sin(t),t)

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

answered 2012-06-06 13:03:34 -0500

Eviatar Bach gravatar image

updated 2012-06-06 13:21:25 -0500

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
            old = new
            new = new.simplify_full()
edit flag offensive delete link more


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 15:37:25 -0500 )edit

Thanks. I opened up a trac ticket for this:

Eviatar Bach gravatar imageEviatar Bach ( 2012-06-09 11:30:29 -0500 )edit

answered 2012-06-05 15:40:33 -0500

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


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 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.

Eviatar Bach gravatar imageEviatar Bach ( 2012-06-06 12:49:42 -0500 )edit

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

daniel.e2718 gravatar imagedaniel.e2718 ( 2012-06-07 10:37:38 -0500 )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


Asked: 2012-06-05 06:32:00 -0500

Seen: 2,515 times

Last updated: Jun 06 '12