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

Module 2 Class Presentation CS5002

CS5002 module2

Uploaded by

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

Module 2 Class Presentation CS5002

CS5002 module2

Uploaded by

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

CS 5002

Discrete Structures

Class Presentation for Week 2


Align MS in Computer Science

Prof. Steve Shafer [email protected]


Today In Class
• I’m going to start the Teams meeting and hit Record

• Please put away / silence your phone, and have only GoogleDoc, this Powerpoint,
and/or Teams running on your laptop
• Be sure your name card is in place (your instructor will always be fooled)

• We will create a GoogleDoc each day in class. Today’s GoogleDoc Link:


https://docs.google.com/document/d/1yH5lQdr0Xk8BcENXY5VC1fw97hg090RvDf
u0AuX1TJI/edit?usp=sharing

• When you’re ready, give me a “thumbs-up”


• When everyone is ready, we’ll start the class session!
Meet Esther Chen
Some very important questions for you:

What do you want us to call you?

What country and city are you from?

What did you do before starting the MS program here?

What is your favorite food?


New Policy In CS 5002
• Minimum score of 12 out of 20 on any Problem you hand in your work for

• If you can’t figure out an answer, just present some of your work on that
problem

• If you mess up one problem you can still get 92 out of 100
• If you mess up all the Individual problems you can still get 76 out of 100

• So you can spend your time and energy better than getting stuck on a
problem
Some Tricks For Understanding New
Stuff
Try looking at specific examples that are easy to understand
not (P or Q) = (not P) and (not Q)
• This is one of DeMorgan’s laws

Maybe draw a picture to visualize the result


P xor Q = (P or Q) AND [(not P) or (not Q)]
Activities You Did Before Class
• Over this week you should have done Problem Set 1
• The first problems were to do yourself
• Then were problems for your group from Day 1 by meeting with them
• Problem Set 1 was due at the start of class

• Then, following the Study Guide 2, you had some stuff to study
• And then you should have done your Quiz 2 yourself
• Quiz 2 was due at the start of class
Review of Problem Set 1
• IP Address
• Overflow
• Weights
• Day of week
• Nim
IP Address
• Simply convert between binary, decimal, and hex

• 32 bits allows 22 x 230 values = 4 x 1,000,000,000 = 4 billion


• If there are 4.5 billion users of the Internet then you need more than 32 bits
• By the way, 32 bits is actually IP version 4 (IPv4)
• In IPv6 there are 128 bits!
• The world has been very slow to convert from IPv4 to IPv6
Overflow
• Computations are straightforward after conversion

• In Overflow, the sign bits of both operands are the same but the result has a
different value

• If both sign bits are the same, then no overflow is possible


• 1 <= x <= 127, and -128 <= y <= -1
• So -127 <= x + y <= 126, no overflow
Weights
• With 1 2 4 8 16 32 just take the binary value of N and put the weights on the
scale (on the other side) that correspond to the 1s in N

• With 1 3 9 27 you have to think of things in base 3


• Each weight can be on the same side as the object, off the scale, or opposite side
• By arranging the weights we are assigning -1, 0, or +1 to the contribution of that
weight
• Possible values are {-1,0,1}x1 + {-1,0,1}x3 + {-1,0,1}x9 + {-1,0,1}x27 = -40 to 40

• With three weights there are 27 possible combinations so you can’t measure
all values of N from 1 to 40
Day of Week
• Compute difference in # days from what you know (January 1, 2023 = Sunday)
• Take the difference mod-7, that tells how many days past Sunday

• You know the number in each month, so within the year you can add up the
number of days in the intervening months

• For years, remember each year is 365 days; 365 mod 7 is 1


• Remember to add leap years every fourth year

• The rest is just doing the calculation


Nim
• Nim can be analyzed mathematically, see
https://web.mit.edu/sp.268/www/nim.pdf

• If the Nim Sum is 0 at the end of your turn you won or can force a win

