# Conditional definition (/;) [duplicate]

This question already has an answer here:

I defined the following functions

CreatorQ[_] := False;
AnnihilatorQ[_] := False;

CreatorQ[q] := True;
AnnihilatorQ[p] := True;
CreatorQ[J[n_]] /; n < 0 := True;
AnnihilatorQ[J[n_]] /; n > 0 := True;


and when I ask for

Assuming[r < 0, CreatorQ[J[r]]]


I get False instead of True. I know that probabilly it's because Matehamtica doesn't evaluate the r, but I have no idea how to change the code in order to get the correct answer. Thanks

## marked as duplicate by Mr.Wizard♦Jan 27 '17 at 15:26

• I don't thing the problem is with evaluating the r symbol or with the downvalues of the function CreatorQ. I think Assuming isn't doing what you think it should. It simply adds the assumption into \$Assumptions, which some functions like Simplify use. This I think does not have any effect on user defined functions, unless they use Refine, Simplify, FullSimplify or FunctionExpand – Vahagn Tumanyan Jan 27 '17 at 14:20
• I think the "problem" is the /; because if I define CreatorQ[J[n_]]:= n<0 it works! – MaPo Jan 27 '17 at 14:47

The problem is that the pattern-matching in CreatorQ doesn't have any sort of knowledge of the assumption you're making about r, so the Condition won't fire. You can, as you commented, get around this by just redefining CreatorQ to return the inequality, which will remain unevaluated if n doesn't have a value that can be compared to 0:

ClearAll[CreatorQ];
CreatorQ[_] = False;
CreatorQ[q] := True;
CreatorQ[J[n_]] := n < 0;


Now, as in Vaghan Tumanyan's comment, you need to use a function that will make use of the assumptions introduced by Assuming. In this case, Simplify is completely adequate:

Assuming[r < 0, Simplify@CreatorQ[J[r]]]
(* True *)


This is what you need:

CreatorQ[_] := False;
AnnihilatorQ[_] := False;

CreatorQ[q] := True;
AnnihilatorQ[p] := True;
CreatorQ[J[n_]] /; Simplify[n < 0] := True;
AnnihilatorQ[J[n_]] /; Simplify[n > 0] := True;

Assuming[r < 0, CreatorQ[J[r]]]

True