Buckets:
| import Mathlib | |
| import OAI.Probability.ThorpRouting.Adaptive.RotationMeeting | |
| namespace OAI | |
| namespace ThorpNine.Adaptive | |
| namespace Thorp | |
| open scoped BigOperators | |
| open Filter | |
| section CycleCounting | |
| variable {d A : ℕ} | |
| lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} | |
| (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : | |
| assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by | |
| classical | |
| unfold assignmentOwner | |
| split_ifs with h | |
| · constructor | |
| · intro hi | |
| have hx := Classical.choose_spec h | |
| rw [Option.some.inj hi] at hx | |
| exact hx | |
| · intro hx | |
| have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx | |
| exact congrArg some (f.property.1 he) | |
| · constructor | |
| · intro hi; contradiction | |
| · intro hx; exact (h ⟨i,hx⟩).elim | |
| lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} | |
| (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by | |
| ext x | |
| simp only [mem_cycleFiber,assignmentOwner_eq_some] | |
| noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} | |
| (f : SlotAssignment p S r) : CycleSlots p S r := | |
| ⟨assignmentOwner f,by | |
| refine ⟨?_,?_,?_⟩ | |
| · intro i | |
| rw [assignmentOwner_fiber] | |
| exact f.property.2 i | |
| · intro i | |
| rw [assignmentOwner_fiber] | |
| exact (f.val i).property.2 | |
| · intro i x hx | |
| rw [assignmentOwner_fiber] | |
| exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ | |
| noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : | |
| CycleSlots p S r ≃ SlotAssignment p S r where | |
| toFun := slotsToAssignment | |
| invFun := assignmentToSlots | |
| left_inv c := by | |
| apply Subtype.ext | |
| apply owner_ext | |
| intro i | |
| rw [assignmentToSlots,assignmentOwner_fiber] | |
| rfl | |
| right_inv f := by | |
| apply Subtype.ext | |
| funext i | |
| apply Subtype.ext | |
| exact assignmentOwner_fiber f i | |
| end CycleCounting | |
| section GroupedCounting | |
| variable {d A : ℕ} | |
| abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} | |
| def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := | |
| ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ | |
| abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} | |
| abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := | |
| {C : SelectedCycle p S // C.val.card = j} | |
| noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : | |
| Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ | |
| abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := | |
| ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val | |
| noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} | |
| (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => | |
| { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ | |
| inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } | |
| noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} | |
| (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := | |
| ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans | |
| (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans | |
| ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans | |
| (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) | |
| noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} | |
| (F : GroupedAssignments p S r) : SlotAssignment p S r := | |
| ⟨groupsEmbedding F, (groupsEmbedding F).injective, | |
| fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ | |
| noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : | |
| SlotAssignment p S r ≃ GroupedAssignments p S r where | |
| toFun := assignmentToGroups | |
| invFun := groupsToAssignment | |
| left_inv f := by | |
| apply Subtype.ext | |
| rfl | |
| right_inv F := by | |
| funext j | |
| apply Function.Embedding.ext | |
| intro i | |
| rcases i with ⟨i,hi⟩ | |
| subst j | |
| rfl | |
| lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : | |
| Fintype.card (CycleSlots p S r) = | |
| ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial | |
| (Fintype.card (SlotsOfLength r j)) := by | |
| classical | |
| rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), | |
| Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] | |
| simp only [Fintype.card_embedding_eq] | |
| lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : | |
| finiteMean (fun ω : SwitchIndex d → Bool => | |
| (∏ j : LengthClass r, | |
| (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial | |
| (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ | |
| ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * | |
| ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by | |
| simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr | |
| end GroupedCounting | |
| section AllLengths | |
| variable {d A : ℕ} | |
| noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) | |
| (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : | |
| SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where | |
| toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ | |
| invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by | |
| simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ | |
| left_inv f := by apply Subtype.ext; funext i; simp | |
| right_inv f := by apply Subtype.ext; funext i; simp | |
| lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) | |
| (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : | |
| Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by | |
| exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans | |
| ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) | |
| lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : | |
| finiteMean (fun ω : SwitchIndex d → Bool => | |
| (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ | |
| ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * | |
| ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by | |
| have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) | |
| simp_rw [←card_cycleSlots_relabel] at h | |
| have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) | |
| simpa only [Function.comp_apply,hp] using h | |
| abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := | |
| {C : SelectedCycle p S // C.val.card ≤ J} | |
| noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : | |
| Fintype (ShortCycle p S J) := Fintype.ofFinite _ | |
| noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} | |
| (C : ShortCycle p S J) : Fin J := | |
| ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ | |
| lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} | |
| (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by | |
| have := C.val.nonempty.card_pos | |
| simp only [shortCycleLength] | |
| omega | |
| noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : | |
| (Fin A ↪ ShortCycle p S J) ≃ | |
| Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where | |
| toFun f := ⟨fun i => shortCycleLength (f i), | |
| ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), | |
| fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ | |
| invFun c := | |
| { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ | |
| inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } | |
| left_inv f := by | |
| apply Function.Embedding.ext | |
| intro i | |
| rfl | |
| right_inv c := by | |
| rcases c with ⟨r,f⟩ | |
| have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by | |
| funext i | |
| apply Fin.ext | |
| simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] | |
| apply Sigma.ext he | |
| apply (Subtype.heq_iff_coe_eq (by | |
| intro x | |
| change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ | |
| simp only [f.property.2,Nat.add_sub_cancel])).mpr | |
| rfl | |
| lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : | |
| (Fintype.card (ShortCycle p S J)).descFactorial A = | |
| ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by | |
| classical | |
| have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) | |
| simp only [Fintype.card_fin] at hc | |
| rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] | |
| apply Finset.sum_congr rfl | |
| intro r _ | |
| exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm | |
| end AllLengths | |
| lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) | |
| (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) | |
| (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : | |
| finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by | |
| have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by | |
| rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] | |
| exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm | |
| have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), | |
| ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by | |
| calc | |
| _ = ((q-1)+1)^(F ω) := by congr 1; ring | |
| _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by | |
| rw [add_pow] | |
| simp only [one_pow,mul_one] | |
| _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by | |
| apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) | |
| intro a _ ha | |
| have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega | |
| rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] | |
| _ = _ := by | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [hc] | |
| ring | |
| simp_rw [hex,finiteMean_sum,finiteMean_mul_const] | |
| calc | |
| _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by | |
| apply Finset.sum_le_sum | |
| intro a _ | |
| exact mul_le_mul_of_nonneg_right (hm a) (by positivity) | |
| _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [mul_pow] | |
| ring | |
| _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ | |
| lemma inv_sqrt_step (j : ℕ) : | |
| 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by | |
| have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) | |
| apply (div_le_iff₀ hp).mpr | |
| have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) | |
| have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) | |
| nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] | |
| lemma sum_inv_sqrt (J : ℕ) : | |
| (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by | |
| have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => | |
| rw [Finset.sum_range_succ] | |
| have hs := inv_sqrt_step n | |
| push_cast | |
| linarith | |
| rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] | |
| exact h J | |
| section CycleMGF | |
| variable {d : ℕ} | |
| lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : | |
| finiteMean (fun ω : SwitchIndex d → Bool => | |
| ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ | |
| ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by | |
| classical | |
| simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] | |
| calc | |
| _ ≤ ∑ r : Fin A → Fin J, | |
| ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * | |
| ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by | |
| apply Finset.sum_le_sum | |
| intro r _ | |
| exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) | |
| _ = _ := by | |
| rw [←Finset.mul_sum,mul_pow] | |
| congr 1 | |
| rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] | |
| simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] | |
| noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := | |
| ∑ C : SelectedCycle p S, C.val.card | |
| lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by | |
| classical | |
| let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := | |
| fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ | |
| have hi : Function.Injective f := by | |
| intro c e h | |
| have hx : c.2.val = e.2.val := congrArg Subtype.val h | |
| have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) | |
| rcases c with ⟨c,x⟩ | |
| rcases e with ⟨e,y⟩ | |
| dsimp only at hC | |
| subst e | |
| have he : x=y := Subtype.ext hx | |
| cases he | |
| rfl | |
| have hh := Fintype.card_le_of_injective f hi | |
| simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh | |
| lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : | |
| Fintype.card (ShortCycle p S J) ≤ S.card := by | |
| classical | |
| calc | |
| _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ | |
| _ = ∑ _ : SelectedCycle p S, 1 := by simp | |
| _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) | |
| _ ≤ _ := cycleMass_le p S | |
| lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : | |
| finiteMean (fun ω : SwitchIndex d → Bool => | |
| q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ | |
| Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by | |
| apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) | |
| · positivity | |
| · exact hq | |
| · exact butterfly_shortCycle_moment S J | |
| end CycleMGF | |
| section FullCycleMGF | |
| variable {d : ℕ} | |
| abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := | |
| {C : SelectedCycle p S // ¬ C.val.card ≤ J} | |
| noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : | |
| Fintype (LongCycle p S J) := Fintype.ofFinite _ | |
| lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : | |
| Fintype.card (SelectedCycle p S) = | |
| Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by | |
| classical | |
| rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] | |
| lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : | |
| J * Fintype.card (LongCycle p S J) ≤ S.card := by | |
| classical | |
| have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) | |
| (fun C : SelectedCycle p S => C.val.card) | |
| rw [Fintype.sum_sum_type] at hs | |
| have h0 : J * Fintype.card (LongCycle p S J) ≤ | |
| ∑ C : LongCycle p S J, C.val.val.card := by | |
| calc | |
| _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] | |
| _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) | |
| have hh := cycleMass_le p S | |
| unfold cycleMass at hh | |
| rw [←hs] at hh | |
| exact h0.trans ((Nat.le_add_left _ _).trans hh) | |
| lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} | |
| (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by | |
| apply div_pos | |
| · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty | |
| · exact Nat.cast_pos.mpr Fintype.card_pos | |
| lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) | |
| (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : | |
| q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by | |
| have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq | |
| have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by | |
| apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr | |
| have hh := longCycle_card_bound p S J | |
| exact_mod_cast (by simpa only [mul_comm] using hh) | |
| calc | |
| _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by | |
| rw [Real.exp_nat_mul,Real.exp_log hq0] | |
| _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) | |
| lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) | |
| (q : ℝ) (hq : 1 ≤ q) : | |
| Real.log (finiteMean (fun ω : SwitchIndex d → Bool => | |
| q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ | |
| (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by | |
| let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) | |
| let c : ℝ := (S.card : ℝ)/J * Real.log q | |
| have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by | |
| have hsum := sum_inv_sqrt J | |
| have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity | |
| have h0 : 0 ≤ 2*Real.sqrt J := by positivity | |
| have hh := mul_le_mul_of_nonneg_left hsum hp | |
| have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq | |
| calc | |
| _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := | |
| mul_le_mul_of_nonneg_left hh hq1 | |
| _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := | |
| mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) | |
| _ = _ := by ring | |
| have hm : finiteMean (fun ω : SwitchIndex d → Bool => | |
| q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ | |
| Real.exp (c+(q-1)*lam) := by | |
| calc | |
| _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => | |
| q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by | |
| apply finiteMean_mono | |
| intro ω | |
| rw [selectedCycle_card_split _ _ J,pow_add] | |
| exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) | |
| _ = finiteMean (fun ω : SwitchIndex d → Bool => | |
| q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := | |
| finiteMean_mul_const _ _ | |
| _ ≤ Real.exp ((q-1)*lam) * Real.exp c := | |
| mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) | |
| _ = _ := by rw [←Real.exp_add,add_comm] | |
| have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => | |
| q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by | |
| apply finiteMean_pos | |
| intro ω | |
| positivity | |
| have hlog := Real.log_le_log hpos hm | |
| rw [Real.log_exp] at hlog | |
| dsimp [c] at hlog | |
| linarith | |
| end FullCycleMGF | |
| structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] | |
| [Fintype ι] [DecidableEq ι] (d : ℕ) where | |
| perm : (ι → Bool) → Equiv.Perm α | |
| path : (ι → Bool) → α → Finset ι | |
| users : (ι → Bool) → ι → α × α | |
| users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 | |
| mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x | |
| card_path : ∀ ω x, (path ω x).card = d | |
| entropy : ∀ ω (S : Finset α), | |
| (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ | |
| (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) | |
| follow : α → (α → QueryTree ι) → QueryTree ι | |
| close : α → α → QueryTree ι → QueryTree ι | |
| follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω | |
| follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω | |
| follow_stale_charge : ∀ x k R ω, | |
| (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω | |
| close_succeeds : ∀ x y k ω, | |
| (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false | |
| close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d | |
| close_stale_charge : ∀ x y k R ω, perm ω x = y → | |
| (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card | |
| namespace RoutingNetwork | |
| variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] | |
| {d : ℕ} (R : RoutingNetwork α ι d) | |
| lemma card_switches_using (ω : ι → Bool) (x : α) : | |
| (Finset.univ.filter (fun i : ι => | |
| (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by | |
| classical | |
| have he : Finset.univ.filter (fun i : ι => | |
| (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by | |
| ext i | |
| simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] | |
| rw [he,R.card_path] | |
| lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : | |
| ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = | |
| (d : ℝ) * ∑ x : α, w x := by | |
| classical | |
| calc | |
| _ = ∑ i : ι, ∑ x : α, | |
| if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| rw [Finset.sum_ite] | |
| simp only [Finset.sum_const_zero, add_zero] | |
| have he : Finset.univ.filter (fun x : α => | |
| (R.users b i).1 = x ∨ (R.users b i).2 = x) = | |
| {(R.users b i).1, (R.users b i).2} := by | |
| ext x; simp [eq_comm] | |
| rw [he, Finset.sum_pair (R.users_ne b i)] | |
| _ = ∑ x : α, ∑ i : ι, | |
| if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := | |
| Finset.sum_comm | |
| _ = ∑ x : α, (d : ℝ) * w x := by | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| rw [Finset.sum_ite] | |
| simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, | |
| card_switches_using] | |
| _ = _ := by rw [Finset.mul_sum] | |
| lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : | |
| ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ | |
| (d : ℝ) / 2 * ∑ x : α, w x := by | |
| have h : 2 * (∑ i : ι, | |
| min (w (R.users b i).1) (w (R.users b i).2)) ≤ | |
| ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_le_sum | |
| intro i _ | |
| linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), | |
| min_le_right (w (R.users b i).1) (w (R.users b i).2)] | |
| rw [switch_incidence_sum] at h | |
| linarith | |
| section Rotation | |
| variable {A : ℕ} | |
| def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by | |
| classical | |
| exact Finset.univ.filter (fun x => o x = some i) | |
| omit [DecidableEq α] in | |
| @[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : | |
| x ∈ cycleFiber o i ↔ o x = some i := by | |
| classical | |
| simp [cycleFiber] | |
| abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} | |
| noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := | |
| 1 / (cycleFiber o i).card | |
| noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := | |
| match o x with | |
| | none => 0 | |
| | some i => slotWeight o i | |
| noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := | |
| match o u, o v with | |
| | some i, some j => if i = j then slotWeight o i else 0 | |
| | _, _ => 0 | |
| noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) | |
| (u v : α) : ℝ := | |
| match o u, o v with | |
| | some i, some j => if i < j then (if (z j).val = v then 1 else 0) | |
| else if j < i then (if (z i).val = u then 1 else 0) | |
| else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) | |
| | _, _ => 0 | |
| omit [DecidableEq α] in | |
| lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : | |
| Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by | |
| classical | |
| simp [cycleFiber,Fintype.card_subtype] | |
| lemma terminal_mean {o : α → Option (Fin A)} | |
| [∀ i : Fin A, Nonempty {x : α // o x = some i}] | |
| (i : Fin A) (x : α) (hx : o x = some i) : | |
| finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by | |
| classical | |
| have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) | |
| i (fun z => if z.val = x then (1:ℝ) else 0) | |
| rw [hev] | |
| have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = | |
| (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by | |
| funext z | |
| simp only [Subtype.ext_iff] | |
| rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] | |
| omit [DecidableEq α] in | |
| lemma slotWeight_antitone (o : α → Option (Fin A)) | |
| (hn : ∀ i, (cycleFiber o i).Nonempty) | |
| (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by | |
| intro i j hij | |
| unfold slotWeight | |
| apply one_div_le_one_div_of_le | |
| · exact_mod_cast Finset.card_pos.mpr (hn i) | |
| · exact_mod_cast hm hij | |
| lemma rotationMeeting_mean {o : α → Option (Fin A)} | |
| [∀ i : Fin A, Nonempty {x : α // o x = some i}] | |
| (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : | |
| finiteMean (fun z : Terminal o => rotationMeeting o z u v) = | |
| min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by | |
| classical | |
| have hn : ∀ i, (cycleFiber o i).Nonempty := by | |
| intro i | |
| obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) | |
| exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ | |
| have hw := slotWeight_antitone o hn hm | |
| cases hu : o u with | |
| | none => | |
| cases hv : o v with | |
| | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] | |
| | some j => | |
| have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity | |
| simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] | |
| | some i => | |
| cases hv : o v with | |
| | none => | |
| have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity | |
| simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] | |
| | some j => | |
| simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] | |
| rcases lt_trichotomy i j with hij | rfl | hji | |
| · simp only [hij,↓reduceIte,ne_of_lt hij] | |
| rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] | |
| · simp only [lt_self_iff_false,↓reduceIte,min_self] | |
| rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] | |
| · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] | |
| rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] | |
| omit [DecidableEq α] in | |
| lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : | |
| ∑ x : α, pathWeight o x = (A : ℝ) := by | |
| classical | |
| have he (x : α) : pathWeight o x = | |
| ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by | |
| cases hx : o x with | |
| | none => simp [pathWeight,hx] | |
| | some j => simp [pathWeight,hx] | |
| simp only [he] | |
| rw [Finset.sum_comm] | |
| have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by | |
| rw [← Finset.sum_filter] | |
| change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 | |
| simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] | |
| exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') | |
| simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] | |
| lemma withinWeight_sum_bound (o : α → Option (Fin A)) | |
| (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : | |
| (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ | |
| ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by | |
| classical | |
| have he (u v : α) : withinWeight o u v = | |
| ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by | |
| simp only [mem_cycleFiber] | |
| cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] | |
| simp only [he] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_le_sum | |
| intro i _ | |
| rw [← Finset.sum_mul] | |
| have hi := R.entropy b (cycleFiber o i) | |
| have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) | |
| have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) | |
| calc | |
| _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / | |
| (2 * Real.log 2) * slotWeight o i := hmul | |
| _ = _ := by unfold slotWeight; field_simp | |
| noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) | |
| (z : Terminal o) : ℝ := | |
| ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 | |
| lemma rotationCharge_mean_bound {o : α → Option (Fin A)} | |
| [∀ i : Fin A, Nonempty {x : α // o x = some i}] | |
| (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : | |
| finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + | |
| ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by | |
| classical | |
| have hn : ∀ i, (cycleFiber o i).Nonempty := by | |
| intro i | |
| obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) | |
| exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ | |
| unfold rotationCharge | |
| rw [finiteMean_sum] | |
| simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] | |
| have h₁ := weighted_switch_min_bound R b (pathWeight o) | |
| rw [pathWeight_sum o hn] at h₁ | |
| have h₂ := withinWeight_sum_bound R o hn b | |
| linarith | |
| lemma rotation_exp_bound {o : α → Option (Fin A)} | |
| [∀ i : Fin A, Nonempty {x : α // o x = some i}] | |
| (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : | |
| Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + | |
| ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ | |
| finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by | |
| have hb := rotationCharge_mean_bound R hm b | |
| have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) | |
| have hm' : -Real.log 2 * ((A:ℝ)*d/2 + | |
| ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ | |
| finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by | |
| have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) | |
| simp only [mul_comm] at he | |
| rw [he] | |
| exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) | |
| exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) | |
| end Rotation | |
| namespace QueryTree | |
| open Thorp.QueryTree | |
| noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : | |
| ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → | |
| QueryTree (ι) | |
| | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject | |
| | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x | |
| (fun y => seekCycle R S a r y (insert x V) k) else reject | |
| lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) | |
| (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) | |
| (ω : ι → Bool) (K : ℕ) | |
| (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) | |
| (hs : (seekCycle R S a r x V k).succeeds ω = true) : | |
| (seekCycle R S a r x V k).charge ω = K + d := by | |
| induction r generalizing x V with | |
| | zero => | |
| by_cases hv : x ∈ S ∧ x ∉ V | |
| · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs | |
| split_ifs at hs with he | |
| · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] | |
| · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs | |
| | succ r ih => | |
| by_cases hv : x ∈ S ∧ x ∉ V | |
| · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs | |
| rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] | |
| exact ih _ _ hs | |
| · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs | |
| noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : | |
| List (α × ℕ) → Finset (α) → QueryTree (ι) | |
| | [], _ => accept | |
| | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) | |
| lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) | |
| (V : Finset (α)) (ω : ι → Bool) | |
| (hs : (seekCycles R S L V).succeeds ω = true) : | |
| (seekCycles R S L V).charge ω = L.length * d := by | |
| induction L generalizing V with | |
| | nil => simp [seekCycles,charge] | |
| | cons ar L ih => | |
| obtain ⟨a,r⟩ := ar | |
| rw [seekCycles] | |
| rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) | |
| (fun V hs => ih V hs) hs] | |
| simp [Nat.add_mul] | |
| lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : | |
| finiteMean (fun ω : ι → Bool => | |
| if (seekCycles R S L ∅).succeeds ω then | |
| ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by | |
| let T := seekCycles R S L ∅ | |
| have hh := mean_freshCharge_le_one T | |
| have he : finiteMean (fun ω : ι → Bool => | |
| if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = | |
| finiteMean (fun ω : ι → Bool => | |
| if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by | |
| apply finiteMean_congr | |
| intro ω | |
| cases hs : T.succeeds ω | |
| · simp | |
| · simp only [↓reduceIte] | |
| have hc := fresh_add_stale T ∅ ω | |
| rw [seekCycles_raw_charge R S L ∅ ω hs] at hc | |
| have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by | |
| rw [←pow_add,hc,←pow_mul,Nat.mul_comm] | |
| rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] | |
| rw [← he] | |
| exact hh | |
| end QueryTree | |
| noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : | |
| Finset (ι) := | |
| V.biUnion (fun x => R.path b x) | |
| @[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by | |
| classical | |
| simp [exposedPaths] | |
| lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : | |
| exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by | |
| classical | |
| simp [exposedPaths,Finset.union_comm] | |
| noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := | |
| (R.path b z ∩ exposedPaths R b V).card | |
| namespace QueryTree | |
| open Thorp.QueryTree | |
| lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) | |
| (x : α) (V W : Finset (α)) (z : α) | |
| (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) | |
| (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : | |
| (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ | |
| (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = | |
| (k W).staleCharge (exposedPaths R (ω) W) ω + | |
| terminalCharge R (ω) z (W.erase z) := by | |
| classical | |
| induction r generalizing x V with | |
| | zero => | |
| simp only [cycleTrace] at h | |
| split_ifs at h with hv | |
| obtain ⟨hxS,hxV,hxa⟩ := hv | |
| obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) | |
| simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] | |
| constructor | |
| · trivial | |
| · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, | |
| Finset.erase_insert hxV] | |
| simp only [terminalCharge] | |
| | succ r ih => | |
| simp only [cycleTrace] at h | |
| split_ifs at h with hv | |
| obtain ⟨hxS,hxV⟩ := hv | |
| rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] | |
| rw [← exposedPaths_insert] | |
| exact ih _ _ h | |
| lemma seekCycle_orbit (S V : Finset (α)) (z : α) | |
| (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) | |
| (hS : orbitSet (R.perm ω) z ⊆ S) | |
| (hV : Disjoint V (orbitSet (R.perm ω) z)) : | |
| let p := R.perm ω | |
| let W := V ∪ orbitSet p z | |
| (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ | |
| (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge | |
| (exposedPaths R (ω) V) ω = | |
| (k W).staleCharge (exposedPaths R (ω) W) ω + | |
| terminalCharge R (ω) z (W.erase z) := by | |
| exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) | |
| end QueryTree | |
| end RoutingNetwork | |
| end Thorp | |
| end ThorpNine.Adaptive | |
| end OAI | |
Xet Storage Details
- Size:
- 36.6 kB
- Xet hash:
- f9329d7db726424b88755eb01ce8cda12139d7199a624b0eb999eb0d94cb06f0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.