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, 24 Jul 2020 15:18:24 +0200can't solve inequality for independent variablehttps://ask.sagemath.org/question/52636/cant-solve-inequality-for-independent-variable/One of the frustrations I'm always having with Sage is how it tries to "solve" inequalities. For a random example:
sage: var('a b x')
sage: f = (a - b * x^2) / (x-1)
sage: solve(f > 0, x)
[[x < 1, b*x^2 - a > 0], [1 < x, -b*x^2 + a > 0]]
Which I knew already (since it's just the numerator).
Ok, so various signs and things matter, but the fact that it can't even tell me
x^2 > a/b
is frustrating. Is there a reason, or a way to convince Sage to actually "solve" these in some way?Thu, 23 Jul 2020 17:26:30 +0200https://ask.sagemath.org/question/52636/cant-solve-inequality-for-independent-variable/Answer by Emmanuel Charpentier for <p>One of the frustrations I'm always having with Sage is how it tries to "solve" inequalities. For a random example:</p>
<pre><code>sage: var('a b x')
sage: f = (a - b * x^2) / (x-1)
sage: solve(f > 0, x)
[[x < 1, b*x^2 - a > 0], [1 < x, -b*x^2 + a > 0]]
</code></pre>
<p>Which I knew already (since it's just the numerator).
Ok, so various signs and things matter, but the fact that it can't even tell me</p>
<pre><code>x^2 > a/b
</code></pre>
<p>is frustrating. Is there a reason, or a way to convince Sage to actually "solve" these in some way?</p>
https://ask.sagemath.org/question/52636/cant-solve-inequality-for-independent-variable/?answer=52639#post-id-52639Not directly. You may try :
sage: S1=solve_ineq([(a-b*x^2)/(x-1)>0],[x]);S1
[[x < 1, b*x^2 - a > 0], [1 < x, -b*x^2 + a > 0]]
But there, you're on your own:
sage: solve_ineq([(S1[0][1]+a)/b],[x])
[[b > 0, b*x^2 - a > 0], [-b > 0, -b*x^2 + a > 0]]
Sage may help you playing with that :
sage: S2=(S1[0][1]+a)/b; S2
x^2 > a/b
but
sage: solve_ineq([S2],[x])
[[b > 0, b*x^2 - a > 0], [-b > 0, -b*x^2 + a > 0]]
is pretty unhelpful.
Note that "the competition" isn't very helpful, either :
sage: mathematica("Reduce[Element[a, Reals] && Element[b, Reals] && Element[x, Reals] && (a-b*x^2)/(x-1)>0 ,x]")
(b < 0 && ((a < b && (Inequality[-Sqrt[a/b], Less, x, Less, 1] ||
x > Sqrt[a/b])) || (a == b && (Inequality[-Sqrt[a/b], Less, x, Less,
1] || x > 1)) || (Inequality[b, Less, a, LessEqual, 0] &&
(Inequality[-Sqrt[a/b], Less, x, Less, Sqrt[a/b]] || x > 1)) ||
(a > 0 && x > 1))) || (b == 0 && ((a < 0 && x < 1) ||
(a > 0 && x > 1))) || (b > 0 && ((a < 0 && x < 1) ||
(Inequality[0, LessEqual, a, Less, b] && (x < -Sqrt[a/b] ||
Inequality[Sqrt[a/b], Less, x, Less, 1])) ||
(a == b && x < -Sqrt[a/b]) || (a > b && (x < -Sqrt[a/b] ||
Inequality[1, Less, x, Less, Sqrt[a/b]]))))
Current progress in `sympy` may someday get us more helpful answere, but we're not here yet.
Another possibility is to use one of the linear prograpping packages available in Sage, bu I do not know them well enough to point you in the right direction...
HTH,Thu, 23 Jul 2020 23:15:21 +0200https://ask.sagemath.org/question/52636/cant-solve-inequality-for-independent-variable/?answer=52639#post-id-52639Comment by cduston for <p>Not directly. You may try :</p>
<pre><code>sage: S1=solve_ineq([(a-b*x^2)/(x-1)>0],[x]);S1
[[x < 1, b*x^2 - a > 0], [1 < x, -b*x^2 + a > 0]]
</code></pre>
<p>But there, you're on your own:</p>
<pre><code>sage: solve_ineq([(S1[0][1]+a)/b],[x])
[[b > 0, b*x^2 - a > 0], [-b > 0, -b*x^2 + a > 0]]
</code></pre>
<p>Sage may help you playing with that :</p>
<pre><code>sage: S2=(S1[0][1]+a)/b; S2
x^2 > a/b
</code></pre>
<p>but</p>
<pre><code>sage: solve_ineq([S2],[x])
[[b > 0, b*x^2 - a > 0], [-b > 0, -b*x^2 + a > 0]]
</code></pre>
<p>is pretty unhelpful.</p>
<p>Note that "the competition" isn't very helpful, either :</p>
<pre><code>sage: mathematica("Reduce[Element[a, Reals] && Element[b, Reals] && Element[x, Reals] && (a-b*x^2)/(x-1)>0 ,x]")
(b < 0 && ((a < b && (Inequality[-Sqrt[a/b], Less, x, Less, 1] ||
x > Sqrt[a/b])) || (a == b && (Inequality[-Sqrt[a/b], Less, x, Less,
1] || x > 1)) || (Inequality[b, Less, a, LessEqual, 0] &&
(Inequality[-Sqrt[a/b], Less, x, Less, Sqrt[a/b]] || x > 1)) ||
(a > 0 && x > 1))) || (b == 0 && ((a < 0 && x < 1) ||
(a > 0 && x > 1))) || (b > 0 && ((a < 0 && x < 1) ||
(Inequality[0, LessEqual, a, Less, b] && (x < -Sqrt[a/b] ||
Inequality[Sqrt[a/b], Less, x, Less, 1])) ||
(a == b && x < -Sqrt[a/b]) || (a > b && (x < -Sqrt[a/b] ||
Inequality[1, Less, x, Less, Sqrt[a/b]]))))
</code></pre>
<p>Current progress in <code>sympy</code> may someday get us more helpful answere, but we're not here yet.</p>
<p>Another possibility is to use one of the linear prograpping packages available in Sage, bu I do not know them well enough to point you in the right direction...</p>
<p>HTH,</p>
https://ask.sagemath.org/question/52636/cant-solve-inequality-for-independent-variable/?comment=52650#post-id-52650Unfortunately, it does help demonstrating that Mathematica does no better. I guess this is the answer ("Sage can't do what you want"), but I'll give a few days to see if anyone knows more. Thanks.Fri, 24 Jul 2020 15:18:24 +0200https://ask.sagemath.org/question/52636/cant-solve-inequality-for-independent-variable/?comment=52650#post-id-52650