Coq:如何添加有意义的提示?

Coq:如何添加有意义的提示?,coq,Coq,我是Coq的新手,可能做得完全不对。在我看来,我需要在编写人类可读性很好的公理/定理和作为提示有用的公理/定理之间做出选择,因为在人类可读的形式中,它们“隐藏”了太多语法,而自动策略无法使用它们。我想知道是否有什么方法可以同时享受这两个世界 我将给出一个有点详细的例子,否则我恐怕无法表达我的意思 作为一个学习练习,我尝试做小组理论。以下是我的定义: Variable G: Set. Variable op: G -> G -> G. Variable inv: G -> G.

我是Coq的新手,可能做得完全不对。在我看来,我需要在编写人类可读性很好的公理/定理和作为提示有用的公理/定理之间做出选择,因为在人类可读的形式中,它们“隐藏”了太多语法,而自动策略无法使用它们。我想知道是否有什么方法可以同时享受这两个世界

我将给出一个有点详细的例子,否则我恐怕无法表达我的意思

作为一个学习练习,我尝试做小组理论。以下是我的定义:

Variable G: Set.
Variable op: G -> G -> G.
Variable inv: G -> G.
Variable e:G.
Infix "+" := op.
Notation "- x" := (inv x).

Definition identity x := forall a:G, a + x = a /\ x + a = a.

Definition associative_law := forall a b c:G, a + (b + c) = (a + b) + c.
Definition identity_law := identity e.
Definition inverse_law := forall a:G, a + (-a ) = e /\ -a + a = e.
Definition group_laws:= associative_law /\ identity_law /\ inverse_law.
Axiom group_laws_hold: group_laws.
我试图让每件事都让人可读(至少对我来说)。所以说e是同一性的公理“隐藏”在两层抽象的背后:“群体法则”和“同一性”

我也可以直接写下这条公理(好吧,我需要它的一半):

 Axiom identity_law_holds: forall a:G, a + e = a.
现在,让我们以我们的组公理作为提示:

Hint Resolve group_laws_hold.
现在我试着证明一个关于群体的简单陈述——身份是独一无二的:

Theorem identity_is_unique: forall x:G, identity x -> x = e.
Proof.
intros.
transitivity (op x e).
symmetry.
到目前为止,一切顺利。现在我的目标是“x+e=x”。如果我现在这样做

apply group_laws_hold.
这一目标将得到解决。然而,执行“自动”没有任何作用,这可能是因为Coq无法识别“group_laws_hold”与“x+e=x”相关,因为“group_laws_hold”与“x+e=x”的语法不同

但是,如果我添加提示

Hint Resolve identity_law_holds.    
当然,“自动”也会起作用。但如果我稍微把“身份法”改为更一般(更正确)的话

然后“自动”将再次失败


所以我的问题是:有没有一种方法可以修复我的代码,使“auto”可以工作,但提示比我的“Axiom identity\u law\u holds:forall a:G,a+e=a”更一般?

eauto
能够进行一些规范化。
eauto
不能做的是归纳, 因为像
和_ind
这样的归纳原则的结论是如此普遍,所以 将减速到几乎停止。无论如何,
eauto
使用
intros
使用
eapply
之前,通常需要在 介绍任何东西

你必须定义自己的不太一般的预测

Lemma l1 : group_laws -> identity_law.
Proof. intros [? [? ?]]. eauto. Qed.

Lemma l2 : identity_law -> identity e.
Proof. eauto. Qed.

Lemma l3 : forall x, identity x -> forall a, a + x = a.
Proof. intros. einduction H. eauto. Qed.

Lemma l4 : forall x, identity x -> forall a, x + a = a.
Proof. intros. einduction H. eauto. Qed.

Hint Resolve eq_sym eq_trans group_laws_hold l1 l2 l3 l4.

Theorem identity_is_unique: forall x, identity x -> x = e.
Proof. info_eauto 7. Qed.
但是您可以强制
eauto
使用
和_ind

Hint Extern 1 => eapply and_ind.
Hint Extern 1 => eapply and_ind.