1.18 pattern example 13

Use pattern to convert p(4.5) + p(3/2) + p(u) to 22.5 + p(u) by squaring and adding arguments of those function which has its argument numeric.

p:=x->`if`(x::numeric,x^2,x); 
p(4.5) + p(3/2) + p(u); 
 
 
      22.50000000 + u
 

In Mathematica

p[x_?NumberQ] := x^2 
p[4.5] + p[3/2] + p[u] 
 
   22.5 + p[u]