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 ```
13 lines
304 B
Text
13 lines
304 B
Text
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
|
||
|
||
@[grind unfold] def h (x : Nat) := 2 * x
|
||
|
||
example : 2 ∣ h x := by grind
|