<p>Is this the type of thing you are looking for</p>

<p><img src="https://i.stack.imgur.com/9Gbvc.png" alt="Sort"></p>

<p>These types of rules can be generalised (e.g. add commutation rules for noncommuting objects, make it handle nonnumeric indices, etc...) and packaged up into a <code>NCMSort</code> routine. You can also optimize it by doing the sorting in a single pass by defining a unique <code>NCMOrder</code> function, e.g.</p>

<pre><code>NCMSort[expr_] := expr /. a_NonCommutativeMultiply :&gt; a[[NCMOrder[a]]]
</code></pre>

<hr>

<p>An aside:
I used such a process in generating the results of <a href="http://arxiv.org/abs/1009.3298" rel="nofollow noreferrer">arXiv:1009.3298</a> -- the notebook will be distributed with the (soon to be released) longer paper.</p>
Mathematica: subscript simplification under noncommutative multiplication
<p>Using Subscript[variable, integer] in Mathematica 7.0+,  I have expressions of the following form:  </p>

<pre><code>a_-4 ** b_1 ** a_-4 ** b_-4 ** a_1 ** c_-4 ** c_1 ** c_5
</code></pre>

<p>I would like to simplify this expression.  </p>

<p>Rules:<br>
* Variables with the same subscript to don't commute,<br>
* variables with different subscripts do commute.  </p>

<p>I need a way to simplify the expression and combine like terms (if possible); the output should be something like:</p>

<pre><code>(a_-4)^2 ** b_-4 ** c_-4 ** b_1 ** a_1 ** c_1 ** c_5
</code></pre>

<p>The most important thing I need is to order the terms in the expression by subscripts while preserving the rules about what commutes and what does not.  The second thing (I would like) to do is to combine like terms once the order is correct.  I need to at least order expressions like above in the following way:  </p>

<pre><code>a_-4 ** a_-4 ** b_-4 ** c_-4 ** b_1 ** a_1 ** c_1 ** c_5,
</code></pre>

<p>that is, commute variables with different subscripts while preserving the non-communicative nature of variables with the same subscripts.  </p>

<p>All ideas are welcome, thanks.</p>