/* * Power product p */ static void print_bv_pprod(FILE *f, pprod_t *p) { assert(! pp_is_empty(p) && p != end_pp); if (pp_is_var(p)) { print_bvvar(f, var_of_pp(p)); } else { print_bv_product(f, p); } }
static void print_pprod0(FILE *f, pprod_t *p) { if (pp_is_var(p)) { fprintf(f, "x_%"PRId32, var_of_pp(p)); } else if (pp_is_empty(p)) { fprintf(f, "1"); } else { print_varexp_array(f, p->prod, p->len); } }
static void print_pprod(FILE *f, pprod_t *p) { fprintf(f, "pprod %p\n", p); if (pp_is_var(p)) { fprintf(f, " var pp = [x_%"PRId32"]\n", var_of_pp(p)); } else if (pp_is_empty(p)) { fprintf(f, " empty\n"); } else { fprintf(f, " len = %"PRIu32"\n", p->len); fprintf(f, " degree = %"PRIu32"\n", p->degree); fprintf(f, " product = "); print_varexp_array(f, p->prod, p->len); fprintf(f, "\n"); } }
int main(void) { uint32_t i, j, n; pprod_t *q; init_pprod_table(&ptbl, 10); init_pp_buffer(&buffer, 10); p[0] = empty_pp; p[1] = var_pp(0); p[2] = var_pp(1); p[3] = var_pp(2); p[4] = var_pp(3); num_prods = 5; for (i=0; i<5; i++) { for (j=0; j<5; j++) { q = pprod_mul(&ptbl, p[i], p[j]); print_pprod0(stdout, p[i]); printf(" * "); print_pprod0(stdout, p[j]); printf(" = "); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); } } n = num_prods; for (i=0; i<n; i++) { for (j=0; j<n; j++) { q = pprod_mul(&ptbl, p[i], p[j]); print_pprod0(stdout, p[i]); printf(" * "); print_pprod0(stdout, p[j]); printf(" = "); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); } } for (i=0; i<num_prods; i++) { pp_buffer_set_pprod(&buffer, p[i]); printf("p[%"PRIu32"] = %p = ", i, p[i]); print_pprod0(stdout, p[i]); printf("\n"); printf("buffer: "); print_pp_buffer0(stdout, &buffer); printf("\n"); q = pprod_from_buffer(&ptbl, &buffer); printf("prod from buffer = %p = ", q); print_pprod0(stdout, q); if (q != p[i]) { printf("BUG: HASH CONSING FAILED\n"); fflush(stdout); abort(); } printf("\n\n"); } // delete the non-trivial products for (i=5; i<num_prods; i++) { q = p[i]; assert(q != empty_pp && q != end_pp && !pp_is_var(q)); printf("deleting p[%"PRIu32"] = %p = ", i, q); print_pprod0(stdout, q); printf("\n"); delete_pprod(&ptbl, q); } printf("\n\n"); p[5] = var_pp(4); num_prods = 6; // reconstruct more products q = pprod_mul(&ptbl, p[1], p[2]); printf("checking q = %p = ", q); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); q = pprod_mul(&ptbl, p[2], p[3]); printf("checking q = %p = ", q); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); q = pprod_mul(&ptbl, p[3], p[2]); printf("rechecking q = %p = ", q); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); q = pprod_mul(&ptbl, p[3], p[4]); printf("checking q = %p = ", q); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); q = pprod_mul(&ptbl, p[4], p[3]); printf("rechecking q = %p = ", q); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); q = pprod_mul(&ptbl, p[4], p[5]); printf("checking q = %p = ", q); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); q = pprod_mul(&ptbl, p[0], p[5]); printf("checking q = %p = ", q); print_pprod0(stdout, q); printf("\n"); check_product(q); printf("\n"); printf("*** Table content before GC ***\n"); print_pprod_table(stdout, &ptbl); pprod_table_set_gc_mark(&ptbl, p[num_prods - 1]); pprod_table_gc(&ptbl); printf("\n*** Table content after GC ***\n"); print_pprod_table(stdout, &ptbl); printf("\n"); delete_pp_buffer(&buffer); delete_pprod_table(&ptbl); return 0; }