roseking's picture
Add lean source and binary files (part 84)
cdec422 verified
Raw History Blame Contribute Delete
38.8 kB
19
lemma purification_filter_identity [Nonempty ι] (P : Matrix ι κ ℂ) :
    referenceFilter (purificationFilter P) (outer (localProbe (ι := ι)) localProbe) =
      outer (vectorize P) (vectorize P) := by
proof · 6 lines
  unfold localProbe purificationFilter
  rw [referenceFilter_vectorize,Matrix.transpose_smul,Matrix.transpose_transpose,
    Matrix.smul_mul,Matrix.mul_smul,Matrix.one_mul,smul_smul]
  have hc : (Real.sqrt (Fintype.card ι : ℝ) : ℂ) ≠ 0 :=
    Complex.ofReal_ne_zero.mpr (Real.sqrt_pos.mpr (by exact_mod_cast Fintype.card_pos)).ne'
  rw [inv_mul_cancel₀ hc,one_smul]
42
def BitDensity.mapReference (τ : BitDensity μ κ)
    (L : Matrix κ κ ℂ →ₗ[ℂ] Matrix ι ι ℂ)
    (hpos : ∀ Z, Z.PosSemidef → (L Z).PosSemidef)
    (htr : ∀ Z, trace (L Z) = trace Z) : BitDensity μ ι where
body · 5 lines
  block i j t := L (τ.block i j t)
  positive i j t := hpos _ (τ.positive i j t)
  measurable i j := L.continuous_of_finiteDimensional.measurable.comp (τ.measurable i j)
  integrable i j := by simpa only [htr] using τ.integrable i j
  normalized := by simpa only [htr] using τ.normalized
52
lemma traceNorm_channel_sub (L : Matrix κ κ ℂ →ₗ[ℂ] Matrix ι ι ℂ)
    (hpos : ∀ Z, Z.PosSemidef → (L Z).PosSemidef)
    (htr : ∀ Z, trace (L Z) = trace Z)
    {A B : Matrix κ κ ℂ} (hA : A.PosSemidef) (hB : B.PosSemidef) :
    traceNorm (L A - L B) ≤ traceNorm (A-B) := by
proof · 2 lines
  rw [← map_sub]
  exact traceNorm_positive_tracePreserving L hpos htr _ (hA.isHermitian.sub hB.isHermitian)
60
theorem BitDensity.idealBitError_mapReference_le (τ : BitDensity μ κ)
    (L : Matrix κ κ ℂ →ₗ[ℂ] Matrix ι ι ℂ)
    (hpos : ∀ Z, Z.PosSemidef → (L Z).PosSemidef)
    (htr : ∀ Z, trace (L Z) = trace Z)
    (σ : Ω → Matrix κ κ ℂ) (hσ : Measurable σ)
    (hσp : ∀ t, (σ t).PosSemidef)
    (hσi : Integrable (fun t => (trace (σ t)).re) μ) :
    (τ.mapReference L hpos htr).idealBitError (fun t => L (σ t)) ≤ τ.idealBitError σ := by
