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 <basix/glue.hpp>
00008
00009 #define int_literal(x) as_int (as_string (x))
00010 #define is_generic_literal is<literal>
00011 #define gen_literal_apply(f,v) gen (as<generic> (f), v)
00012 #define gen_literal_access(f,v) access (as<generic> (f), v)
00013
00014 namespace mmx {
00015 static integer
00016 GLUE_1 (const literal &arg_1) {
00017 return make_literal_integer (arg_1);
00018 }
00019
00020 static integer
00021 GLUE_2 (const int &arg_1) {
00022 return integer (arg_1);
00023 }
00024
00025 static integer
00026 GLUE_3 (const int &arg_1) {
00027 return integer (arg_1);
00028 }
00029
00030 static bool
00031 GLUE_4 (const integer &arg_1) {
00032 return is_int (arg_1);
00033 }
00034
00035 static int
00036 GLUE_5 (const integer &arg_1) {
00037 return as_int (arg_1);
00038 }
00039
00040 static integer
00041 GLUE_6 (const string &arg_1) {
00042 return integer (arg_1);
00043 }
00044
00045 static string
00046 GLUE_7 (const integer &arg_1) {
00047 return as_string (arg_1);
00048 }
00049
00050 static generic
00051 GLUE_8 (const int &arg_1) {
00052 return integer_construct (arg_1);
00053 }
00054
00055 static int
00056 GLUE_9 (const integer &arg_1) {
00057 return as_int (arg_1);
00058 }
00059
00060 static integer
00061 GLUE_10 (const integer &arg_1) {
00062 return -arg_1;
00063 }
00064
00065 static integer
00066 GLUE_11 (const integer &arg_1) {
00067 return square (arg_1);
00068 }
00069
00070 static integer
00071 GLUE_12 (const integer &arg_1, const integer &arg_2) {
00072 return arg_1 + arg_2;
00073 }
00074
00075 static integer
00076 GLUE_13 (const integer &arg_1, const integer &arg_2) {
00077 return arg_1 - arg_2;
00078 }
00079
00080 static integer
00081 GLUE_14 (const integer &arg_1, const integer &arg_2) {
00082 return arg_1 * arg_2;
00083 }
00084
00085 static integer
00086 GLUE_15 (const integer &arg_1, const integer &arg_2) {
00087 return arg_1 / arg_2;
00088 }
00089
00090 static integer
00091 GLUE_16 (const integer &arg_1, const integer &arg_2) {
00092 return quo (arg_1, arg_2);
00093 }
00094
00095 static integer
00096 GLUE_17 (const integer &arg_1, const integer &arg_2) {
00097 return rem (arg_1, arg_2);
00098 }
00099
00100 static bool
00101 GLUE_18 (const integer &arg_1, const integer &arg_2) {
00102 return divides (arg_1, arg_2);
00103 }
00104
00105 static integer
00106 GLUE_19 (const integer &arg_1, const integer &arg_2) {
00107 return gcd (arg_1, arg_2);
00108 }
00109
00110 static integer
00111 GLUE_20 (const integer &arg_1, const integer &arg_2) {
00112 return lcm (arg_1, arg_2);
00113 }
00114
00115 static integer
00116 GLUE_21 (const integer &arg_1, const integer &arg_2) {
00117 return invert_modulo (arg_1, arg_2);
00118 }
00119
00120 static bool
00121 GLUE_22 (const integer &arg_1, const integer &arg_2) {
00122 return arg_1 == arg_2;
00123 }
00124
00125 static bool
00126 GLUE_23 (const integer &arg_1, const integer &arg_2) {
00127 return arg_1 != arg_2;
00128 }
00129
00130 static bool
00131 GLUE_24 (const integer &arg_1, const integer &arg_2) {
00132 return arg_1 < arg_2;
00133 }
00134
00135 static bool
00136 GLUE_25 (const integer &arg_1, const integer &arg_2) {
00137 return arg_1 <= arg_2;
00138 }
00139
00140 static bool
00141 GLUE_26 (const integer &arg_1, const integer &arg_2) {
00142 return arg_1 > arg_2;
00143 }
00144
00145 static bool
00146 GLUE_27 (const integer &arg_1, const integer &arg_2) {
00147 return arg_1 >= arg_2;
00148 }
00149
00150 static int
00151 GLUE_28 (const integer &arg_1) {
00152 return sign (arg_1);
00153 }
00154
00155 static integer
00156 GLUE_29 (const integer &arg_1) {
00157 return abs (arg_1);
00158 }
00159
00160 static integer
00161 GLUE_30 (const integer &arg_1, const integer &arg_2) {
00162 return min (arg_1, arg_2);
00163 }
00164
00165 static integer
00166 GLUE_31 (const integer &arg_1, const integer &arg_2) {
00167 return max (arg_1, arg_2);
00168 }
00169
00170 static integer
00171 GLUE_32 (const integer &arg_1, const integer &arg_2) {
00172 return min (arg_1, arg_2);
00173 }
00174
00175 static integer
00176 GLUE_33 (const integer &arg_1, const integer &arg_2) {
00177 return max (arg_1, arg_2);
00178 }
00179
00180 static integer
00181 GLUE_34 (const integer &arg_1) {
00182 return factorial (arg_1);
00183 }
00184
00185 static integer
00186 GLUE_35 (const integer &arg_1, const integer &arg_2) {
00187 return binomial (arg_1, arg_2);
00188 }
00189
00190 static bool
00191 GLUE_36 (const integer &arg_1) {
00192 return is_probable_prime (arg_1);
00193 }
00194
00195 static integer
00196 GLUE_37 (const integer &arg_1) {
00197 return probable_next_prime (arg_1);
00198 }
00199
00200 static integer
00201 GLUE_38 (const integer &arg_1, const integer &arg_2) {
00202 return arg_1 & arg_2;
00203 }
00204
00205 static integer
00206 GLUE_39 (const integer &arg_1, const integer &arg_2) {
00207 return arg_1 | arg_2;
00208 }
00209
00210 static integer
00211 GLUE_40 (const integer &arg_1, const integer &arg_2) {
00212 return arg_1 ^ arg_2;
00213 }
00214
00215 static integer
00216 GLUE_41 (const integer &arg_1) {
00217 return ~arg_1;
00218 }
00219
00220 static int
00221 GLUE_42 (const integer &arg_1) {
00222 return bit_size (arg_1);
00223 }
00224
00225 static bool
00226 GLUE_43 (const integer &arg_1, const int &arg_2) {
00227 return arg_1[arg_2];
00228 }
00229
00230 static int
00231 GLUE_44 (const integer &arg_1) {
00232 return hamming_norm (arg_1);
00233 }
00234
00235 static int
00236 GLUE_45 (const integer &arg_1, const integer &arg_2) {
00237 return hamming_distance (arg_1, arg_2);
00238 }
00239
00240 static integer
00241 GLUE_46 (const integer &arg_1, const int &arg_2) {
00242 return arg_1 + arg_2;
00243 }
00244
00245 static integer
00246 GLUE_47 (const integer &arg_1, const int &arg_2) {
00247 return arg_1 - arg_2;
00248 }
00249
00250 static integer
00251 GLUE_48 (const integer &arg_1, const int &arg_2) {
00252 return arg_1 * arg_2;
00253 }
00254
00255 static integer
00256 GLUE_49 (const int &arg_1, const integer &arg_2) {
00257 return arg_1 + arg_2;
00258 }
00259
00260 static integer
00261 GLUE_50 (const int &arg_1, const integer &arg_2) {
00262 return arg_1 - arg_2;
00263 }
00264
00265 static integer
00266 GLUE_51 (const int &arg_1, const integer &arg_2) {
00267 return arg_1 * arg_2;
00268 }
00269
00270 static integer
00271 GLUE_52 (const integer &arg_1, const int &arg_2) {
00272 return arg_1 / arg_2;
00273 }
00274
00275 static integer
00276 GLUE_53 (const integer &arg_1, const int &arg_2) {
00277 return quo (arg_1, arg_2);
00278 }
00279
00280 static integer
00281 GLUE_54 (const integer &arg_1, const int &arg_2) {
00282 return rem (arg_1, arg_2);
00283 }
00284
00285 static bool
00286 GLUE_55 (const integer &arg_1, const int &arg_2) {
00287 return divides (arg_1, arg_2);
00288 }
00289
00290 static integer
00291 GLUE_56 (const int &arg_1, const integer &arg_2) {
00292 return arg_1 / arg_2;
00293 }
00294
00295 static integer
00296 GLUE_57 (const int &arg_1, const integer &arg_2) {
00297 return quo (arg_1, arg_2);
00298 }
00299
00300 static integer
00301 GLUE_58 (const int &arg_1, const integer &arg_2) {
00302 return rem (arg_1, arg_2);
00303 }
00304
00305 static bool
00306 GLUE_59 (const int &arg_1, const integer &arg_2) {
00307 return divides (arg_1, arg_2);
00308 }
00309
00310 static bool
00311 GLUE_60 (const integer &arg_1, const int &arg_2) {
00312 return arg_1 == arg_2;
00313 }
00314
00315 static bool
00316 GLUE_61 (const integer &arg_1, const int &arg_2) {
00317 return arg_1 != arg_2;
00318 }
00319
00320 static bool
00321 GLUE_62 (const integer &arg_1, const int &arg_2) {
00322 return arg_1 < arg_2;
00323 }
00324
00325 static bool
00326 GLUE_63 (const integer &arg_1, const int &arg_2) {
00327 return arg_1 <= arg_2;
00328 }
00329
00330 static bool
00331 GLUE_64 (const integer &arg_1, const int &arg_2) {
00332 return arg_1 > arg_2;
00333 }
00334
00335 static bool
00336 GLUE_65 (const integer &arg_1, const int &arg_2) {
00337 return arg_1 >= arg_2;
00338 }
00339
00340 static bool
00341 GLUE_66 (const int &arg_1, const integer &arg_2) {
00342 return arg_1 == arg_2;
00343 }
00344
00345 static bool
00346 GLUE_67 (const int &arg_1, const integer &arg_2) {
00347 return arg_1 != arg_2;
00348 }
00349
00350 static bool
00351 GLUE_68 (const int &arg_1, const integer &arg_2) {
00352 return arg_1 < arg_2;
00353 }
00354
00355 static bool
00356 GLUE_69 (const int &arg_1, const integer &arg_2) {
00357 return arg_1 <= arg_2;
00358 }
00359
00360 static bool
00361 GLUE_70 (const int &arg_1, const integer &arg_2) {
00362 return arg_1 > arg_2;
00363 }
00364
00365 static bool
00366 GLUE_71 (const int &arg_1, const integer &arg_2) {
00367 return arg_1 >= arg_2;
00368 }
00369
00370 static integer
00371 GLUE_72 (const integer &arg_1, const int &arg_2) {
00372 return min (arg_1, arg_2);
00373 }
00374
00375 static integer
00376 GLUE_73 (const integer &arg_1, const int &arg_2) {
00377 return max (arg_1, arg_2);
00378 }
00379
00380 static integer
00381 GLUE_74 (const int &arg_1, const integer &arg_2) {
00382 return min (arg_1, arg_2);
00383 }
00384
00385 static integer
00386 GLUE_75 (const int &arg_1, const integer &arg_2) {
00387 return max (arg_1, arg_2);
00388 }
00389
00390 static integer
00391 GLUE_76 (const integer &arg_1, const int &arg_2) {
00392 return arg_1 & arg_2;
00393 }
00394
00395 static integer
00396 GLUE_77 (const integer &arg_1, const int &arg_2) {
00397 return arg_1 | arg_2;
00398 }
00399
00400 static integer
00401 GLUE_78 (const integer &arg_1, const int &arg_2) {
00402 return arg_1 ^ arg_2;
00403 }
00404
00405 static integer
00406 GLUE_79 (const int &arg_1, const integer &arg_2) {
00407 return arg_1 & arg_2;
00408 }
00409
00410 static integer
00411 GLUE_80 (const int &arg_1, const integer &arg_2) {
00412 return arg_1 | arg_2;
00413 }
00414
00415 static integer
00416 GLUE_81 (const int &arg_1, const integer &arg_2) {
00417 return arg_1 ^ arg_2;
00418 }
00419
00420 void
00421 glue_integer () {
00422 static bool done = false;
00423 if (done) return;
00424 done = true;
00425 call_glue (string ("glue_int"));
00426 call_glue (string ("glue_literal"));
00427 call_glue (string ("glue_string"));
00428 define_type<integer > (lit ("Integer"));
00429 define ("literal_integer", GLUE_1);
00430 define ("integer", GLUE_2);
00431 define_converter ("upgrade", GLUE_3, PENALTY_INCLUSION);
00432 define ("int?", GLUE_4);
00433 define ("as_int", GLUE_5);
00434 define ("as_integer", GLUE_6);
00435 define ("as_string", GLUE_7);
00436 define_constructor<int > (GLUE_8);
00437 define_converter (":>", GLUE_9, PENALTY_INCLUSION);
00438 define ("-", GLUE_10);
00439 define ("square", GLUE_11);
00440 define ("+", GLUE_12);
00441 define ("-", GLUE_13);
00442 define ("*", GLUE_14);
00443 define ("div", GLUE_15);
00444 define ("quo", GLUE_16);
00445 define ("rem", GLUE_17);
00446 define ("divides?", GLUE_18);
00447 define ("gcd", GLUE_19);
00448 define ("lcm", GLUE_20);
00449 define ("invert_modulo", GLUE_21);
00450 define ("=", GLUE_22);
00451 define ("!=", GLUE_23);
00452 define ("<", GLUE_24);
00453 define ("<=", GLUE_25);
00454 define (">", GLUE_26);
00455 define (">=", GLUE_27);
00456 define ("sign", GLUE_28);
00457 define ("abs", GLUE_29);
00458 define ("min", GLUE_30);
00459 define ("max", GLUE_31);
00460 define ("inf", GLUE_32);
00461 define ("sup", GLUE_33);
00462 define (".!", GLUE_34);
00463 define ("binomial", GLUE_35);
00464 define ("probable_prime?", GLUE_36);
00465 define ("probable_next_prime", GLUE_37);
00466 define ("/\\", GLUE_38);
00467 define ("\\/", GLUE_39);
00468 define ("xor", GLUE_40);
00469 define ("!", GLUE_41);
00470 define ("#", GLUE_42);
00471 define (".[]", GLUE_43);
00472 define ("hamming_norm", GLUE_44);
00473 define ("hamming_distance", GLUE_45);
00474 define ("+", GLUE_46);
00475 define ("-", GLUE_47);
00476 define ("*", GLUE_48);
00477 define ("+", GLUE_49);
00478 define ("-", GLUE_50);
00479 define ("*", GLUE_51);
00480 define ("div", GLUE_52);
00481 define ("quo", GLUE_53);
00482 define ("rem", GLUE_54);
00483 define ("divides?", GLUE_55);
00484 define ("div", GLUE_56);
00485 define ("quo", GLUE_57);
00486 define ("rem", GLUE_58);
00487 define ("divides?", GLUE_59);
00488 define ("=", GLUE_60);
00489 define ("!=", GLUE_61);
00490 define ("<", GLUE_62);
00491 define ("<=", GLUE_63);
00492 define (">", GLUE_64);
00493 define (">=", GLUE_65);
00494 define ("=", GLUE_66);
00495 define ("!=", GLUE_67);
00496 define ("<", GLUE_68);
00497 define ("<=", GLUE_69);
00498 define (">", GLUE_70);
00499 define (">=", GLUE_71);
00500 define ("min", GLUE_72);
00501 define ("max", GLUE_73);
00502 define ("min", GLUE_74);
00503 define ("max", GLUE_75);
00504 define ("/\\", GLUE_76);
00505 define ("\\/", GLUE_77);
00506 define ("xor", GLUE_78);
00507 define ("/\\", GLUE_79);
00508 define ("\\/", GLUE_80);
00509 define ("xor", GLUE_81);
00510 }
00511 }