Coq 如何证明偏序归纳谓词的可判定性? 上下文

Coq 如何证明偏序归纳谓词的可判定性? 上下文,coq,proof,deterministic,formal-verification,partial-ordering,Coq,Proof,Deterministic,Formal Verification,Partial Ordering,我试图定义偏序A≤ B≤ C与Coq中的一个关系le,并证明它是可判定的:forall xy,{le xy}+{~le xy} 我通过一个等价的布尔函数leb成功地做到了这一点,但找不到直接证明它的方法(或者对于这个问题leu antisym)。我陷入了如下情况: 1 subgoal H : le C A ______________________________________(1/1) False 问题 我怎样才能证明,leca是一个错误的前提 是否还有其他我应该使用的证明策略 我应该以

我试图定义偏序A≤ B≤ C与Coq中的一个关系
le
,并证明它是可判定的:
forall xy,{le xy}+{~le xy}

我通过一个等价的布尔函数
leb
成功地做到了这一点,但找不到直接证明它的方法(或者对于这个问题
leu antisym
)。我陷入了如下情况:

1 subgoal
H : le C A
______________________________________(1/1)
False
问题
  • 我怎样才能证明,
    leca
    是一个错误的前提
  • 是否还有其他我应该使用的证明策略
  • 我应该以不同的方式定义谓词
    le
  • 最小可执行示例
    需要导入Setoid。
    Ltac inv H:=反转H;清除H;替代品。
    归纳t:Set:=A | B | C。
    Ltac自毁功能:=
    与对手重复比赛进球
    |[x:t |-|]=>自毁x
    结束。
    感应le:t->t->Prop:=
    |勒苏·弗尔:对于所有的x,勒克斯
    |le_trans:forall x y z,le x y->le y z->le x z
    |le_A_B:le A B
    |勒布:勒布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布。
    定义leb(x y:t):布尔:=
    将x,y与
    |A,=>正确
    |_u,C=>真
    |B,B=>true
    |_u,=>false
    结束。
    定理le_iff_leb:对于所有x y,
    le x y leb x y=真。
    证明。
    简介xy。分裂介绍H。
    -诱导H;破坏;简单输入*;相似
    -破坏;eauto使用le;简单输入*;相似
    Qed。
    反对称定理:对于所有的xy,
    LEX y->LEY x->x=y。
    证明。
    简介x y H1 H2。
    重写*中的le_iff_leb。(*如何证明不使用[leb]?*)
    自毁x,y;简单输入*;相似
    Qed。
    定理le_dec:forall xy,{le xy}+{~le xy}。
    简介xy。
    自毁x,y;伊奥托使用了一种新方法。
    -正确申请。
    简介H.(*卡在这里*)
    投资部。
    重写*中的le_iff_leb。
    破坏y;简单输入*;相似
    -正确申请。
    介绍H;库存H.(*同一件事*)
    重写*中的le_iff_leb。
    破坏y;简单输入*;相似
    -正确申请。
    介绍H;库存H.(*同一件事*)
    重写*中的le_iff_leb。
    破坏y;简单输入*;相似
    Qed。
    
    le的问题在于及物性构造函数:在对
    le x y
    的证明进行倒置或归纳时,我们对及物性案例产生的中间点一无所知,这通常会导致证明尝试失败。您可以用关系的另一种(但仍然是归纳的)表征来证明您的结果:

    Require Import Setoid.
    
    Ltac inv H := inversion H; clear H; subst.
    
    Inductive t : Set := A | B | C.
    
    Inductive le : t -> t -> Prop :=
      | le_refl : forall x, le x x
      | le_trans : forall x y z, le x y -> le y z -> le x z
      | le_A_B : le A B
      | le_B_C : le B C .
    
    Inductive le' : t -> t -> Prop :=
      | le'_refl : forall x, le' x x
      | le'_A_B  : le' A B
      | le'_B_C  : le' B C
      | le'_A_C  : le' A C.
    
    Lemma le_le' x y : le x y <-> le' x y.
    Proof.
      split.
      - intros H.
        induction H as [x|x y z xy IHxy yz IHyz| | ]; try now constructor.
        inv IHxy; inv IHyz; constructor.
      - intros H; inv H; eauto using le.
    Qed.
    
    Theorem le_antisym : forall x y,
      le x y -> le y x -> x = y.
    Proof.
      intros x y.
      rewrite 2!le_le'.
      intros []; trivial; intros H; inv H.
    Qed.
    
    Theorem le_dec : forall x y, { le x y } + { ~le x y }.
      intros x y.
      destruct x, y; eauto using le; right; rewrite le_le';
      intros H; inv H.
    Qed.
    

    我也同意亚瑟的解决方案。但让我来演示另一种方法

    首先,我们需要两个支持引理:

    Lemma not_leXA x : x <> A -> ~ le x A.
    Proof. remember A; intros; induction 1; subst; firstorder congruence. Qed.
    
    Lemma not_leCX x : x <> C -> ~ le C x.
    Proof. remember C; intros; induction 1; subst; firstorder congruence. Qed.
    
    请注意,我使用了
    Defined
    而不是
    Qed
    ——现在您可以使用
    leu dec
    进行计算,这通常是使用
    sumbool
    类型的要点

    我还使用了
    abstract
    对评估者隐藏证明条款。例如,假设我定义了一个与
    le_dec
    相同的
    le_dec
    函数,但删除了所有
    abstract
    ,那么我们在尝试计算
    le_dec B a
    /
    le_dec'B a
    时会得到以下结果:

    Compute le_dec B A.
    (* ==> right le_dec_subproof5 *) 
    


    请注意,您可以使用
    关系中的定义来定义订单关系。例如,它包含一个名为
    clos\u refl\u trans
    的自反和传递闭包的定义。结果证明与基于您的定义的证明相似(参见@Anton的答案)

    需要导入关系。
    归纳t:Set:=A | B | C。
    感应le:t->t->Prop:=
    |le_A_B:le A B
    |勒布:勒布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布。
    定义le':=clos\u refl\u trans\ule。
    引理A_极小:对于所有x,xa->~le'xa。
    证明。
    介绍。反面介绍。记住A作为A。诱导反转;替代品。
    -反转H0。
    -矛盾。
    -破坏y;应用IHcontra2+应用IHcontra1;相似
    Qed。
    引理C_极大:对于所有x,xc->~le'cx。
    证明。
    介绍。反面介绍。记住C为C。诱导反转;替代品。
    -反转H0。
    -矛盾。
    -破坏y;应用IHcontra2+应用IHcontra1;相似
    Qed。
    leu反对称引理:对于所有的xy,
    le'x y->le'y x->x=y。
    证明。
    介绍。诱导H。
    -破坏H。
    +在H0中应用_极小值;试着区别对待。矛盾
    +在H0中应用C_极大值;试着区别对待。矛盾
    -自反性。
    -将“乐”折入*。重写IHclos\u refl\u trans1 by(eapply rt\u trans;eassumption)。
    应用IHclos_refl_trans2;(eapply rt_trans;易于消费)。
    Qed。
    
    为什么称之为偏序?有三个元素A | B | C,它们是完全有序的。这是我能得到的最简单的例子,但我正在研究的关系不是完全有序的,所以我不希望有人根据顺序是完全有序的这一事实得出答案。来吧,使用完全相同的
    le'
    @Yves只是在这里和那里做。因此
    le'
    基本上列举了
    leb
    中模式匹配处理的案例?它不导致元素数量为n的情况下出现O(n)吗?我希望通过摆脱leb来避免它。…@authchir是的,它就是这样做的。我认为你无法避免这种增长;如果要泛化
    le
    ,仍然需要至少提及每个构造函数一次。
    Lemma not_leXA x : x <> A -> ~ le x A.
    Proof. remember A; intros; induction 1; subst; firstorder congruence. Qed.
    
    Lemma not_leCX x : x <> C -> ~ le C x.
    Proof. remember C; intros; induction 1; subst; firstorder congruence. Qed.
    
    Definition le_dec x y : { le x y } + { ~le x y }.
    Proof.
      destruct x, y; try (left; abstract constructor).
      - left; abstract (eapply le_trans; constructor).
      - right; abstract now apply not_leXA.
      - right; abstract now apply not_leCX.
      - right; abstract now apply not_leCX.
    Defined.
    
    Compute le_dec B A.
    (* ==> right le_dec_subproof5 *) 
    
    Compute le_dec' B A.
    (* ==> right
         (not_leXA B
            (fun x : B = A =>
             match x in (_ = x0) return (x0 = A -> False) with
             | eq_refl =>
                 fun x0 : B = A =>
                 match
                   match
                     x0 in (_ = x1)
                     return match x1 with
                            | B => True
                            | _ => False
                            end
                   with
                   | eq_refl => I
                   end return False
                 with
                 end
             end eq_refl)) *)
    
    Require Import Relations.
    
    Inductive t : Set := A | B | C.
    
    Inductive le : t -> t -> Prop :=
      | le_A_B : le A B
      | le_B_C : le B C.
    
    Definition le' := clos_refl_trans _ le.
    
    Lemma A_minimal : forall x, x <> A -> ~ le' x A.
    Proof.
      intros. intros contra. remember A as a. induction contra; subst.
      - inversion H0.
      - contradiction.
      - destruct y; apply IHcontra2 + apply IHcontra1; congruence.
    Qed.
    
    Lemma C_maximal : forall x, x <> C -> ~ le' C x.
    Proof.
      intros. intros contra. remember C as c. induction contra; subst.
      - inversion H0.
      - contradiction.
      - destruct y; apply IHcontra2 + apply IHcontra1; congruence.
    Qed.
    
    Lemma le'_antisym : forall x y,
      le' x y -> le' y x -> x = y.
    Proof.
      intros. induction H.
      - destruct H.
        + apply A_minimal in H0; try discriminate. contradiction.
        + apply C_maximal in H0; try discriminate. contradiction.
      - reflexivity.
      - fold le' in *. rewrite IHclos_refl_trans1 by (eapply rt_trans; eassumption).
        apply IHclos_refl_trans2; (eapply rt_trans; eassumption).
    Qed.