![](/img/trans.png)
[英]How to prove (forall x, P x /\ Q x) -> (forall x, P x)
[英]Ltac pattern matching: why does `forall x, ?P x` not match `forall x, x`?
Ltac checkForall H :=
let T := type of H in
match T with
| forall x, ?P x =>
idtac
| _ =>
fail 1 "not a forall"
end.
Example test : (forall x, x) -> True.
Proof.
intros H.
Fail checkForall H. (* not a forall *)
Abort.
我會天真地期待checkForall H
成功,但事實並非如此。
在他的“ 依賴類型認證編程”一書中,Adam Chlipala 討論了依賴類型的模式匹配限制:
問題是統一變量可能不包含本地綁定變量。
這是我在這里看到的行為的原因嗎?
正如larsr所解釋的那樣,模式?P x
只能匹配語法上一個應用程序的術語,這不包括你正在考慮的情況。 但是,Ltac確實為您正在尋找的匹配提供了功能。 正如用戶手冊所說:
對於二階模式匹配問題,還有一個特殊符號:在
@?id id1 …idn
形式的應用模式中,變量id匹配變量id1 …idn
具有(可能)依賴關系的任何復雜表達式並返回形式fun id1 …idn => term
功能術語fun id1 …idn => term
。
因此,我們可以編寫以下證明腳本:
Goal (forall x : Prop, x) -> False.
intros H.
match goal with
| H : forall x : Prop, @?P x |- _ => idtac P
end.
打印(fun x : Prop => x)
。
H的類型是forall x, x
,而不是forall x, P x
。
Ltac checkForall H :=
let T := type of H in
match T with
| forall x, ?P x =>
idtac
| forall x, x =>
idtac "this matches"
| _ =>
fail 1 "not a forall"
end.
Example test : (forall x, x) -> True.
Proof.
intros H.
checkForall H. (* not a forall *)
Abort.
或者匹配你的checkForall
Example test {T} (f:T->Prop) : (forall x, f x) -> True.
Proof.
intros H.
checkForall H.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.