File size: 3,241 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
import OAI.Combinatorics.EditApproximation.Geometry.Connections

namespace OAI

/-!
# Preservation of the two action lower bounds

The action invariant follows from actual edit and shift connection
inequalities, rather than an assumed lower-bound-preserving oracle.
-/

namespace EditApproximation

open EditDistortion

theorem list_sum_map_le {ι : Type*} (entries : List ι) (f g : ι → ℝ)
    (h : ∀ i ∈ entries, f i ≤ g i) : (entries.map f).sum ≤ (entries.map g).sum := by
  induction entries with
  | nil => rfl
  | cons i rest ih =>
    simp only [List.map_cons, List.sum_cons]
    exact add_le_add (h i (by simp)) (ih fun j hj => h j (by simp [hj]))

theorem list_sum_map_div {ι : Type*} (entries : List ι) (f : ι → ℝ) (a : ℝ) :
    (entries.map fun i => f i / a).sum = (entries.map f).sum / a := by
  induction entries with
  | nil => simp
  | cons i rest ih => simp only [List.map_cons, List.sum_cons, ih, add_div]

theorem actual_action_lower {α : Type*} (word : List α)
    (children : List (List α × TargetInterval word.length))
    (parent : TargetInterval word.length) (a : ℝ) (ha : 1 ≤ a)
    (value : (List α × TargetInterval word.length) → ℝ)
    (hcost : ∀ child ∈ children,
      (edit child.1 (substring word child.2.lo child.2.hi) : ℝ) / a ≤ value child)
    (hgap : ∀ child ∈ children,
      |signedLengthGap child.1 (substring word child.2.lo child.2.hi)| ≤ value child) :
    max ((edit (children.map Prod.fst).flatten (substring word parent.lo parent.hi) : ℝ) / a)
        |signedLengthGap (children.map Prod.fst).flatten (substring word parent.lo parent.hi)| ≤
      (connectionBudget parent.lo (children.map Prod.snd) parent.hi : ℝ) +
        (children.map value).sum := by
  have ha0 : 0 < a := by linarith
  let conn : ℝ := connectionBudget parent.lo (children.map Prod.snd) parent.hi
  have hconn0 : 0 ≤ conn := Nat.cast_nonneg _
  have hconnDiv : conn / a ≤ conn := by
    apply (div_le_iff₀ ha0).2
    nlinarith
  apply max_le
  · have hconnection :
        (edit (children.map Prod.fst).flatten (substring word parent.lo parent.hi) : ℝ) ≤
          (children.map fun child =>
            (edit child.1 (substring word child.2.lo child.2.hi) : ℝ)).sum + conn := by
      dsimp only [conn]
      have hcast (entries : List (List α × TargetInterval word.length)) :
          (((entries.map fun child =>
            edit child.1 (substring word child.2.lo child.2.hi)).sum : ℕ) : ℝ) =
            (entries.map fun child =>
              (edit child.1 (substring word child.2.lo child.2.hi) : ℝ)).sum := by
        induction entries with
        | nil => simp
        | cons child rest ih => simp only [List.map_cons, List.sum_cons, Nat.cast_add, ih]
      rw [← hcast]
      exact_mod_cast child_connection_bound word children parent
    have hdivide := div_le_div_of_nonneg_right hconnection ha0.le
    rw [add_div] at hdivide
    have hsum := list_sum_map_le children _ value hcost
    rw [list_sum_map_div] at hsum
    linarith
  · have hconnection := child_shift_connection_bound word children parent
    have hsum := list_sum_map_le children _ value hgap
    change _ ≤ conn + _
    linarith

end EditApproximation

end OAI