Commit graph

76 commits

Author SHA1 Message Date
JovanGerb
c7c50a8bec
chore: fix linter errors (#4502)
The linters in Batteries can be used to spot mistakes in Lean. See the
message on
[Zulip](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Go-to-def.20on.20typeclass.20fields.20and.20type-dependent.20notation/near/442613564).
These are the different linters with errors:

- unusedArguments:
There are many unused instance arguments, especially a redundant `[Monad
m]` is very common
- checkUnivs:
There was a problem with universes in a definition in
`Init.Control.StateCps`. I fixed it by adding a `variable` statement for
the implicit arguments in the file.
- defLemma:
many proofs are written as `def` instead of `theorem`, most notably
`rfl`. Because `rfl` is used as a match pattern, it must be a def. Is
this desirable?
The keyword `abbrev` is sometimes used for an alias of a theorem, which
also results in a def. I would want to replace it with the `alias`
keyword to fix this, but it isn't available.
- dupNamespace:
I fixed some of these, but left `Tactic.Tactic` and `Parser.Parser` as
they are as these seem intended.
- unusedHaveSuffices:
  I cleaned up a few proofs with unused `have` or `suffices`
- explicitVarsOfIff:
  I didn't fix any of these, because that would be a breaking change.
- simpNF:
I didn't fix any of these, because I think that requires knowing the
intended simplification order.
2024-06-19 18:24:08 +00:00
Leonardo de Moura
4d2ff6fb04
feat: pretty print Array DiscrTree.Key (#4208) 2024-05-17 22:35:24 +00:00
Leonardo de Moura
ee0bcc8321
feat: add Simp.Config.index (#4202)
The `simp` tactic uses a discrimination tree to select candidate
theorems that will be used to rewrite an expression. This indexing data
structure minimizes the number of theorems that need to be tried and
improves performance. However, indexing modulo reducibility is
challenging, and a theorem that could be applied, when taking reduction
into account, may be missed. For example, suppose we have a `simp`
theorem `foo : forall x y, f x (x, y).2 = y`, and we are trying to
simplify the expression `f a b <= b`. `foo` will not be tried by `simp`
because the second argument of `f a b` is not a projection of a pair.
However, `f a b` is definitionally equal to `f a (a, b).2` since we can
reduce `(a, b).2`.

In Lean 3, we had a much simpler indexing data structure where only the
head symbol was taken into account. For the theorem `foo`, the head
symbol is `f`. Thus, the theorem would be considered by `simp`.

This commit adds the option `Simp.Config.index`. When `simp (config := {
index := false })`, only the head symbol is considered when retrieving
theorems, as in Lean 3. Moreover, if `set_option diagnostics true`,
`simp` will check whether every applied theorem would also have been
applied if `index := true`, and report them. This feature can help users
diagnose tricky issues in code that has been ported from libraries
developed using Lean 3 and then ported to Lean 4. In the following
example, it will report that `foo` is a problematic theorem.

```lean
opaque f : Nat → Nat → Nat

@[simp] theorem foo : f x (x, y).2 = y := by sorry

example : f a b ≤ b := by
  set_option diagnostics true in
  simp (config := { index := false })
```

In the example above, the following diagnostic message is produced.
```lean
[simp] theorems with bad keys
    foo, key: [f, *, Prod.1, Prod.mk, Nat, Nat, *, *]
```

With the information above, users can annotate theorems such as `foo`
using `no_index` for problematic subterms.
Example:
```lean
opaque f : Nat → Nat → Nat

@[simp] theorem foo : f x (no_index (x, y).2) = y := by sorry

example : f a b ≤ b := by
  simp -- `foo` is still applied
```

cc @semorrison 
cc @PatrickMassot
2024-05-17 21:14:58 +00:00
Leonardo de Moura
3218b25974 doc: for issue #2835 2024-03-06 15:29:04 -08:00
Leonardo de Moura
423fed79a9 feat: simplify .arrow ctor at DiscrTree.lean 2024-03-06 15:29:04 -08:00
Leonardo de Moura
2defc58159 chore: rename isNatLit => isRawNatLit
Motivation: consistency with `mkRawNatLit`
2024-02-23 15:16:12 -08:00
Leonardo de Moura
90b5a0011d feat: assume function application arguments occurring in local simp theorems have been annotated with no_index (#3406)
closes #2670
2024-02-19 12:43:34 -08:00
Henrik Böving
23e49eb519 perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Scott Morrison
2032ffa3fc
chore: DiscrTree helper functions (#3303)
`DiscrTree` helper functions from `Std`, used in `ext`, `exact?`, and
`aesop`.

(There are a few more to follow later, with other Std dependencies.)
2024-02-13 03:46:31 +00:00
Wojciech Nawrocki
66e8cb7966
doc: implicit type arguments are indexed in the discrtree (#3301)
A small fix to the `DiscrTree` documentation to reflect the fact that
implicit type arguments *are* indexed and do not become `star` or
`other`. The following is a reproduction:
```lean
import Lean
open Lean Meta Elab Tactic

elab "test_tac" t:term : tactic => do
  Tactic.withMainContext do
    let e ← Term.elabTerm t none
    let a : DiscrTree Nat ← DiscrTree.empty.insert e 1 {}
    logInfo m!"{a}"

example (α : Type) (ringAdd : Add α) : True := by
  /- (Add.add => (node (Nat => (node (* => (node (0 => (node (1 => (node #[1])))))))))) -/
  test_tac @Add.add Nat instAddNat 0 1
  /- (Add.add => (node (_uniq.1154 => (node (* => (node ( => (node ( => (node #[1])))))))))) -/
  test_tac @Add.add α ringAdd ?_ ?_
```
2024-02-11 21:42:54 +00:00
Joachim Breitner
368ead54b2 refactor: termination_by changes in stdlib 2024-01-10 17:27:35 +01:00
Leonardo de Moura
f54bce2abb chore: remove unused argument 2023-12-28 10:41:04 -08:00
Marcus Rossel
1362268472
doc: fix typos (#2915) 2023-11-19 20:00:47 +00:00
Leonardo de Moura
691defdc5d chore: typos and PR feedback
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
2023-10-25 03:12:35 -07:00
Leonardo de Moura
3a13200772 refactor: add configuration options to control WHNF
This commit also removes parameter `simpleReduce` from discrimination
trees, and take WHNF configuration options.
Reason: it is more dynamic now. For example, the simplifier
will be able to use different configurations for discrimination tree insertion
and retrieval. We need this feature to address issues #2669 and #2281

This commit also removes the dead Meta.Config field `zetaNonDep`.
2023-10-25 03:12:35 -07:00
int-y1
8d7520b36f chore: fix typos in comments 2023-10-08 10:46:05 +02:00
Leonardo de Moura
94d4a427e2 fix: fixes #2115 2023-06-30 19:54:38 -07:00
Leonardo de Moura
eece499da9 fix: fixes #2282 2023-06-27 16:46:38 -07:00
Leonardo de Moura
425f42cd83 feat: better support for Nat literals at DiscrTree.lean 2023-06-21 22:30:09 -07:00
Leonardo de Moura
2b8e55c2f1 fix: Nat literal bug at DiscrTree.lean 2023-06-21 20:28:17 -07:00
Leonardo de Moura
25384fe951 fix: fixes #2232 2023-05-31 05:48:25 -07:00
Leonardo de Moura
dd682bf1d5 feat: add support for HO projections at DiscrTree
closes #1937

Requires update stage0
2023-01-05 13:33:43 -08:00
Leonardo de Moura
71b7562c2f fix: class projection at DiscrTree 2022-11-24 11:56:36 -08:00
Leonardo de Moura
8225be2f0e feat: ensure projections are not reducing at DiscrTree V (simpleReduce := true)
Now, the `simp` discrimination tree does not perform `iota` nor reduce
projections.
2022-11-15 16:47:12 -08:00
Leonardo de Moura
1b0c2f7157 feat: parameterize DiscrTree indicating whether non trivial reductions are allowed or not when indexing/retrieving terms 2022-11-15 16:47:12 -08:00
Leonardo de Moura
81c84bf045 feat: do not perform iota reduction at the discrimination tree module 2022-11-15 16:47:12 -08:00
Leonardo de Moura
7874c03c27 chore: style 2022-10-08 07:49:27 -07:00
Leonardo de Moura
6bc4144409 fix: fixes #1549 2022-10-08 07:41:49 -07:00
Mario Carneiro
6392c5b456 chore: import reductions 2022-09-15 14:02:38 -07:00
Leonardo de Moura
3896244c55 chore: cleanup 2022-07-25 22:39:56 -07:00
Leonardo de Moura
8335a82aed refactor: improve MVarId method discoverability
See issue #1346
2022-07-24 21:36:33 -07:00
Mario Carneiro
f6211b1a74
chore: convert doc/mod comments from /- to /--//-! (#1354) 2022-07-22 12:05:31 -07:00
Gabriel Ebner
a8cab84735 refactor: use computed fields for Expr 2022-07-11 14:19:41 -07:00
Leonardo de Moura
2ebcf29cde chore: use a[i]! for array accesses that may panic 2022-07-02 15:12:05 -07:00
Leonardo de Moura
c498285d94 chore: add missing double backtick 2022-06-27 09:56:47 -07:00
Sebastian Ullrich
ae7b895f7a refactor: unname some unused variables 2022-06-07 16:37:45 -07:00
Leonardo de Moura
42b707e250 perf: improve getMatchWithExtra 2022-03-18 17:10:46 -07:00
Leonardo de Moura
38a1675c72 fix: dicrimination tree getMatchWithExtra
It was buggy when the input argument could be reduced `e`.

fixes #1048
2022-03-17 16:44:38 -07:00
Leonardo de Moura
b664a93d8e fix: a match application is stuck if one of the discriminants contain metavariables 2022-03-06 07:51:09 -08:00
Leonardo de Moura
8bcaafb28b fix: universe metavariables should not be taken into account at getKeyArgs 2022-03-06 07:50:19 -08:00
Leonardo de Moura
613cf19509 fix: discrimination trees and "stuck" terms
See comments and new test.
2022-03-05 15:12:20 -08:00
Leonardo de Moura
9c2942c36d chore: "simp lemma" => "simp theorem" 2022-02-06 09:15:39 -08:00
Leonardo de Moura
12e2a79170 chore: fix codebase after removing auto pure 2022-02-03 18:08:14 -08:00
Leonardo de Moura
8db923e010 feat: generate error message for simp theorems that are equivalent to x = x
see #973
see https://github.com/leanprover-community/mathport/issues/70
2022-01-26 11:16:31 -08:00
Leonardo de Moura
cf3b8d4eb4 chore: cleanup
Make the code style more uniform.
We still have a lot of leftovers from the old frontend.
2022-01-26 09:18:17 -08:00
Leonardo de Moura
bac91b9b5b chore: remove arbitrary 2022-01-15 12:14:27 -08:00
Gabriel Ebner
7537fa7795 fix: unfold x<y in discrimination tree module 2021-11-23 07:34:51 -08:00
Leonardo de Moura
1282fb2d97 fix: getMatchWithExtra
`getMatchKeyArgs` returns arguments in reverse order.
2021-09-25 08:36:12 -07:00
Leonardo de Moura
19a710ffc9 feat: add getMatchWithExtra and improve tryLemma at simp 2021-09-09 19:28:09 -07:00
Leonardo de Moura
09eecc5c08 fix: simp was not applying rewrites to the function application prefixes 2021-09-09 17:07:14 -07:00