L17 – Logic II: Propositional logic
21,364字
90–136 分钟
Oversimplified history
Logic formalizes reasoning.
- Since ancient Greek (until modern high school):
- First subject taught to young people.
- Logic rules are classified and named.
- Goal: Reasoning and debating.
- 19c Mathematicians:
- Formalization of logic.
- Goal: Clarifying foundation of mathematics.
- Subjects: Consistency, independence, soundness, completeness.
- Hilbert’s program “ended” by Gödel.
- Modern days:
- Applications of logic in computer sciences.
- Propositional logic applied both in hardware and software.
- First-order logic applied in automated theorem prover and logic programming.
Structure of the course
We will learn about propositional logic and first-order (predicate) logic. For each we will study
- Syntax : Which strings are allowed?
- Semantics : What does a string mean?
- Deduction : Rules of inference between formulas.
- Resolution : Algorithm for automated proving.
- Application : SAT & logic programming.
Beginning today: propositional logic.
Section 1
Syntax
Atoms and operators
Definition: An atomic proposition is a sentence that is
- declarative.
- either true or false.
- cannot be decomposed.
The symbols used in a formula in propositional logic are
- Atomic propositions (atoms).
- Boolean operators: , , , …
Example
- One plus one equals two.
- The earth is flat.
- Sweet soy milk is more delicious.
- …
Example (Non-examples)
- Shut up!
- How are you?
- bla bla bla …
- …
Formula
Definition: A formula in propositional logic is generated by the following context-free grammar:
- terminals are atoms and operators.
- a nonterminal symbol
fml. - production rules are:
fml, is an atom.fmlfml.fml(fml op fml).op
Any formula that occurs in another formula is called a subformula of .
Example

Or we can define recursively as follows:
- An atom is a formula (atomic formula).
- For every formula , is a formula.
- For every two formulas and , and and … are formulas.
Abbreviations
means , means
Remark: All binary operators can be defined in terms of , , .
Precedence to reduce (‘s and )‘s:
A formula can be represented as a tree
- The leaves are labeled by the atoms.
- The nodes are labeled by operators.
- The node has a single child.
- Other operator nodes each have two children.
- Subtrees are subformulas.
Example

Induction on formula
To show that a statement holds for every formula , we show
- holds for every atomic formula .
- Under the hypothesis that holds for formulas and , then holds for , and .
Section 2
Semantics
Interpretation
Definition: Let be a formula, and be the set of atoms appearing in . An interpretation of is a function . In other words, an interpretation assigns a truth value (true for or false for ) to every atom in .
Definition: Given an interpretation of , the truth value of under , denoted is defined inductively as follows:
Truth table
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 1 |
- is intended to model the word “not”.
- is intended to model the word “and”.
- is intended to model the word “or”, but is inclusive or, not exclusive or.
- is defined as .
- is read “implies” but does not claim causation.
Model and satisfiability
Definition: Given an interpretation of a formula , if , we say that holds under , and is a model of , and write .
Definition
- A formula is satisfiable if has a model.
- Otherwise is unsatisfiable.
- A formula is valid or a tautology if every interpretation is a model, and we write .
Theorem: A formula is a tautology iff is unsatisfiable.
Decision procedure
- We want an algorithm that decides satisfiability.
- That is: given an arbitrary formula , it terminates and returns yes if is satisfiable, and no otherwise.
- Such an algorithm, when applied to , can decide validity.
Example: The truth table is such an algorithm, but very inefficient.
Is there a better algorithm?
Logical equivalence
Definition: Let and be two formulas (on the same set of atoms). If for all interpretations , then and are logically equivalent, denoted by .
Theorem (material equivalence vs logic equivalence) iff is true in every interpretation.
Theorem: Let be a subformula of and . Then , the latter denotes the formula obtained by replacing all occurrences of by .
- Absorption of constants
, , , … - Identical operands
, , , … - Commutativity, Associativity, Distributivity
, , , , … - Defining operators
, …
Set of formulas
Definition: Let be a set of formulas, and be the set of all atoms appearing in some formulas in . An interpretation of is a function . The truth value of under is defined similarly as above.
Definition: A set of formulas is (simultaneously) satisfiable if there is an interpretation such that for all . If this is the case, we say that is a model of . If this is not the case, we say that is unsatisfiable.
Logical consequence
Definition: Let be a set of formulas and be a formula. is a logical consequence of , denoted , iff every model of is a model of .
Theorem (material implication vs logmical consequence) iff .
Literals
Definition: A literal is an atom or the negation of an atom. For an atom , is called a positive literal, is a negative literal, and the pair is a complementary pair of literals.
Theorem: A set of literals is satisfiable iff it does not contain a complementary pair of literals.
Semantic tableau
Given a formula , output a tree all of whose leaves are marked closed or open.
- Initially, the tree has a single node labeled with (not marked!)
- Repeat: Choose an unmarked leaf labeled with a set of formulas (understood with ).
- If is a set of literals, mark closed if it contains a complementary pair, or open otherwise.
- Otherwise, choose a formula in which is not a literal in the following order of preference:
- If has the form of , create a child of with label .
- If , create a child of with label .
- If , create two children of with label for .
Example


