Talk:Arithmetic-geometric mean: Difference between revisions

m
Replacxed <lang> tags with <syntaxhighlight>
m (→‎rapidity: added a new talk section, fixed/(supplied) the previous LANG ending HTML tag.)
m (Replacxed <lang> tags with <syntaxhighlight>)
 
(4 intermediate revisions by 2 users not shown)
Line 39:
The referenced Mathworld page mentions that AGM is meaningful on the complex plane as well.
:It certainly has. It has been called The Mind of God (perhaps beyond the scope of this task!). There is a little more to it than adding +0i to the real solution. In Real Maths sqrt 4 is 2(This task assumes this). In fantasy maths sqrt 4 is 2 and -2. Then the next iteration takes the sqrt of a negative number, and maths goes complex. The result in Complex maths is the set of all these arithmetric geometric means.--[[User:Nigel Galloway|Nigel Galloway]] 14:20, 23 April 2012 (UTC)
<langsyntaxhighlight lang="go">package main
 
import (
Line 47:
)
 
const ε = 1e-14</langsyntaxhighlight>
 
==rapidity of convergence==
 
From this Rosetta Code task's prologue:
Line 55:
:: <big><big>Since the limit of <math>a_n-g_n</math> tends (rapidly) to zero with iterations, this is an efficient method.</big></big>
 
<br>With this in mind, I modified the REXX's entry was modified &nbsp; (and suppressed the normal output being displayed), &nbsp; and
<br>added a display of the iteration count along with the number of decimal digits being used.
 
The modified REXX program is:
<langsyntaxhighlight lang="rexx">/*REXX program calculates the AGM (arithmetic─geometric mean) of two (real) numbers. */
parse arg a b digs . /*obtain optional numbers from the C.L.*/
if digs=='' | digs=='",'" then digs=100 /*No DIGS specified? Then use default.*/
numeric digits digs /*REXX will use lots of decimal digits.*/
if a=='' | a=='",'" then a=1 /*No A specified? Then use default.*/
if b=='' | b=='",'" then b=1 / sqrt(2) /*No B specified? " " " */
call AGM a,b /*invoke AGM & don't show A,B,result.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*────────────────────────────────────────────────────────────────────────────*/
agm: procedure: parse arg x,y; if x=y then return x /*is it an equality case? */
if y=0 then return 0 /*is value of Y zero? */
if x=0 then return y / 2 /* " X " " X " */
d=digits(); numeric digits d+5 /*add 5 more digs to ensure convergence*/
tiny='1e-' || (digits() - 1); /*construct a pretty tiny REXX number. */
ox=x + 1
do #=1 while ox\=x & abs(ox)>tiny; ox=x; oy=y
x=(ox+oy)/2; y=sqrt(ox*oy)
end /*while ··· #*/
numeric digits d /*thisrestore is thenumeric onlydigits output displayedto ►─┐original.*/
 
numeric digits d /*restorethis is numericthe digitsonly output todisplayed original.►─┐*/
say 'digits='right(d, 7)", iterations=" right(#, 3) /* ◄───────────────┘*/
/*this is the only output displayed ►─┐*/
return x/1 /*normalize X to the new digits. */
say 'digits='right(d,7)", iterations=" right(#,3) /* ◄───────────────┘*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
return x/1 /*normalize X to the new digits. */
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); im.=9; numeric form; m. h=9d+6
/*────────────────────────────────────────────────────────────────────────────*/
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g *.5'e'_ % 2
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); i=; m. =9
numeric digits do j=0 while h>9; if x<0 then do; xm.j=-xh; i='i'; end; numeric form; h=d+h % 2 + 1; end /*j*/
parse value do format(x,2,1,,0)k=j+5 'E0'to 0 withby -1; g 'E' _numeric digits m.k; g=(g+x/g)*.5'E'_%2; end /*k*/; return g</syntaxhighlight>
'''outputs''' {{out|output|text=&nbsp; (from multiple runs) &nbsp; with a specified number of digits, and with the various outputs being combined/reduced/edited:}}
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g=.5*(g+x/g); end /*k*/
numeric digits d; return (g/1)i</lang>
'''outputs''' &nbsp; with a specified number of digits, and with the various outputs being combined/reduced/edited:
<pre>
digits= 100, iterations= 9
Line 102 ⟶ 99:
digits= 51200, iterations= 18
</pre>
Needless to say, theThe CPU time increasedquadrupled (about) everytime the digits were doubled.
 
==Formulae hidden to most browsers by under-tested cosmetic edits at 21:25, 14 April 2016==
 
Under-tested cosmetic edits made to the task page at 21:25, 14 April 2016, including the injection of spaces around expressions in &lt;math&gt; tags, have left most of the task description formulae completely invisible to all browsers which display the graphic file version of formulae rather than processing the MathML (this is, in fact, the majority of browsers). The MediaWiki processor does not currently expect such spaces, and generates syntactically ill-formed HTML if they are introduced. Other aspects of these cosmetic edits may further compound the problem. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 08:48, 21 September 2016 (UTC)
 
: Visibility of formulae restored 18 Oct 2016 [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 19:03, 18 October 2016 (UTC)
3,021

edits