Design a data structure for representing a piecewise function. The representation for the piecewise cubic spline above does not interface with other facilities in Maple. Let us represent a piecewise function as an unevaluated function instead as follows. Let
mean
E.g. your procedures should result in the following behaviour.
> IF( x<0, sin(x), cos(x) ); IF(x < 0, sin(x), cos(x)) > diff(",x); IF(x < 0, cos(x), - sin(x)) > IF( Pi/3<0, sin(Pi/3), cos(Pi/3) ); 1/2 IF(1/3 Pi < 0, 1/2 3 , 1/2) > evalf("); .5000000000
Modify your IF procedure to simplify nested IF expressions, and to handle constant conditions like the example above. E.g. your IF procedure should result in the following behaviour.
> IF( x<0, 0, IF( x<1, x^2, IF(x>2, 0, 1-x^2) ) ); 2 2 IF(x < 0, 0, x < 1, x , 2 < x, 0, 1 - x ) > IF( Pi/3<0, sin(Pi/3), cos(Pi/3) ); 1/2