/* * Expanded form for a product c * p * - c is a normalized bitvector constant * - p is a power product stored in a pp_buffer object * - n = bitsize of p * - the expansion is returned in a bvarith_buffer or bvarith64_buffer object * - the result is normalized */ void expand_bvpprod64(bvexp_table_t *table, bvarith64_buffer_t *buffer, pp_buffer_t *p, uint32_t n, uint64_t c) { bv_vartable_t *vtbl; bvmlist64_t *q; pp_buffer_t *aux; pprod_t *r; uint64_t a; uint32_t i, m, e, d; thvar_t x; assert(buffer->store == &table->store64 && buffer->ptbl == &table->pprods); bvarith64_buffer_prepare(buffer, n); bvarith64_buffer_set_one(buffer); aux = p; vtbl = table->vtbl; if (total_degree_test64(table, vtbl, p)) { /* * Expansion of c * x_1^d_1 ... x_n^ d_n: * - for a constant x_i, update c to c * a^d_i (where a = value of c) * - if x_i is expanded to q_i, update buffer to buffer * q_i ^ d_i * - otherwise, x_i^d_i is copied into the aux buffer */ aux = &table->pp; pp_buffer_reset(aux); m = p->len; for (i=0; i<m; i++) { x = p->prod[i].var; d = p->prod[i].exp; if (bvvar_is_const64(vtbl, x)) { a = bvvar_val64(vtbl, x); c *= upower64(a, d); } else { q = bvexp_def64(table, x); if (q != NULL && mlist64_is_short(q, &e) && d * e <= BVEXP_DEGREE_LIMIT) { // replace x^d by q^d in buffer bvarith64_buffer_mul_mlist_power(buffer, q, d, &table->aux64); } else { // copy x^d into aux pp_buffer_mul_varexp(aux, x, d); } } } c = norm64(c, n); pp_buffer_normalize(aux); } /* * The result is c * aux * buffer */ r = pprod_from_buffer(&table->pprods, aux); bvarith64_buffer_mul_mono(buffer, c, r); bvarith64_buffer_normalize(buffer); }
int main(void) { uint32_t d; // powers of 0 for (d=0; d<16; d++) { printf("pow32(0, %"PRIu32") = %"PRIu32"\n", d, upower32(0, d)); printf("pow64(0, %"PRIu32") = %"PRIu64"\n", d, upower64(0, d)); } // powers of 1 for (d=0; d<16; d++) { printf("pow32(1, %"PRIu32") = %"PRIu32"\n", d, upower32(1, d)); printf("pow64(1, %"PRIu32") = %"PRIu64"\n", d, upower64(1, d)); } // powers of 2 for (d=0; d<80; d++) { printf("pow32(2, %"PRIu32") = %"PRIu32"\n", d, upower32(2, d)); printf("pow64(2, %"PRIu32") = %"PRIu64"\n", d, upower64(2, d)); } return 0; }