24 using std::cin;
using std::cout;
using std::endl;
26 #include "system_constants.hpp" 28 #include "monomial.hpp" 29 #include "dynamic_engine.hpp" 30 #include "polynomial_array.hpp" 32 #include "algorithm_buchberger_dynamic.hpp" 60 cout <<
"prime number for base field: ";
63 cout <<
"number of indeterminates: ";
66 cout <<
"do you want to specify the indeterminates' names? (y/n) ";
68 string * names =
new string[n];
71 if (not specify_names) {
73 cout <<
"indeterminate names are: ";
74 for (NVAR_TYPE i = 0; i < n; ++i) {
76 names[i] = P->
name(i);
79 for (NVAR_TYPE i = 0; i < n; ++i)
84 cout <<
"number of polynomials: ";
87 list<Abstract_Polynomial *> I;
88 for (
unsigned np = 0; np < m; ++np) {
89 cout <<
"please enter polynomial #" << np <<
": (use spaces to separate factors) ";
93 list<Prime_Field_Element> A;
96 while (i < inpoly.size()) {
97 bool reading_term =
true;
100 for (NVAR_TYPE i = 0; i < n; ++i) exp[i] = 0;
101 bool positive =
true;
102 while (inpoly[i] ==
' ') ++i;
103 while (reading_term and i < inpoly.size()) {
106 inpoly[i] ==
'+' or inpoly[i] ==
'-' or
107 (inpoly[i] >=
'0' and inpoly[i] <=
'9')
109 bool positive =
true;
110 if (inpoly[i] ==
'-') positive =
false;
111 if (inpoly[i] ==
'+' or inpoly[i] ==
'-') ++i;
112 while (inpoly[i] ==
' ') ++i;
113 if (inpoly[i] >=
'0' and inpoly[i] <=
'9') {
115 while (inpoly[j] >=
'0' and inpoly[j] <=
'9') ++j;
116 a *= stol(inpoly.substr(i, j - i));
117 if (not positive) a *= -1;
121 else if (inpoly[i] ==
'*')
123 else if (inpoly[i] ==
'\0')
127 while ((inpoly[j] >=
'a' and inpoly[j] <=
'z') or
128 (inpoly[j] >=
'A' and inpoly[j] <=
'Z') or
129 (inpoly[j] >=
'0' and inpoly[j] <=
'9'))
131 string var_name = inpoly.substr(i, j - i);
134 for (; not found and k < n; ++k)
135 if (var_name.compare(names[k]) == 0) {
140 while (inpoly[i] ==
' ') ++i;
141 if (inpoly[i] !=
'^')
145 while (inpoly[i] ==
' ') ++i;
147 while (inpoly[j] >=
'0' and inpoly[j] <=
'9') ++j;
148 exp[k] += stol(inpoly.substr(i, j - i));
152 while (inpoly[i] ==
' ') ++i;
153 if (inpoly[i] ==
'+' or inpoly[i] ==
'-') reading_term =
false;
156 if (not positive) a *= -1;
159 A.emplace_back(a, &F);
163 cout <<
"read " << *p << endl;
168 computation.compare(
"s") and computation.compare(
"d")
169 and computation.compare(
"static") and computation.compare(
"dynamic")
171 cout <<
"static (s) or dynamic (d) computation? ";
172 getline(cin, computation);
174 list<Constant_Polynomial *> B;
175 bool dynamic = not (computation.compare(
"d") and computation.compare(
"dynamic"));
180 string solver_choice;
182 solver_choice.compare(
"skel") and solver_choice.compare(
"glpk")
183 and solver_choice.compare(
"ppl") and solver_choice.compare(
"skeleton")
185 cout <<
"which solver? ([skel]eton, glpk, ppl) ";
186 getline(cin, solver_choice);
188 if (not solver_choice.compare(
"skel") or not solver_choice.compare(
"skeleton"))
189 solver = SKELETON_SOLVER;
190 else if (not solver_choice.compare(
"glpk"))
191 solver = GLPK_SOLVER;
192 else if (not solver_choice.compare(
"ppl"))
197 heur_choice.compare(
"h") and heur_choice.compare(
"gh")
198 and heur_choice.compare(
"b") and heur_choice.compare(
"bb")
199 and heur_choice.compare(
"gb") and heur_choice.compare(
"c")
200 and heur_choice.compare(
"d")
202 cout <<
"available heuristics are\n";
203 cout <<
"\t h = hilbert with standard grading\n";
204 cout <<
"\tgh = hilbert with order-based grading\n";
205 cout <<
"\t b = betti with standard grading\n";
206 cout <<
"\tbb = \"big\" betti with standard grading\n";
207 cout <<
"\tgb = betti with order-based grading\n";
208 cout <<
"\t c = minimal number of critical pairs\n";
209 cout <<
"\t d = minimal degree, ties broken by hilbert\n";
210 cout <<
"which heuristic would you like? ";
211 getline(cin, heur_choice);
213 if (not heur_choice.compare(
"h")) heuristic = DynamicHeuristic::ORD_HILBERT_THEN_DEG;
214 else if (not heur_choice.compare(
"gh")) heuristic = DynamicHeuristic::GRAD_HILB_THEN_DEG;
215 else if (not heur_choice.compare(
"b")) heuristic = DynamicHeuristic::BETTI_HILBERT_DEG;
216 else if (not heur_choice.compare(
"bb")) heuristic = DynamicHeuristic::BIG_BETTI_HILBERT_DEG;
217 else if (not heur_choice.compare(
"gb")) heuristic = DynamicHeuristic::GRAD_BETTI_HILBERT_DEG;
218 else if (not heur_choice.compare(
"c")) heuristic = DynamicHeuristic::MIN_CRIT_PAIRS;
219 else if (not heur_choice.compare(
"d")) heuristic = DynamicHeuristic::DEG_THEN_ORD_HILBERT;
220 string whether_analysis;
221 bool analyze_first =
false;
222 while (whether_analysis.compare(
"y") and whether_analysis.compare(
"n")) {
223 cout <<
"perform global analysis at the outset? (y or n) ";
224 cin >> whether_analysis;
226 if (not whether_analysis.compare(
"y")) analyze_first =
true;
228 I, SPolyCreationFlags::GEOBUCKETS, StrategyFlags::SUGAR_STRATEGY,
229 nullptr, heuristic, solver, analyze_first
232 cout <<
"have basis with " << B.size() <<
" elements:\n";
234 cout << b->leading_monomial() <<
", ";
238 for (
auto p : I)
delete p;
The general class of a polynomial.
A Constant_Polynomial is a polynomial that should not change.
virtual void sort_by_order()=0
sort according to the leading monomial’s ordering
list< Constant_Polynomial * > buchberger(const list< Abstract_Polynomial *> &F, SPolyCreationFlags method, StrategyFlags strategy, WT_TYPE *strategy_weights)
Implementation of Buchberger’s algorithm.
Information necessary for a field modulo a prime.
virtual const string name(NVAR_TYPE i) const
name of the th indeterminate
Implementation of monomials.
Encapsulates information about a polynomial ring for easy access: ground field, number of indetermina...
DynamicSolver
used by buchberger_dynamic() to decide which solver to use
list< Constant_Polynomial * > buchberger_dynamic(const list< Abstract_Polynomial *> &F, SPolyCreationFlags method, StrategyFlags strategy, WT_TYPE *strategy_weights, DynamicHeuristic heuristic, DynamicSolver solver_type, bool analyze_inputs)
implementation of the dynamic Buchberger algorithm
void user_interface()
reads ideal definition from cin, then reads options for computation, writes Gröbner basis to cout ...