gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:09:40 25 4
gpt4 key购买 nike

我很难理解如何在证明中使用我在 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.

我已经概括了 Anton Trunov 帮助我证明的引理,但现在我碰到了另一堵墙。我认为问题可能始于我编写定理本身的方式,我会很感激任何想法。

最佳答案

我会证明一些更一般的东西:对于任何两个非空的零字符串 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).

这是一个辅助引理:

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:

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.

关于coq - 如何在 Coq 的证明中应用 Fixpoint 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37662574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com