feat(frontends/lean): remove 'using' from structure instance command
This commit is contained in:
parent
fed96c9e0b
commit
edcc92d9c7
9 changed files with 49 additions and 44 deletions
|
@ -252,24 +252,22 @@ section group
|
|||
iff.intro eq_mul_inv_of_mul_eq mul_eq_of_eq_mul_inv
|
||||
|
||||
definition group.to_left_cancel_semigroup [instance] [coercion] : left_cancel_semigroup A :=
|
||||
⦃ left_cancel_semigroup,
|
||||
⦃ left_cancel_semigroup, s,
|
||||
mul_left_cancel := take a b c,
|
||||
assume H : a * b = a * c,
|
||||
calc
|
||||
b = a⁻¹ * (a * b) : inv_mul_cancel_left
|
||||
... = a⁻¹ * (a * c) : H
|
||||
... = c : inv_mul_cancel_left,
|
||||
using s ⦄
|
||||
... = c : inv_mul_cancel_left⦄
|
||||
|
||||
definition group.to_right_cancel_semigroup [instance] [coercion] : right_cancel_semigroup A :=
|
||||
⦃ right_cancel_semigroup,
|
||||
⦃ right_cancel_semigroup, s,
|
||||
mul_right_cancel := take a b c,
|
||||
assume H : a * b = c * b,
|
||||
calc
|
||||
a = (a * b) * b⁻¹ : mul_inv_cancel_right
|
||||
... = (c * b) * b⁻¹ : H
|
||||
... = c : mul_inv_cancel_right,
|
||||
using s ⦄
|
||||
... = c : mul_inv_cancel_right⦄
|
||||
|
||||
end group
|
||||
|
||||
|
@ -382,25 +380,23 @@ section add_group
|
|||
|
||||
definition add_group.to_left_cancel_semigroup [instance] [coercion] :
|
||||
add_left_cancel_semigroup A :=
|
||||
⦃ add_left_cancel_semigroup,
|
||||
⦃ add_left_cancel_semigroup, s,
|
||||
add_left_cancel := take a b c,
|
||||
assume H : a + b = a + c,
|
||||
calc
|
||||
b = -a + (a + b) : !neg_add_cancel_left⁻¹
|
||||
... = -a + (a + c) : H
|
||||
... = c : neg_add_cancel_left,
|
||||
using s ⦄
|
||||
... = c : neg_add_cancel_left ⦄
|
||||
|
||||
definition add_group.to_add_right_cancel_semigroup [instance] [coercion] :
|
||||
add_right_cancel_semigroup A :=
|
||||
⦃ add_right_cancel_semigroup,
|
||||
⦃ add_right_cancel_semigroup, s,
|
||||
add_right_cancel := take a b c,
|
||||
assume H : a + b = c + b,
|
||||
calc
|
||||
a = (a + b) + -b : !add_neg_cancel_right⁻¹
|
||||
... = (c + b) + -b : H
|
||||
... = c : add_neg_cancel_right,
|
||||
using s ⦄
|
||||
... = c : add_neg_cancel_right ⦄
|
||||
|
||||
/- sub -/
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ structure ordered_comm_group [class] (A : Type) extends add_comm_group A, order_
|
|||
|
||||
definition ordered_comm_group.to_ordered_cancel_comm_monoid [instance] [coercion]
|
||||
[s : ordered_comm_group A] : ordered_cancel_comm_monoid A :=
|
||||
⦃ ordered_cancel_comm_monoid,
|
||||
⦃ ordered_cancel_comm_monoid, s,
|
||||
add_left_cancel := @add.left_cancel _ _,
|
||||
add_right_cancel := @add.right_cancel _ _,
|
||||
le_of_add_le_add_left :=
|
||||
|
@ -210,8 +210,7 @@ definition ordered_comm_group.to_ordered_cancel_comm_monoid [instance] [coercion
|
|||
assume H : a + b ≤ a + c,
|
||||
have H' : -a + (a + b) ≤ -a + (a + c), from ordered_comm_group.add_le_add_left _ _ H _,
|
||||
!neg_add_cancel_left ▸ !neg_add_cancel_left ▸ H'
|
||||
qed,
|
||||
using s ⦄
|
||||
qed ⦄
|
||||
|
||||
section
|
||||
variables [s : ordered_comm_group A] (a b c d e : A)
|
||||
|
|
|
@ -146,7 +146,7 @@ structure ordered_ring [class] (A : Type) extends ring A, ordered_comm_group A :
|
|||
|
||||
definition ordered_ring.to_ordered_semiring [instance] [coercion] [s : ordered_ring A] :
|
||||
ordered_semiring A :=
|
||||
⦃ ordered_semiring,
|
||||
⦃ ordered_semiring, s,
|
||||
mul_zero := mul_zero,
|
||||
zero_mul := zero_mul,
|
||||
add_left_cancel := @add.left_cancel A _,
|
||||
|
@ -187,8 +187,8 @@ definition ordered_ring.to_ordered_semiring [instance] [coercion] [s : ordered_r
|
|||
have H1 : 0 < b - a, from iff.elim_right !sub_pos_iff_lt Hab,
|
||||
have H2 : 0 < (b - a) * c, from ordered_ring.mul_pos _ _ H1 Hc,
|
||||
iff.mp !sub_pos_iff_lt (!mul_sub_right_distrib ▸ H2)
|
||||
qed,
|
||||
using s ⦄
|
||||
qed
|
||||
⦄
|
||||
|
||||
section
|
||||
variable [s : ordered_ring A]
|
||||
|
@ -243,7 +243,7 @@ structure linear_ordered_ring [class] (A : Type) extends ordered_ring A, linear_
|
|||
definition linear_ordered_ring.to_linear_ordered_semiring [instance] [coercion]
|
||||
[s : linear_ordered_ring A] :
|
||||
linear_ordered_semiring A :=
|
||||
⦃ linear_ordered_semiring,
|
||||
⦃ linear_ordered_semiring, s,
|
||||
mul_zero := mul_zero,
|
||||
zero_mul := zero_mul,
|
||||
add_left_cancel := @add.left_cancel A _,
|
||||
|
@ -253,8 +253,8 @@ definition linear_ordered_ring.to_linear_ordered_semiring [instance] [coercion]
|
|||
mul_le_mul_of_nonneg_right := @mul_le_mul_of_nonneg_right A _,
|
||||
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left A _,
|
||||
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right A _,
|
||||
le_total := linear_ordered_ring.le_total,
|
||||
using s ⦄
|
||||
le_total := linear_ordered_ring.le_total
|
||||
⦄
|
||||
|
||||
structure linear_ordered_comm_ring [class] (A : Type) extends linear_ordered_ring A, comm_monoid A
|
||||
|
||||
|
@ -262,7 +262,7 @@ structure linear_ordered_comm_ring [class] (A : Type) extends linear_ordered_rin
|
|||
definition linear_ordered_comm_ring.to_integral_domain [instance] [coercion]
|
||||
[s: linear_ordered_comm_ring A] :
|
||||
integral_domain A :=
|
||||
⦃ integral_domain,
|
||||
⦃ integral_domain, s,
|
||||
eq_zero_or_eq_zero_of_mul_eq_zero := take a b,
|
||||
assume H : a * b = 0,
|
||||
show a = 0 ∨ b = 0, from
|
||||
|
@ -277,8 +277,8 @@ definition linear_ordered_comm_ring.to_integral_domain [instance] [coercion]
|
|||
lt.by_cases
|
||||
(assume Hb : 0 < b, absurd (H ▸ mul_neg_of_neg_of_pos Ha Hb) (lt.irrefl 0))
|
||||
(assume Hb : 0 = b, or.inr (Hb⁻¹))
|
||||
(assume Hb : 0 > b, absurd (H ▸ mul_pos_of_neg_of_neg Ha Hb) (lt.irrefl 0))),
|
||||
using s ⦄
|
||||
(assume Hb : 0 > b, absurd (H ▸ mul_pos_of_neg_of_neg Ha Hb) (lt.irrefl 0)))
|
||||
⦄
|
||||
|
||||
section
|
||||
variable [s : linear_ordered_ring A]
|
||||
|
|
|
@ -153,7 +153,7 @@ end comm_semiring
|
|||
structure ring [class] (A : Type) extends add_comm_group A, monoid A, distrib A, zero_ne_one_class A
|
||||
|
||||
definition ring.to_semiring [instance] [coercion] [s : ring A] : semiring A :=
|
||||
⦃ semiring,
|
||||
⦃ semiring, s,
|
||||
mul_zero := take a,
|
||||
have H : a * 0 + 0 = a * 0 + a * 0, from
|
||||
calc
|
||||
|
@ -167,8 +167,7 @@ definition ring.to_semiring [instance] [coercion] [s : ring A] : semiring A :=
|
|||
0 * a + 0 = 0 * a : add_zero
|
||||
... = (0 + 0) * a : {(add_zero 0)⁻¹}
|
||||
... = 0 * a + 0 * a : ring.right_distrib,
|
||||
show 0 * a = 0, from (add.left_cancel H)⁻¹,
|
||||
using s ⦄
|
||||
show 0 * a = 0, from (add.left_cancel H)⁻¹ ⦄
|
||||
|
||||
section
|
||||
variables [s : ring A] (a b c d e : A)
|
||||
|
@ -223,10 +222,9 @@ end
|
|||
structure comm_ring [class] (A : Type) extends ring A, comm_semigroup A
|
||||
|
||||
definition comm_ring.to_comm_semiring [instance] [coercion] [s : comm_ring A] : comm_semiring A :=
|
||||
⦃ comm_semiring,
|
||||
⦃ comm_semiring, s,
|
||||
mul_zero := mul_zero,
|
||||
zero_mul := zero_mul,
|
||||
using s ⦄
|
||||
zero_mul := zero_mul ⦄
|
||||
|
||||
section
|
||||
variables [s : comm_ring A] (a b c d e : A)
|
||||
|
|
|
@ -1247,12 +1247,12 @@ expr parser::parse_expr(unsigned rbp) {
|
|||
return left;
|
||||
}
|
||||
|
||||
pair<optional<name>, expr> parser::parse_qualified_expr(unsigned rbp) {
|
||||
pair<optional<name>, expr> parser::parse_id_tk_expr(name const & tk, unsigned rbp) {
|
||||
if (curr_is_identifier()) {
|
||||
auto id_pos = pos();
|
||||
name id = get_name_val();
|
||||
next();
|
||||
if (curr_is_token(get_colon_tk())) {
|
||||
if (curr_is_token(tk)) {
|
||||
next();
|
||||
return mk_pair(optional<name>(id), parse_expr(rbp));
|
||||
} else {
|
||||
|
@ -1267,6 +1267,14 @@ pair<optional<name>, expr> parser::parse_qualified_expr(unsigned rbp) {
|
|||
}
|
||||
}
|
||||
|
||||
pair<optional<name>, expr> parser::parse_qualified_expr(unsigned rbp) {
|
||||
return parse_id_tk_expr(get_colon_tk(), rbp);
|
||||
}
|
||||
|
||||
pair<optional<name>, expr> parser::parse_optional_assignment(unsigned rbp) {
|
||||
return parse_id_tk_expr(get_assign_tk(), rbp);
|
||||
}
|
||||
|
||||
expr parser::parse_scoped_expr(unsigned num_ps, expr const * ps, local_environment const & lenv, unsigned rbp) {
|
||||
local_scope scope(*this);
|
||||
m_env = lenv;
|
||||
|
|
|
@ -193,6 +193,8 @@ class parser {
|
|||
bool allow_empty, unsigned rbp);
|
||||
bool parse_local_notation_decl(buffer<notation_entry> * entries);
|
||||
|
||||
pair<optional<name>, expr> parse_id_tk_expr(name const & tk, unsigned rbp);
|
||||
|
||||
friend environment section_cmd(parser & p);
|
||||
friend environment context_cmd(parser & p);
|
||||
friend environment namespace_cmd(parser & p);
|
||||
|
@ -352,12 +354,15 @@ public:
|
|||
expr id_to_expr(name const & id, pos_info const & p);
|
||||
|
||||
expr parse_expr(unsigned rbp = 0);
|
||||
/**
|
||||
\brief Parse an (optionally) qualified expression.
|
||||
If the input is of the form <id> : <expr>, then return the pair (some(id), expr).
|
||||
Otherwise, parse the next expression and return (none, expr).
|
||||
/** \brief Parse an (optionally) qualified expression.
|
||||
If the input is of the form <id> : <expr>, then return the pair (some(id), expr).
|
||||
Otherwise, parse the next expression and return (none, expr).
|
||||
*/
|
||||
pair<optional<name>, expr> parse_qualified_expr(unsigned rbp = 0);
|
||||
/** \brief If the input is of the form <id> := <expr>, then return the pair (some(id), expr).
|
||||
Otherwise, parse the next expression and return (none, expr).
|
||||
*/
|
||||
pair<optional<name>, expr> parse_optional_assignment(unsigned rbp = 0);
|
||||
|
||||
expr parse_led(expr left);
|
||||
expr parse_scoped_expr(unsigned num_params, expr const * ps, local_environment const & lenv, unsigned rbp = 0);
|
||||
|
|
|
@ -985,13 +985,12 @@ static expr parse_struct_expr_core(parser & p, pos_info const & pos, bool curly_
|
|||
buffer<expr> using_exprs;
|
||||
while (p.curr_is_token(get_comma_tk())) {
|
||||
p.next();
|
||||
if (p.curr_is_token(get_using_tk())) {
|
||||
p.next();
|
||||
using_exprs.push_back(p.parse_expr());
|
||||
pair<optional<name>, expr> id_e = p.parse_optional_assignment();
|
||||
if (id_e.first) {
|
||||
field_names.push_back(*id_e.first);
|
||||
field_values.push_back(id_e.second);
|
||||
} else {
|
||||
field_names.push_back(p.check_atomic_id_next("invalid structure instance, identifier expected"));
|
||||
p.check_token_next(get_assign_tk(), "invalid structure instance, ':=' expected");
|
||||
field_values.push_back(p.parse_expr());
|
||||
using_exprs.push_back(id_e.second);
|
||||
}
|
||||
}
|
||||
if (curly_bar)
|
||||
|
|
|
@ -11,7 +11,7 @@ definition s2 := ⦃ test, a := 3, b := 10 ⦄
|
|||
|
||||
eval s2
|
||||
|
||||
definition s3 := {| test, a := 20, using s2 |}
|
||||
definition s3 := {| test, a := 20, s2 |}
|
||||
|
||||
eval s3
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ structure s3 (A : Type) extends s1 A, s2 A :=
|
|||
|
||||
definition v1 : s1 nat := {| s1, x := 10, y := 10, h := rfl |}
|
||||
definition v2 : s2 nat := {| s2, mul := nat.add, one := zero |}
|
||||
definition v3 : s3 nat := {| s3, mul_one := add_zero, using v1, using v2 |}
|
||||
definition v3 : s3 nat := {| s3, mul_one := add_zero, v1, v2 |}
|
||||
|
||||
example : s3.x v3 = 10 := rfl
|
||||
example : s3.y v3 = 10 := rfl
|
||||
|
|
Loading…
Reference in a new issue