[英]Coq destruct with an excluding precondition
我正在用softwarefoundations 書學習 Coq,但被困在歸納章節的最后一個任務 - 練習:5 星,高級(binary_inverse)部分 c。
鑒於接下來的辯護。
Inductive bin : Type :=
| Z
| B0 (n : bin)
| B1 (n : bin).
Fixpoint norm_bin (input :bin): bin :=
match input with
| Z => Z
| B0 Z => Z
| B1 restInput => B1 (norm_bin restInput)
| B0 restInput=> match norm_bin restInput with
| Z => Z
| _ => B0 (norm_bin restInput)
end
end.
我試圖證明
Theorem norm_bin_B0_out :
forall b, norm_bin b <> Z -> norm_bin (B0 b) = B0 (norm_bin b).
我試圖destruct b
,但無法根據條件norm_bin b <> Z
解決b = Z
的情況, b
不能為Z
。 我怎樣才能證明呢? 提前致謝!
感謝下面的回復,我設法以這種方式證明了這一點:
Theorem norm_bin_B0_out :
forall b, norm_bin b <> Z -> norm_bin (B0 b) = B0 (norm_bin b).
Proof.
intros b H.
simpl.
destruct norm_bin eqn:f.
- simpl in H. tauto.
- simpl. destruct b.
{ discriminate. }
{ reflexivity. }
{ reflexivity. }
- destruct b.
{ discriminate. }
{ reflexivity. }
{ reflexivity. }
Qed.
我不知道 norm_bin 可以被破壞。 那是個問題。
當您的假設H
是否定的(例如~A
),但您知道您可以證明被否定的公式(您可以證明A
),那么執行的最佳步驟是case H
,這會導致您的目標確實必須證明A
。
在確認這不是 SF 書中的練習后,我決定再幫助你一些。
在發言的公式norm_bin (B0 b)
可享有由符號執行計算simpl
戰術。 去做。
在此步驟之后,您會看到一個包含 2 個匹配語句的表達式。 其中一個是b
上的 match 語句,另一個是norm_bin b
上的 match 語句。 您的下一步可以是對b
的destruct
,但也可以是對norm_bin
的destruct
norm_bin
。 嘗試兩條路線,但如果您選擇后者,請使用eqn:
destruct
策略的變體。
如果你喜歡,你的下一個步驟是在自毀b
,問題是,你得到一個表達norm_bin
應用(B0 (B0 ...)
使用simpl
與這個公式一個目標會導致過多的計算。您將需要通過使用change
而不是simpl
來馴服這一點,並為自己編寫您認為最適合您需求的中間計算。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.