Mathematical logic (2) Propositional logic 命题逻辑

本文最后更新于 2024年6月11日 晚上

1. Syntax 语法

1.1 Proposition 命题

A declarative sentence that can be judged as either true or false is called Proposition.

1.1.1 Atomic Proposition 原子命题

The proposition can’t be devided into a smaller one.

Typically symbolized as p,q,r,p, q, r, \dots

1.1.2 Compound Proposition 复合命题

The proposition is built by two or more atomic proposition is called composition proposition.

Typically symbolized as A,B,C,A, B, C, \dots

1.2 Logical Connectives 逻辑连接词

Connectives Meaning Term
\land and conjuction
\lor or disjunction
¬\neg not negation
\to if…then… implication
\leftrightarrow if and only if equivalence

1.3 Alphabet 符号系统

  • Atomic proposition: p,q,r,p, q, r, \dots
  • Logic connectives: ,,¬,,\land,\lor,\neg,\to,\leftrightarrow
  • Punctuations: ( , )

1.4 Expressions 表达式

Finite strings of symbols is called expression.

Empty expression is denoted by λ\lambda.

1.5 Formulas 公式

Definition for Atom(LP)Atom(\mathscr{L}^P): A set of expressions consisting of one symbol only.

Induction definition for Form(LP)Form(\mathscr{L}^P):

  1. Atom(LP)Form(LP)Atom(\mathscr{L}^P) \subseteq Form(\mathscr{L}^P).
  2. If AForm(LP)A \in Form(\mathscr{L}^P), then (¬A)Form(LP)(\neg A) \in Form(\mathscr{L}^P).
  3. If A,BForm(LP)A, B \in Form(\mathscr{L}^P), then (AB),(AB),(AB),(AB)Form(LP)(A \land B), (A \lor B), (A \to B), (A \leftrightarrow B) \in Form(\mathscr{L}^P).

A well-formed formula(WFF) can be and only be derived by this way.

1.5.1 Parse Tree 解析树

A parse tree for Form(LP)Form(\mathscr{L}^P) is a tree satisfying:

  1. The root is the formula.
  2. Leaves are atomic formulas.
  3. Each internal node is formed by applying some formation rule on its children.

e.g. The parse tree for pq¬prp \lor q \to \neg p \land r is:

parse_tree

An expression of LP\mathscr{L}^P is a WFF if and only if there is a parse tree of it.

Each well-formed formula of LP\mathscr{L}^P has a unique parsing tree.

From this, we can verify whether an expression is WFF programmably by building a parse tree for it.This is a sample Python program used to verify the validity of an input formula.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# /usr/bin/env python3
# -*- coding: utf-8 -*-
# python version: 3.10.6

# define a binary tree as the parse tree
class parseTree:

# initialize the a leaf of the parse tree
def __init__(self, char = ''):
self.char = char
self.left = None
self.right = None
self.parent = None
self.flag = False # flag to check if this leaf is valid

# insert a character at the current leaf
def insert(self, char):
self.char = char

# visit the left child of the current leaf
def visit_left_child(self):
if self.left == None:
self.left = parseTree('')
self.left.parent = self
return self.left
# visit the right child of the current leaf
def visit_right_child(self):
if self.right == None:
self.right = parseTree('')
self.right.parent = self
return self.right

# visit the parent of the current leaf
def visit_parent(self):
if self.parent != None:
return self.parent
else:
self.flag = True # if the current leaf is the root, then it is invalid
return self

# build the parse tree from the input string
def build_parse_tree(string):
root = parseTree() # the root of the parse tree
cur = root
alphabet = "abcdefghijklmnopqrstuvwxyz" # the set of all possible atomic propositions

for c in string:
if c == '(':
cur = cur.visit_left_child() # '(' means the a branch of the parse tree is needed
elif c == ')':
cur = cur.visit_parent() # ')' means the current branch of the parse tree is finished
else:
if cur.char == '' and c in alphabet: # if the current leaf is empty and the character is an atomic proposition
cur.char = c
elif c == '¬': # if the character is a negation
cur = cur.visit_parent()
cur.insert(c)
cur = cur.visit_left_child()
elif c == '∧' or c == '∨' or c == '→' or c == '↔': # if the character is a binary connective
cur = cur.visit_parent()
cur.insert(c)
cur = cur.visit_right_child()
elif c == ' ': # if the character is a space, then skip
continue
else:
cur.flag = True # if the character is invalid, then the current leaf is invalid
return root

def check_parse_tree(parse_tree):
if parse_tree.flag:
return False
if parse_tree.char == '':
return False

# check if the parse tree is valid, using preorder traversal method
# A parse tree is of an well-formed formula if and only if all of its leaves are valid and non-empty
if parse_tree.left != None:
if not check_parse_tree(parse_tree.visit_left_child()):
return False
if parse_tree.right != None:
if not check_parse_tree(parse_tree.visit_right_child()):
return False
return True

# Main function
if __name__ == '__main__':
s = input()
parse_tree = build_parse_tree(s)
if check_parse_tree(parse_tree):
print(True)
else:
print(False)

1.5.2 Subformula 子公式

A formula GG is a subformula of FF if GG occurs within FF. Specially we called GG a proper subformula when GFG \neq F.

Immediate formula are the branch of a formula in parse tree, and leading connectives is the connective that is used to join the branch.

1.5.3 Structure 结构

Lemma 11: Well-formed formulas of LP\mathscr{L}^P are non-empty expressions.

Lemma 22 : Every well-formed formula of LP\mathscr{L}^P has an equal number of opening and closing brackets.

Given a non-empty expression u=w1vw2u=w_1vw_2

  • Segment: vv is a segment of uu.
  • Proper Segment: vv is non-empty and vuv \neq u.
  • Prefix (Initial Segment): vv is a prefix of uu if w2=λw_2=\lambda, specially vv is called proper prefix if vuv \neq u.
  • Suffix (Terminal Segment): vv is a suffix of uu if w1=λw_1=\lambdam specially vv is called proper suffix if v¬uv \neg u.

Lemma 33:

  • Every proper prefix of a well-formed formula in LP\mathscr{L}^P has more opening brackets than closing brackets.
  • Similarly, every proper suffix of a well-formed formula in LP\mathscr{L}^P has more closing brackets than opening brackets.

UniqueUnique ReadabilityReadability TheoremTheorem: There is a unique way to construct every well-formed formula.

1.6 Precendence 优先顺序

  • Connectives: ¬,,,,\neg,\land,\lor,\to,\leftrightarrow (Less priority from left to right).
  • Parentheses (with punctuations"()") take the highest precendence.
  • With connectives of the same precedence, the rightmost occurrence have more priority (e.g. pqrp(qr)p \to q \to r \equiv p \to (q \to r) ).

2. Semantics 语义

2.1 Truth Table 真值表

2.2 Truth Valuation 真值指派

A truth valuation is a function v:Atom(LP){0,1}v: Atom(\mathscr{L}^P) \to \{0, 1\}.

For pAtom(LP)p \in Atom(\mathscr{L}^P), we use pvp^v to denote the truth value of pp under the truth valuation v,pv{0,1}v, p^v \in \{0, 1\}

  • Atomic proposition: p{0,1}p \in \{0, 1\}

  • Negation:

(¬A)v={1 if Av=00 else(\neg A)^v=\left\{ \begin{aligned} 1 &\text{ if } A^v = 0 \\ 0 &\text{ else} \\ \end{aligned} \right.

  • Conjuction:

(AB)v={1 if Av=Bv=10 else(A \land B)^v=\left\{ \begin{aligned} 1 &\text{ if } A^v=B^v=1 \\ 0 &\text{ else} \\ \end{aligned} \right.

  • Disjunction:

(AB)v={1 if Av=1 or Bv=10 else(A \lor B)^v=\left\{ \begin{aligned} 1 &\text{ if } A^v=1 \text{ or } B^v=1 \\ 0 &\text{ else} \\ \end{aligned} \right.

  • Implication:

(AB)v={1 if Av=0 or Bv=10 else(A \to B)^v=\left\{ \begin{aligned} 1 &\text{ if } A^v=0 \text{ or }B^v=1 \\ 0 &\text{ else} \\ \end{aligned} \right.

  • Equivalence:

(AB)v={1 if Av=Bv0 else(A \leftrightarrow B)^v=\left\{ \begin{aligned} 1 &\text{ if } A^v=B^v \\ 0 &\text{ else} \\ \end{aligned} \right.

Fix a truth valuation vv. Every formula αForm(LP)\alpha \in Form(\mathscr{L}^P) has a value av{0,1}a^v \in \{0, 1\}.

Proof :

  1. Initial Condition: If αAtom(LP)\alpha \in Atom(\mathscr{L}^P), then there must exist αv{0,1}\alpha^v \in \{0, 1\} (definition).
  2. Inductive Step:
    • If av{0,1}a^v \in \{0, 1\}, then (¬a)v{0,1}(\neg a)^v \in \{0, 1\} according to the truth table.
    • If α,β{0,1}\alpha, \beta \in \{0, 1\}, then (αβ)(\alpha \star \beta) also does for every binary connetives \star.
  3. Conclusion: By this induction, every formula in LP\mathscr{L}^P has a truth value in {0,1}\{0, 1\}; and by the Unique Readablitity Theorem we proved that α\alpha has only one value under a fixed vv.

2.3 Truth Properties of Formulas 公式的性质

Let AForm(LP)A \in Form(\mathscr{L}^P)

  • AA is tautogy(永真式) when v,Av=1\forall v, A^v = 1.
  • AA is contradiction(矛盾式) or unsatisfiable when v,Av=0\forall v, A^v = 0.
  • AA is satisfiable(可满足的) when x,AV=1\exists x, A^V = 1.

2.4 Logic Equivalence 逻辑等价

Formulas A,BA, B are logically equivalent iff v,Av=Bv\forall v, A^v=B^v.

2.4.1 Laws for Logic Equivalence 逻辑等价律

  • Identity laws:
    • pTpp \land T \equiv p
    • pFpp \lor F \equiv p
  • Domination laws:
    • pTTp \lor T \equiv T
    • pFFp \land F \equiv F
  • Idempotent laws:
    • pppp \lor p \equiv p
    • pppp \land p \equiv p
  • Double negation laws:
    • ¬(¬p)p\neg(\neg p) \equiv p
  • Commutative laws:
    • pqqpp \lor q \equiv q \lor p
    • pqqpp \land q \equiv q \land p
  • Associative laws:
    • (pq)rp(qr)(p \lor q) \lor r \equiv p \lor (q \lor r)
    • (pq)rp(qr)(p \land q) \land r \equiv p \land (q \land r)
  • Distributive laws:
    • p(qr)(pq)(pr)p \lor (q \land r) \equiv (p \lor q) \land (p \lor r)
    • p(qr)(pq)(pr)p \land (q \lor r) \equiv (p \land q) \lor (p \land r)
  • De Morgan’s law:
    • ¬(pq)¬p¬q\neg(p \lor q) \equiv \neg p \land \neg q
    • ¬(pq)¬p¬q\neg(p \land q) \equiv \neg p \lor \neg q
  • Absorption laws:
    • p(pq)pp \lor (p \land q) \equiv p
    • p(pq)pp \land (p \lor q) \equiv p
  • Negation laws:
    • p¬pTp \lor \neg p \equiv T
    • p¬pFp \land \neg p \equiv F
  • Implicative laws:
    • pq¬pqp \to q \equiv \neg p \lor q
  • Contrapositive laws:
    • pq¬q¬pp \to q \equiv \neg q \to \neg p
  • Equivalence laws:
    • pq(pq)(qp)p \leftrightarrow q \equiv (p \to q) \land (q \to p)

2.4.2 Substitution 代换

BB is a substitution instance of AA iff B may be obtained from AA by substituting formulas for propositional variables in AA, replacing each occurrence of the same variable by an occurrence of the same formula.

e.g. (pp)(pp)(p \to p) \leftrightarrow (p \to p) is a substitution instance of qqq \leftrightarrow q

Theorem 11: A,B(LP)A, B \in (\mathscr{L}^P). If AA is a tautology and BB is a susbtitution instance of AA, then BB is again a tautology.

Theorem 22: AForm(LP)A \in Form(\mathscr{L}^P). AA contain a subformula CC (i.e., CC is a segment of AA and is itself a well-formed formula). If CDC \equiv D, then replacing some occurrences (not necessarily all) of the subformula CC in AA with DD to obtain the formula BB, then ABA \equiv B.

3. Entailment 蕴涵

Let ΣForm(LP),AForm(LP)\Sigma \subseteq Form(\mathscr{L}^P), A \in Form(\mathscr{L}^P). We say:

  • AA is a logical consequence of Σ\Sigma
  • Σ\Sigma entails AA
  • ΣA\Sigma \models A

Iff for all truth valuation vv if Σv=1\Sigma^v=1 then Av=1A^v=1

Also, Σ⊭A\Sigma \not\models A denotes there exists a truth valuation vv such that Σv=1\Sigma^v=1 and Av=0A^v=0.

3.1 Prove Entailment 蕴涵证明

  • Direct Proof: For every truth valuation under which all of the premises are true, show that the conclusion is also true under this valuation.
  • Using Truth Table: Consider all rows of the truth table in which all of the formulas in Σ\Sigma are true. Verify that AA is true in all of these rows.
  • Proof by Contradiction Assume that the entailment does not hold, which means that there is a truth valuation under which all of the premises are true and the conclusion is false. Derive a contradiction.

4. Proof 形式化证明

A formal proof system (deductive system, 形式推演系统) consists of the language part and the inference part.

  • Language part
    • Symbols and alphbet
    • Set of formulas
  • Inference part
    • Set of axioms(公理)
    • Inference rules

4.1 Notation 记号

ΣA\Sigma \vdash A

denotes that "there is a proof with premises Σ\Sigma and conclusion AA.

4.2 Types 类型

  • Hilbert-Style System (ΣHA\Sigma \vdash_H A)
  • Natural Deduction System (ΣNDA\Sigma \vdash_{ND} A)
  • Resolution (ΣResA\Sigma \vdash_{Res} A)

Mathematical logic (2) Propositional logic 命题逻辑
http://example.com/2024/06/11/mml-2/
作者
Zaddle
发布于
2024年6月11日
更新于
2024年6月11日
许可协议