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

Commit 2985fa3

Browse files
committed
feat(combinatorics/simple_graph/prod): add finset lemma and remove unecessary decidable_eq (#17461)
Now that `[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)]` alone implies `fintype ((G □ H).neighbor_set x)` without additional `decidable_eq` arguments, there is no real need to supply the latter argument to lemmas about `(G □ H).neighbor_finset`. The new `simple_graph.box_prod_neighbor_finset` lemma unfortunately isn't true by refl, but the new fintype instance now at least has the right asymptotic complexity in computation.
1 parent cc16583 commit 2985fa3

3 files changed

Lines changed: 32 additions & 18 deletions

File tree

src/combinatorics/simple_graph/basic.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,15 @@ lemma neighbor_finset_def : G.neighbor_finset v = (G.neighbor_set v).to_finset :
788788
w ∈ G.neighbor_finset v ↔ G.adj v w :=
789789
set.mem_to_finset
790790

791+
@[simp] lemma not_mem_neighbor_finset_self : v ∉ G.neighbor_finset v :=
792+
(mem_neighbor_finset _ _ _).not.mpr $ G.loopless _
793+
794+
lemma neighbor_finset_disjoint_singleton : disjoint (G.neighbor_finset v) {v} :=
795+
finset.disjoint_singleton_right.mpr $ not_mem_neighbor_finset_self _ _
796+
797+
lemma singleton_disjoint_neighbor_finset : disjoint {v} (G.neighbor_finset v) :=
798+
finset.disjoint_singleton_left.mpr $ not_mem_neighbor_finset_self _ _
799+
791800
/--
792801
`G.degree v` is the number of vertices adjacent to `v`.
793802
-/

src/combinatorics/simple_graph/prod.lean

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,31 +173,36 @@ by { haveI := (nonempty_prod.1 h.nonempty).1, haveI := (nonempty_prod.1 h.nonemp
173173
@[simp] lemma box_prod_connected : (G □ H).connected ↔ G.connected ∧ H.connected :=
174174
⟨λ h, ⟨h.of_box_prod_left, h.of_box_prod_right⟩, λ h, h.1.box_prod h.2
175175

176-
instance [decidable_eq α] [decidable_eq β] (x : α × β)
176+
instance box_prod_fintype_neighbor_set (x : α × β)
177177
[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)] :
178178
fintype ((G □ H).neighbor_set x) :=
179+
fintype.of_equiv
180+
((G.neighbor_finset x.1 ×ˢ {x.2}).disj_union ({x.1} ×ˢ H.neighbor_finset x.2)
181+
$ finset.disjoint_product.mpr $ or.inl $ neighbor_finset_disjoint_singleton _ _)
182+
((equiv.refl _).subtype_equiv $ λ y, begin
183+
simp_rw [finset.mem_disj_union, finset.mem_product, finset.mem_singleton,
184+
mem_neighbor_finset, mem_neighbor_set, equiv.refl_apply, box_prod_adj],
185+
simp only [eq_comm, and_comm],
186+
end)
187+
188+
lemma box_prod_neighbor_finset (x : α × β)
189+
[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)] [fintype ((G □ H).neighbor_set x)] :
190+
(G □ H).neighbor_finset x =
191+
(G.neighbor_finset x.1 ×ˢ {x.2}).disj_union ({x.1} ×ˢ H.neighbor_finset x.2)
192+
(finset.disjoint_product.mpr $ or.inl $ neighbor_finset_disjoint_singleton _ _) :=
179193
begin
180-
rw box_prod_neighbor_set,
181-
apply_instance,
194+
-- swap out the fintype instance for the canonical one
195+
letI : fintype ((G □ H).neighbor_set x) := simple_graph.box_prod_fintype_neighbor_set _,
196+
refine eq.trans _ finset.attach_map_val,
197+
convert (finset.map_map _ (function.embedding.subtype _) finset.univ),
182198
end
183199

184200
lemma box_prod_degree (x : α × β)
185-
[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)]
186-
[fintype ((G □ H).neighbor_set x)] :
201+
[fintype (G.neighbor_set x.1)] [fintype (H.neighbor_set x.2)] [fintype ((G □ H).neighbor_set x)] :
187202
(G □ H).degree x = G.degree x.1 + H.degree x.2 :=
188203
begin
189-
classical,
190-
simp_rw [← card_neighbor_set_eq_degree, box_prod_neighbor_set,
191-
← set.to_finset_card, set.to_finset_union],
192-
convert finset.card_disjoint_union _;
193-
simp only [set.to_finset_prod, finset.card_product, set.to_finset_card,
194-
set.card_singleton, mul_one, one_mul],
195-
{ rw finset.disjoint_left,
196-
rintro ⟨_,_⟩ hG hH,
197-
simp only [finset.mem_product, set.mem_to_finset,
198-
mem_neighbor_set, set.mem_singleton_iff] at hG hH,
199-
obtain ⟨⟨q, rfl⟩, ⟨rfl, _⟩⟩ := ⟨hG, hH⟩,
200-
exact (q.ne rfl).elim, },
204+
rw [degree, degree, degree, box_prod_neighbor_finset, finset.card_disj_union],
205+
simp_rw [finset.card_product, finset.card_singleton, mul_one, one_mul],
201206
end
202207

203208
end simple_graph

src/data/finset/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ ext $ λ _, by simpa only [mem_map, exists_prop] using exists_eq_right
21652165
s.map (equiv.cast h).to_embedding == s :=
21662166
by { subst h, simp }
21672167

2168-
theorem map_map {g : β ↪ γ} : (s.map f).map g = s.map (f.trans g) :=
2168+
theorem map_map (f : α ↪ β) (g : β ↪ γ) (s : finset α) : (s.map f).map g = s.map (f.trans g) :=
21692169
eq_of_veq $ by simp only [map_val, multiset.map_map]; refl
21702170

21712171
lemma map_comm {β'} {f : β ↪ γ} {g : α ↪ β} {f' : α ↪ β'} {g' : β' ↪ γ}

0 commit comments

Comments
 (0)