File size: 7,051 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import OAI.Computability.RandomMean.Loop

namespace OAI

section
namespace MeanPayoff.TreeDevice.Certified
open BinaryData Code
local infixl:80 " ≫ₚ " => Code.comp
local infixr:70 " ⋏ₚ " => Code.pair
namespace Counter
noncomputable def fixedPower : ℕ → Code Count Count
  | 0 => const [()]
  | k+1 => (Code.id ⋏ₚ fixedPower k) ≫ₚ mul
@[simp] theorem fixedPower_length (k : ℕ) (c : Count) : (fixedPower k c).length=c.length^k := by
  induction k with
  | zero => rfl
  | succ k ih => simp [fixedPower,ih,pow_succ,Nat.mul_comm]
end Counter
namespace RootCode
open InputCode

noncomputable def g : Code Parsed Count := width ≫ₚ NaturalLog.length ≫ₚ Counter.inc ≫ₚ Counter.inc
noncomputable def argument : Code Parsed Count := (const (List.replicate (2^17) ()) ⋏ₚ g) ≫ₚ Counter.mul
noncomputable def exponent : Code Parsed Count := argument ≫ₚ Counter.word ≫ₚ NaturalLog.ceil
noncomputable def cap : Code Parsed Count := (argument ⋏ₚ argument) ≫ₚ Counter.add
noncomputable def samples : Code Parsed Count := (exponent ⋏ₚ cap) ≫ₚ Counter.power
noncomputable def trialBase : Code Parsed Count := (samples ⋏ₚ (n ≫ₚ Counter.inc)) ≫ₚ Counter.mul ≫ₚ Counter.fixedPower 6
noncomputable def trials : Code Parsed Count := (trialBase ⋏ₚ trialBase) ≫ₚ Counter.add ≫ₚ Counter.inc
noncomputable def basic : Code Parsed Count := (n ⋏ₚ ((const (List.replicate 128 ()) ⋏ₚ samples) ≫ₚ Counter.mul)) ≫ₚ Counter.mul
noncomputable def env : Code Parsed RawControl.Env := rows ⋏ₚ exponent ⋏ₚ samples ⋏ₚ trials ⋏ₚ basic

theorem g_length (G : Game) : (g (game G)).length=globalG (topWidth G).toNat+1 := by
  change (NaturalLog.length (width (game G))).length+1+1=_
  rw [NaturalLog.length_exact _ (by rw [width_val]; exact (topWidth_positive G).le),width_val]
  unfold globalG
  omega
 theorem argument_length (G : Game) : (argument (game G)).length=2^17*(globalG (topWidth G).toNat+1) := by
  simp only [argument,comp_eval,pair_eval,const_eval,Counter.mul_length,List.length_replicate,g_length]
 theorem exponent_length (G : Game) : (exponent (game G)).length=sampleExponent (topWidth G).toNat := by
  change (NaturalLog.ceil (Counter.word (argument (game G)))).length=_
  rw [NaturalLog.ceil_exact _ (by rw [Counter.word_val]; exact_mod_cast (show 0<(argument (game G)).length by rw [argument_length]; positivity)),Counter.word_val,Int.toNat_natCast,argument_length]
  rfl
 theorem samples_length (G : Game) : (samples (game G)).length=globalS (topWidth G).toNat := by
  change (Counter.power (exponent (game G),cap (game G))).length=_
  rw [Counter.power_exact]
  · rw [List.length_replicate,exponent_length]
    rfl
  · change 2^(exponent (game G)).length ≤ (Counter.add (argument (game G),argument (game G))).length
    rw [Counter.add_length,exponent_length,argument_length]
    have h := Counter.pow_clog_le (2^17*(globalG (topWidth G).toNat+1)) (by positivity)
    change 2^Nat.clog 2 (2^17*(globalG (topWidth G).toNat+1)) ≤ _
    simpa only [two_mul] using h
 theorem trials_length (G : Game) : (trials (game G)).length=globalJ G.n (topWidth G).toNat := by
  simp only [trials,trialBase,comp_eval,pair_eval,Counter.inc_length,Counter.add_length,Counter.fixedPower_length,Counter.mul_length,n_game,List.length_replicate,samples_length]
  unfold globalJ
  omega
 theorem basic_length (G : Game) : (basic (game G)).length=G.n*(128*globalS (topWidth G).toNat) := by
  simp only [basic,comp_eval,pair_eval,Counter.mul_length,const_eval,List.length_replicate,n_game,samples_length]
 theorem env_rep (G : Game) : RawControl.EnvRep G (topWidth G).toNat (env (game G)) := by
  refine ⟨⟨Normalize.word G,rows_game G,Normalize.word_val G⟩,exponent_length G,samples_length G,trials_length G,?_⟩
  exact (basic_length G).ge
end RootCode
end MeanPayoff.TreeDevice.Certified

end

section
namespace MeanPayoff.TreeDevice.Certified
open BinaryData Code
local infixl:80 " ≫ₚ " => Code.comp
local infixr:70 " ⋏ₚ " => Code.pair
namespace RootCode
open InputCode
noncomputable def ones : Code Parsed (List W) := n ≫ₚ map (Word.constant 1)
noncomputable def budgets : Code Parsed RawBudget.Data :=
  ((n ≫ₚ Counter.word) ⋏ₚ Word.constant 1) ⋏ₚ
  ((n ≫ₚ Counter.word) ⋏ₚ Word.constant 1) ⋏ₚ ones ⋏ₚ ones
noncomputable def box : Code Parsed RawBox.Data :=
  width ⋏ₚ (n ≫ₚ map (Word.constant 0)) ⋏ₚ ((width ⋏ₚ n) ≫ₚ envMap (fst : Code (W×Unit) W))
noncomputable def state : Code Parsed RawControl.State :=
  RawControl.call 0 (RawControl.pack budgets box) (const [])
noncomputable def start : Code Digits (W×RawControl.Acc) :=
  parse ≫ₚ (width ⋏ₚ (env ⋏ₚ state))

 theorem budgets_rep (G : Game) : RawBudget.Rep (rootBudgets G) (budgets (game G)) := by
  have hn : (Counter.word (n (game G))).val=G.n := by simp
  have hx : ones (game G)=List.ofFn (fun _ : Fin G.n => EdgeRead.encodedWord 1) := by
    change (List.replicate G.n ()).map (fun _ => EdgeRead.encodedWord 1)=_
    simp [List.ofFn_const]
  refine ⟨?_,?_,?_,?_,?_,?_,?_⟩
  · change 0<(Counter.word (n (game G))).val
    rw [hn]; exact_mod_cast G.positive
  · change 0<(Word.constant 1 (game G)).val
    simp
  · change 0<(Counter.word (n (game G))).val
    rw [hn]; exact_mod_cast G.positive
  · change 0<(Word.constant 1 (game G)).val
    simp
  · change (G.n : ℚ)=(Counter.word (n (game G))).val/(Word.constant 1 (game G)).val
    simp
  · change (G.n : ℚ)=(Counter.word (n (game G))).val/(Word.constant 1 (game G)).val
    simp
  · refine ⟨fun _ => EdgeRead.encodedWord 1,fun _ => EdgeRead.encodedWord 1,hx,hx,?_,?_,?_,?_⟩ <;>
      intro i <;> simp [EdgeRead.encodedWord_val,rootBudgets]
 theorem box_rep (G : Game) : RawBox.Rep (rootBox G) (box (game G)) := by
  refine ⟨?_,?_,?_⟩
  · change (width (game G)).val=((topWidth G).toNat : ℤ)
    rw [width_val,Int.toNat_of_nonneg (topWidth_positive G).le]
  · refine ⟨fun _ => EdgeRead.encodedWord 0,?_,?_⟩
    · change (List.replicate G.n ()).map (fun _ => EdgeRead.encodedWord 0)=_
      simp [List.ofFn_const]
    · intro i; exact EdgeRead.encodedWord_val 0
  · refine ⟨fun _ => width (game G),?_,?_⟩
    · change (List.replicate G.n ()).map (fun _ => width (game G))=_
      simp [List.ofFn_const]
    · intro i; exact width_val G
 theorem state_rep (G : Game) : RawControl.StateRep
    (SourceControl.State.call (SourceControl.Job.solve (rootBudgets G) (rootBox G)) .done) (state (game G)) := by
  exact .call rfl ⟨budgets_rep G,box_rep G⟩ .done
end RootCode
end MeanPayoff.TreeDevice.Certified

end

section
namespace MeanPayoff.TreeDevice.Certified
open BinaryData Code
local infixl:80 " ≫ₚ " => Code.comp
local infixr:70 " ⋏ₚ " => Code.pair
namespace Allocation
end Allocation
end MeanPayoff.TreeDevice.Certified

end

section
namespace MeanPayoff

namespace PolyBound
variable {ι : Type} {r f g : ι→ℕ}
end PolyBound
namespace TreeDevice
open BinaryData
end TreeDevice
end MeanPayoff

end

end OAI