roseking's picture
Add lean source and binary files (part 84)
cdec422 verified
Raw History Blame Contribute Delete
10.4 kB
15
lemma card_keyWord (n : ℕ) : Fintype.card (KeyWord n) = 2^n := by
proof · 5 lines
  induction n with
  | zero => change Fintype.card Unit = 1; exact Fintype.card_unique
  | succ n ih =>
    change Fintype.card (Bool × KeyWord n) = _
    rw [Fintype.card_prod,Fintype.card_bool,ih,pow_succ,mul_comm]
34
def commonPublicLaw (μ : ℕ → Measure Ω) : Measure Ω :=
body · 1 line
  Measure.sum (fun n => (2⁻¹ : ℝ≥0∞)^n • μ n)
37
lemma commonPublicLaw_univ (μ : ℕ → Measure Ω) [∀ n, IsProbabilityMeasure (μ n)] :
    commonPublicLaw μ Set.univ = 2 := by
proof · 3 lines
  simp only [commonPublicLaw,Measure.sum_apply _ MeasurableSet.univ,Measure.smul_apply,
    measure_univ,smul_eq_mul,mul_one]
  exact ENNReal.tsum_geometric_two
43
instance commonPublicLaw_finite (μ : ℕ → Measure Ω) [∀ n, IsProbabilityMeasure (μ n)] :
    IsFiniteMeasure (commonPublicLaw μ) := ⟨by rw [commonPublicLaw_univ]; norm_num⟩
46
lemma absolutelyContinuous_commonPublicLaw (μ : ℕ → Measure Ω) (n : ℕ) :
    μ n ≪ commonPublicLaw μ := by
proof · 5 lines
  apply Measure.absolutelyContinuous_sum_right n
  apply Measure.AbsolutelyContinuous.mk
  intro S hS hzero
  have hp : (2⁻¹ : ℝ≥0∞)^n ≠ 0 := pow_ne_zero _ (by norm_num)
  simpa only [Measure.smul_apply,smul_eq_mul,mul_eq_zero,hp,false_or] using hzero
73
lemma uniform_gap (hc : InClass R) (hell : 0 < ell) (sigma : EveDensity ν (Fin e)) :
    1/5 ≤ (p.output R hR P hP ν hμν).idealError sigma := by
proof · 3 lines
  cases ell with
  | zero => omega
  | succ n => exact p.protocol.uniform_purified_key_gap_dominated R hc P hP ν hμν sigma
89
lemma of_implementation (p : KeyImplementation a b ell messages)
    (hAC : p.discussion.transcriptLaw ≪ ν) :
    IsCompletedKeyOutput R hR P hP messages ν (p.output R hR P hP ν hAC) := by
proof · 4 lines
  apply (isCompletedKeyOutput_iff_original R hR P hP messages ν _).2
  refine ⟨fun _ => p,fun _ => hAC,?_⟩
  simpa only [KeyDensity.distance_self] using
    (tendsto_const_nhds : Tendsto (fun _ : ℕ => (0 : ℝ)) atTop (nhds 0))
97
theorem uniform_gap (hτ : IsCompletedKeyOutput R hR P hP messages ν τ)
    (hc : InClass R) (hell : 0 < ell) (sigma : EveDensity ν (Fin e)) :
    1/5 ≤ τ.idealError sigma := by
proof · 4 lines
  obtain ⟨p,hAC,hlim⟩ := hτ
  exact KeyDensity.gap_of_traceNorm_limit
    (fun j => (p j).output R hR P hP ν (hAC j)) τ sigma
    (fun j => (p j).uniform_gap R hR P hP ν (hAC j) hc hell sigma) hlim
115
lemma error_nonneg : 0 ≤ p.error := p.actual.idealError_nonneg p.ideal
117
lemma uniform_error (hc : InClass R) (hell : 0 < ell) : 1/5 ≤ p.error :=
proof · 1 line
  p.completed.uniform_gap hc hell p.ideal
128
def groupVector {a b c d : ℕ} (u : Fin a × Fin b → ℂ) (v : Fin c × Fin d → ℂ) :
    Fin (a*c) × Fin (b*d) → ℂ := fun i =>
body · 1 line
  u (groupIndex a b c d i).1 * v (groupIndex a b c d i).2
132
lemma outer_groupVector {a b c d : ℕ} (u : Fin a × Fin b → ℂ) (v : Fin c × Fin d → ℂ) :
    outer (groupVector u v) (groupVector u v) = groupTensor (outer u u) (outer v v) := by
proof · 3 lines
  ext i j
  simp only [outer,groupVector,groupTensor,Matrix.submatrix_apply,Matrix.kroneckerMap_apply,star_mul]
  ring
138
lemma tensorMap_kronecker {a b c d : ℕ} (L : Mat a →ₗ[ℂ] Mat b) (M : Mat c →ₗ[ℂ] Mat d)
    (A : Mat a) (B : Mat c) : tensorMap L M (A ⊗ₖ B) = L A ⊗ₖ M B := by
proof · 12 lines
  ext ⟨i,k⟩ ⟨j,l⟩
  simp only [tensorMap,Matrix.kronecker_apply]
  have hL := linearMap_matrix_units_apply L A i j
  have hM := linearMap_matrix_units_apply M B k l
  rw [hL,hM]
  simp only [Finset.sum_mul]
  simp only [Finset.mul_sum]
  apply Finset.sum_congr rfl; intro x _
  apply Finset.sum_congr rfl; intro y _
  apply Finset.sum_congr rfl; intro z _
  apply Finset.sum_congr rfl; intro w _
  ring
153
lemma matrixUnit_finProd {a c : ℕ} (x y : Fin (a*c)) :
    (matrixUnit x y).submatrix finProdFinEquiv finProdFinEquiv =
      matrixUnit (finProdFinEquiv.symm x).1 (finProdFinEquiv.symm y).1 ⊗ₖ
      matrixUnit (finProdFinEquiv.symm x).2 (finProdFinEquiv.symm y).2 := by
proof · 12 lines
  ext ⟨i,k⟩ ⟨j,l⟩
  simp only [Matrix.submatrix_apply, matrixUnit, Matrix.kronecker_apply]
  have hx : finProdFinEquiv (i,k) = x ↔ i = (finProdFinEquiv.symm x).1 ∧
      k = (finProdFinEquiv.symm x).2 := by
    rw [← Equiv.eq_symm_apply]
    exact Prod.ext_iff
  have hy : finProdFinEquiv (j,l) = y ↔ j = (finProdFinEquiv.symm y).1 ∧
      l = (finProdFinEquiv.symm y).2 := by
    rw [← Equiv.eq_symm_apply]
    exact Prod.ext_iff
  simp only [hx,hy]
  split_ifs <;> simp_all
170
lemma tensorLinear_unit {a b c d : ℕ} (L : Mat a →ₗ[ℂ] Mat b) (M : Mat c →ₗ[ℂ] Mat d)
    (x y : Fin (a*c)) (i j : Fin (b*d)) :
    tensorLinear L M (matrixUnit x y) i j =
    L (matrixUnit (finProdFinEquiv.symm x).1 (finProdFinEquiv.symm y).1)
      (finProdFinEquiv.symm i).1 (finProdFinEquiv.symm j).1 *
    M (matrixUnit (finProdFinEquiv.symm x).2 (finProdFinEquiv.symm y).2)
      (finProdFinEquiv.symm i).2 (finProdFinEquiv.symm j).2 := by
proof · 3 lines
  change (tensorMap L M _ _ _) = _
  rw [matrixUnit_finProd,tensorMap_kronecker]
  rfl
181
lemma tensorMap_groupTensor {a b c d e f g h : ℕ}
    (L : Mat a →ₗ[ℂ] Mat b) (M : Mat c →ₗ[ℂ] Mat d)
    (N : Mat e →ₗ[ℂ] Mat f) (P : Mat g →ₗ[ℂ] Mat h)
    (U : Matrix (Fin a × Fin c) (Fin a × Fin c) ℂ)
    (V : Matrix (Fin e × Fin g) (Fin e × Fin g) ℂ) :
    tensorMap (tensorLinear L N) (tensorLinear M P) (groupTensor U V) =
    groupTensor (tensorMap L M U) (tensorMap N P V) := by
