Ginger 1.1.9
Loading...
Searching...
No Matches
aberth.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <complex>
9#include <lds/lds.hpp>
10#include <utility>
11#include <vector>
12
13namespace ginger {
14 class Options;
15}
16
21template <unsigned long N, unsigned long Base = 2> constexpr auto make_vdc_table()
22 -> std::array<double, N> {
23 std::array<double, N> table{};
24 lds::VdCorput<Base> gen;
25 for (unsigned long i = 0; i < N; ++i) {
26 table[i] = gen.pop();
27 }
28 return table;
29}
30
32constexpr const auto VDC_TABLE_SIZE = 1000UL;
33
36constexpr std::array<double, VDC_TABLE_SIZE> VDC_TABLE_2 = make_vdc_table<VDC_TABLE_SIZE, 2>();
37
41inline double vdc2_table(unsigned long index) { return VDC_TABLE_2[index]; }
42
47inline auto make_circle_table() noexcept -> std::array<std::array<double, 2>, VDC_TABLE_SIZE> {
48 std::array<std::array<double, 2>, VDC_TABLE_SIZE> table{};
49 for (unsigned long i = 0; i < VDC_TABLE_SIZE; ++i) {
50 auto theta = VDC_TABLE_2[i] * lds::TWO_PI;
51 table[i] = {std::cos(theta), std::sin(theta)};
52 }
53 return table;
54}
55
59static const auto CIRCLE_TABLE_2 = make_circle_table();
60
64 std::array<double, VDC_TABLE_SIZE> table{};
65 for (unsigned long i = 0; i < VDC_TABLE_SIZE; ++i) {
66 table[i] = std::cos(lds::TWO_PI / 2.0 * VDC_TABLE_2[i]);
67 }
68 return table;
69}
70
73static const auto COS_PI_VDC2_TABLE = make_cos_pi_vdc2_table();
74
78constexpr double cos_pi_vdc2(unsigned long index) { return COS_PI_VDC2_TABLE[index]; }
79
83constexpr double circle2_table_x(unsigned long index) { return CIRCLE_TABLE_2[index][0]; }
84
88constexpr double circle2_table_y(unsigned long index) { return CIRCLE_TABLE_2[index][1]; }
89
114inline auto horner_eval_c(const std::vector<double>& coeffs, const std::complex<double>& zval)
115 -> std::complex<double> {
116 std::complex<double> result(0.0, 0.0);
117 for (auto coeff : coeffs) {
118 result = result * zval + coeff;
119 }
120 return result;
121}
122
133inline auto horner_eval_f(const std::vector<double>& coeffs, const double& zval) -> double {
134 double result(0.0);
135 for (auto coeff : coeffs) {
136 result = result * zval + coeff;
137 }
138 return result;
139}
140
155extern auto initial_aberth(const std::vector<double>& coeffs) -> std::vector<std::complex<double>>;
156
202extern auto aberth(const std::vector<double>& coeffs, std::vector<std::complex<double>>& zs,
203 const ginger::Options& options) -> std::pair<unsigned int, bool>;
204
219extern auto initial_aberth_autocorr(const std::vector<double>& coeffs)
220 -> std::vector<std::complex<double>>;
221
247extern auto aberth_autocorr(const std::vector<double>& coeffs,
248 std::vector<std::complex<double>>& zs, const ginger::Options& options)
249 -> std::pair<unsigned int, bool>;
250
263extern auto poly_from_roots(const std::vector<std::complex<double>>& zs) -> std::vector<double>;
264
281extern auto leja_order(const std::vector<std::complex<double>>& points)
282 -> std::vector<std::complex<double>>;
283
299extern auto poly_from_autocorr_roots(const std::vector<std::complex<double>>& zs)
300 -> std::vector<double>;
constexpr std::array< double, VDC_TABLE_SIZE > VDC_TABLE_2
Precomputed table of VdCorput sequence values (base 2)
Definition aberth.hpp:36
auto poly_from_roots(const std::vector< std::complex< double > > &zs) -> std::vector< double >
Reconstruct a monic polynomial from its complex roots.
auto horner_eval_f(const std::vector< double > &coeffs, const double &zval) -> double
Definition aberth.hpp:133
auto horner_eval_c(const std::vector< double > &coeffs, const std::complex< double > &zval) -> std::complex< double >
Definition aberth.hpp:114
constexpr auto make_vdc_table() -> std::array< double, N >
Helper to generate a constexpr table of VdCorput<Base> values.
Definition aberth.hpp:21
constexpr double cos_pi_vdc2(unsigned long index)
Access the precomputed cos(pi * vdc2_table[i]) value.
Definition aberth.hpp:78
constexpr double circle2_table_x(unsigned long index)
Access the precomputed Circle base-2 table x-coordinate.
Definition aberth.hpp:83
auto poly_from_autocorr_roots(const std::vector< std::complex< double > > &zs) -> std::vector< double >
Reconstruct a monic polynomial from its autocorrelation roots.
auto initial_aberth_autocorr(const std::vector< double > &coeffs) -> std::vector< std::complex< double > >
Initial guess for the Aberth-Ehrlich method (specifically for auto-correlation functions)
auto aberth_autocorr(const std::vector< double > &coeffs, std::vector< std::complex< double > > &zs, const ginger::Options &options) -> std::pair< unsigned int, bool >
Single-threading Aberth-Ehrlich method (specifically for auto-correlation functions)
auto initial_aberth(const std::vector< double > &coeffs) -> std::vector< std::complex< double > >
Initial guess for the Aberth-Ehrlich method.
constexpr const auto VDC_TABLE_SIZE
Size of the precomputed VdCorput base-2 table.
Definition aberth.hpp:32
auto make_cos_pi_vdc2_table() noexcept -> std::array< double, VDC_TABLE_SIZE >
Helper to generate the precomputed cos(pi * vdc2_table[i]) table.
Definition aberth.hpp:63
double vdc2_table(unsigned long index)
Access the precomputed VdCorput base-2 table.
Definition aberth.hpp:41
auto make_circle_table() noexcept -> std::array< std::array< double, 2 >, VDC_TABLE_SIZE >
Helper to generate the precomputed Circle base-2 table.
Definition aberth.hpp:47
auto aberth(const std::vector< double > &coeffs, std::vector< std::complex< double > > &zs, const ginger::Options &options) -> std::pair< unsigned int, bool >
Single-threading Aberth-Ehrlich method.
auto leja_order(const std::vector< std::complex< double > > &points) -> std::vector< std::complex< double > >
Leja ordering of complex points.
constexpr double circle2_table_y(unsigned long index)
Access the precomputed Circle base-2 table y-coordinate.
Definition aberth.hpp:88
Definition config.hpp:19
Options for convergence-based algorithms.
Definition aberth.hpp:13