0
$\begingroup$

I wrote the following replacing statement:

Binomial[12 - u - v - w + z,  4 - u - w + z] /. 
  {u -> Subscript[c, αβ], 
   v -> Subscript[c, βγ], w -> Subscript[c, γα], 
   z -> Subscript[c, αβγ]}

which on the screen is displayed as

$$\text{Binomial}[12 - u - v - w + z,\ 4 - u - w + z]\ /.\{u\rightarrow c_{\alpha\beta},\ v\rightarrow c_{\beta\gamma},\ w\rightarrow c_{\gamma\alpha},\ z\rightarrow c_{\alpha\beta\gamma}\}$$

But the result is

Binomial[
  12 - Subscript[c, αβ] + Subscript[ c, αβγ] - Subscript[c, β[Gamma]] - 
  Subscript[c, γα], 4 - Subscript[c, αβ] + Subscript[ c, αβγ] - Subscript[c, γα]]

which on the screen is displayed as

$$\text{Binomial}[12 - c_{\alpha\beta}+c_{\alpha\beta\gamma} - c_{\beta\gamma} - c_{\gamma\alpha} ,\,4 - c_{\alpha\beta}+ c_{\alpha\beta\gamma} -c_{\gamma\alpha} ]$$

from which we see the ordering of $u,v,w,z$ are shuffled after ReplaceAll, and with the original ordering it would have been

$$\text{Binomial}[12 - c_{\alpha\beta} - c_{\beta\gamma} - c_{\gamma\alpha}+c_{\alpha\beta\gamma}, \,4 - c_{\alpha\beta} -c_{\gamma\alpha}+ c_{\alpha\beta\gamma} ]$$

Why is this shuffling happening and how can I prevent it?

$\endgroup$
  • 1
    $\begingroup$ Plus[] is commutative (has the Orderless attribute), so Mathematica will sort addends in a canonical order. $\endgroup$ – J. M. will be back soon Jul 27 '17 at 1:05
  • $\begingroup$ @J.M. thank you! $\endgroup$ – Jia Yiyang Jul 27 '17 at 2:02
2
$\begingroup$

It is not an effect of Replace. It is caused by Plus having the attribute Orderless, which makes it act as a Abelian operator. If further computation is not needed, you can suppress the reordering with HoldForm.

HoldForm @ 
  Binomial[
    12 - Subscript[c, αβ] + Subscript[c, αβγ] - Subscript[c, β[Gamma]] - 
      Subscript[c, γα], 
    4 - Subscript[c, αβ] + Subscript[c, αβγ] - Subscript[c, γα]]

held_form

$\endgroup$
  • $\begingroup$ I see, thank you! $\endgroup$ – Jia Yiyang Jul 27 '17 at 2:02

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.