cfahlgren1's picture
download
raw
8.6 kB
10
lemma classSlots_mem (psi : B → U) (slot : B ↪ U) (b : B) (u : U) :
    slot b ∈ classSlots psi slot u ↔ psi b = u := by
proof · 5 lines
  simp only [classSlots,Finset.mem_map,imageClass,Finset.mem_filter,Finset.mem_univ,true_and]
  constructor
  · rintro ⟨c,hc,he⟩
    simpa only [slot.injective he] using hc
  · intro hb; exact ⟨b,hb,rfl⟩
19
lemma removal_weight_at_slot (psi : B → U) (slot : B ↪ U) (b : B) :
    (∑ e : ExchangeIndex B U,
      if slot b ∈ exchangeRemove psi slot e then exchangeWeight psi slot e else 0) =
    (if (imageClass psi (psi b)).card ≤ 5 then (1:ℝ) else 0) +
    (if 5 < (imageClass psi (psi b)).card ∧ slot b ≠ psi b
      then ((imageClass psi (psi b)).card:ℝ)/((imageClass psi (psi b)).card-1) else 0) := by
proof · 24 lines
  classical
  rw [Fintype.sum_sum_type]
  congr 1
  · simp only [exchangeRemove,classSlots_mem]
    rw [Finset.sum_ite_eq]
    simp [exchangeWeight,imageClass_pos psi b]
  · rw [Fintype.sum_prod_type]
    simp only [exchangeRemove,Finset.mem_singleton]
    simp_rw [Finset.sum_ite_eq,Finset.mem_univ,ite_true,exchangeWeight,auxiliary_slot_mem]
    have he (c : B) :
        (if 5 < (imageClass psi (psi c)).card ∧ psi b = psi c ∧ slot b ≠ psi c
          then 1 / ((imageClass psi (psi c)).card - (1:ℝ)) else 0) =
        (if psi c = psi b then
          (if 5 < (imageClass psi (psi b)).card ∧ slot b ≠ psi b
            then 1/((imageClass psi (psi b)).card-(1:ℝ)) else 0) else 0) := by
      by_cases hc : psi c = psi b
      · simp [hc]
      · simp [hc,Ne.symm hc]
    rw [Finset.sum_congr rfl (fun c _ => he c),← Finset.sum_filter]
    change (∑ _c ∈ imageClass psi (psi b),
      if 5 < (imageClass psi (psi b)).card ∧ slot b ≠ psi b
      then 1/((imageClass psi (psi b)).card-(1:ℝ)) else 0) = _
    rw [Finset.sum_const,nsmul_eq_mul]
    split_ifs <;> simp [div_eq_mul_inv]
51
lemma removal_weight_le (psi : B → U) (slot : B ↪ U) (s : U) :
    (∑ e : ExchangeIndex B U,
      if s ∈ exchangeRemove psi slot e then exchangeWeight psi slot e else 0) ≤ (6/5:ℝ) := by
proof · 38 lines
  classical
  by_cases hs : ∃ b, slot b = s
  · obtain ⟨b,rfl⟩ := hs
    rw [removal_weight_at_slot]
    by_cases ht : (imageClass psi (psi b)).card ≤ 5
    · simp only [ht,ite_true,not_lt.mpr ht,false_and,ite_false,add_zero]
      norm_num
    · have ht5 : 5 < (imageClass psi (psi b)).card := lt_of_not_ge ht
      simp only [ht,ite_false,zero_add,ht5,true_and]
      split_ifs
      · have ht6 : (6:ℝ) ≤ (imageClass psi (psi b)).card := by exact_mod_cast ht5
        have hpos : (0:ℝ) < (imageClass psi (psi b)).card-1 := by linarith
        apply (div_le_iff₀ hpos).mpr
        linarith
      · norm_num
  · have hz : (∑ e : ExchangeIndex B U,
        if s ∈ exchangeRemove psi slot e then exchangeWeight psi slot e else 0) = 0 := by
      apply Finset.sum_eq_zero
      intro e _
      cases e with
      | inl u =>
        have hm : s ∉ classSlots psi slot u := by
          intro hm
          obtain ⟨b,_,hb⟩ := Finset.mem_map.mp hm
          exact hs ⟨b,hb⟩
        simp only [exchangeRemove,hm,ite_false]
      | inr bs =>
        obtain ⟨b,t⟩ := bs
        by_cases hst : s = t
        · subst t
          have hm : s ∉ auxiliarySlots psi slot (psi b) := by
            intro hm
            obtain ⟨c,_,hc⟩ := Finset.mem_map.mp (Finset.mem_of_mem_erase hm)
            exact hs ⟨c,hc⟩
          simp [exchangeRemove,exchangeWeight,hm]
        · simp [exchangeRemove,hst]
    rw [hz]
    norm_num
