/* * Print the term map for every uinterpreted term present in ctx->intern_tbl * then print the core */ void dimacs_print_bvcontext(FILE *f, context_t *ctx) { term_table_t *terms; intern_tbl_t *intern; uint32_t i, n; term_t t; assert(ctx->core != NULL); fputs("c Autogenerated by Yices\n", f); fputs("c\n", f); terms = ctx->terms; intern = &ctx->intern; n = intern->map.top; for (i=0; i<n; i++) { t = pos_term(i); if (good_term(terms, t) && term_kind(terms, t) == UNINTERPRETED_TERM) { dimacs_print_term_map(f, ctx, t); } } fputs("c\n", f); dimacs_print_core(f, ctx->core); fflush(f); }
/* * 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; } }
/* * Root of t's class * - apply path compression */ term_t intern_tbl_get_root(intern_tbl_t *tbl, term_t t) { term_t y, z; assert(good_term(tbl->terms, t)); y = intern_tbl_read_parent(tbl, t); if (y < 0) { // t is not in the table or t is a root return t; } z = intern_tbl_read_parent(tbl, y); if (z < 0) { // y is a root: skip path compression return y; } // find the root: we have t --> y --> z do { y = z; z = intern_tbl_read_parent(tbl, y); } while (z >= 0); // path compression: we have t --> .... --> y // and y is the root of all terms on that path do { z = intern_tbl_get_parent(tbl, t); intern_tbl_write_parent(tbl, t, y); t = z; } while (t != y); return y; }
/* * Store that f is abstracted to p * - there must not be a record for f in the cache */ static void cache_abstraction(eq_learner_t *learner, term_t f, epartition_t *p) { ptr_hmap_pair_t *r; assert(good_term(learner->terms, f) && is_boolean_term(learner->terms, f) && p != NULL); r = ptr_hmap_get(&learner->cache, f); assert(r->val == NULL); r->val = p; }
/* * Get abstraction for f in the cache * - this works only if the corresponding record exists */ static epartition_t *get_cached_abstraction(eq_learner_t *learner, term_t f) { ptr_hmap_pair_t *p; assert(good_term(learner->terms, f) && is_boolean_term(learner->terms, f)); p = ptr_hmap_find(&learner->cache, f); assert(p != NULL); return p->val; }
/* * Store the mapping [v --> t] in the cache */ static void convert_cache_map(val_converter_t *convert, value_t v, term_t t) { int_hmap_pair_t *r; assert(good_object(convert->vtbl, v) && good_term(convert->terms, t)); r = int_hmap_get(&convert->cache, v); assert(r->val < 0); r->val = t; }
/* * Add term t to the store: * - t is added as last element of store->terms[i] where i = index for type of t */ static void type_store_add_term(type_store_t *store, term_t t) { uint32_t i; type_t tau; assert(good_term(__yices_globals.terms, t)); tau = term_type(__yices_globals.terms, t); i = type_store_get_type(store, tau); ivector_push(store->terms + i, t); }
/* * Print the mapping for t as a comment in DIMACS */ void dimacs_print_term_map(FILE *f, context_t *ctx, term_t t) { term_table_t *terms; terms = ctx->terms; assert(good_term(terms, t)); fputs("c ", f); print_term_name(f, terms, t); fputs(" --> ", f); dimacs_print_internalized_term(f, ctx, t); fputc('\n', f); }
/* * Variant: don't apply path compression */ term_t intern_tbl_find_root(intern_tbl_t *tbl, term_t t) { term_t y; assert(good_term(tbl->terms, t)); y = intern_tbl_read_parent(tbl, t); while (y >= 0) { t = y; y = intern_tbl_read_parent(tbl, t); } return t; }
/* * Find the value of term t in model * - return null_value if t is not mapped to anything * - return the concrete object mapped to t otherwise */ value_t model_find_term_value(model_t *model, term_t t) { int_hmap_pair_t *r; assert(good_term(model->terms, t)); r = int_hmap_find(&model->map, t); if (r == NULL) { return null_value; } else { return r->val; } }
/* * Check whether t is mapped to a term v in the substitution table. * - return v if it is * - return NULL_TERM otherwise */ term_t model_find_term_substitution(model_t *model, term_t t) { int_hmap_t *alias; int_hmap_pair_t *r; assert(good_term(model->terms, t) && model->has_alias); alias = model->alias_map; if (alias != NULL) { r = int_hmap_find(alias, t); if (r != NULL) { return r->val; } } return NULL_TERM; }
/* * Store the substitution t --> u in the model * - t and u must be valid term indices * - t must be an uninterpreted term, not mapped to anything */ void model_add_substitution(model_t *model, term_t t, term_t u) { int_hmap_t *alias; int_hmap_pair_t *r; assert(term_kind(model->terms, t) == UNINTERPRETED_TERM && good_term(model->terms, u) && t != u && model->has_alias && int_hmap_find(&model->map, t) == NULL); alias = model->alias_map; if (alias == NULL) { alias = (int_hmap_t *) safe_malloc(sizeof(int_hmap_t)); init_int_hmap(alias, 0); // default size model->alias_map = alias; } r = int_hmap_get(alias, t); assert(r->val < 0); r->val = u; }
/* * Multiply b by t^d * - t must be an arithmetic term * - p->ptbl and table->pprods must be equal */ void bvarith_buffer_mul_term_power(bvarith_buffer_t *b, term_table_t *table, term_t t, uint32_t d) { bvarith_buffer_t aux; bvconstant_t c; bvpoly_t *p; pprod_t **v; pprod_t *r; 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: r = pprod_exp(b->ptbl, pprod_for_idx(table, i), d); // r = t^d bvarith_buffer_mul_pp(b, r); break; case BV_CONSTANT: init_bvconstant(&c); bvconstant_copy64(&c, b->bitsize, 1); // c := 1 bvconst_mulpower(c.data, b->width, bvconst_for_idx(table, i)->data, d); // c := t^d bvarith_buffer_mul_const(b, c.data); delete_bvconstant(&c); break; case BV_POLY: p = bvpoly_for_idx(table, i); v = pprods_for_bvpoly(table, p); init_bvarith_buffer(&aux, b->ptbl, b->store); bvarith_buffer_mul_bvpoly_power(b, p, v, d, &aux); delete_bvarith_buffer(&aux); term_table_reset_pbuffer(table); break; default: r = pprod_varexp(b->ptbl, t, d); bvarith_buffer_mul_pp(b, r); break; } }
/* * Store the mapping t := v in model * - t must not be mapped to anything * - v must be a valid object created in model->vtbl. * * If v is a function object and it has no name, then t's name is * given to v. */ void model_map_term(model_t *model, term_t t, value_t v) { int_hmap_pair_t *r; value_table_t *vtbl; char *name; assert(good_term(model->terms, t)); r = int_hmap_get(&model->map, t); assert(r->val < 0); r->val = v; // copy t's name if any name = term_name(model->terms, t); if (name != NULL) { vtbl = &model->vtbl; if (object_is_function(vtbl, v) && vtbl_function(vtbl, v)->name == NULL) { vtbl_set_function_name(vtbl, v, name); } } }
/* * 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; } }