code: def cancel_primitive(b, c, n, DE):
      """
      Poly Risch Differential Equation - Cancellation: Primitive case.
  
      Explanation
      ===========
  
      Given a derivation D on k[t], n either an integer or +oo, ``b`` in k, and
      ``c`` in k[t] with Dt in k and ``b != 0``, either raise
      NonElementaryIntegralException, in which case the equation Dq + b*q == c
      has no solution of degree at most n in k[t], or a solution q in k[t] of
      this equation with deg(q) <= n.
      """
      # Delayed imports
      from .prde import is_log_deriv_k_t_radical_in_field
  
      with DecrementLevel(DE):
          ba, bd = frac_in(b, DE.t)
          A = is_log_deriv_k_t_radical_in_field(ba, bd, DE)
          if A is not None:
              n, z = A
              if n == 1:  # b == Dz/z
                  raise NotImplementedError(
                      "is_deriv_in_field() is required to "
                      " solve this problem."
                  )
                  # if z*c == Dp for p in k[t] and deg(p) <= n:
                  #     return p/z
                  # else:
                  #     raise NonElementaryIntegralException
  
      if c.is_zero:
          return c  # return 0
  
      if n < c.degree(DE.t):
          raise NonElementaryIntegralException
  
      q = Poly(0, DE.t)
      while not c.is_zero:
          m = c.degree(DE.t)
          if n < m:
              raise NonElementaryIntegralException
          with DecrementLevel(DE):
              a2a, a2d = frac_in(c.LC(), DE.t)
              sa, sd = rischDE(ba, bd, a2a, a2d, DE)
          stm = Poly(
              sa.as_expr() / sd.as_expr() * DE.t**m,
              DE.t,
              expand=False,
          )
          q += stm
          n = m - 1
          c -= b * stm + derivation(stm, DE)
  
      return q
  
imports: from operator import mul
  from functools import reduce
  from sympy.core import oo
  from sympy.core.symbol import Dummy
  from sympy.polys import Poly, gcd, ZZ, cancel
  from sympy.functions.elementary.complexes import im, re
  from sympy.functions.elementary.miscellaneous import sqrt
  from sympy.integrals.risch import gcdex_diophantine, frac_in, derivation, splitfactor, NonElementaryIntegralException, DecrementLevel, recognize_log_derivative
label_desc: Use image node_id 11 for calling a global function with example usage: cancel_primitive(b, c, n, DE) and returns: q, c