From 9ee91c759c5a87030cebb6b79adc94230f23da4a Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 19 Apr 2017 22:43:18 +0800 Subject: remove --- SICP/ch1_3.scm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 SICP/ch1_3.scm (limited to 'SICP') diff --git a/SICP/ch1_3.scm b/SICP/ch1_3.scm new file mode 100644 index 0000000..76fadb7 --- /dev/null +++ b/SICP/ch1_3.scm @@ -0,0 +1,33 @@ +(define (cube x) (* x x x)) + +;; Sum from a to b. + +(define (sum term a next b) + (if (> a b ) + 0 + (+ (term a) + (sum term (next a) next b)))) + +(define (inc n) (+ n 1)) +(define (sum-cubes a b) + (sum cube a inc b)) + +(sum-cubes 1 10) + +(define (identity x) x) +(define (sum-integers a b) + (sum identity a inc b)) +(sum-integers 1 10) + +(define (pi-sum a b) + (define (pi-term x) + (/ 1.0 (* x (+ x 2)))) + (define (pi-next x) + (+ x 4)) +(* 8 (sum pi-term a pi-next b))) +(pi-sum 1 1000) + +(define (intergral f a b dx) + (define (add-dx x) (+ x dx)) + (* (sum f (+ a (/ dx 2.0)) add-dx b) dx)) +(intergral cube 0 1 0.0001) -- cgit v1.2.3