File size: 3,538 Bytes
760f90e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Computability.Scheduling.MachineBridge

namespace OAI

section
namespace ThreeMachine.StackCompiler

theorem enc_request {n : ℕ} (x : Request n) :
    enc x = enc (ThreeMachine.encodeInput x.graph x.deadline) := rfl

theorem requestAnswer_time_charge {n : ℕ} (x : Request n) :
    Uniform.requestAnswer.time n x =
      Uniform.requestAnswer.charge (enc (ThreeMachine.encodeInput x.graph x.deadline)) := by
  unfold Uniform.time
  exact congrArg Uniform.requestAnswer.charge (enc_request x)

theorem Uniform.exists_requestMachine
    (R : Uniform (fun n (x : Request n) => Algorithm.output x.graph x.deadline)) :
    ∃ k q g, ∃ M : Machine k q g, ∀ n (x : Request n),
      M.Produces (ThreeMachine.encodeInput x.graph x.deadline)
        (Algorithm.output x.graph x.deadline)
        (2000*(R.time n x+(ThreeMachine.encodeInput x.graph x.deadline).length+
          (Algorithm.output x.graph x.deadline).length+1)) := by
  obtain ⟨k,q,g,M,hM⟩ := R.routine.exists_rawMachine
  refine ⟨k,q,g,M,?_⟩
  intro n x
  have hc := R.correct n x
  rw [enc_request] at hc
  have hr := hM (ThreeMachine.encodeInput x.graph x.deadline)
    (Algorithm.output x.graph x.deadline) hc
  simpa only [Uniform.time,enc_request] using hr

def requestRawBound (x : RequestData.Index) : ℕ :=
  2000*(Uniform.requestAnswer.time x.1 x.2+(RequestData.bits x).length+
    (Algorithm.output x.2.graph x.2.deadline).length+1)

theorem requestRawBound_poly : Poly RequestData.size requestRawBound 150011 := by
  have ht := Costs.requestAnswer
  have hb := RequestData.bitsPoly
  have ho := Costs.requestOutputLength
  unfold requestRawBound
  poly_auto

abbrev SmallDeadline := {x : RequestData.Index // x.2.deadline.getD 0 ≤ x.1}

theorem requestRawBound_length : Poly (fun x : SmallDeadline => (RequestData.bits x.1).length)
    (fun x => requestRawBound x.1) 150020 := by
  let s (x : SmallDeadline) := (RequestData.bits x.1).length
  have hsize : Poly s (fun x => RequestData.size x.1) 1 := by
    apply Poly.of_le (fun x : SmallDeadline => requestSize_le x.1.2 x.2)
    exact (Poly.const s 4).mul (Poly.size s)
  have h := Poly.reparam (r := 1) requestRawBound_poly (Subtype.val : SmallDeadline → RequestData.Index) hsize
  exact h.lift (by omega)

end ThreeMachine.StackCompiler
namespace ThreeMachine
open StackCompiler

theorem main_theorem : ReleaseTheorem := by
  obtain ⟨k,q,g,M,hM⟩ := Uniform.exists_requestMachine Uniform.requestAnswer
  obtain ⟨C,hC⟩ := requestRawBound_length
  refine ⟨k,q,g,M,C+1,by omega,?_⟩
  intro n G hn hG deadline hd
  let x : Request n := ⟨G,deadline⟩
  have hsmall : deadline.getD 0 ≤ n := by
    cases deadline with
    | none => simp only [Option.getD_none]; omega
    | some T => exact (hd T (by simp)).2
  let y : SmallDeadline := ⟨⟨n,x⟩,hsmall⟩
  refine ⟨Algorithm.output G deadline,Algorithm.output_correct G hn hG deadline,?_⟩
  have hr := hM n x
  have hb : 2000*(Uniform.requestAnswer.time n x+
      (encodeInput G deadline).length+(Algorithm.output G deadline).length+1) ≤
        (C+1)*((encodeInput G deadline).length+2)^150020 := by
    calc
      _ = requestRawBound y.1 := rfl
      _ ≤ C*((encodeInput G deadline).length+2)^150020 := by
        have hy := hC y
        dsimp only [RequestData.bits,y,x] at hy
        exact hy
      _ ≤ (C+1)*((encodeInput G deadline).length+2)^150020 :=
        Nat.mul_le_mul_right _ (Nat.le_succ C)
  obtain ⟨t,ht,halt,out⟩ := hr
  exact ⟨t,ht.trans hb,halt,out⟩

end ThreeMachine

end

end OAI