98
noncomputable def connection (S : Finset V) (p : V) : ℝ :=
body · 1 line
  if h : S.Nonempty then S.inf' h (dist p) else 0
100
noncomputable def cost (D S : Finset V) : ℝ := ∑ p ∈ D, connection S p
102
lemma connection_nonneg (S : Finset V) (p : V) : 0 ≤ connection S p := by
proof · 4 lines
  unfold connection
  split_ifs with h
  · exact Finset.le_inf' h _ (fun _ _ => dist_nonneg)
  · rfl
107
lemma connection_le {S : Finset V} {p s : V} (hs : s ∈ S) : connection S p ≤ dist p s := by
proof · 2 lines
  rw [connection,dite_eq_left ⟨s,hs⟩]
  exact Finset.inf'_le _ hs
110
lemma cost_nonneg (D S : Finset V) : 0 ≤ cost D S :=
proof · 1 line
  Finset.sum_nonneg (fun _ _ => connection_nonneg _ _)
112
lemma connection_mono {S T : Finset V} (hS : S.Nonempty) (hST : S ⊆ T) (p : V) :
    connection T p ≤ connection S p := by
proof · 2 lines
  simp only [connection,dite_eq_left hS,dite_eq_left (hS.mono hST)]
  exact Finset.le_inf' hS _ (fun _ hs => Finset.inf'_le _ (hST hs))
116
lemma cost_mono (D : Finset V) {S T : Finset V} (hS : S.Nonempty) (hST : S ⊆ T) :
    cost D T ≤ cost D S := Finset.sum_le_sum (fun p _ => connection_mono hS hST p)
119
noncomputable def nearest (S : Finset V) (hS : S.Nonempty) (p : V) : V :=
body · 1 line
  Classical.choose (Finset.exists_min_image S (dist p) hS)
121
lemma nearest_mem (S : Finset V) (hS : S.Nonempty) (p : V) : nearest S hS p ∈ S :=
proof · 1 line
  (Classical.choose_spec (Finset.exists_min_image S (dist p) hS)).1
123
lemma nearest_distance (S : Finset V) (hS : S.Nonempty) (p : V) :
    dist p (nearest S hS p) = connection S p := by
