Lecture # 02 - New

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 49

CSC:102 Discrete Structure

Instructor : Khurram Iqbal

Department of Computer Science


COMSATS University, Islamabad
Recap

Lecture No 1

Department of Computer Science 2


What is Discrete Structure?

Department of Computer Science Dr.Eng. Mohammed Alhanjouri 23年 8月 31 3



What is Logic?

 Logic is the study of principles and techniques


of reasoning.
 Science of Reasoning
 Logic n.1. The branch of philosophy concerned
with analysing the patterns of reasoning by
which a conclusion is drawn from a set of
premises, without reference to meaning or
context
(Collins English Dictionary)
 “Logic is the beginning of wisdom, not the
end”

Department of Computer Science


What is Proposition?

 A declarative sentence that is either true or


false but not both.
 If a proposition is true, we say that it has a
truth value of "true”.
 If a proposition is false, its truth value is
"false".
 The truth values “True” and “False” are,
respectively, denoted by the letters T and F.

Department of Computer Science


Your Turn

UNDERSTANDING STATEMENTS

1. x + 2 is positive.
2. May I come in?
3. Logic is interesting.
4. It is hot today.
5. -1 > 0
6. x + y = 12

{Some of these sentences are statements and others are not.


Can you tell?}

Department of Computer Science 6


Can you state the truth value of following statements

1. “3 + 2 = 5” and “Lahore is a city in Pakistan”

2. “The grass is green” or “ It is hot today”

3. “Discrete Mathematics is not difficult to me”

Department of Computer Science 7


Symbolic Representation

Statements are symbolically represented by letters such as p, q, r,...

EXAMPLES
p = “Islamabad is the capital of Pakistan”
q = “17 is divisible by 3”

Department of Computer Science 8


Today Covered

After completing this lecture, you will be able to


know
 What this Compound Statement?
 What are Logical connectors?
 How to construct a truth table for a
Compound statements.
 Examples

Department of Computer Science


Lecture No 2
Compound statements and their Truth
Tables

Department of Computer Science 10


Compound Statement

Simple statements could be used to build a compound statement.

EXAMPLES

1. “3 + 2 = 5” and “Lahore is a city in Pakistan”

2. “The grass is green” or “ It is hot today”

3. “Discrete Mathematics is not difficult to me”

AND, OR, NOT are called LOGICAL CONNECTIVES.

Department of Computer Science 11


Logical Connectives

CONNECTIVE MEANINGS SYMBOL CALLED

Negation not ~ Tilde


Conjunction and  Hat
Disjunction or  Vel
Conditional if…then…  Arrow
Biconditional if and only if  Double arrow

Department of Computer Science 12


Examples

p = “Islamabad is the capital of Pakistan”


q = “17 is divisible by 3”

p  q = “Islamabad is the capital of Pakistan and 17 is divisible by 3”

p  q = “Islamabad is the capital of Pakistan or 17 is divisible by 3”

~p = “It is not the case that Islamabad is the capital of Pakistan” or


simply “Islamabad is not the capital of Pakistan”

Department of Computer Science 13


Application of Propositional
Logic
Translating English Sentences

Department of Computer Science


Translating from English to Symbols

Let p = “It is hot”, and q = “ It is sunny”

SENTENCE SYMBOLIC FORM

1. It is not hot. ~p

2. It is hot and sunny. p q


3. It is hot or sunny. q
p
4. It is not hot but sunny. ~ p q
5. It is neither hot nor sunny. ~ p  ~ q

Department of Computer Science 15


Example

Let h = “Zia is healthy”


w = “Zia is wealthy”
s = “Zia is wise”
Translate the compound statements to symbolic form:
1. Zia is healthy and wealthy but not wise. (h  w)  (~s)
2. Zia is not wealthy but he is healthy and wise. ~w  (h  s)
3. Zia is neither healthy, wealthy nor wise. ~h  ~w  ~s

Department of Computer Science 16


Translating from Symbols to English

Let m = “Ali is good in Mathematics”


c = “Ali is a Computer Science student”
Translate the following statement forms into plain English:

1. ~c Ali is not a Computer Science student.


2. c m Ali is a Computer Science student or good in Maths.
3. m  ~ c Ali is good in Maths but not a Computer Science student

Department of Computer Science 17


Truth Table

A convenient method for analyzing a compound


statement is to make a truth table for it.
A truth table specifies the truth value of a
compound proposition for all possible truth values
of its constituent propositions.

The truth values “true” and “false” are


respectively denoted by the letters T and F.

Department of Computer Science 18


Negation(~)

If p is a statement variable, the negation of p, “not


p”, is denoted as “~p”
It has opposite truth value from p i.e.,
if p is true, ~p is false; if p is false, ~p is true.

Department of Computer Science 19


Truth Table for ~ p

p ~p

T F

F T

Department of Computer Science 20


Conjunction ()

If p and q are statements, then the conjunction of


p and q is “p and q”, denoted as “p  q”
It is true when, and only when, both p and q are
true. If either p or q is false, or if both are false,
pq is false.

Department of Computer Science 21


Truth Table for p  q

p q pq

T T T

T F F

F T F

F F F

Department of Computer Science 22


Switches in Series

Switches Light
P Q Bulb
_ Light
Bulb P Q State
+
Closed Closed On

Closed Open Off

Open Closed Off


open
Open Open Off
closed

Department of Computer Science 23


Switches in Series

Switches Light P Q P Q
Bulb
P Q State T T T
Closed Closed On
T F F
Closed Open Off
F T F
Open Closed Off

Open Open Off F F F

The words closed and on are replaced by T and open and off are
replaced by F

Department of Computer Science 24


Disjunction or Inclusive OR

If p & q are statements, then the disjunction of p


and q is “p or q”, denoted as “p  q”
It is true when at least one of p or q is true and is
false only when both p and q are false.

Department of Computer Science 25


Truth Table for p  q

p q pq

T T T

T F T

F T T

F F F

Department of Computer Science 26


Switches in Parallel

P
Switches Light
Bulb
_ Q
Light P Q State
+ Bulb
Closed Closed On

Closed Open On

Open Closed On

Open Open Off

Department of Computer Science 27


Switches in Parallel

Switches Light P Q PQ


Bulb
P Q State T T T
Closed Closed On
T F T
Closed Open On
F T T
Open Closed On

Open Open Off F F F

The words closed and on are replaced by T and open and off are
replace by F.
Department of Computer Science 28
Remark

In English language the word or is sometimes used in an


inclusive sense (p or q or both).
Example I shall buy a pen or a book.
The word or is sometimes used in an exclusive sense (p or
q but not both)
Example Tomorrow at 9, I shall be in Lahore or
Islamabad.
While defining a disjunction the word or is used in its
inclusive sense. Thus the symbol  means the “inclusive
or”

Department of Computer Science 29


Exclusive OR

When or is used in its exclusive sense, The


statement “p or q” means “p or q but not both” or
“p or q and not p and q” which translates into
symbols as:
(p q)  ~(p  q)
Which is abbreviated as:
pq
or p XOR q

Department of Computer Science 30


Truth Table for Exclusive OR

p q pq pq ~ (pq) (pq)  ~ (pq)

T T T T F F

T F T F T T

F T T F T T

F F F F T F

Department of Computer Science 31


UPSHOT

p q pq pq pq

T T T T F

T F F T T

F T F T T

F F F F F

Department of Computer Science 32


Examples

Department of Computer Science


Examples

1. ~pq
2. ~ p  (q  ~ r)
3. (pq)  ~ (pq)

Department of Computer Science 34


How to construct truth table of statement form?

1. Note the distinct statement variables (such as


p, q, r, …) in the statement form.
2. Write all possible combinations of truth values
for the statement variables. Remember that for
n statements variables there are 2n possible
combinations of truth values.
3. Write the truth values for the expression within
the innermost parentheses (expression
evaluated left to right), and then within the
next innermost parentheses and so forth, until
the complete expression is evaluated.
Department of Computer Science 35
Example 1

Write truth table for the statement form ~ p  q

p q ~p ~pq

T T F F
T F F F
F T T T
F F T F

Department of Computer Science 36


Your Turn

Construct the Truth Table for (pq)  ~ (pq)

p q pq pq ~ (pq) (pq)  ~ (pq)

T T T T F F

T F T F T T

F T T F T T

F F F F T F

Department of Computer Science 37


Application of Propositional
Logic
Digital Logic Gates
and
COMBINATIONAL CIRCUIT

Department of Computer Science


Digital Logic Gate

The basic electronic components of a digital system are called digital


logic gates.
The word logic indicates the important role of logic in the design of
such circuits & the word digital indicates that the circuits process
discrete, or separate, signals.
Electronic engineers use the language of logic when they refer to
values of signals produced by an electronic switch as being “true” or
“false”.
But they generally use the symbols 1 and 0 rather than T and F to
denote these values.
The symbols 0 and 1 are called bits, short for binary digits.

Department of Computer Science 39


Basic Logic Gate

1. NOT-gate
A NOT-gate (or inverter) is a circuit with one input and one
output signal. If the input signal is 1, the output signal is 0.
Conversely, if the input signal is 0, then the output signal is 1.

Symbolic Representation & Input/Output Table

P R
Input Output
NOT
P R
1 0
0 1
Department of Computer Science 40
2. AND-gate
An AND-gate is a circuit with two input signals and one output
signal.
If both input signals are 1, the output signal is 1. Otherwise the
output signal is 0.
Symbolic representation & Input/Output Table
Input Output
P P Q R
AND R
Q 1 1 1
1 0 0
0 1 0
0 0 0
Department of Computer Science 41
3. OR-gate
An OR-gate is a circuit with two input signals and one output
signal.
If both input signals are 0, then the output signal is 0.
Otherwise, the output signal is 1.
Symbolic representation & Input/Output Table
Input Output
P P Q R
R
OR
1 1 1
Q
1 0 1
0 1 1
0 0 0
Department of Computer Science 42
Application of Propositional
Logic

Department of Computer Science


Combinational Circuit

A Combinational Circuit is a compound circuit consisting of the basic


logic gates such as NOT, AND, OR.

P
AND
Q
OR

R NOT

Department of Computer Science 44


Circuit corresponding to a Boolean Expression

EXERCISE
Construct circuit for the Boolean expression (PQ)  ~R
SOLUTION

P PQ
AND
Q
(P  Q)  ~R
OR
~R
R NOT
Department of Computer Science 45
Finding a Boolean Expression for a Circuit

EXERCISE
Find the Boolean expression for circuit

P
OR
Q

AND

R OR

Department of Computer Science 46


SOLUTION
Trace through the circuit from left to right, writing down the output of
each logic gate.

P PQ
OR
Q
(PQ)  (PR)
AND

R OR
PR

Hence (PQ) (PR) is the Boolean expression for this circuit.

Department of Computer Science 47


CONCLUSION

Department of Computer Science


Summary

1. What is a statement?
2. How a compound statement is formed.
3. Logical connectives (negation, conjunction, disjunction).
4. How to construct a truth table for a statement form.

Department of Computer Science 49

You might also like