LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
LMCAS::anonymous_namespace{poly_utils.cpp} 命名空间参考

函数

Polynomial< SymbolicPolyCoeff > add_checked_coefficients (const Polynomial< SymbolicPolyCoeff > &left, const Polynomial< SymbolicPolyCoeff > &right, detail::RewriteBudget &budget)
Result< void > check_power_coefficient_count (std::size_t base_count, int exponent, detail::RewriteBudget *budget)
Result< void > check_zero_power_base (const detail::SymbolicNodePtr &base, ComputationContext &context)
void checked_coefficient_count (std::size_t count, detail::RewriteBudget &budget)
std::size_t checked_product_count (std::size_t left, std::size_t right, detail::RewriteBudget &budget)
template<typename Node>
detail::SymbolicNodePtr coefficient_arithmetic (const detail::SymbolicNodePtr &left, const detail::SymbolicNodePtr &right, detail::RewriteBudget &budget)
template<typename T>
Result< Polynomial< T > > constant_to_poly (const detail::SymbolicNodePtr &node, const std::string &variable, detail::RewriteBudget *budget)
Polynomial< SymbolicPolyCoeff > multiply_checked_coefficients (const Polynomial< SymbolicPolyCoeff > &left, const Polynomial< SymbolicPolyCoeff > &right, detail::RewriteBudget &budget)
detail::SymbolicNodePtr normalize_coefficient (const detail::SymbolicNodePtr &node, detail::RewriteBudget &budget)
void trim_checked_coefficients (Polynomial< SymbolicPolyCoeff > &polynomial, detail::RewriteBudget &budget)

函数说明

◆ add_checked_coefficients()

Polynomial< SymbolicPolyCoeff > LMCAS::anonymous_namespace{poly_utils.cpp}::add_checked_coefficients ( const Polynomial< SymbolicPolyCoeff > & left,
const Polynomial< SymbolicPolyCoeff > & right,
detail::RewriteBudget & budget )

在文件 poly_utils.cpp 第 174 行定义.

176 {
177 const auto count = std::max(left.coeffs.size(), right.coeffs.size());
178 checked_coefficient_count(count, budget);
180 result.coeffs.reserve(count);
181 std::size_t nodes = 0;
182 for (std::size_t index = 0; index < count; ++index) {
183 detail::SymbolicNodePtr coefficient;
184 if (index < left.coeffs.size() && index < right.coeffs.size()) {
186 detail::node(left.coeffs[index].val), detail::node(right.coeffs[index].val), budget);
187 } else {
188 const auto& source = index < left.coeffs.size() ? left : right;
189 coefficient = detail::node(source.coeffs[index].val);
190 }
191 nodes = budget.append_size(nodes, budget.measure(coefficient));
192 result.coeffs.emplace_back(detail::make_expression_ptr(std::move(coefficient)));
193 }
194 trim_checked_coefficients(result, budget);
195 return result;
196}
一元多项式模板类
std::string variable_name
变量名
std::vector< CoeffType > coeffs
系数数组,coeffs[i] 为 x^i 的系数
std::size_t measure(const std::shared_ptr< const SymbolicNode > &node)
std::size_t append_size(std::size_t current, std::size_t child)
void trim_checked_coefficients(Polynomial< SymbolicPolyCoeff > &polynomial, detail::RewriteBudget &budget)
void checked_coefficient_count(std::size_t count, detail::RewriteBudget &budget)
detail::SymbolicNodePtr coefficient_arithmetic(const detail::SymbolicNodePtr &left, const detail::SymbolicNodePtr &right, detail::RewriteBudget &budget)
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
std::shared_ptr< const SymbolicNode > SymbolicNodePtr
const ExprPtr & right

引用了 add_checked_coefficients(), LMCAS::detail::RewriteBudget::append_size(), checked_coefficient_count(), coefficient_arithmetic(), LMCAS::Polynomial< CoeffType >::coeffs, LMCAS::detail::make_expression_ptr(), LMCAS::detail::RewriteBudget::measure(), LMCAS::detail::node(), LMCAS::right, trim_checked_coefficients() , 以及 LMCAS::Polynomial< CoeffType >::variable_name.

