簡體   English   中英

Coq:如何證明“ a = b-> nat_compare ab =等式”?

[英]Coq: How to prove “a=b -> nat_compare a b = Eq.”?

為了了解Coq的含義,我最終遇到了這樣一種情況,即我基本上需要證明a=b -> nat_compare ab = Eq

我可以通過以下方法輕松開始:

Coq < Theorem foo: forall (a:nat) (b:nat), a=b->nat_compare a b=Eq.
1 subgoal

============================
forall a b : nat, a = b -> nat_compare a b = Eq

foo < intros. rewrite H. destruct b.

這給了我:

2 subgoals
a : nat
H : a = 0
============================
nat_compare 0 0 = Eq

subgoal 2 is:
nat_compare (S b) (S b) = Eq

第一個很簡單:

foo < simpl. reflexivity.

但是下一個目標讓我難過:

1 subgoal

a : nat
b : nat
H : a = S b
============================
nat_compare (S b) (S b) = Eq

我可以

foo < rewrite <- H.

這使:

1 subgoal

a : nat
b : nat
H : a = S b
============================
nat_compare a a = Eq

(我也可以通過simpl到達這一確切點,這似乎更有意義。)

現在,我用筆紙聲稱這是我的歸納證明。

我是否以正確的方式來解決這個問題? 在哪里可以最好地學習如何正確執行此操作?

我能夠證明這一點

Theorem triv : forall a b, a = b -> nat_compare a b = Eq.
  intros; subst; induction b; auto.
Qed.

這里的竅門是讓歸納假設無處不在。 destruct是一種較弱的induction形式,不會為您提供證明所需的歸納假設。

暫無
暫無

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

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