void rot_to_min(t_stack *a, t_stack *b, int *min_max, int rev) { while (a->top->value != min_max[0]) { if (a->top->value == min_max[1]) { do_op(a, b, "pb"); if (rev == 0) do_op(a, b, "rr"); else do_op(a, b, "rb"); min_max[1]--; } if (a->top && a->top->value == min_max[1]) continue ; if (rev == 1) do_op(a, b, "rra"); else if (rev == 0) do_op(a, b, "ra"); if (rev == -1) rev = 0; } if (is_sort(a)) return ; do_op(a, b, "pb"); }
func_decl * float_decl_plugin::mk_float_const_decl(decl_kind k, unsigned num_parameters, parameter const * parameters, unsigned arity, sort * const * domain, sort * range) { sort * s; if (num_parameters == 1 && parameters[0].is_ast() && is_sort(parameters[0].get_ast()) && is_float_sort(to_sort(parameters[0].get_ast()))) { s = to_sort(parameters[0].get_ast()); } else if (range != 0 && is_float_sort(range)) { s = range; } else { m_manager->raise_exception("sort of floating point constant was not specified"); } SASSERT(is_sort_of(s, m_family_id, FLOAT_SORT)); unsigned ebits = s->get_parameter(0).get_int(); unsigned sbits = s->get_parameter(1).get_int(); scoped_mpf val(m_fm); if (k == OP_FLOAT_NAN) { m_fm.mk_nan(ebits, sbits, val); SASSERT(m_fm.is_nan(val)); } else if (k == OP_FLOAT_MINUS_INF) { m_fm.mk_ninf(ebits, sbits, val); } else { SASSERT(k == OP_FLOAT_PLUS_INF); m_fm.mk_pinf(ebits, sbits, val); } return mk_value_decl(val); }
bool should_visit(expr const & e) { if (m_cache.find(e) != m_cache.end()) return false; m_cache.insert(e); expr type = m_tc.whnf(m_tc.infer(e)); return !m_tc.is_prop(type) && !is_sort(type); }
sort * dl_decl_plugin::mk_relation_sort( unsigned num_parameters, parameter const * parameters) { bool is_finite = true; rational r(1); for (unsigned i = 0; is_finite && i < num_parameters; ++i) { if (!parameters[i].is_ast() || !is_sort(parameters[i].get_ast())) { m_manager->raise_exception("expecting sort parameters"); return 0; } sort* s = to_sort(parameters[i].get_ast()); sort_size sz1 = s->get_num_elements(); if (sz1.is_finite()) { r *= rational(sz1.size(),rational::ui64()); } else { is_finite = false; } } sort_size sz; if (is_finite && r.is_uint64()) { sz = sort_size::mk_finite(r.get_uint64()); } else { sz = sort_size::mk_very_big(); } sort_info info(m_family_id, DL_RELATION_SORT, sz, num_parameters, parameters); return m_manager->mk_sort(symbol("Table"),info); }
expr collect(expr const & e) { return replace(e, [&](expr const & e, unsigned) { if (is_metavar(e)) { name const & id = mlocal_name(e); if (auto r = m_meta_to_param.find(id)) { return some_expr(*r); } else { expr type = m_ctx.infer(e); expr x = m_ctx.push_local("_x", type); m_meta_to_param.insert(id, x); m_meta_to_param_inv.insert(mlocal_name(x), e); m_params.push_back(x); return some_expr(x); } } else if (is_local(e)) { name const & id = mlocal_name(e); if (!m_found_local.contains(id)) { m_found_local.insert(id); m_params.push_back(e); } } else if (is_sort(e)) { return some_expr(update_sort(e, collect(sort_level(e)))); } else if (is_constant(e)) { return some_expr(update_constant(e, collect(const_levels(e)))); } return none_expr(); }); }
int test_sort_easy(t_listd **a, t_listd **b, t_listd *s) { int count; count = 0; while (!is_sort(a, b) && count <= 10000000) { if (*(int*)(s)->data == *(int*)(*a)->next->data && *(int*)(s)->next->data == *(int*)(*a)->data) sa(a, b); else if (*(int*)(s)->data == *((int*)(*a)->data)) { pb(a, b); ft_lstd_pop_front(&s, NULL); } else if (direction(*a, *(int*)(s)->data) || ft_lstd_size(*a) == 3) ra(a, b); else rra(a, b); count++; } while (*b && count <= 10000000) { pa(a, b); count++; } return (count); }
sort * datatype_decl_plugin::mk_sort(decl_kind k, unsigned num_parameters, parameter const * parameters) { try { if (k != DATATYPE_SORT) { throw invalid_datatype(); } buffer<bool, false, 256> found; unsigned num_types = read_int(num_parameters, parameters, 0, found); if (num_types == 0) { throw invalid_datatype(); } unsigned tid = read_int(num_parameters, parameters, 1, found); for (unsigned j = 0; j < num_types; j++) { read_symbol(num_parameters, parameters, 2 + 2*j, found); // type name unsigned o = read_int(num_parameters, parameters, 2 + 2*j + 1, found); unsigned num_constructors = read_int(num_parameters, parameters, o, found); if (num_constructors == 0) { throw invalid_datatype(); } for (unsigned s = 1; s <= num_constructors; s++) { unsigned k_i = read_int(num_parameters, parameters, o + s, found); read_symbol(num_parameters, parameters, k_i, found); // constructor name read_symbol(num_parameters, parameters, k_i + 1, found); // recognizer name unsigned num_accessors = read_int(num_parameters, parameters, k_i + 2, found); unsigned first_accessor = k_i+3; for (unsigned r = 0; r < num_accessors; r++) { read_symbol(num_parameters, parameters, first_accessor + 2*r, found); // accessor name parameter const & a_type = read(num_parameters, parameters, first_accessor + 2*r + 1, found); // accessort type if (!a_type.is_int() && !a_type.is_ast()) { throw invalid_datatype(); if (a_type.is_ast() && !is_sort(a_type.get_ast())) { throw invalid_datatype(); } } } } } // check if there is no garbage if (found.size() != num_parameters || std::find(found.begin(), found.end(), false) != found.end()) { throw invalid_datatype(); } if (!is_well_founded(parameters)) { m_manager->raise_exception("datatype is not well-founded"); return 0; } // compute datatype size sort_size ts = get_datatype_size(parameters); symbol const & tname = parameters[2+2*tid].get_symbol(); return m_manager->mk_sort(tname, sort_info(m_family_id, k, ts, num_parameters, parameters, true)); } catch (invalid_datatype) { m_manager->raise_exception("invalid datatype"); return 0; } }
expr get_ind_result_type(type_context_old & tctx, expr const & ind) { expr ind_type = tctx.relaxed_whnf(tctx.infer(ind)); type_context_old::tmp_locals locals(tctx); while (is_pi(ind_type)) { ind_type = instantiate(binding_body(ind_type), locals.push_local_from_binding(ind_type)); ind_type = tctx.relaxed_whnf(ind_type); } lean_assert(is_sort(ind_type)); return ind_type; }
sort * bvarray2uf_rewriter_cfg::get_index_sort(sort * s) { SASSERT(s->get_num_parameters() >= 2); unsigned total_width = 0; for (unsigned i = 0; i < s->get_num_parameters() - 1; i++) { parameter const & p = s->get_parameter(i); SASSERT(p.is_ast() && is_sort(to_sort(p.get_ast()))); SASSERT(m_bv_util.is_bv_sort(to_sort(p.get_ast()))); total_width += m_bv_util.get_bv_size(to_sort(p.get_ast())); } return m_bv_util.mk_sort(total_width); }
bool has_placeholder(expr const & e) { return (bool) find(e, [](expr const & e, unsigned) { // NOLINT if (is_placeholder(e)) return true; else if (is_sort(e)) return has_placeholder(sort_level(e)); else if (is_constant(e)) return std::any_of(const_levels(e).begin(), const_levels(e).end(), [](level const & l) { return has_placeholder(l); }); else return false; }); }
void resolve_a(t_lst **lsta, t_lst **lstb) { if (verif_swap_a(*lsta)) { options()->moves += swap(lsta); apply_opt_v(*lsta, *lstb); } if (is_sort(*lsta, *lstb) == 1) { options()->moves += push(lsta, lstb); apply_opt_v(*lsta, *lstb); } }
bool bvarray2uf_rewriter_cfg::is_bv_array(sort * s) { if (!m_array_util.is_array(s)) return false; SASSERT(s->get_num_parameters() >= 2); for (unsigned i = 0; i < s->get_num_parameters(); i++) { parameter const & p = s->get_parameter(i); if (!p.is_ast() || !is_sort(to_sort(p.get_ast())) || !m_bv_util.is_bv_sort(to_sort(p.get_ast()))) return false; } return true; }
void resolution(t_lst *lsta, t_lst *lstb) { if (verif_rotate_a(lsta) == 1) { rev_rotate(&lsta); apply_opt_v(lsta, lstb); } if (verif_rotate_a(lsta) == 2) { rotate(&lsta); apply_opt_v(lsta, lstb); } while (is_sort(lsta, lstb)) { while (a_is_sort(lsta) == 1) resolve_a(&lsta, &lstb); while (is_sort(lsta, lstb) == 2) resolve_b(&lsta, &lstb); remove_list(&lsta, &lstb); } ft_print_color(MAGENTA, "\n\nEnd:", 1); print_lst(lsta, lstb); }
static void handle_opts(t_stack *a, t_stack *b, char *s) { if (!g_interactive_opt) { ft_printf("%s", s); if (!is_sort(a) || !empty(b)) ft_printf(" "); else ft_printf("\n"); } if (g_count_opt >= 0) g_count_opt++; if (!g_interactive_opt && g_v_opt) print_stacks(a, b); }
int check_last_push(t_stack *a, t_stack *b) { int min_max[2]; if (is_sort(a)) { while (!empty(b)) do_op(a, b, "pa"); get_min_max(a, min_max, min_max + 1); while (a->top->value != min_max[0]) do_op(a, b, "ra"); } else return (0); return (1); }
bool dl_decl_plugin::is_rel_sort(sort* r, ptr_vector<sort>& sorts) { if (!is_sort_of(r, m_family_id, DL_RELATION_SORT)) { m_manager->raise_exception("expected relation sort"); return false; } unsigned n = r->get_num_parameters(); for (unsigned i = 0; i < n; ++i) { parameter const& p = r->get_parameter(i); if (!p.is_ast() || !is_sort(p.get_ast())) { m_manager->raise_exception("exptected sort parameter"); return false; } sorts.push_back(to_sort(p.get_ast())); } return true; }
bool has_idx_metavar(expr const & e) { if (!has_univ_metavar(e) && !has_expr_metavar(e)) return false; bool found = false; for_each(e, [&](expr const & e, unsigned) { if (found) return false; if (!has_univ_metavar(e) && !has_expr_metavar(e)) return false; if (is_idx_metavar(e)) found = true; else if (is_constant(e) && std::any_of(const_levels(e).begin(), const_levels(e).end(), has_idx_metauniv)) found = true; else if (is_sort(e) && has_idx_metauniv(sort_level(e))) found = true; return true; }); return found; }
int ps_optiop(t_ps *ps, int op_num, int op_max, int p) { int c; c = 0; if (op_num > op_max) return (0); if (op_num == op_max && !ps->b && is_sort(ps->a, 'a')) return (1); if (p != SA && p != SS && (c = ps_swap(ps, 'a'))) { if (ps_optiop(ps, 1 + op_num, op_max, c)) return (1); ps_swap(ps, 'a'); } return (sub_ps_optiop(ps, op_num, op_max, c)); }
static void handle_sort(t_heap **a_heap, t_heap **b_heap, t_opt *opt, int *sorted_tab) { int nbr_elem_lst; int i; i = 1; nbr_elem_lst = get_nbr_elem(a_heap); opt->step = get_step(nbr_elem_lst); while (is_sort(a_heap) != 1) { opt->split = get_pivot(sorted_tab, nbr_elem_lst, opt->step, i); push_step_to_b(opt, nbr_elem_lst, i); sort_step(a_heap, b_heap, opt); put_max_in_last_pos(opt); ++i; } }
name_set collect_univ_params(expr const & e, name_set const & ls) { if (!has_param_univ(e)) { return ls; } else { name_set r = ls; for_each(e, [&](expr const & e, unsigned) { if (!has_param_univ(e)) { return false; } else if (is_sort(e)) { collect_univ_params_core(sort_level(e), r); } else if (is_constant(e)) { for (auto const & l : const_levels(e)) collect_univ_params_core(l, r); } return true; }); return r; } }
/* If type of d is a proposition or return a type, we don't need to compile it. We can just generate (fun args, neutral_expr) This procedure returns true if type of d is a proposition or return a type, and store the dummy code above in */ bool compile_irrelevant(declaration const & d, buffer<procedure> & procs) { type_context ctx(m_env, transparency_mode::All); expr type = d.get_type(); type_context::tmp_locals locals(ctx); while (true) { type = ctx.relaxed_whnf(type); if (!is_pi(type)) break; expr local = locals.push_local_from_binding(type); type = instantiate(binding_body(type), local); } if (ctx.is_prop(type) || is_sort(type)) { expr r = locals.mk_lambda(mk_neutral_expr()); procs.emplace_back(d.get_name(), optional<pos_info>(), r); return true; } else { return false; } }
list<expr> get_coercions_from_to(type_checker & from_tc, type_checker & to_tc, expr const & from_type, expr const & to_type, constraint_seq & cs, bool lift_coe) { constraint_seq new_cs; environment const & env = to_tc.env(); expr whnf_from_type = from_tc.whnf(from_type, new_cs); expr whnf_to_type = to_tc.whnf(to_type, new_cs); if (lift_coe && is_pi(whnf_from_type)) { // Try to lift coercions. // The idea is to convert a coercion from A to B, into a coercion from D->A to D->B if (!is_pi(whnf_to_type)) return list<expr>(); // failed if (!from_tc.is_def_eq(binding_domain(whnf_from_type), binding_domain(whnf_to_type), justification(), new_cs)) return list<expr>(); // failed, the domains must be definitionally equal expr x = mk_local(mk_fresh_name(), "x", binding_domain(whnf_from_type), binder_info()); expr A = instantiate(binding_body(whnf_from_type), x); expr B = instantiate(binding_body(whnf_to_type), x); list<expr> coe = get_coercions_from_to(from_tc, to_tc, A, B, new_cs, lift_coe); if (coe) { cs += new_cs; // Remark: each coercion c in coe is a function from A to B // We create a new list: (fun (f : D -> A) (x : D), c (f x)) expr f = mk_local(mk_fresh_name(), "f", whnf_from_type, binder_info()); expr fx = mk_app(f, x); return map(coe, [&](expr const & c) { return Fun(f, Fun(x, mk_app(c, fx))); }); } else { return list<expr>(); } } else { expr const & fn = get_app_fn(whnf_to_type); list<expr> r; if (is_constant(fn)) { r = get_coercions(env, whnf_from_type, const_name(fn)); } else if (is_pi(whnf_to_type)) { r = get_coercions_to_fun(env, whnf_from_type); } else if (is_sort(whnf_to_type)) { r = get_coercions_to_sort(env, whnf_from_type); } if (r) cs += new_cs; return r; } }
void resolve(t_stack *stack, char **argv) { get_list(stack, argv); if (stack->number_in_a == 2) sa(stack, 1); while (stack->number_in_b || !is_sort(stack)) { if (stack->number_in_a < 4) quicky_sort(stack); else naive_algo(stack); } if (stack->number_of_moves) ft_printf("Moves required : [%[[FG_GRE,SP_RST]d]\n", stack->n_moves); if (stack->end_status) print_stack(&stack->a_begin, stack->number_in_a, 'a', stack->color); if (!stack->no_command) print_command(stack); free_stack(stack); }
void sort(t_heap **a_heap, t_heap **b_heap, t_opt *opt, int *sorted) { int nbr_elem; nbr_elem = get_nbr_elem(a_heap); if (is_sort(a_heap) != 1) { if (nbr_elem == 2) { swap_two_first_elem(a_heap); print_ft("sa", opt); } else if (nbr_elem == 3) if_three_elem(a_heap, opt); else if (nbr_elem < 25) select_sort(a_heap, b_heap, opt); else handle_sort(a_heap, b_heap, opt, sorted); } }
void sort_int_tab(int *tab, unsigned int size) { int buf; unsigned int i; buf = 0; while (!is_sort(tab, size)) { i = 0; while (i < (size - 1)) { if (tab[i] > tab[i + 1]) { buf = tab[i]; tab[i] = tab[i + 1]; tab[i + 1] = buf; } i++; } } }
sort * array_decl_plugin::mk_sort(decl_kind k, unsigned num_parameters, parameter const * parameters) { if (k == _SET_SORT) { if (num_parameters != 1) { m_manager->raise_exception("invalid array sort definition, invalid number of parameters"); return 0; } parameter params[2] = { parameters[0], parameter(m_manager->mk_bool_sort()) }; return mk_sort(ARRAY_SORT, 2, params); } SASSERT(k == ARRAY_SORT); if (num_parameters < 2) { m_manager->raise_exception("invalid array sort definition, invalid number of parameters"); return 0; } for (unsigned i = 0; i < num_parameters; i++) { if (!parameters[i].is_ast() || !is_sort(parameters[i].get_ast())) { m_manager->raise_exception("invalid array sort definition, parameter is not a sort"); return 0; } } sort * range = to_sort(parameters[num_parameters - 1].get_ast()); TRACE("array_decl_plugin_bug", tout << mk_pp(range, *m_manager) << "\n";);
void decl_collector::collect_deps(sort* s, sort_set& set) { if (set.contains(s)) return; set.insert(s); if (s->is_sort_of(m_dt_util.get_family_id(), DATATYPE_SORT)) { unsigned num_sorts = m_dt_util.get_datatype_num_parameter_sorts(s); for (unsigned i = 0; i < num_sorts; ++i) { set.insert(m_dt_util.get_datatype_parameter_sort(s, i)); } unsigned num_cnstr = m_dt_util.get_datatype_num_constructors(s); for (unsigned i = 0; i < num_cnstr; i++) { func_decl * cnstr = m_dt_util.get_datatype_constructors(s)->get(i); set.insert(cnstr->get_range()); for (unsigned j = 0; j < cnstr->get_arity(); ++j) set.insert(cnstr->get_domain(j)); } } for (unsigned i = s->get_num_parameters(); i-- > 0; ) { parameter const& p = s->get_parameter(i); if (p.is_ast() && is_sort(p.get_ast())) { set.insert(to_sort(p.get_ast())); } } }
func_decl * fpa_decl_plugin::mk_float_const_decl(decl_kind k, unsigned num_parameters, parameter const * parameters, unsigned arity, sort * const * domain, sort * range) { sort * s = nullptr; if (num_parameters == 1 && parameters[0].is_ast() && is_sort(parameters[0].get_ast()) && is_float_sort(to_sort(parameters[0].get_ast()))) { s = to_sort(parameters[0].get_ast()); } else if (num_parameters == 2 && parameters[0].is_int() && parameters[1].is_int()) { s = mk_float_sort(parameters[0].get_int(), parameters[1].get_int()); } else if (range != nullptr && is_float_sort(range)) { s = range; } else { m_manager->raise_exception("sort of floating point constant was not specified"); UNREACHABLE(); } SASSERT(is_sort_of(s, m_family_id, FLOATING_POINT_SORT)); unsigned ebits = s->get_parameter(0).get_int(); unsigned sbits = s->get_parameter(1).get_int(); scoped_mpf val(m_fm); switch (k) { case OP_FPA_NAN: m_fm.mk_nan(ebits, sbits, val); SASSERT(m_fm.is_nan(val)); break; case OP_FPA_MINUS_INF: m_fm.mk_ninf(ebits, sbits, val); break; case OP_FPA_PLUS_INF: m_fm.mk_pinf(ebits, sbits, val); break; case OP_FPA_MINUS_ZERO: m_fm.mk_nzero(ebits, sbits, val); break; case OP_FPA_PLUS_ZERO: m_fm.mk_pzero(ebits, sbits, val); break; } return mk_numeral_decl(val); }
Z3_sort Z3_API Z3_get_relation_column(Z3_context c, Z3_sort s, unsigned col) { Z3_TRY; LOG_Z3_get_relation_column(c, s, col); RESET_ERROR_CODE(); sort * r = to_sort(s); if (Z3_get_sort_kind(c, s) != Z3_RELATION_SORT) { SET_ERROR_CODE(Z3_INVALID_ARG); RETURN_Z3(0); } if (col >= r->get_num_parameters()) { SET_ERROR_CODE(Z3_IOB); RETURN_Z3(0); } parameter const& p = r->get_parameter(col); if (!p.is_ast() || !is_sort(p.get_ast())) { UNREACHABLE(); warning_msg("Sort parameter expected at %d", col); SET_ERROR_CODE(Z3_INTERNAL_FATAL); RETURN_Z3(0); } Z3_sort res = of_sort(to_sort(p.get_ast())); RETURN_Z3(res); Z3_CATCH_RETURN(0); }
sort * bvarray2uf_rewriter_cfg::get_value_sort(sort * s) { SASSERT(s->get_num_parameters() >= 2); parameter const & p = s->get_parameter(s->get_num_parameters() - 1); SASSERT(p.is_ast() && is_sort(to_sort(p.get_ast()))); return to_sort(p.get_ast()); }