Task

Implement the algorithm to compute the principal   nth   root   





A

n





{\displaystyle {\sqrt[{n}]{A}}}

   of a positive real number   A,   as explained at the   Wikipedia page.



#lang racket
 
(define (nth-root number root (tolerance 0.001))
  (define (acceptable? next current)
    (< (abs (- next current)) tolerance))
 
  (define (improve current)
    (/ (+ (* (- root 1) current) (/ number (expt current (- root 1)))) root))
 
  (define (loop current)
    (define next-guess (improve current))
    (if (acceptable? next-guess current)
        next-guess
        (loop next-guess)))
  (loop 1.0))