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