Download lean/OAI/Combinatorics/IndependentSets/Machines/Machine2.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 8.17 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Machines/Machine2.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/IndependentSets/Machines/Machine2.lean
-
curl -L -o Machine2.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Machines/Machine2.lean
8.17 kB
Lean 4 · 21
declarations statementsfull
def naturalWordsEncoding : Computability.Encoding (List Nat) Bool where body · 3 lines
encode := encodeWords
decode := decodeWords
decode_encode := decodeWords_encodeWordsdef formulaEncoding : Computability.Encoding Target.Formula Bool where body · 3 lines
encode := formulaBits
decode := decodeFormulaBits
decode_encode := decodeFormulaBits_encodeddef gameEncoding (alphabet : Nat) : Computability.Encoding (Target.Instance alphabet) Bool where body · 3 lines
encode := gameBits
decode := decodeGameBits alphabet
decode_encode := decodeGameBits_encodeddef prefixBitMachine (bit : Bool) : Turing.FinTM2 where body · 9 lines
K := Unit
k₀ := ()
k₁ := ()
Γ _ := Bool
Λ := Unit
main := ()
σ := Unit
initialState := ()
m _ := .push () (fun _ => bit) .haltnoncomputable def prefixBitPolyTime (bit : Bool) :
Turing.TM2ComputableInPolyTime (id : List Bool → List Bool) id (bit :: ·) where body · 16 lines
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 body · 6 lines
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 body · 3 lines
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 composedstructure PolynomialGapReduction
(completenessError soundnessError : RationalError)
extends SemanticGapReduction completenessError soundnessError where body · 2 lines
computation : Turing.TM2ComputableInPolyTime formulaEncoding.encode
(gameEncoding alphabet).encode reducedef 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 := proof · 1 line
(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 proof · 3 lines
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 := proof · 1 line
(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 := proof · 2 lines
(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 proof · 8 lines
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
omegatheorem prefix_le_input (t : GraphTables.Table) (k : Nat) :
PreprocessingPaddingOffsets.offset (padding t) k ≤
ExpanderFamily.growth * inputLength t := by proof · 4 lines
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 := body · 3 lines
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 proof · 6 lines
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 hnoncomputable def regularPolynomial : Polynomial Nat := body · 1 line
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 proof · 10 lines
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 henoncomputable def rotorPolynomial (q : Nat) : Polynomial Nat := body · 2 lines
(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 proof · 10 lines
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 hOutline
- def
naturalWordsEncoding11 - def
formulaEncoding16 - def
gameEncoding21 - def
prefixBitMachine26 - def
prefixBitPolyTime37 - def
enlargePolynomialBound56 - def
composeMachinePhases69 - structure
PolynomialGapReduction81 - def
inputLength94 - theorem
cloudSize_le_input96 - theorem
cloudTotal_le_input100 - theorem
level_le_input106 - theorem
regularVertices_le_input110 - theorem
offset_le_sum115 - theorem
prefix_le_input126 - def
tablePolynomial134 - theorem
tableBits_le_of_counts139 - def
regularPolynomial149 - theorem
regularBits_le152 - def
rotorPolynomial166 - theorem
cloudRotorBits_le170