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.



 
{def root 
  {def good-enough? {lambda {next guess tol}
    {< {abs {- next guess}} tol} }}
  {def improve {lambda {guess num deg}
    {/ {+ {* {- deg 1} guess} 
             {/ num {pow guess {- deg 1}}}} deg} }}
  {def *root {lambda {guess num deg tol}
    {let { {guess guess} {num num} {deg deg} {tol tol}
           {next {improve guess num deg}}
         } {if {good-enough? next guess tol}
            then guess
            else {*root next num deg tol}} }}}
 {lambda {num deg tol}
  {*root 1.0 num deg tol} }}
-> root 
 
{root {pow 2 10} 10 0.1}
-> 2.0473293223683866
{root {pow 2 10} 10 0.01}
-> 2.004632048354822
{root {pow 2 10} 10 0.001}
-> 2.000047868581671
 