class_docstr: A class implementing rewriting systems for `FpGroup`s.
  
  References
  ==========
  .. [1] Epstein, D., Holt, D. and Rees, S. (1991).
         The use of Knuth-Bendix methods to solve the word problem in automatic groups.
         Journal of Symbolic Computation, 12(4-5), pp.397-414.
  
  .. [2] GAP's Manual on its KBMAG package
         https://www.gap-system.org/Manuals/pkg/kbmag-1.5.3/doc/manual.pdf
class_docstr_tok: ["A","class","implementing","rewriting","systems","for","`","FpGroup","`","s",".","References","==========","..","[","1","]","Epstein",",","D.",",","Holt",",","D.","and","Rees",",","S.","(","1991",")",".","The","use","of","Knuth-Bendix","methods","to","solve","the","word","problem","in","automatic","groups",".","Journal","of","Symbolic","Computation",",","12","(","4-5",")",",","pp.397-414",".","..","[","2","]","GAP","'s","Manual","on","its","KBMAG","package","https",":","\/\/www.gap-system.org\/Manuals\/pkg\/kbmag-1.5.3\/doc\/manual.pdf"]
docstr: Apply reduction rules to `word` excluding the reduction rule
  for the lhs equal to `exclude`
docstr_tok: ["Apply","reduction","rules","to","`","word","`","excluding","the","reduction","rule","for","the","lhs","equal","to","`","exclude","`"]
code: def reduce(self, word, exclude=None):
      """
      Apply reduction rules to `word` excluding the reduction rule
      for the lhs equal to `exclude`
  
      """
      rules = {r: self.rules[r] for r in self.rules if r != exclude}
      # the following is essentially `eliminate_words()` code from the
      # `FreeGroupElement` class, the only difference being the first
      # "if" statement
      again = True
      new = word
      while again:
          again = False
          for r in rules:
              prev = new
              if rules[r] ** -1 > r**-1:
                  new = new.eliminate_word(
                      r, rules[r], _all=True, inverse=False
                  )
              else:
                  new = new.eliminate_word(r, rules[r], _all=True)
              if new != prev:
                  again = True
      return new
  
file_path: sympy/sympy/combinatorics/rewritingsystem.py
imports: from collections import deque
  from sympy.combinatorics.rewritingsystem_fsm import StateMachine
label_desc: Use image node_id 10 for calling the RewritingSystem obj's underlying member method code with example usage: obj.reduce(word, exclude) and returns: new