![](/img/trans.png)
[英]Coq: Defining a function by pattern matching on the arity of its argument
[英]Coq: Ltac for transitivity of implication (a.k.a. hypothetical syllogism)
這個問題是關於我正在做的一個項目,即在 Coq 中編碼Principia Mathematica 。 Principia推導出了推理規則,其中之一是 Syll:
∀ PQR : Prop, P→Q, Q→R : P→R
我正在嘗試創建一個 Ltac 腳本來編寫 Syll 推理形式。 以下來自 ( Chlipala 2019 ) 的 MP 策略非常有效:
Ltac MP H1 H2 :=
match goal with
| [ H1 : ?P -> ?Q, H2 : ?P |- _ ] => specialize (H1 H2)
end.
這里我認為“=>”右邊的策略專門用於H1到H2的應用。 現在相關的 Syll 策略不起作用:
Ltac Syll H1 H2 :=
match goal with
| [ H1 : ?P -> ?Q, H2 : ?Q -> ?R |- _ ] =>
specialize Syll2_06 with ?P ?Q ?R;
intros Syll2_06;
apply Syll2_06;
apply H1;
apply H2
end.
我在應用它時遇到的錯誤(在下面的示例中)是:
沒有匹配的匹配子句。
我不確定為什么這是由此產生的錯誤。 引進經典邏輯,證明為定理Syll2_06,即(P→Q)→((Q→R)→(P→R))。 事實上,基本上是 Syll Ltac 應用於定理 Trans2_16 的證明(見下文)。 所以我不確定為什么將代碼轉換為 Ltac 腳本不起作用。
也許我誤解了 Ltac 比賽正在做什么,以及“=>”右側的策略應該是什么。 但是根據查看Coq 手冊,可能是策略的左側是問題,可能是因為 H1 不適用於 H2。
進一步的建議,特別是解釋 Ltac 和/或我的想法錯誤的建議,將不勝感激。
Theorem Syll2_06 : ∀ P Q R : Prop,
(P → Q) → ((Q → R) → (P → R)).
Ltac Syll H1 H2 :=
match goal with
| [ H1 : ?P -> ?Q, H2 : ?Q -> ?R |- _ ] =>
specialize Syll2_06 with ?P ?Q ?R;
intros Syll2_06;
apply Syll2_06;
apply H1;
apply H2
end.
Ltac MP H1 H2 :=
match goal with
| [ H1 : ?P -> ?Q, H2 : ?P |- _ ] => specialize (H1 H2)
end.
Theorem Trans2_16 : forall P Q : Prop,
(P → Q) → (~Q → ~P).
Proof. intros P Q.
specialize n2_12 with Q. intros n2_12a.
specialize Syll2_05 with P Q (~~Q). intros Syll2_05a.
specialize n2_03 with P (~Q). intros n2_03a.
MP n2_12a Syll2_05a.
specialize Syll2_06 with (P→Q) (P→~~Q) (~Q→~P). intros Syll2_06a.
apply Syll2_06a.
apply Syll2_05a.
apply n2_03a.
Qed.
Theorem Trans2_17 : forall P Q : Prop,
(~Q -> ~P) -> (P -> Q).
Proof. intros P Q.
specialize n2_03 with (~Q) P. intros n2_03a.
specialize n2_14 with Q. intros n2_14a.
specialize Syll2_05 with P (~~Q) Q. intros Syll2_05a.
MP n2_14a Syll2_05a.
Syll 2_03a Syll2_05a.
Qed.
我不確定您希望該策略如何運作。 如果我們這樣開始:
Variables P Q R S : Prop.
Goal (P -> Q) -> (S -> Q) -> (Q -> R) -> P -> R.
intros A B C.
那么目標是:
A : P -> Q
B : S -> Q
C : Q -> R
============================
P -> R
你想讓Syll AC
做什么?
它應該解決目標嗎? 是否應該將C
修改為R
? 它是否應該在上下文中添加一個P -> R
類型的新術語(即名為D
)?
例如,如果您想要一種策略來解決目標,則可以使用apply
:
Ltac Syll H1 H2 :=
match goal with
| [ H1 : ?P -> ?Q, H2 : ?Q -> ?R |- ?P -> ?R ] =>
intros p; apply (H2 (H1 p))
end.
如果你想在上下文中添加一個新術語,你可以用assert
構造它:
Ltac Syll H1 H2 N:=
match goal with
| [ H1 : ?P -> ?Q, H2 : ?Q -> ?R |- ?P -> ?R ] =>
assert (N: P -> R) by (intros p; apply (H2 (H1 p)))
end.
另請注意,如果Syll
不將H1
和H2
作為參數,Coq 將自行找到用於構造證明的假設。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.