00001
00002 #include <basix/int.hpp>
00003 #include <basix/vector.hpp>
00004 #include <basix/port.hpp>
00005 #include <basix/literal.hpp>
00006 #include <numerix/integer.hpp>
00007 #include <numerix/modular.hpp>
00008 #include <numerix/modular_integer.hpp>
00009 #include <algebramix/vector_unrolled.hpp>
00010 #include <algebramix/vector_simd.hpp>
00011 #include <algebramix/vector_modular.hpp>
00012 #include <basix/compound.hpp>
00013 #include <basix/mmx_syntax.hpp>
00014 #include <basix/lisp_syntax.hpp>
00015 #include <basix/cpp_syntax.hpp>
00016 #include <basix/syntactic.hpp>
00017 #include <algebramix/polynomial.hpp>
00018 #include <algebramix/polynomial_polynomial.hpp>
00019 #include <algebramix/polynomial_integer.hpp>
00020 #include <algebramix/polynomial_modular.hpp>
00021 #include <algebramix/polynomial_modular_integer.hpp>
00022 #include <algebramix/polynomial_schonhage.hpp>
00023 #include <basix/tuple.hpp>
00024 #include <basix/glue.hpp>
00025
00026 #define int_literal(x) as_int (as_string (x))
00027 #define is_generic_literal is<literal>
00028 #define gen_literal_apply(f,v) gen (as<generic> (f), v)
00029 #define gen_literal_access(f,v) access (as<generic> (f), v)
00030 #define is_generic_compound is<compound>
00031 #define compound_arguments(x) cdr (as_vector (x))
00032 #define gen_compound_apply(f,v) gen (as<generic> (f), v)
00033 namespace mmx {
00034 template<typename C> polynomial<C>
00035 polynomial_reverse (const vector<C>& v) {
00036 return polynomial<C> (reverse (v)); }
00037
00038 template<typename C> polynomial<modular<modulus<C>, modular_local> >
00039 as_polynomial_modular (const polynomial<C>& f, const modulus<C>& p) {
00040 modular<modulus<C>, modular_local>::set_modulus (p);
00041 return as<polynomial<modular<modulus<C>, modular_local> > > (f); }
00042
00043 template<typename C> vector<generic>
00044 wrap_subresultants (const polynomial<C>& f, const polynomial<C>& g) {
00045 return as<vector<generic> > (subresultants (f, g)); }
00046
00047 }
00048 namespace mmx { POLYNOMIAL_GENERIC_USES_SCHONHAGE }
00049
00050 namespace mmx {
00051 static polynomial<mmx_modular(integer) >
00052 GLUE_1 (const tuple<mmx_modular(integer) > &arg_1) {
00053 return polynomial_reverse (as_vector (arg_1));
00054 }
00055
00056 static polynomial<mmx_modular(integer) >
00057 GLUE_2 (const tuple<mmx_modular(integer) > &arg_1) {
00058 return polynomial<mmx_modular(integer) > (as_vector (arg_1));
00059 }
00060
00061 static void
00062 GLUE_3 (const polynomial<mmx_modular(integer) > &arg_1, const generic &arg_2) {
00063 set_variable_name (arg_1, arg_2);
00064 }
00065
00066 static polynomial<mmx_modular(integer) >
00067 GLUE_4 (const mmx_modular(integer) &arg_1) {
00068 return polynomial<mmx_modular(integer) > (arg_1);
00069 }
00070
00071 static iterator<generic>
00072 GLUE_5 (const polynomial<mmx_modular(integer) > &arg_1) {
00073 return as<iterator<generic> > (iterate (arg_1));
00074 }
00075
00076 static int
00077 GLUE_6 (const polynomial<mmx_modular(integer) > &arg_1) {
00078 return N (arg_1);
00079 }
00080
00081 static int
00082 GLUE_7 (const polynomial<mmx_modular(integer) > &arg_1) {
00083 return deg (arg_1);
00084 }
00085
00086 static mmx_modular(integer)
00087 GLUE_8 (const polynomial<mmx_modular(integer) > &arg_1, const int &arg_2) {
00088 return arg_1[arg_2];
00089 }
00090
00091 static polynomial<mmx_modular(integer) >
00092 GLUE_9 (const polynomial<mmx_modular(integer) > &arg_1) {
00093 return -arg_1;
00094 }
00095
00096 static polynomial<mmx_modular(integer) >
00097 GLUE_10 (const polynomial<mmx_modular(integer) > &arg_1) {
00098 return square (arg_1);
00099 }
00100
00101 static polynomial<mmx_modular(integer) >
00102 GLUE_11 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00103 return arg_1 + arg_2;
00104 }
00105
00106 static polynomial<mmx_modular(integer) >
00107 GLUE_12 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00108 return arg_1 - arg_2;
00109 }
00110
00111 static polynomial<mmx_modular(integer) >
00112 GLUE_13 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00113 return arg_1 * arg_2;
00114 }
00115
00116 static polynomial<mmx_modular(integer) >
00117 GLUE_14 (const mmx_modular(integer) &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00118 return arg_1 + arg_2;
00119 }
00120
00121 static polynomial<mmx_modular(integer) >
00122 GLUE_15 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00123 return arg_1 + arg_2;
00124 }
00125
00126 static polynomial<mmx_modular(integer) >
00127 GLUE_16 (const mmx_modular(integer) &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00128 return arg_1 - arg_2;
00129 }
00130
00131 static polynomial<mmx_modular(integer) >
00132 GLUE_17 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00133 return arg_1 - arg_2;
00134 }
00135
00136 static polynomial<mmx_modular(integer) >
00137 GLUE_18 (const mmx_modular(integer) &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00138 return arg_1 * arg_2;
00139 }
00140
00141 static polynomial<mmx_modular(integer) >
00142 GLUE_19 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00143 return arg_1 * arg_2;
00144 }
00145
00146 static polynomial<mmx_modular(integer) >
00147 GLUE_20 (const polynomial<mmx_modular(integer) > &arg_1, const int &arg_2) {
00148 return binpow (arg_1, arg_2);
00149 }
00150
00151 static polynomial<mmx_modular(integer) >
00152 GLUE_21 (const polynomial<mmx_modular(integer) > &arg_1, const int &arg_2) {
00153 return lshiftz (arg_1, arg_2);
00154 }
00155
00156 static polynomial<mmx_modular(integer) >
00157 GLUE_22 (const polynomial<mmx_modular(integer) > &arg_1, const int &arg_2) {
00158 return rshiftz (arg_1, arg_2);
00159 }
00160
00161 static bool
00162 GLUE_23 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00163 return arg_1 == arg_2;
00164 }
00165
00166 static bool
00167 GLUE_24 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00168 return arg_1 != arg_2;
00169 }
00170
00171 static bool
00172 GLUE_25 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00173 return arg_1 == arg_2;
00174 }
00175
00176 static bool
00177 GLUE_26 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00178 return arg_1 != arg_2;
00179 }
00180
00181 static bool
00182 GLUE_27 (const mmx_modular(integer) &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00183 return arg_1 == arg_2;
00184 }
00185
00186 static bool
00187 GLUE_28 (const mmx_modular(integer) &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00188 return arg_1 != arg_2;
00189 }
00190
00191 static polynomial<mmx_modular(integer) >
00192 GLUE_29 (const polynomial<mmx_modular(integer) > &arg_1) {
00193 return derive (arg_1);
00194 }
00195
00196 static polynomial<mmx_modular(integer) >
00197 GLUE_30 (const polynomial<mmx_modular(integer) > &arg_1) {
00198 return xderive (arg_1);
00199 }
00200
00201 static mmx_modular(integer)
00202 GLUE_31 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00203 return evaluate (arg_1, arg_2);
00204 }
00205
00206 static vector<mmx_modular(integer) >
00207 GLUE_32 (const polynomial<mmx_modular(integer) > &arg_1, const vector<mmx_modular(integer) > &arg_2) {
00208 return evaluate (arg_1, arg_2);
00209 }
00210
00211 static mmx_modular(integer)
00212 GLUE_33 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00213 return evaluate (arg_1, arg_2);
00214 }
00215
00216 static vector<mmx_modular(integer) >
00217 GLUE_34 (const polynomial<mmx_modular(integer) > &arg_1, const vector<mmx_modular(integer) > &arg_2) {
00218 return evaluate (arg_1, arg_2);
00219 }
00220
00221 static polynomial<mmx_modular(integer) >
00222 GLUE_35 (const polynomial<integer> &arg_1, const modulus<integer> &arg_2) {
00223 return as_polynomial_modular (arg_1, arg_2);
00224 }
00225
00226 static polynomial<mmx_modular(integer) >
00227 GLUE_36 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00228 return arg_1 / arg_2;
00229 }
00230
00231 static polynomial<mmx_modular(integer) >
00232 GLUE_37 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00233 return arg_1 / arg_2;
00234 }
00235
00236 static polynomial<mmx_modular(integer) >
00237 GLUE_38 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00238 return quo (arg_1, arg_2);
00239 }
00240
00241 static polynomial<mmx_modular(integer) >
00242 GLUE_39 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00243 return rem (arg_1, arg_2);
00244 }
00245
00246 static bool
00247 GLUE_40 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00248 return divides (arg_1, arg_2);
00249 }
00250
00251 static polynomial<mmx_modular(integer) >
00252 GLUE_41 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2, const int &arg_3) {
00253 return subresultant (arg_1, arg_2, arg_3);
00254 }
00255
00256 static vector<generic>
00257 GLUE_42 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00258 return wrap_subresultants (arg_1, arg_2);
00259 }
00260
00261 static mmx_modular(integer)
00262 GLUE_43 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00263 return resultant (arg_1, arg_2);
00264 }
00265
00266 static mmx_modular(integer)
00267 GLUE_44 (const polynomial<mmx_modular(integer) > &arg_1) {
00268 return discriminant (arg_1);
00269 }
00270
00271 static polynomial<mmx_modular(integer) >
00272 GLUE_45 (const polynomial<mmx_modular(integer) > &arg_1) {
00273 return integrate (arg_1);
00274 }
00275
00276 static polynomial<mmx_modular(integer) >
00277 GLUE_46 (const polynomial<mmx_modular(integer) > &arg_1, const polynomial<mmx_modular(integer) > &arg_2) {
00278 return compose (arg_1, arg_2);
00279 }
00280
00281 static polynomial<mmx_modular(integer) >
00282 GLUE_47 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00283 return q_difference (arg_1, arg_2);
00284 }
00285
00286 static polynomial<mmx_modular(integer) >
00287 GLUE_48 (const polynomial<mmx_modular(integer) > &arg_1, const int &arg_2) {
00288 return dilate (arg_1, arg_2);
00289 }
00290
00291 static polynomial<mmx_modular(integer) >
00292 GLUE_49 (const vector<mmx_modular(integer) > &arg_1) {
00293 return annulator (arg_1);
00294 }
00295
00296 static polynomial<mmx_modular(integer) >
00297 GLUE_50 (const vector<mmx_modular(integer) > &arg_1, const vector<mmx_modular(integer) > &arg_2) {
00298 return interpolate (arg_1, arg_2);
00299 }
00300
00301 static polynomial<mmx_modular(integer) >
00302 GLUE_51 (const polynomial<mmx_modular(integer) > &arg_1, const mmx_modular(integer) &arg_2) {
00303 return shift (arg_1, arg_2);
00304 }
00305
00306 static polynomial<mmx_modular(integer) >
00307 GLUE_52 (const polynomial<mmx_modular(integer) > &arg_1) {
00308 return graeffe (arg_1);
00309 }
00310
00311 static polynomial<generic>
00312 GLUE_53 (const polynomial<mmx_modular(integer) > &arg_1) {
00313 return as<polynomial<generic> > (arg_1);
00314 }
00315
00316 void
00317 glue_polynomial_modular_integer () {
00318 static bool done = false;
00319 if (done) return;
00320 done = true;
00321 call_glue (string ("glue_basix_vector_generic"));
00322 call_glue (string ("glue_vector_modular_integer"));
00323 call_glue (string ("glue_polynomial_integer"));
00324 define_type<polynomial<mmx_modular(integer) > > (gen (lit ("Polynomial"), gen (lit ("Modular"), lit ("Integer"))));
00325 define ("poly", GLUE_1);
00326 define ("polynomial", GLUE_2);
00327 define ("set_variable_name", GLUE_3);
00328 define_converter ("upgrade", GLUE_4, PENALTY_INCLUSION);
00329 define_converter (":>", GLUE_5, PENALTY_CAST);
00330 define ("#", GLUE_6);
00331 define ("deg", GLUE_7);
00332 define (".[]", GLUE_8);
00333 define ("-", GLUE_9);
00334 define ("square", GLUE_10);
00335 define ("+", GLUE_11);
00336 define ("-", GLUE_12);
00337 define ("*", GLUE_13);
00338 define ("+", GLUE_14);
00339 define ("+", GLUE_15);
00340 define ("-", GLUE_16);
00341 define ("-", GLUE_17);
00342 define ("*", GLUE_18);
00343 define ("*", GLUE_19);
00344 define ("^", GLUE_20);
00345 define ("<<", GLUE_21);
00346 define (">>", GLUE_22);
00347 define ("=", GLUE_23);
00348 define ("!=", GLUE_24);
00349 define ("=", GLUE_25);
00350 define ("!=", GLUE_26);
00351 define ("=", GLUE_27);
00352 define ("!=", GLUE_28);
00353 define ("derive", GLUE_29);
00354 define ("xderive", GLUE_30);
00355 define ("eval", GLUE_31);
00356 define ("eval", GLUE_32);
00357 define ("evaluate", GLUE_33);
00358 define ("evaluate", GLUE_34);
00359 define ("mod", GLUE_35);
00360 define ("/", GLUE_36);
00361 define ("div", GLUE_37);
00362 define ("quo", GLUE_38);
00363 define ("rem", GLUE_39);
00364 define ("divides?", GLUE_40);
00365 define ("subresultant", GLUE_41);
00366 define ("subresultants", GLUE_42);
00367 define ("resultant", GLUE_43);
00368 define ("discriminant", GLUE_44);
00369 define ("integrate", GLUE_45);
00370 define ("@", GLUE_46);
00371 define ("q_difference", GLUE_47);
00372 define ("dilate", GLUE_48);
00373 define ("annulator", GLUE_49);
00374 define ("interpolate", GLUE_50);
00375 define ("shift", GLUE_51);
00376 define ("graeffe", GLUE_52);
00377 define_converter (":>", GLUE_53, PENALTY_PROMOTE_GENERIC);
00378 }
00379 }