proof · 23 lines
  ext ⟨i,k⟩ ⟨j,l⟩
  simp only [tensorMap, tensorLinear_unit,groupTensor,Matrix.submatrix_apply,
    Matrix.kronecker_apply,groupIndex,Equiv.coe_fn_mk]
  simp_rw [← Equiv.sum_comp (finProdFinEquiv : Fin a × Fin e ≃ _)]
  simp_rw [← Equiv.sum_comp (finProdFinEquiv : Fin c × Fin g ≃ _)]
  simp only [Equiv.symm_apply_apply,Fintype.sum_prod_type]
  simp only [Finset.sum_mul]
  simp only [Finset.mul_sum]
  apply Finset.sum_congr rfl; intro x _
  rw [Finset.sum_comm]
  apply Finset.sum_congr rfl; intro y _
  conv_lhs => arg 2; ext xv; rw [Finset.sum_comm]
  rw [Finset.sum_comm]
  apply Finset.sum_congr rfl; intro z _
  conv_lhs => arg 2; ext xv; arg 2; ext yv; rw [Finset.sum_comm]
  conv_lhs => arg 2; ext xv; rw [Finset.sum_comm]
  rw [Finset.sum_comm]
  apply Finset.sum_congr rfl; intro w _
  apply Finset.sum_congr rfl; intro xv _
  apply Finset.sum_congr rfl; intro yv _
  apply Finset.sum_congr rfl; intro zv _
  apply Finset.sum_congr rfl; intro wv _
  ring
212
lemma InClass.groupTensor {a b c d : ℕ}
    {R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ}
    {S : Matrix (Fin c × Fin d) (Fin c × Fin d) ℂ}
    (hR : InClass R) (hS : InClass S) : InClass (groupTensor R S) := by
proof · 5 lines
  obtain ⟨hdR,p,q,L,M,u,hL,hM,hu⟩ := hR
  obtain ⟨hdS,r,s,N,P,v,hN,hP,hv⟩ := hS
  refine ⟨hdR.groupTensor hdS,p*r,q*s,tensorLinear L N,tensorLinear M P,
    groupVector u v,ppt_tensorLinear hL hN,ppt_tensorLinear hM hP,?_⟩
  rw [outer_groupVector,tensorMap_groupTensor,← hu,← hv]
222
lemma InClass.positiveCopies {a b : ℕ}
    {R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ} (hR : InClass R) (k : ℕ) :
    InClass (positiveCopies R k) := by
proof · 3 lines
  induction k with
  | zero => exact hR
  | succ k ih => exact ih.groupTensor hR
245
lemma eventually_length_zero (hc : InClass R) (hs : s.Secure) :
    ∀ᶠ k in atTop, s.length k = 0 := by
proof · 5 lines
  have he : ∀ᶠ k in atTop, s.error k < 1/5 := (tendsto_order.mp hs).2 _ (by norm_num)
  filter_upwards [he] with k hk
  by_contra hn
  exact (not_lt_of_ge ((s.trial k).uniform_error (hc.positiveCopies k)
    (Nat.pos_of_ne_zero hn))) hk
253
lemma lowerRate_zero (hc : InClass R) (hs : s.Secure) : s.lowerRate = 0 := by
proof · 6 lines
  unfold lowerRate
  have he : (fun k : ℕ => (s.length k : ℝ≥0∞) / (k+1 : ℕ)) =ᶠ[atTop] fun _ => 0 := by
    filter_upwards [s.eventually_length_zero hc hs] with k hk
    simp [hk]
  rw [Filter.liminf_congr he]
  simp
263
theorem class_distillableSecretKey_zero {a b : ℕ} [Nonempty (Fin a)] [Nonempty (Fin b)]
    (R : Matrix (Fin a × Fin b) (Fin a × Fin b) ℂ) (hR : Density R) (hc : InClass R) :
    distillableSecretKey.{u} R hR = 0 := by
proof · 6 lines
  apply le_antisymm ?_ bot_le
  apply sSup_le
  intro r hr
  rcases hr with rfl | ⟨s,hs,rfl⟩
  · rfl
  · exact le_of_eq (s.lowerRate_zero hc hs)