Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ lemma IsEdgeReachable.le_degree [Fintype (G.neighborSet u)] (h : G.IsEdgeReachab
(huv : u ≠ v) : k ≤ G.degree u := by
classical
by_contra! hh
obtain ⟨w, _⟩ :=
@h (G.incidenceSet u) (by simpa [← Set.coe_fintypeCard, ENat.coe_lt_coe]) |>.exists_isPath
rw [← card_incidenceSet_eq_degree, ← ENat.coe_lt_coe, Set.coe_fintypeCard] at hh
obtain ⟨w, _⟩ := h hh |>.exists_isPath
simpa using w.adj_snd <| mt Walk.Nil.eq huv

lemma IsEdgeConnected.le_degree [Fintype (G.neighborSet u)] [Nontrivial V]
Expand Down
3 changes: 2 additions & 1 deletion Mathlib/Combinatorics/SimpleGraph/Copy.lean
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ alias ⟨IsContained.exists_iso_subgraph, IsContained.of_exists_iso_subgraph⟩

theorem Copy.degree_le (f : Copy G H) (v : V) [Fintype <| G.neighborSet v]
[Fintype <| H.neighborSet (f v)] : G.degree v ≤ H.degree (f v) := by
simpa using Fintype.card_le_of_injective _ (f.mapNeighborSet v).injective
simpa [card_neighborSet_eq_degree] using
Fintype.card_le_of_injective _ (f.mapNeighborSet v).injective

theorem Copy.max_degree_le [Fintype V] [Fintype W] [DecidableRel G.Adj] [DecidableRel H.Adj]
(f : Copy G H) : G.maxDegree ≤ H.maxDegree := by
Expand Down
11 changes: 4 additions & 7 deletions Mathlib/Combinatorics/SimpleGraph/Finite.lean
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ lemma edgeFinset_nonempty : G.edgeFinset.Nonempty ↔ G ≠ ⊥ := by
theorem edgeFinset_card : #G.edgeFinset = Fintype.card G.edgeSet :=
Set.toFinset_card _

@[simp]
theorem card_edgeSet : Fintype.card G.edgeSet = #G.edgeFinset :=
.symm <| Set.toFinset_card _

theorem edgeSet_univ_card : #(univ : Finset G.edgeSet) = #G.edgeFinset := by
simp
simp [card_edgeSet]

variable [Fintype V]

Expand Down Expand Up @@ -203,7 +202,6 @@ def degree : ℕ := #(G.neighborFinset v)
@[simp]
theorem card_neighborFinset_eq_degree : #(G.neighborFinset v) = G.degree v := rfl

@[simp]
theorem card_neighborSet_eq_degree : Fintype.card (G.neighborSet v) = G.degree v :=
(Set.toFinset_card _).symm

Expand Down Expand Up @@ -255,7 +253,8 @@ theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] :
Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by
classical
rw [← card_neighborSet_union_compl_neighborSet G v, Set.toFinset_union]
simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v))]
simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v)),
card_neighborSet_eq_degree]

instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) :=
Fintype.ofEquiv (G.neighborSet v) (G.incidenceSetEquivNeighborSet v).symm
Expand All @@ -264,11 +263,9 @@ instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) :=
def incidenceFinset [DecidableEq V] : Finset (Sym2 V) :=
(G.incidenceSet v).toFinset

@[simp]
theorem card_incidenceSet_eq_degree [DecidableEq V] :
Fintype.card (G.incidenceSet v) = G.degree v := by
rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v)]
simp
rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v), card_neighborSet_eq_degree]

@[simp, norm_cast]
theorem coe_incidenceFinset [DecidableEq V] :
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Combinatorics/SimpleGraph/IncMatrix.lean
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ variable [NonAssocSemiring R] [DecidableEq α] [DecidableRel G.Adj] {a : α} {e

theorem sum_incMatrix_apply [Fintype (Sym2 α)] [Fintype (neighborSet G a)] :
∑ e, G.incMatrix R a e = G.degree a := by
simp [incMatrix_apply', sum_boole, Set.filter_mem_univ_eq_toFinset]
simp [incMatrix_apply', sum_boole, Set.filter_mem_univ_eq_toFinset, card_incidenceSet_eq_degree]

theorem incMatrix_mul_transpose_diag [Fintype (Sym2 α)] [Fintype (neighborSet G a)] :
(G.incMatrix R * (G.incMatrix R)ᵀ) a a = G.degree a := by
Expand Down
5 changes: 2 additions & 3 deletions Mathlib/Combinatorics/SimpleGraph/Matching.lean
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,8 @@ lemma odd_matches_node_outside [Finite V] {u : Set V}
apply Nat.not_even_iff_odd.2 c.prop
haveI : Fintype ↑(Subgraph.induce M (Subtype.val '' supp c.val)).verts := Fintype.ofFinite _
classical
haveI : Fintype (c.val.supp) := Fintype.ofFinite _
simpa [Subgraph.induce_verts, Subgraph.verts_top, Nat.card_eq_fintype_card, Set.toFinset_card,
Finset.card_image_of_injective, ← Nat.card_coe_set_eq] using hMmatch.even_card
haveI := Fintype.ofFinite c.val.supp
simpa [Finset.card_image_of_injective] using hMmatch.even_card

end Finite
end ConnectedComponent
Expand Down
3 changes: 1 addition & 2 deletions Mathlib/Combinatorics/SimpleGraph/Subgraph.lean
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,6 @@ lemma adj_iff_of_neighborSet_equiv {v : V} {H : Subgraph G}

end Subgraph

@[simp]
theorem card_neighborSet_toSubgraph (G H : SimpleGraph V) (h : H ≤ G)
(v : V) [Fintype ↑((toSubgraph H h).neighborSet v)] [Fintype ↑(H.neighborSet v)] :
Fintype.card ↑((toSubgraph H h).neighborSet v) = H.degree v := by
Expand All @@ -880,7 +879,7 @@ theorem card_neighborSet_toSubgraph (G H : SimpleGraph V) (h : H ≤ G)
lemma degree_toSubgraph (G H : SimpleGraph V) (h : H ≤ G) {v : V}
[Fintype ↑((toSubgraph H h).neighborSet v)] [Fintype ↑(H.neighborSet v)] :
(toSubgraph H h).degree v = H.degree v := by
simp [Subgraph.degree]
simp [Subgraph.degree, card_neighborSet_toSubgraph]

section MkProperties

Expand Down
1 change: 0 additions & 1 deletion Mathlib/Data/Fintype/Card.lean
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ theorem Fintype.card_lex (α : Type*) [Fintype α] : Fintype.card (Lex α) = Fin

-- Note: The extra hypothesis `h` is there so that the rewrite lemma applies,
-- no matter what instance of `Fintype (Set.univ : Set α)` is used.
@[simp]
theorem Fintype.card_setUniv [Fintype α] {h : Fintype (Set.univ : Set α)} :
Fintype.card (Set.univ : Set α) = Fintype.card α := by
Comment thread
b-mehta marked this conversation as resolved.
apply Fintype.card_of_finset'
Expand Down
5 changes: 4 additions & 1 deletion Mathlib/Data/Set/Card.lean
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ theorem toENat_cardinalMk_subtype (P : α → Prop) :
(Cardinal.mk {x // P x}).toENat = {x | P x}.encard :=
rfl

@[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by
variable (s) in
theorem coe_fintypeCard [Fintype s] : Fintype.card s = s.encard := by
simp [encard_eq_coe_toFinset_card]

@[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) :
Expand Down Expand Up @@ -590,6 +591,7 @@ theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]

variable (s) in
@[simp]
theorem coe_ncard_eq_encard [Finite s] : s.ncard = s.encard :=
s.toFinite.cast_ncard_eq

Expand All @@ -607,6 +609,7 @@ theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
simp [← _root_.Nat.card_coe_set_eq, Nat.card_eq_fintype_card]

variable (s) in
@[simp]
theorem fintypeCard_eq_ncard [Fintype s] : Fintype.card s = s.ncard := by
rw [ncard_eq_toFinset_card', toFinset_card]

Expand Down
1 change: 0 additions & 1 deletion Mathlib/Data/Set/Finite/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ theorem card_fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉
@Fintype.card _ (fintypeInsertOfNotMem s h) = Fintype.card s + 1 := by
simp [Fintype.card_ofFinset]

@[simp]
theorem card_insert {a : α} (s : Set α) [Fintype s] (h : a ∉ s)
{d : Fintype (insert a s : Set α)} : @Fintype.card _ d = Fintype.card s + 1 := by
rw [← card_fintypeInsertOfNotMem s h]; congr!
Expand Down
3 changes: 1 addition & 2 deletions Mathlib/GroupTheory/ClassEquation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ theorem Group.sum_card_conj_classes_eq_card [Finite G] :
∑ᶠ x : ConjClasses G, x.carrier.ncard = Nat.card G := by
classical
cases nonempty_fintype G
rw [Nat.card_eq_fintype_card, ← sum_conjClasses_card_eq_card, finsum_eq_sum_of_fintype]
simp [Set.ncard_eq_toFinset_card']
simp [← sum_conjClasses_card_eq_card, finsum_eq_sum_of_fintype]

/-- The **class equation** for finite groups. The cardinality of a group is equal to the size
of its center plus the sum of the size of all its nontrivial conjugacy classes. -/
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/LinearAlgebra/Matrix/GeneralLinearGroup/Card.lean
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ theorem card_linearIndependent {k : ℕ} (hk : k ≤ n) :
simp only [SetLike.coe_sort_coe, finrank_span_eq_card s.2, card_fin]
rw [Module.card_eq_pow_finrank (K := K)]
simp [card_congr (equiv_linearIndependent k), sum_congr _ _ this, ih (Nat.le_of_succ_le hk),
mul_comm, Fin.prod_univ_succAbove _ (Fin.last k)]
mul_comm, Fin.prod_univ_succAbove _ (Fin.last k), -Set.fintypeCard_eq_ncard]

end LinearIndependent

Expand Down
11 changes: 5 additions & 6 deletions Mathlib/Order/Interval/Finset/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,17 @@ theorem coe_Ico (a b : α) : (Ico a b : Set α) = Set.Ico a b :=
theorem coe_Ioo (a b : α) : (Ioo a b : Set α) = Set.Ioo a b :=
Set.ext fun _ => mem_Ioo

@[simp, to_dual self]
@[to_dual self]
theorem _root_.Fintype.card_Icc (a b : α) [Fintype (Set.Icc a b)] :
Fintype.card (Set.Icc a b) = #(Icc a b) :=
Comment on lines +333 to 335

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simp now prove these lemmas (in a different way)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it just simplifies the LHS to Set.ncard (after Mathlib/Data/Set/Card.lean, not here) so simpNF is angry.

I also think these are pretty strange as simp lemmas, but maybe I haven't used LocallyFiniteOrder enough to see its value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lemmas should be stated in terms of Set.ncard. They were written before the definition existed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make a follow-up PR to make this change?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fintype.card_of_finset' _ fun _ ↦ by simp

@[to_dual (reorder := a b) (attr := simp)]
@[to_dual (reorder := a b)]
theorem _root_.Fintype.card_Ico (a b : α) [Fintype (Set.Ico a b)] :
Fintype.card (Set.Ico a b) = #(Ico a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp

@[simp, to_dual self]
@[to_dual self]
theorem _root_.Fintype.card_Ioo (a b : α) [Fintype (Set.Ioo a b)] :
Fintype.card (Set.Ioo a b) = #(Ioo a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
Expand Down Expand Up @@ -379,12 +379,12 @@ theorem coe_Ici (a : α) : (Ici a : Set α) = Set.Ici a :=
theorem coe_Ioi (a : α) : (Ioi a : Set α) = Set.Ioi a :=
Set.ext fun _ => mem_Ioi

@[to_dual (attr := simp)]
@[to_dual]
theorem _root_.Fintype.card_Ici (a : α) [Fintype (Set.Ici a)] :
Fintype.card (Set.Ici a) = #(Ici a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp

@[to_dual (attr := simp)]
@[to_dual]
theorem _root_.Fintype.card_Ioi (a : α) [Fintype (Set.Ioi a)] :
Fintype.card (Set.Ioi a) = #(Ioi a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
Expand Down Expand Up @@ -437,7 +437,6 @@ theorem mem_uIcc : x ∈ uIcc a b ↔ a ⊓ b ≤ x ∧ x ≤ a ⊔ b :=
theorem coe_uIcc (a b : α) : (Finset.uIcc a b : Set α) = Set.uIcc a b :=
coe_Icc _ _

@[simp]
theorem _root_.Fintype.card_uIcc (a b : α) [Fintype (Set.uIcc a b)] :
Fintype.card (Set.uIcc a b) = #(uIcc a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp [Set.uIcc]
Expand Down
Loading