19 (
context).limits().max_ast_nodes,
"transform");
21 if (deg <= 0)
return {};
23 auto get_coeff = [&](
int d) -> std::shared_ptr<SymbolicExpr> {
24 if (d < 0 || d > deg)
return SymbolicExpr::number(0);
25 return poly.
coeffs[d].val ? poly.
coeffs[d].val : SymbolicExpr::number(0);
31 auto neg_b = SymbolicExpr::multiply(
b, SymbolicExpr::number(-1));
33 }
else if (deg == 2) {
35 }
else if (deg == 3) {
37 }
else if (deg == 4) {
47 std::vector<SymbolicPolyCoeff> sym_coeffs;
48 sym_coeffs.reserve(rat_poly.
coeffs.size());
49 for (
const auto&
c : rat_poly.
coeffs) {
56 const std::string& var, std::vector<std::shared_ptr<SymbolicExpr>>& results,
58 if (factor.
degree() <= 0) {
return; }
60 auto solutions = factor.
degree() <= 4 ?
63 for (
int copy = 0; copy < multiplicity; ++copy) {
64 results.insert(results.end(), solutions.begin(), solutions.end());
78 std::vector<std::shared_ptr<SymbolicExpr>> results;
92 for (
const auto&
r : rational_roots) {
93 results.push_back(SymbolicExpr::number(
r));
97 for (
const auto&
r : rational_roots) {
99 auto [q, rem] = quotient.
div_mod(linear_factor);
100 if (!rem.is_zero()) {
throw std::logic_error(
"solve_by_factoring: inexact root division"); }
104 if (quotient.
degree() <= 0) {
108 if (quotient.
degree() <= 4) {
111 results.insert(results.end(), factor_roots.begin(), factor_roots.end());
117 for (
const auto& [factor, multiplicity] : sqfree_factors) {
std::pair< Polynomial, Polynomial > div_mod(const Polynomial &other) const
多项式带余除法
Polynomial(const std::string &var="x")
构造零多项式
std::string variable_name
变量名
bool is_zero() const
判断是否为零多项式
std::vector< CoeffType > coeffs
系数数组,coeffs[i] 为 x^i 的系数
int degree() const
获取多项式的次数
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
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)
bool bounded_rational_root_search(const Polynomial< Rational > &polynomial)
std::vector< std::shared_ptr< SymbolicExpr > > solve_cubic_impl(const std::shared_ptr< SymbolicExpr > &a, const std::shared_ptr< SymbolicExpr > &b, const std::shared_ptr< SymbolicExpr > &c, const std::shared_ptr< SymbolicExpr > &d, const std::string &variable, ComputationContext &context)
bool convert_to_rational_poly(const Polynomial< SymbolicPolyCoeff > &poly, Polynomial< Rational > &output, ComputationContext &context)
std::vector< std::shared_ptr< SymbolicExpr > > solve_by_factoring_impl(const Polynomial< SymbolicPolyCoeff > &polynomial, const std::string &variable, ComputationContext &context)
std::vector< std::shared_ptr< SymbolicExpr > > solve_quartic_impl(const std::shared_ptr< SymbolicExpr > &a, const std::shared_ptr< SymbolicExpr > &b, const std::shared_ptr< SymbolicExpr > &c, const std::shared_ptr< SymbolicExpr > &d, const std::shared_ptr< SymbolicExpr > &e, const std::string &variable, ComputationContext &context)
std::vector< std::shared_ptr< SymbolicExpr > > solve_quadratic_internal(const std::shared_ptr< SymbolicExpr > &a, const std::shared_ptr< SymbolicExpr > &b, const std::shared_ptr< SymbolicExpr > &c, ComputationContext &context)
const std::string & variable
std::vector< std::pair< Polynomial< Rational >, int > > square_free_factorization(const Polynomial< Rational > &poly)
__attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std std::shared_ptr< SymbolicExpr > r
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
std::vector< std::shared_ptr< SymbolicExpr > > solve_by_factoring(const Polynomial< SymbolicPolyCoeff > &poly, const std::string &variable)
const VectorField const VectorField & c
__attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) std const VectorField const std::string const std::shared_ptr< SymbolicExpr > & a
std::shared_ptr< SymbolicExpr > get_coeff(const Polynomial< SymbolicPolyCoeff > &p, int deg)
std::vector< Rational > find_rational_roots(const Polynomial< Rational > &poly)
static std::vector< std::shared_ptr< SymbolicExpr > > solve_closed_form_poly(const Polynomial< SymbolicPolyCoeff > &poly, const std::string &var, ComputationContext &context)
static Polynomial< SymbolicPolyCoeff > rational_to_symbolic_poly(const Polynomial< Rational > &rat_poly)
static void append_factor_solutions(const Polynomial< Rational > &factor, int multiplicity, const std::string &var, std::vector< std::shared_ptr< SymbolicExpr > > &results, ComputationContext &context)