36
Discrete Mathematics ب س حا ل وم ا ل ع ل ة ع ط ق ت م ات ي ض ا ريMATH 226

رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Embed Size (px)

DESCRIPTION

Introduction What is discrete mathematics? Discrete mathematics is the part of mathematics devoted to ( the study of discrete objects.) (Here discrete means consisting of distinct or unconnected elements.)

Citation preview

Page 1: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Discrete Mathematicsالحاسب لعلوم متقطعة رياضيات

MATH 226

Page 2: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Text books:

(Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw-Hill

Page 3: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Introduction What is discrete mathematics? Discrete mathematics is the part of

mathematics devoted to ( the study of discrete objects.) (Here discrete means consisting of distinct or

unconnected elements.)

Page 4: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

What is the main purpose for this course? - Give About Discrete Mathematics - Understand the principles of mathematical logic

(Logic), and methods of evidence - Identify Groups (Sets) and basic operations on

groups - Understand the different types of relationships and - Boolean algebra (Boolean Algebra), Paul functions

and logical circuits (Logical Circuits) - Graphs and trees

Page 5: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Lecture 1:The Foundations: Logic and Proofs

Chapter 11.1 Propositional Logic. 11.2 Applications of Propositional Logic1.3 Propositional Equivalences . .

Page 6: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Propositional LogicSection 1.1

Page 7: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

PropositionsA proposition is a declarative sentence that is either true or

false.Examples of propositions:

a) riyad is the capital of Saudi Arabiab) the color of blood is greenc) 1 + 0 = 1d) 0 + 0 = 2

Examples that are not propositions.a) Sit down!b) What time is it?c) x + 1 = 2d) x + y = z Propositions a and c are true, whereas b and d are false.

Page 8: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Propositional LogicPropositional Variables:We use letters to denote propositional variables

that is, variables that represent propositionsPropositional Variables: p, q, r, s, …E.g. Proposition p – “Today is Friday.”

Truth values – T, FThe proposition that is always true is denoted by T

and the proposition that is always false is denoted by F.

Propositional Logic – the area of logic that deals with propositions

Page 9: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Compound PropositionsCompound Propositions; constructed from

logical connectives and other propositions Negation ¬ Conjunction ∧ Disjunction ∨ Implication → Biconditional ↔

Page 10: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

ExamplesFind the negation of the proposition “Today is Friday.”

and express this in simple English.

Find the negation of the proposition ““Rana PC runs Linux”.” and express this in simple English.

DEFINITION 1

Let p be a proposition. The negation of p, denoted by ¬p, is the statement “It is not the case that p.”

The proposition ¬p is read “not p.”

Solution: The negation is “It is not the case that today is Friday.” In simple English, “Today is not Friday.” or “It is not Friday today.”

Solution: The negation is“It is not the case that Rana PC runs Linux.”This negation can be more simply expressed as“Rana PC does not run Linux.”.” 10

1.1 Compound Propositions: Negation

Page 11: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

The truth value of the negation of p, ¬p is the opposite of the truth value of p. has this truth table:

Example: If p denotes “The earth is round.”, then ¬p denotes “It is not the case that the earth is round,” or more simply “The earth is not round.”

p ¬p T FF T

Page 12: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

ExamplesFind the conjunction of the propositions p and q where p

is the proposition “Today is Friday.” and q is the proposition “It is raining today.”, and the truth value of the conjunction.

DEFINITION 2

Let p and q be propositions. The conjunction of p and q, denoted by p Λ q, is the proposition “p and q”. The conjunction p Λ q is true when both p and q are true and is false otherwise.

Solution: The conjunction is the proposition “Today is Friday and it is raining today.” The proposition is true on rainy Fridays.

12

Conjunction

Page 13: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Conjunction(p ∧ q ) and has this truth table:

Example: If p denotes “I am at home.” and q denotes “It is raining.” then p ∧q denotes “I am at home and it is raining.”

p q p ∧ q T T TT F FF T FF F F

Page 14: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Note: inclusive or : The disjunction is true when at least one of

the two propositions is true.

E.g. “Students who have taken calculus or computer science can take this class.” – those who take one or both classes.

exclusive or : The disjunction is true only when one of theproposition is true. p ⊕ q E.g. “Students who have taken calculus or computer science,

but not both, can take this class.” – only those who take one of them.

Definition 3 uses inclusive or.

DEFINITION 3

Let p and q be propositions. The disjunction of p and q, denoted by p ν q, is the proposition “p or q”. The conjunction p ν q is false when both p and q are false and is true otherwise.

14

Disjunction

Page 15: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Disjunctiontruth table:

Example: If p denotes “I am at home.” and q denotes “It is raining.” then p ∨q denotes “I am at home or it is raining.”

p q p ∨qT T TT F TF T TF F F

Page 16: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Implication(conditional statement )

and has this truth table:

Example: If p denotes “I am at home.” and q denotes “It is raining.” then p →q denotes “If I am at home then it is raining.”

In p →q , p is the hypothesis and q is the conclusion

p q p →qT T TT F FF T TF F T

DEFINITION 5

Let p and q be propositions. The conditional statement p → q, is the proposition “if p, then q.” The conditional statement is false when p is true and q is false, and true otherwise.

Page 17: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Understanding ImplicationExample:

Let p be the statement “Marim learns discrete mathematics.” and q the statement “Marim will find a good job.” Express the statement p → q as a statement in English. Solution: Any of the following -

“If Marim learns discrete mathematics, then she will find a good job.

“Marim will find a good job when she learns discrete mathematics.”

“Marim will find a good job unless she does not learn discrete mathematics.”

17

Page 18: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Converse, Contrapositive, and InverseFrom p →q we can form new conditional statements .

q →p is the converse of p →q ¬q → ¬ p is the contrapositive of p →q¬ p → ¬ q is the inverse of p →q

Example: Find the converse, inverse, and contrapositive of “It raining is a sufficient condition for my not going to town.”

Solution: converse: If I do not go to town, then it is raining.inverse: If it is not raining, then I will go to town.

contrapositive: If I go to town, then it is not raining. NOTE :only the contrapositive always has the same truth

value as p → q.

Page 19: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Biconditional If p and q are propositions, then we can form the

biconditional proposition p ↔q , read as “p if and only if q .” The biconditional p ↔q denotes the proposition with this truth table:

If p denotes “I am at home.” and q denotes “It is raining.” then p ↔q denotes “I am at home if and only if it is raining.”

p q p ↔q T T TT F FF T FF F T

Page 20: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Truth Tables of Compound Propositions Example Truth TableConstruct a truth table for

p q r r p q p q → r

T T T F T FT T F T T TT F T F T FT F F T T TF T T F T FF T F T T TF F T F F TF F F T F T

Page 21: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Equivalent PropositionsTwo propositions are equivalent if they

always have the same truth value.Example: Show using a truth table that the

biconditional is equivalent to the contrapositive.

Solution: p q ¬ p ¬ q p →q ¬q → ¬ p T T F F T TT F F T F FF T T F T TF F T T F T

Page 22: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Using a Truth Table to Show Non-Equivalence Example: Show using truth tables that

neither the converse nor inverse of an implication are not equivalent to the implication.

Solution: p q ¬ p ¬ q p →q ¬ p →¬ q q → p

T T F F T T TT F F T F T TF T T F T F FF F T T F T T

Page 23: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

ProblemHow many rows are there in a truth table

with n propositional variables?

Solution: 2n We will see how to do this in Chapter 6.Note that this means that with n

propositional variables, we can construct 2n distinct (i.e., not equivalent) propositions.

Page 24: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Precedence of Logical OperatorsOperator Precedence 1

23

45

p q r is equivalent to (p q) rIf the intended meaning is p (q r )then parentheses must be used.

Page 25: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Applications of Propositional Logic

Section 1.2

Page 26: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Translating English SentencesSteps to convert an English sentence to a

statement in propositional logicIdentify atomic propositions and represent

using propositional variables.Determine appropriate logical connectives

“If I go to Harry’s or to the country, I will not go shopping.”p: I go to Harry’sq: I go to the country.r: I will go shopping.

If p or q then not r.

Page 27: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Example Problem: Translate the following sentence

into propositional logic: “You can access the Internet from campus only

if you are a computer science major or you are not a freshman.”

One Solution: Let a, c, and f represent respectively “You can access the internet from campus,” “You are a computer science major,” and “You are a freshman.”

a→ (c ∨ ¬ f )

Page 28: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Logic Circuits (Studied in depth in Chapter 12) Electronic circuits; each input/output signal can be viewed as a 0 or 1.

0 represents False 1 represents True

Complicated circuits are constructed from three basic circuits called gates.

The inverter (NOT gate)takes an input bit and produces the negation of that bit. The OR gate takes two input bits and produces the value equivalent to the

disjunction of the two bits. The AND gate takes two input bits and produces the value equivalent to the

conjunction of the two bits. More complicated digital circuits can be constructed by combining these

basic circuits to produce the desired output given the input signals by building a circuit for each piece of the output expression and then combining them. For example:

Page 29: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Propositional Equivalences

Section 1.3

Page 30: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Logically Equivalent We write this as p⇔q or as p≡q where p and q are

compound propositions. Two compound propositions p and q are equivalent if and

only if the columns in a truth table giving their truth values agree.

This truth table show ¬p ∨ q is equivalent to p → q.p q ¬p ¬p ∨ q p→ qT T F T TT F F F FF T T T TF F T T T

Page 31: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

De Morgan’s Laws

p q ¬p ¬q (p∨q) ¬(p∨q) ¬p∧¬qT T F F T F FT F F T T F FF T T F T F FF F T T F T T

This truth table shows that De Morgan’s Second Law holds.

Augustus De Morgan

1806-1871

Page 32: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Key Logical Equivalences (cont)Commutative Laws: ,

Associative Laws:

Distributive Laws:

Absorption Laws:

Page 33: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Key Logical EquivalencesIdentity Laws: ,

Domination Laws: ,

Idempotent laws: ,

Double Negation Law:

Negation Laws: ,

Page 34: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

More Logical Equivalences

Page 35: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Equivalence ProofsExample: Show that is logically equivalent to Solution:

Page 36: رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill

Equivalence ProofsExample: Show that is a tautology. Solution: