def _basis(G, ring):
 order = ring.order
 leading_monomials = [g.LM for g in G]
 candidates = [ring.zero_monom]
 basis = []
 while candidates:
  t = candidates.pop()
  basis.append(t)
  new_candidates = [_incr_k(t, k) for k in range(ring.ngens) if all(((monomial_div(_incr_k(t, k), lmg) is None) for lmg in leading_monomials))]
  candidates.extend(new_candidates)
  candidates.sort(key=(lambda m: order(m)), reverse=True)
 basis = list(set(basis))
 return sorted(basis, key=(lambda m: order(m)))

def _basis ( G , ring ) : order = ring . order leading_monomials = [ g . LM for g in G ] candidates = [ ring . zero_monom ] basis = [ ] while candidates : t = candidates . pop ( ) basis . append ( t ) new_candidates = [ _incr_k ( t , k ) for k in range ( ring . ngens ) if all ( ( ( monomial_div ( _incr_k ( t , k ) , lmg ) is None ) for lmg in leading_monomials ) ) ] candidates . extend ( new_candidates ) candidates . sort ( key = ( lambda m : order ( m ) ) , reverse = True ) basis = list ( set ( basis ) ) return sorted ( basis , key = ( lambda m : order ( m ) ) )
computes a list of monomials which are not divisible by the leading monomials wrt to o of g .