LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
equivalence_options.cpp
浏览该文件的文档.
1
#include "
internal/equivalence_support.hpp
"
2
3
#include <utility>
4
5
namespace
LMCAS
{
6
namespace
equivalence_detail
{
7
8
Result<void>
validate_eqv_options
(
const
EqvOptions
&
options
) {
9
if
(
options
.budget.max_rewrite_steps == 0 ||
10
options
.budget.max_rewrite_depth == 0 ||
11
options
.budget.max_node_growth_factor == 0) {
12
return
Result<void>::failure
(
13
CasErrc::ResourceLimit
,
14
"equivalence rewrite budget exhausted before normalization"
,
15
kEquivalentOperation
);
16
}
17
return
Result<void>::success
();
18
}
19
20
bool
exact_integer_node
(
const
std::shared_ptr<const SymbolicNode>& node,
21
int
expected) {
22
auto
number = std::dynamic_pointer_cast<const NumberNode>(node);
23
if
(!number)
return
false
;
24
if
(std::holds_alternative<BigInt>(number->value())) {
25
return
std::get<BigInt>(number->value()) == BigInt(expected);
26
}
27
return
std::get<Rational>(number->value()) == Rational(expected);
28
}
29
30
}
31
namespace
{
32
33
Result<EqvProfile>
eqv_profile_failure
(std::string message) {
34
return
Result<EqvProfile>::failure
(
35
CasErrc::UnsupportedExpression
,
36
std::move(message),
37
kEquivalentProfileOperation
);
38
}
39
40
}
41
42
Result<EqvProfile>
eqv_profile_from_name
(
const
std::string&
name
) {
43
if
(
name
==
"Core"
) {
44
return
Result<EqvProfile>::success
(
EqvProfile::Core
);
45
}
46
if
(
name
==
"Trig-Basic"
) {
47
return
Result<EqvProfile>::success
(
EqvProfile::TrigBasic
);
48
}
49
if
(
name
==
"ExpLog-Basic"
) {
50
return
Result<EqvProfile>::success
(
EqvProfile::ExpLogBasic
);
51
}
52
return
eqv_profile_failure(
"unsupported equivalence profile: "
+
name
);
53
}
54
55
Result<void>
set_eqv_profile
(
EqvOptions
&
options
,
56
const
std::string&
name
) {
57
auto
profile =
eqv_profile_from_name
(
name
);
58
if
(!profile) {
59
return
Result<void>::failure
(profile.error());
60
}
61
options
.profile = profile.value();
62
return
Result<void>::success
();
63
}
64
65
Result<void>
set_eqv_budget
(
EqvOptions
&
options
,
66
std::size_t
steps
,
67
std::size_t
depth
,
68
std::size_t
growth
) {
69
EqvOptions
candidate =
options
;
70
candidate.
budget
.
max_rewrite_steps
=
steps
;
71
candidate.
budget
.
max_rewrite_depth
=
depth
;
72
candidate.
budget
.
max_node_growth_factor
=
growth
;
73
auto
valid =
equivalence_detail::validate_eqv_options
(candidate);
74
if
(!valid) {
75
return
valid;
76
}
77
options
= candidate;
78
return
Result<void>::success
();
79
}
80
81
}
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
equivalence_support.hpp
LMCAS::anonymous_namespace{equivalence_options.cpp}::eqv_profile_failure
Result< EqvProfile > eqv_profile_failure(std::string message)
定义
equivalence_options.cpp:33
LMCAS::equivalence_detail
定义
equivalence_complex.cpp:9
LMCAS::equivalence_detail::validate_eqv_options
Result< void > validate_eqv_options(const EqvOptions &options)
定义
equivalence_options.cpp:8
LMCAS::equivalence_detail::exact_integer_node
bool exact_integer_node(const std::shared_ptr< const SymbolicNode > &node, int expected)
定义
equivalence_options.cpp:20
LMCAS
定义
assumption.hpp:11
LMCAS::EqvBudget::max_rewrite_depth
std::size_t max_rewrite_depth
同时活动的重写及嵌套 visitor 层数,根为第 1 层。
定义
equivalence_options.hpp:24
LMCAS::kEquivalentProfileOperation
constexpr const char * kEquivalentProfileOperation
定义
equivalence_engine.hpp:10
LMCAS::options
const std::string ComputationContext const SolveOptions & options
定义
expr.hpp:355
LMCAS::growth
std::size_t std::size_t std::size_t growth
定义
equivalence_options.hpp:45
LMCAS::CasErrc::UnsupportedExpression
@ UnsupportedExpression
定义
result.hpp:23
LMCAS::CasErrc::ResourceLimit
@ ResourceLimit
定义
result.hpp:25
LMCAS::depth
std::size_t std::size_t depth
定义
equivalence_options.hpp:44
LMCAS::EqvBudget::max_rewrite_steps
std::size_t max_rewrite_steps
一次证明及 profile 切换共享的重写遍历、候选追加与阶段步数。 形状查询和缓存清空的实际工作计入 ResourceLimits::max_steps。
定义
equivalence_options.hpp:22
LMCAS::EqvProfile::TrigBasic
@ TrigBasic
定义
equivalence_options.hpp:13
LMCAS::EqvProfile::Core
@ Core
定义
equivalence_options.hpp:12
LMCAS::EqvProfile::ExpLogBasic
@ ExpLogBasic
定义
equivalence_options.hpp:14
LMCAS::set_eqv_profile
Result< void > set_eqv_profile(EqvOptions &options, const std::string &name)
定义
equivalence_options.cpp:55
LMCAS::EqvBudget::max_node_growth_factor
std::size_t max_node_growth_factor
候选树及未封装孩子列表的规模上限取 context.max_ast_nodes 与原始两输入节点总数乘此因子的较小值。 每次子树引用分别计数;整个证明及 profile 切换共用原始基数。 乘法饱和为 ...
定义
equivalence_options.hpp:31
LMCAS::steps
std::size_t steps
定义
equivalence_options.hpp:43
LMCAS::set_eqv_budget
Result< void > set_eqv_budget(EqvOptions &options, std::size_t steps, std::size_t depth, std::size_t growth)
定义
equivalence_options.cpp:65
LMCAS::eqv_profile_from_name
Result< EqvProfile > eqv_profile_from_name(const std::string &name)
定义
equivalence_options.cpp:42
LMCAS::name
__attribute__((visibility("default"))) Result< EqvProfile > eqv_profile_from_name(const std const std::string & name
定义
equivalence_options.hpp:41
LMCAS::EqvOptions::budget
EqvBudget budget
定义
equivalence_options.hpp:36
LMCAS::kEquivalentOperation
constexpr const char * kEquivalentOperation
定义
equivalence_engine.hpp:9
LMCAS::EqvOptions
定义
equivalence_options.hpp:34
src
equivalence_options.cpp
生成于
, 为 LMCAS使用
1.18.0