Download data/lean/OAI/Computability/FourierCircuit/InventoryValidity.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FourierCircuit/InventoryValidity.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/FourierCircuit/InventoryValidity.lean
-
curl -L -o InventoryValidity.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FourierCircuit/InventoryValidity.lean
15 kB
| import OAI.Computability.FourierCircuit.LiveSectors | |
| namespace OAI | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο : Type} [Fintype Ο] [DecidableEq Ο] | |
| {D : ΟβType} [β t,Fintype (D t)] [β t,DecidableEq (D t)] | |
| {A : β t,Matrix (D t) (D t) β} | |
| theorem inventory_card | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] (k : Οββ) (I : β) : | |
| Fintype.card (ActiveSpace D kβFin I)=(β t,k t*Fintype.card (D t))+I := by | |
| rw [Fintype.card_sum,Fintype.card_fin,Fintype.card_sigma,Fintype.sum_sigma] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro t ht | |
| change (β j : Fin (k t),Fintype.card (D t))=_ | |
| simp | |
| theorem inventory_unit (hA : β t,IsUnit (A t)) (k : Οββ) (I : β) : | |
| IsUnit (inventoryWithIdentity (A := A) (Ξ½ := Fin I) k) := by | |
| apply Matrix.isUnit_fromBlocks_zeroββ.mpr | |
| refine β¨?_,isUnit_oneβ© | |
| exact (Pi.isUnit_iff.mpr (fun i : Inventory k=>hA i.1)).map (Matrix.blockDiagonal'RingHom (fun i : Inventory k=>D i.1) β) | |
| theorem inventory_not_monomial (hA : β t,IsUnit (A t)) (k : Οββ) (I : β) | |
| (t : Ο) (hk : 0<k t) (hn : Β¬MonomialMatrix (A t)) : | |
| Β¬MonomialMatrix (inventoryWithIdentity (A := A) (Ξ½ := Fin I) k) := by | |
| intro h | |
| let e : D t βͺ ActiveSpace D kβFin I := | |
| (Embedded.sigmaIn (Ξ² := fun i : Inventory k=>D i.1) β¨t,β¨0,hkβ©β©).trans Function.Embedding.inl | |
| have he : (inventoryWithIdentity (A := A) (Ξ½ := Fin I) k).submatrix e e=A t := by | |
| ext i j | |
| change Matrix.blockDiagonal' (fun i : Inventory k=>A i.1) β¨β¨t,β¨0,hkβ©β©,iβ© β¨β¨t,β¨0,hkβ©β©,jβ©=A t i j | |
| exact Matrix.blockDiagonal'_apply_eq _ _ _ _ | |
| apply hn | |
| rw [β he] | |
| exact h.submatrix_unit e e (he.symm βΈ hA t) | |
| theorem exists_positive_dummy | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] {A : (t : Ο) β Matrix (D t) (D t) β} (hA : β t,IsUnit (A t)) (t : Ο) : | |
| β W : FramedWord D (D t),0<W.frames.length β§ W.matrix (A := A)=1 β§ | |
| β o : Fin W.frames.length,(W.frames.get o).type=t := by | |
| by_cases hn : MonomialMatrix (A t) | |
| Β· let W : Word D A (D t) := callWord t (Function.Embedding.refl _)++monoWord (A t)β»ΒΉ hn.inverse | |
| have hm : W.matrix=1 := by | |
| rw [Word.matrix_append,matrix_callWord,matrix_monoWord] | |
| have he : Embedded.matrix (Function.Embedding.refl (D t)) (A t)=A t := by | |
| ext i j; exact Embedded.matrix_on (Function.Embedding.refl _) _ i j | |
| rw [he] | |
| exact Matrix.mul_nonsing_inv _ ((Matrix.isUnit_iff_isUnit_det _).mp (hA t)) | |
| refine β¨W.framed,?_,(Word.matrix_framed W).trans hm,?_β© | |
| Β· simp [W,Word.framed,callWord,monoWord,FramedWord.pre] | |
| Β· intro o | |
| have h : W.framed.types=[t] := by simp [W] | |
| have hh : (W.framed.frames.get o).typeβW.framed.types := List.mem_map.mpr β¨_,List.get_mem _ _,rflβ© | |
| simpa [h] using hh | |
| Β· obtain β¨h,hh,hgenβ© := PositiveGeneration.positive_generation (A t) (hA t) hn | |
| obtain β¨W,hm,hcβ© := pattern_word t (hgen 1 isUnit_one) | |
| have hl : W.framed.frames.length=h := by | |
| have hlen := congrArg List.length ((Word.types_framed W).trans hc) | |
| simpa [FramedWord.types] using hlen | |
| refine β¨W.framed,hl.symm βΈ hh,(Word.matrix_framed W).trans hm,?_β© | |
| intro o | |
| have ht : W.framed.types=List.replicate h t := (Word.types_framed W).trans hc | |
| have hmem : (W.framed.frames.get o).typeβW.framed.types := by | |
| exact List.mem_map.mpr β¨_,List.get_mem _ _,rflβ© | |
| rw [ht,List.mem_replicate] at hmem | |
| exact hmem.2 | |
| end ExactFourier.Packing | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο : Type} [Fintype Ο] [DecidableEq Ο] | |
| {D : ΟβType} [β t,Fintype (D t)] [β t,DecidableEq (D t)] | |
| {A : β t,Matrix (D t) (D t) β} | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] | |
| theorem scalable_square_win (hA : β t,IsUnit (A t)) (k : Οββ) (I : β) | |
| (hk : β t,0<k t) (anchor : Ο) (hn : Β¬MonomialMatrix (A anchor)) | |
| (key : ΟβLivePair Ο) (P : β p,FramedWord D (PairDomain D (key p))) (m : Οββ) | |
| (hP : β p,(P p).matrix (A := A)=pairMatrix (A := A) (key p)) | |
| (hnum : β s,(β p,if key p=s then m p else 0)= | |
| speciesCopies k I s.1.1*speciesCopies k I s.1.2) | |
| (dummy : β t,FramedWord D (D t)) (hdpos : β t,0<(dummy t).frames.length) | |
| (hdummy : β t,(dummy t).matrix (A := A)=1) | |
| (hdtype : β t (o : Fin (dummy t).frames.length),((dummy t).frames.get o).type=t) | |
| (S : Οββ) (hS : β t,2*k tβ€S t) | |
| (hGS : β t,(β p,m p*(P p).types.count t)+S t= | |
| 2*k t*((β i,k i*Fintype.card (D i))+I)) | |
| (hdK : β t,(dummy t).frames.lengthβ£k t) (hdS : β t,(dummy t).frames.lengthβ£S t) | |
| (hreservoir : 2*(β t,k t*Fintype.card (D t))*((β t,k t*Fintype.card (D t))+I)β€I^2) : | |
| FiniteWinStatement := by | |
| classical | |
| let W := (β t,k t*Fintype.card (D t))+I | |
| have hW : 0<W := by | |
| by_contra hh | |
| have hzero : W=0 := by omega | |
| have hc := inventory_not_monomial hA k I anchor (hk anchor) hn | |
| have hz : Fintype.card (ActiveSpace D kβFin I)=0 := by | |
| rw [inventory_card] | |
| exact hzero | |
| let : IsEmpty (ActiveSpace D kβFin I) := Fintype.card_eq_zero_iff.mp hz | |
| apply hc | |
| refine β¨Equiv.refl _,fun _=>1,fun _=>one_ne_zero,?_β© | |
| intro i | |
| exact isEmptyElim i | |
| let C := β p,(P p).frames.length | |
| let L := C+1 | |
| let u := L+2*C*W+(β t,(dummy t).frames.length)+1 | |
| have hu : L+2*C*Wβ€u := by omega | |
| have huh : β t,(dummy t).frames.length<u := by | |
| intro t | |
| have h := Finset.single_le_sum (fun _ _=>Nat.zero_le _) (Finset.mem_univ t) (f := fun t=>(dummy t).frames.length) | |
| dsimp [u] | |
| omega | |
| let T := (2*W-1)*u | |
| let F := T+1-L | |
| have hp := fun t=>square_inventory_parameters (hk t) hW (hdpos t) (hS t) (hGS t) (hdK t) (hdS t) hu (huh t) | |
| have hF : 0<F := (hp anchor).1 | |
| have hFT : F+L-1=T := (hp anchor).2.1 | |
| have hTu : T<2*(W*u) := (hp anchor).2.2.1 | |
| have hbound : β t,((β p,m p*(P p).types.count t)*u^2 : β)/(F : β)+(C : β)β€(k t*u : β) := | |
| fun t=>(hp t).2.2.2.1 | |
| choose d hkd hdef hdle using fun t=>(hp t).2.2.2.2 | |
| let m' := fun p=>m p*u^2 | |
| have hcount : β t,(β p,m' p*(P p).types.count t)=(β p,m p*(P p).types.count t)*u^2 := by | |
| intro t | |
| rw [Finset.sum_mul] | |
| apply Finset.sum_congr rfl | |
| intros | |
| dsimp [m'] | |
| ring | |
| have hL : β p,(P p).frames.lengthβ€L := by | |
| intro p | |
| exact (Finset.single_le_sum (fun _ _=>Nat.zero_le _) (Finset.mem_univ p)).trans (Nat.le_succ C) | |
| let time := cyclicTime P m' F L hF hL | |
| have ht : β v,StrictMono (time v) := cyclicTime_strict P m' F L hF hL | |
| have hl : β s t,Fintype.card {v : Ξ£ p,Fin (m' p) // | |
| (slotCall (A := A) (framedSlot (P v.1) (time v) s)).kind=some t}β€k t*u := by | |
| intro s t | |
| have hb := cyclic_slot_bound (A := A) P m' F L hF hL s t | |
| rw [hcount] at hb | |
| have hc : (β p,((P p).frames.length : β))=(C : β) := by simp [C] | |
| rw [hc] at hb | |
| simp only [Nat.cast_mul,Nat.cast_pow] at hb | |
| have hb' := hb.trans (hbound t) | |
| exact_mod_cast hb' | |
| have hR : β t,d t*Fintype.card (D t)β€(I*u)^2 := by | |
| calc | |
| _ β€β t,(k t*u*T)*Fintype.card (D t) := Finset.sum_le_sum (fun t _=>Nat.mul_le_mul_right _ (hdle t)) | |
| _ = (β t,k t*Fintype.card (D t))*(u*T) := by | |
| rw [Finset.sum_mul] | |
| apply Finset.sum_congr rfl | |
| intros | |
| ring | |
| _ β€ (β t,k t*Fintype.card (D t))*(u*(2*(W*u))) := Nat.mul_le_mul_left _ (Nat.mul_le_mul_left _ hTu.le) | |
| _ = (2*(β t,k t*Fintype.card (D t))*W)*u^2 := by ring | |
| _ β€ I^2*u^2 := Nat.mul_le_mul_right _ hreservoir | |
| _ = (I*u)^2 := by ring | |
| refine family_square_win (fun t=>k t*u) (I*u) key P m' hP ?_ dummy hdummy hdtype time ht hl d hkd ?_ hR | |
| (inventory_unit hA _ _) (inventory_not_monomial hA _ _ anchor (Nat.mul_pos (hk anchor) (lt_trans (hdpos anchor) (huh anchor))) hn) ?_ | |
| Β· intro s | |
| have he : β a : Option Ο,speciesCopies (fun t=>k t*u) (I*u) a=speciesCopies k I a*u := by intro a; cases a <;> rfl | |
| simp only [he] | |
| calc | |
| (β p,if key p=s then m' p else 0)=(β p,if key p=s then m p else 0)*u^2 := by | |
| rw [Finset.sum_mul] | |
| apply Finset.sum_congr rfl | |
| intro p hp | |
| dsimp [m'] | |
| split_ifs <;> simp | |
| _ = _ := by rw [hnum]; ring | |
| Β· intro t | |
| rw [hcount,hFT] | |
| exact hdef t | |
| Β· rw [hFT] | |
| have hw : Fintype.card (ActiveSpace D (fun t=>k t*u)βFin (I*u))=W*u := by | |
| rw [inventory_card] | |
| dsimp [W] | |
| rw [add_mul,Finset.sum_mul] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intros | |
| ring | |
| rw [hw] | |
| exact hTu | |
| end ExactFourier.Packing | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| /-- Strict comparison positivity is preserved by sufficiently fine downward rational rounding. -/ | |
| theorem integral_positive_combination {Ο Ο : Type} [Fintype Ο] [Fintype Ο] | |
| (Ξ : ΟβΟββ€) (lam : Οββ) (hlam : β r,0β€lam r) | |
| (hpos : β t,0<β r,lam r*(Ξ r t : β)) : | |
| β l : Οββ,β t,0<β r,(l r : β€)*Ξ r t := by | |
| classical | |
| let s := fun t=>β r,lam r*(Ξ r t : β) | |
| let B := fun t=>β r,|(Ξ r t : β)| | |
| have hn : β t,β n : β,B t<(n : β)*s t := by | |
| intro t | |
| obtain β¨n,hnβ© := exists_nat_gt (B t/s t) | |
| exact β¨n,(div_lt_iffβ (hpos t)).mp hnβ© | |
| choose n hn using hn | |
| let N := (β t,n t)+1 | |
| have hN : β t,B t<(N : β)*s t := by | |
| intro t | |
| have hnt : n tβ€N := by | |
| exact (Finset.single_le_sum (fun _ _=>Nat.zero_le _) (Finset.mem_univ t)).trans (Nat.le_add_right _ _) | |
| exact (hn t).trans_le (mul_le_mul_of_nonneg_right (by exact_mod_cast hnt) (hpos t).le) | |
| let l := fun r=>β(N : β)*lam rββ | |
| refine β¨l,?_β© | |
| intro t | |
| have hround : β r,(N : β)*lam r*(Ξ r t : β)-|(Ξ r t : β)|β€(l r : β)*(Ξ r t : β) := by | |
| intro r | |
| have hx : 0β€(N : β)*lam r := mul_nonneg (Nat.cast_nonneg _) (hlam r) | |
| have hlo : (N : β)*lam r<(l r : β)+1 := Nat.lt_floor_add_one _ | |
| have hhi : (l r : β)β€(N : β)*lam r := Nat.floor_le hx | |
| by_cases hd : 0β€(Ξ r t : β) | |
| Β· rw [abs_of_nonneg hd] | |
| have hh := mul_le_mul_of_nonneg_right (show (N : β)*lam r-1β€(l r : β) by linarith) hd | |
| nlinarith | |
| Β· have hd' : (Ξ r t : β)β€0 := le_of_not_ge hd | |
| rw [abs_of_nonpos hd'] | |
| have hh := mul_le_mul_of_nonpos_right hhi hd' | |
| nlinarith | |
| have hs := Finset.sum_le_sum (s := Finset.univ) (fun r _=>hround r) | |
| have he : (β r,((N : β)*lam r*(Ξ r t : β)-|(Ξ r t : β)|))=(N : β)*s t-B t := by | |
| simp only [s,B,Finset.sum_sub_distrib,Finset.mul_sum,mul_assoc] | |
| rw [he] at hs | |
| have hp : 0<β r,(l r : β)*(Ξ r t : β) := by linarith [hN t] | |
| exact_mod_cast hp | |
| end ExactFourier.Packing | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο : Type} [Fintype Ο] [DecidableEq Ο] | |
| {D : ΟβType} [β t,Fintype (D t)] [β t,DecidableEq (D t)] | |
| {A : β t,Matrix (D t) (D t) β} | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] | |
| theorem integer_comparison_win (hA : β t,IsUnit (A t)) | |
| (anchor : Ο) (hn : Β¬MonomialMatrix (A anchor)) | |
| (c : ΟβPairComparison (A := A)) (l : Οββ) | |
| (hpos : β t,0<β r,(l r : β€)*(c r).delta t) : FiniteWinStatement := by | |
| classical | |
| choose dummy hdpos hdm hdt using exists_positive_dummy hA | |
| let h := fun t=>(dummy t).frames.length | |
| let H := β t,h t | |
| have hH : 0<H := Finset.prod_pos (fun t _=>hdpos t) | |
| have hdH : β t,h tβ£H := fun t=>Finset.dvd_prod_of_mem _ (Finset.mem_univ t) | |
| let Z := 2*(β r,l r)+1 | |
| have hZ : 0<Z := by dsimp [Z]; omega | |
| let K := Z*H | |
| let B := β t,Fintype.card (D t) | |
| let R := H*B | |
| let I0 := 4*R+H+1 | |
| let I := Z*I0 | |
| let k : Οββ := fun _=>K | |
| let n := fun p : LivePair Ο=>speciesCopies k I p.1.1*speciesCopies k I p.1.2 | |
| let a := fun r=>Z*2*H*l r | |
| let s : Οββ := fun t=>(β r,(l r : β€)*(c r).delta t).toNat | |
| have hs : β t,(s t : β€)=β r,(l r : β€)*(c r).delta t := by | |
| intro t; exact Int.toNat_of_nonneg (hpos t).le | |
| have hsp : β t : Ο,(1 : β)β€ s t := by | |
| intro t | |
| have hh := hpos t | |
| rw [β hs] at hh | |
| exact_mod_cast hh | |
| let S := fun t=>2*K*s t | |
| have hcap : β p,(β r,if (c r).pair=p then a r else 0)β€n p := by | |
| intro p | |
| have hIK : Kβ€I := by | |
| dsimp [K,I,I0] | |
| exact Nat.mul_le_mul_left Z (by omega) | |
| have hmin : β x : Option Ο,K β€ speciesCopies k I x := by | |
| intro x; cases x with | |
| | none => exact hIK | |
| | some t => exact le_rfl | |
| have hKK : (β r,a r)β€K*K := by | |
| have he : (β r,a r)=Z*2*H*(β r,l r) := by simp only [a,Finset.mul_sum] | |
| rw [he] | |
| have hL : 2*(β r,l r)β€Z*H := by | |
| have hz : 2*(β r,l r)β€Z := by dsimp [Z]; omega | |
| exact hz.trans (by simpa using Nat.mul_le_mul_left Z hH) | |
| calc | |
| Z*2*H*(β r,l r)=K*(2*(β r,l r)) := by dsimp [K]; ring | |
| _ β€ K*(Z*H) := Nat.mul_le_mul_left _ hL | |
| _ = K*K := rfl | |
| calc | |
| (β r,if (c r).pair=p then a r else 0)β€β r,a r := Finset.sum_le_sum (fun r _=>by split_ifs <;> omega) | |
| _ β€ K*K := hKK | |
| _ β€ n p := Nat.mul_le_mul (hmin _) (hmin _) | |
| let m := familyMultiplicity c n a | |
| have hsave : β t,(β p,m p*(familyProgram c p).types.count t)+S t= | |
| 2*k t*((β i,k i*Fintype.card (D i))+I) := by | |
| intro t | |
| have he := family_saving c n a hcap t | |
| have hn : (β p,(n p : β€)*pairBaseline (D := D) p t)= | |
| (2*k t*((β i,k i*Fintype.card (D i))+I) : β) := by | |
| exact_mod_cast pair_baseline_sum (D := D) k I t | |
| have ha : (β r,(a r : β€)*(c r).delta t)=(S t : β€) := by | |
| simp only [a,Nat.cast_mul,Nat.cast_ofNat,S] | |
| rw [hs] | |
| dsimp [K] | |
| simp only [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro r hr | |
| ring | |
| rw [hn,ha] at he | |
| have hm : (β p,(m p : β€)*(familyProgram c p).types.count t)= | |
| ((β p,m p*(familyProgram c p).types.count t : β) : β€) := by push_cast; rfl | |
| rw [hm] at he | |
| have hh : ((β p,m p*(familyProgram c p).types.count t : β) : β€)+(S t : β€)= | |
| ((2*k t*((β i,k i*Fintype.card (D i))+I) : β) : β€) := by omega | |
| exact_mod_cast hh | |
| have hR : 2*(β t,k t*Fintype.card (D t))*((β t,k t*Fintype.card (D t))+I)β€I^2 := by | |
| have he : (β t,k t*Fintype.card (D t))=Z*R := by | |
| simp only [k,β Finset.mul_sum] | |
| dsimp [K,R,B] | |
| ring | |
| rw [he] | |
| have hi : 2*R*(R+I0)β€I0^2 := by dsimp [I0]; nlinarith | |
| have hh := Nat.mul_le_mul_left (Z^2) hi | |
| dsimp [I] | |
| nlinarith only [hh] | |
| apply scalable_square_win hA k I (fun _=>Nat.mul_pos hZ hH) anchor hn | |
| (familyKey c) (familyProgram c) m (familyProgram_matrix c) | |
| (familyMultiplicity_key c n a hcap) dummy hdpos hdm hdt S _ hsave _ _ hR | |
| Β· intro t | |
| dsimp [S,k] | |
| simpa only [mul_one] using Nat.mul_le_mul_left (2*K) (hsp t) | |
| Β· intro t | |
| exact dvd_mul_of_dvd_right (hdH t) Z | |
| Β· intro t | |
| exact dvd_mul_of_dvd_left (dvd_mul_of_dvd_right (dvd_mul_of_dvd_right (hdH t) Z) 2) (s t) | |
| theorem positive_comparison_win (hA : β t,IsUnit (A t)) | |
| (anchor : Ο) (hn : Β¬MonomialMatrix (A anchor)) | |
| (c : ΟβPairComparison (A := A)) (lam : Οββ) (hlam : β r,0β€lam r) | |
| (hpos : β t,0<β r,lam r*((c r).delta t : β)) : FiniteWinStatement := by | |
| obtain β¨l,hlβ© := integral_positive_combination (fun r=>(c r).delta) lam hlam hpos | |
| exact integer_comparison_win hA anchor hn c l hl | |
| end ExactFourier.Packing | |
| end | |
| end | |
| end OAI | |