Theorem
- The algorithm terminates. After termination, all leaves are marked closed or open.
- is unsatisfiable iff is closed (meaning all leaves marked closed).
- is satisfiable iff is open (meaning not closed).
Much better than truth tables.
Is there a better algorithm?
Sketched proofs
Sketched proof for termination.
Design an integer valued function related to the number of binary operators and the number of negations in . Prove that is strictly decreasing, i.e. for a child of , .
Sketched proof for soundness.
Need to prove: If the tableau closes, then the formula is unsatisfiable. Induction on the height of the nodes.
Sketched proof for completeness.
Need to prove: If a tableau is open, then the formula is satisfiable. Let be an open leaf, the union of for on the path from the root to is a Hintikka set:
- For all atom in a formula in , either or .
- If , and .
- If , or .
Such a set satisfiable.
Section 3
Deduction
Deductive system
Definition: A deductive system consists of a set of formulas called axioms and a set of rules of inference. A proof in a deductive system is a (finite) sequence of formulas , where each is either a theorem or a formula that can be inferred from previous formulas in the sequence using a rule of inference. The last formula is called a theorem and the sequence is the proof of . In this case, we say that is provable, denoted .
A priori, no connection to semantics, purely syntactical.
In practice, hope to be semantically “meaningful”.
Gentzen system
- Axioms (only one type): set of literals (understood with ) containing a complementary pair.
- Rules of inference: infer a set of formulas from one or two sets of formulas and .
- If , can be inferred.
- If , can be inferred.
- If and , can be inferred.
Prove in Gentzen system.
Proof.
- (Axiom)
- (Axiom)
- (from 1 and 2, )
- (from 3)
- (from 4)
Prove in Gentzen system.
Proof.
- (Axiom)
- (from 1)
- (Axiom)
- (from 3)
- (from 2, 4)
- (Axiom)
- (from 6)
- (Axiom)
- (from 8)
- (from 7, 9)
- (from 10)
- (from 5, 11)
- (from 12)
Gentzen proof for corresponds to semantic tableau for upside down.

