File size: 2,195 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
import OAI.Combinatorics.EditApproximation.Binary.BinaryGatheredValues

namespace OAI

/-! The default-zero finite buffers preserve the nonnegative bounds of
paired initial/history coordinates when the initial buffer covers them. -/

namespace EditApproximation

theorem finiteAnswerTable_eq_zero_of_not_mem {κ : Type*} [DecidableEq κ]
    (keys : List κ) (values : List ℚ) (query : κ) (hq : query ∉ keys) :
    finiteAnswerTable keys values query = 0 := by
  induction keys generalizing values with
  | nil => rfl
  | cons key keys ih =>
    cases values with
    | nil => rfl
    | cons value values =>
      have hk : query ≠ key := fun he => hq (List.mem_cons.mpr (Or.inl he))
      have ht : query ∉ keys := fun he => hq (List.mem_cons_of_mem key he)
      simpa only [finiteAnswerTable, ite_eq_right hk] using ih values ht

theorem finiteAnswerTable_nonneg {κ : Type*} [DecidableEq κ]
    (keys : List κ) (values : List ℚ) (query : κ) (hv : ∀ value ∈ values, 0 ≤ value) :
    0 ≤ finiteAnswerTable keys values query := by
  induction keys generalizing values with
  | nil => exact le_rfl
  | cons key keys ih =>
    cases values with
    | nil => exact le_rfl
    | cons value values =>
      unfold finiteAnswerTable
      split_ifs
      · exact hv value List.mem_cons_self
      · exact ih values (fun v h => hv v (List.mem_cons_of_mem _ h))

theorem finiteAnswerTable_map_le_of_subset {κ : Type*} [DecidableEq κ]
    (keys initialKeys : List κ) (history initial : κ → ℚ)
    (hkeys : ∀ key ∈ keys, key ∈ initialKeys)
    (hi : ∀ key, 0 ≤ initial key)
    (hle : ∀ key, history key ≤ initial key) (query : κ) :
    finiteAnswerTable keys (keys.map history) query ≤
      finiteAnswerTable initialKeys (initialKeys.map initial) query := by
  by_cases hq : query ∈ keys
  · rw [finiteAnswerTable_map keys history query hq,
      finiteAnswerTable_map initialKeys initial query (hkeys query hq)]
    exact hle query
  · rw [finiteAnswerTable_eq_zero_of_not_mem keys _ query hq]
    apply finiteAnswerTable_nonneg
    intro value hv
    obtain ⟨key, _, rfl⟩ := List.mem_map.mp hv
    exact hi key

end EditApproximation

end OAI