Arithmetic-geometric mean: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,549: | Line 1,549: | ||
=={{header|Lambdatalk}}== |
=={{header|Lambdatalk}}== |
||
<syntaxhighlight lang="Scheme"> |
<syntaxhighlight lang="Scheme"> |
||
{def eps 1e-15} |
|||
-> eps |
|||
{def agm |
{def agm |
||
⚫ | |||
{def agm.r |
|||
{ |
{if {> {abs {- :a :g}} {eps}} |
||
then {agm {/ {+ :a :g} 2} |
|||
{sqrt {* :a :g}}} |
|||
else : |
else :a }}} |
||
⚫ | |||
{agm.r {/ {+ :a0 :g0} 2} {sqrt {* :a0 :g0}} 1e-15}}} |
|||
-> agm |
-> agm |
||
Line 1,562: | Line 1,563: | ||
-> 0.8472130847939792 |
-> 0.8472130847939792 |
||
Multi-precision version using the lib_BN library |
|||
⚫ | |||
⚫ | |||
⚫ | |||
-> EPS |
|||
{def AGM |
{def AGM |
||
⚫ | |||
{def AGM.r |
|||
{if {= {BN.compare {BN.abs {BN.- :a :g}} {EPS}} 1} |
|||
{lambda {:an :gn :tol} |
|||
then {AGM {BN./ {BN.+ :a :g} 2} |
|||
{BN.sqrt {BN.* :a :g}}} |
|||
else :a }}} |
|||
:tol} |
|||
else :an }}} |
|||
⚫ | |||
{AGM.r {BN./ {BN.+ :a0 :g0} 2} |
|||
{BN.sqrt {BN.* :a0 :g0}} |
|||
⚫ | |||
-> AGM |
-> AGM |
||
⚫ | |||
⚫ | |||
{AGM 1 {BN./ 1 {BN.sqrt 2}}} |
{AGM 1 {BN./ 1 {BN.sqrt 2}}} |
||
-> 0.8472130847939790866064991234821916364814459103269421850605793726597339 |
-> 0.8472130847939790866064991234821916364814459103269421850605793726597339 |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|LFE}}== |
=={{header|LFE}}== |