The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Simproc.IsIndecomposable
34 declarations. Mathlib docs · Source
Simproc deciding Matrix.IsIndecomposable
Matrix.reduceIsIndecomposable rewrites M.IsIndecomposable to True or False for a closed
square matrix literal M indexed by Fin n. This requires a kernel-decidable equality for the
matrix entry type.
This is equivalent to determining whether the directed graph corresponding to M is strongly
connected.
Main definitions
Matrix.reduceIsIndecomposable: the simproc decidingM.IsIndecomposable.SpansFrom: states that every vertex is visited following a list of edges starting from a root.isClosed: tests whether a set of vertices has no edges leaving it.packedAdj: a Boolean adjacency matrix stored as the bits of a natural number computed from a matrix literal bypackRows.decideStronglyConnected: searches the graph from and to vertex0, returning two spanning trees or a closed set of vertices.
Implementation notes
This simproc simply runs two bfs on the graph from vertex 0 forwards and
backwards. If all vertices are reached in both passes, then the indecomposability is certified by
the two search trees. Otherwise, M is decomposable, witnessed by a set of rows whose entries
outside the set evaluate to 0.
There is an existing implementation of Tarjan's algorithm at Tactic.Order.Graph.findSCCs, but it
doesn't return a witness for the strongly connected components, and the algorithm is also an
overkill.
The Boolean adjacency matrix of a !![…] literal is packed into one natural number, with entry
(i, j) at bit i * n + j, and both certificates are checked against that number, since reading
the literal by position costs the kernel a walk per entry.
Reachability in a Boolean adjacency matrix
Closed sets of vertices in a Boolean adjacency matrix, and the packed version
Certificates for a matrix from its Boolean adjacency matrix
The Boolean adjacency matrix of a matrix literal
theorem Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.disconnected.injEq E0 #
∀ (closedSet closedSet_1 : Array Bool),
(Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.disconnected closedSet =
Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.disconnected closedSet_1) =
(closedSet = closedSet_1)
abbrev Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.ctorElimType E1 #
{motive : Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult → Sort u} → ℕ → Sort (max 1 u)
theorem Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.connected.injEq E0 #
∀ (outTree inTree outTree_1 inTree_1 : Array (ℕ × ℕ)),
(Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.connected outTree inTree =
Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.connected outTree_1 inTree_1) =
(outTree = outTree_1 ∧ inTree = inTree_1)
def Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.ctorIdx E1 #
Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult → ℕ
theorem Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.connected.inj E1 #
∀ {outTree inTree outTree_1 inTree_1 : Array (ℕ × ℕ)},
Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.connected outTree inTree =
Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.connected outTree_1 inTree_1 →
outTree = outTree_1 ∧ inTree = inTree_1
theorem Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.disconnected.inj E1 #
∀ {closedSet closedSet_1 : Array Bool},
Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.disconnected closedSet =
Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.disconnected closedSet_1 →
closedSet = closedSet_1
theorem Mathlib.Tactic.Matrix.IsIndecomposable.packRow.congr_simp E1 #
∀ {R : Type u_1} [inst : Zero R] {inst_1 : DecidableEq R} [inst_2 : DecidableEq R] (row row_1 : List R),
row = row_1 →
Mathlib.Tactic.Matrix.IsIndecomposable.packRow row = Mathlib.Tactic.Matrix.IsIndecomposable.packRow row_1
theorem Mathlib.Tactic.Matrix.IsIndecomposable.packRows.congr_simp E1 #
∀ {R : Type u_1} [inst : Zero R] {inst_1 : DecidableEq R} [inst_2 : DecidableEq R] (n n_1 : ℕ),
n = n_1 →
∀ (rows rows_1 : List (List R)),
rows = rows_1 →
Mathlib.Tactic.Matrix.IsIndecomposable.packRows n rows =
Mathlib.Tactic.Matrix.IsIndecomposable.packRows n_1 rows_1
def Mathlib.Tactic.Matrix.IsIndecomposable.reached E1 #
{n : ℕ} → (Fin n → Fin n → Bool) → ℕ → List (Fin n × Fin n) → ℕ
The vertices reached from the set bits of s by following the edges es in order. An edge
counts only when it leaves a vertex already reached and is an edge of adj.
theorem Mathlib.Tactic.Matrix.IsIndecomposable.reflTransGen_of_testBit_reached E1 #
∀ {n : ℕ} {adj : Fin n → Fin n → Bool} {root : Fin n} {s : ℕ} {es : List (Fin n × Fin n)},
(∀ (v : Fin n), s.testBit ↑v = true → Relation.ReflTransGen (fun i j ↦ adj i j = true) root v) →
∀ {v : Fin n},
(Mathlib.Tactic.Matrix.IsIndecomposable.reached adj s es).testBit ↑v = true →
Relation.ReflTransGen (fun i j ↦ adj i j = true) root v
abbrev Mathlib.Tactic.Matrix.IsIndecomposable.SpansFrom E3 #
{n : ℕ} → (Fin n → Fin n → Bool) → List (Fin n × Fin n) → Fin n → Prop
The edges es in order reach every vertex of adj starting from root.
theorem Mathlib.Tactic.Matrix.IsIndecomposable.SpansFrom.reflTransGen E1 #
∀ {n : ℕ} {adj : Fin n → Fin n → Bool} {es : List (Fin n × Fin n)} {root : Fin n},
Mathlib.Tactic.Matrix.IsIndecomposable.SpansFrom adj es root →
∀ (v : Fin n), Relation.ReflTransGen (fun i j ↦ adj i j = true) root v
If adj has a spanning list of edges from root, then root reaches every vertex.
def Mathlib.Tactic.Matrix.IsIndecomposable.isClosed E3 #
{n : ℕ} → (Fin n → Fin n → Bool) → ℕ → Bool
Whether no edge of adj leaves the set of vertices given by the set bits of s.
def Mathlib.Tactic.Matrix.IsIndecomposable.packedAdj E3 #
(n : ℕ) → ℕ → Fin n → Fin n → Bool
Entry (i, j) of the n × n Boolean adjacency matrix represented by bits.
def Mathlib.Tactic.Matrix.IsIndecomposable.isClosedPacked E1 #
ℕ → ℕ → ℕ → Bool
Whether no edge of the n × n Boolean adjacency matrix represented by bits leaves the set
of vertices given by the set bits of s. Each row of bits is read at once.
theorem Mathlib.Tactic.Matrix.IsIndecomposable.isClosed_of_isClosedPacked E1 #
∀ {n bits s : ℕ},
Mathlib.Tactic.Matrix.IsIndecomposable.isClosedPacked n bits s = true →
Mathlib.Tactic.Matrix.IsIndecomposable.isClosed (Mathlib.Tactic.Matrix.IsIndecomposable.packedAdj n bits) s = true
theorem Mathlib.Tactic.Matrix.IsIndecomposable.isIndecomposable_of_spansFrom E1 #
∀ {R : Type u_1} [inst : Zero R] {n : ℕ} {M : Matrix (Fin n) (Fin n) R} {adj : Fin n → Fin n → Bool},
(∀ (i j : Fin n), adj i j = true ↔ M i j ≠ 0) →
∀ {root : Fin n} {fwd bwd : List (Fin n × Fin n)},
Mathlib.Tactic.Matrix.IsIndecomposable.SpansFrom adj fwd root →
Mathlib.Tactic.Matrix.IsIndecomposable.SpansFrom (Function.swap adj) bwd root → M.IsIndecomposable
If both adj and its reverse have spanning edge lists from root, then M is
indecomposable (strong connectivity of adj).
theorem Mathlib.Tactic.Matrix.IsIndecomposable.not_isIndecomposable_of_isClosed E1 #
∀ {R : Type u_1} [inst : Zero R] {n : ℕ} {M : Matrix (Fin n) (Fin n) R} {adj : Fin n → Fin n → Bool},
(∀ (i j : Fin n), adj i j = true ↔ M i j ≠ 0) →
∀ {s : ℕ},
Mathlib.Tactic.Matrix.IsIndecomposable.isClosed adj s = true →
∀ {i j : Fin n}, s.testBit ↑i ≠ s.testBit ↑j → ¬M.IsIndecomposable
If adj has a nonempty proper subset of vertices that is closed, then M is decomposable.
def Mathlib.Tactic.Matrix.IsIndecomposable.packRow E1 #
{R : Type u_1} → [Zero R] → [DecidableEq R] → List R → ℕ
The nonzero entries of row, as the set bits of a natural number.
def Mathlib.Tactic.Matrix.IsIndecomposable.packRows E3 #
{R : Type u_1} → [Zero R] → [DecidableEq R] → ℕ → List (List R) → ℕ
The Boolean adjacency matrix of rows interpreted as an n × n matrix, as the set bits of a
natural number with entry (i, j) at bit i * n + j.
theorem Mathlib.Tactic.Matrix.IsIndecomposable.testBit_packRow E1 #
∀ {R : Type u_1} [inst : Zero R] [inst_1 : DecidableEq R] (row : List R) (j : ℕ),
(Mathlib.Tactic.Matrix.IsIndecomposable.packRow row).testBit j = decide (row.getD j 0 ≠ 0)
theorem Mathlib.Tactic.Matrix.IsIndecomposable.testBit_packRows E1 #
∀ {R : Type u_1} [inst : Zero R] [inst_1 : DecidableEq R] {n : ℕ} (rows : List (List R)) (i : ℕ) {j : ℕ},
j < n →
(Mathlib.Tactic.Matrix.IsIndecomposable.packRows n rows).testBit (i * n + j) =
decide ((rows.getD i []).getD j 0 ≠ 0)
theorem Mathlib.Tactic.Matrix.IsIndecomposable.packedAdj_packRows_iff E0 #
∀ {R : Type u_1} [inst : Zero R] [inst_1 : DecidableEq R] {n : ℕ} (rows : List (List R)) (i j : Fin n),
Mathlib.Tactic.Matrix.IsIndecomposable.packedAdj n (Mathlib.Tactic.Matrix.IsIndecomposable.packRows n rows) i j =
true ↔
Mathlib.Tactic.Matrix.ofLists n n rows i j ≠ 0
def Mathlib.Tactic.Matrix.IsIndecomposable.bfs E1 #
ℕ → (ℕ → ℕ → Bool) → ℕ → Array (ℕ × ℕ) × Array Bool
Breadth-first search from root along adj, returning the tree edges in discovery order and
the reached vertices.
def Mathlib.Tactic.Matrix.IsIndecomposable.mkEdgeListLitQ E1 #
(n : ℕ) → Array (ℕ × ℕ) → Lean.MetaM Q(List (Fin «$n» × Fin «$n»))
The list literal of the edges edges.
inductive Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult E1 #
Type
The outcome of searching a directed graph from and to vertex 0.
ctor Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.connected E0 #
Array (ℕ × ℕ) → Array (ℕ × ℕ) → Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult
The graph is strongly connected, with the spanning out-tree outTree from 0 and in-tree
inTree to 0.
ctor Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult.disconnected E0 #
Array Bool → Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult
The graph is not strongly connected. No edge leaves the nonempty proper set of vertices
closedSet.
def Mathlib.Tactic.Matrix.IsIndecomposable.decideStronglyConnected E3 #
Array (Array Bool) → Mathlib.Tactic.Matrix.IsIndecomposable.StrongConnectivityResult
Search the directed graph with Boolean adjacency matrix adjMatrix from and to vertex 0.
def Mathlib.Tactic.Matrix.IsIndecomposable.evalAdjMatrix? E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
Q(Zero «$α») → Q(DecidableEq «$α») → ℕ → Q(List (List «$α»)) → Lean.MetaM (Option (Array (Array Bool)))
The Boolean adjacency matrix of the matrix with rows lit evaluated by the kernel. Returns
none if the kernel cannot decide which entries are zero.
The kernel evaluates the packed number packRows n lit and then unpacks the boolean adjacency
matrix from the bits. This round trip evaluates every entry in one Kernel.whnf call instead
of needing a call per cell (about 2.5x the cost).
def Mathlib.Tactic.Matrix.IsIndecomposable.certifyIsIndecomposable E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(zα : Q(Zero «$α»)) →
Q(DecidableEq «$α») →
(n : ℕ) →
(lit : Q(List (List «$α»))) →
Array (ℕ × ℕ) →
Array (ℕ × ℕ) → Lean.MetaM Q((Mathlib.Tactic.Matrix.ofLists «$n» «$n» «$lit»).IsIndecomposable)
Prove that lit interpreted as an n × n matrix is indecomposable using the spanning
out-tree outTree from vertex 0 and the in-tree inTree to it in its graph.
def Mathlib.Tactic.Matrix.IsIndecomposable.certifyNotIsIndecomposable E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
(zα : Q(Zero «$α»)) →
Q(DecidableEq «$α») →
(n : ℕ) →
(lit : Q(List (List «$α»))) →
Array Bool → Lean.MetaM Q(¬(Mathlib.Tactic.Matrix.ofLists «$n» «$n» «$lit»).IsIndecomposable)
Prove that lit interpreted as an n × n matrix is decomposable from a nonempty proper
set closedSet of vertices that no edge of its graph leaves.
def Mathlib.Tactic.Matrix.IsIndecomposable.reduceIsIndecomposableCore E1 #
Lean.Meta.Simp.Simproc
Core of the Matrix.reduceIsIndecomposable simproc.
def Matrix.reduceIsIndecomposable E3 #
Lean.Meta.Simp.Simproc
Matrix.reduceIsIndecomposable decides M.IsIndecomposable for a closed matrix literal M
indexed by Fin n with n a numeral, whose entry type has an equality the kernel can decide.