File size: 12,535 Bytes
8df23f4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | import OAI.Computability.BinPacking.Computation.MachineUnaryLessAt
import OAI.Computability.BinPacking.CookLevin.ConfigIndex
namespace OAI
namespace BinPackingGames.Foundations.Complexity.CookLevin.Bounds
open Polynomial
noncomputable def pairLengthPolynomial (q : Polynomial ℕ) : Polynomial ℕ :=
C 2 * X + q + 1
noncomputable def horizonPolynomial (p q : Polynomial ℕ) : Polynomial ℕ :=
p.comp (pairLengthPolynomial q)
noncomputable def capacityPolynomial (p q : Polynomial ℕ) (pushes : ℕ) : Polynomial ℕ :=
pairLengthPolynomial q + C pushes * horizonPolynomial p q
@[simp] theorem pairLengthPolynomial_eval (q : Polynomial ℕ) (n : ℕ) :
(pairLengthPolynomial q).eval n = 2 * n + q.eval n + 1 := by
simp [pairLengthPolynomial]
@[simp] theorem horizonPolynomial_eval (p q : Polynomial ℕ) (n : ℕ) :
(horizonPolynomial p q).eval n = p.eval (2 * n + q.eval n + 1) := by
simp [horizonPolynomial, Polynomial.eval_comp]
@[simp] theorem capacityPolynomial_eval (p q : Polynomial ℕ) (pushes n : ℕ) :
(capacityPolynomial p q pushes).eval n =
2 * n + q.eval n + 1 + pushes * p.eval (2 * n + q.eval n + 1) := by
simp [capacityPolynomial]
theorem paired_length_le (q : Polynomial ℕ) (n witnessLength : ℕ)
(hw : witnessLength ≤ q.eval n) :
2 * n + witnessLength + 1 ≤ (pairLengthPolynomial q).eval n := by
rw [pairLengthPolynomial_eval]
omega
theorem one_le_pairLength (q : Polynomial ℕ) (n : ℕ) :
1 ≤ (pairLengthPolynomial q).eval n := by
rw [pairLengthPolynomial_eval]
omega
theorem pairLength_le_capacity (p q : Polynomial ℕ) (pushes n : ℕ) :
(pairLengthPolynomial q).eval n ≤ (capacityPolynomial p q pushes).eval n := by
simp only [capacityPolynomial, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C]
exact Nat.le_add_right _ _
theorem one_le_capacity (p q : Polynomial ℕ) (pushes n : ℕ) :
1 ≤ (capacityPolynomial p q pushes).eval n :=
(one_le_pairLength q n).trans (pairLength_le_capacity p q pushes n)
theorem transition_prefix_le_capacity (p q : Polynomial ℕ) (pushes n inputLength used extra : ℕ)
(hi : inputLength ≤ (pairLengthPolynomial q).eval n)
(ht : used < (horizonPolynomial p q).eval n) (he : extra ≤ pushes) :
inputLength + used * pushes + extra ≤ (capacityPolynomial p q pushes).eval n := by
have hu := Nat.mul_le_mul_right pushes (Nat.succ_le_of_lt ht)
simp only [capacityPolynomial, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C]
calc
inputLength + used * pushes + extra ≤
(pairLengthPolynomial q).eval n + (used + 1) * pushes := by
rw [Nat.add_mul, Nat.one_mul]
omega
_ ≤ (pairLengthPolynomial q).eval n + (horizonPolynomial p q).eval n * pushes :=
Nat.add_le_add_left hu _
_ = _ := by rw [Nat.mul_comm ((horizonPolynomial p q).eval n) pushes]
theorem verifier_time_le_horizon (p q : Polynomial ℕ) (n witnessLength : ℕ)
(hw : witnessLength ≤ q.eval n) :
p.eval (2 * n + witnessLength + 1) ≤ (horizonPolynomial p q).eval n := by
rw [horizonPolynomial, Polynomial.eval_comp]
exact MachineComposition.natPolynomial_eval_mono p (paired_length_le q n witnessLength hw)
theorem horizon_monotone (p q : Polynomial ℕ) :
Monotone (fun n => (horizonPolynomial p q).eval n) :=
fun _ _ h => MachineComposition.natPolynomial_eval_mono _ h
theorem capacity_monotone (p q : Polynomial ℕ) (pushes : ℕ) :
Monotone (fun n => (capacityPolynomial p q pushes).eval n) :=
fun _ _ h => MachineComposition.natPolynomial_eval_mono _ h
theorem execution_stack_length_le_capacity (tm : Turing.FinTM2)
(p q : Polynomial ℕ) (n : ℕ) (input : List (tm.Γ tm.k₀))
(hi : input.length ≤ (pairLengthPolynomial q).eval n)
(finish : tm.Cfg) (budget : ℕ)
(ht : budget ≤ (horizonPolynomial p q).eval n)
(run : StateTransition.EvalsToInTime tm.step (Turing.initList tm input)
(some finish) budget) (k : tm.K) :
(finish.stk k).length ≤ (capacityPolynomial p q (Runtime.programPushBound tm)).eval n := by
have hs := Runtime.executionSizeBound tm.step (fun cfg => (cfg.stk k).length)
(Runtime.programPushBound tm) (Runtime.stepStackLength tm k) run
have hinit := (Runtime.initialStackLength tm input k).trans hi
have hg := Nat.mul_le_mul_right (Runtime.programPushBound tm) ht
calc
(finish.stk k).length ≤ ((Turing.initList tm input).stk k).length +
budget * Runtime.programPushBound tm := hs
_ ≤ (pairLengthPolynomial q).eval n +
(horizonPolynomial p q).eval n * Runtime.programPushBound tm :=
Nat.add_le_add hinit hg
_ = _ := by simp [capacityPolynomial, Nat.mul_comm]
theorem stackCapacity_le_polynomial (tm : Turing.FinTM2)
(p q : Polynomial ℕ) (n : ℕ) (input : List (tm.Γ tm.k₀))
(hi : input.length ≤ (pairLengthPolynomial q).eval n) :
BoundedExecution.stackCapacity tm input ((horizonPolynomial p q).eval n) ≤
(capacityPolynomial p q (Runtime.programPushBound tm)).eval n := by
simpa only [BoundedExecution.stackCapacity, capacityPolynomial,
Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Nat.mul_comm] using
Nat.add_le_add_right hi ((horizonPolynomial p q).eval n * Runtime.programPushBound tm)
theorem run_stack_length_le_capacity (tm : Turing.FinTM2)
(p q : Polynomial ℕ) (n : ℕ) (input : List (tm.Γ tm.k₀))
(hi : input.length ≤ (pairLengthPolynomial q).eval n)
(time : ℕ) (ht : time ≤ (horizonPolynomial p q).eval n) (k : tm.K) :
((BoundedExecution.run tm input time).stk k).length ≤
(capacityPolynomial p q (Runtime.programPushBound tm)).eval n :=
(BoundedExecution.run_stack_le tm input _ time ht k).trans
(stackCapacity_le_polynomial tm p q n input hi)
theorem run_statement_budget_le_capacity (tm : Turing.FinTM2)
(p q : Polynomial ℕ) (n : ℕ) (input : List (tm.Γ tm.k₀))
(hi : input.length ≤ (pairLengthPolynomial q).eval n)
(time : ℕ) (ht : time < (horizonPolynomial p q).eval n)
(label : tm.Λ) (k : tm.K) :
((BoundedExecution.run tm input time).stk k).length +
Runtime.statementPushBound (tm.m label) ≤
(capacityPolynomial p q (Runtime.programPushBound tm)).eval n :=
(BoundedExecution.statement_budget tm input _ time ht label k).trans
(stackCapacity_le_polynomial tm p q n input hi)
noncomputable def configurationWidthPolynomial (p q : Polynomial ℕ)
(pushes controlBits alphabetBits : ℕ) : Polynomial ℕ :=
C controlBits + capacityPolynomial p q pushes * C alphabetBits
noncomputable def transitionGatesPolynomial (p q : Polynomial ℕ)
(pushes controlBits alphabetBits expressionCost : ℕ) : Polynomial ℕ :=
C expressionCost * configurationWidthPolynomial p q pushes controlBits alphabetBits
noncomputable def tableauGatesPolynomial (p q : Polynomial ℕ)
(pushes controlBits alphabetBits expressionCost : ℕ) : Polynomial ℕ :=
horizonPolynomial p q *
transitionGatesPolynomial p q pushes controlBits alphabetBits expressionCost
@[simp] theorem configurationWidthPolynomial_eval (p q : Polynomial ℕ)
(pushes controlBits alphabetBits n : ℕ) :
(configurationWidthPolynomial p q pushes controlBits alphabetBits).eval n =
controlBits + (capacityPolynomial p q pushes).eval n * alphabetBits := by
simp [configurationWidthPolynomial]
@[simp] theorem transitionGatesPolynomial_eval (p q : Polynomial ℕ)
(pushes controlBits alphabetBits expressionCost n : ℕ) :
(transitionGatesPolynomial p q pushes controlBits alphabetBits expressionCost).eval n =
expressionCost * (controlBits + (capacityPolynomial p q pushes).eval n * alphabetBits) := by
simp [transitionGatesPolynomial]
@[simp] theorem tableauGatesPolynomial_eval (p q : Polynomial ℕ)
(pushes controlBits alphabetBits expressionCost n : ℕ) :
(tableauGatesPolynomial p q pushes controlBits alphabetBits expressionCost).eval n =
(horizonPolynomial p q).eval n * expressionCost *
(controlBits + (capacityPolynomial p q pushes).eval n * alphabetBits) := by
simp only [tableauGatesPolynomial, Polynomial.eval_mul, transitionGatesPolynomial_eval]
exact (Nat.mul_assoc _ _ _).symm
noncomputable def formulaBitsPolynomial (varBound clauseBound : Polynomial ℕ) : Polynomial ℕ :=
varBound + clauseBound + C 2 + clauseBound * (C 3 * (varBound + C 2))
@[simp] theorem formulaBitsPolynomial_eval (varBound clauseBound : Polynomial ℕ) (n : ℕ) :
(formulaBitsPolynomial varBound clauseBound).eval n =
varBound.eval n + clauseBound.eval n + 2 +
clauseBound.eval n * (3 * (varBound.eval n + 2)) := by
simp [formulaBitsPolynomial]
theorem formulaBits_length_le_polynomial (F : Target.Formula)
(varBound clauseBound : Polynomial ℕ) (n : ℕ)
(hv : F.variables ≤ varBound.eval n)
(hc : F.clauses.length ≤ clauseBound.eval n) :
(formulaBits F).length ≤ (formulaBitsPolynomial varBound clauseBound).eval n := by
refine (formulaBits_length_le F).trans ?_
rw [formulaBitsPolynomial_eval]
exact Nat.add_le_add
(Nat.add_le_add_right (Nat.add_le_add hv hc) 2)
(Nat.mul_le_mul hc (Nat.mul_le_mul_left 3 (Nat.add_le_add_right hv 2)))
noncomputable def circuitVariablesPolynomial (inputs gates : Polynomial ℕ) : Polynomial ℕ :=
inputs + gates
noncomputable def circuitClausesPolynomial (gates : Polynomial ℕ) : Polynomial ℕ :=
C 3 * gates + 1
noncomputable def circuitBitsPolynomial (inputs gates : Polynomial ℕ) : Polynomial ℕ :=
formulaBitsPolynomial (circuitVariablesPolynomial inputs gates)
(circuitClausesPolynomial gates)
@[simp] theorem circuitVariablesPolynomial_eval (inputs gates : Polynomial ℕ) (n : ℕ) :
(circuitVariablesPolynomial inputs gates).eval n = inputs.eval n + gates.eval n := by
simp [circuitVariablesPolynomial]
@[simp] theorem circuitClausesPolynomial_eval (gates : Polynomial ℕ) (n : ℕ) :
(circuitClausesPolynomial gates).eval n = 3 * gates.eval n + 1 := by
simp [circuitClausesPolynomial]
@[simp] theorem circuitBitsPolynomial_eval (inputs gates : Polynomial ℕ) (n : ℕ) :
(circuitBitsPolynomial inputs gates).eval n =
(inputs.eval n + gates.eval n) + (3 * gates.eval n + 1) + 2 +
(3 * gates.eval n + 1) * (3 * ((inputs.eval n + gates.eval n) + 2)) := by
simp [circuitBitsPolynomial]
theorem circuit_formulaBits_length_le (F : Target.Formula) (inputCount gateCount : ℕ)
(hv : F.variables ≤ inputCount + gateCount)
(hc : F.clauses.length ≤ 3 * gateCount + 1) :
(formulaBits F).length ≤
(inputCount + gateCount) + (3 * gateCount + 1) + 2 +
(3 * gateCount + 1) * (3 * ((inputCount + gateCount) + 2)) := by
exact (formulaBits_length_le F).trans
(Nat.add_le_add (Nat.add_le_add_right (Nat.add_le_add hv hc) 2)
(Nat.mul_le_mul hc (Nat.mul_le_mul_left 3 (Nat.add_le_add_right hv 2))))
theorem circuit_formulaBits_length_le_polynomial (F : Target.Formula)
(inputCount gateCount : ℕ) (inputs gates : Polynomial ℕ) (n : ℕ)
(hi : inputCount ≤ inputs.eval n) (hg : gateCount ≤ gates.eval n)
(hv : F.variables ≤ inputCount + gateCount)
(hc : F.clauses.length ≤ 3 * gateCount + 1) :
(formulaBits F).length ≤ (circuitBitsPolynomial inputs gates).eval n := by
apply formulaBits_length_le_polynomial
· simpa using hv.trans (Nat.add_le_add hi hg)
· simpa using hc.trans (Nat.add_le_add_right (Nat.mul_le_mul_left 3 hg) 1)
theorem toFormula_bits_length_le (circuit : Circuit) :
(formulaBits circuit.toFormula).length ≤
(circuit.inputs + circuit.gates.length) + (3 * circuit.gates.length + 1) + 2 +
(3 * circuit.gates.length + 1) *
(3 * ((circuit.inputs + circuit.gates.length) + 2)) :=
circuit_formulaBits_length_le circuit.toFormula circuit.inputs circuit.gates.length
(Circuit.toFormula_variables circuit).le (Circuit.toFormula_clause_count circuit).le
theorem toFormula_bits_length_le_polynomial (circuit : Circuit)
(inputs gates : Polynomial ℕ) (n : ℕ)
(hi : circuit.inputs ≤ inputs.eval n) (hg : circuit.gates.length ≤ gates.eval n) :
(formulaBits circuit.toFormula).length ≤ (circuitBitsPolynomial inputs gates).eval n :=
circuit_formulaBits_length_le_polynomial circuit.toFormula circuit.inputs circuit.gates.length
inputs gates n hi hg
(Circuit.toFormula_variables circuit).le (Circuit.toFormula_clause_count circuit).le
end BinPackingGames.Foundations.Complexity.CookLevin.Bounds
end OAI
|