[Fwd: array functions]



It is easy to convert an indexed function with its double evaluation
property to a non-indexed function with normal semantics.

Instead of f[i](x):=...some expression involving i and x..., you write

   f[i](x):=('fullf)(i,x)

and define

   fullf(i,x):=...some expression involving i and x...

Of course, this means that there is no (useful) partial evaluation of
the f[i]'s, and no caching of their values, which are the usual reasons
for using indexed functions.

As for your Gauss-Hermite example, the problem there is that Maxima does
not have lexical scope (so the n's in the lambda expression are
evaluated incorrectly).  I will look at it in more detail later -- I
don't have the time right now.

---------------

As for Funmake:

Leo Harten said in sci.math.symbolic:

> I suspect that the issue is the amount of evaluation that
> is performed when the array element h1[2] is calculated
> before the application to the argument(s).

Yes, that's exactly the issue, as I explained at length in my previous
email.

> h3[k]:=lambda([x],funmake(print,["x=",x]),x);

Yes, this works because funmake prevents the print from being evaluated
the first time around.  And it is precisely equivalent to:

  h3[k](x):=funmake(print,["x=",x]);

Dan Stanger asks:

> Is this what funmake is used for?

Not really; it is used when you want to construct a functional
expression f(a,b,c), where f is a variable and you want to evaluate the
arguments (a,b,c) without actually evaluating the result; contrast
Apply, which evaluates the arguments, then evaluates the resulting
expression.  If f is constant, you don't need Funmake at all; you can
just write ('print)(x) for example.  To tell you the truth, I wasn't
aware of the Funmake function; when I want to do this, I just use
substinpart(f,[a,b,c],0) (of course, that is much less efficient).

Note, by the way, that Funmake does NOT block *simplification*.  So for
example funmake(sin,[2.3]) => 0.7457.

Funmake or explicit quoting of functions is NOT the general solution to
the original problem, because you'd have to go through and quote each
one separately.  It is also very clumsy for control structures, e.g.
what do you do with

   h5[i](x):= if i>x then 1 else 0
or
   h5[i](x):= for index:i thru x do ...