File size: 3,556 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Mathlib

namespace OAI

namespace ThreeMachine

structure Instance (n : β„•) where
  edges : List (Fin n Γ— Fin n)

def Instance.edge {n : β„•} (G : Instance n) (u v : Fin n) : Prop :=
  (u, v) ∈ G.edges

def Instance.acyclic {n : β„•} (G : Instance n) : Prop :=
  βˆ€ v, Β¬Relation.TransGen G.edge v v

def Feasible {n : β„•} (G : Instance n) (T : β„•) (Ο„ : Fin n β†’ β„•) : Prop :=
  (βˆ€ v, 1 ≀ Ο„ v ∧ Ο„ v ≀ T) ∧
  (βˆ€ t, ((Finset.univ : Finset (Fin n)).filter (fun v => Ο„ v = t)).card ≀ 3) ∧
  βˆ€ u v, G.edge u v β†’ Ο„ u < Ο„ v

def encodeNat (n : β„•) : List Bool :=
  let b := Computability.encodeNat n
  List.replicate b.length true ++ false :: b

def encodeList {Ξ± : Type} (f : Ξ± β†’ List Bool) (xs : List Ξ±) : List Bool :=
  encodeNat xs.length ++ xs.flatMap f

def encodeInput {n : β„•} (G : Instance n) (deadline : Option β„•) : List Bool :=
  (match deadline with
    | none => [false]
    | some T => true :: encodeNat T) ++
  encodeList encodeNat ((List.range n).map (Β· + 1)) ++
  encodeList (fun (e : Fin n Γ— Fin n) => encodeNat (e.1.val + 1) ++
    encodeNat (e.2.val + 1)) G.edges

def encodeAnswer : Option (List β„•) β†’ List Bool
  | none => [false]
  | some slots => true :: encodeList encodeNat slots

def slots {n : β„•} (Ο„ : Fin n β†’ β„•) : List β„• := List.ofFn Ο„

def CorrectOutput {n : β„•} (G : Instance n) (deadline : Option β„•)
    (out : List Bool) : Prop :=
  match deadline with
  | none => βˆƒ T Ο„, Feasible G T Ο„ ∧
      (βˆ€ T' Ο„', Feasible G T' Ο„' β†’ T ≀ T') ∧
      out = encodeAnswer (some (slots Ο„))
  | some T =>
      (out = encodeAnswer none ∧ Β¬βˆƒ Ο„, Feasible G T Ο„) ∨
      βˆƒ Ο„, Feasible G T Ο„ ∧ out = encodeAnswer (some (slots Ο„))

structure Machine (k q g : β„•) where
  transition : Fin (q + 1) β†’ (Fin (k + 1) β†’ Fin (g + 3)) β†’
    Option (Fin (q + 1) Γ— (Fin (k + 1) β†’ Fin (g + 3) Γ— Option Turing.Dir))

structure Configuration (k q g : β„•) where
  state : Fin (q + 1)
  tapes : Fin (k + 1) β†’ Turing.Tape (Fin (g + 3))

def bitSymbol {g : β„•} (b : Bool) : Fin (g + 3) :=
  if b then ⟨2, by omega⟩ else ⟨1, by omega⟩

def Machine.step {k q g : β„•} (M : Machine k q g)
    (c : Configuration k q g) : Option (Configuration k q g) := do
  let (state, action) ← M.transition c.state (fun i => (c.tapes i).head)
  return { state := state, tapes := fun i =>
    let tape := (c.tapes i).write (action i).1
    match (action i).2 with
    | none => tape
    | some d => tape.move d }

def Machine.initial {k q g : β„•} (_M : Machine k q g)
    (input : List Bool) : Configuration k q g :=
  { state := 0, tapes := fun i =>
      Turing.Tape.mk₁ (if i = 0 then input.map bitSymbol else []) }

def Machine.run {k q g : β„•} (M : Machine k q g) (input : List Bool)
    (t : β„•) : Configuration k q g :=
  (fun c => (M.step c).getD c)^[t] (M.initial input)

def Machine.Produces {k q g : β„•} (M : Machine k q g)
    (input out : List Bool) (timeBound : β„•) : Prop :=
  βˆƒ t ≀ timeBound, M.step (M.run input t) = none ∧
    ((M.run input t).tapes 0).rightβ‚€ = Turing.ListBlank.mk (out.map bitSymbol)

def ReleaseTheorem : Prop :=
  βˆƒ (k q g : β„•) (M : Machine k q g) (C : β„•), 0 < C ∧
    βˆ€ n (G : Instance n), 1 ≀ n β†’ G.acyclic β†’
      βˆ€ deadline : Option β„•,
        (βˆ€ T ∈ deadline, 1 ≀ T ∧ T ≀ n) β†’
        βˆƒ out, CorrectOutput G deadline out ∧
          M.Produces (encodeInput G deadline) out
            (C * ((encodeInput G deadline).length + 2) ^ 150020)

end ThreeMachine

end OAI