lean4-htt/src/Init/Grind
Leonardo de Moura a471f005d6
feat: add [grind norm] and [grind unfold] attributes (#11776)
This PR adds the attributes `[grind norm]` and `[grind unfold]` for
controlling the `grind` normalizer/preprocessor.

The `norm` modifier instructs `grind` to use a theorem as a
normalization rule. That is, the theorem is applied during the
preprocessing step. This feature is meant for advanced users who
understand how the preprocessor and `grind`'s search procedure interact
with each other.
New users can still benefit from this feature by restricting its use to
theorems that completely eliminate a symbol from the goal. Example:
```lean
theorem max_def : max n m = if n ≤ m then m else n
```
For a negative example, consider:
```lean
opaque f : Int → Int → Int → Int
theorem fax1 : f x 0 1 = 1 := sorry
theorem fax2 : f 1 x 1 = 1 := sorry
attribute [grind norm] fax1
attribute [grind =] fax2

example (h : c = 1) : f c 0 c = 1 := by
  grind -- fails
```
In this example, `fax1` is a normalization rule, but it is not
applicable to the input goal since `f c 0 c` is not an instance of `f x
0 1`. However, `f c 0 c` matches the pattern `f 1 x 1` modulo the
equality `c = 1`. Thus, `grind` instantiates `fax2` with `x := 0`,
producing the equality `f 1 0 1 = 1`, which the normalizer simplifies to
`True`. As a result, nothing useful is learned. In the future, we plan
to include linters to automatically detect issues like these. Example:
```lean
opaque f : Nat → Nat
opaque g : Nat → Nat

@[grind norm] axiom fax : f x = x + 2
@[grind norm ←] axiom fg : f x = g x

example : f x ≥ 2 := by grind
example : f x ≥ g x := by grind
example : f x + g x ≥ 4 := by grind
```

The `unfold` modifier instructs `grind` to unfold the given definition
during the preprocessing step. Example:
```lean
@[grind unfold] def h (x : Nat) := 2 * x
example : 6 ∣ 3*h x := by grind
```
2025-12-23 03:54:35 +00:00
..
Module perf: de-fuel some recursive definitions in Core (#11416) 2025-12-05 16:16:31 +00:00
Ordered feat: basic equality propagation for IntModule in grind (#11677) 2025-12-14 22:40:11 +00:00
Ring feat: abstract metavariables when generalizing match motives (#8099) (#11696) 2025-12-16 14:34:29 +00:00
AC.lean chore: use abbrev in denote functions (#11092) 2025-11-05 13:51:36 +00:00
Annotated.lean feat: implement grind_annotated command (#11332) 2025-11-25 02:12:35 +00:00
Attr.lean feat: add [grind norm] and [grind unfold] attributes (#11776) 2025-12-23 03:54:35 +00:00
Cases.lean feat: grind cases on Sum (#11087) 2025-11-11 04:50:34 +00:00
Config.lean feat: add Grind.Config.reducible (#11480) 2025-12-02 18:10:55 +00:00
Ext.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
FieldNormNum.lean feat: Field norm num (#11350) 2025-11-25 19:47:31 +00:00
Injective.lean feat: support for injective functions in grind (#10483) 2025-09-21 06:31:46 +00:00
Interactive.lean feat: grind use/instantiate only can activate all scoped theorems in a namespace (#11335) 2025-11-25 02:41:08 +00:00
Lemmas.lean feat: semiring * propagators in grind (#11653) 2025-12-13 14:32:34 +00:00
Lint.lean feat: #grind_lint skip suffix 2025-11-21 19:35:21 +11:00
Module.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Norm.lean feat: new Int operations in grind (#11656) 2025-12-13 14:55:34 +00:00
Offset.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Order.lean fix: grind order equality propagation for Nat (#11050) 2025-11-01 18:35:34 +00:00
Ordered.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
PP.lean feat: overhaul meta system (#10362) 2025-09-17 21:04:29 +00:00
Propagator.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Ring.lean feat: add LawfulOfScientific class (#10971) 2025-10-27 04:18:55 +00:00
Tactics.lean doc: add link to reference manual in grind docstring (#11700) 2025-12-16 15:35:55 +00:00
ToInt.lean refactor: use deriving LawfulBEq in Init (#10411) 2025-09-16 16:26:32 +00:00
ToIntLemmas.lean chore: avoid confusing public import all combination (#10051) 2025-08-22 12:04:42 +00:00
Util.lean feat: exact? +grind and exact? +try? discharger options (#11469) 2025-12-02 06:31:56 +00:00