@@ -0,0 +1,1791 @@
+## The solution of exercise 1.6%0A## Square roots by Newton's method%0A##%0A## As a case in point, consider the problem of computing square roots.%0A## We can define the square-root function as:%0A##     square(x) = the y, such that y %3E= 0 and y%5E2 = x%0A## This describes a perfectly legitimate mathematical function. We could%0A## use it to recognize whether one number is the square root of another,%0A## or to describe a procedure. Indeed, it tells us almost nothing about%0A## how to actually find the square root of a given number. It will not%0A## help matters to rephrase this definition in pseudo-Lisp:%0A## %0A##     (define (sqrt x)%0A##       (the y (and (%3E= y 0)%0A##                   (= (square y) x))))%0A##%0A## This only begs the question.%0A## -------- (above from SICP)%0A##%0A## How does one compute square roots? The most common way is to use%0A## Newton's method of successive approximations.%0A##%0A%0Adef average(x, y):%0A    return (x + y) / 2.0%0A%0Adef improve(guess, x):%0A    %22%22%22Improve guess.%0A    A guess is improved by averaging it with the quotient of the radicand%0A    and the old guess.%0A    %22%22%22%0A    return average(guess, x * 1.0 / guess)%0A%0A## It is important to point out what we mean by %60good enough%60. Here we%0A## give a simple illustration (but it is not really a very good test).%0A## The idea is to improve the answer until it is close enough so that its%0A## square differs from the radicand by less than a predetermined tolerance%0A## (here 0.0001 is set)%0A## See exercise_07.scm to get a better good-enough? test.%0Adef good_enough(guess, x):%0A    return abs(guess * guess - x) %3C 0.0001%0A%0Adef sqrt_iter(init, x):%0A    %22%22%22Compute the square root of x with initial value.%0A    Newton method is used here.%0A    %22%22%22%0A    guess = init%0A    while not good_enough(guess, x):%0A        guess = improve(guess, x)%0A    return guess%0A%0A%0A%0A%0A

Add exercise 1.6 (python)