File size: 3,154 Bytes
2f887db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Computability.MinUncut.Graphs.GraphWordCodec
import OAI.Computability.MinUncut.Estimates.FiberPrefix

namespace OAI

section
namespace MinUncut.Costed.FrameDecode
open _root_.Turing _root_.OAI.Turing _root_.Turing.PartrecToTM2 _root_.OAI.Turing.PartrecToTM2 MinUncutGames.BinaryEncoding
inductive Mode
  | flag | payload | suffix
  deriving DecidableEq

protected abbrev Mode.enumList : List Mode := [.flag, .payload, .suffix]

protected theorem Mode.enumList_getElem?_ctorIdx_eq (x : Mode) :
    Mode.enumList[x.ctorIdx]? = some x := by
  cases x <;> rfl

protected theorem Mode.enumList_nodup : Mode.enumList.Nodup := by decide

instance : Fintype Mode where
  elems := ⟨Mode.enumList, Mode.enumList_nodup⟩
  complete x := by cases x <;> decide

def next : Mode → Bool → Mode
  | .flag,true => .payload
  | .flag,false => .suffix
  | .payload,_ => .flag
  | .suffix,_ => .suffix

def symbol (b : Bool) : ℕ := b.toNat+1

def emit : Mode → Bool → List Γ'
  | .flag,true => []
  | .flag,false => [.cons]
  | .payload,b => [GraphCodec.bitSymbol b]
  | .suffix,b => trNat (symbol b)++[.cons]

def machine : FinTM2 := WordTransducer.machine .flag next emit
lemma finiteAlphabet (k : machine.K) : Finite (machine.Γ k) :=
  WordTransducer.finiteAlphabet .flag next emit k
lemma suffix_output (v : List Bool) :
    WordTransducer.output next emit .suffix v=trList (v.map symbol) := by
  induction v with
  | nil => rfl
  | cons b v ih =>
    simp only [WordTransducer.output,next,emit,List.map_cons,trList,ih,List.append_assoc,List.singleton_append]
lemma frame_output (v w : List Bool) :
    WordTransducer.output next emit .flag (frame v++w)=
      v.map GraphCodec.bitSymbol++Γ'.cons::trList (w.map symbol) := by
  induction v with
  | nil => simpa only [frame,List.cons_append,List.nil_append,WordTransducer.output,next,emit,
      List.singleton_append,List.map_nil] using congrArg (List.cons Γ'.cons) (suffix_output w)
  | cons b v ih =>
    simp only [frame,List.cons_append,WordTransducer.output,next,emit,List.nil_append,
      List.map_cons,ih]
lemma output_spec (K : ℕ) (w : List Bool) :
    WordTransducer.output next emit .flag (nameBits K++w)=trList (K::w.map symbol) := by
  rw [nameBits,frame_output,←GraphCodec.trNat_bits]
  rfl
def outputs (K : ℕ) (w : List Bool) :
    TM2OutputsInTime machine (nameBits K++w) (some (trList (K::w.map symbol)))
      (2*(nameBits K++w).length+(trList (K::w.map symbol)).length+2) := by
  have h := WordTransducer.outputsInTime .flag next emit (nameBits K++w)
  erw [output_spec] at h
  exact h
lemma count_symbols (v : List Bool) : UnaryWords.count (v.map symbol)=v.length := by
  induction v with
  | nil => rfl
  | cons b v ih =>
    simp only [List.map_cons,UnaryWords.count,symbol,show b.toNat+1≠0 by omega,ite_false,ih,List.length_cons]
lemma magnitude_symbols (v : List Bool) : magnitude (v.map symbol)≤3*v.length := by
  induction v with
  | nil => rfl
  | cons b v ih =>
    have hb : b.toNat≤1 := by cases b <;> decide
    simp only [List.map_cons,magnitude_cons,List.length_cons,symbol]
    omega
end MinUncut.Costed.FrameDecode

end

end OAI