[英]Propositional Logic and Proofs
This is how you'd prove it in Coq: 这就是您在Coq中证明的方式:
Coq < Theorem curry : forall p q r, ((q /\ p) -> r) -> p -> q -> r.
1 subgoal
============================
forall (p q : Prop) (r : Type), (q /\ p -> r) -> p -> q -> r
First, we name all the premises: 首先,我们命名所有前提:
curry < intros p q r f x y.
1 subgoal
p : Prop
q : Prop
r : Type
f : q /\ p -> r
x : p
y : q
============================
r
The only premise that produces the subgoal r
is f
: 产生子目标r
的唯一前提是f
:
curry < apply f.
1 subgoal
p : Prop
q : Prop
r : Type
f : q /\ p -> r
x : p
y : q
============================
q /\ p
To apply f
we first need to satisfy the subgoals q
and p
: 要应用f
我们首先需要满足子目标q
和p
:
curry < split.
2 subgoals
p : Prop
q : Prop
r : Type
f : q /\ p -> r
x : p
y : q
============================
q
subgoal 2 is:
p
The premise y
is a proof for subgoal q
: 前提y
是子目标q
的证明:
curry < exact y.
1 subgoal
p : Prop
q : Prop
r : Type
f : q /\ p -> r
x : p
y : q
============================
p
The premise x
is a proof of subgoal p
: 前提x
是子目标p
的证明:
curry < exact x.
No more subgoals.
We're done. 大功告成 Here's the full proof: 这是完整的证明:
curry < Qed.
intros p q r f x y.
apply f.
split.
exact y.
exact x.
curry is defined
In function programming languages like Haskell you'd have: 在像Haskell这样的函数编程语言中,您将拥有:
curry :: ((q, p) -> r) -> p -> q -> r
curry f x y = f (y, x)
Everything works out due to the Curry-Howard correspondence . 一切由于Curry-Howard的对应关系而得以解决。
We have a Coq proof thanks to @Aadit, and it would only be fair ---ethical?--- to present an Agda proof. 感谢@Aadit,我们有了Coq证明,提出Agda证明只是公平的-道德?
An immediate and simple proof is 一个直接而简单的证明是
open import Data.Product
portation : {P Q R : Set} → (P × Q → R) → (P → Q → R)
portation P×Q→R = λ p q → P×Q→R (p , q)
Of course this may not at all be clear if the asker is not familiar with Agda and is seeking a formalisation. 当然,如果问询者不熟悉Agda并正在寻求正式化,这可能一点都不清楚。 So let's throw in some detail!! 因此,让我们详细介绍一下!
In constructive logic, propositions can be seen as the small types: 在构造逻辑中,命题可以看作是小的类型:
ℙrop = Set
Then pairing is the usual way to form conjugation, 然后配对是形成共轭的常用方法,
data _∧_ (P Q : ℙrop) : Set where
∧I : P → Q → P ∧ Q
In constructive logic, implication is just function space: to say one thing implies another is tantamount to yielding a procedure that with input of the first kind returns output of the second kind. 在构造逻辑中,蕴涵只是函数空间:说一件事意味着另一件事等于产生一个过程,该过程用第一类输入返回第二类输出。
_⇒_ : (P Q : ℙrop) → Set
_⇒_ = λ P Q → (P → Q)
Implication introduction is then just usual function-definition, and implication elimination is then nothing more than function application. 因此,隐含介绍只是通常的函数定义,而隐含消除则仅是函数应用程序。
⇒I : ∀ {P Q} → (P → Q) → P ⇒ Q
⇒I P→Q = P→Q
⇒E : ∀ {P Q} → P ⇒ Q → P → Q
⇒E P→Q p = P→Q p
Now the asker is using natural-deduction style of proofs, so let us introduce some syntactic sugar to bridge the gap from the paper-and-pencil proof to the Agda formalisation. 现在,问问者使用的是自然演绎风格的证明,因此让我们介绍一些语法糖,以弥合纸笔证明与Agda形式化之间的差距。
syntax ⇒I {P} {Q} (λ p → q) = ⇒-I-assuming-proof p of P we-have Q proved-by q
Now the proof! 现在证明!
shunting : (P Q R : ℙrop) → (P ∧ Q) ⇒ R → P ⇒ (Q ⇒ R)
shunting P Q R P∧Q⇒R =
⇒-I-assuming-proof p of P
we-have Q ⇒ R proved-by
⇒-I-assuming-proof q of Q
we-have R proved-by
⇒E P∧Q⇒R (∧I p q)
Which is not only quite readable, but also somewhat close to the asker's presentation! 这不仅可读性强,而且有点像问问者的介绍!
Agda is such a joy! 阿格达真是太高兴了!
This is a proof using Klement's Fitch-style natural deduction proof checker and the forallx textbook providing explanation. 这是使用Klement的Fitch风格自然演绎证明检查器和forallx教科书提供的证明。 (The links are below.) (链接在下面。)
The main problem with the original attempt is that lines 8 and 9 did not discharge the assumptions. 最初尝试的主要问题是第8行和第9行没有执行这些假设。 They appeared to stay in the same subproofs based on the indents and braces. 根据缩进和花括号,它们似乎保留在相同的子证明中。
Otherwise the proof is the same as what I provided. 否则证明与我提供的证明相同。 On my line 6 I discharged the assumption I made of "Q" on line 3 by introducing the conditional (lines 3-5). 在第6行中,我通过引入条件(第3-5行)来消除了对第3行中的“ Q”所做的假设。 On my line 7 I discharged the assumption "P" made on line 2 by introducing the conditional (lines 2-6). 在我的第7行中,我通过引入条件(第2-6行)消除了第2行中的假设“ P”。
Reference 参考
Kevin Klement's JavaScript/PHP Fitch-style natural deduction proof editor and checker http://proofs.openlogicproject.org/ 凯文·克莱门特(Kevin Klement)的JavaScript / PHP Fitch风格自然演绎证明编辑器和检查器http://proofs.openlogicproject.org/
PD Magnus, Tim Button with additions by J. Robert Loftis remixed and revised by Aaron Thomas-Bolduc, Richard Zach, forallx Calgary Remix: An Introduction to Formal Logic, Winter 2018. http://forallx.openlogicproject.org/ PD马格努斯,蒂姆·巴顿由J.罗伯特Loftis添加混音和亚伦·托马斯,Bolduc,理查德·扎克,forallx卡尔加里混音修订:介绍形式逻辑,2018年冬季http://forallx.openlogicproject.org/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.