【问题标题】:IndProp: prove that Prop is not provableIndProp:证明 Prop 不可证明
【发布时间】:2020-07-30 16:31:54
【问题描述】:

任务。

假设我们给 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.

第3个是不可证明的,因为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. ?

【问题讨论】:

    标签: coq logical-foundations


    【解决方案1】:

    您必须在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 策略来极大地减少这个证明,它替换了中间的inversiony 部分。

    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 _ _.
    

    【讨论】:

    • injection prf_l as -> ->. 中的箭头有什么作用?
    • 事先,prf_l : n' :: l' = x :: xsinjection prf_l 会将构造函数上的相等“分开”并在目标周围添加 n' = x -> l' = xs -> _。自动添加as intros 他们。 intros 不仅引入了假设,还可以根据模式破坏它们(例如Goal (nat + nat -> nat). intros [[ | n] | [ | n]].)。如果引入的假设是等式,则模式->(和<-)也可用。它到处重写等式,然后清除额外的假设。 Reference
    【解决方案2】:

    这是一个使用目标泛化技术的简单证明。

    首先,我们证明了一个比我们实际提出的更普遍的属性。

    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.
    

    【讨论】:

    • 请注意,这种概括并没有真正遵循问题中给出的推理,例如它将无法证明,例如not (R2 6 [3;2;1;0;0;0]) 尽管 OP 的非正式证明可以正常工作。我对forall x k xs, ~R2 (S (S x) + k) (x :: xs) 的回答中的(几乎)概括确实通过更接近非正式证明来处理它。
    【解决方案3】:

    这相当于@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.
    

    【讨论】:

      【解决方案4】:

      not AA -&gt; False。你应该引入荒谬的假设和案例推理(见倒置策略)。

      【讨论】:

      • 我明白这一点。可以举个例子吗?
      【解决方案5】:

      您可以编写一个函数来从nat 参数(我们称之为gen)生成列表并证明R2 n l -&gt; l = gen n。由此,您可以通过显示 l &lt;&gt; gen n 来证明您的主张。

      【讨论】:

      • 我创建了一个函数,但我不确定它是否正确。你能看一下问题中的更新吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      • 2023-03-14
      相关资源
      最近更新 更多