I was playing a little dirty, trying to get a template for defining a Curl[] operator.
I wrote the following rule, which I knew was going to spit out a few errors, because all symbols there (including the lists), were undefined:
Cross[{d[1], d[2], d[3]}, {2, 3, 4}] /. Times[a_, b_] -> b[[a]]
Notwithstanding the errors, the result I got was what I wanted:
(* {d[2][[4]] + d[3][[-3]], d[1][[-4]] + d[3][[2]], d[1][[3]] + d[2][[-2]]} *)
with a few more replacements, you can almost see the Curl[] operator materializing.
Sadly, I forgot that the symbol a was already in use in may main .nb, so I changed it to c. Look:
Cross[{d[1], d[2], d[3]}, {2, 3, 4}] /. Times[c_, b_] -> b[[c]]
But now the results are completely different!
(* {(-3)[[d[3]]] + 4[[d[2]]], (-4)[[d[1]]] + 2[[d[3]]], (-2)[[d[2]]] + 3[[d[1]]]} *)
Wow!
I Traced the evaluation, and could easily find out where the both processes started to differ, but I couldn't understand why.
Any ideas?
borchad prior values. Try with delayed rules instead, they scope their variables properly. – Leonid Shifrin Sep 06 '12 at 23:11b,aandb,c, andTimesisOrderless. Some unwanted reorderings may happen based on variable names. – Leonid Shifrin Sep 06 '12 at 23:16