3
$\begingroup$

Why ReplaceAll does not work in this situation?

id = {{1, 0}, {0, 1}};
sx = {{0, 1}, {1, 0}};
sy = {{0, -I}, {I, 0}};
sz = {{1, 0}, {0, -1}};
s = {id, sx, sy, sz};
p[t_] := {p0[t], p1[t], p2[t], 
  p3[t]}; 

In[1]:= 
Sum[p[1][[i]]*s[[i]].sx.s[[i]], {i, 1, 4}] /. p[1] -> {1, 0, 0, 0}

Out[1]= {{0, 
  p0[1] + p1[1] - p2[1] - p3[1]}, {p0[1] + p1[1] - p2[1] - p3[1], 0}}

The output is right, only the replacement of the terms in vector p[t] does not take place.

$\endgroup$
7
$\begingroup$

Because

p[1] -> {1, 0, 0, 0}

evaluates to

{p0[1], p1[1], p2[1], p3[1]} -> {1, 0, 0, 0}

and the left side of this rule does not appear in your expression. What you want is,

MapThread[Rule, {p[1], {1, 0, 0, 0}}]

which evaluates to the list of rules

{p0[1] -> 1, p1[1] -> 0, p2[1] -> 0, p3[1] -> 0}

Using ReplaceAll with that list of rules gives the result,

{{0, 1}, {1, 0}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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