code: def _make_converter(K):
      """Construct the converter to convert back to Expr"""
      # Precompute the effect of converting to SymPy and expanding expressions
      # like (sqrt(2) + sqrt(3))**2. Asking Expr to do the expansion on every
      # conversion from K to Expr is slow. Here we compute the expansions for
      # each power of the generator and collect together the resulting algebraic
      # terms and the rational coefficients into a matrix.
  
      gen = K.ext.as_expr()
      todom = K.dom.from_sympy
  
      # We'll let Expr compute the expansions. We won't make any presumptions
      # about what this results in except that it is QQ-linear in some terms
      # that we will call algebraics. The final result will be expressed in
      # terms of those.
      powers = [S.One, gen]
      for n in range(2, K.mod.degree()):
          powers.append((gen * powers[-1]).expand())
  
      # Collect the rational coefficients and algebraic Expr that can
      # map the ANP coefficients into an expanded SymPy expression
      terms = [
          dict(t.as_coeff_Mul()[::-1] for t in Add.make_args(p))
          for p in powers
      ]
      algebraics = set().union(*terms)
      matrix = [
          [todom(t.get(a, S.Zero)) for t in terms] for a in algebraics
      ]
  
      # Create a function to do the conversion efficiently:
  
      def converter(a):
          """Convert a to Expr using converter"""
          ai = a.to_list()[::-1]
          tosympy = K.dom.to_sympy
          coeffs_dom = [
              sum(mij * aj for mij, aj in zip(mi, ai)) for mi in matrix
          ]
          coeffs_sympy = [tosympy(c) for c in coeffs_dom]
          res = Add(
              *(Mul(c, a) for c, a in zip(coeffs_sympy, algebraics))
          )
          return res
  
      return converter
  
imports: from sympy.core.add import Add
  from sympy.core.mul import Mul
  from sympy.core.singleton import S
  from sympy.polys.domains.characteristiczero import CharacteristicZero
  from sympy.polys.domains.field import Field
  from sympy.polys.domains.simpledomain import SimpleDomain
  from sympy.polys.polyclasses import ANP
  from sympy.polys.polyerrors import CoercionFailed, DomainError, NotAlgebraic, IsomorphismFailed
  from sympy.utilities import public
label_desc: Use image node_id 1 for calling a global function with example usage: _make_converter(K) and returns: converter, res