LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
multiple_integral.cpp
浏览该文件的文档.
1
#include <stdexcept>
2
#include "
internal/expression_transform.hpp
"
3
#include "
internal/integration_support.hpp
"
4
5
namespace
LMCAS
{
6
7
static
bool
validate_integration_steps
(
const
std::vector<IntegrationStep>&
steps
) {
8
if
(
steps
.empty())
return
false
;
9
10
for
(
size_t
i = 0; i <
steps
.size(); ++i) {
11
const
auto
& s =
steps
[i];
12
if
(s.variable.empty())
return
false
;
13
14
// Bounds must be either both null (indefinite) or both set (definite).
15
const
bool
has_lower =
static_cast<
bool
>
(s.lower);
16
const
bool
has_upper =
static_cast<
bool
>
(s.upper);
17
if
(has_lower != has_upper)
return
false
;
18
19
// Reject duplicate variables.
20
for
(
size_t
j = 0; j < i; ++j) {
21
if
(
steps
[j].
variable
== s.variable)
return
false
;
22
}
23
}
24
return
true
;
25
}
26
27
Result<SymbolicExpr>
integrate_multiple_checked
(
28
const
SymbolicExpr& integrand,
29
const
std::vector<IntegrationStep>&
steps
,
30
Integrator&
integrator
,
31
ComputationContext
&
context
)
try
{
32
detail::RewriteBudget
transform_budget(
context
, (
context
).limits().max_recursion_depth,
33
(
context
).limits().max_ast_nodes,
"transform"
);
34
35
if
(!
validate_integration_steps
(
steps
)) {
36
return
Result<SymbolicExpr>::failure
(
37
CasErrc::InvalidArgument
,
"invalid multiple integration steps"
,
38
"integrate.multiple"
);
39
}
40
auto
access =
context
.consume_steps(0,
"integrate.multiple"
);
41
if
(!access)
return
Result<SymbolicExpr>::failure
(access.error());
42
43
auto
current =
LMCAS::detail::make_expression_ptr
(integrand);
44
45
for
(
const
auto
& step :
steps
) {
46
auto
step_access =
context
.consume_steps(1,
"integrate.multiple"
);
47
if
(!step_access) {
48
return
Result<SymbolicExpr>::failure
(step_access.error());
49
}
50
if
(!current) {
51
return
Result<SymbolicExpr>::failure
(
52
CasErrc::InternalInvariant
,
"multiple integration lost its expression"
,
53
"integrate.multiple"
);
54
}
55
56
57
const
bool
definite =
static_cast<
bool
>
(step.lower) &&
static_cast<
bool
>
(step.upper);
58
59
if
(!definite) {
60
auto
result =
integrator
.integrate_checked(*current, step.variable,
context
);
61
if
(!result)
return
result;
62
current =
LMCAS::detail::make_expression_ptr
(result.value());
63
}
else
{
64
auto
result =
integrator
.integrate_def_checked(
65
*current, step.variable, *step.lower, *step.upper,
context
);
66
if
(!result)
return
result;
67
auto
res_ptr =
LMCAS::detail::make_expression_ptr
(result.value());
68
auto
simp =
detail::make_expression_ptr
(
detail::normalize_node
(
detail::node
(res_ptr), transform_budget));
69
current = simp ? simp : res_ptr;
70
}
71
}
72
auto
final_access =
context
.consume_steps(0,
"integrate.multiple"
);
73
if
(!final_access)
return
Result<SymbolicExpr>::failure
(final_access.error());
74
75
return
Result<SymbolicExpr>::success
(*current);
76
}
catch
(
const
CasError& error) {
77
return
Result<SymbolicExpr>::failure
(error);
78
}
catch
(
const
std::bad_alloc&) {
79
return
Result<SymbolicExpr>::failure
(
CasErrc::ResourceLimit
,
"allocation failed"
,
"integrate_multiple_checked"
);
80
}
catch
(
const
std::length_error& error) {
81
return
Result<SymbolicExpr>::failure
(
CasErrc::ResourceLimit
, error.what(),
"integrate_multiple_checked"
);
82
}
catch
(
const
std::exception& error) {
83
return
Result<SymbolicExpr>::failure
(
CasErrc::InternalInvariant
, error.what(),
"integrate_multiple_checked"
);
84
}
85
86
}
// namespace LMCAS
LMCAS::ComputationContext
定义
computation_context.hpp:99
LMCAS::Result
定义
result.hpp:39
LMCAS::Result::failure
static Result failure(CasErrc code, std::string message, std::string operation={})
定义
result.hpp:52
LMCAS::Result::success
static Result success(T value)
定义
result.hpp:48
LMCAS::detail::RewriteBudget
定义
rewrite_budget.hpp:15
expression_transform.hpp
integration_support.hpp
LMCAS::detail::make_expression_ptr
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
定义
base.hpp:111
LMCAS::detail::node
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
定义
base.hpp:91
LMCAS::detail::normalize_node
SymbolicNodePtr normalize_node(const SymbolicNodePtr &node, RewriteBudget &budget, const FactsQuery &facts, Domain domain)
定义
symbolic_core.cpp:201
LMCAS
定义
assumption.hpp:11
LMCAS::variable
const std::string & variable
定义
expr.hpp:286
LMCAS::context
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
定义
exact_factorization.hpp:65
LMCAS::validate_integration_steps
static bool validate_integration_steps(const std::vector< IntegrationStep > &steps)
定义
multiple_integral.cpp:7
LMCAS::CasErrc::InvalidArgument
@ InvalidArgument
定义
result.hpp:13
LMCAS::CasErrc::InternalInvariant
@ InternalInvariant
定义
result.hpp:28
LMCAS::CasErrc::ResourceLimit
@ ResourceLimit
定义
result.hpp:25
LMCAS::integrate_multiple_checked
Result< SymbolicExpr > integrate_multiple_checked(const SymbolicExpr &integrand, const std::vector< IntegrationStep > &steps, Integrator &integrator, ComputationContext &context)
定义
multiple_integral.cpp:27
LMCAS::steps
std::size_t steps
定义
equivalence_options.hpp:43
LMCAS::integrator
const std::vector< IntegrationStep > Integrator & integrator
定义
multiple_integral.hpp:18
src
multiple_integral.cpp
生成于
, 为 LMCAS使用
1.18.0