00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #ifndef _MONOMIAL_H_
00012 #define _MONOMIAL_H_
00013
00021 #include <inttypes.h>
00022
00032
00033
00035
00047 typedef uint64_t monomial_t;
00048
00057 typedef uint8_t exponent_t;
00058
00060
00062
00068 #define MON_BITS_PER_EXP 8
00069
00076 #define MON_BITMASK_BLOCK 0x00000000000000FFULL
00077
00083 #define MON_BITMASK_ALL 0xFFFFFFFFFFFFFFFFULL
00084
00090 #define MON_VARS(n) (n == 1 ? "XY" : n == 2 ? "XYZ" : n == 3 ? "WXYZ" : n == 4 ? "VWXYZ" : n == 5 ? "UVWXYZ" : n == 6 ? "TUVWXYZ" : "STUVWXYZ")
00091
00093
00095
00097
00098
00111 #define MON_INIT(x) ((x) = 0)
00112
00118 #define MON_CLEAR(x)
00119
00127 #define MON_SET(x, y) ((x) = (y))
00128
00136 #define MON_SWAP(x, y) { monomial_t _t_ = (x); (x) = (y); (y) = _t_; }
00137
00145 #define MON_ONE(x) ((x) = 0)
00146
00151
00152
00153
00167 #define MON_GET_EXP(x, i) ((exponent_t) (((x) >> ((i) * MON_BITS_PER_EXP)) & MON_BITMASK_BLOCK))
00168
00176 #define MON_SET_EXP(x, i, e) ((x) = (((x) & (MON_BITMASK_ALL - (MON_BITMASK_BLOCK << ((i) * MON_BITS_PER_EXP)))) | (((monomial_t)(e)) << ((i) * MON_BITS_PER_EXP))))
00177
00186 #define MON_INC_EXP(x, i, e) ((x) = ((x) + (((monomial_t)(e)) << ((i) * MON_BITS_PER_EXP))))
00187
00196 #define MON_DEC_EXP(x, i, e) ((x) = ((x) - (((monomial_t)(e)) << ((i) * MON_BITS_PER_EXP))))
00197
00202
00203
00204
00217 #define MON_CMP_INVLEX(x, y) (((x) < (y)) ? -1 : ((x) > (y) ? 1 : 0))
00218
00226 #define MON_IS_ONE(x) ((x) == 0)
00227
00232
00233
00234
00247 #define MON_MUL(x, y, z) ((x) = (y) + (z))
00248
00256 #define MON_DIV(x, y, z) ((x) = (y) - (z))
00257
00262
00263
00265
00271 uint32_t mon_degree(monomial_t op);
00272
00282 int32_t mon_divides(monomial_t x, monomial_t y);
00283
00298 char * mon_to_string(monomial_t x, const uint8_t n);
00299 char * mon_to_string_pretty(monomial_t x, const uint8_t n, const char * vars);
00300 monomial_t mon_from_string(char * str);
00301
00311 monomial_t * mon_generate_by_degree(uint32_t * len, const uint8_t n,
00312 const uint32_t d);
00313 monomial_t * mon_generate_by_degree_invlex(uint32_t * len, const uint8_t n,
00314 const uint32_t d);
00315
00320 #endif
00321