Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d058118
Import exact matrix multiplication exponents
Vilin97 Nov 25, 2026
420dcc4
Preserve upstream modification notices in matrix exponent port
Vilin97 Nov 25, 2026
4d5ac28
Share generic tensor block operations across coefficient models
Vilin97 Nov 25, 2026
ab80808
Address engineering review of exact exponent formalization
Vilin97 Nov 25, 2026
61d016b
Correct exact exponent citations and share tensor proofs
Vilin97 Nov 25, 2026
4ef7258
Fix tensor-spectrum citations and share separation proofs
Vilin97 Nov 25, 2026
0ec268a
Share tensor descent and Fourier proofs and prune unused interfaces
Vilin97 Nov 25, 2026
c79feb8
Share matrix exponent rank and padding proofs
Vilin97 Nov 26, 2026
a50a014
Unify matrix rank and reset witnesses
Vilin97 Nov 26, 2026
91d7b0e
Share seating and reset cost arguments
Vilin97 Nov 26, 2026
b92b8c9
Share posting proofs and prune isolated interfaces
Vilin97 Nov 26, 2026
8a9a5c3
Consolidate matrix exponent routing, costs and restrictions
Vilin97 Nov 26, 2026
19705aa
Restore the general tripling character bound
Vilin97 Nov 26, 2026
3f82c42
Prune isolated adapters and share tensor restriction proofs
Vilin97 Nov 26, 2026
4975d30
Share length tables and narrow matrix exponent imports
Vilin97 Nov 26, 2026
b3ec0f2
Share reset mixer costs and tensor quotient laws
Vilin97 Nov 26, 2026
ff0183a
Share rectangular rank bounds and trim alternate certificates
Vilin97 Nov 26, 2026
33e87c1
Separate the binary profile proof and generalize rank laws
Vilin97 Nov 26, 2026
032a613
Isolate verification imports and generalize support laws
Vilin97 Nov 26, 2026
d921dce
Share padding witnesses and installation bounds
Vilin97 Nov 26, 2026
0f86072
Reuse weighted cost and tensor restriction proofs
Vilin97 Nov 26, 2026
839dc39
Share coefficient maps and allocation proofs
Vilin97 Nov 26, 2026
165a39b
Share half-rate losses and budget bounds
Vilin97 Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 29 additions & 0 deletions LeanPool/ExactMatrixExponents.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/-
Copyright (c) 2026 Lean Pool contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lean Pool contributors
-/
module

public import LeanPool.ExactMatrixExponents.LinearAlgebra.SpectralBooks.ExactExponent

/-!
# Exact square, dual and rectangular matrix multiplication exponents

Source: url:https://github.com/openai/math/blob/3344da59991ed94f9ba711217b29c1d760badfa6/lean/OAI/LinearAlgebra/SpectralBooks/ExactExponent.lean
Authors: OpenAI
Status: verified
Main declarations: `MatrixMultiplicationAllFields.SpectralBooks.square_exponent`,
`MatrixMultiplicationAllFields.SpectralBooks.dual_exponent`,
`MatrixMultiplicationAllFields.SpectralBooks.rectangular_exponent`
Tags: matrix-multiplication, arithmetic-complexity, tensor-rank, rectangular-exponents
MSC: 68Q17, 15A69, 68Q25
-/

/-!
## Arithmetic model and sources

The pinned Lean file states all three exact results for division-free programs.
The November 24, 2026 preprint states the square equality for formal circuits
allowing division, bounds the dual exponent, and gives rectangular rank lower bounds.
-/
608 changes: 608 additions & 0 deletions LeanPool/ExactMatrixExponents/Imports.lean

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/-
Copyright (c) 2026 the original authors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: OpenAI
-/
/- Modified by Lean Pool contributors for this port. -/
module

public import LeanPool.ExactMatrixExponents.LinearAlgebra.MatrixExponent.FunctionNetwork

/-!
# Testing a sorted list for duplicates

Each internal node checks the boundary between its two sublists. Even
copying the input at every level costs only a logarithmic factor.
-/

@[expose] public section

namespace MatrixMultiplicationAllFields.MatrixExponent

variable {a : Wire}

theorem wd_tree (w : ℕ) (a : Wire) : wd (tree w a) = 2 ^ w * wd a := by
induction w with
| zero => simp [tree]
| succ w ih =>
change wd (tree w a) + wd (tree w a) = _
rw [ih, pow_succ]
ring

