Download data/lean/OAI/Computability/BinPacking/CookLevin/Bounds.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/CookLevin/Bounds.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/BinPacking/CookLevin/Bounds.lean
-
curl -L -o Bounds.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/BinPacking/CookLevin/Bounds.lean
12.5 kB
| 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 | |