Theorem
iff in Gentzen system iff there is a closed semantic tableau for .
Hilbert system
- Axioms:
- Rule (only one): modus ponens, MP
Prove .
Proof.
- (Axiom 2)
- (Axiom 1)
- (MP 1, 2)
- (Axiom 1)
- (MP 3, 4)
Definition: Let be a set of formulas and a formula. means that the formulas in are assumptions in a proof of . A proof under the assumptions is a sequence of lines such that and
- is an axiom,
- is a member of (assumption),
- is a previously proved theorem,
- can be inferred by MP from previous lines.
Derived rules in Hilbert system
- (deduction rule).
- (contraposition rule).
- (transitivity rule).
- (exchange of antecedents).
- , (double negation).
- (reductio ad absurdum).
Prove .
Proof.
- (Assumption)
- (Assumption)
- (MP 1, 2)
- (Assumption)
- (MP 3, 4)
- (Deduction 5)
- (Deduction 6)
- (Deduction 7)
Prove .
Proof.
- (Assumption)
- (Assumption)
- (MP 1, 2)
- (Assumption)
- (MP 3, 4)
- (Deduction 5)
- (Deduction 6)
- (Deduction 7)
Prove .
Proof.
- (Axiom 1)
- (Assumption)
- (MP 1, 2)
- (Contrapositive 3)
- (Contrapositive 4)
- (MP 2, 5)
- (Deduction 6)
Prove .
Proof.
- (Assumption)
- (Contrapositive)
- ()
- (MP 2, 3)
- (Double negation)
- (Deduction 5)
Theorem
- Sound: If then .
- Complete: If then .
Sketched proof for soundness and completeness.
- Soundness:
Axioms are valid, and MP is sound. That is, if and are valid, so is . - Completeness:
For a set of formula, if in Gentzen system, then in Hilbert system. Moreover, if and in Hilbert system, then in Hilbert system. Finally, the rules of inference of Gentzen system can be simulated in Hilbert system.
formula semantic tableau Gentzen proof Hilbert proof
Definition: A set of formula is inconsistent iff for some formula , and . is consistent iff it is not inconsistent. A deduction system is inconsistent if it contains an inconsistent set of formula.
Theorem
In the Hilbert system,
- is inconsistent iff for all , .
- is consistent iff for some , .
- iff is inconsistent.
Since the Hilbert system is sound and , we have in the Hilbert system, so the Hilbert system is consistent.
Section 4
Resolution
Conjunctive normal form (CNF)
Definition: A formula is in conjunctive normal form (CNF) if it is a conjunction of disjunctions of literals.
Theorem: Every formula can be transformed into an equivalent formula in CNF.
- Express all operators in terms of , , .
- Push negations inward.
- Delete double negations.
- Distribute disjunctions.
Example
Clausal form
Definition
- A clause is a set of literals (seen as disjunction of the literals).
- A formula in clausal form is a set of clauses (seen as conjunction of the clauses).
A clausal form is just another way to write a formula in CNF.
- A clause with exactly one literal is a unit clause.
- A clause with no literal is an empty clause, denoted .
An empty clause is unsatisfiable. - A clause with a pair of clashing literals is trivial.
A trivial clause is valid, and can be removed from a set of clauses. - An empty set of clauses is denoted .
An empty set of clauses is valid.
Resolvent
Definition: Let be a literal and be clauses such that and . We say that and are clashing clauses, and they clash on the complementary pair of literals and . The resolvent of and is the clause
and are called parent clauses of .
Theorem
- If two clauses clash on more than one complementary pair, their resolvent is trivial.
- The resolvent is satisfiable iff the parent clauses are both (simultaneously) satisfiable.
Resolution
- Input: A set of clauses .
- Output: Satisfiability of (yes or no).
- Initially . Repeat the following to obtain from .
- Choose a new clashing pair of clauses
- Compute the resolvent .
- If is trivial, .
- If is not trivial, .
- Terminates if
- .
- No clashing pair.
Example
where
- , then
- resolving and
- resolving and
- resolving and
A derivation of from is a refutation by resolution of .
Theorem
- If there is a refutation by resolution of , then is unsatisfiable.
- If is unsatisfiable, then will be derived by resolution.
Section 5
Application: SAT
Clauses
We write to denote that is satisfiable iff is satisfiable.
Theorem (and definition) A pure literal in is a literal that appears in some clause but does not appear in any clause. If this is the case, let be obtained from by deleting every clause containing . Then .
Theorem (and definition) Let be a unit clause and be obtained from by deleting every clause containing and deleting from every remaining clause. Then .
Theorem (and definition) Let be two clauses in . We say that subsumes . If this is the case, let . Then .
Theorem (and definition) Let be a set of atomic propositions. The renaming of by , denoted , is obtained from by replacing each literal on an atom by . We have .
Davis-Putnam Algorithm
- Input: A formula in clausal form.
- Output: is satisfiable or unsatisfiable.
- Repeat the following:
- If there is a unit clause , delete all clauses containing and delete from all other clauses.
- If there is a pure literal , delete all clauses containing .
- Only when the previous two do not apply, choose an atom and perform all possible resolutions on clauses clashing on . Add these resolvents and delete all clauses containing or .
- Terminate
- If empty clause is produced, report unsatisfiable.
- If no more rules applicable, report satisfiable.
Repeating the step about unit clauses until no longer applicable is called unit propagation.
Davis-Putnam-Logemann-Loveland Algorithm
- Input: A formula in clausal form.
- Output: is unsatisfiable or satisfiable with a partial interpretation that satisfies .
- Call the following recursive function , where is a set of clauses and is a partial interpretation, initially with and empty.
- Obtain from by unit propagation. Obtain from by adding all assignments during the propagation.
- Evaluate under .
- If satisfied, return satisfiable and .
- If contains a clause such that , return unsatisfiable.
- Otherwise, continue
- Choose an atom in , extend to with . Call . If result is satisfiable, return it. Otherwise continue.
- Choose an atom in , extend to with . Call . Return the result.
Linear time cases
The 2-SAT problem (satisfiability when each clause contains at most two literals) can be solved in linear time.
Definition: A formula in CNF is a Horn formula if every disjunction contains at most one positive literal.
A Horn formula can also be written in the form of conjunctions of implications.
The satisfiability of a Horn formula can be decided only by unit propagation (in linear time).
© 版权声明
文章版权归作者所有,未经允许请勿转载。




