File tree Expand file tree Collapse file tree 3 files changed +70
-4
lines changed
src/Lean/Meta/Tactic/Grind Expand file tree Collapse file tree 3 files changed +70
-4
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,15 @@ def loop (n : Nat) (x : Action) : Action := fun goal _ kp =>
123123Runs action `a` on the given `goal`.
124124-/
125125def run (goal : Goal) (a : Action) : GrindM ActionResult := do
126- let k := fun goal => if goal.inconsistent then return .closed [] else return .stuck [goal]
126+ let k := fun goal => do
127+ if goal.inconsistent then
128+ return .closed []
129+ else if (← getConfig).trace then
130+ goal.mvarId.admit
131+ let sorryTac ← `(grind| sorry )
132+ return .closed [sorryTac]
133+ else
134+ return .stuck [goal]
127135 a goal k k
128136
129137/--
Original file line number Diff line number Diff line change @@ -294,7 +294,12 @@ hypotheses introduced during case analysis. If the proof is of the form `fun _ _
294294-/
295295private def getFalseProof? (mvarId : MVarId) : MetaM (Option Expr) := mvarId.withContext do
296296 let proof ← instantiateMVars (mkMVar mvarId)
297- go proof
297+ if proof.hasSyntheticSorry then
298+ /- **Note** : We do not perform non-chronological backtracking if the proof
299+ contains synthetic `sorry`. -/
300+ return none
301+ else
302+ go proof
298303where
299304 go (proof : Expr) : MetaM (Option Expr) := do
300305 match_expr proof with
@@ -344,11 +349,25 @@ private def isCompressibleAlts (alts : Array (List (TSyntax `grind))) : Bool :=
344349 else
345350 true
346351
352+ def isSorryAlt (alt : List (TSyntax `grind)) : Bool :=
353+ match alt with
354+ | [tac] => match tac with
355+ | `(grind| sorry ) => true
356+ | _ => false
357+ | _ => false
358+
347359private def mkCasesResultSeq (cases : TSyntax `grind) (alts : Array (List (TSyntax `grind)))
348360 (compress : Bool) : CoreM (List (TSyntax `grind)) := do
349361 if compress && isCompressibleAlts alts then
350- if h : alts.size > 0 then
351- return [(← mkCasesAndThen cases alts[0 ]!)]
362+ if alts.size > 0 then
363+ let firstAlt := alts[0 ]!
364+ if isSorryAlt firstAlt then
365+ /-
366+ **Note** : It is a bit pointless to return a script of the form `cases #<anchor> <;> sorry`
367+ -/
368+ return firstAlt
369+ else
370+ return [(← mkCasesAndThen cases firstAlt)]
352371 else
353372 return [cases]
354373 else
Original file line number Diff line number Diff line change @@ -60,3 +60,42 @@ example (as bs cs : Array α) (v₁ v₂ : α)
6060 (h₆ : j < as.size)
6161 : cs[j] = as[j] := by
6262 grind => finish?
63+
64+ set_option warn.sorry false
65+
66+ /--
67+ info: Try this:
68+ [ apply ] ⏎
69+ cases #c4b6
70+ next =>
71+ ring
72+ cases #8c9f
73+ next => ring
74+ next => sorry
75+ next =>
76+ ring
77+ cases #8c9f
78+ next => ring
79+ next => sorry
80+ -/
81+ #guard_msgs in
82+ example {α : Type } [CommRing α] (a b c d e : α) :
83+ (a^2 = c * b ∨ e^2 = d * c) →
84+ (b^2 = d*c ∨ b^2 = c*d) →
85+ a*b*(b*a) = c^2 *b*d := by
86+ grind => finish?
87+
88+ /--
89+ info: Try this:
90+ [ apply ] ⏎
91+ instantiate only [= Nat.min_def]
92+ cases #7640
93+ next => sorry
94+ next =>
95+ ring
96+ lia
97+ -/
98+ #guard_msgs in
99+ example (as : Array α) (lo hi i j : Nat) (h₁ : lo ≤ i) (_ : i < j) (_ : j ≤ hi) (_ : j < as.size)
100+ (_ : ¬as.size = 0 ) : min lo (as.size - 1 ) < i := by
101+ grind => finish?
You can’t perform that action at this time.
0 commit comments