discrete structures chapter 1 part b fundamentals of logic nurul amelina nasharuddin multimedia...

29
Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Post on 20-Dec-2015

226 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Discrete StructuresChapter 1 Part B

Fundamentals of Logic

Nurul Amelina Nasharuddin

Multimedia Department

1

Page 2: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Predicates

• A predicate is a sentence that contains a finite number of variables and becomes a statement when specific values are substituted for the variables

• The domain of a predicate variable is a set of all values that may be substituted in place of the variable

• P(x): x is a student at UPM• P(x, y): x is a student at y

2

Page 3: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Predicates

• The sets in which predicate variables take their values may be described either in words or in symbols

• x A indicates that x is an element of the set A

• x A; x is not an element of the set A

• {1, 2, 3} refers to the set whose elements are 1, 2 and 3

• Certain set of numbers that frequently referred to are

3

Symbol Set Example

R Set of all real numbers All points on a line number

Z Set of all integers …,-3, -2, -1, 0, 1, 2, 3, …

Q Set of all rational numbers, or quotient of integers

{p/q | p Z, q Z, q ≠ 0}∈ ∈

Page 4: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Predicates

• If P(x) is a predicate and x has domain D, the truth set of P(x) is the set of all elements in D that make P(x) true when substituted for x. The truth set is denoted as:

{x D | P(x)}which is read “the set of all x in D such that P(x)”• True or false?: Let P(x): x2 > x with domain set R (real

numbers).

4

Page 5: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Predicates

• Let Q(n) be the predicate “n is a factor of 8.” Find the truth set of Q(n) if – the domain of n is the set of Z+

– the domain of n is the set of Z

5

• Ans:

•{1, 2, 4, 8}

•{-1, -2, -4, -8, 1, 2, 4, 8}

Page 6: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Predicates

• Let P(x) and Q(x) be predicates with the common domain D

• P(x) Q(x) means that every element in the truth set of P(x) is in the truth set of Q(x), or equivalently for every x, P(x) Q(x)

• P(x) Q(x) means that P(x) and Q(x) have identical truth sets, or equivalently for every x, P(x) Q(x)

6

Page 7: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Universal Quantifier, • Let P(x) be a predicate with domain D. • A universal statement is a statement in the form “x D,

P(x)”. denotes “for all”• It is true iff P(x) is true for every x from D.

It is false iff P(x) is false for at least one x from D.• A value of x for which P(x) is false is called a

counterexample to the universal statement• Examples

– D = {1, 2, 3, 4, 5}: x D, x² >= x (True) x R, x² >= x (False)

• Method of exhaustion

7

Page 8: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Existential Quantifier,

• Let P(x) be a predicate with domain D. • An existential statement is a statement in the form

“x D, P(x)”. denotes “there exists” • It is true iff P(x) is true for at least one x from D.

It is false iff P(x) is false for every x from D.• Examples:

m Z, m² = m (True)– E = {5, 6, 7, 8, 9}, x E, m² = m (False)

8

Page 9: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Quantifier

• Rewrite the following without using and :a. x R, x2 0

b. x Z such that m2 = m

• Ans:a. All real numbers have nonnegative squares

The square of any real number is nonnegative

b. m2 =m, for some integer m

Some integers equal their own square

9

Page 10: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Universal Conditional Statement

• Universal conditional statement “x, if P(x) then Q(x)”:

• Eg: x R, if x > 2, then x2 > 4• Universal conditional statement is called

vacuously true or true by default iff P(x) is false for every x in D

• Eg: When x =1, if 1 > 2, then 12 > 4 (True)When x = -3, if (-3) > 2, then (-3)2 > 4 (True)

10

Page 11: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Negation of Quantified Statements

• The negation of a universally quantified statement x D, P(x) is x D, ~P(x)

(x D, P(x)) x D such that ~P(x)

• The negation of an existentially quantified statement x D, P(x) is x D, ~P(x)( x D, P(x)) x D such that ~P(x)

• Rewrite formally, formal and informal negation: No politicians are honest

11

Page 12: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Answer

No politicians are honest

• Formal version: politicians x, x is not honest

• Formal negation: a politician x such that x is honest

• Informal negation: Some politicians are honest

12

Page 13: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Negation of Quantified Statements

• The negation of a universal conditional statement x D, P(x) Q(x) is x D, P(x) ~Q(x)

(x, if P(x) then Q(x)) x such that P(x) and ~Q(x)

• Noted before; ~(p q) p ~q• Write formal negation: people p, of p is blond then p

has blue eyes• Ans: a person such that p is blond and p does not have

blue eyes

13

Page 14: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Exercises

• Write negations for each of the following statements:– All dinosaurs are extinct– No irrational numbers are integers– Some exercises have answers– All COBOL programs have at least 20 lines– The sum of any two even integers is even– The square of any even integer is even

