Skip to main content
added 98 characters in body
Source Link
Junho Lee
  • 5.2k
  • 1
  • 17
  • 34

How about thisEdit

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

For order preserving as Jens says, I changechanged Attributes

ClearAttributes[Plus, Orderless]

HoldForm[7 + x + 2 + 4 + x + 5] /. f___ + x + l___ :> f + 4 + l

7 + 4 + 2 + 4 + x + 5

And you can revert by SetAttributes[Plus, Orderless]


Origin

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

For order preserving as Jens says, I change Attributes

ClearAttributes[Plus, Orderless]

HoldForm[7 + x + 2 + 4 + x + 5] /. f___ + x + l___ :> f + 4 + l

7 + 4 + 2 + 4 + x + 5

And you can revert by SetAttributes[Plus, Orderless]

Edit

For order preserving as Jens says, I changed Attributes

ClearAttributes[Plus, Orderless]

HoldForm[7 + x + 2 + 4 + x + 5] /. f___ + x + l___ :> f + 4 + l

7 + 4 + 2 + 4 + x + 5

And you can revert by SetAttributes[Plus, Orderless]


Origin

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

added 253 characters in body
Source Link
Junho Lee
  • 5.2k
  • 1
  • 17
  • 34

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

For order preserving as Jens says, I change Attributes

ClearAttributes[Plus, Orderless]

HoldForm[7 + x + 2 + 4 + x + 5] /. f___ + x + l___ :> f + 4 + l

7 + 4 + 2 + 4 + x + 5

And you can revert by SetAttributes[Plus, Orderless]

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

For order preserving as Jens says, I change Attributes

ClearAttributes[Plus, Orderless]

HoldForm[7 + x + 2 + 4 + x + 5] /. f___ + x + l___ :> f + 4 + l

7 + 4 + 2 + 4 + x + 5

And you can revert by SetAttributes[Plus, Orderless]

added 160 characters in body
Source Link
Junho Lee
  • 5.2k
  • 1
  • 17
  • 34

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

How about this

HoldForm[x + 2 + 4 + x] /. x + a___ -> 4 + a

4 + 2 + 4 + x

Post Undeleted by Junho Lee
Post Deleted by Junho Lee
Source Link
Junho Lee
  • 5.2k
  • 1
  • 17
  • 34
Loading