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

Given an expression in x, y, z (for example), and a list with three elements, like {1,2,3}, how can I do the equivalent of expr/.{x->1,y->2,z->3}? So for example suppose

a = {1,2,3}
x^2+y^2+z^2 /.{x->1,y->2,z->3}

but obviously x^2+y^2+z^2/.{x,y,z}->a does not work.

share|improve this question
up vote 2 down vote accepted

You can do this:

a = {1, 2, 3}
x^2 + y^2 + z^2 /. Rule @@@ Transpose[{{x, y, z}, a}]

You might also use MapThread and the like. But anyways, make sure you understand what @@@ does.

share|improve this answer
Thanks. Beyond your suggestion to understand @@@, I also just learned that -> is really infix shorthand for Rule[]. – rogerl May 4 '13 at 1:43

This can be found in many answers, but I can't find the same question on this site or in the documentation. So:

x^2+y^2+z^2 /.Thread[{x, y, z} -> a]
  (* 14 *)
share|improve this answer

Your Answer


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.