File size: 4,783 Bytes
4a56cd6 | 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 | import Mathlib
import OAI.Combinatorics.MatchingCount.Complexity.TreeCostMeasure
import OAI.Combinatorics.MatchingCount.Machines.OnlineTree
namespace OAI
namespace MatchingFPRAS.PhysicalStream.Experiment
variable {A B : Type}
lemma worst_mono (p : Experiment A) (f g : Aββ) (h : p.All (fun a=>f aβ€g a)) :
p.worst fβ€p.worst g := by
induction p with
| done a => exact h
| read p ih => exact max_le_max (ih false h.1) (ih true h.2)
| delay n p ih => exact ih h
lemma All.and {p : Experiment A} {P Q : AβProp} (hp : p.All P) (hq : p.All Q) :
p.All (fun a=>P a β§ Q a) := by
induction p with
| done a => exact β¨hp,hqβ©
| read p ih => exact β¨ih false hp.1 hq.1,ih true hp.2 hq.2β©
| delay n p ih => exact ih hp hq
lemma worst_const (p : Experiment A) (n : β) : p.worst (fun _=>n)=n := by
induction p with
| done a => rfl
| read p ih => simp only [worst,ih, max_self]
| delay n p ih => exact ih
lemma worst_bind (p : Experiment A) (f : AβExperiment B) (h : Bββ) :
(p.bind f).worst h=p.worst (fun a=>(f a).worst h) := by
induction p with
| done a => rfl
| read p ih => simp only [bind,worst,ih]
| delay n p ih => exact ih
lemma worst_map (p : Experiment A) (f : AβB) (h : Bββ) :
(p.map f).worst h=p.worst (h β f) := worst_bind _ _ _
lemma worst_eq_of_mean_eq {p q : Experiment A} (h : β f : Aββ,p.mean f=q.mean f) (g : Aββ) :
p.worst g=q.worst g := by
apply Nat.le_antisymm
Β· exact worst_le _ _ _ (all_of_mean_eq h _ (all_worst q g))
Β· exact worst_le _ _ _ (all_of_mean_eq (fun f=>(h f).symm) _ (all_worst p g))
end MatchingFPRAS.PhysicalStream.Experiment
namespace MatchingFPRAS.OnlineTree
open TreeTyped PhysicalStream Polynomial
variable {A B C : Type} [Codec A] [Codec B] [Codec C]
def WorkBound {f : AβExperiment B} (F : Realizer f) (measure : Aββ) : Prop :=
β p : Polynomial β,β a,F.cost a+(f a).worst weightβ€p.eval (measure a)
abbrev PolynomialTime {f : AβExperiment B} (F : Realizer f) : Prop := WorkBound F weight
lemma work_deterministic {f : AβB} {F : TreeTyped.Realizer f} {m : Aββ}
(hF : TreeTyped.WorkBound F m) : WorkBound (deterministic F) m := hF
lemma work_congr {f g : AβExperiment B} {F : Realizer f} {m : Aββ}
(h : β a w,(f a).mean w=(g a).mean w) (hF : WorkBound F m) : WorkBound (F.congr h) m := by
obtain β¨p,hpβ©:=hF
refine β¨p,fun a=>?_β©
change F.cost a+(g a).worst weightβ€_
rw [βExperiment.worst_eq_of_mean_eq (h a)]
exact hp a
lemma work_remeasure {f : AβExperiment B} {F : Realizer f} {m n : Aββ}
(hF : WorkBound F m) (p : Polynomial β) (hm : β a,m aβ€p.eval (n a)) : WorkBound F n := by
obtain β¨q,hqβ©:=hF
exact β¨q.comp p,fun a=>(hq a).trans (by simpa using polynomial_eval_monotone q (hm a))β©
lemma work_of_polynomial {f : AβExperiment B} {F : Realizer f} {m : Aββ}
(hF : PolynomialTime F) (p : Polynomial β) (hm : β a,weight aβ€p.eval (m a)) : WorkBound F m :=
work_remeasure hF p hm
lemma work_composition {f : AβExperiment B} {g : BβExperiment C} {F : Realizer f} {G : Realizer g}
{m : Aββ} {n : Bββ} (hF : WorkBound F m) (hG : WorkBound G n)
(p : Polynomial β) (hm : β a,(f a).All (fun b=>n bβ€p.eval (m a))) :
WorkBound (composition F G) m := by
obtain β¨q,hqβ©:=hF
obtain β¨r,hrβ©:=hG
refine β¨q+2*(r.comp p),fun a=>?_β©
have hb : (f a).All (fun b=>G.cost b+(g b).worst weightβ€r.eval (p.eval (m a))) :=
(hm a).mono (fun b hb=>(hr b).trans (polynomial_eval_monotone r hb))
have h1:=Experiment.worst_le _ _ _ (hb.mono (fun b hb=>Nat.le_trans (Nat.le_add_right _ _) hb))
have h2:=Experiment.worst_le _ _ _ (hb.mono (fun b hb=>Nat.le_trans (Nat.le_add_left _ _) hb))
have h3:=hq a
change F.cost a+(f a).worst G.cost+((f a).bind g).worst weightβ€_
rw [Experiment.worst_bind]
simp only [Polynomial.eval_add,Polynomial.eval_mul,Polynomial.eval_ofNat,Polynomial.eval_comp]
omega
lemma work_then_polynomial {f : AβExperiment B} {g : BβExperiment C} {F : Realizer f} {G : Realizer g}
{m : Aββ} (hF : WorkBound F m) (hG : PolynomialTime G) : WorkBound (composition F G) m := by
obtain β¨p,hpβ©:=hF
apply work_composition β¨p,hpβ© hG p
intro a
exact (Experiment.all_worst (f a) weight).mono (fun b hb=>hb.trans (Nat.le_trans (Nat.le_add_left _ _) (hp a)))
lemma polynomial_composition {f : AβExperiment B} {g : BβExperiment C} {F : Realizer f} {G : Realizer g}
(hF : PolynomialTime F) (hG : PolynomialTime G) : PolynomialTime (composition F G) := work_then_polynomial hF hG
lemma polynomial_deterministic {f : AβB} {F : TreeTyped.Realizer f} (hF : TreeTyped.PolynomialTime F) :
PolynomialTime (deterministic F) := hF
end MatchingFPRAS.OnlineTree
end OAI
|