discrete mathematics1 znj/dm2017lcs.ios.ac.cn/~znj/dm2017/lecture-notes-chapter2.pdf2. basic...

41
Discrete Mathematics 1 http://lcs.ios.ac.cn/˜znj/DM2017 Naijun Zhan March 6, 2017 1 Special thanks to Profs Hanpin Wang (PKU) and Lijun Zhang (ISCAS) for their courtesy of the slides on this course.

Upload: others

Post on 30-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Discrete Mathematics1

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

Naijun Zhan

March 6, 2017

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

Page 2: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

Page 3: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Chapter 1

The Foundations: Logic andProofs

Logic in Computer Science

During the past fifty years there has been extensive, continuous,and growing interaction between logic and computer science. Inmany 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 ofcomputer science. The argument is that logic plays a fundamen-tal role in computer science, similar to that played by calculusin 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

Page 4: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

• 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 isthis proof correct/incorrect?”

• Boolean algebra owes to George Boole.

• Now, we are interested in: “is the program correct?”

3

Page 5: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

1.1 Propositional Logic – An Appetizer

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

Definition 1.1.2 (Propositional Logic). Fix a countable propo-sition set 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

Page 6: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

For p ∈ AP , negation and conjunction, we can construct thetruth 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

Page 7: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Definition 1.1.4 (Logic and Bit Operators).

• A bit is a symbol with possible values 0 and 1. A Booleanvariable 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 lengthof this string is the number of bits in the string.

• Bitwise OR, bitwise AND and bitwise XOR of two stringsof the same length are the strings that have as their bits theOR, AND and XOR of the corresponding bits in the twostrings, respectively.

6

Page 8: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

1.2 Applications of Propositional Logic

Definition 1.2.1 (Applications).

• System Specifications: The automated reply cannot be sentwhen 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 computerhardware. 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

Page 9: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

1.3 Propositional Equivalences

A formula ϕ is called a

• tautology if it is always true, no matter what the truthvalues 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 ϕ ↔ ψ isa 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

Page 10: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

Page 11: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Definition 1.3.2 (Logical Equivalence). Logical equivalencesinvolving 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

Page 12: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

1.4 Induction and Recursion

PRINCIPLE OF MATHEMATICAL INDUCTION To prove thatP (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 prooftechnique 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

Page 13: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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 allpositive integers k.

Expressed as a rule of inference for first-order logic, this prooftechnique can be stated as:

Ψ := (P (1) ∧ ∀k.(∧ki=1P (i)→ P (k + 1)))→ ∀n.P (n)

Exercise 1.4.2. Prove that if n is a natural number greater than1, then n can be written as the product of primes.

12

Page 14: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Recursively Defined Sets and Structures and StructuralInduction

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 formulasin 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-formedformulas.

Thus, the set of well-formed formulas is a subset of L ⊆ Σ∗.

13

Page 15: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

STRUCTURAL INDUCTION A proof by structural in-duction consists of two parts.

• BASIS STEP: Show that the result holds for all elementsspecified in the basis step.

• RECURSIVE STEP: Show that if the statement is true foreach of the elements used to construct new elements in therecursive step of the definition, the result holds for thesenew elements.

Remark: The validity of structural induction follows from theprinciple of mathematical induction for the nonnegative integers.

Exercise 1.4.5. Show that every well-formed formula for com-pound propositions contains an equal number of left and rightparentheses.

14

Page 16: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

1.5 Normal Forms

Negation Normal Form

• Literal: An atomic proposition p or its negation ¬p;

• Negation Normal Form (NNF): A formula built upwith “∧”, “∨”, and literals.

• Using repeated DeMorgan and Double Negation, we cantransform any formula into a formula with Negation NormalForm.

• 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 formulacan 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

Page 17: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Conjunction Normal Form

• Conjunction Normal Form (CNF): A generalized con-junction of generalized disjunctions of literals.

• Using repeated distribution of ∨ over ∧, any NNF formulacan 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

Page 18: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

Page 19: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

1.6 Propositional Logic and Deduction Sys-

tems: a Sound and Complete Axiomati-

zation

This section considers a complete axiomatization system suchthat, a formula is a tautology if and only if it can be derived bymeans 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 inBNF (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

Page 20: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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) toothers. Thus, it can also be viewed as a function from AP to{T,F}.

Definition 1.6.2 (Semantics). Inductively, we may define therelation ⊆ 2AP × 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

Page 21: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

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

ψ

Given a formula set Γ, a deductive sequence of ϕ from Γ is asequence

ϕ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

Page 22: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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 consequentof Γ, denoted as Γ |= ϕ, if σ Γ implies σ ϕ for eachassignment σ.

Thus, ϕ is a tautology if ϕ is the logical consequent of ∅,denoted as |= ϕ.

Theorem 1.6.5 (Soundness). With Hilbert’s axiom system, wehave 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 elementaryproperties:

(Fin) If Γ ` ϕ, then there exists some finite subset Γ′ of Γ, suchthat Γ′ ` ϕ.

(∈) If ϕ ∈ Γ, then Γ ` ϕ.

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

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

21

Page 23: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

Page 24: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

Page 25: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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 Γ isconsistent, iff there is some ϕ such that Γ 6` ϕ. Moreover, wesay ϕ is consistent w.r.t. Γ iff Γ ∪ {ϕ} is consistent.

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

24

Page 26: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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 ϕ → ¬ϕ ` ¬ϕ, andthis implies Γ ` ¬ϕ, contradiction!

Lemma 1.6.19. If the formula set Γ is inconsistent, then it hassome 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 propositionalformulas as following (note the cardinality of all such formulasis ℵ0):

ϕ0, ϕ1, . . . , ϕn, . . .

Let Γ0 = Γ and

Γi+1 =

{Γi ∪ {ϕi} if Γi 6` ¬ϕi

Γi ∪ {¬ϕi} otherwise

and finally let Γ∗ = limi→∞

Γ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

Page 27: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Theorem 1.6.21 (Completeness). If Γ |= ϕ, then Γ ` ϕ.

Proof. Assume by contradiction that Γ 6` ϕ, then there is anassignment σ such that σ Γ ∪ {¬ϕ}. However, this impliesthat σ Γ 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 previouslemma).

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

Page 28: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

27

Page 29: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Exercise 1.6.24. Show, by applying the rules of the deductionsystem 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 ofsome 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

Page 30: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

29

Page 31: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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 subsetsof 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

Page 32: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

31

Page 33: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

Definition 2.1.2. Let A and B be nonempty sets. A functionf : A→ B from A to B is an assignment of exactly one elementof B to each element of A. We write f(a) = b if b ∈ B isassigned 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 apreimage 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 inversedoes not hold in general.

Definition 2.1.3. Let A and B be two sets. The functionf : 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

Page 34: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

• onto, or a surjection, if and only if for every element b ∈ Bthere 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 elementb ∈ B the unique element a ∈ A such that f(a) = b.

• Let g : A → B and let f : B → C. The composition of thefunctions f and g, denoted f ◦ g, is defined by

(f ◦ g)(a) = f(g(a))

Let A, B, and C be three sets.

33

Page 35: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

• Let R ⊆ A × B, then the inverse relation of R, denotedby 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 therelations 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 usef |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 ofdefinition of f , of a unique element b ∈ B. We say that fis undefined for elements in A \D. When D = A, we saythat f is a total function.

Definition 2.1.6. Consider the set U = 2AP of all assignments.The semantic bracket is a function J · K : PL→ 2U defined by:

• JpK = {σ ∈ U | p ∈ σ},

34

Page 36: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

• J¬ϕK = JϕK,

• Jϕ→ ψK = JϕK ∪ JψK.

Is J · K injective, surjective, or bijective?

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

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

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

35

Page 37: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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 ifthere is a one-to-one correspondence from A to B. WhenA 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 andwe write |A| ≤ |B|. Moreover, when |A| ≤ |B| and A andB have different cardinality, we say that the cardinality ofA 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 samecardinality as the set of positive integers is called countable. Aset that is not countable is called uncountable. When an infiniteset S is countable, we denote the cardinality of S by ℵ0. We write|S| = ℵ0 and say that S has cardinality aleph null.

36

Page 38: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

37

Page 39: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

Page 40: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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

Page 41: Discrete Mathematics1 znj/DM2017lcs.ios.ac.cn/~znj/DM2017/Lecture-notes-chapter2.pdf2. Basic Structures: Sets, Functions, Sequences, Sum-s, and Matrices 3. Algorithms 4.Number Theory

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