2
$\begingroup$

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

$\endgroup$

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ 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 $\endgroup$ – Vahagn Tumanyan Jan 27 '17 at 14:20
  • $\begingroup$ I think the "problem" is the /; because if I define CreatorQ[J[n_]]:= n<0 it works! $\endgroup$ – MaPo Jan 27 '17 at 14:47
4
$\begingroup$

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 *)
$\endgroup$
3
$\begingroup$

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
$\endgroup$

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