File size: 8,167 Bytes
e320e82 | 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 | import Mathlib
import OAI.Combinatorics.IndependentSets.Expansion.PoweringLabels
import OAI.Combinatorics.IndependentSets.Encoding.FormulaEncoding
import OAI.Combinatorics.IndependentSets.Expansion.PreprocessingPaddingOffsets
import OAI.Combinatorics.IndependentSets.Expansion.ExpanderTableWords
namespace OAI
namespace IndependentSetsGames.Foundations.Complexity
def naturalWordsEncoding : Computability.Encoding (List Nat) Bool where
encode := encodeWords
decode := decodeWords
decode_encode := decodeWords_encodeWords
def formulaEncoding : Computability.Encoding Target.Formula Bool where
encode := formulaBits
decode := decodeFormulaBits
decode_encode := decodeFormulaBits_encoded
def gameEncoding (alphabet : Nat) : Computability.Encoding (Target.Instance alphabet) Bool where
encode := gameBits
decode := decodeGameBits alphabet
decode_encode := decodeGameBits_encoded
def prefixBitMachine (bit : Bool) : Turing.FinTM2 where
K := Unit
k₀ := ()
k₁ := ()
Γ _ := Bool
Λ := Unit
main := ()
σ := Unit
initialState := ()
m _ := .push () (fun _ => bit) .halt
noncomputable def prefixBitPolyTime (bit : Bool) :
Turing.TM2ComputableInPolyTime (id : List Bool → List Bool) id (bit :: ·) where
tm := prefixBitMachine bit
inputAlphabet := Equiv.refl Bool
outputAlphabet := Equiv.refl Bool
time := 1
outputsFun bs := {
steps := 1
evals_in_steps := by
change some (Turing.TM2.stepAux (.push () (fun _ => bit) .halt) ()
(fun _ : Unit => bs.map id)) =
some { l := none, var := (), stk := fun _ : Unit => (bit :: bs).map id }
simp [Turing.TM2.stepAux]
funext k
cases k
rfl
steps_le_m := by simp
}
def enlargePolynomialBound {α β αΓ βΓ : Type}
{ea : α → List αΓ} {eb : β → List βΓ} {f : α → β}
(certificate : Turing.TM2ComputableInPolyTime ea eb f)
(bound : Polynomial Nat)
(larger : ∀ n, certificate.time.eval n ≤ bound.eval n) :
Turing.TM2ComputableInPolyTime ea eb f where
toTM2ComputableAux := certificate.toTM2ComputableAux
time := bound
outputsFun a := {
toEvalsTo := (certificate.outputsFun a).toEvalsTo
steps_le_m := Nat.le_trans (certificate.outputsFun a).steps_le_m (larger _)
}
def composeMachinePhases {σ : Type} (step : σ → Option σ)
(start intermediate : σ) (finish : Option σ)
(p q : Polynomial Nat) (inputLength : Nat)
(first : StateTransition.EvalsToInTime step start (some intermediate) (p.eval inputLength))
(second : StateTransition.EvalsToInTime step intermediate finish (q.eval inputLength)) :
StateTransition.EvalsToInTime step start finish ((p + q).eval inputLength) := by
have composed := StateTransition.EvalsToInTime.trans step (p.eval inputLength)
(q.eval inputLength) start intermediate finish first second
simpa only [Polynomial.eval_add, Nat.add_comm] using composed
open Target
structure PolynomialGapReduction
(completenessError soundnessError : RationalError)
extends SemanticGapReduction completenessError soundnessError where
computation : Turing.TM2ComputableInPolyTime formulaEncoding.encode
(gameEncoding alphabet).encode reduce
end IndependentSetsGames.Foundations.Complexity
namespace IndependentSetsGames.Foundations.PCP.PreprocessingMachineBounds
open PreprocessingRegularTables PreprocessingCloudIndex
open IndependentSetsGames.Foundations.Complexity
open scoped BigOperators
def inputLength (t : GraphTables.Table) : Nat := (GraphTables.tableBits t).length
theorem cloudSize_le_input (t : GraphTables.Table) (v : Fin t.vertices) :
cloudSize t v ≤ inputLength t :=
(cloudSize_le_darts t v).trans (GraphTables.darts_le_tableBits_length t)
theorem cloudTotal_le_input (t : GraphTables.Table) (v : Fin t.vertices) :
cloudSize t v + padding t v ≤ ExpanderFamily.growth * inputLength t := by
rw [cloudSize_add_padding]
exact (PreprocessingLevels.cloudPaddedSize_bounds _).2.trans
(Nat.mul_le_mul_left _ (cloudSize_le_input t v))
theorem level_le_input (t : GraphTables.Table) (v : Fin t.vertices) :
PreprocessingLevels.boundedLevel (cloudSize t v) ≤ inputLength t :=
(PreprocessingLevels.boundedLevel_le_input _).trans (cloudSize_le_input t v)
theorem regularVertices_le_input (t : GraphTables.Table) :
vertexCount t (padding t) ≤ ExpanderFamily.growth * inputLength t :=
(vertexCount_le t).trans
(Nat.mul_le_mul_left _ (GraphTables.darts_le_tableBits_length t))
theorem offset_le_sum {n : Nat} (p : Fin n → Nat) (k : Nat) :
PreprocessingPaddingOffsets.offset p k ≤ ∑ v, p v := by
have hfull : (List.finRange n).take n = List.finRange n := by simp
have hsplit : PreprocessingPaddingOffsets.offset p k +
(((List.finRange n).drop k).map p).sum =
PreprocessingPaddingOffsets.offset p n := by
simp only [PreprocessingPaddingOffsets.offset, hfull]
rw [← List.sum_append, ← List.map_append, List.take_append_drop]
rw [PreprocessingPaddingOffsets.offset_all] at hsplit
omega
theorem prefix_le_input (t : GraphTables.Table) (k : Nat) :
PreprocessingPaddingOffsets.offset (padding t) k ≤
ExpanderFamily.growth * inputLength t := by
have hsum : (∑ v, padding t v) ≤ vertexCount t (padding t) := by
unfold vertexCount
omega
exact (offset_le_sum (padding t) k).trans (hsum.trans (regularVertices_le_input t))
noncomputable def tablePolynomial (a b : Nat) : Polynomial Nat :=
Polynomial.C a * Polynomial.X + Polynomial.C b * Polynomial.X + 2 +
(Polynomial.C b * Polynomial.X) *
(Polynomial.C a * Polynomial.X + Polynomial.C b * Polynomial.X + 8192)
theorem tableBits_le_of_counts (t : GraphTables.Table) (a b L : Nat)
(hv : t.vertices ≤ a * L) (he : t.darts ≤ b * L) :
(GraphTables.tableBits t).length ≤ (tablePolynomial a b).eval L := by
have hsum := Nat.add_le_add hv he
have hprod := Nat.mul_le_mul he (Nat.add_le_add_right hsum 8192)
have h := (GraphTables.tableBits_length_le t).trans
(Nat.add_le_add (Nat.add_le_add_right hsum 2) hprod)
simpa only [tablePolynomial, Polynomial.eval_add, Polynomial.eval_mul,
Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] using h
noncomputable def regularPolynomial : Polynomial Nat :=
tablePolynomial ExpanderFamily.growth (ExpanderFamily.growth * (internalDegree + 1))
theorem regularBits_le (H : BaseTable) (t : GraphTables.Table) :
(PortTables.tableBits (regularize H t)).length ≤
regularPolynomial.eval (inputLength t) := by
have hv : (PortTables.graphTable (regularize H t)).vertices ≤
ExpanderFamily.growth * inputLength t := regularVertices_le_input t
have he : (PortTables.graphTable (regularize H t)).darts ≤
(ExpanderFamily.growth * (internalDegree + 1)) * inputLength t := by
change vertexCount t (padding t) * (internalDegree + 1) ≤ _
calc
_ ≤ (ExpanderFamily.growth * inputLength t) * (internalDegree + 1) :=
Nat.mul_le_mul_right _ hv
_ = _ := by ac_rfl
exact tableBits_le_of_counts (PortTables.graphTable (regularize H t)) _ _ _ hv he
noncomputable def rotorPolynomial (q : Nat) : Polynomial Nat :=
(Polynomial.C (ExpanderFamily.growth * q) * Polynomial.X) *
(Polynomial.C (ExpanderFamily.growth * q) * Polynomial.X + 1)
theorem cloudRotorBits_le (t : GraphTables.Table) (v : Fin t.vertices) {q : Nat}
(table : ExpanderTables.Table (cloudSize t v + padding t v) q) :
(encodeWords (ExpanderTableWords.rotationWords table)).length ≤
(rotorPolynomial q).eval (inputLength t) := by
have hd : (cloudSize t v + padding t v) * q ≤
(ExpanderFamily.growth * q) * inputLength t := by
calc
_ ≤ (ExpanderFamily.growth * inputLength t) * q :=
Nat.mul_le_mul_right _ (cloudTotal_le_input t v)
_ = _ := by ac_rfl
have h := (ExpanderTableWords.encode_rotationWords_length_le table).trans
(Nat.mul_le_mul hd (Nat.add_le_add_right hd 1))
simpa only [rotorPolynomial, Polynomial.eval_mul, Polynomial.eval_add,
Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_one] using h
end IndependentSetsGames.Foundations.PCP.PreprocessingMachineBounds
end OAI
|