Graph Theory in Coq: Minors, Treewidth and Isomorphisms Damien Pous - - PowerPoint PPT Presentation
Graph Theory in Coq: Minors, Treewidth and Isomorphisms Damien Pous - - PowerPoint PPT Presentation
Graph Theory in Coq: Minors, Treewidth and Isomorphisms Damien Pous Christian Doczkal CNRS / LIP, ENS de Lyon, France Coq Workshop 2019 - September 8, 2019 Background Graph library published as part ITP 2018 paper: simple graphs, directed
Background
Graph library published as part ITP 2018 paper:
◮ simple graphs, directed mulitgraphs ◮ paths, connected components, etc. ◮ minors and treewidth ◮ extracting term descriptions from graphs ◮ equivalence between treewidth two and K4-freeness
(obtained as a corollary of term extraction)
Additions and improvements for (submitted) journal version:
◮ Menger’s Theorem and corollaries (graph connectivity) ◮ simplified equivalence of treewidth two and K4-freeness ◮ compositional reasoning about graph isomorphisms
- C. Doczkal, D. Pous
Graph Theory in Coq 2 / 20
Background
Graph library published as part ITP 2018 paper:
◮ simple graphs, directed mulitgraphs ◮ paths, connected components, etc. ◮ minors and treewidth ◮ extracting term descriptions from graphs ◮ equivalence between treewidth two and K4-freeness
(obtained as a corollary of term extraction)
Additions and improvements for (submitted) journal version:
◮ Menger’s Theorem and corollaries (graph connectivity) ◮ simplified equivalence of treewidth two and K4-freeness ◮ compositional reasoning about graph isomorphisms
- C. Doczkal, D. Pous
Graph Theory in Coq 2 / 20
Problem: Axiomatizing Graph Isomorphism
Term language describing certain graphs (2p-graphs) Interpretation function: g : Tm → 2p-graph.
◮ compositionally interprets syntactic constructs as graph operations
Axiom System: 2p ⊢ u ≡ v.
- C. Doczkal, D. Pous
Graph Theory in Coq 3 / 20
Problem: Axiomatizing Graph Isomorphism
Term language describing certain graphs (2p-graphs) Interpretation function: g : Tm → 2p-graph.
◮ compositionally interprets syntactic constructs as graph operations
Axiom System: 2p ⊢ u ≡ v.
Theorem ([Cosme-Lopez & Pous ’17, Doczkal & Pous ’18])
g(u) ≃ g(v) ⇐ ⇒ 2p ⊢ u ≡ v
- C. Doczkal, D. Pous
Graph Theory in Coq 3 / 20
Problem: Axiomatizing Graph Isomorphism
Term language describing certain graphs (2p-graphs) Interpretation function: g : Tm → 2p-graph.
◮ compositionally interprets syntactic constructs as graph operations
Axiom System: 2p ⊢ u ≡ v.
Theorem ([Cosme-Lopez & Pous ’17, Doczkal & Pous ’18])
g(u) ≃ g(v) ⇐ ⇒ 2p ⊢ u ≡ v Context:
Theorem ([Freyd & Scedrov ’90, Pous & Vignudelli ’18])
g(u) R g(v) ⇐ ⇒ AL⊤ ⊢ u ≡ v (≃ R)
- C. Doczkal, D. Pous
Graph Theory in Coq 3 / 20
Problem: Axiomatizing Graph Isomorphism
Term language describing certain graphs (2p-graphs) Interpretation function: g : Tm → 2p-graph.
◮ compositionally interprets syntactic constructs as graph operations
Axiom System: 2p ⊢ u ≡ v.
Theorem ([Cosme-Lopez & Pous ’17, Doczkal & Pous ’18])
g(u) ≃ g(v) ⇐ = 2p ⊢ u ≡ v Context:
Theorem ([Freyd & Scedrov ’90, Pous & Vignudelli ’18])
g(u) R g(v) ⇐ ⇒ AL⊤ ⊢ u ≡ v (≃ R)
- C. Doczkal, D. Pous
Graph Theory in Coq 3 / 20
2p-graphs
a a d d b c c
(finite 2-pointed multi-) graphs: labeled directed edges multiple edges between vertices self loops two designated vertices (input and output)
- C. Doczkal, D. Pous
Graph Theory in Coq 4 / 20
Terms of 2p-algebras [Cosme-Lopez & Pous ’17]
u, v, w ::= a
- ⊤
- 1
- u◦
dom(u)
- u v
- u·v
(a ∈ Σ) a
a
⊤ 1 G ◦
G
dom(G)
G
G H
G H
G·H
G H
(where G =
G
and H =
H
)
- C. Doczkal, D. Pous
Graph Theory in Coq 5 / 20
Example 1
(G · H) 1
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 6 / 20
Example 1
(G · H) 1
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 6 / 20
Example 1
(G · H) 1
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 6 / 20
Example 1
(G · H) 1
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 6 / 20
Example 1
(G · H) 1
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 6 / 20
Example 1
(G · H) 1
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 6 / 20
Example 2
dom(G H◦)
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 7 / 20
Example 2
dom(G H◦)
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 7 / 20
Example 2
dom(G H◦)
G H (180◦ rotation – no change)
- C. Doczkal, D. Pous
Graph Theory in Coq 7 / 20
Example 2
dom(G H◦)
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 7 / 20
Example 2
dom(G H◦)
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 7 / 20
Example 2
dom(G H◦)
G H
- C. Doczkal, D. Pous
Graph Theory in Coq 7 / 20
Example 2
dom(G H◦)
G H
The axioms of 2p-algebras [Cosme-Lopez & Pous ’17] equate exactly those terms whose graphs are isomorphic.
- C. Doczkal, D. Pous
Graph Theory in Coq 7 / 20
2p-algebras
u (v w) ≡ (u v) w (A1) u v ≡ v u (A2) u ⊤ ≡ u (A3) u·(v·w) ≡ (u·v)·w (A4) u·1 ≡ u (A5) u◦◦ ≡ u (A6) (u v)◦ ≡ u◦ v ◦ (A7) (u·v)◦ ≡ v ◦·u◦ (A8) 1 1 ≡ 1 (A9) dom(u v ◦) ≡ 1 u·v (A10) u·⊤ ≡ dom(u)·⊤ (A11) (1 u)·v ≡ (1 u)·⊤ v (A12)
- C. Doczkal, D. Pous
Graph Theory in Coq 8 / 20
2p-algebras
u (v w) ≡ (u v) w (A1) u v ≡ v u (A2) u ⊤ ≡ u (A3) u·(v·w) ≡ (u·v)·w (A4) u·1 ≡ u (A5) u◦◦ ≡ u (A6) (u v)◦ ≡ u◦ v ◦ (A7) (u·v)◦ ≡ v ◦·u◦ (A8) 1 1 ≡ 1 (A9) dom(u v ◦) ≡ 1 u·v (A10) u·⊤ ≡ dom(u)·⊤ (A11) (1 u)·v ≡ (1 u)·⊤ v (A12)
- C. Doczkal, D. Pous
Graph Theory in Coq 8 / 20
Coq I: Formalization of Graphs
Record graph := Graph { vertex : finType; edge: finType; source : edge → vertex; target : edge → vertex; label : edge → sym }. Record graph2 := Graph2 { graph of : graph; g in : graph of; g out : graph of }.
Uses finite types from MathComp/Ssreflect. Finite types are closed under disjoint union and quotients.
- C. Doczkal, D. Pous
Graph Theory in Coq 9 / 20
Coq II: Term Graphs
u, v, w ::= a
- ⊤
- 1
- u◦
dom(u)
- u v
- u·v
(a ∈ Σ) Graphs for a, ⊤, and 1 can easily be defined Unary graph operations,
- and dom( ), only change input/output
Binary operations,
- and · , can be described using two primitive
- perations (on graph not on graph2):
◮ Disjoint union:
⊎ : graph → graph → graph
◮ Quotients:
/ / : ∀(G : graph). list(G ∗ G) → graph (with “class” function π : G → G / /e).
G, ι, o · G ′, ι′, o′ := G ⊎ G ′/ /[(inl o, inr ι′)], π(inl ι), π(inr o′)
- C. Doczkal, D. Pous
Graph Theory in Coq 10 / 20
Isomorphisms for two-pointed directed multigraphs
a a
- C. Doczkal, D. Pous
Graph Theory in Coq 11 / 20
Isomorphisms for two-pointed directed multigraphs
- a
s t a s′ t′ a
- C. Doczkal, D. Pous
Graph Theory in Coq 11 / 20
Isomorphisms for two-pointed directed multigraphs
- a
s t a s′ t′ a f f g
- C. Doczkal, D. Pous
Graph Theory in Coq 11 / 20
Isomorphisms for two-pointed directed multigraphs
- a
s t a s′ t′ a f f g
multigraph homomorphisms:
1
s′ ◦ g = f ◦ s
2
t′ ◦ g = f ◦ t
3
l = l′ ◦ g
- C. Doczkal, D. Pous
Graph Theory in Coq 11 / 20
Isomorphisms for two-pointed directed multigraphs
- a
s t a s′ t′ a f f g
multigraph homomorphisms:
1
s′ ◦ g = f ◦ s
2
t′ ◦ g = f ◦ t
3
l = l′ ◦ g
homomorphisms of 2p-graphs: f (ι) = ι′ and f (o) = o′
- C. Doczkal, D. Pous
Graph Theory in Coq 11 / 20
Isomorphisms for two-pointed directed multigraphs
- a
s t a s′ t′ a f f g
multigraph homomorphisms:
1
s′ ◦ g = f ◦ s
2
t′ ◦ g = f ◦ t
3
l = l′ ◦ g
homomorphisms of 2p-graphs: f (ι) = ι′ and f (o) = o′ isomorphisms:
1
f bijective (i.e., define f ′ and show f ◦ f ′ = id and f ′ ◦ f = id)
2
g bijective
- C. Doczkal, D. Pous
Graph Theory in Coq 11 / 20
Isomorphisms for two-pointed directed multigraphs
- a
s t a s′ t′ a f f g
multigraph homomorphisms:
1
s′ ◦ g = f ◦ s
2
t′ ◦ g = f ◦ t
3
l = l′ ◦ g
homomorphisms of 2p-graphs: f (ι) = ι′ and f (o) = o′ isomorphisms:
1
f bijective (i.e., define f ′ and show f ◦ f ′ = id and f ′ ◦ f = id)
2
g bijective
4 function defintions and 9 equalities for every isomorphism source and target include nested quotients (dom(G H◦) ≃ 1 G·H)
- C. Doczkal, D. Pous
Graph Theory in Coq 11 / 20
2p-algebras
u (v w) ≡ (u v) w (A1) u v ≡ v u (A2) u ⊤ ≡ u (A3) u·(v·w) ≡ (u·v)·w (A4) u·1 ≡ u (A5) u◦◦ ≡ u (A6) (u v)◦ ≡ u◦ v ◦ (A7) (u·v)◦ ≡ v ◦·u◦ (A8) 1 1 ≡ 1 (A9) dom(u v ◦) ≡ 1 u·v (A10) u·⊤ ≡ dom(u)·⊤ (A11) (1 u)·v ≡ (1 u)·⊤ v (A12)
- C. Doczkal, D. Pous
Graph Theory in Coq 12 / 20
Context Lemmas for Isomorphisms
Two isomorphism “relations”: ≃ on graphs and ≃2 on 2p-graphs adding points: F ≃ G F, x, y ≃2 G, ? x, ? y
- C. Doczkal, D. Pous
Graph Theory in Coq 13 / 20
Context Lemmas for Isomorphisms
Two isomorphism “relations”: ≃ on graphs and ≃2 on 2p-graphs adding points: h : F ≃ G F, x, y ≃2 G, h x, h y
- C. Doczkal, D. Pous
Graph Theory in Coq 13 / 20
Context Lemmas for Isomorphisms
Two isomorphism “relations”: ≃ on graphs and ≃2 on 2p-graphs adding points: h : F ≃ G F, x, y ≃2 G, h x, h y Formalize isomorphisms as computational objects! (and not just the relation of being isomorphic)
- C. Doczkal, D. Pous
Graph Theory in Coq 13 / 20
Context Lemmas for Isomorphisms
Two isomorphism “relations”: ≃ on graphs and ≃2 on 2p-graphs adding points: h : F ≃ G F, x, y ≃2 G, h x, h y under quotients: h : F ≃ G F / /e, π x, π y ≃2 G / /map h e, π(h x), π(h y) Formalize isomorphisms as computational objects! (and not just the relation of being isomorphic)
- C. Doczkal, D. Pous
Graph Theory in Coq 13 / 20
Strategy for Establishing Isomorphisms
lifting quotients to the top: (F / /e) ⊎ G ≃ (F ⊎ G)/ /map inl e F ⊎ (G / /e) ≃ (F ⊎ G)/ /map inr e joining quotients: e′
2 = mapπe2 ⇒ G /
/e1/ /e′
2, π(πx), π(πy) ≃2 G /
/e1 + + e2, πx, πy Eliminating constants (e.g., 1 and ⊤): K edgeless ∀x : K. inr x = inl (f x) [mod e] F ⊎ K / /e, π(inl x), π(inl y) ≃2 F / /map′ f e, πx, πy
- C. Doczkal, D. Pous
Graph Theory in Coq 14 / 20
Demo
dom(G H◦) ≃ 1 G·H
- C. Doczkal, D. Pous
Graph Theory in Coq 15 / 20
Soundness and Completeness
Theorem (Soundness)
If 2p ⊢ u ≡ v, then g(u) ≃ g(v).
- C. Doczkal, D. Pous
Graph Theory in Coq 16 / 20
Soundness and Completeness
Theorem (Soundness)
If 2p ⊢ u ≡ v, then g(u) ≃ g(v). What about completeness?
Theorem (Completeness [Come-Lopez & Pous ’17,Doczkal & Pous’18])
2p ⊢ u ≡ v whenever g(u) ≃ g(v).
- C. Doczkal, D. Pous
Graph Theory in Coq 16 / 20
First approach to Completeness
Theorem (Completeness [Come-Lopez & Pous ’17,Doczkal & Pous’18])
2p ⊢ u ≡ v whenever g(u) ≃ g(v). Extraction function [Come-Lopez & Pous ’17]:
◮ Define t : TW2 → Tm
(TW2 = g(Tm))
◮ Show (1): 2p ⊢ t(g(u)) ≡ u ◮ Show (2): G ≃ H → 2p ⊢ t(G) ≡ t(H) ◮ Conclude: u ≡ t(g(u)) ≡ t(g(v)) ≡ v
- C. Doczkal, D. Pous
Graph Theory in Coq 17 / 20
First approach to Completeness
Theorem (Completeness [Come-Lopez & Pous ’17,Doczkal & Pous’18])
2p ⊢ u ≡ v whenever g(u) ≃ g(v). Extraction function [Come-Lopez & Pous ’17]:
◮ Define t : TW2 → Tm
(TW2 = g(Tm))
◮ Show (1): 2p ⊢ t(g(u)) ≡ u ◮ Show (2): G ≃ H → 2p ⊢ t(G) ≡ t(H) ◮ Conclude: u ≡ t(g(u)) ≡ t(g(v)) ≡ v
Definition of t exploits K4-freeness Formalization requires theory of minors. ITP 2018: Define t and prove g(t(G)) ≃ G. Formalizing (1) and (2) daunting due to many arbitrary (but necessary) choices.
- C. Doczkal, D. Pous
Graph Theory in Coq 17 / 20
Second approach to Completeness
Theorem (Completeness [Come-Lopez & Pous ’17,Doczkal & Pous’18])
2p ⊢ u ≡ v whenever g(u) ≃ g(v). Graph rewriting [Doczkal & Pous’18]:
◮ Generalize to term-labeled graphs (vertices and edges). ◮ Define rewrite system (→) and read off terms from normal graphs. ◮ Show (1): g(u) →∗
u
.
◮ Show (2): → is confluent up to ≡ on the labels. ◮ Thus,
u
←∗ g(u) ≃ g(v) →∗
v
yields 2p ⊢ u ≡ v by confluence up to ≡.
- C. Doczkal, D. Pous
Graph Theory in Coq 18 / 20
Second approach to Completeness
Theorem (Completeness [Come-Lopez & Pous ’17,Doczkal & Pous’18])
2p ⊢ u ≡ v whenever g(u) ≃ g(v). Graph rewriting [Doczkal & Pous’18]:
◮ Generalize to term-labeled graphs (vertices and edges). ◮ Define rewrite system (→) and read off terms from normal graphs. ◮ Show (1): g(u) →∗
u
.
◮ Show (2): → is confluent up to ≡ on the labels. ◮ Thus,
u
←∗ g(u) ≃ g(v) →∗
v
yields 2p ⊢ u ≡ v by confluence up to ≡.
Nondeterminism in definition of → allows proving (1) by induction Requires neither minors nor treewidth
- C. Doczkal, D. Pous
Graph Theory in Coq 18 / 20
Second approach to Completeness
Theorem (Completeness [Come-Lopez & Pous ’17,Doczkal & Pous’18])
2p ⊢ u ≡ v whenever g(u) ≃ g(v). Graph rewriting [Doczkal & Pous’18]:
◮ Generalize to term-labeled graphs (vertices and edges). ◮ Define rewrite system (→) and read off terms from normal graphs. ◮ Show (1): g(u) →∗
u
.
◮ Show (2): → is confluent up to ≡ on the labels. ◮ Thus,
u
←∗ g(u) ≃ g(v) →∗
v
yields 2p ⊢ u ≡ v by confluence up to ≡.
Nondeterminism in definition of → allows proving (1) by induction Requires neither minors nor treewidth Formalization is ongoing work:
◮ Confluence hard to formalize using type-based graphs ◮ Uses “open” graphs (fixed external vertex type) ◮ Requires transferring results between different representations
- C. Doczkal, D. Pous
Graph Theory in Coq 18 / 20
Related Work
Numerous “graph-theory” developments in the literature:
◮ A formal theory of undirected graphs in HOL [Chou ’95] (HOL) ◮ Euler circuits and paths [Nakamura & Rudnicki ’97] (Mizar) ◮ Four-Color Theorem [Gonthier ’08] (Coq) ◮ Delaunay-Triangulation [Dufourd & Bertot ’10] (Coq) ◮ Flyspeck I: tame graphs [Nipkow et al. ’06] (Isabelle/HOL) ◮ A graph library for Isabelle [Noschinski ’15] (Isabelle/HOL) ◮ Edmonds-Karp Algorithm [Lammich & Selfidgar ’16] (Isabelle/HOL) ◮ Domination Chain [Severin ’19] (Coq - uses our definition of graphs)
Specific to our development:
◮ Disjoint unions, quotients, and isomorphisms. ◮ Path library (dependent concatenation, symmetry reasoning) ◮ Minors and treewidth
- C. Doczkal, D. Pous
Graph Theory in Coq 19 / 20
Related Work
Numerous “graph-theory” developments in the literature:
◮ A formal theory of undirected graphs in HOL [Chou ’95] (HOL) ◮ Euler circuits and paths [Nakamura & Rudnicki ’97] (Mizar) ◮ Four-Color Theorem [Gonthier ’08] (Coq) ◮ Delaunay-Triangulation [Dufourd & Bertot ’10] (Coq) ◮ Flyspeck I: tame graphs [Nipkow et al. ’06] (Isabelle/HOL) ◮ A graph library for Isabelle [Noschinski ’15] (Isabelle/HOL) ◮ Edmonds-Karp Algorithm [Lammich & Selfidgar ’16] (Isabelle/HOL) ◮ Domination Chain [Severin ’19] (Coq - uses our definition of graphs)
Specific to our development:
◮ Disjoint unions, quotients, and isomorphisms. ◮ Path library (dependent concatenation, symmetry reasoning) ◮ Minors and treewidth
- C. Doczkal, D. Pous
Graph Theory in Coq 19 / 20
Related Work
Numerous “graph-theory” developments in the literature:
◮ A formal theory of undirected graphs in HOL [Chou ’95] (HOL) ◮ Euler circuits and paths [Nakamura & Rudnicki ’97] (Mizar) ◮ Four-Color Theorem [Gonthier ’08] (Coq) ◮ Delaunay-Triangulation [Dufourd & Bertot ’10] (Coq) ◮ Flyspeck I: tame graphs [Nipkow et al. ’06] (Isabelle/HOL) ◮ A graph library for Isabelle [Noschinski ’15] (Isabelle/HOL) ◮ Edmonds-Karp Algorithm [Lammich & Selfidgar ’16] (Isabelle/HOL) ◮ Domination Chain [Severin ’19] (Coq - uses our definition of graphs)
Specific to our development:
◮ Disjoint unions, quotients, and isomorphisms. ◮ Path library (dependent concatenation, symmetry reasoning) ◮ Minors and treewidth
Coq development is substantial :
◮ about 12000 lines (roughly 2:3 between specifications and proofs) ◮ almost 400 definitions and more than 1000 lemmas ◮ Available online:
https://perso.ens-lyon.fr/damien.pous/covece/graphs
- C. Doczkal, D. Pous
Graph Theory in Coq 19 / 20
Conclusion
Graph theory development
◮ simple graphs ◮ multigraphs ◮ paths, minors, treewidth [ITP 2018] ◮ Menger’s Theorem, Hall’s Marriage Theorem ◮ Equivalence of treewidth two and K4-freeness ◮ compositional reasoning about isomorphisms
Future work:
◮ Finish the completeness proof ◮ improve modularity/compositionality ◮ stabilize the library and release it via OPAM ◮ charaterization of planar graphs using excluded minors
(Kuratowski’s Theorem)
◮ . . .
- C. Doczkal, D. Pous
Graph Theory in Coq 20 / 20
Conclusion
Graph theory development
◮ simple graphs ◮ multigraphs ◮ paths, minors, treewidth [ITP 2018] ◮ Menger’s Theorem, Hall’s Marriage Theorem ◮ Equivalence of treewidth two and K4-freeness ◮ compositional reasoning about isomorphisms
Future work:
◮ Finish the completeness proof ◮ improve modularity/compositionality ◮ stabilize the library and release it via OPAM ◮ charaterization of planar graphs using excluded minors
(Kuratowski’s Theorem)
◮ . . .
Thank You!
- C. Doczkal, D. Pous
Graph Theory in Coq 20 / 20