; recognizing fibonacci numbers

  (define (square? n)
    (define (isqrt n)
      (if (not (and (positive? n) (integer? n)))
          (error 'isqrt "must be positive integer")
          (let loop ((x n))
            (let ((y (quotient (+ x (quotient n x)) 2)))
              (if (< y x) (loop y) x)))))
    (let ((x (isqrt n)))
      (= (* x x) n)))

(define (fibonacci? x)
  (if (< x 1) #f
    (let loop ((prev 1) (fib 1))
      (if (< fib x) (loop fib (+ fib prev))
        (= fib x)))))

(display (fibonacci? 13)) (newline)
(display (fibonacci? 15)) (newline)

(define (fibonacci? x)
  (let ((5xx (* 5 x x)))
    (or (square? (+ 5xx 4))
        (square? (- 5xx 4)))))

(display (fibonacci? 13)) (newline)
(display (fibonacci? 15)) (newline)