You are on page 1of 60

Discrete Structures LOGIC

prepared by Roselina Sallehuddin and Razana Alwee

Why Are We Studying Logic?


A few of the many reasons: Logic is the foundation for computer operation. Logical conditions are common in programs: Selection: if (score <= max) { ... } Iteration: while (i<limit && list[i]!=sentinel) ... All manner of structures in computing have properties that need to
be proven (and proofs that need to be understood). Examples: Trees, Graphs, Recursive Algorithms, . . . Programs can be proven correct. Computational linguistics must represent and reason about human language, and language represents thought (and thus also logic).
prepared by Roselina Sallehuddin and Razana Alwee

PROPOSITION
A statement or a proposition, is a declarative sentence that is either true or false, but not both. example 4 is less than 3 7 is an even integer Washington, DC, is the capital of United State

prepared by Roselina Sallehuddin and Razana Alwee

Example
Is 2 a positive number? Study logic What is your name? Quiet, please.
The above sentences are not propositions. Why ? (i) & (iii) : is question, not a statement Roselina Sallehuddin and (ii)& (iv) : is aprepared byRazana Alwee command

Examples
i) x is an integer ii)The sun will come out tomorrow

Not Propositions ? Why


We do not know at this time / determine whether it is true / false

prepared by Roselina Sallehuddin and Razana Alwee

CONJUNCTIONS
Conjunctions are: compound propositions formed in English with the word and, formed in logic with the caret symbol ( ), and true only when both participating propositions are true.

prepared by Roselina Sallehuddin and Razana Alwee

TRUTH TABLE Truth tables aid in the evaluation of compound propositions

p q

T T F F

T F T F

T F F F

prepared by Roselina Sallehuddin and Razana Alwee

EXAMPLE
p : 2 is an even integer q : 3 is an odd number pq 2 is an even integer and 3 is an odd number p : today is Monday q : it is hot pq today is Monday and it is hot
prepared by Roselina Sallehuddin and Razana Alwee 8

EXAMPLES
p : 2 divides 4 q : 2 divides 6 pq 2 divides 4 and 2 divides 6. is also written as, 2 divides both 4 and 6.

p : 5 is an integer q : 5 is not an odd integer pq 5 is an integer and 5 is not an odd integer. is also written as, 5 is an integer but 5 is not an odd integer.
prepared by Roselina Sallehuddin and Razana Alwee 9

DISJUNCTION
compound propositions formed in English with the word or, formed in logic with the caret symbol ( V ), and true when one or both participating propositions are true. Let p and q be propositions The disjunction of p and q, written p q is the statement formed by putting statements p and q together using the word or. The symbol is called or
prepared by Roselina Sallehuddin and Razana Alwee 10

DISJUNCTION
TRUTH TABLE FOR p V q
P q pV q

T T F F

T F T F

T T T F

prepared by Roselina Sallehuddin and Razana Alwee

11

EXAMPLES
p : 2 is an integer q : 3 is greater than 5 pq 2 is an integer or 3 is greater thanp : 1+1=3 5 q : A decade is 10 years pq 1+1=3 or a decade is 10 years p : 3 is an even integer q : 3 is an odd integer pq 3 is an even integer or 3 is an odd integer or 3 is an even integer or an oddSallehuddin and integer prepared by Roselina
Razana Alwee 12

NEGATION
Negating a proposition simply flips its value. Symbols representing negation include: x , x , x (NOT) x, Let p be a proposition. The negation of p, written p is the statement obtained by negating statement p.
prepared by Roselina Sallehuddin and Razana Alwee

13

TRUTH TABLE - NEGATION


The truth table of p

P T F

P F T

prepared by Roselina Sallehuddin and Razana Alwee

14

EXAMPLES
p : 2 is positive p, It is not the case that 2 is positive or 2 is not positive

prepared by Roselina Sallehuddin and Razana Alwee

15

EXERCISES
GIVE THE NEGATION OF EACH OF THE FOLLOWING STATEMENTS i) It will rain tomorrow ii)5 is an even number

prepared by Roselina Sallehuddin and Razana Alwee

16

Exercises
In each of the following, form the conjunction and the disjunction of p and q P: I will drive my car q: I will be late

P : NUM > 10

q : NUM 15

prepared by Roselina Sallehuddin and Razana Alwee

17

Conditional Propositions
Let p and q be propositions. if p, then q is a statement called a conditional proposition, written pq

prepared by Roselina Sallehuddin and Razana Alwee

18

CONDITIONAL PROPOSITIONS
False if p = True and q=fal se

The truth table of p q Cause and effect relationship


p q p q

True : p false for any value of q

T T F F

T F T F

T F T T
19

prepared by Roselina Sallehuddin and Razana Alwee

example
p : today is Sunday q : I will go for a walk pq If today is Sunday, then I will go for a walk p : I get a bonus q : I will buy a new car pq If I get a bonus, then I will buy a new car

p : x/2 is an integer q : x is an even integer pq if x/2 is an integer, then x is an even integer


prepared by Roselina Sallehuddin and Razana Alwee

20

Biconditional
Let p and q be propositions. p if and only if q is a statement called a biconditional proposition, written pq

prepared by Roselina Sallehuddin and Razana Alwee

21

Biconditional
The truth table of p q p q p q

T T F F

T F T F

T F F T

prepared by Roselina Sallehuddin and Razana Alwee

22

EXAMPLES
p : my program will compile q : it has no syntax error pq My program will compile if and only if it has no syntax error. p : x is divisible by 3 q : x is divisible by 9 pq p:x<6 x is divisible by 3 if and only if x q : x3 < is divisible by 9

pq x < 6 if and only if x3 < 3


23

prepared by Roselina Sallehuddin and Razana Alwee

exercises
Propositions p, q, r and s are defined as follows: p is "I shall finish my Coursework Assignment" q is "I shall work for forty hours this week" r is "I shall pass Maths" s is "I like Maths" Write each sentence in symbols: (a) I shall not finish my Coursework Assignment. (b) I dont like Maths, but I shall finish my Coursework Assignment. (c) If I finish my Coursework Assignment, I shall pass Maths. (d) I shall pass Maths only if I work for forty hours this week and finish my Coursework Assignment. Write each expression as a sensible (if untrue!) English sentence: (e) q p (f) p r

prepared by Roselina Sallehuddin and Razana Alwee

24

solution
(a) p (b) s p (c) p r (d) r (q p) (e) I shall work for forty hours this week, or Ill finish my Coursework Assignment. (f) If I shall not finish my Coursework Assignment, then I shant pass Maths.

prepared by Roselina Sallehuddin and Razana Alwee

25

Precedence of Logical Connectives

prepared by Roselina Sallehuddin and Razana Alwee

26

prepared by Roselina Sallehuddin and Razana Alwee

27

Construct the truth table for, A = (p q) (q p)

prepared by Roselina Sallehuddin and Razana Alwee

28

Truth table
p q (pV q) (pVq) (q p) A

T T F F

T F T F

T T T F

F F F T

T F F F

T T T F
29

prepared by Roselina Sallehuddin and Razana Alwee

EXERCISES
Construct the truth table for each of the following statements: pq (p q) q ( p q) q (p q) ( q p)

prepared by Roselina Sallehuddin and Razana Alwee

30

Logical Equivalence
The compound propositions Q dan R are made up of the propositions p1, , pn. Q and R are logically equivalent and write,

QR
provided that given any truth values of p1, , pn, either Q and R are both true or Q and R are both false.

prepared by Roselina Sallehuddin and Razana Alwee

31

example Q=pq R= q p Show that, Q R

prepared by Roselina Sallehuddin and Razana Alwee

32

example
The truth table shows that, Q R p q pq q p

T T F F

T F T F

T F T T
prepared by Roselina Sallehuddin and Razana Alwee

T F T T
33

example
Show that, (p q) p q

prepared by Roselina Sallehuddin and Razana Alwee

34

example
The truth table shows that, (p q) p q p q (p q) pq

T T F F

T F T F

F T F F
prepared by Roselina Sallehuddin and Razana Alwee

F T F F
35

EXERCISE
Given, R = p ( q r) Q = p (q r) State whether or not R Q.

prepared by Roselina Sallehuddin and Razana Alwee

36

exercise
For each pair of expressions, construct truth tables to see if the two compound propositions are logically equivalent: (a) (i) p (q p) (ii) p q (b) (i) (p q) (p q) (ii) (p q) (p q)

prepared by Roselina Sallehuddin and Razana Alwee

37

(a) Yes; both results columns give T, T, T, F (b) No; first is F, T, T, F; second is T, F, F, T

prepared by Roselina Sallehuddin and Razana Alwee

38

Basic logical equivalences


Let p, q and r be propositions Idempotent laws ppp ppp
TRUTH TABLE

prepared by Roselina Sallehuddin and Razana Alwee

39

Basic logical equivalences


double negation law pp Commutative laws pqqp pqqp

prepared by Roselina Sallehuddin and Razana Alwee

40

Basic logical equivalences


Associative laws (p q) r p (q r) (p q) r p (q r) Distributive laws p (q r) (p q) (p r) p (q r) (p q) (p r) Absorption laws p (p q) p p (p q) p
prepared by Roselina Sallehuddin and Razana Alwee 41

PROVE

PROVE

solution

prepared by Roselina Sallehuddin and Razana Alwee

42

solution

prepared by Roselina Sallehuddin and Razana Alwee

43

Basic logical equivalences


De Morgans laws (p q) ( p) ( q) (p q) ( p) ( q)

prepared by Roselina Sallehuddin and Razana Alwee

44

The truth table for, (p q) ( p) ( q)

prepared by Roselina Sallehuddin and Razana Alwee

45

prepared by Roselina Sallehuddin and Razana Alwee

46

prepared by Roselina Sallehuddin and Razana Alwee

47

prepared by Roselina Sallehuddin and Razana Alwee

48

prepared by Roselina Sallehuddin and Razana Alwee

49

Propositional functions p, q and r are defined as follows: p is "n = 7" q is "a > 5" r is "x = 0" Write the following expressions in terms of p, q and r, and show that each pair of expressions is logically equivalent. State carefully which of the above laws are used at each stage

(a) ((n = 7) (a > 5))(x = 0) ((n = 7) (x = 0)) ((a > 5)(x = 0)) (b) ((n = 7) (a 5)) (n 7) (a > 5) (c) (n = 7) (((a 5) (x = 0))) ((nprepared by (a Sallehuddin (x 0) = 7) Roselina > 5)) and
Razana Alwee

50

solution
(a) (p q) r (p r) (q r) (p q) r= r (p q) Commutative Law = (r p) (r q) Distributive Law = (p r) (qr) Commutative Law (twice) (b) First, we note that q is "a 5"; and p is "n 7". So the expressions are: (p q) p q (p q)= p (q) De Morgan's Law = p q Involution Law
prepared by Roselina Sallehuddin and Razana Alwee 51

First, we note that r is "x 0". So the expressions are: p ((q r)) (p q) r p ((q r))= p ((q) r)De Morgan's Law = p (q r) = (p q) r Double negation Law Associative Law

prepared by Roselina Sallehuddin and Razana Alwee

52

Proof Techniques
Direct Proof or Proof by Direct Method

Proof of those theorems that can be expressed in the form x (P(x) Q(x)), D is the domain of discourse Select a particular, but arbitrarily chosen, member a of the domain D Show that the statement P(a) Q(a) is true. (Assume that P(a) is true Show that Q(a) is true By the rule of Universal Generalization (UG), x (P(x) Q(x)) is true

Proof Techniques
Direct Proof - Example for all integer x, if x is odd, then x2 is odd Or P(x) = x is an odd integer Q(x) = x2 is an odd integer

x( P ( x) Q ( x )) the domain of discourse is set Z of all ,


Can verify the theorem for certain value of x. x=3, x2 =9 ; odd

integer

Proof Techniques
a is an odd integer

a 2n 1

for some integer n

a 2 (2n 1) 2 a 2 4n 2 4n 1 a 2 2(2n 2 2n) 1 a 2 2m 1 a 2 is an odd integer


where m= 2n2 +2n is an integer

Proof Techniques
Indirect Proof

The implication p q is equivalent to the implication (q p) Therefore, in order to show that p q is true, one can also show that the implication (q p) is true To show that (q p) is true, assume that the negation of q is true and prove that the negation of p is true

Indirect Proof - Example P(n) : n2+3 is an odd number Q(n) : n is even numbern 3 (2k 1)
2 2

n ( P ( n ) Q ( 4k)) 4k 1 3 n
4k 2 4 k 4
2

2k 2 P ( n ) Q ( n ) ~ Q ( n)2(~k 2)( n ) P

~Q(n) is true , n is not even, n is odd so n=2k+1


n
2

3 (2 k 1)
2 2

4 k 4 k

4 k 1 3 4 k 4
2

2 (2 k

2 k 2 )

t 2k 2 2k 2 n 2 3 2t

t is integer

n2+3 is an even integer, thus ~P(n) is true

Proof Techniques
Proof by Contradiction Assume that the conclusion is not true and then arrive at a contradiction Example: Prove that there are infinitely many prime numbers Proof: Assume there are not infinitely many prime numbers, therefore they are listable, i.e. p1,p2,,pn Consider the number q = p1p2pn+1. q is not divisible by any of the listed primes Therefore, q is a prime. However, it was not listed. Contradiction! Therefore, there are infinitely many primes

Proof Techniques

You might also like