被这些函数引用 add_checked_coefficients().

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

◆ check_power_coefficient_count()

Result< void > LMCAS::anonymous_namespace{poly_utils.cpp}::check_power_coefficient_count ( std::size_t base_count,
int exponent,
detail::RewriteBudget * budget )

在文件 poly_utils.cpp 第 246 行定义.

247 {
248 if (!budget || base_count == 0) { return Result<void>::success(); }
249 const auto degree = base_count - 1;
250 const auto maximum = static_cast<std::size_t>(std::numeric_limits<int>::max());
251 const auto count = static_cast<std::size_t>(exponent);
252 if (degree > (maximum - 1) / count) {
254 "Polynomial coefficient storage limit exceeded", "polynomial.convert");
255 }
256 checked_coefficient_count(degree * count + 1, *budget);
257 return Result<void>::success();
258}
static Result failure(CasErrc code, std::string message, std::string operation={})
static Result success(T value)
const ExprPtr & exponent

引用了 check_power_coefficient_count(), checked_coefficient_count(), LMCAS::exponent, LMCAS::Result< T >::failure(), LMCAS::ResourceLimit , 以及 LMCAS::Result< T >::success().

被这些函数引用 check_power_coefficient_count().

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

◆ check_zero_power_base()

Result< void > LMCAS::anonymous_namespace{poly_utils.cpp}::check_zero_power_base ( const detail::SymbolicNodePtr & base,
ComputationContext & context )

在文件 poly_utils.cpp 第 229 行定义.

230 {
231 const auto& facts = detail::no_facts();
232 auto real_defined = detail::query_definedness(base, facts, Domain::Real, context);
233 if (!real_defined) { return Result<void>::failure(real_defined.error()); }
234 auto complex_defined = detail::query_definedness(base, facts, Domain::Complex, context);
235 if (!complex_defined) { return Result<void>::failure(complex_defined.error()); }
236 auto nonzero = detail::query_nonzero_value(base, facts, Domain::Real, context);
237 if (!nonzero) { return Result<void>::failure(nonzero.error()); }
238 if (real_defined.value() != Tribool::True ||
239 complex_defined.value() != Tribool::True || nonzero.value() != Tribool::True) {
241 "Zero power requires a defined nonzero base", "polynomial.convert");
242 }
243 return Result<void>::success();
244}
Result< Tribool > query_nonzero_value(const Node &node, const FactsQuery &facts, Domain domain, ComputationContext &context)
const FactsQuery & no_facts() noexcept
Result< Tribool > query_definedness(const Node &node, const FactsQuery &facts, Domain domain, ComputationContext &context, bool *violated_real_restriction)
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
@ Complex
Complex numbers (default, least specific)
@ Real
Real numbers
@ True
Property definitely holds

引用了 check_zero_power_base(), LMCAS::Complex, LMCAS::context, LMCAS::Result< T >::failure(), LMCAS::detail::no_facts(), LMCAS::detail::query_definedness(), LMCAS::detail::query_nonzero_value(), LMCAS::Real, LMCAS::Result< T >::success(), LMCAS::True , 以及 LMCAS::UnsupportedExpression.

被这些函数引用 check_zero_power_base().

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

◆ checked_coefficient_count()

void LMCAS::anonymous_namespace{poly_utils.cpp}::checked_coefficient_count ( std::size_t count,
detail::RewriteBudget & budget )

在文件 poly_utils.cpp 第 125 行定义.

125 {
126 if (count > static_cast<std::size_t>(std::numeric_limits<int>::max())) {
128 "Polynomial coefficient storage limit exceeded", "polynomial.convert"};
129 }
130 auto terms = budget.context().require_expansion_terms(count, "polynomial.convert");
131 if (!terms) { throw terms.error(); }
132 budget.require_nodes(count);
133}
Result< void > require_expansion_terms(std::size_t amount, const std::string &operation={}) const
ComputationContext & context() const noexcept
void require_nodes(std::size_t nodes) const

引用了 checked_coefficient_count(), LMCAS::detail::RewriteBudget::context(), LMCAS::ComputationContext::require_expansion_terms(), LMCAS::detail::RewriteBudget::require_nodes() , 以及 LMCAS::ResourceLimit.

