Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在coq中使用匹配格和变量等价_Coq - Fatal编程技术网

如何在coq中使用匹配格和变量等价

如何在coq中使用匹配格和变量等价,coq,Coq,我试图使用下面的定理 Theorem nat_rect_1_2: forall (P:nat->Type), (P O -> P 1 -> (forall n:nat, P n -> P (S n) -> P (S (S n))) -> forall n:nat, P n ). Print nat_rect. exact (fun (P : nat -> Type) (f0 : P 0) (f1 : P 1) (ff : forall n :

我试图使用下面的定理

Theorem nat_rect_1_2: forall (P:nat->Type), (P O -> P 1 
  -> (forall n:nat, P n -> P (S n) -> P (S (S n))) -> forall n:nat, P n ).
Print nat_rect.
exact (fun (P : nat -> Type) (f0 : P 0) (f1 : P 1)
  (ff : forall n : nat, P n -> P(S n) -> P (S(S n))) =>
  fix F (n : nat) : P n :=
    match n as n0 return (P n0) with
    | 0 => f0
    | S n' =>  match n' with
       | 0 => f1
       | S n'' => ff n'' (F n'') (F n')
       end
    end).
Qed.

问题是fn'具有类型(pn'),并且位于该位置,但它应该是p(sn')。但是很明显,sn'和n'是一样的,因为我们在这种情况下,但是Coq不能检测到。我该如何解决这个问题呢?

我建议用策略来证明引理,你是不是有意手写证明项

无论如何,我认为你需要帮助Coq处理“护航模式”,这样它可以统一这两个术语。了解更多有关此技术的信息

使用策略编辑校样: 如果我没记错的话,这个证明有一个“窍门”。你不能通过归纳法直接证明它,因为归纳法一次“一”步,你需要两步。诀窍在于首先证明:

Theorem nat_rect_1_2_gen: forall (P:nat->Type), (P O -> P 1 -> 
  (forall n:nat, P n -> P (S n) -> P (S (S n))) -> forall n:nat, (P n) *(P (S n))).
通过对
n
的归纳,然后使用此结果证明您的原始目标。证据将从以下内容开始:

intros P hP0 hP1 hPS. (* introducing basic assumptions *)
induction n as [ | h [hn hSn]]. (* induction on n *)

你应该能够想出如何证明每个子目标。如果你需要更多的帮助,我会提供更多的细节。

事实上,即使是基于战术的证据对我来说也足够了。我个人从来没有能够证明一个新的归纳定理自然数使用战术-这通常是证明定理的基础上,一个特定的归纳定理。但可能是我不知道用elim做这件事的正确方法。@user2833577:我用提示编辑了我的答案,以帮助你通过归纳法证明它。是的,这很有效。谢谢。此外,我还学会了如何使用归纳法来证明两步(或任何一步)归纳法\^^^/