[英]How do destruct list in Coq (nil or not nil)
我想在以下兩種情況下破壞我的類型列表對象:
H: lst = nil.
H: lst <> nil
自定義案例分析的一種可能模式是提供自定義案例分析引理,模式如下:
From Coq Require Import List.
Import ListNotations.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Inductive list_spec A : list A -> Type :=
| Nil_case : forall x, x = [] -> list_spec x
| Cons_case : forall x, x <> [] -> list_spec x.
Lemma listP A (l : list A) : list_spec l.
Proof. now case l; constructor. Qed.
Lemma foo A (l : list A) : False.
Proof.
case (listP l); intros x Hx.
然后你會在你的上下文中得到正確的假設。 使用destruct
而不是case
將清除剩余的虛假l
。
請注意, ssreflect
的case
策略包括對這種案例分析引理的特殊支持,您通常會使用case: l / listP.
如果您使用destruct lst as [ | fst_elnt lst_tl] eqn:H
destruct lst as [ | fst_elnt lst_tl] eqn:H
你有兩個目標,在第一個目標中,你確實有你需要的假設。
H : lst = nil
在第二個目標中,你有一個形式的假設
H : lst = fst_elnt :: lst_tl
這不是您對H
期望,它實際上更強。 要獲得帶有預期語句的H
,您可以鍵入如下:
rename H into H'. (* to free the name H *)
assert (H : lst <> nil).
rewrite H'; discriminate.
discriminate
是一種基本策略,它表達了一個數據類型的兩個不同構造函數不能返回相等值的事實。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.