cis160 mathematical foundations of computer science …jean/cis160/cis160probs-motiv.pdf · cis160...

21
CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department of Computer and Information Science University of Pennsylvania Philadelphia, PA 19104, USA e-mail: [email protected] c Jean Gallier Please, do not reproduce without permission of the author August 31, 2010

Upload: ngokhuong

Post on 26-Apr-2018

229 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

CIS160Mathematical Foundations of

Computer ScienceSome Notes

Jean GallierDepartment of Computer and Information Science

University of PennsylvaniaPhiladelphia, PA 19104, USAe-mail: [email protected]

c� Jean GallierPlease, do not reproduce without permission of the author

August 31, 2010

Page 2: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

2

Page 3: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

Chapter 1

Mathematical Reasoning, ProofPrinciples and Logic

1.1 Motivations, Some Problems

One of the main goals of this course is to learn how to

construct and read mathematical proofs.

Why?

1. Computer scientists write programs and buildsystems.

2. It is very important to have rigorous methods tocheck that these programs and systems behave as ex-pected (are correct, have no bugs).

3

Page 4: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

4 CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

3. It is also important to have methods to analyze thecomplexity of programs (time/space complexity).

More generally, it is crucial to have a firm grasp of thebasic reasoning principles and rules of logic.

This leads to the question:

What is a proof?

There is no short answer to this question!

However, it seems fair to say that a proof is some kindof deduction (derivation) that proceeds from a set ofhypotheses (premises, axioms) in order to derive a con-clusion, using some logical rules.

Page 5: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 5

Al\ cal<) have +,ov( lejs.1h'O..{e -ro\.l( ').

I OJ¥' q cat

Figure 1.1: Dog Logic

A basic rule of logic is modus ponens:

If P implies Q holds and if P holds, then Q holds

Page 6: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

6 CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

A first important observation is that there are differentdegrees of formality of proofs.

1. Proofs can be very informal, using a set of loosely de-fined logical rules, possibly omitting steps and premises.

2. Proofs can be completely formal, using a very clearlydefined set of rules and premises. Such proofs are usu-ally processed or produced by programs called proofcheckers and theorem provers.

Thus, a human prover evolves in a spectrum of formality!

It should be said that it is practically impossible towrite formal proofs .

This is because it would be extremely tedious and time-consuming to write such proofs and these proofs wouldbe huge and thus, very hard to read.

Page 7: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 7

In principle, it is possible to write formalized proofs andsometimes it is desirable to do so if we want to have ab-solute confidence in a proof.

For example, we would like to be sure that a flight-controlsystem is not buggy so that a plane does not accidentlycrash, that a program running a nuclear reactor will notmalfunction or that nuclear missiles will not be fired as aresult of a buggy “alarm system”.

Thus, it is very important to develop tools to assist us inconstructing formal proofs or checking that formal proofsare correct and such systems do exit (Examples: Isabelle,COQ, TPS, NUPRL, PVS, Twelf). However, 99.99% ofus will not have the time or energy to write formal proofs.

Even if we never write formal proofs, it is important tounderstand clearly what are the rules of reasoning thatwe use when we construct informal proofs.

Page 8: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

8 CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

The first part of this course will be devoted to the descrip-tion of a formal notion of proof, represented as a certainkind of tree and using logical rules described in a styleknown as natural deduction.

Having a firm proof-theoretic basis, we will see how thebasic notions of set theory can be defined by formulatingsuitable axioms.

It will then be possible to define the set natural numbers(N = {0, 1, 2, . . .}) and then all sorts of objects used incomputer science: trees, graphs, etc.

Let us now list various mathematical problems that willbe used to illustrate and motivate the kind of materialthat we need to develop.

Page 9: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 9

Figure 1.2: Missing luggage

Page 10: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

10CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

Problem 1. Find formulae for the sums

1 + 2 + 3 + · · · + n = ?

12 + 22 + 32 + · · · + n2 = ?

13 + 23 + 33 + · · · + n3 = ?

· · · · · · · · · · · ·1k + 2k + 3k + · · · + nk = ?

Jacob Bernoulli (1654-1705) discovered the formulae listedbelow:

Page 11: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 11

IfSk(n) = 1k + 2k + 3k + · · · + nk

then

S0(n) = 1n

S1(n) =1

2n2 +

1

2n

S2(n) =1

3n3 +

1

2n2 +

1

6n

S3(n) =1

4n4 +

1

2n3 +

1

4n2

S4(n) =1

5n5 +

1

2n4 +

1

3n3 − 1

30n

S5(n) =1

6n6 +

1

2n5 +

5

12n4 − 1

12n2

S6(n) =1

7n7 +

1

2n6 +

1

2n5 − 1

6n3 +

1

42n

S7(n) =1

8n8 +

1

2n7 +

7

12n6 − 7

24n4 +

1

12n2

S8(n) =1

9n9 +

1

2n8 +

2

3n7 − 7

15n5 +

2

9n3 − 1

30n

S9(n) =1

10n10 +

1

2n9 +

3

4n8 − 7

10n6 +

1

2n4 − 3

20n2

S10(n) =1

11n11 +

1

2n10 +

5

6n9 − n7 + n5 − 1

2n3 +

5

66n

Is there a pattern?

Page 12: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

12CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

What are the mysterious numbers

11

2

1

60 − 1

300

1

420 − 1

300

5

66?

The next two are

0 − 691

2730Why?

