Ask Your Question

sqrt function not working properly

asked 2015-10-28 18:45:04 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I have the following code where I want to substitute a, b, c into s. Since s factors as a square, I want to get the square root of it :

p, t= var('p t')
c=(p*t^2-p^2*t)+(t^2+2*t*p+p^2)+t-p  #3 sides (a,b,c) in terms of theta and phi [equation (1.1)]

Unfortunately the answer I get is

sqrt((3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1)^2)

The sqrt and the square power does not cancel off which I want it to cancel. I tried using the code S.simplify_full() to simplify it hoping the sqrt and square power will cancel off but no luck. Is there any other specific code I can use for that.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-10-28 20:16:22 -0500

kcrisman gravatar image

The square root of a square is not the same as the number. (There is controversy over whether it is the absolute value of the number, or either plus or minus the number. Don't ask.)

But if you want to make it do that, use this:

sage: S.canonicalize_radical()
(3*p + 1)*t^2 - 2*p^2 - 2*(p - 1)*t + p + 1

which even does some factoring for you as a bonus.

edit flag offensive delete link more



@kcrisman,.. Thank you! this worked fine..

Sha gravatar imageSha ( 2015-10-28 20:48:10 -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

1 follower


Asked: 2015-10-28 18:45:04 -0500

Seen: 76 times

Last updated: Oct 28 '15