(self, degree, prec, verbose=False)
return nodes
r"""
        The abscissas and weights for tanh-sinh quadrature of degree
        `m` are given by

        .. math::

            x_k = \tanh(\pi/2 \sinh(t_k))

            w_k = \pi/2 \cosh(t_k) / \cosh(\pi/2 \sinh(t_k))^2

        where `t_k = t_0 + hk` for a step length `h \sim 2^{-m}`. The
        list of nodes is actually infinite, but the weights die off so
        rapidly that only a few are needed.
r"""
        The abscissas and weights for tanh-sinh quadrature of degree
        `m` are given by
r The abscissas and weights for tanh - sinh quadrature of degree m are given by
def calc_nodes(self, degree, prec, verbose=False):
        r"""
        The abscissas and weights for tanh-sinh quadrature of degree
        `m` are given by

        .. math::

            x_k = \tanh(\pi/2 \sinh(t_k))

            w_k = \pi/2 \cosh(t_k) / \cosh(\pi/2 \sinh(t_k))^2

        where `t_k = t_0 + hk` for a step length `h \sim 2^{-m}`. The
        list of nodes is actually infinite, but the weights die off so
        rapidly that only a few are needed.
        """
        ctx = self.ctx
        nodes = []

        extra = 20
        ctx.prec += extra
        tol = ctx.ldexp(1, -prec-10)
        pi4 = ctx.pi/4

        # For simplicity, we work in steps h = 1/2^n, with the first point
        # offset so that we can reuse the sum from the previous degree

        # We define degree 1 to include the "degree 0" steps, including
        # the point x = 0. (It doesn't work well otherwise; not sure why.)
        t0 = ctx.ldexp(1, -degree)
        if degree == 1:
            #nodes.append((mpf(0), pi4))
            #nodes.append((-mpf(0), pi4))
            nodes.append((ctx.zero, ctx.pi/2))
            h = t0
        else:
            h = t0*2

        # Since h is fixed, we can compute the next exponential
        # by simply multiplying by exp(h)
        expt0 = ctx.exp(t0)
        a = pi4 * expt0
        b = pi4 / expt0
        udelta = ctx.exp(h)
        urdelta = 1/udelta

        for k in xrange(0, 20*2**degree+1):
            # Reference implementation:
            # t = t0 + k*h
            # x = tanh(pi/2 * sinh(t))
            # w = pi/2 * cosh(t) / cosh(pi/2 * sinh(t))**2

            # Fast implementation. Note that c = exp(pi/2 * sinh(t))
            c = ctx.exp(a-b)
            d = 1/c
            co = (c+d)/2
            si = (c-d)/2
            x = si / co
            w = (a+b) / co**2
            diff = abs(x-1)
            if diff <= tol:
                break

            nodes.append((x, w))
            nodes.append((-x, w))

            a *= udelta
            b *= urdelta

            if verbose and k % 300 == 150:
                # Note: the number displayed is rather arbitrary. Should
                # figure out how to print something that looks more like a
                # percentage
                print("Calculating nodes:", ctx.nstr(-ctx.log(diff, 10) / prec))

        ctx.prec -= extra
        return nodes
def calc_nodes ( self , degree , prec , verbose = False ) : ctx = self . ctx nodes = [ ] extra = 20 ctx . prec += extra tol = ctx . ldexp ( 1 , - prec - 10 ) pi4 = ctx . pi / 4 # For simplicity, we work in steps h = 1/2^n, with the first point # offset so that we can reuse the sum from the previous degree # We define degree 1 to include the "degree 0" steps, including # the point x = 0. (It doesn't work well otherwise; not sure why.) t0 = ctx . ldexp ( 1 , - degree ) if degree == 1 : #nodes.append((mpf(0), pi4)) #nodes.append((-mpf(0), pi4)) nodes . append ( ( ctx . zero , ctx . pi / 2 ) ) h = t0 else : h = t0 * 2 # Since h is fixed, we can compute the next exponential # by simply multiplying by exp(h) expt0 = ctx . exp ( t0 ) a = pi4 * expt0 b = pi4 / expt0 udelta = ctx . exp ( h ) urdelta = 1 / udelta for k in xrange ( 0 , 20 * 2 ** degree + 1 ) : # Reference implementation: # t = t0 + k*h # x = tanh(pi/2 * sinh(t)) # w = pi/2 * cosh(t) / cosh(pi/2 * sinh(t))**2 # Fast implementation. Note that c = exp(pi/2 * sinh(t)) c = ctx . exp ( a - b ) d = 1 / c co = ( c + d ) / 2 si = ( c - d ) / 2 x = si / co w = ( a + b ) / co ** 2 diff = abs ( x - 1 ) if diff <= tol : break nodes . append ( ( x , w ) ) nodes . append ( ( - x , w ) ) a *= udelta b *= urdelta if verbose and k % 300 == 150 : # Note: the number displayed is rather arbitrary. Should # figure out how to print something that looks more like a # percentage print ( "Calculating nodes:" , ctx . nstr ( - ctx . log ( diff , 10 ) / prec ) ) ctx . prec -= extra return nodes