Skip to main content
added 318 characters in body
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202
expr = g[x3, x2, x1];

You must use RuleDelayed (:>) instead of Rule

g[x3, x2, x1]expr /. g[arg___] :> g[Sequence @@ Reverse[{arg}]]

g[x1, x2, x3]

Many other possibilities include

Cases with {0} level

First @ Cases[g[x3, x2, x1]Cases[expr, h_[args__] :> h[Reverse[{args}]], {0}]

g[{x1, x2, x3}]

Position and Part or Query

p = Reverse @ Flatten @ Position[g[x3, x2, x1]Position[expr, _Symbol, Heads -> False]

{3, 2, 1}

g[x3,expr[[p]]

g[x1, x2, x3]

Query[p] x2,@ x1][[p]]expr

{3 g[x1, 2x2, 1}x3]

You must use RuleDelayed (:>) instead of Rule

g[x3, x2, x1] /. g[arg___] :> g[Sequence @@ Reverse[{arg}]]

g[x1, x2, x3]

Many other possibilities include

Cases with {0} level

First @ Cases[g[x3, x2, x1], h_[args__] :> h[Reverse[{args}]], {0}]

g[{x1, x2, x3}]

Position and Part

p = Reverse @ Flatten @ Position[g[x3, x2, x1], _Symbol, Heads -> False]

{3, 2, 1}

g[x3, x2, x1][[p]]

{3, 2, 1}

expr = g[x3, x2, x1];

You must use RuleDelayed (:>) instead of Rule

expr /. g[arg___] :> g[Sequence @@ Reverse[{arg}]]

g[x1, x2, x3]

Many other possibilities include

Cases with {0} level

First @ Cases[expr, h_[args__] :> h[Reverse[{args}]], {0}]

g[{x1, x2, x3}]

Position and Part or Query

p = Reverse @ Flatten @ Position[expr, _Symbol, Heads -> False]

{3, 2, 1}

expr[[p]]

g[x1, x2, x3]

Query[p] @ expr

g[x1, x2, x3]

added 318 characters in body
Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202

You must use RuleDelayed (:>) instead of Rule

g[x3, x2, x1] /. g[arg___] :> g[Sequence @@ Reverse[{arg}]]

g[x1, x2, x3]

Many other possibilities include

Cases with {0} level

g[x3First @ Cases[g[x3, x2, x1] /., {g[arg___]h_[args__] :> ReverseApplied[g][arg]h[Reverse[{args}]], {0}]

g[x1g[{x1, x2, x3]x3}]

Position and Part

p = Reverse @ Flatten @ Position[g[x3, x2, x1], _Symbol, Heads -> False]

{3, 2, 1}

g[x3, x2, x1][[p]]

{3, 2, 1}

You must use RuleDelayed (:>) instead of Rule

g[x3, x2, x1] /. g[arg___] :> g[Sequence @@ Reverse[{arg}]]

g[x1, x2, x3]

g[x3, x2, x1] /. {g[arg___] :> ReverseApplied[g][arg]}

g[x1, x2, x3]

You must use RuleDelayed (:>) instead of Rule

g[x3, x2, x1] /. g[arg___] :> g[Sequence @@ Reverse[{arg}]]

g[x1, x2, x3]

Many other possibilities include

Cases with {0} level

First @ Cases[g[x3, x2, x1], h_[args__] :> h[Reverse[{args}]], {0}]

g[{x1, x2, x3}]

Position and Part

p = Reverse @ Flatten @ Position[g[x3, x2, x1], _Symbol, Heads -> False]

{3, 2, 1}

g[x3, x2, x1][[p]]

{3, 2, 1}

Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202

You must use RuleDelayed (:>) instead of Rule

g[x3, x2, x1] /. g[arg___] :> g[Sequence @@ Reverse[{arg}]]

g[x1, x2, x3]

g[x3, x2, x1] /. {g[arg___] :> ReverseApplied[g][arg]}

g[x1, x2, x3]