0% found this document useful (0 votes)
7 views314 pages

Discrete Structures Lectures

Uploaded by

yamimuto83
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)
7 views314 pages

Discrete Structures Lectures

Uploaded by

yamimuto83
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/ 314

Assiut University

‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Reference
• Discrete Mathematics and Its Applications by Kenneth Rosen
What is Discrete?
• Computers are fundamentally digital machines.
• Everything is binary, either a 0 or a 1. This finite and discrete nature of
computers links them deeply to discrete mathematics.
• Discrete mathematics is the study of mathematical structures that are
somehow “discrete”.
• Discrete contrasts with “continuous”, as you know well from the real
numbers R and calculus.
Logic and Proofs
• Propositional logic
• Predicate logic
Propositional logic
• Propositions in discrete structures are statements that can be either
true or false.
• They are the fundamental building blocks of logical reasoning and
argumentation.

• Characteristics of Propositions:
• Definiteness: A proposition must have a clear and unambiguous meaning.
• Truth Value: A proposition can only have one of two truth values: true or false.
• Simplicity: Propositions should generally be simple and declarative statements.
Propositional logic (Cont.)
• Examples of Propositions:
• "The Earth is round."
• "2 + 2 = 4."
• "It is raining outside."
• "The cat is on the mat."
Propositional logic (Cont.)
• Non-Examples of Propositions:
• "What is your name?" (This is a question, not a statement.)
• "Go away!" (This is a command, not a statement.)
• x+3=5
Proposition (True or False)
• "The sky is blue" True
• "Go to bed " False
• "It is raining" True
• "It is not raining." True
Proposition (True or False)
Which of the following are propositions?
• System software is a required course for sophomores (proposition)
• Margaret wrote Gone with the Wind (proposition)
• How are you?
• 1+2=3 (proposition)
• 1+2=4 (proposition)
• n2+1 is a prime number
• n2+1 is a prime number for n=2 (proposition)
• The number x is an integer
• Get up and do your exercises.
Constructing Propositions
• An entire proposition is often denoted by a single propositional
variable. Propositional variables are typically among p, q, r, s, t,…

• p = "The sky is blue“

• When a proposition (or proposition variable) is known to always be


true, we can replace it by T.
• When a proposition (or proposition variable) is known to always be
false, we can replace it by F.
Connectives
• We can combine propositions (and propositional variables) into
compound propositions or propositional formulas.
• Propositions can be combined using logical operators to form more
complex statements:
1. Conjunction (AND): p ∧ q (p and q) is true only if both p and q are true.
2. Disjunction (OR): p ∨ q (p or q) is true if either p or q (or both) is true.
3. Negation (NOT): ¬p (not p) is true if p is false and vice versa.
4. Exclusive Or (XOR): The exclusive or of p and q, denoted by p ⊕ q, is the
proposition that is true when exactly one of p and q is true and is false
otherwise.
5. Implication (IF-THEN): p → q (if p then q) is true unless p is true and q is false.
6. Biconditional (IF AND ONLY IF): p q (p if and only if q) is true if both p and q
have the same truth value.
1-Negation
• Negation in discrete structures is a logical operation that reverses
the truth value of a proposition. If a proposition is true, its negation
is false; if a proposition is false, its negation is true.
• Notation:
• ¬p or ~p is commonly used to denote the negation of proposition p.
• Truth Table:

p ¬p
T F
F T
1-Negation (Cont.)
• Examples:
• Proposition: "It is raining."
• Negation: "It is not raining."

• Proposition: "2 + 2 = 5."


• Negation: "2 + 2 ≠ 5."

• Double Negation: ¬(¬p) ≡ p (The negation of the negation of a


proposition is equivalent to the original proposition.)
2-Conjunction
• Conjunction is a logical operation that combines two
propositions into a single proposition that is true only when both
original propositions are true. It is often represented by the word
"and" or the logical symbol ∧.
• Truth Table:
p q p∧q
T T T
T F F
F T F
F F F
2-Conjunction (Cont.)
• Examples:
• Proposition 1: "It is raining."
• Proposition 2: "The sky is cloudy."
• Conjunction: "It is raining, and the sky is cloudy."

• Proposition 1: "2 + 2 = 4."


• Proposition 2: "3 × 3 = 9."
• Conjunction: "2 + 2 = 4 and 3 × 3 = 9."
2-Conjunction (Cont.)
• Properties of Conjunction:
• Commutative: p ∧ q ≡ q ∧ p (The order of the propositions does not affect
the result.)
• Associative: (p ∧ q) ∧ r ≡ p ∧ (q ∧ r) (The grouping of propositions does not
affect the result.)
• Identity: p ∧ T ≡ p (Conjunction with the truth value T does not change the
proposition.)
• Domination: p ∧ F ≡ F (Conjunction with the truth value F always results
in F.)
3-Disjunction
• Disjunction is a logical operation that combines two propositions
into a single proposition that is true if either or both original
propositions are true. It is often represented by the word "or" or
the logical symbol ∨.
• Truth Table:
p q p∨q
T T T
T F T
F T T
F F F
3-Disjunction (Cont.)
• Examples:
• Proposition 1: "It is raining."
• Proposition 2: "The sky is cloudy."
• Disjunction: "It is raining, or the sky is cloudy."

• Proposition 1: "2 + 2 = 4."


• Proposition 2: "3 × 3 = 9."
• Disjunction: "2 + 2 = 4 or 3 × 3 = 9."
3-Disjunction (Cont.)
• Properties of Disjunction:
• Commutative: p ∨ q ≡ q ∨ p (The order of the propositions does not affect
the result.)
• Associative: (p ∨ q) ∨ r ≡ p ∨ (q ∨ r) (The grouping of propositions does not
affect the result.)
• Identity: p ∨ F ≡ p (Disjunction with the truth value F does not change the
proposition.)
• Domination: p ∨ T ≡ T (Disjunction with the truth value T always results in
T.)
4- Exclusive Or
• Exclusive OR (XOR) is a logical operation that returns true if and
only if exactly one of its inputs is true. It can be thought of as
"either A or B, but not both.“
• p ⊕ q ≡ (p ∧ ¬q) ∨ (¬p ∧ q)

• Truth Table: p q p⊕q


T T F
T F T
F T T
F F F
5-Implication
• Implication is a logical connective that relates two propositions.
It is often expressed as "if p then q" or "p implies q." The
implication is true unless p is true and q is false.

p q p→q
T T T
T F F
F T T
F F T
5-Implication (Cont.)
• Examples:
• Proposition 1: "It is raining."
• Proposition 2: "The ground is wet."
• Implication: "If it is raining, then the ground is wet."

• Proposition 1: "2 + 2 = 5."


• Proposition 2: "The sky is blue."
• Implication: "If 2 + 2 = 5, then the sky is blue."
5-Implication (Cont.)
• If q is true, then p→q is always true.
• If p is true and the implication correct (the obligation is upheld),
then q can never be false.
• “Falsity can imply anything.” If the hypothesis is false, then the
implication is always true, regardless of the whether or not the
conclusion is true.
5-Implication (Cont.)
• p → q is false only when p is true and q is false. We do not want a true statement to lead us into believing
something that is false.

• Example:
• If I weight more than 120 pounds (p), I shall enroll in an exercise class (q)
• p q s=p→q
• T T T
• T F F I broke my promise
• F T T
• F F T
5-Implication (Cont.)
• Ways to express p→q :
• “if p, then q”
• “p implies q”
• “if p, q”
• “p only if q”
• “p is sufficient for q”
• “a sufficient condition for q is p”
• “q if p”
• “q whenever p”
• “q when p”
• “q is necessary for p”
• “a necessary condition for p is q”
• “q follows from p”
• “q unless ¬p”
5-Implication (Cont.)
• Example: Let p be the statement “Maria learns discrete mathematics” and q the statement “Maria will find a
good job.” Express the statement p → q as a statement in English.
• “If Maria learns discrete mathematics, then she will find a good job.”
• “Maria will find a good job when she learns discrete mathematics.”
• “For Maria to get a good job, it is sufficient for her to learn discrete mathematics.”
5-Implication (Cont.)
• Properties of Implication:
• Contrapositive: p → q ≡ ¬q → ¬p (The contrapositive of an implication is
logically equivalent to the original implication.)
• Converse: q → p (The converse of an implication is not necessarily
equivalent to the original implication.)
• Inverse: ¬p → ¬q (The inverse of an implication is not necessarily
equivalent to the original implication.)
5-Implication (Cont.)
• If n is divisible by 4, then n is an even integer. (Use if-then for an implication relationship.)
• Note: p → q does NOT imply  p →  q,
• p is sufficient, but not necessary condition of q.
• If n is not divisible by 4, then n is not an even integer. (Incorrect)
Sufficient Condition
• Being in the inner circle is sufficient for
being in the outer circle.
• "Being a human" is sufficient for
"being a mammal." (All humans are
mammals.)
• Being a square is a sufficient condition
(but not a necessary one) for
something's having four sides.
• A condition p is sufficient for a
condition q if and only if whenever p is
true, q must also be true.
• Symbolically: p → q
Necessary Condition
• Being in the outer circle is necessary for
being in the inner circle.
• air is a necessary condition for human
life
• it is by no means a sufficient condition, i.e.
it does not, by itself, i.e. alone, suffice for
human life.
• A condition p is necessary for a
condition q, p must be true in order
for q to be true.
• Symbolically: q → p
• If x is a necessary condition for y, then y is a sufficient condition for x.
• And, equivalently, If y is a sufficient condition for x, then x is a
necessary condition for y.

• "Since having a microscope is necessary for seeing viruses, then seeing


viruses guarantees that one has a microscope (i.e. suffices for having a
microscope).“

• "Since every square must have four sides (i.e. since having four sides is a
necessary condition for being a square), being a square is a sufficient
condition (but not a necessary one) for something's having four sides." Put
another way: "All squares (must) have four sides; but not all four-sided
things [e.g. trapezoids] are squares."
6-Biconditional
• Biconditional is a logical connective that relates two
propositions. It is often expressed as "if and only if" or "p if and
only if q." The biconditional is true if and only if both propositions
have the same truth value.
• Truth Table:
p q p q
T T T
T F F
F T F
F F T
6-Biconditional (Cont.)
• Examples:
• Proposition 1: "It is raining."
• Proposition 2: "The ground is wet."
• Biconditional: "It is raining if and only if the ground is wet."

• Proposition 1: "2 + 2 = 4."


• Proposition 2: "3 × 3 = 9."
• Biconditional: "2 + 2 = 4 if and only if 3 × 3 = 9."
6-Biconditional (Cont.)
• A condition p is necessary and sufficient for a condition q if and
only if p is both necessary and sufficient for q. This means that p
and q are logically equivalent.
• Symbolically: p q
6-Biconditional (Cont.)
• Properties of Biconditional:
• Equivalence: p q is equivalent to (p → q) ∧ (q → p).
• Commutative: p q ≡ q p
• Associative: (p q) r ≡ p (q r)
• Identity: p T ≡ p
• Negation: ¬(p q) ≡ (p ∧ ¬q) ∨ (¬p ∧ q)
6-Biconditional (Cont.)
• EXAMPLE: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.”
Propositional Formulas
• Propositional formulas, also known as logical expressions, are
combinations of propositions using logical operators. They are
used to represent complex logical statements and reasoning.

• Examples of Propositional Formulas:


• Simple proposition: "It is raining."
• Compound proposition: "It is raining, and the sky is cloudy." (using AND)
• Complex proposition: "(¬p ∨ q) → (p → r)" (using negation, disjunction,
and implication)
Order of precedence
1.Parenthesis: always perform operations on expressions inside
parentheses first.
2.Negation: apply negation to a proposition before binary connectives.
3.Conjunction: conjunction before disjunction
4.Disjunction: disjunction after conjunction, but before implication
5.Implication: → after ∧, ∨
6.Biconditional: after ∧,∨,→.
Example 1:
• Formula: p ∧ ¬q → r ∨ s
• Evaluation:
1. ¬q (negation)
2. p ∧ ¬q (conjunction)
3. r ∨ s (disjunction)
4. (p ∧ ¬q) → (r ∨ s) (implication)
Example 2:
• Formula: p → (q ∧ ¬r) s
• Evaluation:
1. ¬r (negation)
2. q ∧ ¬r (conjunction)
3. p → (q ∧ ¬r) (implication)
4. (p → (q ∧ ¬r)) s (biconditional)
Satisfiable
• A propositional formula is satisfiable if there exists at least one
truth assignment for its variables that makes the formula evaluate
to true.
• In other words, it is possible to assign truth values to the variables in a
way that makes the formula true.
• Example: Consider the propositional formula:(p ∧ q) → r
• This formula is satisfiable because there are multiple truth assignments
that make it true. For example, if we assign p = T, q = F, and r = T, the
formula evaluates to true.
Unsatisfiable Formulas
• An unsatisfiable formula is a propositional formula that cannot
be made true under any truth assignment for its variables.
• In other words, it is always false, regardless of the truth values assigned to
its propositions.
• Examples of Unsatisfiable Formulas:
• Contradictions: Formulas that are logically contradictory, such as:
• p ∧ ¬p (p and not p)
• (p → q) ∧ (p ∧ ¬q) (if p then q, and p and not q)
• Tautologies with Negation: Negations of tautologies (formulas that are
always true) are unsatisfiable.
• For example, if p ∨ ¬p is a tautology, then ¬(p ∨ ¬p) is unsatisfiable.
Unsatisfiable Formulas (Cont.)
• Properties of Unsatisfiable Formulas:
• Logical Equivalence: Unsatisfiable formulas are logically equivalent to
the constant false value (F).
• Negation: The negation of an unsatisfiable formula is a tautology.
• Conjunction: Conjoining an unsatisfiable formula with any other formula
results in an unsatisfiable formula.
• Disjunction: Disjoining an unsatisfiable formula with any other formula
results in the original formula.
Truth Tables
• Truth tables are a tabular representation of the truth values of a
propositional formula for all possible combinations of truth values
of its constituent propositions. They are a fundamental tool in
discrete structures for analyzing and understanding logical
expressions.
• Constructing a Truth Table:
1.List all possible combinations of truth values: For n propositions, there
will be 2^n possible combinations.
2.Evaluate the formula for each combination: Apply the logical operators
according to their truth tables to determine the truth value of the formula.
Example
• Consider the propositional formula: (p ∧ q) → r
p q r (p ∧ q) → r
T T T T
T T F F
T F T T
T F F T
F T T T
F T F T
F F T T
F F F T
Inverse, Converse, and Contrapositive
• Inverse is a logical operation that applies to conditional
statements (implications). Given an implication "p → q," the
inverse is "¬p → ¬q." In other words, it negates both the antecedent
(p) and the consequent (q).
• Example:
• Original implication: "If it rains, then the ground is wet."
• Inverse: "If it is not raining, then the ground is not wet."
• Truth Table:
p q p→q ¬p → ¬q
T T T T
T F F T
F T T F
F F T T
Inverse, Converse, and Contrapositive (Cont.)
• Converse is a logical operation that applies to conditional
statements (implications). Given an implication "p → q," the
converse is "q → p." In other words, it switches the antecedent and
the consequent.
• Example:
• Original implication: "If it rains, then the ground is wet."
• Converse: "If the ground is wet, then it is raining."
• Truth Table:
p q p→q q→p
T T T T
T F F T
F T T F
F F T T
Inverse, Converse, and Contrapositive (Cont.)
• Contrapositive is a logical operation that applies to conditional
statements (implications). Given an implication "p → q," the
contrapositive is "¬q → ¬p." In other words, it negates both the
antecedent (p) and the consequent (q) and switches their order.
• Example:
• Original implication: "If it rains, then the ground is wet."
• Contrapositive: "If the ground is not wet, then it is not raining."
p q p→q ¬q → ¬p
T T T T
T F F F
F T T T
F F T T
Inverse, Converse, and Contrapositive (Cont.)
• An implication is not equivalent to its converse or inverse. However,
it is equivalent to its contrapositive.
Translating English to Propositional Logic
• Translating English sentences into propositional logic involves breaking down the
sentences into simpler propositions and then connecting them using logical
operators.
• Key Steps:
1. Identify Propositions: Determine the basic atomic statements that can be either true or
false.
2. Assign Propositional Variables: Assign unique propositional variables (e.g., p, q, r) to each
proposition.
3. Translate Logical Connectives: Identify the logical relationships between the propositions
and represent them using the appropriate logical operators:
1. AND: ∧ (conjunction)
2. OR: ∨ (disjunction)
3. NOT: ¬ (negation)
4. IMPLIES: → (implication)
5. IF AND ONLY IF: (biconditional)
4. Combine Propositions: Use the logical operators to construct a propositional formula that
accurately represents the original English sentence.
Translating English to Propositional Logic
(Cont.)
• Example1:
• English Sentence: "If it rains, then the ground gets wet."
• Propositions:
• p: "It rains."
• q: "The ground gets wet."
• Propositional Formula: p → q
Translating English to Propositional Logic
(Cont.)
• Example2:
• English Sentence: "Either the cat is on the mat or the dog is barking."
• Propositions:
• p: "The cat is on the mat."
• q: "The dog is barking."
• Propositional Formula: p ∨ q
Translating English to Propositional Logic
(Cont.)
• Example3:
• English Sentence: " “If it is raining and I am going outside, I bring an
umbrella.”
• Propositions:
• p: “it is raining”
• q: “I am going outside”
• r: “I bring an umbrella”
• Propositional Formula: p ∧q → r
Tautologies and contradiction
• A tautology is a propositional formula that is always true,
regardless of the truth values of its constituent propositions.
• A contradiction is a propositional formula that is always false,
regardless of the truth values of its constituent propositions.
• Examples of Contradictions:
• Simple contradictions:
• p ∧ ¬p (p and not p)
• p → ¬p (if p then not p)
• Complex contradictions:
• (p ∨ q) ∧ (¬p ∧ ¬q)
• (p → q) ∧ (p ∧ ¬q)
Logically Equivalent
• Logically Equivalent refers to two propositional formulas that have the same
truth value for all possible combinations of truth values for their constituent
propositions.
• The compound propositions p and q are called logically equivalent if p q is a tautology.
The notation p ≡ q denotes that p and q are logically equivalent.
• Equivalence Laws:
• Identity laws:
• p∨F≡p
• p∧T≡p
• Domination laws:
• p∨T≡T
• p∧F≡F
• Idempotent laws:
• p∨p≡p
• p∧p≡p
Logically Equivalent (Cont.)
• De Morgan's laws:
• ¬(p ∧ q) ≡ ¬p ∨ ¬q
• ¬(p ∨ q) ≡ ¬p ∧ ¬q
• Double negation: ¬¬p ≡ p
• Commutative laws:
• p∨q≡q∨p
• p∧q≡q∧p
• 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)
• Material implication: p → q ≡ ¬p ∨ q
• Biconditional equivalence: p q ≡ (p → q) ∧ (q → p)
Logically Equivalent (Cont.)
• Absorption Laws:
p  (p  q) ≡ p and p  (p  q) ≡ p.
Logically Equivalent (Cont.)
Logically Equivalent (Cont.)
• A simple and explicit way to determine if two expressions are logically
equivalent is if their two columns in a truth table are identical.

