<<

Discrete Mathematics1 http://lcs.ios.ac.cn/˜znj/DM2017

Naijun Zhan

March 19, 2017

1Special thanks to Profs Hanpin Wang (PKU) and Lijun Zhang (ISCAS) for their courtesy of the slides on this course. Contents

1. The Foundations: Logic and Proofs 2. Basic Structures: Sets, Functions, Sequences, Sum- s, and Matrices 3. Algorithms 4. Number Theory and Cryptography 5. Induction and Recursion 6. Counting 7. Discrete Probability 8. Advanced Counting Techniques 9. Relations 10. Graphs 11. Trees 12. Boolean Algebra 13. Modeling Computation

1 Chapter 1

The Foundations: Logic and Proofs

Logic in Computer Science During the past fifty years there has been extensive, continuous, and growing interaction between logic and computer science. In many respects, logic provides computer science with both a u- nifying foundational framework and a tool for modeling compu- tational systems. In fact, logic has been called the calculus of computer science. The argument is that logic plays a fundamen- tal role in computer science, similar to that played by calculus in the physical sciences and traditional engineering disciplines. Indeed, logic plays an important role in areas of computer sci- ence as disparate as machine architecture, computer-aided de- sign, programming languages, databases, artificial intelligence, algorithms, and computability and complexity. Moshe Vardi

2 • The origins of logic can be dated back to Aristotle’s time. • The birth of mathematical logic: – Leibnitz’s idea – Russell paradox – Hilbert’s plan – Three schools of modern logic: logicism (Frege, Russell, Whitehead) formalism (Hilbert) intuitionism (Brouwer) • One of the central problem for logicians is that: “why is this proof correct/incorrect?” • Boolean algebra owes to George Boole. • Now, we are interested in: “is the program correct?”

3 1.1 Propositional Logic – An Appetizer

Definition 1.1.1 (). A proposition is a declarative sentence that is either true or false, but not both.

Definition 1.1.2 (Propositional Logic). Fix a countable propo- sition AP. Syntax of propositional formulas in BNF (Backus- Naur form) is given by: ϕ ::= p ∈ AP | ¬ϕ | ϕ ∧ ϕ Accordingly, • Atomic proposition p ∈ AP is a formula. • Compound formulas: ¬ϕ (negation) and ϕ ∧ ψ (conjunc- tion), provided that ϕ and ψ are formulas.

4 For p ∈ AP , negation and conjunction, we can construct the truth tables. We define the following derived operators: • Disjunction: ϕ ∨ ψ := ¬(¬ϕ ∧ ¬ψ) • Implication: ϕ → ψ := ¬ϕ ∨ ψ • Bi-implication: ϕ ↔ ψ := (ϕ → ψ) ∧ (ψ → ϕ) • Exclusive Or: ϕ ⊕ ψ := (ϕ ∨ ψ) ∧ (¬(ϕ ∧ ψ)) Definition 1.1.3 (Precedence of Logical Operators). Operators ¬, ∧, ∨, →, ↔ have precedence 1, 2, 3, 4, 5, respectively.

5 Definition 1.1.4 (Logic and Bit Operators). • A bit is a symbol with possible values 0 and 1.A Boolean variable is a variable with value true or false. • Computer bit operations correspond to logic connectives: OR, AND, XOR in various programming languages corre- spond to ∨, ∧, ⊕, respectively. • A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string. • Bitwise OR, bitwise AND and bitwise XOR of two strings of the same length are the strings that have as their bits the OR, AND and XOR of the corresponding bits in the two strings, respectively.

6 1.2 Applications of Propositional Logic

Definition 1.2.1 (Applications). • System Specifications: The automated reply cannot be sent when the file system is full. • Boolean Searches: (one | two) - (three) • Logic Puzzles. Knights always tell the truth, and the op- posite knaves always lie. A says: ”B is a knight”. B says ”The two of us are opposite types”

Definition 1.2.2 (Logic Circuit). • Propositional logic can be applied to the design of computer hardware. Claude Shannon

• A logic circuit receives input signals p1, p2, . . . , pn and pro- duces an output s. Complicated digital circuits are con- structed from three basic circuits, called gates.

• Build a digital circuit producing (p ∨ ¬r) ∧ (¬p ∨ (q ∨ ¬r)).

7 1.3 Propositional Equivalences

A formula ϕ is called a • tautology if it is always true, no matter what the truth values of the propositional variables are; • contradiction if it is always false; • contingency if it is neither a tautology nor a contradiction. Moreover, ϕ is satisfiable if it is either a tautology or a contin- gency, unsatisfiable if it is a contradiction. Formulas ϕ and ψ are called logically equivalent if ϕ ↔ ψ is a tautology. This is denoted by ϕ ≡ ψ. Definition 1.3.1 (Logical Equivalence). Show the following log- ical equivalences: 1. Identity laws: ϕ ∧ T ≡ ϕ, ϕ ∨ F ≡ ϕ 2. Dominations laws ϕ ∨ T ≡ T, ϕ ∧ F ≡ F

8 3. Idempotent laws ϕ ∨ ϕ ≡ ϕ, ϕ ∧ ϕ ≡ ϕ 4. Double negation law ¬(¬ϕ) ≡ ϕ 5. Commutative laws ϕ ∨ ψ ≡ ψ ∨ ϕ, ϕ ∧ ψ ≡ ψ ∧ ϕ 6. Associative laws

(ϕ1 ∨ϕ2)∨ϕ3 ≡ ϕ1 ∨(ϕ2 ∨ϕ3), (ϕ1 ∧ϕ2)∧ϕ3 ≡ ϕ1 ∧(ϕ2 ∧ϕ3) 7. Distributive laws

ϕ1 ∨ (ϕ2 ∧ ϕ3) ≡ (ϕ1 ∨ ϕ2) ∧ (ϕ1 ∨ ϕ3),

ϕ1 ∧ (ϕ2 ∨ ϕ3) ≡ (ϕ1 ∧ ϕ2) ∨ (ϕ1 ∧ ϕ3) 8. De Morgan’s laws ¬(ϕ ∧ ψ) ≡ ¬ϕ ∨ ¬ψ, ¬(ϕ ∨ ψ) ≡ ¬ϕ ∧ ¬ψ 9. Absorption laws ϕ ∨ (ϕ ∧ ψ) ≡ ϕ, ϕ ∧ (ϕ ∨ ψ) ≡ ϕ 10. Negation laws ϕ ∨ ¬ϕ ≡ T, ϕ ∧ ¬ϕ ≡ F

9 Definition 1.3.2 (Logical Equivalence). Logical equivalences involving conditional statements: 1. ϕ → ψ ≡ ¬ϕ ∨ ψ 2. ϕ → ψ ≡ ¬ψ → ¬ϕ 3. ϕ ∨ ψ ≡ ¬ϕ → ψ 4. ϕ ∧ ψ ≡ ¬(ϕ → ¬ψ) 5. ϕ ∧ ¬ψ ≡ ¬(ϕ → ψ)

6. (ϕ1 → ϕ2) ∧ (ϕ1 → ϕ3) ≡ ϕ1 → (ϕ2 ∧ ϕ3)

7. (ϕ1 → ϕ3) ∧ (ϕ2 → ϕ3) ≡ (ϕ1 ∨ ϕ2) → ϕ3

8. (ϕ1 → ϕ2) ∨ (ϕ1 → ϕ3) ≡ ϕ1 → (ϕ2 ∨ ϕ3)

9. (ϕ1 → ϕ3) ∨ (ϕ2 → ϕ3) ≡ (ϕ1 ∧ ϕ2) → ϕ3 10. ϕ ↔ ψ ≡ ¬ϕ ↔ ¬ψ 11. ϕ ↔ ψ ≡ (ϕ ∧ ψ) ∨ (¬ϕ ∧ ¬ψ) 12. ¬(ϕ ↔ ψ) ≡ ϕ ↔ ¬ψ

10 1.4 Induction and Recursion

PRINCIPLE OF MATHEMATICAL INDUCTION To prove that P (n) is true for all positive integers n, where P (n) is a proposi- tional function, we complete two steps: • BASIS STEP: We verify that P (1) is true. • INDUCTIVE STEP: We show that the conditional state- ment P (k) → P (k + 1) is true for all positive integers k. Expressed as a rule of inference for first-order logic, this proof technique can be stated as:

Φ := (P (1) ∧ ∀k.(P (k) → P (k + 1))) → ∀n.P (n)

Exercise 1.4.1. Prove 1 + 2 + 22 + ... + 2n = 2n+1 − 1.

11 STRONG INDUCTION (Second principle of mathematical induc- tion) To prove that P (n) is true for all positive integers n, where P (n) is a propositional function, we complete two steps: • BASIS STEP: We verify that the proposition P (1) is true. • INDUCTIVE STEP: We show that the conditional state- ment (P (1) ∧ P (2) ∧ ... ∧ P (k)) → P (k + 1) is true for all positive integers k. Expressed as a rule of inference for first-order logic, this proof technique can be stated as:

k Ψ := (P (1) ∧ ∀k.(∧i=1P (i) → P (k + 1))) → ∀n.P (n) Exercise 1.4.2. Prove that if n is a natural number greater than 1, then n can be written as the product of primes.

12 Recursively Defined Sets and Structures and Structural Induction Definition 1.4.3 (Strings). The set Σ∗ of strings over the al- phabet Σ is defined recursively by • BASIS STEP: λ ∈ Σ∗ (where λ is the empty string con- taining no symbols). • RECURSIVE STEP: If w ∈ Σ∗ and x ∈ Σ, then wx ∈ Σ∗.

Definition 1.4.4. We define the set of well-formed formulas in propositional logic, denoted by L, from alphabet Σ := AP ∪ {¬, →, (, )}. • BASIS STEP: each p ∈ AP is a well-formed formula. • RECURSIVE STEP: If ϕ and ψ are well-formed formu- las, i.e., ϕ, ψ ∈ L, then (¬ϕ), (ϕ → ψ) are well-formed formulas. Thus, the set of well-formed formulas is a subset of L ⊆ Σ∗.

13 STRUCTURAL INDUCTION A proof by structural in- duction consists of two parts. • BASIS STEP: Show that the result holds for all elements specified in the basis step. • RECURSIVE STEP: Show that if the statement is true for each of the elements used to construct new elements in the recursive step of the definition, the result holds for these new elements. Remark: The validity of structural induction follows from the principle of mathematical induction for the nonnegative integers. Exercise 1.4.5. Show that every well-formed formula for com- pound contains an equal number of left and right parentheses.

14 1.5 Normal Forms

Negation Normal Form • Literal: An atomic proposition p or its negation ¬p; • Negation Normal Form (NNF): A formula built up with “∧”, “∨”, and literals. • Using repeated DeMorgan and Double Negation, we can transform any formula into a formula with Negation Normal Form. • Example: ¬((A ∨ B) ∧ ¬C) ↔ (DeMorgan) ¬(A ∨ B) ∨ ¬¬C ↔ (Double Neg, DeMorgan) (¬A ∧ ¬B) ∨ C

Disjunction Normal Form • Disjunction Normal Form (DNF): A generalized dis- junction of generalized conjunctions of literals. • Using repeated distribution of ∧ over ∨, any NNF formula can be rewritten in DNF (exercise). • Example: (A ∨ B) ∧ (C ∨ D) ↔ (Distribution) [(A ∨ B) ∧ C] ∨ [(A ∨ B) ∧ D] ↔ (Distribution) (A ∧ C) ∨ (B ∧ C) ∨ (A ∧ D) ∨ (B ∧ D)

15 Conjunction Normal Form • Conjunction Normal Form (CNF): A generalized con- junction of generalized disjunctions of literals. • Using repeated distribution of ∨ over ∧, any NNF formula can be rewritten in CNF (exercise). • Example: (A ∧ B) ∨ (C ∧ D) ↔ (Distribution) [(A ∧ B) ∨ C] ∧ [(A ∧ B) ∨ D] ↔ (Distribution) (A ∨ C) ∧ (B ∨ C) ∧ (A ∨ D) ∧ (B ∨ D)

Truth table

16 Expressive completeness • What are the truth tables for (p ∧ q) ∨ r and p ∧ (q ∨ r)? • Truth table for n-ary Boolean function. • A set of logical connectives is called functionally com- plete if any n-ary Boolean function is definable with it, e.g. {¬, ∧}, {¬, ∨}. • How about {¬, →}? Exercise. Exercise 49 of page 16, Exercise 15 of page 23, Exercise 39 of page 35, Exercise 45 of page 36.

17 1.6 Propositional Logic and Deduction Sys- tems: a Sound and Complete Axiomati- zation

This section considers a complete axiomatization system such that, a formula is a tautology if and only if it can be derived by means of the axioms and the deduction rules of the system.

1.6.1 Syntax and Semantics of Propositional Logic Fix a countable proposition set AP, then formulas of proposi- tional logic are defined by: Definition 1.6.1 (Syntax). Syntax of propositional formulas in BNF (Backus-Naur form) is given by:

ϕ ::= p ∈ AP | ¬ϕ | ϕ → ϕ

It generates recursively the set of well-formed formulas, de- noted by L: • Atomic formula: p ∈ AP implies p ∈ L. • Compound formulas: (¬ϕ) and (ϕ → ψ), provided that ϕ, ψ ∈ L.

18 We omit parentheses if it is clear from the context. Semantics of a formula ϕ is given w.r.t. an assignment σ ∈ 2AP , which is a subset of AP. Intuitively, it assigns true (or, T) to propositions belonging to it, and assigns false (or, F) to others. Thus, it can also be viewed as a function from AP to {T, F}. Definition 1.6.2 (Semantics). Inductively, we may define the AP relation ⊆ 2 × L as follows: • σ p iff p ∈ σ. • σ ¬ϕ iff not σ ϕ (denoted by σ 6 ϕ). • σ ϕ → ψ iff either σ 6 ϕ or σ ψ. where (σ, ϕ) ∈ is denoted as σ ϕ.

The formula ϕ is called a tautology if σ ϕ for all assignment, it is satisfiable if σ ϕ for some assignment.

1.6.2 The Axiom System: the Hilbert’s System Definition 1.6.3 (Axioms). 1. ϕ → (ψ → ϕ). 2. (ϕ → (ψ → η)) → ((ϕ → ψ) → (ϕ → η)).

19 3. (¬ϕ → ¬ψ) → (ψ → ϕ).

ϕ → ψ ϕ Definition 1.6.4 (MP Rule). 1. ψ

Given a formula set Γ, a deductive sequence of ϕ from Γ is a sequence ϕ0, ϕ1, . . . , ϕn = ϕ where each ϕi should be one of the following cases:

1. ϕi ∈ Γ.

2. ϕi is an instance of some axiom.

3. There exists some j, k < i, such that ϕk = ϕj → ϕi. And, we denote by Γ ` ϕ if there exists such deductive sequence. We write Γ, ψ ` ϕ for Γ ∪ {ψ} ` ϕ.

20 1.6.3 The Axiom System: Soundness For a formula set Γ and an assignment σ, the satisfaction relation is defined by: σ Γ iff σ ϕ for every ϕ ∈ Γ. Observe σ ∅ always holds. We say ϕ is a logical consequent of Γ, denoted as Γ |= ϕ, if σ Γ implies σ ϕ for each assignment σ. Thus, ϕ is a tautology if ϕ is the logical consequent of ∅, denoted as |= ϕ. Theorem 1.6.5 (Soundness). With Hilbert’s axiom system, we have that Γ ` ϕ implies Γ |= ϕ. Proof. By induction of the length of deductive sequence of Γ ` ϕ. Corollary 1.6.6. If ` ϕ, then |= ϕ.

1.6.4 The Axiom System: Completeness With Hilbert’s axiom system, we have the following elementary properties: (Fin) If Γ ` ϕ, then there exists some finite subset Γ0 of Γ, such that Γ0 ` ϕ. (∈) If ϕ ∈ Γ, then Γ ` ϕ.

0 0 (∈+) If Γ ` ϕ and Γ ⊆ Γ then Γ ` ϕ.

(MP) If Γ1 ` ϕ and Γ2 ` ϕ → ψ, and Γ1, Γ2 ⊆ Γ, then Γ ` ψ.

21 1.6.5 The Axiom System: Examples of Theorems Example 1.6.7. (Ide): ` ϕ → ϕ Solution. 1. ϕ → (ϕ → ϕ) 2. ϕ → ((ϕ → ϕ) → ϕ) 3.( ϕ → ((ϕ → ϕ) → ϕ)) → ((ϕ → (ϕ → ϕ)) → (ϕ → ϕ)) 4.( ϕ → (ϕ → ϕ)) → (ϕ → ϕ) 5. ϕ → ϕ

Example 1.6.8. (→−): If Γ ` ϕ → ψ then Γ, ϕ ` ψ. Solution. A simple application of MP and( ∈).

Example 1.6.9. (→+): If Γ, ϕ ` ψ then Γ ` ϕ → ψ. Solution. By induction of the deductive sequence of Γ, ϕ ` ψ. Example 1.6.10. (τ): If Γ ` ϕ → ψ and Γ ` ψ → η, then Γ ` ϕ → η.

Solution. By( →−),( →+) and( ∈+). Example 1.6.11. (Abs): ` ¬ϕ → (ϕ → ψ). Solution. 1. ` ¬ϕ → (¬ψ → ¬ϕ) 2. ` (¬ψ → ¬ϕ) → (ϕ → ψ) 3. ` ¬ϕ → (ϕ → ψ) Example 1.6.12. (Abs’): ` ϕ → (¬ϕ → ψ)

Example 1.6.13. (¬w): ¬ϕ → ϕ ` ϕ Solution. 1. ¬ϕ → ϕ ` ¬ϕ → ϕ

22 2. ` ¬ϕ → (ϕ → ¬(¬ϕ → ϕ)) 3. ` (¬ϕ → (ϕ → ¬(¬ϕ → ϕ))) → ((¬ϕ → ϕ) → (¬ϕ → ¬(¬ϕ → ϕ))) 4. ¬ϕ → ϕ ` ¬ϕ → ¬(¬ϕ → ϕ) 5. ` (¬ϕ → ¬(¬ϕ → ϕ)) → ((¬ϕ → ϕ) → ϕ) 6. ¬ϕ → ϕ ` (¬ϕ → ϕ) → ϕ 7. ¬ϕ → ϕ ` ϕ

Example 1.6.14. (¬¬−): ¬¬ϕ ` ϕ Solution. 1. ` ¬¬ϕ → (¬ϕ → ϕ) 2. ` (¬ϕ → ϕ) → ϕ 3. ` ¬¬ϕ → ϕ 4. ¬¬ϕ ` ϕ

Example 1.6.15. (¬s): ϕ → ¬ϕ ` ¬ϕ Solution. 1. ¬¬ϕ ` ϕ 2. ϕ → ¬ϕ ` ϕ → ¬ϕ 3. ϕ → ¬ϕ, ¬¬ϕ ` ϕ 4. ϕ → ¬ϕ ` ¬¬ϕ → ¬ϕ 5. ` (¬¬ϕ → ¬ϕ) → ¬ϕ 6. ϕ → ¬ϕ ` ¬ϕ

Example 1.6.16. (¬¬+): ϕ ` ¬¬ϕ

23 Solution. 1. ` ϕ → (¬ϕ → ¬¬ϕ) 2. ` (¬ϕ → ¬¬ϕ) → ¬¬ϕ 3. ` ϕ → ¬¬ϕ 4. ϕ ` ¬¬ϕ Example 1.6.17. (R0) ϕ → ψ ` ¬ψ → ¬ϕ (R1) ϕ → ¬ψ ` ψ → ¬ϕ (R2) ¬ϕ → ψ ` ¬ψ → ϕ (R3) ¬ϕ → ¬ψ ` ψ → ϕ Solution. 1. ϕ → ψ, ¬¬ϕ ` ϕ 2. ϕ → ψ, ¬¬ϕ ` ψ 3. ` ψ → ¬¬ψ 4. ` (¬¬ϕ → ¬¬ψ) → (¬ψ → ¬ϕ) 5. ϕ → ψ ` ¬ψ → ¬ϕ Definition 1.6.18 (Consistency). We say a formula set Γ is consistent, iff there is some ϕ such that Γ 6` ϕ. Moreover, we say ϕ is consistent w.r.t. Γ iff Γ ∪ {ϕ} is consistent.

Note that we have the theorem ¬ϕ, ϕ ` ψ and hence, Γ is

