From 6af6f15aedd85c59185b68bae0a9361b575f55fa Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 6 Dec 2022 08:09:31 -0500 Subject: Add beginnings of Chapter 3 material. --- chapter-3/3.1-combining-arithmetics.scm | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 chapter-3/3.1-combining-arithmetics.scm 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 +;;; +;;; 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 +;;; . + +(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)) -- cgit v1.2.3