Buckets:
| import OAI.Combinatorics.EditApproximation.Binary.BinaryBandCoordinates | |
| import OAI.Combinatorics.EditApproximation.Definitions | |
| namespace OAI | |
| /-! First-occurrence duplicate removal for the literal adaptive query lists. | |
| The equality tests, accumulated list, and final reversal are charged. -/ | |
| namespace EditApproximation | |
| theorem queryEraseLoopWithWork_value {α : Type*} [BEq α] [LawfulBEq α] | |
| (equal : α → α → Bool × ℕ) (heq : ∀ a b, (equal a b).1 = true ↔ a = b) | |
| (xs seen : List α) : | |
| (queryEraseLoopWithWork equal xs seen).1 = List.eraseDupsBy.loop (· == ·) xs seen := by | |
| induction xs generalizing seen with | |
| | nil => rfl | |
| | cons a xs ih => | |
| have ht : (memberByWithWork equal a seen).1 = seen.any (a == ·) := by | |
| apply Bool.eq_iff_iff.mpr | |
| simp only [memberByWithWork_value equal heq, List.any_eq_true, beq_iff_eq] | |
| exact ⟨fun h => ⟨a, h, rfl⟩, fun ⟨b, hb, hab⟩ => hab ▸ hb⟩ | |
| simp only [queryEraseLoopWithWork, ht, ih, List.eraseDupsBy.loop] | |
| cases seen.any (a == ·) <;> rfl | |
| @[simp] theorem queryEraseWithWork_value {α : Type*} [BEq α] [LawfulBEq α] | |
| (equal : α → α → Bool × ℕ) (heq : ∀ a b, (equal a b).1 = true ↔ a = b) | |
| (xs : List α) : (queryEraseWithWork equal xs).1 = xs.eraseDups := | |
| queryEraseLoopWithWork_value equal heq xs [] | |
| theorem queryEraseLoopWithWork_nodup {α : Type*} | |
| (equal : α → α → Bool × ℕ) (heq : ∀ a b, (equal a b).1 = true ↔ a = b) | |
| (xs seen : List α) (hs : seen.Nodup) : | |
| (queryEraseLoopWithWork equal xs seen).1.Nodup := by | |
| induction xs generalizing seen with | |
| | nil => simpa only [queryEraseLoopWithWork, List.nodup_reverse] using hs | |
| | cons a xs ih => | |
| change (queryEraseLoopWithWork equal xs | |
| (if (memberByWithWork equal a seen).1 then seen else a :: seen)).1.Nodup | |
| by_cases h : (memberByWithWork equal a seen).1 = true | |
| · rw [ite_eq_left h] | |
| exact ih seen hs | |
| · rw [ite_eq_right h] | |
| apply ih | |
| exact List.nodup_cons.mpr ⟨fun ha => h ((memberByWithWork_value equal heq a seen).mpr ha), hs⟩ | |
| theorem queryEraseWithWork_nodup {α : Type*} | |
| (equal : α → α → Bool × ℕ) (heq : ∀ a b, (equal a b).1 = true ↔ a = b) | |
| (xs : List α) : (queryEraseWithWork equal xs).1.Nodup := | |
| queryEraseLoopWithWork_nodup equal heq xs [] (by simp) | |
| theorem queryEraseLoopWithWork_cost {α : Type*} (equal : α → α → Bool × ℕ) | |
| (C : ℕ) (hC : ∀ a b, (equal a b).2 ≤ C) (xs seen : List α) : | |
| (queryEraseLoopWithWork equal xs seen).2 ≤ | |
| (xs.length + 1) * (xs.length + seen.length + 1) * (C + 4) := by | |
| induction xs generalizing seen with | |
| | nil => | |
| simp only [queryEraseLoopWithWork, List.length_nil, zero_add, one_mul] | |
| nlinarith | |
| | cons a xs ih => | |
| have hm := memberByWithWork_cost equal C hC a seen | |
| have hs : (if (memberByWithWork equal a seen).1 then seen else a :: seen).length ≤ | |
| seen.length + 1 := by | |
| split | |
| · omega | |
| · simp only [List.length_cons]; omega | |
| have hi := ih (if (memberByWithWork equal a seen).1 then seen else a :: seen) | |
| have hh : (queryEraseLoopWithWork equal xs | |
| (if (memberByWithWork equal a seen).1 then seen else a :: seen)).2 ≤ | |
| (xs.length + 1) * (xs.length + (seen.length + 1) + 1) * (C + 4) := | |
| hi.trans (Nat.mul_le_mul_right _ (Nat.mul_le_mul_left _ (by omega))) | |
| change (memberByWithWork equal a seen).2 + _ + 2 ≤ _ | |
| simp only [List.length_cons] | |
| nlinarith only [hm, hh, Nat.zero_le xs.length, Nat.zero_le seen.length, Nat.zero_le C] | |
| theorem queryEraseWithWork_cost {α : Type*} (equal : α → α → Bool × ℕ) | |
| (C : ℕ) (hC : ∀ a b, (equal a b).2 ≤ C) (xs : List α) : | |
| (queryEraseWithWork equal xs).2 ≤ (xs.length + 1) ^ 2 * (C + 4) := by | |
| simpa only [queryEraseWithWork, List.length_nil, Nat.add_zero, pow_two] using | |
| queryEraseLoopWithWork_cost equal C hC xs [] | |
| @[simp] theorem queryIntervalEqualWithWork_value {n : ℕ} (a b : TargetInterval n) : | |
| (queryIntervalEqualWithWork a b).1 = true ↔ a = b := by | |
| simp only [queryIntervalEqualWithWork, Bool.and_eq_true, naturalEqualWithWork_value] | |
| constructor | |
| · rintro ⟨hl, hh⟩ | |
| cases a | |
| cases b | |
| cases hl | |
| cases hh | |
| rfl | |
| · intro h | |
| subst b | |
| exact ⟨rfl, rfl⟩ | |
| theorem queryIntervalEqualWithWork_cost {n : ℕ} (a b : TargetInterval n) | |
| (B : ℕ) (hn : Nat.size n ≤ B) : | |
| (queryIntervalEqualWithWork a b).2 ≤ 16 * B + 5 := by | |
| have hl := naturalEqualWithWork_cost a.lo b.lo B | |
| ((Nat.size_le_size (a.ordered.trans a.valid)).trans hn) | |
| ((Nat.size_le_size (b.ordered.trans b.valid)).trans hn) | |
| have hh := naturalEqualWithWork_cost a.hi b.hi B | |
| ((Nat.size_le_size a.valid).trans hn) ((Nat.size_le_size b.valid).trans hn) | |
| change _ + _ + 1 ≤ _ | |
| omega | |
| end EditApproximation | |
| end OAI | |
Xet Storage Details
- Size:
- 4.85 kB
- Xet hash:
- 6c85e0508a6099e656c316f269ba503f3662006f4d2b67e3e90360e0be7d034f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.