Mathlib provides a suite of arithmetic tactics that act as decision procedures for numeric goals. Rather than constructing explicit proof terms about inequalities, equalities, or numeric computations, these tactics analyze the algebraic structure of the goal and automatically discharge it. Together they cover linear and nonlinear arithmetic, ring identities, numeric evaluation, additive group equalities, and field simplification.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/leanprover-community/mathlib4/llms.txt
Use this file to discover all available pages before exploring further.
linarith
linarith attempts to find a contradiction between hypotheses that are linear (in)equalities, or equivalently proves a linear inequality by assuming its negation and deriving False. It works over any type that instantiates CommRing, LinearOrder, and IsStrictOrderedRing, including the concrete types ℕ, ℤ, ℚ, and ℝ.
The tactic collects all linear hypotheses of the form a R b (where R ∈ {<, ≤, =, ≥, >}), rearranges them into the form tᵢ Rᵢ 0, and then uses a Simplex Algorithm oracle to find natural-number coefficients kᵢ witnessing unsatisfiability.
- Basic usage
- Extra hints
- Configuration
linarith is not complete for ℕ and ℤ (non-dense orders). For goals involving integer division or modular arithmetic, use omega instead.How linarith works internally
How linarith works internally
linarith uses the Simplex Algorithm (sparse mode by default) as its oracle. It rearranges all linear hypotheses into the form tᵢ Rᵢ 0 and searches for natural-number coefficients kᵢ such that ∑ kᵢ tᵢ = 0, where for at least one i, kᵢ > 0 and Rᵢ = < (a strict inequality). Once a certificate is found, it is verified by the ring tactic. You can switch to the Fourier-Motzkin oracle with linarith (oracle := .fourierMotzkin), or to the dense Simplex variant with linarith (oracle := .simplexAlgorithmDense).Trace intermediate steps with set_option trace.linarith true.nlinarith
nlinarith extends linarith with a preprocessing step that handles some nonlinear arithmetic goals. Before calling the linear oracle, it adds auxiliary hypotheses derived from products of existing hypotheses.
Specifically, for every subterm a ^ 2 or a * a appearing in the hypotheses, it adds a proof of 0 ≤ a ^ 2 (via sq_nonneg) or 0 ≤ a * a (via mul_self_nonneg). For every pair of hypotheses t₁ R₁ 0 and t₂ R₂ 0 (in rearranged form), it adds a proof of t₁ * t₂ R 0. This often suffices to reduce a nonlinear goal to a linear one.
linarith):
norm_num
norm_num is a verified normalizer for numeric expressions. It can evaluate arithmetic expressions, test primality, check divisibility, compute with rational numbers, and handle square roots and modular arithmetic. It works by reducing numeric goals to kernel-checkable computations.
- Numeric goals
- Primality
- Variants
ring and ring_nf
ring proves equalities that hold in any commutative (semi)ring by normalizing both sides to a canonical polynomial form and checking syntactic equality. It handles +, -, *, ^ (with natural-number exponents), and numeric literals.
ring_nf applies the same normalization without requiring the goal to be a closed equality — it rewrites the expression into normal form and leaves any remaining goals for other tactics.
- ring
- ring_nf
- ring!
abel
abel solves equations in additive commutative monoids and groups. It is analogous to ring but restricted to the + operation, which means it works on types that are additive commutative groups but not full rings — for example, free abelian groups, ZMod n, or abstract AddCommGroup instances.
abel and its variants also work as conv tactics.
omega
omega is a complete decision procedure for linear arithmetic over ℕ and ℤ. Unlike linarith, it handles integer division (/) and modular arithmetic (%), making it the right choice for goals about natural number or integer computations.
field_simp
field_simp simplifies expressions in a field (or more generally a DivisionRing) by clearing all denominators and applying simp lemmas about division. It is most useful as a preprocessing step before ring for goals involving /.
field_simp requires non-zeroness hypotheses to be in the local context (or passed explicitly with field_simp [h1, h2]). It uses ne_of_gt and similar lemmas automatically when it can find them.