diff options
author | David Thompson <dthompson2@worcester.edu> | 2022-12-06 08:09:31 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2022-12-06 08:09:31 -0500 |
commit | 6af6f15aedd85c59185b68bae0a9361b575f55fa (patch) | |
tree | 4a47eb2d6afbc13563f94d382a7258912a8116a5 | |
parent | 2505a8cad55dda8a066258cb50ac2f64989fb9f3 (diff) |
Add beginnings of Chapter 3 material.
-rw-r--r-- | chapter-3/3.1-combining-arithmetics.scm | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/chapter-3/3.1-combining-arithmetics.scm b/chapter-3/3.1-combining-arithmetics.scm new file mode 100644 index 0000000..08210b9 --- /dev/null +++ b/chapter-3/3.1-combining-arithmetics.scm @@ -0,0 +1,43 @@ +;;; Copyright © 2021 Gerald Sussman and Chris Hanson +;;; Copyright © 2022 David Thompson <dthompson2@worcester.edu> +;;; +;;; This program is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see +;;; <http://www.gnu.org/licenses/>. + +(define (stormer-2 F h) + (lambda (history) + (+ (* 2 (x 0 history)) + (* -1 (x 1 history)) + (* (/ (expt h 2) 12) + (+ (* 13 (F (t 0 history) (x 0 history))) + (* -2 (F (t 1 history) (x 1 history))) + (F (t 2 history) (x 2 history))))))) + +(define (stepper h integrator) + (lambda (history) + (extend-history (+ (t 0 history) h) + (integrator history) + history))) + +(define n:> >) +(define n:- -) + +(define (evolver F h make-integrator) + (let* ((integrator (make-integrator F h)) + (step (stepper h integrator))) + (define (evolve history n-steps) + (if (n:> n-steps 0) + (evolve (step history) (n:- n-steps 1)) + history)) + evolve)) |