/-- Selects the leftmost or rightmost leaf of a binary input tree. -/
def edge (right : Bool) : (w : ℕ) → Val (tree w a) → Val a
| 0, x => x
| w + 1, x => edge right w (if right then x.2 else x.1)

private theorem edge_net (F : Type) [Field F] (right : Bool) (w : ℕ) :
DNet F (tree w a) a (edge right w) (2 * wd (tree w a)) := by
induction w with
| zero => exact (DNet.id F a).mono (by change wd a ≤ 2 * wd a; omega)
| succ w ih =>
have h : DNet F (tree (w + 1) a) (tree w a)
(fun x => if right then x.2 else x.1) (wd (tree (w + 1) a)) := by
cases right
· exact DNet.fst F _ _
· exact DNet.snd F _ _
apply (h.comp ih).mono
change _ + 2 * wd (tree w a) ≤ 2 * (wd (tree w a) + wd (tree w a))
simp only [wd]
omega

variable [LinearOrder (Val a)]

private theorem edges (w : ℕ) (x : Val (tree w a))
(hs : (flatten w x).Pairwise (· ≤ ·)) :
edge false w x ∈ flatten w x ∧ edge true w x ∈ flatten w x ∧
∀ z ∈ flatten w x, edge false w x ≤ z ∧ z ≤ edge true w x := by
induction w with
| zero => simp [edge, flatten]
| succ w ih =>
obtain ⟨hl, hr, hcross⟩ := List.pairwise_append.mp hs
obtain ⟨hmin, _, hb⟩ := ih x.1 hl
obtain ⟨_, hmax, hc⟩ := ih x.2 hr
refine ⟨List.mem_append_left _ hmin, List.mem_append_right _ hmax, ?_⟩
intro z hz
rcases List.mem_append.mp hz with hz | hz
· exact ⟨(hb z hz).1, hcross _ hz _ hmax⟩
· exact ⟨hcross _ hmin _ hz, (hc z hz).2⟩

/-- Tests strict increase between consecutive leaves in the left-to-right order. -/
def adjacent : (w : ℕ) → Val (tree w a) → Bool
| 0, _ => true
| w + 1, x => (adjacent w x.1 && adjacent w x.2) &&
decide (edge true w x.1 < edge false w x.2)

theorem adjacent_iff (w : ℕ) (x : Val (tree w a))
(hs : (flatten w x).Pairwise (· ≤ ·)) :
adjacent w x = true ↔ (flatten w x).Nodup := by
induction w with
| zero => simp [adjacent, flatten]
| succ w ih =>
obtain ⟨hl, hr, hcross⟩ := List.pairwise_append.mp hs
obtain ⟨_, hmax, hb⟩ := edges w x.1 hl
obtain ⟨hmin, _, hc⟩ := edges w x.2 hr
rw [adjacent, Bool.and_eq_true, Bool.and_eq_true, decide_eq_true_eq, ih _ hl, ih _ hr,
flatten, List.nodup_append, and_assoc]
apply and_congr_right'
apply and_congr_right'
constructor
· intro h z hz y hy
exact ne_of_lt (((hb z hz).2.trans_lt h).trans_le (hc y hy).1)
· intro h
exact lt_of_le_of_ne (hcross _ hmax _ hmin) (h _ hmax _ hmin)

theorem adjacent_net {F : Type} [Field F] {k : ℕ}
(h : DNet F (.pair a a) .bit (fun x => decide (x.1 < x.2)) k) (w : ℕ) :
DNet F (tree w a) .bit (adjacent w) (2 ^ w * (w + 1) * (8 * wd a + k + 4)) := by
induction w with
| zero =>
apply ((DNet.discard F a).comp (DNet.table F .unit .bit (fun _ => true) (by decide))).mono
simp
omega
| succ w ih =>
let gate := DNet.table F (.pair .bit .bit) .bit (fun x => x.1 && x.2) (by decide)
have children := (ih.par ih).comp gate
have boundary := ((edge_net (a := a) F true w).par (edge_net F false w)).comp h
apply ((children.pair boundary).comp gate).mono
simp only [wd, wd_tree, pow_succ]
have hp : 1 ≤ 2 ^ w := Nat.one_le_pow _ _ (by decide)
nlinarith [Nat.mul_le_mul_right k hp]

end MatrixMultiplicationAllFields.MatrixExponent
Loading
Loading