14

Page 15: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Multiply Quantified Statements

• Imagine you are in a factory and the guide tell you

“There is person supervising every detail of the production process”

• Have both existential quantifier There is and universal quantifier every

• When a statement contains more than one quantifier, the actions being performed is in the order in which the quantifier occur.

15

Page 16: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Multiply Quantified Statements

• To establish the truth of the statement “x in D, y in E such P(x, y)”Pick whatever x from set D , then find element

y in E that “works” for that particular y in P(x, y)

• To establish the truth of the statement “x in D, such that y in E, P(x, y)”Find element x in D that “works” no matter y in

P(x, y)16

Page 17: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Multiply Quantified Statements

• For all positive numbers x, there exists number y such that y < x

• There exists number x such that for all positive numbers y, y < x

• For all people x there exists person y such that x loves y (Informally: Everybody loves somebody)

• There exists person x such that for all people y, x loves y (Informally: Somebody loves everybody)

17

Page 18: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Negation of Multiply Quantified Statements

• The negation of x, y, P(x, y)

is logically equivalent to x, y, ~P(x, y)

• The negation of x, y, P(x, y)

is logically equivalent to x, y, ~P(x, y)

18

Page 19: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Negation of Multiply Quantified Statements

• Rewrite formally and negate: Everybody trusts somebody.

• Formally: (a) people x, a person y such that x trusts y.

• Negation: Somebody trusts nobody.

• Formally: (b) a person x, such that people y, x does not trust y.

19

Page 20: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Necessary and Sufficient Conditions, Only If

x, r(x) is a sufficient condition for s(x) means: x, if r(x) then s(x)

x, r(x) is a necessary condition for s(x) means: x, if s(x) then r(x)

x, r(x) only if s(x) means: x, if r(x) then s(x)

20

Page 21: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Logical Equivalence and Logical Implication for Quantified Statements in One Variable

21

x D, (P(x) Q(x) (x D, P(x)) (x D, Q(x))

x D, (P(x) Q(x)) (x D, P(x)) (x D, Q(x))

(x D, P(x)) (x D, Q(x)) x D, (P(x) Q(x))

x D, (P(x) Q(x)) (x D, P(x)) (x D, Q(x))

Page 22: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Application: Digital Logic Circuits

• Digital Logic Circuit is a basic electronic component of a digital system

• Values of digital signals are 0 or 1 (bits)

• Black Box is specified by the signal input/output table

• Input/output table = truth table

• Three gates: AND-gate, OR-gate, NOT-gate

Page 23: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Application: Digital Logic Circuits

• Combinational circuit is a combination of logical gates

• Combinational circuit always correspond to some Boolean expression, such that input/output table of a table and a truth table of the expression are identical

23

Page 24: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Application: Digital Logic Circuits

• Finding Boolean expression for a circuit:

P ~ (Q R)

24

Page 25: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Application: Digital Logic Circuits

• Determining output for a given input: Move from left to right through the diagram, tracing the action of each gate on the input signals

• Constructing the input/output table for a circuit: list the all possible combinations for input signals, and find the output for each by tracing through the unit

25

Page 26: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Application: Digital Logic Circuits

• A recognizer is a circuit that outputs 1 for exactly one particular combination of input signals and outputs 0’s for all other combinations

• Multiple-input AND and OR gates• Finding a circuit that corresponds to a given

input/output table:– Construct equivalent Boolean expression using disjunctive

normal form: for all outputs of 1 construct a conjunctive form based on the truth table row. All conjunctive forms are united using disjunction

– Construct a digital logic circuit equivalent to the Boolean expression

Page 27: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Application: Digital Logic Circuits

• Given

27

Input Output

P Q R S

1 1 1 1

1 1 0 0

1 0 1 1

1 0 0 1

0 1 1 0

0 1 0 0

0 0 1 0

0 0 0 0

• Boolean expression:

(P Q R) (P Q R) (P Q R)

• Circuit:

Page 28: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Application: Digital Logic Circuits

• Two digital logic circuits are equivalent iff their input/output tables are identical

• Simplification of circuits by using Theorem 1.1.1 to simplify the Boolean expression

• Another way to simplify circuit by using– Scheffer stroke, | (NAND, AND-gate followed by

NOT-gate)– Peirce arrow, (NOR, OR-gate followed by NOT-

gate)

Page 29: Discrete Structures Chapter 1 Part B Fundamentals of Logic Nurul Amelina Nasharuddin Multimedia Department 1

Exercises

• Construct circuits for (P Q) R

• From the given input/output

table below, construct

(a) a Boolean expression

(b) a circuit

Input Output

P Q R S

1 1 1 0

1 1 0 1

1 0 1 0

1 0 0 0

0 1 1 1

0 1 0 0

0 0 1 0

0 0 0 0