Tableau算法里的α规则和β规则具体是怎么区分优先级的?🤔
没错,逻辑这块基础打牢了后面学形式化验证也容易不少。
当年学逻辑的时候,老师让我们手动证明分配律,写了两页纸才搞完。现在看到这些证明步骤又PTSD了😂
确实,命题逻辑是基础,搞懂这些后面一阶逻辑才好理解
那归结原理(Resolution)和这个语义tableau有啥关系?后续会讲吗?
自动化定理证明真的用这些规则吗?感觉好原始
这些符号看得我脑壳疼
硬核,我是来看热闹的,告辞👋
说Gentzen复杂的,其实它和tableau是对偶的😂
之前学数理逻辑的时候,对Hilbert系统的证明真的无语,一个简单的定理要写一堆
真值表算法复杂度O(2^n)吧?语义tableau能好多少?
比我们老师讲得清楚多了hhh
硬核内容,看得我头皮发麻😂
Hilbert系统就三个公理一个规则?那证明A→A都那么长…真实用吗?
语义表和真值表比起来确实省事多了
同感,画真值表太累
Hilbert系统那三条公理看着简单,真用起来头都大了
归结算法蛮巧妙的
确实挺巧妙的
古希腊就开始研究逻辑了啊
感觉这些证明写起来比算数累多了
证明真的比算术费脑子多了
逻辑符号多了以后太容易看花眼了
同感,符号一多真的眼花
CNF转换那块挺绕的,得慢慢看
语义表比真值表快不少
DP算法简化了不少
甜豆浆那个例子笑到了
甜豆浆这个例子我也get到了
Hilbert系统公理少但推导真麻烦
同感,推导步骤多
盖茨系统和语义表倒过来看,有意思
反向思考确实有启发
命题逻辑的语法树表示挺直观
树形结构确实好懂
消解法步骤清晰,比真值表靠谱多了
真值表变量一多就爆炸了
置换定理这块挺直观的,替换就完事了
归结法那块终于讲清楚了,之前一直懵
同感,这块确实容易绕进去
希尔伯特系统证明也太多了吧
同感,推演起来头大
真值表太慢,还是归结法香
同感,归结法效率高。
SAT求解器作用大吗
同问,感觉挺有用的
命题逻辑的语法定义挺清晰的,就是证明部分有点烧脑
同感,证明部分容易绕进去
这Gentzen系统看着比真值表还复杂啊🤔