/* * Random polynomial: * - use variables defined in table */ static polynomial_t *random_poly(poly_buffer_t *b, poly_table_t *table) { rational_t q; uint32_t i, n; int32_t x, a; q_init(&q); reset_poly_buffer(b); a = random_constant(); q_set32(&q, a); poly_buffer_add_const(b, &q); n = random_nterms(); for (i=0; i<n; i++) { a = random_coeff(); x = random_var(table); assert(x > 0); q_set32(&q, a); poly_buffer_add_monomial(b, x, &q); } normalize_poly_buffer(b); q_clear(&q); return poly_buffer_get_poly(b); }
/* * Build a polynomial: * - a = coefficient array * - x = variable array * - n = number of coefficients * * a[0] is the constant (x[0] is ignored) */ static polynomial_t *make_poly(poly_buffer_t *b, int32_t *a, int32_t *x, uint32_t n) { rational_t q; uint32_t i; assert(n > 0); q_init(&q); reset_poly_buffer(b); q_set32(&q, a[0]); poly_buffer_add_const(b, &q); for (i=1; i<n; i++) { q_set32(&q, a[i]); poly_buffer_add_monomial(b, x[i], &q); } normalize_poly_buffer(b); q_clear(&q); return poly_buffer_get_poly(b); }