Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E....

42
Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 1 CMPUT 272 CMPUT 272 Formal Systems Logic Formal Systems Logic in CS in CS I. E. Leonard University of Alberta http://www.cs.ualberta.ca/~isaac/ cmput272/f03
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    234
  • download

    6

Transcript of Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E....

Page 1: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 1

CMPUT 272CMPUT 272Formal Systems Logic in Formal Systems Logic in

CSCS

CMPUT 272CMPUT 272Formal Systems Logic in Formal Systems Logic in

CSCS

I. E. LeonardUniversity of Alberta

http://www.cs.ualberta.ca/~isaac/cmput272/f03

Page 2: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 2

TodayTodayTodayToday

Chapter 3.4Chapter 3.4

Chapter 3.5Chapter 3.5

Chapter 3.6Chapter 3.6

Other things…Other things…

All

imag

es

are

cop

yri

gh

ted

to t

heir

resp

ect

ive c

op

yri

gh

t h

old

ers

an

d r

ep

rod

uce

d h

ere

for

aca

dem

ic p

urp

ose

s u

nd

er

the c

on

dit

ion

of

“fair

usi

ng

”.

Page 3: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 3

AnnouncementsAnnouncementsAnnouncementsAnnouncements

Assignment #2 is due Thursday Oct 9.

Quiz #1 is on Thursday Oct 9.

3 Sample Midterms from Winter 2003 are on the course webpage (with solutions)

Page 4: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 4

Theorem(Division Theorem(Division Algorithm)Algorithm)

Theorem(Division Theorem(Division Algorithm)Algorithm)

For any integer aFor any integer b>0There exist unique integers q and rSuch that

a=qb+r0r<b

q is the quotient when a divided by br is the remainder when a divided by b

Page 5: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 5

QuestionsQuestionsQuestionsQuestions

Page 6: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 6

Greatest Common Greatest Common DivisorDivisor

(Highest Common (Highest Common Factor)Factor)

Greatest Common Greatest Common DivisorDivisor

(Highest Common (Highest Common Factor)Factor)Consider integers a>0, b>0

Consider set F(a,b)={xZ s.t. x|a & x|b}xF(a,b) [ xa & xb ]So F(a,b) is nonempty and bounded above thus has a largest element (by the well-ordering principle)Call max F(a,b) greatest common divisor:

gcd(a,b)

Page 7: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 7

ExampleExampleExampleExample

Page 8: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 8

Euclid’s Algorithm IdeaEuclid’s Algorithm IdeaEuclid’s Algorithm IdeaEuclid’s Algorithm Idea

Works fine for small numbersWhat about gcd(4453,1314) ?Here is an idea:Lemma. a>b, a=qb+r then gcd(a,b)=gcd(b,r)Proof.

Consider F(a,b)={x st x|a & x|b}Consider F(b,r)={x st x|r & x|b}If x1F(b,r) then x1|a, thus x1F(a,b)

If x2F(a,b) then x2|r, thus x2F(b,r)

Page 9: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 9

Euclid’s AlgorithmEuclid’s AlgorithmEuclid’s AlgorithmEuclid’s Algorithm

Page 10: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 10

Euclid’s AlgorithmEuclid’s AlgorithmEuclid’s AlgorithmEuclid’s Algorithm

Page 11: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 11

QuestionsQuestionsQuestionsQuestions

Page 12: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 12

Another ExampleAnother ExampleAnother ExampleAnother Example

Page 13: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 13

Going BackGoing BackGoing BackGoing Back

Page 14: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 14

Going BackGoing BackGoing BackGoing Back

Page 15: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 15

CorollaryCorollaryCorollaryCorollary

Corollary For any integers p,q not both 0, if d=gcd(p,q) then there exist integers x,y s.t.

I xp+qy=d

Proof: Done in class.

Page 16: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 16

QuestionsQuestionsQuestionsQuestions

Page 17: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 17

Fundamental Theorem Of Fundamental Theorem Of ArithmeticArithmetic

Fundamental Theorem Of Fundamental Theorem Of ArithmeticArithmetic

Any integer z0 can be represented as:z = (-1)k p1

k1 p2

k2

… pnkn

where: p1<…<pn are prime numbersk is 0 or 1k1,…,kn are >0

This factorization is unique

Examples:24=(-1)0 23 31

-7=(-1)1 71

Page 18: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 18

Proof (existence)Proof (existence)Proof (existence)Proof (existence)

Let’s prove that for any nZ, n>0 such a representation exists

Steps:Lemma 0. There are n integers between 1 and nLemma 1. Non-trivial factors of a natural n are strictly less than nLemma 2. Every integer n>1 is divisible by a prime numberCorollary: can get exclusively prime factors for n>1

Page 19: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 19

Proof (uniqueness)Proof (uniqueness)Proof (uniqueness)Proof (uniqueness)

Let’s prove that such representation is unique

Steps:Lemma 3. If d=gcd(p,q) then there exist integers x,y s.t. xp+qy=dLemma 4 (Euclid’s 1st Theorem).

If p|ab and prime(p) then p|a or p|b Main Proof:

Suppose not. Then two different factorizations existThen arrive at a contradiction

Page 20: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 20

Further InformationFurther InformationFurther InformationFurther Information

Lecture notes (we reproduced some parts from):

http://www.mat.bham.ac.uk/P.J.Flavell/teaching/Foundation/LectureNotes/

Some background:http://mathworld.wolfram.com/EuclidsTheorems.html

How to discover the proof:http://www.dpmms.cam.ac.uk/~wtg10/FTA.html

Page 21: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 21

QuestionsQuestionsQuestionsQuestions

Page 22: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 22

DefinitionDefinitionDefinitionDefinitionA binary relation R from a set A to a set B is a subset of the Cartesian Product AB, that is,

a set of ordered pairs (a,b) with aA and b BA binary relation R on a set A is a subset of the Cartesian product AA, that is, ordered pairs of the form (a,b) where a A and b A

Instead of (x,y) R AAWe use the shorthand notation: x R y

Examples:3 < 4Angela likes Belinda

Page 23: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 23

ExamplesExamplesExamplesExamples

Binary relations on numbers:Domain : R x R<, , , etc.

Binary relations on sets:Domain : 2U x 2U

, etc.

Binary relations on people:Domain : people x peopleFather of, son of, in love with, took C272 from prof.

Page 24: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 24

Arrow DiagramsArrow DiagramsArrow DiagramsArrow Diagrams

A convenient way of illustrating relations:a R a, b R c, c R d

aa bb cc dd

Page 25: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 25

ReflexivityReflexivityReflexivityReflexivity

A binary relation R is reflexive iff for any x holds x R x

Examples:=

Counter-examples:<

xx

Page 26: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 26

IrreflexivityIrreflexivityIrreflexivityIrreflexivity

A binary relation R is irreflexive iff for any x holds NOT x R x

Counter-Examples:=

Examples:<

xx

Page 27: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 27

QuestionQuestionQuestionQuestion

Is every binary relation either reflexive or irreflexive?

No

Challenge : find a natural counter example

Page 28: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 28

SymmetrySymmetrySymmetrySymmetry

A binary relation R is symmetric iff for any x,y [x R y implies y R x]

Examples:=

Counter-examples:<

xx yy

Page 29: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 29

AsymmetryAsymmetryAsymmetryAsymmetry

A binary relation R is asymmetric iff for any x,y [x R y implies NOT y R x]Counter-examples:

=

Examples:<

xx yy

Page 30: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 30

QuestionQuestionQuestionQuestion

Is every binary relation either symmetric or asymmetric?

No

Challenge : find an original natural counter-example

Page 31: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 31

Equivalence RelationEquivalence RelationEquivalence RelationEquivalence Relation

A relation is an equivalence relation iffit is reflexive, transitive, and symmetric

Examples:= on numbers, sets, etc.

mod z on integers

“logic equivalence” on formulae

Counter examples:<

Page 32: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 32

RemaindersRemaindersRemaindersRemainders

Remainder: suppose n,k,z are integersDivide n by k get z as the remainder:

n=ak+z : remainder(n,k)=z

Examples:remainder(14,7)=0remainder(15,7)=1remainder(22,7)=1

Page 33: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 33

Congruence RelationCongruence RelationCongruence RelationCongruence RelationAny two integers n,m are congruent modulo z iff remainder(n,z) = remainder(m,z)Alternatively: n,m are congruent modulo z iff z divides (n-m)

Notation n m (mod z)Examples:

14 21 (mod 7)

15 22 (mod 7)

NOT 14 15 (mod7)

6 0 (mod 2)

Page 34: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 34

More CongruenceMore CongruenceMore CongruenceMore Congruence

(mod 2) defines the concept ofParity : even and odd numbers

(mod 1) defines the entire set

of integers Z, since for any integers

m and n, the difference m-n is always

divisible by 1

Page 35: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 35

Congruence & Congruence & EquivalenceEquivalence

Congruence & Congruence & EquivalenceEquivalence

Theorem. For any integer n > 0 (mod n) is an equivalence relation

Properties to prove:Reflexive: for any a [a a (mod n)]

Symmetric: for any a,b [a b (mod n) b a mod(n)]

Transitive: for any a,b,c [a b (mod n) & b c (mod n)

a c (mod n)]

Page 36: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 36

Equivalence ClassesEquivalence ClassesEquivalence ClassesEquivalence ClassesSuppose R is an equivalence relation over A x AThen we can define subsets of A in this way:

[x] = {aA | a R x} , where xA (a representative of the class)

Example:A=N

R is (mod 2)

[0] = {nN | n 0 (mod 2)} even numbers

[1] = {nN | n 1 (mod 2)} odd numbers

Question: For a positive integer k, how many equivalence classes does (mod k) have?

Page 37: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 37

QuestionsQuestionsQuestionsQuestions

Page 38: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 38

PartitioningPartitioningPartitioningPartitioningA Set A is partitioned into sets {Ai} iffThe union of all Ai equals to A, that is,

A = Ai

and the sets Ai are pairwise disjoint, that is,

if i k then Ai Ak = Examples:

{a,b,c} = {a,b} {c}N={0,1,…,9} {10,…,19}…N=[0] [1]

Page 39: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 39

Equivalence Classes & Equivalence Classes & PartitioningPartitioning

Equivalence Classes & Equivalence Classes & PartitioningPartitioning

The last example demonstrated that (mod 2) with its two equivalence

classes [0] and [1] partitions N into the disjoint subsets of even and odd integersWill this always be the case?In other words: do equivalence classes always partition of a set into disjoint

subsets?

Page 40: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 40

Theorem 1Theorem 1Theorem 1Theorem 1

For any set A and any equivalence relation R defined on it, the equivalence classes induced by R form a partition of A

Example:N= [0] [1] … [n-1] with respect to (mod n)

Page 41: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 41

Theorem 2: ConverseTheorem 2: ConverseTheorem 2: ConverseTheorem 2: Converse

For any set A and any partition {Ai} of A the binary relation R defined by a R b iff a,bA & i such that a,bAi}is an equivalence relation on A

Proof structure:Show that R is reflexiveShow that R is symmetricShow that R is transitive

Page 42: Oct 2, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03.

Oct 2, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 42

QuestionsQuestionsQuestionsQuestions