Ejemplo n.º 1
0
/*
 * Add t to buffer b
 * - t must be defined in table and be a bitvector term of same bitsize as b
 * - b->ptbl must be the same as table->pprods
 */
void bvarith_buffer_add_term(bvarith_buffer_t *b, term_table_t *table, term_t t) {
  pprod_t **v;
  bvpoly_t *p;
  int32_t i;

  assert(b->ptbl == table->pprods);
  assert(pos_term(t) && good_term(table, t) && is_bitvector_term(table, t) &&
         term_bitsize(table, t) == b->bitsize);

  i = index_of(t);
  switch (table->kind[i]) {
  case POWER_PRODUCT:
    bvarith_buffer_add_pp(b, pprod_for_idx(table, i));
    break;

  case BV_CONSTANT:
    bvarith_buffer_add_const(b, bvconst_for_idx(table, i)->data);
    break;

  case BV_POLY:
    p = bvpoly_for_idx(table, i);
    v = pprods_for_bvpoly(table, p);
    bvarith_buffer_add_bvpoly(b, p, v);
    term_table_reset_pbuffer(table);
    break;

  default:
    bvarith_buffer_add_var(b, t);
    break;
  }
}
Ejemplo n.º 2
0
/*
 * Initialize the buffers:
 * - n = bitsize
 */
static void init_test2(uint32_t n) {
  uint32_t q0[4];
  uint32_t i;

  assert(0 < n && n <= 128);

  for (i=0; i<8; i++) {
    init_bvarith_buffer(aux + i, &prod_table, &store);
    bvarith_buffer_prepare(aux + i, n);
  }

  bvarith_buffer_add_var(&aux[0], 3); // x_3

  bvconst_set32(q0, 4, 2);
  bvarith_buffer_add_const(&aux[1], q0); // 2

  bvarith_buffer_add_var(&aux[2], 1);
  bvarith_buffer_sub_var(&aux[2], 2); // x_1 - x_2

  bvarith_buffer_add_var(&aux[3], 0);
  bvarith_buffer_sub_const(&aux[3], q0); // x_0 - 2

  bvarith_buffer_add_pp(&aux[4], pprod_mul(&prod_table, var_pp(1), var_pp(1))); // x_1^2

  bvarith_buffer_add_var(&aux[5], 0);
  bvarith_buffer_mul_const(&aux[5], q0); // 2 * x_0

  bvarith_buffer_add_varmono(&aux[6], q0, 1); // 2 * x_1

  bvarith_buffer_sub_var(&aux[7], 3);
  bvarith_buffer_sub_var(&aux[7], 3);
  bvarith_buffer_add_var(&aux[7], 4);

  for (i=0; i<8; i++) {
    bvarith_buffer_normalize(aux + i);
  }
}