ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 03 Dec 2021 15:46:29 +0100Some straightforward square root fractions are not simplifiedhttps://ask.sagemath.org/question/60054/some-straightforward-square-root-fractions-are-not-simplified/I'm a Sage beginner who's trying to apply it to a set of equations I'm working on. In that process, I came across an issue where SageMath 9.4 is not simplifying some very straightforward square root fractions in my expressions. Let me show you a minimal example:
x = var('x')
sqrt(1-x)/(1-x)
$$-\frac{\sqrt{-x + 1}}{x - 1}$$
What I was expecting to get, of course, is $1 / \sqrt{1 - x}$. Calling `simplify()` or `full_simplify()` on the expression doesn't make a difference; I still get the same thing out. I experimented with other square root fractions as well to see if this issue recurs:
sqrt(x)/x
$$1/\sqrt{x}$$
sqrt(1+x)/(1+x)
$$1/\sqrt{1+x}$$
sqrt(x-1)/(x-1)
$$1/\sqrt{x-1}$$
So in other words, Sage automatically simplifies all of the other expressions I tried in exactly the way that I would expect. To try out things a bit further, I tried to see if it helps to apply Sympy:
( sqrt(1-x)/(1-x) )._sympy_().simplify()
$$1/\sqrt{1-x}$$
That works. (The `simplify()` argument is essential here; otherwise, the fraction is not automatically simplified.)
So, is there some subtle finesse here that I'm not understanding, or did I stumble across a bug in Sage's simplification algorithms?Erlend M. ViggenFri, 03 Dec 2021 15:46:29 +0100https://ask.sagemath.org/question/60054/eliminating fractions and roots from equationshttps://ask.sagemath.org/question/9400/eliminating-fractions-and-roots-from-equations/I'm trying to solve the following equations for $a$ and $c$, where all numbers are real, $0\leq a < 1$ and $0 < c$:
[sqrt(abs((b - 1)*(a + 1)/sqrt(c^2 + abs(b - 1)^2) + a)^2 + abs((a +
1)*c/sqrt(c^2 + abs(b - 1)^2))^2) == a + 1, sqrt(abs(-(b + 1)*(a -
1)/sqrt(c^2 + abs(b + 1)^2) + a)^2 + abs(-(a - 1)*c/sqrt(c^2 + abs(b +
1)^2))^2) == -a + 1]
$$\sqrt{\left|\frac{(b-1)\cdot(a+1)}{\sqrt{c^2+|b-1|^2}+a}\right|^2+\left|\frac{(a+1)\cdot c}{\sqrt{c^2+|b-1|^2}}\right|^2}=a+1$$
$$\sqrt{\left|\frac{-(b+1)\cdot(a-1)}{\sqrt{c^2+|b+1|^2}+a}\right|^2 + \left|\frac{-(a-1)\cdot c}{\sqrt{c^2+|b+1|^2}}\right|^2}=-a+1$$
Now solve itself seems to take forever on this without coming up with a result. On the other hand, I as a human have a pretty good idea how I'd solve such beasts: square both sides to get rid of the outer square roots, then multiply both sides with the common denominator, then move the single remaining square root to one side and all the rest to the other side and square again.
I know that these steps *might* introduce additional solutions, which are valid solutions of the modified system but not of the original one. Nevertheless, I'd like to be able to get at them, probably with some indication how good they are.
I wrote a bit of code to massage my equations for me:
def massage(e):
e = e.simplify().simplify_radical().full_simplify()
e = e.power(2).simplify()
e = e.multiply_both_sides(e.lhs().denominator()).simplify()
e = e.subtract_from_both_sides(e.rhs()).simplify()
e = e.subtract_from_both_sides([
term for term in e.lhs().operands() if 'sqrt' in str(term)][0])
e = e.simplify().power(2).simplify()
e = e.subtract_from_both_sides(e.rhs()).expand()
e = e.simplify().simplify_radical().full_simplify()
return(e)
But this sequence is highly specific to the equations at hand. And the part about how to identify which operand contains the nested square root is plain ugly. **So what better methods are there to perform this kind of equation simplification?** Preferrably in a much more automated way.
*Just for your information:* If I modify my equations using the code above, I am able to get 9 solutions. I'm not sure whether I actually trust them, as I would have expected something else, but there might be something wrong with either my expectation or the way I obtained the euqations.MvGMon, 08 Oct 2012 12:43:35 +0200https://ask.sagemath.org/question/9400/