proof · 26 lines
  have hm : Measurable (fun t => L (σ t)) := L.continuous_of_finiteDimensional.measurable.comp hσ
  have hi : Integrable (fun t => (trace (L (σ t))).re) μ := by simpa only [htr] using hσi
  have hc (a : Bool) :
      (∫ t, traceNorm (L (τ.block a a t) - (1/2 : ℝ) • L (σ t)) ∂μ) ≤
      ∫ t, traceNorm (τ.block a a t - (1/2 : ℝ) • σ t) ∂μ := by
    have hleft := traceNorm_sub_integrable
      (L.continuous_of_finiteDimensional.measurable.comp (τ.measurable a a))
      (show Measurable (fun t => (1/2 : ℝ) • L (σ t)) from hm.const_smul (1/2 : ℝ)) (fun t => hpos _ (τ.positive a a t))
      (fun t => (hpos _ (hσp t)).smul (show (0:ℝ)≤1/2 by norm_num))
      (show Integrable (fun t => (trace (L (τ.block a a t))).re) μ by simpa only [htr] using τ.integrable a a)
      (by simpa only [Matrix.trace_smul,Complex.smul_re,smul_eq_mul] using hi.const_mul (1/2))
    have hright := traceNorm_sub_integrable (τ.measurable a a) (show Measurable (fun t => (1/2 : ℝ) • σ t) from hσ.const_smul (1/2 : ℝ))
      (τ.positive a a) (fun t => (hσp t).smul (show (0:ℝ)≤1/2 by norm_num))
      (τ.integrable a a)
      (by simpa only [Matrix.trace_smul,Complex.smul_re,smul_eq_mul] using hσi.const_mul (1/2))
    apply integral_mono hleft hright
    intro t
    change traceNorm (L (τ.block a a t) - (1/2 : ℝ) • L (σ t)) ≤ _
    rw [← L.map_smul_of_tower (1/2 : ℝ) (σ t)]
    exact traceNorm_channel_sub L hpos htr (τ.positive a a t)
      ((hσp t).smul (show (0:ℝ)≤1/2 by norm_num))
  have hf := hc false
  have ht := hc true
  unfold BitDensity.idealBitError BitDensity.mass
  simp only [BitDensity.mapReference,htr]
  linarith
127
lemma purifiedDensity_recovery (ν : Measure (ℕ → M)) [SigmaFinite ν]
    (hμν : d.transcriptLaw ≪ ν)
    (L : Matrix κ κ ℂ →ₗ[ℂ] Matrix (ι × η) (ι × η) ℂ)
    (he : ∀ i j S, L ((p.purifiedOutput P i j).value S) = (p.canonicalOutput R i j).value S)
    (i j : Bool) :
    (p.outputDensity R hR ν hμν).block i j =ᵐ[ν]
      fun t => L ((p.purifiedDensity R hR P hP ν hμν).block i j t) := by
