/* * Print a monomial (copied from term_printer.c) */ 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); } }
/* * 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); } }
/* * Print monomial (* a <prefix>_<x>) */ static void dsolver_print_monomial(FILE *f, rational_t *a, int32_t x, char prefix) { if (q_is_one(a)) { fprintf(f, "%c_%"PRId32, prefix, x); } else if (q_is_minus_one(a)) { fprintf(f, "(- %c_%"PRId32")", prefix, x); } else { fprintf(f, "(* "); q_print(f, a); fprintf(f, " %c_%"PRId32")", prefix, x); } }
/* * Check whether b is of the form 1 * X for a non-null power-product X * If so return X in *r */ bool arith_buffer_is_product(arith_buffer_t *b, pprod_t **r) { mlist_t *p; if (b->nterms == 1) { p = b->list; if (p->prod != empty_pp && q_is_one(&p->coeff)) { assert(p->prod != end_pp); *r = p->prod; return true; } } return false; }
/* * Check whether p == x for variable x */ bool polynomial_is_var(polynomial_t *p, int32_t x) { return p->nterms == 1 && p->mono[0].var == x && q_is_one(&p->mono[0].coeff); }
/* * Check whether p == k + x for non-zero k and variable x */ bool polynomial_is_const_plus_var(polynomial_t *p, int32_t x) { return p->nterms == 2 && p->mono[0].var == const_idx && p->mono[1].var == x && q_is_one(&p->mono[1].coeff); }