LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
limit_visitor_squeeze.cpp
浏览该文件的文档.
2
3namespace LMCAS {
4
5std::shared_ptr<const SymbolicNode> LimitVisitor::squeeze_product(const MultiplyNode& node) {
6 bool has_bounded = false;
7 std::vector<std::shared_ptr<const SymbolicNode>> other_factors;
8 for (const auto& operand : node.operands()) {
9 if (is_bounded(operand) || is_bounded_expression(operand)) {
10 has_bounded = true;
11 } else {
12 other_factors.push_back(operand);
13 }
14 }
15 if (!has_bounded || other_factors.empty()) {
16 return nullptr;
17 }
18 if (tends_to_zero(make_product_or_one(other_factors))) {
20 }
21 return nullptr;
22}
23
24std::shared_ptr<const SymbolicNode> LimitVisitor::squeeze_sum(const AddNode& node) {
25 bool has_squeezed_term = false;
26 std::vector<std::shared_ptr<const SymbolicNode>> other_terms;
27 for (const auto& operand : node.operands()) {
28 if (auto product = std::dynamic_pointer_cast<const MultiplyNode>(operand)) {
29 auto squeezed = squeeze_product(*product);
30 if (squeezed && squeezed->is_zero()) {
31 has_squeezed_term = true;
32 continue;
33 }
34 }
35 other_terms.push_back(operand);
36 }
37 if (!has_squeezed_term || other_terms.empty()) {
38 return nullptr;
39 }
40 auto remaining = other_terms.size() == 1 ? other_terms[0] :
41 std::static_pointer_cast<const SymbolicNode>(LMCAS::detail::make_node<AddNode>(other_terms));
42 auto value = eval_limit(remaining);
43 if (value && !is_inf(value)) {
44 return value;
45 }
46 return nullptr;
47}
48
49std::shared_ptr<const SymbolicNode> LimitVisitor::try_squeeze(
50 const std::shared_ptr<const SymbolicNode>& expr) {
51 if (auto product = std::dynamic_pointer_cast<const MultiplyNode>(expr)) {
52 return squeeze_product(*product);
53 }
54 if (auto sum = std::dynamic_pointer_cast<const AddNode>(expr)) {
55 return squeeze_sum(*sum);
56 }
57 return nullptr;
58}
59
60}
加法节点,表示多个操作数的求和。
乘法节点,表示多个操作数的乘积。
极限访问器,通过代入和 L'Hôpital 法则计算极限。
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
std::shared_ptr< const Node > make_node(Args &&... args)
const std::string const ExprPtr & value