<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Snark</id>
		<title>explain xkcd - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Snark"/>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php/Special:Contributions/Snark"/>
		<updated>2026-04-22T18:57:36Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=Talk:2435:_Geothmetic_Meandian&amp;diff=207762</id>
		<title>Talk:2435: Geothmetic Meandian</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=Talk:2435:_Geothmetic_Meandian&amp;diff=207762"/>
				<updated>2021-03-12T06:12:27Z</updated>
		
		<summary type="html">&lt;p&gt;Snark: /* Proof - This is connected to the Heat Equation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Please sign your posts with ~~~~ and don't delete this text. New comments should be added at the bottom.--&amp;gt;&lt;br /&gt;
Oh, this one's good. Just checked in (no, I wasn't hovering over the refresh button, my first visit today!) and one glance had me in paroxysms of laughter. But how to explain it? Gonna have to think about that. [[Special:Contributions/141.101.98.96|141.101.98.96]] 01:12, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
I made a really bad spreadsheet to understand better how it works: https://docs.google.com/spreadsheets/d/1fqmHwDmirJrsKPdf94PutFDw31DMAYxNeR7jef1jneE/edit?usp=sharing&lt;br /&gt;
&lt;br /&gt;
Someone fix my ''awful''  transcript edits please. --[[User:Char Latte49|Char Latte49]] ([[User talk:Char Latte49|talk]]) 02:31, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
Seeing the Python added to the Explanation, try this Perl (typed straight here, so not tested)... &lt;br /&gt;
 ## Your prefered variations of &amp;quot;#!/usr/bin/perl&amp;quot;, &amp;quot;use strict;&amp;quot; and &amp;quot;use warnings;&amp;quot; here! ##&lt;br /&gt;
 sub F { my (@vals)=@_; my $invVals=1/int(@vals);&lt;br /&gt;
  my ($geo,$arith,$med)=(1); # Only defining $geo, so first *= works correctly!&lt;br /&gt;
  while (@vals) { my($lo,$hi)=(shift @vals,pop @vals); # $hi may be undef - this is intended!&lt;br /&gt;
   $arith+=$lo; $geo*=$lo; unless (defined $hi) {  $med =  $lo;     last }&lt;br /&gt;
   $arith+=$hi; $geo*=$hi; unless (@vals)       { ($med)=F($lo,$hi)      }&lt;br /&gt;
  }&lt;br /&gt;
  return ($arith*$invVals, $geo**$invVals, $med);&lt;br /&gt;
 }&lt;br /&gt;
 sub GMDN { my (@vals)=sort @_; my $lim=10**(-5); # Adjust $lim to taste...&lt;br /&gt;
   return &amp;quot;Error: No vals!&amp;quot; unless  @vals; # Catch!&lt;br /&gt;
   return $vals[0]          unless ($vals[$#vals]-$vals[0]) &amp;gt; $lim;&lt;br /&gt;
   return GMDM(F(@vals));&lt;br /&gt;
 }&lt;br /&gt;
 my @test=(1,1,2,3,5);&lt;br /&gt;
 print &amp;quot;Values:              @test\nGeothmetic Meandian: &amp;quot;.GMDN(@test).&amp;quot;\n&amp;quot;;&lt;br /&gt;
...debugged in my head, so probably fatally flawed but easily fixed/adapted anyway. [[Special:Contributions/141.101.99.109|141.101.99.109]] 03:04, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
Why so complicated?&lt;br /&gt;
 perl -e 'use strict; use warnings; sub F { my ($s,$p) = (0,1); my @srt = sort {$a&amp;lt;=&amp;gt;$b} @_; for (@_) { $s += $_; $p *= $_; } return ($s/@_,$p**(1/@_),$srt[$#_/2]); } sub Gmdn { print join(&amp;quot;, &amp;quot;,@_=F(@_)),&amp;quot;\n&amp;quot; for 0..20; return @_; } print join(&amp;quot;, &amp;quot;,Gmdn(1,1,2,3,5)),&amp;quot;\n&amp;quot;;'&lt;br /&gt;
(With interim results) SCNR -- [[User:Xorg|Xorg]] ([[User talk:Xorg|talk]]) 03:18, 11 March 2021 (UTC)&lt;br /&gt;
:''I'' can read your version (and I see you do explicit {$a&amp;lt;=&amp;gt;$b}, which indeed ''may'' be necessary in mine for real use, along with additional sanity checks, I will check later) but I wanted to make mine neat, and ''slightly'' tricksy in implementation, but still not quite so entirely obfuscated to the more uninitiated. TIMTOWTDI, etc, so I like your (almost) bare-bones version too. ;)&lt;br /&gt;
:(Is 20 cycles enough to converge in sufficiently extreme cases? Won't give &amp;quot;Too deep&amp;quot; error, though, even  if it takes at least that long. There's a definite risk that mine might, as written.) [[Special:Contributions/141.101.99.229|141.101.99.229]] 03:45, 11 March 2021 (UTC)&lt;br /&gt;
::Given the lack of precision in Randall's example usage, I think 20 cycles ought to be enough for everyone ;-P. I'm trying to prove that the interval's size has to shrink by somewhat close to a factor of 1/2 every cycle, but it's tricky and it's late. If I can assume a factor of 1/2 in the long run, 64 iterations should pin down a 64-bit float.&lt;br /&gt;
::I actually didn't try to obfuscate, I was just too lazy to type more ;-). Otherwise I might have left out the &amp;quot;return&amp;quot;s and passing parameters at all. -- [[User:Xorg|Xorg]] ([[User talk:Xorg|talk]]) 04:21, 11 March 2021 (UTC)&lt;br /&gt;
:::I find the one-liner more readable: it's straightforward and pretty minimal. For what its worth, here's my version: &amp;lt;pre&amp;gt;perl -MList::Util=sum,product -E 'sub F { (sum @_)/@_, (product @_)**(1/@_), (sort { $a &amp;lt;=&amp;gt; $b } @_)[$#_/2] } $, = &amp;quot; &amp;quot;; say @v = @ARGV; say @v = F(@v) for 1..30' 1 1 2 3 5&amp;lt;/pre&amp;gt; 30 iterations is enough for the numbers to display identically on this system (to 14 decimal places). I think it's even cleaner in Raku (formerly Perl 6): &amp;lt;pre&amp;gt;raku -e 'sub F(@d) { @d.sum/@d, [*](@d)**(1/@d), @d.sort[@d/2] }; say my @v = +«@*ARGS; say @v = F(@v) for 1..33' 1 1 2 3 5&amp;lt;/pre&amp;gt; On this system, Rakudo yields an additional decimal place, which takes another 3 iterations to converge.  [[User:Smylers|Smylers]] ([[User talk:Smylers|talk]]) 06:53, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
Side-thought: is GMDN (nowhere near as logical an ETLA contraction of the title term as, say, 'GMMD' or 'GTMD') actually an oblique reference to the GNDNs as popularised/coined by Trek canon? Worth a citation/Trivia? [[Special:Contributions/162.158.158.97|162.158.158.97]] 04:12, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
Besides of nerdgasm is there some reason why the program code is relevant for the explanation? [[User:Elektrizikekswerk|Elektrizikekswerk]] ([[User talk:Elektrizikekswerk|talk]]) 08:55, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Proof of convergence ==&lt;br /&gt;
&lt;br /&gt;
Can any of you come up with a mathematical proof that repeated application of F on a set of (say) positive real numbers is guaranteed to converge toward a single real number, i.e. that the GMDN of a set of positive real numbers is well-defined? &lt;br /&gt;
&lt;br /&gt;
One observation I've made is that if you consider that maximum and minimum numbers in the original set to be x1 and xn (without loss of generality), something we know for sure is that AM(x1, ..., xn), GM(x1, ..., xn) and Median(x1, ..., xn) are all at least x1 and at most xn that is to say...&lt;br /&gt;
&lt;br /&gt;
x1 &amp;lt;= AM(x1, ..., xn), GM(x1, ..., xn), Median(x1, ..., xn) &amp;lt;= xn&lt;br /&gt;
&lt;br /&gt;
So range(AM(x1, ..., xn), GM(x1, ..., xn), Median(x1, ..., xn)) is necessarily &amp;lt;= range(x1, ..., xn). &lt;br /&gt;
&lt;br /&gt;
And given that we know that unless x1, ..., xn are all equal, that x1 &amp;lt; AM(x1, ..., xn) &amp;lt; xn, we have an even stricter result (unless x1, ..., xn are all equal) that is &lt;br /&gt;
range(AM(x1, ..., xn), GM(x1, ..., xn), Median(x1, ..., xn)) &amp;lt; range(x1, ..., xn). &lt;br /&gt;
&lt;br /&gt;
So, it's clear that range(x1, ..., xn) &amp;gt; range(F(x1, ..., xn)) &amp;gt; range(F(F(x1, ..., xn))) &amp;gt; range(F(F(F(x1, ..., xn)))) &amp;gt; ... and it's also clear that all of these ranges are &amp;gt;= 0. There is a result in number theory that says that any infinite sequence of real numbers which monotonically decreases and is bounded from below converges.&lt;br /&gt;
&lt;br /&gt;
So we know for sure that range(F(F(...F(x1, ..., xn)...))) converges but we still have to show that it converges to 0 to show that the GMDN converges to a single real number.&lt;br /&gt;
&lt;br /&gt;
I'm not sure how to proceed. Does anyone have any ideas?&lt;br /&gt;
&lt;br /&gt;
EDIT:&lt;br /&gt;
I just noticed that unless x1, ..., xn are all equal, AM(x1, ..., xn) is at least ((n-1)/n) * range(x1, ..., xn) away from both x1 and xn. So not only do we have that range(x1, ..., xn) &amp;gt; range(F(x1, ..., xn)) from before, but we also have that ((n-1)/n) * range(x1, ..., xn) &amp;gt;= range(F(x1, ..., xn)). This guarantees that that the range falls exponentially on repeated applications of F. So it's certain that the the range ultimately converges to 0, and hence that the GMDN is well-defined.&lt;br /&gt;
&lt;br /&gt;
It might be a good idea for someone to concretely present this idea as a proof on Page.&lt;br /&gt;
&lt;br /&gt;
See my additional notes below. -Ramakarl&lt;br /&gt;
&lt;br /&gt;
[[Special:Contributions/172.69.135.44|172.69.135.44]] 05:07, 11 March 2021 (UTC) Anirudh Ajith&lt;br /&gt;
&lt;br /&gt;
:That doesn't quite work as it stands, since proving AM is that distance away does not say anything about the other two averages. I think it's true, but a little more rigour is required. [[Special:Contributions/141.101.98.120|141.101.98.120]] 09:17, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
When trying this myself I first arrived at 2.082, not 2.089. What threw me off was the incomplete formula for the median, which only works with sorted lists. The three values returned by F(...) aren't necessarily sorted.&lt;br /&gt;
[[Special:Contributions/141.101.76.194|141.101.76.194]] 09:49, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
First: almost all invocations are with exactly 3 arguments (The output of the previous invocation), so we don't have to deal with N inputs at all.&lt;br /&gt;
Notation: In iteration n we have the values min[n] &amp;lt;= mid[n] &amp;lt;= max[n] (in any order) and can compute AM[n], GM[n] (and median[n] = mid[n]).&lt;br /&gt;
Let Q[n] := max[n]/min[n] &amp;gt;= 1, R[n] := max[n]-min[n] = (Q[n]-1)*min[n].&lt;br /&gt;
We already established that R is decreasing and min is increasing, so Q is decreasing.&lt;br /&gt;
&lt;br /&gt;
Theorem: There is an n0 with R[n+1] &amp;lt;= R[n]*2/3 for all n &amp;gt; n0.&lt;br /&gt;
&lt;br /&gt;
Proof (by case discrimination for each n):&lt;br /&gt;
case 1: mid[n+1] != AM[n]:&lt;br /&gt;
    R[n+1] &amp;lt;= Max(max[n]-AM[n],AM[n]-min[n]) &lt;br /&gt;
            = Max(max[n]*3-(max[n]+mid[n]+min[n]),(max[n]+mid[n]+min[n])-min[n]*3)/3&lt;br /&gt;
            = Max(max[n]*2-(mid[n]+min[n]),(max[n]+mid[n])-min[n]*2)/3&lt;br /&gt;
           &amp;lt;= (max[n]-min[n])*2/3&lt;br /&gt;
            = R[n]*2/3&lt;br /&gt;
    Hence: R[n+1] &amp;lt;= R[n]*2/3&lt;br /&gt;
&lt;br /&gt;
case 2: mid[n+1] == AM[n]:&lt;br /&gt;
  because GM &amp;lt;= AM: min[n+1] = GM[n], max[n+1] = mid[n]&lt;br /&gt;
  Q[n+1] = mid[n]/GM[n]&lt;br /&gt;
         = (mid[n]^3/(max[n]*mid[n]*min[n]))^(1/3)&lt;br /&gt;
         = (mid[n]^2/(max[n]*min[n]))^(1/3)&lt;br /&gt;
        &amp;lt;= (mid[n]/min[n])^(1/3)&lt;br /&gt;
        &amp;lt;= Q[n]^(1/3)&lt;br /&gt;
  R[n+1] = (Q[n+1]-1)*min[n+1]&lt;br /&gt;
        &amp;lt;= (Q[n]^(1/3)-1)*GM[n]&lt;br /&gt;
        &amp;lt;= (Q[n]^(1/3)-1)*(max[n]^2*min[n])^(1/3)&lt;br /&gt;
         = (Q[n]^(1/3)-1)*Q[n]^(2/3)*min[n]&lt;br /&gt;
         = (Q[n]-Q[n]^(2/3))*min[n]&lt;br /&gt;
         = R[n]-(Q[n]^(2/3)-1)*min[n]&lt;br /&gt;
        &amp;lt;= R[n]-(Q[n]-1)*min[n]/(Q[n]^(1/3)+1))&lt;br /&gt;
         = R[n]-R[n]/(Q[n]^(1/3)+1)&lt;br /&gt;
         = R[n]*(1-1/(Q[n]^(1/3)+1))&lt;br /&gt;
  Now we can pick a q1 = Q(n1) with q1 &amp;gt; Q[n] &amp;gt;= 1 for n &amp;gt; n1 because Q is decreasing:&lt;br /&gt;
    R[n+1] &amp;lt;= R[n]*(1-1/(q1^(1/3)+1))&lt;br /&gt;
  &lt;br /&gt;
  Together with case 1, this gives R -&amp;gt; 0 and thus Q -&amp;gt; 1. So we can pick another q0 = Q(n0) with q0 &amp;lt;= 8:&lt;br /&gt;
    R[n+1] &amp;lt;= R[n]*(1-1/(q0^(1/3)+1)) &amp;lt;= R[n]*2/3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
-- [[User:Xorg|Xorg]] ([[User talk:Xorg|talk]]) 17:34, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Better Python implementations ==&lt;br /&gt;
&lt;br /&gt;
I'd like to add a somewhat more compact Python implementation based on the numpy module.&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 &lt;br /&gt;
 def F(x):&lt;br /&gt;
    return np.mean(x), np.exp(np.log(x).mean()), np.median(x)&lt;br /&gt;
 &lt;br /&gt;
 def GMDN(x, tolerance=1e-6):&lt;br /&gt;
    while np.std(x) &amp;gt; tolerance:&lt;br /&gt;
        x = F(x)&lt;br /&gt;
    return x[0]&lt;br /&gt;
 &lt;br /&gt;
 gmdn = GMDN([1, 1, 2, 3, 5])&lt;br /&gt;
 print(gmdn)&lt;br /&gt;
--[[User:Lvdgraaff|Lvdgraaff]] ([[User talk:Lvdgraaff|talk]]) 10:42, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
No need for numpy, there's the statistics module in the stdlib&lt;br /&gt;
&lt;br /&gt;
 import math&lt;br /&gt;
 import statistics&lt;br /&gt;
 &lt;br /&gt;
 def F(*nums):&lt;br /&gt;
     return (&lt;br /&gt;
         statistics.mean(nums),&lt;br /&gt;
         statistics.geometric_mean(nums),&lt;br /&gt;
         statistics.median(nums),&lt;br /&gt;
     )&lt;br /&gt;
 &lt;br /&gt;
 def GMDN(*nums):&lt;br /&gt;
     while not math.isclose(max(nums), min(nums)):&lt;br /&gt;
         nums = F(*nums)&lt;br /&gt;
     return nums[0]&lt;br /&gt;
 &lt;br /&gt;
 gmdn = GMDN(1, 1, 2, 3, 5)&lt;br /&gt;
 print(gmdn)&lt;br /&gt;
&lt;br /&gt;
:For something as simple as this, I always find it cheating to use a package to abstract away the few actually necessary calculations. You might as well use a DWIM module and do 'result = DWIM(input)' as the sole command. But that's me for you. I'd write my own direct-to-memory screen RAM accesses, if silly things like OS HALs and GPU acceleration (once you find a way to message them as directly as possible) hadn't long since made that pretty much moot, if not actually verboten... [[Special:Contributions/141.101.99.109|141.101.99.109]] 17:53, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Sloppy notation? ==&lt;br /&gt;
&lt;br /&gt;
As a mathematician, I immediately noticed a couple of annoying niggles. Firstly, it is only implied, but never clearly stated, that the input list is ordered - which means the median is wrong unless ordered. Now F outputs an ordered triple of real numbers, and in calculating G, this is fed in to F again directly. This will frequently give inputs that are not in order, and in subsequent iterations the &amp;quot;median&amp;quot; will always be the middle number - i.e. the geometric mean - regardless of the actual median. Secondly, Randall's final line gives the output of G as a single number, but as it is just the result of a repeated application of F, the output of G should be an ordered triple. I'm sure Randall is aware of both, and chose to cut out the implied ordering of the inputs and choosing one of the three values as the output of G as they aren't necessary for the joke, but maybe we should note something about this in the explanation.[[Special:Contributions/141.101.99.109|141.101.99.109]] 13:07, 11 March 2021 (UTC)&lt;br /&gt;
:First, I've never seen a definition of median which doesn't account for ordering itself, although I am a little annoyed at his definition for a different reason— that it doesn't account for even-length lists. Second, what I got from the comic initially is that G&amp;lt;sub&amp;gt;MDN&amp;lt;/sub&amp;gt; is supposed to be a single number, specifically that value for which all three of its elements would become equal if implemented infinitely many times (and it ''will'' converge, because if the three elements are all the same it already has converged, and if at least two are different, both means will necessarily become greater than the least value and smaller than the greatest value due to the definition of 'mean'). Another annoyance I noted is that G&amp;lt;sub&amp;gt;MDN&amp;lt;/sub&amp;gt; is real iff there are an even number of negative numbers and/or the length of the initial list is odd, but I suppose that can't be helped. Ooh, complex meandianing! [[User:BlackHat|BlackHat]] ([[User talk:BlackHat|talk]]) 15:15, 11 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Is the arithmetic-geometric mean connected to geometry? ==&lt;br /&gt;
&lt;br /&gt;
In the case that only the arithmetic and geometric mean are used the combined arithmetic-geometric mean can be interpreted as the radius R of a circle which has the same circumference as an ellipse with half axes a and b. &lt;br /&gt;
&lt;br /&gt;
R = M(a,b)&lt;br /&gt;
&lt;br /&gt;
Can the Geothmetic Meandian be interpreted are the radius R of a 3D sphere which has the same surface as an elliptic cylinder with half-axes a and b and length c ?&lt;br /&gt;
&lt;br /&gt;
R = GMDN(a,b,c)&lt;br /&gt;
&lt;br /&gt;
=== The RandallMunroe Set ===&lt;br /&gt;
&lt;br /&gt;
Here is some MATLAB code (sorry) to generate an image showing the number of cycles required to converge, a' la' the Mandelbrot Set. &lt;br /&gt;
Not sure how to post an image here, but it is really cool.&lt;br /&gt;
&lt;br /&gt;
    % RandallMunroeSet.m&lt;br /&gt;
    % From a suggestion by Randall Munroe in XKCD #2435 Mar 10 2021&lt;br /&gt;
    % new statistic GMDN(x) = [mean(x), geomean(x), median(x)]&lt;br /&gt;
    % calculation is recursive, ending when converged&lt;br /&gt;
    % here we count the cycles required to converge and plot a' la' Madelbrot Set&lt;br /&gt;
    % the initial X input can be any length vector, but we restrict to 3 space&lt;br /&gt;
    % here for visualization, and fix Z so we get a 2D image&lt;br /&gt;
    % so far, for positive values, it converges in less than 40 or not at all&lt;br /&gt;
    % for negative x, set max cycles to something larger like 60&lt;br /&gt;
    % I haven't plotted it, but there is logically another set that plots the&lt;br /&gt;
    % resulting converged value.&lt;br /&gt;
    % Explore!&lt;br /&gt;
    % (c)2021 CC BY-NC 2.5 SBStevenson@uh.edu peace, love, trees&lt;br /&gt;
&lt;br /&gt;
    % here we answer the question, how many cycles does it take for GMDN to&lt;br /&gt;
    % converge?&lt;br /&gt;
    maxcycles = 40; stepsize = .0025;&lt;br /&gt;
    z = 1; % pick a Z, any Z&lt;br /&gt;
    x = stepsize:stepsize:(4-stepsize); % explore a range of x and y&lt;br /&gt;
    y = x; &lt;br /&gt;
    wbh = waitbar(0);&lt;br /&gt;
    RMS = zeros(numel(x),numel(y),numel(z)); % no, not root mean square, this is the Randall Munro Set!&lt;br /&gt;
&lt;br /&gt;
    for idx = 1: numel(x)&lt;br /&gt;
        waitbar(idx ./ numel(x)); % feedback on progress&lt;br /&gt;
        for jdx = idx:numel(y) % result is symmetric across the diagonal, so we save time by computing above the diagonal&lt;br /&gt;
&lt;br /&gt;
            for kdx = 1:numel(z)&lt;br /&gt;
                RMS(idx, jdx, kdx)  = gmdn([x(idx),y(jdx),z(kdx)], maxcycles);&lt;br /&gt;
                RMS(jdx, idx, kdx) = RMS(idx, jdx, kdx); % copy across the diagonal&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    close(wbh)&lt;br /&gt;
    RMS = min(maxcycles,RMS);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if numel(z) == 1;&lt;br /&gt;
        figure(420);&lt;br /&gt;
        image(255*RMS./maxcycles);truesize; colormap(jet(256));&lt;br /&gt;
    end&lt;br /&gt;
    if numel(z) == 3; % allow for true color, but in practice it is so sensitive to initial z value it just gives three different sets unless the Zs are VERY CLOSE&lt;br /&gt;
        figure(420);image(RMS./maxcycles);truesize;&lt;br /&gt;
    end&lt;br /&gt;
    title(['RandallMunro Set Z = ' num2str(z)]);&lt;br /&gt;
&lt;br /&gt;
    figure(3);hist(RMS(:),0:maxcycles);&lt;br /&gt;
    %% How many cycles to converge?&lt;br /&gt;
    function ncycles = gmdn(x, maxcycles)&lt;br /&gt;
    ncycles = 0;&lt;br /&gt;
    while ncycles &amp;lt; maxcycles&lt;br /&gt;
        ncycles = ncycles + 1;&lt;br /&gt;
        x = [mean(x), geomean(x), median3(x)];&lt;br /&gt;
        if all(x(1) == x(2:3))&lt;br /&gt;
            break&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    %% Geometric Mean&lt;br /&gt;
    function result = geomean(x)&lt;br /&gt;
    result = prod(x) .^ (1/numel(x));&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    %% Slightly faster median than builtin MATLAB function&lt;br /&gt;
    function result = median3(x)&lt;br /&gt;
    y = sort(x);&lt;br /&gt;
    result = y(2);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
== Proof - This is connected to the Heat Equation ==&lt;br /&gt;
&lt;br /&gt;
Earlier question:&lt;br /&gt;
&amp;gt; Can any of you come up with a mathematical proof that repeated application of F on a set of (say) positive real numbers is guaranteed to converge toward a single real number&lt;br /&gt;
&lt;br /&gt;
Yes. This triplet can be regarded as a partial differential equation with in a monotonically decreasing range that converges to a single value. &lt;br /&gt;
We observe that all three of these always result in a value which is strictly less than the min and max. Thus the PDE equations are progressively bounded by a smaller range, ie. they converge in the same way that the heat equation converges. &amp;quot;Under broad assumptions, an initial/boundary-value problem for a linear parabolic PDE has a solution for all time. The solution .. is generally smoother than the initial data&amp;quot; (https://en.wikipedia.org/wiki/Parabolic_partial_differential_equation#Solution), which holds here.&lt;br /&gt;
The range converges to zero because the values are real numbers.&lt;br /&gt;
&lt;br /&gt;
Given the real 3-vector for Fn, the range of Fn+1 must be strictly less than the range of Fn:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
R(Fn) = max(Fn)-min(Fn)&amp;lt;br&amp;gt;&lt;br /&gt;
R(Fn+1) = max(ave(Fn),geomean(Fn),median(Fn))-min(ave(Fn),geomean(Fn),median(Fn))&amp;lt;br&amp;gt;&lt;br /&gt;
max(ave(Fn),geomean(Fn),median(Fn)) &amp;lt; max(Fn) '''because''' ave(Fn),geomean(Fn),median(Fn) &amp;lt; max(Fn)&amp;lt;br&amp;gt;&lt;br /&gt;
min(ave(Fn),geomean(Fn),median(Fn)) &amp;gt; min(Fn) '''because''' ave(Fn),geomean(Fn),median(Fn) &amp;gt; min(Fn)&amp;lt;br&amp;gt;&lt;br /&gt;
therefore.. &amp;lt;br&amp;gt;&lt;br /&gt;
R(Fn+1) &amp;lt; R(Fn)|&amp;lt;br&amp;gt;&lt;br /&gt;
limit R(Fn+1) = 0 as n approaches inf.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The range of Fn+1 approaches 0, ie. the series converges for positive inputs.&lt;br /&gt;
(note the series is undefined for real negative inputs since the geomean uses the n-th root)&lt;br /&gt;
&lt;br /&gt;
[[User:Ramakarl|Ramakarl]] ([[User talk:Ramakarl|talk]]) 00:00, 12 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
:How can this be formulated as a PDE when F isn't even differentiable?&lt;br /&gt;
:Besides, R(Fn+1) &amp;lt; R(Fn) does not imply limit R(Fn) = 0 (Think R(n) := 1+1/n). -- [[User:Xorg|Xorg]] ([[User talk:Xorg|talk]]) 02:50, 12 March 2021 (UTC)&lt;br /&gt;
&lt;br /&gt;
[[User:snark]]&lt;br /&gt;
This has nothing to do with a PDE or the heat equation. It is an iterative map from R^3 to R^3 (after the first application of F). In&lt;br /&gt;
order to prove it converges you need to show that there is a fixed point and that the mapping takes you closer to it. The fixed points&lt;br /&gt;
are easy since F((x,x,x))=(x,x,x) so there is a line of fixed points. You can then calculate the perpendicular distance between the&lt;br /&gt;
starting point (x1,x2,x3) and the line given by (x(t),x(t),x(t)). Next you calculate the distance between f((x1,x2,x3)) and the line&lt;br /&gt;
and show that is is less than the first distance.&lt;br /&gt;
&lt;br /&gt;
== Why is this funny? ==&lt;br /&gt;
Wow, paragraphs and paragraphs of explanation, and calculations, and computer code describing everything about the XKCD comic.&lt;br /&gt;
I am impressed with how much people know. After all that explanation, can anyone tell me if there is anything comical about this comic?&lt;br /&gt;
Aside from the fact that Randal is combining formulas that don't usually get combined, is there anything here that strikes anyone as funny? The previous one about people asking absurd questions about what they could do after they are vaccinated had me laughing out loud. Can anyone tell me that they laughed at this comic and what was funny? Thanks. [[User:Rtanenbaum|Rtanenbaum]] ([[User talk:Rtanenbaum|talk]]) 01:56, 12 March 2021 (UTC)&lt;br /&gt;
:YMMV, but I found it funny because I just spent the last fortnight teaching how to find mean (and median, and quartiles for that matter) to 15/16yrolds. And they found that hard enough. I did not inform them of Geometric mean. I guess it's funny because it's such a long reach. [[User:Thisfox|Thisfox]] ([[User talk:Thisfox|talk]]) 02:48, 12 March 2021 (UTC)&lt;/div&gt;</summary>
		<author><name>Snark</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=2435:_Geothmetic_Meandian&amp;diff=207750</id>
		<title>2435: Geothmetic Meandian</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=2435:_Geothmetic_Meandian&amp;diff=207750"/>
				<updated>2021-03-12T00:44:13Z</updated>
		
		<summary type="html">&lt;p&gt;Snark: /* Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 2435&lt;br /&gt;
| date      = March 10, 2021&lt;br /&gt;
| title     = Geothmetic Meandian&lt;br /&gt;
| image     = geothmetic_meandian.png&lt;br /&gt;
| titletext = Pythagorean means are nice and all, but throwing the median in the pot is really what turns this into random forest statistics: applying every function you can think of, and then gradually dropping the ones that make the result worse.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
&lt;br /&gt;
There are a number of different ways to identify the '{{w|average}}' value of a series of values, the most common unweighted methods being the {{w|median}} (take the central value from the ordered list of values if there are an odd number - or the value half-way between the two that straddle the divide between two halves if there are an even number) and the {{w|arithmetic mean}} (add all the numbers up, divide by the number of numbers). The {{w|geometric mean}} is less well-known but works similarly to the arithmetic mean. To take the geometric mean of 'n' values, they are multiplied and then the 'n'th root is taken. It will be seen that for purely identical values this returns the single value as the singular average, as would the arithmetic calculation with serial addition then re-division, but it reacts differently to any perturbed values. You might also consider operating arithmetically upon logarithms of the list, then re-exponate the result.&lt;br /&gt;
&lt;br /&gt;
The geometric mean, arithmetic mean and {{w|harmonic mean}} (not shown) are collectively known as the {{w|Pythagorean means}}, as specific modes of a greater and more generalised mean formula that extends arbitrarily to various other possible nuances of mean-value rationisations (cubic, etc).&lt;br /&gt;
&lt;br /&gt;
{{w|Outlier}}s and internal biases within the original sample can make boiling down a set of values into a single 'average' sometimes overly biased by flaws in the data, with your choice of which method to use perhaps resulting in a value that is misleading, exagerating or suppressing the significance of any blips.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Either here or after the next paragraph, demonstrate how (1,1,2,3,5) resolves in each individual method, perhaps? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this depiction, the three named methods of averaging are embedded within a single function that produces a sequence of three values - one output for each of the methods. Being a series of values, Randall suggests that this is ideally suited to being ''itself'' subjected to the comparative 'averaging' method. Not just once, but as many times as it takes to narrow down to a sequence of three values that are very close to one another. &lt;br /&gt;
&lt;br /&gt;
It can be shown that the xkcd value of 2.089 for GMDN(1,1,2,3,5) is validated:&lt;br /&gt;
&lt;br /&gt;
{|-&lt;br /&gt;
 | F0 || 1 || 1 || 2 || 3 || 5 &lt;br /&gt;
 |-&lt;br /&gt;
 |    || Ave || Geomean || Median ||&lt;br /&gt;
 |-&lt;br /&gt;
 | F1 || 2.4 || 1.974350486 || 2		&lt;br /&gt;
 |-&lt;br /&gt;
 | F2 || 2.124783495 ||	2.116192461 || 2		&lt;br /&gt;
 |-&lt;br /&gt;
 | F3 || 2.080325319 || 2.079536819 || 2.116192461		&lt;br /&gt;
 |-&lt;br /&gt;
 | F4 || 2.0920182 || 2.091948605 || 2.080325319		&lt;br /&gt;
 |-&lt;br /&gt;
 | F5 || 2.088097374 || 2.088090133 || 2.091948605		&lt;br /&gt;
 |-&lt;br /&gt;
 | F6 || 2.089378704 ||	2.089377914 || 2.088097374		&lt;br /&gt;
 |-&lt;br /&gt;
 | F7 || 2.088951331 ||	2.088951244 || 2.089377914		&lt;br /&gt;
 |-&lt;br /&gt;
 | F8 || 2.089093496 || 2.089093487 || 2.088951331		&lt;br /&gt;
 |-&lt;br /&gt;
 | F9 || 2.089046105 || 2.089046103 || 2.089093487		&lt;br /&gt;
 |-&lt;br /&gt;
 | F10 || '''2.089061898''' || '''2.089061898''' || '''2.089046105'''		&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
The function GMDN in the comic is  not properly defined since F acts on a vector to produce another three vector, so repeated applications of F will always result in a 3 vector for which the ave, geomean and median can be iterated again. However GMDN is shown to produce a single real number rather than a vector. It is thus missing a final operation of returning any of the values of the components of the vector. Each row shows the set Fn(..) composed of the average, geomean and median computed on the previous row, with the sequence {1,1,2,3,5} as the initial F0. Since the average, geomean and median are all forms of averaging, and the composition of averages can be shown to be equivalent to a smoothing function, the value of GMDN will converge to a singular value for any set of starting values. This can be interpreted as similar to a heat equation which approaches equilibrium.&lt;br /&gt;
&lt;br /&gt;
The comment in the title text about suggests that this will save you the trouble of committing to the 'wrong' analysis as it gradually shaves down any 'outlier average' that is unduly affected by anomalies in the original inputs. It is a method without any danger of divergence of values, since all three averaging methods stay within the interval covering the input values (and two of them will stay strictly within that interval).&lt;br /&gt;
&lt;br /&gt;
The title text may also be a sly reference to an actual mathematical theorem, namely that if one performs this procedure only using the arithmetic mean and the harmonic mean, the result will converge to the geometric mean. Randall suggests that the (non-Pythagorean) median, which does not have such good mathematical properties with relation to convergence, is, in fact, the secret sauce in his definition.&lt;br /&gt;
&lt;br /&gt;
There does exist an {{w|arithmetic-geometric mean}}, which is defined identically to this except with the arithmetic and geometric means, and sees some use in calculus.  In some ways it's also philosophically similar to the {{w|truncated mean}} (extremities of the value range, e.g. the highest and lowest 10%s, are ignored as not acceptable and not counted) or {{w|Winsorized mean}} (instead of ignored, the values are readjusted to be the chosen floor/ceiling values that they lie beyond, to still effectively be counted as 'edge' conditions), only with a strange dilution-and-compromise method rather than one where quantities can be culled or neutered just for being unexpectedly different from most of the other data.&lt;br /&gt;
&lt;br /&gt;
The following python code (inefficiently) implements the above algorithm:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from functools import reduce&lt;br /&gt;
from itertools import count&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def f(*args):&lt;br /&gt;
    args = sorted(args)&lt;br /&gt;
    mean = sum(args) / len(args)&lt;br /&gt;
    gmean = reduce(lambda x, y: x * y, args) ** (1 / len(args))&lt;br /&gt;
    if len(args) % 2:&lt;br /&gt;
        median = args[len(args) // 2]&lt;br /&gt;
    else:&lt;br /&gt;
        median = (args[len(args) // 2] + args[len(args) // 2 - 1]) / 2&lt;br /&gt;
    return mean, gmean, median&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
max_number_of_iterations = 10&lt;br /&gt;
l0 = [1, 1, 2, 3, 5]&lt;br /&gt;
l = l0&lt;br /&gt;
for iterations in range(max_number_of_iterations):&lt;br /&gt;
    fst, *rest = l&lt;br /&gt;
    if all((abs(r - fst) &amp;lt; 0.00000001 for r in rest)):&lt;br /&gt;
        break&lt;br /&gt;
    l = f(*l)&lt;br /&gt;
print(l[0], iterations)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is an implementation of the Gmdn function in R:&lt;br /&gt;
&lt;br /&gt;
    Gmdn &amp;lt;- function (..., threshold = 1E-6) {&lt;br /&gt;
      # Function F(x) as defined in comic&lt;br /&gt;
      f &amp;lt;- function (x) {&lt;br /&gt;
        n &amp;lt;- length(x)&lt;br /&gt;
        return(c(mean(x), prod(x)^(1/n), median(x)))&lt;br /&gt;
      }&lt;br /&gt;
      # Extract input vector from ... argument&lt;br /&gt;
      x &amp;lt;- c(...)&lt;br /&gt;
      # Iterate until the standard deviation of f(x) reaches a threshold&lt;br /&gt;
      while (sd(x) &amp;gt; threshold) x &amp;lt;- f(x)&lt;br /&gt;
      # Return the mean of the final triplet&lt;br /&gt;
      return(mean(x))&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The input sequence of numbers (1,1,2,3,5) chosen by Randall is also the opening of the {{w|Fibonacci sequence}}.  This may have been selected because the Fibonacci sequence also has a convergent property: the ratio of two adjacent numbers in the sequence approaches the [https://en.wikipedia.org/wiki/Golden_ratio#Relationship_to_Fibonacci_sequence golden ratio] as the length of the sequence approaches infinity.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
F(x1,x2,...xn)=({x1+x2+...+xn/n [bracket: arithmetic mean]},{nx,x2...xn, [bracket: geometric mean]} {x n+1/2 [bracket: median]})&lt;br /&gt;
&lt;br /&gt;
Gmdn(x1,x2,...xn)={F(F(F(...F(x1,x2,...xn)...)))[bracket: geothmetic meandian]}&lt;br /&gt;
&lt;br /&gt;
Gmdn(1,1,2,3,5) [equals about sign] 2.089&lt;br /&gt;
&lt;br /&gt;
Caption: Stats tip: If you aren't sure whether to use the mean, median, or geometric mean, just calculate all three, then repeat until it converges&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
For a start, there is a syntax error. After the first application of F, you get a 3-tuple. Subsequent iterations preserve the 3-tuple, and we need to analyze the resulting sequence.&lt;br /&gt;
Perhaps there is an implicit claim all three entries converge to the same result. In any case, lets see what we get:&lt;br /&gt;
&lt;br /&gt;
Wlog, we have three inputs (x_1,y_1,z_1), and want to understand the iterates of the map &lt;br /&gt;
F(x,y,z) = ( (x+y+z)/3, cube root of (xyz), median(x,y,z) ). Lets write F(x_n,y_n,z_n) = (x_{n+1},y_{n+1},z_{n+1}).&lt;br /&gt;
&lt;br /&gt;
The inequality of arithmetic and geometric means gives x_n \geq y_n, if n \geq 2,  and&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Math]]&lt;br /&gt;
[[Category:Statistics]]&lt;/div&gt;</summary>
		<author><name>Snark</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=2435:_Geothmetic_Meandian&amp;diff=207733</id>
		<title>2435: Geothmetic Meandian</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=2435:_Geothmetic_Meandian&amp;diff=207733"/>
				<updated>2021-03-11T23:47:53Z</updated>
		
		<summary type="html">&lt;p&gt;Snark: Pointing out the GMDN is not correctly defined.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 2435&lt;br /&gt;
| date      = March 10, 2021&lt;br /&gt;
| title     = Geothmetic Meandian&lt;br /&gt;
| image     = geothmetic_meandian.png&lt;br /&gt;
| titletext = Pythagorean means are nice and all, but throwing the median in the pot is really what turns this into random forest statistics: applying every function you can think of, and then gradually dropping the ones that make the result worse.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
&lt;br /&gt;
There are a number of different ways to identify the '{{w|average}}' value of a series of values, the most common unweighted methods being the {{w|median}} (take the central value from the ordered list of values if there are an odd number - or the value half-way between the two that straddle the divide between two halves if there are an even number) and the {{w|arithmetic mean}} (add all the numbers up, divide by the number of numbers). The {{w|geometric mean}} is less well-known but works similarly to the arithmetic mean. To take the geometric mean of 'n' values, they are multiplied and then the 'n'th root is taken. It will be seen that for purely identical values this returns the single value as the singular average, as would the arithmetic calculation with serial addition then re-division, but it reacts differently to any perturbed values. You might also consider operating arithmetically upon logarithms of the list, then re-exponate the result.&lt;br /&gt;
&lt;br /&gt;
It can be shown that the xkcd value of 2.089 for GMDN(1,1,2,3,5) is validated:&lt;br /&gt;
&lt;br /&gt;
{|-&lt;br /&gt;
 | F0 || 1 || 1 || 2 || 3 || 5 &lt;br /&gt;
 |-&lt;br /&gt;
 |    || Ave || Geomean || Median ||&lt;br /&gt;
 |-&lt;br /&gt;
 | F1 || 2.4 || 1.974350486 || 2		&lt;br /&gt;
 |-&lt;br /&gt;
 | F2 || 2.124783495 ||	2.116192461 || 2		&lt;br /&gt;
 |-&lt;br /&gt;
 | F3 || 2.080325319 || 2.079536819 || 2.116192461		&lt;br /&gt;
 |-&lt;br /&gt;
 | F4 || 2.0920182 || 2.091948605 || 2.080325319		&lt;br /&gt;
 |-&lt;br /&gt;
 | F5 || 2.088097374 || 2.088090133 || 2.091948605		&lt;br /&gt;
 |-&lt;br /&gt;
 | F6 || 2.089378704 ||	2.089377914 || 2.088097374		&lt;br /&gt;
 |-&lt;br /&gt;
 | F7 || 2.088951331 ||	2.088951244 || 2.089377914		&lt;br /&gt;
 |-&lt;br /&gt;
 | F8 || 2.089093496 || 2.089093487 || 2.088951331		&lt;br /&gt;
 |-&lt;br /&gt;
 | F9 || 2.089046105 || 2.089046103 || 2.089093487		&lt;br /&gt;
 |-&lt;br /&gt;
 | F10 || '''2.089061898''' || '''2.089061898''' || '''2.089046105'''		&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
Each row shows the set Fn(..) composed of the average, geomean and median computed on the previous row, with the sequence {1,1,2,3,5} as the initial F0.&lt;br /&gt;
Since the average, geomean and median are all forms of averaging, and the composition of averages can be shown to be equivalent to a smoothing function, the value of GMDN will converge to a singular value for any set of starting values. This can be interpreted as similar to a heat equation which approaches equilibrium. &lt;br /&gt;
&lt;br /&gt;
The geometric mean, arithmetic mean and {{w|harmonic mean}} (not shown) are collectively known as the {{w|Pythagorean means}}, as specific modes of a greater and more generalised mean formula that extends arbitrarily to various other possible nuances of mean-value rationisations (cubic, etc).&lt;br /&gt;
&lt;br /&gt;
{{w|Outlier}}s and internal biases within the original sample can make boiling down a set of values into a single 'average' sometimes overly biased by flaws in the data, with your choice of which method to use perhaps resulting in a value that is misleading, exagerating or suppressing the significance of any blips.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Either here or after the next paragraph, demonstrate how (1,1,2,3,5) resolves in each individual method, perhaps? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this depiction, the three named methods of averaging are embedded within a single function that produces a sequence of three values - one output for each of the methods. Being a series of values, Randall suggests that this is ideally suited to being ''itself'' subjected to the comparative 'averaging' method. Not just once, but as many times as it takes to narrow down to a sequence of three values that are very close to one another. However the function GMDN used in the comic is not properly defined since F acts on a vector to produce another three vector and so repeated applications of F will always result in a 3 vector and never a scalar. &lt;br /&gt;
&lt;br /&gt;
The comment in the title text about suggests that this will save you the trouble of committing to the 'wrong' analysis as it gradually shaves down any 'outlier average' that is unduly affected by anomalies in the original inputs. It is a method without any danger of divergence of values, since all three averaging methods stay within the interval covering the input values (and two of them will stay strictly within that interval).&lt;br /&gt;
&lt;br /&gt;
The title text may also be a sly reference to an actual mathematical theorem, namely that if one performs this procedure only using the arithmetic mean and the harmonic mean, the result will converge to the geometric mean. Randal suggests that the (non-Pythagorean) median, which does not have such good mathematical properties with relation to convergence, is, in fact, the secret sauce in his definition.&lt;br /&gt;
&lt;br /&gt;
There does exist an {{w|arithmetic-geometric mean}}, which is defined identically to this except with the arithmetic and geometric means, and sees some use in calculus.  In some ways it's also philosophically similar to the {{w|truncated mean}} (extremities of the value range, e.g. the highest and lowest 10%s, are ignored as not acceptable and not counted) or {{w|Winsorized mean}} (instead of ignored, the values are readjusted to be the chosen floor/ceiling values that they lie beyond, to still effectively be counted as 'edge' conditions), only with a strange dilution-and-compromise method rather than one where quantities can be culled or neutered just for being unexpectedly different from most of the other data.&lt;br /&gt;
&lt;br /&gt;
The following python code (inefficiently) implements the above algorithm:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from functools import reduce&lt;br /&gt;
from itertools import count&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def f(*args):&lt;br /&gt;
    args = sorted(args)&lt;br /&gt;
    mean = sum(args) / len(args)&lt;br /&gt;
    gmean = reduce(lambda x, y: x * y, args) ** (1 / len(args))&lt;br /&gt;
    if len(args) % 2:&lt;br /&gt;
        median = args[len(args) // 2]&lt;br /&gt;
    else:&lt;br /&gt;
        median = (args[len(args) // 2] + args[len(args) // 2 - 1]) / 2&lt;br /&gt;
    return mean, gmean, median&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
max_number_of_iterations = 10&lt;br /&gt;
l0 = [1, 1, 2, 3, 5]&lt;br /&gt;
l = l0&lt;br /&gt;
for iterations in range(max_number_of_iterations):&lt;br /&gt;
    fst, *rest = l&lt;br /&gt;
    if all((abs(r - fst) &amp;lt; 0.00000001 for r in rest)):&lt;br /&gt;
        break&lt;br /&gt;
    l = f(*l)&lt;br /&gt;
print(l[0], iterations)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is an implementation of the Gmdn function in R:&lt;br /&gt;
&lt;br /&gt;
    Gmdn &amp;lt;- function (..., threshold = 1E-6) {&lt;br /&gt;
      # Function F(x) as defined in comic&lt;br /&gt;
      f &amp;lt;- function (x) {&lt;br /&gt;
        n &amp;lt;- length(x)&lt;br /&gt;
        return(c(mean(x), prod(x)^(1/n), median(x)))&lt;br /&gt;
      }&lt;br /&gt;
      # Extract input vector from ... argument&lt;br /&gt;
      x &amp;lt;- c(...)&lt;br /&gt;
      # Iterate until the standard deviation of f(x) reaches a threshold&lt;br /&gt;
      while (sd(x) &amp;gt; threshold) x &amp;lt;- f(x)&lt;br /&gt;
      # Return the mean of the final triplet&lt;br /&gt;
      return(mean(x))&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The input sequence of numbers (1,1,2,3,5) chosen by Randall is also the opening of the {{w|Fibonacci sequence}}.  This may have been selected because the Fibonacci sequence also has a convergent property: the ratio of two adjacent numbers in the sequence approaches the [https://en.wikipedia.org/wiki/Golden_ratio#Relationship_to_Fibonacci_sequence golden ratio] as the length of the sequence approaches infinity.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
{{incomplete transcript|Do NOT delete this tag too soon.}}&lt;br /&gt;
&lt;br /&gt;
F(x1,x2,...xn)=({x1+x2+...+xn/n [bracket: arithmetic mean]},{nx,x2...xn, [bracket: geometric mean]} {x n+1/2 [bracket: median]})&lt;br /&gt;
&lt;br /&gt;
Gmdn(x1,x2,...xn)={F(F(F(...F(x1,x2,...xn)...)))[bracket: geothmetic meandian]}&lt;br /&gt;
&lt;br /&gt;
Gmdn(1,1,2,3,5) [equals about sign] 2.089&lt;br /&gt;
&lt;br /&gt;
Caption: Stats tip: If you aren't sure whether to use the mean, median, or geometric mean, just calculate all three, then repeat until it converges&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
For a start, there is a syntax error. After the first application of F, you get a 3-tuple. Subsequent iterations preserve the 3-tuple, and we need to analyze the resulting sequence.&lt;br /&gt;
Perhaps there is an implicit claim all three entries converge to the same result. In any case, lets see what we get:&lt;br /&gt;
&lt;br /&gt;
Wlog, we have three inputs (x_1,y_1,z_1), and want to understand the iterates of the map &lt;br /&gt;
F(x,y,z) = ( (x+y+z)/3, cube root of (xyz), median(x,y,z) ). Lets write F(x_n,y_n,z_n) = (x_{n+1},y_{n+1},z_{n+1}).&lt;br /&gt;
&lt;br /&gt;
The inequality of arithmetic and geometric means gives x_n \geq y_n, if n \geq 2,  and&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Math]]&lt;br /&gt;
[[Category:Statistics]]&lt;/div&gt;</summary>
		<author><name>Snark</name></author>	</entry>

	</feed>