Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Nth-root/Lambdatalk/nth-root.lambdatalk
Normal file
22
Task/Nth-root/Lambdatalk/nth-root.lambdatalk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{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
|
||||
Loading…
Add table
Add a link
Reference in a new issue