数理逻辑01 命题逻辑

\(\newcommand{\I}{\mathfrak{I}}\newcommand{\A}{\mathfrak{A}}\)命题逻辑是最简单的逻辑系统。在定义一套形式系统时,我们首先需要定义形式系统允许使用的符号,称为字母表(alphabet),然后定义这些符号之间相互连接的规则,也就是形式系统的语法(syntax)。

命题逻辑的符号

命题逻辑的字母表包括以下内容:

  • 变量符号(variable symbos):一般认为变量应当记为\(v_0,v_1,\cdots\),这里能够用自然数做下标,是因为我们默认命题逻辑能够使用的变量总数是至多可数的(有时为了方便,也可以把变量记为\(x,y,z,\cdots\)\(a,b,c,\cdots\));
  • 连接符号(connectives):非(\(\neg\)),与(\(\land\)),或(\(\lor\));
  • 括号(parentheses):(\((\)),(\()\))。括号用来区分命题中各个部分的优先级;
  • TRUE: 这四个英文字母整体是一个命题逻辑中的符号;
  • FALSE: 这五个英文字母整体是一个命题逻辑中的符号;

命题逻辑的语法

根据命题逻辑的字母表,我们可以把字母表中的字母任意排列连接成字符串,这些字符串可以是任意的,比如\(\land v_0(\neg v_1\)。然而并不是所有可能的组合形式的字符串都会是我们用到的,只有一小部分满足特定规则的字符串才会构成命题逻辑的“语言”,称为命题逻辑中的一个命题(proposition)。这些组合规则就成为命题逻辑的语法。

我们归纳地定义命题:

  • 单个变量\(v_i\)是一个命题;

  • TRUE是一个命题;FALSE是一个命题;

  • 如果\(t_1\)是一个命题,那么\(\neg t_1\)是一个命题,\((t_1)\)是一个命题

  • 如果\(t_1,t_2\)是命题,那么\(t_1\land t_2\)是一个命题,\(t_1\lor t_2\)是一个命题;

这就是命题逻辑的全部语法了。

命题逻辑的语义

即便是符合命题逻辑语法的一个命题逻辑符号串,在没有被赋予语义之前也是没有意义的。“为一个命题赋予语义”就是用元语言(自然语言)对命题逻辑符号串做出解释。例如,如果我们有\((a \land b) \land \text{TRUE}\),我们如何对该符号串用做出解释?

在命题逻辑中,我们只关心命题的唯一一种属性:真或假。我们首先为每个原子变量赋予真或假的属性,然后建立一套规则推导出任何命题的真或假。

设变量符号集合记为\(\Sigma\),那么我们可以定义一个映射\(\beta:\Sigma\to\{true,false\}\),称为\(\Sigma\)上的一个真值指派(truth assignment)。注意,这里小写的\(true,false\)区别于命题逻辑符号中的\(\text{TRUE},\text{FALSE}\):小写的是自然语言,大写的是命题逻辑符号。

基于真值指派\(\beta\),我们可以定义一个从所有命题逻辑命题到\(\{true,false\}\)的映射,称为一个命题逻辑解释(interpretation),记为\(\mathfrak{I}\)。这就定义了基于真值指派\(\beta\)的命题逻辑语义。\(\mathfrak{I}\)的定义规则如下:

  • 如果\(p \in \Sigma\),那么\(\I(p)=\beta(p)\)
  • \(\I(\text{TRUE})=true,\I(\text{FALSE})=false\)
  • \(\varphi\)是满足命题逻辑语法的proposition,那么如果\(\I(\varphi)=true\)\(\I(\neg\varphi)=false\);如果\(\I(\varphi)=false\)\(\I(\neg\varphi)=true\)
  • \(\varphi\)是满足命题逻辑语法的proposition,那么如果\(\I((\varphi))=\I(\varphi)\)
  • \(\varphi,\psi\)是满足命题逻辑语法的proposition,那么\(\varphi\land \psi,\varphi\lor\psi\)的语义通过下面的表格来定义,称为真值表(truth table):
\(\I(\varphi)\) \(\I(\psi)\) \(\I(\varphi \land \psi)\) \(\I(\varphi \lor \psi)\)
\(true\) \(true\) \(true\) \(true\)
\(true\) \(false\) \(false\) \(true\)
\(false\) \(true\) \(false\) \(true\)
\(false\) \(false\) \(false\) \(false\)

永真式,矛盾式,可满足性

有一些命题是特殊的。

有的命题在任何真值指派(解释)下都永远取\(true\),例如\(\text{TRUE}\)\(\text{TRUE}\lor v_0\)\(a \lor \neg a\)等等。我们把这样的命题称为一个永真式(tautology)。定义:命题\(\varphi\)是永真式,如果在任何解释\(\I\)下都有\(\I(\varphi)=true\)

有的命题在任何解释下都永远取\(false\),例如\(\text{FALSE}\)\(\text{FALSE}\land v_0\)等等。我们把这样的命题称为一个矛盾式(contradiction)。定义:命题\(\varphi\)是永真式,如果在任何解释\(\I\)下都有\(\I(\varphi)=false\)

有的命题满足:存在至少一个解释\(\I\)使它取\(true\),例如\(a \land b\),只需取\(\I(a)=\I(b)=true\),就有\(\I(a\land b)=true\)。我们把这样的命题称为是可满足的(satisfiable)。定义:命题\(\varphi\)是可满足的,如果存在一个解释\(\I\)使得\(\I(\varphi)=true\)

Remark: 我们必须区分“语言”和“语言所指向的东西”。命题的语义是由元语言(自然语言)赋予的,并不意味着命题的语义是一串元语言符号。事实上,对每个原子变量赋予真值,然后根据上面这些规则可以推出命题的真值,这一过程是客观、唯一的,并不依赖于自然语言的描述。自然语言只是帮助阅读这篇文章的人理解“语义是什么”,而不是“语义本身”。那么“语义本身”是什么呢?依据维特根斯坦,这是不可言说的,但是我们已经通过语言领会了它。

语义后承&语义等价

有一些“命题对(pair)”之间有特殊的关系。例如,对于任何一个(关于\(a,b\)的)解释\(\I\),只要成立\(\I(a \land b)=true\),就一定成立\(\I(a)=true\)。所以,自然语言通常会说“‘表达式\(a \land b\)为真’能推出‘表达式\(a\)为真’”。我们定义,如果对于两个命题\(\varphi,\psi\),如果对于任何一个解释\(\I\)都成立“只要\(\I(\varphi)=true\),就有\(\I(\psi)=true\)”,就称\(\psi\)\(\varphi\)的语义后承(consequence),记为\(\varphi \models \psi\)

以上定义可以推广。设\(\Phi\)是一个命题集合,\(\psi\)是一个命题。如果对于任何一个解释\(\I\)都成立“只要满足‘所有\(\varphi\in \Phi\)都有\(\I(\varphi)=true\)’,就有‘\(\I(\psi)=true\)’”,就称命题\(\psi\)是命题集合\(\Phi\)的语义后承,用同样的符号记为\(\Phi \models \psi\)

如果\(\psi\)是永真式,那么它可以作为任何命题的语义后承。换言之,即便\(\Phi\)取空集,也有:\(\varnothing \models \psi\)。所以,我们经常用符号“\(\models \varphi\)”来表示\(\varphi\)是永真式。

如果对于两个命题\(\varphi,\psi\),如果对于任何一个解释\(\I\)都成立“\(\I(\varphi)=true\)当且仅当\(\I(\psi)=true\)”,就称\(\varphi,\psi\)是语义等价(equivalent)的。例如,\(v_0\)\(\neg(\neg v_0)\)是语义等价的。在没有歧义的情况下,我们用符号\(\varphi \equiv \psi\)来表示\(\varphi,\psi\)语义等价。

显然,“\(\varphi\equiv \psi\)”成立当且仅当“\(\varphi \models \psi\)\(\psi\models \varphi\)”成立。

Remark1: 永真式、矛盾式、可满足性、语义后承、语义等价,这些都是关于命题本身的性质,而与具体的解释的选取无关。例如,特别要注意,我们讨论的“后承”不是选定某一解释之后的后承关系,而是在任何解释下都成立的后承关系的。

Remark2: 我们如何“证明”两个命题是语义后承关系,或语义等价关系?一如我们如何“证明”一个命题是否是永真式。唯一的判定标准是按照真值指派代入,然后按照语义的规则计算,再依据永真式、语义后承关系、语义等价关系的定义来做判断。一旦真值指派确定,那么一个命题逻辑符号串是否是永真式,两个命题逻辑符号串之间是否是语义后承关系,答案是唯一确定的。我们可以用自然语言写一个“证明”来说明在某一特定解释下,两个命题之间究竟是否满足语义后承关系。当然,这个“证明”只是为了帮助我们揭示答案,而不需要满足任何语法规则(如果愿意的话甚至可以通过非文字的方式,比如说话,或者画图)。

命题逻辑语义的性质

根据命题逻辑语义的定义,我们可以“证明”以下这些重要性质成立:

  1. \(\models \varphi \lor \neg\varphi\);这称为排中律(law of excluded middle)
  2. \(\{\varphi,\psi\}\models \varphi \land \psi\)
  3. \(\varphi\land \psi \models \varphi\)\(\varphi\land \psi \models \psi\)
  4. \(\varphi \models \varphi\lor \psi\)\(\psi \models \varphi \lor \psi\)
  5. \(\varphi\equiv \neg(\neg \varphi)\);这称为双重否定律(law of double negation)
  6. \(\varphi\land \varphi\equiv \varphi\)\(\varphi\lor \varphi\equiv \varphi\);这称为幂等律(idempotant law)
  7. \(\varphi \land \psi \equiv \psi \land \varphi\);这称为与交换律(commutative law for and)
  8. \(\varphi \lor \psi \equiv \psi \lor \varphi\);这称为或交换律(commutative law for or)
  9. \((\varphi \land \psi)\land \chi \equiv \varphi \land (\psi\land \chi)\);这称为与结合律(commutative law for and)
  10. \((\varphi \lor \psi)\lor \chi \equiv \varphi \lor (\psi\lor \chi)\);这称为或结合律(commutative law for and)
  11. \(\varphi \lor (\psi\land \chi) \equiv (\varphi \lor \psi) \land (\varphi\lor \chi)\)\(\varphi \land (\psi\lor \chi) \equiv (\varphi \land \psi) \lor (\varphi\land \chi)\);这称为分配律(distributive laws)
  12. \(\neg(\varphi\land \psi)\equiv (\neg \varphi)\lor (\neg \psi)\)\(\neg(\varphi\lor \psi)\equiv (\neg \varphi)\land (\neg\psi)\);这称为德摩根律(De Morgan's law)
  13. \(\varphi \lor (\varphi \land \psi)\equiv \varphi\)\(\varphi \land (\varphi \lor \psi)\equiv \varphi\);这称为吸收律(absorption laws)
  14. 如果\(\varphi\models \psi\)并且\(\psi \models \chi\),那么\(\varphi \models \chi\);这称为语义后承关系的传递性(transitivity of consequence)
  15. 如果\(\varphi\equiv \psi\)并且\(\psi \equiv \chi\),那么\(\varphi \equiv \chi\);这称为语义等价关系的传递性(transitivity of equivalence)
  16. 如果\(\varphi\equiv \psi\),那么\(\neg\varphi \equiv \neg\psi\);如果\(\varphi_1\equiv \varphi_2\)并且\(\psi_1\equiv \psi_2\),那么\(\varphi_1\land \psi_1\equiv \varphi_2\land \psi_2\);如果\(\varphi_1\equiv \varphi_2\)并且\(\psi_1\equiv \psi_2\),那么\(\varphi_1\lor \psi_1\equiv \varphi_2\lor \psi_2\);这三者分别称为语义等价关系关于非、与、或的合同性(congruence property)
  17. 对于任意命题集合\(\Phi\),如果\(\Phi \cup \{\varphi_1\}\models \psi\)\(\Phi \cup \{\varphi_2\}\models \psi\),那么\(\Phi \cup\{\varphi_1 \lor \varphi_2\}\models \psi\)
  18. 对于任意命题集合\(\Phi\),如果\(\Phi \cup \{\neg\varphi\}\models \psi\),那么\(\Phi \cup\{\neg\psi\}\models \varphi\);特别地,当\(\Phi=\varnothing\)时,我们有\(\neg\varphi \models \psi\)可以推出\(\neg\psi \models \varphi\)。结合双重否定律以及传递性,我们得到\(\neg \varphi \models \psi\)当且仅当\(\neg\psi\models \varphi\)。这称为逆否律(law of contrapositive)

所有以上这些性质都是可以“证明”的。再次提醒,这里所说的“证明”只是对事实的解释说明。下面我们展示一些证明的例子。这些证明中我们也大量运用了假设和推理,但这些假设和推理与命题逻辑中定义的“语义后承”无关。自然语言的假设和推理是建立在我们对“命题逻辑的语义的定义”这一客观对象的共同理解的基础之上的。我们可以把命题逻辑的这些语义性质理解为一些人们发现的自然规律,而证明中的所有假设和推理只是在用“物理定律”(语义的定义)论证为什么存在这些自然规律。

  • 证明排中律\(\models \varphi \lor \neg\varphi\)
    即证对于任何解释\(\I\),都有\(\I(\varphi\lor \neg\varphi)=true\)。分类讨论,若\(\I(\varphi)=true\),那么根据真值表可知\(\I(\varphi \lor \neg\varphi)=true\);若\(\I(\varphi)=false\),那么\(\I(\neg\varphi)=true\),根据真值表可知\(\I(\varphi \lor \neg\varphi)=true\)。证毕。

  • 证明德摩根律\(\neg(\varphi\land \psi)\equiv (\neg \varphi)\lor (\neg \psi)\)
    即证对于任何解释\(\I\),都有\(\I(\neg(\varphi\land \psi))=true\)当且仅当\(\I((\neg \varphi)\lor (\neg \psi))=true\)。左推右,若\(\I(\neg(\varphi\land \psi))=true\),那么\(\I(\varphi\land \psi)=false\),查询真值表可知\(\I(\varphi)\)\(\I(\psi)\)中至少有一个是\(false\)。若\(\I(\varphi)\)为false,那么\(\I(\neg \varphi)=true\),根据真值表可知\(\I((\neg \varphi)\lor (\neg \psi))=true\);若\(\I(\psi)\)为false,那么\(\I(\neg \psi)=true\),根据真值表可知\(\I((\neg \varphi)\lor (\neg \psi))=true\)。右推左,若\(\I((\neg \varphi)\lor (\neg \psi))=true\),那么\(\I(\neg\varphi)\)\(\I(\neg\psi)\)中至少有一个为\(true\),所以\(\I(\varphi)\)\(\I(\psi)\)中至少有一个为\(false\),所以\(\I(\varphi\land \psi)=false\),所以\(\I(\neg(\varphi\land \psi))=true\)

  • 证明逆否律“对于任意命题集合\(\Phi\),如果\(\Phi \cup \{\neg\varphi\}\models \psi\),那么\(\Phi \cup\{\neg\psi\}\models \varphi\)”:
    要证\(\Phi \cup\{\neg\psi\}\models \varphi\),也就是要证对于任何解释\(\I\),如果\(\I(\Phi\cup \{\neg \psi\})=true\)\(\I(\varphi)=true\)。根据\(\I(\Phi\cup \{\neg \psi\})=true\),可知\(\I(\Phi)=true\)(也即对于任意\(\phi \in \Phi\)\(\I(\phi)=true\)),\(\I(\psi)=false\)。现在,如果\(\I(\varphi)=false\),那么\(\I(\neg\varphi)=true\),于是根据\(\Phi \cup \{\neg\varphi\}\models \psi\)可知\(\I(\psi)=true\),矛盾。因此\(\I(\varphi)=true\)。证毕。

我在Lean中形式化验证了所有这些性质:

import Mathlib
namespace PropositionalLogic

inductive PropLogic where
  | Var (i : Nat) : PropLogic
  | TRUE : PropLogic
  | FALSE : PropLogic
  | Not (φ : PropLogic) : PropLogic
  | And (φ ψ : PropLogic) : PropLogic
  | Or (φ ψ : PropLogic) : PropLogic
deriving Repr, DecidableEq

def Assignment := Nat → Bool

def Interp (β : Assignment) (φ : PropLogic) : Bool :=
  match φ with
  | PropLogic.Var i => β i
  | PropLogic.TRUE => true
  | PropLogic.FALSE => false
  | PropLogic.Not ψ => !(Interp β ψ)
  | PropLogic.And ψ τ => (Interp β ψ) && (Interp β τ)
  | PropLogic.Or ψ τ => (Interp β ψ) || (Interp β τ)

def is_tautology (φ : PropLogic) : Prop :=
  ∀ (β : Assignment), Interp β φ = true

def is_contradiction (φ : PropLogic) : Prop :=
  ∀ (β : Assignment), Interp β φ = false

def is_satisfiable (φ : PropLogic) : Prop :=
  ∃ (β : Assignment), Interp β φ = true

example (a : PropLogic) : is_tautology (PropLogic.Or PropLogic.TRUE (PropLogic.Not a)) :=
by
  unfold is_tautology
  intro b
  simp [Interp]

def Consequence (φ ψ : PropLogic) : Prop :=
  ∀ (β : Assignment), Interp β φ = true → Interp β ψ = true

infix:95 " |= " => Consequence

def PropSet := PropLogic → Prop

def Consequence_set (Φ : PropSet) (ψ : PropLogic) : Prop :=
  ∀ (β : Assignment), (∀ (φ : PropLogic), Φ φ → (Interp β φ = true)) → Interp β ψ = true

infix:95 " |== " => Consequence_set

def Equivalent (φ ψ : PropLogic) : Prop :=
  ∀ (β : Assignment), Interp β φ = Interp β ψ

infix:90 " === " => Equivalent

theorem equiv_iff_mutual_consequence (p q : PropLogic) :
  p === q ↔ ((p |= q) ∧ (q |= p)) := by
  apply Iff.intro
  · intro h
    constructor
    · intro β hp
      specialize h β
      rw [←h]
      exact hp
    · intro β hq
      specialize h β
      rw [h]
      exact hq
  · intro h β
    cases h with | intro h1 h2 =>
    specialize h1 β
    specialize h2 β
    cases hp : Interp β p
    case false =>
      cases hq : Interp β q
      case false => rfl
      case true =>
        have : Interp β p = true := h2 hq
        rw [hp] at this
        contradiction
    case true =>
      have : Interp β q = true := h1 hp
      rw [this]

def SetSingleton (p : PropLogic) : PropSet :=
  fun x => x = p

def SetUnion (P Q : PropSet) : PropSet :=
  fun x => P x ∨ Q x

theorem prop_excluded_middle (φ : PropLogic) : is_tautology (PropLogic.Or φ (PropLogic.Not φ)) := by
  simp [is_tautology]
  intro b
  simp [Interp]

theorem prop_intro_and (φ ψ : PropLogic) : (SetUnion (SetSingleton φ) (SetSingleton ψ)) |== (PropLogic.And φ ψ) := by
  simp [Consequence_set, Consequence, SetUnion, SetSingleton]
  intro b h1 h2
  simp [Interp]
  tauto

theorem prop_elim_and1 (φ ψ : PropLogic) : ((PropLogic.And φ ψ) |= φ) := by
  simp [Consequence]
  intro b h1
  simp [Interp] at h1
  tauto

theorem prop_elim_and2 (φ ψ : PropLogic) :((PropLogic.And φ ψ) |= ψ) := by
  simp [Consequence]
  intro b h1
  simp [Interp] at h1
  tauto

theorem prop_intro_or1 (φ ψ : PropLogic) : (φ |= (PropLogic.Or φ ψ)) := by
  simp [Consequence]
  intro b h1
  simp [Interp]
  tauto

theorem prop_intro_or2 (φ ψ : PropLogic) : (ψ |= (PropLogic.Or φ ψ)) := by
  simp [Consequence]
  intro b h1
  simp [Interp]
  tauto

theorem prop_double_neg (φ : PropLogic) : φ === PropLogic.Not (PropLogic.Not φ) := by
  simp [Equivalent]
  intro b
  simp [Interp]

theorem prop_idempotence1 (φ : PropLogic) : ((PropLogic.And φ φ) === φ) := by
  simp [Equivalent]
  intro b
  simp [Interp]

theorem prop_idempotence2 (φ : PropLogic) : ((PropLogic.Or φ φ) === φ) := by
  simp [Equivalent]
  intro b
  simp [Interp]

theorem prop_comm_and (φ ψ : PropLogic) : PropLogic.And φ ψ === PropLogic.And ψ φ := by
  simp [Equivalent]
  intro b
  simp [Interp]
  exact Bool.and_comm _ _

theorem prop_comm_or (φ ψ : PropLogic) : PropLogic.Or φ ψ === PropLogic.Or ψ φ := by
  simp [Equivalent]
  intro b
  simp [Interp]
  exact Bool.or_comm _ _

theorem prop_assoc_and (φ ψ ξ : PropLogic) : PropLogic.And (PropLogic.And φ ψ) ξ === PropLogic.And φ (PropLogic.And ψ ξ) := by
  simp [Equivalent]
  intro b
  simp [Interp]
  exact Bool.and_assoc _ _ _

theorem prop_assoc_or (φ ψ ξ : PropLogic) : PropLogic.Or (PropLogic.Or φ ψ) ξ === PropLogic.Or φ (PropLogic.Or ψ ξ) := by
  simp [Equivalent]
  intro b
  simp [Interp]
  exact Bool.or_assoc _ _ _

theorem prop_distributive1 (φ ψ ξ : PropLogic) : (PropLogic.Or φ (PropLogic.And ψ ξ) === PropLogic.And (PropLogic.Or φ ψ) (PropLogic.Or φ ξ)) := by
  simp [Equivalent]
  intro b
  simp [Interp]
  exact Bool.or_and_distrib_left _ _ _

theorem prop_distributive2 (φ ψ ξ : PropLogic) : (PropLogic.And φ (PropLogic.Or ψ ξ) === PropLogic.Or (PropLogic.And φ ψ) (PropLogic.And φ ξ)) := by
  simp [Equivalent]
  intro b
  simp [Interp]
  exact Bool.and_or_distrib_left _ _ _

theorem prop_de_morgan1 (φ ψ : PropLogic) : (PropLogic.Not (PropLogic.And φ ψ) === PropLogic.Or (PropLogic.Not φ) (PropLogic.Not ψ)) := by
  simp [Equivalent]
  intro b
  simp [Interp]

theorem prop_de_morgan2 (φ ψ : PropLogic) : (PropLogic.Not (PropLogic.Or φ ψ) === PropLogic.And (PropLogic.Not φ) (PropLogic.Not ψ)) := by
  simp [Equivalent]
  intro b
  simp [Interp]

theorem prop_absorption1 (φ ψ : PropLogic) : (PropLogic.Or φ (PropLogic.And φ ψ) === φ) := by
  simp [Equivalent]
  intro b
  simp [Interp]
  intro h1 h2
  exact h1

theorem prop_absorption2 (φ ψ : PropLogic) : (PropLogic.And φ (PropLogic.Or φ ψ) === φ) := by
  simp [Equivalent]
  intro b
  simp [Interp]
  intro h1
  left
  exact h1

theorem prop_trans_consequence (φ ψ ξ : PropLogic) : (φ |= ψ) → (ψ |= ξ) → (φ |= ξ) := by
  simp [Consequence]
  intro h1 h2 b h3
  specialize h1 b h3
  specialize h2 b h1
  exact h2

theorem prop_trans_equivalence (φ ψ ξ : PropLogic) : (φ === ψ) → (ψ === ξ) → (φ === ξ) := by
  simp [Equivalent]
  intro h1 h2 b
  specialize h1 b
  specialize h2 b
  rw [← h2]
  exact h1

theorem prop_congruence_not (φ1 φ2 : PropLogic) : (φ1 === φ2 → PropLogic.Not φ1 === PropLogic.Not φ2) := by
  simp [Equivalent]
  intro h1 b
  specialize h1 b
  simp [Interp]
  exact h1

theorem prop_congruence_and (φ1 φ2 ψ1 ψ2 : PropLogic) : (φ1 === φ2 → ψ1 === ψ2 → PropLogic.And φ1 ψ1 === PropLogic.And φ2 ψ2) := by
  simp [Equivalent]
  intro h1 h2 b
  specialize h1 b
  specialize h2 b
  simp [Interp]
  rw [h1, h2]

theorem prop_congruence_or (φ1 φ2 ψ1 ψ2 : PropLogic) : (φ1 === φ2 → ψ1 === ψ2 → PropLogic.Or φ1 ψ1 === PropLogic.Or φ2 ψ2) := by
  simp [Equivalent]
  intro h1 h2 b
  specialize h1 b
  specialize h2 b
  simp [Interp]
  rw [h1, h2]

theorem prop_or_elim (Φ : PropSet) (φ1 φ2 ψ : PropLogic) : (SetUnion Φ (SetSingleton φ1)) |== ψ → (SetUnion Φ (SetSingleton φ2)) |== ψ → (SetUnion Φ (SetSingleton (PropLogic.Or φ1 φ2))) |== ψ := by
  simp [Consequence_set, SetUnion, SetSingleton]
  intro h1 h2 b h3
  specialize h1 b
  specialize h2 b
  cases hh: (Interp b (PropLogic.Or φ1 φ2))
  · apply h1
    intro p h3
    simp [Interp] at hh
    rcases hh with ⟨h4, h5⟩
    rcases h3 with h6 | h7
    · specialize h3 p
      apply h3
      left
      exact h6
    · specialize h3 (PropLogic.Or φ1 φ2)
      have h8 : (Interp b (φ1.Or φ2) = true) := by
        apply h3
        simp
      simp [Interp] at h8
      rw [h7]
      rcases h8 with h9 | h10
      · rw [h4] at h9
        contradiction
      · rw [h5] at h10
        contradiction
  · simp [Interp] at hh
    rcases hh with phi1true | phi2true
    · apply h1
      intro p h4
      rcases h4 with h5 | h6
      · apply h3
        left
        exact h5
      · rw [← h6] at phi1true
        exact phi1true
    · apply h2
      intro p h4
      rcases h4 with h5 | h6
      · apply h3
        left
        exact h5
      · rw [← h6] at phi2true
        exact phi2true

theorem prop_contrapositive (Φ : PropSet) (φ ψ : PropLogic) : (SetUnion Φ (SetSingleton (PropLogic.Not φ))) |== ψ → (SetUnion Φ (SetSingleton (PropLogic.Not ψ))) |== φ := by
  simp [Consequence_set, SetUnion, SetSingleton]
  intro h1 b h2
  specialize h1 b
  cases hh: (Interp b φ)
  · have h3 : (Interp b ψ = true) := by
      apply h1
      intro p h3
      rcases h3 with h4 | h5
      · specialize h2 p
        apply h2
        left
        exact h4
      · rw [h5]
        simp [Interp]
        assumption
    have h4 : (Interp b (PropLogic.Not ψ) = false) := by
      simp [Interp]
      assumption
    have h5 : (Interp b φ = true) := by
      specialize h2 (ψ.Not)
      have h6 : Interp b ψ.Not = true := by
        apply h2
        right
        rfl
      rw [h4] at h6
      contradiction
    rw [← h5, ← hh]
  · tauto

def EmptySet : PropSet := fun _ => False

theorem prop_contrapositive_corollary (φ ψ : PropLogic) :
  PropLogic.Not φ |= ψ ↔ PropLogic.Not ψ |= φ := by
  apply Iff.intro
  · let h1 := prop_contrapositive EmptySet φ ψ
    simp [Consequence_set, SetUnion, SetSingleton, EmptySet, Interp] at h1
    simp [Consequence]
    intro h2
    intro b h3
    apply h1
    intro b2 h4
    apply h2
    simp [Interp]
    exact h4
    simp [Interp] at h3
    exact h3
  · let h1 := prop_contrapositive EmptySet ψ φ
    simp [Consequence_set, SetUnion, SetSingleton, EmptySet, Interp] at h1
    simp [Consequence]
    intro h2
    intro b h3
    apply h1
    intro b2 h4
    apply h2
    simp [Interp]
    exact h4
    simp [Interp] at h3
    exact h3

end PropositionalLogic

功能完全性

在命题逻辑中, 我们只引入了三个连接词符号\(\neg,\land,\lor\),并给出了它们在真值指派下的语义。那么,重要的问题是:以上三个符号及其语义的定义是否就已经完全够用了呢?是否对于任意有限个变量\(\Sigma=\{v_1,\cdots,v_n\}\),任何真值表\(f:\Sigma\to \{true,false\}\)都能用仅有\(\neg,\land,\lor\)三个连接词构成的命题来表示?这就是命题逻辑中的\(\{\neg,\land,\lor\}\)-功能完全性问题。

我们可以从搜索的角度理解功能完全性这个问题:对于任何一个真值表,我们可以按照长度穷举所有符合语法的命题逻辑命题,检查该命题是否满足真值表。但搜索无法构成一个有效的证明,因为真值表有无穷多个,并且如果找到了一个不存在命题与之对应的真值表,穷举就会无穷进行下去不会停止。所以,我们再次需要通过“证明”的方式来解决功能完全性问题。

析取范式&合取范式

人们注意到一件重要的事:不必关注所有符合语法的命题逻辑命题。有一些命题虽然合法,但存在比它形式更简单的语义等价命题。例如,\(v_0,\neg\neg v_0,\neg\neg\neg\neg v_0\)全是语义等价的,那么我们就不必考虑其它的,只需考虑\(v_0\)这一个命题。换言之,一张真值表会有无穷个与之对应的命题,而我们只需考虑其中形式最“规范”的命题形式。只要我们给出一个“什么叫规范”的定义,我们就提出了一种命题“范式(normal form)”。最著名的范式就是析取范式和合取范式。

析取范式(Disjunctive Normal Forms, DNF)的定义:单个变量符号\(v\)或带有negation的变量符号\(\neg v\)称为一个literal(注意不包含\(\text{TRUE}\)\(\text{FALSE}\));若干literal之间用“\(\land\)”连接而成的命题称为一个合取子句(conjunctive clause);若干个合取子句之间用“\(\lor\)”连接而成的命题称为一个析取范式(disjunctive normal form)。例如,\(a \lor (b \land \neg a \land c)\)就是一个DNF。\((a \lor b)\land (b \lor c)\)\((\neg\neg a \land b)\lor (c \land d)\)等不是DNF。

下面我们证明,任何一个命题都语义等价于某一个析取范式。固定一个命题\(\varphi\),设\(\varphi\)中用到的原子变量记为\(v_1,\cdots,v_n\)\(n\in \mathbb{N}\),任何命题都是有限长的,因此只包含有限多个变量)。我们只需构造一个DNF \(\psi\),使得在\(2^n\)个可能的真值指派所形成的解释\(\I_1,\cdots,\I_{2^n}\)下,始终有\(\I_k(\varphi)=true\)当且仅当\(\I_k(\psi)=true\)。只需这样构造\(\psi\)

\[\bigvee_{k \in [2^n],\I_k(\varphi)=true}\left(\bigwedge_{i\in [n],\I_k(v_i)=true}v_i \land \bigwedge_{i\in [n],\I_k(v_i)=false}\neg v_i\right) \]

可见,若\(\I_s(\varphi)=true\),则\(\I_s\left(\bigwedge\limits_{i\in [n],\I_s(v_i)=true}v_i \land \bigwedge\limits_{i\in [n],\I_s(v_i)=false}\neg v_i\right)=true\),因此\(\I_k(\psi)=true\);若\(\I_s(\psi)=true\),则至少存在一个满足\(\I_k(\varphi)=true\)\(k\)使得\(\I_s\left(\bigwedge\limits_{i\in [n],\I_k(v_i)=true}v_i \land \bigwedge\limits_{i\in [n],\I_k(v_i)=false}\neg v_i\right)=true\),这意味着对于每个\(v_i\)\(\I_k(v_i)=\I_s(v_i)\),所以\(s=k\),所以\(\I_s(\varphi)=true\)。这就说明对于任意\(k \in [2^n]\)\(\I_k(\varphi)=true\)当且仅当\(\I_k(\psi)=true\)。所以\(\varphi\)\(\psi\)语义等价。

我们可以定义和析取范式类似的另一类范式,称为合取范式。同样,把单个变量符号\(v\)或带有negation的变量符号\(\neg v\)称为一个literal;若干literal之间用“\(\lor\)”连接而成的命题称为一个析取子句(disjunctive clause);若干个合取子句之间用“\(\land\)”连接而成的命题称为一个合取范式(conjunctive normal form, CNF)。

我们可以利用我们在析取范式中得到的结果,证明任何一个命题都语义等价于某一个合取范式。固定一个命题\(\varphi\),我们可以构造与其否定命题\(\neg \varphi\)语义等价的析取范式\(\psi = \bigvee\limits_{k \in [2^n],\I_k(\neg\varphi)=true}\left(\bigwedge\limits_{i\in [n],\I_k(v_i)=true}v_i \land \bigwedge\limits_{i\in [n],\I_k(v_i)=false}\neg v_i\right)\)。那么,\(\varphi\)语义等价于\(\neg\psi\),根据De Morgan's law,\(\neg \psi = \bigwedge\limits_{k \in [2^n],\I_k(\neg\varphi)=true}\left(\bigvee\limits_{i\in [n],\I_k(v_i)=true}\neg v_i \lor \bigvee\limits_{i\in [n],\I_k(v_i)=false}v_i\right)\),这恰好是一个合取范式。

\(\{\neg,\land,\lor\}\)-功能完全性

根据我们已经得到的结论——“任何命题都语义等价于某个析取范式”——我们几乎已经证明了\(\{\neg,\land,\lor\}\)-功能完全性了。对于任意一个真值表\(f\),我们只需取函数值为\(true\)的行,依据每一行的内容构造合取子句,再把它们用\(\lor\)连接。

例如,下面这张真值表可以这样构造析取范式:\((a \land b) \lor (\neg a \land b)\lor (\neg a \land \neg b)\)

\(a\) \(b\) \(f\)
\(true\) \(true\) \(true\)
\(true\) \(false\) \(false\)
\(false\) \(true\) \(true\)
\(false\) \(false\) \(true\)

既然任何真值表都能找到一个析取范式与之对应,那么说明任何真值表都能找到一个命题逻辑命题与之对应。所以\(\{\neg,\land,\lor\}\)-功能完全性成立。

\(\{\neg,\land\}\)-功能完全性

事实上,连符号\(\lor\)也是多余的。我们可以证明\(\{\neg,\land\}\)已经具有功能完全性了。我们归纳地证明,对于任意含有符号\(\{\neg,\land,\lor\}\)的命题\(\varphi\),存在一个只含有符号\(\{\neg,\land\}\)的命题\(\varphi'\)满足\(\varphi\equiv \varphi'\)

  • 归纳基础:若\(\varphi\)\(v_i\)\(\text{TRUE},\text{FALSE}\),只需取\(\varphi'\)\(\varphi\)
  • 归纳步骤:
    (1) 假设\(\varphi\equiv \varphi'\)\(\varphi'\)只含有符号\(\{\neg,\land\}\),则根据\(\neg\)的congruency有\(\neg\varphi \equiv \neg \varphi'\),显然\(\neg\varphi'\)只含有符号\(\{\neg,\land\}\)
    (2) 假设\(\varphi\equiv \varphi',\psi\equiv \psi'\),且\(\varphi',\psi'\)只含有符号\(\{\neg,\land\}\),那么根据\(\land\)的congruence有\(\varphi \land \psi \equiv \varphi'\land \psi'\),显然\(\varphi'\land \psi'\)只含有符号\(\{\neg,\land\}\)
    (3) 假设\(\varphi\equiv \varphi',\psi\equiv \psi'\),且\(\varphi',\psi'\)只含有符号\(\{\neg,\land\}\),那么根据\(\lor\)的congruence有\(\varphi \lor \psi \equiv \varphi'\lor \psi'\),又根据De Morgan's Law,\(\varphi'\lor\psi'\equiv\neg(\neg\varphi'\land \neg\psi')\),根据等价的传递性\(\varphi\lor \psi \equiv \neg(\neg\varphi'\land \neg\psi')\),显然\(\neg(\neg\varphi'\land \neg\psi')\)只含有符号\(\{\neg,\land\}\)

注意,以上归纳法不同于自然数集上的归纳法,而是根据命题的结构做pattern match(模式匹配)的分类讨论来归纳的。这样的归纳法称为“结构归纳法(structural induction)”。

同理,可以证明\(\{\neg,\lor\}\)也是功能完全的。

然而,\(\{\land,\lor\}\)不是功能完全的。考虑\(\neg (a\land b)\),当\(a,b\)都为\(true\)时为\(false\),但是任何只包含\(\land,\lor\)的命题在所有变量都为\(true\)时一定为\(true\)

posted @ 2025-07-15 02:45  行而上  阅读(72)  评论(0)    收藏  举报