cfahlgren1/math / lean /OAI /Combinatorics /IndependentSets /Machines /MachinePaddingBounds.lean
cfahlgren1's picture
download
raw
6.5 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Machines.MachinePaddingRows
namespace OAI
namespace IndependentSetsGames.Foundations.Complexity.MachinePaddingBounds
theorem rowsBits_length_le (v e count : Nat) :
(MachineDummyRows.rowsBits v e count).length ≤ count * (v + e + count + 8194) := by
induction count generalizing e with
| zero => simp [MachineDummyRows.rowsBits]
| succ count ih =>
have hi := ih (e + 1)
have hb : v + (e + 1) + count + 8194 = v + e + (count + 1) + 8194 := by omega
rw [hb] at hi
have hr : v + e + 8194 ≤ v + e + (count + 1) + 8194 := by omega
simp only [MachineDummyRows.rowsBits, List.length_append, MachineDummyRows.rowBits_length]
calc
_ ≤ (v + e + (count + 1) + 8194) +
count * (v + e + (count + 1) + 8194) := Nat.add_le_add hr hi
_ = _ := by rw [Nat.add_mul, Nat.one_mul]; omega
def rowBound (d v e count : Nat) : Nat := v + count + e + (count + 1) * d + 8194
theorem rowBound_next (d v e count : Nat) :
rowBound d (v + 1) (e + d) count = rowBound d v e (count + 1) := by
simp only [rowBound, Nat.add_mul, Nat.one_mul]
omega
theorem blockRow_le_rowBound (d v e count : Nat) :
v + e + d + 8194 ≤ rowBound d v e (count + 1) := by
simp only [rowBound, Nat.add_mul, Nat.one_mul]
omega
theorem steps_le_bound (d v e : Nat) (output : List Bool) (count : Nat) :
MachinePaddingRows.steps d v e output count ≤
count * (d * (4 * rowBound d v e count +
2 * (output.length + count * d * rowBound d v e count) + 10) + 2) + 1 := by
induction count generalizing v e output with
| zero => simp [MachinePaddingRows.steps]
| succ count ih =>
let B := rowBound d v e (count + 1)
let C := d * (4 * B + 2 * (output.length + (count + 1) * d * B) + 10) + 2
have hb : rowBound d (v + 1) (e + d) count = B := rowBound_next d v e count
have hr : v + e + d + 8194 ≤ B := blockRow_le_rowBound d v e count
have hlen : (MachineDummyRows.rowsBits v e d).length ≤ d * B :=
(rowsBits_length_le v e d).trans (Nat.mul_le_mul_left d hr)
have hout : (output ++ MachineDummyRows.rowsBits v e d).length + count * d * B ≤
output.length + (count + 1) * d * B := by
rw [List.length_append]
calc
_ ≤ output.length + d * B + count * d * B :=
Nat.add_le_add_right (Nat.add_le_add_left hlen output.length) _
_ = _ := by simp only [Nat.add_mul, Nat.one_mul]; omega
have hi := ih (v + 1) (e + d) (output ++ MachineDummyRows.rowsBits v e d)
rw [hb] at hi
have hconstant :
d * (4 * B + 2 * ((output ++ MachineDummyRows.rowsBits v e d).length +
count * d * B) + 10) + 2 ≤ C := by
exact Nat.add_le_add_right (Nat.mul_le_mul_left d
(Nat.add_le_add_right (Nat.add_le_add_left (Nat.mul_le_mul_left 2 hout) (4 * B)) 10)) 2
have hremaining := hi.trans
(Nat.add_le_add_right (Nat.mul_le_mul_left count hconstant) 1)
have hcount : d * B ≤ (count + 1) * d * B := by
simpa only [Nat.one_mul, Nat.mul_assoc] using
Nat.mul_le_mul_right (d * B) (Nat.succ_le_succ (Nat.zero_le count))
have hbodyOutput : output.length + d * (v + e + d + 8194) ≤
output.length + (count + 1) * d * B :=
Nat.add_le_add_left ((Nat.mul_le_mul_left d hr).trans hcount) output.length
have hbodyInner : 4 * (v + e + d + 8194) +
2 * (output.length + d * (v + e + d + 8194)) + 10 ≤
4 * B + 2 * (output.length + (count + 1) * d * B) + 10 := by
exact Nat.add_le_add_right (Nat.add_le_add (Nat.mul_le_mul_left 4 hr)
(Nat.mul_le_mul_left 2 hbodyOutput)) 10
have hbody : MachineDummyRows.steps v e output d + 2 ≤ C :=
Nat.add_le_add_right ((MachineDummyRows.steps_le_bound v e output d).trans
(Nat.mul_le_mul_left d hbodyInner)) 2
change (MachineDummyRows.steps v e output d + 2) +
MachinePaddingRows.steps d (v + 1) (e + d)
(output ++ MachineDummyRows.rowsBits v e d) count ≤ (count + 1) * C + 1
calc
_ ≤ C + (count * C + 1) := Nat.add_le_add hbody hremaining
_ = _ := by rw [Nat.add_mul, Nat.one_mul]; omega
def inputSize (v e count : Nat) (output : List Bool) : Nat :=
(encodeWord v).length + (encodeWord e).length + (encodeWord count).length + output.length
def rowCap (d size : Nat) : Nat := size + (size + 1) * d + 8194
theorem rowBound_le_cap (d v e count : Nat) (output : List Bool) :
rowBound d v e count ≤ rowCap d (inputSize v e count output) := by
have hbase : v + e + count ≤ inputSize v e count output := by
simp only [inputSize, encodeWord_length]
omega
have hcount : count ≤ inputSize v e count output := by
simp only [inputSize, encodeWord_length]
omega
have hmul := Nat.mul_le_mul_right d (Nat.succ_le_succ hcount)
have h := Nat.add_le_add_right (Nat.add_le_add hbase hmul) 8194
simpa only [rowBound, rowCap, Nat.succ_eq_add_one, Nat.add_assoc,
Nat.add_comm, Nat.add_left_comm] using h
noncomputable def rowPolynomial (d : Nat) : Polynomial Nat :=
Polynomial.X + (Polynomial.X + 1) * Polynomial.C d + Polynomial.C 8194
noncomputable def timePolynomial (d : Nat) : Polynomial Nat :=
Polynomial.X * (Polynomial.C d *
(Polynomial.C 4 * rowPolynomial d +
Polynomial.C 2 * (Polynomial.X + Polynomial.X * Polynomial.C d * rowPolynomial d) +
Polynomial.C 10) + Polynomial.C 2) + 1
theorem timePolynomial_bounds (d v e count : Nat) (output : List Bool) :
MachinePaddingRows.steps d v e output count ≤
(timePolynomial d).eval (inputSize v e count output) := by
have hc : count ≤ inputSize v e count output := by
simp only [inputSize, encodeWord_length]
omega
have ho : output.length ≤ inputSize v e count output := by
simp only [inputSize, encodeWord_length]
omega
have hb := rowBound_le_cap d v e count output
have hp := Nat.mul_le_mul (Nat.mul_le_mul_right d hc) hb
have hout := Nat.add_le_add ho hp
have hinner := Nat.add_le_add_right
(Nat.add_le_add (Nat.mul_le_mul_left 4 hb) (Nat.mul_le_mul_left 2 hout)) 10
have hbody := Nat.add_le_add_right (Nat.mul_le_mul_left d hinner) 2
have h := (steps_le_bound d v e output count).trans
(Nat.add_le_add_right (Nat.mul_le_mul hc hbody) 1)
simpa only [timePolynomial, rowPolynomial, rowCap, Polynomial.eval_add,
Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_one] using h
end IndependentSetsGames.Foundations.Complexity.MachinePaddingBounds
end OAI

Xet Storage Details

Size:
6.5 kB
·
Xet hash:
07c6d21709812a27310c16c6d0da9f75180624e827022f1843eb81c8baffbfcf

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.