Discrete Mathematics I, Study notes of Discrete Mathematics

This course will develop the intuition for discrete mathematics reasoning involving numbers and sets. Lectures. • Logic.

Typology: Study notes

2021/2022

Uploaded on 08/01/2022

fabh_99
fabh_99 🇧🇭

4.4

(53)

543 documents

1 / 64

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Discrete Mathematics I
Computer Science Tripos, Part 1A
Paper 1
Natural Sciences Tripos, Part 1A,
Computer Science option
Politics, Psychology and Sociology, Part 1,
Introduction to Computer Science option
2009–10
Peter Sewell
Computer Laboratory
University of Cambridge
Time-stamp: <2009-11-01 13:25:09 pes20>
c
Peter Sewell 2008, 2009
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40

Partial preview of the text

Download Discrete Mathematics I and more Study notes Discrete Mathematics in PDF only on Docsity!

Discrete Mathematics I

Computer Science Tripos, Part 1A

Paper 1

Natural Sciences Tripos, Part 1A,

Computer Science option

Politics, Psychology and Sociology, Part 1,

Introduction to Computer Science option

Peter Sewell

Computer Laboratory

University of Cambridge

Time-stamp: <2009-11-01 13:25:09 pes20> © cPeter Sewell 2008, 2009

Contents

  • Syllabus
  • For Supervisors
  • Learning Guide
  • 1 Introduction
  • 2 Propositional Logic
    • 2.1 The Language of Propositional Logic
    • 2.2 Equational Reasoning
  • 3 Predicate Logic
    • 3.1 The Language of Predicate Logic
  • 4 Proof
  • 5 Set Theory
    • 5.1 Relations, Graphs, and Orders
  • 6 Induction
  • 7 Conclusion
  • A Recap: How To Do Proofs
    • A.1 How to go about it
    • A.2 And in More Detail...
      • A.2.1 Meet the Connectives
      • A.2.2 Equivalences
      • A.2.3 How to Prove a Formula
      • A.2.4 How to Use a Formula
    • A.3 An Example
      • A.3.1 Proving the PL
      • A.3.2 Using the PL
  • B Exercises
    • Exercise Sheet 1: Propositional Logic
    • Exercise Sheet 2: Predicate Logic
    • Exercise Sheet 3: Structured Proof
    • Exercise Sheet 4: Sets
    • Exercise Sheet 5: Inductive Proof

For Supervisors (and Students too)

The main aim of the course is to enable students to confidently use the language of propo- sitional and predicate logic, and set theory.

We first introduce the language of propositional logic, discussing the relationship to natural- language argument. We define the meaning of formulae with the truth semantics w.r.t. as- sumptions on the propositional variables, and, equivalently, with truth tables. We also introduce equational reasoning using tautologies, to make instantiation and reasoning-in- context explicit.

We then introduce quantifiers, again emphasising the intuitive reading of formulae and defining the truth semantics. We introduce the notions of free and bound variable (but not alpha equivalence).

We do not develop any metatheory, and we treat propositional assumptions, valuations of variables, and models of atomic predicate symbols all rather informally. There are no turnstiles, but we talk about valid formulae and (briefly) about satisfiable formulae.

We then introduce ‘structured’ proof. This is essentially natural deduction proof, but laid out on the page in roughly the box-and-line style used by Bornat (2005). We don’t give the usual horizontal-line presentation of the rules. The rationale here is to introduce a style of proof for which one can easily define what is (or is not) a legal proof, but where the proof text on the page is reasonably close to the normal mathematical ‘informal but rigorous’ practice that will be used in most of the rest of the Tripos. We emphasise how to prove and how to use each connective, and talk about the pragmatics of finding and writing proofs.

