Skip to content

feat(Combinatorics): define HasAdj for capturing the common structure of different kinds of (simple) graphs#35776

Closed
IvanRenison wants to merge 4 commits intoleanprover-community:masterfrom
IvanRenison:HasAdj
Closed

feat(Combinatorics): define HasAdj for capturing the common structure of different kinds of (simple) graphs#35776
IvanRenison wants to merge 4 commits intoleanprover-community:masterfrom
IvanRenison:HasAdj

Conversation

@IvanRenison
Copy link
Copy Markdown
Collaborator

@IvanRenison IvanRenison commented Feb 25, 2026

We add a vertex set considering that we want to refactor SimpleGraph to also use one


This pr replaces #4127
Zulip discussion: https://leanprover.zulipchat.com/#narrow/channel/252551-graph-theory/topic/HasAdj/with/575843445

Open in Gitpod

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 25, 2026

PR summary 9b809f3970

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Combinatorics.HasAdj.Basic (new file) 214
Mathlib.Combinatorics.Digraph.HasAdj (new file) 502
Mathlib.Combinatorics.SimpleGraph.HasAdj (new file) 524

Declarations diff

+ Adj.left_mem_verts
+ Adj.right_mem_verts
+ HasAdj
+ instance : HasAdj α (Digraph α)
+ instance : HasAdj α (SimpleGraph α)

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for scripts/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Combinatorics.Graph.Adj, even though it's not restricted to Graph? Combinatorics as a folder is definitely too generic for this!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you merge this with Digraph.Basic? Same for SimpleGraph

@[expose] public section

/-- Typeclass for (simple) graphs. -/
class HasAdj (α : outParam Type*) (Gr : Type*) where
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class HasAdj (α : outParam Type*) (Gr : Type*) where
class HasAdj (V : outParam Type*) (E : Type*) where

no?

Comment on lines +35 to +37
/-- There is no edge of the graph outside of it vertices. -/
left_mem_verts_of_adj {G : Gr} {v w : α} (h : Adj G v w) : v ∈ verts G
/-- There is no edge of the graph outside of it vertices. -/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/-- There is no edge of the graph outside of it vertices. -/
left_mem_verts_of_adj {G : Gr} {v w : α} (h : Adj G v w) : v ∈ verts G
/-- There is no edge of the graph outside of it vertices. -/
/-- There is no edge of the graph outside of its vertices. -/
left_mem_verts_of_adj {G : Gr} {v w : α} (h : Adj G v w) : v ∈ verts G
/-- There is no edge of the graph outside of its vertices. -/

@YaelDillies
Copy link
Copy Markdown
Contributor

Do you have more code depending on this somewhere, so that we can tell whether this is a viable approach? eg have you tried refactoring the SimpleGraph API to use this?

@IvanRenison
Copy link
Copy Markdown
Collaborator Author

I made #35783 and #35831, however, after discussion in Zulip, I think we are replacing this pr by #36743

@IvanRenison
Copy link
Copy Markdown
Collaborator Author

#36743 is replacing this pr

@YaelDillies YaelDillies removed their assignment Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-combinatorics Combinatorics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants