Ginger 1.1.5; VERSION ${PROJECT_VERSION}
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
23class Options;
24
43extern auto initial_guess(std::vector<double> coeffs) -> std::vector<Vec2>;
44
90extern auto pbairstow_even_st(const std::vector<double>& coeffs, std::vector<Vec2>& vrs,
91 const Options& options) -> std::pair<unsigned int, bool>;
92
93extern auto pbairstow_even_mt(const std::vector<double>& coeffs, std::vector<Vec2>& vrs,
94 const Options& options) -> std::pair<unsigned int, bool>;
95
96inline auto pbairstow_even(const std::vector<double>& coeffs, std::vector<Vec2>& vrs,
97 const Options& options) -> std::pair<unsigned int, bool> {
98 return pbairstow_even_st(coeffs, vrs, options);
99}
100
121extern auto horner(std::vector<double>& coeffs1, std::size_t degree, const Vec2& vr) -> Vec2;
122
135extern auto suppress_old(Vec2& vA, Vec2& vA1, const Vec2& vri, const Vec2& vrj) -> void;
136
151extern auto suppress(Vec2& vA, Vec2& vA1, const Vec2& vri, const Vec2& vrj) -> void;
152
169extern auto suppress2(Vec2& vA, Vec2& vA1, const Vec2& vri, const Vec2& vrj) -> void;
170
186inline auto makeadjoint(const Vec2& vr, const Vec2& vp) -> Mat2 {
187 auto&& p = vp.x();
188 auto&& s = vp.y();
189 return {Vec2{s, -p}, Vec2{-p * vr.y(), p * vr.x() + s}};
190}
191
206inline auto delta_scalar(const Vec2& vA, const Vec2& vr, const Vec2& vp) -> Vec2 {
207 const auto r = vr.x();
208 const auto q = vr.y();
209 const auto p = vp.x();
210 const auto s = vp.y();
211 // adj = [[s, -p], [-p*q, p*r + s]]
212 // det = s*(p*r + s) - p*p*q
213 const auto det = s * (p * r + s) - p * p * q;
214 // mdot_x = s*vA.x + (-p)*vA.y
215 // mdot_y = (-p*q)*vA.x + (p*r + s)*vA.y
216 const auto mx = s * vA.x() - p * vA.y();
217 const auto my = -p * q * vA.x() + (p * r + s) * vA.y();
218 return Vec2{mx / det, my / det};
219}
220
236inline auto delta(const Vec2& vA, const Vec2& vr, const Vec2& vp) -> Vec2 {
237 const auto mp = makeadjoint(vr, vp); // 2 mul's
238 return mp.mdot(vA) / mp.det(); // 6 mul's + 2 div's
239}
240
259inline auto horner_eval(std::vector<double> coeffs1, std::size_t degree, const double& z)
260 -> double {
261 for (auto idx = 0U; idx != degree; ++idx) {
262 coeffs1[idx + 1] += coeffs1[idx] * z;
263 }
264 return coeffs1[degree];
265}
266
280extern auto poly_from_quadratic_factors(const std::vector<Vec2>& vrs) -> std::vector<double>;
Options for convergence-based algorithms.
Definition config.hpp:15
Matrix2.
Definition matrix2.hpp:28
constexpr auto x() const -> const T1 &
Get the first column vector.
Definition matrix2.hpp:47
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
auto pbairstow_even(const std::vector< double > &coeffs, std::vector< Vec2 > &vrs, const Options &options) -> std::pair< unsigned int, bool >
Definition rootfinding.hpp:96
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_mt(const std::vector< double > &coeffs, std::vector< Vec2 > &vrs, const Options &options) -> std::pair< unsigned int, bool >
auto horner_eval(std::vector< double > coeffs1, std::size_t degree, const double &z) -> double
Definition rootfinding.hpp:259
auto makeadjoint(const Vec2 &vr, const Vec2 &vp) -> Mat2
Create adjoint matrix from two vectors.
Definition rootfinding.hpp:186
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:206
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_st(const std::vector< double > &coeffs, std::vector< Vec2 > &vrs, const Options &options) -> std::pair< unsigned int, bool >
Multi-threading Bairstow's method (even degree only)
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:236