Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-advanced-reader.ss" "lang")((modname |31.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 ;sum-2 : (listof numbers) -> number
5 (define (sum-1 alon)
6 (cond
7 [(empty? alon) 0]
8 [else (+ (first alon)
9 (sum-1 (rest alon)))]))
11 ;sum-2 : (listof numbers) -> number
13 ;sum-a : (listof numbers) number -> number
15 (define (sum-2 alon)
16 (local ;;accumulator represents the sum of all the numbers preceding alon in alon0
17 ((define (sum-a alon accumulator)
18 (cond
19 [(empty? alon) accumulator]
20 [else (sum-a (rest alon) (+ (first alon) accumulator))])))
21 (sum-a alon 0)))
23 (define (g-series n)
24 (cond
25 [(zero? n) empty]
26 [else (cons (expt -0.99 n) (g-series (sub1 n)))]))
28 (sum-1 (g-series #i100000))
29 (sum-2 (g-series #i100000))
31 (* 10e15 (sum-1 (g-series #i100000)))
32 (* 10e15 (sum-2 (g-series #i100000)))
34 ;right->left has errors (abs much larger than 0)
35 ;left->right is zero
36 ;But strange, not what I predicted