LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
assumption_parse_intervals.cpp
浏览该文件的文档.
2
4
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);
22 ctx.current_properties().declare_periodic_checked(
23 sym, variable, period),
24 line_num, keyword);
25}
26
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
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
105 ctx.current_properties().declare_monotonicity_checked(
106 sym, var, iv, m, computation),
107 line_num, keyword);
108}
109
110
111}
void parse_periodic(std::istringstream &ls, const std::string &keyword)
void parse_continuity(std::istringstream &ls, const std::string &keyword)
void parse_monotonicity(std::istringstream &ls, const std::string &keyword)
Monotonicity parse_monotonicity(const std::string &s, int line_num)
std::string_view trim_ascii_whitespace(std::string_view text) noexcept
void require_deserialization_update(const Result< void > &result, int line, const std::string &keyword)
SymbolicExpr parse_serialized_expression(const std::string &text, int line_num, ComputationContext &context)
Interval parse_interval(const std::string &text, int line_num, ComputationContext &context)
const std::string & variable
const VectorField const VectorField & c
Monotonicity
Monotonicity classification for functions over intervals.
std::size_t std::size_t depth
ExprResult sym(const std::string &name)