Ask Your Question
0

issue with variable assumptions

asked 2015-06-16 19:49:11 +0100

this post is marked as community wiki

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

I am using sage to compute a variety of algebra, and often times, when calculating the squareroots of variables, sage gets the assumptions wrong. Here is a short example:

sage: r,M=var('r','M')

sage: assume(r>0,M>0,r>2*M)

sage: sqrt((2*M-r)^2)

2M-r

Clearly the last line is incorrect (should be r-2M), but I have no idea how to fix it. While this is a trivial example, I frequently work with equations that are many variables in length, where ensuring that the correct variables are positive is a requirement.

Edit: I found a partial solution, however it does not seem to work well with simplifying radicals. If there is an alternative to canonicalize_radical which takes assumptions into account, it would be helpful.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-06-16 20:31:07 +0100

eric_g gravatar image

Hi,

Apparently you are using an old version of Sage, because with Sage 6.7, one has

sage: r,M=var('r','M')
sage: assume(r>0,M>0,r>2*M)
sage: sqrt((2*M-r)^2)
sqrt((2*M - r)^2)

To simplify it, simply run

sage: s = sqrt((2*M-r)^2)
sage: s.simplify_real()
-2*M + r

which is correct, given the assumption.

edit flag offensive delete link more

Comments

Thank you! I was using canonicalize.radical(), which is what I assume was the issue.

zalba gravatar imagezalba ( 2015-06-17 16:45:56 +0100 )edit

However, this does not really simplify. Is there something like canonicalize_radicals() that takes assumptions into account? For example, I have the following expression, that won't simplify further sqrt(((M - r)mu + M)^2 + (mu^2 - 1)(2Mr - r^2))), but in Mathematica correctly simplifies to sqrt((mu*M+M-r)^2). canonical_radical finds the solution, but does not get the correct assumptions

zalba gravatar imagezalba ( 2015-06-17 18:15:00 +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

1 follower

Stats

Asked: 2015-06-16 19:49:11 +0100

Seen: 404 times

Last updated: Jun 17 '15