Download lean/OAI/Combinatorics/IndependentSets/Expansion/ExpanderRowControl.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 7.01 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Expansion/ExpanderRowControl.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/IndependentSets/Expansion/ExpanderRowControl.lean
-
curl -L -o ExpanderRowControl.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Expansion/ExpanderRowControl.lean
7.01 kB
Lean 4 · 34
declarations statementsfull
abbrev degree (d : Nat) : Nat := d * d abbrev cloudSize (d : Nat) : Nat := degree d * degree d abbrev rowFactor (d : Nat) : Nat := cloudSize d * degree d structure Control (d : Nat) where body · 6 lines
firstH : Fin (cloudSize d) × Fin d
lastInput : Fin d
firstG : Fin (degree d)
secondG : Fin (degree d)
lastH : Fin (cloudSize d) × Fin d
deriving DecidableEq, Fintypedef squarePorts {d : Nat} (s : Control d) : Fin (degree d) × Fin (degree d) := body · 1 line
(rowIndex (degree d) (degree d)).symm s.firstH.1def start {d : Nat} (H : Table (cloudSize d) d)
(cloud : Fin (cloudSize d)) (port : Fin (degree d)) : Control d := body · 8 lines
let ports := (rowIndex d d).symm port
let first := lookup H (cloud, ports.1)
let square := (rowIndex (degree d) (degree d)).symm first.1
{ firstH := first
lastInput := ports.2
firstG := square.1
secondG := square.2
lastH := first }def receiveFirst {d : Nat} (s : Control d) (returnedPort : Fin (degree d)) : Control d := body · 1 line
{ s with firstG := returnedPort }def receiveSecond {d : Nat} (H : Table (cloudSize d) d)
(s : Control d) (returnedPort : Fin (degree d)) : Control d := body · 4 lines
{ s with
secondG := returnedPort
lastH := lookup H
(rowIndex (degree d) (degree d) (returnedPort,s.firstG),s.lastInput) }def firstOffset {d : Nat} (s : Control d) : Fin (degree d) := (squarePorts s).1 def secondOffset {d : Nat} (s : Control d) : Fin (degree d) := (squarePorts s).2 def outputPort {d : Nat} (s : Control d) : Fin (degree d) := body · 1 line
rowIndex d d (s.lastH.2,s.firstH.2)def outputOffset {d : Nat} (s : Control d) : Fin (rowFactor d) := body · 1 line
rowIndex (cloudSize d) (degree d) (s.lastH.1,outputPort s)def firstAddress {d : Nat} (vertex : Nat) (s : Control d) : Nat := body · 1 line
degree d * vertex + (firstOffset s).val
def secondAddress {d : Nat} (vertex : Nat) (s : Control d) : Nat := body · 1 line
degree d * vertex + (secondOffset s).val
def outputAddress {d : Nat} (vertex : Nat) (s : Control d) : Nat := body · 1 line
rowFactor d * vertex + (outputOffset s).val
@[simp] theorem firstOffset_receiveFirst {d : Nat} (s : Control d) (r : Fin (degree d)) :
firstOffset (receiveFirst s r) = firstOffset s := rfl @[simp] theorem secondOffset_receiveFirst {d : Nat} (s : Control d) (r : Fin (degree d)) :
secondOffset (receiveFirst s r) = secondOffset s := rfl @[simp] theorem receiveFirst_port {d : Nat} (s : Control d) (r : Fin (degree d)) :
(receiveFirst s r).firstG = r := rfl @[simp] theorem receiveSecond_port {d : Nat} (H : Table (cloudSize d) d)
(s : Control d) (r : Fin (degree d)) : (receiveSecond H s r).secondG = r := rfl theorem firstAddress_eq_rowIndex {v d : Nat} (vertex : Fin v) (s : Control d) :
firstAddress vertex.val s =
(rowIndex v (degree d) (vertex,firstOffset s)).val := by proof · 2 lines
rw [rowIndex_val]
exact Nat.add_comm _ _theorem secondAddress_eq_rowIndex {v d : Nat} (vertex : Fin v) (s : Control d) :
secondAddress vertex.val s =
(rowIndex v (degree d) (vertex,secondOffset s)).val := by proof · 2 lines
rw [rowIndex_val]
exact Nat.add_comm _ _theorem firstAddress_lt {v d : Nat} (vertex : Fin v) (s : Control d) :
firstAddress vertex.val s < v * degree d := by proof · 2 lines
rw [firstAddress_eq_rowIndex] exact (rowIndex v (degree d) (vertex,firstOffset s)).isLt
theorem secondAddress_lt {v d : Nat} (vertex : Fin v) (s : Control d) :
secondAddress vertex.val s < v * degree d := by proof · 2 lines
rw [secondAddress_eq_rowIndex] exact (rowIndex v (degree d) (vertex,secondOffset s)).isLt
theorem lookup_vertex_div {v q : Nat} (G : Table v q) (x : Fin v × Fin q) :
(lookup G x).1.val = (reverseIndex G (rowIndex v q x)).val / q := rfl theorem lookup_port_mod {v q : Nat} (G : Table v q) (x : Fin v × Fin q) :
(lookup G x).2.val = (reverseIndex G (rowIndex v q x)).val % q := rfl theorem lookup_port_eq_remainder {v q : Nat} (G : Table v q) (x : Fin v × Fin q)
(r : Fin q) (hr : r.val = (reverseIndex G (rowIndex v q x)).val % q) :
(lookup G x).2 = r := Fin.ext ((lookup_port_mod G x).trans hr.symm) theorem rowIndex_lookup {v q : Nat} (G : Table v q) (x : Fin v × Fin q) :
rowIndex v q (lookup G x) = reverseIndex G (rowIndex v q x) := by proof · 1 line
simp only [lookup, Equiv.apply_symm_apply]def outputPair {v d : Nat} (vertex : Fin v) (s : Control d) :
Fin (v * cloudSize d) × Fin (degree d) := body · 1 line
(rowIndex v (cloudSize d) (vertex,s.lastH.1),outputPort s)theorem outputAddress_eq_rowIndex {v d : Nat} (vertex : Fin v) (s : Control d) :
outputAddress vertex.val s =
(rowIndex (v * cloudSize d) (degree d) (outputPair vertex s)).val := by proof · 2 lines
simp only [outputAddress, outputOffset, outputPair, rowIndex_val, rowFactor] ring
theorem outputAddress_lt {v d : Nat} (vertex : Fin v) (s : Control d) :
outputAddress vertex.val s < (v * cloudSize d) * degree d := by proof · 2 lines
rw [outputAddress_eq_rowIndex] exact (rowIndex (v * cloudSize d) (degree d) (outputPair vertex s)).isLt
def evaluateRow {v d : Nat} (G : Table v (degree d)) (H : Table (cloudSize d) d)
(vertex : Fin v) (cloud : Fin (cloudSize d)) (port : Fin (degree d)) :
Fin v × Control d := body · 5 lines
let s₀ := start H cloud port
let g₁ := lookup G (vertex,firstOffset s₀)
let s₁ := receiveFirst s₀ g₁.2
let g₂ := lookup G (g₁.1,secondOffset s₁)
(g₂.1, receiveSecond H s₁ g₂.2)theorem evaluateRow_eq_lookup_step {v d : Nat}
(G : Table v (degree d)) (H : Table (cloudSize d) d)
(vertex : Fin v) (cloud : Fin (cloudSize d)) (port : Fin (degree d)) :
outputPair (evaluateRow G H vertex cloud port).1 (evaluateRow G H vertex cloud port).2 =
lookup (step G H) (rowIndex v (cloudSize d) (vertex,cloud),port) := by proof · 3 lines
rw [lookup_step]
simp only [evaluateRow, start, receiveFirst, receiveSecond, firstOffset, secondOffset,
squarePorts, outputPair, outputPort, stepLookup, Equiv.symm_apply_apply]theorem outputAddress_eq_step_row {v d : Nat}
(G : Table v (degree d)) (H : Table (cloudSize d) d)
(vertex : Fin v) (cloud : Fin (cloudSize d)) (port : Fin (degree d)) :
outputAddress (evaluateRow G H vertex cloud port).1.val (evaluateRow G H vertex cloud port).2 =
(rowIndex (v * cloudSize d) (degree d)
(lookup (step G H) (rowIndex v (cloudSize d) (vertex,cloud),port))).val := by proof · 1 line
rw [outputAddress_eq_rowIndex, evaluateRow_eq_lookup_step]
theorem outputAddress_eq_step_reverseIndex {v d : Nat}
(G : Table v (degree d)) (H : Table (cloudSize d) d)
(vertex : Fin v) (cloud : Fin (cloudSize d)) (port : Fin (degree d)) :
outputAddress (evaluateRow G H vertex cloud port).1.val (evaluateRow G H vertex cloud port).2 =
(reverseIndex (step G H) (rowIndex (v * cloudSize d) (degree d)
(rowIndex v (cloudSize d) (vertex,cloud),port))).val := by proof · 1 line
rw [outputAddress_eq_step_row, rowIndex_lookup]
Outline
- abbrev
degree10 - abbrev
cloudSize11 - abbrev
rowFactor12 - structure
Control14 - def
squarePorts22 - def
start25 - def
receiveFirst36 - def
receiveSecond39 - def
firstOffset46 - def
secondOffset47 - def
outputPort49 - def
outputOffset52 - def
firstAddress55 - def
secondAddress58 - def
outputAddress61 - theorem
firstOffset_receiveFirst64 - theorem
secondOffset_receiveFirst67 - theorem
receiveFirst_port70 - theorem
receiveSecond_port73 - theorem
firstAddress_eq_rowIndex76 - theorem
secondAddress_eq_rowIndex82 - theorem
firstAddress_lt88 - theorem
secondAddress_lt93 - theorem
lookup_vertex_div98 - theorem
lookup_port_mod101 - theorem
lookup_port_eq_remainder104 - theorem
rowIndex_lookup108 - def
outputPair112 - theorem
outputAddress_eq_rowIndex116 - theorem
outputAddress_lt122 - def
evaluateRow127 - theorem
evaluateRow_eq_lookup_step136 - theorem
outputAddress_eq_step_row145 - theorem
outputAddress_eq_step_reverseIndex153