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

Commit 662786a

Browse files
committed
refactor(data/{finite,fintype}): redefine infinite in terms of finite, move to data.finite.defs (#16390)
1 parent e0bdbbe commit 662786a

File tree

6 files changed

+37
-44
lines changed

6 files changed

+37
-44
lines changed

src/data/finite/basic.lean

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ defined.
1818
former lemma takes `fintype α` as an explicit argument while the latter takes it as an instance
1919
argument.
2020
* `fintype.of_finite` noncomputably creates a `fintype` instance from a `finite` instance.
21-
* `finite_or_infinite` is that every type is either `finite` or `infinite`.
2221
2322
## Implementation notes
2423
@@ -42,13 +41,6 @@ open_locale classical
4241

4342
variables {α β γ : Type*}
4443

45-
lemma finite_or_infinite (α : Type*) :
46-
finite α ∨ infinite α :=
47-
begin
48-
rw ← not_finite_iff_infinite,
49-
apply em
50-
end
51-
5244
namespace finite
5345

5446
@[priority 100] -- see Note [lower instance priority]

src/data/finite/defs.lean

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import logic.equiv.basic
99
# Definition of the `finite` typeclass
1010
1111
This file defines a typeclass `finite` saying that `α : Sort*` is finite. A type is `finite` if it
12-
is equivalent to `fin n` for some `n`.
12+
is equivalent to `fin n` for some `n`. We also define `infinite α` as a typeclass equivalent to
13+
`¬finite α`.
1314
1415
The `finite` predicate has no computational relevance and, being `Prop`-valued, gets to enjoy proof
1516
irrelevance -- it represents the mere fact that the type is finite. While the `fintype` class also
@@ -26,6 +27,7 @@ instead.
2627
## Main definitions
2728
2829
* `finite α` denotes that `α` is a finite type.
30+
* `infinite α` denotes that `α` is an infinite type.
2931
3032
## Implementation notes
3133
@@ -66,11 +68,27 @@ lemma equiv.finite_iff (f : α ≃ β) : finite α ↔ finite β :=
6668
lemma function.bijective.finite_iff {f : α → β} (h : bijective f) : finite α ↔ finite β :=
6769
(equiv.of_bijective f h).finite_iff
6870

69-
namespace finite
71+
lemma finite.of_bijective [finite α] {f : α → β} (h : bijective f) : finite β := h.finite_iff.mp ‹_›
7072

71-
lemma of_bijective [finite α] {f : α → β} (h : bijective f) : finite β := h.finite_iff.mp ‹_›
73+
instance [finite α] : finite (plift α) := finite.of_equiv α equiv.plift.symm
74+
instance {α : Type v} [finite α] : finite (ulift.{u} α) := finite.of_equiv α equiv.ulift.symm
7275

73-
instance [finite α] : finite (plift α) := of_equiv α equiv.plift.symm
74-
instance {α : Type v} [finite α] : finite (ulift.{u} α) := of_equiv α equiv.ulift.symm
76+
/-- A type is said to be infinite if it is not finite. Note that `infinite α` is equivalent to
77+
`is_empty (fintype α)` or `is_empty (finite α)`. -/
78+
class infinite (α : Sort*) : Prop :=
79+
(not_finite : ¬finite α)
7580

76-
end finite
81+
@[simp] lemma not_finite_iff_infinite : ¬finite α ↔ infinite α := ⟨infinite.mk, λ h, h.1
82+
83+
@[simp] lemma not_infinite_iff_finite : ¬infinite α ↔ finite α :=
84+
not_finite_iff_infinite.not_right.symm
85+
86+
lemma finite_or_infinite (α : Sort*) : finite α ∨ infinite α :=
87+
or_iff_not_imp_left.2 $ not_finite_iff_infinite.1
88+
89+
lemma not_finite (α : Sort*) [infinite α] [finite α] : false := @infinite.not_finite α ‹_› ‹_›
90+
91+
protected lemma finite.false [infinite α] (h : finite α) : false := not_finite α
92+
protected lemma infinite.false [finite α] (h : infinite α) : false := not_finite α
93+
94+
alias not_infinite_iff_finite ↔ finite.of_not_infinite finite.not_infinite

src/data/fintype/basic.lean

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,34 +1918,15 @@ well_founded_of_trans_of_irrefl _
19181918

19191919
end finite
19201920

1921-
/-- A type is said to be infinite if it has no fintype instance.
1922-
Note that `infinite α` is equivalent to `is_empty (fintype α)`. -/
1923-
class infinite (α : Type*) : Prop :=
1924-
(not_fintype : fintype α → false)
1925-
1926-
lemma not_finite (α : Type*) [infinite α] [finite α] : false :=
1927-
by { casesI nonempty_fintype α, exact infinite.not_fintype ‹_› }
1928-
1929-
protected lemma finite.false [infinite α] (h : finite α) : false := not_finite α
1930-
19311921
@[nolint fintype_finite]
19321922
protected lemma fintype.false [infinite α] (h : fintype α) : false := not_finite α
1933-
protected lemma infinite.false [finite α] (h : infinite α) : false := not_finite α
19341923

19351924
@[simp] lemma is_empty_fintype {α : Type*} : is_empty (fintype α) ↔ infinite α :=
1936-
⟨λ ⟨x⟩, ⟨x⟩, λ ⟨x⟩, ⟨x⟩⟩
1937-
1938-
lemma not_finite_iff_infinite : ¬ finite α ↔ infinite α :=
1939-
by rw [← is_empty_fintype, finite_iff_nonempty_fintype, not_nonempty_iff]
1940-
1941-
lemma not_infinite_iff_finite : ¬ infinite α ↔ finite α := not_finite_iff_infinite.not_right.symm
1942-
1943-
alias not_finite_iff_infinite ↔ infinite.of_not_finite infinite.not_finite
1944-
alias not_infinite_iff_finite ↔ finite.of_not_infinite finite.not_infinite
1925+
⟨λ ⟨h⟩, ⟨λ h', (@nonempty_fintype α h').elim h⟩, λ ⟨h⟩, ⟨λ h', h h'.finite⟩⟩
19451926

19461927
/-- A non-infinite type is a fintype. -/
19471928
noncomputable def fintype_of_not_infinite {α : Type*} (h : ¬ infinite α) : fintype α :=
1948-
nonempty.some $ by rwa [← not_is_empty_iff, is_empty_fintype]
1929+
@fintype.of_finite _ (not_infinite_iff_finite.mp h)
19491930

19501931
section
19511932
open_locale classical
@@ -1975,6 +1956,8 @@ lemma finset.exists_maximal {α : Type*} [preorder α] (s : finset α) (h : s.no
19751956

19761957
namespace infinite
19771958

1959+
lemma of_not_fintype (h : fintype α → false) : infinite α := is_empty_fintype.mp ⟨h⟩
1960+
19781961
lemma exists_not_mem_finset [infinite α] (s : finset α) : ∃ x, x ∉ s :=
19791962
not_forall.1 $ λ h, fintype.false ⟨s, h⟩
19801963

@@ -1988,15 +1971,15 @@ protected lemma nonempty (α : Type*) [infinite α] : nonempty α :=
19881971
by apply_instance
19891972

19901973
lemma of_injective [infinite β] (f : β → α) (hf : injective f) : infinite α :=
1991-
⟨λ I, by exactI (fintype.of_injective f hf).false⟩
1974+
⟨λ I, by exactI (finite.of_injective f hf).false⟩
19921975

19931976
lemma of_surjective [infinite β] (f : α → β) (hf : surjective f) : infinite α :=
1994-
⟨λ I, by { classical, exactI (fintype.of_surjective f hf).false }
1977+
⟨λ I, by exactI (finite.of_surjective f hf).false⟩
19951978

19961979
end infinite
19971980

19981981
instance : infinite ℕ :=
1999-
λ ⟨s, hs⟩, finset.not_mem_range_self $ s.subset_range_sup_succ (hs _)
1982+
infinite.of_not_fintype $ λ ⟨s, hs⟩, finset.not_mem_range_self $ s.subset_range_sup_succ (hs _)
20001983

20011984
instance : infinite ℤ :=
20021985
infinite.of_injective int.of_nat (λ _ _, int.of_nat.inj)

src/data/fintype/card_embedding.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ end
4343

4444
/- The cardinality of embeddings from an infinite type to a finite type is zero.
4545
This is a re-statement of the pigeonhole principle. -/
46-
@[simp] lemma card_embedding_eq_of_infinite {α β} [infinite α] [fintype β] [fintype (α ↪ β)] :
46+
@[simp] lemma card_embedding_eq_of_infinite {α β : Type*} [infinite α] [fintype β]
47+
[fintype (α ↪ β)] :
4748
‖α ↪ β‖ = 0 :=
48-
card_eq_zero_iff.mpr function.embedding.is_empty
49+
card_eq_zero
4950

5051
end fintype

src/data/set/finite.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,9 @@ theorem infinite_univ [h : infinite α] : (@univ α).infinite :=
853853
infinite_univ_iff.2 h
854854

855855
theorem infinite_coe_iff {s : set α} : infinite s ↔ s.infinite :=
856-
⟨λ ⟨h₁⟩ h₂, h₁ h₂.fintype, λ h₁, ⟨λ h₂, h₁ ⟨h₂⟩⟩⟩
856+
not_finite_iff_infinite.symm.trans finite_coe_iff.not
857857

858-
theorem infinite.to_subtype {s : set α} (h : s.infinite) : infinite s :=
859-
infinite_coe_iff.2 h
858+
alias infinite_coe_iff ↔ _ infinite.to_subtype
860859

861860
/-- Embedding of `ℕ` into an infinite set. -/
862861
noncomputable def infinite.nat_embedding (s : set α) (h : s.infinite) : ℕ ↪ s :=

src/field_theory/is_alg_closed/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ perfect_ring.of_surjective k p $ λ x, is_alg_closed.exists_pow_nat_eq _ $ ne_ze
348348
@[priority 500]
349349
instance {K : Type*} [field K] [is_alg_closed K] : infinite K :=
350350
begin
351-
apply infinite.mk,
351+
apply infinite.of_not_fintype,
352352
introsI hfin,
353353
set n := fintype.card K with hn,
354354
set f := (X : K[X]) ^ (n + 1) - 1 with hf,

0 commit comments

Comments
 (0)