Skip to content

Commit

Permalink
chore(Data/Fin): move Fin.equiv_iff_eq (#10522)
Browse files Browse the repository at this point in the history
The new proof is longer but I need this lemma before `Fintype`
for a future refactor, see #9794
  • Loading branch information
urkud committed Feb 14, 2024
1 parent b5ee7ad commit 3984e58
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 23 additions & 0 deletions Mathlib/Data/Fin/Basic.lean
Expand Up @@ -817,6 +817,29 @@ def castLEEmb (h : n ≤ m) : Fin n ↪o Fin m :=
#align fin.cast_le_mk Fin.castLE_mk
#align fin.cast_le_zero Fin.castLE_zero

/- The next proof can be golfed a lot using `Fintype.card`.
It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency
(not done yet). -/
assert_not_exists Fintype

lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by
refine ⟨fun h ↦ ?_, fun h ↦ ⟨(castLEEmb h).toEmbedding⟩⟩
induction n generalizing m with
| zero => exact m.zero_le
| succ n ihn =>
cases' h with e
rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne'
with ⟨m, rfl⟩
refine Nat.succ_le_succ <| ihn ⟨?_⟩
refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero),
fun i j h ↦ ?_⟩
simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h

lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n :=
fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩),
fun h ↦ h ▸ ⟨.refl _⟩⟩
#align fin.equiv_iff_eq Fin.equiv_iff_eq

@[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) :
i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) :=
rfl
Expand Down
4 changes: 0 additions & 4 deletions Mathlib/Data/Fintype/Card.lean
Expand Up @@ -340,10 +340,6 @@ theorem card_finset_fin_le {n : ℕ} (s : Finset (Fin n)) : s.card ≤ n := by
simpa only [Fintype.card_fin] using s.card_le_univ
#align card_finset_fin_le card_finset_fin_le

theorem Fin.equiv_iff_eq {m n : ℕ} : Nonempty (Fin m ≃ Fin n) ↔ m = n :=
fun ⟨h⟩ => by simpa using Fintype.card_congr h, fun h => ⟨Equiv.cast <| h ▸ rfl⟩⟩
#align fin.equiv_iff_eq Fin.equiv_iff_eq

--@[simp] Porting note: simp can prove it
theorem Fintype.card_subtype_eq (y : α) [Fintype { x // x = y }] :
Fintype.card { x // x = y } = 1 :=
Expand Down

0 comments on commit 3984e58

Please sign in to comment.