refactor(library): rename repeat ==> iterate

Reason: we will implement a new `repeat` tactic.
This commit is contained in:
Leonardo de Moura 2017-12-04 12:34:59 -08:00
parent 7b97e82fb3
commit 75aa94b34c
14 changed files with 45 additions and 45 deletions

View file

@ -11,7 +11,7 @@ namespace tactic
namespace interactive
meta def blast_disjs : tactic unit :=
focus1 $ repeat $ any_goals $ any_hyp $ λ h, do
focus1 $ iterate $ any_goals $ any_hyp $ λ h, do
t ← infer_type h,
guard (t.is_or ≠ none),
tactic.cases h [h.local_pp_name, h.local_pp_name]
@ -50,13 +50,13 @@ meta def is_searchable_constructor_app : expr → bool
| _ := ff
meta def apply_is_searchable_constructors : tactic unit :=
repeat $ any_goals $ do
iterate $ any_goals $ do
t ← target,
guard $ is_searchable_constructor_app t,
constructor
meta def destruct_is_searchable_hyps : tactic unit :=
repeat $ any_goals $ any_hyp $ λ h, do
iterate $ any_goals $ any_hyp $ λ h, do
t ← infer_type h,
guard $ is_searchable_constructor_app t,
cases h,

View file

@ -657,10 +657,10 @@ inductive is_bad_red_black : rbnode α → nat → Prop
| bad_red {c₁ c₂ n l r v} (rb_l : is_red_black l c₁ n) (rb_r : is_red_black r c₂ n) : is_bad_red_black (red_node l v r) n
lemma balance1_rb {l r t : rbnode α} {y v : α} {c_l c_r c_t n} : is_red_black l c_l n → is_red_black r c_r n → is_red_black t c_t n → ∃ c, is_red_black (balance1 l y r v t) c (succ n) :=
by intros h₁ h₂ h₃; cases h₁; cases h₂; repeat {assumption <|> constructor}
by intros h₁ h₂ h₃; cases h₁; cases h₂; iterate {assumption <|> constructor}
lemma balance2_rb {l r t : rbnode α} {y v : α} {c_l c_r c_t n} : is_red_black l c_l n → is_red_black r c_r n → is_red_black t c_t n → ∃ c, is_red_black (balance2 l y r v t) c (succ n) :=
by intros h₁ h₂ h₃; cases h₁; cases h₂; repeat {assumption <|> constructor}
by intros h₁ h₂ h₃; cases h₁; cases h₂; iterate {assumption <|> constructor}
lemma balance1_node_rb {t s : rbnode α} {y : α} {c n} : is_bad_red_black t n → is_red_black s c n → ∃ c, is_red_black (balance1_node t y s) c (succ n) :=
by intros h _; cases h; simp [balance1_node]; apply balance1_rb; assumption'
@ -685,7 +685,7 @@ variable (lt)
lemma ins_rb {t : rbnode α} (x) : ∀ {c n} (h : is_red_black t c n), ins_rb_result (ins lt t x) c n :=
begin
apply ins.induction lt t x; intros; cases h; simp [ins, *, ins_rb_result],
{ repeat { constructor } },
{ iterate { constructor } },
{ specialize ih rb_l, cases ih, constructor, assumption' },
{ constructor, assumption' },
{ specialize ih rb_r, cases ih, constructor, assumption' },

View file

@ -33,7 +33,7 @@ def drop (n : nat) (s : stream α) : stream α :=
s n
protected theorem eta (s : stream α) : head s :: tail s = s :=
funext (λ i, begin cases i, repeat {refl} end)
funext (λ i, begin cases i; refl end)
theorem nth_zero_cons (a : α) (s : stream α) : nth 0 (a :: s) = a := rfl
@ -154,7 +154,7 @@ exists.intro 0 rfl
theorem const_eq (a : α) : const a = a :: const a :=
begin
apply stream.ext, intro n,
cases n, repeat {refl}
cases n; refl
end
theorem tail_const (a : α) : tail (const a) = const a :=
@ -217,7 +217,7 @@ assume hh ht₁ ht₂, eq_of_bisim
(λ s₁ s₂, head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂)
(λ s₁ s₂ ⟨h₁, h₂, h₃⟩,
begin
constructor, exact h₁, rw [← h₂, ← h₃], repeat {constructor, repeat {assumption}}
constructor, exact h₁, rw [← h₂, ← h₃], iterate { constructor, iterate { assumption } }
end)
(and.intro hh (and.intro ht₁ ht₂))

View file

@ -24,7 +24,7 @@ solve1 $ intros
>> try `[apply le_of_not_le, assumption]
meta def tactic.interactive.min_tac (a b : interactive.parse lean.parser.pexpr) : tactic unit :=
`[by_cases (%%a ≤ %%b), repeat {min_tac_step}]
`[by_cases (%%a ≤ %%b), iterate {min_tac_step}]
lemma min_le_left (a b : α) : min a b ≤ a :=
by min_tac a b
@ -451,10 +451,10 @@ lemma abs_abs_sub_abs_le_abs_sub (a b : α) : abs (abs a - abs b) ≤ abs (a - b
begin
apply nonneg_le_nonneg_of_squares_le,
apply abs_nonneg,
repeat {rw abs_sub_square},
repeat {rw abs_mul_abs_self},
iterate {rw abs_sub_square},
iterate {rw abs_mul_abs_self},
apply sub_le_sub_left,
repeat {rw mul_assoc},
iterate {rw mul_assoc},
apply mul_le_mul_of_nonneg_left,
rw [← abs_mul],
apply le_abs_self,

View file

@ -162,7 +162,7 @@ iff.mpr (int.lt_iff_le_and_ne _ _)
protected lemma mul_nonneg {a b : } (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
le.elim ha (assume n, assume hn,
le.elim hb (assume m, assume hm,
le.intro (show 0 + ↑n * ↑m = a * b, begin rw [← hn, ← hm], repeat {rw zero_add} end)))
le.intro (show 0 + ↑n * ↑m = a * b, begin rw [← hn, ← hm], simp [zero_add] end)))
protected lemma mul_pos {a b : } (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
lt.elim ha (assume n, assume hn,

View file

@ -428,7 +428,7 @@ protected lemma bit0_inj : ∀ {n m : }, bit0 n = bit0 m → n = m
| (n+1) (m+1) h :=
have succ (succ (n + n)) = succ (succ (m + m)),
begin unfold bit0 at h, simp [add_one, add_succ, succ_add] at h, exact h end,
have n + n = m + m, by repeat {injection this with this},
have n + n = m + m, by iterate { injection this with this },
have n = m, from bit0_inj this,
by rw this

View file

@ -526,7 +526,7 @@ meta def add_coinductive_predicate
(eqs ++ [eq']).mmap' subst
else skip,
eapply ((const r.func_nm u_params).app_of_list $ ps ++ fs),
repeat assumption)
iterate assumption)
end),
exact h)),
@ -588,7 +588,7 @@ do
solve1 (do
target >>= instantiate_mvars >>= change, -- TODO: bug in existsi & constructor when mvars in hyptohesis
bs.mmap existsi,
repeat econstructor),
iterate econstructor),
-- clean up remaining coinduction steps
all_goals (do

View file

@ -107,7 +107,7 @@ do (r, lhs, rhs) ← target_lhs_rhs,
return ()
meta def funext : conv unit :=
repeat $ do
iterate $ do
(r, lhs, rhs) ← target_lhs_rhs,
guard (r = `eq),
(expr.lam n _ _ _) ← return lhs,

View file

@ -599,10 +599,10 @@ meta def contradiction : tactic unit :=
tactic.contradiction
/--
`repeat { t }` repeatedly applies tactic `t` until `t` fails. The compound tactic always succeeds.
`iterate { t }` repeatedly applies tactic `t` until `t` fails. The compound tactic always succeeds.
-/
meta def repeat : itactic → tactic unit :=
tactic.repeat
meta def iterate : itactic → tactic unit :=
tactic.iterate
/--
`try { t }` tries to apply tactic `t`, but succeeds whether or not `t` succeeds.

View file

@ -42,6 +42,6 @@ target >>= relation_lhs_rhs
/-- Try to apply subst exhaustively -/
meta def subst_vars : tactic unit :=
focus1 $ repeat (any_hyp subst) >> try (reflexivity reducible)
focus1 $ iterate (any_hyp subst) >> try (reflexivity reducible)
end tactic

View file

@ -16,7 +16,7 @@ meta def skip : smt_tactic unit :=
return ()
meta def solve_goals : smt_tactic unit :=
repeat close
iterate close
meta def step {α : Type} (tac : smt_tactic α) : smt_tactic unit :=
tac >> solve_goals
@ -222,8 +222,8 @@ meta def try (t : itactic) : smt_tactic unit :=
smt_tactic.try t
/-- Keep applying the given tactic until it fails. -/
meta def repeat (t : itactic) : smt_tactic unit :=
smt_tactic.repeat t
meta def iterate (t : itactic) : smt_tactic unit :=
smt_tactic.iterate t
/-- Apply the given tactic to all remaining goals. -/
meta def all_goals (t : itactic) : smt_tactic unit :=
@ -256,7 +256,7 @@ smt_tactic.eblast
/-- Keep applying heuristic instantiation using the given lemmas until the current goal is solved, or it fails. -/
meta def eblast_using (l : parse pexpr_list_or_texpr) : smt_tactic unit :=
do hs ← add_hinst_lemmas_from_pexprs reducible ff l hinst_lemmas.mk,
smt_tactic.repeat (smt_tactic.ematch_using hs >> smt_tactic.try smt_tactic.close)
smt_tactic.iterate (smt_tactic.ematch_using hs >> smt_tactic.try smt_tactic.close)
meta def guard_expr_eq (t : expr) (p : parse $ tk ":=" *> texpr) : smt_tactic unit :=
do e ← to_expr p, guard (expr.alpha_eqv t e)

View file

@ -124,7 +124,7 @@ do focus1 $ using_smt_with {em_attr := cfg.attr_name} $
do
add_lemmas_from_facts,
add_lemmas extra,
repeat_at_most cfg.max_rounds (ematch >> try smt_tactic.close),
iterate_at_most cfg.max_rounds (ematch >> try smt_tactic.close),
(done >> return cc_state.mk)
<|>
to_cc_state

View file

@ -155,21 +155,21 @@ meta def try {α : Type} (t : smt_tactic α) : smt_tactic unit :=
(λ ⟨a, new_ss⟩, result.success ((), new_ss))
(λ e ref s', result.success ((), ss) ts)
/-- `repeat_at_most n t`: repeat the given tactic at most n times or until t fails -/
meta def repeat_at_most : nat → smt_tactic unit → smt_tactic unit
/-- `iterate_at_most n t`: repeat the given tactic at most n times or until t fails -/
meta def iterate_at_most : nat → smt_tactic unit → smt_tactic unit
| 0 t := return ()
| (n+1) t := (do t, repeat_at_most n t) <|> return ()
| (n+1) t := (do t, iterate_at_most n t) <|> return ()
/-- `repeat_exactly n t` : execute t n times -/
meta def repeat_exactly : nat → smt_tactic unit → smt_tactic unit
/-- `iterate_exactly n t` : execute t n times -/
meta def iterate_exactly : nat → smt_tactic unit → smt_tactic unit
| 0 t := return ()
| (n+1) t := do t, repeat_exactly n t
| (n+1) t := do t, iterate_exactly n t
meta def repeat : smt_tactic unit → smt_tactic unit :=
repeat_at_most 100000
meta def iterate : smt_tactic unit → smt_tactic unit :=
iterate_at_most 100000
meta def eblast : smt_tactic unit :=
repeat (ematch >> try close)
iterate (ematch >> try close)
open tactic
@ -404,7 +404,7 @@ open smt_tactic
meta def using_smt {α} (t : smt_tactic α) (cfg : smt_config := {}) : tactic α :=
do ss ← smt_state.mk cfg,
(a, _) ← (do a ← t, repeat close, return a) ss,
(a, _) ← (do a ← t, iterate close, return a) ss,
return a
meta def using_smt_with {α} (cfg : smt_config) (t : smt_tactic α) : tactic α :=

View file

@ -114,18 +114,18 @@ meta def success_if_fail {α : Type u} (t : tactic α) : tactic unit :=
end
open nat
/-- (repeat_at_most n t): repeat the given tactic at most n times or until t fails -/
meta def repeat_at_most : nat → tactic unit → tactic unit
/-- (iterate_at_most n t): repeat the given tactic at most n times or until t fails -/
meta def iterate_at_most : nat → tactic unit → tactic unit
| 0 t := skip
| (succ n) t := (do t, repeat_at_most n t) <|> skip
| (succ n) t := (do t, iterate_at_most n t) <|> skip
/-- (repeat_exactly n t) : execute t n times -/
meta def repeat_exactly : nat → tactic unit → tactic unit
/-- (iterate_exactly n t) : execute t n times -/
meta def iterate_exactly : nat → tactic unit → tactic unit
| 0 t := skip
| (succ n) t := do t, repeat_exactly n t
| (succ n) t := do t, iterate_exactly n t
meta def repeat : tactic unit → tactic unit :=
repeat_at_most 100000
meta def iterate : tactic unit → tactic unit :=
iterate_at_most 100000
meta def returnopt (e : option α) : tactic α :=
λ s, match e with