File size: 21,115 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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import OAI.Algorithms.SubexponentialSAT.LeanCompat

namespace OAI.Algorithms

/-!
# Cardinalities for the separated coset enumeration

The outer data are a vector on the complementary coordinates and one quotient
class on each of two coordinate blocks. The inner data are actual vectors in
those quotient classes. These theorems establish their exact cardinalities and
the algebraic identity in equation (4.9). They do not assert a bit-complexity
bound for enumerating a basis, a quotient, or the symbolic ring.
-/

namespace SubexponentialSAT.CosetCardinality

open Module

section Modules

variable {𝔽 V W : Type*} [Field 𝔽]
  [AddCommGroup V] [Module 𝔽 V] [AddCommGroup W] [Module 𝔽 W]

/-- Linear equivalences preserve the cardinality of the underlying set. -/
theorem card_of_linearEquiv (e : V ≃ₗ[𝔽] W) : Nat.card V = Nat.card W :=
  Nat.card_congr e.toEquiv

/-- A finite-dimensional space has a linear coordinate system with exactly
`finrank` coordinates. The basis choice here carries no algorithmic cost claim. -/
noncomputable def finiteCoordinateEquiv [Module.Finite 𝔽 V] :
    V ≃ₗ[𝔽] (Fin (finrank 𝔽 V) β†’ 𝔽) :=
  (Module.finBasis 𝔽 V).equivFun

/-- The cardinality formula for a finite-dimensional vector space. -/
theorem card_module [Module.Finite 𝔽 V] :
    Nat.card V = Nat.card 𝔽 ^ finrank 𝔽 V := by
  let b := Module.finBasis 𝔽 V
  rw [Nat.card_congr b.equivFun.toEquiv, Nat.card_fun]
  simp only [Nat.card_eq_fintype_card, Fintype.card_fin]

/-- The size of an inner subspace is the field size to its dimension. -/
theorem card_submodule [Module.Finite 𝔽 V] (K : Submodule 𝔽 V) :
    Nat.card K = Nat.card 𝔽 ^ finrank 𝔽 K :=
  card_module

/-- The number of cosets in a coordinate block. -/
theorem card_quotient [Module.Finite 𝔽 V] (K : Submodule 𝔽 V) :
    Nat.card (V β§Έ K) = Nat.card 𝔽 ^ (finrank 𝔽 V - finrank 𝔽 K) := by
  rw [card_module (𝔽 := 𝔽), Submodule.finrank_quotient]

/-- A coset is represented as the fiber of the actual quotient map. -/
def CosetFiber (K : Submodule 𝔽 V) (q : V β§Έ K) :=
  {x : V // (Submodule.Quotient.mk x : V β§Έ K) = q}

/-- Taking a quotient class together with a point of that class partitions the
ambient vector space exactly, without duplicates or omitted vectors. -/
def quotientFiberEquiv (K : Submodule 𝔽 V) :
    (Ξ£ q : V β§Έ K, CosetFiber K q) ≃ V :=
  Equiv.sigmaFiberEquiv (fun x : V => (Submodule.Quotient.mk x : V β§Έ K))

/-- Translating the subspace by any representative enumerates its coset
bijectively, even when the field elements are later represented by integers. -/
def cosetEquiv (K : Submodule 𝔽 V) (q : V β§Έ K) (r : V)
    (hr : (Submodule.Quotient.mk r : V β§Έ K) = q) : K ≃ CosetFiber K q where
  toFun k := ⟨r + k, by
    rw [Submodule.Quotient.mk_add, (Submodule.Quotient.mk_eq_zero K).2 k.property,
      add_zero, hr]⟩
  invFun x := ⟨x.val - r, (Submodule.Quotient.eq K).1 (x.property.trans hr.symm)⟩
  left_inv k := by
    apply Subtype.ext
    simp
  right_inv x := by
    apply Subtype.ext
    simp []

/-- Every quotient class has the same cardinality as its subspace. -/
theorem card_coset_eq (K : Submodule 𝔽 V) (q : V β§Έ K) :
    Nat.card (CosetFiber K q) = Nat.card K := by
  obtain ⟨r, hr⟩ := Submodule.Quotient.mk_surjective (p := K) q
  exact Nat.card_congr (cosetEquiv K q r hr).symm

/-- Every inner sum over a coset has exactly this many terms. -/
theorem card_coset [Module.Finite 𝔽 V] (K : Submodule 𝔽 V) (q : V β§Έ K) :
    Nat.card (CosetFiber K q) = Nat.card 𝔽 ^ finrank 𝔽 K := by
  rw [card_coset_eq, card_submodule]

/-- Fintype-facing version for finite sums indexed directly by subspace vectors. -/
theorem fintype_card_submodule [Fintype 𝔽] [Fintype V] (K : Submodule 𝔽 V)
    [Fintype K] : Fintype.card K = Fintype.card 𝔽 ^ finrank 𝔽 K := by
  simpa only [Nat.card_eq_fintype_card] using card_submodule K

end Modules

section OuterData

variable {𝔽 Vstar V0 V1 : Type*} [Field 𝔽]
  [AddCommGroup Vstar] [Module 𝔽 Vstar]
  [AddCommGroup V0] [Module 𝔽 V0] [AddCommGroup V1] [Module 𝔽 V1]

/-- The actual type of outer choices used in Section 4.5. -/
abbrev OuterData (K0 : Submodule 𝔽 V0) (K1 : Submodule 𝔽 V1) :=
  Vstar Γ— (V0 β§Έ K0) Γ— (V1 β§Έ K1)

/-- Every split assignment is uniquely an outer datum and a pair of vectors
in its two cosets. This is the full-domain partition behind the enumeration. -/
def outerFiberEquiv (K0 : Submodule 𝔽 V0) (K1 : Submodule 𝔽 V1) :
    (Vstar Γ— V0 Γ— V1) ≃
      Ξ£ o : OuterData (Vstar := Vstar) K0 K1,
        CosetFiber K0 o.2.1 Γ— CosetFiber K1 o.2.2 where
  toFun x := ⟨(x.1, Submodule.Quotient.mk x.2.1, Submodule.Quotient.mk x.2.2),
    ⟨x.2.1, rfl⟩, ⟨x.2.2, rfl⟩⟩
  invFun y := (y.1.1, y.2.1.val, y.2.2.val)
  left_inv _ := rfl
  right_inv y := by
    rcases y with ⟨⟨xs, q0, q1⟩, ⟨x0, h0⟩, ⟨x1, h1⟩⟩
    dsimp at h0 h1
    subst q0
    subst q1
    rfl

/-- Product cardinality gives the number of outer choices. -/
theorem card_outer [Module.Finite 𝔽 Vstar] [Module.Finite 𝔽 V0]
    [Module.Finite 𝔽 V1] (K0 : Submodule 𝔽 V0) (K1 : Submodule 𝔽 V1) :
    Nat.card (OuterData (Vstar := Vstar) K0 K1) = Nat.card 𝔽 ^
      (finrank 𝔽 Vstar + finrank 𝔽 V0 + finrank 𝔽 V1 -
        finrank 𝔽 K0 - finrank 𝔽 K1) := by
  have h0 := K0.finrank_quotient_add_finrank
  have h1 := K1.finrank_quotient_add_finrank
  simp only [OuterData, Nat.card_prod, card_quotient]
  rw [card_module (𝔽 := 𝔽) (V := Vstar)]
  rw [← pow_add, ← pow_add]
  congr 1
  omega

/-- The arithmetic identity behind equation (4.9). The dimension assumption
is essential when subtraction is natural-number subtraction. -/
theorem iteration_identity (p D d0 d1 : β„•) (h : d0 + d1 ≀ D) :
    p ^ (D - d0 - d1) * (p ^ d0 + p ^ d1) =
      p ^ (D - d1) + p ^ (D - d0) := by
  rw [Nat.mul_add, ← pow_add, ← pow_add]
  congr 1 <;> congr 1 <;> omega

/-- An integer-exponent version of the final inequality in (4.9).
The hypotheses express `d0,d1 β‰₯ D/4` without rounding ambiguity. -/
theorem iteration_bound (p D d0 d1 : β„•) (hp : 0 < p)
    (h : d0 + d1 ≀ D) (h0 : D ≀ 4 * d0) (h1 : D ≀ 4 * d1) :
    p ^ (D - d0 - d1) * (p ^ d0 + p ^ d1) ≀ 2 * p ^ (3 * D / 4) := by
  rw [iteration_identity p D d0 d1 h, two_mul]
  exact Nat.add_le_add
    (Nat.pow_le_pow_right hp (by omega : D - d1 ≀ 3 * D / 4))
    (Nat.pow_le_pow_right hp (by omega : D - d0 ≀ 3 * D / 4))

/-- Counting each term in each of the two inner sums for every outer datum.
This is an iteration count, not a Turing-machine runtime theorem. -/
theorem card_outer_times_inner [Module.Finite 𝔽 Vstar] [Module.Finite 𝔽 V0]
    [Module.Finite 𝔽 V1] (K0 : Submodule 𝔽 V0) (K1 : Submodule 𝔽 V1) :
    Nat.card (OuterData (Vstar := Vstar) K0 K1) * (Nat.card K0 + Nat.card K1) =
      Nat.card 𝔽 ^ (finrank 𝔽 Vstar + finrank 𝔽 V0 + finrank 𝔽 V1 - finrank 𝔽 K1) +
      Nat.card 𝔽 ^ (finrank 𝔽 Vstar + finrank 𝔽 V0 + finrank 𝔽 V1 - finrank 𝔽 K0) := by
  rw [card_outer, card_submodule, card_submodule]
  apply iteration_identity
  have h0 := K0.finrank_quotient_add_finrank
  have h1 := K1.finrank_quotient_add_finrank
  omega

end OuterData

section Coordinates

variable {𝔽 ΞΉ : Type*} [Field 𝔽] [Fintype ΞΉ] [DecidableEq ΞΉ]

/-- The disjoint coordinate supports and their complement split every ambient
assignment uniquely. This map is the actual restriction of coordinates. -/
def coordinateSplitEquiv (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1) :
    (ΞΉ β†’ 𝔽) ≃ₗ[𝔽] ((β†₯((S0 βˆͺ S1)ᢜ) β†’ 𝔽) Γ— (S0 β†’ 𝔽) Γ— (S1 β†’ 𝔽)) where
  toFun x := (fun i => x i.val, fun i => x i.val, fun i => x i.val)
  invFun y i := if h0 : i ∈ S0 then y.2.1 ⟨i, h0⟩
    else if h1 : i ∈ S1 then y.2.2 ⟨i, h1⟩
    else y.1 ⟨i, by simp only [Finset.mem_compl, Finset.mem_union, not_or]; exact ⟨h0, h1⟩⟩
  left_inv x := by
    funext i
    dsimp
    split
    Β· rfl
    Β· split <;> rfl
  right_inv y := by
    apply Prod.ext
    Β· funext i
      have hi : i.val βˆ‰ S0 ∧ i.val βˆ‰ S1 := by
        simpa only [Finset.mem_compl, Finset.mem_union, not_or] using i.property
      dsimp
      simp only [dite_eq_right hi.1, dite_eq_right hi.2]
    Β· apply Prod.ext
      Β· funext i
        dsimp
        simp only [dite_eq_left i.property]
      Β· funext i
        have hi0 : i.val βˆ‰ S0 := fun hi => Finset.disjoint_left.mp h hi i.property
        dsimp
        simp only [dite_eq_right hi0, dite_eq_left i.property]
  map_add' _ _ := rfl
  map_smul' _ _ := rfl

/-- Three disjoint coordinate blocks account for the full ambient dimension. -/
theorem coordinate_card_partition (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1) :
    Fintype.card β†₯((S0 βˆͺ S1)ᢜ) + Fintype.card β†₯S0 + Fintype.card β†₯S1 =
      Fintype.card ΞΉ := by
  simpa only [Fintype.card_coe, Finset.card_union_of_disjoint h, Nat.add_assoc]
    using Finset.card_compl_add_card (S0 βˆͺ S1)

/-- Restricting each subspace to its own coordinate support is represented by
the local domains `S0 β†’ 𝔽` and `S1 β†’ 𝔽`. -/
abbrev CoordinateOuterData (S0 S1 : Finset ΞΉ)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽)) :=
  OuterData (Vstar := β†₯((S0 βˆͺ S1)ᢜ) β†’ 𝔽) K0 K1

/-- A complete ambient assignment is an outer datum and a point in each of
its two cosets, through explicit coordinate restriction and quotient fibers. -/
def coordinateOuterFiberEquiv (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽)) :
    (ΞΉ β†’ 𝔽) ≃ Ξ£ o : CoordinateOuterData S0 S1 K0 K1,
      CosetFiber K0 o.2.1 Γ— CosetFiber K1 o.2.2 :=
  (coordinateSplitEquiv S0 S1 h).toEquiv.trans (outerFiberEquiv K0 K1)

/-- Reconstruct an ambient assignment from its outer data and two coset points. -/
def coordinateReconstruct (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽))
    (o : CoordinateOuterData S0 S1 K0 K1)
    (x0 : CosetFiber K0 o.2.1) (x1 : CosetFiber K1 o.2.2) : ΞΉ β†’ 𝔽 :=
  (coordinateOuterFiberEquiv S0 S1 h K0 K1).symm ⟨o, x0, x1⟩

/-- Reconstructing an assignment gives exactly its three supplied coordinate blocks. -/
theorem coordinateReconstruct_components (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽))
    (o : CoordinateOuterData S0 S1 K0 K1)
    (x0 : CosetFiber K0 o.2.1) (x1 : CosetFiber K1 o.2.2) :
    (fun i : β†₯((S0 βˆͺ S1)ᢜ) => coordinateReconstruct S0 S1 h K0 K1 o x0 x1 i.val) = o.1 ∧
    (fun i : S0 => coordinateReconstruct S0 S1 h K0 K1 o x0 x1 i.val) = x0.val ∧
    (fun i : S1 => coordinateReconstruct S0 S1 h K0 K1 o x0 x1 i.val) = x1.val := by
  have hs := (coordinateSplitEquiv (𝔽 := 𝔽) S0 S1 h).apply_symm_apply
    (o.1, x0.val, x1.val)
  exact ⟨congrArg Prod.fst hs, congrArg (fun z => z.2.1) hs,
    congrArg (fun z => z.2.2) hs⟩

/-- The exact outer count for disjoint coordinate supports, with `D` given by
the cardinality of the original coordinate type. -/
theorem card_coordinate_outer (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽)) :
    Nat.card (CoordinateOuterData S0 S1 K0 K1) =
      Nat.card 𝔽 ^ (Fintype.card ΞΉ - finrank 𝔽 K0 - finrank 𝔽 K1) := by
  rw [card_outer]
  simp only [Module.finrank_fintype_fun_eq_card]
  rw [coordinate_card_partition S0 S1 h]

/-- Over a finite field the outer data themselves form a finite type, with
the expected power of the actual field cardinality. -/
theorem fintype_card_coordinate_outer [Fintype 𝔽] (S0 S1 : Finset ΞΉ)
    (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽)) :
    Fintype.card (CoordinateOuterData S0 S1 K0 K1) =
      Fintype.card 𝔽 ^ (Fintype.card ΞΉ - finrank 𝔽 K0 - finrank 𝔽 K1) := by
  simpa only [Nat.card_eq_fintype_card] using card_coordinate_outer S0 S1 h K0 K1

/-- Disjoint supports bound the sum of the two inner dimensions by the
ambient number of coordinates. -/
theorem coordinate_dimensions_le (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽)) :
    finrank 𝔽 K0 + finrank 𝔽 K1 ≀ Fintype.card ΞΉ := by
  have h0 := K0.finrank_quotient_add_finrank
  have h1 := K1.finrank_quotient_add_finrank
  have hp := coordinate_card_partition S0 S1 h
  simp only [Module.finrank_fintype_fun_eq_card] at h0 h1
  omega

