File size: 2,420 Bytes
e5a97c6 | 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 | import Mathlib
import OAI.Combinatorics.MatchingCount.Machines.PhysicalPost
namespace OAI
namespace MatchingFPRAS.PhysicalPost
open Turing PhysicalStream
variable {Γ Q α β : Type} [Inhabited Γ]
inductive Implements (M : Table Γ Q) (out : α → Cfg Γ Q) :
Cfg Γ Q → Experiment α → Prop
| done (a) : Implements M out (out a) (.done a)
| read (c) (f : Bool → Experiment α)
(h : ∀ b,Implements M out (tick M c b) (f b)) : Implements M out c (.read f)
| delay (c d) (n : ℕ) (p : Experiment α)
(step : ∀ b : Stream,execute M n c b=d)
(rest : Implements M out d p) : Implements M out c (.delay n p)
namespace Implements
variable {M : Table Γ Q} {out : α → Cfg Γ Q} {c : Cfg Γ Q} {p : Experiment α}
lemma execution (h : Implements M out c p) (b : Stream) :
execute M (p.run b).2 c b=out (p.run b).1 := by
induction h generalizing b with
| done a => rfl
| read c f h ih =>
simp only [Experiment.run,execute_add]
exact ih (b 0) (shift 1 b)
| delay c d n p hs hr ih =>
simp only [Experiment.run,execute_add,hs]
exact ih (shift n b)
lemma bind (h : Implements M out c p) (q : α → Experiment β)
(out' : β → Cfg Γ Q) (hq : ∀ a,Implements M out' (out a) (q a)) :
Implements M out' c (p.bind q) := by
induction h with
| done a => exact hq a
| read c f h ih => exact .read c _ ih
| delay c d n p hs hr ih => exact .delay c d n _ hs ih
lemma padded_execution (h : Implements M out c p) (halt : ∀ a,(out a).state=none)
(n : ℕ) (hn : p.cost ≤ n) (b : Stream) :
execute M n c b=out (p.run b).1 := by
have hb : (p.run b).2 ≤ n:=(Experiment.run_cost p b).trans hn
obtain ⟨k,hk⟩:=Nat.exists_eq_add_of_le hb
rw [hk,execute_add,h.execution b]
have he : out (p.run b).1=⟨none,(out (p.run b).1).tape⟩ := by
cases e:out (p.run b).1 with
| mk state tape =>
have hstate := halt (p.run b).1
rw [e] at hstate
change state = none at hstate
subst state
rfl
rw [he,execute_halted]
theorem fair_law (h : Implements M out c p) (halt : ∀ a,(out a).state=none)
(n : ℕ) (hn : p.cost ≤ n) (f : Cfg Γ Q → ℚ) :
average (fun b : Bits n=>f (execute M n c (extend b)))=p.mean (fun a=>f (out a)) := by
simp_rw [h.padded_execution halt n hn]
exact Experiment.average_run p (fun a=>f (out a)) n hn
end Implements
end MatchingFPRAS.PhysicalPost
end OAI
|