Suppose I have a list A={x1,x2,x3}
, a list B={3,4,5}
, and a function f[x]=x1+x2+x3
. Is there a simple way to create a replacement rule R
such that I can do a f[x]/.R
to get 3+4+5
?
1 Answer
Yes, there is a simple way: Thread
.
x1 + x2 + x3 /. Thread[A -> B]
Other ways to create the list of replacement rules include
Rule @@@ Transpose[{A, B}]
MapThread[Rule, {A, B}]
Inner[Rule, A, B, List]
Or less obvious
Function[,Rule[##],Listable][A,B]