Lecture_Note_Discrete_Spring2024
Lecture_Note_Discrete_Spring2024
CSE106 DSU
Spring 2024
Contents
Contents
1 Discrete Mathematics 3
1.1 Discrete Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Propositional Logic 4
2.1 Propositional logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.1 What is proposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.2 Why a question is not a proposition? . . . . . . . . . . . . . . . . . . . 7
2.1.3 Propositional logic in Computer Science . . . . . . . . . . . . . . . . . 7
2.2 Logical Connectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 Truth Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3.1 Truth table construction . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 Examples of compound proposition . . . . . . . . . . . . . . . . . . . . . . . . 13
2.4.1 Truth value of compound proposition . . . . . . . . . . . . . . . . . . 16
2.4.2 More Compound Proposition Examples with Truth Values . . . . . . . 16
2.5 Contrapositive, Converse, and Inverse Examples . . . . . . . . . . . . . . . . . 20
2.5.1 Original Statement: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.5.2 Contrapositive: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.5.3 Converse: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.5.4 Inverse: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.6 Some Mathematical Statements (examples) . . . . . . . . . . . . . . . . . . . . 21
2.6.1 Original Statement: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.6.2 Original Statement: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.6.3 Original Statement: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.7 Bitwise Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.8 Translating English sentences . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.8.1 General rules for translation . . . . . . . . . . . . . . . . . . . . . . . . 24
2.9 Tautology and contradiction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.10 Logical equivalences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2
1 Discrete Mathematics
1 Discrete Mathematics
3
2 Propositional Logic
2 Propositional Logic
4
2 Propositional Logic
5
2 Propositional Logic
6
2 Propositional Logic
7
2 Propositional Logic
8
2 Propositional Logic
that if the antecedent “it rains” is true, then the consequent “the streets will be wet” must
also be true.
5. Bi-Implication (IF AND ONLY IF): A bi-implication, represented by the symbol “↔”
or the phrase “if and only if,” is used to express a relationship between two propositions
in which both propositions must be true or false together. For example, the statement
“John is tall if and only if Jane is short” means that “John is tall” and “Jane is short” must
have the same truth value.
6. Exclusive OR (XOR): logical connective represents a logical operation that outputs true
only when one and only one of its inputs is true. It can also be represented by the symbol
“⊕”.
Here are some examples of using XOR:
• In digital circuit design, XOR can be used to compare two binary signals and produce
a high output only when the signals are different.
• In cryptography, XOR can be used as a simple encryption technique by XORing a
plaintext message with a secret key to produce the ciphertext. The ciphertext can
be decrypted by XORing it with the same key.
• XOR can be used in error detection and correction. For example, in a binary code,
the parity bit can be generated by XORing all the bits in a data word. If the parity
bit is incorrect, it indicates that there is an error in the data word.
• XOR can be used in Boolean logic operations, where it is used to implement logic
gates that perform the XOR operation.
• XOR can be used to toggle a binary value. For example, if we XOR a binary number
9
2 Propositional Logic
10
2 Propositional Logic
For example, consider the proposition “P ∧ Q,” where “P” and “Q” are two propositions. A truth
table for this proposition would have two columns, one for “P” and one for “Q,” and four rows
corresponding to the four possible combinations of truth values for “P” and “Q”:
The truth value of the proposition “P ∧ Q” is given in the last column of the truth table. The
truth value is “T” (true) only when both “P” and “Q” are true, and it is “F” (false) in all other
cases.
Truth tables can be used to evaluate complex propositions involving multiple logical connectives,
such as conjunction, disjunction, negation, implication, and bi-implication. They are also used
to test the validity of arguments, to determine the equivalence of propositions, and to simplify
complex expressions.
In computer science, truth tables are used in the design and analysis of digital circuits and
in the development of algorithms and computer programs. They can also be used to model
decision-making processes and to analyze the behavior of systems in artificial intelligence and
robotics. Here are the truth tables for the six logical connectives:
Negation (NOT) The truth table for the negation of a proposition “P” is given below:
P ¬P
T F
F F
The truth value of “¬𝑃” is “F” (false) if “P” is true, and “T” (true) if “P” is false. Conjunction
(AND) The truth table for the conjunction of two propositions “P” and “Q” is given below:
P Q P ∧𝑄
T T T
T F F
F T F
F F F
The truth value of “P ∧ Q” is “T” (true) if and only if both “P” and “Q” are true.
Disjunction (OR) The truth table for the disjunction of two propositions “P” and “Q” is given
below:
P Q P ∨𝑄
T T T
T F T
F T T
F F F
The truth value of “P ∨ Q” is “T” (true) if either “P” or “Q” or both are true.
Implication (IF-THEN) The truth table for the implication of two propositions “P” and “Q” is
given below:
11
2 Propositional Logic
P Q P→𝑄
T T T
T F F
F T T
F F T
The truth value of “P → Q” is “T” (true) if either “P” is false or “Q” is true, or if both “P” and “Q”
are true.
Bi-Implication (IF AND ONLY IF) The truth table for the bi-implication of two propositions
“P” and “Q” is given below:
P Q P↔𝑄
T T T
T F F
F T F
F F T
The truth value of “P ↔ Q” is “T” (true) if both “P” and “Q” have the same truth value, and “F”
(false) if “P” and “Q” have different truth values.
Exclusive or (XOR) logical connective is a binary operator that evaluates to true if exactly
one of its operands is true and false otherwise. The symbol for XOR is typically written as ⊕.
The truth table for XOR is as follows:
P Q P ⊕𝑄
T T F
T F T
F T T
F F F
In the truth table, the result of P ⊕ Q is true if either P is true and Q is false, or if P is false and
Q is true. If both P and Q are either true or false, the result of P ⊕ Q is false.
In some applications, XOR is used as a means of detecting errors in digital data transmission,
since a change in the value of just one of the input propositions will result in a change in the
truth value of the XOR output. XOR is also used in cryptography and data compression, as well
as in the design of digital circuits and computer algorithms.
12
2 Propositional Logic
p q r p ∧𝑞 p ∧𝑞 → 𝑟
T T T T T
T T F T F
T F T F T
T F F F T
F T T F T
F T F F T
F F T F T
F F F F T
13
2 Propositional Logic
2. “You can borrow my car provided that you fill up the gas tank.” This can be translated
into a logical implication as: “If you fill up the gas tank, then you can borrow my car.”
3. “You can have the cake provided that you share with everyone else.” This can be translated
into a logical implication as: “If you share with everyone else, then you can have the
cake.”
Implication using the phrase “follows from”:
1. “The conclusion follows from the premises.” This can be translated into a logical implica-
tion as: “If the premises are true, then the conclusion is true.”
2. “It follows from the data that the hypothesis is correct.” This can be translated into a
logical implication as: “If the data is true, then the hypothesis is correct.”
3. “The result follows from the equation.” This can be translated into a logical implication
as: “If the equation is true, then the result is true.”
Here are examples of implication using the phrase “is necessary for”:
1. “Exercise is necessary for maintaining good health.” This can be translated into a logical
implication as: “If you want to maintain good health, then you must exercise.”
2. “Good sleep is necessary for being productive.” This can be translated into a logical
implication as: “If you want to be productive, then you must get good sleep.”
3. “Water is necessary for plants to grow.” This can be translated into a logical implication
as: “If you want the plants to grow, then you must provide water.”
Here are examples of implication using the phrase “a sufficient condition for”:
1. “A degree from a top university is a sufficient condition for getting a high-paying job.”
This can be translated into a logical implication as: “If you have a degree from a top
university, then you are guaranteed a high-paying job.”
2. “A good credit score is a sufficient condition for getting a loan.” This can be translated
into a logical implication as: “If you have a good credit score, then you are guaranteed a
loan.”
3. “A high IQ is a sufficient condition for being successful.” This can be translated into a
logical implication as: “If you have a high IQ, then you are guaranteed success.”
The phrase “a sufficient condition for Q is P” is commonly used in mathematical logic
and means that P (a certain condition or proposition) implies that Q (another condition or
proposition) is true. In other words, if P is true, then Q must also be true. This relationship can
be represented using the logical symbol “→”, where 𝑃 → 𝑄 means “if P, then Q”.
Here are some examples:
1. “A sufficient condition for winning the race is having the fastest time.” This means that if
a runner has the fastest time, then they must win the race.
14
2 Propositional Logic
2. “A sufficient condition for getting accepted into a college is having a high GPA.” This
means that if a student has a high GPA, then they will be accepted into the college.
3. “A sufficient condition for a circuit to work is having a complete circuit.” This means that
if a circuit is complete, then it must work.
Examples of bi-conditional statements:
1. If it rains, then the roads will be wet, and if the roads are wet, then it must have rained.
2. You can only enter the club if you are 21 years old or older, and if you are 21 years old or
older, then you can enter the club.
3. The game will start at 7 PM, and if the game starts at 7 PM, then it is 7 PM.
4. The lights will turn on if you switch the switch, and if the lights turn on, then you
switched the switch.
5. You pass the test if you score 80% or higher, and if you score 80% or higher, then you pass
the test.
6. 𝑥 is even ⇔ 𝑥 is divisible by 2
7. 𝑎 is a multiple of 𝑏 ⇔ 𝑏 is a factor of 𝑎
8. 𝑛 is prime ⇔ 𝑛 has exactly two distinct positive divisors
9. 𝑥 is positive ⇔ 𝑥 > 0
10. 𝑝 is a point on line 𝑙 ⇔ 𝑝 lies on 𝑙
11. If and only if it rains, the roads will be wet.
12. If and only if you are 21 years old or older, you can enter the club.
13. If and only if the game starts at 7 PM, it is 7 PM.
14. If and only if you switch the switch, the lights will turn on.
15. If and only if you score 80% or higher, you pass the test.
English examples of Exclusive OR (XOR) statements:
1. You can either take the train or the bus, but not both.
2. You are either a cat person or a dog person, but not both.
3. The game is either on Sunday or on Monday, but not both.
4. You can either have pizza or sushi for dinner, but not both.
5. You either have a red car or a blue car, but not both.
6. You can only play soccer or basketball, not both.
7. You must choose either apples or oranges, not both.
15
2 Propositional Logic
16
2 Propositional Logic
9. “If it is a weekday and I have work, then I will not attend the event.” - Truth Value:
Depends on weekday and work status
10. “I will go shopping if and only if there is a sale.” - Truth Value: Depends on sale
availability
11. “I will not go to the concert unless my favorite band is performing.” - Truth Value:
Depends on favorite band’s performance
12. “If the train is delayed, then I will miss my connecting flight.” - Truth Value: Depends
on train delay
13. “I will be happy only if it is a sunny day and I receive good news.” - Truth Value: Depends
on weather and news
14. “Either I will go for a hike, or I will stay at home and relax.” - Truth Value: Depends on
chosen activity
15. “If I finish my work early, then I will have time for a nap.” - Truth Value: Depends on
finishing work early
16. “I will join the gym, but only if they offer a student discount.” - Truth Value: Depends
on student discount
17. “I will not eat dessert unless it is chocolate.” - Truth Value: Depends on dessert type
18. “If I forget my umbrella, then I will get wet in the rain.” - Truth Value: Depends on
forgetting umbrella
19. “Either I will finish the project by tomorrow, or I will ask for an extension.” - Truth
Value: Depends on project completion
20. “I will attend the conference only if my colleague is also presenting.” - Truth Value:
Depends on colleague’s presentation
21. “If the traffic is heavy and I leave late, then I will be late for the meeting.” - Truth Value:
Depends on traffic and departure time
22. “I will take a vacation if and only if my boss approves the time off.” - Truth Value:
Depends on boss approval
23. “Either I will go to the museum, or I will visit the botanical garden.” - Truth Value:
Depends on chosen destination
24. “If I miss the bus, then I will take a taxi to reach the office on time.” - Truth Value:
Depends on missing the bus
25. “I will exercise regularly only if I see positive results.” - Truth Value: Depends on seeing
positive results
26. “If I forget to set an alarm, then I will oversleep.” - Truth Value: Depends on forgetting
to set an alarm
17
2 Propositional Logic
27. “Either I will buy a new car, or I will continue using public transportation.” - Truth
Value: Depends on car purchase decision
28. “I will not order dessert unless the restaurant has my favorite cheesecake.” - Truth Value:
Depends on cheesecake availability
29. “If I win the lottery, then I will travel around the world.” - Truth Value: Depends on
winning the lottery
30. “I will not attend the party unless my best friend is also invited.” - Truth Value: Depends
on best friend’s invitation
31. “If it snows heavily, then I will build a snowman.” - Truth Value: Depends on heavy
snowfall
32. “I will buy a house if and only if the interest rates are low.” - Truth Value: Depends on
interest rates
33. “Either I will go for a jog, or I will do yoga at home.” - Truth Value: Depends on chosen
activity
34. “I will not start a new project unless I finish my current tasks.” - Truth Value: Depends
on current task completion
35. “If it is a public holiday, then I will spend the day with family.” - Truth Value: Depends
on public holiday
36. “I will not eat fast food unless it is the only option available.” - Truth Value: Depends
on fast food availability
37. “If the concert tickets are sold out, then I will watch it online.” - Truth Value: Depends
on ticket availability
38. “Either I will cook dinner, or I will order takeout tonight.” - Truth Value: Depends on
chosen option
39. “I will buy a bicycle if and only if I move closer to my workplace.” - Truth Value: Depends
on moving closer
40. “If I miss the bus, then I will wait for the next one.” - Truth Value: Depends on missing
the bus
41. “I will not go to the party unless there is live music.” - Truth Value: Depends on live
music availability
42. “Either I will learn a new language, or I will take a photography course.” - Truth Value:
Depends on chosen learning path
43. “I will attend the workshop only if it covers advanced topics.” - Truth Value: Depends
on workshop content
44. “If it is a hot day, then I will go for a swim.” - Truth Value: Depends on hot weather
18
2 Propositional Logic
45. “I will not go on a road trip unless I have a reliable car.” - Truth Value: Depends on car
reliability
46. “If I forget my umbrella, then I will get wet in the rain.” - Truth Value: Depends on
forgetting the umbrella
47. “If it is a weekend, then I will go for a bike ride.” - Truth Value: Depends on whether
it’s a weekend
48. “I will only eat ice cream if it is a hot summer day.” - Truth Value: Depends on weather
conditions
49. “Either I will finish the novel, or I will start a new one.” - Truth Value: Depends on
reading choices
50. “If I miss the train, then I will take the bus to work.” - Truth Value: Depends on missing
the train
51. “I will attend the meeting only if it is necessary and beneficial.” - Truth Value: Depends
on necessity and benefits
52. “Either I will go to the theater, or I will watch a movie at home.” - Truth Value: Depends
on entertainment choice
53. “If it is a holiday and the weather is good, then I will have a barbecue.” - Truth Value:
Depends on holiday and weather
54. “I will buy a new phone if and only if it has both a good camera and ample storage.” -
Truth Value: Depends on camera quality and storage
55. “Either I will go on a road trip, or I will explore a new city.” - Truth Value: Depends on
travel preference
56. “If I receive a promotion, then I will celebrate with my colleagues.” - Truth Value:
Depends on receiving a promotion
57. “I will exercise regularly only if I can find a workout buddy.” - Truth Value: Depends on
finding a workout buddy
58. “Either I will take a nap, or I will drink a cup of coffee to stay awake.” - Truth Value:
Depends on energy level
59. “If I forget my umbrella, then I will borrow one from a friend.” - Truth Value: Depends
on forgetting the umbrella
60. “I will only go to the amusement park if the roller coaster is operational.” - Truth Value:
Depends on roller coaster status
61. “Either I will learn to play the guitar, or I will take piano lessons.” - Truth Value: Depends
on musical interest
19
2 Propositional Logic
62. “If it is a sale day and I have coupons, then I will go shopping.” - Truth Value: Depends
on sale and coupon availability
63. “I will not stay up late unless there is an important event.” - Truth Value: Depends on
the importance of the event
64. “If I forget to water the plants, then they will wither.” - Truth Value: Depends on
forgetting to water the plants
65. “I will buy a new laptop if and only if it meets both my performance and budget criteria.”
- Truth Value: Depends on laptop specifications and budget
66. “Either I will join a book club, or I will start my own reading group.” - Truth Value:
Depends on social preference
Truth Values:
• Scenario 1: It is raining (True), and I stay indoors (True) - Result: True
• Scenario 2: It is not raining (False), and I stay indoors (True) - Result: True
• Scenario 3: It is raining (True), but I do not stay indoors (False) - Result: False
• Scenario 4: It is not raining (False), and I do not stay indoors (False) - Result: True
2.5.2 Contrapositive:
¬𝑄 → ¬𝑃
Truth Values:
• Scenario 1: I don’t stay indoors (False), and it is not raining (False) - Result: True
• Scenario 2: I don’t stay indoors (False), and it is raining (True) - Result: False
• Scenario 3: I stay indoors (True), and it is not raining (False) - Result: True
• Scenario 4: I stay indoors (True), and it is raining (True) - Result: True
20
2 Propositional Logic
2.5.3 Converse:
𝑄 →𝑃
Truth Values:
• Scenario 1: I stay indoors (True), and it is raining (True) - Result: True
• Scenario 2: I stay indoors (True), and it is not raining (False) - Result: True
• Scenario 3: I don’t stay indoors (False), and it is raining (True) - Result: True
• Scenario 4: I don’t stay indoors (False), and it is not raining (False) - Result: True
2.5.4 Inverse:
¬𝑃 → ¬𝑄
Truth Values:
• Scenario 1: It is not raining (False), and I don’t stay indoors (False) - Result: True
• Scenario 2: It is raining (True), and I don’t stay indoors (False) - Result: False
• Scenario 3: It is not raining (False), and I stay indoors (True) - Result: True
• Scenario 4: It is raining (True), and I stay indoors (True) - Result: True
21
2 Propositional Logic
22
2 Propositional Logic
• Bitwise AND: The bitwise AND operation is represented by the symbol “&”. It takes
two binary numbers as operands and performs a logical AND operation on each pair of
corresponding bits. For example:
1010
&
0101
0000
• Bitwise OR: The bitwise OR operation is represented by the symbol “|”. It takes two binary
numbers as operands and performs a logical OR operation on each pair of corresponding
bits. For example:
1010 | 0101 = 1111
• Bitwise XOR: The bitwise XOR operation is represented by the symbol “∧ ”. It takes two
binary numbers as operands and performs a logical exclusive OR operation on each pair
of corresponding bits. For example:
1010 ∧ 0101 = 1111
• Bitwise NOT: The bitwise NOT operation is represented by the symbol “∼”. It takes a
single binary number as an operand and performs a logical NOT operation on each bit.
For example:
∼1010 = 0101
• Bitwise Left Shift: The bitwise left shift operation is represented by the symbol "«". It
takes a binary number and a shift count as operands and shifts the bits of the binary
number to the left by the specified number of positions. For example:
1010 « 2 = 101000
• Bitwise Right Shift: The bitwise right shift operation is represented by the symbol "»".
It takes a binary number and a shift count as operands and shifts the bits of the binary
number to the right by the specified number of positions. For example:
1010 » 2 = 0010
These bitwise operations are widely used in computer systems for various purposes, including
performing low-level operations on data, implementing efficient algorithms, and solving complex
problems in fields such as cryptography and data compression.
23
2 Propositional Logic
where r represents the proposition “it is raining” and w represents the proposition “the ground
is wet.” The biconditional symbol (↔) states that r and w are logically equivalent, meaning
they are both true or both false at the same time. Another example is: “If it is not raining, then
the ground is not wet.” This can be translated into propositional logic as:
¬𝑟 ↔ ¬𝑤
where ¬𝑟 represents the negation of the proposition “it is raining.” The implication symbol (↔)
states that if ¬𝑟 is true, then ¬𝑤 must also be true.
24
2 Propositional Logic
5. Replace propositions with propositional variables: Replace the propositions with the
assigned propositional variables. So the sentence becomes: 𝑞 → 𝑝
6. Simplify: No simplification is necessary in this case.
So the final translated propositional logic is: 𝑞 → 𝑝.
25
2 Propositional Logic
Logical equivalences, also known as logical identities or tautologies, are statements in propo-
sitional logic that are always true, regardless of the truth values of their constituent propositions.
In discrete mathematics, understanding these equivalences is essential for simplifying logical
expressions, making proofs, and solving problems. Here are some common logical equivalences
with explanations:
1. Double Negation:
¬(¬𝑃) ≡ 𝑃
This states that negating a proposition twice is equivalent to the original proposition.
2. Law of Contrapositive:
(𝑃 → 𝑄) ≡ (¬𝑄 → ¬𝑃)
If the implication "if P, then Q" is true, it is logically equivalent to its contrapositive.
3. De Morgan’s Laws:
These laws describe how negation distributes over conjunction (AND) and disjunction
(OR).
4. Idempotent Laws:
(𝑃 ∧ 𝑃) ≡ 𝑃
(𝑃 ∨ 𝑃) ≡ 𝑃
These laws state that repeating an operation on a proposition does not change its truth
value.
5. Commutative Laws:
(𝑃 ∧ 𝑄) ≡ (𝑄 ∧ 𝑃)
(𝑃 ∨ 𝑄) ≡ (𝑄 ∨ 𝑃)
These laws show that the order of conjunction and disjunction does not affect the result.
6. Associative Laws:
(𝑃 ∧ 𝑄) ∧ 𝑅 ≡ 𝑃 ∧ (𝑄 ∧ 𝑅)
(𝑃 ∨ 𝑄) ∨ 𝑅 ≡ 𝑃 ∨ (𝑄 ∨ 𝑅)
These laws indicate that grouping propositions with parentheses does not change the
outcome.
26
2 Propositional Logic
7. Distributive Laws:
𝑃 ∧ (𝑄 ∨ 𝑅) ≡ (𝑃 ∧ 𝑄) ∨ (𝑃 ∧ 𝑅)
𝑃 ∨ (𝑄 ∧ 𝑅) ≡ (𝑃 ∨ 𝑄) ∧ (𝑃 ∨ 𝑅)
These laws describe how conjunction and disjunction distribute over each other.
8. Absorption Laws:
𝑃 ∨ (𝑃 ∧ 𝑄) ≡ 𝑃
𝑃 ∧ (𝑃 ∨ 𝑄) ≡ 𝑃
These laws illustrate how a proposition combined with its own conjunction or disjunction
simplifies.
9. Identity Laws:
𝑃 ∧T≡𝑃
𝑃 ∨F≡𝑃
These laws show that combining a proposition with a tautology (T) or a contradiction (F)
does not change the proposition.
10. Implication Laws:
𝑃 → 𝑄 ≡ ¬𝑃 ∨ 𝑄
𝑃 → 𝑄 ≡ ¬(𝑃 ∧ ¬𝑄)
Exercises
Exercise 1: Simplify the expression (𝑃 ∧ ¬𝑄) ∨ (¬𝑃 ∧ 𝑄).
Solution 1: Using the Commutative Law for Disjunction:
27
2 Propositional Logic
28
2 Propositional Logic
(𝑃 ∧ 𝑄) ∨ (¬𝑃 ∧ 𝑄) ≡ (𝑄 ∧ 𝑃) ∨ (𝑄 ∧ ¬𝑃)
≡ (𝑃 ∧ 𝑄) ∨ (𝑄 ∧ ¬𝑃)
29