Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
6094ec9
feat(exactTriangle): relate lopsided queries and matrix products
edemaine Oct 28, 2026
dec963a
feat(exactTriangle): prove modular counts and the selected-prime bound
edemaine Oct 28, 2026
0d8da3e
doc(threeSum): cite the lopsided triangle paper and clarify adaptatio…
edemaine Oct 28, 2026
8d80ecc
doc(bibliography): sort the new paper entry
edemaine Oct 28, 2026
fd69be7
fix(exactTriangle): repair the prime-window header and hashing docume…
edemaine Oct 28, 2026
ce646c7
feat(exactTriangle): split modular queries and recover witnesses
edemaine Oct 28, 2026
2cae26c
doc(threeSum): record finite splitting and recovery milestone
edemaine Oct 28, 2026
dc4206a
refactor(exactTriangle): reuse the natural residue bound and clarify …
edemaine Oct 28, 2026
2434f47
feat(matrix): prove the tensor recursion and pruned evaluation core
edemaine Oct 28, 2026
62dc601
doc(matrix): clarify the overlapping contributing leaf
edemaine Oct 28, 2026
4f3226c
doc(matrix): make tensor and pruning explanations standalone
edemaine Oct 28, 2026
19ee942
feat(wordram): count Chan–He collisions with native histograms
edemaine Oct 28, 2026
a712205
fix(wordram): preserve collision-counting parameters explicitly
edemaine Oct 28, 2026
844522a
feat(matrix): prove finite thin-product correctness and sparse bounds
edemaine Oct 28, 2026
5cbb93d
feat(wordram): compute Chan–He parameters from native input
edemaine Oct 28, 2026
b4936ce
doc(matrix): explain finite thin-product guarantees in the Lean API
edemaine Oct 28, 2026
0505439
fix(wordram): repair parameter proof hygiene and ceiling-log docs
edemaine Oct 28, 2026
ad3e097
feat(wordram): implement shared tensor encodings
edemaine Oct 28, 2026
3b9234d
test(wordram): connect encoder witnesses to charged runs
edemaine Oct 28, 2026
46e9e72
feat(wordram): checkpoint native pruned-query controller proofs
edemaine Oct 28, 2026
68bbe40
refactor(schonhage): reuse binomial bounds and sharpen signed tests
edemaine Oct 28, 2026
cb261f6
feat(WordRAM): prepare and encode every shared matrix band
edemaine Oct 28, 2026
87ff44c
feat(wordram): checkpoint native pruned accumulation and frame transi…
edemaine Oct 28, 2026
b3b8047
feat(wordram): checkpoint actual pruned-query root-frame stores
edemaine Oct 28, 2026
6603615
fix(nat): reuse existing tuple digit identity in band preparation
edemaine Oct 28, 2026
79c9407
feat(wordram): checkpoint complete native pruned-controller phases
edemaine Oct 28, 2026
99b8a1b
doc(matrix): replace copied source prose with API descriptions
edemaine Oct 28, 2026
12abeee
refactor(finset): use order-embedding names in OrderGlue
edemaine Oct 28, 2026
829613f
feat(WordRAM): prove all-depth pruned controller execution
edemaine Oct 28, 2026
a93c021
style(WordRAM): normalize native proof file modes
edemaine Oct 28, 2026
0c2e0eb
feat(wordram): complete initialized sparse pruned-query execution
edemaine Oct 28, 2026
60bec64
chore(wordram): combine band and query evaluator prerequisites
edemaine Oct 29, 2026
06b3563
feat(wordram): checkpoint computed wanted-query routing
edemaine Oct 29, 2026
7772a34
feat(wordram): checkpoint wanted count-pass proofs
edemaine Oct 29, 2026
702c14b
doc(finset): restore ordered-gluing source credit
SamuelSchlesinger Oct 29, 2026
ce77926
fix(wordram): address pruned-query review findings
edemaine Oct 29, 2026
48a0fa3
chore(exactTriangle): merge current main for sibling integration
codex Oct 29, 2026
3fb98bd
chore(exactTriangle): join reviewed query splitting and counting layers
codex Oct 29, 2026
0b5cfe4
chore(wordram): retain reviewed pruned-query parent repair
edemaine Oct 29, 2026
d1bc583
chore(exactTriangle): reconcile modular-hashing integration documenta…
SamuelSchlesinger Oct 29, 2026
c0b0511
chore(exactTriangle): carry hashing integration through query splitting
SamuelSchlesinger Oct 29, 2026
a76a7d3
chore(exactTriangle): carry documentation integration through native …
SamuelSchlesinger Oct 29, 2026
4f6de79
fix(imports): deduplicate aggregate after counting integration
SamuelSchlesinger Oct 29, 2026
02f1b49
fix(imports): deduplicate aggregate after query-splitting integration
SamuelSchlesinger Oct 29, 2026
60dfe9a
Merge commit '02f1b495322d8cfee81969186795670e3574defa' into coordina…
SamuelSchlesinger Oct 29, 2026
6f48d5c
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
SamuelSchlesinger Oct 29, 2026
b17ece3
Merge commit '4f6de797203eb5dac02b2cadd9e8fa33e7427d57' into coordina…
SamuelSchlesinger Oct 29, 2026
e031b72
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
SamuelSchlesinger Oct 29, 2026
b79ae8e
fix(imports): regenerate aggregate after Chan-He parameter integration
SamuelSchlesinger Oct 29, 2026
3187bca
chore(wordram): retain reviewed sibling source-credit fix
edemaine Oct 29, 2026
a6e4005
feat(wordram): route and group wanted thin-product queries
edemaine Oct 29, 2026
249f960
Merge commit '6f48d5c0efdfea1984c4accf368de9eaa9716b95' into coordina…
SamuelSchlesinger Oct 29, 2026
08a0415
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
SamuelSchlesinger Oct 29, 2026
b0fa45b
Merge commit '08a0415413677534785113b7cf643b1ba9a6ee78' into coordina…
SamuelSchlesinger Oct 29, 2026
bd9bd2b
fix(imports): regenerate aggregate after shared-encoder integration
SamuelSchlesinger Oct 29, 2026
ab3e96c
chore(integration): reconcile splitting layer with landed hashing parent
SamuelSchlesinger Oct 29, 2026
9c8b9fc
perf(wordram): reduce native parameter proof heartbeat budget
SamuelSchlesinger Oct 29, 2026
0c9b346
Merge remote-tracking branch 'github/main' into coordinator-heartbeat…
SamuelSchlesinger Oct 29, 2026
da6a301
chore(integration): adopt splitting layer after its parent landed
SamuelSchlesinger Oct 29, 2026
452924e
chore(wordram): scope measured parameter proof budget to reduction task
SamuelSchlesinger Oct 29, 2026
6aaf569
Merge commit 'da6a301aca1e0c03e6953b3329474b2236f0fac8' into coordina…
SamuelSchlesinger Oct 29, 2026
5f6aad5
chore(integration): refresh tensor recursion supplier after hashing l…
SamuelSchlesinger Oct 29, 2026
d91296f
perf(schonhage): focus cell arithmetic and use the default heartbeat …
SamuelSchlesinger Oct 29, 2026
d8f4162
fix(doc): restore unrelated upstream coordination records
SamuelSchlesinger Oct 29, 2026
a63864f
chore(three-sum): merge corrected supplier preserving scope and sourc…
SamuelSchlesinger Oct 29, 2026
781297c
chore(three-sum): merge refreshed thin-product supplier preserving en…
SamuelSchlesinger Oct 29, 2026
1f2cfc4
Merge commit '781297cef838ef99c33e4036195e58b06ca46779' into coordina…
SamuelSchlesinger Oct 29, 2026
b4aa7b5
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
SamuelSchlesinger Oct 29, 2026
780531b
fix(imports): regenerate band-preparation aggregate from merged inven…
SamuelSchlesinger Oct 29, 2026
04349d4
Merge commit '780531b426051080bb274a0511f49142af03557c' into coordina…
SamuelSchlesinger Oct 29, 2026
5bf1f0e
doc(order-glue): preserve reviewed source credit through supplier merge
SamuelSchlesinger Oct 29, 2026
ec46a4f
chore(schonhage): integrate reviewed query and band suppliers
SamuelSchlesinger Oct 29, 2026
a9d3fb9
chore(schonhage): integrate wanted routing with refreshed query supplier
SamuelSchlesinger Oct 29, 2026
91f485e
chore(schonhage): adopt actual reviewed naming-refactor supplier
SamuelSchlesinger Oct 29, 2026
a677276
Merge remote-tracking branch 'origin/main' into coordinator/refresh-1…
SamuelSchlesinger Oct 29, 2026
8a81617
Merge remote-tracking branch 'github/main' into coordinator-refresh-1…
SamuelSchlesinger Oct 29, 2026
9e9cb10
Merge commit 'a67727699b41ff9fa7d7227964d67c26699ab7f6' into coordina…
SamuelSchlesinger Oct 29, 2026
c3e1bcd
doc(order-glue): restore paper citation and finite scope
SamuelSchlesinger Oct 29, 2026
606fd61
Merge commit 'c3e1bcd3c8d9bb1dc4819d1b0a994bf52119731b' into coordina…
SamuelSchlesinger Oct 29, 2026
59c6f80
feat(wordram): checkpoint native queried-product construction (#1581)
edemaine Oct 29, 2026
9d33c95
Merge commit '606fd614454016f738d69d2cd768cb4d9a9ad795' into coordina…
SamuelSchlesinger Oct 29, 2026
936457e
Merge commit '9d33c950c695a353b20fe43fd7524f25663a4bce' into coordina…
SamuelSchlesinger Oct 29, 2026
4b2d75c
Merge remote-tracking branch 'github/main' into coordinator-queue-146…
SamuelSchlesinger Oct 29, 2026
ea38fc5
Merge remote-tracking branch 'origin/main' into coordinator/refresh-1…
SamuelSchlesinger Oct 29, 2026
6a86e25
fix(imports): regenerate thin-product aggregate after main integration
SamuelSchlesinger Oct 29, 2026
6dbd0cc
Merge commit '6a86e258db83b7724f5bd93c43c0cbc4221a992f' into coordina…
SamuelSchlesinger Oct 29, 2026
c94a52f
Merge commit '4b2d75ce50dbca1101868ed3726170770d0a3e77' into coordina…
SamuelSchlesinger Oct 29, 2026
d072322
Merge remote-tracking branch 'origin/main' into coordinator/repair-15…
SamuelSchlesinger Oct 29, 2026
61e7fe7
doc(wordram): separate shared-encoder integration records
SamuelSchlesinger Oct 29, 2026
e21cbd0
chore(integration): preserve local band-refresh preparation
SamuelSchlesinger Oct 29, 2026
d2e8386
Merge commit '38f32f97e76ad36666b99d1f0d39a64fc0ef3306' into coordina…
SamuelSchlesinger Oct 29, 2026
f55b418
Merge commit 'd2e8386e3352241f97fc1c3faa3da53c1fbb1f68' into coordina…
SamuelSchlesinger Oct 29, 2026
8f25b31
Merge commit 'f04ad02616791b3fa37ff236ac27b0a8690ca985' into coordina…
SamuelSchlesinger Oct 29, 2026
debd649
doc(matrix): keep progress links out of shared reference append block
SamuelSchlesinger Oct 29, 2026
af20863
feat(wordram): checkpoint complete queried-product source before supp…
edemaine Oct 29, 2026
cf25502
chore(wordram): merge actual reviewed queried-product supplier
edemaine Oct 29, 2026
ff31104
feat(wordram): execute queried thin-matrix products (#1581)
edemaine Oct 29, 2026
9a57e13
style(Schonhage): remove trailing space in queried products
edemaine Oct 29, 2026
37306ef
doc(Schonhage): retain band catalogue encoding contract
edemaine Oct 29, 2026
b71ae0e
Merge commit 'cf63e382d02ba396b4f8d460958d70b15735f23e' into coordina…
SamuelSchlesinger Oct 29, 2026
8527c1f
Merge commit 'cf63e382d02ba396b4f8d460958d70b15735f23e' into coordina…
SamuelSchlesinger Oct 29, 2026
82f86fe
Merge commit '8527c1f4d25246fee901303e7c0f1310d30306c0' into coordina…
SamuelSchlesinger Oct 29, 2026
d429833
Merge commit '82f86fec9b93d546f96542987255aa9f16377b3b' into coordina…
SamuelSchlesinger Oct 29, 2026
f43c26e
Merge commit '82f86fec9b93d546f96542987255aa9f16377b3b' into coordina…
SamuelSchlesinger Oct 29, 2026
168a8be
Merge commit 'f43c26edef5bc586602e0678be9f8a59759bd5f2' into coordina…
SamuelSchlesinger Oct 29, 2026
7d82da6
Merge commit 'd429833391f88fe96223bef8124be7e6b21a117f' into coordina…
SamuelSchlesinger Oct 29, 2026
70898da
fix(imports): regenerate wanted-routing aggregate from actual inventory
SamuelSchlesinger Oct 29, 2026
a8cb7c9
chore(schonhage): refresh queried products onto actual wanted parent
SamuelSchlesinger Oct 29, 2026
0cba851
Merge commit '21a3641bd8d436fdb3138f0a74528913417c313e' into coordina…
SamuelSchlesinger Oct 29, 2026
410ca93
chore(schonhage): adopt actual refreshed band supplier for carrier
SamuelSchlesinger Oct 29, 2026
7da96e6
chore(schonhage): integrate matrix carrier with current landed main
SamuelSchlesinger Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions Complexity.lean

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions Complexity/Algorithms/MatrixMultiplication/Schonhage/BandBounds.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/-
Copyright (c) 2026 Erik Demaine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Erik Demaine
-/

module
-- upstream: candidate

public import Complexity.Algorithms.MatrixMultiplication.Schonhage.Layout
import Mathlib.Data.Nat.Choose.Bounds
import Complexity.Algorithms.MatrixMultiplication.Schonhage.Tiling

/-!
# Bounds for guarded band addressing

## Main results

* `bandSize_le_seven_pow`: a complete band fits within the tensor input dimension.
* `band_position_bounds`: all padded row/column arithmetic stays below `N+7^L` before
the native guard. Row-major matrix addresses are computed only after that guard.
-/

@[expose] public section

namespace Cslib.Algorithms.MatrixMultiplication.Schonhage

private theorem mul_add_lt_mul {a b c d : ℕ} (ha : a < b) (hc : c < d) :
a * d + c < b * d := by
have h := Nat.mul_le_mul_right d (Nat.succ_le_of_lt ha)
rw [Nat.succ_mul] at h
omega

/-- The entire band dimension is bounded by the flat tensor input dimension. -/
theorem bandSize_le_seven_pow (L m : ℕ) : bandSize L m ≤ 7 ^ L := by
have hK : K0 L m ≤ 2 ^ L := (Nat.sqrt_le_self _).trans (Nat.choose_le_two_pow _ _)
have hN : N0 L m ≤ 3 ^ L := Nat.pow_le_pow_right (by decide) (Nat.sub_le _ _)
calc bandSize L m ≤ 2 ^ L * 3 ^ L := Nat.mul_le_mul hK hN
_ = 6 ^ L := by rw [← Nat.mul_pow]
_ ≤ 7 ^ L := Nat.pow_le_pow_left (by decide) _

/-- Even the last padded band has small block arithmetic. This bound precedes the `r<N`
guard; it does not assert that a padded row/column is a real matrix position. -/
theorem band_position_bounds {L m N β q o : ℕ} (hβ : β < numBands L m N)
(hq : q < K0 L m) (ho : o < N0 L m) :
β * K0 L m < N + 7 ^ L ∧
β * K0 L m + q < N + 7 ^ L ∧
(β * K0 L m + q) * N0 L m < N + 7 ^ L ∧
(β * K0 L m + q) * N0 L m + o < N + 7 ^ L := by
have hb : β * K0 L m + q < numBands L m N * K0 L m := mul_add_lt_mul hβ hq
have hr : (β * K0 L m + q) * N0 L m + o < numBands L m N * K0 L m * N0 L m :=
mul_add_lt_mul hb ho
have hpad : numBands L m N * bandSize L m ≤ N + bandSize L m - 1 :=
Nat.div_mul_le_self _ _
have hsize := bandSize_le_seven_pow L m
have hblock : β * K0 L m + q ≤ (β * K0 L m + q) * N0 L m :=
Nat.le_mul_of_pos_right _ (N0_pos L m)
have heq : numBands L m N * K0 L m * N0 L m = numBands L m N * bandSize L m := by
rw [bandSize, Nat.mul_assoc]
rw [heq] at hr
omega

/-- Nonempty matrices need at least one shared band. -/
theorem numBands_pos {L m N : ℕ} (hm : m ≤ L) (hN : 0 < N) : 0 < numBands L m N := by
have hb : 0 < bandSize L m := Nat.mul_pos (K0_pos hm) (N0_pos L m)
change 0 < (N + bandSize L m - 1) / bandSize L m
exact Nat.div_pos (by omega) hb

/-- A full band's original matrix entries fit within one encoding-sized block. This bound
is valid for every `m≤L`, without the thin-regime specialization. -/
theorem bandSize_mul_D_le_ten_pow {L m : ℕ} (hm : m ≤ L) :
bandSize L m * D m ≤ 10 ^ L := by
have hK : K0 L m ≤ 2 ^ L := (Nat.sqrt_le_self _).trans (Nat.choose_le_two_pow _ _)
have hN : N0 L m ≤ 4 ^ (L - m) := Nat.pow_le_pow_left (by decide) _
calc bandSize L m * D m ≤ (2 ^ L * 4 ^ (L - m)) * 4 ^ m :=
Nat.mul_le_mul_right _ (Nat.mul_le_mul hK hN)
_ = 8 ^ L := by
rw [Nat.mul_assoc, ← Nat.pow_add, Nat.sub_add_cancel hm, ← Nat.mul_pow]
_ ≤ 10 ^ L := Nat.pow_le_pow_left (by decide) _

/-- All original matrix entries are dominated by the shared band catalogue size; this
charges input copying/restoration without a separate thin-regime estimate. -/
theorem matrix_entries_le_band_encodings {L m : ℕ} (hm : m ≤ L) (N : ℕ) :
N * D m ≤ numBands L m N * 10 ^ L := by
calc N * D m ≤ padN L m N * D m := Nat.mul_le_mul_right _ (le_padN hm N)
_ = numBands L m N * (bandSize L m * D m) := by rw [padN, Nat.mul_assoc]
_ ≤ numBands L m N * 10 ^ L := Nat.mul_le_mul_left _ (bandSize_mul_D_le_ten_pow hm)

/-- For nonempty matrices, table initialization and the original matrix input are all
dominated by a constant times the shared encoding entry count. -/
theorem preparation_shape_le {L m N : ℕ} (hm : m ≤ L) (hN : 0 < N) :
1 + N * D m + 2 ^ L + 2 * numBands L m N * 10 ^ L ≤
5 * (numBands L m N * 10 ^ L) := by
have hinput := matrix_entries_le_band_encodings hm N
have hmask : 2 ^ L ≤ 10 ^ L := Nat.pow_le_pow_left (by decide) _
have hpos : 1 ≤ 10 ^ L := Nat.one_le_pow L 10 (by decide)
have hbands : 10 ^ L ≤ numBands L m N * 10 ^ L :=
Nat.le_mul_of_pos_left _ (numBands_pos hm hN)
rw [Nat.mul_assoc]
omega

end Cslib.Algorithms.MatrixMultiplication.Schonhage
15 changes: 8 additions & 7 deletions Complexity/Algorithms/MatrixMultiplication/Schonhage/Batch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private theorem exists_of_summand_ne_zero {L m : ℕ} (Q : Finset (Fin L)) (hQ :
(r c : OuterStr L m) {u : LeftStr L} {v : RightStr L}
(hγ : ∀ ℓ, coefficient (u ℓ) (v ℓ) (outStrOf Q hQ r c ℓ) ≠ 0) (hu : (innerSetL u).card = m)
(hv : (innerSetR v).card = m) : ∃ π, u = leftStrOf Q hQ r π ∧ v = rightStrOf Q hQ π c := by
simp only [outStrOf, forall_level_iff Q hQ, glue_innerLevel, glue_outerLevel] at hγ
simp only [outStrOf, forall_iff_orderEmbOfFin_and_compl Q hQ, glue_orderEmbOfFin,
glue_orderEmbOfFin_compl] at hγ
obtain ⟨hγin, hγout⟩ := hγ
-- at a level ℓ ∈ Q we have w_ℓ = z₀ […] So (u_ℓ, v_ℓ) = (p_ij, q_ij) for some i, j.
have hin : ∀ k, ∃ ij : Fin 2 × Fin 2,
Expand All @@ -117,11 +118,11 @@ private theorem exists_of_summand_ne_zero {L m : ℕ} (Q : Finset (Fin L)) (hQ :
-- Thus u and v have an inner variable at every level of Q, and their inner sets are therefore
-- exactly Q. So u_ℓ and v_ℓ are outer at the levels outside Q.
have huQ : innerSetL u = Q :=
filter_eq_of_forall_innerLevel Q hQ (fun k => by rw [(hπ k).1]; trivial) hu
filter_eq_of_forall_orderEmbOfFin Q hQ (fun k => by rw [(hπ k).1]; trivial) hu
have hvQ : innerSetR v = Q :=
filter_eq_of_forall_innerLevel Q hQ (fun k => by rw [(hπ k).2]; trivial) hv
have huout := ((filter_eq_iff_forall_level Q hQ).mp huQ).2
have hvout := ((filter_eq_iff_forall_level Q hQ).mp hvQ).2
filter_eq_of_forall_orderEmbOfFin Q hQ (fun k => by rw [(hπ k).2]; trivial) hv
have huout := ((filter_eq_iff_orderEmbOfFin_and_compl Q hQ).mp huQ).2
have hvout := ((filter_eq_iff_orderEmbOfFin_and_compl Q hQ).mp hvQ).2
-- at a level ℓ ∉ Q we have w_ℓ = z_ij for some i, j […] so (u_ℓ, v_ℓ) = (x_i, y_j).
have hout : ∀ k, u ((Qᶜ.orderEmbOfFin (card_compl_of_card_eq Q hQ)) k) = .x (r k) ∧ v
((Qᶜ.orderEmbOfFin (card_compl_of_card_eq Q hQ)) k) = .y (c k) :=
Expand All @@ -135,8 +136,8 @@ private theorem prod_gamma_eq_one {L m : ℕ} (Q : Finset (Fin L)) (hQ : Q.card
∏ ℓ, coefficient (leftStrOf Q hQ r π ℓ) (rightStrOf Q hQ π c ℓ) (outStrOf Q hQ r c ℓ) = 1 := by
have hone : ∀ ℓ,
coefficient (leftStrOf Q hQ r π ℓ) (rightStrOf Q hQ π c ℓ) (outStrOf Q hQ r c ℓ) = 1 := by
simp only [forall_level_iff Q hQ, leftStrOf, rightStrOf, outStrOf, glue_innerLevel,
glue_outerLevel]
simp only [forall_iff_orderEmbOfFin_and_compl Q hQ, leftStrOf, rightStrOf, outStrOf,
glue_orderEmbOfFin, glue_orderEmbOfFin_compl]
exact ⟨fun _ => (coefficient_z0 _ _).trans (ite_eq_left ⟨_, _, rfl, rfl⟩),
fun _ => (coefficient_x_y_z _ _ _ _).trans (ite_eq_left ⟨rfl, rfl⟩)⟩
exact prod_eq_one fun ℓ _ => hone ℓ
Expand Down
23 changes: 13 additions & 10 deletions Complexity/Algorithms/MatrixMultiplication/Schonhage/Levels.lean
Original file line number Diff line number Diff line change
Expand Up @@ -187,35 +187,36 @@ theorem innerSetO_outStrOf (r c : OuterStr L m) : innerSetO (outStrOf Q hQ r c)
theorem outerPartL_leftStrOf (r : OuterStr L m) (π : InnerStr m)
(h : (innerSetL (leftStrOf Q hQ r π)).card = m) : outerPartL (leftStrOf Q hQ r π) h = r :=
funext fun k => congrArg LeftVar.outerIndex
(glue_outerLevel_of_eq Q hQ _ _ (innerSetL_leftStrOf Q hQ r π) h k)
(glue_orderEmbOfFin_compl_of_eq Q hQ _ _ (innerSetL_leftStrOf Q hQ r π) h k)

/-- The inner part of `leftStrOf Q hQ r π` is `π`. -/
@[simp]
theorem innerPartL_leftStrOf (r : OuterStr L m) (π : InnerStr m)
(h : (innerSetL (leftStrOf Q hQ r π)).card = m) : innerPartL (leftStrOf Q hQ r π) h = π :=
funext fun k => congrArg LeftVar.innerIndex
(glue_innerLevel_of_eq Q hQ _ _ (innerSetL_leftStrOf Q hQ r π) h k)
(glue_orderEmbOfFin_of_eq Q hQ _ _ (innerSetL_leftStrOf Q hQ r π) h k)

/-- The inner part of `rightStrOf Q hQ π c` is `π`. -/
@[simp]
theorem innerPartR_rightStrOf (π : InnerStr m) (c : OuterStr L m)
(h : (innerSetR (rightStrOf Q hQ π c)).card = m) : innerPartR (rightStrOf Q hQ π c) h = π :=
funext fun k => congrArg RightVar.innerIndex
(glue_innerLevel_of_eq Q hQ _ _ (innerSetR_rightStrOf Q hQ π c) h k)
(glue_orderEmbOfFin_of_eq Q hQ _ _ (innerSetR_rightStrOf Q hQ π c) h k)

/-- The outer part of `rightStrOf Q hQ π c` is `c`. -/
@[simp]
theorem outerPartR_rightStrOf (π : InnerStr m) (c : OuterStr L m)
(h : (innerSetR (rightStrOf Q hQ π c)).card = m) : outerPartR (rightStrOf Q hQ π c) h = c :=
funext fun k => congrArg RightVar.outerIndex
(glue_outerLevel_of_eq Q hQ _ _ (innerSetR_rightStrOf Q hQ π c) h k)
(glue_orderEmbOfFin_compl_of_eq Q hQ _ _ (innerSetR_rightStrOf Q hQ π c) h k)

/-- The variable of `outStrOf Q hQ r c` at the `k`-th lowest level outside its inner set. -/
private theorem outStrOf_outerLevel (r c : OuterStr L m)
(h : (innerSetO (outStrOf Q hQ r c)).card = m) (k : Fin (L - m)) :
outStrOf Q hQ r c (((innerSetO (outStrOf Q hQ r c))ᶜ.orderEmbOfFin (card_compl_of_card_eq
(innerSetO (outStrOf Q hQ r c)) h)) k) = .z (r k) (c k) := by
rw [outerLevel_congr Q hQ (innerSetO_outStrOf Q hQ r c) h, outStrOf, glue_outerLevel]
simp only [innerSetO_outStrOf] at h ⊢
exact glue_orderEmbOfFin_compl Q hQ _ _ k

/-- The row of `outStrOf Q hQ r c` is `r`. -/
@[simp]
Expand All @@ -236,7 +237,8 @@ part. -/
theorem leftStr_eq_leftStrOf {u : LeftStr L} (hu : innerSetL u = Q) (h : (innerSetL u).card = m) :
u = leftStrOf Q hQ (outerPartL u h) (innerPartL u h) := by
subst hu
refine glue_index _ h LeftVar.IsInner (inner := fun π : Fin 2 × Fin 2 => .p π.1 π.2) ?_ ?_ rfl
refine eq_glue_of_reconstruct _ h LeftVar.IsInner
(fromSubset := fun π : Fin 2 × Fin 2 => .p π.1 π.2) ?_ ?_ rfl
· rintro (i | ⟨i, j⟩) hs
exacts [hs.elim, rfl]
· rintro (i | ⟨i, j⟩) hs
Expand All @@ -247,7 +249,8 @@ part. -/
theorem rightStr_eq_rightStrOf {v : RightStr L} (hv : innerSetR v = Q)
(h : (innerSetR v).card = m) : v = rightStrOf Q hQ (innerPartR v h) (outerPartR v h) := by
subst hv
refine glue_index _ h RightVar.IsInner (inner := fun π : Fin 2 × Fin 2 => .q π.1 π.2) ?_ ?_ rfl
refine eq_glue_of_reconstruct _ h RightVar.IsInner
(fromSubset := fun π : Fin 2 × Fin 2 => .q π.1 π.2) ?_ ?_ rfl
· rintro (j | ⟨i, j⟩) ht
exacts [ht.elim, rfl]
· rintro (j | ⟨i, j⟩) ht
Expand All @@ -257,9 +260,9 @@ theorem rightStr_eq_rightStrOf {v : RightStr L} (hv : innerSetR v = Q)
theorem outStr_eq_outStrOf {w : OutStr L} (hw : innerSetO w = Q) (h : (innerSetO w).card = m) :
w = outStrOf Q hQ (rowO w h) (colO w h) := by
subst hw
refine glue_index _ h OutVar.IsInner (inner := fun _ : Unit => .z0)
(outer := fun rc : Fin 3 × Fin 3 => .z rc.1 rc.2) (innerIndex := fun _ => ())
(outerIndex := fun z => (z.rowIndex, z.colIndex)) ?_ ?_ rfl
refine eq_glue_of_reconstruct _ h OutVar.IsInner (fromSubset := fun _ : Unit => .z0)
(fromCompl := fun rc : Fin 3 × Fin 3 => .z rc.1 rc.2) (toSubset := fun _ => ())
(toCompl := fun z => (z.rowIndex, z.colIndex)) ?_ ?_ rfl
· rintro (⟨i, j⟩ | _) hz
exacts [hz.elim, rfl]
· rintro (⟨i, j⟩ | _) hz
Expand Down
Loading
Loading