# Simplifying conditional expressions using assumptions does not work

I have a conditional expression

f[x_] := x /; x ∈ Reals


This works fine for normal numbers and symbols, e.g. {f, f[Sin], f[I], f[a]} evaluates to {1, Sin, f[I], f[a]} as expected.

However, if I have an unknown number $b$ which I know to be real, I cannot get Mathematica to give $f(b)=b$. I have tried

Simplify[f[b], Assumptions -> {b ∈ Reals}]


but this evaluates to f[b].

• You are mixing things used for representing mathematical concepts with programming constructs. ; is a programming construct: it just influences evaluation. It is not meant o be used this way and Simplify won't (and shouldn't) operate on it. I tried to write an answer but then I realized that the real question is: what do you want to do here? You can take a look at ConditionalExpression which is meant for representing a mathematical concept, but whether it is of use to you depends on what you are trying to do. – Szabolcs Jan 22 '15 at 23:41
• Do you mean, "{f, f[Sin], f[I], f[a]} evaluates to {1, Sin, f[I], f[a]}? – bbgodfrey Jan 22 '15 at 23:55
• @bbgodfrey Yes, I meant that, I must have copy-pasted the wrong part. Thanks for mentioning. – Nikki Bisschop Jan 23 '15 at 0:11
• @Nikki After a few minutes thinking I am guessing this question is a duplicate of one of these: (30312), (30322). For example you could write f[x_] /; Simplify[x \[Element] Reals] := "success!" and then Assuming[x \[Element] Reals, Simplify[f[x]]] which should yield "success!". Does this work for you? – Mr.Wizard Jan 23 '15 at 0:44
• Actually, reviewing both of those questions again they each seem rather complicated. I like the simplicity of this question and its potential answer. I shall answer and see what the community wants to make of it. – Mr.Wizard Jan 23 '15 at 1:04

If you are willing to use Assuming, which acts by way of [$Assumptions](http://reference.wolfram.com/language/ref/$Assumptions.html), you can use an $Assumptions-aware [Condition](http://reference.wolfram.com/language/ref/Condition.html) to achieve what I believe you want. I shall use"success!" to illustrate that the definition is truly being used and not another transformation. f[x_] /; Simplify[x ∈ Reals] := "success!"  Now: Assuming[x ∈ Reals, f[x]]  "success!"  How this works: 1. Assuming has the attribute HoldRest which keeps f[x] unevaluated until: 2. Assuming temporarily changes the value of $Assumptions to include x ∈ Reals
3. f[x] is called and the condition Simplify[x ∈ Reals] is evaluated
4. Simplify uses the value of $Assumptions and determines that x ∈ Reals is True 5. The Condition passes and f[x] evaluates to "success!" This question is arguably a duplicate of each of these: However in review neither question seemed as direct and simple as this one so I hesitated to close. • This is a little bit frustrating because the problem is simple and the solution is far from being trivial ... (because of the use of the use of /; with Simplify , because you have to use Assuming (and its HoldRest attribute), because Simplify or Refine won't do the job at least directly ... The only alternative I've found is to use Block and $Assumptions : Block[{$Assumptions=Element[a,Reals]},Simplify[f[a]]] or Block[{$Assumptions=Element[a,Reals]},Refine[f[a]]]. Are there other ways ? (without using /; for example ?) – SquareOne Jan 23 '15 at 18:01
• @SquareOne Well you could use PatternTest instead of Condition but I don't see that as an improvement per se. Likewise your Block is simply reimplementing Assuming. What exactly is your complaint? Would defining realQ = Simplify[# ∈ Reals] &; and then f[x_?realQ] := "success!" be more pleasing to you? – Mr.Wizard Jan 23 '15 at 18:07