• If the Nim Sum is 0 at the start of your turn you have to change it to non-0
• If the Nim Sum is not 0 at the start of your turn you can win by changing it to 0
• Pick a pile with a 1 in the same bit that the Nim Sum has its leftmost 1
• Remove stones to make that pile equal to (current Nim Sum) XOR (current pile value)
Quiz 2 In Groups
• Do you have any questions about the study materials and Quiz 2?
• How useful were the additional links?
• Now let’s arrange into groups and each group do the same Quiz 2
• Put your answers into today’s GoogleDoc
• Today’s Groups:

Group 1 Group 2 Group 3

Dora Jingjing PandaBro


Ziqun Vivian Jeff
Miranda Anindo Elisa
Naren Wing Timmons
Esther
Ambiguous Sentences
• Example of an ambiguous sentence in English
• Can we get an example of an ambiguous sentence not in English?
• Ambiguity can be based on pronunciation, not just meaning:
The Most Famous Ambiguous Sentence
in English
• Time flies.

• Time flies like an arrow.

• Time flies like an arrow, but fruit flies like a banana.


Question 2
The simplest solution has just three logical operators:

not (A and B) and C

not [(A and B) or (not C)]


= not (A and B) and C by DeMorgan’s Law
Question 3
Find all expressions logically equivalent to

Which of these expressions are identical to the one above?


1. (B ∧ M) ∨ (D ∧ M) ∨ (B ∧ D)
2. (B ∧ M) ∧ (D ∧ M) ∧ (B ∧ D) ∧ (B ∧ D ∧ M)
3. (B ∧ M) ∨ (D ∧ M) ∨ (B ∧ D) ∨ (B ∧ D ∧ M)
4. (B ∧ M ∧ ¬D) ∨ (D ∧ M ∧ ¬B) ∨ (B ∧ D ∧ ¬M) ∨ (B ∧ D ∧ M)
5. (B ∧ M ∧ ¬D) ∨ (D ∧ M ∧ ¬B) ∨ (B ∧ D ∧ ¬M)
6. (¬B ∨ D ∨ M) ∧ (¬D ∨ B ∨ M) ∧ (¬M ∨ B ∨ D)

The answer is: THREE


Question 4
Are these equivalent?
B  [(not A) and C] (not B) or not [A or (not C)]

B  [(not A) and C]
= not {B and not [(not A) and C]} definition of 
= (not B) or [(not A) and C] DeMorgan’s Law
= (not B) or not [A or (not C)] DeMorgan’s Law again

Yes, they are equivalent


Question 5
Anson says, "Bo and Cathy are both Truthies".
Bo says, "Anson is a Falsie and Cathy is a Truthie".
Anson Bo Cathy Would Anson say that? Would Bo say that?
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F

What do you conclude?


Symbolic Logic
https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematic
s/Applied_Discrete_Structures_(Doerr_and_Levasseur)/03%3A_Logic/3.04%3A_Th
e_Laws_of_Logic
Statements And Predicates
• A statement is a specific assertion that may be True or False
• p = “The house at 1234 5th Avenue is painted black”
• q = “1 + 1 = 2”
• We use lower-case letters for statements, especially p, q, r

• A predicate is an expression with one or more variables (parameters)


• It’s a function of those parameters, whose value depends on the parameter value
• P(x) = “The house x is painted black”
• P(y) = “1 + y = 2”
• P(x,y) = “The house x is painted y”
• We use upper-case letters for predicates, especially P, Q, R
• This can get confusing: P(p) so we might say instead F(p)
Logic Operators
• Not, And, Or
• Exclusive Or (a.k.a. XOR)
• Implies (a.k.a. Conditional, or If/Then, or )
• Equivalence (a.k.a. If and Only If, or Iff, or =, or )
p q not p p and q p or q p xor q p  q p=q
T T F T T F T T
T F F F T T F F
F T T F T T T F
F F T F F F T T
Quantifiers
• The basic operators are for statements; the quantifiers are for predicates

• FOR ALL x means that no matter what value x has, the following is true
• x P(x) means “for all possible values of x, P of x is true”
• x: x = x is the basic identity law
• p: (p or not p) = True

• THERE EXISTS x means that somewhere there is an x that makes this true
• x P(x) means “there is at least one value of x that makes P of x true”
• x: x has four legs probably not me or you, but something somewhere
Substitution Rule
p = q means that wherever you see p, you can p q p=q
replace it with q T T T
T F F
In symbols: F T F
p = q  F: F(p) = F(q) F F T
(p = q) = F: F(p) = F(q)
“p equals q means that for all predicates F, F of p has the same value as F of q”

