sinc(x) -- defining evaluating and simplifying operations



> I wanted to define the sinc(x) function:
> 
> (C1) sinc(x) := if (x = 0) then 1 else sin(x)/x;
> ...
> (C4) sinc(x);
>                                     SIN(x)
> (D4)                                ------
>                                       x
> Well, that's not right.

There are three problems with that definition.

First, it is checking for *syntactic* equality to 0.  So for example
sinc((x-1)*(x+1)-x^2+1) will return sin(...)/....  What you want instead
is "if equal(x,0)".  But in many cases, Maxima will not know.  So you
need to turn off Prederror, to have the possibility of "unknown"
(otherwise you'll get an error in that case).  That would give the
following code:

   sinc(x) := block([prederror:false,eqtest],
                 eqtest: is(equal(x,0)),
                 if eqtest=true then 1
                    else if eqtest=false then sin(x)/x
                    else if eqtest='unknown
                       then <<what goes here??>>

The second problem is that you don't provide for the 'unknown' case.
There are two possibilities for what to return here: either an
unevaluated conditional, or an unevaluated application of sinc.  Since
Maxima doesn't really handle unevaluated conditionals at all, an
unevaluated application of sinc is appropriate.  So <<what goes here?>>
is funmake('sinc,[x]).  Note that you can't use sinc(x), because that
will get into an infinite loop.  You could use 'sinc(x) (noun form), but
that would subsequently require that you de-nounify to re-evaluate.  If
you use funmake, it will reevaluate sinc next time you evaluate the
expression (by doing expr,q=1, for example) -- but not, alas, next time
you resimplify the expression (by doing a subst or whatever).  So, for
example, though limit(sinc(x),x,inf) is well-defined, and in that
context x is guaranteed non-zero, sinc(x) does not become sin(x)/x and
so limit can't carry out the limit.

The third problem is that you're using a function to define this; but if
you want automatic resimplification, you need to define a *simplifying*
operation.  Patterns are how you define a *simplifying* operator at the
Maxima user level.  Sometimes I think that we should just expose
simplifying functions directly to the user, so you could write your own
simp-sinc.  But we currently don't.  If you define simplification rules
with patterns, sinc will act much more like a built-in simplifying
function.

      -s