changed return type of first()
added an assertedIndices() helper method
Use matrix multiplication to expand the monomials with common factors