# Multiplying inequality by negative number

20 views

### ma...@mendelu.cz

Dec 10, 2009, 3:37:10 AM12/10/09
to sage-devel
Dear sage-devel

this is doctested in relation.py

sage: f = x + 3 < y - 2
sage: f*(-1)
-x - 3 < -y + 2

Is this really intended behavior? Shouldnt the answer be the
following?

sage: f*(-1)
-x - 3 > -y + 2

But what about f*(a) or f*(x-2)? Should Sage return this?
(-x-3)*(x-2)<(2-y)*(x-2)

Or raise a warning that the inequalities are not equivalent. Or refuse
computation if the sign of the expression which multiplies inequality
cannot be determined? Or simply we assume that the user is not high
school student and she/he knows what she/he is doing?

Is there any opinion to this?

Many thanks

Robert Marik

### Mike Hansen

Dec 10, 2009, 3:45:31 AM12/10/09
On Thu, Dec 10, 2009 at 3:37 PM, ma...@mendelu.cz <ma...@mendelu.cz> wrote:
> sage: f = x + 3 < y - 2
> sage: f*(-1)
> -x - 3 < -y + 2
>
> Is this really intended behavior? Shouldnt the answer be the
> following?
>
> sage: f*(-1)
> -x - 3 > -y + 2
>
> But what about f*(a)  or f*(x-2)? Should Sage return this?
> (-x-3)*(x-2)<(2-y)*(x-2)

I believe that this was indeed the intended behavior for the reasons above.

> Or raise a warning that the inequalities are not equivalent. Or refuse
> computation if the sign of the expression which multiplies inequality
> cannot be determined? Or simply we assume that the user is not high
> school student and she/he knows what she/he is doing?

I think this is the case.

--Mike

### William Stein

Dec 10, 2009, 12:54:36 PM12/10/09
to sage-devel

On Thu, Dec 10, 2009 at 12:45 AM, Mike Hansen <mha...@gmail.com> wrote:
> On Thu, Dec 10, 2009 at 3:37 PM, ma...@mendelu.cz <ma...@mendelu.cz> wrote:
>> sage: f = x + 3 < y - 2
>> sage: f*(-1)
>> -x - 3 < -y + 2
>>
>> Is this really intended behavior? Shouldnt the answer be the
>> following?
>>
>> sage: f*(-1)
>> -x - 3 > -y + 2
>>
>> But what about f*(a)  or f*(x-2)? Should Sage return this?
>> (-x-3)*(x-2)<(2-y)*(x-2)
>
> I believe that this was indeed the intended behavior for the reasons above.

Hmm.  I remember when I first implemented inequalities that f*(-1) *did* reverse the sign of the inequality, like Maple does:

> f := x+3 < y-2;
f := x < y - 5
> f*(-1);
-y + 5 < -x

I guess this was changed subsequently.

Mathematica does something weird and formal:

In[1]:= f := x+3 < y-2;
In[3]:= f*(-1)
Out[3]= -(3 + x < -2 + y)

-----

At this point, I'm just throwing some remarks out, not saying that we should do anything in particular.

I'm curious -- who multiplies equalities by a scalar *except* high school students or college students taking entry level college algebra classes?

William

### kcrisman

Dec 10, 2009, 1:32:24 PM12/10/09
to sage-devel
>
> At this point, I'm just throwing some remarks out, not saying that we should
> do anything in particular.
>
> I'm curious -- who multiplies equalities by a scalar *except* high school
> students or college students taking entry level college algebra classes?

Or those in calculus or LP classes who need them to find solution sets
to various things. But yes.

- kcrisman

### William Stein

Dec 10, 2009, 2:49:21 PM12/10/09
to sage-devel
So we should make the semantics be aimed at such people.

William

### kcrisman

Dec 10, 2009, 4:33:23 PM12/10/09
to sage-devel

On Dec 10, 2:49 pm, William Stein <wst...@gmail.com> wrote:
> On Thu, Dec 10, 2009 at 10:32 AM, kcrisman <kcris...@gmail.com> wrote:
>
> >> At this point, I'm just throwing some remarks out, not saying that we should
> >> do anything in particular.
>
> >> I'm curious -- who multiplies equalities by a scalar *except* high school
> >> students or college students taking entry level college algebra classes?
>
> > Or those in calculus or LP classes who need them to find solution sets
> > to various things.   But yes.
>
> So we should make the semantics be aimed at such people.

But, although
x<y
-x>-y
what would we do for
a*x??a*y
situation? I think this was alluded to above - there isn't an answer,
per se. That doesn't mean we couldn't check for the 'right' answer if
'a=something numeric' or even if 'a is assumed to be pos. or neg. in
assumptions()'. But it's not clear what to do in that case, and we
don't want to cause things to happen that are simply wrong. What does
Maple do in the symbolic case (the Mma answer, though cryptic, at
least is consistent)?

- kcrisman

### William Stein

Dec 10, 2009, 5:15:53 PM12/10/09
to sage-devel
Here is what Maple does:

