code: def lchisqprob(chisq,df):
      
      BIG = 20.0
      def ex(x):
          BIG = 20.0
          if x < -BIG:
              return 0.0
          else:
              return math.exp(x)
  
      if chisq <=0 or df < 1:
          return 1.0
      a = 0.5 * chisq
      if df%2 == 0:
          even = 1
      else:
          even = 0
      if df > 1:
          y = ex(-a)
      if even:
          s = y
      else:
          s = 2.0 * zprob(-math.sqrt(chisq))
      if (df > 2):
          chisq = 0.5 * (df - 1.0)
          if even:
              z = 1.0
          else:
              z = 0.5
          if a > BIG:
              if even:
                  e = 0.0
              else:
                  e = math.log(math.sqrt(math.pi))
              c = math.log(a)
              while (z <= chisq):
                  e = math.log(z) + e
                  s = s + ex(c*z-a-e)
                  z = z + 1.0
              return s
          else:
              if even:
                  e = 1.0
              else:
                  e = 1.0 / math.sqrt(math.pi) / math.sqrt(a)
              c = 0.0
              while (z <= chisq):
                  e = e * (a/float(z))
                  c = c + e
                  z = z + 1.0
              return (c*y+s)
      else:
          return s
docs: Returns the (1-tailed) probability value associated with the provided
  chi-square value and df.  Adapted from chisq.c in Gary Perlman's |Stat.
  
  Usage:   lchisqprob(chisq,df)