52
mt263f-1 1 Discrete Structures Li Tak Sing( 李李李 ) [email protected] Room A0936 27686816

Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) [email protected] Room A0936 27686816

Embed Size (px)

Citation preview

Page 1: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 1

Discrete Structures

Li Tak Sing(李德成 )[email protected]

Room A093627686816

Page 2: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 2

Textbook: Discrete Structures, Logics, and Computability by James L. Hein (2nd Edition)

On Fridays, the second hour will be tutorial and tutorial worksheets will be distributed. They will not be assessed.

Test: Two Tests

Examination: 3 hr examination in late April to mid May

Course result: Test(30%), Examination(70%)

You must have at least 40 marks in both the total score.

Page 3: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 3

Syllabus

Data types, functions, and data structures;Formal logic, recursion, proofs;Algorithms and analysis of algorithms;Formal languages, Turing machines.

Page 4: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 4

Web site

You can find online materials at:http://plbpc001.ouhk.edu.hk/~comps263f

Page 5: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 5

Elementary Notions and Notations

This is related to chapter one of the text book

Logical Statements – statements that can either be true or false.

For example, I am an OUHK student.

Page 6: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 6

Negation

If S represents a logical statement, then negation of S represents the statement “not S”.

If S is: I am a OUHK student, then “not S” is: I am not a OUHK student.

Page 7: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 7

Truth table

A truth table list out all the possible values of different logical statements in different scenarios. So if we list S and “not S” in a true table, we would have:

S Not S

True false

False true

Page 8: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 8

Conjunction

The conjunction of A and B is the statement “A and B”

A B A and B

True True True

True False False

False True False

False False False

Page 9: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 9

Disjunction

The disjunction of A and B is “A or B”.

A B A or B

True True True

True False True

False True True

False False False

Page 10: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 10

Comparison of two logical statements

Two logical statements are equal if and only if they have the same values as listed in a true table.

Page 11: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 11

“not (A and B)” and “(not A) or (not B)”

A B A and B Not (A and B)

T T T F

T F F T

F T F T

F F F T

A B Not A Not B (Not A) or (not B)

T T F F F

T F F T T

F T T F T

F F T T T

This is also known as DeMorgan’s Thereom

Page 12: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 12

Other equivalent logical statements

A and B = B and A (commutative)A or B = B or A (commutative)A and (B and C) = (A and B) and C

(associative)A or (B or C) = (A or B) or C (associative)A and (B or C) = (A and B) or (A and C)

(distributive)

Page 13: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 13

A or (B and C) = (A or B) and (A or C) (distributive)

not (A and B) = (not A) or (not B) (DeMorgan’s theorem)

not (A or B) = (not A) and (not B) (DeMorgan’s theorem)

true and A = Afalse and A = false

Page 14: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 14

true or A = truefalse or A = Anot (not A) = AA and (A or B) = A (absorption)A or (A and B) = A (absorption)

Page 15: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 15

Conditional statements

If A then B. If 3=3 then 2=2 (true) If 3=3 then 2=1 (false) If 3=2 then 2=2 (true) If 3=2 then 2=1 (true)

A B If A then B

True True True

True False False

False True True

False False True

Page 16: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 16

if and only if

“A if and only if B” is actually “if A then B” and “if B then A”. “if and only if” is often written as iff

A B if A then B if B then A A iff B

T T T T T

T F F T F

F T T F F

F F T T T

“A iff B” is true only if both A or B have the same value. A iff B if A is equivalent to B

Page 17: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 17

“If A then B” and “If not B then not A”

A B Not A Not B If not B then not A

T T F F T

T F F T F

F T T F T

F F T T T

So we can see that “if A then B” and “if not B then not A” are equal logical statements.

Page 18: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 18

•So the following statements are equivalent:

•If the room is available, then we can take it.

•If we cannot take the room, then it is not available.

Page 19: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 19

Other equivalent logical statements

Not (A or B) (not A) and (not B)

A and (B or C) (A and B) or (A and C)

A or (B and C) (A or B) and (A or C)

If A then B (not A) or B

Not (if A then B) A and (not B)

Page 20: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 20

Proof techniques

Proof by Exhaustive CheckingThis means that you check every possible case

to see that the statement is true.This is only possible if the number of cases is

finite.

Page 21: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 21

For example, we want to prove the statement:All integers between 10 and 15 exclusive are not square of another integer.Proof: The numbers between 10 and 15 exclusive are 11, 12, 13, 14. We can then check each of these numbers and find that

741.314

605.313

464.312

316.311

Therefore, we have proved the statement

Page 22: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 22

Conditional Proof

Many statements that we want to proof are in the form “if A then B”. We should start the argument from A and then we should arrive at B.

Page 23: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 23

Prove the statement: if n is an odd integer, then n2 is also an odd integer.

Proof: n is an odd integer. Let n=2k+1 where k is an integer. Therefore, n2=4k2+4k+1=2(k2+2k)+1Now, 2(k2+2k) is an even number, therefore 2(k2+2)+1 is an odd number. Therefore n2 is an odd number.