It turns out that the answer has to do with the Bernoullipolynomials , Bk(x), with

Bk(x) =k�

i=0

�k

i

�xk−iBi,

where the Bi are the Bernoulli numbers .

There are various ways of computing the Bernoulli num-bers, including some recurrence formulae.

Amazingly, the Bernoulli numbers show up in very differ-ent areas of mathematics, in particular, algebraic topol-ogy!

Page 13: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 13

Figure 1.3: Funny spheres (in 3D)

Figure 1.4: A plane (granite slab!)

Problem 2. Prove that a sphere and a plane in 3D havethe same number of points .

More precisely, find a one-to-one and onto mapping of thesphere onto the plane (a bijection)

Actually, there are also bijections between the sphere anda (finite) rectangle, with or without its boundary!

Page 14: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

14CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

Problem 3. Counting the number of derangements ofn elements.

A permutation of the set {1, 2, . . . , n} is any one-to-onefunction, f , of {1, 2, . . . , n} into itself. A permutation ischaracterized by its image: {f (1), f (2), . . . , f (n)}.

For example, {3, 1, 4, 2} is a permutation of {1, 2, 3, 4}.

It is easy to show that there are n! = n · (n− 1) · · · 3 · 2distinct permutations of n elements.

A derangements is a permutation that leaves no elementfixed, that is, f (i) �= i for all i.

{3, 1, 4, 2} is a derangement of {1, 2, 3, 4} but{3, 2, 4, 1} is not a derangement since 2 is left fixed.

What is the number of derangements , pn, of n elements?

Page 15: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 15

The number pn/n! can be interpreted as a probability .

Say n people go to a restaurant and they all check theircoat. Unfortunately, the cleck loses all the coat tags.Then, pn/n! is the probability that nobody gets her orhis coat back!

Interestingly, pn/n! has limit 1e ≈

13 as n goes to infinity,

a surprisingly large number.

Page 16: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

16CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

1

16 17 18 19

10 11 12 13 14 15

5 6 7 8 9

1 2 3 4

Figure 1.5: An undirected graph modeling a city map

Problem 4. Finding strongly connected componentsin a directed graph.

The undirected graph of Figure 1.5 represents a map ofsome busy streets in a city.

The city decides to improve the traffic by making thesestreets one-way streets.

However, a good choice of orientation should allow oneto travel between any two locations. We say that theresulting directed graph is strongly connected .

Page 17: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 17

1

16 17 18 19

10 11 12 13 14 15

5 6 7 8 9

1 2 3 4

Figure 1.6: A choice of one-way streets

A possibility of orienting the streets is shown in Figure1.6.

Is the above graph strongly connected?

If not, how do we find its strongly connected compo-nents?

How do we use the strongly connected components to findan orientation that solves our problem?

Page 18: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

18CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

1

d2d3

dn+1

card 1card 2

card n

Figure 1.7: Stack of overhanging cards

Problem 5. The maximum overhang problem.

How do we stack n cards on the edge of a table, respectingthe law of gravity, and achieving a maximum overhang.

We assume each card is 2 units long.

Is it possible to achieve any desired amount of overhangor is there a fixed bound?

How many cards are needed to achieve an overhang of dunits?

Page 19: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 19

Problem 6. Ramsey Numbers

A version of Ramsey’s Theorem says that for every pair,(r, s), of positive natural numbers, there is a least positivenatural number, R(r, s), such that for every coloring ofthe edges of the complete (undirected) graph on R(r, s)vertices using the colors blue and red , either there is acomplete subgraph with r vertices whose edges are allblue or there is a complete subgraph with s vertices whoseedges are all red .

So, R(r, r), is the smallest number of vertices of a com-plete graph whose edges are colored either blue or redthat must contain a complete subgraph with r verticeswhose edges are all of the same color.

Page 20: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

20CHAPTER 1. MATHEMATICAL REASONING, PROOF PRINCIPLES AND LOGIC

1

Figure 1.8: Left: A 2-coloring of K5 with no monochromatic K3; Right: A 2-coloring of K6

with several monochromatic K3’s

The graph shown in Figure 1.8 (left) is a complete graphon 5 vertices with a coloring of its edges so that there isno complete subgraph on 3 vertices whose edges are allof the same color.

Thus, R(3, 3) > 5.

There are215 = 32768

2-colored complete graphs on 6 vertices. One of thesegraphs is shown in Figure 1.8 (right).

It can be shown that all of them contain a triangle whoseedges have the same color, so R(3, 3) = 6.

Page 21: CIS160 Mathematical Foundations of Computer Science …jean/cis160/cis160probs-motiv.pdf · CIS160 Mathematical Foundations of Computer Science Some Notes Jean Gallier Department

1.1. MOTIVATIONS, SOME PROBLEMS 21

The numbers, R(r, s), are called Ramsey numbers .

It turns out that there are very few numbers r, s forwhich R(r, s) is known because the number of coloringsof a graph grows very fast! For example, there are

243×21 = 2903 > 102490 > 10270

2-colored complete graphs with 43 vertices, a huge num-ber!

In comparison, the universe is only approximately 14 bil-lions years old, namely 14× 109 years old.

For example, R(4, 4) = 18, R(4, 5) = 25, but R(5, 5) isunknown , although it can be shown that43 ≤ R(5, 5) ≤ 49.

Finding the R(r, s), or, at least some sharp bounds forthem, is an open problem .