p q ¬p p→q ¬p∨q
F F T T T
F T T T T
T F F F F
T T F T T
Logically Equivalent (Cont.)
p→q ≡ ( q) → ( p) ?

p q p→q q p ( q) → ( p)
T T T F F T
T F F T F F
F T T F T T
F F T T T T

p→q ≡ ( q) → ( p) (Contrapositive law)

• If n is divisible by 4, then n is an even integer.


• ( q) → ( p) :n is not an even integer → it is not divisible by 4.
Logically Equivalent (Cont.)
• Show that ¬(p ∨ q) and ¬p ∧¬q are logically equivalent.
Logically Equivalent (Cont.)
• Equivalence proof
• Prove that p∧(¬p∨q)≡p∧q.
p∧(¬p∨q)≡ (p∧¬p) ∨ (p∧ q) Distributive law
≡ F ∨ (p∧ q) Annihilation
≡ p∧ q Identity law
Logically Equivalent (Cont.)
• Example: Use De Morgan’s laws to express the negations of “Miguel has a cellphone and he has a laptop
computer”
• Let p be “Miguel has a cellphone” and q be “Miguel has a laptop computer.” Then “Miguel has a cellphone
and he has a laptop computer” can be represented by p ∧ q. By the first of De Morgan’s laws, ¬(p ∧ q) is
equivalent to ¬p ∨¬q. Consequently, we can express the negation of our original statement as “Miguel does
not have a cellphone or he does not have a laptop computer.”
Logically Equivalent (Cont.)
• Example: Show that ¬(p ∨ (¬p ∧ q)) and ¬p ∧¬q are logically equivalent by developing a series of logical
equivalences.

¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧¬(¬p ∧ q) by the second De Morgan law


≡ ¬p ∧ [¬(¬p)∨¬q] by the first De Morgan law
≡ ¬p ∧ (p ∨¬q) by the double negation law
≡ (¬p ∧ p) ∨ (¬p ∧¬q) by the second distributive law
≡ F ∨ (¬p ∧¬q) because ¬p ∧ p ≡ F
≡ (¬p ∧¬q) ∨ F by the commutative law for disjunction
≡ ¬p ∧¬q by the identity law for F
Logically Equivalent (Cont.)
Use the laws of logic to prove the following expression is a tautology: (Note: You must list each rule you use. The only
rules you can combine together in one step are the commutative and associative rules to reorder and group terms more
quickly. Hint: First try to “distribute” the not signs before you simplify any other part of the expression.)

( (p  r)  ( (q  r)  p) )   ( ((p  q) )  p )

Solution

( (p  r)  ( (q  r)  p) )   ( ((p  q) )  p ) ≡
( (p  r)  ( (q  r)  p) )  ( p  q)  p ≡ (De Morgans)
( (p  r)  ( (q  r)  p) )  ( p  q)  p ≡ (Double Negation)
(p  p)  ( (p  r)  (q  r)  (p  q)) ≡ (Comm+Assoc, or)
T  ( (p  r)  (q  r)  (p  q)) ≡ (Inverse Law)
T (Domination Law)
Rules of Inference
• Consider the following argument involving propositions (which, by definition, is a sequence of propositions):

“If you have a current password, then you can log onto the network.”
“You have a current password.”
Therefore,
“You can log onto the network.”

• We would like to determine whether this is a valid argument. That is, we would like to determine whether the
conclusion “You can log onto the network” must be true when the premises “If you have a current password,
then you can log onto the network” and “You have a current password” are both true.
Rules of Inference (Cont.)
•The general form of a rule of inference is:
p1
p2
..
.
pn
____
q
•The rule states that if p1 and p2 and … and pn are all true, then q is true as well.
•P1, P2 … called the premises of the argument
•q is the conclusion for the argument.
•if this statement is always true (a tautology), it is a valid argument.

•These rules of inference can be used in any mathematical argument and do not
require any proof.
Rules of Inference (Cont.)
• Essentially, to show that this statement is always true (a tautology), we must show that if all of p1 through pn are true, then q must be true as well.
• Another way to look at this is that we must show that if q is ever false, then at least ONE of p1 through pn must be false as well. (This is the
contrapositive of the original assertion.)
• Let us look at an example of how you might go about proving a statement in a general form, given some extra information.
• Let p, q, are r be the following statements:
• p: Roger studies
• q: Roger plays racketball
• r: Roger passes discrete mathematics
• Let the premises be the following:
• p1 : If Roger studies, he will pass discrete mathematics.
• p2 : If Roger does not play racketball, then he will study.
• p3 :Roger failed discrete mathematics.
• Is the argument (p1 and p2 and p3) → q is valid?
• P1: p→ r
• P2: q → p
• P3:  r
• ((p→r)  (q → p)  (r) ) → q
• We can prove that this is a tautology by using a truth table; verifying that this expression is true for all 8 possible sets of values for p, q and r
Rules of Inference (Cont.)
Another way we can show this statement is to use the laws of logic to simplify the statement as follows:
((p→r)  ( q → p)  ( r) ) → q
[(p  r)  (q  p)  (r)] → r (Identity for implication)
[(p  r)  (q  p)  (q)] → r (Double Negation)
 [((p  r)  (q  p))  (q)]  r (Identity for implication)
((p  r)  (q  p))   (q)  r (De Morgan’s Law)
((p  r)  (q  p))  q  r (Double Negation)
(p  r) (q  p)  q  r (De Morgan’s Law)
(p  r)  (q  p)  q  r (De Morgan’s Law)
(p  r)  (q  p)  q  r (Double Negation)
(r  (p  r))  (q  (q  p)) (Associate+Commutative)
((r  p)  (r  r))  ((q  q)  (q  p)) (Distributive)
((r  p)  T)  (T  (q  p)) (Inverse Laws)
(r  p)  (q  p) (Identity Laws)
(p  p)  (r  q) (Associate+Commutative)
T  (r  q) (Inverse Laws)
T (Domination Laws)
Rules of Inference (Cont.)
• Rules of inference provide the justification of the steps used in a proof.
• One important rule is called modus ponens or the law of detachment. It is based on the
tautology (p(p→q)) → q. We write it in the following way:
p
p→q
____
Q

• P: Lydia wins a ten-million-dollar lottery


• p → q: if Lydia wins a ten-million-dollar lottery, then Kay will quit her
job
•  q Therefore Kay will quit her job
Rules of Inference (Cont.)
p
_____
pq Addition

pq
____
p Simplification
p
q
_____
 pq Conjunction
Rules of Inference (Cont.)
¬q
p→q
_____
 ¬p Modus tollens [(p→q)  q] → p is a tautology

p→q
q→r
_____
p→r Hypothetical syllogism (p→q) (q →r) → (p→r) is a tautology
Rules of Inference (Cont.)
pq
¬p
_____
q Disjunctive syllogism [(p  q) p] →q is a tautology

• p  q: Bart’s wallet is in his back pocket, or it is on his desk


• p: Bart’s wallet is not in his back pocket
• q Therefore Bart’s wallet is on his desk

p∨q
¬p ∨ r
_____
∴q∨r Resolution
Rules of Inference (Cont.)
• Show that the following implication is a tautology
• [(pq)  (p  r)] → [(q  r)]
• You could use the truth table Or

[(qp)  (p  r)] → [(q  r)] Commutative law


[((q)p)  (p  r)] → [(q  r)] Double negative
[(q → p)  (p  r)] → [(q  r)] a→ b ≡ (a)b
[(q → p)  (p→r)] → [(q  r)] a→ b ≡ (a)b
[(q → r)] → [(q  r)] Law of the Syllogism: (p→q) (q →r) → (p→r)
[(q  r)]→ [(q  r)] a→ b ≡ (a)b
a→ a ≡ T
Arguments
• Just like a rule of inference, an argument consists of one or more
hypotheses and a conclusion.

• We say that an argument is valid, if whenever all its hypotheses


are true, its conclusion is also true.

• However, if any hypothesis is false, even a valid argument can lead


to an incorrect conclusion.
Arguments (Cont.)
• Example: State which rule of inference is the basis of the following argument: “It
is below freezing and raining now. Therefore, it is below freezing now.”
• Let p be the proposition “It is below freezing now,” and let q be the
proposition “It is raining now.” This argument is of the form
• p∧q
• ∴p
• This argument uses the simplification rule.
Arguments (Cont.)
• Example: State which rule of inference is used in the argument: If
it rains today, then we will not have a barbecue today. If we do not
have a barbecue today, then we will have a barbecue tomorrow.
Therefore, if it rains today, then we will have a barbecue tomorrow.
Solution: Let p be the proposition “It is raining today,” let q be the
proposition “We will not have a barbecue today,” and let r be the
proposition “We will have a barbecue tomorrow.” Then
this argument is of the form
p→q
q→r
∴p→r
Hence, this argument is a hypothetical syllogism.
Arguments (Cont.)
• Example: Show that the premises “It is not sunny this afternoon and it is colder than yesterday,” “We
will go swimming only if it is sunny,” “If we do not go swimming, then we will take a canoe trip,” and “If
we take a canoe trip, then we will be home by sunset” lead to the conclusion “We will be home by
sunset.”
• Solution: Let p be the proposition “It is sunny this afternoon,” q the proposition “It is colder than
yesterday,” r the proposition “We will go swimming,” s the proposition “We will take a canoe trip,” and t
the proposition “We will be home by sunset.” Then the premises become ¬p ∧ q, r → p,¬r → s, and s → t .
The conclusion is simply t . We need to give a valid argument with premises ¬p ∧ q, r → p, ¬r → s, and s → t
and conclusion t .
• We construct an argument to show that our premises lead to the desired conclusion as follows.
1. ¬p ∧ q Premise
2. ¬p Simplification using (1)
3. r → p Premise
4. ¬r Modus tollens using (2) and (3)
5. ¬r → s Premise
6. s Modus ponens using (4) and (5)
7. s → t Premise
8. t Modus ponens using (6) and (7)
Arguments (Cont.)
• Example: Show that the premises “If you send me an e-mail message, then I will finish writing
the program,” “If you do not send me an e-mail message, then I will go to sleep early,” and “If I
go to sleep early, then I will wake up feeling refreshed” lead to the conclusion “If I do not
finish writing the program, then I will wake up feeling refreshed.”
• Solution: Let p be the proposition “You send me an e-mail message,” q the proposition “I will
finish writing the program,” r the proposition “I will go to sleep early,” and s the proposition “I
willwake up feeling refreshed.” Then the premises are p → q,¬p → r, and r → s. The desired
conclusion is ¬q → s.We need to give a valid argument with premises p → q, ¬p → r, and r → s
and conclusion ¬q → s.
• Step Reason
1. p → q Premise
2. ¬q →¬p Contrapositive of (1)
3. ¬p → r Premise
4. ¬q → r Hypothetical syllogism using (2) and (3)
5. r → s Premise
6. ¬q → s Hypothetical syllogism using (4) and (5)
Arguments (Cont.)
Example:

• “If 101 is divisible by 3, then 1012 is divisible by 9. 101 is divisible


by 3. Consequently, 1012 is divisible by 9.”

• Although the argument is valid, its conclusion is incorrect,


because one of the hypotheses is false (“101 is divisible by 3.”).

• If in the above argument we replace 101 with 102, we could


correctly conclude that 1022 is divisible by 9.
Arguments (Cont.)
• Show that the following argument is valid
• (p→r) /\ (r→ s) /\ (t \/ ¬s) /\ (¬t \/ u) /\ (¬u) → (¬p)
(p→ s) /\ (t \/ ¬s) /\ (¬t \/ u) /\ (¬u) → (¬p) Law of the Syllogism: (p→q) (q →r) → (p→r)
(p→ s) /\ (¬s \/ t ) /\ (¬t \/ u) /\ (¬u) → (¬p) Commutative law
(p→ s) /\ (s→ t ) /\ (t→ u) /\ (¬u) → (¬p) a→ b ≡ (a)b
(p→ t ) /\ (t→ u) /\ (¬u) → (¬p) Law of the Syllogism
(p→ u) /\ (¬u) → (¬p) Law of the Syllogism
(p→ u) /\ (¬u) → (¬p) Modus Tolens [(p→q)  q] → p is a tautology,
Arguments (Cont.)
Example:
• p1: Jonathan does not have his driver’s license, or his new car is out of gas.
• P2: Jonathan has his driver’s license, or he does not like to drive his new car.
• P3: Jonathan’s new car is not out of gas, or he does not like to drive his new car.
• q: Therefore, Jonathan does not like to drive his new car.

• p1 /\ p2 /\ p3 → q
• a: Jonathan has his driver’s license.
• b: Jonathan’s new car is out of gas
• c: Jonathan likes to drive his new car

• p1: (¬a) \/ b
• p2: a \/ (¬c)
• p3: (¬b) \/ (¬c)
• q: (¬c)

• ((¬a) \/ b) /\ (a \/ (¬c)) /\ ((¬b) \/ (¬c)) → (¬c)


Arguments (Cont.)
• You can use the Truth table

(a→ b) /\ (a \/ (¬c)) /\ ((¬b) \/ (¬c)) → (¬c) a→ b ≡ (a)b


(a→ b) /\ ((¬c)\/ a ) /\ ((¬b) \/ (¬c)) → (¬c) Commutative law
(a→ b) /\ (c→ a ) /\ ((¬b) \/ (¬c)) → (¬c) a→ b ≡ (a)b
(a→ b) /\ (c→ a ) /\ (b→ (¬c)) → (¬c) a→ b ≡ (a)b
(a→ b) /\ (b→ (¬c)) /\ (c→ a )) → (¬c) Commutative law
(a→ (¬c)) /\ (c→ a )) → (¬c) Law of the Syllogism
(c→ a ) /\ (a→ (¬c)) → (¬c) Commutative law
(c→ (¬c)) → (¬c) Law of the Syllogism
(¬c) \/ (¬c) → (¬c) a→ b ≡ (a)b
(¬c) → (¬c) (Idempontent Laws)
a→ a ≡ T
Fallacies
• Several common fallacies arise in incorrect arguments.
• Example: Is the following argument valid?
If you do every problem in this book, then you will learn discrete mathematics. You learned discrete
mathematics.
Therefore, you did every problem in this book.

Solution: Let p be the proposition “You did every problem in this book.” Let q be the proposition
“You learned discrete mathematics.” Then this argument is of the form: if p → q and q, then p.

This is an example of an incorrect argument using the fallacy of affirming the conclusion.

Indeed, it is possible for you to learn discrete mathematics in some way other than by doing
every problem in this book. (You may learn discrete mathematics by reading, listening to
lectures, doing some, but not all, the problems in this book, and so on.)
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Predicates
• Predicates: Statements involving variables, such as:
• “x > 3,” “x = y + 3,” “x + y = z,”
• “computer x is under attack by an intruder,”
• “computer x is functioning properly,”

• Example: Let P(x) denote the statement “x > 3.” What are the truth values of P(4) and P(2)?
• We obtain the statement P(4) by setting x = 4 in the statement “x > 3.” Hence, P(4), which is the statement “4 >
3,” is true. However, P(2), which is the statement “2 > 3,” is false.
• Example: Let Q(x, y) denote the statement “x = y + 3.” What are the truth values of the propositions Q(1, 2)
and Q(3, 0)?
• To obtain Q(1, 2), set x = 1 and y = 2 in the statement Q(x, y). Hence, Q(1, 2) is the
statement “1 = 2 + 3,” which
is false. The statement Q(3, 0) is the proposition “3 = 0 + 3,” which is true.
Predicate logic
• Predicate logic is a formal system of logic that extends propositional
logic by introducing quantifiers (∀ and ∃) and predicates. It allows us to
reason about individuals and their properties, as well as relationships
between individuals.
• Components of Predicate Logic:
• Constants: Symbols representing specific individuals or objects.
• Variables: Symbols representing arbitrary individuals or objects.
• Predicates: Symbols representing properties or relations of individuals.
• Quantifiers: Symbols used to express the quantity of individuals that satisfy a
predicate:
• Universal quantifier (∀): "for all"
• Existential quantifier (∃): "there exists"
• Logical operators: AND (∧), OR (∨), NOT (¬), IMPLIES (→), and IF AND ONLY IF
( ).
Predicate logic (Cont.)
• Predicate P(x): "x is a dog.“
• Predicate logic: "For all x, if x is a dog, then x has four legs." (implication)

• Let P(x):=x can fly. Let Q(x):=x are blue. Let the domain of x be all species of
animals.
• P(penguins)∨P(geese) is true.
• P(blue jays)∧Q(blue jays) is true.
• P(penguins)→Q(tigers) is true.
Predicate logic (Cont.)
• Examples of Predicate Logic Formulas:
• ∀x P(x): "For all x, P(x) is true."
• ∃x Q(x): "There exists an x such that Q(x) is true."
• ∀x∀y R(x, y): "For all x and y, R(x, y) is true."
• ∃x∃y S(x, y): "There exists an x and a y such that S(x, y) is true."
Quantifiers
• Types of Quantifiers:
1.Universal Quantifier (∀):
1. Meaning: "For all" or "for every."
2. Usage: Indicates that a statement is true for every element in each set.
3. Example: ∀x ∈ ℝ, x² ≥ 0 (For all real numbers x, x squared is greater than or equal to
0.)
2.Existential Quantifier (∃):
1. Meaning: "There exists" or "there is at least one."
2. Usage: Indicates that there is at least one element in each set that satisfies the
statement.
3. Example: ∃x ∈ ℤ, x is even (There exists an integer x that is even.)
Quantifiers (Cont.)
Example:
• Consider these simple open statements:
• p(x): x > 0
• q(x): x2 – 2x – 3 = 0
• r(x): x < 0
• s(x): x2 > 0

• Decide whether each of these assertions is true or not:


1. x [p(x)  q(x) ] // x=3
2. x[p(x) → s(x)] true
3. x[q(x) → p(x)] false //x =-1
4. x[p(x)  r(x) → s(x)] true
5. x [r(x) → q(x)] // not true x=-1
Quantifiers (Cont.)
Example:
A[1], A[2],.. A[20] is the universe
1) Every entry in the array is nonnegative
x[A(x) >=0]

2) There exist two consecutive entries in A where the second entry is twice the first:
x (A(x+1)=2A[x] )

3) The entries in the array are distinct


xy [(x#y) → (A[x]#A[y])]
Quantifiers (Cont.)
• Scope of Quantifiers:
• The scope of a quantifier is the part of the formula where the quantified
variable is bound. It determines the range of values over which the
quantifier operates.
• Examples:
• ∀x ∈ ℝ, ∃y ∈ ℝ, x + y = 0: This statement means that for every real number
x, there exists a real number y such that their sum is 0.
• ∃x ∈ ℤ, ∀y ∈ ℤ, x + y = y: This statement means that there exists an integer
x such that for every integer y, their sum is equal to y.
Quantifiers (Cont.)
• Combining Quantifiers:
• Quantifiers can be combined to express more complex statements:
• ∀x ∈ A, ∀y ∈ B, P(x, y): This means that for every x in A and every y in B, the predicate
P(x, y) is true.
• ∃x ∈ A, ∃y ∈ B, P(x, y): This means that there exists an x in A and there exists a y in B
such that the predicate P(x, y) is true.
• ∀x ∈ A, ∃y ∈ B, P(x, y): This means that for every x in A, there exists a y in B such that
the predicate P(x, y) is true.
Quantifiers (Cont.)
• Let P(x):=x<5.
• If U is the positive integers, what is the truth value of ∀xP(x)? What is
the truth value of ∃xP(x)?
• ∀xP(x) is false. ∃xP(x) is true.
• If U is the negative integers, what is the truth value of ∀xP(x)? What is
the truth value of ∃xP(x)?
• ∀xP(x) is true. ∃xP(x) is true.
• If U is the numbers 6, 7, and 8, what is the truth value of ∀xP(x)?
What is the truth value of ∃xP(x)?
• ∀xP(x) is false. ∃xP(x) is false.
Precedence of quantifiers
• Quantifiers have a higher precedence than all other logical
connectives.
• ∀x P(x)∨ Q(x) ≡ (∀x P(x))∨ Q(x)
• ∃x P(x)∨ Q(x) ≡ (∃x P(x))∨ Q(x)
• ∃x P(x) → Q(x) ≡ (∃x P(x)) → Q(x)
• If we want a quantifier to apply to multiple predicates, we must use
parentheses. ∀xP(x)∧Q(x) is not the same as ∀x(P(x)∧Q(x)).
Precedence of quantifiers
• Let P(x,y):=x+y=0 and the domain of x and y be the real numbers. The
truth value of the following expressions are:
• ∀x ∀y P(x,y) False
• ∀y ∀x P(x,y) False
• ∃x ∀y P(x,y) False
• ∀y ∃x P(x,y) True
• ∃x ∃y P(x,y) True
Quantifications of Two Variables
Negating Quantifiers (Cont.)
• Negating a universal quantifier (∀): "For all" becomes "There
exists" or "There is at least one.“
• Negating an existential quantifier (∃): "There exists" or "There is at
least one" becomes "For all."
Negating Quantifiers (Cont.)
• Negating a universally quantified statement:
• Original statement: ∀x ∈ A, P(x)
• Negation: ∃x ∈ A, ¬P(x)
• Explanation: The original statement says that for all x in A, P(x) is true. The
negation says that there exists at least one x in A such that P(x) is false.

• Negating an existentially quantified statement:


• Original statement: ∃x ∈ A, P(x)
• Negation: ∀x ∈ A, ¬P(x)
• Explanation: The original statement says that there exists at least one x in
A such that P(x) is true. The negation says that for all x in A, P(x) is false.
Negating Quantifiers (Cont.)
• Negating a doubly quantified statement:
• Original statement: ∀x ∈ A, ∃y ∈ B, P(x, y)
• Negation: ∃x ∈ A, ∀y ∈ B, ¬P(x, y)

• Negating a nested quantified statement:


• Original statement: ∀x ∈ A, (∃y ∈ B, P(x, y) ∧ ∀z ∈ C)
• Negation: ∃x ∈ A, (∀y ∈ B, ¬P(x, y) ∨ ∃z ∈ C)
Negating Quantifiers (Cont.)
• Example:
• Let A = {1, 2, 3} and P(x) be the statement "x is even".
• ∀x ∈ A, P(x): This statement is false because 1 and 3 are not even.
• ∃x ∈ A, P(x): This statement is true because 2 is even.
• ¬ ∀x ∈ A, P(x) ≡ ∃x ∈ A, ¬P(x) is true because 1 and 3 are not even.
• ¬ ∃x ∈ A, P(x) ≡ ∀x ∈ A, ¬P(x) is false because 2 is even.
Negating Quantifiers (Cont.)
• Example: What are the negations of the statement ∀x(x2 > x)?
• Solution: The negation of ∀x(x2 > x) is the statement ¬∀x(x2 > x),
which is equivalent to ∃x¬(x2 > x). This can be rewritten as ∃x(x2 ≤ x).

• Example: What are the negations of the statement ∃x(x2 = 2)?


• Solution: The negation of ∃x(x2 = 2) is the statement ¬∃x(x2 = 2),
which is equivalent to ∀x¬(x2 = 2). This can be rewritten as ∀x(x2 ≠ 2).
The truth values of these statements depend on the domain.
Negating Quantifiers (Cont.)
Find negations of statements including quantifiers.
• (x p(x))
• (All books are interesting) ≡ There exists at least one book that is not interesting

• ( x p(x)) ≡ x [p(x)]


• (Some people like mathematics) ≡ Everybody dislikes mathematics

• P(x) : “student x is a computer science major”


• Q(x): “student x likes mathematics”
• x [P(x) → Q(x)] // Any computer science major student likes mathematics.
• Not all computer science students like mathematics.
•  x [P(x) → Q(x)]
•  x  [ P(x)  Q(x)] // (p→q) ≡ (( p)  q)
•  x [ P(x)   Q(x)]
Negating Quantifiers (Cont.)

Statement When True When False


x p(x) There is an x for which p(x) is p(x) is false for every x
true
x p(x) p(x) is true for every x There is an x for which p(x) is
false
x [p(x)] For at least one value a in the For all values a in the
universe for x, p(a) is false. universe for x, p(a) is true.
x [p(x)] For all values a in the For at least one value a in the
universe for x, p(a) is false. universe for x, p(a) is true.
Example
• The contrapositive of x [p(x) → q(x)] to be x [q(x)→ p(x)]
• The converse of x [p(x) → q(x)] to be x [q(x)→ p(x)]
• The inverse of x [p(x) → q(x)] to be x[q(x)→ p(x)]

Example:
• S(x) : x is a square
• E(x): x is equilateral
• x [s(x) → e(x)] is a true statement
(a) x [s(x) → e(x)] x [e(x) →  s(x)] contrapositive
(b) x [e(x) → s(x)] the converse is false
(c) x [ s(x) → e(x)] the inverse is false
Example
• Let L(x, y) be the proposition “x likes y”. How can we express the following statements?
• Someone likes everybody. x y L(x, y)
• Everybody likes everybody. x y L(x, y)
• Somebody likes somebody. x  y L(x, y)
• Everybody likes somebody. x  y L(x, y)
Quantifiers
So now, consider each of these implications:
1) x [p(x)  q(x)] → [x p(x)  x q(x)]
[x p(x)][x q(x) ] ( →) x[ p(x)q(x) ]
p(x) = “x >10”
q(x) = “x=<10”

2) x [p(x)  q(x)] ≡ [x p(x)  x q(x)]

3) x [p(x)  q(x)] ≡ [x p(x)  x q(x)]

4) [x p(x)  x q(x)] → x [p(x)  q(x)]


x[ p(x)q(x) ] (not →) [x p(x)]  [x q(x) ]
p(x) = “x >10”
q(x) = “x=<10”

x [  p(x)] ≡ [x p(x)]


Quantifiers (Cont.)
What is the negation of " x y p(x, y)?
[x y p(x, y)] ≡ x [(y p(x, y))]
≡ x y p(x, y)

•  [All students in Discrete Structures know some programming language]


≡ There is a student in Discrete Structures who does not know any programming language.

• Here p(x, y) stands for “student x knows programming language y”.

• if p(x,y) is “x+y=17”
• x y p(x, y) is true y=17-x ( for every integer x, there exists y such that x+y=17)
• x y p(x, y) is false (There exists an integer y so that for all integers x, x+y =17)
The Rule of Universal Specification:
If an open statement p (x) is proved to be true for all x , i.e. x p(x), then it is true for any particular x=a,
p(a).

The Rule of Universal Generalization:


To prove that an open statement p (x) is true for all x, i.e. x p(x), we can prove that it is true for any
arbitrary chosen x = c.

The Rule of Existential Specification:


From x p(x) we can infer that there is an instance a with p(a) be true.

The Rule of Existantial Generalization:


From an instance a in the universe with p(a) be true we can infer that x p(x).
Example
We can use this to formally show that IF
x [p(x) → q(x)] AND x [q(x) → r(x)] THEN x [p(x) → r(x)].

1) x [p(x) → q(x)] Premise


2) p(c) → q(c) Step 1 & Rule of Universal Specification
3) x [q(x) → r(x)] Premise
4) q(c) → r(c) Step 3 & Rule of Universal Specification
5) p(c) → r(c) Steps 2 & 4 and Law of Syllogism
6) x [p(x) → r(x)] Step 5 and the Rule of Universal Generalization
Example
x p(x) AND x [p(x)  q(x) → r(x)]
And use those to prove:
x [r(x) → q(x)].

1) x p(x) Premise
2) p(c) Step 1 & Rule of Universal Specification
3) x [p(x)  q(x) → r(x)] Premise
4) p(c)  q(c) → r(c) Step 3 & Rule of Universal Specification
5) T  q(c) → r(c) Substitution from Step 2
6) q(c) → r(c) Identity Law
7) r(c) → q(c) Contrapositive
8) x [r(x) → q(x)] Step 7 & Rule of Universal Generalization
Example
Let p(n), q(n), and r(n) be the following open statements:
p(n): n is an even number.
q(n): n is an odd number.
r(n): n2+n is even.
Since all integers are either even or odd, prove that (p(n)  q(n)) → r(n).

• Proof #1: direct proof by method of exhaustion using cases.


Logically, we can show this is equivalent to: (p(n) → r(n))  (q(n) → r(n))
n is even: Then there is an integer r such that n=2r, then we have
n2+n = (2r)2 + 2r
= 4r2 + 2r
= 2(2r2 + r),
since this value is divisible by 2, it is even.
Example (Cont.)
n is odd: Then there is an integer r such that n=2r+1, then we have

n2+n = (2r+1)2 + (2r+1)


= 4r2 + 4r + 1 + 2r + 1
= 4r2 + 6r + 2
= 2(2r2 + 3r + 1),

and this value is also divisible by 2, thus it is even.


Example (Cont.)
• Proof #2: Contradiction
For contradiction’s sake, assume that n2+n is odd. We have the following: n2+n = n(n+1)
We know that for the product of two integers to be odd, both of them have to be.
However, it is impossible for both n and n+1 to be odd.
Thus, the way contradiction works is that you assume that the result is false. Then use algebra and other
rules to show that the premise must be false as well, or that something impossible occurs if the incorrect
result is assumed.

The reason is that you came to an incorrect conclusion. You must have arrived at it by making an
incorrect step. The ONLY possible incorrect step that could have been taken was the assumption made in
the beginning. Hence, that is wrong, which implies the truth of what you are trying to prove.
Distributing Quantifiers into Compound
Expressions
• Rules for Distribution:
• ∀x (P(x) ∧ Q(x)) ≡ (∀x P(x)) ∧ (∀x Q(x))
• ∃x (P(x) ∨ Q(x)) ≡ (∃x P(x)) ∨ (∃x Q(x))

• ∃x (P(x) ∧ Q(x)) ≠ (∃x P(x)) ∧ (∃x Q(x))


• ∀x (P(x) ∨ Q(x)) ≠ (∀x P(x)) ∨ (∀x Q(x))
Logical Equivalences Involving Quantifiers
• Example: Show that ∀x(P(x) ∧ Q(x)) and ∀xP(x) ∧ ∀xQ(x) are logically equivalent
• We can show that ∀x(P(x) ∧ Q(x)) and ∀xP(x) ∧ ∀xQ(x) are logically equivalent by doing two
things. First, we show that if ∀x(P(x) ∧ Q(x)) is true, then ∀xP(x) ∧ ∀xQ(x) is true. Second, we
show that if ∀xP(x) ∧ ∀xQ(x) is true, then ∀x(P(x) ∧ Q(x)) is true.
• So, suppose that ∀x(P(x) ∧ Q(x)) is true. This means that if a is in the domain, then P(a) ∧ Q(a)
is true. Hence, P(a) is true and Q(a) is true. Because P(a) is true and Q(a) is true for every
element in the domain, we can conclude that ∀xP(x) and ∀xQ(x) are both true. This means that
∀xP(x) ∧ ∀xQ(x) is true.
• Next, suppose that ∀xP(x) ∧ ∀xQ(x) is true. It follows that ∀xP(x) is true and ∀xQ(x) is true.
Hence, if a is in the domain, then P(a) is true and Q(a) is true [because P(x) and Q(x) are both
true for all elements in the domain, there is no conflict using the same value of a here]. It
follows that for all a, P(a) ∧ Q(a) is true. It follows that ∀x(P(x) ∧ Q(x)) is true.
• We can now conclude that ∀x(P(x) ∧ Q(x)) ≡ ∀xP(x) ∧ ∀xQ(x).
Rules of Inference for Quantified Statements
Example
• Show that the premises “Everyone in this discrete mathematics class
has taken a course in computer science” and “Marla is a student in this
class” imply the conclusion “Marla has taken a course in computer
science.”

• Solution: Let D(x) denote “x is in this discrete mathematics class,” and let C(x) denote “x has taken a course in
computer science.” Then the premises are ∀x(D(x) → C(x)) and D(Marla). The conclusion is C(Marla).

The following steps can be used to establish the conclusion from the premises.
Step Reason
1. ∀x(D(x) → C(x)) Premise
2. D(Marla)→C(Marla) Universal instantiation from (1)
3. D(Marla) Premise
4. C(Marla) Modus ponens from (2) and (3)
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Proof Methods
• Proof is a fundamental concept that involves demonstrating the
truth or falsity of a mathematical statement or proposition.
• Several common proof methods:
• Direct Proof
• Indirect Proof
• Proof by Contrapositive
• Proof by Contradiction
• Proof by Exhaustion
• Proof by Case Analysis
Direct proof
• A Direct proof of a conditional statement p → q is constructed
when the first step is the assumption that p is true; subsequent
steps are constructed using rules of inference, with the final step
showing that q must also be true. It's a straightforward approach
that involves:
1.Starting with the premises: Begin with the given premises or
assumptions.
2.Applying logical rules and mathematical operations: Use logical
connectives (AND, OR, NOT, IMPLIES, IF AND ONLY IF) and mathematical
operations to derive intermediate steps and eventually the conclusion.
3.Concluding the statement: Once the conclusion is reached, state that
the original statement is proven.
Direct proof (Cont.)
• Example 1: Prove that if n is an even integer, then n^2 is also
even.
• Proof:
1.Assume: n is an even integer.
2.Definition of even: n = 2k for some integer k.
3.Square n: n^2 = (2k)^2 = 4k^2 = 2(2k^2)
4.Conclusion: Since n^2 can be expressed as 2 times another integer
(2k^2), n^2 is also even.
Direct proof (Cont.)
• Example 2: Prove that if n is an odd integer, then n^2 is also
odd.
• Proof:
1.Assume: n is an odd integer.
2.Definition of even: n = 2k+1 for some integer k.
3.Square n: n^2 = (2k+1)^2 = 4k^2 +4k+1= 2(2k^2 +2k)+1 =2i+1
4.Conclusion: Since n^2 can be expressed as 2 times another integer
(2k^2) plus one, n^2 is also odd.
Direct proof (Cont.)
• Example 3: Prove that if x is a real number, then x^2 ≥ 0.
• Proof:
1.Consider cases:
1. If x = 0, then x^2 = 0, which is non-negative.
2. If x > 0, then x^2 = x * x, and since the product of two positive numbers is positive,
x^2 > 0.
3. If x < 0, then x^2 = (-x) * (-x), and since the product of two negative numbers is
positive, x^2 > 0.
2.Conclusion: In all cases, x^2 is non-negative, so x^2 ≥ 0.
Direct proof (Cont.)
• Example 4: Give a direct proof that if m and n are both perfect squares, then nm is also a perfect square. (An
integer a is a perfect square if there is an integer b such that a = b2.)
• To produce a direct proof of this theorem, we assume that the hypothesis of this conditional statement is true,
namely, we assume that m and n are both perfect squares. By the definition of a perfect square, it follows that
there are integers s and t such that m = s2 and n = t2.
• The goal of the proof is to show that mn must also be a perfect square when m and n are; looking ahead we
see how we can show this by substituting s2 for m and t2 for n into mn. This tells us that mn = s2t2. Hence, mn
= s2t2 = (ss)(t t) = (st)(st) = (st)2, using commutativity and associativity of multiplication.
• By the definition of perfect square, it follows that mn is also a perfect square, because it is the square of st,
which is an integer.
• We have proved that if m and n are both perfect squares, then mn is also a perfect square.
Direct proof (Cont.)
• Example 5: Theorem
A  AB ≡ x [xA → xA B].

• Proof.
Assume x is arbitrary element from set A, xA, (1)
But x A → x A  (any other proposition) since p →p  q is a tautology.
So, (1) implies, that x A  x B, (2)
By the definition of set union, (2) is equivalent to xA B, (3)
We showed that arbitrary element x from set A belongs to the union A B, that is A  AB.
Direct proof (Cont.)
• Example 6: Theorem: Let A and B be any two sets. Prove that AB  A.

Proof
We need to prove that for any x if x AB, then xA, i.e. x [x AB → x A].
So, take arbitrary x  AB (1)
By the definition of the set intersection (1) implies that x  A  xB, (2)
(2) implies that x  A, (3) by p q → p, i. e. p q → p is a tautology.
We showed that any element from AB belongs to A. By the definition of subset relation, it means that AB
 A.
Direct proof (Cont.)
Example 7: Theorem: Prove that the sum of two odd integers is an even integer..
Proof: Let a, b denote two (arbitrary) odd integers. We want to prove that a + b is even.
By the definition of odd integers, there exist integers c and d such that
a=2c+1 (1)
b=2d+1 (2)

Adding equations (1) and (2) yields


a + b = (2 c + 1) + (2 d + 1)
= 2 c + 2 d + 2, commutative and associative laws
= 2 (c + d + 1), distributive law
Since (c + d + 1) is an integer, because c and d are and because of the closure property under add, the above
equation for a + b proves that it is even, by the definition of even integers.
Direct proof (Cont.)
• Example 8: Theorem: Prove that if a | b, and b | c, then a | c, where a, b, and c are integers.
Proof: By the definition of divisibility, a | b implies that there exists integer a’ such that
b = a a’ (1)
Similarly, b | c implies that there exists integer b’ such that
c = b b’ (2)
Substituting b of (1) into (2) yields
c = (a a’) b’
= a (a’ b’), associative law (3)
Since a’ and b’ are integers, a’ b’ is also an integer by the closure property of multiplication. Also, a  0 because
it is a divisor of b. Thus, a  0 and Equation (3) together imply a | c, by the definition of divisibility.
Direct proof (Cont.)
• Example 9: AB ≡ A−B= 

AB ≡ x [xA → xB] by subset definition


≡ x [xA  xB] by equivalence p →q ≡ p q
≡ x  [xA  x B] by DeMorgan’s law
≡ x  [x A−B] by definition of A−B
≡ x [x A−B] by negation of 
≡ A−B =  by definition of empty set
Direct proof (Cont.)
• Example 10: show that A −(A−B) =A B
• Note: A −(A−B)  B!
Proof
A−B = {x| xA  xB }= {x| xA B } = A B
Then: A −(A−B) = A −(AB) = A [(AB)]
= A [A(B)] = A (AB)
= (A A)(A  B) =  (A  B) = A B
Proof by Contrapositive
• Proof by contrapositive is a method of indirect proof where,
instead of proving the original statement "p → q," you prove its
contrapositive "¬q → ¬p." The contrapositive is logically equivalent
to the original statement.
Proof by Contrapositive (Cont.)
• if n is an integer such that 3n+2 is odd, then n is odd.

• Proof: Assume n is not odd. Then, we must prove 3n+2 is not odd.
Since n is not odd, it is even and we have n=2k for some integer k.
Then, 3n+2=3(2k)+2=6k+2=2(3k+1). Letting k′=3k+1 we
have 3n+2=2k′. Hence, it is even.
Proof by Contrapositive (Cont.)
• Prove that if n = ab, where a and b are positive integers, then 𝑎 ≤ 𝑛 or 𝑏 ≤ 𝑛 .

• The first step in a proof by contraposition is to assume that the conclusion of the conditional statement “If n =
ab, where a and b are positive integers, then 𝑎 ≤ 𝑛 or 𝑏 ≤ 𝑛” is false.
• That is, we assume that the statement (𝑎 ≤ 𝑛) ∨ (𝑏 ≤ 𝑛) is false. Using the meaning of disjunction together
with De Morgan’s law, we see that this implies a > 𝑛 and b > 𝑛. We can multiply these inequalities together
(using the fact that if 0 < s < t and 0 < u < v, then su < tv) to obtain ab > 𝑛 · 𝑛 = n. This shows that ab ≠ n,
which contradicts the statement n = ab.
• Because the negation of the conclusion of the conditional statement implies that the hypothesis is false, the
original conditional statement is true.
Proof by Contrapositive (Cont.)
Example: Theorem: If A B, then AB  AB.
Proof:
A B → AB  AB
p→ q

AB = AB → A = B
q→p
We can prove the equivalent contrapositive proposition
Proof. To prove AB = AB → A = B assume AB = AB and prove 1) A B and 2) B  A
1) xA → x AB → x AB → xB
2) xB → x A  B → x A  B → xA
Proof by Contrapositive (Cont.)
Example: If A  B = , then B  A.
Proof:
The contrapositive of this statement is the following:
if ( B  A) then (A  B = ).
If we prove this statement, we have also proven the original, since a statement and its contrapositive are
equivalent.
So, we will assume that ( B  A). Under this assumption we must show that A  B  .
If we have that ( B  A), then there exists an element x such that x is IN B but NOT IN the complement of
A. Symbolically we have:
x | xB  xA
If we have an element xA, by definition of complement, we must have that xA. So we have
x | xB  xA.
But, this means that x  AB!!! From that we can conclude that AB  , as desired.
Proof by contradiction
• Proof by contradiction is a powerful method of indirect proof
where you assume the negation of the statement you want to
prove and then show that this assumption leads to a logical
contradiction. This contradiction implies that the original
statement must be true.
• By contrapositive, if ¬p→F holds then T→p holds.
Therefore, p must be true.
Proof by contradiction (Cont.)
• Example: There is no largest integer.
• Proof: Assume that there does exist some largest integer. Call such an
integer n. But, n+1 is also an integer and n+1 is strictly larger than n.
Therefore, our assumption that a largest integer exists is false. That is,
there is no largest integer is true.
Proof by contradiction (Cont.)
• Prove that 2 is irrational by giving a proof by contradiction.
• Solution: Let p be the proposition “ 2 is irrational.” To start a proof by contradiction, we suppose that ¬p is true.
Note that ¬p is the statement “It is not the case that 2 is irrational,” which says that 2 is rational. We will
shointeger,ng that ¬p is true leads to a contradiction.
• If 2 is rational, there exist integers a and b with 2 = a/b, where b ≠ 0 and a and b have no common factors (so that
the fraction a/b is in lowest terms.) (Here, we are using the fact that every rational number can be written in lowest
terms.) Because 2 = a/b, when both sides of this equation are squared, it follows that 2 =a2/b2 .
• Hence, 2b2 = a2. By the definition of an even integer it follows that a2 is even. We next use the fact that if a2 is even,
a must also be even. Furthermore, because a is even, by the definition of an even integer, a = 2c for some integer c.
Thus, 2b2 = 4c2.
• Dividing both sides of this equation by 2 gives b2 = 2c2 By the definition of even, this means that b2 is even. Again
using the fact that if the square of an integer is even, then the integer itself must be even, we conclude that b must be
even as well.
• We have now shown that the assumption of ¬p leads to the equation 2 = a/b, where a and b have no common
factors, but both a and b are even, that is, 2 divides both a and b.
• Because our assumption of ¬p leads to the contradiction that 2 divides both a and b and 2 does not divide both a
and b, ¬p must be false. That is, the statement p, “ 2 is irrational,” is true. We have proved that 2 is irrational.
Proof by contradiction (Cont.)
• Give a proof by contradiction of the theorem “If 3n + 2 is odd, then n is odd.”
• Solution: Let p be “3n + 2 is odd” and q be “n is odd.” To construct a proof by contradiction, assume that both
p and ¬q are true. That is, assume that 3n + 2 is odd and that n is not odd.
• Because n is not odd, we know that it is even. Because n is even, there is an integer k such that n = 2k. This
implies that 3n + 2 = 3(2k) + 2 = 6k + 2 = 2(3k + 1). Because 3n + 2 is 2t , where t = 3k + 1, 3n + 2 is even.
• Note that the statement “3n + 2 is even” is equivalent to the statement ¬p, because an integer is even if and
only if it is not odd.
• Because both p and ¬p are true, we have a contradiction. This completes the proof by contradiction, proving
that if 3n + 2 is odd, then n is odd.
Proof by contradiction (Cont.)
Example: Theorem: For any two sets A and B (A−B)(AB) = 
Proof by contradiction. Assume
(A−B)(AB)  , (1)
i.e., that there exists at least one element in the intersection.
≡ x [x (A−B)(AB)] definition of empty set
≡ x [x(A−B) x(AB)] definition of 
x [(xA  x B)( xA  xB)] definition of set difference and 
x [xA  (xB xB)] commutative, associative law
≡ x [xA  x ] since BB= 
≡ x [xA] definition of 
≡ x [x] domination law
≡F since x [x ]
We come to the contradiction that proves the original proposition.
Proof by contradiction (Cont.)
Example: If A  B = , then B  A.
So we first assume that A  B = . Next we will also assume that B  A is false.

If we have ( B  A), then we must have an element x that is in B that is NOT in the complement of A.
Symbolically we have:
x | xB  xA
this is equivalent to...
x | xB  xA.
But this is impossible – it contradicts our assumption A  B = . Thus, we must have made a mistake in our
proof. Every step we took was logical EXCEPT for our assumption. Thus, this is what must be wrong...we can
conclude that the opposite of it, is indeed true. This proves that
If A  B = , then B  A.
Mistakes in Proofs
• What is wrong with this famous supposed “proof” that 1 = 2?
• “Proof:“ We use these steps, where a and b are two equal positive integers.

• Step Reason
1. a = b Given
2. a2 = ab Multiply both sides of (1) by a
3. a2 − b2 = ab − b2 Subtract b2 from both sides of (2)
4. (a − b)(a + b) = b(a − b) Factor both sides of (3)
5. a + b = b Divide both sides of (4) by a − b
6. 2b = b Replace a by b in (5) because a = b and simplify
7. 2 = 1 Divide both sides of (6) by b

• Solution: Every step is valid except for one, step 5 where we divided both sides by a − b. The error is that a −
b equals zero; division of both sides of an equation by the same quantity is valid if this quantity is not zero.
Exhaustive Proof and Proof by Cases
• To prove a conditional statement of the form
(p1 ∨ p2 ∨ · · · ∨ pn) → q is tautology. We can use as a rule of inference:
[(p1 ∨ p2 ∨ · · · ∨ pn) → q] [(p1 → q) ∧ (p2 → q) ∧ · · · ∧ (pn → q)]

• This shows that the original conditional statement with a hypothesis made up of a disjunction of
the propositions p1, p2, . . . , pn can be proved by proving each of the n conditional statements pi →
q, i = 1, 2, . . . , n, individually.
Proof by exhaustion
• Proof by exhaustion is a method of proof that involves testing a
statement for all possible cases or instances within a finite
domain. It's particularly effective when the domain is small or can
be easily enumerated.
• Steps involved:
1.Identify the possible cases: Determine all the distinct values or
combinations of values that the variables in the statement can take.
2.Test the statement for each case: Verify that the statement is true for
each of the possible cases.
3.Conclude: If the statement is true for all cases, then it is true for the
entire domain.
Proof by exhaustion (Cont.)
• Example: For any integer n between 1 and 4, n^2 is greater than or
equal to n.
• Proof by exhaustion:
• Case 1: n = 1: 1^2 = 1, which is greater than or equal to 1.
• Case 2: n = 2: 2^2 = 4, which is greater than or equal to 2.
• Case 3: n = 3: 3^2 = 9, which is greater than or equal to 3.
• Case 4: n = 4: 4^2 = 16, which is greater than or equal to 4.
• Conclusion: Since the statement is true for all integers between 1 and 4,
it is true for the entire domain.
Proof by exhaustion (Cont.)
• Truth table method. To prove a statement about small number of Boolean variables make a truth table and
check all possible cases.
Example: (((A  B)  C)  B) ≡ (B  C)
One way is to use a membership table:

A B C BC ((A  B)  C) B (((A  B)  C)  B)


0 0 0 0 1 1 0
0 0 1 0 1 1 0
0 1 0 0 1 0 0
0 1 1 1 0 0 1
1 0 0 0 1 1 0
1 0 1 0 0 1 0
1 1 0 0 1 0 0
1 1 1 1 0 0 1
Proof by Case Analysis
• Proof by case analysis is a method of proof where you divide the proof
into different cases based on specific conditions or possibilities and
then prove the statement for each case separately. This technique is
often used when the domain of a statement is divided into distinct
subsets or when there are different conditions that can affect the truth
of the statement.

• Steps:
1.Identify the cases: Determine the different cases or conditions that can occur.
2.Prove the statement for each case: Prove the statement separately for each
identified case using appropriate proof techniques.
3.Conclude: Since the statement is true for all cases, it is true for the entire
domain.
Proof by Case Analysis (Cont.)
• Example:
• Statement: For any integer n, n^2 is either even or odd.
• Proof by case analysis:
• Case 1: n is even. If n is even, then n = 2k for some integer k. Therefore, n^2 = (2k)^2
= 4k^2 = 2(2k^2), which is even.
• Case 2: n is odd. If n is odd, then n = 2k + 1 for some integer k. Therefore, n^2 = (2k +
1)^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1, which is odd.
• Conclusion: Since n is either even or odd, and we have shown that n^2 is
even in the first case and odd in the second case, it follows that n^2 is
either even or odd for any integer n.
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Sets
• A set is an unordered collection of objects, called elements or members of
the set. Sets are denoted by curly braces {}. For example, the set of even
integers between 2 and 6 can be represented as {2, 4, 6}.
• The set V of all vowels in the English alphabet can be written as V = {a, e, i, o,
u}.
• Set Operations:
• Union (∪): The union of two sets A and B contains all elements that are in A or in B or in
both.
• Intersection (∩): The intersection of two sets A and B contains all elements that are in
both A and B.
• Difference ( - ): The difference of set A and set B contains all elements that are in A but
not in B.
• Complement (A'): The complement of set A contains all elements in the universal set
that are not in A.
• Cartesian Product (A × B): The Cartesian product of two sets A and B contains all
ordered pairs (a, b) where a is in A and b is in B.
Sets (Cont.)
• Set Notation:
• Sets are typically denoted by curly braces {}. For example, the set of even
numbers between 2 and 6 can be written as {2, 4, 6}.
• It is common for sets to be denoted using uppercase letters. Lowercase letters
are usually used to denote elements of sets.
• Elements of a set are separated by commas.
• The symbol ∈ is used to indicate that an element belongs to a set. For example,
4 ∈ {2, 4, 6}.

• Example1: The set of natural numbers N are the “whole numbers”: N = {0,
1, 2, 3, . . .}
• Example2: The set of integers Z are the whole numbers and their
negatives: Z = {. . . ,−2,−1, 0, 1, 2, . . .}
Sets (Cont.)
Sets are used to group objects together.
• A set is a collection of objects (members, elements). A = {3, 7, 14}
• A set is completely defined by its elements.
• An element ‘belongs to’ a set (or a set contains its elements).
• If a set is defined by listing its elements, all that matter is which elements included, not the order. {3, 7, 14}
is equal to {7, 3, 14}
• An element can appear more then once: Sets {3, 7, 14} and {3, 3, 14, 7, 7} are equal.
 Typically, sets will be denoted by uppercase letters.
Sets (Cont.)
• Types of Sets:
• Empty set (∅): A set containing no elements.
• Finite set: A set with a countable number of elements.
• Infinite set: A set with an uncountable number of elements.
• Universal set (U): The set containing all elements under consideration in
a particular context.
Sets (Cont.)
There are some other sets we should be familiar with since they come up so often. Here they are:
• Z = {0, 1, -1, 2, -2, ...} (the set of integers)
• N = {0, 1, 2, 3, ...} (the set of non-negative integers)
• Z+ = {1, 2, 3, ...} (the set of positive integers)
• Q = {a/b | a, bZ  b0} “|” such as
• R = the set of real numbers...
Sets (Cont.)
We have two usual methods of denoting the elements in a set:

1) Explicitly list the elements inside of a set of curly braces ({}), as follows: {1, 2, 3, 4}

• a set of vowels in English alphabet


V ={a, e, i, o, u} (finite set)
• a set of odd positive integers less then 10
B ={1, 3, 5, 7, 9} (finite set)
• a set of natural numbers (nonnegative integers)
 = {0, 1, 2, 3, …}(infinite set)
• a set of integers:
Z={…,-2, -1, 0, 1, 2, …}(infinite set)

2) To use “set builder” notation


Sets (Cont.)
• Set builder notation is a concise way to define sets by specifying a property or condition that elements
must satisfy. It involves using curly braces {}, a variable, a colon :, and a condition.
• In order to understand the second method, we must define the various symbols that are used in this notation.
Here is a list of the symbols we will be using:
• | - translates to “such that”
- “is an element of”
- “is a proper subset of”
- “is a subset of”

• General form: { x | condition(x) }


• This notation reads as "the set of all x such that condition(x) is true."

• Example1: The set of even integers can be written as: { x | x is an integer, and x is divisible by 2 }.
• Example2: The set of prime numbers less than 10 can be written as: { x | x is a prime number and x < 10 }
• Example3: O = {x | x is an odd positive integer less than 10} = {x ∈ Z+ | x is odd and x < 10}.
Sets (Cont.)
• set of odd positive integers less then 10:
B={x | x is positive odd integer less then 10}

• set of rational numbers:


Q = {a / b | a, b Z and b 0 }

• set of positive integers:


Z+= {x | x Z  x>0 }

• a set of squares of natural numbers:


S ={ x2 | xN}
Sets (Cont.)
• Set Properties:
• Equality: Two sets A and B are equal if they contain the same elements.
Therefore, if A and B are sets, then A and B are equal if and only if ∀x(x ∈ A x ∈
B). We write A = B if A and B are equal sets.
• Subset: The set A is a subset of B if and only if every element of A is also an
element of B. We use the notation A ⊆ B to indicate that A is a subset of the set
B. We see that A ⊆ B if and only if the quantification ∀x(x ∈ A → x ∈ B)
• Proper subset: A set A is a proper subset of set B if A is a subset of B and A is
not equal to B.
• A  B ≡ x [xA →x B] x [xB  x  A]
• Note: A  B iff A  B  AB.
• AB→AB
• but A  B does not imply A  B
Sets (Cont.)
• Example: Show that A  B, where
A ={ x| x is a prime number and 42x 51}
B = { y | y = 4k +3 and k  N }

To prove that A  B takes all x  A and show that x B. If x  A, then either x =43 or x=47.
x=43=410+3 and x=47= 411+3. So, in either case x has the form of an element of B, thus x B. Therefore A 
B.
Sets (Cont.)
• EXAMPLE: The sets {1, 3, 5} and {3, 5, 1} are equal, because they
have the same elements.
• Note that the order in which the elements of a set are listed does not
matter.
• Note also that it does not matter if an element of a set is listed more than
once, so {1, 3, 3, 3, 5, 5, 5, 5} is the same as the set {1, 3, 5} because they
have the same elements.
Sets (Cont.)
Equality of two sets
Two sets are equal if they contain the same elements. For example:
{1, 3, 5} = {3, 5, 1, 5}
{1, 4, 9, 16} = {x2 | x  Z+  x2 <20}

More rigorously:
Definition. Two sets are equal if and only if each of them is a subset of the other.
A = B  A B  B  A

Example. Show that A=B, where


A = { x | x is a prime number and 12 x 18 }
B = { y | y =4k +1 and k {3, 4} }

First show A B. Take any x A, then either x=13 or x=17. 13=43+1 →13 B, 17 = 44+1 →17 B, therefore A B. Similarly show
that B  A.
Sets (Cont.)
• Cardinality: The cardinality of a set is the number of elements in the
set. It is denoted by |A| for a set A.
• Let A be the set of odd positive integers less than 10. Then |A| = 5.
• Let S be the set of letters in the English alphabet. Then |S| = 26.
• What is the cardinality of each of the following sets?
|{a}| =1
|{{a}}| =1
|{a, {a}}| =2
|{a, {a}, {a, {a}}}| =3

• Cardinality of empty set || = 0


|{}|=1
|{, {}}|=2
|{, {}, {, {}}}|=3
Venn diagrams
• Venn diagrams are a graphical representation of sets and their
relationships.

• Basic Structure
• A Venn diagram typically consists of overlapping circles enclosed within a
rectangle. Each circle represents a set. The overlapping regions between
circles show the elements common to both sets.
Venn diagrams (Cont.)
• Universal Set (U): This is the set containing all elements under consideration
in a given context. The rectangle usually represents the universal set.
• Intersection (A ∩ B): The intersection of sets A and B is the set of elements
that belong to both A and B. It is represented by the overlapping region of the
circles for A and B.
• Union (A ∪ B): The union of sets A and B is the set of elements that belong to
either A or B (or both). It is represented by the entire area covered by both
circles.
• Complement (A'): The complement of set A is the set of elements in the
universal set that are not in A. It is represented by the area outside of circle A
within the rectangle.
• Difference (A - B): The difference of sets A and B is the set of elements that
belong to A but not to B. It is represented by the portion of circle A that does
not overlap with circle B.
Venn diagrams (Cont.)
• Example:
• Let's consider two sets:
• A: Set of even numbers
• B: Set of multiples of 3
• Venn diagram with two overlapping circles, one labeled A for even
numbers and the other labeled B for multiples of 3.
• The overlapping region represents numbers that are both even and
multiples of 3.
• A ∩ B: Numbers that are both even and multiples of 3 (e.g., 6, 12, 18)
• A ∪ B: Numbers that are either even or multiples of 3 (or both)
• A': Odd numbers
• A - B: Even numbers that are not multiples of 3 (e.g., 2, 4, 8)
Power Sets
• Given a set S, the power set of S is the set of all subsets of the set S. The power set of S is denoted
by P(S).
• What is the power set of the set {0, 1, 2}?
• Solution: The power set P({0, 1, 2}) is the set of all subsets of {0, 1, 2}. Hence, P({0, 1, 2}) = {∅, {0},
{1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}. Note that the empty set and the set itself are members of this
set of subsets.

• Theorem:The cardinality of the power set of S (S with cardinality |S|=n) is 2n, |Power(S)|=2|S|.
Cartesian Products
• Let A and B be sets. The Cartesian product of A and B, denoted by A × B, is the set
of all ordered pairs (a, b), where a ∈ A and b ∈ B. Hence, A × B = {(a, b) | a ∈ A ∧ b
∈ B}.

• Example: What is the Cartesian product of A = {1, 2} and B = {a, b, c}?


• Solution: The Cartesian product A × B is
A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}.
• Note that the Cartesian products A×B and B × A are not equal,
Cartesian Products (Cont.)
• What is the Cartesian product A × B × C, where A = {0, 1}, B = {1, 2}, and C = {0, 1, 2} ?
• Solution: The Cartesian productA × B × C consists of all ordered triples (a, b, c), where a ∈ A,
b ∈ B, and c ∈ C. Hence,
A × B × C = {(0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 2, 0), (0, 2, 1), (0, 2, 2),
(1, 1, 0), (1, 1, 1), (1, 1, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2)}.
Set Operations
• Let A and B be sets. The union of the sets A and B, denoted by A ∪ B, is the set that contains those elements
that are either in A or in B, or in both. A ∪ B = {x | x ∈ A ∨ x ∈ B}.
• Note that |A ∪ B| = |A| + |B| − |A ∩ B|.

• Let A and B be sets. The intersection of the sets A and B, denoted by A ∩ B, is the set containing those
elements in both A and B. A ∩ B = {x | x ∈ A ∧ x ∈ B}.
Set Operations (Cont.)
• Two sets are called disjoint if their intersection is the empty set.
• Let A = {1, 3, 5, 7, 9} and B = {2, 4, 6, 8, 10}. Because A ∩ B = ∅, A and B are disjoint.
• Let A and B be sets. The difference of A and B, denoted by A − B, is the set containing those elements that are
in A but not in B. The difference of A and B is also called the complement of B with respect to A. A − B = {x | x
∈ A ∧ x ∉ B}.
• The difference of sets A and B is sometimes denoted by A\B.
• The difference of {1, 3, 5} and {1, 2, 3} is the set {5}; that is, {1, 3, 5} − {1, 2, 3} = {5}.
• Let U be the universal set. The complement of the set A, denoted by 𝐴,ҧ is the complement of A with respect to
U. Therefore, the complement of the set A is U − A. 𝐴ҧ = {x ∈ U | x ∉ A}.
Set Operations (Cont.)
• Example
If U = {1,2,3 … 9,10} A ={1,2,3,4,5} B={3,4,5,6,7}
• A  B ={1,2,3,4,5,6,7}
• A  B ={3,4,5}
• A ={6,7,8,9,10}
• B – A={6,7}
• A  B={1,2,6,7}

• Definition:
• S, T  U. The sets S and T are called disjoint or mutually disjoint,
when S  T = 
Set Operations (Cont.)
Do not confuse  and  (or ) signs!
Let A ={a, , {b}}.
• aA (T)
• {a} A (F)
• a A (F)
• {a}  A (T)
• {a}  A (T)
• {b}  A (F)
• {b}  A (T)
• {a, {b}}  A (T)
• {a, {b}}  A (T)
• A (T)
•  A (T)
Set Identities
Set Identities (Cont.)
• AB = B A
Proof
AB = { x | xA  xB }, by definition of union
= { x | xB  xA }, by commutative property of 
= B A, by definition of union

• A  (B  C) = (A  B)  C
Proof
A (BC)
={x | (x  A)  (x BC)]}, by definition of 
={x | (x  A)  [(x B) (x C)]}, by definition of 
= {x |[(x  A)  (x B)] (x C)}, by associative property of 
= {x |(x  A  B) (x C)}, by definition of 
= (A B) C, by definition of 
Set Identities (Cont.)
• A  (B  C) = (A  B)  (A  C)
Proof
A B C BC A (BC) A B A C (A  B)  (A  C)
1 1 1 1 1 1 1 1
1 1 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 0 0 0 1 1 1 1
0 1 1 1 1 1 1 1
0 1 0 0 0 1 0 0
0 0 1 0 0 0 1 0
0 0 0 0 0 0 0 0
Set Identities (Cont.)
• A   = A, A  U = A Identity Laws
Proof
A  = {x | x A  x}, by definition of a set union
= {x | x A  F}, since x [x] , x=F
= {x | x A}, by identity law p  F  p
=A
In the proof of A U = A you can consider x  U =T and use another identity law p  T ≡ p
Set Identities (Cont.)
prove that A = (A – B)  (A  B), for all sets A and B.
Proof

(A – B)  (A  B) = (A  B)  (A  B), definition of –


= A  (B  B), distributive law
= A  U, Inverse law
= A, Identity law

membership table method


A B A-B AB (A – B)  (A  B)
1 1 0 1 1
1 0 1 0 1
0 1 0 0 0
0 0 0 0 0
Set Identities (Cont.)
ҧ 𝐵.
• Use set builder notation and logical equivalences to establish the first De Morgan law 𝐴 ∩ 𝐵 = 𝐴𝑈 ത
• Solution:We can prove this identity with the following steps.
𝐴 ∩ 𝐵 = {x | x ∉ A ∩ B} by definition of complement
= {x | ¬(x ∈ (A ∩ B))} by definition of does not belong symbol
= {x | ¬(x ∈ A ∧ x ∈ B)} by definition of intersection
= {x | ¬(x ∈ A)∨¬(x ∈ B)} by the first De Morgan law for logical equivalences
= {x | x ∉ A ∨x ∉ B} by definition of does not belong symbol
= {x | x ∈ 𝐴ҧ ∨ x ∈ 𝐵}
ത by definition of complement
= {x | x ∈ 𝐴ҧ ∪ 𝐵}
ത by definition of union
= 𝐴ҧ ∪ 𝐵ത by meaning of set builder notation
Set Identities (Cont.)
• Use a membership table to show that A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).
Functions
• Let A and B be nonempty sets. A function f from A to B is an assignment of exactly one element of B to each
element of A. We write f (a) = b if b is the unique element of B assigned by the function f to the element a of A.
If f is a function from A to B, we write f : A → B.
• Functions are sometimes also called mappings or transformations.
• If f is a function from A to B, we say that A is the domain of f and B is the codomain of f.
• If f (a) = b, we say that b is the image of a and a is a preimage of b.
• The range, or image, of f is the set of all images of elements of A.
• If f is a function from A to B, we say that f maps A to B.
Functions (Cont.)
• Example: Let f : Z → Z assign the square of an integer to this integer. Then, f (x) =
x2, where the domain of f is the set of all integers, the codomain of f is the set of all
integers, and the range of f is the set of all integers that are perfect squares,
namely, {0, 1, 4, 9, . . . }.
One-to-one (injunction)
• Afunction f is said to be one-to-one, or an injunction, if and only if f (a) = f (b) implies that a = b for all a and
b in the domain of f.
• A function is said to be injective if it is one-to-one.
• Example: Determine whether the function f from {a, b, c, d} to {1, 2, 3, 4, 5} with f (a) = 4, f (b) = 5, f (c) = 1,
and f (d) = 3 is one-to-one.
• The function f is one-to-one because f takes on different values at the four elements of its domain.
One-to-one (injunction) (Cont.)
• Example: Determine whether the function f (x) = x2 from the set of integers to the
set of integers is one-to-one.
• Solution: The function f (x) = x2 is not one-to-one because, for instance, f (1) = f (−1) = 1, but 1 = −1.
One-to-one (injunction) (Cont.)
• Example: Determine whether the function f (x) = x + 1 from the set of
real numbers to itself is one-to-one.
• Solution: The function f (x) = x + 1 is a one-to-one function. To demonstrate this, note that x + 1
≠ y + 1 when x ≠ y.
Onto (surjection)
• A function f from A to B is called onto, or a surjection, if and only if
for every element b ∈ B there is an element a ∈ A with f (a) = b.
• A function f is called surjective if it is onto.
• Example Let f be the function from {a, b, c, d} to {1, 2, 3} defined by
f (a) = 3, f (b) = 2, f (c) = 1, and f (d) = 3. Is f an onto function?
• Solution: Because all three elements of the codomain are images of
elements in the domain, we see that f is onto.
• Note that if the codomain were {1, 2, 3, 4}, then f would not be onto.
Onto (surjection) (Cont.)
• Example: Is the function f (x) = x2 from the set of integers to the set of integers
onto?
• Solution: The function f is not onto because there is no integer x with x2 = −1, for instance.

• Example: Is the function f (x) = x + 1 from the set of integers to the set of integers
onto?
• Solution: This function is onto, because for every integer y there is an integer x such that f (x) = y. To see
this, note that f (x) = y if and only if x + 1 = y, which holds if and only if x = y − 1.
Examples of Different Types of
Correspondences
One-to-one correspondence (bijection)
• The function f is a one-to-one correspondence, or a bijection, if it is both one-to-one and onto. We also say
that such a function is bijective.
• Example: Let f be the function from {a, b, c, d} to {1, 2, 3, 4} with f (a) = 4, f (b) = 2, f (c) = 1, and f (d) = 3. Is f
a bijection?
• Solution: The function f is one-to-one and onto. It is one-to-one because no two values in the domain are assigned the
same function value. It is onto because all four elements of the codomain are images of elements in the domain.
Hence, f is a bijection.
Inverse Functions
• Let f be a one-to-one correspondence from the set A to the set B. The inverse function of f is the function that
assigns to an element b belonging to B the unique element a in A such that f (a) = b. The inverse function of f
is denoted by f −1. Hence, f−1(b) = a when f (a) = b.
Inverse Functions (Cont.)
• Example: Let f be the function from {a, b, c} to {1, 2, 3} such that f (a) = 2, f (b) = 3,
and f (c) = 1. Is f invertible, and if it is, what is its inverse?
• Solution: The function f is invertible because it is a one-to-one correspondence. The inverse function f−1
reverses the correspondence given by f , so f−1(1) = c, f−1(2) = a, and f−1(3) = b.

• Example: Let f : Z → Z be such that f (x) = x + 1. Is f invertible, and if it is, what is


its inverse?
• Solution: The function f has an inverse because it is a one-to-one correspondence. To reverse the
correspondence, suppose that y is the image of x, so that y = x + 1. Then x = y − 1. This means that y − 1 is
the unique element of Z that is sent to y by f . Consequently, f−1 (y) = y − 1.
Inverse Functions (Cont.)
• Example: Let f be the function from R to R with f (x) = x2. Is f invertible?
• Solution: Because f (−2) = f (2) = 4, f is not one-to-one. If an inverse function were defined, it would have
to assign two elements to 4. Hence, f is not invertible.
• Note we can also show that f is not invertible because it is not onto.
Composition of the functions
• Let g be a function from the set A to the set B and let f be a function from the set B
to the set C. The composition of the functions f and g, denoted for all a ∈ A by f ◦ g,
is defined by (f ◦ g)(a) = f (g(a)).
Composition of the functions (Cont.)
• Example: Let f and g be the functions from the set of integers to the set
of integers defined by f (x) = 2x + 3 and g(x) = 3x + 2. What is the
composition of f and g? What is the composition of g and f ?
• Solution: Both the compositions f ◦ g and g ◦ f are defined.
• (f ◦ g)(x) = f (g(x)) = f (3x + 2) = 2(3x + 2) + 3 = 6x + 7
• (g ◦ f )(x) = g(f (x)) = g(2x + 3) = 3(2x + 3) + 2 = 6x + 11.
• f ◦ g and g ◦ f are not equal. In other words, the commutative law does not hold for the
composition of functions.
Floor and ceiling functions
• The floor function assigns to the real number x the largest integer that is less than or equal to x. The value of
the floor function at x is denoted by 𝑥 .
• The ceiling function assigns to the real number x the smallest integer that is greater than or equal to x. The
value of the ceiling function at x is denoted by 𝑥 .
Relations
• Let A and B be sets. A binary relation from A to B is a subset of A × B.
• Example: Let A = {0, 1, 2} and B = {a, b}. Then {(0, a), (0, b), (1, a), (2, b)} is a relation from A to B. This means,
for instance, that 0 R a. Relations can be represented graphically
Relations (Cont.)
• Recall that a function f from a set A to a set B assigns exactly one element of B to each element of A.
• Relations are a generalization of functions; they can be used to express a much wider class of relationships
between sets.
Relations (Cont.)
• A relation on a set A is a relation from A to A.
• In other words, a relation on a set A is a subset of A × A.

• EXAMPLE: Let A be the set {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b) | a
divides b}?
• Solution: Because (a, b) is in R if and only if a and b are positive integers not exceeding 4 such
that a divides b, we see that R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}.
Relations (Cont.)
• EXAMPLE: How many relations are there on a set with n elements?
• Solution: A relation on a set A is a subset of A × A. Because A × A has n2 elements when A has
2
n elements, and a set with m elements has 2m subsets, there are 2𝑛 subsets of A × A. Thus,
2 2
there are 2𝑛 relations on a set with n elements. For example, there are 23 = 29 = 512 relations
on the set {a, b, c}.
Relations (Cont.)
More examples of relations:
• “parent-of”
• “child-of”
• “likes”
• “meet one another today”
• “less then” = {(a, b) | a, b A and a<b} where A={1, 2, …5}
“less then” = { (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)}
Relations (Cont.)
Properties of Relations:
• Reflexive: A relation R on set A is reflexive if (a, a) ∈ R for all a ∈ A.
• EXAMPLE: Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},
R6 = {(3, 4)}.
Which of these relations are reflexive?
Solution: The relations R3 and R5 are reflexive because they both contain all pairs of the form (a, a). R1, R2, R4,
and R6 are not reflexive because (3, 3) is not in any of these relations.
Relations (Cont.)
• Example: Is the “divides” relation on the set of positive integers reflexive?
Solution: Because a | a whenever a is a positive integer, the “divides” relation is reflexive.
(Note that if we replace the set of positive integers with the set of all integers the relation is not
reflexive because 0 does not divide 0.)
Relations (Cont.)
• Symmetric: A relation R on set A is symmetric if (a, b) ∈ R implies (b, a) ∈ R for all a, b ∈ A.
• The relation R on the set A is symmetric if ∀a∀b((a, b) ∈ R → (b, a) ∈ R).
• Antisymmetric: A relation R on a set A such that for all a, b ∈ A, if (a, b) ∈ R and (b, a) ∈ R,
then a = b is called antisymmetric.
• The relation R on the set A is antisymmetric if ∀a∀b(((a, b) ∈ R ∧ (b, a) ∈ R) → (a = b)).
• EXAMPLE: Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},
R6 = {(3, 4)}.
Which of the relations are symmetric and which are antisymmetric?
• Solution: The relations R2 and R3 are symmetric, because in each case (b, a) belongs to the relation whenever (a, b) does.
• None of the other relations is symmetric. This is done by finding a pair (a, b) such that it is in the relation but (b, a) is not.
• R4, R5, and R6 are all antisymmetric. For each of these relations there is no pair of elements a and b with a ≠ b such that both (a, b)
and (b, a) belong to the relation.
Relations (Cont.)
• Example: Is the “divides” relation on the set of positive integers symmetric? Is it
antisymmetric?
• Solution: This relation is not symmetric because 1| 2, but 2 does not divide 1.
It is antisymmetric, for if a and b are positive integers with a |b and b |a, then
a = b.
Relations (Cont.)
• Transitive: A relation R on set A is transitive if (a, b) ∈ R and (b, c) ∈ R
implies (a, c) ∈ R for all a, b, c ∈ A.
• The relation R on a set A is transitive if we have ∀a∀b∀c(((a, b) ∈ R ∧ (b, c) ∈ R) → (a, c) ∈ R).
• EXAMPLE: Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},
R6 = {(3, 4)}.
Which of the relations are transitive?

Solution: R4, R5, and R6 are transitive.


R1 is not transitive because (3, 4) and (4, 1) belong to R1, but (3, 1) does not.
R2 is not transitive because (2, 1) and (1, 2) belong to R2, but (2, 2) does not.
R3 is not transitive because (4, 1) and (1, 2) belong to R3, but (4, 2) does not.
Relations (Cont.)
• Example: Is the “divides” relation on the set of positive integers
transitive?
• Solution: Suppose that a divides b and b divides c. Then there are
positive integers k and l such that b = ak and c = bl. Hence, c = a(kl),
so a divides c. It follows that this relation is transitive.
Relations (Cont.)
• Equivalence Relation: A relation R on set A is an equivalence
relation if it is reflexive, symmetric, and transitive.

• EXAMPLE: Let R be the relation on the set of real numbers such that aRb if and
only if a − b is an integer. Is R an equivalence relation?
• Solution: Because a −a = 0 is an integer for all real numbers a, aRa for all real
numbers a. Hence, R is reflexive.
• Now suppose that aRb. Then a −b is an integer, so b−a is also an integer.
Hence, bRa. It follows that R is symmetric.
• If aRb and bRc, then a −b and b−c are integers. Therefore, a −c = (a −b) + (b−c)
is also an integer. Hence, aRc. Thus, R is transitive.
• Consequently, R is an equivalence relation.
Relations (Cont.)
• EXAMPLE: Suppose that R is the relation on the set of strings of English letters
such that aRb if and only if l(a) = l(b), where l(x) is the length of the string x. Is R
an equivalence relation?
• Solution: Because l(a) = l(a), it follows that aRa whenever a is a string, so that
R is reflexive.
• Next, suppose that aRb, so that l(a) = l(b). Then bRa, because l(b) = l(a). Hence,
R is symmetric.
• Finally, suppose that aRb and bRc. Then l(a) = l(b) and l(b) = l(c). Hence, l(a) =
l(c), so aRc. Consequently, R is transitive.
• Because R is reflexive, symmetric, and transitive, it is an equivalence relation.
Relations (Cont.)
Example: Is the following relation reflexive, irreflexive, symmetric, antisymmetric, or transitive? R =
{(a,b) | a,bZ+  a, 2a, and b are side lengths of a triangle} Note: For all triangles, the sum of the lengths
of any two sides must exceed the length of the third side.
• Reflexive? No – because (a,a)R, this is because a triangle can not have side lengths, a, a and 2a.
• Irreflexive? Yes – the previous argument holds for all positive integers a.
• Symmetric? No – (a, 2a)R, since we can have a triangle with side lengths a, 2a and 2a. However, (2a,
a)R because we can not have a triangle with side lengths 2a, 4a and a.
• Antisymmetric? Yes – If we have a  b, then we have (a,b)R. To prove this, consider a forming a
triangle with side lengths a, 2a, and b. We know that we must have a+b > 2a for a triangle to be formed.
BUT, a+b  a+a = 2a, which means that a+b is NOT greater than 2a. Thus, in this situation, we have
(a,b)R. Thus, for any element (a,b)R, we must have a < b. For each of these elements, we can
guarantee that (b,a)R since b > a.
• Transitive? No – (a, 2a)R as shown above, and we also know that (2a, 4a)R, by a similar analysis.
But we can show that (a,4a)R because a triangle can not have side lengths a, 2a and 4a.
Relations (Cont.)
• Give an example of a relation on A ={a, b, c} that is
a) reflexive but not symmetric
R={(a, a), (b, b), (c, c), (a, b)}

• b) symmetric but not reflexive and not transitive


• R={(a, b), (b, a), (b, b), (b, c), (c, b)}
Relations(Cont.)
• Functions:
• A function is a special type of relation where each element in the first set
(domain) is associated with exactly one element in the second set
(codomain).

• Properties of Functions:
• Injective (one-to-one): A function is injective if no two different elements
in the domain map to the same element in the codomain.
• Surjective (onto): A function is surjective if every element in the codomain
has at least one element in the domain that maps to it.
• Bijective (one-to-one correspondence): A function is bijective if it is both
injective and surjective.
Relations(Cont.)
• Equivalence Classes:
• An equivalence relation partitions a set into disjoint subsets called
equivalence classes. Elements within the same equivalence class are
considered equivalent under the relation.
• Let R be an equivalence relation on a set A. The set of all elements that
are related to an element a of A is called the equivalence class of a. The
equivalence class of a with respect to R is denoted by [a]R. When only one
relation is under consideration, we can delete the subscript R and write
[a] for this equivalence class.
• [a]R = {s | (a, s) ∈ R}.
Relations(Cont.)
• Example: Let R be the relation on the set of integers such that aRb if and only if a
= b or a = −b. What is the equivalence class of an integer for the equivalence
relation R.
• Solution: Because an integer is equivalent to itself and its negative in this
equivalence relation, it follows that [a] = {−a, a}. This set contains two distinct
integers unless a = 0. For instance, [7] = {−7, 7}, [−5] = {−5, 5}, and [0] = {0}.
Relations(Cont.)
• Example: What are the sets in the partition of the integers arising from congruence modulo 4?
• Solution: There are four congruence classes, corresponding to [0]4, [1] 4, [2] 4, and [3] 4. They are
the sets:
[0] 4 = {. . . ,−8,−4, 0, 4, 8, . . . },
[1] 4 = {. . . ,−7,−3, 1, 5, 9, . . . },
[2] 4 = {. . . ,−6,−2, 2, 6, 10, . . . },
[3] 4 = {. . . ,−5,−1, 3, 7, 11, . . . }.
These congruence classes are disjoint, and every integer is in exactly one of them.
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Introduction to Number Theory
Integers: Z={…-3, -2, -1, 0, 1, 2, 3, …}
Operations: addition, multiplication, subtraction.
Given any two integers a, bZ we can define
a + b Z
a − b Z
a  b Z
Integers Z are closed under operations ‘+’, ‘−’, ‘’.

Closure properties under +, −, : If a, b are integers, then a+b, a −b, a  b are integers.

Commutative Law: If a, b are integers, then a+b=b+a; ab=ba

Associative Law: If a, b are integers, then


a+(b+c) = (a+b)+c
a( bc ) = (ab)c
Introduction to Number Theory (Cont.)
Distributive Law
If a, b are integers, then a(b+c) = ab+ ac

Identity elements for addition and multiplication


For all integer a, a+0=a; a  1= a

Additive inverse
For all integer a, a + (−a) = (−a)+a = 0

Division
If a, b Z, b 0, then it may be that (a / b)  Z, so integers are not closed under division.
Divisibility
• If a and b are integers with a ≠ 0, we say that a divides b if there is an integer c such that b = ac, or
equivalently, if b/a is an integer. When a divides b we say that a is a factor or divisor of b, and that b is a
multiple of a. The notation a | b denotes that a divides b.
• We can express a | b using quantifiers as ∃c(ac = b), where the universe of discourse is the set of integers.

• Example: Determine whether 3 | 7


• 7/3 is not an integer

• Example: Determine whether 3 | 12


• 3 | 12 because 12/3 = 4
Divisibility (Cont.)
Some properties of divisibility
For any a Z :
1) a | 0 because 0= a 0
2) 1 | a because a =1a

For any a, b Z
3) If a | b and b | a, then a = b
4) If a | b and b>0 and a>0, then a  b
5) If mZ, m0, then a | b if and only if (ma)|(mb)
Divisibility (Cont.)
For any a, b, c
THEOREM: If a | b and b | c, then a | c.

Proof.
a | b → b = ax for some xZ (by definition of divisibility)
b | c → c = by for some yZ (by definition of divisibility)
By substitution we have c = (ax)y.
By associative law, c = a(xy).
xy=k is an integer by the closure property of integers under
multiplication.
c = ak means that a | c .
Divisibility (Cont.)
THEOREM : If a | b then a | bc.

Proof
By the definition of divisibility, a | b implies that there is some integer x such that b = ax.
For any integer c, bc = (ax)c = a(xc) by associative property of multiplication.
By the closure property integers under multiplication
xc = k, an integer, so bc =ak, i. e. a | bc
Divisibility (Cont.)
• THEOREM : If a | b and a | c then a | (bx + cy) for any x, y Z
Proof is left as an exercise.
Divisibility (Cont.)
• THEOREM
• THE DIVISION ALGORITHM Let a be an integer and d a positive integer. Then there are unique
integers q and r, with 0 ≤ r < d, such that a = dq + r.
• Note that the remainder cannot be negative.
• In the equality given in the division algorithm, d is called the divisor, a is called the dividend, q is
called the
quotient, and r is called the remainder. This notation is used to express the quotient and
remainder: q = a div d, r = a mod d.
• when a is an integer and d is a positive integer, we have
• a div d = 𝑎/𝑑
• Example: What are the quotient and remainder when 101 is divided by 11?
• We have 101 = 11 ・ 9 + 2.
• the quotient when 101 is divided by 11 is 9 = 101 div 11, and the remainder is 2 = 101 mod 11.
• Example: What are the quotient and remainder when −11 is divided by 3?
• Hence, the quotient when −11 is divided by 3 is −4 = −11 div 3, and the remainder is 1 = −11 mod 3.
• Consequently, the remainder is not −2, even though −11 = 3(−3) − 2, because r = −2 does not satisfy 0 ≤ r < 3.
Modular Arithmetic
• We now introduce a notation that indicates that two integers have the same remainder when they are divided
by the positive integer m.
• DEFINITION: If a and b are integers and m is a positive integer, then a is congruent to b modulo m if m
divides a − b. We use the notation a ≡ b (mod m) to indicate that a is congruent to b modulo m. We say that a
≡ b (mod m) is a congruence and that m is its modulus (plural moduli).
• THEOREM: Let a and b be integers, and let m be a positive integer. Then a ≡ b (mod m) if and only if a mod
m = b mod m.
• Example: Determine whether 17 is congruent to 5 modulo 6
• Because 6 divides 17 − 5 = 12, we see that 17 ≡ 5 (mod 6).
• Example: Determine whether 24 is congruent to 14 modulo 6
• 24 − 14 = 10 is not divisible by 6, we see that 24 is not congruent to 14 (mod 6).
Arithmetic Modulo m
• We can define arithmetic operations on Zm, the set of nonnegative integers less than m, that is, the set {0, 1, . .
. , m − 1}.
• We define addition of these integers, denoted by +m by a +m b = (a + b) mod m.
• We define multiplication of these integers, denoted by ・m by a ・m b = (a ・ b) mod m.
• Example: find 7 +11 9
• 7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5

• Example: find 7 ・11 9


• 7 ・11 9 = (7 ・ 9) mod 11 = 63 mod 11 = 8.
Arithmetic Modulo m (Cont.)
• Closure If a and b belong to Zm, then a +m b and a ・m b belong to Zm.
• Associativity If a, b, and c belong to Zm, then (a +m b) +m c = a +m (b +m c) and (a ・m b) ・m c = a ・m (b ・m
c).
• Commutativity If a and b belong to Zm, then a +m b = b +m a and a ・m b = b ・m a.
• Identity elements The elements 0 and 1 are identity elements for addition and multiplication modulo m,
respectively. That is, if a belongs to Zm, then a +m 0 = 0 +m a = a and a ・m 1 =1 ・m a = a.
• Additive inverses If a ≠ 0 belongs to Zm, then m − a is an additive inverse of a modulo m and 0 is its own
additive inverse. That is a +m (m − a) = 0 and 0 +m 0 = 0.
• Distributivity If a, b, and c belong to Zm, then a ・m (b +m c) = (a ・m b) +m (a ・m c) and (a +m b) ・m c = (a
・m c) +m (b ・m c).
Primes
• An integer p greater than 1 is called prime if the only positive factors of p are 1
and p.
• A positive integer that is greater than 1 and is not prime is called composite.
• Example: the integer 7 is prime because its only positive factors are 1 and 7
• Example: the integer 9 is composite because it is divisible by 3.
Primes (Cont.)
• THEOREM:THE FUNDAMENTAL THEOREM OF ARITHMETIC
• Every integer greater than 1 can be written uniquely as a prime or as the product of two or more primes
where the prime factors are written in order of nondecreasing size.
• Examples:
• 100 = 2 ・ 2 ・ 5 ・ 5 = 2252
• 641 = 641
• 999 = 3 ・ 3 ・ 3 ・ 37 = 33 ・ 37,
• 1024 = 2 ・ 2 ・ 2 ・ 2 ・ 2 ・ 2 ・ 2 ・ 2 ・ 2 ・ 2 = 210.
Primes (Cont.)
• THEOREM: If n is a composite integer, then n has a prime divisor less than or equal to 𝑛.
• Example: Show that 101 is prime
• Solution: The only primes not exceeding 101 are 2, 3, 5, and 7. Because 101 is not divisible by 2, 3, 5, or 7 (the quotient of 101 and
each of these integers is not an integer), it follows that 101 is prime.
Greatest Common Divisors
• DEFINITION: Let a and b be integers, not both zero. The largest integer d such that d | a and d | b is called
the greatest common divisor of a and b. The greatest common divisor of a and b is denoted by gcd(a, b).

• EXAMPLE: What is the greatest common divisor of 24 and 36?


• Solution: The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6, and 12. Hence, gcd(24, 36) = 12.

• EXAMPLE: What is the greatest common divisor of 17 and 22?


• Solution: The integers 17 and 22 have no positive common divisors other than 1, so that gcd(17, 22) = 1.

• DEFINITION: The integers a and b are relatively prime if their greatest common divisor is 1.
• Example: it follows that the integers 17 and 22 are relatively prime, because gcd(17, 22) = 1.
Greatest Common Divisors (Cont.)
Suppose that the prime factorizations of the integers a and b are:
a a
a = p1 1 p2 2 ...pna n b b
b = p1 1 p22 ...pnbn
(ai, bi 0 )

where all primes occurring in either factorization are included in


both factorizations with zero exponent if necessary.
Then min( a ,b ) min( a ,b )
gcd( a, b) = p1 p2
1 1
...pnmin( a ,b )
2 2 n n

Example: Find gcd(120, 500) using prime factorization.


We have 120 =23 ×3 ×5 and 500=22 ×53 , then
gcd(120, 500)= 2min(3, 2) ×3min(1, 0) ×5min(1, 3) =22 ×30 ×51=20.
Least common multiple
• The least common multiple of two integers:

max( a1 ,b1 ) max( a 2 ,b2 )


lcm( a, b) = p1 p2 ...pnmax( a n ,bn )
• Lemma. For any two integers x and y we have: x + y = max(x, y)+min(x, y)

• Theorem. For any two integers a and b ab = gcd (a, b) lcm(a, b)

a a a b b b
a  b = ( p1 1  p2 2  ... pk k )  ( p1 1  p22  ... pkk )

a + b1 a + b2 a + bk
= p1 1  p2 2  ...  pk k

max( a1 ,b1 ) + min( a1 ,b1 ) max( a k ,bk ) + min( a k ,bk )


= p1  ...  pk

min( a1 ,b1 ) min( a k ,bk ) max( a1 ,b1 ) max( a k ,bk )


= ( p1  ...  pk )( p1  ...  pk )
What is the lcm(120, 500)?
120500 = 23+23151+3
= gcd(120, 500) lcm(120, 500)
= 22 30 51lcm(120, 500)

lcm(120, 500)= 233153= 3000


The Euclidean Algorithm
• We will discuss an efficient method of finding the greatest common divisor, called the Euclidean algorithm.
• Let a = bq + r, where a, b, q, and r are integers. Then gcd(a, b) = gcd(b, r).
• Example: find gcd(91, 287)
• 287 = 91 ・ 3 + 14.
• Any divisor of 91 and 287 must also be a divisor of 287 − 91 ・ 3 = 14.
• Any divisor of 91 and 14 must also be a divisor of 287 = 91 ・ 3 + 14
• gcd(91, 287) = gcd(91, 14).
• 91 = 14 ・ 6 + 7.
• gcd(91, 14) = gcd(14, 7)
• gcd(14, 7) = 7
• gcd(91, 287) = 7
The Euclidean Algorithm
• Example: Consider computing gcd(125, 87)

125 = 1*87 + 38
= 2*38 + 11
= 3*11 + 5
11 = 2*5 + 1
= 5*1

• Thus, we find that gcd(125,87) = 1.


The Euclidean Algorithm
• Example: gcd(125, 20)

125 = 6*20 + 5
= 4*5,

Thus, the gcd(125,20) = 5


The Euclidean Algorithm (Cont.)
Proof: It is sufficient to prove that set of common divisors of a and b is equal to the set of common divisors
of b and r.

Let d be a common divisor of a and b.


a=a’d
b=b’d
r=a-bq =d(a’-b’q) , i. e. d is also a divisor of r.

Let f be a common divisor of b and r


a = bq + r =f(b’q+r’) i. e. f is also a divisor of a .
The Euclidean Algorithm (Cont.)
• Find the greatest common divisor of 414 and 662 using the Euclidean algorithm
• 662 = 414 ・ 1 + 248
• 414 = 248 ・ 1 + 166
• 248 = 166 ・ 1 + 82
• 166 = 82 ・ 2 + 2
• 82 = 2 ・ 41.
• Hence, gcd(414, 662) = 2, because 2 is the last nonzero remainder
The Euclidean Algorithm (Cont.)
procedure gcd(a, b: positive integers)
x := a
y := b
while y = 0
r := x mod y
x := y
y := r
return x{gcd(a, b) is x}
Theorem
• Theorem: An integer solution (x , y) of equation ax + by =c exists if and only if c is divisible by gcd(a, b).
• To find integer solution of an equation ax+by=c, we need to check first, that gcd(a, b) divides c.

For example, to find integer solution for 85x +34y = 51, find the gcd(85, 34) using Euclid Algorithm:
85=342+17
34= 172
So, gcd(85, 34)=17.
Since 17|51 a solution exists

Find the integers u, v in gcd(a, b)=au+bv.


17 = 85 − 342,  u = 1, v = −2.
By multiplying by 3 we find:
51=853+34 (−6),
i. e. x =3, y = −6 is a solution.
• Other integer solutions
51= 85×x+34×y
17 = 85×u +34×v
1= 5u +2v
1=5(u−2k) +2(v+5k) where k is any integer.
17= 85(u−2k)+34(v+5k)
51 = 85(x −6k) + 34(y+15k)

• So, if a solution (x, y) exists, then there are infinitely many solutions (x −6k, y+15k), k is any integer.
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Proof by induction
• Proof by induction is a powerful technique used to prove
statements about sequences or structures that are defined
recursively. To prove that P(n) is true for all positive integers n,
where P(n) is a propositional function, we complete two steps:
• Base Step :
• We verify that P(1) is true.
• Inductive Step:
• We show that the conditional statement P(k) → P(k + 1) is true for all positive integers k.
• Conclusion:
• If the statement is true for the base case and for all k+1 whenever it is true for k, then
it is true for all values greater than or equal to the base case.
Proof by induction (Cont.)
• Expressed as a rule of inference, this proof technique can be stated as:
(P (1) ∧ ∀k(P(k) → P(k + 1))) → ∀nP (n)
Proof by induction (Cont.)
• Example: For all positive integers n, 1 + 2 + 3 + ... + n = n(n+1)/2.

• Proof by induction:
• Base case: For n = 1, 1 = 1(1+1)/2, which is true.
• Inductive step: Assume the statement is true for n = k: 1 + 2 + 3 + ... + k =
k(k+1)/2. Now, we need to prove it's true for n = k+1:
1 + 2 + 3 + ... + k + (k+1) = k(k+1)/2 + (k+1)
Simplifying the right side: (k+1)(k+2)/2
• Therefore, the statement is true for n = k+1.
Proof by induction (Cont.)
• Example: Use mathematical induction to show that
1 + 2 + 22 +· · ·+2n = 2n+1 − 1 for all nonnegative integers n.

• Proof by induction: Solution: Let P(n) be the proposition that 1 + 2 + 22 +· · ·+2n = 2n+1 − 1 for the integer n.
• BASIS STEP: P(0) is true because 20 = 1 = 21 − 1.
• INDUCTIVE STEP: We assume that P(k) is true for an arbitrary nonnegative integer k. That is, we assume that
1 + 2 + 22 +· · ·+2k = 2k+1 − 1.
• We must show that when we assume that P(k) is true, then P(k + 1) is also true. That is, we must show that
1 + 2 + 22 +· · ·+2k + 2k+1 = 2(k+1)+1 − 1 = 2k+2 − 1
assuming the inductive hypothesis P(k). Under the assumption of P(k), we see that
1 + 2 + 22 +· · ·+2k + 2k+1 = (1 + 2 + 22 +· · ·+2k) + 2k+1
= (2k+1 − 1) + 2k+1 using IH
= 2 · 2k+1 − 1
= 2k+2 − 1.
• We have completed the inductive step.
Strong induction
• Strong induction is a mathematical proof technique that extends
the principle of mathematical induction. Strong induction allows
you to assume that the statement holds for all values up to a
particular value.

• The Principle of Strong Induction


1.Base Case: Prove that the statement is true for the base case (often the
smallest possible value).
2.Inductive Step: Assume that the statement is true for all values from the
base case up to and including a particular value, k.
3.Inductive Conclusion: Use the assumption from step 2 to prove that the
statement is also true for the next value, k+1.
Strong induction (Cont.)
• Example: Proving the Fibonacci Number Formula
The Fibonacci numbers are defined recursively as follows:
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2) for n ≥ 2

• We can prove the following formula for the nth Fibonacci number
using strong induction:
F(n) = [(1 + √5)/2]^n - [(1 - √5)/2]^n / √5
Strong induction (Cont.)
• Base Cases:

• For n = 0: F(0) = 0, which matches the formula.


• For n = 1: F(1) = 1, which matches the formula.
• Inductive Step: Assume that the formula holds for all values from 0 to k, where k ≥ 1.

• Inductive Conclusion: We need to prove that the formula holds for k+1. Using the recursive definition of Fibonacci numbers:

• F(k+1) = F(k) + F(k-1)


• By the inductive hypothesis, we can substitute the formula for F(k) and F(k-1):

• F(k+1) = [(1 + √5)/2]^k - [(1 - √5)/2]^k / √5 + [(1 + √5)/2]^(k-1) - [(1 - √5)/2]^(k-1) / √5


• Simplifying and factoring, we can show that this expression is equivalent to the formula for F(k+1).

• Therefore, by strong induction, the formula holds for all non-negative integers n.
Recursive Definitions
• Recursively Defined Functions
• BASIS STEP: Specify the value of the function at zero.
• RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller integers.

• Example: Suppose that f is defined recursively by


f (0) = 3,
f (n + 1) = 2f (n) + 3. Find f (1), f (2), f (3), and f (4).
• Solution: From the recursive definition it follows that
f (1) = 2f (0) + 3 = 2 · 3 + 3 = 9,
f (2) = 2f (1) + 3 = 2 · 9 + 3 = 21,
f (3) = 2f (2) + 3 = 2 · 21 + 3 = 45,
f (4) = 2f (3) + 3 = 2 · 45 + 3 = 93.
Recursive Definitions (Cont.)
• Example: Give a recursive definition of an, where a is a nonzero real number and
n is a nonnegative integer.
• Solution: The recursive definition contains two parts. First a0 is specified, namely, a0 = 1. Then
the rule for finding an+1 from an, namely, an+1 = a · an, for n = 0, 1, 2, 3, . . . , is given. These two
equations uniquely define an for all nonnegative integers n.
Recursive Algorithms
• An algorithm is called recursive if it solves a problem by reducing it to an instance of the same problem with
smaller input.
• Example: Give a recursive algorithm for computing n!, where n is a nonnegative integer.

procedure factorial(n: nonnegative integer)


if n = 0 then return 1
else return n · factorial(n − 1)
Recursive Algorithms (Cont.)
• Example: Give a recursive algorithm for computing an, where a is a nonzero real number and n is a
nonnegative integer.

procedure power(a: nonzero real number, n: nonnegative integer)


if n = 0 then return 1
else return a · power(a, n − 1)
Recursive Algorithms (Cont.)
• Example: Give a recursive algorithm for computing the greatest common divisor of two nonnegative integers a and
b with a < b.

procedure gcd(a, b: nonnegative integers with a < b)


if a = 0 then return b
else return gcd(b mod a, a)

• We illustrate the workings of the function with a trace when the input is a = 5, b = 8.
• gcd(5, 8) = gcd(8 mod 5, 5) = gcd(3, 5).
• gcd(3, 5) = gcd(5 mod 3, 3) = gcd(2, 3)
• cd(2, 3) = gcd(3 mod 2, 2) = gcd(1, 2)
• gcd(1, 2) = gcd(2 mod 1, 1) = gcd(0, 1).
• Finally, to find gcd(0, 1) it uses the first step with a = 0 to find that gcd(0, 1) = 1.
• Consequently, the function finds that gcd(5, 8) = 1.
Recursive Algorithms (Cont.)
• Example: Give a recursive algorithm for Fibonacci Numbers

procedure fibonacci(n: nonnegative integer)


if n = 0 then return 0
else if n = 1 then return 1
else return fibonacci(n − 1) + fibonacci(n − 2)
Recursive Algorithms (Cont.)
• An Iterative Algorithm for Computing Fibonacci Numbers
• This algorithm requires far less computation than does the recursive algorithm.

procedure iterative fibonacci(n: nonnegative integer)


if n = 0 then return 0
else
x := 0
y := 1
for i := 1 to n − 1
z := x + y
x := y
y := z
return y
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Graphs and Graph Models
• DEFINITION:A graph G = (V ,E) consists of V , a nonempty set of vertices (or nodes) and E, a set of edges.
Each edge has either one or two vertices associated with it, called its endpoints. An edge is said to connect its
endpoints.
Graphs
• Undirected graphs are a type of graph where the edges that
connect nodes (or vertices) do not have a specific direction.
• This means that you can traverse an edge in either direction.
Graphs (Cont.)
• A graph in which each edge connects two different vertices and where no two edges connect the same pair of
vertices is called a simple graph.
Graphs (Cont.)
• Graphs that may have multiple edges connecting the same vertices are called multigraphs.
Graphs (Cont.)
• Graphs that may include loops, and possibly multiple edges connecting the same pair of vertices or a vertex to
itself, are sometimes called pseudographs.
• Loops: edges that connect a vertex to itself.
Graphs (Cont.)
• A directed graph (or digraph) (V ,E) consists of a nonempty set of vertices V and a set of directed edges (or
arcs) E. Each directed edge is associated with an ordered pair of vertices. The directed edge associated with
the ordered pair (u, v) is said to start at u and end at v.
Graphs (Cont.)
• Directed graphs that may have multiple directed edges from a vertex to a second (possibly the same) vertex
are used to model such networks. We called such graphs directed multigraphs. When there are m directed
edges, each associated to an ordered pair of vertices (u, v), we say that (u, v) is an edge of multiplicity m.
Graphs (Cont.)
• Graph Terminology
Graph Models
• SOCIAL NETWORKS
• In these graph models, individuals or organizations are represented by vertices;
relationships between individuals or organizations are represented by edges.
Graph Models (Cont.)
• Influence Graphs: In studies of group behaviour, it is observed that certain people can influence the thinking
of others. A directed graph called an influence graph can be used to model this behavior. Each person of the
group is represented by a vertex. There is a directed edge from vertex a to vertex b when the person
represented by vertex a can influence the person represented by vertex b.
Graph Models (Cont.)
• Collaboration Graphs: A collaboration graph is used to model social networks where two people are
related by working together in a particular way.
• In an academic collaboration graph, vertices represent people (perhaps restricted to members of a
certain academic community), and edges link two people if they have jointly published a paper. The
collaboration graph for people who have published research papers in mathematics was found in 2004 to
have more than 400,000 vertices and 675,000 edges.

