If statement problems

I have a function defined as

a[x_]:=If[x==0,const,f[x]]


where $f(0)\neq const$.

How do I evaluate $a(x)$ such that I just get $f(x)$ without having to put in a specific x value greater than 0? I've tried things like $/;$, Assumptions and Assuming, but haven't been able to do it. This seems like it should be a simple thing, any ideas?

• This answer sheds some light on why this might not be as simply as it first seems. – Quantum_Oli Jun 8 '17 at 16:00

You can use TrueQ:

a[x_] := If[TrueQ[x == 0], const, f[x]]


Or the fourth parameter of If:

a[x_] := If[x == 0, const, f[x], f[x]]


Or formulate your function in two definitions:

a[x_] /; x == 0 = const;
a[x_] := f[x]


• Or If[x === 0, ...] which is what I usually do. – Carl Woll Jun 8 '17 at 16:13