File size: 8,635 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import OAI.Combinatorics.BinaryEdit.FiniteTreeInstantiation
import OAI.Combinatorics.BinaryEdit.FiniteWordPrimeSeparation
import OAI.Combinatorics.BinaryEdit.FiniteTreeTags
import OAI.Combinatorics.BinaryEdit.FiniteSeparationArithmetic
import OAI.Combinatorics.BinaryEdit.TaggedArrays

namespace OAI

/-!
# Geometric separation for the concrete finite tree

The prime construction supplies the half-child condition in the
geometric induction.
-/

noncomputable section
namespace TreeEdit.BinaryLower.FiniteTree

open scoped BigOperators

/-- Literal row/block array of a concrete node word. -/
def finiteBlocks {m k : β„•} (primes : Fin k β†’ Fin m β†’ β„•) (iβ‚€ : Fin m)
    (T h : β„•) (p : List (Fin m)) (x : State (wordPeriods primes)) :
    Fin T β†’ Fin m β†’ Word (Symbol (wordPeriods primes)) ((m * T) ^ h) :=
  fun a i => ⟨finiteWord primes iβ‚€ T h (p ++ [i]) (x + a.val β€’ wordU primes iβ‚€ p),
    finiteWord_length primes iβ‚€ T h _ _⟩

theorem finiteWord_succ_eq_rows {m k : β„•} (primes : Fin k β†’ Fin m β†’ β„•)
    (iβ‚€ : Fin m) (T h : β„•) (p : List (Fin m)) (x : State (wordPeriods primes)) :
    finiteWord primes iβ‚€ T (h + 1) p x =
      TaggedExtraction.rows (finiteBlocks primes iβ‚€ T h p x) := by
  have hrange : (List.finRange T).map Fin.val = List.range T := by
    apply List.ext_getElem
    Β· simp
    Β· intro j hj hj'
      simp
  unfold finiteWord nodeWord
  rw [← hrange, List.flatMap_map]
  rfl

/-- The relative coefficient comparing two rows in a child. -/
def finiteRowShift {m k T : β„•} (primes : Fin k β†’ Fin m β†’ β„•)
    (p : List (Fin m)) (hp : p.length < k) (a b : Fin T) (t : β„€) : β„€ :=
  (b.val : β„€) - (a.val : β„€) + t *
    (FiniteVectors.levelProduct primes ⟨p.length, hp⟩ : β„€)

/-- Children whose prescribed period does not divide the relative coefficient. -/
def separatedChildren {m k T : β„•} (primes : Fin k β†’ Fin m β†’ β„•)
    (iβ‚€ : Fin m) (p : List (Fin m)) (hp : p.length < k) (a b : Fin T) (t : β„€) :
    Finset (Fin m) :=
  Finset.univ.filter fun i => Β¬ (wordPeriod primes iβ‚€ (p ++ [i]) : β„€) ∣
    finiteRowShift primes p hp a b t

