feat(frontends/lean): remove [class] annotation and 'class' command, they are redundant, we only need [instance] and 'instance'
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
112353861c
commit
08465f049a
8 changed files with 7 additions and 62 deletions
|
@ -209,8 +209,6 @@ theorem exists_unique_elim {A : Type} {p : A → Bool} {b : Bool} (H2 : ∃! x,
|
||||||
inductive inhabited (A : Type) : Bool :=
|
inductive inhabited (A : Type) : Bool :=
|
||||||
| inhabited_intro : A → inhabited A
|
| inhabited_intro : A → inhabited A
|
||||||
|
|
||||||
class inhabited
|
|
||||||
|
|
||||||
theorem inhabited_elim {A : Type} {B : Bool} (H1 : inhabited A) (H2 : A → B) : B
|
theorem inhabited_elim {A : Type} {B : Bool} (H1 : inhabited A) (H2 : A → B) : B
|
||||||
:= inhabited_rec H2 H1
|
:= inhabited_rec H2 H1
|
||||||
|
|
||||||
|
|
|
@ -12,22 +12,15 @@ Author: Leonardo de Moura
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
struct class_entry {
|
struct class_entry {
|
||||||
enum class kind { NewClass, NewInstance };
|
|
||||||
kind m_kind;
|
|
||||||
name m_class;
|
name m_class;
|
||||||
name m_instance;
|
name m_instance;
|
||||||
class_entry() {}
|
class_entry() {}
|
||||||
class_entry(name const & c):m_kind(kind::NewClass), m_class(c) {}
|
class_entry(name const & c, name const & i):m_class(c), m_instance(i) {}
|
||||||
class_entry(name const & c, name const & i):m_kind(kind::NewInstance), m_class(c), m_instance(i) {}
|
|
||||||
bool is_new_class() const { return m_kind == kind::NewClass; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct class_state {
|
struct class_state {
|
||||||
typedef rb_map<name, list<name>, name_quick_cmp> class_instances;
|
typedef rb_map<name, list<name>, name_quick_cmp> class_instances;
|
||||||
class_instances m_instances;
|
class_instances m_instances;
|
||||||
void add_class(name const & c) {
|
|
||||||
m_instances.insert(c, list<name>());
|
|
||||||
}
|
|
||||||
void add_instance(name const & c, name const & i) {
|
void add_instance(name const & c, name const & i) {
|
||||||
auto it = m_instances.find(c);
|
auto it = m_instances.find(c);
|
||||||
if (!it)
|
if (!it)
|
||||||
|
@ -41,11 +34,7 @@ struct class_config {
|
||||||
typedef class_state state;
|
typedef class_state state;
|
||||||
typedef class_entry entry;
|
typedef class_entry entry;
|
||||||
static void add_entry(environment const &, io_state const &, state & s, entry const & e) {
|
static void add_entry(environment const &, io_state const &, state & s, entry const & e) {
|
||||||
if (e.m_kind == class_entry::kind::NewClass) {
|
s.add_instance(e.m_class, e.m_instance);
|
||||||
s.add_class(e.m_class);
|
|
||||||
} else {
|
|
||||||
s.add_instance(e.m_class, e.m_instance);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
static name const & get_class_name() {
|
static name const & get_class_name() {
|
||||||
static name g_class_name("class");
|
static name g_class_name("class");
|
||||||
|
@ -56,19 +45,11 @@ struct class_config {
|
||||||
return g_key;
|
return g_key;
|
||||||
}
|
}
|
||||||
static void write_entry(serializer & s, entry const & e) {
|
static void write_entry(serializer & s, entry const & e) {
|
||||||
s.write_char(static_cast<char>(e.m_kind)); // NOLINT
|
s << e.m_class << e.m_instance;
|
||||||
if (e.is_new_class())
|
|
||||||
s << e.m_class;
|
|
||||||
else
|
|
||||||
s << e.m_class << e.m_instance;
|
|
||||||
}
|
}
|
||||||
static entry read_entry(deserializer & d) {
|
static entry read_entry(deserializer & d) {
|
||||||
entry e;
|
entry e;
|
||||||
e.m_kind = static_cast<class_entry::kind>(d.read_char());
|
d >> e.m_class >> e.m_instance;
|
||||||
if (e.is_new_class())
|
|
||||||
d >> e.m_class;
|
|
||||||
else
|
|
||||||
d >> e.m_class >> e.m_instance;
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -76,16 +57,6 @@ struct class_config {
|
||||||
template class scoped_ext<class_config>;
|
template class scoped_ext<class_config>;
|
||||||
typedef scoped_ext<class_config> class_ext;
|
typedef scoped_ext<class_config> class_ext;
|
||||||
|
|
||||||
environment add_class(environment const & env, name const & n) {
|
|
||||||
declaration d = env.get(n);
|
|
||||||
if (d.is_definition() && !d.is_opaque())
|
|
||||||
throw exception(sstream() << "invalid class declaration, '" << n << "' is not an opaque definition");
|
|
||||||
class_state const & s = class_ext::get_state(env);
|
|
||||||
if (s.m_instances.contains(n))
|
|
||||||
throw exception(sstream() << "class '" << n << "' has already been declared");
|
|
||||||
return class_ext::add_entry(env, get_dummy_ios(), class_entry(n));
|
|
||||||
}
|
|
||||||
|
|
||||||
environment add_instance(environment const & env, name const & n) {
|
environment add_instance(environment const & env, name const & n) {
|
||||||
declaration d = env.get(n);
|
declaration d = env.get(n);
|
||||||
expr type = d.get_type();
|
expr type = d.get_type();
|
||||||
|
@ -94,6 +65,9 @@ environment add_instance(environment const & env, name const & n) {
|
||||||
if (!is_constant(get_app_fn(type)))
|
if (!is_constant(get_app_fn(type)))
|
||||||
throw exception(sstream() << "invalid class instance declaration '" << n << "' resultant type must be a class");
|
throw exception(sstream() << "invalid class instance declaration '" << n << "' resultant type must be a class");
|
||||||
name const & c = const_name(get_app_fn(type));
|
name const & c = const_name(get_app_fn(type));
|
||||||
|
declaration c_d = env.get(c);
|
||||||
|
if (c_d.is_definition() && !c_d.is_opaque())
|
||||||
|
throw exception(sstream() << "invalid class instance declaration, '" << c << "' is not a valid class, it is a transparent definition");
|
||||||
return class_ext::add_entry(env, get_dummy_ios(), class_entry(c, n));
|
return class_ext::add_entry(env, get_dummy_ios(), class_entry(c, n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,14 +84,6 @@ list<name> get_class_instances(environment const & env, name const & c) {
|
||||||
return list<name>();
|
return list<name>();
|
||||||
}
|
}
|
||||||
|
|
||||||
environment add_class_cmd(parser & p) {
|
|
||||||
auto pos = p.pos();
|
|
||||||
name c = p.check_id_next("invalid 'class' declaration, identifier expected");
|
|
||||||
expr e = p.id_to_expr(c, pos);
|
|
||||||
if (!is_constant(e)) throw parser_error(sstream() << "invalid 'class' declaration, '" << c << "' is not a constant", pos);
|
|
||||||
return add_class(p.env(), const_name(e));
|
|
||||||
}
|
|
||||||
|
|
||||||
environment add_instance_cmd(parser & p) {
|
environment add_instance_cmd(parser & p) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
environment env = p.env();
|
environment env = p.env();
|
||||||
|
@ -136,7 +102,6 @@ environment add_instance_cmd(parser & p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_class_cmds(cmd_table & r) {
|
void register_class_cmds(cmd_table & r) {
|
||||||
add_cmd(r, cmd_info("class", "add a new class", add_class_cmd));
|
|
||||||
add_cmd(r, cmd_info("instance", "add a new instance", add_instance_cmd));
|
add_cmd(r, cmd_info("instance", "add a new instance", add_instance_cmd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@ Author: Leonardo de Moura
|
||||||
#include "frontends/lean/cmd_table.h"
|
#include "frontends/lean/cmd_table.h"
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
/** \brief Add a new 'class' to the environment. */
|
|
||||||
environment add_class(environment const & env, name const & n);
|
|
||||||
/** \brief Add a new 'class instance' to the environment. */
|
/** \brief Add a new 'class instance' to the environment. */
|
||||||
environment add_instance(environment const & env, name const & n);
|
environment add_instance(environment const & env, name const & n);
|
||||||
/** \brief Return true iff \c c was declared with \c add_class . */
|
/** \brief Return true iff \c c was declared with \c add_class . */
|
||||||
|
|
|
@ -25,7 +25,6 @@ static name g_assign(":=");
|
||||||
static name g_private("[private]");
|
static name g_private("[private]");
|
||||||
static name g_inline("[inline]");
|
static name g_inline("[inline]");
|
||||||
static name g_instance("[instance]");
|
static name g_instance("[instance]");
|
||||||
static name g_class("[class]");
|
|
||||||
|
|
||||||
environment universe_cmd(parser & p) {
|
environment universe_cmd(parser & p) {
|
||||||
name n = p.check_id_next("invalid universe declaration, identifier expected");
|
name n = p.check_id_next("invalid universe declaration, identifier expected");
|
||||||
|
@ -168,12 +167,10 @@ struct decl_modifiers {
|
||||||
bool m_is_private;
|
bool m_is_private;
|
||||||
bool m_is_opaque;
|
bool m_is_opaque;
|
||||||
bool m_is_instance;
|
bool m_is_instance;
|
||||||
bool m_is_class;
|
|
||||||
decl_modifiers() {
|
decl_modifiers() {
|
||||||
m_is_private = false;
|
m_is_private = false;
|
||||||
m_is_opaque = true;
|
m_is_opaque = true;
|
||||||
m_is_instance = false;
|
m_is_instance = false;
|
||||||
m_is_class = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse(parser & p) {
|
void parse(parser & p) {
|
||||||
|
@ -187,9 +184,6 @@ struct decl_modifiers {
|
||||||
} else if (p.curr_is_token(g_instance)) {
|
} else if (p.curr_is_token(g_instance)) {
|
||||||
m_is_instance = true;
|
m_is_instance = true;
|
||||||
p.next();
|
p.next();
|
||||||
} else if (p.curr_is_token(g_class)) {
|
|
||||||
m_is_class = true;
|
|
||||||
p.next();
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -285,8 +279,6 @@ environment definition_cmd_core(parser & p, bool is_theorem, bool _is_opaque) {
|
||||||
std::tie(type, value, new_ls) = p.elaborate_definition(n, type, value);
|
std::tie(type, value, new_ls) = p.elaborate_definition(n, type, value);
|
||||||
env = module::add(env, check(env, mk_definition(env, real_n, append(ls, new_ls), type, value, modifiers.m_is_opaque)));
|
env = module::add(env, check(env, mk_definition(env, real_n, append(ls, new_ls), type, value, modifiers.m_is_opaque)));
|
||||||
}
|
}
|
||||||
if (modifiers.m_is_class)
|
|
||||||
env = add_class(env, real_n);
|
|
||||||
if (modifiers.m_is_instance)
|
if (modifiers.m_is_instance)
|
||||||
env = add_instance(env, real_n);
|
env = add_instance(env, real_n);
|
||||||
return env;
|
return env;
|
||||||
|
|
|
@ -59,8 +59,6 @@ inductive not_zero (x : nat) : Bool :=
|
||||||
theorem not_zero_not_is_zero {x : nat} (H : not_zero x) : ¬ is_zero x
|
theorem not_zero_not_is_zero {x : nat} (H : not_zero x) : ¬ is_zero x
|
||||||
:= not_zero_rec (λ H1, H1) H
|
:= not_zero_rec (λ H1, H1) H
|
||||||
|
|
||||||
class not_zero
|
|
||||||
|
|
||||||
theorem not_zero_add_right [instance] (x y : nat) (H : not_zero y) : not_zero (x + y)
|
theorem not_zero_add_right [instance] (x y : nat) (H : not_zero y) : not_zero (x + y)
|
||||||
:= not_zero_intro (not_zero_add x y (not_zero_not_is_zero H))
|
:= not_zero_intro (not_zero_add x y (not_zero_not_is_zero H))
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ namespace algebra
|
||||||
inductive mul_struct (A : Type) : Type :=
|
inductive mul_struct (A : Type) : Type :=
|
||||||
| mk_mul_struct : (A → A → A) → mul_struct A
|
| mk_mul_struct : (A → A → A) → mul_struct A
|
||||||
|
|
||||||
class mul_struct
|
|
||||||
|
|
||||||
definition mul [inline] {A : Type} {s : mul_struct A} (a b : A)
|
definition mul [inline] {A : Type} {s : mul_struct A} (a b : A)
|
||||||
:= mul_struct_rec (λ f, f) s a b
|
:= mul_struct_rec (λ f, f) s a b
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@ end
|
||||||
inductive group_struct (A : Type) : Type :=
|
inductive group_struct (A : Type) : Type :=
|
||||||
| mk_group_struct : Π (mul : A → A → A) (one : A) (inv : A → A), is_assoc mul → is_id mul one → is_inv mul one inv → group_struct A
|
| mk_group_struct : Π (mul : A → A → A) (one : A) (inv : A → A), is_assoc mul → is_id mul one → is_inv mul one inv → group_struct A
|
||||||
|
|
||||||
class group_struct
|
|
||||||
|
|
||||||
inductive group : Type :=
|
inductive group : Type :=
|
||||||
| mk_group : Π (A : Type), group_struct A → group
|
| mk_group : Π (A : Type), group_struct A → group
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@ end
|
||||||
inductive group_struct (A : Type) : Type :=
|
inductive group_struct (A : Type) : Type :=
|
||||||
| mk_group_struct : Π (mul : A → A → A) (one : A) (inv : A → A), is_assoc mul → is_id mul one → is_inv mul one inv → group_struct A
|
| mk_group_struct : Π (mul : A → A → A) (one : A) (inv : A → A), is_assoc mul → is_id mul one → is_inv mul one inv → group_struct A
|
||||||
|
|
||||||
class group_struct
|
|
||||||
|
|
||||||
inductive group : Type :=
|
inductive group : Type :=
|
||||||
| mk_group : Π (A : Type), group_struct A → group
|
| mk_group : Π (A : Type), group_struct A → group
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue