expr_ref_vector mk_array_instantiation::retrieve_all_selects(expr*array) { expr_ref_vector all_selects(m); for(expr_equiv_class::iterator it = eq_classes.begin(array); it != eq_classes.end(array); ++it) { selects.insert_if_not_there(*it, ptr_vector<expr>()); ptr_vector<expr>& select_ops = selects[*it]; for(unsigned i=0;i<select_ops.size();i++) { all_selects.push_back(rewrite_select(array, select_ops[i])); } } if(all_selects.size()==0) { expr_ref_vector dummy_args(m); dummy_args.push_back(array); for(unsigned i=0;i<get_array_arity(get_sort(array));i++) { dummy_args.push_back(m.mk_var(cnt, get_array_domain(get_sort(array), i))); cnt++; } all_selects.push_back(m_a.mk_select(dummy_args.size(), dummy_args.c_ptr())); } return all_selects; }
expr_ref mk_array_instantiation::create_head(app* old_head) { expr_ref_vector new_args(m); for(unsigned i=0;i<old_head->get_num_args();i++) { expr*arg = old_head->get_arg(i); if(m_a.is_array(get_sort(arg))) { for(unsigned k=0; k< m_ctx.get_params().xform_instantiate_arrays_nb_quantifier();k++) { expr_ref_vector dummy_args(m); dummy_args.push_back(arg); for(unsigned i=0;i<get_array_arity(get_sort(arg));i++) { dummy_args.push_back(m.mk_var(cnt, get_array_domain(get_sort(arg), i))); cnt++; } expr_ref select(m); select = m_a.mk_select(dummy_args.size(), dummy_args.c_ptr()); new_args.push_back(select); selects.insert_if_not_there(arg, ptr_vector<expr>()); selects[arg].push_back(select); } if(!m_ctx.get_params().xform_instantiate_arrays_enforce()) new_args.push_back(arg); } else new_args.push_back(arg); } return create_pred(old_head, new_args); }
void mk_array_instantiation::retrieve_selects(expr* e) { //If the expression is not a function application, we ignore it if (!is_app(e)) { return; } app*f=to_app(e); //Call the function recursively on all arguments unsigned nbargs = f->get_num_args(); for(unsigned i=0;i<nbargs;i++) { retrieve_selects(f->get_arg(i)); } //If it is a select, then add it to selects if(m_a.is_select(f)) { SASSERT(!m_a.is_array(get_sort(e))); selects.insert_if_not_there(f->get_arg(0), ptr_vector<expr>()); selects[f->get_arg(0)].push_back(e); } //If it is a condition between arrays, for example the result of a store, then add it to the equiv_classes if(m_a.is_store(f)) { eq_classes.merge(e, f->get_arg(0)); } else if(m.is_eq(f) && m_a.is_array(get_sort(f->get_arg(0)))) { eq_classes.merge(f->get_arg(0), f->get_arg(1)); } }
void check_for_fd(unsigned n, expr* const* args) { for (unsigned i = 0; i < n; ++i) { if (m_imp.is_fd(get_sort(args[i]))) { throw_non_fd(args[i]); } } }
int main() { int array[MAX],size; printf("Input the muber of elements in an array: \n"); scanf("%d",&size); get_sort(array,size); //calling this function to get and sort the array elements display(array,size); //calling this function to display the required elements return 0; }
var * mk_array_instantiation::mk_select_var(expr* select) { var*result; if(!done_selects.find(select, result)) { ownership.push_back(select); result = m.mk_var(cnt, get_sort(select)); cnt++; done_selects.insert(select, result); } return result; }
expr_ref_vector mk_array_instantiation::instantiate_pred(app*old_pred) { unsigned nb_old_args=old_pred->get_num_args(); //Stores, for each old position, the list of a new possible arguments vector<expr_ref_vector> arg_correspondance; for(unsigned i=0;i<nb_old_args;i++) { expr_ref arg(old_pred->get_arg(i), m); if(m_a.is_array(get_sort(arg))) { vector<expr_ref_vector> arg_possibilities(m_ctx.get_params().xform_instantiate_arrays_nb_quantifier(), retrieve_all_selects(arg)); arg_correspondance.append(arg_possibilities); if(!m_ctx.get_params().xform_instantiate_arrays_enforce()) { expr_ref_vector tmp(m); tmp.push_back(arg); arg_correspondance.push_back(tmp); } } else { expr_ref_vector tmp(m); tmp.push_back(arg); arg_correspondance.push_back(tmp); } } //Now, we need to deal with every combination expr_ref_vector res(m); svector<unsigned> chosen(arg_correspondance.size(), 0u); while(1) { expr_ref_vector new_args(m); for(unsigned i=0;i<chosen.size();i++) { new_args.push_back(arg_correspondance[i][chosen[i]].get()); } res.push_back(create_pred(old_pred, new_args)); unsigned pos=-1; do { pos++; if(pos==chosen.size()) { return res; } }while(chosen[pos]+1>=arg_correspondance[pos].size()); chosen[pos]++; } }
bool reduce_arg(expr* a, expr_ref& result) { sort* s = get_sort(a); if (!m_imp.is_fd(s)) { return false; } unsigned bv_size = get_bv_size(s); if (is_var(a)) { result = m.mk_var(to_var(a)->get_idx(), m_bv.mk_sort(bv_size)); return true; } SASSERT(is_app(a)); func_decl* f = to_app(a)->get_decl(); if (m_dt.is_constructor(f)) { unsigned idx = m_dt.get_constructor_idx(f); result = m_bv.mk_numeral(idx, bv_size); } else if (is_uninterp_const(a)) { func_decl* f_fresh; if (m_imp.m_enum2bv.find(f, f_fresh)) { result = m.mk_const(f_fresh); return true; } // create a fresh variable, add bounds constraints for it. unsigned nc = m_dt.get_datatype_num_constructors(s); result = m.mk_fresh_const(f->get_name().str().c_str(), m_bv.mk_sort(bv_size)); f_fresh = to_app(result)->get_decl(); if (!is_power_of_two(nc) || nc == 1) { m_imp.m_bounds.push_back(m_bv.mk_ule(result, m_bv.mk_numeral(nc-1, bv_size))); } expr_ref f_def(m); ptr_vector<func_decl> const& cs = *m_dt.get_datatype_constructors(s); f_def = m.mk_const(cs[nc-1]); for (unsigned i = nc - 1; i > 0; ) { --i; f_def = m.mk_ite(m.mk_eq(result, m_bv.mk_numeral(i,bv_size)), m.mk_const(cs[i]), f_def); } m_imp.m_enum2def.insert(f, f_def); m_imp.m_enum2bv.insert(f, f_fresh); m_imp.m_bv2enum.insert(f_fresh, f); m_imp.m_enum_consts.push_back(f); m_imp.m_enum_bvs.push_back(f_fresh); m_imp.m_enum_defs.push_back(f_def); } else { throw_non_fd(a); } ++m_imp.m_num_translated; return true; }
void operator()(app * n) { sort * s = get_sort(n); if (!m.is_bool(s) && !fu.is_float(s) && !fu.is_rm(s) && !bu.is_bv_sort(s) && !au.is_real(s)) throw found(); family_id fid = n->get_family_id(); if (fid == m.get_basic_family_id()) return; if (fid == fu.get_family_id() || fid == bu.get_family_id()) return; if (is_uninterp_const(n)) return; if (au.is_real(s) && au.is_numeral(n)) return; throw found(); }
void operator()(app * n) { family_id fid = n->get_family_id(); if (fid != null_family_id && fid != fu.get_family_id()) throw found(); sort * s = get_sort(n); if (fid == fu.get_family_id()) { if (!fu.is_float(s) && !fu.is_rm(s) && to_app(n)->get_decl_kind() != OP_FPA_TO_REAL) throw found(); } else if (fid == null_family_id) { if (!fu.is_float(s) && !fu.is_rm(s) && !m.is_bool(s)) throw found(); } else if (fid == m.get_basic_family_id()) return; else throw found(); }
br_status reduce_app(func_decl * f, unsigned num, expr * const * args, expr_ref & result, proof_ref & result_pr) { expr_ref a0(m), a1(m); expr_ref_vector _args(m); if (m.is_eq(f) && reduce_arg(args[0], a0) && reduce_arg(args[1], a1)) { result = m.mk_eq(a0, a1); return BR_DONE; } else if (m.is_distinct(f) && reduce_args(num, args, _args)) { result = m.mk_distinct(_args.size(), _args.c_ptr()); return BR_DONE; } else if (m_dt.is_recognizer(f) && reduce_arg(args[0], a0)) { unsigned idx = m_dt.get_recognizer_constructor_idx(f); a1 = m_bv.mk_numeral(rational(idx), get_sort(a0)); result = m.mk_eq(a0, a1); return BR_DONE; } else { check_for_fd(num, args); return BR_FAILED; } }
/*-------------------------------------------------------------------------* * Gather All Parameters *-------------------------------------------------------------------------*/ unsigned char get_parms() { unsigned char t; if((SUPER_OP) && (!(IS_ONE_PICKLINE))) { sd_prompt(&fld[0], 0); } sd_prompt(&fld[1], 0); sd_cursor(0, 11, 1); sd_clear(2); while(1) { t = get_pickline(); while (1) { t = get_code(); if (t == UP_CURSOR) break; while (1) { begin_work(); t = get_range(); commit_work(); if (t == UP_CURSOR) break; while (1) { t = get_sort(); if (t == UP_CURSOR) break; if (t == RETURN) return t; } /* end of get_sort */ } /* end of get_range */ } /* end of get_code */ } /* end of get_pickline */ } /* end of get_parms */
expr_ref mk_array_instantiation::create_pred(app*old_pred, expr_ref_vector& n_args) { expr_ref_vector new_args(m); new_args.append(n_args); new_args.append(getId(old_pred, n_args)); for(unsigned i=0;i<new_args.size();i++) { if(m_a.is_select(new_args[i].get())) { new_args[i] = mk_select_var(new_args[i].get()); } } sort_ref_vector new_sorts(m); for(unsigned i=0;i<new_args.size();i++) new_sorts.push_back(get_sort(new_args[i].get())); expr_ref res(m); func_decl_ref fun_decl(m); fun_decl = m.mk_func_decl(symbol((old_pred->get_decl()->get_name().str()+"!inst").c_str()), new_sorts.size(), new_sorts.c_ptr(), old_pred->get_decl()->get_range()); m_ctx.register_predicate(fun_decl, false); if(src_set->is_output_predicate(old_pred->get_decl())) dst->set_output_predicate(fun_decl); res=m.mk_app(fun_decl,new_args.size(), new_args.c_ptr()); return res; }