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

Commit 39cea43

Browse files
committed
docs(data/subtype): add module docstring (#8900)
1 parent 710a76e commit 39cea43

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/data/subtype.lean

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,29 @@ Copyright (c) 2017 Johannes Hölzl. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl
55
-/
6-
import tactic.lint
76
import tactic.ext
7+
import tactic.lint
88
import tactic.simps
99

10+
/-!
11+
# Subtypes
12+
13+
This file provides basic API for subtypes, which are defined in core.
14+
15+
A subtype is a type made from restricting another type, say `α`, to its elements that satisfy some
16+
predicate, say `p : α → Prop`. Specifically, it is the type of pairs `⟨val, property⟩` where
17+
`val : α` and `property : p val`. It is denoted `subtype p` and notation `{val : α // p val}` is
18+
available.
19+
20+
A subtype has a natural coercion to the parent type, by coercing `⟨val, property⟩` to `val`. As
21+
such, subtypes can be thought of as bundled sets, the difference being that elements of a set are
22+
still of type `α` while elements of a subtype aren't.
23+
-/
24+
1025
open function
1126

1227
namespace subtype
13-
variables: Sort*} {β : Sort*} {γ : Sort*} {p : α → Prop} {q : α → Prop}
28+
variablesβ γ : Sort*} {p q : α → Prop}
1429

1530
/-- See Note [custom simps projection] -/
1631
def simps.coe (x : subtype p) : α := x
@@ -29,7 +44,7 @@ lemma prop (x : subtype p) : p x := x.2
2944

3045
/-- An alternative version of `subtype.forall`. This one is useful if Lean cannot figure out `q`
3146
when using `subtype.forall` from right to left. -/
32-
protected theorem forall' {q : ∀x, p x → Prop} :
47+
protected theorem forall' {q : ∀ x, p x → Prop} :
3348
(∀ x h, q x h) ↔ (∀ x : {a // p a}, q x x.2) :=
3449
(@subtype.forall _ _ (λ x, q x.1 x.2)).symm
3550

@@ -76,10 +91,10 @@ theorem val_injective : injective (@val _ p) :=
7691
coe_injective
7792

7893
/-- Restrict a (dependent) function to a subtype -/
79-
def restrict {α} {β : α → Type*} (f : Πx, β x) (p : α → Prop) (x : subtype p) : β x.1 :=
94+
def restrict {α} {β : α → Type*} (f : Π x, β x) (p : α → Prop) (x : subtype p) : β x.1 :=
8095
f x
8196

82-
lemma restrict_apply {α} {β : α → Type*} (f : Πx, β x) (p : α → Prop) (x : subtype p) :
97+
lemma restrict_apply {α} {β : α → Type*} (f : Π x, β x) (p : α → Prop) (x : subtype p) :
8398
restrict f p x = f x.1 :=
8499
by refl
85100

@@ -91,39 +106,39 @@ lemma restrict_injective {α β} {f : α → β} (p : α → Prop) (h : injectiv
91106
h.comp coe_injective
92107

93108
/-- Defining a map into a subtype, this can be seen as an "coinduction principle" of `subtype`-/
94-
@[simps] def coind {α β} (f : α → β) {p : β → Prop} (h : ∀a, p (f a)) : α → subtype p :=
109+
@[simps] def coind {α β} (f : α → β) {p : β → Prop} (h : ∀ a, p (f a)) : α → subtype p :=
95110
λ a, ⟨f a, h a⟩
96111

97-
theorem coind_injective {α β} {f : α → β} {p : β → Prop} (h : ∀a, p (f a))
112+
theorem coind_injective {α β} {f : α → β} {p : β → Prop} (h : ∀ a, p (f a))
98113
(hf : injective f) : injective (coind f h) :=
99114
λ x y hxy, hf $ by apply congr_arg subtype.val hxy
100115

101-
theorem coind_surjective {α β} {f : α → β} {p : β → Prop} (h : ∀a, p (f a))
116+
theorem coind_surjective {α β} {f : α → β} {p : β → Prop} (h : ∀ a, p (f a))
102117
(hf : surjective f) : surjective (coind f h) :=
103118
λ x, let ⟨a, ha⟩ := hf x in ⟨a, coe_injective ha⟩
104119

105-
theorem coind_bijective {α β} {f : α → β} {p : β → Prop} (h : ∀a, p (f a))
120+
theorem coind_bijective {α β} {f : α → β} {p : β → Prop} (h : ∀ a, p (f a))
106121
(hf : bijective f) : bijective (coind f h) :=
107122
⟨coind_injective h hf.1, coind_surjective h hf.2
108123

109124
/-- Restriction of a function to a function on subtypes. -/
110-
@[simps] def map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀a, p a → q (f a)) :
125+
@[simps] def map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀ a, p a → q (f a)) :
111126
subtype p → subtype q :=
112127
λ x, ⟨f x, h x x.prop⟩
113128

114129
theorem map_comp {p : α → Prop} {q : β → Prop} {r : γ → Prop} {x : subtype p}
115-
(f : α → β) (h : ∀a, p a → q (f a)) (g : β → γ) (l : ∀a, q a → r (g a)) :
130+
(f : α → β) (h : ∀ a, p a → q (f a)) (g : β → γ) (l : ∀ a, q a → r (g a)) :
116131
map g l (map f h x) = map (g ∘ f) (assume a ha, l (f a) $ h a ha) x :=
117132
rfl
118133

119-
theorem map_id {p : α → Prop} {h : ∀a, p a → p (id a)} : map (@id α) h = id :=
134+
theorem map_id {p : α → Prop} {h : ∀ a, p a → p (id a)} : map (@id α) h = id :=
120135
funext $ assume ⟨v, h⟩, rfl
121136

122-
lemma map_injective {p : α → Prop} {q : β → Prop} {f : α → β} (h : ∀a, p a → q (f a))
137+
lemma map_injective {p : α → Prop} {q : β → Prop} {f : α → β} (h : ∀ a, p a → q (f a))
123138
(hf : injective f) : injective (map f h) :=
124139
coind_injective _ $ hf.comp coe_injective
125140

126-
lemma map_involutive {p : α → Prop} {f : α → α} (h : ∀a, p a → p (f a))
141+
lemma map_involutive {p : α → Prop} {f : α → α} (h : ∀ a, p a → p (f a))
127142
(hf : involutive f) : involutive (map f h) :=
128143
λ x, subtype.ext (hf x)
129144

@@ -155,7 +170,7 @@ end subtype
155170

156171
namespace subtype
157172
/-! Some facts about sets, which require that `α` is a type. -/
158-
variables: Type*} {β : Type*} {γ : Type*} {p : α → Prop}
173+
variablesβ γ : Type*} {p : α → Prop}
159174

160175
@[simp] lemma coe_prop {S : set α} (a : {a // a ∈ S}) : ↑a ∈ S := a.prop
161176

0 commit comments

Comments
 (0)