LibTactics一批便利的通用策略
(* 本章由 Arthur Charguéraud 维护 *)
本文件包含一组【策略|Tactic】,用以扩展 Rocq 标准发行版自带的内建策略。
它意在克服标准策略集的若干局限,
从而帮助用户写出更短、更稳健的脚本。
希望随时间推移,Rocq 策略会得到改进,
本文件终将变得无用。与此同时,
认真的 Rocq 用户大概会发现它非常有用。
本文件给出这些策略的实现与详细文档。
《软件基础》的读者无需阅读本文件;
建议改读名为 UseTactics.v 的章节,
它是 LibTactic 库中最实用策略的轻松入门。
所提供的主要特性有:
外部致谢:
- 更方便的【假设|Hypothesis】命名语法:引入与【反演|Inversion】 策略的输入只需类型为 Prop 的假设名,而非所有【变量|Variable】名。
- 真正支持操作 n 元【合取|Conjunction】、【析取|Disjunction】 与【存在量化|Existential Quantification】的策略, 隐蔽了底层实现基于二元命题这一事实。
- 便利的【自动化|Automation】支持:策略后跟符号 "~" 或 "*" 会对所产生的【子目标|Subgoal】调用自动化。 符号 "~" 表示 auto,"*" 表示 intuition eauto。 这些绑定可以定制。
- 提供正向链推策略,用变量或假设(或两者的混合) 来【实例化|Instantiation】【引理|Lemma】。
- 提供了更强大的 apply 实现 (它基于 refine,因而在转换方面表现更好)。
- 改进的反演策略,会替换标准反演机制产生的 变量上的等式。此外它支持消去依值类型的等式 (需要公理 K,即【证明无关性|Proof Irrelevance】的弱形式)。
- 节省写证明时间的策略:断言假设或子目标的策略, 以及改进的清除、重命名与排序假设的策略。
- 感谢 Xavier Leroy 提出策略 forward 的想法
- 感谢 Georges Gonthier 在 rapply 中的实现技巧
(* 从 LibBool 移除提示 trans_eq_bool 非常重要,
否则 eauto 会急剧变慢:
Lemma test : forall b, b = false.
time eauto 7. (* 失败就要花 4 秒多!*) *)
#[global]
Remove Hints Bool.trans_eq_bool : core.
否则 eauto 会急剧变慢:
Lemma test : forall b, b = false.
time eauto 7. (* 失败就要花 4 秒多!*) *)
#[global]
Remove Hints Bool.trans_eq_bool : core.
Ltac idcont tt :=
idtac.
idtac.
策略的可选实参
ltac_wilds 是另一个常量,通常用来模拟一连串 N 个通配符,
N 按上下文适当选取。记法是 ___。
Inductive ltac_Wilds : Set :=
| ltac_wilds : ltac_Wilds.
Notation "'___'" := ltac_wilds : ltac_scope.
Open Scope ltac_scope.
| ltac_wilds : ltac_Wilds.
Notation "'___'" := ltac_wilds : ltac_scope.
Open Scope ltac_scope.
gen_until_mark 对语境中的假设从底部开始
反复执行 generalize,一到达类型为 Mark 的假设即停止。
若 Mark 不出现在语境中则失败。
Ltac gen_until_mark :=
match goal with H: ?T ⊢ _ ⇒
match T with
| ltac_Mark ⇒ clear H
| _ ⇒ generalize H; clear H; gen_until_mark
end end.
match goal with H: ?T ⊢ _ ⇒
match T with
| ltac_Mark ⇒ clear H
| _ ⇒ generalize H; clear H; gen_until_mark
end end.
gen_until_mark_with_processing F 与 gen_until_mark 类似,
不同之处是在【泛化|Generalization】每条假设之前立即对其调用 F。
这对处理假设很有用。
Ltac gen_until_mark_with_processing cont :=
match goal with H: ?T ⊢ _ ⇒
match T with
| ltac_Mark ⇒ clear H
| _ ⇒ cont H; generalize H; clear H;
gen_until_mark_with_processing cont
end end.
match goal with H: ?T ⊢ _ ⇒
match T with
| ltac_Mark ⇒ clear H
| _ ⇒ cont H; generalize H; clear H;
gen_until_mark_with_processing cont
end end.
intro_until_mark 反复执行 intro 直到到达类型为 Mark 的假设。
它丢弃假设 Mark。
若 Mark 不作为假设出现在目标中则失败。
Ltac intro_until_mark :=
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| _ ⇒ intro; intro_until_mark
end.
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| _ ⇒ intro; intro_until_mark
end.
(* 注:或可尝试使用递归记法 *)
Notation "'>>'" :=
(@nil Boxer)
(at level 0)
: ltac_scope.
Notation "'>>' v1" :=
((boxer v1)::nil)
(at level 0, v1 at level 0)
: ltac_scope.
Notation "'>>' v1 v2" :=
((boxer v1)::(boxer v2)::nil)
(at level 0, v1 at level 0, v2 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3" :=
((boxer v1)::(boxer v2)::(boxer v3)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)
::(boxer v11)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0, v11 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)
::(boxer v11)::(boxer v12)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0, v11 at level 0,
v12 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)
::(boxer v11)::(boxer v12)::(boxer v13)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0, v11 at level 0,
v12 at level 0, v13 at level 0)
: ltac_scope.
Notation "'>>'" :=
(@nil Boxer)
(at level 0)
: ltac_scope.
Notation "'>>' v1" :=
((boxer v1)::nil)
(at level 0, v1 at level 0)
: ltac_scope.
Notation "'>>' v1 v2" :=
((boxer v1)::(boxer v2)::nil)
(at level 0, v1 at level 0, v2 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3" :=
((boxer v1)::(boxer v2)::(boxer v3)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)
::(boxer v11)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0, v11 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)
::(boxer v11)::(boxer v12)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0, v11 at level 0,
v12 at level 0)
: ltac_scope.
Notation "'>>' v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13" :=
((boxer v1)::(boxer v2)::(boxer v3)::(boxer v4)::(boxer v5)
::(boxer v6)::(boxer v7)::(boxer v8)::(boxer v9)::(boxer v10)
::(boxer v11)::(boxer v12)::(boxer v13)::nil)
(at level 0, v1 at level 0, v2 at level 0, v3 at level 0,
v4 at level 0, v5 at level 0, v6 at level 0, v7 at level 0,
v8 at level 0, v9 at level 0, v10 at level 0, v11 at level 0,
v12 at level 0, v13 at level 0)
: ltac_scope.
策略 list_boxer_of 输入一个项 E,
返回类型为「list boxer」的项,规则如下:
- 若 E 已是类型「list Boxer」,则返回 E;
- 否则返回列表 (boxer E)::nil。
Ltac list_boxer_of E :=
match type of E with
| List.list Boxer ⇒ constr:(E)
| _ ⇒ constr:((boxer E)::nil)
end.
match type of E with
| List.list Boxer ⇒ constr:(E)
| _ ⇒ constr:((boxer E)::nil)
end.
引理数据库
Inductive Ltac_database_token : Prop := ltac_database_token.
Definition ltac_database (D:Boxer) (T:Boxer) (A:Boxer) := Ltac_database_token.
Notation "'Register' D T" := (ltac_database (boxer D) (boxer T) _)
(at level 69, D at level 0, T at level 0).
Lemma ltac_database_provide : ∀ (A:Boxer) (D:Boxer) (T:Boxer),
ltac_database D T A.
Proof using. split. Qed.
Ltac Provide T := apply (@ltac_database_provide (boxer T)).
Ltac ltac_database_get D T :=
let A := fresh "TEMP" in evar (A:Boxer);
let H := fresh "TEMP" in
assert (H : ltac_database (boxer D) (boxer T) A);
[ subst A; auto
| subst A; match type of H with ltac_database _ _ (boxer ?L) ⇒
generalize L end; clear H ].
(* 关于 ltac_database_token 的一种可能替代实现的备注:
Inductive Ltac_database : Type :=
| ltac_database : forall A, A -> Ltac_database.
Implicit Arguments ltac_database A.
*)
Definition ltac_database (D:Boxer) (T:Boxer) (A:Boxer) := Ltac_database_token.
Notation "'Register' D T" := (ltac_database (boxer D) (boxer T) _)
(at level 69, D at level 0, T at level 0).
Lemma ltac_database_provide : ∀ (A:Boxer) (D:Boxer) (T:Boxer),
ltac_database D T A.
Proof using. split. Qed.
Ltac Provide T := apply (@ltac_database_provide (boxer T)).
Ltac ltac_database_get D T :=
let A := fresh "TEMP" in evar (A:Boxer);
let H := fresh "TEMP" in
assert (H : ltac_database (boxer D) (boxer T) A);
[ subst A; auto
| subst A; match type of H with ltac_database _ _ (boxer ?L) ⇒
generalize L end; clear H ].
(* 关于 ltac_database_token 的一种可能替代实现的备注:
Inductive Ltac_database : Type :=
| ltac_database : forall A, A -> Ltac_database.
Implicit Arguments ltac_database A.
*)
rm_term E 移除一条类型与 E 相同的假设。
Ltac rm_term E :=
let T := type of E in
match goal with H: T ⊢ _ ⇒ try clear H end.
let T := type of E in
match goal with H: T ⊢ _ ⇒ try clear H end.
rm_inside E 对 E 中找到的任何形如 rm Ei 的子项
调用 rm_term Ei
Ltac rm_inside E :=
let go E := rm_inside E in
match E with
| rm ?X ⇒ rm_term X
| ?X1 ?X2 ⇒
go X1; go X2
| ?X1 ?X2 ?X3 ⇒
go X1; go X2; go X3
| ?X1 ?X2 ?X3 ?X4 ⇒
go X1; go X2; go X3; go X4
| ?X1 ?X2 ?X3 ?X4 ?X5 ⇒
go X1; go X2; go X3; go X4; go X5
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ⇒
go X1; go X2; go X3; go X4; go X5; go X6
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X8 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7; go X8
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X8 ?X9 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7; go X8; go X9
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X8 ?X9 ?X10 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7; go X8; go X9; go X10
| _ ⇒ idtac
end.
let go E := rm_inside E in
match E with
| rm ?X ⇒ rm_term X
| ?X1 ?X2 ⇒
go X1; go X2
| ?X1 ?X2 ?X3 ⇒
go X1; go X2; go X3
| ?X1 ?X2 ?X3 ?X4 ⇒
go X1; go X2; go X3; go X4
| ?X1 ?X2 ?X3 ?X4 ?X5 ⇒
go X1; go X2; go X3; go X4; go X5
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ⇒
go X1; go X2; go X3; go X4; go X5; go X6
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X8 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7; go X8
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X8 ?X9 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7; go X8; go X9
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X8 ?X9 ?X10 ⇒
go X1; go X2; go X3; go X4; go X5; go X6; go X7; go X8; go X9; go X10
| _ ⇒ idtac
end.
为提高性能,可以把本定义的函数体换成 idtac
来停用 rm_inside。
Ltac fast_rm_inside E :=
rm_inside E.
rm_inside E.
数字作为实参
From Stdlib Require Import BinNums BinInt.
Definition ltac_int_to_nat (x:BinInt.Z) : nat :=
match x with
| BinInt.Z0 ⇒ 0%nat
| BinInt.Zpos p ⇒ BinPos.nat_of_P p
| BinInt.Zneg p ⇒ 0%nat
end.
Ltac number_to_nat N :=
match type of N with
| nat ⇒ constr:(N)
| BinInt.Z ⇒ let N' := constr:(ltac_int_to_nat N) in eval compute in N'
end.
Definition ltac_int_to_nat (x:BinInt.Z) : nat :=
match x with
| BinInt.Z0 ⇒ 0%nat
| BinInt.Zpos p ⇒ BinPos.nat_of_P p
| BinInt.Zneg p ⇒ 0%nat
end.
Ltac number_to_nat N :=
match type of N with
| nat ⇒ constr:(N)
| BinInt.Z ⇒ let N' := constr:(ltac_int_to_nat N) in eval compute in N'
end.
ltac_pattern E at K 与 pattern E at K 相同,
只是 K 是 Rocq 数字(nat 或 Z)而非 Ltac 整数。
语法 ltac_pattern E as K in H 也可用。
Tactic Notation "ltac_pattern" constr(E) "at" constr(K) :=
match number_to_nat K with
| 1 ⇒ pattern E at 1
| 2 ⇒ pattern E at 2
| 3 ⇒ pattern E at 3
| 4 ⇒ pattern E at 4
| 5 ⇒ pattern E at 5
| 6 ⇒ pattern E at 6
| 7 ⇒ pattern E at 7
| 8 ⇒ pattern E at 8
| _ ⇒ fail "ltac_pattern: arity not supported"
end.
Tactic Notation "ltac_pattern" constr(E) "at" constr(K) "in" hyp(H) :=
match number_to_nat K with
| 1 ⇒ pattern E at 1 in H
| 2 ⇒ pattern E at 2 in H
| 3 ⇒ pattern E at 3 in H
| 4 ⇒ pattern E at 4 in H
| 5 ⇒ pattern E at 5 in H
| 6 ⇒ pattern E at 6 in H
| 7 ⇒ pattern E at 7 in H
| 8 ⇒ pattern E at 8 in H
| _ ⇒ fail "ltac_pattern: arity not supported"
end.
match number_to_nat K with
| 1 ⇒ pattern E at 1
| 2 ⇒ pattern E at 2
| 3 ⇒ pattern E at 3
| 4 ⇒ pattern E at 4
| 5 ⇒ pattern E at 5
| 6 ⇒ pattern E at 6
| 7 ⇒ pattern E at 7
| 8 ⇒ pattern E at 8
| _ ⇒ fail "ltac_pattern: arity not supported"
end.
Tactic Notation "ltac_pattern" constr(E) "at" constr(K) "in" hyp(H) :=
match number_to_nat K with
| 1 ⇒ pattern E at 1 in H
| 2 ⇒ pattern E at 2 in H
| 3 ⇒ pattern E at 3 in H
| 4 ⇒ pattern E at 4 in H
| 5 ⇒ pattern E at 5 in H
| 6 ⇒ pattern E at 6 in H
| 7 ⇒ pattern E at 7 in H
| 8 ⇒ pattern E at 8 in H
| _ ⇒ fail "ltac_pattern: arity not supported"
end.
ltac_set (x := E) at K 与 set (x := E) at K 相同,
只是 K 是 Rocq 数字(nat 或 Z)而非 Ltac 整数。
Tactic Notation "ltac_set" "(" ident(X) ":=" constr(E) ")" "at" constr(K) :=
match number_to_nat K with
| 1%nat ⇒ set (X := E) at 1
| 2%nat ⇒ set (X := E) at 2
| 3%nat ⇒ set (X := E) at 3
| 4%nat ⇒ set (X := E) at 4
| 5%nat ⇒ set (X := E) at 5
| 6%nat ⇒ set (X := E) at 6
| 7%nat ⇒ set (X := E) at 7
| 8%nat ⇒ set (X := E) at 8
| 9%nat ⇒ set (X := E) at 9
| 10%nat ⇒ set (X := E) at 10
| 11%nat ⇒ set (X := E) at 11
| 12%nat ⇒ set (X := E) at 12
| 13%nat ⇒ set (X := E) at 13
| _ ⇒ fail "ltac_set: arity not supported"
end.
match number_to_nat K with
| 1%nat ⇒ set (X := E) at 1
| 2%nat ⇒ set (X := E) at 2
| 3%nat ⇒ set (X := E) at 3
| 4%nat ⇒ set (X := E) at 4
| 5%nat ⇒ set (X := E) at 5
| 6%nat ⇒ set (X := E) at 6
| 7%nat ⇒ set (X := E) at 7
| 8%nat ⇒ set (X := E) at 8
| 9%nat ⇒ set (X := E) at 9
| 10%nat ⇒ set (X := E) at 10
| 11%nat ⇒ set (X := E) at 11
| 12%nat ⇒ set (X := E) at 12
| 13%nat ⇒ set (X := E) at 13
| _ ⇒ fail "ltac_set: arity not supported"
end.
Tactic Notation "show" tactic(tac) :=
let R := tac in pose R.
let R := tac in pose R.
dup N 产生当前目标的 N 份拷贝。
它便于构造演示策略行为的示例。
dup 是 dup 2 的简写。
Lemma dup_lemma : ∀ P, P → P → P.
Proof using. auto. Qed.
Ltac dup_tactic N :=
match number_to_nat N with
| 0 ⇒ idtac
| S 0 ⇒ idtac
| S ?N' ⇒ apply dup_lemma; [ | dup_tactic N' ]
end.
Tactic Notation "dup" constr(N) :=
dup_tactic N.
Tactic Notation "dup" :=
dup 2.
Proof using. auto. Qed.
Ltac dup_tactic N :=
match number_to_nat N with
| 0 ⇒ idtac
| S 0 ⇒ idtac
| S ?N' ⇒ apply dup_lemma; [ | dup_tactic N' ]
end.
Tactic Notation "dup" constr(N) :=
dup_tactic N.
Tactic Notation "dup" :=
dup 2.
Ltac is_not_evar E :=
first [ is_evar E; fail 1
| idtac ].
first [ is_evar E; fail 1
| idtac ].
若 E 是 evar 则 is_evar_as_bool E 求值为 true,
否则为 false。
若 E 不含 evar 则 has_no_evar E 成功。
Ltac has_no_evar E :=
first [ has_evar E; fail 1 | idtac ].
first [ has_evar E; fail 1 | idtac ].
Ltac check_noevar M :=
first [ has_evar M; fail 2 | idtac ].
Ltac check_noevar_hyp H :=
let T := type of H in check_noevar T.
Ltac check_noevar_goal :=
match goal with ⊢ ?G ⇒ check_noevar G end.
first [ has_evar M; fail 2 | idtac ].
Ltac check_noevar_hyp H :=
let T := type of H in check_noevar T.
Ltac check_noevar_goal :=
match goal with ⊢ ?G ⇒ check_noevar G end.
Ltac with_evar_base T cont :=
let x := fresh "TEMP" in evar (x:T); cont x; subst x.
Tactic Notation "with_evar" constr(T) tactic(cont) :=
with_evar_base T cont.
let x := fresh "TEMP" in evar (x:T); cont x; subst x.
Tactic Notation "with_evar" constr(T) tactic(cont) :=
with_evar_base T cont.
假设的标记
Ltac get_last_hyp tt :=
match goal with H: _ ⊢ _ ⇒ constr:(H) end.
match goal with H: _ ⊢ _ ⇒ constr:(H) end.
ltac_to_generalize 是对待泛化假设的一种特定标记。
Definition ltac_to_generalize (A:Type) (x:A) := x.
Ltac gen_to_generalize :=
repeat match goal with
H: ltac_to_generalize _ ⊢ _ ⇒ generalize H; clear H end.
Ltac mark_to_generalize H :=
let T := type of H in
change T with (ltac_to_generalize T) in H.
Ltac gen_to_generalize :=
repeat match goal with
H: ltac_to_generalize _ ⊢ _ ⇒ generalize H; clear H end.
Ltac mark_to_generalize H :=
let T := type of H in
change T with (ltac_to_generalize T) in H.
解构项
Ltac get_head E :=
match E with
| ?E' ?x ⇒ get_head E'
| _ ⇒ constr:(E)
end.
match E with
| ?E' ?x ⇒ get_head E'
| _ ⇒ constr:(E)
end.
get_fun_arg E 是分解应用项 E 的策略,
即作用于形如 X1 ... XN 的项时,
返回由 X1 .. X(N-1) 与 XN 构成的偶对。
Ltac get_fun_arg E :=
match E with
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X ⇒ constr:((X1 X2 X3 X4 X5 X6 X7,X))
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X ⇒ constr:((X1 X2 X3 X4 X5 X6,X))
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X ⇒ constr:((X1 X2 X3 X4 X5,X))
| ?X1 ?X2 ?X3 ?X4 ?X ⇒ constr:((X1 X2 X3 X4,X))
| ?X1 ?X2 ?X3 ?X ⇒ constr:((X1 X2 X3,X))
| ?X1 ?X2 ?X ⇒ constr:((X1 X2,X))
| ?X1 ?X ⇒ constr:((X1,X))
end.
match E with
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X7 ?X ⇒ constr:((X1 X2 X3 X4 X5 X6 X7,X))
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X6 ?X ⇒ constr:((X1 X2 X3 X4 X5 X6,X))
| ?X1 ?X2 ?X3 ?X4 ?X5 ?X ⇒ constr:((X1 X2 X3 X4 X5,X))
| ?X1 ?X2 ?X3 ?X4 ?X ⇒ constr:((X1 X2 X3 X4,X))
| ?X1 ?X2 ?X3 ?X ⇒ constr:((X1 X2 X3,X))
| ?X1 ?X2 ?X ⇒ constr:((X1 X2,X))
| ?X1 ?X ⇒ constr:((X1,X))
end.
在出现处施加动作与不在出现处施加动作
Tactic Notation "ltac_action_at" constr(K) "of" constr(E) "do" tactic(Tac) :=
let p := fresh "TEMP" in ltac_pattern E at K;
match goal with ⊢ ?P _ ⇒ set (p:=P) end;
Tac; unfold p; clear p.
Tactic Notation "ltac_action_at" constr(K) "of" constr(E) "in" hyp(H) "do" tactic(Tac) :=
let p := fresh "TEMP" in ltac_pattern E at K in H;
match type of H with ?P _ ⇒ set (p:=P) in H end;
Tac; unfold p in H; clear p.
let p := fresh "TEMP" in ltac_pattern E at K;
match goal with ⊢ ?P _ ⇒ set (p:=P) end;
Tac; unfold p; clear p.
Tactic Notation "ltac_action_at" constr(K) "of" constr(E) "in" hyp(H) "do" tactic(Tac) :=
let p := fresh "TEMP" in ltac_pattern E at K in H;
match type of H with ?P _ ⇒ set (p:=P) in H end;
Tac; unfold p in H; clear p.
protects E do Tac 给表达式 E 暂时赋予一个名字,
使策略 Tac 的执行不会修改 E。
例如,这可用于限制 simpl 的作用。
Tactic Notation "protects" constr(E) "do" tactic(Tac) :=
(* let x := fresh "TEMP" in sets_eq x: E; T; subst x. *)
let x := fresh "TEMP" in let H := fresh "TEMP" in
set (X := E) in *; assert (H : X = E) by reflexivity;
clearbody X; Tac; subst x.
Tactic Notation "protects" constr(E) "do" tactic(Tac) "/" :=
protects E do Tac.
(* let x := fresh "TEMP" in sets_eq x: E; T; subst x. *)
let x := fresh "TEMP" in let H := fresh "TEMP" in
set (X := E) in *; assert (H : X = E) by reflexivity;
clearbody X; Tac; subst x.
Tactic Notation "protects" constr(E) "do" tactic(Tac) "/" :=
protects E do Tac.
Definition eq' := @eq.
#[global]
Hint Unfold eq' : core.
Notation "x '='' y" := (@eq' _ x y)
(at level 70, y at next level).
#[global]
Hint Unfold eq' : core.
Notation "x '='' y" := (@eq' _ x y)
(at level 70, y at next level).
Ltac check_enabled := constr:(true).
Tactic Notation "check" uconstr(E) :=
lazymatch check_enabled with
| false ⇒ idtac
| true ⇒
first [ generalize E; match goal with ⊢ ?T → _ ⇒ idtac E; idtac ":" T end; intros _
| idtac E; fail 1 "does not typecheck" ]
end.
Tactic Notation "check" uconstr(E) :=
lazymatch check_enabled with
| false ⇒ idtac
| true ⇒
first [ generalize E; match goal with ⊢ ?T → _ ⇒ idtac E; idtac ":" T end; intros _
| idtac E; fail 1 "does not typecheck" ]
end.
Ltac jauto_set_hyps :=
repeat match goal with H: ?T ⊢ _ ⇒
match T with
| _ ∧ _ ⇒ destruct H
| iff _ _ ⇒ destruct H
| ∃ a, _ ⇒ destruct H
| _ ⇒ generalize H; clear H
end
end.
Ltac jauto_set_goal :=
repeat match goal with
| ⊢ ∃ a, _ ⇒ esplit
| ⊢ _ ∧ _ ⇒ split
| ⊢ iff _ _ ⇒ split
end.
Ltac jauto_set :=
intros; jauto_set_hyps;
intros; jauto_set_goal;
unfold not in ×.
repeat match goal with H: ?T ⊢ _ ⇒
match T with
| _ ∧ _ ⇒ destruct H
| iff _ _ ⇒ destruct H
| ∃ a, _ ⇒ destruct H
| _ ⇒ generalize H; clear H
end
end.
Ltac jauto_set_goal :=
repeat match goal with
| ⊢ ∃ a, _ ⇒ esplit
| ⊢ _ ∧ _ ⇒ split
| ⊢ iff _ _ ⇒ split
end.
Ltac jauto_set :=
intros; jauto_set_hyps;
intros; jauto_set_goal;
unfold not in ×.
Ltac old_refine f :=
refine f. (* ; shelve_unifiable. *)
refine f. (* ; shelve_unifiable. *)
rapply 是与 eapply 类似的策略,
不同之处是它基于 refine 策略,
因而严格更强(至少理论上如此)。
简言之,为让实参匹配它能即时做转换,
并且需要时能实例化存在量化。
Tactic Notation "rapply" constr(t) :=
first (* --注:这里的 @ 并无用处 *)
[ eexact (@t)
| old_refine (@t)
| old_refine (@t _)
| old_refine (@t _ _)
| old_refine (@t _ _ _)
| old_refine (@t _ _ _ _)
| old_refine (@t _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
].
first (* --注:这里的 @ 并无用处 *)
[ eexact (@t)
| old_refine (@t)
| old_refine (@t _)
| old_refine (@t _ _)
| old_refine (@t _ _ _)
| old_refine (@t _ _ _ _)
| old_refine (@t _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _ _ _)
| old_refine (@t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
].
不做类型类解析的 refine 应用,为 Rocq < 8.11 临时保留。
Ltac nrapply H :=
first
[ notypeclasses refine (H)
| notypeclasses refine (H _)
| notypeclasses refine (H _ _)
| notypeclasses refine (H _ _ _)
| notypeclasses refine (H _ _ _ _)
| notypeclasses refine (H _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _ _ _ _) ].
first
[ notypeclasses refine (H)
| notypeclasses refine (H _)
| notypeclasses refine (H _ _)
| notypeclasses refine (H _ _ _)
| notypeclasses refine (H _ _ _ _)
| notypeclasses refine (H _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _ _ _)
| notypeclasses refine (H _ _ _ _ _ _ _ _ _ _ _ _ _ _) ].
策略 applys_N T(N 为自然数)
提供了更高效的使用 applys T 的方式。
它通过显式指定函数 T 的元数,
避免尝试所有可能的元数。
Tactic Notation "rapply_0" constr(t) :=
old_refine (@t).
Tactic Notation "rapply_1" constr(t) :=
old_refine (@t _).
Tactic Notation "rapply_2" constr(t) :=
old_refine (@t _ _).
Tactic Notation "rapply_3" constr(t) :=
old_refine (@t _ _ _).
Tactic Notation "rapply_4" constr(t) :=
old_refine (@t _ _ _ _).
Tactic Notation "rapply_5" constr(t) :=
old_refine (@t _ _ _ _ _).
Tactic Notation "rapply_6" constr(t) :=
old_refine (@t _ _ _ _ _ _).
Tactic Notation "rapply_7" constr(t) :=
old_refine (@t _ _ _ _ _ _ _).
Tactic Notation "rapply_8" constr(t) :=
old_refine (@t _ _ _ _ _ _ _ _).
Tactic Notation "rapply_9" constr(t) :=
old_refine (@t _ _ _ _ _ _ _ _ _).
Tactic Notation "rapply_10" constr(t) :=
old_refine (@t _ _ _ _ _ _ _ _ _ _).
old_refine (@t).
Tactic Notation "rapply_1" constr(t) :=
old_refine (@t _).
Tactic Notation "rapply_2" constr(t) :=
old_refine (@t _ _).
Tactic Notation "rapply_3" constr(t) :=
old_refine (@t _ _ _).
Tactic Notation "rapply_4" constr(t) :=
old_refine (@t _ _ _ _).
Tactic Notation "rapply_5" constr(t) :=
old_refine (@t _ _ _ _ _).
Tactic Notation "rapply_6" constr(t) :=
old_refine (@t _ _ _ _ _ _).
Tactic Notation "rapply_7" constr(t) :=
old_refine (@t _ _ _ _ _ _ _).
Tactic Notation "rapply_8" constr(t) :=
old_refine (@t _ _ _ _ _ _ _ _).
Tactic Notation "rapply_9" constr(t) :=
old_refine (@t _ _ _ _ _ _ _ _ _).
Tactic Notation "rapply_10" constr(t) :=
old_refine (@t _ _ _ _ _ _ _ _ _ _).
lets_base H E 把假设 H : T 加入语境,
其中 T 是项 E 的类型。
若 H 是引入模式,则按该模式解构 H。
Ltac lets_base I E := generalize E; intros I.
applys_to H E 把假设 H 的类型
替换为项 E 应用到 H 的结果。
直观上它等价于 lets H: (E H)。
Tactic Notation "applys_to" hyp(H) constr(E) :=
let H' := fresh "TEMP" in rename H into H';
(first [ lets_base H (E H')
| lets_base H (E _ H')
| lets_base H (E _ _ H')
| lets_base H (E _ _ _ H')
| lets_base H (E _ _ _ _ H')
| lets_base H (E _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ _ _ _ H') ]
); clear H'.
let H' := fresh "TEMP" in rename H into H';
(first [ lets_base H (E H')
| lets_base H (E _ H')
| lets_base H (E _ _ H')
| lets_base H (E _ _ _ H')
| lets_base H (E _ _ _ _ H')
| lets_base H (E _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ _ _ H')
| lets_base H (E _ _ _ _ _ _ _ _ _ H') ]
); clear H'.
applys_to H1,...,HN E 把 E 应用到多条假设
Tactic Notation "applys_to" hyp(H1) "," hyp(H2) constr(E) :=
applys_to H1 E; applys_to H2 E.
Tactic Notation "applys_to" hyp(H1) "," hyp(H2) "," hyp(H3) constr(E) :=
applys_to H1 E; applys_to H2 E; applys_to H3 E.
Tactic Notation "applys_to" hyp(H1) "," hyp(H2) "," hyp(H3) "," hyp(H4) constr(E) :=
applys_to H1 E; applys_to H2 E; applys_to H3 E; applys_to H4 E.
applys_to H1 E; applys_to H2 E.
Tactic Notation "applys_to" hyp(H1) "," hyp(H2) "," hyp(H3) constr(E) :=
applys_to H1 E; applys_to H2 E; applys_to H3 E.
Tactic Notation "applys_to" hyp(H1) "," hyp(H2) "," hyp(H3) "," hyp(H4) constr(E) :=
applys_to H1 E; applys_to H2 E; applys_to H3 E; applys_to H4 E.
constructors 调用 constructor 或 econstructor。
Tactic Notation "asserts" simple_intropattern(I) ":" constr(T) :=
let H := fresh "TEMP" in assert (H : T);
[ | generalize H; clear H; intros I ].
let H := fresh "TEMP" in assert (H : T);
[ | generalize H; clear H; intros I ].
asserts H1 .. HN: T 是
asserts \[H1 \[H2 \[.. HN\]\]\]\: T] 的简写。
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) ":" constr(T) :=
asserts [I1 I2]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) ":" constr(T) :=
asserts [I1 [I2 I3]]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) ":" constr(T) :=
asserts [I1 [I2 [I3 I4]]]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5) ":" constr(T) :=
asserts [I1 [I2 [I3 [I4 I5]]]]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) ":" constr(T) :=
asserts [I1 [I2 [I3 [I4 [I5 I6]]]]]: T.
simple_intropattern(I2) ":" constr(T) :=
asserts [I1 I2]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) ":" constr(T) :=
asserts [I1 [I2 I3]]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) ":" constr(T) :=
asserts [I1 [I2 [I3 I4]]]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5) ":" constr(T) :=
asserts [I1 [I2 [I3 [I4 I5]]]]: T.
Tactic Notation "asserts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) ":" constr(T) :=
asserts [I1 [I2 [I3 [I4 [I5 I6]]]]]: T.
asserts: T 即 asserts H: T,其中 H 自动选取。
Tactic Notation "asserts" ":" constr(T) :=
let H := fresh "TEMP" in asserts H : T.
let H := fresh "TEMP" in asserts H : T.
cuts H: T 与 asserts H: T 相同,
只是所产生的两个子目标顺序对调:
子目标 T 排在第二。
注意与 cut 不同,它会引入该假设。
Tactic Notation "cuts" simple_intropattern(I) ":" constr(T) :=
cut (T); [ intros I | idtac ].
cut (T); [ intros I | idtac ].
cuts: T 即 cuts H: T,其中 H 自动选取。
Tactic Notation "cuts" ":" constr(T) :=
let H := fresh "TEMP" in cuts H: T.
let H := fresh "TEMP" in cuts H: T.
cuts H1 .. HN: T 是
cuts \[H1 \[H2 \[.. HN\]\]\]\: T] 的简写。
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) ":" constr(T) :=
cuts [I1 I2]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) ":" constr(T) :=
cuts [I1 [I2 I3]]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) ":" constr(T) :=
cuts [I1 [I2 [I3 I4]]]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5) ":" constr(T) :=
cuts [I1 [I2 [I3 [I4 I5]]]]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) ":" constr(T) :=
cuts [I1 [I2 [I3 [I4 [I5 I6]]]]]: T.
simple_intropattern(I2) ":" constr(T) :=
cuts [I1 I2]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) ":" constr(T) :=
cuts [I1 [I2 I3]]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) ":" constr(T) :=
cuts [I1 [I2 [I3 I4]]]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5) ":" constr(T) :=
cuts [I1 [I2 [I3 [I4 I5]]]]: T.
Tactic Notation "cuts" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3)
simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) ":" constr(T) :=
cuts [I1 [I2 [I3 [I4 [I5 I6]]]]]: T.
实例化与正向链推
(* 底层实现 *)
Ltac app_assert t P cont :=
let H := fresh "TEMP" in
assert (H : P); [ | cont(t H); clear H ].
Ltac app_evar t A cont :=
let x := fresh "TEMP" in
evar (x:A);
let t' := constr:(t x) in
let t'' := (eval unfold x in t') in
subst x; cont t''.
Ltac app_arg t P v cont :=
let H := fresh "TEMP" in
assert (H : P); [ apply v | cont(t H); try clear H ].
Ltac build_app_alls t final :=
let rec go t :=
match type of t with
| ?P → ?Q ⇒ app_assert t P go
| ∀ _:?A, _ ⇒ app_evar t A go
| _ ⇒ final t
end in
go t.
Ltac boxerlist_next_type vs :=
match vs with
| nil ⇒ constr:(ltac_wild)
| (boxer ltac_wild)::?vs' ⇒ boxerlist_next_type vs'
| (boxer ltac_wilds)::_ ⇒ constr:(ltac_wild)
| (@boxer ?T _)::_ ⇒ constr:(T)
end.
(* 注:拒绝用命题实例化依值假设;
拒绝用非 Type 类型的值实例化类型为 Type 的实参。
*)
Ltac build_app_hnts t vs final :=
let rec go t vs :=
match vs with
| nil ⇒ first [ final t | fail 1 ]
| (boxer ltac_wilds)::_ ⇒ first [ build_app_alls t final | fail 1 ]
| (boxer ?v)::?vs' ⇒
let cont t' := go t' vs in
let cont' t' := go t' vs' in
let T := type of t in
let T := eval hnf in T in
match v with
| ltac_wild ⇒
first [ let U := boxerlist_next_type vs' in
match U with
| ltac_wild ⇒
match T with
| ?P → ?Q ⇒ first [ app_assert t P cont' | fail 3 ]
| ∀ _:?A, _ ⇒ first [ app_evar t A cont' | fail 3 ]
end
| _ ⇒
match T with (* 应当测试 T 是否可归一 *)
| U → ?Q ⇒ first [ app_assert t U cont' | fail 3 ]
| ∀ _:U, _ ⇒ first [ app_evar t U cont' | fail 3 ]
| ?P → ?Q ⇒ first [ app_assert t P cont | fail 3 ]
| ∀ _:?A, _ ⇒ first [ app_evar t A cont | fail 3 ]
end
end
| fail 2 ]
| _ ⇒
match T with
| ?P → ?Q ⇒ first [ app_arg t P v cont'
| app_assert t P cont
| fail 3 ]
| ∀ _:Type, _ ⇒
match type of v with
| Type ⇒ first [ cont' (t v)
| app_evar t Type cont
| fail 3 ]
| _ ⇒ first [ app_evar t Type cont
| fail 3 ]
end
| ∀ _:?A, _ ⇒
let V := type of v in
match type of V with
| Prop ⇒ first [ app_evar t A cont
| fail 3 ]
| _ ⇒ first [ cont' (t v)
| app_evar t A cont
| fail 3 ]
end
end
end
end in
go t vs.
Ltac app_assert t P cont :=
let H := fresh "TEMP" in
assert (H : P); [ | cont(t H); clear H ].
Ltac app_evar t A cont :=
let x := fresh "TEMP" in
evar (x:A);
let t' := constr:(t x) in
let t'' := (eval unfold x in t') in
subst x; cont t''.
Ltac app_arg t P v cont :=
let H := fresh "TEMP" in
assert (H : P); [ apply v | cont(t H); try clear H ].
Ltac build_app_alls t final :=
let rec go t :=
match type of t with
| ?P → ?Q ⇒ app_assert t P go
| ∀ _:?A, _ ⇒ app_evar t A go
| _ ⇒ final t
end in
go t.
Ltac boxerlist_next_type vs :=
match vs with
| nil ⇒ constr:(ltac_wild)
| (boxer ltac_wild)::?vs' ⇒ boxerlist_next_type vs'
| (boxer ltac_wilds)::_ ⇒ constr:(ltac_wild)
| (@boxer ?T _)::_ ⇒ constr:(T)
end.
(* 注:拒绝用命题实例化依值假设;
拒绝用非 Type 类型的值实例化类型为 Type 的实参。
*)
Ltac build_app_hnts t vs final :=
let rec go t vs :=
match vs with
| nil ⇒ first [ final t | fail 1 ]
| (boxer ltac_wilds)::_ ⇒ first [ build_app_alls t final | fail 1 ]
| (boxer ?v)::?vs' ⇒
let cont t' := go t' vs in
let cont' t' := go t' vs' in
let T := type of t in
let T := eval hnf in T in
match v with
| ltac_wild ⇒
first [ let U := boxerlist_next_type vs' in
match U with
| ltac_wild ⇒
match T with
| ?P → ?Q ⇒ first [ app_assert t P cont' | fail 3 ]
| ∀ _:?A, _ ⇒ first [ app_evar t A cont' | fail 3 ]
end
| _ ⇒
match T with (* 应当测试 T 是否可归一 *)
| U → ?Q ⇒ first [ app_assert t U cont' | fail 3 ]
| ∀ _:U, _ ⇒ first [ app_evar t U cont' | fail 3 ]
| ?P → ?Q ⇒ first [ app_assert t P cont | fail 3 ]
| ∀ _:?A, _ ⇒ first [ app_evar t A cont | fail 3 ]
end
end
| fail 2 ]
| _ ⇒
match T with
| ?P → ?Q ⇒ first [ app_arg t P v cont'
| app_assert t P cont
| fail 3 ]
| ∀ _:Type, _ ⇒
match type of v with
| Type ⇒ first [ cont' (t v)
| app_evar t Type cont
| fail 3 ]
| _ ⇒ first [ app_evar t Type cont
| fail 3 ]
end
| ∀ _:?A, _ ⇒
let V := type of v in
match type of V with
| Prop ⇒ first [ app_evar t A cont
| fail 3 ]
| _ ⇒ first [ cont' (t v)
| app_evar t A cont
| fail 3 ]
end
end
end
end in
go t vs.
较新版本:支持类型类
Ltac app_typeclass t cont :=
let t' := constr:(t _) in
cont t'.
Ltac build_app_alls t final ::=
let rec go t :=
match type of t with
| ?P → ?Q ⇒ app_assert t P go
| ∀ _:?A, _ ⇒
first [ app_evar t A go
| app_typeclass t go
| fail 3 ]
| _ ⇒ final t
end in
go t.
Ltac build_app_hnts t vs final ::=
let rec go t vs :=
match vs with
| nil ⇒ first [ final t | fail 1 ]
| (boxer ltac_wilds)::_ ⇒ first [ build_app_alls t final | fail 1 ]
| (boxer ?v)::?vs' ⇒
let cont t' := go t' vs in
let cont' t' := go t' vs' in
let T := type of t in
let T := eval hnf in T in
match v with
| ltac_wild ⇒
first [ let U := boxerlist_next_type vs' in
match U with
| ltac_wild ⇒
match T with
| ?P → ?Q ⇒ first [ app_assert t P cont' | fail 3 ]
| ∀ _:?A, _ ⇒ first [ app_typeclass t cont'
| app_evar t A cont'
| fail 3 ]
end
| _ ⇒
match T with (* 应当测试 T 是否可归一 *)
| U → ?Q ⇒ first [ app_assert t U cont' | fail 3 ]
| ∀ _:U, _ ⇒ first
[ app_typeclass t cont'
| app_evar t U cont'
| fail 3 ]
| ?P → ?Q ⇒ first [ app_assert t P cont | fail 3 ]
| ∀ _:?A, _ ⇒ first
[ app_typeclass t cont
| app_evar t A cont
| fail 3 ]
end
end
| fail 2 ]
| _ ⇒
match T with
| ?P → ?Q ⇒ first [ app_arg t P v cont'
| app_assert t P cont
| fail 3 ]
| ∀ _:Type, _ ⇒
match type of v with
| Type ⇒ first [ cont' (t v)
| app_evar t Type cont
| fail 3 ]
| _ ⇒ first [ app_evar t Type cont
| fail 3 ]
end
| ∀ _:?A, _ ⇒
let V := type of v in
match type of V with
| Prop ⇒ first [ app_typeclass t cont
| app_evar t A cont
| fail 3 ]
| _ ⇒ first [ cont' (t v)
| app_typeclass t cont
| app_evar t A cont
| fail 3 ]
end
end
end
end in
go t vs.
(* --注:对 first ... 使用局部函数 *)
Ltac build_app args final :=
first [
match args with (@boxer ?T ?t)::?vs ⇒
let t := constr:(t:T) in
build_app_hnts t vs final;
fast_rm_inside args
end
| fail 1 "Instantiation fails for:" args].
Ltac unfold_head_until_product T :=
eval hnf in T.
Ltac args_unfold_head_if_not_product args :=
match args with (@boxer ?T ?t)::?vs ⇒
let T' := unfold_head_until_product T in
constr:((@boxer T' t)::vs)
end.
Ltac args_unfold_head_if_not_product_but_params args :=
match args with
| (boxer ?t)::(boxer ?v)::?vs ⇒
args_unfold_head_if_not_product args
| _ ⇒ constr:(args)
end.
let t' := constr:(t _) in
cont t'.
Ltac build_app_alls t final ::=
let rec go t :=
match type of t with
| ?P → ?Q ⇒ app_assert t P go
| ∀ _:?A, _ ⇒
first [ app_evar t A go
| app_typeclass t go
| fail 3 ]
| _ ⇒ final t
end in
go t.
Ltac build_app_hnts t vs final ::=
let rec go t vs :=
match vs with
| nil ⇒ first [ final t | fail 1 ]
| (boxer ltac_wilds)::_ ⇒ first [ build_app_alls t final | fail 1 ]
| (boxer ?v)::?vs' ⇒
let cont t' := go t' vs in
let cont' t' := go t' vs' in
let T := type of t in
let T := eval hnf in T in
match v with
| ltac_wild ⇒
first [ let U := boxerlist_next_type vs' in
match U with
| ltac_wild ⇒
match T with
| ?P → ?Q ⇒ first [ app_assert t P cont' | fail 3 ]
| ∀ _:?A, _ ⇒ first [ app_typeclass t cont'
| app_evar t A cont'
| fail 3 ]
end
| _ ⇒
match T with (* 应当测试 T 是否可归一 *)
| U → ?Q ⇒ first [ app_assert t U cont' | fail 3 ]
| ∀ _:U, _ ⇒ first
[ app_typeclass t cont'
| app_evar t U cont'
| fail 3 ]
| ?P → ?Q ⇒ first [ app_assert t P cont | fail 3 ]
| ∀ _:?A, _ ⇒ first
[ app_typeclass t cont
| app_evar t A cont
| fail 3 ]
end
end
| fail 2 ]
| _ ⇒
match T with
| ?P → ?Q ⇒ first [ app_arg t P v cont'
| app_assert t P cont
| fail 3 ]
| ∀ _:Type, _ ⇒
match type of v with
| Type ⇒ first [ cont' (t v)
| app_evar t Type cont
| fail 3 ]
| _ ⇒ first [ app_evar t Type cont
| fail 3 ]
end
| ∀ _:?A, _ ⇒
let V := type of v in
match type of V with
| Prop ⇒ first [ app_typeclass t cont
| app_evar t A cont
| fail 3 ]
| _ ⇒ first [ cont' (t v)
| app_typeclass t cont
| app_evar t A cont
| fail 3 ]
end
end
end
end in
go t vs.
(* --注:对 first ... 使用局部函数 *)
Ltac build_app args final :=
first [
match args with (@boxer ?T ?t)::?vs ⇒
let t := constr:(t:T) in
build_app_hnts t vs final;
fast_rm_inside args
end
| fail 1 "Instantiation fails for:" args].
Ltac unfold_head_until_product T :=
eval hnf in T.
Ltac args_unfold_head_if_not_product args :=
match args with (@boxer ?T ?t)::?vs ⇒
let T' := unfold_head_until_product T in
constr:((@boxer T' t)::vs)
end.
Ltac args_unfold_head_if_not_product_but_params args :=
match args with
| (boxer ?t)::(boxer ?v)::?vs ⇒
args_unfold_head_if_not_product args
| _ ⇒ constr:(args)
end.
lets H: (>> E0 E1 .. EN) 会把引理 E0
实例化到实参 Ei(可以是通配符 __)上,
并把所得项命名为 H。
H 可以是引入模式、一列引入模式 I1 I2 IN,
或为空。
语法 lets H: E0 E1 .. EN 也可用。
若最后一个实参 EN 是 ___(三下划线),
则 H 的所有实参都将被实例化。
Ltac lets_build I Ei :=
let args := list_boxer_of Ei in
let args := args_unfold_head_if_not_product_but_params args in
(* let Ei''' := args_unfold_head_if_not_product Ei'' in*)
build_app args ltac:(fun R ⇒ lets_base I R).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E) :=
lets_build I E.
Tactic Notation "lets" ":" constr(E) :=
let H := fresh in lets H: E.
Tactic Notation "lets" ":" constr(E0)
constr(A1) :=
lets: (>> E0 A1).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) :=
lets: (>> E0 A1 A2).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets: (>> E0 A1 A2 A3).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets: (>> E0 A1 A2 A3 A4).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets: (>> E0 A1 A2 A3 A4 A5).
(* 已废弃的语法 lets I1 I2 *)
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
":" constr(E) :=
lets [I1 I2]: E.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) ":" constr(E) :=
lets [I1 [I2 I3]]: E.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) ":" constr(E) :=
lets [I1 [I2 [I3 I4]]]: E.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
":" constr(E) :=
lets [I1 [I2 [I3 [I4 I5]]]]: E.
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
lets I: (>> E0 A1).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
lets I: (>> E0 A1 A2).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets I: (>> E0 A1 A2 A3).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets I: (>> E0 A1 A2 A3 A4).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets I: (>> E0 A1 A2 A3 A4 A5).
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) :=
lets [I1 I2]: E0 A1.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) :=
lets [I1 I2]: E0 A1 A2.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets [I1 I2]: E0 A1 A2 A3.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets [I1 I2]: E0 A1 A2 A3 A4.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets [I1 I2]: E0 A1 A2 A3 A4 A5.
let args := list_boxer_of Ei in
let args := args_unfold_head_if_not_product_but_params args in
(* let Ei''' := args_unfold_head_if_not_product Ei'' in*)
build_app args ltac:(fun R ⇒ lets_base I R).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E) :=
lets_build I E.
Tactic Notation "lets" ":" constr(E) :=
let H := fresh in lets H: E.
Tactic Notation "lets" ":" constr(E0)
constr(A1) :=
lets: (>> E0 A1).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) :=
lets: (>> E0 A1 A2).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets: (>> E0 A1 A2 A3).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets: (>> E0 A1 A2 A3 A4).
Tactic Notation "lets" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets: (>> E0 A1 A2 A3 A4 A5).
(* 已废弃的语法 lets I1 I2 *)
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
":" constr(E) :=
lets [I1 I2]: E.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) ":" constr(E) :=
lets [I1 [I2 I3]]: E.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) ":" constr(E) :=
lets [I1 [I2 [I3 I4]]]: E.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
":" constr(E) :=
lets [I1 [I2 [I3 [I4 I5]]]]: E.
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
lets I: (>> E0 A1).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
lets I: (>> E0 A1 A2).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets I: (>> E0 A1 A2 A3).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets I: (>> E0 A1 A2 A3 A4).
Tactic Notation "lets" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets I: (>> E0 A1 A2 A3 A4 A5).
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) :=
lets [I1 I2]: E0 A1.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) :=
lets [I1 I2]: E0 A1 A2.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets [I1 I2]: E0 A1 A2 A3.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets [I1 I2]: E0 A1 A2 A3 A4.
Tactic Notation "lets" simple_intropattern(I1) simple_intropattern(I2) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets [I1 I2]: E0 A1 A2 A3 A4 A5.
forwards H: (>> E0 E1 .. EN)
是 forwards H: (>> E0 E1 .. EN ___) 的简写。
实参 Ei 可以是通配符 __(E0 除外)。
H 可以是引入模式、一列引入模式,或为空。
语法 forwards H: E0 E1 .. EN 也可用。
Ltac forwards_build_app_arg Ei :=
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
let args := args_unfold_head_if_not_product args in
args.
Ltac forwards_then Ei cont :=
let args := forwards_build_app_arg Ei in
let args := args_unfold_head_if_not_product_but_params args in
build_app args cont.
Tactic Notation "forwards" simple_intropattern(I) ":" constr(Ei) :=
let args := forwards_build_app_arg Ei in
lets I: args.
Tactic Notation "forwards" ":" constr(E) :=
let H := fresh in forwards H: E.
Tactic Notation "forwards" ":" constr(E0)
constr(A1) :=
forwards: (>> E0 A1).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) :=
forwards: (>> E0 A1 A2).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards: (>> E0 A1 A2 A3).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards: (>> E0 A1 A2 A3 A4).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards: (>> E0 A1 A2 A3 A4 A5).
(* --已废弃的语法 *)
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
":" constr(E) :=
forwards [I1 I2]: E.
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) ":" constr(E) :=
forwards [I1 [I2 I3]]: E.
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) ":" constr(E) :=
forwards [I1 [I2 [I3 I4]]]: E.
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
":" constr(E) :=
forwards [I1 [I2 [I3 [I4 I5]]]]: E.
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
forwards I: (>> E0 A1).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
forwards I: (>> E0 A1 A2).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards I: (>> E0 A1 A2 A3).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards I: (>> E0 A1 A2 A3 A4).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards I: (>> E0 A1 A2 A3 A4 A5).
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
let args := args_unfold_head_if_not_product args in
args.
Ltac forwards_then Ei cont :=
let args := forwards_build_app_arg Ei in
let args := args_unfold_head_if_not_product_but_params args in
build_app args cont.
Tactic Notation "forwards" simple_intropattern(I) ":" constr(Ei) :=
let args := forwards_build_app_arg Ei in
lets I: args.
Tactic Notation "forwards" ":" constr(E) :=
let H := fresh in forwards H: E.
Tactic Notation "forwards" ":" constr(E0)
constr(A1) :=
forwards: (>> E0 A1).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) :=
forwards: (>> E0 A1 A2).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards: (>> E0 A1 A2 A3).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards: (>> E0 A1 A2 A3 A4).
Tactic Notation "forwards" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards: (>> E0 A1 A2 A3 A4 A5).
(* --已废弃的语法 *)
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
":" constr(E) :=
forwards [I1 I2]: E.
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) ":" constr(E) :=
forwards [I1 [I2 I3]]: E.
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) ":" constr(E) :=
forwards [I1 [I2 [I3 I4]]]: E.
Tactic Notation "forwards" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
":" constr(E) :=
forwards [I1 [I2 [I3 [I4 I5]]]]: E.
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
forwards I: (>> E0 A1).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
forwards I: (>> E0 A1 A2).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards I: (>> E0 A1 A2 A3).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards I: (>> E0 A1 A2 A3 A4).
Tactic Notation "forwards" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards I: (>> E0 A1 A2 A3 A4 A5).
forwards_nounfold I: E 类似 forwards I: E,
但若 E 中没有可见的量化或假设,
则不展开 E 的头部常量。
它主要供其他策略使用。
Tactic Notation "forwards_nounfold" simple_intropattern(I) ":" constr(Ei) :=
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
build_app args ltac:(fun R ⇒ lets_base I R).
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
build_app args ltac:(fun R ⇒ lets_base I R).
forwards_nounfold_then E ltac:(fun K ⇒ ..)
类似 forwards: E,但它以名字 K
把所得项提供给一个续延。
Ltac forwards_nounfold_then Ei cont :=
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
build_app args cont.
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
build_app args cont.
applys (>> E0 E1 .. EN) 把引理 E0
实例化到实参 Ei(可以是通配符 __)上,
并用前面定义的策略 applys
把所得项应用到当前目标。
applys E0 E1 E2 .. EN 也可用。
Ltac applys_build Ei :=
let args := list_boxer_of Ei in
let args := args_unfold_head_if_not_product_but_params args in
build_app args ltac:(fun R ⇒
first [ apply R | eapply R | rapply R ]).
Ltac applys_base E :=
match type of E with
| list Boxer ⇒ applys_build E
| _ ⇒ first [ rapply E | applys_build E ]
end; fast_rm_inside E.
Tactic Notation "applys" constr(E) :=
applys_base E.
Tactic Notation "applys" constr(E0) constr(A1) :=
applys (>> E0 A1).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) :=
applys (>> E0 A1 A2).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) constr(A3) :=
applys (>> E0 A1 A2 A3).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
applys (>> E0 A1 A2 A3 A4).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
applys (>> E0 A1 A2 A3 A4 A5).
let args := list_boxer_of Ei in
let args := args_unfold_head_if_not_product_but_params args in
build_app args ltac:(fun R ⇒
first [ apply R | eapply R | rapply R ]).
Ltac applys_base E :=
match type of E with
| list Boxer ⇒ applys_build E
| _ ⇒ first [ rapply E | applys_build E ]
end; fast_rm_inside E.
Tactic Notation "applys" constr(E) :=
applys_base E.
Tactic Notation "applys" constr(E0) constr(A1) :=
applys (>> E0 A1).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) :=
applys (>> E0 A1 A2).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) constr(A3) :=
applys (>> E0 A1 A2 A3).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
applys (>> E0 A1 A2 A3 A4).
Tactic Notation "applys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
applys (>> E0 A1 A2 A3 A4 A5).
fapplys (>> E0 E1 .. EN) 把引理 E0
实例化到实参 Ei 上,并带上实参 ___,
表示所有 evar 都应被显式实例化,
然后把所得项应用到当前目标。
fapplys E0 E1 E2 .. EN 也可用。
Ltac fapplys_build Ei :=
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
let args := args_unfold_head_if_not_product_but_params args in
build_app args ltac:(fun R ⇒ apply R).
Tactic Notation "fapplys" constr(E0) :=
match type of E0 with
| list Boxer ⇒ fapplys_build E0
| _ ⇒ fapplys_build (>> E0)
end.
Tactic Notation "fapplys" constr(E0) constr(A1) :=
fapplys (>> E0 A1).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) :=
fapplys (>> E0 A1 A2).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) constr(A3) :=
fapplys (>> E0 A1 A2 A3).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
fapplys (>> E0 A1 A2 A3 A4).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
fapplys (>> E0 A1 A2 A3 A4 A5).
let args := list_boxer_of Ei in
let args := (eval simpl in (args ++ ((boxer ___)::nil))) in
let args := args_unfold_head_if_not_product_but_params args in
build_app args ltac:(fun R ⇒ apply R).
Tactic Notation "fapplys" constr(E0) :=
match type of E0 with
| list Boxer ⇒ fapplys_build E0
| _ ⇒ fapplys_build (>> E0)
end.
Tactic Notation "fapplys" constr(E0) constr(A1) :=
fapplys (>> E0 A1).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) :=
fapplys (>> E0 A1 A2).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) constr(A3) :=
fapplys (>> E0 A1 A2 A3).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
fapplys (>> E0 A1 A2 A3 A4).
Tactic Notation "fapplys" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
fapplys (>> E0 A1 A2 A3 A4 A5).
specializes H (>> E1 E2 .. EN)
会把假设 H 实例化到实参 Ei(可以是通配符 __)上。
若最后一个实参 EN 是 ___(三下划线),
则 H 的所有实参都将被实例化。
Ltac specializes_build H Ei :=
let H' := fresh "TEMP" in rename H into H';
let args := list_boxer_of Ei in
let args := constr:((boxer H')::args) in
let args := args_unfold_head_if_not_product args in
build_app args ltac:(fun R ⇒ lets H: R);
clear H'.
Ltac specializes_base H Ei :=
specializes_build H Ei; fast_rm_inside Ei.
Tactic Notation "specializes" hyp(H) :=
specializes_base H (___).
Tactic Notation "specializes" hyp(H) constr(A) :=
specializes_base H A.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) :=
specializes H (>> A1 A2).
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) :=
specializes H (>> A1 A2 A3).
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) :=
specializes H (>> A1 A2 A3 A4).
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
specializes H (>> A1 A2 A3 A4 A5).
let H' := fresh "TEMP" in rename H into H';
let args := list_boxer_of Ei in
let args := constr:((boxer H')::args) in
let args := args_unfold_head_if_not_product args in
build_app args ltac:(fun R ⇒ lets H: R);
clear H'.
Ltac specializes_base H Ei :=
specializes_build H Ei; fast_rm_inside Ei.
Tactic Notation "specializes" hyp(H) :=
specializes_base H (___).
Tactic Notation "specializes" hyp(H) constr(A) :=
specializes_base H A.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) :=
specializes H (>> A1 A2).
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) :=
specializes H (>> A1 A2 A3).
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) :=
specializes H (>> A1 A2 A3 A4).
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
specializes H (>> A1 A2 A3 A4 A5).
specializes_vars H 等价于 specializes H __ .. __,
其中双下划线的个数等于从 H 的类型可见的
依值实参个数。注意目前不做任何展开
(这一行为将来可能改变)。
当前实现仅限于 H 是已有假设的情形
注:这一点可以推广。
Ltac specializes_var_base H :=
match type of H with
| ?P → ?Q ⇒ fail 1
| ∀ _:_, _ ⇒ specializes H __
end.
Ltac specializes_vars_base H :=
repeat (specializes_var_base H).
Tactic Notation "specializes_var" hyp(H) :=
specializes_var_base H.
Tactic Notation "specializes_vars" hyp(H) :=
specializes_vars_base H.
match type of H with
| ?P → ?Q ⇒ fail 1
| ∀ _:_, _ ⇒ specializes H __
end.
Ltac specializes_vars_base H :=
repeat (specializes_var_base H).
Tactic Notation "specializes_var" hyp(H) :=
specializes_var_base H.
Tactic Notation "specializes_vars" hyp(H) :=
specializes_vars_base H.
Tactic Notation "fapply" constr(E) :=
let H := fresh "TEMP" in forwards H: E;
first [ apply H | eapply H | rapply H | hnf; apply H
| hnf; eapply H | applys H ].
(* 注:applys 与 rapply 是否重复?*)
let H := fresh "TEMP" in forwards H: E;
first [ apply H | eapply H | rapply H | hnf; apply H
| hnf; eapply H | applys H ].
(* 注:applys 与 rapply 是否重复?*)
sapply 意为「超级 apply」。
它依次尝试 apply、eapply、applys 与 fapply,
并且还会先尝试把目标头范式化。
Tactic Notation "sapply" constr(H) :=
first [ apply H | eapply H | rapply H | applys H
| hnf; apply H | hnf; eapply H | hnf; applys H
| fapply H ].
first [ apply H | eapply H | rapply H | applys H
| hnf; apply H | hnf; eapply H | hnf; applys H
| fapply H ].
Tactic Notation "lets_simpl" ident(H) ":" constr(E) :=
lets H: E; try simpl in H.
Tactic Notation "lets_simpl" ":" constr(T) :=
let H := fresh "TEMP" in lets_simpl H: T.
lets H: E; try simpl in H.
Tactic Notation "lets_simpl" ":" constr(T) :=
let H := fresh "TEMP" in lets_simpl H: T.
lets_hnf H: E 与 lets H: E 相同,
只是会调用 hnf 把定义置于头范式。
也提供 lets_hnf: E。
Tactic Notation "lets_hnf" ident(H) ":" constr(E) :=
lets H: E; hnf in H.
Tactic Notation "lets_hnf" ":" constr(T) :=
let H := fresh "TEMP" in lets_hnf H: T.
lets H: E; hnf in H.
Tactic Notation "lets_hnf" ":" constr(T) :=
let H := fresh "TEMP" in lets_hnf H: T.
puts X: E 是 pose (X := E) 的同义写法。
另一种语法是 puts: E。
Tactic Notation "puts" ident(X) ":" constr(E) :=
pose (X := E).
Tactic Notation "puts" ":" constr(E) :=
let X := fresh "X" in pose (X := E).
pose (X := E).
Tactic Notation "puts" ":" constr(E) :=
let X := fresh "X" in pose (X := E).
重言式的应用
Ltac logic_base E cont :=
assert (H:E); [ cont tt | eapply H; clear H ].
Tactic Notation "logic" constr(E) :=
logic_base E ltac:(fun _ ⇒ tauto).
assert (H:E); [ cont tt | eapply H; clear H ].
Tactic Notation "logic" constr(E) :=
logic_base E ltac:(fun _ ⇒ tauto).
模等式应用
Section equatesLemma.
Variables (A0 A1 : Type).
Variables (A2 : ∀ (x1 : A1), Type).
Variables (A3 : ∀ (x1 : A1) (x2 : A2 x1), Type).
Variables (A4 : ∀ (x1 : A1) (x2 : A2 x1) (x3 : A3 x2), Type).
Variables (A5 : ∀ (x1 : A1) (x2 : A2 x1) (x3 : A3 x2) (x4 : A4 x3), Type).
Variables (A6 : ∀ (x1 : A1) (x2 : A2 x1) (x3 : A3 x2) (x4 : A4 x3) (x5 : A5 x4), Type).
Lemma equates_0 : ∀ (P Q:Prop),
P → P = Q → Q.
Proof using. intros. subst. auto. Qed.
Lemma equates_1 :
∀ (P:A0→Prop) x1 y1,
P y1 → x1 = y1 → P x1.
Proof using. intros. subst. auto. Qed.
Lemma equates_2 :
∀ y1 (P:A0→∀(x1:A1),Prop) x1 x2,
P y1 x2 → x1 = y1 → P x1 x2.
Proof using. intros. subst. auto. Qed.
Lemma equates_3 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1),Prop) x1 x2 x3,
P y1 x2 x3 → x1 = y1 → P x1 x2 x3.
Proof using. intros. subst. auto. Qed.
Lemma equates_4 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1)(x3:A3 x2),Prop) x1 x2 x3 x4,
P y1 x2 x3 x4 → x1 = y1 → P x1 x2 x3 x4.
Proof using. intros. subst. auto. Qed.
Lemma equates_5 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1)(x3:A3 x2)(x4:A4 x3),Prop) x1 x2 x3 x4 x5,
P y1 x2 x3 x4 x5 → x1 = y1 → P x1 x2 x3 x4 x5.
Proof using. intros. subst. auto. Qed.
Lemma equates_6 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1)(x3:A3 x2)(x4:A4 x3)(x5:A5 x4),Prop)
x1 x2 x3 x4 x5 x6,
P y1 x2 x3 x4 x5 x6 → x1 = y1 → P x1 x2 x3 x4 x5 x6.
Proof using. intros. subst. auto. Qed.
End equatesLemma.
Ltac equates_lemma n :=
match number_to_nat n with
| 0 ⇒ constr:(equates_0)
| 1 ⇒ constr:(equates_1)
| 2 ⇒ constr:(equates_2)
| 3 ⇒ constr:(equates_3)
| 4 ⇒ constr:(equates_4)
| 5 ⇒ constr:(equates_5)
| 6 ⇒ constr:(equates_6)
| _ ⇒ fail 100 "equates tactic only support up to arity 6"
end.
Ltac equates_one n :=
let L := equates_lemma n in
eapply L.
Ltac equates_several E cont :=
let all_pos := match type of E with
| List.list Boxer ⇒ constr:(E)
| _ ⇒ constr:((boxer E)::nil)
end in
let rec go pos :=
match pos with
| nil ⇒ cont tt
| (boxer ?n)::?pos' ⇒ equates_one n; [ go pos' | ]
end in
go all_pos.
Tactic Notation "equates" constr(E) :=
equates_several E ltac:(fun _ ⇒ idtac).
Tactic Notation "equates" constr(n1) constr(n2) :=
equates (>> n1 n2).
Tactic Notation "equates" constr(n1) constr(n2) constr(n3) :=
equates (>> n1 n2 n3).
Tactic Notation "equates" constr(n1) constr(n2) constr(n3) constr(n4) :=
equates (>> n1 n2 n3 n4).
Variables (A0 A1 : Type).
Variables (A2 : ∀ (x1 : A1), Type).
Variables (A3 : ∀ (x1 : A1) (x2 : A2 x1), Type).
Variables (A4 : ∀ (x1 : A1) (x2 : A2 x1) (x3 : A3 x2), Type).
Variables (A5 : ∀ (x1 : A1) (x2 : A2 x1) (x3 : A3 x2) (x4 : A4 x3), Type).
Variables (A6 : ∀ (x1 : A1) (x2 : A2 x1) (x3 : A3 x2) (x4 : A4 x3) (x5 : A5 x4), Type).
Lemma equates_0 : ∀ (P Q:Prop),
P → P = Q → Q.
Proof using. intros. subst. auto. Qed.
Lemma equates_1 :
∀ (P:A0→Prop) x1 y1,
P y1 → x1 = y1 → P x1.
Proof using. intros. subst. auto. Qed.
Lemma equates_2 :
∀ y1 (P:A0→∀(x1:A1),Prop) x1 x2,
P y1 x2 → x1 = y1 → P x1 x2.
Proof using. intros. subst. auto. Qed.
Lemma equates_3 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1),Prop) x1 x2 x3,
P y1 x2 x3 → x1 = y1 → P x1 x2 x3.
Proof using. intros. subst. auto. Qed.
Lemma equates_4 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1)(x3:A3 x2),Prop) x1 x2 x3 x4,
P y1 x2 x3 x4 → x1 = y1 → P x1 x2 x3 x4.
Proof using. intros. subst. auto. Qed.
Lemma equates_5 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1)(x3:A3 x2)(x4:A4 x3),Prop) x1 x2 x3 x4 x5,
P y1 x2 x3 x4 x5 → x1 = y1 → P x1 x2 x3 x4 x5.
Proof using. intros. subst. auto. Qed.
Lemma equates_6 :
∀ y1 (P:A0→∀(x1:A1)(x2:A2 x1)(x3:A3 x2)(x4:A4 x3)(x5:A5 x4),Prop)
x1 x2 x3 x4 x5 x6,
P y1 x2 x3 x4 x5 x6 → x1 = y1 → P x1 x2 x3 x4 x5 x6.
Proof using. intros. subst. auto. Qed.
End equatesLemma.
Ltac equates_lemma n :=
match number_to_nat n with
| 0 ⇒ constr:(equates_0)
| 1 ⇒ constr:(equates_1)
| 2 ⇒ constr:(equates_2)
| 3 ⇒ constr:(equates_3)
| 4 ⇒ constr:(equates_4)
| 5 ⇒ constr:(equates_5)
| 6 ⇒ constr:(equates_6)
| _ ⇒ fail 100 "equates tactic only support up to arity 6"
end.
Ltac equates_one n :=
let L := equates_lemma n in
eapply L.
Ltac equates_several E cont :=
let all_pos := match type of E with
| List.list Boxer ⇒ constr:(E)
| _ ⇒ constr:((boxer E)::nil)
end in
let rec go pos :=
match pos with
| nil ⇒ cont tt
| (boxer ?n)::?pos' ⇒ equates_one n; [ go pos' | ]
end in
go all_pos.
Tactic Notation "equates" constr(E) :=
equates_several E ltac:(fun _ ⇒ idtac).
Tactic Notation "equates" constr(n1) constr(n2) :=
equates (>> n1 n2).
Tactic Notation "equates" constr(n1) constr(n2) constr(n3) :=
equates (>> n1 n2 n3).
Tactic Notation "equates" constr(n1) constr(n2) constr(n3) constr(n4) :=
equates (>> n1 n2 n3 n4).
applys_eq H i1 .. iK 等同于
先 equates i1 .. iK,
再在第一个子目标上 applys H。
已废弃:请改用 applys_eq H。
Tactic Notation "applys_eq" constr(H) constr(E) :=
equates_several E ltac:(fun _ ⇒ sapply H).
Tactic Notation "applys_eq" constr(H) constr(n1) constr(n2) :=
applys_eq H (>> n1 n2).
Tactic Notation "applys_eq" constr(H) constr(n1) constr(n2) constr(n3) :=
applys_eq H (>> n1 n2 n3).
Tactic Notation "applys_eq" constr(H) constr(n1) constr(n2) constr(n3) constr(n4) :=
applys_eq H (>> n1 n2 n3 n4).
equates_several E ltac:(fun _ ⇒ sapply H).
Tactic Notation "applys_eq" constr(H) constr(n1) constr(n2) :=
applys_eq H (>> n1 n2).
Tactic Notation "applys_eq" constr(H) constr(n1) constr(n2) constr(n3) :=
applys_eq H (>> n1 n2 n3).
Tactic Notation "applys_eq" constr(H) constr(n1) constr(n2) constr(n3) constr(n4) :=
applys_eq H (>> n1 n2 n3 n4).
applys_eq H 助力从结论为 P y1 .. yN 的假设 H
证明形如 P x1 .. xN 的目标,
其中实参 xi 与 yi 可能可转换也可能不可。
对所有无法归一的实参都会产生等式。
该策略对所有实参调用 equates,
然后调用 applys K,
并对旁支等式尝试 reflexivity。
Lemma applys_eq_init : ∀ (P Q:Prop),
P = Q →
Q →
P.
Proof using. intros. subst. auto. Qed.
Lemma applys_eq_step_dep : ∀ B (P Q: (∀ A, A→B)) (T:Type),
P = Q →
P T = Q T.
Proof using. intros. subst. auto. Qed.
Lemma applys_eq_step : ∀ A B (P Q:A→B) x y,
P = Q →
x = y →
P x = Q y.
Proof using. intros. subst. auto. Qed.
Ltac applys_eq_loop tt :=
match goal with
| ⊢ ?P ?x ⇒
first [ eapply applys_eq_step; [ applys_eq_loop tt | ]
| eapply applys_eq_step_dep; applys_eq_loop tt ]
| _ ⇒ reflexivity
end.
Ltac applys_eq_core H :=
eapply applys_eq_init;
[ applys_eq_loop tt | applys H ];
try reflexivity.
Tactic Notation "applys_eq" constr(H) :=
applys_eq_core H.
P = Q →
Q →
P.
Proof using. intros. subst. auto. Qed.
Lemma applys_eq_step_dep : ∀ B (P Q: (∀ A, A→B)) (T:Type),
P = Q →
P T = Q T.
Proof using. intros. subst. auto. Qed.
Lemma applys_eq_step : ∀ A B (P Q:A→B) x y,
P = Q →
x = y →
P x = Q y.
Proof using. intros. subst. auto. Qed.
Ltac applys_eq_loop tt :=
match goal with
| ⊢ ?P ?x ⇒
first [ eapply applys_eq_step; [ applys_eq_loop tt | ]
| eapply applys_eq_step_dep; applys_eq_loop tt ]
| _ ⇒ reflexivity
end.
Ltac applys_eq_core H :=
eapply applys_eq_init;
[ applys_eq_loop tt | applys H ];
try reflexivity.
Tactic Notation "applys_eq" constr(H) :=
applys_eq_core H.
Tactic Notation "false_goal" :=
exfalso.
exfalso.
false_post 是用来证明形如 False 的目标的底层策略。
在默认实现中,若语境含有 False,
或含有形如 C x1 .. xN = D y1 .. yM 的假设,
或 congruence 策略能为某个 x 找到 x ≠ x 的证明,
它就证明该目标。
Ltac false_post :=
solve [ assumption | discriminate | congruence ].
solve [ assumption | discriminate | congruence ].
false 把任意目标替换为目标 False,并调用 false_post
Tactic Notation "false" :=
false_goal; try false_post.
false_goal; try false_post.
tryfalse 尝试用矛盾解出目标,
解不出则保持目标不变。
它等价于 try solve \[ false \]。
Tactic Notation "tryfalse" :=
try solve [ false ].
try solve [ false ].
false E 尝试利用引理 E 来把目标证为假。
false E1 .. EN 等价于 false (>> E1 .. EN),
它先尝试应用 applys (>> E1 .. EN),
不行则尝试 forwards H: (>> E1 .. EN)
再接 false
Ltac false_then E cont :=
false_goal; first
[ applys E
| forwards_then E ltac:(fun M ⇒
pose M; jauto_set_hyps; intros; false) ];
cont tt.
(* 注:cont 是必需的吗?*)
Tactic Notation "false" constr(E) :=
false_then E ltac:(fun _ ⇒ idtac).
Tactic Notation "false" constr(E) constr(E1) :=
false (>> E E1).
Tactic Notation "false" constr(E) constr(E1) constr(E2) :=
false (>> E E1 E2).
Tactic Notation "false" constr(E) constr(E1) constr(E2) constr(E3) :=
false (>> E E1 E2 E3).
Tactic Notation "false" constr(E) constr(E1) constr(E2) constr(E3) constr(E4) :=
false (>> E E1 E2 E3 E4).
false_goal; first
[ applys E
| forwards_then E ltac:(fun M ⇒
pose M; jauto_set_hyps; intros; false) ];
cont tt.
(* 注:cont 是必需的吗?*)
Tactic Notation "false" constr(E) :=
false_then E ltac:(fun _ ⇒ idtac).
Tactic Notation "false" constr(E) constr(E1) :=
false (>> E E1).
Tactic Notation "false" constr(E) constr(E1) constr(E2) :=
false (>> E E1 E2).
Tactic Notation "false" constr(E) constr(E1) constr(E2) constr(E3) :=
false (>> E E1 E2 E3).
Tactic Notation "false" constr(E) constr(E1) constr(E2) constr(E3) constr(E4) :=
false (>> E E1 E2 E3 E4).
若调用 inversion H 与 false 之后
目标变得荒谬,则 false_invert H 证明该目标
Ltac false_invert_for H :=
let M := fresh "TEMP" in pose (M := H); inversion H; false.
Tactic Notation "false_invert" constr(H) :=
try solve [ false_invert_for H | false ].
let M := fresh "TEMP" in pose (M := H); inversion H; false.
Tactic Notation "false_invert" constr(H) :=
try solve [ false_invert_for H | false ].
只要语境中(或作为全称量化假设出现在目标头部的)
至少有一条假设 H,
调用 inversion H 能把它证为荒谬,
false_invert 就能证明任何目标。
Ltac false_invert_iter :=
match goal with H:_ ⊢ _ ⇒
solve [ inversion H; false
| clear H; false_invert_iter
| fail 2 ] end.
Tactic Notation "false_invert" :=
intros; solve [ false_invert_iter | false ].
match goal with H:_ ⊢ _ ⇒
solve [ inversion H; false
| clear H; false_invert_iter
| fail 2 ] end.
Tactic Notation "false_invert" :=
intros; solve [ false_invert_iter | false ].
tryfalse_invert H 与 tryfalse_invert 类似上面二者,
但解不出时保持目标不变。
Tactic Notation "tryfalse_invert" constr(H) :=
try (false_invert H).
Tactic Notation "tryfalse_invert" :=
try false_invert.
try (false_invert H).
Tactic Notation "tryfalse_invert" :=
try false_invert.
若语境含有形如 E ≠ E 的假设,
false_neq_self_hyp 就能证明任何目标。
它是 false 的受限优化版本,
仅供其他策略使用。
引入
- 若对形如 ∀ x, H 的目标调用 introv, 它应引入目标头部所有用 ∀ 量化的变量, 但不引入位于箭头构造子之前的假设, 如 P → Q 中那样。
- 若对既非 ∀ x, H 也非 P → Q 的目标调用 introv,该策略会展开定义, 直到目标形如 ∀ x, H 或 P → Q。 若展开定义并不产生这种形式的目标, 则策略 introv 什么也不做。
(* introv_rec 引入所有可见变量。
它不尝试展开任何定义。 *)
Ltac introv_rec :=
match goal with
| ⊢ ?P → ?Q ⇒ idtac
| ⊢ ∀ _, _ ⇒ intro; introv_rec
| ⊢ _ ⇒ idtac
end.
(* introv_noarg 迫使目标成为 ∀ 或 →,
然后调用 introv_rec 引入变量
(可能没有,此时 introv 等同于 hnf)。
若目标不是乘积类型,则什么也不做。 *)
Ltac introv_noarg :=
match goal with
| ⊢ ?P → ?Q ⇒ idtac
| ⊢ ∀ _, _ ⇒ introv_rec
| ⊢ ?G ⇒ hnf;
match goal with
| ⊢ ?P → ?Q ⇒ idtac
| ⊢ ∀ _, _ ⇒ introv_rec
end
| ⊢ _ ⇒ idtac
end.
(* 更简单但也许效率更低的实现 *)
Ltac introv_noarg_not_optimized :=
intro; match goal with H:_⊢_ ⇒ revert H end; introv_rec.
(* introv_arg H 先引入该假设之前用 ∀ 量化的变量,
再以名字 H 引入一条非依值假设。
若不存在可引入的假设,该策略失败。 *)
(* 注:introv 中的 __ 表示 "intros" *)
Ltac introv_arg H :=
hnf; match goal with
| ⊢ ?P → ?Q ⇒ intros H
| ⊢ ∀ _, _ ⇒ intro; introv_arg H
end.
(* introv I1 .. IN 对 introv Ik 迭代 *)
Tactic Notation "introv" :=
introv_noarg.
Tactic Notation "introv" simple_intropattern(I1) :=
introv_arg I1.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2) :=
introv I1; introv I2.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) :=
introv I1; introv I2 I3.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) :=
introv I1; introv I2 I3 I4.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5) :=
introv I1; introv I2 I3 I4 I5.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) :=
introv I1; introv I2 I3 I4 I5 I6.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) :=
introv I1; introv I2 I3 I4 I5 I6 I7.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8) :=
introv I1; introv I2 I3 I4 I5 I6 I7 I8.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) :=
introv I1; introv I2 I3 I4 I5 I6 I7 I8 I9.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) simple_intropattern(I10) :=
introv I1; introv I2 I3 I4 I5 I6 I7 I8 I9 I10.
它不尝试展开任何定义。 *)
Ltac introv_rec :=
match goal with
| ⊢ ?P → ?Q ⇒ idtac
| ⊢ ∀ _, _ ⇒ intro; introv_rec
| ⊢ _ ⇒ idtac
end.
(* introv_noarg 迫使目标成为 ∀ 或 →,
然后调用 introv_rec 引入变量
(可能没有,此时 introv 等同于 hnf)。
若目标不是乘积类型,则什么也不做。 *)
Ltac introv_noarg :=
match goal with
| ⊢ ?P → ?Q ⇒ idtac
| ⊢ ∀ _, _ ⇒ introv_rec
| ⊢ ?G ⇒ hnf;
match goal with
| ⊢ ?P → ?Q ⇒ idtac
| ⊢ ∀ _, _ ⇒ introv_rec
end
| ⊢ _ ⇒ idtac
end.
(* 更简单但也许效率更低的实现 *)
Ltac introv_noarg_not_optimized :=
intro; match goal with H:_⊢_ ⇒ revert H end; introv_rec.
(* introv_arg H 先引入该假设之前用 ∀ 量化的变量,
再以名字 H 引入一条非依值假设。
若不存在可引入的假设,该策略失败。 *)
(* 注:introv 中的 __ 表示 "intros" *)
Ltac introv_arg H :=
hnf; match goal with
| ⊢ ?P → ?Q ⇒ intros H
| ⊢ ∀ _, _ ⇒ intro; introv_arg H
end.
(* introv I1 .. IN 对 introv Ik 迭代 *)
Tactic Notation "introv" :=
introv_noarg.
Tactic Notation "introv" simple_intropattern(I1) :=
introv_arg I1.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2) :=
introv I1; introv I2.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) :=
introv I1; introv I2 I3.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) :=
introv I1; introv I2 I3 I4.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5) :=
introv I1; introv I2 I3 I4 I5.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) :=
introv I1; introv I2 I3 I4 I5 I6.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) :=
introv I1; introv I2 I3 I4 I5 I6 I7.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8) :=
introv I1; introv I2 I3 I4 I5 I6 I7 I8.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) :=
introv I1; introv I2 I3 I4 I5 I6 I7 I8 I9.
Tactic Notation "introv" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) simple_intropattern(I10) :=
introv I1; introv I2 I3 I4 I5 I6 I7 I8 I9 I10.
intros_all 尽可能久地重复 intro。
与 intros 不同,它沿途展开任何定义。
注意它还会展开否定的定义,
所以对形如 ∀ x, P x → ¬Q 的目标
应用 intros_all 会引入 x、P x 与 Q,
并把 False 留在目标中。
Tactic Notation "intros_all" :=
repeat intro.
repeat intro.
intros_hnf 引入一条假设并把它置于头范式
Tactic Notation "intro_hnf" :=
intro; match goal with H: _ ⊢ _ ⇒ hnf in H end.
intro; match goal with H: _ ⊢ _ ⇒ hnf in H end.
(* ⇒ I1 .. IN 与 intros I1 .. IN 相同 *)
Ltac ltac_intros_post := idtac.
Tactic Notation "=>" :=
intros.
Tactic Notation "=>" simple_intropattern(I1) :=
intros I1.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2) :=
intros I1 I2.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) :=
intros I1 I2 I3.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) :=
intros I1 I2 I3 I4.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5) :=
intros I1 I2 I3 I4 I5.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) :=
intros I1 I2 I3 I4 I5 I6.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) :=
intros I1 I2 I3 I4 I5 I6 I7.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8) :=
intros I1 I2 I3 I4 I5 I6 I7 I8.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) :=
intros I1 I2 I3 I4 I5 I6 I7 I8 I9.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) simple_intropattern(I10) :=
intros I1 I2 I3 I4 I5 I6 I7 I8 I9 I10.
(* =>> 先引入所有非依值变量,然后表现得如同 intros。
若头部没有可见量词,它用 hnf 展开目标的头部。
注:Inhab 的实例被视为非依值的并被自动引入。 *)
(* 注:本策略后面会为支持 Inhab 而重新定义 *)
Ltac intro_nondeps_aux_special_intro G :=
fail.
Ltac intro_nondeps_aux is_already_hnf :=
match goal with
| ⊢ (?P → ?Q) ⇒ idtac
| ⊢ ?G → _ ⇒ intro_nondeps_aux_special_intro G;
intro; intro_nondeps_aux true
| ⊢ (∀ _,_) ⇒ intros ?; intro_nondeps_aux true
| ⊢ _ ⇒
match is_already_hnf with
| true ⇒ idtac
| false ⇒ hnf; intro_nondeps_aux true
end
end.
Ltac intro_nondeps tt := intro_nondeps_aux false.
Tactic Notation "=>>" :=
intro_nondeps tt.
Tactic Notation "=>>" simple_intropattern(I1) :=
=>>; intros I1.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2) :=
=>>; intros I1 I2.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) :=
=>>; intros I1 I2 I3.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) :=
=>>; intros I1 I2 I3 I4.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5) :=
=>>; intros I1 I2 I3 I4 I5.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) :=
=>>; intros I1 I2 I3 I4 I5 I6.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7 I8.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7 I8 I9.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) simple_intropattern(I10) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7 I8 I9 I10.
Ltac ltac_intros_post := idtac.
Tactic Notation "=>" :=
intros.
Tactic Notation "=>" simple_intropattern(I1) :=
intros I1.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2) :=
intros I1 I2.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) :=
intros I1 I2 I3.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) :=
intros I1 I2 I3 I4.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5) :=
intros I1 I2 I3 I4 I5.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) :=
intros I1 I2 I3 I4 I5 I6.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) :=
intros I1 I2 I3 I4 I5 I6 I7.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8) :=
intros I1 I2 I3 I4 I5 I6 I7 I8.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) :=
intros I1 I2 I3 I4 I5 I6 I7 I8 I9.
Tactic Notation "=>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) simple_intropattern(I10) :=
intros I1 I2 I3 I4 I5 I6 I7 I8 I9 I10.
(* =>> 先引入所有非依值变量,然后表现得如同 intros。
若头部没有可见量词,它用 hnf 展开目标的头部。
注:Inhab 的实例被视为非依值的并被自动引入。 *)
(* 注:本策略后面会为支持 Inhab 而重新定义 *)
Ltac intro_nondeps_aux_special_intro G :=
fail.
Ltac intro_nondeps_aux is_already_hnf :=
match goal with
| ⊢ (?P → ?Q) ⇒ idtac
| ⊢ ?G → _ ⇒ intro_nondeps_aux_special_intro G;
intro; intro_nondeps_aux true
| ⊢ (∀ _,_) ⇒ intros ?; intro_nondeps_aux true
| ⊢ _ ⇒
match is_already_hnf with
| true ⇒ idtac
| false ⇒ hnf; intro_nondeps_aux true
end
end.
Ltac intro_nondeps tt := intro_nondeps_aux false.
Tactic Notation "=>>" :=
intro_nondeps tt.
Tactic Notation "=>>" simple_intropattern(I1) :=
=>>; intros I1.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2) :=
=>>; intros I1 I2.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) :=
=>>; intros I1 I2 I3.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) :=
=>>; intros I1 I2 I3 I4.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5) :=
=>>; intros I1 I2 I3 I4 I5.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) :=
=>>; intros I1 I2 I3 I4 I5 I6.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7 I8.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7 I8 I9.
Tactic Notation "=>>" simple_intropattern(I1) simple_intropattern(I2)
simple_intropattern(I3) simple_intropattern(I4) simple_intropattern(I5)
simple_intropattern(I6) simple_intropattern(I7) simple_intropattern(I8)
simple_intropattern(I9) simple_intropattern(I10) :=
=>>; intros I1 I2 I3 I4 I5 I6 I7 I8 I9 I10.
泛化
Tactic Notation "gen" ident(X1) :=
generalize dependent X1.
Tactic Notation "gen" ident(X1) ident(X2) :=
gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) :=
gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) :=
gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5) :=
gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) :=
gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) :=
gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) ident(X8) :=
gen X8; gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) ident(X8) ident(X9) :=
gen X9; gen X8; gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) ident(X8) ident(X9) ident(X10) :=
gen X10; gen X9; gen X8; gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
generalize dependent X1.
Tactic Notation "gen" ident(X1) ident(X2) :=
gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) :=
gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) :=
gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5) :=
gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) :=
gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) :=
gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) ident(X8) :=
gen X8; gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) ident(X8) ident(X9) :=
gen X9; gen X8; gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
Tactic Notation "gen" ident(X1) ident(X2) ident(X3) ident(X4) ident(X5)
ident(X6) ident(X7) ident(X8) ident(X9) ident(X10) :=
gen X10; gen X9; gen X8; gen X7; gen X6; gen X5; gen X4; gen X3; gen X2; gen X1.
generalizes X 是调用 generalize X; clear X 的简写。
它比策略 gen X 弱,因为不支持依赖关系。
它主要用于编写策略。
Tactic Notation "generalizes" hyp(X) :=
generalize X; clear X.
Tactic Notation "generalizes" hyp(X1) hyp(X2) :=
generalizes X1; generalizes X2.
Tactic Notation "generalizes" hyp(X1) hyp(X2) hyp(X3) :=
generalizes X1 X2; generalizes X3.
Tactic Notation "generalizes" hyp(X1) hyp(X2) hyp(X3) hyp(X4) :=
generalizes X1 X2 X3; generalizes X4.
generalize X; clear X.
Tactic Notation "generalizes" hyp(X1) hyp(X2) :=
generalizes X1; generalizes X2.
Tactic Notation "generalizes" hyp(X1) hyp(X2) hyp(X3) :=
generalizes X1 X2; generalizes X3.
Tactic Notation "generalizes" hyp(X1) hyp(X2) hyp(X3) hyp(X4) :=
generalizes X1 X2 X3; generalizes X4.
Tactic Notation "sets" ident(X) ":" constr(E) :=
set (X := E) in ×.
set (X := E) in ×.
当 X := E 是局部定义时适用 def_to_eq E X H。
它添加假设 H: X = E,
然后清除 X 的定义。
def_to_eq_sym 类似,只是它产生等式 H: E = X。
Ltac def_to_eq X HX E :=
assert (HX : X = E) by reflexivity; clearbody X.
Ltac def_to_eq_sym X HX E :=
assert (HX : E = X) by reflexivity; clearbody X.
assert (HX : X = E) by reflexivity; clearbody X.
Ltac def_to_eq_sym X HX E :=
assert (HX : E = X) by reflexivity; clearbody X.
set_eq X H: E 以新名字 X 产生等式 H: X = E,
并在当前目标中用 X 替换 E。
语法 set_eq X: E 与 set_eq: E 也可用。
类似地,set_eq <- X H: E 产生等式 H: E = X。
sets_eq X HX: E 作用相同,
但在目标中各处用 X 替换 E。
sets_eq X HX: E in H 在 H 中替换。
set_eq X HX: E in ⊢ 完全不做替换。
Tactic Notation "set_eq" ident(X) ident(HX) ":" constr(E) :=
set (X := E); def_to_eq X HX E.
Tactic Notation "set_eq" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in set_eq X HX: E.
Tactic Notation "set_eq" ":" constr(E) :=
let X := fresh "X" in set_eq X: E.
Tactic Notation "set_eq" "<-" ident(X) ident(HX) ":" constr(E) :=
set (X := E); def_to_eq_sym X HX E.
Tactic Notation "set_eq" "<-" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in set_eq <- X HX: E.
Tactic Notation "set_eq" "<-" ":" constr(E) :=
let X := fresh "X" in set_eq <- X: E.
Tactic Notation "sets_eq" ident(X) ident(HX) ":" constr(E) :=
set (X := E) in *; def_to_eq X HX E.
Tactic Notation "sets_eq" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in sets_eq X HX: E.
Tactic Notation "sets_eq" ":" constr(E) :=
let X := fresh "X" in sets_eq X: E.
Tactic Notation "sets_eq" "<-" ident(X) ident(HX) ":" constr(E) :=
set (X := E) in *; def_to_eq_sym X HX E.
Tactic Notation "sets_eq" "<-" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in sets_eq <- X HX: E.
Tactic Notation "sets_eq" "<-" ":" constr(E) :=
let X := fresh "X" in sets_eq <- X: E.
Tactic Notation "set_eq" ident(X) ident(HX) ":" constr(E) "in" hyp(H) :=
set (X := E) in H; def_to_eq X HX E.
Tactic Notation "set_eq" ident(X) ":" constr(E) "in" hyp(H) :=
let HX := fresh "EQ" X in set_eq X HX: E in H.
Tactic Notation "set_eq" ":" constr(E) "in" hyp(H) :=
let X := fresh "X" in set_eq X: E in H.
Tactic Notation "set_eq" "<-" ident(X) ident(HX) ":" constr(E) "in" hyp(H) :=
set (X := E) in H; def_to_eq_sym X HX E.
Tactic Notation "set_eq" "<-" ident(X) ":" constr(E) "in" hyp(H) :=
let HX := fresh "EQ" X in set_eq <- X HX: E in H.
Tactic Notation "set_eq" "<-" ":" constr(E) "in" hyp(H) :=
let X := fresh "X" in set_eq <- X: E in H.
Tactic Notation "set_eq" ident(X) ident(HX) ":" constr(E) "in" "⊢" :=
set (X := E) in ⊢; def_to_eq X HX E.
Tactic Notation "set_eq" ident(X) ":" constr(E) "in" "⊢" :=
let HX := fresh "EQ" X in set_eq X HX: E in ⊢.
Tactic Notation "set_eq" ":" constr(E) "in" "⊢" :=
let X := fresh "X" in set_eq X: E in ⊢.
Tactic Notation "set_eq" "<-" ident(X) ident(HX) ":" constr(E) "in" "⊢" :=
set (X := E) in ⊢; def_to_eq_sym X HX E.
Tactic Notation "set_eq" "<-" ident(X) ":" constr(E) "in" "⊢" :=
let HX := fresh "EQ" X in set_eq <- X HX: E in ⊢.
Tactic Notation "set_eq" "<-" ":" constr(E) "in" "⊢" :=
let X := fresh "X" in set_eq <- X: E in ⊢.
set (X := E); def_to_eq X HX E.
Tactic Notation "set_eq" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in set_eq X HX: E.
Tactic Notation "set_eq" ":" constr(E) :=
let X := fresh "X" in set_eq X: E.
Tactic Notation "set_eq" "<-" ident(X) ident(HX) ":" constr(E) :=
set (X := E); def_to_eq_sym X HX E.
Tactic Notation "set_eq" "<-" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in set_eq <- X HX: E.
Tactic Notation "set_eq" "<-" ":" constr(E) :=
let X := fresh "X" in set_eq <- X: E.
Tactic Notation "sets_eq" ident(X) ident(HX) ":" constr(E) :=
set (X := E) in *; def_to_eq X HX E.
Tactic Notation "sets_eq" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in sets_eq X HX: E.
Tactic Notation "sets_eq" ":" constr(E) :=
let X := fresh "X" in sets_eq X: E.
Tactic Notation "sets_eq" "<-" ident(X) ident(HX) ":" constr(E) :=
set (X := E) in *; def_to_eq_sym X HX E.
Tactic Notation "sets_eq" "<-" ident(X) ":" constr(E) :=
let HX := fresh "EQ" X in sets_eq <- X HX: E.
Tactic Notation "sets_eq" "<-" ":" constr(E) :=
let X := fresh "X" in sets_eq <- X: E.
Tactic Notation "set_eq" ident(X) ident(HX) ":" constr(E) "in" hyp(H) :=
set (X := E) in H; def_to_eq X HX E.
Tactic Notation "set_eq" ident(X) ":" constr(E) "in" hyp(H) :=
let HX := fresh "EQ" X in set_eq X HX: E in H.
Tactic Notation "set_eq" ":" constr(E) "in" hyp(H) :=
let X := fresh "X" in set_eq X: E in H.
Tactic Notation "set_eq" "<-" ident(X) ident(HX) ":" constr(E) "in" hyp(H) :=
set (X := E) in H; def_to_eq_sym X HX E.
Tactic Notation "set_eq" "<-" ident(X) ":" constr(E) "in" hyp(H) :=
let HX := fresh "EQ" X in set_eq <- X HX: E in H.
Tactic Notation "set_eq" "<-" ":" constr(E) "in" hyp(H) :=
let X := fresh "X" in set_eq <- X: E in H.
Tactic Notation "set_eq" ident(X) ident(HX) ":" constr(E) "in" "⊢" :=
set (X := E) in ⊢; def_to_eq X HX E.
Tactic Notation "set_eq" ident(X) ":" constr(E) "in" "⊢" :=
let HX := fresh "EQ" X in set_eq X HX: E in ⊢.
Tactic Notation "set_eq" ":" constr(E) "in" "⊢" :=
let X := fresh "X" in set_eq X: E in ⊢.
Tactic Notation "set_eq" "<-" ident(X) ident(HX) ":" constr(E) "in" "⊢" :=
set (X := E) in ⊢; def_to_eq_sym X HX E.
Tactic Notation "set_eq" "<-" ident(X) ":" constr(E) "in" "⊢" :=
let HX := fresh "EQ" X in set_eq <- X HX: E in ⊢.
Tactic Notation "set_eq" "<-" ":" constr(E) "in" "⊢" :=
let X := fresh "X" in set_eq <- X: E in ⊢.
gen_eq X: E 是一个引入等式的策略,
用以绕开 induction 策略通常丢失信息的局限。
gen_eq E as X 用新变量 X 替换项 E 的所有出现,
并把等式 X = E 作为额外假设加到当前结论上。
换言之,结论 C 将变成 (X = E) → C。
gen_eq: E 与 gen_eq: E as X 也被接受。
Tactic Notation "gen_eq" ident(X) ":" constr(E) :=
let EQ := fresh "EQ" X in sets_eq X EQ: E; revert EQ.
Tactic Notation "gen_eq" ":" constr(E) :=
let X := fresh "X" in gen_eq X: E.
Tactic Notation "gen_eq" ":" constr(E) "as" ident(X) :=
gen_eq X: E.
Tactic Notation "gen_eq" ident(X1) ":" constr(E1) ","
ident(X2) ":" constr(E2) :=
gen_eq X2: E2; gen_eq X1: E1.
Tactic Notation "gen_eq" ident(X1) ":" constr(E1) ","
ident(X2) ":" constr(E2) "," ident(X3) ":" constr(E3) :=
gen_eq X3: E3; gen_eq X2: E2; gen_eq X1: E1.
let EQ := fresh "EQ" X in sets_eq X EQ: E; revert EQ.
Tactic Notation "gen_eq" ":" constr(E) :=
let X := fresh "X" in gen_eq X: E.
Tactic Notation "gen_eq" ":" constr(E) "as" ident(X) :=
gen_eq X: E.
Tactic Notation "gen_eq" ident(X1) ":" constr(E1) ","
ident(X2) ":" constr(E2) :=
gen_eq X2: E2; gen_eq X1: E1.
Tactic Notation "gen_eq" ident(X1) ":" constr(E1) ","
ident(X2) ":" constr(E2) "," ident(X3) ":" constr(E3) :=
gen_eq X3: E3; gen_eq X2: E2; gen_eq X1: E1.
sets_let X 找到目标中第一个 let 表达式,
并把它的函数体命名为 X。sets_eq_let X 类似,
只是它产生一条显式等式。
策略 sets_let X in H 与 sets_eq_let X in H
允许指定特定的假设
(默认考虑第一个含 let 的假设)。
已知局限:从 ltac 似乎无法支持
为项内多个 let-in 构造命名。
Ltac sets_let_base tac :=
match goal with
| ⊢ context[let _ := ?E in _] ⇒ tac E; cbv zeta
| H: context[let _ := ?E in _] ⊢ _ ⇒ tac E; cbv zeta in H
end.
Ltac sets_let_in_base H tac :=
match type of H with context[let _ := ?E in _] ⇒
tac E; cbv zeta in H end.
Tactic Notation "sets_let" ident(X) :=
sets_let_base ltac:(fun E ⇒ sets X: E).
Tactic Notation "sets_let" ident(X) "in" hyp(H) :=
sets_let_in_base H ltac:(fun E ⇒ sets X: E).
Tactic Notation "sets_eq_let" ident(X) :=
sets_let_base ltac:(fun E ⇒ sets_eq X: E).
Tactic Notation "sets_eq_let" ident(X) "in" hyp(H) :=
sets_let_in_base H ltac:(fun E ⇒ sets_eq X: E).
match goal with
| ⊢ context[let _ := ?E in _] ⇒ tac E; cbv zeta
| H: context[let _ := ?E in _] ⊢ _ ⇒ tac E; cbv zeta in H
end.
Ltac sets_let_in_base H tac :=
match type of H with context[let _ := ?E in _] ⇒
tac E; cbv zeta in H end.
Tactic Notation "sets_let" ident(X) :=
sets_let_base ltac:(fun E ⇒ sets X: E).
Tactic Notation "sets_let" ident(X) "in" hyp(H) :=
sets_let_in_base H ltac:(fun E ⇒ sets X: E).
Tactic Notation "sets_eq_let" ident(X) :=
sets_let_base ltac:(fun E ⇒ sets_eq X: E).
Tactic Notation "sets_eq_let" ident(X) "in" hyp(H) :=
sets_let_in_base H ltac:(fun E ⇒ sets_eq X: E).
改写
Ltac rewrites_base E cont :=
match type of E with
| List.list Boxer ⇒ forwards_then E cont
| _ ⇒ cont E; fast_rm_inside E
end.
Tactic Notation "rewrites" constr(E) :=
rewrites_base E ltac:(fun M ⇒ rewrite M ).
Tactic Notation "rewrites" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ rewrite M in H).
Tactic Notation "rewrites" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ rewrite M in *).
Tactic Notation "rewrites" "<-" constr(E) :=
rewrites_base E ltac:(fun M ⇒ rewrite <- M ).
Tactic Notation "rewrites" "<-" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ rewrite <- M in H).
Tactic Notation "rewrites" "<-" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ rewrite <- M in *).
match type of E with
| List.list Boxer ⇒ forwards_then E cont
| _ ⇒ cont E; fast_rm_inside E
end.
Tactic Notation "rewrites" constr(E) :=
rewrites_base E ltac:(fun M ⇒ rewrite M ).
Tactic Notation "rewrites" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ rewrite M in H).
Tactic Notation "rewrites" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ rewrite M in *).
Tactic Notation "rewrites" "<-" constr(E) :=
rewrites_base E ltac:(fun M ⇒ rewrite <- M ).
Tactic Notation "rewrites" "<-" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ rewrite <- M in H).
Tactic Notation "rewrites" "<-" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ rewrite <- M in *).
erewrites E 类似 erewrite,
不同之处是它支持用 rm 指令随手清除假设,
并支持形如 rewrites (>> E1 E2 E3) 的实参列表,
表示在调用 rewrites 之前应先调用 forwards。
Tactic Notation "erewrites" constr(E) :=
rewrites_base E ltac:(fun M ⇒ erewrite M ).
Tactic Notation "erewrites" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ erewrite M in H).
Tactic Notation "erewrites" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ erewrite M in *).
Tactic Notation "erewrites" "<-" constr(E) :=
rewrites_base E ltac:(fun M ⇒ erewrite <- M ).
Tactic Notation "erewrites" "<-" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ erewrite <- M in H).
Tactic Notation "erewrites" "<-" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ erewrite <- M in *).
(* --注:是否应扩展下面的策略以使用 rewrites?*)
rewrites_base E ltac:(fun M ⇒ erewrite M ).
Tactic Notation "erewrites" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ erewrite M in H).
Tactic Notation "erewrites" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ erewrite M in *).
Tactic Notation "erewrites" "<-" constr(E) :=
rewrites_base E ltac:(fun M ⇒ erewrite <- M ).
Tactic Notation "erewrites" "<-" constr(E) "in" hyp(H) :=
rewrites_base E ltac:(fun M ⇒ erewrite <- M in H).
Tactic Notation "erewrites" "<-" constr(E) "in" "*" :=
rewrites_base E ltac:(fun M ⇒ erewrite <- M in *).
(* --注:是否应扩展下面的策略以使用 rewrites?*)
rewrite_all E 是尽可能反复执行 rewrite E 的版本。
警告:该策略很容易陷入无限循环。
从右往左【改写|Rewrite】和/或在假设中改写的语法
与 rewrite 的类似。
Tactic Notation "rewrite_all" constr(E) :=
repeat rewrite E.
Tactic Notation "rewrite_all" "<-" constr(E) :=
repeat rewrite <- E.
Tactic Notation "rewrite_all" constr(E) "in" ident(H) :=
repeat rewrite E in H.
Tactic Notation "rewrite_all" "<-" constr(E) "in" ident(H) :=
repeat rewrite <- E in H.
Tactic Notation "rewrite_all" constr(E) "in" "*" :=
repeat rewrite E in ×.
Tactic Notation "rewrite_all" "<-" constr(E) "in" "*" :=
repeat rewrite <- E in ×.
repeat rewrite E.
Tactic Notation "rewrite_all" "<-" constr(E) :=
repeat rewrite <- E.
Tactic Notation "rewrite_all" constr(E) "in" ident(H) :=
repeat rewrite E in H.
Tactic Notation "rewrite_all" "<-" constr(E) "in" ident(H) :=
repeat rewrite <- E in H.
Tactic Notation "rewrite_all" constr(E) "in" "*" :=
repeat rewrite E in ×.
Tactic Notation "rewrite_all" "<-" constr(E) "in" "*" :=
repeat rewrite <- E in ×.
asserts_rewrite E 断言等式 E 成立
(产生相应子目标),并立刻在当前目标中改写它。
这样就免去了给等式命名再清除它的麻烦。
从右往左改写和/或在假设中改写的语法
与 rewrite 的类似。
注:策略 replaces 起类似作用。
Ltac asserts_rewrite_tactic E action :=
let EQ := fresh "TEMP" in (assert (EQ : E);
[ idtac | action EQ; clear EQ ]).
Tactic Notation "asserts_rewrite" constr(E) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ).
Tactic Notation "asserts_rewrite" "<-" constr(E) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ).
Tactic Notation "asserts_rewrite" constr(E) "in" hyp(H) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ in H).
Tactic Notation "asserts_rewrite" "<-" constr(E) "in" hyp(H) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ in H).
Tactic Notation "asserts_rewrite" constr(E) "in" "*" :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ in *).
Tactic Notation "asserts_rewrite" "<-" constr(E) "in" "*" :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ in *).
let EQ := fresh "TEMP" in (assert (EQ : E);
[ idtac | action EQ; clear EQ ]).
Tactic Notation "asserts_rewrite" constr(E) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ).
Tactic Notation "asserts_rewrite" "<-" constr(E) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ).
Tactic Notation "asserts_rewrite" constr(E) "in" hyp(H) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ in H).
Tactic Notation "asserts_rewrite" "<-" constr(E) "in" hyp(H) :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ in H).
Tactic Notation "asserts_rewrite" constr(E) "in" "*" :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ in *).
Tactic Notation "asserts_rewrite" "<-" constr(E) "in" "*" :=
asserts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ in *).
cuts_rewrite E 与 asserts_rewrite E 相同,
只是子目标顺序对调。
Ltac cuts_rewrite_tactic E action :=
let EQ := fresh "TEMP" in (cuts EQ: E;
[ action EQ; clear EQ | idtac ]).
Tactic Notation "cuts_rewrite" constr(E) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ).
Tactic Notation "cuts_rewrite" "<-" constr(E) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ).
Tactic Notation "cuts_rewrite" constr(E) "in" hyp(H) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ in H).
Tactic Notation "cuts_rewrite" "<-" constr(E) "in" hyp(H) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ in H).
let EQ := fresh "TEMP" in (cuts EQ: E;
[ action EQ; clear EQ | idtac ]).
Tactic Notation "cuts_rewrite" constr(E) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ).
Tactic Notation "cuts_rewrite" "<-" constr(E) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ).
Tactic Notation "cuts_rewrite" constr(E) "in" hyp(H) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite EQ in H).
Tactic Notation "cuts_rewrite" "<-" constr(E) "in" hyp(H) :=
cuts_rewrite_tactic E ltac:(fun EQ ⇒ rewrite <- EQ in H).
rewrite_except H EQ 在除假设 H 之外的各处
改写等式 EQ。主要对其他策略有用。
Ltac rewrite_except H EQ :=
let K := fresh "TEMP" in let T := type of H in
set (K := T) in H;
rewrite EQ in *; unfold K in H; clear K.
let K := fresh "TEMP" in let T := type of H in
set (K := T) in H;
rewrite EQ in *; unfold K in H; clear K.
当 E 形如 T1 = T2 时,rewrites E at K
在当前目标中 T1 的第 K 次出现处改写等式 E。
语法 rewrites <- E at K 与 rewrites E at K in H
也可用。
Tactic Notation "rewrites" constr(E) "at" constr(K) :=
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T1 do (rewrites E) end.
Tactic Notation "rewrites" "<-" constr(E) "at" constr(K) :=
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T2 do (rewrites <- E) end.
Tactic Notation "rewrites" constr(E) "at" constr(K) "in" hyp(H) :=
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T1 in H do (rewrites E in H) end.
Tactic Notation "rewrites" "<-" constr(E) "at" constr(K) "in" hyp(H) :=
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T2 in H do (rewrites <- E in H) end.
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T1 do (rewrites E) end.
Tactic Notation "rewrites" "<-" constr(E) "at" constr(K) :=
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T2 do (rewrites <- E) end.
Tactic Notation "rewrites" constr(E) "at" constr(K) "in" hyp(H) :=
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T1 in H do (rewrites E in H) end.
Tactic Notation "rewrites" "<-" constr(E) "at" constr(K) "in" hyp(H) :=
match type of E with ?T1 = ?T2 ⇒
ltac_action_at K of T2 in H do (rewrites <- E in H) end.
替换
Tactic Notation "replaces" constr(E) "with" constr(F) :=
let T := fresh "TEMP" in assert (T: E = F); [ | replace E with F; clear T ].
Tactic Notation "replaces" constr(E) "with" constr(F) "in" hyp(H) :=
let T := fresh "TEMP" in assert (T: E = F); [ | replace E with F in H; clear T ].
let T := fresh "TEMP" in assert (T: E = F); [ | replace E with F; clear T ].
Tactic Notation "replaces" constr(E) "with" constr(F) "in" hyp(H) :=
let T := fresh "TEMP" in assert (T: E = F); [ | replace E with F in H; clear T ].
replaces E at K with F 在当前目标中
用 F 替换 E 的第 K 次出现。
语法 replaces E at K with F in H 也可用。
Tactic Notation "replaces" constr(E) "at" constr(K) "with" constr(F) :=
let T := fresh "TEMP" in assert (T: E = F); [ | rewrites T at K; clear T ].
Tactic Notation "replaces" constr(E) "at" constr(K) "with" constr(F) "in" hyp(H) :=
let T := fresh "TEMP" in assert (T: E = F); [ | rewrites T at K in H; clear T ].
let T := fresh "TEMP" in assert (T: E = F); [ | rewrites T at K; clear T ].
Tactic Notation "replaces" constr(E) "at" constr(K) "with" constr(F) "in" hyp(H) :=
let T := fresh "TEMP" in assert (T: E = F); [ | rewrites T at K in H; clear T ].
(* --注:是否应支持 "changes (E1 = E2)" *)
Tactic Notation "changes" constr(E1) "with" constr(E2) "in" hyp(H) :=
asserts_rewrite (E1 = E2) in H; [ reflexivity | ].
Tactic Notation "changes" constr(E1) "with" constr(E2) :=
asserts_rewrite (E1 = E2); [ reflexivity | ].
Tactic Notation "changes" constr(E1) "with" constr(E2) "in" "*" :=
asserts_rewrite (E1 = E2) in *; [ reflexivity | ].
Tactic Notation "changes" constr(E1) "with" constr(E2) "in" hyp(H) :=
asserts_rewrite (E1 = E2) in H; [ reflexivity | ].
Tactic Notation "changes" constr(E1) "with" constr(E2) :=
asserts_rewrite (E1 = E2); [ reflexivity | ].
Tactic Notation "changes" constr(E1) "with" constr(E2) "in" "*" :=
asserts_rewrite (E1 = E2) in *; [ reflexivity | ].
Tactic Notation "renames" ident(X1) "to" ident(Y1) :=
rename X1 into Y1.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) :=
renames X1 to Y1; renames X2 to Y2.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) ","
ident(X4) "to" ident(Y4) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3, X4 to Y4.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) ","
ident(X4) "to" ident(Y4) "," ident(X5) "to" ident(Y5) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3, X4 to Y4, X5 to Y5.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) ","
ident(X4) "to" ident(Y4) "," ident(X5) "to" ident(Y5) ","
ident(X6) "to" ident(Y6) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3, X4 to Y4, X5 to Y5, X6 to Y6.
rename X1 into Y1.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) :=
renames X1 to Y1; renames X2 to Y2.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) ","
ident(X4) "to" ident(Y4) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3, X4 to Y4.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) ","
ident(X4) "to" ident(Y4) "," ident(X5) "to" ident(Y5) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3, X4 to Y4, X5 to Y5.
Tactic Notation "renames" ident(X1) "to" ident(Y1) ","
ident(X2) "to" ident(Y2) "," ident(X3) "to" ident(Y3) ","
ident(X4) "to" ident(Y4) "," ident(X5) "to" ident(Y5) ","
ident(X6) "to" ident(Y6) :=
renames X1 to Y1; renames X2 to Y2, X3 to Y3, X4 to Y4, X5 to Y5, X6 to Y6.
展开
Ltac apply_to_head_of E cont :=
let go E :=
let P := get_head E in cont P in
match E with
| ∀ _,_ ⇒ intros; apply_to_head_of E cont
| ?A = ?B ⇒ first [ go A | go B ]
| ?A ⇒ go A
end.
Ltac unfolds_base :=
match goal with ⊢ ?G ⇒
apply_to_head_of G ltac:(fun P ⇒ unfold P) end.
Tactic Notation "unfolds" :=
unfolds_base.
let go E :=
let P := get_head E in cont P in
match E with
| ∀ _,_ ⇒ intros; apply_to_head_of E cont
| ?A = ?B ⇒ first [ go A | go B ]
| ?A ⇒ go A
end.
Ltac unfolds_base :=
match goal with ⊢ ?G ⇒
apply_to_head_of G ltac:(fun P ⇒ unfold P) end.
Tactic Notation "unfolds" :=
unfolds_base.
unfolds in H 展开假设 H 的头部定义,
即若 H 的类型为 P x1 ... xN
则调用 unfold P in H。
Ltac unfolds_in_base H :=
match type of H with ?G ⇒
apply_to_head_of G ltac:(fun P ⇒ unfold P in H) end.
Tactic Notation "unfolds" "in" hyp(H) :=
unfolds_in_base H.
match type of H with ?G ⇒
apply_to_head_of G ltac:(fun P ⇒ unfold P in H) end.
Tactic Notation "unfolds" "in" hyp(H) :=
unfolds_in_base H.
unfolds in H1,H2,..,HN 允许一次展开
多条假设中的头部常量。
Tactic Notation "unfolds" "in" hyp(H1) hyp(H2) :=
unfolds in H1; unfolds in H2.
Tactic Notation "unfolds" "in" hyp(H1) hyp(H2) hyp(H3) :=
unfolds in H1; unfolds in H2 H3.
Tactic Notation "unfolds" "in" hyp(H1) hyp(H2) hyp(H3) hyp(H4) :=
unfolds in H1; unfolds in H2 H3 H4.
Tactic Notation "unfolds" "in" hyp(H1) hyp(H2) hyp(H3) hyp(H4) hyp(H5) :=
unfolds in H1; unfolds in H2 H3 H4 H5.
unfolds in H1; unfolds in H2.
Tactic Notation "unfolds" "in" hyp(H1) hyp(H2) hyp(H3) :=
unfolds in H1; unfolds in H2 H3.
Tactic Notation "unfolds" "in" hyp(H1) hyp(H2) hyp(H3) hyp(H4) :=
unfolds in H1; unfolds in H2 H3 H4.
Tactic Notation "unfolds" "in" hyp(H1) hyp(H2) hyp(H3) hyp(H4) hyp(H5) :=
unfolds in H1; unfolds in H2 H3 H4 H5.
unfolds P1,..,PN 是 unfold P1,..,PN in × 的简写。
Tactic Notation "unfolds" constr(F1) :=
unfold F1 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2) :=
unfold F1,F2 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) :=
unfold F1,F2,F3 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) :=
unfold F1,F2,F3,F4 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5) :=
unfold F1,F2,F3,F4,F5 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5) "," constr(F6) :=
unfold F1,F2,F3,F4,F5,F6 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5)
"," constr(F6) "," constr(F7) :=
unfold F1,F2,F3,F4,F5,F6,F7 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5)
"," constr(F6) "," constr(F7) "," constr(F8) :=
unfold F1,F2,F3,F4,F5,F6,F7,F8 in ×.
unfold F1 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2) :=
unfold F1,F2 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) :=
unfold F1,F2,F3 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) :=
unfold F1,F2,F3,F4 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5) :=
unfold F1,F2,F3,F4,F5 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5) "," constr(F6) :=
unfold F1,F2,F3,F4,F5,F6 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5)
"," constr(F6) "," constr(F7) :=
unfold F1,F2,F3,F4,F5,F6,F7 in ×.
Tactic Notation "unfolds" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) "," constr(F5)
"," constr(F6) "," constr(F7) "," constr(F8) :=
unfold F1,F2,F3,F4,F5,F6,F7,F8 in ×.
folds P1,..,PN 是 fold P1 in *; ..; fold PN in × 的简写。
Tactic Notation "folds" constr(H) :=
fold H in ×.
Tactic Notation "folds" constr(H1) "," constr(H2) :=
folds H1; folds H2.
Tactic Notation "folds" constr(H1) "," constr(H2) "," constr(H3) :=
folds H1; folds H2; folds H3.
Tactic Notation "folds" constr(H1) "," constr(H2) "," constr(H3)
"," constr(H4) :=
folds H1; folds H2; folds H3; folds H4.
Tactic Notation "folds" constr(H1) "," constr(H2) "," constr(H3)
"," constr(H4) "," constr(H5) :=
folds H1; folds H2; folds H3; folds H4; folds H5.
fold H in ×.
Tactic Notation "folds" constr(H1) "," constr(H2) :=
folds H1; folds H2.
Tactic Notation "folds" constr(H1) "," constr(H2) "," constr(H3) :=
folds H1; folds H2; folds H3.
Tactic Notation "folds" constr(H1) "," constr(H2) "," constr(H3)
"," constr(H4) :=
folds H1; folds H2; folds H3; folds H4.
Tactic Notation "folds" constr(H1) "," constr(H2) "," constr(H3)
"," constr(H4) "," constr(H5) :=
folds H1; folds H2; folds H3; folds H4; folds H5.
Tactic Notation "simpls" :=
simpl in ×.
simpl in ×.
simpls P1,..,PN 是
simpl P1 in *; ..; simpl PN in × 的简写。
Tactic Notation "simpls" constr(F1) :=
simpl F1 in ×.
Tactic Notation "simpls" constr(F1) "," constr(F2) :=
simpls F1; simpls F2.
Tactic Notation "simpls" constr(F1) "," constr(F2)
"," constr(F3) :=
simpls F1; simpls F2; simpls F3.
Tactic Notation "simpls" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) :=
simpls F1; simpls F2; simpls F3; simpls F4.
simpl F1 in ×.
Tactic Notation "simpls" constr(F1) "," constr(F2) :=
simpls F1; simpls F2.
Tactic Notation "simpls" constr(F1) "," constr(F2)
"," constr(F3) :=
simpls F1; simpls F2; simpls F3.
Tactic Notation "simpls" constr(F1) "," constr(F2)
"," constr(F3) "," constr(F4) :=
simpls F1; simpls F2; simpls F3; simpls F4.
unsimpl E 用 E 替换 X 的所有出现,
其中 X 是策略 simpl 作用于 E 所得的结果。
它可用于撤销 simpl 化简过度的地方。
Tactic Notation "unsimpl" constr(E) :=
let F := (eval simpl in E) in change F with E.
let F := (eval simpl in E) in change F with E.
unsimpl E in H 类似 unsimpl E,
但作用于特定假设 H 内部。
Tactic Notation "unsimpl" constr(E) "in" hyp(H) :=
let F := (eval simpl in E) in change F with E in H.
let F := (eval simpl in E) in change F with E in H.
unsimpl E in × 在所有可能之处应用 unsimpl E。
unsimpls E 是同义写法。
Tactic Notation "unsimpl" constr(E) "in" "*" :=
let F := (eval simpl in E) in change F with E in ×.
Tactic Notation "unsimpls" constr(E) :=
unsimpl E in ×.
let F := (eval simpl in E) in change F with E in ×.
Tactic Notation "unsimpls" constr(E) :=
unsimpl E in ×.
nosimpl t 保护 Rocq 项 t 免受某些形式的化简。
此技巧的细节见 Gonthier 的工作。
Tactic Notation "hnfs" := hnf in ×.
Tactic Notation "substs" :=
repeat (match goal with H: ?x = ?y ⊢ _ ⇒
first [ subst x | subst y ] end).
repeat (match goal with H: ?x = ?y ⊢ _ ⇒
first [ subst x | subst y ] end).
substs below 的实现,它允许对证明语境中
位于给定位置之后的所有假设调用 subst。
Ltac substs_below limit :=
match goal with H: ?T ⊢ _ ⇒
match T with
| limit ⇒ idtac
| ?x = ?y ⇒
first [ subst x; substs_below limit
| subst y; substs_below limit
| generalizes H; substs_below limit; intro ]
end end.
match goal with H: ?T ⊢ _ ⇒
match T with
| limit ⇒ idtac
| ?x = ?y ⇒
first [ subst x; substs_below limit
| subst y; substs_below limit
| generalizes H; substs_below limit; intro ]
end end.
substs below body E 对语境中第一条函数体为 E
的假设之后出现的所有等式应用 subst。
若语境中没有这样的假设,则等价于 subst。
例如,若 H 是假设,
则 substs below H 会替换假设 H 之后的等式。
Tactic Notation "substs" "below" "body" constr(M) :=
substs_below M.
substs_below M.
substs below H 对语境中名字为 H 的假设之后
出现的所有等式应用 subst。
注意当前实现在技术上并不正确,
因为它会混淆函数体相同的不同假设。
Tactic Notation "substs" "below" hyp(H) :=
match type of H with ?M ⇒ substs below body M end.
match type of H with ?M ⇒ substs below body M end.
subst_hyp H 替换语境中第一条假设所含的等式。
Ltac intro_subst_hyp := fail. (* 定义见后文 *)
subst_hyp H 替换 H 中所含的等式。
Ltac subst_hyp_base H :=
match type of H with
| (_,_,_,_,_) = (_,_,_,_,_) ⇒ injection H; clear H; do 4 intro_subst_hyp
| (_,_,_,_) = (_,_,_,_) ⇒ injection H; clear H; do 4 intro_subst_hyp
| (_,_,_) = (_,_,_) ⇒ injection H; clear H; do 3 intro_subst_hyp
| (_,_) = (_,_) ⇒ injection H; clear H; do 2 intro_subst_hyp
| ?x = ?x ⇒ clear H
| ?x = ?y ⇒ first [ subst x | subst y ]
end.
Tactic Notation "subst_hyp" hyp(H) := subst_hyp_base H.
Ltac intro_subst_hyp ::=
let H := fresh "TEMP" in intros H; subst_hyp H.
match type of H with
| (_,_,_,_,_) = (_,_,_,_,_) ⇒ injection H; clear H; do 4 intro_subst_hyp
| (_,_,_,_) = (_,_,_,_) ⇒ injection H; clear H; do 4 intro_subst_hyp
| (_,_,_) = (_,_,_) ⇒ injection H; clear H; do 3 intro_subst_hyp
| (_,_) = (_,_) ⇒ injection H; clear H; do 2 intro_subst_hyp
| ?x = ?x ⇒ clear H
| ?x = ?y ⇒ first [ subst x | subst y ]
end.
Tactic Notation "subst_hyp" hyp(H) := subst_hyp_base H.
Ltac intro_subst_hyp ::=
let H := fresh "TEMP" in intros H; subst_hyp H.
intro_subst 是 intro H; subst_hyp H 的简写:
它引入并替换当前目标头部的等式。
Tactic Notation "intro_subst" :=
let H := fresh "TEMP" in intros H; subst_hyp H.
let H := fresh "TEMP" in intros H; subst_hyp H.
subst_local 替换语境中所有局部定义
Ltac subst_local :=
repeat match goal with H:=_ ⊢ _ ⇒ subst H end.
repeat match goal with H:=_ ⊢ _ ⇒ subst H end.
subst_eq E 取等式 x = t,并在目标各处
用 t 替换 x
Ltac subst_eq_base E :=
let H := fresh "TEMP" in lets H: E; subst_hyp H.
Tactic Notation "subst_eq" constr(E) :=
subst_eq_base E.
let H := fresh "TEMP" in lets H: E; subst_hyp H.
Tactic Notation "subst_eq" constr(E) :=
subst_eq_base E.
pi_rewrite E 用新的【归一变量|Unification Variable】
替换类型为 Prop 的 E,
从而不必显式写出 rewrite (proof_irrelevance E E')
就能利用证明无关性。
当 E' 是大表达式时尤其有用。
Ltac pi_rewrite_base E rewrite_tac :=
let E' := fresh "TEMP" in let T := type of E in evar (E':T);
rewrite_tac (@proof_irrelevance _ E E'); subst E'.
Tactic Notation "pi_rewrite" constr(E) :=
pi_rewrite_base E ltac:(fun X ⇒ rewrite X).
Tactic Notation "pi_rewrite" constr(E) "in" hyp(H) :=
pi_rewrite_base E ltac:(fun X ⇒ rewrite X in H).
let E' := fresh "TEMP" in let T := type of E in evar (E':T);
rewrite_tac (@proof_irrelevance _ E E'); subst E'.
Tactic Notation "pi_rewrite" constr(E) :=
pi_rewrite_base E ltac:(fun X ⇒ rewrite X).
Tactic Notation "pi_rewrite" constr(E) "in" hyp(H) :=
pi_rewrite_base E ltac:(fun X ⇒ rewrite X in H).
证明等式
Section FuncEq.
Variables (A1 A2 A3 A4 A5 A6 A7 B : Type).
Lemma args_eq_1 : ∀ (f:A1→B) x1 y1,
x1 = y1 →
f x1 = f y1.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_2 : ∀ (f:A1→A2→B) x1 y1 x2 y2,
x1 = y1 → x2 = y2 →
f x1 x2 = f y1 y2.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_3 : ∀ (f:A1→A2→A3→B) x1 y1 x2 y2 x3 y3,
x1 = y1 → x2 = y2 → x3 = y3 →
f x1 x2 x3 = f y1 y2 y3.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_4 : ∀ (f:A1→A2→A3→A4→B) x1 y1 x2 y2 x3 y3 x4 y4,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 →
f x1 x2 x3 x4 = f y1 y2 y3 y4.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_5 : ∀ (f:A1→A2→A3→A4→A5→B) x1 y1 x2 y2 x3 y3 x4 y4 x5 y5,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 → x5 = y5 →
f x1 x2 x3 x4 x5 = f y1 y2 y3 y4 y5.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_6 : ∀ (f:A1→A2→A3→A4→A5→A6→B) x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 → x5 = y5 → x6 = y6 →
f x1 x2 x3 x4 x5 x6 = f y1 y2 y3 y4 y5 y6.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_7 : ∀ (f:A1→A2→A3→A4→A5→A6→A7→B) x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6 x7 y7,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 → x5 = y5 → x6 = y6 → x7 = y7 →
f x1 x2 x3 x4 x5 x6 x7 = f y1 y2 y3 y4 y5 y6 y7.
Proof using. intros. subst. auto. Qed.
End FuncEq.
Ltac fequal_post :=
try solve [ reflexivity ].
Variables (A1 A2 A3 A4 A5 A6 A7 B : Type).
Lemma args_eq_1 : ∀ (f:A1→B) x1 y1,
x1 = y1 →
f x1 = f y1.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_2 : ∀ (f:A1→A2→B) x1 y1 x2 y2,
x1 = y1 → x2 = y2 →
f x1 x2 = f y1 y2.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_3 : ∀ (f:A1→A2→A3→B) x1 y1 x2 y2 x3 y3,
x1 = y1 → x2 = y2 → x3 = y3 →
f x1 x2 x3 = f y1 y2 y3.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_4 : ∀ (f:A1→A2→A3→A4→B) x1 y1 x2 y2 x3 y3 x4 y4,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 →
f x1 x2 x3 x4 = f y1 y2 y3 y4.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_5 : ∀ (f:A1→A2→A3→A4→A5→B) x1 y1 x2 y2 x3 y3 x4 y4 x5 y5,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 → x5 = y5 →
f x1 x2 x3 x4 x5 = f y1 y2 y3 y4 y5.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_6 : ∀ (f:A1→A2→A3→A4→A5→A6→B) x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 → x5 = y5 → x6 = y6 →
f x1 x2 x3 x4 x5 x6 = f y1 y2 y3 y4 y5 y6.
Proof using. intros. subst. auto. Qed.
Lemma args_eq_7 : ∀ (f:A1→A2→A3→A4→A5→A6→A7→B) x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6 x7 y7,
x1 = y1 → x2 = y2 → x3 = y3 → x4 = y4 → x5 = y5 → x6 = y6 → x7 = y7 →
f x1 x2 x3 x4 x5 x6 x7 = f y1 y2 y3 y4 y5 y6 y7.
Proof using. intros. subst. auto. Qed.
End FuncEq.
Ltac fequal_post :=
try solve [ reflexivity ].
在 LibEqual 中实现的 fequal_support_for_exist
旨在利用证明无关性,
化简形如 exist _ _ = exist _ _ 与
existT _ _ = existT _ _ 的目标。
Ltac fequal_support_for_exist tt :=
fail.
fail.
对 n 元组而言,fequal 与 f_equal 不同,
它强制对与右分量相关联的 (n-1) 元组递归调用。
Ltac fequal_base :=
match goal with
| ⊢ (_,_,_) = (_,_,_) ⇒ apply args_eq_2; [ fequal_base | ]
| ⊢ _ ⇒ first
[ fequal_support_for_exist tt
| apply args_eq_1
| apply args_eq_2
| apply args_eq_3
| apply args_eq_4
| apply args_eq_5
| apply args_eq_6
| apply args_eq_7
| f_equal (* 回退到 Rocq 的 f_equal *) ]
end.
Tactic Notation "fequal" :=
fequal_base; fequal_post.
match goal with
| ⊢ (_,_,_) = (_,_,_) ⇒ apply args_eq_2; [ fequal_base | ]
| ⊢ _ ⇒ first
[ fequal_support_for_exist tt
| apply args_eq_1
| apply args_eq_2
| apply args_eq_3
| apply args_eq_4
| apply args_eq_5
| apply args_eq_6
| apply args_eq_7
| f_equal (* 回退到 Rocq 的 f_equal *) ]
end.
Tactic Notation "fequal" :=
fequal_base; fequal_post.
fequals 与 fequal 相同,
只是它尝试用 reflexivity 与 congruence
(以及证明无关性原理)
解出所有平凡子目标。
fequals 作用于形如 f x1 .. xN = f y1 .. yN 的目标,
并产生若干形如 xi = yi 的子目标。
Ltac fequals_post :=
try solve [ reflexivity | congruence | apply proof_irrelevance ].
Tactic Notation "fequals" :=
fequal; fequals_post.
try solve [ reflexivity | congruence | apply proof_irrelevance ].
Tactic Notation "fequals" :=
fequal; fequals_post.
fequals_rec 递归调用 fequals。
它等价于 repeat (progress fequals)。
Tactic Notation "fequals_rec" :=
repeat (progress fequals).
repeat (progress fequals).
invert keep H as X1 .. XN 与 inversion H as ... 相同,
只有非变量的假设才需要显式命名,
其方式与 introv 只为假设命名相仿。
Tactic Notation "invert" "keep" hyp(H) "as" simple_intropattern(I1) :=
invert keep H; introv I1.
Tactic Notation "invert" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
invert keep H; introv I1 I2.
Tactic Notation "invert" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
invert keep H; introv I1 I2 I3.
invert keep H; introv I1.
Tactic Notation "invert" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
invert keep H; introv I1 I2.
Tactic Notation "invert" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
invert keep H; introv I1 I2 I3.
invert H 与 inversion H 相同,
只是它把所得的全部事实放进目标并清除假设 H。
换言之,它等价于 invert keep H; clear H。
Tactic Notation "invert" hyp(H) :=
invert keep H; clear H.
invert keep H; clear H.
invert H as X1 .. XN 与 invert keep H as X1 .. XN 相同,
但它还清除假设 H。
Tactic Notation "invert_tactic" hyp(H) tactic(tac) :=
let H' := fresh "TEMP" in rename H into H'; tac H'; clear H'.
Tactic Notation "invert" hyp(H) "as" simple_intropattern(I1) :=
invert_tactic H (fun H ⇒ invert keep H as I1).
Tactic Notation "invert" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
invert_tactic H (fun H ⇒ invert keep H as I1 I2).
Tactic Notation "invert" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
invert_tactic H (fun H ⇒ invert keep H as I1 I2 I3).
let H' := fresh "TEMP" in rename H into H'; tac H'; clear H'.
Tactic Notation "invert" hyp(H) "as" simple_intropattern(I1) :=
invert_tactic H (fun H ⇒ invert keep H as I1).
Tactic Notation "invert" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
invert_tactic H (fun H ⇒ invert keep H as I1 I2).
Tactic Notation "invert" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
invert_tactic H (fun H ⇒ invert keep H as I1 I2 I3).
(* --我们不导入 Eqdep,因为它会自动导入恼人的提示
From TLC Require Import Eqdep. *)
Axiom inj_pair2 : (* 事实上可由 LibAxiom.v 中的公理导出 *)
∀ (U : Type) (P : U → Type) (p : U) (x y : P p),
existT P p x = existT P p y → x = y.
(* Proof using. apply Eqdep.EqdepTheory.inj_pair2. Qed. *)
Ltac inverts_tactic H i1 i2 i3 i4 i5 i6 :=
let rec go i1 i2 i3 i4 i5 i6 :=
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| ⊢ (?x = ?y → _) ⇒ let H := fresh "TEMP" in intro H;
first [ subst x | subst y ];
go i1 i2 i3 i4 i5 i6
| ⊢ (existT ?P ?p ?x = existT ?P ?p ?y → _) ⇒
let H := fresh "TEMP" in intro H;
generalize (@inj_pair2 _ P p x y H);
clear H; go i1 i2 i3 i4 i5 i6
| ⊢ (?P → ?Q) ⇒ i1; go i2 i3 i4 i5 i6 ltac:(intro)
| ⊢ (∀ _, _) ⇒ intro; go i1 i2 i3 i4 i5 i6
end in
generalize ltac_mark; invert keep H; go i1 i2 i3 i4 i5 i6;
unfold eq' in ×.
From TLC Require Import Eqdep. *)
Axiom inj_pair2 : (* 事实上可由 LibAxiom.v 中的公理导出 *)
∀ (U : Type) (P : U → Type) (p : U) (x y : P p),
existT P p x = existT P p y → x = y.
(* Proof using. apply Eqdep.EqdepTheory.inj_pair2. Qed. *)
Ltac inverts_tactic H i1 i2 i3 i4 i5 i6 :=
let rec go i1 i2 i3 i4 i5 i6 :=
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| ⊢ (?x = ?y → _) ⇒ let H := fresh "TEMP" in intro H;
first [ subst x | subst y ];
go i1 i2 i3 i4 i5 i6
| ⊢ (existT ?P ?p ?x = existT ?P ?p ?y → _) ⇒
let H := fresh "TEMP" in intro H;
generalize (@inj_pair2 _ P p x y H);
clear H; go i1 i2 i3 i4 i5 i6
| ⊢ (?P → ?Q) ⇒ i1; go i2 i3 i4 i5 i6 ltac:(intro)
| ⊢ (∀ _, _) ⇒ intro; go i1 i2 i3 i4 i5 i6
end in
generalize ltac_mark; invert keep H; go i1 i2 i3 i4 i5 i6;
unfold eq' in ×.
inverts keep H 与 invert keep H 相同,
只是它对反演产生的所有等式应用 subst。
Tactic Notation "inverts" "keep" hyp(H) :=
inverts_tactic H ltac:(intro) ltac:(intro) ltac:(intro)
ltac:(intro) ltac:(intro) ltac:(intro).
inverts_tactic H ltac:(intro) ltac:(intro) ltac:(intro)
ltac:(intro) ltac:(intro) ltac:(intro).
inverts keep H as X1 .. XN 与
invert keep H as X1 .. XN 相同,
只是它对反演产生的所有等式应用 subst
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1) :=
inverts_tactic H ltac:(intros I1)
ltac:(intro) ltac:(intro) ltac:(intro) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2)
ltac:(intro) ltac:(intro) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intro) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intros I4) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intros I4) ltac:(intros I5) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intros I4) ltac:(intros I5) ltac:(intros I6).
inverts_tactic H ltac:(intros I1)
ltac:(intro) ltac:(intro) ltac:(intro) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2)
ltac:(intro) ltac:(intro) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intro) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intros I4) ltac:(intro) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intros I4) ltac:(intros I5) ltac:(intro).
Tactic Notation "inverts" "keep" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) :=
inverts_tactic H ltac:(intros I1) ltac:(intros I2) ltac:(intros I3)
ltac:(intros I4) ltac:(intros I5) ltac:(intros I6).
inverts H 与 inverts keep H 相同,
只是它清除假设 H。
Tactic Notation "inverts" hyp(H) :=
inverts keep H; try clear H.
inverts keep H; try clear H.
inverts H as X1 .. XN 与 inverts keep H as X1 .. XN 相同,
但它还清除假设 H。
Tactic Notation "inverts_tactic" hyp(H) tactic(tac) :=
let H' := fresh "TEMP" in rename H into H'; tac H'; clear H'.
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1) :=
invert_tactic H (fun H ⇒ inverts keep H as I1).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3 I4).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3 I4 I5).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3 I4 I5 I6).
let H' := fresh "TEMP" in rename H into H'; tac H'; clear H'.
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1) :=
invert_tactic H (fun H ⇒ inverts keep H as I1).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3 I4).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3 I4 I5).
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) :=
invert_tactic H (fun H ⇒ inverts keep H as I1 I2 I3 I4 I5 I6).
inverts H as 对假设 H 做反演,替换所产生的等式,
并把其余新创建的假设放进目标,
供用户显式命名。
inverts keep H as 相同,只是不清除 H。
注:也许可用它重新实现上面的 inverts
Ltac inverts_as_tactic H :=
let rec go tt :=
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| ⊢ (?x = ?y → _) ⇒ let H := fresh "TEMP" in intro H;
first [ subst x | subst y ];
go tt
| ⊢ (existT ?P ?p ?x = existT ?P ?p ?y → _) ⇒
let H := fresh "TEMP" in intro H;
generalize (@inj_pair2 _ P p x y H);
clear H; go tt
| ⊢ (∀ _, _) ⇒
intro; let H := get_last_hyp tt in mark_to_generalize H; go tt
end in
pose ltac_mark; inversion H;
generalize ltac_mark; gen_until_mark;
go tt; gen_to_generalize; unfolds ltac_to_generalize;
unfold eq' in ×.
Tactic Notation "inverts" "keep" hyp(H) "as" :=
inverts_as_tactic H.
Tactic Notation "inverts" hyp(H) "as" :=
inverts_as_tactic H; clear H.
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) simple_intropattern(I7) :=
inverts H as; introv I1 I2 I3 I4 I5 I6 I7.
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) simple_intropattern(I7)
simple_intropattern(I8) :=
inverts H as; introv I1 I2 I3 I4 I5 I6 I7 I8.
let rec go tt :=
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| ⊢ (?x = ?y → _) ⇒ let H := fresh "TEMP" in intro H;
first [ subst x | subst y ];
go tt
| ⊢ (existT ?P ?p ?x = existT ?P ?p ?y → _) ⇒
let H := fresh "TEMP" in intro H;
generalize (@inj_pair2 _ P p x y H);
clear H; go tt
| ⊢ (∀ _, _) ⇒
intro; let H := get_last_hyp tt in mark_to_generalize H; go tt
end in
pose ltac_mark; inversion H;
generalize ltac_mark; gen_until_mark;
go tt; gen_to_generalize; unfolds ltac_to_generalize;
unfold eq' in ×.
Tactic Notation "inverts" "keep" hyp(H) "as" :=
inverts_as_tactic H.
Tactic Notation "inverts" hyp(H) "as" :=
inverts_as_tactic H; clear H.
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) simple_intropattern(I7) :=
inverts H as; introv I1 I2 I3 I4 I5 I6 I7.
Tactic Notation "inverts" hyp(H) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4)
simple_intropattern(I5) simple_intropattern(I6) simple_intropattern(I7)
simple_intropattern(I8) :=
inverts H as; introv I1 I2 I3 I4 I5 I6 I7 I8.
lets_inverts E as I1 .. IN 直观上等价于 inverts E,
不同之处是它适用于任何表达式,
而不只是假设的名字。
Ltac lets_inverts_base E cont :=
let H := fresh "TEMP" in lets H: E; try cont H.
Tactic Notation "lets_inverts" constr(E) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1 I2).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1 I2 I3).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1 I2 I3 I4).
let H := fresh "TEMP" in lets H: E; try cont H.
Tactic Notation "lets_inverts" constr(E) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1)
simple_intropattern(I2) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1 I2).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1 I2 I3).
Tactic Notation "lets_inverts" constr(E) "as" simple_intropattern(I1)
simple_intropattern(I2) simple_intropattern(I3) simple_intropattern(I4) :=
lets_inverts_base E ltac:(fun H ⇒ inverts H as I1 I2 I3 I4).
Ltac injects_tactic H :=
let rec go _ :=
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| ⊢ (?x = ?y → _) ⇒ let H := fresh "TEMP" in intro H;
first [ subst x | subst y | idtac ];
go tt
end in
generalize ltac_mark; injection H; go tt.
let rec go _ :=
match goal with
| ⊢ (ltac_Mark → _) ⇒ intros _
| ⊢ (?x = ?y → _) ⇒ let H := fresh "TEMP" in intro H;
first [ subst x | subst y | idtac ];
go tt
end in
generalize ltac_mark; injection H; go tt.
injects keep H 取形如
C a1 .. aN = C b1 .. bN 的假设 H,
并替换所产生的所有等式 ai = bi。
Tactic Notation "injects" "keep" hyp(H) :=
injects_tactic H.
injects_tactic H.
injects H 类似 injects keep H,
但清除假设 H。
Tactic Notation "injects" hyp(H) :=
injects_tactic H; clear H.
injects_tactic H; clear H.
inject H as X1 .. XN 等同于 injection
之后接 intros X1 .. XN
Tactic Notation "inject" hyp(H) :=
injection H.
Tactic Notation "inject" hyp(H) "as" ident(X1) :=
injection H; intros X1.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) :=
injection H; intros X1 X2.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) ident(X3) :=
injection H; intros X1 X2 X3.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) ident(X3)
ident(X4) :=
injection H; intros X1 X2 X3 X4.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) ident(X3)
ident(X4) ident(X5) :=
injection H; intros X1 X2 X3 X4 X5.
injection H.
Tactic Notation "inject" hyp(H) "as" ident(X1) :=
injection H; intros X1.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) :=
injection H; intros X1 X2.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) ident(X3) :=
injection H; intros X1 X2 X3.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) ident(X3)
ident(X4) :=
injection H; intros X1 X2 X3 X4.
Tactic Notation "inject" hyp(H) "as" ident(X1) ident(X2) ident(X3)
ident(X4) ident(X5) :=
injection H; intros X1 X2 X3 X4 X5.
带替换的反演与单射性推理:粗略实现
Tactic Notation "inversions" "keep" hyp(H) :=
inversion H; subst.
inversion H; subst.
inversions H 是 inversion H 之后接 subst
与 clear H 的简写。
它是 inverts keep H 的粗略实现,
当证明语境已含等式时表现不佳。
提供它以防更好的实现太慢。
Tactic Notation "inversions" hyp(H) :=
inversion H; subst; try clear H.
inversion H; subst; try clear H.
injections keep H 等同于 injection H
之后接 intros 与 subst。
它是 injects keep H 的粗略实现,
当证明语境已含等式、
或目标以 forall 或蕴含开头时表现不佳。
Tactic Notation "injections" "keep" hyp(H) :=
injection H; intros; subst.
injection H; intros; subst.
injections H 等同于 injection H
之后接 clear H、intros 与 subst。
它是 injects keep H 的粗略实现,
当证明语境已含等式、
或目标以 forall 或蕴含开头时表现不佳。
Tactic Notation "injections" "keep" hyp(H) :=
injection H; clear H; intros; subst.
injection H; clear H; intros; subst.
Tactic Notation "cases" constr(E) "as" ident(H) :=
let X := fresh "TEMP" in
set (X := E) in *; def_to_eq_sym X H E;
destruct X.
Tactic Notation "cases" constr(E) :=
let H := fresh "Eq" in cases E as H.
let X := fresh "TEMP" in
set (X := E) in *; def_to_eq_sym X H E;
destruct X.
Tactic Notation "cases" constr(E) :=
let H := fresh "Eq" in cases E as H.
case_if_post H 稍后将被定义为
清理假设 H 与目标的策略。
默认情况下它寻找明显的矛盾。
目前该策略在 LibReflect 中被扩展
以清理布尔命题。
Ltac case_if_post H :=
tryfalse.
tryfalse.
case_if 在目标中寻找形如 if ?B then ?E1 else ?E2
的模式,并通过调用 destruct B 对 B 做【分类讨论|Case Analysis】。
含矛盾的子目标被丢弃。
case_if 先在目标中寻找,
否则在第一条含 if 语句的假设中寻找。
case_if in H 可用来指定考虑哪条假设。
语法 case_if as Eq 与 case_if in H as Eq
允许为分类讨论产生的假设命名。
Ltac case_if_on_tactic_core E Eq :=
match type of E with
| {_}+{_} ⇒ destruct E as [Eq | Eq]
| _ ⇒ let X := fresh "TEMP" in
sets_eq <- X Eq: E;
destruct X
end.
Ltac case_if_on_tactic E Eq :=
case_if_on_tactic_core E Eq; case_if_post Eq.
Tactic Notation "case_if_on" constr(E) "as" simple_intropattern(Eq) :=
case_if_on_tactic E Eq.
Tactic Notation "case_if" "as" simple_intropattern(Eq) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ case_if_on B as Eq
| K: context [if ?B then _ else _] ⊢ _ ⇒ case_if_on B as Eq
end.
Tactic Notation "case_if" "in" hyp(H) "as" simple_intropattern(Eq) :=
match type of H with context [if ?B then _ else _] ⇒
case_if_on B as Eq end.
Tactic Notation "case_if" :=
let Eq := fresh "C" in case_if as Eq.
Tactic Notation "case_if" "in" hyp(H) :=
let Eq := fresh "C" in case_if in H as Eq.
match type of E with
| {_}+{_} ⇒ destruct E as [Eq | Eq]
| _ ⇒ let X := fresh "TEMP" in
sets_eq <- X Eq: E;
destruct X
end.
Ltac case_if_on_tactic E Eq :=
case_if_on_tactic_core E Eq; case_if_post Eq.
Tactic Notation "case_if_on" constr(E) "as" simple_intropattern(Eq) :=
case_if_on_tactic E Eq.
Tactic Notation "case_if" "as" simple_intropattern(Eq) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ case_if_on B as Eq
| K: context [if ?B then _ else _] ⊢ _ ⇒ case_if_on B as Eq
end.
Tactic Notation "case_if" "in" hyp(H) "as" simple_intropattern(Eq) :=
match type of H with context [if ?B then _ else _] ⇒
case_if_on B as Eq end.
Tactic Notation "case_if" :=
let Eq := fresh "C" in case_if as Eq.
Tactic Notation "case_if" "in" hyp(H) :=
let Eq := fresh "C" in case_if in H as Eq.
cases_if 类似 case_if,有两点主要区别:
它会产生形如 x = y 的等式,
并随后在目标中替换它
Ltac cases_if_on_tactic_core E Eq :=
match type of E with
| {_}+{_} ⇒ destruct E as [Eq|Eq]; try subst_hyp Eq
| _ ⇒ let X := fresh "TEMP" in
sets_eq <- X Eq: E;
destruct X
end.
Ltac cases_if_on_tactic E Eq :=
cases_if_on_tactic_core E Eq; tryfalse; case_if_post Eq.
Tactic Notation "cases_if_on" constr(E) "as" simple_intropattern(Eq) :=
cases_if_on_tactic E Eq.
Tactic Notation "cases_if" "as" simple_intropattern(Eq) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ cases_if_on B as Eq
| K: context [if ?B then _ else _] ⊢ _ ⇒ cases_if_on B as Eq
end.
Tactic Notation "cases_if" "in" hyp(H) "as" simple_intropattern(Eq) :=
match type of H with context [if ?B then _ else _] ⇒
cases_if_on B as Eq end.
Tactic Notation "cases_if" :=
let Eq := fresh "C" in cases_if as Eq.
Tactic Notation "cases_if" "in" hyp(H) :=
let Eq := fresh "C" in cases_if in H as Eq.
match type of E with
| {_}+{_} ⇒ destruct E as [Eq|Eq]; try subst_hyp Eq
| _ ⇒ let X := fresh "TEMP" in
sets_eq <- X Eq: E;
destruct X
end.
Ltac cases_if_on_tactic E Eq :=
cases_if_on_tactic_core E Eq; tryfalse; case_if_post Eq.
Tactic Notation "cases_if_on" constr(E) "as" simple_intropattern(Eq) :=
cases_if_on_tactic E Eq.
Tactic Notation "cases_if" "as" simple_intropattern(Eq) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ cases_if_on B as Eq
| K: context [if ?B then _ else _] ⊢ _ ⇒ cases_if_on B as Eq
end.
Tactic Notation "cases_if" "in" hyp(H) "as" simple_intropattern(Eq) :=
match type of H with context [if ?B then _ else _] ⇒
cases_if_on B as Eq end.
Tactic Notation "cases_if" :=
let Eq := fresh "C" in cases_if as Eq.
Tactic Notation "cases_if" "in" hyp(H) :=
let Eq := fresh "C" in cases_if in H as Eq.
case_ifs 类似 repeat case_if
Ltac case_ifs_core :=
repeat case_if.
Tactic Notation "case_ifs" :=
case_ifs_core.
repeat case_if.
Tactic Notation "case_ifs" :=
case_ifs_core.
destruct_if 在目标中寻找形如
if ?B then ?E1 else ?E2 的模式,
并通过调用 destruct B 对 B 做分类讨论。
它先在目标中寻找,
否则在第一条含 if 语句的假设中寻找。
Ltac destruct_if_post := tryfalse.
Tactic Notation "destruct_if"
"as" simple_intropattern(Eq1) simple_intropattern(Eq2) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ destruct B as [Eq1|Eq2]
| K: context [if ?B then _ else _] ⊢ _ ⇒ destruct B as [Eq1|Eq2]
end;
destruct_if_post.
Tactic Notation "destruct_if" "in" hyp(H)
"as" simple_intropattern(Eq1) simple_intropattern(Eq2) :=
match type of H with context [if ?B then _ else _] ⇒
destruct B as [Eq1|Eq2] end;
destruct_if_post.
Tactic Notation "destruct_if" "as" simple_intropattern(Eq) :=
destruct_if as Eq Eq.
Tactic Notation "destruct_if" "in" hyp(H) "as" simple_intropattern(Eq) :=
destruct_if in H as Eq Eq.
Tactic Notation "destruct_if" :=
let Eq := fresh "C" in destruct_if as Eq Eq.
Tactic Notation "destruct_if" "in" hyp(H) :=
let Eq := fresh "C" in destruct_if in H as Eq Eq.
Tactic Notation "destruct_if"
"as" simple_intropattern(Eq1) simple_intropattern(Eq2) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ destruct B as [Eq1|Eq2]
| K: context [if ?B then _ else _] ⊢ _ ⇒ destruct B as [Eq1|Eq2]
end;
destruct_if_post.
Tactic Notation "destruct_if" "in" hyp(H)
"as" simple_intropattern(Eq1) simple_intropattern(Eq2) :=
match type of H with context [if ?B then _ else _] ⇒
destruct B as [Eq1|Eq2] end;
destruct_if_post.
Tactic Notation "destruct_if" "as" simple_intropattern(Eq) :=
destruct_if as Eq Eq.
Tactic Notation "destruct_if" "in" hyp(H) "as" simple_intropattern(Eq) :=
destruct_if in H as Eq Eq.
Tactic Notation "destruct_if" :=
let Eq := fresh "C" in destruct_if as Eq Eq.
Tactic Notation "destruct_if" "in" hyp(H) :=
let Eq := fresh "C" in destruct_if in H as Eq Eq.
提供 cases' 是为了与 remember 兼容。
cases' E 类似 case_eq E,
不同之处是它把等式产生在语境而非目标中。
语法 cases' E as H 允许指定该假设的名字 H。
Tactic Notation "cases'" constr(E) "as" ident(H) :=
let X := fresh "TEMP" in
set (X := E) in *; def_to_eq X H E;
destruct X.
Tactic Notation "cases'" constr(E) :=
let x := fresh "Eq" in cases' E as H.
let X := fresh "TEMP" in
set (X := E) in *; def_to_eq X H E;
destruct X.
Tactic Notation "cases'" constr(E) :=
let x := fresh "Eq" in cases' E as H.
cases_if' 类似 cases_if,
只是它产生对称方向的等式。
Ltac cases_if_on' E Eq :=
match type of E with
| {_}+{_} ⇒ destruct E as [Eq|Eq]; try subst_hyp Eq
| _ ⇒ let X := fresh "TEMP" in
sets_eq X Eq: E;
destruct X
end; case_if_post Eq.
Tactic Notation "cases_if'" "as" simple_intropattern(Eq) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ cases_if_on' B Eq
| K: context [if ?B then _ else _] ⊢ _ ⇒ cases_if_on' B Eq
end.
Tactic Notation "cases_if'" :=
let Eq := fresh "C" in cases_if' as Eq.
match type of E with
| {_}+{_} ⇒ destruct E as [Eq|Eq]; try subst_hyp Eq
| _ ⇒ let X := fresh "TEMP" in
sets_eq X Eq: E;
destruct X
end; case_if_post Eq.
Tactic Notation "cases_if'" "as" simple_intropattern(Eq) :=
match goal with
| ⊢ context [if ?B then _ else _] ⇒ cases_if_on' B Eq
| K: context [if ?B then _ else _] ⊢ _ ⇒ cases_if_on' B Eq
end.
Tactic Notation "cases_if'" :=
let Eq := fresh "C" in cases_if' as Eq.
归纳
From Stdlib.Program Require Import Equality.
Ltac inductions_post :=
unfold eq' in ×.
Tactic Notation "inductions" ident(E) :=
dependent induction E; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) :=
dependent induction E generalizing X1; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2) :=
dependent induction E generalizing X1 X2; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) :=
dependent induction E generalizing X1 X2 X3; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) :=
dependent induction E generalizing X1 X2 X3 X4; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) :=
dependent induction E generalizing X1 X2 X3 X4 X5; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) ident(X6) :=
dependent induction E generalizing X1 X2 X3 X4 X5 X6; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) ident(X6) ident(X7) :=
dependent induction E generalizing X1 X2 X3 X4 X5 X6 X7; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) ident(X6) ident(X7) ident(X8) :=
dependent induction E generalizing X1 X2 X3 X4 X5 X6 X7 X8; inductions_post.
Ltac inductions_post :=
unfold eq' in ×.
Tactic Notation "inductions" ident(E) :=
dependent induction E; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) :=
dependent induction E generalizing X1; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2) :=
dependent induction E generalizing X1 X2; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) :=
dependent induction E generalizing X1 X2 X3; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) :=
dependent induction E generalizing X1 X2 X3 X4; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) :=
dependent induction E generalizing X1 X2 X3 X4 X5; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) ident(X6) :=
dependent induction E generalizing X1 X2 X3 X4 X5 X6; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) ident(X6) ident(X7) :=
dependent induction E generalizing X1 X2 X3 X4 X5 X6 X7; inductions_post.
Tactic Notation "inductions" ident(E) "gen" ident(X1) ident(X2)
ident(X3) ident(X4) ident(X5) ident(X6) ident(X7) ident(X8) :=
dependent induction E generalizing X1 X2 X3 X4 X5 X6 X7 X8; inductions_post.
induction_wf IH: E X 用来对给定的良基关系
应用【良基归纳原理|Well-Founded Induction Principle】。
它作用于目标 PX,其中 PX 是关于 X 的命题。
先用 pattern X 把目标整理成
(fun a ⇒ P a) X 的形式,
再应用在 E 上实例化的良基归纳原理。
这里 E 可以是:
- 类型 A→A→Prop 的关系 R 的 wf R 证明
- 类型 A→A→Prop 的二元关系
- 类型 A → nat 的度量 // 仅当使用 LibWf 时。
(* DEPRECATED
Tactic Notation "induction_wf" ident(IH) ":" constr(E) ident(X) :=
pattern X; apply (well_founded_ind E); clear X; intros X IH.
*)
Ltac induction_wf_process_wf_hyp tt := (* 在 LibWf 中精化 *)
idtac.
Ltac induction_wf_process_measure E := (* 在 LibWf 中精化 *)
fail.
Ltac induction_wf_core_then E X cont :=
let clearX tt :=
first [ clear X | fail 3 "the variable on which the induction is done appears in the hypotheses" ] in
pattern X;
first [ eapply (@well_founded_ind _ E)
| eapply (@well_founded_ind _ (E _))
| eapply (@well_founded_ind _ (E _ _))
| eapply (@well_founded_ind _ (E _ _ _))
| induction_wf_process_measure E
| applys well_founded_ind E ];
clearX tt;
first [ induction_wf_process_wf_hyp tt
| intros X; cont tt ].
Ltac induction_wf_core IH E X :=
induction_wf_core_then E X ltac:(fun _ ⇒ intros IH).
Tactic Notation "induction_wf" ident(IH) ":" constr(E) ident(X) :=
induction_wf_core IH E X.
Tactic Notation "induction_wf" ident(IH) ":" constr(E) ident(X) :=
pattern X; apply (well_founded_ind E); clear X; intros X IH.
*)
Ltac induction_wf_process_wf_hyp tt := (* 在 LibWf 中精化 *)
idtac.
Ltac induction_wf_process_measure E := (* 在 LibWf 中精化 *)
fail.
Ltac induction_wf_core_then E X cont :=
let clearX tt :=
first [ clear X | fail 3 "the variable on which the induction is done appears in the hypotheses" ] in
pattern X;
first [ eapply (@well_founded_ind _ E)
| eapply (@well_founded_ind _ (E _))
| eapply (@well_founded_ind _ (E _ _))
| eapply (@well_founded_ind _ (E _ _ _))
| induction_wf_process_measure E
| applys well_founded_ind E ];
clearX tt;
first [ induction_wf_process_wf_hyp tt
| intros X; cont tt ].
Ltac induction_wf_core IH E X :=
induction_wf_core_then E X ltac:(fun _ ⇒ intros IH).
Tactic Notation "induction_wf" ident(IH) ":" constr(E) ident(X) :=
induction_wf_core IH E X.
对导出式高度的归纳:辅助策略 induct_height
有助于证明带最大高度计数器的辅助判断的等价性
(示例见 LibTacticsDemos)
From Stdlib Require Import Compare_dec.
From Stdlib Require Import Lia.
Lemma induct_height_max2 : ∀ n1 n2 : nat,
∃ n, n1 < n ∧ n2 < n.
Proof using.
intros. destruct (lt_dec n1 n2).
∃ (S n2). lia.
∃ (S n1). lia.
Qed.
Ltac induct_height_step x :=
match goal with
| H: ∃ _, _ ⊢ _ ⇒
let n := fresh "n" in let y := fresh "x" in
destruct H as [n ?];
forwards (y&?&?): induct_height_max2 n x;
induct_height_step y
| _ ⇒ ∃ (S x); eauto
end.
Ltac induct_height := induct_height_step O.
From Stdlib Require Import Lia.
Lemma induct_height_max2 : ∀ n1 n2 : nat,
∃ n, n1 < n ∧ n2 < n.
Proof using.
intros. destruct (lt_dec n1 n2).
∃ (S n2). lia.
∃ (S n1). lia.
Qed.
Ltac induct_height_step x :=
match goal with
| H: ∃ _, _ ⊢ _ ⇒
let n := fresh "n" in let y := fresh "x" in
destruct H as [n ?];
forwards (y&?&?): induct_height_max2 n x;
induct_height_step y
| _ ⇒ ∃ (S x); eauto
end.
Ltac induct_height := induct_height_step O.
余归纳
Definition COIND (P:Prop) := P.
Tactic Notation "cofixs" ident(IH) :=
cofix IH;
match type of IH with ?P ⇒ change P with (COIND P) in IH end.
Tactic Notation "cofixs" ident(IH) :=
cofix IH;
match type of IH with ?P ⇒ change P with (COIND P) in IH end.
策略 clear_coind 清除所有余归纳假设,
前提是它们已被标记
策略 abstracts tac 类似 abstract tac,
不同之处是它清除余归纳假设,
使生产性检查得以通过。
例如,可用 abstracts lia
获得与 lia 相同的行为,
同时生成一条辅助引理。
Tactic Notation "abstracts" tactic(tac) :=
clear_coind; tac.
clear_coind; tac.
Ltac decides_equality_tactic :=
first [ decide equality | progress(unfolds); decides_equality_tactic ].
Tactic Notation "decides_equality" :=
decides_equality_tactic.
first [ decide equality | progress(unfolds); decides_equality_tactic ].
Tactic Notation "decides_equality" :=
decides_equality_tactic.
等价
Lemma iff_intro_swap : ∀ (P Q : Prop),
(Q → P) → (P → Q) → (P ↔ Q).
Proof using. intuition. Qed.
Tactic Notation "iff" simple_intropattern(H1) simple_intropattern(H2) :=
split; [ intros H1 | intros H2 ].
Tactic Notation "iff" simple_intropattern(H) :=
iff H H.
Tactic Notation "iff" :=
let H := fresh "H" in iff H.
Tactic Notation "iff" "<-" simple_intropattern(H1) simple_intropattern(H2) :=
apply iff_intro_swap; [ intros H1 | intros H2 ].
Tactic Notation "iff" "<-" simple_intropattern(H) :=
iff <- H H.
Tactic Notation "iff" "<-" :=
let H := fresh "H" in iff <- H.
(Q → P) → (P → Q) → (P ↔ Q).
Proof using. intuition. Qed.
Tactic Notation "iff" simple_intropattern(H1) simple_intropattern(H2) :=
split; [ intros H1 | intros H2 ].
Tactic Notation "iff" simple_intropattern(H) :=
iff H H.
Tactic Notation "iff" :=
let H := fresh "H" in iff H.
Tactic Notation "iff" "<-" simple_intropattern(H1) simple_intropattern(H2) :=
apply iff_intro_swap; [ intros H1 | intros H2 ].
Tactic Notation "iff" "<-" simple_intropattern(H) :=
iff <- H H.
Tactic Notation "iff" "<-" :=
let H := fresh "H" in iff <- H.
目标中 n 元合取的拆分
splits 的底层实现
Ltac splits_tactic N :=
match N with
| O ⇒ fail
| S O ⇒ idtac
| S ?N' ⇒ split; [| splits_tactic N']
end.
Ltac unfold_goal_until_conjunction :=
match goal with
| ⊢ _ ∧ _ ⇒ idtac
| _ ⇒ progress(unfolds); unfold_goal_until_conjunction
end.
Ltac get_term_conjunction_arity T :=
match T with
| _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(8)
| _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(7)
| _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(6)
| _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(5)
| _ ∧ _ ∧ _ ∧ _ ⇒ constr:(4)
| _ ∧ _ ∧ _ ⇒ constr:(3)
| _ ∧ _ ⇒ constr:(2)
| _ → ?T' ⇒ get_term_conjunction_arity T'
| _ ⇒ let P := get_head T in
let T' := eval unfold P in T in
match T' with
| T ⇒ fail 1
| _ ⇒ get_term_conjunction_arity T'
end
(* --待办:警告,这可能循环……*)
end.
Ltac get_goal_conjunction_arity :=
match goal with ⊢ ?T ⇒ get_term_conjunction_arity T end.
match N with
| O ⇒ fail
| S O ⇒ idtac
| S ?N' ⇒ split; [| splits_tactic N']
end.
Ltac unfold_goal_until_conjunction :=
match goal with
| ⊢ _ ∧ _ ⇒ idtac
| _ ⇒ progress(unfolds); unfold_goal_until_conjunction
end.
Ltac get_term_conjunction_arity T :=
match T with
| _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(8)
| _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(7)
| _ ∧ _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(6)
| _ ∧ _ ∧ _ ∧ _ ∧ _ ⇒ constr:(5)
| _ ∧ _ ∧ _ ∧ _ ⇒ constr:(4)
| _ ∧ _ ∧ _ ⇒ constr:(3)
| _ ∧ _ ⇒ constr:(2)
| _ → ?T' ⇒ get_term_conjunction_arity T'
| _ ⇒ let P := get_head T in
let T' := eval unfold P in T in
match T' with
| T ⇒ fail 1
| _ ⇒ get_term_conjunction_arity T'
end
(* --待办:警告,这可能循环……*)
end.
Ltac get_goal_conjunction_arity :=
match goal with ⊢ ?T ⇒ get_term_conjunction_arity T end.
splits 作用于形如 (T1 ∧ .. ∧ TN) 的目标,
把它解构为 N 个子目标 T1 .. TN。
若目标不是合取,则展开头部定义。
Tactic Notation "splits" :=
unfold_goal_until_conjunction;
let N := get_goal_conjunction_arity in
splits_tactic N.
unfold_goal_until_conjunction;
let N := get_goal_conjunction_arity in
splits_tactic N.
splits N 类似 splits,
只是它会为得到 n 元合取
展开尽可能多的必要定义。
Tactic Notation "splits" constr(N) :=
let N := number_to_nat N in
splits_tactic N.
let N := number_to_nat N in
splits_tactic N.
n 元合取的解构
destructs 的底层实现
Ltac destructs_conjunction_tactic N T :=
match N with
| 2 ⇒ destruct T as [? ?]
| 3 ⇒ destruct T as [? [? ?]]
| 4 ⇒ destruct T as [? [? [? ?]]]
| 5 ⇒ destruct T as [? [? [? [? ?]]]]
| 6 ⇒ destruct T as [? [? [? [? [? ?]]]]]
| 7 ⇒ destruct T as [? [? [? [? [? [? ?]]]]]]
end.
match N with
| 2 ⇒ destruct T as [? ?]
| 3 ⇒ destruct T as [? [? ?]]
| 4 ⇒ destruct T as [? [? [? ?]]]
| 5 ⇒ destruct T as [? [? [? [? ?]]]]
| 6 ⇒ destruct T as [? [? [? [? [? ?]]]]]
| 7 ⇒ destruct T as [? [? [? [? [? [? ?]]]]]]
end.
destructs T 允许解构作为 n 元合取的项 T。
它等价于 destruct T as (H1 .. HN),
只是无需手动指定 N 个不同的名字。
Tactic Notation "destructs" constr(T) :=
let TT := type of T in
let N := get_term_conjunction_arity TT in
destructs_conjunction_tactic N T.
let TT := type of T in
let N := get_term_conjunction_arity TT in
destructs_conjunction_tactic N T.
destructs N T 等价于 destruct T as (H1 .. HN),
只是无需手动指定 N 个不同的名字。
注意它并不限于 n 元合取。
Tactic Notation "destructs" constr(N) constr(T) :=
let N := number_to_nat N in
destructs_conjunction_tactic N T.
let N := number_to_nat N in
destructs_conjunction_tactic N T.
证明 n 元析取目标
branch 的底层实现
Ltac branch_tactic K N :=
match constr:((K,N)) with
| (_,0) ⇒ fail 1
| (0,_) ⇒ fail 1
| (1,1) ⇒ idtac
| (1,_) ⇒ left
| (S ?K', S ?N') ⇒ right; branch_tactic K' N'
end.
Ltac unfold_goal_until_disjunction :=
match goal with
| ⊢ _ ∨ _ ⇒ idtac
| _ ⇒ progress(unfolds); unfold_goal_until_disjunction
end.
Ltac get_term_disjunction_arity T :=
match T with
| _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(8)
| _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(7)
| _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(6)
| _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(5)
| _ ∨ _ ∨ _ ∨ _ ⇒ constr:(4)
| _ ∨ _ ∨ _ ⇒ constr:(3)
| _ ∨ _ ⇒ constr:(2)
| _ → ?T' ⇒ get_term_disjunction_arity T'
| _ ⇒ let P := get_head T in
let T' := eval unfold P in T in
match T' with
| T ⇒ fail 1
| _ ⇒ get_term_disjunction_arity T'
end
end.
Ltac get_goal_disjunction_arity :=
match goal with ⊢ ?T ⇒ get_term_disjunction_arity T end.
match constr:((K,N)) with
| (_,0) ⇒ fail 1
| (0,_) ⇒ fail 1
| (1,1) ⇒ idtac
| (1,_) ⇒ left
| (S ?K', S ?N') ⇒ right; branch_tactic K' N'
end.
Ltac unfold_goal_until_disjunction :=
match goal with
| ⊢ _ ∨ _ ⇒ idtac
| _ ⇒ progress(unfolds); unfold_goal_until_disjunction
end.
Ltac get_term_disjunction_arity T :=
match T with
| _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(8)
| _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(7)
| _ ∨ _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(6)
| _ ∨ _ ∨ _ ∨ _ ∨ _ ⇒ constr:(5)
| _ ∨ _ ∨ _ ∨ _ ⇒ constr:(4)
| _ ∨ _ ∨ _ ⇒ constr:(3)
| _ ∨ _ ⇒ constr:(2)
| _ → ?T' ⇒ get_term_disjunction_arity T'
| _ ⇒ let P := get_head T in
let T' := eval unfold P in T in
match T' with
| T ⇒ fail 1
| _ ⇒ get_term_disjunction_arity T'
end
end.
Ltac get_goal_disjunction_arity :=
match goal with ⊢ ?T ⇒ get_term_disjunction_arity T end.
branch N 作用于形如
P1 ∨ ... ∨ PK ∨ ... ∨ PN 的目标,
留下目标 PK。
它只能展开头部定义(若有的话),
要做更复杂的展开应使用策略 branch K of N。
Tactic Notation "branch" constr(K) :=
let K := number_to_nat K in
unfold_goal_until_disjunction;
let N := get_goal_disjunction_arity in
branch_tactic K N.
let K := number_to_nat K in
unfold_goal_until_disjunction;
let N := get_goal_disjunction_arity in
branch_tactic K N.
branch K of N 类似 branch K,
只是析取的元数 N 由手动给出,
因此该版本的策略能够展开定义。
换言之,它作用于形如
P1 ∨ ... ∨ PK ∨ ... ∨ PN 的目标,
留下目标 PK。
Tactic Notation "branch" constr(K) "of" constr(N) :=
let N := number_to_nat N in
let K := number_to_nat K in
branch_tactic K N.
let N := number_to_nat N in
let K := number_to_nat K in
branch_tactic K N.
n 元析取的解构
branches 的底层实现
Ltac destructs_disjunction_tactic N T :=
match N with
| 2 ⇒ destruct T as [? | ?]
| 3 ⇒ destruct T as [? | [? | ?]]
| 4 ⇒ destruct T as [? | [? | [? | ?]]]
| 5 ⇒ destruct T as [? | [? | [? | [? | ?]]]]
end.
match N with
| 2 ⇒ destruct T as [? | ?]
| 3 ⇒ destruct T as [? | [? | ?]]
| 4 ⇒ destruct T as [? | [? | [? | ?]]]
| 5 ⇒ destruct T as [? | [? | [? | [? | ?]]]]
end.
branches T 允许解构作为 n 元析取的项 T。
它等价于 destruct T as [ H1 | .. | HN ] ,
并产生与 N 种可能情形对应的 N 个子目标。
Tactic Notation "branches" constr(T) :=
let TT := type of T in
let N := get_term_disjunction_arity TT in
destructs_disjunction_tactic N T.
let TT := type of T in
let N := get_term_disjunction_arity TT in
destructs_disjunction_tactic N T.
branches N T 与 branches T 相同,
只是元数被强制为 N。
该版本便于随手展开定义。
Tactic Notation "branches" constr(N) constr(T) :=
let N := number_to_nat N in
destructs_disjunction_tactic N T.
let N := number_to_nat N in
destructs_disjunction_tactic N T.
branches 自动找到一条为析取的假设 h 并解构它。
n 元存在量化
∃ T1 ... TN 是 ∃ T1; ...; ∃ TN 的简写。
它用于证明形如 exist X1 .. XN, P 的目标。
若所给实参是 __(双下划线),则引入一个 evar。
∃ T1 .. TN ___ 等价于
带尽可能多 __ 的 ∃ T1 .. TN __ __ __。
Tactic Notation "exists_original" constr(T1) :=
∃ T1.
Tactic Notation "exists" constr(T1) :=
match T1 with
| ltac_wild ⇒ esplit
| ltac_wilds ⇒ repeat esplit
| _ ⇒ ∃ T1
end.
Tactic Notation "exists" constr(T1) constr(T2) :=
∃ T1; ∃ T2.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) :=
∃ T1; ∃ T2; ∃ T3.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) constr(T4) :=
∃ T1; ∃ T2; ∃ T3; ∃ T4.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) :=
∃ T1; ∃ T2; ∃ T3; ∃ T4; ∃ T5.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) constr(T6) :=
∃ T1; ∃ T2; ∃ T3; ∃ T4; ∃ T5; ∃ T6.
∃ T1.
Tactic Notation "exists" constr(T1) :=
match T1 with
| ltac_wild ⇒ esplit
| ltac_wilds ⇒ repeat esplit
| _ ⇒ ∃ T1
end.
Tactic Notation "exists" constr(T1) constr(T2) :=
∃ T1; ∃ T2.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) :=
∃ T1; ∃ T2; ∃ T3.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) constr(T4) :=
∃ T1; ∃ T2; ∃ T3; ∃ T4.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) :=
∃ T1; ∃ T2; ∃ T3; ∃ T4; ∃ T5.
Tactic Notation "exists" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) constr(T6) :=
∃ T1; ∃ T2; ∃ T3; ∃ T4; ∃ T5; ∃ T6.
为与 Rocq 语法兼容,也提供 ∃ T1, .., TN。
Tactic Notation "exists" constr(T1) "," constr(T2) :=
∃ T1 T2.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) :=
∃ T1 T2 T3.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) "," constr(T4) :=
∃ T1 T2 T3 T4.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) "," constr(T4) ","
constr(T5) :=
∃ T1 T2 T3 T4 T5.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) "," constr(T4) ","
constr(T5) "," constr(T6) :=
∃ T1 T2 T3 T4 T5 T6.
∃ T1 T2.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) :=
∃ T1 T2 T3.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) "," constr(T4) :=
∃ T1 T2 T3 T4.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) "," constr(T4) ","
constr(T5) :=
∃ T1 T2 T3 T4 T5.
Tactic Notation "exists" constr(T1) "," constr(T2) "," constr(T3) "," constr(T4) ","
constr(T5) "," constr(T6) :=
∃ T1 T2 T3 T4 T5 T6.
不带实参的策略 ∃
会按目标头部可见的存在量化个数
重复执行 esplit。
若可见存在量化为零,则调用一次 hnf。
若此时可见存在量化仍为零,则策略失败。
要得到支持任意个存在量化
(包括零个)的策略,请用 try ∃。
Ltac exists_noarg_positive tt :=
match goal with
| ⊢ ∃ _, _ ⇒ esplit; try exists_noarg_positive tt
end.
Ltac exists_noarg tt :=
match goal with
| ⊢ ∃ _, _ ⇒ exists_noarg_positive tt
| _ ⇒ hnf; exists_noarg_positive tt
end.
Tactic Notation "exists" :=
exists_noarg tt.
Definition def_with_exists (n:nat) : Prop :=
∃ x, x = n.
match goal with
| ⊢ ∃ _, _ ⇒ esplit; try exists_noarg_positive tt
end.
Ltac exists_noarg tt :=
match goal with
| ⊢ ∃ _, _ ⇒ exists_noarg_positive tt
| _ ⇒ hnf; exists_noarg_positive tt
end.
Tactic Notation "exists" :=
exists_noarg tt.
Definition def_with_exists (n:nat) : Prop :=
∃ x, x = n.
策略 exists_nounfold 类似 ∃,
只是若目标中没有可见的存在量化则什么也不做。
该策略对以稳健方式编写其他策略可能有用。
Tactic Notation "exists_nounfold" :=
try exists_noarg_positive tt.
try exists_noarg_positive tt.
假设中的存在量化与合取
unpack 或 unpack H 解构全部或单条假设中的
合取与存在量化。
Ltac unpack_core :=
repeat match goal with
| H: _ ∧ _ ⊢ _ ⇒ destruct H
| H: ∃ (varname: _), _ ⊢ _ ⇒
(* 为保留量化变量名字而作的权宜处理 *)
let name := fresh varname in
destruct H as [name ?]
end.
Ltac unpack_hypothesis H :=
try match type of H with
| _ ∧ _ ⇒
let h1 := fresh "TEMP" in
let h2 := fresh "TEMP" in
destruct H as [ h1 h2 ];
unpack_hypothesis h1;
unpack_hypothesis h2
| ∃ (varname: _), _ ⇒
(* 为保留量化变量名字而作的权宜处理 *)
let name := fresh varname in
let body := fresh "TEMP" in
destruct H as [name body];
unpack_hypothesis body
end.
Tactic Notation "unpack" :=
unpack_core.
Tactic Notation "unpack" constr(H) :=
unpack_hypothesis H.
repeat match goal with
| H: _ ∧ _ ⊢ _ ⇒ destruct H
| H: ∃ (varname: _), _ ⊢ _ ⇒
(* 为保留量化变量名字而作的权宜处理 *)
let name := fresh varname in
destruct H as [name ?]
end.
Ltac unpack_hypothesis H :=
try match type of H with
| _ ∧ _ ⇒
let h1 := fresh "TEMP" in
let h2 := fresh "TEMP" in
destruct H as [ h1 h2 ];
unpack_hypothesis h1;
unpack_hypothesis h2
| ∃ (varname: _), _ ⇒
(* 为保留量化变量名字而作的权宜处理 *)
let name := fresh varname in
let body := fresh "TEMP" in
destruct H as [name body];
unpack_hypothesis body
end.
Tactic Notation "unpack" :=
unpack_core.
Tactic Notation "unpack" constr(H) :=
unpack_hypothesis H.
Tactic Notation "typeclass" :=
let go _ := eauto with typeclass_instances in
solve [ go tt | constructor; go tt ].
let go _ := eauto with typeclass_instances in
solve [ go tt | constructor; go tt ].
solve_typeclass 是 typeclass 的简化版本,
供解决实例的提示策略使用
Tactic Notation "solve_typeclass" :=
solve [ eauto with typeclass_instances ].
solve [ eauto with typeclass_instances ].
Tactic Notation "f_equal" :=
f_equal.
Tactic Notation "constructor" :=
constructor.
Tactic Notation "simple" :=
simpl.
Tactic Notation "split" :=
split.
Tactic Notation "right" :=
right.
Tactic Notation "left" :=
left.
f_equal.
Tactic Notation "constructor" :=
constructor.
Tactic Notation "simple" :=
simpl.
Tactic Notation "split" :=
split.
Tactic Notation "right" :=
right.
Tactic Notation "left" :=
left.
Tactic Notation "hint" constr(E) :=
let H := fresh "Hint" in lets H: E.
Tactic Notation "hint" constr(E1) "," constr(E2) :=
hint E1; hint E2.
Tactic Notation "hint" constr(E1) "," constr(E2) "," constr(E3) :=
hint E1; hint E2; hint(E3).
Tactic Notation "hint" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) :=
hint E1; hint E2; hint(E3); hint(E4 ).
let H := fresh "Hint" in lets H: E.
Tactic Notation "hint" constr(E1) "," constr(E2) :=
hint E1; hint E2.
Tactic Notation "hint" constr(E1) "," constr(E2) "," constr(E3) :=
hint E1; hint E2; hint(E3).
Tactic Notation "hint" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) :=
hint E1; hint E2; hint(E3); hint(E4 ).
新自动化策略 jauto
- 打开语境中所有存在量化与合取
- 对目标中的存在量化与合取调用 esplit 与 split
- 调用 eauto。
Tactic Notation "jauto" :=
try solve [ jauto_set; eauto ].
Tactic Notation "jauto_fast" :=
try solve [ auto | eauto | jauto ].
try solve [ jauto_set; eauto ].
Tactic Notation "jauto_fast" :=
try solve [ auto | eauto | jauto ].
iauto 是 intuition eauto 的简写
Tactic Notation "iauto" := try solve [intuition eauto].
自动化策略的定义
Ltac auto_tilde_default := auto.
Ltac auto_tilde := auto_tilde_default.
Ltac auto_tilde := auto_tilde_default.
auto_star 是每当策略后使用符号 ×
时被调用的策略。
Ltac auto_star_default := try solve [ auto | eauto | intuition eauto ].
(* --待办:应为 jauto *)
Ltac auto_star := try solve [ jauto ]. (* 《软件基础》专用版本 *)
(* --待办:应为 jauto *)
Ltac auto_star := try solve [ jauto ]. (* 《软件基础》专用版本 *)
autos¬ 是策略 auto_tilde 的记法。
其后可跟引理(或证明项),
auto 将能用它们来解出目标。 autos 是 autos¬ 的别名
Tactic Notation "autos" :=
auto_tilde.
Tactic Notation "autos" "~" :=
auto_tilde.
Tactic Notation "autos" "~" constr(E1) :=
lets: E1; auto_tilde.
Tactic Notation "autos" "~" constr(E1) constr(E2) :=
lets: E1; autos¬E2.
Tactic Notation "autos" "~" constr(E1) constr(E2) constr(E3) :=
lets: E1; autos¬E2 E3.
Tactic Notation "autos" "~" constr(E1) constr(E2) constr(E3) constr(E4) :=
lets: E1; autos¬E2 E3 E4.
Tactic Notation "autos" "~" constr(E1) constr(E2) constr(E3) constr(E4)
constr(E5):=
lets: E1; autos¬E2 E3 E4 E5.
(* 使用逗号的新语法 *)
Tactic Notation "autos" :=
auto_tilde.
Tactic Notation "autos" "~" :=
auto_tilde.
Tactic Notation "autos" "~" constr(E1) :=
lets: E1; auto_tilde.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) :=
lets: E1; autos¬E2.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) "," constr(E3) :=
lets: E1; autos¬E2 E3.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) :=
lets: E1; autos¬E2 E3 E4.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) ","
constr(E5):=
lets: E1; autos¬E2 E3 E4 E5.
auto_tilde.
Tactic Notation "autos" "~" :=
auto_tilde.
Tactic Notation "autos" "~" constr(E1) :=
lets: E1; auto_tilde.
Tactic Notation "autos" "~" constr(E1) constr(E2) :=
lets: E1; autos¬E2.
Tactic Notation "autos" "~" constr(E1) constr(E2) constr(E3) :=
lets: E1; autos¬E2 E3.
Tactic Notation "autos" "~" constr(E1) constr(E2) constr(E3) constr(E4) :=
lets: E1; autos¬E2 E3 E4.
Tactic Notation "autos" "~" constr(E1) constr(E2) constr(E3) constr(E4)
constr(E5):=
lets: E1; autos¬E2 E3 E4 E5.
(* 使用逗号的新语法 *)
Tactic Notation "autos" :=
auto_tilde.
Tactic Notation "autos" "~" :=
auto_tilde.
Tactic Notation "autos" "~" constr(E1) :=
lets: E1; auto_tilde.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) :=
lets: E1; autos¬E2.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) "," constr(E3) :=
lets: E1; autos¬E2 E3.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) :=
lets: E1; autos¬E2 E3 E4.
Tactic Notation "autos" "~" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) ","
constr(E5):=
lets: E1; autos¬E2 E3 E4 E5.
autos× 是策略 auto_star 的记法。
其后可跟引理(或证明项),
auto 将能用它们来解出目标。
Tactic Notation "autos" "*" :=
auto_star.
Tactic Notation "autos" "*" constr(E1) :=
lets: E1; auto_star.
Tactic Notation "autos" "*" constr(E1) constr(E2) :=
lets: E1; autos× E2.
Tactic Notation "autos" "*" constr(E1) constr(E2) constr(E3) :=
lets: E1; autos× E2 E3.
Tactic Notation "autos" "*" constr(E1) constr(E2) constr(E3) constr(E4) :=
lets: E1; autos× E2 E3 E4.
Tactic Notation "autos" "*" constr(E1) constr(E2) constr(E3) constr(E4)
constr(E5):=
lets: E1; autos× E2 E3 E4 E5.
(* 使用逗号的新语法 *)
Tactic Notation "autos" "*" :=
auto_star.
Tactic Notation "autos" "*" constr(E1) :=
lets: E1; auto_star.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) :=
lets: E1; autos× E2.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) "," constr(E3) :=
lets: E1; autos× E2 E3.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) :=
lets: E1; autos× E2 E3 E4.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) ","
constr(E5):=
lets: E1; autos× E2 E3 E4 E5.
auto_star.
Tactic Notation "autos" "*" constr(E1) :=
lets: E1; auto_star.
Tactic Notation "autos" "*" constr(E1) constr(E2) :=
lets: E1; autos× E2.
Tactic Notation "autos" "*" constr(E1) constr(E2) constr(E3) :=
lets: E1; autos× E2 E3.
Tactic Notation "autos" "*" constr(E1) constr(E2) constr(E3) constr(E4) :=
lets: E1; autos× E2 E3 E4.
Tactic Notation "autos" "*" constr(E1) constr(E2) constr(E3) constr(E4)
constr(E5):=
lets: E1; autos× E2 E3 E4 E5.
(* 使用逗号的新语法 *)
Tactic Notation "autos" "*" :=
auto_star.
Tactic Notation "autos" "*" constr(E1) :=
lets: E1; auto_star.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) :=
lets: E1; autos× E2.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) "," constr(E3) :=
lets: E1; autos× E2 E3.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) :=
lets: E1; autos× E2 E3 E4.
Tactic Notation "autos" "*" constr(E1) "," constr(E2) "," constr(E3) "," constr(E4) ","
constr(E5):=
lets: E1; autos× E2 E3 E4 E5.
auto_false 是能发现某些矛盾的 auto 版本。
对 ↔ 目标有特设支持:先调用 split。
auto_false¬ 与 auto_false× 也可用。
Ltac auto_false_base cont :=
try solve [
intros_all; try match goal with ⊢ _ ↔ _ ⇒ split end;
solve [ cont tt | intros_all; false; cont tt ] ].
Tactic Notation "auto_false" :=
auto_false_base ltac:(fun tt ⇒ auto).
Tactic Notation "auto_false" "~" :=
auto_false_base ltac:(fun tt ⇒ auto_tilde).
Tactic Notation "auto_false" "*" :=
auto_false_base ltac:(fun tt ⇒ auto_star).
Tactic Notation "dauto" :=
dintuition eauto.
try solve [
intros_all; try match goal with ⊢ _ ↔ _ ⇒ split end;
solve [ cont tt | intros_all; false; cont tt ] ].
Tactic Notation "auto_false" :=
auto_false_base ltac:(fun tt ⇒ auto).
Tactic Notation "auto_false" "~" :=
auto_false_base ltac:(fun tt ⇒ auto_tilde).
Tactic Notation "auto_false" "*" :=
auto_false_base ltac:(fun tt ⇒ auto_star).
Tactic Notation "dauto" :=
dintuition eauto.
轻量自动化的解析
- cuts 与 asserts 只对第一个子目标调用 auto,
- apply¬ 依赖 sapply 而非 apply,
- tryfalse¬ 被定义为 tryfalse by auto_tilde。
Tactic Notation "equates" "~" constr(E) :=
equates E; auto_tilde.
Tactic Notation "equates" "~" constr(n1) constr(n2) :=
equates n1 n2; auto_tilde.
Tactic Notation "equates" "~" constr(n1) constr(n2) constr(n3) :=
equates n1 n2 n3; auto_tilde.
Tactic Notation "equates" "~" constr(n1) constr(n2) constr(n3) constr(n4) :=
equates n1 n2 n3 n4; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) :=
applys_eq H; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(E) :=
applys_eq H E; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(n1) constr(n2) :=
applys_eq H n1 n2; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(n1) constr(n2) constr(n3) :=
applys_eq H n1 n2 n3; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(n1) constr(n2) constr(n3) constr(n4) :=
applys_eq H n1 n2 n3 n4; auto_tilde.
Tactic Notation "apply" "~" constr(H) :=
sapply H; auto_tilde.
Tactic Notation "destruct" "~" constr(H) :=
destruct H; auto_tilde.
Tactic Notation "destruct" "~" constr(H) "as" simple_intropattern(I) :=
destruct H as I; auto_tilde.
Tactic Notation "f_equal" "~" :=
f_equal; auto_tilde.
Tactic Notation "induction" "~" constr(H) :=
induction H; auto_tilde.
Tactic Notation "inversion" "~" constr(H) :=
inversion H; auto_tilde.
Tactic Notation "split" "~" :=
split; auto_tilde.
Tactic Notation "subst" "~" :=
subst; auto_tilde.
Tactic Notation "right" "~" :=
right; auto_tilde.
Tactic Notation "left" "~" :=
left; auto_tilde.
Tactic Notation "constructor" "~" :=
constructor; auto_tilde.
Tactic Notation "constructors" "~" :=
constructors; auto_tilde.
Tactic Notation "false" "~" :=
false; auto_tilde.
Tactic Notation "false" "~" constr(E) :=
false_then E ltac:(fun _ ⇒ auto_tilde).
Tactic Notation "false" "~" constr(E0) constr(E1) :=
false¬(>> E0 E1).
Tactic Notation "false" "~" constr(E0) constr(E1) constr(E2) :=
false¬(>> E0 E1 E2).
Tactic Notation "false" "~" constr(E0) constr(E1) constr(E2) constr(E3) :=
false¬(>> E0 E1 E2 E3).
Tactic Notation "false" "~" constr(E0) constr(E1) constr(E2) constr(E3) constr(E4) :=
false¬(>> E0 E1 E2 E3 E4).
Tactic Notation "tryfalse" "~" :=
try solve [ false¬].
Tactic Notation "asserts" "~" simple_intropattern(H) ":" constr(E) :=
asserts H: E; [ auto_tilde | idtac ].
Tactic Notation "asserts" "~" ":" constr(E) :=
let H := fresh "H" in asserts¬H: E.
Tactic Notation "cuts" "~" simple_intropattern(H) ":" constr(E) :=
cuts H: E; [ auto_tilde | idtac ].
Tactic Notation "cuts" "~" ":" constr(E) :=
cuts: E; [ auto_tilde | idtac ].
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E) :=
lets I: E; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
lets I: E0 A1; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
lets I: E0 A1 A2; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets I: E0 A1 A2 A3; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets I: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets I: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E) :=
lets: E; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) :=
lets: E0 A1; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) :=
lets: E0 A1 A2; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets: E0 A1 A2 A3; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E) :=
forwards I: E; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
forwards I: E0 A1; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
forwards I: E0 A1 A2; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards I: E0 A1 A2 A3; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards I: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards I: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E) :=
forwards: E; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) :=
forwards: E0 A1; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) :=
forwards: E0 A1 A2; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards: E0 A1 A2 A3; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "applys" "~" constr(H) :=
sapply H; auto_tilde. (*待办?*)
Tactic Notation "applys" "~" constr(E0) constr(A1) :=
applys E0 A1; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) :=
applys E0 A1; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) :=
applys E0 A1 A2; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) constr(A3) :=
applys E0 A1 A2 A3; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
applys E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
applys E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "specializes" "~" hyp(H) :=
specializes H; auto_tilde.
Tactic Notation "specializes" "~" hyp(H) constr(A1) :=
specializes H A1; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) :=
specializes H A1 A2; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) :=
specializes H A1 A2 A3; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) :=
specializes H A1 A2 A3 A4; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
specializes H A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "fapply" "~" constr(E) :=
fapply E; auto_tilde.
Tactic Notation "sapply" "~" constr(E) :=
sapply E; auto_tilde.
Tactic Notation "logic" "~" constr(E) :=
logic_base E ltac:(fun _ ⇒ auto_tilde).
Tactic Notation "intros_all" "~" :=
intros_all; auto_tilde.
Tactic Notation "unfolds" "~" :=
unfolds; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) :=
unfolds F1; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) "," constr(F2) :=
unfolds F1, F2; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) "," constr(F2) "," constr(F3) :=
unfolds F1, F2, F3; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) "," constr(F2) "," constr(F3) ","
constr(F4) :=
unfolds F1, F2, F3, F4; auto_tilde.
Tactic Notation "simple" "~" :=
simpl; auto_tilde.
Tactic Notation "simple" "~" "in" hyp(H) :=
simpl in H; auto_tilde.
Tactic Notation "simpls" "~" :=
simpls; auto_tilde.
Tactic Notation "hnfs" "~" :=
hnfs; auto_tilde.
Tactic Notation "hnfs" "~" "in" hyp(H) :=
hnf in H; auto_tilde.
Tactic Notation "substs" "~" :=
substs; auto_tilde.
Tactic Notation "intro_hyp" "~" hyp(H) :=
subst_hyp H; auto_tilde.
Tactic Notation "intro_subst" "~" :=
intro_subst; auto_tilde.
Tactic Notation "subst_eq" "~" constr(E) :=
subst_eq E; auto_tilde.
Tactic Notation "rewrite" "~" constr(E) :=
rewrite E; auto_tilde.
Tactic Notation "rewrite" "~" "<-" constr(E) :=
rewrite <- E; auto_tilde.
Tactic Notation "rewrite" "~" constr(E) "in" hyp(H) :=
rewrite E in H; auto_tilde.
Tactic Notation "rewrite" "~" "<-" constr(E) "in" hyp(H) :=
rewrite <- E in H; auto_tilde.
Tactic Notation "rewrites" "~" constr(E) :=
rewrites E; auto_tilde.
Tactic Notation "rewrites" "~" constr(E) "in" hyp(H) :=
rewrites E in H; auto_tilde.
Tactic Notation "rewrites" "~" constr(E) "in" "*" :=
rewrites E in *; auto_tilde.
Tactic Notation "rewrites" "~" "<-" constr(E) :=
rewrites <- E; auto_tilde.
Tactic Notation "rewrites" "~" "<-" constr(E) "in" hyp(H) :=
rewrites <- E in H; auto_tilde.
Tactic Notation "rewrites" "~" "<-" constr(E) "in" "*" :=
rewrites <- E in *; auto_tilde.
Tactic Notation "rewrite_all" "~" constr(E) :=
rewrite_all E; auto_tilde.
Tactic Notation "rewrite_all" "~" "<-" constr(E) :=
rewrite_all <- E; auto_tilde.
Tactic Notation "rewrite_all" "~" constr(E) "in" ident(H) :=
rewrite_all E in H; auto_tilde.
Tactic Notation "rewrite_all" "~" "<-" constr(E) "in" ident(H) :=
rewrite_all <- E in H; auto_tilde.
Tactic Notation "rewrite_all" "~" constr(E) "in" "*" :=
rewrite_all E in *; auto_tilde.
Tactic Notation "rewrite_all" "~" "<-" constr(E) "in" "*" :=
rewrite_all <- E in *; auto_tilde.
Tactic Notation "asserts_rewrite" "~" constr(E) :=
asserts_rewrite E; auto_tilde.
Tactic Notation "asserts_rewrite" "~" "<-" constr(E) :=
asserts_rewrite <- E; auto_tilde.
Tactic Notation "asserts_rewrite" "~" constr(E) "in" hyp(H) :=
asserts_rewrite E in H; auto_tilde.
Tactic Notation "asserts_rewrite" "~" "<-" constr(E) "in" hyp(H) :=
asserts_rewrite <- E in H; auto_tilde.
Tactic Notation "asserts_rewrite" "~" constr(E) "in" "*" :=
asserts_rewrite E in *; auto_tilde.
Tactic Notation "asserts_rewrite" "~" "<-" constr(E) "in" "*" :=
asserts_rewrite <- E in *; auto_tilde.
Tactic Notation "cuts_rewrite" "~" constr(E) :=
cuts_rewrite E; auto_tilde.
Tactic Notation "cuts_rewrite" "~" "<-" constr(E) :=
cuts_rewrite <- E; auto_tilde.
Tactic Notation "cuts_rewrite" "~" constr(E) "in" hyp(H) :=
cuts_rewrite E in H; auto_tilde.
Tactic Notation "cuts_rewrite" "~" "<-" constr(E) "in" hyp(H) :=
cuts_rewrite <- E in H; auto_tilde.
Tactic Notation "erewrite" "~" constr(E) :=
erewrite E; auto_tilde.
Tactic Notation "erewrites" "~" constr(E) :=
erewrites E; auto_tilde.
Tactic Notation "fequal" "~" :=
fequal; auto_tilde.
Tactic Notation "fequals" "~" :=
fequals; auto_tilde.
Tactic Notation "pi_rewrite" "~" constr(E) :=
pi_rewrite E; auto_tilde.
Tactic Notation "pi_rewrite" "~" constr(E) "in" hyp(H) :=
pi_rewrite E in H; auto_tilde.
Tactic Notation "invert" "~" hyp(H) :=
invert H; auto_tilde.
Tactic Notation "inverts" "~" hyp(H) :=
inverts H; auto_tilde.
Tactic Notation "inverts" "~" hyp(E) "as" :=
inverts E as; auto_tilde.
Tactic Notation "injects" "~" hyp(H) :=
injects H; auto_tilde.
Tactic Notation "inversions" "~" hyp(H) :=
inversions H; auto_tilde.
Tactic Notation "cases" "~" constr(E) "as" ident(H) :=
cases E as H; auto_tilde.
Tactic Notation "cases" "~" constr(E) :=
cases E; auto_tilde.
Tactic Notation "case_if" "~" :=
case_if; auto_tilde.
Tactic Notation "case_ifs" "~" :=
case_ifs; auto_tilde.
Tactic Notation "case_if" "~" "in" hyp(H) :=
case_if in H; auto_tilde.
Tactic Notation "cases_if" "~" :=
cases_if; auto_tilde.
Tactic Notation "cases_if" "~" "in" hyp(H) :=
cases_if in H; auto_tilde.
Tactic Notation "destruct_if" "~" :=
destruct_if; auto_tilde.
Tactic Notation "destruct_if" "~" "in" hyp(H) :=
destruct_if in H; auto_tilde.
Tactic Notation "cases'" "~" constr(E) "as" ident(H) :=
cases' E as H; auto_tilde.
Tactic Notation "cases'" "~" constr(E) :=
cases' E; auto_tilde.
Tactic Notation "cases_if'" "~" "as" ident(H) :=
cases_if' as H; auto_tilde.
Tactic Notation "cases_if'" "~" :=
cases_if'; auto_tilde.
Tactic Notation "decides_equality" "~" :=
decides_equality; auto_tilde.
Tactic Notation "iff" "~" :=
iff; auto_tilde.
Tactic Notation "iff" "~" simple_intropattern(I) :=
iff I; auto_tilde.
Tactic Notation "splits" "~" :=
splits; auto_tilde.
Tactic Notation "splits" "~" constr(N) :=
splits N; auto_tilde.
Tactic Notation "destructs" "~" constr(T) :=
destructs T; auto_tilde.
Tactic Notation "destructs" "~" constr(N) constr(T) :=
destructs N T; auto_tilde.
Tactic Notation "branch" "~" constr(N) :=
branch N; auto_tilde.
Tactic Notation "branch" "~" constr(K) "of" constr(N) :=
branch K of N; auto_tilde.
Tactic Notation "branches" "~" :=
branches; auto_tilde.
Tactic Notation "branches" "~" constr(T) :=
branches T; auto_tilde.
Tactic Notation "branches" "~" constr(N) constr(T) :=
branches N T; auto_tilde.
Tactic Notation "exists" "~" :=
∃; auto_tilde.
Tactic Notation "exists" "~" constr(T1) :=
∃ T1; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) :=
∃ T1 T2; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) :=
∃ T1 T2 T3; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) constr(T4) :=
∃ T1 T2 T3 T4; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) :=
∃ T1 T2; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) :=
∃ T1 T2 T3; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) :=
∃ T1 T2 T3 T4; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) "," constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_tilde.
equates E; auto_tilde.
Tactic Notation "equates" "~" constr(n1) constr(n2) :=
equates n1 n2; auto_tilde.
Tactic Notation "equates" "~" constr(n1) constr(n2) constr(n3) :=
equates n1 n2 n3; auto_tilde.
Tactic Notation "equates" "~" constr(n1) constr(n2) constr(n3) constr(n4) :=
equates n1 n2 n3 n4; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) :=
applys_eq H; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(E) :=
applys_eq H E; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(n1) constr(n2) :=
applys_eq H n1 n2; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(n1) constr(n2) constr(n3) :=
applys_eq H n1 n2 n3; auto_tilde.
Tactic Notation "applys_eq" "~" constr(H) constr(n1) constr(n2) constr(n3) constr(n4) :=
applys_eq H n1 n2 n3 n4; auto_tilde.
Tactic Notation "apply" "~" constr(H) :=
sapply H; auto_tilde.
Tactic Notation "destruct" "~" constr(H) :=
destruct H; auto_tilde.
Tactic Notation "destruct" "~" constr(H) "as" simple_intropattern(I) :=
destruct H as I; auto_tilde.
Tactic Notation "f_equal" "~" :=
f_equal; auto_tilde.
Tactic Notation "induction" "~" constr(H) :=
induction H; auto_tilde.
Tactic Notation "inversion" "~" constr(H) :=
inversion H; auto_tilde.
Tactic Notation "split" "~" :=
split; auto_tilde.
Tactic Notation "subst" "~" :=
subst; auto_tilde.
Tactic Notation "right" "~" :=
right; auto_tilde.
Tactic Notation "left" "~" :=
left; auto_tilde.
Tactic Notation "constructor" "~" :=
constructor; auto_tilde.
Tactic Notation "constructors" "~" :=
constructors; auto_tilde.
Tactic Notation "false" "~" :=
false; auto_tilde.
Tactic Notation "false" "~" constr(E) :=
false_then E ltac:(fun _ ⇒ auto_tilde).
Tactic Notation "false" "~" constr(E0) constr(E1) :=
false¬(>> E0 E1).
Tactic Notation "false" "~" constr(E0) constr(E1) constr(E2) :=
false¬(>> E0 E1 E2).
Tactic Notation "false" "~" constr(E0) constr(E1) constr(E2) constr(E3) :=
false¬(>> E0 E1 E2 E3).
Tactic Notation "false" "~" constr(E0) constr(E1) constr(E2) constr(E3) constr(E4) :=
false¬(>> E0 E1 E2 E3 E4).
Tactic Notation "tryfalse" "~" :=
try solve [ false¬].
Tactic Notation "asserts" "~" simple_intropattern(H) ":" constr(E) :=
asserts H: E; [ auto_tilde | idtac ].
Tactic Notation "asserts" "~" ":" constr(E) :=
let H := fresh "H" in asserts¬H: E.
Tactic Notation "cuts" "~" simple_intropattern(H) ":" constr(E) :=
cuts H: E; [ auto_tilde | idtac ].
Tactic Notation "cuts" "~" ":" constr(E) :=
cuts: E; [ auto_tilde | idtac ].
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E) :=
lets I: E; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
lets I: E0 A1; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
lets I: E0 A1 A2; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets I: E0 A1 A2 A3; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets I: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "lets" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets I: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E) :=
lets: E; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) :=
lets: E0 A1; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) :=
lets: E0 A1 A2; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets: E0 A1 A2 A3; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "lets" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E) :=
forwards I: E; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
forwards I: E0 A1; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
forwards I: E0 A1 A2; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards I: E0 A1 A2 A3; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards I: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "forwards" "~" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards I: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E) :=
forwards: E; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) :=
forwards: E0 A1; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) :=
forwards: E0 A1 A2; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards: E0 A1 A2 A3; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards: E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "forwards" "~" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards: E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "applys" "~" constr(H) :=
sapply H; auto_tilde. (*待办?*)
Tactic Notation "applys" "~" constr(E0) constr(A1) :=
applys E0 A1; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) :=
applys E0 A1; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) :=
applys E0 A1 A2; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) constr(A3) :=
applys E0 A1 A2 A3; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
applys E0 A1 A2 A3 A4; auto_tilde.
Tactic Notation "applys" "~" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
applys E0 A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "specializes" "~" hyp(H) :=
specializes H; auto_tilde.
Tactic Notation "specializes" "~" hyp(H) constr(A1) :=
specializes H A1; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) :=
specializes H A1 A2; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) :=
specializes H A1 A2 A3; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) :=
specializes H A1 A2 A3 A4; auto_tilde.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
specializes H A1 A2 A3 A4 A5; auto_tilde.
Tactic Notation "fapply" "~" constr(E) :=
fapply E; auto_tilde.
Tactic Notation "sapply" "~" constr(E) :=
sapply E; auto_tilde.
Tactic Notation "logic" "~" constr(E) :=
logic_base E ltac:(fun _ ⇒ auto_tilde).
Tactic Notation "intros_all" "~" :=
intros_all; auto_tilde.
Tactic Notation "unfolds" "~" :=
unfolds; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) :=
unfolds F1; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) "," constr(F2) :=
unfolds F1, F2; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) "," constr(F2) "," constr(F3) :=
unfolds F1, F2, F3; auto_tilde.
Tactic Notation "unfolds" "~" constr(F1) "," constr(F2) "," constr(F3) ","
constr(F4) :=
unfolds F1, F2, F3, F4; auto_tilde.
Tactic Notation "simple" "~" :=
simpl; auto_tilde.
Tactic Notation "simple" "~" "in" hyp(H) :=
simpl in H; auto_tilde.
Tactic Notation "simpls" "~" :=
simpls; auto_tilde.
Tactic Notation "hnfs" "~" :=
hnfs; auto_tilde.
Tactic Notation "hnfs" "~" "in" hyp(H) :=
hnf in H; auto_tilde.
Tactic Notation "substs" "~" :=
substs; auto_tilde.
Tactic Notation "intro_hyp" "~" hyp(H) :=
subst_hyp H; auto_tilde.
Tactic Notation "intro_subst" "~" :=
intro_subst; auto_tilde.
Tactic Notation "subst_eq" "~" constr(E) :=
subst_eq E; auto_tilde.
Tactic Notation "rewrite" "~" constr(E) :=
rewrite E; auto_tilde.
Tactic Notation "rewrite" "~" "<-" constr(E) :=
rewrite <- E; auto_tilde.
Tactic Notation "rewrite" "~" constr(E) "in" hyp(H) :=
rewrite E in H; auto_tilde.
Tactic Notation "rewrite" "~" "<-" constr(E) "in" hyp(H) :=
rewrite <- E in H; auto_tilde.
Tactic Notation "rewrites" "~" constr(E) :=
rewrites E; auto_tilde.
Tactic Notation "rewrites" "~" constr(E) "in" hyp(H) :=
rewrites E in H; auto_tilde.
Tactic Notation "rewrites" "~" constr(E) "in" "*" :=
rewrites E in *; auto_tilde.
Tactic Notation "rewrites" "~" "<-" constr(E) :=
rewrites <- E; auto_tilde.
Tactic Notation "rewrites" "~" "<-" constr(E) "in" hyp(H) :=
rewrites <- E in H; auto_tilde.
Tactic Notation "rewrites" "~" "<-" constr(E) "in" "*" :=
rewrites <- E in *; auto_tilde.
Tactic Notation "rewrite_all" "~" constr(E) :=
rewrite_all E; auto_tilde.
Tactic Notation "rewrite_all" "~" "<-" constr(E) :=
rewrite_all <- E; auto_tilde.
Tactic Notation "rewrite_all" "~" constr(E) "in" ident(H) :=
rewrite_all E in H; auto_tilde.
Tactic Notation "rewrite_all" "~" "<-" constr(E) "in" ident(H) :=
rewrite_all <- E in H; auto_tilde.
Tactic Notation "rewrite_all" "~" constr(E) "in" "*" :=
rewrite_all E in *; auto_tilde.
Tactic Notation "rewrite_all" "~" "<-" constr(E) "in" "*" :=
rewrite_all <- E in *; auto_tilde.
Tactic Notation "asserts_rewrite" "~" constr(E) :=
asserts_rewrite E; auto_tilde.
Tactic Notation "asserts_rewrite" "~" "<-" constr(E) :=
asserts_rewrite <- E; auto_tilde.
Tactic Notation "asserts_rewrite" "~" constr(E) "in" hyp(H) :=
asserts_rewrite E in H; auto_tilde.
Tactic Notation "asserts_rewrite" "~" "<-" constr(E) "in" hyp(H) :=
asserts_rewrite <- E in H; auto_tilde.
Tactic Notation "asserts_rewrite" "~" constr(E) "in" "*" :=
asserts_rewrite E in *; auto_tilde.
Tactic Notation "asserts_rewrite" "~" "<-" constr(E) "in" "*" :=
asserts_rewrite <- E in *; auto_tilde.
Tactic Notation "cuts_rewrite" "~" constr(E) :=
cuts_rewrite E; auto_tilde.
Tactic Notation "cuts_rewrite" "~" "<-" constr(E) :=
cuts_rewrite <- E; auto_tilde.
Tactic Notation "cuts_rewrite" "~" constr(E) "in" hyp(H) :=
cuts_rewrite E in H; auto_tilde.
Tactic Notation "cuts_rewrite" "~" "<-" constr(E) "in" hyp(H) :=
cuts_rewrite <- E in H; auto_tilde.
Tactic Notation "erewrite" "~" constr(E) :=
erewrite E; auto_tilde.
Tactic Notation "erewrites" "~" constr(E) :=
erewrites E; auto_tilde.
Tactic Notation "fequal" "~" :=
fequal; auto_tilde.
Tactic Notation "fequals" "~" :=
fequals; auto_tilde.
Tactic Notation "pi_rewrite" "~" constr(E) :=
pi_rewrite E; auto_tilde.
Tactic Notation "pi_rewrite" "~" constr(E) "in" hyp(H) :=
pi_rewrite E in H; auto_tilde.
Tactic Notation "invert" "~" hyp(H) :=
invert H; auto_tilde.
Tactic Notation "inverts" "~" hyp(H) :=
inverts H; auto_tilde.
Tactic Notation "inverts" "~" hyp(E) "as" :=
inverts E as; auto_tilde.
Tactic Notation "injects" "~" hyp(H) :=
injects H; auto_tilde.
Tactic Notation "inversions" "~" hyp(H) :=
inversions H; auto_tilde.
Tactic Notation "cases" "~" constr(E) "as" ident(H) :=
cases E as H; auto_tilde.
Tactic Notation "cases" "~" constr(E) :=
cases E; auto_tilde.
Tactic Notation "case_if" "~" :=
case_if; auto_tilde.
Tactic Notation "case_ifs" "~" :=
case_ifs; auto_tilde.
Tactic Notation "case_if" "~" "in" hyp(H) :=
case_if in H; auto_tilde.
Tactic Notation "cases_if" "~" :=
cases_if; auto_tilde.
Tactic Notation "cases_if" "~" "in" hyp(H) :=
cases_if in H; auto_tilde.
Tactic Notation "destruct_if" "~" :=
destruct_if; auto_tilde.
Tactic Notation "destruct_if" "~" "in" hyp(H) :=
destruct_if in H; auto_tilde.
Tactic Notation "cases'" "~" constr(E) "as" ident(H) :=
cases' E as H; auto_tilde.
Tactic Notation "cases'" "~" constr(E) :=
cases' E; auto_tilde.
Tactic Notation "cases_if'" "~" "as" ident(H) :=
cases_if' as H; auto_tilde.
Tactic Notation "cases_if'" "~" :=
cases_if'; auto_tilde.
Tactic Notation "decides_equality" "~" :=
decides_equality; auto_tilde.
Tactic Notation "iff" "~" :=
iff; auto_tilde.
Tactic Notation "iff" "~" simple_intropattern(I) :=
iff I; auto_tilde.
Tactic Notation "splits" "~" :=
splits; auto_tilde.
Tactic Notation "splits" "~" constr(N) :=
splits N; auto_tilde.
Tactic Notation "destructs" "~" constr(T) :=
destructs T; auto_tilde.
Tactic Notation "destructs" "~" constr(N) constr(T) :=
destructs N T; auto_tilde.
Tactic Notation "branch" "~" constr(N) :=
branch N; auto_tilde.
Tactic Notation "branch" "~" constr(K) "of" constr(N) :=
branch K of N; auto_tilde.
Tactic Notation "branches" "~" :=
branches; auto_tilde.
Tactic Notation "branches" "~" constr(T) :=
branches T; auto_tilde.
Tactic Notation "branches" "~" constr(N) constr(T) :=
branches N T; auto_tilde.
Tactic Notation "exists" "~" :=
∃; auto_tilde.
Tactic Notation "exists" "~" constr(T1) :=
∃ T1; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) :=
∃ T1 T2; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) :=
∃ T1 T2 T3; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) constr(T4) :=
∃ T1 T2 T3 T4; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_tilde.
Tactic Notation "exists" "~" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) :=
∃ T1 T2; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) :=
∃ T1 T2 T3; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) :=
∃ T1 T2 T3 T4; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_tilde.
Tactic Notation "exists" "~" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) "," constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_tilde.
强力自动化的解析
Tactic Notation "equates" "*" constr(E) :=
equates E; auto_star.
Tactic Notation "equates" "*" constr(n1) constr(n2) :=
equates n1 n2; auto_star.
Tactic Notation "equates" "*" constr(n1) constr(n2) constr(n3) :=
equates n1 n2 n3; auto_star.
Tactic Notation "equates" "*" constr(n1) constr(n2) constr(n3) constr(n4) :=
equates n1 n2 n3 n4; auto_star.
Tactic Notation "applys_eq" "*" constr(H) :=
applys_eq H; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(E) :=
applys_eq H E; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(n1) constr(n2) :=
applys_eq H n1 n2; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(n1) constr(n2) constr(n3) :=
applys_eq H n1 n2 n3; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(n1) constr(n2) constr(n3) constr(n4) :=
applys_eq H n1 n2 n3 n4; auto_star.
Tactic Notation "apply" "*" constr(H) :=
sapply H; auto_star.
Tactic Notation "destruct" "*" constr(H) :=
destruct H; auto_star.
Tactic Notation "destruct" "*" constr(H) "as" simple_intropattern(I) :=
destruct H as I; auto_star.
Tactic Notation "f_equal" "*" :=
f_equal; auto_star.
Tactic Notation "induction" "*" constr(H) :=
induction H; auto_star.
Tactic Notation "inversion" "*" constr(H) :=
inversion H; auto_star.
Tactic Notation "split" "*" :=
split; auto_star.
Tactic Notation "subs" "*" :=
subst; auto_star.
Tactic Notation "subst" "*" :=
subst; auto_star.
Tactic Notation "right" "*" :=
right; auto_star.
Tactic Notation "left" "*" :=
left; auto_star.
Tactic Notation "constructor" "*" :=
constructor; auto_star.
Tactic Notation "constructors" "*" :=
constructors; auto_star.
Tactic Notation "false" "*" :=
false; auto_star.
Tactic Notation "false" "*" constr(E) :=
false_then E ltac:(fun _ ⇒ auto_star).
Tactic Notation "false" "*" constr(E0) constr(E1) :=
false× (>> E0 E1).
Tactic Notation "false" "*" constr(E0) constr(E1) constr(E2) :=
false× (>> E0 E1 E2).
Tactic Notation "false" "*" constr(E0) constr(E1) constr(E2) constr(E3) :=
false× (>> E0 E1 E2 E3).
Tactic Notation "false" "*" constr(E0) constr(E1) constr(E2) constr(E3) constr(E4) :=
false× (>> E0 E1 E2 E3 E4).
Tactic Notation "tryfalse" "*" :=
try solve [ false× ].
Tactic Notation "asserts" "*" simple_intropattern(H) ":" constr(E) :=
asserts H: E; [ auto_star | idtac ].
Tactic Notation "asserts" "*" ":" constr(E) :=
let H := fresh "H" in asserts× H: E.
Tactic Notation "cuts" "*" simple_intropattern(H) ":" constr(E) :=
cuts H: E; [ auto_star | idtac ].
Tactic Notation "cuts" "*" ":" constr(E) :=
cuts: E; [ auto_star | idtac ].
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E) :=
lets I: E; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
lets I: E0 A1; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
lets I: E0 A1 A2; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets I: E0 A1 A2 A3; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets I: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets I: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "lets" "*" ":" constr(E) :=
lets: E; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) :=
lets: E0 A1; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) :=
lets: E0 A1 A2; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets: E0 A1 A2 A3; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E) :=
forwards I: E; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
forwards I: E0 A1; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
forwards I: E0 A1 A2; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards I: E0 A1 A2 A3; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards I: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards I: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "forwards" "*" ":" constr(E) :=
forwards: E; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) :=
forwards: E0 A1; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) :=
forwards: E0 A1 A2; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards: E0 A1 A2 A3; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "applys" "*" constr(H) :=
sapply H; auto_star. (*待办?*)
Tactic Notation "applys" "*" constr(E0) constr(A1) :=
applys E0 A1; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) :=
applys E0 A1; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) :=
applys E0 A1 A2; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) constr(A3) :=
applys E0 A1 A2 A3; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
applys E0 A1 A2 A3 A4; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
applys E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "specializes" "*" hyp(H) :=
specializes H; auto_star.
Tactic Notation "specializes" "~" hyp(H) constr(A1) :=
specializes H A1; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) :=
specializes H A1 A2; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) :=
specializes H A1 A2 A3; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) :=
specializes H A1 A2 A3 A4; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
specializes H A1 A2 A3 A4 A5; auto_star.
Tactic Notation "fapply" "*" constr(E) :=
fapply E; auto_star.
Tactic Notation "sapply" "*" constr(E) :=
sapply E; auto_star.
Tactic Notation "logic" constr(E) :=
logic_base E ltac:(fun _ ⇒ auto_star).
Tactic Notation "intros_all" "*" :=
intros_all; auto_star.
Tactic Notation "unfolds" "*" :=
unfolds; auto_star.
Tactic Notation "unfolds" "*" constr(F1) :=
unfolds F1; auto_star.
Tactic Notation "unfolds" "*" constr(F1) "," constr(F2) :=
unfolds F1, F2; auto_star.
Tactic Notation "unfolds" "*" constr(F1) "," constr(F2) "," constr(F3) :=
unfolds F1, F2, F3; auto_star.
Tactic Notation "unfolds" "*" constr(F1) "," constr(F2) "," constr(F3) ","
constr(F4) :=
unfolds F1, F2, F3, F4; auto_star.
Tactic Notation "simple" "*" :=
simpl; auto_star.
Tactic Notation "simple" "*" "in" hyp(H) :=
simpl in H; auto_star.
Tactic Notation "simpls" "*" :=
simpls; auto_star.
Tactic Notation "hnfs" "*" :=
hnfs; auto_star.
Tactic Notation "hnfs" "*" "in" hyp(H) :=
hnf in H; auto_star.
Tactic Notation "substs" "*" :=
substs; auto_star.
Tactic Notation "intro_hyp" "*" hyp(H) :=
subst_hyp H; auto_star.
Tactic Notation "intro_subst" "*" :=
intro_subst; auto_star.
Tactic Notation "subst_eq" "*" constr(E) :=
subst_eq E; auto_star.
Tactic Notation "rewrite" "*" constr(E) :=
rewrite E; auto_star.
Tactic Notation "rewrite" "*" "<-" constr(E) :=
rewrite <- E; auto_star.
Tactic Notation "rewrite" "*" constr(E) "in" hyp(H) :=
rewrite E in H; auto_star.
Tactic Notation "rewrite" "*" "<-" constr(E) "in" hyp(H) :=
rewrite <- E in H; auto_star.
Tactic Notation "rewrites" "*" constr(E) :=
rewrites E; auto_star.
Tactic Notation "rewrites" "*" constr(E) "in" hyp(H):=
rewrites E in H; auto_star.
Tactic Notation "rewrites" "*" constr(E) "in" "*":=
rewrites E in *; auto_star.
Tactic Notation "rewrites" "*" "<-" constr(E) :=
rewrites <- E; auto_star.
Tactic Notation "rewrites" "*" "<-" constr(E) "in" hyp(H):=
rewrites <- E in H; auto_star.
Tactic Notation "rewrites" "*" "<-" constr(E) "in" "*":=
rewrites <- E in *; auto_star.
Tactic Notation "rewrite_all" "*" constr(E) :=
rewrite_all E; auto_star.
Tactic Notation "rewrite_all" "*" "<-" constr(E) :=
rewrite_all <- E; auto_star.
Tactic Notation "rewrite_all" "*" constr(E) "in" ident(H) :=
rewrite_all E in H; auto_star.
Tactic Notation "rewrite_all" "*" "<-" constr(E) "in" ident(H) :=
rewrite_all <- E in H; auto_star.
Tactic Notation "rewrite_all" "*" constr(E) "in" "*" :=
rewrite_all E in *; auto_star.
Tactic Notation "rewrite_all" "*" "<-" constr(E) "in" "*" :=
rewrite_all <- E in *; auto_star.
Tactic Notation "asserts_rewrite" "*" constr(E) :=
asserts_rewrite E; auto_star.
Tactic Notation "asserts_rewrite" "*" "<-" constr(E) :=
asserts_rewrite <- E; auto_star.
Tactic Notation "asserts_rewrite" "*" constr(E) "in" hyp(H) :=
asserts_rewrite E; auto_star.
Tactic Notation "asserts_rewrite" "*" "<-" constr(E) "in" hyp(H) :=
asserts_rewrite <- E; auto_star.
Tactic Notation "asserts_rewrite" "*" constr(E) "in" "*" :=
asserts_rewrite E in *; auto_tilde.
Tactic Notation "asserts_rewrite" "*" "<-" constr(E) "in" "*" :=
asserts_rewrite <- E in *; auto_tilde.
Tactic Notation "cuts_rewrite" "*" constr(E) :=
cuts_rewrite E; auto_star.
Tactic Notation "cuts_rewrite" "*" "<-" constr(E) :=
cuts_rewrite <- E; auto_star.
Tactic Notation "cuts_rewrite" "*" constr(E) "in" hyp(H) :=
cuts_rewrite E in H; auto_star.
Tactic Notation "cuts_rewrite" "*" "<-" constr(E) "in" hyp(H) :=
cuts_rewrite <- E in H; auto_star.
Tactic Notation "erewrite" "*" constr(E) :=
erewrite E; auto_star.
Tactic Notation "erewrites" "*" constr(E) :=
erewrites E; auto_star.
Tactic Notation "fequal" "*" :=
fequal; auto_star.
Tactic Notation "fequals" "*" :=
fequals; auto_star.
Tactic Notation "pi_rewrite" "*" constr(E) :=
pi_rewrite E; auto_star.
Tactic Notation "pi_rewrite" "*" constr(E) "in" hyp(H) :=
pi_rewrite E in H; auto_star.
Tactic Notation "invert" "*" hyp(H) :=
invert H; auto_star.
Tactic Notation "inverts" "*" hyp(H) :=
inverts H; auto_star.
Tactic Notation "inverts" "*" hyp(E) "as" :=
inverts E as; auto_star.
Tactic Notation "injects" "*" hyp(H) :=
injects H; auto_star.
Tactic Notation "inversions" "*" hyp(H) :=
inversions H; auto_star.
Tactic Notation "cases" "*" constr(E) "as" ident(H) :=
cases E as H; auto_star.
Tactic Notation "cases" "*" constr(E) :=
cases E; auto_star.
Tactic Notation "case_if" "*" :=
case_if; auto_star.
Tactic Notation "case_ifs" "*" :=
case_ifs; auto_star.
Tactic Notation "case_if" "*" "in" hyp(H) :=
case_if in H; auto_star.
Tactic Notation "cases_if" "*" :=
cases_if; auto_star.
Tactic Notation "cases_if" "*" "in" hyp(H) :=
cases_if in H; auto_star.
Tactic Notation "destruct_if" "*" :=
destruct_if; auto_star.
Tactic Notation "destruct_if" "*" "in" hyp(H) :=
destruct_if in H; auto_star.
Tactic Notation "cases'" "*" constr(E) "as" ident(H) :=
cases' E as H; auto_star.
Tactic Notation "cases'" "*" constr(E) :=
cases' E; auto_star.
Tactic Notation "cases_if'" "*" "as" ident(H) :=
cases_if' as H; auto_star.
Tactic Notation "cases_if'" "*" :=
cases_if'; auto_star.
Tactic Notation "decides_equality" "*" :=
decides_equality; auto_star.
Tactic Notation "iff" "*" :=
iff; auto_star.
Tactic Notation "iff" "*" simple_intropattern(I) :=
iff I; auto_star.
Tactic Notation "splits" "*" :=
splits; auto_star.
Tactic Notation "splits" "*" constr(N) :=
splits N; auto_star.
Tactic Notation "destructs" "*" constr(T) :=
destructs T; auto_star.
Tactic Notation "destructs" "*" constr(N) constr(T) :=
destructs N T; auto_star.
Tactic Notation "branch" "*" constr(N) :=
branch N; auto_star.
Tactic Notation "branch" "*" constr(K) "of" constr(N) :=
branch K of N; auto_star.
Tactic Notation "branches" "*" constr(T) :=
branches T; auto_star.
Tactic Notation "branches" "*" constr(N) constr(T) :=
branches N T; auto_star.
Tactic Notation "exists" "*" :=
∃; auto_star.
Tactic Notation "exists" "*" constr(T1) :=
∃ T1; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) :=
∃ T1 T2; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) :=
∃ T1 T2 T3; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) constr(T4) :=
∃ T1 T2 T3 T4; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) :=
∃ T1 T2; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) :=
∃ T1 T2 T3; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) :=
∃ T1 T2 T3 T4; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) "," constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_star.
equates E; auto_star.
Tactic Notation "equates" "*" constr(n1) constr(n2) :=
equates n1 n2; auto_star.
Tactic Notation "equates" "*" constr(n1) constr(n2) constr(n3) :=
equates n1 n2 n3; auto_star.
Tactic Notation "equates" "*" constr(n1) constr(n2) constr(n3) constr(n4) :=
equates n1 n2 n3 n4; auto_star.
Tactic Notation "applys_eq" "*" constr(H) :=
applys_eq H; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(E) :=
applys_eq H E; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(n1) constr(n2) :=
applys_eq H n1 n2; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(n1) constr(n2) constr(n3) :=
applys_eq H n1 n2 n3; auto_star.
Tactic Notation "applys_eq" "*" constr(H) constr(n1) constr(n2) constr(n3) constr(n4) :=
applys_eq H n1 n2 n3 n4; auto_star.
Tactic Notation "apply" "*" constr(H) :=
sapply H; auto_star.
Tactic Notation "destruct" "*" constr(H) :=
destruct H; auto_star.
Tactic Notation "destruct" "*" constr(H) "as" simple_intropattern(I) :=
destruct H as I; auto_star.
Tactic Notation "f_equal" "*" :=
f_equal; auto_star.
Tactic Notation "induction" "*" constr(H) :=
induction H; auto_star.
Tactic Notation "inversion" "*" constr(H) :=
inversion H; auto_star.
Tactic Notation "split" "*" :=
split; auto_star.
Tactic Notation "subs" "*" :=
subst; auto_star.
Tactic Notation "subst" "*" :=
subst; auto_star.
Tactic Notation "right" "*" :=
right; auto_star.
Tactic Notation "left" "*" :=
left; auto_star.
Tactic Notation "constructor" "*" :=
constructor; auto_star.
Tactic Notation "constructors" "*" :=
constructors; auto_star.
Tactic Notation "false" "*" :=
false; auto_star.
Tactic Notation "false" "*" constr(E) :=
false_then E ltac:(fun _ ⇒ auto_star).
Tactic Notation "false" "*" constr(E0) constr(E1) :=
false× (>> E0 E1).
Tactic Notation "false" "*" constr(E0) constr(E1) constr(E2) :=
false× (>> E0 E1 E2).
Tactic Notation "false" "*" constr(E0) constr(E1) constr(E2) constr(E3) :=
false× (>> E0 E1 E2 E3).
Tactic Notation "false" "*" constr(E0) constr(E1) constr(E2) constr(E3) constr(E4) :=
false× (>> E0 E1 E2 E3 E4).
Tactic Notation "tryfalse" "*" :=
try solve [ false× ].
Tactic Notation "asserts" "*" simple_intropattern(H) ":" constr(E) :=
asserts H: E; [ auto_star | idtac ].
Tactic Notation "asserts" "*" ":" constr(E) :=
let H := fresh "H" in asserts× H: E.
Tactic Notation "cuts" "*" simple_intropattern(H) ":" constr(E) :=
cuts H: E; [ auto_star | idtac ].
Tactic Notation "cuts" "*" ":" constr(E) :=
cuts: E; [ auto_star | idtac ].
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E) :=
lets I: E; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
lets I: E0 A1; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
lets I: E0 A1 A2; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets I: E0 A1 A2 A3; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets I: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "lets" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets I: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "lets" "*" ":" constr(E) :=
lets: E; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) :=
lets: E0 A1; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) :=
lets: E0 A1 A2; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
lets: E0 A1 A2 A3; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
lets: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "lets" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
lets: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E) :=
forwards I: E; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) :=
forwards I: E0 A1; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) :=
forwards I: E0 A1 A2; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards I: E0 A1 A2 A3; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards I: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "forwards" "*" simple_intropattern(I) ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards I: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "forwards" "*" ":" constr(E) :=
forwards: E; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) :=
forwards: E0 A1; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) :=
forwards: E0 A1 A2; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) :=
forwards: E0 A1 A2 A3; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) :=
forwards: E0 A1 A2 A3 A4; auto_star.
Tactic Notation "forwards" "*" ":" constr(E0)
constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
forwards: E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "applys" "*" constr(H) :=
sapply H; auto_star. (*待办?*)
Tactic Notation "applys" "*" constr(E0) constr(A1) :=
applys E0 A1; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) :=
applys E0 A1; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) :=
applys E0 A1 A2; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) constr(A3) :=
applys E0 A1 A2 A3; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) :=
applys E0 A1 A2 A3 A4; auto_star.
Tactic Notation "applys" "*" constr(E0) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
applys E0 A1 A2 A3 A4 A5; auto_star.
Tactic Notation "specializes" "*" hyp(H) :=
specializes H; auto_star.
Tactic Notation "specializes" "~" hyp(H) constr(A1) :=
specializes H A1; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) :=
specializes H A1 A2; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) :=
specializes H A1 A2 A3; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) :=
specializes H A1 A2 A3 A4; auto_star.
Tactic Notation "specializes" hyp(H) constr(A1) constr(A2) constr(A3) constr(A4) constr(A5) :=
specializes H A1 A2 A3 A4 A5; auto_star.
Tactic Notation "fapply" "*" constr(E) :=
fapply E; auto_star.
Tactic Notation "sapply" "*" constr(E) :=
sapply E; auto_star.
Tactic Notation "logic" constr(E) :=
logic_base E ltac:(fun _ ⇒ auto_star).
Tactic Notation "intros_all" "*" :=
intros_all; auto_star.
Tactic Notation "unfolds" "*" :=
unfolds; auto_star.
Tactic Notation "unfolds" "*" constr(F1) :=
unfolds F1; auto_star.
Tactic Notation "unfolds" "*" constr(F1) "," constr(F2) :=
unfolds F1, F2; auto_star.
Tactic Notation "unfolds" "*" constr(F1) "," constr(F2) "," constr(F3) :=
unfolds F1, F2, F3; auto_star.
Tactic Notation "unfolds" "*" constr(F1) "," constr(F2) "," constr(F3) ","
constr(F4) :=
unfolds F1, F2, F3, F4; auto_star.
Tactic Notation "simple" "*" :=
simpl; auto_star.
Tactic Notation "simple" "*" "in" hyp(H) :=
simpl in H; auto_star.
Tactic Notation "simpls" "*" :=
simpls; auto_star.
Tactic Notation "hnfs" "*" :=
hnfs; auto_star.
Tactic Notation "hnfs" "*" "in" hyp(H) :=
hnf in H; auto_star.
Tactic Notation "substs" "*" :=
substs; auto_star.
Tactic Notation "intro_hyp" "*" hyp(H) :=
subst_hyp H; auto_star.
Tactic Notation "intro_subst" "*" :=
intro_subst; auto_star.
Tactic Notation "subst_eq" "*" constr(E) :=
subst_eq E; auto_star.
Tactic Notation "rewrite" "*" constr(E) :=
rewrite E; auto_star.
Tactic Notation "rewrite" "*" "<-" constr(E) :=
rewrite <- E; auto_star.
Tactic Notation "rewrite" "*" constr(E) "in" hyp(H) :=
rewrite E in H; auto_star.
Tactic Notation "rewrite" "*" "<-" constr(E) "in" hyp(H) :=
rewrite <- E in H; auto_star.
Tactic Notation "rewrites" "*" constr(E) :=
rewrites E; auto_star.
Tactic Notation "rewrites" "*" constr(E) "in" hyp(H):=
rewrites E in H; auto_star.
Tactic Notation "rewrites" "*" constr(E) "in" "*":=
rewrites E in *; auto_star.
Tactic Notation "rewrites" "*" "<-" constr(E) :=
rewrites <- E; auto_star.
Tactic Notation "rewrites" "*" "<-" constr(E) "in" hyp(H):=
rewrites <- E in H; auto_star.
Tactic Notation "rewrites" "*" "<-" constr(E) "in" "*":=
rewrites <- E in *; auto_star.
Tactic Notation "rewrite_all" "*" constr(E) :=
rewrite_all E; auto_star.
Tactic Notation "rewrite_all" "*" "<-" constr(E) :=
rewrite_all <- E; auto_star.
Tactic Notation "rewrite_all" "*" constr(E) "in" ident(H) :=
rewrite_all E in H; auto_star.
Tactic Notation "rewrite_all" "*" "<-" constr(E) "in" ident(H) :=
rewrite_all <- E in H; auto_star.
Tactic Notation "rewrite_all" "*" constr(E) "in" "*" :=
rewrite_all E in *; auto_star.
Tactic Notation "rewrite_all" "*" "<-" constr(E) "in" "*" :=
rewrite_all <- E in *; auto_star.
Tactic Notation "asserts_rewrite" "*" constr(E) :=
asserts_rewrite E; auto_star.
Tactic Notation "asserts_rewrite" "*" "<-" constr(E) :=
asserts_rewrite <- E; auto_star.
Tactic Notation "asserts_rewrite" "*" constr(E) "in" hyp(H) :=
asserts_rewrite E; auto_star.
Tactic Notation "asserts_rewrite" "*" "<-" constr(E) "in" hyp(H) :=
asserts_rewrite <- E; auto_star.
Tactic Notation "asserts_rewrite" "*" constr(E) "in" "*" :=
asserts_rewrite E in *; auto_tilde.
Tactic Notation "asserts_rewrite" "*" "<-" constr(E) "in" "*" :=
asserts_rewrite <- E in *; auto_tilde.
Tactic Notation "cuts_rewrite" "*" constr(E) :=
cuts_rewrite E; auto_star.
Tactic Notation "cuts_rewrite" "*" "<-" constr(E) :=
cuts_rewrite <- E; auto_star.
Tactic Notation "cuts_rewrite" "*" constr(E) "in" hyp(H) :=
cuts_rewrite E in H; auto_star.
Tactic Notation "cuts_rewrite" "*" "<-" constr(E) "in" hyp(H) :=
cuts_rewrite <- E in H; auto_star.
Tactic Notation "erewrite" "*" constr(E) :=
erewrite E; auto_star.
Tactic Notation "erewrites" "*" constr(E) :=
erewrites E; auto_star.
Tactic Notation "fequal" "*" :=
fequal; auto_star.
Tactic Notation "fequals" "*" :=
fequals; auto_star.
Tactic Notation "pi_rewrite" "*" constr(E) :=
pi_rewrite E; auto_star.
Tactic Notation "pi_rewrite" "*" constr(E) "in" hyp(H) :=
pi_rewrite E in H; auto_star.
Tactic Notation "invert" "*" hyp(H) :=
invert H; auto_star.
Tactic Notation "inverts" "*" hyp(H) :=
inverts H; auto_star.
Tactic Notation "inverts" "*" hyp(E) "as" :=
inverts E as; auto_star.
Tactic Notation "injects" "*" hyp(H) :=
injects H; auto_star.
Tactic Notation "inversions" "*" hyp(H) :=
inversions H; auto_star.
Tactic Notation "cases" "*" constr(E) "as" ident(H) :=
cases E as H; auto_star.
Tactic Notation "cases" "*" constr(E) :=
cases E; auto_star.
Tactic Notation "case_if" "*" :=
case_if; auto_star.
Tactic Notation "case_ifs" "*" :=
case_ifs; auto_star.
Tactic Notation "case_if" "*" "in" hyp(H) :=
case_if in H; auto_star.
Tactic Notation "cases_if" "*" :=
cases_if; auto_star.
Tactic Notation "cases_if" "*" "in" hyp(H) :=
cases_if in H; auto_star.
Tactic Notation "destruct_if" "*" :=
destruct_if; auto_star.
Tactic Notation "destruct_if" "*" "in" hyp(H) :=
destruct_if in H; auto_star.
Tactic Notation "cases'" "*" constr(E) "as" ident(H) :=
cases' E as H; auto_star.
Tactic Notation "cases'" "*" constr(E) :=
cases' E; auto_star.
Tactic Notation "cases_if'" "*" "as" ident(H) :=
cases_if' as H; auto_star.
Tactic Notation "cases_if'" "*" :=
cases_if'; auto_star.
Tactic Notation "decides_equality" "*" :=
decides_equality; auto_star.
Tactic Notation "iff" "*" :=
iff; auto_star.
Tactic Notation "iff" "*" simple_intropattern(I) :=
iff I; auto_star.
Tactic Notation "splits" "*" :=
splits; auto_star.
Tactic Notation "splits" "*" constr(N) :=
splits N; auto_star.
Tactic Notation "destructs" "*" constr(T) :=
destructs T; auto_star.
Tactic Notation "destructs" "*" constr(N) constr(T) :=
destructs N T; auto_star.
Tactic Notation "branch" "*" constr(N) :=
branch N; auto_star.
Tactic Notation "branch" "*" constr(K) "of" constr(N) :=
branch K of N; auto_star.
Tactic Notation "branches" "*" constr(T) :=
branches T; auto_star.
Tactic Notation "branches" "*" constr(N) constr(T) :=
branches N T; auto_star.
Tactic Notation "exists" "*" :=
∃; auto_star.
Tactic Notation "exists" "*" constr(T1) :=
∃ T1; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) :=
∃ T1 T2; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) :=
∃ T1 T2 T3; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) constr(T4) :=
∃ T1 T2 T3 T4; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_star.
Tactic Notation "exists" "*" constr(T1) constr(T2) constr(T3) constr(T4)
constr(T5) constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) :=
∃ T1 T2; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) :=
∃ T1 T2 T3; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) :=
∃ T1 T2 T3 T4; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) :=
∃ T1 T2 T3 T4 T5; auto_star.
Tactic Notation "exists" "*" constr(T1) "," constr(T2) "," constr(T3) ","
constr(T4) "," constr(T5) "," constr(T6) :=
∃ T1 T2 T3 T4 T5 T6; auto_star.
(* 实现 *)
Definition ltac_something (P:Type) (e:P) := e.
Notation "'Something'" :=
(@ltac_something _ _).
Lemma ltac_something_eq : ∀ (e:Type),
e = (@ltac_something _ e).
Proof using. auto. Qed.
Lemma ltac_something_hide : ∀ (e:Type),
e → (@ltac_something _ e).
Proof using. auto. Qed.
Lemma ltac_something_show : ∀ (e:Type),
(@ltac_something _ e) → e.
Proof using. auto. Qed.
Definition ltac_something (P:Type) (e:P) := e.
Notation "'Something'" :=
(@ltac_something _ _).
Lemma ltac_something_eq : ∀ (e:Type),
e = (@ltac_something _ e).
Proof using. auto. Qed.
Lemma ltac_something_hide : ∀ (e:Type),
e → (@ltac_something _ e).
Proof using. auto. Qed.
Lemma ltac_something_show : ∀ (e:Type),
(@ltac_something _ e) → e.
Proof using. auto. Qed.
hide_def x 与 show_def x 可用于
隐藏/显示定义 x 的函数体。
Tactic Notation "hide_def" hyp(x) :=
let x' := constr:(x) in
let T := eval unfold x in x' in
change T with (@ltac_something _ T) in x.
Tactic Notation "show_def" hyp(x) :=
let x' := constr:(x) in
let U := eval unfold x in x' in
match U with @ltac_something _ ?T ⇒
change U with T in x end.
let x' := constr:(x) in
let T := eval unfold x in x' in
change T with (@ltac_something _ T) in x.
Tactic Notation "show_def" hyp(x) :=
let x' := constr:(x) in
let U := eval unfold x in x' in
match U with @ltac_something _ ?T ⇒
change U with T in x end.
show_def 展开目标中的 Something
Tactic Notation "show_def" :=
unfold ltac_something.
Tactic Notation "show_def" "in" hyp(H) :=
unfold ltac_something in H.
Tactic Notation "show_def" "in" "*" :=
unfold ltac_something in ×.
unfold ltac_something.
Tactic Notation "show_def" "in" hyp(H) :=
unfold ltac_something in H.
Tactic Notation "show_def" "in" "*" :=
unfold ltac_something in ×.
hide_defs 与 show_defs 作用于所有定义
Tactic Notation "hide_defs" :=
repeat match goal with H := ?T ⊢ _ ⇒
match T with
| @ltac_something _ _ ⇒ fail 1
| _ ⇒ change T with (@ltac_something _ T) in H
end
end.
Tactic Notation "show_defs" :=
repeat match goal with H := (@ltac_something _ ?T) ⊢ _ ⇒
change (@ltac_something _ T) with T in H end.
repeat match goal with H := ?T ⊢ _ ⇒
match T with
| @ltac_something _ _ ⇒ fail 1
| _ ⇒ change T with (@ltac_something _ T) in H
end
end.
Tactic Notation "show_defs" :=
repeat match goal with H := (@ltac_something _ ?T) ⊢ _ ⇒
change (@ltac_something _ T) with T in H end.
hide_hyp H 用记法 Something 替换 H 的类型,
而 show_hyp H 揭示该假设的类型。
注意 H 被隐藏的类型仍与 H 的真实类型可转换。
Tactic Notation "show_hyp" hyp(H) :=
apply ltac_something_show in H.
Tactic Notation "hide_hyp" hyp(H) :=
apply ltac_something_hide in H.
apply ltac_something_show in H.
Tactic Notation "hide_hyp" hyp(H) :=
apply ltac_something_hide in H.
hide_hyps 与 show_hyps 可用于
隐藏/显示所有类型为 Prop 的假设。
Tactic Notation "show_hyps" :=
repeat match goal with
H: @ltac_something _ _ ⊢ _ ⇒ show_hyp H end.
Tactic Notation "hide_hyps" :=
repeat match goal with H: ?T ⊢ _ ⇒
match type of T with
| Prop ⇒
match T with
| @ltac_something _ _ ⇒ fail 2
| _ ⇒ hide_hyp H
end
| _ ⇒ fail 1
end
end.
repeat match goal with
H: @ltac_something _ _ ⊢ _ ⇒ show_hyp H end.
Tactic Notation "hide_hyps" :=
repeat match goal with H: ?T ⊢ _ ⇒
match type of T with
| Prop ⇒
match T with
| @ltac_something _ _ ⇒ fail 2
| _ ⇒ hide_hyp H
end
| _ ⇒ fail 1
end
end.
hide H 与 show H 自动在
hide_hyp 或 hide_def、
show_hyp 或 show_def 之间选择。
类似地,hide_all 与 show_all 作用于全部。
Tactic Notation "hide" hyp(H) :=
first [hide_def H | hide_hyp H].
Tactic Notation "show" hyp(H) :=
first [show_def H | show_hyp H].
Tactic Notation "hide_all" :=
hide_hyps; hide_defs.
Tactic Notation "show_all" :=
unfold ltac_something in ×.
first [hide_def H | hide_hyp H].
Tactic Notation "show" hyp(H) :=
first [show_def H | show_hyp H].
Tactic Notation "hide_all" :=
hide_hyps; hide_defs.
Tactic Notation "show_all" :=
unfold ltac_something in ×.
hide_term E 可用于从目标中隐藏一个项。
show_term 或 show_term E 可用于揭示它。
hide_term E in H 可用于指定假设。
Tactic Notation "hide_term" constr(E) :=
change E with (@ltac_something _ E).
Tactic Notation "show_term" constr(E) :=
change (@ltac_something _ E) with E.
Tactic Notation "show_term" :=
unfold ltac_something.
Tactic Notation "hide_term" constr(E) "in" hyp(H) :=
change E with (@ltac_something _ E) in H.
Tactic Notation "show_term" constr(E) "in" hyp(H) :=
change (@ltac_something _ E) with E in H.
Tactic Notation "show_term" "in" hyp(H) :=
unfold ltac_something in H.
change E with (@ltac_something _ E).
Tactic Notation "show_term" constr(E) :=
change (@ltac_something _ E) with E.
Tactic Notation "show_term" :=
unfold ltac_something.
Tactic Notation "hide_term" constr(E) "in" hyp(H) :=
change E with (@ltac_something _ E) in H.
Tactic Notation "show_term" constr(E) "in" hyp(H) :=
change (@ltac_something _ E) with E in H.
Tactic Notation "show_term" "in" hyp(H) :=
unfold ltac_something in H.
show_unfold R 展开 R 的定义
并揭示被隐藏的 R 定义。--待办:测试,
并用简单的 unfold 实现
(* --待办:改成 "unfolds" *)
Tactic Notation "show_unfold" constr(R1) :=
unfold R1; show_def.
Tactic Notation "show_unfold" constr(R1) "," constr(R2) :=
unfold R1, R2; show_def.
Tactic Notation "show_unfold" constr(R1) :=
unfold R1; show_def.
Tactic Notation "show_unfold" constr(R1) "," constr(R2) :=
unfold R1, R2; show_def.
Ltac sort_tactic :=
try match goal with H: ?T ⊢ _ ⇒
match type of T with Prop ⇒
generalizes H; (try sort_tactic); intro
end end.
Tactic Notation "sort" :=
sort_tactic.
try match goal with H: ?T ⊢ _ ⇒
match type of T with Prop ⇒
generalizes H; (try sort_tactic); intro
end end.
Tactic Notation "sort" :=
sort_tactic.
Tactic Notation "clears" ident(X1) :=
let rec doit _ :=
match goal with
| H:context[X1] ⊢ _ ⇒ clear H; try (doit tt)
| _ ⇒ clear X1
end in doit tt.
Tactic Notation "clears" ident(X1) ident(X2) :=
clears X1; clears X2.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) :=
clears X1; clears X2; clears X3.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) ident(X4) :=
clears X1; clears X2; clears X3; clears X4.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) ident(X4)
ident(X5) :=
clears X1; clears X2; clears X3; clears X4; clears X5.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) ident(X4)
ident(X5) ident(X6) :=
clears X1; clears X2; clears X3; clears X4; clears X5; clears X6.
let rec doit _ :=
match goal with
| H:context[X1] ⊢ _ ⇒ clear H; try (doit tt)
| _ ⇒ clear X1
end in doit tt.
Tactic Notation "clears" ident(X1) ident(X2) :=
clears X1; clears X2.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) :=
clears X1; clears X2; clears X3.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) ident(X4) :=
clears X1; clears X2; clears X3; clears X4.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) ident(X4)
ident(X5) :=
clears X1; clears X2; clears X3; clears X4; clears X5.
Tactic Notation "clears" ident(X1) ident(X2) ident(X3) ident(X4)
ident(X5) ident(X6) :=
clears X1; clears X2; clears X3; clears X4; clears X5; clears X6.
clears(不带任何实参)清除语境中所有未使用的变量。
换言之,它移除任何既非命题(即类型不是 Prop)
又不出现在其他假设或目标中的变量。
(* --待办:改名为 clears_var?*)
Ltac clears_tactic :=
match goal with H: ?T ⊢ _ ⇒
match type of T with
| Prop ⇒ generalizes H; (try clears_tactic); intro
| ?TT ⇒ clear H; (try clears_tactic)
| ?TT ⇒ generalizes H; (try clears_tactic); intro
end end.
Tactic Notation "clears" :=
clears_tactic.
Ltac clears_tactic :=
match goal with H: ?T ⊢ _ ⇒
match type of T with
| Prop ⇒ generalizes H; (try clears_tactic); intro
| ?TT ⇒ clear H; (try clears_tactic)
| ?TT ⇒ generalizes H; (try clears_tactic); intro
end end.
Tactic Notation "clears" :=
clears_tactic.
clears_all 清除语境中所有可清除的假设。
它只留下目标中提到的假设。
Ltac clears_or_generalizes_all_core :=
repeat match goal with H: _ ⊢ _ ⇒
first [ clear H | generalizes H] end.
Tactic Notation "clears_all" :=
generalize ltac_mark;
clears_or_generalizes_all_core;
intro_until_mark.
repeat match goal with H: _ ⊢ _ ⇒
first [ clear H | generalizes H] end.
Tactic Notation "clears_all" :=
generalize ltac_mark;
clears_or_generalizes_all_core;
intro_until_mark.
clears_but H1 H2 .. HN 清除所有假设,
但留下被提到的以及无法清除的那些。
Ltac clears_but_core cont :=
generalize ltac_mark;
cont tt;
clears_or_generalizes_all_core;
intro_until_mark.
Tactic Notation "clears_but" :=
clears_but_core ltac:(fun _ ⇒ idtac).
Tactic Notation "clears_but" ident(H1) :=
clears_but_core ltac:(fun _ ⇒ gen H1).
Tactic Notation "clears_but" ident(H1) ident(H2) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2).
Tactic Notation "clears_but" ident(H1) ident(H2) ident(H3) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2 H3).
Tactic Notation "clears_but" ident(H1) ident(H2) ident(H3) ident(H4) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2 H3 H4).
Tactic Notation "clears_but" ident(H1) ident(H2) ident(H3) ident(H4) ident(H5) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2 H3 H4 H5).
Lemma demo_clears_all_and_clears_but :
∀ x y:nat, y < 2 → x = x → x ≥ 2 → x < 3 → True.
Proof using.
introv M1 M2 M3. dup 6.
(* clears_all 清除所有假设。 *)
clears_all. auto.
(* clears_but H 清除除 H 以外的全部 *)
clears_but M3. auto.
clears_but y. auto.
clears_but x. auto.
clears_but M2 M3. auto.
clears_but x y. auto.
Qed.
generalize ltac_mark;
cont tt;
clears_or_generalizes_all_core;
intro_until_mark.
Tactic Notation "clears_but" :=
clears_but_core ltac:(fun _ ⇒ idtac).
Tactic Notation "clears_but" ident(H1) :=
clears_but_core ltac:(fun _ ⇒ gen H1).
Tactic Notation "clears_but" ident(H1) ident(H2) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2).
Tactic Notation "clears_but" ident(H1) ident(H2) ident(H3) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2 H3).
Tactic Notation "clears_but" ident(H1) ident(H2) ident(H3) ident(H4) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2 H3 H4).
Tactic Notation "clears_but" ident(H1) ident(H2) ident(H3) ident(H4) ident(H5) :=
clears_but_core ltac:(fun _ ⇒ gen H1 H2 H3 H4 H5).
Lemma demo_clears_all_and_clears_but :
∀ x y:nat, y < 2 → x = x → x ≥ 2 → x < 3 → True.
Proof using.
introv M1 M2 M3. dup 6.
(* clears_all 清除所有假设。 *)
clears_all. auto.
(* clears_but H 清除除 H 以外的全部 *)
clears_but M3. auto.
clears_but y. auto.
clears_but x. auto.
clears_but M2 M3. auto.
clears_but x y. auto.
Qed.
clears_last 清除语境中最后一条假设。
clears_last N 清除语境中最后 N 条假设。
Tactic Notation "clears_last" :=
match goal with H: ?T ⊢ _ ⇒ clear H end.
Ltac clears_last_base N :=
match number_to_nat N with
| 0 ⇒ idtac
| S ?p ⇒ clears_last; clears_last_base p
end.
Tactic Notation "clears_last" constr(N) :=
clears_last_base N.
match goal with H: ?T ⊢ _ ⇒ clear H end.
Ltac clears_last_base N :=
match number_to_nat N with
| 0 ⇒ idtac
| S ?p ⇒ clears_last; clears_last_base p
end.
Tactic Notation "clears_last" constr(N) :=
clears_last_base N.
跳过子目标
Axiom skip_axiom : False.
Ltac skip_with_axiom :=
exfalso; apply skip_axiom.
Tactic Notation "skip" :=
skip_with_axiom.
Ltac skip_with_axiom :=
exfalso; apply skip_axiom.
Tactic Notation "skip" :=
skip_with_axiom.
要在下面定义的策略中用传统 admit 代替 skip,
请取消下面定义的注释,把 skip 绑定到 admit。
(*
Tactic Notation "skip" :=
admit.
*)
Tactic Notation "skip" :=
admit.
*)
demo 类似 admit,但它表明承认是有意为之
Tactic Notation "demo" :=
skip.
skip.
admits H: T 把名为 H、类型为 T 的假设
加入当前语境,盲目假定它为真。
admit: T 是另一种可用语法。
注意 H 可以是引入模式。
Tactic Notation "admits" simple_intropattern(I) ":" constr(T) :=
asserts I: T; [ skip | ].
Tactic Notation "admits" ":" constr(T) :=
let H := fresh "TEMP" in admits H: T.
Tactic Notation "admits" "~" ":" constr(T) :=
admits: T; auto_tilde.
Tactic Notation "admits" "*" ":" constr(T) :=
admits: T; auto_star.
asserts I: T; [ skip | ].
Tactic Notation "admits" ":" constr(T) :=
let H := fresh "TEMP" in admits H: T.
Tactic Notation "admits" "~" ":" constr(T) :=
admits: T; auto_tilde.
Tactic Notation "admits" "*" ":" constr(T) :=
admits: T; auto_star.
admit_cuts T 只是把当前目标替换为 T。
Tactic Notation "admit_cuts" constr(T) :=
cuts: T; [ skip | ].
cuts: T; [ skip | ].
admit_goal H 适用于任何目标。
它只是假定当前目标为真,
该假设命名为「H」。
它便于搭建归纳或余归纳证明。
语法 admit_goal 也被接受。
Tactic Notation "admit_goal" ident(H) :=
match goal with ⊢ ?G ⇒ admits H: G end.
Tactic Notation "admit_goal" :=
let IH := fresh "IH" in admit_goal IH.
match goal with ⊢ ?G ⇒ admits H: G end.
Tactic Notation "admit_goal" :=
let IH := fresh "IH" in admit_goal IH.
当 T 是等式时可应用 admit_rewrite T。
它盲目假定该等式为真,
并在目标中改写它。
Tactic Notation "admit_rewrite" constr(T) :=
let M := fresh "TEMP" in admits M: T; rewrite M; clear M.
let M := fresh "TEMP" in admits M: T; rewrite M; clear M.
admit_rewrite T in H 类似 admit_rewrite,
只是在假设 H 中改写。
Tactic Notation "admit_rewrite" constr(T) "in" hyp(H) :=
let M := fresh "TEMP" in admits M: T; rewrite M in H; clear M.
let M := fresh "TEMP" in admits M: T; rewrite M in H; clear M.
admit_rewrites_all T 类似 admit_rewrite,
只是在各处(目标与所有假设)改写。
Tactic Notation "admit_rewrite_all" constr(T) :=
let M := fresh "TEMP" in admits M: T; rewrite_all M; clear M.
let M := fresh "TEMP" in admits M: T; rewrite_all M; clear M.
forwards_nounfold_admit_sides_then E ltac:(fun K ⇒ ..)
类似 forwards: E,但它以名字 K
把所得项提供给续延,
并用 skip 策略承认 E 的实例化
所产生的任何边条件。
Inductive ltac_goal_to_discard := ltac_goal_to_discard_intro.
Ltac forwards_nounfold_admit_sides_then S cont :=
let MARK := fresh "TEMP" in
generalize ltac_goal_to_discard_intro;
intro MARK;
forwards_nounfold_then S ltac:(fun K ⇒
clear MARK;
cont K);
match goal with
| MARK: ltac_goal_to_discard ⊢ _ ⇒ skip
| _ ⇒ idtac
end.
Ltac forwards_nounfold_admit_sides_then S cont :=
let MARK := fresh "TEMP" in
generalize ltac_goal_to_discard_intro;
intro MARK;
forwards_nounfold_then S ltac:(fun K ⇒
clear MARK;
cont K);
match goal with
| MARK: ltac_goal_to_discard ⊢ _ ⇒ skip
| _ ⇒ idtac
end.
与标准库的兼容
Module LibTacticsCompatibility.
Tactic Notation "apply" "*" constr(H) :=
sapply H; auto_star.
Tactic Notation "subst" "*" :=
subst; auto_star.
End LibTacticsCompatibility.
Open Scope nat_scope.
(* 2026-11-26 15:55 *)
Tactic Notation "apply" "*" constr(H) :=
sapply H; auto_star.
Tactic Notation "subst" "*" :=
subst; auto_star.
End LibTacticsCompatibility.
Open Scope nat_scope.
(* 2026-11-26 15:55 *)
