I'm trying to solve simple operator algebra problems invovling the harmonic oscillator creation and annihilation operators. So I want to do things like a b^n -> n b^(n-1) + b^n a where [a,b] = 1

I've defined a set of rules that almost get me there, but the final result does not fully simplify and I don't know why. For example if I try to reduce a b^5 it produces 2 b^4 + 3 b^4 + b^5 a

I'm not sure what I'm doing wrong here. If there is a better way to go about doing this kind of simplification please let me know.

My code is as follows:

```
a::Symbol;
b::Symbol;
{a,b}::NonCommuting;
{m,n,r,s}::Integer.
r1 := {
a^0 -> 1,
b^0 -> 1,
b^1 -> b,
a b^m -> (1+b a) b^{m-1},
a b -> 1 + b a,
b^m b -> b^{m+1},
b b^m -> b^{1+m}
};
def act(ex):
converge(ex):
distribute(ex)
expand(ex)
substitute(ex,r1)
sort_sum(ex)
collect_factors(ex)
collect_terms(ex)
simplify(ex)
return ex
act($a b^5$);
```