The set theory material introduces the basic notions of set, element, union, intersection, powerset, and product, relating to predicates (e.g. relating predicates and set comprehen- sions, and the properties of union to those of disjunction), with some more small example proofs. We then define some of the standard properties of relations (reflexive, symmetric, transitive, antisymmetric, acyclic, total) to characterise directed graphs, undirected graphs, equivalence relations, pre-orders, partial orders, and functions). These are illustrated with simple examples to introduce the concepts, but their properties and uses are not explored in any depth (for example, we do not define what it means to be an injection or surjection).

Finally, we recall inductive proof over the naturals, making the induction principle explicit in predicate logic, and over lists, talking about inductive proof of simple pure functional programs (taking examples from the previous SWEng II notes).

I’d suggest 3 supervisons. A possible schedule might be:

  1. After the first 2–3 lectures (on or after Thurs 19 Nov) Example Sheets 1 and 2, covering Propositional and Predicate Logic
  2. After the next 3–4 lectures (on or after Thurs 26 Nov) Example Sheets 3 and the first part of 4, covering Structured Proof and Sets
  3. After all 8 lectures (on or after Thurs 3 Dec) Example Sheet 4 (the remainder) and 5, covering Inductive Proof

Learning Guide

Notes: These notes include all the slides, but by no means everything that’ll be said in lectures.

Exercises: There are some exercises at the end of the notes. I suggest you do all of them. Most should be rather straightforward; they’re aimed at strengthening your intuition about the concepts and helping you develop quick (but precise) manipulation skills, not to provide deep intellectual challenges. A few may need a bit more thought. Some are taken (or

adapted) from Devlin, Rosen, or Velleman. More exercises and examples can be found in any of those.

Tripos questions: This version of the course was new in 2008.

Feedback: Please do complete the on-line feedback form at the end of the course, and let me know during it if you discover errors in the notes or if the pace is too fast or slow.

Errata: A list of any corrections to the notes will be on the course web page.

Logic and Set Theory — Pure Mathematics

Origins with the Greeks, 500–350 BC, philosophy and geometry: Aristotle, Euclid

Formal logic in the 1800s: De Morgan, Boole, Venn, Peirce, Frege

Set theory, model theory, proof theory; late 1800s and early 1900s: Cantor, Russell, Hilbert, Zermelo, Frankel, Goedel, Turing, Bourbaki, Gentzen, Tarski

Focus then on the foundations of mathematics — but what was developed then turns out to be unreasonably effective in Computer Science. This is the core of the applied maths that we need.

Logic and Set Theory — Applications in Computer Science

  • modelling digital circuits (1A Digital Electronics, 1B ECAD)
  • proofs about particular algorithms and code (1A Algorithms 1, 1B Algorithms 2)
  • proofs about what is (or is not!) computable and with what complexity (1B Computation Theory, Complexity Theory)
  • proofs about programming languages and type systems (1A Regular Languages and Finite Automata, 1B Semantics of Programming Languages, 2 Types)
  • foundation of databases (1B Databases)
  • automated reasoning and model-checking tools (1B Logic & Proof, 2 Specification & Verification)

Outline

  • Propositional Logic
  • Predicate Logic
  • Sets
  • Inductive Proof

Focus on using this material, rather than on metatheoretic study.

More (and more metatheory) in Discrete Maths 2 and in Logic & Proof.

New course last year — feedback welcome.

Supervisons Not rocket science (?), but needs practice to become fluent. Five example sheets. Many more suitable exercises in the books. Up to your DoS and supervisor, but I’d suggest 3 supervisons. A possible schedule might be:

  1. After the first 2–3 lectures (on or after Thurs 19 Nov) Example Sheets 1 and 2, covering Propositional and Predicate Logic
  2. After the next 3–4 lectures (on or after Thurs 26 Nov) Example Sheets 3 and the first part of 4, covering Structured Proof and Sets
  3. After all 8 lectures (on or after Thurs 3 Dec) Example Sheet 4 (the remainder) and 5, covering Inductive Proof

2 Propositional Logic

Propositional Logic

