# Applying rules to functions with non numeric arguments

I am trying to do the following (it's a simplified version):

In:= rulepositive = { f[a_?Positive]:> f[a] };
In:= rulenegative = { f[a_?Negative]:> 0 };

In:= $Assumptions = Elements[w,Positive]; In:= f[w]/.rulepositive In:= f[w]/.rulenegative  where I expect Out:= f[w] Out:= 0  But it doesn't work. In words I want to apply a set of mapping rules in functions with non numeric arguments, which nevertheless have definite nature (e.g. Positive/Negative). How could I do it? • Why you can't simply use Piecewise? – vi pa Mar 22 '20 at 10:00 • f[a_]:=Piecewise[{{Unevaluated[f[a]],a > 0},{0, a < 0}}] – vi pa Mar 22 '20 at 13:48 ## 2 Answers Positive is not a set.  ?? Positive (*Positive[x] gives True if x is a positive number.*)  Compare to  ?? Integers (*Integers represents the domain of integers, as in x∈Integers. *)  Besides, your expectations seem to be off. Why would you expect '0' out of f[w]/.rulenegative? Moreover, was zero (which is neither positive nor negative) considered in your logic? In any case, the code below might help you. The basic idea is to assign the information to w instead. See TagSetDelayed help "f/:lhs:=rhs assigns rhs to be the delayed value of lhs, and associates the assignment with the symbol f."  rulepositive = {f[a_?Positive] :> "yeah"}; rulenegative = {f[a_?Negative] :> "bummer"}; w /: Positive[w] = True; w /: Negative[w] = False; f[w] /. {{rulepositive}, {rulenegative}} (*{{"yeah"}, {f[w]}}*)  • No, zero is not a case due to the nature of the problem. Also w shouldn't be fixed positive or negative – hal Mar 20 '20 at 11:55 I don't follow what you expect, but you can use Simplify to respect $Assumptions:

rulepositive = {f[a_] /; Simplify[Positive@a] :> 1};   (* modified from your example *)
rulenegative = {f[a_] /; Simplify[Negative@a] :> 0};

$Assumptions = {w > 0}; f[w] /. rulepositive f[w] /. rulenegative   1 f[w]  $Assumptions = {w < 0};

f[w] /. rulepositive
f[w] /. rulenegative

 f[w]

0


Reference: