class_docstr: A class representing group homomorphisms. Instantiate using `homomorphism()`.
  
  References
  ==========
  
  .. [1] Holt, D., Eick, B. and O'Brien, E. (2005). Handbook of computational group theory.
docstr: Return an element of the preimage of ``g`` or of each element
  of ``g`` if ``g`` is a list.
  
  Explanation
  ===========
  
  If the codomain is an FpGroup, the inverse for equal
  elements might not always be the same unless the FpGroup's
  rewriting system is confluent. However, making a system
  confluent can be time-consuming. If it's important, try
  `self.codomain.make_confluent()` first.
docstr_tok: ["Return","an","element","of","the","preimage","of","``","g","``","or","of","each","element","of","``","g","``","if","``","g","``","is","a","list",".","Explanation","===========","If","the","codomain","is","an","FpGroup",",","the","inverse","for","equal","elements","might","not","always","be","the","same","unless","the","FpGroup's","rewriting","system","is","confluent",".","However",",","making","a","system","confluent","can","be","time-consuming",".","If","it","'s","important",",","try","`","self.codomain.make_confluent","(",")","`","first","."]
code: def invert(self, g):
      """
      Return an element of the preimage of ``g`` or of each element
      of ``g`` if ``g`` is a list.
  
      Explanation
      ===========
  
      If the codomain is an FpGroup, the inverse for equal
      elements might not always be the same unless the FpGroup's
      rewriting system is confluent. However, making a system
      confluent can be time-consuming. If it's important, try
      `self.codomain.make_confluent()` first.
  
      """
      from sympy.combinatorics import Permutation
      from sympy.combinatorics.free_groups import FreeGroupElement
  
      if isinstance(g, (Permutation, FreeGroupElement)):
          if isinstance(self.codomain, FpGroup):
              g = self.codomain.reduce(g)
          if self._inverses is None:
              self._inverses = self._invs()
          image = self.image()
          w = self.domain.identity
          if isinstance(self.codomain, PermutationGroup):
              gens = image.generator_product(g)[::-1]
          else:
              gens = g
          # the following can't be "for s in gens:"
          # because that would be equivalent to
          # "for s in gens.array_form:" when g is
          # a FreeGroupElement. On the other hand,
          # when you call gens by index, the generator
          # (or inverse) at position i is returned.
          for i in range(len(gens)):
              s = gens[i]
              if s.is_identity:
                  continue
              if s in self._inverses:
                  w = w * self._inverses[s]
              else:
                  w = w * self._inverses[s**-1] ** -1
          return w
      elif isinstance(g, list):
          return [self.invert(e) for e in g]
  
imports: import itertools
  from sympy.combinatorics.fp_groups import FpGroup, FpSubgroup, simplify_presentation
  from sympy.combinatorics.free_groups import FreeGroup
  from sympy.combinatorics.perm_groups import PermutationGroup
  from sympy.core.intfunc import igcd
  from sympy.ntheory.factor_ import totient
  from sympy.core.singleton import S
label_desc: Use image node_id 3 for calling the GroupHomomorphism obj's underlying member method code with example usage: obj.invert(g) and returns: w, unknown