简体   繁体   English

IndProp:证明 Prop 不可证明

[英]IndProp: prove that Prop is not provable

The task.任务。

Suppose we give Coq the following definition:假设我们给 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.

Which of the following propositions are provable?以下哪个命题是可证明的?

I proved 2 out of 3.我证明了三分之二。

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.

The 3-rd is not provable, because c3 will only increase n, and it will never be equal to the head of list + 1. But how to formally prove that it is not provable?第三个是不可证明的,因为c3只会增加n,永远不会等于list的头部+1。但是如何正式证明它是不可证明的呢?

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

Qed.

Update 1更新 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. ?

You have to proceed by induction on the R2 .您必须在R2上进行归纳。 Basically, if you have R2 6 (3:: _) , then it must be a c3 (no other constructor fits), so it contains an R2 7 (3:: _) , which must also be c3 , which contains R2 8 (3:: _) , etc. This chain is infinite, so you'll never reach the end.基本上,如果你有R2 6 (3:: _) ,那么它必须是c3 (没有其他构造函数适合),所以它包含一个R2 7 (3:: _) ,它也必须是c3 ,它包含R2 8 (3:: _)等。这条链是无限的,所以你永远不会到达终点。 Therefore, you can use False as the goal of the induction and you will never reach the base case where you actually have to produce False .因此,您可以使用False作为归纳的目标,并且您永远不会达到实际必须产生False的基本情况。 It is not enough to just use inversion .仅使用inversion是不够的。 Inversion is really just one step of the needed induction, and induction on any of the other things in the context doesn't help.倒置实际上只是所需归纳的一个步骤,而对上下文中任何其他事物的归纳都无济于事。

During the induction, the first parameter will vary.在归纳过程中,第一个参数会发生变化。 Specifically, it will always be more than S 3 (that's what lets us rule out the other constructors), so we need to generalize with respect to k where the first parameter is always 5 + k (starting with k = 1 for our case where we have 6 ).具体来说,它总是大于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.

We can reduce this proof immensely by using the experimental dependent induction tactic, which replaces the middle, inversion y part.我们可以通过使用实验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.

Another form of cleanup would be extracting the generalized proof out into a lemma:另一种清理形式是将广义证明提取到引理中:

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

Here is a simple proof that uses the goal generalization technique.这是一个使用目标泛化技术的简单证明。

First, we prove a more general property than we actually are posed with.首先,我们证明了一个比我们实际提出的更普遍的性质。

From Coq Require Import Lia.

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

Now our example is a simple concrete instance of the more general property.现在我们的示例是更一般属性的简单具体实例。

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

This is equivalent to @HTNW's proof这相当于@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 A is A -> False . not AA -> False You should introduce the absurd hypothesis and reason by cases on it (see the inversion tactic).你应该通过案例来介绍荒谬的假设和推理(参见倒置策略)。

You could write a function to generate the list from the nat parameter (let's call it gen ) and prove R2 nl -> l = gen n .您可以编写一个 function 来从nat参数(我们称之为gen )生成列表并证明R2 nl -> l = gen n From that, you can prove your proposition by showing that l <> gen n .由此,您可以通过证明l <> gen n来证明您的命题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 证明 Prop 中的两个居民不相等? - Prove two inhabitants in Prop are not equal? IndProp test_nostutter_4 - IndProp test_nostutter_4 如何证明明显的逻辑-Prop中的list_get问题 - How to prove something obviously logical - list_get problem in Prop IndProp:ev_plus_plus - IndProp: ev_plus_plus IndProp:re_not_empty_correct - IndProp: re_not_empty_correct 如何证明所有人(pq:Prop),〜p-&gt;〜((p-&gt; q)-&gt; p) 使用coq - How to prove forall (p q:Prop), ~p->~((p ->q) ->p). using coq 在 Coq 中如何证明或证伪 `forall (PQ : Prop), (P -&gt; Q) -&gt; (Q -&gt; P) -&gt; P = Q.`? - How or is that possible to prove or falsify `forall (P Q : Prop), (P -> Q) -> (Q -> P) -> P = Q.` in Coq? 如何用给定的假设证明排除中间(forall PQ: Prop, (P -&gt; Q) -&gt; (~P \/ Q))? - How can I prove excluded middle with the given hypothesis (forall P Q : Prop, (P -> Q) -> (~P \/ Q))? 如何证明从典型类型到“Prop”的所有函数 P、Q,“forall a, b, P(a) or Q(b) 成立”当且仅当“forall a, P(a), or, forall b, Q (b),持有”? - How to prove for all functions P, Q from typical type to `Prop`, “forall a, b, P(a) or Q(b) holds” iff “forall a, P(a), or, forall b, Q(b), holds”? 在Coq /直觉逻辑中,这种关系是否可以证明? - Is this relationship between forall and exists provable in Coq/intuitionistic logic?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM