Question: Match parameter name of a function


I'm trying to create an iterator function

Iter := proc(ff, n)    
    local i,f;
    if n = 0 then return (x->x); end;
    f := x->ff:
    f := apply(unapply(ff))(x);
    for i from 1 to n-1 do
        f := ff(f);
    return unapply(f,x);


This seems to work except that it converts the independent variable to x, which can cause problems.


That is, if I pass something like n->sin(n) then it will output something like x->sin(sin(x))...


Of course, I do explicitly use x but it is because I don't know how to get the input's independent variable.


Ideally I'd like to be able to work on multiple arguments and iterate over the first, by default.


e.g., f#2(x,y,z) = f(f(x,y,z),y,z)


Ultimately the proc above doesn't work well as I want to be able to use it in all contexts(I could pass the value to Iter but I'd rather use function notation.


Please Wait...