您必须在R2
. 基本上,如果你有R2 6 (3 :: _)
,那么它必须是 a 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 _ _.