File size: 3,682 Bytes
4a56cd6 | 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 | import Mathlib
import OAI.Combinatorics.IndependentSets.Machines.MachineFiniteAlphabet
import OAI.Combinatorics.IndependentSets.Machines.GraphCounterFinish
namespace OAI
namespace LargeIndependentSets.BoundedIteration
open Turing
open IndependentSetsGames.Foundations.Complexity
variable {Ξ± Ξ² : Type}
def counted (count : Ξ± β β) (enc : Ξ² β List Bool) (start : Ξ± β Ξ²) (a : Ξ±) : List Bool :=
encodeWord (count a) ++ enc (start a)
lemma count_le (count : Ξ± β β) (enc : Ξ² β List Bool) (start : Ξ± β Ξ²) (a : Ξ±) :
count a β€ (counted count enc start a).length := by
simp [counted,encodeWord]
noncomputable def runtime (body length : Polynomial β) : Polynomial β :=
Polynomial.X*(body.comp length + 2*length + 4) + 2*length + 4
lemma runtime_eval (body length : Polynomial β) (n : β) :
(runtime body length).eval n = n*(body.eval (length.eval n)+2*length.eval n+4)+2*length.eval n+4 := by
simp [runtime]
noncomputable def certificate (enc : Ξ² β List Bool) (step : Ξ² β Ξ²) (start : Ξ± β Ξ²)
(count : Ξ± β β) (body : TM2ComputableInPolyTime enc enc step) (length : Polynomial β)
(growth : β a i, iβ€count a β (enc (step^[i] (start a))).length β€
length.eval (counted count enc start a).length) :
TM2ComputableInPolyTime (counted count enc start) enc
(fun a => step^[count a] (start a)) where
tm := MachineRepeat.machine body.tm body.inputAlphabet body.outputAlphabet
inputAlphabet := body.inputAlphabet
outputAlphabet := body.inputAlphabet
time := runtime body.time length
outputsFun a := by
let words : β β List Bool := fun i => enc (step^[i] (start a))
let budgets : β β β := fun i => body.time.eval (words i).length
have runs (i : β) (_hi : i<count a) :
TM2OutputsInTime body.tm ((words i).map body.inputAlphabet.symm)
(some ((words (i+1)).map body.outputAlphabet.symm)) (budgets i) := by
simpa only [words,budgets,Function.iterate_succ_apply',Equiv.symm,Equiv.coe_fn_mk] using
body.outputsFun (step^[i] (start a))
let run := MachineRepeat.executeSequence body.tm body.inputAlphabet body.outputAlphabet
(count a) words budgets runs
have start_eq : encodeWord (count a) ++ words 0 = counted count enc start a := rfl
rw [start_eq] at run
refine { toEvalsTo := run.toEvalsTo, steps_le_m := ?_ }
let N := (counted count enc start a).length
let L := length.eval N
let B := body.time.eval L
have hl (i : β) (hi : iβ€count a) : (words i).lengthβ€L := growth a i hi
have hb (i : β) (hi : i<count a) : budgets iβ€B :=
MachineComposition.natPolynomial_eval_mono body.time (hl i hi.le)
have hloop := MachineRepeat.loopBudget_le (count a) words budgets B L hb hl
have hc : count aβ€N := count_le count enc start a
rw [runtime_eval]
calc
run.steps β€ count a+1+MachineRepeat.loopBudget (count a) words budgets := run.steps_le_m
_ β€ count a+1+(count a*(B+2*L+3)+2*L+3) := Nat.add_le_add_left hloop _
_ = count a*(B+2*L+4)+2*L+4 := by ring
_ β€ N*(B+2*L+4)+2*L+4 := by gcongr
lemma certificate_finiteAlphabet (enc : Ξ² β List Bool) (step : Ξ² β Ξ²) (start : Ξ± β Ξ²)
(count : Ξ± β β) (body : TM2ComputableInPolyTime enc enc step) (length : Polynomial β)
(growth) (hbody : MachineFiniteAlphabet.FiniteAlphabet body.tm)
(k : (certificate enc step start count body length growth).tm.K) :
Finite ((certificate enc step start count body length growth).tm.Ξ k) :=
MachineFiniteAlphabet.repeat_machine body.tm body.inputAlphabet body.outputAlphabet hbody k
end LargeIndependentSets.BoundedIteration
end OAI
|