leanprover / leanprover/reference-manual

Explain the transformation `rewrite` attempts step by step

Open
#232 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

doc-request
Dominant language
Lean
Stars
129
Forks
67
Avg merge
1d 15h
Merged PRs (30d)
16

Description

What question should the reference manual answer?

How does the rewrite tactic proceed? Which steps would I perform if I were to do it manually?

Additional context

The improved error message "error: tactic 'rewrite' failed, motive is not type correct" is really helpful and contains the explanation I was looking for (reformatted for better presentation):

First, it looks for all 'a' in 'e'.
Second, it tries to abstract these occurrences of 'a' to create a function 'm := fun _a => ...', called the *motive*, with the property that 'm a' is definitionally equal to 'e'.
Third, we observe that 'congrArg' implies that 'm a = m b', which can be used with lemmas such as 'Eq.mpr' to change the goal.
However, if 'e' depends on specific properties of 'a', then the motive 'm' might not typecheck.

Possible solutions: 
* Use rewrite's 'occs' configuration option to limit which occurrences are rewritten.
* Use 'simp' or 'conv' mode, which have strategies for certain kinds of dependencies (these tactics can handle proofs and 'Decidable' instances whose types depend on the rewritten term, and 'simp' can apply user-defined '@[congr]' theorems as well).

Perhaps some of this wisdom could be added to the reference manual entry for rewrite. This improved entry could include the example from test case motiveNotTypeCorrect and perhaps exemplify the workarounds.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reference manual's linked rewrite entry and read tests/lean/motiveNotTypeCorect.lean, especially the motiveNotTypeCorrect test case. Document the tactic's step-by-step behavior, the motive type-checking failure, and the occs, simp, and conv workarounds, including the example from the test.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.