windowed functions



On 4/22/07, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>
> Another way to approach all this which *does* support some simplification
> is using signum to construct algebraic expressions with steps in them.  The
> expressions get very messy, but Maxima can currently do more simplifications
> on them.


Let's take the examples in the previous mail, and assume we don't care about
behavior at the discontinuities -- that allows us to simplify signum(x)^2 =>
1, for example.

Definitions

/* if a is negative, then nval, otherwise pval */
ifneg(a,nval,pval):=(pval+nval)/2+(pval-nval)/2*signum(a);

/* if x is between a and b, then val, else 0 */
inrange(x,a,b,val):= ifneg(x-b,0,ifneg(x-a,val,0)));

Applications

ifneg(-x,x,-x)*ifneg(-x,1/x,1) =>
       x*signum(x)*((1/x+1)/2-(1-1/x)*signum(x)/2)
ratsubst(1,signum(x)^2,%) =>
      ((x+1)*signum(x)-x+1)/2
cf.
ifneg(-x,1,-x) =>
         (1-x)/2-(-x-1)*signum(x)/2
ratsimp(%) =>
       ((x+1)*signum(x)-x+1)/2

ifneg(-x,ifneg(x,1,0),2) =>
     (5/2-signum(x)/2)/2-(signum(x)/2+3/2)*signum(x)/2
ratsubst(1,signum(x)^2,%) =>
     1-signum(x)

But things get messy quickly....

              -s