Download data/lean/OAI/NumberTheory/GaussianMoat/SignedGeometry.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 33.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/NumberTheory/GaussianMoat/SignedGeometry.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/NumberTheory/GaussianMoat/SignedGeometry.lean
-
curl -L -o SignedGeometry.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/NumberTheory/GaussianMoat/SignedGeometry.lean
33.1 kB
| import OAI.NumberTheory.GaussianMoat.BooleanCube | |
| namespace OAI | |
| universe uIota | |
| namespace GaussianMoat | |
| open MeasureTheory ProbabilityTheory | |
| open scoped NNReal | |
| def cubeEquiv : (n : β) β Cube n β (Fin n β Bool) | |
| | 0 => { | |
| toFun := fun _ i => Fin.elim0 i | |
| invFun := fun _ => () | |
| left_inv := fun x => by cases x; rfl | |
| right_inv := fun f => by funext i; exact Fin.elim0 i } | |
| | n+1 => (Equiv.prodCongr (Equiv.refl Bool) (cubeEquiv n)).trans (Fin.consEquiv (fun _ => Bool)) | |
| noncomputable def cubeSignEquiv (ΞΉ : Type uIota) [Fintype ΞΉ] : Cube (Fintype.card ΞΉ) β (ΞΉ β Bool) := | |
| (cubeEquiv (Fintype.card ΞΉ)).trans | |
| (Equiv.arrowCongr (Fintype.equivFin ΞΉ).symm (Equiv.refl Bool)) | |
| noncomputable def signDist {ΞΉ : Type uIota} [Fintype ΞΉ] (Ο Ο : ΞΉ β Bool) : β := by | |
| classical | |
| exact β i, if Ο i = Ο i then 0 else 1 | |
| theorem cubeEquiv_dist (n : β) (x y : Cube n) : | |
| signDist (cubeEquiv n x) (cubeEquiv n y) = cubeDist n x y := by | |
| classical | |
| induction n with | |
| | zero => simp [signDist, cubeDist] | |
| | succ n ih => | |
| obtain β¨b,xβ© := x | |
| obtain β¨c,yβ© := y | |
| simp only [signDist, Fin.sum_univ_succ, cubeEquiv, Equiv.trans_apply, | |
| Equiv.prodCongr_apply, Fin.consEquiv_apply, Fin.cons_zero, | |
| Fin.cons_succ, cubeDist] | |
| congr 1 | |
| exact ih x y | |
| theorem cubeSignEquiv_dist (ΞΉ : Type uIota) [Fintype ΞΉ] (x y : Cube (Fintype.card ΞΉ)) : | |
| signDist (cubeSignEquiv ΞΉ x) (cubeSignEquiv ΞΉ y) = cubeDist (Fintype.card ΞΉ) x y := by | |
| classical | |
| rw [β cubeEquiv_dist] | |
| unfold signDist cubeSignEquiv | |
| simp only [Equiv.trans_apply, Equiv.arrowCongr_apply, Equiv.symm_symm] | |
| exact (Fintype.equivFin ΞΉ).sum_comp (fun i => if cubeEquiv (Fintype.card ΞΉ) x i = | |
| cubeEquiv (Fintype.card ΞΉ) y i then (0 : β) else 1) | |
| theorem signMeasure_real_singleton {ΞΉ : Type uIota} [Fintype ΞΉ] (Ο : ΞΉ β Bool) : | |
| (signMeasure ΞΉ).real {Ο} = ((2 : β)^Fintype.card ΞΉ)β»ΒΉ := by | |
| simp [measureReal_def, signMeasure, Measure.pi_singleton, fairCoin, | |
| PMF.uniformOfFintype_apply] | |
| open scoped Classical in | |
| theorem signMeasure_real_set {ΞΉ : Type uIota} [Fintype ΞΉ] (S : Set (ΞΉ β Bool)) : | |
| (signMeasure ΞΉ).real S = (β Ο, if Ο β S then (1 : β) else 0) / | |
| (2 : β)^Fintype.card ΞΉ := by | |
| classical | |
| have he : S = (β(Finset.univ.filter (Β· β S)) : Set (ΞΉ β Bool)) := by ext; simp | |
| conv_lhs => rw [he, β sum_measureReal_singleton] | |
| rw [Finset.sum_filter, Finset.sum_div] | |
| apply Finset.sum_congr rfl | |
| intro Ο _ | |
| by_cases hΟ : Ο β S <;> simp [hΟ, signMeasure_real_singleton] | |
| theorem cubeSignEquiv_measure {ΞΉ : Type uIota} [Fintype ΞΉ] (S : (ΞΉ β Bool) β Prop) : | |
| (signMeasure ΞΉ).real {Ο | S Ο} = | |
| (cubeSize (fun x => S (cubeSignEquiv ΞΉ x)) : β) / (2 : β)^Fintype.card ΞΉ := by | |
| classical | |
| rw [signMeasure_real_set] | |
| congr 1 | |
| simp only [Set.mem_ofPred_eq] | |
| rw [β (cubeSignEquiv ΞΉ).sum_comp (fun Ο => if S Ο then (1 : β) else 0)] | |
| simp only [cubeSize, Nat.cast_sum, Nat.cast_ite, Nat.cast_one, Nat.cast_zero] | |
| noncomputable def SplitSieve.extendSigns (s : SplitSieve) (Ο : s.primes β Bool) (p : β) : Bool := by | |
| classical | |
| exact if hp : p β s.primes then Ο β¨p,hpβ© else false | |
| @[simp] theorem SplitSieve.extendSigns_mem (s : SplitSieve) (Ο : s.primes β Bool) | |
| (p : β) (hp : p β s.primes) : s.extendSigns Ο p = Ο β¨p,hpβ© := by | |
| simp [SplitSieve.extendSigns, hp] | |
| noncomputable def SplitSieve.signedProduct (s : SplitSieve) (Ο : s.primes β Bool) : GaussianInt := | |
| β p β s.primes, signedFactor (s.factor p) (s.extendSigns Ο p) | |
| theorem SplitSieve.line_witness_log_lower (s : SplitSieve) (Ο : s.primes β Bool) | |
| {v w : GaussianInt} (hv : PrimitiveDirection v) (hv0 : v β 0) (hw : w β 0) | |
| (hline : determinant v w = 0) (hdiv : s.signedProduct Ο β£ w) | |
| {B : β} (hbound : (w.norm : β) β€ B) : | |
| Real.log (v.norm : β) / 2 + (β p : s.primes, Real.log (p : β)) - Real.log B / 2 β€ | |
| β p : s.primes, s.lineLog v p (Ο p) := by | |
| classical | |
| let t := s.primes.filter (fun p => Β¬signedFactor (s.factor p) (s.extendSigns Ο p) β£ v) | |
| have hp (p : β) (hp : p β t) : 0 < (p : β) := by | |
| exact_mod_cast (s.prime_mem p (Finset.mem_filter.mp hp).1).pos | |
| have hprod : 0 < β p β t, (p : β) := Finset.prod_pos hp | |
| have hvpos : 0 < (v.norm : β) := by exact_mod_cast (GaussianInt.norm_pos.mpr hv0) | |
| have hlo := s.line_witness_norm_lower s.primes (fun _ h => h) (s.extendSigns Ο) hv hw hline hdiv | |
| have hlow : (v.norm : β) * (β p β t, (p : β))^2 β€ B := by | |
| apply le_trans ?_ hbound | |
| have hc : ((v.norm * (β p β t, (p : β€))^2 : β€) : β) β€ (w.norm : β) := by exact_mod_cast hlo | |
| push_cast at hc | |
| exact hc | |
| have hlog := Real.log_le_log (mul_pos hvpos (sq_pos_of_pos hprod)) hlow | |
| rw [Real.log_mul hvpos.ne' (sq_pos_of_pos hprod).ne', Real.log_pow, | |
| Real.log_prod (fun p hp' => (hp p hp').ne')] at hlog | |
| have hsum : (β p β t, Real.log (p : β)) = | |
| (β p : s.primes, Real.log (p : β)) - β p : s.primes, s.lineLog v p (Ο p) := by | |
| calc | |
| _ = β p β s.primes, (Real.log (p : β) - s.lineLog v p (s.extendSigns Ο p)) := by | |
| unfold t | |
| rw [Finset.sum_filter] | |
| apply Finset.sum_congr rfl | |
| intro p hp' | |
| unfold SplitSieve.lineLog | |
| split_ifs <;> simp_all | |
| _ = _ := by | |
| rw [β Finset.sum_coe_sort s.primes | |
| (fun p => Real.log (p : β) - s.lineLog v p (s.extendSigns Ο p))] | |
| simp [SplitSieve.extendSigns, Finset.sum_sub_distrib] | |
| rw [hsum] at hlog | |
| norm_num only [Nat.cast_ofNat] at hlog | |
| linarith only [hlog] | |
| def SplitSieve.lineEvent (s : SplitSieve) (Q : Set GaussianInt) (v : GaussianInt) | |
| (Ο : s.primes β Bool) : Prop := | |
| β w β Q, w β 0 β§ determinant v w = 0 β§ s.signedProduct Ο β£ w | |
| theorem SplitSieve.line_event_tail (s : SplitSieve) {Q : Set GaussianInt} | |
| {v : GaussianInt} (hv : PrimitiveDirection v) (hv0 : v β 0) {B Ξ΅ : β} | |
| (hQ : β w β Q, (w.norm : β) β€ B) (hΞ΅ : 0 β€ Ξ΅) | |
| (hexcess : Ξ΅ β€ (β p : s.primes, Real.log (p : β)) - Real.log B / 2) : | |
| (signMeasure s.primes).real {Ο | s.lineEvent Q v Ο} β€ | |
| Real.exp (-Ξ΅^2 / (2 * β p : s.primes, | |
| (((βReal.log (p : β)ββ / 2)^2 : ββ₯0) : β))) := by | |
| apply le_trans (measureReal_mono (sβ := {Ο | | |
| Real.log (v.norm : β) / 2 + Ξ΅ β€ β p : s.primes, s.lineLog v p (Ο p)}) ?_) | |
| Β· exact s.lineLog_tail hv hv0 hΞ΅ | |
| Β· rintro Ο β¨w,hwQ,hw,hline,hdβ© | |
| have hl := s.line_witness_log_lower Ο hv hv0 hw hline hd (hQ w hwQ) | |
| change Real.log (v.norm : β) / 2 + Ξ΅ β€ _ | |
| linarith | |
| open scoped Classical in | |
| noncomputable def SplitSieve.commonProduct (s : SplitSieve) (Ο Ο : s.primes β Bool) : GaussianInt := | |
| β p β s.primes.filter (fun p => s.extendSigns Ο p = s.extendSigns Ο p), | |
| signedFactor (s.factor p) (s.extendSigns Ο p) | |
| theorem SplitSieve.commonProduct_dvd_left (s : SplitSieve) (Ο Ο : s.primes β Bool) : | |
| s.commonProduct Ο Ο β£ s.signedProduct Ο := by | |
| classical | |
| exact Finset.prod_dvd_prod_of_subset _ _ _ (Finset.filter_subset _ _) | |
| theorem SplitSieve.commonProduct_comm (s : SplitSieve) (Ο Ο : s.primes β Bool) : | |
| s.commonProduct Ο Ο = s.commonProduct Ο Ο := by | |
| classical | |
| unfold SplitSieve.commonProduct | |
| apply Finset.prod_congr | |
| Β· ext p | |
| simp only [Finset.mem_filter, eq_comm] | |
| Β· intro p hp | |
| rw [(Finset.mem_filter.mp hp).2] | |
| theorem SplitSieve.commonProduct_dvd_right (s : SplitSieve) (Ο Ο : s.primes β Bool) : | |
| s.commonProduct Ο Ο β£ s.signedProduct Ο := by | |
| rw [s.commonProduct_comm] | |
| exact s.commonProduct_dvd_left Ο Ο | |
| open scoped Classical in | |
| theorem SplitSieve.signDist_eq_card (s : SplitSieve) (Ο Ο : s.primes β Bool) : | |
| signDist Ο Ο = (s.primes.filter (fun p => s.extendSigns Ο p β s.extendSigns Ο p)).card := by | |
| classical | |
| rw [Finset.card_eq_sum_ones, Finset.sum_filter, β Finset.sum_coe_sort s.primes | |
| (fun p => if s.extendSigns Ο p β s.extendSigns Ο p then 1 else 0)] | |
| unfold signDist | |
| apply Finset.sum_congr rfl | |
| intro p _ | |
| simp [SplitSieve.extendSigns] | |
| theorem SplitSieve.period_le_common_norm (s : SplitSieve) (Ο Ο : s.primes β Bool) | |
| {U : β} (hpU : β p β s.primes, (p : β) β€ U) : | |
| (s.period : β) β€ ((s.commonProduct Ο Ο).norm : β) * U^(signDist Ο Ο) := by | |
| classical | |
| let c := s.primes.filter (fun p => s.extendSigns Ο p = s.extendSigns Ο p) | |
| let d := s.primes.filter (fun p => s.extendSigns Ο p β s.extendSigns Ο p) | |
| have hc : ((s.commonProduct Ο Ο).norm : β) = β p β c, (p : β) := by | |
| unfold SplitSieve.commonProduct | |
| rw [norm_finset_prod, Int.cast_prod] | |
| apply Finset.prod_congr rfl | |
| intro p hp | |
| rw [signedFactor_norm, s.factor_norm p (Finset.mem_filter.mp hp).1] | |
| exact_mod_cast (rfl : (p : β) = p) | |
| have hd : (β p β d, (p : β)) β€ U^d.card := by | |
| rw [β Finset.prod_const] | |
| exact Finset.prod_le_prodβ (fun p _ => Nat.cast_nonneg p) | |
| (fun p hp => hpU p (Finset.mem_filter.mp hp).1) | |
| have hp : (s.period : β) = (β p β c, (p : β)) * (β p β d, (p : β)) := by | |
| unfold SplitSieve.period | |
| push_cast | |
| exact (Finset.prod_filter_mul_prod_filter_not s.primes | |
| (fun p => s.extendSigns Ο p = s.extendSigns Ο p) (fun p => (p : β))).symm | |
| rw [hp, hc, s.signDist_eq_card] | |
| exact mul_le_mul_of_nonneg_left hd (Finset.prod_nonneg (fun p _ => Nat.cast_nonneg p)) | |
| theorem SplitSieve.near_witnesses_collinear (s : SplitSieve) (Ο Ο : s.primes β Bool) | |
| {w w' : GaussianInt} (hw : s.signedProduct Ο β£ w) (hw' : s.signedProduct Ο β£ w') | |
| {U B : β} (hU : 0 < U) (hpU : β p β s.primes, (p : β) β€ U) | |
| (hdet : (|determinant w w'| : β) β€ B) | |
| (hsmall : B * U^(signDist Ο Ο) < (s.period : β)) : determinant w w' = 0 := by | |
| have hbound := lt_of_lt_of_le hsmall (s.period_le_common_norm Ο Ο hpU) | |
| have hlt : B < ((s.commonProduct Ο Ο).norm : β) := | |
| (mul_lt_mul_iff_leftβ (pow_pos hU _)).mp (by simpa only [mul_comm] using hbound) | |
| apply determinant_eq_zero_of_common_factor | |
| ((s.commonProduct_dvd_left Ο Ο).trans hw) ((s.commonProduct_dvd_right Ο Ο).trans hw') | |
| exact_mod_cast hdet.trans_lt hlt | |
| theorem determinant_zero_trans {u v w : GaussianInt} (hv : v β 0) | |
| (huv : determinant u v = 0) (hvw : determinant v w = 0) : | |
| determinant u w = 0 := by | |
| have hcoord : v.re β 0 β¨ v.im β 0 := by | |
| contrapose! hv | |
| ext <;> simp [hv.1, hv.2] | |
| unfold determinant at * | |
| rcases hcoord with hr | hi | |
| Β· apply (mul_eq_zero.mp (show v.re * (u.re * w.im - u.im * w.re) = 0 by | |
| nlinarith [congrArg (fun x : β€ => x * w.re) huv, | |
| congrArg (fun x : β€ => u.re * x) hvw])).resolve_left hr | |
| Β· apply (mul_eq_zero.mp (show v.im * (u.re * w.im - u.im * w.re) = 0 by | |
| nlinarith [congrArg (fun x : β€ => x * w.im) huv, | |
| congrArg (fun x : β€ => u.im * x) hvw])).resolve_left hi | |
| @[simp] theorem determinant_self (v : GaussianInt) : determinant v v = 0 := by | |
| unfold determinant | |
| ring | |
| theorem determinant_swap (u v : GaussianInt) : determinant u v = -determinant v u := by | |
| unfold determinant | |
| ring | |
| def witnessLine (v : GaussianInt) : Set GaussianInt := {w | determinant v w = 0} | |
| theorem witnessLine_eq {v w : GaussianInt} (hv : v β 0) (hw : w β 0) | |
| (hvw : determinant v w = 0) : witnessLine v = witnessLine w := by | |
| ext u | |
| constructor | |
| Β· intro hu | |
| exact determinant_zero_trans hv (by rw [determinant_swap, hvw, neg_zero]) hu | |
| Β· exact determinant_zero_trans hw hvw | |
| def SplitSieve.badSign (s : SplitSieve) (Q : Set GaussianInt) (Ο : s.primes β Bool) : Prop := | |
| β w β Q, w β 0 β§ s.signedProduct Ο β£ w | |
| noncomputable def SplitSieve.badWitness (s : SplitSieve) (Q : Set GaussianInt) | |
| (Ο : {Ο : s.primes β Bool // s.badSign Q Ο}) : GaussianInt := Ο.property.choose | |
| theorem SplitSieve.badWitness_spec (s : SplitSieve) (Q : Set GaussianInt) | |
| (Ο : {Ο : s.primes β Bool // s.badSign Q Ο}) : | |
| s.badWitness Q Ο β Q β§ s.badWitness Q Ο β 0 β§ s.signedProduct Ο.val β£ s.badWitness Q Ο := | |
| Ο.property.choose_spec | |
| def SplitSieve.badLines (s : SplitSieve) (Q : Set GaussianInt) : Set (Set GaussianInt) := | |
| Set.range (fun Ο : {Ο : s.primes β Bool // s.badSign Q Ο} => witnessLine (s.badWitness Q Ο)) | |
| instance SplitSieve.badLines_finite (s : SplitSieve) (Q : Set GaussianInt) : | |
| Finite (s.badLines Q) := by | |
| unfold SplitSieve.badLines | |
| infer_instance | |
| theorem SplitSieve.badLine_primitive (s : SplitSieve) (Q : Set GaussianInt) | |
| (L : s.badLines Q) : β v : GaussianInt, PrimitiveDirection v β§ v β 0 β§ witnessLine v = L.val := by | |
| obtain β¨Ο, hΟβ© := L.property | |
| have hw := s.badWitness_spec Q Ο | |
| obtain β¨v,hv,hv0,a,_hanz,haβ© := exists_primitive_direction hw.2.1 | |
| refine β¨v,hv,hv0, ?_β© | |
| rw [β hΟ] | |
| apply witnessLine_eq hv0 hw.2.1 | |
| rw [ha] | |
| unfold determinant | |
| simp only [Zsqrtd.re_mul, Zsqrtd.im_mul, Zsqrtd.re_intCast, Zsqrtd.im_intCast] | |
| ring | |
| def SplitSieve.lineClass (s : SplitSieve) (Q : Set GaussianInt) (L : s.badLines Q) | |
| (Ο : s.primes β Bool) : Prop := | |
| β hΟ : s.badSign Q Ο, witnessLine (s.badWitness Q β¨Ο,hΟβ©) = L.val | |
| theorem SplitSieve.badSign_iff_class (s : SplitSieve) (Q : Set GaussianInt) (Ο : s.primes β Bool) : | |
| s.badSign Q Ο β β L : s.badLines Q, s.lineClass Q L Ο := by | |
| constructor | |
| Β· intro hΟ | |
| exact β¨β¨witnessLine (s.badWitness Q β¨Ο,hΟβ©), β¨β¨Ο,hΟβ©,rflβ©β©, hΟ, rflβ© | |
| Β· rintro β¨L,hΟ,_β© | |
| exact hΟ | |
| theorem SplitSieve.lineClass_subset_event (s : SplitSieve) (Q : Set GaussianInt) | |
| (L : s.badLines Q) {v : GaussianInt} (hvL : witnessLine v = L.val) : | |
| {Ο | s.lineClass Q L Ο} β {Ο | s.lineEvent Q v Ο} := by | |
| rintro Ο β¨hΟ,hLβ© | |
| have hw := s.badWitness_spec Q β¨Ο,hΟβ© | |
| refine β¨_,hw.1,hw.2.1,?_,hw.2.2β© | |
| change s.badWitness Q β¨Ο,hΟβ© β witnessLine v | |
| rw [hvL, β hL] | |
| exact determinant_self _ | |
| theorem SplitSieve.lineClasses_separated (s : SplitSieve) (Q : Set GaussianInt) | |
| {U B : β} (hU : 1 β€ U) (hpU : β p β s.primes, (p : β) β€ U) | |
| (hdet : β w β Q, β w' β Q, (|determinant w w'| : β) β€ B) | |
| {h : β} (hsmall : B * U^(2*h) < (s.period : β)) (hB : 0 β€ B) : | |
| β L L' : s.badLines Q, L β L' β β Ο, s.lineClass Q L Ο β | |
| β Ο, s.lineClass Q L' Ο β 2*h < signDist Ο Ο := by | |
| intro L L' hLL Ο β¨hΟ,hΟLβ© Ο β¨hΟ,hΟLβ© | |
| by_contra hn | |
| have hd : signDist Ο Ο β€ 2*h := le_of_not_gt hn | |
| have hw := s.badWitness_spec Q β¨Ο,hΟβ© | |
| have hw' := s.badWitness_spec Q β¨Ο,hΟβ© | |
| have hsm : B * U^(signDist Ο Ο) < (s.period : β) := | |
| (mul_le_mul_of_nonneg_left (pow_le_pow_rightβ hU hd) hB).trans_lt hsmall | |
| have hcol := s.near_witnesses_collinear Ο Ο hw.2.2 hw'.2.2 (by linarith) hpU | |
| (hdet _ hw.1 _ hw'.1) hsm | |
| apply hLL | |
| apply Subtype.ext | |
| rw [β hΟL, β hΟL] | |
| exact witnessLine_eq hw.2.1 hw'.2.1 hcol | |
| theorem cubeSize_exists_le_sum {n : β} {ΞΉ : Type uIota} [Fintype ΞΉ] | |
| (S : ΞΉ β Cube n β Prop) : cubeSize (fun x => β i, S i x) β€ β i, cubeSize (S i) := by | |
| classical | |
| unfold cubeSize | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_le_sum | |
| intro x _ | |
| by_cases hx : β i, S i x | |
| Β· obtain β¨i, hiβ© := hx | |
| rw [ite_eq_left β¨i,hiβ©] | |
| have h : (if S i x then 1 else 0) β€ β j : ΞΉ, if S j x then 1 else 0 := | |
| Finset.single_le_sum (f := fun j => if S j x then (1 : β) else 0) | |
| (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) | |
| simpa only [ite_eq_left hi] using h | |
| Β· simp only [ite_eq_right hx] | |
| exact Nat.zero_le _ | |
| theorem SplitSieve.signed_region_bound (s : SplitSieve) (Q : Set GaussianInt) | |
| (hr : 0 < s.primes.card) {U B N Ξ΅ a E A : β} {h : β} | |
| (hU : 1 β€ U) (hpU : β p β s.primes, (p : β) β€ U) | |
| (hB : 0 β€ B) (hdet : β w β Q, β w' β Q, (|determinant w w'| : β) β€ B) | |
| (hsmall : B * U^(2*h) < (s.period : β)) | |
| (hQ : β w β Q, (w.norm : β) β€ N) (hΞ΅ : 0 β€ Ξ΅) | |
| (hexcess : Ξ΅ β€ (β p : s.primes, Real.log (p : β)) - Real.log N / 2) | |
| (ha : 0 β€ a) (hE : 0 < E) (hA : 0 < A) | |
| (hlogE : Real.log E β€ (s.primes.card : β) * Real.log 2 - a) | |
| (hseed : A * Real.exp (-Ξ΅^2 / (2 * β p : s.primes, | |
| (((βReal.log (p : β)ββ / 2)^2 : ββ₯0) : β))) * (2 : β)^s.primes.card β€ E) | |
| (hfactor : A β€ (1 + a / ((s.primes.card : β)*Real.log 2))^h) : | |
| (signMeasure s.primes).real {Ο | s.badSign Q Ο} β€ Aβ»ΒΉ := by | |
| classical | |
| let : Fintype (s.badLines Q) := Fintype.ofFinite _ | |
| let S : s.badLines Q β Cube (Fintype.card s.primes) β Prop := | |
| fun L x => s.lineClass Q L (cubeSignEquiv s.primes x) | |
| have hcard : Fintype.card s.primes = s.primes.card := Fintype.card_coe _ | |
| have hpow : 0 < (2 : β)^Fintype.card s.primes := pow_pos (by norm_num) _ | |
| have hseed' (L : s.badLines Q) : A * cubeSize (S L) β€ E := by | |
| obtain β¨v,hv,hv0,hvLβ© := s.badLine_primitive Q L | |
| have hm := (measureReal_mono (s.lineClass_subset_event Q L hvL)).trans | |
| (s.line_event_tail hv hv0 hQ hΞ΅ hexcess) | |
| rw [cubeSignEquiv_measure] at hm | |
| have hc : (cubeSize (S L) : β) β€ Real.exp (-Ξ΅^2 / (2 * β p : s.primes, | |
| (((βReal.log (p : β)ββ / 2)^2 : ββ₯0) : β))) * (2 : β)^Fintype.card s.primes := | |
| (div_le_iffβ hpow).mp hm | |
| have hh := mul_le_mul_of_nonneg_left hc hA.le | |
| exact hh.trans (by simpa only [hcard, mul_assoc] using hseed) | |
| have hsep : β L L' : s.badLines Q, L β L' β β x, S L x β β y, S L' y β | |
| 2*h < cubeDist (Fintype.card s.primes) x y := by | |
| intro L L' hLL x hx y hy | |
| have hh := s.lineClasses_separated Q hU hpU hdet hsmall hB L L' hLL | |
| (cubeSignEquiv s.primes x) hx (cubeSignEquiv s.primes y) hy | |
| simpa only [cubeSignEquiv_dist] using hh | |
| have hpack := cube_separated_bound (n := Fintype.card s.primes) (h := h) | |
| (by simpa only [hcard] using hr) S ha hE (by simpa only [hcard] using hlogE) | |
| hseed' (by simpa only [hcard] using hfactor) hsep | |
| have hunion : (cubeSize (fun x => s.badSign Q (cubeSignEquiv s.primes x)) : β) β€ | |
| β L, (cubeSize (S L) : β) := by | |
| have he : (fun x => s.badSign Q (cubeSignEquiv s.primes x)) = (fun x => β L, S L x) := by | |
| funext x | |
| exact propext (s.badSign_iff_class Q _) | |
| rw [he] | |
| exact_mod_cast cubeSize_exists_le_sum S | |
| rw [cubeSignEquiv_measure, div_le_iffβ hpow] | |
| have hh := (mul_le_mul_of_nonneg_left hunion hA.le).trans hpack | |
| calc | |
| _ β€ (2 : β)^Fintype.card s.primes / A := (le_div_iffβ hA).mpr (by simpa only [mul_comm] using hh) | |
| _ = _ := by rw [div_eq_mul_inv, mul_comm] | |
| theorem SplitSieve.signed_region_exp_bound (s : SplitSieve) (Q : Set GaussianInt) | |
| (hr : 0 < s.primes.card) {U B N Ξ΅ a b : β} {h : β} | |
| (hU : 1 β€ U) (hpU : β p β s.primes, (p : β) β€ U) | |
| (hB : 0 β€ B) (hdet : β w β Q, β w' β Q, (|determinant w w'| : β) β€ B) | |
| (hsmall : B * U^(2*h) < (s.period : β)) | |
| (hQ : β w β Q, (w.norm : β) β€ N) (hΞ΅ : 0 β€ Ξ΅) | |
| (hexcess : Ξ΅ β€ (β p : s.primes, Real.log (p : β)) - Real.log N / 2) | |
| (ha : 0 β€ a) (hb : b β€ a) | |
| (htail : 2*a β€ Ξ΅^2 / (2 * β p : s.primes, | |
| (((βReal.log (p : β)ββ / 2)^2 : ββ₯0) : β))) | |
| (hgrowth : b β€ (h : β) * Real.log (1 + a / ((s.primes.card : β)*Real.log 2))) : | |
| (signMeasure s.primes).real {Ο | s.badSign Q Ο} β€ Real.exp (-b) := by | |
| have htwo : 0 < Real.log 2 := Real.log_pos (by norm_num) | |
| have hr' : 0 < (s.primes.card : β) := by exact_mod_cast hr | |
| have hbase : 0 < 1 + a / ((s.primes.card : β)*Real.log 2) := by | |
| have := div_nonneg ha (mul_pos hr' htwo).le | |
| linarith | |
| have hbexp : Real.exp b β€ (1 + a / ((s.primes.card : β)*Real.log 2))^h := by | |
| rw [β Real.exp_log (pow_pos hbase h)] | |
| apply Real.exp_le_exp.mpr | |
| simpa only [Real.log_pow] using hgrowth | |
| have hh := s.signed_region_bound Q hr hU hpU hB hdet hsmall hQ hΞ΅ hexcess ha | |
| (E := (2 : β)^s.primes.card * Real.exp (-a)) | |
| (A := Real.exp b) (h := h) (mul_pos (pow_pos (by norm_num) _) (Real.exp_pos _)) | |
| (Real.exp_pos _) (by | |
| rw [Real.log_mul (pow_pos (by norm_num : (0 : β) < 2) _).ne' (Real.exp_pos _).ne', | |
| Real.log_pow, Real.log_exp] | |
| linarith) (by | |
| rw [β Real.exp_add] | |
| have he : b + -Ξ΅^2 / (2 * β p : s.primes, | |
| (((βReal.log (p : β)ββ / 2)^2 : ββ₯0) : β)) β€ -a := by | |
| rw [neg_div] | |
| linarith | |
| exact (mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr he) | |
| (pow_nonneg (by norm_num) _)).trans_eq (mul_comm _ _)) hbexp | |
| simpa only [Real.exp_neg] using hh | |
| def orientedRectangle (e : β) (R W : β) : Set GaussianInt := | |
| {z | |(star e * (z : β)).re| β€ R β§ |(star e * (z : β)).im| β€ W} | |
| theorem rectangle_norm_bound {e : β} (he : βeβ = 1) {R W : β} | |
| (hW : 0 β€ W) (hWR : W β€ R) {z : GaussianInt} (hz : z β orientedRectangle e R W) : | |
| (z.norm : β) β€ 2 * R^2 := by | |
| have hnorm : βstar e * (z : β)β = β(z : β)β := by | |
| rw [norm_mul, norm_star, he, one_mul] | |
| rw [norm_square_complex, β hnorm, β Complex.normSq_eq_norm_sq, Complex.normSq_apply] | |
| have hx : (star e * (z : β)).re ^ 2 β€ R^2 := by | |
| simpa only [sq_abs] using (sq_le_sqβ (abs_nonneg ((star e * (z : β)).re)) | |
| (hW.trans hWR)).mpr hz.1 | |
| have hy : (star e * (z : β)).im ^ 2 β€ W^2 := by | |
| simpa only [sq_abs] using (sq_le_sqβ (abs_nonneg ((star e * (z : β)).im)) hW).mpr hz.2 | |
| have hww := (sq_le_sqβ hW (hW.trans hWR)).mpr hWR | |
| nlinarith | |
| theorem determinant_rotated (e : β) (he : βeβ = 1) (z w : GaussianInt) : | |
| (determinant z w : β) = | |
| (star e * (z : β)).re * (star e * (w : β)).im - | |
| (star e * (z : β)).im * (star e * (w : β)).re := by | |
| have hsq : e.re^2 + e.im^2 = 1 := by | |
| have hh := Complex.normSq_eq_norm_sq e | |
| rw [he] at hh | |
| simpa [Complex.normSq_apply, pow_two] using hh | |
| simp only [Complex.mul_re, Complex.mul_im, Complex.star_def, Complex.conj_re, Complex.conj_im, | |
| β GaussianInt.intCast_re, β GaussianInt.intCast_im, determinant, Int.cast_sub, Int.cast_mul] | |
| nlinarith [congrArg (fun x : β => x * ((z.re : β) * w.im - z.im * w.re)) hsq] | |
| theorem rectangle_determinant_bound {e : β} (he : βeβ = 1) {R W : β} | |
| (hR : 0 β€ R) (hW : 0 β€ W) {z w : GaussianInt} | |
| (hz : z β orientedRectangle e R W) (hw : w β orientedRectangle e R W) : | |
| (|determinant z w| : β) β€ 2*R*W := by | |
| rw [determinant_rotated e he] | |
| apply (abs_sub _ _).trans | |
| rw [abs_mul, abs_mul] | |
| have h1 := mul_le_mul hz.1 hw.2 (abs_nonneg _) hR | |
| have h2 := mul_le_mul hz.2 hw.1 (abs_nonneg _) hW | |
| nlinarith | |
| theorem rectangle_cube_growth {r : β} {d : β} (hd : 0 < d) (hd1 : d β€ 1/4) | |
| (hlarge : 1000 β€ d^3 * r) : | |
| let h := βd * r / 10ββ | |
| d^3 * r / 5120 β€ (h : β) * Real.log (1 + (d^2 * r / 64) / ((r : β) * Real.log 2)) := by | |
| dsimp only | |
| have hr : 0 < (r : β) := by | |
| by_contra h | |
| have hr0 : (r : β) = 0 := le_antisymm (le_of_not_gt h) (Nat.cast_nonneg _) | |
| rw [hr0, mul_zero] at hlarge | |
| norm_num at hlarge | |
| have loglo : (1/2 : β) β€ Real.log 2 := by linarith [Real.log_two_gt_d9] | |
| have loghi : Real.log 2 β€ 1 := by linarith [Real.log_two_lt_d9] | |
| have hlog : 0 < Real.log 2 := lt_of_lt_of_le (by norm_num) loglo | |
| have hdle : d β€ 1 := by linarith | |
| have hsq : d^2 β€ 1 := by nlinarith | |
| have hdr : d^3 * r β€ d * r := by | |
| exact mul_le_mul_of_nonneg_right (by nlinarith [mul_nonneg hd.le (sub_nonneg.mpr hsq)]) hr.le | |
| have hfloor : d * r / 20 β€ (βd * r / 10ββ : β) := by | |
| have hh := Nat.lt_floor_add_one (d * r / 10) | |
| have hdrl : 1000 β€ d * r := hlarge.trans hdr | |
| linarith | |
| have heq : (d^2 * r / 64) / ((r : β) * Real.log 2) = d^2 / (64 * Real.log 2) := by | |
| field_simp | |
| let Ξ΄ := d^2 / (64 * Real.log 2) | |
| have hΞ΄ : 0 β€ Ξ΄ := div_nonneg (sq_nonneg _) (by positivity) | |
| have hΞ΄1 : Ξ΄ β€ 1 := by | |
| apply (div_le_iffβ (mul_pos (by norm_num) hlog)).mpr | |
| nlinarith | |
| have hΞ΄lo : d^2 / 64 β€ Ξ΄ := by | |
| apply (le_div_iffβ (mul_pos (by norm_num) hlog)).mpr | |
| nlinarith [mul_nonneg (sq_nonneg d) (sub_nonneg.mpr loghi)] | |
| have hlogΞ΄ : Ξ΄/2 β€ Real.log (1+Ξ΄) := by | |
| apply le_trans ?_ (Real.le_log_one_add_of_nonneg hΞ΄) | |
| apply (le_div_iffβ (by linarith : 0 < Ξ΄+2)).mpr | |
| nlinarith [mul_nonneg hΞ΄ (sub_nonneg.mpr hΞ΄1)] | |
| rw [heq] | |
| change _ β€ (βd * r / 10ββ : β) * Real.log (1+Ξ΄) | |
| have hm := mul_le_mul hfloor hlogΞ΄ (by linarith) (Nat.cast_nonneg _) | |
| have hm' : d^3 * r / 2560 β€ (d*r/20) * (Ξ΄/2) := by | |
| have := mul_le_mul_of_nonneg_left hΞ΄lo (by positivity : 0 β€ d*r/40) | |
| nlinarith | |
| have hnon : 0 β€ d^3 * r := by positivity | |
| nlinarith | |
| theorem rectangle_linear_large {r d : β} (hr : 0 β€ r) (hd : 0 β€ d) (hd1 : d β€ 1) | |
| (hlarge : 1000 β€ d^3 * r) : 1000 β€ d*r := by | |
| have hs : d^2 β€ 1 := by nlinarith | |
| have hc : d^3 β€ d := by nlinarith [mul_nonneg hd (sub_nonneg.mpr hs)] | |
| exact hlarge.trans (mul_le_mul_of_nonneg_right hc hr) | |
| theorem rectangle_log_small {r : β} {d t u l : β} | |
| (hd : 0 < d) (hd1 : d β€ 1/4) (ht : 1/2 β€ t) (hu : 0 β€ u) (hutu : u β€ 2*t) | |
| (hl : (r : β)*t β€ l) (hlarge : 1000 β€ d^3 * r) : | |
| Real.log 2 + (1-d)*l + (2*βd*r/10ββ : β)*u < l := by | |
| have hdr : 1000 β€ d*r := rectangle_linear_large (Nat.cast_nonneg _) hd.le (by linarith) hlarge | |
| have hf : (βd*r/10ββ : β) β€ d*r/10 := Nat.floor_le (by positivity) | |
| have hm : (2*βd*r/10ββ : β)*u β€ (d*r/5)*(2*t) := by | |
| push_cast | |
| apply mul_le_mul (by linarith) hutu hu | |
| positivity | |
| have hdl := mul_le_mul_of_nonneg_left hl hd.le | |
| have hdt : 500 β€ d*r*t := by | |
| have hh := mul_le_mul_of_nonneg_left ht (by positivity : 0 β€ d*r) | |
| nlinarith | |
| have hlog : Real.log 2 β€ 1 := by linarith [Real.log_two_lt_d9] | |
| nlinarith | |
| theorem rectangle_log_excess {r : β} {d t l : β} (hd : 0 < d) (hd1 : d β€ 1/4) | |
| (ht : 1/2 β€ t) (hl : (r : β)*t β€ l) (hlarge : 1000 β€ d^3 * r) : | |
| d*l/2 β€ l - ((1-d)*l + Real.log 2/2) := by | |
| have hdr : 1000 β€ d*r := rectangle_linear_large (Nat.cast_nonneg _) hd.le (by linarith) hlarge | |
| have h1 := mul_le_mul_of_nonneg_left hl hd.le | |
| have h2 := mul_le_mul_of_nonneg_left ht (by positivity : 0 β€ d*r) | |
| have hlog : Real.log 2 β€ 1 := by linarith [Real.log_two_lt_d9] | |
| nlinarith | |
| theorem rectangle_hoeffding_exponent {r d t l V : β} (hr : 0 < r) (hd : 0 β€ d) | |
| (ht : 0 < t) (hl : r*t β€ l) (hV : 0 < V) (hVup : V β€ r*t^2) : | |
| 2*(d^2*r/64) β€ (d*l/2)^2 / (2*V) := by | |
| have hdl : 0 β€ d*r*t/2 := by positivity | |
| have hdl' : d*r*t/2 β€ d*l/2 := by nlinarith [mul_le_mul_of_nonneg_left hl hd] | |
| have hs : (d*r*t/2)^2 β€ (d*l/2)^2 := (sq_le_sqβ hdl (hdl.trans hdl')).mpr hdl' | |
| have hden : 0 < 2*r*t^2 := by positivity | |
| calc | |
| 2*(d^2*r/64) β€ d^2*r/8 := by nlinarith [mul_nonneg (sq_nonneg d) hr.le] | |
| _ = (d*r*t/2)^2 / (2*r*t^2) := by field_simp; ring | |
| _ β€ (d*l/2)^2 / (2*r*t^2) := div_le_div_of_nonneg_right hs hden.le | |
| _ β€ (d*l/2)^2 / (2*V) := div_le_div_of_nonneg_left (sq_nonneg _) (by positivity) (by nlinarith) | |
| theorem SplitSieve.log_period (s : SplitSieve) : | |
| Real.log (s.period : β) = β p : s.primes, Real.log (p : β) := by | |
| classical | |
| unfold SplitSieve.period | |
| push_cast | |
| rw [Real.log_prod (fun p hp => by | |
| exact_mod_cast (s.prime_mem p hp).ne_zero)] | |
| exact (Finset.sum_coe_sort s.primes (fun p => Real.log (p : β))).symm | |
| noncomputable def SplitSieve.logVariance (s : SplitSieve) : β := | |
| β p : s.primes, (((βReal.log (p : β)ββ / 2)^2 : ββ₯0) : β) | |
| theorem SplitSieve.logVariance_pos (s : SplitSieve) (hr : 0 < s.primes.card) : | |
| 0 < s.logVariance := by | |
| classical | |
| obtain β¨p,hpβ© := Finset.card_pos.mp hr | |
| have hlog : 0 < Real.log (p : β) := Real.log_pos (by exact_mod_cast (s.prime_mem p hp).one_lt) | |
| apply Finset.sum_pos' (fun _ _ => by positivity) | |
| refine β¨β¨p,hpβ©, Finset.mem_univ _, ?_β© | |
| simp only [NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, coe_nnnorm, Real.norm_eq_abs, | |
| abs_of_pos hlog] | |
| positivity | |
| theorem SplitSieve.logVariance_le (s : SplitSieve) {U : β} | |
| (hU : 1 β€ U) (hpU : β p β s.primes, (p : β) β€ U) : | |
| s.logVariance β€ (s.primes.card : β) * (Real.log U / 2)^2 := by | |
| classical | |
| calc | |
| _ β€ β _p : s.primes, (Real.log U / 2)^2 := by | |
| apply Finset.sum_le_sum | |
| intro p _ | |
| have hp : 0 < (p : β) := by exact_mod_cast (s.prime_mem p p.property).pos | |
| have hlog : 0 β€ Real.log (p : β) := Real.log_nonneg (by exact_mod_cast (s.prime_mem p p.property).one_le) | |
| have hle := Real.log_le_log hp (hpU p p.property) | |
| simp only [NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, coe_nnnorm, Real.norm_eq_abs, | |
| abs_of_nonneg hlog] | |
| exact (sq_le_sqβ (by positivity) (div_nonneg (Real.log_nonneg hU) (by norm_num))).mpr (by linarith) | |
| _ = _ := by simp [nsmul_eq_mul] | |
| theorem SplitSieve.signed_rectangle (s : SplitSieve) | |
| {T R W d : β} {e : β} (he : βeβ = 1) (hT : 5 β€ T) | |
| (hpT : β p β s.primes, T β€ (p : β) β§ (p : β) β€ 2*T) | |
| (hW : 1 β€ W) (hWR : W β€ R) (hd : 0 < d) (hd1 : d < 1/4) | |
| (harea : R*W β€ (s.period : β)^(1-d)) (hlarge : 1000 β€ d^3*s.primes.card) : | |
| (signMeasure s.primes).real {Ο | s.badSign (orientedRectangle e R W) Ο} β€ | |
| Real.exp (-(d^3*s.primes.card/5120)) := by | |
| have hr : 0 < s.primes.card := by | |
| by_contra h | |
| have hz : s.primes.card = 0 := Nat.eq_zero_of_not_pos h | |
| rw [hz, Nat.cast_zero, mul_zero] at hlarge | |
| norm_num at hlarge | |
| have hr' : 0 < (s.primes.card : β) := by exact_mod_cast hr | |
| have hP : 0 < (s.period : β) := by exact_mod_cast s.period_pos | |
| have hTpos : 0 < T := by linarith | |
| have hU : 1 β€ 2*T := by linarith | |
| have hUpos : 0 < 2*T := by linarith | |
| have hWpos : 0 < W := by linarith | |
| have hRpos : 0 < R := lt_of_lt_of_le hWpos hWR | |
| have hRW : 0 < R*W := mul_pos hRpos hWpos | |
| have hlogT : 1/2 β€ Real.log T := by | |
| have hlog2T := Real.log_le_log (by norm_num : (0 : β) < 2) (by linarith : 2 β€ T) | |
| linarith [Real.log_two_gt_d9] | |
| have hlogU : Real.log (2*T) β€ 2*Real.log T := by | |
| rw [Real.log_mul (by norm_num) hTpos.ne'] | |
| have hh := Real.log_le_log (by norm_num : (0 : β) < 2) (by linarith : 2 β€ T) | |
| linarith | |
| have hlogP : (s.primes.card : β)*Real.log T β€ Real.log (s.period : β) := by | |
| rw [s.log_period] | |
| calc | |
| _ = β _p : s.primes, Real.log T := by simp [nsmul_eq_mul] | |
| _ β€ _ := Finset.sum_le_sum (fun p _ => Real.log_le_log hTpos (hpT p p.property).1) | |
| have hlogPpos : 0 < Real.log (s.period : β) := | |
| (mul_pos hr' (by linarith : 0 < Real.log T)).trans_le hlogP | |
| have hRarea : R β€ R*W := by nlinarith | |
| have hlogR : Real.log R β€ (1-d)*Real.log (s.period : β) := by | |
| have hh := Real.log_le_log hRpos (hRarea.trans harea) | |
| simpa only [Real.log_rpow hP] using hh | |
| have hlogB : Real.log (2*R*W) β€ Real.log 2 + (1-d)*Real.log (s.period : β) := by | |
| have hh := Real.log_le_log hRW harea | |
| rw [Real.log_rpow hP] at hh | |
| have heq : 2*R*W = 2*(R*W) := by ring | |
| rw [heq, Real.log_mul (by norm_num) hRW.ne'] | |
| linarith | |
| have hlogN : Real.log (2*R^2)/2 β€ (1-d)*Real.log (s.period : β) + Real.log 2/2 := by | |
| rw [Real.log_mul (by norm_num) (pow_pos hRpos 2).ne', Real.log_pow] | |
| norm_num only [Nat.cast_ofNat] | |
| linarith | |
| let h : β := βd*s.primes.card/10ββ | |
| have hsmall : (2*R*W) * (2*T)^(2*h) < (s.period : β) := by | |
| apply (Real.log_lt_log_iff (mul_pos (by positivity) (pow_pos hUpos _)) hP).mp | |
| rw [Real.log_mul (by positivity : 2*R*W β 0) (pow_pos hUpos _).ne', Real.log_pow] | |
| have hh := rectangle_log_small hd hd1.le hlogT (Real.log_nonneg hU) hlogU hlogP hlarge | |
| exact (add_le_add_left hlogB _).trans_lt hh | |
| have hV := s.logVariance_pos hr | |
| have hVup : s.logVariance β€ (s.primes.card : β)*(Real.log T)^2 := by | |
| apply (s.logVariance_le hU (fun p hp => (hpT p hp).2)).trans | |
| apply mul_le_mul_of_nonneg_left ?_ hr'.le | |
| apply (sq_le_sqβ (div_nonneg (Real.log_nonneg hU) (by norm_num)) (by linarith : 0 β€ Real.log T)).mpr | |
| linarith | |
| apply s.signed_region_exp_bound (orientedRectangle e R W) hr hU | |
| (fun p hp => (hpT p hp).2) (by positivity) (fun _ hw _ hw' => | |
| rectangle_determinant_bound he hRpos.le hWpos.le hw hw') hsmall | |
| (fun _ hz => rectangle_norm_bound he hWpos.le hWR hz) | |
| (Ξ΅ := d*Real.log (s.period : β)/2) (a := d^2*s.primes.card/64) (h := h) | |
| Β· positivity | |
| Β· rw [β s.log_period] | |
| have hh := rectangle_log_excess hd hd1.le hlogT hlogP hlarge | |
| linarith | |
| Β· positivity | |
| Β· have hc : d^3 β€ d^2 := by nlinarith [sq_nonneg d, mul_nonneg (sq_nonneg d) (by linarith : 0 β€ 1-d)] | |
| have hh := mul_le_mul_of_nonneg_right hc hr'.le | |
| nlinarith [mul_nonneg (sq_nonneg d) hr'.le] | |
| Β· exact rectangle_hoeffding_exponent hr' hd.le (by linarith) hlogP hV hVup | |
| Β· exact rectangle_cube_growth hd hd1.le hlarge | |
| end GaussianMoat | |
| end OAI | |