def altseriesaccel(a, n):
    """
    Convergence acceleration for alternating series.  This is Algorithm 1 from
    /Convergence Acceleration of Alternating Series/ by Cohen, Villegas, and
    Zagier, with a minor tweak so that the d-value isn't computed via floating
    point.  The article is available at
    https://people.mpim-bonn.mpg.de/zagier/files/exp-math-9/fulltext.pdf.
    Input:
        a -- an iterable.  The series to be summed is a[0] - a[1] + a[2] - ...
        n -- the number of terms to use.  A couple dozen terms is probably good.
    Output: a floating-point number.
    Examples:
    """
    Vl, Vh = 2, 6
    for bit in bin(n)[2:]:
        Vl, Vh = (Vh * Vl - 6, Vh * Vh - 2) if bit == '1' else (Vl * Vl - 2,
            Vh * Vl - 6)
    d = Vl // 2
    b, c, s = -1, -d, 0
    for k in range(n):
        c = b - c
        s = s + c * next(a)
        b = (k + n) * (k - n) * b / ((k + 0.5) * (k + 1))
    return s / d
