0% found this document useful (0 votes)
6 views

CS101 Chapter 1 - Week 1_MG

Uploaded by

Shehab magdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

CS101 Chapter 1 - Week 1_MG

Uploaded by

Shehab magdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Pharos University in Alexandria

Faculty of Computer Science & Artificial Intelligence


Course Title: Discrete Structures
Code: CS 101

Week 1 - Chapter 1

The foundations: Logic and Proofs

Dr. eng Maha Ghoneim


Email: [email protected]
Mobile: 01000110740

Slides are adopted from “Discrete Mathematics and It's Applications” Kenneth H. Rosen; 7th edition, 2012.
WEEK 1 1
How to do well in this course?
BEFORE every lecture
o Read the relevant portion of the textbook
DURING every lecture
o Ask questions if anything is not clear
AFTER every lecture
o Review the lecture slides.
o Solve all exercises assigned after each section

IF anything is not clear


THEN ask me about it at the beginning of the next lecture
OR visit me in my office during office hours
IF any exercise is not solvable for you,
THEN ask me or ask the teaching assistant directly
WEEK 1 2
Course Contents
❑ Logic and proofs

❑ Sets, and Functions

❑ Counting

❑ Relations

❑ Graph theory

❑ Trees

WEEK 1 3
What is Discrete Mathematics?
• Discrete mathematics is mathematics that deal
with discrete objects.

– Discrete objects are separated from each other, such as:


Integers, rational numbers, automobiles, houses, people
etc.
– We will learn the concepts associated with discrete
objects, their properties, and relationships among them
among others.

• Because discrete mathematics includes more topics, We can


view it as the mathematics that is necessary for decision
making in non-continuous situations
WEEK 1 4
Why is Discrete Mathematics so crucial?
1. Foundation of Computer Science
Discrete mathematics provides the theoretical foundation for many areas of computer
science. Key topics such as algorithms, data structures, and complexity theory all rely on
principles of discrete mathematics, including graph theory, combinatorics, and logic.
Programming Languages: Logical structures and propositional logic in discrete math are
used in designing and verifying algorithms.

2. Cryptography
Discrete mathematics, particularly number theory and combinatorics, is crucial for
modern cryptography. Techniques like RSA encryption are based on the difficulty of
factoring large numbers and solving problems in finite fields.
Security: Cryptography uses properties of prime numbers, modular arithmetic, and
complexity theory from discrete mathematics to secure communications.

3.Probability Theory: Discrete probability, an essential component of discrete


mathematics, is used in AI, machine learning, and network security to analyze events.

WEEK 1 5
Why is Discrete Mathematics so crucial?

4.Database organization: Trees and Graphs are Fundamental in database organization,


compiler design, and file systems.

5. Coding Theory
Error detection and correction in communication systems depend on discrete
mathematics, particularly through coding theory. This is essential for data transmission
and storage, from CDs and DVDs to digital communication networks.

6. Algorithmic Thinking
Discrete mathematics trains individuals in algorithmic thinking, which is crucial for solving
problems in computer science, engineering, and operations research. Propositional logic
problems in discrete mathematics lead directly to algorithms used in real-world
applications.

WEEK 1 6
Chapter 1

1.1 Propositional Logic

WEEK 1 7
1.1 Propositional Logic
1- A proposition:
Is a declarative sentence (that is, a sentence that declares a fact) that is either true or false,
but not both or somewhere “in between!” . Commands and questions are not propositions.
❑ EXAMPLE 1: All the following declarative sentences are propositions.
1. Washington, D.C., is the capital of the USA.
2 . Cairo is the capital of Egypt.
3.1+1=2.
4.2+2=3.
➢ Propositions 1 and 3 are true, whereas 2 and 4 are false

❑ EXAMPLE 2: All the following sentences are not propositions.


1 . What time is it?
2 . Read this carefully.
3.x+1=2
4.x+y=Z
➢ Sentences 1 and 2 are not propositions because they are not declarative sentences.
➢ Sentences 3 and 4 are not propositions because they are neither true nor false
➢ Each of sentences 3 and 4 can be turned into a proposition if we assign values to the variables.

WEEK 1 8
1.1 Propositional Logic
2-Propositional variables (or statement variables):
are letters used to represent propositions, not used to denote numerical variables.
➢The conventional letters used for propositional variables are p, q , r, s, . . . .
➢The truth value of a proposition is denoted by:
•T if it is a true proposition
•F if it is a false proposition

3-Propositional logic (or propositional calculus):


