fact
stringlengths
6
3.84k
type
stringclasses
11 values
library
stringclasses
32 values
imports
listlengths
1
14
filename
stringlengths
20
95
symbolic_name
stringlengths
1
90
docstring
stringlengths
7
20k
mk_natCast_nonneg_prf (p : Expr × Expr) : MetaM (Option Expr) := match p with | ⟨e, target⟩ => try commitIfNoEx (mkAppM ``natCast_nonneg #[target, e]) catch e => do trace[linarith] "Got exception when using cast {e.toMessageData}" return none
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
mk_natCast_nonneg_prf
If `e : ℕ`, returns a proof of `0 ≤ (e : C)`.
@[deprecated "Use `Expr.lt` and `Expr.equal` or `Expr.eqv` directly. \ If you need to order expressions, consider ordering them by order seen, with AtomM." (since := "2025-08-31")] Expr.Ord : Ord Expr := ⟨fun a b => if Expr.lt a b then .lt else if a.equal b then .eq else .gt⟩
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
Expr.Ord
Ordering on `Expr`.
natToInt : GlobalBranchingPreprocessor where description := "move nats to ints" transform g l := do let l ← l.mapM fun h => do let t ← whnfR (← instantiateMVars (← inferType h)) if ← isNatProp t then let (some (h', t'), _) ← Term.TermElabM.run' (run_for g (zifyProof none h t)) | th...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
natToInt
If `h` is an equality or inequality between natural numbers, `natToInt` lifts this inequality to the integers. It also adds the facts that the integers involved are nonnegative. To avoid adding the same nonnegativity facts many times, it is a global preprocessor.
mkNonstrictIntProof (pf : Expr) : MetaM (Option Expr) := do match ← (← inferType pf).ineqOrNotIneq? with | (true, Ineq.lt, .const ``Int [], a, b) => return mkApp (← mkAppM ``Iff.mpr #[← mkAppOptM ``Int.add_one_le_iff #[a, b]]) pf | (false, Ineq.le, .const ``Int [], a, b) => return mkApp (← mkAppM ``Iff.mp...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
mkNonstrictIntProof
If `pf` is a proof of a strict inequality `(a : ℤ) < b`, `mkNonstrictIntProof pf` returns a proof of `a + 1 ≤ b`, and similarly if `pf` proves a negated weak inequality.
strengthenStrictInt : Preprocessor where description := "strengthen strict inequalities over int" transform h := return [(← mkNonstrictIntProof h).getD h]
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
strengthenStrictInt
`strengthenStrictInt h` turns a proof `h` of a strict integer inequality `t1 < t2` into a proof of `t1 ≤ t2 + 1`.
partial rearrangeComparison (e : Expr) : MetaM (Option Expr) := do match ← (← inferType e).ineq? with | (Ineq.le, _) => try? <| mkAppM ``Linarith.sub_nonpos_of_le #[e] | (Ineq.lt, _) => try? <| mkAppM ``Linarith.sub_neg_of_lt #[e] | (Ineq.eq, _) => try? <| mkAppM ``sub_eq_zero_of_eq #[e]
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
rearrangeComparison
`rearrangeComparison e` takes a proof `e` of an equality, inequality, or negation thereof, and turns it into a proof of a comparison `_ R 0`, where `R ∈ {=, ≤, <}`.
compWithZero : Preprocessor where description := "make comparisons with zero" transform e := return (← rearrangeComparison e).toList
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
compWithZero
`compWithZero h` takes a proof `h` of an equality, inequality, or negation thereof, and turns it into a proof of a comparison `_ R 0`, where `R ∈ {=, ≤, <}`.
without_one_mul {M : Type*} [MulOneClass M] {a b : M} (h : 1 * a = b) : a = b := by rwa [one_mul] at h
theorem
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
without_one_mul
null
normalizeDenominatorsLHS (h lhs : Expr) : MetaM Expr := do let mut (v, lhs') ← CancelDenoms.derive lhs if v = 1 then lhs' ← mkAppM ``without_one_mul #[lhs'] let (_, h'') ← mkSingleCompZeroOf v h try h''.rewriteType lhs' catch e => dbg_trace s!"Error in Linarith.normalizeDenominatorsLHS: {← e...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
normalizeDenominatorsLHS
`normalizeDenominatorsLHS h lhs` assumes that `h` is a proof of `lhs R 0`. It creates a proof of `lhs' R 0`, where all numeric division in `lhs` has been cancelled.
cancelDenoms : Preprocessor where description := "cancel denominators" transform := fun pf => (do let (_, lhs) ← parseCompAndExpr (← inferType pf) guard <| lhs.containsConst <| fun n => n = ``HDiv.hDiv || n = ``Div.div || n = ``Inv.inv || n == ``OfScientific.ofScientific pure [← normalizeD...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
cancelDenoms
`cancelDenoms pf` assumes `pf` is a proof of `t R 0`. If `t` contains the division symbol `/`, it tries to scale `t` to cancel out division by numerals.
partial findSquares (s : TreeSet (Nat × Bool) lexOrd.compare) (e : Expr) : AtomM (TreeSet (Nat × Bool) lexOrd.compare) := if e.hasLooseBVars then return s else match e.getAppFnArgs with | (``HPow.hPow, #[_, _, _, _, a, b]) => match b.numeral? with | some 2 => do let s ← findSquares s a let (ai...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
findSquares
`findSquares s e` collects all terms of the form `a ^ 2` and `a * a` that appear in `e` and adds them to the set `s`. A pair `(i, true)` is added to `s` when `atoms[i]^2` appears in `e`, and `(i, false)` is added to `s` when `atoms[i]*atoms[i]` appears in `e`.
private nlinarithGetSquareProofs (ls : List Expr) : MetaM (List Expr) := withTraceNode `linarith (return m!"{exceptEmoji ·} finding squares") do let s ← AtomM.run .reducible do let si ← ls.foldrM (fun h s' => do findSquares s' (← instantiateMVars (← inferType h))) ∅ si.toList.mapM fun (i, is_sq) => return (...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
nlinarithGetSquareProofs
Get proofs of `-x^2 ≤ 0` and `-(x*x) ≤ 0`, when those terms appear in `ls`
private nlinarithGetProductsProofs (ls : List Expr) : MetaM (List Expr) := withTraceNode `linarith (return m!"{exceptEmoji ·} adding product terms") do let with_comps ← ls.mapM (fun e => do let tp ← inferType e try let ⟨ine, _⟩ ← parseCompAndExpr tp pure (ine, e) catch _ => pure (Ineq.lt, e)...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
nlinarithGetProductsProofs
Get proofs for products of inequalities from `ls`. Note that the length of the resulting list is proportional to `ls.length^2`, which can make a large amount of work for the linarith oracle.
nlinarithExtras : GlobalPreprocessor where description := "nonlinear arithmetic extras" transform ls := do let new_es ← nlinarithGetSquareProofs ls let products ← nlinarithGetProductsProofs (new_es ++ ls) return (new_es ++ ls ++ products)
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
nlinarithExtras
`nlinarithExtras` is the preprocessor corresponding to the `nlinarith` tactic. * For every term `t` such that `t^2` or `t*t` appears in the input, adds a proof of `t^2 ≥ 0` or `t*t ≥ 0`. * For every pair of comparisons `t1 R1 0` and `t2 R2 0`, adds a proof of `t1*t2 R 0`. This preprocessor is typically run last, af...
partial removeNe_aux : MVarId → List Expr → MetaM (List Branch) := fun g hs => do let some (e, α, a, b) ← hs.findSomeM? (fun e : Expr => do let some (α, a, b) := (← instantiateMVars (← inferType e)).ne?' | return none return some (e, α, a, b)) | return [(g, hs)] let [ng1, ng2] ← g.apply (← mkAppOptM ``Or.el...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
removeNe_aux
`removeNe_aux` case splits on any proof `h : a ≠ b` in the input, turning it into `a < b ∨ a > b`. This produces `2^n` branches when there are `n` such hypotheses in the input.
removeNe : GlobalBranchingPreprocessor where description := "case split on ≠" transform := removeNe_aux
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
removeNe
`removeNe` case splits on any proof `h : a ≠ b` in the input, turning it into `a < b ∨ a > b`, by calling `linarith.removeNe_aux`. This produces `2^n` branches when there are `n` such hypotheses in the input.
defaultPreprocessors : List GlobalBranchingPreprocessor := [filterComparisons, removeNegations, natToInt, strengthenStrictInt, compWithZero, cancelDenoms]
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
defaultPreprocessors
The default list of preprocessors, in the order they should typically run.
preprocess (pps : List GlobalBranchingPreprocessor) (g : MVarId) (l : List Expr) : MetaM (List Branch) := do withTraceNode `linarith (fun e => return m!"{exceptEmoji e} Running preprocessors") <| g.withContext <| pps.foldlM (init := [(g, l)]) fun ls pp => do return (← ls.mapM fun (g, l) => do pp...
def
Tactic
[ "Mathlib.Control.Basic", "Mathlib.Lean.Meta.Tactic.Rewrite", "Mathlib.Tactic.CancelDenoms.Core", "Mathlib.Tactic.Linarith.Datatypes", "Mathlib.Tactic.Zify", "Mathlib.Util.AtomM" ]
Mathlib/Tactic/Linarith/Preprocessing.lean
preprocess
`preprocess pps l` takes a list `l` of proofs of propositions. It maps each preprocessor `pp ∈ pps` over this list. The preprocessors are run sequentially: each receives the output of the previous one. Note that a preprocessor may produce multiple or no expressions from each input expression, so the size of the list ma...
ofNatQ (α : Q(Type $u)) (_ : Q(Semiring $α)) (n : ℕ) : Q($α) := match n with | 0 => q(0 : $α) | 1 => q(1 : $α) | k+2 => have lit : Q(ℕ) := mkRawNatLit n have k : Q(ℕ) := mkRawNatLit k haveI : $lit =Q $k + 2 := ⟨⟩ q(OfNat.ofNat $lit)
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
ofNatQ
Typesafe conversion of `n : ℕ` to `Q($α)`.
mulExpr' {u : Level} (n : ℕ) {α : Q(Type $u)} (inst : Q(Semiring $α)) (e : Q($α)) : Q($α) := if n = 1 then e else let n := ofNatQ α inst n q($n * $e)
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
mulExpr'
A typesafe version of `mulExpr`.
mulExpr (n : ℕ) (e : Expr) : MetaM Expr := do let ⟨_, α, e⟩ ← inferTypeQ' e let inst : Q(Semiring $α) ← synthInstanceQ q(Semiring $α) return mulExpr' n inst e
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
mulExpr
`mulExpr n e` creates an `Expr` representing `n*e`. When elaborated, the coefficient will be a native numeral of the same type as `e`.
addExprs' {u : Level} {α : Q(Type $u)} (_inst : Q(AddMonoid $α)) : List Q($α) → Q($α) | [] => q(0) | h::t => go h t where /-- Inner loop for `addExprs'`. -/ go (p : Q($α)) : List Q($α) → Q($α) | [] => p | [q] => q($p + $q) | q::t => go q($p + $q) t
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
addExprs'
A type-safe analogue of `addExprs`.
addExprs : List Expr → MetaM Expr | [] => return q(0) -- This may not be of the intended type; use with caution. | L@(h::_) => do let ⟨_, α, _⟩ ← inferTypeQ' h let inst : Q(AddMonoid $α) ← synthInstanceQ q(AddMonoid $α) return addExprs' inst L
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
addExprs
`addExprs L` creates an `Expr` representing the sum of the elements of `L`, associated left.
addIneq : Ineq → Ineq → (Name × Ineq) | eq, eq => (``Linarith.eq_of_eq_of_eq, eq) | eq, le => (``Linarith.le_of_eq_of_le, le) | eq, lt => (``Linarith.lt_of_eq_of_lt, lt) | le, eq => (``Linarith.le_of_le_of_eq, le) | le, le => (``Linarith.add_nonpos, le) | le, lt => (``Linarith.add_lt_of_le_of_neg, lt) | l...
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
addIneq
If our goal is to add together two inequalities `t1 R1 0` and `t2 R2 0`, `addIneq R1 R2` produces the strength of the inequality in the sum `R`, along with the name of a lemma to apply in order to conclude `t1 + t2 R 0`.
mkLTZeroProof : List (Expr × ℕ) → MetaM Expr | [] => throwError "no linear hypotheses found" | [(h, c)] => do let (_, t) ← mkSingleCompZeroOf c h return t | ((h, c)::t) => do let (iq, h') ← mkSingleCompZeroOf c h let (_, t) ← t.foldlM (fun pr ce ↦ step pr.1 pr.2 ce.1 ce.2) (iq, h') r...
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
mkLTZeroProof
`mkLTZeroProof coeffs pfs` takes a list of proofs of the form `tᵢ Rᵢ 0`, paired with coefficients `cᵢ`. It produces a proof that `∑cᵢ * tᵢ R 0`, where `R` is as strong as possible.
leftOfIneqProof (prf : Expr) : MetaM Expr := do let (_, _, t, _) ← (← inferType prf).ineq? return t
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
leftOfIneqProof
If `prf` is a proof of `t R s`, `leftOfIneqProof prf` returns `t`.
typeOfIneqProof (prf : Expr) : MetaM Expr := do let (_, ty, _) ← (← inferType prf).ineq? return ty
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
typeOfIneqProof
If `prf` is a proof of `t R s`, `typeOfIneqProof prf` returns the type of `t`.
mkNegOneLtZeroProof (tp : Expr) : MetaM Expr := do let zero_lt_one ← mkAppOptM ``Linarith.zero_lt_one #[tp, none, none, none] mkAppM `neg_neg_of_pos #[zero_lt_one]
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
mkNegOneLtZeroProof
`mkNegOneLtZeroProof tp` returns a proof of `-1 < 0`, where the numerals are natively of type `tp`.
addNegEqProofs : List Expr → MetaM (List Expr) | [] => return [] | (h::tl) => do let (iq, t) ← parseCompAndExpr (← inferType h) match iq with | Ineq.eq => do let nep := mkAppN (← mkAppM `Iff.mpr #[← mkAppOptM ``neg_eq_zero #[none, none, t]]) #[h] let tl ← addNegEqProofs tl return h::ne...
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
addNegEqProofs
`addNegEqProofs l` inspects the list of proofs `l` for proofs of the form `t = 0`. For each such proof, it adds a proof of `-t = 0` to the list.
proveEqZeroUsing (tac : TacticM Unit) (e : Expr) : MetaM Expr := do let ⟨u, α, e⟩ ← inferTypeQ' e let _h : Q(Zero $α) ← synthInstanceQ q(Zero $α) synthesizeUsing' q($e = 0) tac /-! #### The main method -/
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
proveEqZeroUsing
`proveEqZeroUsing tac e` tries to use `tac` to construct a proof of `e = 0`.
proveFalseByLinarith (transparency : TransparencyMode) (oracle : CertificateOracle) (discharger : TacticM Unit) : MVarId → List Expr → MetaM Expr | _, [] => throwError "no args to linarith" | g, l@(h::_) => do Lean.Core.checkSystem decl_name%.toString let l' ← detailTrace "addNegEqProofs" <| addNegE...
def
Tactic
[ "Mathlib.Tactic.Linarith.Parsing", "Mathlib.Util.Qq" ]
Mathlib/Tactic/Linarith/Verification.lean
proveFalseByLinarith
`proveFalseByLinarith` is the main workhorse of `linarith`. Given a list `l` of proofs of `tᵢ Rᵢ 0`, it tries to derive a contradiction from `l` and use this to produce a proof of `False`. `oracle : CertificateOracle` is used to search for a certificate of unsatisfiability. The returned certificate is a map `m` from ...
add_eq_eq [Add α] (p₁ : (a₁ : α) = b₁) (p₂ : a₂ = b₂) : a₁ + a₂ = b₁ + b₂ := p₁ ▸ p₂ ▸ rfl
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
add_eq_eq
null
add_le_eq [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] (p₁ : (a₁ : α) ≤ b₁) (p₂ : a₂ = b₂) : a₁ + a₂ ≤ b₁ + b₂ := p₂ ▸ add_le_add_right p₁ b₂
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
add_le_eq
null
add_eq_le [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] (p₁ : (a₁ : α) = b₁) (p₂ : a₂ ≤ b₂) : a₁ + a₂ ≤ b₁ + b₂ := p₁ ▸ add_le_add_left p₂ b₁
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
add_eq_le
null
add_lt_eq [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (p₁ : (a₁ : α) < b₁) (p₂ : a₂ = b₂) : a₁ + a₂ < b₁ + b₂ := p₂ ▸ add_lt_add_right p₁ b₂
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
add_lt_eq
null
add_eq_lt [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] {a₁ b₁ a₂ b₂ : α} (p₁ : a₁ = b₁) (p₂ : a₂ < b₂) : a₁ + a₂ < b₁ + b₂ := p₁ ▸ add_lt_add_left p₂ b₁ /-! ### Multiplication -/
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
add_eq_lt
null
mul_eq_const [Mul α] (p : a = b) (c : α) : a * c = b * c := p ▸ rfl
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_eq_const
null
mul_le_const [Semiring α] [PartialOrder α] [IsOrderedRing α] (p : b ≤ c) {a : α} (ha : 0 ≤ a) : b * a ≤ c * a := mul_le_mul_of_nonneg_right p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_le_const
null
mul_lt_const [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (p : b < c) {a : α} (ha : 0 < a) : b * a < c * a := mul_lt_mul_of_pos_right p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_lt_const
null
mul_lt_const_weak [Semiring α] [PartialOrder α] [IsOrderedRing α] (p : b < c) {a : α} (ha : 0 ≤ a) : b * a ≤ c * a := mul_le_mul_of_nonneg_right p.le ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_lt_const_weak
null
mul_const_eq [Mul α] (p : b = c) (a : α) : a * b = a * c := p ▸ rfl
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_const_eq
null
mul_const_le [Semiring α] [PartialOrder α] [IsOrderedRing α] (p : b ≤ c) {a : α} (ha : 0 ≤ a) : a * b ≤ a * c := mul_le_mul_of_nonneg_left p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_const_le
null
mul_const_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (p : b < c) {a : α} (ha : 0 < a) : a * b < a * c := mul_lt_mul_of_pos_left p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_const_lt
null
mul_const_lt_weak [Semiring α] [PartialOrder α] [IsOrderedRing α] (p : b < c) {a : α} (ha : 0 ≤ a) : a * b ≤ a * c := mul_le_mul_of_nonneg_left p.le ha /-! ### Scalar multiplication -/
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mul_const_lt_weak
null
smul_eq_const [SMul K α] (p : t = s) (c : α) : t • c = s • c := p ▸ rfl
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_eq_const
null
smul_le_const [Ring K] [PartialOrder K] [IsOrderedRing K] [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] [Module K α] [IsOrderedModule K α] (p : t ≤ s) {a : α} (ha : 0 ≤ a) : t • a ≤ s • a := smul_le_smul_of_nonneg_right p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_le_const
null
smul_lt_const [Ring K] [PartialOrder K] [IsOrderedRing K] [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] [Module K α] [IsStrictOrderedModule K α] (p : t < s) {a : α} (ha : 0 < a) : t • a < s • a := smul_lt_smul_of_pos_right p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_lt_const
null
smul_lt_const_weak [Ring K] [PartialOrder K] [IsOrderedRing K] [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] [Module K α] [IsStrictOrderedModule K α] (p : t < s) {a : α} (ha : 0 ≤ a) : t • a ≤ s • a := smul_le_smul_of_nonneg_right p.le ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_lt_const_weak
null
smul_const_eq [SMul K α] (p : b = c) (s : K) : s • b = s • c := p ▸ rfl
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_const_eq
null
smul_const_le [Semiring K] [PartialOrder K] [AddCommMonoid α] [PartialOrder α] [Module K α] [PosSMulMono K α] (p : b ≤ c) {s : K} (hs : 0 ≤ s) : s • b ≤ s • c := smul_le_smul_of_nonneg_left p hs
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_const_le
null
smul_const_lt [Semiring K] [PartialOrder K] [AddCommMonoid α] [PartialOrder α] [Module K α] [PosSMulStrictMono K α] (p : b < c) {s : K} (hs : 0 < s) : s • b < s • c := smul_lt_smul_of_pos_left p hs
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_const_lt
null
smul_const_lt_weak [Semiring K] [PartialOrder K] [AddCommMonoid α] [PartialOrder α] [Module K α] [PosSMulMono K α] (p : b < c) {s : K} (hs : 0 ≤ s) : s • b ≤ s • c := smul_le_smul_of_nonneg_left p.le hs /-! ### Division -/
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smul_const_lt_weak
null
div_eq_const [Div α] (p : a = b) (c : α) : a / c = b / c := p ▸ rfl
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
div_eq_const
null
div_le_const [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] (p : b ≤ c) {a : α} (ha : 0 ≤ a) : b / a ≤ c / a := div_le_div_of_nonneg_right p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
div_le_const
null
div_lt_const [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] (p : b < c) {a : α} (ha : 0 < a) : b / a < c / a := div_lt_div_of_pos_right p ha
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
div_lt_const
null
div_lt_const_weak [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] (p : b < c) {a : α} (ha : 0 ≤ a) : b / a ≤ c / a := div_le_div_of_nonneg_right p.le ha /-! ### Lemmas constructing the reduction of a goal to a specified built-up hypothesis -/
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
div_lt_const_weak
null
eq_of_eq [Add α] [IsRightCancelAdd α] (p : (a : α) = b) (H : a' + b = b' + a) : a' = b' := by rw [p] at H exact add_right_cancel H
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
eq_of_eq
null
le_of_le [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (p : (a : α) ≤ b) (H : a' + b ≤ b' + a) : a' ≤ b' := by rw [← add_le_add_iff_right b] apply H.trans apply add_le_add_left p
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
le_of_le
null
le_of_eq [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (p : (a : α) = b) (H : a' + b ≤ b' + a) : a' ≤ b' := by rwa [p, add_le_add_iff_right] at H
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
le_of_eq
null
le_of_lt [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (p : (a : α) < b) (H : a' + b ≤ b' + a) : a' ≤ b' := le_of_le p.le H
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
le_of_lt
null
lt_of_le [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (p : (a : α) ≤ b) (H : a' + b < b' + a) : a' < b' := by rw [← add_lt_add_iff_right b] apply H.trans_le apply add_le_add_left p
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
lt_of_le
null
lt_of_eq [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (p : (a : α) = b) (H : a' + b < b' + a) : a' < b' := by rwa [p, add_lt_add_iff_right] at H
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
lt_of_eq
null
lt_of_lt [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] (p : (a : α) < b) (H : a' + b ≤ b' + a) : a' < b' := by rw [← add_lt_add_iff_right b] apply H.trans_lt apply add_lt_add_left p alias ⟨eq_rearrange, _⟩ := sub_eq_zero
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
lt_of_lt
null
le_rearrange {α : Type*} [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] {a b : α} (h : a - b ≤ 0) : a ≤ b := sub_nonpos.mp h
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
le_rearrange
null
lt_rearrange {α : Type*} [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] {a b : α} (h : a - b < 0) : a < b := sub_neg.mp h
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
lt_rearrange
null
eq_of_add_pow [Ring α] [NoZeroDivisors α] (n : ℕ) (p : (a : α) = b) (H : (a' - b') ^ n - (a - b) = 0) : a' = b' := by rw [← sub_eq_zero] at p ⊢; apply pow_eq_zero (n := n); rwa [sub_eq_zero, p] at H
theorem
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
eq_of_add_pow
null
addRelRelData : Ineq → Ineq → Name | eq, eq => ``add_eq_eq | eq, le => ``add_eq_le | eq, lt => ``add_eq_lt | le, eq => ``add_le_eq | le, le => ``add_le_add | le, lt => ``add_lt_add_of_le_of_lt | lt, eq => ``add_lt_eq | lt, le => ``add_lt_add_of_lt_of_le | lt, lt => ``add_lt_add
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
addRelRelData
Given two (in)equalities, look up the lemma to add them.
protected WithStrictness : Type | eq : Ineq.WithStrictness | le : Ineq.WithStrictness | lt (strict : Bool) : Ineq.WithStrictness
inductive
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
WithStrictness
Finite inductive type extending `Mathlib.Ineq`: a type of inequality (`eq`, `le` or `lt`), together with, in the case of `lt`, a Boolean, typically representing the strictness (< or ≤) of some other inequality.
mulRelConstData : Ineq.WithStrictness → Name | .eq => ``mul_eq_const | .le => ``mul_le_const | .lt true => ``mul_lt_const | .lt false => ``mul_lt_const_weak
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mulRelConstData
Given an (in)equality, look up the lemma to left-multiply it by a constant. If relevant, also take into account the degree of positivity which can be proved of the constant: strict or non-strict.
mulConstRelData : Ineq.WithStrictness → Name | .eq => ``mul_const_eq | .le => ``mul_const_le | .lt true => ``mul_const_lt | .lt false => ``mul_const_lt_weak
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
mulConstRelData
Given an (in)equality, look up the lemma to right-multiply it by a constant. If relevant, also take into account the degree of positivity which can be proved of the constant: strict or non-strict.
smulRelConstData : Ineq.WithStrictness → Name | .eq => ``smul_eq_const | .le => ``smul_le_const | .lt true => ``smul_lt_const | .lt false => ``smul_lt_const_weak
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smulRelConstData
Given an (in)equality, look up the lemma to left-scalar-multiply it by a constant (scalar). If relevant, also take into account the degree of positivity which can be proved of the constant: strict or non-strict.
smulConstRelData : Ineq.WithStrictness → Name | .eq => ``smul_const_eq | .le => ``smul_const_le | .lt true => ``smul_const_lt | .lt false => ``smul_const_lt_weak
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
smulConstRelData
Given an (in)equality, look up the lemma to right-scalar-multiply it by a constant (vector). If relevant, also take into account the degree of positivity which can be proved of the constant: strict or non-strict.
divRelConstData : Ineq.WithStrictness → Name | .eq => ``div_eq_const | .le => ``div_le_const | .lt true => ``div_lt_const | .lt false => ``div_lt_const_weak
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
divRelConstData
Given an (in)equality, look up the lemma to divide it by a constant. If relevant, also take into account the degree of positivity which can be proved of the constant: strict or non-strict.
relImpRelData : Ineq → Ineq → Option (Name × Ineq) | eq, eq => some (``eq_of_eq, eq) | eq, le => some (``Tactic.LinearCombination.le_of_eq, le) | eq, lt => some (``lt_of_eq, lt) | le, eq => none | le, le => some (``le_of_le, le) | le, lt => some (``lt_of_le, lt) | lt, eq => none | lt, le => some (``Tact...
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
relImpRelData
Given two (in)equalities `P` and `Q`, look up the lemma to deduce `Q` from `P`, and the relation appearing in the side condition produced by this lemma.
rearrangeData : Ineq → Name | eq => ``eq_rearrange | le => ``le_rearrange | lt => ``lt_rearrange
def
Tactic
[ "Mathlib.Algebra.Field.Defs", "Mathlib.Algebra.Order.Module.Defs", "Mathlib.Data.Ineq" ]
Mathlib/Tactic/LinearCombination/Lemmas.lean
rearrangeData
Given an (in)equality, look up the lemma to move everything to the LHS.
CommandStart.endPos (stx : Syntax) : Option String.Pos := if let some cmd := stx.find? (#[``Parser.Command.declaration, `lemma].contains ·.getKind) then if let some ind := cmd.find? (·.isOfKind ``Parser.Command.inductive) then match ind.find? (·.isOfKind ``Parser.Command.optDeclSig) with | none => dbg...
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
CommandStart.endPos
The `commandStart` linter emits a warning if * either a command does not start at the beginning of a line; * or the "hypotheses segment" of a declaration does not coincide with its pretty-printed version. In practice, this makes sure that the spacing in a typical declaration looks like ```lean example (a : Nat) {R : T...
mkFormatError (ls ms : String) (msg : String) (length : Nat := 1) : FormatError where srcNat := ls.length srcEndPos := ls.endPos fmtPos := ms.length msg := msg length := length srcStartPos := ls.endPos
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
mkFormatError
A `FormatError` is the main structure tracking how some surface syntax differs from its pretty-printed version. In case of deviations, it contains the deviation's location within an ambient string. -/ -- Some of the information contained in `FormatError` is redundant, however, it is useful to convert -- between the `S...
pushFormatError (fs : Array FormatError) (f : FormatError) : Array FormatError := if fs.isEmpty then fs.push f else let back := fs.back! if back.msg != f.msg || back.srcNat - back.length != f.srcNat then fs.push f else fs.pop.push {back with length := back.length + f.length, srcStartPos := f.srcEndPos}
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
pushFormatError
Add a new `FormatError` `f` to the array `fs`, trying, as much as possible, to merge the new `FormatError` with the last entry of `fs`.
partial parallelScanAux (as : Array FormatError) (L M : String) : Array FormatError := if M.trim.isEmpty then as else if L.take 3 == "/--" && M.take 3 == "/--" then parallelScanAux as (L.drop 3) (M.drop 3) else if L.take 2 == "--" then let newL := L.dropWhile (· != '\n') let diff := L.length - newL.le...
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
parallelScanAux
Scan the two input strings `L` and `M`, assuming `M` is the pretty-printed version of `L`. This almost means that `L` and `M` only differ in whitespace. While scanning the two strings, accumulate any discrepancies --- with some heuristics to avoid flagging some line-breaking changes. (The pretty-printer does not alway...
parallelScan (src fmt : String) : Array FormatError := parallelScanAux ∅ src fmt
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
parallelScan
null
unlintedNodes := #[ ``«term{_:_//_}», `«term{_}», ``«term{}», `Mathlib.Meta.setBuilder, `str, ``«term_::_», ``«term¬_», ``Parser.Command.declId, `Mathlib.Tactic.superscriptTerm, `Mathlib.Tactic.subscript, `Bundle.termπ__, `Finset.«term_#_», ``Parser.Command.docComment, ``Parser.Term.doubleQuot...
abbrev
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
unlintedNodes
`unlintedNodes` contains the `SyntaxNodeKind`s for which there is no clear formatting preference: if they appear in surface syntax, the linter will ignore formatting. Currently, the unlined nodes are mostly related to `Subtype`, `Set` and `Finset` notation and list notation.
getUnlintedRanges (a : Array SyntaxNodeKind) : Std.HashSet String.Range → Syntax → Std.HashSet String.Range | curr, s@(.node _ kind args) => let new := args.foldl (init := curr) (·.union <| getUnlintedRanges a curr ·) if a.contains kind then new.insert (s.getRange?.getD default) else new ...
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
getUnlintedRanges
Given an array `a` of `SyntaxNodeKind`s, we accumulate the ranges of the syntax nodes of the input syntax whose kind is in `a`. The linter uses this information to avoid emitting a warning for nodes with kind contained in `unlintedNodes`.
isOutside (rgs : Std.HashSet String.Range) (rg : String.Range) : Bool := rgs.all fun {start := a, stop := b} ↦ !(a ≤ rg.start && rg.stop ≤ b)
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
isOutside
Given a `HashSet` of `String.Range`s `rgs` and a further `String.Range` `rg`, `isOutside rgs rg` returns `false` if and only if `rgs` contains a range that completely contains `rg`. The linter uses this to figure out which nodes should be ignored.
mkWindow (orig : String) (start ctx : Nat) : String := let head := orig.dropRight (start + 1) -- `orig`, up to one character before the discrepancy let middle := orig.takeRight (start + 1) let headCtx := head.takeRightWhile (!·.isWhitespace) let tail := middle.drop ctx |>.takeWhile (!·.isWhitespace) s!"{headC...
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
mkWindow
`mkWindow orig start ctx` extracts from `orig` a string that starts at the first non-whitespace character before `start`, then expands to cover `ctx` more characters and continues still until the first non-whitespace character. In essence, it extracts the substring of `orig` that begins at `start`, continues for `ctx`...
commandStartLinter : Linter where run := withSetOptionIn fun stx ↦ do unless Linter.getLinterValue linter.style.commandStart (← getLinterOptions) do return if (← get).messages.hasErrors then return if stx.find? (·.isOfKind ``runCmd) |>.isSome then return if let some pos := stx.getPos? then let c...
def
Tactic
[ "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/CommandStart.lean
commandStartLinter
null
addModuleDeprecation {m : Type → Type} [Monad m] [MonadEnv m] (msg? : Option String) : m Unit := do let modName ← getMainModule modifyEnv (deprecatedModuleExt.addEntry · (modName, (← getEnv).imports.filterMap fun i ↦ if i.module == `Init || i.module == `Mathlib.Tactic.Linter.DeprecatedModule ...
def
Tactic
[ "Std.Time.Format", "Mathlib.Init" ]
Mathlib/Tactic/Linter/DeprecatedModule.lean
addModuleDeprecation
The `deprecated.module` linter emits a warning when a file that has been renamed or split is imported. The default value is `true`, since this linter is designed to warn projects downstream of `Mathlib` of refactors and deprecations in `Mathlib` itself. -/ register_option linter.deprecated.module : Bool := { defValue...
@[inherit_doc Mathlib.Linter.linter.deprecated.module] deprecated.moduleLinter : Linter where run := withSetOptionIn fun stx ↦ do unless getLinterValue linter.deprecated.module (← getLinterOptions) do return if (← get).messages.hasErrors then return let laterCommand ← IsLaterCommand.get if laterCommand ...
def
Tactic
[ "Std.Time.Format", "Mathlib.Init" ]
Mathlib/Tactic/Linter/DeprecatedModule.lean
deprecated.moduleLinter
null
getSetOptionMaxHeartbeatsComment : Syntax → Option (Name × Nat × Substring) | stx@`(command|set_option $mh $n:num in $_) => let opt := mh.getId if !opt.components.contains `maxHeartbeats then none else if let some inAtom := stx.find? (·.getAtomVal == "in") then inAtom.getTrailing?.map ...
def
Tactic
[ "Lean.Elab.Command", "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/DeprecatedSyntaxLinter.lean
getSetOptionMaxHeartbeatsComment
The option `linter.style.refine` of the deprecated syntax linter flags usages of the `refine'` tactic. The tactics `refine`, `apply` and `refine'` are similar, but they handle metavariables slightly differently. This means that they are not completely interchangeable, nor can one completely replace another. However, `...
isDecideNative (stx : Syntax ) : Bool := match stx with | .node _ ``Lean.Parser.Tactic.decide args => let config := args[1]![0] if let (.node _ _ config_args) := config then let natives := config_args.filterMap (match ·[0] with | `(Parser.Tactic.posConfigItem| +native) => some true | `...
def
Tactic
[ "Lean.Elab.Command", "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/DeprecatedSyntaxLinter.lean
isDecideNative
Whether a given piece of syntax represents a `decide` tactic call with the `native` option enabled. This may have false negatives for `decide (config := {<options>})` syntax).
partial getDeprecatedSyntax : Syntax → Array (SyntaxNodeKind × Syntax × MessageData) | stx@(.node _ kind args) => let rargs := args.flatMap getDeprecatedSyntax match kind with | ``Lean.Parser.Tactic.refine' => rargs.push (kind, stx, "The `refine'` tactic is discouraged: \ please str...
def
Tactic
[ "Lean.Elab.Command", "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/DeprecatedSyntaxLinter.lean
getDeprecatedSyntax
`getDeprecatedSyntax t` returns all usages of deprecated syntax in the input syntax `t`.
deprecatedSyntaxLinter : Linter where run stx := do unless getLinterValue linter.style.refine (← getLinterOptions) || getLinterValue linter.style.cases (← getLinterOptions) || getLinterValue linter.style.induction (← getLinterOptions) || getLinterValue linter.style.admit (← getLinterOptions) || ...
def
Tactic
[ "Lean.Elab.Command", "Mathlib.Tactic.Linter.Header" ]
Mathlib/Tactic/Linter/DeprecatedSyntaxLinter.lean
deprecatedSyntaxLinter
The deprecated syntax linter flags usages of deprecated syntax and suggests replacement syntax. For each individual case, linting can be turned on or off separately. * `refine'`, superseded by `refine` and `apply` (controlled by `linter.style.refine`) * `cases'`, superseded by `obtain`, `rcases` and `cases` (controlle...
findImports (path : System.FilePath) : IO (Array Lean.Name) := do return (← Lean.parseImports' (← IO.FS.readFile path) path.toString).imports |>.map (fun imp ↦ imp.module) |>.erase `Init
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
findImports
Parse all imports in a text file at `path` and return just their names: this is just a thin wrapper around `Lean.parseImports'`. Omit `Init` (which is part of the prelude).
Lean.Name.findPrefix {α} (f : Name → Option α) (n : Name) : Option α := do f n <|> match n with | anonymous => none | str n' _ => n'.findPrefix f | num n' _ => n'.findPrefix f
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
Lean.Name.findPrefix
Find the longest prefix of `n` such that `f` returns `some` (or return `none` otherwise).
Lean.Name.prefixes (n : Name) : NameSet := NameSet.insert (n := n) <| match n with | anonymous => ∅ | str n' _ => n'.prefixes | num n' _ => n'.prefixes
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
Lean.Name.prefixes
Make a `NameSet` containing all prefixes of `n`.
Lean.Name.prefix? (n : Name) : Option Name := match n with | anonymous => none | str n' _ => some n' | num n' _ => some n'
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
Lean.Name.prefix
Return the immediate prefix of `n` (if any).
Lean.Name.collectPrefixes (ns : Array Name) : NameSet := ns.foldl (fun ns n => ns.append n.prefixes) ∅
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
Lean.Name.collectPrefixes
Collect all prefixes of names in `ns` into a single `NameSet`.
Lean.Name.prefixToName (p : Name) (ns : Array Name) : Option Name := ns.find? p.isPrefixOf
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
Lean.Name.prefixToName
Find a name in `ns` that starts with prefix `p`.
Lean.Environment.importPath (env : Environment) (imported : Name) : Array Name := Id.run do let mut result := #[] let modData := env.header.moduleData let modNames := env.header.moduleNames if let some idx := env.getModuleIdx? imported then let mut target := imported for i in [idx.toNat + 1 : modData.si...
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
Lean.Environment.importPath
Find the dependency chain, starting at a module that imports `imported`, and ends with the current module. The path only contains the intermediate steps: it excludes `imported` and the current module.
NamePrefixRel := NameMap NameSet
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
NamePrefixRel
The `directoryDependency` linter detects detects imports between directories that are supposed to be independent. If this is the case, it emits a warning. -/ register_option linter.directoryDependency : Bool := { defValue := true descr := "enable the directoryDependency linter" } namespace DirectoryDependency /--...
insert (r : NamePrefixRel) (n₁ n₂ : Name) : NamePrefixRel := match r.find? n₁ with | some ns => NameMap.insert r n₁ (ns.insert n₂) | none => NameMap.insert r n₁ (.insert ∅ n₂)
def
Tactic
[ "Lean.Elab.Command", "Lean.Elab.ParseImportsFast" ]
Mathlib/Tactic/Linter/DirectoryDependency.lean
insert
Make all names with prefix `n₁` related to names with prefix `n₂`.