Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 477338d

Browse files
jcommelinrobertylewis
authored andcommitted
refactor(data/subtype): organise in namespaces, use variables, add two simp-lemmas (#760)
1 parent af2cf74 commit 477338d

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

src/data/subtype.lean

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,34 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Author: Johannes Hölzl
55
-/
66

7+
-- Lean complains if this section is turned into a namespace
78
section subtype
8-
variables {α : Sort*} {β : α → Prop}
9+
variables {α : Sort*} {p : α → Prop}
910

10-
protected lemma subtype.eq' : ∀ {a1 a2 : {x // β x}}, a1.val = a2.val → a1 = a2
11-
| ⟨x, h1⟩ ⟨.(x), h2⟩ rfl := rfl
12-
13-
lemma subtype.ext {a1 a2 : {x // β x}} : a1 = a2 ↔ a1.val = a2.val :=
14-
⟨congr_arg _, subtype.eq'⟩
15-
16-
lemma subtype.coe_ext {a1 a2 : {x // β x}} : a1 = a2 ↔ (a1 : α) = a2 :=
17-
subtype.ext
18-
19-
theorem subtype.val_injective : function.injective (@subtype.val _ β) :=
20-
λ a b, subtype.eq'
21-
22-
@[simp] theorem subtype.coe_eta {α : Type*} {β : α → Prop}
23-
(a : {a // β a}) (h : β a) : subtype.mk ↑a h = a := subtype.eta _ _
24-
25-
@[simp] theorem subtype.coe_mk {α : Type*} {β : α → Prop}
26-
(a h) : (@subtype.mk α β a h : α) = a := rfl
27-
28-
@[simp] theorem subtype.mk_eq_mk {α : Type*} {β : α → Prop}
29-
{a h a' h'} : @subtype.mk α β a h = @subtype.mk α β a' h' ↔ a = a' :=
30-
⟨λ H, by injection H, λ H, by congr; assumption⟩
31-
32-
@[simp] theorem subtype.forall {p : {a // β a} → Prop} :
33-
(∀ x, p x) ↔ (∀ a b, p ⟨a, b⟩) :=
11+
@[simp] theorem subtype.forall {q : {a // p a} → Prop} :
12+
(∀ x, q x) ↔ (∀ a b, q ⟨a, b⟩) :=
3413
⟨assume h a b, h ⟨a, b⟩, assume h ⟨a, b⟩, h a b⟩
3514

36-
@[simp] theorem subtype.exists {p : {a // β a} → Prop} :
37-
(∃ x, p x) ↔ (∃ a b, p ⟨a, b⟩) :=
15+
@[simp] theorem subtype.exists {q : {a // p a} → Prop} :
16+
(∃ x, q x) ↔ (∃ a b, q ⟨a, b⟩) :=
3817
⟨assume ⟨⟨a, b⟩, h⟩, ⟨a, b, h⟩, assume ⟨a, b, h⟩, ⟨⟨a, b⟩, h⟩⟩
3918

4019
end subtype
4120

4221
namespace subtype
43-
variables {α : Sort*} {β : Sort*} {γ : Sort*}
22+
variables {α : Sort*} {β : Sort*} {γ : Sort*} {p : α → Prop}
23+
24+
protected lemma eq' : ∀ {a1 a2 : {x // p x}}, a1.val = a2.val → a1 = a2
25+
| ⟨x, h1⟩ ⟨.(x), h2⟩ rfl := rfl
26+
27+
lemma ext {a1 a2 : {x // p x}} : a1 = a2 ↔ a1.val = a2.val :=
28+
⟨congr_arg _, subtype.eq'⟩
29+
30+
lemma coe_ext {a1 a2 : {x // p x}} : a1 = a2 ↔ (a1 : α) = a2 :=
31+
ext
32+
33+
theorem val_injective : function.injective (@val _ p) :=
34+
λ a b, subtype.eq'
4435

4536
/-- Restriction of a function to a function on subtypes. -/
4637
def map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀a, p a → q (f a)) :
@@ -55,19 +46,14 @@ rfl
5546
theorem map_id {p : α → Prop} {h : ∀a, p a → p (id a)} : map (@id α) h = id :=
5647
funext $ assume ⟨v, h⟩, rfl
5748

58-
end subtype
59-
60-
namespace subtype
61-
variables {α : Sort*}
62-
6349
instance [has_equiv α] (p : α → Prop) : has_equiv (subtype p) :=
6450
⟨λ s t, s.val ≈ t.val⟩
6551

6652
theorem equiv_iff [has_equiv α] {p : α → Prop} {s t : subtype p} :
6753
s ≈ t ↔ s.val ≈ t.val :=
6854
iff.rfl
6955

70-
variables [setoid α] {p : α → Prop}
56+
variables [setoid α]
7157

7258
protected theorem refl (s : subtype p) : s ≈ s :=
7359
setoid.refl s.val
@@ -79,9 +65,28 @@ protected theorem trans {s t u : subtype p} (h₁ : s ≈ t) (h₂ : t ≈ u) :
7965
setoid.trans h₁ h₂
8066

8167
theorem equivalence (p : α → Prop) : equivalence (@has_equiv.equiv (subtype p) _) :=
82-
mk_equivalence _ subtype.refl (@subtype.symm _ _ p) (@subtype.trans _ _ p)
68+
mk_equivalence _ subtype.refl (@subtype.symm _ p _) (@subtype.trans _ p _)
8369

8470
instance (p : α → Prop) : setoid (subtype p) :=
8571
setoid.mk (≈) (equivalence p)
8672

8773
end subtype
74+
75+
namespace subtype
76+
variables {α : Type*} {β : Type*} {γ : Type*} {p : α → Prop}
77+
78+
@[simp] theorem coe_eta {α : Type*} {p : α → Prop}
79+
(a : {a // p a}) (h : p a) : mk ↑a h = a := eta _ _
80+
81+
@[simp] theorem coe_mk {α : Type*} {p : α → Prop}
82+
(a h) : (@mk α p a h : α) = a := rfl
83+
84+
@[simp] theorem mk_eq_mk {α : Type*} {p : α → Prop}
85+
{a h a' h'} : @mk α p a h = @mk α p a' h' ↔ a = a' :=
86+
⟨λ H, by injection H, λ H, by congr; assumption⟩
87+
88+
@[simp] lemma val_prop {S : set α} (a : {a // a ∈ S}) : a.val ∈ S := a.property
89+
90+
@[simp] lemma val_prop' {S : set α} (a : {a // a ∈ S}) : ↑a ∈ S := a.property
91+
92+
end subtype

0 commit comments

Comments
 (0)