6#define _USE_MATH_DEFINES
28class AssumptionContext;
34 std::shared_ptr<SymbolicExpr>
symbol;
35 std::shared_ptr<SymbolicExpr>
value;
49struct SymbolicExprAccess;
58class LMCAS_API SymbolicExpr :
public std::enable_shared_from_this<SymbolicExpr> {
61 std::shared_ptr<const Impl> impl_;
63 explicit SymbolicExpr(std::shared_ptr<const Impl> impl) : impl_(std::move(impl)) {
65 throw std::invalid_argument(
"SymbolicExpr requires a non-null implementation");
70 LMCAS::ComputationContext& context)
const;
72 friend struct LMCAS::detail::SymbolicExprAccess;
77 SymbolicExpr() =
delete;
84 int compare(
const std::shared_ptr<SymbolicExpr>& other)
const;
99 static std::shared_ptr<SymbolicExpr> poly_resultant(
const std::shared_ptr<SymbolicExpr>& a,
const std::shared_ptr<SymbolicExpr>& b,
const std::string& var);
106 static std::shared_ptr<SymbolicExpr> transpose(
const std::shared_ptr<SymbolicExpr>& mat);
116 static std::vector<std::map<std::string, std::shared_ptr<SymbolicExpr>>> solve_system(
117 const std::vector<std::shared_ptr<SymbolicExpr>>& equations,
118 const std::vector<std::string>& vars);
127 static std::vector<std::map<std::string, std::shared_ptr<SymbolicExpr>>> solve_system(
128 const std::vector<std::shared_ptr<SymbolicExpr>>& equations,
129 const std::vector<std::string>& unknowns,
130 const std::vector<std::string>& parameters);
140 std::shared_ptr<SymbolicExpr> series(
const std::string& var,
const std::shared_ptr<SymbolicExpr>& point,
int order,
const LMCAS::AssumptionContext* ctx =
nullptr)
const;
148 static std::shared_ptr<SymbolicExpr>
divide(
const std::shared_ptr<SymbolicExpr>& num,
const std::shared_ptr<SymbolicExpr>& den);
156 static std::shared_ptr<SymbolicExpr> make_integral(
const std::shared_ptr<SymbolicExpr>& expr,
const std::string& var);
165 static std::shared_ptr<SymbolicExpr> make_limit(
const std::shared_ptr<SymbolicExpr>& expr,
const std::string& var,
const std::shared_ptr<SymbolicExpr>& point);
171 LMCAS::ComputationContext& context)
const;
183 std::shared_ptr<SymbolicExpr> cancel()
const;
191 static std::shared_ptr<SymbolicExpr> number(
int n);
195 std::enable_if_t<std::is_integral_v<Integer> &&
196 !std::is_same_v<Integer, int>,
int> = 0>
197 static std::shared_ptr<SymbolicExpr> number(Integer) =
delete;
199 static std::shared_ptr<SymbolicExpr> number(
double n);
206 static std::shared_ptr<SymbolicExpr> number(const ::LMCAS::BigInt& bi);
213 static std::shared_ptr<SymbolicExpr> number(const ::LMCAS::Rational& r);
220 static std::shared_ptr<SymbolicExpr> infinity(
int k = 1);
227 static std::shared_ptr<SymbolicExpr>
sqrt(std::shared_ptr<SymbolicExpr> operand);
235 static std::shared_ptr<SymbolicExpr>
multiply(std::shared_ptr<SymbolicExpr> left, std::shared_ptr<SymbolicExpr> right);
243 static std::shared_ptr<SymbolicExpr>
add(std::shared_ptr<SymbolicExpr> left, std::shared_ptr<SymbolicExpr> right);
251 static std::shared_ptr<SymbolicExpr> power(std::shared_ptr<SymbolicExpr> base, std::shared_ptr<SymbolicExpr> exponent);
258 static std::shared_ptr<SymbolicExpr>
sin(std::shared_ptr<SymbolicExpr> op);
265 static std::shared_ptr<SymbolicExpr>
cos(std::shared_ptr<SymbolicExpr> op);
272 static std::shared_ptr<SymbolicExpr>
tan(std::shared_ptr<SymbolicExpr> op);
279 static std::shared_ptr<SymbolicExpr> ln(std::shared_ptr<SymbolicExpr> op);
286 static std::shared_ptr<SymbolicExpr>
exp(std::shared_ptr<SymbolicExpr> op);
293 static std::shared_ptr<SymbolicExpr> lambertw(std::shared_ptr<SymbolicExpr> op);
301 static std::shared_ptr<SymbolicExpr>
log(std::shared_ptr<SymbolicExpr> val, std::shared_ptr<SymbolicExpr> base);
309 static std::shared_ptr<SymbolicExpr> atan2(std::shared_ptr<SymbolicExpr> y, std::shared_ptr<SymbolicExpr> x);
318 static std::shared_ptr<SymbolicExpr> root_of(std::shared_ptr<SymbolicExpr> poly,
const std::string& var,
int index);
326 static std::shared_ptr<SymbolicExpr>
eq(std::shared_ptr<SymbolicExpr> lhs, std::shared_ptr<SymbolicExpr> rhs);
333 static std::shared_ptr<SymbolicExpr> matrix(
const std::vector<std::vector<std::shared_ptr<SymbolicExpr>>>& elements);
340 static std::shared_ptr<SymbolicExpr>
variable(
const std::string& name);
346 std::shared_ptr<SymbolicExpr> simplify_trig()
const;
352 std::string to_string()
const;
355 bool is_number()
const;
358 bool get_number_value_is_zero()
const;
361 bool is_big_int()
const;
364 bool is_rational()
const;
374 std::variant<int, ::LMCAS::BigInt, ::LMCAS::Rational> get_number()
const;
382 ::LMCAS::BigInt get_big_int()
const;
399 lmmc_real_t to_numeric()
const;
任意精度整数 BigInt,底层调用 LMMP 实现高性能大数运算。
bool is_zero(const SymbolicExpr &expression)
Node divide(const Node &numerator, const Node &denominator)
Node multiply(const Node &left, const Node &right)
Node add(const Node &left, const Node &right)
const std::string & variable
ExprResult eq(const ExprPtr &lhs, const ExprPtr &rhs, ComputationContext &context)
ExprResult exp(const ExprPtr &expression, ComputationContext &context)
@ Rational
Rational numbers
std::shared_ptr< SymbolicExpr > symbol
Result< std::shared_ptr< SymbolicExpr > > ExpressionResult
Result of an operation that produces a symbolic expression.
ExprResult sin(const ExprPtr &expression, ComputationContext &context)
RelationOp
Stable relational operator used by public APIs.
ExprResult tan(const ExprPtr &expression, ComputationContext &context)
ExprResult cos(const ExprPtr &expression, ComputationContext &context)
ExprResult sqrt(const ExprPtr &expression, ComputationContext &context)
std::shared_ptr< SymbolicExpr > value
ExprResult log(const ExprPtr &expression, ComputationContext &context)
精确有理数 Rational,基于 BigInt 分子/分母表示,自动约分。