I am trying to define a function that is zero when it is evaluated on real numbers and on a preset list of symbols. I am doing this by using


where {m,a,b} are the set of symbols I want the function to be zero on. The problem is, I can't seem to set more rules for the function f. For example, if I try to set the rule

newRule= {f[x_]:>g[x]+q[x]}

Mathematica evaluates this to


How should a set the pattern for f so that I can make rules that do not evaluate to zero?

I am using Mathematica 11.


1 Answer 1


You may use multiple definitions for $f$, perhaps something like this:

f[x_?NumericQ] := 0
f[x_?(MemberQ[{m, a, b}, #] &)] := 0
f[x_] := g[x] + q[x]

See sample outputs:

f[3]     (* 0 *)
f[Pi]    (* 0 *)
f[1.2]   (* 0 *)

f[a]     (* 0 *)
f[c]     (* g[c] + q[c] *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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