Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Complexity/Algorithms/Reachability/ReingoldEval.lean
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ theorem reingoldStep_rot {V : Type*} (G : RotationMap V B) (y : V) (c a : B) :
((r₂.1, s₄.1), reingoldFinish e s₄.2) := by
simp only [reingoldStep, rot_relabel, reingoldHStep, reingoldFinish, Equiv.apply_symm_apply]
change Prod.map id e.symm (powRot (G.zigzag H).rot 2 ((y, c), e.symm.symm a)) = _
simp only [powRot, Equiv.symm_symm, zigzag, zigzagRot, Fin.tail, Prod.map_apply, id_eq]
simp only [powRot, Equiv.symm_symm, zigzagRot, Fin.tail, Prod.map_apply, id_eq]
refine Prod.ext rfl (congrArg e.symm (funext fun i ↦ ?_))
fin_cases i <;> simp [Matrix.cons_val_zero, Matrix.cons_val_one, Fin.snoc]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ open Turing.MultiTapeTM

/-- The input prefix, certificate length and verifier time bound used by the Cook–Levin
reduction are jointly computable in polynomial time, with the bounds in unary. -/
@[fun_prop]
-- The reducible tuple is handled by compositional rules. Registering this certificate would
-- index its specialized formula under `Prod.mk` and interfere with unrelated tuple clients.
theorem computableInPolyTime_parameters {α : Type} (p : Polynomial ℕ) (c d : ℕ)
(enc : α ↪ List Bool) :
ComputableInPolyTime (parameters p c d enc)
Expand Down
4 changes: 3 additions & 1 deletion Complexity/Computability/Complexity/CookLevin/Reduction.lean
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ theorem Var.index_injective : Function.Injective (Var.index (k := k) (State := S
variable [DecidableEq State] {α : Type}

/-- The framed input prefix, certificate length and verifier time bound supplied to the tableau.
The verifier is allowed `c * (n + 1) ^ d` steps on an input of encoded length `n`. -/
The verifier is allowed `c * (n + 1) ^ d` steps on an input of encoded length `n`.
The tuple wrapper is reducible so projection clients can compute its components directly. -/
@[reducible]
def parameters (p : Polynomial ℕ) (c d : ℕ) (enc : α ↪ List Bool) (a : α) :
List Bool × ℕ × ℕ :=
(frame (enc a), p.eval (enc a).length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ Tensor and zig-zag rotations are straight-line programs calling their constituen
Their certificates charge the complete vertex and edge-label encodings, including copying and
intermediate pairs. The affine-plane rotation similarly composes multiplication and subtraction.

The structure wrappers `RotationMap.tensor`, `RotationMap.zigzag`, `RotationMap.affinePlane`,
`RotationMap.contract` and `RotationMap.reindex` are reducible. Thus `fun_prop` sees the distinct
certified rotation programs beneath their `.rot` projections, including in larger compositions.
Default `simp` also exposes the corresponding `tensorRot`, `zigzagRot`, `affinePlaneRot`,
`contractRot` and `reindexRot` forms; the `rot_*` equations remain available for `rw` and
applicable explicit `simp only` proofs.

These rules certify a rotation call. They do not enumerate a graph or certify an unbounded
recursive tower. In particular, a certificate for a fixed finite base is not a uniform efficiency
theorem for a varying field size or tower depth.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ theorem lookup_iterate_numbered {B : Type*} (H : RotationMap B D)
rw [Function.iterate_zero_apply]
change (initial (H.reindex numbering)).lookup (numbering vertex).val label = _
rw [lookup_initial]
simp only [rot_reindex, Equiv.symm_apply_apply]
simp only [reindexRot, Equiv.symm_apply_apply]
rfl
| succ level ih =>
rcases vertex with ⟨vertex, cloud⟩
Expand All @@ -213,10 +213,10 @@ theorem lookup_iterate_numbered {B : Type*} (H : RotationMap B D)
(ZigzagTowerVertex.equivFin numbering level vertex).val := by
rw [Nat.mul_comm (ZigzagTowerVertex.equivFin numbering level vertex).val,
Nat.mul_add_div hb, Nat.div_eq_of_lt (numbering cloud).isLt, Nat.add_zero]
simp only [nextRow, hmod, hdiv, rot_reindex, Equiv.trans_apply, Fin.eta,
simp only [nextRow, hmod, hdiv, reindexRot, Equiv.trans_apply, Fin.eta,
Equiv.symm_apply_apply, Equiv.symm_trans_apply, Equiv.apply_symm_apply]
rw [ih, ih]
simp only [rot_zigzagTower_succ, rot_zigzag, square_relabel_rotation, hstep]
simp only [rot_zigzagTower_succ, zigzagRot, square_relabel_rotation, hstep]

/-- The selected complete table has the exact cardinality used by the tower family. -/
theorem length_build (H : RotationMap (Fin b) D) (e : Fin b ≃ (Fin 2 → D × D))
Expand All @@ -232,7 +232,7 @@ theorem lookup_build {B : Type*} (H : RotationMap B D) (e : B ≃ (Fin 2 → D
let target := ((zigzagTower H e (Nat.clog b size - 1)).reindex
(ZigzagTowerVertex.equivFin numbering (Nat.clog b size - 1))).rot (vertex, label)
(target.1.val, target.2) := by
simpa only [build, Equiv.apply_symm_apply, rot_reindex] using
simpa only [build, Equiv.apply_symm_apply, reindexRot] using
lookup_iterate_numbered H e numbering hb (Nat.clog b size - 1)
((ZigzagTowerVertex.equivFin numbering (Nat.clog b size - 1)).symm vertex) label

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ theorem contract_eq {m n : ℕ} (G : RotationMap (Fin m) (D × D))
if hindex : vertex.val + n * label.1.val < m then
some (⟨vertex.val + n * label.1.val, hindex⟩ : Fin m) else none := rfl
unfold contract contractFin
simp only [rot_contract, hdecode, hlength]
simp only [contractRot, hdecode, hlength]
split <;> rename_i hindex
· simp only [hlookup ⟨vertex.val + n * label.1.val, hindex⟩ label.2]
simp only [contractDart, finSlotEncode]
Expand Down
4 changes: 2 additions & 2 deletions Complexity/Computability/PCP/Encoded/Preprocess.lean
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private theorem rotationEdges_represents {V : Type} (vertices : ℕ)
change (rotate (vertices, (eV.symm p.1).val, p.2)).1 = _
rw [hrotate]
simp [RegularConstraintGraph.toConstraintGraph, RegularConstraintGraph.unconstrained,
RotationMap.neighbor_def, hnumber]
RotationMap.neighbor_def, RotationMap.reindexRot, hnumber]
· intro p a b
simp [edge, htruth, RegularConstraintGraph.toConstraintGraph,
RegularConstraintGraph.unconstrained]
Expand Down Expand Up @@ -318,7 +318,7 @@ theorem toGraph_preprocess [DecidableEq α] (htruth : ∀ a b, eval truth a b =
(RotationMap.loops (Fin n) Unit) (fun _ _ => rfl) eV number hnumber
have hreindex : (RotationMap.loops (Fin n) Unit).reindex eV =
RotationMap.loops (Fin g.edges.length × Bool) Unit := by
ext p <;> simp
ext p <;> simp [RotationMap.reindexRot]
have hloopedges : rotationEdges (fun p : ℕ × ℕ × Unit => p.2) [()] n =
(List.range n).map (fun v => (v, v)) := by
simp only [rotationEdges, List.map_cons, List.map_nil]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def affinePlaneRot (p : (K × K) × K) : (K × K) × K :=

/-- The affine-plane graph: `(a, b)` is adjacent to `(c, d)` when `a * c = b + d`.
The edge to first coordinate `c` has label `c`, and its reverse has label `a`. -/
@[reducible]
def affinePlane : RotationMap (K × K) K where
rot := affinePlaneRot K
rot_involutive p := by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ theorem contractRot_contractDart (rotate : V × D → V × D) (p : V × D) :
simp [contractRot, contractDart, h.eq]

/-- Contract the occupied slots over each vertex, completing the degree with self-loops. -/
@[reducible]
def contract (G : RotationMap V D) : RotationMap W (I × D) where
rot := contractRot encode decode G.rot
rot_involutive := by
Expand Down
1 change: 1 addition & 0 deletions Complexity/Foundations/Combinatorics/Expander/Reindex.lean
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def reindexRot (forward : V → W) (backward : W → V) (rotate : V × D → V
(forward next.1, next.2)

/-- Rename the vertices of a graph, retaining every outgoing and return edge label. -/
@[reducible]
def reindex (G : RotationMap V D) (e : V ≃ W) : RotationMap W D where
rot := reindexRot e e.symm G.rot
rot_involutive p := by simp [reindexRot]
Expand Down
1 change: 1 addition & 0 deletions Complexity/Foundations/Combinatorics/Expander/Tensor.lean
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def tensorRot (rotate : V × D → V × D) (other : V' × D' → V' × D')
[Reingold, Vadhan and Wigderson, Section 2.3][ReingoldVadhanWigderson2002]: the multigraph on
`V × V'` with labels `D × D'` whose edge `(i, i')` at `(v, v')` takes the edge `i` of `G` at `v` and
the edge `i'` of `H` at `v'` at the same time. -/
@[reducible]
def tensor : RotationMap (V × V') (D × D') where
rot := tensorRot G.rot H.rot
rot_involutive p := by simp [tensorRot]
Expand Down
1 change: 1 addition & 0 deletions Complexity/Foundations/Combinatorics/Expander/Zigzag.lean
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ at `v`, grouped into the cloud `{v} × D` of `v`, and its labels are pairs of la
`(i, j)` at `(v, k)` takes the edge `i` of `H` from `k` to `k'` inside the cloud ("zig"), crosses
the `k'`-th edge of `G` from `v` to `(w, ℓ')`, where it is the `ℓ'`-th edge at `w`, and takes the
edge `j` of `H` from `ℓ'` to `ℓ` inside the cloud of `w` ("zag"), ending at `(w, ℓ)`. -/
@[reducible]
def zigzag : RotationMap (V × D) (E × E) where
rot := zigzagRot G.rot H.rot
rot_involutive p := by simp [zigzagRot]
Expand Down
6 changes: 6 additions & 0 deletions ComplexityTests/CookLevinPolyTime.lean
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ example {k : ℕ} {State : Type} [Fintype State] [DecidableEq State] :
(encPair (encPair (encPair encBits encUnary) encUnary) encUnary) encCNF := by
fun_prop

-- The full reducible tuple composes without a specialized `Prod.mk` search rule.
example {α : Type} (enc : α ↪ List Bool) (p : Polynomial ℕ) (c d : ℕ) :
ComputableInPolyTime (parameters p c d enc)
enc (encPair encBits (encPair encUnary encUnary)) := by
fun_prop

-- The input encoding, polynomial and machine are fixed parameters of the reduction.
example {k : ℕ} {State α : Type} [Fintype State]
(tm : Turing.MultiTapeTM k Bool State) (enc : α ↪ List Bool)
Expand Down
3 changes: 1 addition & 2 deletions ComplexityTests/ExpanderContraction.lean
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ example : ComputableInPolyTime threeVertices.rot
have hg : ComputableInPolyTime completeFive.rot
(encPair (encFinEnum (Fin 5)) (encFinEnum (Fin 5)))
(encPair (encFinEnum (Fin 5)) (encFinEnum (Fin 5))) := .of_finite _
exact ComputableInPolyTime.rotationMap_contract he hd hg
fun_prop [threeVertices, RotationMap.contractFin]

example {V W I D : Type} (G : RotationMap V D) (encode : V → W × I)
(decode : W × I → Option V) (hinv : Function.IsPartialInv encode decode)
Expand All @@ -80,7 +80,6 @@ example {V W I D : Type} (G : RotationMap V D) (encode : V → W × I)
(fun p : (W × (I × D)) × Bool => ((RotationMap.contract encode decode hinv G).rot p.1, !p.2))
(encPair (encPair ew (encPair ei ed)) encBool)
(encPair (encPair ew (encPair ei ed)) encBool) := by
dsimp only [RotationMap.contract, RotationMap.contractRot, RotationMap.contractDart]
fail_if_success (clear he; fun_prop)
fail_if_success (clear hd; fun_prop)
fail_if_success (clear hg; fun_prop)
Expand Down
3 changes: 1 addition & 2 deletions ComplexityTests/ExpanderFamily.lean
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ example {V W D : Type} (G : RotationMap V D) (e : V ≃ W)
let next := (G.reindex e).rot p.1
(next, !p.2))
(encPair (encPair ew ed) encBool) (encPair (encPair ew ed) encBool) := by
dsimp only [RotationMap.reindex, RotationMap.reindexRot]
fail_if_success (clear hf; fun_prop)
fail_if_success (clear hb; fun_prop)
fail_if_success (clear hg; fun_prop)
Expand All @@ -110,7 +109,7 @@ example (G : RotationMap (Bool × List Bool) Bool)
ComputableInPolyTime (G.reindex (Equiv.prodComm Bool (List Bool))).rot
(encPair (encPair encBits encBool) encBool)
(encPair (encPair encBits encBool) encBool) := by
simp only [RotationMap.reindex, Equiv.prodComm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk]
simp only [Equiv.prodComm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk]
fun_prop [Prod.swap]

end ComplexityTests.ExpanderFamily
23 changes: 17 additions & 6 deletions ComplexityTests/ExplicitExpanders.lean
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ example {K : Type} [Field K] (encode : K ↪ List Bool)
ComputableInPolyTime (RotationMap.affinePlaneTowerBase K).rot
(encPair (baseEncoding encode) (planeEncoding encode))
(encPair (baseEncoding encode) (planeEncoding encode)) := by
have hplane := ComputableInPolyTime.rotationMap_affinePlane hmul hsub
exact ((hplane.rotationMap_tensor hplane).rotationMap_zigzag hplane).rotationMap_zigzag hplane
fun_prop [RotationMap.affinePlaneTowerBase]

-- Only the fixed field operations use the finite-domain theorem; graph products compose them.
example (encode : ZMod 257 ↪ List Bool) :
Expand All @@ -76,8 +75,7 @@ example (encode : ZMod 257 ↪ List Bool) :
(planeEncoding encode) encode := .of_finite _
have hsub : ComputableInPolyTime (fun p : ZMod 257 × ZMod 257 => p.1 - p.2)
(planeEncoding encode) encode := .of_finite _
have hplane := ComputableInPolyTime.rotationMap_affinePlane hmul hsub
exact ((hplane.rotationMap_tensor hplane).rotationMap_zigzag hplane).rotationMap_zigzag hplane
fun_prop [RotationMap.affinePlaneTowerBase]

-- Equivalent direct and let-bound spellings, with a supplied rotation on an arbitrary type.
example {V D E : Type} (G : RotationMap V D) (H : RotationMap D E)
Expand All @@ -88,7 +86,6 @@ example {V D E : Type} (G : RotationMap V D) (H : RotationMap D E)
(fun p : ((V × D) × (E × E)) × Bool => ((G.zigzag H).rot p.1, !p.2))
(encPair (encPair (encPair vertex label) (encPair small small)) encBool)
(encPair (encPair (encPair vertex label) (encPair small small)) encBool) := by
dsimp only [RotationMap.zigzag, RotationMap.zigzagRot]
fail_if_success (clear hG; fun_prop)
fail_if_success (clear hH; fun_prop)
fun_prop
Expand All @@ -103,7 +100,21 @@ example {V D E : Type} (G : RotationMap V D) (H : RotationMap D E)
(next, !p.2))
(encPair (encPair (encPair vertex label) (encPair small small)) encBool)
(encPair (encPair (encPair vertex label) (encPair small small)) encBool) := by
dsimp only [RotationMap.zigzag, RotationMap.zigzagRot]
fun_prop

-- Tensor and zig-zag wrappers must lead search to their distinct rotation programs.
example {V D W E : Type} (G : RotationMap V D) (H : RotationMap W E)
(vertex : V ↪ List Bool) (label : D ↪ List Bool)
(otherVertex : W ↪ List Bool) (otherLabel : E ↪ List Bool)
(hG : ComputableInPolyTime G.rot (encPair vertex label) (encPair vertex label))
(hH : ComputableInPolyTime H.rot
(encPair otherVertex otherLabel) (encPair otherVertex otherLabel)) :
ComputableInPolyTime
(fun p : ((V × W) × (D × E)) × Bool => ((G.tensor H).rot p.1, !p.2))
(encPair (encPair (encPair vertex otherVertex) (encPair label otherLabel)) encBool)
(encPair (encPair (encPair vertex otherVertex) (encPair label otherLabel)) encBool) := by
fail_if_success (clear hG; fun_prop)
fail_if_success (clear hH; fun_prop)
fun_prop

end ComplexityTests.ExplicitExpanders
1 change: 0 additions & 1 deletion ComplexityTests/MultiTapePolyTime.lean
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ example {α : Type} (enc : α ↪ List Bool) (p : Polynomial ℕ) (c d : ℕ) :
ComputableTidilyInPolyTime
(fun a => List.range (Cslib.Complexity.CookLevin.parameters p c d enc a).2.2)
enc (encList encUnary) := by
dsimp only [Cslib.Complexity.CookLevin.parameters]
fun_prop

private def finish (move : SignType) (symbol : Bool) : Turing.MultiTapeTM 0 Bool Unit :=
Expand Down
Loading