LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
assumption_parse_intervals.cpp
浏览该文件的文档.
1
#include "
internal/assumption_parser.hpp
"
2
3
namespace
LMCAS::assumption_detail
{
4
5
void
AssumptionParser::parse_periodic
(
6
std::istringstream& ls,
const
std::string& keyword) {
7
std::string
sym
,
variable
;
8
if
(!(ls >>
sym
>>
variable
)) {
9
throw
std::invalid_argument(
10
"Line "
+ std::to_string(
line_num
) +
": PERIODIC requires symbol and variable"
);
11
}
12
std::string period_str;
13
std::getline(ls, period_str);
14
const
auto
period_text =
trim_ascii_whitespace
(period_str);
15
if
(period_text.empty()) {
16
throw
std::invalid_argument(
17
"Line "
+ std::to_string(
line_num
) +
": PERIODIC requires period value"
);
18
}
19
auto
period =
parse_serialized_expression
(
20
std::string(period_text),
line_num
,
computation
);
21
require_deserialization_update
(
22
ctx
.current_properties().declare_periodic_checked(
23
sym
,
variable
, period),
24
line_num
, keyword);
25
}
26
27
void
AssumptionParser::parse_continuity
(
28
std::istringstream& ls,
const
std::string& keyword) {
29
std::string
sym
;
30
if
(!(ls >>
sym
)) {
31
throw
std::invalid_argument(
32
"Line "
+ std::to_string(
line_num
) +
": "
+ keyword +
" requires symbol"
);
33
}
34
std::string iv_str;
35
std::getline(ls, iv_str);
36
const
auto
interval_text =
trim_ascii_whitespace
(iv_str);
37
if
(interval_text.empty()) {
38
throw
std::invalid_argument(
39
"Line "
+ std::to_string(
line_num
) +
": "
+ keyword +
" requires interval"
);
40
}
41
Interval iv =
parse_interval
(
42
std::string(interval_text),
line_num
,
computation
);
43
auto
declared = keyword ==
"DIFFERENTIABLE"
44
?
ctx
.current_properties().declare_differentiable_checked(
45
sym
, iv,
computation
)
46
:
ctx
.current_properties().declare_continuous_checked(
47
sym
, iv,
computation
);
48
require_deserialization_update
(declared,
line_num
, keyword);
49
}
50
51
52
void
AssumptionParser::parse_monotonicity
(
53
std::istringstream& ls,
const
std::string& keyword) {
54
55
std::string
sym
, var;
56
if
(!(ls >>
sym
>> var)) {
57
throw
std::invalid_argument(
58
"Line "
+ std::to_string(
line_num
) +
59
": MONOTONICITY requires symbol and variable"
);
60
}
61
std::string rest_line;
62
std::getline(ls, rest_line);
63
const
auto
monotonicity_text =
trim_ascii_whitespace
(rest_line);
64
if
(monotonicity_text.empty()) {
65
throw
std::invalid_argument(
66
"Line "
+ std::to_string(
line_num
) +
67
": MONOTONICITY requires interval and type"
);
68
}
69
rest_line = monotonicity_text;
70
size_t
bracket_end = std::string::npos;
71
if
(rest_line.front() ==
'['
|| rest_line.front() ==
'('
) {
72
size_t
depth
= 0;
73
for
(
size_t
i = 1; i < rest_line.size(); ++i) {
74
const
char
c
= rest_line[i];
75
if
(
c
==
'('
||
c
==
'['
) {
76
++
depth
;
77
}
else
if
(
c
==
')'
||
c
==
']'
) {
78
if
(
depth
== 0) {
79
bracket_end = i;
80
break
;
81
}
82
--
depth
;
83
}
84
}
85
}
86
if
(bracket_end == std::string::npos) {
87
throw
std::invalid_argument(
88
"Line "
+ std::to_string(
line_num
) +
89
": MONOTONICITY malformed interval"
);
90
}
91
std::string mono_iv_str = rest_line.substr(0, bracket_end + 1);
92
Interval iv =
parse_interval
(mono_iv_str,
line_num
,
computation
);
93
94
std::string mono_str = rest_line.substr(bracket_end + 1);
95
const
auto
type_text =
trim_ascii_whitespace
(mono_str);
96
if
(type_text.empty()) {
97
throw
std::invalid_argument(
98
"Line "
+ std::to_string(
line_num
) +
99
": MONOTONICITY requires type after interval"
);
100
}
101
mono_str = type_text;
102
103
Monotonicity
m =
assumption_detail::parse_monotonicity
(mono_str,
line_num
);
104
require_deserialization_update
(
105
ctx
.current_properties().declare_monotonicity_checked(
106
sym
, var, iv, m,
computation
),
107
line_num
, keyword);
108
}
109
110
111
}
assumption_parser.hpp
LMCAS::assumption_detail::AssumptionParser::line_num
int line_num
定义
assumption_parser.hpp:42
LMCAS::assumption_detail::AssumptionParser::parse_periodic
void parse_periodic(std::istringstream &ls, const std::string &keyword)
定义
assumption_parse_intervals.cpp:5
LMCAS::assumption_detail::AssumptionParser::computation
ComputationContext & computation
定义
assumption_parser.hpp:40
LMCAS::assumption_detail::AssumptionParser::parse_continuity
void parse_continuity(std::istringstream &ls, const std::string &keyword)
定义
assumption_parse_intervals.cpp:27
LMCAS::assumption_detail::AssumptionParser::ctx
AssumptionContext ctx
定义
assumption_parser.hpp:41
LMCAS::assumption_detail::AssumptionParser::parse_monotonicity
void parse_monotonicity(std::istringstream &ls, const std::string &keyword)
定义
assumption_parse_intervals.cpp:52
LMCAS::assumption_detail
定义
assumption_deserialization.cpp:3
LMCAS::assumption_detail::parse_monotonicity
Monotonicity parse_monotonicity(const std::string &s, int line_num)
定义
assumption_parse_values.cpp:79
LMCAS::assumption_detail::trim_ascii_whitespace
std::string_view trim_ascii_whitespace(std::string_view text) noexcept
定义
assumption_parse_atoms.cpp:10
LMCAS::assumption_detail::require_deserialization_update
void require_deserialization_update(const Result< void > &result, int line, const std::string &keyword)
定义
assumption_parse_atoms.cpp:51
LMCAS::assumption_detail::parse_serialized_expression
SymbolicExpr parse_serialized_expression(const std::string &text, int line_num, ComputationContext &context)
定义
assumption_parse_atoms.cpp:154
LMCAS::assumption_detail::parse_interval
Interval parse_interval(const std::string &text, int line_num, ComputationContext &context)
定义
assumption_parse_atoms.cpp:266
LMCAS::variable
const std::string & variable
定义
expr.hpp:286
LMCAS::c
const VectorField const VectorField & c
定义
vector_calculus_vectors.hpp:60
LMCAS::Monotonicity
Monotonicity
Monotonicity classification for functions over intervals.
定义
assumption.hpp:57
LMCAS::depth
std::size_t std::size_t depth
定义
equivalence_options.hpp:44
LMCAS::sym
ExprResult sym(const std::string &name)
定义
expr_values.cpp:30
src
assumption_parse_intervals.cpp
生成于
, 为 LMCAS使用
1.18.0