如何在Coq中的证明中应用Fixpoint定义?

时间:2016-06-06 16:33:26

标签: coq

我在理解如何使用我在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 n 0s 0 (s 0 (s 0( ... s 0 E)))相同我只是找不到让coq知道的方法,我'我试过和apply compress with混淆10个不同的东西,我仍然可以做对。我需要"展开"它就像那样(当然unfold不起作用......)。

我没有想法,我非常感谢您对此提出的任何意见!

现在编辑。

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.

我概括了安东·特鲁诺夫帮助我证明的那些引理,但现在我碰到了另一面墙。我认为问题可能从我编写定理本身的方式开始,我会欣赏任何想法。

1 个答案:

答案 0 :(得分:4)

我证明了一些更普遍的东西:对于任何两个非空的零字符串s = 0000...0和t = 00...0,如果length s > length t,那么{ {1}},即

s |= t

这是一个辅助引理:

forall n m,
  m <> 0 ->
  n > m -> 
  Rules (RepString n 0 |= RepString m 0).

现在,我们可以很容易地证明我们广告中的一般引理:

Require Import Coq.Arith.Arith.
Require Import Coq.omega.Omega.
Hint Constructors Rules.  (* add this line after the definition of `Rules` *)

Lemma LongCompress_helper (n m k : nat):
  n = (S m) + k ->
  Rules (RepString (S n) 0 |= RepString (S m) 0).
Proof.
  generalize dependent m.
  generalize dependent n.
  induction k; intros n m H.
  - Search (?X + 0 = ?X). rewrite Nat.add_0_r in H.
    subst. simpl. eauto.
  - apply (transitive _ (RepString n 0) _); simpl in H; rewrite H.
    + simpl. constructor.
    + apply IHk. omega.
Qed.

很容易看出,任何足够长的零字符串都可以压缩成单例字符串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.

0