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