Sync from openai/math@faee2cf485a8 (part 7)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lean/OAI/Analysis/FourierLLogL/Assembly/Cast.lean+185-185
- lean/OAI/Analysis/FourierLLogL/Assembly/Chill.lean+179-179
- lean/OAI/Analysis/FourierLLogL/Assembly/Duration.lean+241-241
- lean/OAI/Analysis/FourierLLogL/Assembly/Endpoint.lean+62-62
- lean/OAI/Analysis/FourierLLogL/Assembly/Festival.lean+213-213
- lean/OAI/Analysis/FourierLLogL/Assembly/Gross.lean+225-225
- lean/OAI/Analysis/FourierLLogL/Assembly/Phase.lean+215-215
- lean/OAI/Analysis/FourierLLogL/Assembly/Rail.lean+190-190
- lean/OAI/Analysis/FourierLLogL/Assembly/Receipt.lean+182-182
- lean/OAI/Analysis/FourierLLogL/Assembly/Series.lean+273-273
- lean/OAI/Analysis/FourierLLogL/Assembly/Slab.lean+138-138
- lean/OAI/Analysis/FourierLLogL/Assembly/Tokens.lean+223-223
- lean/OAI/Analysis/FourierLLogL/Assembly/Verdict.lean+215-215
- lean/OAI/Analysis/FourierLLogL/Assembly/Weighted.lean+154-154
- lean/OAI/Analysis/FourierLLogL/Capture/Append.lean+180-180
- lean/OAI/Analysis/FourierLLogL/Capture/Book.lean+114-114
- lean/OAI/Analysis/FourierLLogL/Capture/Criterion.lean+206-206
- lean/OAI/Analysis/FourierLLogL/Capture/Curve.lean+190-190
- lean/OAI/Analysis/FourierLLogL/Capture/Dual.lean+157-157
- lean/OAI/Analysis/FourierLLogL/Capture/Flex.lean+167-167
- lean/OAI/Analysis/FourierLLogL/Capture/Mask.lean+196-196
- lean/OAI/Analysis/FourierLLogL/Capture/MaskKernel.lean+243-243
- lean/OAI/Analysis/FourierLLogL/Compress/Blocks.lean+165-165
- lean/OAI/Analysis/FourierLLogL/Compress/Context.lean+260-260
- lean/OAI/Analysis/FourierLLogL/Compress/Cost.lean+232-232
- lean/OAI/Analysis/FourierLLogL/Compress/Endpoint.lean+222-222
- lean/OAI/Analysis/FourierLLogL/Compress/Fraction.lean+170-170
- lean/OAI/Analysis/FourierLLogL/Compress/Freeze.lean+216-216
- lean/OAI/Analysis/FourierLLogL/Compress/Low.lean+274-274
- lean/OAI/Analysis/FourierLLogL/Compress/Observe.lean+222-222
- lean/OAI/Analysis/FourierLLogL/Compress/Params.lean+330-330
- lean/OAI/Analysis/FourierLLogL/Compress/Phase.lean+284-284
- lean/OAI/Analysis/FourierLLogL/Compress/Prefix.lean+169-169
- lean/OAI/Analysis/FourierLLogL/Compress/Projection.lean+179-179
- lean/OAI/Analysis/FourierLLogL/Compress/Rent.lean+171-171
- lean/OAI/Analysis/FourierLLogL/Compress/Schedule.lean+205-205
- lean/OAI/Analysis/FourierLLogL/Compress/Search.lean+363-363
- lean/OAI/Analysis/FourierLLogL/Compress/Select.lean+178-178
- lean/OAI/Analysis/FourierLLogL/Compress/Theorem.lean+95-95
- lean/OAI/Analysis/FourierLLogL/Compress/ThinChoice.lean+213-213
- lean/OAI/Analysis/FourierLLogL/Compress/Thinning.lean+207-207
- lean/OAI/Analysis/FourierLLogL/Compress/Variational.lean+230-230
- lean/OAI/Analysis/FourierLLogL/Dyadic/Circle.lean+192-192
- lean/OAI/Analysis/FourierLLogL/Dyadic/Discrete.lean+214-214
- lean/OAI/Analysis/FourierLLogL/Dyadic/Grid.lean+259-259
- lean/OAI/Analysis/FourierLLogL/Dyadic/Lift.lean+331-331
- lean/OAI/Analysis/FourierLLogL/Dyadic/Node.lean+232-232
- lean/OAI/Analysis/FourierLLogL/Dyadic/Snap.lean+163-163
- lean/OAI/Analysis/FourierLLogL/Dyadic/Span.lean+137-137
- lean/OAI/Analysis/FourierLLogL/Edges/Charge.lean+95-95
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185import OAI.Analysis.FourierLLogL.Assembly.Receipt/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef tailE (s : Scene M) (J : ℕ) (x u : Grid M) :=∑ n ∈ Finset.Ico s.here.lev J, ∑ k ∈ Finset.range (2^n),FinJump ⟨n,k⟩ (finMod s.wage u) xprivate lemma lone (s : Scene M) (p : Node) (hv : p.valid) (x u : Grid M) (h : x∈p.block M) :∑ k∈Finset.range (2^p.lev), FinJump ⟨p.lev,k⟩ (finMod s.wage u) x = FinJump p (finMod s.wage u) x := byrw [Finset.sum_eq_single p.ix]· intro b hb hhrw [FinJump, Gi_out _ (show pos x∉ Node.cells ⟨p.lev,b⟩ from byintro Hexact Set.disjoint_left.mp (cells_dis hh) H h),zero_smul]intro H; exact (H (Finset.mem_range.mpr hv)).elimlemma tail_move {s : Scene M} (x u : Grid M) (hh : s.here.valid)(hp : s.here.lev < J) (h : x∈s.here.block M) (b : Bool) :tailE s J x u=FinJump s.here (finMod s.wage u) x+tailE (s.smaller b) J x u := byunfold tailElet f (n) := ∑ k∈Finset.range (2^n),FinJump ⟨n,k⟩ (finMod s.wage u) xlet n := s.here.levhave he : Finset.Ico s.here.lev J=insert n (Finset.Ico (n+1) J) := byext i; simp only [Finset.mem_insert,Finset.mem_Ico,n]; omegarw [he,Finset.sum_insert (by simp),lone s s.here hh x u h]cases b <;> rfllemma tail_attempt {s : Scene M} (v : Update j M s.here) (x u : Grid M) (J : ℕ) :tailE s J x u=tailE (s.lose v) J x u + tailE (s.win v) J x u := bylet f := finMod s.wage u; let g := finMod (s.lose v).wage ulet w := finMod (s.win v).wage uhave H : f=g+w := byfunext iunfold f g w lose win finMod; simp only [Pi.add_apply]by_cases HH : v.take s.fund.mood iall_goals simp [HH]have HV (p : Node) :FinJump p (finMod s.wage u) x=FinJump p g x+FinJump p w x := byunfold FinJumphave Hx (x : Grid M) : finMod s.wage u x=g x+w x := congrFun H xsimp_rw [Hx,smul_add,avg_sum,Finset.sum_add_distrib,smul_add]unfold tailE; simp_rw [HV,Finset.sum_add_distrib]; rfllemma tail_fail (s : Scene M) (u x : Grid M) (h : Safe s j J f)(hp : finGood (cutoff j) J f x) (hh : x∈s.here.block M)(ht : ¬s.openHere j J f) :tailE s J x u=0 := byby_cases hb : s.here.lev < J· have hx := hp s.here h.within.1 hb hhhave he : s.mass=0 := le_antisymm (le_of_not_gt (fun hv => ht ⟨hb,hx,hv⟩)) h.mass_lowerhave H (i) (hf : i∈s.here.block M) : s.wage i=0 := byhave HE := mass_actor (s:=s) h.within h.positive irw [he,zero_mul] at HEexact (mul_eq_zero.mp HE.symm).resolve_left ((dice_positive h.within).2 hf).ne'unfold tailE; apply Finset.sum_eq_zero; intro n hnapply Finset.sum_eq_zero; intro k hklet p := Node.mk n kby_cases hm : x∈p.block M· have HI (y : Grid M) (hy : y∈p.block M) : finMod s.wage u y=0 := byunfold finMod; rw [H y]; simphave hf := coarse_const (Finset.mem_Ico.mp hn).1 (q:=p) (p:=s.here) (x:=pos x) (y:=pos y) hm hyexact hf.mp hhrw [FinJump,avg_sum]rw [Finset.sum_eq_zero (fun i hi => by rw [HI _ ((mem_group _ _).1 hi),smul_zero])]simp· rw [FinJump, Gi_out p hm,zero_smul]· unfold tailE; simp [Finset.Ico_eq_empty hb]lemma FinJump_align (s : Scene M) (hv : s.here.valid) (hm : s.here.lev < M)(he : 0 < s.norm) (u x : Grid M) :FinJump s.here (finMod s.wage u) x=(s.norm:ℂ)*proceeds x u (Thread.Beat.mk s s ((step s).bit x)) := bylet p := s.here; let f := finMod s.wage ulet g (y : Grid M) := p.Hi (pos y) • f yhave H (b : Bool) :(p.child b).avg g=((curl b:ℝ)*s.norm:ℝ)*scalar (s.smaller b) u := byrw [avg_cx (child_ok p hv hm b)]unfold Cx scalar; rw [Finset.mul_sum]refine Finset.sum_congr rfl fun i _ => ?_let q := p.child bby_cases hh : i∈q.block M· change (q.dice M i:ℂ)*g i=(((curl b*s.norm:ℝ):ℝ):ℂ)*((↑(wt q s.wage s.norm i):ℂ)*_)unfold g p wtrw [heav_bit _ _ _ hh,Complex.real_smul]have HR : (s.norm:ℂ) ≠ 0 := by exact_mod_cast he.ne'unfold f finModpush_cast; field_simphave hx : q.dice M i=0 := by rw [dice_apply (child_ok p hv hm b),ite_eq_right hh]have hi : wt (s.smaller b).here (s.smaller b).wage (s.smaller b).norm i=0 := byunfold wt; rw [show (s.smaller b).here=q from rfl,hx]; simprw [hx,hi]; simprw [FinJump, Complex.real_smul]have hi : p.avg g=(s.norm:ℂ)*gain s u := byrw [avg_split_complex]rw [show p.L=p.child false from rfl,show p.R=p.child true from rfl,H,H]unfold gain; simp only [curl,Bool.false_eq_true,↓reduceIte]; push_castringchange (p.Gi (pos x):ℂ)*p.avg g=_*((p.Gi (pos x):ℂ)*_)rw [hi]; ring/-- Payment from the already open plateau, without its children plateaus. -/def ordinary (u x : Grid M) (t : Play j M s) :=(s.norm:ℂ)*subtotal (proceeds x u) ((project t).stream x)def summons (u x : Grid M) {s : Scene M} (t : Play j M s) : ℂ := match t with| .rest _ => 0| .ticket _ t => ordinary u x t + summons u x t| .freeze _ t => summons u x t| .attempt _ _ l r => summons u x l+summons u x r| .jump s l r => if (step s).bit x then summons u x r else summons u x llemma ordinary_jump (s : Scene M) (l : Play j M (s.smaller false)) (r : Play j M (s.smaller true)) (u x : Grid M) :let b := (step s).bit xordinary u x (.jump s l r)=(s.norm:ℂ)*proceeds x u ⟨s,s,b⟩+if b=true then ordinary u x r else ordinary u x l := byintro bunfold ordinary bsimp only [project,stream,subtotal_cons]cases (step s).bit x <;>simp only [smaller,Bool.false_eq_true,↓reduceIte,mul_add]/-- common bit selection is correct for the shifted Haar step -/lemma stage_shift (s : Scene M) (t : Play j M s) (u x : Grid M)(h : t.Follows J f) (hp : x∈ s.here.block M)(hh : finGood (cutoff j) J f x) : tailE s J x u=ordinary u x t+summons u x t := byinduction t with| rest s =>rw [tail_fail s u x h.1 hh hp h.2]unfold ordinary; simp [project,stream,subtotal,summons]| ticket s t ih =>have HH := ih h.2.2.2.2 hpchange tailE s.reset _ _ _ = _rw [HH]simp [ordinary,project,stream,subtotal,summons]| freeze s t ih =>have H := ih h.2.2.2 hpchange tailE s.out _ _ _ = _rw [H]simp [ordinary,project,stream,subtotal,summons,out]| attempt s v l r il ir =>rw [tail_attempt v x u J, il h.2.2.2.2.1 hp, ir h.2.2.2.2.2 hp]rw [show ordinary u x (.attempt s v l r) = ordinary u x l byunfold ordinary; rw [project]cases project l <;> rfl]rw [summons]rw [show ordinary u x r=0 by unfold ordinary; rw [show (s.win v).norm=0 from rfl]; simp]; ring| jump s l r il ir =>obtain ⟨ha,hb,hc,hd,he⟩ := hlet b := (step s).bit xhave hM : s.here.lev < M := (Play.first hd).within.2have hs := share_small hbhave Hm := FinJump_align s ha.within.1 hM hs.1 u xhave HE := stream_child (less_self _) hprw [tail_move x u ha.within.1 hb.1.1 hp b,Hm]change x ∈ (s.smaller b).here.block M at HEunfold b at *rcases HA : (step s).bit x· rw [ordinary_jump s l r u x, summons,HA,ite_eq_right (by simp)]rw [HA] at HErw [il hd HE]; simp only [Bool.false_eq_true,↓reduceIte,add_assoc]· rw [ordinary_jump s l r u x, summons,HA,ite_eq_left rfl]rw [HA] at HErw [ir he HE]; simp only [↓reduceIte,add_assoc]end CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185import OAI.Analysis.FourierLLogL.Assembly.Receipt/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef tailE (s : Scene M) (J : ℕ) (x u : Grid M) :=∑ n ∈ Finset.Ico s.here.lev J, ∑ k ∈ Finset.range (2^n),FinJump ⟨n,k⟩ (finMod s.wage u) xprivate lemma lone (s : Scene M) (p : Node) (hv : p.valid) (x u : Grid M) (h : x∈p.block M) :∑ k∈Finset.range (2^p.lev), FinJump ⟨p.lev,k⟩ (finMod s.wage u) x = FinJump p (finMod s.wage u) x := byrw [Finset.sum_eq_single p.ix]· intro b hb hhrw [FinJump, Gi_out _ (show pos x∉ Node.cells ⟨p.lev,b⟩ from byintro Hexact Set.disjoint_left.mp (cells_dis hh) H h),zero_smul]intro H; exact (H (Finset.mem_range.mpr hv)).elimlemma tail_move {s : Scene M} (x u : Grid M) (hh : s.here.valid)(hp : s.here.lev < J) (h : x∈s.here.block M) (b : Bool) :tailE s J x u=FinJump s.here (finMod s.wage u) x+tailE (s.smaller b) J x u := byunfold tailElet f (n) := ∑ k∈Finset.range (2^n),FinJump ⟨n,k⟩ (finMod s.wage u) xlet n := s.here.levhave he : Finset.Ico s.here.lev J=insert n (Finset.Ico (n+1) J) := byext i; simp only [Finset.mem_insert,Finset.mem_Ico,n]; omegarw [he,Finset.sum_insert (by simp),lone s s.here hh x u h]cases b <;> rfllemma tail_attempt {s : Scene M} (v : Update j M s.here) (x u : Grid M) (J : ℕ) :tailE s J x u=tailE (s.lose v) J x u + tailE (s.win v) J x u := bylet f := finMod s.wage u; let g := finMod (s.lose v).wage ulet w := finMod (s.win v).wage uhave H : f=g+w := byfunext iunfold f g w lose win finMod; simp only [Pi.add_apply]by_cases HH : v.take s.fund.mood iall_goals simp [HH]have HV (p : Node) :FinJump p (finMod s.wage u) x=FinJump p g x+FinJump p w x := byunfold FinJumphave Hx (x : Grid M) : finMod s.wage u x=g x+w x := congrFun H xsimp_rw [Hx,smul_add,avg_sum,Finset.sum_add_distrib,smul_add]unfold tailE; simp_rw [HV,Finset.sum_add_distrib]; rfllemma tail_fail (s : Scene M) (u x : Grid M) (h : Safe s j J f)(hp : finGood (cutoff j) J f x) (hh : x∈s.here.block M)(ht : ¬s.openHere j J f) :tailE s J x u=0 := byby_cases hb : s.here.lev < J· have hx := hp s.here h.within.1 hb hhhave he : s.mass=0 := le_antisymm (le_of_not_gt (fun hv => ht ⟨hb,hx,hv⟩)) h.mass_lowerhave H (i) (hf : i∈s.here.block M) : s.wage i=0 := byhave HE := mass_actor (s:=s) h.within h.positive irw [he,zero_mul] at HEexact (mul_eq_zero.mp HE.symm).resolve_left ((dice_positive h.within).2 hf).ne'unfold tailE; apply Finset.sum_eq_zero; intro n hnapply Finset.sum_eq_zero; intro k hklet p := Node.mk n kby_cases hm : x∈p.block M· have HI (y : Grid M) (hy : y∈p.block M) : finMod s.wage u y=0 := byunfold finMod; rw [H y]; simphave hf := coarse_const (Finset.mem_Ico.mp hn).1 (q:=p) (p:=s.here) (x:=pos x) (y:=pos y) hm hyexact hf.mp hhrw [FinJump,avg_sum]rw [Finset.sum_eq_zero (fun i hi => by rw [HI _ ((mem_group _ _).1 hi),smul_zero])]simp· rw [FinJump, Gi_out p hm,zero_smul]· unfold tailE; simp [Finset.Ico_eq_empty hb]lemma FinJump_align (s : Scene M) (hv : s.here.valid) (hm : s.here.lev < M)(he : 0 < s.norm) (u x : Grid M) :FinJump s.here (finMod s.wage u) x=(s.norm:ℂ)*proceeds x u (Thread.Beat.mk s s ((step s).bit x)) := bylet p := s.here; let f := finMod s.wage ulet g (y : Grid M) := p.Hi (pos y) • f yhave H (b : Bool) :(p.child b).avg g=((curl b:ℝ)*s.norm:ℝ)*scalar (s.smaller b) u := byrw [avg_cx (child_ok p hv hm b)]unfold Cx scalar; rw [Finset.mul_sum]refine Finset.sum_congr rfl fun i _ => ?_let q := p.child bby_cases hh : i∈q.block M· change (q.dice M i:ℂ)*g i=(((curl b*s.norm:ℝ):ℝ):ℂ)*((↑(wt q s.wage s.norm i):ℂ)*_)unfold g p wtrw [heav_bit _ _ _ hh,Complex.real_smul]have HR : (s.norm:ℂ) ≠ 0 := by exact_mod_cast he.ne'unfold f finModpush_cast; field_simphave hx : q.dice M i=0 := by rw [dice_apply (child_ok p hv hm b),ite_eq_right hh]have hi : wt (s.smaller b).here (s.smaller b).wage (s.smaller b).norm i=0 := byunfold wt; rw [show (s.smaller b).here=q from rfl,hx]; simprw [hx,hi]; simprw [FinJump, Complex.real_smul]have hi : p.avg g=(s.norm:ℂ)*gain s u := byrw [avg_split_complex]rw [show p.L=p.child false from rfl,show p.R=p.child true from rfl,H,H]unfold gain; simp only [curl,Bool.false_eq_true,↓reduceIte]; push_castringchange (p.Gi (pos x):ℂ)*p.avg g=_*((p.Gi (pos x):ℂ)*_)rw [hi]; ring/-- Payment from the already open plateau, without its children plateaus. -/def ordinary (u x : Grid M) (t : Play j M s) :=(s.norm:ℂ)*subtotal (proceeds x u) ((project t).stream x)def summons (u x : Grid M) {s : Scene M} (t : Play j M s) : ℂ := match t with| .rest _ => 0| .ticket _ t => ordinary u x t + summons u x t| .freeze _ t => summons u x t| .attempt _ _ l r => summons u x l+summons u x r| .jump s l r => if (step s).bit x then summons u x r else summons u x llemma ordinary_jump (s : Scene M) (l : Play j M (s.smaller false)) (r : Play j M (s.smaller true)) (u x : Grid M) :let b := (step s).bit xordinary u x (.jump s l r)=(s.norm:ℂ)*proceeds x u ⟨s,s,b⟩+if b=true then ordinary u x r else ordinary u x l := byintro bunfold ordinary bsimp only [project,stream,subtotal_cons]cases (step s).bit x <;>simp only [smaller,Bool.false_eq_true,↓reduceIte,mul_add]/-- common bit selection is correct for the shifted Haar step -/lemma stage_shift (s : Scene M) (t : Play j M s) (u x : Grid M)(h : t.Follows J f) (hp : x∈ s.here.block M)(hh : finGood (cutoff j) J f x) : tailE s J x u=ordinary u x t+summons u x t := byinduction t with| rest s =>rw [tail_fail s u x h.1 hh hp h.2]unfold ordinary; simp [project,stream,subtotal,summons]| ticket s t ih =>have HH := ih h.2.2.2.2 hpchange tailE s.reset _ _ _ = _rw [HH]simp [ordinary,project,stream,subtotal,summons]| freeze s t ih =>have H := ih h.2.2.2 hpchange tailE s.out _ _ _ = _rw [H]simp [ordinary,project,stream,subtotal,summons,out]| attempt s v l r il ir =>rw [tail_attempt v x u J, il h.2.2.2.2.1 hp, ir h.2.2.2.2.2 hp]rw [show ordinary u x (.attempt s v l r) = ordinary u x l byunfold ordinary; rw [project]cases project l <;> rfl]rw [summons]rw [show ordinary u x r=0 by unfold ordinary; rw [show (s.win v).norm=0 from rfl]; simp]; ring| jump s l r il ir =>obtain ⟨ha,hb,hc,hd,he⟩ := hlet b := (step s).bit xhave hM : s.here.lev < M := (Play.first hd).within.2have hs := share_small hbhave Hm := FinJump_align s ha.within.1 hM hs.1 u xhave HE := stream_child (less_self _) hprw [tail_move x u ha.within.1 hb.1.1 hp b,Hm]change x ∈ (s.smaller b).here.block M at HEunfold b at *rcases HA : (step s).bit x· rw [ordinary_jump s l r u x, summons,HA,ite_eq_right (by simp)]rw [HA] at HErw [il hd HE]; simp only [Bool.false_eq_true,↓reduceIte,add_assoc]· rw [ordinary_jump s l r u x, summons,HA,ite_eq_left rfl]rw [HA] at HErw [ir he HE]; simp only [↓reduceIte,add_assoc]end CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179import OAI.Analysis.FourierLLogL.Assembly.Gross/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef drought (m : ℝ) := max (-log m) 0lemma drought_pos (m : ℝ) : 0 ≤ drought m := le_max_right _ _def chargeStatic (j : ℕ) (m : ℝ) :=10^150*(Thermal.H j +1+drought m)*(height j+2+drought m)lemma charge_pos (j : ℕ) (m : ℝ) : 0 ≤ chargeStatic j m := byunfold chargeStatichave := H_pos jhave := d_pos jhave := drought_pos mpositivitydef coldLump (v : Journal j M) := if v.froze then chargeStatic j v.done.mass else 0def coldFee {s : Scene M} (t : Road j M s) :=expHike t (fun l _ => coldLump l)lemma chill_descendants :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ,∀ s : Scene M, ∀ t : Play j M s, Play.Follows J f t →s.live=false → s.norm=0 → 0 < s.mass →netGross t ≤ chargeStatic j s.mass := byfilter_upwards [cutoff_log] with j h M J f s t hF he hx hmlet x := s.masslet A := height j+2+drought xlet v := Thermal.H j; let U := 20000*vhave HV : 1 ≤ v := H_ge jhave hA : 0 ≤ A := by unfold A; have := d_pos j; have := drought_pos x; positivityhave HE (q : Scene M) (hh : Safe q j J f) (h : 0 < q.mass) :log q.mass ≤ U :=le_trans (log_le_log h hh.budget) (by assumption)let K : ℝ := 10^140*Ahave hK : 0 ≤ K := by unfold K; positivityhave HT (s : Scene M) (hh : x ≤ s.mass) (ht : s.live=false) :gateTax s.reset j ≤ K := byunfold gateTax amount; simp only [reset,ht, Bool.false_eq_true, ↓reduceIte]have hi : max (-log s.mass) 0 ≤ drought x := max_le_max_right 0 (neg_le_neg (log_le_log hm hh))unfold K A; linarithhave HI {q : Scene M} (t : Play j M q) (h : Play.Follows J f t) (he : q.live=false)(hE : x ≤ q.norm) (hL : log q.norm ≤ U) :netGross t ≤ 2*K*(U-log q.norm) := byinduction t with| rest q =>rw [netGross,trace,flat_finish]; nlinarith| ticket q z ih =>obtain ⟨ha,hb,hc,hd,hf⟩ := hhave he₁ := hb.2.2have he₂ : 0 < q.norm := hm.trans_le hEhave hv : x ≤ q.mass := by unfold enter at hd; linarithhave HE' := ih hf he hv (HE q ha he₁)unfold netGrossrw [trace,flat_push]change gateTax _ j+netGross z ≤ _have he₃ : log q.norm+1/2 ≤ log q.mass := byhave HH := log_le_log (show 0 < 2*q.norm by positivity) (le_of_lt (show 2*q.norm < q.mass from hd))rw [log_mul (by norm_num) he₂.ne'] at HHlinarith [Real.log_two_gt_d9]change netGross z ≤ 2*K*(U-log q.mass) at HE'linarith [mul_le_mul_of_nonneg_left he₃ hK,HT q hv he]| jump q l r il ir =>have HG := traced _ true hrw [netGross,trace,flat_fork _ _ HG]obtain ⟨ha,hb,hc,hd,hf⟩ := hrw [← Ex_const (Turn.fork (Turn.move (j:=j) (s:=q))).probs (2*K*(U-log q.norm))]apply Ex_mono; intro bcases b· change normStamp q j+netGross l ≤ _rw [normStamp,ite_eq_right (by rw [he]; simp),zero_add]exact il hd he hE hLchange normStamp q j+netGross r ≤ _rw [normStamp,ite_eq_right (by rw [he]; simp),zero_add]exact ir hf he hE hL| attempt q u l r =>have HH := h.2.2.1rw [he] at HH; cases HH| freeze q w ih =>have HH := h.2.2.1.1rw [he] at HH; cases HHcases t with| rest s =>rw [netGross,trace,flat_finish]; exact charge_pos _ _| freeze s w =>have HH := hF.2.2.1.1rw [he] at HH; cases HH| attempt s u l r =>have HH := hF.2.2.1rw [he] at HH; cases HH| jump s l r =>have HH := share_small hF.2.1rw [hx] at HHlinarith [HH.1]| ticket s w =>rw [netGross,trace,flat_push]have HC := HI w hF.2.2.2.2 he (le_refl _) (HE s hF.1 hm)change netGross w ≤ 2*K*(U-log x) at HCchange gateTax s.reset j+netGross w ≤ 10^150*(v+1+drought x)*Ahave hz := drought_pos xhave hx' : -log x ≤ drought x := le_max_left _ _apply le_trans (add_le_add (HT s le_rfl he) HC)unfold K U; nlinarith/-- Every coast including virtual ends of the true live processing bills only once for staticdescendants. -/lemma frostCompare :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ, ∀ s : Scene M,∀ t : Play j M s, Play.Follows J f t → s.live=true →netGross t ≤ (trace false t).flatFee billOf + coldFee (trace false t) := byfilter_upwards [chill_descendants] with j h M J f s t hh heinduction t with| rest s =>unfold coldFee netGross; simp only [trace,flat_finish,zero_add]simp [expHike,hike,Ex_const,coldLump]| freeze s t ih =>have HX := hh.2.2.2have H := h M J f s.out t HX rfl rfl hh.2.1.2.2unfold netGross coldFeerw [trace,ite_eq_left rfl, flat_push]simp only [trace,Bool.false_eq_true,ite_false,flat_finish,zero_add]simp only [expHike,hike,coldLump, ↓reduceIte,Ex_const]change 0+netGross t ≤ _rw [zero_add]; exact H| ticket s t ih =>have H := ih hh.2.2.2.2 heunfold netGross coldFeerw [trace,flat_push]simp only [trace,flat_push]rw [Ex_hike_push]apply le_trans (add_le_add_right H _)rw [← add_assoc]; exact le_rfl| jump s l r il ir =>have HF := traced _ true hhhave HG := traced _ false hhunfold netGross coldFeerw [trace,flat_fork _ _ HF]simp only [trace,flat_fork _ _ HG]rw [Ex_hike_fork HG, ← Ex_add]apply Ex_mono; intro bcases b· apply le_trans (add_le_add_right (il hh.2.2.2.1 he) _)rw [←add_assoc]; exact le_rfl· apply le_trans (add_le_add_right (ir hh.2.2.2.2 he) _)rw [←add_assoc]; exact le_rfl| attempt s u l r il ir =>have HF := traced _ true hhhave HG := traced _ false hhunfold netGross coldFee; rw [trace,flat_fork _ _ HF]simp only [trace,flat_fork _ _ HG]rw [Ex_hike_fork HG, ← Ex_add]apply Ex_mono; intro bcases b· apply le_trans (add_le_add_right (il hh.2.2.2.2.1 he) _)rw [← add_assoc]; exact le_rfl· apply le_trans (add_le_add_right (ir hh.2.2.2.2.2 he) _)rw [← add_assoc]; exact le_rflend CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179import OAI.Analysis.FourierLLogL.Assembly.Gross/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef drought (m : ℝ) := max (-log m) 0lemma drought_pos (m : ℝ) : 0 ≤ drought m := le_max_right _ _def chargeStatic (j : ℕ) (m : ℝ) :=10^150*(Thermal.H j +1+drought m)*(height j+2+drought m)lemma charge_pos (j : ℕ) (m : ℝ) : 0 ≤ chargeStatic j m := byunfold chargeStatichave := H_pos jhave := d_pos jhave := drought_pos mpositivitydef coldLump (v : Journal j M) := if v.froze then chargeStatic j v.done.mass else 0def coldFee {s : Scene M} (t : Road j M s) :=expHike t (fun l _ => coldLump l)lemma chill_descendants :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ,∀ s : Scene M, ∀ t : Play j M s, Play.Follows J f t →s.live=false → s.norm=0 → 0 < s.mass →netGross t ≤ chargeStatic j s.mass := byfilter_upwards [cutoff_log] with j h M J f s t hF he hx hmlet x := s.masslet A := height j+2+drought xlet v := Thermal.H j; let U := 20000*vhave HV : 1 ≤ v := H_ge jhave hA : 0 ≤ A := by unfold A; have := d_pos j; have := drought_pos x; positivityhave HE (q : Scene M) (hh : Safe q j J f) (h : 0 < q.mass) :log q.mass ≤ U :=le_trans (log_le_log h hh.budget) (by assumption)let K : ℝ := 10^140*Ahave hK : 0 ≤ K := by unfold K; positivityhave HT (s : Scene M) (hh : x ≤ s.mass) (ht : s.live=false) :gateTax s.reset j ≤ K := byunfold gateTax amount; simp only [reset,ht, Bool.false_eq_true, ↓reduceIte]have hi : max (-log s.mass) 0 ≤ drought x := max_le_max_right 0 (neg_le_neg (log_le_log hm hh))unfold K A; linarithhave HI {q : Scene M} (t : Play j M q) (h : Play.Follows J f t) (he : q.live=false)(hE : x ≤ q.norm) (hL : log q.norm ≤ U) :netGross t ≤ 2*K*(U-log q.norm) := byinduction t with| rest q =>rw [netGross,trace,flat_finish]; nlinarith| ticket q z ih =>obtain ⟨ha,hb,hc,hd,hf⟩ := hhave he₁ := hb.2.2have he₂ : 0 < q.norm := hm.trans_le hEhave hv : x ≤ q.mass := by unfold enter at hd; linarithhave HE' := ih hf he hv (HE q ha he₁)unfold netGrossrw [trace,flat_push]change gateTax _ j+netGross z ≤ _have he₃ : log q.norm+1/2 ≤ log q.mass := byhave HH := log_le_log (show 0 < 2*q.norm by positivity) (le_of_lt (show 2*q.norm < q.mass from hd))rw [log_mul (by norm_num) he₂.ne'] at HHlinarith [Real.log_two_gt_d9]change netGross z ≤ 2*K*(U-log q.mass) at HE'linarith [mul_le_mul_of_nonneg_left he₃ hK,HT q hv he]| jump q l r il ir =>have HG := traced _ true hrw [netGross,trace,flat_fork _ _ HG]obtain ⟨ha,hb,hc,hd,hf⟩ := hrw [← Ex_const (Turn.fork (Turn.move (j:=j) (s:=q))).probs (2*K*(U-log q.norm))]apply Ex_mono; intro bcases b· change normStamp q j+netGross l ≤ _rw [normStamp,ite_eq_right (by rw [he]; simp),zero_add]exact il hd he hE hLchange normStamp q j+netGross r ≤ _rw [normStamp,ite_eq_right (by rw [he]; simp),zero_add]exact ir hf he hE hL| attempt q u l r =>have HH := h.2.2.1rw [he] at HH; cases HH| freeze q w ih =>have HH := h.2.2.1.1rw [he] at HH; cases HHcases t with| rest s =>rw [netGross,trace,flat_finish]; exact charge_pos _ _| freeze s w =>have HH := hF.2.2.1.1rw [he] at HH; cases HH| attempt s u l r =>have HH := hF.2.2.1rw [he] at HH; cases HH| jump s l r =>have HH := share_small hF.2.1rw [hx] at HHlinarith [HH.1]| ticket s w =>rw [netGross,trace,flat_push]have HC := HI w hF.2.2.2.2 he (le_refl _) (HE s hF.1 hm)change netGross w ≤ 2*K*(U-log x) at HCchange gateTax s.reset j+netGross w ≤ 10^150*(v+1+drought x)*Ahave hz := drought_pos xhave hx' : -log x ≤ drought x := le_max_left _ _apply le_trans (add_le_add (HT s le_rfl he) HC)unfold K U; nlinarith/-- Every coast including virtual ends of the true live processing bills only once for staticdescendants. -/lemma frostCompare :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ, ∀ s : Scene M,∀ t : Play j M s, Play.Follows J f t → s.live=true →netGross t ≤ (trace false t).flatFee billOf + coldFee (trace false t) := byfilter_upwards [chill_descendants] with j h M J f s t hh heinduction t with| rest s =>unfold coldFee netGross; simp only [trace,flat_finish,zero_add]simp [expHike,hike,Ex_const,coldLump]| freeze s t ih =>have HX := hh.2.2.2have H := h M J f s.out t HX rfl rfl hh.2.1.2.2unfold netGross coldFeerw [trace,ite_eq_left rfl, flat_push]simp only [trace,Bool.false_eq_true,ite_false,flat_finish,zero_add]simp only [expHike,hike,coldLump, ↓reduceIte,Ex_const]change 0+netGross t ≤ _rw [zero_add]; exact H| ticket s t ih =>have H := ih hh.2.2.2.2 heunfold netGross coldFeerw [trace,flat_push]simp only [trace,flat_push]rw [Ex_hike_push]apply le_trans (add_le_add_right H _)rw [← add_assoc]; exact le_rfl| jump s l r il ir =>have HF := traced _ true hhhave HG := traced _ false hhunfold netGross coldFeerw [trace,flat_fork _ _ HF]simp only [trace,flat_fork _ _ HG]rw [Ex_hike_fork HG, ← Ex_add]apply Ex_mono; intro bcases b· apply le_trans (add_le_add_right (il hh.2.2.2.1 he) _)rw [←add_assoc]; exact le_rfl· apply le_trans (add_le_add_right (ir hh.2.2.2.2 he) _)rw [←add_assoc]; exact le_rfl| attempt s u l r il ir =>have HF := traced _ true hhhave HG := traced _ false hhunfold netGross coldFee; rw [trace,flat_fork _ _ HF]simp only [trace,flat_fork _ _ HG]rw [Ex_hike_fork HG, ← Ex_add]apply Ex_mono; intro bcases b· apply le_trans (add_le_add_right (il hh.2.2.2.2.1 he) _)rw [← add_assoc]; exact le_rfl· apply le_trans (add_le_add_right (ir hh.2.2.2.2.2 he) _)rw [← add_assoc]; exact le_rflend CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241import OAI.Analysis.FourierLLogL.Assembly.Slab/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Plot Run Streak Beamdef tagM (i : ℕ) : Grade := ⟨true,i⟩def tagL (i : ℕ) : Grade := ⟨false,i⟩def depthRate (i : ℕ) := √(side i)def mainRatio (i : ℕ) (j : ℕ) (L : Path M) :=let g := tagM i(1+fullKills L+ (rose g 0).flagged L) / depthRate i +depthRate i*timex g j Ldef mainSticker (i : ℕ) (j : ℕ) (L : Path M) :=mainRatio i j L+(billWait (tagM (i-1)) j L:ℝ)def scalarSticker (i : ℕ) (j : ℕ) (L : Path M) :=let g := tagL idepthRate i*(1+fullKills L+timex g j L)lemma rate_easy (i) : 0 < depthRate i ∧ depthRate i ≤ 1 ∧ (depthRate i)^2=side i :=thick_rate (M:=0) (rose (tagM i) 0)lemma mainRatio_one (i j : ℕ) {L : Path M} {x : Grid M} {s : Scene M}(h : Trip x s L) : 1 ≤ mainRatio i j L := bylet g := tagM i; let p : Streak M := rose g 0have hv := trip_K h; have ht := flagged_pos p hhave hi := (timex_scores g j L).1let a := depthRate i; have hx : 0 < a ∧ a ≤ 1 := ⟨(rate_easy _).1,(rate_easy i).2.1⟩change 1 ≤ (1+fullKills L+p.flagged L)/a+a*_exact le_trans ((one_le_div hx.1).mpr (by linarith))(le_add_of_nonneg_right (mul_nonneg hx.1.le hi))lemma mainSticker_pos (i j : ℕ) {L : Path M} {x : Grid M} {s : Scene M}(h : Trip x s L) : 0 ≤ mainSticker i j L :=add_nonneg (le_trans (by norm_num) (mainRatio_one i j h)) (by positivity)lemma scalarSticker_pos (i j : ℕ) {L : Path M} {x : Grid M} {s : Scene M}(h : Trip x s L) : 0 ≤ scalarSticker i j L :=mul_nonneg (rate_easy i).1.le(add_nonneg (add_nonneg (by norm_num) (trip_K h)) (timex_scores (tagL i) j L).1)/-- Bounding a suffix without bigger main activations. -/lemma ride :∀ᶠ j : ℕ in atTop,∀ M J i : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ, ∀ l r m : Path M,∀ (b : Beat M) (x u : Grid M),let g := tagM ilet D := b::rlet L := l++(D++m)let p := heroPlot g LCast j J f s L → Trip x s L → entitled g s j →ringing u p j l b →(0 < i → stall u (tagM (i-1)) j L (l++D)) →‖subtotal (proceeds x u) D‖ ≤ 10^20*(fullFax D+mainSticker i j L) := byfilter_upwards [live_rec,channel_inner,near_size] with j h₁ h₂ h₃M J i s f l r m b x u g D L p hh he hg hp hflet g' := tagM (i-1)let n := billWait g' j Lobtain ⟨z,hz⟩ := bound_stage (u:=u) L hh g'obtain ⟨v,hA,l₀,l₁,hL,hT⟩ := h₁ M J s f u g l (r++m) b hh hg hplet t := timex g j Llet S := rose g vhave HT : 2*log (sumbling S none (l₁++(b::(r++m)))) ≤ t := byapply le_trans _ hTunfold S g Troupe.rose Troupe.tagM recitalsimpexact le_rflhave hI : i ≤ mainIx j := (hg rfl).1have H : ∃ k, delta (dye b.post) k ≤ sepRad j ∧ rad (u-v-k) ≤ 2*spotLimit b.post j i true := bychange aligned p b.post j u v at hAunfold aligned at hArw [ite_eq_left (show p.main=true from rfl)] at hA; exact hAobtain ⟨k,hK,hD⟩ := Hlet a := depthRate iobtain ⟨_,q,hq⟩ := trip_cut (show Trip x s (l++(D++m)) from he)obtain ⟨hX,_,_⟩ := trip_cut hqhave hY : b.post.here=q.here := hX.2.1.lower.here.trans (congrArg Scene.here hX.1)have hy : dye b.post=dye q := (trip_attend hX b List.mem_cons_self).2.2.2.2have HV (c : Beat M) (hc : c∈D) (hA : ¬betweenS z n c) :innerV S c.post := byhave hr := trip_attend hX c hcrefine h₂ i hI M b.post c.post (by rw [hY]; exact hr.2.2.2.1)(hr.2.2.2.2.trans hy.symm) hr.1.climb u v k hK hD ?_intro hi hxhave HX := hf hiexact hA (hz (l++D) m (by unfold L; rw [List.append_assoc]) HX c (by simp [hc]) hx)let P := proceeds x uhave HA : 1 ≤ mainRatio i j L := mainRatio_one i j hehave hc (v' w q' : Path M) (hiD : D=v'++(w++q')) (hiA : ∀ b∈w, ¬betweenS z n b) :‖subtotal P w‖ ≤ 10^16*(fullFax w+mainRatio i j L) := byhave hp₁ : Trip x q (v'++(w++q')) := hiD ▸ hXhave hp₂ : L=l₀++(((l₁++v')++(w++(q'++m)))) := byunfold L; rw [hL,hiD]; simp only [List.append_assoc]have hp₃ : l₁++(b::(r++m))=(l₁++v')++(w++(q'++m)) := bychange l₁++(D++m)=_rw [hiD]; simp only [List.append_assoc]let K := (l₁++v')++(w++(q'++m))obtain ⟨hU,c₀,hc₀⟩ := trip_cut (show Trip x s (l₀++K) from hp₂ ▸ he)have hi₁ := possible S (l₁++v') w (q'++m) hc₀(fun b hb => HV b (by rw [hiD]; simp [hb]) (hiA b hb)) t (hp₃ ▸ HT)have hi₂ : yieldW (subtotal (duties x v) w) ≤ 10^15*(fullFax w + mainRatio i j L) := byapply hi₁.trans; unfold mainRatiochange 10^15*(fullFax w+(1+fullKills K+flagged S K)/a+a*t) ≤10^15*(fullFax w+((1+fullKills L+flagged S L)/a+a*t))have ht₁ : fullKills K ≤ fullKills L := byrw [hp₂,show fullKills (l₀++K)=fullKills l₀+fullKills K from subtotal_app killed _ _]exact le_add_of_nonneg_left (trip_K hU)have ht₂ : flagged S K ≤ flagged S L := byrw [hp₂,show flagged S (l₀++K)=flagged S l₀+flagged S K from subtotal_app _ _ _]exact le_add_of_nonneg_left (flagged_pos S hU)have ha : 0 < a := (rate_easy i).1have HE : (1+fullKills K+flagged S K)/a ≤ (1+fullKills L+flagged S L)/a :=div_le_div_of_nonneg_right (by linarith) ha.lelinarithhave hi₃ := h₃ i hIhave hga : 64*q.here.len*rad (u-v-k) ≤ 4 := byhave HE : b.post.here.len*rad (u-v-k) ≤ 2*sig j :=halo_limit b.post j i true _ (below_refl _) hDrw [←hY]; nlinarith [hi₃.2, side_le i, side_pos i]have HB := below_decode u v k x (dye b.post) v' w q' hp₁ hy (hK.trans (hi₃.1.trans (side_le i)))apply HB.transobtain ⟨_,C,Hc⟩ := trip_cut hp₁linarith [trip_fax (trip_cut Hc).1]obtain ⟨w,v,q,hD',hw,hp,hq⟩ := slab_on _ _ (matrix_trip D hX) z nlet K := mainRatio i j Lhave Heq : mainSticker i j L=K+(n:ℝ) := rflhave HW : D=w++(v++q) := by rw [hD',List.append_assoc]have HA₁ := hc [] w (v++q) (by simpa using HW) hwhave HA₂ := hc (w++v) q [] (by simpa using hD') hpobtain ⟨hw',q₀,Hh⟩ := trip_cut (show Trip x _ (w++(v++q)) from HW ▸ hX)obtain ⟨hv',q₁,hq₁⟩ := trip_cut Hhrw [Heq,hD',subtotal_app,subtotal_app]change ‖subtotal P w + subtotal P v + subtotal P q‖ ≤ _apply (norm_add_le _ _).transhave he' : (v.length:ℝ) ≤ n := by exact_mod_cast hqhave HE := straight_fee u v hv'change ‖subtotal P v‖ ≤ _ at HEchange 1 ≤ K at HAchange _ ≤ 10^16* (fullFax w+K) at HA₁change _ ≤ 10^16*(fullFax q+K) at HA₂have HE : fullFax (w++v++q)=fullFax w+fullFax v+fullFax q := byrw [fullFax,subtotal_app,subtotal_app]; rflrw [HE]linarith [norm_add_le (subtotal P w) (subtotal P v),trip_fax hw',trip_fax hv',trip_fax hq₁]/-- Scalar suffix exact part with mask specified by chosen representative. -/def guardedV (i : ℕ) (v : Grid M) (b : Beat M) := guarded v (side i) b.postdef ampU (s : Scene M) (u : Grid M) :=max ‖scalar (s.smaller false) u‖ ‖scalar (s.smaller true) u‖lemma mask_estimate :∀ᶠ j : ℕ in atTop, ∀ M J i : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ,∀ l r m : Path M, ∀ b : Beat M, ∀ x u : Grid M,let g := tagL ilet D := b::rlet L := l++(D++m)let p := heroPlot g LCast j J f s L → Trip x s L → ringing u p j l b →∃ v : Grid M, let μ := guardedV i v‖subtotal (aired μ x u) D‖ ≤ 20000*scalarSticker i j L ∧∀ z∈D, ¬μ z → 4*side i < ampU z.post u := byfilter_upwards [live_rec] with j hj M J i s f l r m b x u g D L p h ht hplet y := side ihave Hg : entitled g s j := fun H => False.elim (Bool.noConfusion H)obtain ⟨v,hA,l₀,l₁,hL,hT⟩ := hj M J s f u g l (r++m) b h Hg hphave HK : rad (u-v) ≤ 2*spotLimit b.post j i false := bychange aligned p b.post j u v at hAunfold aligned at hA; rw [ite_eq_right (show p.main ≠ true from Bool.false_ne_true)] at hA; exact hAobtain ⟨_,q,hq⟩ := trip_cut (show Trip x s (l++(D++m)) from ht)have HX := (trip_cut hq).1have HE : b.post.here=q.here := HX.2.1.lower.here.trans (congrArg Scene.here HX.1)have hb : b.post.here.len*rad (u-v) ≤ 2*(y^4/65536) := halo_limit _ j i false _ (below_refl _) HKlet a := depthRate ihave ha : 0 < a ∧ a ≤ 1 ∧ a^2=y := rate_easy ihave hy : 0 < y := side_pos ihave hf : y^4 ≤ y := by simpa using pow_le_pow_of_le_one hy.le (side_le i) (by omega : 1≤4)refine ⟨v,?_⟩intro μlet t := timex g j Lhave hp₂ : L=l₀++(l₁++(D++m)) := by unfold L; rw [hL,List.append_assoc]constructor· have ht₀ : 2*log (coldScore v y (l₁++D++m)) ≤ t := byapply le_trans _ hTsimp only [g,tagL,recital,Bool.false_eq_true,↓reduceIte,List.append_assoc]exact le_rflobtain ⟨hU,c₀,hc₀⟩ := trip_cut (show Trip x s (l₀++(l₁++(D++m))) from hp₂ ▸ ht)have He : Trip x c₀ (l₁++D++m) := by rwa [List.append_assoc]have HR : aired μ x v = frosty x v y := byfunext b; unfold aired frosty prizesplit_ifs with h1 h2 h2· rfl· exact (h2 h1).elim· exact (h1 h2).elimsimphave Hx := rail_fee u v μ [] D [] (s:=q) (by simpa using HX)have HV := frosty_portion v hy (side_le i) l₁ D m He t ht₀have H := norm_add_le (subtotal (aired μ x u) D-chi (u-v) x*subtotal (aired μ x v) D)(chi (u-v) x*subtotal (aired μ x v) D)rw [sub_add_cancel,norm_mul,norm_chi,one_mul,HR] at Hhave hE' : fullKills (l₁++D++m) ≤ fullKills L := byrw [hp₂,List.append_assoc,show fullKills (l₀++(l₁++(D++m)))=fullKills l₀+fullKills (l₁++(D++m)) from subtotal_app killed _ _]exact le_add_of_nonneg_left (trip_K hU)have hV : 0 ≤ fullKills L := trip_K hthave hY : 0 ≤ t := (timex_scores g j _).1apply H.transrw [HR,← HE] at Hxchange _ ≤ 12000*a*_ at HVchange _ ≤ 20000*(a*(1+fullKills L+t))nlinarith· intro z hz hμobtain ⟨hz₁,hz₂,hz₃,hz₄,hz₅⟩ := trip_attend HX z hzrw [←HE] at hz₄change ¬∀ k, ‖scalar (z.post.smaller k) v‖ ≤ 10*y at hμpush Not at hμobtain ⟨c,hc⟩ := hμlet d := z.post.smaller chave H1 := hz₁.climb.child chave H2 := scalar_compare d u v H1.ready H1.pos.le 4 H1.lifthave H3 : d.here.len ≤ b.post.here.len :=node_compress (below_trans (child_below _ _) hz₄)have HH' : ‖scalar d u‖ ≤ ampU z.post u := by unfold d ampU; cases c; exact le_max_left _ _; exact le_max_right _ _change _ < ‖scalar d v‖ at hcchange 4*y < _nlinarith [(abs_le.mp H2).1,rad_nonneg (u-v)]end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241import OAI.Analysis.FourierLLogL.Assembly.Slab/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Plot Run Streak Beamdef tagM (i : ℕ) : Grade := ⟨true,i⟩def tagL (i : ℕ) : Grade := ⟨false,i⟩def depthRate (i : ℕ) := √(side i)def mainRatio (i : ℕ) (j : ℕ) (L : Path M) :=let g := tagM i(1+fullKills L+ (rose g 0).flagged L) / depthRate i +depthRate i*timex g j Ldef mainSticker (i : ℕ) (j : ℕ) (L : Path M) :=mainRatio i j L+(billWait (tagM (i-1)) j L:ℝ)def scalarSticker (i : ℕ) (j : ℕ) (L : Path M) :=let g := tagL idepthRate i*(1+fullKills L+timex g j L)lemma rate_easy (i) : 0 < depthRate i ∧ depthRate i ≤ 1 ∧ (depthRate i)^2=side i :=thick_rate (M:=0) (rose (tagM i) 0)lemma mainRatio_one (i j : ℕ) {L : Path M} {x : Grid M} {s : Scene M}(h : Trip x s L) : 1 ≤ mainRatio i j L := bylet g := tagM i; let p : Streak M := rose g 0have hv := trip_K h; have ht := flagged_pos p hhave hi := (timex_scores g j L).1let a := depthRate i; have hx : 0 < a ∧ a ≤ 1 := ⟨(rate_easy _).1,(rate_easy i).2.1⟩change 1 ≤ (1+fullKills L+p.flagged L)/a+a*_exact le_trans ((one_le_div hx.1).mpr (by linarith))(le_add_of_nonneg_right (mul_nonneg hx.1.le hi))lemma mainSticker_pos (i j : ℕ) {L : Path M} {x : Grid M} {s : Scene M}(h : Trip x s L) : 0 ≤ mainSticker i j L :=add_nonneg (le_trans (by norm_num) (mainRatio_one i j h)) (by positivity)lemma scalarSticker_pos (i j : ℕ) {L : Path M} {x : Grid M} {s : Scene M}(h : Trip x s L) : 0 ≤ scalarSticker i j L :=mul_nonneg (rate_easy i).1.le(add_nonneg (add_nonneg (by norm_num) (trip_K h)) (timex_scores (tagL i) j L).1)/-- Bounding a suffix without bigger main activations. -/lemma ride :∀ᶠ j : ℕ in atTop,∀ M J i : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ, ∀ l r m : Path M,∀ (b : Beat M) (x u : Grid M),let g := tagM ilet D := b::rlet L := l++(D++m)let p := heroPlot g LCast j J f s L → Trip x s L → entitled g s j →ringing u p j l b →(0 < i → stall u (tagM (i-1)) j L (l++D)) →‖subtotal (proceeds x u) D‖ ≤ 10^20*(fullFax D+mainSticker i j L) := byfilter_upwards [live_rec,channel_inner,near_size] with j h₁ h₂ h₃M J i s f l r m b x u g D L p hh he hg hp hflet g' := tagM (i-1)let n := billWait g' j Lobtain ⟨z,hz⟩ := bound_stage (u:=u) L hh g'obtain ⟨v,hA,l₀,l₁,hL,hT⟩ := h₁ M J s f u g l (r++m) b hh hg hplet t := timex g j Llet S := rose g vhave HT : 2*log (sumbling S none (l₁++(b::(r++m)))) ≤ t := byapply le_trans _ hTunfold S g Troupe.rose Troupe.tagM recitalsimpexact le_rflhave hI : i ≤ mainIx j := (hg rfl).1have H : ∃ k, delta (dye b.post) k ≤ sepRad j ∧ rad (u-v-k) ≤ 2*spotLimit b.post j i true := bychange aligned p b.post j u v at hAunfold aligned at hArw [ite_eq_left (show p.main=true from rfl)] at hA; exact hAobtain ⟨k,hK,hD⟩ := Hlet a := depthRate iobtain ⟨_,q,hq⟩ := trip_cut (show Trip x s (l++(D++m)) from he)obtain ⟨hX,_,_⟩ := trip_cut hqhave hY : b.post.here=q.here := hX.2.1.lower.here.trans (congrArg Scene.here hX.1)have hy : dye b.post=dye q := (trip_attend hX b List.mem_cons_self).2.2.2.2have HV (c : Beat M) (hc : c∈D) (hA : ¬betweenS z n c) :innerV S c.post := byhave hr := trip_attend hX c hcrefine h₂ i hI M b.post c.post (by rw [hY]; exact hr.2.2.2.1)(hr.2.2.2.2.trans hy.symm) hr.1.climb u v k hK hD ?_intro hi hxhave HX := hf hiexact hA (hz (l++D) m (by unfold L; rw [List.append_assoc]) HX c (by simp [hc]) hx)let P := proceeds x uhave HA : 1 ≤ mainRatio i j L := mainRatio_one i j hehave hc (v' w q' : Path M) (hiD : D=v'++(w++q')) (hiA : ∀ b∈w, ¬betweenS z n b) :‖subtotal P w‖ ≤ 10^16*(fullFax w+mainRatio i j L) := byhave hp₁ : Trip x q (v'++(w++q')) := hiD ▸ hXhave hp₂ : L=l₀++(((l₁++v')++(w++(q'++m)))) := byunfold L; rw [hL,hiD]; simp only [List.append_assoc]have hp₃ : l₁++(b::(r++m))=(l₁++v')++(w++(q'++m)) := bychange l₁++(D++m)=_rw [hiD]; simp only [List.append_assoc]let K := (l₁++v')++(w++(q'++m))obtain ⟨hU,c₀,hc₀⟩ := trip_cut (show Trip x s (l₀++K) from hp₂ ▸ he)have hi₁ := possible S (l₁++v') w (q'++m) hc₀(fun b hb => HV b (by rw [hiD]; simp [hb]) (hiA b hb)) t (hp₃ ▸ HT)have hi₂ : yieldW (subtotal (duties x v) w) ≤ 10^15*(fullFax w + mainRatio i j L) := byapply hi₁.trans; unfold mainRatiochange 10^15*(fullFax w+(1+fullKills K+flagged S K)/a+a*t) ≤10^15*(fullFax w+((1+fullKills L+flagged S L)/a+a*t))have ht₁ : fullKills K ≤ fullKills L := byrw [hp₂,show fullKills (l₀++K)=fullKills l₀+fullKills K from subtotal_app killed _ _]exact le_add_of_nonneg_left (trip_K hU)have ht₂ : flagged S K ≤ flagged S L := byrw [hp₂,show flagged S (l₀++K)=flagged S l₀+flagged S K from subtotal_app _ _ _]exact le_add_of_nonneg_left (flagged_pos S hU)have ha : 0 < a := (rate_easy i).1have HE : (1+fullKills K+flagged S K)/a ≤ (1+fullKills L+flagged S L)/a :=div_le_div_of_nonneg_right (by linarith) ha.lelinarithhave hi₃ := h₃ i hIhave hga : 64*q.here.len*rad (u-v-k) ≤ 4 := byhave HE : b.post.here.len*rad (u-v-k) ≤ 2*sig j :=halo_limit b.post j i true _ (below_refl _) hDrw [←hY]; nlinarith [hi₃.2, side_le i, side_pos i]have HB := below_decode u v k x (dye b.post) v' w q' hp₁ hy (hK.trans (hi₃.1.trans (side_le i)))apply HB.transobtain ⟨_,C,Hc⟩ := trip_cut hp₁linarith [trip_fax (trip_cut Hc).1]obtain ⟨w,v,q,hD',hw,hp,hq⟩ := slab_on _ _ (matrix_trip D hX) z nlet K := mainRatio i j Lhave Heq : mainSticker i j L=K+(n:ℝ) := rflhave HW : D=w++(v++q) := by rw [hD',List.append_assoc]have HA₁ := hc [] w (v++q) (by simpa using HW) hwhave HA₂ := hc (w++v) q [] (by simpa using hD') hpobtain ⟨hw',q₀,Hh⟩ := trip_cut (show Trip x _ (w++(v++q)) from HW ▸ hX)obtain ⟨hv',q₁,hq₁⟩ := trip_cut Hhrw [Heq,hD',subtotal_app,subtotal_app]change ‖subtotal P w + subtotal P v + subtotal P q‖ ≤ _apply (norm_add_le _ _).transhave he' : (v.length:ℝ) ≤ n := by exact_mod_cast hqhave HE := straight_fee u v hv'change ‖subtotal P v‖ ≤ _ at HEchange 1 ≤ K at HAchange _ ≤ 10^16* (fullFax w+K) at HA₁change _ ≤ 10^16*(fullFax q+K) at HA₂have HE : fullFax (w++v++q)=fullFax w+fullFax v+fullFax q := byrw [fullFax,subtotal_app,subtotal_app]; rflrw [HE]linarith [norm_add_le (subtotal P w) (subtotal P v),trip_fax hw',trip_fax hv',trip_fax hq₁]/-- Scalar suffix exact part with mask specified by chosen representative. -/def guardedV (i : ℕ) (v : Grid M) (b : Beat M) := guarded v (side i) b.postdef ampU (s : Scene M) (u : Grid M) :=max ‖scalar (s.smaller false) u‖ ‖scalar (s.smaller true) u‖lemma mask_estimate :∀ᶠ j : ℕ in atTop, ∀ M J i : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ,∀ l r m : Path M, ∀ b : Beat M, ∀ x u : Grid M,let g := tagL ilet D := b::rlet L := l++(D++m)let p := heroPlot g LCast j J f s L → Trip x s L → ringing u p j l b →∃ v : Grid M, let μ := guardedV i v‖subtotal (aired μ x u) D‖ ≤ 20000*scalarSticker i j L ∧∀ z∈D, ¬μ z → 4*side i < ampU z.post u := byfilter_upwards [live_rec] with j hj M J i s f l r m b x u g D L p h ht hplet y := side ihave Hg : entitled g s j := fun H => False.elim (Bool.noConfusion H)obtain ⟨v,hA,l₀,l₁,hL,hT⟩ := hj M J s f u g l (r++m) b h Hg hphave HK : rad (u-v) ≤ 2*spotLimit b.post j i false := bychange aligned p b.post j u v at hAunfold aligned at hA; rw [ite_eq_right (show p.main ≠ true from Bool.false_ne_true)] at hA; exact hAobtain ⟨_,q,hq⟩ := trip_cut (show Trip x s (l++(D++m)) from ht)have HX := (trip_cut hq).1have HE : b.post.here=q.here := HX.2.1.lower.here.trans (congrArg Scene.here HX.1)have hb : b.post.here.len*rad (u-v) ≤ 2*(y^4/65536) := halo_limit _ j i false _ (below_refl _) HKlet a := depthRate ihave ha : 0 < a ∧ a ≤ 1 ∧ a^2=y := rate_easy ihave hy : 0 < y := side_pos ihave hf : y^4 ≤ y := by simpa using pow_le_pow_of_le_one hy.le (side_le i) (by omega : 1≤4)refine ⟨v,?_⟩intro μlet t := timex g j Lhave hp₂ : L=l₀++(l₁++(D++m)) := by unfold L; rw [hL,List.append_assoc]constructor· have ht₀ : 2*log (coldScore v y (l₁++D++m)) ≤ t := byapply le_trans _ hTsimp only [g,tagL,recital,Bool.false_eq_true,↓reduceIte,List.append_assoc]exact le_rflobtain ⟨hU,c₀,hc₀⟩ := trip_cut (show Trip x s (l₀++(l₁++(D++m))) from hp₂ ▸ ht)have He : Trip x c₀ (l₁++D++m) := by rwa [List.append_assoc]have HR : aired μ x v = frosty x v y := byfunext b; unfold aired frosty prizesplit_ifs with h1 h2 h2· rfl· exact (h2 h1).elim· exact (h1 h2).elimsimphave Hx := rail_fee u v μ [] D [] (s:=q) (by simpa using HX)have HV := frosty_portion v hy (side_le i) l₁ D m He t ht₀have H := norm_add_le (subtotal (aired μ x u) D-chi (u-v) x*subtotal (aired μ x v) D)(chi (u-v) x*subtotal (aired μ x v) D)rw [sub_add_cancel,norm_mul,norm_chi,one_mul,HR] at Hhave hE' : fullKills (l₁++D++m) ≤ fullKills L := byrw [hp₂,List.append_assoc,show fullKills (l₀++(l₁++(D++m)))=fullKills l₀+fullKills (l₁++(D++m)) from subtotal_app killed _ _]exact le_add_of_nonneg_left (trip_K hU)have hV : 0 ≤ fullKills L := trip_K hthave hY : 0 ≤ t := (timex_scores g j _).1apply H.transrw [HR,← HE] at Hxchange _ ≤ 12000*a*_ at HVchange _ ≤ 20000*(a*(1+fullKills L+t))nlinarith· intro z hz hμobtain ⟨hz₁,hz₂,hz₃,hz₄,hz₅⟩ := trip_attend HX z hzrw [←HE] at hz₄change ¬∀ k, ‖scalar (z.post.smaller k) v‖ ≤ 10*y at hμpush Not at hμobtain ⟨c,hc⟩ := hμlet d := z.post.smaller chave H1 := hz₁.climb.child chave H2 := scalar_compare d u v H1.ready H1.pos.le 4 H1.lifthave H3 : d.here.len ≤ b.post.here.len :=node_compress (below_trans (child_below _ _) hz₄)have HH' : ‖scalar d u‖ ≤ ampU z.post u := by unfold d ampU; cases c; exact le_max_left _ _; exact le_max_right _ _change _ < ‖scalar d v‖ at hcchange 4*y < _nlinarith [(abs_le.mp H2).1,rad_nonneg (u-v)]end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import OAI.Analysis.FourierLLogL.Assembly.Weighted/-!# The grid bound-/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Node Real Period Compress.Params Thermalopen Procedure Procedure.Scene Procedure.Paths Procedure.Paths.Troupe Procedure.Paths.CastShowvariable {M J j : ℕ} {s : Scene M} {f : Grid M → ℝ}open scoped Classicaltheorem gridProof : GridBound := byrefine ⟨10^222,by positivity,?_⟩filter_upwards [grossDry,grossOur,plant,annual_valid] with j h1 h2 hp h Jfilter_upwards [eventually_ge_atTop (J+20)] with M hM f hF hm hGlet m := expU flet b := decide (1/Thermal.H j ≤ m)let s := beginPlay f bhave he : J ≤ M := by omegaobtain ⟨t,ht⟩ := hp M J he f hF hm hG blet W (x : Grid M) := annual x thave hX (x : Grid M) : x ∈ s.here.block M := (mem_group _ _).mp(by change x∈root.group M; rw [group_top]; simp)refine ⟨W,fun x => ?_, ?_,?_⟩· exact le_trans (norm_nonneg _) (h M J he s f t ht 0 x (hX x))· rw [← top_avg W,avg_ex (root_ok M)]change yieldA t ≤ _suffices H : ∀ b : Bool, decide (1/Thermal.H j ≤ m)=b → ∀ t : Play j M (beginPlay f b), t.Follows J f → yieldA t ≤ (10:ℝ)^222*height j from H b rfl t htintro b ha t hthave hd := d_pos jcases b· have hh := le_of_not_ge (of_decide_eq_false ha)exact le_trans (h1 M J f hG t ht (by rw [show (beginPlay f false).mass=m from top_avg _]; exact hh)) (by linarith)· have hh := of_decide_eq_true hahave HE : 1000*(2:ℝ)^J ≤ 2^M := byapply le_trans _ (pow_le_pow_right₀ (by norm_num) hM)rw [pow_add]nlinarith [show 0 < (2:ℝ)^J by positivity]have HX : (beginPlay f true).mass=m := top_avg fhave HV := h2 M J HE f hG t ht (HX.symm ▸ hh)rw [HX] at HVhave hc : m ≤ 2 := hmchange _ ≤ (10:ℝ)^222* height jnlinarithintro x hx uhave HE := stage_shift s t u x ht (hX x) hxhave HI : tailE s J x u=FinShift J (finMod f u) x := byunfold tailE; rw [show s.here.lev=0 from rfl,Nat.Ico_zero_eq_range]rflrw [HI,ordinary,show s.norm=0 from rfl,Complex.ofReal_zero,zero_mul,zero_add] at HErw [HE]; exact h M J he s f t ht u x (hX x)end FourierLLogL.Dyadicend OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import OAI.Analysis.FourierLLogL.Assembly.Weighted/-!# The grid bound-/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Node Real Period Compress.Params Thermalopen Procedure Procedure.Scene Procedure.Paths Procedure.Paths.Troupe Procedure.Paths.CastShowvariable {M J j : ℕ} {s : Scene M} {f : Grid M → ℝ}open scoped Classicaltheorem gridProof : GridBound := byrefine ⟨10^222,by positivity,?_⟩filter_upwards [grossDry,grossOur,plant,annual_valid] with j h1 h2 hp h Jfilter_upwards [eventually_ge_atTop (J+20)] with M hM f hF hm hGlet m := expU flet b := decide (1/Thermal.H j ≤ m)let s := beginPlay f bhave he : J ≤ M := by omegaobtain ⟨t,ht⟩ := hp M J he f hF hm hG blet W (x : Grid M) := annual x thave hX (x : Grid M) : x ∈ s.here.block M := (mem_group _ _).mp(by change x∈root.group M; rw [group_top]; simp)refine ⟨W,fun x => ?_, ?_,?_⟩· exact le_trans (norm_nonneg _) (h M J he s f t ht 0 x (hX x))· rw [← top_avg W,avg_ex (root_ok M)]change yieldA t ≤ _suffices H : ∀ b : Bool, decide (1/Thermal.H j ≤ m)=b → ∀ t : Play j M (beginPlay f b), t.Follows J f → yieldA t ≤ (10:ℝ)^222*height j from H b rfl t htintro b ha t hthave hd := d_pos jcases b· have hh := le_of_not_ge (of_decide_eq_false ha)exact le_trans (h1 M J f hG t ht (by rw [show (beginPlay f false).mass=m from top_avg _]; exact hh)) (by linarith)· have hh := of_decide_eq_true hahave HE : 1000*(2:ℝ)^J ≤ 2^M := byapply le_trans _ (pow_le_pow_right₀ (by norm_num) hM)rw [pow_add]nlinarith [show 0 < (2:ℝ)^J by positivity]have HX : (beginPlay f true).mass=m := top_avg fhave HV := h2 M J HE f hG t ht (HX.symm ▸ hh)rw [HX] at HVhave hc : m ≤ 2 := hmchange _ ≤ (10:ℝ)^222* height jnlinarithintro x hx uhave HE := stage_shift s t u x ht (hX x) hxhave HI : tailE s J x u=FinShift J (finMod f u) x := byunfold tailE; rw [show s.here.lev=0 from rfl,Nat.Ico_zero_eq_range]rflrw [HI,ordinary,show s.norm=0 from rfl,Complex.ofReal_zero,zero_mul,zero_add] at HErw [HE]; exact h M J he s f t ht u x (hX x)end FourierLLogL.Dyadicend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213import OAI.Analysis.FourierLLogL.Assembly.Tokens/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupelemma masked_split (m : Beat M → Prop) (x u : Grid M) (l : Path M) :subtotal (proceeds x u) l=subtotal (aired m x u) l+subtotal (aired (fun b => ¬m b) x u) l := byinduction l with| nil => simp [subtotal]| cons b l ih =>simp only [subtotal_cons,ih]by_cases h : m b <;> unfold aired <;> simp only [h,not_false_eq_true,ite_false,ite_true,zero_add,not_true]all_goals abellemma subt_le {l : Path M} {f g : Beat M → ℝ} (h : ∀ b∈l, f b ≤ g b) :subtotal f l ≤ subtotal g l := byinduction l with| nil => exact le_rfl| cons b l ih =>exact add_le_add (h b List.mem_cons_self)(ih (fun i hi => h i (List.mem_cons_of_mem _ hi)))def crumb (n T j : ℕ) (L : Path M) :=20000*∑ i∈Finset.Ico n T, scalarSticker i j Llemma start_ico (t n : ℕ) (h : n < t) (f : ℕ → ℝ) :∑ i∈Finset.Ico n t,f i = f n+∑ i∈Finset.Ico (n+1) t,f i := byhave he : Finset.Ico n t=insert n (Finset.Ico (n+1) t) := byext i; simp only [Finset.mem_insert, Finset.mem_Ico]; omegarw [he, Finset.sum_insert (by simp)]lemma scalar_stage :∀ᶠ j : ℕ in atTop,∀ (M J : ℕ) (s : Scene M) (c : Bool) (f : Grid M → ℝ) (x u : Grid M),let t := lowI j clet T := highI j M c∀ (L : Path M) (a : Grade → ℕ), Cast j J f s L → Trip x s L → shades a u L j →∀ (l r : Path M), L=l++r → (c=true→stall u (tagM (mainIx j)) j L l) →‖subtotal (proceeds x u) l‖ ≤subtotal (token a L j c) l + crumb t T j L := byfilter_upwards [mask_estimate] with j hj M J s c f x u t T L a h hh hVlet P := proceeds x ulet q := token a L j csuffices HE : ∀ k n : ℕ, t ≤ n → n+k=T → ∀ l r : Path M, L=l++r →(c=true → stall u (tagM (mainIx j)) j L l) →(∀ i∈Finset.Ico t n, stall u (tagL i) j L l) →‖subtotal P l‖ ≤ subtotal q l+crumb n T j L byintro l r hx hfhave hT : t ≤ T := Nat.le_trans (Nat.le_add_right _ _) (Nat.le_add_right _ _)exact HE (T-t) t (le_refl _) (by omega) l r hx hf (by simp)intro kinduction k with| zero =>intro n hn hE l r hl hf heobtain rfl := (show T=n by omega)rw [show crumb T T j L=0 by simp [crumb],add_zero]apply (subt_norm l P).transexact subt_le (fun b hb => direct_point hh j c a hV T l r b hf he ⟨hn,le_rfl⟩ hl hb (by omega))| succ k ih =>intro n hn hE l r hl hf hehave hT : n < T := by omegahave HV : crumb n T j L = 20000*scalarSticker n j L + crumb (n+1) T j L := byrw [crumb, start_ico T n hT,mul_add]; rflrw [HV]let g := tagL nhave HP (p w : Path M) (hL : l=p++w) (hh : stall u g j L p) :‖subtotal P p‖ ≤ subtotal q p + crumb (n+1) T j L := byhave hx (g) (hh : stall u g j L l) : stall u g j L p := byrw [hL] at hhexact ((mute_cat _ _ _ _ _ _).1 hh).1apply ih (n+1) (hn.trans (Nat.le_add_right n 1)) (by omega) p (w++r) ?_(fun H => hx _ (hf H))· intro i hiobtain ⟨h₁,h₂⟩ := Finset.mem_Ico.mp hiby_cases heq : i=n· subst heq; exact hh· exact hx _ (he _ (Finset.mem_Ico.mpr ⟨h₁,by omega⟩))rw [hl,hL,List.append_assoc]let p := heroPlot g Lrcases first_on u p (vacant M) j l with H|⟨d,b,m,H,h₁,h₂⟩· have Hx := HP l [] (by simp) Hhave HE := scalarSticker_pos n j hh; linarith· let w := b::mlet L' := d++(w++r)have HB : L=L' := by unfold L' w; rw [hl,H,List.append_assoc]have HC : ringing u (heroPlot g L') j d b := HB ▸ h₂have Hw : l=d++w := Hobtain ⟨v,hX⟩ := hj M J n s f d m r b x u (show Cast j J f s L' from HB ▸ h) (show Trip x s L' from HB ▸ hh) HClet μ := guardedV n v; let Q := aired μ x u; let R := aired (fun z => ¬μ z) x uchange ‖subtotal Q w‖ ≤ _*scalarSticker n j L' ∧ _ at hXhave hx₁ : ‖subtotal Q w‖ ≤ 20000* scalarSticker n j L := by rw [HB]; exact hX.1have hx₂ : ‖subtotal R w‖ ≤ subtotal q w := byapply (subt_norm w R).trans; apply subt_leintro z hzunfold R aired; split· rename_i HHapply direct_point hh j c a hV n l r z hf he ⟨hn,hT.le⟩ hl (by rw [Hw]; simp [hz])intro _; exact hX.2 z hz HH· rw [norm_zero]; exact tokens_nonneg a L z j crw [Hw,subtotal_app,subtotal_app,show subtotal P w=subtotal Q w+subtotal R w from masked_split μ x u w]apply (norm_add_le _ _).translinarith [HP d w Hw h₁,norm_add_le (subtotal Q w) (subtotal R w)]def bigCrumb (n t j : ℕ) (L : Path M) :=10^20* ∑ i∈Finset.Ico n t, mainSticker i j L/-- Main handles a contour interval, consuming the small leading prefix only once. -/lemma main_stage :∀ᶠ j : ℕ in atTop, ∀ (M J : ℕ) (s : Scene M) (f : Grid M → ℝ) (x u : Grid M)(L : Path M), s.live=true → Cast j J f s L → Trip x s L →∀ (v : ℝ),(∀ l r : Path M, L=l++r → (∀ i, i ≤ mainIx j → stall u (tagM i) j L l) →‖subtotal (proceeds x u) l‖ ≤ v) →‖subtotal (proceeds x u) L‖ ≤ v+10^20*fullFax L+bigCrumb 0 (mainIx j+1) j L := byfilter_upwards [ride] with j hj M J s f x u L hs hc ht v hvlet P := proceeds x ulet T := mainIx j+1suffices H : ∀ k n : ℕ, n+k=T → ∀ (l r : Path M), L=l++r →(∀ i, i < n → stall u (tagM i) j L l) →‖subtotal P l‖ ≤ v+10^20*fullFax l+bigCrumb n T j L fromH T 0 (by omega) L [] (by simp) (by omega)intro k; induction k with| zero =>intro n hh l r he hfhave HX : Trip x s (l++r) := he ▸ hthave hT : n=T := by omegacases hThave HH := hv l r he (fun i hi => hf i (Nat.lt_succ_of_le hi))have HJ := trip_fax (trip_cut HX).1simp only [bigCrumb,Finset.Ico_self,Finset.sum_empty,mul_zero,add_zero]unfold P; linarith| succ k ih =>intro n hn l r hl hflet g := tagM n; let p := heroPlot g Lhave hE : n < mainIx j+1 := Nat.lt_of_lt_of_le (by omega : n < T) (le_refl _)have hX : Cast j J f s (l++r) := hl ▸ hchave hY : Trip x s (l++r) := hl ▸ hthave HI (d w : Path M) (hD : l=d++w) (hh : stall u g j L d) :‖subtotal P d‖ ≤ v+10^20*fullFax d+bigCrumb (n+1) T j L := byapply ih _ (by omega) d (w++r) ?_· intro i hiby_cases he : i=n; subst i; exact hhhave H := hf i (by omega)rw [hD] at Hexact ((mute_cat _ _ _ _ _ _).1 H).1rw [hl,hD,List.append_assoc]rw [show bigCrumb n T j L=10^20*mainSticker n j L+bigCrumb (n+1) T j L byunfold bigCrumb; rw [start_ico _ n hE,mul_add]]rcases first_on u p (vacant M) j l with H|⟨d,b,w,hD,hp,ha⟩· have HE := HI l [] (by simp) Hlinarith [mainSticker_pos n j ht]· let D := b::w; let X := d++(D++r)have heq : X = L := by unfold X D; rw [hl,hD,List.append_assoc]have H : Cast j J f s X := heq.symm ▸ hc; have HR : Trip x s X := heq.symm ▸ hthave HF : ringing u (heroPlot g X) j d b := by rw [heq]; exact hahave Ht (hh : 0 < n) : stall u (tagM (n-1)) j X (d++D) := by rw [heq]; exact (hD ▸ hf (n-1) (by omega))have HH := hj M J n s f d w r b x u H HR (fun _ => ⟨by change n ≤ mainIx j; omega,hs⟩) HF Htchange ‖subtotal P D‖ ≤ _*(fullFax D+mainSticker n j X) at HHrw [heq] at HHrw [show l=d++D from hD,subtotal_app,show fullFax (d++D)=fullFax d+fullFax D from subtotal_app billFax d D]apply (norm_add_le _ _).trans; linarith [HI d D hD hp]def souvenir (c : Bool) (j : ℕ) (L : Path M) :=let t := lowI j c; let T := highI j M ctokenCost j c L+crumb t T j L+(if c then 10^20*fullFax L+bigCrumb 0 (mainIx j+1) j L else 0)lemma gala :∀ᶠ j : ℕ in atTop, ∀ (M J : ℕ), J ≤ M → ∀ s : Scene M, ∀ f : Grid M → ℝ,∀ x u : Grid M, ∀ L : Path M, Cast j J f s L → Trip x s L →‖subtotal (proceeds x u) L‖ ≤ souvenir s.live j L := byfilter_upwards [scalar_stage, main_stage] with j hs hm M J hJ s f x u L h hhobtain ⟨a,ha⟩ := sheds h ulet V (c : Bool) := tokenCost j c L+ crumb (lowI j c) (highI j M c) j Lhave HV (b : Bool) (l r : Path M) (he : L=l++r) (ht : b=true→stall u (tagM (mainIx j)) j L l) :‖subtotal (proceeds x u) l‖ ≤ V b := byapply (hs M J s b f x u L a h hh ha l r he ht).transapply add_le_add_lefthave hM : L.length ≤ M := by have HE := trip_depth_limit h; omegaapply le_trans _ (max_tokens L hh a j b hM)obtain ⟨hx,V,hR⟩ := trip_cut (show Trip x s (l++r) from he ▸ hh)nth_rw 3 [he]exact le_trans (le_add_of_nonneg_right (trip_nonneg hR (f:=token a L j b)(fun i _ => tokens_nonneg _ _ _ _ _))) (le_of_eq (subtotal_app _ l r).symm)unfold souvenirby_cases HB : s.live=true· have HH := hm M J s f x u L HB h hh (V true) (fun l r hL he =>HV _ _ _ hL (fun _ => he _ (le_refl _)))rw [HB,ite_eq_left rfl]unfold V at HH; linarithrw [show s.live=false from Bool.eq_false_iff.mpr HB,ite_eq_right (by simp),add_zero]exact HV false L [] (by simp) fun h => Bool.noConfusion hend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213import OAI.Analysis.FourierLLogL.Assembly.Tokens/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupelemma masked_split (m : Beat M → Prop) (x u : Grid M) (l : Path M) :subtotal (proceeds x u) l=subtotal (aired m x u) l+subtotal (aired (fun b => ¬m b) x u) l := byinduction l with| nil => simp [subtotal]| cons b l ih =>simp only [subtotal_cons,ih]by_cases h : m b <;> unfold aired <;> simp only [h,not_false_eq_true,ite_false,ite_true,zero_add,not_true]all_goals abellemma subt_le {l : Path M} {f g : Beat M → ℝ} (h : ∀ b∈l, f b ≤ g b) :subtotal f l ≤ subtotal g l := byinduction l with| nil => exact le_rfl| cons b l ih =>exact add_le_add (h b List.mem_cons_self)(ih (fun i hi => h i (List.mem_cons_of_mem _ hi)))def crumb (n T j : ℕ) (L : Path M) :=20000*∑ i∈Finset.Ico n T, scalarSticker i j Llemma start_ico (t n : ℕ) (h : n < t) (f : ℕ → ℝ) :∑ i∈Finset.Ico n t,f i = f n+∑ i∈Finset.Ico (n+1) t,f i := byhave he : Finset.Ico n t=insert n (Finset.Ico (n+1) t) := byext i; simp only [Finset.mem_insert, Finset.mem_Ico]; omegarw [he, Finset.sum_insert (by simp)]lemma scalar_stage :∀ᶠ j : ℕ in atTop,∀ (M J : ℕ) (s : Scene M) (c : Bool) (f : Grid M → ℝ) (x u : Grid M),let t := lowI j clet T := highI j M c∀ (L : Path M) (a : Grade → ℕ), Cast j J f s L → Trip x s L → shades a u L j →∀ (l r : Path M), L=l++r → (c=true→stall u (tagM (mainIx j)) j L l) →‖subtotal (proceeds x u) l‖ ≤subtotal (token a L j c) l + crumb t T j L := byfilter_upwards [mask_estimate] with j hj M J s c f x u t T L a h hh hVlet P := proceeds x ulet q := token a L j csuffices HE : ∀ k n : ℕ, t ≤ n → n+k=T → ∀ l r : Path M, L=l++r →(c=true → stall u (tagM (mainIx j)) j L l) →(∀ i∈Finset.Ico t n, stall u (tagL i) j L l) →‖subtotal P l‖ ≤ subtotal q l+crumb n T j L byintro l r hx hfhave hT : t ≤ T := Nat.le_trans (Nat.le_add_right _ _) (Nat.le_add_right _ _)exact HE (T-t) t (le_refl _) (by omega) l r hx hf (by simp)intro kinduction k with| zero =>intro n hn hE l r hl hf heobtain rfl := (show T=n by omega)rw [show crumb T T j L=0 by simp [crumb],add_zero]apply (subt_norm l P).transexact subt_le (fun b hb => direct_point hh j c a hV T l r b hf he ⟨hn,le_rfl⟩ hl hb (by omega))| succ k ih =>intro n hn hE l r hl hf hehave hT : n < T := by omegahave HV : crumb n T j L = 20000*scalarSticker n j L + crumb (n+1) T j L := byrw [crumb, start_ico T n hT,mul_add]; rflrw [HV]let g := tagL nhave HP (p w : Path M) (hL : l=p++w) (hh : stall u g j L p) :‖subtotal P p‖ ≤ subtotal q p + crumb (n+1) T j L := byhave hx (g) (hh : stall u g j L l) : stall u g j L p := byrw [hL] at hhexact ((mute_cat _ _ _ _ _ _).1 hh).1apply ih (n+1) (hn.trans (Nat.le_add_right n 1)) (by omega) p (w++r) ?_(fun H => hx _ (hf H))· intro i hiobtain ⟨h₁,h₂⟩ := Finset.mem_Ico.mp hiby_cases heq : i=n· subst heq; exact hh· exact hx _ (he _ (Finset.mem_Ico.mpr ⟨h₁,by omega⟩))rw [hl,hL,List.append_assoc]let p := heroPlot g Lrcases first_on u p (vacant M) j l with H|⟨d,b,m,H,h₁,h₂⟩· have Hx := HP l [] (by simp) Hhave HE := scalarSticker_pos n j hh; linarith· let w := b::mlet L' := d++(w++r)have HB : L=L' := by unfold L' w; rw [hl,H,List.append_assoc]have HC : ringing u (heroPlot g L') j d b := HB ▸ h₂have Hw : l=d++w := Hobtain ⟨v,hX⟩ := hj M J n s f d m r b x u (show Cast j J f s L' from HB ▸ h) (show Trip x s L' from HB ▸ hh) HClet μ := guardedV n v; let Q := aired μ x u; let R := aired (fun z => ¬μ z) x uchange ‖subtotal Q w‖ ≤ _*scalarSticker n j L' ∧ _ at hXhave hx₁ : ‖subtotal Q w‖ ≤ 20000* scalarSticker n j L := by rw [HB]; exact hX.1have hx₂ : ‖subtotal R w‖ ≤ subtotal q w := byapply (subt_norm w R).trans; apply subt_leintro z hzunfold R aired; split· rename_i HHapply direct_point hh j c a hV n l r z hf he ⟨hn,hT.le⟩ hl (by rw [Hw]; simp [hz])intro _; exact hX.2 z hz HH· rw [norm_zero]; exact tokens_nonneg a L z j crw [Hw,subtotal_app,subtotal_app,show subtotal P w=subtotal Q w+subtotal R w from masked_split μ x u w]apply (norm_add_le _ _).translinarith [HP d w Hw h₁,norm_add_le (subtotal Q w) (subtotal R w)]def bigCrumb (n t j : ℕ) (L : Path M) :=10^20* ∑ i∈Finset.Ico n t, mainSticker i j L/-- Main handles a contour interval, consuming the small leading prefix only once. -/lemma main_stage :∀ᶠ j : ℕ in atTop, ∀ (M J : ℕ) (s : Scene M) (f : Grid M → ℝ) (x u : Grid M)(L : Path M), s.live=true → Cast j J f s L → Trip x s L →∀ (v : ℝ),(∀ l r : Path M, L=l++r → (∀ i, i ≤ mainIx j → stall u (tagM i) j L l) →‖subtotal (proceeds x u) l‖ ≤ v) →‖subtotal (proceeds x u) L‖ ≤ v+10^20*fullFax L+bigCrumb 0 (mainIx j+1) j L := byfilter_upwards [ride] with j hj M J s f x u L hs hc ht v hvlet P := proceeds x ulet T := mainIx j+1suffices H : ∀ k n : ℕ, n+k=T → ∀ (l r : Path M), L=l++r →(∀ i, i < n → stall u (tagM i) j L l) →‖subtotal P l‖ ≤ v+10^20*fullFax l+bigCrumb n T j L fromH T 0 (by omega) L [] (by simp) (by omega)intro k; induction k with| zero =>intro n hh l r he hfhave HX : Trip x s (l++r) := he ▸ hthave hT : n=T := by omegacases hThave HH := hv l r he (fun i hi => hf i (Nat.lt_succ_of_le hi))have HJ := trip_fax (trip_cut HX).1simp only [bigCrumb,Finset.Ico_self,Finset.sum_empty,mul_zero,add_zero]unfold P; linarith| succ k ih =>intro n hn l r hl hflet g := tagM n; let p := heroPlot g Lhave hE : n < mainIx j+1 := Nat.lt_of_lt_of_le (by omega : n < T) (le_refl _)have hX : Cast j J f s (l++r) := hl ▸ hchave hY : Trip x s (l++r) := hl ▸ hthave HI (d w : Path M) (hD : l=d++w) (hh : stall u g j L d) :‖subtotal P d‖ ≤ v+10^20*fullFax d+bigCrumb (n+1) T j L := byapply ih _ (by omega) d (w++r) ?_· intro i hiby_cases he : i=n; subst i; exact hhhave H := hf i (by omega)rw [hD] at Hexact ((mute_cat _ _ _ _ _ _).1 H).1rw [hl,hD,List.append_assoc]rw [show bigCrumb n T j L=10^20*mainSticker n j L+bigCrumb (n+1) T j L byunfold bigCrumb; rw [start_ico _ n hE,mul_add]]rcases first_on u p (vacant M) j l with H|⟨d,b,w,hD,hp,ha⟩· have HE := HI l [] (by simp) Hlinarith [mainSticker_pos n j ht]· let D := b::w; let X := d++(D++r)have heq : X = L := by unfold X D; rw [hl,hD,List.append_assoc]have H : Cast j J f s X := heq.symm ▸ hc; have HR : Trip x s X := heq.symm ▸ hthave HF : ringing u (heroPlot g X) j d b := by rw [heq]; exact hahave Ht (hh : 0 < n) : stall u (tagM (n-1)) j X (d++D) := by rw [heq]; exact (hD ▸ hf (n-1) (by omega))have HH := hj M J n s f d w r b x u H HR (fun _ => ⟨by change n ≤ mainIx j; omega,hs⟩) HF Htchange ‖subtotal P D‖ ≤ _*(fullFax D+mainSticker n j X) at HHrw [heq] at HHrw [show l=d++D from hD,subtotal_app,show fullFax (d++D)=fullFax d+fullFax D from subtotal_app billFax d D]apply (norm_add_le _ _).trans; linarith [HI d D hD hp]def souvenir (c : Bool) (j : ℕ) (L : Path M) :=let t := lowI j c; let T := highI j M ctokenCost j c L+crumb t T j L+(if c then 10^20*fullFax L+bigCrumb 0 (mainIx j+1) j L else 0)lemma gala :∀ᶠ j : ℕ in atTop, ∀ (M J : ℕ), J ≤ M → ∀ s : Scene M, ∀ f : Grid M → ℝ,∀ x u : Grid M, ∀ L : Path M, Cast j J f s L → Trip x s L →‖subtotal (proceeds x u) L‖ ≤ souvenir s.live j L := byfilter_upwards [scalar_stage, main_stage] with j hs hm M J hJ s f x u L h hhobtain ⟨a,ha⟩ := sheds h ulet V (c : Bool) := tokenCost j c L+ crumb (lowI j c) (highI j M c) j Lhave HV (b : Bool) (l r : Path M) (he : L=l++r) (ht : b=true→stall u (tagM (mainIx j)) j L l) :‖subtotal (proceeds x u) l‖ ≤ V b := byapply (hs M J s b f x u L a h hh ha l r he ht).transapply add_le_add_lefthave hM : L.length ≤ M := by have HE := trip_depth_limit h; omegaapply le_trans _ (max_tokens L hh a j b hM)obtain ⟨hx,V,hR⟩ := trip_cut (show Trip x s (l++r) from he ▸ hh)nth_rw 3 [he]exact le_trans (le_add_of_nonneg_right (trip_nonneg hR (f:=token a L j b)(fun i _ => tokens_nonneg _ _ _ _ _))) (le_of_eq (subtotal_app _ l r).symm)unfold souvenirby_cases HB : s.live=true· have HH := hm M J s f x u L HB h hh (V true) (fun l r hL he =>HV _ _ _ hL (fun _ => he _ (le_refl _)))rw [HB,ite_eq_left rfl]unfold V at HH; linarithrw [show s.live=false from Bool.eq_false_iff.mpr HB,ite_eq_right (by simp),add_zero]exact HV false L [] (by simp) fun h => Bool.noConfusion hend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225import OAI.Analysis.FourierLLogL.Assembly.Cast/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef jackpot (x : Grid M) {s : Scene M} (t : Play j M s) :=s.norm*souvenir s.live j ((project t).stream x)def annual (x : Grid M) {s : Scene M} (t : Play j M s) : ℝ := match t with| .rest _ => 0| .ticket _ t => jackpot x t+annual x t| .freeze _ t => annual x t| .attempt _ _ l r => annual x l+annual x r| .jump s l r => if (step s).bit x then annual x r else annual x llemma fit_ticket {s : Scene M} {t : Play j M s.reset} (h : (Play.ticket s t).Follows J f) :Fit s.reset ∧ entry s.reset ∧ (s.live=true → exp (-height j) ≤ s.reset.norm) := byobtain ⟨ha,hb,hc,hd,he⟩ := hhave hh := hb.2.2refine ⟨⟨⟨ha.within,ha.positive⟩,hh,?_⟩,rfl, fun H => le_of_not_gt (fun h => hc ⟨H,Or.inr h⟩)⟩change s.mass/s.mass ≤ 4; rw [div_self hh.ne']; norm_numlemma annual_valid :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, J ≤ M → ∀ s : Scene M, ∀ f : Grid M → ℝ,∀ t : Play j M s, t.Follows J f → ∀ u x : Grid M, x∈s.here.block M →‖summons u x t‖ ≤ annual x t := byfilter_upwards [gala] with j hj M J hh s f t h u x hxinduction t with| rest s => simp [summons,annual]| ticket s t ih =>rw [summons,annual]have HT := fit_ticket hobtain ⟨ha,hb,hc,hd,he⟩ := happly le_trans (norm_add_le _ _)apply add_le_add _ (ih he hx)let q := tunfold ordinary jackpot; rw [norm_scaleC,abs_of_nonneg HT.1.pos.le]apply mul_le_mul_of_nonneg_left _ HT.1.pos.lehave H := Thread.projected _ heexact hj _ _ hh _ f _ _ _ (stream_cast _ H x) (trip_stream _ H HT.1 hx)| freeze s t ih => exact ih h.2.2.2 hx| attempt s v l r il ir =>rw [summons,annual]exact (norm_add_le _ _).trans (add_le_add (il h.2.2.2.2.1 hx) (ir h.2.2.2.2.2 hx))| jump s l r il ir =>rw [summons,annual]have HE := stream_child (less_self _) hxsplit_ifs with HH· exact ir h.2.2.2.2 (HH ▸ HE)· rw [show (step s).bit x=false from Bool.eq_false_iff.mpr HH] at HEexact il h.2.2.2.1 HE/-- Prices in true history. -/def normStamp (s : Scene M) (j : ℕ) :=if s.live then (s.norm/s.mass)*stamp s j else 0def billOf : Event j M → ℝ| .pace s .renew => gateTax s.reset j| .march s .move _ => normStamp s j| _ => 0def netGross {s : Scene M} (t : Play j M s) := (trace true t).flatFee billOfdef yieldA {s : Scene M} (t : Play j M s) :=(s.here.dice M).Ex (fun x => annual x t)def overdue {s : Scene M} (t : Play j M s) :=if s.live then s.norm*stats (project t) (subtotal (fun b => stamp b.post j)) else 0lemma dueEmpty {s : Scene M} {t : Play j M s} (h : project t=blank s) : overdue t=0 := byunfold overdue; rw [h]split; simp only [stats_nil,subtotal_nil,mul_zero]; rfllemma due_restart {s : Scene M} {t : Play j M s} (h : s.norm=0) : overdue t=0 := by simp [overdue,h]lemma cost_jump (s : Scene M) (l : Play j M (s.smaller false)) (r : Play j M (s.smaller true))(h : (Play.jump s l r).Follows J f) :let a := s.norm*(if s.live then stamp s j else 0)yieldA (Play.jump s l r) + overdue (Play.jump s l r) =((yieldA l+overdue l)+(yieldA r+overdue r))/2+a :=byintro alet t := Play.jump s l rlet k (b : Bool) : Thread M (s.smaller b) := match b with | false => project l | true => project rhave HG : Following j J f (ran s s k) := projected _ hobtain ⟨ha,hb,hc,hd,he⟩ := hlet v (b : Thread.Beat M) := stamp b.post jlet U (q : Scene M) := q.here.dice Mhave hM : s.here.lev < M := (Play.first hd).within.2have HH : yieldA t=(yieldA l+yieldA r)/2 := byunfold yieldArw [dice_child s.here ha.within.1 hM]have H (b : Bool) (x : Grid M) (hx : 0 < (U (s.smaller b)) x) :(step s).bit x=b := step_dice_child s.here ha.within.1 hM b hxhave HE : (U (s.smaller false)).Ex (fun x => annual x t)=yieldA l := byapply Ex_congr_mem; intro x hx; unfold t; rw [annual,H false x hx]; rflhave HF : (U (s.smaller true)).Ex (fun x => annual x t)=yieldA r := byapply Ex_congr_mem; intro x hx; unfold t; rw [annual,H true x hx]; rflchange ((U (s.smaller false)).Ex (fun x => annual x t) + (U (s.smaller true)).Ex (fun x => annual x t))/2=(yieldA l+yieldA r)/2rw [HE,HF]have HF : (project t).fee v=stamp s j+((project l).fee v+(project r).fee v)/2 := bychange (ran s s k).fee v=_rw [Thread.fee_ran k HG,fair_av]change (stamp s j+_+(stamp s j+_))/2=_unfold k; ringchange yieldA t+_ = _rw [HH]unfold a overduechange (yieldA l+yieldA r)/2 +(if s.live=true then s.norm*(project t).fee v else 0) =((yieldA l+(if s.live=true then s.norm*(project l).fee v else 0))+(yieldA r+(if s.live=true then s.norm*(project r).fee v else 0)))/2+s.norm*(if s.live then _ else 0)rw [HF]; split <;> ringlemma cost_attempt (s : Scene M) (u : Update j M s.here)(l : Play j M (s.lose u)) (r : Play j M (s.win u)) :yieldA (Play.attempt s u l r)+overdue (Play.attempt s u l r) =yieldA l+overdue l+(yieldA r+overdue r) := byrw [due_restart (s:=s.win u) rfl]have h₁ : yieldA (Play.attempt s u l r)=yieldA l+yieldA r :=Ex_add (s.here.dice M) _ _have h₂ : overdue (Play.attempt s u l r)=overdue l := byunfold overdue; rw [project]cases project l <;> rflrw [h₁,h₂]; ringlemma cost_overall :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ, ∀ s : Scene M,∀ t : Play j M s, t.Follows J f → (∀ x, f x ≤ exp (height j)) →yieldA t+overdue t ≤ s.mass*netGross t := byfilter_upwards [receipt_paid] with j hj M J f s t h hfinduction t with| rest s =>rw [netGross,trace,flat_finish,dueEmpty rfl]simp_rw [yieldA,annual,Ex_const]; simp| ticket s t ih =>let v := s.resethave hs := fit_ticket hobtain ⟨ha,hb,hc,hd,he⟩ := hhave HE := hj M J v (project t) f (projected _ he) hs.1 hs.2.1 hs.2.2 hfhave HA : yieldA (Play.ticket s t)=v.norm*stats (project t) (souvenir v.live j)+yieldA t := byunfold yieldAsimp_rw [annual,jackpot]; rw [Ex_add,Ex_lmul]rflrw [HA, netGross, trace, flat_push,dueEmpty rfl,add_zero]let x := stats (project t) (souvenir v.live j)change v.norm*x+_ ≤ s.mass*(gateTax s.reset j+netGross t)let a : ℝ := if v.live then stats (project t) (subtotal (fun b => stamp b.post j)) else 0change x ≤ gateTax v j+a at HEhave Hi := ih herw [show overdue t = s.mass*a by unfold overdue a v; split <;> first|rfl|simp] at Hichange yieldA t+s.mass*a ≤ s.mass*_ at Hichange s.mass*x+_ ≤ s.mass*(gateTax v j+_)nlinarith [hb.2.2]| freeze s t ih =>rw [dueEmpty rfl,netGross,trace]rw [ite_eq_left rfl,flat_push]have HH := ih h.2.2.2rw [due_restart (s:=s.out) rfl] at HHchange yieldA t+0 ≤ s.mass*(0+netGross t)rw [zero_add]; exact HH| jump s l r il ir =>let t := Play.jump s l rrw [cost_jump _ _ _ h]have H₁ := traced t true hunfold netGross; rw [trace,flat_fork _ _ H₁]obtain ⟨ha,hb,hc,hd,he⟩ := hlet g (b : Bool) := if b then netGross r else netGross llet v : Bool → ℝ := fun b => match b with| false => netGross l| true => netGross rlet w : ∀ b, Road j M (s.smaller b) := fun b => match b with| false => trace true l| true => trace true rlet P := (step s).probslet m := s.mass; let x := s.norm*(if s.live then stamp s j else 0)have HV (b : Bool) : (w b).flatFee billOf = v b := by cases b <;> rflhave heq : P.Ex (fun b : Bool => normStamp s j+(w b).flatFee billOf) = normStamp s j+P.Ex v := bysimp_rw [HV,Ex_add _ (f:=fun _ => _),Ex_const]change _ + x ≤ s.mass*P.Ex (fun b => normStamp s j+(w b).flatFee billOf)rw [heq,mul_add]have hM : s.here.lev < M := (Play.first hd).within.2have hi := output_split s ha.within.1 hM ha.positive hb.1.2.2 vhave hm := hb.1.2.2rw [show s.mass*normStamp s j=x by unfold x normStamp; split; field_simp; simp]change s.mass*P.Ex v=_ at hirw [hi,fair_av]have HI : (fun b => (s.smaller b).mass*v b) false = (s.smaller false).mass*netGross l := rflchange _/2+x ≤ x+ ((s.smaller false).mass*netGross l+(s.smaller true).mass*netGross r)/2linarith [il hd,ir he]| attempt s u l r il ir =>let t := Play.attempt s u l rlet v := toss s u; let P := v.probshave H := traced t true hrw [cost_attempt,netGross,trace,flat_fork _ _ H]obtain ⟨ha,hb,hc,hd,he,hx⟩ := hlet w : ∀ b, Road j M (v.dst b) := fun b => match b with| false => trace true l| true => trace true rchange _ ≤ s.mass*P.Ex (fun b => 0+(w b).flatFee billOf)simp only [zero_add,Ex,Fintype.sum_bool]have Hi := toss_true u ha.within ha.positive hb.1.2.2have HH : (s.lose u).mass = P false*s.mass := toss_mass Hi falsehave HJ : (s.win u).mass = P true*s.mass := toss_mass Hi truechange _ ≤ s.mass*(P true*netGross r+P false*netGross l)have Hi₁ := il he; have Hi₂ := ir hxrw [HH] at Hi₁; rw [HJ] at Hi₂; linarithend CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225import OAI.Analysis.FourierLLogL.Assembly.Cast/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef jackpot (x : Grid M) {s : Scene M} (t : Play j M s) :=s.norm*souvenir s.live j ((project t).stream x)def annual (x : Grid M) {s : Scene M} (t : Play j M s) : ℝ := match t with| .rest _ => 0| .ticket _ t => jackpot x t+annual x t| .freeze _ t => annual x t| .attempt _ _ l r => annual x l+annual x r| .jump s l r => if (step s).bit x then annual x r else annual x llemma fit_ticket {s : Scene M} {t : Play j M s.reset} (h : (Play.ticket s t).Follows J f) :Fit s.reset ∧ entry s.reset ∧ (s.live=true → exp (-height j) ≤ s.reset.norm) := byobtain ⟨ha,hb,hc,hd,he⟩ := hhave hh := hb.2.2refine ⟨⟨⟨ha.within,ha.positive⟩,hh,?_⟩,rfl, fun H => le_of_not_gt (fun h => hc ⟨H,Or.inr h⟩)⟩change s.mass/s.mass ≤ 4; rw [div_self hh.ne']; norm_numlemma annual_valid :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, J ≤ M → ∀ s : Scene M, ∀ f : Grid M → ℝ,∀ t : Play j M s, t.Follows J f → ∀ u x : Grid M, x∈s.here.block M →‖summons u x t‖ ≤ annual x t := byfilter_upwards [gala] with j hj M J hh s f t h u x hxinduction t with| rest s => simp [summons,annual]| ticket s t ih =>rw [summons,annual]have HT := fit_ticket hobtain ⟨ha,hb,hc,hd,he⟩ := happly le_trans (norm_add_le _ _)apply add_le_add _ (ih he hx)let q := tunfold ordinary jackpot; rw [norm_scaleC,abs_of_nonneg HT.1.pos.le]apply mul_le_mul_of_nonneg_left _ HT.1.pos.lehave H := Thread.projected _ heexact hj _ _ hh _ f _ _ _ (stream_cast _ H x) (trip_stream _ H HT.1 hx)| freeze s t ih => exact ih h.2.2.2 hx| attempt s v l r il ir =>rw [summons,annual]exact (norm_add_le _ _).trans (add_le_add (il h.2.2.2.2.1 hx) (ir h.2.2.2.2.2 hx))| jump s l r il ir =>rw [summons,annual]have HE := stream_child (less_self _) hxsplit_ifs with HH· exact ir h.2.2.2.2 (HH ▸ HE)· rw [show (step s).bit x=false from Bool.eq_false_iff.mpr HH] at HEexact il h.2.2.2.1 HE/-- Prices in true history. -/def normStamp (s : Scene M) (j : ℕ) :=if s.live then (s.norm/s.mass)*stamp s j else 0def billOf : Event j M → ℝ| .pace s .renew => gateTax s.reset j| .march s .move _ => normStamp s j| _ => 0def netGross {s : Scene M} (t : Play j M s) := (trace true t).flatFee billOfdef yieldA {s : Scene M} (t : Play j M s) :=(s.here.dice M).Ex (fun x => annual x t)def overdue {s : Scene M} (t : Play j M s) :=if s.live then s.norm*stats (project t) (subtotal (fun b => stamp b.post j)) else 0lemma dueEmpty {s : Scene M} {t : Play j M s} (h : project t=blank s) : overdue t=0 := byunfold overdue; rw [h]split; simp only [stats_nil,subtotal_nil,mul_zero]; rfllemma due_restart {s : Scene M} {t : Play j M s} (h : s.norm=0) : overdue t=0 := by simp [overdue,h]lemma cost_jump (s : Scene M) (l : Play j M (s.smaller false)) (r : Play j M (s.smaller true))(h : (Play.jump s l r).Follows J f) :let a := s.norm*(if s.live then stamp s j else 0)yieldA (Play.jump s l r) + overdue (Play.jump s l r) =((yieldA l+overdue l)+(yieldA r+overdue r))/2+a :=byintro alet t := Play.jump s l rlet k (b : Bool) : Thread M (s.smaller b) := match b with | false => project l | true => project rhave HG : Following j J f (ran s s k) := projected _ hobtain ⟨ha,hb,hc,hd,he⟩ := hlet v (b : Thread.Beat M) := stamp b.post jlet U (q : Scene M) := q.here.dice Mhave hM : s.here.lev < M := (Play.first hd).within.2have HH : yieldA t=(yieldA l+yieldA r)/2 := byunfold yieldArw [dice_child s.here ha.within.1 hM]have H (b : Bool) (x : Grid M) (hx : 0 < (U (s.smaller b)) x) :(step s).bit x=b := step_dice_child s.here ha.within.1 hM b hxhave HE : (U (s.smaller false)).Ex (fun x => annual x t)=yieldA l := byapply Ex_congr_mem; intro x hx; unfold t; rw [annual,H false x hx]; rflhave HF : (U (s.smaller true)).Ex (fun x => annual x t)=yieldA r := byapply Ex_congr_mem; intro x hx; unfold t; rw [annual,H true x hx]; rflchange ((U (s.smaller false)).Ex (fun x => annual x t) + (U (s.smaller true)).Ex (fun x => annual x t))/2=(yieldA l+yieldA r)/2rw [HE,HF]have HF : (project t).fee v=stamp s j+((project l).fee v+(project r).fee v)/2 := bychange (ran s s k).fee v=_rw [Thread.fee_ran k HG,fair_av]change (stamp s j+_+(stamp s j+_))/2=_unfold k; ringchange yieldA t+_ = _rw [HH]unfold a overduechange (yieldA l+yieldA r)/2 +(if s.live=true then s.norm*(project t).fee v else 0) =((yieldA l+(if s.live=true then s.norm*(project l).fee v else 0))+(yieldA r+(if s.live=true then s.norm*(project r).fee v else 0)))/2+s.norm*(if s.live then _ else 0)rw [HF]; split <;> ringlemma cost_attempt (s : Scene M) (u : Update j M s.here)(l : Play j M (s.lose u)) (r : Play j M (s.win u)) :yieldA (Play.attempt s u l r)+overdue (Play.attempt s u l r) =yieldA l+overdue l+(yieldA r+overdue r) := byrw [due_restart (s:=s.win u) rfl]have h₁ : yieldA (Play.attempt s u l r)=yieldA l+yieldA r :=Ex_add (s.here.dice M) _ _have h₂ : overdue (Play.attempt s u l r)=overdue l := byunfold overdue; rw [project]cases project l <;> rflrw [h₁,h₂]; ringlemma cost_overall :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ, ∀ s : Scene M,∀ t : Play j M s, t.Follows J f → (∀ x, f x ≤ exp (height j)) →yieldA t+overdue t ≤ s.mass*netGross t := byfilter_upwards [receipt_paid] with j hj M J f s t h hfinduction t with| rest s =>rw [netGross,trace,flat_finish,dueEmpty rfl]simp_rw [yieldA,annual,Ex_const]; simp| ticket s t ih =>let v := s.resethave hs := fit_ticket hobtain ⟨ha,hb,hc,hd,he⟩ := hhave HE := hj M J v (project t) f (projected _ he) hs.1 hs.2.1 hs.2.2 hfhave HA : yieldA (Play.ticket s t)=v.norm*stats (project t) (souvenir v.live j)+yieldA t := byunfold yieldAsimp_rw [annual,jackpot]; rw [Ex_add,Ex_lmul]rflrw [HA, netGross, trace, flat_push,dueEmpty rfl,add_zero]let x := stats (project t) (souvenir v.live j)change v.norm*x+_ ≤ s.mass*(gateTax s.reset j+netGross t)let a : ℝ := if v.live then stats (project t) (subtotal (fun b => stamp b.post j)) else 0change x ≤ gateTax v j+a at HEhave Hi := ih herw [show overdue t = s.mass*a by unfold overdue a v; split <;> first|rfl|simp] at Hichange yieldA t+s.mass*a ≤ s.mass*_ at Hichange s.mass*x+_ ≤ s.mass*(gateTax v j+_)nlinarith [hb.2.2]| freeze s t ih =>rw [dueEmpty rfl,netGross,trace]rw [ite_eq_left rfl,flat_push]have HH := ih h.2.2.2rw [due_restart (s:=s.out) rfl] at HHchange yieldA t+0 ≤ s.mass*(0+netGross t)rw [zero_add]; exact HH| jump s l r il ir =>let t := Play.jump s l rrw [cost_jump _ _ _ h]have H₁ := traced t true hunfold netGross; rw [trace,flat_fork _ _ H₁]obtain ⟨ha,hb,hc,hd,he⟩ := hlet g (b : Bool) := if b then netGross r else netGross llet v : Bool → ℝ := fun b => match b with| false => netGross l| true => netGross rlet w : ∀ b, Road j M (s.smaller b) := fun b => match b with| false => trace true l| true => trace true rlet P := (step s).probslet m := s.mass; let x := s.norm*(if s.live then stamp s j else 0)have HV (b : Bool) : (w b).flatFee billOf = v b := by cases b <;> rflhave heq : P.Ex (fun b : Bool => normStamp s j+(w b).flatFee billOf) = normStamp s j+P.Ex v := bysimp_rw [HV,Ex_add _ (f:=fun _ => _),Ex_const]change _ + x ≤ s.mass*P.Ex (fun b => normStamp s j+(w b).flatFee billOf)rw [heq,mul_add]have hM : s.here.lev < M := (Play.first hd).within.2have hi := output_split s ha.within.1 hM ha.positive hb.1.2.2 vhave hm := hb.1.2.2rw [show s.mass*normStamp s j=x by unfold x normStamp; split; field_simp; simp]change s.mass*P.Ex v=_ at hirw [hi,fair_av]have HI : (fun b => (s.smaller b).mass*v b) false = (s.smaller false).mass*netGross l := rflchange _/2+x ≤ x+ ((s.smaller false).mass*netGross l+(s.smaller true).mass*netGross r)/2linarith [il hd,ir he]| attempt s u l r il ir =>let t := Play.attempt s u l rlet v := toss s u; let P := v.probshave H := traced t true hrw [cost_attempt,netGross,trace,flat_fork _ _ H]obtain ⟨ha,hb,hc,hd,he,hx⟩ := hlet w : ∀ b, Road j M (v.dst b) := fun b => match b with| false => trace true l| true => trace true rchange _ ≤ s.mass*P.Ex (fun b => 0+(w b).flatFee billOf)simp only [zero_add,Ex,Fintype.sum_bool]have Hi := toss_true u ha.within ha.positive hb.1.2.2have HH : (s.lose u).mass = P false*s.mass := toss_mass Hi falsehave HJ : (s.win u).mass = P true*s.mass := toss_mass Hi truechange _ ≤ s.mass*(P true*netGross r+P false*netGross l)have Hi₁ := il he; have Hi₂ := ir hxrw [HH] at Hi₁; rw [HJ] at Hi₂; linarithend CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215import OAI.Analysis.FourierLLogL.Paths.Screen/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Plot/-- channel perturbation estimate. -/private lemma ray_channel (A : Form M) (f : Grid M → ℂ) (x : Grid M) :(channel A x).Cx f = (label A).Cx fun z => f (x+z) := byapply Complex.ext· rw [re_Cx,re_Cx,ch_ex]· have H (P : Law (Grid M)) (f) : (P.Cx f).im=P.Ex (fun i => (f i).im) := bysimp [Cx,Ex,Complex.im_sum]rw [H,H,ch_ex]lemma duet_decode (s : Scene M) (v k : Grid M) :∑ z, chi k z*letter s v z = (cred (dye s) k:ℂ)*scalar s (v+k) := bylet A := dye slet L := channel Ahave HE (x : Grid M) :∑ z, (L x z:ℂ)*chi k z=chi k x*(cred A k:ℂ) := bychange (channel A x).Cx _=_rw [ray_channel,cred_eq]simp_rw [chi_add,Cx_lmul]unfold letter fz scalar; unfold omegaObssimp_rw [Finset.mul_sum]rw [Finset.sum_comm]apply Finset.sum_congr rfl; intro i _let p : ℂ := ante s icalc_ = p*chi v i*∑ z,(L i z:ℂ)*chi k z := byrw [Finset.mul_sum]exact Finset.sum_congr rfl fun z _ => by unfold L p A ante; push_cast; ring_ = _ := by rw [HE i,chi_add']; unfold p ante A; ringlemma gain_decode (s : Scene M) (v k : Grid M) :∑ z, chi k z*factor s v z = (cred (dye s) k:ℂ)*gain s (v+k) := byunfold factorsimp_rw [← mul_div_assoc,mul_sub]; rw [←Finset.sum_div,Finset.sum_sub_distrib,duet_decode,duet_decode,gain]simp only [dye,smaller]; ringlemma energy_near_channel (s : Scene M) (h : Fit s) (v k : Grid M) :energy s v ≤ 2*energy s (v+k)+2*(share s*delta (dye s) k^2) := bylet A := dye s; let P := channel A; let f := ante slet W (x y : Grid M) := f x * P x ylet a := letter s v; let b := letter s (v+k)let m := matter slet T (x y : Grid M) := chi k x-chi k ylet G (y : Grid M) := ∑ i,W i y* ‖T i y‖^2have hw (x y) : 0 ≤ W x y := mul_nonneg (ante_nonneg _ h.ready.2 h.pos.le _) ((P x).nonneg _)have H (z : Grid M) :b z-chi k z*a z = ∑ x, (W x z:ℂ)*(T x z*chi v x) := byunfold a b letter fz; rw [Finset.mul_sum,←Finset.sum_sub_distrib]exact Finset.sum_congr rfl fun x _ => byrw [chi_add']unfold W T f P A ante omegaObsringhave HI (y) : ‖b y-chi k y*a y‖^2 / m y ≤ G y := byhave HH : 0 ≤ m y := matter_nonneg h _rcases eq_or_lt_of_le HH with HH|HH· rw [←HH,div_zero]; exact Finset.sum_nonneg fun _ _ => mul_nonneg (hw _ _) (sq_nonneg _)apply (div_le_iff₀ HH).mprrw [H y]have hi (x : Grid M) :‖(W x y:ℂ)*(T x y*chi v x)‖= W x y* ‖T x y‖ := byrw [norm_scaleC,norm_mul,abs_of_nonneg (hw _ _),norm_chi,mul_one]apply le_trans (pow_le_pow_left₀ (norm_nonneg _) (norm_sum_le _ _) _)simp_rw [hi]have HX : m y=∑ x,W x y := rflrw [HX]; unfold Gapply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul _(fun i _ => mul_nonneg (hw _ _) (sq_nonneg _)) (fun i _ => hw _ _) (fun i _ => ?_)exact le_of_eq (by ring)have HB (x : Grid M) : ∑ y,P x y* ‖T x y‖^2=delta A k ^ 2 := bychange (channel A x).Ex _=_rw [ch_ex]have he (z) : T x (x+z)=chi k x *(1-chi k z) := by unfold T; rw [chi_add]; ringsimp_rw [he,norm_mul,norm_chi,one_mul]exact (sq_sqrt ((label A).Ex_nonneg fun i => sq_nonneg _)).symmhave HL : ∑ z,G z=share s*delta A k ^ 2 := byunfold G; rw [Finset.sum_comm]simp_rw [W,mul_assoc,← Finset.mul_sum,HB]rw [← Finset.sum_mul,ante_total _ h.ready.1]unfold energy energyZchange ∑ z, ‖a z‖^2/m z ≤ 2*(∑ z, ‖b z‖^2/m z)+2*(share s*_)rw [show dye s=A from rfl,←HL, Finset.mul_sum, Finset.mul_sum,← Finset.sum_add_distrib]apply Finset.sum_le_sum; intro z _have he : ‖a z‖ ≤ ‖b z‖+‖b z-chi k z*a z‖ := byhave H := norm_sub_le (b z) (b z-chi k z*a z)rw [sub_sub_cancel,norm_mul,norm_chi,one_mul] at H; exact Hhave hev : ‖a z‖^2 ≤ 2*‖b z‖^2+2*‖b z-chi k z*a z‖^2 := byhave H := pow_le_pow_left₀ (norm_nonneg _) he 2nlinarith [sq_nonneg (‖b z‖-‖b z-chi k z*a z‖)]apply le_trans (div_le_div_of_nonneg_right hev (matter_nonneg h _))rw [add_div,mul_div_assoc,mul_div_assoc]; linarith [HI z]lemma near_size :∀ᶠ j : ℕ in atTop,∀ i : ℕ, i ≤ mainIx j → sepRad j ≤ side i ∧ 256*sig j ≤ side i^2 := byfilter_upwards [h_large 1000] with j h i hilet a := Thermal.H jhave H : 1/a^16 ≤ side i :=le_trans (bottom_level j).ge (pow_le_pow_of_le_one (by norm_num) (by norm_num) hi)have hx : 1000 ≤ a := hhave hH : 1 ≤ a := by linarithchange 1/a^30 ≤ _ ∧ 256*(1/a^40) ≤ _constructor· apply le_trans _ H; gcongr; omega· apply le_trans (b:=(1/a^16)^2) _ (pow_le_pow_left₀ (by positivity) H 2)have hv : a ≤ a^8 := by simpa using pow_le_pow_right₀ hH (by omega : 1≤8)field_simp; nlinarithlemma node_compress {p q : Node} (h : p.below q) :p.len ≤ q.len := pow_le_pow_of_le_one (by norm_num) (by norm_num) h.1lemma halo_limit {p : Scene M} (s : Scene M) (j i : ℕ) (main : Bool) (d : Grid M)(hh : s.here.below p.here) (h : rad d ≤ 2*spotLimit p j i main) :s.here.len*rad d ≤ 2*tolerance j i main := bycalc_ ≤ p.here.len*(2*spotLimit p j i main) :=mul_le_mul (node_compress hh) h (rad_nonneg _) p.here.len_pos.le_ = _ := by rw [spotLimit,rinv]; field_simp [p.here.len_pos.ne']/-- Combining errors after activation. First main interval may use b=1, then inner always. -/lemma channel_inner :∀ᶠ j : ℕ in atTop, ∀ (i : ℕ), i ≤ mainIx j → ∀ (M : ℕ)(p q : Scene M), q.here.below p.here → dye q=dye p → Climb q →∀ u v k : Grid M, delta (dye p) k ≤ sepRad j →rad (u-v-k) ≤ 2*spotLimit p j i true →(0 < i → ¬ snag ⟨true,i-1⟩ u (⟨q,q,false⟩:Beat M)) →Run.Streak.innerV (rose ⟨true,i⟩ v) q := byfilter_upwards [near_size] with j hj i hI M p q h1 h2 h u v k hx hk hpby_cases hi : i=0· subst iapply Or.inr; intro blet s := q.smaller bapply ((energy_small (h.child b) v).2.trans (h.child b).lift).transchange (4:ℝ) ≤ 64*side 0^2; norm_num [side]let A := rose ⟨true,i⟩ vapply or_iff_not_imp_left.mprintro HHhave hf := hp (Nat.pos_of_ne_zero hi)have HV (b : Bool) : energy (q.smaller b) u ≤ (2*side i)^2 := byhave HH' : ¬ hazard q true (i-1) := fun hh => HH ⟨Nat.pos_of_ne_zero hi, hh⟩have Ht : energy (q.smaller b) u < side (i-1)^2 :=lt_of_not_ge fun hz => hf ⟨⟨b,hz⟩,HH'⟩have hc := side_succ (i-1)rw [Nat.sub_add_cancel (by omega : 1 ≤ i)] at hcrw [hc]; nlinarithintro blet s := q.smaller bhave hS : below s.here p.here := below_trans (child_below _ _) h1let x := side ihave HP := h.child bhave H : energy s (v+k) ≤ energy s u+4*(16*s.here.len*rad (v+k-u)) :=magnitude_near true s (v+k) u HP.ready HP.pos.le 4 HP.liftrw [show v+k-u= -(u-v-k) by ring,rad_even] at Hhave he₁ : s.here.len*rad (u-v-k) ≤ 2*sig j :=halo_limit s j i true _ hS hkhave hd := hj i hIhave he₂ : delta (dye s) k^2 ≤ side i^2 := bychange delta (dye q) k^2 ≤ _rw [h2]; exact pow_le_pow_left₀ (sqrt_nonneg _) (hx.trans hd.1) _change energy s v ≤ 64*side i^2have ht₁ : share s*delta (dye s) k^2 ≤ 4*(side i)^2 := byapply le_trans (mul_le_mul_of_nonneg_right HP.lift (sq_nonneg _)); nlinarithhave hT : energy s u ≤ (2*side i)^2 := HV bnlinarith [energy_near_channel s HP v k, hd.2]lemma gain_point {s : Scene M} (hp : Climb s)(u v x : Grid M) (hh : x∈s.here.block M) :‖gain s u-chi (u-v) x*gain s v‖ ≤ 32*(s.here.len*rad (u-v)) := bylet a B := scalar (s.smaller B) u- chi (u-v) x * scalar (s.smaller B) vlet k := s.here.len*rad (u-v)have H (b : Bool) : ‖a b‖ ≤ 32*k := byhave he := hp.child bapply (scalar_point _ u he.ready he.pos.le (child_below s.here b) x hh v).transrw [mul_assoc 8]nlinarith [show 0 ≤ k from mul_nonneg s.here.len_pos.le (rad_nonneg _),he.lift]rw [show gain s u-chi (u-v) x*gain s v=(a false-a true)/2 by unfold gain a; ring]apply (norm_halfcomplex _ _).trans; linarith [H false,H true]/-- big unlabelled coefficients force labelled high -/lemma scalar_energy (s : Scene M) (h : Fit s) (u) :‖scalar s u‖^2 ≤ 4*energy s u := byrw [scalar_label]apply le_trans (pow_le_pow_left₀ (norm_nonneg _) (norm_sum_le _ _) _)apply le_trans (b:=share s*energy s u)· rw [←matter_sum h,sun_energy h]apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul _ (fun i _ => matter_nonneg h _)(fun i _ => (sun_rays h _ _).1) (fun i _ => ?_)rw [← (mean_hold _ h _ _).1,norm_scaleC,abs_of_nonneg (matter_nonneg h _)]unfold sun; exact le_of_eq (by ring)exact mul_le_mul_of_nonneg_right h.lift (energy_small h u).1end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215import OAI.Analysis.FourierLLogL.Paths.Screen/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Plot/-- channel perturbation estimate. -/private lemma ray_channel (A : Form M) (f : Grid M → ℂ) (x : Grid M) :(channel A x).Cx f = (label A).Cx fun z => f (x+z) := byapply Complex.ext· rw [re_Cx,re_Cx,ch_ex]· have H (P : Law (Grid M)) (f) : (P.Cx f).im=P.Ex (fun i => (f i).im) := bysimp [Cx,Ex,Complex.im_sum]rw [H,H,ch_ex]lemma duet_decode (s : Scene M) (v k : Grid M) :∑ z, chi k z*letter s v z = (cred (dye s) k:ℂ)*scalar s (v+k) := bylet A := dye slet L := channel Ahave HE (x : Grid M) :∑ z, (L x z:ℂ)*chi k z=chi k x*(cred A k:ℂ) := bychange (channel A x).Cx _=_rw [ray_channel,cred_eq]simp_rw [chi_add,Cx_lmul]unfold letter fz scalar; unfold omegaObssimp_rw [Finset.mul_sum]rw [Finset.sum_comm]apply Finset.sum_congr rfl; intro i _let p : ℂ := ante s icalc_ = p*chi v i*∑ z,(L i z:ℂ)*chi k z := byrw [Finset.mul_sum]exact Finset.sum_congr rfl fun z _ => by unfold L p A ante; push_cast; ring_ = _ := by rw [HE i,chi_add']; unfold p ante A; ringlemma gain_decode (s : Scene M) (v k : Grid M) :∑ z, chi k z*factor s v z = (cred (dye s) k:ℂ)*gain s (v+k) := byunfold factorsimp_rw [← mul_div_assoc,mul_sub]; rw [←Finset.sum_div,Finset.sum_sub_distrib,duet_decode,duet_decode,gain]simp only [dye,smaller]; ringlemma energy_near_channel (s : Scene M) (h : Fit s) (v k : Grid M) :energy s v ≤ 2*energy s (v+k)+2*(share s*delta (dye s) k^2) := bylet A := dye s; let P := channel A; let f := ante slet W (x y : Grid M) := f x * P x ylet a := letter s v; let b := letter s (v+k)let m := matter slet T (x y : Grid M) := chi k x-chi k ylet G (y : Grid M) := ∑ i,W i y* ‖T i y‖^2have hw (x y) : 0 ≤ W x y := mul_nonneg (ante_nonneg _ h.ready.2 h.pos.le _) ((P x).nonneg _)have H (z : Grid M) :b z-chi k z*a z = ∑ x, (W x z:ℂ)*(T x z*chi v x) := byunfold a b letter fz; rw [Finset.mul_sum,←Finset.sum_sub_distrib]exact Finset.sum_congr rfl fun x _ => byrw [chi_add']unfold W T f P A ante omegaObsringhave HI (y) : ‖b y-chi k y*a y‖^2 / m y ≤ G y := byhave HH : 0 ≤ m y := matter_nonneg h _rcases eq_or_lt_of_le HH with HH|HH· rw [←HH,div_zero]; exact Finset.sum_nonneg fun _ _ => mul_nonneg (hw _ _) (sq_nonneg _)apply (div_le_iff₀ HH).mprrw [H y]have hi (x : Grid M) :‖(W x y:ℂ)*(T x y*chi v x)‖= W x y* ‖T x y‖ := byrw [norm_scaleC,norm_mul,abs_of_nonneg (hw _ _),norm_chi,mul_one]apply le_trans (pow_le_pow_left₀ (norm_nonneg _) (norm_sum_le _ _) _)simp_rw [hi]have HX : m y=∑ x,W x y := rflrw [HX]; unfold Gapply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul _(fun i _ => mul_nonneg (hw _ _) (sq_nonneg _)) (fun i _ => hw _ _) (fun i _ => ?_)exact le_of_eq (by ring)have HB (x : Grid M) : ∑ y,P x y* ‖T x y‖^2=delta A k ^ 2 := bychange (channel A x).Ex _=_rw [ch_ex]have he (z) : T x (x+z)=chi k x *(1-chi k z) := by unfold T; rw [chi_add]; ringsimp_rw [he,norm_mul,norm_chi,one_mul]exact (sq_sqrt ((label A).Ex_nonneg fun i => sq_nonneg _)).symmhave HL : ∑ z,G z=share s*delta A k ^ 2 := byunfold G; rw [Finset.sum_comm]simp_rw [W,mul_assoc,← Finset.mul_sum,HB]rw [← Finset.sum_mul,ante_total _ h.ready.1]unfold energy energyZchange ∑ z, ‖a z‖^2/m z ≤ 2*(∑ z, ‖b z‖^2/m z)+2*(share s*_)rw [show dye s=A from rfl,←HL, Finset.mul_sum, Finset.mul_sum,← Finset.sum_add_distrib]apply Finset.sum_le_sum; intro z _have he : ‖a z‖ ≤ ‖b z‖+‖b z-chi k z*a z‖ := byhave H := norm_sub_le (b z) (b z-chi k z*a z)rw [sub_sub_cancel,norm_mul,norm_chi,one_mul] at H; exact Hhave hev : ‖a z‖^2 ≤ 2*‖b z‖^2+2*‖b z-chi k z*a z‖^2 := byhave H := pow_le_pow_left₀ (norm_nonneg _) he 2nlinarith [sq_nonneg (‖b z‖-‖b z-chi k z*a z‖)]apply le_trans (div_le_div_of_nonneg_right hev (matter_nonneg h _))rw [add_div,mul_div_assoc,mul_div_assoc]; linarith [HI z]lemma near_size :∀ᶠ j : ℕ in atTop,∀ i : ℕ, i ≤ mainIx j → sepRad j ≤ side i ∧ 256*sig j ≤ side i^2 := byfilter_upwards [h_large 1000] with j h i hilet a := Thermal.H jhave H : 1/a^16 ≤ side i :=le_trans (bottom_level j).ge (pow_le_pow_of_le_one (by norm_num) (by norm_num) hi)have hx : 1000 ≤ a := hhave hH : 1 ≤ a := by linarithchange 1/a^30 ≤ _ ∧ 256*(1/a^40) ≤ _constructor· apply le_trans _ H; gcongr; omega· apply le_trans (b:=(1/a^16)^2) _ (pow_le_pow_left₀ (by positivity) H 2)have hv : a ≤ a^8 := by simpa using pow_le_pow_right₀ hH (by omega : 1≤8)field_simp; nlinarithlemma node_compress {p q : Node} (h : p.below q) :p.len ≤ q.len := pow_le_pow_of_le_one (by norm_num) (by norm_num) h.1lemma halo_limit {p : Scene M} (s : Scene M) (j i : ℕ) (main : Bool) (d : Grid M)(hh : s.here.below p.here) (h : rad d ≤ 2*spotLimit p j i main) :s.here.len*rad d ≤ 2*tolerance j i main := bycalc_ ≤ p.here.len*(2*spotLimit p j i main) :=mul_le_mul (node_compress hh) h (rad_nonneg _) p.here.len_pos.le_ = _ := by rw [spotLimit,rinv]; field_simp [p.here.len_pos.ne']/-- Combining errors after activation. First main interval may use b=1, then inner always. -/lemma channel_inner :∀ᶠ j : ℕ in atTop, ∀ (i : ℕ), i ≤ mainIx j → ∀ (M : ℕ)(p q : Scene M), q.here.below p.here → dye q=dye p → Climb q →∀ u v k : Grid M, delta (dye p) k ≤ sepRad j →rad (u-v-k) ≤ 2*spotLimit p j i true →(0 < i → ¬ snag ⟨true,i-1⟩ u (⟨q,q,false⟩:Beat M)) →Run.Streak.innerV (rose ⟨true,i⟩ v) q := byfilter_upwards [near_size] with j hj i hI M p q h1 h2 h u v k hx hk hpby_cases hi : i=0· subst iapply Or.inr; intro blet s := q.smaller bapply ((energy_small (h.child b) v).2.trans (h.child b).lift).transchange (4:ℝ) ≤ 64*side 0^2; norm_num [side]let A := rose ⟨true,i⟩ vapply or_iff_not_imp_left.mprintro HHhave hf := hp (Nat.pos_of_ne_zero hi)have HV (b : Bool) : energy (q.smaller b) u ≤ (2*side i)^2 := byhave HH' : ¬ hazard q true (i-1) := fun hh => HH ⟨Nat.pos_of_ne_zero hi, hh⟩have Ht : energy (q.smaller b) u < side (i-1)^2 :=lt_of_not_ge fun hz => hf ⟨⟨b,hz⟩,HH'⟩have hc := side_succ (i-1)rw [Nat.sub_add_cancel (by omega : 1 ≤ i)] at hcrw [hc]; nlinarithintro blet s := q.smaller bhave hS : below s.here p.here := below_trans (child_below _ _) h1let x := side ihave HP := h.child bhave H : energy s (v+k) ≤ energy s u+4*(16*s.here.len*rad (v+k-u)) :=magnitude_near true s (v+k) u HP.ready HP.pos.le 4 HP.liftrw [show v+k-u= -(u-v-k) by ring,rad_even] at Hhave he₁ : s.here.len*rad (u-v-k) ≤ 2*sig j :=halo_limit s j i true _ hS hkhave hd := hj i hIhave he₂ : delta (dye s) k^2 ≤ side i^2 := bychange delta (dye q) k^2 ≤ _rw [h2]; exact pow_le_pow_left₀ (sqrt_nonneg _) (hx.trans hd.1) _change energy s v ≤ 64*side i^2have ht₁ : share s*delta (dye s) k^2 ≤ 4*(side i)^2 := byapply le_trans (mul_le_mul_of_nonneg_right HP.lift (sq_nonneg _)); nlinarithhave hT : energy s u ≤ (2*side i)^2 := HV bnlinarith [energy_near_channel s HP v k, hd.2]lemma gain_point {s : Scene M} (hp : Climb s)(u v x : Grid M) (hh : x∈s.here.block M) :‖gain s u-chi (u-v) x*gain s v‖ ≤ 32*(s.here.len*rad (u-v)) := bylet a B := scalar (s.smaller B) u- chi (u-v) x * scalar (s.smaller B) vlet k := s.here.len*rad (u-v)have H (b : Bool) : ‖a b‖ ≤ 32*k := byhave he := hp.child bapply (scalar_point _ u he.ready he.pos.le (child_below s.here b) x hh v).transrw [mul_assoc 8]nlinarith [show 0 ≤ k from mul_nonneg s.here.len_pos.le (rad_nonneg _),he.lift]rw [show gain s u-chi (u-v) x*gain s v=(a false-a true)/2 by unfold gain a; ring]apply (norm_halfcomplex _ _).trans; linarith [H false,H true]/-- big unlabelled coefficients force labelled high -/lemma scalar_energy (s : Scene M) (h : Fit s) (u) :‖scalar s u‖^2 ≤ 4*energy s u := byrw [scalar_label]apply le_trans (pow_le_pow_left₀ (norm_nonneg _) (norm_sum_le _ _) _)apply le_trans (b:=share s*energy s u)· rw [←matter_sum h,sun_energy h]apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul _ (fun i _ => matter_nonneg h _)(fun i _ => (sun_rays h _ _).1) (fun i _ => ?_)rw [← (mean_hold _ h _ _).1,norm_scaleC,abs_of_nonneg (matter_nonneg h _)]unfold sun; exact le_of_eq (by ring)exact mul_le_mul_of_nonneg_right h.lift (energy_small h u).1end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import OAI.Analysis.FourierLLogL.Assembly.Phase/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupelemma blend (l : Path M) {E : Type*} [AddCommMonoid E] (f g : Beat M → E) :subtotal (fun b => f b+g b) l = subtotal f l + subtotal g l := byinduction l with| nil => change 0=0+(0:E); simp| cons b l ih => simp only [subtotal_cons,ih]; ac_rfllemma subtC (l : Path M) (f : Beat M → ℂ) (c : ℂ) :subtotal (fun b => c*f b) l=c*subtotal f l := byinduction l with| nil => change 0=c*0; simp| cons b l ih => rw [subtotal_cons,subtotal_cons,ih,mul_add]lemma subtR (l : Path M) (f : Beat M → ℝ) (c : ℝ) :subtotal (fun b => c*f b) l=c*subtotal f l := byinduction l with| nil => change 0=c*0; simp| cons b l ih => rw [subtotal_cons,subtotal_cons,ih,mul_add]lemma subt_constant (l : Path M) (c : ℝ) :subtotal (fun _ => c) l = c*l.length := byinduction l with| nil => simp [subtotal]| cons b l ih => rw [subtotal_cons,List.length_cons,ih]; push_cast; ringlemma subt_neg (l : Path M) (f g : Beat M → ℂ) :subtotal f l-subtotal g l=subtotal (fun b => f b-g b) l := byinduction l with| nil => simp [subtotal]| cons b l ih => rw [subtotal_cons,subtotal_cons,subtotal_cons,← ih]; abellemma subt_norm (l : Path M) (f : Beat M → ℂ) :‖subtotal f l‖ ≤ subtotal (fun b => ‖f b‖) l := byinduction l with| nil => change ‖(0:ℂ)‖ ≤ 0; simp| cons b l ih => exact (norm_add_le (f b) _).trans (add_le_add_right ih _)lemma trip_attend {x : Grid M} {l : Path M} (h : Trip x s l) :∀ b∈l, Ideal b.pre b.post ∧ x∈b.post.here.block M ∧ |blow x b|=1 ∧b.post.here.below s.here ∧ dye b.post=dye s := byinduction l generalizing s with| nil => simp| cons b l ih =>intro z hzrcases List.mem_cons.mp hz with rfl|hz· refine ⟨h.2.1,?_,trip_final h,?_,?_⟩· exact block_of_below (child_below _ _) _ (trip_head h.2.2).2· rw [h.2.1.lower.here,h.1]; exact below_refl _rw [dye,h.2.1.lower.fund,h.1]; rflobtain ⟨hp,hj,hi,h₁,h₂⟩ := ih h.2.2 z hzrefine ⟨hp,hj,hi,?_,?_⟩· rw [← h.1,← h.2.1.lower.here]; exact below_trans h₁ (child_below _ _)change dye z.post=dye b.post at h₂; rw [h₂,dye,h.2.1.lower.fund,h.1]; rfldef spaceRent (b : Beat M) := b.post.here.lenlemma length_fee {x : Grid M} {l : Path M} (h : Trip x s l) :subtotal spaceRent l ≤ 2*s.here.len := byinduction l generalizing s with| nil => change 0 ≤ 2*_; exact mul_nonneg (by norm_num) s.here.len_pos.le| cons b l ih =>have H := ih h.2.2rw [show (winds b).here.len=b.post.here.len/2 from child_len _ b.bit] at Hrw [←h.1,←h.2.1.lower.here]change b.post.here.len+subtotal spaceRent l ≤ _linarithdef aired (m : Beat M → Prop) (x u : Grid M) (b : Beat M) :=if m b then proceeds x u b else 0lemma rail_fee {x : Grid M} (u v : Grid M) (μ : Beat M → Prop) (p l r : Path M)(h : Trip x s (p++(l++r))) :‖subtotal (aired μ x u) l-chi (u-v) x*subtotal (aired μ x v) l‖ ≤64*s.here.len*rad (u-v) := byrw [← subtC,subt_neg]let F (b : Beat M) := aired μ x u b-chi (u-v) x * aired μ x v bapply (subt_norm l F).transhave ht := trip_cut hobtain ⟨hs,w,hk⟩ := htobtain ⟨hL,t,hT⟩ := trip_cut hkhave HH : subtotal (fun b => ‖F b‖) l ≤ subtotal (fun b => 32*rad (u-v)*spaceRent b) l := bysuffices HX : ∀ l s, Trip x s l → subtotal (fun b => ‖F b‖) l ≤subtotal (fun b => 32*rad (u-v)*spaceRent b) l from HX _ w hLintro l; induction l with| nil => intro s h; exact le_rfl| cons b l ih =>intro s Hrw [subtotal_cons,subtotal_cons]apply add_le_add _ (ih (winds b) H.2.2)unfold F aired; split_ifs· rw [proceeds,proceeds,mul_left_comm,← mul_sub,norm_scaleC,trip_final H,one_mul]have HC := (trip_attend H b List.mem_cons_self)exact (gain_point H.2.1.climb u v x HC.2.1).trans (le_of_eq (by unfold spaceRent; ring))· simp; exact mul_nonneg (mul_nonneg (by norm_num) (rad_nonneg _)) b.post.here.len_pos.leapply HH.transrw [subtR]have hp' : subtotal spaceRent l ≤ 2*s.here.len := byhave HH := length_fee hsimp_rw [subtotal_app] at HHlinarith [trip_nonneg hs (f:=spaceRent) (fun b _ => b.post.here.len_pos.le),trip_nonneg hT (f:=spaceRent) (fun b _ => b.post.here.len_pos.le)]nlinarith [rad_nonneg (u-v)]lemma straight_fee {x : Grid M} (u : Grid M) (l : Path M)(h : Trip x s l) :‖subtotal (proceeds x u) l‖ ≤ 4*l.length := byinduction l generalizing s with| nil => change ‖(0:ℂ)‖ ≤ 4*(↑([]:Path M).length:ℝ); simp| cons b l ih =>rw [subtotal_cons,List.length_cons]; push_castapply (norm_add_le _ _).transhave he := h.2.1.climbrw [proceeds,norm_scaleC,trip_final h,one_mul]linarith [(gain_norm he u).trans he.fit.lift,ih h.2.2]lemma decode_track (l : Path M) (x v k : Grid M) {s : Scene M}(h : Trip x s l) :let w := subtotal (duties x v) l∑ z,chi k z*w z=(cred (dye s) k:ℂ)*subtotal (proceeds x (v+k)) l := byinduction l generalizing s with| nil => simp [subtotal]| cons b l ih =>have H := gain_decode b.post v klet C : ℂ := cred (dye b.post) khave HH := ih h.2.2intro whave hr : dye b.post=dye s := (trip_attend h b List.mem_cons_self).2.2.2.2rw [←hr]let t := duties x v b; let u := subtotal (duties x v) lhave hw (z) : w z=t z+u z := rflsimp_rw [hw,mul_add,Finset.sum_add_distrib]rw [subtotal_cons,mul_add]congr 1· unfold t duties; simp_rw [mul_left_comm (chi k _),←Finset.mul_sum]rw [H]; unfold proceeds; ringlemma below_decode (u v k x : Grid M) (A : Form M) (p l r : Path M)(h : Trip x s (p++(l++r))) (hx : A=dye s)(hh : delta A k ≤ 1) :‖subtotal (proceeds x u) l‖ ≤2*Beam.yieldW (subtotal (duties x v) l)+64*s.here.len*rad (u-v-k) := byobtain ⟨_,q,h₁⟩ := trip_cut hobtain ⟨hp,d,h₂⟩ := trip_cut h₁let a := v+klet f := subtotal (proceeds x a) l; let W := subtotal (duties x v) lhave HI : ‖f‖ ≤ 2*Beam.yieldW W := byby_cases ht : l=[]· unfold f W; rw [ht,subtotal_nil,subtotal_nil,norm_zero,Beam.yield_zero]; norm_numhave hz := decode_track l x v k hphave HV : dye q=A := byobtain ⟨b,hb⟩ := List.exists_mem_of_ne_nil _ hthave hT : b∈p++(l++r) := by simp [hb]rw [← (trip_attend hp b hb).2.2.2.2, (trip_attend h b hT).2.2.2.2,hx]change ∑ z,chi k z*W z=(cred (dye q) k:ℂ)*f at hzrw [HV] at hzhave hC : 1/2 ≤ cred A k := bynlinarith [delta_sq A k,show 0 ≤ delta A k from sqrt_nonneg _]have H : ‖(↑(cred A k):ℂ)*f‖ ≤ Beam.yieldW W := byrw [← hz]exact (norm_sum_le _ _).trans (by simp only [norm_mul,norm_chi,one_mul]; exact le_rfl)rw [norm_scaleC,abs_of_nonneg (by linarith)] at Hnlinarith [norm_nonneg f]have he := rail_fee u a (fun _ => True) p l r hhave hA (v) : aired (fun _ => True) x v=proceeds x v := by funext b; simp [aired]rw [hA,hA] at helet f' := subtotal (proceeds x u) lhave HH : ‖f'‖ ≤ ‖f'-chi (u-a) x*f‖ + ‖f‖ := byhave H := norm_add_le (f'-chi (u-a) x*f) (chi (u-a) x*f)rwa [sub_add_cancel,norm_mul,norm_chi,one_mul] at Hrw [show u-v-k=u-a by unfold a; ring]change ‖f'-chi (u-a) x*f‖ ≤ _ at hechange ‖f'‖ ≤ 2*Beam.yieldW W+_linarithend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import OAI.Analysis.FourierLLogL.Assembly.Phase/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupelemma blend (l : Path M) {E : Type*} [AddCommMonoid E] (f g : Beat M → E) :subtotal (fun b => f b+g b) l = subtotal f l + subtotal g l := byinduction l with| nil => change 0=0+(0:E); simp| cons b l ih => simp only [subtotal_cons,ih]; ac_rfllemma subtC (l : Path M) (f : Beat M → ℂ) (c : ℂ) :subtotal (fun b => c*f b) l=c*subtotal f l := byinduction l with| nil => change 0=c*0; simp| cons b l ih => rw [subtotal_cons,subtotal_cons,ih,mul_add]lemma subtR (l : Path M) (f : Beat M → ℝ) (c : ℝ) :subtotal (fun b => c*f b) l=c*subtotal f l := byinduction l with| nil => change 0=c*0; simp| cons b l ih => rw [subtotal_cons,subtotal_cons,ih,mul_add]lemma subt_constant (l : Path M) (c : ℝ) :subtotal (fun _ => c) l = c*l.length := byinduction l with| nil => simp [subtotal]| cons b l ih => rw [subtotal_cons,List.length_cons,ih]; push_cast; ringlemma subt_neg (l : Path M) (f g : Beat M → ℂ) :subtotal f l-subtotal g l=subtotal (fun b => f b-g b) l := byinduction l with| nil => simp [subtotal]| cons b l ih => rw [subtotal_cons,subtotal_cons,subtotal_cons,← ih]; abellemma subt_norm (l : Path M) (f : Beat M → ℂ) :‖subtotal f l‖ ≤ subtotal (fun b => ‖f b‖) l := byinduction l with| nil => change ‖(0:ℂ)‖ ≤ 0; simp| cons b l ih => exact (norm_add_le (f b) _).trans (add_le_add_right ih _)lemma trip_attend {x : Grid M} {l : Path M} (h : Trip x s l) :∀ b∈l, Ideal b.pre b.post ∧ x∈b.post.here.block M ∧ |blow x b|=1 ∧b.post.here.below s.here ∧ dye b.post=dye s := byinduction l generalizing s with| nil => simp| cons b l ih =>intro z hzrcases List.mem_cons.mp hz with rfl|hz· refine ⟨h.2.1,?_,trip_final h,?_,?_⟩· exact block_of_below (child_below _ _) _ (trip_head h.2.2).2· rw [h.2.1.lower.here,h.1]; exact below_refl _rw [dye,h.2.1.lower.fund,h.1]; rflobtain ⟨hp,hj,hi,h₁,h₂⟩ := ih h.2.2 z hzrefine ⟨hp,hj,hi,?_,?_⟩· rw [← h.1,← h.2.1.lower.here]; exact below_trans h₁ (child_below _ _)change dye z.post=dye b.post at h₂; rw [h₂,dye,h.2.1.lower.fund,h.1]; rfldef spaceRent (b : Beat M) := b.post.here.lenlemma length_fee {x : Grid M} {l : Path M} (h : Trip x s l) :subtotal spaceRent l ≤ 2*s.here.len := byinduction l generalizing s with| nil => change 0 ≤ 2*_; exact mul_nonneg (by norm_num) s.here.len_pos.le| cons b l ih =>have H := ih h.2.2rw [show (winds b).here.len=b.post.here.len/2 from child_len _ b.bit] at Hrw [←h.1,←h.2.1.lower.here]change b.post.here.len+subtotal spaceRent l ≤ _linarithdef aired (m : Beat M → Prop) (x u : Grid M) (b : Beat M) :=if m b then proceeds x u b else 0lemma rail_fee {x : Grid M} (u v : Grid M) (μ : Beat M → Prop) (p l r : Path M)(h : Trip x s (p++(l++r))) :‖subtotal (aired μ x u) l-chi (u-v) x*subtotal (aired μ x v) l‖ ≤64*s.here.len*rad (u-v) := byrw [← subtC,subt_neg]let F (b : Beat M) := aired μ x u b-chi (u-v) x * aired μ x v bapply (subt_norm l F).transhave ht := trip_cut hobtain ⟨hs,w,hk⟩ := htobtain ⟨hL,t,hT⟩ := trip_cut hkhave HH : subtotal (fun b => ‖F b‖) l ≤ subtotal (fun b => 32*rad (u-v)*spaceRent b) l := bysuffices HX : ∀ l s, Trip x s l → subtotal (fun b => ‖F b‖) l ≤subtotal (fun b => 32*rad (u-v)*spaceRent b) l from HX _ w hLintro l; induction l with| nil => intro s h; exact le_rfl| cons b l ih =>intro s Hrw [subtotal_cons,subtotal_cons]apply add_le_add _ (ih (winds b) H.2.2)unfold F aired; split_ifs· rw [proceeds,proceeds,mul_left_comm,← mul_sub,norm_scaleC,trip_final H,one_mul]have HC := (trip_attend H b List.mem_cons_self)exact (gain_point H.2.1.climb u v x HC.2.1).trans (le_of_eq (by unfold spaceRent; ring))· simp; exact mul_nonneg (mul_nonneg (by norm_num) (rad_nonneg _)) b.post.here.len_pos.leapply HH.transrw [subtR]have hp' : subtotal spaceRent l ≤ 2*s.here.len := byhave HH := length_fee hsimp_rw [subtotal_app] at HHlinarith [trip_nonneg hs (f:=spaceRent) (fun b _ => b.post.here.len_pos.le),trip_nonneg hT (f:=spaceRent) (fun b _ => b.post.here.len_pos.le)]nlinarith [rad_nonneg (u-v)]lemma straight_fee {x : Grid M} (u : Grid M) (l : Path M)(h : Trip x s l) :‖subtotal (proceeds x u) l‖ ≤ 4*l.length := byinduction l generalizing s with| nil => change ‖(0:ℂ)‖ ≤ 4*(↑([]:Path M).length:ℝ); simp| cons b l ih =>rw [subtotal_cons,List.length_cons]; push_castapply (norm_add_le _ _).transhave he := h.2.1.climbrw [proceeds,norm_scaleC,trip_final h,one_mul]linarith [(gain_norm he u).trans he.fit.lift,ih h.2.2]lemma decode_track (l : Path M) (x v k : Grid M) {s : Scene M}(h : Trip x s l) :let w := subtotal (duties x v) l∑ z,chi k z*w z=(cred (dye s) k:ℂ)*subtotal (proceeds x (v+k)) l := byinduction l generalizing s with| nil => simp [subtotal]| cons b l ih =>have H := gain_decode b.post v klet C : ℂ := cred (dye b.post) khave HH := ih h.2.2intro whave hr : dye b.post=dye s := (trip_attend h b List.mem_cons_self).2.2.2.2rw [←hr]let t := duties x v b; let u := subtotal (duties x v) lhave hw (z) : w z=t z+u z := rflsimp_rw [hw,mul_add,Finset.sum_add_distrib]rw [subtotal_cons,mul_add]congr 1· unfold t duties; simp_rw [mul_left_comm (chi k _),←Finset.mul_sum]rw [H]; unfold proceeds; ringlemma below_decode (u v k x : Grid M) (A : Form M) (p l r : Path M)(h : Trip x s (p++(l++r))) (hx : A=dye s)(hh : delta A k ≤ 1) :‖subtotal (proceeds x u) l‖ ≤2*Beam.yieldW (subtotal (duties x v) l)+64*s.here.len*rad (u-v-k) := byobtain ⟨_,q,h₁⟩ := trip_cut hobtain ⟨hp,d,h₂⟩ := trip_cut h₁let a := v+klet f := subtotal (proceeds x a) l; let W := subtotal (duties x v) lhave HI : ‖f‖ ≤ 2*Beam.yieldW W := byby_cases ht : l=[]· unfold f W; rw [ht,subtotal_nil,subtotal_nil,norm_zero,Beam.yield_zero]; norm_numhave hz := decode_track l x v k hphave HV : dye q=A := byobtain ⟨b,hb⟩ := List.exists_mem_of_ne_nil _ hthave hT : b∈p++(l++r) := by simp [hb]rw [← (trip_attend hp b hb).2.2.2.2, (trip_attend h b hT).2.2.2.2,hx]change ∑ z,chi k z*W z=(cred (dye q) k:ℂ)*f at hzrw [HV] at hzhave hC : 1/2 ≤ cred A k := bynlinarith [delta_sq A k,show 0 ≤ delta A k from sqrt_nonneg _]have H : ‖(↑(cred A k):ℂ)*f‖ ≤ Beam.yieldW W := byrw [← hz]exact (norm_sum_le _ _).trans (by simp only [norm_mul,norm_chi,one_mul]; exact le_rfl)rw [norm_scaleC,abs_of_nonneg (by linarith)] at Hnlinarith [norm_nonneg f]have he := rail_fee u a (fun _ => True) p l r hhave hA (v) : aired (fun _ => True) x v=proceeds x v := by funext b; simp [aired]rw [hA,hA] at helet f' := subtotal (proceeds x u) lhave HH : ‖f'‖ ≤ ‖f'-chi (u-a) x*f‖ + ‖f‖ := byhave H := norm_add_le (f'-chi (u-a) x*f) (chi (u-a) x*f)rwa [sub_add_cancel,norm_mul,norm_chi,one_mul] at Hrw [show u-v-k=u-a by unfold a; ring]change ‖f'-chi (u-a) x*f‖ ≤ _ at hechange ‖f'‖ ≤ 2*Beam.yieldW W+_linarithend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182import OAI.Analysis.FourierLLogL.Assembly.Series/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Run Streakdef parody (s : Scene M) (i : ℕ) := (rose (tagM i) (0:Grid M)).flag sdef stampAux (s : Scene M) (j : ℕ) :=4*parody s (mainIx j+1)+10^20*(fax s+(∑ i∈Finset.Ico 0 (mainIx j+1), parody s i / depthRate i))def stamp (s : Scene M) (j : ℕ) := 512*mutedR s j true + stampAux s jlemma stamp_nonneg {s : Scene M} (h : Climb s) (j : ℕ) : 0 ≤ stamp s j := byunfold stamp stampAuxhave H := surcharge_nonneg s false (priciest s j true)have HH (i : ℕ) : 0 ≤ parody s i := flag_nonneg _ _have HP : 0 ≤ ∑ i∈Finset.Ico 0 (mainIx j+1), parody s i / depthRate i :=Finset.sum_nonneg (fun _ _ => div_nonneg (HH _) (rate_easy _).1.le)unfold mutedRlinarith [(fax_floor h).1,HH (mainIx j+1)]private lemma chamber_fee (c j) (L : Path M) :tokenCost j c L + crumb (lowI j c) (highI j M c) j L =rooms c j L+512*subtotal (fun b => mutedR b.post j c) L+(if c then 4*(subtotal (special j) L+(billWait (tagM (mainIx j)) j L:ℝ)) else 0) := byunfold tokenCost crumb rooms miniStage playsLrw [Finset.sum_add_distrib,← Finset.mul_sum]ringlemma receipt_main (j : ℕ) (L : Path M) :souvenir true j L=rooms true j L+palaces j L + subtotal (fun b => stamp b.post j) L := bysimp only [souvenir,chamber_fee]simp only [↓reduceIte]unfold palaces stamp stampAux bigCrumbsimp_rw [blend _ (f:=fun _ => _) (g:=fun _ => _),subtR]let m := Finset.Ico 0 (mainIx j+1)let F (b : Beat M) (i : ℕ) := parody b.post i / depthRate ihave H (i : ℕ) : mainSticker i j L = nakedStage i j L + subtotal (fun b => F b i) L := byunfold F mainSticker nakedStage mainRatio parody flaggedsimp_rw [div_eq_mul_inv,mul_comm _ (depthRate i)⁻¹,subtR]ringsimp_rw [H,Finset.sum_add_distrib]have HH := cross_subtotal L m Funfold F m at HHrw [blend L (fun b => fax b.post),HH]; unfold Frw [show subtotal (fun b => fax b.post) L=fullFax L from rfl]have HV : special j = fun b : Beat M => parody b.post (mainIx j+1) := rflrw [HV]linarithlemma receipt_static (j : ℕ) (L : Path M) :souvenir false j L=rooms false j L+512*subtotal (fun b => mutedR b.post j false) L := bysimp only [souvenir,chamber_fee]; simpdef gateTax (s : Scene M) (j : ℕ) :=if s.live then 10^140*height j/Thermal.H j else 10^140*amount s jlemma tax_pos (s : Scene M) (j : ℕ) : 0 ≤ gateTax s j := byhave := d_pos j; have := H_pos j; have HA := (amount_limits s j).1unfold gateTax; split <;> positivitylemma receipt_paid :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ s : Scene M, ∀ t : Thread M s, ∀ f : Grid M → ℝ,t.Following j J f → Fit s → entry s →(s.live=true → exp (-height j) ≤ s.norm) →(∀ x, f x ≤ exp (height j)) →stats t (souvenir s.live j) ≤ gateTax s j +(if s.live then stats t (subtotal (fun b => stamp b.post j)) else 0) := byfilter_upwards [rooms_fee,palaces_fee,segment_cost,hpoly 1 1] with j hr hp hv hTM J s t f h hh hx he hflet d := height jlet k := amount s j; let v := Thermal.H jhave hV : 1 ≤ v := H_ge _have hk : 1 ≤ k := (amount_limits _ _).1have hd : 1 ≤ d := one_le_pow₀ (by norm_num)have HG := stats_plus thave HS := hr M J s f t h hh hx hfunfold gateTaxsplit· rename_i hEhave Ht := HS truehave HH := hp M J s f t h hh hx hE (he hE) hfhave hK : k ≤ 4*d := byhave H := log_le_log (exp_pos _) (he hE)rw [log_exp] at Hchange d+max _ 0+2 ≤ _have he' : max (-log s.norm) 0 ≤ d := max_le (by unfold d; linarith) (by linarith)linarithrw [hE]rw [show souvenir (M:=M) true j=fun L => rooms true j L+palaces j L+subtotal (fun b => stamp b.post j) L from funext (receipt_main _)]rw [HG (f:=fun L => _),HG (f:=fun L => _)]have heq : lowI j true=mainIx j := rflrw [heq,depth_at_main] at Hthave hi : 0 < v := H_pos jhave HE : 1/v^8 ≤ 1/v := one_div_le_one_div_of_le hi(by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 8))have HT : 1+10^30*(1/v^8)*k ≤ 10^31*(d/v) := byhave hΦ : 1 ≤ d/v := (one_le_div hi).mpr (by simpa using hT)have hh := mul_le_mul HE hK (by positivity) (by positivity)rw [show 1/v*(4*d)=4*(d/v) by ring] at hh; nlinarithchange stats t _ ≤ 1+10^30*(1/v^8)*k at Htunfold v d at *nlinarith [show 0 ≤ height j/Thermal.H j by have := H_pos j; have := d_pos j; positivity,show 10^140*height j/Thermal.H j=10^140*(height j/Thermal.H j) by ring,show 10^120*height j/Thermal.H j=10^120*(height j/Thermal.H j) by ring]· rename_i hEhave Ht := HS falserw [show lowI j false=0 from rfl,show depthRate 0=1 by simp [depthRate,side]] at Hthave HM := hv M J s f t h hf (show 0 < s.mass from hx ▸ hh.pos) hh.pos (fun q => priciest q j false) falserw [show s.mass/s.norm=1 from entry_share hh hx, one_mul] at HMrw [show s.live=false from Bool.eq_false_iff.mpr hE]simp only [add_zero]rw [show souvenir (M:=M) false j =fun L => rooms false j L+512* subtotal (fun b => mutedR b.post j false) L from funext (receipt_static _)]change stats t _ ≤ _*krw [HG]have HE : stats t (fun L => 512*subtotal (fun b => mutedR b.post j false) L) =512* t.fee (fun b => mutedR b.post j false) :=Ex_lmul (s.here.dice M) _ 512rw [HE]change _≤ 1+_*_*k at Hthave hp : height j ≤ k := (amount_limits _ _).2have hh0 : -log s.mass ≤ k := by unfold entry at hx; rw [← hx]; unfold k amount; linarith [le_max_left (-log s.norm) 0,d_pos j]unfold mutedR; linarith/-- pointwise price comparison for expected flags. -/lemma parody_fee (s : Scene M) (j : ℕ) (i : ℕ) (h : i ≤ mainIx j+1) :parody s i ≤ 10^6*Thermal.H j^32*surcharge s true (i-1) := byhave hE : 0 < Thermal.H j := H_pos _by_cases he : (rose (tagM i) (0:Grid M)).rogue s· have hx := he.1have hp : 0 < i := hxhave HH := he.2have HC := (bottom_level j)have HT : side (mainIx j) ≤ side (i-1) :=side_ant _ _ (by omega)rw [HC] at HTchange hazard s true (i-1) at HHrw [show parody s i=1 from ite_eq_left he,surcharge,ite_eq_left HH]change side (i-1)^2/128 ≤ _ at HHlet v := Thermal.H jhave Hb : 1/v^32/128 ≤ edgeW s (i-1) := byhave Hi : 0 ≤ 1/(Thermal.H j)^16 := by positivityapply le_trans _ HHhave HT := div_le_div_of_nonneg_right (pow_le_pow_left₀ Hi HT 2) (by norm_num : (0:ℝ)≤128)rw [show (1/Thermal.H j^16)^2=1/v^32 by unfold v; ring] at HT; exact HThave hx' : 0 < v^32 := pow_pos hE _change 1 ≤ 10^6*v^32*_nlinarith [mul_le_mul_of_nonneg_left Hb hx'.le,show v^32*(1/v^32/128)=1/128 by have Hx : 0 < v := hE; field_simp]· rw [show parody s i=0 from ite_eq_right he]exact mul_nonneg (by positivity) (surcharge_nonneg _ _ _)lemma depth_rate_fee (i j : ℕ) (h : i ≤ mainIx j) :1/depthRate i ≤ Thermal.H j^8 := byhave H : depthRate (mainIx j) ≤ depthRate i := sqrt_le_sqrt (side_ant i _ h)rw [depth_at_main] at Happly (div_le_iff₀ (rate_easy _).1).mprhave HE := (div_le_iff₀ (show 0 < Thermal.H j^8 by have := H_pos j; positivity)).mp Hlinarithend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182import OAI.Analysis.FourierLLogL.Assembly.Series/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Run Streakdef parody (s : Scene M) (i : ℕ) := (rose (tagM i) (0:Grid M)).flag sdef stampAux (s : Scene M) (j : ℕ) :=4*parody s (mainIx j+1)+10^20*(fax s+(∑ i∈Finset.Ico 0 (mainIx j+1), parody s i / depthRate i))def stamp (s : Scene M) (j : ℕ) := 512*mutedR s j true + stampAux s jlemma stamp_nonneg {s : Scene M} (h : Climb s) (j : ℕ) : 0 ≤ stamp s j := byunfold stamp stampAuxhave H := surcharge_nonneg s false (priciest s j true)have HH (i : ℕ) : 0 ≤ parody s i := flag_nonneg _ _have HP : 0 ≤ ∑ i∈Finset.Ico 0 (mainIx j+1), parody s i / depthRate i :=Finset.sum_nonneg (fun _ _ => div_nonneg (HH _) (rate_easy _).1.le)unfold mutedRlinarith [(fax_floor h).1,HH (mainIx j+1)]private lemma chamber_fee (c j) (L : Path M) :tokenCost j c L + crumb (lowI j c) (highI j M c) j L =rooms c j L+512*subtotal (fun b => mutedR b.post j c) L+(if c then 4*(subtotal (special j) L+(billWait (tagM (mainIx j)) j L:ℝ)) else 0) := byunfold tokenCost crumb rooms miniStage playsLrw [Finset.sum_add_distrib,← Finset.mul_sum]ringlemma receipt_main (j : ℕ) (L : Path M) :souvenir true j L=rooms true j L+palaces j L + subtotal (fun b => stamp b.post j) L := bysimp only [souvenir,chamber_fee]simp only [↓reduceIte]unfold palaces stamp stampAux bigCrumbsimp_rw [blend _ (f:=fun _ => _) (g:=fun _ => _),subtR]let m := Finset.Ico 0 (mainIx j+1)let F (b : Beat M) (i : ℕ) := parody b.post i / depthRate ihave H (i : ℕ) : mainSticker i j L = nakedStage i j L + subtotal (fun b => F b i) L := byunfold F mainSticker nakedStage mainRatio parody flaggedsimp_rw [div_eq_mul_inv,mul_comm _ (depthRate i)⁻¹,subtR]ringsimp_rw [H,Finset.sum_add_distrib]have HH := cross_subtotal L m Funfold F m at HHrw [blend L (fun b => fax b.post),HH]; unfold Frw [show subtotal (fun b => fax b.post) L=fullFax L from rfl]have HV : special j = fun b : Beat M => parody b.post (mainIx j+1) := rflrw [HV]linarithlemma receipt_static (j : ℕ) (L : Path M) :souvenir false j L=rooms false j L+512*subtotal (fun b => mutedR b.post j false) L := bysimp only [souvenir,chamber_fee]; simpdef gateTax (s : Scene M) (j : ℕ) :=if s.live then 10^140*height j/Thermal.H j else 10^140*amount s jlemma tax_pos (s : Scene M) (j : ℕ) : 0 ≤ gateTax s j := byhave := d_pos j; have := H_pos j; have HA := (amount_limits s j).1unfold gateTax; split <;> positivitylemma receipt_paid :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ s : Scene M, ∀ t : Thread M s, ∀ f : Grid M → ℝ,t.Following j J f → Fit s → entry s →(s.live=true → exp (-height j) ≤ s.norm) →(∀ x, f x ≤ exp (height j)) →stats t (souvenir s.live j) ≤ gateTax s j +(if s.live then stats t (subtotal (fun b => stamp b.post j)) else 0) := byfilter_upwards [rooms_fee,palaces_fee,segment_cost,hpoly 1 1] with j hr hp hv hTM J s t f h hh hx he hflet d := height jlet k := amount s j; let v := Thermal.H jhave hV : 1 ≤ v := H_ge _have hk : 1 ≤ k := (amount_limits _ _).1have hd : 1 ≤ d := one_le_pow₀ (by norm_num)have HG := stats_plus thave HS := hr M J s f t h hh hx hfunfold gateTaxsplit· rename_i hEhave Ht := HS truehave HH := hp M J s f t h hh hx hE (he hE) hfhave hK : k ≤ 4*d := byhave H := log_le_log (exp_pos _) (he hE)rw [log_exp] at Hchange d+max _ 0+2 ≤ _have he' : max (-log s.norm) 0 ≤ d := max_le (by unfold d; linarith) (by linarith)linarithrw [hE]rw [show souvenir (M:=M) true j=fun L => rooms true j L+palaces j L+subtotal (fun b => stamp b.post j) L from funext (receipt_main _)]rw [HG (f:=fun L => _),HG (f:=fun L => _)]have heq : lowI j true=mainIx j := rflrw [heq,depth_at_main] at Hthave hi : 0 < v := H_pos jhave HE : 1/v^8 ≤ 1/v := one_div_le_one_div_of_le hi(by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 8))have HT : 1+10^30*(1/v^8)*k ≤ 10^31*(d/v) := byhave hΦ : 1 ≤ d/v := (one_le_div hi).mpr (by simpa using hT)have hh := mul_le_mul HE hK (by positivity) (by positivity)rw [show 1/v*(4*d)=4*(d/v) by ring] at hh; nlinarithchange stats t _ ≤ 1+10^30*(1/v^8)*k at Htunfold v d at *nlinarith [show 0 ≤ height j/Thermal.H j by have := H_pos j; have := d_pos j; positivity,show 10^140*height j/Thermal.H j=10^140*(height j/Thermal.H j) by ring,show 10^120*height j/Thermal.H j=10^120*(height j/Thermal.H j) by ring]· rename_i hEhave Ht := HS falserw [show lowI j false=0 from rfl,show depthRate 0=1 by simp [depthRate,side]] at Hthave HM := hv M J s f t h hf (show 0 < s.mass from hx ▸ hh.pos) hh.pos (fun q => priciest q j false) falserw [show s.mass/s.norm=1 from entry_share hh hx, one_mul] at HMrw [show s.live=false from Bool.eq_false_iff.mpr hE]simp only [add_zero]rw [show souvenir (M:=M) false j =fun L => rooms false j L+512* subtotal (fun b => mutedR b.post j false) L from funext (receipt_static _)]change stats t _ ≤ _*krw [HG]have HE : stats t (fun L => 512*subtotal (fun b => mutedR b.post j false) L) =512* t.fee (fun b => mutedR b.post j false) :=Ex_lmul (s.here.dice M) _ 512rw [HE]change _≤ 1+_*_*k at Hthave hp : height j ≤ k := (amount_limits _ _).2have hh0 : -log s.mass ≤ k := by unfold entry at hx; rw [← hx]; unfold k amount; linarith [le_max_left (-log s.norm) 0,d_pos j]unfold mutedR; linarith/-- pointwise price comparison for expected flags. -/lemma parody_fee (s : Scene M) (j : ℕ) (i : ℕ) (h : i ≤ mainIx j+1) :parody s i ≤ 10^6*Thermal.H j^32*surcharge s true (i-1) := byhave hE : 0 < Thermal.H j := H_pos _by_cases he : (rose (tagM i) (0:Grid M)).rogue s· have hx := he.1have hp : 0 < i := hxhave HH := he.2have HC := (bottom_level j)have HT : side (mainIx j) ≤ side (i-1) :=side_ant _ _ (by omega)rw [HC] at HTchange hazard s true (i-1) at HHrw [show parody s i=1 from ite_eq_left he,surcharge,ite_eq_left HH]change side (i-1)^2/128 ≤ _ at HHlet v := Thermal.H jhave Hb : 1/v^32/128 ≤ edgeW s (i-1) := byhave Hi : 0 ≤ 1/(Thermal.H j)^16 := by positivityapply le_trans _ HHhave HT := div_le_div_of_nonneg_right (pow_le_pow_left₀ Hi HT 2) (by norm_num : (0:ℝ)≤128)rw [show (1/Thermal.H j^16)^2=1/v^32 by unfold v; ring] at HT; exact HThave hx' : 0 < v^32 := pow_pos hE _change 1 ≤ 10^6*v^32*_nlinarith [mul_le_mul_of_nonneg_left Hb hx'.le,show v^32*(1/v^32/128)=1/128 by have Hx : 0 < v := hE; field_simp]· rw [show parody s i=0 from ite_eq_right he]exact mul_nonneg (by positivity) (surcharge_nonneg _ _ _)lemma depth_rate_fee (i j : ℕ) (h : i ≤ mainIx j) :1/depthRate i ≤ Thermal.H j^8 := byhave H : depthRate (mainIx j) ≤ depthRate i := sqrt_le_sqrt (side_ant i _ h)rw [depth_at_main] at Happly (div_le_iff₀ (rate_easy _).1).mprhave HE := (div_le_iff₀ (show 0 < Thermal.H j^8 by have := H_pos j; positivity)).mp Hlinarithend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273import OAI.Analysis.FourierLLogL.Assembly.Festival/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Plotdef miniStage (j i : ℕ) (L : Path M) :=20000*scalarSticker i j L+4*side i*(billWait (tagL i) j L:ℝ)def rooms (c : Bool) (j : ℕ) (L : Path M) :=1+ ∑ i∈playsL j M c, miniStage j i Ldef nakedStage (i j : ℕ) (L : Path M) :=(1+fullKills L)/depthRate i + depthRate i*timex (tagM i) j L+(billWait (tagM (i-1)) j L:ℝ)def palaces (j : ℕ) (L : Path M) :=4*(billWait (tagM (mainIx j)) j L:ℝ)+10^20* ∑ i∈Finset.Ico 0 (mainIx j+1), nakedStage i j Llemma decayed (n : ℕ) : depthRate (n+1) ≤ 3/4*depthRate n := bylet x := depthRate (n+1); let y := depthRate nhave h := rate_easy (n+1); have hv := rate_easy nobtain ⟨ha,hb,hc⟩ := hrw [side_succ] at hcnlinarithlemma weight_decay (x : ℝ) (hx : 0 ≤ x) (n m : ℕ) (h : n ≤ m) :∑ i∈Finset.Ico n m, depthRate i*(x+1+i) ≤ 10*depthRate n*(x+10+n) := bysuffices hh : ∀ k n : ℕ, n+k=m →∑ i∈Finset.Ico n m, depthRate i*(x+1+i) ≤ 10*depthRate n*(x+10+n) from hh (m-n) n (by omega)intro k; induction k with| zero =>intro n he; simp only [Nat.add_zero] at herw [he]; simp only [Finset.Ico_self,Finset.sum_empty]have := (rate_easy m).1; positivity| succ k ih =>intro n herw [start_ico _ n (by omega)]apply le_trans (add_le_add_right (ih (n+1) (by omega)) (depthRate n*(x+1+n)))push_casthave H := decayed n; have hp := (rate_easy n).1nlinarith [Nat.cast_nonneg (α:=ℝ) n]lemma waiting_fee {g : Grade} {t : Thread M s} {j : ℕ}(h : stats t (fun l => (chooseCap g l:ℝ)) ≤ 10^6*dBase g s j) :stats t (fun l => (billWait g j l:ℝ)) ≤ 10^10*(dBase g s j+Thermal.H j) := bylet U := s.here.dice M; let f (x : Grid M) := (↑(chooseCap g (t.stream x)):ℝ)have HE : stats t (fun l => (billWait g j l:ℝ)) =1000*(1+U.Ex f+g.i+(ell j:ℝ)) := byunfold stats billWait latencypush_castsimp_rw [heroPlot,stage]rw [Ex_lmul,Ex_add,Ex_add,Ex_add (f:=fun _ => 1)]simp only [Ex_const]rflrw [HE]change U.Ex f ≤ _ at hhave Hi : (ell j:ℝ) ≤ Thermal.H j := by unfold Thermal.H; exact_mod_cast ell_le_h jhave H := log_nonneg (amount_limits s j).1unfold dBase at *; linarith [H_pos j,Nat.cast_nonneg (α:=ℝ) g.i]lemma size_stat {t : Thread M s} (h : t.Following j J f) (hh : Fit s) (hv : entry s) :stats t fullKills ≤ 1 :=le_trans (deaths t h hh.pos) (entry_share hh hv).lelemma rooms_fee :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ, ∀ t : Thread M s,t.Following j J f → Fit s → entry s →(∀ x, f x ≤ exp (height j)) →∀ c : Bool, stats t (rooms c j) ≤ 1 + 10^30*depthRate (lowI j c)*amount s j := byfilter_upwards [paid_levels,hpoly 20 1] with j hj hv M J s f t h hh hx hf clet n := lowI j c; let m := highI j M clet A := amount s jhave hP : 1 ≤ A ∧ height j ≤ A := amount_limits _ _have hz : 20*Thermal.H j ≤ height j := by rw [pow_one] at hv; exact hvhave H (i : ℕ) : stats t (miniStage j i) ≤ 10^20*depthRate i*(A+1+i) := bylet g := tagL i; let a := depthRate ilet H := dBase g s jhave hi := hj M J s f t h hh hx hf g (fun x => Bool.noConfusion x)obtain ⟨h₁,h₂⟩ := hihave HC : H ≤ 2*(A+1+i) := bychange 1+log A+(i:ℝ) ≤ _linarith [Real.log_le_sub_one_of_pos (by linarith : 0<A),Nat.cast_nonneg (α:=ℝ) i]have HT : cutBook g s j ≤ 1000*(A+1+i) := byunfold g cutBook tagL scLimitsimp only [↓reduceIte,Bool.false_eq_true]unfold A amount; linarithhave HE : stats t (timex g j) ≤ 10^11*(A+1+i) := bychange stats t _ ≤ _*(H+_) at h₁linarith [Nat.cast_nonneg (α:=ℝ) i]have HR := waiting_fee h₂change stats t _ ≤ 10^10*(H+_) at HRlet f (l : Path M) := ((billWait g j l):ℝ)have HJ : stats t f ≤ 10^11*(A+1+i) := byapply HR.translinarith [Nat.cast_nonneg (α:=ℝ) i]have hE : stats t (miniStage j i) =20000*(a*(1+stats t fullKills+stats t (timex g j)))+(4*side i)*stats t f := bychange stats t (fun L => 20000*(a*(1+_+_)) +4*side i * _) = _unfold statsrw [Ex_add _ (f:=fun l => _),Ex_lmul,Ex_lmul,Ex_lmul,Ex_add,Ex_add (f:=fun l=>1),Ex_const]rw [hE]have ha : 0 < a ∧ a ≤ 1 ∧ a^2=side i := rate_easy _have HA : side i ≤ a := by nlinarithhave hv := size_stat h hh hxhave HL : side i * stats t f ≤ a*(10^11*(A+1+i)) :=(mul_le_mul_of_nonneg_left HJ (side_pos i).le).trans(mul_le_mul_of_nonneg_right HA (by have hh := le_trans (by norm_num : (0:ℝ)≤1) hP.1; positivity))change _ ≤ 10^20*a*_nlinarith [mul_le_mul_of_nonneg_left HE ha.1.le,Nat.cast_nonneg (α:=ℝ) i,mul_nonneg ha.1.le (Nat.cast_nonneg (α:=ℝ) i)]have Hn : (n:ℝ) ≤ 19*Thermal.H j := byunfold n lowIsplit· exact (main_bounds j (Nat.le_add_right _ 3)).2.1· simp only [Nat.cast_zero]; have := H_pos j; positivitycalc_ = 1+∑ i∈Finset.Ico n m, stats t (miniStage j i) := byunfold stats rooms; rw [Ex_add (f:=fun _ => 1),Ex_const,Ex_finset_sum]rfl_ ≤ 1+∑ i∈Finset.Ico n m, (10^20*depthRate i*(A+1+i)) :=add_le_add_right (Finset.sum_le_sum (fun i _ => H i)) __ ≤ _ := bysimp_rw [mul_assoc (a:=(10:ℝ)^20) (b:=depthRate _),← Finset.mul_sum]have HC := weight_decay A (by linarith) n m (by unfold m highI n; omega)have H : A+10+n ≤ 1000*A := by linarithchange _ ≤ 1+10^30*depthRate n*Anlinarith [mul_le_mul_of_nonneg_left H (rate_easy n).1.le,show0 ≤ depthRate n*A by apply mul_nonneg (rate_easy n).1.le; linarith]lemma depth_at_main (j : ℕ) : depthRate (mainIx j) = 1/(Thermal.H j)^8 := byunfold depthRate; rw [bottom_level]rw [show 1/Thermal.H j^16=(1/Thermal.H j^8)^2 by ring]; rw [Real.sqrt_sq (by positivity)]lemma palaces_fee :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ, ∀ t : Thread M s,t.Following j J f → Fit s → entry s →s.live=true → exp (-height j) ≤ s.norm →(∀ x, f x ≤ exp (height j)) →stats t (palaces j) ≤ 10^120*height j/Thermal.H j := byfilter_upwards [paid_levels,hpoly_mix 1 11 1,eventually_ge_atTop 1] with j hj hT HjM J s f t h hh hx he hhx hflet d := height j; let v := Thermal.H j; let k := mainIx j+1have hd : 1 ≤ d := one_le_pow₀ (by norm_num)have hV : 1 ≤ v := H_ge jhave hv : 0 < v := by linarithhave hk : (k:ℝ) ≤ 20*v := byunfold k; push_castlinarith [(main_bounds j (Nat.le_add_right (mainIx j) 3)).2.1,show Thermal.H j=v from rfl]let A := amount s jhave hl : A ≤ 4*d := byhave H := log_le_log (exp_pos _) hhxrw [log_exp] at Hchange d+max _ 0 + 2 ≤ _have he' : max (-log s.norm) 0 ≤ d := max_le (by unfold d; linarith) (by linarith)linarithlet m := (j:ℝ)have hm : 1 ≤ m := by unfold m; exact_mod_cast Hjhave HP : v^11*m ≤ d := by simpa only [pow_one,one_mul] using hThave hA : log A ≤ 4+m := byhave Hx : 1 ≤ A := (amount_limits _ _).1apply (log_le_log (show 0 < A by linarith) hl).transunfold d; rw [log_mul (by positivity) (d_pos j).ne',height, log_pow]unfold mhave hU : log 2 ≤ 1 := by linarith [log_le_sub_one_of_pos (by norm_num : (0:ℝ) < 2)]nlinarith [log_le_sub_one_of_pos (by norm_num : (0:ℝ)<4),Nat.cast_nonneg (α:=ℝ) j]have hP (i : ℕ) (hK : i < k) := hj M J s f t h hh hx hf (tagM i) (fun _ =>⟨(by change i ≤ mainIx j; unfold k at hK; omega),he⟩)have HR (i : ℕ) (hi : i<k) :stats t (fun l => (billWait (tagM i) j l:ℝ)) ≤ 10^12*(v+m) := byapply (waiting_fee (hP i hi).2).transchange (10:ℝ)^10*(1+log A+(i:ℝ)+v) ≤ _have HH : (i:ℝ) ≤ k := Nat.cast_le.mpr hi.lelinarithhave HX : m ≤ d/v := (le_div_iff₀ hv).mpr (byhave HL : v ≤ v^11 := by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 11)nlinarith)have HU (i : ℕ) (hi : i<k) :stats t (timex (tagM i) j) ≤ 10^35*(d/v)*(1+(i:ℝ)) := byapply (hP i hi).1.translet y := (i:ℝ); let W := codeWeight capAhave HH : 1 ≤ W ∧ W ≤ 10^25 := by unfold W codeWeight capA reserve; norm_numhave HE : cutBook (tagM i) s j = W*(d/v)*(2+y) := byunfold cutBook kappasimp only [tagM,↓reduceIte]push_cast; unfold W d v y; ringrw [HE]change _ *(1+log A+y+W*(d/v)*(2+y)) ≤ _*(d/v)*(1+y)have hY : 0 ≤ y := by unfold y; positivitynlinarith [show W*(d/v)*(2+y) ≤ 10^25*((d/v)*(2+y)) byrw [mul_assoc]; gcongr; linarith, mul_le_mul_of_nonneg_right HX hY]have hcost (i : ℕ) (hi : i < k) :stats t (nakedStage i j) ≤2*v^8 + 10^12*(v+m) + 10^35*(d/v)*(depthRate i * (1+(i:ℝ))) := bylet a := depthRate ihave ha := (rate_easy i).1have HE : stats t (nakedStage i j) =(1+stats t fullKills)/a+a*stats t (timex (tagM i) j)+stats t (fun L => (↑(billWait (tagM (i-1)) j L):ℝ)) := byunfold stats nakedStagesimp_rw [Ex_add,Ex_lmul,div_eq_mul_inv,Ex_mul,Ex_add (f:=fun _ => 1),Ex_const]rflhave hb : 1/a ≤ v^8 := byhave hn : i ≤ mainIx j := by unfold k at hi; omegahave HH : depthRate (mainIx j) ≤ a := sqrt_le_sqrt (side_ant _ _ hn)rw [depth_at_main] at HHapply (div_le_iff₀ ha).mprhave H' := (div_le_iff₀ (show 0 < v^8 by positivity)).mp HHlinarithrw [HE]have HH : (1+stats t fullKills)/a ≤ 2/a := div_le_div_of_nonneg_right (by linarith [size_stat h hh hx]) ha.lehave ht := HR (i-1) (by omega)unfold a at *; linarith [mul_le_mul_of_nonneg_left (HU i hi) ha.le,show(2:ℝ)/depthRate i=2*(1/depthRate i) by ring]let F (i) := depthRate i*(1+(i:ℝ))let V := 2*v^8+10^12*(v+m); let S := 10^35*(d/v)have HS : 0 ≤ S := by unfold S; positivitylet R := Finset.Ico 0 khave HI : ∑ i∈R,stats t (nakedStage i j) ≤ k*V+100*S := byhave H : ∑ i∈R,F i ≤ 100 := byhave HI := weight_decay 0 le_rfl 0 k (by omega)unfold F Rnorm_num [depthRate,side] at HI ⊢; exact HIcalc_ ≤ ∑ i∈R,(V+S*F i) := Finset.sum_le_sum fun i hi => hcost i (Finset.mem_Ico.mp hi).2_ ≤ _ := byunfold R; rw [Finset.sum_add_distrib,←Finset.mul_sum,Finset.sum_const,Nat.card_Ico,nsmul_eq_mul,Nat.sub_zero]unfold R at H; nlinarithhave hΦ : (v:ℝ)^10 *m ≤ d/v := (le_div_iff₀ hv).mpr (by apply le_trans _ HP; exact le_of_eq (by ring))have HQ : k*V ≤ 10^16*(d/v) := byhave he' : v^9 ≤ v^10*m := le_trans (pow_le_pow_right₀ hV (by omega))(le_mul_of_one_le_right (by positivity) hm)have ht' : v^2 ≤ v^9 := pow_le_pow_right₀ hV (by omega)have hh' : v*m ≤ v^10*m := mul_le_mul_of_nonneg_right(by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 10)) (by linarith)have hv' : 0 ≤ V := by unfold V; positivityapply (mul_le_mul_of_nonneg_right hk hv').transunfold V; nlinarithhave H₁ : stats t (fun l => (billWait (tagM (mainIx j)) j l:ℝ)) ≤ 10^14*(d/v) := byapply (HR (mainIx j) (by unfold k; omega)).transhave HH : v ≤ d/v := le_trans (byhave HE : v ≤ v^10 := by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 10)exact le_trans HE (le_mul_of_one_le_right (by positivity) hm)) hΦlinarithhave HHH : stats t (palaces j) =4*stats t (fun l => (billWait (tagM (mainIx j)) j l:ℝ))+10^20*∑ i∈R,stats t (nakedStage i j) := byunfold stats palaces; rw [Ex_add _ (f:=fun _ => _),Ex_lmul,Ex_lmul,Ex_finset_sum]rw [HHH]apply le_trans (add_le_add (mul_le_mul_of_nonneg_left H₁ (by norm_num)) (mul_le_mul_of_nonneg_left HI (by norm_num)))change _ ≤10^120*d/vunfold S at *; nlinarith [show 10^120*d/v=10^120*(d/v) by ring]end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273import OAI.Analysis.FourierLLogL.Assembly.Festival/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Plotdef miniStage (j i : ℕ) (L : Path M) :=20000*scalarSticker i j L+4*side i*(billWait (tagL i) j L:ℝ)def rooms (c : Bool) (j : ℕ) (L : Path M) :=1+ ∑ i∈playsL j M c, miniStage j i Ldef nakedStage (i j : ℕ) (L : Path M) :=(1+fullKills L)/depthRate i + depthRate i*timex (tagM i) j L+(billWait (tagM (i-1)) j L:ℝ)def palaces (j : ℕ) (L : Path M) :=4*(billWait (tagM (mainIx j)) j L:ℝ)+10^20* ∑ i∈Finset.Ico 0 (mainIx j+1), nakedStage i j Llemma decayed (n : ℕ) : depthRate (n+1) ≤ 3/4*depthRate n := bylet x := depthRate (n+1); let y := depthRate nhave h := rate_easy (n+1); have hv := rate_easy nobtain ⟨ha,hb,hc⟩ := hrw [side_succ] at hcnlinarithlemma weight_decay (x : ℝ) (hx : 0 ≤ x) (n m : ℕ) (h : n ≤ m) :∑ i∈Finset.Ico n m, depthRate i*(x+1+i) ≤ 10*depthRate n*(x+10+n) := bysuffices hh : ∀ k n : ℕ, n+k=m →∑ i∈Finset.Ico n m, depthRate i*(x+1+i) ≤ 10*depthRate n*(x+10+n) from hh (m-n) n (by omega)intro k; induction k with| zero =>intro n he; simp only [Nat.add_zero] at herw [he]; simp only [Finset.Ico_self,Finset.sum_empty]have := (rate_easy m).1; positivity| succ k ih =>intro n herw [start_ico _ n (by omega)]apply le_trans (add_le_add_right (ih (n+1) (by omega)) (depthRate n*(x+1+n)))push_casthave H := decayed n; have hp := (rate_easy n).1nlinarith [Nat.cast_nonneg (α:=ℝ) n]lemma waiting_fee {g : Grade} {t : Thread M s} {j : ℕ}(h : stats t (fun l => (chooseCap g l:ℝ)) ≤ 10^6*dBase g s j) :stats t (fun l => (billWait g j l:ℝ)) ≤ 10^10*(dBase g s j+Thermal.H j) := bylet U := s.here.dice M; let f (x : Grid M) := (↑(chooseCap g (t.stream x)):ℝ)have HE : stats t (fun l => (billWait g j l:ℝ)) =1000*(1+U.Ex f+g.i+(ell j:ℝ)) := byunfold stats billWait latencypush_castsimp_rw [heroPlot,stage]rw [Ex_lmul,Ex_add,Ex_add,Ex_add (f:=fun _ => 1)]simp only [Ex_const]rflrw [HE]change U.Ex f ≤ _ at hhave Hi : (ell j:ℝ) ≤ Thermal.H j := by unfold Thermal.H; exact_mod_cast ell_le_h jhave H := log_nonneg (amount_limits s j).1unfold dBase at *; linarith [H_pos j,Nat.cast_nonneg (α:=ℝ) g.i]lemma size_stat {t : Thread M s} (h : t.Following j J f) (hh : Fit s) (hv : entry s) :stats t fullKills ≤ 1 :=le_trans (deaths t h hh.pos) (entry_share hh hv).lelemma rooms_fee :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ, ∀ t : Thread M s,t.Following j J f → Fit s → entry s →(∀ x, f x ≤ exp (height j)) →∀ c : Bool, stats t (rooms c j) ≤ 1 + 10^30*depthRate (lowI j c)*amount s j := byfilter_upwards [paid_levels,hpoly 20 1] with j hj hv M J s f t h hh hx hf clet n := lowI j c; let m := highI j M clet A := amount s jhave hP : 1 ≤ A ∧ height j ≤ A := amount_limits _ _have hz : 20*Thermal.H j ≤ height j := by rw [pow_one] at hv; exact hvhave H (i : ℕ) : stats t (miniStage j i) ≤ 10^20*depthRate i*(A+1+i) := bylet g := tagL i; let a := depthRate ilet H := dBase g s jhave hi := hj M J s f t h hh hx hf g (fun x => Bool.noConfusion x)obtain ⟨h₁,h₂⟩ := hihave HC : H ≤ 2*(A+1+i) := bychange 1+log A+(i:ℝ) ≤ _linarith [Real.log_le_sub_one_of_pos (by linarith : 0<A),Nat.cast_nonneg (α:=ℝ) i]have HT : cutBook g s j ≤ 1000*(A+1+i) := byunfold g cutBook tagL scLimitsimp only [↓reduceIte,Bool.false_eq_true]unfold A amount; linarithhave HE : stats t (timex g j) ≤ 10^11*(A+1+i) := bychange stats t _ ≤ _*(H+_) at h₁linarith [Nat.cast_nonneg (α:=ℝ) i]have HR := waiting_fee h₂change stats t _ ≤ 10^10*(H+_) at HRlet f (l : Path M) := ((billWait g j l):ℝ)have HJ : stats t f ≤ 10^11*(A+1+i) := byapply HR.translinarith [Nat.cast_nonneg (α:=ℝ) i]have hE : stats t (miniStage j i) =20000*(a*(1+stats t fullKills+stats t (timex g j)))+(4*side i)*stats t f := bychange stats t (fun L => 20000*(a*(1+_+_)) +4*side i * _) = _unfold statsrw [Ex_add _ (f:=fun l => _),Ex_lmul,Ex_lmul,Ex_lmul,Ex_add,Ex_add (f:=fun l=>1),Ex_const]rw [hE]have ha : 0 < a ∧ a ≤ 1 ∧ a^2=side i := rate_easy _have HA : side i ≤ a := by nlinarithhave hv := size_stat h hh hxhave HL : side i * stats t f ≤ a*(10^11*(A+1+i)) :=(mul_le_mul_of_nonneg_left HJ (side_pos i).le).trans(mul_le_mul_of_nonneg_right HA (by have hh := le_trans (by norm_num : (0:ℝ)≤1) hP.1; positivity))change _ ≤ 10^20*a*_nlinarith [mul_le_mul_of_nonneg_left HE ha.1.le,Nat.cast_nonneg (α:=ℝ) i,mul_nonneg ha.1.le (Nat.cast_nonneg (α:=ℝ) i)]have Hn : (n:ℝ) ≤ 19*Thermal.H j := byunfold n lowIsplit· exact (main_bounds j (Nat.le_add_right _ 3)).2.1· simp only [Nat.cast_zero]; have := H_pos j; positivitycalc_ = 1+∑ i∈Finset.Ico n m, stats t (miniStage j i) := byunfold stats rooms; rw [Ex_add (f:=fun _ => 1),Ex_const,Ex_finset_sum]rfl_ ≤ 1+∑ i∈Finset.Ico n m, (10^20*depthRate i*(A+1+i)) :=add_le_add_right (Finset.sum_le_sum (fun i _ => H i)) __ ≤ _ := bysimp_rw [mul_assoc (a:=(10:ℝ)^20) (b:=depthRate _),← Finset.mul_sum]have HC := weight_decay A (by linarith) n m (by unfold m highI n; omega)have H : A+10+n ≤ 1000*A := by linarithchange _ ≤ 1+10^30*depthRate n*Anlinarith [mul_le_mul_of_nonneg_left H (rate_easy n).1.le,show0 ≤ depthRate n*A by apply mul_nonneg (rate_easy n).1.le; linarith]lemma depth_at_main (j : ℕ) : depthRate (mainIx j) = 1/(Thermal.H j)^8 := byunfold depthRate; rw [bottom_level]rw [show 1/Thermal.H j^16=(1/Thermal.H j^8)^2 by ring]; rw [Real.sqrt_sq (by positivity)]lemma palaces_fee :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ s : Scene M, ∀ f : Grid M → ℝ, ∀ t : Thread M s,t.Following j J f → Fit s → entry s →s.live=true → exp (-height j) ≤ s.norm →(∀ x, f x ≤ exp (height j)) →stats t (palaces j) ≤ 10^120*height j/Thermal.H j := byfilter_upwards [paid_levels,hpoly_mix 1 11 1,eventually_ge_atTop 1] with j hj hT HjM J s f t h hh hx he hhx hflet d := height j; let v := Thermal.H j; let k := mainIx j+1have hd : 1 ≤ d := one_le_pow₀ (by norm_num)have hV : 1 ≤ v := H_ge jhave hv : 0 < v := by linarithhave hk : (k:ℝ) ≤ 20*v := byunfold k; push_castlinarith [(main_bounds j (Nat.le_add_right (mainIx j) 3)).2.1,show Thermal.H j=v from rfl]let A := amount s jhave hl : A ≤ 4*d := byhave H := log_le_log (exp_pos _) hhxrw [log_exp] at Hchange d+max _ 0 + 2 ≤ _have he' : max (-log s.norm) 0 ≤ d := max_le (by unfold d; linarith) (by linarith)linarithlet m := (j:ℝ)have hm : 1 ≤ m := by unfold m; exact_mod_cast Hjhave HP : v^11*m ≤ d := by simpa only [pow_one,one_mul] using hThave hA : log A ≤ 4+m := byhave Hx : 1 ≤ A := (amount_limits _ _).1apply (log_le_log (show 0 < A by linarith) hl).transunfold d; rw [log_mul (by positivity) (d_pos j).ne',height, log_pow]unfold mhave hU : log 2 ≤ 1 := by linarith [log_le_sub_one_of_pos (by norm_num : (0:ℝ) < 2)]nlinarith [log_le_sub_one_of_pos (by norm_num : (0:ℝ)<4),Nat.cast_nonneg (α:=ℝ) j]have hP (i : ℕ) (hK : i < k) := hj M J s f t h hh hx hf (tagM i) (fun _ =>⟨(by change i ≤ mainIx j; unfold k at hK; omega),he⟩)have HR (i : ℕ) (hi : i<k) :stats t (fun l => (billWait (tagM i) j l:ℝ)) ≤ 10^12*(v+m) := byapply (waiting_fee (hP i hi).2).transchange (10:ℝ)^10*(1+log A+(i:ℝ)+v) ≤ _have HH : (i:ℝ) ≤ k := Nat.cast_le.mpr hi.lelinarithhave HX : m ≤ d/v := (le_div_iff₀ hv).mpr (byhave HL : v ≤ v^11 := by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 11)nlinarith)have HU (i : ℕ) (hi : i<k) :stats t (timex (tagM i) j) ≤ 10^35*(d/v)*(1+(i:ℝ)) := byapply (hP i hi).1.translet y := (i:ℝ); let W := codeWeight capAhave HH : 1 ≤ W ∧ W ≤ 10^25 := by unfold W codeWeight capA reserve; norm_numhave HE : cutBook (tagM i) s j = W*(d/v)*(2+y) := byunfold cutBook kappasimp only [tagM,↓reduceIte]push_cast; unfold W d v y; ringrw [HE]change _ *(1+log A+y+W*(d/v)*(2+y)) ≤ _*(d/v)*(1+y)have hY : 0 ≤ y := by unfold y; positivitynlinarith [show W*(d/v)*(2+y) ≤ 10^25*((d/v)*(2+y)) byrw [mul_assoc]; gcongr; linarith, mul_le_mul_of_nonneg_right HX hY]have hcost (i : ℕ) (hi : i < k) :stats t (nakedStage i j) ≤2*v^8 + 10^12*(v+m) + 10^35*(d/v)*(depthRate i * (1+(i:ℝ))) := bylet a := depthRate ihave ha := (rate_easy i).1have HE : stats t (nakedStage i j) =(1+stats t fullKills)/a+a*stats t (timex (tagM i) j)+stats t (fun L => (↑(billWait (tagM (i-1)) j L):ℝ)) := byunfold stats nakedStagesimp_rw [Ex_add,Ex_lmul,div_eq_mul_inv,Ex_mul,Ex_add (f:=fun _ => 1),Ex_const]rflhave hb : 1/a ≤ v^8 := byhave hn : i ≤ mainIx j := by unfold k at hi; omegahave HH : depthRate (mainIx j) ≤ a := sqrt_le_sqrt (side_ant _ _ hn)rw [depth_at_main] at HHapply (div_le_iff₀ ha).mprhave H' := (div_le_iff₀ (show 0 < v^8 by positivity)).mp HHlinarithrw [HE]have HH : (1+stats t fullKills)/a ≤ 2/a := div_le_div_of_nonneg_right (by linarith [size_stat h hh hx]) ha.lehave ht := HR (i-1) (by omega)unfold a at *; linarith [mul_le_mul_of_nonneg_left (HU i hi) ha.le,show(2:ℝ)/depthRate i=2*(1/depthRate i) by ring]let F (i) := depthRate i*(1+(i:ℝ))let V := 2*v^8+10^12*(v+m); let S := 10^35*(d/v)have HS : 0 ≤ S := by unfold S; positivitylet R := Finset.Ico 0 khave HI : ∑ i∈R,stats t (nakedStage i j) ≤ k*V+100*S := byhave H : ∑ i∈R,F i ≤ 100 := byhave HI := weight_decay 0 le_rfl 0 k (by omega)unfold F Rnorm_num [depthRate,side] at HI ⊢; exact HIcalc_ ≤ ∑ i∈R,(V+S*F i) := Finset.sum_le_sum fun i hi => hcost i (Finset.mem_Ico.mp hi).2_ ≤ _ := byunfold R; rw [Finset.sum_add_distrib,←Finset.mul_sum,Finset.sum_const,Nat.card_Ico,nsmul_eq_mul,Nat.sub_zero]unfold R at H; nlinarithhave hΦ : (v:ℝ)^10 *m ≤ d/v := (le_div_iff₀ hv).mpr (by apply le_trans _ HP; exact le_of_eq (by ring))have HQ : k*V ≤ 10^16*(d/v) := byhave he' : v^9 ≤ v^10*m := le_trans (pow_le_pow_right₀ hV (by omega))(le_mul_of_one_le_right (by positivity) hm)have ht' : v^2 ≤ v^9 := pow_le_pow_right₀ hV (by omega)have hh' : v*m ≤ v^10*m := mul_le_mul_of_nonneg_right(by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 10)) (by linarith)have hv' : 0 ≤ V := by unfold V; positivityapply (mul_le_mul_of_nonneg_right hk hv').transunfold V; nlinarithhave H₁ : stats t (fun l => (billWait (tagM (mainIx j)) j l:ℝ)) ≤ 10^14*(d/v) := byapply (HR (mainIx j) (by unfold k; omega)).transhave HH : v ≤ d/v := le_trans (byhave HE : v ≤ v^10 := by simpa using pow_le_pow_right₀ hV (by omega : 1 ≤ 10)exact le_trans HE (le_mul_of_one_le_right (by positivity) hm)) hΦlinarithhave HHH : stats t (palaces j) =4*stats t (fun l => (billWait (tagM (mainIx j)) j l:ℝ))+10^20*∑ i∈R,stats t (nakedStage i j) := byunfold stats palaces; rw [Ex_add _ (f:=fun _ => _),Ex_lmul,Ex_lmul,Ex_finset_sum]rw [HHH]apply le_trans (add_le_add (mul_le_mul_of_nonneg_left H₁ (by norm_num)) (mul_le_mul_of_nonneg_left HI (by norm_num)))change _ ≤10^120*d/vunfold S at *; nlinarith [show 10^120*d/v=10^120*(d/v) by ring]end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138import OAI.Analysis.FourierLLogL.Assembly.Rail/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupe/-- Depth of a sequence (no missing jumps within plateau) -/def matrix (n : ℕ) : Path M → Prop| [] => True| b::l => depthB b=n ∧ matrix (n+1) llemma matrix_trip {x : Grid M} (l : Path M) (h : Trip x s l) :matrix s.here.lev l := byinduction l generalizing s with| nil => exact True.intro| cons b l ih =>have He : depthB b=s.here.lev := by unfold depthB; rw [h.2.1.lower.here,h.1]have HH := ih h.2.2rw [depth_next,He] at HH; exact ⟨He,HH⟩lemma matrix_cut (l : Path M) (n : ℕ) (k : ℕ) (h : matrix n l) :∃ p q : Path M, l=p++q ∧ matrix (n+p.length) q ∧(∀ b∈p, depthB b < k) ∧ (∀ b∈q, k ≤ depthB b) ∧n+p.length = min (max n k) (n+l.length) := byinduction l generalizing n with| nil => refine ⟨[],[],rfl,True.intro,?_⟩; simp| cons b l ih =>obtain ⟨hp,hq,hh,hE,h₁,h₂,h₃⟩ := ih _ h.2have HI : depthB b=n := h.1by_cases hv : n < k· refine ⟨b::hp,hq, by rw [hh]; rfl,?_,?_,h₂,?_⟩· rw [List.length_cons,show n+(List.length hp+1)=n+1+List.length hp by omega]exact hE· intro x hx; rcases List.mem_cons.mp hx with rfl|hx· omegaexact h₁ _ hx· simp only [List.length_cons]omega· have H : hp.length=0 := by omegahave hL : hp=[] := List.eq_nil_of_length_eq_zero Hrw [hL,List.nil_append] at hh; cases hhrefine ⟨[],b::l,rfl,h,fun b hb => ?_,fun z hz => ?_,?_⟩· simp at hb· rcases List.mem_cons.mp hz with rfl|hz; omegaexact h₂ _ hz· simp; omegalemma slab_on (l : Path M) (n : ℕ) (h : matrix n l) (a k : ℕ) :∃ p q r : Path M, l=p++q++r ∧(∀ b∈p, ¬betweenS a k b) ∧ (∀ b∈r, ¬betweenS a k b) ∧q.length ≤ k := byobtain ⟨p,s,H,h₁,h₂,h₃,h₄⟩ := matrix_cut l n a hobtain ⟨q,r,hr,hx,hp,he,hk⟩ := matrix_cut s _ (a+k) h₁refine ⟨p,q,r,by rw [H,hr,List.append_assoc],fun b hi hh => ?_,fun b hi hh => ?_,?_⟩exact (h₂ b hi).not_ge hh.1exact hh.2.not_ge (he b hi)have ht₁ : l.length=p.length+s.length := by rw [H,List.length_append]have ht₂ : s.length=q.length+r.length := by rw [hr,List.length_append]omega/-- quality trip coupons that cover all high nonbad jumps before activation. -/def shades (m : Grade → ℕ) (u : Grid M) (l : Path M) (j : ℕ) :=∀ g : Grade, ∀ p q : Path M, l=p++q → stall u g j l p →∀ b∈p, snag g u b → betweenS (m g) (billWait g j l) blemma sheds {s : Scene M} {l : Path M} (h : Cast j J f s l) (u : Grid M) :∃ m : Grade → ℕ, shades m u l j := bychoose m hm using fun g => bound_stage (u:=u) l h gexact ⟨m,hm⟩def stripe (a : Grade → ℕ) (g : Grade) (j : ℕ) (l : Path M) (b : Beat M) :=if betweenS (a g) (billWait g j l) b then (1:ℝ) else 0lemma stripe_pos (a : Grade → ℕ) (g : Grade) (j : ℕ) (l : Path M) (b : Beat M) :0 ≤ stripe a g j l b := by unfold stripe; split <;> norm_numlemma stripe_bill (a : Grade → ℕ) (g : Grade) (j : ℕ) (l : Path M) (x : Grid M){s : Scene M} (h : Trip x s l) : subtotal (stripe a g j l) l ≤ billWait g j l := bylet f := stripe a g j lobtain ⟨v,w,p,hl,hv,hp,hw⟩ := slab_on l _ (matrix_trip l h) (a g) (billWait g j l)have HF (m : Path M) (hi : ∀ b∈m, ¬ betweenS (a g) (billWait g j l) b) :subtotal f m=0 := byinduction m with| nil => rfl| cons b r ih =>have HH : f b=0 := ite_eq_right (hi b List.mem_cons_self)rw [subtotal_cons,HH,ih fun y hy => hi y (List.mem_cons_of_mem _ hy),zero_add]have HX (m : Path M) :subtotal f m ≤ m.length := byinduction m with| nil => simp [subtotal]| cons b r ih =>have he : f b≤ 1 := by unfold f stripe; split <;> norm_numrw [subtotal_cons, List.length_cons]; push_cast; linarithchange subtotal f l ≤ _nth_rw 1 [hl]rw [subtotal_app,subtotal_app,HF v hv,HF p hp,zero_add,add_zero]apply (HX w).transexact_mod_cast hwlemma trim_cost (g : Beat M → ℝ) (hg : ∀ b, Ideal b.pre b.post → 0 ≤ g b){x : Grid M} (l p r : Path M) (h : Trip x s (p++(l++r))) :subtotal g l ≤ subtotal g (p++(l++r)) := byrw [subtotal_app,subtotal_app]obtain ⟨ha,q,hq⟩ := trip_cut hobtain ⟨hc,t,ht⟩ := trip_cut hqlinarith [trip_nonneg ht hg,trip_nonneg ha hg]lemma trip_depth_limit {l : Path M} {s : Scene M} (h : Cast j J f s l) :s.here.lev+l.length ≤ J := byinduction l generalizing s with| nil => exact (show s.Safe j J f from h).depth_ok| cons b l ih =>obtain ⟨rfl,⟨t,ht⟩,hh⟩ := hhave hi := ih hhrw [List.length_cons]have hX := ht.2.1.1.hererw [depth_next,depthB,hX] at hiomegaend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138import OAI.Analysis.FourierLLogL.Assembly.Rail/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupe/-- Depth of a sequence (no missing jumps within plateau) -/def matrix (n : ℕ) : Path M → Prop| [] => True| b::l => depthB b=n ∧ matrix (n+1) llemma matrix_trip {x : Grid M} (l : Path M) (h : Trip x s l) :matrix s.here.lev l := byinduction l generalizing s with| nil => exact True.intro| cons b l ih =>have He : depthB b=s.here.lev := by unfold depthB; rw [h.2.1.lower.here,h.1]have HH := ih h.2.2rw [depth_next,He] at HH; exact ⟨He,HH⟩lemma matrix_cut (l : Path M) (n : ℕ) (k : ℕ) (h : matrix n l) :∃ p q : Path M, l=p++q ∧ matrix (n+p.length) q ∧(∀ b∈p, depthB b < k) ∧ (∀ b∈q, k ≤ depthB b) ∧n+p.length = min (max n k) (n+l.length) := byinduction l generalizing n with| nil => refine ⟨[],[],rfl,True.intro,?_⟩; simp| cons b l ih =>obtain ⟨hp,hq,hh,hE,h₁,h₂,h₃⟩ := ih _ h.2have HI : depthB b=n := h.1by_cases hv : n < k· refine ⟨b::hp,hq, by rw [hh]; rfl,?_,?_,h₂,?_⟩· rw [List.length_cons,show n+(List.length hp+1)=n+1+List.length hp by omega]exact hE· intro x hx; rcases List.mem_cons.mp hx with rfl|hx· omegaexact h₁ _ hx· simp only [List.length_cons]omega· have H : hp.length=0 := by omegahave hL : hp=[] := List.eq_nil_of_length_eq_zero Hrw [hL,List.nil_append] at hh; cases hhrefine ⟨[],b::l,rfl,h,fun b hb => ?_,fun z hz => ?_,?_⟩· simp at hb· rcases List.mem_cons.mp hz with rfl|hz; omegaexact h₂ _ hz· simp; omegalemma slab_on (l : Path M) (n : ℕ) (h : matrix n l) (a k : ℕ) :∃ p q r : Path M, l=p++q++r ∧(∀ b∈p, ¬betweenS a k b) ∧ (∀ b∈r, ¬betweenS a k b) ∧q.length ≤ k := byobtain ⟨p,s,H,h₁,h₂,h₃,h₄⟩ := matrix_cut l n a hobtain ⟨q,r,hr,hx,hp,he,hk⟩ := matrix_cut s _ (a+k) h₁refine ⟨p,q,r,by rw [H,hr,List.append_assoc],fun b hi hh => ?_,fun b hi hh => ?_,?_⟩exact (h₂ b hi).not_ge hh.1exact hh.2.not_ge (he b hi)have ht₁ : l.length=p.length+s.length := by rw [H,List.length_append]have ht₂ : s.length=q.length+r.length := by rw [hr,List.length_append]omega/-- quality trip coupons that cover all high nonbad jumps before activation. -/def shades (m : Grade → ℕ) (u : Grid M) (l : Path M) (j : ℕ) :=∀ g : Grade, ∀ p q : Path M, l=p++q → stall u g j l p →∀ b∈p, snag g u b → betweenS (m g) (billWait g j l) blemma sheds {s : Scene M} {l : Path M} (h : Cast j J f s l) (u : Grid M) :∃ m : Grade → ℕ, shades m u l j := bychoose m hm using fun g => bound_stage (u:=u) l h gexact ⟨m,hm⟩def stripe (a : Grade → ℕ) (g : Grade) (j : ℕ) (l : Path M) (b : Beat M) :=if betweenS (a g) (billWait g j l) b then (1:ℝ) else 0lemma stripe_pos (a : Grade → ℕ) (g : Grade) (j : ℕ) (l : Path M) (b : Beat M) :0 ≤ stripe a g j l b := by unfold stripe; split <;> norm_numlemma stripe_bill (a : Grade → ℕ) (g : Grade) (j : ℕ) (l : Path M) (x : Grid M){s : Scene M} (h : Trip x s l) : subtotal (stripe a g j l) l ≤ billWait g j l := bylet f := stripe a g j lobtain ⟨v,w,p,hl,hv,hp,hw⟩ := slab_on l _ (matrix_trip l h) (a g) (billWait g j l)have HF (m : Path M) (hi : ∀ b∈m, ¬ betweenS (a g) (billWait g j l) b) :subtotal f m=0 := byinduction m with| nil => rfl| cons b r ih =>have HH : f b=0 := ite_eq_right (hi b List.mem_cons_self)rw [subtotal_cons,HH,ih fun y hy => hi y (List.mem_cons_of_mem _ hy),zero_add]have HX (m : Path M) :subtotal f m ≤ m.length := byinduction m with| nil => simp [subtotal]| cons b r ih =>have he : f b≤ 1 := by unfold f stripe; split <;> norm_numrw [subtotal_cons, List.length_cons]; push_cast; linarithchange subtotal f l ≤ _nth_rw 1 [hl]rw [subtotal_app,subtotal_app,HF v hv,HF p hp,zero_add,add_zero]apply (HX w).transexact_mod_cast hwlemma trim_cost (g : Beat M → ℝ) (hg : ∀ b, Ideal b.pre b.post → 0 ≤ g b){x : Grid M} (l p r : Path M) (h : Trip x s (p++(l++r))) :subtotal g l ≤ subtotal g (p++(l++r)) := byrw [subtotal_app,subtotal_app]obtain ⟨ha,q,hq⟩ := trip_cut hobtain ⟨hc,t,ht⟩ := trip_cut hqlinarith [trip_nonneg ht hg,trip_nonneg ha hg]lemma trip_depth_limit {l : Path M} {s : Scene M} (h : Cast j J f s l) :s.here.lev+l.length ≤ J := byinduction l generalizing s with| nil => exact (show s.Safe j J f from h).depth_ok| cons b l ih =>obtain ⟨rfl,⟨t,ht⟩,hh⟩ := hhave hi := ih hhrw [List.length_cons]have hX := ht.2.1.1.hererw [depth_next,depthB,hX] at hiomegaend Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223import OAI.Analysis.FourierLLogL.Assembly.Duration/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Run Streakdef lowI (j : ℕ) (b : Bool) := if b then mainIx j else 0def highI (j M : ℕ) (b : Bool) := lowI j b+M+1def playsL (j M : ℕ) (b : Bool) := Finset.Ico (lowI j b) (highI j M b)def picks (s : Scene M) (i j : ℕ) (b : Bool) :=i ∈ playsL j M b ∧ hazard s false idef priciest (s : Scene M) (j : ℕ) (b : Bool) :=if h : ∃ i, picks s i j b then Nat.find h else lowI j bdef mutedR (s : Scene M) (j : ℕ) (b : Bool) :=surcharge s false (priciest s j b)/-- scalar edge charges pay the largest bad level, chosen locally at the pre-bit moment. -/lemma pricey (s : Scene M) (j : ℕ) (b : Bool) (i : ℕ) (h : picks s i j b) :side i ≤ 128*mutedR s j b := bylet n := priciest s j bhave hi : ∃ i, picks s i j b := ⟨i,h⟩have hn : n=Nat.find hi := dite_eq_left hihave HE : hazard s false n := hn.symm ▸ (Nat.find_spec hi).2have H : side i ≤ side n := pow_le_pow_of_le_one (by norm_num) (by norm_num)(hn.le.trans (Nat.find_min' hi h))change side n / 128 ≤ edgeW s n at HEchange _ ≤ 128*surcharge s false nrw [surcharge,ite_eq_left (show hazard s false n from HE)]; linarithdef special (j : ℕ) (b : Beat M) := (rose (tagM (mainIx j +1)) (0:Grid M)).flag b.postdef token (a : Grade → ℕ) (L : Path M) (j : ℕ) (s : Bool) (b : Beat M) :=side M+512*mutedR b.post j s+(∑ i∈playsL j M s,4*side i*stripe a (tagL i) j L b) +(if s then 4*(special j b+stripe a (tagM (mainIx j)) j L b) else 0)lemma token_floor (a : Grade → ℕ) (j : ℕ) (s : Bool) (L : Path M) (b : Beat M) :side M ≤ token a L j s b ∧ 512*mutedR b.post j s ≤ token a L j s b ∧(∑ i∈playsL j M s,4*side i*stripe a (tagL i) j L b) ≤ token a L j s b ∧(s=true → 4*(special j b+stripe a (tagM (mainIx j)) j L b) ≤ token a L j s b) := bylet z := ∑ i∈playsL j M s,4*side i*stripe a (tagL i) j L bhave hZ : 0 ≤ z := Finset.sum_nonneg fun i _ => mul_nonneg (mul_nonneg (by norm_num)(side_pos _).le) (stripe_pos _ _ _ _ _)have hx : 0 ≤ mutedR b.post j s := surcharge_nonneg _ _ _have hi : 0 ≤ special j b := flag_nonneg _ _have hv := stripe_pos a (tagM (mainIx j)) j L bhave hh := side_pos Munfold tokenunfold z at *cases s <;> simp only [↓reduceIte,Bool.false_eq_true] <;>refine ⟨?_,?_,?_,fun H => ?_⟩ <;> first | linarith | contradictionlemma tokens_nonneg (a : Grade → ℕ) (L : Path M) (b : Beat M) (j : ℕ) (s : Bool) :0 ≤ token a L j s b := (side_pos M).le.trans (token_floor a j s L b).1lemma amp_test {s : Scene M} (h : Climb s) (u : Grid M) :‖gain s u‖ ≤ ampU s u ∧ ampU s u ≤ 4 ∧∃ b : Bool, ampU s u=‖scalar (s.smaller b) u‖ := byhave H (b) := (scalar_norm (h.child b) u).trans (h.child b).liftconstructor· apply (norm_halfcomplex _ _).transhave h1 : ‖scalar (s.smaller false) u‖ ≤ ampU s u := le_max_left _ _have h2 : ‖scalar (s.smaller true) u‖ ≤ ampU s u := le_max_right _ _linarith· unfold ampUrefine ⟨max_le (H false) (H true),?_⟩by_cases hh : ‖scalar (s.smaller true) u‖ ≤ ‖scalar (s.smaller false) u‖exact ⟨false,max_eq_left hh⟩exact ⟨true,max_eq_right (le_of_not_ge hh)⟩lemma side_ant (i j : ℕ) (h : i ≤ j) : side j ≤ side i :=pow_le_pow_of_le_one (by norm_num) (by norm_num) h/-- Each unmasked direct jump outside the main intervals can be paid by its amplitude-selectedcoupons. During the recursion node n hasn't entered or is unmasked for its scalar level. -/lemma direct_point {s : Scene M} {L : Path M} {x u : Grid M} (h : Trip x s L)(j : ℕ) (c : Bool) (a : Grade → ℕ) (hh : shades a u L j)(n : ℕ) (l r : Path M) (b : Beat M)(hR : c=true → stall u (tagM (mainIx j)) j L l)(hc : ∀ i ∈ Finset.Ico (lowI j c) n, stall u (tagL i) j L l)(_hn : n ∈ Set.Icc (lowI j c) (highI j M c)) (hl : L=l++r)(hm : b∈l) (hb : n < highI j M c → 4*side n < ampU b.post u) :‖proceeds x u b‖ ≤ token a L j c b := bylet t := lowI j c; let B := side t; let q := b.post; let s := playsL j M clet K := t+Mlet v := token a L j c blet p := ampU q uhave ht := trip_attend h b (by rw [hl]; simp [hm])have H := token_floor a j c L bchange _ ≤ v ∧ _ ≤ v ∧ _ ≤ v ∧ (c=true→_ ≤ v) at Hobtain ⟨hP,hB,z,hz⟩ := amp_test ht.1.climb uchange p ≤ 4 at hBchange p=_ at hzrw [proceeds,norm_scaleC,ht.2.2.1,one_mul]apply hP.transby_cases hi : 4*B < p· have he : c=true := byby_contra hehave HE : t=0 := ite_eq_right heunfold B at hi; rw [HE,show side 0=1 by simp [side]] at hi; linarithhave hI : mainIx j=t := by unfold t lowI; rw [ite_eq_left he]apply le_trans _ (H.2.2.2 he)by_cases ha : hazard q true t· have HF : special j b=1 :=ite_eq_left ⟨(show 0 < mainIx j + 1 by omega),bychange hazard q true (mainIx j+1-1); rw [hI]; exact ha⟩rw [HF]linarith [stripe_pos a (tagM (mainIx j)) j L b]· have HV : snag (tagM (mainIx j)) u b := byrw [hI]; refine ⟨⟨z,?_⟩,ha⟩change B^2 ≤ energy (q.smaller z) uhave hi' := scalar_energy (q.smaller z) (ht.1.climb.child z) uchange p=‖scalar (q.smaller z) u‖ at hzrw [←hz] at hi'nlinarith [show 0 < B from side_pos _]have HW := hh _ l r hl (hR he) b hm HVrw [show stripe a (tagM (mainIx j)) j L b=1 from ite_eq_left HW]have hx : 0 ≤ special j b := flag_nonneg _ _linarithhave hk : p ≤ 4*B := le_of_not_gt hiby_cases h : p < side K· apply le_trans _ H.1exact h.le.trans (side_ant M K (by unfold K; omega))have hq : side K ≤ p := le_of_not_gt hlet goodN (i : ℕ) := t ≤ i ∧ side i ≤ phave HX : goodN K := ⟨by unfold K; omega,hq⟩have HF : ∃ i,goodN i := ⟨K,HX⟩let i := Nat.find HFhave hE : goodN i := Nat.find_spec HFhave hV : i ≤ K := Nat.find_min' HF HXhave hS : i∈s := Finset.mem_Ico.mpr ⟨hE.1,Nat.lt_succ_of_le hV⟩have HI : p ≤ 4*side i := byby_cases HC : t=i· unfold B at hk; rwa [← HC]have HH := Nat.find_min HF (m:=i-1) (by have hi : t < i := lt_of_le_of_ne hE.1 HC; change i-1 < i; omega)have hx' : p < side (i-1) := lt_of_not_ge fun H =>HH ⟨Nat.le_sub_one_of_lt (lt_of_le_of_ne hE.1 HC), H⟩have H := side_succ (i-1)have HV : 0 < i := by have hi := hE.1; omegarw [Nat.sub_add_cancel HV] at Hnlinarith [side_pos i]have hj : i < n := byby_cases hz : n < highI j M c· by_contra! heexact not_lt_of_ge (HI.trans (mul_le_mul_of_nonneg_left (side_ant n i he) (by norm_num)))(hb hz)exact (Finset.mem_Ico.mp hS).2.trans_le (le_of_not_gt hz)apply HI.transby_cases hv : hazard q false i· apply le_trans _ H.2.1linarith [pricey b.post j c i (show picks q i j c from ⟨hS,hv⟩)]· let g := tagL ihave hb : stall u g j L l := hc _ (Finset.mem_Ico.mpr ⟨hE.1,hj⟩)have hi : betweenS (a g) (billWait g j L) b :=hh g l r hl hb b hm ⟨⟨z,(show side i ≤ ‖scalar _ _‖ from le_trans hE.2 hz.le)⟩,hv⟩have hx' : stripe a g j L b=1 := ite_eq_left hiapply le_trans _ H.2.2.1calc_ = 4*side i*stripe a (tagL i) j L b := by rw [hx']; ring_ ≤ _ := Finset.single_le_sum (f:=fun i => 4*side i*stripe a (tagL i) j L b) (fun k _ =>mul_nonneg (mul_nonneg (by norm_num) (side_pos _).le) (stripe_pos _ _ _ _ _)) hSdef tokenCost (j : ℕ) (s : Bool) (L : Path M) :=1 + 512*subtotal (fun b => mutedR b.post j s) L+(∑ i∈playsL j M s,4*side i*(billWait (tagL i) j L:ℝ))+(if s then 4*(subtotal (special j) L+(billWait (tagM (mainIx j)) j L:ℝ)) else 0)lemma cross_subtotal (l : Path M) (s : Finset ℕ) (f : Beat M → ℕ → ℝ) :subtotal (fun b => ∑ i∈s,f b i) l=∑ i∈s,subtotal (fun b => f b i) l := byinduction l with| nil => simp only [subtotal_nil,Finset.sum_const_zero]| cons b l ih =>rw [subtotal_cons,ih]; simp_rw [subtotal_cons,Finset.sum_add_distrib]lemma max_tokens {x : Grid M} (L : Path M) (h : Trip x s L)(a : Grade→ℕ) (j : ℕ) (p : Bool)(hh : L.length ≤ M) :subtotal (token a L j p) L ≤ tokenCost j p L := bylet C i := 4*side ihave h1 : subtotal (fun _ => side M) L ≤ 1 := byrw [subt_constant]have H : (L.length:ℝ) ≤ 2^M := by exact_mod_cast (hh.trans Nat.lt_two_pow_self.le)apply le_trans (mul_le_mul_of_nonneg_left H (side_pos _).le)rw [side_card]have h2 (T : Finset ℕ) :subtotal (fun b => ∑ i∈T,4*side i *stripe a (tagL i) j L b) L ≤∑ i∈T,4*side i*(billWait (tagL i) j L:ℝ) := byrw [cross_subtotal _ _ (fun b i => _)]apply Finset.sum_le_sum; intro i _rw [subtR]; exact mul_le_mul_of_nonneg_left (stripe_bill _ _ _ _ x h)(mul_nonneg (by norm_num) (side_pos _).le)have HE (b : Bool) :subtotal (fun B : Beat M => 512*mutedR B.post j b) L=512*subtotal (fun B => mutedR B.post j b) L :=subtR _ _ _unfold token tokenCosthave h3 := stripe_bill a (tagM (mainIx j)) j L x hcases p <;>simp only [Bool.false_eq_true,↓reduceIte,add_zero]· rw [blend _ (f:=fun _ => _) (g:=fun _ => _),blend _ (f:=fun _=>_) (g:=fun _=>_),HE]linarith [h2 (playsL j M false)]· simp_rw [blend _ (f:=fun b => _) (g:=fun b => _)]rw [HE,subtR _ _ 4,blend _ (f:=special j)]linarith [h2 (playsL j M true)]end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223import OAI.Analysis.FourierLLogL.Assembly.Duration/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace Troupeopen Run Streakdef lowI (j : ℕ) (b : Bool) := if b then mainIx j else 0def highI (j M : ℕ) (b : Bool) := lowI j b+M+1def playsL (j M : ℕ) (b : Bool) := Finset.Ico (lowI j b) (highI j M b)def picks (s : Scene M) (i j : ℕ) (b : Bool) :=i ∈ playsL j M b ∧ hazard s false idef priciest (s : Scene M) (j : ℕ) (b : Bool) :=if h : ∃ i, picks s i j b then Nat.find h else lowI j bdef mutedR (s : Scene M) (j : ℕ) (b : Bool) :=surcharge s false (priciest s j b)/-- scalar edge charges pay the largest bad level, chosen locally at the pre-bit moment. -/lemma pricey (s : Scene M) (j : ℕ) (b : Bool) (i : ℕ) (h : picks s i j b) :side i ≤ 128*mutedR s j b := bylet n := priciest s j bhave hi : ∃ i, picks s i j b := ⟨i,h⟩have hn : n=Nat.find hi := dite_eq_left hihave HE : hazard s false n := hn.symm ▸ (Nat.find_spec hi).2have H : side i ≤ side n := pow_le_pow_of_le_one (by norm_num) (by norm_num)(hn.le.trans (Nat.find_min' hi h))change side n / 128 ≤ edgeW s n at HEchange _ ≤ 128*surcharge s false nrw [surcharge,ite_eq_left (show hazard s false n from HE)]; linarithdef special (j : ℕ) (b : Beat M) := (rose (tagM (mainIx j +1)) (0:Grid M)).flag b.postdef token (a : Grade → ℕ) (L : Path M) (j : ℕ) (s : Bool) (b : Beat M) :=side M+512*mutedR b.post j s+(∑ i∈playsL j M s,4*side i*stripe a (tagL i) j L b) +(if s then 4*(special j b+stripe a (tagM (mainIx j)) j L b) else 0)lemma token_floor (a : Grade → ℕ) (j : ℕ) (s : Bool) (L : Path M) (b : Beat M) :side M ≤ token a L j s b ∧ 512*mutedR b.post j s ≤ token a L j s b ∧(∑ i∈playsL j M s,4*side i*stripe a (tagL i) j L b) ≤ token a L j s b ∧(s=true → 4*(special j b+stripe a (tagM (mainIx j)) j L b) ≤ token a L j s b) := bylet z := ∑ i∈playsL j M s,4*side i*stripe a (tagL i) j L bhave hZ : 0 ≤ z := Finset.sum_nonneg fun i _ => mul_nonneg (mul_nonneg (by norm_num)(side_pos _).le) (stripe_pos _ _ _ _ _)have hx : 0 ≤ mutedR b.post j s := surcharge_nonneg _ _ _have hi : 0 ≤ special j b := flag_nonneg _ _have hv := stripe_pos a (tagM (mainIx j)) j L bhave hh := side_pos Munfold tokenunfold z at *cases s <;> simp only [↓reduceIte,Bool.false_eq_true] <;>refine ⟨?_,?_,?_,fun H => ?_⟩ <;> first | linarith | contradictionlemma tokens_nonneg (a : Grade → ℕ) (L : Path M) (b : Beat M) (j : ℕ) (s : Bool) :0 ≤ token a L j s b := (side_pos M).le.trans (token_floor a j s L b).1lemma amp_test {s : Scene M} (h : Climb s) (u : Grid M) :‖gain s u‖ ≤ ampU s u ∧ ampU s u ≤ 4 ∧∃ b : Bool, ampU s u=‖scalar (s.smaller b) u‖ := byhave H (b) := (scalar_norm (h.child b) u).trans (h.child b).liftconstructor· apply (norm_halfcomplex _ _).transhave h1 : ‖scalar (s.smaller false) u‖ ≤ ampU s u := le_max_left _ _have h2 : ‖scalar (s.smaller true) u‖ ≤ ampU s u := le_max_right _ _linarith· unfold ampUrefine ⟨max_le (H false) (H true),?_⟩by_cases hh : ‖scalar (s.smaller true) u‖ ≤ ‖scalar (s.smaller false) u‖exact ⟨false,max_eq_left hh⟩exact ⟨true,max_eq_right (le_of_not_ge hh)⟩lemma side_ant (i j : ℕ) (h : i ≤ j) : side j ≤ side i :=pow_le_pow_of_le_one (by norm_num) (by norm_num) h/-- Each unmasked direct jump outside the main intervals can be paid by its amplitude-selectedcoupons. During the recursion node n hasn't entered or is unmasked for its scalar level. -/lemma direct_point {s : Scene M} {L : Path M} {x u : Grid M} (h : Trip x s L)(j : ℕ) (c : Bool) (a : Grade → ℕ) (hh : shades a u L j)(n : ℕ) (l r : Path M) (b : Beat M)(hR : c=true → stall u (tagM (mainIx j)) j L l)(hc : ∀ i ∈ Finset.Ico (lowI j c) n, stall u (tagL i) j L l)(_hn : n ∈ Set.Icc (lowI j c) (highI j M c)) (hl : L=l++r)(hm : b∈l) (hb : n < highI j M c → 4*side n < ampU b.post u) :‖proceeds x u b‖ ≤ token a L j c b := bylet t := lowI j c; let B := side t; let q := b.post; let s := playsL j M clet K := t+Mlet v := token a L j c blet p := ampU q uhave ht := trip_attend h b (by rw [hl]; simp [hm])have H := token_floor a j c L bchange _ ≤ v ∧ _ ≤ v ∧ _ ≤ v ∧ (c=true→_ ≤ v) at Hobtain ⟨hP,hB,z,hz⟩ := amp_test ht.1.climb uchange p ≤ 4 at hBchange p=_ at hzrw [proceeds,norm_scaleC,ht.2.2.1,one_mul]apply hP.transby_cases hi : 4*B < p· have he : c=true := byby_contra hehave HE : t=0 := ite_eq_right heunfold B at hi; rw [HE,show side 0=1 by simp [side]] at hi; linarithhave hI : mainIx j=t := by unfold t lowI; rw [ite_eq_left he]apply le_trans _ (H.2.2.2 he)by_cases ha : hazard q true t· have HF : special j b=1 :=ite_eq_left ⟨(show 0 < mainIx j + 1 by omega),bychange hazard q true (mainIx j+1-1); rw [hI]; exact ha⟩rw [HF]linarith [stripe_pos a (tagM (mainIx j)) j L b]· have HV : snag (tagM (mainIx j)) u b := byrw [hI]; refine ⟨⟨z,?_⟩,ha⟩change B^2 ≤ energy (q.smaller z) uhave hi' := scalar_energy (q.smaller z) (ht.1.climb.child z) uchange p=‖scalar (q.smaller z) u‖ at hzrw [←hz] at hi'nlinarith [show 0 < B from side_pos _]have HW := hh _ l r hl (hR he) b hm HVrw [show stripe a (tagM (mainIx j)) j L b=1 from ite_eq_left HW]have hx : 0 ≤ special j b := flag_nonneg _ _linarithhave hk : p ≤ 4*B := le_of_not_gt hiby_cases h : p < side K· apply le_trans _ H.1exact h.le.trans (side_ant M K (by unfold K; omega))have hq : side K ≤ p := le_of_not_gt hlet goodN (i : ℕ) := t ≤ i ∧ side i ≤ phave HX : goodN K := ⟨by unfold K; omega,hq⟩have HF : ∃ i,goodN i := ⟨K,HX⟩let i := Nat.find HFhave hE : goodN i := Nat.find_spec HFhave hV : i ≤ K := Nat.find_min' HF HXhave hS : i∈s := Finset.mem_Ico.mpr ⟨hE.1,Nat.lt_succ_of_le hV⟩have HI : p ≤ 4*side i := byby_cases HC : t=i· unfold B at hk; rwa [← HC]have HH := Nat.find_min HF (m:=i-1) (by have hi : t < i := lt_of_le_of_ne hE.1 HC; change i-1 < i; omega)have hx' : p < side (i-1) := lt_of_not_ge fun H =>HH ⟨Nat.le_sub_one_of_lt (lt_of_le_of_ne hE.1 HC), H⟩have H := side_succ (i-1)have HV : 0 < i := by have hi := hE.1; omegarw [Nat.sub_add_cancel HV] at Hnlinarith [side_pos i]have hj : i < n := byby_cases hz : n < highI j M c· by_contra! heexact not_lt_of_ge (HI.trans (mul_le_mul_of_nonneg_left (side_ant n i he) (by norm_num)))(hb hz)exact (Finset.mem_Ico.mp hS).2.trans_le (le_of_not_gt hz)apply HI.transby_cases hv : hazard q false i· apply le_trans _ H.2.1linarith [pricey b.post j c i (show picks q i j c from ⟨hS,hv⟩)]· let g := tagL ihave hb : stall u g j L l := hc _ (Finset.mem_Ico.mpr ⟨hE.1,hj⟩)have hi : betweenS (a g) (billWait g j L) b :=hh g l r hl hb b hm ⟨⟨z,(show side i ≤ ‖scalar _ _‖ from le_trans hE.2 hz.le)⟩,hv⟩have hx' : stripe a g j L b=1 := ite_eq_left hiapply le_trans _ H.2.2.1calc_ = 4*side i*stripe a (tagL i) j L b := by rw [hx']; ring_ ≤ _ := Finset.single_le_sum (f:=fun i => 4*side i*stripe a (tagL i) j L b) (fun k _ =>mul_nonneg (mul_nonneg (by norm_num) (side_pos _).le) (stripe_pos _ _ _ _ _)) hSdef tokenCost (j : ℕ) (s : Bool) (L : Path M) :=1 + 512*subtotal (fun b => mutedR b.post j s) L+(∑ i∈playsL j M s,4*side i*(billWait (tagL i) j L:ℝ))+(if s then 4*(subtotal (special j) L+(billWait (tagM (mainIx j)) j L:ℝ)) else 0)lemma cross_subtotal (l : Path M) (s : Finset ℕ) (f : Beat M → ℕ → ℝ) :subtotal (fun b => ∑ i∈s,f b i) l=∑ i∈s,subtotal (fun b => f b i) l := byinduction l with| nil => simp only [subtotal_nil,Finset.sum_const_zero]| cons b l ih =>rw [subtotal_cons,ih]; simp_rw [subtotal_cons,Finset.sum_add_distrib]lemma max_tokens {x : Grid M} (L : Path M) (h : Trip x s L)(a : Grade→ℕ) (j : ℕ) (p : Bool)(hh : L.length ≤ M) :subtotal (token a L j p) L ≤ tokenCost j p L := bylet C i := 4*side ihave h1 : subtotal (fun _ => side M) L ≤ 1 := byrw [subt_constant]have H : (L.length:ℝ) ≤ 2^M := by exact_mod_cast (hh.trans Nat.lt_two_pow_self.le)apply le_trans (mul_le_mul_of_nonneg_left H (side_pos _).le)rw [side_card]have h2 (T : Finset ℕ) :subtotal (fun b => ∑ i∈T,4*side i *stripe a (tagL i) j L b) L ≤∑ i∈T,4*side i*(billWait (tagL i) j L:ℝ) := byrw [cross_subtotal _ _ (fun b i => _)]apply Finset.sum_le_sum; intro i _rw [subtR]; exact mul_le_mul_of_nonneg_left (stripe_bill _ _ _ _ x h)(mul_nonneg (by norm_num) (side_pos _).le)have HE (b : Bool) :subtotal (fun B : Beat M => 512*mutedR B.post j b) L=512*subtotal (fun B => mutedR B.post j b) L :=subtR _ _ _unfold token tokenCosthave h3 := stripe_bill a (tagM (mainIx j)) j L x hcases p <;>simp only [Bool.false_eq_true,↓reduceIte,add_zero]· rw [blend _ (f:=fun _ => _) (g:=fun _ => _),blend _ (f:=fun _=>_) (g:=fun _=>_),HE]linarith [h2 (playsL j M false)]· simp_rw [blend _ (f:=fun b => _) (g:=fun b => _)]rw [HE,subtR _ _ 4,blend _ (f:=special j)]linarith [h2 (playsL j M true)]end Troupeend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215import OAI.Analysis.FourierLLogL.Assembly.Chill/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef holders (j : ℕ) := Finset.Ico 0 (mainIx j+2)def picker (j M : ℕ) : Policy M := fun s => priciest s j truedef bouts (i _j : ℕ) (s : Scene M) := surcharge s true (i-1)def aura (i : ℕ) (e : Event j M) := edgeFee (fun _ => i-1) true edef upperFare (e : Event j M) :=10^140*(height j/Thermal.H j)*beginFee e+512*edgeFee (picker j M) false e+4*10^20*infoFee e + 10^40*Thermal.H j^40* (∑ i∈holders j, aura i e)lemma stamp_upper (s : Scene M) (j : ℕ) :stamp s j ≤ 512*mutedR s j true + 10^20*fax s+10^40*Thermal.H j^40*(∑ i∈holders j,bouts i j s) := bylet R := holders j; let n := mainIx j; let a := Thermal.H jlet f (i) := bouts i j shave he : 1 ≤ a := H_ge jhave hp : 0 < a := H_pos jhave hi (i) : 0 ≤ f i := surcharge_nonneg _ _ _have HR : 0 ≤ ∑ i∈R,f i := Finset.sum_nonneg fun i _ => hi _let K := Finset.Ico 0 (n+1)have HH :∑ i∈K, parody s i/depthRate i ≤ (10^6*a^40)*∑ i∈R, f i := byhave he' : 0 ≤ 10^6*a^40 := by positivityapply le_trans (b:=(10^6*a^40)*∑ i∈K,f i)· rw [Finset.mul_sum]apply Finset.sum_le_sum; intro i hvhave hI : i ≤ n := byhave hx : i < n+1 := (Finset.mem_Ico.mp hv).2; omegahave Hx : parody s i ≤ 10^6*a^32*f i := parody_fee s j i (hI.trans (Nat.le_add_right _ _))have Hv := depth_rate_fee i j hIrw [div_eq_mul_one_div]apply le_trans (mul_le_mul Hx Hv (by have := (rate_easy i).1; positivity)(by have := hi i; positivity)); change 10^6*a^32*f i*a^8 ≤ _exact le_of_eq (by ring)· apply mul_le_mul_of_nonneg_left _ he'refine Finset.sum_le_sum_of_subset_of_nonneg ?_ fun i _ _ => hi iunfold K R holders n; intro i hiobtain ⟨ha,hb⟩ := Finset.mem_Ico.mp hi; exact Finset.mem_Ico.mpr ⟨ha,by omega⟩have HK : f (n+1) ≤ ∑ i∈R,f i := Finset.single_le_sum (fun i _ => hi i)(Finset.mem_Ico.mpr ⟨by omega,by unfold n; omega⟩)have HT : parody s (n+1) ≤ (10^6*a^40)*∑ i∈R, f i := byapply (parody_fee s j (n+1) le_rfl).transchange 10^6*a^32*f (n+1) ≤ _gcongr <;> first| omega| apply hiunfold stamp stampAuxchange _ + (4*parody s (n+1)+10^20*(fax s+∑ i∈K,_)) ≤ _+_+10^40*a^40*(∑ i∈R,f i)nlinarith [mul_nonneg (show 0 ≤ a^40 by positivity) HR]private lemma bound_bit (s : Scene M) (k : Bool)(h : Safe s j J f) (he : s.live=true) (hp : work s j J f) :let b := Event.march s (Turn.move (j:=j)) kbillOf b ≤ upperFare b := byintro bunfold b upperFarelet r := s.norm/s.masshave ht : normStamp s j=r*stamp s j := ite_eq_left hehave h1 : edgeFee (picker j M) false b=r*mutedR s j true := byunfold b edgeFee tollsimp only [true_and,ite_eq_left hp.2.2, r, picker,mutedR]have h2 (i) : aura i b=r*bouts i j s := byunfold aura b edgeFee tollsimp only [true_and,ite_eq_left hp.2.2,r,bouts]have HH : 0 ≤ r := div_nonneg h.norm_ok h.mass_lowerchange normStamp s j ≤ _*0+512*edgeFee (picker j M) false b+4*10^20*(1/4*r*fax s)+ 10^40* Thermal.H j^40*(∑ i∈holders j,aura i b)simp_rw [h2,h1,ht,← Finset.mul_sum]apply le_trans (mul_le_mul_of_nonneg_left (stamp_upper s j) HH)exact le_of_eq (by ring)lemma short_trace_bound (t : Play j M s) (h : t.Follows J f) (he : s.live=true) :let v := trace false tv.flatFee billOf ≤ v.flatFee upperFare := byinduction t with| rest s => simp only [trace,flat_finish,le_refl]| freeze s t ih =>intro vchange flatFee (.finish s true : Road j M s) billOf ≤ flatFee (.finish s true) upperFarerw [flat_finish,flat_finish]| ticket s t ih =>simp only [trace,flat_push]apply add_le_add _ (ih h.2.2.2.2 he)unfold upperFare billOf beginFee edgeFee infoFee gateTaxhave H : ∀ i, aura i (.pace s .renew : Event j M)=0 := fun i => rflsimp only [H,reset,he,↓reduceIte,Finset.sum_const_zero]exact le_of_eq (by ring)| jump s l r il ir =>simp only [trace, flat_fork _ _ (traced _ false h)]apply Ex_mono; intro bapply add_le_add (bound_bit s b h.1 he h.2.1)cases bexact il h.2.2.2.1 heexact ir h.2.2.2.2 he| attempt s u l r il ir =>simp only [trace,flat_fork _ _ (traced _ false h)]apply Ex_mono; intro bapply add_le_add· have H : ∀ i, aura i (.march s (.ask u) b)=0 := fun i => rflsimp [upperFare,H,beginFee,edgeFee,infoFee,billOf]· cases b; exact il h.2.2.2.2.1 he; exact ir h.2.2.2.2.2 helemma linear_fee (t : Road j M s) (A B : Event j M → ℝ) (a : ℝ) :flatFee t (fun i => A i+B i)=flatFee t A+flatFee t B ∧flatFee t (fun i => a*A i)=a*flatFee t A := byhave HE (l : List (Event j M)) :(l.map (fun i => A i+B i)).sum=(l.map A).sum+(l.map B).sum ∧(l.map (fun i => a*A i)).sum=a*(l.map A).sum := byinduction l with| nil => simp| cons b l ih =>simp only [List.map_cons,List.sum_cons, ih.1, ih.2]constructor <;> ringconstructor· unfold flatFee expHike Journal.fee; simp_rw [(HE _).1, Ex_add]unfold flatFee expHike Journal.fee; simp_rw [(HE _).2, Ex_lmul]lemma sum_fee (t : Road j M s) (p : Finset ℕ) (f : ℕ → Event j M → ℝ) :t.flatFee (fun i => ∑ z∈p,f z i)=∑ z∈p,t.flatFee (f z) := byinduction p using Finset.induction_on with| empty =>have H (s : Journal j M) : s.fee (fun _ => 0)=0 := byunfold Journal.fee; induction s.events with| nil => simp| cons a l ih => simpsimp only [Finset.sum_empty,flatFee,expHike,H,Ex_const]| @insert a p ha ih =>simp only [Finset.sum_insert ha]rw [(linear_fee t (f a) (fun i => _) 0).1,ih]lemma upper_total :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ,(∀ x,f x ≤ exp (height j)) →let s := beginPlay f true∀ t : Road j M s, t.Trusted J f → 1/Thermal.H j ≤ s.mass →t.flatFee upperFare ≤ 10^190*height j := byfilter_upwards [global_edges, fisher_bound, final_coarse,hpoly 1 42] with j he hq ht hkM J f hF s t h hplet a := Thermal.H j; let d := height j; let phi := t.flatFeelet x := limitCobtain ⟨H1,H2⟩ := he M J f hF t h hphave H₃ := hq M J f hF t h hphave H₄ := (ht M J s f t h hp).2.2 rfllet R := holders jhave HH : ∑ i∈R,phi (aura i) ≤ 300000*x*a^2 := bycalc_ ≤ ∑ _i∈R,10000*x*a := Finset.sum_le_sum fun i hi => byhave hh := (Finset.mem_Ico.mp hi).2apply H2unfold testIx; omega_ ≤ _ := byunfold R holderssimp only [Finset.sum_const,Nat.card_Ico,Nat.sub_zero,nsmul_eq_mul]have he : ((mainIx j:ℕ):ℝ) ≤ 19*a := (main_bounds j (Nat.le_add_right _ 3)).2.1push_casthave HX : 1 ≤ a := H_ge _unfold x limitC; nlinarithlet f₁ := edgeFee (picker j M) false (j:=j)let C := 10^140*(d/a)let Y := 10^40*a^40have HY : 0 ≤ C ∧ 0 ≤ Y := byhave hi : 0 < a := H_pos _have hh : 0 < d := d_pos junfold C Y; constructor <;> positivityhave HE (A B : Event j M → ℝ) : phi (fun i => A i+B i)=phi A+phi B := (linear_fee t A B 1).1have HM (A : Event j M → ℝ) (c : ℝ) : phi (fun i => c*A i)=c*phi A := (linear_fee t A A c).2have H := H1 (picker j M)unfold upperFarechange phi (fun e => C*beginFee e+512*f₁ e+4*10^20*infoFee e + Y*(∑ i∈R,aura i e)) ≤ _simp_rw [HE (fun _ => _) (fun _ => _),HM]rw [show phi (fun e => ∑ i∈R,aura i e) = ∑ i∈R,phi (aura i) from sum_fee t R aura]have Ha : 1 ≤ a := H_ge _have hd : 0 ≤ d := (d_pos j).lechange phi f₁ ≤ 1000*d at Hchange phi infoFee ≤ x*d at H₃change phi beginFee ≤ 100*x*a at H₄have HZ : a^42 ≤ d := by simpa using hkhave HC : C*(100*x*a) ≤ 10^180*d := byhave He : 0<a := by linarithunfold x limitC Crw [show 10^140*(d/a)*(100*10^30*a)=10^172*d by field_simp; ring]linarithhave HL : Y*(300000*x*a^2) ≤ 10^78*d := byapply le_trans _ (mul_le_mul_of_nonneg_left HZ (by norm_num : (0:ℝ)≤10^78))unfold Y x limitCnlinarith [pow_nonneg (lt_of_lt_of_le zero_lt_one Ha).le 42]change _ ≤ 10^190*dhave HH' := mul_le_mul_of_nonneg_left HH HY.2have H₄' := mul_le_mul_of_nonneg_left H₄ HY.1unfold x limitC at *linarithend CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215import OAI.Analysis.FourierLLogL.Assembly.Chill/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupedef holders (j : ℕ) := Finset.Ico 0 (mainIx j+2)def picker (j M : ℕ) : Policy M := fun s => priciest s j truedef bouts (i _j : ℕ) (s : Scene M) := surcharge s true (i-1)def aura (i : ℕ) (e : Event j M) := edgeFee (fun _ => i-1) true edef upperFare (e : Event j M) :=10^140*(height j/Thermal.H j)*beginFee e+512*edgeFee (picker j M) false e+4*10^20*infoFee e + 10^40*Thermal.H j^40* (∑ i∈holders j, aura i e)lemma stamp_upper (s : Scene M) (j : ℕ) :stamp s j ≤ 512*mutedR s j true + 10^20*fax s+10^40*Thermal.H j^40*(∑ i∈holders j,bouts i j s) := bylet R := holders j; let n := mainIx j; let a := Thermal.H jlet f (i) := bouts i j shave he : 1 ≤ a := H_ge jhave hp : 0 < a := H_pos jhave hi (i) : 0 ≤ f i := surcharge_nonneg _ _ _have HR : 0 ≤ ∑ i∈R,f i := Finset.sum_nonneg fun i _ => hi _let K := Finset.Ico 0 (n+1)have HH :∑ i∈K, parody s i/depthRate i ≤ (10^6*a^40)*∑ i∈R, f i := byhave he' : 0 ≤ 10^6*a^40 := by positivityapply le_trans (b:=(10^6*a^40)*∑ i∈K,f i)· rw [Finset.mul_sum]apply Finset.sum_le_sum; intro i hvhave hI : i ≤ n := byhave hx : i < n+1 := (Finset.mem_Ico.mp hv).2; omegahave Hx : parody s i ≤ 10^6*a^32*f i := parody_fee s j i (hI.trans (Nat.le_add_right _ _))have Hv := depth_rate_fee i j hIrw [div_eq_mul_one_div]apply le_trans (mul_le_mul Hx Hv (by have := (rate_easy i).1; positivity)(by have := hi i; positivity)); change 10^6*a^32*f i*a^8 ≤ _exact le_of_eq (by ring)· apply mul_le_mul_of_nonneg_left _ he'refine Finset.sum_le_sum_of_subset_of_nonneg ?_ fun i _ _ => hi iunfold K R holders n; intro i hiobtain ⟨ha,hb⟩ := Finset.mem_Ico.mp hi; exact Finset.mem_Ico.mpr ⟨ha,by omega⟩have HK : f (n+1) ≤ ∑ i∈R,f i := Finset.single_le_sum (fun i _ => hi i)(Finset.mem_Ico.mpr ⟨by omega,by unfold n; omega⟩)have HT : parody s (n+1) ≤ (10^6*a^40)*∑ i∈R, f i := byapply (parody_fee s j (n+1) le_rfl).transchange 10^6*a^32*f (n+1) ≤ _gcongr <;> first| omega| apply hiunfold stamp stampAuxchange _ + (4*parody s (n+1)+10^20*(fax s+∑ i∈K,_)) ≤ _+_+10^40*a^40*(∑ i∈R,f i)nlinarith [mul_nonneg (show 0 ≤ a^40 by positivity) HR]private lemma bound_bit (s : Scene M) (k : Bool)(h : Safe s j J f) (he : s.live=true) (hp : work s j J f) :let b := Event.march s (Turn.move (j:=j)) kbillOf b ≤ upperFare b := byintro bunfold b upperFarelet r := s.norm/s.masshave ht : normStamp s j=r*stamp s j := ite_eq_left hehave h1 : edgeFee (picker j M) false b=r*mutedR s j true := byunfold b edgeFee tollsimp only [true_and,ite_eq_left hp.2.2, r, picker,mutedR]have h2 (i) : aura i b=r*bouts i j s := byunfold aura b edgeFee tollsimp only [true_and,ite_eq_left hp.2.2,r,bouts]have HH : 0 ≤ r := div_nonneg h.norm_ok h.mass_lowerchange normStamp s j ≤ _*0+512*edgeFee (picker j M) false b+4*10^20*(1/4*r*fax s)+ 10^40* Thermal.H j^40*(∑ i∈holders j,aura i b)simp_rw [h2,h1,ht,← Finset.mul_sum]apply le_trans (mul_le_mul_of_nonneg_left (stamp_upper s j) HH)exact le_of_eq (by ring)lemma short_trace_bound (t : Play j M s) (h : t.Follows J f) (he : s.live=true) :let v := trace false tv.flatFee billOf ≤ v.flatFee upperFare := byinduction t with| rest s => simp only [trace,flat_finish,le_refl]| freeze s t ih =>intro vchange flatFee (.finish s true : Road j M s) billOf ≤ flatFee (.finish s true) upperFarerw [flat_finish,flat_finish]| ticket s t ih =>simp only [trace,flat_push]apply add_le_add _ (ih h.2.2.2.2 he)unfold upperFare billOf beginFee edgeFee infoFee gateTaxhave H : ∀ i, aura i (.pace s .renew : Event j M)=0 := fun i => rflsimp only [H,reset,he,↓reduceIte,Finset.sum_const_zero]exact le_of_eq (by ring)| jump s l r il ir =>simp only [trace, flat_fork _ _ (traced _ false h)]apply Ex_mono; intro bapply add_le_add (bound_bit s b h.1 he h.2.1)cases bexact il h.2.2.2.1 heexact ir h.2.2.2.2 he| attempt s u l r il ir =>simp only [trace,flat_fork _ _ (traced _ false h)]apply Ex_mono; intro bapply add_le_add· have H : ∀ i, aura i (.march s (.ask u) b)=0 := fun i => rflsimp [upperFare,H,beginFee,edgeFee,infoFee,billOf]· cases b; exact il h.2.2.2.2.1 he; exact ir h.2.2.2.2.2 helemma linear_fee (t : Road j M s) (A B : Event j M → ℝ) (a : ℝ) :flatFee t (fun i => A i+B i)=flatFee t A+flatFee t B ∧flatFee t (fun i => a*A i)=a*flatFee t A := byhave HE (l : List (Event j M)) :(l.map (fun i => A i+B i)).sum=(l.map A).sum+(l.map B).sum ∧(l.map (fun i => a*A i)).sum=a*(l.map A).sum := byinduction l with| nil => simp| cons b l ih =>simp only [List.map_cons,List.sum_cons, ih.1, ih.2]constructor <;> ringconstructor· unfold flatFee expHike Journal.fee; simp_rw [(HE _).1, Ex_add]unfold flatFee expHike Journal.fee; simp_rw [(HE _).2, Ex_lmul]lemma sum_fee (t : Road j M s) (p : Finset ℕ) (f : ℕ → Event j M → ℝ) :t.flatFee (fun i => ∑ z∈p,f z i)=∑ z∈p,t.flatFee (f z) := byinduction p using Finset.induction_on with| empty =>have H (s : Journal j M) : s.fee (fun _ => 0)=0 := byunfold Journal.fee; induction s.events with| nil => simp| cons a l ih => simpsimp only [Finset.sum_empty,flatFee,expHike,H,Ex_const]| @insert a p ha ih =>simp only [Finset.sum_insert ha]rw [(linear_fee t (f a) (fun i => _) 0).1,ih]lemma upper_total :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ,(∀ x,f x ≤ exp (height j)) →let s := beginPlay f true∀ t : Road j M s, t.Trusted J f → 1/Thermal.H j ≤ s.mass →t.flatFee upperFare ≤ 10^190*height j := byfilter_upwards [global_edges, fisher_bound, final_coarse,hpoly 1 42] with j he hq ht hkM J f hF s t h hplet a := Thermal.H j; let d := height j; let phi := t.flatFeelet x := limitCobtain ⟨H1,H2⟩ := he M J f hF t h hphave H₃ := hq M J f hF t h hphave H₄ := (ht M J s f t h hp).2.2 rfllet R := holders jhave HH : ∑ i∈R,phi (aura i) ≤ 300000*x*a^2 := bycalc_ ≤ ∑ _i∈R,10000*x*a := Finset.sum_le_sum fun i hi => byhave hh := (Finset.mem_Ico.mp hi).2apply H2unfold testIx; omega_ ≤ _ := byunfold R holderssimp only [Finset.sum_const,Nat.card_Ico,Nat.sub_zero,nsmul_eq_mul]have he : ((mainIx j:ℕ):ℝ) ≤ 19*a := (main_bounds j (Nat.le_add_right _ 3)).2.1push_casthave HX : 1 ≤ a := H_ge _unfold x limitC; nlinarithlet f₁ := edgeFee (picker j M) false (j:=j)let C := 10^140*(d/a)let Y := 10^40*a^40have HY : 0 ≤ C ∧ 0 ≤ Y := byhave hi : 0 < a := H_pos _have hh : 0 < d := d_pos junfold C Y; constructor <;> positivityhave HE (A B : Event j M → ℝ) : phi (fun i => A i+B i)=phi A+phi B := (linear_fee t A B 1).1have HM (A : Event j M → ℝ) (c : ℝ) : phi (fun i => c*A i)=c*phi A := (linear_fee t A A c).2have H := H1 (picker j M)unfold upperFarechange phi (fun e => C*beginFee e+512*f₁ e+4*10^20*infoFee e + Y*(∑ i∈R,aura i e)) ≤ _simp_rw [HE (fun _ => _) (fun _ => _),HM]rw [show phi (fun e => ∑ i∈R,aura i e) = ∑ i∈R,phi (aura i) from sum_fee t R aura]have Ha : 1 ≤ a := H_ge _have hd : 0 ≤ d := (d_pos j).lechange phi f₁ ≤ 1000*d at Hchange phi infoFee ≤ x*d at H₃change phi beginFee ≤ 100*x*a at H₄have HZ : a^42 ≤ d := by simpa using hkhave HC : C*(100*x*a) ≤ 10^180*d := byhave He : 0<a := by linarithunfold x limitC Crw [show 10^140*(d/a)*(100*10^30*a)=10^172*d by field_simp; ring]linarithhave HL : Y*(300000*x*a^2) ≤ 10^78*d := byapply le_trans _ (mul_le_mul_of_nonneg_left HZ (by norm_num : (0:ℝ)≤10^78))unfold Y x limitCnlinarith [pow_nonneg (lt_of_lt_of_le zero_lt_one Ha).le 42]change _ ≤ 10^190*dhave HH' := mul_le_mul_of_nonneg_left HH HY.2have H₄' := mul_le_mul_of_nonneg_left H₄ HY.1unfold x limitC at *linarithend CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154import OAI.Analysis.FourierLLogL.Assembly.Verdictimport OAI.Analysis.FourierLLogL.Procedure.Rare/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupelemma burn_rate :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, 1000*((2:ℝ)^J) ≤ 2^M →∀ f : Grid M → ℝ, (∀ x, f x ≤ exp (height j)) →let s := beginPlay f true∀ t : Road j M s, Trusted J f t → 1/Thermal.H j ≤ s.mass →coldFee t ≤ 10^220*height j := byfilter_upwards [rare,log_mass_budget,hpoly 1 4] with j h1 h2 hd M J hm f hf s t h hhlet a := Thermal.H j; let d := height j; let P := s.actorlet c := 10*limitChave hp : 1 ≤ a := H_ge jhave ha : 0 < a := H_pos jhave he : a^4 ≤ d := by simpa using hdhave hD : 1 ≤ d := one_le_pow₀ (by norm_num)let k (x : Grid M) := t.hike xlet w (x : Grid M) := if (k x).froze then (1:ℝ) else 0let y (x : Grid M) := drought (k x).done.masshave HX : P.Ex w ≤ 1/a^10 := byapply le_trans _ (h1 M J hm f hf t h hh)apply Ex_mono; intro x; unfold wcases he : (k x).froze <;> simp_all only [k,Bool.false_eq_true,↓reduceIte,le_refl]have HH : P.Ex (fun i => y i^2) ≤ (c*a)^2 := h2 M J s f t h hhlet L := fun i => w i*y ilet K := fun i => w i*y i^2have hw (i) : w i ≤ 1 ∧ w i^2=w i := by unfold w; split <;> norm_numhave H : P.Ex K ≤ (c*a)^2 := le_trans (Ex_mono _ fun i =>mul_le_of_le_one_left (sq_nonneg (y i)) (hw _).1) HHhave HC : P.Ex L ≤ c := byhave Heq := Law.sq_Ex_mul P w ysimp_rw [(hw _).2] at Heqhave HJ : P.Ex w * P.Ex (fun i => y i^2) ≤ (1/a^10)*(c*a)^2 :=mul_le_mul HX HH (Ex_nonneg _ (fun _ => sq_nonneg _)) (by positivity)have HF : (1/a^10)*(c*a)^2 ≤ c^2 := byapply le_trans (b:=(1/a^2)*(c*a)^2)· apply mul_le_mul_of_nonneg_right _ (sq_nonneg _)exact one_div_le_one_div_of_le (by positivity) (pow_le_pow_right₀ hp (by omega))exact le_of_eq (by field_simp)change (P.Ex L)^2 ≤ _ at Heqhave hP : 0 < c := by unfold c limitC; norm_numnlinarithhave heq (x : Grid M) : coldLump (k x) =10^150* ((a+1)*(d+2)*w x+(a+d+3)*L x+K x) := byunfold coldLump chargeStaticunfold L K w ysplit_ifs <;> unfold d a <;> ringunfold coldFee expHikechange P.Ex (fun i => coldLump (k i)) ≤ 10^220*dsimp_rw [heq,Ex_lmul,Ex_add,Ex_lmul]have HR : a ≤ d := le_trans (by simpa using pow_le_pow_right₀ hp (by omega : 1≤4)) hehave Hs : a^2 ≤ d := le_trans (pow_le_pow_right₀ hp (by omega)) hehave HS : (a+1)*(d+2)*P.Ex w ≤ 6*d :=le_trans (mul_le_mul_of_nonneg_left HX (by positivity)) (byhave H : 1/a^10 ≤ 1/a := one_div_le_one_div_of_le ha (by simpa using pow_le_pow_right₀ hp (by omega : 1≤10))apply (mul_le_mul_of_nonneg_left H (show 0 ≤ (a+1)*(d+2) by positivity)).transrw [mul_one_div]apply (div_le_iff₀ ha).mpr; nlinarith)have HT : (a+d+3)*P.Ex L ≤ 5*d*c :=le_trans (mul_le_mul_of_nonneg_left HC (by positivity)) (byhave H : 0 ≤ c := by unfold c limitC; norm_numnlinarith)unfold c limitC at *nlinarithlemma grossOur :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, 1000*((2:ℝ)^J) ≤ 2^M →∀ f : Grid M → ℝ, (∀ x, f x ≤ exp (height j)) →let s := beginPlay f true∀ t : Play j M s, t.Follows J f → 1/Thermal.H j ≤ s.mass →yieldA t ≤ s.mass*(10^221*height j) := byfilter_upwards [cost_overall,burn_rate,upper_total,frostCompare] with j h1 h2 h3 h4 M J hC f hf s t h hmhave H := traced t false hhave HP := (Play.first h).mass_lowerlet v := trace false thave hE := h1 M J f s t h hfrw [due_restart rfl,add_zero] at hEapply le_trans hE (mul_le_mul_of_nonneg_left ?_ HP)have hc := h2 M J hC f hf v H hmhave he := h3 M J f hf v H hmhave HH := short_trace_bound t h rflapply (h4 M J f s t h rfl).transchange v.flatFee billOf ≤ v.flatFee upperFare at HHchange v.flatFee billOf+coldFee v ≤ _linarith [d_pos j]private lemma scale_drought (m : ℝ) (hm : 0 < m) (h : m ≤ 1) :m*drought m ≤ 4 ∧ m*(drought m)^2 ≤ 4 := byhave hh' : drought m= -log m := max_eq_left (by linarith [log_nonpos hm.le h])let x := drought mhave heq : m= (exp x)⁻¹ := by unfold x; rw [hh',exp_neg,inv_inv,exp_log hm]have H : x^2 /4 ≤ exp x := byhave h0 : exp x=(exp (x/2))^2 := by rw [pow_two,←exp_add]; ring_nfhave hi := add_one_le_exp (x/2)rw [h0]nlinarith [show 0 ≤ x from drought_pos m]have HH := mul_le_mul_of_nonneg_left H hm.lehave Hx : m*exp x=1 := by rw [heq,inv_mul_cancel₀ (exp_pos x).ne']change m*x≤4 ∧ m*x^2≤4constructor· nlinarith [mul_nonneg hm.le (sq_nonneg (x-1))]linarithlemma grossDry :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ,(∀ x, f x ≤ exp (height j)) →let s := beginPlay f false∀ t : Play j M s, t.Follows J f → s.mass ≤ 1/Thermal.H j →yieldA t ≤ 10^152*height j := byfilter_upwards [cost_overall,chill_descendants,hpoly 1 1] with j h1 h2 h3 M J f hf s t h hmhave H := h1 _ _ f s t h hfrw [due_restart rfl,add_zero] at Happly H.translet m := s.mass; let d := height j; let a := Thermal.H jhave hh : 0 ≤ m := (Play.first h).mass_lowerhave ha : 1 ≤ a := H_ge _have hd : 1 ≤ d := one_le_pow₀ (by norm_num)have hp : a ≤ d := by simpa using h3have hz : 0 < a := by linarithchange m≤1/a at hmhave hi : m*a ≤ 1 := (le_div_iff₀ hz).mp hmhave hr : m ≤ 1 := by nlinarithchange m*_ ≤ 10^152*drcases eq_or_lt_of_le hh with hh|hh· rw [←hh,zero_mul]; positivityapply le_trans (mul_le_mul_of_nonneg_left (h2 M J f s t h rfl rfl hh) hh.le)let x := drought mchange m*(10^150*(a+1+x)*(d+2+x)) ≤ _have he : m*x ≤ 4 ∧ m*x^2 ≤ 4 := scale_drought m hh hrnlinarith [mul_le_mul_of_nonneg_right hi (show 0 ≤ d by linarith),mul_le_mul_of_nonneg_right he.1(show 0 ≤ a by linarith),mul_le_mul_of_nonneg_right he.1 (show 0 ≤ d by linarith)]end CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154import OAI.Analysis.FourierLLogL.Assembly.Verdictimport OAI.Analysis.FourierLLogL.Procedure.Rare/-! # The uniform output path -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Pathsopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Capture Chart Snapshotvariable {M j J : ℕ} {s q : Scene M} {f : Grid M → ℝ}open scoped Classicalnamespace CastShowopen Troupelemma burn_rate :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, 1000*((2:ℝ)^J) ≤ 2^M →∀ f : Grid M → ℝ, (∀ x, f x ≤ exp (height j)) →let s := beginPlay f true∀ t : Road j M s, Trusted J f t → 1/Thermal.H j ≤ s.mass →coldFee t ≤ 10^220*height j := byfilter_upwards [rare,log_mass_budget,hpoly 1 4] with j h1 h2 hd M J hm f hf s t h hhlet a := Thermal.H j; let d := height j; let P := s.actorlet c := 10*limitChave hp : 1 ≤ a := H_ge jhave ha : 0 < a := H_pos jhave he : a^4 ≤ d := by simpa using hdhave hD : 1 ≤ d := one_le_pow₀ (by norm_num)let k (x : Grid M) := t.hike xlet w (x : Grid M) := if (k x).froze then (1:ℝ) else 0let y (x : Grid M) := drought (k x).done.masshave HX : P.Ex w ≤ 1/a^10 := byapply le_trans _ (h1 M J hm f hf t h hh)apply Ex_mono; intro x; unfold wcases he : (k x).froze <;> simp_all only [k,Bool.false_eq_true,↓reduceIte,le_refl]have HH : P.Ex (fun i => y i^2) ≤ (c*a)^2 := h2 M J s f t h hhlet L := fun i => w i*y ilet K := fun i => w i*y i^2have hw (i) : w i ≤ 1 ∧ w i^2=w i := by unfold w; split <;> norm_numhave H : P.Ex K ≤ (c*a)^2 := le_trans (Ex_mono _ fun i =>mul_le_of_le_one_left (sq_nonneg (y i)) (hw _).1) HHhave HC : P.Ex L ≤ c := byhave Heq := Law.sq_Ex_mul P w ysimp_rw [(hw _).2] at Heqhave HJ : P.Ex w * P.Ex (fun i => y i^2) ≤ (1/a^10)*(c*a)^2 :=mul_le_mul HX HH (Ex_nonneg _ (fun _ => sq_nonneg _)) (by positivity)have HF : (1/a^10)*(c*a)^2 ≤ c^2 := byapply le_trans (b:=(1/a^2)*(c*a)^2)· apply mul_le_mul_of_nonneg_right _ (sq_nonneg _)exact one_div_le_one_div_of_le (by positivity) (pow_le_pow_right₀ hp (by omega))exact le_of_eq (by field_simp)change (P.Ex L)^2 ≤ _ at Heqhave hP : 0 < c := by unfold c limitC; norm_numnlinarithhave heq (x : Grid M) : coldLump (k x) =10^150* ((a+1)*(d+2)*w x+(a+d+3)*L x+K x) := byunfold coldLump chargeStaticunfold L K w ysplit_ifs <;> unfold d a <;> ringunfold coldFee expHikechange P.Ex (fun i => coldLump (k i)) ≤ 10^220*dsimp_rw [heq,Ex_lmul,Ex_add,Ex_lmul]have HR : a ≤ d := le_trans (by simpa using pow_le_pow_right₀ hp (by omega : 1≤4)) hehave Hs : a^2 ≤ d := le_trans (pow_le_pow_right₀ hp (by omega)) hehave HS : (a+1)*(d+2)*P.Ex w ≤ 6*d :=le_trans (mul_le_mul_of_nonneg_left HX (by positivity)) (byhave H : 1/a^10 ≤ 1/a := one_div_le_one_div_of_le ha (by simpa using pow_le_pow_right₀ hp (by omega : 1≤10))apply (mul_le_mul_of_nonneg_left H (show 0 ≤ (a+1)*(d+2) by positivity)).transrw [mul_one_div]apply (div_le_iff₀ ha).mpr; nlinarith)have HT : (a+d+3)*P.Ex L ≤ 5*d*c :=le_trans (mul_le_mul_of_nonneg_left HC (by positivity)) (byhave H : 0 ≤ c := by unfold c limitC; norm_numnlinarith)unfold c limitC at *nlinarithlemma grossOur :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, 1000*((2:ℝ)^J) ≤ 2^M →∀ f : Grid M → ℝ, (∀ x, f x ≤ exp (height j)) →let s := beginPlay f true∀ t : Play j M s, t.Follows J f → 1/Thermal.H j ≤ s.mass →yieldA t ≤ s.mass*(10^221*height j) := byfilter_upwards [cost_overall,burn_rate,upper_total,frostCompare] with j h1 h2 h3 h4 M J hC f hf s t h hmhave H := traced t false hhave HP := (Play.first h).mass_lowerlet v := trace false thave hE := h1 M J f s t h hfrw [due_restart rfl,add_zero] at hEapply le_trans hE (mul_le_mul_of_nonneg_left ?_ HP)have hc := h2 M J hC f hf v H hmhave he := h3 M J f hf v H hmhave HH := short_trace_bound t h rflapply (h4 M J f s t h rfl).transchange v.flatFee billOf ≤ v.flatFee upperFare at HHchange v.flatFee billOf+coldFee v ≤ _linarith [d_pos j]private lemma scale_drought (m : ℝ) (hm : 0 < m) (h : m ≤ 1) :m*drought m ≤ 4 ∧ m*(drought m)^2 ≤ 4 := byhave hh' : drought m= -log m := max_eq_left (by linarith [log_nonpos hm.le h])let x := drought mhave heq : m= (exp x)⁻¹ := by unfold x; rw [hh',exp_neg,inv_inv,exp_log hm]have H : x^2 /4 ≤ exp x := byhave h0 : exp x=(exp (x/2))^2 := by rw [pow_two,←exp_add]; ring_nfhave hi := add_one_le_exp (x/2)rw [h0]nlinarith [show 0 ≤ x from drought_pos m]have HH := mul_le_mul_of_nonneg_left H hm.lehave Hx : m*exp x=1 := by rw [heq,inv_mul_cancel₀ (exp_pos x).ne']change m*x≤4 ∧ m*x^2≤4constructor· nlinarith [mul_nonneg hm.le (sq_nonneg (x-1))]linarithlemma grossDry :∀ᶠ j : ℕ in atTop, ∀ M J : ℕ, ∀ f : Grid M → ℝ,(∀ x, f x ≤ exp (height j)) →let s := beginPlay f false∀ t : Play j M s, t.Follows J f → s.mass ≤ 1/Thermal.H j →yieldA t ≤ 10^152*height j := byfilter_upwards [cost_overall,chill_descendants,hpoly 1 1] with j h1 h2 h3 M J f hf s t h hmhave H := h1 _ _ f s t h hfrw [due_restart rfl,add_zero] at Happly H.translet m := s.mass; let d := height j; let a := Thermal.H jhave hh : 0 ≤ m := (Play.first h).mass_lowerhave ha : 1 ≤ a := H_ge _have hd : 1 ≤ d := one_le_pow₀ (by norm_num)have hp : a ≤ d := by simpa using h3have hz : 0 < a := by linarithchange m≤1/a at hmhave hi : m*a ≤ 1 := (le_div_iff₀ hz).mp hmhave hr : m ≤ 1 := by nlinarithchange m*_ ≤ 10^152*drcases eq_or_lt_of_le hh with hh|hh· rw [←hh,zero_mul]; positivityapply le_trans (mul_le_mul_of_nonneg_left (h2 M J f s t h rfl rfl hh) hh.le)let x := drought mchange m*(10^150*(a+1+x)*(d+2+x)) ≤ _have he : m*x ≤ 4 ∧ m*x^2 ≤ 4 := scale_drought m hh hrnlinarith [mul_le_mul_of_nonneg_right hi (show 0 ≤ d by linarith),mul_le_mul_of_nonneg_right he.1(show 0 ≤ a by linarith),mul_le_mul_of_nonneg_right he.1 (show 0 ≤ d by linarith)]end CastShowend FourierLLogL.Dyadic.Procedure.Pathsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180import OAI.Analysis.FourierLLogL.Capture.Bookopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Chartvariable {M : ℕ}open scoped Classicaldef offset (i n : ℕ) := 16+i*2+n*2def price (b : Bool) (i : ℕ) := amp i b^2/2048private lemma leak_gate (i n : ℕ) (main : Bool) :side (offset i n) ≤ amp i main/128 ∧2^n*side (offset i n) ≤ side n*(amp i main/128) := byhave hi : side i ^2 ≤ amp i main := (strength_bounds main (side_pos _) (side_le _)).2.2have he' := side_le nhave he := side_pos nhave hs : side (offset i n) = side 16 * side i^2*side n^2 := by simp [offset,side,pow_add,pow_mul]have hP : side 16 ≤ 1/128 := by norm_num [side]have hQ : 2^n*side n=(1:ℝ) := by rw [mul_comm,side_card]rw [hs]have hn' : side 16*side i^2 ≤ amp i main/128 := bycalc_ ≤ (1/128)*amp i main := mul_le_mul hP hi (sq_nonneg _) (by norm_num)_ = _ := by ringconstructor· refine le_trans (mul_le_of_le_one_right (mul_nonneg (side_pos _).le (sq_nonneg _)) ?_) hn'; nlinarithcalc_ = side n*(side 16*side i^2) := byrw [show 2^n * (side 16*side i^2*side n^2) =(2^n * side n)*(side n*(side 16*side i^2)) by ring,hQ,one_mul]_ ≤ _ := by gcongrprivate lemma boundary_leak (p : Node) (hp : p.ok M) (F g : Grid M → ℝ)(hF : ∀ x, 0 ≤ g x ∧ |F x| ≤ g x) (hG : expU F=0) (L : ℝ)(he : expU (fun x => if x∈p.block M then 0 else g x) ≤ L*p.len) :(p.dice M).Ex F ≤ L := bylet f (x : Grid M) := if x∈p.block M then F x else 0let g' (x : Grid M) := if x∈p.block M then 0 else g xhave hE (x : Grid M) : f x ≤ F x+g' x := byunfold f g'; split_ifs· rw [add_zero]· linarith [(abs_le.mp (hF x).2).1]have hX : expU f ≤ L*p.len := byapply le_trans (b:=expU (fun x => F x+g' x))· rw [expU_ex,expU_ex]; apply Ex_mono _ hErw [expU_add,hG,zero_add]; exact hehave hh : (p.dice M).Ex F = expU f / p.len := byrw [← avg_ex hp,avg]; rw [div_eq_inv_mul,smul_eq_mul]congr 2rw [hh]exact (div_le_iff₀ p.len_pos).mpr hXtheorem append_choose (main : Bool) (i : ℕ) {q : Scene M}(hp : q.here.valid) (he : q.here.lev < M) (ha : 0 ≤ q.wage) (hn : 0 < q.norm)(hm : 0 < q.mass) (hM : q.mass ≤ 2*q.norm) (hE : ¬ hazard q main i)(D : Chart M) (hD : D.Sound)(x : Grid M) (hx : intense main q (side i) x)(hX : ¬ atReach D.items (D.wide+band q.here i (offset i D.size)) x) :∃ C : Chart M, C.items=insert x D.items ∧ D.size+1=C.size ∧C.wide=D.wide+band q.here i (offset i D.size) ∧ C.Sound ∧flex q main C.refs + price main i ≤ flex q main D.refs := bylet r := offset i D.sizelet p := band q.here i rlet a := amp i main; let t := a/128let P := tracker q main; let U := q.here.dice Mhave hR : 0 ≤ p := by unfold p band; positivityhave h₀ : 0 < a := amp_pos _ _have hT : 0 < t := by unfold t; positivityhave h₁ : a ≤ 1 := amp_hi _ _obtain ⟨g,hg,f,hf,hY,hZ,hW⟩ := masked_bias main x hp he ha hn hm hM hx hE r (leak_gate i D.size main).1let B := D.refslet Y (z y : Grid M) := f y * (g z * chi x y).relet L (z y : Grid M) := 1+t*Y z ylet C : Chart M := ⟨fun z y => B z y*L z y, insert x D.items, D.wide+p⟩have HT (z y) : |Y z y| ≤ 1 := byunfold Y; rw [abs_mul]have hfy : |f y| ≤ 1 := by simpa only [abs_of_nonneg (hY y).1] using (hY y).2have hgy : |(g z * chi x y).re| ≤ 1 :=(Complex.abs_re_le_norm _).trans (by rw [norm_mul,norm_chi,mul_one]; exact hg _)exact (mul_le_mul_of_nonneg_right hfy (abs_nonneg _)).trans (by simpa using hgy)have HF (z y) : 1/2 ≤ L z y ∧ L z y ≤ 2 := byunfold L t; rcases abs_le.mp (HT z y) with ⟨hh1,hh2⟩; constructor <;> nlinarithhave HH (z) :x∉D.items ∧ tinted C.items C.wide (C.refs z) := byconvert tinted_extend _ _ _ _ _ (hD.radius z) hf hD.bound hRx hX ((t:ℂ)*g z) using 2· dsimp only [C,B,L,Y]funext y; rw [mul_assoc (a:=(t:ℂ)),Complex.re_ofReal_mul]; ringhave HX : C.size=D.size+1 := Finset.card_insert_of_notMem (HH 0).1have HL : C.Sound := byconstructor· exact add_nonneg hD.bound hR· intro z yrcases HF z y with ⟨hh1,hh2⟩rcases hD.total z y with ⟨HE1,HE2⟩have he := side_pos D.sizerw [HX, side_succ,pow_succ]unfold C Bdsimp onlyconstructor <;> nlinarithintro z; exact (HH z).2refine ⟨C,rfl,HX.symm,rfl,HL,?_⟩have HE (z : Grid M) : log (normQ q C.refs z) - log (normQ q B z) ≤ t*(a/128) := byhave hv (y) : |B z y*Y z y| ≤ 2^D.size * f y := byhave he : 0 ≤ B z y := ((Chart.Sound.pos D hD) _ _).lehave hM := hY yunfold Y; simp_rw [abs_mul,abs_of_nonneg he, abs_of_nonneg hM.1]rw [← mul_assoc]refine le_trans (mul_le_of_le_one_right (mul_nonneg he hM.1) ?_) ?_· exact (Complex.abs_re_le_norm _).trans (by rw [norm_mul,norm_chi,mul_one]; exact hg _)exact mul_le_mul_of_nonneg_right (hD.total _ _).2 hM.1have hh : U.Ex (fun y => B z y*Y z y) ≤ 2^D.size * side r := byapply boundary_leak _ ⟨hp,he.le⟩ _ (fun y => 2^D.size*f y)(fun i => ⟨by have hx := (hY i).1; positivity,hv i⟩)· unfold Y B; simp_rw [← mul_assoc]exact tinted_cancel (tinted_mul (hD.radius z) hf) hX _· rw [expU_ex]; rw [expU_ex] at hZsimp_rw [show ∀ x : Grid M, (if x∈q.here.block M then (0:ℝ) else 2^D.size*f x) =2^D.size*(if x∈q.here.block M then 0 else f x) from fun x => by split_ifs <;> ring, Ex_lmul]apply le_trans (mul_le_mul_of_nonneg_left hZ (by positivity))exact le_of_eq (by ring)have hn : normQ q C.refs z=normQ q B z+t* U.Ex (fun y => B z y*Y z y) := bychange U.Ex _ = U.Ex _ + _rw [← Ex_lmul,← Ex_add]congr 1; funext ichange B z i*(1+t*Y z i) = _ringhave hG : side D.size ≤ normQ q B z :=le_trans (Ex_const U _).ge (Ex_mono U fun i => (hD.total _ _).1)have h₃ : 0 < normQ q B z := normQ_pos _ _ (Chart.Sound.pos D hD) _have h₄ : 0 < normQ q C.refs z := normQ_pos _ _ (Chart.Sound.pos C HL) _rw [← log_div h₄.ne' h₃.ne']apply le_trans (Real.log_le_sub_one_of_pos (div_pos h₄ h₃))have hl : 2^D.size * side r ≤ side D.size*(a/128) := (leak_gate _ _ main).2refine sub_le_iff_le_add.mpr ((div_le_iff₀ h₃).mpr ?_)nlinarith [hh.trans (hl.trans (mul_le_mul_of_nonneg_right hG (by positivity : 0 ≤ a/128)))]have h₃ : t*(a/8) - 2*t^2 ≤ P.Ex (fun i => log (L i.2 i.1)) := bylet W (i : Grid M × Grid M) := Y i.2 i.1have hi (i : Grid M × Grid M) :t*W i - 2*t^2 ≤ log (L i.2 i.1) := byhave hW := HT i.2 i.1have hX : |t* W i| ≤ t := byrw [abs_mul,abs_of_nonneg hT.le]exact mul_le_of_le_one_right hT.le hWhave hF : log (1+t*W i) ≥ t*W i -2*(t*W i)^2 :=log_shift_bound _ (hX.trans (by unfold t; linarith))change _ ≤ log (1+t*W i)have hE := pow_le_pow_left₀ (abs_nonneg _) hX 2; rw [sq_abs] at hElinarithhave HT := P.Ex_mono hirw [Ex_sub,Ex_lmul,Ex_const] at HTchange a/8 ≤ P.Ex W at hWnlinarithunfold flexlet delta := fun (F : ProductRef M) (i : Grid M × Grid M) => log (normQ q F i.2)-log (F i.2 i.1)have HX (i : Grid M × Grid M) :delta C.refs i+log (L i.2 i.1) ≤ delta B i+t*(a/128) := byunfold deltahave heq : C.refs i.2 i.1=B i.2 i.1*L i.2 i.1 := rflrw [heq,Real.log_mul ((Chart.Sound.pos D hD) _ _).ne'(lt_of_lt_of_le (by norm_num : (0:ℝ)<1/2) (HF _ _).1).ne']linarith [HE i.2]have He := Ex_mono P HXrw [Ex_add,Ex_add,Ex_const] at Heunfold pricechange _+ P.Ex (delta C.refs)+ a^2/2048 ≤ _ + P.Ex (delta D.refs)unfold t B at *nlinarithend FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180import OAI.Analysis.FourierLLogL.Capture.Bookopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Chartvariable {M : ℕ}open scoped Classicaldef offset (i n : ℕ) := 16+i*2+n*2def price (b : Bool) (i : ℕ) := amp i b^2/2048private lemma leak_gate (i n : ℕ) (main : Bool) :side (offset i n) ≤ amp i main/128 ∧2^n*side (offset i n) ≤ side n*(amp i main/128) := byhave hi : side i ^2 ≤ amp i main := (strength_bounds main (side_pos _) (side_le _)).2.2have he' := side_le nhave he := side_pos nhave hs : side (offset i n) = side 16 * side i^2*side n^2 := by simp [offset,side,pow_add,pow_mul]have hP : side 16 ≤ 1/128 := by norm_num [side]have hQ : 2^n*side n=(1:ℝ) := by rw [mul_comm,side_card]rw [hs]have hn' : side 16*side i^2 ≤ amp i main/128 := bycalc_ ≤ (1/128)*amp i main := mul_le_mul hP hi (sq_nonneg _) (by norm_num)_ = _ := by ringconstructor· refine le_trans (mul_le_of_le_one_right (mul_nonneg (side_pos _).le (sq_nonneg _)) ?_) hn'; nlinarithcalc_ = side n*(side 16*side i^2) := byrw [show 2^n * (side 16*side i^2*side n^2) =(2^n * side n)*(side n*(side 16*side i^2)) by ring,hQ,one_mul]_ ≤ _ := by gcongrprivate lemma boundary_leak (p : Node) (hp : p.ok M) (F g : Grid M → ℝ)(hF : ∀ x, 0 ≤ g x ∧ |F x| ≤ g x) (hG : expU F=0) (L : ℝ)(he : expU (fun x => if x∈p.block M then 0 else g x) ≤ L*p.len) :(p.dice M).Ex F ≤ L := bylet f (x : Grid M) := if x∈p.block M then F x else 0let g' (x : Grid M) := if x∈p.block M then 0 else g xhave hE (x : Grid M) : f x ≤ F x+g' x := byunfold f g'; split_ifs· rw [add_zero]· linarith [(abs_le.mp (hF x).2).1]have hX : expU f ≤ L*p.len := byapply le_trans (b:=expU (fun x => F x+g' x))· rw [expU_ex,expU_ex]; apply Ex_mono _ hErw [expU_add,hG,zero_add]; exact hehave hh : (p.dice M).Ex F = expU f / p.len := byrw [← avg_ex hp,avg]; rw [div_eq_inv_mul,smul_eq_mul]congr 2rw [hh]exact (div_le_iff₀ p.len_pos).mpr hXtheorem append_choose (main : Bool) (i : ℕ) {q : Scene M}(hp : q.here.valid) (he : q.here.lev < M) (ha : 0 ≤ q.wage) (hn : 0 < q.norm)(hm : 0 < q.mass) (hM : q.mass ≤ 2*q.norm) (hE : ¬ hazard q main i)(D : Chart M) (hD : D.Sound)(x : Grid M) (hx : intense main q (side i) x)(hX : ¬ atReach D.items (D.wide+band q.here i (offset i D.size)) x) :∃ C : Chart M, C.items=insert x D.items ∧ D.size+1=C.size ∧C.wide=D.wide+band q.here i (offset i D.size) ∧ C.Sound ∧flex q main C.refs + price main i ≤ flex q main D.refs := bylet r := offset i D.sizelet p := band q.here i rlet a := amp i main; let t := a/128let P := tracker q main; let U := q.here.dice Mhave hR : 0 ≤ p := by unfold p band; positivityhave h₀ : 0 < a := amp_pos _ _have hT : 0 < t := by unfold t; positivityhave h₁ : a ≤ 1 := amp_hi _ _obtain ⟨g,hg,f,hf,hY,hZ,hW⟩ := masked_bias main x hp he ha hn hm hM hx hE r (leak_gate i D.size main).1let B := D.refslet Y (z y : Grid M) := f y * (g z * chi x y).relet L (z y : Grid M) := 1+t*Y z ylet C : Chart M := ⟨fun z y => B z y*L z y, insert x D.items, D.wide+p⟩have HT (z y) : |Y z y| ≤ 1 := byunfold Y; rw [abs_mul]have hfy : |f y| ≤ 1 := by simpa only [abs_of_nonneg (hY y).1] using (hY y).2have hgy : |(g z * chi x y).re| ≤ 1 :=(Complex.abs_re_le_norm _).trans (by rw [norm_mul,norm_chi,mul_one]; exact hg _)exact (mul_le_mul_of_nonneg_right hfy (abs_nonneg _)).trans (by simpa using hgy)have HF (z y) : 1/2 ≤ L z y ∧ L z y ≤ 2 := byunfold L t; rcases abs_le.mp (HT z y) with ⟨hh1,hh2⟩; constructor <;> nlinarithhave HH (z) :x∉D.items ∧ tinted C.items C.wide (C.refs z) := byconvert tinted_extend _ _ _ _ _ (hD.radius z) hf hD.bound hRx hX ((t:ℂ)*g z) using 2· dsimp only [C,B,L,Y]funext y; rw [mul_assoc (a:=(t:ℂ)),Complex.re_ofReal_mul]; ringhave HX : C.size=D.size+1 := Finset.card_insert_of_notMem (HH 0).1have HL : C.Sound := byconstructor· exact add_nonneg hD.bound hR· intro z yrcases HF z y with ⟨hh1,hh2⟩rcases hD.total z y with ⟨HE1,HE2⟩have he := side_pos D.sizerw [HX, side_succ,pow_succ]unfold C Bdsimp onlyconstructor <;> nlinarithintro z; exact (HH z).2refine ⟨C,rfl,HX.symm,rfl,HL,?_⟩have HE (z : Grid M) : log (normQ q C.refs z) - log (normQ q B z) ≤ t*(a/128) := byhave hv (y) : |B z y*Y z y| ≤ 2^D.size * f y := byhave he : 0 ≤ B z y := ((Chart.Sound.pos D hD) _ _).lehave hM := hY yunfold Y; simp_rw [abs_mul,abs_of_nonneg he, abs_of_nonneg hM.1]rw [← mul_assoc]refine le_trans (mul_le_of_le_one_right (mul_nonneg he hM.1) ?_) ?_· exact (Complex.abs_re_le_norm _).trans (by rw [norm_mul,norm_chi,mul_one]; exact hg _)exact mul_le_mul_of_nonneg_right (hD.total _ _).2 hM.1have hh : U.Ex (fun y => B z y*Y z y) ≤ 2^D.size * side r := byapply boundary_leak _ ⟨hp,he.le⟩ _ (fun y => 2^D.size*f y)(fun i => ⟨by have hx := (hY i).1; positivity,hv i⟩)· unfold Y B; simp_rw [← mul_assoc]exact tinted_cancel (tinted_mul (hD.radius z) hf) hX _· rw [expU_ex]; rw [expU_ex] at hZsimp_rw [show ∀ x : Grid M, (if x∈q.here.block M then (0:ℝ) else 2^D.size*f x) =2^D.size*(if x∈q.here.block M then 0 else f x) from fun x => by split_ifs <;> ring, Ex_lmul]apply le_trans (mul_le_mul_of_nonneg_left hZ (by positivity))exact le_of_eq (by ring)have hn : normQ q C.refs z=normQ q B z+t* U.Ex (fun y => B z y*Y z y) := bychange U.Ex _ = U.Ex _ + _rw [← Ex_lmul,← Ex_add]congr 1; funext ichange B z i*(1+t*Y z i) = _ringhave hG : side D.size ≤ normQ q B z :=le_trans (Ex_const U _).ge (Ex_mono U fun i => (hD.total _ _).1)have h₃ : 0 < normQ q B z := normQ_pos _ _ (Chart.Sound.pos D hD) _have h₄ : 0 < normQ q C.refs z := normQ_pos _ _ (Chart.Sound.pos C HL) _rw [← log_div h₄.ne' h₃.ne']apply le_trans (Real.log_le_sub_one_of_pos (div_pos h₄ h₃))have hl : 2^D.size * side r ≤ side D.size*(a/128) := (leak_gate _ _ main).2refine sub_le_iff_le_add.mpr ((div_le_iff₀ h₃).mpr ?_)nlinarith [hh.trans (hl.trans (mul_le_mul_of_nonneg_right hG (by positivity : 0 ≤ a/128)))]have h₃ : t*(a/8) - 2*t^2 ≤ P.Ex (fun i => log (L i.2 i.1)) := bylet W (i : Grid M × Grid M) := Y i.2 i.1have hi (i : Grid M × Grid M) :t*W i - 2*t^2 ≤ log (L i.2 i.1) := byhave hW := HT i.2 i.1have hX : |t* W i| ≤ t := byrw [abs_mul,abs_of_nonneg hT.le]exact mul_le_of_le_one_right hT.le hWhave hF : log (1+t*W i) ≥ t*W i -2*(t*W i)^2 :=log_shift_bound _ (hX.trans (by unfold t; linarith))change _ ≤ log (1+t*W i)have hE := pow_le_pow_left₀ (abs_nonneg _) hX 2; rw [sq_abs] at hElinarithhave HT := P.Ex_mono hirw [Ex_sub,Ex_lmul,Ex_const] at HTchange a/8 ≤ P.Ex W at hWnlinarithunfold flexlet delta := fun (F : ProductRef M) (i : Grid M × Grid M) => log (normQ q F i.2)-log (F i.2 i.1)have HX (i : Grid M × Grid M) :delta C.refs i+log (L i.2 i.1) ≤ delta B i+t*(a/128) := byunfold deltahave heq : C.refs i.2 i.1=B i.2 i.1*L i.2 i.1 := rflrw [heq,Real.log_mul ((Chart.Sound.pos D hD) _ _).ne'(lt_of_lt_of_le (by norm_num : (0:ℝ)<1/2) (HF _ _).1).ne']linarith [HE i.2]have He := Ex_mono P HXrw [Ex_add,Ex_add,Ex_const] at Heunfold pricechange _+ P.Ex (delta C.refs)+ a^2/2048 ≤ _ + P.Ex (delta D.refs)unfold t B at *nlinarithend FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import OAI.Analysis.FourierLLogL.Capture.Fleximport OAI.Analysis.FourierLLogL.Dyadic.Spanopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M : ℕ}open scoped Classicaldef atReach (d : Finset (Grid M)) (r : ℝ) (x : Grid M) :=∃ i, enclosed d 1 i ∧ rad (x-i) ≤ rdef tinted (d : Finset (Grid M)) (r : ℝ) (f : Grid M → ℝ) :=∀ i, ¬ atReach d r i → fc (fun x => (↑(f x):ℂ)) i = 0lemma atReach_neg {d : Finset (Grid M)} {r : ℝ} {x : Grid M} (h : atReach d r x) :atReach d r (-x) := byobtain ⟨i,h1,h2⟩ := hexact ⟨-i,enclosed_neg h1,by rw [show -x- -i= -(x-i) by ring,rad_even]; exact h2⟩lemma tinted_mul {d : Finset (Grid M)} {r s : ℝ} {f g : Grid M → ℝ} (hf : tinted d r f)(hg : limitR g s) : tinted d (r+s) (fun i => f i*g i) := byintro i hisimp only [Complex.ofReal_mul]rw [fc_prod]apply Finset.sum_eq_zero; intro j _by_cases h : atReach d r j· obtain ⟨v,hv,H⟩ := hhave hX : s < rad (i-j) := byby_contra! he; apply hi; refine ⟨v,hv,?_⟩have hZ := rad_add (i-j) (j-v); rw [sub_add_sub_cancel] at hZ; linarithrw [hg _ hX,mul_zero]rw [hf j h,zero_mul]lemma tinted_cancel {d : Finset (Grid M)} {r : ℝ} {f : Grid M → ℝ} (hf : tinted d r f){i : Grid M} (hh : ¬ atReach d r i) (c : ℂ) :expU (fun x => f x*(c*chi i x).re)=0 := byhave H : c* fc (fun x => (↑(f x):ℂ)) (-i) = 0 := byrw [hf (-i) (fun h => hh (by simpa using atReach_neg h)),mul_zero]unfold fc at Hrw [expU_cx,← Cx_lmul] at Hhave HE := congrArg Complex.re Hsimp_rw [re_Cx,neg_neg,mul_left_comm c, Complex.re_ofReal_mul,← expU_ex,Complex.zero_re] at HEexact HElemma tinted_one (d : Finset (Grid M)) {r : ℝ} (h : 0 ≤ r) : tinted d r (fun _ => 1) := byintro i hihave hn : ¬ enclosed d 1 i := byintro H; apply hi; exact ⟨i,H,by simp [rad,h]⟩simp only [Complex.ofReal_one]; exact spanned_one _ _ hnlemma tinted_extend (f g : Grid M → ℝ) (d : Finset (Grid M)) (r s : ℝ) (hf : tinted d r f)(hg : limitR g s) (hr : 0 ≤ r) (hs : 0 ≤ s)(i : Grid M) (hi : ¬ atReach d (r+s) i) (c : ℂ) :i∉d ∧ tinted (insert i d) (r+s)(fun x => f x*(1+g x*(c*chi i x).re)) := byhave hx : i∉d := fun H => hi ⟨i,enclosed_mem _ H,by simp [rad]; linarith⟩let F : Grid M → ℂ := fun x => (f x * g x:ℝ)have Hf : ∀ x, ¬ atReach d (r+s) x → fc F x=0 := tinted_mul hf hgrefine ⟨hx,?_⟩intro x hhhave H (p : Grid M) (h : ¬ atReach (insert i d) (r+s) x)(j : ℤ) (hj : |j| ≤ 1) (heq : x=p+j•i) :¬ atReach d (r+s) p := byintro hLobtain ⟨u,hu,hb⟩ := hLapply hrefine ⟨u+j•i,enclosed_insert hx hu j (by simpa using hj),?_⟩rw [heq]; simpa only [add_sub_add_right_eq_sub] using hbhave hX : ¬ atReach d (r+s) x := H x hh 0 (by norm_num) (by simp)have hA : ¬ atReach d r x := byrintro ⟨p,hp,hb⟩exact hX ⟨p,hp,by linarith⟩have hB : ¬ atReach d (r+s) (x-i) := H _ hh 1 (by norm_num) (by simp)have hC : ¬ atReach d (r+s) (x+i) := H _ hh (-1) (by norm_num) (by simp)have he (x) :(↑(f x * (1 + g x *(c*chi i x).re)):ℂ) = (↑(f x):ℂ)+F x*((c*chi i x).re) := byunfold F; push_cast; ringsimp_rw [he,fc_add,hf x hA]have ht := expand_one_step F c i xrw [Hf x hX,Hf (x-i) hB,Hf (x+i) hC] at hthave h₁ (x) : F x*(1+(↑((c*chi i x).re):ℂ))=F x+F x*((c*chi i x).re) := by ringsimp_rw [h₁,fc_add,Hf x hX] at htexact ht.trans (by ring)structure Chart (M : ℕ) whererefs : ProductRef Mitems : Finset (Grid M)wide : ℝnamespace Chartdef classic (M : ℕ) : Chart M := ⟨fun _ _ => 1,∅,0⟩def size (c : Chart M) := c.items.cardstructure Sound (c : Chart M) : Prop wherebound : 0 ≤ c.widetotal z y : side c.size ≤ c.refs z y ∧ c.refs z y ≤ 2^c.sizeradius z : tinted c.items c.wide (c.refs z)lemma classic_sound (M : ℕ) : (classic M).Sound :=⟨le_rfl, by simp [classic,size,side], fun z => tinted_one _ le_rfl⟩lemma Sound.pos (c : Chart M) (h : c.Sound) (z y) : 0 < c.refs z y :=lt_of_lt_of_le (side_pos _) (h.total z y).1end Chartend FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import OAI.Analysis.FourierLLogL.Capture.Fleximport OAI.Analysis.FourierLLogL.Dyadic.Spanopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M : ℕ}open scoped Classicaldef atReach (d : Finset (Grid M)) (r : ℝ) (x : Grid M) :=∃ i, enclosed d 1 i ∧ rad (x-i) ≤ rdef tinted (d : Finset (Grid M)) (r : ℝ) (f : Grid M → ℝ) :=∀ i, ¬ atReach d r i → fc (fun x => (↑(f x):ℂ)) i = 0lemma atReach_neg {d : Finset (Grid M)} {r : ℝ} {x : Grid M} (h : atReach d r x) :atReach d r (-x) := byobtain ⟨i,h1,h2⟩ := hexact ⟨-i,enclosed_neg h1,by rw [show -x- -i= -(x-i) by ring,rad_even]; exact h2⟩lemma tinted_mul {d : Finset (Grid M)} {r s : ℝ} {f g : Grid M → ℝ} (hf : tinted d r f)(hg : limitR g s) : tinted d (r+s) (fun i => f i*g i) := byintro i hisimp only [Complex.ofReal_mul]rw [fc_prod]apply Finset.sum_eq_zero; intro j _by_cases h : atReach d r j· obtain ⟨v,hv,H⟩ := hhave hX : s < rad (i-j) := byby_contra! he; apply hi; refine ⟨v,hv,?_⟩have hZ := rad_add (i-j) (j-v); rw [sub_add_sub_cancel] at hZ; linarithrw [hg _ hX,mul_zero]rw [hf j h,zero_mul]lemma tinted_cancel {d : Finset (Grid M)} {r : ℝ} {f : Grid M → ℝ} (hf : tinted d r f){i : Grid M} (hh : ¬ atReach d r i) (c : ℂ) :expU (fun x => f x*(c*chi i x).re)=0 := byhave H : c* fc (fun x => (↑(f x):ℂ)) (-i) = 0 := byrw [hf (-i) (fun h => hh (by simpa using atReach_neg h)),mul_zero]unfold fc at Hrw [expU_cx,← Cx_lmul] at Hhave HE := congrArg Complex.re Hsimp_rw [re_Cx,neg_neg,mul_left_comm c, Complex.re_ofReal_mul,← expU_ex,Complex.zero_re] at HEexact HElemma tinted_one (d : Finset (Grid M)) {r : ℝ} (h : 0 ≤ r) : tinted d r (fun _ => 1) := byintro i hihave hn : ¬ enclosed d 1 i := byintro H; apply hi; exact ⟨i,H,by simp [rad,h]⟩simp only [Complex.ofReal_one]; exact spanned_one _ _ hnlemma tinted_extend (f g : Grid M → ℝ) (d : Finset (Grid M)) (r s : ℝ) (hf : tinted d r f)(hg : limitR g s) (hr : 0 ≤ r) (hs : 0 ≤ s)(i : Grid M) (hi : ¬ atReach d (r+s) i) (c : ℂ) :i∉d ∧ tinted (insert i d) (r+s)(fun x => f x*(1+g x*(c*chi i x).re)) := byhave hx : i∉d := fun H => hi ⟨i,enclosed_mem _ H,by simp [rad]; linarith⟩let F : Grid M → ℂ := fun x => (f x * g x:ℝ)have Hf : ∀ x, ¬ atReach d (r+s) x → fc F x=0 := tinted_mul hf hgrefine ⟨hx,?_⟩intro x hhhave H (p : Grid M) (h : ¬ atReach (insert i d) (r+s) x)(j : ℤ) (hj : |j| ≤ 1) (heq : x=p+j•i) :¬ atReach d (r+s) p := byintro hLobtain ⟨u,hu,hb⟩ := hLapply hrefine ⟨u+j•i,enclosed_insert hx hu j (by simpa using hj),?_⟩rw [heq]; simpa only [add_sub_add_right_eq_sub] using hbhave hX : ¬ atReach d (r+s) x := H x hh 0 (by norm_num) (by simp)have hA : ¬ atReach d r x := byrintro ⟨p,hp,hb⟩exact hX ⟨p,hp,by linarith⟩have hB : ¬ atReach d (r+s) (x-i) := H _ hh 1 (by norm_num) (by simp)have hC : ¬ atReach d (r+s) (x+i) := H _ hh (-1) (by norm_num) (by simp)have he (x) :(↑(f x * (1 + g x *(c*chi i x).re)):ℂ) = (↑(f x):ℂ)+F x*((c*chi i x).re) := byunfold F; push_cast; ringsimp_rw [he,fc_add,hf x hA]have ht := expand_one_step F c i xrw [Hf x hX,Hf (x-i) hB,Hf (x+i) hC] at hthave h₁ (x) : F x*(1+(↑((c*chi i x).re):ℂ))=F x+F x*((c*chi i x).re) := by ringsimp_rw [h₁,fc_add,Hf x hX] at htexact ht.trans (by ring)structure Chart (M : ℕ) whererefs : ProductRef Mitems : Finset (Grid M)wide : ℝnamespace Chartdef classic (M : ℕ) : Chart M := ⟨fun _ _ => 1,∅,0⟩def size (c : Chart M) := c.items.cardstructure Sound (c : Chart M) : Prop wherebound : 0 ≤ c.widetotal z y : side c.size ≤ c.refs z y ∧ c.refs z y ≤ 2^c.sizeradius z : tinted c.items c.wide (c.refs z)lemma classic_sound (M : ℕ) : (classic M).Sound :=⟨le_rfl, by simp [classic,size,side], fun z => tinted_one _ le_rfl⟩lemma Sound.pos (c : Chart M) (h : c.Sound) (z y) : 0 < c.refs z y :=lt_of_lt_of_le (side_pos _) (h.total z y).1end Chartend FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206import OAI.Analysis.FourierLLogL.Capture.Maskimport OAI.Analysis.FourierLLogL.Plateau.Local/-! # Criteria and their polarized tests -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M J j : ℕ} {s : Scene M}open scoped Classicaldef optic (s : Scene M) (b : Bool) := if b then s.fund.mood else 0def energy (s : Scene M) (u : Grid M) := energyZ s.here s.wage s.norm s.fund.mood udef scalar (s : Scene M) (u : Grid M) :=∑ i : Grid M, (↑(wt s.here s.wage s.norm i):ℂ)*chi u idef magnitude (main : Bool) (s : Scene M) (u : Grid M) :=if main then energy s u else ‖scalar s u‖def strength (main : Bool) (b : ℝ) := if main then b^2 else bdef intense (main : Bool) (s : Scene M) (r : ℝ) (i : Grid M) :=∃ b, strength main r ≤ magnitude main (s.smaller b) idef amp (i : ℕ) (b : Bool) := strength b (side i)lemma strength_bounds (b : Bool) {r : ℝ} (hr : 0 < r) (h : r ≤ 1) :0 < strength b r ∧ strength b r ≤ r ∧ r^2 ≤ strength b r := byhave he : r^2 ≤ r := by nlinarithcases b <;> simp only [strength, Bool.false_eq_true,↓reduceIte] <;> exact ⟨by positivity,by linarith,by linarith⟩lemma amp_pos (i : ℕ) (b : Bool) : 0 < amp i b :=(strength_bounds b (side_pos i) (side_le i)).1lemma amp_hi (i : ℕ) (b : Bool) : amp i b ≤ 1 :=(strength_bounds b (side_pos i) (side_le i)).2.1.trans (side_le i)lemma gate_amp (i : ℕ) (b : Bool) :gateWidth b i = amp i b /128 := rfllemma intent_main (s : Scene M) (r : ℝ) (i : Grid M) :intense true s r i ↔ high s.here s.wage s.norm s.fund.mood r i := byrfllemma scalar_series (s : Scene M) (A : Form M) (u : Grid M) :scalar s u = ∑ z, fz s.here s.wage s.norm A u z := byunfold fz scalarrw [Finset.sum_comm]; refine Finset.sum_congr rfl fun i hi => ?_unfold omegaObs; simp_rw [Complex.ofReal_mul,mul_right_comm((wt s.here s.wage s.norm i):ℂ) _ (chi u i)]rw [← Finset.mul_sum,← Complex.ofReal_sum,(channel A i).total]; simplemma strong_sum (s : Scene M) (b : Bool) (x : Grid M)(ha : 0 ≤ s.wage) (hb : 0 < s.norm) :magnitude b s x ≤ ∑ z, ‖fz s.here s.wage s.norm (optic s b) x z‖ := bycases b· change ‖scalar s x‖ ≤ _rw [scalar_series s (optic s false)]; exact norm_sum_le _ _· exact energyZ_le s.here ha hb.le _ _def tracker (s : Scene M) (main : Bool) := s.actor.withNext (channel (optic s main))def aim {p : Node} (b : Bool) (y : Grid M) : ℝ := if y∈(child p b).block M then 1 else 0private lemma aim_identity (s : Scene M) (b : Bool) (i : Grid M) (main : Bool)(v : Grid M → ℂ) (hp : s.here.valid) (hh : s.here.lev < M)(ha : 0 ≤ s.wage) (hb : 0 < s.norm) (hm : 0 < s.mass) :let q := s.smaller b∑ z, (v z*fz q.here q.wage q.norm (optic q main) i z).re =(2*s.mass/s.norm)*(tracker s main).Ex (fun w =>aim (p:=s.here) b w.1*(v w.2*chi i w.1).re) := byclassicalintro qlet A := optic s mainlet L := channel A; let P := s.actorlet H := fun y : Grid M => aim (p:=s.here) b ylet c := 2*s.mass/s.normhave HE (z : Grid M) :(v z*fz q.here q.wage q.norm (optic q main) i z).re =∑ y, c * (P y * (L y z * (H y*(v z*chi i y).re))) := byunfold fz; rw [Finset.mul_sum,Complex.re_sum]refine Finset.sum_congr rfl fun y hy => ?_have Hi : omegaObs q.here q.wage q.norm (optic q main) y z =c*H y*P y*L y z := byunfold omegaObschange wt (s.here.child b) s.wage s.norm y*L y z = _unfold H Procedure.Capture.aim c Prw [actor_def ⟨hp,hh.le⟩ ha hm y,wt_half hp hh]split_ifs· unfold mass wt; unfold mass at hm; field_simp· simprw [Hi,mul_left_comm,Complex.re_ofReal_mul]; ringunfold tracker; rw [Ex_withNext]; simp only [HE,← Finset.mul_sum,Ex]congr 1rw [Finset.sum_comm]dsimp only [c,P,H,A,L]simp_rw [Finset.mul_sum]lemma criterion_bias (s : Scene M) (main : Bool) (k : ℕ) (x : Grid M)(hp : s.here.valid) (hh : s.here.lev < M) (ha : 0 ≤ s.wage)(hx : 0 < s.norm) (hm : 0 < s.mass) (he : intense main s (side k) x) :∃ b : Bool, ∃ f : Grid M → ℂ, (∀ z, ‖f z‖ ≤ 1) ∧amp k main /2 ≤ (s.mass/s.norm)*(tracker s main).Ex (fun w =>aim (p:=s.here) b w.1 * (f w.2*chi x w.1).re) := byobtain ⟨b,hL⟩ := helet q := s.smaller blet v := fun z => fz q.here q.wage q.norm (optic q main) x zlet f := fun z => polar (v z)have HH := aim_identity s b x main f hp hh ha hx hmhave He (z : Grid M) : (f z*v z).re=‖v z‖ := polar_identity _have H : amp k main ≤ ∑ z, ‖v z‖ := hL.trans (strong_sum q main x ha hx)refine ⟨b,f,fun z => polar_unit _,?_⟩change ∑ z,(f z*v z).re = _ at HHsimp_rw [He,mul_div_assoc] at HHnlinarithprivate lemma test_one (g z : ℂ) (hg : ‖g‖ ≤ 1) (hz : ‖z‖ = 1) :|(g*z).re| ≤ 1 := (Complex.abs_re_le_norm _).trans(by rw [norm_mul,hz,mul_one]; exact hg)lemma expensive_intent {s : Scene M} (main : Bool) {k : ℕ} {x : Grid M}(hp : s.here.valid) (hh : s.here.lev < M) (ha : 0 ≤ s.wage)(hx : 0 < s.norm) (hm : 0 < s.mass) (he : intense main s (side k) x) :amp k main /2 ≤ s.mass/s.norm := byobtain ⟨b,f,hf,hb⟩ := criterion_bias _ _ _ _ hp hh ha hx hm heapply hb.transapply mul_le_of_le_one_right (by positivity)refine le_trans (Ex_mono _ (g:=fun _ => 1) fun i => ?_) (Ex_const _ _).leunfold aim; split_ifs· rw [one_mul]; exact (le_abs_self _).trans (test_one _ _ (hf _) (norm_chi _ _))norm_numlemma edge_prob {s : Scene M} {i : ℕ} (hm : 0 < s.mass) (hn : 0 < s.norm)(hp : s.here.ok M) (h : 0 ≤ s.wage) :s.mass/s.norm * s.actor.prob (fun x => lanes s.here i M ∧ flanked s.here i x)= edgeW s i := byclassicalrw [prob_eq,edgeW]by_cases hh : lanes s.here i M· simp only [hh,ite_true,true_and]; rw [Finset.mul_sum]refine Finset.sum_congr rfl fun x hx => ?_split_ifs with H· rw [actor_def hp h hm]unfold wt mass; unfold mass at hmfield_simpexact mul_zero _simp [hh]/-- Mask of sufficient precision is a biased test under the post law -/theorem masked_bias {s : Scene M} {i : ℕ} (main : Bool) (x : Grid M)(hp : s.here.valid) (he : s.here.lev < M)(ha : 0 ≤ s.wage) (hn : 0 < s.norm) (hm : 0 < s.mass) (hM : s.mass ≤ 2*s.norm)(h : intense main s (side i) x)(hB : ¬ hazard s main i) (r : ℕ) (hr : side r ≤ amp i main /128) :∃ g : Grid M → ℂ, (∀ z, ‖g z‖ ≤ 1) ∧ ∃ f : Grid M → ℝ,limitR f (band s.here i r) ∧ (∀ y, 0 ≤ f y ∧ f y ≤ 1) ∧expU (fun y => if y∈s.here.block M then 0 else f y) ≤ s.here.len*side r ∧amp i main /8 ≤ (tracker s main).Ex (fun y => f y.1*(g y.2*chi x y.1).re) := byobtain ⟨b,g,hg,hG⟩ := criterion_bias s main i x hp he ha hn hm hobtain ⟨f,hf,hN,hE,hP⟩ := make_mask (M:=M) s.here hp he b i rlet p := s.herelet a := amp i main; let v := s.mass/s.normlet P := tracker s mainlet w (y : Grid M × Grid M) := (g y.2*chi x y.1).relet G (y : Grid M) := lanes p i M ∧ flanked p i ylet F (y : Grid M × Grid M) := f y.1*w yhave Hq : v*P.prob (fun y => G y.1) ≤ a/128 := byrw [← prob_send P Prod.fst G,show P.send Prod.fst=s.actor from send_fst_withNext _ _]rw [edge_prob hm hn ⟨hp,he.le⟩ ha]exact le_of_not_ge hBhave Hw (i) : |w i| ≤ 1 := test_one _ _ (hg _) (norm_chi _ _)have H : v * P.Ex (fun i => aim (p:=p) b i.1*w i) ≤v* (P.Ex F + P.prob (fun i => G i.1) + side r) := byapply mul_le_mul_of_nonneg_left _ (by positivity)rw [← Ex_const P (side r)]; unfold probrw [← Ex_add,← Ex_add]apply Ex_mono_mem; rintro ⟨y,z⟩ hhave h0 : y∈p.block M := byhave hh : 0 < s.actor y := pos_of_mul_pos_left h ((channel (optic s main) y).nonneg z)exact piece_support ⟨hp,he.le⟩ (actor_def ⟨hp,he.le⟩ ha hm) _ hhchange aim (p:=p) b y*w (y,z) ≤ f y*w (y,z)+(@ite ℝ (G y) (Classical.propDecidable _) 1 0)+side rhave hi := abs_le.mp (Hw (y,z))have hi' := hN ysplit_ifs with H· unfold aim; split_ifs <;> nlinarith [side_pos r]have He : |aim (p:=p) b y-f y| ≤ side r := hE y h0 Hhave hY := (mul_le_mul He (Hw (y,z)) (abs_nonneg _) (side_pos r).le)rw [← abs_mul,mul_one] at hYhave hx := (abs_le.mp hY).2linarithrefine ⟨g,hg,f,hf,hN,hP,?_⟩have hv : v ≤ 2 := (div_le_iff₀ hn).mpr hMhave hp' : 0 < v := by unfold v; positivitychange a/2 ≤ _ at hGchange _ ≤ v * P.Ex (fun i => aim (p:=p) b i.1*w i) at hGhave HH : 0 < a := amp_pos _ _change a/8 ≤ P.Ex Fchange side r ≤ a/128 at hrnlinarithend FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206import OAI.Analysis.FourierLLogL.Capture.Maskimport OAI.Analysis.FourierLLogL.Plateau.Local/-! # Criteria and their polarized tests -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M J j : ℕ} {s : Scene M}open scoped Classicaldef optic (s : Scene M) (b : Bool) := if b then s.fund.mood else 0def energy (s : Scene M) (u : Grid M) := energyZ s.here s.wage s.norm s.fund.mood udef scalar (s : Scene M) (u : Grid M) :=∑ i : Grid M, (↑(wt s.here s.wage s.norm i):ℂ)*chi u idef magnitude (main : Bool) (s : Scene M) (u : Grid M) :=if main then energy s u else ‖scalar s u‖def strength (main : Bool) (b : ℝ) := if main then b^2 else bdef intense (main : Bool) (s : Scene M) (r : ℝ) (i : Grid M) :=∃ b, strength main r ≤ magnitude main (s.smaller b) idef amp (i : ℕ) (b : Bool) := strength b (side i)lemma strength_bounds (b : Bool) {r : ℝ} (hr : 0 < r) (h : r ≤ 1) :0 < strength b r ∧ strength b r ≤ r ∧ r^2 ≤ strength b r := byhave he : r^2 ≤ r := by nlinarithcases b <;> simp only [strength, Bool.false_eq_true,↓reduceIte] <;> exact ⟨by positivity,by linarith,by linarith⟩lemma amp_pos (i : ℕ) (b : Bool) : 0 < amp i b :=(strength_bounds b (side_pos i) (side_le i)).1lemma amp_hi (i : ℕ) (b : Bool) : amp i b ≤ 1 :=(strength_bounds b (side_pos i) (side_le i)).2.1.trans (side_le i)lemma gate_amp (i : ℕ) (b : Bool) :gateWidth b i = amp i b /128 := rfllemma intent_main (s : Scene M) (r : ℝ) (i : Grid M) :intense true s r i ↔ high s.here s.wage s.norm s.fund.mood r i := byrfllemma scalar_series (s : Scene M) (A : Form M) (u : Grid M) :scalar s u = ∑ z, fz s.here s.wage s.norm A u z := byunfold fz scalarrw [Finset.sum_comm]; refine Finset.sum_congr rfl fun i hi => ?_unfold omegaObs; simp_rw [Complex.ofReal_mul,mul_right_comm((wt s.here s.wage s.norm i):ℂ) _ (chi u i)]rw [← Finset.mul_sum,← Complex.ofReal_sum,(channel A i).total]; simplemma strong_sum (s : Scene M) (b : Bool) (x : Grid M)(ha : 0 ≤ s.wage) (hb : 0 < s.norm) :magnitude b s x ≤ ∑ z, ‖fz s.here s.wage s.norm (optic s b) x z‖ := bycases b· change ‖scalar s x‖ ≤ _rw [scalar_series s (optic s false)]; exact norm_sum_le _ _· exact energyZ_le s.here ha hb.le _ _def tracker (s : Scene M) (main : Bool) := s.actor.withNext (channel (optic s main))def aim {p : Node} (b : Bool) (y : Grid M) : ℝ := if y∈(child p b).block M then 1 else 0private lemma aim_identity (s : Scene M) (b : Bool) (i : Grid M) (main : Bool)(v : Grid M → ℂ) (hp : s.here.valid) (hh : s.here.lev < M)(ha : 0 ≤ s.wage) (hb : 0 < s.norm) (hm : 0 < s.mass) :let q := s.smaller b∑ z, (v z*fz q.here q.wage q.norm (optic q main) i z).re =(2*s.mass/s.norm)*(tracker s main).Ex (fun w =>aim (p:=s.here) b w.1*(v w.2*chi i w.1).re) := byclassicalintro qlet A := optic s mainlet L := channel A; let P := s.actorlet H := fun y : Grid M => aim (p:=s.here) b ylet c := 2*s.mass/s.normhave HE (z : Grid M) :(v z*fz q.here q.wage q.norm (optic q main) i z).re =∑ y, c * (P y * (L y z * (H y*(v z*chi i y).re))) := byunfold fz; rw [Finset.mul_sum,Complex.re_sum]refine Finset.sum_congr rfl fun y hy => ?_have Hi : omegaObs q.here q.wage q.norm (optic q main) y z =c*H y*P y*L y z := byunfold omegaObschange wt (s.here.child b) s.wage s.norm y*L y z = _unfold H Procedure.Capture.aim c Prw [actor_def ⟨hp,hh.le⟩ ha hm y,wt_half hp hh]split_ifs· unfold mass wt; unfold mass at hm; field_simp· simprw [Hi,mul_left_comm,Complex.re_ofReal_mul]; ringunfold tracker; rw [Ex_withNext]; simp only [HE,← Finset.mul_sum,Ex]congr 1rw [Finset.sum_comm]dsimp only [c,P,H,A,L]simp_rw [Finset.mul_sum]lemma criterion_bias (s : Scene M) (main : Bool) (k : ℕ) (x : Grid M)(hp : s.here.valid) (hh : s.here.lev < M) (ha : 0 ≤ s.wage)(hx : 0 < s.norm) (hm : 0 < s.mass) (he : intense main s (side k) x) :∃ b : Bool, ∃ f : Grid M → ℂ, (∀ z, ‖f z‖ ≤ 1) ∧amp k main /2 ≤ (s.mass/s.norm)*(tracker s main).Ex (fun w =>aim (p:=s.here) b w.1 * (f w.2*chi x w.1).re) := byobtain ⟨b,hL⟩ := helet q := s.smaller blet v := fun z => fz q.here q.wage q.norm (optic q main) x zlet f := fun z => polar (v z)have HH := aim_identity s b x main f hp hh ha hx hmhave He (z : Grid M) : (f z*v z).re=‖v z‖ := polar_identity _have H : amp k main ≤ ∑ z, ‖v z‖ := hL.trans (strong_sum q main x ha hx)refine ⟨b,f,fun z => polar_unit _,?_⟩change ∑ z,(f z*v z).re = _ at HHsimp_rw [He,mul_div_assoc] at HHnlinarithprivate lemma test_one (g z : ℂ) (hg : ‖g‖ ≤ 1) (hz : ‖z‖ = 1) :|(g*z).re| ≤ 1 := (Complex.abs_re_le_norm _).trans(by rw [norm_mul,hz,mul_one]; exact hg)lemma expensive_intent {s : Scene M} (main : Bool) {k : ℕ} {x : Grid M}(hp : s.here.valid) (hh : s.here.lev < M) (ha : 0 ≤ s.wage)(hx : 0 < s.norm) (hm : 0 < s.mass) (he : intense main s (side k) x) :amp k main /2 ≤ s.mass/s.norm := byobtain ⟨b,f,hf,hb⟩ := criterion_bias _ _ _ _ hp hh ha hx hm heapply hb.transapply mul_le_of_le_one_right (by positivity)refine le_trans (Ex_mono _ (g:=fun _ => 1) fun i => ?_) (Ex_const _ _).leunfold aim; split_ifs· rw [one_mul]; exact (le_abs_self _).trans (test_one _ _ (hf _) (norm_chi _ _))norm_numlemma edge_prob {s : Scene M} {i : ℕ} (hm : 0 < s.mass) (hn : 0 < s.norm)(hp : s.here.ok M) (h : 0 ≤ s.wage) :s.mass/s.norm * s.actor.prob (fun x => lanes s.here i M ∧ flanked s.here i x)= edgeW s i := byclassicalrw [prob_eq,edgeW]by_cases hh : lanes s.here i M· simp only [hh,ite_true,true_and]; rw [Finset.mul_sum]refine Finset.sum_congr rfl fun x hx => ?_split_ifs with H· rw [actor_def hp h hm]unfold wt mass; unfold mass at hmfield_simpexact mul_zero _simp [hh]/-- Mask of sufficient precision is a biased test under the post law -/theorem masked_bias {s : Scene M} {i : ℕ} (main : Bool) (x : Grid M)(hp : s.here.valid) (he : s.here.lev < M)(ha : 0 ≤ s.wage) (hn : 0 < s.norm) (hm : 0 < s.mass) (hM : s.mass ≤ 2*s.norm)(h : intense main s (side i) x)(hB : ¬ hazard s main i) (r : ℕ) (hr : side r ≤ amp i main /128) :∃ g : Grid M → ℂ, (∀ z, ‖g z‖ ≤ 1) ∧ ∃ f : Grid M → ℝ,limitR f (band s.here i r) ∧ (∀ y, 0 ≤ f y ∧ f y ≤ 1) ∧expU (fun y => if y∈s.here.block M then 0 else f y) ≤ s.here.len*side r ∧amp i main /8 ≤ (tracker s main).Ex (fun y => f y.1*(g y.2*chi x y.1).re) := byobtain ⟨b,g,hg,hG⟩ := criterion_bias s main i x hp he ha hn hm hobtain ⟨f,hf,hN,hE,hP⟩ := make_mask (M:=M) s.here hp he b i rlet p := s.herelet a := amp i main; let v := s.mass/s.normlet P := tracker s mainlet w (y : Grid M × Grid M) := (g y.2*chi x y.1).relet G (y : Grid M) := lanes p i M ∧ flanked p i ylet F (y : Grid M × Grid M) := f y.1*w yhave Hq : v*P.prob (fun y => G y.1) ≤ a/128 := byrw [← prob_send P Prod.fst G,show P.send Prod.fst=s.actor from send_fst_withNext _ _]rw [edge_prob hm hn ⟨hp,he.le⟩ ha]exact le_of_not_ge hBhave Hw (i) : |w i| ≤ 1 := test_one _ _ (hg _) (norm_chi _ _)have H : v * P.Ex (fun i => aim (p:=p) b i.1*w i) ≤v* (P.Ex F + P.prob (fun i => G i.1) + side r) := byapply mul_le_mul_of_nonneg_left _ (by positivity)rw [← Ex_const P (side r)]; unfold probrw [← Ex_add,← Ex_add]apply Ex_mono_mem; rintro ⟨y,z⟩ hhave h0 : y∈p.block M := byhave hh : 0 < s.actor y := pos_of_mul_pos_left h ((channel (optic s main) y).nonneg z)exact piece_support ⟨hp,he.le⟩ (actor_def ⟨hp,he.le⟩ ha hm) _ hhchange aim (p:=p) b y*w (y,z) ≤ f y*w (y,z)+(@ite ℝ (G y) (Classical.propDecidable _) 1 0)+side rhave hi := abs_le.mp (Hw (y,z))have hi' := hN ysplit_ifs with H· unfold aim; split_ifs <;> nlinarith [side_pos r]have He : |aim (p:=p) b y-f y| ≤ side r := hE y h0 Hhave hY := (mul_le_mul He (Hw (y,z)) (abs_nonneg _) (side_pos r).le)rw [← abs_mul,mul_one] at hYhave hx := (abs_le.mp hY).2linarithrefine ⟨g,hg,f,hf,hN,hP,?_⟩have hv : v ≤ 2 := (div_le_iff₀ hn).mpr hMhave hp' : 0 < v := by unfold v; positivitychange a/2 ≤ _ at hGchange _ ≤ v * P.Ex (fun i => aim (p:=p) b i.1*w i) at hGhave HH : 0 < a := amp_pos _ _change a/8 ≤ P.Ex Fchange side r ≤ a/128 at hrnlinarithend FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import OAI.Analysis.FourierLLogL.Capture.Append/-! # Adaptive frequency list along a plateau -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Chartvariable {M J j : ℕ}open scoped Classicaldef speed (p : Node) (i n : ℕ) := band p i (offset i n)def horizon (p : Node) (i n : ℕ) := (1+n:ℝ)*speed p i ndef localSize (p : Node) (i : ℕ) (c : Chart M) :=c.wide ≤ c.size*speed p i c.sizelemma speed_pos (p : Node) (i n : ℕ) : 0 ≤ speed p i n := by unfold speed band; positivitylemma speed_le {p q : Node} (h : p.lev ≤ q.lev) {i n m : ℕ} (he : n ≤ m) :speed p i n ≤ speed q i m := byunfold speed band offsetgcongr; norm_num/-- One or several appends before a jump. -/structure Widen (p : Scene M) (i : ℕ) (main : Bool) (c d : Chart M) : Prop wheresonic : d.Soundextend : c.items ⊆ d.itemspaid : flex p main d.refs+price main i*(d.size-c.size:ℝ) ≤ flex p main c.refsexpands : localSize p.here i c → localSize p.here i dmass : d.size=c.size ∨ amp i main/2 ≤ p.mass/p.normawake : ¬ hazard p main i → ∀ x, intense main p (side i) x →atReach d.items (d.wide+speed p.here i d.size) xlemma widen_done (main : Bool) (i : ℕ) {q : Scene M}(hp : q.here.valid) (he : q.here.lev < M) (ha : 0 ≤ q.wage) (hn : 0 < q.norm)(hm : 0 < q.mass) (hM : q.mass ≤ 2*q.norm)(c : Chart M) (h : c.Sound) : ∃ d, Widen q i main c d := byclassicallet b := Fintype.card (Grid M)suffices H : ∀ n : ℕ, ∀ c : Chart M, b-c.size=n → c.Sound →∃ d, Widen q i main c d from H _ _ rfl hintro n; induction n using Nat.strong_induction_on with| h n ih =>intro c heq hby_cases hv : ¬ hazard q main i → ∀ x, intense main q (side i) x →atReach c.items (c.wide+speed q.here i c.size) x· exact ⟨c,h,Finset.Subset.refl _,by simp,id,Or.inl rfl,hv⟩push Not at hvobtain ⟨hH,x,hx,hB⟩ := hvobtain ⟨d,h1,h2,h3,h4,h5⟩ := append_choose _ _ hp he ha hn hm hM hH c h x hx hBhave hd : b-d.size < n := byhave H : d.size ≤ b := Finset.card_le_univ _; omegaobtain ⟨t,h₁,h₂,h₃,h₄,h₅,h₆⟩ := ih _ hd d rfl h4refine ⟨t,h₁,Finset.Subset.trans ?_ h₂,?_,fun hk => h₄ ?_,Or.inr(expensive_intent main hp he ha hn hm hx), h₆⟩· rw [h1]; exact Finset.subset_insert _ _· rw [← h2] at h₃; push_cast at *linarithunfold localSize at *; rw [h3,← h2]; push_casthave hi' : speed q.here i c.size ≤ speed q.here i (c.size+1) := speed_le le_rfl (by omega)change c.wide+speed q.here i c.size ≤ _nlinarith [Nat.cast_nonneg (α:=ℝ) c.size]def zoom (s : Scene M) (i : ℕ) (main : Bool) (q : Chart M) : Chart M :=if h : ∃ c, Widen s i main q c then Classical.choose h else qlemma zoom_spec {s q : Scene M} {l}(t : Chart M) (hp : t.Sound) (i : ℕ) (main : Bool) {f : Grid M → ℝ}(h : Following j J f (Thread.ran s q l)) :Widen q i main t (zoom q i main t) := byunfold zoom; split· exact Classical.choose_spec _· rename_i hF; apply False.elim; apply hFobtain ⟨ha,hb,hc,hd,he,hk⟩ := hhave hS := hd.2.2; unfold enter at hShave ht := hd.1.2.2exact widen_done main _ hc.within.1 (rooted _ (hk false)).within.2 hc.positive (by linarith) ht(by linarith) _ hpdef goal (i : ℕ) (main : Bool) (q : Chart M) : List (Beat M) → Chart M| [] => q| b::l => goal i main (zoom b.post i main q) ldef buildup (i : ℕ) (main : Bool) (q : Chart M) (l : List (Beat M)) :=((goal i main q l).size:ℝ) - q.sizelemma buildup_ran (i : ℕ) (main : Bool) (q : Chart M) (b : Beat M) (l : List (Beat M)) :buildup i main q (b::l) = (zoom b.post i main q).size - (q.size:ℝ) +buildup i main (zoom b.post i main q) l := by simp only [buildup,goal]; ringdef chartDebt (s : Scene M) (j : ℕ) (q : Chart M) (b : Bool) :=flex s b q.refs+(minimumT j)⁻¹lemma buildup_total (s : Scene M) (t : Thread M s) (f : Grid M → ℝ)(h : Following j J f t) (main : Bool) (i : ℕ) (C : Chart M) (hC : C.Sound)(hn : 0 < s.norm) :(amp i main/2*price main i)*(s.here.dice M).Ex (fun x => buildup i main C (t.stream x)) ≤s.mass/s.norm*chartDebt s j C main := byinduction t generalizing C with| blank s =>have hh := rooted _ hrcases eq_or_lt_of_le hh.mass_lower with H|H· simp [stream,buildup,goal,← H,Ex_const]have hF := flex_nonneg _ ⟨hh.within,hh.positive⟩ H main _ (Chart.Sound.pos C hC)have hp : 0 ≤ s.mass/s.norm*chartDebt s j C main := mul_nonneg (by positivity)(add_nonneg hF (inv_nonneg.mpr (minimum_pos j).le))simpa only [stream,buildup,goal,sub_self,Ex_const,mul_zero] using hp| ran s q k ih =>let Z := zoom q i main Clet A := amp i main; let b := price main ilet G (u : Chart M) (t : Scene M) := flex t main u.refslet B := (minimumT j)⁻¹let v := step q; let m := (keep s q).sniphave hm' := pre_pos hhave hD : Widen q i main C Z := zoom_spec _ hC i main hhave hd := debt_at hrw [stream_branch k h (fun l _ => buildup i main C l)]have he b' :(q.smaller b').norm = q.norm := rflobtain ⟨ha,hb,hc,hf,ht,hk⟩ := hhave hs' : ReadyAt s := ⟨ha.within,ha.positive⟩have hq' : ReadyAt q := ⟨hc.within,hc.positive⟩have hQ : 0 < q.norm := by rw [hb.1.flat]; exact hnhave hq := hf.1.2.2have hv : q.here.lev < M := (rooted _ (hk false)).within.2have hF := flex_down main q hc.within.1 hv hc.positive hq Z.refs (Chart.Sound.pos _ hD.sonic)have hS := flex_keep main hb.1 hs' hq' hm' _ (Chart.Sound.pos _ hC)have hK : m.probs true * s.mass=q.mass := (kept_mass hb.1 hs' hq' hm').symmhave hz : 0 ≤ (Z.size:ℝ)-C.size := byapply sub_nonneg.mprexact_mod_cast Finset.card_le_card hD.extendhave HP : 0 ≤ b := by unfold b price; positivitylet d := (Z.size:ℝ)-C.sizehave hP : A/2*b*d ≤ q.mass/q.norm*(b*d) := byrcases hD.mass with H|H· unfold d; simp [H]· rw [mul_assoc]exact mul_le_mul_of_nonneg_right H (mul_nonneg HP hz)let D (u) := G Z (q.smaller u)+Bhave hh (u : Bool) :(A/2*b)* ((q.smaller u).here.dice M).Ex (fun x => buildup i main Z ((k u).stream x)) ≤(q.smaller u).mass/q.norm * D u := ih u (hk u) Z hD.sonic hQlet U := uniform Boollet x (u : Bool) := ((q.smaller u).here.dice M).Ex (fun x => buildup i main Z ((k u).stream x))have HI : U.Ex (fun z => ((q.smaller z).mass/q.norm)*D z) ≤q.mass/q.norm*(G Z q +B) := byhave He := output_split q hc.within.1 hv hc.positive hq (fun z => q.norm⁻¹*D z)have HM : (step q).probs.Ex D ≤ G Z q+B := byunfold D; rw [Ex_add,Ex_const]exact add_le_add_left hF Brw [Ex_lmul] at Hecalc_ = q.mass*(q.norm⁻¹ * v.probs.Ex D) := byunfold U v; rw [He]; congr 1; funext z; ring_ ≤ _ := byrw [← mul_assoc,← div_eq_mul_inv]; exact mul_le_mul_of_nonneg_left HM (by positivity)have HS :(A/2*b)*(U.Ex fun z => d+x z) ≤ q.mass/q.norm*(b*d+G Z q+B) := byrw [Ex_add (f:=fun _ => d),Ex_const,mul_add,← Ex_lmul]have HH := U.Ex_mono hhchange U.Ex (fun z => A/2*b*x z) ≤ _ at HHapply le_trans (add_le_add hP (HH.trans HI)); rw [mul_add,mul_add]exact le_of_eq (by ring)simp_rw [buildup_ran,Ex_add,Ex_const]have hhT : (A/2*b)*(d+U.Ex x) ≤ q.mass/q.norm*(b*d+G Z q+B) := byrw [Ex_add (f:=fun _=>d),Ex_const] at HS; exact HShave hg3 :q.mass/q.norm*(b*d+G Z q+B) ≤ s.mass/s.norm*(G C s+B) := byrw [hb.1.flat,← hK]have hx : b*d + G Z q ≤ G C q := byhave hi := hD.paid; change G Z q + b*d ≤ G C q at hi; linarithhave ht : m.probs true*(b*d+G Z q+B) ≤ G C s+B := bychange m.probs.entropy ≤ B*m.probs false at hdchange m.probs true*G C q ≤ G C s+m.probs.entropy at hShave HQ : m.probs true + m.probs false = 1 := by simpa only [Fintype.sum_bool] using m.probs.totalnlinarith [m.probs.nonneg true,show B * (m.probs true + m.probs false) = B by rw [HQ]; ring]rw [mul_div_assoc,mul_comm (m.probs true),mul_assoc (a:=s.mass/s.norm)]exact mul_le_mul_of_nonneg_left ht (div_nonneg hm'.le hn.le)change A/2*b*(d+U.Ex x) ≤ s.mass/s.norm*(G C s+B)exact hhT.trans hg3end FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import OAI.Analysis.FourierLLogL.Capture.Append/-! # Adaptive frequency list along a plateau -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Thread Chartvariable {M J j : ℕ}open scoped Classicaldef speed (p : Node) (i n : ℕ) := band p i (offset i n)def horizon (p : Node) (i n : ℕ) := (1+n:ℝ)*speed p i ndef localSize (p : Node) (i : ℕ) (c : Chart M) :=c.wide ≤ c.size*speed p i c.sizelemma speed_pos (p : Node) (i n : ℕ) : 0 ≤ speed p i n := by unfold speed band; positivitylemma speed_le {p q : Node} (h : p.lev ≤ q.lev) {i n m : ℕ} (he : n ≤ m) :speed p i n ≤ speed q i m := byunfold speed band offsetgcongr; norm_num/-- One or several appends before a jump. -/structure Widen (p : Scene M) (i : ℕ) (main : Bool) (c d : Chart M) : Prop wheresonic : d.Soundextend : c.items ⊆ d.itemspaid : flex p main d.refs+price main i*(d.size-c.size:ℝ) ≤ flex p main c.refsexpands : localSize p.here i c → localSize p.here i dmass : d.size=c.size ∨ amp i main/2 ≤ p.mass/p.normawake : ¬ hazard p main i → ∀ x, intense main p (side i) x →atReach d.items (d.wide+speed p.here i d.size) xlemma widen_done (main : Bool) (i : ℕ) {q : Scene M}(hp : q.here.valid) (he : q.here.lev < M) (ha : 0 ≤ q.wage) (hn : 0 < q.norm)(hm : 0 < q.mass) (hM : q.mass ≤ 2*q.norm)(c : Chart M) (h : c.Sound) : ∃ d, Widen q i main c d := byclassicallet b := Fintype.card (Grid M)suffices H : ∀ n : ℕ, ∀ c : Chart M, b-c.size=n → c.Sound →∃ d, Widen q i main c d from H _ _ rfl hintro n; induction n using Nat.strong_induction_on with| h n ih =>intro c heq hby_cases hv : ¬ hazard q main i → ∀ x, intense main q (side i) x →atReach c.items (c.wide+speed q.here i c.size) x· exact ⟨c,h,Finset.Subset.refl _,by simp,id,Or.inl rfl,hv⟩push Not at hvobtain ⟨hH,x,hx,hB⟩ := hvobtain ⟨d,h1,h2,h3,h4,h5⟩ := append_choose _ _ hp he ha hn hm hM hH c h x hx hBhave hd : b-d.size < n := byhave H : d.size ≤ b := Finset.card_le_univ _; omegaobtain ⟨t,h₁,h₂,h₃,h₄,h₅,h₆⟩ := ih _ hd d rfl h4refine ⟨t,h₁,Finset.Subset.trans ?_ h₂,?_,fun hk => h₄ ?_,Or.inr(expensive_intent main hp he ha hn hm hx), h₆⟩· rw [h1]; exact Finset.subset_insert _ _· rw [← h2] at h₃; push_cast at *linarithunfold localSize at *; rw [h3,← h2]; push_casthave hi' : speed q.here i c.size ≤ speed q.here i (c.size+1) := speed_le le_rfl (by omega)change c.wide+speed q.here i c.size ≤ _nlinarith [Nat.cast_nonneg (α:=ℝ) c.size]def zoom (s : Scene M) (i : ℕ) (main : Bool) (q : Chart M) : Chart M :=if h : ∃ c, Widen s i main q c then Classical.choose h else qlemma zoom_spec {s q : Scene M} {l}(t : Chart M) (hp : t.Sound) (i : ℕ) (main : Bool) {f : Grid M → ℝ}(h : Following j J f (Thread.ran s q l)) :Widen q i main t (zoom q i main t) := byunfold zoom; split· exact Classical.choose_spec _· rename_i hF; apply False.elim; apply hFobtain ⟨ha,hb,hc,hd,he,hk⟩ := hhave hS := hd.2.2; unfold enter at hShave ht := hd.1.2.2exact widen_done main _ hc.within.1 (rooted _ (hk false)).within.2 hc.positive (by linarith) ht(by linarith) _ hpdef goal (i : ℕ) (main : Bool) (q : Chart M) : List (Beat M) → Chart M| [] => q| b::l => goal i main (zoom b.post i main q) ldef buildup (i : ℕ) (main : Bool) (q : Chart M) (l : List (Beat M)) :=((goal i main q l).size:ℝ) - q.sizelemma buildup_ran (i : ℕ) (main : Bool) (q : Chart M) (b : Beat M) (l : List (Beat M)) :buildup i main q (b::l) = (zoom b.post i main q).size - (q.size:ℝ) +buildup i main (zoom b.post i main q) l := by simp only [buildup,goal]; ringdef chartDebt (s : Scene M) (j : ℕ) (q : Chart M) (b : Bool) :=flex s b q.refs+(minimumT j)⁻¹lemma buildup_total (s : Scene M) (t : Thread M s) (f : Grid M → ℝ)(h : Following j J f t) (main : Bool) (i : ℕ) (C : Chart M) (hC : C.Sound)(hn : 0 < s.norm) :(amp i main/2*price main i)*(s.here.dice M).Ex (fun x => buildup i main C (t.stream x)) ≤s.mass/s.norm*chartDebt s j C main := byinduction t generalizing C with| blank s =>have hh := rooted _ hrcases eq_or_lt_of_le hh.mass_lower with H|H· simp [stream,buildup,goal,← H,Ex_const]have hF := flex_nonneg _ ⟨hh.within,hh.positive⟩ H main _ (Chart.Sound.pos C hC)have hp : 0 ≤ s.mass/s.norm*chartDebt s j C main := mul_nonneg (by positivity)(add_nonneg hF (inv_nonneg.mpr (minimum_pos j).le))simpa only [stream,buildup,goal,sub_self,Ex_const,mul_zero] using hp| ran s q k ih =>let Z := zoom q i main Clet A := amp i main; let b := price main ilet G (u : Chart M) (t : Scene M) := flex t main u.refslet B := (minimumT j)⁻¹let v := step q; let m := (keep s q).sniphave hm' := pre_pos hhave hD : Widen q i main C Z := zoom_spec _ hC i main hhave hd := debt_at hrw [stream_branch k h (fun l _ => buildup i main C l)]have he b' :(q.smaller b').norm = q.norm := rflobtain ⟨ha,hb,hc,hf,ht,hk⟩ := hhave hs' : ReadyAt s := ⟨ha.within,ha.positive⟩have hq' : ReadyAt q := ⟨hc.within,hc.positive⟩have hQ : 0 < q.norm := by rw [hb.1.flat]; exact hnhave hq := hf.1.2.2have hv : q.here.lev < M := (rooted _ (hk false)).within.2have hF := flex_down main q hc.within.1 hv hc.positive hq Z.refs (Chart.Sound.pos _ hD.sonic)have hS := flex_keep main hb.1 hs' hq' hm' _ (Chart.Sound.pos _ hC)have hK : m.probs true * s.mass=q.mass := (kept_mass hb.1 hs' hq' hm').symmhave hz : 0 ≤ (Z.size:ℝ)-C.size := byapply sub_nonneg.mprexact_mod_cast Finset.card_le_card hD.extendhave HP : 0 ≤ b := by unfold b price; positivitylet d := (Z.size:ℝ)-C.sizehave hP : A/2*b*d ≤ q.mass/q.norm*(b*d) := byrcases hD.mass with H|H· unfold d; simp [H]· rw [mul_assoc]exact mul_le_mul_of_nonneg_right H (mul_nonneg HP hz)let D (u) := G Z (q.smaller u)+Bhave hh (u : Bool) :(A/2*b)* ((q.smaller u).here.dice M).Ex (fun x => buildup i main Z ((k u).stream x)) ≤(q.smaller u).mass/q.norm * D u := ih u (hk u) Z hD.sonic hQlet U := uniform Boollet x (u : Bool) := ((q.smaller u).here.dice M).Ex (fun x => buildup i main Z ((k u).stream x))have HI : U.Ex (fun z => ((q.smaller z).mass/q.norm)*D z) ≤q.mass/q.norm*(G Z q +B) := byhave He := output_split q hc.within.1 hv hc.positive hq (fun z => q.norm⁻¹*D z)have HM : (step q).probs.Ex D ≤ G Z q+B := byunfold D; rw [Ex_add,Ex_const]exact add_le_add_left hF Brw [Ex_lmul] at Hecalc_ = q.mass*(q.norm⁻¹ * v.probs.Ex D) := byunfold U v; rw [He]; congr 1; funext z; ring_ ≤ _ := byrw [← mul_assoc,← div_eq_mul_inv]; exact mul_le_mul_of_nonneg_left HM (by positivity)have HS :(A/2*b)*(U.Ex fun z => d+x z) ≤ q.mass/q.norm*(b*d+G Z q+B) := byrw [Ex_add (f:=fun _ => d),Ex_const,mul_add,← Ex_lmul]have HH := U.Ex_mono hhchange U.Ex (fun z => A/2*b*x z) ≤ _ at HHapply le_trans (add_le_add hP (HH.trans HI)); rw [mul_add,mul_add]exact le_of_eq (by ring)simp_rw [buildup_ran,Ex_add,Ex_const]have hhT : (A/2*b)*(d+U.Ex x) ≤ q.mass/q.norm*(b*d+G Z q+B) := byrw [Ex_add (f:=fun _=>d),Ex_const] at HS; exact HShave hg3 :q.mass/q.norm*(b*d+G Z q+B) ≤ s.mass/s.norm*(G C s+B) := byrw [hb.1.flat,← hK]have hx : b*d + G Z q ≤ G C q := byhave hi := hD.paid; change G Z q + b*d ≤ G C q at hi; linarithhave ht : m.probs true*(b*d+G Z q+B) ≤ G C s+B := bychange m.probs.entropy ≤ B*m.probs false at hdchange m.probs true*G C q ≤ G C s+m.probs.entropy at hShave HQ : m.probs true + m.probs false = 1 := by simpa only [Fintype.sum_bool] using m.probs.totalnlinarith [m.probs.nonneg true,show B * (m.probs true + m.probs false) = B by rw [HQ]; ring]rw [mul_div_assoc,mul_comm (m.probs true),mul_assoc (a:=s.mass/s.norm)]exact mul_le_mul_of_nonneg_left ht (div_nonneg hm'.le hn.le)change A/2*b*(d+U.Ex x) ≤ s.mass/s.norm*(G C s+B)exact hhT.trans hg3end FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157import OAI.Analysis.FourierLLogL.Capture.Criterionimport OAI.Analysis.FourierLLogL.Plateau.Featuresopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M : ℕ} {s : Scene M}open scoped Classicaldef utility (main : Bool) (k x : ℂ) :=if main then 2*(k*x).re-‖k‖^2 else (k*x).redef sales (main : Bool) (s : Scene M) (c : Grid M → ℂ) (i : Grid M) :=rung s (channel (optic s main)) (fun x z => utility main (c z) (chi i x))lemma utility_bounds (main : Bool) (k x : ℂ) (hk : ‖k‖ ≤ 1) (hx : ‖x‖=1) :|utility main k x| ≤ 3 := byhave hi : |(k*x).re| ≤ 1 := (Complex.abs_re_le_norm _).trans (by rw [norm_mul,hx,mul_one]; exact hk)obtain ⟨h1,h2⟩ := abs_le.mp hirw [abs_le]unfold utility; split <;>· constructor <;> nlinarith [norm_nonneg k]lemma utility_diff (main : Bool) (k x y : ℂ) (hk : ‖k‖ ≤ 1) :|utility main k x- utility main k y| ≤ 2* ‖x-y‖ := byhave he : |(k*x).re-(k*y).re| ≤ ‖x-y‖ := byrw [← Complex.sub_re,←mul_sub]exact (Complex.abs_re_le_norm _).trans (byrw [norm_mul]; exact mul_le_of_le_one_left (norm_nonneg _) hk)cases main· change |(k*x).re-(k*y).re| ≤ _; linarith [norm_nonneg (x-y)]change |2*_ -_-(2*_ -_)| ≤ _rw [sub_sub_sub_cancel_right,←mul_sub,abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2)]linarithprivate lemma income (main : Bool) (s : Scene M) (c : Grid M → ℂ) (i : Grid M) :let A := optic s main(sales main s c i) = ∑ z : Grid M, let f := fz s.here s.wage s.norm A i zlet H := hist s (channel A) zif main then 2 * (c z*f).re - H*‖c z‖^2else (c z*f).re := byintro Aunfold sales rungrw [Finset.sum_comm]refine Finset.sum_congr rfl fun z _ => ?_let l := fun x : Grid M => addMass s (channel A) x zhave hi : (c z * fz s.here s.wage s.norm A i z).re =∑ x : Grid M, l x * (c z * chi i x).re := byunfold fzrw [Finset.mul_sum,Complex.re_sum]refine Finset.sum_congr rfl fun x hx => ?_rw [mul_left_comm, Complex.re_ofReal_mul]rflchange ∑ x, l x * utility main _ _ = (if _ then _ else _)rw [hi]splitcase isTrue he =>simp_rw [show ∀ k v : ℂ, utility main k v = 2*(k*v).re-‖k‖^2 from fun _ _ => by simp [he,utility]]rw [Finset.mul_sum,show hist s (channel A) z=∑ i, l i from rfl, Finset.sum_mul]rw [← Finset.sum_sub_distrib]; exact Finset.sum_congr rfl fun _ _ => by ringcase isFalse he =>simp_rw [show ∀ k v : ℂ, utility main k v = (k*v).re from fun _ _ => by simp [he,utility]]private lemma fz_dry (s : Scene M) (i z : Grid M) :fz s.here s.wage s.norm 0 i z = (side M:ℂ)*scalar s i := byunfold fz omegaObs scalar; simp_rw [no_label,uniform_side,Complex.ofReal_mul,Finset.mul_sum]exact Finset.sum_congr rfl fun _ _ => by ringprivate def seller (M : ℝ) (f : ℂ) : ℂ := conj f / Mprivate lemma seller_limit (M : ℝ) (f : ℂ) (hf : ‖f‖ ≤ M) : ‖seller M f‖ ≤ 1 := byhave hx : 0 ≤ M := le_trans (norm_nonneg _) hfunfold seller; rw [norm_div,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hx,Complex.norm_conj]rcases eq_or_lt_of_le hx with h|h· rw [← h,div_zero]; norm_numexact (div_le_one h).mpr hfprivate lemma price_upper (m : ℝ) (f k : ℂ) (hf : ‖f‖ ≤ m) :2*(k*f).re - m*‖k‖^2 ≤ ‖f‖^2/m := byhave hx : 0 ≤ m := le_trans (norm_nonneg _) hfrcases eq_or_lt_of_le hx with h|h· have hh : f=0 := norm_le_zero_iff.mp (h ▸ hf)simp [←h, hh]· have hi : (k*f).re ≤ ‖k‖ * ‖f‖ :=(le_abs_self _).trans ((Complex.abs_re_le_norm _).trans (by rw [norm_mul]))apply (le_div_iff₀ h).mprnlinarith [sq_nonneg (m *‖k‖ - ‖f‖),mul_le_mul_of_nonneg_left hi h.le]private lemma seller_eq (m : ℝ) (f : ℂ) (hf : ‖f‖ ≤ m) :2*(seller m f*f).re - m*‖seller m f‖^2= ‖f‖^2 / m := byhave hx : 0 ≤ m := le_trans (norm_nonneg _) hfunfold sellerby_cases hm : m = 0· subst m; simp· rw [div_mul_eq_mul_div,mul_comm (conj f) f,Complex.mul_conj,←Complex.sq_norm,← Complex.ofReal_div,norm_div,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hx,Complex.norm_conj,Complex.ofReal_re]field_simp; ring/-- sales of every packet at most the magnitude, attained by choice of a bounded tester. -/theorem test_complete (main : Bool) (s : Scene M) (hp : 0 ≤ s.wage) (hv : 0 ≤ s.norm)(i : Grid M) :(∀ c : Grid M → ℂ, (∀ z, ‖c z‖ ≤ 1) → sales main s c i ≤ magnitude main s i) ∧∃ c : Grid M → ℂ, (∀ z, ‖c z‖ ≤ 1) ∧ sales main s c i = magnitude main s i := bycases maincase true =>let L (z) := Mz s.here s.wage s.norm s.fund.mood zlet f (z) := fz s.here s.wage s.norm s.fund.mood i zhave hf z : ‖f z‖ ≤ L z := fz_norm _ hp hv _ _ _constructor· intro c _; rw [income]apply Finset.sum_le_sum; intro j hj; exact price_upper (L j) (f j) _ (hf j)refine ⟨fun i => seller (L i) (f i),fun i => seller_limit _ _ (hf i),?_⟩rw [income]refine Finset.sum_congr rfl fun j _ => seller_eq (L j) (f j) (hf j)case false =>let f := scalar s ihave h1 (c : Grid M → ℂ) :sales false s c i = (uniform (Grid M)).Ex (fun z => (c z*f).re) := byrw [income]change ∑ z : Grid M,(c z*fz s.here s.wage s.norm 0 i z).re= _unfold Exrefine Finset.sum_congr rfl fun z _ => ?_rw [fz_dry,mul_left_comm,Complex.re_ofReal_mul,uniform_side]constructor· intro c hcrw [h1]apply le_trans (b:=(uniform (Grid M)).Ex fun _ => ‖f‖)· refine Ex_mono _ fun i => ?_apply (le_abs_self _).trans ((Complex.abs_re_le_norm _).trans _)rw [norm_mul]; exact mul_le_of_le_one_left (norm_nonneg _) (hc i)rw [Ex_const]exact le_rflrefine ⟨fun _ => polar f,fun _ => polar_unit f,?_⟩rw [h1,Ex_const]exact polar_identity flemma sup_children (main : Bool) (s : Scene M) (hp : s.here.valid) (h : s.here.lev < M)(ha : 0 ≤ s.wage) (hb : 0 ≤ s.norm) (i : Grid M) :∃ b, magnitude main s i ≤ magnitude main (s.smaller b) i := byobtain ⟨c,hc,H⟩ := (test_complete main s ha hb i).2let T (b : Bool) := sales main (s.smaller b) c ihave he : T false+T true= 2*sales main s c i := rung_split s hp h _ _by_contra! HHhave h1 (b : Bool) : T b ≤ magnitude main (s.smaller b) i :=(test_complete main (s.smaller b) ha hb i).1 _ hclinarith [HH true,HH false,h1 true,h1 false]end FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157import OAI.Analysis.FourierLLogL.Capture.Criterionimport OAI.Analysis.FourierLLogL.Plateau.Featuresopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M : ℕ} {s : Scene M}open scoped Classicaldef utility (main : Bool) (k x : ℂ) :=if main then 2*(k*x).re-‖k‖^2 else (k*x).redef sales (main : Bool) (s : Scene M) (c : Grid M → ℂ) (i : Grid M) :=rung s (channel (optic s main)) (fun x z => utility main (c z) (chi i x))lemma utility_bounds (main : Bool) (k x : ℂ) (hk : ‖k‖ ≤ 1) (hx : ‖x‖=1) :|utility main k x| ≤ 3 := byhave hi : |(k*x).re| ≤ 1 := (Complex.abs_re_le_norm _).trans (by rw [norm_mul,hx,mul_one]; exact hk)obtain ⟨h1,h2⟩ := abs_le.mp hirw [abs_le]unfold utility; split <;>· constructor <;> nlinarith [norm_nonneg k]lemma utility_diff (main : Bool) (k x y : ℂ) (hk : ‖k‖ ≤ 1) :|utility main k x- utility main k y| ≤ 2* ‖x-y‖ := byhave he : |(k*x).re-(k*y).re| ≤ ‖x-y‖ := byrw [← Complex.sub_re,←mul_sub]exact (Complex.abs_re_le_norm _).trans (byrw [norm_mul]; exact mul_le_of_le_one_left (norm_nonneg _) hk)cases main· change |(k*x).re-(k*y).re| ≤ _; linarith [norm_nonneg (x-y)]change |2*_ -_-(2*_ -_)| ≤ _rw [sub_sub_sub_cancel_right,←mul_sub,abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2)]linarithprivate lemma income (main : Bool) (s : Scene M) (c : Grid M → ℂ) (i : Grid M) :let A := optic s main(sales main s c i) = ∑ z : Grid M, let f := fz s.here s.wage s.norm A i zlet H := hist s (channel A) zif main then 2 * (c z*f).re - H*‖c z‖^2else (c z*f).re := byintro Aunfold sales rungrw [Finset.sum_comm]refine Finset.sum_congr rfl fun z _ => ?_let l := fun x : Grid M => addMass s (channel A) x zhave hi : (c z * fz s.here s.wage s.norm A i z).re =∑ x : Grid M, l x * (c z * chi i x).re := byunfold fzrw [Finset.mul_sum,Complex.re_sum]refine Finset.sum_congr rfl fun x hx => ?_rw [mul_left_comm, Complex.re_ofReal_mul]rflchange ∑ x, l x * utility main _ _ = (if _ then _ else _)rw [hi]splitcase isTrue he =>simp_rw [show ∀ k v : ℂ, utility main k v = 2*(k*v).re-‖k‖^2 from fun _ _ => by simp [he,utility]]rw [Finset.mul_sum,show hist s (channel A) z=∑ i, l i from rfl, Finset.sum_mul]rw [← Finset.sum_sub_distrib]; exact Finset.sum_congr rfl fun _ _ => by ringcase isFalse he =>simp_rw [show ∀ k v : ℂ, utility main k v = (k*v).re from fun _ _ => by simp [he,utility]]private lemma fz_dry (s : Scene M) (i z : Grid M) :fz s.here s.wage s.norm 0 i z = (side M:ℂ)*scalar s i := byunfold fz omegaObs scalar; simp_rw [no_label,uniform_side,Complex.ofReal_mul,Finset.mul_sum]exact Finset.sum_congr rfl fun _ _ => by ringprivate def seller (M : ℝ) (f : ℂ) : ℂ := conj f / Mprivate lemma seller_limit (M : ℝ) (f : ℂ) (hf : ‖f‖ ≤ M) : ‖seller M f‖ ≤ 1 := byhave hx : 0 ≤ M := le_trans (norm_nonneg _) hfunfold seller; rw [norm_div,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hx,Complex.norm_conj]rcases eq_or_lt_of_le hx with h|h· rw [← h,div_zero]; norm_numexact (div_le_one h).mpr hfprivate lemma price_upper (m : ℝ) (f k : ℂ) (hf : ‖f‖ ≤ m) :2*(k*f).re - m*‖k‖^2 ≤ ‖f‖^2/m := byhave hx : 0 ≤ m := le_trans (norm_nonneg _) hfrcases eq_or_lt_of_le hx with h|h· have hh : f=0 := norm_le_zero_iff.mp (h ▸ hf)simp [←h, hh]· have hi : (k*f).re ≤ ‖k‖ * ‖f‖ :=(le_abs_self _).trans ((Complex.abs_re_le_norm _).trans (by rw [norm_mul]))apply (le_div_iff₀ h).mprnlinarith [sq_nonneg (m *‖k‖ - ‖f‖),mul_le_mul_of_nonneg_left hi h.le]private lemma seller_eq (m : ℝ) (f : ℂ) (hf : ‖f‖ ≤ m) :2*(seller m f*f).re - m*‖seller m f‖^2= ‖f‖^2 / m := byhave hx : 0 ≤ m := le_trans (norm_nonneg _) hfunfold sellerby_cases hm : m = 0· subst m; simp· rw [div_mul_eq_mul_div,mul_comm (conj f) f,Complex.mul_conj,←Complex.sq_norm,← Complex.ofReal_div,norm_div,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hx,Complex.norm_conj,Complex.ofReal_re]field_simp; ring/-- sales of every packet at most the magnitude, attained by choice of a bounded tester. -/theorem test_complete (main : Bool) (s : Scene M) (hp : 0 ≤ s.wage) (hv : 0 ≤ s.norm)(i : Grid M) :(∀ c : Grid M → ℂ, (∀ z, ‖c z‖ ≤ 1) → sales main s c i ≤ magnitude main s i) ∧∃ c : Grid M → ℂ, (∀ z, ‖c z‖ ≤ 1) ∧ sales main s c i = magnitude main s i := bycases maincase true =>let L (z) := Mz s.here s.wage s.norm s.fund.mood zlet f (z) := fz s.here s.wage s.norm s.fund.mood i zhave hf z : ‖f z‖ ≤ L z := fz_norm _ hp hv _ _ _constructor· intro c _; rw [income]apply Finset.sum_le_sum; intro j hj; exact price_upper (L j) (f j) _ (hf j)refine ⟨fun i => seller (L i) (f i),fun i => seller_limit _ _ (hf i),?_⟩rw [income]refine Finset.sum_congr rfl fun j _ => seller_eq (L j) (f j) (hf j)case false =>let f := scalar s ihave h1 (c : Grid M → ℂ) :sales false s c i = (uniform (Grid M)).Ex (fun z => (c z*f).re) := byrw [income]change ∑ z : Grid M,(c z*fz s.here s.wage s.norm 0 i z).re= _unfold Exrefine Finset.sum_congr rfl fun z _ => ?_rw [fz_dry,mul_left_comm,Complex.re_ofReal_mul,uniform_side]constructor· intro c hcrw [h1]apply le_trans (b:=(uniform (Grid M)).Ex fun _ => ‖f‖)· refine Ex_mono _ fun i => ?_apply (le_abs_self _).trans ((Complex.abs_re_le_norm _).trans _)rw [norm_mul]; exact mul_le_of_le_one_left (norm_nonneg _) (hc i)rw [Ex_const]exact le_rflrefine ⟨fun _ => polar f,fun _ => polar_unit f,?_⟩rw [h1,Ex_const]exact polar_identity flemma sup_children (main : Bool) (s : Scene M) (hp : s.here.valid) (h : s.here.lev < M)(ha : 0 ≤ s.wage) (hb : 0 ≤ s.norm) (i : Grid M) :∃ b, magnitude main s i ≤ magnitude main (s.smaller b) i := byobtain ⟨c,hc,H⟩ := (test_complete main s ha hb i).2let T (b : Bool) := sales main (s.smaller b) c ihave he : T false+T true= 2*sales main s c i := rung_split s hp h _ _by_contra! HHhave h1 (b : Bool) : T b ≤ magnitude main (s.smaller b) i :=(test_complete main (s.smaller b) ha hb i).1 _ hclinarith [HH true,HH false,h1 true,h1 false]end FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167import OAI.Analysis.FourierLLogL.Capture.Criterion/-! # Entropy relative to the adaptive product -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M : ℕ} {s q : Scene M}open scoped Classicalabbrev ProductRef (M : ℕ) := Grid M → Grid M → ℝdef normQ (s : Scene M) (f : ProductRef M) (z : Grid M) :=(s.here.dice M).Ex (f z)lemma normQ_pos (s : Scene M) (f : ProductRef M) (h : ∀ i j, 0 < f i j) (z) :0 < normQ s f z := bylet Q := s.here.dice Mobtain ⟨i,hi,he⟩ := Q.exists_le_Ex (f z)exact lt_of_lt_of_le (h z i) hedef flex (s : Scene M) (main : Bool) (Q : ProductRef M) :=deficit s (channel (optic s main)) +(tracker s main).Ex (fun i => log (normQ s Q i.2)-log (Q i.2 i.1))lemma flex_nonneg (s : Scene M) (h : ReadyAt s) (hm : 0 < s.mass)(main : Bool) (f : ProductRef M) (hP : ∀ z y, 0 < f z y) :0 ≤ flex s main f := bylet A := optic s mainlet k := channel Alet Q := s.actor.withNext klet P := s.here.dice Mhave hh (z : Grid M) : 0 < ∑ i, P i * f z i := normQ_pos s _ hP zlet Hq (z : Grid M) : Law (Grid M) := proportional (fun i => P i*f z i)(fun i => mul_nonneg (P.nonneg _) (hP _ _).le) (hh z)have hz (i z : Grid M) : Hq z i = P i*f z i / normQ s f z := rflhave HV (x : Grid M × Grid M) (hx : 0 < Q x) : 0 < P x.1 := byapply (dice_positive h.1).mprapply piece_support h.1 (actor_def h.1 h.2 hm)exact pos_of_mul_pos_left hx ((k _).nonneg _)have hi := Hcond_compare Q Prod.fst Prod.snd Hq (fun i hi => byrw [hz]; exact div_pos (mul_pos (HV i hi) (hP _ _)) (normQ_pos s _ hP _))have he (i) (hx : 0 < Q i) :-log (Hq i.2 i.1) = levels s+(log (normQ s f i.2)-log (f i.2 i.1)) := byrw [hz,Real.log_div (mul_pos (HV i hx) (hP _ _)).ne' (normQ_pos s _ hP _).ne',Real.log_mul (HV i hx).ne' (hP _ _).ne']have HE := (dice_positive h.1).mp (HV i hx)unfold levels Prw [dice_apply h.1,ite_eq_left HE,Real.log_mul (side_pos _).ne'(inv_pos.mpr s.here.len_pos).ne']unfold len; simp_rw [side_pow_two,log_inv,log_pow]rw [Nat.cast_sub h.1.2]ringrw [Ex_congr_mem _ he, Ex_add (f:=fun _ => levels s), Ex_const] at hichange 0 ≤ levels s -Q.Hcond Prod.fst Prod.snd + Q.Ex _linarithlemma flex_one (s : Scene M) (main : Bool) :flex s main (fun _ _ => 1) = deficit s (channel (optic s main)) := bysimp_rw [flex,normQ,Ex_const,log_one,sub_zero,add_zero]lemma track_shift {s : Scene M} (main : Bool) {v : Fork M} (he : v.src = s)(h : v.TrueLaw) (k : ∀ i, optic (v.dst i) main = optic s main)(g : Bool → Grid M × Grid M → ℝ) :v.probs.Ex (fun i => (tracker (v.dst i) main).Ex (g i)) =(tracker s main).Ex (fun x => g (v.bit x.1) x) := bysubst sunfold trackersimp_rw [k,Ex_withNext]exact expect_bit h (fun i x => (channel _ x).Ex (fun y => g i (x,y)))lemma flex_keep (main : Bool) {s q : Scene M} (h : Less s q) (hh : ReadyAt s)(hp : ReadyAt q) (hm : 0 < s.mass)(f : ProductRef M) (hF : ∀ i j, 0 < f i j) :let P := (keep s q).snip.probsP true * flex q main f ≤ flex s main f + P.entropy := byintro Plet v := (keep s q).sniphave he := keep_true h hh hp hmlet A := optic s main; let k := channel Ahave hX (i : Bool) : optic (v.dst i) main = A := bycases i· rflchange optic q main=optic s main; simp [optic,h.fund]have hi (i) : (v.dst i).here=s.here := keep_here h _let Z (i : Grid M × Grid M) := log (normQ s f i.2)-log (f i.2 i.1)have hv : P.Ex (fun i => flex (v.dst i) main f) ≤ flex s main f + P.entropy := byhave hi' := track_shift main (v:=v) rfl he hX (fun _ => Z)have heq (i z) : normQ (v.dst i) f z = normQ s f z := by unfold normQ; rw [hi]have hE' : P.Ex (fun i => deficit (v.dst i) k) ≤ deficit s k + P.entropy := byhave he := conditioned_balance k v heunfold deficit; rw [Ex_sub]; have hz (b) : levels (v.dst b)=levels s := by unfold levels; rw [hi]simp_rw [hz,Ex_const]have HE := old_entropy_cost v kchange _+_= s.actor.privateH k at heunfold P v at *linarithhave hF (i) : flex (v.dst i) main f =deficit (v.dst i) k + (tracker (v.dst i) main).Ex Z := byunfold flex; simp_rw [heq,hX]; rflsimp_rw [hF,Ex_add]change P.Ex _ + v.probs.Ex _ ≤ deficit s k + (tracker s main).Ex Z + _rw [hi']change _ + (tracker s main).Ex Z ≤ _linarithrw [Ex,Fintype.sum_bool] at hvhave hE : 0 ≤ P false * flex (v.dst false) main f := byrcases eq_or_lt_of_le (P.nonneg false) with H|H; rw [← H,zero_mul]exact mul_nonneg H.le <| flex_nonneg _ (other_ok h hh)((true_mass he).mp H) _ _ hFexact (le_add_of_nonneg_right hE).trans hvlemma flex_down (main : Bool) (s : Scene M) (hp : s.here.valid) (hh : s.here.lev < M)(ha : 0 ≤ s.wage) (hm : 0 < s.mass)(f : ProductRef M) (hF : ∀ i j, 0 < f i j) :(step s).probs.Ex (fun i => flex (s.smaller i) main f) ≤ flex s main f := bylet P := tracker s main; let v := step slet k := channel (optic s main)have hx (i : Bool) : channel (optic (s.smaller i) main) = k := rfllet g (x : Grid M × Grid M) := v.bit x.1have H := step_true hp hh ha hmlet q (z : Grid M) (b : Bool) : ℝ := normQ (s.smaller b) f z/(2*normQ s f z)have HQ (z i) : 0 < q z i := div_pos (normQ_pos _ _ hF _) (by have := normQ_pos s f hF z; positivity)let Q (z : Grid M) : Law Bool :=⟨q z,fun i => (HQ z i).le,byrw [Fintype.sum_bool]have HE :normQ s f z=(normQ (s.smaller false) f z+normQ (s.smaller true) f z)/2 :=s.here.dice_child hp hh _have hh := normQ_pos s f hF zsimp only [q]; field_simp; linarith⟩have he := Hcond_compare P g Prod.snd Q (fun i _ => HQ _ _)have hl (i : Grid M × Grid M) : -log (Q i.2 (g i)) =log 2+log (normQ s f i.2)-log (normQ (s.smaller (g i)) f i.2) := bychange -log (q _ _) = _unfold q; have hx := normQ_pos s f hF i.2rw [log_div (normQ_pos _ _ hF _).ne' (by positivity),log_mul (by norm_num) hx.ne']; ringrw [funext hl] at helet D (b : Bool) (x : Grid M × Grid M) :=log (normQ (s.smaller b) f x.2)-log (f x.2 x.1)have hi : P.Hcond g Prod.snd = sideH v k := rflrw [hi] at hehave hT :v.probs.Ex (fun i => (tracker (s.smaller i) main).Ex (D i)) = P.Ex fun x => D (g x) x :=track_shift main (v:=v) rfl H (fun _ => rfl) Dhave hhE : v.probs.Ex (fun b => (s.smaller b).actor.privateH k) =s.actor.privateH k-sideH v k := byhave Hh := conditioned_balance k v Hchange v.probs.Ex (fun b => (s.smaller b).actor.privateH k)+_=s.actor.privateH k at Hhlinarithchange v.probs.Ex (fun b => deficit _ k + (tracker _ _).Ex (D b)) ≤ _unfold flex deficitsimp_rw [levels_child s hh, Ex_add v.probs]rw [show v.probs.Ex (fun x => _-_) = levels s-log 2-v.probs.Ex(fun b => (s.smaller b).actor.privateH k) by rw [Ex_sub (f:=fun _ => levels s-log 2),Ex_const],hT,hhE]unfold D at *simp_rw [Ex_sub] at *change _ ≤ levels s-s.actor.privateH k+(P.Ex _-P.Ex _)rw [Ex_add (f:=fun _=>log 2),Ex_const] at helinarithend FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167import OAI.Analysis.FourierLLogL.Capture.Criterion/-! # Entropy relative to the adaptive product -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulse Threadvariable {M : ℕ} {s q : Scene M}open scoped Classicalabbrev ProductRef (M : ℕ) := Grid M → Grid M → ℝdef normQ (s : Scene M) (f : ProductRef M) (z : Grid M) :=(s.here.dice M).Ex (f z)lemma normQ_pos (s : Scene M) (f : ProductRef M) (h : ∀ i j, 0 < f i j) (z) :0 < normQ s f z := bylet Q := s.here.dice Mobtain ⟨i,hi,he⟩ := Q.exists_le_Ex (f z)exact lt_of_lt_of_le (h z i) hedef flex (s : Scene M) (main : Bool) (Q : ProductRef M) :=deficit s (channel (optic s main)) +(tracker s main).Ex (fun i => log (normQ s Q i.2)-log (Q i.2 i.1))lemma flex_nonneg (s : Scene M) (h : ReadyAt s) (hm : 0 < s.mass)(main : Bool) (f : ProductRef M) (hP : ∀ z y, 0 < f z y) :0 ≤ flex s main f := bylet A := optic s mainlet k := channel Alet Q := s.actor.withNext klet P := s.here.dice Mhave hh (z : Grid M) : 0 < ∑ i, P i * f z i := normQ_pos s _ hP zlet Hq (z : Grid M) : Law (Grid M) := proportional (fun i => P i*f z i)(fun i => mul_nonneg (P.nonneg _) (hP _ _).le) (hh z)have hz (i z : Grid M) : Hq z i = P i*f z i / normQ s f z := rflhave HV (x : Grid M × Grid M) (hx : 0 < Q x) : 0 < P x.1 := byapply (dice_positive h.1).mprapply piece_support h.1 (actor_def h.1 h.2 hm)exact pos_of_mul_pos_left hx ((k _).nonneg _)have hi := Hcond_compare Q Prod.fst Prod.snd Hq (fun i hi => byrw [hz]; exact div_pos (mul_pos (HV i hi) (hP _ _)) (normQ_pos s _ hP _))have he (i) (hx : 0 < Q i) :-log (Hq i.2 i.1) = levels s+(log (normQ s f i.2)-log (f i.2 i.1)) := byrw [hz,Real.log_div (mul_pos (HV i hx) (hP _ _)).ne' (normQ_pos s _ hP _).ne',Real.log_mul (HV i hx).ne' (hP _ _).ne']have HE := (dice_positive h.1).mp (HV i hx)unfold levels Prw [dice_apply h.1,ite_eq_left HE,Real.log_mul (side_pos _).ne'(inv_pos.mpr s.here.len_pos).ne']unfold len; simp_rw [side_pow_two,log_inv,log_pow]rw [Nat.cast_sub h.1.2]ringrw [Ex_congr_mem _ he, Ex_add (f:=fun _ => levels s), Ex_const] at hichange 0 ≤ levels s -Q.Hcond Prod.fst Prod.snd + Q.Ex _linarithlemma flex_one (s : Scene M) (main : Bool) :flex s main (fun _ _ => 1) = deficit s (channel (optic s main)) := bysimp_rw [flex,normQ,Ex_const,log_one,sub_zero,add_zero]lemma track_shift {s : Scene M} (main : Bool) {v : Fork M} (he : v.src = s)(h : v.TrueLaw) (k : ∀ i, optic (v.dst i) main = optic s main)(g : Bool → Grid M × Grid M → ℝ) :v.probs.Ex (fun i => (tracker (v.dst i) main).Ex (g i)) =(tracker s main).Ex (fun x => g (v.bit x.1) x) := bysubst sunfold trackersimp_rw [k,Ex_withNext]exact expect_bit h (fun i x => (channel _ x).Ex (fun y => g i (x,y)))lemma flex_keep (main : Bool) {s q : Scene M} (h : Less s q) (hh : ReadyAt s)(hp : ReadyAt q) (hm : 0 < s.mass)(f : ProductRef M) (hF : ∀ i j, 0 < f i j) :let P := (keep s q).snip.probsP true * flex q main f ≤ flex s main f + P.entropy := byintro Plet v := (keep s q).sniphave he := keep_true h hh hp hmlet A := optic s main; let k := channel Ahave hX (i : Bool) : optic (v.dst i) main = A := bycases i· rflchange optic q main=optic s main; simp [optic,h.fund]have hi (i) : (v.dst i).here=s.here := keep_here h _let Z (i : Grid M × Grid M) := log (normQ s f i.2)-log (f i.2 i.1)have hv : P.Ex (fun i => flex (v.dst i) main f) ≤ flex s main f + P.entropy := byhave hi' := track_shift main (v:=v) rfl he hX (fun _ => Z)have heq (i z) : normQ (v.dst i) f z = normQ s f z := by unfold normQ; rw [hi]have hE' : P.Ex (fun i => deficit (v.dst i) k) ≤ deficit s k + P.entropy := byhave he := conditioned_balance k v heunfold deficit; rw [Ex_sub]; have hz (b) : levels (v.dst b)=levels s := by unfold levels; rw [hi]simp_rw [hz,Ex_const]have HE := old_entropy_cost v kchange _+_= s.actor.privateH k at heunfold P v at *linarithhave hF (i) : flex (v.dst i) main f =deficit (v.dst i) k + (tracker (v.dst i) main).Ex Z := byunfold flex; simp_rw [heq,hX]; rflsimp_rw [hF,Ex_add]change P.Ex _ + v.probs.Ex _ ≤ deficit s k + (tracker s main).Ex Z + _rw [hi']change _ + (tracker s main).Ex Z ≤ _linarithrw [Ex,Fintype.sum_bool] at hvhave hE : 0 ≤ P false * flex (v.dst false) main f := byrcases eq_or_lt_of_le (P.nonneg false) with H|H; rw [← H,zero_mul]exact mul_nonneg H.le <| flex_nonneg _ (other_ok h hh)((true_mass he).mp H) _ _ hFexact (le_add_of_nonneg_right hE).trans hvlemma flex_down (main : Bool) (s : Scene M) (hp : s.here.valid) (hh : s.here.lev < M)(ha : 0 ≤ s.wage) (hm : 0 < s.mass)(f : ProductRef M) (hF : ∀ i j, 0 < f i j) :(step s).probs.Ex (fun i => flex (s.smaller i) main f) ≤ flex s main f := bylet P := tracker s main; let v := step slet k := channel (optic s main)have hx (i : Bool) : channel (optic (s.smaller i) main) = k := rfllet g (x : Grid M × Grid M) := v.bit x.1have H := step_true hp hh ha hmlet q (z : Grid M) (b : Bool) : ℝ := normQ (s.smaller b) f z/(2*normQ s f z)have HQ (z i) : 0 < q z i := div_pos (normQ_pos _ _ hF _) (by have := normQ_pos s f hF z; positivity)let Q (z : Grid M) : Law Bool :=⟨q z,fun i => (HQ z i).le,byrw [Fintype.sum_bool]have HE :normQ s f z=(normQ (s.smaller false) f z+normQ (s.smaller true) f z)/2 :=s.here.dice_child hp hh _have hh := normQ_pos s f hF zsimp only [q]; field_simp; linarith⟩have he := Hcond_compare P g Prod.snd Q (fun i _ => HQ _ _)have hl (i : Grid M × Grid M) : -log (Q i.2 (g i)) =log 2+log (normQ s f i.2)-log (normQ (s.smaller (g i)) f i.2) := bychange -log (q _ _) = _unfold q; have hx := normQ_pos s f hF i.2rw [log_div (normQ_pos _ _ hF _).ne' (by positivity),log_mul (by norm_num) hx.ne']; ringrw [funext hl] at helet D (b : Bool) (x : Grid M × Grid M) :=log (normQ (s.smaller b) f x.2)-log (f x.2 x.1)have hi : P.Hcond g Prod.snd = sideH v k := rflrw [hi] at hehave hT :v.probs.Ex (fun i => (tracker (s.smaller i) main).Ex (D i)) = P.Ex fun x => D (g x) x :=track_shift main (v:=v) rfl H (fun _ => rfl) Dhave hhE : v.probs.Ex (fun b => (s.smaller b).actor.privateH k) =s.actor.privateH k-sideH v k := byhave Hh := conditioned_balance k v Hchange v.probs.Ex (fun b => (s.smaller b).actor.privateH k)+_=s.actor.privateH k at Hhlinarithchange v.probs.Ex (fun b => deficit _ k + (tracker _ _).Ex (D b)) ≤ _unfold flex deficitsimp_rw [levels_child s hh, Ex_add v.probs]rw [show v.probs.Ex (fun x => _-_) = levels s-log 2-v.probs.Ex(fun b => (s.smaller b).actor.privateH k) by rw [Ex_sub (f:=fun _ => levels s-log 2),Ex_const],hT,hhE]unfold D at *simp_rw [Ex_sub] at *change _ ≤ levels s-s.actor.privateH k+(P.Ex _-P.Ex _)rw [Ex_add (f:=fun _=>log 2),Ex_const] at helinarithend FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196import OAI.Analysis.FourierLLogL.Capture.MaskKernelimport OAI.Analysis.FourierLLogL.Finite.Tailopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulsevariable {p : Node} {M : ℕ}open scoped Classicallemma margins (p : Node) (hp : p.valid) : 0 ≤ p.a ∧ p.a+p.len ≤ 1 := byunfold ahave he : 0 < p.len := p.len_posrefine ⟨by positivity,?_⟩calc_ = ↑(p.ix+1)*p.len := by push_cast; ring_ ≤ ↑(2^p.lev:ℕ)*p.len :=mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hp) he.le_ = _ := by unfold len; push_cast; rw [mul_comm,side_card]lemma inner_strip (p : Node) (b : Bool) (i : ℕ) (x : Grid M)(hx : x∈(child p b).block M) (hh : ¬ flanked p i x) :let q := child p b; let r := p.len*side (reach i)q.a+r ≤ pos x ∧ pos x < q.a+q.len-r := byintro q rhave hi (c : Bool) : ¬ (x∈(strip p i b c).block M) :=fun h => hh ⟨_,_,h⟩have h1 : (strip p i b false).a=q.a := extreme_left q _have h2 (c : Bool) : (strip p i b c).len=r := strip_length _ _ _ _have h3 : (strip p i b true).a + r=q.a+q.len := byrw [← h2 true]; exact extreme_right _ _have Hp : x∈q.block M:=hxconstructor· by_contra! happly hi falsechange pos x∈Ico _ _rw [h1,h2]exact ⟨Hp.1,h⟩· by_contra! happly hi truechange pos x∈Ico _ _rw [h2,h3]; exact ⟨by linarith,Hp.2⟩lemma circle_near (p : Node) (hp : p.valid) (x y : Grid M) (r : ℝ)(hr : 0 < r) (hx : p.a+r ≤ pos x) (he : pos x ≤ p.a+p.len-r)(hy : Dyadic.diam (x-y)<r) : y∈p.block M := byhave hp' := margins _ hpchange p.a ≤ pos y ∧ pos y < p.a+p.lenby_cases H : x-y=0· have h := sub_eq_zero.mp H; subst y; constructor <;> linarithrw [diam_min,min_lt_iff,pos_neg H] at hyrcases le_total x.val y.val with h|h· have h1 := pos_sub_val hrw [show y-x= -(x-y) by ring,pos_neg H] at h1rcases hy with hy|hy <;> constructor <;> linarith [pos_lt y,pos_lt (x-y),pos_nonneg y]have h1 := pos_sub_val hrcases hy with hy|hy <;> constructor <;> linarith [pos_nonneg y,pos_lt y,pos_nonneg (x-y)]private def inland (p : Node) (r : ℝ) (x : Grid M) := ∀ y, Dyadic.diam (x-y)<r → y∈p.block Mprivate lemma limit_full {f : Grid M → ℝ} (s : ℝ) (h : 2^M ≤ s) : limitR f s := byintro x hxhave H := rad_le_val xhave hh : (x.val:ℝ) < 2^M := by exact_mod_cast ZMod.val_lt xlinarithprivate lemma smoothing_limit (P : Law (Grid M)) (q : Grid M → Prop) (r : ℝ)(h : limitR P r) : limitR (fun x => P.prob fun y => q (x-y)) r := byhave He (x : Grid M) :P.prob (fun y => q (x-y)) = ∑ y, (if q y then P (x-y) else 0) := byrw [prob_eq]apply Fintype.sum_equiv ((Equiv.neg _).trans (Equiv.addLeft x))intro ihave HH : x-i=x+ -i := sub_eq_add_neg x ichange (if q (x-i) then P i else 0) = if q (x+ -i) then P (x-(x+ -i)) else 0; rw [← HH,sub_sub_self]unfold limitR limit; intro i hisimp_rw [He,Complex.ofReal_sum]rw [fc_sum _ (fun y x => (↑(if q y then P (x-y) else 0):ℂ))]apply Finset.sum_eq_zero; intro x hxby_cases H : q x· simp only [H,ite_true]rw [fc_right_translate (fun x => (P x:ℂ)) x i, h _ hi,mul_zero]· simp only [H,ite_false,fc, Complex.ofReal_zero,zero_mul,expU,Finset.sum_const_zero,smul_zero]def band (p : Node) (i j : ℕ) : ℝ := (2:ℝ)^(p.lev+reach i+10)*(2*(j+10))lemma make_mask (p : Node) (h : p.valid) (hp : p.lev < M) (b : Bool) (i j : ℕ) :let q := p.child b∃ f : Grid M → ℝ, limitR f (band p i j) ∧ (∀ x, 0 ≤ f x ∧ f x ≤ 1) ∧(∀ x, x∈p.block M → ¬ (lanes p i M ∧ flanked p i x) →|(if x∈q.block M then (1:ℝ) else 0)-f x| ≤ side j) ∧expU (fun x => if x∈p.block M then 0 else f x) ≤ p.len*side j := byclassicallet s : ℝ := p.len*side (reach i)intro qhave Hq := child_ok p h hp bhave hpq := block_of_below (child_below p b) Mlet D := 2^(p.lev+reach i+10)have hD : 0<D := by unfold D; positivityhave hD' : (0:ℝ) < D := Nat.cast_pos.mpr hDhave hS : 0 < s := mul_pos p.len_pos (side_pos _)have He : band p i j = (D:ℝ)*(2*(j+10)) := by unfold D band; push_cast; rflby_cases H : D ≤ 2^Mcase neg =>let f (x : Grid M) := if x∈q.block M then (1:ℝ) else 0have hj := side_pos jrefine ⟨f,limit_full _ ?_, fun x => by unfold f; split_ifs <;> norm_num,fun x _ _ => by unfold f; simp [hj.le],?_⟩· rw [He]; have hx : (2:ℝ)^M ≤ D := by exact_mod_cast le_of_not_ge Hnlinarith [Nat.cast_nonneg (α:=ℝ) j]have HE (x : Grid M) : (if x∈p.block M then 0 else f x) = 0 := byunfold fsplit_ifs with h hq· rfl· exact (h (hpq hq)).elimrflsimp_rw [HE,expU,Finset.sum_const_zero,smul_zero]; exact (mul_pos p.len_pos hj).leobtain ⟨P,hP,hT⟩ := boosted M D j hD Hlet r : ℝ := 16/Dhave hr : 0<r := div_pos (by norm_num) hD'have hb : lanes p i M := byhave HE : p.lev+reach i+10 ≤ M :=(Nat.pow_le_pow_iff_right (by omega : 1 < 2)).mp Hunfold lanes; omegahave hrS : 2*r ≤ s := byhave he : s * D = 2^10 := byunfold D s len; push_castrw [side_pow_two,side_pow_two,pow_add,pow_add]; field_simpunfold r; rw [← mul_div_assoc]; apply (div_le_iff₀ hD').mpr; rw [he]; norm_numlet g (x : Grid M) := inland q r xlet f (x : Grid M) := P.prob (fun i => g (x-i))have hHi (x : Grid M) (hx : g x) : x∈q.block M := byapply hx xsimpa only [sub_self,diam,rad, neg_zero,ZMod.val_zero,min_self,Nat.cast_zero,mul_zero] using hrrefine ⟨f,smoothing_limit _ _ _ ?_,fun x => ⟨prob_nonneg _ _,prob_le_one _ _⟩,?_,?_⟩· rw [He,show (D:ℝ)*(2*(j+10))=2*(D:ℝ)*(j+10) by ring]exact hP· intro x hx hEhave hv : ¬ flanked p i x := fun hh => hE ⟨hb,hh⟩by_cases HH : x∈q.block M· have hi := inner_strip p b i x HH hvhave hi (v : Grid M) (hv : Dyadic.diam v<r) : g (x-v) := byintro y hyrefine circle_near q Hq.1 x y s hS hi.1 hi.2.le ?_have H := diam_add v (x-v-y)rw [show v+(x-v-y)=x-y by ring] at H; linarithrw [ite_eq_left HH, abs_of_nonneg (sub_nonneg.mpr (prob_le_one _ _))]rw [← prob_compl]refine (prob_mono _ _ _ fun i hv => ?_).trans hTexact le_of_not_gt (fun h => hv (hi i h))rw [ite_eq_right HH,zero_sub,abs_neg,abs_of_nonneg (prob_nonneg _ _)]apply le_trans _ hTrefine prob_mono _ _ _ fun i hi => ?_apply le_of_not_gt; intro hi'apply HHapply hi x; rw [sub_sub_cancel_left,diam_even]; exact hi'rw [expU_ex]let U := uniform (Grid M)let G (x i : Grid M) := if x∈p.block M then (0:ℝ) else if g (x-i) then 1 else 0have heq (x : Grid M) : (if x∈p.block M then 0 else f x) = P.Ex (G x) := byunfold f prob G; split_ifs with hxrw [Ex_const]rflhave hg1 : U.prob g ≤ p.len := byrw [← prob_block (M:=M) (p:=p) ⟨h,hp.le⟩]apply prob_mono _ _ _ (fun i hi => hpq (hHi _ hi))have heq' (i : Grid M) : U.Ex (fun x => G x i) ≤ p.len*(if r ≤ Dyadic.diam i then 1 else 0) := bysplit_ifs with H· rw [mul_one]apply le_trans (b:=U.prob fun x => g (x-i))· unfold prob G; apply Ex_mono; intro x; split_ifs <;> norm_numrw [prob_translate g]; exact hg1have he (x : Grid M) : G x i=0 := byunfold G; split_ifs with h h'· rfl· refine (h (hpq (h' x ?_))).elimrw [sub_sub_cancel_left,diam_even]exact not_le.mp Hrflrw [funext he,Ex_const,mul_zero]simp_rw [heq,Ex_swap (uniform (Grid M)) P]apply le_trans (Ex_mono P heq')rw [Ex_lmul]apply mul_le_mul_of_nonneg_left _ p.len_pos.leapply le_trans _ hTrw [prob_eq]unfold Ex rsimpend FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196import OAI.Analysis.FourierLLogL.Capture.MaskKernelimport OAI.Analysis.FourierLLogL.Finite.Tailopen Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulsevariable {p : Node} {M : ℕ}open scoped Classicallemma margins (p : Node) (hp : p.valid) : 0 ≤ p.a ∧ p.a+p.len ≤ 1 := byunfold ahave he : 0 < p.len := p.len_posrefine ⟨by positivity,?_⟩calc_ = ↑(p.ix+1)*p.len := by push_cast; ring_ ≤ ↑(2^p.lev:ℕ)*p.len :=mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hp) he.le_ = _ := by unfold len; push_cast; rw [mul_comm,side_card]lemma inner_strip (p : Node) (b : Bool) (i : ℕ) (x : Grid M)(hx : x∈(child p b).block M) (hh : ¬ flanked p i x) :let q := child p b; let r := p.len*side (reach i)q.a+r ≤ pos x ∧ pos x < q.a+q.len-r := byintro q rhave hi (c : Bool) : ¬ (x∈(strip p i b c).block M) :=fun h => hh ⟨_,_,h⟩have h1 : (strip p i b false).a=q.a := extreme_left q _have h2 (c : Bool) : (strip p i b c).len=r := strip_length _ _ _ _have h3 : (strip p i b true).a + r=q.a+q.len := byrw [← h2 true]; exact extreme_right _ _have Hp : x∈q.block M:=hxconstructor· by_contra! happly hi falsechange pos x∈Ico _ _rw [h1,h2]exact ⟨Hp.1,h⟩· by_contra! happly hi truechange pos x∈Ico _ _rw [h2,h3]; exact ⟨by linarith,Hp.2⟩lemma circle_near (p : Node) (hp : p.valid) (x y : Grid M) (r : ℝ)(hr : 0 < r) (hx : p.a+r ≤ pos x) (he : pos x ≤ p.a+p.len-r)(hy : Dyadic.diam (x-y)<r) : y∈p.block M := byhave hp' := margins _ hpchange p.a ≤ pos y ∧ pos y < p.a+p.lenby_cases H : x-y=0· have h := sub_eq_zero.mp H; subst y; constructor <;> linarithrw [diam_min,min_lt_iff,pos_neg H] at hyrcases le_total x.val y.val with h|h· have h1 := pos_sub_val hrw [show y-x= -(x-y) by ring,pos_neg H] at h1rcases hy with hy|hy <;> constructor <;> linarith [pos_lt y,pos_lt (x-y),pos_nonneg y]have h1 := pos_sub_val hrcases hy with hy|hy <;> constructor <;> linarith [pos_nonneg y,pos_lt y,pos_nonneg (x-y)]private def inland (p : Node) (r : ℝ) (x : Grid M) := ∀ y, Dyadic.diam (x-y)<r → y∈p.block Mprivate lemma limit_full {f : Grid M → ℝ} (s : ℝ) (h : 2^M ≤ s) : limitR f s := byintro x hxhave H := rad_le_val xhave hh : (x.val:ℝ) < 2^M := by exact_mod_cast ZMod.val_lt xlinarithprivate lemma smoothing_limit (P : Law (Grid M)) (q : Grid M → Prop) (r : ℝ)(h : limitR P r) : limitR (fun x => P.prob fun y => q (x-y)) r := byhave He (x : Grid M) :P.prob (fun y => q (x-y)) = ∑ y, (if q y then P (x-y) else 0) := byrw [prob_eq]apply Fintype.sum_equiv ((Equiv.neg _).trans (Equiv.addLeft x))intro ihave HH : x-i=x+ -i := sub_eq_add_neg x ichange (if q (x-i) then P i else 0) = if q (x+ -i) then P (x-(x+ -i)) else 0; rw [← HH,sub_sub_self]unfold limitR limit; intro i hisimp_rw [He,Complex.ofReal_sum]rw [fc_sum _ (fun y x => (↑(if q y then P (x-y) else 0):ℂ))]apply Finset.sum_eq_zero; intro x hxby_cases H : q x· simp only [H,ite_true]rw [fc_right_translate (fun x => (P x:ℂ)) x i, h _ hi,mul_zero]· simp only [H,ite_false,fc, Complex.ofReal_zero,zero_mul,expU,Finset.sum_const_zero,smul_zero]def band (p : Node) (i j : ℕ) : ℝ := (2:ℝ)^(p.lev+reach i+10)*(2*(j+10))lemma make_mask (p : Node) (h : p.valid) (hp : p.lev < M) (b : Bool) (i j : ℕ) :let q := p.child b∃ f : Grid M → ℝ, limitR f (band p i j) ∧ (∀ x, 0 ≤ f x ∧ f x ≤ 1) ∧(∀ x, x∈p.block M → ¬ (lanes p i M ∧ flanked p i x) →|(if x∈q.block M then (1:ℝ) else 0)-f x| ≤ side j) ∧expU (fun x => if x∈p.block M then 0 else f x) ≤ p.len*side j := byclassicallet s : ℝ := p.len*side (reach i)intro qhave Hq := child_ok p h hp bhave hpq := block_of_below (child_below p b) Mlet D := 2^(p.lev+reach i+10)have hD : 0<D := by unfold D; positivityhave hD' : (0:ℝ) < D := Nat.cast_pos.mpr hDhave hS : 0 < s := mul_pos p.len_pos (side_pos _)have He : band p i j = (D:ℝ)*(2*(j+10)) := by unfold D band; push_cast; rflby_cases H : D ≤ 2^Mcase neg =>let f (x : Grid M) := if x∈q.block M then (1:ℝ) else 0have hj := side_pos jrefine ⟨f,limit_full _ ?_, fun x => by unfold f; split_ifs <;> norm_num,fun x _ _ => by unfold f; simp [hj.le],?_⟩· rw [He]; have hx : (2:ℝ)^M ≤ D := by exact_mod_cast le_of_not_ge Hnlinarith [Nat.cast_nonneg (α:=ℝ) j]have HE (x : Grid M) : (if x∈p.block M then 0 else f x) = 0 := byunfold fsplit_ifs with h hq· rfl· exact (h (hpq hq)).elimrflsimp_rw [HE,expU,Finset.sum_const_zero,smul_zero]; exact (mul_pos p.len_pos hj).leobtain ⟨P,hP,hT⟩ := boosted M D j hD Hlet r : ℝ := 16/Dhave hr : 0<r := div_pos (by norm_num) hD'have hb : lanes p i M := byhave HE : p.lev+reach i+10 ≤ M :=(Nat.pow_le_pow_iff_right (by omega : 1 < 2)).mp Hunfold lanes; omegahave hrS : 2*r ≤ s := byhave he : s * D = 2^10 := byunfold D s len; push_castrw [side_pow_two,side_pow_two,pow_add,pow_add]; field_simpunfold r; rw [← mul_div_assoc]; apply (div_le_iff₀ hD').mpr; rw [he]; norm_numlet g (x : Grid M) := inland q r xlet f (x : Grid M) := P.prob (fun i => g (x-i))have hHi (x : Grid M) (hx : g x) : x∈q.block M := byapply hx xsimpa only [sub_self,diam,rad, neg_zero,ZMod.val_zero,min_self,Nat.cast_zero,mul_zero] using hrrefine ⟨f,smoothing_limit _ _ _ ?_,fun x => ⟨prob_nonneg _ _,prob_le_one _ _⟩,?_,?_⟩· rw [He,show (D:ℝ)*(2*(j+10))=2*(D:ℝ)*(j+10) by ring]exact hP· intro x hx hEhave hv : ¬ flanked p i x := fun hh => hE ⟨hb,hh⟩by_cases HH : x∈q.block M· have hi := inner_strip p b i x HH hvhave hi (v : Grid M) (hv : Dyadic.diam v<r) : g (x-v) := byintro y hyrefine circle_near q Hq.1 x y s hS hi.1 hi.2.le ?_have H := diam_add v (x-v-y)rw [show v+(x-v-y)=x-y by ring] at H; linarithrw [ite_eq_left HH, abs_of_nonneg (sub_nonneg.mpr (prob_le_one _ _))]rw [← prob_compl]refine (prob_mono _ _ _ fun i hv => ?_).trans hTexact le_of_not_gt (fun h => hv (hi i h))rw [ite_eq_right HH,zero_sub,abs_neg,abs_of_nonneg (prob_nonneg _ _)]apply le_trans _ hTrefine prob_mono _ _ _ fun i hi => ?_apply le_of_not_gt; intro hi'apply HHapply hi x; rw [sub_sub_cancel_left,diam_even]; exact hi'rw [expU_ex]let U := uniform (Grid M)let G (x i : Grid M) := if x∈p.block M then (0:ℝ) else if g (x-i) then 1 else 0have heq (x : Grid M) : (if x∈p.block M then 0 else f x) = P.Ex (G x) := byunfold f prob G; split_ifs with hxrw [Ex_const]rflhave hg1 : U.prob g ≤ p.len := byrw [← prob_block (M:=M) (p:=p) ⟨h,hp.le⟩]apply prob_mono _ _ _ (fun i hi => hpq (hHi _ hi))have heq' (i : Grid M) : U.Ex (fun x => G x i) ≤ p.len*(if r ≤ Dyadic.diam i then 1 else 0) := bysplit_ifs with H· rw [mul_one]apply le_trans (b:=U.prob fun x => g (x-i))· unfold prob G; apply Ex_mono; intro x; split_ifs <;> norm_numrw [prob_translate g]; exact hg1have he (x : Grid M) : G x i=0 := byunfold G; split_ifs with h h'· rfl· refine (h (hpq (h' x ?_))).elimrw [sub_sub_cancel_left,diam_even]exact not_le.mp Hrflrw [funext he,Ex_const,mul_zero]simp_rw [heq,Ex_swap (uniform (Grid M)) P]apply le_trans (Ex_mono P heq')rw [Ex_lmul]apply mul_le_mul_of_nonneg_left _ p.len_pos.leapply le_trans _ hTrw [prob_eq]unfold Ex rsimpend FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243import OAI.Analysis.FourierLLogL.Plateau.Thread/-! # Band-limited cutoffs -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulsevariable {M : ℕ}open scoped Classicaldef limit (f : Grid M → ℂ) (r : ℝ) := ∀ x, r < rad x → fc f x=0def limitR (f : Grid M → ℝ) := limit (fun x => (f x:ℂ))lemma limit_mul (f g : Grid M → ℂ) (p q : ℝ) (hf : limit f p) (hg : limit g q) :limit (fun x => f x*g x) (p+q) := byintro x hx; rw [fc_prod]; apply Finset.sum_eq_zero; intro i _by_cases hh : p < rad i· rw [hf i hh,zero_mul]have H : q < rad (x-i) := byhave Hh := rad_add (x-i) i; rw [sub_add_cancel] at Hhlinarithrw [hg _ H,mul_zero]lemma limit_scale (f : Grid M → ℂ) (c : ℂ) (p : ℝ) (hf : limit f p) :limit (fun x => c*f x) p := by intro x hx; rw [fc_lmul,hf x hx,mul_zero]lemma limit_const (p : ℝ) (hp : 0 ≤ p) : limit (M:=M) (fun _ => 1) p := byintro x hx; rw [← funext chi_zero_left,fc_chi,ite_eq_right]intro h; subst x; simp [rad] at hx; linarithlemma limit_pow (f : Grid M → ℂ) (p : ℝ) (hf : limit f p) (k : ℕ) :limit (fun x => f x^k) (k*p) := byinduction k with| zero => simpa only [Nat.cast_zero,zero_mul,pow_zero] using limit_const (M:=M) 0 le_rfl| succ k ih =>simp_rw [pow_succ,Nat.cast_add_one,add_mul,one_mul]exact limit_mul _ _ _ p ih hflemma limit_star (f : Grid M → ℂ) (p : ℝ) (hf : limit f p) :limit (fun x => conj (f x)) p := byintro x hxhave hh : fc (fun x => conj (f x)) x = conj (fc f (-x)) := byunfold fcsimp_rw [expU_cx,← Cx_conj,chi_neg', map_mul]simprw [hh,hf _ (by rw [rad_even]; exact hx),map_zero]/-- Dirichlet factor normalized to one. -/private def tile (M d : ℕ) (x : Grid M) := (d:ℂ)⁻¹ * ∑ i∈Finset.range d, chi (i:Grid M) xdef slab (M d : ℕ) (x : Grid M) := ‖tile M d x‖^2private lemma tile_limit (M d : ℕ) : limit (tile M d) d := byintro x hxunfold tile; rw [fc_lmul,fc_sum _ (fun i : ℕ => chi (i:Grid M))]suffices H : ∀ i ∈ Finset.range d, fc (chi (i:Grid M)) x=0 by simp [Finset.sum_eq_zero H]intro i hi; rw [fc_chi,ite_eq_right]intro h; subst xhave H := rad_le_nat (M:=M) ihave hi : (i:ℝ) < d := Nat.cast_lt.mpr (Finset.mem_range.mp hi)linarithlemma slab_limit (M d : ℕ) : limitR (slab M d) (2*d) := byhave hi (x : Grid M) : (↑(slab M d x):ℂ) =tile M d x * conj (tile M d x) := by rw [slab,Complex.mul_conj,Complex.sq_norm]have h := tile_limit M dunfold limitR; simp_rw [hi, two_mul]exact limit_mul _ _ _ _ h (limit_star _ _ h)lemma slab_nonneg (M d : ℕ) (x : Grid M) : 0 ≤ slab M d x := by unfold slab; positivitylemma slab_total (M : ℕ) (d : ℕ) (h : 0 < d) (he : d ≤ 2^M) :expU (slab M d) = (d:ℝ)⁻¹ := bychange expU (fun x => ‖tile M d x‖^2) = _rw [← fc_parseval]have H (x : Grid M) : fc (tile M d) x = if x∈Dyadic.first M d then (d:ℂ)⁻¹ else 0 := byunfold tile; rw [fc_lmul,fc_sum _ (fun i : ℕ => chi (i:Grid M))]simp_rw [fc_chi]by_cases hx : x∈Dyadic.first M d· rw [ite_eq_left hx]rw [Finset.sum_eq_single x.val, ite_eq_left (ZMod.natCast_zmod_val _),mul_one]· intro j hj he'; rw [ite_eq_right]intro Hhave hi := ZMod.val_natCast_of_lt ((Finset.mem_range.mp hj).trans_le he)rw [H] at hi; exact he' hi.symm· exact fun HH => (HH (Finset.mem_range.mpr ((mem_first _ _).mp hx))).elimrw [first_eq_range d he] at hxrw [first_eq_range d he,ite_eq_right hx,Finset.sum_eq_zero,mul_zero]intro i hi; rw [ite_eq_right]; intro H; exact hx (Finset.mem_image.mpr ⟨_,hi,H⟩)simp_rw [H]calc_ = ∑ _x ∈ Dyadic.first M d, ((d:ℝ)⁻¹)^2 := byclassicalhave hi (x : Grid M) :‖(if x∈Dyadic.first M d then (d:ℂ)⁻¹ else 0)‖^2 =if x∈Dyadic.first M d then ((d:ℝ)⁻¹)^2 else 0 := by split_ifs <;> simpsimp_rw [hi]; rw [← Finset.sum_filter]simp_ = _ := by simp [first_card d he]; field_simpprivate lemma tile_lower (M d : ℕ) (h : 0 < d) (x : Grid M)(hx : Dyadic.diam x ≤ (1/16:ℝ)/d) :1/2 ≤ ‖tile M d x‖ := byhave hp : 0 < (d:ℝ) := by positivityhave hh := norm_phase_sq 1 xhave ha : ‖1-chi 1 x‖ ≤ 8*Dyadic.diam x := by nlinarith [(cost_diam x).2,diam_nonneg x]have HF (i : ℕ) : ‖1-chi (i:Grid M) x‖ ≤ i*‖1-chi 1 x‖ := byinduction i with| zero => simp [chi_zero_left]| succ i ih =>push_casthave Hx := norm_phase_add x (i:Grid M) 1rw [chi_comm x _,chi_comm x _,chi_comm x _] at Hxlinarithhave hE (i : ℕ) (hi : i < d) : ‖1-chi (i:Grid M) x‖ ≤ 1/2 := calc_ ≤ _ := HF i_ ≤ d*(8*Dyadic.diam x) := mul_le_mul (Nat.cast_le.mpr hi.le) ha (norm_nonneg _) hp.le_ ≤ _ := by have := (le_div_iff₀ hp).mp hx; linarithhave hr (i : ℕ) (hi : i < d) : 1/2 ≤ (chi (i:Grid M) x).re := byhave H := Complex.abs_re_le_norm (1-chi (i:Grid M) x); simp only [Complex.sub_re,Complex.one_re] at Hlinarith [(abs_le.mp (H.trans (hE i hi))).2]apply le_trans (b:=(tile M d x).re)· unfold tile; rw [show (d:ℂ)⁻¹=(↑((d:ℝ)⁻¹):ℂ) by push_cast; rfl,Complex.re_ofReal_mul,Complex.re_sum,← div_eq_inv_mul]apply (le_div_iff₀ hp).mprhave HH := Finset.sum_le_sum (s:=Finset.range d) fun i hi => hr i (Finset.mem_range.mp hi)simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at HH; linarithexact (le_abs_self _).trans (Complex.abs_re_le_norm _)private lemma tile_upper (M d : ℕ) (h : 0 < d) (x : Grid M) :(4*d:ℝ)*Dyadic.diam x * ‖tile M d x‖ ≤ 2 := bylet z := chi (1:Grid M) xhave he (i : ℕ) : z ^ i = chi (i:Grid M) x := by unfold z; rw [← chi_nsmul,nsmul_one]have H : ‖1-z‖ * (d:ℝ)* ‖tile M d x‖ ≤ 2 := bylet W := ∑ i∈Finset.range d,z^ihave HH := geom_sum_mul_neg z dhave HB : ‖W*(1-z)‖ ≤ 2 := byrw [show W*(1-z)=_ from HH]apply (norm_sub_le _ _).trans; rw [norm_pow,norm_one,show ‖z‖=1 from norm_chi _ _]; simpnorm_numrw [norm_mul] at HBhave Hp : 0 < (d:ℝ) := by positivityhave hz : ‖tile M d x‖ = (d:ℝ)⁻¹*‖W‖ := byunfold tile W; simp_rw [he, norm_mul,norm_inv]; simprw [hz]apply le_trans _ HB; exact le_of_eq (by field_simp)have he₁ := (cost_diam x).1have He : 4*Dyadic.diam x ≤ ‖1-z‖ := by unfold z; nlinarith [norm_phase_sq 1 x,norm_nonneg (1-chi 1 x)]apply le_trans _ Hhave hp : 0 ≤ (d:ℝ) := by positivityrw [mul_right_comm (4:ℝ)]; gcongropen Nodelemma boosted (M d k : ℕ) (h : 0 < d) (he : d ≤ 2^M) :∃ P : Law (Grid M), limitR P (2*(d:ℝ)*(k+10)) ∧P.prob (fun x => 16/d ≤ Dyadic.diam x) ≤ side k := bylet n := k+10let f (x : Grid M) := slab M d x^nlet a := ∑ x, f xhave hh : (0:ℝ)<d := Nat.cast_pos.mpr hlet b := side Mhave hb : 0 < b := side_pos Mhave hf (x) : 0 ≤ f x := pow_nonneg (slab_nonneg _ _ _) _let r := ((1/16:ℝ)/d)/bhave hr : 0 ≤ r := by unfold r; positivityhave heR : r ≤ 2^M := byunfold r; apply (div_le_iff₀ hb).mprrw [show (2:ℝ)^M*b=1 by unfold b; rw [mul_comm,side_card]]have H : 1 ≤ (d:ℝ) := by exact_mod_cast happly (div_le_one hh).mpr; linarithlet D := arc M rhave Hlow (x) (hx : x∈D) : (1/4:ℝ)^n ≤ f x := byapply pow_le_pow_left₀ (by norm_num : 0 ≤ (1/4:ℝ))have HI : Dyadic.diam x ≤ (1/16:ℝ)/d := byhave HI := (mem_arc r _).mp hxrw [diam,mul_comm]exact (le_div_iff₀ hb).mp HIunfold slabhave HE := tile_lower M d h x HI; nlinarithhave HD : r ≤ (D.card:ℝ) := arc_card_lo M r hr heRhave HG : r*(1/4:ℝ)^n ≤ a := calc_ ≤ D.card*(1/4:ℝ)^n := by gcongr_ = ∑ _i∈D,(1/4:ℝ)^n := by simp_ ≤ ∑ i∈D,f i := Finset.sum_le_sum Hlow_ ≤ ∑ i,f i := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun i _ _ => hf i)have ha : 0 < a := lt_of_lt_of_le (by unfold r; positivity) HGlet P := proportional f hf harefine ⟨P,?_,?_⟩· have He : limitR f (n*(2*d):ℝ) := byunfold limitR f; simp_rw [Complex.ofReal_pow]; exact limit_pow _ _ (slab_limit M d) _unfold limitRhave HE (x : Grid M) : P x = a⁻¹ * f x := by unfold P; rw [proportional_apply,div_eq_inv_mul]simp_rw [HE,Complex.ofReal_mul]rw [show 2*(d:ℝ)*(k+10) = n*(2*d) by unfold n; push_cast; ring]exact limit_scale _ _ _ He· let t (x : Grid M) := (16/d:ℝ) ≤ Dyadic.diam xhave Ht (x : Grid M) (hx : t x) : slab M d x ≤ 1/16 := byunfold slabhave Hx := tile_upper M d h xhave HH := (div_le_iff₀ hh).mp hxgeneralize HE : ‖tile M d x‖ = w at *have hw : 0 ≤ w := HE ▸ norm_nonneg _nlinarith [mul_le_mul_of_nonneg_right HH hw]let A := (1/16:ℝ)^(k+9)have HI :∑ x, (if t x then f x else 0) ≤ A*(∑ x : Grid M, slab M d x) := byrw [Finset.mul_sum]apply Finset.sum_le_sum; intro i hihave hip := slab_nonneg M d isplit_ifs with H· apply le_trans (b:=slab M d i^(k+9)*slab M d i)· unfold f n; rw [show k+10=k+9+1 from rfl,pow_succ]unfold A; gcongr; exact Ht i Hunfold A; positivityhave HT (x : Grid M) : P x=f x/a := proportional_apply f hf ha _rw [prob_eq]; simp_rw [HT]have HH (i : Grid M) : (if t i then f i/a else 0) = (if t i then f i else 0)/a := bysplit_ifs <;> simpchange (∑ i, if t i then f i / a else 0) ≤ side ksimp_rw [HH, ← Finset.sum_div]apply (div_le_iff₀ ha).mprhave H := slab_total M d h hechange b* (∑ x : Grid M, slab M d x) = _ at Hcalc_ ≤ _ := HI_ ≤ side k * (r*(1/4:ℝ)^n) := byapply le_of_mul_le_mul_left ?_ hbrw [mul_left_comm b, H]unfold r nhave he : b*(side k*(1/16/d/b*(1/4:ℝ)^(k+10))) =(d:ℝ)⁻¹*((1/16)*(side k*(1/4:ℝ)^(k+10))) := by field_simprw [he]unfold Aapply le_trans (le_of_eq (mul_comm _ _)) (mul_le_mul_of_nonneg_left ?_ (by positivity))unfold siderw [pow_add, pow_add]have hh : (1/16:ℝ)^k ≤ (1/2:ℝ)^k*(1/4:ℝ)^k := by rw [← mul_pow]; norm_num; gcongr; norm_numnorm_num at *; nlinarith [show 0 ≤ (1/16:ℝ)^k by positivity]_ ≤ _ := mul_le_mul_of_nonneg_left HG (side_pos _).leend FourierLLogL.Dyadic.Procedure.Captureend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243import OAI.Analysis.FourierLLogL.Plateau.Thread/-! # Band-limited cutoffs -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Captureopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Wire Pulsevariable {M : ℕ}open scoped Classicaldef limit (f : Grid M → ℂ) (r : ℝ) := ∀ x, r < rad x → fc f x=0def limitR (f : Grid M → ℝ) := limit (fun x => (f x:ℂ))lemma limit_mul (f g : Grid M → ℂ) (p q : ℝ) (hf : limit f p) (hg : limit g q) :limit (fun x => f x*g x) (p+q) := byintro x hx; rw [fc_prod]; apply Finset.sum_eq_zero; intro i _by_cases hh : p < rad i· rw [hf i hh,zero_mul]have H : q < rad (x-i) := byhave Hh := rad_add (x-i) i; rw [sub_add_cancel] at Hhlinarithrw [hg _ H,mul_zero]lemma limit_scale (f : Grid M → ℂ) (c : ℂ) (p : ℝ) (hf : limit f p) :limit (fun x => c*f x) p := by intro x hx; rw [fc_lmul,hf x hx,mul_zero]lemma limit_const (p : ℝ) (hp : 0 ≤ p) : limit (M:=M) (fun _ => 1) p := byintro x hx; rw [← funext chi_zero_left,fc_chi,ite_eq_right]intro h; subst x; simp [rad] at hx; linarithlemma limit_pow (f : Grid M → ℂ) (p : ℝ) (hf : limit f p) (k : ℕ) :limit (fun x => f x^k) (k*p) := byinduction k with| zero => simpa only [Nat.cast_zero,zero_mul,pow_zero] using limit_const (M:=M) 0 le_rfl| succ k ih =>simp_rw [pow_succ,Nat.cast_add_one,add_mul,one_mul]exact limit_mul _ _ _ p ih hflemma limit_star (f : Grid M → ℂ) (p : ℝ) (hf : limit f p) :limit (fun x => conj (f x)) p := byintro x hxhave hh : fc (fun x => conj (f x)) x = conj (fc f (-x)) := byunfold fcsimp_rw [expU_cx,← Cx_conj,chi_neg', map_mul]simprw [hh,hf _ (by rw [rad_even]; exact hx),map_zero]/-- Dirichlet factor normalized to one. -/private def tile (M d : ℕ) (x : Grid M) := (d:ℂ)⁻¹ * ∑ i∈Finset.range d, chi (i:Grid M) xdef slab (M d : ℕ) (x : Grid M) := ‖tile M d x‖^2private lemma tile_limit (M d : ℕ) : limit (tile M d) d := byintro x hxunfold tile; rw [fc_lmul,fc_sum _ (fun i : ℕ => chi (i:Grid M))]suffices H : ∀ i ∈ Finset.range d, fc (chi (i:Grid M)) x=0 by simp [Finset.sum_eq_zero H]intro i hi; rw [fc_chi,ite_eq_right]intro h; subst xhave H := rad_le_nat (M:=M) ihave hi : (i:ℝ) < d := Nat.cast_lt.mpr (Finset.mem_range.mp hi)linarithlemma slab_limit (M d : ℕ) : limitR (slab M d) (2*d) := byhave hi (x : Grid M) : (↑(slab M d x):ℂ) =tile M d x * conj (tile M d x) := by rw [slab,Complex.mul_conj,Complex.sq_norm]have h := tile_limit M dunfold limitR; simp_rw [hi, two_mul]exact limit_mul _ _ _ _ h (limit_star _ _ h)lemma slab_nonneg (M d : ℕ) (x : Grid M) : 0 ≤ slab M d x := by unfold slab; positivitylemma slab_total (M : ℕ) (d : ℕ) (h : 0 < d) (he : d ≤ 2^M) :expU (slab M d) = (d:ℝ)⁻¹ := bychange expU (fun x => ‖tile M d x‖^2) = _rw [← fc_parseval]have H (x : Grid M) : fc (tile M d) x = if x∈Dyadic.first M d then (d:ℂ)⁻¹ else 0 := byunfold tile; rw [fc_lmul,fc_sum _ (fun i : ℕ => chi (i:Grid M))]simp_rw [fc_chi]by_cases hx : x∈Dyadic.first M d· rw [ite_eq_left hx]rw [Finset.sum_eq_single x.val, ite_eq_left (ZMod.natCast_zmod_val _),mul_one]· intro j hj he'; rw [ite_eq_right]intro Hhave hi := ZMod.val_natCast_of_lt ((Finset.mem_range.mp hj).trans_le he)rw [H] at hi; exact he' hi.symm· exact fun HH => (HH (Finset.mem_range.mpr ((mem_first _ _).mp hx))).elimrw [first_eq_range d he] at hxrw [first_eq_range d he,ite_eq_right hx,Finset.sum_eq_zero,mul_zero]intro i hi; rw [ite_eq_right]; intro H; exact hx (Finset.mem_image.mpr ⟨_,hi,H⟩)simp_rw [H]calc_ = ∑ _x ∈ Dyadic.first M d, ((d:ℝ)⁻¹)^2 := byclassicalhave hi (x : Grid M) :‖(if x∈Dyadic.first M d then (d:ℂ)⁻¹ else 0)‖^2 =if x∈Dyadic.first M d then ((d:ℝ)⁻¹)^2 else 0 := by split_ifs <;> simpsimp_rw [hi]; rw [← Finset.sum_filter]simp_ = _ := by simp [first_card d he]; field_simpprivate lemma tile_lower (M d : ℕ) (h : 0 < d) (x : Grid M)(hx : Dyadic.diam x ≤ (1/16:ℝ)/d) :1/2 ≤ ‖tile M d x‖ := byhave hp : 0 < (d:ℝ) := by positivityhave hh := norm_phase_sq 1 xhave ha : ‖1-chi 1 x‖ ≤ 8*Dyadic.diam x := by nlinarith [(cost_diam x).2,diam_nonneg x]have HF (i : ℕ) : ‖1-chi (i:Grid M) x‖ ≤ i*‖1-chi 1 x‖ := byinduction i with| zero => simp [chi_zero_left]| succ i ih =>push_casthave Hx := norm_phase_add x (i:Grid M) 1rw [chi_comm x _,chi_comm x _,chi_comm x _] at Hxlinarithhave hE (i : ℕ) (hi : i < d) : ‖1-chi (i:Grid M) x‖ ≤ 1/2 := calc_ ≤ _ := HF i_ ≤ d*(8*Dyadic.diam x) := mul_le_mul (Nat.cast_le.mpr hi.le) ha (norm_nonneg _) hp.le_ ≤ _ := by have := (le_div_iff₀ hp).mp hx; linarithhave hr (i : ℕ) (hi : i < d) : 1/2 ≤ (chi (i:Grid M) x).re := byhave H := Complex.abs_re_le_norm (1-chi (i:Grid M) x); simp only [Complex.sub_re,Complex.one_re] at Hlinarith [(abs_le.mp (H.trans (hE i hi))).2]apply le_trans (b:=(tile M d x).re)· unfold tile; rw [show (d:ℂ)⁻¹=(↑((d:ℝ)⁻¹):ℂ) by push_cast; rfl,Complex.re_ofReal_mul,Complex.re_sum,← div_eq_inv_mul]apply (le_div_iff₀ hp).mprhave HH := Finset.sum_le_sum (s:=Finset.range d) fun i hi => hr i (Finset.mem_range.mp hi)simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at HH; linarithexact (le_abs_self _).trans (Complex.abs_re_le_norm _)private lemma tile_upper (M d : ℕ) (h : 0 < d) (x : Grid M) :(4*d:ℝ)*Dyadic.diam x * ‖tile M d x‖ ≤ 2 := bylet z := chi (1:Grid M) xhave he (i : ℕ) : z ^ i = chi (i:Grid M) x := by unfold z; rw [← chi_nsmul,nsmul_one]have H : ‖1-z‖ * (d:ℝ)* ‖tile M d x‖ ≤ 2 := bylet W := ∑ i∈Finset.range d,z^ihave HH := geom_sum_mul_neg z dhave HB : ‖W*(1-z)‖ ≤ 2 := byrw [show W*(1-z)=_ from HH]apply (norm_sub_le _ _).trans; rw [norm_pow,norm_one,show ‖z‖=1 from norm_chi _ _]; simpnorm_numrw [norm_mul] at HBhave Hp : 0 < (d:ℝ) := by positivityhave hz : ‖tile M d x‖ = (d:ℝ)⁻¹*‖W‖ := byunfold tile W; simp_rw [he, norm_mul,norm_inv]; simprw [hz]apply le_trans _ HB; exact le_of_eq (by field_simp)have he₁ := (cost_diam x).1have He : 4*Dyadic.diam x ≤ ‖1-z‖ := by unfold z; nlinarith [norm_phase_sq 1 x,norm_nonneg (1-chi 1 x)]apply le_trans _ Hhave hp : 0 ≤ (d:ℝ) := by positivityrw [mul_right_comm (4:ℝ)]; gcongropen Nodelemma boosted (M d k : ℕ) (h : 0 < d) (he : d ≤ 2^M) :∃ P : Law (Grid M), limitR P (2*(d:ℝ)*(k+10)) ∧P.prob (fun x => 16/d ≤ Dyadic.diam x) ≤ side k := bylet n := k+10let f (x : Grid M) := slab M d x^nlet a := ∑ x, f xhave hh : (0:ℝ)<d := Nat.cast_pos.mpr hlet b := side Mhave hb : 0 < b := side_pos Mhave hf (x) : 0 ≤ f x := pow_nonneg (slab_nonneg _ _ _) _let r := ((1/16:ℝ)/d)/bhave hr : 0 ≤ r := by unfold r; positivityhave heR : r ≤ 2^M := byunfold r; apply (div_le_iff₀ hb).mprrw [show (2:ℝ)^M*b=1 by unfold b; rw [mul_comm,side_card]]have H : 1 ≤ (d:ℝ) := by exact_mod_cast happly (div_le_one hh).mpr; linarithlet D := arc M rhave Hlow (x) (hx : x∈D) : (1/4:ℝ)^n ≤ f x := byapply pow_le_pow_left₀ (by norm_num : 0 ≤ (1/4:ℝ))have HI : Dyadic.diam x ≤ (1/16:ℝ)/d := byhave HI := (mem_arc r _).mp hxrw [diam,mul_comm]exact (le_div_iff₀ hb).mp HIunfold slabhave HE := tile_lower M d h x HI; nlinarithhave HD : r ≤ (D.card:ℝ) := arc_card_lo M r hr heRhave HG : r*(1/4:ℝ)^n ≤ a := calc_ ≤ D.card*(1/4:ℝ)^n := by gcongr_ = ∑ _i∈D,(1/4:ℝ)^n := by simp_ ≤ ∑ i∈D,f i := Finset.sum_le_sum Hlow_ ≤ ∑ i,f i := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun i _ _ => hf i)have ha : 0 < a := lt_of_lt_of_le (by unfold r; positivity) HGlet P := proportional f hf harefine ⟨P,?_,?_⟩· have He : limitR f (n*(2*d):ℝ) := byunfold limitR f; simp_rw [Complex.ofReal_pow]; exact limit_pow _ _ (slab_limit M d) _unfold limitRhave HE (x : Grid M) : P x = a⁻¹ * f x := by unfold P; rw [proportional_apply,div_eq_inv_mul]simp_rw [HE,Complex.ofReal_mul]rw [show 2*(d:ℝ)*(k+10) = n*(2*d) by unfold n; push_cast; ring]exact limit_scale _ _ _ He· let t (x : Grid M) := (16/d:ℝ) ≤ Dyadic.diam xhave Ht (x : Grid M) (hx : t x) : slab M d x ≤ 1/16 := byunfold slabhave Hx := tile_upper M d h xhave HH := (div_le_iff₀ hh).mp hxgeneralize HE : ‖tile M d x‖ = w at *have hw : 0 ≤ w := HE ▸ norm_nonneg _nlinarith [mul_le_mul_of_nonneg_right HH hw]let A := (1/16:ℝ)^(k+9)have HI :∑ x, (if t x then f x else 0) ≤ A*(∑ x : Grid M, slab M d x) := byrw [Finset.mul_sum]apply Finset.sum_le_sum; intro i hihave hip := slab_nonneg M d isplit_ifs with H· apply le_trans (b:=slab M d i^(k+9)*slab M d i)· unfold f n; rw [show k+10=k+9+1 from rfl,pow_succ]unfold A; gcongr; exact Ht i Hunfold A; positivityhave HT (x : Grid M) : P x=f x/a := proportional_apply f hf ha _rw [prob_eq]; simp_rw [HT]have HH (i : Grid M) : (if t i then f i/a else 0) = (if t i then f i else 0)/a := bysplit_ifs <;> simpchange (∑ i, if t i then f i / a else 0) ≤ side ksimp_rw [HH, ← Finset.sum_div]apply (div_le_iff₀ ha).mprhave H := slab_total M d h hechange b* (∑ x : Grid M, slab M d x) = _ at Hcalc_ ≤ _ := HI_ ≤ side k * (r*(1/4:ℝ)^n) := byapply le_of_mul_le_mul_left ?_ hbrw [mul_left_comm b, H]unfold r nhave he : b*(side k*(1/16/d/b*(1/4:ℝ)^(k+10))) =(d:ℝ)⁻¹*((1/16)*(side k*(1/4:ℝ)^(k+10))) := by field_simprw [he]unfold Aapply le_trans (le_of_eq (mul_comm _ _)) (mul_le_mul_of_nonneg_left ?_ (by positivity))unfold siderw [pow_add, pow_add]have hh : (1/16:ℝ)^k ≤ (1/2:ℝ)^k*(1/4:ℝ)^k := by rw [← mul_pow]; norm_num; gcongr; norm_numnorm_num at *; nlinarith [show 0 ≤ (1/16:ℝ)^k by positivity]_ ≤ _ := mul_le_mul_of_nonneg_left HG (side_pos _).leend FourierLLogL.Dyadic.Procedure.Captureend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165import OAI.Analysis.FourierLLogL.Compress.Variational/-! # Indexed blocks of letters -/open Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realabbrev Letters (n : ℕ) (α : Type) := Fin n → αabbrev WordSample (n : ℕ) (α G : Type) := Sample (Fin n) α Gvariable {ι τ κ n m k : ℕ} {α Ω G : Type}def offset (j l : ℕ) (h : j+l ≤ n) (i : Fin l) : Fin n := ⟨j+i, by have := i.isLt; omega⟩def readBlock (X : Ω → Letters n α) (j l : ℕ) (h : j+l ≤ n) :=keep X (offset j l h)def prefixB (X : Ω → Letters n α) (l : ℕ) (h : l ≤ n) := readBlock X 0 l (by omega)def readLetter (X : Ω → Letters n α) (j : ℕ) (h : j<n) := fun x => X x ⟨j,h⟩lemma offset_injective (j l : ℕ) (h : j+l ≤ n) : Injective (offset j l h) := byintro a b habhave H := congrArg Fin.val habsimp only [offset,Nat.add_left_cancel_iff] at Hexact Fin.ext Hlemma prefix_partition (X : Ω → Letters n α) (l k : ℕ) (h : l+k ≤ n) (x y : Ω) :prefixB X (l+k) h x = prefixB X (l+k) h y ↔prefixB X l (by omega) x = prefixB X l (by omega) y ∧ readBlock X l k h x = readBlock X l k h y := bysimp only [funext_iff]constructor· intro H; constructor· intro iexact H (i.castAdd k)· intro ⟨i,hi⟩have h1 := H (⟨l+i,by omega⟩:Fin (l+k))simpa only [prefixB,readBlock,keep,offset,zero_add] using h1· rintro ⟨H,G⟩ ⟨i,hi⟩by_cases hp : i < l· exact H ⟨i,hp⟩· have h1 := G (⟨i-l,by omega⟩:Fin k)simpa only [prefixB,readBlock,keep,offset,zero_add, Nat.add_sub_of_le (le_of_not_gt hp)]using h1lemma prefix_last_partition (X : Ω → Letters n α) (l : ℕ) (h : l<n) (x y : Ω) :prefixB X (l+1) h x = prefixB X (l+1) h y ↔readLetter X l h x = readLetter X l h y ∧prefixB X l (by omega) x = prefixB X l (by omega) y := byrw [prefix_partition X l 1 h]have HH : readBlock X l 1 h x = readBlock X l 1 h y ↔ readLetter X l h x = readLetter X l h y :=⟨fun e => congrFun e (0:Fin 1),fun e => by funext i; rw [Subsingleton.elim i 0]; exact e⟩rw [HH,and_comm]lemma prefix_zero (X : Ω → Letters n α) : prefixB X 0 (by omega) = fun _ => Fin.elim0 :=funext fun _ => Subsingleton.elim _ _lemma prefix_all (X : Ω → Letters n α) : prefixB X n le_rfl = X := byfunext a ⟨i,hi⟩simp only [prefixB,readBlock,keep,offset,zero_add]lemma block_cut (X : Ω → Letters n α) (j m l : ℕ) (h : j+m ≤ n) (hl : l ≤ m) :readBlock X j l (by omega) = prefixB (readBlock X j m h) l hl := byfunext a ⟨i,hi⟩; simp only [prefixB,readBlock,keep,offset,zero_add]lemma block_in_prefix (X : Ω → Letters n α) (j k l : ℕ) (hk : j+k ≤ l) (hl : l ≤ n) :readBlock X j k (hk.trans hl) = readBlock (prefixB X l hl) j k hk := byfunext a ⟨i,hi⟩; simp only [prefixB,readBlock,keep,offset,zero_add]def splitIx {n : ℕ} (l m : ℕ) (h : l+m=n) : (Fin m ⊕ Fin l) ≃ Fin n :=((Equiv.sumComm _ _).trans finSumFinEquiv).trans (finCongr h)lemma splitIx_left (l m : ℕ) (h : l+m=n) (i : Fin m) :splitIx l m h (.inl i) = offset l m h.le i := byapply Fin.extsimp only [splitIx,Equiv.trans_apply,finCongr_apply_coe]rfllemma splitIx_right (l m : ℕ) (h : l+m=n) (i : Fin l) :splitIx l m h (.inr i) = offset 0 l (by omega : 0+l≤n) i := byapply Fin.extsimp only [splitIx,Equiv.trans_apply,finCongr_apply_coe,offset,zero_add]rflsection reindexvariable {I J K : Type} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J][Fintype K] [DecidableEq K]omit [Fintype I] [Fintype J] [DecidableEq J] [DecidableEq I] inlemma lift_perm (g : J → I) (hg : Injective g) (e : Equiv.Perm J) :∃ f : Equiv.Perm I, (∀ i, f (g i) = g (e i)) ∧ ∀ x, x ∉ range g → f x = x := byclassicallet T := (Equiv.sumCongr (Equiv.ofInjective g hg) (Equiv.refl {x : I // x ∉ range g}))|>.trans (Equiv.sumCompl (fun x => x ∈ range g))let E := Equiv.sumCongr e (Equiv.refl {x : I // x ∉ range g})have H (x) : ((T.symm.trans E).trans T) (T x) = T (E x) := by simprefine ⟨(T.symm.trans E).trans T,fun i => H (.inl i),fun x hx => ?_⟩exact H (.inr ⟨x,hx⟩)variable [Fintype α] [Fintype G]def subSample (g : J → I) (p : Sample I α G) : Sample J α G :=((fun j => p.1 (g j)), p.2)lemma exch_subSample {P : Law (Sample I α G)} (hx : exch P)(g : J → I) (hg : Injective g) : exch (P.send (subSample g)) := byintro eobtain ⟨f,hf,hf'⟩ := lift_perm g hg erw [send_send]have HH := congrArg (fun R : Law (Sample I α G) => R.send (subSample g)) (hx f)rw [send_send] at HHsimpa [subSample,appPerm,hf] using HHlemma exch_subSample_cond {P : Law (Sample I α G)} (hx : exch P)(g : J → I) (hg : Injective g) (u : K → I) (hu : ∀ i, u i ∉ range g)(w : K → α) :let W := keep (fun p : Sample I α G => p.1) uexch ((P.after W w).send (subSample g)) := byintro W eobtain ⟨f,hf,hf'⟩ := lift_perm g hg ehave HH := congrArg (fun R : Law (Sample I α G) => R.send fun x => (subSample g x,W x)) (hx f)rw [send_send] at HHhave h1 (x : Sample I α G) : subSample g (appPerm f x) = appPerm e (subSample g x) := bysimp only [appPerm,subSample,hf]have h2 (x : Sample I α G) : W (appPerm f x) = W x := byfunext isimp only [W,keep,appPerm,hf' _ (hu i)]simp_rw [h1,h2] at HHrw [send_send]exact after_send_eq_of_send_pair_eq (X:=fun x => appPerm e (subSample g x)) (W:=W)(Y:=subSample g) (V:=W) HH wend reindexsection billsplitvariable [Fintype α] [Fintype Ω] [Fintype G] [AddCommGroup G]lemma prefix_bill (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → Letters n α) (U : Ω → G) (h : covered P X q)(j m : ℕ) (hh : j+m ≤ n) :let W := prefixB X j (by omega)(P.send W).Ex (fun w => bill tag c q (P.after W w) (readBlock X j m hh) U) ≤bill tag c q P X U := byintro Wlet l := n-jhave he : j+l=n := by dsimp [l]; omegahave hhh := bill_split tag c q P X U h (splitIx j l he)let V := readBlock X j l he.lehave H1 :(P.send W).Ex (fun w => bill tag c q (P.after W w) V U) ≤ bill tag c q P X U := bysimpa only [W,V,prefixB,readBlock,splitIx_left,splitIx_right] using hhhapply le_trans ?_ H1refine Ex_mono_mem _ (fun w hw => ?_)have hB : readBlock X j m hh = prefixB V m (by omega) := block_cut X j l m he.le (by omega)rw [hB]exact bill_subfamily tag c q _ V U(covered_subfamily (covered_after h _ _ hw) _) _ (offset_injective 0 m _)end billsplitend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165import OAI.Analysis.FourierLLogL.Compress.Variational/-! # Indexed blocks of letters -/open Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realabbrev Letters (n : ℕ) (α : Type) := Fin n → αabbrev WordSample (n : ℕ) (α G : Type) := Sample (Fin n) α Gvariable {ι τ κ n m k : ℕ} {α Ω G : Type}def offset (j l : ℕ) (h : j+l ≤ n) (i : Fin l) : Fin n := ⟨j+i, by have := i.isLt; omega⟩def readBlock (X : Ω → Letters n α) (j l : ℕ) (h : j+l ≤ n) :=keep X (offset j l h)def prefixB (X : Ω → Letters n α) (l : ℕ) (h : l ≤ n) := readBlock X 0 l (by omega)def readLetter (X : Ω → Letters n α) (j : ℕ) (h : j<n) := fun x => X x ⟨j,h⟩lemma offset_injective (j l : ℕ) (h : j+l ≤ n) : Injective (offset j l h) := byintro a b habhave H := congrArg Fin.val habsimp only [offset,Nat.add_left_cancel_iff] at Hexact Fin.ext Hlemma prefix_partition (X : Ω → Letters n α) (l k : ℕ) (h : l+k ≤ n) (x y : Ω) :prefixB X (l+k) h x = prefixB X (l+k) h y ↔prefixB X l (by omega) x = prefixB X l (by omega) y ∧ readBlock X l k h x = readBlock X l k h y := bysimp only [funext_iff]constructor· intro H; constructor· intro iexact H (i.castAdd k)· intro ⟨i,hi⟩have h1 := H (⟨l+i,by omega⟩:Fin (l+k))simpa only [prefixB,readBlock,keep,offset,zero_add] using h1· rintro ⟨H,G⟩ ⟨i,hi⟩by_cases hp : i < l· exact H ⟨i,hp⟩· have h1 := G (⟨i-l,by omega⟩:Fin k)simpa only [prefixB,readBlock,keep,offset,zero_add, Nat.add_sub_of_le (le_of_not_gt hp)]using h1lemma prefix_last_partition (X : Ω → Letters n α) (l : ℕ) (h : l<n) (x y : Ω) :prefixB X (l+1) h x = prefixB X (l+1) h y ↔readLetter X l h x = readLetter X l h y ∧prefixB X l (by omega) x = prefixB X l (by omega) y := byrw [prefix_partition X l 1 h]have HH : readBlock X l 1 h x = readBlock X l 1 h y ↔ readLetter X l h x = readLetter X l h y :=⟨fun e => congrFun e (0:Fin 1),fun e => by funext i; rw [Subsingleton.elim i 0]; exact e⟩rw [HH,and_comm]lemma prefix_zero (X : Ω → Letters n α) : prefixB X 0 (by omega) = fun _ => Fin.elim0 :=funext fun _ => Subsingleton.elim _ _lemma prefix_all (X : Ω → Letters n α) : prefixB X n le_rfl = X := byfunext a ⟨i,hi⟩simp only [prefixB,readBlock,keep,offset,zero_add]lemma block_cut (X : Ω → Letters n α) (j m l : ℕ) (h : j+m ≤ n) (hl : l ≤ m) :readBlock X j l (by omega) = prefixB (readBlock X j m h) l hl := byfunext a ⟨i,hi⟩; simp only [prefixB,readBlock,keep,offset,zero_add]lemma block_in_prefix (X : Ω → Letters n α) (j k l : ℕ) (hk : j+k ≤ l) (hl : l ≤ n) :readBlock X j k (hk.trans hl) = readBlock (prefixB X l hl) j k hk := byfunext a ⟨i,hi⟩; simp only [prefixB,readBlock,keep,offset,zero_add]def splitIx {n : ℕ} (l m : ℕ) (h : l+m=n) : (Fin m ⊕ Fin l) ≃ Fin n :=((Equiv.sumComm _ _).trans finSumFinEquiv).trans (finCongr h)lemma splitIx_left (l m : ℕ) (h : l+m=n) (i : Fin m) :splitIx l m h (.inl i) = offset l m h.le i := byapply Fin.extsimp only [splitIx,Equiv.trans_apply,finCongr_apply_coe]rfllemma splitIx_right (l m : ℕ) (h : l+m=n) (i : Fin l) :splitIx l m h (.inr i) = offset 0 l (by omega : 0+l≤n) i := byapply Fin.extsimp only [splitIx,Equiv.trans_apply,finCongr_apply_coe,offset,zero_add]rflsection reindexvariable {I J K : Type} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J][Fintype K] [DecidableEq K]omit [Fintype I] [Fintype J] [DecidableEq J] [DecidableEq I] inlemma lift_perm (g : J → I) (hg : Injective g) (e : Equiv.Perm J) :∃ f : Equiv.Perm I, (∀ i, f (g i) = g (e i)) ∧ ∀ x, x ∉ range g → f x = x := byclassicallet T := (Equiv.sumCongr (Equiv.ofInjective g hg) (Equiv.refl {x : I // x ∉ range g}))|>.trans (Equiv.sumCompl (fun x => x ∈ range g))let E := Equiv.sumCongr e (Equiv.refl {x : I // x ∉ range g})have H (x) : ((T.symm.trans E).trans T) (T x) = T (E x) := by simprefine ⟨(T.symm.trans E).trans T,fun i => H (.inl i),fun x hx => ?_⟩exact H (.inr ⟨x,hx⟩)variable [Fintype α] [Fintype G]def subSample (g : J → I) (p : Sample I α G) : Sample J α G :=((fun j => p.1 (g j)), p.2)lemma exch_subSample {P : Law (Sample I α G)} (hx : exch P)(g : J → I) (hg : Injective g) : exch (P.send (subSample g)) := byintro eobtain ⟨f,hf,hf'⟩ := lift_perm g hg erw [send_send]have HH := congrArg (fun R : Law (Sample I α G) => R.send (subSample g)) (hx f)rw [send_send] at HHsimpa [subSample,appPerm,hf] using HHlemma exch_subSample_cond {P : Law (Sample I α G)} (hx : exch P)(g : J → I) (hg : Injective g) (u : K → I) (hu : ∀ i, u i ∉ range g)(w : K → α) :let W := keep (fun p : Sample I α G => p.1) uexch ((P.after W w).send (subSample g)) := byintro W eobtain ⟨f,hf,hf'⟩ := lift_perm g hg ehave HH := congrArg (fun R : Law (Sample I α G) => R.send fun x => (subSample g x,W x)) (hx f)rw [send_send] at HHhave h1 (x : Sample I α G) : subSample g (appPerm f x) = appPerm e (subSample g x) := bysimp only [appPerm,subSample,hf]have h2 (x : Sample I α G) : W (appPerm f x) = W x := byfunext isimp only [W,keep,appPerm,hf' _ (hu i)]simp_rw [h1,h2] at HHrw [send_send]exact after_send_eq_of_send_pair_eq (X:=fun x => appPerm e (subSample g x)) (W:=W)(Y:=subSample g) (V:=W) HH wend reindexsection billsplitvariable [Fintype α] [Fintype Ω] [Fintype G] [AddCommGroup G]lemma prefix_bill (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → Letters n α) (U : Ω → G) (h : covered P X q)(j m : ℕ) (hh : j+m ≤ n) :let W := prefixB X j (by omega)(P.send W).Ex (fun w => bill tag c q (P.after W w) (readBlock X j m hh) U) ≤bill tag c q P X U := byintro Wlet l := n-jhave he : j+l=n := by dsimp [l]; omegahave hhh := bill_split tag c q P X U h (splitIx j l he)let V := readBlock X j l he.lehave H1 :(P.send W).Ex (fun w => bill tag c q (P.after W w) V U) ≤ bill tag c q P X U := bysimpa only [W,V,prefixB,readBlock,splitIx_left,splitIx_right] using hhhapply le_trans ?_ H1refine Ex_mono_mem _ (fun w hw => ?_)have hB : readBlock X j m hh = prefixB V m (by omega) := block_cut X j l m he.le (by omega)rw [hB]exact bill_subfamily tag c q _ V U(covered_subfamily (covered_after h _ _ hw) _) _ (offset_injective 0 m _)end billsplitend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260import OAI.Analysis.FourierLLogL.Compress.Projectionimport OAI.Analysis.FourierLLogL.Compress.Selectopen Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A V W G E α β Ω Ω' : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype α] [Fintype β] [Fintype Ω] [Fintype Ω'] [Fintype V] [Fintype W][Fintype E] [Nonempty E] {n : ℕ}set_option linter.unusedSectionVars false/-- Numerical Context State. -/structure Labelled (A : Type) [Fintype A] whereobs : Type[fObs : Fintype obs]law : Law (A × obs)attribute [instance] Labelled.fObsdef initial (p : Law A) : Labelled A := {obs := Unit, law:=p.send (fun x => (x,()))}def refines (P Q : Labelled A) : Prop :=∃ u : P.obs → Q.obs, P.law.send (fun a => (a.1,u a.2)) = Q.lawlemma refines_refl (p : Labelled A) : refines p p := byrefine ⟨id,?_⟩; exact send_id p.lawlemma refines_trans {p q r : Labelled A} :refines p q → refines q r → refines p r := byrintro ⟨u,hu⟩ ⟨v,hv⟩rw [← hu,send_send] at hvexact ⟨v ∘ u,hv⟩def lblSum (tag : A → G) (W : Labelled A) (m : ℕ) (x : Letters m (A × W.obs)) : G :=tot (tag ∘ Prod.fst) xdef lblCtx (W : Labelled A) (m : ℕ) (x : Letters m (A × W.obs)) : Letters m W.obs :=fun i => (x i).2/-- m-letter block of joint letter-and-context pairs, iid. -/def lblP (W : Labelled A) (m : ℕ) := iid W.law m/-- Conditional entropy of total sum. -/def fundG (tag : A → G) (p : Labelled A) (m : ℕ) :=(lblP p m).Hcond (lblSum tag p m) (lblCtx p m)/-- Conditional exact cost. -/def fundI (tag : A → G) (P : Labelled A) (r : ℕ) :=opt r P.law (tag ∘ Prod.fst) Prod.snd (fun _ : Unit => (0:G)) (fun _ => 0)/-- Conditional m-block noisy cost. -/def fundK (tag : A → G) (c : G → ℝ) (P : Labelled A) (m r : ℕ) :=opt r (lblP P m) (lblSum tag P m) (lblCtx P m) id clemma I_anti (tag : A → G) {P Q : Labelled A} (h : refines P Q) (r : ℕ) :fundI tag P r ≤ fundI tag Q r := byobtain ⟨u,hu⟩ := hunfold fundIrw [← hu]let f (x : A×P.obs) := (x.1,u x.2)exact opt_refined (tag ∘ Prod.fst) Prod.snd Prod.snd (fun _ : Unit => 0) (fun _ => 0) P.law f r u rfllemma K_anti (tag : A → G) (c : G → ℝ) {P Q : Labelled A}(h : refines P Q) (m r : ℕ) : fundK tag c P m r ≤ fundK tag c Q m r := byobtain ⟨u,hu⟩ := hlet X (x : A × P.obs) := (x.1,u x.2)let f (x : Letters m _) i := X (x i)have H : lblP Q m = (lblP P m).send f := byunfold lblP iid; rw [show Q.law = _ from hu.symm]exact (sendPack (fun _ : Fin m => P.law) (fun _ => X)).symmunfold fundKrw [H]exact opt_refined (lblSum tag Q m) (lblCtx Q m) (lblCtx P m) id c (lblP P m) f r (fun x i => u (x i)) rfllemma G_anti (tag : A → G) {P Q : Labelled A} (h : refines P Q)(m : ℕ) : fundG tag P m ≤ fundG tag Q m := byobtain ⟨u,hu⟩ := hlet X (x : A × P.obs) := (x.1,u x.2)let f (x : Letters m _) i := X (x i)have H : lblP Q m = (lblP P m).send f := byunfold lblP iid; rw [show Q.law = _ from hu.symm]exact (sendPack (fun _ : Fin m => P.law) (fun _ => X)).symmunfold fundGrw [H,Hcond_send]apply Hcond_antitoneintro a b hhfunext iexact congrArg u (congrFun hh i)lemma fundG_one (tag : A → G) (hi : Injective tag) (P : Labelled A) :fundG tag P 1 = P.law.Hcond Prod.fst Prod.snd := bylet Q := lblP P 1have h : Q.send (fun x => x 0) = P.law := marginalPack _ _rw [← h,Hcond_send]unfold fundG Hcondcongr 1· refine H_partition _ fun a b => ?_unfold lblSum lblCtx totsimp only [Fin.sum_univ_one,comp_apply,Prod.mk.injEq,hi.eq_iff,funext_iff]simp [Fin.forall_fin_one]· refine H_partition _ fun a b => ?_simp [funext_iff,lblCtx, Fin.forall_fin_one]def appendOne {m : ℕ} (p : A × Letters m A) : Letters (m+1) A := Fin.cons p.1 p.2lemma iid_succ (P : Law A) (m : ℕ) :iid P (m+1) = (P.tensorP (iid P m)).send appendOne := byapply ext_by_productsintro fdsimp only [iid]rw [Ex_send,Ex_tensorP]rw [pack_Ex_prod _ f]simp_rw [Fin.prod_univ_succ]unfold appendOnesimp only [Fin.cons_zero,Fin.cons_succ]simp_rw [Ex_lmul,pack_Ex_prod _ (fun i : Fin m => f i.succ),Ex_mul]lemma cons_part {m : ℕ} {a b : A} {x y : Letters m A} :(Fin.cons a x : Letters (m+1) A) = Fin.cons b y ↔ a = b ∧ x = y := byconstructor· intro hexact ⟨by simpa using congrFun h 0,by funext i; simpa using congrFun h i.succ⟩· rintro ⟨rfl,rfl⟩; rfllemma Hcond_tensor (P : Law Ω) (Q : Law Ω') (X : Ω → α) (Z : Ω' → β)(Y : Ω → V) (T : Ω' → W) :(P.tensorP Q).Hcond (fun x => (X x.1,Z x.2)) (fun x => (Y x.1,T x.2)) =P.Hcond X Y + Q.Hcond Z T := byunfold Hcondrw [H_partition (X:=fun (x:Ω×Ω') => ((X x.1,Z x.2),(Y x.1,T x.2)))(Y:=fun x => ((X x.1,Y x.1),(Z x.2,T x.2))) _ (fun _ _ => by simp; tauto)]rw [H_tensorP P Q (fun x => (X x,Y x)) (fun x => (Z x,T x)),H_tensorP]; ringlemma Hcond_tensor_right (P : Law Ω) (Q : Law Ω') (Z : Ω' → β)(Y : Ω → V) (T : Ω' → W) :(P.tensorP Q).Hcond (fun x => Z x.2) (fun x => (Y x.1,T x.2)) = Q.Hcond Z T := bylet X (_x : Ω) := ()rw [show Q.Hcond Z T = P.Hcond X Y + Q.Hcond Z T byrw [Hcond_determined (P:=P) (X:=X) (W:=Y) (fun _ _ _ => rfl)]; ring,← Hcond_tensor]unfold Hcondcongr 1apply H_partitionsimp only [Prod.mk.injEq, X]; tautolemma lbl_succ_sum (tag : A → G) (P : Labelled A) (m : ℕ)(x : (A×P.obs) × Letters m (A × P.obs)) :lblSum tag P (m+1) (appendOne x) = tag x.1.1 + lblSum tag P m x.2 := byunfold lblSum tot; rw [Fin.sum_univ_succ]; rfllemma lbl_succ_ctx (P : Labelled A) (m : ℕ)(x : (A×P.obs) × Letters m (A × P.obs)) :lblCtx P (m+1) (appendOne x) = appendOne (x.1.2,lblCtx P m x.2) := byfunext icases i using Fin.cases <;> simp [lblCtx,appendOne]lemma fundG_succ (tag : A → G) (P : Labelled A) (m : ℕ) :let Q := P.law.tensorP (lblP P m)let X (x : (A×P.obs) × Letters m (A×P.obs)) := tag x.1.1 + lblSum tag P m x.2let Z (x : (A×P.obs) × Letters m (A×P.obs)) := (x.1.2,lblCtx P m x.2)fundG tag P (m+1) = Q.Hcond X Z := byintro Q X Zunfold fundGrw [show lblP P (m+1)=Q.send appendOne from iid_succ P.law m,Hcond_send]simp_rw [lbl_succ_sum,lbl_succ_ctx]refine Hcond_right_partition _ X (fun x y => ?_)unfold appendOne Zsimp only [cons_part,Prod.mk.injEq]lemma fundG_mono (tag : A → G) (P : Labelled A) : Monotone (fundG tag P) := byrefine monotone_nat_of_le_succ fun i => ?_rw [fundG_succ]let Q := lblP P ilet R := P.law.tensorP Qlet W (x : (A×P.obs) × Letters i (A×P.obs)) := (x.1, lblCtx P i x.2)let X (x : (A×P.obs) × Letters i (A×P.obs)) := tag x.1.1 + lblSum tag P i x.2have hr : R.Hcond X W = R.Hcond (fun x => lblSum tag P i x.2) W := byunfold Hcondcongr 1apply H_partitionintro x ysimp only [W,X,Prod.mk.injEq]constructor· rintro ⟨h,h1,h2⟩; rw [h1] at h; exact ⟨add_left_cancel h,h1,h2⟩· rintro ⟨h,h1,h2⟩; exact ⟨by rw [h,h1],h1,h2⟩have he : R.Hcond (fun x => lblSum tag P i x.2) W = fundG tag P i :=Hcond_tensor_right P.law Q (lblSum tag P i) (fun x => x) (lblCtx P i)change fundG tag P i ≤ R.Hcond X _rw [← hr.trans he]apply Hcond_antitoneintro x y hhave H1 := congrArg Prod.fst hhave H2 := congrArg Prod.snd hexact Prod.ext (show x.1.2=y.1.2 from congrArg Prod.snd H1) (show lblCtx P i x.2=lblCtx P i y.2 from H2)lemma opt_succ (p : Law A) (tag : A → G) (w : A → V)(u : E → G) (c : E → ℝ) (n : ℕ) :opt n p tag w u c ≤ opt (n+1) p tag w u c := byobtain ⟨P,hP,he⟩ := (opt_spec (n+1) p tag w u c).1let X : WordSample (n+1) A E → Letters (n+1) A := Prod.fstlet U : WordSample (n+1) A E → E := Prod.sndlet Y (x : _) (i : Fin n) := X x i.succlet A' := readP X 0let W (x) := ans tag X (fun x => u (U x)) xlet Z (x) := ans tag Y (fun x => u (U x)) xlet WX (x : WordSample (n+1) A E) := (W x,ctxt w X x)let WY (x : WordSample (n+1) A E) := (Z x,ctxt w Y x)have hr : rent tag w u c P Y U ≤ rent tag w u c P X U := byhave h :P.Hcond X WX = P.Hcond Y (fun x => (A' x,WX x))+P.Hcond A' WX := byrw [← Hcond_chain]unfold Hcondcongr 1refine H_partition _ fun x y => ?_have hX : X x = X y ↔ Y x = Y y ∧ A' x = A' y := byconstructor· intro h; dsimp only [Y,A',readP]; rw [h]; exact ⟨rfl,rfl⟩· rintro ⟨h1,h2⟩; funext icases i using Fin.cases with| zero => exact h2| succ j => exact congrFun h1 jsimp only [Prod.mk.injEq,hX]have hc : P.Hcond Y (fun x => (A' x,WX x)) ≤ P.Hcond Y WY := byrefine Hcond_antitone _ _ fun x y hh => ?_change (Z x,ctxt w Y x) = _have heW (x) : W x = tag (A' x)+Z x := byunfold W Z ans totrw [Fin.sum_univ_succ,add_assoc]rflhave h1 := congrArg Prod.fst hhhave h2 := congrArg Prod.snd hhhave h3 : W x=W y := congrArg (fun a : G×_ => a.1) h2have h4 : ctxt w X x=ctxt w X y := congrArg (fun a : G×_ => a.2) h2rw [heW,heW, show A' x = A' y from h1] at h3exact Prod.ext (add_left_cancel h3) (funext fun i => congrFun h4 i.succ)have hd : P.Hcond A' WX ≤ P.Hcond A' (w ∘ A') := byrefine Hcond_antitone P _ (fun x y hh => ?_)have he : ctxt w X x = ctxt w X y := congrArg (fun a : G×_ => a.2) hhexact congrFun he 0unfold rentrefine add_le_add_left ?_ _change _ - P.Hcond Y WY ≤ _ - P.Hcond X WXrw [Fin.sum_univ_succ,h]have hEq (i : Fin n) : readP X i.succ = readP Y i := rflsimp_rw [hEq]change _ ≤ P.Hcond A' (w ∘ A')+_ - _linarithexact (opt_le_rent tag w u c p P Y U fun i => hP i.succ).trans (hr.trans he.le)lemma fundI_mono (tag : A → G) (P : Labelled A) : Monotone (fundI tag P) :=monotone_nat_of_le_succ (fun n => opt_succ P.law (tag ∘ Prod.fst) Prod.snd(fun _ : Unit => 0) (fun _ => 0) n)end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260import OAI.Analysis.FourierLLogL.Compress.Projectionimport OAI.Analysis.FourierLLogL.Compress.Selectopen Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A V W G E α β Ω Ω' : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype α] [Fintype β] [Fintype Ω] [Fintype Ω'] [Fintype V] [Fintype W][Fintype E] [Nonempty E] {n : ℕ}set_option linter.unusedSectionVars false/-- Numerical Context State. -/structure Labelled (A : Type) [Fintype A] whereobs : Type[fObs : Fintype obs]law : Law (A × obs)attribute [instance] Labelled.fObsdef initial (p : Law A) : Labelled A := {obs := Unit, law:=p.send (fun x => (x,()))}def refines (P Q : Labelled A) : Prop :=∃ u : P.obs → Q.obs, P.law.send (fun a => (a.1,u a.2)) = Q.lawlemma refines_refl (p : Labelled A) : refines p p := byrefine ⟨id,?_⟩; exact send_id p.lawlemma refines_trans {p q r : Labelled A} :refines p q → refines q r → refines p r := byrintro ⟨u,hu⟩ ⟨v,hv⟩rw [← hu,send_send] at hvexact ⟨v ∘ u,hv⟩def lblSum (tag : A → G) (W : Labelled A) (m : ℕ) (x : Letters m (A × W.obs)) : G :=tot (tag ∘ Prod.fst) xdef lblCtx (W : Labelled A) (m : ℕ) (x : Letters m (A × W.obs)) : Letters m W.obs :=fun i => (x i).2/-- m-letter block of joint letter-and-context pairs, iid. -/def lblP (W : Labelled A) (m : ℕ) := iid W.law m/-- Conditional entropy of total sum. -/def fundG (tag : A → G) (p : Labelled A) (m : ℕ) :=(lblP p m).Hcond (lblSum tag p m) (lblCtx p m)/-- Conditional exact cost. -/def fundI (tag : A → G) (P : Labelled A) (r : ℕ) :=opt r P.law (tag ∘ Prod.fst) Prod.snd (fun _ : Unit => (0:G)) (fun _ => 0)/-- Conditional m-block noisy cost. -/def fundK (tag : A → G) (c : G → ℝ) (P : Labelled A) (m r : ℕ) :=opt r (lblP P m) (lblSum tag P m) (lblCtx P m) id clemma I_anti (tag : A → G) {P Q : Labelled A} (h : refines P Q) (r : ℕ) :fundI tag P r ≤ fundI tag Q r := byobtain ⟨u,hu⟩ := hunfold fundIrw [← hu]let f (x : A×P.obs) := (x.1,u x.2)exact opt_refined (tag ∘ Prod.fst) Prod.snd Prod.snd (fun _ : Unit => 0) (fun _ => 0) P.law f r u rfllemma K_anti (tag : A → G) (c : G → ℝ) {P Q : Labelled A}(h : refines P Q) (m r : ℕ) : fundK tag c P m r ≤ fundK tag c Q m r := byobtain ⟨u,hu⟩ := hlet X (x : A × P.obs) := (x.1,u x.2)let f (x : Letters m _) i := X (x i)have H : lblP Q m = (lblP P m).send f := byunfold lblP iid; rw [show Q.law = _ from hu.symm]exact (sendPack (fun _ : Fin m => P.law) (fun _ => X)).symmunfold fundKrw [H]exact opt_refined (lblSum tag Q m) (lblCtx Q m) (lblCtx P m) id c (lblP P m) f r (fun x i => u (x i)) rfllemma G_anti (tag : A → G) {P Q : Labelled A} (h : refines P Q)(m : ℕ) : fundG tag P m ≤ fundG tag Q m := byobtain ⟨u,hu⟩ := hlet X (x : A × P.obs) := (x.1,u x.2)let f (x : Letters m _) i := X (x i)have H : lblP Q m = (lblP P m).send f := byunfold lblP iid; rw [show Q.law = _ from hu.symm]exact (sendPack (fun _ : Fin m => P.law) (fun _ => X)).symmunfold fundGrw [H,Hcond_send]apply Hcond_antitoneintro a b hhfunext iexact congrArg u (congrFun hh i)lemma fundG_one (tag : A → G) (hi : Injective tag) (P : Labelled A) :fundG tag P 1 = P.law.Hcond Prod.fst Prod.snd := bylet Q := lblP P 1have h : Q.send (fun x => x 0) = P.law := marginalPack _ _rw [← h,Hcond_send]unfold fundG Hcondcongr 1· refine H_partition _ fun a b => ?_unfold lblSum lblCtx totsimp only [Fin.sum_univ_one,comp_apply,Prod.mk.injEq,hi.eq_iff,funext_iff]simp [Fin.forall_fin_one]· refine H_partition _ fun a b => ?_simp [funext_iff,lblCtx, Fin.forall_fin_one]def appendOne {m : ℕ} (p : A × Letters m A) : Letters (m+1) A := Fin.cons p.1 p.2lemma iid_succ (P : Law A) (m : ℕ) :iid P (m+1) = (P.tensorP (iid P m)).send appendOne := byapply ext_by_productsintro fdsimp only [iid]rw [Ex_send,Ex_tensorP]rw [pack_Ex_prod _ f]simp_rw [Fin.prod_univ_succ]unfold appendOnesimp only [Fin.cons_zero,Fin.cons_succ]simp_rw [Ex_lmul,pack_Ex_prod _ (fun i : Fin m => f i.succ),Ex_mul]lemma cons_part {m : ℕ} {a b : A} {x y : Letters m A} :(Fin.cons a x : Letters (m+1) A) = Fin.cons b y ↔ a = b ∧ x = y := byconstructor· intro hexact ⟨by simpa using congrFun h 0,by funext i; simpa using congrFun h i.succ⟩· rintro ⟨rfl,rfl⟩; rfllemma Hcond_tensor (P : Law Ω) (Q : Law Ω') (X : Ω → α) (Z : Ω' → β)(Y : Ω → V) (T : Ω' → W) :(P.tensorP Q).Hcond (fun x => (X x.1,Z x.2)) (fun x => (Y x.1,T x.2)) =P.Hcond X Y + Q.Hcond Z T := byunfold Hcondrw [H_partition (X:=fun (x:Ω×Ω') => ((X x.1,Z x.2),(Y x.1,T x.2)))(Y:=fun x => ((X x.1,Y x.1),(Z x.2,T x.2))) _ (fun _ _ => by simp; tauto)]rw [H_tensorP P Q (fun x => (X x,Y x)) (fun x => (Z x,T x)),H_tensorP]; ringlemma Hcond_tensor_right (P : Law Ω) (Q : Law Ω') (Z : Ω' → β)(Y : Ω → V) (T : Ω' → W) :(P.tensorP Q).Hcond (fun x => Z x.2) (fun x => (Y x.1,T x.2)) = Q.Hcond Z T := bylet X (_x : Ω) := ()rw [show Q.Hcond Z T = P.Hcond X Y + Q.Hcond Z T byrw [Hcond_determined (P:=P) (X:=X) (W:=Y) (fun _ _ _ => rfl)]; ring,← Hcond_tensor]unfold Hcondcongr 1apply H_partitionsimp only [Prod.mk.injEq, X]; tautolemma lbl_succ_sum (tag : A → G) (P : Labelled A) (m : ℕ)(x : (A×P.obs) × Letters m (A × P.obs)) :lblSum tag P (m+1) (appendOne x) = tag x.1.1 + lblSum tag P m x.2 := byunfold lblSum tot; rw [Fin.sum_univ_succ]; rfllemma lbl_succ_ctx (P : Labelled A) (m : ℕ)(x : (A×P.obs) × Letters m (A × P.obs)) :lblCtx P (m+1) (appendOne x) = appendOne (x.1.2,lblCtx P m x.2) := byfunext icases i using Fin.cases <;> simp [lblCtx,appendOne]lemma fundG_succ (tag : A → G) (P : Labelled A) (m : ℕ) :let Q := P.law.tensorP (lblP P m)let X (x : (A×P.obs) × Letters m (A×P.obs)) := tag x.1.1 + lblSum tag P m x.2let Z (x : (A×P.obs) × Letters m (A×P.obs)) := (x.1.2,lblCtx P m x.2)fundG tag P (m+1) = Q.Hcond X Z := byintro Q X Zunfold fundGrw [show lblP P (m+1)=Q.send appendOne from iid_succ P.law m,Hcond_send]simp_rw [lbl_succ_sum,lbl_succ_ctx]refine Hcond_right_partition _ X (fun x y => ?_)unfold appendOne Zsimp only [cons_part,Prod.mk.injEq]lemma fundG_mono (tag : A → G) (P : Labelled A) : Monotone (fundG tag P) := byrefine monotone_nat_of_le_succ fun i => ?_rw [fundG_succ]let Q := lblP P ilet R := P.law.tensorP Qlet W (x : (A×P.obs) × Letters i (A×P.obs)) := (x.1, lblCtx P i x.2)let X (x : (A×P.obs) × Letters i (A×P.obs)) := tag x.1.1 + lblSum tag P i x.2have hr : R.Hcond X W = R.Hcond (fun x => lblSum tag P i x.2) W := byunfold Hcondcongr 1apply H_partitionintro x ysimp only [W,X,Prod.mk.injEq]constructor· rintro ⟨h,h1,h2⟩; rw [h1] at h; exact ⟨add_left_cancel h,h1,h2⟩· rintro ⟨h,h1,h2⟩; exact ⟨by rw [h,h1],h1,h2⟩have he : R.Hcond (fun x => lblSum tag P i x.2) W = fundG tag P i :=Hcond_tensor_right P.law Q (lblSum tag P i) (fun x => x) (lblCtx P i)change fundG tag P i ≤ R.Hcond X _rw [← hr.trans he]apply Hcond_antitoneintro x y hhave H1 := congrArg Prod.fst hhave H2 := congrArg Prod.snd hexact Prod.ext (show x.1.2=y.1.2 from congrArg Prod.snd H1) (show lblCtx P i x.2=lblCtx P i y.2 from H2)lemma opt_succ (p : Law A) (tag : A → G) (w : A → V)(u : E → G) (c : E → ℝ) (n : ℕ) :opt n p tag w u c ≤ opt (n+1) p tag w u c := byobtain ⟨P,hP,he⟩ := (opt_spec (n+1) p tag w u c).1let X : WordSample (n+1) A E → Letters (n+1) A := Prod.fstlet U : WordSample (n+1) A E → E := Prod.sndlet Y (x : _) (i : Fin n) := X x i.succlet A' := readP X 0let W (x) := ans tag X (fun x => u (U x)) xlet Z (x) := ans tag Y (fun x => u (U x)) xlet WX (x : WordSample (n+1) A E) := (W x,ctxt w X x)let WY (x : WordSample (n+1) A E) := (Z x,ctxt w Y x)have hr : rent tag w u c P Y U ≤ rent tag w u c P X U := byhave h :P.Hcond X WX = P.Hcond Y (fun x => (A' x,WX x))+P.Hcond A' WX := byrw [← Hcond_chain]unfold Hcondcongr 1refine H_partition _ fun x y => ?_have hX : X x = X y ↔ Y x = Y y ∧ A' x = A' y := byconstructor· intro h; dsimp only [Y,A',readP]; rw [h]; exact ⟨rfl,rfl⟩· rintro ⟨h1,h2⟩; funext icases i using Fin.cases with| zero => exact h2| succ j => exact congrFun h1 jsimp only [Prod.mk.injEq,hX]have hc : P.Hcond Y (fun x => (A' x,WX x)) ≤ P.Hcond Y WY := byrefine Hcond_antitone _ _ fun x y hh => ?_change (Z x,ctxt w Y x) = _have heW (x) : W x = tag (A' x)+Z x := byunfold W Z ans totrw [Fin.sum_univ_succ,add_assoc]rflhave h1 := congrArg Prod.fst hhhave h2 := congrArg Prod.snd hhhave h3 : W x=W y := congrArg (fun a : G×_ => a.1) h2have h4 : ctxt w X x=ctxt w X y := congrArg (fun a : G×_ => a.2) h2rw [heW,heW, show A' x = A' y from h1] at h3exact Prod.ext (add_left_cancel h3) (funext fun i => congrFun h4 i.succ)have hd : P.Hcond A' WX ≤ P.Hcond A' (w ∘ A') := byrefine Hcond_antitone P _ (fun x y hh => ?_)have he : ctxt w X x = ctxt w X y := congrArg (fun a : G×_ => a.2) hhexact congrFun he 0unfold rentrefine add_le_add_left ?_ _change _ - P.Hcond Y WY ≤ _ - P.Hcond X WXrw [Fin.sum_univ_succ,h]have hEq (i : Fin n) : readP X i.succ = readP Y i := rflsimp_rw [hEq]change _ ≤ P.Hcond A' (w ∘ A')+_ - _linarithexact (opt_le_rent tag w u c p P Y U fun i => hP i.succ).trans (hr.trans he.le)lemma fundI_mono (tag : A → G) (P : Labelled A) : Monotone (fundI tag P) :=monotone_nat_of_le_succ (fun n => opt_succ P.law (tag ∘ Prod.fst) Prod.snd(fun _ : Unit => 0) (fun _ => 0) n)end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232import OAI.Analysis.FourierLLogL.Finite.Alternativeimport OAI.Analysis.FourierLLogL.Finite.Independent/-! # Noisy sum entropy cost -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Lawvariable {ι τ κ α Ω Ω' A G : Type}variable [Fintype ι] [DecidableEq ι] [Fintype τ] [DecidableEq τ] [Fintype κ] [DecidableEq κ]variable [Fintype α] [Fintype Ω] [Fintype Ω'] [Fintype A] [Fintype G] [AddCommGroup G]def tot (tag : α → G) (x : ι → α) : G := ∑ i, tag (x i)def ans (tag : α → G) (X : Ω → ι → α) (U : Ω → G) (a : Ω) := tot tag (X a)+U a/-- Noisy bill: cross entropy with fixed comparator law per position, entropy ofletter vector conditional on noisy sum, plus error cost. -/def bill (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) :=(∑ i, P.Ex fun a => -log (q (X a i))) - P.Hcond X (ans tag X U) + P.Ex (fun a => c (U a))lemma bill_send (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω' → ι → α) (U : Ω' → G) (W : Ω → Ω') :bill tag c q (P.send W) X U = bill tag c q P (fun x => X (W x)) (fun x => U (W x)) := byunfold bill; simp_rw [Hcond_send,Ex_send]; rfllemma bill_mixture_le (tag : α → G) (c : G → ℝ) (q : Law α)(P Q : Law Ω) (X : Ω → ι → α) (U : Ω → G) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :bill tag c q (mixture P Q t h0 h1) X U ≤t*bill tag c q P X U + (1-t)*bill tag c q Q X U := byunfold billsimp_rw [mixture_Ex,Finset.sum_add_distrib, ← Finset.mul_sum]have H := Hcond_mixture_ge P Q t h0 h1 X (ans tag X U)linarithlemma bill_cont (tag : α → G) (c : G → ℝ) (q : Law α)(X : Ω → ι → α) (U : Ω → G) :Continuous (fun P : Law Ω => bill tag c q P X U) :=((continuous_finsetSum _ fun _ _ => continuous_Ex _).sub (continuous_Hcond _ _)).add(continuous_Ex _)lemma bill_through_le (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω' → ι → α) (U : Ω' → G) (Q : Ω → Law Ω') :bill tag c q (P.through Q) X U ≤ P.Ex (fun a => bill tag c q (Q a) X U) := byunfold billsimp_rw [Ex_add,Ex_sub,Ex_through, ← Ex_finset_sum]linarith [Hcond_through P Q X (ans tag X U)]/-- All letters have support contained in comparison law's. -/def covered (P : Law Ω) (X : Ω → ι → α) (q : Law α) : Prop :=∀ x, 0 < P x → ∀ i, 0 < q (X x i)lemma covered_pack {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q) :(P.send X).dominated (pack (fun _ => q)) := byintro x hxobtain ⟨a,rfl,ha⟩ := (send_pos_iff _ _ _).mp hxexact (pack_pos _ _).mpr (h a ha)lemma sum_crosspack {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q) :(P.send X).crossE (pack (fun _ => q)) = ∑ i, P.Ex fun a => -log (q (X a i)) := byrw [crossE_pack (covered_pack h)]simp_rw [crossE,Ex_send]lemma kl_le_bill {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (_hc : ∀ x, 0 ≤ c x) (U : Ω → G) :(P.send X).kl (pack (fun _ => q)) + P.Ex (fun a => c (U a)) ≤ bill tag c q P X U := byunfold bill klrw [sum_crosspack h]exact add_le_add_left (sub_le_sub_left (Hcond_le_H P X _) _) _lemma bill_nonneg {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (U : Ω → G) :0 ≤ bill tag c q P X U := le_trans(add_nonneg (kl_nonneg (covered_pack h)) (P.Ex_nonneg fun a => hc (U a)))(kl_le_bill h tag c hc U)lemma bill_with_entropy {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (U : Ω → G) :bill tag c q P X U =(P.send X).kl (pack (fun _ => q)) + (P.H (ans tag X U) - P.Hcond U X) +P.Ex fun a => c (U a) := bylet Z := ans tag X Uhave h1 : P.H (fun a => (U a,X a)) = P.H (fun a => (X a,Z a)) :=P.H_partition fun x y => bysimp only [Z,ans,Prod.mk.injEq]constructor· rintro ⟨hu,hx⟩; rw [hu,hx]; exact ⟨rfl,rfl⟩· rintro ⟨hx,hz⟩; rw [hx] at hz; exact ⟨add_left_cancel hz,hx⟩unfold bill klrw [← sum_crosspack h]change _ - P.Hcond X Z + _ = (_ - P.H X) + (P.H Z- P.Hcond U X)+_unfold Hcond; rw [h1]; ringlemma bill_change {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (U : Ω → G) (p : Law α)(hp : ∀ i, P.send (fun x => X x i) = p) :bill tag c p P X U ≤ bill tag c q P X U := byapply add_le_add_leftapply sub_le_sub_rightrefine Finset.sum_le_sum fun i _ => ?_let x (a : Ω) := X a ihave h1 : p.dominated q := byintro b hbhave HH : 0 < P.send x b := by rw [hp i]; exact hbobtain ⟨a,rfl,ha⟩ := (P.send_pos_iff _ b).mp HHexact h a ha isuffices hi : (P.send x).crossE p ≤ (P.send x).crossE q bysimpa only [crossE, Ex_send] using hirw [show x = _ from rfl, hp i]exact sub_nonneg.mp (kl_nonneg h1)lemma bill_condition (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) (W : Ω → A) :(P.send W).Ex (fun w => bill tag c q (P.after W w) X U) ≤bill tag c q P X U + P.H W := bylet Z := ans tag X Uhave hE (f : Ω → ℝ) :(P.send W).Ex (fun w => (P.after W w).Ex f) = P.Ex f :=P.after_Ex_sum W (fun _ => f)have hY := Hcond_after_cond P X Z Whave hP := P.Hcond_nonneg W (fun x => (X x,Z x))have hl := Hcond_le_H P W Zhave heq := P.H_partition (X:=fun x => ((X x), Z x,W x))(Y:=fun x => (W x,X x,Z x)) (fun _ _ => by simp; tauto)have hp := P.H_pair_rev W Zunfold billsimp_rw [Ex_add,Ex_sub,Ex_finset_sum,hE]change _ - ((P.send W).Ex (fun w => (P.after W w).Hcond X Z)) + _ ≤(_-P.Hcond X Z + _)+_rw [← hY]unfold Hcond at *linarithomit [DecidableEq ι] [DecidableEq τ] [DecidableEq κ] inlemma sum_split' (e : τ ⊕ κ ≃ ι) {M : Type*} [AddCommMonoid M] (f : ι → M) :∑ i, f i = ∑ i, f (e (.inl i)) + ∑ i, f (e (.inr i)) :=calc_ = ∑ i, f (e i) :=(Fintype.sum_equiv e _ f (fun _ => rfl)).symm_ = _ := Fintype.sum_sum_type _def keep (X : Ω → ι → α) (s : τ → ι) := fun a i => X a (s i)lemma bill_split (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) (h : covered P X q) (e : τ ⊕ κ ≃ ι) :let V := keep X (fun i => e (.inl i))let W := keep X (fun i => e (.inr i))(P.send W).Ex (fun w => bill tag c q (P.after W w) V U) ≤ bill tag c q P X U := byintro V Wlet Y := ans tag V Ulet Z := ans tag X Uhave hs (x : Ω) : Z x = Y x + tot tag (W x) := byunfold Z Y ans totrw [sum_split' e (fun i => tag _)]dsimp only [V,W,keep]abelhave hh (x y : Ω) : X x = X y ↔ (V x,W x) = (V y,W y) := byconstructor· intro h; unfold V W keep; rw [h]· intro Hfunext iobtain ⟨t,rfl⟩ := e.surjective ircases t with t|t· exact congrFun (congrArg Prod.fst H) t· exact congrFun (congrArg Prod.snd H) thave hpart :P.Hcond X Z = P.Hcond (fun x => (V x,W x)) Z := byunfold Hcondcongr 1exact P.H_partition fun x y => by simp [hh x y]have hpart' :P.Hcond V (fun x => (W x,Z x)) = P.Hcond V (fun x => (Y x,W x)) := byapply Hcond_right_partitionintro a bsimp only [Prod.mk.injEq, hs]constructor· rintro ⟨h,he⟩; rw [h] at he; exact ⟨add_right_cancel he,h⟩· rintro ⟨h,h'⟩; rw [h,h']; exact ⟨rfl,rfl⟩have hCE : P.Hcond W Z ≤ ∑ i, P.Ex (fun x => -log (q (W x i))) := byhave hcW : covered P W q := fun x hx _ => h x hx _apply le_trans (P.Hcond_le_H W Z)rw [← sum_crosspack hcW]exact sub_nonneg.mp (kl_nonneg (covered_pack hcW))have hE (f : Ω → ℝ) :(P.send W).Ex (fun w => (P.after W w).Ex f) = P.Ex f :=P.after_Ex_sum W (fun _ => f)unfold billsimp_rw [Ex_add,Ex_sub,Ex_finset_sum,hE, ← Hcond_after_cond]change _ - P.Hcond V _ + _ ≤ (_ - P.Hcond X Z) + _rw [sum_split' e (fun i : ι => P.Ex (fun x => -log (q (X x i)))),hpart,Hcond_chain,hpart']change _ - P.Hcond V (fun x => (Y x,W x)) + _ ≤((∑ i, P.Ex fun x => -log (q (V x i))) + (∑ i, P.Ex fun x => -log (q (W x i))) - _) + _linarithlemma bill_subfamily (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) (h : covered P X q)(g : τ → ι) (hg : Injective g) :bill tag c q P (keep X g) U ≤ bill tag c q P X U := byclassicallet e := (Equiv.sumCongr (Equiv.ofInjective g hg)(Equiv.refl {x // ¬ (fun y => y ∈ range g) x})).trans (Equiv.sumCompl (fun y => y ∈ range g))let V := keep X (fun i => e (.inl i))let W := keep X (fun i => e (.inr i))have H :bill tag c q P V U ≤ bill tag c q P X U := byrefine le_trans ?_ (bill_split tag c q P X U h e)have hh := bill_through_le tag c q (P.send W) V U (P.after W)rw [through_after] at hhexact hhhave heq : V = keep X g := rflrwa [heq] at Homit [Fintype ι] [DecidableEq ι] [Fintype τ] [DecidableEq τ] inlemma covered_subfamily {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(g : τ → ι) : covered P (keep X g) q := fun x hx _ => h x hx _omit [Fintype ι] [DecidableEq ι] inlemma covered_after {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(W : Ω → A) (w : A) (hw : 0 < P.send W w) : covered (P.after W w) X q :=fun x hx i => h x ((after_mem hw).mp hx).2 iend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232import OAI.Analysis.FourierLLogL.Finite.Alternativeimport OAI.Analysis.FourierLLogL.Finite.Independent/-! # Noisy sum entropy cost -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Lawvariable {ι τ κ α Ω Ω' A G : Type}variable [Fintype ι] [DecidableEq ι] [Fintype τ] [DecidableEq τ] [Fintype κ] [DecidableEq κ]variable [Fintype α] [Fintype Ω] [Fintype Ω'] [Fintype A] [Fintype G] [AddCommGroup G]def tot (tag : α → G) (x : ι → α) : G := ∑ i, tag (x i)def ans (tag : α → G) (X : Ω → ι → α) (U : Ω → G) (a : Ω) := tot tag (X a)+U a/-- Noisy bill: cross entropy with fixed comparator law per position, entropy ofletter vector conditional on noisy sum, plus error cost. -/def bill (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) :=(∑ i, P.Ex fun a => -log (q (X a i))) - P.Hcond X (ans tag X U) + P.Ex (fun a => c (U a))lemma bill_send (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω' → ι → α) (U : Ω' → G) (W : Ω → Ω') :bill tag c q (P.send W) X U = bill tag c q P (fun x => X (W x)) (fun x => U (W x)) := byunfold bill; simp_rw [Hcond_send,Ex_send]; rfllemma bill_mixture_le (tag : α → G) (c : G → ℝ) (q : Law α)(P Q : Law Ω) (X : Ω → ι → α) (U : Ω → G) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :bill tag c q (mixture P Q t h0 h1) X U ≤t*bill tag c q P X U + (1-t)*bill tag c q Q X U := byunfold billsimp_rw [mixture_Ex,Finset.sum_add_distrib, ← Finset.mul_sum]have H := Hcond_mixture_ge P Q t h0 h1 X (ans tag X U)linarithlemma bill_cont (tag : α → G) (c : G → ℝ) (q : Law α)(X : Ω → ι → α) (U : Ω → G) :Continuous (fun P : Law Ω => bill tag c q P X U) :=((continuous_finsetSum _ fun _ _ => continuous_Ex _).sub (continuous_Hcond _ _)).add(continuous_Ex _)lemma bill_through_le (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω' → ι → α) (U : Ω' → G) (Q : Ω → Law Ω') :bill tag c q (P.through Q) X U ≤ P.Ex (fun a => bill tag c q (Q a) X U) := byunfold billsimp_rw [Ex_add,Ex_sub,Ex_through, ← Ex_finset_sum]linarith [Hcond_through P Q X (ans tag X U)]/-- All letters have support contained in comparison law's. -/def covered (P : Law Ω) (X : Ω → ι → α) (q : Law α) : Prop :=∀ x, 0 < P x → ∀ i, 0 < q (X x i)lemma covered_pack {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q) :(P.send X).dominated (pack (fun _ => q)) := byintro x hxobtain ⟨a,rfl,ha⟩ := (send_pos_iff _ _ _).mp hxexact (pack_pos _ _).mpr (h a ha)lemma sum_crosspack {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q) :(P.send X).crossE (pack (fun _ => q)) = ∑ i, P.Ex fun a => -log (q (X a i)) := byrw [crossE_pack (covered_pack h)]simp_rw [crossE,Ex_send]lemma kl_le_bill {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (_hc : ∀ x, 0 ≤ c x) (U : Ω → G) :(P.send X).kl (pack (fun _ => q)) + P.Ex (fun a => c (U a)) ≤ bill tag c q P X U := byunfold bill klrw [sum_crosspack h]exact add_le_add_left (sub_le_sub_left (Hcond_le_H P X _) _) _lemma bill_nonneg {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (U : Ω → G) :0 ≤ bill tag c q P X U := le_trans(add_nonneg (kl_nonneg (covered_pack h)) (P.Ex_nonneg fun a => hc (U a)))(kl_le_bill h tag c hc U)lemma bill_with_entropy {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (U : Ω → G) :bill tag c q P X U =(P.send X).kl (pack (fun _ => q)) + (P.H (ans tag X U) - P.Hcond U X) +P.Ex fun a => c (U a) := bylet Z := ans tag X Uhave h1 : P.H (fun a => (U a,X a)) = P.H (fun a => (X a,Z a)) :=P.H_partition fun x y => bysimp only [Z,ans,Prod.mk.injEq]constructor· rintro ⟨hu,hx⟩; rw [hu,hx]; exact ⟨rfl,rfl⟩· rintro ⟨hx,hz⟩; rw [hx] at hz; exact ⟨add_left_cancel hz,hx⟩unfold bill klrw [← sum_crosspack h]change _ - P.Hcond X Z + _ = (_ - P.H X) + (P.H Z- P.Hcond U X)+_unfold Hcond; rw [h1]; ringlemma bill_change {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(tag : α → G) (c : G → ℝ) (U : Ω → G) (p : Law α)(hp : ∀ i, P.send (fun x => X x i) = p) :bill tag c p P X U ≤ bill tag c q P X U := byapply add_le_add_leftapply sub_le_sub_rightrefine Finset.sum_le_sum fun i _ => ?_let x (a : Ω) := X a ihave h1 : p.dominated q := byintro b hbhave HH : 0 < P.send x b := by rw [hp i]; exact hbobtain ⟨a,rfl,ha⟩ := (P.send_pos_iff _ b).mp HHexact h a ha isuffices hi : (P.send x).crossE p ≤ (P.send x).crossE q bysimpa only [crossE, Ex_send] using hirw [show x = _ from rfl, hp i]exact sub_nonneg.mp (kl_nonneg h1)lemma bill_condition (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) (W : Ω → A) :(P.send W).Ex (fun w => bill tag c q (P.after W w) X U) ≤bill tag c q P X U + P.H W := bylet Z := ans tag X Uhave hE (f : Ω → ℝ) :(P.send W).Ex (fun w => (P.after W w).Ex f) = P.Ex f :=P.after_Ex_sum W (fun _ => f)have hY := Hcond_after_cond P X Z Whave hP := P.Hcond_nonneg W (fun x => (X x,Z x))have hl := Hcond_le_H P W Zhave heq := P.H_partition (X:=fun x => ((X x), Z x,W x))(Y:=fun x => (W x,X x,Z x)) (fun _ _ => by simp; tauto)have hp := P.H_pair_rev W Zunfold billsimp_rw [Ex_add,Ex_sub,Ex_finset_sum,hE]change _ - ((P.send W).Ex (fun w => (P.after W w).Hcond X Z)) + _ ≤(_-P.Hcond X Z + _)+_rw [← hY]unfold Hcond at *linarithomit [DecidableEq ι] [DecidableEq τ] [DecidableEq κ] inlemma sum_split' (e : τ ⊕ κ ≃ ι) {M : Type*} [AddCommMonoid M] (f : ι → M) :∑ i, f i = ∑ i, f (e (.inl i)) + ∑ i, f (e (.inr i)) :=calc_ = ∑ i, f (e i) :=(Fintype.sum_equiv e _ f (fun _ => rfl)).symm_ = _ := Fintype.sum_sum_type _def keep (X : Ω → ι → α) (s : τ → ι) := fun a i => X a (s i)lemma bill_split (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) (h : covered P X q) (e : τ ⊕ κ ≃ ι) :let V := keep X (fun i => e (.inl i))let W := keep X (fun i => e (.inr i))(P.send W).Ex (fun w => bill tag c q (P.after W w) V U) ≤ bill tag c q P X U := byintro V Wlet Y := ans tag V Ulet Z := ans tag X Uhave hs (x : Ω) : Z x = Y x + tot tag (W x) := byunfold Z Y ans totrw [sum_split' e (fun i => tag _)]dsimp only [V,W,keep]abelhave hh (x y : Ω) : X x = X y ↔ (V x,W x) = (V y,W y) := byconstructor· intro h; unfold V W keep; rw [h]· intro Hfunext iobtain ⟨t,rfl⟩ := e.surjective ircases t with t|t· exact congrFun (congrArg Prod.fst H) t· exact congrFun (congrArg Prod.snd H) thave hpart :P.Hcond X Z = P.Hcond (fun x => (V x,W x)) Z := byunfold Hcondcongr 1exact P.H_partition fun x y => by simp [hh x y]have hpart' :P.Hcond V (fun x => (W x,Z x)) = P.Hcond V (fun x => (Y x,W x)) := byapply Hcond_right_partitionintro a bsimp only [Prod.mk.injEq, hs]constructor· rintro ⟨h,he⟩; rw [h] at he; exact ⟨add_right_cancel he,h⟩· rintro ⟨h,h'⟩; rw [h,h']; exact ⟨rfl,rfl⟩have hCE : P.Hcond W Z ≤ ∑ i, P.Ex (fun x => -log (q (W x i))) := byhave hcW : covered P W q := fun x hx _ => h x hx _apply le_trans (P.Hcond_le_H W Z)rw [← sum_crosspack hcW]exact sub_nonneg.mp (kl_nonneg (covered_pack hcW))have hE (f : Ω → ℝ) :(P.send W).Ex (fun w => (P.after W w).Ex f) = P.Ex f :=P.after_Ex_sum W (fun _ => f)unfold billsimp_rw [Ex_add,Ex_sub,Ex_finset_sum,hE, ← Hcond_after_cond]change _ - P.Hcond V _ + _ ≤ (_ - P.Hcond X Z) + _rw [sum_split' e (fun i : ι => P.Ex (fun x => -log (q (X x i)))),hpart,Hcond_chain,hpart']change _ - P.Hcond V (fun x => (Y x,W x)) + _ ≤((∑ i, P.Ex fun x => -log (q (V x i))) + (∑ i, P.Ex fun x => -log (q (W x i))) - _) + _linarithlemma bill_subfamily (tag : α → G) (c : G → ℝ) (q : Law α)(P : Law Ω) (X : Ω → ι → α) (U : Ω → G) (h : covered P X q)(g : τ → ι) (hg : Injective g) :bill tag c q P (keep X g) U ≤ bill tag c q P X U := byclassicallet e := (Equiv.sumCongr (Equiv.ofInjective g hg)(Equiv.refl {x // ¬ (fun y => y ∈ range g) x})).trans (Equiv.sumCompl (fun y => y ∈ range g))let V := keep X (fun i => e (.inl i))let W := keep X (fun i => e (.inr i))have H :bill tag c q P V U ≤ bill tag c q P X U := byrefine le_trans ?_ (bill_split tag c q P X U h e)have hh := bill_through_le tag c q (P.send W) V U (P.after W)rw [through_after] at hhexact hhhave heq : V = keep X g := rflrwa [heq] at Homit [Fintype ι] [DecidableEq ι] [Fintype τ] [DecidableEq τ] inlemma covered_subfamily {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(g : τ → ι) : covered P (keep X g) q := fun x hx _ => h x hx _omit [Fintype ι] [DecidableEq ι] inlemma covered_after {P : Law Ω} {X : Ω → ι → α} {q : Law α} (h : covered P X q)(W : Ω → A) (w : A) (hw : 0 < P.send W w) : covered (P.after W w) X q :=fun x hx i => h x ((after_mem hw).mp hx).2 iend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222import OAI.Analysis.FourierLLogL.Compress.Theoremimport OAI.Analysis.FourierLLogL.Compress.Params/-! # The compression lemma, asymptotic scales -/open Set Function Filteropen scoped Topology BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Law Paramslemma log_ticket (r j : ℕ) (hr : 1 ≤ r) (h : r ≤ 2^j) (hj : 1 ≤ j) :log (Fintype.card (Ticket r (2*r)) : ℝ) ≤ 1 + r*(2*(j:ℝ)) := byhave hp : 0 < (r:ℝ) := by exact_mod_cast hrhave hcard : Fintype.card (Fin r ↪ Fin (2*r)) ≤ (2*r)^r := byhave hi := Fintype.card_le_of_injective(fun (e : Fin r ↪ Fin (2*r)) => (e : Fin r → Fin (2*r))) (by intro a b hab; ext i : 1; exact congrFun hab i)simpa using hihave hl2 := log_le_sub_one_of_pos (show (0:ℝ)<2 by norm_num)have hx : log (2*(r:ℝ)) ≤ 2*(j:ℝ) := byrw [log_mul (by norm_num) hp.ne']have h1 := Real.log_le_log hp (show (r:ℝ) ≤ 2^j by exact_mod_cast h)rw [log_pow] at h1have hJ : (1:ℝ) ≤ j := by exact_mod_cast hjnlinarithunfold Ticketrw [Fintype.card_option]have ht : 0 < ((Fintype.card (Fin r ↪ Fin (2*r)) + 1:ℕ):ℝ) := by positivityapply le_trans (Real.log_le_log ht (y:=2*(2*(r:ℝ))^r) ?_) ?_· have h1 : Fintype.card (Fin r ↪ Fin (2*r)) + 1 ≤ 2*(2*r)^r := byhave hp : 0 < (2*r)^r := pow_pos (by omega) _omegaexact_mod_cast h1rw [Real.log_mul (by norm_num) (by positivity),Real.log_pow]nlinarithprivate lemma approx_error {d h F D T m j : ℝ} (hh : 1 ≤ h) (hj : h ≤ j)(hd : 0 < d) (hm : 0 < m) (hD : 1 ≤ D)(hF : d/h^2 ≤ F) (hFd : F ≤ D*d)(Ht : d=4*T*h^6)(H : 1024*D*j^16 ≤ m) (H' : m^4 ≤ d) :(2*m*√F/T)*(d*j^2) ≤ F := byhave hh' : 0 < h := by linarithhave hF' : 0 < F := lt_of_lt_of_le (by positivity) hFhave hp : 0 < T := pos_of_mul_pos_left (show 0 < T*(4*h^6) bycalc 0 < d := hd_ = T*(4*h^6) := by rw [Ht]; ring) (by positivity)have hw : 8*D*(j^2*h^8) ≤ m := byapply le_trans _ Hhave hj1 : 1 ≤ j := hh.trans hjcalc_ ≤ 8*D*(j^2*j^8) := by gcongr_ ≤ 1024*D*j^16 := byhave HH : j^10 ≤ j^16 := pow_le_pow_right₀ hj1 (by omega)rw [← pow_add]; gcongr; norm_numhave hsr : √F ≤ D*√d := byhave Hx := sq_sqrt hF'.lehave Hy := sq_sqrt hd.lehave Hh : D*d ≤ (D*√d)^2 := byrw [mul_pow,Hy]; gcongr; nlinarithnlinarith [hFd.trans Hh,sqrt_nonneg F, show 0 ≤ D*√d by positivity]have hQ : m^2 ≤ √d := byhave Ht := sq_sqrt hd.lenlinarith [show m^4=(m^2)^2 by ring,sqrt_nonneg d,sq_nonneg (m^2-√d)]have hz : 8*m*√F*j^2*h^8 ≤ d := bycalc_ ≤ m * √d * (8*D*(j^2*h^8)) := bycalc_ ≤ 8*m*(D*√d)*j^2*h^8 := by gcongr_ = _ := by ring_ ≤ m*√d*m := mul_le_mul_of_nonneg_left hw (by positivity)_ = m^2*√d := by ring_ ≤ √d*√d := mul_le_mul_of_nonneg_right hQ (sqrt_nonneg _)_ = d := by rw [← sq,sq_sqrt hd.le]apply le_trans (b:=d/h^2) _ hFapply (le_div_iff₀ (pow_pos hh' 2)).mprhave hle : 2*m*√F*j^2*h^2 ≤ T := byrw [Ht] at hzrefine le_of_mul_le_mul_right ?_ (show 0 < 4*h^6 by positivity)calc_ = 8*m*√F*j^2*h^8 := by ring_ ≤ 4*T*h^6 := hz_ = T*(4*h^6) := by ringcalc_ = (2*m*√F*j^2*h^2)/T*d := by ring_ ≤ 1*d := mul_le_mul_of_nonneg_right ((div_le_one hp).mpr hle) hd.le_ = d := one_mul dprivate lemma size_bound {d h F D T a : ℝ} (hh : 1 ≤ h) (hd : 0 < d) (hT : 0 < T)(hD : 1 ≤ D) (hp : 0 < F) (hF : F ≤ D*d)(Ht : d=4*T*h^6)(H : D*h^8 ≤ d) (ha : a ≤ 66/h^2) :8*(3*(F/T)+a*(20*D*d)*(20*D*d)/F)+2 ≤ 300000*D^2*d^2/(F*h^2) := byhave hh' : 0 < h := by linarithhave hc : 0 < 20*D*d := by positivityapply (le_div_iff₀ (by positivity : 0 < F*h^2)).mprlet x := D^2*d^2have hx : 0 ≤ x := by unfold x; positivityhave hF1 : F^2 ≤ x := by unfold x; rw [← mul_pow]; gcongrhave hT1 : h^2 ≤ 4*T := byhave H1 : h^8 ≤ d := le_trans (le_mul_of_one_le_left (by positivity) hD) Hrw [Ht,show h^8=h^2*h^6 by ring] at H1exact le_of_mul_le_mul_right H1 (by positivity)have he1 : F/T*(F*h^2) ≤ 4*x := calc_ ≤ F/T*(F*(4*T)) := by gcongr_ = 4*F^2 := by field_simp_ ≤ 4*x := by gcongrhave he2 : a*(20*D*d)*(20*D*d)/F*(F*h^2) ≤ (66*400)*x := bycalc_ ≤ (66/h^2)*(20*D*d)*(20*D*d)/F*(F*h^2) := by gcongr_ = _ := by unfold x; field_simp; ringhave HH : h^2 ≤ h^8 := pow_le_pow_right₀ hh (by norm_num)have he3 : F*h^2 ≤ x := byhave h1 : h^8 ≤ d := le_trans (le_mul_of_one_le_left (by positivity) hD) Hcalc_ ≤ (D*d)*(D*d) := by gcongr; nlinarith_ = _ := by unfold x; ringcalc_ = 24*(F/T*(F*h^2))+8*(a*(20*D*d)*(20*D*d)/F*(F*h^2))+2*(F*h^2) := by ring_ ≤ 300000*x := by linarith_ = _ := by unfold x; ring/-- Compression at the scales in terms of d=2^j. -/theorem entropy_compression (D : ℝ) (hD : 1 ≤ D) :∀ᶠ j : ℕ in atTop, ∀ (A G Θ : Type)(_ : Fintype A) (_ : Fintype G) (_ : Fintype Θ) (_ : Nonempty A)(_ : DecidableEq G) (_ : AddCommGroup G)(tag : A → G), Injective tag → ∀ (q : Law G), (∀ x, 0 < q x) →∀ (c : G → ℝ), (∀ x, 0 ≤ c x) → c 0=0 →∀ (Q : Law Θ) (χ : Θ → AddChar G ℂ),(∀ t x, ‖χ t x‖=1) →(∀ g, (↑(exp (-c g)):ℂ)=Q.Cx (fun t => χ t g)) →(∀ g, -log (q g) = -log (q 0) + c g) →-log (q 0) ≤ D*height j →(∀ n : ℕ, n ≤ 2^(2*j) → lnS (Fin n) tag ≤ height j * j^2) →∀ F : ℝ, height j/(slow j:ℝ)^2 ≤ F → F ≤ D*height j →(∀ p : Law A, exp (-F) ≤ heatMoment (Fin (sLen j)) p tag c) →∃ (a : A) (s : Finset A), s.Nonempty ∧log (Fintype.card A)-log (s.card:ℝ) ≤300000*D^2*(height j)^2/(F*(slow j:ℝ)^2) ∧small_defects tag χ Q (long j) s a (350*F) := byfilter_upwards [array_spec,big_t_real,below_base 16 (1024*D),slow_le_j,slow_tendsto.eventually (eventually_ge_atTop 4),t_expr] with j hs ht hb hj h4 hjtintro A G Θ _ _ _ _ _ _ tag hi q hq c hc hc0 Q χ hn hrq hlog hq0 hv F hF hFd hlet d := height j; let t : ℝ := slow jhave h4' : 4 ≤ t := by unfold t; exact_mod_cast h4have htj : t ≤ j := by unfold t; exact_mod_cast hjhave hd : 0 < d := by unfold d height; positivitylet N := sSeg jhave hpN : (0:ℝ) < N := byunfold N; exact_mod_cast pow_pos_nat (j-6*ell j-2)obtain ⟨hT,hsm,hmd,hil,horder⟩ := hschange d=4*N*t^6 ∧ _ at hthave hb' : (base j:ℝ) ≤ cap j := by exact_mod_cast base_le_cap jhave hj1 : (1:ℝ) ≤ (j:ℝ) := by linarithhave hh : D*t^8 ≤ d := byhave h1 : (cap j:ℝ) ≤ d := by unfold d height; exact_mod_cast hmdcalc_ ≤ 1024*D*(j:ℝ)^16 := byhave hx : t^8 ≤ (j:ℝ)^16 := le_trans (pow_le_pow_left₀ (by linarith) htj _) (pow_le_pow_right₀ hj1 (by norm_num))gcongr; nlinarith_ ≤ _ := hb.trans (hb'.trans h1)have h44 : t^2 ≤ d := bycalct^2 ≤ t^8 := pow_le_pow_right₀ (by linarith) (by norm_num)_ ≤ _ := le_trans (le_mul_of_one_le_left (by positivity) hD) hhhave htp : 0 < t := by linarithhave he : 1 ≤ F := le_trans (b := d / t^2) ((le_div_iff₀ (sq_pos_of_pos htp)).mpr (by simpa)) hFlet S := searchSched j h4obtain ⟨a,s,h1,h2,h3⟩ := compress_arrays tag hi q hq c hc hc0 Q χ hn hrq hlogF (long j) (20*D*d) he (by unfold long; positivity)(sLen j) N (cap j) (pow_pos_nat _) hsm hT S (stepLow j) (stepHigh j) (stepRows j)(byintro i _have hh := hil iexact ⟨hh.1,hh.2.1,pow_pos_nat _,pow_pos_nat _,hh.2.2.1.le,hh.2.2.2.1⟩)(by intro i k hik hk; exact horder i k hik hk) h (by dsimp only [d] at *; linarith)(fun i _ => pow_pos_nat _) (byhave hn' : N ≤ 2^j := by unfold N sSeg; apply Nat.pow_le_pow_right <;> omegahave hErr := approx_error (by linarith : (1:ℝ) ≤ t) htj hd(show (0:ℝ) < cap j by exact_mod_cast pow_pos_nat (capE j))hD hF hFd ht.1 (hb.trans hb') ht.2intro i _let l := stepLow j i; let r := stepRows j ihave hlo := hil ihave hjt : 2^j ≤ 2^(2*j) := Nat.pow_le_pow_right (by omega) (by omega)let ε := 2*(cap j:ℝ)*√F/Nhave hε : 0 ≤ ε := by unfold ε; positivityhave hz (k : ℕ) (hh : k ≤ 2^j) : ε * lnS (Fin k) tag ≤ F :=(mul_le_mul_of_nonneg_left (hv k (hh.trans hjt)) hε).trans hErrhave hp : 0 < r := pow_pos_nat _have hl : 0 < l := pow_pos_nat _have hqr : 2*r*l=N := hlo.2.2.1have hiN : r*l ≤ N := by nlinarithhave hiR : r ≤ N := le_trans (Nat.le_mul_of_pos_right r hl) hiNhave HR := hz (r*l) (hiN.trans hn')refine ⟨hz _ (hlo.2.1.trans hmd),?_⟩have H1 := log_ticket r j hp (hiR.trans hn') (by omega)have hb'' : (base j:ℝ) ≤ l := by exact_mod_cast hlo.2.2.2.2have hlB : 4*(j:ℝ)*t^2 ≤ l := byapply le_trans _ (hb.trans hb'')calc_ ≤ 4*((j:ℝ)*(j:ℝ)^2) := by rw [mul_assoc]; gcongr_ ≤ _ := byrw [show (j:ℝ)*(j:ℝ)^2=(j:ℝ)^3 by ring]have HH : (j:ℝ)^3 ≤ (j:ℝ)^16 := pow_le_pow_right₀ hj1 (by norm_num)gcongr; linarithhave hND : (N:ℝ) ≤ d := by unfold d height; exact_mod_cast hn'have hRN : (r:ℝ)*l ≤ N := by exact_mod_cast hiNhave hrD : (r:ℝ)*(4*(j:ℝ)) ≤ F := byapply le_trans _ hFapply (le_div_iff₀ (by positivity : 0 < t^2)).mprrw [mul_assoc]exact (mul_le_mul_of_nonneg_left hlB (by positivity)).trans (hRN.trans hND)change log _+(r:ℝ)+ 2 * ε*lnS (Fin (r*l)) tag ≤ _nlinarith [show (0:ℝ) ≤ r by positivity])exact ⟨a,s,h1,h2.trans(size_bound (by linarith : (1:ℝ) ≤ t) hd hpN hD (by linarith) hFd ht.1 hh (searchSched_loss _ h4)),h3⟩end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222import OAI.Analysis.FourierLLogL.Compress.Theoremimport OAI.Analysis.FourierLLogL.Compress.Params/-! # The compression lemma, asymptotic scales -/open Set Function Filteropen scoped Topology BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Law Paramslemma log_ticket (r j : ℕ) (hr : 1 ≤ r) (h : r ≤ 2^j) (hj : 1 ≤ j) :log (Fintype.card (Ticket r (2*r)) : ℝ) ≤ 1 + r*(2*(j:ℝ)) := byhave hp : 0 < (r:ℝ) := by exact_mod_cast hrhave hcard : Fintype.card (Fin r ↪ Fin (2*r)) ≤ (2*r)^r := byhave hi := Fintype.card_le_of_injective(fun (e : Fin r ↪ Fin (2*r)) => (e : Fin r → Fin (2*r))) (by intro a b hab; ext i : 1; exact congrFun hab i)simpa using hihave hl2 := log_le_sub_one_of_pos (show (0:ℝ)<2 by norm_num)have hx : log (2*(r:ℝ)) ≤ 2*(j:ℝ) := byrw [log_mul (by norm_num) hp.ne']have h1 := Real.log_le_log hp (show (r:ℝ) ≤ 2^j by exact_mod_cast h)rw [log_pow] at h1have hJ : (1:ℝ) ≤ j := by exact_mod_cast hjnlinarithunfold Ticketrw [Fintype.card_option]have ht : 0 < ((Fintype.card (Fin r ↪ Fin (2*r)) + 1:ℕ):ℝ) := by positivityapply le_trans (Real.log_le_log ht (y:=2*(2*(r:ℝ))^r) ?_) ?_· have h1 : Fintype.card (Fin r ↪ Fin (2*r)) + 1 ≤ 2*(2*r)^r := byhave hp : 0 < (2*r)^r := pow_pos (by omega) _omegaexact_mod_cast h1rw [Real.log_mul (by norm_num) (by positivity),Real.log_pow]nlinarithprivate lemma approx_error {d h F D T m j : ℝ} (hh : 1 ≤ h) (hj : h ≤ j)(hd : 0 < d) (hm : 0 < m) (hD : 1 ≤ D)(hF : d/h^2 ≤ F) (hFd : F ≤ D*d)(Ht : d=4*T*h^6)(H : 1024*D*j^16 ≤ m) (H' : m^4 ≤ d) :(2*m*√F/T)*(d*j^2) ≤ F := byhave hh' : 0 < h := by linarithhave hF' : 0 < F := lt_of_lt_of_le (by positivity) hFhave hp : 0 < T := pos_of_mul_pos_left (show 0 < T*(4*h^6) bycalc 0 < d := hd_ = T*(4*h^6) := by rw [Ht]; ring) (by positivity)have hw : 8*D*(j^2*h^8) ≤ m := byapply le_trans _ Hhave hj1 : 1 ≤ j := hh.trans hjcalc_ ≤ 8*D*(j^2*j^8) := by gcongr_ ≤ 1024*D*j^16 := byhave HH : j^10 ≤ j^16 := pow_le_pow_right₀ hj1 (by omega)rw [← pow_add]; gcongr; norm_numhave hsr : √F ≤ D*√d := byhave Hx := sq_sqrt hF'.lehave Hy := sq_sqrt hd.lehave Hh : D*d ≤ (D*√d)^2 := byrw [mul_pow,Hy]; gcongr; nlinarithnlinarith [hFd.trans Hh,sqrt_nonneg F, show 0 ≤ D*√d by positivity]have hQ : m^2 ≤ √d := byhave Ht := sq_sqrt hd.lenlinarith [show m^4=(m^2)^2 by ring,sqrt_nonneg d,sq_nonneg (m^2-√d)]have hz : 8*m*√F*j^2*h^8 ≤ d := bycalc_ ≤ m * √d * (8*D*(j^2*h^8)) := bycalc_ ≤ 8*m*(D*√d)*j^2*h^8 := by gcongr_ = _ := by ring_ ≤ m*√d*m := mul_le_mul_of_nonneg_left hw (by positivity)_ = m^2*√d := by ring_ ≤ √d*√d := mul_le_mul_of_nonneg_right hQ (sqrt_nonneg _)_ = d := by rw [← sq,sq_sqrt hd.le]apply le_trans (b:=d/h^2) _ hFapply (le_div_iff₀ (pow_pos hh' 2)).mprhave hle : 2*m*√F*j^2*h^2 ≤ T := byrw [Ht] at hzrefine le_of_mul_le_mul_right ?_ (show 0 < 4*h^6 by positivity)calc_ = 8*m*√F*j^2*h^8 := by ring_ ≤ 4*T*h^6 := hz_ = T*(4*h^6) := by ringcalc_ = (2*m*√F*j^2*h^2)/T*d := by ring_ ≤ 1*d := mul_le_mul_of_nonneg_right ((div_le_one hp).mpr hle) hd.le_ = d := one_mul dprivate lemma size_bound {d h F D T a : ℝ} (hh : 1 ≤ h) (hd : 0 < d) (hT : 0 < T)(hD : 1 ≤ D) (hp : 0 < F) (hF : F ≤ D*d)(Ht : d=4*T*h^6)(H : D*h^8 ≤ d) (ha : a ≤ 66/h^2) :8*(3*(F/T)+a*(20*D*d)*(20*D*d)/F)+2 ≤ 300000*D^2*d^2/(F*h^2) := byhave hh' : 0 < h := by linarithhave hc : 0 < 20*D*d := by positivityapply (le_div_iff₀ (by positivity : 0 < F*h^2)).mprlet x := D^2*d^2have hx : 0 ≤ x := by unfold x; positivityhave hF1 : F^2 ≤ x := by unfold x; rw [← mul_pow]; gcongrhave hT1 : h^2 ≤ 4*T := byhave H1 : h^8 ≤ d := le_trans (le_mul_of_one_le_left (by positivity) hD) Hrw [Ht,show h^8=h^2*h^6 by ring] at H1exact le_of_mul_le_mul_right H1 (by positivity)have he1 : F/T*(F*h^2) ≤ 4*x := calc_ ≤ F/T*(F*(4*T)) := by gcongr_ = 4*F^2 := by field_simp_ ≤ 4*x := by gcongrhave he2 : a*(20*D*d)*(20*D*d)/F*(F*h^2) ≤ (66*400)*x := bycalc_ ≤ (66/h^2)*(20*D*d)*(20*D*d)/F*(F*h^2) := by gcongr_ = _ := by unfold x; field_simp; ringhave HH : h^2 ≤ h^8 := pow_le_pow_right₀ hh (by norm_num)have he3 : F*h^2 ≤ x := byhave h1 : h^8 ≤ d := le_trans (le_mul_of_one_le_left (by positivity) hD) Hcalc_ ≤ (D*d)*(D*d) := by gcongr; nlinarith_ = _ := by unfold x; ringcalc_ = 24*(F/T*(F*h^2))+8*(a*(20*D*d)*(20*D*d)/F*(F*h^2))+2*(F*h^2) := by ring_ ≤ 300000*x := by linarith_ = _ := by unfold x; ring/-- Compression at the scales in terms of d=2^j. -/theorem entropy_compression (D : ℝ) (hD : 1 ≤ D) :∀ᶠ j : ℕ in atTop, ∀ (A G Θ : Type)(_ : Fintype A) (_ : Fintype G) (_ : Fintype Θ) (_ : Nonempty A)(_ : DecidableEq G) (_ : AddCommGroup G)(tag : A → G), Injective tag → ∀ (q : Law G), (∀ x, 0 < q x) →∀ (c : G → ℝ), (∀ x, 0 ≤ c x) → c 0=0 →∀ (Q : Law Θ) (χ : Θ → AddChar G ℂ),(∀ t x, ‖χ t x‖=1) →(∀ g, (↑(exp (-c g)):ℂ)=Q.Cx (fun t => χ t g)) →(∀ g, -log (q g) = -log (q 0) + c g) →-log (q 0) ≤ D*height j →(∀ n : ℕ, n ≤ 2^(2*j) → lnS (Fin n) tag ≤ height j * j^2) →∀ F : ℝ, height j/(slow j:ℝ)^2 ≤ F → F ≤ D*height j →(∀ p : Law A, exp (-F) ≤ heatMoment (Fin (sLen j)) p tag c) →∃ (a : A) (s : Finset A), s.Nonempty ∧log (Fintype.card A)-log (s.card:ℝ) ≤300000*D^2*(height j)^2/(F*(slow j:ℝ)^2) ∧small_defects tag χ Q (long j) s a (350*F) := byfilter_upwards [array_spec,big_t_real,below_base 16 (1024*D),slow_le_j,slow_tendsto.eventually (eventually_ge_atTop 4),t_expr] with j hs ht hb hj h4 hjtintro A G Θ _ _ _ _ _ _ tag hi q hq c hc hc0 Q χ hn hrq hlog hq0 hv F hF hFd hlet d := height j; let t : ℝ := slow jhave h4' : 4 ≤ t := by unfold t; exact_mod_cast h4have htj : t ≤ j := by unfold t; exact_mod_cast hjhave hd : 0 < d := by unfold d height; positivitylet N := sSeg jhave hpN : (0:ℝ) < N := byunfold N; exact_mod_cast pow_pos_nat (j-6*ell j-2)obtain ⟨hT,hsm,hmd,hil,horder⟩ := hschange d=4*N*t^6 ∧ _ at hthave hb' : (base j:ℝ) ≤ cap j := by exact_mod_cast base_le_cap jhave hj1 : (1:ℝ) ≤ (j:ℝ) := by linarithhave hh : D*t^8 ≤ d := byhave h1 : (cap j:ℝ) ≤ d := by unfold d height; exact_mod_cast hmdcalc_ ≤ 1024*D*(j:ℝ)^16 := byhave hx : t^8 ≤ (j:ℝ)^16 := le_trans (pow_le_pow_left₀ (by linarith) htj _) (pow_le_pow_right₀ hj1 (by norm_num))gcongr; nlinarith_ ≤ _ := hb.trans (hb'.trans h1)have h44 : t^2 ≤ d := bycalct^2 ≤ t^8 := pow_le_pow_right₀ (by linarith) (by norm_num)_ ≤ _ := le_trans (le_mul_of_one_le_left (by positivity) hD) hhhave htp : 0 < t := by linarithhave he : 1 ≤ F := le_trans (b := d / t^2) ((le_div_iff₀ (sq_pos_of_pos htp)).mpr (by simpa)) hFlet S := searchSched j h4obtain ⟨a,s,h1,h2,h3⟩ := compress_arrays tag hi q hq c hc hc0 Q χ hn hrq hlogF (long j) (20*D*d) he (by unfold long; positivity)(sLen j) N (cap j) (pow_pos_nat _) hsm hT S (stepLow j) (stepHigh j) (stepRows j)(byintro i _have hh := hil iexact ⟨hh.1,hh.2.1,pow_pos_nat _,pow_pos_nat _,hh.2.2.1.le,hh.2.2.2.1⟩)(by intro i k hik hk; exact horder i k hik hk) h (by dsimp only [d] at *; linarith)(fun i _ => pow_pos_nat _) (byhave hn' : N ≤ 2^j := by unfold N sSeg; apply Nat.pow_le_pow_right <;> omegahave hErr := approx_error (by linarith : (1:ℝ) ≤ t) htj hd(show (0:ℝ) < cap j by exact_mod_cast pow_pos_nat (capE j))hD hF hFd ht.1 (hb.trans hb') ht.2intro i _let l := stepLow j i; let r := stepRows j ihave hlo := hil ihave hjt : 2^j ≤ 2^(2*j) := Nat.pow_le_pow_right (by omega) (by omega)let ε := 2*(cap j:ℝ)*√F/Nhave hε : 0 ≤ ε := by unfold ε; positivityhave hz (k : ℕ) (hh : k ≤ 2^j) : ε * lnS (Fin k) tag ≤ F :=(mul_le_mul_of_nonneg_left (hv k (hh.trans hjt)) hε).trans hErrhave hp : 0 < r := pow_pos_nat _have hl : 0 < l := pow_pos_nat _have hqr : 2*r*l=N := hlo.2.2.1have hiN : r*l ≤ N := by nlinarithhave hiR : r ≤ N := le_trans (Nat.le_mul_of_pos_right r hl) hiNhave HR := hz (r*l) (hiN.trans hn')refine ⟨hz _ (hlo.2.1.trans hmd),?_⟩have H1 := log_ticket r j hp (hiR.trans hn') (by omega)have hb'' : (base j:ℝ) ≤ l := by exact_mod_cast hlo.2.2.2.2have hlB : 4*(j:ℝ)*t^2 ≤ l := byapply le_trans _ (hb.trans hb'')calc_ ≤ 4*((j:ℝ)*(j:ℝ)^2) := by rw [mul_assoc]; gcongr_ ≤ _ := byrw [show (j:ℝ)*(j:ℝ)^2=(j:ℝ)^3 by ring]have HH : (j:ℝ)^3 ≤ (j:ℝ)^16 := pow_le_pow_right₀ hj1 (by norm_num)gcongr; linarithhave hND : (N:ℝ) ≤ d := by unfold d height; exact_mod_cast hn'have hRN : (r:ℝ)*l ≤ N := by exact_mod_cast hiNhave hrD : (r:ℝ)*(4*(j:ℝ)) ≤ F := byapply le_trans _ hFapply (le_div_iff₀ (by positivity : 0 < t^2)).mprrw [mul_assoc]exact (mul_le_mul_of_nonneg_left hlB (by positivity)).trans (hRN.trans hND)change log _+(r:ℝ)+ 2 * ε*lnS (Fin (r*l)) tag ≤ _nlinarith [show (0:ℝ) ≤ r by positivity])exact ⟨a,s,h1,h2.trans(size_bound (by linarith : (1:ℝ) ≤ t) hd hpN hD (by linarith) hFd ht.1 hh (searchSched_loss _ h4)),h3⟩end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170import OAI.Analysis.FourierLLogL.Compress.Observe/-! # Partial refinements -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {V W Y Ω G A : Type} [Fintype A] [Fintype V] [Fintype W] [Fintype G][Fintype Y] [Fintype Ω] [AddCommGroup G]lemma mix_send (P Q : Law Ω) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1)(X : Ω → A) :(mixture P Q t h0 h1).send X = mixture (P.send X) (Q.send X) t h0 h1 := byapply ext_of_Ex; intro fsimp_rw [mixture_Ex,Ex_send,mixture_Ex]lemma marked_cond (P Q : Law Ω) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1)(X : Ω → A) (W : Ω → V) (f : V → Bool)(hP : ∀ x, 0 < P x → f (W x) = true)(hQ : ∀ x, 0 < Q x → f (W x) = false) :(mixture P Q t h0 h1).Hcond X W =t*P.Hcond X W+(1-t)*Q.Hcond X W := byrw [mixture_eq_through]let B := coinP t h0 h1let K (b : Bool) := if b then P else Qlet R := withNext B Kchange (through B K).Hcond X W = _have hy (z : Bool × Ω) (hz : 0 < R z) : f (W z.2) = z.1 := byobtain ⟨b,x⟩ := zchange 0 < B b * K b x at hzhave hx : 0 < K b x := pos_of_mul_pos_right hz (B.nonneg b)cases b· exact hQ x hx· exact hP x hxlet X' (z : Bool×Ω) := X z.2let W' (z : Bool×Ω) := W z.2rw [← send_snd_withNext B K,Hcond_send]have HH : R.Hcond X' W' = R.Hcond X' (fun z => (z.1, W' z)) := bycalc_ = R.Hcond X' (fun z => (f (W' z),W' z)) :=Hcond_right_partition _ _ (fun _ _ => by simp; grind)_ = _ := Hcond_congr (X:=X') (fun _ _ => rfl)(W:=fun z => (f (W' z),W' z)) fun z hz => by rw [show _=z.1 from hy z hz]have H :=Hcond_withNext B K (fun _ => X) (fun _ => W)change R.Hcond X' W' = _rw [HH,show R.Hcond X' _ = _ from H,coinP_Ex]rfldef retag (f : V → W) (x : A×V) : A×W := (x.1,f x.2)omit [Fintype A] [Fintype V] [Fintype W] inlemma retag_inj (f : V → W) (hf : Injective f) :Injective (retag (A:=A) f) := byrintro ⟨x,a⟩ ⟨y,b⟩ hsimpa only [retag,Prod.mk.injEq,hf.eq_iff] using habbrev blend (P Q : Labelled A) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) : Labelled A :={ obs := P.obs ⊕ Q.obslaw := mixture (P.law.send (retag Sum.inl)) (Q.law.send (retag Sum.inr)) t h0 h1 }lemma blend_refines (P Q R : Labelled A) (hp : refines P R) (hq : refines Q R)(t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) : refines (blend P Q t h0 h1) R := byobtain ⟨u,hu⟩ := hp; obtain ⟨v,hv⟩ := hqrefine ⟨Sum.elim u v,?_⟩dsimp only [blend]rw [mix_send,send_send,send_send]apply Law.ext; intro arw [mixture_apply]dsimp only [retag,Sum.elim_inl,Sum.elim_inr]rw [hu,hv]; ringlemma retag_Hcond (P : Law (A×V)) (f : V→W) (h : Injective f) :(P.send (retag f)).Hcond (fun x => x) Prod.snd = P.Hcond (fun x => x) Prod.snd := byrw [full_pair,full_pair,Hcond_send]apply Hcond_right_partitionexact fun _ _ => h.eq_ifflemma blend_H (P Q : Labelled A) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :(blend P Q t h0 h1).law.Hcond (fun a => a) Prod.snd =t*P.law.Hcond (fun a => a) Prod.snd+(1-t)*Q.law.Hcond (fun a => a) Prod.snd := bydsimp only [blend]let K := Sum.elim (fun _ : P.obs => true) (fun _ : Q.obs => false)rw [marked_cond _ _ t h0 h1 _ _ K, retag_Hcond _ (Sum.inl : P.obs → P.obs ⊕ Q.obs)Sum.inl_injective,retag_Hcond _ (Sum.inr : Q.obs → P.obs ⊕ Q.obs) Sum.inr_injective]all_goalsintro x hxobtain ⟨y,rfl,_⟩ := (send_pos_iff _ _ _).mp hxrfldef upRows (n : ℕ) (f : V→W) (x : WordSample n (A×V) Unit) :WordSample n (A×W) Unit := (ctxt (retag f) Prod.fst x, x.2)def packedH (n : ℕ) (tag : A→G) (W : Type) [Fintype W] (x : WordSample n (A×W) Unit) :=(ans (tag ∘ Prod.fst) Prod.fst (fun _ => 0) x,ctxt Prod.snd Prod.fst x)lemma retag_trial (n : ℕ) (tag : A → G) (P : Law (WordSample n (A×V) Unit))(f : V → W) (h : Injective f) :(P.send (upRows n f)).Hcond Prod.fst (packedH n tag W) =P.Hcond Prod.fst (packedH n tag V) := byrw [Hcond_send]have hc (x y : WordSample n (A×V) Unit) :packedH n tag W (upRows n f x) = packedH n tag W (upRows n f y) ↔packedH n tag V x = packedH n tag V y := bysimp only [packedH,upRows,ctxt,ans,tot,comp_apply,retag, Prod.mk.injEq,funext_iff,h.eq_iff]unfold Hcondcongr 1· refine H_partition _ fun x y => ?_have heq : (upRows n f x).1=(upRows n f y).1 ↔ x.1=y.1 := bysimp only [funext_iff,upRows,ctxt,(retag_inj f h).eq_iff]rw [show (Prod.fst x) = x.1 from rfl]constructor· intro hhreplace hh := Prod.mk.inj hhexact Prod.ext (heq.mp hh.1) ((hc x y).mp hh.2)· intro hhreplace hh := Prod.mk.inj hhexact Prod.ext (heq.mpr hh.1) ((hc x y).mpr hh.2)· exact H_partition _ hclemma retag_trial_rows (n : ℕ) (p : Law (A × V)) (P : Law (WordSample n (A × V) Unit))(h : hasRows p P Prod.fst) (f : V → W) :hasRows (p.send (retag f)) (P.send (upRows n f)) Prod.fst := byintro i; rw [← h i,send_send,send_send]; rfllemma exact_rent (n : ℕ) (S : Labelled A) (tag : A → G)(P : Law (WordSample n (A×S.obs) Unit)) (h : hasRows S.law P Prod.fst) :rent (tag ∘ Prod.fst) Prod.snd (fun _ : Unit => (0:G)) (fun _ => 0) P Prod.fst Prod.snd =(n:ℝ) * S.law.Hcond (fun a => a) Prod.snd - P.Hcond Prod.fst (packedH n tag _) := byrw [rent,rent_first h, Fintype.card_fin]rw [Ex_const,add_zero]; rfllemma blend_I (tag : A → G) (P Q : Labelled A) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1)(n : ℕ) : fundI tag (blend P Q t h0 h1) n ≤ t*fundI tag P n+(1-t)*fundI tag Q n := bylet u0 (_ : Unit) := (0:G)let c0 (_ : Unit) := (0:ℝ)obtain ⟨R,hR,eR⟩ := (opt_spec n P.law (tag ∘ Prod.fst) Prod.snd u0 c0).1obtain ⟨S,hS,eS⟩ := (opt_spec n Q.law (tag ∘ Prod.fst) Prod.snd u0 c0).1let B := blend P Q t h0 h1let p := (Sum.inl : P.obs → P.obs ⊕ Q.obs)let q := (Sum.inr : Q.obs → P.obs ⊕ Q.obs)let T := mixture (R.send (upRows n p)) (S.send (upRows n q)) t h0 h1have hT : hasRows (blend P Q t h0 h1).law T Prod.fst := byintro iunfold Trw [mix_send, retag_trial_rows n _ R hR p i, retag_trial_rows n _ S hS q i]apply le_trans (opt_le_rent (tag ∘ Prod.fst) Prod.snd u0 c0 _ T _ Prod.snd hT)change _ ≤ t*opt n P.law _ _ u0 c0+(1-t)*opt n Q.law _ _ u0 c0rw [← eR,← eS]dsimp only [u0,c0]rw [exact_rent n (blend P Q t h0 h1) tag T hT, exact_rent n P tag R hR,exact_rent n Q tag S hS]have hp := Hcond_mixture_ge (R.send (upRows n p)) (S.send (upRows n q)) t h0 h1Prod.fst (packedH n tag _)rw [retag_trial n tag R p Sum.inl_injective, retag_trial n tag S q Sum.inr_injective] at hprw [blend_H]unfold Tlinarithlemma blend_G1 (tag : A→G) (hi : Injective tag) (P Q : Labelled A)(t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :fundG tag (blend P Q t h0 h1) 1 = t*fundG tag P 1+(1-t)*fundG tag Q 1 := byrw [I_single tag hi, I_single tag hi, I_single tag hi]; exact blend_H P Q t h0 h1end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170import OAI.Analysis.FourierLLogL.Compress.Observe/-! # Partial refinements -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {V W Y Ω G A : Type} [Fintype A] [Fintype V] [Fintype W] [Fintype G][Fintype Y] [Fintype Ω] [AddCommGroup G]lemma mix_send (P Q : Law Ω) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1)(X : Ω → A) :(mixture P Q t h0 h1).send X = mixture (P.send X) (Q.send X) t h0 h1 := byapply ext_of_Ex; intro fsimp_rw [mixture_Ex,Ex_send,mixture_Ex]lemma marked_cond (P Q : Law Ω) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1)(X : Ω → A) (W : Ω → V) (f : V → Bool)(hP : ∀ x, 0 < P x → f (W x) = true)(hQ : ∀ x, 0 < Q x → f (W x) = false) :(mixture P Q t h0 h1).Hcond X W =t*P.Hcond X W+(1-t)*Q.Hcond X W := byrw [mixture_eq_through]let B := coinP t h0 h1let K (b : Bool) := if b then P else Qlet R := withNext B Kchange (through B K).Hcond X W = _have hy (z : Bool × Ω) (hz : 0 < R z) : f (W z.2) = z.1 := byobtain ⟨b,x⟩ := zchange 0 < B b * K b x at hzhave hx : 0 < K b x := pos_of_mul_pos_right hz (B.nonneg b)cases b· exact hQ x hx· exact hP x hxlet X' (z : Bool×Ω) := X z.2let W' (z : Bool×Ω) := W z.2rw [← send_snd_withNext B K,Hcond_send]have HH : R.Hcond X' W' = R.Hcond X' (fun z => (z.1, W' z)) := bycalc_ = R.Hcond X' (fun z => (f (W' z),W' z)) :=Hcond_right_partition _ _ (fun _ _ => by simp; grind)_ = _ := Hcond_congr (X:=X') (fun _ _ => rfl)(W:=fun z => (f (W' z),W' z)) fun z hz => by rw [show _=z.1 from hy z hz]have H :=Hcond_withNext B K (fun _ => X) (fun _ => W)change R.Hcond X' W' = _rw [HH,show R.Hcond X' _ = _ from H,coinP_Ex]rfldef retag (f : V → W) (x : A×V) : A×W := (x.1,f x.2)omit [Fintype A] [Fintype V] [Fintype W] inlemma retag_inj (f : V → W) (hf : Injective f) :Injective (retag (A:=A) f) := byrintro ⟨x,a⟩ ⟨y,b⟩ hsimpa only [retag,Prod.mk.injEq,hf.eq_iff] using habbrev blend (P Q : Labelled A) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) : Labelled A :={ obs := P.obs ⊕ Q.obslaw := mixture (P.law.send (retag Sum.inl)) (Q.law.send (retag Sum.inr)) t h0 h1 }lemma blend_refines (P Q R : Labelled A) (hp : refines P R) (hq : refines Q R)(t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) : refines (blend P Q t h0 h1) R := byobtain ⟨u,hu⟩ := hp; obtain ⟨v,hv⟩ := hqrefine ⟨Sum.elim u v,?_⟩dsimp only [blend]rw [mix_send,send_send,send_send]apply Law.ext; intro arw [mixture_apply]dsimp only [retag,Sum.elim_inl,Sum.elim_inr]rw [hu,hv]; ringlemma retag_Hcond (P : Law (A×V)) (f : V→W) (h : Injective f) :(P.send (retag f)).Hcond (fun x => x) Prod.snd = P.Hcond (fun x => x) Prod.snd := byrw [full_pair,full_pair,Hcond_send]apply Hcond_right_partitionexact fun _ _ => h.eq_ifflemma blend_H (P Q : Labelled A) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :(blend P Q t h0 h1).law.Hcond (fun a => a) Prod.snd =t*P.law.Hcond (fun a => a) Prod.snd+(1-t)*Q.law.Hcond (fun a => a) Prod.snd := bydsimp only [blend]let K := Sum.elim (fun _ : P.obs => true) (fun _ : Q.obs => false)rw [marked_cond _ _ t h0 h1 _ _ K, retag_Hcond _ (Sum.inl : P.obs → P.obs ⊕ Q.obs)Sum.inl_injective,retag_Hcond _ (Sum.inr : Q.obs → P.obs ⊕ Q.obs) Sum.inr_injective]all_goalsintro x hxobtain ⟨y,rfl,_⟩ := (send_pos_iff _ _ _).mp hxrfldef upRows (n : ℕ) (f : V→W) (x : WordSample n (A×V) Unit) :WordSample n (A×W) Unit := (ctxt (retag f) Prod.fst x, x.2)def packedH (n : ℕ) (tag : A→G) (W : Type) [Fintype W] (x : WordSample n (A×W) Unit) :=(ans (tag ∘ Prod.fst) Prod.fst (fun _ => 0) x,ctxt Prod.snd Prod.fst x)lemma retag_trial (n : ℕ) (tag : A → G) (P : Law (WordSample n (A×V) Unit))(f : V → W) (h : Injective f) :(P.send (upRows n f)).Hcond Prod.fst (packedH n tag W) =P.Hcond Prod.fst (packedH n tag V) := byrw [Hcond_send]have hc (x y : WordSample n (A×V) Unit) :packedH n tag W (upRows n f x) = packedH n tag W (upRows n f y) ↔packedH n tag V x = packedH n tag V y := bysimp only [packedH,upRows,ctxt,ans,tot,comp_apply,retag, Prod.mk.injEq,funext_iff,h.eq_iff]unfold Hcondcongr 1· refine H_partition _ fun x y => ?_have heq : (upRows n f x).1=(upRows n f y).1 ↔ x.1=y.1 := bysimp only [funext_iff,upRows,ctxt,(retag_inj f h).eq_iff]rw [show (Prod.fst x) = x.1 from rfl]constructor· intro hhreplace hh := Prod.mk.inj hhexact Prod.ext (heq.mp hh.1) ((hc x y).mp hh.2)· intro hhreplace hh := Prod.mk.inj hhexact Prod.ext (heq.mpr hh.1) ((hc x y).mpr hh.2)· exact H_partition _ hclemma retag_trial_rows (n : ℕ) (p : Law (A × V)) (P : Law (WordSample n (A × V) Unit))(h : hasRows p P Prod.fst) (f : V → W) :hasRows (p.send (retag f)) (P.send (upRows n f)) Prod.fst := byintro i; rw [← h i,send_send,send_send]; rfllemma exact_rent (n : ℕ) (S : Labelled A) (tag : A → G)(P : Law (WordSample n (A×S.obs) Unit)) (h : hasRows S.law P Prod.fst) :rent (tag ∘ Prod.fst) Prod.snd (fun _ : Unit => (0:G)) (fun _ => 0) P Prod.fst Prod.snd =(n:ℝ) * S.law.Hcond (fun a => a) Prod.snd - P.Hcond Prod.fst (packedH n tag _) := byrw [rent,rent_first h, Fintype.card_fin]rw [Ex_const,add_zero]; rfllemma blend_I (tag : A → G) (P Q : Labelled A) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1)(n : ℕ) : fundI tag (blend P Q t h0 h1) n ≤ t*fundI tag P n+(1-t)*fundI tag Q n := bylet u0 (_ : Unit) := (0:G)let c0 (_ : Unit) := (0:ℝ)obtain ⟨R,hR,eR⟩ := (opt_spec n P.law (tag ∘ Prod.fst) Prod.snd u0 c0).1obtain ⟨S,hS,eS⟩ := (opt_spec n Q.law (tag ∘ Prod.fst) Prod.snd u0 c0).1let B := blend P Q t h0 h1let p := (Sum.inl : P.obs → P.obs ⊕ Q.obs)let q := (Sum.inr : Q.obs → P.obs ⊕ Q.obs)let T := mixture (R.send (upRows n p)) (S.send (upRows n q)) t h0 h1have hT : hasRows (blend P Q t h0 h1).law T Prod.fst := byintro iunfold Trw [mix_send, retag_trial_rows n _ R hR p i, retag_trial_rows n _ S hS q i]apply le_trans (opt_le_rent (tag ∘ Prod.fst) Prod.snd u0 c0 _ T _ Prod.snd hT)change _ ≤ t*opt n P.law _ _ u0 c0+(1-t)*opt n Q.law _ _ u0 c0rw [← eR,← eS]dsimp only [u0,c0]rw [exact_rent n (blend P Q t h0 h1) tag T hT, exact_rent n P tag R hR,exact_rent n Q tag S hS]have hp := Hcond_mixture_ge (R.send (upRows n p)) (S.send (upRows n q)) t h0 h1Prod.fst (packedH n tag _)rw [retag_trial n tag R p Sum.inl_injective, retag_trial n tag S q Sum.inr_injective] at hprw [blend_H]unfold Tlinarithlemma blend_G1 (tag : A→G) (hi : Injective tag) (P Q : Labelled A)(t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :fundG tag (blend P Q t h0 h1) 1 = t*fundG tag P 1+(1-t)*fundG tag Q 1 := byrw [I_single tag hi, I_single tag hi, I_single tag hi]; exact blend_H P Q t h0 h1end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216import OAI.Analysis.FourierLLogL.Compress.Contextopen Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A G V B Ω I : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype V] [Fintype Ω] [Fintype B] [Fintype I] [DecidableEq I]set_option linter.unusedSectionVars falselemma average_two_below (P : Law Ω) (f g : Ω → ℝ)(h0 : ∀ x, 0 < P x → 0 ≤ f x) (h1 : ∀ x, 0 < P x → 0 ≤ g x)(F G : ℝ) (hp : 0 < F) (hq : 0 < G) (hf : P.Ex f ≤ F) (hg : P.Ex g ≤ G) :∃ x, 0 < P x ∧ f x ≤ 2*F ∧ g x ≤ 2*G := byobtain ⟨x,hx,hh⟩ := P.exists_le_Ex (fun x => F*g x + G*f x)rw [Ex_add,Ex_lmul,Ex_lmul] at hhhave H : F*g x + G*f x ≤ F*G+G*F := le_trans hh (by gcongr)exact ⟨x,hx,by nlinarith [h1 _ hx],by nlinarith [h0 _ hx]⟩/-- A small noisy cost implies a large heat sum (Gibbs comparison). -/lemma large_heat (P : Law Ω) (q : Law A) (X : Ω → A) (tag : A → G) (U : Ω → G) (c : G → ℝ)(hcov : (P.send X).dominated q) (F : ℝ)(hF : P.Ex (fun x => -log (q (X x))) - P.Hcond X (fun x => tag (X x)+U x)+P.Ex (fun x => c (U x)) ≤ F) :∃ z : G, exp (-F) ≤ q.Ex fun a => exp (-c (z-tag a)) := bylet Z (a : Ω) := tag (X a)+U alet V := P.send Zlet p z := P.after Z zlet g (z : G) :=(p z).Ex (fun x => -log (q (X x))) - (p z).H X + (p z).Ex (fun x => c (U x))have hh : V.Ex g ≤ F := byhave H (f : Ω → ℝ) :V.Ex (fun z => (p z).Ex f) = P.Ex f := after_Ex_sum P Z (fun _ => f)unfold g; rw [Ex_add,Ex_sub,H,H]change _ - (P.send Z).Ex (fun z => (P.after Z z).H X)+_≤ _rw [← Hcond_after]; exact hFobtain ⟨z,hz,hze⟩ := V.exists_le_Ex glet f a := q a* exp (-c (z-tag a))let D := ∑ a, f ahave hf (a) : 0 ≤ f a := mul_nonneg (q.nonneg _) (exp_nonneg _)have hc (a) (ha : 0 < p z a) : 0 < q (X a) := byhave HH := (after_mem (P:=P) (W:=Z) hz).mp haexact hcov _ (P.send_pos X HH.2)have ht : 0 < D := byobtain ⟨x,hx⟩ := q.mem_nonemptyhave h : 0 < f x := mul_pos hx (exp_pos _)exact lt_of_lt_of_le h (Finset.single_le_sum (s:=Finset.univ) (fun a _ => hf a) (Finset.mem_univ _))let Q := proportional f hf hthave he (x) (hx : 0 < p z x) :-log (Q (X x)) = -log (q (X x))+c (U x)+log D := byhave hx' := (after_mem (P:=P) (W:=Z) hz).mp hxhave h : z-tag (X x)=U x := by rw [← hx'.1]; unfold Z; abelchange -log (f _/D) = _rw [log_div (mul_pos (hc _ hx) (exp_pos _)).ne' ht.ne']rw [log_mul (hc _ hx).ne' (exp_pos _).ne',h,log_exp]ringhave hd : ((p z).send X).dominated Q := byintro a haobtain ⟨y,rfl,hy⟩ := (send_pos_iff _ _ _).mp haexact div_pos (mul_pos (hc y hy) (exp_pos _)) hthave HC : (p z).H X ≤ (p z).Ex (fun x => -log (Q (X x))) := byrw [← Ex_send (p z) X (fun x => -log (Q x))]exact sub_nonneg.mp (kl_nonneg hd)have hlin := ((p z).Ex_congr_mem he)rw [hlin,Ex_add,Ex_add,Ex_const] at HChave h1 : -F ≤ log D := byhave hi := hze.trans hhdsimp only [g] at hi; linarithrefine ⟨z,le_trans (Real.exp_le_exp.mpr h1) (Real.exp_log ht).le⟩/-- Stack selection with one coordinate per actual letter. -/lemma stack_select (tag : A → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x)(p : Law (A×V)) (P : Law Ω) (X : Ω → I → A) (W : Ω → I → V) (U : Ω → G)(hp : ∀ i : I, P.send (fun x => (X x i,W x i)) = p)(F D : ℝ) (hF : 0 < F) (hD : 0 < D)[Nonempty I](hs : Fintype.card I * p.Hcond Prod.fst Prod.snd -P.Hcond X (fun x => (ans tag X U x, W x)) + P.Ex (fun x => c (U x)) ≤ F)(hd : log (Fintype.card A) - p.Hcond Prod.fst Prod.snd ≤ D) :∃ (q : I → Law A) (z : G),exp (-(2*F)) ≤ (pack q).Ex (fun x => exp (-c (z-tot tag x))) ∧∑ i, (log (Fintype.card A)- (q i).entropy) ≤ 2*(Fintype.card I*D) := byclassicallet R w := P.after W wlet k v := (p.after Prod.snd v).send Prod.fstlet q (w : I → V) (i : I) : Law A := k (w i)let Z := ans tag X Ulet Y := P.send Whave hval (a : Ω) (ha : 0 < P a) (i : I) : 0 < q (W a) i (X a i) := byhave H0 := P.send_pos (fun a => (X a i,W a i)) harw [hp i] at H0exact (p.after Prod.snd (W a i)).send_pos Prod.fst (p.after_self_pos _ H0)have hdom (w : I → V) (hw : 0 < Y w) :((R w).send X).dominated (pack (q w)) := byintro x hxobtain ⟨a,rfl,ha⟩ := (send_pos_iff _ _ _).mp hxhave H := (after_mem hw).mp harw [pack_pos,← H.1]exact hval a H.2let N := Fintype.card Ilet a (w : I → V) :=(R w).Ex (fun x => -log (pack (q w) (X x))) -(R w).Hcond X Z + (R w).Ex fun x => c (U x)let b (w : I → V) := ∑ i, (log (Fintype.card A) - entropy (q w i))have ha (w) (hw : 0 < Y w) : 0 ≤ a w := byhave hh := kl_nonneg (hdom w hw)unfold kl crossE at hhrw [Ex_send] at hhhave ht := Hcond_le_H (R w) X Zunfold H at htexact add_nonneg (by linarith) (Ex_nonneg (R w) (fun x => hc _))have hb (w : I → V) : 0 ≤ b w :=Finset.sum_nonneg fun i _ => sub_nonneg.mpr (entropy_le_log_card _)have hrow (i : I) (f : (A×V) → ℝ) :P.Ex (fun x => f (X x i,W x i)) = p.Ex f := byrw [← Ex_send P (fun x => (X x i,W x i)), hp i]have hE : Y.Ex a ≤ F := byhave hX : Y.Ex (fun w => (R w).Ex fun x => -log (pack (q w) (X x))) =∑ i : I, p.Hcond Prod.fst Prod.snd := bylet f (w : I → V) (x : Ω) := -log (pack (q w) (X x))rw [show Y.Ex _ = P.Ex _ from P.after_Ex_sum W f]have H1 (x : Ω) (hx : 0 < P x) :f (W x) x = ∑ i, -log (q (W x) i (X x i)) := byunfold f; rw [pack_apply,log_prod,Finset.sum_neg_distrib]exact fun i _ => (hval x hx i).ne'rw [P.Ex_congr_mem H1,Ex_finset_sum,Hcond_log]refine Finset.sum_congr rfl fun i _ => ?_exact hrow i (fun x => -log (k x.2 x.1))have HU : Y.Ex (fun w => (R w).Ex (fun x => c (U x))) = _ :=P.after_Ex_sum W (fun _ x => c (U x))have hz : Y.Ex (fun w => (R w).Hcond X Z) = _ :=(Hcond_after_cond P X Z W).symmunfold arw [Ex_add,Ex_sub,hX,HU,hz,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]exact hshave hB : Y.Ex b ≤ N * D := byhave HH : ∀ i : I, Y.Ex (fun w => entropy (q w i)) = p.Hcond Prod.fst Prod.snd := byintro idsimp only [Y]; rw [Ex_send]rw [Hcond_after,Ex_send]exact hrow i (fun x => entropy (k x.2))unfold bsimp_rw [Ex_finset_sum,Ex_sub,HH,Ex_const,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]exact mul_le_mul_of_nonneg_left hd (by positivity)obtain ⟨w,hw,hw',hw''⟩ :=average_two_below Y a b ha (fun x _ => hb x) F (N*D) hF(mul_pos (by unfold N; positivity) hD) hE hBobtain ⟨z,hz⟩ := large_heat (R w) (pack (q w)) X (tot tag) U c (hdom w hw) (2*F) hw'exact ⟨q w,z,hz,hw''⟩lemma freeze (tag : A → G) (hi : Injective tag) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x)(P : Labelled A) (m r : ℕ) (hm : 0 < m) (hr : 0 < r)(F D : ℝ) (hF : 0 < F) (hD : 0 < D) (hs : fundK tag c P m r ≤ F)(hd : log (Fintype.card A) - fundG tag P 1 ≤ D) :∃ (q : (Fin r×Fin m) → Law A) (z : G),exp (-(2*F)) ≤ (pack q).Ex (fun x => exp (-c (z-tot tag x))) ∧∑ i, (log (Fintype.card A)- (q i).entropy) ≤ 2*((r:ℝ)*m*D) := byhave : NeZero r := ⟨hr.ne'⟩have : NeZero m := ⟨hm.ne'⟩let t := lblSum tag P mlet C := lblCtx P mlet Q := lblP P mobtain ⟨S,hS,he⟩ := (opt_spec r Q t C (fun x => x) c).1let Y := WordSample r (Letters m (A×P.obs)) Glet X (p : Y) (i : Fin r × Fin m) := (p.1 i.1 i.2).1let W (p : Y) (i : Fin r × Fin m) := (p.1 i.1 i.2).2have Hrow (i : Fin r×Fin m) : S.send (fun p => (X p i,W p i)) = P.law := byhave h1 : Q.send (fun x => x i.2) = P.law := marginalPack _ _rw [← h1,← hS i.1,send_send]; rflhave HQ : Q.Hcond (fun x => x) C = m*P.law.Hcond Prod.fst Prod.snd := byhave HH := Hcond_vec_pack (fun _ : Fin m => P.law) (fun _ a => a)(fun _ => Prod.snd)have hi : P.law.Hcond (fun x => x) Prod.snd = P.law.Hcond Prod.fst Prod.snd := byunfold Hcond; congr 1; apply H_partition; simpsimp_rw [hi,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at HHexact HHlet u0 : Y → G := Prod.sndlet s0 (x : Y) := ans t Prod.fst u0 xhave ht0 (x : Y) : s0 x = ans tag X u0 x := byunfold s0 t lblSum ans totsimp only [Fintype.sum_prod_type, Function.comp_apply, X]let w0 (x : Y) := ctxt C Prod.fst xhave h1 : S.Hcond Prod.fst (fun x => (s0 x,w0 x)) =S.Hcond X (fun x => (ans tag X u0 x,W x)) := byunfold Hcondhave h' (x y : Y) : w0 x = w0 y ↔ W x=W y := bysimp only [w0,W,C,ctxt,lblCtx,funext_iff,Prod.forall]congr 1· apply H_partitionintro x ysimp only [Prod.mk.injEq,h',ht0]have hy : x.1=y.1 ↔ X x=X y ∧ W x=W y := bysimp only [X,W,funext_iff,Prod.forall]constructor· intro h; simp [h]· grindtauto· apply H_partition; simp only [Prod.mk.injEq,h',ht0]; tautohave hcost : Fintype.card (Fin r×Fin m)*P.law.Hcond Prod.fst Prod.snd -S.Hcond X (fun x => (ans tag X u0 x,W x))+ S.Ex (fun a => c (u0 a)) ≤ F := byhave HH : rent t C (fun x => x) c S Prod.fst Prod.snd ≤ F := he.le.trans hsunfold rent at HHrw [rent_first hS,HQ] at HHchange _ - S.Hcond Prod.fst (fun x => (s0 x,w0 x))+S.Ex (fun x => c (u0 x)) ≤ F at HHrw [h1] at HHsimp only [Fintype.card_fin,Fintype.card_prod,Nat.cast_mul,mul_assoc] at *exact HHhave Hsel := stack_select tag c hc P.law S X W u0 Hrow F D hF hD hcost(by rwa [fundG_one tag hi] at hd)simpa only [Fintype.card_prod,Fintype.card_fin,Nat.cast_mul] using Hselend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216import OAI.Analysis.FourierLLogL.Compress.Contextopen Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A G V B Ω I : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype V] [Fintype Ω] [Fintype B] [Fintype I] [DecidableEq I]set_option linter.unusedSectionVars falselemma average_two_below (P : Law Ω) (f g : Ω → ℝ)(h0 : ∀ x, 0 < P x → 0 ≤ f x) (h1 : ∀ x, 0 < P x → 0 ≤ g x)(F G : ℝ) (hp : 0 < F) (hq : 0 < G) (hf : P.Ex f ≤ F) (hg : P.Ex g ≤ G) :∃ x, 0 < P x ∧ f x ≤ 2*F ∧ g x ≤ 2*G := byobtain ⟨x,hx,hh⟩ := P.exists_le_Ex (fun x => F*g x + G*f x)rw [Ex_add,Ex_lmul,Ex_lmul] at hhhave H : F*g x + G*f x ≤ F*G+G*F := le_trans hh (by gcongr)exact ⟨x,hx,by nlinarith [h1 _ hx],by nlinarith [h0 _ hx]⟩/-- A small noisy cost implies a large heat sum (Gibbs comparison). -/lemma large_heat (P : Law Ω) (q : Law A) (X : Ω → A) (tag : A → G) (U : Ω → G) (c : G → ℝ)(hcov : (P.send X).dominated q) (F : ℝ)(hF : P.Ex (fun x => -log (q (X x))) - P.Hcond X (fun x => tag (X x)+U x)+P.Ex (fun x => c (U x)) ≤ F) :∃ z : G, exp (-F) ≤ q.Ex fun a => exp (-c (z-tag a)) := bylet Z (a : Ω) := tag (X a)+U alet V := P.send Zlet p z := P.after Z zlet g (z : G) :=(p z).Ex (fun x => -log (q (X x))) - (p z).H X + (p z).Ex (fun x => c (U x))have hh : V.Ex g ≤ F := byhave H (f : Ω → ℝ) :V.Ex (fun z => (p z).Ex f) = P.Ex f := after_Ex_sum P Z (fun _ => f)unfold g; rw [Ex_add,Ex_sub,H,H]change _ - (P.send Z).Ex (fun z => (P.after Z z).H X)+_≤ _rw [← Hcond_after]; exact hFobtain ⟨z,hz,hze⟩ := V.exists_le_Ex glet f a := q a* exp (-c (z-tag a))let D := ∑ a, f ahave hf (a) : 0 ≤ f a := mul_nonneg (q.nonneg _) (exp_nonneg _)have hc (a) (ha : 0 < p z a) : 0 < q (X a) := byhave HH := (after_mem (P:=P) (W:=Z) hz).mp haexact hcov _ (P.send_pos X HH.2)have ht : 0 < D := byobtain ⟨x,hx⟩ := q.mem_nonemptyhave h : 0 < f x := mul_pos hx (exp_pos _)exact lt_of_lt_of_le h (Finset.single_le_sum (s:=Finset.univ) (fun a _ => hf a) (Finset.mem_univ _))let Q := proportional f hf hthave he (x) (hx : 0 < p z x) :-log (Q (X x)) = -log (q (X x))+c (U x)+log D := byhave hx' := (after_mem (P:=P) (W:=Z) hz).mp hxhave h : z-tag (X x)=U x := by rw [← hx'.1]; unfold Z; abelchange -log (f _/D) = _rw [log_div (mul_pos (hc _ hx) (exp_pos _)).ne' ht.ne']rw [log_mul (hc _ hx).ne' (exp_pos _).ne',h,log_exp]ringhave hd : ((p z).send X).dominated Q := byintro a haobtain ⟨y,rfl,hy⟩ := (send_pos_iff _ _ _).mp haexact div_pos (mul_pos (hc y hy) (exp_pos _)) hthave HC : (p z).H X ≤ (p z).Ex (fun x => -log (Q (X x))) := byrw [← Ex_send (p z) X (fun x => -log (Q x))]exact sub_nonneg.mp (kl_nonneg hd)have hlin := ((p z).Ex_congr_mem he)rw [hlin,Ex_add,Ex_add,Ex_const] at HChave h1 : -F ≤ log D := byhave hi := hze.trans hhdsimp only [g] at hi; linarithrefine ⟨z,le_trans (Real.exp_le_exp.mpr h1) (Real.exp_log ht).le⟩/-- Stack selection with one coordinate per actual letter. -/lemma stack_select (tag : A → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x)(p : Law (A×V)) (P : Law Ω) (X : Ω → I → A) (W : Ω → I → V) (U : Ω → G)(hp : ∀ i : I, P.send (fun x => (X x i,W x i)) = p)(F D : ℝ) (hF : 0 < F) (hD : 0 < D)[Nonempty I](hs : Fintype.card I * p.Hcond Prod.fst Prod.snd -P.Hcond X (fun x => (ans tag X U x, W x)) + P.Ex (fun x => c (U x)) ≤ F)(hd : log (Fintype.card A) - p.Hcond Prod.fst Prod.snd ≤ D) :∃ (q : I → Law A) (z : G),exp (-(2*F)) ≤ (pack q).Ex (fun x => exp (-c (z-tot tag x))) ∧∑ i, (log (Fintype.card A)- (q i).entropy) ≤ 2*(Fintype.card I*D) := byclassicallet R w := P.after W wlet k v := (p.after Prod.snd v).send Prod.fstlet q (w : I → V) (i : I) : Law A := k (w i)let Z := ans tag X Ulet Y := P.send Whave hval (a : Ω) (ha : 0 < P a) (i : I) : 0 < q (W a) i (X a i) := byhave H0 := P.send_pos (fun a => (X a i,W a i)) harw [hp i] at H0exact (p.after Prod.snd (W a i)).send_pos Prod.fst (p.after_self_pos _ H0)have hdom (w : I → V) (hw : 0 < Y w) :((R w).send X).dominated (pack (q w)) := byintro x hxobtain ⟨a,rfl,ha⟩ := (send_pos_iff _ _ _).mp hxhave H := (after_mem hw).mp harw [pack_pos,← H.1]exact hval a H.2let N := Fintype.card Ilet a (w : I → V) :=(R w).Ex (fun x => -log (pack (q w) (X x))) -(R w).Hcond X Z + (R w).Ex fun x => c (U x)let b (w : I → V) := ∑ i, (log (Fintype.card A) - entropy (q w i))have ha (w) (hw : 0 < Y w) : 0 ≤ a w := byhave hh := kl_nonneg (hdom w hw)unfold kl crossE at hhrw [Ex_send] at hhhave ht := Hcond_le_H (R w) X Zunfold H at htexact add_nonneg (by linarith) (Ex_nonneg (R w) (fun x => hc _))have hb (w : I → V) : 0 ≤ b w :=Finset.sum_nonneg fun i _ => sub_nonneg.mpr (entropy_le_log_card _)have hrow (i : I) (f : (A×V) → ℝ) :P.Ex (fun x => f (X x i,W x i)) = p.Ex f := byrw [← Ex_send P (fun x => (X x i,W x i)), hp i]have hE : Y.Ex a ≤ F := byhave hX : Y.Ex (fun w => (R w).Ex fun x => -log (pack (q w) (X x))) =∑ i : I, p.Hcond Prod.fst Prod.snd := bylet f (w : I → V) (x : Ω) := -log (pack (q w) (X x))rw [show Y.Ex _ = P.Ex _ from P.after_Ex_sum W f]have H1 (x : Ω) (hx : 0 < P x) :f (W x) x = ∑ i, -log (q (W x) i (X x i)) := byunfold f; rw [pack_apply,log_prod,Finset.sum_neg_distrib]exact fun i _ => (hval x hx i).ne'rw [P.Ex_congr_mem H1,Ex_finset_sum,Hcond_log]refine Finset.sum_congr rfl fun i _ => ?_exact hrow i (fun x => -log (k x.2 x.1))have HU : Y.Ex (fun w => (R w).Ex (fun x => c (U x))) = _ :=P.after_Ex_sum W (fun _ x => c (U x))have hz : Y.Ex (fun w => (R w).Hcond X Z) = _ :=(Hcond_after_cond P X Z W).symmunfold arw [Ex_add,Ex_sub,hX,HU,hz,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]exact hshave hB : Y.Ex b ≤ N * D := byhave HH : ∀ i : I, Y.Ex (fun w => entropy (q w i)) = p.Hcond Prod.fst Prod.snd := byintro idsimp only [Y]; rw [Ex_send]rw [Hcond_after,Ex_send]exact hrow i (fun x => entropy (k x.2))unfold bsimp_rw [Ex_finset_sum,Ex_sub,HH,Ex_const,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]exact mul_le_mul_of_nonneg_left hd (by positivity)obtain ⟨w,hw,hw',hw''⟩ :=average_two_below Y a b ha (fun x _ => hb x) F (N*D) hF(mul_pos (by unfold N; positivity) hD) hE hBobtain ⟨z,hz⟩ := large_heat (R w) (pack (q w)) X (tot tag) U c (hdom w hw) (2*F) hw'exact ⟨q w,z,hz,hw''⟩lemma freeze (tag : A → G) (hi : Injective tag) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x)(P : Labelled A) (m r : ℕ) (hm : 0 < m) (hr : 0 < r)(F D : ℝ) (hF : 0 < F) (hD : 0 < D) (hs : fundK tag c P m r ≤ F)(hd : log (Fintype.card A) - fundG tag P 1 ≤ D) :∃ (q : (Fin r×Fin m) → Law A) (z : G),exp (-(2*F)) ≤ (pack q).Ex (fun x => exp (-c (z-tot tag x))) ∧∑ i, (log (Fintype.card A)- (q i).entropy) ≤ 2*((r:ℝ)*m*D) := byhave : NeZero r := ⟨hr.ne'⟩have : NeZero m := ⟨hm.ne'⟩let t := lblSum tag P mlet C := lblCtx P mlet Q := lblP P mobtain ⟨S,hS,he⟩ := (opt_spec r Q t C (fun x => x) c).1let Y := WordSample r (Letters m (A×P.obs)) Glet X (p : Y) (i : Fin r × Fin m) := (p.1 i.1 i.2).1let W (p : Y) (i : Fin r × Fin m) := (p.1 i.1 i.2).2have Hrow (i : Fin r×Fin m) : S.send (fun p => (X p i,W p i)) = P.law := byhave h1 : Q.send (fun x => x i.2) = P.law := marginalPack _ _rw [← h1,← hS i.1,send_send]; rflhave HQ : Q.Hcond (fun x => x) C = m*P.law.Hcond Prod.fst Prod.snd := byhave HH := Hcond_vec_pack (fun _ : Fin m => P.law) (fun _ a => a)(fun _ => Prod.snd)have hi : P.law.Hcond (fun x => x) Prod.snd = P.law.Hcond Prod.fst Prod.snd := byunfold Hcond; congr 1; apply H_partition; simpsimp_rw [hi,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at HHexact HHlet u0 : Y → G := Prod.sndlet s0 (x : Y) := ans t Prod.fst u0 xhave ht0 (x : Y) : s0 x = ans tag X u0 x := byunfold s0 t lblSum ans totsimp only [Fintype.sum_prod_type, Function.comp_apply, X]let w0 (x : Y) := ctxt C Prod.fst xhave h1 : S.Hcond Prod.fst (fun x => (s0 x,w0 x)) =S.Hcond X (fun x => (ans tag X u0 x,W x)) := byunfold Hcondhave h' (x y : Y) : w0 x = w0 y ↔ W x=W y := bysimp only [w0,W,C,ctxt,lblCtx,funext_iff,Prod.forall]congr 1· apply H_partitionintro x ysimp only [Prod.mk.injEq,h',ht0]have hy : x.1=y.1 ↔ X x=X y ∧ W x=W y := bysimp only [X,W,funext_iff,Prod.forall]constructor· intro h; simp [h]· grindtauto· apply H_partition; simp only [Prod.mk.injEq,h',ht0]; tautohave hcost : Fintype.card (Fin r×Fin m)*P.law.Hcond Prod.fst Prod.snd -S.Hcond X (fun x => (ans tag X u0 x,W x))+ S.Ex (fun a => c (u0 a)) ≤ F := byhave HH : rent t C (fun x => x) c S Prod.fst Prod.snd ≤ F := he.le.trans hsunfold rent at HHrw [rent_first hS,HQ] at HHchange _ - S.Hcond Prod.fst (fun x => (s0 x,w0 x))+S.Ex (fun x => c (u0 x)) ≤ F at HHrw [h1] at HHsimp only [Fintype.card_fin,Fintype.card_prod,Nat.cast_mul,mul_assoc] at *exact HHhave Hsel := stack_select tag c hc P.law S X W u0 Hrow F D hF hD hcost(by rwa [fundG_one tag hi] at hd)simpa only [Fintype.card_prod,Fintype.card_fin,Nat.cast_mul] using Hselend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274import OAI.Analysis.FourierLLogL.Compress.Thinningimport OAI.Analysis.FourierLLogL.Compress.Context/-! # Initial estimates for contextual costs -/open Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A Ω G : Type} [Fintype A] [Fintype Ω] [Fintype G] [AddCommGroup G][DecidableEq G] {n : ℕ}set_option linter.unusedSectionVars falselemma initial_pack (p : Law A) (m : ℕ) :lblP (initial p) m = (iid p m).send(fun x => fun i => (x i,())) := byunfold lblP iid initialexact (sendPack (fun _ => p) (fun _ (x : A) => (x,()))).symmlemma G_initial (tag : A → G) (p : Law A) (m : ℕ) :fundG tag (initial p) m = (iid p m).H (tot tag) := byunfold fundGrw [initial_pack]exact (Hcond_send (iid p m) (fun x i => (x i,()))(lblSum tag (initial p) m) (lblCtx (initial p) m)).trans (Hcond_constant _ _ (fun _ => ()))lemma K_initial (tag : A → G) (c : G → ℝ) (p : Law A) (m r : ℕ) :fundK tag c (initial p) m r = opt r (iid p m) (tot tag)(fun _ => fun _ : Fin m => ()) id c := byunfold fundKrw [initial_pack]exact opt_proj (lblSum tag (initial p) m) (lblCtx (initial p) m) id c(iid p m) (fun x i => (x i,())) rlemma I_initial (tag : A → G) (p : Law A) (r : ℕ) :fundI tag (initial p) r = opt r p tag (fun _ => ()) (fun _ : Unit => (0:G))(fun _ => 0) := byunfold fundI initialexact opt_proj (fun x : A×Unit => tag x.1) Prod.snd _ _ p (fun x => (x,())) rlemma trial_initial {E Z : Type} [Fintype E] [Fintype Z] [Nonempty E](tag : A → G) (p : Law A) (e : E → G) (c : E→ℝ) (z : Z)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → E)(h : hasRows p P X) :rent tag (fun _ => z) e c P X U =(∑ i, P.Ex (fun a => -log (p (X a i)))) -P.Hcond X (ans tag X (fun a => e (U a))) + P.Ex (fun a => c (U a)) := byhave hz (i : Fin n) :P.Hcond (readP X i) ((fun _ => z) ∘ readP X i) =P.Ex (fun a => -log (p (X a i))) := byhave h1 : P.Hcond (readP X i) (fun _ => z) = P.H (readP X i) :=Hcond_constant _ _ _rw [show (fun (_:A) => z) ∘ readP X i = fun _ => z from rfl,h1,H_log,h i]; rflunfold rentsimp_rw [hz]congr 2apply Hcond_right_partitionsimp only [Prod.mk.injEq]; tautolemma K_initial_le (tag : A → G) (c : G → ℝ) (p : Law A) (m r : ℕ)(P : Law Ω) (X : Ω → Letters r (Letters m A)) (U : Ω → G)(h : hasRows (iid p m) P X) :fundK tag c (initial p) m r ≤ bill (tot tag) c (iid p m) P X U := byrw [K_initial]apply le_trans (opt_le_rent _ _ _ _ _ P X U h) (le_of_eq ?_)rw [trial_initial _ _ _ _ _ _ X U h]; rfllemma exact_zero_g {I : Type} [Fintype I] [DecidableEq I](P : Law Ω) (X : Ω → I → A) (tag : A → G) (q : Law A) (h : covered P X q) :bill tag (fun _=>0) q P X (fun _=>0) =(P.send X).kl (pack (fun _ => q)) + P.H (fun a => tot tag (X a)) := byrw [bill_with_entropy h,Hcond_determined (P:=P) (X:=fun _=>0) (W:=X) (fun _ _ _ => rfl)]unfold anssimp_rw [add_zero,Ex_const]ringlemma I_initial_le (tag : A → G) (p : Law A) (r : ℕ)(P : Law Ω) (X : Ω → Letters r A) (hh : hasRows p P X) :fundI tag (initial p) r ≤ (P.send X).kl (iid p r)+P.H (fun a => tot tag (X a)) := byrw [I_initial]apply le_trans (opt_le_rent _ _ _ _ p P X (fun _ => ()) hh)rw [trial_initial _ _ _ _ _ _ X _ hh]change bill tag (fun _=>0) p P X (fun _=>0) ≤ _exact (exact_zero_g P X tag p (kl_covered P X p hh)).le/-- Compare the entropy of the exact sum with the entropy of the perturbed sum and the error. -/lemma sum_entropy {I : Type} [Fintype I] [DecidableEq I](P : Law Ω) (X : Ω → I → A) (U : Ω → G) (tag : A → G)(c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (q : Law A) (hcov : covered P X q)(Q : Law G) (hQ : ∀ y, 0 < Q y) (L : ℝ) (hL : ∀ y, -log (Q y) = L+c y) :let F := bill tag c q P X UP.H (fun a => tot tag (X a)) + (P.send X).kl (pack fun _ => q) ≤ 3*F+2*L := byintro Flet S (a) := tot tag (X a)let Z := ans tag X Uhave hEnt : P.H U ≤ L + P.Ex (fun a => c (U a)) := byhave H := entropy_le_cross_aux (P.send U) Q Q.nonneg Q.total.le fun x _ => hQ xrefine H.trans (le_of_eq ?_)unfold crossEsimp_rw [hL,Ex_send,Ex_add,Ex_const]have hBill : P.Ex (fun a => c (U a)) ≤ F :=((le_add_of_nonneg_left (kl_nonneg (covered_pack hcov))).trans(kl_le_bill hcov tag c hc _))have hH := bill_with_entropy hcov tag c Uchange F = _+(P.H Z-_)+_ at hHhave HI : P.H S ≤ P.H Z + P.H U := byhave H1 : P.H S ≤ P.H (fun a => (U a,Z a)) :=H_le_of_determined _ fun a b hh => byhave hi := Prod.mk.inj hhchange U a=U b ∧ S a+U a=S b+U b at hiexact add_right_cancel (b:=U b) (by rw [← hi.2,hi.1])have H2 := Hcond_le_H P U Zrw [H_pair_chain] at H1; linarithhave hC := Hcond_le_H P U Xchange P.H S + _ ≤ _linarith [P.Ex_nonneg (fun a => hc (U a))]structure Starting (tag : A → G) (c : G → ℝ) (N m : ℕ) (E ε : ℝ) whereq : Law AP : Law (WordSample N A G)sym : exch Pmarg (i : Fin N) : P.send (fun a => a.1 i) = qbound : bill tag c q P Prod.fst Prod.snd ≤ Ewithin : m ≤ Nnear : tv (P.send (prefixB Prod.fst m within)) (iid q m) ≤ εnamespace Startingvariable {tag : A → G} {c : G → ℝ} {N m : ℕ} {E ε : ℝ} (s : Starting tag c N m E ε)lemma cover : covered s.P Prod.fst s.q := kl_covered _ _ _ s.marglemma exact_bound (hc : ∀ x, 0 ≤ c x) (Q : Law G) (hQ : ∀ y, 0 < Q y)(L : ℝ) (hL : ∀ y, -log (Q y)=L+c y)(n : ℕ) (hn : n ≤ N) :let X := prefixB (α:=A) (Ω:=WordSample N A G) Prod.fst n hns.P.H (fun a => tot tag (X a)) + (s.P.send X).kl (iid s.q n) ≤ 3*E+2*L := byintro Xhave h1 := bill_subfamily tag c s.q s.P Prod.fst Prod.snd s.cover(offset 0 n (show 0+n ≤ N by omega)) (offset_injective _ _ _)change bill tag c s.q s.P X Prod.snd ≤ _ at h1refine (sum_entropy s.P X Prod.snd tag c hc s.q (covered_subfamily s.cover _) Q hQ L hL).trans ?_linarith [s.bound]lemma I_upper (hc : ∀ x, 0 ≤ c x) (Q : Law G) (hQ : ∀ y, 0 < Q y)(L : ℝ) (hL : ∀ y,-log (Q y)=L+c y) (n : ℕ) (hn : n ≤ N) :fundI tag (initial s.q) n ≤ 3*E+2*L := byhave h := s.exact_bound hc Q hQ L hL n hnlet X := prefixB (α:=A) (Ω:=WordSample N A G) Prod.fst n hnhave heq : hasRows s.q s.P X := fun i => s.marg (offset 0 n _ i)refine (I_initial_le tag s.q n s.P X heq).trans ?_rw [add_comm]exact hlemma near_small (n : ℕ) (hn : n ≤ m) :tv (s.P.send (prefixB Prod.fst n (hn.trans s.within))) (iid s.q n) ≤ ε := bylet X : Letters m A → Letters n A := fun x i => x (offset 0 n (by omega : 0+n ≤ m) i)have h := tv_data_processing (s.P.send (prefixB Prod.fst m s.within)) (iid s.q m) Xrw [send_send] at hhave hh : (iid s.q m).send X = iid s.q n :=sendPack_embedding _ _ (offset_injective _ _ _)rw [hh] at happly le_trans _ s.nearhave he : (fun a : WordSample N A G => X (prefixB Prod.fst m s.within a)) = prefixB Prod.fst n (hn.trans s.within) := byfunext x ⟨i,hi⟩; simp only [X,prefixB,readBlock,keep,offset,zero_add]rwa [he] at hlemma G_upper (hc : ∀ x, 0 ≤ c x) (Q : Law G) (hQ : ∀ y, 0 < Q y)(L : ℝ) (hL : ∀ y,-log (Q y)=L+c y) (n : ℕ) (hn : n ≤ m) :fundG tag (initial s.q) n ≤ 3*E+2*L+log 2 + ε*lnS (Fin n) tag := byrw [G_initial]let X := prefixB (α:=A) (Ω:= WordSample N A G) Prod.fst n (hn.trans s.within)let Y := tot tag (ι:=Fin n)have H1 : tv ((iid s.q n).send Y) ((s.P.send X).send Y) ≤ ε := byrw [tv_comm]exact (tv_data_processing _ _ Y).trans (s.near_small n hn)have HT := entropy_le_of_tv ((iid s.q n).send Y) ((s.P.send X).send Y)(sums (Fin n) tag) fun x hx => byobtain ⟨a,rfl,_⟩ := (send_pos_iff _ _ _).mp hxexact Finset.mem_image_of_mem _ (Finset.mem_univ _)change _ ≤ (s.P.send X).H Y + (_ + _ * lnS (Fin n) tag) at HThave hk : dominated (s.P.send X) (iid s.q n) := covered_pack(covered_subfamily s.cover _)have he := s.exact_bound hc Q hQ L hL n (hn.trans s.within)change s.P.H _+kl (s.P.send X) _ ≤ _ at heapply HT.transrw [H_send]nlinarith [kl_nonneg hk,lnS_nonneg (Fin n) tag]lemma block_near (n : ℕ) (hn : n ≤ m) (g : Fin n → Fin N) (hg : Injective g) :tv (s.P.send (keep Prod.fst g)) (iid s.q n) ≤ ε := bylet f := offset 0 n (by have := s.within; omega : 0+n ≤ N)have Hf : Injective f := offset_injective _ _ _obtain ⟨e,he⟩ := Equiv.Perm.exists_extending_pair _ _ Hf hghave hh :=congrArg (fun R : Law (WordSample N A G) => R.send (keep Prod.fst f)) (s.sym e)rw [send_send] at hhhave heq : (fun x : WordSample N A G => keep Prod.fst f (appPerm e x)) =keep Prod.fst g := byfunext x i; dsimp only [keep,appPerm]; rw [he i]rw [heq] at hhrw [hh]exact s.near_small n hnlemma block_card (n r : ℕ) :lnS (Fin r) (tot tag (ι:=Fin n)) = lnS (Fin (r*n)) tag := bylet e := finProdFinEquiv (m:=r) (n:=n)have hh (x : Fin (r*n) → A) :tot tag x = tot (tot tag (ι:=Fin n)) (fun i : Fin r => fun j => x (e (i,j))) := byunfold totrw [← Fintype.sum_equiv e (fun i => tag (x (e i))) (fun i => tag (x i)) (fun _ => rfl),Fintype.sum_prod_type]have H : sums (Fin (r*n)) tag = sums (Fin r) (tot tag (ι:=Fin n)) := byext asimp only [sums,Finset.mem_image,Finset.mem_univ,true_and]constructor· rintro ⟨x,rfl⟩exact ⟨_,(hh x).symm⟩· rintro ⟨x,rfl⟩refine ⟨(fun i => x (e.symm i).1 (e.symm i).2),?_⟩rw [hh]; simpsimp only [lnS,H]lemma K_upper (hc : ∀ x, 0 ≤ c x) (hc0 : c 0 = 0)(n r : ℕ) (hr : 0 < r) (hn : n ≤ m) (hn' : 2*r*n ≤ N) :fundK tag c (initial s.q) n r ≤ E + log (Fintype.card (Ticket r (2*r))) +(r + 2*ε*lnS (Fin (r*n)) tag) := bylet g : Fin (2*r) × Fin n → Fin N := offset 0 ((2*r)*n) (by omega) ∘ finProdFinEquivhave hg : Injective g := (offset_injective _ _ _).comp finProdFinEquiv.injectivelet X (x : WordSample N A G) (i : Fin (2*r)) (j : Fin n) := x.1 (g (i,j))let q := iid s.q nhave Hc : covered s.P X q := byintro x hx i; exact (pack_pos _ _).mpr (fun j => s.cover x hx (g (i,j)))have Hm (i : Fin (2*r)) : tv (s.P.send (fun x => X x i)) q ≤ ε :=s.block_near _ hn (fun j => g (i,j)) (fun _ _ h => congrArg Prod.snd (hg h))obtain ⟨Q,hQ,hb⟩ := thinned_bill (tot tag (ι:=Fin n)) c hc hc0 r (2*r) hr rfls.P X Prod.snd q Hc ε Hmlet X' := keep (Prod.fst : WordSample N A G → _) ghave heq : bill (tot tag (ι:=Fin n)) c q s.P X Prod.snd =bill tag c s.q s.P X' Prod.snd := bylet Y := ans tag X' Prod.sndhave hy : ans (tot tag (ι:=Fin n)) X Prod.snd = Y := byext x; unfold Y ans totrw [Fintype.sum_prod_type]; rflunfold billrw [hy, Fintype.sum_prod_type]have h2 : s.P.Hcond X Y = s.P.Hcond X' Y := byunfold Hcondcongr 1refine H_partition _ fun a b => ?_simp only [Prod.mk.injEq,funext_iff,Prod.forall,X,X',keep]have h1 (i : Fin (2*r)) : s.P.Ex (fun a => -log (q (X a i))) =∑ j, s.P.Ex (fun a => -log (s.q (X' a (i,j)))) := byrw [← Ex_finset_sum]apply Ex_congr_memintro x hxchange -log (∏ j : Fin n, s.q (X x i j)) = _rw [log_prod,Finset.sum_neg_distrib]· rfl· exact fun j _ => (s.cover x hx _).ne'rw [h2]simp_rw [h1]rflhave hh := bill_subfamily tag c s.q s.P Prod.fst Prod.snd s.cover g hgchange bill tag c s.q s.P X' Prod.snd ≤ _ at hhrw [heq,block_card] at hbrefine le_trans (K_initial_le tag c s.q n r Q Prod.fst Prod.snd hQ) ?_exact le_trans hb (add_le_add_left (add_le_add_left (hh.trans s.bound) _) _)end Startingend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274import OAI.Analysis.FourierLLogL.Compress.Thinningimport OAI.Analysis.FourierLLogL.Compress.Context/-! # Initial estimates for contextual costs -/open Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A Ω G : Type} [Fintype A] [Fintype Ω] [Fintype G] [AddCommGroup G][DecidableEq G] {n : ℕ}set_option linter.unusedSectionVars falselemma initial_pack (p : Law A) (m : ℕ) :lblP (initial p) m = (iid p m).send(fun x => fun i => (x i,())) := byunfold lblP iid initialexact (sendPack (fun _ => p) (fun _ (x : A) => (x,()))).symmlemma G_initial (tag : A → G) (p : Law A) (m : ℕ) :fundG tag (initial p) m = (iid p m).H (tot tag) := byunfold fundGrw [initial_pack]exact (Hcond_send (iid p m) (fun x i => (x i,()))(lblSum tag (initial p) m) (lblCtx (initial p) m)).trans (Hcond_constant _ _ (fun _ => ()))lemma K_initial (tag : A → G) (c : G → ℝ) (p : Law A) (m r : ℕ) :fundK tag c (initial p) m r = opt r (iid p m) (tot tag)(fun _ => fun _ : Fin m => ()) id c := byunfold fundKrw [initial_pack]exact opt_proj (lblSum tag (initial p) m) (lblCtx (initial p) m) id c(iid p m) (fun x i => (x i,())) rlemma I_initial (tag : A → G) (p : Law A) (r : ℕ) :fundI tag (initial p) r = opt r p tag (fun _ => ()) (fun _ : Unit => (0:G))(fun _ => 0) := byunfold fundI initialexact opt_proj (fun x : A×Unit => tag x.1) Prod.snd _ _ p (fun x => (x,())) rlemma trial_initial {E Z : Type} [Fintype E] [Fintype Z] [Nonempty E](tag : A → G) (p : Law A) (e : E → G) (c : E→ℝ) (z : Z)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → E)(h : hasRows p P X) :rent tag (fun _ => z) e c P X U =(∑ i, P.Ex (fun a => -log (p (X a i)))) -P.Hcond X (ans tag X (fun a => e (U a))) + P.Ex (fun a => c (U a)) := byhave hz (i : Fin n) :P.Hcond (readP X i) ((fun _ => z) ∘ readP X i) =P.Ex (fun a => -log (p (X a i))) := byhave h1 : P.Hcond (readP X i) (fun _ => z) = P.H (readP X i) :=Hcond_constant _ _ _rw [show (fun (_:A) => z) ∘ readP X i = fun _ => z from rfl,h1,H_log,h i]; rflunfold rentsimp_rw [hz]congr 2apply Hcond_right_partitionsimp only [Prod.mk.injEq]; tautolemma K_initial_le (tag : A → G) (c : G → ℝ) (p : Law A) (m r : ℕ)(P : Law Ω) (X : Ω → Letters r (Letters m A)) (U : Ω → G)(h : hasRows (iid p m) P X) :fundK tag c (initial p) m r ≤ bill (tot tag) c (iid p m) P X U := byrw [K_initial]apply le_trans (opt_le_rent _ _ _ _ _ P X U h) (le_of_eq ?_)rw [trial_initial _ _ _ _ _ _ X U h]; rfllemma exact_zero_g {I : Type} [Fintype I] [DecidableEq I](P : Law Ω) (X : Ω → I → A) (tag : A → G) (q : Law A) (h : covered P X q) :bill tag (fun _=>0) q P X (fun _=>0) =(P.send X).kl (pack (fun _ => q)) + P.H (fun a => tot tag (X a)) := byrw [bill_with_entropy h,Hcond_determined (P:=P) (X:=fun _=>0) (W:=X) (fun _ _ _ => rfl)]unfold anssimp_rw [add_zero,Ex_const]ringlemma I_initial_le (tag : A → G) (p : Law A) (r : ℕ)(P : Law Ω) (X : Ω → Letters r A) (hh : hasRows p P X) :fundI tag (initial p) r ≤ (P.send X).kl (iid p r)+P.H (fun a => tot tag (X a)) := byrw [I_initial]apply le_trans (opt_le_rent _ _ _ _ p P X (fun _ => ()) hh)rw [trial_initial _ _ _ _ _ _ X _ hh]change bill tag (fun _=>0) p P X (fun _=>0) ≤ _exact (exact_zero_g P X tag p (kl_covered P X p hh)).le/-- Compare the entropy of the exact sum with the entropy of the perturbed sum and the error. -/lemma sum_entropy {I : Type} [Fintype I] [DecidableEq I](P : Law Ω) (X : Ω → I → A) (U : Ω → G) (tag : A → G)(c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (q : Law A) (hcov : covered P X q)(Q : Law G) (hQ : ∀ y, 0 < Q y) (L : ℝ) (hL : ∀ y, -log (Q y) = L+c y) :let F := bill tag c q P X UP.H (fun a => tot tag (X a)) + (P.send X).kl (pack fun _ => q) ≤ 3*F+2*L := byintro Flet S (a) := tot tag (X a)let Z := ans tag X Uhave hEnt : P.H U ≤ L + P.Ex (fun a => c (U a)) := byhave H := entropy_le_cross_aux (P.send U) Q Q.nonneg Q.total.le fun x _ => hQ xrefine H.trans (le_of_eq ?_)unfold crossEsimp_rw [hL,Ex_send,Ex_add,Ex_const]have hBill : P.Ex (fun a => c (U a)) ≤ F :=((le_add_of_nonneg_left (kl_nonneg (covered_pack hcov))).trans(kl_le_bill hcov tag c hc _))have hH := bill_with_entropy hcov tag c Uchange F = _+(P.H Z-_)+_ at hHhave HI : P.H S ≤ P.H Z + P.H U := byhave H1 : P.H S ≤ P.H (fun a => (U a,Z a)) :=H_le_of_determined _ fun a b hh => byhave hi := Prod.mk.inj hhchange U a=U b ∧ S a+U a=S b+U b at hiexact add_right_cancel (b:=U b) (by rw [← hi.2,hi.1])have H2 := Hcond_le_H P U Zrw [H_pair_chain] at H1; linarithhave hC := Hcond_le_H P U Xchange P.H S + _ ≤ _linarith [P.Ex_nonneg (fun a => hc (U a))]structure Starting (tag : A → G) (c : G → ℝ) (N m : ℕ) (E ε : ℝ) whereq : Law AP : Law (WordSample N A G)sym : exch Pmarg (i : Fin N) : P.send (fun a => a.1 i) = qbound : bill tag c q P Prod.fst Prod.snd ≤ Ewithin : m ≤ Nnear : tv (P.send (prefixB Prod.fst m within)) (iid q m) ≤ εnamespace Startingvariable {tag : A → G} {c : G → ℝ} {N m : ℕ} {E ε : ℝ} (s : Starting tag c N m E ε)lemma cover : covered s.P Prod.fst s.q := kl_covered _ _ _ s.marglemma exact_bound (hc : ∀ x, 0 ≤ c x) (Q : Law G) (hQ : ∀ y, 0 < Q y)(L : ℝ) (hL : ∀ y, -log (Q y)=L+c y)(n : ℕ) (hn : n ≤ N) :let X := prefixB (α:=A) (Ω:=WordSample N A G) Prod.fst n hns.P.H (fun a => tot tag (X a)) + (s.P.send X).kl (iid s.q n) ≤ 3*E+2*L := byintro Xhave h1 := bill_subfamily tag c s.q s.P Prod.fst Prod.snd s.cover(offset 0 n (show 0+n ≤ N by omega)) (offset_injective _ _ _)change bill tag c s.q s.P X Prod.snd ≤ _ at h1refine (sum_entropy s.P X Prod.snd tag c hc s.q (covered_subfamily s.cover _) Q hQ L hL).trans ?_linarith [s.bound]lemma I_upper (hc : ∀ x, 0 ≤ c x) (Q : Law G) (hQ : ∀ y, 0 < Q y)(L : ℝ) (hL : ∀ y,-log (Q y)=L+c y) (n : ℕ) (hn : n ≤ N) :fundI tag (initial s.q) n ≤ 3*E+2*L := byhave h := s.exact_bound hc Q hQ L hL n hnlet X := prefixB (α:=A) (Ω:=WordSample N A G) Prod.fst n hnhave heq : hasRows s.q s.P X := fun i => s.marg (offset 0 n _ i)refine (I_initial_le tag s.q n s.P X heq).trans ?_rw [add_comm]exact hlemma near_small (n : ℕ) (hn : n ≤ m) :tv (s.P.send (prefixB Prod.fst n (hn.trans s.within))) (iid s.q n) ≤ ε := bylet X : Letters m A → Letters n A := fun x i => x (offset 0 n (by omega : 0+n ≤ m) i)have h := tv_data_processing (s.P.send (prefixB Prod.fst m s.within)) (iid s.q m) Xrw [send_send] at hhave hh : (iid s.q m).send X = iid s.q n :=sendPack_embedding _ _ (offset_injective _ _ _)rw [hh] at happly le_trans _ s.nearhave he : (fun a : WordSample N A G => X (prefixB Prod.fst m s.within a)) = prefixB Prod.fst n (hn.trans s.within) := byfunext x ⟨i,hi⟩; simp only [X,prefixB,readBlock,keep,offset,zero_add]rwa [he] at hlemma G_upper (hc : ∀ x, 0 ≤ c x) (Q : Law G) (hQ : ∀ y, 0 < Q y)(L : ℝ) (hL : ∀ y,-log (Q y)=L+c y) (n : ℕ) (hn : n ≤ m) :fundG tag (initial s.q) n ≤ 3*E+2*L+log 2 + ε*lnS (Fin n) tag := byrw [G_initial]let X := prefixB (α:=A) (Ω:= WordSample N A G) Prod.fst n (hn.trans s.within)let Y := tot tag (ι:=Fin n)have H1 : tv ((iid s.q n).send Y) ((s.P.send X).send Y) ≤ ε := byrw [tv_comm]exact (tv_data_processing _ _ Y).trans (s.near_small n hn)have HT := entropy_le_of_tv ((iid s.q n).send Y) ((s.P.send X).send Y)(sums (Fin n) tag) fun x hx => byobtain ⟨a,rfl,_⟩ := (send_pos_iff _ _ _).mp hxexact Finset.mem_image_of_mem _ (Finset.mem_univ _)change _ ≤ (s.P.send X).H Y + (_ + _ * lnS (Fin n) tag) at HThave hk : dominated (s.P.send X) (iid s.q n) := covered_pack(covered_subfamily s.cover _)have he := s.exact_bound hc Q hQ L hL n (hn.trans s.within)change s.P.H _+kl (s.P.send X) _ ≤ _ at heapply HT.transrw [H_send]nlinarith [kl_nonneg hk,lnS_nonneg (Fin n) tag]lemma block_near (n : ℕ) (hn : n ≤ m) (g : Fin n → Fin N) (hg : Injective g) :tv (s.P.send (keep Prod.fst g)) (iid s.q n) ≤ ε := bylet f := offset 0 n (by have := s.within; omega : 0+n ≤ N)have Hf : Injective f := offset_injective _ _ _obtain ⟨e,he⟩ := Equiv.Perm.exists_extending_pair _ _ Hf hghave hh :=congrArg (fun R : Law (WordSample N A G) => R.send (keep Prod.fst f)) (s.sym e)rw [send_send] at hhhave heq : (fun x : WordSample N A G => keep Prod.fst f (appPerm e x)) =keep Prod.fst g := byfunext x i; dsimp only [keep,appPerm]; rw [he i]rw [heq] at hhrw [hh]exact s.near_small n hnlemma block_card (n r : ℕ) :lnS (Fin r) (tot tag (ι:=Fin n)) = lnS (Fin (r*n)) tag := bylet e := finProdFinEquiv (m:=r) (n:=n)have hh (x : Fin (r*n) → A) :tot tag x = tot (tot tag (ι:=Fin n)) (fun i : Fin r => fun j => x (e (i,j))) := byunfold totrw [← Fintype.sum_equiv e (fun i => tag (x (e i))) (fun i => tag (x i)) (fun _ => rfl),Fintype.sum_prod_type]have H : sums (Fin (r*n)) tag = sums (Fin r) (tot tag (ι:=Fin n)) := byext asimp only [sums,Finset.mem_image,Finset.mem_univ,true_and]constructor· rintro ⟨x,rfl⟩exact ⟨_,(hh x).symm⟩· rintro ⟨x,rfl⟩refine ⟨(fun i => x (e.symm i).1 (e.symm i).2),?_⟩rw [hh]; simpsimp only [lnS,H]lemma K_upper (hc : ∀ x, 0 ≤ c x) (hc0 : c 0 = 0)(n r : ℕ) (hr : 0 < r) (hn : n ≤ m) (hn' : 2*r*n ≤ N) :fundK tag c (initial s.q) n r ≤ E + log (Fintype.card (Ticket r (2*r))) +(r + 2*ε*lnS (Fin (r*n)) tag) := bylet g : Fin (2*r) × Fin n → Fin N := offset 0 ((2*r)*n) (by omega) ∘ finProdFinEquivhave hg : Injective g := (offset_injective _ _ _).comp finProdFinEquiv.injectivelet X (x : WordSample N A G) (i : Fin (2*r)) (j : Fin n) := x.1 (g (i,j))let q := iid s.q nhave Hc : covered s.P X q := byintro x hx i; exact (pack_pos _ _).mpr (fun j => s.cover x hx (g (i,j)))have Hm (i : Fin (2*r)) : tv (s.P.send (fun x => X x i)) q ≤ ε :=s.block_near _ hn (fun j => g (i,j)) (fun _ _ h => congrArg Prod.snd (hg h))obtain ⟨Q,hQ,hb⟩ := thinned_bill (tot tag (ι:=Fin n)) c hc hc0 r (2*r) hr rfls.P X Prod.snd q Hc ε Hmlet X' := keep (Prod.fst : WordSample N A G → _) ghave heq : bill (tot tag (ι:=Fin n)) c q s.P X Prod.snd =bill tag c s.q s.P X' Prod.snd := bylet Y := ans tag X' Prod.sndhave hy : ans (tot tag (ι:=Fin n)) X Prod.snd = Y := byext x; unfold Y ans totrw [Fintype.sum_prod_type]; rflunfold billrw [hy, Fintype.sum_prod_type]have h2 : s.P.Hcond X Y = s.P.Hcond X' Y := byunfold Hcondcongr 1refine H_partition _ fun a b => ?_simp only [Prod.mk.injEq,funext_iff,Prod.forall,X,X',keep]have h1 (i : Fin (2*r)) : s.P.Ex (fun a => -log (q (X a i))) =∑ j, s.P.Ex (fun a => -log (s.q (X' a (i,j)))) := byrw [← Ex_finset_sum]apply Ex_congr_memintro x hxchange -log (∏ j : Fin n, s.q (X x i j)) = _rw [log_prod,Finset.sum_neg_distrib]· rfl· exact fun j _ => (s.cover x hx _).ne'rw [h2]simp_rw [h1]rflhave hh := bill_subfamily tag c s.q s.P Prod.fst Prod.snd s.cover g hgchange bill tag c s.q s.P X' Prod.snd ≤ _ at hhrw [heq,block_card] at hbrefine le_trans (K_initial_le tag c s.q n r Q Prod.fst Prod.snd hQ) ?_exact le_trans hb (add_le_add_left (add_le_add_left (hh.trans s.bound) _) _)end Startingend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222import OAI.Analysis.FourierLLogL.Compress.Context/-! # The block observation -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A V G E Ω Ω' : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype Ω] [Fintype Ω']set_option linter.unusedSectionVars falsedef sumLaw (tag : A → G) (P : Labelled A) (m : ℕ) :=(lblP P m).send (fun a => (lblSum tag P m a,lblCtx P m a))lemma full_pair (p : Law (Ω×Ω')) :p.Hcond (fun x => x) Prod.snd = p.Hcond Prod.fst Prod.snd := byunfold Hcondcongr 1exact H_partition _ (by simp)lemma G_as_sum (tag : A → G) (P : Labelled A) (m) :fundG tag P m = (sumLaw tag P m).Hcond (fun x => x) Prod.snd := byrw [full_pair]unfold sumLaw fundG; rw [Hcond_send]lemma I_single (tag : A → G) (hi : Injective tag) (P : Labelled A) :fundG tag P 1 = P.law.Hcond (fun x => x) Prod.snd :=(fundG_one _ hi P).trans (full_pair P.law).symmlemma K_as_sum (tag : A → G) (c : G → ℝ) (P : Labelled A) (m n) :fundK tag c P m n = opt n (sumLaw tag P m) Prod.fst Prod.snd (fun x => x) c :=(opt_proj Prod.fst Prod.snd (fun x => x) c (lblP P m) (fun a => (lblSum tag P m a,lblCtx P m a)) n).symmdef sumPlus (tag : A → G) (P : Labelled A) (m : ℕ)(x : (A × P.obs) × (G × Letters m P.obs)) : G × Letters (m+1) P.obs :=(tag x.1.1+x.2.1, appendOne (x.1.2,x.2.2))def rowPlus (tag : A → G) (P : Labelled A) (m : ℕ)(x : (A × P.obs) × (G × Letters m P.obs)) := (x.1.1,sumPlus tag P m x)lemma sumLaw_succ (tag : A → G) (P : Labelled A) (m) :sumLaw tag P (m+1) = (P.law.tensorP (sumLaw tag P m)).send (sumPlus tag P m) := byunfold sumLawrw [show lblP P (m+1) = _ from iid_succ P.law m,send_send]have hQ := send_tensorP P.law (lblP P m) (fun x => x)(fun a => (lblSum tag P m a,lblCtx P m a))rw [send_id] at hQrw [← hQ,send_send]simp_rw [lbl_succ_sum,lbl_succ_ctx]rflabbrev observe (tag : A → G) (P : Labelled A) (m : ℕ) : Labelled A :={ obs := G × Letters (m+1) P.obslaw := (P.law.tensorP (sumLaw tag P m)).send (rowPlus tag P m) }lemma observe_refines (tag : A → G) (P : Labelled A) (m : ℕ) :refines (observe tag P m) P := byrefine ⟨fun x => x.2 0,?_⟩dsimp only [observe]rw [send_send]have he : (fun x : (A × P.obs) × (G × Letters m P.obs) =>((rowPlus tag P m x).1,(rowPlus tag P m x).2.2 0)) = Prod.fst := byfunext x; rflrw [he, send_fst_tensorP]lemma rowPlus_inj (tag : A → G) (P : Labelled A) (m : ℕ) :Injective (rowPlus tag P m) := byrintro ⟨⟨a,b⟩,⟨s,w⟩⟩ ⟨⟨a',b'⟩,⟨s',w'⟩⟩ hesimp only [rowPlus,sumPlus,Prod.mk.injEq,appendOne,cons_part] at *grindlemma observe_row_ent (tag : A → G) (P : Labelled A) (m : ℕ) :(sumLaw tag P (m+1)).Hcond (fun x => x) Prod.snd +(observe tag P m).law.Hcond (fun x => x) Prod.snd =P.law.Hcond (fun x => x) Prod.snd + (sumLaw tag P m).Hcond (fun x => x) Prod.snd := byrw [sumLaw_succ]dsimp only [observe]let R := P.lawlet Q := sumLaw tag P mlet Z := R.tensorP Qlet Y := sumPlus tag P mlet X := rowPlus tag P mhave hf {α β : Type} [Fintype α] [Fintype β] (P : Law (α × β)) :P.Hcond (fun x => x) Prod.snd = P.entropy - P.H Prod.snd := byhave h := Hcond_function P (fun x => x) Prod.sndrw [H_self] at h; exact hsimp_rw [hf]have hx : Z.H X = Z.entropy :=(H_partition Z (X:=X) (Y:=fun x => x) (fun a b => (rowPlus_inj tag P m).eq_iff)).trans (H_self Z)have hz : (Z.send Y).H Prod.snd = P.law.H Prod.snd + Q.H Prod.snd := byrw [H_send]; refine Eq.trans ?_ (H_tensorP R Q Prod.snd Prod.snd)apply H_partitionintro x ysimp only [Y,sumPlus,appendOne,cons_part,Prod.mk.injEq]change ((Z.send Y).entropy - (Z.send Y).H Prod.snd)+((Z.send X).entropy - (Z.send X).H Prod.snd) = _rw [hz,H_send]change (Z.H Y- (R.H Prod.snd+Q.H Prod.snd))+(Z.H X-Z.H Y) = _rw [hx,show Z.entropy = _ from entropy_tensorP R Q]change _ = (R.entropy-_) + (Q.entropy-_)ringlemma observe_cost (tag : A → G) (hi : Injective tag) (P : Labelled A) (m : ℕ) :fundG tag P 1 - fundG tag (observe tag P m) 1 =fundG tag P (m+1) - fundG tag P m := byrw [I_single tag hi,I_single tag hi,G_as_sum tag P (m+1),G_as_sum tag P m]linarith [observe_row_ent tag P m]private lemma observe_cond (tag : A → G) (P : Labelled A) (m r : ℕ)(R : Law Ω) (S : Law Ω') (X : Ω → Letters r (A×P.obs))(Y : Ω' → Letters r (G × Letters m P.obs)) (g : Ω' → G) :let V := R.tensorP Slet tag' := tag ∘ Prod.fst (β := P.obs)let Y' (x : Ω × Ω') (i : Fin r) := sumPlus tag P m (X x.1 i, Y x.2 i)let X' (x : Ω × Ω') (i : Fin r) := rowPlus tag P m (X x.1 i, Y x.2 i)R.Hcond X (fun x => (ans tag' X (fun _ => 0) x, ctxt Prod.snd X x)) +S.Hcond Y (fun x => (ans Prod.fst Y g x, ctxt Prod.snd Y x)) ≤V.Hcond Y' (fun x => (ans Prod.fst Y' (fun x => g x.2) x, ctxt Prod.snd Y' x)) +V.Hcond X' (fun x => (ans (tag ∘ Prod.fst) X' (fun _ => 0) x, ctxt Prod.snd X' x)) := byintro V tag' Y' X'let B (x) := (ans tag' X (fun _ => 0) x, ctxt Prod.snd X x)let C (x) := (ans Prod.fst Y g x, ctxt Prod.snd Y x)let B' (x) := (ans Prod.fst Y' (fun x => g x.2) x, ctxt Prod.snd Y' x)let C' (x) := (ans (tag ∘ Prod.fst) X' (fun _ => 0) x, ctxt Prod.snd X' x)let W (x : Ω × Ω') := (B x.1,C x.2)have hb1 (x : Ω × Ω') : (B' x).1 = (B x.1).1 + (C x.2).1 := byunfold B' B C Y'unfold ans tot tag' sumPlussimp only [Finset.sum_add_distrib,comp_apply,add_zero,add_assoc]have hc1 (x : Ω × Ω') : (C' x).1 = (B x.1).1 := rflhave H1 : V.Hcond Y' W ≤ V.Hcond Y' B' := byapply Hcond_antitoneintro x y hhhave h1 : B x.1 = B y.1 := congrArg (fun v => v.1) hhhave h2 : C x.2 = C y.2 := congrArg Prod.snd hhapply Prod.ext· rw [hb1,hb1,h1,h2]· funext ihave h3 := congrFun (congrArg Prod.snd h1) ihave h4 := congrFun (congrArg Prod.snd h2) ichange appendOne (_,_) = appendOne (_,_)exact congrArg appendOne (Prod.ext h3 h4)have H2 : V.Hcond X' (fun x => (Y' x,W x)) ≤ V.Hcond X' C' := byrefine Hcond_antitone _ _ fun x y hh => ?_have h1 : W x=W y := congrArg Prod.snd hhhave h2 : Y' x=Y' y := congrArg Prod.fst hhapply Prod.ext· rw [hc1,hc1,show B x.1 = B y.1 from congrArg Prod.fst h1]· exact h2have Hi : V.Hcond (fun x => (X x.1,Y x.2)) W = V.Hcond (fun x => (X' x,Y' x)) W := byunfold Hcondcongr 1apply H_partitionintro a bhave HH : (X a.1,Y a.2)=(X b.1,Y b.2) ↔ (X' a,Y' a)=(X' b,Y' b) := bysimp only [X',Y',funext_iff,Prod.mk.injEq,(rowPlus_inj tag P m).eq_iff,forall_and]constructor· intro ⟨hh,h⟩; simp [hh,h]· tautosimp only [Prod.mk.injEq,HH]rw [Hcond_chain V X' Y' W] at Hihave h := Hcond_tensor R S X Y B Cchange V.Hcond (fun x => (X x.1,Y x.2)) W = _ at hchange R.Hcond X B+S.Hcond Y C ≤ V.Hcond Y' B'+V.Hcond X' C'linarithlemma observe_save (tag : A → G) (c : G → ℝ) (P : Labelled A) (m r : ℕ) :fundK tag c P (m+1) r + fundI tag (observe tag P m) r ≤fundI tag P r + fundK tag c P m r := byclassicalrw [K_as_sum,K_as_sum]let tag' : A × P.obs → G := tag ∘ Prod.fstlet u0 (_ : Unit) := (0:G)let c0 (_ : Unit) := (0:ℝ)obtain ⟨R,hR,eR⟩ := (opt_spec r P.law tag' Prod.snd u0 c0).1let Q := sumLaw tag P mobtain ⟨S,hS,eS⟩ := (opt_spec r Q Prod.fst Prod.snd (fun x => x) c).1let D := WordSample r (A × P.obs) Unitlet E := WordSample r (G × Letters m P.obs) Glet V := R.tensorP Slet Y (x : D×E) (i : Fin r) := sumPlus tag P m (x.1.1 i, x.2.1 i)let X (x : D×E) (i : Fin r) := rowPlus tag P m (x.1.1 i, x.2.1 i)let Ue (x : D×E) := x.2.2have Hlaw (i : Fin r) :V.send (fun x : D×E => (x.1.1 i,x.2.1 i)) = P.law.tensorP Q := byrw [show (fun x : D×E => (x.1.1 i,x.2.1 i)) = _ from rfl]have HH := send_tensorP R S (readP Prod.fst i) (readP Prod.fst i)rw [hR i,hS i] at HHexact HHhave hY : hasRows (sumLaw tag P (m+1)) V Y := byintro irw [sumLaw_succ,show P.law.tensorP (sumLaw tag P m) = _ from (Hlaw i).symm,send_send]; rflhave hX : hasRows (observe tag P m).law V X := byintro i; dsimp only [observe]rw [show P.law.tensorP (sumLaw tag P m) = _ from (Hlaw i).symm,send_send]; rfllet tag'' : (A × (observe tag P m).obs) → G := tag ∘ Prod.fstrefine (add_le_add (opt_le_rent _ _ _ c _ V Y Ue hY)(opt_le_rent tag'' Prod.snd u0 c0 _ V X (fun _ => ()) hX)).trans ?_change _ ≤ opt _ _ tag' _ u0 c0 + opt _ Q _ _ _ _rw [← eR,← eS]dsimp only []unfold rentrw [rent_first hX,rent_first hY,rent_first hS,rent_first hR]have H := observe_cond tag P m r R S Prod.fst Prod.fst Prod.sndhave H0 := observe_row_ent tag P mhave heq : V.Ex (fun a => c (Ue a)) = S.Ex (fun a => c a.2) := bydsimp only [V,Ue]rw [Ex_tensorP]; exact Ex_const R (S.Ex (fun a => c a.2))dsimp only [u0,c0,X,Y,Ue,tag'',tag',V,Q,id_eq,comp_apply] at *simp only [Ex_const]have hmul := congrArg (fun t : ℝ => (Fintype.card (Fin r):ℝ)*t) H0linarithend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222import OAI.Analysis.FourierLLogL.Compress.Context/-! # The block observation -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A V G E Ω Ω' : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype Ω] [Fintype Ω']set_option linter.unusedSectionVars falsedef sumLaw (tag : A → G) (P : Labelled A) (m : ℕ) :=(lblP P m).send (fun a => (lblSum tag P m a,lblCtx P m a))lemma full_pair (p : Law (Ω×Ω')) :p.Hcond (fun x => x) Prod.snd = p.Hcond Prod.fst Prod.snd := byunfold Hcondcongr 1exact H_partition _ (by simp)lemma G_as_sum (tag : A → G) (P : Labelled A) (m) :fundG tag P m = (sumLaw tag P m).Hcond (fun x => x) Prod.snd := byrw [full_pair]unfold sumLaw fundG; rw [Hcond_send]lemma I_single (tag : A → G) (hi : Injective tag) (P : Labelled A) :fundG tag P 1 = P.law.Hcond (fun x => x) Prod.snd :=(fundG_one _ hi P).trans (full_pair P.law).symmlemma K_as_sum (tag : A → G) (c : G → ℝ) (P : Labelled A) (m n) :fundK tag c P m n = opt n (sumLaw tag P m) Prod.fst Prod.snd (fun x => x) c :=(opt_proj Prod.fst Prod.snd (fun x => x) c (lblP P m) (fun a => (lblSum tag P m a,lblCtx P m a)) n).symmdef sumPlus (tag : A → G) (P : Labelled A) (m : ℕ)(x : (A × P.obs) × (G × Letters m P.obs)) : G × Letters (m+1) P.obs :=(tag x.1.1+x.2.1, appendOne (x.1.2,x.2.2))def rowPlus (tag : A → G) (P : Labelled A) (m : ℕ)(x : (A × P.obs) × (G × Letters m P.obs)) := (x.1.1,sumPlus tag P m x)lemma sumLaw_succ (tag : A → G) (P : Labelled A) (m) :sumLaw tag P (m+1) = (P.law.tensorP (sumLaw tag P m)).send (sumPlus tag P m) := byunfold sumLawrw [show lblP P (m+1) = _ from iid_succ P.law m,send_send]have hQ := send_tensorP P.law (lblP P m) (fun x => x)(fun a => (lblSum tag P m a,lblCtx P m a))rw [send_id] at hQrw [← hQ,send_send]simp_rw [lbl_succ_sum,lbl_succ_ctx]rflabbrev observe (tag : A → G) (P : Labelled A) (m : ℕ) : Labelled A :={ obs := G × Letters (m+1) P.obslaw := (P.law.tensorP (sumLaw tag P m)).send (rowPlus tag P m) }lemma observe_refines (tag : A → G) (P : Labelled A) (m : ℕ) :refines (observe tag P m) P := byrefine ⟨fun x => x.2 0,?_⟩dsimp only [observe]rw [send_send]have he : (fun x : (A × P.obs) × (G × Letters m P.obs) =>((rowPlus tag P m x).1,(rowPlus tag P m x).2.2 0)) = Prod.fst := byfunext x; rflrw [he, send_fst_tensorP]lemma rowPlus_inj (tag : A → G) (P : Labelled A) (m : ℕ) :Injective (rowPlus tag P m) := byrintro ⟨⟨a,b⟩,⟨s,w⟩⟩ ⟨⟨a',b'⟩,⟨s',w'⟩⟩ hesimp only [rowPlus,sumPlus,Prod.mk.injEq,appendOne,cons_part] at *grindlemma observe_row_ent (tag : A → G) (P : Labelled A) (m : ℕ) :(sumLaw tag P (m+1)).Hcond (fun x => x) Prod.snd +(observe tag P m).law.Hcond (fun x => x) Prod.snd =P.law.Hcond (fun x => x) Prod.snd + (sumLaw tag P m).Hcond (fun x => x) Prod.snd := byrw [sumLaw_succ]dsimp only [observe]let R := P.lawlet Q := sumLaw tag P mlet Z := R.tensorP Qlet Y := sumPlus tag P mlet X := rowPlus tag P mhave hf {α β : Type} [Fintype α] [Fintype β] (P : Law (α × β)) :P.Hcond (fun x => x) Prod.snd = P.entropy - P.H Prod.snd := byhave h := Hcond_function P (fun x => x) Prod.sndrw [H_self] at h; exact hsimp_rw [hf]have hx : Z.H X = Z.entropy :=(H_partition Z (X:=X) (Y:=fun x => x) (fun a b => (rowPlus_inj tag P m).eq_iff)).trans (H_self Z)have hz : (Z.send Y).H Prod.snd = P.law.H Prod.snd + Q.H Prod.snd := byrw [H_send]; refine Eq.trans ?_ (H_tensorP R Q Prod.snd Prod.snd)apply H_partitionintro x ysimp only [Y,sumPlus,appendOne,cons_part,Prod.mk.injEq]change ((Z.send Y).entropy - (Z.send Y).H Prod.snd)+((Z.send X).entropy - (Z.send X).H Prod.snd) = _rw [hz,H_send]change (Z.H Y- (R.H Prod.snd+Q.H Prod.snd))+(Z.H X-Z.H Y) = _rw [hx,show Z.entropy = _ from entropy_tensorP R Q]change _ = (R.entropy-_) + (Q.entropy-_)ringlemma observe_cost (tag : A → G) (hi : Injective tag) (P : Labelled A) (m : ℕ) :fundG tag P 1 - fundG tag (observe tag P m) 1 =fundG tag P (m+1) - fundG tag P m := byrw [I_single tag hi,I_single tag hi,G_as_sum tag P (m+1),G_as_sum tag P m]linarith [observe_row_ent tag P m]private lemma observe_cond (tag : A → G) (P : Labelled A) (m r : ℕ)(R : Law Ω) (S : Law Ω') (X : Ω → Letters r (A×P.obs))(Y : Ω' → Letters r (G × Letters m P.obs)) (g : Ω' → G) :let V := R.tensorP Slet tag' := tag ∘ Prod.fst (β := P.obs)let Y' (x : Ω × Ω') (i : Fin r) := sumPlus tag P m (X x.1 i, Y x.2 i)let X' (x : Ω × Ω') (i : Fin r) := rowPlus tag P m (X x.1 i, Y x.2 i)R.Hcond X (fun x => (ans tag' X (fun _ => 0) x, ctxt Prod.snd X x)) +S.Hcond Y (fun x => (ans Prod.fst Y g x, ctxt Prod.snd Y x)) ≤V.Hcond Y' (fun x => (ans Prod.fst Y' (fun x => g x.2) x, ctxt Prod.snd Y' x)) +V.Hcond X' (fun x => (ans (tag ∘ Prod.fst) X' (fun _ => 0) x, ctxt Prod.snd X' x)) := byintro V tag' Y' X'let B (x) := (ans tag' X (fun _ => 0) x, ctxt Prod.snd X x)let C (x) := (ans Prod.fst Y g x, ctxt Prod.snd Y x)let B' (x) := (ans Prod.fst Y' (fun x => g x.2) x, ctxt Prod.snd Y' x)let C' (x) := (ans (tag ∘ Prod.fst) X' (fun _ => 0) x, ctxt Prod.snd X' x)let W (x : Ω × Ω') := (B x.1,C x.2)have hb1 (x : Ω × Ω') : (B' x).1 = (B x.1).1 + (C x.2).1 := byunfold B' B C Y'unfold ans tot tag' sumPlussimp only [Finset.sum_add_distrib,comp_apply,add_zero,add_assoc]have hc1 (x : Ω × Ω') : (C' x).1 = (B x.1).1 := rflhave H1 : V.Hcond Y' W ≤ V.Hcond Y' B' := byapply Hcond_antitoneintro x y hhhave h1 : B x.1 = B y.1 := congrArg (fun v => v.1) hhhave h2 : C x.2 = C y.2 := congrArg Prod.snd hhapply Prod.ext· rw [hb1,hb1,h1,h2]· funext ihave h3 := congrFun (congrArg Prod.snd h1) ihave h4 := congrFun (congrArg Prod.snd h2) ichange appendOne (_,_) = appendOne (_,_)exact congrArg appendOne (Prod.ext h3 h4)have H2 : V.Hcond X' (fun x => (Y' x,W x)) ≤ V.Hcond X' C' := byrefine Hcond_antitone _ _ fun x y hh => ?_have h1 : W x=W y := congrArg Prod.snd hhhave h2 : Y' x=Y' y := congrArg Prod.fst hhapply Prod.ext· rw [hc1,hc1,show B x.1 = B y.1 from congrArg Prod.fst h1]· exact h2have Hi : V.Hcond (fun x => (X x.1,Y x.2)) W = V.Hcond (fun x => (X' x,Y' x)) W := byunfold Hcondcongr 1apply H_partitionintro a bhave HH : (X a.1,Y a.2)=(X b.1,Y b.2) ↔ (X' a,Y' a)=(X' b,Y' b) := bysimp only [X',Y',funext_iff,Prod.mk.injEq,(rowPlus_inj tag P m).eq_iff,forall_and]constructor· intro ⟨hh,h⟩; simp [hh,h]· tautosimp only [Prod.mk.injEq,HH]rw [Hcond_chain V X' Y' W] at Hihave h := Hcond_tensor R S X Y B Cchange V.Hcond (fun x => (X x.1,Y x.2)) W = _ at hchange R.Hcond X B+S.Hcond Y C ≤ V.Hcond Y' B'+V.Hcond X' C'linarithlemma observe_save (tag : A → G) (c : G → ℝ) (P : Labelled A) (m r : ℕ) :fundK tag c P (m+1) r + fundI tag (observe tag P m) r ≤fundI tag P r + fundK tag c P m r := byclassicalrw [K_as_sum,K_as_sum]let tag' : A × P.obs → G := tag ∘ Prod.fstlet u0 (_ : Unit) := (0:G)let c0 (_ : Unit) := (0:ℝ)obtain ⟨R,hR,eR⟩ := (opt_spec r P.law tag' Prod.snd u0 c0).1let Q := sumLaw tag P mobtain ⟨S,hS,eS⟩ := (opt_spec r Q Prod.fst Prod.snd (fun x => x) c).1let D := WordSample r (A × P.obs) Unitlet E := WordSample r (G × Letters m P.obs) Glet V := R.tensorP Slet Y (x : D×E) (i : Fin r) := sumPlus tag P m (x.1.1 i, x.2.1 i)let X (x : D×E) (i : Fin r) := rowPlus tag P m (x.1.1 i, x.2.1 i)let Ue (x : D×E) := x.2.2have Hlaw (i : Fin r) :V.send (fun x : D×E => (x.1.1 i,x.2.1 i)) = P.law.tensorP Q := byrw [show (fun x : D×E => (x.1.1 i,x.2.1 i)) = _ from rfl]have HH := send_tensorP R S (readP Prod.fst i) (readP Prod.fst i)rw [hR i,hS i] at HHexact HHhave hY : hasRows (sumLaw tag P (m+1)) V Y := byintro irw [sumLaw_succ,show P.law.tensorP (sumLaw tag P m) = _ from (Hlaw i).symm,send_send]; rflhave hX : hasRows (observe tag P m).law V X := byintro i; dsimp only [observe]rw [show P.law.tensorP (sumLaw tag P m) = _ from (Hlaw i).symm,send_send]; rfllet tag'' : (A × (observe tag P m).obs) → G := tag ∘ Prod.fstrefine (add_le_add (opt_le_rent _ _ _ c _ V Y Ue hY)(opt_le_rent tag'' Prod.snd u0 c0 _ V X (fun _ => ()) hX)).trans ?_change _ ≤ opt _ _ tag' _ u0 c0 + opt _ Q _ _ _ _rw [← eR,← eS]dsimp only []unfold rentrw [rent_first hX,rent_first hY,rent_first hS,rent_first hR]have H := observe_cond tag P m r R S Prod.fst Prod.fst Prod.sndhave H0 := observe_row_ent tag P mhave heq : V.Ex (fun a => c (Ue a)) = S.Ex (fun a => c a.2) := bydsimp only [V,Ue]rw [Ex_tensorP]; exact Ex_const R (S.Ex (fun a => c a.2))dsimp only [u0,c0,X,Y,Ue,tag'',tag',V,Q,id_eq,comp_apply] at *simp only [Ex_const]have hmul := congrArg (fun t : ℝ => (Fintype.card (Fin r):ℝ)*t) H0linarithend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330import OAI.Analysis.FourierLLogL.Compress.Schedule/-! # Choice of entropy parametersHere j tends to infinity, d=2^j. We take h a power of two, comparable with log j. -/open Set Function Filteropen scoped Topology BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compress.Paramsopen Realdef ell (j : ℕ) := Nat.log 2 (Nat.log 2 j / 1000)def slow (j : ℕ) : ℕ := 2^ell jdef wide (j : ℕ) : ℕ := 2^slow jdef height (j : ℕ) : ℝ := 2^jdef sLen (j : ℕ) := 2^(j-6*ell j)def sSeg (j : ℕ) := 2^(j-6*ell j-2)def long (j : ℕ) := height j * (2:ℝ)^wide jlemma pow_pos_nat (n : ℕ) : 0 < 2^n := Nat.pow_pos (by omega)lemma slow_pos (j : ℕ) : 0 < slow j := pow_pos_nat _lemma ell_tendsto : Tendsto ell atTop atTop := byrefine tendsto_atTop.2 fun l => ?_filter_upwards [eventually_ge_atTop (2^(2^l*1000))] with j hjhave h := Nat.le_log_of_pow_le (by omega : 1 < 2) hjapply Nat.le_log_of_pow_le (by omega : 1 < 2)change 2^l ≤ Nat.log 2 j / 1000omegalemma slow_tendsto : Tendsto slow atTop atTop := byrefine tendsto_atTop_mono (f:=ell) ?_ ell_tendstointro jexact (Nat.lt_two_pow_self).lelemma wide_tendsto : Tendsto wide atTop atTop := byrefine tendsto_atTop_mono (f:=slow) ?_ slow_tendstointro jexact Nat.le_of_lt (Nat.lt_two_pow_self)lemma evt_slow : ∀ᶠ j : ℕ in atTop,2^(1000*slow j) ≤ j ∧ j < 2^(3000*slow j) := byfilter_upwards [eventually_ge_atTop (2^1000)] with j hjhave h := Nat.le_log_of_pow_le (by omega : 1 < 2) hjhave hp := (show 0 < Nat.log 2 j/1000 by omega)have h1 : 2^ell j ≤ Nat.log 2 j/1000 := Nat.pow_log_le_self 2 hp.ne'have hx := slow_pos jhave h2 := Nat.lt_pow_succ_log_self (by omega : 1 < 2) (Nat.log 2 j/1000)change _ < 2^(ell j+1) at h2rw [pow_succ] at h2change _ < slow j *2 at h2change slow j ≤ _ at h1constructor· apply le_trans (b:=2^(Nat.log 2 j)) ?_ (Nat.pow_log_le_self 2 (by have := pow_pos_nat 1000; omega))apply Nat.pow_le_pow_right (by omega)omega· apply lt_of_lt_of_le (Nat.lt_pow_succ_log_self (by omega : 1 < 2) j)apply Nat.pow_le_pow_right (by omega)omegalemma eventually_pow_small (n : ℕ) (C : ℝ) :∀ᶠ j : ℕ in atTop, C*(j:ℝ)^n ≤ 2^j := byhave H := (tendsto_pow_const_div_const_pow_of_one_lt n (show (1:ℝ)<2 by norm_num)).const_mul Crw [mul_zero] at Hfilter_upwards [H.eventually (gt_mem_nhds (show (0:ℝ)<1 by norm_num))] with j hjapply le_of_ltapply (div_lt_one (by positivity : (0:ℝ)<2^j)).mprw [mul_div_assoc]exact hjlemma eventually_pow_small_slow (n : ℕ) (C : ℝ) :∀ᶠ j : ℕ in atTop, C*(slow j:ℝ)^n ≤ 2^slow j :=slow_tendsto.eventually (eventually_pow_small n C)lemma nat_pow_small_slow (n C : ℕ) :∀ᶠ j in atTop, C * (slow j)^n ≤ wide j := byfilter_upwards [eventually_pow_small_slow n C] with j hjunfold wide; exact_mod_cast hjdef base (j : ℕ) : ℕ := 2^(wide j ^ 2)def capE (j : ℕ) : ℕ := 2^(64*slow j)def cap (j : ℕ) : ℕ := 2^capE jlemma wide_le_j : ∀ᶠ j : ℕ in atTop, wide j ≤ j := byfilter_upwards [evt_slow] with j ⟨hj,h'⟩exact le_trans (Nat.pow_le_pow_right (by omega) (by omega)) hjlemma ell_le_h (j : ℕ) : ell j ≤ slow j := Nat.le_of_lt Nat.lt_two_pow_selflemma h_le_wide (j : ℕ) : slow j ≤ wide j := Nat.le_of_lt Nat.lt_two_pow_selflemma slow_le_j : ∀ᶠ j in atTop, slow j ≤ j := wide_le_j.mono fun j h => (h_le_wide j).trans hlemma base_le_cap (j : ℕ) : base j ≤ cap j := byunfold base cap capE wideapply Nat.pow_le_pow_right (by omega)rw [← pow_mul]apply Nat.pow_le_pow_right (by omega)omegalemma cap_power : ∀ᶠ j : ℕ in atTop, 64*capE j ≤ j := byfilter_upwards [evt_slow] with j hjapply le_trans (b:=2^(1000*slow j)) _ hj.1unfold capErw [show 64 = 2^6 by norm_num]rw [← pow_add]apply Nat.pow_le_pow_right (by omega)have := slow_pos j; omegalemma below_base (n : ℕ) (C : ℝ) :∀ᶠ j : ℕ in atTop, C * (j:ℝ)^n ≤ base j := byobtain ⟨k,hk⟩ := exists_nat_gt Cfilter_upwards [evt_slow, wide_tendsto.eventually (eventually_ge_atTop (max k (4000*n+2)))] with j ⟨hj,h1⟩ h2apply le_trans (b:=(k:ℝ)*(j:ℝ)^n) (mul_le_mul_of_nonneg_right hk.le (by positivity))suffices H : k*j^n ≤ base j by exact_mod_cast Hhave hk1 : k ≤ wide j := le_trans (le_max_left _ _) h2apply le_trans (b:= (2^k)*(2^(3000*slow j))^n) (Nat.mul_le_mul(Nat.le_of_lt Nat.lt_two_pow_self) (Nat.pow_le_pow_left h1.le n))unfold baserw [← pow_mul, ← pow_add]apply Nat.pow_le_pow_right (by omega)have hx : 4000*n+2 ≤ wide j := le_trans (le_max_right _ _) h2nlinarith [h_le_wide j]lemma t_expr : ∀ᶠ j : ℕ in atTop,sLen j * (slow j)^6 = 2^j ∧ 4*sSeg j = sLen j := byfilter_upwards [evt_slow] with j ⟨h,_⟩have h1 := Nat.lt_two_pow_self (n:=1000*slow j)have h2 := ell_le_h jhave h3 := slow_pos jconstructor· unfold sLen slowrw [← pow_mul,← pow_add]congr 1; omega· unfold sSeg sLenrw [show 4=2^2 by norm_num,← pow_add]congr 1; omegadef nSched (j : ℕ) : ℕ := 2^(16*slow j)def qSched (j : ℕ) : ℕ := 2*slow j^2def mSched (j : ℕ) : ℕ := nSched j * (qSched j*nSched j)def searchSched (j : ℕ) (hj : 4 ≤ slow j) : Schedule := bylet h : ℝ := slow jhave hh : 4 ≤ h := by dsimp only [h]; exact_mod_cast hjhave h' : 0 < h := by linarithlet N := nSched j; let q := qSched jhave hn : exp (6*h) ≤ (N:ℝ) := byhave hi : (1:ℝ)/2 ≤ log 2 := by linarith [Real.log_two_gt_d9]have hN : 0 < (N:ℝ) := by exact_mod_cast pow_pos_nat (16*slow j)rw [← Real.exp_log hN]apply Real.exp_monotonedsimp only [N,nSched]; push_cast; rw [Real.log_pow]push_castunfold h at *nlinarithhave Hn (k : ℝ) (hk : k ≤ 4) : 1 < N * exp (-k*h) := byhave H : 0 < 6*h+-k*h := by nlinarithcalc1 < exp (6*h+-k*h) := Real.one_lt_exp_iff.mpr H_ = _ := Real.exp_add _ __ ≤ _ := mul_le_mul_of_nonneg_right hn (exp_nonneg _)have hq : (q:ℝ)=2*h^2 := by dsimp only [q,h,qSched]; push_cast; rflrefine { N := N, n := N, q := qN0 := pow_pos_nat _, n0 := pow_pos_nat _, q0 := ?_u := 1/h^2, a:= 1/h^3, δ:=exp (-4*h), η:=exp (-2*h)α:=32/h^2, ε:=exp (-2*h)u0:=by positivitya0:=by positivityd0:=exp_pos _heta:=?_hn:= Hn 4 le_rflhα:=by positivityhε:=exp_pos _hβ:=?_hc:=?_hq:=?_ht:=Hn 2 (by norm_num) }· have : (0:ℝ) < q := by rw [hq]; positivityexact_mod_cast this· rw [← exp_add]apply le_of_eq; congr 1; field_simp; ring· field_simp; nlinarith· rw [show (1/h^3)/(32/h^2) = 1/(32*h) by field_simp]rw [hq,add_mul,← exp_add]have he : -2*h+ 2*(1/(32*h))*(2*h^2) ≤ -h := by field_simp; nlinarithhave hx := Real.exp_monotone herw [Real.exp_neg] at hxhave HH : (exp h)⁻¹ ≤ 1/2 := byhave := Real.add_one_le_exp hrw [inv_le_comm₀ (exp_pos h) (by norm_num)]norm_num; linarithlinarith· rw [hq]; field_simp; nlinarithlemma nSched_scale (j : ℕ) (hj : 4 ≤ slow j) :(searchSched j hj).size = mSched j := rfllemma searchSched_loss (j : ℕ) (hj : 4 ≤ slow j) :(searchSched j hj).loss ≤ 66/(slow j:ℝ)^2 := bylet h : ℝ := slow jhave hp : 4 ≤ h := by dsimp only [h]; exact_mod_cast hjchange 2*(32/h^2)+1/h^3*(1+exp (-2*h)) ≤ 66/h^2have HH : exp (-2*h) ≤ 1 := Real.exp_le_one_iff.mpr (by linarith)have : (0:ℝ) < h := by linarithfield_simp; ring_nf at HH ⊢; nlinarithdef levelLow (j i : ℕ) : ℕ := wide j ^ 2 + 4*wide j*(mSched j-i)def levelHigh (j i : ℕ) : ℕ := levelLow j i + 3*wide jdef stepLow (j i : ℕ) : ℕ := 2^levelLow j idef stepHigh (j i : ℕ) : ℕ := 2^levelHigh j idef stepRows (j i : ℕ) : ℕ := 2^(j-(6*ell j+3+levelLow j i))lemma index_budgets :∀ᶠ j : ℕ in atTop, ∀ i, levelHigh j i ≤ capE j ∧ 6*ell j+3+levelHigh j i ≤ j := byfilter_upwards [wide_tendsto.eventually (eventually_ge_atTop 8),cap_power] with j h wjlet w := wide jhave hp : 8 ≤ w := hhave hm : nSched j = w^16 := byunfold nSched w widerw [← pow_mul]; congr 1; omegahave hc : capE j = w^64 := byunfold capE w widerw [← pow_mul]; congr 1; omegahave hb : mSched j ≤ 2*w^34 := byrw [mSched,hm,qSched]calc_ ≤ w^16*(2*w^2*w^16) := byhave H : slow j ≤ w := h_le_wide jgcongr_ = _ := by ringhave hhE : 6*ell j+3 ≤ capE j := byhave hg : ell j ≤ w := (ell_le_h j).trans (h_le_wide j)rw [hc]have hh : w^2 ≤ w^64 := Nat.pow_le_pow_right (by omega) (by omega)nlinarithintro ihave hx : levelHigh j i ≤ capE j := byhave H1 : mSched j-i ≤ 2*w^34 := le_trans (by omega) hbchange w^2+4*w*(mSched j-i)+3*w ≤ _rw [hc]have h₁ : w ≤ w^35 := byexact le_trans (by rw [pow_one] : w ≤ w^1) (Nat.pow_le_pow_right (by omega) (by omega))have h₂ : w^2 ≤ w^35 := Nat.pow_le_pow_right (by omega) (by omega)have h₃ : 16*w^35 ≤ w^64 := byhave H : 16 ≤ w^29 := le_trans (b:=w^2) (by nlinarith)(Nat.pow_le_pow_right (by omega) (by omega))apply le_trans (Nat.mul_le_mul_right (w^35) H)rw [← pow_add]calc_ ≤ w^2+4*w*(2*w^34)+3*w := by gcongr_ ≤ 16*w^35 := byrw [show 4*w*(2*w^34)=8*w^35 by ring]; omega_ ≤ _ := h₃exact ⟨hx,by omega⟩lemma array_spec :∀ᶠ j : ℕ in atTop,3*sSeg j ≤ sLen j ∧ cap j ≤ sSeg j ∧cap j ≤ 2^j ∧(∀ i, stepLow j i ≤ stepHigh j i ∧ stepHigh j i ≤ cap j ∧2*stepRows j i * stepLow j i = sSeg j ∧long j ≤ (stepRows j i:ℝ) * stepHigh j i ∧base j ≤ stepLow j i) ∧(∀ i k, i < k → k < mSched j →stepHigh j k ≤ stepLow j i ∧ stepRows j i ≤ stepRows j k) := byfilter_upwards [index_budgets,t_expr,nat_pow_small_slow 1 10,slow_tendsto.eventually (eventually_ge_atTop 4),cap_power] with j heq ht hw hs hjhave h1 : 6*ell j+2+capE j ≤ j := byhave H0 : 6*ell j ≤ levelHigh j 0 := byunfold levelHigh levelLow; rw [pow_one] at hwhave H := ell_le_h j; omegahave h2 := heq 0have hh := pow_pos_nat (64*slow j); change 0 < capE j at hhomegarefine ⟨by omega,?_,?_ ,?_,?_⟩· apply Nat.pow_le_pow_right (by omega)omega· apply Nat.pow_le_pow_right (by omega)omega· intro ihave hp := heq ihave hlow : levelLow j i ≤ levelHigh j i := by unfold levelHigh; omegarefine ⟨Nat.pow_le_pow_right (by omega) hlow,Nat.pow_le_pow_right (by omega) hp.1,?_,?_,?_⟩· unfold stepLow stepRows sSegnth_rw 1 [show 2 = 2^1 by rfl]rw [← pow_add,← pow_add]; congr 1; omega· unfold long height stepRows stepHighpush_castrw [← pow_add, ← pow_add]apply pow_le_pow_right₀ (by norm_num)unfold levelHigh at *rw [pow_one] at hwhave hh := ell_le_h jomega· unfold base stepLowapply Nat.pow_le_pow_right (by omega)unfold levelLow; omegaintro i k hi hkhave h1 : levelHigh j k ≤ levelLow j i := byunfold levelHigh levelLowhave h2 : mSched j-k+1 ≤ mSched j-i := by omeganlinarithconstructor· exact Nat.pow_le_pow_right (by omega) h1· unfold stepRowsapply Nat.pow_le_pow_right (by omega)unfold levelHigh at h1; omegalemma big_t_real :∀ᶠ j : ℕ in atTop,height j = 4*(sSeg j:ℝ)*(slow j:ℝ)^6 ∧(cap j:ℝ)^4 ≤ height j := byfilter_upwards [t_expr,cap_power] with j h h'constructor· have H : 2^j = 4*sSeg j*slow j^6 := by rw [h.2,h.1]unfold heightexact_mod_cast H· have H1 : cap j^4 ≤ (2:ℕ)^j := byrw [cap, ← pow_mul]exact Nat.pow_le_pow_right (by omega) (by omega)unfold heightexact_mod_cast H1end FourierLLogL.Compress.Paramsend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330import OAI.Analysis.FourierLLogL.Compress.Schedule/-! # Choice of entropy parametersHere j tends to infinity, d=2^j. We take h a power of two, comparable with log j. -/open Set Function Filteropen scoped Topology BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compress.Paramsopen Realdef ell (j : ℕ) := Nat.log 2 (Nat.log 2 j / 1000)def slow (j : ℕ) : ℕ := 2^ell jdef wide (j : ℕ) : ℕ := 2^slow jdef height (j : ℕ) : ℝ := 2^jdef sLen (j : ℕ) := 2^(j-6*ell j)def sSeg (j : ℕ) := 2^(j-6*ell j-2)def long (j : ℕ) := height j * (2:ℝ)^wide jlemma pow_pos_nat (n : ℕ) : 0 < 2^n := Nat.pow_pos (by omega)lemma slow_pos (j : ℕ) : 0 < slow j := pow_pos_nat _lemma ell_tendsto : Tendsto ell atTop atTop := byrefine tendsto_atTop.2 fun l => ?_filter_upwards [eventually_ge_atTop (2^(2^l*1000))] with j hjhave h := Nat.le_log_of_pow_le (by omega : 1 < 2) hjapply Nat.le_log_of_pow_le (by omega : 1 < 2)change 2^l ≤ Nat.log 2 j / 1000omegalemma slow_tendsto : Tendsto slow atTop atTop := byrefine tendsto_atTop_mono (f:=ell) ?_ ell_tendstointro jexact (Nat.lt_two_pow_self).lelemma wide_tendsto : Tendsto wide atTop atTop := byrefine tendsto_atTop_mono (f:=slow) ?_ slow_tendstointro jexact Nat.le_of_lt (Nat.lt_two_pow_self)lemma evt_slow : ∀ᶠ j : ℕ in atTop,2^(1000*slow j) ≤ j ∧ j < 2^(3000*slow j) := byfilter_upwards [eventually_ge_atTop (2^1000)] with j hjhave h := Nat.le_log_of_pow_le (by omega : 1 < 2) hjhave hp := (show 0 < Nat.log 2 j/1000 by omega)have h1 : 2^ell j ≤ Nat.log 2 j/1000 := Nat.pow_log_le_self 2 hp.ne'have hx := slow_pos jhave h2 := Nat.lt_pow_succ_log_self (by omega : 1 < 2) (Nat.log 2 j/1000)change _ < 2^(ell j+1) at h2rw [pow_succ] at h2change _ < slow j *2 at h2change slow j ≤ _ at h1constructor· apply le_trans (b:=2^(Nat.log 2 j)) ?_ (Nat.pow_log_le_self 2 (by have := pow_pos_nat 1000; omega))apply Nat.pow_le_pow_right (by omega)omega· apply lt_of_lt_of_le (Nat.lt_pow_succ_log_self (by omega : 1 < 2) j)apply Nat.pow_le_pow_right (by omega)omegalemma eventually_pow_small (n : ℕ) (C : ℝ) :∀ᶠ j : ℕ in atTop, C*(j:ℝ)^n ≤ 2^j := byhave H := (tendsto_pow_const_div_const_pow_of_one_lt n (show (1:ℝ)<2 by norm_num)).const_mul Crw [mul_zero] at Hfilter_upwards [H.eventually (gt_mem_nhds (show (0:ℝ)<1 by norm_num))] with j hjapply le_of_ltapply (div_lt_one (by positivity : (0:ℝ)<2^j)).mprw [mul_div_assoc]exact hjlemma eventually_pow_small_slow (n : ℕ) (C : ℝ) :∀ᶠ j : ℕ in atTop, C*(slow j:ℝ)^n ≤ 2^slow j :=slow_tendsto.eventually (eventually_pow_small n C)lemma nat_pow_small_slow (n C : ℕ) :∀ᶠ j in atTop, C * (slow j)^n ≤ wide j := byfilter_upwards [eventually_pow_small_slow n C] with j hjunfold wide; exact_mod_cast hjdef base (j : ℕ) : ℕ := 2^(wide j ^ 2)def capE (j : ℕ) : ℕ := 2^(64*slow j)def cap (j : ℕ) : ℕ := 2^capE jlemma wide_le_j : ∀ᶠ j : ℕ in atTop, wide j ≤ j := byfilter_upwards [evt_slow] with j ⟨hj,h'⟩exact le_trans (Nat.pow_le_pow_right (by omega) (by omega)) hjlemma ell_le_h (j : ℕ) : ell j ≤ slow j := Nat.le_of_lt Nat.lt_two_pow_selflemma h_le_wide (j : ℕ) : slow j ≤ wide j := Nat.le_of_lt Nat.lt_two_pow_selflemma slow_le_j : ∀ᶠ j in atTop, slow j ≤ j := wide_le_j.mono fun j h => (h_le_wide j).trans hlemma base_le_cap (j : ℕ) : base j ≤ cap j := byunfold base cap capE wideapply Nat.pow_le_pow_right (by omega)rw [← pow_mul]apply Nat.pow_le_pow_right (by omega)omegalemma cap_power : ∀ᶠ j : ℕ in atTop, 64*capE j ≤ j := byfilter_upwards [evt_slow] with j hjapply le_trans (b:=2^(1000*slow j)) _ hj.1unfold capErw [show 64 = 2^6 by norm_num]rw [← pow_add]apply Nat.pow_le_pow_right (by omega)have := slow_pos j; omegalemma below_base (n : ℕ) (C : ℝ) :∀ᶠ j : ℕ in atTop, C * (j:ℝ)^n ≤ base j := byobtain ⟨k,hk⟩ := exists_nat_gt Cfilter_upwards [evt_slow, wide_tendsto.eventually (eventually_ge_atTop (max k (4000*n+2)))] with j ⟨hj,h1⟩ h2apply le_trans (b:=(k:ℝ)*(j:ℝ)^n) (mul_le_mul_of_nonneg_right hk.le (by positivity))suffices H : k*j^n ≤ base j by exact_mod_cast Hhave hk1 : k ≤ wide j := le_trans (le_max_left _ _) h2apply le_trans (b:= (2^k)*(2^(3000*slow j))^n) (Nat.mul_le_mul(Nat.le_of_lt Nat.lt_two_pow_self) (Nat.pow_le_pow_left h1.le n))unfold baserw [← pow_mul, ← pow_add]apply Nat.pow_le_pow_right (by omega)have hx : 4000*n+2 ≤ wide j := le_trans (le_max_right _ _) h2nlinarith [h_le_wide j]lemma t_expr : ∀ᶠ j : ℕ in atTop,sLen j * (slow j)^6 = 2^j ∧ 4*sSeg j = sLen j := byfilter_upwards [evt_slow] with j ⟨h,_⟩have h1 := Nat.lt_two_pow_self (n:=1000*slow j)have h2 := ell_le_h jhave h3 := slow_pos jconstructor· unfold sLen slowrw [← pow_mul,← pow_add]congr 1; omega· unfold sSeg sLenrw [show 4=2^2 by norm_num,← pow_add]congr 1; omegadef nSched (j : ℕ) : ℕ := 2^(16*slow j)def qSched (j : ℕ) : ℕ := 2*slow j^2def mSched (j : ℕ) : ℕ := nSched j * (qSched j*nSched j)def searchSched (j : ℕ) (hj : 4 ≤ slow j) : Schedule := bylet h : ℝ := slow jhave hh : 4 ≤ h := by dsimp only [h]; exact_mod_cast hjhave h' : 0 < h := by linarithlet N := nSched j; let q := qSched jhave hn : exp (6*h) ≤ (N:ℝ) := byhave hi : (1:ℝ)/2 ≤ log 2 := by linarith [Real.log_two_gt_d9]have hN : 0 < (N:ℝ) := by exact_mod_cast pow_pos_nat (16*slow j)rw [← Real.exp_log hN]apply Real.exp_monotonedsimp only [N,nSched]; push_cast; rw [Real.log_pow]push_castunfold h at *nlinarithhave Hn (k : ℝ) (hk : k ≤ 4) : 1 < N * exp (-k*h) := byhave H : 0 < 6*h+-k*h := by nlinarithcalc1 < exp (6*h+-k*h) := Real.one_lt_exp_iff.mpr H_ = _ := Real.exp_add _ __ ≤ _ := mul_le_mul_of_nonneg_right hn (exp_nonneg _)have hq : (q:ℝ)=2*h^2 := by dsimp only [q,h,qSched]; push_cast; rflrefine { N := N, n := N, q := qN0 := pow_pos_nat _, n0 := pow_pos_nat _, q0 := ?_u := 1/h^2, a:= 1/h^3, δ:=exp (-4*h), η:=exp (-2*h)α:=32/h^2, ε:=exp (-2*h)u0:=by positivitya0:=by positivityd0:=exp_pos _heta:=?_hn:= Hn 4 le_rflhα:=by positivityhε:=exp_pos _hβ:=?_hc:=?_hq:=?_ht:=Hn 2 (by norm_num) }· have : (0:ℝ) < q := by rw [hq]; positivityexact_mod_cast this· rw [← exp_add]apply le_of_eq; congr 1; field_simp; ring· field_simp; nlinarith· rw [show (1/h^3)/(32/h^2) = 1/(32*h) by field_simp]rw [hq,add_mul,← exp_add]have he : -2*h+ 2*(1/(32*h))*(2*h^2) ≤ -h := by field_simp; nlinarithhave hx := Real.exp_monotone herw [Real.exp_neg] at hxhave HH : (exp h)⁻¹ ≤ 1/2 := byhave := Real.add_one_le_exp hrw [inv_le_comm₀ (exp_pos h) (by norm_num)]norm_num; linarithlinarith· rw [hq]; field_simp; nlinarithlemma nSched_scale (j : ℕ) (hj : 4 ≤ slow j) :(searchSched j hj).size = mSched j := rfllemma searchSched_loss (j : ℕ) (hj : 4 ≤ slow j) :(searchSched j hj).loss ≤ 66/(slow j:ℝ)^2 := bylet h : ℝ := slow jhave hp : 4 ≤ h := by dsimp only [h]; exact_mod_cast hjchange 2*(32/h^2)+1/h^3*(1+exp (-2*h)) ≤ 66/h^2have HH : exp (-2*h) ≤ 1 := Real.exp_le_one_iff.mpr (by linarith)have : (0:ℝ) < h := by linarithfield_simp; ring_nf at HH ⊢; nlinarithdef levelLow (j i : ℕ) : ℕ := wide j ^ 2 + 4*wide j*(mSched j-i)def levelHigh (j i : ℕ) : ℕ := levelLow j i + 3*wide jdef stepLow (j i : ℕ) : ℕ := 2^levelLow j idef stepHigh (j i : ℕ) : ℕ := 2^levelHigh j idef stepRows (j i : ℕ) : ℕ := 2^(j-(6*ell j+3+levelLow j i))lemma index_budgets :∀ᶠ j : ℕ in atTop, ∀ i, levelHigh j i ≤ capE j ∧ 6*ell j+3+levelHigh j i ≤ j := byfilter_upwards [wide_tendsto.eventually (eventually_ge_atTop 8),cap_power] with j h wjlet w := wide jhave hp : 8 ≤ w := hhave hm : nSched j = w^16 := byunfold nSched w widerw [← pow_mul]; congr 1; omegahave hc : capE j = w^64 := byunfold capE w widerw [← pow_mul]; congr 1; omegahave hb : mSched j ≤ 2*w^34 := byrw [mSched,hm,qSched]calc_ ≤ w^16*(2*w^2*w^16) := byhave H : slow j ≤ w := h_le_wide jgcongr_ = _ := by ringhave hhE : 6*ell j+3 ≤ capE j := byhave hg : ell j ≤ w := (ell_le_h j).trans (h_le_wide j)rw [hc]have hh : w^2 ≤ w^64 := Nat.pow_le_pow_right (by omega) (by omega)nlinarithintro ihave hx : levelHigh j i ≤ capE j := byhave H1 : mSched j-i ≤ 2*w^34 := le_trans (by omega) hbchange w^2+4*w*(mSched j-i)+3*w ≤ _rw [hc]have h₁ : w ≤ w^35 := byexact le_trans (by rw [pow_one] : w ≤ w^1) (Nat.pow_le_pow_right (by omega) (by omega))have h₂ : w^2 ≤ w^35 := Nat.pow_le_pow_right (by omega) (by omega)have h₃ : 16*w^35 ≤ w^64 := byhave H : 16 ≤ w^29 := le_trans (b:=w^2) (by nlinarith)(Nat.pow_le_pow_right (by omega) (by omega))apply le_trans (Nat.mul_le_mul_right (w^35) H)rw [← pow_add]calc_ ≤ w^2+4*w*(2*w^34)+3*w := by gcongr_ ≤ 16*w^35 := byrw [show 4*w*(2*w^34)=8*w^35 by ring]; omega_ ≤ _ := h₃exact ⟨hx,by omega⟩lemma array_spec :∀ᶠ j : ℕ in atTop,3*sSeg j ≤ sLen j ∧ cap j ≤ sSeg j ∧cap j ≤ 2^j ∧(∀ i, stepLow j i ≤ stepHigh j i ∧ stepHigh j i ≤ cap j ∧2*stepRows j i * stepLow j i = sSeg j ∧long j ≤ (stepRows j i:ℝ) * stepHigh j i ∧base j ≤ stepLow j i) ∧(∀ i k, i < k → k < mSched j →stepHigh j k ≤ stepLow j i ∧ stepRows j i ≤ stepRows j k) := byfilter_upwards [index_budgets,t_expr,nat_pow_small_slow 1 10,slow_tendsto.eventually (eventually_ge_atTop 4),cap_power] with j heq ht hw hs hjhave h1 : 6*ell j+2+capE j ≤ j := byhave H0 : 6*ell j ≤ levelHigh j 0 := byunfold levelHigh levelLow; rw [pow_one] at hwhave H := ell_le_h j; omegahave h2 := heq 0have hh := pow_pos_nat (64*slow j); change 0 < capE j at hhomegarefine ⟨by omega,?_,?_ ,?_,?_⟩· apply Nat.pow_le_pow_right (by omega)omega· apply Nat.pow_le_pow_right (by omega)omega· intro ihave hp := heq ihave hlow : levelLow j i ≤ levelHigh j i := by unfold levelHigh; omegarefine ⟨Nat.pow_le_pow_right (by omega) hlow,Nat.pow_le_pow_right (by omega) hp.1,?_,?_,?_⟩· unfold stepLow stepRows sSegnth_rw 1 [show 2 = 2^1 by rfl]rw [← pow_add,← pow_add]; congr 1; omega· unfold long height stepRows stepHighpush_castrw [← pow_add, ← pow_add]apply pow_le_pow_right₀ (by norm_num)unfold levelHigh at *rw [pow_one] at hwhave hh := ell_le_h jomega· unfold base stepLowapply Nat.pow_le_pow_right (by omega)unfold levelLow; omegaintro i k hi hkhave h1 : levelHigh j k ≤ levelLow j i := byunfold levelHigh levelLowhave h2 : mSched j-k+1 ≤ mSched j-i := by omeganlinarithconstructor· exact Nat.pow_le_pow_right (by omega) h1· unfold stepRowsapply Nat.pow_le_pow_right (by omega)unfold levelHigh at h1; omegalemma big_t_real :∀ᶠ j : ℕ in atTop,height j = 4*(sSeg j:ℝ)*(slow j:ℝ)^6 ∧(cap j:ℝ)^4 ≤ height j := byfilter_upwards [t_expr,cap_power] with j h h'constructor· have H : 2^j = 4*sSeg j*slow j^6 := by rw [h.2,h.1]unfold heightexact_mod_cast H· have H1 : cap j^4 ≤ (2:ℕ)^j := byrw [cap, ← pow_mul]exact Nat.pow_le_pow_right (by omega) (by omega)unfold heightexact_mod_cast H1end FourierLLogL.Compress.Paramsend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284import OAI.Analysis.FourierLLogL.Compress.Freezeimport OAI.Analysis.FourierLLogL.Finite.Complexopen Set Function Filteropen scoped BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Lawvariable {A G Θ I Ω : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype Θ] [Fintype I] [DecidableEq I] [Fintype Ω]set_option linter.unusedSectionVars falselemma char_neg (χ : AddChar G ℂ) (hn : ∀ x, ‖χ x‖ = 1) (x : G) :χ (-x) = conj (χ x) := byapply mul_left_cancel₀ (a := χ x) (by intro h; have H := hn x; rw [h,norm_zero] at H; norm_num at H)rw [← χ.map_add_eq_mul,Complex.mul_conj,← Complex.sq_norm, hn]simplemma char_sum (χ : AddChar G ℂ) (f : I → G) :χ (∑ i, f i) = ∏ i, χ (f i) := byclassicalsuffices H : ∀ s : Finset I, χ (∑ i ∈ s, f i) = ∏ i ∈ s, χ (f i) from H _intro sinduction s using Finset.induction_on with| empty => simp| @insert i s hi ih => rw [Finset.prod_insert hi,Finset.sum_insert hi,χ.map_add_eq_mul,ih]lemma heat_prod (tag : A→G) (c : G→ℝ) (Q : Law Θ) (χ : Θ→AddChar G ℂ)(hn : ∀ t x, ‖χ t x‖=1)(hc : ∀ g, ((exp (-c g) : ℝ):ℂ)=Q.Cx (fun t => χ t g))(p : I→Law A) (z : G) :(pack p).Ex (fun x => exp (-c (z-tot tag x))) ≤Q.Ex (fun t => ∏ i, ‖(p i).Cx (fun a => χ t (tag a))‖) := bylet f (x : I→A) := exp (-c (z-tot tag x))have H (x : I→A) (t : Θ) :χ t (z-tot tag x) = χ t z * ∏ i, conj (χ t (tag (x i))) := byrw [sub_eq_add_neg,(χ t).map_add_eq_mul,char_neg (χ t) (hn t)]unfold totrw [char_sum,map_prod]let C (i : I) (t : Θ) := (p i).Cx fun a => χ t (tag a)have heq :(↑((pack p).Ex f) : ℂ) =Q.Cx fun t => χ t z * ∏ i, conj (C i t) := byrw [← Cx_ofReal]; unfold fsimp_rw [hc,H]rw [Cx_swap]apply congrArgfunext trw [Cx_lmul,Cx_prod p (fun _ x => conj (χ t (tag x)))]simp_rw [Cx_conj]; rflhave ht := Cx_norm Q (fun t => χ t z * ∏ i, conj (C i t))rw [← heq, Complex.norm_real, Real.norm_eq_abs] at htsimp_rw [norm_mul,Complex.norm_prod,hn,one_mul,Complex.norm_conj] at htexact le_trans (le_abs_self _) ht/-- Defect between two letter phases. -/def defect (tag : A → G) (χ : Θ → AddChar G ℂ) (a b : A) (t : Θ) :=1 - (χ t (tag a-tag b)).relemma defect_nonneg (tag : A → G) (χ : Θ → AddChar G ℂ) (hn : ∀ t x, ‖χ t x‖=1) (a b t) :0 ≤ defect tag χ a b t := byunfold defecthave H := Complex.abs_re_le_norm (χ t (tag a-tag b))rw [hn] at H; linarith [(abs_le.mp H).2]lemma defect_mean (tag : A → G) (χ : Θ → AddChar G ℂ) (hn : ∀ t x, ‖χ t x‖=1)(p : Law A) (t) :p.Ex (fun a => p.Ex (fun b => defect tag χ a b t)) =1- ‖p.Cx (fun a => χ t (tag a))‖^2 := byunfold defecthave h (a b : A) :(χ t) (tag a-tag b) = χ t (tag a)*conj (χ t (tag b)) := byrw [sub_eq_add_neg,(χ t).map_add_eq_mul,char_neg _ (hn t)]simp_rw [h,Ex_sub,Ex_const,sq_norm_Cx]/-- If the characteristic product has large integral, then it has large volume at thecorresponding defect level. -/lemma phase_region (Q : Law Θ) (f : I → Θ → ℝ) (hf : ∀ i t, 0 ≤ f i t ∧ f i t ≤ 1){E : ℝ} (he : 1 ≤ E) (h : exp (-(2*E)) ≤ Q.Ex fun t => ∏ i, f i t) :let A (x : Θ) := ∑ i, (1-f i x ^ 2)exp (-(3*E)) ≤ Q.prob fun x => A x ≤ 8*E := byclassicalintro Dlet S (x : Θ) := D x ≤ 8*Ehave h1 (x : ℝ) (hp : 0 ≤ x) : x ≤ exp (-(1-x^2)/2) := byhave hi := Real.add_one_le_exp (-(1-x^2))have hh := Real.exp_pos (-(1-x^2)/2)rw [show -(1-x^2)=-(1-x^2)/2+ -(1-x^2)/2 by ring,Real.exp_add] at hinlinarithhave hx (x : Θ) :(∏ i, f i x) ≤ (if S x then (1:ℝ) else 0)+ exp (-(4*E)) := bysplit_ifs with H· apply le_trans (b:=∏ i : I,(1:ℝ)) (Finset.prod_le_prod₀ (fun i _ => (hf i x).1)(fun i _ => (hf i x).2))simp [exp_nonneg]· apply le_trans (b:=∏ i, exp (-(1-f i x^2)/2)) (Finset.prod_le_prod₀(fun i _ => (hf i x).1) (fun i _ => h1 _ (hf _ _).1))have heq : ∑ i, (-(1-f i x^2)/2) = -(D x)/2 := byunfold D; rw [← Finset.sum_div,Finset.sum_neg_distrib]rw [← Real.exp_sum,heq,zero_add]apply exp_monotone; unfold S at H; linarithhave heq : Q.Ex (fun x => if S x then (1:ℝ) else 0) = Q.prob S := byunfold probcongr 1have H := Q.Ex_mono hxrw [Ex_add,heq,Ex_const] at Hhave hb : 2 ≤ exp E := le_trans (by linarith) (Real.add_one_le_exp E)have H1 := exp_nonneg (-(4*E))have H2 := exp_nonneg (-(3*E))have H3 : exp (-(2*E)) = exp (-(3*E))*exp E := by rw [← exp_add]; congr 1; ringhave H4 : exp (-(3*E)) = exp (-(4*E))*exp E := by rw [← exp_add]; congr 1; ringchange _ ≤ Q.prob Snlinarithlemma log_gap (P : Law A) [Nonempty A](s : Finset A)(hp : (1/2:ℝ) ≤ P.prob fun x => x ∈ s) :log (Fintype.card A) - log (s.card:ℝ) ≤2*(log (Fintype.card A)-P.entropy+log 2) := byclassicallet f (x : A) : Bool := decide (x ∈ s)let Q := P.send fhave h1 : P.entropy = Q.entropy +Q.Ex fun b => (P.after f b).entropy := byhave hI : P.H (fun x => (x,f x)) = P.entropy := byrw [← H_self]; apply H_partition; simprw [← hI,H_pair_chain,Hcond_after]simp_rw [H_self]rflhave hh : Q true = P.prob (fun x => x ∈ s) := byunfold Q; rw [ send_apply]congr; simp [f]have hPos : 0 < Q true := by rw [hh]; linarithhave hcard : 0 < (s.card:ℝ) := byobtain ⟨x,hx,_⟩ := (send_pos_iff P f true).mp hPoshave ht : x ∈ s := by simpa only [f,decide_eq_true_eq] using hxexact_mod_cast Finset.card_pos.mpr ⟨x,ht⟩let L := log (Fintype.card A)let T := log (s.card:ℝ)have hT : T ≤ L := Real.log_le_log hcard (by exact_mod_cast Finset.card_le_univ _)have H : (P.after f true).entropy ≤ T :=entropy_le_log_size _ s fun x hx => bysimpa only [f,decide_eq_true_eq] using ((after_mem hPos).mp hx).1have H' : (P.after f false).entropy ≤ L := entropy_le_log_card _have Hb : Q.entropy ≤ log 2 := by simpa using entropy_le_log_card Qhave HI : Q false + Q true = 1 := by simpa [Fintype.sum_bool,add_comm] using Q.totalrw [h1,Ex,Fintype.sum_bool]change L-T ≤ _have : L-T ≤ 2*(L-(Q.entropy+(Q true*(P.after f true).entropy + Q false*(P.after f false).entropy))+log 2) := byhave hPos' := Q.nonneg falserw [← hh] at hpnlinarith [mul_le_mul_of_nonneg_left H hPos.le,mul_le_mul_of_nonneg_left H' hPos', show Q false * L+ Q true * L=L by rw [← add_mul,HI,one_mul]]exact thislemma prob_half (P : Law Ω) (f : Ω → ℝ) (hn : ∀ x, 0 ≤ f x) (E : ℝ) (he : 0 < E)(hp : P.Ex f ≤ E) :(1/2:ℝ) ≤ P.prob fun x => f x ≤ 2*E := byclassicallet p (x : Ω) := f x ≤ 2*Elet F (x : Ω) := if ¬p x then 1 else (0:ℝ)have hh : P.Ex F = P.prob (fun x => ¬p x) := byapply congrArg (P.Ex)funext x; unfold Fsplit_ifs <;> simp_allrw [prob_compl] at hhhave hi (x : Ω) : 2*E * F x ≤ f x := byunfold F p; split_ifs with H· simp [hn x]· simp; linarithhave H := (P.Ex_mono hi).trans hprw [Ex_lmul, hh] at Hchange _ ≤ P.prob pnlinarithdef small_defects (tag : A → G) (χ : Θ → AddChar G ℂ) (Q : Law Θ)(L : ℝ) (s : Finset A) (a : A) (F : ℝ) : Prop :=∀ p : Law A, (∀ x, 0 < p x → x ∈ s) →exp (-F) ≤ Q.Ex fun t => exp ((-L)*p.Ex (fun x => defect tag χ x a t))lemma alignment (tag : A → G) (c : G → ℝ) (Q : Law Θ) (χ : Θ → AddChar G ℂ)(hn : ∀ t x, ‖χ t x‖=1)(hc : ∀ g, ((exp (-c g) : ℝ):ℂ)=Q.Cx (fun t => χ t g))(p : I → Law A) [Nonempty I] [Nonempty A] (z : G)(F D L : ℝ) (he : 1 ≤ F) (hd : 0 < D) (hL : 0 ≤ L)(hL' : L ≤ Fintype.card I)(hz : exp (-(2*F)) ≤ (pack p).Ex (fun x => exp (-c (z-tot tag x))))(hs : ∑ i, (log (Fintype.card A)-entropy (p i)) ≤ 2*(Fintype.card I*D)) :∃ (a : A) (s : Finset A), s.Nonempty ∧log (Fintype.card A) - log (s.card:ℝ) ≤ 8*D+2 ∧small_defects tag χ Q L s a (35*F) := byclassicallet f i (t : Θ) := ‖(p i).Cx (fun a => χ t (tag a))‖have hf1 (i : I) (t : Θ) : f i t ≤ 1 := norm_Cx_unit _ _ fun x => (hn _ _).lehave hf0 (i : I) (t : Θ) : 0 ≤ f i t := norm_nonneg _let W (x : Θ) : Prop := ∑ i, (1 - f i x ^ 2) ≤ 8*Fhave hh : exp (-(3*F)) ≤ Q.prob W := phase_region Q f (fun i t => ⟨hf0 _ _,hf1 _ _⟩)he (hz.trans (heat_prod _ _ _ _ hn hc p z))let P := Q.condP Whave hW : 0 < Q.prob W := lt_of_lt_of_le (exp_pos _) hhlet g (i : I) := P.Ex fun t => 1-f i t^2let A' (i : I) := log (Fintype.card A)-entropy (p i)have hgp (i : I) : 0 ≤ g i := Ex_nonneg P fun t => bynlinarith [hf1 i t,hf0 i t]let T := (Fintype.card I:ℝ)have ht : 0 < T := by unfold T; positivityhave hg : (uniform I).Ex g ≤ 8*F/T := byhave hi : ∑ i, g i ≤ 8*F := byunfold grw [← Ex_finset_sum]refine le_trans (b:=P.Ex fun _ => 8*F) (P.Ex_mono_mem fun x hx => ?_) (P.Ex_const _).leexact ((Law.condP_mem hW).mp hx).1simp_rw [Ex,uniform_apply,← Finset.mul_sum]exact le_trans (mul_le_mul_of_nonneg_left hi (inv_pos.mpr ht).le)(by dsimp [T]; rw [← div_eq_inv_mul])have ha : (uniform I).Ex A' ≤ 2*D := bysimp_rw [Ex,uniform_apply,← Finset.mul_sum,← div_eq_inv_mul]exact (div_le_iff₀ ht).mpr (by dsimp only [T,A']; linarith)obtain ⟨i, _,hi,hi'⟩ := average_two_below (uniform I) g A' (fun i _ => hgp i)(fun i _ => sub_nonneg.mpr (entropy_le_log_card _)) (8*F/T) (2*D)(by have := lt_of_lt_of_le zero_lt_one he; positivity) (by positivity) hg halet R := p ilet G (x y : A) := P.Ex (defect tag χ x y)have HG : R.Ex (fun y => R.Ex fun x => G x y) ≤ 16*F/T := byhave Heq : R.Ex (fun y => R.Ex fun x => G x y) = g i := byrw [Ex_swap]unfold Gsimp_rw [Ex_swap R P]unfold g fsimp_rw [defect_mean _ _ hn]rflrw [Heq]exact hi.trans (le_of_eq (by ring))obtain ⟨a,ha',ha''⟩ := R.exists_le_Ex (fun y => R.Ex fun x => G x y)let s := Finset.univ.filter fun x => G x a ≤ 2*(16*F/T)have ha0 : R.Ex (fun x => G x a) ≤ 16*F/T := ha''.trans HGhave hp : (1/2:ℝ) ≤ R.prob fun x => x ∈ s := bysimp only [s,Finset.mem_filter,Finset.mem_univ,true_and]exact prob_half _ _ (fun x => Ex_nonneg _ (fun y => defect_nonneg _ _ hn x a y))_ (by have := lt_of_lt_of_le zero_lt_one he; positivity) ha0obtain ⟨x,hx,_⟩ := (prob_pos_iff R (fun x => x∈s)).mp(lt_of_lt_of_le (by norm_num : (0:ℝ)<1/2) hp)refine ⟨a,s,⟨x,hx⟩,(log_gap R s hp).trans ?_,?_⟩· change log (Fintype.card A) - entropy R ≤ _ at hi'have hi := Real.log_le_sub_one_of_pos (x:=2) (by norm_num)linarithintro V hvlet v (t : Θ) := V.Ex fun x => defect tag χ x a thave hB : P.Ex v ≤ 32*F/T := byunfold v; rw [Ex_swap P V]refine le_trans (b:=V.Ex fun _ => 32*F/T) (V.Ex_mono_mem fun x hx => ?_)(V.Ex_const _).lehave H := (Finset.mem_filter.mp (hv x hx)).2change G x a ≤ _exact H.trans (le_of_eq (by ring))have H1 : P.Ex (fun t => exp ((-L)* v t)) ≥ exp (-(32*F)) := byhave H := Ex_exp P (fun t => (-L)*v t)rw [Ex_lmul] at Happly le_trans _ Happly exp_monotonehave hbp := (le_div_iff₀ ht).mp hBchange L ≤ T at hL'have hg1 : 0 ≤ P.Ex v :=P.Ex_nonneg fun t => V.Ex_nonneg fun x => defect_nonneg tag χ hn x a tnlinarithcalcexp (-(35*F)) = exp (-(3*F))*exp (-(32*F)) := by rw [← exp_add]; congr 1; ring_ ≤ Q.prob W * P.Ex (fun t => exp ((-L)*v t)) :=mul_le_mul hh H1 (exp_nonneg _) hW.le_ ≤ _ := bydsimp only [P]rw [prob_mul_Ex_condP]apply Q.Ex_mono; intro t; split_ifs <;> first | exact le_rfl | exact exp_nonneg _end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284import OAI.Analysis.FourierLLogL.Compress.Freezeimport OAI.Analysis.FourierLLogL.Finite.Complexopen Set Function Filteropen scoped BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Lawvariable {A G Θ I Ω : Type} [Fintype A] [Fintype G] [AddCommGroup G][Fintype Θ] [Fintype I] [DecidableEq I] [Fintype Ω]set_option linter.unusedSectionVars falselemma char_neg (χ : AddChar G ℂ) (hn : ∀ x, ‖χ x‖ = 1) (x : G) :χ (-x) = conj (χ x) := byapply mul_left_cancel₀ (a := χ x) (by intro h; have H := hn x; rw [h,norm_zero] at H; norm_num at H)rw [← χ.map_add_eq_mul,Complex.mul_conj,← Complex.sq_norm, hn]simplemma char_sum (χ : AddChar G ℂ) (f : I → G) :χ (∑ i, f i) = ∏ i, χ (f i) := byclassicalsuffices H : ∀ s : Finset I, χ (∑ i ∈ s, f i) = ∏ i ∈ s, χ (f i) from H _intro sinduction s using Finset.induction_on with| empty => simp| @insert i s hi ih => rw [Finset.prod_insert hi,Finset.sum_insert hi,χ.map_add_eq_mul,ih]lemma heat_prod (tag : A→G) (c : G→ℝ) (Q : Law Θ) (χ : Θ→AddChar G ℂ)(hn : ∀ t x, ‖χ t x‖=1)(hc : ∀ g, ((exp (-c g) : ℝ):ℂ)=Q.Cx (fun t => χ t g))(p : I→Law A) (z : G) :(pack p).Ex (fun x => exp (-c (z-tot tag x))) ≤Q.Ex (fun t => ∏ i, ‖(p i).Cx (fun a => χ t (tag a))‖) := bylet f (x : I→A) := exp (-c (z-tot tag x))have H (x : I→A) (t : Θ) :χ t (z-tot tag x) = χ t z * ∏ i, conj (χ t (tag (x i))) := byrw [sub_eq_add_neg,(χ t).map_add_eq_mul,char_neg (χ t) (hn t)]unfold totrw [char_sum,map_prod]let C (i : I) (t : Θ) := (p i).Cx fun a => χ t (tag a)have heq :(↑((pack p).Ex f) : ℂ) =Q.Cx fun t => χ t z * ∏ i, conj (C i t) := byrw [← Cx_ofReal]; unfold fsimp_rw [hc,H]rw [Cx_swap]apply congrArgfunext trw [Cx_lmul,Cx_prod p (fun _ x => conj (χ t (tag x)))]simp_rw [Cx_conj]; rflhave ht := Cx_norm Q (fun t => χ t z * ∏ i, conj (C i t))rw [← heq, Complex.norm_real, Real.norm_eq_abs] at htsimp_rw [norm_mul,Complex.norm_prod,hn,one_mul,Complex.norm_conj] at htexact le_trans (le_abs_self _) ht/-- Defect between two letter phases. -/def defect (tag : A → G) (χ : Θ → AddChar G ℂ) (a b : A) (t : Θ) :=1 - (χ t (tag a-tag b)).relemma defect_nonneg (tag : A → G) (χ : Θ → AddChar G ℂ) (hn : ∀ t x, ‖χ t x‖=1) (a b t) :0 ≤ defect tag χ a b t := byunfold defecthave H := Complex.abs_re_le_norm (χ t (tag a-tag b))rw [hn] at H; linarith [(abs_le.mp H).2]lemma defect_mean (tag : A → G) (χ : Θ → AddChar G ℂ) (hn : ∀ t x, ‖χ t x‖=1)(p : Law A) (t) :p.Ex (fun a => p.Ex (fun b => defect tag χ a b t)) =1- ‖p.Cx (fun a => χ t (tag a))‖^2 := byunfold defecthave h (a b : A) :(χ t) (tag a-tag b) = χ t (tag a)*conj (χ t (tag b)) := byrw [sub_eq_add_neg,(χ t).map_add_eq_mul,char_neg _ (hn t)]simp_rw [h,Ex_sub,Ex_const,sq_norm_Cx]/-- If the characteristic product has large integral, then it has large volume at thecorresponding defect level. -/lemma phase_region (Q : Law Θ) (f : I → Θ → ℝ) (hf : ∀ i t, 0 ≤ f i t ∧ f i t ≤ 1){E : ℝ} (he : 1 ≤ E) (h : exp (-(2*E)) ≤ Q.Ex fun t => ∏ i, f i t) :let A (x : Θ) := ∑ i, (1-f i x ^ 2)exp (-(3*E)) ≤ Q.prob fun x => A x ≤ 8*E := byclassicalintro Dlet S (x : Θ) := D x ≤ 8*Ehave h1 (x : ℝ) (hp : 0 ≤ x) : x ≤ exp (-(1-x^2)/2) := byhave hi := Real.add_one_le_exp (-(1-x^2))have hh := Real.exp_pos (-(1-x^2)/2)rw [show -(1-x^2)=-(1-x^2)/2+ -(1-x^2)/2 by ring,Real.exp_add] at hinlinarithhave hx (x : Θ) :(∏ i, f i x) ≤ (if S x then (1:ℝ) else 0)+ exp (-(4*E)) := bysplit_ifs with H· apply le_trans (b:=∏ i : I,(1:ℝ)) (Finset.prod_le_prod₀ (fun i _ => (hf i x).1)(fun i _ => (hf i x).2))simp [exp_nonneg]· apply le_trans (b:=∏ i, exp (-(1-f i x^2)/2)) (Finset.prod_le_prod₀(fun i _ => (hf i x).1) (fun i _ => h1 _ (hf _ _).1))have heq : ∑ i, (-(1-f i x^2)/2) = -(D x)/2 := byunfold D; rw [← Finset.sum_div,Finset.sum_neg_distrib]rw [← Real.exp_sum,heq,zero_add]apply exp_monotone; unfold S at H; linarithhave heq : Q.Ex (fun x => if S x then (1:ℝ) else 0) = Q.prob S := byunfold probcongr 1have H := Q.Ex_mono hxrw [Ex_add,heq,Ex_const] at Hhave hb : 2 ≤ exp E := le_trans (by linarith) (Real.add_one_le_exp E)have H1 := exp_nonneg (-(4*E))have H2 := exp_nonneg (-(3*E))have H3 : exp (-(2*E)) = exp (-(3*E))*exp E := by rw [← exp_add]; congr 1; ringhave H4 : exp (-(3*E)) = exp (-(4*E))*exp E := by rw [← exp_add]; congr 1; ringchange _ ≤ Q.prob Snlinarithlemma log_gap (P : Law A) [Nonempty A](s : Finset A)(hp : (1/2:ℝ) ≤ P.prob fun x => x ∈ s) :log (Fintype.card A) - log (s.card:ℝ) ≤2*(log (Fintype.card A)-P.entropy+log 2) := byclassicallet f (x : A) : Bool := decide (x ∈ s)let Q := P.send fhave h1 : P.entropy = Q.entropy +Q.Ex fun b => (P.after f b).entropy := byhave hI : P.H (fun x => (x,f x)) = P.entropy := byrw [← H_self]; apply H_partition; simprw [← hI,H_pair_chain,Hcond_after]simp_rw [H_self]rflhave hh : Q true = P.prob (fun x => x ∈ s) := byunfold Q; rw [ send_apply]congr; simp [f]have hPos : 0 < Q true := by rw [hh]; linarithhave hcard : 0 < (s.card:ℝ) := byobtain ⟨x,hx,_⟩ := (send_pos_iff P f true).mp hPoshave ht : x ∈ s := by simpa only [f,decide_eq_true_eq] using hxexact_mod_cast Finset.card_pos.mpr ⟨x,ht⟩let L := log (Fintype.card A)let T := log (s.card:ℝ)have hT : T ≤ L := Real.log_le_log hcard (by exact_mod_cast Finset.card_le_univ _)have H : (P.after f true).entropy ≤ T :=entropy_le_log_size _ s fun x hx => bysimpa only [f,decide_eq_true_eq] using ((after_mem hPos).mp hx).1have H' : (P.after f false).entropy ≤ L := entropy_le_log_card _have Hb : Q.entropy ≤ log 2 := by simpa using entropy_le_log_card Qhave HI : Q false + Q true = 1 := by simpa [Fintype.sum_bool,add_comm] using Q.totalrw [h1,Ex,Fintype.sum_bool]change L-T ≤ _have : L-T ≤ 2*(L-(Q.entropy+(Q true*(P.after f true).entropy + Q false*(P.after f false).entropy))+log 2) := byhave hPos' := Q.nonneg falserw [← hh] at hpnlinarith [mul_le_mul_of_nonneg_left H hPos.le,mul_le_mul_of_nonneg_left H' hPos', show Q false * L+ Q true * L=L by rw [← add_mul,HI,one_mul]]exact thislemma prob_half (P : Law Ω) (f : Ω → ℝ) (hn : ∀ x, 0 ≤ f x) (E : ℝ) (he : 0 < E)(hp : P.Ex f ≤ E) :(1/2:ℝ) ≤ P.prob fun x => f x ≤ 2*E := byclassicallet p (x : Ω) := f x ≤ 2*Elet F (x : Ω) := if ¬p x then 1 else (0:ℝ)have hh : P.Ex F = P.prob (fun x => ¬p x) := byapply congrArg (P.Ex)funext x; unfold Fsplit_ifs <;> simp_allrw [prob_compl] at hhhave hi (x : Ω) : 2*E * F x ≤ f x := byunfold F p; split_ifs with H· simp [hn x]· simp; linarithhave H := (P.Ex_mono hi).trans hprw [Ex_lmul, hh] at Hchange _ ≤ P.prob pnlinarithdef small_defects (tag : A → G) (χ : Θ → AddChar G ℂ) (Q : Law Θ)(L : ℝ) (s : Finset A) (a : A) (F : ℝ) : Prop :=∀ p : Law A, (∀ x, 0 < p x → x ∈ s) →exp (-F) ≤ Q.Ex fun t => exp ((-L)*p.Ex (fun x => defect tag χ x a t))lemma alignment (tag : A → G) (c : G → ℝ) (Q : Law Θ) (χ : Θ → AddChar G ℂ)(hn : ∀ t x, ‖χ t x‖=1)(hc : ∀ g, ((exp (-c g) : ℝ):ℂ)=Q.Cx (fun t => χ t g))(p : I → Law A) [Nonempty I] [Nonempty A] (z : G)(F D L : ℝ) (he : 1 ≤ F) (hd : 0 < D) (hL : 0 ≤ L)(hL' : L ≤ Fintype.card I)(hz : exp (-(2*F)) ≤ (pack p).Ex (fun x => exp (-c (z-tot tag x))))(hs : ∑ i, (log (Fintype.card A)-entropy (p i)) ≤ 2*(Fintype.card I*D)) :∃ (a : A) (s : Finset A), s.Nonempty ∧log (Fintype.card A) - log (s.card:ℝ) ≤ 8*D+2 ∧small_defects tag χ Q L s a (35*F) := byclassicallet f i (t : Θ) := ‖(p i).Cx (fun a => χ t (tag a))‖have hf1 (i : I) (t : Θ) : f i t ≤ 1 := norm_Cx_unit _ _ fun x => (hn _ _).lehave hf0 (i : I) (t : Θ) : 0 ≤ f i t := norm_nonneg _let W (x : Θ) : Prop := ∑ i, (1 - f i x ^ 2) ≤ 8*Fhave hh : exp (-(3*F)) ≤ Q.prob W := phase_region Q f (fun i t => ⟨hf0 _ _,hf1 _ _⟩)he (hz.trans (heat_prod _ _ _ _ hn hc p z))let P := Q.condP Whave hW : 0 < Q.prob W := lt_of_lt_of_le (exp_pos _) hhlet g (i : I) := P.Ex fun t => 1-f i t^2let A' (i : I) := log (Fintype.card A)-entropy (p i)have hgp (i : I) : 0 ≤ g i := Ex_nonneg P fun t => bynlinarith [hf1 i t,hf0 i t]let T := (Fintype.card I:ℝ)have ht : 0 < T := by unfold T; positivityhave hg : (uniform I).Ex g ≤ 8*F/T := byhave hi : ∑ i, g i ≤ 8*F := byunfold grw [← Ex_finset_sum]refine le_trans (b:=P.Ex fun _ => 8*F) (P.Ex_mono_mem fun x hx => ?_) (P.Ex_const _).leexact ((Law.condP_mem hW).mp hx).1simp_rw [Ex,uniform_apply,← Finset.mul_sum]exact le_trans (mul_le_mul_of_nonneg_left hi (inv_pos.mpr ht).le)(by dsimp [T]; rw [← div_eq_inv_mul])have ha : (uniform I).Ex A' ≤ 2*D := bysimp_rw [Ex,uniform_apply,← Finset.mul_sum,← div_eq_inv_mul]exact (div_le_iff₀ ht).mpr (by dsimp only [T,A']; linarith)obtain ⟨i, _,hi,hi'⟩ := average_two_below (uniform I) g A' (fun i _ => hgp i)(fun i _ => sub_nonneg.mpr (entropy_le_log_card _)) (8*F/T) (2*D)(by have := lt_of_lt_of_le zero_lt_one he; positivity) (by positivity) hg halet R := p ilet G (x y : A) := P.Ex (defect tag χ x y)have HG : R.Ex (fun y => R.Ex fun x => G x y) ≤ 16*F/T := byhave Heq : R.Ex (fun y => R.Ex fun x => G x y) = g i := byrw [Ex_swap]unfold Gsimp_rw [Ex_swap R P]unfold g fsimp_rw [defect_mean _ _ hn]rflrw [Heq]exact hi.trans (le_of_eq (by ring))obtain ⟨a,ha',ha''⟩ := R.exists_le_Ex (fun y => R.Ex fun x => G x y)let s := Finset.univ.filter fun x => G x a ≤ 2*(16*F/T)have ha0 : R.Ex (fun x => G x a) ≤ 16*F/T := ha''.trans HGhave hp : (1/2:ℝ) ≤ R.prob fun x => x ∈ s := bysimp only [s,Finset.mem_filter,Finset.mem_univ,true_and]exact prob_half _ _ (fun x => Ex_nonneg _ (fun y => defect_nonneg _ _ hn x a y))_ (by have := lt_of_lt_of_le zero_lt_one he; positivity) ha0obtain ⟨x,hx,_⟩ := (prob_pos_iff R (fun x => x∈s)).mp(lt_of_lt_of_le (by norm_num : (0:ℝ)<1/2) hp)refine ⟨a,s,⟨x,hx⟩,(log_gap R s hp).trans ?_,?_⟩· change log (Fintype.card A) - entropy R ≤ _ at hi'have hi := Real.log_le_sub_one_of_pos (x:=2) (by norm_num)linarithintro V hvlet v (t : Θ) := V.Ex fun x => defect tag χ x a thave hB : P.Ex v ≤ 32*F/T := byunfold v; rw [Ex_swap P V]refine le_trans (b:=V.Ex fun _ => 32*F/T) (V.Ex_mono_mem fun x hx => ?_)(V.Ex_const _).lehave H := (Finset.mem_filter.mp (hv x hx)).2change G x a ≤ _exact H.trans (le_of_eq (by ring))have H1 : P.Ex (fun t => exp ((-L)* v t)) ≥ exp (-(32*F)) := byhave H := Ex_exp P (fun t => (-L)*v t)rw [Ex_lmul] at Happly le_trans _ Happly exp_monotonehave hbp := (le_div_iff₀ ht).mp hBchange L ≤ T at hL'have hg1 : 0 ≤ P.Ex v :=P.Ex_nonneg fun t => V.Ex_nonneg fun x => defect_nonneg tag χ hn x a tnlinarithcalcexp (-(35*F)) = exp (-(3*F))*exp (-(32*F)) := by rw [← exp_add]; congr 1; ring_ ≤ Q.prob W * P.Ex (fun t => exp ((-L)*v t)) :=mul_le_mul hh H1 (exp_nonneg _) hW.le_ ≤ _ := bydsimp only [P]rw [prob_mul_Ex_condP]apply Q.Ex_mono; intro t; split_ifs <;> first | exact le_rfl | exact exp_nonneg _end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169import OAI.Analysis.FourierLLogL.Compress.Blocks/-! # Entropy increments along a prefix -/open Function Set Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {n m : ℕ} {α Ω G : Type} [Fintype α] [Fintype Ω] [Fintype G]def rateH (P : Law Ω) (X : Ω → Letters n α) (j : ℕ) :=if h : j < n then P.Hcond (readLetter X j h) (prefixB X j h.le) else 0lemma rate_lt (P : Law Ω) (X : Ω → Letters n α) {j : ℕ} (h : j < n) :rateH P X j = P.Hcond (readLetter X j h) (prefixB X j h.le) :=dite_eq_left hlemma H_prefix (P : Law Ω) (X : Ω → Letters n α) (l : ℕ) (h : l ≤ n) :P.H (prefixB X l h) = ∑ j ∈ Finset.range l, rateH P X j := byinduction l with| zero =>rw [prefix_zero, H_constant]; simp| succ l ih =>have hh := P.H_partition (X:=prefixB X (l+1) h)(Y:=fun x => (readLetter X l h x, prefixB X l (by omega) x))(by intro x y; simp only [Prod.mk.injEq]; exact prefix_last_partition X l h x y)rw [hh,H_pair_chain, ih, Finset.sum_range_succ, rate_lt _ _ h]lemma H_post_prefix (P : Law Ω) (X : Ω → Letters n α) (j l : ℕ) (h : j+l ≤ n) :let W := prefixB X j (by omega)(P.send W).Ex (fun w => (P.after W w).H (readBlock X j l h)) =∑ i ∈ Finset.range l, rateH P X (j+i) := byintro Wrw [← Hcond_after,Hcond]have H : P.H (prefixB X (j+l) h) = P.H (fun x => (readBlock X j l h x, W x)) := byrefine P.H_partition fun x y => ?_rw [prefix_partition, Prod.mk.injEq]exact and_commrw [← H,H_prefix]dsimp only [W]rw [H_prefix, Finset.sum_range_add]ringprivate abbrev S := WordSamplelemma conditional_block_exch {P : Law (S n α G)} (hp : exch P){j m} (hh : j+m ≤ n) (w : Letters j α) :exch ((P.after (prefixB Prod.fst j (by omega)) w).send (fun p =>(readBlock Prod.fst j m hh p,p.2))) := byapply exch_subSample_cond hp (offset j m hh) (offset_injective _ _ _)(offset 0 j (by omega))rintro i ⟨b,hb⟩have H := congrArg Fin.val hbsimp only [offset] at Homegalemma conditional_block_marg {P : Law (S n α G)} (hp : exch P){j m} (hh : j+m ≤ n) (w : Letters j α) (i : Fin m) :let R := P.after (prefixB Prod.fst j (by omega)) wR.send (fun x => readBlock Prod.fst j m hh x i) =R.send (readLetter Prod.fst j (by have := i.isLt; omega)) := byintro Rlet i₀ : Fin m := ⟨0,by have := i.isLt; omega⟩have he := same_marginal (conditional_block_exch hp hh w) i i₀simp only [send_send] at heexact helemma rate_antitone_succ {P : Law (S n α G)} (hp : exch P){j} (h : j+1 < n) : rateH P Prod.fst (j+1) ≤ rateH P Prod.fst j := bylet X : S n α G → Letters n α := Prod.fstlet W := prefixB X j (by omega)let V := prefixB X (j+1) h.lehave H : P.Hcond (readLetter X (j+1) h) W = P.Hcond (readLetter X j (by omega)) W := byrw [Hcond_after,Hcond_after]have HH (w) := conditional_block_marg hp (j:=j) (m:=2) (by omega) w (1:Fin 2)have hEq (w : Letters j α) :(P.after W w).send (readLetter X (j+1) h) =(P.after W w).send (readLetter X j (by omega)) := HH wsimp_rw [Law.H,hEq]rw [rate_lt _ _ h, rate_lt _ _ (by omega : j < n)]change P.Hcond _ V ≤ P.Hcond (readLetter X j _) Wrw [← H]apply Hcond_antitoneexact fun a b hh => ((prefix_last_partition X j (by omega) a b).mp hh).2lemma rate_antitone {P : Law (S n α G)} (hp : exch P) :Antitone (rateH P Prod.fst) := byrefine antitone_nat_of_succ_le fun k => ?_by_cases h : k+1<n· exact rate_antitone_succ hp hrw [rateH,dite_eq_right h]unfold rateHsplit· exact Hcond_nonneg _ _ _· exact le_rfllemma rate_bdd (P : Law Ω) (X : Ω → Letters n α) (j : ℕ) :rateH P X j ≤ log (Fintype.card α) := byrw [rateH]split· exact (Hcond_le_H P _ _).trans (H_card _ _)· cases Fintype.card α with| zero => simp| succ k => apply log_nonneg; simp/-- The joint divergence of the conditional block from the product of its row marginals. -/lemma avg_block_kl {P : Law (S n α G)} (hp : exch P){j m} (hh : j+m ≤ n) (hj : j<n) :let X : S n α G → Letters n α := Prod.fstlet W := prefixB X j hj.lelet V := readBlock X j m hh(P.send W).Ex (fun w =>let R := P.after W wkl (R.send V) (pack (fun _ : Fin m => R.send (readLetter X j hj)))) =∑ i ∈ Finset.range m, (rateH P X j - rateH P X (j+i)) := byintro X W Vlet f := readLetter X j hjlet A (w : Letters j α) := P.after W whave hk (w : Letters j α) :kl ((A w).send V) (pack (fun _ : Fin m => (A w).send f)) =(m:ℝ) * (A w).H f - (A w).H V := byhave hm (i : Fin m) := conditional_block_marg hp hh w ihave hm' (i : Fin m) :((A w).send V).send (fun x => x i) = (A w).send f := by rw [send_send]; exact hm ihave he : dominated ((A w).send V) (pack (fun _ : Fin m => (A w).send f)) := byintro x hxrw [pack_pos]intro irw [← hm' i]; exact send_pos _ _ hxrw [kl,crossE_pack he]simp_rw [hm']simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]rflchange (P.send W).Ex (fun w => kl ((A w).send V) (pack (fun _ : Fin m => (A w).send f))) = _have h1 : (P.send W).Ex (fun w => (A w).H f) = rateH P X j :=(rate_lt P X hj ▸ Hcond_after P f W).symmhave h2 : (P.send W).Ex (fun w => (A w).H V) = _ := H_post_prefix P X j m hhsimp_rw [hk,Ex_sub,Ex_lmul,h1,h2,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_range,nsmul_eq_mul]lemma kl_uniform {α : Type} [Fintype α] [Nonempty α](P : Law (Letters n α)) :P.kl (pack (fun _ : Fin n => uniform α)) =n*log (Fintype.card α) - P.entropy := byhave h : P.dominated (pack (fun _ => uniform α)) := byintro x _rw [pack_pos]intro irw [uniform_apply]positivityunfold klrw [crossE_pack h]simp_rw [crossE, uniform_apply, log_inv,neg_neg,Ex_const,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]lemma sum_deficit (P : Law Ω) [Nonempty α] (X : Ω → Letters n α) :∑ j ∈ Finset.range n, (log (Fintype.card α)-rateH P X j) =(P.send X).kl (pack (fun _ => uniform α)) := byhave h := H_prefix P X n le_rflrw [prefix_all] at hrw [Finset.sum_sub_distrib,kl_uniform,← h]simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; rflend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169import OAI.Analysis.FourierLLogL.Compress.Blocks/-! # Entropy increments along a prefix -/open Function Set Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {n m : ℕ} {α Ω G : Type} [Fintype α] [Fintype Ω] [Fintype G]def rateH (P : Law Ω) (X : Ω → Letters n α) (j : ℕ) :=if h : j < n then P.Hcond (readLetter X j h) (prefixB X j h.le) else 0lemma rate_lt (P : Law Ω) (X : Ω → Letters n α) {j : ℕ} (h : j < n) :rateH P X j = P.Hcond (readLetter X j h) (prefixB X j h.le) :=dite_eq_left hlemma H_prefix (P : Law Ω) (X : Ω → Letters n α) (l : ℕ) (h : l ≤ n) :P.H (prefixB X l h) = ∑ j ∈ Finset.range l, rateH P X j := byinduction l with| zero =>rw [prefix_zero, H_constant]; simp| succ l ih =>have hh := P.H_partition (X:=prefixB X (l+1) h)(Y:=fun x => (readLetter X l h x, prefixB X l (by omega) x))(by intro x y; simp only [Prod.mk.injEq]; exact prefix_last_partition X l h x y)rw [hh,H_pair_chain, ih, Finset.sum_range_succ, rate_lt _ _ h]lemma H_post_prefix (P : Law Ω) (X : Ω → Letters n α) (j l : ℕ) (h : j+l ≤ n) :let W := prefixB X j (by omega)(P.send W).Ex (fun w => (P.after W w).H (readBlock X j l h)) =∑ i ∈ Finset.range l, rateH P X (j+i) := byintro Wrw [← Hcond_after,Hcond]have H : P.H (prefixB X (j+l) h) = P.H (fun x => (readBlock X j l h x, W x)) := byrefine P.H_partition fun x y => ?_rw [prefix_partition, Prod.mk.injEq]exact and_commrw [← H,H_prefix]dsimp only [W]rw [H_prefix, Finset.sum_range_add]ringprivate abbrev S := WordSamplelemma conditional_block_exch {P : Law (S n α G)} (hp : exch P){j m} (hh : j+m ≤ n) (w : Letters j α) :exch ((P.after (prefixB Prod.fst j (by omega)) w).send (fun p =>(readBlock Prod.fst j m hh p,p.2))) := byapply exch_subSample_cond hp (offset j m hh) (offset_injective _ _ _)(offset 0 j (by omega))rintro i ⟨b,hb⟩have H := congrArg Fin.val hbsimp only [offset] at Homegalemma conditional_block_marg {P : Law (S n α G)} (hp : exch P){j m} (hh : j+m ≤ n) (w : Letters j α) (i : Fin m) :let R := P.after (prefixB Prod.fst j (by omega)) wR.send (fun x => readBlock Prod.fst j m hh x i) =R.send (readLetter Prod.fst j (by have := i.isLt; omega)) := byintro Rlet i₀ : Fin m := ⟨0,by have := i.isLt; omega⟩have he := same_marginal (conditional_block_exch hp hh w) i i₀simp only [send_send] at heexact helemma rate_antitone_succ {P : Law (S n α G)} (hp : exch P){j} (h : j+1 < n) : rateH P Prod.fst (j+1) ≤ rateH P Prod.fst j := bylet X : S n α G → Letters n α := Prod.fstlet W := prefixB X j (by omega)let V := prefixB X (j+1) h.lehave H : P.Hcond (readLetter X (j+1) h) W = P.Hcond (readLetter X j (by omega)) W := byrw [Hcond_after,Hcond_after]have HH (w) := conditional_block_marg hp (j:=j) (m:=2) (by omega) w (1:Fin 2)have hEq (w : Letters j α) :(P.after W w).send (readLetter X (j+1) h) =(P.after W w).send (readLetter X j (by omega)) := HH wsimp_rw [Law.H,hEq]rw [rate_lt _ _ h, rate_lt _ _ (by omega : j < n)]change P.Hcond _ V ≤ P.Hcond (readLetter X j _) Wrw [← H]apply Hcond_antitoneexact fun a b hh => ((prefix_last_partition X j (by omega) a b).mp hh).2lemma rate_antitone {P : Law (S n α G)} (hp : exch P) :Antitone (rateH P Prod.fst) := byrefine antitone_nat_of_succ_le fun k => ?_by_cases h : k+1<n· exact rate_antitone_succ hp hrw [rateH,dite_eq_right h]unfold rateHsplit· exact Hcond_nonneg _ _ _· exact le_rfllemma rate_bdd (P : Law Ω) (X : Ω → Letters n α) (j : ℕ) :rateH P X j ≤ log (Fintype.card α) := byrw [rateH]split· exact (Hcond_le_H P _ _).trans (H_card _ _)· cases Fintype.card α with| zero => simp| succ k => apply log_nonneg; simp/-- The joint divergence of the conditional block from the product of its row marginals. -/lemma avg_block_kl {P : Law (S n α G)} (hp : exch P){j m} (hh : j+m ≤ n) (hj : j<n) :let X : S n α G → Letters n α := Prod.fstlet W := prefixB X j hj.lelet V := readBlock X j m hh(P.send W).Ex (fun w =>let R := P.after W wkl (R.send V) (pack (fun _ : Fin m => R.send (readLetter X j hj)))) =∑ i ∈ Finset.range m, (rateH P X j - rateH P X (j+i)) := byintro X W Vlet f := readLetter X j hjlet A (w : Letters j α) := P.after W whave hk (w : Letters j α) :kl ((A w).send V) (pack (fun _ : Fin m => (A w).send f)) =(m:ℝ) * (A w).H f - (A w).H V := byhave hm (i : Fin m) := conditional_block_marg hp hh w ihave hm' (i : Fin m) :((A w).send V).send (fun x => x i) = (A w).send f := by rw [send_send]; exact hm ihave he : dominated ((A w).send V) (pack (fun _ : Fin m => (A w).send f)) := byintro x hxrw [pack_pos]intro irw [← hm' i]; exact send_pos _ _ hxrw [kl,crossE_pack he]simp_rw [hm']simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]rflchange (P.send W).Ex (fun w => kl ((A w).send V) (pack (fun _ : Fin m => (A w).send f))) = _have h1 : (P.send W).Ex (fun w => (A w).H f) = rateH P X j :=(rate_lt P X hj ▸ Hcond_after P f W).symmhave h2 : (P.send W).Ex (fun w => (A w).H V) = _ := H_post_prefix P X j m hhsimp_rw [hk,Ex_sub,Ex_lmul,h1,h2,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_range,nsmul_eq_mul]lemma kl_uniform {α : Type} [Fintype α] [Nonempty α](P : Law (Letters n α)) :P.kl (pack (fun _ : Fin n => uniform α)) =n*log (Fintype.card α) - P.entropy := byhave h : P.dominated (pack (fun _ => uniform α)) := byintro x _rw [pack_pos]intro irw [uniform_apply]positivityunfold klrw [crossE_pack h]simp_rw [crossE, uniform_apply, log_inv,neg_neg,Ex_const,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]lemma sum_deficit (P : Law Ω) [Nonempty α] (X : Ω → Letters n α) :∑ j ∈ Finset.range n, (log (Fintype.card α)-rateH P X j) =(P.send X).kl (pack (fun _ => uniform α)) := byhave h := H_prefix P X n le_rflrw [prefix_all] at hrw [Finset.sum_sub_distrib,kl_uniform,← h]simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; rflend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179import OAI.Analysis.FourierLLogL.Compress.Rent/-! # Data processing for contextual cost -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A B V W G E Ω Ω' : Type} [Fintype A] [Fintype B][Fintype V] [Fintype W] [Fintype G] [Fintype E] [Nonempty E][Fintype Ω] [Fintype Ω'] [AddCommGroup G] {n : ℕ}set_option linter.unusedSectionVars falselemma Hcond_congr {P : Law Ω} {X Y : Ω → A} {W W' : Ω → B}(h : ∀ a, 0 < P a → X a = Y a) (h' : ∀ a, 0 < P a → W a = W' a) :P.Hcond X W = P.Hcond Y W' := byunfold Hcondrw [H_congr_mem P h']congr 1refine H_congr_mem P fun a ha => ?_rw [h a ha,h' a ha]lemma rent_proj_eq (tag : B → G) (w : B → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → E) (σ : A → B) :let Y := ctxt σ Xrent (tag ∘ σ) (w ∘ σ) u c P X U =rent tag w u c P Y U +((∑ i, P.Hcond (readP X i) (readP Y i)) -P.Hcond X (fun x => (Y x, ans tag Y (fun a => u (U a)) x))) := byintro Ylet Z := ans tag Y (fun a => u (U a))have h1 (i : Fin n) :P.Hcond (readP X i) ((w ∘ σ) ∘ readP X i) =P.Hcond (readP X i) (readP Y i) + P.Hcond (readP Y i) (w ∘ readP Y i) := bylet R := (w ∘ readP Y i)have he := Hcond_reduce P (readP X i) R σchange P.Hcond _ R = _ + P.Hcond (readP Y i) Rrw [he]; congr 1apply Hcond_right_partitionsimp only [R,Y,ctxt,readP,comp_apply,Prod.mk.injEq]grindhave h2 :P.Hcond X (fun x => (Z x,ctxt w Y x)) =P.Hcond X (fun x => (Y x,Z x)) +P.Hcond Y (fun x => (Z x,ctxt w Y x)) := bynth_rw 1 [Hcond_reduce P X _ (fun v i => σ (v i))]congr 1apply Hcond_right_partitionintro a bsimp only [Prod.mk.injEq,Y,ctxt,funext_iff]grindunfold rentchange _ - P.Hcond X (fun x => (Z x,ctxt w Y x))+_ = _rw [h2]simp_rw [h1,Finset.sum_add_distrib]dsimp only [Z]ringlemma rent_projection (tag : B → G) (w : B → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → E) (σ : A → B) :rent tag w u c P (ctxt σ X) U ≤ rent (tag ∘ σ) (w ∘ σ) u c P X U := byrw [rent_proj_eq]refine le_add_of_nonneg_right (sub_nonneg.mpr ?_)let Y := ctxt σ Xlet Z (x : Ω) := (Y x,ans tag Y (fun x => u (U x)) x)refine (Hcond_vec_le P X Z).trans (Finset.sum_le_sum fun i _ => ?_)apply Hcond_antitoneintro a b hexact congrFun (congrArg Prod.fst h) ilemma rent_congr_mem (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(P : Law Ω) {X Y : Ω → Letters n A} (U : Ω → E)(h : ∀ x, 0 < P x → X x=Y x) :rent tag w u c P X U = rent tag w u c P Y U := byunfold rentsuffices H : ∑ i, P.Hcond (readP X i) (w ∘ readP X i) =∑ i, P.Hcond (readP Y i) (w ∘ readP Y i) byhave hh (x : Ω) (hx : 0 < P x) :(ans tag X (fun x => u (U x)) x, ctxt w X x) =(ans tag Y (fun x => u (U x)) x, ctxt w Y x) := byunfold ans ctxt; rw [h x hx]rw [H]have ht := Hcond_congr h (W:=fun x => (ans tag X (fun x => u (U x)) x, ctxt w X x))(W':=fun x => (ans tag Y (fun x => u (U x)) x, ctxt w Y x)) hhrw [ht]refine Finset.sum_congr rfl fun i _ => ?_apply Hcond_congr· exact fun x hx => congrFun (h x hx) _· exact fun x hx => congrArg w (congrFun (h x hx) _)lemma opt_proj (tag : B → G) (w : B → V) (u : E → G) (c : E → ℝ)(p : Law A) (σ : A → B) (n : ℕ) :opt n (p.send σ) tag w u c = opt n p (tag ∘ σ) (w ∘ σ) u c := byclassicalapply le_antisymm· obtain ⟨P,hP,he⟩ := (opt_spec n p (tag ∘ σ) (w ∘ σ) u c).1rw [← he]let X : WordSample n A E → Letters n A := Prod.fstexact (opt_le_rent tag w u c (p.send σ) P (ctxt σ X) Prod.snd fun i => byrw [← hP i,send_send]; rfl).trans (rent_projection tag w u c P _ _ _)obtain ⟨P,hP,he⟩ := (opt_spec n (p.send σ) tag w u c).1let X : WordSample n B E → Letters n B := Prod.fstlet Q x := pack (fun i : Fin n => p.after σ (X x i))let R := P.withNext Qlet Y : WordSample n B E × (Letters n A) → Letters n A := Prod.sndlet B0 (z : WordSample n B E × Letters n A) := X z.1let error (z : WordSample n B E × Letters n A) := z.1.2have hr : hasRows p R Y := byintro iapply ext_of_Ex; intro frw [Ex_send]change R.Ex (fun z => f (z.2 i)) = p.Ex funfold Rrw [Ex_withNext]simp_rw [Q, Ex_pack_proj _ i f]change P.Ex (fun x => (p.after σ (readP X i x)).Ex f) = _rw [← Ex_send P (readP X i) (fun b => (p.after σ b).Ex f),show P.send (readP X i) = _ from hP i]exact p.after_Ex_sum σ (fun _ => f)have heq (x : WordSample n B E × Letters n A) (hx : 0 < R x) : ctxt σ Y x = B0 x := byrcases x with ⟨a,b⟩change 0 < P a * Q a b at hxhave hpos : 0 < P a ∧ 0 < Q a b :=(mul_pos_iff.mp hx).resolve_right (by intro hh; linarith [hh.1,P.nonneg a])funext ihave hi := (pack_pos (fun i => p.after σ (X a i)) b).mp hpos.2 ihave hmarg := P.send_pos (readP X i) hpos.1rw [show P.send (readP X i) = _ from hP i] at hmargexact ((after_mem hmarg).mp hi).1have hsrc : rent tag w u c R B0 error = opt n (p.send σ) tag w u c := byhave h1 := send_fst_withNext P Qhave hi := rent_send tag w u c R X Prod.snd Prod.fstchange rent tag w u c (R.send Prod.fst) X Prod.snd = _ at hirw [h1] at hiexact hi.symm.trans herefine (opt_le_rent (tag ∘ σ) (w ∘ σ) u c p R Y error hr).trans ?_rw [rent_proj_eq]let B1 := ctxt σ Ylet Z (b : WordSample n B E × Letters n A) :=(B1 b, ans tag B1 (fun x => u (error x)) b)let Z0 (b : WordSample n B E × Letters n A) :=(B0 b, ans tag B0 (fun x => u (error x)) b)change rent tag w u c R B1 error + (_ - R.Hcond Y Z) ≤ _rw [rent_congr_mem tag w u c R error heq,hsrc]suffices H : ∑ i, R.Hcond (readP Y i) (readP B1 i) ≤ R.Hcond Y Z by linarithhave hZ : R.Hcond Y Z = R.Hcond Y Z0 :=Hcond_congr (fun _ _ => rfl) fun x hx => by unfold Z Z0 ans; rw [show B1 x = B0 x from heq x hx]rw [hZ]apply le_trans (b:=R.Hcond Y Prod.fst)· have H1 : R.Hcond Y Prod.fst = P.Ex (fun x => (Q x).entropy) := byhave H := Hcond_withNext' P Q (fun _ y => y)simpa only [H_self] using Hhave H2 (i : Fin n) : R.Hcond (readP Y i) (readP B1 i) = p.Hcond (fun a => a) σ := byrw [← hr i]rw [Hcond_send]; rflhave H3 (i : Fin n) :P.Ex (fun x => (p.after σ (X x i)).entropy) = p.Hcond (fun a => a) σ := byrw [Hcond_after]simp_rw [H_self]have hi := hP irw [← hi,Ex_send]; rflrw [H1]; simp_rw [Q,entropy_pack,H2,Ex_finset_sum,H3]; exact le_rfl· apply Hcond_antitonerintro ⟨a,b⟩ ⟨a',b'⟩ hcases (show a=a' from h)rfllemma opt_refined (tag : B → G) (w : B → V) (w' : A → W) (u : E → G) (c : E → ℝ)(p : Law A) (σ : A → B) (n : ℕ) (g : W → V) (h : w ∘ σ = g ∘ w') :opt n p (tag ∘ σ) w' u c ≤ opt n (p.send σ) tag w u c := byrw [opt_proj tag w]obtain ⟨P,hP,he⟩ := (opt_spec n p (tag ∘ σ) (w ∘ σ) u c).1exact (opt_le_rent _ _ _ _ p P _ _ hP).trans((rent_antitone _ w' (w ∘ σ) u c g h P Prod.fst Prod.snd).trans he.le)end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179import OAI.Analysis.FourierLLogL.Compress.Rent/-! # Data processing for contextual cost -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A B V W G E Ω Ω' : Type} [Fintype A] [Fintype B][Fintype V] [Fintype W] [Fintype G] [Fintype E] [Nonempty E][Fintype Ω] [Fintype Ω'] [AddCommGroup G] {n : ℕ}set_option linter.unusedSectionVars falselemma Hcond_congr {P : Law Ω} {X Y : Ω → A} {W W' : Ω → B}(h : ∀ a, 0 < P a → X a = Y a) (h' : ∀ a, 0 < P a → W a = W' a) :P.Hcond X W = P.Hcond Y W' := byunfold Hcondrw [H_congr_mem P h']congr 1refine H_congr_mem P fun a ha => ?_rw [h a ha,h' a ha]lemma rent_proj_eq (tag : B → G) (w : B → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → E) (σ : A → B) :let Y := ctxt σ Xrent (tag ∘ σ) (w ∘ σ) u c P X U =rent tag w u c P Y U +((∑ i, P.Hcond (readP X i) (readP Y i)) -P.Hcond X (fun x => (Y x, ans tag Y (fun a => u (U a)) x))) := byintro Ylet Z := ans tag Y (fun a => u (U a))have h1 (i : Fin n) :P.Hcond (readP X i) ((w ∘ σ) ∘ readP X i) =P.Hcond (readP X i) (readP Y i) + P.Hcond (readP Y i) (w ∘ readP Y i) := bylet R := (w ∘ readP Y i)have he := Hcond_reduce P (readP X i) R σchange P.Hcond _ R = _ + P.Hcond (readP Y i) Rrw [he]; congr 1apply Hcond_right_partitionsimp only [R,Y,ctxt,readP,comp_apply,Prod.mk.injEq]grindhave h2 :P.Hcond X (fun x => (Z x,ctxt w Y x)) =P.Hcond X (fun x => (Y x,Z x)) +P.Hcond Y (fun x => (Z x,ctxt w Y x)) := bynth_rw 1 [Hcond_reduce P X _ (fun v i => σ (v i))]congr 1apply Hcond_right_partitionintro a bsimp only [Prod.mk.injEq,Y,ctxt,funext_iff]grindunfold rentchange _ - P.Hcond X (fun x => (Z x,ctxt w Y x))+_ = _rw [h2]simp_rw [h1,Finset.sum_add_distrib]dsimp only [Z]ringlemma rent_projection (tag : B → G) (w : B → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → E) (σ : A → B) :rent tag w u c P (ctxt σ X) U ≤ rent (tag ∘ σ) (w ∘ σ) u c P X U := byrw [rent_proj_eq]refine le_add_of_nonneg_right (sub_nonneg.mpr ?_)let Y := ctxt σ Xlet Z (x : Ω) := (Y x,ans tag Y (fun x => u (U x)) x)refine (Hcond_vec_le P X Z).trans (Finset.sum_le_sum fun i _ => ?_)apply Hcond_antitoneintro a b hexact congrFun (congrArg Prod.fst h) ilemma rent_congr_mem (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(P : Law Ω) {X Y : Ω → Letters n A} (U : Ω → E)(h : ∀ x, 0 < P x → X x=Y x) :rent tag w u c P X U = rent tag w u c P Y U := byunfold rentsuffices H : ∑ i, P.Hcond (readP X i) (w ∘ readP X i) =∑ i, P.Hcond (readP Y i) (w ∘ readP Y i) byhave hh (x : Ω) (hx : 0 < P x) :(ans tag X (fun x => u (U x)) x, ctxt w X x) =(ans tag Y (fun x => u (U x)) x, ctxt w Y x) := byunfold ans ctxt; rw [h x hx]rw [H]have ht := Hcond_congr h (W:=fun x => (ans tag X (fun x => u (U x)) x, ctxt w X x))(W':=fun x => (ans tag Y (fun x => u (U x)) x, ctxt w Y x)) hhrw [ht]refine Finset.sum_congr rfl fun i _ => ?_apply Hcond_congr· exact fun x hx => congrFun (h x hx) _· exact fun x hx => congrArg w (congrFun (h x hx) _)lemma opt_proj (tag : B → G) (w : B → V) (u : E → G) (c : E → ℝ)(p : Law A) (σ : A → B) (n : ℕ) :opt n (p.send σ) tag w u c = opt n p (tag ∘ σ) (w ∘ σ) u c := byclassicalapply le_antisymm· obtain ⟨P,hP,he⟩ := (opt_spec n p (tag ∘ σ) (w ∘ σ) u c).1rw [← he]let X : WordSample n A E → Letters n A := Prod.fstexact (opt_le_rent tag w u c (p.send σ) P (ctxt σ X) Prod.snd fun i => byrw [← hP i,send_send]; rfl).trans (rent_projection tag w u c P _ _ _)obtain ⟨P,hP,he⟩ := (opt_spec n (p.send σ) tag w u c).1let X : WordSample n B E → Letters n B := Prod.fstlet Q x := pack (fun i : Fin n => p.after σ (X x i))let R := P.withNext Qlet Y : WordSample n B E × (Letters n A) → Letters n A := Prod.sndlet B0 (z : WordSample n B E × Letters n A) := X z.1let error (z : WordSample n B E × Letters n A) := z.1.2have hr : hasRows p R Y := byintro iapply ext_of_Ex; intro frw [Ex_send]change R.Ex (fun z => f (z.2 i)) = p.Ex funfold Rrw [Ex_withNext]simp_rw [Q, Ex_pack_proj _ i f]change P.Ex (fun x => (p.after σ (readP X i x)).Ex f) = _rw [← Ex_send P (readP X i) (fun b => (p.after σ b).Ex f),show P.send (readP X i) = _ from hP i]exact p.after_Ex_sum σ (fun _ => f)have heq (x : WordSample n B E × Letters n A) (hx : 0 < R x) : ctxt σ Y x = B0 x := byrcases x with ⟨a,b⟩change 0 < P a * Q a b at hxhave hpos : 0 < P a ∧ 0 < Q a b :=(mul_pos_iff.mp hx).resolve_right (by intro hh; linarith [hh.1,P.nonneg a])funext ihave hi := (pack_pos (fun i => p.after σ (X a i)) b).mp hpos.2 ihave hmarg := P.send_pos (readP X i) hpos.1rw [show P.send (readP X i) = _ from hP i] at hmargexact ((after_mem hmarg).mp hi).1have hsrc : rent tag w u c R B0 error = opt n (p.send σ) tag w u c := byhave h1 := send_fst_withNext P Qhave hi := rent_send tag w u c R X Prod.snd Prod.fstchange rent tag w u c (R.send Prod.fst) X Prod.snd = _ at hirw [h1] at hiexact hi.symm.trans herefine (opt_le_rent (tag ∘ σ) (w ∘ σ) u c p R Y error hr).trans ?_rw [rent_proj_eq]let B1 := ctxt σ Ylet Z (b : WordSample n B E × Letters n A) :=(B1 b, ans tag B1 (fun x => u (error x)) b)let Z0 (b : WordSample n B E × Letters n A) :=(B0 b, ans tag B0 (fun x => u (error x)) b)change rent tag w u c R B1 error + (_ - R.Hcond Y Z) ≤ _rw [rent_congr_mem tag w u c R error heq,hsrc]suffices H : ∑ i, R.Hcond (readP Y i) (readP B1 i) ≤ R.Hcond Y Z by linarithhave hZ : R.Hcond Y Z = R.Hcond Y Z0 :=Hcond_congr (fun _ _ => rfl) fun x hx => by unfold Z Z0 ans; rw [show B1 x = B0 x from heq x hx]rw [hZ]apply le_trans (b:=R.Hcond Y Prod.fst)· have H1 : R.Hcond Y Prod.fst = P.Ex (fun x => (Q x).entropy) := byhave H := Hcond_withNext' P Q (fun _ y => y)simpa only [H_self] using Hhave H2 (i : Fin n) : R.Hcond (readP Y i) (readP B1 i) = p.Hcond (fun a => a) σ := byrw [← hr i]rw [Hcond_send]; rflhave H3 (i : Fin n) :P.Ex (fun x => (p.after σ (X x i)).entropy) = p.Hcond (fun a => a) σ := byrw [Hcond_after]simp_rw [H_self]have hi := hP irw [← hi,Ex_send]; rflrw [H1]; simp_rw [Q,entropy_pack,H2,Ex_finset_sum,H3]; exact le_rfl· apply Hcond_antitonerintro ⟨a,b⟩ ⟨a',b'⟩ hcases (show a=a' from h)rfllemma opt_refined (tag : B → G) (w : B → V) (w' : A → W) (u : E → G) (c : E → ℝ)(p : Law A) (σ : A → B) (n : ℕ) (g : W → V) (h : w ∘ σ = g ∘ w') :opt n p (tag ∘ σ) w' u c ≤ opt n (p.send σ) tag w u c := byrw [opt_proj tag w]obtain ⟨P,hP,he⟩ := (opt_spec n p (tag ∘ σ) (w ∘ σ) u c).1exact (opt_le_rent _ _ _ _ p P _ _ hP).trans((rent_antitone _ w' (w ∘ σ) u c g h P Prod.fst Prod.snd).trans he.le)end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171import OAI.Analysis.FourierLLogL.Compress.Blocks/-! # Cost of a coupling of contextual rows -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A B U V W G Ω Ω' E : Type} [Fintype A] [Fintype B][Fintype U] [Fintype V] [Fintype W] [Fintype G] [Fintype E] [Nonempty E][AddCommGroup G] [Fintype Ω] [Fintype Ω']{I : Type} [Fintype I] [DecidableEq I] {n : ℕ}/-- Context part of a vector of full rows. -/def ctxt (w : A → V) (X : Ω → I → A) (a : Ω) (i : I) := w (X a i)def readP (X : Ω → I → A) (i : I) (a : Ω) : A := X a i/-- Contextual cost of a coupling with tag-sum output and random error ø of alphabet E. -/def rent (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω → I → A) (U : Ω → E) :=(∑ i, P.Hcond (readP X i) (w ∘ readP X i)) -P.Hcond X (fun a => (ans tag X (fun x => u (U x)) a, ctxt w X a)) +P.Ex (fun a => c (U a))def hasRows (p : Law A) (P : Law Ω) (X : Ω → I → A) : Prop :=∀ i, P.send (readP X i) = pomit [DecidableEq I] inlemma rent_first {P : Law Ω} {X : Ω → I → A} {p : Law A} (h : hasRows p P X)(w : A → V) :∑ i, P.Hcond (readP X i) (w ∘ readP X i) = Fintype.card I * p.Hcond (fun x => x) w := byhave heq (i : I) :P.Hcond (readP X i) (w ∘ readP X i) = p.Hcond (fun x => x) w := byrw [← h i,Hcond_send]; rflsimp_rw [heq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]omit [Fintype E] [Nonempty E] inlemma rent_nonneg (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(hc : ∀ x, 0 ≤ c x) (P : Law Ω) (X : Ω → I → A) (U : Ω → E) :0 ≤ rent tag w u c P X U := byrefine add_nonneg (sub_nonneg.mpr ?_) (P.Ex_nonneg fun a => hc _)refine (P.Hcond_vec_le X _).trans (Finset.sum_le_sum fun i _ => ?_)apply Hcond_antitoneintro a b hhexact congrFun (congrArg Prod.snd hh) iomit [Fintype E] [Nonempty E] inlemma rent_send (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω' → I → A) (U : Ω' → E) (b : Ω → Ω') :rent tag w u c (P.send b) X U = rent tag w u c P (fun a => X (b a)) (fun a => U (b a)) := byunfold rent; simp_rw [Hcond_send,Ex_send]rflomit [Fintype E] [Nonempty E] inlemma rent_cont (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(X : Ω → I → A) (U : Ω → E) :Continuous (fun P : Law Ω => rent tag w u c P X U) :=((continuous_finsetSum _ fun _ _ => continuous_Hcond _ _).sub (continuous_Hcond _ _)).add(continuous_Ex _)/-- Min rent uses r rows. -/def opt (n : ℕ) (p : Law A) (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ) :=sInf ((fun P : Law (WordSample n A E) => rent tag w u c P Prod.fst Prod.snd) ''{P | hasRows p P Prod.fst})lemma opt_spec (n : ℕ) (p : Law A) (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ) :let C (P : Law (WordSample n A E)) := rent tag w u c P Prod.fst Prod.snd(∃ P : Law (WordSample n A E), hasRows p P Prod.fst ∧ C P = opt n p tag w u c) ∧∀ P : Law (WordSample n A E), hasRows p P Prod.fst → opt n p tag w u c ≤ C P := byclassicalintro Clet s := {P : Law (WordSample n A E) | hasRows p P Prod.fst}have hs : IsCompact s := byapply IsClosed.isCompacthave heq : s = ⋂ i, {P | P.send (readP Prod.fst i) = p} := by ext; simp [s,hasRows]rw [heq]exact isClosed_iInter fun i => isClosed_eq (continuous_send _) continuous_constlet Q := pack fun _ : Fin n => pobtain ⟨e⟩ := (inferInstance : Nonempty E)have h1 : s.Nonempty := byrefine ⟨Q.send (fun x => (x,e)),fun i => ?_⟩rw [send_send]; exact marginalPack _ ihave hh := hs.image (rent_cont tag w u c Prod.fst Prod.snd)have H1 : (C '' s).Nonempty := h1.image _exact ⟨hh.sInf_mem H1,fun P h => csInf_le hh.bddBelow ⟨_, h,rfl⟩⟩lemma opt_le_rent (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(p : Law A) (P : Law Ω) (X : Ω → Fin n → A) (U : Ω → E) (h : hasRows p P X) :opt n p tag w u c ≤ rent tag w u c P X U := bylet Q := P.send (fun a => (X a,U a))have hh := (opt_spec n p tag w u c).2 Q (byintro idsimp only [Q]; rw [send_send]; exact h i)dsimp only [Q] at hhrw [rent_send] at hhexact hhlemma opt_nonneg (n : ℕ) (p : Law A) (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(hc : ∀ x, 0 ≤ c x) : 0 ≤ opt n p tag w u c := byobtain ⟨P,_,he⟩ := (opt_spec n p tag w u c).1rw [← he]exact rent_nonneg tag w u c hc P _ _lemma Hcond_function (P : Law Ω) (X : Ω → A) (W : A → V) :P.Hcond X (fun x => W (X x)) = P.H X - P.H (fun x => W (X x)) := byunfold Hcondcongr 1apply H_partitionsimp [Prod.mk.injEq]; grind/-- Chain rule for deterministic reduction f(X). -/lemma Hcond_reduce (P : Law Ω) (X : Ω → A) (W : Ω → V) (f : A → B) :P.Hcond X W = P.Hcond X (fun x => (f (X x),W x)) + P.Hcond (fun x => f (X x)) W := byrw [← Hcond_chain P X (fun x => f (X x)) W]unfold Hcondcongr 1refine H_partition _ fun a b => ?_simp only [Prod.mk.injEq]constructor <;> grindomit [Fintype E] [Nonempty E] in/-- Improving contexts, for the same full rows and tag, reduces the rent. -/lemma rent_antitone (tag : A → G) (w : A → V) (w' : A → W) (u : E → G) (c : E → ℝ)(p : V → W) (h : w' = p ∘ w)(P : Law Ω) (X : Ω → I → A) (U : Ω → E) :rent tag w u c P X U ≤ rent tag w' u c P X U := bysubst w'let Y := ans tag X (fun x => u (U x))let W₁ := ctxt w Xlet W₂ := ctxt (p ∘ w) Xhave h (i : I) : P.Hcond (readP X i) ((p ∘ w) ∘ readP X i) =P.Hcond (readP X i) (w ∘ readP X i) + P.Hcond (readP W₁ i) (readP W₂ i) := byhave h1 := Hcond_function P (readP X i) (p ∘ w)have h2 := Hcond_function P (readP X i) whave h3 := Hcond_function P (readP W₁ i) pchange P.Hcond (readP X i) (fun x => p (w ((readP X i) x))) = _dsimp only [comp_apply] at h1rw [h1]change _ = P.Hcond (readP X i) (fun x => w ((readP X i) x)) +P.Hcond (readP W₁ i) (fun x => p (readP W₁ i x))rw [h2,h3]; simp only [W₁]; unfold readP ctxt; ringlet vmap (x : I → A) (i : I) := w (x i)let Z₁ (x : Ω) := (Y x,W₁ x)let Z₂ (x : Ω) := (Y x,W₂ x)have hz : P.Hcond X Z₂ = P.Hcond X Z₁ + P.Hcond W₁ Z₂ := bynth_rw 1 [Hcond_reduce P X Z₂ vmap]have H : P.Hcond X (fun x => (vmap (X x), Z₂ x)) = P.Hcond X Z₁ := byapply Hcond_right_partitionintro a bsimp only [Z₁,Z₂,W₁,W₂,ctxt,vmap,Prod.mk.injEq,funext_iff,comp_apply]constructor· tauto· rintro ⟨hh,hx⟩simp [hx,hh]rw [H]; rflhave H : P.Hcond W₁ Z₂ ≤ ∑ i, P.Hcond (readP W₁ i) (readP W₂ i) := byrefine (P.Hcond_vec_le W₁ Z₂).trans (Finset.sum_le_sum fun i _ => ?_)exact Hcond_antitone P _ fun _ _ hh => congrFun (congrArg Prod.snd hh) iunfold rentrefine add_le_add_left ?_ _change _ - P.Hcond X Z₁ ≤ _ - P.Hcond X Z₂rw [hz]simp_rw [h,Finset.sum_add_distrib]linarithend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171import OAI.Analysis.FourierLLogL.Compress.Blocks/-! # Cost of a coupling of contextual rows -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A B U V W G Ω Ω' E : Type} [Fintype A] [Fintype B][Fintype U] [Fintype V] [Fintype W] [Fintype G] [Fintype E] [Nonempty E][AddCommGroup G] [Fintype Ω] [Fintype Ω']{I : Type} [Fintype I] [DecidableEq I] {n : ℕ}/-- Context part of a vector of full rows. -/def ctxt (w : A → V) (X : Ω → I → A) (a : Ω) (i : I) := w (X a i)def readP (X : Ω → I → A) (i : I) (a : Ω) : A := X a i/-- Contextual cost of a coupling with tag-sum output and random error ø of alphabet E. -/def rent (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω → I → A) (U : Ω → E) :=(∑ i, P.Hcond (readP X i) (w ∘ readP X i)) -P.Hcond X (fun a => (ans tag X (fun x => u (U x)) a, ctxt w X a)) +P.Ex (fun a => c (U a))def hasRows (p : Law A) (P : Law Ω) (X : Ω → I → A) : Prop :=∀ i, P.send (readP X i) = pomit [DecidableEq I] inlemma rent_first {P : Law Ω} {X : Ω → I → A} {p : Law A} (h : hasRows p P X)(w : A → V) :∑ i, P.Hcond (readP X i) (w ∘ readP X i) = Fintype.card I * p.Hcond (fun x => x) w := byhave heq (i : I) :P.Hcond (readP X i) (w ∘ readP X i) = p.Hcond (fun x => x) w := byrw [← h i,Hcond_send]; rflsimp_rw [heq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]omit [Fintype E] [Nonempty E] inlemma rent_nonneg (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(hc : ∀ x, 0 ≤ c x) (P : Law Ω) (X : Ω → I → A) (U : Ω → E) :0 ≤ rent tag w u c P X U := byrefine add_nonneg (sub_nonneg.mpr ?_) (P.Ex_nonneg fun a => hc _)refine (P.Hcond_vec_le X _).trans (Finset.sum_le_sum fun i _ => ?_)apply Hcond_antitoneintro a b hhexact congrFun (congrArg Prod.snd hh) iomit [Fintype E] [Nonempty E] inlemma rent_send (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(P : Law Ω) (X : Ω' → I → A) (U : Ω' → E) (b : Ω → Ω') :rent tag w u c (P.send b) X U = rent tag w u c P (fun a => X (b a)) (fun a => U (b a)) := byunfold rent; simp_rw [Hcond_send,Ex_send]rflomit [Fintype E] [Nonempty E] inlemma rent_cont (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(X : Ω → I → A) (U : Ω → E) :Continuous (fun P : Law Ω => rent tag w u c P X U) :=((continuous_finsetSum _ fun _ _ => continuous_Hcond _ _).sub (continuous_Hcond _ _)).add(continuous_Ex _)/-- Min rent uses r rows. -/def opt (n : ℕ) (p : Law A) (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ) :=sInf ((fun P : Law (WordSample n A E) => rent tag w u c P Prod.fst Prod.snd) ''{P | hasRows p P Prod.fst})lemma opt_spec (n : ℕ) (p : Law A) (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ) :let C (P : Law (WordSample n A E)) := rent tag w u c P Prod.fst Prod.snd(∃ P : Law (WordSample n A E), hasRows p P Prod.fst ∧ C P = opt n p tag w u c) ∧∀ P : Law (WordSample n A E), hasRows p P Prod.fst → opt n p tag w u c ≤ C P := byclassicalintro Clet s := {P : Law (WordSample n A E) | hasRows p P Prod.fst}have hs : IsCompact s := byapply IsClosed.isCompacthave heq : s = ⋂ i, {P | P.send (readP Prod.fst i) = p} := by ext; simp [s,hasRows]rw [heq]exact isClosed_iInter fun i => isClosed_eq (continuous_send _) continuous_constlet Q := pack fun _ : Fin n => pobtain ⟨e⟩ := (inferInstance : Nonempty E)have h1 : s.Nonempty := byrefine ⟨Q.send (fun x => (x,e)),fun i => ?_⟩rw [send_send]; exact marginalPack _ ihave hh := hs.image (rent_cont tag w u c Prod.fst Prod.snd)have H1 : (C '' s).Nonempty := h1.image _exact ⟨hh.sInf_mem H1,fun P h => csInf_le hh.bddBelow ⟨_, h,rfl⟩⟩lemma opt_le_rent (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(p : Law A) (P : Law Ω) (X : Ω → Fin n → A) (U : Ω → E) (h : hasRows p P X) :opt n p tag w u c ≤ rent tag w u c P X U := bylet Q := P.send (fun a => (X a,U a))have hh := (opt_spec n p tag w u c).2 Q (byintro idsimp only [Q]; rw [send_send]; exact h i)dsimp only [Q] at hhrw [rent_send] at hhexact hhlemma opt_nonneg (n : ℕ) (p : Law A) (tag : A → G) (w : A → V) (u : E → G) (c : E → ℝ)(hc : ∀ x, 0 ≤ c x) : 0 ≤ opt n p tag w u c := byobtain ⟨P,_,he⟩ := (opt_spec n p tag w u c).1rw [← he]exact rent_nonneg tag w u c hc P _ _lemma Hcond_function (P : Law Ω) (X : Ω → A) (W : A → V) :P.Hcond X (fun x => W (X x)) = P.H X - P.H (fun x => W (X x)) := byunfold Hcondcongr 1apply H_partitionsimp [Prod.mk.injEq]; grind/-- Chain rule for deterministic reduction f(X). -/lemma Hcond_reduce (P : Law Ω) (X : Ω → A) (W : Ω → V) (f : A → B) :P.Hcond X W = P.Hcond X (fun x => (f (X x),W x)) + P.Hcond (fun x => f (X x)) W := byrw [← Hcond_chain P X (fun x => f (X x)) W]unfold Hcondcongr 1refine H_partition _ fun a b => ?_simp only [Prod.mk.injEq]constructor <;> grindomit [Fintype E] [Nonempty E] in/-- Improving contexts, for the same full rows and tag, reduces the rent. -/lemma rent_antitone (tag : A → G) (w : A → V) (w' : A → W) (u : E → G) (c : E → ℝ)(p : V → W) (h : w' = p ∘ w)(P : Law Ω) (X : Ω → I → A) (U : Ω → E) :rent tag w u c P X U ≤ rent tag w' u c P X U := bysubst w'let Y := ans tag X (fun x => u (U x))let W₁ := ctxt w Xlet W₂ := ctxt (p ∘ w) Xhave h (i : I) : P.Hcond (readP X i) ((p ∘ w) ∘ readP X i) =P.Hcond (readP X i) (w ∘ readP X i) + P.Hcond (readP W₁ i) (readP W₂ i) := byhave h1 := Hcond_function P (readP X i) (p ∘ w)have h2 := Hcond_function P (readP X i) whave h3 := Hcond_function P (readP W₁ i) pchange P.Hcond (readP X i) (fun x => p (w ((readP X i) x))) = _dsimp only [comp_apply] at h1rw [h1]change _ = P.Hcond (readP X i) (fun x => w ((readP X i) x)) +P.Hcond (readP W₁ i) (fun x => p (readP W₁ i x))rw [h2,h3]; simp only [W₁]; unfold readP ctxt; ringlet vmap (x : I → A) (i : I) := w (x i)let Z₁ (x : Ω) := (Y x,W₁ x)let Z₂ (x : Ω) := (Y x,W₂ x)have hz : P.Hcond X Z₂ = P.Hcond X Z₁ + P.Hcond W₁ Z₂ := bynth_rw 1 [Hcond_reduce P X Z₂ vmap]have H : P.Hcond X (fun x => (vmap (X x), Z₂ x)) = P.Hcond X Z₁ := byapply Hcond_right_partitionintro a bsimp only [Z₁,Z₂,W₁,W₂,ctxt,vmap,Prod.mk.injEq,funext_iff,comp_apply]constructor· tauto· rintro ⟨hh,hx⟩simp [hx,hh]rw [H]; rflhave H : P.Hcond W₁ Z₂ ≤ ∑ i, P.Hcond (readP W₁ i) (readP W₂ i) := byrefine (P.Hcond_vec_le W₁ Z₂).trans (Finset.sum_le_sum fun i _ => ?_)exact Hcond_antitone P _ fun _ _ hh => congrFun (congrArg Prod.snd hh) iunfold rentrefine add_le_add_left ?_ _change _ - P.Hcond X Z₁ ≤ _ - P.Hcond X Z₂rw [hz]simp_rw [h,Finset.sum_add_distrib]linarithend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205import OAI.Analysis.FourierLLogL.Compress.Searchimport OAI.Analysis.FourierLLogL.Compress.Fraction/-! # Using the refinement search -/open Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realprivate lemma any_above {f : ℕ → ℝ} {k : ℕ} (a : ℝ)(h : k*a < ∑ i ∈ Finset.range k, f i) :∃ i < k, a < f i := byby_contra! hhhave he : ∑ i ∈ Finset.range k, f i ≤ ∑ i ∈ Finset.range k, a :=Finset.sum_le_sum fun i hi => hh i (Finset.mem_range.mp hi)simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at helinarithprivate lemma exists_offer (k m : ℕ) (hkm : k ≤ m) (hmp : 0 < m)(d c : ℕ → ℝ) (τ p : ℝ) (hT : 0 < τ) (hp : 0 ≤ p)(h : τ < ∑ i ∈ Finset.range k, d i) (h1 : ∑ i ∈ Finset.range k, c i = τ*p)(hg : ∀ i, 0 ≤ c i) :∃ i < k, τ/(2*m) ≤ d i ∧ c i ≤ 2*p*d i := byhave hpos : (0:ℝ) < m := by exact_mod_cast hmplet v := τ/(2*m)have hv : 0 ≤ v := by unfold v; positivityhave HH : k*v ≤ τ/2 := calc_ ≤ (m:ℝ)*v := by gcongr_ = τ/2 := by unfold v; field_simpobtain hs|hs := eq_or_lt_of_le hp· obtain ⟨i,hi,hb⟩ := any_above v (f:=d) (k:=k) (by linarith)refine ⟨i,hi,hb.le,?_⟩have he := Finset.single_le_sum (fun i (_ : i ∈ Finset.range k) => hg i)(Finset.mem_range.mpr hi)rw [← hs] at h1 ⊢linarithobtain ⟨i,hi,hb⟩ := any_above v (f:=fun i => d i - c i/(2*p)) (k:=k) (byrw [Finset.sum_sub_distrib, ← Finset.sum_div,h1]rw [show τ*p/(2*p)=τ/2 by field_simp]linarith)have hn : 0 ≤ c i/(2*p) := by have := hg i; positivityrefine ⟨i,hi,le_of_lt (by linarith),?_⟩have hI : c i/(2*p) ≤ d i := by linarithhave he := (div_le_iff₀ (show 0 < 2*p by positivity)).mp hIlinarith/-- Parameters of the two-order search. -/structure Schedule whereN : ℕq : ℕn : ℕN0 : 0 < Nq0 : 0 < qn0 : 0 < nu : ℝa : ℝδ : ℝη : ℝα : ℝε : ℝu0 : 0 < ua0 : 0 < ad0 : 0 < δheta : δ*exp (2*u/a) ≤ ηhn : 1 < (n:ℝ)*δhα : 0 < αhε : 0 < εhβ : 2*(a/α) ≤ 1hc : (ε+η)*exp (2*(a/α)*q) ≤ 1hq : 1 < (q:ℝ)*uht : 1 < (N:ℝ)*εnamespace Scheduledef size (w : Schedule) := w.N*(w.q*w.n)def loss (w : Schedule) := 2*w.α+w.a*(1+w.η)lemma loss_pos (w : Schedule) : 0 < w.loss := byhave H := lt_of_lt_of_le (mul_pos w.d0 (exp_pos _)) w.hetaunfold loss; nlinarith [w.hα,w.a0]end Schedulevariable {A G : Type} [Fintype A] [Fintype G] [AddCommGroup G]lemma offer_at (tag : A→G) (hi : Injective tag) (c : G→ℝ) (s : Labelled A)(D F : ℝ) (hd : 0 < D) (hf : 0 < F) (r l u M : ℕ) (hl : l ≤ u) (hu : u ≤ M)(hm : 0 < M) (hno : F+fundK tag c s l r < fundK tag c s u r)(x : ℝ) (hx : 0 < x) (hb : x ≤ F/D/(2*M)) :∃ t, refines t s ∧x ≤ fundI tag s r / D - fundI tag t r / D ∧F/D * (fundG tag s 1 / D - fundG tag t 1 / D) ≤2*(fundG tag s u/D-fundG tag s l/D)*x := bylet g n := fundG tag s n/Dlet a t := fundI tag t r/Dlet τ := F/Dlet T m := observe tag s (l+m)let k := u-llet f m := a s - a (T m)let b m := τ*(fundG tag s 1/D - fundG tag (T m) 1 / D)let K n := fundK tag c s n rhave hg : Monotone g := fun i j hh => div_le_div_of_nonneg_right(fundG_mono tag s hh) hd.lehave hτ : 0 < τ := div_pos hf hdhave h1 : τ < ∑ i ∈ Finset.range k, f i := byhave hc (i : ℕ) : K (l+(i+1))/D-K (l+i)/D ≤ f i := byhave hh := observe_save tag c s (l+i) runfold K f a T; rw [← sub_div, ← sub_div,← Nat.add_assoc]exact div_le_div_of_nonneg_right (by linarith) hd.lerefine lt_of_lt_of_le ?_ (Finset.sum_le_sum (fun i _ => hc i))rw [Finset.sum_range_sub (fun i => K (l+i)/D)]unfold k τ Krw [Nat.add_zero,Nat.add_sub_of_le hl, ← sub_div]gcongr; linarithhave heq (i : ℕ) : b i = τ*(g (l+(i+1))-g (l+i)) := byunfold b g Trw [← sub_div,observe_cost tag hi s (l+i),← sub_div,Nat.add_assoc]have h2 : ∑ i ∈ Finset.range k, b i = τ*(g u-g l) := bysimp_rw [heq,← Finset.mul_sum]rw [Finset.sum_range_sub (fun i => g (l+i))]simp only [k,Nat.add_sub_of_le hl,Nat.add_zero]obtain ⟨i,hh,hI,hJ⟩ := exists_offer k M (by omega) hm f b τ (g u-g l)hτ (sub_nonneg.mpr (hg hl)) h1 h2 (byintro i; rw [heq]; exact mul_nonneg hτ.le (sub_nonneg.mpr (hg (by omega))))have hX : x ≤ f i := le_trans hb hIhave Hf : 0 < f i := lt_of_lt_of_le hx hXlet y := x/f ihave hy0 : 0 ≤ y := (div_pos hx Hf).lehave hy1 : y ≤ 1 := (div_le_one Hf).mpr hXrefine ⟨blend (T i) s y hy0 hy1,blend_refines _ _ _ (observe_refines _ _ _) (refines_refl s) _ _ _, ?_,?_⟩· have hh := blend_I tag (T i) s y hy0 hy1 rhave hi := div_le_div_of_nonneg_right hh hd.lehave He : y*f i=x := div_mul_cancel₀ _ Hf.ne'unfold f a at He; rw [add_div,mul_div_assoc,mul_div_assoc] at hilinarith· rw [blend_G1 tag hi _ _ _]change τ*_ ≤ 2*(g u-g l)*xcalc_ = y*b i := by unfold b; ring_ ≤ y*(2*(g u-g l)*f i) := mul_le_mul_of_nonneg_left hJ hy0_ = _ := by rw [mul_left_comm,show y*f i=x from div_mul_cancel₀ _ Hf.ne']/-- Reach a long, low-cost block length. -/theorem reach (tag : A → G) (hi : Injective tag) (c : G → ℝ) (_hc0 : ∀ x, 0 ≤ c x)(S : Labelled A) (D F : ℝ) (hd : 0 < D) (hf : 0 < F) (B : Schedule)(m : ℕ) (l u r : ℕ → ℕ) (hm : 0 < m)(hl : ∀ i, i < B.size → l i ≤ u i ∧ u i ≤ m)(hp : ∀ i j, i < j → j < B.size → u j ≤ l i ∧ r i ≤ r j)(hG : ∀ i, i<B.size → fundG tag S (u i) ≤ D)(hI : ∀ i, i<B.size → fundI tag S (r i) ≤ D) :∃ T, refines T S ∧ fundG tag S 1 - fundG tag T 1 ≤ B.loss*D*D/F ∧∃ i, i < B.size ∧ fundK tag c T (u i) (r i) ≤ F+fundK tag c T (l i) (r i) := bylet Ω := {p // refines p S}let τ := F/Dhave hτ : 0 < τ := div_pos hf hdlet g (i : ℕ) (x : Ω) := fundG tag x.val i / Dlet a (i : ℕ) (x : Ω) := fundI tag x.val (r i) / Dlet v : Arena Ω :={ N := B.sizemov := fun s t => refines t.val s.valrefl := fun s => refines_refl _trans := fun h1 h2 => refines_trans h2 h1topc := fun x => τ*g 1 xpay := fun {x y} hh => mul_le_mul_of_nonneg_left (div_le_div_of_nonneg_right(G_anti tag hh 1) hd.le) hτ.leA := aAlo := fun s i _ => div_nonneg (opt_nonneg _ s.val.law (tag ∘ Prod.fst) Prod.snd(fun _ : Unit => 0) (fun _ => 0) (fun _ => le_refl _)) hd.leAhi := fun s i hi => (div_le_one hd).mpr ((I_anti tag s.property _).trans (hI i hi))Am := fun s {i j} hij hj => byobtain h|h := eq_or_lt_of_le hij· subst i; exact le_rfl· exact div_le_div_of_nonneg_right (fundI_mono tag _ (hp i j h hj).2) hd.leAs := fun {x y} h _ _ => div_le_div_of_nonneg_right (I_anti _ h _) hd.leL := fun i => g (l i)H := fun i => g (u i)Llo := fun s i h => div_nonneg (show 0 ≤ fundG tag s.val (l i) from Hcond_nonneg _ _ _) hd.leHhi := fun s i hi => (div_le_one hd).mpr ((G_anti tag s.property _).trans (hG i hi))LH := fun s i h => div_le_div_of_nonneg_right (fundG_mono _ _ (hl i h).1) hd.leBC := fun s {i j} h hb => div_le_div_of_nonneg_right (fundG_mono _ _ (hp i j h hb).1) hd.leLs := fun {s t} h i _ => div_le_div_of_nonneg_right (G_anti _ h _) hd.leHs := fun {s t} h i _ => div_le_div_of_nonneg_right (G_anti _ h _) hd.lefound := fun s => ∃ i, i < B.size ∧ fundK tag c s.val (u i) (r i) ≤ F +fundK tag c s.val (l i) (r i)rate := τ/(2*m)r0 := by have : (0:ℝ) < m := by exact_mod_cast hmpositivityoffer := byintro s i hb h x hx hx'obtain ⟨Q,hQ,h1,h2⟩ := offer_at tag hi c s.val D F hd hf (r i) (l i) (u i)m (hl i hb).1 (hl i hb).2 hm (lt_of_not_ge (fun hh => h ⟨i,hb,hh⟩)) x hx hx'exact ⟨⟨Q,refines_trans hQ s.property⟩,hQ,h1,by rwa [← mul_sub]⟩ }obtain ⟨t,ht,hc,hP⟩ :=v.complete_search ⟨S,refines_refl S⟩ B.N B.q B.n B.n0 B.q0 B.N0 le_rflB.u B.a B.δ B.η B.α B.ε B.u0 B.a0 B.d0 B.heta B.hn B.hα B.hε B.hβ B.hc B.hq B.htrefine ⟨t.val,t.property,?_,hc⟩change F/D * (fundG tag S 1 / D) - F/D*(fundG tag t.val 1 / D) ≤ B.loss at hPfield_simp at *linarithend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205import OAI.Analysis.FourierLLogL.Compress.Searchimport OAI.Analysis.FourierLLogL.Compress.Fraction/-! # Using the refinement search -/open Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realprivate lemma any_above {f : ℕ → ℝ} {k : ℕ} (a : ℝ)(h : k*a < ∑ i ∈ Finset.range k, f i) :∃ i < k, a < f i := byby_contra! hhhave he : ∑ i ∈ Finset.range k, f i ≤ ∑ i ∈ Finset.range k, a :=Finset.sum_le_sum fun i hi => hh i (Finset.mem_range.mp hi)simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at helinarithprivate lemma exists_offer (k m : ℕ) (hkm : k ≤ m) (hmp : 0 < m)(d c : ℕ → ℝ) (τ p : ℝ) (hT : 0 < τ) (hp : 0 ≤ p)(h : τ < ∑ i ∈ Finset.range k, d i) (h1 : ∑ i ∈ Finset.range k, c i = τ*p)(hg : ∀ i, 0 ≤ c i) :∃ i < k, τ/(2*m) ≤ d i ∧ c i ≤ 2*p*d i := byhave hpos : (0:ℝ) < m := by exact_mod_cast hmplet v := τ/(2*m)have hv : 0 ≤ v := by unfold v; positivityhave HH : k*v ≤ τ/2 := calc_ ≤ (m:ℝ)*v := by gcongr_ = τ/2 := by unfold v; field_simpobtain hs|hs := eq_or_lt_of_le hp· obtain ⟨i,hi,hb⟩ := any_above v (f:=d) (k:=k) (by linarith)refine ⟨i,hi,hb.le,?_⟩have he := Finset.single_le_sum (fun i (_ : i ∈ Finset.range k) => hg i)(Finset.mem_range.mpr hi)rw [← hs] at h1 ⊢linarithobtain ⟨i,hi,hb⟩ := any_above v (f:=fun i => d i - c i/(2*p)) (k:=k) (byrw [Finset.sum_sub_distrib, ← Finset.sum_div,h1]rw [show τ*p/(2*p)=τ/2 by field_simp]linarith)have hn : 0 ≤ c i/(2*p) := by have := hg i; positivityrefine ⟨i,hi,le_of_lt (by linarith),?_⟩have hI : c i/(2*p) ≤ d i := by linarithhave he := (div_le_iff₀ (show 0 < 2*p by positivity)).mp hIlinarith/-- Parameters of the two-order search. -/structure Schedule whereN : ℕq : ℕn : ℕN0 : 0 < Nq0 : 0 < qn0 : 0 < nu : ℝa : ℝδ : ℝη : ℝα : ℝε : ℝu0 : 0 < ua0 : 0 < ad0 : 0 < δheta : δ*exp (2*u/a) ≤ ηhn : 1 < (n:ℝ)*δhα : 0 < αhε : 0 < εhβ : 2*(a/α) ≤ 1hc : (ε+η)*exp (2*(a/α)*q) ≤ 1hq : 1 < (q:ℝ)*uht : 1 < (N:ℝ)*εnamespace Scheduledef size (w : Schedule) := w.N*(w.q*w.n)def loss (w : Schedule) := 2*w.α+w.a*(1+w.η)lemma loss_pos (w : Schedule) : 0 < w.loss := byhave H := lt_of_lt_of_le (mul_pos w.d0 (exp_pos _)) w.hetaunfold loss; nlinarith [w.hα,w.a0]end Schedulevariable {A G : Type} [Fintype A] [Fintype G] [AddCommGroup G]lemma offer_at (tag : A→G) (hi : Injective tag) (c : G→ℝ) (s : Labelled A)(D F : ℝ) (hd : 0 < D) (hf : 0 < F) (r l u M : ℕ) (hl : l ≤ u) (hu : u ≤ M)(hm : 0 < M) (hno : F+fundK tag c s l r < fundK tag c s u r)(x : ℝ) (hx : 0 < x) (hb : x ≤ F/D/(2*M)) :∃ t, refines t s ∧x ≤ fundI tag s r / D - fundI tag t r / D ∧F/D * (fundG tag s 1 / D - fundG tag t 1 / D) ≤2*(fundG tag s u/D-fundG tag s l/D)*x := bylet g n := fundG tag s n/Dlet a t := fundI tag t r/Dlet τ := F/Dlet T m := observe tag s (l+m)let k := u-llet f m := a s - a (T m)let b m := τ*(fundG tag s 1/D - fundG tag (T m) 1 / D)let K n := fundK tag c s n rhave hg : Monotone g := fun i j hh => div_le_div_of_nonneg_right(fundG_mono tag s hh) hd.lehave hτ : 0 < τ := div_pos hf hdhave h1 : τ < ∑ i ∈ Finset.range k, f i := byhave hc (i : ℕ) : K (l+(i+1))/D-K (l+i)/D ≤ f i := byhave hh := observe_save tag c s (l+i) runfold K f a T; rw [← sub_div, ← sub_div,← Nat.add_assoc]exact div_le_div_of_nonneg_right (by linarith) hd.lerefine lt_of_lt_of_le ?_ (Finset.sum_le_sum (fun i _ => hc i))rw [Finset.sum_range_sub (fun i => K (l+i)/D)]unfold k τ Krw [Nat.add_zero,Nat.add_sub_of_le hl, ← sub_div]gcongr; linarithhave heq (i : ℕ) : b i = τ*(g (l+(i+1))-g (l+i)) := byunfold b g Trw [← sub_div,observe_cost tag hi s (l+i),← sub_div,Nat.add_assoc]have h2 : ∑ i ∈ Finset.range k, b i = τ*(g u-g l) := bysimp_rw [heq,← Finset.mul_sum]rw [Finset.sum_range_sub (fun i => g (l+i))]simp only [k,Nat.add_sub_of_le hl,Nat.add_zero]obtain ⟨i,hh,hI,hJ⟩ := exists_offer k M (by omega) hm f b τ (g u-g l)hτ (sub_nonneg.mpr (hg hl)) h1 h2 (byintro i; rw [heq]; exact mul_nonneg hτ.le (sub_nonneg.mpr (hg (by omega))))have hX : x ≤ f i := le_trans hb hIhave Hf : 0 < f i := lt_of_lt_of_le hx hXlet y := x/f ihave hy0 : 0 ≤ y := (div_pos hx Hf).lehave hy1 : y ≤ 1 := (div_le_one Hf).mpr hXrefine ⟨blend (T i) s y hy0 hy1,blend_refines _ _ _ (observe_refines _ _ _) (refines_refl s) _ _ _, ?_,?_⟩· have hh := blend_I tag (T i) s y hy0 hy1 rhave hi := div_le_div_of_nonneg_right hh hd.lehave He : y*f i=x := div_mul_cancel₀ _ Hf.ne'unfold f a at He; rw [add_div,mul_div_assoc,mul_div_assoc] at hilinarith· rw [blend_G1 tag hi _ _ _]change τ*_ ≤ 2*(g u-g l)*xcalc_ = y*b i := by unfold b; ring_ ≤ y*(2*(g u-g l)*f i) := mul_le_mul_of_nonneg_left hJ hy0_ = _ := by rw [mul_left_comm,show y*f i=x from div_mul_cancel₀ _ Hf.ne']/-- Reach a long, low-cost block length. -/theorem reach (tag : A → G) (hi : Injective tag) (c : G → ℝ) (_hc0 : ∀ x, 0 ≤ c x)(S : Labelled A) (D F : ℝ) (hd : 0 < D) (hf : 0 < F) (B : Schedule)(m : ℕ) (l u r : ℕ → ℕ) (hm : 0 < m)(hl : ∀ i, i < B.size → l i ≤ u i ∧ u i ≤ m)(hp : ∀ i j, i < j → j < B.size → u j ≤ l i ∧ r i ≤ r j)(hG : ∀ i, i<B.size → fundG tag S (u i) ≤ D)(hI : ∀ i, i<B.size → fundI tag S (r i) ≤ D) :∃ T, refines T S ∧ fundG tag S 1 - fundG tag T 1 ≤ B.loss*D*D/F ∧∃ i, i < B.size ∧ fundK tag c T (u i) (r i) ≤ F+fundK tag c T (l i) (r i) := bylet Ω := {p // refines p S}let τ := F/Dhave hτ : 0 < τ := div_pos hf hdlet g (i : ℕ) (x : Ω) := fundG tag x.val i / Dlet a (i : ℕ) (x : Ω) := fundI tag x.val (r i) / Dlet v : Arena Ω :={ N := B.sizemov := fun s t => refines t.val s.valrefl := fun s => refines_refl _trans := fun h1 h2 => refines_trans h2 h1topc := fun x => τ*g 1 xpay := fun {x y} hh => mul_le_mul_of_nonneg_left (div_le_div_of_nonneg_right(G_anti tag hh 1) hd.le) hτ.leA := aAlo := fun s i _ => div_nonneg (opt_nonneg _ s.val.law (tag ∘ Prod.fst) Prod.snd(fun _ : Unit => 0) (fun _ => 0) (fun _ => le_refl _)) hd.leAhi := fun s i hi => (div_le_one hd).mpr ((I_anti tag s.property _).trans (hI i hi))Am := fun s {i j} hij hj => byobtain h|h := eq_or_lt_of_le hij· subst i; exact le_rfl· exact div_le_div_of_nonneg_right (fundI_mono tag _ (hp i j h hj).2) hd.leAs := fun {x y} h _ _ => div_le_div_of_nonneg_right (I_anti _ h _) hd.leL := fun i => g (l i)H := fun i => g (u i)Llo := fun s i h => div_nonneg (show 0 ≤ fundG tag s.val (l i) from Hcond_nonneg _ _ _) hd.leHhi := fun s i hi => (div_le_one hd).mpr ((G_anti tag s.property _).trans (hG i hi))LH := fun s i h => div_le_div_of_nonneg_right (fundG_mono _ _ (hl i h).1) hd.leBC := fun s {i j} h hb => div_le_div_of_nonneg_right (fundG_mono _ _ (hp i j h hb).1) hd.leLs := fun {s t} h i _ => div_le_div_of_nonneg_right (G_anti _ h _) hd.leHs := fun {s t} h i _ => div_le_div_of_nonneg_right (G_anti _ h _) hd.lefound := fun s => ∃ i, i < B.size ∧ fundK tag c s.val (u i) (r i) ≤ F +fundK tag c s.val (l i) (r i)rate := τ/(2*m)r0 := by have : (0:ℝ) < m := by exact_mod_cast hmpositivityoffer := byintro s i hb h x hx hx'obtain ⟨Q,hQ,h1,h2⟩ := offer_at tag hi c s.val D F hd hf (r i) (l i) (u i)m (hl i hb).1 (hl i hb).2 hm (lt_of_not_ge (fun hh => h ⟨i,hb,hh⟩)) x hx hx'exact ⟨⟨Q,refines_trans hQ s.property⟩,hQ,h1,by rwa [← mul_sub]⟩ }obtain ⟨t,ht,hc,hP⟩ :=v.complete_search ⟨S,refines_refl S⟩ B.N B.q B.n B.n0 B.q0 B.N0 le_rflB.u B.a B.δ B.η B.α B.ε B.u0 B.a0 B.d0 B.heta B.hn B.hα B.hε B.hβ B.hc B.hq B.htrefine ⟨t.val,t.property,?_,hc⟩change F/D * (fundG tag S 1 / D) - F/D*(fundG tag t.val 1 / D) ≤ B.loss at hPfield_simp at *linarithend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363import Mathlib/-! # Two-order finite refinement search -/open Set Function Filternoncomputable sectionnamespace OAInamespace FourierLLogL.Compressset_option maxHeartbeats 600000open Realuniverse uvariable {S : Type u}/-- Normalized potentials. A can only move down in time. Across indices Amoves up while the low and high potentials are margins of disjoint intervalsthat move down. -/structure Arena (S : Type u) whereN : ℕmov : S → S → Proprefl (s) : mov s strans {s t u} : mov s t → mov t u → mov s utopc : S → ℝpay {s t} : mov s t → topc t ≤ topc sA : ℕ → S → ℝAlo (s i) (hi : i<N) : 0 ≤ A i sAhi (s i) (hi : i<N) : A i s ≤ 1Am (s) {i j} (hi : i ≤ j) (hj : j<N) : A i s ≤ A j sAs {s t} (h : mov s t) {i} (hi : i<N) : A i t ≤ A i sL : ℕ → S → ℝH : ℕ → S → ℝLlo (s i) (hi : i<N) : 0 ≤ L i sHhi (s i) (hi : i<N) : H i s ≤ 1LH (s i) (hi : i<N) : L i s ≤ H i sBC (s) {i j} (hi : i < j) (hj : j<N) : H j s ≤ L i sLs {s t} (h : mov s t) {i} (hi : i<N) : L i t ≤ L i sHs {s t} (h : mov s t) {i} (hi : i<N) : H i t ≤ H i sfound : S → Proprate : ℝr0 : 0 < rateoffer (s) {i} (hi : i < N) (h : ¬ found s) (x : ℝ) (hp : 0 < x) (hb : x ≤ rate) :∃ t, mov s t ∧ x ≤ A i s - A i t ∧topc s - topc t ≤ 2*(H i s-L i s)*xnamespace Arenavariable (d : Arena S)omit d inprivate lemma dummy : True := triviallemma H_index (s) {i j} (hi : i ≤ j) (hj : j<d.N) : d.H j s ≤ d.H i s := byobtain rfl|h := eq_or_lt_of_le hi· exact le_rfl· exact (d.BC s h hj).trans (d.LH s _ (by omega))lemma L_index (s) {i j} (hi : i ≤ j) (hj : j<d.N) : d.L j s ≤ d.L i s := byobtain rfl|h := eq_or_lt_of_le hi· exact le_rfl· exact (d.LH s _ hj).trans (d.BC s h hj)lemma budget_index (s : S) {i : ℕ} (hi : i < d.N)(u a δ η : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η) :∃ t, d.mov s t ∧ d.topc s-d.topc t ≤ a*η ∧(d.found t ∨ u ≤ d.A i s - d.A i t ∨(d.topc s-d.topc t)+a*δ ≤ a*(d.H i s-d.L i t)) := byclassicallet cost (t : S) := d.topc s-d.topc tlet Δ t := d.A i s - d.A i tlet b t := min u (Δ t)let goal (t : S) := d.found t ∨ u ≤ Δ t ∨ cost t+a*δ ≤ a*(d.H i s-d.L i t)have H (k : ℕ) : ∃ t, d.mov s t ∧ cost t+a*δ ≤ a*δ*exp (2*b t/a) ∧(goal t ∨ k*d.rate ≤ Δ t) := byinduction k with| zero =>refine ⟨s,d.refl _,?_ ,Or.inr ?_⟩ <;> simp [cost,Δ,b,le_of_lt hu]| succ k ih =>obtain ⟨t,hst,hc,hk⟩ := ihby_cases h : goal t· exact ⟨t,hst,hc,Or.inl h⟩unfold goal at hpush Not at hhave he : 0 < u-Δ t := by linarith [h.2.1]let x := min d.rate (u-Δ t)have hx : 0 < x := lt_min d.r0 heobtain ⟨q,hq,hA,hV⟩ := d.offer t hi h.1 x hx (min_le_left _ _)have hT : b t = Δ t := min_eq_right h.2.1.lehave hQ : Δ t+x ≤ b q := byrefine le_min ?_ ?_· linarith [show x ≤ u-Δ t from min_le_right _ _]· dsimp [Δ]; linarithhave hcp : 0 ≤ cost t := sub_nonneg.mpr (d.pay hst)have H1 : cost q+a*δ ≤ (cost t+a*δ)*(1+2*x/a) := byhave HH : a*(d.H i t-d.L i t) ≤ cost t+a*δ :=(mul_le_mul_of_nonneg_left (sub_le_sub_right (d.Hs hst hi) _) ha.le).trans h.2.2.lehave h1 : a*(cost q-cost t) ≤ (cost t+a*δ)* (2*x) := bycalc_ ≤ a*(2*(d.H i t-d.L i t)*x) :=mul_le_mul_of_nonneg_left (by unfold cost; linarith) ha.le_ = a*(d.H i t-d.L i t)*(2*x) := by ring_ ≤ _ := mul_le_mul_of_nonneg_right HH (by positivity)field_simp; linarithhave H2 : exp (2*b t/a) * exp (2*x/a) ≤ exp (2*b q/a) := byrw [← exp_add,exp_le_exp,hT]field_simp; linarithhave H3 : cost q+a*δ ≤ a*δ*exp (2*b q/a) := byapply le_trans H1have hxp : 1+2*x/a ≤ exp (2*x/a) := by linarith [add_one_le_exp (2*x/a)]apply le_trans (mul_le_mul hc hxp (by positivity) (by positivity))rw [mul_assoc]exact mul_le_mul_of_nonneg_left H2 (mul_pos ha hδ).lerefine ⟨q,d.trans hst hq,H3,?_⟩rcases le_total d.rate (u-Δ t) with hn|hn· have hh : k*d.rate ≤ Δ t := hk.resolve_left (by unfold goal; grind)righthave hh' : x = d.rate := min_eq_left hnpush_casthave H := min_le_right u (Δ q)linarith [show b q ≤ Δ q from H]· leftrefine Or.inr (Or.inl ?_)have hh : x = u - Δ t := min_eq_right hnhave he : b q ≤ Δ q := min_le_right _ _linarithobtain ⟨k,hk⟩ := exists_nat_gt (1 / d.rate)obtain ⟨t,hst,h1,h2⟩ := H khave h3 : goal t :=h2.resolve_right (fun hh => byhave Hr := (div_lt_iff₀ d.r0).mp hkunfold Δ at hh; linarith [d.Ahi s i hi,d.Alo t i hi])refine ⟨t,hst,?_ ,h3⟩have H0 : b t ≤ u := min_le_left _ _have H1 : exp (2*b t/a) ≤ exp (2*u/a) := by gcongrchange cost t ≤ _nlinarith [mul_le_mul_of_nonneg_left H1 (mul_pos ha hδ).le,mul_le_mul_of_nonneg_left hη ha.le]/-- Forward search through adjacent blocks [o+i*m,o+(i+1)m). Fully failed blocks consume width. -/lemma budget_ascending (s : S) (G : S → Prop)(o n m : ℕ) (hm : 0 < m) (hn : 0 < n) (hb : o+n*m ≤ d.N)(a b δ : ℝ) (ha : 0 < a) (hδ : 1 < n*δ)(hstep : ∀ (t) (_h : d.mov s t) i (_hi : i<n), ∃ q, d.mov t q ∧((G q ∧ d.topc t-d.topc q ≤ a*(d.H (o+i*m) t-d.L (o+(i+1)*m-1) q)+b) ∨(d.topc t-d.topc q)+a*δ ≤ a*(d.H (o+i*m) t-d.L (o+(i+1)*m-1) q))) :∃ t, d.mov s t ∧ G t ∧ d.topc s-d.topc t ≤ a*(d.H o s-d.L (o+n*m-1) t)+b := bylet first i := o+i*mlet last i := o+(i+1)*m-1have hF (i) (hi : i < n) : first i < d.N := by dsimp [first]; nlinarithhave hL (i) (hi : i < n) : last i < d.N := byhave hb' : o+(i+1)*m ≤ o+n*m := by gcongr; omegahave hp : 0 < (i+1)*m := Nat.mul_pos (by omega) hmdsimp [last]; omegahave H (k) (hk : k < n) :∃ t, d.mov s t ∧((G t ∧ d.topc s-d.topc t ≤ a*(d.H o s-d.L (last k) t)+b) ∨d.topc s-d.topc t+((k:ℝ)+1)*(a*δ) ≤ a*(d.H o s-d.L (last k) t)) := byinduction k with| zero => simpa [last] using hstep s (d.refl s) 0 hk| succ k ih =>have hk' : k<n := by omegaobtain ⟨t,hst,HG|hh⟩ := ih hk'· refine ⟨t,hst,Or.inl ⟨HG.1,HG.2.trans ?_⟩⟩have Hs : d.L (last (k+1)) t ≤ d.L (last k) t :=d.L_index _ (by unfold last; gcongr; omega) (hL _ hk)gcongrobtain ⟨q,hq,hq'⟩ := hstep t hst (k+1) hkhave he : last k < first (k+1) := byhave : 0 < m*(k+1) := Nat.mul_pos hm (by omega)rw [Nat.mul_comm] at thisunfold last first; omegahave h' := mul_le_mul_of_nonneg_left (d.BC t he (hF _ hk)) ha.lehave hd : 0 ≤ (k+1:ℝ)*(a*δ) := byhave hp : 0 < δ := byhave : (0:ℝ) < n := by exact_mod_cast hnnlinarithpositivityrefine ⟨q,d.trans hst hq,?_⟩dsimp only [last,first] at *rcases hq' with H1|H1· exact Or.inl ⟨H1.1,by linarith [H1.2]⟩· right; push_cast; linarithobtain ⟨k,rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'obtain ⟨t,hst,hh|hh⟩ := H k (by omega)· exact ⟨t,hst,hh⟩exfalsohave h1 := (d.pay hst)have h2 := d.Llo t (last k) (hL k (by omega))have hx : o < d.N := by simpa [first] using hF 0 (by omega)have h3 := d.Hhi s o hxpush_cast at hδnlinarithlemma budget_sub (s : S) (o n : ℕ) (hn : 0<n) (hb : o+n ≤ d.N)(u a δ η : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η)(hnδ : 1 < (n:ℝ)*δ) :∃ t, d.mov s t ∧(d.found t ∨ u ≤ d.A (o+n-1) s - d.A o t) ∧d.topc s-d.topc t ≤ a*(d.H o s-d.L (o+n-1) t)+a*η := bylet G t := d.found t ∨ u ≤ d.A (o+n-1) s-d.A o thave step : ∀ (t) (_h : d.mov s t) i (_hi : i<n), ∃ q, d.mov t q ∧((G q ∧ d.topc t-d.topc q ≤ a*(d.H (o+i) t-d.L (o+i) q)+a*η) ∨(d.topc t-d.topc q)+a*δ ≤ a*(d.H (o+i) t-d.L (o+i) q)) := byintro t ht i hihave hb' : o+i<d.N := by omegaobtain ⟨q,hq,hA,hQ⟩ := d.budget_index t hb' u a δ η hu ha hδ hηrefine ⟨q,hq,?_⟩have hp := (d.Ls hq hb').trans (d.LH t _ hb')have hA' : d.topc t - d.topc q ≤ a*(d.H (o+i) t-d.L (o+i) q)+a*η := bynlinarithrcases hQ with h|h|h· exact Or.inl ⟨Or.inl h,hA'⟩· have hl := d.Am q (i:=o) (by omega) hb'have hv := d.Am s (i:=o+i) (by omega) (by omega : o+n-1<d.N)have hj := d.As ht hb'exact Or.inl ⟨Or.inr (by linarith),hA'⟩· exact Or.inr hhave Hstep := d.budget_ascending s G o n 1 (by omega) hn (by simpa)a (a*η) δ ha (by linarith)simpa only [G,mul_one] using Hstep (by simpa [← add_assoc] using step)/-- The macro-scale scan goes from right to left through small blocks.Skip if lower-to-upper width is too large, unless goal encountered. -/lemma budget_macro (s : S) (o q n : ℕ) (hn : 0 < n) (hq : 0 < q)(hb : o+q*n ≤ d.N)(u a δ η α ε : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η) (hnδ : 1 < (n:ℝ)*δ)(ha' : 0 < α) (he : 0 < ε) (hb' : 2*(a/α) ≤ 1)(hc : (ε+η)*exp (2*(a/α)*q) ≤ 1) (hqu : 1 < (q:ℝ)*u) :∃ t, d.mov s t ∧((d.found t ∧ d.topc s-d.topc t ≤ α+a*(1+η)) ∨(d.topc s-d.topc t)+α*ε ≤ α*(d.H o s-d.L (o+q*n-1) t)) := byclassicallet l := o+q*n-1have hpn : 0 < q*n := Nat.mul_pos hq hnhave hlo : o ≤ l := by unfold l; omegahave hl : l<d.N := by unfold l; omegahave hl' := lt_of_le_of_lt hlo hllet x t := d.topc s-d.topc tlet y t := α*(d.H o s-d.L l t)let z := α*(η+ε)let β := a/αlet G t := (d.found t ∧ x t ≤ α+a*(1+η)) ∨ x t + α*ε ≤ y thave bpos : 0 < β := div_pos ha ha'have zpos : 0 < z := mul_pos ha' (add_pos_of_nonneg_of_pos(le_trans (by positivity : 0 ≤ δ*exp (2*u/a)) hη) he)have hB : β*α = a := div_mul_cancel₀ a ha'.ne'change 2*β ≤ 1 at hb'change _*exp (2*β*q) ≤ 1 at hchave HI (k : ℕ) (hk : k ≤ q) : ∃ t, d.mov s t ∧(G t ∨(x t + z ≤ z * exp (2*β*k) ∧ k*u ≤ (1:ℝ) ∧∀ i < o+(q-k)*n, d.A i t ≤ 1 - k*u)) := byinduction k with| zero =>refine ⟨s,d.refl _,Or.inr ⟨by simp [x],by simp,?_⟩⟩intro i hi; have HH : i<d.N := lt_of_lt_of_le (by simpa using hi) hbsimpa using d.Ahi s i HH| succ k ih =>obtain ⟨t,hst,ht|⟨ht,hv,hA⟩⟩ := ih (by omega)· exact ⟨t,hst,Or.inl ht⟩let b := o+(q-(k+1))*nhave h1 : b+n=o+(q-k)*n := byhave H1 : q-k=q-(k+1)+1 := by omegaunfold b; rw [H1,add_mul]; omegahave h2 : b+n ≤ o+q*n := by rw [h1]; gcongr; omegaobtain ⟨t',htt',hg,hw⟩ := d.budget_sub t b n hn (h2.trans hb) u a δ η hu ha hδ hη hnδhave hx := d.trans hst htt'refine ⟨t',hx,?_⟩have hy1 : b+n-1 ≤ l := by dsimp only [l]; omegahave hb0 : o ≤ b := Nat.le_add_right _ _have hy2 : o ≤ b+n-1 := by omegahave hl2 := lt_of_le_of_lt hy1 hlhave hl3 : b ≤ b+n-1 := by omegahave hl4 := lt_of_le_of_lt hl3 hl2have hw' : x t' - x t ≤ a*(d.H o s-d.L l t')+a*η := byhave hA : d.H b t ≤ d.H o s := le_trans (d.Hs hst hl4) (d.H_index s hb0 hl4)have hL := d.L_index t' hy1 hlunfold xnlinarith [hw]rcases hg with hh|hh· have hE : exp (2*β*k) ≤ exp (2*β*q) := bygcongr; omegahave hv : z*exp (2*β*q) ≤ α := byunfold z; nlinarith [mul_le_mul_of_nonneg_left hc ha'.le]have hT : x t ≤ α := by nlinarithexact Or.inl (Or.inl ⟨hh,by nlinarith [d.Hhi s o hl',d.Llo t' l hl]⟩)by_cases H : x t'+α*ε ≤ y t'· exact Or.inl (Or.inr H)have hy : y t' ≤ x t'+α*ε := le_of_not_ge Hhave hrec : (x t'+z)*(1-β) ≤ (x t+z) := byunfold y at hyunfold zhave Hh := mul_le_mul_of_nonneg_left hy bpos.lesimp only [mul_add, ← mul_assoc,hB] at Hhhave h3 (c : ℝ) : β*(α*c) = a*c := by rw [← mul_assoc,hB]nlinarith [h3 (η+ε)]have hxp : x t'+z ≥ 0 := by have H := d.pay hx; unfold x; linarithhave hiter : (x t'+z) ≤ z * exp (2*β*(k+1)) := byhave hg : 1 ≤ (1-β)*exp (2*β) := byhave h := Real.add_one_le_exp (2*β)nlinarithapply le_trans (b:=(z*exp (2*β*k))*exp (2*β))· have HH := mul_le_mul_of_nonneg_right (hrec.trans ht) (exp_nonneg (2*β))exact le_trans (byrw [mul_assoc]; exact le_mul_of_one_le_right hxp hg) HH· rw [mul_assoc,← exp_add]apply le_of_eq; ring_nfrefine Or.inr ⟨by push_cast; exact hiter,?_,?_⟩· have H := hA (b+n-1) (by omega)have H1 := d.Alo t' b hl4push_cast; linarith· intro i hihave H := hA (b+n-1) (by omega)change i < b at hihave H1 := d.Am t' hi.le hl4push_cast; linarithobtain ⟨t,hst,h|h⟩ := HI q le_rfl· exact ⟨t,hst,h⟩· exfalsolinarith [h.2.1]lemma complete_search (s : S) (N q n : ℕ) (hn : 0<n) (hq : 0<q)(hN : 0<N) (hb : N*(q*n) ≤ d.N)(u a δ η α ε : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η) (hnδ : 1 < (n:ℝ)*δ)(ha' : 0 < α) (he : 0 < ε) (hb' : 2*(a/α) ≤ 1)(hc : (ε+η)*exp (2*(a/α)*q) ≤ 1) (hqu : 1 < (q:ℝ)*u) (ht : 1 < (N:ℝ)*ε) :∃ t, d.mov s t ∧ d.found t ∧ d.topc s-d.topc t ≤ 2*α+a*(1+η) := bylet m := q*nhave hm : 0 < m := Nat.mul_pos hq hnobtain ⟨t,hst,hd,hH⟩ := d.budget_ascending s d.found 0 N m hm hN(by simpa using hb) α (α+a*(1+η)) ε ha' ht (byintro t hst i hisimp only [zero_add]have h1 : i*m+m ≤ d.N := byrw [show i*m+m=(i+1)*m by ring]exact le_trans (Nat.mul_le_mul_right m hi) hbobtain ⟨t',h',hH⟩ :=d.budget_macro t (i*m) q n hn hq h1 u a δ η α ε hu ha hδ hη hnδ ha' he hb' hc hqurw [show (i+1)*m=i*m+q*n by dsimp [m]; ring]refine ⟨t',h',?_⟩rcases hH with h|h· lefthave hh : i*m ≤ i*m+m-1 := by omegahave hk : i*m+m-1 < d.N := by omegahave ht : d.L (i*m+m-1) t' ≤ d.H (i*m) t := (d.Ls h' hk).trans((d.L_index t hh hk).trans (d.LH _ _ (by omega)))exact ⟨h.1,h.2.trans (le_add_of_nonneg_left (mul_nonneg ha'.le (sub_nonneg.mpr ht)))⟩· exact Or.inr h)refine ⟨t,hst,hd,?_⟩have hh : 0<N*m := Nat.mul_pos hN hmhave hh' : N*m ≤ d.N := hbhave h1 := d.Hhi s 0 (by omega)have h2 := d.Llo t (0+N*m-1) (by omega)nlinarithend Arenaend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363import Mathlib/-! # Two-order finite refinement search -/open Set Function Filternoncomputable sectionnamespace OAInamespace FourierLLogL.Compressset_option maxHeartbeats 600000open Realuniverse uvariable {S : Type u}/-- Normalized potentials. A can only move down in time. Across indices Amoves up while the low and high potentials are margins of disjoint intervalsthat move down. -/structure Arena (S : Type u) whereN : ℕmov : S → S → Proprefl (s) : mov s strans {s t u} : mov s t → mov t u → mov s utopc : S → ℝpay {s t} : mov s t → topc t ≤ topc sA : ℕ → S → ℝAlo (s i) (hi : i<N) : 0 ≤ A i sAhi (s i) (hi : i<N) : A i s ≤ 1Am (s) {i j} (hi : i ≤ j) (hj : j<N) : A i s ≤ A j sAs {s t} (h : mov s t) {i} (hi : i<N) : A i t ≤ A i sL : ℕ → S → ℝH : ℕ → S → ℝLlo (s i) (hi : i<N) : 0 ≤ L i sHhi (s i) (hi : i<N) : H i s ≤ 1LH (s i) (hi : i<N) : L i s ≤ H i sBC (s) {i j} (hi : i < j) (hj : j<N) : H j s ≤ L i sLs {s t} (h : mov s t) {i} (hi : i<N) : L i t ≤ L i sHs {s t} (h : mov s t) {i} (hi : i<N) : H i t ≤ H i sfound : S → Proprate : ℝr0 : 0 < rateoffer (s) {i} (hi : i < N) (h : ¬ found s) (x : ℝ) (hp : 0 < x) (hb : x ≤ rate) :∃ t, mov s t ∧ x ≤ A i s - A i t ∧topc s - topc t ≤ 2*(H i s-L i s)*xnamespace Arenavariable (d : Arena S)omit d inprivate lemma dummy : True := triviallemma H_index (s) {i j} (hi : i ≤ j) (hj : j<d.N) : d.H j s ≤ d.H i s := byobtain rfl|h := eq_or_lt_of_le hi· exact le_rfl· exact (d.BC s h hj).trans (d.LH s _ (by omega))lemma L_index (s) {i j} (hi : i ≤ j) (hj : j<d.N) : d.L j s ≤ d.L i s := byobtain rfl|h := eq_or_lt_of_le hi· exact le_rfl· exact (d.LH s _ hj).trans (d.BC s h hj)lemma budget_index (s : S) {i : ℕ} (hi : i < d.N)(u a δ η : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η) :∃ t, d.mov s t ∧ d.topc s-d.topc t ≤ a*η ∧(d.found t ∨ u ≤ d.A i s - d.A i t ∨(d.topc s-d.topc t)+a*δ ≤ a*(d.H i s-d.L i t)) := byclassicallet cost (t : S) := d.topc s-d.topc tlet Δ t := d.A i s - d.A i tlet b t := min u (Δ t)let goal (t : S) := d.found t ∨ u ≤ Δ t ∨ cost t+a*δ ≤ a*(d.H i s-d.L i t)have H (k : ℕ) : ∃ t, d.mov s t ∧ cost t+a*δ ≤ a*δ*exp (2*b t/a) ∧(goal t ∨ k*d.rate ≤ Δ t) := byinduction k with| zero =>refine ⟨s,d.refl _,?_ ,Or.inr ?_⟩ <;> simp [cost,Δ,b,le_of_lt hu]| succ k ih =>obtain ⟨t,hst,hc,hk⟩ := ihby_cases h : goal t· exact ⟨t,hst,hc,Or.inl h⟩unfold goal at hpush Not at hhave he : 0 < u-Δ t := by linarith [h.2.1]let x := min d.rate (u-Δ t)have hx : 0 < x := lt_min d.r0 heobtain ⟨q,hq,hA,hV⟩ := d.offer t hi h.1 x hx (min_le_left _ _)have hT : b t = Δ t := min_eq_right h.2.1.lehave hQ : Δ t+x ≤ b q := byrefine le_min ?_ ?_· linarith [show x ≤ u-Δ t from min_le_right _ _]· dsimp [Δ]; linarithhave hcp : 0 ≤ cost t := sub_nonneg.mpr (d.pay hst)have H1 : cost q+a*δ ≤ (cost t+a*δ)*(1+2*x/a) := byhave HH : a*(d.H i t-d.L i t) ≤ cost t+a*δ :=(mul_le_mul_of_nonneg_left (sub_le_sub_right (d.Hs hst hi) _) ha.le).trans h.2.2.lehave h1 : a*(cost q-cost t) ≤ (cost t+a*δ)* (2*x) := bycalc_ ≤ a*(2*(d.H i t-d.L i t)*x) :=mul_le_mul_of_nonneg_left (by unfold cost; linarith) ha.le_ = a*(d.H i t-d.L i t)*(2*x) := by ring_ ≤ _ := mul_le_mul_of_nonneg_right HH (by positivity)field_simp; linarithhave H2 : exp (2*b t/a) * exp (2*x/a) ≤ exp (2*b q/a) := byrw [← exp_add,exp_le_exp,hT]field_simp; linarithhave H3 : cost q+a*δ ≤ a*δ*exp (2*b q/a) := byapply le_trans H1have hxp : 1+2*x/a ≤ exp (2*x/a) := by linarith [add_one_le_exp (2*x/a)]apply le_trans (mul_le_mul hc hxp (by positivity) (by positivity))rw [mul_assoc]exact mul_le_mul_of_nonneg_left H2 (mul_pos ha hδ).lerefine ⟨q,d.trans hst hq,H3,?_⟩rcases le_total d.rate (u-Δ t) with hn|hn· have hh : k*d.rate ≤ Δ t := hk.resolve_left (by unfold goal; grind)righthave hh' : x = d.rate := min_eq_left hnpush_casthave H := min_le_right u (Δ q)linarith [show b q ≤ Δ q from H]· leftrefine Or.inr (Or.inl ?_)have hh : x = u - Δ t := min_eq_right hnhave he : b q ≤ Δ q := min_le_right _ _linarithobtain ⟨k,hk⟩ := exists_nat_gt (1 / d.rate)obtain ⟨t,hst,h1,h2⟩ := H khave h3 : goal t :=h2.resolve_right (fun hh => byhave Hr := (div_lt_iff₀ d.r0).mp hkunfold Δ at hh; linarith [d.Ahi s i hi,d.Alo t i hi])refine ⟨t,hst,?_ ,h3⟩have H0 : b t ≤ u := min_le_left _ _have H1 : exp (2*b t/a) ≤ exp (2*u/a) := by gcongrchange cost t ≤ _nlinarith [mul_le_mul_of_nonneg_left H1 (mul_pos ha hδ).le,mul_le_mul_of_nonneg_left hη ha.le]/-- Forward search through adjacent blocks [o+i*m,o+(i+1)m). Fully failed blocks consume width. -/lemma budget_ascending (s : S) (G : S → Prop)(o n m : ℕ) (hm : 0 < m) (hn : 0 < n) (hb : o+n*m ≤ d.N)(a b δ : ℝ) (ha : 0 < a) (hδ : 1 < n*δ)(hstep : ∀ (t) (_h : d.mov s t) i (_hi : i<n), ∃ q, d.mov t q ∧((G q ∧ d.topc t-d.topc q ≤ a*(d.H (o+i*m) t-d.L (o+(i+1)*m-1) q)+b) ∨(d.topc t-d.topc q)+a*δ ≤ a*(d.H (o+i*m) t-d.L (o+(i+1)*m-1) q))) :∃ t, d.mov s t ∧ G t ∧ d.topc s-d.topc t ≤ a*(d.H o s-d.L (o+n*m-1) t)+b := bylet first i := o+i*mlet last i := o+(i+1)*m-1have hF (i) (hi : i < n) : first i < d.N := by dsimp [first]; nlinarithhave hL (i) (hi : i < n) : last i < d.N := byhave hb' : o+(i+1)*m ≤ o+n*m := by gcongr; omegahave hp : 0 < (i+1)*m := Nat.mul_pos (by omega) hmdsimp [last]; omegahave H (k) (hk : k < n) :∃ t, d.mov s t ∧((G t ∧ d.topc s-d.topc t ≤ a*(d.H o s-d.L (last k) t)+b) ∨d.topc s-d.topc t+((k:ℝ)+1)*(a*δ) ≤ a*(d.H o s-d.L (last k) t)) := byinduction k with| zero => simpa [last] using hstep s (d.refl s) 0 hk| succ k ih =>have hk' : k<n := by omegaobtain ⟨t,hst,HG|hh⟩ := ih hk'· refine ⟨t,hst,Or.inl ⟨HG.1,HG.2.trans ?_⟩⟩have Hs : d.L (last (k+1)) t ≤ d.L (last k) t :=d.L_index _ (by unfold last; gcongr; omega) (hL _ hk)gcongrobtain ⟨q,hq,hq'⟩ := hstep t hst (k+1) hkhave he : last k < first (k+1) := byhave : 0 < m*(k+1) := Nat.mul_pos hm (by omega)rw [Nat.mul_comm] at thisunfold last first; omegahave h' := mul_le_mul_of_nonneg_left (d.BC t he (hF _ hk)) ha.lehave hd : 0 ≤ (k+1:ℝ)*(a*δ) := byhave hp : 0 < δ := byhave : (0:ℝ) < n := by exact_mod_cast hnnlinarithpositivityrefine ⟨q,d.trans hst hq,?_⟩dsimp only [last,first] at *rcases hq' with H1|H1· exact Or.inl ⟨H1.1,by linarith [H1.2]⟩· right; push_cast; linarithobtain ⟨k,rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'obtain ⟨t,hst,hh|hh⟩ := H k (by omega)· exact ⟨t,hst,hh⟩exfalsohave h1 := (d.pay hst)have h2 := d.Llo t (last k) (hL k (by omega))have hx : o < d.N := by simpa [first] using hF 0 (by omega)have h3 := d.Hhi s o hxpush_cast at hδnlinarithlemma budget_sub (s : S) (o n : ℕ) (hn : 0<n) (hb : o+n ≤ d.N)(u a δ η : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η)(hnδ : 1 < (n:ℝ)*δ) :∃ t, d.mov s t ∧(d.found t ∨ u ≤ d.A (o+n-1) s - d.A o t) ∧d.topc s-d.topc t ≤ a*(d.H o s-d.L (o+n-1) t)+a*η := bylet G t := d.found t ∨ u ≤ d.A (o+n-1) s-d.A o thave step : ∀ (t) (_h : d.mov s t) i (_hi : i<n), ∃ q, d.mov t q ∧((G q ∧ d.topc t-d.topc q ≤ a*(d.H (o+i) t-d.L (o+i) q)+a*η) ∨(d.topc t-d.topc q)+a*δ ≤ a*(d.H (o+i) t-d.L (o+i) q)) := byintro t ht i hihave hb' : o+i<d.N := by omegaobtain ⟨q,hq,hA,hQ⟩ := d.budget_index t hb' u a δ η hu ha hδ hηrefine ⟨q,hq,?_⟩have hp := (d.Ls hq hb').trans (d.LH t _ hb')have hA' : d.topc t - d.topc q ≤ a*(d.H (o+i) t-d.L (o+i) q)+a*η := bynlinarithrcases hQ with h|h|h· exact Or.inl ⟨Or.inl h,hA'⟩· have hl := d.Am q (i:=o) (by omega) hb'have hv := d.Am s (i:=o+i) (by omega) (by omega : o+n-1<d.N)have hj := d.As ht hb'exact Or.inl ⟨Or.inr (by linarith),hA'⟩· exact Or.inr hhave Hstep := d.budget_ascending s G o n 1 (by omega) hn (by simpa)a (a*η) δ ha (by linarith)simpa only [G,mul_one] using Hstep (by simpa [← add_assoc] using step)/-- The macro-scale scan goes from right to left through small blocks.Skip if lower-to-upper width is too large, unless goal encountered. -/lemma budget_macro (s : S) (o q n : ℕ) (hn : 0 < n) (hq : 0 < q)(hb : o+q*n ≤ d.N)(u a δ η α ε : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η) (hnδ : 1 < (n:ℝ)*δ)(ha' : 0 < α) (he : 0 < ε) (hb' : 2*(a/α) ≤ 1)(hc : (ε+η)*exp (2*(a/α)*q) ≤ 1) (hqu : 1 < (q:ℝ)*u) :∃ t, d.mov s t ∧((d.found t ∧ d.topc s-d.topc t ≤ α+a*(1+η)) ∨(d.topc s-d.topc t)+α*ε ≤ α*(d.H o s-d.L (o+q*n-1) t)) := byclassicallet l := o+q*n-1have hpn : 0 < q*n := Nat.mul_pos hq hnhave hlo : o ≤ l := by unfold l; omegahave hl : l<d.N := by unfold l; omegahave hl' := lt_of_le_of_lt hlo hllet x t := d.topc s-d.topc tlet y t := α*(d.H o s-d.L l t)let z := α*(η+ε)let β := a/αlet G t := (d.found t ∧ x t ≤ α+a*(1+η)) ∨ x t + α*ε ≤ y thave bpos : 0 < β := div_pos ha ha'have zpos : 0 < z := mul_pos ha' (add_pos_of_nonneg_of_pos(le_trans (by positivity : 0 ≤ δ*exp (2*u/a)) hη) he)have hB : β*α = a := div_mul_cancel₀ a ha'.ne'change 2*β ≤ 1 at hb'change _*exp (2*β*q) ≤ 1 at hchave HI (k : ℕ) (hk : k ≤ q) : ∃ t, d.mov s t ∧(G t ∨(x t + z ≤ z * exp (2*β*k) ∧ k*u ≤ (1:ℝ) ∧∀ i < o+(q-k)*n, d.A i t ≤ 1 - k*u)) := byinduction k with| zero =>refine ⟨s,d.refl _,Or.inr ⟨by simp [x],by simp,?_⟩⟩intro i hi; have HH : i<d.N := lt_of_lt_of_le (by simpa using hi) hbsimpa using d.Ahi s i HH| succ k ih =>obtain ⟨t,hst,ht|⟨ht,hv,hA⟩⟩ := ih (by omega)· exact ⟨t,hst,Or.inl ht⟩let b := o+(q-(k+1))*nhave h1 : b+n=o+(q-k)*n := byhave H1 : q-k=q-(k+1)+1 := by omegaunfold b; rw [H1,add_mul]; omegahave h2 : b+n ≤ o+q*n := by rw [h1]; gcongr; omegaobtain ⟨t',htt',hg,hw⟩ := d.budget_sub t b n hn (h2.trans hb) u a δ η hu ha hδ hη hnδhave hx := d.trans hst htt'refine ⟨t',hx,?_⟩have hy1 : b+n-1 ≤ l := by dsimp only [l]; omegahave hb0 : o ≤ b := Nat.le_add_right _ _have hy2 : o ≤ b+n-1 := by omegahave hl2 := lt_of_le_of_lt hy1 hlhave hl3 : b ≤ b+n-1 := by omegahave hl4 := lt_of_le_of_lt hl3 hl2have hw' : x t' - x t ≤ a*(d.H o s-d.L l t')+a*η := byhave hA : d.H b t ≤ d.H o s := le_trans (d.Hs hst hl4) (d.H_index s hb0 hl4)have hL := d.L_index t' hy1 hlunfold xnlinarith [hw]rcases hg with hh|hh· have hE : exp (2*β*k) ≤ exp (2*β*q) := bygcongr; omegahave hv : z*exp (2*β*q) ≤ α := byunfold z; nlinarith [mul_le_mul_of_nonneg_left hc ha'.le]have hT : x t ≤ α := by nlinarithexact Or.inl (Or.inl ⟨hh,by nlinarith [d.Hhi s o hl',d.Llo t' l hl]⟩)by_cases H : x t'+α*ε ≤ y t'· exact Or.inl (Or.inr H)have hy : y t' ≤ x t'+α*ε := le_of_not_ge Hhave hrec : (x t'+z)*(1-β) ≤ (x t+z) := byunfold y at hyunfold zhave Hh := mul_le_mul_of_nonneg_left hy bpos.lesimp only [mul_add, ← mul_assoc,hB] at Hhhave h3 (c : ℝ) : β*(α*c) = a*c := by rw [← mul_assoc,hB]nlinarith [h3 (η+ε)]have hxp : x t'+z ≥ 0 := by have H := d.pay hx; unfold x; linarithhave hiter : (x t'+z) ≤ z * exp (2*β*(k+1)) := byhave hg : 1 ≤ (1-β)*exp (2*β) := byhave h := Real.add_one_le_exp (2*β)nlinarithapply le_trans (b:=(z*exp (2*β*k))*exp (2*β))· have HH := mul_le_mul_of_nonneg_right (hrec.trans ht) (exp_nonneg (2*β))exact le_trans (byrw [mul_assoc]; exact le_mul_of_one_le_right hxp hg) HH· rw [mul_assoc,← exp_add]apply le_of_eq; ring_nfrefine Or.inr ⟨by push_cast; exact hiter,?_,?_⟩· have H := hA (b+n-1) (by omega)have H1 := d.Alo t' b hl4push_cast; linarith· intro i hihave H := hA (b+n-1) (by omega)change i < b at hihave H1 := d.Am t' hi.le hl4push_cast; linarithobtain ⟨t,hst,h|h⟩ := HI q le_rfl· exact ⟨t,hst,h⟩· exfalsolinarith [h.2.1]lemma complete_search (s : S) (N q n : ℕ) (hn : 0<n) (hq : 0<q)(hN : 0<N) (hb : N*(q*n) ≤ d.N)(u a δ η α ε : ℝ) (hu : 0 < u) (ha : 0 < a) (hδ : 0 < δ)(hη : δ*exp (2*u/a) ≤ η) (hnδ : 1 < (n:ℝ)*δ)(ha' : 0 < α) (he : 0 < ε) (hb' : 2*(a/α) ≤ 1)(hc : (ε+η)*exp (2*(a/α)*q) ≤ 1) (hqu : 1 < (q:ℝ)*u) (ht : 1 < (N:ℝ)*ε) :∃ t, d.mov s t ∧ d.found t ∧ d.topc s-d.topc t ≤ 2*α+a*(1+η) := bylet m := q*nhave hm : 0 < m := Nat.mul_pos hq hnobtain ⟨t,hst,hd,hH⟩ := d.budget_ascending s d.found 0 N m hm hN(by simpa using hb) α (α+a*(1+η)) ε ha' ht (byintro t hst i hisimp only [zero_add]have h1 : i*m+m ≤ d.N := byrw [show i*m+m=(i+1)*m by ring]exact le_trans (Nat.mul_le_mul_right m hi) hbobtain ⟨t',h',hH⟩ :=d.budget_macro t (i*m) q n hn hq h1 u a δ η α ε hu ha hδ hη hnδ ha' he hb' hc hqurw [show (i+1)*m=i*m+q*n by dsimp [m]; ring]refine ⟨t',h',?_⟩rcases hH with h|h· lefthave hh : i*m ≤ i*m+m-1 := by omegahave hk : i*m+m-1 < d.N := by omegahave ht : d.L (i*m+m-1) t' ≤ d.H (i*m) t := (d.Ls h' hk).trans((d.L_index t hh hk).trans (d.LH _ _ (by omega)))exact ⟨h.1,h.2.trans (le_add_of_nonneg_left (mul_nonneg ha'.le (sub_nonneg.mpr ht)))⟩· exact Or.inr h)refine ⟨t,hst,hd,?_⟩have hh : 0<N*m := Nat.mul_pos hN hmhave hh' : N*m ≤ d.N := hbhave h1 := d.Hhi s 0 (by omega)have h2 := d.Llo t (0+N*m-1) (by omega)nlinarithend Arenaend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178import OAI.Analysis.FourierLLogL.Compress.Prefix/-! # Selecting conditional iid comparator -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Lawprivate lemma choose_slow {a : ℕ → ℝ} (ha : Monotone a)(h0 : ∀ j, 0 ≤ a j) {E : ℝ} (hE : 0 ≤ E) (T N m : ℕ)(hN : 0 < N) (hm : m ≤ N) (hT : 3*N ≤ T)(hh : ∑ j ∈ Finset.range T, a j ≤ E) :∃ j, j < N ∧ a j ≤ E/N ∧∑ i ∈ Finset.range m, (a (j+i)-a j) ≤ m^2*E/(N:ℝ)^2 := byhave hp : 0 < (N:ℝ) := by exact_mod_cast hNlet D := E/Nhave hs (l : ℕ) (hl : l ≤ 2*N) : a l ≤ D := byhave Hlt : ∑ j ∈ Finset.range (l+N), a j ≤ E :=le_trans (Finset.sum_le_sum_of_subset_of_nonneg(Finset.range_mono (by omega)) (fun i _ _ => h0 i)) hhrw [Finset.sum_range_add] at Hlthave H : ∑ _ ∈ Finset.range N, a l ≤ ∑ i ∈ Finset.range N, a (l+i) :=Finset.sum_le_sum fun i _ => ha (by omega : l ≤ l+i)simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at Happly (le_div_iff₀ hp).mprhave : 0 ≤ ∑ j ∈ Finset.range l, a j := Finset.sum_nonneg fun j _ => h0 jlinarithhave HD : 0 ≤ D := div_nonneg hE hp.lehave hr (i : ℕ) (hi : i ≤ m) :∑ j ∈ Finset.range N, (a (j+i)-a j) ≤ m*D := byhave h1 := Finset.sum_range_add a N ihave h2 := Finset.sum_range_add a i Nhave hcmp : ∑ j ∈ Finset.range i, a (N+j) ≤ ∑ j ∈ Finset.range i, D := byapply Finset.sum_le_sumintro j hjapply hs; rw [Finset.mem_range] at hj; omegasimp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at hcmphave hl : 0 ≤ ∑ j ∈ Finset.range i, a j := Finset.sum_nonneg fun j _ => h0 jhave hle : (i:ℝ)*D ≤ (m:ℝ)*D := by gcongrrw [show i+N=N+i by omega] at h2simp_rw [show ∀ j, j+i=i+j from fun j => add_comm _ _, Finset.sum_sub_distrib]linarithlet f j := ∑ i ∈ Finset.range m, (a (j+i)-a j)have hAvg : ∑ j ∈ Finset.range N, f j ≤ ∑ i ∈ Finset.range N, ((m:ℝ)^2*E/(N:ℝ)^2) := byunfold frw [Finset.sum_comm]calc_ ≤ ∑ i ∈ Finset.range m, ((m:ℝ)*D) :=Finset.sum_le_sum fun i hi => hr i (Finset.mem_range.mp hi).le_ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul,D]; field_simpby_contra! hyapply (not_lt_of_ge hAvg)refine Finset.sum_lt_sum_of_nonempty ⟨0,Finset.mem_range.mpr hN⟩ (fun j hj => ?_)have hj := Finset.mem_range.mp hjexact hy _ hj (hs _ (by omega))variable {α G Ω : Type} [Fintype α] [Fintype G] [Fintype Ω] [AddCommGroup G]omit [AddCommGroup G] inprivate lemma choose3 (P : Law Ω) (a b c : Ω → ℝ)(ha : ∀ x, 0 ≤ a x) (hb : ∀ x, 0 ≤ b x) (hc : ∀ x, 0 ≤ c x)(A B C : ℝ) (hA : 0 < A) (hB : 0 < B) (hC : 0 < C)(h1 : P.Ex a ≤ A) (h2 : P.Ex b ≤ B) (h3 : P.Ex c ≤ C) :∃ x, 0 < P x ∧ a x ≤ 3*A ∧ b x ≤ 3*B ∧ c x ≤ 3*C := byobtain ⟨x,hx,hh⟩ := P.exists_le_Ex fun x => a x*A⁻¹+b x*B⁻¹+c x*C⁻¹have H : a x/A+b x/B+c x/C ≤ 3 := bysimp_rw [Ex_add,Ex_mul, ← div_eq_mul_inv] at hhlinarith [(div_le_one hA).mpr h1,(div_le_one hB).mpr h2,(div_le_one hC).mpr h3]have hI := div_nonneg (ha x) hA.lehave hJ := div_nonneg (hb x) hB.lehave hK := div_nonneg (hc x) hC.leexact ⟨x,hx,(div_le_iff₀ hA).mp (by linarith),(div_le_iff₀ hB).mp(by linarith),(div_le_iff₀ hC).mp (by linarith)⟩lemma kl_covered {ι : Type} [Fintype ι] [DecidableEq ι](P : Law Ω) (X : Ω → ι → α) (q : Law α) (h : ∀ i, P.send (fun a => X a i) = q) :covered P X q := byintro a ha irw [← h i]exact P.send_pos (fun a => X a i) hadef iid (p : Law α) (n : ℕ) := pack (fun _ : Fin n => p)theorem select_context (tag : α → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x)(T N m : ℕ) (hm0 : 0 < m) (hm : m ≤ N) (hT : 3*N ≤ T)(E : ℝ) (hE : 0 < E) [Nonempty α](h : ∀ p : Law α, exp (-E) ≤ heatMoment (Fin T) p tag c) :∃ (p : Law α) (Ψ : Law (WordSample N α G)), exch Ψ ∧(∀ i : Fin N, Ψ.send (fun a => a.1 i) = p) ∧log (Fintype.card α) - p.entropy ≤ 3*(E/N) ∧bill tag c p Ψ Prod.fst Prod.snd ≤ 3*E ∧tv (Ψ.send (prefixB Prod.fst m hm)) (iid p m) ≤ 2*m*√E/N := byobtain ⟨P,hp,hx,hu⟩ := noisy_symm tag c E hlet X : WordSample T α G → Letters T α := Prod.fstlet L := log (Fintype.card α)let a j := L-rateH P X jhave h0 : 0 < N := by omegahave h1 (j : ℕ) : 0 ≤ a j := sub_nonneg.mpr (rate_bdd P X j)let u := uniform αhave hcov : covered P X u := kl_covered P X u huhave heq : ∑ j ∈ Finset.range T, a j ≤ E := byhave H := kl_le_bill hcov tag c hc Prod.snddsimp only [a,L]rw [sum_deficit]exact le_trans (le_trans(le_add_of_nonneg_right (P.Ex_nonneg fun x => hc (x.2))) H) hpobtain ⟨j,hj,hb,hj'⟩ := choose_slow (a:=a) (fun x y hh =>sub_le_sub_left (rate_antitone hx hh) _) h1 hE.le T N m h0 hm hT heqlet W := prefixB X j (by omega)let V := readBlock X j N (by omega)let Y := readBlock X j m (by omega)let R (w) := P.after W wlet H := readLetter X j (by omega)let ν (w) := (R w).send Hlet Pw := P.send Wlet b (w) := L-(ν w).entropylet k (w) := bill tag c u (R w) V Prod.sndlet d (w) := kl ((R w).send Y) (pack (fun _ : Fin m => ν w))have Hb (w : Letters j α) : 0 ≤ b w :=sub_nonneg.mpr (entropy_le_log_card _)have Hk (w : Letters j α) : 0 ≤ k w := byapply bill_nonneg _ tag c hcintro a _ _rw [uniform_apply]positivityhave hv (w) (i : Fin m) :(R w).send (fun x => Y x i) = ν w := conditional_block_marg hx (j:=j) (m:=m) (by omega) w ihave hv' (w) (i : Fin N) :(R w).send (fun x => V x i) = ν w := conditional_block_marg hx (j:=j) (m:=N) (by omega) w ihave Hd (w : Letters j α) : 0 ≤ d w := kl_nonneg(covered_pack (kl_covered _ _ _ (hv w)))have Hm' : (0:ℝ) < m := by exact_mod_cast hm0have HN : (0:ℝ) < N := by exact_mod_cast h0have H1 : Pw.Ex b ≤ E/N := byunfold b ν Pwrw [Ex_sub,Ex_const]exact le_trans (le_of_eq (bydsimp only [a]rw [rate_lt P X (show j<T by omega),Hcond_after]; rfl)) hbhave H2 : Pw.Ex k ≤ E := le_trans(prefix_bill tag c u P X _ hcov j N (by omega)) hphave H3 : Pw.Ex d ≤ (m:ℝ)^2*E/N^2 := byunfold Pw dhave HH := avg_block_kl hx (j:=j) (m:=m) (by omega) (by omega)apply le_trans (b:=∑ i ∈ Finset.range m, (rateH P X j - rateH P X (j+i))) HH.leapply le_trans (b:=∑ i ∈ Finset.range m, (a (j+i)-a j)) ?_ hj'apply Finset.sum_le_sum; intro i _; dsimp only [a]; linarithobtain ⟨w,hw,h1,h2,h3⟩ := choose3 Pw b k d Hb Hk Hd (E/N) E ((m:ℝ)^2*E/N^2)(by positivity) hE (by positivity) H1 H2 H3let Ψ := (R w).send (fun x => (V x,x.2))have hmx := conditional_block_exch hx (j:=j) (m:=N) (by omega) wrefine ⟨ν w,Ψ,hmx,fun i => ?_,h1,?_,?_⟩· dsimp only [Ψ]rw [send_send]; exact hv' w i· dsimp only [Ψ]rw [bill_send]exact (bill_change (covered_subfamily (covered_after hcov W w hw) (offset j N (by omega)))tag c Prod.snd (ν w) (hv' w)).trans h2· have hh : Ψ.send (prefixB Prod.fst m hm) = (R w).send Y := byunfold Ψ; rw [send_send, show Y = _ from block_cut X j N m (by omega) hm]; rflrw [hh]let v := tv ((R w).send Y) (iid (ν w) m)have ht : v^2 ≤ 3*((m:ℝ)^2*E/N^2) :=(tv_sq_le_kl (covered_pack (kl_covered _ _ _ (hv w)))).trans h3have h4 : 3*((m:ℝ)^2*E/N^2) ≤ (2*m*√E/N)^2 := byrw [div_pow,mul_pow,mul_pow, sq_sqrt hE.le]have H := pow_pos HN 2field_simp; nlinarithchange v ≤ _nlinarith [ht.trans h4,sqrt_nonneg E,show 0 ≤ 2*m*√E/N by positivity]end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178import OAI.Analysis.FourierLLogL.Compress.Prefix/-! # Selecting conditional iid comparator -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Real Lawprivate lemma choose_slow {a : ℕ → ℝ} (ha : Monotone a)(h0 : ∀ j, 0 ≤ a j) {E : ℝ} (hE : 0 ≤ E) (T N m : ℕ)(hN : 0 < N) (hm : m ≤ N) (hT : 3*N ≤ T)(hh : ∑ j ∈ Finset.range T, a j ≤ E) :∃ j, j < N ∧ a j ≤ E/N ∧∑ i ∈ Finset.range m, (a (j+i)-a j) ≤ m^2*E/(N:ℝ)^2 := byhave hp : 0 < (N:ℝ) := by exact_mod_cast hNlet D := E/Nhave hs (l : ℕ) (hl : l ≤ 2*N) : a l ≤ D := byhave Hlt : ∑ j ∈ Finset.range (l+N), a j ≤ E :=le_trans (Finset.sum_le_sum_of_subset_of_nonneg(Finset.range_mono (by omega)) (fun i _ _ => h0 i)) hhrw [Finset.sum_range_add] at Hlthave H : ∑ _ ∈ Finset.range N, a l ≤ ∑ i ∈ Finset.range N, a (l+i) :=Finset.sum_le_sum fun i _ => ha (by omega : l ≤ l+i)simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at Happly (le_div_iff₀ hp).mprhave : 0 ≤ ∑ j ∈ Finset.range l, a j := Finset.sum_nonneg fun j _ => h0 jlinarithhave HD : 0 ≤ D := div_nonneg hE hp.lehave hr (i : ℕ) (hi : i ≤ m) :∑ j ∈ Finset.range N, (a (j+i)-a j) ≤ m*D := byhave h1 := Finset.sum_range_add a N ihave h2 := Finset.sum_range_add a i Nhave hcmp : ∑ j ∈ Finset.range i, a (N+j) ≤ ∑ j ∈ Finset.range i, D := byapply Finset.sum_le_sumintro j hjapply hs; rw [Finset.mem_range] at hj; omegasimp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] at hcmphave hl : 0 ≤ ∑ j ∈ Finset.range i, a j := Finset.sum_nonneg fun j _ => h0 jhave hle : (i:ℝ)*D ≤ (m:ℝ)*D := by gcongrrw [show i+N=N+i by omega] at h2simp_rw [show ∀ j, j+i=i+j from fun j => add_comm _ _, Finset.sum_sub_distrib]linarithlet f j := ∑ i ∈ Finset.range m, (a (j+i)-a j)have hAvg : ∑ j ∈ Finset.range N, f j ≤ ∑ i ∈ Finset.range N, ((m:ℝ)^2*E/(N:ℝ)^2) := byunfold frw [Finset.sum_comm]calc_ ≤ ∑ i ∈ Finset.range m, ((m:ℝ)*D) :=Finset.sum_le_sum fun i hi => hr i (Finset.mem_range.mp hi).le_ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul,D]; field_simpby_contra! hyapply (not_lt_of_ge hAvg)refine Finset.sum_lt_sum_of_nonempty ⟨0,Finset.mem_range.mpr hN⟩ (fun j hj => ?_)have hj := Finset.mem_range.mp hjexact hy _ hj (hs _ (by omega))variable {α G Ω : Type} [Fintype α] [Fintype G] [Fintype Ω] [AddCommGroup G]omit [AddCommGroup G] inprivate lemma choose3 (P : Law Ω) (a b c : Ω → ℝ)(ha : ∀ x, 0 ≤ a x) (hb : ∀ x, 0 ≤ b x) (hc : ∀ x, 0 ≤ c x)(A B C : ℝ) (hA : 0 < A) (hB : 0 < B) (hC : 0 < C)(h1 : P.Ex a ≤ A) (h2 : P.Ex b ≤ B) (h3 : P.Ex c ≤ C) :∃ x, 0 < P x ∧ a x ≤ 3*A ∧ b x ≤ 3*B ∧ c x ≤ 3*C := byobtain ⟨x,hx,hh⟩ := P.exists_le_Ex fun x => a x*A⁻¹+b x*B⁻¹+c x*C⁻¹have H : a x/A+b x/B+c x/C ≤ 3 := bysimp_rw [Ex_add,Ex_mul, ← div_eq_mul_inv] at hhlinarith [(div_le_one hA).mpr h1,(div_le_one hB).mpr h2,(div_le_one hC).mpr h3]have hI := div_nonneg (ha x) hA.lehave hJ := div_nonneg (hb x) hB.lehave hK := div_nonneg (hc x) hC.leexact ⟨x,hx,(div_le_iff₀ hA).mp (by linarith),(div_le_iff₀ hB).mp(by linarith),(div_le_iff₀ hC).mp (by linarith)⟩lemma kl_covered {ι : Type} [Fintype ι] [DecidableEq ι](P : Law Ω) (X : Ω → ι → α) (q : Law α) (h : ∀ i, P.send (fun a => X a i) = q) :covered P X q := byintro a ha irw [← h i]exact P.send_pos (fun a => X a i) hadef iid (p : Law α) (n : ℕ) := pack (fun _ : Fin n => p)theorem select_context (tag : α → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x)(T N m : ℕ) (hm0 : 0 < m) (hm : m ≤ N) (hT : 3*N ≤ T)(E : ℝ) (hE : 0 < E) [Nonempty α](h : ∀ p : Law α, exp (-E) ≤ heatMoment (Fin T) p tag c) :∃ (p : Law α) (Ψ : Law (WordSample N α G)), exch Ψ ∧(∀ i : Fin N, Ψ.send (fun a => a.1 i) = p) ∧log (Fintype.card α) - p.entropy ≤ 3*(E/N) ∧bill tag c p Ψ Prod.fst Prod.snd ≤ 3*E ∧tv (Ψ.send (prefixB Prod.fst m hm)) (iid p m) ≤ 2*m*√E/N := byobtain ⟨P,hp,hx,hu⟩ := noisy_symm tag c E hlet X : WordSample T α G → Letters T α := Prod.fstlet L := log (Fintype.card α)let a j := L-rateH P X jhave h0 : 0 < N := by omegahave h1 (j : ℕ) : 0 ≤ a j := sub_nonneg.mpr (rate_bdd P X j)let u := uniform αhave hcov : covered P X u := kl_covered P X u huhave heq : ∑ j ∈ Finset.range T, a j ≤ E := byhave H := kl_le_bill hcov tag c hc Prod.snddsimp only [a,L]rw [sum_deficit]exact le_trans (le_trans(le_add_of_nonneg_right (P.Ex_nonneg fun x => hc (x.2))) H) hpobtain ⟨j,hj,hb,hj'⟩ := choose_slow (a:=a) (fun x y hh =>sub_le_sub_left (rate_antitone hx hh) _) h1 hE.le T N m h0 hm hT heqlet W := prefixB X j (by omega)let V := readBlock X j N (by omega)let Y := readBlock X j m (by omega)let R (w) := P.after W wlet H := readLetter X j (by omega)let ν (w) := (R w).send Hlet Pw := P.send Wlet b (w) := L-(ν w).entropylet k (w) := bill tag c u (R w) V Prod.sndlet d (w) := kl ((R w).send Y) (pack (fun _ : Fin m => ν w))have Hb (w : Letters j α) : 0 ≤ b w :=sub_nonneg.mpr (entropy_le_log_card _)have Hk (w : Letters j α) : 0 ≤ k w := byapply bill_nonneg _ tag c hcintro a _ _rw [uniform_apply]positivityhave hv (w) (i : Fin m) :(R w).send (fun x => Y x i) = ν w := conditional_block_marg hx (j:=j) (m:=m) (by omega) w ihave hv' (w) (i : Fin N) :(R w).send (fun x => V x i) = ν w := conditional_block_marg hx (j:=j) (m:=N) (by omega) w ihave Hd (w : Letters j α) : 0 ≤ d w := kl_nonneg(covered_pack (kl_covered _ _ _ (hv w)))have Hm' : (0:ℝ) < m := by exact_mod_cast hm0have HN : (0:ℝ) < N := by exact_mod_cast h0have H1 : Pw.Ex b ≤ E/N := byunfold b ν Pwrw [Ex_sub,Ex_const]exact le_trans (le_of_eq (bydsimp only [a]rw [rate_lt P X (show j<T by omega),Hcond_after]; rfl)) hbhave H2 : Pw.Ex k ≤ E := le_trans(prefix_bill tag c u P X _ hcov j N (by omega)) hphave H3 : Pw.Ex d ≤ (m:ℝ)^2*E/N^2 := byunfold Pw dhave HH := avg_block_kl hx (j:=j) (m:=m) (by omega) (by omega)apply le_trans (b:=∑ i ∈ Finset.range m, (rateH P X j - rateH P X (j+i))) HH.leapply le_trans (b:=∑ i ∈ Finset.range m, (a (j+i)-a j)) ?_ hj'apply Finset.sum_le_sum; intro i _; dsimp only [a]; linarithobtain ⟨w,hw,h1,h2,h3⟩ := choose3 Pw b k d Hb Hk Hd (E/N) E ((m:ℝ)^2*E/N^2)(by positivity) hE (by positivity) H1 H2 H3let Ψ := (R w).send (fun x => (V x,x.2))have hmx := conditional_block_exch hx (j:=j) (m:=N) (by omega) wrefine ⟨ν w,Ψ,hmx,fun i => ?_,h1,?_,?_⟩· dsimp only [Ψ]rw [send_send]; exact hv' w i· dsimp only [Ψ]rw [bill_send]exact (bill_change (covered_subfamily (covered_after hcov W w hw) (offset j N (by omega)))tag c Prod.snd (ν w) (hv' w)).trans h2· have hh : Ψ.send (prefixB Prod.fst m hm) = (R w).send Y := byunfold Ψ; rw [send_send, show Y = _ from block_cut X j N m (by omega) hm]; rflrw [hh]let v := tv ((R w).send Y) (iid (ν w) m)have ht : v^2 ≤ 3*((m:ℝ)^2*E/N^2) :=(tv_sq_le_kl (covered_pack (kl_covered _ _ _ (hv w)))).trans h3have h4 : 3*((m:ℝ)^2*E/N^2) ≤ (2*m*√E/N)^2 := byrw [div_pow,mul_pow,mul_pow, sq_sqrt hE.le]have H := pow_pos HN 2field_simp; nlinarithchange v ≤ _nlinarith [ht.trans h4,sqrt_nonneg E,show 0 ≤ 2*m*√E/N by positivity]end FourierLLogL.Compressend OAI
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import OAI.Analysis.FourierLLogL.Compress.Scheduleimport OAI.Analysis.FourierLLogL.Compress.Phaseimport OAI.Analysis.FourierLLogL.Compress.Lowopen Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A G Θ : Type} [Fintype A] [Fintype G] [DecidableEq G][AddCommGroup G] [Nonempty A] [Fintype Θ]omit [Nonempty A] inlemma init_gap (tag : A → G) (hi : Injective tag) (P : Law A) :fundG tag (initial P) 1 = P.entropy := byrw [G_initial]let Q := iid P 1have h : Q.send (fun x => x 0) = P := marginalPack (fun _ => P) _change Q.H _ = _; rw [← h]refine H_partition Q (X:=tot tag) (Y:=fun x => x 0) (fun _ _ => ?_)simp only [tot,Fin.sum_univ_one,hi.eq_iff]/-- Finite compression from schedule and numerical constraints, before achoice of scales in terms of height. -/lemma compress_arrays (tag : A → G) (hi : Injective tag) (q : Law G)(hq : ∀ x, 0 < q x) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (hc0 : c 0=0)(Q : Law Θ) (χ : Θ → AddChar G ℂ) (hn : ∀ t x, ‖χ t x‖=1)(hrq : ∀ g, (↑(exp (-c g)):ℂ)=Q.Cx fun t => χ t g)(hlog : ∀ g, -log (q g) = -log (q 0) + c g)(F L C : ℝ) (hF : 1 ≤ F) (hL : 0 ≤ L)(T N m : ℕ) (hm : 0 < m) (hN : m ≤ N) (hT : 3*N ≤ T) (S : Schedule)(l u r : ℕ → ℕ)(hl : ∀ i, i < S.size → l i ≤ u i ∧ u i ≤ m ∧ 0 < u i ∧ 0 < r i ∧2*r i*l i ≤ N ∧ L ≤ (r i:ℝ)*(u i:ℝ))(hp : ∀ i j, i < j → j < S.size → u j ≤ l i ∧ r i ≤ r j)(hg : ∀ P : Law A, exp (-F) ≤ heatMoment (Fin T) P tag c)(hC : 10*F+2*(-log (q 0))+1 ≤ C)(hh : ∀ i, i < S.size → 0 < l i)(hs : ∀ i, i < S.size →2*m*√F/N*lnS (Fin (u i)) tag ≤ F ∧log (Fintype.card (Ticket (r i) (2*r i))) + r i +2*(2*m*√F/N)*lnS (Fin (r i*l i)) tag ≤ 6*F) :∃ (a : A) (s : Finset A), s.Nonempty ∧log (Fintype.card A)-log (s.card:ℝ) ≤8*(3*(F/N)+S.loss*C*C/F)+2 ∧ small_defects tag χ Q L s a (350*F) := byhave hFp : 0 < F := by linarithhave hCp : 0 < C := byhave hh := Real.log_nonpos (q.nonneg 0) (q.le_one 0)linarithhave hNp : (0:ℝ)< N := byexact_mod_cast (Nat.lt_of_lt_of_le hm hN)obtain ⟨p,R,h1,h2,h3,h4,h5⟩ := select_context tag c hc T N m hm hN hT F hFp hglet ε := 2*m*√F/Nlet x : Starting tag c N m (3*F) ε := ⟨p,R,h1,h2,h4,hN,h5⟩let W := initial phave ha (i) (hh : i < S.size) : fundG tag W (u i) ≤ C := byhave H := x.G_upper hc q hq (-log (q 0)) hlog _ (hl i hh).2.1apply H.transunfold εhave hj := Real.log_le_sub_one_of_pos (show (0:ℝ)<2 by norm_num)linarith [(hs i hh).1]have hb (i) (hh : i < S.size) (hle : 1 ≤ l i) : fundI tag W (r i) ≤ C := byrefine (x.I_upper hc q hq (-log (q 0)) hlog _ ?_).trans ?_· have := (hl i hh).2.2.2.2.1nlinarithlinarithobtain ⟨P,hv,hW,i,hi',hK⟩ :=reach tag hi c hc W C F hCp hFp S m l u r hm (fun i h => ⟨(hl i h).1,(hl i h).2.1⟩)hp ha (fun i h => hb i h (hh i h))obtain ⟨hi1,hi2,hu',hr',hn',hL'⟩ := hl i hi'have HK : fundK tag c P (u i) (r i) ≤ 10*F := byhave H := x.K_upper hc hc0 (l i) (r i) hr' (le_trans hi1 hi2) hn'have HH := K_anti tag c hv (l i) (r i)change fundK tag c W _ _ ≤ _ at Hdsimp only [ε] at Hlinarith [(hs i hi').2]let D := 3*(F/N)+S.loss*C*C/Fhave hD : 0 < D := by unfold D; have := S.loss_pos; positivityhave Hd : log (Fintype.card A) - fundG tag P 1 ≤ D := byrw [show fundG tag W 1 = _ from init_gap tag hi p] at hWlinarithobtain ⟨p',z,hz,hz'⟩ := freeze tag hi c hc P (u i) (r i) hu' hr' (10*F) D(by positivity) hD HK Hdhave : NeZero (r i) := ⟨hr'.ne'⟩have : NeZero (u i) := ⟨hu'.ne'⟩have H0 := alignment tag c Q χ hn hrq p' z (10*F) D L (by linarith) hD hL(by simpa only [Fintype.card_prod,Fintype.card_fin,Nat.cast_mul]) hz (bysimpa only [Fintype.card_prod,Fintype.card_fin,Nat.cast_mul])rwa [show 350*F = 35*(10*F) by ring]end FourierLLogL.Compressend OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import OAI.Analysis.FourierLLogL.Compress.Scheduleimport OAI.Analysis.FourierLLogL.Compress.Phaseimport OAI.Analysis.FourierLLogL.Compress.Lowopen Function Filter Setopen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A G Θ : Type} [Fintype A] [Fintype G] [DecidableEq G][AddCommGroup G] [Nonempty A] [Fintype Θ]omit [Nonempty A] inlemma init_gap (tag : A → G) (hi : Injective tag) (P : Law A) :fundG tag (initial P) 1 = P.entropy := byrw [G_initial]let Q := iid P 1have h : Q.send (fun x => x 0) = P := marginalPack (fun _ => P) _change Q.H _ = _; rw [← h]refine H_partition Q (X:=tot tag) (Y:=fun x => x 0) (fun _ _ => ?_)simp only [tot,Fin.sum_univ_one,hi.eq_iff]/-- Finite compression from schedule and numerical constraints, before achoice of scales in terms of height. -/lemma compress_arrays (tag : A → G) (hi : Injective tag) (q : Law G)(hq : ∀ x, 0 < q x) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (hc0 : c 0=0)(Q : Law Θ) (χ : Θ → AddChar G ℂ) (hn : ∀ t x, ‖χ t x‖=1)(hrq : ∀ g, (↑(exp (-c g)):ℂ)=Q.Cx fun t => χ t g)(hlog : ∀ g, -log (q g) = -log (q 0) + c g)(F L C : ℝ) (hF : 1 ≤ F) (hL : 0 ≤ L)(T N m : ℕ) (hm : 0 < m) (hN : m ≤ N) (hT : 3*N ≤ T) (S : Schedule)(l u r : ℕ → ℕ)(hl : ∀ i, i < S.size → l i ≤ u i ∧ u i ≤ m ∧ 0 < u i ∧ 0 < r i ∧2*r i*l i ≤ N ∧ L ≤ (r i:ℝ)*(u i:ℝ))(hp : ∀ i j, i < j → j < S.size → u j ≤ l i ∧ r i ≤ r j)(hg : ∀ P : Law A, exp (-F) ≤ heatMoment (Fin T) P tag c)(hC : 10*F+2*(-log (q 0))+1 ≤ C)(hh : ∀ i, i < S.size → 0 < l i)(hs : ∀ i, i < S.size →2*m*√F/N*lnS (Fin (u i)) tag ≤ F ∧log (Fintype.card (Ticket (r i) (2*r i))) + r i +2*(2*m*√F/N)*lnS (Fin (r i*l i)) tag ≤ 6*F) :∃ (a : A) (s : Finset A), s.Nonempty ∧log (Fintype.card A)-log (s.card:ℝ) ≤8*(3*(F/N)+S.loss*C*C/F)+2 ∧ small_defects tag χ Q L s a (350*F) := byhave hFp : 0 < F := by linarithhave hCp : 0 < C := byhave hh := Real.log_nonpos (q.nonneg 0) (q.le_one 0)linarithhave hNp : (0:ℝ)< N := byexact_mod_cast (Nat.lt_of_lt_of_le hm hN)obtain ⟨p,R,h1,h2,h3,h4,h5⟩ := select_context tag c hc T N m hm hN hT F hFp hglet ε := 2*m*√F/Nlet x : Starting tag c N m (3*F) ε := ⟨p,R,h1,h2,h4,hN,h5⟩let W := initial phave ha (i) (hh : i < S.size) : fundG tag W (u i) ≤ C := byhave H := x.G_upper hc q hq (-log (q 0)) hlog _ (hl i hh).2.1apply H.transunfold εhave hj := Real.log_le_sub_one_of_pos (show (0:ℝ)<2 by norm_num)linarith [(hs i hh).1]have hb (i) (hh : i < S.size) (hle : 1 ≤ l i) : fundI tag W (r i) ≤ C := byrefine (x.I_upper hc q hq (-log (q 0)) hlog _ ?_).trans ?_· have := (hl i hh).2.2.2.2.1nlinarithlinarithobtain ⟨P,hv,hW,i,hi',hK⟩ :=reach tag hi c hc W C F hCp hFp S m l u r hm (fun i h => ⟨(hl i h).1,(hl i h).2.1⟩)hp ha (fun i h => hb i h (hh i h))obtain ⟨hi1,hi2,hu',hr',hn',hL'⟩ := hl i hi'have HK : fundK tag c P (u i) (r i) ≤ 10*F := byhave H := x.K_upper hc hc0 (l i) (r i) hr' (le_trans hi1 hi2) hn'have HH := K_anti tag c hv (l i) (r i)change fundK tag c W _ _ ≤ _ at Hdsimp only [ε] at Hlinarith [(hs i hi').2]let D := 3*(F/N)+S.loss*C*C/Fhave hD : 0 < D := by unfold D; have := S.loss_pos; positivityhave Hd : log (Fintype.card A) - fundG tag P 1 ≤ D := byrw [show fundG tag W 1 = _ from init_gap tag hi p] at hWlinarithobtain ⟨p',z,hz,hz'⟩ := freeze tag hi c hc P (u i) (r i) hu' hr' (10*F) D(by positivity) hD HK Hdhave : NeZero (r i) := ⟨hr'.ne'⟩have : NeZero (u i) := ⟨hu'.ne'⟩have H0 := alignment tag c Q χ hn hrq p' z (10*F) D L (by linarith) hD hL(by simpa only [Fintype.card_prod,Fintype.card_fin,Nat.cast_mul]) hz (bysimpa only [Fintype.card_prod,Fintype.card_fin,Nat.cast_mul])rwa [show 350*F = 35*(10*F) by ring]end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213import OAI.Analysis.FourierLLogL.Compress.Select/-! # Thinning to exact row marginals -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A B Ω ι κ : Type} [Fintype A] [Fintype B] [DecidableEq B] [Fintype Ω] {n r : ℕ}abbrev Ticket (r n : ℕ) := Option (Fin r ↪ Fin n)def gain (j : Fin r) (f : Fin n → ℝ) : Ticket r n → ℝ| none => 0| some e => f (e j)private lemma perm_uniform (x : B) :(uniform (Equiv.Perm B)).send (fun e => e x) = letI : Nonempty B := ⟨x⟩; uniform B := byhave : Nonempty B := ⟨x⟩let R := uniform (Equiv.Perm B)let W := R.send (fun e => e x)have he (a b : B) : W a = W b := byclassicallet f := Equiv.swap a bhave hh (e : Equiv.Perm B) : (e x=a) ↔ (f*e) x=b := bychange _ ↔ f (e x) = _rw [← show f a = b from Equiv.swap_apply_left _ _, f.injective.eq_iff]unfold W; rw [send_apply,send_apply,prob_eq,prob_eq]exact Fintype.sum_equiv (Equiv.mulLeft f) _ _ fun i => bychange _ = if (f*i) x=b then _ else _split_ifs <;> simp_all onlyall_goals first | rfl | exact False.elim (by grind)apply Law.extintro ahave hh (w : B) := he w ahave H := W.totalsimp_rw [hh, Finset.sum_const,Finset.card_univ,nsmul_eq_mul] at Hchange W a = _rw [uniform_apply]field_simplinarithprivate lemma count_frac (s : Finset (Fin n)) (hn : 0 < n) :0 ≤ (s.card:ℝ)/n ∧ (s.card:ℝ)/n ≤ 1 := byhave hp : (0:ℝ)< n := by exact_mod_cast hnconstructor· positivity· apply (div_le_one hp).mprexact_mod_cast (by simpa using Finset.card_le_univ s : s.card ≤ n)/-- Sampling rule for the realized set of tagged input blocks. -/lemma choose_tickets (r n : ℕ) (hr : 0 < r) (hn : 0 < n) (s : Finset (Fin n)) :∃ k : Law (Ticket r n), ∀ (j : Fin r) (f : Fin n → ℝ),k.Ex (gain j f) = if r ≤ s.card then (∑ i ∈ s, f i)/n else 0 := byclassicalby_cases hs : r ≤ s.card· have he : r ≤ Fintype.card s := by simpa using hshave : Nonempty s := Fintype.card_pos_iff.mp (lt_of_lt_of_le hr he)let t := (s.card:ℝ)/nlet g : Fin r ↪ s := (Fin.castLEEmb he).trans (Fintype.equivFin _).symm.toEmbeddinglet T (f : Equiv.Perm s) : Ticket r n :=some ((g.trans f.toEmbedding).trans (Embedding.subtype _))refine ⟨mixture ((uniform (Equiv.Perm s)).send T) (point none) t(count_frac _ hn).1 (count_frac _ hn).2,?_⟩intro j frw [ite_eq_left hs, mixture_Ex,Ex_point,Ex_send]dsimp only [gain,T]let F (x : s) := f xchange t*(uniform (Equiv.Perm s)).Ex (fun i => F (i (g j))) + _*0 = _have h : (uniform (Equiv.Perm s)).Ex (fun i => F (i (g j))) = (uniform s).Ex F := byhave H := Ex_send (uniform (Equiv.Perm s)) (fun i => i (g j)) Frw [perm_uniform] at Hexact H.symmrw [h]unfold t Ex Fhave hh : 0 < (s.card:ℝ) := by exact_mod_cast lt_of_lt_of_le hr hssimp only [uniform_apply,← Finset.mul_sum,mul_zero,add_zero, Fintype.card_coe,Finset.univ_eq_attach,Finset.sum_attach]field_simp· refine ⟨point none,fun j f => ?_⟩rw [ite_eq_right hs,Ex_point]; rfl/-- A numerical tag probability. -/private def ratio (a b : ℝ) := min a b/aprivate lemma ratio_bounds (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) :0 ≤ ratio a b ∧ ratio a b ≤ 1 ∧ a * ratio a b = min a b := byunfold ratioobtain hx|hx := eq_or_lt_of_le ha· simp [← hx,hb]exact ⟨div_nonneg (le_min ha hb) ha, (div_le_one hx).mpr (min_le_left _ _), by field_simp⟩def tagChance (p q : Law A) (x : A) : Law Bool :=coinP (ratio (p x) (q x)) (ratio_bounds _ _ (p.nonneg _) (q.nonneg _)).1(ratio_bounds _ _ (p.nonneg _) (q.nonneg _)).2.1lemma tag_test (p q : Law A) (f : A → ℝ) :p.Ex (fun x => (tagChance p q x).Ex (fun b : Bool => if b then f x else 0)) =∑ x, min (p x) (q x) * f x := byunfold tagChancesimp_rw [coinP_Ex]simp only [Bool.false_eq_true, ↓reduceIte,mul_zero,add_zero,Ex,← mul_assoc,(ratio_bounds (p _) (q _) (p.nonneg _) (q.nonneg _)).2.2]/-- Build a channel from the underlying input to the rejection/selected rows. -/lemma thin_sampler (r n : ℕ) (hr : 0 < r) (hn : n=2*r) (P : Law Ω) (q : Law A)(X : Ω → Fin n → A) (ε : ℝ)(hε : ∀ i, ((P.send fun x => X x i).tv q) ≤ ε) :∃ (k : Ω → Law (Ticket r n)),let R := P.withNext kR.prob (fun x => x.2 = none) ≤ 2 * ε ∧(∀ (j : Fin r) (f : A → ℝ) (_h : ∀ x, 0 ≤ f x),R.Ex (fun x => gain j (fun i => f (X x.1 i)) x.2) ≤ q.Ex f) := byclassicalhave hnp : 0 < n := by omegahave hNr : (0:ℝ) < n := by exact_mod_cast hnpchoose c hc using choose_tickets r n hr hnplet p (i : Fin n) := P.send fun x => X x ilet Q (x) := pack (fun i : Fin n => tagChance (p i) q (X x i))let S (x : Fin n → Bool) := Finset.univ.filter (fun i => x i = true)let k (x : Ω) := (Q x).through fun y => c (S y)let R := P.withNext khave hTag (x) (f : Fin n → ℝ) :(Q x).Ex (fun b => ∑ i ∈ S b, f i) =∑ i : Fin n, (tagChance (p i) q (X x i)).Ex (fun b : Bool => if b then f i else 0) := byunfold S Qsimp_rw [Finset.sum_filter,Ex_finset_sum]apply Finset.sum_congr rflintro i _exact Ex_pack_proj _ i (fun b : Bool => if b then f i else 0)have hComp (f : A → ℝ) :P.Ex (fun x => (Q x).Ex fun b => ∑ i ∈ S b, f (X x i)) =∑ i : Fin n, ∑ a, min (p i a) (q a) * f a := byhave HH (x : Ω) := hTag x (fun i => f (X x i))simp_rw [HH,Ex_finset_sum]apply Finset.sum_congr rfl; intro i _rw [← tag_test]exact (Ex_send P (fun x => X x i) (fun y =>(tagChance (p i) q y).Ex (fun b => if b then f y else 0))).symmhave hTick (x) (j : Fin r) (f : Fin n → ℝ) :(k x).Ex (gain j f) =(Q x).Ex (fun b => if r ≤ (S b).card then (∑ i ∈ S b, f i)/n else 0) := byunfold k; rw [Ex_through]; simp_rw [hc]refine ⟨k,?_,?_⟩· let j : Fin r := ⟨0,hr⟩let F := fun (_ : Fin n) => (1:ℝ)have hg : R.prob (fun x => x.2 = none) =1 - P.Ex (fun x => (k x).Ex (gain j F)) := byunfold probrw [← Ex_withNext P k (fun x => gain j F x.2)]calc_ = R.Ex fun x => 1-gain j F x.2 := bycongr 1; funext x; cases x with| mk a b => cases b <;> simp [gain,F]_ = _ := by rw [Ex_sub (f:=fun _ => 1),Ex_const]have h1 (x : Ω) :2/n * (Q x).Ex (fun b => ∑ i ∈ S b, F i)-1 ≤ (k x).Ex (gain j F) := byrw [hTick]have HH (b : Fin n → Bool) :2/(n:ℝ) * (∑ i ∈ S b, F i) - 1 ≤ if r ≤ (S b).card then(∑ i ∈ S b, F i)/n else 0 := byhave ha : (↑n:ℝ) = 2*(r:ℝ) := by exact_mod_cast hnhave hb : ((S b).card:ℝ) ≤ n := by exact_mod_cast(by simpa using Finset.card_le_univ (S b) : (S b).card ≤ n)simp only [F,Finset.sum_const,nsmul_eq_mul,mul_one]split_ifs with H· field_simp; linarith· have : ((S b).card:ℝ) ≤ r := by exact_mod_cast (le_of_not_ge H)field_simp; linarithrefine le_trans (b:=(Q x).Ex (fun b => 2/(n:ℝ)*(∑ i ∈ S b, F i)-1))?_ (Ex_mono _ HH)rw [Ex_sub,Ex_lmul,Ex_const]have HE := hComp (fun _ => 1)have HF : (n:ℝ)*(1-ε) ≤ P.Ex fun x => (Q x).Ex (fun b => ∑ i ∈ S b, F i) := byunfold F; rw [HE]simp_rw [mul_one,tv_common]apply le_trans (b:=∑ i : Fin n,(1-ε)) _ (Finset.sum_le_sum _)· simp; apply le_of_eq; ringintro i _; exact sub_le_sub_left (hε i) _have HL := P.Ex_mono h1rw [Ex_sub,Ex_lmul,Ex_const] at HLchange R.prob _ ≤ _rw [hg]field_simp at HLnlinarith· intro j f hfchange R.Ex _ ≤ _unfold R; rw [Ex_withNext]have h1 (x : Ω) :(k x).Ex (gain j (fun i => f (X x i))) ≤(Q x).Ex (fun b => ∑ i ∈ S b, f (X x i)) * (n:ℝ)⁻¹ := byrw [hTick, ← Ex_mul]apply Ex_monointro bsplit_ifs· simp [div_eq_mul_inv]· exact mul_nonneg (Finset.sum_nonneg (fun i _ => hf _)) (by positivity)refine le_trans (Ex_mono P h1) ?_rw [Ex_mul,hComp]apply le_trans (b := (∑ i : Fin n, q.Ex f) * (n:ℝ)⁻¹)· apply mul_le_mul_of_nonneg_right _ (by positivity)refine Finset.sum_le_sum fun i _ => Finset.sum_le_sum fun a _ =>mul_le_mul_of_nonneg_right (min_le_right _ _) (hf _)simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]apply le_of_eq; field_simpend FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213import OAI.Analysis.FourierLLogL.Compress.Select/-! # Thinning to exact row marginals -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A B Ω ι κ : Type} [Fintype A] [Fintype B] [DecidableEq B] [Fintype Ω] {n r : ℕ}abbrev Ticket (r n : ℕ) := Option (Fin r ↪ Fin n)def gain (j : Fin r) (f : Fin n → ℝ) : Ticket r n → ℝ| none => 0| some e => f (e j)private lemma perm_uniform (x : B) :(uniform (Equiv.Perm B)).send (fun e => e x) = letI : Nonempty B := ⟨x⟩; uniform B := byhave : Nonempty B := ⟨x⟩let R := uniform (Equiv.Perm B)let W := R.send (fun e => e x)have he (a b : B) : W a = W b := byclassicallet f := Equiv.swap a bhave hh (e : Equiv.Perm B) : (e x=a) ↔ (f*e) x=b := bychange _ ↔ f (e x) = _rw [← show f a = b from Equiv.swap_apply_left _ _, f.injective.eq_iff]unfold W; rw [send_apply,send_apply,prob_eq,prob_eq]exact Fintype.sum_equiv (Equiv.mulLeft f) _ _ fun i => bychange _ = if (f*i) x=b then _ else _split_ifs <;> simp_all onlyall_goals first | rfl | exact False.elim (by grind)apply Law.extintro ahave hh (w : B) := he w ahave H := W.totalsimp_rw [hh, Finset.sum_const,Finset.card_univ,nsmul_eq_mul] at Hchange W a = _rw [uniform_apply]field_simplinarithprivate lemma count_frac (s : Finset (Fin n)) (hn : 0 < n) :0 ≤ (s.card:ℝ)/n ∧ (s.card:ℝ)/n ≤ 1 := byhave hp : (0:ℝ)< n := by exact_mod_cast hnconstructor· positivity· apply (div_le_one hp).mprexact_mod_cast (by simpa using Finset.card_le_univ s : s.card ≤ n)/-- Sampling rule for the realized set of tagged input blocks. -/lemma choose_tickets (r n : ℕ) (hr : 0 < r) (hn : 0 < n) (s : Finset (Fin n)) :∃ k : Law (Ticket r n), ∀ (j : Fin r) (f : Fin n → ℝ),k.Ex (gain j f) = if r ≤ s.card then (∑ i ∈ s, f i)/n else 0 := byclassicalby_cases hs : r ≤ s.card· have he : r ≤ Fintype.card s := by simpa using hshave : Nonempty s := Fintype.card_pos_iff.mp (lt_of_lt_of_le hr he)let t := (s.card:ℝ)/nlet g : Fin r ↪ s := (Fin.castLEEmb he).trans (Fintype.equivFin _).symm.toEmbeddinglet T (f : Equiv.Perm s) : Ticket r n :=some ((g.trans f.toEmbedding).trans (Embedding.subtype _))refine ⟨mixture ((uniform (Equiv.Perm s)).send T) (point none) t(count_frac _ hn).1 (count_frac _ hn).2,?_⟩intro j frw [ite_eq_left hs, mixture_Ex,Ex_point,Ex_send]dsimp only [gain,T]let F (x : s) := f xchange t*(uniform (Equiv.Perm s)).Ex (fun i => F (i (g j))) + _*0 = _have h : (uniform (Equiv.Perm s)).Ex (fun i => F (i (g j))) = (uniform s).Ex F := byhave H := Ex_send (uniform (Equiv.Perm s)) (fun i => i (g j)) Frw [perm_uniform] at Hexact H.symmrw [h]unfold t Ex Fhave hh : 0 < (s.card:ℝ) := by exact_mod_cast lt_of_lt_of_le hr hssimp only [uniform_apply,← Finset.mul_sum,mul_zero,add_zero, Fintype.card_coe,Finset.univ_eq_attach,Finset.sum_attach]field_simp· refine ⟨point none,fun j f => ?_⟩rw [ite_eq_right hs,Ex_point]; rfl/-- A numerical tag probability. -/private def ratio (a b : ℝ) := min a b/aprivate lemma ratio_bounds (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) :0 ≤ ratio a b ∧ ratio a b ≤ 1 ∧ a * ratio a b = min a b := byunfold ratioobtain hx|hx := eq_or_lt_of_le ha· simp [← hx,hb]exact ⟨div_nonneg (le_min ha hb) ha, (div_le_one hx).mpr (min_le_left _ _), by field_simp⟩def tagChance (p q : Law A) (x : A) : Law Bool :=coinP (ratio (p x) (q x)) (ratio_bounds _ _ (p.nonneg _) (q.nonneg _)).1(ratio_bounds _ _ (p.nonneg _) (q.nonneg _)).2.1lemma tag_test (p q : Law A) (f : A → ℝ) :p.Ex (fun x => (tagChance p q x).Ex (fun b : Bool => if b then f x else 0)) =∑ x, min (p x) (q x) * f x := byunfold tagChancesimp_rw [coinP_Ex]simp only [Bool.false_eq_true, ↓reduceIte,mul_zero,add_zero,Ex,← mul_assoc,(ratio_bounds (p _) (q _) (p.nonneg _) (q.nonneg _)).2.2]/-- Build a channel from the underlying input to the rejection/selected rows. -/lemma thin_sampler (r n : ℕ) (hr : 0 < r) (hn : n=2*r) (P : Law Ω) (q : Law A)(X : Ω → Fin n → A) (ε : ℝ)(hε : ∀ i, ((P.send fun x => X x i).tv q) ≤ ε) :∃ (k : Ω → Law (Ticket r n)),let R := P.withNext kR.prob (fun x => x.2 = none) ≤ 2 * ε ∧(∀ (j : Fin r) (f : A → ℝ) (_h : ∀ x, 0 ≤ f x),R.Ex (fun x => gain j (fun i => f (X x.1 i)) x.2) ≤ q.Ex f) := byclassicalhave hnp : 0 < n := by omegahave hNr : (0:ℝ) < n := by exact_mod_cast hnpchoose c hc using choose_tickets r n hr hnplet p (i : Fin n) := P.send fun x => X x ilet Q (x) := pack (fun i : Fin n => tagChance (p i) q (X x i))let S (x : Fin n → Bool) := Finset.univ.filter (fun i => x i = true)let k (x : Ω) := (Q x).through fun y => c (S y)let R := P.withNext khave hTag (x) (f : Fin n → ℝ) :(Q x).Ex (fun b => ∑ i ∈ S b, f i) =∑ i : Fin n, (tagChance (p i) q (X x i)).Ex (fun b : Bool => if b then f i else 0) := byunfold S Qsimp_rw [Finset.sum_filter,Ex_finset_sum]apply Finset.sum_congr rflintro i _exact Ex_pack_proj _ i (fun b : Bool => if b then f i else 0)have hComp (f : A → ℝ) :P.Ex (fun x => (Q x).Ex fun b => ∑ i ∈ S b, f (X x i)) =∑ i : Fin n, ∑ a, min (p i a) (q a) * f a := byhave HH (x : Ω) := hTag x (fun i => f (X x i))simp_rw [HH,Ex_finset_sum]apply Finset.sum_congr rfl; intro i _rw [← tag_test]exact (Ex_send P (fun x => X x i) (fun y =>(tagChance (p i) q y).Ex (fun b => if b then f y else 0))).symmhave hTick (x) (j : Fin r) (f : Fin n → ℝ) :(k x).Ex (gain j f) =(Q x).Ex (fun b => if r ≤ (S b).card then (∑ i ∈ S b, f i)/n else 0) := byunfold k; rw [Ex_through]; simp_rw [hc]refine ⟨k,?_,?_⟩· let j : Fin r := ⟨0,hr⟩let F := fun (_ : Fin n) => (1:ℝ)have hg : R.prob (fun x => x.2 = none) =1 - P.Ex (fun x => (k x).Ex (gain j F)) := byunfold probrw [← Ex_withNext P k (fun x => gain j F x.2)]calc_ = R.Ex fun x => 1-gain j F x.2 := bycongr 1; funext x; cases x with| mk a b => cases b <;> simp [gain,F]_ = _ := by rw [Ex_sub (f:=fun _ => 1),Ex_const]have h1 (x : Ω) :2/n * (Q x).Ex (fun b => ∑ i ∈ S b, F i)-1 ≤ (k x).Ex (gain j F) := byrw [hTick]have HH (b : Fin n → Bool) :2/(n:ℝ) * (∑ i ∈ S b, F i) - 1 ≤ if r ≤ (S b).card then(∑ i ∈ S b, F i)/n else 0 := byhave ha : (↑n:ℝ) = 2*(r:ℝ) := by exact_mod_cast hnhave hb : ((S b).card:ℝ) ≤ n := by exact_mod_cast(by simpa using Finset.card_le_univ (S b) : (S b).card ≤ n)simp only [F,Finset.sum_const,nsmul_eq_mul,mul_one]split_ifs with H· field_simp; linarith· have : ((S b).card:ℝ) ≤ r := by exact_mod_cast (le_of_not_ge H)field_simp; linarithrefine le_trans (b:=(Q x).Ex (fun b => 2/(n:ℝ)*(∑ i ∈ S b, F i)-1))?_ (Ex_mono _ HH)rw [Ex_sub,Ex_lmul,Ex_const]have HE := hComp (fun _ => 1)have HF : (n:ℝ)*(1-ε) ≤ P.Ex fun x => (Q x).Ex (fun b => ∑ i ∈ S b, F i) := byunfold F; rw [HE]simp_rw [mul_one,tv_common]apply le_trans (b:=∑ i : Fin n,(1-ε)) _ (Finset.sum_le_sum _)· simp; apply le_of_eq; ringintro i _; exact sub_le_sub_left (hε i) _have HL := P.Ex_mono h1rw [Ex_sub,Ex_lmul,Ex_const] at HLchange R.prob _ ≤ _rw [hg]field_simp at HLnlinarith· intro j f hfchange R.Ex _ ≤ _unfold R; rw [Ex_withNext]have h1 (x : Ω) :(k x).Ex (gain j (fun i => f (X x i))) ≤(Q x).Ex (fun b => ∑ i ∈ S b, f (X x i)) * (n:ℝ)⁻¹ := byrw [hTick, ← Ex_mul]apply Ex_monointro bsplit_ifs· simp [div_eq_mul_inv]· exact mul_nonneg (Finset.sum_nonneg (fun i _ => hf _)) (by positivity)refine le_trans (Ex_mono P h1) ?_rw [Ex_mul,hComp]apply le_trans (b := (∑ i : Fin n, q.Ex f) * (n:ℝ)⁻¹)· apply mul_le_mul_of_nonneg_right _ (by positivity)refine Finset.sum_le_sum fun i _ => Finset.sum_le_sum fun a _ =>mul_le_mul_of_nonneg_right (min_le_right _ _) (hf _)simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]apply le_of_eq; field_simpend FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207import OAI.Analysis.FourierLLogL.Compress.ThinChoice/-! # Thinned coupling -/open Function Set Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A G Ω I : Type} [Fintype A] [Fintype G] [Fintype Ω] [Fintype I] [DecidableEq I][AddCommGroup G] [DecidableEq G]set_option linter.unusedSectionVars falsedef sums (I : Type) [Fintype I] [DecidableEq I] (tag : A → G) : Finset G :=Finset.univ.image (tot tag : (I→A) → G)def lnS (I : Type) [Fintype I] [DecidableEq I] (tag : A → G) :=log ((sums I tag).card)lemma lnS_bound (P : Law Ω) (X : Ω → I → A) (tag : A → G) :P.H (fun x => tot tag (X x)) ≤ lnS I tag := byclassicalrefine entropy_le_log_size _ _ fun x hx => ?_obtain ⟨a,rfl,ha⟩ := (send_pos_iff _ _ _).mp hxexact Finset.mem_image_of_mem _ (Finset.mem_univ _)lemma lnS_nonneg (I : Type) [Fintype I] [DecidableEq I] (tag : A → G) :0 ≤ lnS I tag := byunfold lnScases (sums I tag).card with| zero => simp| succ n => exact log_nonneg (by simp)lemma kl_le_by_height (d : ℝ) (hd : 0 < d) (P Q : Law A) (h : ∀ x, d*P x ≤ Q x) :P.kl Q ≤ -log d := byrw [kl_ex,show -log d = P.Ex _ from (Ex_const P (-log d)).symm]refine Ex_mono_mem P ?_intro x hxhave H := Real.log_le_log (mul_pos hd hx) (h x)rw [log_mul hd.ne' hx.ne'] at Hlinarithlemma fill_cost (tag : A → G) (c : G → ℝ) (hc : c 0=0) (q : Law A)(d : ℝ) (hd : 0 < d) (Q : I → Law A) (hq : ∀ i x, d*Q i x ≤ q x) :d * bill tag c q (pack Q) (fun x => x) (fun _ => 0) ≤Fintype.card I + d * lnS I tag := byhave hh (i : I) : (Q i).dominated q :=fun x hx => lt_of_lt_of_le (mul_pos hd hx) (hq i x)have heq : covered (pack Q) (fun x => x) q :=fun x hx i => hh i _ ((pack_pos Q x).mp hx i)rw [bill_with_entropy heq,send_id,pack_kl hh]have Hk : ∑ i, kl (Q i) q ≤ ∑ _i : I, -log d := Finset.sum_le_sum(fun i _ => kl_le_by_height d hd (Q i) q (hq i))have Hs := lnS_bound (pack Q) (fun x => x) tagunfold anssimp only [add_zero]have Hn := Hcond_nonneg (pack Q) (fun _ => (0:G)) (fun x => x)simp_rw [hc,Ex_const]have HC := Real.negMulLog_le_one_sub_self hd.leunfold negMulLog at HChave hsub : d*(-log d) ≤ 1 := by linarithcalc_ ≤ d*((∑ _i : I, -log d)+lnS I tag) := byapply mul_le_mul_of_nonneg_left _ hd.lelinarith_ ≤ _ := byrw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]have H : (0:ℝ)≤ Fintype.card I := by positivitynlinarith [mul_le_mul_of_nonneg_left hsub H]private lemma complete_row (δ : ℝ) (hd : 0 ≤ δ) (P : Law A) (a : A → ℝ)(_h0 : ∀ x, 0 ≤ a x) (hp : ∀ x, a x ≤ P x) (ht : ∑ x, a x = 1-δ) :∃ R : Law A, ∀ x, a x + δ*R x = P x := byhave h : ∑ x, (P x - a x) = δ := by rw [Finset.sum_sub_distrib,P.total,ht]; ringobtain hz|hz := eq_or_lt_of_le hd· refine ⟨P,fun x => ?_⟩have HH := Finset.single_le_sum (s:=Finset.univ) (f:=fun x => P x-a x)(fun x _ => sub_nonneg.mpr (hp x)) (Finset.mem_univ x)rw [← hz,zero_mul]; linarith [hp x]· refine ⟨proportional (fun x => P x-a x) (fun x => sub_nonneg.mpr (hp x)) (by rw [h]; exact hz),fun x => ?_⟩rw [proportional_apply,h]; field_simp; ringtheorem thinned_bill (tag : A → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (hc0 : c 0 = 0)(r n : ℕ) (hr : 0 < r) (hn : n=2*r)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → G) (q : Law A)(hcov : covered P X q) (ε : ℝ) (hε : ∀ i, tv (P.send (fun x => X x i)) q ≤ ε) :∃ Q : Law (WordSample r A G), (∀ i, Q.send (fun a => a.1 i) = q) ∧bill tag c q Q Prod.fst Prod.snd ≤ bill tag c q P X U +log (Fintype.card (Ticket r n)) + (r + 2*ε*lnS (Fin r) tag) := byclassicalobtain ⟨k, hδ, h⟩ := thin_sampler r n hr hn P q X ε hεlet R := P.withNext klet W := Ticket r nlet Z : Ω × W → W := Prod.sndlet D := R.send Prod.sndlet δ := D nonehave hd : 0 ≤ δ := D.nonneg _have hds : δ ≤ 2*ε := le_trans (le_of_eq (send_apply R Prod.snd none)) hδlet X' (p : Ω × W) := X p.1let U' (p : Ω × W) := U p.1let QA (e : Fin r ↪ Fin n) : Law (WordSample r A G) :=(R.after Z (some e)).send (fun x => (keep X' e x,U' x))let m (i : Fin r) (a : A) :=∑ e : Fin r ↪ Fin n, D (some e) * ((QA e).send (fun x => x.1 i)) ahave hmm (i : Fin r) (f : A → ℝ) :∑ e : Fin r ↪ Fin n, D (some e)* (QA e).Ex (fun x => f (x.1 i)) =R.Ex (fun x => gain i (fun j => f (X' x j)) x.2) := bylet V (j : W) (x : Ω × W) := gain i (fun a => f (X' x a)) jhave H : D.Ex (fun w => (R.after Z w).Ex (V w)) = _ :=R.after_Ex_sum Z Vrefine Eq.trans ?_ Hchange _ = ∑ w, D w * (R.after Z w).Ex (V w)rw [Fintype.sum_option]unfold V gainchange _ = D none*((R.after Z none).Ex fun _ => 0)+(∑ e : Fin r ↪ Fin n,D (some e)*((R.after Z (some e)).Ex fun a => f (X' a (e i))))rw [Ex_const,mul_zero,zero_add]refine Finset.sum_congr rfl fun e _ => ?_dsimp only [QA]rw [Ex_send]; rflhave Hm0 (i a) : 0 ≤ m i a := Finset.sum_nonneg fun e _ =>mul_nonneg (D.nonneg _) ((send _ _).nonneg _)have Hmp (i a) : m i a ≤ q a := bylet f (x : A) : ℝ := if x=a then 1 else 0have HH := h i f (by intro x; unfold f; split_ifs <;> norm_num)change R.Ex (fun x => gain i (fun j => f (X' x j)) x.2) ≤ _ at HHrw [← hmm] at HHhave H1 (P : Law A) : P.Ex f = P a := by unfold f Ex; simphave H2 (e : Fin r ↪ Fin n) :(QA e).Ex (fun x => f (x.1 i)) = (QA e).send (fun x => x.1 i) a :=(Ex_send (QA e) (fun x => x.1 i) f).symm.trans (H1 _)simp_rw [H1,H2] at HH; exact HHhave ht (i) : ∑ a, m i a = 1-δ := byunfold mrw [Finset.sum_comm]simp only [← Finset.mul_sum,Law.total,mul_one]have HH := D.totalrw [Fintype.sum_option] at HHunfold δ; linarithchoose R' hR using fun i => complete_row δ hd q (m i) (Hm0 i) (Hmp i) (ht i)let Ξ : Law (WordSample r A G) := (pack R').send (fun x => (x,0))let T (x : Ticket r n) := match x with| none => Ξ| some e => QA erefine ⟨D.through T,fun i => ?_,?_⟩· apply Law.ext; intro alet f (x : WordSample r A G) := x.1 ihave heq : (D.through T).send f = D.through (fun w => (T w).send f) := byapply ext_of_Ex; intro g; rw [Ex_send]simp_rw [Ex_through,Ex_send]change (D.through T).send f a = q arw [heq,through_apply,Ex,Fintype.sum_option]have h1 : (T none).send f a = R' i a := bychange (((pack R').send _).send _) _ = _unfold f; rw [send_send]exact congrArg (fun P : Law A => P a) (marginalPack _ i)rw [h1]exact (add_comm _ _).trans (hR i a)let C (Q : Law (WordSample r A G)) := bill tag c q Q Prod.fst Prod.sndlet V (w) := bill tag c q (R.after Z w) X' U'have HV : D.Ex V ≤ bill tag c q P X U + log (Fintype.card (Ticket r n)) := byhave heq : bill tag c q R X' U' = bill tag c q P X U :=calc_ = bill tag c q (R.send Prod.fst) X U := (bill_send tag c q R X U Prod.fst).symm_ = _ := by rw [show R.send Prod.fst = P from send_fst_withNext P k]refine (bill_condition tag c q R X' U' Z).trans ?_rw [heq]exact add_le_add_right (H_card _ _) _have hr' : covered R X' q := fun x hx i => hcov _ (byhave H := R.send_pos Prod.fst hx; rwa [show R.send Prod.fst=P from send_fst_withNext P k] at H) ihave hb (e : Fin r ↪ Fin n) :D (some e)*C (QA e) ≤ D (some e)*V (some e) := byobtain hh|hh := eq_or_lt_of_le (D.nonneg (some e))· rw [← hh,zero_mul,zero_mul]· apply mul_le_mul_of_nonneg_left _ hh.leunfold C QArw [bill_send]exact bill_subfamily tag c q (R.after Z _) X' U' (covered_after hr' Z _ hh) _ e.injectivehave hxy : δ*C Ξ ≤ r + 2*ε*lnS (Fin r) tag + δ*V none := byobtain he|he := eq_or_lt_of_le hd· rw [← he,zero_mul,zero_mul]have := lnS_nonneg (Fin r) taghave : 0 ≤ ε := by linarithpositivityunfold C Ξrw [bill_send]have hF := fill_cost tag c hc0 q δ he R' (fun i x => by linarith [hR i x,Hm0 i x])rw [Fintype.card_fin] at hFhave hV : 0 ≤ V none := bill_nonneg (covered_after hr' Z _ he) _ _ hc _refine hF.trans ?_nlinarith [lnS_nonneg (Fin r) tag]refine (bill_through_le tag c q D Prod.fst Prod.snd T).trans ?_change D.Ex (fun w => C (T w)) ≤ _ + _calc_ ≤ D.Ex V + (r+2*ε*lnS (Fin r) tag) := byunfold Exrw [Fintype.sum_option,Fintype.sum_option]dsimp only [T]have HH := Finset.sum_le_sum (s:=Finset.univ) (fun e _ => hb e)unfold δ at hxylinarith_ ≤ _ := add_le_add_left HV _end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207import OAI.Analysis.FourierLLogL.Compress.ThinChoice/-! # Thinned coupling -/open Function Set Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {A G Ω I : Type} [Fintype A] [Fintype G] [Fintype Ω] [Fintype I] [DecidableEq I][AddCommGroup G] [DecidableEq G]set_option linter.unusedSectionVars falsedef sums (I : Type) [Fintype I] [DecidableEq I] (tag : A → G) : Finset G :=Finset.univ.image (tot tag : (I→A) → G)def lnS (I : Type) [Fintype I] [DecidableEq I] (tag : A → G) :=log ((sums I tag).card)lemma lnS_bound (P : Law Ω) (X : Ω → I → A) (tag : A → G) :P.H (fun x => tot tag (X x)) ≤ lnS I tag := byclassicalrefine entropy_le_log_size _ _ fun x hx => ?_obtain ⟨a,rfl,ha⟩ := (send_pos_iff _ _ _).mp hxexact Finset.mem_image_of_mem _ (Finset.mem_univ _)lemma lnS_nonneg (I : Type) [Fintype I] [DecidableEq I] (tag : A → G) :0 ≤ lnS I tag := byunfold lnScases (sums I tag).card with| zero => simp| succ n => exact log_nonneg (by simp)lemma kl_le_by_height (d : ℝ) (hd : 0 < d) (P Q : Law A) (h : ∀ x, d*P x ≤ Q x) :P.kl Q ≤ -log d := byrw [kl_ex,show -log d = P.Ex _ from (Ex_const P (-log d)).symm]refine Ex_mono_mem P ?_intro x hxhave H := Real.log_le_log (mul_pos hd hx) (h x)rw [log_mul hd.ne' hx.ne'] at Hlinarithlemma fill_cost (tag : A → G) (c : G → ℝ) (hc : c 0=0) (q : Law A)(d : ℝ) (hd : 0 < d) (Q : I → Law A) (hq : ∀ i x, d*Q i x ≤ q x) :d * bill tag c q (pack Q) (fun x => x) (fun _ => 0) ≤Fintype.card I + d * lnS I tag := byhave hh (i : I) : (Q i).dominated q :=fun x hx => lt_of_lt_of_le (mul_pos hd hx) (hq i x)have heq : covered (pack Q) (fun x => x) q :=fun x hx i => hh i _ ((pack_pos Q x).mp hx i)rw [bill_with_entropy heq,send_id,pack_kl hh]have Hk : ∑ i, kl (Q i) q ≤ ∑ _i : I, -log d := Finset.sum_le_sum(fun i _ => kl_le_by_height d hd (Q i) q (hq i))have Hs := lnS_bound (pack Q) (fun x => x) tagunfold anssimp only [add_zero]have Hn := Hcond_nonneg (pack Q) (fun _ => (0:G)) (fun x => x)simp_rw [hc,Ex_const]have HC := Real.negMulLog_le_one_sub_self hd.leunfold negMulLog at HChave hsub : d*(-log d) ≤ 1 := by linarithcalc_ ≤ d*((∑ _i : I, -log d)+lnS I tag) := byapply mul_le_mul_of_nonneg_left _ hd.lelinarith_ ≤ _ := byrw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]have H : (0:ℝ)≤ Fintype.card I := by positivitynlinarith [mul_le_mul_of_nonneg_left hsub H]private lemma complete_row (δ : ℝ) (hd : 0 ≤ δ) (P : Law A) (a : A → ℝ)(_h0 : ∀ x, 0 ≤ a x) (hp : ∀ x, a x ≤ P x) (ht : ∑ x, a x = 1-δ) :∃ R : Law A, ∀ x, a x + δ*R x = P x := byhave h : ∑ x, (P x - a x) = δ := by rw [Finset.sum_sub_distrib,P.total,ht]; ringobtain hz|hz := eq_or_lt_of_le hd· refine ⟨P,fun x => ?_⟩have HH := Finset.single_le_sum (s:=Finset.univ) (f:=fun x => P x-a x)(fun x _ => sub_nonneg.mpr (hp x)) (Finset.mem_univ x)rw [← hz,zero_mul]; linarith [hp x]· refine ⟨proportional (fun x => P x-a x) (fun x => sub_nonneg.mpr (hp x)) (by rw [h]; exact hz),fun x => ?_⟩rw [proportional_apply,h]; field_simp; ringtheorem thinned_bill (tag : A → G) (c : G → ℝ) (hc : ∀ x, 0 ≤ c x) (hc0 : c 0 = 0)(r n : ℕ) (hr : 0 < r) (hn : n=2*r)(P : Law Ω) (X : Ω → Letters n A) (U : Ω → G) (q : Law A)(hcov : covered P X q) (ε : ℝ) (hε : ∀ i, tv (P.send (fun x => X x i)) q ≤ ε) :∃ Q : Law (WordSample r A G), (∀ i, Q.send (fun a => a.1 i) = q) ∧bill tag c q Q Prod.fst Prod.snd ≤ bill tag c q P X U +log (Fintype.card (Ticket r n)) + (r + 2*ε*lnS (Fin r) tag) := byclassicalobtain ⟨k, hδ, h⟩ := thin_sampler r n hr hn P q X ε hεlet R := P.withNext klet W := Ticket r nlet Z : Ω × W → W := Prod.sndlet D := R.send Prod.sndlet δ := D nonehave hd : 0 ≤ δ := D.nonneg _have hds : δ ≤ 2*ε := le_trans (le_of_eq (send_apply R Prod.snd none)) hδlet X' (p : Ω × W) := X p.1let U' (p : Ω × W) := U p.1let QA (e : Fin r ↪ Fin n) : Law (WordSample r A G) :=(R.after Z (some e)).send (fun x => (keep X' e x,U' x))let m (i : Fin r) (a : A) :=∑ e : Fin r ↪ Fin n, D (some e) * ((QA e).send (fun x => x.1 i)) ahave hmm (i : Fin r) (f : A → ℝ) :∑ e : Fin r ↪ Fin n, D (some e)* (QA e).Ex (fun x => f (x.1 i)) =R.Ex (fun x => gain i (fun j => f (X' x j)) x.2) := bylet V (j : W) (x : Ω × W) := gain i (fun a => f (X' x a)) jhave H : D.Ex (fun w => (R.after Z w).Ex (V w)) = _ :=R.after_Ex_sum Z Vrefine Eq.trans ?_ Hchange _ = ∑ w, D w * (R.after Z w).Ex (V w)rw [Fintype.sum_option]unfold V gainchange _ = D none*((R.after Z none).Ex fun _ => 0)+(∑ e : Fin r ↪ Fin n,D (some e)*((R.after Z (some e)).Ex fun a => f (X' a (e i))))rw [Ex_const,mul_zero,zero_add]refine Finset.sum_congr rfl fun e _ => ?_dsimp only [QA]rw [Ex_send]; rflhave Hm0 (i a) : 0 ≤ m i a := Finset.sum_nonneg fun e _ =>mul_nonneg (D.nonneg _) ((send _ _).nonneg _)have Hmp (i a) : m i a ≤ q a := bylet f (x : A) : ℝ := if x=a then 1 else 0have HH := h i f (by intro x; unfold f; split_ifs <;> norm_num)change R.Ex (fun x => gain i (fun j => f (X' x j)) x.2) ≤ _ at HHrw [← hmm] at HHhave H1 (P : Law A) : P.Ex f = P a := by unfold f Ex; simphave H2 (e : Fin r ↪ Fin n) :(QA e).Ex (fun x => f (x.1 i)) = (QA e).send (fun x => x.1 i) a :=(Ex_send (QA e) (fun x => x.1 i) f).symm.trans (H1 _)simp_rw [H1,H2] at HH; exact HHhave ht (i) : ∑ a, m i a = 1-δ := byunfold mrw [Finset.sum_comm]simp only [← Finset.mul_sum,Law.total,mul_one]have HH := D.totalrw [Fintype.sum_option] at HHunfold δ; linarithchoose R' hR using fun i => complete_row δ hd q (m i) (Hm0 i) (Hmp i) (ht i)let Ξ : Law (WordSample r A G) := (pack R').send (fun x => (x,0))let T (x : Ticket r n) := match x with| none => Ξ| some e => QA erefine ⟨D.through T,fun i => ?_,?_⟩· apply Law.ext; intro alet f (x : WordSample r A G) := x.1 ihave heq : (D.through T).send f = D.through (fun w => (T w).send f) := byapply ext_of_Ex; intro g; rw [Ex_send]simp_rw [Ex_through,Ex_send]change (D.through T).send f a = q arw [heq,through_apply,Ex,Fintype.sum_option]have h1 : (T none).send f a = R' i a := bychange (((pack R').send _).send _) _ = _unfold f; rw [send_send]exact congrArg (fun P : Law A => P a) (marginalPack _ i)rw [h1]exact (add_comm _ _).trans (hR i a)let C (Q : Law (WordSample r A G)) := bill tag c q Q Prod.fst Prod.sndlet V (w) := bill tag c q (R.after Z w) X' U'have HV : D.Ex V ≤ bill tag c q P X U + log (Fintype.card (Ticket r n)) := byhave heq : bill tag c q R X' U' = bill tag c q P X U :=calc_ = bill tag c q (R.send Prod.fst) X U := (bill_send tag c q R X U Prod.fst).symm_ = _ := by rw [show R.send Prod.fst = P from send_fst_withNext P k]refine (bill_condition tag c q R X' U' Z).trans ?_rw [heq]exact add_le_add_right (H_card _ _) _have hr' : covered R X' q := fun x hx i => hcov _ (byhave H := R.send_pos Prod.fst hx; rwa [show R.send Prod.fst=P from send_fst_withNext P k] at H) ihave hb (e : Fin r ↪ Fin n) :D (some e)*C (QA e) ≤ D (some e)*V (some e) := byobtain hh|hh := eq_or_lt_of_le (D.nonneg (some e))· rw [← hh,zero_mul,zero_mul]· apply mul_le_mul_of_nonneg_left _ hh.leunfold C QArw [bill_send]exact bill_subfamily tag c q (R.after Z _) X' U' (covered_after hr' Z _ hh) _ e.injectivehave hxy : δ*C Ξ ≤ r + 2*ε*lnS (Fin r) tag + δ*V none := byobtain he|he := eq_or_lt_of_le hd· rw [← he,zero_mul,zero_mul]have := lnS_nonneg (Fin r) taghave : 0 ≤ ε := by linarithpositivityunfold C Ξrw [bill_send]have hF := fill_cost tag c hc0 q δ he R' (fun i x => by linarith [hR i x,Hm0 i x])rw [Fintype.card_fin] at hFhave hV : 0 ≤ V none := bill_nonneg (covered_after hr' Z _ he) _ _ hc _refine hF.trans ?_nlinarith [lnS_nonneg (Fin r) tag]refine (bill_through_le tag c q D Prod.fst Prod.snd T).trans ?_change D.Ex (fun w => C (T w)) ≤ _ + _calc_ ≤ D.Ex V + (r+2*ε*lnS (Fin r) tag) := byunfold Exrw [Fintype.sum_option,Fintype.sum_option]dsimp only [T]have HH := Finset.sum_le_sum (s:=Finset.univ) (fun e _ => hb e)unfold δ at hxylinarith_ ≤ _ := add_le_add_left HV _end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230import OAI.Analysis.FourierLLogL.Compress.Cost/-! # Noisy variational construction -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {ι α G : Type} [Fintype ι] [DecidableEq ι] [Fintype α] [Fintype G] [AddCommGroup G]abbrev Sample (ι α G : Type) := (ι → α) × Gdef Emp (P : Law (Sample ι α G)) (a : α) : ℝ :=∑ i, P.send (fun x => x.1 i) aomit [AddCommGroup G] inlemma Emp_cont : Continuous (fun P : Law (Sample ι α G) => Emp P) :=continuous_pi fun y => continuous_finsetSum _ fun _ _ => continuous_send_pdf _ yomit [AddCommGroup G] inlemma Emp_mixture (P Q : Law (Sample ι α G)) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :Emp (mixture P Q t h0 h1) = t • Emp P + (1-t) • Emp Q := byclassicalfunext xsimp only [Pi.add_apply, Pi.smul_apply,smul_eq_mul,Emp,send_apply,prob,mixture_Ex,Finset.sum_add_distrib,← Finset.mul_sum]/-- Average of exp(-c) on the sum-difference of 2T independent letters. -/def heatMoment (ι : Type) [Fintype ι] [DecidableEq ι] (p : Law α) (tag : α → G) (c : G → ℝ) : ℝ :=let Q := pack (fun _ : ι => p)Q.Ex fun y => Q.Ex fun x => exp (-c (tot tag y - tot tag x))variable [Nonempty α]lemma trial_bill_uniform (tag : α → G) (c : G → ℝ)(p : Law (ι → α)) (z : G) :bill tag c (uniform α) (p.send (fun x => (x,z-tot tag x))) Prod.fst Prod.snd =Fintype.card ι * log (Fintype.card α) - p.entropy +p.Ex fun x => c (z-tot tag x) := byrw [bill_send]unfold billhave HH : ans tag (fun x : ι → α => x) (fun x => z - tot tag x) =(fun _ => z) := funext (fun x => bychange tot tag x + (z-tot tag x) = zrw [add_comm,sub_add_cancel])change _ - Hcond p (fun x => x) (ans tag (fun x => x) (fun x => z - tot tag x)) + _ = _rw [HH,Hcond_constant,H_self]simp only [uniform_apply, log_inv, neg_neg,Ex_const,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]lemma exp_norm (a : α → ℝ) : 0 < ∑ x, exp (a x) :=Finset.sum_pos (fun _ _ => exp_pos _) Finset.univ_nonempty/-- The scalar potential dual test used below. -/lemma trial_cost_with_potential (tag : α → G) (c : G → ℝ)(E : ℝ) (h : ∀ p : Law α, exp (-E) ≤ heatMoment ι p tag c)(a : α → ℝ) :∃ P : Law (Sample ι α G),bill tag c (uniform α) P Prod.fst Prod.snd +∑ i : ι, (P.Ex (fun x => a (x.1 i))-(uniform α).Ex a) ≤ E := byclassicallet s : ℝ := ∑ x, exp (-a x)have hs : 0 < s := exp_norm _let p : Law α := proportional (fun x => exp (-a x)) (fun _ => exp_nonneg _) hshave hpos (x : α) : 0 < p x := div_pos (exp_pos _) hslet Q := pack fun _ : ι => pobtain ⟨y,_,hy⟩ := Q.exists_Ex_le fun y => Q.Ex fun x => exp (-c (tot tag y - tot tag x))let z := tot tag ylet W (x) := Q x * exp (-c (z - tot tag x))have hpW (x) : 0 < W x := mul_pos ((pack_pos _ _).mpr fun _ => hpos _) (exp_pos _)let D := ∑ x, W xhave hD : exp (-E) ≤ D := le_trans (h p) hyhave hD' : 0 < D := (exp_pos _).trans_le hDlet R := proportional W (fun x => (hpW x).le) hD'let n := (Fintype.card ι : ℝ)have hlogp (x : α) : log (p x) = -a x - log s := bydsimp only [p,s]rw [proportional_apply,log_div (exp_pos _).ne' hs.ne', log_exp]have hlogQ (x) : log (Q x) = ∑ i : ι, (-a (x i) - log s) := bydsimp only [Q]; rw [pack_apply,Real.log_prod (fun j _ => (hpos _).ne')]simp_rw [hlogp]have hlogR (x) :-log (R x) = (∑ i, a (x i)) + n*log s + c (z - tot tag x) + log D := bychange -log (W x/D) = _rw [log_div (hpW x).ne' hD'.ne']unfold W; rw [log_mul ((pack_pos _ _).mpr fun _ => hpos _).ne'(exp_pos _).ne',hlogQ,log_exp, Finset.sum_sub_distrib,Finset.sum_const,Finset.sum_neg_distrib]unfold n; rw [Finset.card_univ,nsmul_eq_mul]; ringhave hR : R.entropy =(∑ i, R.Ex (fun x => a (x i))) + n*log s + R.Ex (fun x => c (z-tot tag x)) + log D := byunfold entropy crossE; simp_rw [hlogR,Ex_add,Ex_finset_sum,Ex_const]refine ⟨R.send (fun x => (x,z-tot tag x)),?_⟩rw [trial_bill_uniform]simp_rw [Ex_send,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]have hce := Law.entropy_le_cross_aux (uniform α) p p.nonneg p.total.le (fun x _ => hpos _)rw [Law.entropy_uniform, crossE] at hcehave Hpl (x : α) : -log (p x) = a x + log s := by rw [hlogp]; ringsimp_rw [Hpl,Ex_add,Ex_const] at hcehave HH : -E ≤ log D := byrw [← Real.exp_le_exp]; simpa only [Real.exp_log hD'] using hDchange n*_ - _ + _ + (_ - n*_) ≤ Erw [hR]have Hn : 0 ≤ n := by dsimp [n]; positivitynlinarithomit [AddCommGroup G] inprivate lemma Emp_linear (P : Law (Sample ι α G))(L : (α → ℝ) →L[ℝ] ℝ) :L (Emp P - fun x => Fintype.card ι * uniform α x) =∑ i : ι, (P.Ex (fun x => L (point (x.1 i) : α → ℝ)) -(uniform α).Ex (fun a => L (point a : α → ℝ))) := byclassicalhave hh (Q : Law α) : L (fun a => Q a) = Q.Ex (fun a => L (point a : α → ℝ)) := byhave hEq : (fun a => Q a) = ∑ i : α, Q i • (fun a => point i a) := byfunext asimp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,point_apply]simpnth_rw 1 [hEq]simp only [map_sum, map_smul, Ex]rflhave he : Emp P = ∑ i : ι, (fun y => P.send (fun x => x.1 i) y) := byfunext; simp only [Finset.sum_apply, Emp]rw [map_sub,he,map_sum,show (fun x => Fintype.card ι * uniform α x) =(Fintype.card ι : ℝ) • (fun x => uniform α x) from rfl,map_smul]rw [hh (uniform α),Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,smul_eq_mul]congr 1apply Finset.sum_congr rflintro i _rw [hh, Ex_send]/-- Version with uniform averaged one-letter marginal. -/theorem noisy_avg (tag : α → G) (c : G → ℝ) (E : ℝ)(h : ∀ p : Law α, exp (-E) ≤ heatMoment ι p tag c) :∃ P : Law (Sample ι α G),bill tag c (uniform α) P Prod.fst Prod.snd ≤ E ∧Emp P = fun x => Fintype.card ι * uniform α x := byclassicallet g (P : Law (Sample ι α G)) := Emp P - fun x => Fintype.card ι * uniform α xhave hh : ∃ P, bill tag c (uniform α) P Prod.fst Prod.snd ≤ E ∧ g P = 0 := byrefine Law.primal_feasible _ (bill_cont _ _ _ _ _) g (Emp_cont.sub continuous_const)(fun _ _ _ _ _ => bill_mixture_le _ _ _ _ _ _ _ _ _ _) ?_ ?_ E ?_· intro P Q t h0 h1unfold g; rw [Emp_mixture]module· let P : Law (ι → α) := pack (fun _ => uniform α)refine ⟨P.send (fun x => (x,(0:G))), ?_⟩unfold grw [sub_eq_zero]ext1 xsimp_rw [Emp,send_send]simp only [P,marginalPack, Finset.sum_const,Finset.card_univ,nsmul_eq_mul]intro Lobtain ⟨P,hP⟩ := trial_cost_with_potential tag c E h(fun x => L (point x : α → ℝ))exact ⟨P,by unfold g; rw [Emp_linear]; exact hP⟩obtain ⟨P,h1,h2⟩ := hhexact ⟨P,h1,sub_eq_zero.mp h2⟩def appPerm (e : Equiv.Perm ι) (x : Sample ι α G) : Sample ι α G :=((fun i => x.1 (e i)), x.2)def exch (P : Law (Sample ι α G)) := ∀ e : Equiv.Perm ι, P.send (appPerm e) = Pomit [AddCommGroup G] [Nonempty α] inlemma same_marginal {P : Law (Sample ι α G)} (hx : exch P) (i j : ι) :P.send (fun a => a.1 i) = P.send (fun a => a.1 j) := bylet e := Equiv.swap i jhave H := congrArg (fun r : Law (Sample ι α G) => send r (fun a => a.1 i)) (hx e)rw [send_send] at Hsimpa [appPerm,e] using H.symmomit [AddCommGroup G] [Nonempty α] inlemma Emp_perm (P : Law (Sample ι α G)) (e : Equiv.Perm ι) :Emp (P.send (appPerm e)) = Emp P := byext xunfold Empsimp_rw [send_send]exact Fintype.sum_equiv e _ (fun i : ι => P.send (fun a => a.1 i) x) (fun i => rfl)/-- Symmetrize to obtain exact prescribed marginal in each coordinate. -/theorem noisy_symm (tag : α → G) (c : G → ℝ) (E : ℝ)(h : ∀ p : Law α, exp (-E) ≤ heatMoment ι p tag c) :∃ P : Law (Sample ι α G),bill tag c (uniform α) P Prod.fst Prod.snd ≤ E ∧ exch P ∧∀ i : ι, P.send (fun x => x.1 i) = uniform α := byclassicalobtain ⟨P,hp,hp'⟩ := noisy_avg tag c E hlet V := uniform (Equiv.Perm ι)let q (e : Equiv.Perm ι) := P.send (appPerm e)let R := V.through qhave hx : exch R := byintro eapply ext_of_Ex; intro frw [Ex_send]dsimp only [R,q]simp_rw [Ex_through,Ex_send]let g (d : Equiv.Perm ι) := P.Ex fun x => f (appPerm d x)change V.Ex (fun d => P.Ex (fun x => f (appPerm e (appPerm d x)))) = V.Ex ghave heq (d : Equiv.Perm ι) : P.Ex (fun x => f (appPerm e (appPerm d x))) = g (d*e) := rflsimp_rw [heq,Ex]exact Fintype.sum_equiv (Equiv.mulRight e) _ _ (fun d => rfl)refine ⟨R,?_ ,hx,?_⟩· have hq (e : Equiv.Perm ι) :bill tag c (uniform α) (q e) Prod.fst Prod.snd ≤ E := bydsimp only [q]rw [bill_send]have HH := bill_subfamily tag c (uniform α) P Prod.fst Prod.snd (fun x _ i => byrw [uniform_apply]; positivity) e e.injectiveexact HH.trans hpexact le_trans (bill_through_le tag c _ _ _ _ _) ((V.Ex_mono hq).trans (V.Ex_const _).le)intro i; have : Nonempty ι := ⟨i⟩apply Law.ext; intro xhave H (e) : Emp (q e) x = Fintype.card ι * (uniform α x) := by dsimp only [q]; rw [Emp_perm, hp']have H2 : Emp R x = V.Ex fun e => Emp (q e) x := byunfold Emp Rsimp_rw [send_apply,prob,Ex_through,Ex_finset_sum]have H3 : Emp R x = (Fintype.card ι : ℝ) * R.send (fun a => a.1 i) x := bycalc_ = ∑ j : ι, R.send (fun a => a.1 i) x :=Finset.sum_congr rfl fun j _ => by rw [same_marginal hx j i]_ = _ := by simpsimp_rw [H, V.Ex_const] at H2exact mul_left_cancel₀ (by positivity : (Fintype.card ι : ℝ) ≠ 0) (H3.symm.trans H2)end FourierLLogL.Compressend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230import OAI.Analysis.FourierLLogL.Compress.Cost/-! # Noisy variational construction -/open Set Function Filteropen scoped BigOperatorsnoncomputable sectionnamespace OAInamespace FourierLLogL.Compressopen Law Realvariable {ι α G : Type} [Fintype ι] [DecidableEq ι] [Fintype α] [Fintype G] [AddCommGroup G]abbrev Sample (ι α G : Type) := (ι → α) × Gdef Emp (P : Law (Sample ι α G)) (a : α) : ℝ :=∑ i, P.send (fun x => x.1 i) aomit [AddCommGroup G] inlemma Emp_cont : Continuous (fun P : Law (Sample ι α G) => Emp P) :=continuous_pi fun y => continuous_finsetSum _ fun _ _ => continuous_send_pdf _ yomit [AddCommGroup G] inlemma Emp_mixture (P Q : Law (Sample ι α G)) (t : ℝ) (h0 : 0 ≤ t) (h1 : t ≤ 1) :Emp (mixture P Q t h0 h1) = t • Emp P + (1-t) • Emp Q := byclassicalfunext xsimp only [Pi.add_apply, Pi.smul_apply,smul_eq_mul,Emp,send_apply,prob,mixture_Ex,Finset.sum_add_distrib,← Finset.mul_sum]/-- Average of exp(-c) on the sum-difference of 2T independent letters. -/def heatMoment (ι : Type) [Fintype ι] [DecidableEq ι] (p : Law α) (tag : α → G) (c : G → ℝ) : ℝ :=let Q := pack (fun _ : ι => p)Q.Ex fun y => Q.Ex fun x => exp (-c (tot tag y - tot tag x))variable [Nonempty α]lemma trial_bill_uniform (tag : α → G) (c : G → ℝ)(p : Law (ι → α)) (z : G) :bill tag c (uniform α) (p.send (fun x => (x,z-tot tag x))) Prod.fst Prod.snd =Fintype.card ι * log (Fintype.card α) - p.entropy +p.Ex fun x => c (z-tot tag x) := byrw [bill_send]unfold billhave HH : ans tag (fun x : ι → α => x) (fun x => z - tot tag x) =(fun _ => z) := funext (fun x => bychange tot tag x + (z-tot tag x) = zrw [add_comm,sub_add_cancel])change _ - Hcond p (fun x => x) (ans tag (fun x => x) (fun x => z - tot tag x)) + _ = _rw [HH,Hcond_constant,H_self]simp only [uniform_apply, log_inv, neg_neg,Ex_const,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]lemma exp_norm (a : α → ℝ) : 0 < ∑ x, exp (a x) :=Finset.sum_pos (fun _ _ => exp_pos _) Finset.univ_nonempty/-- The scalar potential dual test used below. -/lemma trial_cost_with_potential (tag : α → G) (c : G → ℝ)(E : ℝ) (h : ∀ p : Law α, exp (-E) ≤ heatMoment ι p tag c)(a : α → ℝ) :∃ P : Law (Sample ι α G),bill tag c (uniform α) P Prod.fst Prod.snd +∑ i : ι, (P.Ex (fun x => a (x.1 i))-(uniform α).Ex a) ≤ E := byclassicallet s : ℝ := ∑ x, exp (-a x)have hs : 0 < s := exp_norm _let p : Law α := proportional (fun x => exp (-a x)) (fun _ => exp_nonneg _) hshave hpos (x : α) : 0 < p x := div_pos (exp_pos _) hslet Q := pack fun _ : ι => pobtain ⟨y,_,hy⟩ := Q.exists_Ex_le fun y => Q.Ex fun x => exp (-c (tot tag y - tot tag x))let z := tot tag ylet W (x) := Q x * exp (-c (z - tot tag x))have hpW (x) : 0 < W x := mul_pos ((pack_pos _ _).mpr fun _ => hpos _) (exp_pos _)let D := ∑ x, W xhave hD : exp (-E) ≤ D := le_trans (h p) hyhave hD' : 0 < D := (exp_pos _).trans_le hDlet R := proportional W (fun x => (hpW x).le) hD'let n := (Fintype.card ι : ℝ)have hlogp (x : α) : log (p x) = -a x - log s := bydsimp only [p,s]rw [proportional_apply,log_div (exp_pos _).ne' hs.ne', log_exp]have hlogQ (x) : log (Q x) = ∑ i : ι, (-a (x i) - log s) := bydsimp only [Q]; rw [pack_apply,Real.log_prod (fun j _ => (hpos _).ne')]simp_rw [hlogp]have hlogR (x) :-log (R x) = (∑ i, a (x i)) + n*log s + c (z - tot tag x) + log D := bychange -log (W x/D) = _rw [log_div (hpW x).ne' hD'.ne']unfold W; rw [log_mul ((pack_pos _ _).mpr fun _ => hpos _).ne'(exp_pos _).ne',hlogQ,log_exp, Finset.sum_sub_distrib,Finset.sum_const,Finset.sum_neg_distrib]unfold n; rw [Finset.card_univ,nsmul_eq_mul]; ringhave hR : R.entropy =(∑ i, R.Ex (fun x => a (x i))) + n*log s + R.Ex (fun x => c (z-tot tag x)) + log D := byunfold entropy crossE; simp_rw [hlogR,Ex_add,Ex_finset_sum,Ex_const]refine ⟨R.send (fun x => (x,z-tot tag x)),?_⟩rw [trial_bill_uniform]simp_rw [Ex_send,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul]have hce := Law.entropy_le_cross_aux (uniform α) p p.nonneg p.total.le (fun x _ => hpos _)rw [Law.entropy_uniform, crossE] at hcehave Hpl (x : α) : -log (p x) = a x + log s := by rw [hlogp]; ringsimp_rw [Hpl,Ex_add,Ex_const] at hcehave HH : -E ≤ log D := byrw [← Real.exp_le_exp]; simpa only [Real.exp_log hD'] using hDchange n*_ - _ + _ + (_ - n*_) ≤ Erw [hR]have Hn : 0 ≤ n := by dsimp [n]; positivitynlinarithomit [AddCommGroup G] inprivate lemma Emp_linear (P : Law (Sample ι α G))(L : (α → ℝ) →L[ℝ] ℝ) :L (Emp P - fun x => Fintype.card ι * uniform α x) =∑ i : ι, (P.Ex (fun x => L (point (x.1 i) : α → ℝ)) -(uniform α).Ex (fun a => L (point a : α → ℝ))) := byclassicalhave hh (Q : Law α) : L (fun a => Q a) = Q.Ex (fun a => L (point a : α → ℝ)) := byhave hEq : (fun a => Q a) = ∑ i : α, Q i • (fun a => point i a) := byfunext asimp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,point_apply]simpnth_rw 1 [hEq]simp only [map_sum, map_smul, Ex]rflhave he : Emp P = ∑ i : ι, (fun y => P.send (fun x => x.1 i) y) := byfunext; simp only [Finset.sum_apply, Emp]rw [map_sub,he,map_sum,show (fun x => Fintype.card ι * uniform α x) =(Fintype.card ι : ℝ) • (fun x => uniform α x) from rfl,map_smul]rw [hh (uniform α),Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,smul_eq_mul]congr 1apply Finset.sum_congr rflintro i _rw [hh, Ex_send]/-- Version with uniform averaged one-letter marginal. -/theorem noisy_avg (tag : α → G) (c : G → ℝ) (E : ℝ)(h : ∀ p : Law α, exp (-E) ≤ heatMoment ι p tag c) :∃ P : Law (Sample ι α G),bill tag c (uniform α) P Prod.fst Prod.snd ≤ E ∧Emp P = fun x => Fintype.card ι * uniform α x := byclassicallet g (P : Law (Sample ι α G)) := Emp P - fun x => Fintype.card ι * uniform α xhave hh : ∃ P, bill tag c (uniform α) P Prod.fst Prod.snd ≤ E ∧ g P = 0 := byrefine Law.primal_feasible _ (bill_cont _ _ _ _ _) g (Emp_cont.sub continuous_const)(fun _ _ _ _ _ => bill_mixture_le _ _ _ _ _ _ _ _ _ _) ?_ ?_ E ?_· intro P Q t h0 h1unfold g; rw [Emp_mixture]module· let P : Law (ι → α) := pack (fun _ => uniform α)refine ⟨P.send (fun x => (x,(0:G))), ?_⟩unfold grw [sub_eq_zero]ext1 xsimp_rw [Emp,send_send]simp only [P,marginalPack, Finset.sum_const,Finset.card_univ,nsmul_eq_mul]intro Lobtain ⟨P,hP⟩ := trial_cost_with_potential tag c E h(fun x => L (point x : α → ℝ))exact ⟨P,by unfold g; rw [Emp_linear]; exact hP⟩obtain ⟨P,h1,h2⟩ := hhexact ⟨P,h1,sub_eq_zero.mp h2⟩def appPerm (e : Equiv.Perm ι) (x : Sample ι α G) : Sample ι α G :=((fun i => x.1 (e i)), x.2)def exch (P : Law (Sample ι α G)) := ∀ e : Equiv.Perm ι, P.send (appPerm e) = Pomit [AddCommGroup G] [Nonempty α] inlemma same_marginal {P : Law (Sample ι α G)} (hx : exch P) (i j : ι) :P.send (fun a => a.1 i) = P.send (fun a => a.1 j) := bylet e := Equiv.swap i jhave H := congrArg (fun r : Law (Sample ι α G) => send r (fun a => a.1 i)) (hx e)rw [send_send] at Hsimpa [appPerm,e] using H.symmomit [AddCommGroup G] [Nonempty α] inlemma Emp_perm (P : Law (Sample ι α G)) (e : Equiv.Perm ι) :Emp (P.send (appPerm e)) = Emp P := byext xunfold Empsimp_rw [send_send]exact Fintype.sum_equiv e _ (fun i : ι => P.send (fun a => a.1 i) x) (fun i => rfl)/-- Symmetrize to obtain exact prescribed marginal in each coordinate. -/theorem noisy_symm (tag : α → G) (c : G → ℝ) (E : ℝ)(h : ∀ p : Law α, exp (-E) ≤ heatMoment ι p tag c) :∃ P : Law (Sample ι α G),bill tag c (uniform α) P Prod.fst Prod.snd ≤ E ∧ exch P ∧∀ i : ι, P.send (fun x => x.1 i) = uniform α := byclassicalobtain ⟨P,hp,hp'⟩ := noisy_avg tag c E hlet V := uniform (Equiv.Perm ι)let q (e : Equiv.Perm ι) := P.send (appPerm e)let R := V.through qhave hx : exch R := byintro eapply ext_of_Ex; intro frw [Ex_send]dsimp only [R,q]simp_rw [Ex_through,Ex_send]let g (d : Equiv.Perm ι) := P.Ex fun x => f (appPerm d x)change V.Ex (fun d => P.Ex (fun x => f (appPerm e (appPerm d x)))) = V.Ex ghave heq (d : Equiv.Perm ι) : P.Ex (fun x => f (appPerm e (appPerm d x))) = g (d*e) := rflsimp_rw [heq,Ex]exact Fintype.sum_equiv (Equiv.mulRight e) _ _ (fun d => rfl)refine ⟨R,?_ ,hx,?_⟩· have hq (e : Equiv.Perm ι) :bill tag c (uniform α) (q e) Prod.fst Prod.snd ≤ E := bydsimp only [q]rw [bill_send]have HH := bill_subfamily tag c (uniform α) P Prod.fst Prod.snd (fun x _ i => byrw [uniform_apply]; positivity) e e.injectiveexact HH.trans hpexact le_trans (bill_through_le tag c _ _ _ _ _) ((V.Ex_mono hq).trans (V.Ex_const _).le)intro i; have : Nonempty ι := ⟨i⟩apply Law.ext; intro xhave H (e) : Emp (q e) x = Fintype.card ι * (uniform α x) := by dsimp only [q]; rw [Emp_perm, hp']have H2 : Emp R x = V.Ex fun e => Emp (q e) x := byunfold Emp Rsimp_rw [send_apply,prob,Ex_through,Ex_finset_sum]have H3 : Emp R x = (Fintype.card ι : ℝ) * R.send (fun a => a.1 i) x := bycalc_ = ∑ j : ι, R.send (fun a => a.1 i) x :=Finset.sum_congr rfl fun j _ => by rw [same_marginal hx j i]_ = _ := by simpsimp_rw [H, V.Ex_const] at H2exact mul_left_cancel₀ (by positivity : (Fintype.card ι : ℝ) ≠ 0) (H3.symm.trans H2)end FourierLLogL.Compressend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192import OAI.Analysis.FourierLLogL.Dyadic.Discrete/-! # Grid distance and elementary counting -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Period Realvariable {M : ℕ}def rad (x : Grid M) : ℝ := ↑(min x.val (-x).val)def diam (x : Grid M) : ℝ := side M * rad xdef liftInt (x : Grid M) : ℤ := if x.val ≤ (-x).val then x.val else -↑(-x).vallemma rad_abs (x : Grid M) : rad x = |(liftInt x:ℝ)| := byunfold liftInt radsplit_ifs with h· rw [min_eq_left h, Int.cast_natCast,abs_of_nonneg (by positivity)]· rw [min_eq_right (by omega),Int.cast_neg, abs_neg,Int.cast_natCast,abs_of_nonneg (by positivity)]lemma liftInt_cast (x : Grid M) : (liftInt x:Grid M) = x := by unfold liftInt; split_ifs <;> simplemma rad_even (x : Grid M) : rad (-x) = rad x := by simp [rad,min_comm]lemma diam_even (x : Grid M) : diam (-x) = diam x := by rw [diam,diam,rad_even]lemma rad_nonneg (x : Grid M) : 0 ≤ rad x := by rw [rad_abs]; positivitylemma diam_nonneg (x : Grid M) : 0 ≤ diam x := mul_nonneg (side_pos _).le (rad_nonneg _)lemma pos_nonneg (x : Grid M) : 0 ≤ pos x := mul_nonneg (by positivity) (side_pos _).lelemma pos_lt (x : Grid M) : pos x < 1 := (atom_sub x (pos_mem x)).2lemma pos_neg {x : Grid M} (hx : x≠0) : pos (-x) = 1-pos x := byhave : NeZero x := ⟨hx⟩simp_rw [pos, ZMod.val_neg_of_ne_zero, Nat.cast_sub (ZMod.val_lt _).le, sub_mul,side_pow_two]push_castrw [mul_inv_cancel₀ (by positivity)]lemma diam_min (x : Grid M) : diam x = min (pos x) (pos (-x)) := byunfold diam rad posrw [Nat.cast_min, mul_comm, min_mul_of_nonneg _ _ (side_pos _).le]lemma diam_le_half (x : Grid M) : diam x ≤ 1/2 := byrw [diam_min]by_cases hx : x=0· subst x; simp [pos]· rw [pos_neg hx, min_le_iff]by_cases H : pos x ≤ 1/2· exact Or.inl H· exact Or.inr (by linarith)lemma rad_le_val (x : Grid M) : rad x ≤ ↑x.val := by simp [rad]lemma rad_le_nat (k : ℕ) : rad (k:Grid M) ≤ ↑k := byrefine (rad_le_val _).trans ?_rw [ZMod.val_natCast]; exact_mod_cast (Nat.mod_le k (2^M))lemma rad_le_int (k : ℤ) : rad (k:Grid M) ≤ |(k:ℝ)| := bycases k with| ofNat k => simpa using rad_le_nat (M:=M) k| negSucc k =>rw [show ((Int.negSucc k:ℤ):Grid M) = -((k+1:ℕ):Grid M) by simp, rad_even]convert rad_le_nat (M:=M) (k+1) using 1push_castrw [abs_of_nonpos (by have H := Nat.cast_nonneg (α:=ℝ) k; linarith)]; ringlemma rad_add (x y : Grid M) : rad (x+y) ≤ rad x+rad y := byhave H := rad_le_int (M:=M) (liftInt x + liftInt y)rw [Int.cast_add,liftInt_cast,liftInt_cast,Int.cast_add] at Hrw [rad_abs x,rad_abs y]exact H.trans (abs_add_le _ _)lemma diam_add (x y : Grid M) : diam (x+y) ≤ diam x+diam y := bysimp_rw [diam]; rw [← mul_add]exact mul_le_mul_of_nonneg_left (rad_add _ _) (side_pos _).lelemma pos_sub_val {x y : Grid M} (h : y.val ≤ x.val) : pos (x-y) = pos x-pos y := bysimp [pos,ZMod.val_sub h,Nat.cast_sub h,sub_mul]lemma diam_le_diff (x y : Grid M) : diam (x-y) ≤ |pos x-pos y| := byrcases le_total y.val x.val with h|h· exact le_trans (show diam (x-y) ≤ pos (x-y) by rw [diam_min]; exact min_le_left _ _)(by rw [pos_sub_val h]; exact le_abs_self _)rw [diam_min,neg_sub]exact (min_le_right _ _).trans (by rw [pos_sub_val h,abs_sub_comm]; exact le_abs_self _)lemma phase_distance (s x y : Grid M) :‖chi s x-chi s y‖ ≤ rad s * (8 * |pos x-pos y|) := bycalc_ = ‖phase (liftInt s :ℝ) (pos x) - phase (liftInt s:ℝ) (pos y)‖ := byrw [← chi_cast,← chi_cast,liftInt_cast]_ ≤ _ := (norm_phase_sub _ _ _).trans (by rw [rad_abs s]; gcongr; linarith [pi_le_four])def first (M m : ℕ) : Finset (Grid M) :=Finset.univ.filter fun x => x.val < mlemma mem_first (m : ℕ) (x : Grid M) : x ∈ first M m ↔ x.val < m := by simp [first]lemma first_eq_range (m : ℕ) (h : m ≤ 2^M) :first M m = (Finset.range m).image (fun k : ℕ => (k:Grid M)) := byext xrw [mem_first,Finset.mem_image]constructor· intro hi; exact ⟨x.val,Finset.mem_range.mpr hi, ZMod.natCast_zmod_val _⟩· rintro ⟨k,hk,rfl⟩; rw [ZMod.val_natCast_of_lt ((Finset.mem_range.mp hk).trans_le h)]exact Finset.mem_range.mp hklemma range_inj {m : ℕ} (h : m ≤ 2^M) :Set.InjOn (fun k : ℕ => (k:Grid M)) (Finset.range m) := byintro i hi j hj HHhave he := congrArg ZMod.val HHrwa [ZMod.val_natCast_of_lt ((Finset.mem_range.mp hi).trans_le h),ZMod.val_natCast_of_lt ((Finset.mem_range.mp hj).trans_le h)] at helemma first_card (m : ℕ) (h : m ≤ 2^M) : (first M m).card = m := byrw [first_eq_range m h,Finset.card_image_of_injOn (range_inj h), Finset.card_range]lemma first_card_le (m : ��) : (first M m).card ≤ m := byrcases le_total m (2^M) with h | h· exact (first_card _ h).le· refine le_trans (Finset.card_le_univ _) ?_simpa [Grid] using hlemma sum_first {E : Type*} [AddCommMonoid E] (m : ℕ) (h : m ≤ 2^M) (f : ℕ → E) :∑ x ∈ first M m, f x.val = ∑ k ∈ Finset.range m, f k := byrw [first_eq_range _ h, Finset.sum_image]· exact Finset.sum_congr rfl fun i hi => byrw [ZMod.val_natCast_of_lt ((Finset.mem_range.mp hi).trans_le h)]intro i hi j hj h'exact range_inj h hi hj h'lemma first_max : first M (2^M) = Finset.univ := byext x; simp [first,ZMod.val_lt]lemma sum_grid {E : Type*} [AddCommMonoid E] (f : ℕ → E) :∑ x : Grid M, f x.val = ∑ k ∈ Finset.range (2^M), f k := byrw [← sum_first _ le_rfl, first_max]def arc (M : ℕ) (r : ℝ) : Finset (Grid M) := Finset.univ.filter fun x => rad x ≤ rlemma mem_arc (r : ℝ) (x : Grid M) : x ∈ arc M r ↔ rad x ≤ r := by simp [arc]lemma arc_card_hi (M : ℕ) (r : ℝ) (hr : 0 ≤ r) :((arc M r).card :ℝ) ≤ 2*(r+1) := bylet m := Nat.floor r +1have hin :arc M r ⊆ first M m ∪ (first M m).image Neg.neg := byintro x hxrw [mem_arc, rad, Nat.cast_min,min_le_iff] at hxrw [Finset.mem_union,Finset.mem_image,mem_first]rcases hx with H | H· exact Or.inl (Nat.lt_succ_of_le ((Nat.le_floor_iff hr).mpr H))exact Or.inr ⟨-x, (mem_first _ _).mpr (Nat.lt_succ_of_le ((Nat.le_floor_iff hr).mpr H)),neg_neg _⟩have h1 := (Finset.card_le_card hin).trans (Finset.card_union_le _ _)have h2 := Finset.card_image_le (s:=first M m) (f:=Neg.neg)have he : (arc M r).card ≤ 2*m := by have := first_card_le (M:=M) m; omegacalc_ ≤ ((2*m:ℕ):ℝ) := Nat.cast_le.mpr he_ ≤ _ := by unfold m; push_cast; have H := Nat.floor_le hr; linarithlemma arc_card_lo (M : ℕ) (r : ℝ) (_hr : 0 ≤ r) (h : r ≤ 2^M) :r ≤ ((arc M r).card:ℝ) := bylet m := Nat.ceil rhave hm : m ≤ 2^M := Nat.ceil_le.mpr (by exact_mod_cast h)have hh : first M m ⊆ arc M r := byintro x hxrw [mem_first] at hx; rw [mem_arc]exact (rad_le_val x).trans ((Nat.lt_ceil.mp hx).le)calc_ ≤ (m:ℝ) := Nat.le_ceil __ ≤ _ := Nat.cast_le.mpr (by rw [← first_card m hm]; exact Finset.card_le_card hh)lemma side_card (M : ℕ) : side M * (2:ℝ)^M = 1 := by rw [side_pow_two]; field_simplemma arc_length (M : ℕ) (r : ℝ) (hr : 0 ≤ r) :(uniform (Grid M)).prob (fun x => diam x ≤ r) ≤ 2*(r+side M) := byrw [prob_eq]have Heq :(∑ x : Grid M, if diam x ≤ r then uniform (Grid M) x else 0) =(arc M (r / side M)).card* side M := byhave he : arc M (r / side M) = Finset.univ.filter fun x : Grid M => diam x ≤ r := byext xsimp [diam,arc,le_div_iff₀ (side_pos M),mul_comm]rw [← Finset.sum_filter,← he]simp [uniform_side]rw [Heq]calc_ ≤ (2*(r / side M +1))*side M := byapply mul_le_mul_of_nonneg_right (arc_card_hi M _ (div_nonneg hr (side_pos _).le)) (side_pos _).le_ = _ := by field_simp [(side_pos _).ne']end FourierLLogL.Dyadicend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192import OAI.Analysis.FourierLLogL.Dyadic.Discrete/-! # Grid distance and elementary counting -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Period Realvariable {M : ℕ}def rad (x : Grid M) : ℝ := ↑(min x.val (-x).val)def diam (x : Grid M) : ℝ := side M * rad xdef liftInt (x : Grid M) : ℤ := if x.val ≤ (-x).val then x.val else -↑(-x).vallemma rad_abs (x : Grid M) : rad x = |(liftInt x:ℝ)| := byunfold liftInt radsplit_ifs with h· rw [min_eq_left h, Int.cast_natCast,abs_of_nonneg (by positivity)]· rw [min_eq_right (by omega),Int.cast_neg, abs_neg,Int.cast_natCast,abs_of_nonneg (by positivity)]lemma liftInt_cast (x : Grid M) : (liftInt x:Grid M) = x := by unfold liftInt; split_ifs <;> simplemma rad_even (x : Grid M) : rad (-x) = rad x := by simp [rad,min_comm]lemma diam_even (x : Grid M) : diam (-x) = diam x := by rw [diam,diam,rad_even]lemma rad_nonneg (x : Grid M) : 0 ≤ rad x := by rw [rad_abs]; positivitylemma diam_nonneg (x : Grid M) : 0 ≤ diam x := mul_nonneg (side_pos _).le (rad_nonneg _)lemma pos_nonneg (x : Grid M) : 0 ≤ pos x := mul_nonneg (by positivity) (side_pos _).lelemma pos_lt (x : Grid M) : pos x < 1 := (atom_sub x (pos_mem x)).2lemma pos_neg {x : Grid M} (hx : x≠0) : pos (-x) = 1-pos x := byhave : NeZero x := ⟨hx⟩simp_rw [pos, ZMod.val_neg_of_ne_zero, Nat.cast_sub (ZMod.val_lt _).le, sub_mul,side_pow_two]push_castrw [mul_inv_cancel₀ (by positivity)]lemma diam_min (x : Grid M) : diam x = min (pos x) (pos (-x)) := byunfold diam rad posrw [Nat.cast_min, mul_comm, min_mul_of_nonneg _ _ (side_pos _).le]lemma diam_le_half (x : Grid M) : diam x ≤ 1/2 := byrw [diam_min]by_cases hx : x=0· subst x; simp [pos]· rw [pos_neg hx, min_le_iff]by_cases H : pos x ≤ 1/2· exact Or.inl H· exact Or.inr (by linarith)lemma rad_le_val (x : Grid M) : rad x ≤ ↑x.val := by simp [rad]lemma rad_le_nat (k : ℕ) : rad (k:Grid M) ≤ ↑k := byrefine (rad_le_val _).trans ?_rw [ZMod.val_natCast]; exact_mod_cast (Nat.mod_le k (2^M))lemma rad_le_int (k : ℤ) : rad (k:Grid M) ≤ |(k:ℝ)| := bycases k with| ofNat k => simpa using rad_le_nat (M:=M) k| negSucc k =>rw [show ((Int.negSucc k:ℤ):Grid M) = -((k+1:ℕ):Grid M) by simp, rad_even]convert rad_le_nat (M:=M) (k+1) using 1push_castrw [abs_of_nonpos (by have H := Nat.cast_nonneg (α:=ℝ) k; linarith)]; ringlemma rad_add (x y : Grid M) : rad (x+y) ≤ rad x+rad y := byhave H := rad_le_int (M:=M) (liftInt x + liftInt y)rw [Int.cast_add,liftInt_cast,liftInt_cast,Int.cast_add] at Hrw [rad_abs x,rad_abs y]exact H.trans (abs_add_le _ _)lemma diam_add (x y : Grid M) : diam (x+y) ≤ diam x+diam y := bysimp_rw [diam]; rw [← mul_add]exact mul_le_mul_of_nonneg_left (rad_add _ _) (side_pos _).lelemma pos_sub_val {x y : Grid M} (h : y.val ≤ x.val) : pos (x-y) = pos x-pos y := bysimp [pos,ZMod.val_sub h,Nat.cast_sub h,sub_mul]lemma diam_le_diff (x y : Grid M) : diam (x-y) ≤ |pos x-pos y| := byrcases le_total y.val x.val with h|h· exact le_trans (show diam (x-y) ≤ pos (x-y) by rw [diam_min]; exact min_le_left _ _)(by rw [pos_sub_val h]; exact le_abs_self _)rw [diam_min,neg_sub]exact (min_le_right _ _).trans (by rw [pos_sub_val h,abs_sub_comm]; exact le_abs_self _)lemma phase_distance (s x y : Grid M) :‖chi s x-chi s y‖ ≤ rad s * (8 * |pos x-pos y|) := bycalc_ = ‖phase (liftInt s :ℝ) (pos x) - phase (liftInt s:ℝ) (pos y)‖ := byrw [← chi_cast,← chi_cast,liftInt_cast]_ ≤ _ := (norm_phase_sub _ _ _).trans (by rw [rad_abs s]; gcongr; linarith [pi_le_four])def first (M m : ℕ) : Finset (Grid M) :=Finset.univ.filter fun x => x.val < mlemma mem_first (m : ℕ) (x : Grid M) : x ∈ first M m ↔ x.val < m := by simp [first]lemma first_eq_range (m : ℕ) (h : m ≤ 2^M) :first M m = (Finset.range m).image (fun k : ℕ => (k:Grid M)) := byext xrw [mem_first,Finset.mem_image]constructor· intro hi; exact ⟨x.val,Finset.mem_range.mpr hi, ZMod.natCast_zmod_val _⟩· rintro ⟨k,hk,rfl⟩; rw [ZMod.val_natCast_of_lt ((Finset.mem_range.mp hk).trans_le h)]exact Finset.mem_range.mp hklemma range_inj {m : ℕ} (h : m ≤ 2^M) :Set.InjOn (fun k : ℕ => (k:Grid M)) (Finset.range m) := byintro i hi j hj HHhave he := congrArg ZMod.val HHrwa [ZMod.val_natCast_of_lt ((Finset.mem_range.mp hi).trans_le h),ZMod.val_natCast_of_lt ((Finset.mem_range.mp hj).trans_le h)] at helemma first_card (m : ℕ) (h : m ≤ 2^M) : (first M m).card = m := byrw [first_eq_range m h,Finset.card_image_of_injOn (range_inj h), Finset.card_range]lemma first_card_le (m : ℕ) : (first M m).card ≤ m := byrcases le_total m (2^M) with h | h· exact (first_card _ h).le· refine le_trans (Finset.card_le_univ _) ?_simpa [Grid] using hlemma sum_first {E : Type*} [AddCommMonoid E] (m : ℕ) (h : m ≤ 2^M) (f : ℕ → E) :∑ x ∈ first M m, f x.val = ∑ k ∈ Finset.range m, f k := byrw [first_eq_range _ h, Finset.sum_image]· exact Finset.sum_congr rfl fun i hi => byrw [ZMod.val_natCast_of_lt ((Finset.mem_range.mp hi).trans_le h)]intro i hi j hj h'exact range_inj h hi hj h'lemma first_max : first M (2^M) = Finset.univ := byext x; simp [first,ZMod.val_lt]lemma sum_grid {E : Type*} [AddCommMonoid E] (f : ℕ → E) :∑ x : Grid M, f x.val = ∑ k ∈ Finset.range (2^M), f k := byrw [← sum_first _ le_rfl, first_max]def arc (M : ℕ) (r : ℝ) : Finset (Grid M) := Finset.univ.filter fun x => rad x ≤ rlemma mem_arc (r : ℝ) (x : Grid M) : x ∈ arc M r ↔ rad x ≤ r := by simp [arc]lemma arc_card_hi (M : ℕ) (r : ℝ) (hr : 0 ≤ r) :((arc M r).card :ℝ) ≤ 2*(r+1) := bylet m := Nat.floor r +1have hin :arc M r ⊆ first M m ∪ (first M m).image Neg.neg := byintro x hxrw [mem_arc, rad, Nat.cast_min,min_le_iff] at hxrw [Finset.mem_union,Finset.mem_image,mem_first]rcases hx with H | H· exact Or.inl (Nat.lt_succ_of_le ((Nat.le_floor_iff hr).mpr H))exact Or.inr ⟨-x, (mem_first _ _).mpr (Nat.lt_succ_of_le ((Nat.le_floor_iff hr).mpr H)),neg_neg _⟩have h1 := (Finset.card_le_card hin).trans (Finset.card_union_le _ _)have h2 := Finset.card_image_le (s:=first M m) (f:=Neg.neg)have he : (arc M r).card ≤ 2*m := by have := first_card_le (M:=M) m; omegacalc_ ≤ ((2*m:ℕ):ℝ) := Nat.cast_le.mpr he_ ≤ _ := by unfold m; push_cast; have H := Nat.floor_le hr; linarithlemma arc_card_lo (M : ℕ) (r : ���) (_hr : 0 ≤ r) (h : r ≤ 2^M) :r ≤ ((arc M r).card:ℝ) := bylet m := Nat.ceil rhave hm : m ≤ 2^M := Nat.ceil_le.mpr (by exact_mod_cast h)have hh : first M m ⊆ arc M r := byintro x hxrw [mem_first] at hx; rw [mem_arc]exact (rad_le_val x).trans ((Nat.lt_ceil.mp hx).le)calc_ ≤ (m:ℝ) := Nat.le_ceil __ ≤ _ := Nat.cast_le.mpr (by rw [← first_card m hm]; exact Finset.card_le_card hh)lemma side_card (M : ℕ) : side M * (2:ℝ)^M = 1 := by rw [side_pow_two]; field_simplemma arc_length (M : ℕ) (r : ℝ) (hr : 0 ≤ r) :(uniform (Grid M)).prob (fun x => diam x ≤ r) ≤ 2*(r+side M) := byrw [prob_eq]have Heq :(∑ x : Grid M, if diam x ≤ r then uniform (Grid M) x else 0) =(arc M (r / side M)).card* side M := byhave he : arc M (r / side M) = Finset.univ.filter fun x : Grid M => diam x ≤ r := byext xsimp [diam,arc,le_div_iff₀ (side_pos M),mul_comm]rw [← Finset.sum_filter,← he]simp [uniform_side]rw [Heq]calc_ ≤ (2*(r / side M +1))*side M := byapply mul_le_mul_of_nonneg_right (arc_card_hi M _ (div_nonneg hr (side_pos _).le)) (side_pos _).le_ = _ := by field_simp [(side_pos _).ne']end FourierLLogL.Dyadicend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214import OAI.Analysis.FourierLLogL.Dyadic.Gridimport OAI.Analysis.FourierLLogL.Finite.Complex/-! # Cyclic grid, characters and averaged Fourier coefficients -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Period Lawvariable {M : ℕ}lemma card_side (M : ℕ) : side M = (Fintype.card (Grid M):ℝ)⁻¹ := byunfold Gridrw [ZMod.card]simp [side]lemma uniform_side (x : Grid M) : uniform (Grid M) x = side M :=(uniform_apply x).trans (card_side M).symmlemma side_pow_two (M : ℕ) : side M = ((2:ℝ)^M)⁻¹ := by simp [side]lemma expU_ex (f : Grid M → ℝ) : expU f = (uniform _).Ex f := byunfold expU Exsimp_rw [uniform_side,← Finset.mul_sum]; rfllemma expU_cx (f : Grid M → ℂ) : expU f = (uniform _).Cx f := byunfold expU Cxsimp_rw [uniform_side,← Finset.mul_sum]rw [Complex.real_smul]lemma expU_prod {E : Type*} [AddCommMonoid E] [DistribMulAction ℝ E](f : Grid M → Grid M → E) :expU (fun y => expU (f y)) = expU fun x => expU fun y => f y x := byunfold expUsimp_rw [← Finset.smul_sum]rw [Finset.sum_comm]lemma expU_sum {E : Type*} [AddCommMonoid E] [DistribMulAction ℝ E]{ι : Type*} (s : Finset ι) (f : ι → Grid M → E) :expU (fun y => ∑ i ∈ s, f i y) = ∑ i ∈ s, expU (f i) := byunfold expU; rw [Finset.sum_comm, Finset.smul_sum]lemma expU_add {E : Type*} [AddCommMonoid E] [DistribMulAction ℝ E](f g : Grid M → E) :expU (fun x => f x+g x) = expU f+expU g := byunfold expU; rw [Finset.sum_add_distrib, smul_add]lemma expU_translate {E : Type*} [AddCommMonoid E] [SMul ℝ E](f : Grid M → E) (a : Grid M) :expU (fun x => f (a+x)) = expU f := byunfold expUcongr 1exact Fintype.sum_equiv (Equiv.addLeft a) _ _ (fun _ => rfl)lemma expU_reflect {E : Type*} [AddCommMonoid E] [SMul ℝ E](f : Grid M → E) :expU (fun x => f (-x)) = expU f := byunfold expU; congr 1exact Fintype.sum_equiv (Equiv.neg _) _ _ (fun _ => rfl)lemma expU_lmul (a : ℂ) (f : Grid M → ℂ) :expU (fun x => a*f x) = a*expU f := by rw [expU_cx, expU_cx, Cx_lmul]lemma expU_real (f : Grid M → ℝ) :expU (fun x => (f x:ℂ)) = (expU f:ℝ) := by rw [expU_cx, expU_ex, Cx_ofReal]/-- Wrap grid characters as an AddChar. -/def phaseChar (u : Grid M) : AddChar (Grid M) ℂ := ZMod.stdAddChar.mulShift u@[simp] lemma phaseChar_apply (u x : Grid M) : phaseChar u x = chi u x := rfllemma chi_comm (x y : Grid M) : chi x y = chi y x := byunfold chi; rw [mul_comm]lemma chi_zero_right (u : Grid M) : chi u 0 = 1 := (phaseChar u).map_zero_eq_onelemma chi_zero_left (u : Grid M) : chi 0 u = 1 := by rw [chi_comm,chi_zero_right]lemma chi_add (u x y : Grid M) : chi u (x+y) = chi u x * chi u y :=(phaseChar u).map_add_eq_mul _ _lemma chi_add' (x y u : Grid M) : chi (x+y) u = chi x u * chi y u := byrw [chi_comm _ u,chi_add,chi_comm u x,chi_comm u y]lemma chi_neg (u x : Grid M) : chi u (-x) = conj (chi u x) := byhave H1 : chi u x * chi u (-x) = 1 := by rw [← chi_add, add_neg_cancel, chi_zero_right]have H2 := Complex.mul_conj (chi u x)rw [← Complex.sq_norm,norm_chi] at H2simp only [one_pow,Complex.ofReal_one] at H2exact mul_left_cancel₀ (by rintro H; rw [H] at H1; simp at H1) (H1.trans H2.symm)lemma chi_neg' (x u : Grid M) : chi (-x) u = conj (chi x u) := by rw [chi_comm,chi_neg,chi_comm u x]lemma chi_sub (u x y : Grid M) : chi u (x-y) = chi u x * conj (chi u y) := byrw [sub_eq_add_neg,chi_add,chi_neg]lemma chi_nsmul (u x : Grid M) (n : ℕ) : chi (n • u) x = (chi u x)^n := byinduction n with| zero => simp [chi_zero_left]| succ n ih =>rw [add_smul,one_smul,chi_add',ih,pow_succ]lemma expU_chi (u : Grid M) :expU (chi u) = if u=0 then 1 else 0 := byby_cases H : u=0· subst urw [expU_cx, funext chi_zero_left]norm_num [Cx,← Complex.ofReal_sum, uniform_apply, ZMod.card,Grid]· rw [ite_eq_right H]unfold expU chirw [show ∑ x : Grid M, ZMod.stdAddChar (u*x) = 0 fromAddChar.sum_eq_zero_of_ne_one (ZMod.isPrimitive_stdAddChar _ H), smul_zero]/-- Averages against conj character. Evaluation form instead of linear notation. -/def fc (f : Grid M → ℂ) (u : Grid M) : ℂ := expU fun x => f x * chi (-u) xlemma fc_lmul (f : Grid M → ℂ) (a : ℂ) (u : Grid M) :fc (fun x => a*f x) u = a*fc f u := bysimp_rw [fc,mul_assoc]exact expU_lmul _ _lemma fc_add (f g : Grid M → ℂ) (u : Grid M) :fc (fun x => f x+g x) u = fc f u+fc g u := bysimp_rw [fc,add_mul]exact expU_add _ _lemma fc_sum {ι : Type*} (s : Finset ι) (f : ι → Grid M → ℂ) (u : Grid M) :fc (fun x => ∑ i ∈ s, f i x) u = ∑ i ∈ s, fc (f i) u := bysimp_rw [fc,Finset.sum_mul]exact expU_sum _ _lemma fc_chi (u v : Grid M) : fc (chi v) u = if v=u then 1 else 0 := bysimp_rw [fc,← chi_add', ← sub_eq_add_neg, expU_chi, sub_eq_zero]lemma expU_coeff (f : Grid M → ℂ) (u : Grid M) :expU (fun x => f x*chi u x) = fc f (-u) := by rw [fc]; simplemma fc_neg_even (f : Grid M → ℂ) (h : f.Even) (u : Grid M) :fc f (-u) = fc f u := byunfold fcrw [← expU_reflect (fun x => f x*chi (-u) x)]simp_rw [neg_neg, h _, chi_neg',chi_neg, RingHomCompTriple.comp_apply]rfllemma fc_neg_real (f : Grid M → ℝ) (u : Grid M) :fc (fun x => (f x:ℂ)) (-u) = conj (fc (fun x => (f x:ℂ)) u) := byunfold fcsimp_rw [expU_cx, ← Cx_conj, map_mul, chi_neg', Complex.conj_ofReal]lemma real_fc_even (f : Grid M → ℝ) (h : f.Even) (u : Grid M) :(↑(fc (fun x => (f x:ℂ)) u).re:ℂ) = fc (fun x => (f x:ℂ)) u := byrw [← fc_neg_even (fun x => (f x:ℂ)) (fun x => by simp [h x]) u]have H := fc_neg_even (fun x => (f x:ℂ)) (fun x => by simp [h x]) uhave he := fc_neg_real f urw [H]have hi := congrArg Complex.im (H.symm.trans he)simp only [Complex.conj_im] at hiapply Complex.ext· simp· simp; linarithlemma invert_fc (f : Grid M → ℂ) (x : Grid M) :∑ u : Grid M, fc f u * chi u x = f x := byunfold fc expUsimp only [Complex.real_smul, Finset.mul_sum,Finset.sum_mul]rw [Finset.sum_comm]have heq (y : Grid M) :∑ u : Grid M, ↑(side M)*(f y*chi (-u) y)*chi u x =f y * expU fun u : Grid M => chi (x-y) u := byunfold expU; simp only [Complex.real_smul, Finset.mul_sum]apply Finset.sum_congr rfl; intro u hurw [chi_comm (x-y) u,chi_sub,chi_neg']ringsimp_rw [heq,expU_chi,sub_eq_zero,mul_ite,mul_one,mul_zero]simplemma fc_mul_chi (f : Grid M → ℂ) (u v : Grid M) :fc (fun y => f y * chi v y) u = fc f (u-v) := bysimp_rw [fc, mul_assoc, ← chi_add', neg_sub, ← sub_eq_add_neg]lemma fc_prod (f g : Grid M → ℂ) (u : Grid M) :fc (fun y => f y * g y) u = ∑ v : Grid M, fc f v * fc g (u-v) := bycalc_ = fc (fun y => ∑ v : Grid M, fc f v * (g y*chi v y)) u := bycongr 1; funext y; rw [← invert_fc f y,Finset.sum_mul]exact Finset.sum_congr rfl fun _ _ => by ring_ = _ := by simp_rw [fc_sum,fc_lmul,fc_mul_chi]lemma fc_right_translate (f : Grid M → ℂ) (a u : Grid M) :fc (fun y => f (y-a)) u = chi (-u) a * fc f u := byunfold fc; rw [← expU_translate (fun y => f (y-a)*chi (-u) y) a]simp_rw [add_sub_cancel_left,chi_add]rw [← expU_lmul]congr 1; funext y; ringlemma fc_parseval (f : Grid M → ℂ) :∑ u, ‖fc f u‖^2 = expU fun y => ‖f y‖^2 := byhave hc (u : Grid M) :fc (fun y => conj (f y)) (-u) = conj (fc f u) := byunfold fcsimp_rw [expU_cx,← Cx_conj,map_mul, chi_neg']have H := fc_prod f (fun y => conj (f y)) 0simp_rw [zero_sub,hc,Complex.mul_conj,← Complex.sq_norm] at Hunfold fc at Hrw [neg_zero] at Hsimp_rw [chi_zero_left,mul_one,expU_real,← Complex.ofReal_sum] at Hexact Complex.ofReal_inj.mp H.symmend FourierLLogL.Dyadicend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214import OAI.Analysis.FourierLLogL.Dyadic.Gridimport OAI.Analysis.FourierLLogL.Finite.Complex/-! # Cyclic grid, characters and averaged Fourier coefficients -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Period Lawvariable {M : ℕ}lemma card_side (M : ℕ) : side M = (Fintype.card (Grid M):ℝ)⁻¹ := byunfold Gridrw [ZMod.card]simp [side]lemma uniform_side (x : Grid M) : uniform (Grid M) x = side M :=(uniform_apply x).trans (card_side M).symmlemma side_pow_two (M : ℕ) : side M = ((2:ℝ)^M)⁻¹ := by simp [side]lemma expU_ex (f : Grid M → ℝ) : expU f = (uniform _).Ex f := byunfold expU Exsimp_rw [uniform_side,← Finset.mul_sum]; rfllemma expU_cx (f : Grid M → ℂ) : expU f = (uniform _).Cx f := byunfold expU Cxsimp_rw [uniform_side,← Finset.mul_sum]rw [Complex.real_smul]lemma expU_prod {E : Type*} [AddCommMonoid E] [DistribMulAction ℝ E](f : Grid M → Grid M → E) :expU (fun y => expU (f y)) = expU fun x => expU fun y => f y x := byunfold expUsimp_rw [← Finset.smul_sum]rw [Finset.sum_comm]lemma expU_sum {E : Type*} [AddCommMonoid E] [DistribMulAction ℝ E]{ι : Type*} (s : Finset ι) (f : ι → Grid M → E) :expU (fun y => ∑ i ∈ s, f i y) = ∑ i ∈ s, expU (f i) := byunfold expU; rw [Finset.sum_comm, Finset.smul_sum]lemma expU_add {E : Type*} [AddCommMonoid E] [DistribMulAction ℝ E](f g : Grid M → E) :expU (fun x => f x+g x) = expU f+expU g := byunfold expU; rw [Finset.sum_add_distrib, smul_add]lemma expU_translate {E : Type*} [AddCommMonoid E] [SMul ℝ E](f : Grid M → E) (a : Grid M) :expU (fun x => f (a+x)) = expU f := byunfold expUcongr 1exact Fintype.sum_equiv (Equiv.addLeft a) _ _ (fun _ => rfl)lemma expU_reflect {E : Type*} [AddCommMonoid E] [SMul ℝ E](f : Grid M → E) :expU (fun x => f (-x)) = expU f := byunfold expU; congr 1exact Fintype.sum_equiv (Equiv.neg _) _ _ (fun _ => rfl)lemma expU_lmul (a : ℂ) (f : Grid M → ℂ) :expU (fun x => a*f x) = a*expU f := by rw [expU_cx, expU_cx, Cx_lmul]lemma expU_real (f : Grid M → ℝ) :expU (fun x => (f x:ℂ)) = (expU f:ℝ) := by rw [expU_cx, expU_ex, Cx_ofReal]/-- Wrap grid characters as an AddChar. -/def phaseChar (u : Grid M) : AddChar (Grid M) ℂ := ZMod.stdAddChar.mulShift u@[simp] lemma phaseChar_apply (u x : Grid M) : phaseChar u x = chi u x := rfllemma chi_comm (x y : Grid M) : chi x y = chi y x := byunfold chi; rw [mul_comm]lemma chi_zero_right (u : Grid M) : chi u 0 = 1 := (phaseChar u).map_zero_eq_onelemma chi_zero_left (u : Grid M) : chi 0 u = 1 := by rw [chi_comm,chi_zero_right]lemma chi_add (u x y : Grid M) : chi u (x+y) = chi u x * chi u y :=(phaseChar u).map_add_eq_mul _ _lemma chi_add' (x y u : Grid M) : chi (x+y) u = chi x u * chi y u := byrw [chi_comm _ u,chi_add,chi_comm u x,chi_comm u y]lemma chi_neg (u x : Grid M) : chi u (-x) = conj (chi u x) := byhave H1 : chi u x * chi u (-x) = 1 := by rw [← chi_add, add_neg_cancel, chi_zero_right]have H2 := Complex.mul_conj (chi u x)rw [← Complex.sq_norm,norm_chi] at H2simp only [one_pow,Complex.ofReal_one] at H2exact mul_left_cancel₀ (by rintro H; rw [H] at H1; simp at H1) (H1.trans H2.symm)lemma chi_neg' (x u : Grid M) : chi (-x) u = conj (chi x u) := by rw [chi_comm,chi_neg,chi_comm u x]lemma chi_sub (u x y : Grid M) : chi u (x-y) = chi u x * conj (chi u y) := byrw [sub_eq_add_neg,chi_add,chi_neg]lemma chi_nsmul (u x : Grid M) (n : ℕ) : chi (n • u) x = (chi u x)^n := byinduction n with| zero => simp [chi_zero_left]| succ n ih =>rw [add_smul,one_smul,chi_add',ih,pow_succ]lemma expU_chi (u : Grid M) :expU (chi u) = if u=0 then 1 else 0 := byby_cases H : u=0· subst urw [expU_cx, funext chi_zero_left]norm_num [Cx,← Complex.ofReal_sum, uniform_apply, ZMod.card,Grid]· rw [ite_eq_right H]unfold expU chirw [show ∑ x : Grid M, ZMod.stdAddChar (u*x) = 0 fromAddChar.sum_eq_zero_of_ne_one (ZMod.isPrimitive_stdAddChar _ H), smul_zero]/-- Averages against conj character. Evaluation form instead of linear notation. -/def fc (f : Grid M → ℂ) (u : Grid M) : ℂ := expU fun x => f x * chi (-u) xlemma fc_lmul (f : Grid M → ℂ) (a : ℂ) (u : Grid M) :fc (fun x => a*f x) u = a*fc f u := bysimp_rw [fc,mul_assoc]exact expU_lmul _ _lemma fc_add (f g : Grid M → ℂ) (u : Grid M) :fc (fun x => f x+g x) u = fc f u+fc g u := bysimp_rw [fc,add_mul]exact expU_add _ _lemma fc_sum {ι : Type*} (s : Finset ι) (f : ι → Grid M → ℂ) (u : Grid M) :fc (fun x => ∑ i ∈ s, f i x) u = ∑ i ∈ s, fc (f i) u := bysimp_rw [fc,Finset.sum_mul]exact expU_sum _ _lemma fc_chi (u v : Grid M) : fc (chi v) u = if v=u then 1 else 0 := bysimp_rw [fc,← chi_add', ← sub_eq_add_neg, expU_chi, sub_eq_zero]lemma expU_coeff (f : Grid M → ℂ) (u : Grid M) :expU (fun x => f x*chi u x) = fc f (-u) := by rw [fc]; simplemma fc_neg_even (f : Grid M → ℂ) (h : f.Even) (u : Grid M) :fc f (-u) = fc f u := byunfold fcrw [← expU_reflect (fun x => f x*chi (-u) x)]simp_rw [neg_neg, h _, chi_neg',chi_neg, RingHomCompTriple.comp_apply]rfllemma fc_neg_real (f : Grid M → ℝ) (u : Grid M) :fc (fun x => (f x:ℂ)) (-u) = conj (fc (fun x => (f x:ℂ)) u) := byunfold fcsimp_rw [expU_cx, ← Cx_conj, map_mul, chi_neg', Complex.conj_ofReal]lemma real_fc_even (f : Grid M → ℝ) (h : f.Even) (u : Grid M) :(↑(fc (fun x => (f x:ℂ)) u).re:ℂ) = fc (fun x => (f x:ℂ)) u := byrw [← fc_neg_even (fun x => (f x:ℂ)) (fun x => by simp [h x]) u]have H := fc_neg_even (fun x => (f x:ℂ)) (fun x => by simp [h x]) uhave he := fc_neg_real f urw [H]have hi := congrArg Complex.im (H.symm.trans he)simp only [Complex.conj_im] at hiapply Complex.ext· simp· simp; linarithlemma invert_fc (f : Grid M → ℂ) (x : Grid M) :∑ u : Grid M, fc f u * chi u x = f x := byunfold fc expUsimp only [Complex.real_smul, Finset.mul_sum,Finset.sum_mul]rw [Finset.sum_comm]have heq (y : Grid M) :∑ u : Grid M, ↑(side M)*(f y*chi (-u) y)*chi u x =f y * expU fun u : Grid M => chi (x-y) u := byunfold expU; simp only [Complex.real_smul, Finset.mul_sum]apply Finset.sum_congr rfl; intro u hurw [chi_comm (x-y) u,chi_sub,chi_neg']ringsimp_rw [heq,expU_chi,sub_eq_zero,mul_ite,mul_one,mul_zero]simplemma fc_mul_chi (f : Grid M → ℂ) (u v : Grid M) :fc (fun y => f y * chi v y) u = fc f (u-v) := bysimp_rw [fc, mul_assoc, ← chi_add', neg_sub, ← sub_eq_add_neg]lemma fc_prod (f g : Grid M → ℂ) (u : Grid M) :fc (fun y => f y * g y) u = ∑ v : Grid M, fc f v * fc g (u-v) := bycalc_ = fc (fun y => ∑ v : Grid M, fc f v * (g y*chi v y)) u := bycongr 1; funext y; rw [← invert_fc f y,Finset.sum_mul]exact Finset.sum_congr rfl fun _ _ => by ring_ = _ := by simp_rw [fc_sum,fc_lmul,fc_mul_chi]lemma fc_right_translate (f : Grid M → ℂ) (a u : Grid M) :fc (fun y => f (y-a)) u = chi (-u) a * fc f u := byunfold fc; rw [← expU_translate (fun y => f (y-a)*chi (-u) y) a]simp_rw [add_sub_cancel_left,chi_add]rw [← expU_lmul]congr 1; funext y; ringlemma fc_parseval (f : Grid M → ℂ) :∑ u, ‖fc f u‖^2 = expU fun y => ‖f y‖^2 := byhave hc (u : Grid M) :fc (fun y => conj (f y)) (-u) = conj (fc f u) := byunfold fcsimp_rw [expU_cx,← Cx_conj,map_mul, chi_neg']have H := fc_prod f (fun y => conj (f y)) 0simp_rw [zero_sub,hc,Complex.mul_conj,← Complex.sq_norm] at Hunfold fc at Hrw [neg_zero] at Hsimp_rw [chi_zero_left,mul_one,expU_real,← Complex.ofReal_sum] at Hexact Complex.ofReal_inj.mp H.symmend FourierLLogL.Dyadicend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259import OAI.Analysis.FourierLLogL.Fourier.Affine/-! # The finite spatial model -/open MeasureTheory Filter Set Functionopen scoped ENNReal BigOperators Topology Realnamespace OAInamespace FourierLLogL.Dyadicopen Periodnoncomputable sectionabbrev Grid (M : ℕ) := ZMod (2^M)def pos {M : ℕ} (x : Grid M) : ℝ := x.val * side Mdef chi {M : ℕ} (n x : Grid M) : ℂ := ZMod.stdAddChar (n*x)lemma chi_cast {M : ℕ} (n : ℤ) (x : Grid M) : chi (n:Grid M) x = phase n (pos x) := byunfold chihave heq : (n:Grid M)*x = ((n*(x.val:ℤ):ℤ):Grid M) := byrw [Int.cast_mul, Int.cast_natCast, ZMod.natCast_zmod_val]rw [heq, ZMod.stdAddChar_coe, phase, pos, side]congr 1push_castsimp only [div_eq_mul_inv, ← inv_pow]; ringlemma norm_chi {M : ℕ} (n x : Grid M) : ‖chi n x‖ = 1 := byunfold chisimp [ZMod.stdAddChar_apply]/-- Uniform probability average. -/def expU {E : Type*} [SMul ℝ E] [AddCommMonoid E] {M : ℕ} (f : Grid M → E) :=side M • ∑ y, f y@[ext] structure Node wherelev : ℕix : ℕderiving DecidableEqnamespace Nodedef root : Node := ⟨0,0⟩def valid (p : Node) : Prop := p.ix < 2^p.levdef len (p : Node) := side p.levdef a (p : Node) : ℝ := p.ix * p.lendef cells (p : Node) := box p.a p.lentheorem len_pos (p : Node) : 0 < p.len := side_pos _lemma cells_sub {p : Node} (hp : p.valid) : p.cells ⊆ unitInt := bysimpa [lft, unitInt, cells, a, len, box] using cell_in_top 0 zero_lt_one hplemma cells_dis {n k l : ℕ} (h : k ≠ l) :Disjoint (cells ⟨n,k⟩) (cells ⟨n,l⟩) := byrw [Set.disjoint_left]intro x hx hyapply happly cell_unique 0 1 zero_lt_one n (x:=x)all_goals simpa only [lft,one_mul,zero_add]def L (p : Node) : Node := ⟨p.lev+1,p.ix*2⟩def R (p : Node) : Node := ⟨p.lev+1,p.ix*2+1⟩lemma len_L (p : Node) : p.L.len = p.len/2 := side_succ _lemma len_R (p : Node) : p.R.len = p.len/2 := side_succ _lemma a_L (p : Node) : p.L.a = p.a := byunfold arw [len_L]dsimp only [L]push_cast; ringlemma a_R (p : Node) : p.R.a = p.a+p.len/2 := byunfold arw [len_R]dsimp only [R]push_cast; ringlemma cells_L (p : Node) : p.L.cells = Ico p.a (p.a+p.len/2) := by rw [cells, len_L, a_L, box]lemma cells_R (p : Node) : p.R.cells = Ico (p.a+p.len/2) (p.a+p.len) := byrw [cells,len_R,a_R,box]ring_nflemma cells_split (p : Node) : p.cells = p.L.cells ∪ p.R.cells := byrw [cells_L,cells_R,Ico_union_Ico_eq_Ico (by linarith [p.len_pos]) (by linarith [p.len_pos])]rfllemma valid_L (p : Node) : p.L.valid ↔ p.valid := byunfold L valid; simp; omegalemma valid_R (p : Node) : p.R.valid ↔ p.valid := byunfold R valid; simp; omegadef block (p : Node) (M : ℕ) := (pos : Grid M → ℝ) ⁻¹' p.cellsdef avg (p : Node) {M : ℕ} {E : Type*} [AddCommMonoid E] [SMul ℝ E] (f : Grid M → E) :=p.len⁻¹ • expU ((p.block M).indicator f)def normarg (p : Node) (x : ℝ) : ℝ := (x-p.a) / p.lendef Hi (p : Node) (x : ℝ) : ℝ := haarH (p.normarg x)def Gi (p : Node) (x : ℝ) : ℝ := haarG (p.normarg x)lemma arg_mem (p : Node) (x : ℝ) : p.normarg x ∈ unitInt ↔ x ∈ p.cells :=norm_mem_box p.len_poslemma argL_eq (p : Node) (x : ℝ) : p.L.normarg x = 2*p.normarg x := byrw [normarg, a_L,len_L,normarg]ringlemma argR_eq (p : Node) (x : ℝ) : p.R.normarg x = 2*p.normarg x - 1 := byrw [normarg, a_R,len_R,normarg]have H := p.len_posfield_simp; ringlemma Gi_eq (p : Node) (x : ℝ) : p.Gi x = p.L.Hi x - p.R.Hi x := byrw [Hi,Hi, argL_eq, argR_eq]; rfllemma Hi_L (p : Node) {x : ℝ} (hx : x ∈ p.L.cells) : p.Hi x = 1 := byrw [← arg_mem, argL_eq] at hxapply H_of_leftconstructor <;> linarith [hx.1,hx.2]lemma Hi_R (p : Node) {x : ℝ} (hx : x ∈ p.R.cells) : p.Hi x = -1 := byrw [← arg_mem, argR_eq] at hxapply H_of_rightconstructor <;> linarith [hx.1,hx.2]lemma Hi_out (p : Node) {x : ℝ} (hx : x ∉ p.cells) : p.Hi x = 0 := byrw [← arg_mem] at hxexact H_outside hxlemma Gi_out (p : Node) {x : ℝ} (hx : x ∉ p.cells) : p.Gi x = 0 := byrw [← arg_mem] at hxexact G_outside hxend Nodeopen Nodedef vertex {M : ℕ} (x : Grid M) : Node := ⟨M,x.val⟩def atom {M : ℕ} (x : Grid M) := (vertex x).cellslemma pos_mem {M : ℕ} (x : Grid M) : pos x ∈ atom x :=⟨le_refl (pos x), lt_add_of_pos_right (pos x) (side_pos M)⟩lemma atom_sub {M : ℕ} (x : Grid M) : atom x ⊆ unitInt :=cells_sub (ZMod.val_lt _)lemma atom_disjoint {M : ℕ} : Pairwise (fun x y : Grid M => Disjoint (atom x) (atom y)) := byintro x y happly cells_disintro hehave H := congrArg (fun n : ℕ => (n:Grid M)) heexact h (by simpa using H)lemma atom_measurable {M : ℕ} (x : Grid M) : MeasurableSet (atom x) := measurableSet_Icolemma atom_volume {M : ℕ} (x : Grid M) : volume (atom x) = ENNReal.ofReal (side M) := bychange volume (Ico (pos x) (pos x+side M)) = _simplemma atom_partition (M : ℕ) : unitInt = ⋃ x : Grid M, atom x := byapply Subset.antisymm _ (iUnion_subset atom_sub)intro x hxobtain ⟨p,hp,hi,hxp⟩ :∃ p : Node, p.valid ∧ p.lev = M ∧ x ∈ p.cells := byinduction M with| zero =>refine ⟨root,by simp [valid,root], rfl, ?_⟩simpa [root,cells,box, len,side,a,unitInt] using hx| succ M ih =>obtain ⟨p,hv,hM,hx⟩ := ihrw [cells_split] at hxexact hx.elim (fun h => ⟨p.L,p.valid_L.mpr hv,congrArg Nat.succ hM,h⟩)(fun h => ⟨p.R,p.valid_R.mpr hv,congrArg Nat.succ hM,h⟩)refine mem_iUnion.mpr ⟨(p.ix:Grid M),?_⟩obtain ⟨n,k⟩ := pcases hichange x ∈ cells ⟨_, ((k:Grid _).val)⟩rwa [ZMod.val_natCast_of_lt hp]/-- Every atom fully inside/out of a coarser dyadic cell. -/lemma coarse_const {p q : Node} (h : p.lev ≤ q.lev) {x y : ℝ}(hx : x ∈ q.cells) (hy : y ∈ q.cells) : x ∈ p.cells ↔ y ∈ p.cells := bysuffices HH : ∀ n : ℕ, ∀ q : Node, q.lev = p.lev+n →x ∈ q.cells → y ∈ q.cells → (x ∈ p.cells ↔ y ∈ p.cells) byexact HH (q.lev - p.lev) q (by omega) hx hyintro ninduction n with| zero =>rintro ⟨l,k⟩ hl hx hyobtain ⟨m,r⟩ := psimp only [Nat.add_zero] at hlsubst lby_cases H : r = k· subst r; exact iff_of_true hx hy· have Hd := Set.disjoint_left.mp (cells_dis (n:=m) H)exact iff_of_false (fun hh => Hd hh hx) (fun hh => Hd hh hy)| succ n ih =>rintro ⟨l,k⟩ hl hx hylet r : Node := ⟨p.lev+n,k/2⟩have hs : cells ⟨l,k⟩ ⊆ r.cells := byhave heq : (⟨l,k⟩:Node) = r.L ∨ (⟨l,k⟩:Node) = r.R := bysimp only [r,L,R,Node.mk.injEq]change l = p.lev+(n+1) at hlomegarw [cells_split r]exact heq.elim (fun e => e ▸ subset_union_left) (fun e => e ▸ subset_union_right)exact ih r rfl (hs hx) (hs hy)lemma atom_iff_coarse {M : ℕ} (p : Node) (h : p.lev ≤ M) {y : Grid M} {x : ℝ}(hx : x ∈ atom y) : x ∈ p.cells ↔ y ∈ p.block M :=coarse_const (q:=vertex y) h hx (pos_mem y)lemma Hi_const {p q : Node} (h : p.lev+1 ≤ q.lev) {x y : ℝ} (hx : x ∈ q.cells)(hy : y ∈ q.cells) : p.Hi x = p.Hi y := byby_cases hp : x ∈ p.cells· rw [cells_split] at hpexact hp.elim (fun hh => (p.Hi_L hh).trans(p.Hi_L ((coarse_const (p:=p.L) h hx hy).mp hh)).symm)(fun hh => (p.Hi_R hh).trans (p.Hi_R ((coarse_const (p:=p.R) h hx hy).mp hh)).symm)· rw [p.Hi_out hp, p.Hi_out (mt (coarse_const (p:=p) (by omega) hy hx).mp hp)]lemma Gi_const {p q : Node} (h : p.lev+2 ≤ q.lev) {x y : ℝ} (hx : x ∈ q.cells)(hy : y ∈ q.cells) : p.Gi x = p.Gi y := byrw [Gi_eq,Gi_eq, Hi_const (p:=p.L) h hx hy, Hi_const (p:=p.R) h hx hy]def FinJump {M : ℕ} (p : Node) (F : Grid M → ℂ) (x : Grid M) :=p.Gi (pos x) • p.avg (fun y => p.Hi (pos y) • F y)def FinShift {M : ℕ} (J : ℕ) (F : Grid M → ℂ) (x : Grid M) :=∑ n ∈ Finset.range J, ∑ k ∈ Finset.range (2^n), FinJump ⟨n,k⟩ F xdef finMod {M : ℕ} (ρ : Grid M → ℝ) (u : Grid M) (x : Grid M) :=(ρ x : ℂ)*chi u xdef finGood {M : ℕ} (D : ℝ) (J : ℕ) (ρ : Grid M → ℝ) (x : Grid M) :=∀ p : Node, p.valid → p.lev < J → x ∈ p.block M → p.avg ρ ≤ D/-- Finite cut statement; asks for an L¹ majorant restricted to points where density steps staybelow threshold. There is no dependence on a frequency or depth cutoff in the constant. -/def GridBound : Prop :=∃ C : ℝ, 0 ≤ C ∧ ∀ᶠ j : ℕ in atTop, ∀ J : ℕ, ∀ᶠ M : ℕ in atTop,∀ (ρ : Grid M → ℝ), (∀ x, 0 ≤ ρ x) → expU ρ ≤ 2 →(∀ x, ρ x ≤ Real.exp ((2:ℝ)^j)) →∃ W : Grid M → ℝ, (∀ x, 0 ≤ W x) ∧ expU W ≤ C*(2:ℝ)^j ∧∀ x : Grid M, finGood (((j:ℝ)+1)^3) J ρ x →∀ u : Grid M, ‖FinShift J (finMod ρ u) x‖ ≤ W xendend FourierLLogL.Dyadicend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259import OAI.Analysis.FourierLLogL.Fourier.Affine/-! # The finite spatial model -/open MeasureTheory Filter Set Functionopen scoped ENNReal BigOperators Topology Realnamespace OAInamespace FourierLLogL.Dyadicopen Periodnoncomputable sectionabbrev Grid (M : ℕ) := ZMod (2^M)def pos {M : ℕ} (x : Grid M) : ℝ := x.val * side Mdef chi {M : ℕ} (n x : Grid M) : ℂ := ZMod.stdAddChar (n*x)lemma chi_cast {M : ℕ} (n : ℤ) (x : Grid M) : chi (n:Grid M) x = phase n (pos x) := byunfold chihave heq : (n:Grid M)*x = ((n*(x.val:ℤ):ℤ):Grid M) := byrw [Int.cast_mul, Int.cast_natCast, ZMod.natCast_zmod_val]rw [heq, ZMod.stdAddChar_coe, phase, pos, side]congr 1push_castsimp only [div_eq_mul_inv, ← inv_pow]; ringlemma norm_chi {M : ℕ} (n x : Grid M) : ‖chi n x‖ = 1 := byunfold chisimp [ZMod.stdAddChar_apply]/-- Uniform probability average. -/def expU {E : Type*} [SMul ℝ E] [AddCommMonoid E] {M : ℕ} (f : Grid M → E) :=side M • ∑ y, f y@[ext] structure Node wherelev : ℕix : ℕderiving DecidableEqnamespace Nodedef root : Node := ⟨0,0⟩def valid (p : Node) : Prop := p.ix < 2^p.levdef len (p : Node) := side p.levdef a (p : Node) : ℝ := p.ix * p.lendef cells (p : Node) := box p.a p.lentheorem len_pos (p : Node) : 0 < p.len := side_pos _lemma cells_sub {p : Node} (hp : p.valid) : p.cells ⊆ unitInt := bysimpa [lft, unitInt, cells, a, len, box] using cell_in_top 0 zero_lt_one hplemma cells_dis {n k l : ℕ} (h : k ≠ l) :Disjoint (cells ⟨n,k⟩) (cells ⟨n,l⟩) := byrw [Set.disjoint_left]intro x hx hyapply happly cell_unique 0 1 zero_lt_one n (x:=x)all_goals simpa only [lft,one_mul,zero_add]def L (p : Node) : Node := ⟨p.lev+1,p.ix*2⟩def R (p : Node) : Node := ⟨p.lev+1,p.ix*2+1⟩lemma len_L (p : Node) : p.L.len = p.len/2 := side_succ _lemma len_R (p : Node) : p.R.len = p.len/2 := side_succ _lemma a_L (p : Node) : p.L.a = p.a := byunfold arw [len_L]dsimp only [L]push_cast; ringlemma a_R (p : Node) : p.R.a = p.a+p.len/2 := byunfold arw [len_R]dsimp only [R]push_cast; ringlemma cells_L (p : Node) : p.L.cells = Ico p.a (p.a+p.len/2) := by rw [cells, len_L, a_L, box]lemma cells_R (p : Node) : p.R.cells = Ico (p.a+p.len/2) (p.a+p.len) := byrw [cells,len_R,a_R,box]ring_nflemma cells_split (p : Node) : p.cells = p.L.cells ∪ p.R.cells := byrw [cells_L,cells_R,Ico_union_Ico_eq_Ico (by linarith [p.len_pos]) (by linarith [p.len_pos])]rfllemma valid_L (p : Node) : p.L.valid ↔ p.valid := byunfold L valid; simp; omegalemma valid_R (p : Node) : p.R.valid ↔ p.valid := byunfold R valid; simp; omegadef block (p : Node) (M : ℕ) := (pos : Grid M → ℝ) ⁻¹' p.cellsdef avg (p : Node) {M : ℕ} {E : Type*} [AddCommMonoid E] [SMul ℝ E] (f : Grid M → E) :=p.len⁻¹ • expU ((p.block M).indicator f)def normarg (p : Node) (x : ℝ) : ℝ := (x-p.a) / p.lendef Hi (p : Node) (x : ℝ) : ℝ := haarH (p.normarg x)def Gi (p : Node) (x : ℝ) : ℝ := haarG (p.normarg x)lemma arg_mem (p : Node) (x : ℝ) : p.normarg x ∈ unitInt ↔ x ∈ p.cells :=norm_mem_box p.len_poslemma argL_eq (p : Node) (x : ℝ) : p.L.normarg x = 2*p.normarg x := byrw [normarg, a_L,len_L,normarg]ringlemma argR_eq (p : Node) (x : ℝ) : p.R.normarg x = 2*p.normarg x - 1 := byrw [normarg, a_R,len_R,normarg]have H := p.len_posfield_simp; ringlemma Gi_eq (p : Node) (x : ℝ) : p.Gi x = p.L.Hi x - p.R.Hi x := byrw [Hi,Hi, argL_eq, argR_eq]; rfllemma Hi_L (p : Node) {x : ℝ} (hx : x ∈ p.L.cells) : p.Hi x = 1 := byrw [← arg_mem, argL_eq] at hxapply H_of_leftconstructor <;> linarith [hx.1,hx.2]lemma Hi_R (p : Node) {x : ℝ} (hx : x ∈ p.R.cells) : p.Hi x = -1 := byrw [← arg_mem, argR_eq] at hxapply H_of_rightconstructor <;> linarith [hx.1,hx.2]lemma Hi_out (p : Node) {x : ℝ} (hx : x ∉ p.cells) : p.Hi x = 0 := byrw [← arg_mem] at hxexact H_outside hxlemma Gi_out (p : Node) {x : ℝ} (hx : x ∉ p.cells) : p.Gi x = 0 := byrw [← arg_mem] at hxexact G_outside hxend Nodeopen Nodedef vertex {M : ℕ} (x : Grid M) : Node := ⟨M,x.val⟩def atom {M : ℕ} (x : Grid M) := (vertex x).cellslemma pos_mem {M : ℕ} (x : Grid M) : pos x ∈ atom x :=⟨le_refl (pos x), lt_add_of_pos_right (pos x) (side_pos M)⟩lemma atom_sub {M : ℕ} (x : Grid M) : atom x ⊆ unitInt :=cells_sub (ZMod.val_lt _)lemma atom_disjoint {M : ℕ} : Pairwise (fun x y : Grid M => Disjoint (atom x) (atom y)) := byintro x y happly cells_disintro hehave H := congrArg (fun n : ℕ => (n:Grid M)) heexact h (by simpa using H)lemma atom_measurable {M : ℕ} (x : Grid M) : MeasurableSet (atom x) := measurableSet_Icolemma atom_volume {M : ℕ} (x : Grid M) : volume (atom x) = ENNReal.ofReal (side M) := bychange volume (Ico (pos x) (pos x+side M)) = _simplemma atom_partition (M : ℕ) : unitInt = ⋃ x : Grid M, atom x := byapply Subset.antisymm _ (iUnion_subset atom_sub)intro x hxobtain ⟨p,hp,hi,hxp⟩ :∃ p : Node, p.valid ∧ p.lev = M ∧ x ∈ p.cells := byinduction M with| zero =>refine ⟨root,by simp [valid,root], rfl, ?_⟩simpa [root,cells,box, len,side,a,unitInt] using hx| succ M ih =>obtain ⟨p,hv,hM,hx⟩ := ihrw [cells_split] at hxexact hx.elim (fun h => ⟨p.L,p.valid_L.mpr hv,congrArg Nat.succ hM,h⟩)(fun h => ⟨p.R,p.valid_R.mpr hv,congrArg Nat.succ hM,h⟩)refine mem_iUnion.mpr ⟨(p.ix:Grid M),?_⟩obtain ⟨n,k⟩ := pcases hichange x ∈ cells ⟨_, ((k:Grid _).val)⟩rwa [ZMod.val_natCast_of_lt hp]/-- Every atom fully inside/out of a coarser dyadic cell. -/lemma coarse_const {p q : Node} (h : p.lev ≤ q.lev) {x y : ℝ}(hx : x ∈ q.cells) (hy : y ∈ q.cells) : x ∈ p.cells ↔ y ∈ p.cells := bysuffices HH : ∀ n : ℕ, ∀ q : Node, q.lev = p.lev+n →x ∈ q.cells → y ∈ q.cells → (x ∈ p.cells ↔ y ∈ p.cells) byexact HH (q.lev - p.lev) q (by omega) hx hyintro ninduction n with| zero =>rintro ⟨l,k⟩ hl hx hyobtain ⟨m,r⟩ := psimp only [Nat.add_zero] at hlsubst lby_cases H : r = k· subst r; exact iff_of_true hx hy· have Hd := Set.disjoint_left.mp (cells_dis (n:=m) H)exact iff_of_false (fun hh => Hd hh hx) (fun hh => Hd hh hy)| succ n ih =>rintro ⟨l,k⟩ hl hx hylet r : Node := ⟨p.lev+n,k/2⟩have hs : cells ⟨l,k⟩ ⊆ r.cells := byhave heq : (⟨l,k⟩:Node) = r.L ∨ (⟨l,k⟩:Node) = r.R := bysimp only [r,L,R,Node.mk.injEq]change l = p.lev+(n+1) at hlomegarw [cells_split r]exact heq.elim (fun e => e ▸ subset_union_left) (fun e => e ▸ subset_union_right)exact ih r rfl (hs hx) (hs hy)lemma atom_iff_coarse {M : ℕ} (p : Node) (h : p.lev ≤ M) {y : Grid M} {x : ℝ}(hx : x ∈ atom y) : x ∈ p.cells ↔ y ∈ p.block M :=coarse_const (q:=vertex y) h hx (pos_mem y)lemma Hi_const {p q : Node} (h : p.lev+1 ≤ q.lev) {x y : ℝ} (hx : x ∈ q.cells)(hy : y ∈ q.cells) : p.Hi x = p.Hi y := byby_cases hp : x ∈ p.cells· rw [cells_split] at hpexact hp.elim (fun hh => (p.Hi_L hh).trans(p.Hi_L ((coarse_const (p:=p.L) h hx hy).mp hh)).symm)(fun hh => (p.Hi_R hh).trans (p.Hi_R ((coarse_const (p:=p.R) h hx hy).mp hh)).symm)· rw [p.Hi_out hp, p.Hi_out (mt (coarse_const (p:=p) (by omega) hy hx).mp hp)]lemma Gi_const {p q : Node} (h : p.lev+2 ≤ q.lev) {x y : ℝ} (hx : x ∈ q.cells)(hy : y ∈ q.cells) : p.Gi x = p.Gi y := byrw [Gi_eq,Gi_eq, Hi_const (p:=p.L) h hx hy, Hi_const (p:=p.R) h hx hy]def FinJump {M : ℕ} (p : Node) (F : Grid M → ℂ) (x : Grid M) :=p.Gi (pos x) • p.avg (fun y => p.Hi (pos y) • F y)def FinShift {M : ℕ} (J : ℕ) (F : Grid M → ℂ) (x : Grid M) :=∑ n ∈ Finset.range J, ∑ k ∈ Finset.range (2^n), FinJump ⟨n,k⟩ F xdef finMod {M : ℕ} (ρ : Grid M → ℝ) (u : Grid M) (x : Grid M) :=(ρ x : ℂ)*chi u xdef finGood {M : ℕ} (D : ℝ) (J : ℕ) (ρ : Grid M → ℝ) (x : Grid M) :=∀ p : Node, p.valid → p.lev < J → x ∈ p.block M → p.avg ρ ≤ D/-- Finite cut statement; asks for an L¹ majorant restricted to points where density steps staybelow threshold. There is no dependence on a frequency or depth cutoff in the constant. -/def GridBound : Prop :=∃ C : ℝ, 0 ≤ C ∧ ∀ᶠ j : ℕ in atTop, ∀ J : ℕ, ∀ᶠ M : ℕ in atTop,∀ (ρ : Grid M → ℝ), (∀ x, 0 ≤ ρ x) → expU ρ ≤ 2 →(∀ x, ρ x ≤ Real.exp ((2:ℝ)^j)) →∃ W : Grid M → ℝ, (∀ x, 0 ≤ W x) ∧ expU W ≤ C*(2:ℝ)^j ∧∀ x : Grid M, finGood (((j:ℝ)+1)^3) J ρ x →∀ u : Grid M, ‖FinShift J (finMod ρ u) x‖ ≤ W xendend FourierLLogL.Dyadicend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331import OAI.Analysis.FourierLLogL.Dyadic.Grid/-! # Reduction to the finite grid -/open MeasureTheory Filter Set Functionopen scoped ENNReal BigOperators Topology Realnamespace OAInamespace FourierLLogL.Dyadicopen Period Nodenoncomputable sectionlemma expU_mono {M : ℕ} {f g : Grid M → ℝ} (h : ∀ y, f y ≤ g y) :expU f ≤ expU g :=mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun y _ => h y)) (side_pos _).lelemma avg_mono {M : ℕ} (p : Node) {f g : Grid M → ℝ} (h : ∀ y ∈ p.block M, f y ≤ g y) :p.avg f ≤ p.avg g := byapply mul_le_mul_of_nonneg_left (expU_mono ?_) (inv_pos.mpr p.len_pos).leintro yby_cases hy : y ∈ p.block M· simpa [hy] using h y hy· simp [hy]lemma atom_volume_real {M : ℕ} (x : Grid M) : volume.real (atom x) = side M := byrw [measureReal_def, atom_volume, ENNReal.toReal_ofReal (side_pos M).le]section Evariable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]/-- Cell averages from the real model. -/def liftGrid (M : ℕ) (f : ℝ → E) (y : Grid M) : E :=(side M)⁻¹ • ∫ x in atom y, f xlemma expU_liftGrid (M : ℕ) (f : ℝ → E) (hf : Integrable f μ₁) :expU (liftGrid M f) = ∫ x, f x ∂μ₁ := byhave hi : IntegrableOn f (⋃ y : Grid M, atom y) := by rw [← atom_partition]; exact hfunfold expU liftGrid μ₁rw [atom_partition M, integral_iUnion atom_measurable atom_disjoint hi, tsum_fintype]rw [Finset.smul_sum]refine Finset.sum_congr rfl fun x _ => ?_rw [smul_smul, mul_inv_cancel₀ (side_pos M).ne', one_smul]lemma liftGrid_ind {M : ℕ} (p : Node) (h : p.lev ≤ M) (f : ℝ → E) :liftGrid M (p.cells.indicator f) = (p.block M).indicator (liftGrid M f) := byext yby_cases hy : y ∈ p.block M· rw [indicator_of_mem hy]unfold liftGridcongr 1exact setIntegral_congr_fun (atom_measurable y)(fun x hx => indicator_of_mem ((atom_iff_coarse p h hx).mpr hy) f)· rw [indicator_of_notMem hy, liftGrid, setIntegral_eq_zero_of_forall_eq_zero]· exact smul_zero _· exact fun x hx => indicator_of_notMem (mt (atom_iff_coarse p h hx).mp hy) flemma avg_liftGrid {M : ℕ} (f : ℝ → E) (hf : Integrable f μ₁){p : Node} (hp : p.valid) (h : p.lev ≤ M) :p.avg (liftGrid M f) = p.len⁻¹ • ∫ x in p.cells, f x := byrw [avg, ← liftGrid_ind p h, expU_liftGrid, μ₁, setIntegral_indicator(show MeasurableSet p.cells from measurableSet_Ico), inter_eq_right.mpr (cells_sub hp)]exact hf.indicator measurableSet_Icolemma avg_smulHi_lift {M : ℕ} (f : ℝ → E) {p : Node} (hp : p.valid) (h : p.lev+1 ≤ M)(hF : Integrable (fun x => p.Hi x • f x) μ₁) :p.avg (fun y => p.Hi (pos y) • liftGrid M f y) =∫ x, haarH x • f (p.a+p.len*x) ∂μ₁ := byhave heq : (fun y => p.Hi (pos y) • liftGrid M f y) =liftGrid M (fun x => p.Hi x • f x) := byext yunfold liftGridrw [smul_comm, ← integral_smul]congr 1exact setIntegral_congr_fun (atom_measurable _) fun x hx =>congrArg (fun c : ℝ => c • f x) (Hi_const (p:=p) (q:=vertex y) h (pos_mem y) hx)rw [heq, avg_liftGrid _ hF hp (by omega),cells, box, ← mean_translate_scale (fun x => p.Hi x • f x) p.a p.len_pos]congr 1funext xrw [show p.Hi (p.a+p.len*x) = haarH x from congrArg haarH (byunfold normarg; field_simp [p.len_pos.ne']; ring)]lemma norm_expU_le {M : ℕ} (f : Grid M → E) : ‖expU f‖ ≤ expU (fun x => ‖f x‖) := byunfold expUrw [norm_smul, Real.norm_eq_abs, abs_of_pos (side_pos _)]exact mul_le_mul_of_nonneg_left (norm_sum_le _ _) (side_pos _).lelemma norm_avg_le {M : ℕ} (p : Node) (f : Grid M → E) :‖p.avg f‖ ≤ p.avg (fun x => ‖f x‖) := byunfold avgrw [norm_smul, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr p.len_pos)]refine mul_le_mul_of_nonneg_left ((norm_expU_le _).trans ?_) (inv_pos.mpr p.len_pos).leapply expU_monointro y; by_cases hy : y ∈ block p M <;> simp [hy]lemma avg_sub {M : ℕ} (p : Node) (f g : Grid M → E) :p.avg (fun y => f y - g y) = p.avg f - p.avg g := byunfold avg expUsimp_rw [indicator_sub, Finset.sum_sub_distrib, smul_sub]variable [CompleteSpace E]lemma liftGrid_const {M : ℕ} (c : E) (y : Grid M) :liftGrid M (fun _ => c) y = c := byrw [liftGrid, setIntegral_const, atom_volume_real, smul_smul,inv_mul_cancel₀ (side_pos _).ne', one_smul]lemma avg_const {M : ℕ} {p : Node} (hp : p.valid) (h : p.lev ≤ M) (c : E) :p.avg (fun _ : Grid M => c) = c := byhave heq := funext (liftGrid_const (M:=M) c)rw [← heq, avg_liftGrid (fun _ : ℝ => c) (integrable_const _) hp h, setIntegral_const]have hh : volume.real p.cells = p.len := byrw [cells,box, Real.volume_real_Ico_of_le (by linarith [p.len_pos])]ringrw [hh, smul_smul, inv_mul_cancel₀ p.len_pos.ne', one_smul]end Elemma lift_bounds {M : ℕ} {ρ : ℝ → ℝ} (hρ : Integrable ρ μ₁) (h0 : ∀ x, 0 ≤ ρ x)(B : ℝ) (hb : ∀ x, ρ x ≤ B) (y : Grid M) :0 ≤ liftGrid M ρ y ∧ liftGrid M ρ y ≤ B := byhave hi : IntegrableOn ρ (atom y) := (show IntegrableOn ρ unitInt volume from hρ).mono_set (atom_sub y)have : IsFiniteMeasure (volume.restrict (atom y)) :=show IsFiniteMeasure (volume.restrict (Ico (pos y) (pos y+side M))) from inferInstanceconstructor· exact mul_nonneg (inv_pos.mpr (side_pos _)).le (integral_nonneg h0)· have H : (∫ x in atom y, ρ x) ≤ ∫ x in atom y, B :=integral_mono hi (integrable_const _) hbexact le_trans (mul_le_mul_of_nonneg_left H (inv_pos.mpr (side_pos _)).le)(liftGrid_const B y).lelemma lift_shift {M : ℕ} (J : ℕ) (hJ : J+1 ≤ M) (f : ℝ → ℂ)(hf : Measurable f) (B : ℝ) (hb : ∀ x, ‖f x‖ ≤ B) {y : Grid M} {x : ℝ} (hx : x ∈ atom y) :FinShift J (liftGrid M f) y = shift f 0 1 J x := byunfold FinShift shift haarLayerrefine Finset.sum_congr rfl fun n hn => Finset.sum_congr rfl fun k hk => ?_let p : Node := ⟨n,k⟩have hl : p.lev+2 ≤ M := by dsimp [p]; rw [Finset.mem_range] at hn; omegahave hB' (x : ℝ) := H_bound (p.normarg x)have Hm : Measurable (p.Hi) := measurableH.comp (by unfold normarg; fun_prop)have Hi : Integrable (fun x => p.Hi x • f x) μ₁ :=Integrable.of_bound (Hm.smul hf).aestronglyMeasurable B (ae_of_all _ (fun x => bychange ‖p.Hi x • f x‖ ≤ _rw [norm_smul]exact (mul_le_of_le_one_left (norm_nonneg _)(show ‖p.Hi x‖ ≤ 1 from hB' x)).trans (hb x)))rw [show lft 0 1 n k = p.a by simp [lft,p,a,len], one_mul]change FinJump p _ y = p.Gi x • _rw [FinJump, Gi_const (q:=vertex y) hl (pos_mem y) hx,avg_smulHi_lift f (Finset.mem_range.mp hk) (by omega) Hi]rfllemma lift_mod_error (M : ℕ) {ρ : ℝ → ℝ} (hρ : Measurable ρ) (h0 : ∀ x, 0 ≤ ρ x)(B : ℝ) (hb : ∀ x, ρ x ≤ B) (n : ℤ) (y : Grid M) :‖liftGrid M (modρ ρ (n:ℝ)) y - finMod (liftGrid M ρ) (n:Grid M) y‖ ≤(B * |(n:ℝ)| * (2*π)) * side M := byrw [finMod, chi_cast]have : IsFiniteMeasure (volume.restrict (atom y)) :=show IsFiniteMeasure (volume.restrict (Ico (pos y) (pos y+side M))) from inferInstancelet u : ℝ := nlet q (x : ℝ) := (ρ x:ℂ) * phase u (pos y)let F := modρ ρ ulet C := (B * |u| *(2*π))*side Mhave heq : (↑(liftGrid M ρ y) : ℂ) * phase u (pos y) = liftGrid M q y := byunfold liftGrid qrw [integral_mul_const, integral_complex_ofReal]simp only [Complex.real_smul, smul_eq_mul, Complex.ofReal_mul, mul_assoc]change ‖liftGrid M F y - _ * phase u (pos y)‖ ≤ Crw [heq]have HiF : IntegrableOn F (atom y) := Integrable.of_bound (measurable_mod hρ _).aestronglyMeasurable B(ae_of_all _ fun x => by rw [norm_mod h0]; exact hb x)have Hiq : IntegrableOn q (atom y) :=Integrable.of_bound (((Complex.continuous_ofReal.measurable.comp hρ).mul measurable_const).aestronglyMeasurable) B (ae_of_all _ fun x => bychange ‖q x‖ ≤ _unfold qsimpa only [norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (h0 x),phase_unimod, mul_one] using hb x)have hh (x : ℝ) (hx : x ∈ atom y) : ‖F x - q x‖ ≤ C := byunfold F modρ q Crw [← mul_sub, norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (h0 _)]have hk : |x-pos y| ≤ side M := bychange pos y ≤ x ∧ x < pos y+side M at hxrw [abs_le]; constructor <;> linarith [hx.1,hx.2,side_pos M]calc_ ≤ B*(|u| *(2*π*side M)) := mul_le_mul (hb x)((norm_phase_sub u x _).trans (by gcongr)) (norm_nonneg _) ((h0 x).trans (hb x))_ = _ := by ringrw [liftGrid, liftGrid, ← smul_sub, ← integral_sub HiF Hiq, norm_smul, Real.norm_eq_abs,abs_of_pos (inv_pos.mpr (side_pos M))]have H : ‖∫ x in atom y, F x - q x‖ ≤ ∫ _ in atom y, C :=(norm_integral_le_integral_norm _).trans (integral_mono_ae (HiF.sub Hiq).norm(integrable_const _) ((ae_restrict_mem (atom_measurable y)).mono hh))refine (mul_le_mul_of_nonneg_left H (inv_pos.mpr (side_pos M)).le).trans ?_rw [setIntegral_const, atom_volume_real, smul_eq_mul, ← mul_assoc,inv_mul_cancel₀ (side_pos M).ne', one_mul]lemma FinJump_error {M : ℕ} {f g : Grid M → ℂ} (B : ℝ)(h : ∀ x, ‖f x - g x‖ ≤ B) {p : Node} (hp : p.valid) (hl : p.lev ≤ M) (x : Grid M) :‖FinJump p f x - FinJump p g x‖ ≤ B := byrw [FinJump, FinJump, ← smul_sub, ← avg_sub, norm_smul, Real.norm_eq_abs]refine (mul_le_of_le_one_left (norm_nonneg _) (G_bound _)).trans((norm_avg_le _ _).trans ?_)refine (avg_mono p (g:=fun _ => B) fun y _ => ?_).trans (avg_const hp hl B).lerw [← smul_sub, norm_smul, Real.norm_eq_abs]exact (mul_le_of_le_one_left (norm_nonneg _) (H_bound _)).trans (h _)lemma FinShift_error {M : ℕ} {f g : Grid M → ℂ} (B : ℝ)(h : ∀ x, ‖f x - g x‖ ≤ B) {J : ℕ} (hJ : J ≤ M) (x : Grid M) :‖FinShift J f x - FinShift J g x‖ ≤ (∑ n ∈ Finset.range J, (2:ℝ)^n)*B := byunfold FinShiftrw [← Finset.sum_sub_distrib,Finset.sum_mul]refine (norm_sum_le _ _).trans (Finset.sum_le_sum (fun n hn => ?_))rw [← Finset.sum_sub_distrib]refine (norm_sum_le _ _).trans ?_apply le_trans (b:=∑ k ∈ Finset.range (2^n), B)· exact Finset.sum_le_sum (fun k hk => FinJump_error B h (Finset.mem_range.mp hk)((Finset.mem_range.mp hn).le.trans hJ) _)simplemma usable_transfer {ρ : ℝ → ℝ} (hf : Integrable ρ μ₁) (D : ℝ){M J : ℕ} (h : J ≤ M) {x : ℝ} (hx : usable ρ 0 1 J D x){y : Grid M} (hy : x ∈ atom y) :finGood D J (liftGrid M ρ) y := byintro p hp hl hpyrw [avg_liftGrid ρ hf hp (hl.le.trans h)]have hx' : x ∈ p.cells := (atom_iff_coarse p (hl.le.trans h) hy).mpr hpyhave H1 : lft 0 1 p.lev p.ix = p.a := by simp [lft,a,len]have H2 : 1*side p.lev = p.len := one_mul _have H := hx p.lev hl p.ix hp (by rwa [H1,H2])rw [H1,H2,density,mean_translate_scale _ _ p.len_pos] at Hexact Hlemma expU_add_one (M : ℕ) (W : Grid M → ℝ) :expU (fun y => W y + 1) = expU W + 1 := bysimp only [expU, Finset.sum_add_distrib, smul_eq_mul, Finset.sum_const, Finset.card_univ,nsmul_eq_mul, mul_one, mul_add, Grid, ZMod.card, Nat.cast_pow, Nat.cast_ofNat]rw [mul_comm (side M) ((2:ℝ)^M), pow_mul_side]theorem GridBound.unitTreeBound (hgrid : GridBound) : UnitTreeBound := byobtain ⟨C,hC,h⟩ := hgridrefine ⟨C+1, by positivity,?_⟩filter_upwards [h] with j hjintro ρ hρ h0 hm hb J G hG hGu hDlet B := Real.exp ((2:ℝ)^j)have hB : 0 ≤ B := Real.exp_nonneg _have hbi : Integrable ρ μ₁ := Integrable.of_bound hρ.aestronglyMeasurable B(ae_of_all _ (fun x => by simpa [Real.norm_eq_abs, abs_of_nonneg (h0 x)] using hb x))let Y (n : ℤ) (x : ℝ) := ENNReal.ofReal ‖shift (modρ ρ n) 0 1 J x‖let Z (n : ℕ) (x : ℝ) := ⨆ i : ℤ, ⨆ (_h : i.natAbs ≤ n), Y i xhave hYm (n : ℤ) : Measurable (Y n) :=(show Measurable (fun x => shift (modρ ρ n) 0 1 J x)from measurable_shift_comp (measurable_mod hρ _) measurable_const measurable_const measurable_id J)|>.norm.ennreal_ofRealhave hZm (n : ℕ) : Measurable (Z n) :=Measurable.iSup fun i => Measurable.iSup fun (_ : i.natAbs ≤ n) => hYm ihave hZo : Monotone Z := fun n m h x => iSup_le fun i => iSup_le fun hi =>le_iSup₂ (f := fun i (_h : i.natAbs ≤ m) => Y i x) i (le_trans hi h)have hZ (x : ℝ) : maxShift ρ 0 1 J x ≤ ⨆ n, Z n x := byrefine iSup_le fun i =>(le_iSup₂ (f := fun l : ℤ => fun (_ : l.natAbs ≤ i.natAbs) => Y l x) i le_rfl).trans(le_iSup (fun n => Z n x) i.natAbs)refine (lintegral_mono hZ).trans ?_rw [lintegral_iSup hZm hZo]refine iSup_le fun n => ?_let S := ∑ m ∈ Finset.range J, (2:ℝ)^mhave ht : Tendsto (fun M => S*(B*(n:ℝ)*(2*π))*side M) atTop (𝓝 0) := byhave hs : Tendsto side atTop (𝓝 0) := tendsto_pow_atTop_nhds_zero_of_lt_one(by norm_num) (by norm_num)simpa only [mul_zero] using hs.const_mul (S*(B*(n:ℝ)*(2*π)))obtain ⟨M,hM,hMJ,hMt⟩ := ((hj J).and((eventually_ge_atTop (J+1)).and (ht.eventually (gt_mem_nhds (show (0:ℝ)<1 by norm_num))))).existschange _ < (1:ℝ) at hMtobtain ⟨W,hW,hWm,hWe⟩ :=hM (liftGrid M ρ) (fun y => (lift_bounds hbi h0 B hb y).1) (by rwa [expU_liftGrid M ρ hbi])(fun y => (lift_bounds hbi h0 B hb y).2)have Hx (y : Grid M) (x : ℝ) (hx : x ∈ atom y) (hxg : x ∈ G) :Z n x ≤ ENNReal.ofReal (W y + 1) := byrefine iSup_le fun (i : ℤ) => iSup_le fun hi => ?_have hw := hWe y (usable_transfer hbi _ (by omega) (hD x hxg) hx) (i:Grid M)let f := liftGrid M (modρ ρ (i:ℝ))have hh := FinShift_error (B*|(i:ℝ)| * (2*π)*side M) (lift_mod_error M hρ h0 B hb i)(show J ≤ M by omega) ychange ‖FinShift J f y - _‖ ≤ S*_ at hhhave Hlem : |(i:ℝ)| ≤ (n:ℝ) := by rw [abs_le]; constructor <;> exact_mod_cast (by omega)have hlim : S*(B*|(i:ℝ)| * (2*π)*side M) ≤ 1 := bycalc_ ≤ S*(B*(n:ℝ)*(2*π)*side M) := byhave h := side_pos Mhave : 0 ≤ S := Finset.sum_nonneg (fun _ _ => by positivity)gcongr_ ≤ 1 := by linarithchange ENNReal.ofReal _ ≤ _apply ENNReal.ofReal_le_ofRealhave hfi (x : ℝ) : ‖modρ ρ i x‖ ≤ B := by rw [norm_mod h0]; exact hb _rw [← lift_shift J hMJ _ (measurable_mod hρ _) B hfi hx]have HE := norm_sub_norm_le (FinShift J f y) (FinShift J (finMod (liftGrid M ρ) (i:Grid M)) y)change ‖FinShift J f y‖ ≤ W y + 1linarithlet V := G.indicator (Z n)have HV : (∫⁻ x in G, Z n x) = ∫⁻ x in unitInt, V x := byunfold Vrw [lintegral_indicator hG, Measure.restrict_restrict hG, inter_eq_left.mpr hGu]rw [HV, atom_partition M, lintegral_iUnion atom_measurable atom_disjoint, tsum_fintype]have Hv (y : Grid M) :(∫⁻ x in atom y, V x) ≤ ENNReal.ofReal ((W y+1)*side M) := bycalc_ ≤ ∫⁻ _ in atom y, ENNReal.ofReal (W y+1) := byapply lintegral_mono_aefilter_upwards [ae_restrict_mem (atom_measurable y)] with x hxby_cases H : x ∈ G· simpa [V,H] using Hx y x hx H· simp [V,H]_ = _ := by rw [setLIntegral_const, atom_volume,ENNReal.ofReal_mul (by linarith [hW y] : 0 ≤ W y+1)]refine (Finset.sum_le_sum (fun y _ => Hv y)).trans ?_rw [← ENNReal.ofReal_sum_of_nonneg]· apply ENNReal.ofReal_le_ofRealcalc∑ y, _ = expU (fun y => W y + 1) := by simp only [expU,smul_eq_mul,← Finset.sum_mul]; ring_ ≤ C*(2:ℝ)^j+1 := by rw [expU_add_one M W]; linarith_ ≤ _ := by linarith [one_le_pow₀ (by norm_num : (1:ℝ) ≤ 2) (n:=j)]· intro y _; have := side_pos M; have := hW y; positivityendend FourierLLogL.Dyadicend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331import OAI.Analysis.FourierLLogL.Dyadic.Grid/-! # Reduction to the finite grid -/open MeasureTheory Filter Set Functionopen scoped ENNReal BigOperators Topology Realnamespace OAInamespace FourierLLogL.Dyadicopen Period Nodenoncomputable sectionlemma expU_mono {M : ℕ} {f g : Grid M → ℝ} (h : ∀ y, f y ≤ g y) :expU f ≤ expU g :=mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun y _ => h y)) (side_pos _).lelemma avg_mono {M : ℕ} (p : Node) {f g : Grid M → ℝ} (h : ∀ y ∈ p.block M, f y ≤ g y) :p.avg f ≤ p.avg g := byapply mul_le_mul_of_nonneg_left (expU_mono ?_) (inv_pos.mpr p.len_pos).leintro yby_cases hy : y ∈ p.block M· simpa [hy] using h y hy· simp [hy]lemma atom_volume_real {M : ℕ} (x : Grid M) : volume.real (atom x) = side M := byrw [measureReal_def, atom_volume, ENNReal.toReal_ofReal (side_pos M).le]section Evariable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]/-- Cell averages from the real model. -/def liftGrid (M : ℕ) (f : ℝ → E) (y : Grid M) : E :=(side M)⁻¹ • ∫ x in atom y, f xlemma expU_liftGrid (M : ℕ) (f : ℝ → E) (hf : Integrable f μ₁) :expU (liftGrid M f) = ∫ x, f x ∂μ₁ := byhave hi : IntegrableOn f (⋃ y : Grid M, atom y) := by rw [← atom_partition]; exact hfunfold expU liftGrid μ₁rw [atom_partition M, integral_iUnion atom_measurable atom_disjoint hi, tsum_fintype]rw [Finset.smul_sum]refine Finset.sum_congr rfl fun x _ => ?_rw [smul_smul, mul_inv_cancel₀ (side_pos M).ne', one_smul]lemma liftGrid_ind {M : ℕ} (p : Node) (h : p.lev ≤ M) (f : ℝ → E) :liftGrid M (p.cells.indicator f) = (p.block M).indicator (liftGrid M f) := byext yby_cases hy : y ∈ p.block M· rw [indicator_of_mem hy]unfold liftGridcongr 1exact setIntegral_congr_fun (atom_measurable y)(fun x hx => indicator_of_mem ((atom_iff_coarse p h hx).mpr hy) f)· rw [indicator_of_notMem hy, liftGrid, setIntegral_eq_zero_of_forall_eq_zero]· exact smul_zero _· exact fun x hx => indicator_of_notMem (mt (atom_iff_coarse p h hx).mp hy) flemma avg_liftGrid {M : ℕ} (f : ℝ → E) (hf : Integrable f μ₁){p : Node} (hp : p.valid) (h : p.lev ≤ M) :p.avg (liftGrid M f) = p.len⁻¹ • ∫ x in p.cells, f x := byrw [avg, ← liftGrid_ind p h, expU_liftGrid, μ₁, setIntegral_indicator(show MeasurableSet p.cells from measurableSet_Ico), inter_eq_right.mpr (cells_sub hp)]exact hf.indicator measurableSet_Icolemma avg_smulHi_lift {M : ℕ} (f : ℝ → E) {p : Node} (hp : p.valid) (h : p.lev+1 ≤ M)(hF : Integrable (fun x => p.Hi x • f x) μ₁) :p.avg (fun y => p.Hi (pos y) • liftGrid M f y) =∫ x, haarH x • f (p.a+p.len*x) ∂μ₁ := byhave heq : (fun y => p.Hi (pos y) • liftGrid M f y) =liftGrid M (fun x => p.Hi x • f x) := byext yunfold liftGridrw [smul_comm, ← integral_smul]congr 1exact setIntegral_congr_fun (atom_measurable _) fun x hx =>congrArg (fun c : ℝ => c • f x) (Hi_const (p:=p) (q:=vertex y) h (pos_mem y) hx)rw [heq, avg_liftGrid _ hF hp (by omega),cells, box, ← mean_translate_scale (fun x => p.Hi x • f x) p.a p.len_pos]congr 1funext xrw [show p.Hi (p.a+p.len*x) = haarH x from congrArg haarH (byunfold normarg; field_simp [p.len_pos.ne']; ring)]lemma norm_expU_le {M : ℕ} (f : Grid M → E) : ‖expU f‖ ≤ expU (fun x => ‖f x‖) := byunfold expUrw [norm_smul, Real.norm_eq_abs, abs_of_pos (side_pos _)]exact mul_le_mul_of_nonneg_left (norm_sum_le _ _) (side_pos _).lelemma norm_avg_le {M : ℕ} (p : Node) (f : Grid M → E) :‖p.avg f‖ ≤ p.avg (fun x => ‖f x‖) := byunfold avgrw [norm_smul, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr p.len_pos)]refine mul_le_mul_of_nonneg_left ((norm_expU_le _).trans ?_) (inv_pos.mpr p.len_pos).leapply expU_monointro y; by_cases hy : y ∈ block p M <;> simp [hy]lemma avg_sub {M : ℕ} (p : Node) (f g : Grid M → E) :p.avg (fun y => f y - g y) = p.avg f - p.avg g := byunfold avg expUsimp_rw [indicator_sub, Finset.sum_sub_distrib, smul_sub]variable [CompleteSpace E]lemma liftGrid_const {M : ℕ} (c : E) (y : Grid M) :liftGrid M (fun _ => c) y = c := byrw [liftGrid, setIntegral_const, atom_volume_real, smul_smul,inv_mul_cancel₀ (side_pos _).ne', one_smul]lemma avg_const {M : ℕ} {p : Node} (hp : p.valid) (h : p.lev ≤ M) (c : E) :p.avg (fun _ : Grid M => c) = c := byhave heq := funext (liftGrid_const (M:=M) c)rw [← heq, avg_liftGrid (fun _ : ℝ => c) (integrable_const _) hp h, setIntegral_const]have hh : volume.real p.cells = p.len := byrw [cells,box, Real.volume_real_Ico_of_le (by linarith [p.len_pos])]ringrw [hh, smul_smul, inv_mul_cancel₀ p.len_pos.ne', one_smul]end Elemma lift_bounds {M : ℕ} {ρ : ℝ → ℝ} (hρ : Integrable ρ μ₁) (h0 : ∀ x, 0 ≤ ρ x)(B : ℝ) (hb : ∀ x, ρ x ≤ B) (y : Grid M) :0 ≤ liftGrid M ρ y ∧ liftGrid M ρ y ≤ B := byhave hi : IntegrableOn ρ (atom y) := (show IntegrableOn ρ unitInt volume from hρ).mono_set (atom_sub y)have : IsFiniteMeasure (volume.restrict (atom y)) :=show IsFiniteMeasure (volume.restrict (Ico (pos y) (pos y+side M))) from inferInstanceconstructor· exact mul_nonneg (inv_pos.mpr (side_pos _)).le (integral_nonneg h0)· have H : (∫ x in atom y, ρ x) ≤ ∫ x in atom y, B :=integral_mono hi (integrable_const _) hbexact le_trans (mul_le_mul_of_nonneg_left H (inv_pos.mpr (side_pos _)).le)(liftGrid_const B y).lelemma lift_shift {M : ℕ} (J : ℕ) (hJ : J+1 ≤ M) (f : ℝ → ℂ)(hf : Measurable f) (B : ℝ) (hb : ∀ x, ‖f x‖ ≤ B) {y : Grid M} {x : ℝ} (hx : x ∈ atom y) :FinShift J (liftGrid M f) y = shift f 0 1 J x := byunfold FinShift shift haarLayerrefine Finset.sum_congr rfl fun n hn => Finset.sum_congr rfl fun k hk => ?_let p : Node := ⟨n,k⟩have hl : p.lev+2 ≤ M := by dsimp [p]; rw [Finset.mem_range] at hn; omegahave hB' (x : ℝ) := H_bound (p.normarg x)have Hm : Measurable (p.Hi) := measurableH.comp (by unfold normarg; fun_prop)have Hi : Integrable (fun x => p.Hi x • f x) μ₁ :=Integrable.of_bound (Hm.smul hf).aestronglyMeasurable B (ae_of_all _ (fun x => bychange ‖p.Hi x • f x‖ ≤ _rw [norm_smul]exact (mul_le_of_le_one_left (norm_nonneg _)(show ‖p.Hi x‖ ≤ 1 from hB' x)).trans (hb x)))rw [show lft 0 1 n k = p.a by simp [lft,p,a,len], one_mul]change FinJump p _ y = p.Gi x • _rw [FinJump, Gi_const (q:=vertex y) hl (pos_mem y) hx,avg_smulHi_lift f (Finset.mem_range.mp hk) (by omega) Hi]rfllemma lift_mod_error (M : ℕ) {ρ : ℝ → ℝ} (hρ : Measurable ρ) (h0 : ∀ x, 0 ≤ ρ x)(B : ℝ) (hb : ∀ x, ρ x ≤ B) (n : ℤ) (y : Grid M) :‖liftGrid M (modρ ρ (n:ℝ)) y - finMod (liftGrid M ρ) (n:Grid M) y‖ ≤(B * |(n:ℝ)| * (2*π)) * side M := byrw [finMod, chi_cast]have : IsFiniteMeasure (volume.restrict (atom y)) :=show IsFiniteMeasure (volume.restrict (Ico (pos y) (pos y+side M))) from inferInstancelet u : ℝ := nlet q (x : ℝ) := (ρ x:ℂ) * phase u (pos y)let F := modρ ρ ulet C := (B * |u| *(2*π))*side Mhave heq : (↑(liftGrid M ρ y) : ℂ) * phase u (pos y) = liftGrid M q y := byunfold liftGrid qrw [integral_mul_const, integral_complex_ofReal]simp only [Complex.real_smul, smul_eq_mul, Complex.ofReal_mul, mul_assoc]change ‖liftGrid M F y - _ * phase u (pos y)‖ ≤ Crw [heq]have HiF : IntegrableOn F (atom y) := Integrable.of_bound (measurable_mod hρ _).aestronglyMeasurable B(ae_of_all _ fun x => by rw [norm_mod h0]; exact hb x)have Hiq : IntegrableOn q (atom y) :=Integrable.of_bound (((Complex.continuous_ofReal.measurable.comp hρ).mul measurable_const).aestronglyMeasurable) B (ae_of_all _ fun x => bychange ‖q x‖ ≤ _unfold qsimpa only [norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (h0 x),phase_unimod, mul_one] using hb x)have hh (x : ℝ) (hx : x ∈ atom y) : ‖F x - q x‖ ≤ C := byunfold F modρ q Crw [← mul_sub, norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (h0 _)]have hk : |x-pos y| ≤ side M := bychange pos y ≤ x ∧ x < pos y+side M at hxrw [abs_le]; constructor <;> linarith [hx.1,hx.2,side_pos M]calc_ ≤ B*(|u| *(2*π*side M)) := mul_le_mul (hb x)((norm_phase_sub u x _).trans (by gcongr)) (norm_nonneg _) ((h0 x).trans (hb x))_ = _ := by ringrw [liftGrid, liftGrid, ← smul_sub, ← integral_sub HiF Hiq, norm_smul, Real.norm_eq_abs,abs_of_pos (inv_pos.mpr (side_pos M))]have H : ‖∫ x in atom y, F x - q x‖ ≤ ∫ _ in atom y, C :=(norm_integral_le_integral_norm _).trans (integral_mono_ae (HiF.sub Hiq).norm(integrable_const _) ((ae_restrict_mem (atom_measurable y)).mono hh))refine (mul_le_mul_of_nonneg_left H (inv_pos.mpr (side_pos M)).le).trans ?_rw [setIntegral_const, atom_volume_real, smul_eq_mul, ← mul_assoc,inv_mul_cancel₀ (side_pos M).ne', one_mul]lemma FinJump_error {M : ℕ} {f g : Grid M → ℂ} (B : ℝ)(h : ∀ x, ‖f x - g x‖ ≤ B) {p : Node} (hp : p.valid) (hl : p.lev ≤ M) (x : Grid M) :‖FinJump p f x - FinJump p g x‖ ≤ B := byrw [FinJump, FinJump, ← smul_sub, ← avg_sub, norm_smul, Real.norm_eq_abs]refine (mul_le_of_le_one_left (norm_nonneg _) (G_bound _)).trans((norm_avg_le _ _).trans ?_)refine (avg_mono p (g:=fun _ => B) fun y _ => ?_).trans (avg_const hp hl B).lerw [← smul_sub, norm_smul, Real.norm_eq_abs]exact (mul_le_of_le_one_left (norm_nonneg _) (H_bound _)).trans (h _)lemma FinShift_error {M : ℕ} {f g : Grid M → ℂ} (B : ℝ)(h : ∀ x, ‖f x - g x‖ ≤ B) {J : ℕ} (hJ : J ≤ M) (x : Grid M) :‖FinShift J f x - FinShift J g x‖ ≤ (∑ n ∈ Finset.range J, (2:ℝ)^n)*B := byunfold FinShiftrw [← Finset.sum_sub_distrib,Finset.sum_mul]refine (norm_sum_le _ _).trans (Finset.sum_le_sum (fun n hn => ?_))rw [← Finset.sum_sub_distrib]refine (norm_sum_le _ _).trans ?_apply le_trans (b:=∑ k ∈ Finset.range (2^n), B)· exact Finset.sum_le_sum (fun k hk => FinJump_error B h (Finset.mem_range.mp hk)((Finset.mem_range.mp hn).le.trans hJ) _)simplemma usable_transfer {ρ : ℝ → ℝ} (hf : Integrable ρ μ₁) (D : ℝ){M J : ℕ} (h : J ≤ M) {x : ℝ} (hx : usable ρ 0 1 J D x){y : Grid M} (hy : x ∈ atom y) :finGood D J (liftGrid M ρ) y := byintro p hp hl hpyrw [avg_liftGrid ρ hf hp (hl.le.trans h)]have hx' : x ∈ p.cells := (atom_iff_coarse p (hl.le.trans h) hy).mpr hpyhave H1 : lft 0 1 p.lev p.ix = p.a := by simp [lft,a,len]have H2 : 1*side p.lev = p.len := one_mul _have H := hx p.lev hl p.ix hp (by rwa [H1,H2])rw [H1,H2,density,mean_translate_scale _ _ p.len_pos] at Hexact Hlemma expU_add_one (M : ℕ) (W : Grid M → ℝ) :expU (fun y => W y + 1) = expU W + 1 := bysimp only [expU, Finset.sum_add_distrib, smul_eq_mul, Finset.sum_const, Finset.card_univ,nsmul_eq_mul, mul_one, mul_add, Grid, ZMod.card, Nat.cast_pow, Nat.cast_ofNat]rw [mul_comm (side M) ((2:ℝ)^M), pow_mul_side]theorem GridBound.unitTreeBound (hgrid : GridBound) : UnitTreeBound := byobtain ⟨C,hC,h⟩ := hgridrefine ⟨C+1, by positivity,?_⟩filter_upwards [h] with j hjintro ρ hρ h0 hm hb J G hG hGu hDlet B := Real.exp ((2:ℝ)^j)have hB : 0 ≤ B := Real.exp_nonneg _have hbi : Integrable ρ μ₁ := Integrable.of_bound hρ.aestronglyMeasurable B(ae_of_all _ (fun x => by simpa [Real.norm_eq_abs, abs_of_nonneg (h0 x)] using hb x))let Y (n : ℤ) (x : ℝ) := ENNReal.ofReal ‖shift (modρ ρ n) 0 1 J x‖let Z (n : ℕ) (x : ℝ) := ⨆ i : ℤ, ⨆ (_h : i.natAbs ≤ n), Y i xhave hYm (n : ℤ) : Measurable (Y n) :=(show Measurable (fun x => shift (modρ ρ n) 0 1 J x)from measurable_shift_comp (measurable_mod hρ _) measurable_const measurable_const measurable_id J)|>.norm.ennreal_ofRealhave hZm (n : ℕ) : Measurable (Z n) :=Measurable.iSup fun i => Measurable.iSup fun (_ : i.natAbs ≤ n) => hYm ihave hZo : Monotone Z := fun n m h x => iSup_le fun i => iSup_le fun hi =>le_iSup₂ (f := fun i (_h : i.natAbs ≤ m) => Y i x) i (le_trans hi h)have hZ (x : ℝ) : maxShift ρ 0 1 J x ≤ ⨆ n, Z n x := byrefine iSup_le fun i =>(le_iSup₂ (f := fun l : ℤ => fun (_ : l.natAbs ≤ i.natAbs) => Y l x) i le_rfl).trans(le_iSup (fun n => Z n x) i.natAbs)refine (lintegral_mono hZ).trans ?_rw [lintegral_iSup hZm hZo]refine iSup_le fun n => ?_let S := ∑ m ∈ Finset.range J, (2:ℝ)^mhave ht : Tendsto (fun M => S*(B*(n:ℝ)*(2*π))*side M) atTop (𝓝 0) := byhave hs : Tendsto side atTop (𝓝 0) := tendsto_pow_atTop_nhds_zero_of_lt_one(by norm_num) (by norm_num)simpa only [mul_zero] using hs.const_mul (S*(B*(n:ℝ)*(2*π)))obtain ⟨M,hM,hMJ,hMt⟩ := ((hj J).and((eventually_ge_atTop (J+1)).and (ht.eventually (gt_mem_nhds (show (0:ℝ)<1 by norm_num))))).existschange _ < (1:ℝ) at hMtobtain ⟨W,hW,hWm,hWe⟩ :=hM (liftGrid M ρ) (fun y => (lift_bounds hbi h0 B hb y).1) (by rwa [expU_liftGrid M ρ hbi])(fun y => (lift_bounds hbi h0 B hb y).2)have Hx (y : Grid M) (x : ℝ) (hx : x ∈ atom y) (hxg : x ∈ G) :Z n x ≤ ENNReal.ofReal (W y + 1) := byrefine iSup_le fun (i : ℤ) => iSup_le fun hi => ?_have hw := hWe y (usable_transfer hbi _ (by omega) (hD x hxg) hx) (i:Grid M)let f := liftGrid M (modρ ρ (i:ℝ))have hh := FinShift_error (B*|(i:ℝ)| * (2*π)*side M) (lift_mod_error M hρ h0 B hb i)(show J ≤ M by omega) ychange ‖FinShift J f y - _‖ ≤ S*_ at hhhave Hlem : |(i:ℝ)| ≤ (n:ℝ) := by rw [abs_le]; constructor <;> exact_mod_cast (by omega)have hlim : S*(B*|(i:ℝ)| * (2*π)*side M) ≤ 1 := bycalc_ ≤ S*(B*(n:ℝ)*(2*π)*side M) := byhave h := side_pos Mhave : 0 ≤ S := Finset.sum_nonneg (fun _ _ => by positivity)gcongr_ ≤ 1 := by linarithchange ENNReal.ofReal _ ≤ _apply ENNReal.ofReal_le_ofRealhave hfi (x : ℝ) : ‖modρ ρ i x‖ ≤ B := by rw [norm_mod h0]; exact hb _rw [← lift_shift J hMJ _ (measurable_mod hρ _) B hfi hx]have HE := norm_sub_norm_le (FinShift J f y) (FinShift J (finMod (liftGrid M ρ) (i:Grid M)) y)change ‖FinShift J f y‖ ≤ W y + 1linarithlet V := G.indicator (Z n)have HV : (∫⁻ x in G, Z n x) = ∫⁻ x in unitInt, V x := byunfold Vrw [lintegral_indicator hG, Measure.restrict_restrict hG, inter_eq_left.mpr hGu]rw [HV, atom_partition M, lintegral_iUnion atom_measurable atom_disjoint, tsum_fintype]have Hv (y : Grid M) :(∫⁻ x in atom y, V x) ≤ ENNReal.ofReal ((W y+1)*side M) := bycalc_ ≤ ∫⁻ _ in atom y, ENNReal.ofReal (W y+1) := byapply lintegral_mono_aefilter_upwards [ae_restrict_mem (atom_measurable y)] with x hxby_cases H : x ∈ G· simpa [V,H] using Hx y x hx H· simp [V,H]_ = _ := by rw [setLIntegral_const, atom_volume,ENNReal.ofReal_mul (by linarith [hW y] : 0 ≤ W y+1)]refine (Finset.sum_le_sum (fun y _ => Hv y)).trans ?_rw [← ENNReal.ofReal_sum_of_nonneg]· apply ENNReal.ofReal_le_ofRealcalc∑ y, _ = expU (fun y => W y + 1) := by simp only [expU,smul_eq_mul,← Finset.sum_mul]; ring_ ≤ C*(2:ℝ)^j+1 := by rw [expU_add_one M W]; linarith_ ≤ _ := by linarith [one_le_pow₀ (by norm_num : (1:ℝ) ≤ 2) (n:=j)]· intro y _; have := side_pos M; have := hW y; positivityendend FourierLLogL.Dyadicend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232import OAI.Analysis.FourierLLogL.Dyadic.Circle/-! # Finite dyadic blocks and probabilities -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugate Realnoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Period Lawnamespace Nodevariable {M : ℕ}def invlen (p : Node) : ℝ := 2^p.levlemma rinv (p : Node) : invlen p = p.len⁻¹ := by rw [len,side_pow_two,inv_inv]; rfllemma invlen_ge (p : Node) : 1 ≤ invlen p := one_le_pow₀ (by norm_num)lemma invlen_pos (p : Node) : 0 < invlen p := lt_of_lt_of_le zero_lt_one p.invlen_gelemma descale {p : Node} (h : p.lev ≤ M) :p.len = side M * (2:ℝ)^(M-p.lev) := byrw [len,side_pow_two,side_pow_two]conv_rhs => lhs; rw [show M=p.lev+(M-p.lev) by omega]rw [pow_add]; field_simplemma mem_block_iff {p : Node} (h : p.lev ≤ M) (x : Grid M) :x ∈ p.block M ↔ p.ix*2^(M-p.lev) ≤ x.val ∧ x.val < (p.ix+1)*2^(M-p.lev) := bychange p.a ≤ pos x ∧ _ < p.a+p.len ↔ _have he (i : ℕ) : (i:ℝ)*p.len = (i*2^(M-p.lev) : ℕ) * side M := byrw [descale h]; push_cast; ringunfold a posrw [show p.ix*p.len+p.len=↑(p.ix+1)*p.len by push_cast; ring, he,he,mul_le_mul_iff_left₀ (side_pos _),mul_lt_mul_iff_left₀ (side_pos _)]norm_cast/-- First grid index in a fitting node. -/def idx (p : Node) (M : ℕ) := p.ix * 2^(M-p.lev)def wid (p : Node) (M : ℕ) := 2^(M-p.lev)lemma fitting (p : Node) (hv : p.valid) (h : p.lev ≤ M) :p.idx M+p.wid M ≤ 2^M := byunfold idx widcalc_ = (p.ix+1)*2^(M-p.lev) := by ring_ ≤ 2^p.lev*2^(M-p.lev) := Nat.mul_le_mul_right _ hv_ = _ := by rw [← pow_add]; congr 1; omegalemma wid_pos (p : Node) (M : ℕ) : 0 < p.wid M := pow_pos (by omega) _def start (p : Node) (M : ℕ) : Grid M := (p.idx M : Grid M)lemma start_val {p : Node} (hv : p.valid) (h : p.lev ≤ M) :(p.start M).val = p.idx M := byapply ZMod.val_natCast_of_lthave HH := p.fitting hv hhave HH' := p.wid_pos Momegalemma start_pos {p : Node} (hv : p.valid) (h : p.lev ≤ M) :pos (p.start M) = p.a := byrw [pos, start_val hv h,a,descale h]unfold idx; push_cast; ringlemma start_mem {p : Node} (hv : p.valid) (h : p.lev ≤ M) :p.start M ∈ p.block M := byrw [mem_block_iff h,start_val hv h]unfold idxconstructor· exact le_rfl· gcongr; omegaopen scoped Classical/-- Finset of vertices. -/def group (p : Node) (M : ℕ) := (p.block M).toFinsetlemma mem_group (p : Node) (x : Grid M) : x ∈ p.group M ↔ x ∈ p.block M := by simp [group]lemma group_range {p : Node} (h : p.lev ≤ M) :p.group M = first M (p.idx M+p.wid M) \ first M (p.idx M) := byext i; simp only [mem_group, Finset.mem_sdiff, mem_first, mem_block_iff h]unfold idx wid; rw [add_mul,one_mul]; omegalemma group_card {p : Node} (hv : p.valid) (h : p.lev ≤ M) :(p.group M).card = p.wid M := byhave hh := p.fitting hv hrw [group_range h,Finset.card_sdiff_of_subset ?sub,first_card _ hh,first_card _ (by omega)]· omegacase sub =>intro x hxsimp_rw [mem_first] at *omegalemma group_size {p : Node} (hv : p.valid) (h : p.lev ≤ M) :(p.group M).card * side M = p.len := byrw [group_card hv h,descale h]unfold wid; push_cast; ringlemma block_separate (p : Node) (M : ℕ) :Disjoint (p.L.block M) (p.R.block M) := byrefine Set.disjoint_left.mpr fun x hx hy => ?_exact Set.disjoint_left.mp (cells_dis (k:=p.ix*2) (l:=p.ix*2+1) (by omega)(n:=p.lev+1)) hx hylemma block_union (p : Node) (M : ℕ) :p.block M = p.L.block M ∪ p.R.block M := by rw [block,p.cells_split]; rfllemma group_dis (p : Node) (M : ℕ) :Disjoint (p.L.group M) (p.R.group M) :=Finset.disjoint_left.mpr fun _ hx hy => Set.disjoint_left.mp (p.block_separate _)((mem_group _ _).mp hx) ((mem_group _ _).mp hy)lemma group_union (p : Node) (M : ℕ) :p.group M = p.L.group M ∪ p.R.group M := by ext x; simp only [Finset.mem_union,mem_group]; rw [p.block_union]; rfldef ok (p : Node) (M : ℕ) : Prop := p.valid ∧ p.lev ≤ Mlemma root_ok (M : ℕ) : ok root M := by simp [ok,valid,root]lemma len_top : root.len = 1 := by simp [len,root,side]lemma invlen_top : root.invlen = 1 := by simp [invlen,root]lemma group_top (M : ℕ) : root.group M = Finset.univ := byext x; rw [mem_group,mem_block_iff (root_ok M).2]simp only [root, Nat.zero_mul, Nat.zero_le, true_and, zero_add,one_mul,Nat.sub_zero]simp [ZMod.val_lt]open scoped Classical/-- Local averages as sums. -/lemma avg_sum {E : Type*} [AddCommMonoid E] [SMul ℝ E] (p : Node)(f : Grid M → E) :p.avg f = p.len⁻¹ • (side M • ∑ x ∈ p.group M, f x) := byunfold avg expUcongr 2calc_ = ∑ x ∈ p.group M, (p.block M).indicator f x := byrefine (Finset.sum_subset (Finset.subset_univ _) ?_).symmintro i _ hiapply Set.indicator_of_notMem ((mem_group _ _).not.mp hi) f_ = _ := Finset.sum_congr rfl fun i hi => Set.indicator_of_mem ((mem_group _ _).mp hi) flemma avg_nonneg (p : Node) {f : Grid M → ℝ} (h : ∀ x, x∈p.block M → 0 ≤ f x) :0 ≤ p.avg f := byrw [avg_sum, smul_eq_mul, smul_eq_mul]exact mul_nonneg (inv_nonneg.mpr p.len_pos.le) <| mul_nonneg (side_pos _).le(Finset.sum_nonneg fun i hi => h _ ((mem_group _ _).mp hi))lemma avg_split_real (p : Node) (f : Grid M → ℝ) :p.avg f = (p.L.avg f+p.R.avg f)/2 := byrw [avg_sum,avg_sum,avg_sum,p.group_union,Finset.sum_union (p.group_dis M),p.len_L,p.len_R]; simp; ringlemma avg_split_complex (p : Node) (f : Grid M → ℂ) :p.avg f = (p.L.avg f+p.R.avg f)/2 := byrw [avg_sum,avg_sum,avg_sum,p.group_union,Finset.sum_union (p.group_dis M),p.len_L,p.len_R]simp_rw [Complex.real_smul]; push_cast; ring_nf/-- Uniform conditional law on a block (total default law if not fitting). -/def dice (p : Node) (M : ℕ) : Law (Grid M) := (uniform _).condP fun x => x ∈ p.block Mlemma prob_block {p : Node} (h : p.ok M) :(uniform (Grid M)).prob (fun x => x∈p.block M) = p.len := byrw [prob_eq]have He : Finset.univ.filter (fun x : Grid M => x∈p.block M)=p.group M := byext x; simp [mem_group]rw [← Finset.sum_filter, He]simp_rw [uniform_side,Finset.sum_const,nsmul_eq_mul,group_size h.1 h.2]lemma dice_apply {p : Node} (h : p.ok M) (x : Grid M) :p.dice M x = if x∈p.block M then side M * p.len⁻¹ else 0 := byunfold dicerw [condP_pos_apply _ _ (by rw [prob_block h]; exact p.len_pos),prob_block h,uniform_side]split_ifs <;> simp [div_eq_mul_inv]lemma dice_positive {p : Node} (h : p.ok M) {x : Grid M} :0 < p.dice M x ↔ x ∈ p.block M := byrw [dice_apply h]; split_ifs with hh· exact iff_of_true (mul_pos (side_pos _) (inv_pos.mpr p.len_pos)) hh· simp [hh]lemma avg_ex {p : Node} (h : p.ok M) (f : Grid M → ℝ) :p.avg f = (p.dice M).Ex f := bysimp_rw [avg,smul_eq_mul,expU_ex,Ex,dice_apply h,uniform_side,Finset.mul_sum]refine Finset.sum_congr rfl fun i _ => ?_split_ifs with hi· rw [Set.indicator_of_mem hi]; ringrw [Set.indicator_of_notMem hi]; ringlemma avg_cx {p : Node} (h : p.ok M) (f : Grid M → ℂ) :p.avg f = (p.dice M).Cx f := bysimp_rw [avg,Complex.real_smul,expU_cx,Cx,dice_apply h,uniform_side,Finset.mul_sum]refine Finset.sum_congr rfl fun i _ => ?_split_ifs with hi· rw [Set.indicator_of_mem hi]; push_cast; ringrw [Set.indicator_of_notMem hi]; push_cast; ringlemma dice_child (p : Node) (hv : p.valid) (h : p.lev < M) (f : Grid M → ℝ) :(p.dice M).Ex f = ((p.L.dice M).Ex f + (p.R.dice M).Ex f)/2 := byhave H : ok p M := ⟨hv,h.le⟩have H1 : ok p.L M := ⟨p.valid_L.mpr hv,h⟩have H2 : ok p.R M := ⟨p.valid_R.mpr hv,h⟩rw [← avg_ex H,← avg_ex H1,← avg_ex H2]exact p.avg_split_real _/-- Called branching. -/def below (p q : Node) : Prop := p.lev ≥ q.lev ∧ p.cells ⊆ q.cellslemma below_left (p : Node) : p.L.below p := byrefine ⟨Nat.le_add_right _ 1,?_⟩rw [cells_split p]; exact subset_union_leftlemma below_right (p : Node) : p.R.below p := byrefine ⟨Nat.le_add_right _ 1,?_⟩rw [cells_split p]; exact subset_union_rightlemma below_refl (p : Node) : p.below p := ⟨le_rfl,Subset.rfl⟩lemma below_trans {p q r : Node} (h : p.below q) (h' : q.below r) : p.below r :=⟨h'.1.trans h.1,h.2.trans h'.2⟩lemma block_of_below {p q : Node} (h : p.below q) (M : ℕ) : p.block M ⊆ q.block M :=Set.preimage_mono h.2lemma scale_below {p q : Node} (h : p.below q) : q.invlen ≤ p.invlen :=pow_le_pow_right₀ (by norm_num) h.1lemma diam_block {p : Node} {x y : Grid M} (hx : x ∈ p.block M) (hy : y ∈ p.block M) :|pos x-pos y| ≤ p.len := by rw [abs_le]; constructor <;> linarith [hx.1,hx.2,hy.1,hy.2]end Nodeend FourierLLogL.Dyadicend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232import OAI.Analysis.FourierLLogL.Dyadic.Circle/-! # Finite dyadic blocks and probabilities -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugate Realnoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Period Lawnamespace Nodevariable {M : ℕ}def invlen (p : Node) : ℝ := 2^p.levlemma rinv (p : Node) : invlen p = p.len⁻¹ := by rw [len,side_pow_two,inv_inv]; rfllemma invlen_ge (p : Node) : 1 ≤ invlen p := one_le_pow₀ (by norm_num)lemma invlen_pos (p : Node) : 0 < invlen p := lt_of_lt_of_le zero_lt_one p.invlen_gelemma descale {p : Node} (h : p.lev ≤ M) :p.len = side M * (2:ℝ)^(M-p.lev) := byrw [len,side_pow_two,side_pow_two]conv_rhs => lhs; rw [show M=p.lev+(M-p.lev) by omega]rw [pow_add]; field_simplemma mem_block_iff {p : Node} (h : p.lev ≤ M) (x : Grid M) :x ∈ p.block M ↔ p.ix*2^(M-p.lev) ≤ x.val ∧ x.val < (p.ix+1)*2^(M-p.lev) := bychange p.a ≤ pos x ∧ _ < p.a+p.len ↔ _have he (i : ℕ) : (i:ℝ)*p.len = (i*2^(M-p.lev) : ℕ) * side M := byrw [descale h]; push_cast; ringunfold a posrw [show p.ix*p.len+p.len=↑(p.ix+1)*p.len by push_cast; ring, he,he,mul_le_mul_iff_left₀ (side_pos _),mul_lt_mul_iff_left₀ (side_pos _)]norm_cast/-- First grid index in a fitting node. -/def idx (p : Node) (M : ℕ) := p.ix * 2^(M-p.lev)def wid (p : Node) (M : ℕ) := 2^(M-p.lev)lemma fitting (p : Node) (hv : p.valid) (h : p.lev ≤ M) :p.idx M+p.wid M ≤ 2^M := byunfold idx widcalc_ = (p.ix+1)*2^(M-p.lev) := by ring_ ≤ 2^p.lev*2^(M-p.lev) := Nat.mul_le_mul_right _ hv_ = _ := by rw [← pow_add]; congr 1; omegalemma wid_pos (p : Node) (M : ℕ) : 0 < p.wid M := pow_pos (by omega) _def start (p : Node) (M : ℕ) : Grid M := (p.idx M : Grid M)lemma start_val {p : Node} (hv : p.valid) (h : p.lev ≤ M) :(p.start M).val = p.idx M := byapply ZMod.val_natCast_of_lthave HH := p.fitting hv hhave HH' := p.wid_pos Momegalemma start_pos {p : Node} (hv : p.valid) (h : p.lev ≤ M) :pos (p.start M) = p.a := byrw [pos, start_val hv h,a,descale h]unfold idx; push_cast; ringlemma start_mem {p : Node} (hv : p.valid) (h : p.lev ≤ M) :p.start M ∈ p.block M := byrw [mem_block_iff h,start_val hv h]unfold idxconstructor· exact le_rfl· gcongr; omegaopen scoped Classical/-- Finset of vertices. -/def group (p : Node) (M : ℕ) := (p.block M).toFinsetlemma mem_group (p : Node) (x : Grid M) : x ∈ p.group M ↔ x ∈ p.block M := by simp [group]lemma group_range {p : Node} (h : p.lev ≤ M) :p.group M = first M (p.idx M+p.wid M) \ first M (p.idx M) := byext i; simp only [mem_group, Finset.mem_sdiff, mem_first, mem_block_iff h]unfold idx wid; rw [add_mul,one_mul]; omegalemma group_card {p : Node} (hv : p.valid) (h : p.lev ≤ M) :(p.group M).card = p.wid M := byhave hh := p.fitting hv hrw [group_range h,Finset.card_sdiff_of_subset ?sub,first_card _ hh,first_card _ (by omega)]· omegacase sub =>intro x hxsimp_rw [mem_first] at *omegalemma group_size {p : Node} (hv : p.valid) (h : p.lev ≤ M) :(p.group M).card * side M = p.len := byrw [group_card hv h,descale h]unfold wid; push_cast; ringlemma block_separate (p : Node) (M : ℕ) :Disjoint (p.L.block M) (p.R.block M) := byrefine Set.disjoint_left.mpr fun x hx hy => ?_exact Set.disjoint_left.mp (cells_dis (k:=p.ix*2) (l:=p.ix*2+1) (by omega)(n:=p.lev+1)) hx hylemma block_union (p : Node) (M : ℕ) :p.block M = p.L.block M ∪ p.R.block M := by rw [block,p.cells_split]; rfllemma group_dis (p : Node) (M : ℕ) :Disjoint (p.L.group M) (p.R.group M) :=Finset.disjoint_left.mpr fun _ hx hy => Set.disjoint_left.mp (p.block_separate _)((mem_group _ _).mp hx) ((mem_group _ _).mp hy)lemma group_union (p : Node) (M : ℕ) :p.group M = p.L.group M ∪ p.R.group M := by ext x; simp only [Finset.mem_union,mem_group]; rw [p.block_union]; rfldef ok (p : Node) (M : ℕ) : Prop := p.valid ∧ p.lev ≤ Mlemma root_ok (M : ℕ) : ok root M := by simp [ok,valid,root]lemma len_top : root.len = 1 := by simp [len,root,side]lemma invlen_top : root.invlen = 1 := by simp [invlen,root]lemma group_top (M : ℕ) : root.group M = Finset.univ := byext x; rw [mem_group,mem_block_iff (root_ok M).2]simp only [root, Nat.zero_mul, Nat.zero_le, true_and, zero_add,one_mul,Nat.sub_zero]simp [ZMod.val_lt]open scoped Classical/-- Local averages as sums. -/lemma avg_sum {E : Type*} [AddCommMonoid E] [SMul ℝ E] (p : Node)(f : Grid M → E) :p.avg f = p.len⁻¹ • (side M • ∑ x ∈ p.group M, f x) := byunfold avg expUcongr 2calc_ = ∑ x ∈ p.group M, (p.block M).indicator f x := byrefine (Finset.sum_subset (Finset.subset_univ _) ?_).symmintro i _ hiapply Set.indicator_of_notMem ((mem_group _ _).not.mp hi) f_ = _ := Finset.sum_congr rfl fun i hi => Set.indicator_of_mem ((mem_group _ _).mp hi) flemma avg_nonneg (p : Node) {f : Grid M → ℝ} (h : ∀ x, x∈p.block M → 0 ≤ f x) :0 ≤ p.avg f := byrw [avg_sum, smul_eq_mul, smul_eq_mul]exact mul_nonneg (inv_nonneg.mpr p.len_pos.le) <| mul_nonneg (side_pos _).le(Finset.sum_nonneg fun i hi => h _ ((mem_group _ _).mp hi))lemma avg_split_real (p : Node) (f : Grid M → ℝ) :p.avg f = (p.L.avg f+p.R.avg f)/2 := byrw [avg_sum,avg_sum,avg_sum,p.group_union,Finset.sum_union (p.group_dis M),p.len_L,p.len_R]; simp; ringlemma avg_split_complex (p : Node) (f : Grid M → ℂ) :p.avg f = (p.L.avg f+p.R.avg f)/2 := byrw [avg_sum,avg_sum,avg_sum,p.group_union,Finset.sum_union (p.group_dis M),p.len_L,p.len_R]simp_rw [Complex.real_smul]; push_cast; ring_nf/-- Uniform conditional law on a block (total default law if not fitting). -/def dice (p : Node) (M : ℕ) : Law (Grid M) := (uniform _).condP fun x => x ∈ p.block Mlemma prob_block {p : Node} (h : p.ok M) :(uniform (Grid M)).prob (fun x => x∈p.block M) = p.len := byrw [prob_eq]have He : Finset.univ.filter (fun x : Grid M => x∈p.block M)=p.group M := byext x; simp [mem_group]rw [← Finset.sum_filter, He]simp_rw [uniform_side,Finset.sum_const,nsmul_eq_mul,group_size h.1 h.2]lemma dice_apply {p : Node} (h : p.ok M) (x : Grid M) :p.dice M x = if x∈p.block M then side M * p.len⁻¹ else 0 := byunfold dicerw [condP_pos_apply _ _ (by rw [prob_block h]; exact p.len_pos),prob_block h,uniform_side]split_ifs <;> simp [div_eq_mul_inv]lemma dice_positive {p : Node} (h : p.ok M) {x : Grid M} :0 < p.dice M x ↔ x ∈ p.block M := byrw [dice_apply h]; split_ifs with hh· exact iff_of_true (mul_pos (side_pos _) (inv_pos.mpr p.len_pos)) hh· simp [hh]lemma avg_ex {p : Node} (h : p.ok M) (f : Grid M → ℝ) :p.avg f = (p.dice M).Ex f := bysimp_rw [avg,smul_eq_mul,expU_ex,Ex,dice_apply h,uniform_side,Finset.mul_sum]refine Finset.sum_congr rfl fun i _ => ?_split_ifs with hi· rw [Set.indicator_of_mem hi]; ringrw [Set.indicator_of_notMem hi]; ringlemma avg_cx {p : Node} (h : p.ok M) (f : Grid M → ℂ) :p.avg f = (p.dice M).Cx f := bysimp_rw [avg,Complex.real_smul,expU_cx,Cx,dice_apply h,uniform_side,Finset.mul_sum]refine Finset.sum_congr rfl fun i _ => ?_split_ifs with hi· rw [Set.indicator_of_mem hi]; push_cast; ringrw [Set.indicator_of_notMem hi]; push_cast; ringlemma dice_child (p : Node) (hv : p.valid) (h : p.lev < M) (f : Grid M → ℝ) :(p.dice M).Ex f = ((p.L.dice M).Ex f + (p.R.dice M).Ex f)/2 := byhave H : ok p M := ⟨hv,h.le⟩have H1 : ok p.L M := ⟨p.valid_L.mpr hv,h⟩have H2 : ok p.R M := ⟨p.valid_R.mpr hv,h⟩rw [← avg_ex H,← avg_ex H1,← avg_ex H2]exact p.avg_split_real _/-- Called branching. -/def below (p q : Node) : Prop := p.lev ≥ q.lev ∧ p.cells ⊆ q.cellslemma below_left (p : Node) : p.L.below p := byrefine ⟨Nat.le_add_right _ 1,?_⟩rw [cells_split p]; exact subset_union_leftlemma below_right (p : Node) : p.R.below p := byrefine ⟨Nat.le_add_right _ 1,?_⟩rw [cells_split p]; exact subset_union_rightlemma below_refl (p : Node) : p.below p := ⟨le_rfl,Subset.rfl⟩lemma below_trans {p q r : Node} (h : p.below q) (h' : q.below r) : p.below r :=⟨h'.1.trans h.1,h.2.trans h'.2⟩lemma block_of_below {p q : Node} (h : p.below q) (M : ℕ) : p.block M ⊆ q.block M :=Set.preimage_mono h.2lemma scale_below {p q : Node} (h : p.below q) : q.invlen ≤ p.invlen :=pow_le_pow_right₀ (by norm_num) h.1lemma diam_block {p : Node} {x y : Grid M} (hx : x ∈ p.block M) (hy : y ∈ p.block M) :|pos x-pos y| ≤ p.len := by rw [abs_le]; constructor <;> linarith [hx.1,hx.2,hy.1,hy.2]end Nodeend FourierLLogL.Dyadicend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163import OAI.Analysis.FourierLLogL.Dyadic.Node/-! # Subgrids, snapping and projecting -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugate Realnoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Node Period Realvariable {M l : ℕ}private def times_step (l M : ℕ) : ℤ →+ Grid M wheretoFun x := ↑((2^(M-l):ℕ)*(x:ℤ))map_zero' := by simpmap_add' x y := by push_cast; ring/-- Mesh 2^(M-l) in multiples. -/def raise (h : l ≤ M) : Grid l →+ Grid M :=ZMod.lift (2^l) ⟨times_step l M,bychange (((↑(2^(M-l):ℕ):ℤ) * ↑(2^l:ℕ) : ℤ):Grid M)=0rw [← Nat.cast_mul,← pow_add,show M-l+l=M by omega]rw [Int.cast_natCast,ZMod.natCast_self]⟩def cut (h : l ≤ M) : Grid M →+* Grid l :=ZMod.castHom (pow_dvd_pow _ h) _lemma cut_natCast (h : l ≤ M) (k : ℕ) :cut h (k:Grid M) = (k:Grid l) := map_natCast _ _lemma cut_val (h : l ≤ M) (x : Grid M) :cut h x = (x.val:Grid l) := by rw [← cut_natCast h,ZMod.natCast_zmod_val]lemma cut_mod (h : l ≤ M) (x : Grid M) :(cut h x).val = x.val % 2^l := by rw [cut_val,ZMod.val_natCast]lemma raise_cast (h : l ≤ M) (x : ℕ) :raise h (x : Grid l) = (↑(2^(M-l)*x:ℕ):Grid M) := byhave H : ∀ k : ℤ, raise h (k:Grid l) = times_step l M k := fun k => ZMod.lift_coe _ _ _convert H x using 1 <;> simp [times_step]lemma raise_eq (h : l ≤ M) (x : Grid l) :raise h x = ↑(2^(M-l)*x.val:ℕ) := by rw [← raise_cast h,ZMod.natCast_zmod_val]lemma raise_val (h : l ≤ M) (x : Grid l) :(raise h x).val = 2^(M-l)*x.val := byrw [raise_eq,ZMod.val_natCast_of_lt]calc_ < 2^(M-l)*2^l := Nat.mul_lt_mul_of_pos_left (ZMod.val_lt _) (by positivity)_ = _ := by rw [← pow_add]; congr 1; omegalemma raise_inj (h : l ≤ M) : Injective (raise h) := byintro x y heapply ZMod.val_injective _have H := congrArg ZMod.val hesimp only [raise_val] at Hexact mul_left_cancel₀ (by positivity) Hlemma raised_pos (h : l ≤ M) (i : Grid l) : pos (raise h i) = pos i := bysimp only [pos,raise_val]have heq : side l = side M*(2:ℝ)^(M-l) := descale (p:=⟨l,0⟩) hrw [heq]; push_cast; ringlemma cut_chi (h : l ≤ M) (i : Grid l) (x : Grid M) :chi (raise h i) x = chi i (cut h x) := byrw [cut_val,chi_comm i _,chi_comm (raise h i) x]have heq (x : ℕ) : chi (x:Grid M) (raise h i) = chi (x:Grid l) i := byhave H := chi_cast (x:ℤ) (raise h i)have hh := chi_cast (x:ℤ) irw [raised_pos] at Hsimpa only [Int.cast_natCast] using H.trans hh.symmrw [← heq, ZMod.natCast_zmod_val x]lemma annihilator (h : l ≤ M) (u : Grid M) :cut (show M-l ≤ M by omega) u = 0 ↔ ∃ i, raise h i = u := bylet p := cut (show M-l ≤ M by omega)have he (u : Grid M) : p u = 0 ↔ 2^(M-l) ∣ u.val := byrw [← (ZMod.val_injective (2^(M-l))).eq_iff]simp only [p,cut_mod,ZMod.val_zero,Nat.dvd_iff_mod_eq_zero]constructor· intro huobtain ⟨i,hi⟩ := (he _).mp hurefine ⟨(i:Grid l),?_⟩rw [raise_cast,← hi,ZMod.natCast_zmod_val]rintro ⟨i,rfl⟩exact (he _).mpr (by rw [raise_val]; simp)/-- A snap (rounding down). -/def down (_h : l ≤ M) (u : Grid M) : Grid l :=↑(u.val / 2^(M-l))lemma raise_down (h : l ≤ M) (u : Grid M) :u - raise h (down h u) = (↑(u.val % 2^(M-l)):Grid M) := byhave hh := Nat.mod_add_div u.val (2^(M-l))unfold down; rw [raise_cast]apply sub_eq_iff_eq_add.mpr; rw [← Nat.cast_add,hh,ZMod.natCast_zmod_val]lemma snap_dist (h : l ≤ M) (u : Grid M) :rad (u-raise h (down h u)) ≤ 2^(M-l)-1 := byrw [raise_down]apply le_trans (rad_le_nat _)have H : u.val % 2^(M-l) +1 ≤ 2^(M-l) := Nat.mod_lt _ (by positivity)apply le_sub_iff_add_le.mprexact_mod_cast Hlemma cut_injOn {p : Node} (h : l ≤ M) (hp : p.lev ≤ M) (hh : M-l ≤ p.lev) :InjOn (cut h) (p.block M) := byintro x hx y hy hxyapply ZMod.val_injective _have HE := congrArg ZMod.val hxysimp only [cut_mod] at HErw [mem_block_iff hp x] at hx; rw [mem_block_iff hp y] at hylet a := 2^(M-p.lev)let b := 2^llet i := p.ixchange i*a ≤ _ ∧ _ < (i+1)*a at hx hyrw [add_mul,one_mul] at hx hyhave h1 := Nat.mod_add_div x.val bhave h2 := Nat.mod_add_div y.val bhave hi : a ≤ b := Nat.pow_le_pow_right (by omega) (by omega)change _ % b = _ % b at HEhave h3 : x.val/b=y.val/b := byby_contra! hercases lt_or_gt_of_ne he with H|H· have Hx : b*(x.val/b +1) ≤ b*(y.val/b) := Nat.mul_le_mul_left b Hrw [mul_add,mul_one] at Hx; omega· have Hx : b*(y.val/b +1) ≤ b*(x.val/b) := Nat.mul_le_mul_left b Hrw [mul_add,mul_one] at Hx; omegarw [HE,h3,h2] at h1; exact h1.symm/-- Projection density bound for any input sublaw on p. -/lemma cut_send {p : Node} (h : l ≤ M) (hp : p.ok M) (hh : M-l ≤ p.lev)(P : Law (Grid M)) (a : ℝ) (ha : 0 ≤ a)(H : ∀ x, P x ≤ a*p.dice M x) (i : Grid l) :P.send (cut h) i ≤ a*p.invlen*side M := byclassicalrcases eq_or_lt_of_le ((P.send (cut h)).nonneg i) with H0|H0· rw [← H0]have := p.invlen_pos; have := side_pos M; positivityobtain ⟨x,hx,hx'⟩ := (P.send_pos_iff _ _).mp H0have he {x : Grid M} (hh : 0 < P x) : x∈p.block M := byhave H := lt_of_lt_of_le hh (H x)rw [dice_apply hp] at Hby_contra h'rw [ite_eq_right h',mul_zero] at Hexact lt_irrefl _ Hrw [send_apply, prob_eq]have HX := H xrw [dice_apply hp,ite_eq_left (he hx'), p.rinv] at *rw [Finset.sum_eq_single x,ite_eq_left hx,mul_right_comm]· nlinarith· intro j _ hj; split_ifs with hi· by_contra hh'have h2 : j∈p.block M := he ((P.nonneg j).lt_of_ne (Ne.symm hh'))exact hj (cut_injOn h hp.2 hh h2 (he hx') (hi.trans hx.symm))rflsimpend FourierLLogL.Dyadicend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163import OAI.Analysis.FourierLLogL.Dyadic.Node/-! # Subgrids, snapping and projecting -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugate Realnoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Node Period Realvariable {M l : ℕ}private def times_step (l M : ℕ) : ℤ →+ Grid M wheretoFun x := ↑((2^(M-l):ℕ)*(x:ℤ))map_zero' := by simpmap_add' x y := by push_cast; ring/-- Mesh 2^(M-l) in multiples. -/def raise (h : l ≤ M) : Grid l →+ Grid M :=ZMod.lift (2^l) ⟨times_step l M,bychange (((↑(2^(M-l):ℕ):ℤ) * ↑(2^l:ℕ) : ℤ):Grid M)=0rw [← Nat.cast_mul,← pow_add,show M-l+l=M by omega]rw [Int.cast_natCast,ZMod.natCast_self]⟩def cut (h : l ≤ M) : Grid M →+* Grid l :=ZMod.castHom (pow_dvd_pow _ h) _lemma cut_natCast (h : l ≤ M) (k : ℕ) :cut h (k:Grid M) = (k:Grid l) := map_natCast _ _lemma cut_val (h : l ≤ M) (x : Grid M) :cut h x = (x.val:Grid l) := by rw [← cut_natCast h,ZMod.natCast_zmod_val]lemma cut_mod (h : l ≤ M) (x : Grid M) :(cut h x).val = x.val % 2^l := by rw [cut_val,ZMod.val_natCast]lemma raise_cast (h : l ≤ M) (x : ℕ) :raise h (x : Grid l) = (↑(2^(M-l)*x:ℕ):Grid M) := byhave H : ∀ k : ℤ, raise h (k:Grid l) = times_step l M k := fun k => ZMod.lift_coe _ _ _convert H x using 1 <;> simp [times_step]lemma raise_eq (h : l ≤ M) (x : Grid l) :raise h x = ↑(2^(M-l)*x.val:ℕ) := by rw [← raise_cast h,ZMod.natCast_zmod_val]lemma raise_val (h : l ≤ M) (x : Grid l) :(raise h x).val = 2^(M-l)*x.val := byrw [raise_eq,ZMod.val_natCast_of_lt]calc_ < 2^(M-l)*2^l := Nat.mul_lt_mul_of_pos_left (ZMod.val_lt _) (by positivity)_ = _ := by rw [← pow_add]; congr 1; omegalemma raise_inj (h : l ≤ M) : Injective (raise h) := byintro x y heapply ZMod.val_injective _have H := congrArg ZMod.val hesimp only [raise_val] at Hexact mul_left_cancel₀ (by positivity) Hlemma raised_pos (h : l ≤ M) (i : Grid l) : pos (raise h i) = pos i := bysimp only [pos,raise_val]have heq : side l = side M*(2:ℝ)^(M-l) := descale (p:=⟨l,0⟩) hrw [heq]; push_cast; ringlemma cut_chi (h : l ≤ M) (i : Grid l) (x : Grid M) :chi (raise h i) x = chi i (cut h x) := byrw [cut_val,chi_comm i _,chi_comm (raise h i) x]have heq (x : ℕ) : chi (x:Grid M) (raise h i) = chi (x:Grid l) i := byhave H := chi_cast (x:ℤ) (raise h i)have hh := chi_cast (x:ℤ) irw [raised_pos] at Hsimpa only [Int.cast_natCast] using H.trans hh.symmrw [← heq, ZMod.natCast_zmod_val x]lemma annihilator (h : l ≤ M) (u : Grid M) :cut (show M-l ≤ M by omega) u = 0 ↔ ∃ i, raise h i = u := bylet p := cut (show M-l ≤ M by omega)have he (u : Grid M) : p u = 0 ↔ 2^(M-l) ∣ u.val := byrw [← (ZMod.val_injective (2^(M-l))).eq_iff]simp only [p,cut_mod,ZMod.val_zero,Nat.dvd_iff_mod_eq_zero]constructor· intro huobtain ⟨i,hi⟩ := (he _).mp hurefine ⟨(i:Grid l),?_⟩rw [raise_cast,← hi,ZMod.natCast_zmod_val]rintro ⟨i,rfl⟩exact (he _).mpr (by rw [raise_val]; simp)/-- A snap (rounding down). -/def down (_h : l ≤ M) (u : Grid M) : Grid l :=↑(u.val / 2^(M-l))lemma raise_down (h : l ≤ M) (u : Grid M) :u - raise h (down h u) = (↑(u.val % 2^(M-l)):Grid M) := byhave hh := Nat.mod_add_div u.val (2^(M-l))unfold down; rw [raise_cast]apply sub_eq_iff_eq_add.mpr; rw [← Nat.cast_add,hh,ZMod.natCast_zmod_val]lemma snap_dist (h : l ≤ M) (u : Grid M) :rad (u-raise h (down h u)) ≤ 2^(M-l)-1 := byrw [raise_down]apply le_trans (rad_le_nat _)have H : u.val % 2^(M-l) +1 ≤ 2^(M-l) := Nat.mod_lt _ (by positivity)apply le_sub_iff_add_le.mprexact_mod_cast Hlemma cut_injOn {p : Node} (h : l ≤ M) (hp : p.lev ≤ M) (hh : M-l ≤ p.lev) :InjOn (cut h) (p.block M) := byintro x hx y hy hxyapply ZMod.val_injective _have HE := congrArg ZMod.val hxysimp only [cut_mod] at HErw [mem_block_iff hp x] at hx; rw [mem_block_iff hp y] at hylet a := 2^(M-p.lev)let b := 2^llet i := p.ixchange i*a ≤ _ ∧ _ < (i+1)*a at hx hyrw [add_mul,one_mul] at hx hyhave h1 := Nat.mod_add_div x.val bhave h2 := Nat.mod_add_div y.val bhave hi : a ≤ b := Nat.pow_le_pow_right (by omega) (by omega)change _ % b = _ % b at HEhave h3 : x.val/b=y.val/b := byby_contra! hercases lt_or_gt_of_ne he with H|H· have Hx : b*(x.val/b +1) ≤ b*(y.val/b) := Nat.mul_le_mul_left b Hrw [mul_add,mul_one] at Hx; omega· have Hx : b*(y.val/b +1) ≤ b*(x.val/b) := Nat.mul_le_mul_left b Hrw [mul_add,mul_one] at Hx; omegarw [HE,h3,h2] at h1; exact h1.symm/-- Projection density bound for any input sublaw on p. -/lemma cut_send {p : Node} (h : l ≤ M) (hp : p.ok M) (hh : M-l ≤ p.lev)(P : Law (Grid M)) (a : ℝ) (ha : 0 ≤ a)(H : ∀ x, P x ≤ a*p.dice M x) (i : Grid l) :P.send (cut h) i ≤ a*p.invlen*side M := byclassicalrcases eq_or_lt_of_le ((P.send (cut h)).nonneg i) with H0|H0· rw [← H0]have := p.invlen_pos; have := side_pos M; positivityobtain ⟨x,hx,hx'⟩ := (P.send_pos_iff _ _).mp H0have he {x : Grid M} (hh : 0 < P x) : x∈p.block M := byhave H := lt_of_lt_of_le hh (H x)rw [dice_apply hp] at Hby_contra h'rw [ite_eq_right h',mul_zero] at Hexact lt_irrefl _ Hrw [send_apply, prob_eq]have HX := H xrw [dice_apply hp,ite_eq_left (he hx'), p.rinv] at *rw [Finset.sum_eq_single x,ite_eq_left hx,mul_right_comm]· nlinarith· intro j _ hj; split_ifs with hi· by_contra hh'have h2 : j∈p.block M := he ((P.nonneg j).lt_of_ne (Ne.symm hh'))exact hj (cut_injOn h hp.2 hh h2 (he hx') (hi.trans hx.symm))rflsimpend FourierLLogL.Dyadicend OAI
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137import OAI.Analysis.FourierLLogL.Dyadic.Discrete/-! # Signed combination spans and Fourier support -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Period Realvariable {M : ℕ}def enclosed (s : Finset (Grid M)) (n : ℕ) (x : Grid M) : Prop :=∃ f : Grid M → ℤ, (∀ i∈s, |f i| ≤ n) ∧ ∑ i∈s, f i • i = xlemma enclosed_zero (s : Finset (Grid M)) (n : ℕ) : enclosed s n 0 :=⟨fun _ => 0,by simp,by simp⟩lemma enclosed_mem (s : Finset (Grid M)) {x : Grid M} (hx : x∈s) : enclosed s 1 x := byrefine ⟨fun i => if i=x then 1 else 0,fun i hi => ?_,?_⟩· dsimp only; split_ifs <;> norm_numsimp [ite_smul,hx]lemma enclosed_neg {s : Finset (Grid M)} {n : ℕ} {x : Grid M} (h : enclosed s n x) :enclosed s n (-x) := byobtain ⟨f,hf,rfl⟩ := hrefine ⟨fun i => -f i,fun i hi => ?_,?_⟩· simpa only [abs_neg] using hf i hisimplemma enclosed_add {s : Finset (Grid M)} {n m : ℕ} {x y : Grid M} (h : enclosed s n x)(h' : enclosed s m y) : enclosed s (n+m) (x+y) := byobtain ⟨f,hf,rfl⟩ := hobtain ⟨g,hg,rfl⟩ := h'refine ⟨fun i => f i + g i,fun i hi => ?_,?_⟩· rw [Nat.cast_add]exact (abs_add_le _ _).trans (add_le_add (hf _ hi) (hg _ hi))simp [add_smul,Finset.sum_add_distrib]lemma enclosed_insert {s : Finset (Grid M)} {i x : Grid M} (hi : i ∉ s){n : ℕ} (h : enclosed s n x) (j : ℤ) (hj : |j| ≤ n) :enclosed (insert i s) n (x+j•i) := byobtain ⟨f,hf,rfl⟩ := hrefine ⟨fun k => if k=i then j else f k,?_,?_⟩· intro k hkdsimp onlysplit_ifs with h· exact hj· exact hf _ ((Finset.mem_insert.mp hk).resolve_left h)· rw [Finset.sum_insert hi]; dsimp only; rw [ite_eq_left rfl,add_comm _ (j • i)]congr 1exact Finset.sum_congr rfl fun k hk => by rw [ite_eq_right (by intro he; exact hi (he ▸ hk))]lemma enclosed_sum {α : Type*} [Fintype α] (s : Finset (Grid M)) (X : α → Grid M)(h : ∀ x, enclosed s 1 (X x)) :enclosed s (Fintype.card α) (∑ i, X i) := byclassicalsuffices HH : ∀ t : Finset α, enclosed s t.card (∑ i∈t, X i) from HH _intro t; induction t using Finset.induction_on with| empty => simp [enclosed_zero]| @insert i t hi ih =>rw [Finset.sum_insert hi,Finset.card_insert_of_notMem hi,add_comm t.card]exact enclosed_add (h _) ihopen scoped Classicaldef palace (s : Finset (Grid M)) (n : ℕ) := Finset.univ.filter (enclosed s n)lemma palace_size (s : Finset (Grid M)) (n : ℕ) : (palace s n).card ≤ (2*n+1)^s.card := byclassicallet t : Finset ℤ := Finset.Icc (-(n:ℤ)) nlet f (w : s → (t:Type)) := ∑ i : s, (w i).val • (i:Grid M)have hs : palace s n ⊆ Finset.univ.image f := byintro i hiobtain ⟨g,hg,he⟩ := (Finset.mem_filter.mp hi).2let w (i : s) : t := ⟨g i, Finset.mem_Icc.mpr (abs_le.mp (hg _ i.property))⟩refine Finset.mem_image.mpr ⟨w,Finset.mem_univ _,?_⟩rw [← he,← Finset.sum_attach s]simp only [f,w]; rflapply le_trans ((Finset.card_le_card hs).trans Finset.card_image_le)simp only [Finset.card_univ, Fintype.card_fun,Fintype.card_coe]have He : t.card = 2*n+1 := by simp [t]; omegarw [He]/-- The Fourier coefficients are supported within a bandwidth of the signed span. Thisform (arbitrary thickening of our unthickened case) will also be used for broad capture. -/def spanned (s : Finset (Grid M)) (f : Grid M → ℂ) : Prop :=∀ i, ¬enclosed s 1 i → fc f i=0lemma spanned_one (s : Finset (Grid M)) : spanned s 1 := byintro i hihave hn : i≠0 := fun he => hi (he ▸ enclosed_zero s 1)change fc (fun x => 1) i = 0rw [← funext chi_zero_left,fc_chi,ite_eq_right hn.symm]private lemma fc_real_step (f : Grid M → ℂ) (c : ℂ) (s i : Grid M) :fc (fun x => f x * (↑((c*chi s x).re):ℂ)) i =2⁻¹*(c*fc f (i-s)+conj c*fc f (i+s)) := byhave he (x : Grid M) :f x * (↑((c*chi s x).re):ℂ) = 2⁻¹ *(c*(f x*chi s x) + (conj c)*(f x * chi (-s) x)) := byrw [Complex.re_eq_add_conj,map_mul,chi_neg']ringsimp_rw [he]; rw [fc_lmul,fc_add, fc_lmul,fc_lmul, fc_mul_chi,fc_mul_chi]rw [sub_neg_eq_add]lemma expand_one_step (f : Grid M → ℂ) (c : ℂ) (s i : Grid M) :fc (fun x => f x * (1 + (↑((c*chi s x).re):ℂ))) i =fc f i + 2⁻¹*(c*fc f (i-s)+conj c*fc f (i+s)) := bysimp_rw [mul_add,mul_one,fc_add,fc_real_step]ringlemma span_augment {f : Grid M → ℂ} {u : Finset (Grid M)} (h : spanned u f)(c : ℂ) (s : Grid M) (hs : ¬ enclosed u 1 s) :let g := fun x : Grid M => f x * (1+(↑((c*chi s x).re):ℂ))spanned (insert s u) g ∧ fc g 0 = fc f 0 := byhave hx : s ∉ u := fun h => hs (enclosed_mem _ h)intro ghave ha (i : Grid M) := expand_one_step f c s iconstructor· intro i hihave hA : ¬ enclosed u 1 i := byintro heapply hi; simpa using enclosed_insert hx he 0 (by norm_num)have hB : ¬ enclosed u 1 (i-s) := byintro heapply hi; simpa using enclosed_insert hx he 1 (by norm_num)have hC : ¬ enclosed u 1 (i+s) := byintro heapply hi; simpa using enclosed_insert hx he (-1) (by norm_num)rw [ha i,h _ hA,h _ hB,h _ hC]; ring· have hs' : ¬ enclosed u 1 (-s) := fun he => hs (by simpa using enclosed_neg he)rw [ha 0, zero_add, zero_sub,h _ hs,h _ hs']; ringend FourierLLogL.Dyadicend OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137import OAI.Analysis.FourierLLogL.Dyadic.Discrete/-! # Signed combination spans and Fourier support -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadicopen Law Period Realvariable {M : ℕ}def enclosed (s : Finset (Grid M)) (n : ℕ) (x : Grid M) : Prop :=∃ f : Grid M → ℤ, (∀ i∈s, |f i| ≤ n) ∧ ∑ i∈s, f i • i = xlemma enclosed_zero (s : Finset (Grid M)) (n : ℕ) : enclosed s n 0 :=⟨fun _ => 0,by simp,by simp⟩lemma enclosed_mem (s : Finset (Grid M)) {x : Grid M} (hx : x∈s) : enclosed s 1 x := byrefine ⟨fun i => if i=x then 1 else 0,fun i hi => ?_,?_⟩· dsimp only; split_ifs <;> norm_numsimp [ite_smul,hx]lemma enclosed_neg {s : Finset (Grid M)} {n : ℕ} {x : Grid M} (h : enclosed s n x) :enclosed s n (-x) := byobtain ⟨f,hf,rfl⟩ := hrefine ⟨fun i => -f i,fun i hi => ?_,?_⟩· simpa only [abs_neg] using hf i hisimplemma enclosed_add {s : Finset (Grid M)} {n m : ℕ} {x y : Grid M} (h : enclosed s n x)(h' : enclosed s m y) : enclosed s (n+m) (x+y) := byobtain ⟨f,hf,rfl⟩ := hobtain ⟨g,hg,rfl⟩ := h'refine ⟨fun i => f i + g i,fun i hi => ?_,?_⟩· rw [Nat.cast_add]exact (abs_add_le _ _).trans (add_le_add (hf _ hi) (hg _ hi))simp [add_smul,Finset.sum_add_distrib]lemma enclosed_insert {s : Finset (Grid M)} {i x : Grid M} (hi : i ∉ s){n : ℕ} (h : enclosed s n x) (j : ℤ) (hj : |j| ≤ n) :enclosed (insert i s) n (x+j•i) := byobtain ⟨f,hf,rfl⟩ := hrefine ⟨fun k => if k=i then j else f k,?_,?_⟩· intro k hkdsimp onlysplit_ifs with h· exact hj· exact hf _ ((Finset.mem_insert.mp hk).resolve_left h)· rw [Finset.sum_insert hi]; dsimp only; rw [ite_eq_left rfl,add_comm _ (j • i)]congr 1exact Finset.sum_congr rfl fun k hk => by rw [ite_eq_right (by intro he; exact hi (he ▸ hk))]lemma enclosed_sum {α : Type*} [Fintype α] (s : Finset (Grid M)) (X : α → Grid M)(h : ∀ x, enclosed s 1 (X x)) :enclosed s (Fintype.card α) (∑ i, X i) := byclassicalsuffices HH : ∀ t : Finset α, enclosed s t.card (∑ i∈t, X i) from HH _intro t; induction t using Finset.induction_on with| empty => simp [enclosed_zero]| @insert i t hi ih =>rw [Finset.sum_insert hi,Finset.card_insert_of_notMem hi,add_comm t.card]exact enclosed_add (h _) ihopen scoped Classicaldef palace (s : Finset (Grid M)) (n : ℕ) := Finset.univ.filter (enclosed s n)lemma palace_size (s : Finset (Grid M)) (n : ℕ) : (palace s n).card ≤ (2*n+1)^s.card := byclassicallet t : Finset ℤ := Finset.Icc (-(n:ℤ)) nlet f (w : s → (t:Type)) := ∑ i : s, (w i).val • (i:Grid M)have hs : palace s n ⊆ Finset.univ.image f := byintro i hiobtain ⟨g,hg,he⟩ := (Finset.mem_filter.mp hi).2let w (i : s) : t := ⟨g i, Finset.mem_Icc.mpr (abs_le.mp (hg _ i.property))⟩refine Finset.mem_image.mpr ⟨w,Finset.mem_univ _,?_⟩rw [← he,← Finset.sum_attach s]simp only [f,w]; rflapply le_trans ((Finset.card_le_card hs).trans Finset.card_image_le)simp only [Finset.card_univ, Fintype.card_fun,Fintype.card_coe]have He : t.card = 2*n+1 := by simp [t]; omegarw [He]/-- The Fourier coefficients are supported within a bandwidth of the signed span. Thisform (arbitrary thickening of our unthickened case) will also be used for broad capture. -/def spanned (s : Finset (Grid M)) (f : Grid M → ℂ) : Prop :=∀ i, ¬enclosed s 1 i → fc f i=0lemma spanned_one (s : Finset (Grid M)) : spanned s 1 := byintro i hihave hn : i≠0 := fun he => hi (he ▸ enclosed_zero s 1)change fc (fun x => 1) i = 0rw [← funext chi_zero_left,fc_chi,ite_eq_right hn.symm]private lemma fc_real_step (f : Grid M → ℂ) (c : ℂ) (s i : Grid M) :fc (fun x => f x * (↑((c*chi s x).re):ℂ)) i =2⁻¹*(c*fc f (i-s)+conj c*fc f (i+s)) := byhave he (x : Grid M) :f x * (↑((c*chi s x).re):ℂ) = 2⁻¹ *(c*(f x*chi s x) + (conj c)*(f x * chi (-s) x)) := byrw [Complex.re_eq_add_conj,map_mul,chi_neg']ringsimp_rw [he]; rw [fc_lmul,fc_add, fc_lmul,fc_lmul, fc_mul_chi,fc_mul_chi]rw [sub_neg_eq_add]lemma expand_one_step (f : Grid M → ℂ) (c : ℂ) (s i : Grid M) :fc (fun x => f x * (1 + (↑((c*chi s x).re):ℂ))) i =fc f i + 2⁻¹*(c*fc f (i-s)+conj c*fc f (i+s)) := bysimp_rw [mul_add,mul_one,fc_add,fc_real_step]ringlemma span_augment {f : Grid M → ℂ} {u : Finset (Grid M)} (h : spanned u f)(c : ℂ) (s : Grid M) (hs : ¬ enclosed u 1 s) :let g := fun x : Grid M => f x * (1+(↑((c*chi s x).re):ℂ))spanned (insert s u) g ∧ fc g 0 = fc f 0 := byhave hx : s ∉ u := fun h => hs (enclosed_mem _ h)intro ghave ha (i : Grid M) := expand_one_step f c s iconstructor· intro i hihave hA : ¬ enclosed u 1 i := byintro heapply hi; simpa using enclosed_insert hx he 0 (by norm_num)have hB : ¬ enclosed u 1 (i-s) := byintro heapply hi; simpa using enclosed_insert hx he 1 (by norm_num)have hC : ¬ enclosed u 1 (i+s) := byintro heapply hi; simpa using enclosed_insert hx he (-1) (by norm_num)rw [ha i,h _ hA,h _ hB,h _ hC]; ring· have hs' : ¬ enclosed u 1 (-s) := fun he => hs (by simpa using enclosed_neg he)rw [ha 0, zero_add, zero_sub,h _ hs,h _ hs']; ringend FourierLLogL.Dyadicend OAI
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import OAI.Analysis.FourierLLogL.Edges.Intervals/-! # The unlabelled entropy charge inequality -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Wireopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Pulsevariable {M : ℕ} {s : Scene M}open scoped Classicaldef toll (p : Policy M) (main : Bool) (e : Pulse M) :=if e.active = true ∧ ¬ enter e.scene thene.scene.norm/e.scene.mass * surcharge e.scene main (p e.scene) else 0private lemma mark_total {p : Policy M} (main : Bool) (w : Wire M s) {a : Bool}(h : w.Valid a) (hm : 0 < s.mass) :w.expenditure (toll p main) ≤ 2*s.actor.Ex (fun x => labels p (w.read x)) := byinduction w generalizing a with| term => simp [expenditure,read,Ex_const,labels]| stay s v w ih =>rw [fee_stay]cases v <;> exact ih h.2 hm| spot s u k ih =>have hh := h.2.2.1 hmhave h1 := spotEx u k (fun z _ => (labels p z:ℝ)) hhrw [fee_spot _ _ _ hh,h1,← Ex_lmul]apply Ex_mono_mem _exact fun b hb => ih b (h.2.2.2 _) ((true_mass hh).mp hb)| link s v k ih =>obtain ⟨he,hh,hx,hk⟩ := hhave hf := step_true he.1.1 hh he.2 hmlet P := (step s).probs; let T := s.actorlet F (b : Bool) := (k b).expenditure (toll p main)let L := Wire.link s v klet Q (b : Bool) := (s.smaller b).actorhave ht (b : Bool) (hp : 0 < P b) :F b ≤ 2*(Q b).Ex (fun x => (labels p ((k b).read x):ℝ)) :=ih b (hk _) ((true_mass hf).mp hp)let Y (b : Bool) : Pulse M := ⟨s,v,b⟩let B := if v = true ∧ ¬ s.enter then s.norm/s.mass * surcharge s main (p s) else 0have hT (b) : toll p main (Y b) = B := rfllet x1 (b : Bool) (i : Grid M) : ℝ := ↑(tags p (Y b) ((k b).read i))let x2 (b : Bool) (i : Grid M) : ℝ := ↑(labels p ((k b).read i))have Hx : T.Ex (fun i => (labels p (L.read i):ℝ)) =P.Ex (fun b => (Q b).Ex (x1 b)+(Q b).Ex (x2 b)) := byunfold T L; rw [linkEx v k (fun z _ => (labels p z:ℝ)) hf]unfold P Q; simp only [labels,Nat.cast_add]simp_rw [Ex_add]; rflhave H₁ : B ≤ 2*P.Ex (fun b => (Q b).Ex (x1 b)) := byhave hp1 : 0 ≤ 2*P.Ex (fun b => (Q b).Ex (x1 b)) := byapply mul_nonneg (by norm_num)exact Ex_nonneg _ fun i => Ex_nonneg _ fun j => by unfold x1; positivitydsimp only [B]split_ifs with hv· obtain ⟨hv,hE⟩ := hvcases ha : decide (hazard s main (p s))· rw [surcharge,ite_eq_right (of_decide_eq_false ha),mul_zero]; exact hp1have hi := of_decide_eq_true harw [surcharge,ite_eq_left hi,(hazard_rule he.1 he.2 hm hE hi).2.1]have Hh : L.Valid a := ⟨he,hh,hx,hk⟩apply (mark_chance L Hh hm hE main (p s) hi).transrefine mul_le_mul_of_nonneg_left (le_of_eq ?_) (by norm_num)unfold probrw [linkEx v k (fun z i => if startMark (p s) z then (1:ℝ) else 0) hf]unfold P Qcongr 1; funext b; refine congrArg (Q b).Ex ?_funext iunfold x1 tags Ysimp [hv]exact hp1rw [fee_link v k _ hf,Ex_add]change P.Ex (fun b => toll p main (Y b))+P.Ex F ≤ _simp_rw [hT,Ex_const]change _ ≤ 2*T.Ex (fun i => (labels p (L.read i):ℝ))rw [Hx,Ex_add,mul_add]apply add_le_add H₁rw [← Ex_lmul]; exact Ex_mono_mem _ ht/-- All length charge or the version using trailing K. -/theorem edge_total (p : Policy M) (main : Bool) (t : Wire M s) {a : Bool}(h : Valid t a) (hm : 0 < s.mass) (K : ℕ) (hk : ∀ x : Scene M, K=0 ∨ reach (p x) ≤ K) :t.expenditure (toll p main) ≤ 128*t.expenditure (due K)+2*K := byapply le_trans (mark_total main t h hm)have H := s.actor.Ex_mono (mark_intervals p t h K hk)rw [Ex_add,Ex_lmul,Ex_const] at Hunfold expenditurelinarithend FourierLLogL.Dyadic.Procedure.Wireend OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import OAI.Analysis.FourierLLogL.Edges.Intervals/-! # The unlabelled entropy charge inequality -/open Function Set Filteropen scoped Topology BigOperators ComplexConjugatenoncomputable sectionnamespace OAInamespace FourierLLogL.Dyadic.Procedure.Wireopen Law Node Real Period Compress.Params Thermal Fund Scene Fork Road Event Journal Pulsevariable {M : ℕ} {s : Scene M}open scoped Classicaldef toll (p : Policy M) (main : Bool) (e : Pulse M) :=if e.active = true ∧ ¬ enter e.scene thene.scene.norm/e.scene.mass * surcharge e.scene main (p e.scene) else 0private lemma mark_total {p : Policy M} (main : Bool) (w : Wire M s) {a : Bool}(h : w.Valid a) (hm : 0 < s.mass) :w.expenditure (toll p main) ≤ 2*s.actor.Ex (fun x => labels p (w.read x)) := byinduction w generalizing a with| term => simp [expenditure,read,Ex_const,labels]| stay s v w ih =>rw [fee_stay]cases v <;> exact ih h.2 hm| spot s u k ih =>have hh := h.2.2.1 hmhave h1 := spotEx u k (fun z _ => (labels p z:ℝ)) hhrw [fee_spot _ _ _ hh,h1,← Ex_lmul]apply Ex_mono_mem _exact fun b hb => ih b (h.2.2.2 _) ((true_mass hh).mp hb)| link s v k ih =>obtain ⟨he,hh,hx,hk⟩ := hhave hf := step_true he.1.1 hh he.2 hmlet P := (step s).probs; let T := s.actorlet F (b : Bool) := (k b).expenditure (toll p main)let L := Wire.link s v klet Q (b : Bool) := (s.smaller b).actorhave ht (b : Bool) (hp : 0 < P b) :F b ≤ 2*(Q b).Ex (fun x => (labels p ((k b).read x):ℝ)) :=ih b (hk _) ((true_mass hf).mp hp)let Y (b : Bool) : Pulse M := ⟨s,v,b⟩let B := if v = true ∧ ¬ s.enter then s.norm/s.mass * surcharge s main (p s) else 0have hT (b) : toll p main (Y b) = B := rfllet x1 (b : Bool) (i : Grid M) : ℝ := ↑(tags p (Y b) ((k b).read i))let x2 (b : Bool) (i : Grid M) : ℝ := ↑(labels p ((k b).read i))have Hx : T.Ex (fun i => (labels p (L.read i):ℝ)) =P.Ex (fun b => (Q b).Ex (x1 b)+(Q b).Ex (x2 b)) := byunfold T L; rw [linkEx v k (fun z _ => (labels p z:ℝ)) hf]unfold P Q; simp only [labels,Nat.cast_add]simp_rw [Ex_add]; rflhave H₁ : B ≤ 2*P.Ex (fun b => (Q b).Ex (x1 b)) := byhave hp1 : 0 ≤ 2*P.Ex (fun b => (Q b).Ex (x1 b)) := byapply mul_nonneg (by norm_num)exact Ex_nonneg _ fun i => Ex_nonneg _ fun j => by unfold x1; positivitydsimp only [B]split_ifs with hv· obtain ⟨hv,hE⟩ := hvcases ha : decide (hazard s main (p s))· rw [surcharge,ite_eq_right (of_decide_eq_false ha),mul_zero]; exact hp1have hi := of_decide_eq_true harw [surcharge,ite_eq_left hi,(hazard_rule he.1 he.2 hm hE hi).2.1]have Hh : L.Valid a := ⟨he,hh,hx,hk⟩apply (mark_chance L Hh hm hE main (p s) hi).transrefine mul_le_mul_of_nonneg_left (le_of_eq ?_) (by norm_num)unfold probrw [linkEx v k (fun z i => if startMark (p s) z then (1:ℝ) else 0) hf]unfold P Qcongr 1; funext b; refine congrArg (Q b).Ex ?_funext iunfold x1 tags Ysimp [hv]exact hp1rw [fee_link v k _ hf,Ex_add]change P.Ex (fun b => toll p main (Y b))+P.Ex F ≤ _simp_rw [hT,Ex_const]change _ ≤ 2*T.Ex (fun i => (labels p (L.read i):ℝ))rw [Hx,Ex_add,mul_add]apply add_le_add H₁rw [← Ex_lmul]; exact Ex_mono_mem _ ht/-- All length charge or the version using trailing K. -/theorem edge_total (p : Policy M) (main : Bool) (t : Wire M s) {a : Bool}(h : Valid t a) (hm : 0 < s.mass) (K : ℕ) (hk : ∀ x : Scene M, K=0 ∨ reach (p x) ≤ K) :t.expenditure (toll p main) ≤ 128*t.expenditure (due K)+2*K := byapply le_trans (mark_total main t h hm)have H := s.actor.Ex_mono (mark_intervals p t h K hk)rw [Ex_add,Ex_lmul,Ex_const] at Hunfold expenditurelinarithend FourierLLogL.Dyadic.Procedure.Wireend OAI
lean/OAI/Analysis/FourierLLogL/Assembly/Cast.lean+185-185
lean/OAI/Analysis/FourierLLogL/Assembly/Chill.lean+179-179
lean/OAI/Analysis/FourierLLogL/Assembly/Duration.lean+241-241
lean/OAI/Analysis/FourierLLogL/Assembly/Endpoint.lean+62-62
lean/OAI/Analysis/FourierLLogL/Assembly/Festival.lean+213-213
lean/OAI/Analysis/FourierLLogL/Assembly/Gross.lean+225-225
lean/OAI/Analysis/FourierLLogL/Assembly/Phase.lean+215-215
lean/OAI/Analysis/FourierLLogL/Assembly/Rail.lean+190-190
lean/OAI/Analysis/FourierLLogL/Assembly/Receipt.lean+182-182
lean/OAI/Analysis/FourierLLogL/Assembly/Series.lean+273-273
lean/OAI/Analysis/FourierLLogL/Assembly/Slab.lean+138-138
lean/OAI/Analysis/FourierLLogL/Assembly/Tokens.lean+223-223
lean/OAI/Analysis/FourierLLogL/Assembly/Verdict.lean+215-215
lean/OAI/Analysis/FourierLLogL/Assembly/Weighted.lean+154-154
lean/OAI/Analysis/FourierLLogL/Capture/Append.lean+180-180
lean/OAI/Analysis/FourierLLogL/Capture/Book.lean+114-114
lean/OAI/Analysis/FourierLLogL/Capture/Criterion.lean+206-206
lean/OAI/Analysis/FourierLLogL/Capture/Curve.lean+190-190
lean/OAI/Analysis/FourierLLogL/Capture/Dual.lean+157-157
lean/OAI/Analysis/FourierLLogL/Capture/Flex.lean+167-167
lean/OAI/Analysis/FourierLLogL/Capture/Mask.lean+196-196
lean/OAI/Analysis/FourierLLogL/Capture/MaskKernel.lean+243-243
lean/OAI/Analysis/FourierLLogL/Compress/Blocks.lean+165-165
lean/OAI/Analysis/FourierLLogL/Compress/Context.lean+260-260
lean/OAI/Analysis/FourierLLogL/Compress/Cost.lean+232-232
lean/OAI/Analysis/FourierLLogL/Compress/Endpoint.lean+222-222
lean/OAI/Analysis/FourierLLogL/Compress/Fraction.lean+170-170
lean/OAI/Analysis/FourierLLogL/Compress/Freeze.lean+216-216
lean/OAI/Analysis/FourierLLogL/Compress/Low.lean+274-274
lean/OAI/Analysis/FourierLLogL/Compress/Observe.lean+222-222
lean/OAI/Analysis/FourierLLogL/Compress/Params.lean+330-330
lean/OAI/Analysis/FourierLLogL/Compress/Phase.lean+284-284
lean/OAI/Analysis/FourierLLogL/Compress/Prefix.lean+169-169
lean/OAI/Analysis/FourierLLogL/Compress/Projection.lean+179-179
lean/OAI/Analysis/FourierLLogL/Compress/Rent.lean+171-171
lean/OAI/Analysis/FourierLLogL/Compress/Schedule.lean+205-205
lean/OAI/Analysis/FourierLLogL/Compress/Search.lean+363-363
lean/OAI/Analysis/FourierLLogL/Compress/Select.lean+178-178
lean/OAI/Analysis/FourierLLogL/Compress/Theorem.lean+95-95
lean/OAI/Analysis/FourierLLogL/Compress/ThinChoice.lean+213-213
lean/OAI/Analysis/FourierLLogL/Compress/Thinning.lean+207-207
lean/OAI/Analysis/FourierLLogL/Compress/Variational.lean+230-230
lean/OAI/Analysis/FourierLLogL/Dyadic/Circle.lean+192-192
lean/OAI/Analysis/FourierLLogL/Dyadic/Discrete.lean+214-214
lean/OAI/Analysis/FourierLLogL/Dyadic/Grid.lean+259-259
lean/OAI/Analysis/FourierLLogL/Dyadic/Lift.lean+331-331
lean/OAI/Analysis/FourierLLogL/Dyadic/Node.lean+232-232
lean/OAI/Analysis/FourierLLogL/Dyadic/Snap.lean+163-163
lean/OAI/Analysis/FourierLLogL/Dyadic/Span.lean+137-137
lean/OAI/Analysis/FourierLLogL/Edges/Charge.lean+95-95