class_docstr: Quadrature rules are implemented using this class, in order to
  simplify the code and provide a common infrastructure
  for tasks such as error estimation and node caching.
  
  You can implement a custom quadrature rule by subclassing
  :class:`QuadratureRule` and implementing the appropriate
  methods. The subclass can then be used by :func:`~mpmath.quad` by
  passing it as the *method* argument.
  
  :class:`QuadratureRule` instances are supposed to be singletons.
  :class:`QuadratureRule` therefore implements instance caching
  in :func:`~mpmath.__new__`.
class_docstr_tok: ["Quadrature","rules","are","implemented","using","this","class",",","in","order","to","simplify","the","code","and","provide","a","common","infrastructure","for","tasks","such","as","error","estimation","and","node","caching",".","You","can","implement","a","custom","quadrature","rule","by","subclassing",":","class",":","`","QuadratureRule","`","and","implementing","the","appropriate","methods",".","The","subclass","can","then","be","used","by",":","func",":","`","~mpmath.quad","`","by","passing","it","as","the","*","method","*","argument",".",":","class",":","`","QuadratureRule","`","instances","are","supposed","to","be","singletons",".",":","class",":","`","QuadratureRule","`","therefore","implements","instance","caching","in",":","func",":","`","~mpmath.__new__","`","."]
docstr: Given results from integrations `[I_1, I_2, \ldots, I_k]` done
  with a quadrature of rule of degree `1, 2, \ldots, k`, estimate
  the error of `I_k`.
  
  For `k = 2`, we estimate  `|I_{\infty}-I_2|` as `|I_2-I_1|`.
  
  For `k > 2`, we extrapolate `|I_{\infty}-I_k| \approx |I_{k+1}-I_k|`
  from `|I_k-I_{k-1}|` and `|I_k-I_{k-2}|` under the assumption
  that each degree increment roughly doubles the accuracy of
  the quadrature rule (this is true for both :class:`TanhSinh`
  and :class:`GaussLegendre`). The extrapolation formula is given
  by Borwein, Bailey & Girgensohn. Although not very conservative,
  this method seems to be very robust in practice.
docstr_tok: ["Given","results","from","integrations","`","[","I_1",",","I_2",",","\\ldots",",","I_k","]","`","done","with","a","quadrature","of","rule","of","degree","`","1",",","2",",","\\ldots",",","k","`",",","estimate","the","error","of","`","I_k","`",".","For","`","k","=","2","`",",","we","estimate","`","|I_","{","\\infty","}","-I_2|","`","as","`","|I_2-I_1|","`",".","For","`","k",">","2","`",",","we","extrapolate","`","|I_","{","\\infty","}","-I_k|","\\approx","|I_","{","k+1","}","-I_k|","`","from","`","|I_k-I_","{","k-1","}","|","`","and","`","|I_k-I_","{","k-2","}","|","`","under","the","assumption","that","each","degree","increment","roughly","doubles","the","accuracy","of","the","quadrature","rule","(","this","is","true","for","both",":","class",":","`","TanhSinh","`","and",":","class",":","`","GaussLegendre","`",")",".","The","extrapolation","formula","is","given","by","Borwein",",","Bailey","&","Girgensohn",".","Although","not","very","conservative",",","this","method","seems","to","be","very","robust","in","practice","."]
code: def estimate_error(self, results, prec, epsilon):
      r"""
      Given results from integrations `[I_1, I_2, \ldots, I_k]` done
      with a quadrature of rule of degree `1, 2, \ldots, k`, estimate
      the error of `I_k`.
  
      For `k = 2`, we estimate  `|I_{\infty}-I_2|` as `|I_2-I_1|`.
  
      For `k > 2`, we extrapolate `|I_{\infty}-I_k| \approx |I_{k+1}-I_k|`
      from `|I_k-I_{k-1}|` and `|I_k-I_{k-2}|` under the assumption
      that each degree increment roughly doubles the accuracy of
      the quadrature rule (this is true for both :class:`TanhSinh`
      and :class:`GaussLegendre`). The extrapolation formula is given
      by Borwein, Bailey & Girgensohn. Although not very conservative,
      this method seems to be very robust in practice.
      """
      if len(results) == 2:
          return abs(results[0] - results[1])
      try:
          if results[-1] == results[-2] == results[-3]:
              return self.ctx.zero
          D1 = self.ctx.log(abs(results[-1] - results[-2]), 10)
          D2 = self.ctx.log(abs(results[-1] - results[-3]), 10)
      except ValueError:
          return epsilon
      D3 = -prec
      D4 = min(0, max(D1**2 / D2, 2 * D1, D3))
      return self.ctx.mpf(10) ** int(D4)
  
imports: import math
  from ..libmp.backend import xrange
label_desc: Use image node_id 7 for calling the QuadratureRule obj's underlying member method code with example usage: obj.estimate_error(results, prec, epsilon) and returns: unknown, abs, self, epsilon