fix(library/standard): orelse notation, avoid conflict with inductive datatype declaration
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
e0501104e2
commit
a97f82be1a
8 changed files with 46 additions and 16 deletions
|
@ -39,11 +39,12 @@ definition apply {B : Type} (b : B) : tactic := builtin_tactic
|
|||
definition unfold {B : Type} (b : B) : tactic := builtin_tactic
|
||||
definition exact {B : Type} (b : B) : tactic := builtin_tactic
|
||||
definition trace (s : string) : tactic := builtin_tactic
|
||||
infixl `;`:200 := and_then
|
||||
infixl `|`:100 := or_else
|
||||
precedence `;`:200
|
||||
infixl ; := and_then
|
||||
notation `!` t:max := repeat t
|
||||
notation `⟦` t `⟧` := apply t
|
||||
definition try (t : tactic) : tactic := t | id
|
||||
-- [ t_1 | ... | t_n ] notation
|
||||
notation `[` h:100 `|` r:(foldl 100 `|` (e r, or_else r e) h) `]` := r
|
||||
definition try (t : tactic) : tactic := [ t | id ]
|
||||
notation `?` t:max := try t
|
||||
definition repeat1 (t : tactic) : tactic := t ; !t
|
||||
definition focus (t : tactic) : tactic := focus_at t 0
|
||||
|
|
|
@ -3,7 +3,7 @@ using tactic
|
|||
|
||||
theorem tst (a b : Bool) (H : a ↔ b) : b ↔ a
|
||||
:= by apply iff_intro;
|
||||
⟦ assume Hb, iff_mp_right H Hb ⟧;
|
||||
⟦ assume Ha, iff_mp_left H Ha ⟧
|
||||
apply (assume Hb, iff_mp_right H Hb);
|
||||
apply (assume Ha, iff_mp_left H Ha)
|
||||
|
||||
check tst
|
||||
|
|
|
@ -4,6 +4,6 @@ using tactic
|
|||
theorem tst (a b : Bool) (H : a ↔ b) : b ↔ a
|
||||
:= have H1 [fact] : a → b, -- We need to mark H1 as fact, otherwise it is not visible by tactics
|
||||
from iff_elim_left H,
|
||||
by ⟦ iff_intro ⟧;
|
||||
⟦ assume Hb, iff_mp_right H Hb ⟧;
|
||||
⟦ assume Ha, H1 Ha ⟧
|
||||
by apply iff_intro;
|
||||
apply (assume Hb, iff_mp_right H Hb);
|
||||
apply (assume Ha, H1 Ha)
|
||||
|
|
|
@ -2,7 +2,7 @@ import standard
|
|||
using tactic
|
||||
|
||||
definition basic_tac : tactic
|
||||
:= repeat (apply @and_intro | apply @not_intro | assumption)
|
||||
:= repeat [apply @and_intro | apply @not_intro | assumption]
|
||||
|
||||
reset_proof_qed basic_tac -- basic_tac is automatically applied to each element of a proof-qed block
|
||||
|
||||
|
|
|
@ -2,4 +2,4 @@ import standard
|
|||
using tactic
|
||||
|
||||
theorem T (a b c d : Bool) (Ha : a) (Hb : b) (Hc : c) (Hd : d) : a ∧ b ∧ c ∧ d
|
||||
:= by fixpoint (λ f, (apply @and_intro; f) | (assumption; f) | id)
|
||||
:= by fixpoint (λ f, [apply @and_intro; f | assumption; f | id])
|
||||
|
|
30
tests/lean/run/tactic23.lean
Normal file
30
tests/lean/run/tactic23.lean
Normal file
|
@ -0,0 +1,30 @@
|
|||
import standard
|
||||
using num (num pos_num num_rec pos_num_rec)
|
||||
using tactic
|
||||
|
||||
inductive nat : Type :=
|
||||
| zero : nat
|
||||
| succ : nat → nat
|
||||
|
||||
definition add [inline] (a b : nat) : nat
|
||||
:= nat_rec a (λ n r, succ r) b
|
||||
infixl `+`:65 := add
|
||||
|
||||
definition one [inline] := succ zero
|
||||
|
||||
-- Define coercion from num -> nat
|
||||
-- By default the parser converts numerals into a binary representation num
|
||||
definition pos_num_to_nat [inline] (n : pos_num) : nat
|
||||
:= pos_num_rec one (λ n r, r + r) (λ n r, r + r + one) n
|
||||
definition num_to_nat [inline] (n : num) : nat
|
||||
:= num_rec zero (λ n, pos_num_to_nat n) n
|
||||
coercion num_to_nat
|
||||
|
||||
-- Now we can write 2 + 3, the coercion will be applied
|
||||
check 2 + 3
|
||||
|
||||
-- Define an assump as an alias for the eassumption tactic
|
||||
definition assump : tactic := eassumption
|
||||
|
||||
theorem T {p : nat → Bool} {a : nat } (H : p (a+1)) : ∃ x, p (succ x)
|
||||
:= by apply exists_intro; assump
|
|
@ -2,8 +2,8 @@ import standard
|
|||
using tactic
|
||||
|
||||
theorem tst {A B : Bool} (H1 : A) (H2 : B) : A
|
||||
:= by trace "first"; state; now |
|
||||
trace "second"; state; fail |
|
||||
trace "third"; assumption
|
||||
:= by [trace "first"; state; now |
|
||||
trace "second"; state; fail |
|
||||
trace "third"; assumption]
|
||||
|
||||
check tst
|
|
@ -6,7 +6,6 @@ theorem tst {A B : Bool} (H1 : A) (H2 : B) : A ∧ B ∧ A
|
|||
check tst
|
||||
|
||||
theorem tst2 {A B : Bool} (H1 : A) (H2 : B) : A ∧ B ∧ A
|
||||
:= by !((apply @and_intro | assumption) ; trace "STEP"; state; trace "----------")
|
||||
:= by !([apply @and_intro | assumption] ; trace "STEP"; state; trace "----------")
|
||||
|
||||
check tst2
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue