Added code to amalgamate r.e. terms with the same grouping factor

Not yet sure that the gradient is being calculated properly in this case.
Rewrote some of the multiplication methods as scale! methods don't handle AbstractMatrix arguments.