Ask Your Question

Multiplying an inequality by -1.

asked 2012-08-05 00:22:01 -0500

anonymous user


updated 2015-01-13 14:11:12 -0500

FrédéricC gravatar image

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


edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2012-08-05 00:53:20 -0500


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
edit flag offensive delete link 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?

nbits gravatar imagenbits ( 2012-08-05 09:12:16 -0500 )edit

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.

vdelecroix gravatar imagevdelecroix ( 2012-08-05 17:12:10 -0500 )edit

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

nbits gravatar imagenbits ( 2012-08-06 04:24:51 -0500 )edit

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

kcrisman gravatar imagekcrisman ( 2012-08-06 16:57:59 -0500 )edit

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)

nbits gravatar imagenbits ( 2012-08-16 17:48:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-08-05 00:22:01 -0500

Seen: 228 times

Last updated: Aug 05 '12