Re: mg[14566]: Follow-up on Piecewise Continuous Functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg14587] Re: mg[14566]: Follow-up on Piecewise Continuous Functions*From*: Jack Goldberg <jackgold at math.lsa.umich.edu>*Date*: Mon, 2 Nov 1998 01:50:59 -0500*Sender*: owner-wri-mathgroup at wolfram.com

Hi Group: I remarked in my earlier post that manipulating PC functions was not difficult and I promised to show why and how in subsequent posts. Here I explain the basic ideas. (1). Let us agree on a standard form for PC functions. I prefer using Which[]. Examples: tent[x_] := Which[ -Infinity<x<0, 0, 0<=x<1, x, 1<=x<2, 2-x, 2<=x<Infinity, 0 ] square[x_] := Which[ -Infinity<x<0, 0, 0<=x<1, 1, 1<=x<Infinity, 0 ] noname[x_] := Which[ -Infinity<x<0, x, 0<=x<Infinity, 1 ] (a) All functions are defined for all x. If necessary we use "-Infinity < x < a, 0" and "b<= x < Infinity < 0" to insure that the functions are defined everywhere. (b) The functions are continuous from the right, that is, f(a) = Lim f(x), x->a, x>a (c) In "Which[..., a<=x<b, f(x), ...]" f(x) is assumed to be analytic in a<x<b. (So f[x] is not itself a piecewise continuous function.) Now the question. The function (A) noname[x] + tent[x]*square[x] for example, is a PC function. What is its canonical Which form? To construct the which form for this function, I rely on a new function called "step". (Not to be confused with UnitStep[] which appears in many packages but is not built-in at least in Version 3.0 and earlier.) (2). Defining "step" step[x_, a_, f_] is not available to the user. It is a function used only in the private part of the package as an intermediate computation. It is a numerical function of x, a and f(x) but is never evaluated. Its meaning is this: step( x, a, f(x) ) returns 0 if x<a, returns f(x) if x>=a. Various simplification rules are defined for "step" (as of now I have 9) Here are some samples. step /: step[ x_,a_,f_ ]*step[ x_, b_, g_ ] := step[ x,Max[a,b], f*g ] step /: step[ x_,a_,f_ ]^n_Integer?Positive := step[ x,a,f^n ] step /: step[ x_,a_,f_ ]+step[ x_,a_,g_ ] := step[ x,a,f+g ] (3). The central idea. The private function "tostep[]" takes as an argument any combination of canonical Which[]'s such as the one given in (A) above, and produces a sum of step functions. The private function "fromstep[]" converts output of "tostep' to the canonical "Which[]". The rules that define "step" when used in "tostep" always lead to a sum of this kind, step[ x,a1,f1[x] ] + step[ x,a2,f2[x] ] + ... + step[ x,an,fn[x] ] where a1 < a2 < ... < an. From such sums, "fromstep[]" easily converts to a single canonical "Which[]". Handling ordinary functions combined with PC functions is easy, since a separate program writes f(x) as Which[ -Infinity<x<Infinity,f] or, if necessary, Which[ -Infinity<x<a, 0, a<=x<b, f(x), b<=x<Infinity, 0 ] This latter case occurs for functions such as Sqrt[1-x^2] which is not defined for |x|>1. The actual implementation of each of these functions (step, tostep, fromstep, etc) is not difficult but is a bit tiresome. The code itself is less than 100 lines and has printing and tabulation options that make for easier visualization. For example, the user function ToPiecewise[f_,x_,opts] calls on the private functions to return the canonical PC representation for any (?) f(x). An optional to ToPiecewise sketches the graph; a second option writes the PC function in a convenient ColumnForm. The code will be posted (I hope!) next week. Jack