code: def homomorphism(domain, codomain, gens, images=(), check=True):
      """
      Create (if possible) a group homomorphism from the group ``domain``
      to the group ``codomain`` defined by the images of the domain's
      generators ``gens``. ``gens`` and ``images`` can be either lists or tuples
      of equal sizes. If ``gens`` is a proper subset of the group's generators,
      the unspecified generators will be mapped to the identity. If the
      images are not specified, a trivial homomorphism will be created.
  
      If the given images of the generators do not define a homomorphism,
      an exception is raised.
  
      If ``check`` is ``False``, do not check whether the given images actually
      define a homomorphism.
  
      """
      if not isinstance(domain, (PermutationGroup, FpGroup, FreeGroup)):
          raise TypeError("The domain must be a group")
      if not isinstance(
          codomain, (PermutationGroup, FpGroup, FreeGroup)
      ):
          raise TypeError("The codomain must be a group")
  
      generators = domain.generators
      if not all(g in generators for g in gens):
          raise ValueError(
              "The supplied generators must be a subset of the domain's generators"
          )
      if not all(g in codomain for g in images):
          raise ValueError(
              "The images must be elements of the codomain"
          )
  
      if images and len(images) != len(gens):
          raise ValueError(
              "The number of images must be equal to the number of generators"
          )
  
      gens = list(gens)
      images = list(images)
  
      images.extend(
          [codomain.identity] * (len(generators) - len(images))
      )
      gens.extend([g for g in generators if g not in gens])
      images = dict(zip(gens, images))
  
      if check and not _check_homomorphism(domain, codomain, images):
          raise ValueError(
              "The given images do not define a homomorphism"
          )
      return GroupHomomorphism(domain, codomain, images)
  
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 1 for calling a global function with example usage: homomorphism(domain, codomain, gens, images, check) and returns: GroupHomomorphism