mathlib icon indicating copy to clipboard operation
mathlib copied to clipboard

feat(combinatorics/simple_graph/inc_matrix): Oriented incidence matrix

Open gabrielmoise opened this issue 4 years ago • 16 comments

and graph orientations.


The intention of this file is to create the oriented incidence matrix, together with some useful (I assume) lemmas and theorems for later use in other areas.

Open in Gitpod

gabrielmoise avatar May 04 '21 17:05 gabrielmoise

so sorry your PR has been basically left open forever, here are some comments. I'll look at N(o) later, but I think it's better you get to see some of these first

Hello! There is no worries about that, I am sure there are a lot of PRs in similar situations and there's a lot of workload. I wanted to say that, if this is fine for you, I will take a look into the PR after the 18th of June, since then I finish the exam session. Thanks for the feedback! 😄

gabrielmoise avatar Jun 01 '21 14:06 gabrielmoise

No worries, best of luck! I'll try finish the review by then :)

ericrbg avatar Jun 01 '21 17:06 ericrbg

@gabrielmoise Good luck with your exams. When you've updated your PR, please ping us on zulip so that we can review again. (For now I've labelled it WIP and awaiting-author.)

jcommelin avatar Jun 07 '21 12:06 jcommelin

Thank you so much for waiting! And also thanks for the support towards my exams! They went fine :smile:!

gabrielmoise avatar Jun 22 '21 08:06 gabrielmoise

Wow it took me long to catch the obvious! You're not defining the incidence matrix but the adjacency matrix. Here ya go for a round of renaming 😅 EDIT: This is wrong. I got completely confused.

YaelDillies avatar Jul 12 '21 18:07 YaelDillies

isn't the adj matrix V × V? I think this is V × E

ericrbg avatar Jul 12 '21 18:07 ericrbg

Wow it took me long to catch the obvious! You're not defining the incidence matrix but the adjacency matrix. Here ya go for a round of renaming

No, I am defining the incidence matrix. The adjacency matrix is already in the standard library as adj_matrix.

gabrielmoise avatar Jul 13 '21 08:07 gabrielmoise

ping? @gabrielmoise - should we take over from you?

dimpase avatar Nov 02 '21 11:11 dimpase

ping? @gabrielmoise - should we take over from you?

Hello!

Sorry for my inactivity! I was very busy lately with applications for internships and with university work. Yes, I would be very happy if you would take over from me. :)

Thanks a lot for the help!

gabrielmoise avatar Nov 03 '21 19:11 gabrielmoise

Does anyone active on this PR see an easy way forward here? It was a part of @gabrielmoise 's project I supervised (and thus I feel like it should not be let to bitrot), but I'm not really familiar with most details here.

dimpase avatar Nov 03 '21 22:11 dimpase

I have already many pans on the stove, but I could take that one too. For having reviewed this PR quite thoroughly, I know what"s to be fixed and can probably make it mergeable rather quickly. Any help remains welcome!

YaelDillies avatar Nov 03 '21 23:11 YaelDillies

I think it would be good to split off a new PR of just the stuff about unoriented incidence matrices. Things about orientations and oriented incidence matrices can wait in this PR until then. (These still need some thought for how they'll interact with the rest of the library.)

I remember there were some theorems in this gist that would be good to include (the gist has the gist of unoriented incidence matrices, originally based on this PR). The combinatorics.simple_graph.adj_matrix module could probably be used as a model.

kmill avatar Nov 03 '21 23:11 kmill

just the stuff about unoriented incidence matrices

The main reason for oriented incidence matrices to appear here is that it's the most direct way to get the Laplacian matrix of the graph. The latter didn't make it to this PR, though.

dimpase avatar Nov 03 '21 23:11 dimpase

@dimpase I get that (and I very much want that factorization of the Laplacian matrix) -- what I've been thinking is that orientations should probably come from simple_digraph, which doesn't exist yet. There's a map simple_digraph V -> simple_graph V from forgetting orientations, or rather from symmetrizing the adj relation.

kmill avatar Nov 04 '21 00:11 kmill

It might also be OK for orientations to be their own thing. I'd suggest changing the definition, though, to something that is closer to the definition of simple_graph. Here's a possibility, along with a reimplementation of the old projections in terms of it:

structure orientation (G : simple_graph V) :=
(fwd : V → V → Prop)
(fwd_adj : ∀ v w, fwd v w → G.adj v w)
(neg_fwd_iff_fwd : ∀ v w, ¬fwd v w ↔ fwd w v)

namespace orientation
variables {G} (o : G.orientation)
variables [decidable_eq V] [decidable_rel o.fwd]

def orient (e : G.edge_set) : V × V :=
sym2.lift ⟨λ v w, if o.fwd v w then (v, w) else (w, v),
λ v w, by { rw ←ite_not, simp [o.neg_fwd_iff_fwd] }⟩ e.val

@[simp] lemma orient_prop (e : G.edge_set) : ⟦o.orient e⟧ = e :=
begin
  cases e with e h,
  induction e using quotient.ind,
  cases e with v w,
  by_cases hf : o.fwd v w;
  simp [orient, hf, -quotient.eq, sym2.eq_swap],
end

def head (e : G.edge_set) : V := (o.orient e).1

def tail (e : G.edge_set) : V := (o.orient e).2

@[simp] lemma consistent (e : G.edge_set) : ⟦(o.head e, o.tail e)⟧ = e :=
begin
  cases e with e h,
  induction e using quotient.ind,
  simp [head, tail, orient_prop],
end

end orientation

kmill avatar Nov 04 '21 01:11 kmill

@RaduEu

dimpase avatar Nov 04 '21 13:11 dimpase