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).
© 版权声明
文章版权归作者所有,未经允许请勿转载。




文中说的‘所有二元算子都能用¬∧∨表示’这个很关键,当年死活想不通
形式化验证里命题逻辑真的够用吗?感觉实际项目要处理的东西复杂多了
语法树那块例子再多点就好了
围观大佬讨论,我默默收藏了
命题逻辑确实是基础中的基础,理解透彻了后面才好走
救命,Hilbert系统证明A→A居然要五行!?🤯
之前用真值表做作业做到凌晨,后来发现语义tableau快多了
比教科书讲得清楚
Tableau里的α规则和β规则有优先级吗?感觉不好区分
这证明看得人想摔书😤
看得我眼花缭乱,逻辑学真是门玄学hhh
学完这个直接想转行,太费脑子了😭
说Gentzen系统比真值表更抽象?其实更适合机器推理我觉得
逻辑课看得我眼皮打架,得整点咖啡☕
这Tableau算法原理讲得清楚,但优化思路能多讲点就好了
当年学命题逻辑,老师让手写分配律证明写了三页纸😂
语法树那块还不太理解,有例子吗🤔
Hilbert那证明看得我直接放弃了,还是真值表香😤
确实,Hilbert那套证明太反直觉了,真值表虽然慢但至少能看懂