| 1 |
<html> |
| 2 |
<head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 4 |
<title>Luroth Expansions</title> |
| 5 |
<link rel="stylesheet" href="../../math.css" type="text/css"> |
| 6 |
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> |
| 7 |
<link rel="home" href="../../index.html" title="Math Toolkit 4.2.1"> |
| 8 |
<link rel="up" href="../internals.html" title="Internal tools"> |
| 9 |
<link rel="prev" href="centered_continued_fraction.html" title="Centered Continued Fractions"> |
| 10 |
<link rel="next" href="engel_expansion.html" title="Engel Expansion"> |
| 11 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 12 |
</head> |
| 13 |
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 14 |
<table cellpadding="2" width="100%"><tr> |
| 15 |
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> |
| 16 |
<td align="center"><a href="../../../../../../index.html">Home</a></td> |
| 17 |
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> |
| 18 |
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> |
| 19 |
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> |
| 20 |
<td align="center"><a href="../../../../../../more/index.htm">More</a></td> |
| 21 |
</tr></table> |
| 22 |
<hr> |
| 23 |
<div class="spirit-nav"> |
| 24 |
<a accesskey="p" href="centered_continued_fraction.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../internals.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="engel_expansion.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> |
| 25 |
</div> |
| 26 |
<div class="section"> |
| 27 |
<div class="titlepage"><div><div><h3 class="title"> |
| 28 |
<a name="math_toolkit.internals.luroth_expansion"></a><a class="link" href="luroth_expansion.html" title="Luroth Expansions">Luroth Expansions</a> |
| 29 |
</h3></div></div></div> |
| 30 |
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">tools</span><span class="special">/</span><span class="identifier">luroth_expansion</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> |
| 31 |
<span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span> <span class="special">{</span> |
| 32 |
|
| 33 |
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Real</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Z</span> <span class="special">=</span> <span class="identifier">int64_t</span><span class="special">></span> |
| 34 |
<span class="keyword">class</span> <span class="identifier">luroth_expansion</span> <span class="special">{</span> |
| 35 |
<span class="keyword">public</span><span class="special">:</span> |
| 36 |
<span class="identifier">luroth_expansion</span><span class="special">(</span><span class="identifier">Real</span> <span class="identifier">x</span><span class="special">);</span> |
| 37 |
|
| 38 |
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">Z</span><span class="special">></span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">digits</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> |
| 39 |
|
| 40 |
<span class="identifier">Real</span> <span class="identifier">digit_geometric_mean</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> |
| 41 |
|
| 42 |
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Z_</span><span class="special">></span> |
| 43 |
<span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&</span> <span class="keyword">operator</span><span class="special"><<(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&</span> <span class="identifier">out</span><span class="special">,</span> <span class="identifier">luroth_expansion</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Z_</span><span class="special">>&</span> <span class="identifier">luroth</span><span class="special">);</span> |
| 44 |
<span class="special">};</span> |
| 45 |
<span class="special">}</span> |
| 46 |
</pre> |
| 47 |
<p> |
| 48 |
The <code class="computeroutput"><span class="identifier">luroth_expansion</span></code> class |
| 49 |
provided by Boost expands a floating point number into a Lüroth representation, |
| 50 |
i.e., |
| 51 |
</p> |
| 52 |
<p> |
| 53 |
<span class="inlinemediaobject"><object type="image/svg+xml" data="../../../equations/luroth_expansion.svg" width="457" height="55"></object></span> |
| 54 |
</p> |
| 55 |
<p> |
| 56 |
The numbers <span class="emphasis"><em>d</em></span><sub>i</sub> are called digits or denominators; we |
| 57 |
use the terminology digits, since technically in our notation <span class="emphasis"><em>d</em></span><sub>0</sub> is |
| 58 |
not a denominator. |
| 59 |
</p> |
| 60 |
<p> |
| 61 |
Here's a minimal working example: |
| 62 |
</p> |
| 63 |
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special">;</span> |
| 64 |
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">luroth_expansion</span><span class="special">;</span> |
| 65 |
<span class="keyword">auto</span> <span class="identifier">luroth</span> <span class="special">=</span> <span class="identifier">luroth_expansion</span><span class="special">(</span><span class="identifier">pi</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">double</span><span class="special">>());</span> |
| 66 |
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"π ≈ "</span> <span class="special"><<</span> <span class="identifier">luroth</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span> |
| 67 |
<span class="comment">// Prints:</span> |
| 68 |
<span class="comment">// π ≈ ((3; 7, 1, 1, 1, 2, 1, 4, 23, 4, 1, 1, 1, 1, 80, 1, 1, 5))</span> |
| 69 |
</pre> |
| 70 |
<p> |
| 71 |
The class computes denominators while simultaneously computing convergents. |
| 72 |
Once a convergent is within a few ulps of the input value, the computation |
| 73 |
stops. |
| 74 |
</p> |
| 75 |
<p> |
| 76 |
<span class="emphasis"><em>Nota bene:</em></span> There is an alternative definition of the |
| 77 |
Lüroth representation where every digit is shifted by 1. We follow the definition |
| 78 |
given in Kalpazidou; with the modification that we do not constrain the input |
| 79 |
to be in the interval [0,1] and let the first digit be the floor of the input. |
| 80 |
</p> |
| 81 |
<p> |
| 82 |
For almost all real numbers, the geometric mean of the digits converges to |
| 83 |
a constant which is approximately 2.2001610580. This is "Khinchin's |
| 84 |
constant" for the Lüroth representation. |
| 85 |
</p> |
| 86 |
<h5> |
| 87 |
<a name="math_toolkit.internals.luroth_expansion.h0"></a> |
| 88 |
<span class="phrase"><a name="math_toolkit.internals.luroth_expansion.references"></a></span><a class="link" href="luroth_expansion.html#math_toolkit.internals.luroth_expansion.references">References</a> |
| 89 |
</h5> |
| 90 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 91 |
<li class="listitem"> |
| 92 |
Kalpazidou, Sofia. "Khintchine's constant for Lüroth representation." |
| 93 |
Journal of Number Theory 29.2 (1988): 196-205. |
| 94 |
</li> |
| 95 |
<li class="listitem"> |
| 96 |
Finch, Steven R. Mathematical constants. Cambridge university press, |
| 97 |
2003. |
| 98 |
</li> |
| 99 |
</ul></div> |
| 100 |
</div> |
| 101 |
<div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland, |
| 102 |
Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno |
| 103 |
Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde, |
| 104 |
Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle |
| 105 |
Walker and Xiaogang Zhang<p> |
| 106 |
Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 107 |
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) |
| 108 |
</p> |
| 109 |
</div> |
| 110 |
<hr> |
| 111 |
<div class="spirit-nav"> |
| 112 |
<a accesskey="p" href="centered_continued_fraction.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../internals.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="engel_expansion.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> |
| 113 |
</div> |
| 114 |
</body> |
| 115 |
</html> |