int main() { pprod_t *p1, *p2; uint32_t i, j; int32_t cmp; p[0] = empty_pp; p[1] = var_pp(0); p[2] = var_pp(1); p[3] = var_pp(0x3fffffff); init_pp_buffer(&buffer, 0); p[4] = pp_buffer_getprod(&buffer); // empty pp_buffer_reset(&buffer); pp_buffer_mul_var(&buffer, 0); p[5] = pp_buffer_getprod(&buffer); // x_0 pp_buffer_reset(&buffer); pp_buffer_mul_var(&buffer, 0); pp_buffer_mul_var(&buffer, 1); pp_buffer_mul_var(&buffer, 0); p[6] = pp_buffer_getprod(&buffer); // x_0^2 x_1 pp_buffer_reset(&buffer); pp_buffer_mul_varexp(&buffer, 1, 2); pp_buffer_mul_varexp(&buffer, 4, 3); p[7] = pp_buffer_getprod(&buffer); // x_1^2 x_4^3 pp_buffer_set_varexp(&buffer, 3, 2); pp_buffer_mul_varexp(&buffer, 1, 4); p[8] = pp_buffer_getprod(&buffer); // x_3^2 x_1^4 pp_buffer_set_pprod(&buffer, p[7]); pp_buffer_mul_pprod(&buffer, p[1]); pp_buffer_mul_pprod(&buffer, p[8]); p[9] = pp_buffer_getprod(&buffer); for (i=0; i<NUM_PRODS; i++) { printf("p[%"PRIu32"] = ", i); print_pprod(stdout, p[i]); printf(" total degree = %"PRIu32"\n", pprod_degree(p[i])); for (j=0; j<5; j++) { printf(" degree of x_%"PRIu32" = %"PRIu32"\n", j, pprod_var_degree(p[i], j)); } printf("----\n"); } printf("\n"); for (i=0; i<NUM_PRODS; i++) { p1 = p[i]; for (j=0; j<NUM_PRODS; j++) { p2 = p[j]; printf("p1: "); print_pprod0(stdout, p1); printf("p2: "); print_pprod0(stdout, p2); if (pprod_equal(p1, p2)) { printf("equal products\n"); } if (pprod_divides(p1, p2)) { printf("p1 divides p2\n"); } if (pprod_divisor(&buffer, p1, p2)) { printf("p2/p1: "); print_pp_buffer0(stdout, &buffer); } if (pprod_divides(p2, p1)) { printf("p2 divides p1\n"); } if (pprod_divisor(&buffer, p2, p1)) { printf("p1/p2: "); print_pp_buffer0(stdout, &buffer); } cmp = pprod_lex_cmp(p1, p2); if (cmp < 0) { printf("p1 < p2 in lex order\n"); } else if (cmp > 0) { printf("p1 > p2 in lex order\n"); } else { printf("p1 = p2 in lex order\n"); } if (pprod_precedes(p1, p2)) { printf("p1 < p2 in deglex ordering\n"); } if (pprod_precedes(p2, p1)) { printf("p2 < p1 in deglex ordering\n"); } printf("----\n"); } } for (i=0; i<10; i++) { free_pprod(p[i]); } delete_pp_buffer(&buffer); return 0; }
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; }