Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
endgames.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/io/parsing/settings_parsers/endgames.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/io/parsing/settings_parsers/endgames.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/io/parsing/settings_parsers/endgames.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22
28
29#pragma once
30
31
34
35
36namespace bertini {
37 namespace parsing {
38 namespace classic {
39
40
41
45 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
47 struct ConfigSettingParser<Iterator, bertini::endgame::SecurityConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::SecurityConfig(), Skipper>
48 {
49 using T = double;
50
51 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "SecurityConfig")
52 {
53
54 namespace phx = boost::phoenix;
55 using qi::_1;
56 using qi::_2;
57 using qi::_3;
58 using qi::_4;
59 using qi::_val;
60 using qi::eps;
61 using qi::lit;
62 using qi::char_;
63 using qi::omit;
64 using boost::spirit::lexeme;
65 using boost::spirit::as_string;
66 using boost::spirit::ascii::no_case;
67
68
69
70 std::string level_name = "securitylevel";
71 std::string maxnorm_name = "securitymaxnorm";
72
73
74 root_rule_.name("config::Security");
75
76 root_rule_ = ((security_level_[phx::bind( [](bertini::endgame::SecurityConfig & S, int l)
77 {
78 S.level = l;
79 }, _val, _1 )]
80 ^ security_max_norm_[phx::bind( [](bertini::endgame::SecurityConfig & S, T norm)
81 {
82 S.max_norm = norm;
83 }, _val, _1 )])
84 >> -no_setting_) | no_setting_;
85
86 all_names_ = (no_case[level_name] >> ':') | (no_case[maxnorm_name] >> ':');
87
88 security_level_.name("security_level_");
89 security_level_ = *(char_ - all_names_) >> (no_case[level_name] >> ':') >> qi::int_[_val = _1] >> ';';
90
91 security_max_norm_.name("security_max_norm_");
92 security_max_norm_ = *(char_ - all_names_) >> (no_case[maxnorm_name] >> ':')
93 >> mpfr_rules.number_string_[phx::bind( [](T & num, std::string str)
94 {
96 }, _val, _1 )] >> ';';
97
98 no_setting_.name("no_setting_");
99 no_setting_ = *(char_ - all_names_);
100
101 no_decl_.name("no_decl_");
102 no_decl_ = *(char_);
103
104
105
106
107 qi::on_error<qi::fail>(
108 root_rule_,
109 phx::bind(&ReportParseError, _1, _2, _3, _4, std::string("config::Security"))
110 );
111
112
113
114 }
115
116
117 private:
118 qi::rule<Iterator, bertini::endgame::SecurityConfig(), ascii::space_type > root_rule_;
119 qi::rule<Iterator, int(), ascii::space_type > security_level_;
120 qi::rule<Iterator, T(), ascii::space_type > security_max_norm_;
121 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
122 rules::LongNum<Iterator> mpfr_rules;
123
124
125
126 }; //re: SecurityParser
127
128
129
130
131
135 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
137 struct ConfigSettingParser<Iterator, bertini::endgame::EndgameConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::EndgameConfig(), Skipper>
138 {
139 using T = double;
140 using R = mpq_rational;
141
142
143 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "EndgameConfig")
144 {
145 namespace phx = boost::phoenix;
146 using qi::_1;
147 using qi::_2;
148 using qi::_3;
149 using qi::_4;
150 using qi::_val;
151 using qi::eps;
152 using qi::lit;
153 using qi::char_;
154 using qi::omit;
155 using boost::spirit::lexeme;
156 using boost::spirit::as_string;
157 using boost::spirit::ascii::no_case;
158
159
160
161 std::string samplefactor_name = "samplefactor";
162 std::string numpoints_name = "numsamplepoints";
163 std::string mintrack_name = "nbhdradius";
164 std::string final_tol_name = "finaltol";
165
166
167 root_rule_.name("config::Endgame");
168
169 root_rule_ = ((sample_factor_[phx::bind( [](bertini::endgame::EndgameConfig & S, R num)
170 {
171 S.sample_factor = num;
172 }, _val, _1 )]
173 ^ min_track_[phx::bind( [](bertini::endgame::EndgameConfig & S, T num)
174 {
175 S.min_track_time = num;
176 }, _val, _1 )]
177 ^ num_sample_[phx::bind( [](bertini::endgame::EndgameConfig & S, unsigned num)
178 {
179 S.num_sample_points = num;
180 }, _val, _1 )]
181 ^ final_tol_[phx::bind( [](bertini::endgame::EndgameConfig & S, T num)
182 {
183 S.final_tolerance = num;
184 }, _val, _1 )])
185
186 >> -no_setting_)
187 | no_setting_;
188
189
190 all_names_ = (no_case[samplefactor_name] >> ':') | (no_case[numpoints_name] >> ':')| (no_case[mintrack_name] >> ':')
191 | (no_case[final_tol_name] >> ':');
192
193 sample_factor_.name("sample_factor_");
194 sample_factor_ = *(char_ - all_names_) >> (no_case[samplefactor_name] >> ':')
195 >> mpfr_rules.rational[phx::bind( [](R & num, std::string const& str)
196 {
198 }, _val, _1 )] >> ';';
199
200 min_track_.name("min_track_");
201 min_track_ = *(char_ - all_names_) >> (no_case[mintrack_name] >> ':')
202 >> mpfr_rules.number_string_[phx::bind( [](T & num, std::string str)
203 {
205 }, _val, _1 )] >> ';';
206
207 num_sample_.name("num_sample_");
208 num_sample_ = *(char_ - all_names_) >> (no_case[numpoints_name] >> ':')
209 >> qi::uint_[_val=_1] >> ';';
210
211 final_tol_.name("final_tol_");
212 final_tol_ = *(char_ - all_names_) >> (no_case[final_tol_name] >> ':')
213 >> mpfr_rules.number_string_[phx::bind( [](T & num, std::string str)
214 {
216 }, _val, _1 )] >> ';';
217
218 no_setting_.name("no_setting_");
219 no_setting_ = *(char_ - all_names_);
220
221 no_decl_.name("no_decl_");
222 no_decl_ = *(char_);
223
224
225
226
227
228 qi::on_error<qi::fail>(
229 root_rule_,
230 phx::bind(&ReportParseError, _1, _2, _3, _4, std::string("config::Endgame"))
231 );
232
233
234
235 }
236
237
238 private:
239 qi::rule<Iterator, bertini::endgame::EndgameConfig(), ascii::space_type > root_rule_;
240 qi::rule<Iterator, R(), ascii::space_type > sample_factor_;
241 qi::rule<Iterator, T(), ascii::space_type > min_track_, final_tol_;
242 qi::rule<Iterator, unsigned int(), ascii::space_type > num_sample_;
243 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
244 rules::LongNum<Iterator> mpfr_rules;
245 }; //re: EndgameParser
246
247
248
249
250
254 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
256 struct ConfigSettingParser<Iterator, bertini::endgame::PowerSeriesConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::PowerSeriesConfig(), Skipper>
257 {
258 using T = double;
259
260 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "bertini::endgame::PowerSeriesConfigType")
261 {
262 namespace phx = boost::phoenix;
263 using qi::_1;
264 using qi::_2;
265 using qi::_3;
266 using qi::_4;
267 using qi::_val;
268 using qi::eps;
269 using qi::lit;
270 using qi::char_;
271 using qi::omit;
272 using boost::spirit::lexeme;
273 using boost::spirit::as_string;
274 using boost::spirit::ascii::no_case;
275
276
277
278 std::string maxcycle_name = "maxcyclenum";
279
280
281 root_rule_.name("bertini::endgame::PowerSeriesConfig");
282
283 root_rule_ = (max_cycle_[phx::bind( [](bertini::endgame::PowerSeriesConfig & S, unsigned num)
284 {
285 S.max_cycle_number = num;
286 }, _val, _1 )]
287
288 >> -no_setting_)
289 | no_setting_;
290
291
292
293 all_names_ = eps >> (no_case[maxcycle_name] >> ':');
294
295 max_cycle_.name("max_cycle_");
296 max_cycle_ = *(char_ - all_names_) >> (no_case[maxcycle_name] >> ':') >> qi::uint_[_val=_1] >> ';';
297
298 no_setting_.name("no_setting_");
299 no_setting_ = *(char_ - all_names_);
300
301 no_decl_.name("no_decl_");
302 no_decl_ = *(char_);
303
304
305
306
307
308 qi::on_error<qi::fail>(
309 root_rule_,
310 phx::bind(&ReportParseError, _1, _2, _3, _4, std::string("bertini::endgame::PowerSeriesConfig"))
311 );
312
313
314
315 }
316
317
318 private:
319 qi::rule<Iterator, bertini::endgame::PowerSeriesConfig(), Skipper> root_rule_;
320 qi::rule<Iterator, unsigned int(), ascii::space_type > max_cycle_;
321 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
322 }; //re: PowerSeriesParser
323
324
325
326
327
331 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
333 struct ConfigSettingParser<Iterator, bertini::endgame::CauchyConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::CauchyConfig(), Skipper>
334 {
335 using T = double;
336
337 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "bertini::endgame::CauchyConfig")
338 {
339 namespace phx = boost::phoenix;
340 using qi::_1;
341 using qi::_2;
342 using qi::_3;
343 using qi::_4;
344 using qi::_val;
345 using qi::eps;
346 using qi::lit;
347 using qi::char_;
348 using qi::omit;
349 using boost::spirit::lexeme;
350 using boost::spirit::as_string;
351 using boost::spirit::ascii::no_case;
352
353
354
355 std::string cyclecutoff_name = "cycletimecutoff";
356 std::string ratiocutoff_name = "ratiotimecutoff";
357
358
359 root_rule_.name("config::Cauchy");
360
361 root_rule_ = ((cycle_cutoff_[phx::bind( [](bertini::endgame::CauchyConfig & S, T num)
362 {
363 S.cycle_cutoff_time = num;
364 }, _val, _1 )]
365 ^ ratio_cutoff_[phx::bind( [](bertini::endgame::CauchyConfig & S, T num)
366 {
367 S.ratio_cutoff_time = num;
368 }, _val, _1 )])
369 >> -no_setting_) | no_setting_;
370
371 all_names_ = (no_case[cyclecutoff_name] >> ':') | (no_case[ratiocutoff_name] >> ':');
372
373 cycle_cutoff_.name("cycle_cutoff_");
374 cycle_cutoff_ = *(char_ - all_names_) >> (no_case[cyclecutoff_name] >> ':')
375 >> mpfr_rules.number_string_[phx::bind( [](T & num, std::string str)
376 {
378 }, _val, _1 )] >> ';';
379
380 ratio_cutoff_.name("ratio_cutoff_");
381 ratio_cutoff_ = *(char_ - all_names_) >> (no_case[ratiocutoff_name] >> ':')
382 >> mpfr_rules.number_string_[phx::bind( [](T & num, std::string str)
383 {
385 }, _val, _1 )] >> ';';
386
387 no_setting_.name("no_setting_");
388 no_setting_ = *(char_ - all_names_);
389
390 no_decl_.name("no_decl_");
391 no_decl_ = *(char_);
392
393
394
395
396 qi::on_error<qi::fail>(
397 root_rule_,
398 phx::bind(&ReportParseError, _1, _2, _3, _4, std::string("config::Cauchy"))
399 );
400
401
402
403 }
404
405
406 private:
407 qi::rule<Iterator, bertini::endgame::CauchyConfig(), ascii::space_type > root_rule_;
408 qi::rule<Iterator, T(), ascii::space_type > cycle_cutoff_, ratio_cutoff_;
409 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
410 rules::LongNum<Iterator> mpfr_rules;
411
412
413
414 }; //re: CauchyParser
415
416
417
418 template<typename Iterator, typename Skipper> //boost::spirit::unused_type
420 struct ConfigSettingParser<Iterator, bertini::endgame::TrackBackConfig, Skipper> : qi::grammar<Iterator, bertini::endgame::TrackBackConfig(), Skipper>
421 {
422 using T = double;
423
424 ConfigSettingParser() : ConfigSettingParser::base_type(root_rule_, "bertini::endgame::TrackBackConfig")
425 {
426 namespace phx = boost::phoenix;
427 using qi::_1;
428 using qi::_2;
429 using qi::_3;
430 using qi::_4;
431 using qi::_val;
432 using qi::eps;
433 using qi::lit;
434 using qi::char_;
435 using qi::omit;
436 using boost::spirit::lexeme;
437 using boost::spirit::as_string;
438 using boost::spirit::ascii::no_case;
439
440
441
442 std::string min_cycle_name = "mincycletrackback";
443 std::string junk_removal_name = "junkremovaltrackback";
444 std::string maxdepth_name = "maxldtdepth";
445
446 root_rule_.name("bertini::endgame::TrackBackConfig");
447
448 root_rule_ = root_rule_ = ((min_cycle_[phx::bind( [](bertini::endgame::TrackBackConfig & S, unsigned num)
449 {
450 S.minimum_cycle = num;
451 }, _val, _1 )]
452 ^ junk_removal_[phx::bind( [](bertini::endgame::TrackBackConfig & S, int num)
453 {
454 S.junk_removal_test = static_cast<bool>(num);
455 }, _val, _1 )]
456 ^ max_depth_[phx::bind( [](bertini::endgame::TrackBackConfig & S, unsigned num)
457 {
458 S.max_depth_LDT = num;
459 }, _val, _1 )]
460 )
461 >> -no_setting_) | no_setting_;
462
463
464
465 all_names_ = eps >> (no_case[min_cycle_name] >> ':') |
466 (no_case[junk_removal_name] >> ':') |
467 (no_case[maxdepth_name] >> ':');
468
469 min_cycle_.name("min_cycle_");
470 min_cycle_ = *(char_ - all_names_) >> (no_case[min_cycle_name] >> ':') >> qi::uint_[_val=_1] >> ';';
471
472 junk_removal_.name("junk_removal_");
473 junk_removal_ = *(char_ - all_names_) >> (no_case[junk_removal_name] >> ':') >> qi::int_[_val=_1] >> ';';
474
475 max_depth_.name("max_depth_");
476 max_depth_ = *(char_ - all_names_) >> (no_case[maxdepth_name] >> ':') >> qi::uint_[_val=_1] >> ';';
477
478 no_setting_.name("no_setting_");
479 no_setting_ = *(char_ - all_names_);
480
481 no_decl_.name("no_decl_");
482 no_decl_ = *(char_);
483
484
485
486
487
488 qi::on_error<qi::fail>(
489 root_rule_,
490 phx::bind(&ReportParseError, _1, _2, _3, _4, std::string("bertini::endgame::TrackBackConfig"))
491 );
492
493
494
495 }
496
497
498 private:
499 qi::rule<Iterator, bertini::endgame::TrackBackConfig(), Skipper> root_rule_;
500 qi::rule<Iterator, unsigned int(), ascii::space_type > min_cycle_, max_depth_;
501 qi::rule<Iterator, int(), ascii::space_type > junk_removal_;
502 qi::rule<Iterator, ascii::space_type, std::string()> no_decl_, no_setting_, all_names_;
503 }; //re: TrackBackParser
504
505
506
507
508
509 } // re: namespace classic
510
511 }// re: namespace parsing
512}// re: namespace bertini
Provides the base type for config settings parsers.
Configs and settings for endgames.
Definition classic_utilities.hpp:41
void ReportParseError(std::string::const_iterator begin, std::string::const_iterator end, std::string::const_iterator err_pos, boost::spirit::info const &what, std::string const &parser_name)
Report a parse error (via FormatParseError) to the log, for use in a Spirit on_error handler.
Definition qi_files.hpp:199
Definition classic_utilities.hpp:40
Definition algorithm_builder.hpp:36
boost::multiprecision::number< boost::multiprecision::backends::gmp_rational, boost::multiprecision::et_on > mpq_rational
The exact rational number type.
Definition mpfr_extensions.hpp:55
Numeric traits for a bertini number type: digit counts, conversions, and companion types.
Definition num_traits.hpp:57
Cauchy-endgame configuration.
Definition config.hpp:142
T ratio_cutoff_time
Time below which the c/k ratio test stops.
Definition config.hpp:146
T cycle_cutoff_time
Time below which the cycle-number heuristic stops.
Definition config.hpp:145
Configuration common to all endgames (sampling and final-approximation tolerances).
Definition config.hpp:103
T final_tolerance
The tolerance to which to compute the endpoint using the endgame.
Definition config.hpp:113
unsigned num_sample_points
Number of sample points used per approximation.
Definition config.hpp:106
T min_track_time
Smallest time the endgame will track to (the neighborhood radius).
Definition config.hpp:107
mpq_rational sample_factor
Geometric factor between successive sample times (exact rational).
Definition config.hpp:109
Power-series-endgame configuration.
Definition config.hpp:134
unsigned max_cycle_number
Largest cycle number to consider.
Definition config.hpp:135
Security (divergence-bailout) configuration for an endgame.
Definition config.hpp:95
int level
Security level; >0 disables the max-norm divergence check.
Definition config.hpp:96
NumErrorT max_norm
A path diverges if its norm exceeds this during the endgame.
Definition config.hpp:97
Track-back endgame configuration.
Definition config.hpp:167
unsigned minimum_cycle
Minimum cycle number for track-back.
Definition config.hpp:168
bool junk_removal_test
Whether to run the junk-removal test.
Definition config.hpp:169
unsigned max_depth_LDT
Maximum depth of the local dimension test.
Definition config.hpp:170
double T
The number type used by this parser.
Definition endgames.hpp:49
mpq_rational R
Exact rational type (decimal-to-rational, no floating-point precision to go stale).
Definition endgames.hpp:140
double T
The number type used by this parser.
Definition endgames.hpp:139
double T
The number type used by this parser.
Definition endgames.hpp:422
double T
The number type used by this parser.
Definition endgames.hpp:335