11.001001000011111101101010100010001000 Arithmazium
Home

This is an automatically generated file.

Part 1

Part 2

def e_squared():
    """Compute exp(2) from the Taylor series for exp(x).

    We compute exp(1/2) and square it twice.
    exp(1/2) = 1 + 1/2 + 1/8 + 1/48 + 1/(48*2*4) + 1/(48*4*4*5) + ...
             = 13/8 + 1/48 * (1 + 1/8 + 1/80 + 1/960 + ...)
    Compute the sum as a two-piece hi/lo accumulation and then
    evaluate 13/8 + sum/48.

    Basic 5320-5350
    """

Part 3

    # Initialize the loop values so that the first term is 1, addied
    # into the initial sum of zero.
    x = ZERO
    k = 2
    term = TWO * THREE
    x_lo = ZERO
    if verbose:
        print("Loop to compute 1/48th the sum of terms 3 to k")
        print("of the Taylor series of exp(1/2).")
    while True:
        old_x = x
        k = k + 1
        term = term / (k + k)
        inc = x_lo + term
        x = old_x + inc
        # After adding the next term into the sum, capture x_lo, the
        # amount of inc that is not captured by x.
        x_lo = (old_x - x) + inc
        if verbose:
            print("\texp2 x={:.6e} x_lo={:.6e} term={:.6e}"
                  .format(x, x_lo, term))
        # Exit the loop when the value x is no longer changing.
        if x <= old_x: break

Part 4

    e12 = (ONE_AND_HALF + ONE / EIGHT) + x / (ONE_AND_HALF * THIRTY_TWO)
    e = e12 * e12
    e2 = e * e
    if verbose:
        print("exp(1/2) = {:.12f}  exp(1) = {:.12f}  exp(2) = {:.12f}"
              .format(e12, e, e2))
    return e2


Part 5

Home