proof · 9 lines
  have hAC (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      (p.purifiedOutput P i j).value S = 0 := p.purifiedOutput_ac P i j S hS (hμν hz)
  let LC := L.toContinuousLinearMap
  apply (p.canonicalOutput R i j).positiveDensity_eq_ae ν
    (LC.integrable_comp ((p.purifiedOutput P i j).positiveDensity_integrable ν hAC))
  intro S hS
  rw [LC.integral_comp_comm ((p.purifiedOutput P i j).positiveDensity_integrable ν hAC).integrableOn,
    (p.purifiedOutput P i j).positiveDensity_integral ν hAC S hS]
  exact (he i j S).symm
146
theorem BitProtocol.uniform_gap_purification {a b : ℕ} [Nonempty (Fin a)] [Nonempty (Fin b)]
    (p : BitProtocol (ι := Fin a) (η := Fin b) d A B TA TB CA CB)
    (R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ) (hR : InClass R)
    (P : Matrix (Fin a × Fin b) κ ℂ) (hP : P * Pᴴ = R)
    (sigma : PositiveMatrixMeasure (ℕ → M) κ)
    (hsigma : (trace (sigma.value Set.univ)).re = 1) :
    1/5 ≤ p.purifiedSecretBitError R hR.1 P hP sigma := by
proof · 29 lines
  let ν := d.transcriptLaw + sigma.traceMeasure
  have hμν : d.transcriptLaw ≪ ν := Measure.AbsolutelyContinuous.rfl.add_right _
  have hsν : sigma.traceMeasure ≪ ν := Measure.AbsolutelyContinuous.rfl.add_right' _
  have hsAC (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      sigma.value S = 0 := sigma.value_zero_of_traceMeasure_zero S hS (hsν hz)
  obtain ⟨L,hpos,htr,hrec⟩ := p.purifiedOutput_recovery R hR.1 P hP
  let tp := p.purifiedDensity R hR.1 P hP ν hμν
  let tc := p.outputDensity R hR.1 ν hμν
  let sp := sigma.positiveDensity ν
  have hspm := sigma.measurable_positiveDensity ν
  have hspp := sigma.positiveDensity_pos ν
  have hspi := sigma.integrable_positiveDensity_trace ν hsAC
  have hspn := (sigma.integral_positiveDensity_trace ν hsAC).trans hsigma
  obtain ⟨τ,X,Y,hX,hY,hτ,hi,he⟩ := p.canonical_density_representation R hR.1
  have hg := class_factor_gap_dominating_measure hμν R hR τ X Y hX hY hτ
    (fun t => L (sp t)) (L.continuous_of_finiteDimensional.measurable.comp hspm)
    (fun t => hpos _ (hspp t))
    (show Integrable (fun t => (trace (L (sp t))).re) ν by simpa only [htr] using hspi)
    (show (∫ t, (trace (L (sp t))).re ∂ν) = 1 by simpa only [htr] using hspn)
  have heq := BitDensity.idealBitError_congr tc (τ.changeMeasure hμν)
    (fun t => L (sp t)) (fun t => L (sp t))
    (p.outputDensity_eq R hR.1 ν hμν τ hi he) Filter.EventuallyEq.rfl
  have hrc := BitDensity.idealBitError_congr tc (tp.mapReference L hpos htr)
    (fun t => L (sp t)) (fun t => L (sp t))
    (p.purifiedDensity_recovery R hR.1 P hP ν hμν L hrec) Filter.EventuallyEq.rfl
  have hcontract := tp.idealBitError_mapReference_le L hpos htr sp hspm hspp hspi
  change 1/5 ≤ tp.idealBitError sp
  rw [← heq,hrc] at hg
  exact hg.trans hcontract
208
lemma postprocess_value (f : K → Bool) (i : Bool) (x : Ω) :
    (b.postprocess f).value i x = ∑ k ∈ Finset.univ.filter (fun k => f k = i), b.value k x := by
proof · 5 lines
  have hs : ((Finset.univ.filter (fun k => f k = i) : Finset K) : Set K) = f ⁻¹' {i} := by
    ext k; simp
  change e.state x ((b.instrument x).operation (f ⁻¹' {i}) 1) = _
  rw [← hs]
  exact b.event_finset _ x
257
lemma canonicalOutput_ac (R : Matrix (ι × η) (ι × η) ℂ) (i j : K)
    (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : d.transcriptLaw S = 0) :
    (p.canonicalOutput R i j).value S = 0 := by
proof · 3 lines
  have hp : d.probeLaw (d.sampler.publicRecord ⁻¹' S) = 0 := by
    simpa only [Discussion.transcriptLaw,Measure.map_apply d.sampler.measurable_publicRecord hS] using hz
  rw [p.canonicalOutput_event R i j S hS,Measure.restrict_eq_zero.mpr hp,integral_zero_measure]
264
def outputDensity (R : Matrix (ι × η) (ι × η) ℂ) (ν : Measure (ℕ → M)) (i j : K) :
    (ℕ → M) → Matrix (ι × η) (ι × η) ℂ := (p.canonicalOutput R i j).positiveDensity ν
298
def firstBit : BitProtocol (ι := ι) (η := η) d A B TA TB CA CB := p.toBit Prod.fst
301
lemma firstBit_completeReference [StandardBorelSpace M] [Nonempty M] [Nonempty ι] [Nonempty η] (i j : Bool) (x : ℕ → O) :
    p.firstBit.completeReference i j x =
      ∑ a : Λ, ∑ b : Λ, p.completeReference (i,a) (j,b) x := by
proof · 12 lines
  have ha : (p.readoutA.postprocess Prod.fst).value i x = ∑ a : Λ, p.readoutA.value (i,a) x := by
    rw [IncomingObservableProcess.FiniteReadout.postprocess_value]
    cases i <;> simp [Finset.sum_filter,Fintype.sum_prod_type]
  have hb : (p.readoutB.postprocess Prod.fst).value j x = ∑ b : Λ, p.readoutB.value (j,b) x := by
    rw [IncomingObservableProcess.FiniteReadout.postprocess_value]
    cases j <;> simp [Finset.sum_filter,Fintype.sum_prod_type]
  change (p.readoutA.postprocess Prod.fst).value i x ⊗ₖ
    (p.readoutB.postprocess Prod.fst).value j x = _
  rw [ha,hb]
  ext k l
  simp only [Matrix.kroneckerMap_apply,Matrix.sum_apply,Finset.sum_mul,Finset.mul_sum,completeReference,Matrix.kroneckerMap_apply]
  rw [Finset.sum_comm]
317
lemma firstBit_output_event (R : Matrix (ι × η) (ι × η) ℂ)
    (i j : Bool) (S : Set (ℕ → M)) (hS : MeasurableSet S) :
    (p.firstBit.canonicalOutput R i j).value S =
      ∑ a : Λ, ∑ b : Λ, (p.canonicalOutput R (i,a) (j,b)).value S := by
proof · 11 lines
  rw [p.firstBit.canonicalOutput_event R i j S hS]
  simp_rw [p.firstBit_completeReference,Matrix.mul_sum,Matrix.sum_mul]
  rw [integral_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ =>
    (integrable_filter (preparationFilter R) (p.completeReference_integrable (i,a) (j,b))).integrableOn))]
  apply Finset.sum_congr rfl
  intro a _
  rw [integral_finsetSum _ (fun b _ =>
    (integrable_filter (preparationFilter R) (p.completeReference_integrable (i,a) (j,b))).integrableOn)]
  apply Finset.sum_congr rfl
  intro b _
  exact (p.canonicalOutput_event R (i,a) (j,b) S hS).symm
333
lemma firstBit_outputDensity (R : Matrix (ι × η) (ι × η) ℂ) (hR : Density R)
    (ν : Measure (ℕ → M)) [SigmaFinite ν] (hμν : d.transcriptLaw ≪ ν) (i j : Bool) :
    (p.firstBit.outputDensity R hR ν hμν).block i j =ᵐ[ν]
      fun t => ∑ a : Λ, ∑ b : Λ, p.outputDensity R ν (i,a) (j,b) t := by
proof · 15 lines
  have hAC (a b : Bool × Λ) (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      (p.canonicalOutput R a b).value S = 0 := p.canonicalOutput_ac R a b S hS (hμν hz)
  have hi (a b : Bool × Λ) : Integrable (p.outputDensity R ν a b) ν :=
    (p.canonicalOutput R a b).positiveDensity_integrable ν (hAC a b)
  apply (p.firstBit.canonicalOutput R i j).positiveDensity_eq_ae ν
    (integrable_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ => hi (i,a) (j,b))))
  intro S hS
  rw [p.firstBit_output_event R i j S hS]
  rw [integral_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ => (hi (i,a) (j,b)).integrableOn))]
  apply Finset.sum_congr rfl
  intro a _
  rw [integral_finsetSum _ (fun b _ => (hi (i,a) (j,b)).integrableOn)]
  apply Finset.sum_congr rfl
  intro b _
  exact ((p.canonicalOutput R (i,a) (j,b)).positiveDensity_integral ν (hAC (i,a) (j,b)) S hS).symm
382
def secretKeyError (R : Matrix (ι × η) (ι × η) ℂ)
    (sigma : PositiveMatrixMeasure (ℕ → M) (ι × η)) : ℝ :=
body · 3 lines
  let ν := d.transcriptLaw + sigma.traceMeasure
  cqDistance (p.outputDensity R ν)
    (fun a b t => idealFiniteBlocks (sigma.positiveDensity ν t) a b) ν
389
lemma secretKeyError_nonneg [Nonempty ι] [Nonempty η] (R : Matrix (ι × η) (ι × η) ℂ)
    (sigma : PositiveMatrixMeasure (ℕ → M) (ι × η)) : 0 ≤ p.secretKeyError R sigma := by
proof · 2 lines
  exact Finset.sum_nonneg fun a _ => Finset.sum_nonneg fun b _ =>
    integral_nonneg fun t => traceNorm_nonneg _
405
theorem firstBit_error_le (R : Matrix (ι × η) (ι × η) ℂ) (hR : Density R)
    (sigma : PositiveMatrixMeasure (ℕ → M) (ι × η)) :
    p.firstBit.secretBitError R hR sigma ≤ p.secretKeyError R sigma := by
proof · 25 lines
  let ν := d.transcriptLaw + sigma.traceMeasure
  have hμν : d.transcriptLaw ≪ ν := Measure.AbsolutelyContinuous.rfl.add_right _
  have hsν : sigma.traceMeasure ≪ ν := Measure.AbsolutelyContinuous.rfl.add_right' _
  have hsAC (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      sigma.value S = 0 := sigma.value_zero_of_traceMeasure_zero S hS (hsν hz)
  have hAC (a b : Bool × Λ) (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      (p.canonicalOutput R a b).value S = 0 := p.canonicalOutput_ac R a b S hS (hμν hz)
  have h := cqFirstBit_ideal_le (p.outputDensity R ν)
    (fun a b => (p.canonicalOutput R a b).measurable_positiveDensity ν)
    (fun a b => (p.canonicalOutput R a b).positiveDensity_pos ν)
    (fun a b => (p.canonicalOutput R a b).integrable_positiveDensity_trace ν (hAC a b))
    (sigma.positiveDensity ν) (sigma.measurable_positiveDensity ν)
    (sigma.positiveDensity_pos ν) (sigma.integrable_positiveDensity_trace ν hsAC)
  apply le_trans (le_of_eq ?_) h
  change (p.firstBit.outputDensity R hR ν hμν).idealBitError (sigma.positiveDensity ν) = _
  rw [BitDensity.idealBitError_eq_cq]
  unfold cqBitError
  apply Finset.sum_congr rfl
  intro i _
  apply Finset.sum_congr rfl
  intro j _
  apply integral_congr_ae
  filter_upwards [p.firstBit_outputDensity R hR ν hμν i j] with t ht
  rw [ht]
  rfl
434
theorem uniform_key_gap {a b : ℕ} [Nonempty (Fin a)] [Nonempty (Fin b)]
    (p : FiniteProtocol (ι := Fin a) (η := Fin b) (K := Bool × Λ) d A B TA TB CA CB)
    (R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ) (hR : InClass R)
    (sigma : PositiveMatrixMeasure (ℕ → M) (Fin a × Fin b))
    (hsigma : (trace (sigma.value Set.univ)).re = 1) :
    1/5 ≤ p.secretKeyError R sigma :=
proof · 1 line
  (p.firstBit.uniform_gap R hR sigma hsigma).trans (p.firstBit_error_le R hR.1 sigma)
475
def purifiedSecretKeyError (P : Matrix (ι × η) κ ℂ)
    (sigma : PositiveMatrixMeasure (ℕ → M) κ) : ℝ :=
body · 3 lines
  let ν := d.transcriptLaw + sigma.traceMeasure
  cqDistance (p.purifiedOutputDensity P ν)
    (fun a b t => idealFiniteBlocks (sigma.positiveDensity ν t) a b) ν
492
lemma firstBit_purifiedOutput_event (P : Matrix (ι × η) κ ℂ)
    (i j : Bool) (S : Set (ℕ → M)) (hS : MeasurableSet S) :
    (p.firstBit.purifiedOutput P i j).value S =
      ∑ a : Λ, ∑ b : Λ, (p.purifiedOutput P (i,a) (j,b)).value S := by
proof · 13 lines
  rw [BitProtocol.purifiedOutput,PositiveMatrixMeasure.filter_value,
    p.firstBit.probeOutput_event i j S hS,
    ← integral_filter _ (p.firstBit.completeReference_integrable i j).integrableOn]
  simp_rw [p.firstBit_completeReference,Matrix.mul_sum,Matrix.sum_mul]
  rw [integral_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ =>
    (integrable_filter (purificationFilter P) (p.completeReference_integrable (i,a) (j,b))).integrableOn))]
  apply Finset.sum_congr rfl
  intro a _
  rw [integral_finsetSum _ (fun b _ =>
    (integrable_filter (purificationFilter P) (p.completeReference_integrable (i,a) (j,b))).integrableOn)]
  apply Finset.sum_congr rfl
  intro b _
  exact (p.purifiedOutput_event P (i,a) (j,b) S hS).symm