proof · 4 lines
  rw [connection,dite_eq_left hS]
  exact le_antisymm (Finset.le_inf' hS _
    (Classical.choose_spec (Finset.exists_min_image S (dist p) hS)).2)
    (Finset.inf'_le _ (nearest_mem S hS p))
132
def WidthLocalMin (F D S : Finset V) (w : ℕ) : Prop :=
body · 1 line
  ∀ T ⊆ F, T.card = S.card → (S \ T).card ≤ w → (T \ S).card ≤ w → cost D S ≤ cost D T
135
lemma padded_not_worse (F D S T : Finset V) (hSF : S ⊆ F) (hTF : T ⊆ F)
    (hT : T.Nonempty) (hts : T.card ≤ S.card) :
    ∃ U ⊆ F, U.card = S.card ∧ T ⊆ U ∧ S \ U ⊆ S \ T ∧ U \ S ⊆ T \ S ∧
      cost D U ≤ cost D T := by
proof · 12 lines
  obtain ⟨U,hTU,hU,hcard⟩ := Finset.exists_subsuperset_card_eq
    (Finset.subset_union_left : T ⊆ T ∪ S) hts
    (Finset.card_le_card (Finset.subset_union_right : S ⊆ T ∪ S))
  refine ⟨U,hU.trans (Finset.union_subset hTF hSF),hcard,hTU,?_,?_,cost_mono D hT hTU⟩
  · intro x hx
    exact Finset.mem_sdiff.mpr ⟨(Finset.mem_sdiff.mp hx).1,
      fun hxt => (Finset.mem_sdiff.mp hx).2 (hTU hxt)⟩
  · intro x hx
    rcases Finset.mem_sdiff.mp hx with ⟨hxu,hxs⟩
    rcases Finset.mem_union.mp (hU hxu) with hxt | hxs'
    · exact Finset.mem_sdiff.mpr ⟨hxt,hxs⟩
    · exact (hxs hxs').elim
152
lemma local_min_le_smaller (F D S : Finset V) (w : ℕ) (hSF : S ⊆ F)
    (hlocal : WidthLocalMin F D S w) (T : Finset V) (hTF : T ⊆ F)
    (hT : T.Nonempty) (hcard : T.card ≤ S.card)
    (hremove : (S \ T).card ≤ w) (hadd : (T \ S).card ≤ w) : cost D S ≤ cost D T := by
proof · 3 lines
  obtain ⟨U,hUF,hUS,_,hrem,hnew,hcost⟩ := padded_not_worse F D S T hSF hTF hT hcard
  exact (hlocal U hUF hUS ((Finset.card_le_card hrem).trans hremove)
    ((Finset.card_le_card hnew).trans hadd)).trans hcost
161
lemma exchange_card_le (S R A : Finset V) (hRS : R ⊆ S) (hAR : A.card ≤ R.card) :
    ((S \ R) ∪ A).card ≤ S.card := by
proof · 2 lines
  have hh := Finset.card_sdiff_add_card_eq_card hRS
  exact (Finset.card_union_le _ _).trans (by omega)
166
lemma exchange_diff_bounds (S R A : Finset V) :
    S \ ((S \ R) ∪ A) ⊆ R ∧ ((S \ R) ∪ A) \ S ⊆ A := by
proof · 10 lines
  constructor
  · intro x hx
    by_contra hn
    exact (Finset.mem_sdiff.mp hx).2 (Finset.mem_union_left _
      (Finset.mem_sdiff.mpr ⟨(Finset.mem_sdiff.mp hx).1,hn⟩))
  · intro x hx
    rcases Finset.mem_sdiff.mp hx with ⟨hxu,hxs⟩
    rcases Finset.mem_union.mp hxu with hx | hx
    · exact (hxs (Finset.mem_sdiff.mp hx).1).elim
    · exact hx
178
lemma local_exchange (F D S : Finset V) (w : ℕ) (hSF : S ⊆ F)
    (hlocal : WidthLocalMin F D S w) (R A : Finset V)
    (hRS : R ⊆ S) (hAF : A ⊆ F) (hA : A.Nonempty)
    (hcard : A.card ≤ R.card) (hR : R.card ≤ w) (ha : A.card ≤ w) :
    cost D S ≤ cost D ((S \ R) ∪ A) := by
proof · 5 lines
  have hd := exchange_diff_bounds S R A
  exact local_min_le_smaller F D S w hSF hlocal _
    (Finset.union_subset (Finset.sdiff_subset.trans hSF) hAF)
    (hA.mono Finset.subset_union_right) (exchange_card_le S R A hRS hcard)
    ((Finset.card_le_card hd.1).trans hR) ((Finset.card_le_card hd.2).trans ha)

Xet Storage Details

Size:
8.6 kB
·
Xet hash:
91412b0ee8c819adc6c33c3b30d462b19e0dba716357928cf9717a63dd0522ff

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.