       Re: LessEqual vs Inequality, was ..Re: Replacement Rule with Sqrt in denominator

• To: mathgroup at smc.vnet.net
• Subject: [mg114716] Re: LessEqual vs Inequality, was ..Re: Replacement Rule with Sqrt in denominator
• From: Richard Fateman <fateman at cs.berkeley.edu>
• Date: Tue, 14 Dec 2010 06:54:15 -0500 (EST)

```On 12/13/2010 12:52 AM, Andrzej Kozlowski wrote:
> On 12 Dec 2010, at 23:48, Richard Fateman wrote:
>
>>>>
>>> Do you mean a user should not be allowed to enter Less[2,x,3] but
> always required to use the form Inequality[2,Less,x,Less,3]?
>> I did not propose to tie the user's hands in this way.
>>>   Or should Less[2,x,3] always evaluate to
> Inequality[2,Less,x,Less,3]?
>> That would be my solution,.  Is my solution.  Indeed,  Less[x,y] is
> simplified to  Inequality[x,Less,y]
>>>   (In that case you would still have the same problem if, for some
> reason, you prevented evaluation).
>> If I prevented simplification/evaluation, I would presumably not
> expect much of anything to work.
>> I can' t think of a reason.
>
> First  in Mathematica, there are often functions that have attributes
> HoldAll or Hold First etc, which means that the act on unevaluated
> arguments. So if an argument was written as Less[x,y] it would not be
> converted to Inequality[x,Less,y] before pattern matching was applied to
> it (most Mathematica "functions" are just local pattern matching rules).

Um, I think this is irrelevant.  Consider the "function" in Mathematica
Divide. It exists in Mathematica.

Divide[a,b] is immediately transformed to Times[a,Power[b,-1].

Divide[a,b] /. Times-> Foo   results in Foo[a,Power[b,-1]].

Divide has attributes Protected, Listable, NumericFunction.

It's not that different from Less, in some senses:
(a). Divide can always be rewritten as Times[Power ..] or as Rational.
(a') Less can always be rewritten as Inequality[ ..], at least if
Mathematica didn't insist on rewriting in the opposite direction,
namely making Inequality[a,Less,b] into Less[a,b].
(b). Divide does not have attributes Hold, HoldFirst, etc etc
(b') Neither does Less.

So now we have set the stage for DanL and friends.
1. Remove Less. and always replace it with Inequality ...
2. Same for Greater, etc etc.
3. (suggestion)  Rename Inequality with Comparison.
4. modify the rest of the programs, like Compile, Display, as necessary.
5. Change the documentation.

There may still be work to do for dealing with the elements in
Mathematica that do not obey the "law of trichotomy", which states
that a<b, a==b, or a>b.  But this is not true for objects that are
not comparable.  Like Complex numbers, various undefined objects,
Indeterminate, NaN.

> But much more importantly and, in my opinion, crucially (that was the
> main point of my reply, but somehow you managed to skirt around so I
> will now try to make it as explicit as I can):
>
>   if Less[x,y] was always automatically converted to Inequality[x,Less,y]
> than clearly LogicalExpand[Inequality[x, Less, y]] would not longer
> work,
Huh?  It would work the same way as Less[x,y] today, if Mathematica did
not pre-emptively convert Inequality[x,Less,y] into Less[x,y]. That is
LogicalExpand should just leave that alone, and I am sure it could be
convinced to do that.

Note that LogicalExpand does not distinguish between Less[x,y,z] and
Inequality[x,Less,y,Less, z].

and what's worse LogicalExpand[Inequality[x, Less, y, LessEqual,
> z]] etc. would not work.

Really?  I don't know what you mean "wouldn't work".  It works today
to produce
And[Less[x,y], LessEqual[y,z]

in my proposal it would presumably work to produce
And[  Compare[x,Less,y],  Compare [y, LessEqual, z]]

> But that would make it vastly harder to get expressions involving
> inequalities into a canonical form.

I have no idea why you think this is the case.  We have already seen
the reverse.  Which is that Mathematica thinks that Less[x,y,z]
and Inequality[x,Less,y,Less,z] are both canonical forms.

Indeed
FullSimplify [Less[x,y,z]-Inequality[x,Less,y,Less,z] ]
does not reduce to zero, as it should.  So Mathematica, dare
I say, exhibits a bug.

Oh, LogicalExpand[Inequality[x,Less,y,Less,z]] is x<y&&y<z
as is LogicalExpand[x<y<z].

>
>   As it is now, an expression involve both Inequality[x, Less, y,
> LessEqual, z] and And[Less[x,y],LessEqual[y,z]] (which is simply
> x<y&&y<=z). Both of these are equivalent and obviously you would want
> any patterns to apply to both.

Lovely. You are now proposing some kind of semantic pattern match.

As things work now, all you need to do is
> to use LogicalExpand to replace all expressions with Inequality by
> canonical forms and you can do unambiguous pattern matching.

Actually, you appear to be wrong, since
LogicalExpand[x<y<z]  and LogicalExpand[z>y>x]  are different.

But I like your idea of improving on "syntactic pattern matching".

Note that whatever value your thought has is true if you replace all the
expressions involving Less, Equal, .... ,  with Comparison. E.g.
Less[x,y] becomes Comparison[x,Less,y]  etc.  You do have
to be careful with negation, e.g. is x<y the same as Not [x>=y]?
{not if x is ultimately Indeterminate.}

If your
> approach were adopted this would not be possible.

Actually, you have it quite wrong, and I don't see your point.

> to pick out all the different x<y and y<=z in your expression, and
> "simplify" them to a canonical form involving Inequality.

I am not proposing to simplify them any more than is requested.
Less[a_,b_]  would look like Comparison[a_,Less,b_].  What could
be simpler to do?  Note that we do not change
Less[x,y] in Mathematica today to Not[Greater[y,x]]

> But this
> clearly would a great deal more complex than just applying
> LogicalExpand.

I think I get it.  You believe that Comparison[...]  would be
a replacement for Disjunctive Normal Form, which is produced by
LogicalExpand.  Of course it isn't.  LogicalExpand should only produce
pairs, so in this new scheme, you would only use

For a start, the expression could involve many
> conjunctions and disjunctions so that x<y and y<=z would not
> necessarily appear next to each other, i.e. it could be something like
> x<y&&...various relations ...y<=z&&... .

Uh, not at all.

I think my point should now
> be clear -
Yes, you misunderstand the proposal and its implications.

what you are proposing would probably greatly increase the
> complexity of working with inequalities and may well be impracticable.

You appear to be proposing some
kind of alternative to disjunctive normal form (or conjunctive normal
form), both of which are quite well studied. Re-grouping of logical
terms for logic synthesis is also quite well studied, (see circuit
minimization). The general circuit minimization problem is believed to
be intractable. Apparently there are advantages to a computer science
education :)

> Thus implementing your idea would probably amount to introducing  a
> terrible bug into Mathematica, in  your own terminology.

Nope. You miss my point.  I hope I have clarified it for you and anyone