7.94 bug in iscont/piecewise in Maple V.4 (28.8.97)

7.94.1 Jean Brillet
7.94.2 Robert Israel (4.9.97)

7.94.1 Jean Brillet

Is it a bug in iscont function ?

> p:=x->piecewise(x>=0,cos(x),exp(-x)); 
> iscont(p(x),x=-infinity..infinity); 
 
                        false
 

Also, it seems that, sometimes, piecewise functions are not evaluated correctly when arguments have not numeric type :

>fx:=x->piecewise(x>-2 and x<2,cos(x),x>=2,cos(2),exp(-abs(x))): 
>fx(Pi); 
 
       PIECEWISE([-1, -2-Pi < 0 and Pi-2 < 0],[cos(2), 2 <= Pi],[exp(-Pi), 
                  otherwise]) 
 
>fx(ln(2)); 
 
       PIECEWISE([cos(ln(2)), -2-ln(2) < 0 and ln(2)-2 < 0],[cos(2), 2 <= 
                  ln(2)],[1/2, otherwise]) 
Results of fx(evalf(Pi)) and fx(evalf(ln(2)) are correct
 

However,

> fz:=z->piecewise(z<Pi/2,1,2): 
> fz(0); 
                1 
> fz(exp(1)); 
                2
 

What happens ? Is it due to MAPLE difficulty to evaluate bolean expressions with symbolic constants

The bug is removed with Maple V Release 5. (U. Klein)

7.94.2 Robert Israel (4.9.97)

| Is it a bug in iscont function ?

Sort of. Really you might call it a bit of false advertising. The help for "iscont" claims

  The iscont function returns true if the expression is continuous on the 
  interval (thus having no poles), or false if the expression is not continuous. 
  If iscont cannot determine the result it returns FAIL.

However, this is not really true. "iscont" basically uses the "discont" function to find the real discontinuities of your expression, and then checks whether any of these is in the interval given. But the help for "discont" says

  discont returns a set of values where it is possible (not necessarily certain) 
  that discontinuities occur.

So a "false" result from iscont is only an indication that there might be a discontinuity, not a guarantee that there is one. On the other hand, a "true" result is not necessarily reliable either. In many cases Maple tries to use "solve" to find, say, a zero of the denominator of a fraction, and the capabilities of "solve" are limited. For example,

> iscont(1/(cos(x)-x^2), x = -Pi .. Pi); 
                             true
 

From examining the code for `discont/discontR`, it seems to me that for any piecewise expression (unless the expressions in two intervals are actually the same), "discont" will always claim there is a discontinuity at the boundaries of the intervals. Moreover, for an expression that is not a rational function but is a sum or product of terms, "discont" will report any point that is a discontinuity of any of those terms; it does not try to check whether there is a cancellation of some sort.

Conclusion: be very skeptical about the results of "iscont" or "discont".

| Also, it seems that, sometimes, piecewise functions are not evaluated ...

This is not really a failure to evaluate correctly, it is a failure to simplify.

> simplify(fx(Pi)); 
 
             cos(2) 
 
> simplify(fx(ln(2))); 
 
             cos(ln(2))
 

Perhaps the "and" causes Maple some confusion:

> fxp:= x -> piecewise(x  <= -2, exp(-abs(x)), x >= 2, cos(2), cos(x)): 
> fxp(Pi); 
             cos(2) 
> fxp(ln(2)) 
             cos(ln(2))
 

But here’s a genuine bug:

> simplify(fx(x)); 
                                  {     3 cos(x) - 3 cos(2)             x <= -2 
                                  { 
                                  { 4 cos(x) - exp(x) - 3 cos(2)         x < 2 
                                  { 
                                  {       cos(2) - exp(2)                x = 2 
                                  { 
                                  {  2 cos(x) - exp(x) - cos(2)          2 < x
 

| However, ...

What’s your complaint here? These results are perfectly correct.