code: def K(dim=4, dfn=7, dfd=np.inf):
      r"""
      Determine the polynomial K in:
  
          Worsley, K.J. (1994). 'Local maxima and the expected Euler
          characteristic of excursion sets of \chi^2, F and t fields.' Advances in
          Applied Probability, 26:13-42.
  
      If dfd=inf, return the limiting polynomial.
      """
  
      def lbinom(n, j):
          return gammaln(n + 1) - gammaln(j + 1) - gammaln(n - j + 1)
  
      m = dfd
      n = dfn
      D = dim
      k = np.arange(D)
      coef = 0
      for j in range(int(np.floor((D - 1) / 2.0) + 1)):
          if np.isfinite(m):
              t = (
                  gammaln((m + n - D) / 2.0 + j)
                  - gammaln(j + 1)
                  - gammaln((m + n - D) / 2.0)
              )
              t += lbinom(m - 1, k - j) - k * np.log(m)
          else:
              _t = np.power(2.0, -j) / (factorial(k - j) * factorial(j))
              t = np.log(_t)
              t[np.isinf(_t)] = -np.inf
          t += lbinom(n - 1, D - 1 - j - k)
          coef += (
              (-1) ** (D - 1)
              * factorial(D - 1)
              * np.exp(t)
              * np.power(-1.0 * n, k)
          )
      return np.poly1d(coef[::-1])
  
imports: import numpy
  import scipy.stats
  from scipy.special import gammaln, hermitenorm
  import pytest
  from numpy.testing import assert_almost_equal
  from ..None import rft
label_desc: Use image node_id 2 for calling a global function with example usage: K(dim, dfn, dfd) and returns: np, unknown