File size: 2,784 Bytes
e63eb7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Combinatorics.EditApproximation.Queries.QueryPhysicalScalarReads
import OAI.Combinatorics.EditApproximation.Definitions


namespace OAI

/-! Counted pass/copy indexing for the independent scalar family.  Both
remainders and the complete family address are computed before lookup. -/

namespace EditApproximation



theorem queryFinOfNatWithWork_value (bound value : ℕ) (hb : 0 < bound) [NeZero bound] :
    (queryFinOfNatWithWork bound value hb).1 = Fin.ofNat bound value := by
  apply Fin.ext
  exact (binaryNaturalDivModWithWork_spec value bound hb).2

theorem queryFinOfNatWithWork_cost (bound value B : ℕ) (hb : 0 < bound)
    (hbound : Nat.size bound ≤ B) (hvalue : Nat.size value ≤ B) :
    (queryFinOfNatWithWork bound value hb).2 ≤ 60 * (B + 1) ^ 2 + 1 := by
  have h := binaryNaturalDivModWithWork_cost value bound
  change (binaryNaturalDivModWithWork value bound).2.2 + 1 ≤ _
  nlinarith only [h, hbound, hvalue, Nat.zero_le B]

section Family
variable {α : Type*} {M J R : ℕ} (target : List α)
  (N P F exponent H Q passes copies pass copy : ℕ)



theorem queryFamilyTagWithWork_value
    (scalar : PhysicalScalarKey M J N target.length exponent F Q R (localOnlineMassBound M P H)) :
    (queryFamilyTagWithWork target N P F exponent H Q passes copies pass copy scalar).1 =
      (Fin.ofNat (passes + 1) pass, Fin.ofNat (copies + 1) copy, scalar) := by
  simp only [queryFamilyTagWithWork, queryFinOfNatWithWork_value]



theorem queryFamilyGroupRead_refines (node : PhysicalInternalNode M J) (time : Fin R)
    (key : GroupScalarKey M F Q) :
    BitQuery.Refines (fun word value => word.value = value)
      (queryFamilyGroupRead target N P F exponent H Q passes copies pass copy node time key)
      (physicalFamilyGroupRead target N P F exponent H Q passes copies pass copy node time key) := by
  exact (queryPhysicalScalarGroupRead_refines M J N target.length exponent F Q R
    (localOnlineMassBound M P H) node time key).mapKeysWithWork _ _
      (queryFamilyTagWithWork_value target N P F exponent H Q passes copies pass copy)



theorem queryFamilyOnlineRead_refines (node : PhysicalInternalNode M J) (time : Fin R)
    (key : ℕ × TargetInterval target.length) (range : ℕ) :
    BitQuery.Refines (fun word value => word.value = value)
      (queryFamilyOnlineRead target N P F exponent H Q passes copies pass copy node time key range)
      (physicalFamilyOnlineRead target N P F exponent H Q passes copies pass copy node time key range) := by
  exact (queryPhysicalScalarOnlineRead_refines M J N target.length exponent F Q R
    (localOnlineMassBound M P H) node time key range).mapKeysWithWork _ _
      (queryFamilyTagWithWork_value target N P F exponent H Q passes copies pass copy)

end Family
end EditApproximation

end OAI