簡體   English   中英

IndProp:證明 Prop 不可證明

[英]IndProp: prove that Prop is not provable

任務。

假設我們給 Coq 定義如下:

Inductive R2 : nat -> list nat -> Prop :=
| c1 : R2 0 []
| c2 : forall n l, R2 n l -> R2 (S n) (n :: l)
| c3 : forall n l, R2 (S n) l -> R2 n l.

以下哪個命題是可證明的?

我證明了三分之二。

Example Example_R21 : R2 2 [1;0].
Proof.
  apply c2. apply c2. apply c1.
Qed.

Example Example_R22 : R2 1 [1;2;1;0].
Proof.
  repeat constructor.
Qed.

第三個是不可證明的,因為c3只會增加n,永遠不會等於list的頭部+1。但是如何正式證明它是不可證明的呢?

Example Example_R23 : not (R2 6 [3;2;1;0]).
Proof.

Qed.

更新 1

Fixpoint gen (n: nat) : list nat :=
  match n with
  | 0 => []
  | S n' => (n' :: gen n')
  end.

Lemma R2_gen : forall (n : nat) (l : list nat), R2 n l -> l = gen n.
Proof.
  intros n l H. induction H.
  - simpl. reflexivity.
  - simpl. rewrite IHR2. reflexivity.
  - simpl in IHR2. ?

您必須在R2上進行歸納。 基本上,如果你有R2 6 (3:: _) ,那么它必須是c3 (沒有其他構造函數適合),所以它包含一個R2 7 (3:: _) ,它也必須是c3 ,它包含R2 8 (3:: _)等。這條鏈是無限的,所以你永遠不會到達終點。 因此,您可以使用False作為歸納的目標,並且您永遠不會達到實際必須產生False的基本情況。 僅使用inversion是不夠的。 倒置實際上只是所需歸納的一個步驟,而對上下文中任何其他事物的歸納都無濟於事。

在歸納過程中,第一個參數會發生變化。 具體來說,它總是大於S 3 (這就是讓我們排除其他構造函數的原因),所以我們需要對k進行泛化,其中第一個參數總是5 + k (對於我們的情況,從k = 1開始,其中我們有6 )。

Example Example_R23 : not (R2 6 [3;2;1;0]).
Proof.
  set (xs := [2; 1; 0]).
  change 6 with (5 + 1).
  set (x := 3). (* sets are not strictly needed, but help clean things up *)
  generalize 1 as k.
  intros k.
  (* Everything up to here is just generalizing over k *)
  remember (S (S x) + k) as n eqn:prf_n.
  remember (x :: xs) as l eqn:prf_l.
  intros no.
  revert k prf_n prf_l.
  induction no as [ | n' l' _ _ | n' l' _ rec_no]
  ; intros k prf_n prf_l.
  - discriminate.
  - injection prf_l as -> ->.
    discriminate.
  - subst.
    (* Everything up to here is combined inversion and induction *)
    eapply rec_no.
    + apply plus_n_Sm.
    + reflexivity.
Defined.

我們可以通過使用實驗dependent induction策略來極大地減少這個證明,它取代了中間的inversion y 部分。

Example Example_R23 : not (R2 6 [3;2;1;0]).
Proof.
  set (xs := [2; 1; 0]).
  change 6 with (5 + 1).
  set (x := 3).
  generalize 1 as k.
  intros k no.
  dependent induction no generalizing k.
  eapply IHno.
  - apply plus_n_Sm.
  - reflexivity.
Defined.

另一種清理形式是將廣義證明提取到引理中:

Lemma R2_head x k xs : ~R2 (S (S x) + k) (x :: xs).
Proof.
  intros no.
  dependent induction no generalizing k.
  - clear no IHno. (* Another "infinite chain" contradiction *)
    rename x into prf_x, x0 into x.
    induction x as [ | x rec_x].
    + discriminate.
    + injection prf_x.
      apply rec_x.
  - eapply IHno.
    + apply plus_n_Sm.
    + reflexivity.
Defined.
Example Example_R232 : not (R2 6 [3;2;1;0]) := R2_head 3 _ _.

這是一個使用目標泛化技術的簡單證明。

首先,我們證明了一個比我們實際提出的更普遍的性質。

From Coq Require Import Lia.

Lemma R2_len n l : R2 n l -> n <= length l.
Proof. induction 1; simpl; lia. Qed.

現在我們的示例是更一般屬性的簡單具體實例。

Example Example_R23 : not (R2 6 [3;2;1;0]).
Proof. intros H%R2_len; simpl in H; lia. Qed.

這相當於@HTNW 的證明

Lemma R2_head' {a n l}: R2 a (n::l) -> a <= S n.
  intros H; dependent induction H; 
    try pose proof (IHR2 _ _ eq_refl); lia.
Qed.
  
Example Example_R23 : not (R2 6 [3;2;1;0]).
Proof. intros C; pose proof (R2_head' C); lia. Qed.

not AA -> False 你應該通過案例來介紹荒謬的假設和推理(參見倒置策略)。

您可以編寫一個 function 來從nat參數(我們稱之為gen )生成列表並證明R2 nl -> l = gen n 由此,您可以通過證明l <> gen n來證明您的命題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM