5

I am making some random algebra equations, and I want to have the ordering be random too, such that if my random equation generator makes `x+1`

, the output stays `x+1`

, without reverting to `1+x`

.

I have tried `ClearAttributes[Plus, Orderless]`

, but it simply did not work - entering `x+1`

returns `1+x`

.

The following sort-of works:

```
Unprotect[Plus];
Format[Plus[a_, b_]] := ToString@a <> " + " <> ToString@b
```

But it uses `Unprotect`

, converts everything to strings, and also doesn't work when `b`

is a fraction (fractions `p/q`

are represented as `p\n--\nq`

).

Is there a nicer way to do this?

Also, I plan to convert everything to `TraditionalForm`

at the end, so using that to control ordering won't work either.

I found another solution, which is again not that great (as in it is super slow), but at least it gives me the results I want:

`Rasterize[TraditionalForm[a]]+Rasterize[TraditionalForm[b]]`

– VF1 – 2012-11-04T19:18:14.957What exactly are you trying to do? I see the problem but I don't understand the objective well enough to offer alternatives. Your suggested fix still makes x+1 turn into 1+x, right? – Rojo – 2012-11-04T19:26:41.860

1@Rojo actually, don't worry about it. I figured it out.

`plus = Row[{#1, " + ", #2}] &;`

was what I was looking for:`x~plus~1 // TraditionalForm`

gives exactly what I want. – VF1 – 2012-11-04T19:29:49.333Yeah, that would work for 2 arguments, for more you can use Riffle. Row@Riffle[{##}, " + "] &. I would prefer using that as Format to plus more than as an ownvalue. Something like Format[plus[args__]] := Interpretation[HoldForm[Plus[args]], plus[args]] – Rojo – 2012-11-04T19:49:42.623

2Also, perhaps you would like wrapping your code in Module (or Block, depending on what you are doing) with Plus=plus, so you can use the + symbol at will. Module[{Plus = plus}, x + 1] – Rojo – 2012-11-04T19:50:49.563

@Rojo I find it interesting though, that after

`ClearAttributes[Plus, Orderless]`

, MMA still returns`1+x`

even for`Plus[x,1]`

input. – VF1 – 2012-11-06T03:49:13.617