@public
def itermonomials(variables, degree):
 if (not variables):
  return set([S.One])
 else:
  (x, tail) = (variables[0], variables[1:])
  monoms = itermonomials(tail, degree)
  for i in range(1, (degree + 1)):
   monoms |= set([((x ** i) * m) for m in itermonomials(tail, (degree - i))])
  return monoms

@ public def itermonomials ( variables , degree ) : if ( not variables ) : return set ( [ S . One ] ) else : ( x , tail ) = ( variables [ 0 ] , variables [ 1 : ] ) monoms = itermonomials ( tail , degree ) for i in range ( 1 , ( degree + 1 ) ) : monoms |= set ( [ ( ( x ** i ) * m ) for m in itermonomials ( tail , ( degree - i ) ) ] ) return monoms
generate a set of monomials of the given total degree or less .