File size: 6,238 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import OAI.Combinatorics.EditApproximation.Geometry.ChargedGlobalQuery
import OAI.Combinatorics.EditApproximation.Probability.FiniteQueryWork

namespace OAI

/-! All initial-entry information used by a charged table body arrives
through explicit requests. Flattening those requests gives an adaptive
coarse oracle program whose shape is independent of coarse answers. -/

namespace EditApproximation

namespace FiniteQuery

def substitute {ι κ : Type*} (ask : ι → FiniteQuery κ) : FiniteQuery ι → FiniteQuery κ
  | .done value => .done value
  | .read key next => bind (ask key) (fun value => substitute ask (next value))

theorem substitute_cost {ι κ : Type*} (ask : ι → FiniteQuery κ) (oracle : κ → ℚ)
    (weight : κ → ℕ) (query : FiniteQuery ι) :
    (query.substitute ask).cost oracle weight = query.cost
      (fun key => (ask key).value oracle) (fun key => (ask key).cost oracle weight) := by
  induction query with
  | done value => rfl
  | read key next ih =>
    simp only [substitute, cost_bind, cost]
    exact congrArg ((ask key).cost oracle weight + ·) (ih ((ask key).value oracle))

theorem substitute_value {ι κ : Type*} (ask : ι → FiniteQuery κ) (oracle : κ → ℚ)
    (query : FiniteQuery ι) :
    (query.substitute ask).value oracle = query.value (fun key => (ask key).value oracle) := by
  induction query with
  | done value => rfl
  | read key next ih =>
    simp only [substitute, bind_value, value]
    exact ih ((ask key).value oracle)

end FiniteQuery

section Coarse

variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
  (source target : List α) (N P F exponent H Q T S passes copies : ℕ)
  (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
  (group : ℕ → ℕ → PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q)
  (integer : ℕ → ℕ → PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)

/-- An internal refinement body never inspects a coarse seed function
while building its local query. Its seed needs are explicit child reads. -/
theorem physicalGlobalQuery_refinement_initial_independent
    (left right : PhysicalEntry M J target.length → ℕ)
    (parent : PhysicalTableRequest M J target.length)
    (hi : ¬ parent.index ≤ T) (hd : parent.node.1.val < J)
    (hw : ¬ (physicalSourceInterval source.length parent.node).hi -
      (physicalSourceInterval source.length parent.node).lo ≤ 1) :
    physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
      tau eta kappa delta group integer left parent =
    physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
      tau eta kappa delta group integer right parent := by
  unfold physicalGlobalQuery
  dsimp only
  erw [dite_eq_right hi, dite_eq_right hi, dite_eq_left hd, dite_eq_left hd,
    dite_eq_right hw, dite_eq_right hw]

/-- Coarse answers enter the charged program only at coarse leaves. -/
theorem chargedGlobalQuery_table_initial_independent
    (left right : PhysicalEntry M J target.length → ℕ)
    (parent : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) :
    chargedGlobalQuery source target N P F exponent H Q T S passes copies factor multiplier
      tau eta kappa delta group integer left (.inr parent) =
    chargedGlobalQuery source target N P F exponent H Q T S passes copies factor multiplier
      tau eta kappa delta group integer right (.inr parent) := by
  unfold chargedGlobalQuery
  dsimp only
  split_ifs with hi hd hw
  · rfl
  · rfl
  · unfold physicalBoundedQuery restrictRankedProgram
    rw [physicalGlobalQuery_refinement_initial_independent source target N P F exponent H Q T S
      copies factor multiplier tau eta kappa delta group integer left right parent.val hi hd hw]
  · rfl

/-- The flattened program receives each coarse answer from an explicit
external read. The constant zero here is never used as a seed answer. -/
def chargedCoarseQuery (root : ChargedPhysicalRequest M J target.length passes copies T S) :
    FiniteQuery (PhysicalEntry M J target.length) :=
  match root with
  | .inl entry => .read entry FiniteQuery.done
  | .inr parent =>
    (chargedGlobalQuery source target N P F exponent H Q T S passes copies factor multiplier
      tau eta kappa delta group integer (fun _ => 0) (.inr parent)).substitute
        (fun child => chargedCoarseQuery child.val)
termination_by root.rank
decreasing_by exact child.property

theorem chargedCoarseQuery_value
    (initial : PhysicalEntry M J target.length → ℕ)
    (root : ChargedPhysicalRequest M J target.length passes copies T S) :
    (chargedCoarseQuery source target N P F exponent H Q T S passes copies factor multiplier
      tau eta kappa delta group integer root).value (fun entry => (initial entry : ℚ)) =
    rankedProgramValue ChargedPhysicalRequest.rank
      (chargedGlobalQuery source target N P F exponent H Q T S passes copies factor multiplier
        tau eta kappa delta group integer initial) root := by
  have hall : ∀ level root, root.rank = level →
      (chargedCoarseQuery source target N P F exponent H Q T S passes copies factor multiplier
        tau eta kappa delta group integer root).value (fun entry => (initial entry : ℚ)) =
      rankedProgramValue ChargedPhysicalRequest.rank
        (chargedGlobalQuery source target N P F exponent H Q T S passes copies factor multiplier
          tau eta kappa delta group integer initial) root := by
    intro level
    induction level using Nat.strong_induction_on with
    | h level ih =>
      intro root hlevel
      cases root with
      | inl entry =>
        rw [chargedCoarseQuery, rankedProgramValue]
        rfl
      | inr parent =>
        rw [chargedCoarseQuery, FiniteQuery.substitute_value, rankedProgramValue,
          chargedGlobalQuery_table_initial_independent source target N P F exponent H Q T S passes copies
            factor multiplier tau eta kappa delta group integer (fun _ => 0) initial parent]
        congr 1
        funext child
        exact ih child.val.rank (hlevel ▸ child.property) child.val rfl
  exact hall root.rank root rfl

end Coarse

end EditApproximation

end OAI