11 const std::shared_ptr<SymbolicExpr>& polynomial,
15 constexpr const char* operation =
"rootof.construct";
20 "RootOf requires a polynomial and named variable", operation);
27 if (!recognized.value()) {
30 "RootOf coefficients must be exact rational constants",
34 std::move(*recognized.value()), index,
context, operation);
41 std::move(identity.value()),
variable)));
45 const std::shared_ptr<SymbolicExpr>& polynomial,
52 const std::shared_ptr<SymbolicExpr>& coefficient,
53 const std::string&
variable,
int degree) {
54 if (degree == 0)
return coefficient;
55 auto symbol = SymbolicExpr::variable(
variable);
56 auto power = degree == 1
57 ? symbol : SymbolicExpr::power(symbol, SymbolicExpr::number(degree));
58 return coefficient->is_one()
59 ? power : SymbolicExpr::multiply(coefficient, power);
66 (
context).limits().max_ast_nodes,
"transform");
67 if (poly.
is_zero())
return SymbolicExpr::number(0);
69 std::vector<std::shared_ptr<SymbolicExpr>> terms;
70 for (
int i = poly.
degree(); i >= 0; --i) {
71 const auto& coeff = poly.
coeffs[i];
73 auto coeff_expr = coeff.val;
76 coeff_expr = simplified;
85 if (terms.empty())
return SymbolicExpr::number(0);
86 if (terms.size() == 1)
return terms[0];
88 auto result = terms[0];
89 for (
size_t i = 1; i < terms.size(); ++i) {
90 result = SymbolicExpr::add(result, terms[i]);
98 const std::string& var) {
106 if (poly.
degree() <= 0)
return {};
109 *polynomial_expression, var,
context);
110 if (!recognized)
throw recognized.error();
111 if (!recognized.value())
return {};
112 auto canonical = recognized.value()->square_free_part().make_monic();
113 canonical.variable_name =
"_root";
114 std::vector<std::shared_ptr<SymbolicExpr>> solutions;
115 solutions.reserve(
static_cast<std::size_t
>(canonical.degree()));
116 for (
int index = 0; index < canonical.degree(); ++index) {
120 canonical,
static_cast<std::size_t
>(index)},
130 const std::shared_ptr<SymbolicExpr>& rootof_expr,
132 const std::string& operation) {
137 auto root = std::dynamic_pointer_cast<const RootOfNode>(
142 "expression is not a valid RootOf", operation);
144 auto access =
context.consume_steps(1, operation);
153 const std::shared_ptr<SymbolicExpr>& rootof_expr,
156 constexpr const char* operation =
"rootof_evaluate";
157 auto request = parse_rootof_request(rootof_expr,
context, operation);
160 request.value()->exact_id(),
169 const std::shared_ptr<SymbolicExpr>& rootof_expr) {
175 const std::shared_ptr<SymbolicExpr>& rootof_expr,
177 constexpr const char* operation =
"rootof_evaluate_complex";
178 auto request = parse_rootof_request(rootof_expr,
context, operation);
183 request.value()->exact_id(),
188 const std::shared_ptr<SymbolicExpr>& rootof_expr) {
std::string variable_name
变量名
bool is_zero() const
判断是否为零多项式
std::vector< CoeffType > coeffs
系数数组,coeffs[i] 为 x^i 的系数
int degree() const
获取多项式的次数
static Result failure(CasErrc code, std::string message, std::string operation={})
static Result success(std::shared_ptr< SymbolicExpr > value)
virtual bool is_zero() const
Result< const RootOfNode * > parse_rootof_request(const std::shared_ptr< SymbolicExpr > &rootof_expr, ComputationContext &context, const std::string &operation)
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
Result< ExactRootId > make_exact_root_id(Polynomial< Rational > polynomial, std::size_t index, ComputationContext &context, const std::string &operation)
std::shared_ptr< const Node > make_node(Args &&... args)
Result< ApproxComplex > evaluate_root_complex(const ExactRootId &root, const NumericEvaluationOptions &options, ComputationContext &context)
Result< ApproxReal > evaluate_root_real(const ExactRootId &root, const NumericEvaluationOptions &options, ComputationContext &context)
SymbolicNodePtr normalize_node(const SymbolicNodePtr &node, RewriteBudget &budget, const FactsQuery &facts, Domain domain)
std::vector< std::shared_ptr< SymbolicExpr > > make_rootof_solutions_impl(const Polynomial< SymbolicPolyCoeff > &polynomial, const std::string &variable, ComputationContext &context)
std::size_t std::size_t ComputationContext & context
std::vector< std::shared_ptr< SymbolicExpr > > make_rootof_solutions(const Polynomial< SymbolicPolyCoeff > &poly, const std::string &var)
const std::string & variable
RootOfComplexEvaluationResult rootof_evaluate_complex_checked(const std::shared_ptr< SymbolicExpr > &rootof_expr, ComputationContext &context)
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
RootOfEvaluationResult rootof_evaluate_checked(const std::shared_ptr< SymbolicExpr > &rootof_expr, ComputationContext &context)
static std::shared_ptr< SymbolicExpr > symbolic_root_term(const std::shared_ptr< SymbolicExpr > &coefficient, const std::string &variable, int degree)
static std::shared_ptr< SymbolicExpr > symbolic_poly_to_expr(const Polynomial< SymbolicPolyCoeff > &poly, ComputationContext &context)
RootOfConstructionResult make_rootof_checked(const std::shared_ptr< SymbolicExpr > &polynomial, const std::string &variable, std::size_t index, ComputationContext &context)
Result< ApproxComplex > RootOfComplexEvaluationResult
Result< OptionalRationalPolynomial > recognize_rational_polynomial(const SymbolicExpr &expression, const std::string &variable, ComputationContext &context)
Result< std::shared_ptr< SymbolicExpr > > RootOfConstructionResult
Result< lmmc_real_t > RootOfEvaluationResult