5

I would like to compare variables t and u and print either Yes or No depending one which is larger.

My code is simply the following:

Assuming[t < u, If[t - u < 0, Print[Yes], Print[No]]]

Since t < u is assumed, t - u < 0 holds. So I should get Yes. But what I get is a repetition of If term. That is,

If[t - u < 0, Print[Yes], Print[No]]

Am I missing something?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
ppp
  • 817
  • 8
  • 15

1 Answers1

6

What you need to use here is Refine:

Refine[If[t - u < 0, Print[Yes], Print[No]], t < u]

Yes

Ad if you need to work with $Assumptions as well, then you could do this:

$Assumptions = t < u;

Refine[If[t - u < 0, Print[Yes], Print[No]], $Assumptions]

Yes

The last line is also the way it would look if you were to wrap your If statement in Assuming. However, since $Assumptions is also used by default, you can simply do this:

Assuming[t < u, Refine[If[t - u < 0, Print[Yes], Print[No]]]]

Yes
Jens
  • 97,245
  • 7
  • 213
  • 499