LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
LMCAS::Polynomial< CoeffType > 模板类 参考

一元多项式模板类 更多...

#include <polynomial.hpp>

类 LMCAS::Polynomial< CoeffType > 继承关系图:
LMCAS::Polynomial< CoeffType > 的协作图:

Public 成员函数

 Polynomial (const CoeffType &c, const std::string &var="x")
 从单个常数构造常数多项式
 Polynomial (const std::string &var="x")
 构造零多项式
 Polynomial (const std::vector< CoeffType > &c, const std::string &var="x")
 从系数向量构造多项式
CoeffType content () const
 计算多项式的容度(所有系数的 GCD)
int degree () const
 获取多项式的次数
Polynomial differentiate () const
 求导
std::pair< Polynomial, Polynomial > div_mod (const Polynomial &other) const
 多项式带余除法
CoeffType eval (const CoeffType &val) const
 对多项式求值(Horner 法)
bool is_zero () const
 判断是否为零多项式
CoeffType lead_coeff () const
 获取首项系数
Polynomial make_monic () const
 首一化(使首项系数为 1)
Polynomial operator* (const Polynomial &other) const
 多项式乘法
Polynomial operator+ (const Polynomial &other) const
 多项式加法
Polynomial operator- (const Polynomial &other) const
 多项式减法
bool operator== (const Polynomial &other) const
 多项式判等
Polynomial primitive_part () const
 计算多项式的本原部分(除以容度)
std::pair< Polynomial, Polynomial > pseudo_div_mod (const Polynomial &other) const
 通过系数缩放执行伪除法,运算保持在原系数环
Polynomial pseudo_div_mod_rem (const Polynomial &other) const
 伪除法取余数
Polynomial square_free_part () const
 计算无平方因子部分
std::string to_string () const
 转换为字符串表示
void trim ()
 去除高次零系数

静态 Public 成员函数

static Polynomial gcd (Polynomial a, Polynomial b)
 计算两个多项式的最大公因式
static CoeffType gcd_coeff (const CoeffType &a, const CoeffType &b)
 计算两个系数的 GCD(静态方法)

Public 属性

std::vector< CoeffType > coeffs
 系数数组,coeffs[i] 为 x^i 的系数
std::string variable_name
 变量名

Private 成员函数

void append_string_term (std::string &text, CoeffType coefficient, int power) const
void require_compatible_variables (const Polynomial &other, const char *operation) const
bool variables_compatible (const Polynomial &other) const

详细描述

template<typename CoeffType>
class LMCAS::Polynomial< CoeffType >

一元多项式模板类

模板参数
CoeffType系数类型(支持 BigInt,Rational,int 等)

系数按升幂存储:coeffs[i] 对应 x^i 的系数. 非零操作数必须属于同一命名变量环(包括显式常数),否则算术、 带余除法、伪除法和 GCD 抛出 std::invalid_argument,判等返回 false。 加减乘中的零元素嵌入非零侧变量环;双方为零时保留左侧变量环。 零被除数的商和余数采用除数变量环;零除数始终非法。

在文件 polynomial.hpp 第 52 行定义.

构造及析构函数说明

◆ Polynomial() [1/3]

template<typename CoeffType>
LMCAS::Polynomial< CoeffType >::Polynomial ( const std::string & var = "x")
inline

构造零多项式

参数
var变量名,默认 "x"

在文件 polynomial.hpp 第 62 行定义.

一元多项式模板类
std::string variable_name
变量名

被这些函数引用 LMCAS::anonymous_namespace{poly_utils.cpp}::constant_to_poly(), LMCAS::Polynomial< Rational >::differentiate(), LMCAS::Polynomial< Rational >::div_mod(), gcd(), primitive_part(), pseudo_div_mod(), pseudo_div_mod_rem(), LMCAS::rational_to_symbolic_poly(), square_free_part() , 以及 LMCAS::symbolic_to_poly_recursive().

这是这个函数的调用关系图:

◆ Polynomial() [2/3]

template<typename CoeffType>
LMCAS::Polynomial< CoeffType >::Polynomial ( const std::vector< CoeffType > & c,
const std::string & var = "x" )
inline

从系数向量构造多项式

参数
c系数向量(升幂排列)
var变量名

在文件 polynomial.hpp 第 69 行定义.

71 trim();
72 }
std::vector< CoeffType > coeffs
系数数组,coeffs[i] 为 x^i 的系数
void trim()
去除高次零系数

◆ Polynomial() [3/3]

template<typename CoeffType>
LMCAS::Polynomial< CoeffType >::Polynomial ( const CoeffType & c,
const std::string & var = "x" )
inline

从单个常数构造常数多项式

参数
c常数值
var变量名

在文件 polynomial.hpp 第 79 行定义.

81 trim();
82 }

成员函数说明

◆ append_string_term()

