|
| 1 | +/- |
| 2 | +Copyright (c) 2026 Jun Kwon. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Jun Kwon, Peter Nelson |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.Combinatorics.Graph.Subgraph |
| 9 | + |
| 10 | +/-! |
| 11 | +# Maps between graphs |
| 12 | +
|
| 13 | +This file defines vertex map between graphs `Graph α β`. Morphisms between graphs will also be |
| 14 | +defined in this file in the future. |
| 15 | +
|
| 16 | +## Main definitions |
| 17 | +
|
| 18 | +* `map`: the map on graphs induced by a function on vertices `f : α → α'` |
| 19 | +
|
| 20 | +## TODO |
| 21 | +
|
| 22 | +* Morphisms between graphs |
| 23 | +
|
| 24 | +-/ |
| 25 | + |
| 26 | +public section |
| 27 | + |
| 28 | +variable {α α' α'' β : Type*} {G H : Graph α β} {f g : α → α'} {u v : α} {e : β} {x y : α'} |
| 29 | + |
| 30 | +open Set Relation |
| 31 | + |
| 32 | +namespace Graph |
| 33 | + |
| 34 | +section Map |
| 35 | + |
| 36 | +/-- Map `G : Graph α β` to a `Graph α' β` with the same edge set by applying a function `f : α → α'` |
| 37 | + to each vertex. Edges between identified vertices become loops. -/ |
| 38 | +@[expose, simps! (attr := grind =)] |
| 39 | +def map (f : α → α') (G : Graph α β) : Graph α' β where |
| 40 | + vertexSet := f '' V(G) |
| 41 | + edgeSet := E(G) |
| 42 | + IsLink e := Relation.Map (G.IsLink e) f f |
| 43 | + isLink_symm _ he := map_symmetric (G.isLink_symm he) f |
| 44 | + eq_or_eq_of_isLink_of_isLink := by |
| 45 | + rintro e - - - - ⟨x, y, hxy, rfl, rfl⟩ ⟨z, w, hzw, rfl, rfl⟩ |
| 46 | + obtain rfl | rfl := hxy.left_eq_or_eq hzw <;> simp |
| 47 | + edge_mem_iff_exists_isLink e := by |
| 48 | + refine ⟨fun h ↦ ?_, fun ⟨_, _, _, _, h, _, _⟩ ↦ h.edge_mem⟩ |
| 49 | + obtain ⟨x, y, hxy⟩ := exists_isLink_of_mem_edgeSet h |
| 50 | + exact ⟨_, _, _, _, hxy, rfl, rfl⟩ |
| 51 | + left_mem_of_isLink := by |
| 52 | + rintro e - - ⟨x, y, h, rfl, rfl⟩ |
| 53 | + exact Set.mem_image_of_mem _ h.left_mem |
| 54 | + |
| 55 | +protected lemma IsLink.map (f : α → α') (h : G.IsLink e u v) : (G.map f).IsLink e (f u) (f v) := |
| 56 | + ⟨u, v, h, rfl, rfl⟩ |
| 57 | + |
| 58 | +@[simp] |
| 59 | +lemma map_inc (f : α → α') : (G.map f).Inc e x ↔ ∃ v, G.Inc e v ∧ x = f v := by |
| 60 | + simp only [Inc, map_isLink, map_apply] |
| 61 | + tauto |
| 62 | + |
| 63 | +protected lemma Inc.map (f : α → α') (h : G.Inc e v) : (G.map f).Inc e (f v) := by |
| 64 | + obtain ⟨w, hw⟩ := h |
| 65 | + exact ⟨f w, hw.map f⟩ |
| 66 | + |
| 67 | +@[simp] |
| 68 | +lemma map_isLoopAt (f : α → α') : |
| 69 | + (G.map f).IsLoopAt e x ↔ ∃ u v, G.IsLink e u v ∧ f u = x ∧ f v = x := Iff.rfl |
| 70 | + |
| 71 | +protected lemma IsLoopAt.map (f : α → α') (h : G.IsLoopAt e v) : (G.map f).IsLoopAt e (f v) := |
| 72 | + IsLink.map f h |
| 73 | + |
| 74 | +@[simp] |
| 75 | +lemma map_adj (f : α → α') : (G.map f).Adj x y ↔ Relation.Map G.Adj f f x y := by |
| 76 | + simp only [Adj, map_isLink, map_apply] |
| 77 | + tauto |
| 78 | + |
| 79 | +protected lemma Adj.map (f : α → α') (h : G.Adj u v) : (G.map f).Adj (f u) (f v) := by |
| 80 | + obtain ⟨e, h⟩ := h |
| 81 | + exact ⟨e, h.map f⟩ |
| 82 | + |
| 83 | +@[simp] lemma map_id : G.map id = G := by ext a b c <;> simp |
| 84 | + |
| 85 | +@[simp] |
| 86 | +lemma map_map (f : α → α') (f' : α' → α'') : (G.map f).map f' = G.map (f' ∘ f) := by |
| 87 | + ext a b c <;> simp [map_apply] |
| 88 | + |
| 89 | +@[gcongr] |
| 90 | +protected lemma IsSubgraph.map (f : α → α') (h : G ≤ H) : G.map f ≤ H.map f where |
| 91 | + vertexSet_mono v := by grind [h.vertexSet_mono] |
| 92 | + isLink_mono e := map_mono <| h.isLink_mono (e := e) |
| 93 | +alias map_mono := IsSubgraph.map |
| 94 | + |
| 95 | +@[gcongr] |
| 96 | +protected lemma IsSpanningSubgraph.map (f : α → α') (hsle : G ≤s H) : G.map f ≤s H.map f where |
| 97 | + le := hsle.le.map f |
| 98 | + vertexSet_eq := by simp [hsle.vertexSet_eq] |
| 99 | + |
| 100 | +@[gcongr] |
| 101 | +lemma map_eq_of_eqOn (h : EqOn f g V(G)) : G.map f = G.map g := by |
| 102 | + refine Graph.ext (by grind) fun _ _ _ ↦ ⟨fun ⟨_, _, hvw, _, _⟩ ↦ ?_, fun ⟨_, _, hvw, _, _⟩ ↦ ?_⟩ |
| 103 | + <;> grind [h hvw.left_mem, h hvw.right_mem, hvw.map] |
| 104 | + |
| 105 | +end Map |
| 106 | + |
| 107 | +end Graph |
0 commit comments