While this submission is a draft, it cannot be used by other submissions.

Thin matrix products and persistent entry queries

Lax350013.ThinMatrices · concepts/Lax350013/ThinMatrices.lean · lax-350013

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    Two integer matrices have dimensions N×DN\times D and D×ND\times N, and entries bounded in absolute value by UU. Wanted output positions are a list without repetitions. The data-structure specification bounds preprocessing time and the extent of retained memory, then requires correctness for every finite sequence of entry queries.

    Concept map
    4 concepts; 7 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1/-
    2Copyright (c) 2026 Anthropic, PBC. All rights reserved.
    3Released under Apache 2.0 license as described in the file LICENSE.
    4SPDX-License-Identifier: Apache-2.0
    5-/
    6/-
    7Modified for the independent Lax packaging by Édouard Bonnet, 2026.
    8Derived from 3sum-apsp/EndStatement.lean / PaperStatements.lean at upstream commit e1a4e6508154ea59f030480661590a9fe3018011.
    9Changes: Lax module/namespace layout, separated concepts and proofs, archive
    10annotations, and compatibility with the archive Lean/mathlib environment.
    11See NOTICE and README.md in the submission root for provenance and scope.
    12-/
    13
    14import Mathlib.Algebra.MvPolynomial.Basic
    15import Mathlib.Analysis.SpecialFunctions.Log.Base
    16import Mathlib.Analysis.SpecialFunctions.Log.Basic
    17import Mathlib.Analysis.SpecialFunctions.Pow.Real
    18import Mathlib.Combinatorics.SimpleGraph.Basic
    19import Mathlib.Data.Finset.Sort
    20import Mathlib.LinearAlgebra.Matrix.Notation
    21import Mathlib.MeasureTheory.Integral.Bochner.Basic
    22import Mathlib.NumberTheory.PrimeCounting
    23import Mathlib.Probability.Independence.Basic
    24import Mathlib.Tactic.DeriveFintype
    25import Lax350013.RAMResources
    26
    27/-!
    28---
    29title: Thin matrix products and persistent entry queries
    30type: definition
    31---
    32Two integer matrices have dimensions N×DN\times D and D×ND\times N, and entries bounded in absolute value by UU. Wanted output positions are a list without repetitions. The data-structure specification bounds preprocessing time and the extent of retained memory, then requires correctness for every finite sequence of entry queries.
    33-/
    34
    35namespace Lax350013.ThinMatrices
    36
    37open Finset
    38open Lax350013.WordRAM
    39open Lax350013.RAMResources
    40
    41/-- A matrix written row by row. -/
    42def rowMajor {n m : ℕ} (A : Fin n → Fin m → ℤ) : List ℤ :=
    43 (List.finRange n).flatMap fun i => (List.finRange m).map fun j => A i j
    44
    45/-- A Boolean as a number. -/
    46def bit (p : Bool) : ℤ := if p then 1 else 0
    47
    48/-- Two matrices `X ∈ ℤ^{N×D}` and `Y ∈ ℤ^{D×N}` with entries of absolute value at most `U`. -/
    49structure ThinPair where
    50 /-- The long side. -/
    51 N : ℕ
    52 /-- The short side. -/
    53 D : ℕ
    54 /-- The bound on the absolute values of the entries. -/
    55 U : ℕ
    56 /-- The first matrix. -/
    57 X : Matrix (Fin N) (Fin D) ℤ
    58 /-- The second matrix. -/
    59 Y : Matrix (Fin D) (Fin N) ℤ
    60 /-- The entries of `X` are bounded. -/
    61 boundX : ∀ i j, |X i j| ≤ (U : ℤ)
    62 /-- The entries of `Y` are bounded. -/
    63 boundY : ∀ i j, |Y i j| ≤ (U : ℤ)
    64
    65/-- Theorem 5: two such matrices and "a set W of [...] positions of an N × N matrix".
    66
    67NOTE. The paper does not say how a set is given. Here it is a list without repetitions, in any
    68order. -/
    69structure ThinInstance extends ThinPair where
    70 /-- The wanted positions. -/
    71 W : List (Fin N × Fin N)
    72 /-- No position is listed twice. -/
    73 nodup : W.Nodup
    74
    75/-- The input of the matrix problems: `N`, `D`, `|W|`, then further parameters `extra` (none, except
    76in Theorem 30), then `X`, then `Y`, then the rows `I` of the wanted positions, then their columns
    77`J`. -/
    78def ThinInstance.input (x : ThinInstance) (extra : List ℤ) : List ℤ :=
    79 [(x.N : ℤ), (x.D : ℤ), (x.W.length : ℤ)] ++ extra ++ rowMajor x.X ++ rowMajor x.Y ++
    80 x.W.map (fun q => (q.1.val : ℤ)) ++ x.W.map (fun q => (q.2.val : ℤ))
    81
    82/-- **The wanted entries of a thin matrix product** (Theorem 5): accept, and leave `(XY)[I,J]` for
    83the `i`-th wanted position `(I,J)` in the `i`-th output cell. -/
    84def thinProduct (extra : List ℤ) : Problem where
    85 Inst := ThinInstance
    86 params x := [x.N, x.D]
    87 input x := x.input extra
    88 IsAnswer x verdict out :=
    89 verdict = true ∧ ∀ (i : ℕ) (h : i < x.W.length), out i = (x.X * x.Y) x.W[i].1 x.W[i].2
    90
    91/-- The input of the preprocessing: `N`, `D`, further parameters `extra` (none, except in
    92Theorem 30), then `X`, then `Y`. The list `extra` is fixed before the instance. -/
    93def ThinPair.input (x : ThinPair) (extra : List ℤ) : List ℤ :=
    94 [(x.N : ℤ), (x.D : ℤ)] ++ extra ++ rowMajor x.X ++ rowMajor x.Y
    95
    96/-- **A data structure for the entries of a thin matrix product** (Theorem 30, Corollary 26): "After
    97preprocessing X and Y [...], the data structure answers a query for any single entry of XY, not
    98known in advance" (Section 4).
    99
    100`P` is the preprocessing program, `Q` the query program, `qI`, `qJ`, `qOut` the three cells through
    101which queries are put and answered; all of them, and the slope `b`, are fixed before the instance.
    102On every instance in `dom` and at every admissible word size:
    103
    104* time: the preprocessing accepts within `Tp x` steps;
    105* space: it leaves unchanged every cell `a` with `a < -Sp x` or `a > len + Sp x`, where the input
    106 occupies the cells 0 to `len - 1` (so the cells of the input are not counted);
    107* queries: then every sequence of queries `(I, J)` with `I, J < N` is served, each query within
    108 `Tq x` steps. A query starts on the memory left behind; nothing is reset for it.
    109
    110NOTE. The paper says "time and space" and does not define space. Here space is the extent of the
    111memory in which the preprocessing leaves the data structure, not the number of cells written, which
    112is at most the time anyway; a structure that is scattered over a large range of addresses does not
    113count as small. Cells that the preprocessing restores, and cells that the queries write, are not
    114constrained. -/
    115def IsDataStructure (P Q : List Instr) (qI qJ qOut : ℤ) (b : ℕ) (extra : List ℤ)
    116 (dom : ThinPair → Prop) (Tp Sp Tq : ThinPair → ℝ) : Prop :=
    117 ∀ x : ThinPair, dom x → ∀ bits : ℕ, Admissible b [x.N, x.D] bits →
    118 ∃ (tp tq : ℕ) (c : ℤ → BitVec bits), (tp : ℝ) ≤ Tp x ∧ (tq : ℝ) ≤ Tq x ∧
    119 exec P tp 0 (loadWords bits (x.input extra)) = some (true, c) ∧
    120 (∀ a : ℤ, ((a : ℝ) < -Sp x ∨ ((x.input extra).length : ℝ) + Sp x < (a : ℝ)) →
    121 c a = loadWords bits (x.input extra) a) ∧
    122 ∀ queries : List (ℕ × ℕ), (∀ q ∈ queries, q.1 < x.N ∧ q.2 < x.N) →
    123 Serves Q qI qJ qOut tq
    124 (fun I J => if h : I < x.N ∧ J < x.N then (x.X * x.Y) ⟨I, h.1⟩ ⟨J, h.2⟩ else 0) c queries
    125
    126end Lax350013.ThinMatrices
    127

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…