Stream Coq中一个流的简单证明

Stream Coq中一个流的简单证明,stream,coq,proof,Stream,Coq,Proof,从CPDT获取代码,我想证明easy stream的一个属性,它总是返回1 CoFixpoint ones : Stream Z := Cons 1 ones. 同样在CPDT中,我使用此函数从流中检索列表: Fixpoint approx A (s:Stream A) (n:nat) : list A := match n with | O => nil | S p => match s with | Cons h t => h ::

从CPDT获取代码,我想证明easy stream
的一个属性,它总是返回
1

CoFixpoint ones : Stream Z := Cons 1 ones.
同样在CPDT中,我使用此函数从流中检索列表:

Fixpoint approx A (s:Stream A) (n:nat) : list A :=
    match n with
    | O => nil
    | S p => match s with
        | Cons h t => h :: approx A t p
        end
    end.
要获取五个
1
的列表,例如:

Eval compute in approx Z ones 5.
= 1 :: 1 :: 1 :: 1 :: 1 :: nil
  : list Z
我如何证明,对于给定给
近似值的所有
n
,列表将只包含
1
?我甚至不知道该如何表述。我是否应该对列表使用类似于
nth n list
的帮助函数,该函数从
list
返回元素编号
n
?那

forall (n length : nat), nth n1 (approx Z ones length) = 1
(或者可以使用
Zeq
而不是
=


我的方向正确吗?

我认为,与列表的逐点视图相比,具有更全面的视图将更容易处理。以下是我的想法(证明是0自动化,以确保您看到所有内容):

如果您更喜欢使用更具功能性的
所有定义
,以下是一些等效的定义:

Fixpoint fix_all_ones (l: list Z) : Prop := match l with
  | nil => True
  | 1%Z :: tl => fix_all_ones tl
  | _ => False
end.

Fixpoint fix_bool_all_ones (l: list Z) : bool := match l with
  | nil => true
  | 1%Z :: tl => fix_bool_all_ones tl
  | _ => false
end.

Lemma equiv1 : forall l, all_ones l <-> fix_all_ones l.
Proof.
induction l as [ | hd tl hi]; split; intros h; simpl in *.
- now idtac.
- now constructor.
- destruct hd; simpl in *.
  + now inversion h; subst; clear h.
  + inversion h; subst; clear h. 
    now apply hi.
  + now inversion h; subst; clear h.
- destruct hd; simpl in *.
  + now case h.
  + destruct p; simpl in *.
    * now case h.
    * now case h.
    * constructor; now apply hi.
  + now case h.
Qed.

Lemma equiv2 : forall l, fix_all_ones l <-> fix_bool_all_ones l = true.
Proof.
induction l as [ | hd tl hi]; split; intros h; simpl in *.
- reflexivity.
- now idtac.
- destruct hd; simpl in *.
  + now case h.
  + destruct p; simpl in *.
    * now case h.
    * now case h.
    * now apply hi.
  + now case h.
- destruct hd; simpl in *.
  + discriminate h.
  + destruct p; simpl in *.
    * now case h.
    * now case h.
    * now apply hi.
  + discriminate h. 
Qed.
Fixpoint fix\u all\u one(l:list Z):Prop:=将l与
|nil=>True
|1%Z::tl=>修复所有对象tl
|_uz=>错误
结束。
固定点固定布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔布尔
|nil=>true
|1%Z::tl=>fix\u bool\u all\u one tl
|_uz=>错误
结束。
引理等价1:对于所有的l,所有的l固定所有的l。
证明。
诱导l为[| hd-tl-hi];分裂介绍h;简单输入*。
-现在是idtac。
-现在是构造函数。
-破坏hd;简单输入*。
+现在倒位h;subst;清除h。
+反转h;subst;清除h。
现在申请嗨。
+现在倒位h;subst;清除h。
-破坏hd;简单输入*。
+现在是案例h。
+破坏p;简单输入*。
*现在是案例h。
*现在是案例h。
*建造师;现在申请嗨。
+现在是案例h。
Qed。
引理等价2:对于所有l,fix_all_one l fix_bool_all_one l=true。
证明。
诱导l为[| hd-tl-hi];分裂介绍h;简单输入*。
-自反性。
-现在是idtac。
-破坏hd;简单输入*。
+现在是案例h。
+破坏p;简单输入*。
*现在是案例h。
*现在是案例h。
*现在申请嗨。
+现在是案例h。
-破坏hd;简单输入*。
+辨别h。
+破坏p;简单输入*。
*现在是案例h。
*现在是案例h。
*现在申请嗨。
+辨别h。
Qed。
最好的

Fixpoint fix_all_ones (l: list Z) : Prop := match l with
  | nil => True
  | 1%Z :: tl => fix_all_ones tl
  | _ => False
end.

Fixpoint fix_bool_all_ones (l: list Z) : bool := match l with
  | nil => true
  | 1%Z :: tl => fix_bool_all_ones tl
  | _ => false
end.

Lemma equiv1 : forall l, all_ones l <-> fix_all_ones l.
Proof.
induction l as [ | hd tl hi]; split; intros h; simpl in *.
- now idtac.
- now constructor.
- destruct hd; simpl in *.
  + now inversion h; subst; clear h.
  + inversion h; subst; clear h. 
    now apply hi.
  + now inversion h; subst; clear h.
- destruct hd; simpl in *.
  + now case h.
  + destruct p; simpl in *.
    * now case h.
    * now case h.
    * constructor; now apply hi.
  + now case h.
Qed.

Lemma equiv2 : forall l, fix_all_ones l <-> fix_bool_all_ones l = true.
Proof.
induction l as [ | hd tl hi]; split; intros h; simpl in *.
- reflexivity.
- now idtac.
- destruct hd; simpl in *.
  + now case h.
  + destruct p; simpl in *.
    * now case h.
    * now case h.
    * now apply hi.
  + now case h.
- destruct hd; simpl in *.
  + discriminate h.
  + destruct p; simpl in *.
    * now case h.
    * now case h.
    * now apply hi.
  + discriminate h. 
Qed.