【问题标题】:Proving non-existence of an infinite inductive value in Coq在 Coq 中证明不存在无限归纳值
【发布时间】:2024-01-10 09:02:01
【问题描述】:

假设我有一个非常简单的归纳类型:

Inductive ind : Set :=
    | ind0 : ind
    | ind1 : ind -> ind.

我想证明某些值是不存在的。具体来说,不能有没有充分根据的价值观:~exists i, i = ind1 i

 

我在互联网上四处张望了一下,但一无所获。我能写:

Fixpoint depth (i : ind) : nat :=
    match i with
    | ind0 => 0
    | ind1 i2 => 1 + depth i2
    end.

Goal ~exists i, i = ind1 i.
Proof.
    intro. inversion_clear H.
    remember (depth x) as d.
    induction d.
        rewrite H0 in Heqd; simpl in Heqd. discriminate.
        rewrite H0 in Heqd; simpl in Heqd. injection Heqd. assumption.
Qed.

可行,但看起来真的丑陋且不一般。

【问题讨论】:

    标签: coq proof induction


    【解决方案1】:

    我认为没有一种通用的方法可以证明这些目标。然而,根据我的经验,这似乎不是一个问题。在您的情况下,有一个更简单的证明,使用 congruence 策略:

    Inductive ind : Type :=
    | ind0 : ind
    | ind1 : ind -> ind.
    
    Goal ~exists i, i = ind1 i.
    Proof.
      intros [x Hx]. induction x; congruence.
    Qed.
    

    【讨论】:

    • 完美运行。我今天学到了一些关于intros 的新东西。谢谢!
    【解决方案2】:

    或者,您可以对证明进行编程。

    Definition IsO (n1 : nat) : Prop :=
      match n1 with
      | O   => True
      | S _ => False
      end.
    
    Definition eq_O {n1 : nat} (H1 : O = n1) : IsO n1 :=
      match H1 with
      | eq_refl => I
      end.
    
    Definition O_S_impl {n1 : nat} (H1 : O = S n1) : False := eq_O H1.
    
    Definition S_S_impl {n1 n2 : nat} (H1 : S n1 = S n2) : n1 = n2 :=
      match H1 with
      | eq_refl => eq_refl
      end.
    
    Fixpoint nat_inf'' {n1 : nat} : n1 = S n1 -> False :=
      match n1 with
      | O   => fun H1 => O_S_impl H1
      | S _ => fun H1 => nat_inf'' (S_S_impl H1)
      end.
    
    Definition nat_inf' (H1 : exists n1, n1 = S n1) : False :=
      match H1 with
      | ex_intro _ H2 => nat_inf'' H2
      end.
    
    Definition nat_inf : ~ exists n1, n1 = S n1 := nat_inf'.
    

    【讨论】:

      【解决方案3】:

      我会证明forall n1, n1 = Succ n1 <-> False,并将其放入自动重写数据库中。

      Require Import Coq.Setoids.Setoid.
      
      Lemma L1 : forall P1, (P1 <-> P1) <-> True.
      Proof. tauto. Qed.
      
      Hint Rewrite L1 : LogHints.
      
      Lemma L2 : forall (S1 : Set) (e1 : S1), e1 = e1 <-> True.
      Proof. tauto. Qed.
      
      Hint Rewrite L2 : LogHints.
      
      Lemma L3 : forall n1, O = S n1 <-> False.
      Proof.
      intros. split.
        intros H1. inversion H1.
        tauto.
      Qed.
      
      Lemma L4 : forall n1, S n1 = O <-> False.
      Proof.
      intros. split.
        intros H1. inversion H1.
        tauto.
      Qed.
      
      Lemma L5 : forall n1 n2, S n1 = S n2 <-> n1 = n2.
      Proof.
      intros. split.
        intros H1. inversion H1 as [H2]. tauto.
        intros H1. rewrite H1. tauto.
      Qed.
      
      Hint Rewrite L3 L4 L5 : NatHints.
      
      Lemma L6 : forall n1, n1 = S n1 <-> False.
      Proof.
      induction n1 as [| n1 H1];
        autorewrite with LogHints NatHints;
        tauto.
      Qed.
      
      Lemma L7 : forall n1, S n1 = n1 <-> False.
      Proof.
      induction n1 as [| n1 H1];
        autorewrite with LogHints NatHints;
        tauto.
      Qed.
      
      Hint Rewrite L6 L7 : NatHints.
      

      【讨论】: