Question: Inconsistent behavior of eval in piecewise

Strange (inconsistent) behavior of eval in piecewise

 

restart;#####################

a:=2:

p:=piecewise(x<a, 1/(x-a), x=a, 22, 33);

p := piecewise(x < 2, 1/(-2+x), x = 2, 22, 33)

(1)

eval(p, x=a);

22

(2)

restart;#####################

a:=Pi:

p:=piecewise(x<a, 1/(x-a), x=a, 22, 33);

p := piecewise(x < Pi, 1/(-Pi+x), x = Pi, 22, 33)

(3)

eval(p, x=a);

Error, (in eval/piecewise) numeric exception: division by zero

 

restart;#####################

a:=Pi+ln(2):

p:=piecewise(x<a, 1/(x-a), x=a, 22, 33);

p := piecewise(x < Pi+ln(2), 1/(-Pi-ln(2)+x), x = Pi+ln(2), 22, 33)

(4)

eval(p, x=a);

22

(5)

restart;#####################

a:=Pi+1:

p:=piecewise(x<a, 1/(x-a), x=a, 22, 33);

p := piecewise(x < Pi+1, 1/(-Pi-1+x), x = Pi+1, 22, 33)

(6)

eval(p, x=a);

Error, (in eval/piecewise) numeric exception: division by zero

 

restart;#####################

a:=gamma:

p:=piecewise(x<a, 1/(x-a), x=a, 22, 33);

p := piecewise(x < gamma, 1/(-gamma+x), x = gamma, 22, 33)

(7)

eval(p, x=a);

Error, (in eval/piecewise) numeric exception: division by zero

 

#######################

f:=x->piecewise(x<Pi, 1/(x-Pi), x=Pi, 22, 33);

f := proc (x) options operator, arrow; piecewise(x < Pi, 1/(x-Pi), x = Pi, 22, 33) end proc

(8)

f(Pi);

22

(9)

 


Download piecewise-strange.mw

Please Wait...