In Mathematica, I have the following code:
f1[x_] := 1;
f2[x_] := 2;
f[x_] := If[x > 5, f1[x], If[x < 0, f2[x], 3]]
f[x]
Which produces the following output:
If[x > 5, f1[x], If[x < 0, f2[x], 3]]
How can I get this output:
If[x > 5, 1, If[x < 0, 2, 3]]
ClearAll[f]; f[x_] := Internal`InheritedBlock[{If}, ClearAttributes[If, HoldRest]; If[x > 5, f1[x], If[x < 0, f2[x], 3]]]? – kglr Jul 29 '23 at 13:18f[x_] := With[{t1 = f1[x], t2 = f2[x]}, If[x > 5, t1, If[x < 0, t2, 3]]]– Daniel Huber Jul 29 '23 at 18:42ClearAll[f]; f[x_] := If[x > 5, #, If[x < 0, #2, 3]] &[f1[x], f2[x]]– kglr Jul 29 '23 at 20:13