# Mapping two pure functions over different lists

Say if I have two lists of vectors of the same length, for example:

u = {{1,0,0},{0,1,0},{0,0,1}}
v = {{1,0,1},{1,1,0},{1,1,1}}


I want to add (modulo 2) u1 + v and then u2 + v and then u3 + v, so I want to obtain:

u1 + v = {{0,0,1},{1,0,0},{1,1,0}}
u2 + v = {{1,1,1},{1,0,0},{1,1,0}}
u3 + v = {{1,0,0},{1,1,1},{1,1,0}}


The only way I can do this so far is:

Mod[u[[1]]+v[[#]],2]&/@Range[Length[u]]
Mod[u[[2]]+v[[#]],2]&/@Range[Length[u]]
Mod[u[[3]]+v[[#]],2]&/@Range[Length[u]]


However, this involves manual/clunky computation. Is it possible to iterate through the positions of u as well as iterating through the position of v, so that I would be able to calculate this in one go without writing out all the equations?

This is a frequent problem I encounter where I want to define two pure functions to be mapped over different lists in the same line of code. Is it possible?

• Does Outer[Mod[Plus[##], 2] &, u, v, 1] do what you want? Sep 20, 2023 at 14:46
• For your current attempt: You can map over the elements of v themselves, without having to take the roundtrip over indices: Mod[u[[1]]+#,2]&/@v Sep 20, 2023 at 14:55
• @LukasLang That is certainly a better way of doing it! I wonder then if there is a way to iterate through the index of u simultaneously? Sep 20, 2023 at 15:08
• @J.M.'slackofA.I. This is exactly what I was looking to do, thank you! I am still interested as to whether it can be done in the format I'd tried, although my suspicion is that I was just going about it the wrong way. Sep 20, 2023 at 15:10
• Also: Table[Mod[Plus[u[[i]], v[[j]]], 2], {i, #1}, {j, #2}] & @@ Rest@Dimensions@{u, v} Sep 20, 2023 at 19:18