@acer

Thanks... The problem is my ignorance in understanding maple. I can do basically what I want to do but generally for "complicated" stuff is not satisfactory.

There is something bizzaire about how maple does things that just does not jive with my experiences in using programming languages. My expectations always deceive me in maple in certain situations. I'm used to common programming languages like C and it's pretty straight foward.

f := x->...

is what I see as a "lambda function". A sort of short hand to define a function. The lhs is just the independent variables and the rhs is what to do with them. This notation is used in some programming languages or some variant. Of course function usage is same generally: f(3), f(n), f(x), etc...

The issue is that in some cases there are issues. For example, I can pass f to a proc and it seems to pass in the entire function as sort of object with the independent variable and such... but then other circumstances f is not the same as f(x) and when passed in in to some proc/function it sees it as something different.

One of the problems I was that when I was iterating it was working fine except if I had a depth of 0... i.e., no iteration.. .and then the result was different. It's all hard to explain because this stuff creeps up when I'm trying to solve a problem and it doesn't work out. Then I spend several minutes trying to hack it so I can continue to move along. For example, I tried @@ but it didn't work:

C := n->n^2:

C@@(3)(5);

@@(C, 3)

So I moved on. Using loops to iterate... then put it in a proc to make it more general, etc... to make it more general I'd like to use an arbitrary function(before I was using a global function which works fine). Then things don't quite work, for example:

Iter := proc(f, n)

end:

The idea is Iter should take an arbitrary function(univariate is fine but sometimes I define a function to have parameters and I still want it to work withe parameters. (One thing maple doesn't seem to have is default values which kinda sucks)

Iter := proc(f,n)

local g, i;

g := f; # We can't use f to iterate on. g should be a "copy" of f.

for i from 1 to n do

g := f(g):

end:

end:

but g(f) doesn't make sense. We have to have a value. I could extend Iter but I'd rather use functional/composition like syntax.

the above Iter returns

Iter(C,3);

C^8

So clearly C is being treated as a constant.

but

Iter := proc(f,n)

print(f);

local g, i;

g := f; # We can't use f to iterate on. g should be a "copy" of f.

for i from 1 to n do

g := f(g):

end:

end:

Iter(C,3);

n->n^2

C^8

So C is being passed as a function but somehow it turns in to an unassigned variable. I guess that is due to g := f;

so then I say g := x->f(x);

Iter := proc(f,n)

local g, i;

g := x->f(x); # We can't use f to iterate on. g should be a "copy" of f.

for i from 1 to n do

g := f(g):

end:

end:

Iter(C,3);

g^8

which is invalid...

so I change to g := f(x);

and I get x^16 which is "correct"(well, it's iterated one to much).

Iter := proc(f,n)

local g, i;

g := f(x); # We can't use f to iterate on. g should be a "copy" of f.

for i from 1 to n do

g := f(g):

end:

g;

end:

So that seems to work. But the g := f(x) is strange is that is the evaluation of f at x. Also it creates a dependency on the name x and also on f being univariate. So it is not as general as I want.

I want to simplify the iteration process so it works in general when ever I need it. If I create a new function with several parameters, I don't want to change any of the syntax:

C := (n,a,b)->n^a + b;

Iter(C,5);

And it will iterate over the first independent but the others are still parameters. In fact, as parameters, I might want to index them.

I.e., C(C(n,a1,b1),a2,b2), etc...

I don't want to have to treat everyone as a special case. Ideally to have defaults for the most used case and then be able to modify it for more specific cases with the least amount of work. I.e., if I have parameters to be able to specify indexing them, and also to specify the independent variable that is used in the interation which is usually the first(so it defaults to it).

Whatever is returned by Iter should be as if I were to define it manually by hand else it does not accomplish it's purpose.

What you've given may work fine:

K:=proc(F,X,L2,n)
foldl(L->F(L,op(_rest)),X,L2$n);
end proc:
for k from 0 to 3 do
K(f, a, [b,c], k);
end do;

except it doesn't seem to index the parameter list with the interation count.

It seems that maple may have default vaules {a := b} makes a default to b... so maybe I can get what I want.

Best I can tell, your code does what I want except it doesn't capture the ability to add depth indexing to the other parameters and doens't default to the case of not doing that. That probably seems relatively easy enough by modifying the L2$n part and using the {a:=b} stuff...

I'll have to play around with it and see...

Thanks!