簡體   English   中英

Coq 的證明#Coq

[英]Coq's proof #Coq

我試圖解決這個證明,但我不知道如何解決。 我有兩個子目標,但我什至不知道它是否正確。

這是我試圖解決的引理,但我被困住了:

Lemma le_Linear : forall a b, (Equal (leB a b) True) \/ (Equal (leB b a) True). 
Proof.
intros.
induction a.
simpl.
induction b.
firstorder.
simpl.
firstorder.
intuition.
apply H.
simpl.

2 個子目標

a,b:自然

H: 相等 (leB ab) 真

______________________________________(1/2)

與 b 相等匹配

| Z => 假

| S m' => leB a m'

結束 (leB ab) / 相等 (leB b (S a)) (leB ab)

______________________________________(2/2)

相等 (leB (S a) b) 真 / 相等 (leB b (S a)) 真

Inductive Bool : Type :=
          True : Bool | False : Bool.

Definition Not(b : Bool) : Bool :=
          Bool_rect (fun a => Bool)
                     False
                     True
                     b.



Lemma classic : forall b : Bool, Equal b (Not (Not b)).
Proof.
intro.
induction b.
simpl.
apply refl.
simpl.
apply refl.
Qed.

Definition Equal(T : Type)(x y : T) : Prop :=
           forall P : T -> Prop, (P x) -> (P y).

Arguments Equal[T].
(* Avec certaines versions Arguments Equal[T] *)

Lemma refl : forall T : Type, forall x : T, Equal x x.
Proof.
intros.
unfold Equal.
intros.
assumption.
Qed.

Fixpoint leB n m : Bool :=
  match n, m with
    | Z, _ => True
    | _, Z => False
    | S n', S m' => leB n' m'
  end.

Lemma Linear : forall a b, (Equal (leB a b) True) \/ (Equal (leB b a) True). 
Proof.

                                                                                       

首先,不要以intros開頭引入所有變量。 你會得到一個太弱的歸納假設。 只介紹a

然后在每個分支中,使用destruct策略考慮b的不同情況。 它將簡化您的目標,您可以查看目標的左側或右側是否正確,並使用您的refl lemma 完成目標。

最后一種情況要求您使用歸納假設,在這里重要的是它適用於所有b ,而不僅僅是一個特定的b

另外,您沒有為您的Nat類型提供定義,我想它是這樣的:

Inductive Nat := Z | S (n:Nat).

這是一個證明。

Lemma Linear : forall a b, (Equal (leB a b) True) \/ (Equal (leB b a) True). 
  Proof.
induction a. 
- intros b. destruct b; simpl.
    + left. apply refl. 
    + left. apply refl.
- intros b. destruct b; simpl.
  + right. apply refl.
  + destruct (IHa b) as [Hleft | Hright].
    ++ left. apply Hleft.
    ++ right. apply Hright.
Qed.

雖然它可能沒有那么有洞察力,但您也可以使用嘗試這些步驟的策略來獲得更短的證明。

induction a; destruct b; firstorder.

也將證明你的引理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM