julia> @syms a b c
(a, b, c)
julia> r = @rule ~a*~b + ~a*~c => ~a * (~b+~c)
~a * ~b + ~a * ~c => ~a * (~b + ~c)
julia> r(a*b + a*c)
a*(b + c)
julia> r(b*a + b*c)
julia>
a way to fix could be generate the permutations of all commutative operations at the top level, and not during the recursion