Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #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 12687dd9 2023-08-04 jrmu ;sum-2 : (listof numbers) -> number
5 12687dd9 2023-08-04 jrmu (define (sum-1 alon)
6 12687dd9 2023-08-04 jrmu (cond
7 12687dd9 2023-08-04 jrmu [(empty? alon) 0]
8 12687dd9 2023-08-04 jrmu [else (+ (first alon)
9 12687dd9 2023-08-04 jrmu (sum-1 (rest alon)))]))
10 12687dd9 2023-08-04 jrmu
11 12687dd9 2023-08-04 jrmu ;sum-2 : (listof numbers) -> number
12 12687dd9 2023-08-04 jrmu
13 12687dd9 2023-08-04 jrmu ;sum-a : (listof numbers) number -> number
14 12687dd9 2023-08-04 jrmu
15 12687dd9 2023-08-04 jrmu (define (sum-2 alon)
16 12687dd9 2023-08-04 jrmu (local ;;accumulator represents the sum of all the numbers preceding alon in alon0
17 12687dd9 2023-08-04 jrmu ((define (sum-a alon accumulator)
18 12687dd9 2023-08-04 jrmu (cond
19 12687dd9 2023-08-04 jrmu [(empty? alon) accumulator]
20 12687dd9 2023-08-04 jrmu [else (sum-a (rest alon) (+ (first alon) accumulator))])))
21 12687dd9 2023-08-04 jrmu (sum-a alon 0)))
22 12687dd9 2023-08-04 jrmu
23 12687dd9 2023-08-04 jrmu (define (g-series n)
24 12687dd9 2023-08-04 jrmu (cond
25 12687dd9 2023-08-04 jrmu [(zero? n) empty]
26 12687dd9 2023-08-04 jrmu [else (cons (expt -0.99 n) (g-series (sub1 n)))]))
27 12687dd9 2023-08-04 jrmu
28 12687dd9 2023-08-04 jrmu (sum-1 (g-series #i100))
29 12687dd9 2023-08-04 jrmu (sum-2 (g-series #i100))
30 12687dd9 2023-08-04 jrmu
31 12687dd9 2023-08-04 jrmu (* 10e15 (sum-1 (g-series #i100)))
32 12687dd9 2023-08-04 jrmu (* 10e15 (sum-2 (g-series #i100)))
33 12687dd9 2023-08-04 jrmu
34 12687dd9 2023-08-04 jrmu ;right->left has errors (abs much larger than 0)
35 12687dd9 2023-08-04 jrmu ;left->right is zero
36 12687dd9 2023-08-04 jrmu ;But strange, not what I predicted