f



map(x->map(y->map(f,y),x),A);

Is there an easier way to obtain the results of computations like the
following?


>A:={ { [1,2],[3,4] } , { [5,6],[7,8] } }:
> map(x->map(y->map(f,y),x),A);

      { {[f(1), f(2)], [f(3), f(4)]}, {[f(5), f(6)], [f(7), f(8)]} }

--I would appreciate any conceptually simpler ways of doing this. Too
many nested maps makes me dizzy.

--Edwin

0
Edwin
10/27/2007 9:06:38 PM
comp.soft-sys.math.maple 4344 articles. 3 followers. Post Follow

3 Replies
814 Views

Similar Articles

[PageSpeed] 57

Edwin Clark <wclark1@tampabay.rr.com> writes:

> Is there an easier way to obtain the results of computations like the
> following?
>
>
>>A:={ { [1,2],[3,4] } , { [5,6],[7,8] } }:
>> map(x->map(y->map(f,y),x),A);
>
>       { {[f(1), f(2)], [f(3), f(4)]}, {[f(5), f(6)], [f(7), f(8)]} }

An easy way to accomplish this is to use evalindets (or subsindets).
It has an undocumented flat option that prevents further recursing once
the type parameter matches.  Here you could do

  evalindets[flat](A, algebraic, f);
         { {[f(1), f(2)], [f(3), f(4)]}, {[f(5), f(6)], [f(7), f(8)]} }


A better example that illustrates the effect of flat is the following

  A := { { [a+1,2],[3,4] } , { [5,6],[7,8] } }:

  evalindets[flat](A, algebraic, f);

        {{[f(3), f(4)], [f(a + 1), f(2)]}, {[f(5), f(6)], [f(7), f(8)]}}

  evalindets(A, algebraic, f);

                                       f(2)
    {{[f(3), f(4)], [f(f(a) f(1) + f(1)    ), f(2)]}, {[f(5), f(6)], [f(7), f(8)]}}


Somewhat safer is

  evalindets[flat](A, list, curry(map,f));

       {{[f(3), f(4)], [f(a + 1), f(2)]}, {[f(5), f(6)], [f(7), f(8)]}}

That works fine without the flat option.


--
Joe Riel
0
Joe
10/27/2007 9:37:08 PM
Edwin Clark <wclark1@tampabay.rr.com> writes:

> Is there an easier way to obtain the results of computations like the
> following?
>
>
>>A:={ { [1,2],[3,4] } , { [5,6],[7,8] } }:
>> map(x->map(y->map(f,y),x),A);
>
>       { {[f(1), f(2)], [f(3), f(4)]}, {[f(5), f(6)], [f(7), f(8)]} }
>
> --I would appreciate any conceptually simpler ways of doing this. Too
> many nested maps makes me dizzy.

Here's a different approach.  Assign the function

maptolev := proc(lev::nonnegint, f, e) 
local i;
    apply(seq(map[lev-i],i=0..lev-1),f,e) 
end proc:

maptolev(3, f, A);

    { {[f(1), f(2)], [f(3), f(4)]}, {[f(5), f(6)], [f(7), f(8)]} }


--
Joe Riel
0
Joe
10/27/2007 11:06:27 PM
Joe,

Thanks for the suggestions. I think I like

> evalindets(A, list, curry(map,f));

best--so far.

Edwin



0
Edwin
10/28/2007 8:36:07 PM
Reply: