41
1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Embed Size (px)

Citation preview

Page 1: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

1

SSK3003 DISCRETE STRUCTURES

Prof. Madya Dr.Ali Mamat

Department of Computer Science

Page 2: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

2

INTRODUCTION

Discrete mathematics (structures) is the study of mathematical structures (objects) that are fundamentally discrete rather than continuous (vary smoothly)

Continuous objects are studied in calculus.

The term discrete means separate, distinct.Discrete structures include integers, sets, functions, relations, graphs and

trees.Topics in discrete mathematics include:• Logic• Set theory• Number theory• Proof Techniques (Mathematic Induction)• Counting• Functions and relations

Page 3: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

3

INTRODUCTION (cont.)

• Recursions• Graphs and trees33

Discrete mathematics has become popular in recent years because of its application to computer science.

• Logic has applications to automated theorem proving (logic programming) and software development.

• Set theory → software engineering, databases• Relations → to databases• Proof techniques → analysis of algorithms• Number theory → cryptography• Graphs and trees → data structures

Page 4: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

4

CH.1: The Logic of Compound Statements

Learning Outcomes

1. Evaluate logical statements

2. Determine two statements are equivalent

3. Determine the validity of arguments

Page 5: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

5

Contents

• Logical form and logical equivalence

• Conditional Statements

• Valid and invalid arguments

• Application: Digital logic circuits

Page 6: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

6

1.1 Logical form and logical equivalenceLogics are formal languages for formalizing reasoning, in particularfor representing information such that conclusion can be drawn.A logic involves:• A language with a syntax for specifying what is a legal expression in the language; syntax defines well formed sentences in the language

• Semantics for associating elements of the language with elements of some subject matter. Semantics defines the meaning of sentences (link to the domain); i.e., semantics defines the truth of a sentence with respect to each possible domain (world). E.g likes(Anas, Azura)

• Inference rules for manipulating sentences in the language (e.g modus ponens)

Page 7: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

7

Propositional Logic

A statement (or Proposition) is a sentence that is either true or false but not both.

“Two plus two equals four” is a statement“He is a university student” is not a statement.Which one is a statement?

√ 2 > 1 1 + 1 = 1 What time is it? Read this sentence carefully. x + y > 0

Page 8: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

8

Compound Statements

A statement can be atomic or compound.

Atomic Statement Peter hates Lewis : p It is raining outside: q√ 2 > 1: rPeter stays at home : t

Compound statements are formed from existing statements using logical operators, i.e.

¬ (not), ∧ (and), ∨ (or), → (imply or if then), ↔ (equivalent if and only if ).

Page 9: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

9

Compound Statements

Example

Peter hates Lewis and it is raining outside. : p ∧ q

If it is raining outside then Peter stays at home : q → t

If Peter doesn't hate Lewis then It is raining or √ 2 > 1 :

¬p → (q ∨ r )

Page 10: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

10

Truth Table

• A truth table displays the relationships among the truth values of statements. In constructing such truth tables, we write “0” (F) for false and “1” (T) for true.

p q pvq p∧q

T T T T

T F T F

F T T F

F F F F

Page 11: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

11

Truth Table

Page 12: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

12

Well-Formed Formulas

Statements and compound statements must follow syntax.

Statements that follows syntax are called well-formed formulas (wffs) or formula.

A wff is defined as follows:• Atomic formula is a wff• If p and q are wffs then

¬p, p∨q, p∧q, p→q, p↔q are wffs

Page 13: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

13

Well-Formed Formulas

Page 14: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

14

Type of formula

A statement/proposition: true or false

Atomic: P, Q, X, Y, …

Unit Formula: P, ~P,

Conjunctive: P ∧ Q, P ∧ ¬Q, …

Disjunctive: P v Q, P v (P∧ X),…

Conditional: P Q

Biconditional: P ↔ Q

Page 15: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

15

Determining truth of a formula

Atomic formulae: given

Compound formulae: via meaning ofthe connectives

Suppose: P is trueQ is false

How about: (P v Q)

Truth tables

Page 16: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

16

Precedence

• ¬ highest• ∧ • v, ↔ lowest

• Avoid confusion - use ‘(‘ and ‘)’:P ∧ Q v X

(P ∧ Q) v X

Page 17: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

17

Parenthesizing

• Parenthesize & build truth tables

• Similar to arithmetics:– 3*5+7 = (3*5)+7 but NOT 3*(5+7)

– A ∧ B v C = (A ∧ B) v C but NOT A ∧ (B v C)

• So start with sub-formulae with highest-precedence connectives and work your way out

Page 18: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

18

Evaluate The Truth Value

• Given a compound statement, how do we compute the truth value?

Page 19: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

19

Translating English Sentence English (even every other human languages)

is ambiguous. E.g. words such as present,

“sumbang”Example “If you are under 4 feet tall and you

are younger than 16 years old then you cannot ride the roller coaster."

You can ride the roller coaster : p You are under 4 feet tall : q You are younger than 16 years old : r (q ∧ r ) → ¬ p

Page 20: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

20

Logical Equivalences

• Denition : The propositions p and q are called logically equivalent if they have identical truth values, denoted by p ≡ q.One way to determine if two propositions are logically equivalent is to use truth table.

• The truth table can also be used to show that two propositions are not equivalent.

Page 21: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

21

Some Useful Logical Equivalences

Page 22: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

22

Logical equivalence (cont.)

Equivalence Name

p v ¬p ≡ T0

p ∧ ¬p ≡ F0

Inverse laws or negation laws

p v (p ∧ q) ≡ p

p ∧ (p v q) ≡ p

Absorption laws

T0 is a tautology

F0 is a contradiction

Page 23: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Use of Equivalences

• Simplification

• Suppose someone gives you ~P v (AB) v ~(C v D H) v P v X↔Y

• and asks you to compute it for all possible input values

• You can either immediately draw a truth table with 28 = 256 rows

• Or you can simplify it first

23

Page 24: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Simplification

~P v (AB) v ~(C v D H) v P v X↔Y

~P v P v (AB) v ~(C v D H) v X↔Y

T v (AB) v ~(C v D H) v X↔Y

T

The statement is a tautology – always true…

24

Page 25: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

25

Evaluate Logical Equivalences

Page 26: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

26

Tautology

• Definition : A tautology (denoted by T0) is a statement that is always true regardless of the truth values of the individual statements.

• A contradiction (denoted by F0) is a statement that is always false regardless of the truth values of the individual statements.

• A contingency is a statement that is sometimes true and sometimes false.

Page 27: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Equivalence & Tautology

Suppose A and B are logically equivalentConsider proposition (A ≡ B)What can we say about it?It is a tautology!Why?A B A ≡ B A ↔ BF F T TT T T T

27

Page 28: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

28

1.2 Conditional Statement

• Conditional statement (or implication), p → q, is only false when q is false and p is true. E.g.

• If you show up for work Monday morning, then you’ll get the job.

• Related Implications

• The variable p is called the hypothesis (antecedent) and q the conclusion (or consequent).

• Caution ! : Only the contrapositive form is logically equivalent to conditional statement. The converse and the inverse are equivalent.

Page 29: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

29

Conditional and its contrapositive

p q p → q q p ¬q → ¬p

T T T F F T

T F F T F F

F T T F T T

F F T T T T

Page 30: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

30

Bi-conditional

• The biconditional of p and q is “p if and only if q” and is denoted p ↔ q.

• It is true if both p and q have the same truth values and is false if p and q have opposite truth values.

• p ↔ q is equivalent to p → q ∧ q → p:

• p → q p is a sufficient condition for q q is a necessary condition for p. (if q does not occur then p

does not occur too, i,e. ¬q → ¬p )

Page 31: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Recall

Learning Outcomes

1. Evaluate logical statements

2. Determine two statements are equivalent

3. Determine the validity of arguments

31

Page 32: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Questions

• 1. What is an argument?

• 2. What is a premise and a conclusion?

• 3. When is an argument valid?

• 4. How to determine whether an argument is valid.

32

Page 33: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

33

Argument• An argument is a sequence of statements. All

the statements before the final one are called premises (or assumption or hypothesis). The final statement is called the conclusion.

• An argument is valid whenever the truth of all its premises implies the truth of its conclusion.

• How to show a conclusion q logically follows from the premises

• Basically, we show that the argument is tautology.

Page 34: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

34

Valid Argument

• Example Show that the argument where premises are p v (q v r ) and ¬r , and the conclusion is p v q, is valid.

Page 35: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

35

Valid Argument

• Example Show that the argument where premises are p v (q v r ) and ¬r , and the conclusion is p v q, is valid.

Page 36: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

36

Valid Argument

• Example Show that the argument where premises are p v (q v r ) and ¬r , and the conclusion is p v q, is valid.

Page 37: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Valid argument

p q r

q v r p v (q v r ) ¬r p v q pv(qvr) ^¬ r → (pv q)

T T T T T F T T

T T F T T T T T

T F T T T F T T

T F F F T T T T

F T T T T F T T

F T F T T T T T

F F T T T F F T

F F F F F T F T

37

Page 38: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

Logical Implication

• From the previous table:

p1 : pv(qvr) p2: ¬r q1: q

p1 ^ p2 → q1 is a tautology.

If p, q are arbitrary statements such that p → q, then we says p logically implies q, denoted as p q

38

Page 39: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

39

Rule of Inferences• Although the truth table method always works, however, it

is not convenient. Since the appropriate truth table must have 2n lines where n is the number of atomic propositions.

• Another way to show an argument is valid is to construct a formal proof. To do the formal proof we use rules of inference.

• A rule of inference is a form of argument that is valid. • In rules of inference, premise(s) are written in lines and the

conclusion is on the last line preceded with the symbol which denotes “therefore".

• For example the following rule is called Modus Ponens.

• In words, if p and p → q are true then q is true.

Page 40: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

40

List of Rule of Inferences

Page 41: 1 SSK3003 DISCRETE STRUCTURES Prof. Madya Dr.Ali Mamat Department of Computer Science

41

Recap

• Introduction to logic• Propositions (statement)• Logical Operators• wffs• Truth table• Logical equivalences• Tautologies• Conditional statements• Bi-conditional statements• Valid argument• Rule of inferences