LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
limit_visitor_squeeze.cpp
浏览该文件的文档.
1
#include "
internal/visitors/limit_visitor.hpp
"
2
3
namespace
LMCAS
{
4
5
std::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))) {
19
return
LMCAS::detail::make_node<NumberNode>
(BigInt(0));
20
}
21
return
nullptr
;
22
}
23
24
std::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
49
std::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
}
LMCAS::AddNode
加法节点,表示多个操作数的求和。
定义
arithmetic.hpp:55
LMCAS::MultiplyNode
乘法节点,表示多个操作数的乘积。
定义
arithmetic.hpp:134
limit_visitor.hpp
极限访问器,通过代入和 L'Hôpital 法则计算极限。
LMCAS::detail::node
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
定义
base.hpp:91
LMCAS::detail::make_node
std::shared_ptr< const Node > make_node(Args &&... args)
定义
base.hpp:123
LMCAS
定义
assumption.hpp:11
LMCAS::value
const std::string const ExprPtr & value
定义
expr.hpp:293
src
limit_visitor_squeeze.cpp
生成于
, 为 LMCAS使用
1.18.0