| Author |
Comment/Response |
Randy Silvers
|
05/21/07 4:55pm
For a function with, say, two arguments, that yields one such argument, what is the best way to apply this recursively to a list of such arguments?
e.g., f: X^2 -> X
where X is some space
For example, nummeet[x_List,y_List]:=MapThread[Min[#1, #2]&,{x,y}] produces the meet, which is the coordinate-wide minimum.
nummeet[ {1, 1}, {0 ,2 }] = {0, 1}
One inelegant (and thus likely to result in errors) way to apply nummeet to a sequence of pairs is to nest nummeet functions as
nummeet[nummeet[nummeet[ {a, b}, {c, d}], {e, f}], {g, h}]
Another way is to define the list and then use Do:
xyz = {{a, b}, {c, d}, {e, f}, {g, h}};
Do[If [i = 1, meet = xyz[[i]], meet = nummeet[meet, xyz[[i - 1]]]], {i, 1, Length[xyz]}]
Is there a more elegant method, using Map or MapAt or Apply or Nest or Fold? Each of these will seemingly apply a function to each element of the list; it seems that recursion requires a Do loop.
URL: sirandol@deakin.edu.au, |
|