File size: 2,118 Bytes
f0f05de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Combinatorics.BinaryEdit.LCSEditUpper
import OAI.Combinatorics.BinaryEdit.EditLCSLower

namespace OAI

/-!
Both metric comparisons in the preliminary section, for the actual unrestricted
unit-cost edit scripts and longest-common-subsequence definitions.
-/
namespace TreeEdit.BinaryLower

/-- Second inequality of source equation `eq:metric-conversion`. -/
theorem delta_le_twice_editDistance {α : Type*} (x y : List α) :
    x.length + y.length - 2 * lcs x y ≤ 2 * ed x y := by
  have hs : EditScript x y (ed x y) :=
    TreeEdit.ed_script x y
  exact EditScript.lcs_loss_le hs

/-- Ordinary edit distance and insertion--deletion distance differ by at most
factor two, without imposing a cap on intermediate script words. -/
theorem editDistance_delta_bounds {α : Type*} (x y : List α) :
    ed x y ≤ x.length + y.length - 2 * lcs x y ∧
      x.length + y.length - 2 * lcs x y ≤ 2 * ed x y :=
  ⟨editDistance_le_delta x y, delta_le_twice_editDistance x y⟩

/-- Lower inequality of source equation `eq:deficit`, on equal-length words. -/
theorem deficit_le_editDistance {α : Type*} {n : ℕ} {x y : List α}
    (hx : x.length = n) (hy : y.length = n) :
    deficit n x y ≤ ed x y := by
  have h := delta_le_twice_editDistance x y
  rw [hx, hy] at h
  unfold deficit
  omega

/-- The complete equal-length deficit comparison, including empty words. -/
theorem editDistance_deficit_bounds {α : Type*} {n : ℕ} {x y : List α}
    (hx : x.length = n) (hy : y.length = n) :
    deficit n x y ≤ ed x y ∧
      ed x y ≤ 2 * deficit n x y :=
  ⟨deficit_le_editDistance hx hy, editDistance_le_twice_deficit hx hy⟩

/-- Real-valued form used in the fixed-length binary conversion inequalities. -/
theorem editDistance_deficit_bounds_real {α : Type*} {n : ℕ} {x y : List α}
    (hx : x.length = n) (hy : y.length = n) :
    (deficit n x y : ℝ) ≤ (ed x y : ℝ) ∧
      (ed x y : ℝ) ≤ 2 * (deficit n x y : ℝ) := by
  constructor
  · exact_mod_cast deficit_le_editDistance hx hy
  · exact_mod_cast editDistance_le_twice_deficit hx hy

end TreeEdit.BinaryLower

end OAI