• Call Graphs: Graphs can be used to model telephone calls made in a network.
• Each telephone number is represented by a vertex and each telephone call is represented by a directed edge.
• The edge representing a call starts at the telephone number from which the call was made and ends at the telephone
number to which the call was made.
• We need directed edges because the direction in which the call is made matters.
• We need multiple directed edges because we want to represent each call made from a particular telephone number to a
second number.
Graph Models (Cont.)
• The Web Graph: The World Wide Web can be modelled as a directed graph where each Web page is
represented by a vertex and where an edge starts at the Web page a and ends at the Web page b if there is a
link on a pointing to b. Because new Web pages are created and others removed somewhere on the Web
almost every second, the Web graph changes on an almost continual basis.

• Citation Graphs: Graphs can be used to represent citations in different types of documents. In such graphs,
each document is represented by a vertex, and there is an edge from one document to a second document if
the first document cites the second in its citation list.

• Road Networks: Graphs can be used to model road networks. In such models, vertices represent intersections
and edges represent roads.

• ….etc.
Graph Terminology
• Two vertices u and v in an undirected graph G are called adjacent (or neighbors) in G if u and v are endpoints
of an edge e of G.
• Such an edge e is called incident with the vertices u and v and e is said to connect u and v.

• The set of all neighbours of a vertex v of G = (V ,E), denoted by N(v), is called the neighborhood of v. If A is a
subset of V , we denote by N(A) the set of all vertices in G that are adjacent to at least one vertex in A. So, N(A)
= Uv∈A N(v).

• The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a
vertex contributes twice to the degree of that vertex. The degree of the vertex v is denoted by deg(v).
Graph Terminology (Cont.)
• EXAMPLE:
• deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1, deg(e) = 3, and deg(g) = 0.
• The neighborhoods of these vertices are N(a) = {b, f }, N(b) = {a, c, e, f }, N(c) =
{b, d, e, f }, N(d) = {c}, N(e) = {b, c, f }, N(f ) = {a, b, c, e}, and N(g) = ∅.
Graph Terminology (Cont.)
• EXAMPLE
• deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, and deg(d ) = 5.
• The neighborhoods of these vertices are N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b}, N(d) = {a, b, e},
and N(e) = {a, b, d}.
Graph Terminology (Cont.)
THE HANDSHAKING THEOREM Let G = (V ,E) be an undirected graph with m edges. Then
2𝑚 = ෍ 𝑑ⅇ𝑔 𝑣
𝑣𝜖𝑉
(Note that this applies even if multiple edges and loops are present.)

• Example: How many edges are there in a graph with 10 vertices each of degree six?
• Solution: Because the sum of the degrees of the vertices is 6 ・ 10 = 60, it follows that 2m = 60 where m
is the number of edges. Therefore, m = 30.
Graph Terminology (Cont.)
• When (u, v) is an edge of the graph G with directed edges, the vertex u is called the initial vertex of (u, v), and v
is called the terminal or end vertex of (u, v). The initial vertex and terminal vertex of a loop are the same.
• In a graph with directed edges the in-degree of a vertex v, denoted by deg− (v), is the number of edges with v as
their terminal vertex. The out-degree of v, denoted by deg+ (v), is the number of edges with v as their initial
vertex. (Note that a loop at a vertex contributes 1 to both the in-degree and the out-degree of this vertex.)
• EXAMPLE: Find the in-degree and out-degree of each vertex in the graph G with directed edges.
• Solution: The in-degrees in G are deg−(a) = 2, deg−(b) = 2, deg−(c) = 3, deg−(d) = 2, deg−(e) = 3, and
deg−(f ) = 0.
• The out-degrees are deg+ (a) = 4, deg+(b) = 1, deg+(c) = 2, deg+(d) = 2, deg+(e) = 3, and deg+(f ) = 0.
Graph Terminology (Cont.)
• THEOREM: Let G = (V ,E) be a graph with directed edges. Then

෍ deg − 𝑣 = ෍ deg + 𝑣 = 𝐸
𝑣∈V 𝑣∈V
Some Special Simple Graphs
• Complete Graphs: A complete graph on n vertices, denoted by Kn, is a simple graph that contains exactly
one edge between each pair of distinct vertices.
Some Special Simple Graphs (Cont.)
• Cycles: A cycle Cn, n ≥ 3, consists of n vertices v1, v2, . . . , vn and edges {v1, v2}, {v2, v3}, . . . , {vn−1, vn},
and {vn, v1}.
Some Special Simple Graphs (Cont.)
• Wheels: We obtain a wheel Wn when we add an additional vertex to a cycle Cn, for n ≥ 3, and connect this
new vertex to each of the n vertices in Cn, by new edges.
Some Special Simple Graphs (Cont.)
• n-Cubes An n-dimensional hypercube, or n-cube, denoted by Qn, is a graph that has vertices representing
the 2n bit strings of length n. Two vertices are adjacent if and only if the bit strings that they represent differ in
exactly one bit position.
Some Special Simple Graphs (Cont.)
• A simple graph G is called bipartite if its vertex set V can be partitioned into two disjoint sets V1 and V2 such
that every edge in the graph connects a vertex in V1 and a vertex in V2 (so that no edge in G connects either
two vertices in V1 or two vertices in V2). When this condition holds, we call the pair (V1, V2) a bipartition of
the vertex set V of G.
• For example, consider the graph representing marriages between men and women in a village, where each
person is represented by a vertex and a marriage is represented by an edge. In this graph, each edge connects a
vertex in the subset of vertices representing males and a vertex in the subset of vertices representing females.
• The following figure show a bipartite graph, because its vertex set can be partitioned into the two sets V1 =
{v1, v3, v5} and V2 = {v2, v4, v6}, and every edge of C6 connects a vertex in V1 and a vertex in V2.
Some Special Simple Graphs (Cont.)
• THEOREM: A simple graph is bipartite if and only if it is possible to assign one of two different colors to
each vertex of the graph so that no two adjacent vertices are assigned the same color.
• Example: Use the Theorem to determine whether the following graph is bipartite.
• Solution: Yes

• Example: Use the Theorem to determine whether the following graph is bipartite.
• Solution: No
Representing Graphs
• Adjacency lists, which specify the vertices that are adjacent to each vertex of the graph.

• EXAMPLE: Use adjacency lists to describe the following simple


graph
Representing Graphs (Cont.)
• EXAMPLE: Use adjacency lists to describe the following Directed
Graph
Representing Graphs (Cont.)
• The adjacency matrix A (or AG) of G, with respect to this listing of the vertices, is the n x n zero–one matrix
with 1 as its (i, j )th entry when vi and vj are adjacent, and 0 as its (i, j )th entry when they are not adjacent.
1 𝑖𝑓 𝑣𝑖 , 𝑣𝑗 𝑖𝑠 𝑎𝑛 ⅇ𝑑𝑔ⅇ 𝑜𝑓 𝐺
𝑎𝑖𝑗 = ቊ
0 𝑜𝑡ℎⅇ𝑟𝑤𝑖𝑠ⅇ
• EXAMPLE: Use an adjacency matrix to represent the graph in the following Figure.
• Solution: We order the vertices as a, b, c, d. The matrix representing this graph is
Representing Graphs (Cont.)
• Draw a graph with the adjacency matrix with respect to the ordering of vertices a, b, c, d.
Representing Graphs (Cont.)
• The adjacency matrix of a simple graph is symmetric, that is, aij = aji , because both of these entries are 1 when
vi and vj are adjacent, and both are 0 otherwise. Furthermore, because a simple graph has no loops, each entry
aii, i = 1, 2, 3, . . . , n, is 0.
• Adjacency matrices can also be used to represent undirected graphs with loops and with multiple edges.
• A loop at the vertex vi is represented by a 1 at the (i, i)th position of the adjacency matrix.
• When multiple edges connecting the same pair of vertices vi and vj, or multiple loops at the same vertex,
are present, the adjacency matrix is no longer a zero–one matrix, because the (i, j )th entry of this matrix
equals the number of edges that are associated to {vi , vj }.
• EXAMPLE: Use an adjacency matrix to represent the following graph
Representing Graphs (Cont.)
• TRADE-OFFS BETWEEN ADJACENCY LISTS AND ADJACENCY MATRICES
• When a simple graph contains relatively few edges, that is, when it is sparse, it is usually preferable to
use adjacency lists rather than an adjacency matrix to represent the graph.
• Now suppose that a simple graph is dense, that is, suppose that it contains many edges, such as a graph
that contains more than half of all possible edges. In this case, using an adjacency matrix to represent the
graph is usually preferable overusing adjacency lists.
Representing Graphs (Cont.)
• Incidence matrices. Let G = (V ,E) be an undirected graph. Suppose that v1, v2, . . . , vn are the vertices and
e1, e2, . . . , em are the edges of G. Then the incidence matrix with respect to this ordering of V and E is the n ×
m matrix M = [mij ], where
1 when edge ⅇ𝑗 is incident with 𝑣𝑖
𝑚𝑖𝑗 = ቊ
0 otherwise.
• Example: Represent the following graph with an incidence matrix.
Assiut University
‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Introduction to Trees
• DEFINITION:A tree is a connected undirected graph with no simple circuits.
• Because a tree cannot have a simple circuit, a tree cannot contain multiple edges or loops. Therefore, any
tree must be a simple graph.
• Example: Which of the graphs shown in the following figure are trees?
• Solution: G1 and G2 are trees, because both are connected graphs with no simple circuits.
• G3 is not a tree because e, b, a, d, e is a simple circuit in this graph.
• G4 is not a tree because it is not connected.
Rooted Trees
• DEFINITION:A rooted tree is a tree in which one vertex has been designated as the root and every edge is
directed away from the root.
• Suppose that T is a rooted tree. If v is a vertex in T other than the root, the parent of v is the unique vertex u
such that there is a directed edge from u to v. When u is the parent of v, v is called a child of u.
• Vertices with the same parent are called siblings.
• The ancestors of a vertex other than the root are the vertices in the path from the root to this vertex, excluding
the vertex itself and including the root.
• The descendants of a vertex v are those vertices that have v as an ancestor.
• A vertex of a rooted tree is called a leaf if it has no children.
• Vertices that have children are called internal vertices.
Rooted Trees (Cont.)
• Example: In the following rooted tree (with root a), find the parent of c, the children of g, the siblings of h, all
ancestors of e, all descendants of b, all internal vertices, and all leaves. What is the subtree rooted at g?
• Solution: The parent of c is b. The children of g are h, i, and j . The siblings of h are i and j .
• The ancestors of e are c, b, and a. The descendants of b are c, d, and e.
• The internal vertices are a, b, c, g, h, and j . The leaves are d, e, f , i, k, l, and m. The subtree rooted at g is
shown in the Figure.
Rooted Trees (Cont.)
• DEFINITION:A rooted tree is called an m-ary tree if every internal vertex has no more than m children.
• The tree is called a full m-ary tree if every internal vertex has exactly m children.
• An m-ary tree with m = 2 is called a binary tree.

• Example:T1 is a full binary tree because each of its internal vertices has two children.
• T2 is a full 3-ary tree because each of its internal vertices has three children.
• In T3 each internal vertex has five children, so T3 is a full 5-ary tree.
• T4 is not a full m-ary tree for any m because some of its internal vertices have two children and others
have three children.
Trees as Models
• An Organizational Tree for a Computer Company
Trees as Models (Cont.)
• A Computer File System
Properties of Trees
• THEOREM: A tree with n vertices has n − 1 edges.
• Proof: We will use mathematical induction to prove this theorem.
• BASIS STEP: When n = 1, a tree with n = 1 vertex has no edges. It follows that the theorem is true for n = 1.
• INDUCTIVE STEP: The inductive hypothesis states that every tree with k vertices has k − 1 edges, where k is
a positive integer. Suppose that a tree T has k + 1 vertices and that v is a leaf of T (which must exist because
the tree is finite), and let w be the parent of v. Removing from T the vertex v and the edge connecting w to v
produces a tree T with k vertices, because the resulting graph is still connected and has no simple circuits. By
the inductive hypothesis, T has k − 1 edges. It follows that T has k edges because it has one more edge than T,
the edge connecting v and w. This completes the inductive step.
Properties of Trees (Cont.)
• The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. The level
of the root is defined to be zero.
• The height of a rooted tree is the maximum of the levels of vertices.
• In other words, the height of a rooted tree is the length of the longest path from the root to any vertex.

• EXAMPLE: Find the level of each vertex in the following rooted tree. What is the height of this tree?
• Solution: The root a is at level 0.
• Vertices b, j , and k are at level 1.
• Vertices c, e, f , and l are at level 2.
• Vertices d, g, i, m, and n are at level 3.
• Vertex h is at level 4.
• Because the largest level of any vertex is 4, this tree has height 4.
Properties of Trees (Cont.)
• A rooted m-ary tree of height h is balanced if all leaves are at levels h or h − 1.
• EXAMPLE: Which of the following rooted trees are balanced?
• Solution: T1 is balanced, because all its leaves are at levels 3 and 4.
• T2 is not balanced, because it has leaves at levels 2, 3, and 4.
• T3 is balanced, because all its leaves are at level 3.
Properties of Trees (Cont.)
• THEOREM: There are at most mh leaves in an m-ary tree of height h.
Binary Search Trees
• A binary search tree, which is a binary tree in which each child of a vertex is designated as a right or left
child, no vertex has more than one right child or left child,
• each vertex is labeled with a key.
• Vertices are assigned keys so that the key of a vertex is both larger than the keys of all vertices in its left
subtree and smaller than the keys of all vertices in its right subtree.
• EXAMPLE: Form a binary search tree for the words mathematics, physics, geography, zoology, meteorology,
geology, psychology, and chemistry (using alphabetical order).
ALGORITHM: Locating an Item in or Adding an Item to a
Binary Search Tree

procedure insertion(T : binary search tree, x: item)


v := root of T
{a vertex not present in T has the value null }
while v ≠ null and label(v) ≠ x
if x < label(v) then
if left child of v ≠ null then v := left child of v
else add new vertex as a left child of v and set v := null
else
if right child of v ≠ null then v := right child of v
else add new vertex as a right child of v and set v := null
if root of T = null then add a vertex v to the tree and label it with x
else if v is null or label(v) ≠ x then label new vertex with x and let v be this new vertex
return v {v = location of x}
Decision Trees
• Rooted tree in which each internal vertex corresponds to a decision, with a subtree at these vertices for each
possible outcome of the decision, is called a decision tree.
• Example: Suppose there are seven coins, all with the same weight, and a counterfeit coin that weighs less
than the others. How many weightings are necessary using a balance scale to determine which of the eight
coins is the counterfeit one? Give an algorithm for finding this counterfeit coin.
• Solution: It is possible to determine the counterfeit coin using two weighings.
A Decision Tree for Sorting Three Distinct
Elements

• THEOREM:A sorting algorithm based on binary comparisons requires at least log 𝑛! comparisons.
• log 𝑛! is θ(n log n),
HUFFMAN CODING
• Huffman coding is a fundamental algorithm in data compression, the subject devoted to reducing the number
of bits required to represent information.
• Huffman coding is extensively used to compress bit strings representing text and it also plays an important
role in compressing audio and image files.

• The algorithm begins with a forest of trees each consisting of one vertex, where each vertex has a symbol as
its label and where the weight of this vertex equals the frequency of the symbol that is its label.
• At each step, we combine two trees having the least total weight into a single tree by introducing a new root
and placing the tree with larger weight as its left subtree and the tree with smaller weight as its right subtree.
• Furthermore, we assign the sum of the weights of the two subtrees of this tree as the total weight of the tree.

• Example: Use Huffman coding to encode the following symbols with the frequencies listed: A: 0.08, B: 0.10,
C: 0.12, D: 0.15, E: 0.20, F: 0.35. What is the average number of bits used to encode a character?
HUFFMAN CODING (Cont.)
• Solution: The encoding produced encodes A by 111, B by 110, C by 011, D by 010, E by 10, and F by 00. The
average number of bits used to encode a symbol using this encoding is
• 3 · 0.08 + 3 · 0.10 + 3 · 0.12 + 3 · 0.15 + 2 · 0.20 + 2 · 0.35 = 2.45.
Tree Traversal
• Ordered rooted trees are often used to store information.We need procedures for visiting each vertex of an
ordered rooted tree to access data.
The Universal Address System of an Ordered Rooted Tree
Traversal Algorithms
• Preorder traversal
• Inorder traversal
• Postorder traversal
Preorder traversal

ALGORITHM:Preorder Traversal.
procedure preorder(T : ordered rooted tree)
r := root of T
list r
for each child c of r from left to right
T (c) := subtree with c as its root
preorder(T (c))
Inorder traversal

ALGORITHM: Inorder Traversal.


procedure inorder(T : ordered rooted tree)
r := root of T
if r is a leaf then list r
else
l := first child of r from left to right
T (l) := subtree with l as its root
inorder(T (l))
list r
for each child c of r except for l from left to right
T (c) := subtree with c as its root
inorder(T (c))
Postorder Traversal

ALGORITHM:Postorder Traversal.
procedure postorder(T : ordered rooted tree)
r := root of T
for each child c of r from left to right
T (c) := subtree with c as its root
postorder(T (c))
list r

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy