コード例 #1
0
void expand_bvpprod(bvexp_table_t *table, bvarith_buffer_t *buffer, pp_buffer_t *p, uint32_t n, uint32_t *c) {
  bv_vartable_t *vtbl;
  bvmlist_t *q;
  pp_buffer_t *aux;
  pprod_t *r;
  uint32_t *a;
  uint32_t i, m, d, e, k;
  thvar_t x;


  assert(buffer->store == &table->store && buffer->ptbl == &table->pprods);

  bvarith_buffer_prepare(buffer, n);
  bvarith_buffer_set_one(buffer);
  aux = p;

  vtbl = table->vtbl;

  if (total_degree_test(table, vtbl, p)) {
    aux = &table->pp;
    pp_buffer_reset(aux);

    // make a copy of c in the internal bvconst buffer
    bvconstant_copy(&table->bvconst, n, c);
    c = table->bvconst.data;

    k = (n + 31) >> 5;
    m = p->len;
    for (i=0; i<m; i++) {
      x = p->prod[i].var;
      d = p->prod[i].exp;
      if (bvvar_is_const(vtbl, x)) {
        a = bvvar_val(vtbl, x);
        bvconst_mulpower(c, k, a, d);
      } else {
        q = bvexp_def(table, x);
        if (q != NULL && mlist_is_short(q, &e) && d * e <= BVEXP_DEGREE_LIMIT) {
          bvarith_buffer_mul_mlist_power(buffer, q, d, &table->aux);
        } else {
          pp_buffer_mul_varexp(aux, x, d);
        }
      }
    }

    // normalize
    bvconst_normalize(c, n);
    pp_buffer_normalize(aux);
  }

  /*
   * The result is c * aux * buffer
   */
  r = pprod_from_buffer(&table->pprods, aux);
  bvarith_buffer_mul_mono(buffer, c, r);
  bvarith_buffer_normalize(buffer);
}
コード例 #2
0
/*
 * Add a * t to b
 * - t must be defined in table and be a bitvector term of same bitsize as b
 * - a must be have the same bitsize as b (as many words a b->width)
 * - b->ptbl must be the same as table->pprods
 */
void bvarith_buffer_add_const_times_term(bvarith_buffer_t *b, term_table_t *table, uint32_t *a, term_t t) {
  bvconstant_t c;
  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_mono(b, a, pprod_for_idx(table, i));
    break;

  case BV_CONSTANT:
    init_bvconstant(&c);
    bvconstant_copy(&c, b->bitsize, bvconst_for_idx(table, i)->data);
    bvconst_mul(c.data, b->width, a);
    bvarith_buffer_add_const(b, c.data);
    delete_bvconstant(&c);
    break;

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

  default:
    bvarith_buffer_add_varmono(b, a, t);
    break;
  }
}