2
$\begingroup$

So I've used Mathematica for some months, but I never noticed this sort of thing about it, namely:

(a > b) == (b < a)

which are supposed to be identical sets of solution.

simple test of the tautology:

In: (a > b) == (a > b)
Out: True

but the output of the previous is:

Out: False

OK, maybe we just need a more powerful function. I've used Simplify, FullSimplify, Refine and Reduce. Yet they return the same form: (a > b) == (b < a). So I used TautologyQ... It returned "False"... What's wrong with the engine?

It's because of this caveat that I'm having trouble with a function I wrote that should neatly evaluate everything. I refuse to drastically change the code, because the fault is not on my end.

I don't want a discussion. Right now, I just want a quick patch, like declaring a wrapper function.

$\endgroup$
  • $\begingroup$ Please help me out... I've got nothing else to do tonight... So basically I'm wasting time waiting here. $\endgroup$ – kozner Sep 22 '16 at 9:33
3
$\begingroup$

Define

tf[e_] := Reduce[e, x, Reals]

Then,

Simplify[(a > b) == (b < a), TransformationFunctions -> {Automatic, tf}]
(* True *)

See the documentation for TransformationFunctions for background. Interestingly,

Simplify[(a > b) == (b < a), TransformationFunctions -> tf]

also works.

$\endgroup$
  • $\begingroup$ Alright, basically puts a variable on the left side of both (in)equalites in hopes that the right sides are SameQ, but You really can't expect that the right side will be written the same way for more complex expressions. $\endgroup$ – kozner Sep 22 '16 at 21:54
  • $\begingroup$ You may wish to add a second instance to your question or, alternatively, pose a new question. I should point out that, though, that simplification is not, in general, simple. $\endgroup$ – bbgodfrey Sep 22 '16 at 21:58
  • $\begingroup$ You're right, I might have to do post a new question. $\endgroup$ – kozner Sep 22 '16 at 23:37
1
$\begingroup$

Consider

ineq = (a > b) == (b < a)

Then

FullForm@ineq

Equal[Greater[a,b], Less[b,a]]

hence you want to compare heads Greater and Less with reversed arguments. My solution is to change Less[b,a] into Greater[a,b] (credit):

lessToGreater := Module[{rep},
   rep = Replace[#, head_[arg__] :> Greater[arg], {0, Infinity}];
   rep~Reverse~1
   ] &

lessToGreater[ineq[[2]]]

a>b

lessToGreater[ineq[[2]]] == (a > b)

True

$\endgroup$
  • $\begingroup$ Thank you. At least now I know more what's going on underneath... I'll see if I can come up with a solution that is as generic and seamless as possible. $\endgroup$ – kozner Sep 22 '16 at 13:13
  • $\begingroup$ There's an "overloading" equivalent in Mathematica that allows you to elegantly substitute a function inside another function... Really bad for security, but useful in this domain... I just can't remember what it's called. I don't think it's in Mathemaica 10's documentation any more. $\endgroup$ – kozner Sep 22 '16 at 13:23
  • $\begingroup$ If I could only remember that language construct that does that internal overloading of a function.... I could do all the combination of all the substitution of Less to Greater and switching left and rigth sides, etc --nestedly... Too back Mathematica doesn't lend itself easily to Combinatronics, so there doesn't seem to be Combnation generating functions, but it's possible to create them using PermutationList. Probably also have to call LogicalExpand before anything to make sure I get everything. $\endgroup$ – kozner Sep 22 '16 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.