File size: 12,230 Bytes
92416a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import OAI.Computability.WLIdentification.AcceptingMates

namespace OAI

namespace WLIdentification

namespace ComparisonSchemas
variable {r : ℕ} {P E : Type} (S : ComparisonSchemas r P E)

/-- Exactly the individual scalar-image hypotheses of special-twist
sufficiency. No simultaneous choice satisfying the wires is required. -/
structure SpecialImages (b : E → Bit) where
  values : (p : P) → (Fin r → Bool) → Set (Fin (S.dimension p) → Bit)
  nonempty : ∀ p a, (values p a).Nonempty
  equation : ∀ e (a : S.DomainAddress e),
    S.left e '' values (S.source e) (S.expressAddress e true a) =
    (fun v => b e + S.right e v) '' values (S.target e) (S.expressAddress e false a)

namespace SpecialImages
variable {S} {b : E → Bit} (I : S.SpecialImages b)

theorem chooseAt (A : Fin r → Bool) (p : P) (v : Fin (S.dimension p) → Bit)
    (hv : v ∈ I.values p A) :
    ∃ q : S.RealShift, (∀ p, q p ∈ I.values p A) ∧ q p = v := by
  classical
  choose q hq using fun p => I.nonempty p A
  refine ⟨Function.update q p v, ?_, by simp⟩
  intro p'
  by_cases hp : p' = p
  · subst p'; simpa using hv
  · simpa only [Function.update_of_ne hp] using hq p'

theorem scalar_mem (e : E) (a : S.DomainAddress e) (side : Bool) (q : S.RealShift)
    (hq : ∀ p, q p ∈ I.values p (S.expressAddress e side a)) :
    (if side then S.left e (q (S.source e)) else b e + S.right e (q (S.target e))) ∈
      S.left e '' I.values (S.source e) (S.expressAddress e true a) := by
  cases side with
  | false =>
    rw [I.equation]
    exact ⟨q (S.target e), hq _, rfl⟩
  | true => exact ⟨q (S.source e), hq _, rfl⟩

theorem scalar_preimage (e : E) (a : S.DomainAddress e) (side : Bool) (s : Bit)
    (hs : s ∈ S.left e '' I.values (S.source e) (S.expressAddress e true a)) :
    ∃ q : S.RealShift, (∀ p, q p ∈ I.values p (S.expressAddress e side a)) ∧
      (if side then S.left e (q (S.source e)) else b e + S.right e (q (S.target e))) = s := by
  cases side with
  | false =>
    rw [I.equation] at hs
    obtain ⟨v, hv, he⟩ := hs
    obtain ⟨q, hq, eq⟩ := I.chooseAt _ _ v hv
    refine ⟨q, hq, ?_⟩
    change b e + S.right e (q (S.target e)) = s
    rw [eq]
    exact he
  | true =>
    obtain ⟨v, hv, he⟩ := hs
    obtain ⟨q, hq, eq⟩ := I.chooseAt _ _ v hv
    refine ⟨q, hq, ?_⟩
    change S.left e (q (S.source e)) = s
    rw [eq]
    exact he

/-- The one constrained old wrapping component lifts even if it lies entirely
inside a wire and the new cut re-expresses it at the opposite real endpoint. -/
theorem wrapping_shift_extension {n : ℕ} (hr : 3 ≤ r) {U : Finset (S.layout n).Block}
    (hu : U.card ≤ r) (hw : (S.layout n).Wrapping (by omega) U)
    {cut cut' : E → Fin n} (hc : S.Avoids n U cut) (hc' : S.Avoids n U cut')
    {A A' : Fin r → Bool}
    (hA : (S.layout n).IsWrappingAddress U (S.align n cut) A)
    (hA' : (S.layout n).IsWrappingAddress U (S.align n cut') A')
    (q : S.RealShift) (hq : ∀ p, q p ∈ I.values p A) :
    ∃ q' : S.RealShift, (∀ p, q' p ∈ I.values p A') ∧
      ∀ h : (S.layout n).HName, Sum.inl h ∈ (S.layout n).names U →
        S.starShift n cut' b q' h.1 = S.starShift n cut b q h.1 := by
  classical
  have hpos : 0 < U.card := lt_of_lt_of_le (by omega) ((S.layout n).wrapping_card hr hw)
  obtain ⟨z, hz⟩ := Finset.card_pos.mp hpos
  let root := (S.layout n).blockRepresentative z
  have he (q' : S.RealShift) (l : S.Link n) (hl : l ∈ (S.layout n).usedLinks U) :
      (S.layout n).firstForm l (S.starShift n cut b q ((S.layout n).first l)) +
        (S.layout n).secondForm l (S.starShift n cut b q ((S.layout n).second l)) =
      (S.layout n).firstForm l (S.starShift n cut' b q' ((S.layout n).first l)) +
        (S.layout n).secondForm l (S.starShift n cut' b q' ((S.layout n).second l)) :=
    (S.starShift_link hc b q hl).trans (S.starShift_link hc' b q' hl).symm
  by_cases hre : ∃ (d : (S.layout n).Corner) (p : P),
      ((S.layout n).cornerGraph (by omega) U).Reachable root d ∧ d.1 = Sum.inl p
  · obtain ⟨d, p, hd, hdp⟩ := hre
    have hAA := S.wrapping_real_addresses hr hu hw hc hc' hA hA' hz hdp hd
    subst A'
    refine ⟨q, hq, ?_⟩
    intro h hh
    have hpath := hd.symm.trans ((S.layout n).wrapping_names_reachable hr hu hw hz hh).1
    have hbase : S.starShift n cut b q d.1 = S.starShift n cut' b q d.1 := by rw [hdp]; rfl
    exact (S.shift_agreement_reachable (by omega) _ _ (he q)
      (fun _ _ _ _ => rfl) hbase hpath).symm
  · have hn : S.NoRealFrom n (by omega) U root := by
      intro d hd p hp
      exact hre ⟨d, p, hd, hp⟩
    have htype : ∃ (e : E) (j : Fin (n + 1)), root.1 = Sum.inr (e, j) := by
      cases ht : root.1 with
      | inl p => exact (hn root (.refl root) p ht).elim
      | inr ej => exact ⟨ej.1, ej.2, rfl⟩
    obtain ⟨e, j, ht⟩ := htype
    let side := decide (S.onLeft n cut e j)
    let side' := decide (S.onLeft n cut' e j)
    have harm : S.arm n cut root.1 = some (e, side) := by rw [ht]; rfl
    have harm' : S.arm n cut' root.1 = some (e, side') := by rw [ht]; rfl
    obtain ⟨a, hAa, hAa'⟩ := S.wrapping_internal_addresses hr hu hw hc hc' hA hA' hz hn harm harm'
    let scalar : Bit := if side then S.left e (q (S.source e)) else b e + S.right e (q (S.target e))
    have hs := I.scalar_mem e a side q (by simpa only [← hAa] using hq)
    obtain ⟨q', hq', hscalar⟩ := I.scalar_preimage e a side' scalar hs
    refine ⟨q', by simpa only [← hAa'] using hq', ?_⟩
    intro h hh
    have hpath := ((S.layout n).wrapping_names_reachable hr hu hw hz hh).1
    have hbase : S.starShift n cut b q root.1 = S.starShift n cut' b q' root.1 := by
      rw [ht]
      funext k
      change (if S.onLeft n cut e j then _ else _) = (if S.onLeft n cut' e j then _ else _)
      simpa only [scalar, side, side', decide_eq_true_eq] using hscalar.symm
    exact (S.shift_agreement_reachable (by omega) _ _ (he q')
      (fun d hd p hp => (hn d hd p hp).elim) hbase hpath).symm

end SpecialImages
end ComparisonSchemas

namespace RingLayout
variable {r : ℕ} {T L : Type} (R : RingLayout r T L)

theorem translation_eq_of_shifts {U : Finset R.Block} (old new : R.Shift) (M : R.Potential)
    (he : ∀ h : R.HName, Sum.inl h ∈ R.names U → new h.1 = old h.1)
    {b : R.Block} (hb : b ∈ U) {c : R.Coordinate} (hc : c ∈ R.coordinates b) :
    R.translation new M c = R.translation old M c := by
  have hn := R.name_present hb (R.coordinate_name_mem hc)
  cases c with
  | inl h =>
    change (R.potentialHorizontal new M h.1) h.2 = (R.potentialHorizontal old M h.1) h.2
    unfold potentialHorizontal
    rw [he h.1 hn]
  | inr v => rfl

end RingLayout

namespace ComparisonSchemas.SpecialImages
variable {r : ℕ} {P E : Type} {S : ComparisonSchemas r P E} {b : E → Bit}
    (I : S.SpecialImages b)

/-- A stronger sufficient family using globally completed cut stars. Its
address restriction is imposed only by wrapping subcollections of size r. -/
def Admissible (n : ℕ) (hr : 2 ≤ r) (U : Finset (S.layout n).Block)
    (x : (S.layout n).Coordinate → Bit) : Prop :=
  U.card ≤ r + 1 ∧ ∃ cut : E → Fin n, S.Avoids n U cut ∧
    ∃ A : Fin r → Bool, S.GoodAddress n hr U cut A ∧
      ∃ q : S.RealShift, (∀ p, q p ∈ I.values p A) ∧
        ∃ M : (S.layout n).Potential, ∀ a ∈ U, ∀ c ∈ (S.layout n).coordinates a,
          x c = (S.layout n).translation (S.starShift n cut b q) M c

theorem admissible_nonempty {n : ℕ} (hr : 3 ≤ r) (hn : r + 1 < n)
    (U : Finset (S.layout n).Block) (hu : U.card ≤ r + 1) :
    ∃ x, I.Admissible n (by omega) U x := by
  classical
  obtain ⟨cut, hc⟩ := S.exists_cuts n U (lt_of_le_of_lt hu hn)
  obtain ⟨A, hA⟩ := S.goodAddress_exists n hr hu hc
  choose q hq using fun p => I.nonempty p A
  refine ⟨(S.layout n).translation (S.starShift n cut b q) (fun _ _ => 0),
    hu, cut, hc, A, hA, q, hq, (fun _ _ => 0), ?_⟩
  exact fun _ _ _ _ => rfl

theorem admissible_restrict {n : ℕ} {hr : 2 ≤ r} {U V : Finset (S.layout n).Block}
    {x : (S.layout n).Coordinate → Bit} (hVU : V ⊆ U) (hx : I.Admissible n hr U x) :
    I.Admissible n hr V x := by
  obtain ⟨hu, cut, hc, A, hA, q, hq, M, hM⟩ := hx
  exact ⟨(Finset.card_le_card hVU).trans hu, cut, S.avoids_mono hVU hc,
    A, S.goodAddress_mono hVU hA, q, hq, M, fun a ha => hM a (hVU ha)⟩

variable [Fintype P] [Fintype E]

theorem admissible_legal {n : ℕ} {hr : 2 ≤ r} {U : Finset (S.layout n).Block}
    {x : (S.layout n).Coordinate → Bit} (hx : I.Admissible n hr U x)
    {a : (S.layout n).Block} (ha : a ∈ U) :
    ((S.layout n).affine hr).Legal (S.specialTwist n b) a (((S.layout n).affine hr).restrict a x) := by
  obtain ⟨_, cut, hc, _, _, q, _, M, hM⟩ := hx
  have he : ((S.layout n).affine hr).restrict a x =
      ((S.layout n).affine hr).restrict a ((S.layout n).translation (S.starShift n cut b q) M) := by
    funext c
    exact hM a ha c.val c.property
  rw [he]
  exact S.translation_legal hc hr b q M ha

omit [Fintype P] [Fintype E] in
theorem admissible_extend {n : ℕ} (hr : 3 ≤ r) (hn : r + 1 < n)
    {U : Finset (S.layout n).Block} {x : (S.layout n).Coordinate → Bit}
    (hu : U.card < r + 1) (hx : I.Admissible n (by omega) U x) (z : (S.layout n).Block) :
    ∃ y, I.Admissible n (by omega) (insert z U) y ∧
      ∀ a ∈ U, ∀ c ∈ (S.layout n).coordinates a, y c = x c := by
  classical
  obtain ⟨_, cut, hc, A, hA, q, hq, M, hM⟩ := hx
  have hu' : U.card ≤ r := by omega
  have hnew : (insert z U).card ≤ r + 1 := by
    have := Finset.card_insert_le z U
    omega
  obtain ⟨cut', hc'⟩ := S.exists_cuts n (insert z U) (lt_of_le_of_lt hnew hn)
  obtain ⟨A', hA'⟩ := S.goodAddress_exists n hr hnew hc'
  have hsub : U ⊆ insert z U := Finset.subset_insert _ _
  have hc'U := S.avoids_mono hsub hc'
  have finish (q' : S.RealShift) (hq' : ∀ p, q' p ∈ I.values p A')
      (N : (S.layout n).Potential)
      (hN : ∀ a ∈ U, ∀ c ∈ (S.layout n).coordinates a,
        (S.layout n).translation (S.starShift n cut' b q') N c =
          (S.layout n).translation (S.starShift n cut b q) M c) :
      ∃ y, I.Admissible n (by omega) (insert z U) y ∧
        ∀ a ∈ U, ∀ c ∈ (S.layout n).coordinates a, y c = x c := by
    refine ⟨(S.layout n).translation (S.starShift n cut' b q') N,
      ⟨hnew, cut', hc', A', hA', q', hq', N, fun _ _ _ _ => rfl⟩, ?_⟩
    intro a ha c hc
    exact (hN a ha c hc).trans (hM a ha c hc).symm
  by_cases hw : (S.layout n).Wrapping (by omega) U
  · obtain ⟨q', hq', hshift⟩ := I.wrapping_shift_extension hr hu' hw hc hc'U
      (hA U (Finset.Subset.refl _) hu' hw) (hA' U hsub hu' hw) q hq
    apply finish q' hq' M
    intro a ha c hc
    exact (S.layout n).translation_eq_of_shifts _ _ M hshift ha hc
  · choose q' hq' using fun p => I.nonempty p A'
    obtain ⟨N, hN⟩ := (S.layout n).adjust_potential hr hw (S.starShift n cut b q)
      (S.starShift n cut' b q') M (fun l hl =>
        (S.starShift_link hc b q hl).trans (S.starShift_link hc'U b q' hl).symm)
    exact finish q' hq' N hN

/-- A proved producer of the exact-projection interface, not a hypothesis
asserting that local translations happen to extend. -/
noncomputable def offsetFamily {n : ℕ} (hr : 3 ≤ r) (hn : r + 1 < n) :
    ((S.layout n).affine (by omega)).OffsetFamily (S.specialTwist n b) (r + 1) where
  admissible := I.Admissible n (by omega)
  empty := I.admissible_nonempty hr hn ∅ (by simp)
  legal := fun hx _ ha => I.admissible_legal hx ha
  restrict := I.admissible_restrict
  extend := I.admissible_extend hr hn

include I in
/-- Equivalence of the special twist on the uncolored
leaf-coded graph; the private interior may be arbitrarily longer than K. -/
theorem equivalent_special {n : ℕ} (hr : 32 ≤ r) (hn : r + 1 < n) :
    Equivalent r (((S.layout n).affine (by omega)).graph 0)
      (((S.layout n).affine (by omega)).graph (S.specialTwist n b)) := by
  exact AffineBlocks.graph_equivalent_of_offsetFamily _ (S.layout n).owner
    (S.layout n).owner_covers (S.specialTwist n b) (offsetFamily I (by omega) hn)
    (by omega) (by omega)

end ComparisonSchemas.SpecialImages

end WLIdentification

end OAI