This file contains 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 (p) (p)) ;; P is a recursive function which does not end. | |
(defun (text x y)) | |
(if (= x 0) | |
0 | |
y)) | |
(test 0 (p)) | |
This file contains 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
; Ex 1.5 Normal order vs applicative order | |
(defun p () | |
(p)) | |
(defun test (x y) | |
(if (= x 0) | |
y | |
(p))) |
This file contains 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
(defun square-root (x) | |
(labels ( | |
(try (guess) | |
(if (good-enough? guess) | |
guess | |
(try (improve guess))) | |
) | |
(good-enough? (guess) | |
(if (< (abs (- guess (/ x guess))) (eps)) guess nil )) | |
(eps () |
This file contains 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 (new-if predicate then-clause else-clause) | |
(cond (predicate then-clause) | |
(else else-clause))) | |
(define (p) (p)) | |
(define (new-test x) | |
(new-if (= x 0) | |
1 | |
(p))) |
This file contains 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 (p) (p)) | |
(define (test x) | |
(if (= x 0) | |
1 | |
(p))) |
This file contains 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 (new-if predicate then-clause else-clause) | |
(cond (predicate then-clause) | |
(else else-clause))) | |
(define (sqrt-iter guess x) | |
(new-if (good-enough? guess x) | |
guess | |
(sqrt-iter (improve guess x) | |
x))) |
This file contains 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
(defun square-root (x) | |
(labels ( | |
(try (guess) | |
(if (good-enough? guess) | |
guess | |
(try (improve guess)))) | |
(good-enough? (guess) | |
(if (< (abs (- guess (/ x guess))) eps) guess nil )) | |
(improve (guess) | |
(average guess (/ x guess)))) |
This file contains 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
(defun my-sqrt (x) | |
(labels ( | |
(try (guess) | |
(let ((improved (improve guess))) | |
(if (good-enough? guess improved) | |
improved | |
(try improved)))) | |
(improve (guess) | |
(average guess (/ x guess))) | |
(good-enough? ( guess improved) |
This file contains 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
(defun my-cube-rt (x) | |
(labels ( | |
(try (guess) | |
(let ((improved (improve guess))) | |
(if (good-enough? guess improved) | |
improved | |
(try improved)))) | |
(improve (guess) | |
(/ (+ (/ x (square guess)) (* 2 guess)) 3)) | |
(good-enough? ( guess improved) |
This file contains 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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <math.h> | |
#define EPS 0.0001 | |
float average (float x, float y) ; | |
float improve (float guess, float x) ; | |
int good_enough (float guess, float x) ; | |
float my_square_root (float x, float guess) ; | |
float square (float x) ; |
OlderNewer