ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 06 Jul 2018 04:11:19 -0500Assumptions and inequalitieshttp://ask.sagemath.org/question/42825/assumptions-and-inequalities/Hello all.
I have some expressions like **sums of ratios of real polynomials in a variable t**. Mathematically, by assuming t real in a specific interval, each such expression is either always positive, or always non-negative.
For Sage, this is **sometimes the case, sometimes not:** as you can see, the first one is correct, the second one not
<pre><code>
var('t')
expr1 = -1 + (t^2 - 1)/t^2 + 1/t^2
expr2 = (t^2 - 1)/(t^2 - 3)
with assuming(t > 0, t < 1/2):
print(bool(expr1 <= 0), bool(expr1 > 0))
print(bool(expr2 <= 0), bool(expr2 > 0))
</code></pre>
**Output:** (True, False) \n (False, False)
**Questions:** Why? How can I avoid this problem?
(An answer to the second question would be enough for me)
Thanks in advance :)Wed, 04 Jul 2018 06:32:58 -0500http://ask.sagemath.org/question/42825/assumptions-and-inequalities/Comment by rburing for <p>Hello all.</p>
<p>I have some expressions like <strong>sums of ratios of real polynomials in a variable t</strong>. Mathematically, by assuming t real in a specific interval, each such expression is either always positive, or always non-negative.</p>
<p>For Sage, this is <strong>sometimes the case, sometimes not:</strong> as you can see, the first one is correct, the second one not</p>
<pre><code>
var('t')
expr1 = -1 + (t^2 - 1)/t^2 + 1/t^2
expr2 = (t^2 - 1)/(t^2 - 3)
with assuming(t > 0, t < 1/2):
print(bool(expr1 <= 0), bool(expr1 > 0))
print(bool(expr2 <= 0), bool(expr2 > 0))
</code></pre>
<p><strong>Output:</strong> (True, False) \n (False, False)</p>
<p><strong>Questions:</strong> Why? How can I avoid this problem?</p>
<p>(An answer to the second question would be enough for me)</p>
<p>Thanks in advance :)</p>
http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?comment=42841#post-id-42841The [bug or "missing feature" in Maxima](https://sourceforge.net/p/maxima/bugs/2288/) (first reported in 2011) is indeed because of irrational roots. To work around your problem I would first treat the numerator and denominator separately (or multiply them, as suggested in the answer below, though this gives a polynomial with larger degree) so the problem is reduced to polynomials. Then it depends on what you want to do: to determine the sign in one interval, or to determine all the intervals on which the sign is constant (the latter can be used to answer the former).Fri, 06 Jul 2018 04:11:19 -0500http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?comment=42841#post-id-42841Comment by yeah for <p>Hello all.</p>
<p>I have some expressions like <strong>sums of ratios of real polynomials in a variable t</strong>. Mathematically, by assuming t real in a specific interval, each such expression is either always positive, or always non-negative.</p>
<p>For Sage, this is <strong>sometimes the case, sometimes not:</strong> as you can see, the first one is correct, the second one not</p>
<pre><code>
var('t')
expr1 = -1 + (t^2 - 1)/t^2 + 1/t^2
expr2 = (t^2 - 1)/(t^2 - 3)
with assuming(t > 0, t < 1/2):
print(bool(expr1 <= 0), bool(expr1 > 0))
print(bool(expr2 <= 0), bool(expr2 > 0))
</code></pre>
<p><strong>Output:</strong> (True, False) \n (False, False)</p>
<p><strong>Questions:</strong> Why? How can I avoid this problem?</p>
<p>(An answer to the second question would be enough for me)</p>
<p>Thanks in advance :)</p>
http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?comment=42832#post-id-42832Thanks. About my first question: Could the reason be that sqrt(3) is not rational? (I have no idea).
About my second question: I also tried without assumptions in other ways, like by using solve or solve_ineq. But I have similar problems.
Anyway, an alternative procedure that works (that is, an answer to the second question), for me would be considered as a full answer (and very appreciated).Thu, 05 Jul 2018 09:17:08 -0500http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?comment=42832#post-id-42832Comment by rburing for <p>Hello all.</p>
<p>I have some expressions like <strong>sums of ratios of real polynomials in a variable t</strong>. Mathematically, by assuming t real in a specific interval, each such expression is either always positive, or always non-negative.</p>
<p>For Sage, this is <strong>sometimes the case, sometimes not:</strong> as you can see, the first one is correct, the second one not</p>
<pre><code>
var('t')
expr1 = -1 + (t^2 - 1)/t^2 + 1/t^2
expr2 = (t^2 - 1)/(t^2 - 3)
with assuming(t > 0, t < 1/2):
print(bool(expr1 <= 0), bool(expr1 > 0))
print(bool(expr2 <= 0), bool(expr2 > 0))
</code></pre>
<p><strong>Output:</strong> (True, False) \n (False, False)</p>
<p><strong>Questions:</strong> Why? How can I avoid this problem?</p>
<p>(An answer to the second question would be enough for me)</p>
<p>Thanks in advance :)</p>
http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?comment=42831#post-id-42831It seems that Sage uses Maxima and Pynac for the assumptions framework. The same problem is present in Maxima 5.39.0:
(%i1) declare(x, real);
(%o1) done
(%i2) assume(x > 0, x < 1/2);
1
(%o2) [x > 0, x < -]
2
(%i3) is(x^2 - 1 < 0);
(%o3) true
(%i4) is(x^2 - 3 < 0);
(%o4) unknown
(%i5) is((x^2 - 1)/(x^2 - 3) > 0);
(%o5) unknown
I guess that Sage converts Maxima's `unknown` to `False`. I tried to track down what Pynac does, but found the code hard to follow.Thu, 05 Jul 2018 07:53:47 -0500http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?comment=42831#post-id-42831Answer by tmonteil for <p>Hello all.</p>
<p>I have some expressions like <strong>sums of ratios of real polynomials in a variable t</strong>. Mathematically, by assuming t real in a specific interval, each such expression is either always positive, or always non-negative.</p>
<p>For Sage, this is <strong>sometimes the case, sometimes not:</strong> as you can see, the first one is correct, the second one not</p>
<pre><code>
var('t')
expr1 = -1 + (t^2 - 1)/t^2 + 1/t^2
expr2 = (t^2 - 1)/(t^2 - 3)
with assuming(t > 0, t < 1/2):
print(bool(expr1 <= 0), bool(expr1 > 0))
print(bool(expr2 <= 0), bool(expr2 > 0))
</code></pre>
<p><strong>Output:</strong> (True, False) \n (False, False)</p>
<p><strong>Questions:</strong> Why? How can I avoid this problem?</p>
<p>(An answer to the second question would be enough for me)</p>
<p>Thanks in advance :)</p>
http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?answer=42834#post-id-42834One possible approach could be to use ``qepcad`` optional package. You can install it by typing from a terminal:
sage -i qepcad
Then, you can do something:
sage: var('t')
t
sage: qf = qepcad_formula
sage: f = qf.forall(t,qf.implies(qf.and_([t>0, t<1/2]), expr2 > 0))
sage: f
(A t)[[t > 0 /\ t < 1/2] ==> (t^2 - 1)/(t^2 - 3) > 0]
sage: qepcad(f)
But apparently, it takes too much time (unless qepcad is only able do deal with polynomials but the interface does not catch the error, to be investigated). So, if only the sign matters, you can notice that the sign of a/b is the same than the one of a*b, so, up to taking care of the possible cases when b=0, you can do:
sage: f = qf.forall(t,qf.implies(qf.and_([t>0, t<1/2]), expr2.denominator()*expr2.numerator() > 0))
sage: qepcad(f)
TRUE
Which is correct.
If you want to get a Python boolean, just do:
sage: qepcad(f) == 'TRUE'
True
sage: f = qf.forall(t,qf.implies(qf.and_([t>0, t<1/2]), expr2.denominator()*expr2.numerator() <= 0))
sage: qepcad(f) == 'TRUE'
FalseThu, 05 Jul 2018 16:51:33 -0500http://ask.sagemath.org/question/42825/assumptions-and-inequalities/?answer=42834#post-id-42834