leanprover-community / leanprover-community/mathlib4
Controlling `unfold_projs`
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 4.2k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
The unfold_projs tactic takes all class projection functions and tries to reduce them. For example, in the following,
example : default = 0 := by
unfold_projs
-- ⊢ Nat.zero = 0
recall that default is the projection Inhabited.default {α : Type} [self : Inhabited α] : α, and so the tactic sees @default ℕ instInhabitedNat and reduces this projection by unfolding instInhabitedNat.
The tactic is very simple. The implementation is less than 20 lines. It transform the entire expression by trying to apply the core function unfoldProjInst? to each subexpression.
However, this tactic unfolds projections indiscriminately. It would be nice to be able to control the unfolding.
Suggested features:
unfold_projs +singlePasscould do one level of unfolding. This could be implemented by having it usereturn .continue (← instantiateMVars node')instead ofreturn .visit (← instantiateMVars node')when that flag is set.unfold_projscould take a list of names of projections to unfold. For example,unfold_projs [default]could have it unfold only instances ofInhabited.default. Maybe alsounfold_projs [Inhabited]would unfold all projections associated toInhabited. I imagine that to implement this, it would be best to copy the code ofunfoldProjInst?, making a new version that takes a(p : ProjectionFunctionInfo -> Bool)predicate.- One might consider a more complicated version where
unfold_projstakes expressions. For example,unfold_projs [Inhabited Nat]might only unfold projections for the specified parameters. Or, e.g.,unfold_projs [HAdd Nat, Add Nat], to make sure onlyNatadditions are unfolded. The modifiedunfoldProjInst?should just need to have a(p : ProjectionFunctionInfo -> MetaM Bool)predicate for this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Mathlib/Tactic/DefEqTransformations.lean at the unfold_projs implementation and inspect the core unfoldProjInst? function. Determine which of the proposed controls is in scope, then define completion as unfold_projs honoring that control without changing its existing behavior; no test file is mentioned in the issue.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100