diff --git a/SICP/code05.tm b/SICP/code05.tm index 05d46ee..364dcdc 100644 --- a/SICP/code05.tm +++ b/SICP/code05.tm @@ -1,12 +1,14 @@ -> +> <\body> - <\session|scheme|default> - <\unfolded-io|Scheme] > + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> (define (expt-1 b n) \ \ (if (= n 0) @@ -18,19 +20,25 @@ expt-1 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (expt-1 1 0) <|unfolded-io> 1 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (expt-1 2 3) <|unfolded-io> 8 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (expt-2 b n) \ \ (define (expt-iter b counter product) @@ -52,21 +60,27 @@ expt-2 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (expt-2 3 3) <|unfolded-io> 27 - <\input|Scheme] > + <\input> + \\ + <|input> \; - <\session|scheme|default> - <\unfolded-io|Scheme] > + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> (define (fast-expt b n) \ \ (define (even? n) @@ -86,17 +100,27 @@ fast-expt - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (fast-expt 3 3) <|unfolded-io> 27 + + <\input> + \\ + <|input> + \; + - <\session|scheme|default> - <\unfolded-io|Scheme] > + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> (define (gcd a b) \ \ (if (= b 0) @@ -108,11 +132,19 @@ gcd - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (gcd 10 20) <|unfolded-io> 10 + + <\input> + \\ + <|input> + \; + @@ -128,4 +160,22 @@ > > - \ No newline at end of file + + +<\auxiliary> + <\collection> + <\associate|toc> + |math-font-series||Orders + of Growth> |.>>>>|> + + + |math-font-series||Exponentiation> + |.>>>>|> + + + |math-font-series||Greatest + Common Divisors> |.>>>>|> + + + + \ No newline at end of file diff --git a/SICP/code07.tm b/SICP/code07.tm index d3ee7f5..61c7ee3 100644 --- a/SICP/code07.tm +++ b/SICP/code07.tm @@ -1,18 +1,22 @@ -> +> <\body> - <\session|scheme|default> - <\unfolded-io|Scheme] > + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> (define (cube x) (* x x x)) <|unfolded-io> cube - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (sum-integers a b) \ \ (if (\ a b) @@ -24,7 +28,9 @@ sum-integers - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (sum-cubes a b) \ \ (if (\ a b) @@ -36,7 +42,9 @@ sum-cubes - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (pi-sum a b) \ \ (if (\ a b) @@ -48,25 +56,33 @@ pi-sum - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (sum-integers 1 3) <|unfolded-io> 6 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (sum-cubes 1 3) <|unfolded-io> 36 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (pi-sum 1 3) <|unfolded-io> 0.3333333333333333 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (sum term a next b) \ \ (if (\ a b) @@ -80,13 +96,17 @@ sum - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (inc n) (+ n 1)) <|unfolded-io> inc - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (sum-cubes-2 a b) \ \ (sum cube a inc b)) @@ -94,23 +114,25 @@ sum-cubes-2 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (sum-cubes-2 1 3) <|unfolded-io> 36 - <\input|Scheme] > - \; - - - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (identity x) x) <|unfolded-io> identity - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (sum-integers-2 a b) \ \ (sum identity a inc b)) @@ -118,13 +140,17 @@ sum-integers-2 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (sum-integers-2 1 10) <|unfolded-io> 55 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (pi-sum-2 a b) \ \ (define (pi-term x) @@ -140,47 +166,61 @@ pi-sum-2 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (* 8 (pi-sum-2 1 1000)) <|unfolded-io> 3.139592655589783 - <\input|Scheme] > + <\input> + \\ + <|input> \; - <\session|scheme|default> - <\unfolded-io|Scheme] > + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> (define (square x) (* x x)) <|unfolded-io> square - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> ((lambda (x y z) (+ x y (square z))) 1 2 3) <|unfolded-io> 12 - <\input|Scheme] > + <\input> + \\ + <|input> \; - <\session|scheme|default> - <\unfolded-io|Scheme] > + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> (define (average x y) (/ (+ x y) 2)) <|unfolded-io> average - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (search f neg-point pos-point) \ \ (let ((midpoint (average neg-point pos-point))) @@ -204,7 +244,9 @@ search - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (close-enough? x y) \ \ (\ (abs (- x y)) 0.001)) @@ -212,7 +254,9 @@ close-enough? - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (half-interval-method f a b) \ \ (let ((a-value (f a)) @@ -234,13 +278,17 @@ half-interval-method - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (half-interval-method sin 2.0 4.0) <|unfolded-io> 3.14111328125 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (half-interval-method (lambda (x) (- (* x x x) (* 2 x) 3)) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1.0 @@ -250,17 +298,17 @@ 1.89306640625 - <\input|Scheme] > - \; - - - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define tolerance 0.00001) <|unfolded-io> 0.00001 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (define (fixed-point f first-guess) \ \ (define (close-enough? v1 v2) @@ -282,13 +330,17 @@ fixed-point - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (fixed-point cos 1.0) <|unfolded-io> 0.7390822985224024 - <\unfolded-io|Scheme] > + <\unfolded-io> + \\ + <|unfolded-io> (fixed-point (lambda (y) (+ (sin y) (cos y))) \ \ \ \ \ \ \ \ \ \ \ \ \ 1.0) @@ -296,7 +348,9 @@ 1.2587315962971173 - <\input|Scheme] > + <\input> + \\ + <|input> \;