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 a desired precision `p` in bits, estimate the degree `m`
  of the quadrature required to accomplish full accuracy for
  typical integrals. By default, :func:`~mpmath.quad` will perform up
  to `m` iterations. The value of `m` should be a slight
  overestimate, so that "slightly bad" integrals can be dealt
  with automatically using a few extra iterations. On the
  other hand, it should not be too big, so :func:`~mpmath.quad` can
  quit within a reasonable amount of time when it is given
  an "unsolvable" integral.
  
  The default formula used by :func:`~mpmath.guess_degree` is tuned
  for both :class:`TanhSinh` and :class:`GaussLegendre`.
  The output is roughly as follows:
  
      +---------+---------+
      | `p`     | `m`     |
      +=========+=========+
      | 50      | 6       |
      +---------+---------+
      | 100     | 7       |
      +---------+---------+
      | 500     | 10      |
      +---------+---------+
      | 3000    | 12      |
      +---------+---------+
  
  This formula is based purely on a limited amount of
  experimentation and will sometimes be wrong.
docstr_tok: ["Given","a","desired","precision","`","p","`","in","bits",",","estimate","the","degree","`","m","`","of","the","quadrature","required","to","accomplish","full","accuracy","for","typical","integrals",".","By","default",",",":","func",":","`","~mpmath.quad","`","will","perform","up","to","`","m","`","iterations",".","The","value","of","`","m","`","should","be","a","slight","overestimate",",","so","that","``","slightly","bad","''","integrals","can","be","dealt","with","automatically","using","a","few","extra","iterations",".","On","the","other","hand",",","it","should","not","be","too","big",",","so",":","func",":","`","~mpmath.quad","`","can","quit","within","a","reasonable","amount","of","time","when","it","is","given","an","``","unsolvable","''","integral",".","The","default","formula","used","by",":","func",":","`","~mpmath.guess_degree","`","is","tuned","for","both",":","class",":","`","TanhSinh","`","and",":","class",":","`","GaussLegendre","`",".","The","output","is","roughly","as","follows",":","+","--","--","--","--","-+","--","--","--","--","-+","|","`","p","`","|","`","m","`","|","+=========+=========+","|","50","|","6","|","+","--","--","--","--","-+","--","--","--","--","-+","|","100","|","7","|","+","--","--","--","--","-+","--","--","--","--","-+","|","500","|","10","|","+","--","--","--","--","-+","--","--","--","--","-+","|","3000","|","12","|","+","--","--","--","--","-+","--","--","--","--","-+","This","formula","is","based","purely","on","a","limited","amount","of","experimentation","and","will","sometimes","be","wrong","."]
code: def guess_degree(self, prec):
      """
      Given a desired precision `p` in bits, estimate the degree `m`
      of the quadrature required to accomplish full accuracy for
      typical integrals. By default, :func:`~mpmath.quad` will perform up
      to `m` iterations. The value of `m` should be a slight
      overestimate, so that "slightly bad" integrals can be dealt
      with automatically using a few extra iterations. On the
      other hand, it should not be too big, so :func:`~mpmath.quad` can
      quit within a reasonable amount of time when it is given
      an "unsolvable" integral.
  
      The default formula used by :func:`~mpmath.guess_degree` is tuned
      for both :class:`TanhSinh` and :class:`GaussLegendre`.
      The output is roughly as follows:
  
          +---------+---------+
          | `p`     | `m`     |
          +=========+=========+
          | 50      | 6       |
          +---------+---------+
          | 100     | 7       |
          +---------+---------+
          | 500     | 10      |
          +---------+---------+
          | 3000    | 12      |
          +---------+---------+
  
      This formula is based purely on a limited amount of
      experimentation and will sometimes be wrong.
      """
      # Expected degree
      # XXX: use mag
      g = int(4 + max(0, self.ctx.log(prec / 30.0, 2)))
      # Reasonable "worst case"
      g += 2
      return g
  
imports: import math
  from ..libmp.backend import xrange
label_desc: Use image node_id 6 for calling the QuadratureRule obj's underlying member method code with example usage: obj.guess_degree(prec) and returns: g