diff options
| author | Steve Lee <me@xiangyangli.com> | 2017-12-02 06:10:20 +0800 |
|---|---|---|
| committer | Steve Lee <me@xiangyangli.com> | 2017-12-02 06:10:20 +0800 |
| commit | 9b939e65cf007e859dabe5de6b31d255d647e0ce (patch) | |
| tree | bf9229755f4e58bb81add73c7f3c32fe4023e7ec /Computer_Science/SICP/ch1_3.scm | |
| parent | 5dc061ae68ac3b5b28556bdbd1574579d8da33e7 (diff) | |
| download | 42-9b939e65cf007e859dabe5de6b31d255d647e0ce.tar.xz 42-9b939e65cf007e859dabe5de6b31d255d647e0ce.zip | |
category
Diffstat (limited to 'Computer_Science/SICP/ch1_3.scm')
| -rw-r--r-- | Computer_Science/SICP/ch1_3.scm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Computer_Science/SICP/ch1_3.scm b/Computer_Science/SICP/ch1_3.scm new file mode 100644 index 0000000..76fadb7 --- /dev/null +++ b/Computer_Science/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) |