510
lemma firstBit_purifiedOutputDensity (R : Matrix (ι × η) (ι × η) ℂ) (hR : Density R)
    (P : Matrix (ι × η) κ ℂ) (hP : P * Pᴴ = R)
    (ν : Measure (ℕ → M)) [SigmaFinite ν] (hμν : d.transcriptLaw ≪ ν) (i j : Bool) :
    (p.firstBit.purifiedDensity R hR P hP ν hμν).block i j =ᵐ[ν]
      fun t => ∑ a : Λ, ∑ b : Λ, p.purifiedOutputDensity P ν (i,a) (j,b) t := by
proof · 15 lines
  have hAC (a b : Bool × Λ) (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      (p.purifiedOutput P a b).value S = 0 := p.purifiedOutput_ac P a b S hS (hμν hz)
  have hi (a b : Bool × Λ) : Integrable (p.purifiedOutputDensity P ν a b) ν :=
    (p.purifiedOutput P a b).positiveDensity_integrable ν (hAC a b)
  apply (p.firstBit.purifiedOutput P i j).positiveDensity_eq_ae ν
    (integrable_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ => hi (i,a) (j,b))))
  intro S hS
  rw [p.firstBit_purifiedOutput_event P i j S hS]
  rw [integral_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ => (hi (i,a) (j,b)).integrableOn))]
  apply Finset.sum_congr rfl
  intro a _
  rw [integral_finsetSum _ (fun b _ => (hi (i,a) (j,b)).integrableOn)]
  apply Finset.sum_congr rfl
  intro b _
  exact ((p.purifiedOutput P (i,a) (j,b)).positiveDensity_integral ν (hAC (i,a) (j,b)) S hS).symm
