14#include "lmmc/config.h"
15#include "lmmc/numeric.h"
23#include <unordered_set>
40 std::unordered_set<std::string>
wildcards,
49 const SymbolicExpr& base,
const SymbolicExpr&
exponent,
57 const SymbolicExpr& expression,
62inline std::shared_ptr<SymbolicExpr>
sym_sub(
63 const SymbolicExpr& lhs,
64 const SymbolicExpr&
rhs) {
65 auto negated_rhs = SymbolicExpr::multiply(
71 const BigInt& numerator,
const BigInt&
denominator) {
72 return SymbolicExpr::number(Rational(numerator,
denominator));
75 const NumberNode& number,
int minimum_exponent,
int maximum_exponent) {
76 const auto narrow = [minimum_exponent, maximum_exponent](
const BigInt&
exponent)
77 -> std::optional<int> {
78 if (
exponent < BigInt(minimum_exponent) ||
exponent > BigInt(maximum_exponent)) {
81 const auto bounded_exponent =
exponent.try_to_int64();
82 if (!bounded_exponent) {
return std::nullopt; }
83 return static_cast<int>(*bounded_exponent);
88 if (!
exponent->is_integer()) {
return std::nullopt; }
89 return narrow(
exponent->to_bigint());
97 const std::shared_ptr<SymbolicExpr>& operand) {
100 std::vector<std::shared_ptr<const SymbolicNode>>{
105 const std::shared_ptr<SymbolicExpr>& operand) {
110 const std::shared_ptr<const SymbolicNode>& node) {
115template <
typename Transform>
117 const std::vector<detail::IntegrationEntry>& table,
const SymbolicExpr& matched,
119 for (
const auto& rule : table) {
120 const auto* entry = &rule;
123 if (!Matcher::match(entry->pattern, matched, entry->wildcards,
bindings)) {
continue; }
128 const bool complete = std::all_of(entry->wildcards.begin(), entry->wildcards.end(),
129 [&](
const std::string&
name) { return bindings.find(name) != bindings.end(); });
130 if (!complete || (entry->condition && !entry->condition(
bindings, matched_variable, budget.
context()))) {
134 Matcher::replace(entry->result,
bindings,
false));
139 auto candidate = transform(std::move(instantiated));
140 if (!candidate) {
continue; }
AssumptionContext class with scoped push/pop management.
const std::variant< BigInt, Rational > & value() const noexcept
ComputationContext & context() const noexcept
std::size_t measure(const std::shared_ptr< const SymbolicNode > &node)
Symbolic integration APIs.
模式匹配引擎 Matcher 与重写规则系统 RewriteEngine。
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
bool contains_node_type(const SymbolicNodePtr &root)
SymbolicExpr materialize_integral(const IntegralParts &parts, const std::string &variable, RewriteBudget &budget)
Result< std::optional< SymbolicExpr > > integrate_power_primitive(const SymbolicExpr &base, const SymbolicExpr &exponent, const std::string &variable, ComputationContext &)
bool integration_depends_on_variable(const SymbolicNodePtr &expression, const std::string &variable, RewriteBudget *budget=nullptr)
std::shared_ptr< const Node > make_node(Args &&... args)
std::vector< IntegrationEntry > make_integration_entries()
SymbolicNodePtr normalize_node(const SymbolicNodePtr &node, RewriteBudget &budget, const FactsQuery &facts, Domain domain)
const std::string & variable
std::shared_ptr< SymbolicExpr > lookup_integral(const std::vector< detail::IntegrationEntry > &table, const SymbolicExpr &matched, const std::string &matched_variable, detail::RewriteBudget &budget, Transform &&transform)
bool contains_unevaluated_integral(const std::shared_ptr< const SymbolicNode > &node)
std::shared_ptr< SymbolicExpr > make_arctan(const std::shared_ptr< SymbolicExpr > &operand)
bool depends_on_integration_variable(const SymbolicExpr &expression, const std::string &variable)
std::shared_ptr< SymbolicExpr > sym_rational(const BigInt &numerator, const BigInt &denominator)
const std::vector< Binding > & bindings
std::unordered_map< std::string, SymbolicExpr > MatchMap
匹配结果映射,通配符名称 → 绑定的表达式
const std::string const ExprPtr & value
std::shared_ptr< SymbolicExpr > make_unary_function(FunctionNode::FuncType type, const std::shared_ptr< SymbolicExpr > &operand)
std::shared_ptr< SymbolicExpr > sym_sub(const SymbolicExpr &lhs, const SymbolicExpr &rhs)
std::optional< int > integration_bounded_exponent(const NumberNode &number, int minimum_exponent, int maximum_exponent)
const ExprPtr & denominator
__attribute__((visibility("default"))) Result< EqvProfile > eqv_profile_from_name(const std const std::string & name
一元多项式模板类 Polynomial<T>,支持四则运算,GCD,求导,求值.
std::unordered_set< std::string > wildcards
std::function< bool(const MatchMap &, const std::string &, ComputationContext &)> condition
IntegrationEntry(std::string name, SymbolicExpr pattern, SymbolicExpr result, std::unordered_set< std::string > wildcards, std::function< bool(const MatchMap &, const std::string &, ComputationContext &)> condition=nullptr, int priority=100)