23 using std::cout;
using std::endl;
25 #include "system_constants.hpp" 27 #include "cyclic_n.hpp" 28 #include "polynomial.hpp" 29 #include "strategies.hpp" 30 #include "monomial_ordering.hpp" 31 #include "particular_orderings.hpp" 32 #include "algorithm_buchberger_basic.hpp" 33 #include "f4_reduction.hpp" 34 #include "algorithm_buchberger_explorer_serial.hpp" 39 bool meaningful_arguments(
40 int argc,
char *argv[],
bool & homogeneous,
int & modulus,
int & numvars,
47 int main(
int argc,
char *argv[]) {
56 if (not meaningful_arguments(
57 argc, argv, homog, modulus, numvars, method, f4, xplor,
58 &mord, strategy, &grading
64 list<Abstract_Polynomial *> F =
cyclic_n(numvars, FF, homog, mord);
66 cout <<
"Computing a Groebner basis for:\n";
68 cout <<
'\t' << *f << endl;
71 list<Constant_Polynomial *> G;
79 cout << G.size() <<
" polynomials in basis:\n";
83 cout << G.size() <<
" leading monomials:\n";
85 cout << g->leading_monomial() <<
", ";
87 if (verbose) cout <<
'\t' << *g << endl;
93 if (mord != generic_grevlex_ptr)
98 enum order_flags { GENERIC_GREVLEX = 0, GREVLEX, LEX, WGREVLEX };
100 bool meaningful_arguments(
int argc,
char *argv[],
bool & homogeneous,
101 int & modulus,
int & numvars,
108 method = SPolyCreationFlags::LINKED_LST;
110 WT_TYPE * weights =
nullptr;
111 unsigned int order_flag = 0;
112 bool good_args = (argc > 1);
114 for (
int i = 1; good_args and i < argc; ++i) {
115 if (!strcmp(argv[i],
"hom") or !strcmp(argv[i],
"homog")
116 or !strcmp(argv[i],"homogeneous"))
118 else if (!strcmp(argv[i],"f4"))
120 else if (!strcmp(argv[i],"xplor"))
124 for (; argv[i][j] !=
'=' and argv[i][j] !=
'\0'; ++j) { }
125 if (argv[i][j] !=
'=') {
127 cout <<
"Arguments must have form <option>=<value>.\n";
131 if (!strcmp(argv[i],
"n") or !strcmp(argv[i],
"num")
132 or !strcmp(argv[i],
"numvars")) {
133 numvars = atoi(&(argv[i][j+1]));
136 cout <<
"Invalid number of variables: must be at least 3.\n";
139 else if (!strcmp(argv[i],
"m") or !strcmp(argv[i],
"mod")
140 or !strcmp(argv[i],
"modulus"))
142 modulus = atoi(&(argv[i][j+1]));
145 cout <<
"Invalid modulus; must be at least 2.\n";
148 else if (!strcmp(argv[i],
"r") or !strcmp(argv[i],
"repr")
149 or !strcmp(argv[i],
"representation"))
153 method <= SPolyCreationFlags::MIN_SPCREATE_FLAG or
154 method >= SPolyCreationFlags::MAX_SPCREATE_FLAG
157 cout <<
"Invalid method; must be at least 1 and at most 3.\n";
160 else if (!strcmp(argv[i],
"ord") or !strcmp(argv[i],
"order")
161 or !strcmp(argv[i],"ordering"))
163 char * request = &(argv[i][j+1]);
164 if (!strcmp(request,
"generic"))
165 order_flag = GENERIC_GREVLEX;
166 else if (!strcmp(request,
"grevlex"))
167 order_flag = GREVLEX;
168 else if (!strcmp(request,
"lex"))
170 else if (!strcmp(request,
"wgrevlex")) {
171 order_flag = WGREVLEX;
172 unsigned n = (homogeneous) ? numvars + 1 : numvars;
173 weights =
new WT_TYPE [n];
175 for (; k < i + n and k < argc; ++k)
176 weights[k - i] = atoi(argv[k]);
183 cout <<
"Ordering must be 'generic', 'grevlex', " 184 <<
"'lex', or 'wgrevlex'.\n" 185 <<
"(Matrix orderings not yet supported via command line.)\n" 186 <<
"When using 'wgrevlex', follow it with a list of 'n' " 187 <<
"positive integers.\n";
190 else if (!strcmp(argv[i],
"strat") or !strcmp(argv[i],
"strategy")) {
191 char * request = &(argv[i][j+1]);
192 if (!strcmp(request,
"normal") or !strcmp(request,
"norm"))
193 strategy = StrategyFlags::NORMAL_STRATEGY;
194 else if (!strcmp(request,
"sugar") or !strcmp(request,
"sug"))
195 strategy = StrategyFlags::SUGAR_STRATEGY;
196 else if (!strcmp(request,
"wsugar") or !strcmp(request,
"wsug")) {
197 strategy = StrategyFlags::WSUGAR_STRATEGY;
198 unsigned n = (homogeneous) ? numvars + 1 : numvars;
199 *grading =
new WT_TYPE [n];
201 for (; k < i + n and k < argc; ++k)
202 (*grading)[k - i] = atoi(argv[k]);
209 cout <<
"Strategy must be 'normal' or 'sugar'.";
213 cout <<
"Unrecognized argument.\n"; good_args =
false;
220 unsigned n = (homogeneous) ? numvars + 1 : numvars;
221 switch (order_flag) {
222 case GENERIC_GREVLEX: *mord = generic_grevlex_ptr;
break;
226 default: *mord = generic_grevlex_ptr;
233 cout <<
"Call with options n=<num> m=<mod> r=<repr>\n";
234 cout <<
"You *must* specify <num> vars, an integer greater than 2.\n";
235 cout <<
"You can add optional <mod>ulus (please make it prime).\n";
236 cout <<
"The option <hom>ogenize will give you a homogenized ideal.\n";
237 cout <<
"You can also select the <repr>esentation of s-polynomials:\n";
238 cout <<
"\t1) linked lists,\n";
239 cout <<
"\t2) geobuckets, or\n";
240 cout <<
"\t3) double-buffered polynomials.\n";
241 cout <<
"So 'test_cyclicn n=6 m=43 r=2' would compute the Groebner basis\n";
242 cout <<
"of the Cyclic-n ideal in 6 variables, modulo 43,";
243 cout <<
"using geobuckets.\n";
244 cout <<
"You can also specify the strategy ('normal', 'sugar', 'wsugar')\n";
245 cout <<
"('wsugar' requires a list of <num> integers, where <num> is as above,";
246 cout <<
"and the term ordering ('generic', 'grevlex', 'lex', 'wgrevlex').\n";
247 cout <<
"('wgrevlex' requires a list of <num> integers, where <num>";
248 cout <<
" is as above.\n";
249 cout <<
"The 'f4' option runs the F4 algorithm.\n";
The general class of a polynomial.
list< Constant_Polynomial * > buchberger_explorer(const vector< Abstract_Polynomial *> &F, SPolyCreationFlags method, StrategyFlags strategy, WT_TYPE *strategy_weights, const int comm_id, const int comm_size)
Alternate implementation of Buchberger’s algorithm, for parallelization.
A Constant_Polynomial is a polynomial that should not change.
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.
StrategyFlags
flag indicating which strategy to use for computation
SPolyCreationFlags
flag indicating which structure to use for an s-polynomial
interface to a monomial ordering
Encapsulates information about a polynomial ring for easy access: ground field, number of indetermina...
the lex ordering for a specified number of variables
the grevlex ordering for a specified number of variables
list< Constant_Polynomial * > f4_control(const list< Abstract_Polynomial *> &F)
equivalent to buchberger(), but for Faugère’s F4 algorithm
the weighted grevlex ordering for a specified number of variables, with cached weights for each monom...
list< Abstract_Polynomial * > cyclic_n(NVAR_TYPE n, Prime_Field &F, bool homog, Monomial_Ordering *mord=generic_grevlex_ptr)
generates the Cyclic- system