简体   繁体   English

重命名Coq中的假设的一部分

[英]renaming part of hypothesis in Coq

After destructing n in my proof, I am stuck at the following: 在证明中破坏n之后,我陷入了以下困境:

1 subgoal
n : nat
X : Type
h : X
t : list X
n' : nat
E : n = S n'
H' : length t = n'
IHl : length t = n -> nth_error t n = None
______________________________________(1/1)
nth_error t n' = None

I want to rewrite using IHl, but that is not possible. 我想使用IHl进行重写,但这是不可能的。 How do I compose IHl and H' to make sense and prove this theorem? 我如何构成IH1和H'才能理解并证明该定理?

I am just trying to elaborate on @Arthur answer. 我只是想详细说明@Arthur的答案。

I was able to reproduce your goal with the following script: 我能够使用以下脚本重现您的目标:

Require Import List.

Lemma toto (n : nat) (X : Type) (l : list nat) : length l = n -> nth_error l n = None.
Proof.
induction l as [ | h t IHl].
case_eq n.
simpl; auto.
simpl; discriminate.
case_eq n.
simpl; discriminate.
intros n' E.
simpl; intros E'; injection E'; clear E'; intros H'.

and I agree that this goal cannot be proved. 我同意这一目标无法得到证明。 Now, if you instead start your proof with the following text (the Proof and induction lines have to be replaced), it will be provable (I checked). 现在,如果您改为使用以下文本(必须替换Proof行和induction行)来开始证明,那么它将是可证明的(我已选中)。

Proof.
revert n.
induction l as [ | h t IHl]; intros n.

The difference is that the induction hypothesis now has the following statement. 不同之处在于归纳假设现在具有以下陈述。

forall n : nat, length t = n -> nth_error t n = None

What happened? 发生了什么? In the first (faulty) variant, you attempt to prove a statement for all lists whose length is equal to a precise n, because n is fixed before you start the proof by induction. 在第一个(故障)变体中,您尝试为长度等于精确n的所有列表证明一条语句,因为在通过归纳开始证明之前, n是固定的。 In the second (correct) variant, you attempt to prove a statement for all lists l , and this statement accepts any n as long as length l = n . 在第二个(正确)的变体,你试图证明声明的所有列表l及本声明接受任何n只要length l = n

In the first variant, n is fixed and the equality length l = n restricts l to be among those that have length precisely n . 在第一个变体中, n是固定的,等式length l = nl限制为长度精确为n那些。 In the second case, l is chosen first, and n is not fixed, but the equality length l = n restricts n to follow the length of l . 在第二种情况下,首先选择l ,并且n不固定,但是等length l = n限制n跟随l的长度。

This is called "loading the induction" because the statement forall n, length l = n -> nth_error ln = None is stronger (it is loaded) than the statement that you attempt to prove in the first variant (just for one specific n ), but surprisingly it is easier to prove. 这称为“加载归纳”,因为语句forall n, length l = n -> nth_error ln = None (已加载)比您尝试在第一个变量中证明的语句(仅针对一个特定的n )要强。 ,但令人惊讶的是,它更容易证明。

You cannot, because your induction hypothesis is not general enough. 您不能,因为归纳假设还不够笼统。 Here is a statement that should be easier to prove: 这是一条更容易证明的声明:

forall (X : Type) (t : list X), nth_error t (length t) = None

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM