Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 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
7bf9cf1
Walks
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
27cab2a
Merge branch 'HasDartDef' into HasDartProd
Jun2M Mar 16, 2026
7660be0
prodDart all the way
Jun2M Mar 16, 2026
aef5e89
mk_all
Jun2M Mar 16, 2026
f6b609d
Reflect doc
Jun2M Mar 16, 2026
1acab6b
minor fix
Jun2M Mar 16, 2026
d7062bc
doc
Jun2M Mar 17, 2026
ed52ffa
exists_length_eq_one_iff
Jun2M Mar 17, 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
7d1800a
Reflect doc
Jun2M Mar 16, 2026
cbeb431
dart_iff_adj
Jun2M Mar 17, 2026
fa960a2
apply Laura's suggsetions
Jun2M Mar 17, 2026
b49f01c
Reverse of darts
Jun2M Mar 17, 2026
a87ff58
update instances
Jun2M Mar 17, 2026
ade11ce
back to Dart
Jun2M Mar 17, 2026
bde19d2
No fix points
Jun2M Mar 17, 2026
d1a5621
darts
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
04aee94
Merge branch 'HasDartDef' into HasDartProd
Jun2M Mar 18, 2026
e7d13dd
GraphLike
Jun2M Mar 18, 2026
f2115cb
doc
Jun2M Mar 18, 2026
ed70efe
doc
Jun2M Mar 18, 2026
cbfaa20
dartSym2 & dartSymm
Jun2M Mar 18, 2026
581877d
mv Symm to new PR
Jun2M Mar 18, 2026
62f39fd
init
Jun2M Mar 18, 2026
8902248
mk_all
Jun2M Mar 18, 2026
0e84c35
mk_all
Jun2M Mar 18, 2026
0e58e59
build fix
Jun2M Mar 18, 2026
773bdf7
quick save
Jun2M Mar 18, 2026
4edf0cc
Merge branch 'HasDartDef' into HasDartProd
Jun2M Mar 18, 2026
5d5460c
mv file
Jun2M Mar 18, 2026
728055c
Merge branch 'HasDartDef' into SymmGraphLike
Jun2M Mar 18, 2026
8fe1268
mk_all
Jun2M Mar 18, 2026
ffe6e2b
update doc for step
Jun2M Mar 18, 2026
6f45c98
Walk over Prod
Jun2M Mar 19, 2026
fad6117
darts_def
Jun2M Mar 19, 2026
6caf468
save
Jun2M Mar 19, 2026
14ed26b
merge
Jun2M Mar 19, 2026
4958d00
Digraph instance
Jun2M Mar 20, 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
c6206e4
Merge branch 'master' into SymmGraphLike
Jun2M Mar 21, 2026
a36869f
Merge branch 'master' into HasDartProd
Jun2M Mar 21, 2026
087e5b3
init
Jun2M Mar 22, 2026
fbee84d
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Mar 22, 2026
180c199
fix
Jun2M Mar 22, 2026
8aa2e74
archive fix
Jun2M Mar 22, 2026
4293067
Merge branch 'master' into GraphLikeSimpleGraph
Jun2M Mar 24, 2026
8413578
fix
Jun2M Mar 24, 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
4cb77ef
Merge branch 'master' into SymmGraphLike
Jun2M Apr 15, 2026
a63ff26
GraphLike per Graph
Jun2M Apr 17, 2026
13cc160
docs
Jun2M Apr 17, 2026
d4b55f8
Merge branch 'master' into SymmGraphLike
Jun2M Apr 17, 2026
525ad36
Merge branch 'master' into HasDartDef
Jun2M Apr 17, 2026
8000b7c
Merge branch 'HasDartDef' into SymmGraphLike
Jun2M Apr 17, 2026
e61a791
Merge remote-tracking branch 'origin/HasDartDef' into SymmGraphLike
Jun2M Apr 17, 2026
e863a26
save
Jun2M Apr 17, 2026
83d4bdb
docs
Jun2M Apr 17, 2026
c9ddb2a
Merge branch 'master' into HasDartDef
Jun2M Apr 20, 2026
492fb23
update
Jun2M Apr 21, 2026
9ab3d69
Merge remote-tracking branch 'origin/HasDartDef' into SymmGraphLike
Jun2M Apr 21, 2026
9d804ef
update
Jun2M Apr 26, 2026
15d4484
Merge branch 'SymmGraphLike' into HasDartProd
Jun2M Apr 26, 2026
61a7ffa
update
Jun2M Apr 26, 2026
fc7c58e
docs
Jun2M Apr 26, 2026
59491d8
expose DartAdj
Jun2M Apr 26, 2026
f2b1ce8
mk_all
Jun2M Apr 27, 2026
ca32583
Add edge
Jun2M Apr 28, 2026
19b14b4
Merge branch 'HasDartProd' into GraphLikeSimpleGraph
Jun2M Apr 29, 2026
738ed9a
fix 1
Jun2M Apr 29, 2026
0cebcce
Merge remote-tracking branch 'upstream/master' into GraphLikeSimpleGraph
Jun2M Apr 29, 2026
e2e2b60
Merge branch 'master' into GraphLikeSimpleGraph
Jun2M Apr 29, 2026
aca395b
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Apr 29, 2026
1151770
fix done
Jun2M Apr 29, 2026
dd5d8e0
mk_all
Jun2M Apr 29, 2026
4f85b63
import fix
Jun2M Apr 29, 2026
a3c8373
streamline
Jun2M May 7, 2026
b04b807
floating dart
Jun2M May 10, 2026
e346221
Merge branch 'HasDartProd' into GraphLikeSimpleGraph
Jun2M May 10, 2026
25a88b8
floating dart update
Jun2M May 11, 2026
72ef86a
Merge branch 'master' into GraphLikeSimpleGraph
Jun2M May 11, 2026
3420364
docs for SimpleGraph.Adj.toStep
Jun2M May 11, 2026
da970f1
Merge branch 'GraphLikeSimpleGraph' of https://github.com/Jun2M/mathl…
Jun2M May 11, 2026
c33f49d
mk_all
Jun2M May 11, 2026
eb9ce78
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
3 changes: 2 additions & 1 deletion Archive/Wiedijk100Theorems/Konigsberg.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ We show that a graph that represents the islands and mainlands of Königsberg an
between them has no Eulerian trail.
-/

open GraphLike

namespace Konigsberg

Expand Down Expand Up @@ -74,7 +75,7 @@ lemma setOf_odd_degree_eq :
simp [not_even_degree_iff, ← Nat.not_even_iff_odd]

/-- The Königsberg graph is not Eulerian. -/
theorem not_isEulerian {u v : Verts} (p : graph.Walk u v) (h : p.IsEulerian) : False := by
theorem not_isEulerian {u v : Verts} (p : Walk graph u v) (h : p.IsEulerian) : False := by
have h := h.card_odd_degree
have h' := setOf_odd_degree_eq
apply_fun Fintype.card at h'
Expand Down
5 changes: 5 additions & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,9 @@ public import Mathlib.Combinatorics.Graph.Delete
public import Mathlib.Combinatorics.Graph.Lattice
public import Mathlib.Combinatorics.Graph.Maps
public import Mathlib.Combinatorics.Graph.Subgraph
public import Mathlib.Combinatorics.GraphLike.Basic
public import Mathlib.Combinatorics.GraphLike.Walks.Basic
public import Mathlib.Combinatorics.GraphLike.Walks.Simple
public import Mathlib.Combinatorics.HalesJewett
public import Mathlib.Combinatorics.Hall.Basic
public import Mathlib.Combinatorics.Hall.Finite
Expand Down Expand Up @@ -3594,6 +3597,7 @@ public import Mathlib.Combinatorics.SimpleGraph.Finite
public import Mathlib.Combinatorics.SimpleGraph.Finsubgraph
public import Mathlib.Combinatorics.SimpleGraph.FiveWheelLike
public import Mathlib.Combinatorics.SimpleGraph.Girth
public import Mathlib.Combinatorics.SimpleGraph.GraphLike
public import Mathlib.Combinatorics.SimpleGraph.Hall
public import Mathlib.Combinatorics.SimpleGraph.Hamiltonian
public import Mathlib.Combinatorics.SimpleGraph.Hasse
Expand Down Expand Up @@ -7295,6 +7299,7 @@ public import Mathlib.Tactic.Set
public import Mathlib.Tactic.SetLike
public import Mathlib.Tactic.SimpIntro
public import Mathlib.Tactic.SimpRw
public import Mathlib.Tactic.Simproc.CastData
public import Mathlib.Tactic.Simproc.Divisors
public import Mathlib.Tactic.Simproc.ExistsAndEq
public import Mathlib.Tactic.Simproc.Factors
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/CategoryTheory/Sites/IsSheafFor.lean
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ noncomputable def shrinkFunctorHomEquiv [LocallySmall.{w} C] {F : Cᵒᵖ ⥤ Ty
ext
dsimp
rw! [Equiv.apply_symm_apply]
simp
rfl

@[deprecated "In terms of `Sieve.shrinkFunctor`" (since := "2026-03-13")]
alias natTransEquivCompatibleFamily := shrinkFunctorHomEquiv
Expand Down
240 changes: 240 additions & 0 deletions Mathlib/Combinatorics/GraphLike/Basic.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/-
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.
* `NoMultiEdgeGraphLike`: is the typeclass for graph-like structures with no multi-edge.
* `SymmGraphLike`: extends `GraphLike` for graph-like structures with symmetric darts.
* `noMultiEdgeSymmGraphLike`: extends `SymmGraphLike` and `NoMultiEdgeGraphLike` for graph-like
structures with no multi-edge and symmetric darts.

## 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
obtain ⟨d, hd, rfl, rfl⟩ := exists_darts_iff_adj.mpr h
exact source_mem_of_darts hd

lemma Adj.right_mem (h : Adj G v w) : w ∈ V(G) := by
obtain ⟨d, hd, rfl, rfl⟩ := exists_darts_iff_adj.mpr 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

section noMultiEdgeGraphLike

/-
### GraphLike with no multi-edge

Some graph-like structures, such as `SimpleGraph` and `Digraph`, does not allow multiple darts/edges
between the same pair of vertices. This section defines a typeclass `NoMultiEdgeGraphLike` for such
graph-like structures.
-/

/-- A graph-like structure with no multi-edge. This includes `SimpleGraph` and `Digraph`. -/
class NoMultiEdgeGraphLike (V D E : outParam Type*) (Gr : Type*) extends GraphLike V D E Gr where
protected src_tgt_inj (G : Gr) : Function.Injective fun d ↦ (source G d, target G d)

variable [NoMultiEdgeGraphLike V D E Gr]

lemma dart_eq_of_src_tgt_eq {d₁ d₂ : D} (h : source G d₁ = source G d₂)
(h' : target G d₁ = target G d₂) : d₁ = d₂ := by
apply NoMultiEdgeGraphLike.src_tgt_inj G
grind

lemma src_tgt_inj (d₁ d₂ : D) : source G d₁ = source G d₂ ∧ target G d₁ = target G d₂ ↔ d₁ = d₂ :=
⟨fun h => dart_eq_of_src_tgt_eq h.1 h.2, by grind⟩

@[simp]
lemma mem_darts_iff_adj : d ∈ D(G) ↔ Adj G (source G d) (target G d) := by
rw [← exists_darts_iff_adj]
refine ⟨fun h => (by use d), fun ⟨d', hd', hs, ht⟩ => ?_⟩
obtain rfl := src_tgt_inj d' d |>.mp ⟨hs, ht⟩
exact hd'

instance [DecidableRel (Adj G)] : DecidablePred (· ∈ D(G)) :=
fun d => decidable_of_iff (Adj G (source G d) (target G d)) mem_darts_iff_adj.symm

end noMultiEdgeGraphLike

section SymmGraphLike

/-- `SymmGraphLike` extends `GraphLike` for graph-like structures where darts are symmetric. -/
class SymmGraphLike (V D E : outParam Type*) (Gr : Type*) extends GraphLike V D E Gr where
/-- The inverse of a dart. -/
inv : D → D
inv_invol : ∀ ⦃d⦄, inv (inv d) = d
inv_source (G : Gr) (d : D) : source G (inv d) = (target G d : V)
inv_target (G : Gr) (d : D) : target G (inv d) = (source G d : V)
inv_ne : ∀ ⦃G d⦄, d ∈ darts G → inv d ≠ d
inv_mem_darts_iff : ∀ ⦃G d⦄, inv d ∈ darts G ↔ d ∈ darts G
edge_eq_edge_iff : ∀ ⦃G d d'⦄, d ∈ darts G → d' ∈ darts G →
(edge G d = edge G d' ↔ d = d' ∨ inv d = d')

open SymmGraphLike

attribute [simp, grind =] inv_invol inv_source inv_target inv_mem_darts_iff
attribute [grind →] inv_ne

variable [SymmGraphLike V D E Gr]

lemma inv_mem_darts (hd : d ∈ D(G)) : inv Gr d ∈ D(G) := inv_mem_darts_iff.mpr hd

instance : Std.Symm (Adj G) where
symm _ _ h := by
rw [← exists_darts_iff_adj] at h ⊢
obtain ⟨d, hd, rfl, rfl⟩ := h
exact ⟨SymmGraphLike.inv Gr d, inv_mem_darts hd, inv_source G d, inv_target G d⟩

@[symm] lemma Adj.symm (h : Adj G v w) : Adj G w v := symm_of (Adj G) h

lemma adj_comm : Adj G v w ↔ Adj G w v := ⟨symm_of (Adj G), symm_of (Adj G)⟩

lemma adj_tgt_src (hd : d ∈ D(G)) : Adj G (target G d) (source G d) :=
(adj_source_target hd).symm

/-- The two vertices of the dart as an unordered pair. -/
@[expose] def dartSym2 (d : D(G)) : Sym2 V := s(source G d.val, target G d.val)

@[simp]
theorem dartSym2_mk (h : d ∈ D(G)) : dartSym2 (⟨d, h⟩ : D(G)) = s(source G d, target G d) := rfl

/-- The dart with reversed orientation from a given dart. -/
@[expose] def dartSymm (d : D(G)) : D(G) := ⟨inv Gr d.val, inv_mem_darts_iff.mpr d.prop⟩

@[simp]
theorem dartSymm_mk (h : d ∈ D(G)) : dartSymm (⟨d, h⟩) = ⟨inv Gr d, inv_mem_darts_iff.mpr h⟩ := rfl

@[simp]
theorem dartSym2_inv (d : D(G)) : dartSym2 (dartSymm d) = dartSym2 d := by
simp [dartSym2, dartSymm]

@[simp]
theorem dartSym2_comp_inv : dartSym2 ∘ dartSymm = (dartSym2 : D(G) → Sym2 _) :=
funext dartSym2_inv

@[simp]
theorem dartSymm_dartSymm (d : D(G)) : dartSymm (dartSymm d) = d :=
darts_ext _ _ <| by simp [dartSymm]

@[simp]
theorem dartSymm_involutive : Function.Involutive (dartSymm : D(G) → D(G)) :=
dartSymm_dartSymm

theorem dartSym2_eq_mk'_iff {d : D(G)} :
dartSym2 d = s(u, v) ↔ toProd d = (u, v) ∨ toProd d = (v, u) := by
obtain ⟨p, hp⟩ := d
simp [toProd]

theorem dartSym2_eq_mk'_iff' {d : D(G)} : dartSym2 d = s(u, v) ↔
source G d.val = u ∧ target G d.val = v ∨ source G d.val = v ∧ target G d.val = u := by
obtain ⟨p, hp⟩ := d
simp

end SymmGraphLike

section noMultiEdgeGraphLike

open SymmGraphLike

/-- A graph-like structure with no multi-edge and symmetric darts. -/
class noMultiEdgeSymmGraphLike (V D E : outParam Type*) (Gr : Type*) extends
SymmGraphLike V D E Gr, NoMultiEdgeGraphLike V D E Gr where

@[simp]
theorem dartSym2_eq_iff [noMultiEdgeSymmGraphLike V D E Gr] (d₁ d₂ : D(G)) :
dartSym2 d₁ = dartSym2 d₂ ↔ d₁ = d₂ ∨ d₁ = dartSymm d₂ := by
obtain ⟨p, hp⟩ := d₁
obtain ⟨q, hq⟩ := d₂
simp only [dartSym2_mk, Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk,
Subtype.mk.injEq, dartSymm_mk]
refine ⟨?_, by rintro (rfl | rfl) <;> simp⟩
rintro (⟨h1, h2⟩ | ⟨h1, h2⟩)
· exact Or.inl <| dart_eq_of_src_tgt_eq h1 h2
exact Or.inr <| dart_eq_of_src_tgt_eq (inv_source G q ▸ h1) (inv_target G q ▸ h2)

end noMultiEdgeGraphLike

end GraphLike
Loading
Loading