; Golden ratio: ; phi/(1 + phi) = 1/phi ; => phi^2 = 1 + phi ; => phi^2 - phi - 1 = 0 ; Let y be a fixed point of x -> 1 + 1/x ; Then y = 1 + 1/y => y^2 = y + 1 => y^2 - y - 1 = 0 => phi is a fixed point (define tolerance 0.00001) (define (fixed-point f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess) (let ((next (f guess))) (if (close-enough? next guess) next (try next)))) (try first-guess)) (define phi (fixed-point (lambda (x) (+ 1.0 (/ 1.0 x))) 1)) ; 1 ]=> phi ; ; ;Value: 1.6180327868852458 ; ; 1 ]=> (/ 1 phi) ; ; ;Value: .6180344478216819 ; ; 1 ]=> (/ phi (+ 1 phi)) ; ; ;Value: .6180338134001252 ; ; 1 ]=> (- (* phi phi) phi 1) ; ; ;Value: -2.687449610405679e-6