%%HP: T(3)A(R)F(.);
\<< CLLCD
    @
    "HP 48G: Riemann Sums" 2 DISP
    @
    "  Copyright (c) 1995" 4 DISP
    "    by Jack Courtney" 5 DISP
    " All Rights Reserved" 6 DISP
    @
    @ Calculates the following Riemann Sums:
    @
    @   Left Hand 
    @   Right Hand
    @   Trapezoidal (as the average of LH and RH)
    @   Mid Point
    @   Simpson's (as the weighted average of MP & Trap)
    @
    @   Note: As a consequence of the method of calculation,
    @         Simpson's rule uses 2*n+1 sample points; i.e.,
    @         the endpoints plus the midpoints of each strip.
    @
    @ The integrand must be contained in 'EQ'
    @ 
    @ Stack On Entry:
    @
    @   LEVEL 5: The integrand
    @   LEVEL 4: The variable of integration
    @   LEVEL 3: 'a', the left end point of the interval of integration 
    @   LEVEL 2: 'b', the right end point of the interval of integration 
    @   LEVEL 1: 'n', the number of non-overlapping strips of equal width covering [a,b]  
    @
    @ Usage example:
    @
    @  'X^2' 'X' -1 2 7 [RSUM]
    @
    \-> a b n
    \<<
        INDEP 
        STEQ
        b a - n /
        \-> h
        \<< a b XRNG
            'X' 'X' a b h SEQ 
            DUP 1 \<<RCEQ x xR 2 \->LIST | \->NUM \>> DOLIST 
            DUP TAIL \GSLIST h *           @ LH sum
            SWAP REVLIST TAIL \GSLIST h *  @ RH sum
            DUP2 + 2 /                     @ Trap sum
            "Trapezoidal Sum" \->TAG ROT
            "Left Hand Sum"   \->TAG ROT
            "Right Hand Sum"  \->TAG ROT 
            4 ROLL 
            DUP TAIL 
            SWAP REVLIST TAIL REVLIST 
            ADD 2 / 
            1 \<< RCEQ 'PPAR' 3 GET ROT 2 \->LIST | \->NUM \>> DOLIST
            \GSLIST h *                    @ MP sum
            DUP
            "Mid Point Sum"   \->TAG  
            SWAP 2 * 3 PICK DTAG + 3 /     @ Simp sum
            "Simpson's Sum"   \->TAG
        \>>
    \>>    
\>>
    