File size: 2,442 Bytes
8df23f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Computability.BinPacking.Computation.MachineCanonicalOutput

namespace OAI

namespace BinPackingGap.ExtensionMachineSpace

open Turing BinPackingGames.Foundations.Complexity

def lengthSum {K : Type} {Γ : K → Type} (chosen : List K)
    (tapes : ∀ k, List (Γ k)) : Nat :=
  (chosen.map fun k => (tapes k).length).sum

theorem execution_stackLength (tm : FinTM2) (k : tm.K)
    {start finish : tm.Cfg} {budget : Nat}
    (run : StateTransition.EvalsToInTime tm.step start (some finish) budget) :
    (finish.stk k).length ≤ (start.stk k).length + budget * Runtime.programPushBound tm :=
  Runtime.executionSizeBound tm.step (fun cfg => (cfg.stk k).length)
    (Runtime.programPushBound tm) (Runtime.stepStackLength tm k) run

theorem execution_lengthSum (tm : FinTM2) (chosen : List tm.K)
    {start finish : tm.Cfg} {budget : Nat}
    (run : StateTransition.EvalsToInTime tm.step start (some finish) budget) :
    lengthSum chosen finish.stk ≤
      lengthSum chosen start.stk + chosen.length * (budget * Runtime.programPushBound tm) := by
  induction chosen with
  | nil => simp [lengthSum]
  | cons k chosen ih =>
      have stepBound := execution_stackLength tm k run
      simp only [lengthSum, List.map_cons, List.sum_cons, List.length_cons,
        Nat.add_mul, Nat.one_mul] at ih ⊢
      omega

theorem execution_uniformStackLength (tm : FinTM2)
    {start finish : tm.Cfg} {budget initialBound : Nat}
    (initial : ∀ k, (start.stk k).length ≤ initialBound)
    (run : StateTransition.EvalsToInTime tm.step start (some finish) budget) :
    ∀ k, (finish.stk k).length ≤ initialBound + budget * Runtime.programPushBound tm := by
  intro k
  exact (execution_stackLength tm k run).trans (Nat.add_le_add_right (initial k) _)

theorem lengthSum_le_uniform {K : Type} {Γ : K → Type} (chosen : List K)
    (tapes : ∀ k, List (Γ k)) (bound : Nat) (bounded : ∀ k, (tapes k).length ≤ bound) :
    lengthSum chosen tapes ≤ chosen.length * bound := by
  induction chosen with
  | nil => simp [lengthSum]
  | cons k chosen ih =>
      have head := bounded k
      simp only [lengthSum, List.map_cons, List.sum_cons, List.length_cons,
        Nat.add_mul, Nat.one_mul] at ih ⊢
      omega

theorem lengthSum_eq_cleanup {K : Type} (chosen : List K) (tapes : K → List Bool) :
    lengthSum chosen tapes = MachineDrainMany.lengthSum chosen tapes := rfl

end BinPackingGap.ExtensionMachineSpace

end OAI