/-- Ordered-tag alignment and half-child nondivisibility imply separation
for arbitrary common-subsequence matchings. -/
theorem finiteWord_separation_of_half_children {m k T : β„•}
    (primes : Fin k β†’ Fin m β†’ β„•) (iβ‚€ : Fin m) (hm : 2 ≀ m) (hT : 0 < T)
    (hhalf : βˆ€ p (hp : p.length < k) (a b : Fin T) (t : β„€),
      Β¬ (wordPeriod primes iβ‚€ p : β„€) ∣ t β†’
      m ≀ 2 * (separatedChildren primes iβ‚€ p hp a b t).card)
    (h : β„•) (p : List (Fin m)) (hlen : p.length + h = k)
    (x : State (wordPeriods primes)) (t : β„€)
    (ht : Β¬ (wordPeriod primes iβ‚€ p : β„€) ∣ t) :
    (((m * T) ^ h : β„•) : ℝ) / (4 : ℝ) ^ h ≀
      (deficit ((m * T) ^ h) (finiteWord primes iβ‚€ T h p x)
        (finiteWord primes iβ‚€ T h p (x + t β€’ wordW primes iβ‚€ p)) : ℝ) := by
  classical
  induction h generalizing p x t with
  | zero =>
      have hp : p.length = k := by simpa using hlen
      simpa using (finiteWord_leaf_deficit primes iβ‚€ T p hp x t ht).symm.le
  | succ h ih =>
      have hp : p.length < k := by omega
      let B : β„• := (m * T) ^ h
      let q : ℝ := (B : ℝ) / (4 : ℝ) ^ h
      let d : ℝ := (m : ℝ) * q / 2
      let X := finiteBlocks primes iβ‚€ T h p x
      let Y := finiteBlocks primes iβ‚€ T h p (x + t β€’ wordW primes iβ‚€ p)
      have hB : 0 < B := by dsimp [B]; exact pow_pos (Nat.mul_pos (by omega) hT) _
      have hq : 0 ≀ q := by dsimp [q]; positivity
      have hd : 0 ≀ d := by dsimp [d]; positivity
      have hlocal (a b : Fin T) : d ≀ βˆ‘ i, (deficit B (X a i).val (Y b i).val : ℝ) := by
        apply row_deficit_charge (separatedChildren primes iβ‚€ p hp a b t) _ q hq
          (fun i => Nat.cast_nonneg _) _ (hhalf p hp a b t ht)
        intro i hi
        have hnot : Β¬ (wordPeriod primes iβ‚€ (p ++ [i]) : β„€) ∣
            finiteRowShift primes p hp a b t := (Finset.mem_filter.mp hi).2
        change q ≀ (deficit B
          (finiteWord primes iβ‚€ T h (p ++ [i]) (x + a.val β€’ wordU primes iβ‚€ p))
          (finiteWord primes iβ‚€ T h (p ++ [i])
            (x + t β€’ wordW primes iβ‚€ p + b.val β€’ wordU primes iβ‚€ p)) : ℝ)
        rw [finiteWord_child_relative primes iβ‚€ i T h p hlen x t a.val b.val]
        exact ih (p ++ [i]) (by simp; omega) _ _ hnot
      have hX : βˆ€ (a : Fin T) (i : Fin m) (s : Symbol (wordPeriods primes)),
          s ∈ (X a i).val β†’ s ∈ subtreeAlphabet (wordPeriods primes) (p ++ [i]) := by
        intro a i s hs
        exact mem_subtreeAlphabet_of_mem (wordPeriods primes)
          ⟨List.replicate k iβ‚€, by simp⟩ (wordU primes iβ‚€) h (p ++ [i])
          (by simp; omega) _ s hs
      have hY : βˆ€ (a : Fin T) (i : Fin m) (s : Symbol (wordPeriods primes)),
          s ∈ (Y a i).val β†’ s ∈ subtreeAlphabet (wordPeriods primes) (p ++ [i]) := by
        intro a i s hs
        exact mem_subtreeAlphabet_of_mem (wordPeriods primes)
          ⟨List.replicate k iβ‚€, by simp⟩ (wordU primes iβ‚€) h (p ++ [i])
          (by simp; omega) _ s hs
      have hdg : d ≀ (((m - 1) * B : β„•) : ℝ) := by
        have hh := finite_charge_le_gap m h hm (B : ℝ) (Nat.cast_nonneg _)
        simpa [d, q, Nat.cast_mul, Nat.cast_sub (show 1 ≀ m by omega)] using hh
      have hsep := (Tagged.rows_with_ordered_tags hT hm hB
        (fun i => subtreeAlphabet (wordPeriods primes) (p ++ [i]))
        (subtreeAlphabet_children_pairwise_disjoint (wordPeriods primes) p)
        X Y hX hY d hd hlocal).2.2 hdg
      have hN : T * m * B = (m * T) ^ (h + 1) := by dsimp [B]; rw [pow_succ]; ring
      have hcharge : (T : ℝ) * d / 2 = (((m * T) ^ (h + 1) : β„•) : ℝ) / (4 : ℝ) ^ (h + 1) := by
        dsimp [d, q, B]
        push_cast
        rw [pow_succ, pow_succ]
        ring
      rw [hcharge, hN] at hsep
      simpa only [X, Y, ← finiteWord_succ_eq_rows] using hsep

/-- Uniform separation of the root half-period shift. -/
theorem finiteWord_root_deficit_of_half_children {m k T : β„•}
    (primes : Fin k β†’ Fin m β†’ β„•) (iβ‚€ : Fin m) (hm : 2 ≀ m) (hT : 0 < T)
    (hhalf : βˆ€ p (hp : p.length < k) (a b : Fin T) (t : β„€),
      Β¬ (wordPeriod primes iβ‚€ p : β„€) ∣ t β†’
      m ≀ 2 * (separatedChildren primes iβ‚€ p hp a b t).card)
    (x : State (wordPeriods primes)) :
    (((m * T) ^ k : β„•) : ℝ) / (4 : ℝ) ^ k ≀
      (deficit ((m * T) ^ k) (finiteWord primes iβ‚€ T k [] x)
        (finiteWord primes iβ‚€ T k [] (x + wordW primes iβ‚€ [])) : ℝ) := by
  have h := finiteWord_separation_of_half_children primes iβ‚€ hm hT hhalf
    k [] (by simp) x 1 (by simp)
  simpa using h

/-- Source finite-tree separation for the actual prime periods and words. -/
theorem finiteWord_separation {k : β„•} (hk : 2 ≀ k)
    (primes : Fin k β†’ Fin (20 * k) β†’ β„•) (iβ‚€ : Fin (20 * k))
    (hinj : Function.Injective
      (fun z : Fin k Γ— Fin (20 * k) => primes z.1 z.2))
    (hprime : βˆ€ q i, Nat.Prime (primes q i))
    (hlarge : βˆ€ q i, k ^ 4 ≀ primes q i)
    (h : β„•) (p : List (Fin (20 * k))) (hlen : p.length + h = k)
    (x : State (wordPeriods primes)) (t : β„€)
    (ht : Β¬ (wordPeriod primes iβ‚€ p : β„€) ∣ t) :
    (((20 * k * k ^ (20 * k)) ^ h : β„•) : ℝ) / (4 : ℝ) ^ h ≀
      (deficit ((20 * k * k ^ (20 * k)) ^ h)
        (finiteWord primes iβ‚€ (k ^ (20 * k)) h p x)
        (finiteWord primes iβ‚€ (k ^ (20 * k)) h p
          (x + t β€’ wordW primes iβ‚€ p)) : ℝ) := by
  apply finiteWord_separation_of_half_children primes iβ‚€ (by omega)
    (pow_pos (by omega) _) _ h p hlen x t ht
  intro p hp a b t ht
  exact finiteWord_half_children hk primes iβ‚€ p hp hinj hprime hlarge a b t ht

/-- Distinct large primes give the uniform root deficit for the
prescribed half-period shift. -/
theorem finiteWord_root_deficit {k : β„•} (hk : 2 ≀ k)
    (primes : Fin k β†’ Fin (20 * k) β†’ β„•) (iβ‚€ : Fin (20 * k))
    (hinj : Function.Injective
      (fun z : Fin k Γ— Fin (20 * k) => primes z.1 z.2))
    (hprime : βˆ€ q i, Nat.Prime (primes q i))
    (hlarge : βˆ€ q i, k ^ 4 ≀ primes q i)
    (x : State (wordPeriods primes)) :
    (((20 * k * k ^ (20 * k)) ^ k : β„•) : ℝ) / (4 : ℝ) ^ k ≀
      (deficit ((20 * k * k ^ (20 * k)) ^ k)
        (finiteWord primes iβ‚€ (k ^ (20 * k)) k [] x)
        (finiteWord primes iβ‚€ (k ^ (20 * k)) k []
          (x + wordW primes iβ‚€ [])) : ℝ) := by
  have h := finiteWord_separation hk primes iβ‚€ hinj hprime hlarge k []
    (by simp) x 1 (by simp)
  simpa using h

end TreeEdit.BinaryLower.FiniteTree

end

end OAI