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.Thu, 23 Aug 2012 13:35:29 +0200Multiplying an inequality by -1.https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/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?Sun, 05 Aug 2012 07:22:01 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/Answer by vdelecroix for <p>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.:</p>
<pre><code>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
</code></pre>
<p>Why?</p>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?answer=13898#post-id-13898Hi,
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) * zSun, 05 Aug 2012 07:53:20 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?answer=13898#post-id-13898Comment by nbits for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19218#post-id-19218(to kcristman) If there is a way to "define" things so that sage "properly interprets," e.g., can verify, expand, reduce, simplify, transform in various useful (and preferably user configurable) ways, algebraic formulae (expressions and sentences typically containing a combination of free and bound variables ranging over sets), with respect to a user specified algebraic structure, then please enlighten me. I can write python/C code if necessary but my python is a bit stale. Ultimately, what I'm looking for is generic paperless mathematics authoring at arbitrary levels of sophistication, a scriptable "smart editor" if you will. I am not looking for a run-of-the-mill assemblage of canned solutions or a prover.Fri, 17 Aug 2012 01:53:45 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19218#post-id-19218Comment by kcrisman for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19266#post-id-19266I don't know if it's antics, but rather that some of these things are pretty tricky to define well.Mon, 06 Aug 2012 23:57:59 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19266#post-id-19266Comment by nbits for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19219#post-id-19219but that its peculiar brand of sparsely inconsistent pseudo-mathematics is either (1) insidious or (2) a rather disappointing veneer over the Python interactive console.Fri, 17 Aug 2012 00:52:12 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19219#post-id-19219Comment by kcrisman for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19189#post-id-19189It's conceivable that http://lurch.sourceforge.net is what you are looking for. With respect to the formulae, Maxima itself is far more configurable (too much so for many of our users, including quite sophisticated ones) so perhaps that will be more of a pure option for you. You can access it inside of Sage, or with `sage -maxima`.Thu, 23 Aug 2012 13:32:53 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19189#post-id-19189Comment by nbits for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19268#post-id-19268Your antics are mostly just impudent and unhelpful, but it is possible that you have saved me some time.Mon, 06 Aug 2012 11:24:51 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19268#post-id-19268Comment by kcrisman for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19188#post-id-19188As to the "contra vdelecroix", I don't think everything is such an expression, but all "symbolic expressions" are. Certainly 2.1+2 is coerced into the field that makes the most sense there - since every integer is a (53-digit precision) real as well, we can do that. If you use ">", then I guess you've automatically assumed there is an order implicit in the field... anyway, this might be a better discussion to have on one of the Sage email lists, since it's difficult to have a sustained argument - not to mention actual interaction - in comments :) Hope that at least something has helped here!Thu, 23 Aug 2012 13:35:29 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19188#post-id-19188Comment by nbits for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19220#post-id-19220What 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)Fri, 17 Aug 2012 00:48:30 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19220#post-id-19220Comment by vdelecroix for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19274#post-id-19274Yes, 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.Mon, 06 Aug 2012 00:12:10 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19274#post-id-19274Comment by nbits for <p>Hi,</p>
<p>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</p>
<pre><code>sage: print bool(5), bool(0), bool(5*0)
True False False
</code></pre>
<p>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</p>
<pre><code># 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
</code></pre>
<p>The second line is particularly interesting with respect to your question. What would you like as a result of the following operation ?</p>
<pre><code>sage: x,y,z
sage: (x + 3 < y - 2) * z
</code></pre>
https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19275#post-id-19275Are 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?Sun, 05 Aug 2012 16:12:16 +0200https://ask.sagemath.org/question/9207/multiplying-an-inequality-by-1/?comment=19275#post-id-19275