Shameless plug: our JS fraction library https://github.com/SheetJS/frac implements the mediant as well as the Aberth algorithm.
Shameless plug: our JS fraction library https://github.com/SheetJS/frac implements the mediant as well as the Aberth algorithm.
The Aberth algorithm (I hadn't heard it called that; nice to know) is much more efficient--it converges quadratically.
Another thing I heard, but have not been able to prove (and is not in the Wiki article), is that if you record whether you take the Left or Right segments in the algorithm, you can construct a continued fraction for any real number as int(N) + 1 / (1 (L -> -, R -> +) (number of times you took that direction before "turning around") / 1 (L -> -, R -> +) (#direction) ... ))).
My inability to prove may be primarily because I never really got the flavor of proofs about continued/infinite fractions -- considering the source I'd say it's likely true (or I misremembered).
You don't happen to know where I'd look for hints on the proof there, do you? :)
Suppose you were at a point in the mediant algorithm where the two terms were a/b and c/d. Taking the left segment transforms this to [a/b, (a+c)/(b+d)] and taking the right segment transforms this to [(a+c)/(b+d), c/d].
Represent this as a matrix of the form [[a,b],[c,d]]. In this form, what does "take the left segment" look like in terms of a matrix operation? what does "take the right segment" look like? Can you find any useful properties (for example, how do you repeat)
A convenient root matrix is [[0,1],[1,0]]
Such a beautiful circle of ideas!