在Coq中展开嵌套定义

时间:2016-07-08 09:19:40

标签: typeclass coq

我正在使用Coq中的math-classes库。这个库巧妙地使用类型类来重载符号,比如这个。

(* From math-classes *)
Class Equiv A := equiv : relation A.
Infix "=" := equiv : type_scope.

(* My code *)
Definition MyDataType : Type := ...
Definition MyEquality (x y : MyDataType) : Prop := ...
Instance MyEq_equiv : Equiv MyDataType := MyEquality.

我可以为许多不同的数据类型定义这样的实例,x = y会 通过实例解析机制,我可以理解为xy类型注册的相等性。

然而,在证明中处理这些等式是有点烦人的,因为我必须unfold许多连续的定义:

Lemma MyEquality_refl : forall x : MyDataType, x = x.
Proof.
   intro.
   unfold equiv, MyEq_equiv, MyEquality.
   ...
Qed.

是否有更有效的方法来执行此操作unfold

1 个答案:

答案 0 :(得分:1)

(1)您可以使用自定义策略:

(* unfolds only in the goal *)
Ltac unfold_equiv := unfold equiv, MyEq_equiv, MyEquality.

(* unfolds in the goal and in the context *)
Ltac unfold_equiv_everywhere := unfold equiv, MyEq_equiv, MyEquality in *.

Lemma MyEquality_refl : forall x : MyDataType, x = x.
Proof.
   intro.
   unfold_equiv.    (* or `unfold_equiv_everywhere.` *)
   ...
Qed.

<小时/> (2)您可以使用提示数据库。只需将您的定义Hint Unfold添加到数据库中。

Hint Unfold equiv MyEq_equiv MyEquality.

(* a couple more convenient pseudonyms *)
Ltac unfold_selected := repeat autounfold with *.
Ltac unfold_selected_everywhere := repeat autounfold with * in *.

Lemma MyEquality_refl : forall x : MyDataType, x = x.
Proof.
   intro.
   unfold_selected. (* or just literally `repeat autounfold with *.` *)
   ...
Qed.