i have following expression:

Cases[cx[i, k] cx[k, q] a[z, x], _Symbol, 2] // DeleteDuplicates

what i expect is to get:


but i get

{z, x, i, k, q}

is there any way to preserve the order of multiplication ?



Cases[Hold[cx[i, k] cx[k, q] a[z, x]], _Symbol, 3] // DeleteDuplicates

The problem was that Mathematica automatically reorders the order of multiplication in a product when you evalute it. The Hold prevents Mathematica from evaluating.

  • $\begingroup$ u changed 2 to 3 because of Hold ? now your head is Hold right? $\endgroup$ – user49047 Jan 25 at 16:11
  • $\begingroup$ yes, since it wraps the expression you needed to increase the depth by one. $\endgroup$ – mmeent Jan 25 at 16:13
  • $\begingroup$ very nice and clever. $\endgroup$ – user49047 Jan 25 at 16:14

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.