import Mathlib import OAI.Probability.CoordinateSweeps.Perturbation namespace OAI open scoped Matrix.Norms.L2Operator namespace CoordinateSweeps lemma moment_le_exp_of_logMoment_le {t B : ℝ} (ht : 0≤t) (h : logMoment t ≤ (B:EReal)) : t ≤ Real.exp B := by by_cases hz : t=0 · rw [hz]; exact (Real.exp_pos _).le · rw [logMoment,ite_eq_right hz] at h have hh : Real.log t ≤ B := by exact_mod_cast h simpa only [Real.exp_log (lt_of_le_of_ne ht (Ne.symm hz))] using Real.exp_le_exp.mpr hh lemma logMoment_le_of_moment_le_exp {t B : ℝ} (ht : 0≤t) (h : t≤Real.exp B) : logMoment t ≤ (B:EReal) := by simpa only [Real.log_exp] using logMoment_le_of_le ht (Real.exp_pos B) h end CoordinateSweeps namespace CoordinateSweeps.Grid.Holes open SparseScalar SparseDimension ScalarInduction variable {G : Grid} {h r : ℕ} (H : G.Holes h) lemma conditionalAverage_free_cancel (hf : H.Feasible) (z : ℝ) (σ : UnitaryIrrep H.stabilizer) : H.conditionalAverage hf z ((σ.pullback H.stabilizerFreeEquiv.symm).pullback H.stabilizerFreeEquiv)= H.conditionalAverage hf z σ := by rw [H.conditionalAverage_eq_sum,H.conditionalAverage_eq_sum] apply Finset.sum_congr rfl intro ω hω change (_:ℂ) • σ.matrix (H.stabilizerFreeEquiv.symm (H.stabilizerFreeEquiv (H.residual hf ω)))=_ rw [MulEquiv.symm_apply_apply] /-- Entire nonautomatic sparse-dimension branch of the conditional main, with the actual stabilizer irrep, actual feasible paths and a common real z interval. -/ theorem conditional_sparse_main (hr : ScaleLarge r) (hrS : ScaleReady r) (hG : G.Allowed r) (hS : MainSizeReady SparseScalar.q G.size) (hf : H.Feasible) {zStar : ℝ} (hζ : SparsePerturb r zStar) {z : ℝ} (hz : z∈Set.Icc 0 zStar) (σ : UnitaryIrrep H.stabilizer) (hσ : σ.dimension≠1) (ha : ¬ (1+c G.size)*Real.log σ.dimension ≤ e G.size*h*Real.log G.size-H.cost) (hF : Real.log σ.dimension < (G.size:ℝ)^(1-a/4)) : schattenMoment SparseScalar.q (H.conditionalAverage hf z σ) ≤ Real.exp (-c G.size*Real.log σ.dimension+e G.size*h*Real.log G.size-H.cost) := by let ρ := σ.pullback H.stabilizerFreeEquiv.symm obtain ⟨k,t,hkt,ht,hD,hkM,⟨L⟩⟩ := exists_level ρ have hΩ : Fintype.card (H.FreeAt 0)≤G.size := by rw [H.card_freeAt]; exact Nat.sub_le _ _ have hks := hkM.trans hΩ have hlogs := level_log_bounds ρ G.size_pos hΩ hkt ht hD change Real.log σ.dimension≤k*Real.log G.size ∧ (k:ℝ)≤4*Real.log σ.dimension at hlogs have hk : 1≤k := by by_contra hh have he : k=0 := by omega rw [he,pow_zero] at hD have hdim : σ.dimension=1 := by have hh0:=σ.positive; change σ.dimension≤1 at hD; omega exact hσ hdim have hL := (scale_coefficients hr G hG).1 have hc := (scale_coefficients hr G hG).2.1 have hc1 : c G.size≤1 := hc.trans (by norm_num [c0,a]) have hF0 : 0≤Real.log σ.dimension := Real.log_nonneg (by exact_mod_cast σ.positive) have hallow := H.allowance_lower hr hG have hn := lt_of_not_ge ha have hhh : (h:ℝ)*Real.log G.size ≤ K0*Real.log σ.dimension := by have hm := mul_le_mul_of_nonneg_right hc1 hF0 norm_num [e0,a,K0] at hallow ⊢ nlinarith have hh : (h:ℝ)≤K0*k := by have hm := mul_le_mul_of_nonneg_left hlogs.1 (by norm_num [K0] : 0≤K0) exact (mul_le_mul_iff_right₀ hL).mp (by nlinarith) have hsp : ((h+k:ℕ):ℝ)≤(G.size:ℝ)^(1-theta) := by have hh0 := (Nat.cast_nonneg h : (0:ℝ)≤h) have hhle : (h:ℝ)≤K0*Real.log σ.dimension := by nlinarith [hS.one] have hsum : ((h+k:ℕ):ℝ)≤(100004:ℝ)*Real.log σ.dimension := by push_cast norm_num [K0] at hhle linarith [hlogs.2] apply hsum.trans apply (mul_le_mul_of_nonneg_left hF.le (by norm_num : (0:ℝ)≤100004)).trans simpa only [theta] using hS.sparse have hnorm := H.level_sparse_norm hrS hG hf hζ hz hk hks hh hsp ρ L rw [show ρ=σ.pullback H.stabilizerFreeEquiv.symm from rfl,H.conditionalAverage_free_cancel] at hnorm let : NeZero σ.dimension := ⟨σ.positive.ne'⟩ have hp := pow_le_pow_left₀ (norm_nonneg (H.conditionalAverage hf z σ)) hnorm (2*SparseScalar.q) calc _ ≤ (σ.dimension:ℝ)*‖H.conditionalAverage hf z σ‖^(2*SparseScalar.q) := trace_moment_le _ _ _ ≤ (σ.dimension:ℝ)*((G.size:ℝ)^(-rho*k))^(2*SparseScalar.q) := mul_le_mul_of_nonneg_left hp (Nat.cast_nonneg _) _ = Real.exp (Real.log σ.dimension-4*k*Real.log G.size) := by rw [rpow_exp _ _ (by exact_mod_cast G.size_pos),←Real.exp_nat_mul] nth_rw 1 [←Real.exp_log (by exact_mod_cast σ.positive : (0:ℝ)<σ.dimension)] rw [←Real.exp_add] congr 1 norm_num [SparseScalar.q,rho] ring _ ≤ Real.exp (-3*Real.log σ.dimension) := Real.exp_le_exp.mpr (by nlinarith [hlogs.1]) _ ≤ _ := Real.exp_le_exp.mpr (by have hm := mul_le_mul_of_nonneg_right hc1 hF0 have ha0 := H.allowance_nonneg hr hG linarith) end CoordinateSweeps.Grid.Holes namespace CoordinateSweeps /-- Real exponential version of the exact conditional main estimate, used only as the induction predicate; its equivalence to logMoment includes zero moments. -/ def MomentBound (G : Grid) (q : ℕ) (z : ℝ) : Prop := ∀ (h : ℕ) (H : G.Holes h) (hf : H.Feasible) (σ : UnitaryIrrep H.stabilizer), schattenMoment q (H.conditionalAverage hf z σ) ≤ Real.exp (-c G.size*Real.log σ.dimension+e G.size*h*Real.log G.size-H.cost) noncomputable def cHat (s : ℕ) : ℝ := c s+1/(20*Real.sqrt (Real.log s)) noncomputable def eHat (s : ℕ) : ℝ := e s-1/(20*Real.sqrt (Real.log s)) end CoordinateSweeps namespace CoordinateSweeps.Grid.Holes open ScalarInduction YoungCorner variable {A B : Grid} {r h q : ℕ} (H : (concat A B).Holes h) theorem hook_auxiliary (hr : ScaleLarge r) (hA : A.Allowed r) (hB : B.Allowed r) (hAB : A.b≤B.b) (hBA : B.b≤2*A.b) (hq : 1≤q) (hS : MainSizeReady q (concat A B).size) (z : ℝ) (hIA : MomentBound A q z) (hIB : MomentBound B q z) (hf : H.Feasible) (σ : UnitaryIrrep H.stabilizer) (p : ℕ) (hp : 0
.trans_lt (removedPart_rank_lt μ p x)
have hL0 : (0:ℝ)