RosettaCodeData/Task/Nth-root/Common-Lisp/nth-root-1.lisp
2023-07-01 13:44:08 -04:00

9 lines
317 B
Common Lisp

(defun nth-root (n a &optional (epsilon .0001) (guess (1- n)))
(assert (and (> n 1) (> a 0)))
(flet ((next (x)
(/ (+ (* (1- n) x)
(/ a (expt x (1- n))))
n)))
(do* ((xi guess xi+1)
(xi+1 (next xi) (next xi)))
((< (abs (- xi+1 xi)) epsilon) xi+1))))