被这些函数引用 add_checked_coefficients(), check_power_coefficient_count(), checked_coefficient_count(), checked_product_count() , 以及 constant_to_poly().

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

◆ checked_product_count()

std::size_t LMCAS::anonymous_namespace{poly_utils.cpp}::checked_product_count ( std::size_t left,
std::size_t right,
detail::RewriteBudget & budget )

在文件 poly_utils.cpp 第 135 行定义.

136 {
137 if (left == 0 || right == 0) return 0;
138 const auto maximum = static_cast<std::size_t>(std::numeric_limits<int>::max());
139 if (left > maximum || right - 1 > maximum - left) {
141 "Polynomial coefficient storage limit exceeded", "polynomial.convert"};
142 }
143 const auto count = left + right - 1;
144 checked_coefficient_count(count, budget);
145 return count;
146}

引用了 checked_coefficient_count(), checked_product_count(), LMCAS::ResourceLimit , 以及 LMCAS::right.

被这些函数引用 checked_product_count() , 以及 multiply_checked_coefficients().

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

◆ coefficient_arithmetic()

template<typename Node>
detail::SymbolicNodePtr LMCAS::anonymous_namespace{poly_utils.cpp}::coefficient_arithmetic ( const detail::SymbolicNodePtr & left,
const detail::SymbolicNodePtr & right,
detail::RewriteBudget & budget )

在文件 poly_utils.cpp 第 156 行定义.

158 {
161 std::vector<detail::SymbolicNodePtr>{left, right}), budget);
162}
detail::SymbolicNodePtr normalize_coefficient(const detail::SymbolicNodePtr &node, detail::RewriteBudget &budget)
std::shared_ptr< const Node > make_node(Args &&... args)
std::size_t normalization_check_arithmetic(detail::RewriteBudget *budget, std::size_t extra_nodes, const std::shared_ptr< const Nodes > &... children)

引用了 coefficient_arithmetic(), LMCAS::detail::make_node(), LMCAS::normalization_check_arithmetic(), normalize_coefficient() , 以及 LMCAS::right.

被这些函数引用 add_checked_coefficients(), coefficient_arithmetic() , 以及 multiply_checked_coefficients().

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

◆ constant_to_poly()

template<typename T>
Result< Polynomial< T > > LMCAS::anonymous_namespace{poly_utils.cpp}::constant_to_poly ( const detail::SymbolicNodePtr & node,
const std::string & variable,
detail::RewriteBudget * budget )

在文件 poly_utils.cpp 第 261 行定义.

263 {
264 if constexpr (std::is_same_v<T, SymbolicPolyCoeff>) {
265 if (budget) {
266 checked_coefficient_count(1, *budget);
267 auto coefficient = normalize_coefficient(node, *budget);
268 budget->append_size(0, budget->measure(coefficient));
269 Polynomial<T> result(variable);
270 result.coeffs.emplace_back(detail::make_expression_ptr(std::move(coefficient)));
271 trim_checked_coefficients(result, *budget);
272 return result;
273 }
274 }
275 auto coefficient = extract_coeff_value<T>(detail::make_expression_ptr(node));
276 if (!coefficient) { return Result<Polynomial<T>>::failure(coefficient.error()); }
277 return Polynomial<T>({std::move(coefficient.value())}, variable);
278}
Polynomial(const std::string &var="x")
构造零多项式
const std::string & variable
Result< T > extract_coeff_value(const std::shared_ptr< SymbolicExpr > &coefficient)
精确提取系数;不支持的值返回错误,保持数值完整。

引用了 LMCAS::Polynomial< CoeffType >::Polynomial(), LMCAS::detail::RewriteBudget::append_size(), checked_coefficient_count(), LMCAS::Polynomial< CoeffType >::coeffs, constant_to_poly(), LMCAS::extract_coeff_value(), LMCAS::detail::make_expression_ptr(), LMCAS::detail::RewriteBudget::measure(), normalize_coefficient(), trim_checked_coefficients() , 以及 LMCAS::variable.

被这些函数引用 constant_to_poly().

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

◆ multiply_checked_coefficients()

