File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed
src/Lean/Meta/Tactic/Grind Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ private def getAssignmentExt? (e : Expr) : GoalM (Option Rat) := do
1616 if let some val ← getAssignment? (← get) e then
1717 -- Easy case when `e : Int`
1818 return some val
19+ /-
20+ **Note** : The following code assumes that instantiated mvars occurring in types
21+ have been instantiated.
22+ -/
1923 let type ← inferType e
2024 if type == Int.mkType then
2125 -- It should have been handled in the previous getAssignment?
Original file line number Diff line number Diff line change @@ -270,6 +270,11 @@ See issue #11806 for a motivating example.
270270def withProtectedMCtx [Monad m] [MonadControlT MetaM m] [MonadLiftT MetaM m]
271271 [MonadExcept Exception m] [MonadRuntimeException m]
272272 (abstractProof : Bool) (mvarId : MVarId) (k : MVarId → m α) : m α := do
273+ /-
274+ **Note** : `instantiateGoalMVars` here also instantiates mvars occurring in hypotheses.
275+ This is particularly important when using `grind -revert`.
276+ -/
277+ let mvarId ← mvarId.instantiateGoalMVars
273278 let mvarId ← mvarId.abstractMVars
274279 let mvarId ← mvarId.clearImplDetails
275280 tryCatchRuntimeEx (main mvarId) fun ex => do
Original file line number Diff line number Diff line change @@ -19,6 +19,18 @@ def _root_.Lean.MVarId.ensureNoMVar (mvarId : MVarId) : MetaM Unit := do
1919 if type.hasExprMVar then
2020 throwTacticEx `grind mvarId "goal contains metavariables"
2121
22+ /--
23+ Instantiates metavariables occurring in the target and hypotheses.
24+ -/
25+ def _root_.Lean.MVarId.instantiateGoalMVars (mvarId : MVarId) : MetaM MVarId := do
26+ mvarId.checkNotAssigned `grind
27+ let mvarDecl ← mvarId.getDecl
28+ let lctx ← instantiateLCtxMVars mvarDecl.lctx
29+ let type ← Lean.instantiateMVars mvarDecl.type
30+ let mvarNew ← mkFreshExprMVarAt lctx mvarDecl.localInstances type .syntheticOpaque mvarDecl.userName
31+ mvarId.assign mvarNew
32+ return mvarNew.mvarId!
33+
2234/-- Abstracts metavariables occurring in the target. -/
2335def _root_.Lean.MVarId.abstractMVars (mvarId : MVarId) : MetaM MVarId := do
2436 mvarId.checkNotAssigned `grind
Original file line number Diff line number Diff line change 1+ namespace Nat
2+
3+ def ascFactorial (n : Nat) : Nat → Nat
4+ | 0 => 1
5+ | k + 1 => (n + k) * ascFactorial n k
6+
7+ def descFactorial (n : Nat) : Nat → Nat
8+ | 0 => 1
9+ | k + 1 => (n - k) * descFactorial n k
10+
11+ theorem descFactorial_of_lt {n : Nat} : ∀ {k : Nat}, n < k → n.descFactorial k = 0 := by sorry
12+
13+ theorem add_descFactorial_eq_ascFactorial' (n : Nat) :
14+ ∀ k : Nat, (n + k - 1 ).descFactorial k = n.ascFactorial k := by sorry
15+
16+ def ascFactorialBinary (n k : Nat) : Nat :=
17+ match k with
18+ | 0 => 1
19+ | 1 => n
20+ | k@(_ + 2 ) => ascFactorialBinary n (k / 2 ) * ascFactorialBinary (n + k / 2 ) ((k + 1 ) / 2 )
21+
22+ theorem ascFactorial_eq_ascFactorialBinary : ascFactorial = ascFactorialBinary := sorry
23+
24+ def descFactorialBinary (n k : Nat) : Nat :=
25+ if n < k then 0
26+ else ascFactorialBinary (n - k + 1 ) k
27+
28+ theorem descFactorial_eq_descFactorialBinary : descFactorial = descFactorialBinary := by
29+ ext n k
30+ rw [descFactorialBinary]
31+ split <;> rename_i h
32+ · rw [descFactorial_of_lt h]
33+ · rw [← ascFactorial_eq_ascFactorialBinary, ← add_descFactorial_eq_ascFactorial']
34+ grind
35+
36+ end Nat
You can’t perform that action at this time.
0 commit comments