# [Maxima] unit_step (was Re: New piecewise package in development)

Barton Willis willisb at unk.edu
Sun Nov 9 11:39:22 CST 2008

```>Also, I believe that the orthogonal polynomial package has a "unit_step"
>function, though I don't know whether its left-continuous nature is
>compatible with what you need.

Maybe unit_step in orthopoly should be changed to exclusively use
signum. Otherwise, we get too many related functions with non-local
simplifications. Something like (lightly tested):

unit_step_right_continuous(x) := block([s : signum(x)], s *(1-s) / 2 + 1);

unit_step_left_continuous(x) := block([s : signum(x)], s * (1 + s) / 2);

unit_ramp(x) := (x + abs(x))/2;

unit_blip(x) := block([s : signum(x)], (1 + s) * (1 - s));

unit_pulse(x, left ,right) :=
if is(left = 'open) then (
if is(right = 'open) then unit_step_left_continuous(x) -
unit_step_right_continuous(x-1)
else if right = 'closed then unit_step_left_continuous(x) -
unit_step_left_continuous(x-1)
else error("The third argument to unit_pulse must be closed or open"))
else if is(left = 'closed) then (
if is(right = 'open) then unit_step_right_continuous(x) -
unit_step_right_continuous(x-1)
else if right = 'closed then unit_step_right_continuous(x) -
unit_step_left_continuous(x-1)
else error("The third argument to unit_pulse must be closed or open"))
else error("The second argument to unit_pulse must be closed or open");

Short test:

(%i78) map(lambda([s], unit_pulse(s, 'closed, 'open)),[0,1]);
(%o78) [1,0]

(%i79) map(lambda([s], unit_pulse(s, 'closed, 'closed)),[0,1]);
(%o79) [1,1]

(%i80) map(lambda([s], unit_pulse(s, 'open, 'open)),[0,1]);
(%o80) [0,0]

(%i81) map(lambda([s], unit_pulse(s, 'open, 'closed)),[0,1]);
(%o81) [0,1]

(%i82) unit_step_left_continuous(0);
(%o82) 0

(%i83) unit_step_right_continuous(0);
(%o83) 1

(%i84) map('unit_blip, [-1,0,42]);
(%o84) [0,1,0]

unit_pulse(x, 'closed, 'closed) is a mess, but so it goes:

(%i85) unit_pulse(x, 'closed, 'closed);
(%o85) ((1-signum(x))*signum(x))/2-(signum(x-1)*(signum(x-1)+1))/2+1

(%i86) unit_pulse(x, 'closed, 'open);
(%o86) ((1-signum(x))*signum(x))/2-((1-signum(x-1))*signum(x-1))/2

A nonlocal simplification (that would be hard to do without uniformly
using signum for all these functions:

(%i93) is(equal(unit_step_right_continuous(x) - unit_step_left_continuous
(x), unit_blip(x)));
(%o93) true

Barton

```