The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Linarith.Datatypes
70 declarations. Mathlib docs · Source
Datatypes for linarith
Some of the data structures here are used in multiple parts of the tactic. We split them into their own file.
This file also contains a few convenient auxiliary functions.
Linear expressions
Comparisons with 0
Parsing into linear form
Control
Auxiliary functions
These functions are used by multiple modules, so we put them here for accessibility.
def Mathlib.Tactic.Linarith.GlobalPreprocessor.ctorIdx E1 #
Mathlib.Tactic.Linarith.GlobalPreprocessor → ℕ
theorem Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor.mk.inj E1 #
∀ {toPreprocessorBase : Mathlib.Tactic.Linarith.PreprocessorBase}
{transform : Lean.MVarId → List Lean.Expr → Lean.MetaM (List Mathlib.Tactic.Linarith.Branch)}
{toPreprocessorBase_1 : Mathlib.Tactic.Linarith.PreprocessorBase}
{transform_1 : Lean.MVarId → List Lean.Expr → Lean.MetaM (List Mathlib.Tactic.Linarith.Branch)},
{ toPreprocessorBase := toPreprocessorBase, transform := transform } =
{ toPreprocessorBase := toPreprocessorBase_1, transform := transform_1 } →
toPreprocessorBase = toPreprocessorBase_1 ∧ transform = transform_1
def Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor.ctorIdx E1 #
Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor → ℕ
theorem Mathlib.Tactic.Linarith.Preprocessor.mk.inj E1 #
∀ {toPreprocessorBase : Mathlib.Tactic.Linarith.PreprocessorBase} {transform : Lean.Expr → Lean.MetaM (List Lean.Expr)}
{toPreprocessorBase_1 : Mathlib.Tactic.Linarith.PreprocessorBase}
{transform_1 : Lean.Expr → Lean.MetaM (List Lean.Expr)},
{ toPreprocessorBase := toPreprocessorBase, transform := transform } =
{ toPreprocessorBase := toPreprocessorBase_1, transform := transform_1 } →
toPreprocessorBase = toPreprocessorBase_1 ∧ transform = transform_1
theorem Mathlib.Tactic.Linarith.PreprocessorBase.mk.inj E1 #
∀ {name : autoParam Lean.Name Mathlib.Tactic.Linarith.PreprocessorBase.name._autoParam} {description : String}
{name_1 : autoParam Lean.Name Mathlib.Tactic.Linarith.PreprocessorBase.name._autoParam} {description_1 : String},
{ name := name, description := description } = { name := name_1, description := description_1 } →
name = name_1 ∧ description = description_1
theorem Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor.mk.injEq E0 #
∀ (toPreprocessorBase : Mathlib.Tactic.Linarith.PreprocessorBase)
(transform : Lean.MVarId → List Lean.Expr → Lean.MetaM (List Mathlib.Tactic.Linarith.Branch))
(toPreprocessorBase_1 : Mathlib.Tactic.Linarith.PreprocessorBase)
(transform_1 : Lean.MVarId → List Lean.Expr → Lean.MetaM (List Mathlib.Tactic.Linarith.Branch)),
({ toPreprocessorBase := toPreprocessorBase, transform := transform } =
{ toPreprocessorBase := toPreprocessorBase_1, transform := transform_1 }) =
(toPreprocessorBase = toPreprocessorBase_1 ∧ transform = transform_1)
theorem Mathlib.Tactic.Linarith.Preprocessor.mk.injEq E0 #
∀ (toPreprocessorBase : Mathlib.Tactic.Linarith.PreprocessorBase) (transform : Lean.Expr → Lean.MetaM (List Lean.Expr))
(toPreprocessorBase_1 : Mathlib.Tactic.Linarith.PreprocessorBase)
(transform_1 : Lean.Expr → Lean.MetaM (List Lean.Expr)),
({ toPreprocessorBase := toPreprocessorBase, transform := transform } =
{ toPreprocessorBase := toPreprocessorBase_1, transform := transform_1 }) =
(toPreprocessorBase = toPreprocessorBase_1 ∧ transform = transform_1)
theorem Mathlib.Tactic.Linarith.Comp.mk.inj E1 #
∀ {str : Mathlib.Ineq} {coeffs : Mathlib.Tactic.Linarith.Linexp} {str_1 : Mathlib.Ineq}
{coeffs_1 : Mathlib.Tactic.Linarith.Linexp},
{ str := str, coeffs := coeffs } = { str := str_1, coeffs := coeffs_1 } → str = str_1 ∧ coeffs = coeffs_1
theorem Mathlib.Tactic.Linarith.Comp.mk.injEq E0 #
∀ (str : Mathlib.Ineq) (coeffs : Mathlib.Tactic.Linarith.Linexp) (str_1 : Mathlib.Ineq)
(coeffs_1 : Mathlib.Tactic.Linarith.Linexp),
({ str := str, coeffs := coeffs } = { str := str_1, coeffs := coeffs_1 }) = (str = str_1 ∧ coeffs = coeffs_1)
def Mathlib.Tactic.Linarith.CertificateOracle.ctorIdx E1 #
Mathlib.Tactic.Linarith.CertificateOracle → ℕ
def Mathlib.Tactic.Linarith.instInhabitedComp.default E1 #
Mathlib.Tactic.Linarith.Comp
theorem Mathlib.Tactic.Linarith.CertificateOracle.mk.injEq E0 #
∀ (produceCertificate produceCertificate_1 : List Mathlib.Tactic.Linarith.Comp → ℕ → Lean.MetaM (Std.HashMap ℕ ℕ)),
({ produceCertificate := produceCertificate } = { produceCertificate := produceCertificate_1 }) =
(produceCertificate = produceCertificate_1)
theorem Mathlib.Tactic.Linarith.GlobalPreprocessor.mk.injEq E0 #
∀ (toPreprocessorBase : Mathlib.Tactic.Linarith.PreprocessorBase)
(transform : List Lean.Expr → Lean.MetaM (List Lean.Expr))
(toPreprocessorBase_1 : Mathlib.Tactic.Linarith.PreprocessorBase)
(transform_1 : List Lean.Expr → Lean.MetaM (List Lean.Expr)),
({ toPreprocessorBase := toPreprocessorBase, transform := transform } =
{ toPreprocessorBase := toPreprocessorBase_1, transform := transform_1 }) =
(toPreprocessorBase = toPreprocessorBase_1 ∧ transform = transform_1)
def Mathlib.Tactic.Linarith.Comp.ctorIdx E1 #
Mathlib.Tactic.Linarith.Comp → ℕ
theorem Mathlib.Tactic.Linarith.GlobalPreprocessor.mk.inj E1 #
∀ {toPreprocessorBase : Mathlib.Tactic.Linarith.PreprocessorBase}
{transform : List Lean.Expr → Lean.MetaM (List Lean.Expr)}
{toPreprocessorBase_1 : Mathlib.Tactic.Linarith.PreprocessorBase}
{transform_1 : List Lean.Expr → Lean.MetaM (List Lean.Expr)},
{ toPreprocessorBase := toPreprocessorBase, transform := transform } =
{ toPreprocessorBase := toPreprocessorBase_1, transform := transform_1 } →
toPreprocessorBase = toPreprocessorBase_1 ∧ transform = transform_1
theorem Mathlib.Tactic.Linarith.CertificateOracle.mk.inj E1 #
∀ {produceCertificate produceCertificate_1 : List Mathlib.Tactic.Linarith.Comp → ℕ → Lean.MetaM (Std.HashMap ℕ ℕ)},
{ produceCertificate := produceCertificate } = { produceCertificate := produceCertificate_1 } →
produceCertificate = produceCertificate_1
def Mathlib.Tactic.Linarith.PreprocessorBase.ctorIdx E1 #
Mathlib.Tactic.Linarith.PreprocessorBase → ℕ
def Mathlib.Tactic.Linarith.Preprocessor.ctorIdx E1 #
Mathlib.Tactic.Linarith.Preprocessor → ℕ
theorem Mathlib.Tactic.Linarith.PreprocessorBase.mk.injEq E0 #
∀ (name : autoParam Lean.Name Mathlib.Tactic.Linarith.PreprocessorBase.name._autoParam) (description : String)
(name_1 : autoParam Lean.Name Mathlib.Tactic.Linarith.PreprocessorBase.name._autoParam) (description_1 : String),
({ name := name, description := description } = { name := name_1, description := description_1 }) =
(name = name_1 ∧ description = description_1)
def Mathlib.Tactic.Linarith.linarithGetProofsMessage E1 #
List Lean.Expr → Lean.MetaM Lean.MessageData
A shorthand for getting the types of a list of proofs terms, to trace.
def Mathlib.Tactic.Linarith.linarithTraceProofs E1 #
{α : Type} → [Lean.ToMessageData α] → α → List Lean.Expr → Lean.MetaM Unit
A shorthand for tracing the types of a list of proof terms
when the trace.linarith option is set to true.
abbrev Mathlib.Tactic.Linarith.Linexp E1 #
Type
A linear expression is a list of pairs of variable indices and coefficients, representing the sum of the products of each coefficient with its corresponding variable.
Some functions on Linexp assume that n : Nat occurs at most once as the first element of a pair,
and that the list is sorted in decreasing order of the first argument.
This is not enforced by the type but the operations here preserve it.
opaque Mathlib.Tactic.Linarith.Linexp.add E1 #
Mathlib.Tactic.Linarith.Linexp → Mathlib.Tactic.Linarith.Linexp → Mathlib.Tactic.Linarith.Linexp
Add two Linexps together componentwise.
Preserves sorting and uniqueness of the first argument.
def Mathlib.Tactic.Linarith.Linexp.scale E1 #
ℤ → Mathlib.Tactic.Linarith.Linexp → Mathlib.Tactic.Linarith.Linexp
l.scale c scales the values in l by c without modifying the order or keys.
def Mathlib.Tactic.Linarith.Linexp.get E1 #
ℕ → Mathlib.Tactic.Linarith.Linexp → Option ℤ
l.get n returns the value in l associated with key n, if it exists, and none otherwise.
This function assumes that l is sorted in decreasing order of the first argument,
that is, it will return none as soon as it finds a key smaller than n.
def Mathlib.Tactic.Linarith.Linexp.contains E1 #
ℕ → Mathlib.Tactic.Linarith.Linexp → Bool
l.contains n is true iff n is the first element of a pair in l.
def Mathlib.Tactic.Linarith.Linexp.zfind E1 #
ℕ → Mathlib.Tactic.Linarith.Linexp → ℤ
l.zfind n returns the value associated with key n if there is one, and 0 otherwise.
def Mathlib.Tactic.Linarith.Linexp.vars E1 #
Mathlib.Tactic.Linarith.Linexp → List ℕ
l.vars returns the list of variables that occur in l.
def Mathlib.Tactic.Linarith.Linexp.cmp E1 #
Mathlib.Tactic.Linarith.Linexp → Mathlib.Tactic.Linarith.Linexp → Ordering
Defines a lex ordering on Linexp. This function is performance critical.
structure Mathlib.Tactic.Linarith.Comp E1 #
Type
The main datatype for FM elimination.
Variables are represented by natural numbers, each of which has an integer coefficient.
Index 0 is reserved for constants, i.e. coeffs.find 0 is the coefficient of 1.
The represented term is coeffs.sum (fun ⟨k, v⟩ ↦ v * Var[k]).
str determines the strength of the comparison -- is it < 0, ≤ 0, or = 0?
ctor Mathlib.Tactic.Linarith.Comp.mk E0 #
Mathlib.Ineq → Mathlib.Tactic.Linarith.Linexp → Mathlib.Tactic.Linarith.Comp
abbrev Mathlib.Tactic.Linarith.Comp.str E1 #
Mathlib.Tactic.Linarith.Comp → Mathlib.Ineq
The strength of the comparison, <, ≤, or =.
abbrev Mathlib.Tactic.Linarith.Comp.coeffs E1 #
Mathlib.Tactic.Linarith.Comp → Mathlib.Tactic.Linarith.Linexp
The coefficients of the comparison, stored as list of pairs (i, a),
where i is the index of a recorded atom, and a is the coefficient.
instance Mathlib.Tactic.Linarith.instInhabitedComp E0 #
Inhabited Mathlib.Tactic.Linarith.Comp
def Mathlib.Tactic.Linarith.instReprComp.repr E1 #
Mathlib.Tactic.Linarith.Comp → ℕ → Std.Format
instance Mathlib.Tactic.Linarith.instReprComp E0 #
Repr Mathlib.Tactic.Linarith.Comp
def Mathlib.Tactic.Linarith.Comp.vars E1 #
Mathlib.Tactic.Linarith.Comp → List ℕ
c.vars returns the list of variables that appear in the linear expression contained in c.
def Mathlib.Tactic.Linarith.Comp.coeffOf E1 #
Mathlib.Tactic.Linarith.Comp → ℕ → ℤ
c.coeffOf a projects the coefficient of variable a out of c.
def Mathlib.Tactic.Linarith.Comp.scale E1 #
Mathlib.Tactic.Linarith.Comp → ℕ → Mathlib.Tactic.Linarith.Comp
c.scale n scales the coefficients of c by n.
def Mathlib.Tactic.Linarith.Comp.add E1 #
Mathlib.Tactic.Linarith.Comp → Mathlib.Tactic.Linarith.Comp → Mathlib.Tactic.Linarith.Comp
Comp.add c1 c2 adds the expressions represented by c1 and c2.
The coefficient of variable a in c1.add c2
is the sum of the coefficients of a in c1 and c2.
def Mathlib.Tactic.Linarith.Comp.cmp E1 #
Mathlib.Tactic.Linarith.Comp → Mathlib.Tactic.Linarith.Comp → Ordering
Comp has a lex order. First the ineqs are compared, then the coeffs.
def Mathlib.Tactic.Linarith.Comp.isContr E1 #
Mathlib.Tactic.Linarith.Comp → Bool
A Comp represents a contradiction if its expression has no coefficients and its strength is <,
that is, it represents the fact 0 < 0.
instance Mathlib.Tactic.Linarith.Comp.ToFormat E0 #
Std.ToFormat Mathlib.Tactic.Linarith.Comp
structure Mathlib.Tactic.Linarith.PreprocessorBase E1 #
Type
Metadata about preprocessors, for trace output.
ctor Mathlib.Tactic.Linarith.PreprocessorBase.mk E0 #
autoParam Lean.Name Mathlib.Tactic.Linarith.PreprocessorBase.name._autoParam →
String → Mathlib.Tactic.Linarith.PreprocessorBase
abbrev Mathlib.Tactic.Linarith.PreprocessorBase.name E1 #
Mathlib.Tactic.Linarith.PreprocessorBase → Lean.Name
The name of the preprocessor, populated automatically, to create linkable trace messages.
abbrev Mathlib.Tactic.Linarith.PreprocessorBase.description E1 #
Mathlib.Tactic.Linarith.PreprocessorBase → String
The description of the preprocessor.
structure Mathlib.Tactic.Linarith.Preprocessor E1 #
Type
A preprocessor transforms a proof of a proposition into a proof of a different proposition.
The return type is List Expr, since some preprocessing steps may create multiple new hypotheses,
and some may remove a hypothesis from the list.
A "no-op" preprocessor should return its input as a singleton list.
abbrev Mathlib.Tactic.Linarith.Preprocessor.toPreprocessorBase E1 #
Mathlib.Tactic.Linarith.Preprocessor → Mathlib.Tactic.Linarith.PreprocessorBase
ctor Mathlib.Tactic.Linarith.Preprocessor.mk E0 #
Mathlib.Tactic.Linarith.PreprocessorBase →
(Lean.Expr → Lean.MetaM (List Lean.Expr)) → Mathlib.Tactic.Linarith.Preprocessor
abbrev Mathlib.Tactic.Linarith.Preprocessor.transform E1 #
Mathlib.Tactic.Linarith.Preprocessor → Lean.Expr → Lean.MetaM (List Lean.Expr)
Replace a hypothesis by a list of hypotheses. These expressions are the proof terms.
structure Mathlib.Tactic.Linarith.GlobalPreprocessor E1 #
Type
Some preprocessors need to examine the full list of hypotheses instead of working item by item.
As with Preprocessor, the input to a GlobalPreprocessor is replaced by, not added to, its
output.
ctor Mathlib.Tactic.Linarith.GlobalPreprocessor.mk E0 #
Mathlib.Tactic.Linarith.PreprocessorBase →
(List Lean.Expr → Lean.MetaM (List Lean.Expr)) → Mathlib.Tactic.Linarith.GlobalPreprocessor
abbrev Mathlib.Tactic.Linarith.GlobalPreprocessor.toPreprocessorBase E1 #
Mathlib.Tactic.Linarith.GlobalPreprocessor → Mathlib.Tactic.Linarith.PreprocessorBase
abbrev Mathlib.Tactic.Linarith.GlobalPreprocessor.transform E1 #
Mathlib.Tactic.Linarith.GlobalPreprocessor → List Lean.Expr → Lean.MetaM (List Lean.Expr)
Replace the collection of all hypotheses with new hypotheses. These expressions are proof terms.
def Mathlib.Tactic.Linarith.Branch E1 #
Type
Some preprocessors perform branching case splits. A Branch is used to track one of these case
splits. The first component, an MVarId, is the goal corresponding to this branch of the split,
given as a metavariable. The List Expr component is the list of hypotheses for linarith
in this branch.
structure Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor E1 #
Type
Some preprocessors perform branching case splits.
A GlobalBranchingPreprocessor produces a list of branches to run.
Each branch is independent, so hypotheses that appear in multiple branches should be duplicated.
The preprocessor is responsible for making sure that each branch contains the correct goal
metavariable.
ctor Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor.mk E0 #
Mathlib.Tactic.Linarith.PreprocessorBase →
(Lean.MVarId → List Lean.Expr → Lean.MetaM (List Mathlib.Tactic.Linarith.Branch)) →
Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor
abbrev Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor.toPreprocessorBase E1 #
Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor → Mathlib.Tactic.Linarith.PreprocessorBase
abbrev Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor.transform E1 #
Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor →
Lean.MVarId → List Lean.Expr → Lean.MetaM (List Mathlib.Tactic.Linarith.Branch)
Given a goal, and a list of hypotheses, produce a list of pairs (consisting of a goal and list of hypotheses).
def Mathlib.Tactic.Linarith.Preprocessor.globalize E1 #
Mathlib.Tactic.Linarith.Preprocessor → Mathlib.Tactic.Linarith.GlobalPreprocessor
A Preprocessor lifts to a GlobalPreprocessor by folding it over the input list.
def Mathlib.Tactic.Linarith.GlobalPreprocessor.branching E1 #
Mathlib.Tactic.Linarith.GlobalPreprocessor → Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor
A GlobalPreprocessor lifts to a GlobalBranchingPreprocessor by producing only one branch.
def Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor.process E1 #
Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor →
Lean.MVarId → List Lean.Expr → Lean.MetaM (List Mathlib.Tactic.Linarith.Branch)
process pp l runs pp.transform on l and returns the result,
tracing the result if trace.linarith is on.
instance Mathlib.Tactic.Linarith.PreprocessorToGlobalBranchingPreprocessor E0 #
Coe Mathlib.Tactic.Linarith.Preprocessor Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor
instance Mathlib.Tactic.Linarith.GlobalPreprocessorToGlobalBranchingPreprocessor E0 #
Coe Mathlib.Tactic.Linarith.GlobalPreprocessor Mathlib.Tactic.Linarith.GlobalBranchingPreprocessor
structure Mathlib.Tactic.Linarith.CertificateOracle E1 #
Type
A CertificateOracle provides a function
produceCertificate : List Comp → Nat → MetaM (HashMap Nat Nat).
The default CertificateOracle used by linarith is
Linarith.CertificateOracle.simplexAlgorithmSparse.
Linarith.CertificateOracle.simplexAlgorithmDense and Linarith.CertificateOracle.fourierMotzkin
are also available (though the Fourier-Motzkin oracle has some bugs).
ctor Mathlib.Tactic.Linarith.CertificateOracle.mk E0 #
(List Mathlib.Tactic.Linarith.Comp → ℕ → Lean.MetaM (Std.HashMap ℕ ℕ)) → Mathlib.Tactic.Linarith.CertificateOracle
abbrev Mathlib.Tactic.Linarith.CertificateOracle.produceCertificate E1 #
Mathlib.Tactic.Linarith.CertificateOracle → List Mathlib.Tactic.Linarith.Comp → ℕ → Lean.MetaM (Std.HashMap ℕ ℕ)
produceCertificate hyps max_var tries to derive a contradiction from the comparisons in
hyps by eliminating all variables ≤ max_var.
If successful, it returns a map coeff : Nat → Nat as a certificate.
This map represents that we can find a contradiction by taking the sum ∑ (coeff i) * hyps[i].
def Mathlib.Tactic.Linarith.parseCompAndExpr E1 #
Lean.Expr → Lean.MetaM (Mathlib.Ineq × Lean.Expr)
parseCompAndExpr e checks if e is of the form t < 0, t ≤ 0, or t = 0.
If it is, it returns the comparison along with t.
def Mathlib.Tactic.Linarith.mkSingleCompZeroOf E1 #
ℕ → Lean.Expr → Lean.MetaM (Mathlib.Ineq × Lean.Expr)
mkSingleCompZeroOf c h assumes that h is a proof of t R 0.
It produces a pair (R', h'), where h' is a proof of c*t R' 0.
Typically R and R' will be the same, except when c = 0, in which case R' is =.
If c = 1, h' is the same as h -- specifically, it does not change the type to 1*t R 0.