File size: 4,396 Bytes
ea76aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import Mathlib

namespace OAI

namespace MeanPayoff
structure Game where
  n : ℕ
  positive : 0 < n
  m : ℕ
  tail : Fin m → Fin n
  head : Fin m → Fin n
  maxOwner : Fin n → Bool
  weight : Fin m → ℤ
  total : ∀ v : Fin n, ∃ e : Fin m, tail e = v

def Strategy (G : Game) :=
  List (Fin G.m) → (v : Fin G.n) → {e : Fin G.m // G.tail e = v}

def move (G : Game) (σ τ : Strategy G) (v : Fin G.n)
    (history : List (Fin G.m)) : Fin G.m :=
  if G.maxOwner v then (σ history v).val else (τ history v).val

def position (G : Game) (σ τ : Strategy G) (start : Fin G.n) :
    ℕ → Fin G.n × List (Fin G.m)
  | 0 => (start, [])
  | t + 1 =>
    let p := position G σ τ start t
    let e := move G σ τ p.1 p.2
    (G.head e, p.2 ++ [e])

def play (G : Game) (σ τ : Strategy G) (start : Fin G.n) (t : ℕ) : Fin G.m :=
  let p := position G σ τ start t
  move G σ τ p.1 p.2

noncomputable def meanPayoff (G : Game) (π : ℕ → Fin G.m) : ℝ :=
  Filter.liminf (fun T : ℕ =>
    (∑ j ∈ Finset.range T, (G.weight (π j) : ℝ)) / (T : ℝ)) Filter.atTop

def Winning (G : Game) (v : Fin G.n) : Prop :=
  ∃ σ : Strategy G, ∀ τ : Strategy G, 0 ≤ meanPayoff G (play G σ τ v)

def encodeNat (n : ℕ) : List Bool :=
  let bits := Nat.bits (n + 1)
  List.replicate bits.length true ++ [false] ++ bits

def encodeInt (z : ℤ) : List Bool :=
  decide (z < 0) :: encodeNat z.natAbs

def input (G : Game) : List Bool :=
  encodeNat G.n ++ encodeNat G.m ++ List.ofFn G.maxOwner ++
    (List.ofFn (fun e : Fin G.m =>
      encodeNat ((G.tail e).val + 1) ++ encodeNat ((G.head e).val + 1) ++
        encodeInt (G.weight e))).flatten

abbrev Symbol := Option Bool

inductive Direction where
  | left | stay | right
  deriving DecidableEq

def Direction.offset : Direction → ℤ
  | .left => -1
  | .stay => 0
  | .right => 1

structure Action (q : ℕ) where
  next : Fin q
  write : Fin 3 → Symbol
  shift : Fin 3 → Direction

structure Machine where
  states : ℕ
  start : Fin states
  transition : Fin states → (Fin 3 → Symbol) → Bool → Option (Action states)

structure Configuration (M : Machine) where
  control : Option (Fin M.states)
  head : Fin 3 → ℤ
  tape : Fin 3 → ℤ → Symbol

def initial (M : Machine) (code : List Bool) : Configuration M where
  control := some M.start
  head := fun _ => 0
  tape := fun k j => if k = 0 ∧ 0 ≤ j then code[j.toNat]? else none

def step (M : Machine) (c : Configuration M) (bit : Bool) : Configuration M :=
  match c.control with
  | none => c
  | some s =>
    match M.transition s (fun k => c.tape k (c.head k)) bit with
    | none => { c with control := none }
    | some a =>
      { control := some a.next
        head := fun k => c.head k + (a.shift k).offset
        tape := fun k => Function.update (c.tape k) (c.head k) (a.write k) }

def run (M : Machine) (code : List Bool) (random : ℕ → Bool) : ℕ → Configuration M
  | 0 => initial M code
  | t + 1 => step M (run M code random t) (random t)

def padBits {T : ℕ} (bits : Fin T → Bool) (j : ℕ) : Bool :=
  if h : j < T then bits ⟨j, h⟩ else false

def result (M : Machine) (G : Game) (T : ℕ) (bits : Fin T → Bool) : Configuration M :=
  run M (input G) (padBits bits) T

def CorrectOutput (G : Game) {M : Machine} (c : Configuration M) : Prop :=
  c.control = none ∧
  (∀ v : Fin G.n, c.tape 2 (v.val : ℤ) = some true ↔ Winning G v) ∧
  (∀ v : Fin G.n, c.tape 2 (v.val : ℤ) = some false ↔ ¬ Winning G v) ∧
  ∀ j : ℤ, (j < 0 ∨ (G.n : ℤ) ≤ j) → c.tape 2 j = none

noncomputable def MainClaim : Prop := by
  classical
  exact ∃ M : Machine, ∃ C : ℝ, 0 < C ∧ ∀ G : Game, ∃ T : ℕ,
    (T : ℝ) ≤ (2 : ℝ) ^ (C * (Real.logb 2 ((input G).length + 2)) ^ 2) ∧
    (∀ bits : Fin T → Bool, (result M G T bits).control = none) ∧
    7 * 2 ^ T ≤ 8 * (Finset.univ.filter
      (fun bits : Fin T → Bool => CorrectOutput G (result M G T bits))).card


def Deterministic (M : Machine) : Prop :=
  ∀ s cells, M.transition s cells true = M.transition s cells false
def DeterministicMainClaim : Prop :=
  ∃ M : Machine, Deterministic M ∧ ∃ C : ℝ, 0 < C ∧ ∀ G : Game, ∃ T : ℕ,
    (T : ℝ) ≤ (2 : ℝ) ^ (C * (Real.logb 2 ((input G).length + 2)) ^ 2) ∧
    CorrectOutput G (run M (input G) (fun _ => false) T)
end MeanPayoff

end OAI