1
$\begingroup$

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

f[x_]:=0/;Element[x,Reals]||MemberQ[{m,a,b},x]

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

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

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

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

ClearAll[f]
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] *)
$\endgroup$

Your Answer

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

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