template<typename CoeffType>
void LMCAS::Polynomial< CoeffType >::append_string_term ( std::string & text,
CoeffType coefficient,
int power ) const
inlineprivate

在文件 polynomial.hpp 第 390 行定义.

390 {
391 const bool positive = !(coefficient < CoeffType(0));
392 if (!text.empty()) {
393 text += positive ? " + " : " - ";
394 } else if (!positive) {
395 text += "-";
396 }
397 if (!positive) {
399 }
400 if (!(coefficient == CoeffType(1)) || power == 0) {
401 if constexpr (std::is_same_v<CoeffType, BigInt> ||
404 } else {
406 }
407 if (power > 0) {
408 text += "*";
409 }
410 }
411 if (power > 0) {
413 }
414 if (power > 1) {
415 text += "^" + std::to_string(power);
416 }
417 }
std::string to_string() const
转换为字符串表示

◆ content()

template<typename CoeffType>
CoeffType LMCAS::Polynomial< CoeffType >::content ( ) const
inline

计算多项式的容度(所有系数的 GCD)

返回
容度值

在文件 polynomial_division.hpp 第 9 行定义.

9 {
10 if (is_zero()) return CoeffType(0);
11 CoeffType g = coeffs[0];
12
14 return CoeffType(1);
15 } else {
16
17 for (size_t i = 1; i < coeffs.size(); ++i) {
18 g = gcd_coeff(g, coeffs[i]);
19 if (g == CoeffType(1)) break;
20 }
21 return g;
22 }
23}
static CoeffType gcd_coeff(const CoeffType &a, const CoeffType &b)
计算两个系数的 GCD(静态方法)
bool is_zero() const
判断是否为零多项式

引用了 coeffs, gcd_coeff() , 以及 is_zero().

被这些函数引用 primitive_part().

函数调用图:
这是这个函数的调用关系图:

◆ degree()

template<typename CoeffType>
int LMCAS::Polynomial< CoeffType >::degree ( ) const
inline

获取多项式的次数

返回
次数;零多项式返回 -1

在文件 polynomial.hpp 第 100 行定义.

100 {
101 if (coeffs.empty()) return -1;
102 return static_cast<int>(coeffs.size()) - 1;
103 }

被这些函数引用 LMCAS::RootOfNode::RootOfNode(), LMCAS::detail::inequality_support::append_factor_roots(), LMCAS::append_factor_solutions(), LMCAS::berlekamp_factor(), LMCAS::berlekamp_detail::bk_is_suitable_prime(), LMCAS::berlekamp_detail::bk_select_prime(), LMCAS::polynomial_solver_detail::bounded_rational_root_search(), LMCAS::anonymous_namespace{univariate_factor_bridge.cpp}::bridge_append_repeated(), LMCAS::anonymous_namespace{univariate_factor_bridge.cpp}::bridge_lift_bound(), LMCAS::anonymous_namespace{univariate_factor_bridge.cpp}::bridge_reduction(), LMCAS::detail::count_real_roots_exact(), LMCAS::detail::complex_root::count_rectangle_roots(), LMCAS::deflate_rational_root(), LMCAS::diophantine_target(), LMCAS::diophantine_univariate_factors(), LMCAS::Polynomial< Rational >::div_mod(), LMCAS::detail::complex_root::anonymous_namespace{complex_root_winding.cpp}::edge_is_clear(), LMCAS::detail::evaluate_root_real(), LMCAS::exact_factor_roots(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::exact_polynomial_sign_intervals(), LMCAS::detail::anonymous_namespace{complex_root_isolation.cpp}::factor_biquadratic(), LMCAS::detail::factor_denominator(), LMCAS::factor_univariate_bridge_checked(), LMCAS::find_rational_roots(), LMCAS::get_coeff(), LMCAS::anonymous_namespace{residual_verification.cpp}::has_zero_root_remainder(), LMCAS::hl_compute_lift_height(), LMCAS::hl_mignotte_bound(), LMCAS::hl_validate_lift_inputs(), LMCAS::detail::homogenize_factor(), LMCAS::detail::integrate_rational_term(), LMCAS::detail::isolate_exact_roots(), LMCAS::detail::isolate_real_roots_exact(), LMCAS::detail::anonymous_namespace{complex_root_isolation.cpp}::isolate_unfactored(), LMCAS::detail::make_exact_real_algebraic(), LMCAS::detail::make_exact_root_id(), LMCAS::detail::make_rootof_solutions_impl(), LMCAS::detail::anonymous_namespace{exact_sturm.cpp}::make_sturm_sequence(), LMCAS::operator<<(), LMCAS::Polynomial< Rational >::operator==(), LMCAS::detail::anonymous_namespace{exact_sturm.cpp}::polynomial_sign_at(), LMCAS::detail::definite::polynomial_sign_checked(), pseudo_div_mod(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::rational_polynomial_expression(), LMCAS::anonymous_namespace{integration_rational_factorization.cpp}::rd_factor_quadratic(), LMCAS::anonymous_namespace{integration_rational_coefficients.cpp}::rd_fill_factor_columns(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_integrate_proper_fraction(), LMCAS::anonymous_namespace{integration_rational_collection.cpp}::rd_normalize_fraction(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_reduce_reciprocal(), LMCAS::rootof_simplify(), LMCAS::detail::definite::roots_checked(), LMCAS::polynomial_solver_detail::solve_by_factoring_impl(), LMCAS::solve_closed_form_from_poly(), LMCAS::solve_closed_form_poly(), LMCAS::detail::solve_coefficients(), LMCAS::solve_diophantine_pair(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::solve_exact_affine_inequality_impl(), LMCAS::solve_exact_factor(), LMCAS::solve_exact_polynomial_set(), LMCAS::solve_higher_exact_roots(), LMCAS::detail::inequality_support::solve_symbolic_poly(), LMCAS::solve_symbolic_polynomial_set(), LMCAS::square_free_factorization(), square_free_part(), LMCAS::detail::strict_cauchy_root_bound(), LMCAS::detail::anonymous_namespace{complex_root_isolation.cpp}::strict_factors(), LMCAS::anonymous_namespace{symbolic_algebra_adapter.cpp}::sylvester_matrix(), LMCAS::symbolic_poly_to_expr(), LMCAS::tf_square_free(), LMCAS::zc_divides_exactly(), LMCAS::zc_enumerate(), LMCAS::zc_finalize() , 以及 LMCAS::zc_try_candidate().

这是这个函数的调用关系图:

◆ differentiate()

template<typename CoeffType>
Polynomial LMCAS::Polynomial< CoeffType >::differentiate ( ) const
inline

求导

返回
导多项式

在文件 polynomial.hpp 第 307 行定义.

307 {
308 if (degree() < 1) return Polynomial(variable_name);
310 res.coeffs.resize(coeffs.size() - 1);
311 for (size_t i = 1; i < coeffs.size(); ++i) {
312 CoeffType c = coeffs[i];
313
314 res.coeffs[i-1] = c * CoeffType(i);
315 }
316 res.trim();
317 return res;
318 }
Polynomial(const std::string &var="x")
构造零多项式
int degree() const
获取多项式的次数

被这些函数引用 LMCAS::detail::anonymous_namespace{exact_sturm.cpp}::make_sturm_sequence(), LMCAS::detail::definite::rational_pole_divergence(), LMCAS::detail::definite::roots_checked(), LMCAS::square_free_factorization(), square_free_part() , 以及 LMCAS::tf_square_free().

这是这个函数的调用关系图:

◆ div_mod()

template<typename CoeffType>
std::pair< Polynomial, Polynomial > LMCAS::Polynomial< CoeffType >::div_mod ( const Polynomial< CoeffType > & other) const
inline

多项式带余除法

参数
other除数多项式
返回
pair(商, 余数)
异常
std::runtime_error除数为零多项式时抛出
std::invalid_argument两个非零操作数的变量名不同时抛出

在文件 polynomial.hpp 第 207 行定义.

207 {
208 if (other.is_zero()) throw std::runtime_error("Division by zero polynomial");
209 require_compatible_variables(other, "Polynomial::div_mod");
210 if (is_zero()) {
212 }
213
215 Polynomial remainder = *this;
216
217 int deg_rem = remainder.degree();
218 int deg_div = other.degree();
220
221 if (deg_rem < deg_div) {
222 return {quotient, remainder};
223 }
224
225 quotient.coeffs.resize(deg_rem - deg_div + 1, CoeffType(0));
226
227 while (deg_rem >= deg_div && !remainder.is_zero()) {
228
230 int deg_diff = deg_rem - deg_div;
231
233
235 term.coeffs.resize(deg_diff + 1, CoeffType(0));
237
241 }
242
243 quotient.trim();
244 return {quotient, remainder};
245 }
void require_compatible_variables(const Polynomial &other, const char *operation) const
CoeffType lead_coeff() const
获取首项系数

被这些函数引用 LMCAS::anonymous_namespace{symbolic_cancel.cpp}::cancel_polynomial_gcd(), LMCAS::deflate_rational_root(), LMCAS::exact_factor_roots(), LMCAS::detail::complex_root::anonymous_namespace{complex_root_projection.cpp}::exact_poly_divide(), LMCAS::extended_gcd_poly(), LMCAS::anonymous_namespace{integration_rational_coefficients.cpp}::rd_factor_complements(), LMCAS::anonymous_namespace{integration_rational_factorization.cpp}::rd_factor_piece(), LMCAS::anonymous_namespace{integration_rational_factorization.cpp}::rd_factor_quadratic(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_integrate_proper_fraction(), LMCAS::anonymous_namespace{integration_rational_collection.cpp}::rd_normalize_fraction(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_reduce_reciprocal(), LMCAS::reconstruct_rational_roots(), LMCAS::multivariate_checked_detail::restore_specialization_unit(), LMCAS::detail::definite::roots_checked(), LMCAS::polynomial_solver_detail::solve_by_factoring_impl(), LMCAS::solve_diophantine_pair(), LMCAS::solve_exact_factor(), LMCAS::square_free_factorization(), square_free_part(), LMCAS::tf_square_free(), LMCAS::zc_divides_exactly() , 以及 LMCAS::zc_try_candidate().

这是这个函数的调用关系图:

◆ eval()

◆ gcd()

template<typename CoeffType>
Polynomial< CoeffType > LMCAS::Polynomial< CoeffType >::gcd ( Polynomial< CoeffType > a,
Polynomial< CoeffType > b )
inlinestatic

计算两个多项式的最大公因式

参数
a第一个多项式
b第二个多项式
返回
gcd(a, b)
异常
std::invalid_argument两个非零操作数的变量名不同时抛出

在文件 polynomial_division.hpp 第 107 行定义.

108 {
109 a.require_compatible_variables(b, "Polynomial::gcd");
110 if (b.is_zero()) return a;
111 if (a.is_zero()) return b;
112
114
115 while (!b.is_zero()) {
116 auto [q, r] = a.div_mod(b);
117 a = b;
118 b = r;
119 }
120
121 return a.make_monic();
122 } else {
123
124 CoeffType cA = a.content();
125 CoeffType cB = b.content();
127
128 a = a.primitive_part();
129 b = b.primitive_part();
130
131 while (!b.is_zero()) {
132
134
135 if (r.is_zero()) {
136 a = b;
137 b = r;
138 } else {
139
140 a = b;
141 b = r.primitive_part();
142 }
143 }
144
145 if (c == CoeffType(1)) return a;
146
147 for (auto& val : a.coeffs) val = val * c;
148 return a;
149 }
150}
Polynomial pseudo_div_mod_rem(const Polynomial &other) const
伪除法取余数
std::pair< Polynomial, Polynomial > div_mod(const Polynomial &other) const
多项式带余除法
Polynomial primitive_part() const
计算多项式的本原部分(除以容度)
CoeffType content() const
计算多项式的容度(所有系数的 GCD)
Polynomial make_monic() const
首一化(使首项系数为 1)

引用了 Polynomial(), LMCAS::a, LMCAS::b, LMCAS::c, LMCAS::gcd_coeff_impl() , 以及 LMCAS::r.

被这些函数引用 LMCAS::anonymous_namespace{symbolic_cancel.cpp}::cancel_polynomial_gcd(), LMCAS::detail::anonymous_namespace{exact_algebraic.cpp}::common_root_in_enclosures(), LMCAS::anonymous_namespace{integration_rational_collection.cpp}::rd_normalize_fraction(), LMCAS::square_free_factorization(), square_free_part(), LMCAS::tf_square_free(), LMCAS::univariate_gcd() , 以及 LMCAS::anonymous_namespace{integration_weierstrass.cpp}::weier_reduce_rational().

函数调用图:
这是这个函数的调用关系图:

◆ gcd_coeff()

template<typename CoeffType>
CoeffType LMCAS::Polynomial< CoeffType >::gcd_coeff ( const CoeffType & a,
const CoeffType & b )
inlinestatic

计算两个系数的 GCD(静态方法)

参数
a第一个系数
b第二个系数
返回
gcd(a, b)

在文件 polynomial.hpp 第 253 行定义.

253 {
254 if constexpr (std::is_same_v<CoeffType, BigInt>) {
255 return BigInt::gcd(a, b);
256 } else if constexpr (std::is_same_v<CoeffType, Rational>) {
257 return CoeffType(1);
258 } else {
259
260 if constexpr (std::is_integral_v<CoeffType>) {
261 return std::gcd(a, b);
262 }
263
264 return CoeffType(1);
265 }
266 }

被这些函数引用 content().

这是这个函数的调用关系图:

◆ is_zero()

template<typename CoeffType>
bool LMCAS::Polynomial< CoeffType >::is_zero ( ) const
inline

判断是否为零多项式

在文件 polynomial.hpp 第 92 行定义.

92 {
93 return coeffs.empty();
94 }

被这些函数引用 LMCAS::berlekamp_factor(), LMCAS::berlekamp_detail::bk_is_suitable_prime(), LMCAS::berlekamp_detail::bk_reduce_to_mod_coeffs(), LMCAS::berlekamp_detail::bk_select_prime(), content(), LMCAS::detail::inequality_support::determine_leading_sign(), LMCAS::Polynomial< Rational >::div_mod(), LMCAS::polynomial_solver_detail::exact_polynomial_roots(), LMCAS::extended_gcd_poly(), LMCAS::factor_univariate_bridge_checked(), LMCAS::find_rational_roots(), LMCAS::anonymous_namespace{residual_verification.cpp}::has_zero_root_remainder(), LMCAS::hl_compute_lift_height(), LMCAS::hl_validate_lift_inputs(), LMCAS::detail::integrate_rational_term(), LMCAS::detail::anonymous_namespace{exact_algebraic.cpp}::monic(), LMCAS::Polynomial< Rational >::operator*(), LMCAS::Polynomial< Rational >::operator+(), LMCAS::Polynomial< Rational >::operator-(), LMCAS::operator<<(), LMCAS::detail::definite::polynomial_at_root_sign(), LMCAS::polynomial_product_fits(), LMCAS::detail::anonymous_namespace{exact_sturm.cpp}::polynomial_sign_at(), LMCAS::detail::definite::polynomial_sign_checked(), primitive_part(), pseudo_div_mod(), LMCAS::anonymous_namespace{integration_rational_factorization.cpp}::rd_factor_piece(), LMCAS::anonymous_namespace{integration_rational_factorization.cpp}::rd_factor_quadratic(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_integrate_polynomial(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_integrate_proper_fraction(), LMCAS::anonymous_namespace{integration_rational_collection.cpp}::rd_normalize_fraction(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_reduce_reciprocal(), LMCAS::detail::inequality_support::snap_verified_integer_root(), LMCAS::polynomial_solver_detail::solve_by_factoring_impl(), LMCAS::solve_diophantine_pair(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::solve_exact_affine_inequality_impl(), LMCAS::solve_exact_factor(), LMCAS::solve_exact_polynomial_set(), LMCAS::detail::inequality_support::solve_symbolic_poly(), LMCAS::square_free_factorization(), LMCAS::symbolic_poly_to_expr(), LMCAS::univariate_gcd(), LMCAS::Polynomial< Rational >::variables_compatible(), LMCAS::zassenhaus_combine_impl(), LMCAS::zc_divides_exactly(), LMCAS::zc_finalize() , 以及 LMCAS::zc_make_primitive().

这是这个函数的调用关系图:

◆ lead_coeff()

◆ make_monic()

template<typename CoeffType>
Polynomial LMCAS::Polynomial< CoeffType >::make_monic ( ) const
inline

◆ operator*()

template<typename CoeffType>
Polynomial LMCAS::Polynomial< CoeffType >::operator* ( const Polynomial< CoeffType > & other) const
inline

多项式乘法

参数
other乘数
返回
积多项式

在文件 polynomial.hpp 第 163 行定义.

163 {
164 require_compatible_variables(other, "Polynomial::operator*");
165 const auto& result_var = is_zero() && !other.is_zero()
168 if (is_zero() || other.is_zero()) { return res; }
169 res.coeffs.resize(coeffs.size() + other.coeffs.size() - 1, CoeffType(0));
170
171 for (size_t i = 0; i < coeffs.size(); ++i) {
172 for (size_t j = 0; j < other.coeffs.size(); ++j) {
173 res.coeffs[i + j] = res.coeffs[i + j] + coeffs[i] * other.coeffs[j];
174 }
175 }
176 res.trim();
177 return res;
178 }

◆ operator+()

template<typename CoeffType>
Polynomial LMCAS::Polynomial< CoeffType >::operator+ ( const Polynomial< CoeffType > & other) const
inline

多项式加法

参数
other加数
返回
和多项式

在文件 polynomial.hpp 第 119 行定义.

119 {
120 require_compatible_variables(other, "Polynomial::operator+");
121 const auto& result_var = is_zero() && !other.is_zero()
124 size_t n = std::max(coeffs.size(), other.coeffs.size());
125 res.coeffs.resize(n);
126
127 for (size_t i = 0; i < n; ++i) {
128 CoeffType a = (i < coeffs.size()) ? coeffs[i] : CoeffType(0);
129 CoeffType b = (i < other.coeffs.size()) ? other.coeffs[i] : CoeffType(0);
130 res.coeffs[i] = a + b;
131 }
132 res.trim();
133 return res;
134 }

◆ operator-()

template<typename CoeffType>
Polynomial LMCAS::Polynomial< CoeffType >::operator- ( const Polynomial< CoeffType > & other) const
inline

多项式减法

参数
other减数
返回
差多项式

在文件 polynomial.hpp 第 141 行定义.

141 {
142 require_compatible_variables(other, "Polynomial::operator-");
143 const auto& result_var = is_zero() && !other.is_zero()
146 size_t n = std::max(coeffs.size(), other.coeffs.size());
147 res.coeffs.resize(n);
148
149 for (size_t i = 0; i < n; ++i) {
150 CoeffType a = (i < coeffs.size()) ? coeffs[i] : CoeffType(0);
151 CoeffType b = (i < other.coeffs.size()) ? other.coeffs[i] : CoeffType(0);
152 res.coeffs[i] = a - b;
153 }
154 res.trim();
155 return res;
156 }

◆ operator==()

template<typename CoeffType>
bool LMCAS::Polynomial< CoeffType >::operator== ( const Polynomial< CoeffType > & other) const
inline

多项式判等

参数
other比较对象
返回
同一命名变量环内系数完全相同返回 true;所有零多项式相等

在文件 polynomial.hpp 第 185 行定义.

185 {
186 if (degree() != other.degree()) {
187 return false;
188 }
190 return false;
191 }
192 for (size_t i = 0; i < coeffs.size(); ++i) {
193 if (coeffs[i] != other.coeffs[i]) {
194 return false;
195 }
196 }
197 return true;
198 }
bool variables_compatible(const Polynomial &other) const

◆ primitive_part()

template<typename CoeffType>
Polynomial< CoeffType > LMCAS::Polynomial< CoeffType >::primitive_part ( ) const
inline

计算多项式的本原部分(除以容度)

返回
本原多项式

在文件 polynomial_division.hpp 第 26 行定义.

26 {
27 if (is_zero()) return *this;
29 if (c == CoeffType(0)) return *this;
30
31 Polynomial res = *this;
32 if (c != CoeffType(1)) {
33 for (auto& val : res.coeffs) {
34 val = val / c;
35 }
36 }
37
38 if (res.lead_coeff() < CoeffType(0)) {
39 for (auto& val : res.coeffs) {
40 val = CoeffType(0) - val;
41 }
42 }
43 return res;
44}

引用了 Polynomial(), LMCAS::c, coeffs, content(), is_zero() , 以及 lead_coeff().

函数调用图:

◆ pseudo_div_mod()

template<typename CoeffType>
std::pair< Polynomial< CoeffType >, Polynomial< CoeffType > > LMCAS::Polynomial< CoeffType >::pseudo_div_mod ( const Polynomial< CoeffType > & other) const
inline

通过系数缩放执行伪除法,运算保持在原系数环

参数
other除数多项式
返回
pair(伪商, 伪余数)
异常
std::runtime_error除数为零多项式时抛出
std::invalid_argument两个非零操作数的变量名不同时抛出

在文件 polynomial_division.hpp 第 48 行定义.

48 {
49 if (other.is_zero()) throw std::runtime_error("Division by zero polynomial");
50 require_compatible_variables(other, "Polynomial::pseudo_div_mod");
51 if (is_zero()) {
53 }
54
55 int deg_rem = degree();
56 int deg_div = other.degree();
57
58 if (deg_rem < deg_div) {
59 return {Polynomial(variable_name), *this};
60 }
61
62 Polynomial remainder = *this;
65
66 int delta = deg_rem - deg_div;
67 quotient.coeffs.resize(delta + 1, CoeffType(0));
68
69 while (deg_rem >= deg_div && !remainder.is_zero()) {
72
73 for (auto& c : quotient.coeffs) c = c * lc_div;
74
76
78 term.coeffs.resize(current_diff + 1, CoeffType(0));
80
81 for(auto& c : remainder.coeffs) c = c * lc_div;
82
83 for (size_t i = 0; i < other.coeffs.size(); ++i) {
84 size_t target_idx = i + current_diff;
85
86 if (target_idx < remainder.coeffs.size()) {
88 }
89
90 }
91
94 }
95
96 return {quotient, remainder};
97}

引用了 Polynomial(), LMCAS::c, coeffs, degree(), is_zero(), lead_coeff(), require_compatible_variables(), trim() , 以及 variable_name.

被这些函数引用 pseudo_div_mod_rem().

函数调用图:
这是这个函数的调用关系图:

◆ pseudo_div_mod_rem()

template<typename CoeffType>
Polynomial< CoeffType > LMCAS::Polynomial< CoeffType >::pseudo_div_mod_rem ( const Polynomial< CoeffType > & other) const
inline

伪除法取余数

参数
other除数多项式
返回
伪余数

在文件 polynomial_division.hpp 第 101 行定义.

101 {
102
103 return pseudo_div_mod(other).second;
104}
std::pair< Polynomial, Polynomial > pseudo_div_mod(const Polynomial &other) const
通过系数缩放执行伪除法,运算保持在原系数环

引用了 Polynomial() , 以及 pseudo_div_mod().

函数调用图:

◆ require_compatible_variables()

template<typename CoeffType>
void LMCAS::Polynomial< CoeffType >::require_compatible_variables ( const Polynomial< CoeffType > & other,
const char * operation ) const
inlineprivate

在文件 polynomial.hpp 第 382 行定义.

382 {
385 std::string(operation) + ": variable name mismatch ('" +
386 variable_name + "' vs '" + other.variable_name + "')");
387 }
388 }

被这些函数引用 pseudo_div_mod().

这是这个函数的调用关系图:

◆ square_free_part()

template<typename CoeffType>
Polynomial< CoeffType > LMCAS::Polynomial< CoeffType >::square_free_part ( ) const
inline

计算无平方因子部分

返回
去除重因子后的多项式

在文件 polynomial_division.hpp 第 153 行定义.

153 {
154
155 if (degree() <= 0) return *this;
156
158 Polynomial g = gcd(*this, deriv);
159
160 auto [q, r] = div_mod(g);
161
163 return q.make_monic();
164 }
165 return q;
166}
static Polynomial gcd(Polynomial a, Polynomial b)
计算两个多项式的最大公因式
Polynomial differentiate() const
求导

引用了 Polynomial(), degree(), differentiate(), div_mod(), gcd() , 以及 LMCAS::r.

被这些函数引用 LMCAS::detail::count_real_roots_exact(), LMCAS::detail::isolate_exact_roots(), LMCAS::detail::isolate_real_roots_exact(), LMCAS::detail::make_exact_root_id() , 以及 LMCAS::detail::anonymous_namespace{exact_sturm.cpp}::make_sturm_sequence().

函数调用图:
这是这个函数的调用关系图:

◆ to_string()

template<typename CoeffType>
std::string LMCAS::Polynomial< CoeffType >::to_string ( ) const
inline

转换为字符串表示

返回
多项式的字符串形式

在文件 polynomial.hpp 第 363 行定义.

363 {
364 if (is_zero()) {
365 return "0";
366 }
368 for (int i = degree(); i >= 0; --i) {
369 if (coeffs[i] == CoeffType(0)) {
370 continue;
371 }
373 }
374 return s.empty() ? "0" : s;
375 }
void append_string_term(std::string &text, CoeffType coefficient, int power) const

◆ trim()

◆ variables_compatible()

template<typename CoeffType>
bool LMCAS::Polynomial< CoeffType >::variables_compatible ( const Polynomial< CoeffType > & other) const
inlineprivate

在文件 polynomial.hpp 第 378 行定义.

378 {
380 }

类成员变量说明

◆ coeffs

template<typename CoeffType>
std::vector<CoeffType> LMCAS::Polynomial< CoeffType >::coeffs

系数数组,coeffs[i] 为 x^i 的系数

在文件 polynomial.hpp 第 55 行定义.

被这些函数引用 LMCAS::anonymous_namespace{poly_utils.cpp}::add_checked_coefficients(), LMCAS::detail::inequality_support::append_affine_root(), LMCAS::detail::inequality_support::append_factor_roots(), LMCAS::detail::inequality_support::append_quadratic_roots(), LMCAS::berlekamp_detail::bk_reduce_to_mod_coeffs(), LMCAS::bk_to_poly_modint(), LMCAS::polynomial_solver_detail::bounded_rational_root_search(), LMCAS::anonymous_namespace{univariate_factor_bridge.cpp}::bridge_lift_bound(), LMCAS::detail::complex_root::clear_denominators(), LMCAS::detail::ExactRootId::compare(), LMCAS::detail::complex_root::anonymous_namespace{complex_root_projection.cpp}::complex_bivariate_parts(), LMCAS::anonymous_namespace{poly_utils.cpp}::constant_to_poly(), content(), LMCAS::polynomial_solver_detail::convert_to_rational_poly(), LMCAS::Polynomial< Rational >::differentiate(), LMCAS::diophantine_univariate_factors(), LMCAS::Polynomial< Rational >::div_mod(), LMCAS::detail::complex_root::anonymous_namespace{complex_root_winding.cpp}::edge_image(), LMCAS::anonymous_namespace{multivariate_factor_checked.cpp}::embed_univariate_factor(), LMCAS::detail::anonymous_namespace{exact_algebraic_refinement.cpp}::evaluate_polynomial_double(), LMCAS::exact_factor_roots(), LMCAS::extended_gcd_poly(), LMCAS::detail::anonymous_namespace{complex_root_isolation.cpp}::factor_biquadratic(), LMCAS::factor_integer_polynomial(), LMCAS::find_rational_roots(), LMCAS::get_coeff(), LMCAS::anonymous_namespace{residual_verification.cpp}::has_zero_root_remainder(), LMCAS::detail::ExactRootId::hash(), LMCAS::hensel_lift_checked(), LMCAS::hl_l2_norm_squared(), LMCAS::hl_validate_lift_inputs(), LMCAS::detail::homogenize_factor(), LMCAS::detail::isolate_real_roots_exact(), LMCAS::Polynomial< Rational >::make_monic(), LMCAS::detail::anonymous_namespace{exact_algebraic.cpp}::monic(), LMCAS::anonymous_namespace{poly_utils.cpp}::multiply_checked_coefficients(), LMCAS::Polynomial< Rational >::operator*(), LMCAS::Polynomial< Rational >::operator+(), LMCAS::Polynomial< Rational >::operator-(), LMCAS::operator<<(), LMCAS::Polynomial< Rational >::operator==(), LMCAS::RootOfNode::polynomial(), LMCAS::detail::definite::polynomial_budget(), LMCAS::polynomial_product_fits(), LMCAS::detail::anonymous_namespace{exact_sturm.cpp}::polynomial_sign_at(), primitive_part(), pseudo_div_mod(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::rational_polynomial_expression(), LMCAS::rational_root_candidate(), LMCAS::rational_to_symbolic_poly(), LMCAS::anonymous_namespace{integration_rational_terms.cpp}::rd_integrate_linear_term(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_integrate_polynomial(), LMCAS::anonymous_namespace{integration_rational_terms.cpp}::rd_integrate_quadratic_term(), LMCAS::anonymous_namespace{integration_rational_collection.cpp}::rd_normalize_fraction(), LMCAS::anonymous_namespace{rational_polynomial_recognition.cpp}::recognize_sum(), LMCAS::detail::anonymous_namespace{complex_root_isolation.cpp}::same_polynomial(), LMCAS::detail::anonymous_namespace{exact_algebraic.cpp}::same_polynomial(), LMCAS::detail::complex_root::scale_poly(), LMCAS::anonymous_namespace{inequality_solver_parametric.cpp}::simplify_coefficients(), LMCAS::solve_closed_form_from_poly(), LMCAS::solve_closed_form_poly(), LMCAS::detail::solve_coefficients(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::solve_exact_affine_inequality_impl(), LMCAS::solve_exact_factor(), LMCAS::solve_higher_exact_roots(), LMCAS::detail::inequality_support::solve_symbolic_poly(), LMCAS::detail::strict_cauchy_root_bound(), LMCAS::anonymous_namespace{symbolic_algebra_adapter.cpp}::sylvester_matrix(), LMCAS::symbolic_poly_to_expr(), LMCAS::symbolic_power_to_poly(), LMCAS::symbolic_product_to_poly(), LMCAS::symbolic_to_poly_recursive(), LMCAS::anonymous_namespace{poly_utils.cpp}::trim_checked_coefficients(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::verify_quadratic_boundary(), LMCAS::anonymous_namespace{expr_serialization.cpp}::Writer::visit() , 以及 LMCAS::zc_validate_lifted_product().

◆ variable_name

template<typename CoeffType>
std::string LMCAS::Polynomial< CoeffType >::variable_name

变量名

在文件 polynomial.hpp 第 56 行定义.

被这些函数引用 LMCAS::anonymous_namespace{poly_utils.cpp}::add_checked_coefficients(), LMCAS::berlekamp_factor(), LMCAS::anonymous_namespace{univariate_factor_bridge.cpp}::bridge_factor(), LMCAS::polynomial_solver_detail::convert_to_rational_poly(), LMCAS::deflate_rational_root(), LMCAS::diophantine_target(), LMCAS::diophantine_univariate_factors(), LMCAS::Polynomial< Rational >::div_mod(), LMCAS::exact_factor_roots(), LMCAS::detail::anonymous_namespace{complex_root_isolation.cpp}::factor_biquadratic(), LMCAS::factor_integer_polynomial(), LMCAS::find_rational_roots(), LMCAS::hensel_lift_checked(), LMCAS::detail::isolate_exact_roots(), LMCAS::detail::make_exact_root_id(), LMCAS::anonymous_namespace{poly_utils.cpp}::multiply_checked_coefficients(), LMCAS::Polynomial< Rational >::operator*(), LMCAS::Polynomial< Rational >::operator+(), LMCAS::Polynomial< Rational >::operator-(), LMCAS::operator<<(), pseudo_div_mod(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::rational_polynomial_expression(), LMCAS::rational_to_symbolic_poly(), LMCAS::anonymous_namespace{integration_rational_coefficients.cpp}::rd_factor_complements(), LMCAS::anonymous_namespace{integration_rational_factorization.cpp}::rd_factor_quadratic(), LMCAS::anonymous_namespace{integration_rational_coefficients.cpp}::rd_fill_coefficient_matrix(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_integrate_proper_fraction(), LMCAS::anonymous_namespace{integration_rational_terms.cpp}::rd_integrate_repeated_quadratic(), LMCAS::anonymous_namespace{integration_rational.cpp}::rd_reduce_reciprocal(), LMCAS::Polynomial< Rational >::require_compatible_variables(), LMCAS::multivariate_checked_detail::restore_specialization_unit(), LMCAS::detail::anonymous_namespace{exact_algebraic.cpp}::same_polynomial(), LMCAS::detail::solve_coefficients(), LMCAS::solve_diophantine_pair(), LMCAS::anonymous_namespace{inequality_solver_polynomial.cpp}::solve_exact_polynomial_inequality_impl(), LMCAS::symbolic_poly_to_expr(), LMCAS::tf_square_free(), LMCAS::Polynomial< Rational >::variables_compatible(), LMCAS::zc_finalize() , 以及 LMCAS::zc_try_candidate().


该类的文档由以下文件生成: