|
|
|
|
@ -32,19 +32,19 @@ could prove things like `a + 0 = a`.
|
|
|
|
|
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
TacticDoc rewrite
|
|
|
|
|
"
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
TacticDoc rw
|
|
|
|
|
"
|
|
|
|
|
## Summary
|
|
|
|
|
|
|
|
|
|
If `h` is a proof of `X = Y`, then `rw h,` will change
|
|
|
|
|
all `X`s in the goal to `Y`s. Variants: `rw ← h` (changes
|
|
|
|
|
`Y` to `X`) and
|
|
|
|
|
`rw h at h2` (changes `X` to `Y` in hypothesis `h2` instead
|
|
|
|
|
of the goal).
|
|
|
|
|
If `h` is a proof of `X = Y`, then `rw [h]` will change
|
|
|
|
|
all `X`s in the goal to `Y`s.
|
|
|
|
|
|
|
|
|
|
### Variants
|
|
|
|
|
|
|
|
|
|
* `rw [← h#` (changes `Y` to `X`)
|
|
|
|
|
* `rw [h] at h2` (changes `X` to `Y` in hypothesis `h2` instead of the goal)
|
|
|
|
|
* `rw [h] at *` (changes `X` to `Y` in the goal and all hypotheses)
|
|
|
|
|
|
|
|
|
|
## Details
|
|
|
|
|
|
|
|
|
|
@ -53,14 +53,14 @@ are two distinct situations where use this tactics.
|
|
|
|
|
|
|
|
|
|
1) If `h : A = B` is a hypothesis (i.e., a proof of `A = B`)
|
|
|
|
|
in your local context (the box in the top right)
|
|
|
|
|
and if your goal contains one or more `A`s, then `rw h`
|
|
|
|
|
and if your goal contains one or more `A`s, then `rw [h]`
|
|
|
|
|
will change them all to `B`'s.
|
|
|
|
|
|
|
|
|
|
2) The `rw` tactic will also work with proofs of theorems
|
|
|
|
|
which are equalities (look for them in the drop down
|
|
|
|
|
menu on the left, within Theorem Statements).
|
|
|
|
|
For example, in world 1 level 4
|
|
|
|
|
we learn about `add_zero x : x + 0 = x`, and `rw add_zero`
|
|
|
|
|
we learn about `add_zero x : x + 0 = x`, and `rw [add_zero]`
|
|
|
|
|
will change `x + 0` into `x` in your goal (or fail with
|
|
|
|
|
an error if Lean cannot find `x + 0` in the goal).
|
|
|
|
|
|
|
|
|
|
@ -70,7 +70,7 @@ or perhaps even a proposition itself rather than its proof),
|
|
|
|
|
then `rw` is not the tactic you want to use. For example,
|
|
|
|
|
`rw (P = Q)` is never correct: `P = Q` is the true-false
|
|
|
|
|
statement itself, not the proof.
|
|
|
|
|
If `h : P = Q` is its proof, then `rw h` will work.
|
|
|
|
|
If `h : P = Q` is its proof, then `rw [h]` will work.
|
|
|
|
|
|
|
|
|
|
Pro tip 1: If `h : A = B` and you want to change
|
|
|
|
|
`B`s to `A`s instead, try `rw ←h` (get the arrow with `\\l` and
|
|
|
|
|
@ -80,7 +80,9 @@ note that this is a small letter L, not a number 1).
|
|
|
|
|
If it looks like this in the top right hand box:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Objects:
|
|
|
|
|
x y : ℕ
|
|
|
|
|
Assumptions:
|
|
|
|
|
h : x = y + y
|
|
|
|
|
Goal:
|
|
|
|
|
succ (x + 0) = succ (y + y)
|
|
|
|
|
@ -88,14 +90,14 @@ Goal:
|
|
|
|
|
|
|
|
|
|
then
|
|
|
|
|
|
|
|
|
|
`rw add_zero,`
|
|
|
|
|
`rw [add_zero]`
|
|
|
|
|
|
|
|
|
|
will change the goal into `⊢ succ x = succ (y + y)`, and then
|
|
|
|
|
will change the goal into `succ x = succ (y + y)`, and then
|
|
|
|
|
|
|
|
|
|
`rw h,`
|
|
|
|
|
`rw [h]`
|
|
|
|
|
|
|
|
|
|
will change the goal into `⊢ succ (y + y) = succ (y + y)`, which
|
|
|
|
|
can be solved with `refl,`.
|
|
|
|
|
will change the goal into `succ (y + y) = succ (y + y)`, which
|
|
|
|
|
can be solved with `rfl`.
|
|
|
|
|
|
|
|
|
|
### Example:
|
|
|
|
|
|
|
|
|
|
@ -103,13 +105,15 @@ You can use `rw` to change a hypothesis as well.
|
|
|
|
|
For example, if your local context looks like this:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Objects:
|
|
|
|
|
x y : ℕ
|
|
|
|
|
Assumptions:
|
|
|
|
|
h1 : x = y + 3
|
|
|
|
|
h2 : 2 * y = x
|
|
|
|
|
Goal:
|
|
|
|
|
y = 3
|
|
|
|
|
```
|
|
|
|
|
then `rw h1 at h2` will turn `h2` into `h2 : 2 * y = y + 3`.
|
|
|
|
|
then `rw [h1] at h2` will turn `h2` into `h2 : 2 * y = y + 3`.
|
|
|
|
|
|
|
|
|
|
## Game modifications
|
|
|
|
|
|
|
|
|
|
|