File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Lean.Elab.Tactic
2+
3+ open Lean Elab.Tactic Meta
4+
5+ partial def seqsolve (goal : MVarId) : TacticM Bool :=
6+ goal.withContext do
7+ if ← goal.assumptionCore then
8+ return true
9+
10+ if ← goal.contradictionCore {} then
11+ return true
12+
13+ let goalType ← goal.getType'
14+ if let .forallE _ _ _ _ := goalType then
15+ let (_, newGoal) ← goal.intro .anonymous
16+ replaceMainGoal [newGoal]
17+ let _ ← seqsolve newGoal
18+ return true
19+
20+ matchConstInduct goalType.getAppFn
21+ (fun _ => throwTacticEx `seqsolve goal "target is not an inductive datatype" )
22+ fun ival us => do
23+ for ctor in ival.ctors do
24+ try
25+ let newGoals ← goal.apply (Lean.mkConst ctor us) {}
26+ replaceMainGoal newGoals
27+ newGoals.forM $ fun newGoal => do
28+ if not $ ← seqsolve newGoal then
29+ failure
30+ catch _ =>
31+ pure ()
32+
33+ return false
34+
35+ elab "seqsolve" : tactic =>
36+ withMainContext do
37+ let goals ← getGoals
38+ goals.forM $ fun goal => do
39+ let _ ← seqsolve goal
40+
41+ example {φ : Prop } : φ → φ := by
42+ seqsolve
43+
44+ example {φ : Prop } (h : φ) : φ := by
45+ seqsolve
46+
47+ example {φ : Prop } : False → φ := by
48+ seqsolve
49+
50+ example {φ : Prop } : (φ → φ) ∧ (φ → φ) := by
51+ seqsolve
52+
53+ example {φ : Prop } : False ∨ (φ → φ) := by
54+ seqsolve
You can’t perform that action at this time.
0 commit comments