Ask Your Question
2

Assumptions and inequalities

asked 2018-07-04 13:32:58 +0200

yeah gravatar image

updated 2018-07-05 18:19:25 +0200

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


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))

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 :)

edit retag flag offensive close merge delete

Comments

It 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.

rburing gravatar imagerburing ( 2018-07-05 14:53:47 +0200 )edit
1

Thanks. 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).

yeah gravatar imageyeah ( 2018-07-05 16:17:08 +0200 )edit

The bug or "missing feature" in Maxima (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).

rburing gravatar imagerburing ( 2018-07-06 11:11:19 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-07-05 23:51:33 +0200

tmonteil gravatar image

updated 2018-07-06 00:00:27 +0200

One 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'
False
edit flag offensive delete link more

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: 2018-07-04 13:32:58 +0200

Seen: 473 times

Last updated: Jul 06 '18