如何在Coq的证明中应用不动点定义?

如何在Coq的证明中应用不动点定义?,coq,Coq,我很难理解如何在证明中使用我在Coq中定义的一些东西。我有这个定义和函数片段: Inductive string : Set := | E : string | s : nat -> string -> string. Inductive deduce : Set := |de : string -> string -> deduce. Infix "|=" := de. Inductive Rules : deduce -> Prop := | com

我很难理解如何在证明中使用我在Coq中定义的一些东西。我有这个定义和函数片段:

Inductive string : Set :=
| E  : string
| s  : nat -> string -> string.

Inductive deduce : Set :=
|de : string -> string -> deduce.

Infix "|=" := de. 

Inductive Rules : deduce -> Prop :=
| compress : forall (n   : nat) (A    : string), rule (( s n ( s n A))  |= ( s n A))
 | transitive : forall A B C : string, rule (A |= B) -> rule (B |= C) -> rule (A |= C).

Fixpoint RepString (n m : nat): string:=
match n with  
|0 => E
|S n => s m ( RepString n m)
end.
我需要证明一些看似简单的事情,但我遇到了两个问题:

Lemma LongCompress (C : string)(n : nat): n >=1 -> Rules 
((RepString n 0 ) |= (s 0 E) ).
Proof.
intros.
induction n.
inversion H.
simpl.
apply compress.
所以这里我有一个问题,我得到:

"Unable to unify "Rules (s ?M1805 (s ?M1805 ?M1806) |= s ?M1805 ?M1806)" with 
"Rules (s 0 (RepString n 0) |- s 0 E)".'"
现在,我明白了为什么我会出错,虽然从技术上讲,
RepString n0
s0(s0(s0(…s0e)))是一样的。
我只是找不到让coq知道的方法,我试着用
应用压缩来搞乱
就像10件不同的事情一样,我仍然无法正确处理。我需要像那样“展开”它(当然,
展开
不起作用…)

我没有主意了,我非常感谢你在这方面的任何意见

从现在开始编辑

Inductive Rules : deduce -> Prop :=
| compress : forall (n   : nat) (A    : string), rule (( s n ( s n A))  |= ( s n A))
 | transitive : forall A B C : string, rule (A |= B) -> rule (B |= C) -> rule (A |= C)
 | inspection : forall (n m : nat) (A    : string), m < n -> rule ((s n A) |- (s m A)).

 Definition less (n :nat )  (A B : string) :=  B |= (s n A).
 Lemma oneLess (n m : nat):  rule (less 0 (RepString n 1) (RepString m 1)) <-> n< m.
归纳规则:演绎->道具:=
|压缩:forall(n:nat)(A:string),rule((sn(sna))|=(sna))
|及物性:对于所有的abc:string,规则(A |=B)->规则(B |=C)->规则(A |=C)
|检查:forall(nm:nat)(A:string),mrule((sna)|-(sma))。
定义less(n:nat)(ab:string):=B |=(sna)。
引理oneLess(nm:nat):规则(小于0(RepString n1)(RepString m1))n

我已经概括了安东·特鲁诺夫帮助我证明的引理,但现在我遇到了另一面墙。我想问题可能是从我写定理本身的方式开始的,我会很感激任何想法

我要证明一些更一般的东西:对于任意两个非空的零字符串s=
0000…0
和t=
00…0
,如果
length s>length t
,那么
s|=t
,即

forall n m,
  m <> 0 ->
  n > m -> 
  Rules (RepString n 0 |= RepString m 0).
现在,我们可以很容易地证明我们宣传的一般引理:

Lemma LongCompress_general (n m : nat):
  m <> 0 ->
  n > m -> 
  Rules (RepString n 0 |= RepString m 0).
Proof.
  intros Hm Hn. destruct n.
  - inversion Hn.
  - destruct m.
    + exfalso. now apply Hm.
    + apply LongCompress_helper with (k := n - m - 1). omega.
Qed.
“安东·特鲁诺夫”,谢谢你的回答。我没有写我也有一个传递规则,但我现在添加了它。所以他们的想法是“如果字符串的第一个和第二个元素相同,我可以删除其中一个事件”。以数字表示:
0000 |=000 |=00 |=0
。你能给我一些关于如何正确写出引理的提示吗?我看不出如何修复它:(@“安东·特鲁诺夫”,感谢您更新此内容,它帮助我更好地了解情况,但我有几个问题,特别是关于帮助者的问题。我们为什么需要搜索,它到底在做什么?我尝试过寻找它,但解释对我帮助不大。证据上的+和-做了什么?我从未见过它们,我想了解更多!我的最后一个问题,当我进入
apply(transitive(RepString n 0)
部分时,我发现一个错误,即“n”不在环境中,我觉得我在这里遗漏了一些东西。o再次感谢您的帮助!@Sara(1)
Search
是一个本地命令(它不是一种策略),可以帮助您根据某种模式找到引理(它在当前上下文中搜索,如导入的模块、当前文件的定义等)。在本例中,我想将
sm+0
重写为
sm
,而这正是
Nat.add\u 0\r
所做的(从Coq 8.5开始)。(2)
+
-
*
+
-
**
等称为“项目符号”它们可以帮助你将证明组织成嵌套的子目标。同一级别的子目标必须有相同的项目符号。例如,如果我有
-destruct?
,则嵌套的子目标不能以
-
开头,请参见答案。@Sara(3)您是否有机会删除了
-
项目符号?如果
eauto
策略失败,则可能会发生此故障。如果您忘记添加
提示构造函数规则
@“Anton Trunov”,则
eauto
将失败很抱歉,我之前没有回答,我试图找出答案,但没有成功。我没有删除项目符号,并且添加了提示。我有
错误:错误的项目符号-:当前项目符号-未完成。
就在eauto之后,所以我认为你是对的,缺少了一些东西。
Lemma LongCompress_general (n m : nat):
  m <> 0 ->
  n > m -> 
  Rules (RepString n 0 |= RepString m 0).
Proof.
  intros Hm Hn. destruct n.
  - inversion Hn.
  - destruct m.
    + exfalso. now apply Hm.
    + apply LongCompress_helper with (k := n - m - 1). omega.
Qed.
Lemma LongCompress (n : nat):
  n > 1 -> Rules ( RepString n 0  |= s 0 E ).
Proof.
  intro H. replace (s 0 E) with (RepString 1 0) by easy.
  apply LongCompress_general; auto.
Qed.