statement stringlengths 1 2.88k | proof stringlengths 0 13.9k | type stringclasses 10
values | symbolic_name stringlengths 1 131 | library stringclasses 417
values | filename stringlengths 17 80 | imports listlengths 0 16 | deps listlengths 0 64 | docstring stringlengths 0 10.2k | source_url stringclasses 1
value | commit stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|
make_comp_with_zero : preprocessor | { name := "make comparisons with zero",
transform := λ e, singleton <$> rearr_comp e <|> return [] } | def | linarith.make_comp_with_zero | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [] | `mk_comp_with_zero 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 ∈ {=, ≤, <}`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
normalize_denominators_in_lhs (h lhs : expr) : tactic expr | do (v, lhs') ← cancel_factors.derive lhs,
if v = 1 then return h else do
(ih, h'') ← mk_single_comp_zero_pf v h,
(_, nep, _) ← infer_type h'' >>= rewrite_core lhs',
mk_eq_mp nep h'' | def | linarith.normalize_denominators_in_lhs | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [
"cancel_factors.derive",
"ih"
] | `normalize_denominators_in_lhs 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. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
cancel_denoms : preprocessor | { name := "cancel denominators",
transform := λ pf,
(do some (_, lhs) ← parse_into_comp_and_expr <$> (infer_type pf >>= instantiate_mvars),
guardb $ lhs.contains_constant (= `has_div.div),
singleton <$> normalize_denominators_in_lhs pf lhs)
<|> return [pf] } | def | linarith.cancel_denoms | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [] | `cancel_denoms 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. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
find_squares : rb_set (expr × bool) → expr → tactic (rb_set $ expr ×ₗ bool) | | s `(%%a ^ 2) := do s ← find_squares s a, return (s.insert (a, tt))
| s e@`(%%e1 * %%e2) := if e1 = e2 then do s ← find_squares s e1, return (s.insert (e1, ff)) else
e.mfoldl find_squares s
| s e := e.mfoldl find_squares s | def | linarith.find_squares | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [] | `find_squares m e` collects all terms of the form `a ^ 2` and `a * a` that appear in `e`
and adds them to the set `m`.
A pair `(a, tt)` is added to `m` when `a^2` appears in `e`, and `(a, ff)` is added to `m`
when `a*a` appears in `e`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nlinarith_extras : global_preprocessor | { name := "nonlinear arithmetic extras",
transform := λ ls,
do s ← ls.mfoldr (λ h s', infer_type h >>= find_squares s') mk_rb_set,
new_es ← s.mfold ([] : list expr) $ λ ⟨e, is_sq⟩ new_es,
((do p ← mk_app (if is_sq then ``sq_nonneg else ``mul_self_nonneg) [e],
return $ p::new_es) <|> return new_es),
... | def | linarith.nlinarith_extras | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [
"mul_nonneg_of_nonpos_of_nonpos",
"mul_pos_of_neg_of_neg",
"mul_self_nonneg",
"sq_nonneg"
] | `nlinarith_extras` 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, a... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
remove_ne_aux : list expr → tactic (list branch) | λ hs,
(do e ← hs.mfind (λ e : expr, do e ← infer_type e >>= instantiate_mvars, guard $ e.is_ne.is_some),
[(_, ng1), (_, ng2)] ← to_expr ``(or.elim (lt_or_gt_of_ne %%e)) >>= apply,
let do_goal : expr → tactic (list branch) := λ g,
do set_goals [g],
h ← intro1,
ls ← remove_ne_aux $ hs.remo... | def | linarith.remove_ne_aux | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [] | `remove_ne_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. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
remove_ne : global_branching_preprocessor | { name := "remove_ne",
transform := remove_ne_aux } | def | linarith.remove_ne | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [] | `remove_ne` case splits on any proof `h : a ≠ b` in the input, turning it into `a < b ∨ a > b`,
by calling `linarith.remove_ne_aux`.
This produces `2^n` branches when there are `n` such hypotheses in the input. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
default_preprocessors : list global_branching_preprocessor | [filter_comparisons, remove_negations, nat_to_int, strengthen_strict_int,
make_comp_with_zero, cancel_denoms] | def | linarith.default_preprocessors | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [] | The default list of preprocessors, in the order they should typically run. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
preprocess (pps : list global_branching_preprocessor) (l : list expr) :
tactic (list branch) | do g ← get_goal,
pps.mfoldl (λ ls pp,
list.join <$> (ls.mmap $ λ b, set_goals [b.1] >> pp.process b.2))
[(g, l)] | def | linarith.preprocess | tactic.linarith | src/tactic/linarith/preprocessing.lean | [
"data.prod.lex",
"tactic.cancel_denoms",
"tactic.linarith.datatypes",
"tactic.zify"
] | [] | `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 recieves 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... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mul_expr (n : ℕ) (e : expr) : pexpr | if n = 1 then ``(%%e) else
``(%%(nat.to_pexpr n) * %%e) | def | linarith.mul_expr | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | `mul_expr n e` creates a `pexpr` representing `n*e`.
When elaborated, the coefficient will be a native numeral of the same type as `e`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_exprs_aux : pexpr → list pexpr → pexpr | | p [] := p
| p [a] := ``(%%p + %%a)
| p (h::t) := add_exprs_aux ``(%%p + %%h) t | def | linarith.add_exprs_aux | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
add_exprs : list pexpr → pexpr | | [] := ``(0)
| (h::t) := add_exprs_aux h t | def | linarith.add_exprs | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | `add_exprs l` creates a `pexpr` representing the sum of the elements of `l`, associated left.
If `l` is empty, it will be the `pexpr` 0. Otherwise, it does not include 0 in the sum. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ineq_const_nm : ineq → ineq → (name × ineq) | | eq eq := (``eq_of_eq_of_eq, eq)
| eq le := (``le_of_eq_of_le, le)
| eq lt := (``lt_of_eq_of_lt, lt)
| le eq := (``le_of_le_of_eq, le)
| le le := (`add_nonpos, le)
| le lt := (`add_lt_of_le_of_neg, lt)
| lt eq := (``lt_of_lt_of_eq, lt)
| lt le := (`add_lt_of_neg_of_le, lt)
| lt lt := (`left.add_neg, lt) | def | linarith.ineq_const_nm | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [
"le_of_eq_of_le",
"le_of_le_of_eq",
"lt_of_eq_of_lt",
"lt_of_lt_of_eq"
] | If our goal is to add together two inequalities `t1 R1 0` and `t2 R2 0`,
`ineq_const_nm 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`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_lt_zero_pf_aux (c : ineq) (pf npf : expr) (coeff : ℕ) : tactic (ineq × expr) | do (iq, h') ← mk_single_comp_zero_pf coeff npf,
let (nm, niq) := ineq_const_nm c iq,
prod.mk niq <$> mk_app nm [pf, h'] | def | linarith.mk_lt_zero_pf_aux | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | `mk_lt_zero_pf_aux c pf npf coeff` assumes that `pf` is a proof of `t1 R1 0` and `npf` is a proof
of `t2 R2 0`. It uses `mk_single_comp_zero_pf` to prove `t1 + coeff*t2 R 0`, and returns `R`
along with this proof. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_lt_zero_pf : list (expr × ℕ) → tactic expr | | [] := fail "no linear hypotheses found"
| [(h, c)] := prod.snd <$> mk_single_comp_zero_pf c h
| ((h, c)::t) :=
do (iq, h') ← mk_single_comp_zero_pf c h,
prod.snd <$> t.mfoldl (λ pr ce, mk_lt_zero_pf_aux pr.1 pr.2 ce.1 ce.2) (iq, h') | def | linarith.mk_lt_zero_pf | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | `mk_lt_zero_pf 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. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
term_of_ineq_prf (prf : expr) : tactic expr | prod.fst <$> (infer_type prf >>= instantiate_mvars >>= get_rel_sides) | def | linarith.term_of_ineq_prf | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | If `prf` is a proof of `t R s`, `term_of_ineq_prf prf` returns `t`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ineq_prf_tp (prf : expr) : tactic expr | term_of_ineq_prf prf >>= infer_type >>= instantiate_mvars | def | linarith.ineq_prf_tp | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | If `prf` is a proof of `t R s`, `ineq_prf_tp prf` returns the type of `t`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_neg_one_lt_zero_pf (tp : expr) : tactic expr | do h ← mk_mapp `linarith.zero_lt_one [tp, none, none],
mk_app `neg_neg_of_pos [h] | def | linarith.mk_neg_one_lt_zero_pf | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [
"linarith.zero_lt_one"
] | `mk_neg_one_lt_zero_pf tp` returns a proof of `-1 < 0`,
where the numerals are natively of type `tp`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_neg_eq_zero_pf (e : expr) : tactic expr | to_expr ``(neg_eq_zero.mpr %%e) | def | linarith.mk_neg_eq_zero_pf | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | If `e` is a proof that `t = 0`, `mk_neg_eq_zero_pf e` returns a proof that `-t = 0`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
prove_eq_zero_using (tac : tactic unit) (e : expr) : tactic expr | do tgt ← to_expr ``(%%e = 0),
prod.snd <$> solve_aux tgt (tac >> done) | def | linarith.prove_eq_zero_using | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | `prove_eq_zero_using tac e` tries to use `tac` to construct a proof of `e = 0`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_neg_eq_pfs : list expr → tactic (list expr) | | [] := return []
| (h::t) :=
do some (iq, tp) ← parse_into_comp_and_expr <$> (infer_type h >>= instantiate_mvars),
match iq with
| ineq.eq := do nep ← mk_neg_eq_zero_pf h, tl ← add_neg_eq_pfs t, return $ h::nep::tl
| _ := list.cons h <$> add_neg_eq_pfs t
end | def | linarith.add_neg_eq_pfs | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | `add_neg_eq_pfs 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. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
prove_false_by_linarith (cfg : linarith_config) : list expr → tactic expr | | [] := fail "no args to linarith"
| l@(h::t) := do
-- for the elimination to work properly, we must add a proof of `-1 < 0` to the list,
-- along with negated equality proofs.
l' ← add_neg_eq_pfs l,
hz ← ineq_prf_tp h >>= mk_neg_one_lt_zero_pf,
let inputs := hz::l',
-- perform the elimination a... | def | linarith.prove_false_by_linarith | tactic.linarith | src/tactic/linarith/verification.lean | [
"tactic.linarith.elimination",
"tactic.linarith.parsing"
] | [] | `prove_false_by_linarith` 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`.
An oracle is used to search for a certificate of unsatisfiability.
In the current implementation, this is the Fourier Motzkin e... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nolint_attr : user_attribute (name_map (list name)) (list name) | { name := "nolint",
descr := "Do not report this declaration in any of the tests of `#lint`",
after_set := some $ λ n _ _, (do
ls@(_::_) ← parse_name_list <$> nolint_attr.get_param_untyped n
| fail "you need to specify at least one linter to disable",
skip),
cache_cfg :=
{ dependencies := [],
... | def | nolint_attr | tactic.lint | src/tactic/lint/basic.lean | [
"tactic.core"
] | [
"parse_name_list"
] | Defines the user attribute `nolint` for skipping `#lint` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
should_be_linted (linter : name) (decl : name) : tactic bool | do
c ← nolint_attr.get_cache,
pure $ linter ∉ (c.find decl).get_or_else [] | def | should_be_linted | tactic.lint | src/tactic/lint/basic.lean | [
"tactic.core"
] | [
"linter"
] | `should_be_linted linter decl` returns true if `decl` should be checked
using `linter`, i.e., if there is no `nolint` attribute. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter | (test : declaration → tactic (option string))
(no_errors_found : string)
(errors_found : string)
(is_fast : bool := tt)
(auto_decls : bool) | structure | linter | tactic.lint | src/tactic/lint/basic.lean | [
"tactic.core"
] | [] | A linting test for the `#lint` command.
`test` defines a test to perform on every declaration. It should never fail. Returning `none`
signifies a passing test. Returning `some msg` reports a failing test with error `msg`.
`no_errors_found` is the message printed when all tests are negative, and `errors_found` is prin... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_linters (l : list name) : tactic (list (name × linter)) | l.mmap (λ n, prod.mk n.last <$> (mk_const n >>= eval_expr linter)
<|> fail format!"invalid linter: {n}") | def | get_linters | tactic.lint | src/tactic/lint/basic.lean | [
"tactic.core"
] | [
"linter"
] | Takes a list of names that resolve to declarations of type `linter`,
and produces a list of linters. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter_attr : user_attribute unit unit | { name := "linter",
descr := "Use this declaration as a linting test in #lint",
after_set := some $ λ nm _ _,
mk_const nm >>= infer_type >>= unify `(linter) } | def | linter_attr | tactic.lint | src/tactic/lint/basic.lean | [
"tactic.core"
] | [] | Defines the user attribute `linter` for adding a linter to the default set.
Linters should be defined in the `linter` namespace.
A linter `linter.my_new_linter` is referred to as `my_new_linter` (without the `linter` namespace)
when used in `#lint`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mathlib_linters : list name | by do
ls ← get_checks tt [] ff,
let ls := ls.map (λ ⟨n, _⟩, `linter ++ n) ++
[`assert_not_exists.linter, `assert_no_instance.linter],
exact (reflect ls) | def | mathlib_linters | tactic.lint | src/tactic/lint/default.lean | [
"tactic.to_additive",
"tactic.lint.frontend",
"tactic.lint.misc",
"tactic.lint.simp",
"tactic.lint.type_classes"
] | [
"assert_no_instance.linter",
"assert_not_exists.linter",
"get_checks",
"linter"
] | The default linters used in mathlib CI. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_verbosity | low | medium | high | inductive | lint_verbosity | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [] | Verbosity for the linter output.
* `low`: only print failing checks, print nothing on success.
* `medium`: only print failing checks, print confirmation on success.
* `high`: print output of every check. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_checks (slow : bool) (extra : list name) (use_only : bool) :
tactic (list (name × linter)) | do
default ← if use_only then return [] else attribute.get_instances `linter >>= get_linters,
let default := if slow then default else default.filter (λ l, l.2.is_fast),
list.append default <$> get_linters extra | def | get_checks | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"get_linters",
"linter"
] | `get_checks slow extra use_only` produces a list of linters.
`extras` is a list of names that should resolve to declarations with type `linter`.
If `use_only` is true, it only uses the linters in `extra`.
Otherwise, it uses all linters in the environment tagged with `@[linter]`.
If `slow` is false, it only uses the fas... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_core (all_decls non_auto_decls : list declaration) (checks : list (name × linter)) :
tactic (list (name × linter × rb_map name string)) | do
checks.mmap $ λ ⟨linter_name, linter⟩, do
let test_decls := if linter.auto_decls then all_decls else non_auto_decls,
test_decls ← test_decls.mfilter (λ decl, should_be_linted linter_name decl.to_name),
s ← read,
let results := test_decls.map_async_chunked $ λ decl, prod.mk decl.to_name $
match linter.t... | def | lint_core | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"linter",
"should_be_linted"
] | `lint_core all_decls non_auto_decls checks` applies the linters `checks` to the list of
declarations.
If `auto_decls` is false for a linter (default) the linter is applied to `non_auto_decls`.
If `auto_decls` is true, then it is applied to `all_decls`.
The resulting list has one element for each linter, containing the ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sort_results {α} (e : environment) (results : rb_map name α) : list (name × α) | list.reverse $ rb_lmap.values $ rb_lmap.of_list $
results.fold [] $ λ decl linter_warning results,
(((e.decl_pos decl).get_or_else ⟨0,0⟩).line, (decl, linter_warning)) :: results | def | sort_results | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [] | Sorts a map with declaration keys as names by line number. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
print_warning (decl_name : name) (warning : string) : format | "#check @" ++ to_fmt decl_name ++ " /- " ++ warning ++ " -/" | def | print_warning | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [] | Formats a linter warning as `#check` command with comment. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
workflow_command_replacements : char → string | | '%' := "%25"
| '\n' := "%0A"
| c := to_string c | def | workflow_command_replacements | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
escape_workflow_command (s : string) : string | "".intercalate $ s.to_list.map workflow_command_replacements | def | escape_workflow_command | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"workflow_command_replacements"
] | Escape characters that may not be used in a workflow commands, following
https://github.com/actions/toolkit/blob/7257597d731b34d14090db516d9ea53439300e98/packages/core/src/command.ts#L92-L105 | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
print_workflow_command (env : environment) (linter_name decl_name : name)
(warning : string) : option string | do
po ← env.decl_pos decl_name,
ol ← env.decl_olean decl_name,
return $ sformat!"\n::error file={ol},line={po.line},col={po.column},title=" ++
sformat!"Warning from {linter_name} linter::" ++
sformat!"{escape_workflow_command $ to_string decl_name} - {escape_workflow_command warning}" | def | print_workflow_command | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [] | Prints a workflow command to emit an error understood by github in an actions workflow.
This enables CI to tag the parts of the file where linting failed with annotations, and makes it
easier for mathlib contributors to see what needs fixing.
See https://docs.github.com/en/actions/learn-github-actions/workflow-commands... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
print_warnings (env : environment) (emit_workflow_commands : bool) (linter_name : name)
(results : rb_map name string) : format | format.intercalate format.line $ (sort_results env results).map $
λ ⟨decl_name, warning⟩, let form := print_warning decl_name warning in
if emit_workflow_commands then
form ++ (print_workflow_command env linter_name decl_name warning).get_or_else ""
else form | def | print_warnings | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"format.intercalate",
"print_warning",
"print_workflow_command",
"sort_results"
] | Formats a map of linter warnings using `print_warning`, sorted by line number. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
grouped_by_filename (e : environment) (results : rb_map name string) (drop_fn_chars := 0)
(formatter: rb_map name string → format) : format | let results := results.fold (rb_map.mk string (rb_map name string)) $
λ decl_name linter_warning results,
let fn := (e.decl_olean decl_name).get_or_else "" in
results.insert fn (((results.find fn).get_or_else mk_rb_map).insert
decl_name linter_warning) in
let l := results.to_list.reverse.map (λ ⟨fn, res... | def | grouped_by_filename | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"format.intercalate"
] | Formats a map of linter warnings grouped by filename with `-- filename` comments.
The first `drop_fn_chars` characters are stripped from the filename. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
format_linter_results
(env : environment)
(results : list (name × linter × rb_map name string))
(decls non_auto_decls : list declaration)
(group_by_filename : option ℕ)
(where_desc : string) (slow : bool) (verbose : lint_verbosity) (num_linters : ℕ)
-- whether to include codes understood by github to create... | do
let formatted_results := results.map $ λ ⟨linter_name, linter, results⟩,
let report_str : format := to_fmt "/- The `" ++ to_fmt linter_name ++ "` linter reports: -/\n" in
if ¬ results.empty then
let warnings := match group_by_filename with
| none := print_warnings env emit_workflow_commands linter_name... | def | format_linter_results | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"grouped_by_filename",
"lint_verbosity",
"linter",
"print_warnings"
] | Formats the linter results as Lean code with comments and `#check` commands. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_aux (decls : list declaration) (group_by_filename : option ℕ)
(where_desc : string) (slow : bool) (verbose : lint_verbosity) (checks : list (name × linter)) :
tactic (name_set × format) | do
e ← get_env,
let non_auto_decls := decls.filter (λ d, ¬ d.is_auto_or_internal e),
results ← lint_core decls non_auto_decls checks,
let s := format_linter_results e results decls non_auto_decls
group_by_filename where_desc slow verbose checks.length,
let ns := name_set.of_list (do (_,_,rs) ← results, rs.keys),
pure... | def | lint_aux | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"format_linter_results",
"lint_core",
"lint_verbosity",
"linter"
] | The common denominator of `#lint[|mathlib|all]`.
The different commands have different configurations for `l`,
`group_by_filename` and `where_desc`.
If `slow` is false, doesn't do the checks that take a lot of time.
If `verbose` is false, it will suppress messages from passing checks.
By setting `checks` you can custom... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint (slow : bool := tt) (verbose : lint_verbosity := lint_verbosity.medium)
(extra : list name := []) (use_only : bool := ff) : tactic (name_set × format) | do
checks ← get_checks slow extra use_only,
e ← get_env,
let l := e.filter (λ d, e.in_current_file d.to_name),
lint_aux l none "in the current file" slow verbose checks | def | lint | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"get_checks",
"lint_aux",
"lint_verbosity"
] | Return the message printed by `#lint` and a `name_set` containing all declarations that fail. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_project_decls (proj_folder : string) : tactic (list declaration) | do
e ← get_env,
pure $ e.filter $ λ d, e.is_prefix_of_file proj_folder d.to_name | def | lint_project_decls | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [] | Returns the declarations in the folder `proj_folder`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_project (proj_folder proj_name : string) (slow : bool := tt)
(verbose : lint_verbosity := lint_verbosity.medium)
(extra : list name := []) (use_only : bool := ff) : tactic (name_set × format) | do
checks ← get_checks slow extra use_only,
decls ← lint_project_decls proj_folder,
lint_aux decls proj_folder.length ("in " ++ proj_name ++ " (only in imported files)")
slow verbose checks | def | lint_project | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"get_checks",
"lint_aux",
"lint_project_decls",
"lint_verbosity"
] | Returns the linter message by running the linter on all declarations in project `proj_name` in
folder `proj_folder`. It also returns a `name_set` containing all declarations that fail.
To add a linter command for your own project, write
```
open lean.parser lean tactic interactive
@[user_command] meta def lint_my_proj... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_all (slow : bool := tt) (verbose : lint_verbosity := lint_verbosity.medium)
(extra : list name := []) (use_only : bool := ff) : tactic (name_set × format) | do
checks ← get_checks slow extra use_only,
e ← get_env,
let l := e.get_decls,
lint_aux l (some 0) "in all imported files (including this one)" slow verbose checks | def | lint_all | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"get_checks",
"lint_aux",
"lint_verbosity"
] | Return the message printed by `#lint_all` and a `name_set` containing all declarations
that fail. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
parse_lint_additions : parser (bool × list name) | prod.mk <$> only_flag <*> (list.map (name.append `linter) <$> ident*) | def | parse_lint_additions | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"linter"
] | Parses an optional `only`, followed by a sequence of zero or more identifiers.
Prepends `linter.` to each of these identifiers. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
parse_verbosity : parser (option lint_verbosity) | tk "-" >> return lint_verbosity.low <|>
tk "+" >> return lint_verbosity.high <|>
return none | def | parse_verbosity | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"lint_verbosity"
] | Parses a "-" or "+", returning `lint_verbosity.low` or `lint_verbosity.high` respectively,
or returns `none`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_cmd_aux
(scope : bool → lint_verbosity → list name → bool → tactic (name_set × format)) :
parser unit | do verbosity ← parse_verbosity,
fast_only ← optional (tk "*"),
-- allow either order of *-
verbosity ← if verbosity.is_some then return verbosity else parse_verbosity,
let verbosity := verbosity.get_or_else lint_verbosity.medium,
(use_only, extra) ← parse_lint_additions,
(failed, s) ← scope fast_only.... | def | lint_cmd_aux | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"lint_verbosity",
"parse_lint_additions",
"parse_verbosity"
] | The common denominator of `lint_cmd`, `lint_mathlib_cmd`, `lint_all_cmd` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_cmd (_ : parse $ tk "#lint") : parser unit | lint_cmd_aux @lint | def | lint_cmd | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"lint",
"lint_cmd_aux"
] | The command `#lint` at the bottom of a file will warn you about some common mistakes
in that file. Usage: `#lint`, `#lint linter_1 linter_2`, `#lint only linter_1 linter_2`.
`#lint-` will suppress the output if all checks pass.
`#lint+` will enable verbose output.
Use the command `#list_linters` to see all available l... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_mathlib_cmd (_ : parse $ tk "#lint_mathlib") : parser unit | do str ← get_mathlib_dir, lint_cmd_aux (@lint_project str "mathlib") | def | lint_mathlib_cmd | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"get_mathlib_dir",
"lint_cmd_aux",
"lint_project"
] | The command `#lint_mathlib` checks all of mathlib for certain mistakes.
Usage: `#lint_mathlib`, `#lint_mathlib linter_1 linter_2`, `#lint_mathlib only linter_1 linter_2`.
`#lint_mathlib-` will suppress the output if all checks pass.
`lint_mathlib+` will enable verbose output.
Use the command `#list_linters` to see all... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_all_cmd (_ : parse $ tk "#lint_all") : parser unit | lint_cmd_aux @lint_all | def | lint_all_cmd | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"lint_all",
"lint_cmd_aux"
] | The command `#lint_all` checks all imported files for certain mistakes.
Usage: `#lint_all`, `#lint_all linter_1 linter_2`, `#lint_all only linter_1 linter_2`.
`#lint_all-` will suppress the output if all checks pass.
`lint_all+` will enable verbose output.
Use the command `#list_linters` to see all available linters. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
list_linters (_ : parse $ tk "#list_linters") : parser unit | do env ← get_env,
let ns := env.decl_filter_map $ λ dcl,
if (dcl.to_name.get_prefix = `linter) && (dcl.type = `(linter)) then some dcl.to_name else none,
trace "Available linters:\n linters marked with (*) are in the default lint set\n",
ns.mmap' $ λ n, do
b ← has_attribute' `linter n,
trace $ n.po... | def | list_linters | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"linter"
] | The command `#list_linters` prints a list of all available linters. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lint_hole_cmd : hole_command | { name := "Lint",
descr := "Lint: Find common mistakes in current file.",
action := λ es, do (_, s) ← lint, return [(s.to_string,"")] } | def | lint_hole_cmd | tactic.lint | src/tactic/lint/frontend.lean | [
"meta.rb_map",
"tactic.lint.basic"
] | [
"lint"
] | Invoking the hole command `lint` ("Find common mistakes in current file") will print text that
indicates mistakes made in the file above the command. It is equivalent to copying and pasting the
output of `#lint`. On large files, it may take some time before the output appears. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
illegal_ge_gt : list name | [`gt, `ge] | def | illegal_ge_gt | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | The names of `≥` and `>`, mostly disallowed in lemma statements | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
contains_illegal_ge_gt : expr → bool | | (const nm us) := if nm ∈ illegal_ge_gt then tt else ff
| (app f e@(app (app (const nm us) tp) tc)) :=
contains_illegal_ge_gt f || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt e
| (app (app custom_binder (app (app (app (app (const nm us) tp) tc) (var 0)) t))
e@(lam var_name bi var_type body)) :=
c... | def | contains_illegal_ge_gt | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"illegal_ge_gt"
] | Checks whether `≥` and `>` occurs in an illegal way in the expression.
The main ways we legally use these orderings are:
- `f (≥)`
- `∃ x ≥ t, b`. This corresponds to the expression
`@Exists α (fun (x : α), (@Exists (x > t) (λ (H : x > t), b)))`
This function returns `tt` when it finds `ge`/`gt`, except in ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ge_or_gt_in_statement (d : declaration) : tactic (option string) | return $ if d.type.contains_constant (λ n, n ∈ illegal_ge_gt) &&
contains_illegal_ge_gt d.type
then some "the type contains ≥/>. Use ≤/< instead."
else none | def | ge_or_gt_in_statement | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"contains_illegal_ge_gt",
"illegal_ge_gt"
] | Checks whether a `>`/`≥` is used in the statement of `d`.
It first does a quick check to see if there is any `≥` or `>` in the statement, and then does a
slower check whether the occurrences of `≥` and `>` are allowed.
Currently it checks only the conclusion of the declaration, to eliminate false positive from
binders... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.ge_or_gt : linter | { test := ge_or_gt_in_statement,
auto_decls := ff,
no_errors_found := "Not using ≥/> in declarations.",
errors_found := "The following declarations use ≥/>, probably in a way where we would prefer
to use ≤/< instead. See note [nolint_ge] for more information.",
is_fast := ff } | def | linter.ge_or_gt | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"ge_or_gt_in_statement",
"linter"
] | A linter for checking whether illegal constants (≥, >) appear in a declaration's type. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
dup_namespace (d : declaration) : tactic (option string) | is_instance d.to_name >>= λ is_inst,
return $ let nm := d.to_name.components in if nm.chain' (≠) ∨ is_inst then none
else let s := (nm.find $ λ n, nm.count n ≥ 2).iget.to_string in
some $ "The namespace `" ++ s ++ "` is duplicated in the name" | def | dup_namespace | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Checks whether a declaration has a namespace twice consecutively in its name | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.dup_namespace : linter | { test := dup_namespace,
auto_decls := ff,
no_errors_found := "No declarations have a duplicate namespace.",
errors_found := "DUPLICATED NAMESPACES IN NAME:" } | def | linter.dup_namespace | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"dup_namespace",
"linter"
] | A linter for checking whether a declaration has a namespace twice consecutively in its name. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
check_unused_arguments_aux : list ℕ → ℕ → ℕ → expr → list ℕ | l n n_max e | if n > n_max then l else
if ¬ is_lambda e ∧ ¬ is_pi e then l else
let b := e.binding_body in
let l' := if b.has_var_idx 0 then l else n :: l in check_unused_arguments_aux l' (n+1) n_max b | def | check_unused_arguments_aux | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Auxiliary definition for `check_unused_arguments` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
check_unused_arguments (d : declaration) : option (list ℕ) | let l := check_unused_arguments_aux [] 1 d.type.pi_arity d.value in
if l = [] then none else
let l2 := check_unused_arguments_aux [] 1 d.type.pi_arity d.type in
(l.filter $ λ n, n ∈ l2).reverse | def | check_unused_arguments | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"check_unused_arguments_aux"
] | Check which arguments of a declaration are not used.
Prints a list of natural numbers corresponding to which arguments are not used (e.g.
this outputs [1, 4] if the first and fourth arguments are unused).
Checks both the type and the value of `d` for whether the argument is used
(in rare cases an argument is used in ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unused_arguments (d : declaration) : tactic (option string) | do
ff ← d.to_name.contains_sorry | return none,
let ns := check_unused_arguments d,
tt ← return ns.is_some | return none,
let ns := ns.iget,
(ds, _) ← get_pi_binders d.type,
let ns := ns.map (λ n, (n, (ds.nth $ n - 1).iget)),
let ns := ns.filter (λ x, x.2.type.get_app_fn ≠ const `interactive.parse []),
... | def | unused_arguments | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"check_unused_arguments"
] | Check for unused arguments, and print them with their position, variable name, type and whether
the argument is a duplicate.
See also `check_unused_arguments`.
This tactic additionally filters out all unused arguments of type `parse _`.
We skip all declarations that contain `sorry` in their value. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.unused_arguments : linter | { test := unused_arguments,
auto_decls := ff,
no_errors_found := "No unused arguments.",
errors_found := "UNUSED ARGUMENTS." } | def | linter.unused_arguments | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"linter",
"unused_arguments"
] | A linter object for checking for unused arguments. This is in the default linter set. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
doc_blame_report_defn : declaration → tactic (option string) | | (declaration.defn n _ _ _ _ _) := doc_string n >> return none <|> return "def missing doc string"
| (declaration.cnst n _ _ _) := doc_string n >> return none <|> return "constant missing doc string"
| _ := return none | def | doc_blame_report_defn | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Reports definitions and constants that are missing doc strings | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
doc_blame_report_thm : declaration → tactic (option string) | | (declaration.thm n _ _ _) := doc_string n >> return none <|> return "theorem missing doc string"
| _ := return none | def | doc_blame_report_thm | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Reports definitions and constants that are missing doc strings | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.doc_blame : linter | { test := λ d, mcond (bnot <$> has_attribute' `instance d.to_name)
(doc_blame_report_defn d) (return none),
auto_decls := ff,
no_errors_found := "No definitions are missing documentation.",
errors_found := "DEFINITIONS ARE MISSING DOCUMENTATION STRINGS:" } | def | linter.doc_blame | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"doc_blame_report_defn",
"linter"
] | A linter for checking definition doc strings | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.doc_blame_thm : linter | { test := doc_blame_report_thm,
auto_decls := ff,
no_errors_found := "No theorems are missing documentation.",
errors_found := "THEOREMS ARE MISSING DOCUMENTATION STRINGS:",
is_fast := ff } | def | linter.doc_blame_thm | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"doc_blame_report_thm",
"linter"
] | A linter for checking theorem doc strings. This is not in the default linter set. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
incorrect_def_lemma (d : declaration) : tactic (option string) | if d.is_constant ∨ d.is_axiom
then return none else do
is_instance_d ← is_instance d.to_name,
if is_instance_d then return none else do
-- the following seems to be a little quicker than `is_prop d.type`.
expr.sort n ← infer_type d.type,
is_pattern ← has_attribute' `pattern d.to_name,
... | def | incorrect_def_lemma | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Checks whether the correct declaration constructor (definition or theorem) by
comparing it to its sort. Instances will not be printed.
This test is not very quick: maybe we can speed-up testing that something is a proposition?
This takes almost all of the execution time. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.def_lemma : linter | { test := incorrect_def_lemma,
auto_decls := ff,
no_errors_found := "All declarations correctly marked as def/lemma.",
errors_found := "INCORRECT DEF/LEMMA:" } | def | linter.def_lemma | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"incorrect_def_lemma",
"linter"
] | A linter for checking whether the correct declaration constructor (definition or theorem)
has been used. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
check_type (d : declaration) : tactic (option string) | (type_check d.type >> return none) <|> return "The statement doesn't type-check" | def | check_type | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Checks whether the statement of a declaration is well-typed. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.check_type : linter | { test := check_type,
auto_decls := ff,
no_errors_found :=
"The statements of all declarations type-check with default reducibility settings.",
errors_found := "THE STATEMENTS OF THE FOLLOWING DECLARATIONS DO NOT TYPE-CHECK.
Some definitions in the statement are marked `@[irreducible]`, which means that the s... | def | linter.check_type | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"check_type",
"linter"
] | A linter for missing checking whether statements of declarations are well-typed. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
expr.univ_params_grouped (e : expr) (nm₀ : name) : rb_set (list name) | e.fold mk_rb_set $ λ e n l,
match e with
| e@(sort u) := l.insert u.params.to_list
| e@(const nm us) := if nm.get_prefix = nm₀ ∧ nm.last.starts_with "_proof_" then l else
l.union $ rb_set.of_list $ us.map $ λ u : level, u.params.to_list
| _ := l
end | def | expr.univ_params_grouped | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | `univ_params_grouped e` computes for each `level` `u` of `e` the parameters that occur in `u`,
and returns the corresponding set of lists of parameters.
In pseudo-mathematical form, this returns `{ { p : parameter | p ∈ u } | (u : level) ∈ e }`
We use `list name` instead of `name_set`, since `name_set` does not h... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
bad_params : rb_set (list name) → list name | l | let good_levels : name_set :=
l.fold mk_name_set $ λ us prev, if us.length = 1 then prev.insert us.head else prev in
if good_levels.empty then
l.fold [] list.union
else bad_params $ rb_set.of_list $ l.to_list.map $ λ us, us.filter $ λ nm, !good_levels.contains nm | def | bad_params | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | The good parameters are the parameters that occur somewhere in the `rb_set` as a singleton or
(recursively) with only other good parameters.
All other parameters in the `rb_set` are bad. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
check_univs (d : declaration) : tactic (option string) | do
let l := d.type.univ_params_grouped d.to_name,
let bad := bad_params l,
if bad.empty then return none else
return $ some $ "universes " ++ to_string bad ++ " only occur together." | def | check_univs | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"bad_params"
] | Checks whether all universe levels `u` in the type of `d` are "good".
This means that `u` either occurs in a `level` of `d` by itself, or (recursively)
with only other good levels.
When this fails, usually this means that there is a level `max u v`, where neither `u` nor `v`
occur by themselves in a level. It is ok if ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.check_univs : linter | { test := check_univs,
auto_decls := ff,
no_errors_found :=
"All declarations have good universe levels.",
errors_found := "THE STATEMENTS OF THE FOLLOWING DECLARATIONS HAVE BAD UNIVERSE LEVELS. " ++
"This usually means that there is a `max u v` in the type where neither `u` nor `v` " ++
"occur by themselves.... | def | linter.check_univs | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"check_univs",
"linter"
] | A linter for checking that there are no bad `max u v` universe levels. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
syn_taut (d : declaration) : tactic (option string) | (do (el, er) ← d.type.pi_codomain.is_eq,
guardb (el =ₐ er),
return $ some "LHS equals RHS syntactically") <|>
return none | def | syn_taut | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Checks whether a lemma is a declaration of the form `∀ a b ... z, e₁ = e₂`
where `e₁` and `e₂` are identical exprs.
We call declarations of this form syntactic tautologies.
Such lemmas are (mostly) useless and sometimes introduced unintentionally when proving basic facts
with rfl when elaboration results in a different... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.syn_taut : linter | { test := syn_taut,
auto_decls := ff, -- many false positives with this enabled
no_errors_found :=
"No declarations are syntactic tautologies.",
errors_found := "THE FOLLOWING DECLARATIONS ARE SYNTACTIC TAUTOLOGIES. " ++
"This usually means that they are of the form `∀ a b ... z, e₁ = e₂` where `e₁` and `e₂` ... | def | linter.syn_taut | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"linter",
"syn_taut"
] | A linter for checking that declarations aren't syntactic tautologies. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
expr.has_zero_var (e : expr) : bool | e.fold ff $ λ e' d res, res || match e' with | var k := k = d | _ := ff end | def | expr.has_zero_var | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Check if an expression contains `var 0` by folding over the expression and matching the binder depth | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
find_unused_have_suffices_macros : expr → tactic (list string) | | (app a b) := (++) <$> find_unused_have_suffices_macros a <*> find_unused_have_suffices_macros b
| (lam var_name bi var_type body) := find_unused_have_suffices_macros body
| (pi var_name bi var_type body) := find_unused_have_suffices_macros body
| (elet var_name type assignment body) := (++) <$> find_unused_have_suffi... | def | find_unused_have_suffices_macros | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Return a list of unused have and suffices terms in an expression | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unused_have_of_decl : declaration → tactic (list string) | | (declaration.defn _ _ _ bd _ _) := find_unused_have_suffices_macros bd
| (declaration.thm _ _ _ bd) := find_unused_have_suffices_macros bd.get
| _ := return [] | def | unused_have_of_decl | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"find_unused_have_suffices_macros"
] | Return a list of unused have and suffices terms in a declaration | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
has_unused_haves_suffices (d : declaration) : tactic (option string) | do
ns ← unused_have_of_decl d,
if ns.length = 0 then
return none
else
return (", ".intercalate (ns.map to_string)) | def | has_unused_haves_suffices | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"unused_have_of_decl"
] | Checks whether a declaration contains term mode have statements that have no effect on the resulting
term. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.unused_haves_suffices : linter | { test := has_unused_haves_suffices,
auto_decls := ff,
no_errors_found := "No declarations have unused term mode have statements.",
errors_found := "THE FOLLOWING DECLARATIONS HAVE INEFFECTUAL TERM MODE HAVE/SUFFICES BLOCKS. " ++
"In the case of `have` this is a term of the form `have h := foo, bar` where `bar` d... | def | linter.unused_haves_suffices | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"has_unused_haves_suffices",
"linter"
] | A linter for checking that declarations don't have unused term mode have statements. We do not
tag this as `@[linter]` so that it is not in the default linter set as it is slow and an uncommon
problem. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unprintable_interactive (d : declaration) : tactic (option string) | match d.to_name with
| name.mk_string _ (name.mk_string "interactive" (name.mk_string _ name.anonymous)) := do
(ds, _) ← mk_local_pis d.type,
ds ← ds.mfilter $ λ d, bnot <$> succeeds (interactive.param_desc d.local_type),
ff ← return ds.empty | return none,
ds ← ds.mmap (pp ∘ to_binder),
return $ some $ ds.to... | def | unprintable_interactive | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"succeeds"
] | Ensures that every interactive tactic has arguments for which `interactive.param_desc` succeeds.
This is used to generate the parser documentation that appears in hovers on interactive tactics. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.unprintable_interactive : linter | { test := unprintable_interactive,
auto_decls := tt,
no_errors_found := "No tactics are unprintable.",
errors_found := "THE FOLLOWING TACTICS ARE UNPRINTABLE. " ++
"This means that an interactive tactic is using `parse p` where `p` does not have " ++
"an associated description. You can fix this by wrapping `p` as... | def | linter.unprintable_interactive | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"linter",
"unprintable_interactive"
] | A linter for checking that interactive tactics have parser documentation. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unravel_explicits_of_pi :
expr → ℕ → list name → list ℕ → (list name) × (list ℕ) × expr | | (pi n default _ e) i ln li := unravel_explicits_of_pi e (i + 1) (n :: ln) (i :: li)
| (pi n _ _ e) i ln li := unravel_explicits_of_pi e (i + 1) ln li
| e _ ln li := (ln, li, e) | def | unravel_explicits_of_pi | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Recursively consumes a Pi expression while accumulating names and the complement of de-Bruijn
indexes of explicit variables, ultimately obtaining the remaining non-Pi expression as well. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
explicit_vars_of_iff (d : declaration) :
tactic (option string) | do
let (ln, li, e) := unravel_explicits_of_pi d.type 0 [] [],
match e.is_iff with
| none := return none
| some (el, er) := do
let li := li.map (λ i, d.type.pi_arity - i - 1), -- fixing for the actual de-Bruijn indexes
let l := (ln.zip li).filter (λ t, (el.has_var_idx t.2) && (er.has_var_idx t.2... | def | explicit_vars_of_iff | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"filter",
"unravel_explicits_of_pi"
] | This function works as follows:
1. Call `unravel_explicits_of_pi` to obtain the names, complements of de-Bruijn indexes and the
remaining non-Pi expression;
2. Check if the remaining non-Pi expression is an iff, already obtaining the respective left and
right expressions if this is the case. Returns `none` otherwise;
3... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.explicit_vars_of_iff : linter | { test := explicit_vars_of_iff,
auto_decls := ff,
no_errors_found := "No explicit variables on both sides of iff",
errors_found := "EXPLICIT VARIABLES ON BOTH SIDES OF IFF" } | def | linter.explicit_vars_of_iff | tactic.lint | src/tactic/lint/misc.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [
"explicit_vars_of_iff",
"linter"
] | A linter for checking if variables appearing on both sides of an iff are explicit. Ideally, such
variables should be implicit instead. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
simp_lhs_rhs : expr → tactic (expr × expr) | ty | do
ty ← head_beta ty,
-- We only detect a fixed set of simp relations here.
-- This is somewhat justified since for a custom simp relation R,
-- the simp lemma `R a b` is implicitly converted to `R a b ↔ true` as well.
match ty with
| `(¬ %%lhs) := pure (lhs, `(false))
| `(%%lhs = %%rhs) := pure (lhs, rhs)
| `(%%lhs ↔ ... | def | simp_lhs_rhs | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [] | `simp_lhs_rhs ty` returns the left-hand and right-hand side of a simp lemma with type `ty`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
simp_lhs (ty : expr): tactic expr | prod.fst <$> simp_lhs_rhs ty | def | simp_lhs | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"simp_lhs_rhs"
] | `simp_lhs ty` returns the left-hand side of a simp lemma with type `ty`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
simp_is_conditional_core : expr → tactic (option expr) | ty | do
ty ← head_beta ty,
match ty with
| `(¬ %%lhs) := pure lhs
| `(%%lhs = _) := pure lhs
| `(%%lhs ↔ _) := pure lhs
| (expr.pi n bi a b) := do
l ← mk_local' n bi a,
some lhs ← simp_is_conditional_core (b.instantiate_var l) | pure none,
if bi ≠ binder_info.inst_implicit ∧
¬ (lhs.abstract_local l.local_uniq_na... | def | simp_is_conditional_core | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [] | `simp_is_conditional_core ty` returns `none` if `ty` is a conditional simp
lemma, and `some lhs` otherwise. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
simp_is_conditional (ty : expr) : tactic bool | option.is_none <$> simp_is_conditional_core ty | def | simp_is_conditional | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"simp_is_conditional_core"
] | `simp_is_conditional ty` returns true iff the simp lemma with type `ty` is conditional. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
heuristic_simp_lemma_extraction (prf : expr) : tactic (list name) | prf.list_constant.to_list.mfilter is_simp_lemma | def | heuristic_simp_lemma_extraction | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
is_simp_eq (a b : expr) : tactic bool | if a.get_app_fn.const_name ≠ b.get_app_fn.const_name then pure ff else
succeeds $ is_def_eq a b transparency.reducible | def | is_simp_eq | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"succeeds"
] | Checks whether two expressions are equal for the simplifier. That is,
they are reducibly-definitional equal, and they have the same head symbol. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
simp_nf_linter (timeout := 200000) (d : declaration) : tactic (option string) | do
tt ← is_simp_lemma d.to_name | pure none,
-- Sometimes, a definition is tagged @[simp] to add the equational lemmas to the simp set.
-- In this case, ignore the declaration if it is not a valid simp lemma by itself.
tt ← is_valid_simp_lemma_cnst d.to_name | pure none,
[] ← get_eqn_lemmas_for ff d.to_name | pure none... | def | simp_nf_linter | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"heuristic_simp_lemma_extraction",
"is_simp_eq",
"simp_is_conditional",
"simp_lhs_rhs"
] | Reports declarations that are simp lemmas whose left-hand side is not in simp-normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.simp_nf : linter | { test := simp_nf_linter,
auto_decls := tt,
no_errors_found := "All left-hand sides of simp lemmas are in simp-normal form.",
errors_found := "SOME SIMP LEMMAS ARE NOT IN SIMP-NORMAL FORM.
see note [simp-normal form] for tips how to debug this.
https://leanprover-community.github.io/mathlib_docs/notes.html#simp-n... | def | linter.simp_nf | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"linter",
"simp_nf_linter"
] | A linter for simp lemmas whose lhs is not in simp-normal form, and which hence never fire. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
simp_var_head (d : declaration) : tactic (option string) | do
tt ← is_simp_lemma d.to_name | pure none,
-- Sometimes, a definition is tagged @[simp] to add the equational lemmas to the simp set.
-- In this case, ignore the declaration if it is not a valid simp lemma by itself.
tt ← is_valid_simp_lemma_cnst d.to_name | pure none,
lhs ← simp_lhs d.type,
head_sym@(expr.local_cons... | def | simp_var_head | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"simp_lhs"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
linter.simp_var_head : linter | { test := simp_var_head,
auto_decls := tt,
no_errors_found :=
"No left-hand sides of a simp lemma has a variable as head symbol.",
errors_found := "LEFT-HAND SIDE HAS VARIABLE AS HEAD SYMBOL.\n" ++
"Some simp lemmas have a variable as head symbol of the left-hand side:" } | def | linter.simp_var_head | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"linter",
"simp_var_head"
] | A linter for simp lemmas whose lhs has a variable as head symbol,
and which hence never fire. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
simp_comm (d : declaration) : tactic (option string) | do
tt ← is_simp_lemma d.to_name | pure none,
-- Sometimes, a definition is tagged @[simp] to add the equational lemmas to the simp set.
-- In this case, ignore the declaration if it is not a valid simp lemma by itself.
tt ← is_valid_simp_lemma_cnst d.to_name | pure none,
(lhs, rhs) ← simp_lhs_rhs d.type,
if lhs.get_app... | def | simp_comm | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"simp_lhs_rhs",
"succeeds"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
linter.simp_comm : linter | { test := simp_comm,
auto_decls := tt,
no_errors_found := "No commutativity lemma is marked simp.",
errors_found := "COMMUTATIVITY LEMMA IS SIMP.\n" ++
"Some commutativity lemmas are simp lemmas:" } | def | linter.simp_comm | tactic.lint | src/tactic/lint/simp.lean | [
"tactic.lint.basic"
] | [
"linter",
"simp_comm"
] | A linter for commutativity lemmas that are marked simp. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
print_arguments {α} [has_to_tactic_format α] (l : list (ℕ × α)) : tactic string | do
fs ← l.mmap (λ ⟨n, b⟩, (λ s, to_fmt "argument " ++ to_fmt (n+1) ++ ": " ++ s) <$> pp b),
return $ fs.to_string_aux tt | def | print_arguments | tactic.lint | src/tactic/lint/type_classes.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | Pretty prints a list of arguments of a declaration. Assumes `l` is a list of argument positions
and binders (or any other element that can be pretty printed).
`l` can be obtained e.g. by applying `list.indexes_values` to a list obtained by
`get_pi_binders`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
instance_priority (d : declaration) : tactic (option string) | do
let nm := d.to_name,
b ← is_instance nm,
/- return `none` if `d` is not an instance -/
if ¬ b then return none else do
(is_persistent, prio) ← has_attribute `instance nm,
/- return `none` if `d` is has low priority -/
if prio < 1000 then return none else do
(_, tp) ← open_pis d.type,
tp ← whnf tp t... | def | instance_priority | tactic.lint | src/tactic/lint/type_classes.lean | [
"data.bool.basic",
"meta.rb_map",
"tactic.lint.basic"
] | [] | checks whether an instance that always applies has priority ≥ 1000. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.