This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (square x) | |
(* x x)) | |
(define (sum-of-squares x y) | |
(+ (square x) (square y))) | |
(define (sum-of-highest-squares x y z) | |
(cond ((< x y z) (sum-of-squares y z)) | |
((< y z x) (sum-of-squares z x)) | |
((< z x y) (sum-of-squares x y)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;Re-written version of the code | |
(define (a-plus-abs-b a b) | |
(if (> b 0) | |
(+ a b) | |
(- a b))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(test 0 p) | |
;;;Applicative-order | |
(test 0 p) ;;; Substitute p with p | |
(test 0 p) ;;; Substitute p with p | |
(test 0 p) ;;; Substitute p with p | |
;;;Normal order | |
(test 0 p) | |
(if (= 0 0) 0 p) ;;;p's value not needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (square x) (* x x)) | |
(define (average x y) | |
(/ (+ x y) 2)) | |
(define (improve guess x) | |
(average guess (/ x guess))) | |
;;; Newly implemented guess | |
;;; Good enough when |guess - improved-guess|/guess < 0.001 (0.1%) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (square x) (* x x)) | |
(define (improve guess x) | |
(/ (+ (/ x (square guess)) (* 2 guess)) 3)) | |
(define (good-enough? guess improved-guess x) | |
(< (/ (abs (- guess improved-guess)) guess) 0.001)) | |
(define (cubic-root-iter guess x) | |
(if (good-enough? guess (improve guess x) x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; First process | |
(+ 4 5) | |
(inc (+ 3 5)) | |
(inc (inc (+ 2 5))) | |
(inc (inc (inc (+ 1 5)))) | |
(inc (inc (inc (inc (+ 0 5))))) | |
(inc (inc (inc (inc 5)))) | |
(inc (inc (inc 6))) | |
(inc (inc 7)) | |
(inc 8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;(A 1 10) | |
(A 0 (A 1 9) | |
(* 2 (A 0 (A 1 8))) | |
(* 2 (* 2 (A 0 (A 1 7)))) | |
(* 2 (* 2 (* 2 (A 0 (A 1 6))))) | |
(* 2 (* 2 (* 2 (* 2 (A 0 (A 1 5)))))) | |
(* 2 (* 2 (* 2 (* 2 (* 2 (A 0 (A 1 4))))))) | |
(* 2 (* 2 (* 2 (* 2 (* 2 (* 2 (A 0 (A 1 3)))))))) | |
(* 2 (* 2 (* 2 (* 2 (* 2 (* 2 (* 2 (A 0 (A 1 2))))))))) | |
(* 2 (* 2 (* 2 (* 2 (* 2 (* 2 (* 2 (* 2 (A 0 (A 1 1)))))))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;(A 2 4) | |
;;; We know that (A 1 n) = 2^n, so steps to evaluate (A 1 n) are omitted here. | |
(A 1 (A 2 3)) | |
(A 1 (A 1 (A 2 2))) | |
(A 1 (A 1 (A 1 (A 2 1)))) | |
(A 1 (A 1 (A 1 2))) | |
... | |
(A 1 (A 1 4)) | |
... | |
(A 1 16) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;(A 3 3) | |
;;; We know that (A 1 n) = 2^n, so steps to evaluate (A 1 n) are omitted here. | |
;;; We also know that (A 2 n) = 2^2^...n times, so steps to evaluate (A 2 n) are omitted here. | |
(A 3 3) | |
(A 2 (A 3 2)) | |
(A 2 (A 2 (A 3 1))) | |
(A 2 (A 2 2)) | |
... | |
(A 2 4) | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (f n) | |
(if (< n 3) | |
n | |
(+ (f (- n 1)) | |
(* 2 (f (- n 2))) | |
(* 3 (f (- n 3)))))) |
OlderNewer