Skip to content

Commit b547ac7

Browse files
committed
Update docs
1 parent 08f0490 commit b547ac7

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

doc/internals/simple_continued_fraction.qbk

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[/
22
Copyright Nick Thompson, 2020
3+
Copyright Matt Borland, 2023
34
Distributed under the Boost Software License, Version 1.0.
45
(See accompanying file LICENSE_1_0.txt or copy at
56
http://www.boost.org/LICENSE_1_0.txt).
@@ -19,9 +20,17 @@
1920

2021
Real khinchin_harmonic_mean() const;
2122

22-
template<typename T, typename Z_>
23-
friend std::ostream& operator<<(std::ostream& out, simple_continued_fraction<T, Z>& scf);
23+
const std::vector<Z>& partial_denominators() const;
24+
25+
inline std::vector<Z>&& get_data() noexcept;
26+
27+
template<typename T, typename Z2>
28+
friend std::ostream& operator<<(std::ostream& out, simple_continued_fraction<T, Z2>& scf);
2429
};
30+
31+
template<typename Real, typename Z = int64_t>
32+
inline std::vector<Z> simple_continued_fraction_coefficients(Real x);
33+
2534
}
2635

2736

@@ -47,6 +56,35 @@ This is because when examining known values like π, it creates a large number o
4756
It may be the case the a few incorrect partial convergents is harmless, but we compute continued fractions because we would like to do something with them.
4857
One sensible thing to do it to ask whether the number is in some sense "random"; a question that can be partially answered by computing the Khinchin geometric mean
4958

59+
If you only require the coefficients of the simple continued fraction for example in the calculation of [@https://en.wikipedia.org/wiki/Continued_fraction#Best_rational_approximations best rational approximations] there is a free function for that.
60+
61+
An example of this calculation follows:
62+
63+
using boost::math::tools::simple_continued_fraction_coefficients;
64+
65+
auto coefs1 = simple_continued_fraction_coefficients(static_cast<Real>(3.14155L)); // [3; 7, 15, 2, 7, 1, 4, 2]
66+
auto coefs2 = simple_continued_fraction_coefficients(static_cast<Real>(3.14165L)); // [3; 7, 16, 1, 3, 4, 2, 4]
67+
68+
const std::size_t max_size = (std::min)(coefs1.size(), coefs2.size());
69+
std::vector<std::int64_t> coefs;
70+
coefs.reserve(max_size);
71+
72+
for (std::size_t i = 0; i < max_size; ++i)
73+
{
74+
const auto c1 = coefs1[i];
75+
const auto c2 = coefs2[i];
76+
if (c1 == c2)
77+
{
78+
coefs.emplace_back(c1);
79+
continue;
80+
}
81+
82+
coefs.emplace_back((std::min)(c1, c2) + 1);
83+
break;
84+
}
85+
86+
// Result is [3; 7, 16]
87+
5088
[$../equations/khinchin_geometric.svg]
5189

5290
and Khinchin harmonic mean

0 commit comments

Comments
 (0)