Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
eeeba14
init
Jun2M Mar 16, 2026
72a23c6
mkall
Jun2M Mar 16, 2026
ab6b965
docs
Jun2M Mar 16, 2026
0e06a4a
inherit_doc
Jun2M Mar 16, 2026
e759a8f
prodDart
Jun2M Mar 16, 2026
391eca7
doc
Jun2M Mar 16, 2026
4d2c7a7
HasDart instances
Jun2M Mar 16, 2026
7a76b33
minor cleanup
Jun2M Mar 16, 2026
0396da0
mk_all
Jun2M Mar 16, 2026
f6b609d
Reflect doc
Jun2M Mar 16, 2026
757ed33
dart_iff_adj
Jun2M Mar 17, 2026
e2efa7c
apply Laura's suggsetions
Jun2M Mar 17, 2026
5a1787d
Reverse of darts
Jun2M Mar 17, 2026
45003bf
update instances
Jun2M Mar 17, 2026
79cfe9b
back to Dart
Jun2M Mar 17, 2026
b9957af
No fix points
Jun2M Mar 17, 2026
8c9442b
DartLike & step
Jun2M Mar 18, 2026
8996b14
doc change
Jun2M Mar 18, 2026
5051f88
mk_all
Jun2M Mar 18, 2026
f2115cb
doc
Jun2M Mar 18, 2026
cbfaa20
dartSym2 & dartSymm
Jun2M Mar 18, 2026
581877d
mv Symm to new PR
Jun2M Mar 18, 2026
8902248
mk_all
Jun2M Mar 18, 2026
0e58e59
build fix
Jun2M Mar 18, 2026
773bdf7
quick save
Jun2M Mar 18, 2026
ffe6e2b
update doc for step
Jun2M Mar 18, 2026
3064d67
Instances
Jun2M Mar 20, 2026
313de21
lint
Jun2M Mar 20, 2026
98ba7c4
lowercase
Jun2M Mar 20, 2026
a73392c
Merge branch 'master' into HasDartDef
Jun2M Mar 21, 2026
99f39d6
rm Graph GraphLike for now
Jun2M Mar 21, 2026
c35faee
mk_all
Jun2M Mar 21, 2026
1586764
accept review feedback
Jun2M Mar 27, 2026
6b57d36
Merge branch 'master' into HasDartDef
Jun2M Mar 27, 2026
e82c435
Merge branch 'master' into HasDartDef
Jun2M Apr 7, 2026
568873d
change type name
Jun2M Apr 7, 2026
285031b
Update Mathlib/Combinatorics/Digraph/GraphLike.lean
Jun2M Apr 7, 2026
24d44ff
Update Mathlib/Combinatorics/SimpleGraph/GraphLike.lean
Jun2M Apr 7, 2026
ae27cff
Type name change
Jun2M Apr 7, 2026
be0121a
Change other files too
Jun2M Apr 7, 2026
46c5063
Merge branch 'master' into HasDartDef
Jun2M Apr 15, 2026
a63ff26
GraphLike per Graph
Jun2M Apr 17, 2026
13cc160
docs
Jun2M Apr 17, 2026
525ad36
Merge branch 'master' into HasDartDef
Jun2M Apr 17, 2026
83d4bdb
docs
Jun2M Apr 17, 2026
c9ddb2a
Merge branch 'master' into HasDartDef
Jun2M Apr 20, 2026
f1badf7
Merge branch 'master' into HasDartDef
Jun2M Apr 25, 2026
2e8ce55
docs
Jun2M Apr 26, 2026
e29bad2
Merge branch 'master' into HasDartDef
Jun2M Apr 27, 2026
c3dff34
Add edge
Jun2M Apr 27, 2026
8ab592c
from simple graph migration PR
Jun2M Apr 29, 2026
a9af2e3
comments from Laura
Jun2M May 6, 2026
e0036cc
better docs
Jun2M May 7, 2026
add3f38
move src & tgt
Jun2M May 7, 2026
bc5b9f7
Break off files into new PR
Jun2M May 7, 2026
9112141
edge
Jun2M May 7, 2026
191d2b2
adj_src_tgt
Jun2M May 8, 2026
16b3ffc
Step with capital S
Jun2M May 8, 2026
dc187e6
name changes
Jun2M May 8, 2026
9a1b5c3
floating darts
Jun2M May 11, 2026
bfbf6af
Source & Target
Jun2M May 11, 2026
18c5d4a
rm Step
Jun2M May 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3465,6 +3465,7 @@ public import Mathlib.Combinatorics.Graph.Basic
public import Mathlib.Combinatorics.Graph.Delete
public import Mathlib.Combinatorics.Graph.Lattice
public import Mathlib.Combinatorics.Graph.Subgraph
public import Mathlib.Combinatorics.GraphLike.Basic
public import Mathlib.Combinatorics.HalesJewett
public import Mathlib.Combinatorics.Hall.Basic
public import Mathlib.Combinatorics.Hall.Finite
Expand Down
103 changes: 103 additions & 0 deletions Mathlib/Combinatorics/GraphLike/Basic.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/-
Copyright (c) 2026 Jun Kwon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jun Kwon
-/
module