Therefore, if p = q then we can substitute q wherever we see p


Basic Operators Are And, Or, Not
p q not p p and q p or q p xor q pq p=q
T T F T T F T T
T F F F T T F F
F T T F T T T F
F F T F F F T T

p xor q = (p or q) and not (p and q)


pq = not [p and (not q)]
p=q = (p and q) or [(not p) and (not q)]
Some Basic Laws
p not P not not p p and p p or p p and not p p or not p
T F T T T F T
F T F F F F T

Involution
not (not p) = p
Idempotent
(p and p) = p (p or p) = p
Negation
[p and (not p)] = F [p or (not p)] = T
More Basic Laws
p not P p and T p or F p and F p or T
T F T T F T
F T F F F T

Identity
(p and T) = p (p or F) = p
Null
(p and F) = F (p or T) = T
Almost As Basic Laws
Commutative
change order (p and q) = (q and p) (p or q) = (q or p)

Associative
reorder () [(p and q) and r] = [p and (q and r)]
[(p or q) or r] = [p or (q or r)]

Distributive
split into cases [p and (q or r)] = [(p and q) or (p and r)]
[p or (q and r)] = [(p or q) and (p or r)]
Example of Truth Table for Distributive
Lawp q r q or r p and p and q p and r (p and q) or
(q or r) (p and r)
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F

[p and (q or r)] = [(p and q) or (p and r)]


Absorption is a Little Bit More
Complicated
p and (p or q)
if p is T: p is T and (p or q) = (T or q) = T so the result is T
if p is F: p is F and (F and anything) = F so the result is F
No matter what p is, the result is the same as p
p q p and q p or q p and p or
p and (p or q) = p (p or q) (p and q)
T T
p or (p and q) = p T F
F T
F F
DeMorgan’s Laws
Convert between and and or

not (p and q) = (not p) or (not q)


In other words, if p and q are not both true, then one or the other must be false

not (p or q) = (not p) and (not q)


In other words, if neither p nor q is true, then they must both be false

Practically speaking: You can replace “and” with “or” (or “or” with “and”) by
negating the whole thing, and negating each of the operands
DeMorgan’s Laws By Truth Table
not (p and q) = (not p) or (not q)

p q p and q not not p not q (not p)


(p and q) or
(not q)
T T
T F
F T
F F
DeMorgan’s Laws – Steve’s Way
(p and q) = not [ (not p) or (not q) ]
In other words, if both p and q are true, then neither p nor q is false

(p or q) = not [ (not p) and (not q)]


In other words, if either p or q is true, then they can’t both be false

I like this “positive” way of stating the laws because it is easier to substitute:
To change and to or:
Negate each of the parts
Then negate the whole thing
Lukasiewicz Notation (loo-kass-ee-
vitch)
Use upper-case letters for the operators:
not = N and = K or = A =C ==E xor = X

Now put the operator before the operands (“prefix notation”)


p or q becomes Apq
p and not q becomes KpNq
pq becomes Cpq which is also NKpNq
p xor q becomes Xpq which is also KApqNKpq
Commutative Law (p and q) = (q and p) Kpq = Kqp EKpqKqp
Distributive Law E KpAqr AKpqKpr
DeMorgan’s Law E NKpq ANpNq or E Kpq NANpNq
Implications
Detachment (modus ponens) [(p  q) and p]  q
Indirect Reasoning (modus tollens) [(p  q) and (not q)]  not p
Disjunctive Addition p  (p and q)
Conjunctive Simplification (p and q)  p
Disjunctive Simplification [(p or q) and (not p)]  q
Chain Rule [(p  q) and (q  r)]  (p  r)
Conditional Equivalence (p  q) = [(not p) or q]
Biconditional Equivalence (p = q) = [(p  q) and (q  p)]
Contrapositive (p  q) = [(not q)  (not p)]
ECpqCNqNp
Example of Proving Conjunctive
Simplification
(p and q)  p
We will use the definition of : p  q = not [p and (not q)]

