MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

UnitStep and Simplify

  • To: mathgroup at
  • Subject: [mg19980] UnitStep and Simplify
  • From: Jack Goldberg <jackgold at>
  • Date: Thu, 23 Sep 1999 23:26:26 -0400
  • Sender: owner-wri-mathgroup at

Hi Group,

I'm happy to see that UnitStep has moved from the 
"AddOns" to the "BuiltIns".  This was long overdue
and, at least for me, a significant step - so to speak.

Having said that let me add a mild criticism and what 
I think is an improvement to the present situation.

I think the UnitStep[x] should have been defined as 
UnitStep[x,0] and UnitStep[x-a] as UnitStep[x,a]. This 
is a small point but after experimenting for years (literally!)
I came to the conclusion that UnitStep ought to be a function 
of two variables, the second variable the point at which the 
function jumps.  But, in any case, it is not hard to convert
back and forth by replacement rules.  A more serious issue is 
the lack of a real simplifier for complicated functions of 
UnitStep.  I provide this also. So here goes.  (Suggestions,
comments and praises are welcome!)

First let us define Step[_,_] as the function Mathematica should have 
defined! :-).

Step[x_,a_?NumericQ] /; x<a :=0
Step[x_,a_?NumericQ] /; x>=a := 1

Now a new function which simplifies functions of Step.
Later on I provide an explanation.

StepSimplify[f_,x_] /; MemberQ[f,_Step,{0,-1}] :=
	Module[ {brkpts,A0,line1},
		brkpts = Cases[f,Step[x,a_]->a,{0,-1}]//Union;
		A0 = f - (f/. Step[x,a_]->0);
		line1 = Fold[(#1-(#1/.Step[x,a_]
		f-line1 ]

Try it on some simple examples.  Say,

ex1 = (x Step[x,1]-Step[x,2])^2, ex2 = Cos[Step[x,0],
ex3 = Sqrt[1+Step[x,1]*Step[x,2]-Step[x,3]].

Now try FullSimplify!

The idea behind the code given in StepSimplify is this:

Supposing that  f  contains various Step functions say
Step[x,0], Step[x,-1] and Step[x,1]. I assert that 
f may be expanded as follows

(1)  f = A[x] + B[x]* Step[x,-1] + C[x]*Step[x,0] + D[x]*Step[x,1]

(and this expansion is unique if f has certain "reasonable" 
properties) where A[x], B[x] etc. does not contain any Step[x,_]. 

(2) brkpts (breakpoints) gives the list of jumps due to the Step

(3) A0  simply forms  A0 = f-A[x] by replacing all Step's in 
    (1) by zero.

(4) line1  uses the iterated nature of (1) to obtain B[x],
C[x] and D[x]  in turn.  For example, to obtain  B[x] we 
take  f-A[x] and set the arguments of all steps to x=-1 
(the first entry in brkpts). All Steps, Step[x,a], a>-1 
vanish and  Step[-1,-1]->1. It then follows that we have 
B[x].  We form  f-A[x]-B[x] Step[x,-1]  to set up the 
Fold function to find  C[x], etc.

(5) I think I need {0,-1} in both MemberQ and Cases to capture 
the trivial case f=Step[x,a]. Also, Union was used both to 
order the brkpts (breakpoints) and to remove repeats. Ordering
seems essential to the scheme and this is one minor reason 
I prefer  Step[x,a] to UnitStep[x-a].   

By the way, it also simplifies correctly, Step[Step[x,a],b]
and replaces  g[x] Step[x,a] + h[x] Step[x,a]  by 
(g[x]+h[x])Step[x,a], a task which I found required some 
vary careful programming, particularly if Expand is used
to simplify the final coefficients of each  Step.   

Again, feedback is appreciated and if I am correct in 
my statements about StepSimplify, perhaps someone could
suggest improvements in the code or alternatives. By the way,
FullSimplify does a litte simplification on simples expressions
containing UnitStep but is woefully 
inadequate most cases. 



  • Prev by Date: Select cell
  • Next by Date: Re: Plotting questions
  • Previous by thread: RE: Select cell
  • Next by thread: Mathematica Animations into Screen Savers