# Multiplying an inequality by -1. Anonymous I am new to sage and wondering why it doesn't reverse the terms (or the sign) of an inequality when multiplying by -1. E.g.:

sage: var('x y')
(x, y)
sage: f = x + 3 < y - 2
sage: f*2
2*x + 6 < 2*y - 4   # preserves truth-value of f
sage: f*(-1)
-x - 3 < -y + 2     # reverses truth-value of f


Why?

edit retag close merge delete

Sort by » oldest newest most voted

Hi,

Your question is not very well defined. The variables x and y may be anything (even if you think of them as integer or real number). They may be substituted with a complex number, a function, a matrix, ... anything. Preserving the truth of an expression involving undefined quantities is just impossible. Even the mathematical meaning of such an expression is not very well defined. Moreover, you don't want that multiplication preserves trueness as

sage: print bool(5), bool(0), bool(5*0)
True False False


You may have a look at the code for the multiplication of symbolic expression sage.symbolic.expression.Expression._mul_ (note that you can not access this method through the reference manual). For that method, the documentation says almost nothing except some examples which contain

# multiplying relational expressions
sage: ( (x+y) > x ) * ( x > y )
(x + y)*x > x*y

sage: ( (x+y) > x ) * x
(x + y)*x > x^2

sage: ( (x+y) > x ) * -1
-x - y > -x


The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?

sage: x,y,z
sage: (x + 3 < y - 2) * z

more

Are you saying that the ordered field of real numbers (represented internally by finite, rational approximations, of course) is not the default algebraic structure with respect to which sage interprets an unqualified (and unquantified, if applicable) expression or sentence in the absence of some sort of explicit interpretation of the symbols belonging to the formula and/or the domain of each variable? If so, how do I make those specifications in sage?

Yes, sage does not assume that x is a real number. It is possible to use "assume" as in assume(x, 'real') or assume(x > 0). But as far as I can see, it does not work that well. If you type assume(x, 'real'), then bool(x*x > 0) is evaluated to False.

Your antics are mostly just impudent and unhelpful, but it is possible that you have saved me some time.

I don't know if it's antics, but rather that some of these things are pretty tricky to define well.

What bothers me most is that the sage console acts just like the intelligent "notebook" it claims to be, with the "usual" ordered field axioms over the reals as the default structure. Contra vdelecroix, it does not treat user input as "expressions involving undefined quantities." If I enter "2.1 + 2" sage responds not with an error message regarding "undefined" terms, but with the "usual" answer "4.1." If I add two identities, or "multiply both sides" of relation by the same value or expression it gives the right answer, just as long as the relation is not an inequality and the value is not a negative number! My point is emphatically not that sage has made a schoolchild's error (continued below)