2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Luroth expansions (#401)

This commit is contained in:
Nick
2020-07-18 09:28:39 -04:00
committed by GitHub
parent dfca1aaa36
commit ee2cd5d5e5
7 changed files with 317 additions and 0 deletions

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,62 @@
[/
Copyright Nick Thompson, 2020
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
]
[section:luroth_expansion Luroth Expansions]
#include <boost/math/tools/luroth_expansion.hpp>
namespace boost::math::tools {
template<typename Real, typename Z = int64_t>
class luroth_expansion {
public:
luroth_expansion(Real x);
std::vector<Z> const & digits() const;
Real digit_geometric_mean() const;
template<typename T, typename Z_>
friend std::ostream& operator<<(std::ostream& out, luroth_expansion<T, Z_>& luroth);
};
}
The `luroth_expansion` class provided by Boost expands a floating point number into a Lüroth representation, i.e.,
[$../equations/luroth_expansion.svg]
The numbers /d/[sub i] are called digits or denominators; we use the terminology digits, since technically in our notation /d/[sub 0] is not a denominator.
Here's a minimal working example:
using boost::math::constants::pi;
using boost::math::tools::luroth_expansion;
auto luroth = luroth_expansion(pi<long double>());
std::cout << "π ≈ " << luroth << "\n";
// Prints:
// π ≈ ((3; 7, 1, 1, 1, 2, 1, 4, 23, 4, 1, 1, 1, 1, 80, 1, 1, 5))
The class computes denominators while simultaneously computing convergents.
Once a convergent is within a few ulps of the input value, the computation stops.
/Nota bene:/ There is an alternative definition of the Lüroth representation where every digit is shifted by 1.
We follow the definition given in Kalpazidou; with the modification that we do not constrain the input to be in the interval [0,1]
and let the first digit be the floor of the input.
For almost all real numbers, the geometric mean of the digits converges to a constant which is approximately 2.2001610580.
This is "Khinchin's constant" for the Lüroth representation.
[heading References]
* Kalpazidou, Sofia. "Khintchine's constant for Lüroth representation." Journal of Number Theory 29.2 (1988): 196-205.
* Finch, Steven R. Mathematical constants. Cambridge university press, 2003.
[endsect]

View File

@@ -753,6 +753,7 @@ and as a CD ISBN 0-9504833-2-X 978-0-9504833-2-0, Classification 519.2-dc22.
[include internals/fraction.qbk]
[include internals/simple_continued_fraction.qbk]
[include internals/centered_continued_fraction.qbk]
[include internals/luroth_expansion.qbk]
[include internals/recurrence.qbk]
[/include internals/rational.qbk] [/moved to tools]
[include internals/tuple.qbk]