chore(library/definitional,frontends/lean): remove decreasing macro
This commit is contained in:
parent
8c36cd04a3
commit
f75de2e950
7 changed files with 1 additions and 92 deletions
|
|
@ -715,7 +715,6 @@ parse_table init_nud_table() {
|
|||
parse_table init_led_table() {
|
||||
parse_table r(false);
|
||||
r = r.add({transition("->", mk_expr_action(get_arrow_prec()-1))}, mk_arrow(Var(1), Var(1)));
|
||||
r = r.add({transition("<d", mk_expr_action(get_decreasing_prec()))}, mk_decreasing(Var(1), Var(0)));
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1143,40 +1143,6 @@ expr old_elaborator::visit_inaccessible(expr const & e, constraint_seq & cs) {
|
|||
return mk_inaccessible(visit(get_annotation_arg(e), cs));
|
||||
}
|
||||
|
||||
expr old_elaborator::visit_decreasing(expr const & e, constraint_seq & cs) {
|
||||
if (!m_equation_lhs)
|
||||
throw_elaborator_exception("invalid occurrence of 'decreasing' annotation, it must only occur in "
|
||||
"the right-hand-side of recursive equations", e);
|
||||
if (!m_equation_R)
|
||||
throw_elaborator_exception("invalid occurrence of 'decreasing' annotation, it can only be used when "
|
||||
"recursive equations are being defined by well-founded recursion", e);
|
||||
expr const & lhs_fn = get_app_fn(*m_equation_lhs);
|
||||
if (get_app_fn(decreasing_app(e)) != lhs_fn)
|
||||
throw_elaborator_exception("invalid occurrence of 'decreasing' annotation, expression must be an "
|
||||
"application of the recursive function being defined", e);
|
||||
expr dec_app = visit(decreasing_app(e), cs);
|
||||
expr dec_proof = visit(decreasing_proof(e), cs);
|
||||
expr f_type = mlocal_type(get_app_fn(*m_equation_lhs));
|
||||
buffer<expr> ts;
|
||||
old_type_checker & tc = *m_tc;
|
||||
to_telescope(tc, f_type, ts, optional<binder_info>(), cs);
|
||||
buffer<expr> old_args;
|
||||
buffer<expr> new_args;
|
||||
get_app_args(*m_equation_lhs, old_args);
|
||||
get_app_args(dec_app, new_args);
|
||||
if (new_args.size() != old_args.size() || new_args.size() != ts.size())
|
||||
throw_elaborator_exception("invalid recursive application, mistmatch in the number of arguments", e);
|
||||
expr old_tuple = mk_sigma_mk(tc, ts, old_args, cs);
|
||||
expr new_tuple = mk_sigma_mk(tc, ts, new_args, cs);
|
||||
expr expected_dec_proof_type = mk_app(mk_app(*m_equation_R, new_tuple, e.get_tag()), old_tuple, e.get_tag());
|
||||
expr dec_proof_type = infer_type(dec_proof, cs);
|
||||
justification j = mk_type_mismatch_jst(dec_proof, dec_proof_type, expected_dec_proof_type, decreasing_proof(e));
|
||||
auto new_dec_proof_cs = ensure_has_type(dec_proof, dec_proof_type, expected_dec_proof_type, j);
|
||||
dec_proof = new_dec_proof_cs.first;
|
||||
cs += new_dec_proof_cs.second;
|
||||
return mk_decreasing(dec_app, dec_proof);
|
||||
}
|
||||
|
||||
bool old_elaborator::is_structure_like(expr const & S) {
|
||||
expr const & I = get_app_fn(S);
|
||||
return is_constant(I) && ::lean::is_structure_like(env(), const_name(I));
|
||||
|
|
@ -1385,8 +1351,6 @@ expr old_elaborator::visit_core(expr const & e, constraint_seq & cs) {
|
|||
return visit_equation(e, cs);
|
||||
} else if (is_inaccessible(e)) {
|
||||
return visit_inaccessible(e, cs);
|
||||
} else if (is_decreasing(e)) {
|
||||
return visit_decreasing(e, cs);
|
||||
} else if (is_structure_instance(e)) {
|
||||
return visit_structure_instance(e, cs);
|
||||
} else if (is_checkpoint_annotation(e)) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ class old_elaborator {
|
|||
// and inaccessible expressions are allowed
|
||||
bool m_in_equation_lhs;
|
||||
// if m_equation_lhs is not none, we are processing the right-hand-side of an equation
|
||||
// and decreasing expressions are allowed
|
||||
optional<expr> m_equation_lhs;
|
||||
// if m_equation_R is not none when elaborator is processing recursive equation using the well-founded relation R.
|
||||
optional<expr> m_equation_R;
|
||||
|
|
@ -162,7 +161,6 @@ class old_elaborator {
|
|||
expr visit_equations(expr const & eqns, constraint_seq & cs);
|
||||
expr visit_equation(expr const & e, constraint_seq & cs);
|
||||
expr visit_inaccessible(expr const & e, constraint_seq & cs);
|
||||
expr visit_decreasing(expr const & e, constraint_seq & cs);
|
||||
constraint mk_equations_cnstr(expr const & m, expr const & eqns);
|
||||
|
||||
bool is_structure_like(expr const & S);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ Author: Leonardo de Moura
|
|||
|
||||
namespace lean {
|
||||
static unsigned g_arrow_prec = 25;
|
||||
static unsigned g_decreasing_prec = 100;
|
||||
static unsigned g_max_prec = 1024;
|
||||
static unsigned g_Max_prec = 1024*1024;
|
||||
static unsigned g_plus_prec = 65;
|
||||
|
|
@ -20,7 +19,6 @@ static unsigned g_cup_prec = 60;
|
|||
unsigned get_max_prec() { return g_max_prec; }
|
||||
unsigned get_Max_prec() { return g_Max_prec; }
|
||||
unsigned get_arrow_prec() { return g_arrow_prec; }
|
||||
unsigned get_decreasing_prec() { return g_decreasing_prec; }
|
||||
static token_table update(token_table const & s, char const * token, char const * val,
|
||||
optional<unsigned> expr_prec, optional<unsigned> tac_prec) {
|
||||
lean_assert(expr_prec || tac_prec);
|
||||
|
|
@ -85,7 +83,6 @@ static char const * g_forall_unicode = "\u2200";
|
|||
static char const * g_arrow_unicode = "\u2192";
|
||||
static char const * g_cup = "\u2294";
|
||||
static char const * g_qed_unicode = "∎";
|
||||
static char const * g_decreasing_unicode = "↓";
|
||||
|
||||
void init_token_table(token_table & t) {
|
||||
pair<char const *, unsigned> builtin[] =
|
||||
|
|
@ -102,7 +99,7 @@ void init_token_table(token_table & t) {
|
|||
{"@@", g_max_prec}, {"@", g_max_prec},
|
||||
{"sorry", g_max_prec}, {"+", g_plus_prec}, {g_cup, g_cup_prec}, {"->", g_arrow_prec}, {"<-", 0},
|
||||
{"?(", g_max_prec}, {"⌞", g_max_prec}, {"⌟", 0}, {"match", 0},
|
||||
{"<d", g_decreasing_prec}, {"renaming", 0}, {"extends", 0}, {nullptr, 0}};
|
||||
{"renaming", 0}, {"extends", 0}, {nullptr, 0}};
|
||||
|
||||
char const * commands[] =
|
||||
{"theorem", "axiom", "axioms", "variable", "protected", "private", "reveal",
|
||||
|
|
@ -154,7 +151,6 @@ void init_token_table(token_table & t) {
|
|||
}
|
||||
t = add_token(t, g_arrow_unicode, "->", get_arrow_prec());
|
||||
t = add_token(t, "←", "<-", 0);
|
||||
t = add_token(t, g_decreasing_unicode, "<d", get_decreasing_prec());
|
||||
|
||||
auto it4 = cmd_aliases;
|
||||
while (it4->first) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ unsigned get_max_prec();
|
|||
// Internal maximum precedence used for @@, @ and ! operators
|
||||
unsigned get_Max_prec();
|
||||
unsigned get_arrow_prec();
|
||||
unsigned get_decreasing_prec();
|
||||
class token_info {
|
||||
bool m_command;
|
||||
name m_token;
|
||||
|
|
|
|||
|
|
@ -33,13 +33,11 @@ namespace lean {
|
|||
static name * g_equations_name = nullptr;
|
||||
static name * g_equation_name = nullptr;
|
||||
static name * g_no_equation_name = nullptr;
|
||||
static name * g_decreasing_name = nullptr;
|
||||
static name * g_inaccessible_name = nullptr;
|
||||
static name * g_equations_result_name = nullptr;
|
||||
static std::string * g_equations_opcode = nullptr;
|
||||
static std::string * g_equation_opcode = nullptr;
|
||||
static std::string * g_no_equation_opcode = nullptr;
|
||||
static std::string * g_decreasing_opcode = nullptr;
|
||||
static std::string * g_equations_result_opcode = nullptr;
|
||||
|
||||
[[ noreturn ]] static void throw_eqs_ex() { throw exception("unexpected occurrence of 'equations' expression"); }
|
||||
|
|
@ -80,28 +78,8 @@ public:
|
|||
virtual void write(serializer & s) const { s.write_string(*g_no_equation_opcode); }
|
||||
};
|
||||
|
||||
class decreasing_macro_cell : public macro_definition_cell {
|
||||
void check_macro(expr const & m) const {
|
||||
if (!is_macro(m) || macro_num_args(m) != 2)
|
||||
throw exception("invalid 'decreasing' expression, incorrect number of arguments");
|
||||
}
|
||||
public:
|
||||
decreasing_macro_cell() {}
|
||||
virtual name get_name() const { return *g_decreasing_name; }
|
||||
virtual expr check_type(expr const & m, abstract_type_context & ctx, bool infer_only) const {
|
||||
check_macro(m);
|
||||
return ctx.check(macro_arg(m, 0), infer_only);
|
||||
}
|
||||
virtual optional<expr> expand(expr const & m, abstract_type_context &) const {
|
||||
check_macro(m);
|
||||
return some_expr(macro_arg(m, 0));
|
||||
}
|
||||
virtual void write(serializer & s) const { s.write_string(*g_decreasing_opcode); }
|
||||
};
|
||||
|
||||
static macro_definition * g_equation = nullptr;
|
||||
static macro_definition * g_no_equation = nullptr;
|
||||
static macro_definition * g_decreasing = nullptr;
|
||||
|
||||
bool is_equation(expr const & e) { return is_macro(e) && macro_def(e) == *g_equation; }
|
||||
|
||||
|
|
@ -128,14 +106,6 @@ bool is_lambda_no_equation(expr const & e) {
|
|||
return is_no_equation(e);
|
||||
}
|
||||
|
||||
bool is_decreasing(expr const & e) { return is_macro(e) && macro_def(e) == *g_decreasing; }
|
||||
expr const & decreasing_app(expr const & e) { lean_assert(is_decreasing(e)); return macro_arg(e, 0); }
|
||||
expr const & decreasing_proof(expr const & e) { lean_assert(is_decreasing(e)); return macro_arg(e, 1); }
|
||||
expr mk_decreasing(expr const & t, expr const & H) {
|
||||
expr args[2] = { t, H };
|
||||
return mk_macro(*g_decreasing, 2, args);
|
||||
}
|
||||
|
||||
bool is_equations(expr const & e) { return is_macro(e) && macro_def(e).get_name() == *g_equations_name; }
|
||||
bool is_wf_equations_core(expr const & e) {
|
||||
lean_assert(is_equations(e));
|
||||
|
|
@ -230,17 +200,14 @@ void initialize_equations() {
|
|||
g_equations_name = new name("equations");
|
||||
g_equation_name = new name("equation");
|
||||
g_no_equation_name = new name("no_equation");
|
||||
g_decreasing_name = new name("decreasing");
|
||||
g_inaccessible_name = new name("innaccessible");
|
||||
g_equations_result_name = new name("equations_result");
|
||||
g_equation = new macro_definition(new equation_macro_cell());
|
||||
g_no_equation = new macro_definition(new no_equation_macro_cell());
|
||||
g_decreasing = new macro_definition(new decreasing_macro_cell());
|
||||
g_equations_result = new macro_definition(new equations_result_macro_cell());
|
||||
g_equations_opcode = new std::string("Eqns");
|
||||
g_equation_opcode = new std::string("Eqn");
|
||||
g_no_equation_opcode = new std::string("NEqn");
|
||||
g_decreasing_opcode = new std::string("Decr");
|
||||
g_equations_result_opcode = new std::string("EqnR");
|
||||
register_annotation(*g_inaccessible_name);
|
||||
register_macro_deserializer(*g_equations_opcode,
|
||||
|
|
@ -269,12 +236,6 @@ void initialize_equations() {
|
|||
throw corrupted_stream_exception();
|
||||
return mk_no_equation();
|
||||
});
|
||||
register_macro_deserializer(*g_decreasing_opcode,
|
||||
[](deserializer &, unsigned num, expr const * args) {
|
||||
if (num != 2)
|
||||
throw corrupted_stream_exception();
|
||||
return mk_decreasing(args[0], args[1]);
|
||||
});
|
||||
register_macro_deserializer(*g_equations_result_opcode,
|
||||
[](deserializer &, unsigned num, expr const * args) {
|
||||
return mk_equations_result(num, args);
|
||||
|
|
@ -286,16 +247,13 @@ void finalize_equations() {
|
|||
delete g_equation_opcode;
|
||||
delete g_no_equation_opcode;
|
||||
delete g_equations_opcode;
|
||||
delete g_decreasing_opcode;
|
||||
delete g_equations_result;
|
||||
delete g_equation;
|
||||
delete g_no_equation;
|
||||
delete g_decreasing;
|
||||
delete g_equations_result_name;
|
||||
delete g_equations_name;
|
||||
delete g_equation_name;
|
||||
delete g_no_equation_name;
|
||||
delete g_decreasing_name;
|
||||
delete g_inaccessible_name;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,11 +22,6 @@ bool is_lambda_equation(expr const & e);
|
|||
expr mk_no_equation();
|
||||
bool is_no_equation(expr const & e);
|
||||
|
||||
bool is_decreasing(expr const & e);
|
||||
expr const & decreasing_app(expr const & e);
|
||||
expr const & decreasing_proof(expr const & e);
|
||||
expr mk_decreasing(expr const & t, expr const & H);
|
||||
|
||||
bool is_equations(expr const & e);
|
||||
bool is_wf_equations(expr const & e);
|
||||
unsigned equations_size(expr const & e);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue