Ask Your Question

Sage is refusing to simplify an element of the symbolic ring to an integer

asked 2012-01-29 16:03:06 +0200

Zaubertrank gravatar image

updated 2012-01-30 10:56:12 +0200

DSM gravatar image

For example: How can I get sage to simplify ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) ) to -1? I've tried simplify() but it wont do it. Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-01-29 16:11:44 +0200

DSM gravatar image

updated 2012-01-29 17:11:07 +0200

Not every method -- i.e. a function which lives inside an object -- has a function form. What I mean is that you can write sqrt(2), because sqrt is a function, and you could also write 2.sqrt(), but not everything is paired up like that.

This holds for simplify too. There is a simplify function, but you can get much tighter control by calling the simplify methods. You can usually look inside an object by hitting TAB. For example:

sage: q = ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) ) 
sage: q.[HERE I HIT TAB]
q.N                         q.exp_simplify              q.leading_coeff             q.reduce_trig
q.Order                     q.expand                    q.leading_coefficient       q.rename
q.abs                       q.expand_log                q.left                      q.reset_name
q.add                       q.expand_rational           q.left_hand_side            q.rhs
q.add_to_both_sides         q.expand_trig               q.lgamma                    q.right
q.additive_order            q.factor                    q.lhs                       q.right_hand_side

In sage, lots of functionality lives inside objects like this. If you type

sage: q.simp[TAB]
q.simplify            q.simplify_factorial  q.simplify_log        q.simplify_rational   
q.simplify_exp        q.simplify_full       q.simplify_radical    q.simplify_trig

you'll see a bunch of possibilities. If you type

sage: q.simplify_radical?

you can see the docs for it (and two ?? show the code.)

All of that is a long-winded way to bring us here:

sage: q = ( sqrt(2) + sqrt(3) ) * ( sqrt(2) - sqrt(3) ) 
sage: q.simplify_radical()
sage: q.simplify_full()
edit flag offensive delete link more


oh man great answer, I didn't even know about all that functionality, thanks.

Zaubertrank gravatar imageZaubertrank ( 2012-01-29 16:49:47 +0200 )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-01-29 16:03:06 +0200

Seen: 1,508 times

Last updated: Jan 29 '12