/* * DISPLAY CONSTRAINT */ static void show_constant(FILE *f, rational_t *a, bool first) { if (first) { if (q_is_neg(a)) { fprintf(f, "- "); } } else { if (q_is_neg(a)) { fprintf(f, " - "); } else { fprintf(f, " + "); } } q_print_abs(f, a); }
/* * Print stuff */ static void print_mono(const char *prefix, rational_t *coeff, int32_t x, bool first) { bool negative; bool abs_one; negative = q_is_neg(coeff); if (negative) { if (first) { printf("-"); if (x != const_idx) { printf(" "); } } else { printf(" - "); } abs_one = q_is_minus_one(coeff); } else { if (! first) { printf(" + "); } abs_one = q_is_one(coeff); } if (x == const_idx) { q_print_abs(stdout, coeff); } else { if (! abs_one) { q_print_abs(stdout, coeff); printf(" * "); } printf("%s%"PRId32, prefix, x); } }
/* * Difference logic triple (x - y + d) * - x and y are vertices */ void print_idl_triple(FILE *f, dl_triple_t *triple) { bool space; space = false; if (triple->target >= 0) { print_idl_vertex(f, triple->target); // x space = true; } if (triple->source >= 0) { if (space) fputc(' ', f); fputs("- ", f); print_idl_vertex(f, triple->source); // y space = true; } if (! space) { q_print(f, &triple->constant); } else if (q_is_pos(&triple->constant)) { fprintf(f, " + "); q_print(f, &triple->constant); } else if (q_is_neg(&triple->constant)) { fprintf(f, " - "); q_print_abs(f, &triple->constant); } }
/* * Print a monomial (copied from term_printer.c) * - variables v is converted to vertex id i-1 */ static void print_monomial(int32_t v, rational_t *coeff, bool first) { bool negative; bool abs_one; negative = q_is_neg(coeff); if (negative) { if (first) { printf("- "); } else { printf(" - "); } abs_one = q_is_minus_one(coeff); } else { if (! first) { printf(" + "); } abs_one = q_is_one(coeff); } if (v == const_idx) { q_print_abs(stdout, coeff); } else { if (! abs_one) { q_print_abs(stdout, coeff); printf(" * "); } printf("x!%"PRId32, v-1); } }
/* * Print buffer b */ static void print_monomial(FILE *f, rational_t *coeff, pprod_t *r, bool first) { bool negative; bool abs_one; negative = q_is_neg(coeff); if (negative) { if (first) { fprintf(f, "- "); } else { fprintf(f, " - "); } abs_one = q_is_minus_one(coeff); } else { if (! first) { fprintf(f, " + "); } abs_one = q_is_one(coeff); } if (pp_is_empty(r)) { q_print_abs(f, coeff); } else { if (! abs_one) { q_print_abs(f, coeff); fprintf(f, " "); } print_pprod0(f, r); } }
static void print_avar_monomial(FILE *f, arith_vartable_t *table, thvar_t v, rational_t *coeff, bool first) { bool negative; bool abs_one; negative = q_is_neg(coeff); if (negative) { if (first) { fputs("- ", f); } else { fputs(" - ", f); } abs_one = q_is_minus_one(coeff); } else { if (! first) { fputs(" + ", f); } abs_one = q_is_one(coeff); } if (v == const_idx) { q_print_abs(f, coeff); } else { if (! abs_one) { q_print_abs(f, coeff); fputs(" * ", f); } print_avar(f, table, v); } }
static void print_vtable(offset_manager_t *mngr) { offset_table_t *table; offset_desc_t *d; uint32_t i, n; table = &mngr->vtable; printf("===== vtable ====\n"); n = table->nvars; for (i=0; i<n; i++) { d = table->desc + i; printf("z%"PRIu32" = z%"PRId32, i, d->root); if (q_is_neg(&d->offset)) { printf(" - "); } else { printf(" + "); } q_print_abs(stdout, &d->offset); printf("\n"); printf(" dep: "); print_dep(table->dep[i]); printf("\n"); } }
/* * Print a triple */ static void print_dl_triple(dl_triple_t *t) { bool space; space = false; if (t->target >= 0) { printf("x!%"PRId32, t->target); space = true; } if (t->source >= 0) { if (space) printf(" "); printf("- x!%"PRId32, t->source); } if (! space) { q_print(stdout, &t->constant); } else if (q_is_pos(&t->constant)) { printf(" + "); q_print(stdout, &t->constant); } else if (q_is_neg(&t->constant)) { printf(" - "); q_print_abs(stdout, &t->constant); } }
bool arith_buffer_is_neg(arith_buffer_t *b) { return b->nterms == 1 && b->list->prod == empty_pp && q_is_neg(&b->list->coeff); }
bool polynomial_is_nonpos(polynomial_t *p) { return p->nterms == 0 || (p->nterms == 1 && p->mono[0].var == const_idx && q_is_neg(&p->mono[0].coeff)); }
/* * Phase and period of p * - p is c + (a_1/b_1) x_1 + ... + (a_n/b_n) x_n where * a_i/b_i is an irreducible fraction * - let D = gcd(a_1,..., a_n) and L = lcm(b_1,...,b_n) * then period = D/L and phase = c - floor(c/period) * period */ void monarray_period_and_phase(monomial_t *p, rational_t *period, rational_t *phase) { rational_t aux; monomial_t *c; int32_t v; /* * c := the constant monomial of p or NULL if p's constant is zero */ c = NULL; v = p->var; if (v == const_idx) { c = p; p ++; v = p->var; } if (v < max_idx) { /* * p is not a constant: compute D and L * we use period for D and phase for L */ q_get_num(period, &p->coeff); // D := |a_1| if (q_is_neg(period)) { q_neg(period); } q_get_den(phase, &p->coeff); // L := b_1 q_init(&aux); for (;;) { p ++; v = p->var; if (v >= max_idx) break; q_get_num(&aux, &p->coeff); q_gcd(period, &aux); // D := gcd(D, a_i) q_get_den(&aux, &p->coeff); q_lcm(phase, &aux); // L := lcm(L, b_i) } assert(q_is_pos(period) && q_is_pos(phase)); q_div(period, phase); // period := D/L /* * Phase: constant modulo D/L */ if (c == NULL) { q_clear(phase); // no constant: phase = 0 } else { q_set(&aux, &c->coeff); q_div(&aux, period); q_floor(&aux); // aux = floor(c/period) q_set(phase, &c->coeff); q_submul(phase, &aux, period); // phase = c - aux * period assert(q_is_nonneg(phase) && q_lt(phase, period)); } q_clear(&aux); } else { /* * p is constant: period := 0, phase = constant coeff */ q_clear(period); if (c == NULL) { q_clear(phase); } else { q_set(phase, &c->coeff); } } }