There are more examples in the textbook.

Page 24: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 24

Set

A set is a collection of things called its elements, members or objects. If S is a set and x is an element in S, then we write

xSIf x is not an element in S, then we write

xSEvery element in a set must be distinct. We are not interested in the order of its

elements.

Page 25: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 25

Describing Sets

List out the elements:A={a,b,c}B={0,1,....,100}C={0,1,1,2} : this is not a set as it has two elements that are equal to 1.

Empty set:{},

Page 26: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 26

Equality of sets

Two sets are equal if they have the same elements.

{1,2,3}={3,2,1}A = B iff (xA iff xB)One consequence is that all empty sets

are equal because they all contain no elements.

Page 27: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 27

Finite and infinite sets

Finite sets are sets that contain finite number of elements. For example A={1,2,3}

Infinite sets are sets with in infinite number of elements. For example: N={0,1,2,3,...}, Z={....-2,-1,0,1,2,3...}

Page 28: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 28

Describing sets by properties

S={x| x has property P}A={x| x is an even number}R={x| x is a real number}

Page 29: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 29

Subsets

If every element of A can be found in B, then A is a subset of B, and is written as:AB

If A is not a subset of B, we write:

ABVenn diagram is a graphical

representation of sets. The following Venn diagram represents AB.

Page 30: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 30

A

B

A

Page 31: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 31

•Consequence: if A is a set, then AA.•Proof: if A is a set, then every element in A is in A, therefore AA.Consequence: if A is a set, then A.•Proof: the condition of A is that every element of should be in A. The other way to put it is: you cannot find any element that is in but not in A. Now, this statement is true because you cannot find any element in .

Page 32: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 32

ExampleProve that AB where A={x|x>4}, B={x|x2>1}For every xA,

x>4x2>16x2>1xB

So every x in A is also in B, so AB

Page 33: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 33

Power set

A power set of S is the set that contains all the subsets of S. The power set is denoted as power(S).

If S={a,b,c}, thenpower(S)={,{a},{b},{c},{a,b},{b,c},{c,a}, {a,b,c}}

If S is a set with n elements, then power(S) is a set with 2n elements.

Page 34: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 34

Equality of sets

A=B means AB and BA

Page 35: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 35

Union

The union of two sets A and B is the set of all the elements that are either in A or in B.

It is denoted as AB.AB={x| xA or xB}The following figure represents AB.

Page 36: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 36

A B

Page 37: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 37

Properties of Union

A=AAB=BA (commutative)A(BC)=(AB) C (associative)AA=AAB if and only if AB=B.

Page 38: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

Proof of A=A Obviously, A ANow, we want to prove that A A.For every x A x A or x x A or falsex ATherefore, A ATherefore A=A

mt263f-1 38

Page 39: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

Proof of AB if and only if AB=B

If AB, xAx BNow, BAB, we want to prove that

ABB.x AB

x A or x B x B or x B (since xAx B) x B

Therefore ABBTherefore AB=B

mt263f-1 39

Page 40: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

Proof of AB if and only if AB=B (Cont.)Assume AB=B xA

xA or xB xAB xB (since AB=B )

Therefore AB

mt263f-1 40

Page 41: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 41

Intersection of sets

The intersection of two sets A and B is the set of all elements that are in both A and B.

It is denoted as AB.A B={x| xA and xB}The following figure represents A B.

Page 42: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 42

A B

Page 43: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 43

Properties of Intersection

A=AB=BA (commutative)A(BC)=(AB) C (associative)AA=AAB if and only if AB=A

Page 44: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

Proof of A=

Obviously, A.Now, we just have to prove that A.x A

x A and x x A and falsefalse x

Therefore, A Therefore A=

mt263f-1 44

Page 45: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

Proof of AB if and only if AB=A

Assume that AB, we want to prove that AB=A.

Obviously, ABAxA

xA and xB (since AB)xAB

Therefore AB=A

mt263f-1 45

Page 46: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

Proof of AB if and only if AB=A(cont.)Assume that AB=AxA

xAB (since AB=A) xA and xB xB

Therefore AB

mt263f-1 46

Page 47: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 47

Difference of sets

If A and B are sets, then the different A-B is the set of elements in A that are not in B.

A-B={x| xA and xB}

Page 48: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 48

A B

Page 49: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 49

Symmetric Difference of Sets

The symmetric difference of sets A and B is the set AB of elements that are either in A or in B but not both.

AB={x| (xA or xB) and not (xA and xB) }

Page 50: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 50

A B

Page 51: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 51

Complement of a Set

The complement of A is the set that contain all elements except those in A.

A’={x| xA}

Page 52: Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) tsli@ouhk.edu.hk Room A0936 27686816

mt263f-1 52

Combining properties

A(BC)=(AB)(AC) (distributive)A(BC)=(AB)(AC) (distributive)A(AB)=A (absorption)A(AB)=A (absorption)(A’)’=A(AB)’=A’B’ (DeMorgan’s theorem)