24 consistent iff for each ϕ, either Γ 6` ϕ or Γ 6` ¬ϕ. Further, ϕ is consistent w.r.t. Γ iff Γ 6` ¬ϕ. Suppose that Γ 6` ¬ϕ and Γ ∪ {ϕ} is inconsistent, then we have Γ, ϕ ` ¬ϕ hence Γ ` ϕ → ¬ϕ. Recall that we have ϕ → ¬ϕ ` ¬ϕ, and this implies Γ ` ¬ϕ, contradiction! Lemma 1.6.19. If the formula set Γ is inconsistent, then it has some finite inconsistent subset ∆. Theorem 1.6.20. Γ is consistent iff Γ is satisfiable.

Proof sketch. The “if” direction is easy: suppose that σ Γ but Γ ` ϕ and Γ ` ¬ϕ, then σ ϕ and σ ¬ϕ, contradiction. For the “only if” direction, let us enumerate all propositional formulas as following (note the cardinality of all such formulas is ℵ0): ϕ0, ϕ1, . . . , ϕn,...

Let Γ0 = Γ and ( Γi ∪ {ϕi} if Γi 6` ¬ϕi Γi+1 = Γi ∪ {¬ϕi} otherwise

∗ and finally let Γ = lim Γi. i→∞ The formula set Γ∗ has the following properties:

∗ 1. Each Γi is consistent, and Γ is also consistent. 2.Γ ∗ is a maximal set, i.e., for each formula ϕ, either ϕ ∈ Γ∗ or ¬ϕ ∈ Γ∗. 3. For each formula ϕ, we have Γ∗ |= ϕ iff ϕ ∈ Γ∗.

∗ ∗ Then we have σ Γ , where σ = Γ ∩ AP.

25 Theorem 1.6.21 (Completeness). If Γ |= ϕ, then Γ ` ϕ. Proof. Assume by contradiction that Γ 6` ϕ, then there is an assignment σ such that σ Γ ∪ {¬ϕ}. However, this implies that σ Γ and σ 6 ϕ, which violates the assumption Γ |= ϕ. Corollary 1.6.22. |= ϕ implies that ` ϕ.

The Axiom System: Compactness Theorem 1.6.23. Given a formula set Γ, we have 1. Γ is consistent iff each of its finite subsets is consistent; 2. Γ is satisfiable iff each of its finite subsets is satisfiable. Proof. 1. The first property has been proven (see the previous lemma). 2. With the aforementioned theorem: for propositional logic, a set is satisfiable iff it is consistent.

Rules of Inference for Propositional Logic (cf. page 72):

26 27 Exercise 1.6.24. Show, by applying the rules of the deduction system presented in Section 1.6, the following statements: 1. ` (ϕ → ψ) → ((¬ϕ → ¬ψ) → (ψ → ϕ)) 2. ` ((ϕ → (ψ → η)) → (ϕ → ψ)) → ((ϕ → (ψ → η)) → (ϕ → η)) 3. ` (ϕ → (ϕ → ψ)) → (ϕ → ψ) 4. ` ϕ → (ψ → (ϕ → ψ)) 5. {ϕ → ψ, ¬(ψ → η) → ¬ϕ} ` ϕ → η 6. ϕ → (ψ → η) ` ψ → (ϕ → η) 7. ` ((ϕ → ψ) → ϕ) → ϕ 8. ` ¬(ϕ → ψ) → (ψ → ϕ)

Exercise 1.6.25. Find a deduction showing the correctness of some of the following equivalences, that is, if ϕ ≡ ψ, then pro- vide a deduction for ` ϕ → ψ and for ` ψ → ϕ. 1. ϕ ∨ (ϕ ∧ ψ) ≡ ϕ,

2. (ϕ1 → ϕ2) ∨ (ϕ1 → ϕ3) ≡ ϕ1 → (ϕ2 ∨ ϕ3).

28 Exercise 1.6.26 (* not required). Fill the missing parts of the proofs of the soundness and completeness theorems in Sec- tion 1.6.

29 Chapter 2

Basic Structures: Sets, Functions, Sequences, Sums, and Matrices

2.1 Sets and Functions

Definition 2.1.1. • Fix an universal set U. Set operations: union ∪, intersec- tion ∩, complement A. • Set inclusion: A ⊆ B iff for all a ∈ A it holds a ∈ B. A = B iff A ⊆ B and B ⊆ A. • Given a set S, the power set of S is the set of all subsets of the set S. The power set is denoted by P(S), or 2S.

• The Cartesian product of sets A1,A2,...,An is defined by: A1 × · · · × An := {(a1, . . . , an) | ai ∈ Ai for i = 1, . . . , n}. • The cardinality of finite set A, denoted by |A|, is the num- ber of its elements. The principle of inclusion-exclusion: |A ∪ B| = |A| + |B| − |A ∩ B|

30 31 Definition 2.1.2. Let A and B be nonempty sets. A function f : A → B from A to B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b ∈ B is assigned by f to the element a ∈ A. We say that • A is the domain of f, • B is the codomain of f. • If f(a) = b, we say that b is the image of a and a is a preimage of b. • The range, or image, of f is the set of all images of ele- ments of A.

Given two sets A and B, • a relation R between A and B is a subset of A × B. • a function from A to B must be a relation, but the inverse does not hold in general. Definition 2.1.3. Let A and B be two sets. The function f : A → B is called • one-to-one, or an injunction, if and only if f(a) = f(b) implies that a = b for all a and b in the domain of f.

32 • onto, or a surjection, if and only if for every element b ∈ B there is an element a ∈ A with f(a) = b. • one-to-one correspondence, or a bijection, if it is both one- to-one and onto.

Definition 2.1.4. Let A, B, and C be three sets. • Let f : A → B be bijective. The inverse function of f, denoted by f −1, is the function that assigns to an element b ∈ B the unique element a ∈ A such that f(a) = b. • Let g : A → B and let f : B → C. The composition of the functions f and g, denoted f ◦ g, is defined by (f ◦ g)(a) = f(g(a))

Let A, B, and C be three sets.

33 • Let R ⊆ A × B, then the inverse relation of R, denoted by R−1, is a subset of B × A such that (b, a) ∈ R−1 iff (a, b) ∈ R, which is a relation between B and A.

• Let R1 ⊆: A × B and R2 ⊆ B × C. The composition of the relations R1 and R2, denoted R1 ◦ R2, is defined by

(R1 ◦ R2) = {(a, c) | ∃b.(a, b) ∈ R1 ∧ (b, c) ∈ R2}

Definition 2.1.5 (Some Notations). Let A and B be two sets. • For a function f : A → B, and a set D ⊆ A, we use f|D : D → B to denote the function f with domain restrict- ed to the set D. • A partial function f from a set A to a set B is an assign- ment to each element a ∈ D ⊆ A, called the domain of definition of f, of a unique element b ∈ B. We say that f is undefined for elements in A \ D. When D = A, we say that f is a total function.

Definition 2.1.6. Consider the set U = 2AP of all assignments. The semantic bracket is a function · : PL → 2U defined by: J K • p = {σ ∈ U | p ∈ σ}, J K 34 • ¬ϕ = ϕ , J K J K • ϕ → ψ = ϕ ∪ ψ . J K J K J K Is · injective, surjective, or bijective? J K

Definition 2.1.7 (Currying). Let A1,...,An and B be sets

0 • for any f ∈ A1 × A2 × · · · An → B, there exists f ∈ A1 → (A2 → · · · (An → B) ··· ), such that for any (a1, ··· , an) ∈ 0 A1 × · · · × An, it follows f(a1, ··· , an) = f (a1)(a2) ··· (an).

0 • Conversely, for any f ∈ A1 → (A2 → · · · (An → B) ··· ), there exists f ∈ A1 × A2 × · · · An → B, such that for any 0 (a1, ··· , an) ∈ A1 × · · · An, it follows f (a1)(a2) ··· (an) = f(a1, ··· , an).

35 2.2 Cardinality, Diagonalization Argument

Definition 2.2.1. Let A and B be two sets. • The sets A and B have the same cardinality if and only if there is a one-to-one correspondence from A to B. When A and B have the same cardinality, we write |A| = |B|. • If there is a one-to-one function from A to B, the cardinal- ity of A is less than or the same as the cardinality of B and we write |A| ≤ |B|. Moreover, when |A| ≤ |B| and A and B have different cardinality, we say that the cardinality of A is less than the cardinality of B and we write |A| < |B|.

Definition 2.2.2. A set that is either finite or has the same cardinality as the set of positive integers is called countable.A set that is not countable is called uncountable. When an infinite set S is countable, we denote the cardinality of S by ℵ0. We write |S| = ℵ0 and say that S has cardinality aleph null.

36 Theorem 2.2.3 (SCHRODER-BERNSTEIN¨ THEOREM). If A and B are sets with |A| ≤ |B| and |B| ≤ |A|, then |A| = |B|.

37 Lemma 2.2.4. Prove that 1. The union, intersection of countable sets is countable.

2. The set N2 is countable. 3. The set Z of integer numbers is countable. 4. The set Q of rational numbers is countable. 5. The set Nc with c ∈ N is countable. 6. The countable union of countable sets is countable.

7. The set N∗ is countable.

38 Lemma 2.2.5. Prove that 1. |[0, 1]| = |(0, 1]| = |[0, 1)| = |(0, 1)|. 2. |(0, 1]| = |[1, ∞)|.

3. |[0, 1]| = |[0, k]| = |[0, ∞)| = |R|. 4. |{0, 1}ω| = |[0, 1]|.

5. |2N| = |{0, 1}ω|.

6. |2N| = |{ f | f : N → {0, 1} }|.

39 Lemma 2.2.6 (Cantor diagonalization argument).

• The set R of real numbers is uncountable. • For a set A, it holds: |A| < |2A|. Exercise

• Prove R is uncountable.

• Prove (ϕ1 → ψ1) ∨ (ϕ2 → ψ2) ` (ϕ1 → ψ2) ∨ (ϕ2 → ψ1). • Prove (ϕ ∧ ψ) → θ, θ → χ, ψ ∧ ¬χ ` ¬ϕ.

40 Chapter 3

First Order Logic (FOL)

3.1 Syntax of FOL

Propositional logic is a coarse language, which only concerns about propositions and boolean connectives. Practically, this logic is not powerful enough to describe important properties we are interested in. Example 3.1.1 (Syllogism of Aristotle). Consider the following assertions: 1. All men are mortal. 2. Socrates is a man. 3. So Socrates would die. ∀x(Man(x) → Mortal(x)) Definition 3.1.2. First order logic is an extension of proposi- tion logic: 1. To accept parameters, it generalized propositions to predi- cates.

41 2. To designate elements in the domain, it is equipped with functions and constants. 3. It also involves quantifiers to capture infinite conjunction and disjunction.

Definition 3.1.3. We are given:

• an arbitrary set of variable symbolsVS = {x, y, x1,... }; • an arbitrary set (maybe empty) of function symbolsFS = {f, g, f1,... }, where each symbol has an arity; • an arbitrary set (maybe empty) of predicate symbolsPS = {P, Q, P1,... }, where each symbol has an arity; • an equality symbol set ES which is either empty or one element set containing {≈}. Let L = VS ∪ {(, ), →, ¬, ∀} ∪ FS ∪ PS ∪ ES. Here VS ∪ {(, ), →, ¬, ∀} are referred to as logical symbols, and FS ∪ PS ∪ ES are referred to as non-logical symbols. We often make use of the

• set of constant symbols, denoted by CS = {a, b, a1,... } ⊆ FS, which consist of function symbols with arity 0;

42 • set of propositional symbols, denoted by PS = {p, q, p1,... } ⊆ FS, which consist of predicate symbols with arity 0.

Definition 3.1.4 (FOL terms). The terms of the first order logic are constructed according to the following grammar:

t ::= x | ft1 . . . tn where x ∈ VS, and f ∈ FS has arity n. Accordingly, the set T of terms is the smallest set satisfying the following conditions: • each variable x ∈ VS is a term.

• Compound terms: ft1 . . . tn is a term (thus in T ), provided that f is a n-arity function symbol, and t1, . . . , tn ∈ T . Particularly, a ∈ CS is a term.

We often write f(t1, . . . , tn) for the compound terms.

43 Definition 3.1.5 (FOL formulas). The well-formed formulas of the first order logic are constructed according to the following grammar:

ϕ ::= P t1 . . . tn | ¬ϕ | ϕ → ϕ | ∀xϕ where t1, . . . , tn are terms, P ∈ PS has arity n, and x ∈ VS. We often write P (t1, . . . , tn) for clarity. Accordingly, the set FOF of first order formulas is the smallest set satisfying:

• P (t1, . . . , tn) ∈ FOF is a formula, referred to as the atomic formula. • Compound formulas: (¬ϕ) (negation), (ϕ → ψ) (impli- cation), and (∀xϕ) (universal quantification) are formulas (thus in FOF ), provided that ϕ, ψ ∈ FOF . We omit parentheses if it is clear from the context. As syntactic sugar, we can define ∃xϕ as ∃xϕ := ¬∀x¬ϕ. We assume that ∀ and ∃ have higher precedence than all logical operators.

44 Examples of first-order logics 1. Mathematical theories:

• Presburger Arithmetic hN, 0, 1, +, =,

• Alternatively, let f (f(x) is the father of x) be a unary function symbol. Consider ∀x(S(x; f(me)) → B(x; me)).

45 • Translating an English sentence into predicate logic can be tricky. Definition 3.1.6 (Sub-formulas). For a formula ϕ, we define the sub-formula function Sf : FOF → 2FOF as follows:

Sf (P (t1, . . . , tn)) = {P (t1, . . . , tn)} Sf (¬ϕ) = {¬ϕ} ∪ Sf (ϕ) Sf (ϕ → ψ) = {ϕ → ψ} ∪ Sf (ϕ) ∪ Sf (ψ) Sf (∀xϕ) = {∀xϕ} ∪ Sf (ϕ) Sf (∃xϕ) = {∃xϕ} ∪ Sf (ϕ)

Definition 3.1.7 (Scope). The part of a logical expression to which a quantifier is applied is called the scope of this quantifier. Formally, each sub-formula of the form Qxψ ∈ Sf (ϕ), the scope of the corresponding quantifier Qx is ψ. Here Q ∈ {∀, ∃}.

46 Substitution for Terms Definition 3.1.8 (Sentence). We say an occurrence of x in ϕ is free if it is not in scope of any quantifiers ∀x (or ∃x). Otherwise, we say that this occurrence is a bound occurrence. If a variable ϕ has no free variables, it is called a closed formula, or a sentence.

Definition 3.1.9 (Substitution). The substitution of x with t x within ϕ, denoted as St ϕ, is obtained from ϕ by replacing each free occurrence of x with t.

47 We would extend this notation to Sx1,...,xn ϕ. t1,...,tn Remark 3.1.10. It is important to remark that Sx1,...,xn ϕ is not t1,...,tn the same as Sx1 ...Sxn ϕ: the former performs a simultaneous t1 tn substitution. For example, consider the formula P (x, y): the subsitution x,y x,y Sy,x P (x, y) gives Sy,x P (x, y) = P (y, x) while the substitutions x y x y x Sy SxP (x, y) give Sy SxP (x, y) = Sy P (x, x) = P (y, y).

Remark 3.1.11. Consider ϕ = ∃y(x < y) in the number theory. x What is St ϕ for the special case of t = y? Definition 3.1.12 (Substitutable on Terms). We say that t is substitutable for x within ϕ iff for each variable y occurring in t, there is no free occurrence of x in scope of ∀y/∃y in ϕ.

48 Definition 3.1.13 (α-β condition). If the formula ϕ and the variables x and y fulfill: 1. y has no free occurrence in ϕ, and 2. y is substitutable for x within ϕ, then we say that ϕ, x and y meet the α-β condition, denoted as C(ϕ, x, y).

y x Lemma 3.1.14. If C(ϕ, x, y), then SxSy ϕ = ϕ.

49 3.2 The Axiom System: the Hilbert’s System

As for propositional logic, also FOL can be axiomatized. Definition 3.2.1 (Axioms). 1. ϕ → (ψ → ϕ) 2. (ϕ → (ψ → η)) → ((ϕ → ψ) → (ϕ → η)) 3. (¬ϕ → ¬ψ) → (ψ → ϕ)

x 4. ∀xϕ → St ϕ if t is substitutable for x within ϕ 5. ∀x(ϕ → ψ) → (∀xϕ → ∀xψ) 6. ϕ → ∀xϕ if x is not free in ϕ

7. ∀x1 ... ∀xnϕ if ϕ is an instance of (one of) the above axioms

ϕ → ψ ϕ MP Rule: ψ

50 Definition 3.2.2 (Syntactical Equivalence). We say ϕ and ψ are syntactically equivalent iff ϕ ` ψ and ψ ` ϕ.

Theorem 3.2.3. (Gen): If x has no free occurrence in Γ, then Γ ` ϕ implies Γ ` ∀xϕ.

Solution. Suppose that ϕ0, ϕ1, . . . , ϕn = ϕ is the deductive se- quence of ϕ from Γ.

• If ϕi is an instance of some axiom, then according to (A7), ∀xϕi is also an axiom.

• If ϕi ∈ Γ, since x is not free in Γ, we have ` ϕi → ∀xϕi according to (A6). Therefore, we have Γ ` ∀xϕi in this case.

• If ϕi is obtained by applying (MP) to some ϕj and ϕk = ϕj → ϕi. By induction, we have Γ ` ∀xϕj and Γ ` ∀x(ϕj → ϕi). With (A5) and (MP), we also have Γ ` ∀xϕi in this case.

Thus, we have Γ ` ∀xϕn, i.e., Γ ` ∀xϕ.

51 Exercise 3.2.4. Prove that 1. ∀x∀yϕ ` ∀y∀xϕ, 2. ∃x∀yϕ ` ∀y∃xϕ.

Exercise 3.2.5. Prove that 1. ∀x(ϕ → ψ) ` ∀x(¬ψ → ¬ϕ), 2. ∀x(ϕ → ψ) ` ∃xϕ → ∃xψ.

52 Exercise 3.2.6. Prove that 1. If Γ ` ϕ and Γ ` ¬ψ, then Γ ` ¬(ϕ → ψ), 2. ∀x¬(ϕ → ψ) ` ¬(ϕ → ∃xψ).

x Lemma 3.2.7. (Ren): If C(ϕ, x, y), then ∀xϕ and ∀ySy ϕ are syntactical equivalent. That is,

x 1. ∀xϕ ` ∀ySy ϕ. x 2. ∀ySy ϕ ` ∀xϕ.

53 ϕ Lemma 3.2.8. (RS): Let ηψ denote the formula obtained by replacing (some or all) ϕ inside η by ψ. ϕ ϕ If ϕ ` ψ and ψ ` ϕ then η ` ηψ and ηψ ` η. Solution. By induction on the structure of η.

∀xϕ Lemma 3.2.9. If C(ϕ, x, y) and Γ ` ψ, then Γ ` ψ x . ∀ySy ϕ Solution. An immediate result of (Ren) and (RS).

54 x Theorem 3.2.10. (GenC) If Γ ` Sa ϕ where a does not occur in Γ ∪ {ϕ}, then Γ ` ∀xϕ.

55 3.3 Semantics of FOL

To give semantics of terms/formulas of first order logic, we need an appropriate structure in which interpret the functions and predicates of FOL.

Definition 3.3.1. A Tarski structure is a pair I = hD, Ii, where: •D is a non-empty set, called the domain. • For each n-ary function f, we have I(f) ∈ Dn → D. • For each n-ary predicate P , we have I(P ) ∈ Dn → {0, 1}. Thus, for each constant a, we have I(a) ∈ D.

Definition 3.3.2. Given a Tarski structure I = hD, Ii, an assignment σ under I is a mapping σ : VS → D. We use ΣI to denote the set consisting of assignments under I .

56 Definition 3.3.3. Let I = hD, Ii and σ ∈ ΣI . Each term t is interpreted to an element I (t)(σ) belonging to D: • If t = x is a variable, then I (t)(σ) = σ(x).

• If t = f(t1, . . . , tn) where f is an n-ary function, then I (t)(σ) = I(f)(I (t1)(σ),..., I (tn)(σ)). Thus, if t = a is a constant, then I (t)(σ) = I(a).

Definition 3.3.4. Each formula ϕ has a truth value I (ϕ)(σ) ∈ {0, 1}:

• If ϕ = P (t1, . . . , tn), where P is an n-ary predicate, then I (ϕ)(σ) = I(P )(I (t1)(σ),..., I (tn)(σ)).

57 • If ϕ = ¬ψ, then I (ϕ)(σ) = 1 − I (ψ)(σ). • If ϕ = ψ → η, then ( 1 if I (ψ)(σ) = 0 or I (η)(σ) = 1, I (ϕ)(σ) = 0 if I (ψ)(σ) = 1 and I (η)(σ) = 0.

• If ϕ = ∀xψ, then ( 1 if I (ψ)(σ[x/d]) = 1 for each d ∈ D, I (ϕ)(σ) = 0 if I (ψ)(σ[x/d]) = 0 for some d ∈ D where σ[x/d] is a new assignment defined as ( σ(y) if y 6= x, σ[x/d](y) = d if y = x.

We write (I , σ) ϕ if I (ϕ)(σ) = 1.

58 Theorem 3.3.5 (Theorem of Substitution). Suppose that t is substitutable for x within ϕ, then

x (I , σ) St ϕ if and only if (I , σ[x/I (t)(σ)]) ϕ.

59 We say that I is a model of ϕ, denoted as I ϕ, if (I , σ) ϕ for each σ ∈ ΣI . In particular, we say that I = hD, Ii is a frugal model of ϕ if |D| is not more than the cardinality of the language. Recall that ϕ is a sentence, if there is no free variable occur- ring in ϕ. Theorem 3.3.6. If ϕ is a sentence, then

• I ϕ iff (I , σ) ϕ for some σ ∈ ΣI .

Definition 3.3.7. Let ϕ, ψ be FOL formulas and Γ be a set of FOL formulas. Then we define:

• (I , σ) Γ if for each η ∈ Γ, (I , σ) η;

• Γ |= ϕ if for each I and σ ∈ ΣI , (I , σ) Γ implies (I , σ) ϕ; • ϕ and ψ are equivalent if {ϕ} |= ψ and {ψ} |= ϕ; • ϕ is valid if ∅ |= ϕ.

60 Definition 3.3.8 (Tautology for FOL). For a formula ϕ ∈ FOL, we construct ϕ0 as follows: • for each sub-formula ψ of ϕ which is either an atomic for- mula, or a formula of the form ∀xη, we replace it with a corresponding propositional variable pψ. If ϕ0 is a tautology in propositional logic, then we say ϕ is a tautology for FOL.

Definition 3.3.9 (Prenex Normal Form (PNF)). A formula is in prenex normal form if and only if it is of the form Q1x1Q2x2 ...QkxkP (x1, x2, . . . , xk), where each Qi, i = 1, 2, ... , k is either the existential quantifi- er or the universal quantifier, and P (x1, . . . , xk) is a predicate involving no quantifiers.

61 Question: can we transform a formula into an equivalent P- NF form?

3.4 A Sound and Complete Axiomatization for FOL without Equality ≈

3.4.1 The Axiom System: Soundness Similarly to propositional logic, for FOL we have the soundness property: Theorem 3.4.1. If Γ ` ϕ, then Γ |= ϕ. Hint. For proving the theorem, show and make use of the fol- lowing results: • {∀x(ϕ → ψ), ∀xϕ} |= ∀xψ; • if x is not free in ϕ, then ` ϕ → ∀xϕ. Corollary 3.4.2. If ` ϕ, then |= ϕ.

62 3.4.2 The Axiom System: Completeness A Hintikka set Γ is a set of FOL formulas fulfilling the following properties:

1. For each atomic formula ϕ (i.e, ϕ = P (t1, . . . , tn), where n ≥ 0), either ϕ∈ / Γ or ¬ϕ∈ / Γ. 2. ϕ → ψ ∈ Γ implies that either ¬ϕ ∈ Γ or ψ ∈ Γ. 3. ¬¬ϕ ∈ Γ implies that ϕ ∈ Γ. 4. ¬(ϕ → ψ) ∈ Γ implies that ϕ ∈ Γ and ¬ψ ∈ Γ.

x 5. ∀xϕ ∈ Γ implies that St ϕ ∈ Γ for each t which is substi- tutable for x within ϕ. 6. ¬∀xϕ ∈ Γ implies that there is some t with C(ϕ, x, t) such x that ¬St ϕ ∈ Γ. Note: C(ϕ, x, t) iff C(ϕ, x, y) for all y occurring in t. Lemma 3.4.3. A Hintikka set Γ is consistent, and moreover, for each formula ϕ, either ϕ 6∈ Γ, or ¬ϕ 6∈ Γ. Theorem 3.4.4. A Hintikka set Γ is satisfiable, i.e, there is some interpretation I and some σ ∈ ΣI such that (I , σ) ϕ for each ϕ ∈ Γ.

63 Theorem 3.4.5. If Γ is a set of FOL formulas, then “Γ is consistent” implies that “Γ is satisfiable”. Particularly, if Γ consists only of sentences, then Γ has a frugal model.

1 Proof. Let us enumerate the formulas as ϕ0, ϕ1, . . . , ϕn,..., and subsequently define a series of formula sets as follows. Let Γ0 = Γ, and

Γ ∪ {¬ϕ } if Γ ` ¬ϕ  i i i i Γi+1 = Γi ∪ {ϕi} if Γi 6` ¬ϕi and ϕi 6= ¬∀xψ  x Γi ∪ {ϕi, ¬Sa ψ} if Γi 6` ¬ϕi, and ϕi = ¬∀xψ Above, for each formula ∀xψ, we pick and fix the constant a which does not occur in Γi ∪ {ϕi}.

1We assume the language to be countable, yet the result can be extended to languages with arbitrary cardinality.

64 ∗ Finally let Γ = lim Γi. i→∞ If Γ is consistent, the set Γ∗ is maximal and consistent, and is referred to as the Henkin set. Thus, a Henkin set is also a Hintikka set.

65 Theorem 3.4.6. If Γ |= ϕ, then Γ ` ϕ. Corollary 3.4.7. If |= ϕ, then ` ϕ. Theorem 3.4.8. Γ is consistent iff each of its finite subset is consistent. Moreover, Γ is satisfiable iff each of its finite subsets is satisfiable.

66 3.5 A Sound and Complete Axiomatization for FOL with Equality ≈

The axiomatization based on the Hilbert’s systems seen in the previous section can be extended to the case of first order logic with the equality ≈. To do this, two additional axioms have to be included in the Hilbert’s system:

A≈: x ≈ x;

0 x A≈: (x ≈ y) → (α → αy ), where α is an atomic formula. The soundness and completeness results can be proved sim- ilarly in the extended Hilbert’s system; note that for the com- pleteness one, a variation of the Tarski structure is required, namely, the domain considered in the construction modulo the relation ≈. This allows us so manage correctly the formulas that are equivalent under ≈. The actual details about the above construction are omitted; the interested reader is invited to formalize them.

67 68 3.6 Exercises

Let A be a finite alphabet, such as the English alphabet, and consider the following simple programming language WHILE whose well-formed programs are those obtained by applying the rules of the following grammar:

Numbers:

Num ::= d | dNum where d ∈ {0, 1,..., 9}

Identifiers:

Id ::= aId 0 where a ∈ A Id 0 ::= λ | aId 0 | NumId 0

Numeric expressions:

Exp ::= Num | Id | Exp + Exp | Exp − Exp | Exp ∗ Exp | Exp/Exp

Boolean expressions:

BExp ::= true | false | Exp = Exp | ¬BExp | BExp ∧ BExp | BExp ∨ BExp

Programs:

P ::= skip | Id := Exp | P ; P | if BExp then P else P fi | while BExp do P done

69 Exercise 3.6.1. Show, by providing the appropriate functions, that the set of identifiers has the same cardinality as N.

Exercise 3.6.2. Show that the set of all well-formed WHILE programs is countable.

Exercise 3.6.3. Show the following statements: 1. If A is an uncountable set and B is a countable set, then |A \ B| = |A|.

2. Let I be the set of irrational numbers, i.e., I = { r ∈ R | r∈ / Q }. Then |{0, 1}ω \{0, 1}∗0ω| = |I ∩ [0, 1]|. 3. |{0, 1}ω| = |[0, 1]|. 4. |[0, 1]| = |[0, 1] × [0, 1]| = |[0, 1]n| for each n ≥ 1.

70 Hint. For point 3, make use of points 1 and 2; for point 4, make use of point 3. Exercise 3.6.4. Consider the semantic bracket operator pre- sented in Definition 2.1.6 of the lecture notes. Show that |= ϕ → ψ iff ϕ ⊆ ψ . J K J K

Exercise 3.6.5. Let Q1 ⊆ FOL be the set of FOL formulas ϕ such that each quantifier operator Qx (with Q ∈ {∀, ∃} and x ∈ VS) appears at most once in ϕ. Provide a function Scope, including its type, such that, given a quantifier operator Qx (with Q ∈ {∀, ∃} and x ∈ VS) and a formula ϕ ∈ Q1, it returns the formula corresponding to the scope of Qx.

71 Exercise 3.6.6. Given ϕ, ψ, η ∈ FOL, 1. provide a function #, including its type, that returns how many times ψ occurs in ϕ as sub-formula;

2. provide a function R∞, including its type, that replaces each occurrence of ϕ in η with ψ;

3. provide a function R1, including its type, that replaces ex- actly one occurrence of ϕ in η with ψ if ϕ occurs in η, and that returns η if ϕ does not occur in η. If ϕ occurs in η mul- tiple times, then there is no requirement on the particular instance to be replaced.

Exercise 3.6.7. Prove the following:

72 1. For any predicate P with arity 2, ∀x∀yP (x, y) ` ∀y∀zP (y, z). 2. Assume x is not free in ϕ, then ϕ → ∀xψ and ∀x(ϕ → ψ) are syntactically equivalent. 3. We say a formula ϕ has repeated occurrences of a bound variable x, if Qx appears more than once in the sub-formulas of ϕ (recall Q ∈ {∀, ∃}). Prove that there exists a formula ϕ0 which has no repeated occurrences of any bound variable such that ϕ and ϕ0 are syntactically equivalent.

Exercise 3.6.8. Prove the following: Q1 ¬∀xϕ `a ∃x¬ϕ; and ¬∃xϕ `a ∀x¬ϕ. Q2 ∀xϕ ∧ ψ `a ∀x(ϕ ∧ ψ, if x does not occur in ψ. Q3 ∃xϕ ∨ ∃xψ `a ∃x(ϕ ∨ ψ).

73 Exercise 3.6.9. Let S be a binary predicate symbol, P and Q unary predicate symbols. Prove the following: Q1 ∃x∃y(S(x, y) ∨ S(y, x)) ` S(x, y). Q2 ∀x∀y∀z(S(x, y)∧S(y, z) → S(x, z)), ∀x¬S(x, x) ` ∀x∀y(S(x, y) → ¬S(y, x)). Q3 ∃x∃y(S(x, y) ∨ S(y, x)), ¬∃xS(x, x) ` ∃x∃y(x 6= y). Q4 ∀x(P (x) ∨ Q(x)) ` ∀xP (x) ∨ ∀Q(x) is not provable.

Exercise 3.6.10. Prove Lemma 3.4.3: a Hintikka set Γ is con- sistent, and moreover, for each formula ϕ, either ϕ 6∈ Γ, or ¬ϕ 6∈ Γ.

74 Exercise 3.6.11. Given a formula ϕ, let H(ϕ) be the set of Hintikka sets containing ϕ, that is, H(ϕ) = { Γ ⊆ FOF | ϕ ∈ Γ and Γ is a Hintikka set }. We say that Γ ∈ H(ϕ) is min- imal if, for each Γ0 ∈ H(ϕ), it holds that Γ0 ⊆ Γ implies Γ0 = Γ; we denote by m(ϕ) the set of minimal Hintikka sets in H(ϕ), that is, m(ϕ) = { Γ ∈ H(ϕ) | Γ is minimal }.

1. Provide a minimal Hintikka set Γϕ ∈ m(ϕ) for the formula ϕ = ∀x∀y(¬(x ≈ y) → (R(x, y) → ¬R(y, x)))

under the assumption that VS = {x, y}, FS = CS = {a, b}, PS = {R}, and ES = {≈}. 2. Prove that H(ϕ) ∩ H(¬ϕ) = ∅ for each ϕ ∈ FOF . 3. Let PL ⊆ FOF be the set of FOL formulas in which each predicate appears at most once and in which no quantifier Q ∈ {∀, ∃} occurs. Define a function c: PL → N such that, for each ϕ ∈ PL, returns the number of different minimal Hintikka sets containing ϕ.

75