Coq 用归纳法证明两个不动点函数

Coq 用归纳法证明两个不动点函数,coq,induction,Coq,Induction,我正在努力解决看似简单的引理,它包含两个不动点定义。以下两个是颜色库中的轴向定义: From Coq Require Import Vector Program. Import VectorNotations. Program Fixpoint Vnth {A:Type} {n} (v : t A n) : forall i, i < n -> A := match v with | nil _ => fun i ip => ! | cons _ x _ v

我正在努力解决看似简单的引理,它包含两个不动点定义。以下两个是颜色库中的轴向定义:

From Coq Require Import Vector Program.
Import VectorNotations.

Program Fixpoint Vnth {A:Type} {n} (v : t A n) : forall i, i < n -> A :=
  match v with
  | nil _ => fun i ip => !
  | cons _ x _ v' => fun i =>
                      match i with
                      | 0 => fun _ => x
                      | S j => fun H => Vnth v' j _
                      end
  end.
Admit Obligations.

Fixpoint Vmap {A B : Type} (f: A -> B) n (v : t A n) : t B n :=
  match v with
  | nil _ => nil _
  | cons _ a _ v' => cons _ (f a) _ (Vmap f _ v')
  end.
来自Coq的
需要导入向量程序。
导入矢量符号。
程序不动点Vnth{A:Type}{n}(v:tan):对于所有i,iA:=
匹配
|无=乐趣i ip=>!
|cons\ux\uv'=>乐趣i=>
匹配
|0=>fun=>x
|S j=>fun H=>Vnth v'j_
结束
结束。
承认义务。
不动点Vmap{ab:Type}(f:A->B)n(v:tan):tbn:=
匹配
|零=零_
|cons uA v'=>cons f(a)v(Vmap f v')
结束。
实际问题是:

Fixpoint Ind (n:nat) {A:Type} (f:A -> A -> A)
         (initial: A) (v: A) {struct n} : t A n
  :=
    match n with
    | O => []
    | S p => cons _ initial _ (Vmap (fun x => f x v) _ (Ind p f initial v))
    end.

Lemma Foo {A: Type} (n : nat) (f : A -> A -> A) (initial v : A)
      (b : nat) (bc : S b < n) (bc1 : b < n)
  : Vnth (Ind n f initial v) _ bc = f (Vnth (Ind n f initial v) _ bc1) v.
Proof.
Qed.
fixpointind(n:nat){A:Type}(f:A->A->A)
(首字母:A)(v:A){struct n}:t A n
:=
匹配
|O=>[]
|S p=>cons uu首字母(Vmap(乐趣x=>f x v)up(Ind p f首字母v))
结束。
引理Foo{A:Type}(n:nat)(f:A->A->A)(首字母v:A)
(b:nat)(bc:sb

通常情况下,我会在
n
上进行归纳,但这不会让我走得更远。我觉得我错过了一些东西。我还在这里尝试了
程序归纳法。

您需要简化Vnth_vmap和广义归纳法来实现这一点:

From Coq Require Import Vector Program.
Import VectorNotations.

Program Fixpoint Vnth {A:Type} {n} (v : t A n) : forall i, i < n -> A :=
  match v with
  | nil _ => fun i ip => !
  | cons _ x _ v' => fun i =>
                  match i with
                  | 0 => fun _ => x
                  | S j => fun H => Vnth v' j _
                  end
  end.
Admit Obligations.

Fixpoint Vmap {A B : Type} (f: A -> B) n (v : t A n) : t B n :=
  match v with
  | nil _ => nil _
  | cons _ a _ v' => cons _ (f a) _ (Vmap f _ v')
  end.

Lemma Vnth_vmap {A B i n p} (v : t A n) f : Vnth (Vmap (B:=B) f n v) i p = f (Vnth v i p).
Proof.
  induction i in n, p, v |- *. destruct v. inversion p.
  simpl. reflexivity.
  destruct v. simpl. bang.
  simpl.
  rewrite IHi. f_equal. f_equal.
  (* Applies proof-irrelevance, might also be directly provable when giving the proofs in Vnth *) pi.
Qed.

Fixpoint Ind (n:nat) {A:Type} (f:A -> A -> A)
     (initial: A) (v: A) {struct n} : t A n
  :=
match n with
| O => []
| S p => cons _ initial _ (Vmap (fun x => f x v) _ (Ind p f initial v))
end.

Lemma Foo {A: Type} (n : nat) (f : A -> A -> A) (initial v : A)
  (b : nat) (bc : S b < n) (bc1 : b < n)
: Vnth (Ind n f initial v) _ bc = f (Vnth (Ind n f initial v) _ bc1) v.
Proof.
induction n in b, bc, bc1 |- *; simpl.
- bang.
- rewrite Vnth_vmap. f_equal.
  destruct b.
  + destruct n. simpl. bang. simpl. reflexivity.
  + rewrite Vnth_vmap. apply IHn.
Qed.
来自Coq的
需要导入向量程序。
导入矢量符号。
程序不动点Vnth{A:Type}{n}(v:tan):对于所有i,iA:=
匹配
|无=乐趣i ip=>!
|cons\ux\uv'=>乐趣i=>
匹配
|0=>fun=>x
|S j=>fun H=>Vnth v'j_
结束
结束。
承认义务。
不动点Vmap{ab:Type}(f:A->B)n(v:tan):tbn:=
匹配
|零=零_
|cons uA v'=>cons f(a)v(Vmap f v')
结束。
引理Vnth_vmap{A B i n p}(v:t A n)f:Vnth(vmap(B:=B)f n v)i p=f(Vnth v i p)。
证明。
n,p,v |-*。破坏。倒置p。
简单。自反性。
破坏。简单。猛敲
简单。
重写IHi。f_等于。f_等于。
(*应用证明无关性,在Vnth*中给出证明时也可以直接证明)pi。
Qed。
不动点Ind(n:nat){A:Type}(f:A->A->A)
(首字母:A)(v:A){struct n}:t A n
:=
匹配
|O=>[]
|S p=>cons uu首字母(Vmap(乐趣x=>f x v)up(Ind p f首字母v))
结束。
引理Foo{A:Type}(n:nat)(f:A->A->A)(首字母v:A)
(b:nat)(bc:sb
谢谢!我学到了一些新东西!(
b、bc、bc1中的诱导n |-*