(p and q)  p
= not [(p and q) and (not p) by definition of 
= [not (p and q)] or p by DeMorgan’s Law
= (not p) or (not q) or p by DeMorgan’s Law
= p or (not p) or (not q) by Commutative Law
= T or (not q) by Negation Law
=T by Null Law
So the original statement is always true. This is called a Tautology
Example of Proving Detachment (Modus
Ponens)
[(p  q) and p]  q
We will use the definition of : p  q = not [p and (not q)]

[(p  q) and p]  q
= not {[(p  q) and p] and (not q)} by definition of 
= not [(p  q) and p] or q by DeMorgan’s Law
= [not (p  q)] or (not p) or q by DeMorgan’s Law
= [p and (not q)] or (not p) or q by definition of 
= [p or (not p) or q] and [(not q) or (not p) or q] by Distributive Law
= (T or q) and [T or (not p)]
= T and T = T so the original statement above is a Tautology
Disjunctive Normal Form
• You can rewrite any logical expression as the OR of a bunch of AND statements
• This is called Disjunctive Normal Form (DNF)

• An example of DNF: (p and q) or (q and r) or [r and (not p)]

• We can go from the truth table directly to DNF using the Ts:
p q s
T T T
s= (p and q) or [(not p) and (not q)]
T F F
F T F
this is DNF
F F T
Conjunctive Normal Form
• You can rewrite any logical expression as the AND of a bunch of OR statements
• This is called Conjunctive Normal Form (CNF)

• An example of CNF: (p or q) and (q or r) and [r or (not p)]


• We can go from the truth table directly to CNF using the Fs:

p q s
(not s) = [p and (not q)] or [(not p) and q]
T T T
T F F s = not {[p and (not q)] or [(not p) and q]}
F T F s = {not [p and (not q)]} and {not [(not p) and q]}
F F T s = [(not p) or q] and [p or (not q)] is CNF
Logic Circuit Diagrams
• Gates are bits of circuit that implement logical operations on signals
• Electrical Engineers have standard symbols for gates
Handout on Symbolic Logic
You will find all of these laws on this handout for class, in Canvas Module 2:

Module 2 Rules of Symbolic Logic.pdf

You can use this to aid with Problem Set 2


Do We Want To Do Another Group
Activity?
More on logic puzzles at https://philosophy.hku.hk/think/logic/knights.php
(this is puzzle #102)

A very special island is inhabited only by knights and knaves. Knights always
tell the truth, and knaves always lie.
You meet four inhabitants: Bart, Dave, Rex and Zoey. Bart tells you that Rex
and Dave are both knights or both knaves. Dave tells you that Zoey is a knave.
Rex claims, “Bart is a knave.” Zoey claims, “Rex is a knight and Dave is a
knave.”
Can you determine who is a knight and who is a knave?
A Sneaky Way To Solve This Puzzle
• Notice that Bart and Zoey contradict each other, so both cannot be Truthies.
• Bart says that Rex and Dave are both Truthies or both Falsies
• Zoey claims “Rex is a Truthie and Dave is a Falsie”

• Suppose Bart is a Truthie. Then Zoey must be a Falsie.


• Dave said Zoey is a Falsie, so Dave must be a Truthie.
• Rex said Bart is a Falsie, so Rex must be a Falsie.
• Then Bart was wrong, so this is a contradiction!

• Then suppose Bart is a Falsie and Zoey is a Truthie.


• Dave told a lie (Falsie) and Rex told the truth (Truthie)
• So Bart did indeed lie, and Zoey did tell the truth.
• It all works! Rex and Zoey are Truthies, and Bart and Dave are Falsies.
Questions About This Class Presentation

• Was this presentation about symbolic logic useful?


• It seems maybe a repeat of what you studied this past week

• Should we continue to go back and forth between Powerpoint for lecture


and Googledoc for group activities?
• I could prepare everything in the Googledoc instead
Your Homework This Week
• Problem Set 2 is based on today’s class; due in Canvas before next class

• Study Guide 3 is what you need to learn for the next class
• Quiz 3 is based on the study materials; due in Canvas before next class

You might also like