passing functions as argument one more time



Given that you want to compute spline approximations to "functions" I think
that you can do better if you actually pass expressions, rather than pieces
of program (i.e. maxima functions).

You can, for example, pass an expression like u:sin(x), and its variable x.

When you want to differentiate it, compute v:diff(u,x).
You can evaluate v by subst(1.23,x,v) or  maybe  subst(1.23, 'x, v) if you
think x might be assigned somewhere.  Or if you are sure x occurs nowhere
else,  ev(v,x=1.23).


You can use functions, but the original design is more supportive of
expressions.



> -----Original Message-----
> From: amli at comcast.net [mailto:amli at comcast.net]
> Sent: Sunday, October 08, 2006 1:32 PM
> To: Richard Fateman
> Cc: maxima at math.utexas.edu
> Subject: Re: [Maxima] passing functions as argument one more time
> 
> Thank you Richard
> 
> This is the reason I was using apply command as suggested by Barton in an
> earlier posting
> 
> (%i1)  g(f,x):=block([h:f],diff(h(x),x))$
> 
> (%i2)  h(t):=t^3 + t$
> 
> (%i3)  p(t) := sqrt(5) * t^2$
> 
> (%i4)  g(h,x);
>                                               2
> (%o4)                              3 x  + 1
> (%i5)  g(p,x);
>                                               2
> (%o5)                              3 x  + 1
> (%i6)  gg(f,t) := diff(apply('f,[t]),t)$
> 
> (%i7)  gg(p,x);
> (%o7)                             2 sqrt(5) x
> (%i8)  gg(h,t);
>                                               2
> (%o8)                              3 t  + 1
> 
> 
> 
>  Defining functions inside may not be popular and I am not an experienced
> user of maxima but
> I need to pass different functions to compute its B-spline
> representations.  I  do not want earlier functions to corrupt results.
> These are not the actual computations that I am doing.  This is my way of
> identifying the problem so I can post it.
> 
> I now understand how to do my computations.  Thank you for your  input.
> 
> Ram
>  -------------- Original message ----------------------
> From: Richard Fateman <fateman at cs.berkeley.edu>
> > 1. try apply(f,[t]). I don't know why you are doing apply('f ...).
> >
> > 2. block ([...],local(h), ..h(x):= ....
> >
> > 3. defining functions within functions was not a popular way of writing
> > lisp programs in 1968.
> > It still isn't, though with scheme and lexically scoped common lisp it
> > is more plausible.
> > You seem to be straining to do something that can be done by this:
> >
> > ff(f,x):= block([], local(h), h(x):= if x<1 then x else 3*x,
> > apply(f,x)*h(2*x));
> >
> >
> >
> > RJF
> >
> >
> > amli at comcast.net wrote:
> >
> > >1.  How can I make sure that the functions defined in global space do
> not
> > conflict with passing of
> > >function arguments? For example I do not want f(x) defined outside the
> program
> > conflict with passing the function f.   (In a scipt file I may have many
> > functions defined)
> > >
> > >
> > >x:5;
> > >t:3;
> > >ff(f,x):=block([t,g,h],g:apply('f,[t]),if x<1 then h(x):=x else
> > h(x):=3*x,ev(g,t=x)*h(2*x));
> > >ff(sin,2);    //works
> > >
> > >
> > >f(x):=x^2;
> > >ff(f,x):=block([t,g,h],g:apply('f,[t]),if x<1 then h(x):=x else
> > h(x):=3*x,ev(g,t=x)*h(2*x));
> > >ff(sin,2);  //does not work
> > >
> > >I tried this
> > >(x):=x^2;
> > >ff(f,x):=block([t,g,h],g:'apply('f,[t]),if x<1 then h(x):=x else
> > h(x):=3*x,ev(g,t=x)*h(2*x));
> > >ff(sin,2);
> > >but how do you get the final evaluation.
> > >
> > >2.  I also do not want the functions defined inside the program such as
> h have
> > global scope.  How can I restrict them to be local only.   I suppose I
> could use
> > the kill command.  Is that the only solution?
> > >
> > >Thank you
> > >
> > >Ram
> > >_______________________________________________
> > >Maxima mailing list
> > >Maxima at math.utexas.edu
> > >http://www.math.utexas.edu/mailman/listinfo/maxima
> > >
> > >
> >
>