(define heron-sqrt - PowerPoint PPT Presentation

1 / 2
About This Presentation
Title:

(define heron-sqrt

Description:

(define heron-sqrt (lambda (x) ;Try some guess for sqrt(x)--we always pick 1. (try 1 x) ... (abs (- (square guess) x)) 0.0001))) (define improve ;average guess ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 3
Provided by: dexter8
Category:
Tags: define | heron | sqrt

less

Transcript and Presenter's Notes

Title: (define heron-sqrt


1
(define heron-sqrt (lambda (x) Try some
guess for sqrt(x)--we always pick 1. (try 1
x))) (define try (lambda (guess x) If the
guess is good enough (if (good-enough? guess
x) then stop and return the old guess
guess otherwise, try an improved
guess. (try (improve guess x)
x)))) (define good-enough? (lambda (guess x)
(lt (abs (- (square guess) x))
0.0001))) (define improve average guess and
x/guess. (lambda (guess x) (/ ( guess (/ x
guess)) 2.0))) (define square (lambda (x) ( x
x)))
2
  • The Substitution Model
  • To evaluate a combination (other than a special
    form)
  • evaluate the subexpressions of the combination
    from left to right
  • apply the leftmost value (which must be a
    function object) to the remaining values.
  • To apply a function to a list of values
  • substitute each value for the corresponding
    parameter in the body of the function
  • evaluate the body of the function.
Write a Comment
User Comments (0)
About PowerShow.com