Documentation

CslibFrontier.Foundations.LinearAlgebra.AffineSolutionSampling

Sampling affine solutions with bounded retries #

The MAYO SampleSolution subroutine takes a linear system A x = y and an explicit randomness vector r. It solves the shifted system A x' = y - A r and returns x' + r; it reports failure whenever A does not have full row rank, even when this particular target is in the range. MAYO signing tries fresh componentwise randomness in order and keeps the first successful attempt ([BCC+26], Section 2.1.2, Algorithm 2, pp. 8--9, and Section 2.1.5, Algorithm 7, p. 14).

Cslib.LinearAlgebra.AffineSolutionSolver records only the deterministic contract of the inner solver. It deliberately leaves the elimination algorithm abstract; a concrete implementation can reuse Matrix.GaussJordan. AffineSolutionSolver.sampleSolution implements the source's shift, and retrySampleSolution reuses List.findSome? for ordered first-success semantics. The latter returns the successful attempt data along with the solution, so a client does not lose separate randomness components such as MAYO's vinegar vectors and solution shift.

This module proves deterministic equation and failure behavior only. It does not assert that a random input produces a uniform solution, that attempts are independent, or that a system is surjective with any particular probability.

Main definitions #

Main results #

References #

structure Cslib.LinearAlgebra.AffineSolutionSolver {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] (A : U →ₗ[F] V) :
Type (max u_2 u_3)

The deterministic contract of a solver for A x = y that accepts exactly when A is surjective. In particular, a nonsurjective map is rejected even when the requested target happens to lie in its range. This structure specifies correctness and failure, not an elimination algorithm or a running-time bound.

  • solve : V → Option U

    Solve the affine system for a target, or report that A is not surjective.

  • map_eq_of_solve_eq_some {y : V} {x : U} : self.solve y = some x → A x = y

    Every returned value solves the requested system.

  • solve_eq_none_iff_not_surjective (y : V) : self.solve y = none ↔ ¬Function.Surjective ⇑A

    Failure depends only on lack of surjectivity, not on consistency for the particular target.

def Cslib.LinearAlgebra.AffineSolutionSolver.sampleSolution {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] {A : U →ₗ[F] V} (solver : AffineSolutionSolver A) (y : V) (r : U) :

Shift by explicit randomness r, solve A x' = y - A r, and return x' + r.

The randomness is data supplied by the caller. This definition makes no distributional claim.

theorem Cslib.LinearAlgebra.AffineSolutionSolver.map_eq_of_sampleSolution_eq_some {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] {A : U →ₗ[F] V} (solver : AffineSolutionSolver A) {y : V} {r x : U} (h : solver.sampleSolution y r = some x) :
A x = y

Every successful shifted sample solves the original affine system.

theorem Cslib.LinearAlgebra.AffineSolutionSolver.sampleSolution_eq_none_iff {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] {A : U →ₗ[F] V} (solver : AffineSolutionSolver A) (y : V) (r : U) :

Shifted sampling fails exactly when the linear map is not surjective. This preserves the source behavior that a consistent target still fails for a rank-deficient system.

def Cslib.LinearAlgebra.retrySampleSolution {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] {Attempt : Type u_4} (attempts : List Attempt) (system : Attempt → U →ₗ[F] V) (solver : (a : Attempt) → AffineSolutionSolver (system a)) (target : Attempt → V) (randomness : Attempt → U) :
Option (Attempt × U)

Try explicit attempt data in list order and return the first successful attempt together with its solution. The functions system, target, and randomness keep the attempt's components separate; for example, a MAYO client can put all vinegar vectors and the solution-shift vector in Attempt and recover them on success.

The empty list and a list whose systems are all nonsurjective return none.

theorem Cslib.LinearAlgebra.retrySampleSolution_eq_some_iff {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] {Attempt : Type u_4} {attempts : List Attempt} {system : Attempt → U →ₗ[F] V} {solver : (a : Attempt) → AffineSolutionSolver (system a)} {target : Attempt → V} {randomness : Attempt → U} {a : Attempt} {x : U} :
retrySampleSolution attempts system solver target randomness = some (a, x) ↔ ∃ (before : List Attempt) (after : List Attempt), attempts = before ++ a :: after ∧ (solver a).sampleSolution (target a) (randomness a) = some x ∧ ∀ a' ∈ before, ¬Function.Surjective ⇑(system a')

Exact first-success semantics: a retry returns (a, x) exactly when the list splits at a, all earlier systems are nonsurjective, and attempt a returns x.

theorem Cslib.LinearAlgebra.mem_and_map_eq_of_retrySampleSolution_eq_some {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] {Attempt : Type u_4} {attempts : List Attempt} {system : Attempt → U →ₗ[F] V} {solver : (a : Attempt) → AffineSolutionSolver (system a)} {target : Attempt → V} {randomness : Attempt → U} {a : Attempt} {x : U} (h : retrySampleSolution attempts system solver target randomness = some (a, x)) :
a ∈ attempts ∧ (system a) x = target a

A returned attempt belongs to the input list, and its returned vector solves that attempt's affine system.

theorem Cslib.LinearAlgebra.retrySampleSolution_eq_none_iff {F : Type u_1} {U : Type u_2} {V : Type u_3} [Field F] [AddCommGroup U] [Module F U] [AddCommGroup V] [Module F V] {Attempt : Type u_4} (attempts : List Attempt) (system : Attempt → U →ₗ[F] V) (solver : (a : Attempt) → AffineSolutionSolver (system a)) (target : Attempt → V) (randomness : Attempt → U) :
retrySampleSolution attempts system solver target randomness = none ↔ ∀ a ∈ attempts, ¬Function.Surjective ⇑(system a)

Bounded retries fail exactly when every listed attempt has a nonsurjective system. No probability or independence premise is hidden in this deterministic statement.