The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V34. The tactics of Mathlib

Mathlib.Tactic.Echelon.Core

56 declarations. Mathlib docs · Source

Parameterized computation core for the Bareiss elimination

bareissDecomp computes the transform L, the echelon form U, the row swaps and the pivot columns of an echelon decomposition by fraction-free elimination on a carrier of values.

As an optimisation, rows are scaled to clear their denominators (when applicable) before the elimination with the scales folded back into L afterwards.

A computation model supplies the carrier, its arithmetic operations (RingOps) and the encoding between entry syntax and values, and the tactic selects a model through the bareiss_ext extension registry.

Main definitions

  • RingOps: the arithmetic of a model's carrier.
  • Model: the computation model of a ring, including the encode/decode between the ring element and the carrier representation, and an optional entry certifier.
  • EntryCertifier: the functions that prove the ring arithmetic facts about single entries that a certificate needs.
  • bareissDecomp: runs fraction-free elimination over a model's carrier.
  • BareissData: raw data of the computed decomposition.
  • bareiss_ext: the attribute registering a computation model.

Implementation notes

The elimination in bareissDecomp maintains the invariant L * A_σ = W, where A_σ := A.submatrix σ id is the input with its rows in the arrangement σ accumulated so far and W is the working matrix. When the pivot search swaps the rows at positions r < p, the invariant must be restored against the new A_σ' = S * A_σ, where S is the permutation matrix of the transposition τ = (r, p):

S * W = S * L * (S⁻¹ * S) * A_σ = (S * L * S⁻¹) * A_σ'

so L is conjugated by the matrix of τ, as in LU factorisation with partial pivoting.

References

  • [Bareiss, Sylvester's identity and multistep integer-preserving Gaussian elimination][bareiss1968]

def Mathlib.Tactic.Echelon.BareissExt.ctorIdx E1 #

Mathlib.Tactic.Echelon.BareissExt → ℕ

def Mathlib.Tactic.Echelon.BareissData.ctorIdx E1 #

{V : Type} → Mathlib.Tactic.Echelon.BareissData V → ℕ

theorem Mathlib.Tactic.Echelon.ModelAux.mk.inj E1 #

∀ {u : Lean.Level} {α : Q(Type u)} {V : Type} {ops : Mathlib.Tactic.Echelon.RingOps V}
  {evalEntry : Q(«$α») → Lean.MetaM (V × Option V)} {commonMultiple : V → V → V} {mkEntry : V → Lean.MetaM Q(«$α»)}
  {entryCertifier? : Option (Mathlib.Tactic.Echelon.EntryCertifier α)} {ops_1 : Mathlib.Tactic.Echelon.RingOps V}
  {evalEntry_1 : Q(«$α») → Lean.MetaM (V × Option V)} {commonMultiple_1 : V → V → V}
  {mkEntry_1 : V → Lean.MetaM Q(«$α»)} {entryCertifier?_1 : Option (Mathlib.Tactic.Echelon.EntryCertifier α)},
  { ops := ops, evalEntry := evalEntry, commonMultiple := commonMultiple, mkEntry := mkEntry,
        entryCertifier? := entryCertifier? } =
      { ops := ops_1, evalEntry := evalEntry_1, commonMultiple := commonMultiple_1, mkEntry := mkEntry_1,
        entryCertifier? := entryCertifier?_1 } →
    ops = ops_1 ∧
      evalEntry = evalEntry_1 ∧
        commonMultiple = commonMultiple_1 ∧ mkEntry = mkEntry_1 ∧ entryCertifier? = entryCertifier?_1

theorem Mathlib.Tactic.Echelon.ModelAux.mk.injEq E0 #

∀ {u : Lean.Level} {α : Q(Type u)} {V : Type} (ops : Mathlib.Tactic.Echelon.RingOps V)
  (evalEntry : Q(«$α») → Lean.MetaM (V × Option V)) (commonMultiple : V → V → V) (mkEntry : V → Lean.MetaM Q(«$α»))
  (entryCertifier? : Option (Mathlib.Tactic.Echelon.EntryCertifier α)) (ops_1 : Mathlib.Tactic.Echelon.RingOps V)
  (evalEntry_1 : Q(«$α») → Lean.MetaM (V × Option V)) (commonMultiple_1 : V → V → V)
  (mkEntry_1 : V → Lean.MetaM Q(«$α»)) (entryCertifier?_1 : Option (Mathlib.Tactic.Echelon.EntryCertifier α)),
  ({ ops := ops, evalEntry := evalEntry, commonMultiple := commonMultiple, mkEntry := mkEntry,
        entryCertifier? := entryCertifier? } =
      { ops := ops_1, evalEntry := evalEntry_1, commonMultiple := commonMultiple_1, mkEntry := mkEntry_1,
        entryCertifier? := entryCertifier?_1 }) =
    (ops = ops_1 ∧
      evalEntry = evalEntry_1 ∧
        commonMultiple = commonMultiple_1 ∧ mkEntry = mkEntry_1 ∧ entryCertifier? = entryCertifier?_1)

def Mathlib.Tactic.Echelon.RingOps.ctorIdx E1 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → ℕ

theorem Mathlib.Tactic.Echelon.BareissExt.mk.injEq E0 #

∀ (model? model?_1 : {u : Lean.Level} → (α : Q(Type u)) → Lean.MetaM (Option (Mathlib.Tactic.Echelon.Model α))),
  ({ model? := model? } = { model? := model?_1 }) = (model? = model?_1)

def Mathlib.Tactic.Echelon.EntryCertifier.ctorIdx E1 #

{u : Lean.Level} → {α : Q(Type u)} → Mathlib.Tactic.Echelon.EntryCertifier α → ℕ

theorem Mathlib.Tactic.Echelon.RingOps.mk.injEq E0 #

∀ {V : Type} (zero one : V) (mul sub divExact : V → V → V) (isZero : V → Bool) (zero_1 one_1 : V)
  (mul_1 sub_1 divExact_1 : V → V → V) (isZero_1 : V → Bool),
  ({ zero := zero, one := one, mul := mul, sub := sub, divExact := divExact, isZero := isZero } =
      { zero := zero_1, one := one_1, mul := mul_1, sub := sub_1, divExact := divExact_1, isZero := isZero_1 }) =
    (zero = zero_1 ∧ one = one_1 ∧ mul = mul_1 ∧ sub = sub_1 ∧ divExact = divExact_1 ∧ isZero = isZero_1)

theorem Mathlib.Tactic.Echelon.BareissData.mk.inj E1 #

∀ {V : Type} {L U : Array (Array V)} {swaps : Array (ℕ × ℕ)} {pivot : Array ℕ} {L_1 U_1 : Array (Array V)}
  {swaps_1 : Array (ℕ × ℕ)} {pivot_1 : Array ℕ},
  { L := L, U := U, swaps := swaps, pivot := pivot } = { L := L_1, U := U_1, swaps := swaps_1, pivot := pivot_1 } →
    L = L_1 ∧ U = U_1 ∧ swaps = swaps_1 ∧ pivot = pivot_1

theorem Mathlib.Tactic.Echelon.RingOps.mk.inj E1 #

∀ {V : Type} {zero one : V} {mul sub divExact : V → V → V} {isZero : V → Bool} {zero_1 one_1 : V}
  {mul_1 sub_1 divExact_1 : V → V → V} {isZero_1 : V → Bool},
  { zero := zero, one := one, mul := mul, sub := sub, divExact := divExact, isZero := isZero } =
      { zero := zero_1, one := one_1, mul := mul_1, sub := sub_1, divExact := divExact_1, isZero := isZero_1 } →
    zero = zero_1 ∧ one = one_1 ∧ mul = mul_1 ∧ sub = sub_1 ∧ divExact = divExact_1 ∧ isZero = isZero_1

theorem Mathlib.Tactic.Echelon.BareissExt.mk.inj E1 #

∀ {model? model?_1 : {u : Lean.Level} → (α : Q(Type u)) → Lean.MetaM (Option (Mathlib.Tactic.Echelon.Model α))},
  { model? := model? } = { model? := model?_1 } → model? = model?_1

theorem Mathlib.Tactic.Echelon.BareissData.mk.injEq E0 #

∀ {V : Type} (L U : Array (Array V)) (swaps : Array (ℕ × ℕ)) (pivot : Array ℕ) (L_1 U_1 : Array (Array V))
  (swaps_1 : Array (ℕ × ℕ)) (pivot_1 : Array ℕ),
  ({ L := L, U := U, swaps := swaps, pivot := pivot } = { L := L_1, U := U_1, swaps := swaps_1, pivot := pivot_1 }) =
    (L = L_1 ∧ U = U_1 ∧ swaps = swaps_1 ∧ pivot = pivot_1)

def Mathlib.Tactic.Echelon.ModelAux.ctorIdx E1 #

{u : Lean.Level} → {α : Q(Type u)} → {V : Type} → Mathlib.Tactic.Echelon.ModelAux α V → ℕ

theorem Mathlib.Tactic.Echelon.EntryCertifier.mk.injEq E0 #

∀ {u : Lean.Level} {α : Q(Type u)} (eq : (a b : Q(«$α»)) → Lean.MetaM Q(«$a» = «$b»))
  (neZero : (zα : Q(Zero «$α»)) → (a : Q(«$α»)) → Lean.MetaM Q(«$a» ≠ 0))
  (eq_1 : (a b : Q(«$α»)) → Lean.MetaM Q(«$a» = «$b»))
  (neZero_1 : (zα : Q(Zero «$α»)) → (a : Q(«$α»)) → Lean.MetaM Q(«$a» ≠ 0)),
  ({ eq := eq, neZero := neZero } = { eq := eq_1, neZero := neZero_1 }) = (eq = eq_1 ∧ neZero = neZero_1)

theorem Mathlib.Tactic.Echelon.EntryCertifier.mk.inj E1 #

∀ {u : Lean.Level} {α : Q(Type u)} {eq : (a b : Q(«$α»)) → Lean.MetaM Q(«$a» = «$b»)}
  {neZero : (zα : Q(Zero «$α»)) → (a : Q(«$α»)) → Lean.MetaM Q(«$a» ≠ 0)}
  {eq_1 : (a b : Q(«$α»)) → Lean.MetaM Q(«$a» = «$b»)}
  {neZero_1 : (zα : Q(Zero «$α»)) → (a : Q(«$α»)) → Lean.MetaM Q(«$a» ≠ 0)},
  { eq := eq, neZero := neZero } = { eq := eq_1, neZero := neZero_1 } → eq = eq_1 ∧ neZero = neZero_1

structure Mathlib.Tactic.Echelon.RingOps E3 #

Type → Type

Arithmetics on values of V.

ctor Mathlib.Tactic.Echelon.RingOps.mk E0 #

{V : Type} → V → V → (V → V → V) → (V → V → V) → (V → V → V) → (V → Bool) → Mathlib.Tactic.Echelon.RingOps V

abbrev Mathlib.Tactic.Echelon.RingOps.zero E1 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → V

The zero value.

abbrev Mathlib.Tactic.Echelon.RingOps.one E1 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → V

The one value.

abbrev Mathlib.Tactic.Echelon.RingOps.mul E1 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → V → V → V

Multiplication.

abbrev Mathlib.Tactic.Echelon.RingOps.sub E1 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → V → V → V

Subtraction.

abbrev Mathlib.Tactic.Echelon.RingOps.divExact E1 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → V → V → V

Exact division.

abbrev Mathlib.Tactic.Echelon.RingOps.isZero E1 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → V → Bool

The pivot zero test.

instance Mathlib.Tactic.Echelon.instNonemptyRingOps E0 #

∀ {V : Type} [Nonempty V], Nonempty (Mathlib.Tactic.Echelon.RingOps V)

structure Mathlib.Tactic.Echelon.BareissData E3 #

Type → Type

Decomposition data with entries in V, the carrier of the elimination or Expr once the entries are encoded.

ctor Mathlib.Tactic.Echelon.BareissData.mk E0 #

{V : Type} → Array (Array V) → Array (Array V) → Array (ℕ × ℕ) → Array ℕ → Mathlib.Tactic.Echelon.BareissData V

abbrev Mathlib.Tactic.Echelon.BareissData.L E1 #

{V : Type} → Mathlib.Tactic.Echelon.BareissData V → Array (Array V)

The lower-triangular transform.

abbrev Mathlib.Tactic.Echelon.BareissData.U E1 #

{V : Type} → Mathlib.Tactic.Echelon.BareissData V → Array (Array V)

The echelon form, the final working matrix L * A_σ of the elimination.

abbrev Mathlib.Tactic.Echelon.BareissData.swaps E1 #

{V : Type} → Mathlib.Tactic.Echelon.BareissData V → Array (ℕ × ℕ)

The row swaps, in order. Swaps are infrequent in common cases, so their product is a smaller term for the kernel than a row permutation.

abbrev Mathlib.Tactic.Echelon.BareissData.pivot E1 #

{V : Type} → Mathlib.Tactic.Echelon.BareissData V → Array ℕ

The pivot columns. The k-th entry is the column of the pivot in row k of the final echelon form.

def Mathlib.Tactic.Echelon.BareissData.mapM E1 #

{V W : Type} →
  (V → Lean.MetaM W) → Mathlib.Tactic.Echelon.BareissData V → Lean.MetaM (Mathlib.Tactic.Echelon.BareissData W)

Map over the entries of the transform.

def Mathlib.Tactic.Echelon.BareissData.rowOrder E1 #

{V : Type} → Mathlib.Tactic.Echelon.BareissData V → Array ℕ

The row arrangement of the swaps: the entry at position i is the original row index that the swaps move to position i, that is, σ i.

def Mathlib.Tactic.Echelon.bareissDecomp E3 #

{V : Type} → Mathlib.Tactic.Echelon.RingOps V → Array (Array V) → Lean.MetaM (Mathlib.Tactic.Echelon.BareissData V)

Core algorithm of fraction-free Gaussian elimination, with the arithmetic supplied by the model.

A single sweep accumulates the transform L alongside the working matrix W, maintaining L * (A.submatrix σ id) = W for the row arrangement σ so far. The divisions are exact by Sylvester's identity, although the data-only computation does not prove that.

structure Mathlib.Tactic.Echelon.EntryCertifier E3 #

{u : Lean.Level} → Q(Type u) → Type

An entry certifier proves arithmetic facts about expressions of the ring α that the certificates need. eq proves an equation a = b, such as an unreduced entry of a matrix product equal to its computed value, and neZero proves a ≠ 0, such as for a pivot entry.

eq is typically built on a normalizer, while neZero may depend on bespoke methods if a normalizer cannot provide a disequality proof.

ctor Mathlib.Tactic.Echelon.EntryCertifier.mk E0 #

{u : Lean.Level} →
  {α : Q(Type u)} →
    ((a b : Q(«$α»)) → Lean.MetaM Q(«$a» = «$b»)) →
      ((zα : Q(Zero «$α»)) → (a : Q(«$α»)) → Lean.MetaM Q(«$a» ≠ 0)) → Mathlib.Tactic.Echelon.EntryCertifier α

abbrev Mathlib.Tactic.Echelon.EntryCertifier.eq E1 #

{u : Lean.Level} →
  {α : Q(Type u)} → Mathlib.Tactic.Echelon.EntryCertifier α → (a b : Q(«$α»)) → Lean.MetaM Q(«$a» = «$b»)

Prove a = b.

abbrev Mathlib.Tactic.Echelon.EntryCertifier.neZero E1 #

{u : Lean.Level} →
  {α : Q(Type u)} →
    Mathlib.Tactic.Echelon.EntryCertifier α → (zα : Q(Zero «$α»)) → (a : Q(«$α»)) → Lean.MetaM Q(«$a» ≠ 0)

Prove a ≠ 0, stated with the caller's Zero instance zα.

structure Mathlib.Tactic.Echelon.ModelAux E0 #

{u : Lean.Level} → Q(Type u) → Type → Type

The underlying type of Model.

We want to allow the carrier type of this model to be any type. Unfortunately, making it a structure field causes the structure to live in Type 1, which doesn't work in IO/MetaM.

ctor Mathlib.Tactic.Echelon.ModelAux.mk E0 #

{u : Lean.Level} →
  {α : Q(Type u)} →
    {V : Type} →
      Mathlib.Tactic.Echelon.RingOps V →
        (Q(«$α») → Lean.MetaM (V × Option V)) →
          (V → V → V) →
            (V → Lean.MetaM Q(«$α»)) →
              Option (Mathlib.Tactic.Echelon.EntryCertifier α) → Mathlib.Tactic.Echelon.ModelAux α V

abbrev Mathlib.Tactic.Echelon.ModelAux.ops E1 #

{u : Lean.Level} → {α : Q(Type u)} → {V : Type} → Mathlib.Tactic.Echelon.ModelAux α V → Mathlib.Tactic.Echelon.RingOps V

The arithmetic of the carrier.

abbrev Mathlib.Tactic.Echelon.ModelAux.evalEntry E1 #

{u : Lean.Level} →
  {α : Q(Type u)} → {V : Type} → Mathlib.Tactic.Echelon.ModelAux α V → Q(«$α») → Lean.MetaM (V × Option V)

Evaluate an entry to a value with an optional denominator for the row scaling. (n, some d) denotes n / d with d nonzero, and (n, none) denotes n.

abbrev Mathlib.Tactic.Echelon.ModelAux.commonMultiple E1 #

{u : Lean.Level} → {α : Q(Type u)} → {V : Type} → Mathlib.Tactic.Echelon.ModelAux α V → V → V → V

A nonzero common multiple for eliminating the denominators (ops.mul by default). A carrier type with a cheap lcm could supply it as an optimisation to keep the scaled entries small.

abbrev Mathlib.Tactic.Echelon.ModelAux.mkEntry E1 #

{u : Lean.Level} → {α : Q(Type u)} → {V : Type} → Mathlib.Tactic.Echelon.ModelAux α V → V → Lean.MetaM Q(«$α»)

The expression of the ring denoting a value.

abbrev Mathlib.Tactic.Echelon.ModelAux.entryCertifier? E1 #

{u : Lean.Level} →
  {α : Q(Type u)} → {V : Type} → Mathlib.Tactic.Echelon.ModelAux α V → Option (Mathlib.Tactic.Echelon.EntryCertifier α)

An optional certifier for the ring, or none to leave the conditions to the kernel. With none, the kernel checks the decomposition product L * A_σ = U by evaluating the list-based form as a whole without assembling it from per-entry proofs, which is faster than applying decideCertifier on every entry. As a result this field is optional rather than taking a default value, so that Mathlib.Tactic.Matrix.certifyProductEq can perform this optimization.

instance Mathlib.Tactic.Echelon.instNonemptyModelAux E0 #

∀ {u : Lean.Level} {α : Q(Type u)} {V : Type} [Nonempty V], Nonempty (Mathlib.Tactic.Echelon.ModelAux α V)

def Mathlib.Tactic.Echelon.ModelType E1 #

{u : Lean.Level} → Q(Type u) → Type

An opaque model type that is used in place of the actual model type. We artificially add a parameter α to avoid mixing model types of different rings.

instance Mathlib.Tactic.Echelon.instNonemptyModelType E0 #

∀ {u : Lean.Level} (α : Q(Type u)), Nonempty (Mathlib.Tactic.Echelon.ModelType α)

abbrev Mathlib.Tactic.Echelon.Model E3 #

{u : Lean.Level} → Q(Type u) → Type

A computation model of a ring α. It should be constructed using Model.mk.

def Mathlib.Tactic.Echelon.Model.mk E1 #

{u : Lean.Level} → {α : Q(Type u)} → (V : Type) → Mathlib.Tactic.Echelon.ModelAux α V → Mathlib.Tactic.Echelon.Model α

Construct a Model α from a ModelAux α V by replacing V with ModelType α using unsafeCast. This is safe if you use only one Model α at a time.

def Mathlib.Tactic.Echelon.scaleRows E1 #

{V : Type} →
  Mathlib.Tactic.Echelon.RingOps V → (V → V → V) → Array (Array (V × Option V)) → Array (Array V) × Array (Option V)

Clear the denominators of the rows before the decomposition algorithm.

def Mathlib.Tactic.Echelon.restoreScaling E1 #

{V : Type} →
  Mathlib.Tactic.Echelon.RingOps V →
    Array (Option V) → Mathlib.Tactic.Echelon.BareissData V → Mathlib.Tactic.Echelon.BareissData V

Fold the row scales into the transform after the decomposition algorithm. Column j of L is multiplied by the scale of the row that ends up in position j after permutation.

structure Mathlib.Tactic.Echelon.BareissExt E1 #

Type

An extension of the Bareiss ring computation model.

ctor Mathlib.Tactic.Echelon.BareissExt.mk E0 #

({u : Lean.Level} → (α : Q(Type u)) → Lean.MetaM (Option (Mathlib.Tactic.Echelon.Model α))) →
  Mathlib.Tactic.Echelon.BareissExt

abbrev Mathlib.Tactic.Echelon.BareissExt.model? E1 #

Mathlib.Tactic.Echelon.BareissExt →
  {u : Lean.Level} → (α : Q(Type u)) → Lean.MetaM (Option (Mathlib.Tactic.Echelon.Model α))

The model for the element type α and its carrier, or none if the extension does not handle α.

def Mathlib.Tactic.Echelon.mkBareissExt E1 #

Lean.Name → Lean.ImportM Mathlib.Tactic.Echelon.BareissExt

Read a bareiss_ext extension from a declaration of the right type.

opaque Mathlib.Tactic.Echelon.bareissExt E1 #

Lean.ScopedEnvExtension Lean.Name (Lean.Name × Mathlib.Tactic.Echelon.BareissExt)
  (Array (Lean.Name × Mathlib.Tactic.Echelon.BareissExt))

Environment extension for the bareiss_ext computation models. Uses a simple array to store the name-extension pairs for now.