File size: 3,760 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import OAI.Combinatorics.EditApproximation.Queries.QuerySourceBuffers
import OAI.Combinatorics.EditApproximation.Definitions


namespace OAI

/-! Counted local data buffers for the adaptive gathers. Bounds depend on
stored keys and the requested key, not on an unbounded ambient key type. -/

namespace EditApproximation
namespace BinaryFraction

theorem gatheredWordLookupWithWork_cost_on {ΞΊ : Type*}
    (equal : ΞΊ β†’ ΞΊ β†’ Bool Γ— β„•) (C : β„•) (keys : List ΞΊ)
    (values : List BinaryFraction) (query : ΞΊ)
    (hC : βˆ€ key ∈ keys, (equal query key).2 ≀ C) :
    (gatheredWordLookupWithWork equal keys values query).2 ≀
      1 + keys.length * (C + 1) := by
  induction keys generalizing values with
  | nil => simp only [gatheredWordLookupWithWork, List.length_nil, Nat.zero_mul, Nat.add_zero, le_rfl]
  | cons key keys ih =>
    have hc := hC key List.mem_cons_self
    have ht := ih (values.drop 1) (fun k hk => hC k (List.mem_cons_of_mem _ hk))
    cases values with
    | nil => simp only [gatheredWordLookupWithWork]; omega
    | cons value values =>
      simp only [List.drop_succ_cons, List.drop_zero] at ht
      simp only [gatheredWordLookupWithWork]
      split_ifs <;> simp only [List.length_cons, Nat.add_mul, Nat.one_mul] <;> omega



@[simp] theorem queryChildReadWithWork_value {M n : β„•}
    (keys : List (Fin M Γ— TargetInterval n)) (values : List BinaryFraction)
    (i : Fin M) (q : TargetInterval n) :
    (queryChildReadWithWork keys values i q).1.value =
      finiteAnswerTable keys (values.map value) (i, q) :=
  gatheredWordLookupWithWork_value _ coordinateEqualWithWork_value keys values (i, q)

theorem queryChildReadWithWork_cost {M n : β„•} (keys : List (Fin M Γ— TargetInterval n))
    (values : List BinaryFraction) (i : Fin M) (q : TargetInterval n)
    (B : β„•) (hM : Nat.size M ≀ B) (hn : Nat.size n ≀ B) :
    (queryChildReadWithWork keys values i q).2 ≀ 1 + keys.length * (24 * B + 9) := by
  exact gatheredWordLookupWithWork_cost coordinateEqualWithWork (24 * B + 8)
    (fun a b => coordinateEqualWithWork_cost a b B hM hn) keys values (i, q)



@[simp] theorem queryHistoryReadWithWork_value {M n : β„•}
    (keys : List (Fin M Γ— β„• Γ— TargetInterval n)) (values : List BinaryFraction)
    (s : β„•) (input : Fin M Γ— TargetInterval n) :
    (queryHistoryReadWithWork keys values s input).1.value =
      finiteAnswerTable keys (values.map value) (input.1, s, input.2) :=
  gatheredWordLookupWithWork_value _ queryHistoryEqualWithWork_value keys values (input.1, s, input.2)

theorem queryHistoryReadWithWork_cost {M n : β„•}
    (keys : List (Fin M Γ— β„• Γ— TargetInterval n)) (values : List BinaryFraction)
    (s : β„•) (input : Fin M Γ— TargetInterval n) (B : β„•)
    (hM : Nat.size M ≀ B) (hn : Nat.size n ≀ B) (hs : Nat.size s ≀ B)
    (ht : βˆ€ key ∈ keys, Nat.size key.2.1 ≀ B) :
    (queryHistoryReadWithWork keys values s input).2 ≀
      1 + keys.length * (32 * B + 12) := by
  apply gatheredWordLookupWithWork_cost_on queryHistoryEqualWithWork (32 * B + 11)
  intro key hk
  have hc := coordinateEqualWithWork_cost input (key.1, key.2.2) B hM hn
  have he := naturalEqualWithWork_cost s key.2.1 B hs (ht key hk)
  change (coordinateEqualWithWork input (key.1, key.2.2)).2 +
    (naturalEqualWithWork s key.2.1).2 + 1 ≀ _
  omega

theorem queryHistoryReadWithWork_width {M n : β„•}
    (keys : List (Fin M Γ— β„• Γ— TargetInterval n)) (values : List BinaryFraction)
    (s : β„•) (input : Fin M Γ— TargetInterval n) (B : β„•)
    (hB : 2 ≀ B) (hv : βˆ€ v ∈ values, v.width ≀ B) :
    (queryHistoryReadWithWork keys values s input).1.width ≀ B :=
  gatheredWordLookupWithWork_width _ keys values _ B hB hv

end BinaryFraction
end EditApproximation

end OAI