flat:release_notes wstein\$ maple
|\^/| Maple 13 (APPLE UNIVERSAL OSX)
._|\| |/|_. Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2009
<____ ____> Waterloo Maple Inc.
| Type ? for help.
> f := x < y;
f := x < y

> f*(-3)
> ;
-3 y < -3 x

> f*z;
*(x < y, z)

> f*a;
*(x < y, a)

### Simon King

Dec 10, 2009, 5:37:50 PM12/10/09
to sage-devel
Hi!

On 10 Dez., 23:15, William Stein <wst...@gmail.com> wrote:
[...]
>                                   f := x < y
>
> > f*(-3)
> > ;
>
>                                   -3 y < -3 x
>
> > f*z;
>
>                                   *(x < y, z)
>
> > f*a;
>
>                                   *(x < y, a)

What else could it be? Maple's answer seems quite reasonable to me.

Cheers,
Simon

### VictorMiller

Dec 10, 2009, 5:41:05 PM12/10/09
to sage-devel
To do this correctly in full generality one needs to get into
"cyclindrical algebraic decomposition" -- a set in R^n has a
cylindrical algebraic
decomposition if it is written as a finite union of sets of the form
{ x : f(x) > 0 } where f is a polynomial. There is an algorithm due
to Tarski
for creating such sets.

Victor

On Dec 10, 5:15 pm, William Stein <wst...@gmail.com> wrote:

### Jason Grout

Dec 10, 2009, 5:56:17 PM12/10/09
VictorMiller wrote:
> To do this correctly in full generality one needs to get into
> "cyclindrical algebraic decomposition" -- a set in R^n has a
> cylindrical algebraic
> decomposition if it is written as a finite union of sets of the form
> { x : f(x) > 0 } where f is a polynomial. There is an algorithm due
> to Tarski
> for creating such sets.
>

Carl Witty has (unreleased) Sage code for doing such things. We also
have an optional spkg for qepcadb, which computes such things.

Unfortunately, it seems like Carl has not been active in the project
lately, so I don't know who else could or wants to do this. Carl: if
you are reading these messages, is there the possibility you could post
your code somewhere so interested people could work from there?

I might note that Mathematica has a very powerful CAD implementation,
from what I understand.

Jason

--
Jason Grout

### Burcin Erocal

Dec 11, 2009, 8:59:44 AM12/11/09
On Thu, 10 Dec 2009 14:37:50 -0800 (PST)
Simon King <simon...@nuigalway.ie> wrote:

> On 10 Dez., 23:15, William Stein <wst...@gmail.com> wrote:
> [...]
> > __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ f := x < y
> >
> > > f*(-3)
> > > ;
> >
> > __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ -3 y < -3 x
> >
> > > f*z;
> >
> > __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ *(x < y, z)
> >
> > > f*a;
> >
> > __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ *(x < y, a)
>
> What else could it be? Maple's answer seems quite reasonable to me.

I opened a ticket for this:

http://trac.sagemath.org/sage_trac/ticket/7660

Checking if the argument is a real number and inverting the relation if
it's negative, like Maple does, is a good option. I hope it doesn't
slow down the arithmetic with symbolic expressions too much tough.

Cheers,
Burcin

### Carl Witty

Jul 11, 2010, 5:16:12 AM7/11/10
On Thu, Dec 10, 2009 at 3:56 PM, Jason Grout
<jason...@creativetrax.com> wrote:
> VictorMiller wrote:
>> To do this correctly in full generality one needs to get into
>> "cyclindrical algebraic decomposition" -- a set in R^n has a
>> cylindrical algebraic
>> decomposition if it is written as a finite union of sets of the form
>> { x : f(x) > 0 } where f is a polynomial.  There is an algorithm due
>> to Tarski
>> for creating such sets.

I don't understand what CAD has to do with the problem. It could be
used to verify a theorem like "If a!=0, then x>y iff (a>0 and a*x>a*y)
or (a<0 and a*x<a*y)", but that doesn't help us decide how to
represent and print a*(x>y).

sage: qepcad('[a /= 0 ==> [x > y <==> [ [a x > a y /\ a > 0] \/ [a x <
a y /\ a < 0] ] ] ]', vars=('a','x','y'))
TRUE

> Carl Witty has (unreleased) Sage code for doing such things.  We also
> have an optional spkg for qepcadb, which computes such things.
>
> Unfortunately, it seems like Carl has not been active in the project
> lately, so I don't know who else could or wants to do this.  Carl: if
> you are reading these messages, is there the possibility you could post
> your code somewhere so interested people could work from there?

I'm back to being active. If there are people interested in
half-written, slow CAD code I'd be happy to work with them! My
impression, though, was that there were a few people interested in
having my work in Sage, but nobody interested in actually helping me
write the code. (Which is fine, it just means it'll take a while to
get finished.)

> I might note that Mathematica has a very powerful CAD implementation,
> from what I understand.
>
> Jason

Carl