public import Mathlib.Data.Sym.Sym2

/-!
# Typeclass for different kinds of graphs

This module defines the typeclass `GraphLike` for capturing the common structure of different kinds
of graph structures including `SimpleGraph`, `Graph`, and `Digraph`.

## Main definitions

* `GraphLike`: is the main typeclass for capturing the common notion of graphs.
The field `verts` gives the set of vertices of a graph-like structure,
the field `darts` gives the set of darts, which is an oriented edge, of a graph-like structure,
the field `edges` gives the set of edges of a graph-like structure,
and the field `Adj` gives the adjacency relation between vertices.
* `darts G` is the direct generalization of `Dart` in `SimpleGraph`.

## Notes

* `GraphLike V D E Gr` generalizes `SimpleGraph`, `Digraph`, and `Graph`. When multi-digraph and
hypergraphs are formalized, they can also use this typeclass.

-/

public section

/-- The `GraphLike` typeclass abstracts over graph-like structures including hypergraphs.
It has vertex and edge sets so subgraph relations can be handled within the same type.
The "darts" terminology comes from combinatorial maps, and they are also known as "half-edges" or
"bonds." They represents the ways an edge can be traversed: if `d` is a dart with `edge d = e`,
`source d = u` and `target d = v` then `d` is walk of length 1 from `u` to `v` with edge `e`. In an
undirected graph, each edge is composed of two darts.
`Adj` is the adjacency relation of a graph-like structure. Two vertices, `u` & `v`, are adjacent iff
there is a dart between them and therefore there is an edge that can be traversed from `u` to `v`.
(See `exists_darts_iff_adj`.) -/
class GraphLike (V D E : outParam Type*) (Gr : Type*) where
/-- The set of vertices of a graph-like structure. -/
verts : Gr → Set V
/-- The set of darts (oriented edges) of a graph-like structure. -/
darts : Gr → Set D
/-- The set of edges of a graph-like structure. -/
edges : Gr → Set E
/-- The source vertex of a dart. -/
source : Gr → D → V
/-- The target vertex of a dart. -/
target : Gr → D → V
/-- The edge of a dart. -/
edge : Gr → D → E
source_mem_of_darts : ∀ ⦃G d⦄, d ∈ darts G → source G d ∈ verts G
target_mem_of_darts : ∀ ⦃G d⦄, d ∈ darts G → target G d ∈ verts G
edge_mem_of_darts : ∀ ⦃G d⦄, d ∈ darts G → edge G d ∈ edges G
/-- The adjacency relation of a graph-like structure. -/
Adj : Gr → V → V → Prop := fun G u v ↦ ∃ d ∈ darts G, source G d = u ∧ target G d = v
/-- Two vertices are adjacent if and only if there is a dart between them. -/
exists_darts_iff_adj : ∀ ⦃G u v⦄, (∃ d ∈ darts G, source G d = u ∧ target G d = v) ↔ Adj G u v

namespace GraphLike

@[inherit_doc verts]
scoped notation "V(" G ")" => verts G

@[inherit_doc darts]
scoped notation "D(" G ")" => darts G

@[inherit_doc edges]
scoped notation "E(" G ")" => edges G

variable {V D E Gr : Type*} {G : Gr} {u u' v v' w : V} {d : D} {e : E}

section GraphLike

variable [GraphLike V D E Gr]

@[ext] theorem darts_ext (d₁ d₂ : D(G)) (h : d₁.val = d₂.val) : d₁ = d₂ := Subtype.ext h

lemma adj_source_target (hd : d ∈ D(G)) : Adj G (source G d) (target G d) :=
exists_darts_iff_adj.mp ⟨d, hd, rfl, rfl⟩

lemma Adj.left_mem (h : Adj G v w) : v ∈ V(G) := by
rw [← exists_darts_iff_adj] at h
obtain ⟨d, hd, rfl, rfl⟩ := h
exact source_mem_of_darts hd

lemma Adj.right_mem (h : Adj G v w) : w ∈ V(G) := by
rw [← exists_darts_iff_adj] at h
obtain ⟨d, hd, rfl, rfl⟩ := h
exact target_mem_of_darts hd

/-- Convert a dart to a pair of vertices. -/
@[expose] def toProd (d : D(G)) : V × V := (source G d.val, target G d.val)

/-- Two darts are said to be adjacent if they could be consecutive darts in a walk -- that is, the
first dart's target is equal to the second dart's source. -/
@[expose] def DartAdj (d d' : D(G)) : Prop := target G d.val = source G d'.val

end GraphLike.GraphLike
Loading