Download lean/OAI/Combinatorics/IndependentSets/Machines/MachineComposition.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 7.01 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Machines/MachineComposition.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/IndependentSets/Machines/MachineComposition.lean
-
curl -L -o MachineComposition.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Machines/MachineComposition.lean
7.01 kB
Lean 4 · 12
declarations statementsfull
def advance {σ : Type} (step : σ → Option σ) (state : Option σ) : Option σ := body · 1 line
state.bind step
@[simp] theorem advance_none {σ : Type} (step : σ → Option σ) :
advance step none = none := rfl @[simp] theorem advance_some {σ : Type} (step : σ → Option σ) (state : σ) :
advance step (some state) = step state := rfl @[simp] theorem advance_iterate_none {σ : Type} (step : σ → Option σ) (n : Nat) :
(advance step)^[n] none = none := by proof · 3 lines
induction n with
| zero => rfl
| succ n ih => rw [Function.iterate_succ_apply', ih, advance_none]theorem liftSuccessfulTrace {σ τ : Type} (source : σ → Option σ)
(target : τ → Option τ) (embed : σ → τ)
(simulation : ∀ a b, source a = some b → target (embed a) = some (embed b))
(n : Nat) (start finish : σ)
(trace : (advance source)^[n] (some start) = some finish) :
(advance target)^[n] (some (embed start)) = some (embed finish) := by proof · 17 lines
induction n generalizing start with
| zero =>
have same := Option.some.inj trace
cases same
rfl
| succ n ih =>
rw [Function.iterate_succ_apply] at trace ⊢
change (advance source)^[n] (source start) = some finish at trace
change (advance target)^[n] (target (embed start)) = some (embed finish)
cases firstStep : source start with
| none =>
rw [firstStep, advance_iterate_none] at trace
contradiction
| some intermediate =>
rw [firstStep] at trace
rw [simulation start intermediate firstStep]
exact ih intermediate tracedef liftExecutionInTime {σ τ : Type} (source : σ → Option σ)
(target : τ → Option τ) (embed : σ → τ)
(simulation : ∀ a b, source a = some b → target (embed a) = some (embed b))
{start finish : σ} {budget : Nat}
(execution : StateTransition.EvalsToInTime source start (some finish) budget) :
StateTransition.EvalsToInTime target (embed start) (some (embed finish)) budget where body · 7 lines
steps := execution.steps
evals_in_steps := by
have sourceTrace := execution.evals_in_steps
change (advance source)^[execution.steps] (some start) = some finish at sourceTrace
change (advance target)^[execution.steps] (some (embed start)) = some (embed finish)
exact liftSuccessfulTrace source target embed simulation execution.steps start finish sourceTrace
steps_le_m := execution.steps_le_m@[simp] theorem liftExecutionInTime_steps {σ τ : Type} (source : σ → Option σ)
(target : τ → Option τ) (embed : σ → τ)
(simulation : ∀ a b, source a = some b → target (embed a) = some (embed b))
{start finish : σ} {budget : Nat}
(execution : StateTransition.EvalsToInTime source start (some finish) budget) :
(liftExecutionInTime source target embed simulation execution).steps = execution.steps := rfl def embeddedExecution {K E Λ Λextra σ τ : Type} {Γ : K → Type} {Δ : E → Type}
[DecidableEq K] [DecidableEq E]
(haltTarget : Option (Λ ⊕ Λextra)) (extraState : τ)
(extraTapes : ∀ e, List (Δ e))
(source : Λ → Turing.TM2.Stmt Γ Λ σ)
(extra : Λextra → Turing.TM2.Stmt (MachineEmbedding.Alphabet Γ Δ)
(Λ ⊕ Λextra) (σ × τ))
{start finish : Turing.TM2.Cfg Γ Λ σ} {budget : Nat}
(execution : StateTransition.EvalsToInTime (Turing.TM2.step source)
start (some finish) budget) :
StateTransition.EvalsToInTime (Turing.TM2.step (MachineEmbedding.program haltTarget source extra))
(MachineEmbedding.configuration haltTarget extraState extraTapes start)
(some (MachineEmbedding.configuration haltTarget extraState extraTapes finish)) budget := body · 4 lines
liftExecutionInTime (Turing.TM2.step source)
(Turing.TM2.step (MachineEmbedding.program haltTarget source extra))
(MachineEmbedding.configuration haltTarget extraState extraTapes)
(MachineEmbedding.step_simulation haltTarget extraState extraTapes source extra) executiontheorem natPolynomial_eval_mono (p : Polynomial Nat) {a b : Nat} (h : a ≤ b) :
p.eval a ≤ p.eval b := by proof · 6 lines
induction p using Polynomial.induction_on' with
| add p q hp hq =>
simpa only [Polynomial.eval_add] using Nat.add_le_add hp hq
| monomial degree coefficient =>
simp only [Polynomial.eval_monomial]
exact Nat.mul_le_mul_left coefficient (Nat.pow_le_pow_left h degree)noncomputable def compositionPolynomial (first second intermediate : Polynomial Nat) : Polynomial Nat := body · 1 line
first + Polynomial.C 2 * (intermediate + 1) + second.comp intermediatetheorem compositionBudget_le (first second intermediate : Polynomial Nat)
(inputLength intermediateLength : Nat)
(intermediateBound : intermediateLength ≤ intermediate.eval inputLength) :
first.eval inputLength + 2 * (intermediateLength + 1) + second.eval intermediateLength ≤
(compositionPolynomial first second intermediate).eval inputLength := by proof · 5 lines
have secondBound := natPolynomial_eval_mono second intermediateBound
have transferBound := Nat.mul_le_mul_left 2 (Nat.add_le_add_right intermediateBound 1)
simp only [compositionPolynomial, Polynomial.eval_add, Polynomial.eval_mul,
Polynomial.eval_C, Polynomial.eval_one, Polynomial.eval_comp]
omegadef fourPhaseExecution {σ : Type} (step : σ → Option σ)
(start afterFirst afterTransfer₁ afterTransfer₂ : σ) (finish : Option σ)
(first second intermediate : Polynomial Nat) (inputLength intermediateLength : Nat)
(intermediateBound : intermediateLength ≤ intermediate.eval inputLength)
(runFirst : StateTransition.EvalsToInTime step start (some afterFirst) (first.eval inputLength))
(transfer₁ : StateTransition.EvalsToInTime step afterFirst (some afterTransfer₁)
(intermediateLength + 1))
(transfer₂ : StateTransition.EvalsToInTime step afterTransfer₁ (some afterTransfer₂)
(intermediateLength + 1))
(runSecond : StateTransition.EvalsToInTime step afterTransfer₂ finish
(second.eval intermediateLength)) :
StateTransition.EvalsToInTime step start finish
((compositionPolynomial first second intermediate).eval inputLength) := by body · 13 lines
let firstTwo := StateTransition.EvalsToInTime.trans step _ _ start afterFirst
(some afterTransfer₁) runFirst transfer₁
let firstThree := StateTransition.EvalsToInTime.trans step _ _ start afterTransfer₁
(some afterTransfer₂) firstTwo transfer₂
let allFour := StateTransition.EvalsToInTime.trans step _ _ start afterTransfer₂
finish firstThree runSecond
refine {
toEvalsTo := allFour.toEvalsTo
steps_le_m := Nat.le_trans allFour.steps_le_m ?_
}
have bounded := compositionBudget_le first second intermediate inputLength intermediateLength
intermediateBound
omegaOutline
- def
advance8 - theorem
advance_none11 - theorem
advance_some14 - theorem
advance_iterate_none17 - theorem
liftSuccessfulTrace23 - def
liftExecutionInTime47 - theorem
liftExecutionInTime_steps61 - def
embeddedExecution68 - theorem
natPolynomial_eval_mono86 - def
compositionPolynomial95 - theorem
compositionBudget_le98 - def
fourPhaseExecution109