Polynomial< SymbolicPolyCoeff > LMCAS::anonymous_namespace{poly_utils.cpp}::multiply_checked_coefficients ( const Polynomial< SymbolicPolyCoeff > & left,
const Polynomial< SymbolicPolyCoeff > & right,
detail::RewriteBudget & budget )

在文件 poly_utils.cpp 第 198 行定义.

200 {
201 const auto count = checked_product_count(left.coeffs.size(), right.coeffs.size(), budget);
203 result.coeffs.reserve(count);
204 std::size_t nodes = 0;
205 for (std::size_t degree = 0; degree < count; ++degree) {
206 detail::SymbolicNodePtr coefficient;
207 std::size_t coefficient_nodes = 0;
208 const auto first = degree < right.coeffs.size() ? 0 : degree - right.coeffs.size() + 1;
209 const auto last = std::min(degree, left.coeffs.size() - 1);
210 for (std::size_t index = first; index <= last; ++index) {
212 detail::node(left.coeffs[index].val),
213 detail::node(right.coeffs[degree - index].val), budget);
214 if (coefficient) {
215 coefficient = coefficient_arithmetic<AddNode>(coefficient, product, budget);
216 } else {
217 coefficient.swap(product);
218 }
219 coefficient_nodes = budget.measure(coefficient);
220 budget.append_size(nodes, coefficient_nodes);
221 }
222 nodes = budget.append_size(nodes, coefficient_nodes);
223 result.coeffs.emplace_back(detail::make_expression_ptr(std::move(coefficient)));
224 }
225 trim_checked_coefficients(result, budget);
226 return result;
227}
std::size_t checked_product_count(std::size_t left, std::size_t right, detail::RewriteBudget &budget)

引用了 LMCAS::detail::RewriteBudget::append_size(), checked_product_count(), coefficient_arithmetic(), LMCAS::Polynomial< CoeffType >::coeffs, LMCAS::detail::make_expression_ptr(), LMCAS::detail::RewriteBudget::measure(), multiply_checked_coefficients(), LMCAS::detail::node(), LMCAS::right, trim_checked_coefficients() , 以及 LMCAS::Polynomial< CoeffType >::variable_name.

被这些函数引用 multiply_checked_coefficients().

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

◆ normalize_coefficient()

detail::SymbolicNodePtr LMCAS::anonymous_namespace{poly_utils.cpp}::normalize_coefficient ( const detail::SymbolicNodePtr & node,
detail::RewriteBudget & budget )

在文件 poly_utils.cpp 第 148 行定义.

149 {
150 auto step = budget.context().consume_steps(1, "polynomial.coefficient");
151 if (!step) { throw step.error(); }
152 return detail::normalize_node(node, budget);
153}
Result< void > consume_steps(std::size_t amount=1, const std::string &operation={})
SymbolicNodePtr normalize_node(const SymbolicNodePtr &node, RewriteBudget &budget, const FactsQuery &facts, Domain domain)

引用了 LMCAS::ComputationContext::consume_steps(), LMCAS::detail::RewriteBudget::context(), normalize_coefficient() , 以及 LMCAS::detail::normalize_node().

被这些函数引用 coefficient_arithmetic(), constant_to_poly() , 以及 normalize_coefficient().

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

◆ trim_checked_coefficients()

void LMCAS::anonymous_namespace{poly_utils.cpp}::trim_checked_coefficients ( Polynomial< SymbolicPolyCoeff > & polynomial,
detail::RewriteBudget & budget )

在文件 poly_utils.cpp 第 164 行定义.

165 {
166 while (!polynomial.coeffs.empty()) {
167 auto step = budget.context().consume_steps(1, "polynomial.coefficient");
168 if (!step) { throw step.error(); }
169 if (!detail::node(polynomial.coeffs.back().val)->is_zero()) break;
170 polynomial.coeffs.pop_back();
171 }
172}

引用了 LMCAS::Polynomial< CoeffType >::coeffs, LMCAS::ComputationContext::consume_steps(), LMCAS::detail::RewriteBudget::context(), LMCAS::detail::node() , 以及 trim_checked_coefficients().

被这些函数引用 add_checked_coefficients(), constant_to_poly(), multiply_checked_coefficients() , 以及 trim_checked_coefficients().

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