Download data/lean/OAI/Analysis/DiamondDistortion/SignCube.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiamondDistortion/SignCube.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Analysis/DiamondDistortion/SignCube.lean
-
curl -L -o SignCube.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Analysis/DiamondDistortion/SignCube.lean
12.1 kB
| import OAI.Analysis.DiamondDistortion.RecursiveBounds | |
| namespace OAI | |
| universe u v | |
| noncomputable section | |
| open scoped BigOperators Classical Topology | |
| open Set | |
| namespace DiamondDistortion | |
| open scoped ENNReal | |
| namespace SignCube | |
| abbrev History : β β Type | |
| | 0 => Unit | |
| | n+1 => History n Γ Bool | |
| instance (n : β) : Fintype (History n) := by induction n with | zero => infer_instance | succ n ih => exact inferInstance | |
| instance (n : β) : Nonempty (History n) := by induction n with | zero => infer_instance | succ n ih => exact inferInstance | |
| lemma history_card (n : β) : Fintype.card (History n)=2^n := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => change Fintype.card (History n Γ Bool)=_; rw [Fintype.card_prod,ih,Fintype.card_bool,pow_succ] | |
| /-- Expectation for the uniform sign probability, written as iterated fair averages. -/ | |
| def mean : (n : β) β (History n β β) β β | |
| | 0,f => f () | |
| | n+1,f => mean n (fun h => (f (h,false)+f (h,true))/2) | |
| @[simp] lemma mean_zero (n : β) : mean n (fun _ => 0)=0 := by | |
| induction n with | zero => rfl | succ n ih => simpa only [mean,zero_add,zero_div] using ih | |
| @[simp] lemma mean_const (n : β) (c : β) : mean n (fun _ => c)=c := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => simpa only [mean,show (c+c)/2=c by ring] using ih | |
| lemma mean_mono (n : β) {f g : History n β β} (hfg : β h,f h β€ g h) : mean n f β€ mean n g := by | |
| induction n with | |
| | zero => exact hfg () | |
| | succ n ih => exact ih (fun h => by change (f (h,false)+f (h,true))/2 β€ _; linarith [hfg (h,false),hfg (h,true)]) | |
| lemma mean_nonneg (n : β) {f : History n β β} (hf : β h,0 β€ f h) : 0 β€ mean n f := by | |
| simpa only [mean_zero] using mean_mono n hf | |
| lemma mean_lower (n : β) {f : History n β β} {a : β} (hf : β h,a β€ f h) : a β€ mean n f := by | |
| simpa only [mean_const] using mean_mono n hf | |
| lemma mean_upper (n : β) {f : History n β β} {a : β} (hf : β h,f h β€ a) : mean n f β€ a := by | |
| simpa only [mean_const] using mean_mono n hf | |
| lemma mean_add (n : β) (f g : History n β β) : mean n (fun h => f h+g h)=mean n f+mean n g := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| change mean n (fun h => (f (h,false)+g (h,false)+(f (h,true)+g (h,true)))/2)=_ | |
| simp_rw [show β a b c d : β,(a+b+(c+d))/2=(a+c)/2+(b+d)/2 by intros; ring] | |
| exact ih _ _ | |
| lemma mean_mul (n : β) (c : β) (f : History n β β) : mean n (fun h => c*f h)=c*mean n f := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| change mean n (fun h => (c*f (h,false)+c*f (h,true))/2)=_ | |
| simp_rw [show β a b : β,(c*a+c*b)/2=c*((a+b)/2) by intros; ring] | |
| exact ih _ | |
| lemma mean_sub (n : β) (f g : History n β β) : mean n (fun h => f h-g h)=mean n f-mean n g := by | |
| have he (h : History n) : f h-g h=f h+(-1)*g h := by ring | |
| simp_rw [he] | |
| rw [mean_add,mean_mul] | |
| ring | |
| lemma mean_last (n : β) (f : History n β β) : mean (n+1) (fun h => f h.1)=mean n f := by | |
| simp only [mean,show β a : β,(a+a)/2=a by intro; ring] | |
| lemma mean_uniform (n : β) (f : History n β β) : | |
| mean n f=(β h,f h)/(Fintype.card (History n):β) := by | |
| induction n with | |
| | zero => simp [mean] | |
| | succ n ih => | |
| change mean n (fun h => (f (h,false)+f (h,true))/2)=_ | |
| rw [ih,β Finset.sum_div,Finset.sum_add_distrib] | |
| simp only [Fintype.sum_prod_type,Fintype.sum_bool,Fintype.card_prod,Fintype.card_bool,Nat.cast_mul,Nat.cast_ofNat,Finset.sum_add_distrib] | |
| ring | |
| inductive Protocol (X : Type u) (I : Type v) : β β Type (max u v) | |
| | initial (x : X) (H : I) : Protocol X I 0 | |
| | extend {n : β} (prev : Protocol X I n) (A B : History n β I) | |
| (next : History (n+1) β X) : Protocol X I (n+1) | |
| namespace Protocol | |
| variable {X I : Type*} | |
| def last : {n : β} β Protocol X I n β History n β X | |
| | 0,.initial x _,_ => x | |
| | _+1,.extend _ _ _ W,h => W h | |
| def lastHead : {n : β} β Protocol X I n β History n β I | |
| | 0,.initial _ H,_ => H | |
| | _+1,.extend _ _ B _,h => B h.1 | |
| variable [NormedAddCommGroup X] [NormedSpace β X] | |
| /-- Fair one-step conditional expectations. Iterating gives W_i=E(W_m|F_i). -/ | |
| def Martingale : {n : β} β Protocol X I n β Prop | |
| | 0,.initial _ _ => True | |
| | _+1,.extend T _ _ W => Martingale T β§ β h,T.last h=(1/2:β) β’ (W (h,false)+W (h,true)) | |
| variable [Preorder I] | |
| def Nested : {n : β} β Protocol X I n β Prop | |
| | 0,.initial _ _ => True | |
| | _+1,.extend T A B _ => Nested T β§ β h,T.lastHead h β€ A h β§ A h β€ B h | |
| /-- Each layer is between consecutive support heads, not separated by a new | |
| unrecorded head. This is imposed only for the inputs that require it. -/ | |
| def Anchored : {n : β} β Protocol X I n β Prop | |
| | 0,.initial _ _ => True | |
| | _+1,.extend T A _ _ => Anchored T β§ β h,A h=T.lastHead h | |
| /-- Fixed across each level (stronger than predictability); required only by the | |
| deterministic leakage input. -/ | |
| def CommonHeads : {n : β} β Protocol X I n β Prop | |
| | 0,.initial _ _ => True | |
| | _+1,.extend T _ B _ => CommonHeads T β§ β H,β h,B h=H | |
| def Supported (P : I β X βL[β] X) : {n : β} β Protocol X I n β Prop | |
| | 0,.initial x H => P H x=x | |
| | _+1,.extend T _ B W => Supported P T β§ β h b,P (B h) (W (h,b))=W (h,b) | |
| def childEnergy (P : I β X βL[β] X) (n : β) (A B : History n β I) (W : History (n+1) β X) : β := | |
| mean (n+1) (fun h => βP (B h.1) (W h)-P (A h.1) (W h)β^2) | |
| def parentEnergy (P : I β X βL[β] X) (n : β) (A B : History n β I) (W : History n β X) : β := | |
| mean n (fun h => βP (B h) (W h)-P (A h) (W h)β^2) | |
| def freshSum (P : I β X βL[β] X) : {n : β} β Protocol X I n β β | |
| | 0,.initial _ _ => 0 | |
| | n+1,.extend T A B W => freshSum P T+childEnergy P n A B W | |
| def leakageSum (P : I β X βL[β] X) : {n : β} β Protocol X I n β β | |
| | 0,.initial _ _ => 0 | |
| | n+1,.extend T A B _ => leakageSum P T+parentEnergy P n A B T.last | |
| def terminalEnergy {n : β} (T : Protocol X I n) : β := mean n (fun h => βT.last hβ^2) | |
| lemma terminalEnergy_nonneg {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] {n : β} (T : Protocol X I n) : 0 β€ T.terminalEnergy := | |
| mean_nonneg _ (fun _ => sq_nonneg _) | |
| lemma terminalEnergy_bound {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] {n : β} (T : Protocol X I n) {D : β} (hD : 0 β€ D) | |
| (h : β u,βT.last uβ β€ D) : T.terminalEnergy β€ D^2 := | |
| mean_upper _ (fun u => (sq_le_sqβ (norm_nonneg _) hD).mpr (h u)) | |
| lemma freshSum_nonneg {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] (P : I β X βL[β] X) {n : β} (T : Protocol X I n) : 0 β€ T.freshSum P := by | |
| induction T with | |
| | initial x H => exact le_rfl | |
| | @extend n T A B W ih => exact add_nonneg ih (mean_nonneg _ (fun _ => sq_nonneg _)) | |
| lemma leakageSum_nonneg {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] (P : I β X βL[β] X) {n : β} (T : Protocol X I n) : 0 β€ T.leakageSum P := by | |
| induction T with | |
| | initial x H => exact le_rfl | |
| | @extend n T A B W ih => exact add_nonneg ih (mean_nonneg _ (fun _ => sq_nonneg _)) | |
| end Protocol | |
| end SignCube | |
| namespace DirectLayers | |
| open SignCube | |
| variable {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] | |
| def SignInput (P : I β X βL[β] X) (C : β) : Prop := | |
| β (m : β) (T : Protocol X I m),T.Martingale β T.Nested β | |
| T.freshSum P β€ C*(T.terminalEnergy+T.leakageSum P) | |
| def PredictableInput (P : I β X βL[β] X) (B : β) : Prop := | |
| β (m : β) (T : Protocol X I m),T.Martingale β T.Nested β T.Anchored β T.Supported P β | |
| β C : β,(β h,βT.last hβ β€ C) β T.freshSum P β€ B*C^2 | |
| def LeakageInput (P : I β X βL[β] X) : Prop := | |
| β (m : β) (T : Protocol X I m),T.Martingale β T.Nested β T.Anchored β T.CommonHeads β | |
| T.freshSum P β€ 1024*(T.terminalEnergy+T.leakageSum P) | |
| def GapInput (P : I β X βL[β] X) : Prop := | |
| β (A B : I),A β€ B β β x y : X,P A x=x β P B y=y β | |
| βP B y-P A yβ^2 β€ 400*((βx+yβ^2+βx-yβ^2)/2-βxβ^2) | |
| structure Regular (A : Midpoint.Heads I X) : Prop where | |
| nonempty : Nonempty I | |
| upper : β H K : I,β J,H β€ J β§ K β€ J | |
| nested_left : β H K : I,H β€ K β β x : X,A.projection H (A.projection K x)=A.projection H x | |
| nested_right : β H K : I,H β€ K β β x : X,A.projection K (A.projection H x)=A.projection H x | |
| contractive : β H : I,β x : X,βA.projection H xβ β€ βxβ | |
| namespace Regular | |
| variable {A : Midpoint.Heads I X} (hA : Regular A) | |
| include hA | |
| lemma finite_upper (S : Finset I) : β B,β H β S,H β€ B := by | |
| classical | |
| induction S using Finset.induction_on with | |
| | empty => obtain β¨Bβ© := hA.nonempty; exact β¨B,by simpβ© | |
| | @insert H S hHS ih => | |
| obtain β¨K,hKβ© := ih | |
| obtain β¨B,hHB,hKBβ© := hA.upper H K | |
| refine β¨B,?_β© | |
| intro J hJ | |
| rcases Finset.mem_insert.mp hJ with rfl|hJ | |
| Β· exact hHB | |
| Β· exact (hK J hJ).trans hKB | |
| lemma tail_norm (H : I) (x : X) : βx-A.projection H xβ β€ 2*βxβ := by | |
| have hh := (norm_sub_le x (A.projection H x)).trans (add_le_add (le_refl _) (hA.contractive H x)) | |
| linarith | |
| /-- A single larger ancestral head captures any finite family. -/ | |
| lemma capture {ΞΊ : Type*} [Fintype ΞΊ] (H : I) (x : ΞΊ β X) {Ξ· : β} (hΞ· : 0 < Ξ·) : | |
| β B : I,H β€ B β§ β j,βx j-A.projection B (x j)β < Ξ· := by | |
| classical | |
| choose K p hfix hclose using fun j => A.approximation (x j) (Ξ·/2) (half_pos hΞ·) | |
| obtain β¨B,hBβ© := hA.finite_upper (insert H (Finset.univ.image K)) | |
| refine β¨B,hB H (Finset.mem_insert_self _ _),?_β© | |
| intro j | |
| have hKB := hB (K j) (Finset.mem_insert_of_mem (Finset.mem_image.mpr β¨j,Finset.mem_univ _,rflβ©)) | |
| have hBp : A.projection B (p j)=p j := by | |
| rw [β hfix j,hA.nested_right _ _ hKB] | |
| have he : x j-A.projection B (x j)=(x j-p j)-A.projection B (x j-p j) := by | |
| rw [map_sub,hBp]; abel | |
| rw [he] | |
| exact (hA.tail_norm B (x j-p j)).trans_lt (by linarith [hclose j]) | |
| lemma capture_one (H : I) (x : X) {Ξ· : β} (hΞ· : 0 < Ξ·) : | |
| β B : I,H β€ B β§ βx-A.projection B xβ < Ξ· := by | |
| obtain β¨B,hHB,hBβ© := hA.capture H (fun _ : Unit => x) hΞ· | |
| exact β¨B,hHB,hB ()β© | |
| lemma layer_parent (H B : I) (hHB : H β€ B) (x : X) : | |
| βA.projection B x-A.projection H xβ β€ βx-A.projection H xβ := by | |
| calc | |
| _ = βA.projection B (x-A.projection H x)β := by rw [map_sub,hA.nested_right H B hHB] | |
| _ β€ _ := hA.contractive _ _ | |
| end Regular | |
| lemma select_tail {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] (A : Midpoint.Heads I X) (H : I) (z : β β X) {R a r : β} | |
| (hz : β j,βz jβ β€ R) (hs : β i j,i β j β a β€ βz i-z jβ) (hr : r < a/2) : | |
| β j,r < βz j-A.projection H (z j)β := by | |
| let := A.finite H | |
| by_contra! hn | |
| have hh := Midpoint.tail_packing (A.projection H) z hz hs hn | |
| linarith | |
| end DirectLayers | |
| namespace SignCube.Protocol | |
| variable {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] | |
| def initialEnergy : {n : β} β Protocol X I n β β | |
| | 0,.initial x _ => βxβ^2 | |
| | _+1,.extend T _ _ _ => T.initialEnergy | |
| lemma initialEnergy_nonneg {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] {n : β} (T : Protocol X I n) : 0 β€ T.initialEnergy := by | |
| induction T with | initial x H => exact sq_nonneg _ | extend T A B W ih => exact ih | |
| variable [Preorder I] | |
| lemma common_last {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] {n : β} (T : Protocol X I n) (h : T.CommonHeads) : | |
| β H,β u,T.lastHead u=H := by | |
| cases T with | |
| | initial x H => exact β¨H,fun _ => rflβ© | |
| | extend T A B W => obtain β¨H,hHβ© := h.2; exact β¨H,fun u => hH u.1β© | |
| lemma supported_last {X I : Type*} [NormedAddCommGroup X] [NormedSpace β X] [Preorder I] (P : I β X βL[β] X) {n : β} (T : Protocol X I n) (h : T.Supported P) : | |
| β u,P (T.lastHead u) (T.last u)=T.last u := by | |
| cases T with | |
| | initial x H => exact fun _ => h | |
| | extend T A B W => exact fun u => h.2 u.1 u.2 | |
| end SignCube.Protocol | |
| end DiamondDistortion | |
| end | |
| end OAI | |