/-- Equation (4.9), before the real-valued `3D/4` estimate: the outer count
times the two inner sizes is the sum of these two powers. -/
theorem coordinate_iteration_count (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽)) :
    Nat.card (CoordinateOuterData S0 S1 K0 K1) * (Nat.card K0 + Nat.card K1) =
      Nat.card 𝔽 ^ (Fintype.card ΞΉ - finrank 𝔽 K1) +
      Nat.card 𝔽 ^ (Fintype.card ΞΉ - finrank 𝔽 K0) := by
  rw [card_outer_times_inner]
  simp only [Module.finrank_fintype_fun_eq_card]
  rw [coordinate_card_partition S0 S1 h]

/-- The iteration formula counts a concrete type: an outer choice, followed
by either an index for the first inner sum or an index for the second. -/
theorem card_coordinate_iteration_type [Fintype 𝔽] (S0 S1 : Finset ΞΉ)
    (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽)) :
    Nat.card (CoordinateOuterData S0 S1 K0 K1 Γ— (K0 βŠ• K1)) =
      Fintype.card 𝔽 ^ (Fintype.card ΞΉ - finrank 𝔽 K1) +
      Fintype.card 𝔽 ^ (Fintype.card ΞΉ - finrank 𝔽 K0) := by
  rw [Nat.card_prod, Nat.card_sum]
  simpa only [Nat.card_eq_fintype_card] using
    coordinate_iteration_count S0 S1 h K0 K1

/-- The complete integer-cardinality bound in (4.9). The exponent is the
floor of `3D/4`, so this is slightly sharper than its real-exponent version. -/
theorem coordinate_iteration_bound [Fintype 𝔽] (S0 S1 : Finset ΞΉ)
    (h : Disjoint S0 S1)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽))
    (h0 : Fintype.card ΞΉ ≀ 4 * finrank 𝔽 K0)
    (h1 : Fintype.card ΞΉ ≀ 4 * finrank 𝔽 K1) :
    Nat.card (CoordinateOuterData S0 S1 K0 K1) * (Nat.card K0 + Nat.card K1) ≀
      2 * Fintype.card 𝔽 ^ (3 * Fintype.card ΞΉ / 4) := by
  rw [card_coordinate_outer S0 S1 h, card_submodule, card_submodule]
  simp only [Nat.card_eq_fintype_card]
  exact iteration_bound _ _ _ _ Fintype.card_pos
    (coordinate_dimensions_le S0 S1 h K0 K1) h0 h1

omit [DecidableEq ΞΉ] in
/-- The sizes of the actual two cosets used for any outer choice. -/
theorem coordinate_inner_sizes (S0 S1 : Finset ΞΉ)
    (K0 : Submodule 𝔽 (S0 β†’ 𝔽)) (K1 : Submodule 𝔽 (S1 β†’ 𝔽))
    (q0 : (S0 β†’ 𝔽) β§Έ K0) (q1 : (S1 β†’ 𝔽) β§Έ K1) :
    Nat.card (CosetFiber K0 q0) = Nat.card 𝔽 ^ finrank 𝔽 K0 ∧
      Nat.card (CosetFiber K1 q1) = Nat.card 𝔽 ^ finrank 𝔽 K1 :=
  ⟨card_coset K0 q0, card_coset K1 q1⟩

/-- Restriction of an ambient subspace to a selected set of coordinates. -/
def coordinateRestriction (S : Finset ΞΉ) (K : Submodule 𝔽 (ΞΉ β†’ 𝔽)) :
    K β†’β‚—[𝔽] (S β†’ 𝔽) where
  toFun x i := x.val i.val
  map_add' _ _ := rfl
  map_smul' _ _ := rfl

omit [Fintype ΞΉ] in
/-- Restriction loses no information for a subspace supported on `S`. -/
theorem coordinateRestriction_injective (S : Finset ΞΉ) (K : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (hK : βˆ€ x ∈ K, βˆ€ i, i βˆ‰ S β†’ x i = 0) :
    Function.Injective (coordinateRestriction S K) := by
  intro x y hxy
  apply Subtype.ext
  funext i
  by_cases hi : i ∈ S
  · exact congrFun hxy ⟨i, hi⟩
  Β· rw [hK x.val x.property i hi, hK y.val y.property i hi]

/-- The same supported subspace, viewed as a subspace of its local coordinates. -/
abbrev restrictedSubspace (S : Finset ΞΉ) (K : Submodule 𝔽 (ΞΉ β†’ 𝔽)) :
    Submodule 𝔽 (S β†’ 𝔽) :=
  LinearMap.range (coordinateRestriction S K)

/-- Ambient and local presentations of a supported subspace are linearly equivalent. -/
noncomputable def restrictionEquiv (S : Finset ΞΉ) (K : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (hK : βˆ€ x ∈ K, βˆ€ i, i βˆ‰ S β†’ x i = 0) :
    K ≃ₗ[𝔽] restrictedSubspace S K :=
  LinearEquiv.ofInjective (coordinateRestriction S K)
    (coordinateRestriction_injective S K hK)

omit [Fintype ΞΉ] in
theorem finrank_restrictedSubspace (S : Finset ΞΉ) (K : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (hK : βˆ€ x ∈ K, βˆ€ i, i βˆ‰ S β†’ x i = 0) :
    finrank 𝔽 (restrictedSubspace S K) = finrank 𝔽 K :=
  (restrictionEquiv S K hK).finrank_eq.symm

/-- The outer-count theorem with precisely the ambient-subspace support
hypotheses of the interpolation layout. -/
theorem card_supported_outer (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 K1 : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (h0 : βˆ€ x ∈ K0, βˆ€ i, i βˆ‰ S0 β†’ x i = 0)
    (h1 : βˆ€ x ∈ K1, βˆ€ i, i βˆ‰ S1 β†’ x i = 0) :
    Nat.card (CoordinateOuterData S0 S1
      (restrictedSubspace S0 K0) (restrictedSubspace S1 K1)) =
      Nat.card 𝔽 ^ (Fintype.card ΞΉ - finrank 𝔽 K0 - finrank 𝔽 K1) := by
  rw [card_coordinate_outer S0 S1 h,
    finrank_restrictedSubspace S0 K0 h0, finrank_restrictedSubspace S1 K1 h1]

omit [Fintype ΞΉ] in
/-- A supported ambient vector whose restriction lies in the restricted
subspace already lies in the original ambient subspace. -/
theorem mem_of_restriction_mem (S : Finset ΞΉ) (K : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (hK : βˆ€ x ∈ K, βˆ€ i, i βˆ‰ S β†’ x i = 0) (x : ΞΉ β†’ 𝔽)
    (hx : βˆ€ i, i βˆ‰ S β†’ x i = 0)
    (hr : (fun i : S => x i.val) ∈ restrictedSubspace S K) : x ∈ K := by
  obtain ⟨r, hr⟩ := hr
  have heq : x = r.val := by
    funext i
    by_cases hi : i ∈ S
    · exact (congrFun hr ⟨i, hi⟩).symm
    Β· rw [hx i hi, hK r.val r.property i hi]
  exact heq.symm β–Έ r.property

omit [Fintype ΞΉ] in
/-- Equal restrictions modulo the local subspace and equality outside its
support imply that the ambient difference belongs to the original subspace. -/
theorem sub_mem_of_local_quotient_eq (S : Finset ΞΉ) (K : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (hK : βˆ€ x ∈ K, βˆ€ i, i βˆ‰ S β†’ x i = 0) (x y : ΞΉ β†’ 𝔽)
    (houtside : βˆ€ i, i βˆ‰ S β†’ x i = y i)
    (hq : (Submodule.Quotient.mk (fun i : S => x i.val) :
      (S β†’ 𝔽) β§Έ restrictedSubspace S K) =
      Submodule.Quotient.mk (fun i : S => y i.val)) : x - y ∈ K := by
  apply mem_of_restriction_mem S K hK (x - y)
  Β· intro i hi
    exact sub_eq_zero.mpr (houtside i hi)
  Β· exact (Submodule.Quotient.eq (restrictedSubspace S K)).mp hq

/-- With outer data and the right point fixed, varying the left point within
its local coset changes the ambient assignment by a vector of the global `K0`. -/
theorem coordinateReconstruct_left_sub_mem (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 K1 : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (hK0 : βˆ€ x ∈ K0, βˆ€ i, i βˆ‰ S0 β†’ x i = 0)
    (o : CoordinateOuterData S0 S1 (restrictedSubspace S0 K0) (restrictedSubspace S1 K1))
    (x0 y0 : CosetFiber (restrictedSubspace S0 K0) o.2.1)
    (x1 : CosetFiber (restrictedSubspace S1 K1) o.2.2) :
    coordinateReconstruct S0 S1 h _ _ o x0 x1 -
      coordinateReconstruct S0 S1 h _ _ o y0 x1 ∈ K0 := by
  have hx := coordinateReconstruct_components S0 S1 h _ _ o x0 x1
  have hy := coordinateReconstruct_components S0 S1 h _ _ o y0 x1
  apply sub_mem_of_local_quotient_eq S0 K0 hK0
  Β· intro i hi0
    by_cases hi1 : i ∈ S1
    · exact congrFun (hx.2.2.trans hy.2.2.symm) ⟨i, hi1⟩
    Β· exact congrFun (hx.1.trans hy.1.symm)
        ⟨i, by simp only [Finset.mem_compl, Finset.mem_union, not_or]; exact ⟨hi0, hi1⟩⟩
  Β· rw [hx.2.1, hy.2.1]
    exact x0.property.trans y0.property.symm

/-- The symmetric global-subspace difference statement for the right point. -/
theorem coordinateReconstruct_right_sub_mem (S0 S1 : Finset ΞΉ) (h : Disjoint S0 S1)
    (K0 K1 : Submodule 𝔽 (ΞΉ β†’ 𝔽))
    (hK1 : βˆ€ x ∈ K1, βˆ€ i, i βˆ‰ S1 β†’ x i = 0)
    (o : CoordinateOuterData S0 S1 (restrictedSubspace S0 K0) (restrictedSubspace S1 K1))
    (x0 : CosetFiber (restrictedSubspace S0 K0) o.2.1)
    (x1 y1 : CosetFiber (restrictedSubspace S1 K1) o.2.2) :
    coordinateReconstruct S0 S1 h _ _ o x0 x1 -
      coordinateReconstruct S0 S1 h _ _ o x0 y1 ∈ K1 := by
  have hx := coordinateReconstruct_components S0 S1 h _ _ o x0 x1
  have hy := coordinateReconstruct_components S0 S1 h _ _ o x0 y1
  apply sub_mem_of_local_quotient_eq S1 K1 hK1
  Β· intro i hi1
    by_cases hi0 : i ∈ S0
    · exact congrFun (hx.2.1.trans hy.2.1.symm) ⟨i, hi0⟩
    Β· exact congrFun (hx.1.trans hy.1.symm)
        ⟨i, by simp only [Finset.mem_compl, Finset.mem_union, not_or]; exact ⟨hi0, hi1⟩⟩
  Β· rw [hx.2.2, hy.2.2]
    exact x1.property.trans y1.property.symm

end Coordinates

end SubexponentialSAT.CosetCardinality

end OAI.Algorithms