@@ -454,27 +454,36 @@ lemma Connected.exists_preconnected_induce_compl_singleton_of_finite [Finite V]
454454 obtain ⟨v, hv⟩ := hconn.exists_connected_induce_compl_singleton_of_finite_nontrivial
455455 exact ⟨v, hv.preconnected⟩
456456
457- lemma IsTree .dist_ne_of_adj (hG : G.IsTree) (u : V) { v w : V} (hadj : G.Adj v w) :
458- G.dist u v ≠ G.dist u w := by
459- obtain ⟨p, hp, hp'⟩ := hG.isConnected. exists_path_of_dist u v
460- obtain ⟨q, hq, hq'⟩ := hG.isConnected.exists_path_of_dist u w
457+ lemma IsAcyclic .dist_ne_of_adj (hG : G.IsAcyclic) {u v w : V} (hadj : G.Adj v w)
458+ (hreach : G.Reachable u v) : G.dist u v ≠ G.dist u w := by
459+ obtain ⟨p, hp, hp'⟩ := hreach. exists_path_of_dist
460+ obtain ⟨q, hq, hq'⟩ := hreach.trans hadj.reachable |>.exists_path_of_dist
461461 rw [← hp', ← hq']
462462 by_cases hw : w ∈ p.support
463- · rw [hG.IsAcyclic. path_concat hq hp hadj.symm hw, q.length_concat]
463+ · rw [hG.path_concat hq hp hadj.symm hw, q.length_concat]
464464 exact q.length.ne_add_one.symm
465- · have hv : v ∈ q.support := hG.IsAcyclic. mem_support_of_ne_mem_support_of_adj_of_isPath hq hp
465+ · have hv : v ∈ q.support := hG.mem_support_of_ne_mem_support_of_adj_of_isPath hq hp
466466 hadj.symm hw
467- rw [hG.IsAcyclic. path_concat hp hq hadj hv, p.length_concat]
467+ rw [hG.path_concat hp hq hadj hv, p.length_concat]
468468 exact p.length.ne_add_one
469469
470- lemma IsTree.diff_dist_adj (hG : G.IsTree) (u : V) {v w : V} (hadj : SimpleGraph.Adj G v w) :
471- G.dist u v = G.dist u w + 1 ∨ G.dist u v + 1 = G.dist u w := by
472- grind [dist_ne_of_adj, Connected.diff_dist_adj, IsTree]
470+ lemma IsTree.dist_ne_of_adj (hG : G.IsTree) (u : V) {v w : V} (hadj : G.Adj v w) :
471+ G.dist u v ≠ G.dist u w :=
472+ hG.IsAcyclic.dist_ne_of_adj hadj <| hG.isConnected u v
473+
474+ lemma IsAcyclic.dist_eq_dist_add_one_of_adj_of_reachable
475+ (hG : G.IsAcyclic) (u : V) {v w : V} (hadj : G.Adj v w) (hreach : G.Reachable u v) :
476+ G.dist u v = G.dist u w + 1 ∨ G.dist u w = G.dist u v + 1 := by
477+ grind [dist_ne_of_adj, Adj.diff_dist_adj]
478+
479+ lemma IsTree.dist_eq_dist_add_one_of_adj (hG : G.IsTree) (u : V) {v w : V} (hadj : G.Adj v w) :
480+ G.dist u v = G.dist u w + 1 ∨ G.dist u w = G.dist u v + 1 := by
481+ grind [dist_ne_of_adj, Adj.diff_dist_adj]
473482
474483/-- The unique two-coloring of a tree that colors the given vertex with zero -/
475484noncomputable def IsTree.coloringTwoOfVert (hG : G.IsTree) (u : V) : G.Coloring (Fin 2 ) :=
476485 Coloring.mk (fun v ↦ ⟨G.dist u v % 2 , Nat.mod_lt (G.dist u v) Nat.zero_lt_two⟩) <| by
477- grind [diff_dist_adj ]
486+ grind [dist_eq_dist_add_one_of_adj ]
478487
479488/-- Arbitrary coloring with two colors for a tree -/
480489noncomputable def IsTree.coloringTwo (hG : G.IsTree) : G.Coloring (Fin 2 ) :=
@@ -483,4 +492,23 @@ noncomputable def IsTree.coloringTwo (hG : G.IsTree) : G.Coloring (Fin 2) :=
483492lemma IsTree.isBipartite (hG : G.IsTree) : G.IsBipartite :=
484493 ⟨hG.coloringTwo⟩
485494
495+ /-- The unique two-coloring of a forest that colors the given vertices with zero -/
496+ noncomputable def IsAcyclic.coloringTwoOfVerts (hG : G.IsAcyclic) (verts : G.ConnectedComponent → V)
497+ (h : ∀ C, verts C ∈ C) : G.Coloring (Fin 2 ) where
498+ toFun v :=
499+ let u := verts <| G.connectedComponentMk v
500+ ⟨G.dist u v % 2 , Nat.mod_lt (G.dist u v) Nat.zero_lt_two⟩
501+ map_rel' := by
502+ intro u v hadj
503+ have := ConnectedComponent.sound hadj.reachable
504+ have := hG.dist_eq_dist_add_one_of_adj_of_reachable _ hadj <| ConnectedComponent.exact <| h _
505+ grind [top_adj]
506+
507+ /-- Arbitrary coloring with two colors for a forest -/
508+ noncomputable def IsAcyclic.coloringTwo (hG : G.IsAcyclic) : G.Coloring (Fin 2 ) :=
509+ hG.coloringTwoOfVerts (·.nonempty_supp.some) (·.nonempty_supp.some_mem)
510+
511+ lemma IsAcyclic.isBipartite (hG : G.IsAcyclic) : G.IsBipartite :=
512+ ⟨hG.coloringTwo⟩
513+
486514end SimpleGraph
0 commit comments