|
1 | 1 | # Commands |
2 | 2 |
|
3 | | -Mathlib version: `26fffffcccd7299b26cf63fac902165bc553fd56` |
| 3 | +Mathlib version: `3ea6690c3470d61c7d4fd71e7efd6336a6d05ffd` |
4 | 4 |
|
5 | 5 | ## \#adaptation_note |
6 | 6 | Defined in: `adaptationNoteCmd` |
@@ -423,9 +423,14 @@ Defined in: `Lean.Grind.grindLintSkip` |
423 | 423 | `#grind_lint skip thm₁ …` marks the given theorem(s) to be skipped entirely by `#grind_lint check`. |
424 | 424 | Skipped theorems are neither analyzed nor reported, but may still be used for |
425 | 425 | instantiation when analyzing other theorems. |
426 | | -Example: |
| 426 | + |
| 427 | +`#grind_lint skip suffix name₁ …` marks all theorems with the given suffix(es) to be skipped. |
| 428 | +For example, `#grind_lint skip suffix foo` will skip `bar.foo`, `qux.foo`, etc. |
| 429 | + |
| 430 | +Examples: |
427 | 431 | ```lean |
428 | 432 | #grind_lint skip Array.range_succ |
| 433 | +#grind_lint skip suffix append |
429 | 434 | ``` |
430 | 435 |
|
431 | 436 | ## \#grind_lint |
@@ -592,7 +597,7 @@ Position reporting: |
592 | 597 | `#guard_msgs` appears. |
593 | 598 | - `positions := false` does not report position info. |
594 | 599 |
|
595 | | -For example, `#guard_msgs (error, drop all) in cmd` means to check warnings and drop |
| 600 | +For example, `#guard_msgs (error, drop all) in cmd` means to check errors and drop |
596 | 601 | everything else. |
597 | 602 |
|
598 | 603 | The command elaborator has special support for `#guard_msgs` for linting. |
@@ -1777,9 +1782,127 @@ inductive types defined at `Prelude.lean`. |
1777 | 1782 | Temporarily also controls the generation of the `ctorIdx` definition. |
1778 | 1783 | It is meant for bootstrapping purposes only. |
1779 | 1784 |
|
| 1785 | +## grind_annotated |
| 1786 | +Defined in: `Lean.Parser.Command.grindAnnotated` |
| 1787 | + |
| 1788 | +`grind_annotated "YYYY-MM-DD"` marks the current file as having been manually annotated for `grind`. |
| 1789 | + |
| 1790 | +When the LibrarySuggestion framework is called with `caller := "grind"` (as happens when using |
| 1791 | +`grind +suggestions`), theorems from grind-annotated files are excluded from premise selection. |
| 1792 | +This is because these files have already been manually reviewed and annotated with appropriate |
| 1793 | +`@[grind]` attributes. |
| 1794 | + |
| 1795 | +The date argument (in YYYY-MM-DD format) records when the file was annotated. This is currently |
| 1796 | +informational only, but may be used in the future to detect files that have been significantly |
| 1797 | +modified since annotation and may need re-review. |
| 1798 | + |
| 1799 | +Example: |
| 1800 | +```lean |
| 1801 | +grind_annotated "2025-01-15" |
| 1802 | +``` |
| 1803 | + |
| 1804 | +This command should typically appear near the top of a file, after imports. |
| 1805 | + |
1780 | 1806 | ## grind_pattern |
1781 | 1807 | Defined in: `Lean.Parser.Command.grindPattern` |
1782 | 1808 |
|
| 1809 | +The `grind_pattern` command can be used to manually select a pattern for theorem instantiation. |
| 1810 | +Enabling the option `trace.grind.ematch.instance` causes `grind` to print a trace message for each |
| 1811 | +theorem instance it generates, which can be helpful when determining patterns. |
| 1812 | + |
| 1813 | +When multiple patterns are specified together, all of them must match in the current context before |
| 1814 | +`grind` attempts to instantiate the theorem. This is referred to as a *multi-pattern*. |
| 1815 | +This is useful for theorems such as transitivity rules, where multiple premises must be simultaneously |
| 1816 | +present for the rule to apply. |
| 1817 | + |
| 1818 | +In the following example, `R` is a transitive binary relation over `Int`. |
| 1819 | +``` |
| 1820 | +opaque R : Int → Int → Prop |
| 1821 | +axiom Rtrans {x y z : Int} : R x y → R y z → R x z |
| 1822 | +``` |
| 1823 | +To use the fact that `R` is transitive, `grind` must already be able to satisfy both premises. |
| 1824 | +This is represented using a multi-pattern: |
| 1825 | +```lean |
| 1826 | +grind_pattern Rtrans => R x y, R y z |
| 1827 | +
|
| 1828 | +example {a b c d} : R a b → R b c → R c d → R a d := by |
| 1829 | + grind |
| 1830 | +``` |
| 1831 | +The multi-pattern `R x y`, `R y z` instructs `grind` to instantiate `Rtrans` only when both `R x y` |
| 1832 | +and `R y z` are available in the context. In the example, `grind` applies `Rtrans` to derive `R a c` |
| 1833 | +from `R a b` and `R b c`, and can then repeat the same reasoning to deduce `R a d` from `R a c` and |
| 1834 | +`R c d`. |
| 1835 | + |
| 1836 | +You can add constraints to restrict theorem instantiation. For example: |
| 1837 | +```lean |
| 1838 | +grind_pattern extract_extract => (as.extract i j).extract k l where |
| 1839 | + as =/= #[] |
| 1840 | +``` |
| 1841 | +The constraint instructs `grind` to instantiate the theorem only if `as` is **not** definitionally equal |
| 1842 | +to `#[]`. |
| 1843 | + |
| 1844 | +## Constraints |
| 1845 | + |
| 1846 | +- `x =/= term`: The term bound to `x` (one of the theorem parameters) is **not** definitionally equal to `term`. |
| 1847 | + The term may contain holes (i.e., `_`). |
| 1848 | + |
| 1849 | +- `x =?= term`: The term bound to `x` is definitionally equal to `term`. |
| 1850 | + The term may contain holes (i.e., `_`). |
| 1851 | + |
| 1852 | +- `size x < n`: The term bound to `x` has size less than `n`. Implicit arguments |
| 1853 | +and binder types are ignored when computing the size. |
| 1854 | + |
| 1855 | +- `depth x < n`: The term bound to `x` has depth less than `n`. |
| 1856 | + |
| 1857 | +- `is_ground x`: The term bound to `x` does not contain local variables or meta-variables. |
| 1858 | + |
| 1859 | +- `is_value x`: The term bound to `x` is a value. That is, it is a constructor fully applied to value arguments, |
| 1860 | +a literal (`Nat`, `Int`, `String`, etc.), or a lambda `fun x => t`. |
| 1861 | + |
| 1862 | +- `is_strict_value x`: Similar to `is_value`, but without lambdas. |
| 1863 | + |
| 1864 | +- `not_value x`: The term bound to `x` is a **not** value (see `is_value`). |
| 1865 | + |
| 1866 | +- `not_strict_value x`: Similar to `not_value`, but without lambdas. |
| 1867 | + |
| 1868 | +- `gen < n`: The theorem instance has generation less than `n`. Recall that each term is assigned a |
| 1869 | +generation, and terms produced by theorem instantiation have a generation that is one greater than |
| 1870 | +the maximal generation of all the terms used to instantiate the theorem. This constraint complements |
| 1871 | +the `gen` option available in `grind`. |
| 1872 | + |
| 1873 | +- `max_insts < n`: A new instance is generated only if less than `n` instances have been generated so far. |
| 1874 | + |
| 1875 | +- `guard e`: The instantiation is delayed until `grind` learns that `e` is `true` in this state. |
| 1876 | + |
| 1877 | +- `check e`: Similar to `guard e`, but `grind` checks whether `e` is implied by its current state by |
| 1878 | +assuming `¬ e` and trying to deduce an inconsistency. |
| 1879 | + |
| 1880 | +## Example |
| 1881 | + |
| 1882 | +Consider the following example where `f` is a monotonic function |
| 1883 | +``` |
| 1884 | +opaque f : Nat → Nat |
| 1885 | +axiom fMono : x ≤ y → f x ≤ f y |
| 1886 | +``` |
| 1887 | +and you want to instruct `grind` to instantiate `fMono` for every pair of terms `f x` and `f y` when |
| 1888 | +`x ≤ y` and `x` is **not** definitionally equal to `y`. You can use |
| 1889 | +``` |
| 1890 | +grind_pattern fMono => f x, f y where |
| 1891 | + guard x ≤ y |
| 1892 | + x =/= y |
| 1893 | +``` |
| 1894 | +Then, in the following example, only three instances are generated. |
| 1895 | +```lean |
| 1896 | +/-- |
| 1897 | +trace: [grind.ematch.instance] fMono: a ≤ f a → f a ≤ f (f a) |
| 1898 | +[grind.ematch.instance] fMono: f a ≤ f (f a) → f (f a) ≤ f (f (f a)) |
| 1899 | +[grind.ematch.instance] fMono: a ≤ f (f a) → f a ≤ f (f (f a)) |
| 1900 | +-/ |
| 1901 | +#guard_msgs in |
| 1902 | +example : f b = f c → a ≤ f a → f (f a) ≤ f (f (f a)) := by |
| 1903 | + set_option trace.grind.ematch.instance true in |
| 1904 | + grind |
| 1905 | +``` |
1783 | 1906 |
|
1784 | 1907 | ## grind_propagator |
1785 | 1908 | Defined in: `Lean.Parser.«command_Grind_propagator___(_):=_»` |
@@ -2853,6 +2976,19 @@ Defined in: `Mathlib.WhatsNew.commandWhatsnewIn__` |
2853 | 2976 | `whatsnew in $command` executes the command and then prints the |
2854 | 2977 | declarations that were added to the environment. |
2855 | 2978 |
|
| 2979 | +## with_weak_namespace |
| 2980 | +Defined in: `Lean.Parser.Command.withWeakNamespace` |
| 2981 | + |
| 2982 | +`with_weak_namespace <id> <cmd>` changes the current namespace to `<id>` for the duration of |
| 2983 | +executing command `<cmd>`, without causing scoped things to go out of scope. |
| 2984 | + |
| 2985 | +This is in contrast to `namespace <id>` which pushes a new scope and deactivates scoped entries |
| 2986 | +from the previous namespace. `with_weak_namespace` modifies the existing scope's namespace, |
| 2987 | +so scoped extensions remain active. |
| 2988 | + |
| 2989 | +This is primarily useful for defining syntax extensions that should be scoped to a different |
| 2990 | +namespace than the current one. |
| 2991 | + |
2856 | 2992 | ## with_weak_namespace |
2857 | 2993 | Defined in: `Lean.Elab.Command.commandWith_weak_namespace__` |
2858 | 2994 |
|
|
0 commit comments