Skip to content

Commit a6874c5

Browse files
committed
chore(Tactic): rewrite rify tactic docstring (#38004)
This PR rewrites the docstrings for the `rify` tactic, to consistently match the official style guide, to make sure they are complete while not getting too long: https://github.com/leanprover/lean4/blob/master/doc/style.md#tactics In particular, the contents and structure of `rify`'s docstring should match those of `qify` and `zify`, of #37765. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
1 parent 6d5e4af commit a6874c5

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

Mathlib/Tactic/Rify.lean

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,48 @@ open Lean.Parser.Tactic
4444
open Lean.Elab.Tactic
4545

4646
/--
47-
The `rify` tactic is used to shift propositions from `ℕ`, `ℤ` or `` to `ℝ`.
47+
`rify` rewrites the main goal by shifting propositions from `ℕ`, `ℤ`, `ℚ` or `ℝ≥0` to `ℝ`.
4848
Although less useful than its cousins `zify` and `qify`, it can be useful when your
4949
goal or context already involves real numbers.
5050
51-
In the example below, assumption `hn` is about natural numbers, `hk` is about integers
52-
and involves casting a natural number to `ℤ`, and the conclusion is about real numbers.
53-
The proof uses `rify` to lift both assumptions to `ℝ` before calling `linarith`.
51+
`rify` makes use of the `@[zify_simps]`, `@[qify_simps]` and `@[rify_simps]` attributes to insert
52+
casts into propositions, and the `push_cast` tactic to simplify the `ℝ`-valued expressions.
53+
54+
`rify` is in some sense dual to the `lift` tactic. `lift (r : ℝ) to ℚ` will change the type of a
55+
real number `r` (in the supertype) to `ℚ` (the subtype), given a proof that `r` is rational;
56+
propositions concerning `r` will still be over `ℝ`. `rify` changes propositions about `ℕ`, `ℤ`, `ℚ`
57+
or `ℝ≥0` (the subtype) to propositions about `ℝ` (the supertype), without changing the type of any
58+
variable.
59+
60+
* `rify at l1 l2 ...` rewrites at the given locations.
61+
* `rify [h₁, ..., hₙ]` uses the expressions `h₁`, ..., `hₙ` as extra lemmas for simplification.
62+
This is especially useful in the presence of nat subtraction or of division: passing arguments of
63+
type `· ≤ ·` or `· ∣ ·` will allow `push_cast` to do more work.
64+
65+
Examples:
5466
```
67+
/--
68+
import Mathlib
69+
70+
open Real
71+
Here, the assumption `hn` is about natural numbers, `hk` is about integers
72+
and involves casting a natural number to `ℤ`, and the conclusion is about real numbers.
73+
-/
5574
example {n : ℕ} {k : ℤ} (hn : 8 ≤ n) (hk : 2 * k ≤ n + 2) :
5675
(0 : ℝ) < n - k - 1 := by
5776
rify at hn hk /- Now have hn : 8 ≤ (n : ℝ) hk : 2 * (k : ℝ) ≤ (n : ℝ) + 2 -/
5877
linarith
59-
```
60-
61-
`rify` makes use of the `@[zify_simps]`, `@[qify_simps]` and `@[rify_simps]` attributes to move
62-
propositions, and the `push_cast` tactic to simplify the `ℝ`-valued expressions.
6378
64-
`rify` can be given extra lemmas to use in simplification. This is especially useful in the
65-
presence of nat subtraction: passing `≤` arguments will allow `push_cast` to do more work.
66-
```
79+
-- Extra hypotheses allow `push_cast` to do more work.
6780
example (a b c : ℕ) (h : a - b < c) (hab : b ≤ a) : a < b + c := by
68-
rify [hab] at h ⊢
81+
rify [hab] at h ⊢ -- Here `zify` or `qify` would have also worked.
6982
linarith
83+
84+
example (a b : ℕ) (ha : π ≤ a) : 3 ≤ a + b := by
85+
rify
86+
linarith [pi_gt_three]
7087
```
71-
Note that `zify` or `qify` would work just as well in the above example (and `zify` is the natural
72-
choice since it is enough to get rid of the pathological `ℕ` subtraction). -/
88+
-/
7389
syntax (name := rify) "rify" (simpArgs)? (location)? : tactic
7490

7591
macro_rules

0 commit comments

Comments
 (0)