Propositional Logic Starting point is informal natural-language argument:

Socrates is a man. All men are mortal. So Socrates is mortal.

Propositional Logic Starting point is informal natural-language argument:

Socrates is a man. All men are mortal. So Socrates is mortal.

If a person runs barefoot, then his feet hurt. Socrates’ feet hurt. Therefore, Socrates ran barefoot

It will either rain or snow tomorrow. It’s too warm for snow. Therefore, it will rain.

Building Compound Propositions: Truth and Falsity

We’ll write T for the constant true proposition, and F for the constant false proposition.

Building Compound Propositions: Conjunction

If P and Q are two propositions, P ∧ Q is a proposition.

Pronounce P ∧ Q as ‘P and Q’. Sometimes written with & or.

Definition: P ∧ Q is true if (and only if) P is true and Q is true

Examples:

Tom is a student ∧ Tom has red hair (1 + 1 = 2) ∧ (7 ≤ 10) (1 + 1 = 2) ∧ (2 = 3) ((1 + 1 = 2) ∧ (7 ≤ 10)) ∧ (5 ≤ 5) (p ∧ q) ∧ p

Building Compound Propositions: Conjunction

We defined the meaning of P ∧ Q by saying ‘P ∧ Q is true if and only if P is true and Q is true’.

We could instead, equivalently, have defined it by enumerating all the cases, in a truth table :

P Q P ∧ Q T T T T F F F T F F F F

According to this definition , is ((1 + 1 = 2) ∧ (7 ≤ 10)) ∧ (5 ≤ 5) true

or false?

Building Compound Propositions: Conjunction

We pronounce P ∧ Q as ‘P and Q’, but not all uses of the English ‘and’ can be faithfully translated into ∧.

Tom and Alice had a dance.

Grouping

Tom went to a lecture and had lunch.

Temporal ordering?

The Federal Reserve relaxed banking regulations, and the markets boomed.

Causality?

When we want to talk about time or causality in CS, we’ll do so explicitly; they are not built into this logic.

Building Compound Propositions: Conjunction

Basic properties:

The order doesn’t matter: whatever P and Q are, P ∧ Q means the same thing as Q ∧ P.

Check, according to the truth table definition, considering each of the 4 possible cases: P Q P ∧ Q Q ∧ P T T T T T F F F F T F F F F F F

In other words, ∧ is commutative

Building Compound Propositions: Conjunction

...and:

The grouping doesn’t matter: whatever P , Q, and R are, P ∧ (Q ∧ R) means the same thing as (P ∧ Q) ∧ R.

(Check, according to the truth table definition, considering each of the 8 possible cases).

In other words, ∧ is associative

So we’ll happily omit some parentheses, e.g. writing P 1 ∧ P 2 ∧ P 3 ∧ P 4

for P 1 ∧ (P 2 ∧ (P 3 ∧ P 4 )).

Building Compound Propositions: Disjunction

If P and Q are two propositions, P ∨ Q is a proposition.

Pronounce P ∨ Q as ‘P or Q’. Sometimes written with | or +

Definition: P ∨ Q is true if and only if P is true or Q is true

Equivalent truth-table definition:

P Q P ∨ Q T T T T F T F T T F F F

Building Compound Propositions: Implication If P and Q are two propositions, P ⇒ Q is a proposition. Pronounce P ⇒ Q as ‘P implies Q’. Sometimes written with → Definition: P ⇒ Q is true if (and only if), whenever P is true, Q is true Equivalent truth-table definition:

P Q P ⇒ Q T T T T F F F T T F F T

Building Compound Propositions: Implication That can be confusing. First, the logic is not talking about causation, but just about truth values. (1 + 1 = 2) ⇒ (3 < 4) is true Second, P ⇒ Q is vacuously true if P is false. ‘If I’m a giant squid, then I live in the ocean’ For that to be true, either:

(a) I really am a giant squid, in which case I must live in the ocean, or

(b) I’m not a giant squid, in which case we don’t care where I live.

P ⇒ Q and (P ∧ Q) ∨ ¬P and Q ∨ ¬P all have the same meaning

Building Compound Propositions: Implication Basic properties: P ⇒ Q and ¬Q ⇒ ¬P have the same meaning ⇒ is not commutative: P ⇒ Q and Q ⇒ P do not have the same meaning P ⇒ (Q ∧ R) and (P ⇒ Q) ∧ (P ⇒ R) have the same meaning (P ∧ Q) ⇒ R and (P ⇒ R) ∧ (Q ⇒ R) do not (P ∧ Q) ⇒ R and P ⇒ Q ⇒ R do

Building Compound Propositions: Bi-Implication

If P and Q are two propositions, P ⇔ Q is a proposition.

Pronounce P ⇔ Q as ‘P if and only if Q’. Sometimes written with ↔ or =.

Definition: P ⇔ Q is true if (and only if) P is true whenever Q is true, and vice versa

Equivalent truth-table definition:

P Q P ⇔ Q T T T T F F F T F F F T

The Language of Propositional Logic

Summarising, the formulae of propositional logic are the terms of the grammar

P , Q ::= p | T | F | ¬P | P ∧ Q | P ∨ Q | P ⇒ Q | P ⇔ Q

where p ranges over atomic propositions p, q, etc., and we use parentheses (P ) as necessary to avoid ambiguity.

For any such formula P , assuming the truth value of each atomic proposition p it mentions is fixed (true or false), we’ve defined whether P is true or false.

Example Compound Truth Table

Given an arbitrary formula P , we can calculate the meaning of P for all possible assumptions on its atomic propositions by enumerating the

cases in a truth table.

For example, consider P def = ((p ∨ ¬q) ⇒ (p ∧ q)). It mentions two atomic propositions, p and q, so we have to consider 22 possibilities:

p q ¬q p ∨ ¬q p ∧ q (p ∨ ¬q) ⇒ (p ∧ q) T T F T T T T F T T F F F T F F F T F F T T F F

Notice that this calculation is compositional in the structure of P.

Equational Reasoning

Tautologies are really useful — because they can be used anywhere.

In more detail, this P iff Q is a proper notion of equality. You can see from its definition that

  • it’s reflexive , i.e., for any P , we have P iff P
  • it’s symmetric , i.e., if P iff Q then Q iff P
  • it’s transitive , i.e., if P iff Q and Q iff R then P iff R

Moreover, if P iff Q then we can replace a subformula P by Q in any context, without affecting the meaning of the whole thing. For example, if P iff Q then P ∧ R iff Q ∧ R, R ∧ P iff R ∧ Q, ¬P iff ¬Q, etc.

Equational Reasoning

Now we’re in business: we can do equational reasoning, replacing equal subformulae by equal subformulae, just as you do in normal algebraic

manipulation (where you’d use 2 + 2 = 4 without thinking).

This complements direct verification using truth tables — sometimes that’s more convenient, and sometimes this is. Later, we’ll see a third option — structured proof.

Some Collected Tautologies, for Reference

For any propositions P , Q, and R Commutativity: P ∧ Q iff Q ∧ P (and-comm) P ∨ Q iff Q ∨ P (or-comm)

Associativity: P ∧ (Q ∧ R) iff (P ∧ Q) ∧ R (and-assoc) P ∨ (Q ∨ R) iff (P ∨ Q) ∨ R (or-assoc)

Distributivity: P ∧ (Q ∨ R) iff (P ∧ Q) ∨ (P ∧ R) (and-or-dist) P ∨ (Q ∧ R) iff (P ∨ Q) ∧ (P ∨ R) (or-and-dist)

Identity: P ∧ T iff P (and-id) P ∨ F iff P (or-id)

Unit: P ∧ F iff F (and-unit) P ∨ T iff T (or-unit)

Complement: P ∧ ¬P iff F (and-comp) P ∨ ¬P iff T (or-comp)

De Morgan: ¬(P ∧ Q) iff ¬P ∨ ¬Q (and-DM) ¬(P ∨ Q) iff ¬P ∧ ¬Q (or-DM)

Defn: P ⇒ Q iff Q ∨ ¬P (imp) P ⇔ Q = (P ⇒ Q) ∧ (Q ⇒ P ) (bi)

Equational Reasoning — Example

Suppose we wanted to prove a 3-way De Morgan law

¬(P 1 ∧ P 2 ∧ P 3 ) iff ¬P 1 ∨ ¬P 2 ∨ ¬P 3

We could do so either by truth tables, checking 23 cases, or by equational reasoning:

¬(P 1 ∧ P 2 ∧ P 3 ) iff ¬(P 1 ∧ (P 2 ∧ P 3 )) choosing an ∧ association iff ¬P 1 ∨ ¬(P 2 ∧ P 3 ) by (and-DM) (and-DM) is ¬(P ∧ Q) iff ¬P ∨ ¬Q. Instantiating the metavariables P and Q as P 7 → P 1 Q 7 → P 2 ∧ P 3 we get exactly the ¬(P 1 ∧ (P 2 ∧ P 3 )) iff ¬P 1 ∨ ¬(P 2 ∧ P 3 ) needed.

¬(P 1 ∧ P 2 ∧ P 3 ) iff ¬(P 1 ∧ (P 2 ∧ P 3 )) choosing an ∧ association iff ¬P 1 ∨ ¬(P 2 ∧ P 3 ) by (and-DM) iff ¬P 1 ∨ (¬P 2 ∨ ¬P 3 ) by (and-DM) (and-DM) is ¬(P ∧ Q) iff ¬P ∨ ¬Q. Instantiating the metavariables P and Q as P 7 → P 2 Q 7 → P 3 we get ¬(P 2 ∧ P 3 ) iff ¬P 2 ∨ ¬P 3. Using that in the context ¬P 1 ∨ ... gives us exactly the equality ¬P 1 ∨ ¬(P 2 ∧ P 3 )) iff ¬P 1 ∨ (¬P 2 ∨ ¬P 3 ). iff ¬P 1 ∨ ¬P 2 ∨ ¬P 3 forgetting the ∨ association So by transitivity of iff, we have ¬(P 1 ∧ P 2 ∧ P 3 ) iff ¬P 1 ∨ ¬P 2 ∨ ¬P 3

There I unpacked the steps in some detail, so you can see what’s really going on. Later, we’d normally just give the brief justification on each line; we wouldn’t write down the boxed reasoning (instantiation, context, transitivity) — but it should be clearly in your head when you’re doing a proof.

If it’s not clear, write it down — use the written proof as a tool for thinking.

Still later, you’ll use equalities like this one as single steps in bigger proofs.

Equational reasoning from those tautologies is sound : however we instantiate them, and chain them together, if we deduce that P iff Q then P iff Q.

Pragmatically important: if you’ve faithfully modelled some real-world situation in propositional logic, then you can do any amount of equational reasoning, and the result will be meaningful.

Is equational reasoning from those tautologies also complete? I.e., if

P iff Q, is there an equational proof of that? Yes (though proving completeness is beyond the scope of DM1).

Pragmatically: if P iff Q, and you systematically explore all possible candidate equational proofs, eventually you’ll find one. But there are

infinitely many candidates: at any point, there might be several tautologies you could try to apply, and sometimes there are infinitely many instantiations (consider T iff P ∨ ¬P ).

...so naive proof search is not a decision procedure (but sometimes you can find short proofs).

In contrast, we had a terminating algorithm for checking tautologies by truth tables (but that’s exponential in the number of propositional variables).

Predicate Logic (or Predicate Calculus, or First-Order Logic)

