# Replacing $x,y$ in $f(x,y,z)$ with values from a list

I'm sure there is a simple solution to this using map or apply, but its not occurring to me.

Suppose I have a function $$f(x,y,z)= x+y+z)$$

And I want to evaluate $$f(x,y,1)$$ for $$\{x,y\} ∈ \{\{1,2\},\{3,4\}\}$$

What is the best way to do this?

Examples:

If I use f[x_,y_,z_]:= x+y+z; f[#1,#2,1]&/@ {{1,2},{3,4}}

this will give me things like {{2+#2,3+#2}}.

On the other hand, Apply works on a single element f[#1,#2,1]& @@ {1,2} but not on a list such as {{1,2},{3,4}}. On the list it gives me {f[1,3,1],f[2,4,1]

I am not sure how to go from the case of a single pair to a list of pairs

• Tp apply to all cross pairs: Outer[f[#1, #2, 1] &, xList, yList] Oct 22 '20 at 22:43

f[x_, y_, z_] := x + y + z;


Try @@@ (Apply at Level 1):

f[#,#2, 1] & @@@ {{1, 2}, {3, 4}}

{4, 8}

• Ahhh, I think I see now. When I use @@, (which I think applies at level 0), uses List[1,2] for the first argument, and List[3,4] for the second. Whereas apply at level 1 applies the function to each part on level 1 of the expression. Thank you very much! I greatly appreciate it. Oct 22 '20 at 20:42
• Sorry, quick follow-up question: Why use SlotSequence ## instead of f[#1,#2,1]? Both work for me in the simply example. Is it just for generality? Oct 22 '20 at 20:48
• @user106860, I changed it to #, #2. The two ways give different results when fed a list like {{1},{1,2,3}.
– kglr
Oct 22 '20 at 20:54
• Awesome. Thanks again! Oct 22 '20 at 20:55