# How to use Assuming and If together?

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?

• If[t < u, Print[Yes], Print[No]]
– paw
Sep 6, 2014 at 18:04
• You need a Simplify (Assuming[t < u, Simplify[If[t - u < 0, Print[Yes], Print[No]]]]) otherwise the Assumpition has no effect. Sep 6, 2014 at 18:07
• If has no Assumptions option. Sep 6, 2014 at 18:08
• Assuming only has an effect on an expression, if the expression has the option Assumptions, like Simplify has. Sep 6, 2014 at 18:11
• @ppp I noticed you never accepted any answer to your previous questions. Maybe you would get more responses if you checked "Accept" on some of the earlier answers that you apparently liked.
– Jens
Sep 7, 2014 at 3:35

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

• This is very helpful. Thanks a lot!
– ppp
Sep 6, 2014 at 18:25
• what about in case of multiple assumptions? Can I do add them with &&?
– ppp
Sep 6, 2014 at 18:47
• @ppp Yes, the docs have many examples.
– Jens
Sep 6, 2014 at 18:54