Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit eb52e13

Browse files
committed
First attempt at nat_cases
1 parent 315a642 commit eb52e13

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/tactic/nat_cases.lean

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import tactic.interactive
2+
3+
open tactic
4+
meta def get_nat_ineq : expr → tactic (expr × expr × ℕ)
5+
| `(%%val < %%ebound) := prod.mk val <$> (prod.mk ebound <$> eval_expr ℕ ebound)
6+
| `(%%val ≤ %%ebound) := prod.mk val <$> (prod.mk ebound <$> nat.succ <$> eval_expr ℕ ebound)
7+
| _ := failed
8+
9+
namespace tactic.interactive
10+
open lean.parser interactive
11+
meta def nat_cases (h : parse ident) : tactic unit :=
12+
focus1 $ do
13+
e ← get_local h,
14+
⟨val, ⟨ebound, bound⟩⟩ ← infer_type e >>= get_nat_ineq,
15+
expr.local_const _ nval _ _ ← return val,
16+
iterate_at_most bound $ do {
17+
val ← get_local nval,
18+
cases_core val,
19+
clear_lst [h],
20+
swap },
21+
e ← get_local h,
22+
val ← get_local nval,
23+
proof ← to_expr ```(absurd %%e (not_lt_of_ge $ nat.le_add_left %%ebound %%val)),
24+
tactic.exact proof,
25+
goals ← get_goals,
26+
set_goals goals.reverse
27+
28+
end tactic.interactive
29+
30+
example (n : ℕ) (h : n ≤ 4) : n ≤ 10 :=
31+
begin
32+
nat_cases h,
33+
do { goals ← get_goals, guard (goals.length = 5) },
34+
all_goals { exact dec_trivial},
35+
end
36+
37+
example (n : ℕ) (h : n < 4) : n ≤ 10 :=
38+
begin
39+
nat_cases h,
40+
do { goals ← get_goals, guard (goals.length = 4) },
41+
all_goals { exact dec_trivial},
42+
end

0 commit comments

Comments
 (0)