def elimination_technique_2(C):
 rels = C._reidemeister_relators
 rels.sort(reverse=True)
 gens = C._schreier_generators
 for i in range((len(gens) - 1), (-1), (-1)):
  rel = rels[i]
  for j in range((len(gens) - 1), (-1), (-1)):
   gen = gens[j]
   if (rel.generator_count(gen) == 1):
    k = rel.exponent_sum(gen)
    gen_index = rel.index((gen ** k))
    bk = rel.subword((gen_index + 1), len(rel))
    fw = rel.subword(0, gen_index)
    rep_by = ((bk * fw) ** ((-1) * k))
    del rels[i]
    del gens[j]
    for l in range(len(rels)):
     rels[l] = rels[l].eliminate_word(gen, rep_by)
    break
 C._reidemeister_relators = rels
 C._schreier_generators = gens
 return (C._schreier_generators, C._reidemeister_relators)

def elimination_technique_2 ( C ) : rels = C . _reidemeister_relators rels . sort ( reverse = True ) gens = C . _schreier_generators for i in range ( ( len ( gens ) - 1 ) , ( - 1 ) , ( - 1 ) ) : rel = rels [ i ] for j in range ( ( len ( gens ) - 1 ) , ( - 1 ) , ( - 1 ) ) : gen = gens [ j ] if ( rel . generator_count ( gen ) == 1 ) : k = rel . exponent_sum ( gen ) gen_index = rel . index ( ( gen ** k ) ) bk = rel . subword ( ( gen_index + 1 ) , len ( rel ) ) fw = rel . subword ( 0 , gen_index ) rep_by = ( ( bk * fw ) ** ( ( - 1 ) * k ) ) del rels [ i ] del gens [ j ] for l in range ( len ( rels ) ) : rels [ l ] = rels [ l ] . eliminate_word ( gen , rep_by ) break C . _reidemeister_relators = rels C . _schreier_generators = gens return ( C . _schreier_generators , C . _reidemeister_relators )
this technique eliminates one generator at a time .