
























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This course will develop the intuition for discrete mathematics reasoning involving numbers and sets. Lectures. • Logic.
Typology: Study notes
1 / 64
This page cannot be seen from the preview
Don't miss anything!

























































Time-stamp: <2009-11-01 13:25:09 pes20> © cPeter Sewell 2008, 2009
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:
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
Outline
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:
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
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 )
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′)