33 for (i = 1; i <=
n; i++) {
56 for (i =
n - p + 2; i <=
n; i++) {
72void CNP(
int a,
int b, Value *result) {
85 for (i = a; i > b; --i) {
89 for (i = 1; i <= (a - b); ++i) {
99void Gcd(Value a, Value b, Value *result) {
126 for (i = 0; i < length; i++) {
131 return ((i == length) ? -1 : i);
144 errormsg1(
"Vector_Alloc",
"outofmem",
"out of memory space");
147 vector->
Size = length;
148 vector->
p = (Value *)malloc(length *
sizeof(Value));
150 errormsg1(
"Vector_Alloc",
"outofmem",
"out of memory space");
154 for (i = 0; i < length; i++)
168 for (i = 0; i < vector->
Size; i++)
182 fprintf(Dst,
"%d\n", length = vector->
Size);
184 for (i = 0; i < length; i++) {
205 scanf(
"%d", &length);
208 errormsg1(
"Vector_Read",
"outofmem",
"out of memory space");
212 for (i = 0; i < length; i++) {
213 int r = scanf(
"%ms", &
s);
215 errormsg1(
"Vector_Read",
"hi, Mathematica",
"scanf at line 231 failed");
233 for (i = 0; i < length; i++) {
247 for (i = 0; i < length; i++) {
264 for (i = 0; i < length; i++)
273void Vector_Add(Value *p1, Value *p2, Value *p3,
unsigned length) {
275 Value *cp1, *cp2, *cp3;
281 for (i = 0; i < length; i++) {
294void Vector_Sub(Value *p1, Value *p2, Value *p3,
unsigned length) {
296 Value *cp1, *cp2, *cp3;
302 for (i = 0; i < length; i++) {
315void Vector_Or(Value *p1, Value *p2, Value *p3,
unsigned length) {
317 Value *cp1, *cp2, *cp3;
323 for (i = 0; i < length; i++) {
336void Vector_Scale(Value *p1, Value *p2, Value lambda,
unsigned length) {
343 for (i = 0; i < length; i++) {
359 for (i = 0; i < length; i++)
369 for (i = 0; i < len; ++i)
383 for (i = 1; i < length; i++)
398 for (i = 1; i < length; i++) {
415 for (i = 1; i < length; i++) {
431 for (i = 0; i < length; i++) {
446 for (i = 0; i <
n; ++i)
470 for (i = i + 1; i < length; i++) {
488 int i, Not_Zero, Index_Min = 0;
490 q = (Value *)malloc(length *
sizeof(Value));
493 for (i = 0; i < length; i++)
499 for (cq = q, i = 0; i < length; i++) {
512 for (i = 0; i < length; i++, cq++)
513 if (i != Index_Min) {
524 for (i = 0; i < length; i++)
533void Vector_Map(Value *p1, Value *p2, Value *p3,
unsigned length,
534 Value *(*f)(Value, Value)) {
535 Value *cp1, *cp2, *cp3;
541 for (i = 0; i < length; i++) {
599 for (i = 1; i < length; i++) {
612 Value *current_node = (Value *)0;
613 Value *left_son, *right_son;
617 for (i = (
n - 1) / 2; i >= 0; i--) {
624 while (j <= (
n - 1) / 2) {
625 current_node = vector + j;
626 left_son = vector + (j << 1) + 1;
629 if ((j << 1) + 2 >=
n) {
638 right_son = left_son + 1;
639 if (
value_lt(*right_son, *left_son)) {
656 for (i =
n - 1; i > 0; i--) {
665 current_node = vector + j;
666 left_son = vector + (j << 1) + 1;
669 if ((j << 1) + 2 >= i) {
678 right_son = left_son + 1;
679 if (
value_lt(*right_son, *left_son)) {
746#define MAX_CACHE_SIZE 20
754#ifdef THREAD_SAFE_POLYLIB
758static pthread_once_t once_cache = PTHREAD_ONCE_INIT;
759static pthread_key_t cache_key;
761#define cache_size (cache[MAX_CACHE_SIZE].size)
768 assert(pthread_setspecific(cache_key,
cache) == 0);
771static void free_local_cache(
void *c) { free(c); }
772static void init_value_caches(
void) {
773 pthread_key_create(&cache_key, free_local_cache);
785#ifdef THREAD_SAFE_POLYLIB
786 assert(pthread_once(&once_cache, init_value_caches) == 0);
789 cache = allocate_local_cache();
795 if (
cache[i].size >= want) {
807 p = (Value *)realloc(
cache[best].p, want *
sizeof(Value));
813 p = (Value *)malloc(want *
sizeof(Value));
820 for (i = *got; i < want; ++i)
830#ifdef THREAD_SAFE_POLYLIB
837 (
cache = pthread_getspecific(cache_key)) != NULL);
847 for (i = 0; i < size; i++)
857#ifdef THREAD_SAFE_POLYLIB
858 assert(pthread_once(&once_cache, init_value_caches) == 0);
860 if ((
cache = pthread_getspecific(cache_key)) == NULL)
862 pthread_key_delete(cache_key);
873#ifdef THREAD_SAFE_POLYLIB
875 pthread_key_delete(cache_key);
#define value_oppose(ref, val)
#define value_maximum(ref, val1, val2)
#define value_pdivision(ref, val1, val2)
#define value_orto(ref, val1, val2)
#define value_swap(v1, v2)
#define value_notzero_p(val)
#define value_divexact(ref, val1, val2)
#define value_notone_p(val)
#define value_absolute(ref, val)
#define value_zero_p(val)
#define value_assign(v1, v2)
#define value_set_si(val, i)
#define value_addmul(ref, val1, val2)
#define value_minimum(ref, val1, val2)
#define value_read(val, str)
#define value_division(ref, val1, val2)
#define value_multiply(ref, val1, val2)
#define value_print(Dst, fmt, val)
#define value_modulus(ref, val1, val2)
#define value_subtract(ref, val1, val2)
#define value_addto(ref, val1, val2)
void errormsg1(const char *f, const char *msgname, const char *msg)
Value * value_alloc(int want, int *got)
void Vector_Free(Vector *vector)
void Vector_Scale(Value *p1, Value *p2, Value lambda, unsigned length)
void Vector_Print(FILE *Dst, const char *Format, Vector *vector)
void Vector_Set(Value *p, int n, unsigned length)
void Inner_Product(Value *p1, Value *p2, unsigned length, Value *ip)
int Vector_Equal(Value *Vec1, Value *Vec2, unsigned n)
void value_free(Value *p, int size)
void Vector_Normalize_Positive(Value *p, int length, int pos)
void Gcd(Value a, Value b, Value *result)
void Vector_Combine(Value *p1, Value *p2, Value *p3, Value lambda, Value mu, unsigned length)
cache_holder cache[MAX_CACHE_SIZE]
Vincent's patch for thread safe value cache.
int Vector_IsZero(Value *v, unsigned length)
void Vector_Max(Value *p, unsigned length, Value *max)
void Factorial(int n, Value *fact)
void Vector_Gcd(Value *p, unsigned length, Value *min)
void Vector_Exchange(Value *p1, Value *p2, unsigned length)
void Vector_AntiScale(Value *p1, Value *p2, Value lambda, unsigned length)
void Vector_Add(Value *p1, Value *p2, Value *p3, unsigned length)
void Vector_Sub(Value *p1, Value *p2, Value *p3, unsigned length)
void Vector_Reduce(Value *p, unsigned length, void(*f)(Value, Value *), Value *r)
void Vector_Normalize(Value *p, unsigned length)
void Vector_Min_Not_Zero(Value *p, unsigned length, int *index, Value *min)
void Vector_Sort(Value *vector, unsigned n)
Vector * Vector_Alloc(unsigned length)
void Vector_Copy(Value *p1, Value *p2, unsigned length)
int First_Non_Zero(Value *p, unsigned length)
void Vector_Map(Value *p1, Value *p2, Value *p3, unsigned length, Value *(*f)(Value, Value))
void CNP(int a, int b, Value *result)
void Vector_Oppose(Value *p1, Value *p2, unsigned len)
int ConstraintSimplify(Value *old, Value *newp, int len, Value *v)
void Binomial(int n, int p, Value *result)
void Vector_Min(Value *p, unsigned length, Value *min)
void Vector_Or(Value *p1, Value *p2, Value *p3, unsigned length)