使用Coq中从1开始的归纳法

时间:2019-02-18 17:24:43

标签: coq coq-tactic formal-verification

在Coq证明中,我尝试使用从1开始的归纳法。从this question中,我得到了我需要的归纳原理的证明:

[Note]

我得到的结果在结构上与标准归纳非常相似。实际上,[Name] 【Age】 【City】 【Note】 Chandru,. 29, chennai TN, Contain TN John, 43, Mumbai MH, age >30 George, 35, Madurai TN, Contain TN | age >30 Karthik., 25, Kolkata WB 会产生

Section induction_at_1.
  Variable P : nat -> Prop.
  Hypothesis p1 : P 1.
  Hypothesis pS : forall n, P n -> P (S n).

  Theorem induction_at_1:
    forall n, n > 0 -> P n.

    induction n; intro.
    - exfalso; omega.
    - destruct n.
      + apply p1.
      + assert (S n >= 1) by omega.
        intuition.
  Qed.
End induction_at_1.

Check nat_ind产生

nat_ind:
  forall P : nat -> Prop,
  P 0 ->
  (forall n : nat, P n -> P (S n)) ->
  forall n : nat, P n

当我尝试应用此归纳原理时,就会出现问题。例如,我想通过归纳证明

Check induction_at_1

这似乎完全适合我上面的归纳法,但是当我开始这样的证明时

induction_at_1:
  forall P : nat -> Prop,
  P 1 ->
  (forall n : nat, P n -> P (S n)) ->
  forall n : nat, n > 0 -> P n

我收到以下无法解释的错误:

Lemma cancellation:
  forall a b c: nat, a > 0 -> a * b = a * c -> b = c.

由于这两个归纳原理看起来几乎与我相同,所以我不确定为什么这不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我也发现这种行为令人困惑,但是有几种解决方法。一种是使用称为elim的反射诱导策略:

From Coq Require Import ssreflect.

Lemma cancellation:
  forall a b c: nat, a > 0 -> a * b = a * c -> b = c.
Proof.
intros a b c H.
elim/induction_at_1: a / H.
(* ... *)
Abort.

第二行告诉Coq对H(而不是a)进行归纳,同时推广a并使用归纳原理induction_at_1。我无法使用常规的Coq induction获得类似的工作。

一种替代方法是使用普通自然数归纳法。在这种情况下,我认为引理是在归纳b的同时对c进行归纳(我不确定a的归纳是否有效)。如果确实需要为所有m <= n -> P n显示n形式的内容,则可以将n替换为n - m + mm <= n假设应该可以实现) ),然后通过对P (n - m + m)进行归纳来证明n - m