1-- The side of a vertex set as a multigraph of its own: the edges inside a2-- vertex set, the end functions restricted to them, and the ends, degrees,3-- and cuts read through the restriction; a side crossed by no edge of a4-- bridgeless graph is bridgeless.5-- Part of Cumulus, the Grace17 mathematics library.6-- Copyright (c) 2026 Grant Passmore.7-- Released under the Apache License 2.0. See LICENSE in the repository root.8-- Authors: Grant Passmore910module Grace.Cumulus.GraphTheory.Multigraph.Subgraph11import Connectivity1213-- The edges of F inside X are edges of F, grow with F, and have both ends14-- in X.15theorem inside.subset (leftEnd rightEnd F X : Set)16shows inside(leftEnd, rightEnd, F, X) ⊆ F17proof18intros e edge19exact edge.left2021theorem inside.monotone (leftEnd rightEnd F G X : Set)22requires subset : F ⊆ G23shows inside(leftEnd, rightEnd, F, X) ⊆ inside(leftEnd, rightEnd, G, X)24proof25intros e edge26exact⟨(subset with e, edge.left), edge.right⟩2728theorem inside.ends (leftEnd rightEnd F X : Set)29shows∀ e ∈ inside(leftEnd, rightEnd, F, X),30 leftEnd(e) ∈ X ∧ rightEnd(e) ∈ X31proof32intros e edge33exact edge.right3435-- Two sets of ends agree when they agree on every pair (f, i).36theorem incidentEnds.ext (leftEnd rightEnd otherLeft otherRight F G v w : Set)37requires agree : ∀ f, ∀ i,38 ((f, i) ∈ incidentEnds(leftEnd, rightEnd, F, v) ↔39 (f, i) ∈ incidentEnds(otherLeft, otherRight, G, w))40shows incidentEnds(leftEnd, rightEnd, F, v) =41 incidentEnds(otherLeft, otherRight, G, w)42proof43ext p44constructor45 . intro hp46obtain⟨f, _, i, _, rfl⟩:= incidentEnds.shape with hp47have rule := agree with f, i48exact rule.forward with hp49 . intro hp50obtain⟨f, _, i, _, rfl⟩:= incidentEnds.shape with hp51have rule := agree with f, i52exact rule.backward with hp5354-- On the edges of D the restricted ends are the ends, so the ends at a55-- vertex, the degrees, and the cuts of an edge set inside D are the same56-- for both.57theorem incidentEnds.restricted (W E D F leftEnd rightEnd v : Set)58requires graph : Graph(W, E, leftEnd, rightEnd)59requires edges : D ⊆ E60requires subset : F ⊆ D61shows incidentEnds(restrict(leftEnd, D), restrict(rightEnd, D), F, v) =62 incidentEnds(leftEnd, rightEnd, F, v)63proof64apply incidentEnds.ext65intros f i66 by_cases inF : f ∈ F67 . have inD := subset with f, inF68have leftValue := restrict.domain_apply with graph.left, edges, inD69have rightValue := restrict.domain_apply with graph.right, edges, inD70simp [incidentEnds.pair, leftValue, rightValue]71 . simp [incidentEnds.pair, inF]7273theorem degreeIn.restricted (W E D F leftEnd rightEnd v : Set)74requires graph : Graph(W, E, leftEnd, rightEnd)75requires edges : D ⊆ E76requires subset : F ⊆ D77shows degreeIn(restrict(leftEnd, D), restrict(rightEnd, D), F, v) =78 degreeIn(leftEnd, rightEnd, F, v)79proof80unfold degreeIn81rw incidentEnds.restricted with graph, edges, subset8283theorem crossing.restricted (W E D X leftEnd rightEnd : Set)84requires graph : Graph(W, E, leftEnd, rightEnd)85requires edges : D ⊆ E86shows crossing(restrict(leftEnd, D), restrict(rightEnd, D), D, X) =87 crossing(leftEnd, rightEnd, D, X)88proof89ext e90 by_cases inD : e ∈ D91 . have leftValue := restrict.domain_apply with graph.left, edges, inD92have rightValue := restrict.domain_apply with graph.right, edges, inD93simp [crossing, leftValue, rightValue]94 . simp [crossing, inD]9596-- A side of a split is a graph on its own vertices once the end functions97-- are restricted to its inside edges, and it stays bridgeless when no edge98-- crosses the split.99theorem inside.graph (V E leftEnd rightEnd X : Set)100requires graph : Graph(V, E, leftEnd, rightEnd)101requires subset : X ⊆ V102shows Graph(X, inside(leftEnd, rightEnd, E, X),103 restrict(leftEnd, inside(leftEnd, rightEnd, E, X)),104 restrict(rightEnd, inside(leftEnd, rightEnd, E, X)))105proof106have edges := inside.subset at leftEnd, rightEnd, E, X107have ends := inside.ends at leftEnd, rightEnd, E, X108have leftIn : ∀ e ∈ inside(leftEnd, rightEnd, E, X), leftEnd(e) ∈ X109intros e he110exact (ends with e, he).left111have rightIn : ∀ e ∈ inside(leftEnd, rightEnd, E, X), rightEnd(e) ∈ X112intros e he113exact (ends with e, he).right114exact⟨(restrict.function with graph.left, edges, leftIn),115 (restrict.function with graph.right, edges, rightIn)⟩116117theorem inside.bridgeless (V E leftEnd rightEnd X : Set)118requires graph : Graph(V, E, leftEnd, rightEnd)119requiressplit : X ⊆ V ∧ crossing(leftEnd, rightEnd, E, X) =∅120requires bridgeless : Bridgeless(V, E, leftEnd, rightEnd)121shows Bridgeless(X, inside(leftEnd, rightEnd, E, X),122 restrict(leftEnd, inside(leftEnd, rightEnd, E, X)),123 restrict(rightEnd, inside(leftEnd, rightEnd, E, X)))124proof125intros Y bound126obtain⟨subset, none⟩:=split127have edges := inside.subset at leftEnd, rightEnd, E, X128-- An edge leaving Y ⊆ X has its other end in X, as no edge leaves X, so129-- the cut of Y within the side is its cut in the whole graph.130have within : crossing(leftEnd, rightEnd, E, Y) ⊆131 inside(leftEnd, rightEnd, E, X)132intros e he133obtain⟨inE, sides⟩:= he134have notCross : ¬e ∈ crossing(leftEnd, rightEnd, E, X)135rw none136simp137have both : leftEnd(e) ∈ X ∧ rightEnd(e) ∈ X138by_contra outside139apply notCross140refine⟨inE, _⟩141rcases sides with⟨leftY, rightY⟩|⟨rightY, leftY⟩142 . left143have leftX := bound with leftEnd(e), leftY144refine⟨leftX, _⟩145intro rightX146exact outside with⟨leftX, rightX⟩147 . right148have rightX := bound with rightEnd(e), rightY149refine⟨rightX, _⟩150intro leftX151exact outside with⟨leftX, rightX⟩152exact⟨inE, both⟩153have same : crossing(restrict(leftEnd, inside(leftEnd, rightEnd, E, X)),154 restrict(rightEnd, inside(leftEnd, rightEnd, E, X)),155 inside(leftEnd, rightEnd, E, X), Y) = crossing(leftEnd, rightEnd, E, Y)156rw [(crossing.restricted with graph, edges), (crossing.restrict with edges)]157exact intersection.eq_left_of_subset with within158rw same159exact bridgeless with Y, (Subset.transitive with bound, subset)160