On 12/5/11, Edwin Woollett <woollett at charter.net> wrote:
> I have a simple simpson's one third rule
> code in simpson.mac, and want to define
> a local function (inside another function)
> to call simp1 for given values
> of one of the expression variables, but am
> not succeeding.
>
> In what follows, I use two different methods
> (in test1 and test2 respectively)
> to define the local function h(x) (or h(var)).
>
> ----------------------------------------------
> Maxima 5.25.1 http://maxima.sourceforge.net
> using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
>
> (%i1) load(simpson);
>
> (%o1) "c:/work2/simpson.mac"
>
> (%i2) trace(simp1)$
>
> (%i3) simp1(0.5*v^2,v,0,1,4);
>
> 1 Enter simp1 [0.5*v^2,v,0,1,4]
> 1 Exit simp1 0.16666666666667
> (%o3) 0.16666666666667
>
> (%i4) test1(expr,x,y) :=
> block(local(h),
> define( h(x),apply('simp1,[expr,y,0,1,4] ) ),
> print(" h(0.2) = ",h(0.2)),
> print(" h(0.5) = ",h(0.5)),
> disp ("bye"))$
>
> (%i5) test1(u*v^2,u,v)$
>
> 1 Enter simp1 [u*v^2,v,0,1,4]
> 1 Exit simp1 0.33333333333333*u
> h(0.2) = 0.066666666666667
> h(0.5) = 0.16666666666667
> "bye"
>
> (%i6) test2(expr,x,y) :=
> block([var],local(h),
> define( h(var),apply('simp1,[subst(var,x,expr),y,0,1,4] ) ),
> print(" h(0.2) = ",h(0.2)),
> print(" h(0.5) = ",h(0.5)),
> disp ("bye"))$
>
> (%i7) test2(u*v^2,u,v)$
>
> 1 Enter simp1 [v^2*var,v,0,1,4]
> 1 Exit simp1 0.33333333333333*v
> h(0.2) = 0.33333333333333*v
> h(0.5) = 0.33333333333333*v
> "bye"
I guess you want simp1 to be called from h,
but the way it is stated above, simp1 is called
by apply, so it's called just once, when h is defined,
and not afterwards.
I think you want funmake, which is like apply except that
the function isn't called, or buildq, which is a non-evaluating
substitution. I'll recommend buildq since it is easier to see
what you'll get. In this case you want something like
define(h(x), buildq([foo:x, bar:y, baz:z], simp1(foo, bar, baz)));
(Sorry, the arguments for buildq are certainly wrong, you'll
have to sort it out.)
What is the definition of simp1, by the way?
best
Robert Dodier