Threading objects of unequal length
- To: mathgroup at smc.vnet.net
- Subject: [mg8112] Threading objects of unequal length
- From: "C. Woll" <carlw at u.washington.edu>
- Date: Tue, 12 Aug 1997 00:54:52 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Hi group, I'm interested in adding variable length List. For example, I would like to do something like {a,b}+{c,d,e}+{f} to return {a+c+f,b+d,e} Of course, Plus doesn't work, since you can't thread objects of unequal length. So what is a good way of defining a function to do this? To be specific, I would like a function g which accepts multiple arguments, and when given an input like g[{a,b}, {c,d,e}, {f}] returns {h[a,c,f],h[b,d],h[e]} where in my particular application, I want h to be Plus. However, it would be nice to have the function work for arbitrary heads. I could do something like padding each of the arguments with some dummy variable so that everything has the same length, then threading, then removing the dummy variable, but that seems very cumbersome. Can anyone think of a better way? Thanks for any comments. Carl Woll Physics Dept U of Washington