(define (heron-sqrt <function>) - PowerPoint PPT Presentation

1 / 2
About This Presentation
Title:

(define (heron-sqrt <function>)

Description:

Try some guess for sqrt(x)--we always pick 1. (try 1 x))) (define (try function ... (method ((guess number ) (x number )) ( (abs (- (square guess) x)) 0.0001) ... – PowerPoint PPT presentation

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

less

Transcript and Presenter's Notes

Title: (define (heron-sqrt <function>)


1
(define (heron-sqrt ltfunctiongt) (method ((x
ltnumbergt)) Try some guess for sqrt(x)--we
always pick 1. (try 1 x))) (define (try
ltfunctiongt) (method ((guess ltnumbergt) (x
ltnumbergt)) 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?
ltfunctiongt) (method ((guess ltnumbergt) (x
ltnumbergt)) (lt (abs (- (square guess) x))
0.0001))) (define (improve ltfunctiongt) (method
((guess ltnumbergt) (x ltnumbergt)) (/ ( guess
(/ x guess)) 2.0))) (define (square ltfunctiongt)
(method ((x ltnumbergt)) ( 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