is the area of logic that deals with propositions.

4- Negation operator:
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."
•The truth value of the negation of p, p, is the opposite of the truth value of p.

WEEK 1 9
1.1 Propositional Logic
❑ EXAMPLE 3:
Find the negation of the proposition
"Today is Friday.“ and express this in simple English.

Solution: The negation is "It is not the case that today is Friday."
This negation can be more simply expressed by
•"Today is not Friday,“ Or,
•"It is not Friday today.”

❑ Truth Table for p and ¬ p

WEEK 1 10
1.1 Propositional Logic
5-Compound:
Propositions, are formed from existing propositions using logical operators.

6-Conjunction Operator

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
• False otherwise.

WEEK 1 11
1.1 Propositional Logic
❑ Truth Table for p  q

❑ Example 5:
Find the conjunction of the propositions p and q where:
– p is the proposition "Today is Friday “
– q is the proposition "It is raining today“

Solution: The conjunction p  q is the proposition:


– "Today is Friday and it is raining today"

• This proposition is:


– True on rainy Fridays
– False on any day that is not a Friday and on Fridays when it does not rain
WEEK 1 12
1.1 Propositional Logic
7- Disjunction Operator
Let p and q be propositions.
The disjunction of p and q, denoted by p V q, is the proposition “p or q”.

➢The disjunction p V q is:


• False when both p and q are false and
• True otherwise.

❑ Truth Table for p  q

WEEK 1 13
1.1 Propositional Logic
❑ Example:
Find the disjunction of the propositions p and q where:
• p is the proposition "Today is Friday “
• q is the proposition "It is raining today“

Solution:
The disjunction p v q is the proposition:
"Today is Friday or it is raining today.“

This proposition is:


• True on any day that is either a Friday or a rainy day
(including rainy Fridays)
• False only on days that are not Fridays when it also does not rain.
➢Note that: Connective OR is used in two ways:

WEEK 1 14
1.1 Propositional Logic
A) Inclusive Or (normal or)
– A disjunction is True when at least one of the two propositions is true.

❑ Example:
"Students who have taken calculus or computer science can take this class“
• That is, students that can take the class are:
– Who have taken both calculus and computer science,
– Who have taken calculus
– Who have taken computer science

WEEK 1 15
1.1 Propositional Logic
B) Exclusive Or
Let p and q be propositions.
The exclusive OR of p and q, denoted by p q (p XOR q),is the proposition that is:

• True when exactly one of p and q is true and

• False otherwise.

❑ Truth Table for p  q

WEEK 1 16
1.1 Propositional Logic
❑ Example:

1-"Students who have taken calculus or computer science, but not both,
can enroll in this class"
• That is, students who can take the class are: Who have taken calculus, Who have
taken computer science but not those who have taken both calculus and a
computer science course are allowed to take the class.

2- A main dish in a restaurant comes with a soup or Salad/ potato or rice


• The restaurant always means that customers can have either Soup or Salad/potato
or rice , but not both

WEEK 1 17
1.1 Propositional Logic
8-Conditional Statements:
Let p and q be propositions. The conditional statement p → q is the
proposition "if p, then q" .The conditional statement p → q is:

• False when p is true and q is false, and


• True otherwise.

➢ In the conditional statement p → q , p is called the hypothesis and q is


called the conclusion.

➢ A conditional statement is also called an implication.

WEEK 1 18
1.1 Propositional Logic
❑ The truth table for the conditional statement p → q is shown in Table.

➢ Note that:
The statement (p → q) is true when:
-both p and q are true, and when:
-p is false (no matter what truth value q has).

WEEK 1 19
1.1 Propositional Logic
ways to express this conditional statement:
• "if p, then q"
• "if p, q "
• "p is sufficient for q"
• "q if p"
• "q when p"
• "a necessary condition for p is q"
• "q unless → p"
• "p implies q"
• "p only if q"
• "a sufficient condition for q is p"
• "q whenever p"
• "q is necessary for p"
• "q follows from p" WEEK 1 20
1.1 Propositional Logic
❑ Example:
Let p be the statement “Ahmad learns discrete mathematics" and q the
statement “Ahmad will find a good job“.
Express the statement p → q in English

• Solution:
The statement p → q can be expressed in English by several ways:
–If Ahmad learns discrete mathematics, then he will find a good job
–Ahmad will find a good job when he learns discrete mathematics
–For Ahmad to get a good job, it is sufficient for him to learn discrete
mathematics
–Ahmad will find a good job unless he does not learn discrete
mathematics

WEEK 1 21
1.1 Propositional Logic
9-Converse, Contrapositive, and Inverse
There are three related conditional statements to statement p → q:
• The converse of p → q is q → p
• The contrapositive of p → q is ¬ q → ¬ p
• The inverse of p → q is ¬ p → ¬ q

➢ Note that
•Conditional statement and its contrapositive are equivalent.
•The converse and the inverse of a conditional statement are also equivalent

WEEK 1 22
1.1 Propositional Logic
❑ Example 9:
What are the contrapositive, the converse, and the inverse of the conditional
statement
"The home team wins whenever it is raining."?

Solution:
Because "q whenever p" is one of the ways to express the conditional
statement p → q , the original statement can be rewritten as

"If it is raining, then the home team wins ."

WEEK 1 23
1.1 Propositional Logic
Consequently,
• The contrapositive of this conditional statement is
"If the home team does not win, then it is not raining."

•The converse is
"If the home team wins, then it is raining.“

• The inverse is
"If it is not raining, then the home team does not win.“

➢ Note that:
Only the contrapositive is equivalent to the original statement.

WEEK 1 24
1.1 Propositional Logic
10-Biconditional

Let p and q be propositions. The biconditional statement p q is the


proposition "p if and only if q .
" The biconditional statement p q is true when p , q have the same
truth values and is false otherwise.

Biconditional statements are also called bi-implications.


❑ The truth table for p  q

WEEK 1 25
1.1 Propositional Logic
❑ Example 10:
Let p be the statement "You can take the flight" and let q be the
statement "You buy a ticket.“

Then p q is the statement


"You can take the flight if and only if you buy a ticket.“

This statement is true if p and q are either both true or both false,
That is:
• if you buy a ticket and can take the flight or
•if you do not buy a ticket and you cannot take the flight.
•It is false when p and q have opposite truth values.
WEEK 1 26
1.1 Propositional Logic
• There are some other common ways to express p  q:
– "p is necessary and sufficient for q"
– "if p then q, and conversely"
– "p iff q.“

➢ Note that:

p  q has exactly the same truth value as (p → q)  (q → p).

WEEK 1 27
1.1 Propositional Logic

❑ Example 11:
Construct the truth table of the compound proposition

(p v ¬ q) → (p  q).

WEEK 1 28
1.1 Propositional Logic
11-Logic and Bit Operations
Computers represent information using bits (binary digits)
A bit is a symbol with two possible values: 0 and 1

- A bit can be used to represent a truth value


Because there are two truth values: true and false.
Then we can use the bits as follow:
1 represents T (true)
0 represents F (false)
-A variable is called a Boolean variable if its value is either true or false.
-A Boolean variable can be represented using a bit.

WEEK 1 29
1.1 Propositional Logic
Bit Operations correspond to Logical Connectives

After replacing true by 1 and false by 0 in the truth tables, we can use
the bit operators OR, AND, and XOR as follow:

WEEK 1 30
1.1 Propositional Logic
12-Bit string
A bit string is a sequence of zero or more bits. The length of this string is
the number of bits in the string.
101010011 is a bit string of length nine.

We can extend bit operations to bit strings.


bitwise OR, bitwise AND, and bitwise XOR
Bitwise OR of two strings of the same length is the string that have
the OR of the corresponding bits in the two strings
Similarly for bitwise AND and bitwise XOR

We use the symbols , , and  to represent the bitwise OR, bitwise


AND, and bitwise XOR operations, respectively

WEEK 1 31
13-Bit Operations

▪ Boolean values can be represented as 1 (true) and 0 (false)

▪ A bit string is a series of Boolean values. Length of the string is the


number of bits.

▪ 10110100 is eight Boolean values in one string

▪ We can then do operations on these Boolean strings.

▪ Each column is its own Boolean operation

01011010
10110100
11101110
WEEK 1 32
❑ Example :
Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings
0 1 1 0 1 1 0 1 1 0 and 1 1 000 1 1 1 0 1 .
(Note that: bit strings will be split into blocks of four bits to make them easier to
read.)

Solution:
The bitwise OR, bitwise AND, and bitwise XOR of these strings are obtained by
taking the OR, AND, and XOR of the corresponding bits, respectively.

01 1011 0110
11 0001 1101

1 1 1 0 1 1 1 1 1 1 bitwise OR
0 1 0 0 0 1 0 1 0 0 bitwise AND
1 0 1 0 1 0 1 0 1 1 bitwise XOR
WEEK 1 33

You might also like