introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.4 kB
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