8#include "lmmc/config.h"
26 return std::numeric_limits<double>::quiet_NaN();
28 if (expr->is_number()) {
31 return std::numeric_limits<double>::quiet_NaN();
33 if (std::holds_alternative<BigInt>(node->value())) {
34 return std::get<BigInt>(node->value()).to_double();
36 return std::get<Rational>(node->value()).to_double();
38 return std::numeric_limits<double>::quiet_NaN();
42 const std::shared_ptr<SymbolicExpr>& expr,
46 const std::string& operation)
48 auto step =
context.consume_steps(1, operation);
54 "ODE expression cannot be null",
57 if (x.empty() || y.empty()) {
59 "ODE variable names cannot be empty",
64 "ODE independent and dependent variables must be distinct",
71 const std::shared_ptr<SymbolicExpr>& first,
72 const std::shared_ptr<SymbolicExpr>& second,
76 const std::string& operation)
78 auto step =
context.consume_steps(1, operation);
84 "ODE expressions cannot be null",
87 if (x.empty() || y.empty()) {
89 "ODE variable names cannot be empty",
94 "ODE independent and dependent variables must be distinct",
102 const std::string& operation)
107 "ODE solver produced no solution in the supported domain",
113 "ODE solver reported an unexpected method",
120 const std::string& x,
121 const std::string& y,
123 const std::string& operation)
125 auto step =
context.consume_steps(1, operation);
129 if (x.empty() || y.empty()) {
131 "ODE variable names cannot be empty",
136 "ODE independent and dependent variables must be distinct",
143 const std::vector<double>& coeffs,
144 std::size_t min_size,
145 std::size_t max_size,
146 const std::string& operation)
148 if (coeffs.size() < min_size || coeffs.size() > max_size) {
150 "ODE coefficient list has unsupported size",
153 if (!std::isfinite(coeffs.front()) || coeffs.front() == 0.0) {
155 "ODE leading coefficient must be finite and nonzero",
158 for (
double coeff : coeffs) {
159 if (!std::isfinite(coeff)) {
161 "ODE coefficients must be finite",
169 const std::shared_ptr<SymbolicExpr>& first,
170 const std::shared_ptr<SymbolicExpr>& second,
171 const std::shared_ptr<SymbolicExpr>& third,
172 const std::string& x,
174 const std::string& operation)
176 auto step =
context.consume_steps(1, operation);
183 "ODE expressions cannot be null",
188 "ODE variable name cannot be empty",
195 const std::shared_ptr<SymbolicExpr>& p,
196 const std::shared_ptr<SymbolicExpr>& q,
197 const std::shared_ptr<SymbolicExpr>& x0,
198 const std::string& x,
200 const std::string& operation)
202 auto step =
context.consume_steps(1, operation);
208 "Frobenius inputs cannot be null",
213 "ODE variable name cannot be empty",
static Result failure(CasErrc code, std::string message, std::string operation={})
static Result success(T value)
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
Result< void > validate_ode_expr_var_pair(const std::shared_ptr< SymbolicExpr > &expr, const std::string &x, const std::string &y, ComputationContext &context, const std::string &operation)
ODESolutionResult wrap_ode_solution(ODESolution solution, ODEType expected_method, const std::string &operation)
ODEType method_used
使用的求解方法
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
ODEType
ODE 类型枚举,标识方程所属的求解类别.
double try_eval_double(const std::shared_ptr< SymbolicExpr > &expression)
尝试将表达式求值为 double。
Result< void > validate_ode_three_expr_one_var(const std::shared_ptr< SymbolicExpr > &first, const std::shared_ptr< SymbolicExpr > &second, const std::shared_ptr< SymbolicExpr > &third, const std::string &x, ComputationContext &context, const std::string &operation)
std::shared_ptr< SymbolicExpr > general_solution
通解表达式
Result< void > validate_numeric_ode_coefficients(const std::vector< double > &coefficients, std::size_t minimum_size, std::size_t maximum_size, const std::string &operation)
Result< void > validate_ode_variables(const std::string &x, const std::string &y, ComputationContext &context, const std::string &operation)
Result< void > validate_ode_two_expr_point(const std::shared_ptr< SymbolicExpr > &p, const std::shared_ptr< SymbolicExpr > &q, const std::shared_ptr< SymbolicExpr > &x0, const std::string &x, ComputationContext &context, const std::string &operation)
Result< void > validate_ode_pair_var_pair(const std::shared_ptr< SymbolicExpr > &first, const std::shared_ptr< SymbolicExpr > &second, const std::string &x, const std::string &y, ComputationContext &context, const std::string &operation)
Result< ODESolution > ODESolutionResult
符号表达式主类 SymbolicExpr 及其工厂方法,运算接口.
统一 ODE 求解引擎:分类,分派,多种求解方法.