The ordered-clique graph and its contraction sequence
Lax528502.CliqueConstruction · concepts/Lax528502/CliqueConstruction.lean · lax-528502
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Lemma
The disjoint paths reduction assigns a position to each vertex and each arc, and one extra position to the dummy vertex. Incoming and outgoing arcs are processed in topological order by optional exchanges of two positions. Copies of the ordered cliques align each modified crossing edge with a block boundary. After deleting the dummy, merge the prefixes of the blocks from right to left and then contract consecutive blocks (Section 5).
Concept map
In the paper
- page 16 of this submission's paper
Lean source view on GitHub
| 1 | import Lax528502.DisjointPaths |
| 2 | import Lax528502.ColoringGadgets |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: The ordered-clique graph and its contraction sequence |
| 7 | type: lemma |
| 8 | --- |
| 9 | The disjoint paths reduction assigns a position to each vertex and each arc, |
| 10 | and one extra position to the dummy vertex. Incoming and outgoing arcs are |
| 11 | processed in topological order by optional exchanges of two positions. |
| 12 | Copies of the ordered cliques align each modified crossing edge with a block |
| 13 | boundary. After deleting the dummy, merge the prefixes of the blocks from |
| 14 | right to left and then contract consecutive blocks (Section 5). |
| 15 | -/ |
| 16 | |
| 17 | namespace Lax528502.CliqueConstruction |
| 18 | |
| 19 | open ColoringGadgets |
| 20 | |
| 21 | abbrev Step := EdgePattern ℕ |
| 22 | |
| 23 | /-- Exchange p and q optionally, restoring every intermediate position. -/ |
| 24 | def exchange (p q : ℕ) : List Step := |
| 25 | let moves := (List.range (q - p - 1)).map fun i => |
| 26 | EdgePattern.swap (p + i) (p + i + 1) |
| 27 | moves ++ [.choice (q - 1) q] ++ moves.reverse |
| 28 | |
| 29 | structure Plan where |
| 30 | colors : ℕ |
| 31 | steps : List Step |
| 32 | |
| 33 | /-- Number sources, sinks, and old vertices, add private terminal arcs, and |
| 34 | process the vertices in a topological order. All positions start at 0. -/ |
| 35 | def plan (n : ℕ) (arcs terminals : List (ℕ × ℕ)) : Plan := |
| 36 | let pairs := terminals.zipIdx |
| 37 | let old := fun v => 2 * terminals.length + v |
| 38 | let vertices := pairs.map (fun (_, h) => 2*h) ++ (List.range n).map old ++ |
| 39 | pairs.map (fun (_, h) => 2*h+1) |
| 40 | let edges := pairs.map (fun ((s,_), h) => (2*h, old s)) ++ |
| 41 | arcs.map (fun (u,v) => (old u, old v)) ++ pairs.map (fun ((_,t), h) => (old t, 2*h+1)) |
| 42 | let indexed := edges.zipIdx |
| 43 | let transfers := fun v (arcsAtVertex : List ((ℕ × ℕ) × ℕ)) => |
| 44 | arcsAtVertex.flatMap fun (_, i) => exchange v (vertices.length + i) |
| 45 | let route := vertices.flatMap fun v => |
| 46 | transfers v (indexed.filter fun ((_,t), _) => t == v) ++ |
| 47 | transfers v (indexed.filter fun ((s,_), _) => s == v) |
| 48 | let active := vertices.length + edges.length |
| 49 | let free := (List.range active).filter fun p => !(p < 2 * pairs.length && p % 2 == 1) |
| 50 | let permute := free.flatMap fun p => (free.filter (p < ·)).flatMap (exchange p) |
| 51 | let swaps := pairs.map fun (_, h) => EdgePattern.swap (2*h) (2*h+1) |
| 52 | ⟨active + 1, .copy :: route ++ permute ++ swaps⟩ |
| 53 | |
| 54 | /-- Insert at least one copy before each operation and at the closing edge. |
| 55 | If the left position is p, the new column has index p+2 modulo m=k−1. -/ |
| 56 | def pad (m previous : ℕ) : List Step → List Step |
| 57 | | [] => List.replicate (m - previous % m) .copy |
| 58 | | step :: rest => |
| 59 | let copies := match step with |
| 60 | | .copy => 1 |
| 61 | | .swap p _ | .choice p _ => 1 + (p % m + (m - previous % m)) % m |
| 62 | List.replicate copies .copy ++ step :: pad m (previous + copies + 1) rest |
| 63 | |
| 64 | /-- Check the congruence of every special step and of the total column count. -/ |
| 65 | def Aligned (m previous : ℕ) : List Step → Prop |
| 66 | | [] => previous % m = 0 |
| 67 | | .copy :: xs => Aligned m (previous + 1) xs |
| 68 | | .swap p _ :: xs | .choice p _ :: xs => |
| 69 | (previous + 1) % m = (p + 2) % m ∧ Aligned m (previous + 1) xs |
| 70 | |
| 71 | /-- Padding places every modified crossing edge at the prescribed block boundary. -/ |
| 72 | axiom padding_aligns (m : ℕ) (hm : 0 < m) (previous : ℕ) (ops : List Step) : |
| 73 | Aligned m previous (pad m previous ops) |
| 74 | |
| 75 | /-- Delete the dummy vertex of column 0 and use the vertex numbering C−1. -/ |
| 76 | def vertexCount (k : ℕ) (steps : List Step) : ℕ := k * (steps.length + 1) - 1 |
| 77 | |
| 78 | def graph (k : ℕ) (steps : List Step) : SimpleGraph (Fin (vertexCount k steps)) := |
| 79 | let column := fun (v : Fin (vertexCount k steps)) => (v.val + 1) / k |
| 80 | let position := fun (v : Fin (vertexCount k steps)) => k - 1 - ((v.val + 1) % k) |
| 81 | let forward := fun u v => |
| 82 | (column v = column u + 1 ∧ (steps[column u]?.getD .copy).Edge (position u) (position v)) ∨ |
| 83 | (column u = steps.length ∧ column v = 0 ∧ position u < position v) |
| 84 | { Adj := fun u v => u ≠ v ∧ (column u = column v ∨ forward u v ∨ forward v u) |
| 85 | symm := ⟨fun _ _ ⟨hne, h⟩ => ⟨hne.symm, h.elim (fun e => Or.inl e.symm) |
| 86 | (fun e => Or.inr e.symm)⟩⟩ |
| 87 | loopless := ⟨fun _ h => h.1 rfl⟩ } |
| 88 | |
| 89 | /-- The pair (a,b) means that the part represented by b joins the part |
| 90 | represented by a. First grow every block prefix, then merge adjacent blocks. -/ |
| 91 | def merges (blockSize blocks : ℕ) : List (ℕ × ℕ) := |
| 92 | let grow := (List.range (blockSize - 1)).flatMap fun j => |
| 93 | (List.range blocks).reverse.map fun i => (blockSize*i, blockSize*i+j+1) |
| 94 | grow ++ (List.range (blocks - 1)).map fun i => (0, blockSize*(i+1)) |
| 95 | |
| 96 | def representative (ms : List (ℕ × ℕ)) (v : ℕ) : ℕ := |
| 97 | ms.foldl (fun part (a,b) => if part = b then a else part) v |
| 98 | |
| 99 | /-- Serialize the graph, followed by the equivalence matrix after every |
| 100 | prefix of the merge list, in the coloring input format. -/ |
| 101 | noncomputable def Plan.words (P : Plan) : List ℕ := |
| 102 | let k := P.colors |
| 103 | let steps := pad (k-1) 0 P.steps |
| 104 | let n := vertexCount k steps |
| 105 | let ms := merges (k-1) (n / (k-1)) |
| 106 | let partitions := (List.range (ms.length + 1)).flatMap fun i => |
| 107 | let rep := representative (ms.take i) |
| 108 | ContractionInput.matrix n n fun u v => rep u.val = rep v.val |
| 109 | k :: ContractionInput.graph (Equiv.refl _) (graph k steps) ++ [ms.length] ++ partitions |
| 110 | |
| 111 | /-- The graph, color count, and explicit 2-sequence prescribed on a DAG input. -/ |
| 112 | noncomputable def words (I : DisjointPaths.Instance) : List ℕ := by |
| 113 | classical |
| 114 | let arcs := (List.ofFn fun (u : Fin I.n) => (List.ofFn id).filterMap fun v => |
| 115 | if I.arc u v then some (u.val,v.val) else none).flatten |
| 116 | exact (plan I.n arcs (I.terminals.map fun (s,t) => (s.val,t.val))).words |
| 117 | |
| 118 | end Lax528502.CliqueConstruction |
| 119 |
Used by
From Mathlib
none
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments