diff options
Diffstat (limited to 'root.scm')
-rw-r--r-- | root.scm | 28 |
1 files changed, 0 insertions, 28 deletions
@@ -46,34 +46,6 @@ ;; (lambda (x) (* 2 x)) ;; (ash 1 (quotient (integer-length y) 2)))) -;;;; http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/math/isqrt/isqrt.txt -;;; Akira Kurihara -;;; School of Mathematics -;;; Japan Women's University -;@ -(define integer-sqrt - (let ((table '#(0 - 1 1 1 - 2 2 2 2 2 - 3 3 3 3 3 3 3 - 4 4 4 4 4 4 4 4 4)) - (square (lambda (x) (* x x)))) - (lambda (n) - (define (isqrt n) - (if (> n 24) - (let* ((len/4 (quotient (- (integer-length n) 1) 4)) - (top (isqrt (ash n (* -2 len/4)))) - (init (ash top len/4)) - (q (quotient n init)) - (iter (quotient (+ init q) 2))) - (cond ((odd? q) iter) - ((< (remainder n init) (square (- iter init))) (- iter 1)) - (else iter))) - (vector-ref table n))) - (if (and (exact? n) (integer? n) (not (negative? n))) - (isqrt n) - (type-error 'integer-sqrt n))))) - ;@ (define (newton:find-root f df/dx x_0 prec) (if (and (negative? prec) (integer? prec)) |