File size: 3,779 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import OAI.Combinatorics.EditApproximation.Queries.QueryPhysicalInitial
import OAI.Combinatorics.EditApproximation.Queries.QueryWarmupProgram
import OAI.Combinatorics.EditApproximation.Geometry.ChargedGlobalQuery
import OAI.Combinatorics.EditApproximation.Definitions


namespace OAI

/-! Executed warmup dispatch and ranked child reads.  Both the terminal
and positive-depth branches use the same adaptive initial-cone program. -/

namespace EditApproximation

section Child
variable {M J ny passes copies T S : ℕ}
  (parent : {r : PhysicalTableRequest M J ny // r.Bounded passes copies T S})
  (hbelow : parent.val.node.1.val < J) (hindex : 0 < parent.val.index)
  (input : Fin M × TargetInterval ny)



theorem queryChargedWarmupChild_refines :
    BitQuery.Refines (fun word value => word.value = value)
      (queryChargedWarmupChild parent hbelow hindex input)
      (chargedWarmupChild parent hbelow hindex input) :=
  queryChargedRead_refines parent _

end Child

section Warmup
variable (source target : List ℕ) {M J passes copies T S : ℕ}
  (N P F : ℕ) (A a : BinaryFraction) (multiplier : ℕ → ℕ)
  (parent : {r : PhysicalTableRequest M J target.length // r.Bounded passes copies T S})
  (occurrence : BinaryMemo PositionCounts) (symbolBits positionBits : ℕ)



theorem queryChargedWarmup_refines (factor : ℕ → ℚ) (hA : A.value = factor parent.val.pass) (hP : 0 < P)
    (ha : a.value = refinementFactor A.value F)
    (hs : ∀ z ∈ source, z < 2 ^ symbolBits) (ht : ∀ z ∈ target, z < 2 ^ symbolBits)
    (hp : target.length ≤ 2 ^ positionBits)
    (htable : occurrence = occurrenceBuild symbolBits positionBits target.zipIdx) :
    BitQuery.Refines (fun word value => word.value = value)
      (queryChargedWarmup source target N P F A a multiplier parent occurrence symbolBits positionBits)
      (chargedWarmupQuery source target N P F factor multiplier parent) := by
  have hi (q : TargetInterval target.length) := queryPhysicalInitial_refines source target N P F A a
    multiplier parent occurrence symbolBits positionBits q hP ha hs ht hp htable
  unfold queryChargedWarmup chargedWarmupQuery
  rw [← hA]
  apply BitQuery.Refines.charge
  by_cases hz : parent.val.index = 0
  · rw [dite_eq_left hz, dite_eq_left ((naturalEqualWithWork_value _ _).mpr hz)]
    exact hi _
  · rw [dite_eq_right hz, dite_eq_right (fun h => hz ((naturalEqualWithWork_value _ _).mp h))]
    apply BitQuery.Refines.charge
    by_cases hb : parent.val.node.1.val < J
    · rw [dite_eq_left hb, dite_eq_left ((binaryNaturalCompareWithWork_lt _ _).mpr hb)]
      dsimp only
      apply BitQuery.Refines.charge
      have htest : (wordLEWithWork
          (saturatingSubtractWithWork (physicalSourceInterval source.length parent.val.node).hi
            (physicalSourceInterval source.length parent.val.node).lo).1 [true]).1 = true ↔
          (physicalSourceInterval source.length parent.val.node).hi -
            (physicalSourceInterval source.length parent.val.node).lo ≤ 1 := by
        rw [wordLEWithWork_value, saturatingSubtractWithWork_value]
        rfl
      by_cases hshort : (physicalSourceInterval source.length parent.val.node).hi -
          (physicalSourceInterval source.length parent.val.node).lo ≤ 1
      · rw [ite_eq_left hshort, ite_eq_left (htest.mpr hshort)]
        exact hi _
      · rw [ite_eq_right hshort, ite_eq_right (fun h => hshort (htest.mp h))]
        unfold physicalWarmupStepQuery
        rw [← ha]
        exact queryWarmupProgram_refines _ N P F hP a _ _ _ _ _ hi
          (fun input => queryChargedWarmupChild_refines parent hb _ input)
    · rw [dite_eq_right hb, dite_eq_right (fun h => hb ((binaryNaturalCompareWithWork_lt _ _).mp h))]
      exact hi _

end Warmup
end EditApproximation

end OAI