Ch1 Logic & Proofs

本篇笔记介绍了命题逻辑的基本概念,包括命题、逻辑运算符、条件语句、真值表及其应用等内容。接着,讨论了逻辑等值式、逻辑定律、全功能集和标准式等重要主题。最后,笔记还涵盖了谓词逻辑、嵌套量词、推理准则和证明方法等内容,提供了对逻辑推理和证明的深入理解。(由 gpt-4o-mini 生成摘要)

Word Table

  • 有理数(rational)
  • 反例(counterexample)
  • 前提(premise)

1. 命题逻辑 Propositional Logic

1.1. 命题 Propositions

命题(proposition):A proposition is a declarative sentence that is either true or false, but not both.

  • 悖论(paradox) 不属于命题(e.g. This statement is false. or I'm lying.

命题逻辑(propositional logic):The area of logic that deals with propositions.

命题变量(propositional variable):Small letters such as p,q,r,s,p,q,r,s,\ldots used to present propositions.

真值(truth value):T (true proposition), or F (false proposition)

We call a series of propositions consistent(一致的) if they can possibly be satisfied at the same time.

1.2. 逻辑运算符 Logical Operators

逻辑运算符(logical operator) or 逻辑连接词(logical connective): be used to form compound propositions from existing propositions

Connectives Expression Note
Negation (NOT) ¬p\lnot p
和取 Conjunction (AND) pqp \land q
析取 Disjunction (OR) pqp\lor q
亦或 Exclusive Or (XOR) pqp\oplus q
条件 Conditional (IF-THEN) pqp\rightarrow q
双条件 Biconditional (IF AND ONLY IF) pqp\leftrightarrow q 参见下节介绍
  • 英语中的单词 or 既可以表示 inclusive or 也可以表示 exclusive or(e.g. George was born in 1956 or 1957.),取决于具体语境。

逻辑运算符的优先级(precedence) 如下:

(( and )) ¬\lnot \land \lor \rightarrow \leftrightarrow
0 1 2 3 4 5

1.3. 条件语句 Conditional Statements

推断(implication) or 条件语句(conditional statement)pqp\rightarrow q, false when pp is true and qq is false. pp 为假时推出什么都是真的,pp 为真时必须推出真的才为真。

注意 pp only if qq

只有在 qq 成立的时候 pp 成立,即 ¬q¬p\lnot q \rightarrow \lnot p,实际上等价于 pqp\rightarrow q

More Equivalent Forms

  • If pp, then qq
  • pp implies qq
  • If pp, qq
  • qq if pp
  • qq when pp
  • qq follows from pp
  • qq whenever pp
  • pp is a sufficient condition for qq
  • qq is a necessary condition for pp
  • qq unless ¬p\lnot p

  • 假设(hypothesis = antecedent = premise)pp
  • 结论(conclusion = consequence): qq

对于推断 pqp\rightarrow q 我们可以定义以下条件语句:

  • 逆命题(converse)qpq\rightarrow p
  • 否命题(inverse)¬p¬q\lnot p\rightarrow \lnot q
  • 逆否命题(contrapositive)¬q¬p\lnot q\rightarrow \lnot p

逆否命题与原命题等价

The contrapositive has the same truth values as the original implication.

双条件语句(biconditional statement):The biconditional statement pqp\leftrightarrow q is the propostion “pp if and only if qq.” The biconditonal statemnt

1.4. 真值表 Truth Table

要学会画真值表(truth table)

  • nn 个不同的布尔变量所画的真值表应有 2n2^n 行。

例:nn 个不同的布尔变量可以构成多少个不等价的逻辑表达式?

可以从真值表的角度入手考虑,nn 个布尔变量有 2n2^n 个取值,而这其中的每一个取值在代入逻辑表达式后都可以得到一个 0011,故共有 22n2^{2^n} 种可能,也就是有 22n2^{2^n} 种不同的逻辑表达式。

1.5. 命题逻辑的应用 Applications of Propositional Logic

1.5.1. 翻译句子 Translating Sentences

  • 将英语句子翻译成逻辑表达式,来减少自然语言的不准确(inaccuracy)模糊(ambiguous)

1.5.2. 系统描述 System Specification

可以用于精确地描述系统需求、解决一些逻辑谜题等。

1.5.3. 逻辑谜题 Logical Puzzles

例:宝箱谜题

As a reward for saving his daughter from pirates, the King has given you the opportunity to win a treasure hidden inside one of three trunks. The two trunks that do not hold the treasure are empty. To win, you must select the correct trunk. Trunks 1 and 2 are each inscribed with the message “This trunk is empty,” and Trunk 3 is inscribed with the message “The treasure is in Trunk 2.” The Queen, who never lies, tells you that only one of these inscriptions is true, while the other two are wrong. Which trunk should you select to win?

Answer

2. 逻辑等值式 Propositional Equivalences

2.1. 导论 Introduction

先定义以下基本概念:

  • 永真(tautology):A proposition which is always true. (e.g. p¬pp \lor \lnot p)
  • 永假(contradiction):A proposition which is always false. (e.g. p¬pp \land \lnot p)
  • 可能式(contingency):A proposition which is neither a tautology nor a contradiction. (e.g. pp)

命题 ppqq逻辑等值(logically equivalent) 的,当且仅当命题 pqp\leftrightarrow q 是永真的。可被表示为:pqp\Leftrightarrow qpqp\equiv q

  • 一个复合命题是可满足的(satisfiable):if there is an assignment of truth values to its variables that makes it true. 称这组赋值为该复合命题的解。
  • 一个复合命题是不可满足的(unsatisfiable):when it is false for all assignments of truth values to its variables.

2.2. 逻辑定律 Logical Laws

  • 可以用真值表来证明一些基本的逻辑定律:对于涉及到 nn 个变量的两个命题,画出 2n2^n 种可能的变量取值下的真值表,若两个命题的值都相同则说明这两个命题是逻辑等值的。
Name Expression Note
统一律 Identity Laws pTppFpp\land \text{T}\equiv p \quad\quad p\lor \text{F} \equiv p
零一律 Domination Laws pTTpFFp\lor \text{T}\equiv \text{T}\quad\quad p\land \text{F}\equiv \text{F}
幂等律 Idempotent Laws ppppppp\land p \equiv p \quad\quad p\lor p \equiv p
对合律 Double Negation Law ¬¬pp\lnot \lnot p \equiv p
交换律 Commutative Laws pqqppqqpp\lor q \equiv q \lor p\quad\quad p\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 Laws ¬(pq)¬p¬q\lnot(p\lor q)\equiv \lnot p\land \lnot q
¬(pq)=¬p¬q\lnot(p\land q)=\lnot p\lor\lnot q
重要
否定律 Negation Laws p¬pTp¬pFp\lor \lnot p\equiv \text{T}\quad\quad p\land \lnot p\equiv \text{F}
吸收律 Absorption Laws p(pq)pp(pq)pp\lor (p\land q)\equiv p\quad\quad p\land (p\lor q) \equiv p
逆否律 Contrapositive Law pq¬q¬pp\rightarrow q \equiv \lnot q\rightarrow \lnot p 命题与它的逆否命题等价
导出律 Exportation Law (pq)rp(qr)(p\land q)\rightarrow r\equiv p\rightarrow (q\rightarrow r)
Absurdity Law (pq)(p¬q)¬p(p\rightarrow q)\land (p\rightarrow \lnot q)\equiv \lnot p
蕴含律 Implication Law pq¬pqp\rightarrow q \equiv \lnot p \lor q 用于去掉箭头
Equivalence Law pq(pq)(qp)p\leftrightarrow q\equiv (p\rightarrow q)\land (q\rightarrow p)

2.3. 全功能集 Functionally Complete Collection of Logical Operators

只需要部分运算符就可以表示出所有可能的运算,称这样的一个运算符集合为全功能集(Functionally Complete Collection)

极小全功能集{¬,}\{\lnot, \lor\}, {¬,}\{\lnot, \land\}, {}\{|\}, {}\{\downarrow\} 等。

2.4. 标准式 Propositional Normal Forms

2.4.1. DNF/CNF

先给出以下基本定义:

  • A 字面量(literal) is a variable or its negation.
  • Conjunctions with literals as conjuncts are called 合取子句(conjunctive clauses) (clauses). 通过 AND 连接起来的一组字面量。

标准式(Propositional Normal Forms) 有以下两种:

  • 析取范式(Disjunctive Normal Form, DNF):A formula is said to be in disjunctive normal form if it is written as a disjunction, in which all the terms are conjunctions of literals. (e.g. (pq)(p¬q)(p\land q)\lor(p\land \lnot q).)
    • 最外面一层的运算符都是析取 \lor
    • 括号内的运算符都是合取 \land
    • 括号不能嵌套;
    • ¬\lnot 只能出现在变量前。
  • 合取范式(Conjunctive Normal Form, CNF):和 DNF 的定义相反;把 \land\lor 互换。

Theorem

Any formula AA is tautologically equivalent to some formula in DNF (CNF).

Proof

可以通过真值表构造,详见下面的 get the Full DNF of any formula 部分。

Construct the truth table for the proposition. Then an equivalent proposition is the disjunction with n disjuncts (where n is the number of rows for which the formula evaluates to T). Each disjunct has m conjuncts where m is the number of distinct propositional variables. Each conjunct includes the positive form of the propositional variable if the variable is assigned T in that row and the negated form if the variable is assigned F in that row. This proposition is in disjunctive normal from.

2.4.2. Full DNF/CNF

  • A 极小项(minterm) is a conjunctive of literals in which each variable is represented exactly once.
  • A 极大项(maxterm) is a disjunctive of literals in which each variable is represented exactly once.

可以从真值表中得到主析取范式(Full Disjunctive Normal Form)

  • 每个最小项对应真值表中 f=Tf=\text{T} 的恰好一行。

利用 De Morgan's Laws,也可以从真值表中得到主合取范式(Full Conjuctive Normal Form)

  • 取出所有真值表为中为 F\text{F} 的位置,写出 ¬f\lnot f
  • ¬f\lnot f 应用 De Morgan's Laws,可以将式子中的合取析取互换,从而求得 FCNF。

3. 谓词逻辑 Predicate Logic

3.1. 谓词 Predicates

考虑 x>0x>0,可以被表示为命题函数(propositional function) P(x)P(x),这里 PP 表示 is greater than 0\text{is greater than } 0xx 是一个变量。

  • Propositional functions become propositions (and have truth values) when their variables are each replaced by a value from the domain or bound by a quantifier.
  • A statement of the form P(x1,x2,,xn)P(x_1,x_2,\ldots, x_n) is the value of the propositional function P at the nn-tuple (x1,x2,,xn)(x_1,x_2,\ldots, x_n) and PP is called a nn-ary predicate.

我们可以用命题函数来描述前提条件(preconditions)后置条件(postconditions) ,这可以用于约束一段程序的输入和输出。

3.2. 量词 Quantifiers

  • 全称量词(universal quantifier) \forall:都是真才为真,存在一个为假就为假。可以转化为合取。
  • 存在量词(existential quantifier) \exists:都是假才为假,存在一个为真就为真。可以转化为析取。
  • 唯一量词(uniqueless quantifier) !\exists !:有且仅有一个为真时才为真。

我们在使用量词时,可能只要求对于某一范围内的 xx 成立,我们把此时 xx 的取值范围称为 讨论域(domain of discourse = universe of discourse),一般简写为 domain。

量词的优先级(precedence of quantifiers)

量词的优先级高于所有逻辑运算。The quantifiers \forall and \exists have higher precedence than all the logical operators.

所以平时我们再说,对于所有 xx,满足 p(x)p(x)q(x)q(x) 时可能会表示为 xp(x)q(x)\forall x p(x)\land q(x),但正确的做法应该是 x(p(x)q(x))\forall x (p(x) \land q(x))

3.3. 谓词逻辑的等值 Equivalences in Predicate Logic

Statements involving predicates and quantifiers are logically equivalent if and only if they have the same truth value no matter

  • 代入了什么谓词选择 which predicates are substituted into these statements and
  • 使用了什么讨论域 which domain of discourse is used for the variables in these propositional functions

同样使用 \equiv 符号来表示谓词逻辑中的等值。

德摩根定律(De Morgan’s laws) 在谓词逻辑中也适用:

¬xP(x)x¬P(x)¬xP(x)x¬P(x)\begin{aligned} \lnot \forall x P(x) &\equiv \exists x \lnot P(x)\\ \lnot \exists x P(x) &\equiv \forall x \lnot P(x) \end{aligned}

只有在 A(x)A(x)B(x)B(x) 都输出真时,A(x)B(x)A(x) \land B(x) 才为真,此时第一个等式的两侧都为真,否则两侧都为假。类似的可以证明第二个等式。

x(A(x)B(x))xA(x)xB(x)x(A(x)B(x))xA(x)xB(x)\begin{aligned} \forall x (A(x) \land B(x)) &\equiv \forall x A(x) \land \forall x B(x)\\ \exists x (A(x) \lor B(x)) &\equiv \exists x A(x) \lor \exists x B(x) \end{aligned}

但是如果把上面的等式的 \land\lor 互换则不成立。容易举出反例。

x(A(x)B(x))≢xA(x)xB(x)x(A(x)B(x))≢xA(x)xB(x)\begin{aligned} \forall x (A(x) \lor B(x)) &\not\equiv \forall x A(x) \lor \forall x B(x)\\ \exists x (A(x) \land B(x)) &\not\equiv \exists x A(x) \land \exists x B(x) \end{aligned}

但这两个命题在其中一个方向上是正确的。

xA(x)xB(x)x(A(x)B(x))x(A(x)B(x))xA(x)xB(x)\begin{aligned} \forall x A(x) \lor \forall x B(x) &\Rightarrow \forall x (A(x) \lor B(x))\\ \exists x (A(x) \land B(x)) &\Rightarrow \exists x A(x) \land \exists x B(x)\\ \end{aligned}

此外,还有:

x is not occurring in P.xA(x)Px(A(x)P)xA(x)Px(A(x)P)xA(x)Px(A(x)P)xA(x)Px(A(x)P)\begin{aligned} x \text{ is not occurring in } P.\\ \forall x A(x) \lor P &\equiv \forall x (A(x) \lor P)\\ \forall x A(x) \land P &\equiv \forall x (A(x) \land P)\\ \exists x A(x) \lor P &\equiv \exists x (A(x) \lor P)\\ \exists x A(x) \land P &\equiv \exists x (A(x) \land P)\\ \end{aligned}
x is not occurring in B.x(BA(x))BxA(x)x(BA(x))BxA(x)x(A(x)B)xA(x)Bx(A(x)B)xA(x)B\begin{aligned} x \text{ is not occurring in } B.\\ \forall x (B \rightarrow A(x)) &\equiv B \rightarrow \forall x A(x)\\ \exists x (B \rightarrow A(x)) &\equiv B \rightarrow \exists x A(x)\\ \forall x (A(x) \rightarrow B) &\equiv \exists x A(x) \rightarrow B\\ \exists x (A(x) \rightarrow B) &\equiv \forall x A(x) \rightarrow B\\ \end{aligned}

4. 嵌套量词 Nested Quantifiers

嵌套量词(nested quantifier):出现在另一个量词的辖域下的量词。Nest quantifiers are quantfiers that occur within the scope of other quantifiers.

4.1. 量词的顺序 Order of Quantifiers

除非所有量词都是 \forall 或所有量词都是 \exists,否则量词的顺序是有意义的。The order of nested quantifiers matters if quantifiers are of different types

E.g.:

  • x y L(x,y)\forall x\ \exists y\ L(x,y)Everybody loves somebody.
  • y x L(x,y)\exists y\ \forall x\ L(x,y)There is someone who is loved by everyone.

可以用循环来理解量词的顺序。

4.2. 前缀范式 Prenex Normal Form

任意表达式都可以被转化为前缀范式(prenex normal form)

如何得到 PNF?可以遵循一下步骤:

  1. 消除所有的 \rightarrow\leftrightarrow。Eliminate all occurrences of \rightarrow and \leftrightarrow from the formula in question.
  2. 向内移动否定符号,注意应用德摩根定律。Move all negations inward such that, in the end, negation only appear as part of literals.
  3. 对变量进行重命名,确定不同部分的变量不会冲突。Standardize the variables a part (when necessary).
  4. 最后,将所有量词移动到最前面。The prenex normal form can now be obtained by moving all quantifiers to the front of the formula.

5. 推理准则 Rules of Inference

  • An 论据(argument) is a sequence of statements that end with a conclusion
  • By 有效的(valid), we mean the conclusion must follow from the truth of the preceding statements (premises)
  • We use 推理准则(rules of inference) to construct valid arguments

Caution

在结论前别忘了加 \therefore 和一条横线,这才是标准格式。

6. 证明 Proof

6.1. 一些术语 Some Terminology

  • A 证明(proof) is a valid argument that establishes the truth of a mathematical statement.
  • A 定理(theorem) (or 命题(proposition)/fact/result) is a statement that can be shown to be true.
    • 公理(axioms) (or 假设(postulates)) are statements we assume to be true
  • A 引理(lemma) is a less important theorem that is helpful in the proof of other results
  • A 推论(corollary) is a theorem that can be established directly from a theorem that has been proved.
  • A 猜想(conjecture) is a statement that is being proposed to be a true statement
    • A conjecture becomes a theorem once it has been proved to be true.

6.2. 形式化证明 Formal Proofs

形式化证明(formal proof) v.s. 非形式化证明(informal proof)

  • Formal Proofs:
    • Can be extremely long;
    • May be hard to follow.
  • Informal Proofs:
    • Each step may involve multiple rules of inference;
    • Steps may be skipped;
    • The axioms being assumed and the rules of inference used are not explicitly stated.

6.3. 证明方法 Proof Methods

6.3.1. 直接证明法 Direct Proof

通过直接证明法(direct proof) 证明 pqp\rightarrow q 的方法是:

  • 通过推理规则(rules of inference)、公理、逻辑恒等式(logical equivalences) 等推出 qq 也为真。

其余的证明方法都是间接证明法(indirect proof)

6.3.2. 空证明和平凡证明 Vacuous and Trivial Proof

  • 空证明(vacuous proof):当 pp 为假时 pqp\rightarrow q 为真,所以我们可以通过证明 pp 为假来证明 pqp\rightarrow q 为真。
  • 平凡证明(trivial proof):当 qq 为真时 pqp\rightarrow q 为真,所以我们也可以通过证明 qq 为真来证明 pqp\rightarrow q 为真。

6.3.3. 反证法 Proof by Contraposition

反证法(proof by contraposition) 可以看做对原命题的逆否命题的直接证明,根据逻辑恒等式:

pq¬q¬pp\rightarrow q \equiv \lnot q\rightarrow \lnot p
  • 假设 ¬q\lnot q 为真;
  • 推出 ¬p\lnot p 也为真(or 推出 pp 为假),从而证明原命题。

6.3.4. 归谬证明法 Proof by Contradiciton

Proof pp by contradiction:

  • assumes pp is false.
  • deduces that ¬p(q¬q)\lnot p \rightarrow (q \land \lnot q), which q¬qq \land \lnot q is a contradiction.
  • pp follows from the above

Proof pqp\rightarrow q by contradiction:

  • assumes that both ¬q\lnot q and pp are true.
  • show that (p¬q)F(p \land \lnot q) \rightarrow \text{F}.

注意区分 Proof by Contraposition 和 Proof by Contradiction

Proof by Contradiction 相比于 Proof by Contraposition 多假设了一个 pp is true,并且只需要最后将其归谬即可。

6.4. 证明策略 Proof Strategies

6.4.1. 分类讨论 Proof by Cases

  • Convince the reader that the cases are inclusive (i.e. they exhaust all possibilities)
  • Establish all implications

6.4.2. 穷举法 Exhausitve Proof

An 穷举法(exhaustive proof) is a special type of proof by cases where each case involves checking a single example.

6.4.3. 不失一般性地 Without Loss of Generality

不失一般性地(without loss of generality),常用于证明过程中,可以缩写为 WLOG。比如:我们想要证明 xy=xy|xy|=|x|\cdot |y|,若已经证明了 x0, y<0x\ge 0,\ y<0 的情况下成立,则可以不是一般性的得到 x<0, y0x<0,\ y\ge 0 时也成立,因为这就是把 x=y, y=xx'=y,\ y'=x 代入后运用一次乘法交换律的情况。

合理运用 WLOG 可以帮助我们在分类讨论的过程中省略一些重复的证明,从而使证明过程更为简洁。

6.4.4. 存在性证明 Existence Proof

  • 构造存在性证明(constructive existence proof)
    • 证明 P(c)P(c) 对于定义域中的某一个 cc 成立。
    • 然后 xP(x)\exists x P(x) 就成立,根据存在性推广规则(existential generalization = EG)
  • 非构造存在性证明(inconstructive existence proof)
    • 假设不存在 cc 使得 P(c)P(c) 成立。
    • 然后推出一个矛盾,这可以说明原命题成立。

6.4.5. 唯一性证明 Uniqueness Proof

唯一性证明(uniqueness proof) To show that a theorem assert the existence of a unique element with a particular property.

x(P(x)y(yx¬P(y)))\exists x (P(x) \land \forall y (y\neq x \rightarrow \lnot P(y)))

唯一性证明可以分为证明其存在性和唯一性两部分。

  • 存在性(existence):We show that an element xx with the desired property exists.
  • 唯一性(uniqueness):We show that if yxy\neq x, then yy does not have the desired property. Equivalently, we can also show that if xx and yy both have the desired property, then x=yx=y.

评论

TABLE OF CONTENTS

1. 命题逻辑 Propositional Logic
1.1. 命题 Propositions
1.2. 逻辑运算符 Logical Operators
1.3. 条件语句 Conditional Statements
1.4. 真值表 Truth Table
1.5. 命题逻辑的应用 Applications of Propositional Logic
2. 逻辑等值式 Propositional Equivalences
2.1. 导论 Introduction
2.2. 逻辑定律 Logical Laws
2.3. 全功能集 Functionally Complete Collection of Logical Operators
2.4. 标准式 Propositional Normal Forms
3. 谓词逻辑 Predicate Logic
3.1. 谓词 Predicates
3.2. 量词 Quantifiers
3.3. 谓词逻辑的等值 Equivalences in Predicate Logic
4. 嵌套量词 Nested Quantifiers
4.1. 量词的顺序 Order of Quantifiers
4.2. 前缀范式 Prenex Normal Form
5. 推理准则 Rules of Inference
6. 证明 Proof
6.1. 一些术语 Some Terminology
6.2. 形式化证明 Formal Proofs
6.3. 证明方法 Proof Methods
6.4. 证明策略 Proof Strategies