If[condition,t,f] is left unevaluated if condition evaluates to neither True nor False.
I see, that's the reason. So I need to explicitly tell mathematica to evaluate it, e.g.
fn[x_]=Module[{vv,ww},
ww=ArcTan[x];
If[x<ww, Evaluate[ww], Evaluate[ (x+ww)/2 ]
]
which yields the desired result
If[x < ArcTan[x], ArcTan[x], (x + ArcTan[x])/2]
Similarly, with a Which statement I need to sprinkle Evaluate in the right places:
fn[x_]=Module[{ww,yy},
ww=ArcTan[x];
yy=Exp[x];
Which[
x<0, Evaluate[ww],
Evaluate[x<ww], Evaluate[yy],
True, Evaluate[2*yy]
]
]
which yields the desired result
Which[x < 0, ArcTan[x], x < ArcTan[x], E^x, True, 2*E^x]
Thank you.