Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 11 down vote accepted

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.