Socrates is a man. All men are mortal. So Socrates is mortal.

Can we formalise in propositional logic? Write p for Socrates is a man Write q for Socrates is mortal p p ⇒ q q ?

Predicate Logic Often, we want to talk about properties of things, not just atomic propositions.

All lions are fierce. Some lions do not drink coffee. Therefore, some fierce creatures do not drink coffee. [Lewis Carroll, 1886]

Let x range over creatures. Write L(x ) for ‘x is a lion’. Write C(x ) for ‘x drinks coffee’. Write F(x ) for ‘x is fierce’. ∀ x .L(x ) ⇒ F(x ) ∃ x .L(x ) ∧ ¬C(x ) ∃ x .F(x ) ∧ ¬C(x )

3.1 The Language of Predicate Logic

Predicate Logic So, we extend the language. Variables x , y, etc., ranging over some specified domain. Atomic predicates A(x ), B(x ), etc., like the earlier atomic propositions, but with truth values that depend on the values of the variables. Write A(x ) for an arbitrary atomic predicate. E.g.: Let A(x ) denote x + 7 = 10, where x ranges over the natural numbers. A(x ) is true if x = 3, otherwise false, so A(3) ∧ ¬A(4) Let B(n) denote 1 + 2 + ... + n = n(n + 1)/ 2 , where n ranges over the naturals. B(n) is true for any value of n, so B(27). Add these to the language of formulae:

P , Q ::= A(x ) | T | F | ¬P | P ∧ Q | P ∨ Q | P ⇒ Q | P ⇔ Q

Predicate Logic — Universal Quantifiers

If P is a formula, then ∀ x .P is a formula

Pronounce ∀ x .P as ‘for all x , P ’.

Definition: ∀ x .P is true if (and only if) P is true for all values of x (taken from its specified domain).

Sometimes we write P (x ) for a formula that might mention x , so that we

can write (e.g.) P (27) for the formula with x instantiated to 27.

Then, if x is ranging over the naturals, ∀ x .P (x ) if and only if P (0) and P (1) and P (2) and ...

Or, if x is ranging over {red, green, blue},then (∀ x .P (x )) iff P (red) ∧ P (green) ∧ P (blue).

Predicate Logic — Existential Quantifiers

If P is a formula, then ∃ x .P is a formula

Pronounce ∃ x .P as ‘exists x such that P ’.

Definition: ∃ x .P is true if (and only if) there is at least one value of x (taken from its specified domain) such that P is true.

So, if x is ranging over {red, green, blue}, then (∃ x .P (x )) iff P (red) ∨ P (green) ∨ P (blue).

Because the domain might be infinite, we don’t give truth-table definitions

for ∀ and ∃.

Note also that we don’t allow infinitary formulae — I carefully didn’t write (∀ x .P (x )) iff P (0) ∧ P (1) ∧ P (2) ∧ ... ×

The Language of Predicate Logic

Summarising, the formulae of predicate logic are the terms of the grammar

P , Q ::= A(x ) | T | F | ¬P | P ∧ Q | P ∨ Q | P ⇒ Q | P ⇔ Q | ∀ x .P | ∃ x .P

Convention: the scope of a quantifier extends as far to the right as possible, so (e.g.) ∀ x .A(x ) ∧ B(x ) is ∀x .(A(x ) ∧ B(x )), not (∀ x .A(x )) ∧ B(x ).

(other convention — no dot, always parenthesise: ∀ x (P ) )

Predicate Logic — Extensions

n-ary atomic predicates A(x , y), B(x , y, z ),...

(regard our old p, q, etc. as 0-ary atomic predicates)

Equality as a special binary predicate (e = e′) where e and e′^ are some mathematical expressions (that might mention variables such as x ), and similarly for <, >, ≤, ≥ over numbers.

(e 6 = e′) iff ¬(e = e′)

(e ≤ e′) iff (e < e′) ∨ (e = e′)