Ginger 1.1.9
Loading...
Searching...
No Matches
rootfinding.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <utility>
9#include <vector>
10
11#include "matrix2.hpp"
12#include "vector2.hpp"
13
16
23namespace ginger {
24 class Options;
25}
26
45extern auto initial_guess(std::vector<double> coeffs) -> std::vector<Vec2>;
46
75extern auto pbairstow_even_st(const std::vector<double>& coeffs, std::vector<Vec2>& vrs,
76 const ginger::Options& options) -> std::pair<unsigned int, bool>;
77
78inline auto pbairstow_even(const std::vector<double>& coeffs, std::vector<Vec2>& vrs,
79 const ginger::Options& options) -> std::pair<unsigned int, bool> {
81}
82
103extern auto horner(std::vector<double>& coeffs1, std::size_t degree, const Vec2& vr) -> Vec2;
104
117extern auto suppress_old(Vec2& vA, Vec2& vA1, const Vec2& vri, const Vec2& vrj) -> void;
118
133extern auto suppress(Vec2& vA, Vec2& vA1, const Vec2& vri, const Vec2& vrj) -> void;
134
151extern auto suppress2(Vec2& vA, Vec2& vA1, const Vec2& vri, const Vec2& vrj) -> void;
152
168inline auto makeadjoint(const Vec2& vr, const Vec2& vp) -> Mat2 {
169 auto&& p = vp.x();
170 auto&& s = vp.y();
171 return {Vec2{s, -p}, Vec2{-p * vr.y(), p * vr.x() + s}};
172}
173
188inline auto delta_scalar(const Vec2& vA, const Vec2& vr, const Vec2& vp) -> Vec2 {
189 const auto r = vr.x();
190 const auto q = vr.y();
191 const auto p = vp.x();
192 const auto s = vp.y();
193 // adj = [[s, -p], [-p*q, p*r + s]]
194 // det = s*(p*r + s) - p*p*q
195 const auto det = s * (p * r + s) - p * p * q;
196 // mdot_x = s*vA.x + (-p)*vA.y
197 // mdot_y = (-p*q)*vA.x + (p*r + s)*vA.y
198 const auto mx = s * vA.x() - p * vA.y();
199 const auto my = -p * q * vA.x() + (p * r + s) * vA.y();
200 return Vec2{mx / det, my / det};
201}
202
218inline auto delta(const Vec2& vA, const Vec2& vr, const Vec2& vp) -> Vec2 {
219 const auto mp = makeadjoint(vr, vp); // 2 mul's
220 return mp.mdot(vA) / mp.det(); // 6 mul's + 2 div's
221}
222
241inline auto horner_eval(std::vector<double> coeffs1, std::size_t degree, const double& z)
242 -> double {
243 for (auto idx = 0U; idx != degree; ++idx) {
244 coeffs1[idx + 1] += coeffs1[idx] * z;
245 }
246 return coeffs1[degree];
247}
248
262extern auto poly_from_quadratic_factors(const std::vector<Vec2>& vrs) -> std::vector<double>;
constexpr auto make_vdc_table() -> std::array< double, N >
Helper to generate a constexpr table of VdCorput<Base> values.
Definition aberth.hpp:21
Matrix2.
Definition matrix2.hpp:28
constexpr auto x() const -> const T1 &
Get the first column vector.
Definition matrix2.hpp:47
Definition config.hpp:19
Vector2.
Definition vector2.hpp:19
constexpr auto y() const noexcept -> const T2 &
Definition vector2.hpp:81
constexpr auto x() const noexcept -> const T1 &
Definition vector2.hpp:74
2x2 matrix template for polynomial root-finding
Options for convergence-based algorithms.
Definition aberth.hpp:13
auto initial_guess(std::vector< double > coeffs) -> std::vector< Vec2 >
Initial guess for the parallel Bairstow method.
auto suppress(Vec2 &vA, Vec2 &vA1, const Vec2 &vri, const Vec2 &vrj) -> void
Zero suppression step in Bairstow's method (matrix variant)
auto suppress_old(Vec2 &vA, Vec2 &vA1, const Vec2 &vri, const Vec2 &vrj) -> void
Zero suppression step in Bairstow's method (scalar arithmetic)
auto pbairstow_even_st(const std::vector< double > &coeffs, std::vector< Vec2 > &vrs, const ginger::Options &options) -> std::pair< unsigned int, bool >
Single-threading Bairstow's method (even degree only)
auto horner_eval(std::vector< double > coeffs1, std::size_t degree, const double &z) -> double
Definition rootfinding.hpp:241
auto makeadjoint(const Vec2 &vr, const Vec2 &vp) -> Mat2
Create adjoint matrix from two vectors.
Definition rootfinding.hpp:168
auto delta_scalar(const Vec2 &vA, const Vec2 &vr, const Vec2 &vp) -> Vec2
Calculate Newton correction delta (scalar arithmetic, no Matrix2 temporaries)
Definition rootfinding.hpp:188
auto poly_from_quadratic_factors(const std::vector< Vec2 > &vrs) -> std::vector< double >
Reconstruct a monic polynomial from its quadratic factors.
auto suppress2(Vec2 &vA, Vec2 &vA1, const Vec2 &vri, const Vec2 &vrj) -> void
Zero suppression step in Bairstow's method (variant 2)
auto horner(std::vector< double > &coeffs1, std::size_t degree, const Vec2 &vr) -> Vec2
Horner's rule.
auto pbairstow_even(const std::vector< double > &coeffs, std::vector< Vec2 > &vrs, const ginger::Options &options) -> std::pair< unsigned int, bool >
Definition rootfinding.hpp:78
ginger::Vector2< double > Vec2
Definition rootfinding.hpp:14
auto delta(const Vec2 &vA, const Vec2 &vr, const Vec2 &vp) -> Vec2
Calculate Newton correction delta (matrix-based)
Definition rootfinding.hpp:218