Skip to content

Instantly share code, notes, and snippets.

@cipher1024
Created May 30, 2018 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipher1024/72af1694ce395d7162bab1a72c1f9c56 to your computer and use it in GitHub Desktop.
Save cipher1024/72af1694ce395d7162bab1a72c1f9c56 to your computer and use it in GitHub Desktop.
Tactic for adding assumptions about every subtractions in the goal
import tactic.norm_num
meta def expr.find_all (f : expr → list (expr × expr)) (e : expr) : list (expr × expr) :=
e.fold [] (λ x _ xs, f x ++ xs)
namespace tactic
meta def is_sub : expr → list (expr × expr)
| `(%%x - %%y) := [(x,y)]
| _ := []
meta def is_div : expr → list (expr × expr)
| `(%%x / %%y) := [(x,y)]
| _ := []
namespace interactive
meta def assume_sub_nneg (discharger : itactic) : tactic unit :=
focus1 $ do
g ← target,
hs ← (g.find_all is_sub).mmap (λ ⟨x,y⟩, do
h ← get_unused_name `h,
to_expr ``(%%y ≤ %%x) >>= assert h,
[v₀, v₁] ← get_goals,
set_goals [v₀],
discharger,
vs ← get_goals,
set_goals [v₁],
return vs ),
[g'] ← get_goals,
set_goals $ g' :: hs.join,
return ()
end interactive
end tactic
example : 5 - (3 - 1) = (3 : ℕ) :=
begin
assume_sub_nneg { norm_num },
-- h : 1 ≤ 3,
-- h_1 : 3 - 1 ≤ 5
-- ⊢ 5 - (3 - 1) = 3
admit,
end
example : 5 - (3 - 1) = (3 : ℕ) :=
begin
assume_sub_nneg { },
-- 3 goals
-- h : 1 ≤ 3,
-- h_1 : 3 - 1 ≤ 5
-- ⊢ 5 - (3 - 1) = 3
-- ⊢ 1 ≤ 3
-- h : 1 ≤ 3
-- ⊢ 3 - 1 ≤ 5
repeat { admit },
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment