#### 7.27 bug aﬀecting piecewise in maple v.5 (22.2.99)

##### 7.27.1 Robert Michael Sinclair (PHj)

Can anyone explain the following? The ﬁrst result is ﬁne, but the second is blatantly wrong (the only diﬀerence is that the second function has "sin(x)/x" instead of "sin(x)" for x>0):

    |\^/|     Maple V Release 5 (WMI Campus Wide License)
._|\|   |/|_. Copyright (c) 1981-1997 by Waterloo Maple Inc. All rights
\  MAPLE  /  reserved. Maple and Maple V are registered trademarks of
<____ ____>  Waterloo Maple Inc.
|       Type ? for help.

> piecewise(x>0,sin(x), x=0,1, x<0,sin(x)/x);
{ sin(x)        0 < x
{
{   1           x = 0
{
{ sin(x)
{ ------        x < 0
{   x

> diff(%,x);
{ cos(x)   sin(x)
{ ------ - ------        x < 0
{   x         2
{            x
{
{    undefined           x = 0
{
{     cos(x)             0 < x

> piecewise(x>0,sin(x)/x, x=0,1, x<0,sin(x)/x);
{ sin(x)
{ ------        0 < x
{   x
{
{   1           x = 0
{
{ sin(x)
{ ------        x < 0
{   x

> diff(%,x);
{ undefined          x = 0
{
{     0            otherwise



It is corrected with Maple 6. (U. Klein)

##### 7.27.2 Preben Alsholm (24.2.99)

The bug appears to be in convert/piecewise. The procedure diff/piecewise converts the expression to Heaviside before it (correctly) diﬀerentiates the expression.

The result is then converted to piecewise, the result of which is wrong (in your last example).

Here is an imitation of what is going on:

> restart;
> p:=piecewise(x>0,sin(x)/x, x=0,1, x<0,sin(x)/x):
> pH:=convert(p,Heaviside);

sin(x)   sin(x) Dirac(x)
pH := Dirac(x) + ------ - ---------------
x             x

> pHd:=diff(pH,x);

cos(x)   sin(x)   cos(x) Dirac(x)
pHd := Dirac(1, x) + ------ - ------ - ---------------
x         2            x
x

sin(x) Dirac(x)   sin(x) Dirac(1, x)
+ --------------- - ------------------
2                  x
x

> convert(pHd,piecewise);

{ undefined          x = 0
{
{     0            otherwise

> simplify(pH); #OK

sin(x)
------
x

> simplify(pHd); #OK

cos(x) x - sin(x)
-----------------
2
x