531
theorem firstBit_purified_error_le (R : Matrix (ι × η) (ι × η) ℂ) (hR : Density R)
    (P : Matrix (ι × η) κ ℂ) (hP : P * Pᴴ = R)
    (sigma : PositiveMatrixMeasure (ℕ → M) κ) :
    p.firstBit.purifiedSecretBitError R hR P hP sigma ≤ p.purifiedSecretKeyError P sigma := by
proof · 25 lines
  let ν := d.transcriptLaw + sigma.traceMeasure
  have hμν : d.transcriptLaw ≪ ν := Measure.AbsolutelyContinuous.rfl.add_right _
  have hsν : sigma.traceMeasure ≪ ν := Measure.AbsolutelyContinuous.rfl.add_right' _
  have hsAC (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      sigma.value S = 0 := sigma.value_zero_of_traceMeasure_zero S hS (hsν hz)
  have hAC (a b : Bool × Λ) (S : Set (ℕ → M)) (hS : MeasurableSet S) (hz : ν S = 0) :
      (p.purifiedOutput P a b).value S = 0 := p.purifiedOutput_ac P a b S hS (hμν hz)
  have h := cqFirstBit_ideal_le (p.purifiedOutputDensity P ν)
    (fun a b => (p.purifiedOutput P a b).measurable_positiveDensity ν)
    (fun a b => (p.purifiedOutput P a b).positiveDensity_pos ν)
    (fun a b => (p.purifiedOutput P a b).integrable_positiveDensity_trace ν (hAC a b))
    (sigma.positiveDensity ν) (sigma.measurable_positiveDensity ν)
    (sigma.positiveDensity_pos ν) (sigma.integrable_positiveDensity_trace ν hsAC)
  apply le_trans (le_of_eq ?_) h
  change (p.firstBit.purifiedDensity R hR P hP ν hμν).idealBitError (sigma.positiveDensity ν) = _
  rw [BitDensity.idealBitError_eq_cq]
  unfold cqBitError
  apply Finset.sum_congr rfl
  intro i _
  apply Finset.sum_congr rfl
  intro j _
  apply integral_congr_ae
  filter_upwards [p.firstBit_purifiedOutputDensity R hR P hP ν hμν i j] with t ht
  rw [ht]
  rfl
561
theorem uniform_purified_key_gap {a b : ℕ} [Nonempty (Fin a)] [Nonempty (Fin b)]
    (p : FiniteProtocol (ι := Fin a) (η := Fin b) (K := Bool × Λ) d A B TA TB CA CB)
    (R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ) (hR : InClass R)
    (P : Matrix (Fin a × Fin b) κ ℂ) (hP : P * Pᴴ = R)
    (sigma : PositiveMatrixMeasure (ℕ → M) κ)
    (hsigma : (trace (sigma.value Set.univ)).re = 1) :
    1/5 ≤ p.purifiedSecretKeyError P sigma :=
proof · 2 lines
  (p.firstBit.uniform_gap_purification R hR P hP sigma hsigma).trans
    (p.firstBit_purified_error_le R hR.1 P hP sigma)
588
lemma idealError_nonneg : 0 ≤ τ.idealError sigma := cqDistance_nonneg _ _
590
lemma distance_nonneg : 0 ≤ τ.distance υ := cqDistance_nonneg _ _
593
lemma distance_self [DecidableEq K] : τ.distance τ = 0 := by
proof · 3 lines
  have hz : traceNorm (0 : Matrix ι ι ℂ) = 0 := by
    rw [traceNorm_posSemidef (Matrix.PosSemidef.zero)]; simp
  simp [distance,cqDistance,hz]
598
lemma idealError_triangle : τ.idealError sigma ≤ τ.distance υ + υ.idealError sigma :=
proof · 4 lines
  cqDistance_triangle τ.block υ.block (fun a b t => idealFiniteBlocks (sigma.block t) a b)
    τ.measurable υ.measurable (idealFinite_measurable sigma.block sigma.measurable)
    τ.positive υ.positive (fun a b t => idealFinite_positive (sigma.block t) (sigma.positive t) a b)
    τ.integrable υ.integrable (idealFinite_trace_integrable sigma.block sigma.integrable)
604
theorem gap_of_traceNorm_limit (τ : ℕ → KeyDensity μ K ι) (υ : KeyDensity μ K ι)
    (sigma : EveDensity μ ι) (hgap : ∀ n, 1/5 ≤ (τ n).idealError sigma)
    (hlim : Tendsto (fun n => (τ n).distance υ) atTop (nhds 0)) :
    1/5 ≤ υ.idealError sigma := by
proof · 4 lines
  have hle (n : ℕ) := (hgap n).trans ((τ n).idealError_triangle υ sigma)
  have ht : Tendsto (fun n => (τ n).distance υ + υ.idealError sigma)
      atTop (nhds (υ.idealError sigma)) := by simpa using hlim.add_const (υ.idealError sigma)
  exact ge_of_tendsto ht (Filter.Eventually.of_forall hle)
617
def toEveDensity (W : PositiveMatrixMeasure Ω ι) (μ : Measure Ω) [SigmaFinite μ]
    (hAC : ∀ S, MeasurableSet S → μ S = 0 → W.value S = 0)
    (hn : (trace (W.value Set.univ)).re = 1) : EveDensity μ ι where
body · 5 lines
  block := W.positiveDensity μ
  measurable := W.measurable_positiveDensity μ
  positive := W.positiveDensity_pos μ
  integrable := W.integrable_positiveDensity_trace μ hAC
  normalized := (W.integral_positiveDensity_trace μ hAC).trans hn
655
theorem BitProtocol.uniform_gap_purification_dominated
    {a b : ℕ} [Nonempty (Fin a)] [Nonempty (Fin b)]
    (p : BitProtocol (ι := Fin a) (η := Fin b) d A B TA TB CA CB)
    (R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ) (hR : InClass R)
    (P : Matrix (Fin a × Fin b) κ ℂ) (hP : P * Pᴴ = R)
    (ν : Measure (ℕ → M)) [SigmaFinite ν] (hμν : d.transcriptLaw ≪ ν)
    (sigma : EveDensity ν κ) :
    1/5 ≤ (p.purifiedDensity R hR.1 P hP ν hμν).idealBitError sigma.block := by
proof · 16 lines
  obtain ⟨L,hpos,htr,hrec⟩ := p.purifiedOutput_recovery R hR.1 P hP
  let tp := p.purifiedDensity R hR.1 P hP ν hμν
  let tc := p.outputDensity R hR.1 ν hμν
  have hg := p.uniform_gap_dominated R hR ν hμν
    (fun t => L (sigma.block t)) (L.continuous_of_finiteDimensional.measurable.comp sigma.measurable)
    (fun t => hpos _ (sigma.positive t))
    (show Integrable (fun t => (trace (L (sigma.block t))).re) ν by simpa only [htr] using sigma.integrable)
    (show (∫ t, (trace (L (sigma.block t))).re ∂ν) = 1 by simpa only [htr] using sigma.normalized)
  have hrc := BitDensity.idealBitError_congr tc (tp.mapReference L hpos htr)
    (fun t => L (sigma.block t)) (fun t => L (sigma.block t))
    (p.purifiedDensity_recovery R hR.1 P hP ν hμν L hrec) Filter.EventuallyEq.rfl
  have hc := tp.idealBitError_mapReference_le L hpos htr sigma.block
    sigma.measurable sigma.positive sigma.integrable
  change 1/5 ≤ tp.idealBitError sigma.block
  rw [hrc] at hg
  exact hg.trans hc
685
theorem FiniteProtocol.uniform_purified_key_gap_dominated
    {a b : ℕ} [Nonempty (Fin a)] [Nonempty (Fin b)]
    (p : FiniteProtocol (ι := Fin a) (η := Fin b) (K := Bool × Λ) d A B TA TB CA CB)
    (R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ) (hR : InClass R)
    (P : Matrix (Fin a × Fin b) κ ℂ) (hP : P * Pᴴ = R)
    (ν : Measure (ℕ → M)) [SigmaFinite ν] (hμν : d.transcriptLaw ≪ ν)
    (sigma : EveDensity ν κ) :
    1/5 ≤ (p.purifiedKeyDensity R hR.1 P hP ν hμν).idealError sigma := by
proof · 18 lines
  let τ := p.purifiedKeyDensity R hR.1 P hP ν hμν
  have hc := cqFirstBit_ideal_le τ.block τ.measurable τ.positive τ.integrable
    sigma.block sigma.measurable sigma.positive sigma.integrable
  have he : (p.firstBit.purifiedDensity R hR.1 P hP ν hμν).idealBitError sigma.block =
      cqBitError (fun i j t => firstBitBlocks (fun a b => τ.block a b t) i j) sigma.block ν := by
    rw [BitDensity.idealBitError_eq_cq]
    unfold cqBitError
    apply Finset.sum_congr rfl
    intro i _
    apply Finset.sum_congr rfl
    intro j _
    apply integral_congr_ae
    filter_upwards [p.firstBit_purifiedOutputDensity R hR.1 P hP ν hμν i j] with t ht
    rw [ht]
    rfl
  have hg := p.firstBit.uniform_gap_purification_dominated R hR P hP ν hμν sigma
  rw [he] at hg
  exact hg.trans hc