cse 240 logic and discrete mathematicsbaruah/... · extensible networking platform 9 9 - cse 240...

27
Extensible Networking Platform 1 1 - CSE 240 – Logic and Discrete Mathematics CSE 240 Logic and Discrete Mathematics Instructor: Todd Sproull Department of Computer Science and Engineering Washington University in St. Louis

Upload: others

Post on 26-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 1 1 - CSE 240 – Logic and Discrete Mathematics

CSE240LogicandDiscreteMathematics

Instructor:ToddSproull

DepartmentofComputerScienceandEngineeringWashingtonUniversityinSt.Louis

Page 2: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 2 2 - CSE 240 – Logic and Discrete Mathematics

Implications

•  Denotedbythesymbol→–  p→qcorrespondsto“Ifp,thenq”or“pimpliesq”or“qwheneverp”

•  Example–  IfIworkhardinthisclass,thenIwillearnanAinCSE240–  IftodayisFriday,then2+3=5(TrueorFalse?Why?)–  IftodayisFriday,then2+3=6(TrueorFalse?Why)

•  TruthTableforimplications

p q p→ q

TTFF

TFTF

TFTT

Page 3: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 3 3 - CSE 240 – Logic and Discrete Mathematics

Truthtableforpq

p q p→ q

TTFF

TFTF

TFTT

Page 4: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 4 4 - CSE 240 – Logic and Discrete Mathematics

Moreaboutp→ q

•  DifferentEnglishrepresentationsof→ pimpliesqqwheneverp

•  xisodd→x+1iseven–  Ifxisodd,itistrue–  IfxisNOTodd,thewholestatementistrue

•  PropositionscanonlybeTrueorFalse– Noundefined

p q p→ q

TTFF

TFTF

TFTT

Page 5: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 5 5 - CSE 240 – Logic and Discrete Mathematics

LogicalEquivalence

•  Denotedbythesymbolp¬¬pcorrespondsto“ pislogicallyequivalenttoNOTNOTp“

•  Consider¬pvq?p→q–  Aretheylogicallyequivalent?–  Howcanweprovethat?

p q ¬p ¬p v q p→ q

TTFF

TFTF

FFTT

TFTT

TFTT

≡≡

p q ¬p ¬p v q p→ q

TTFF

TFTF

p q ¬p ¬p v q p→ q

TTFF

TFTF

FFTT

p q ¬p ¬p v q p→ q

TTFF

TFTF

FFTT

TFTT

Page 6: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 6 6 - CSE 240 – Logic and Discrete Mathematics

Converse,Contrapositive,andInverse

•  Formedasvariantsoftheconditionalstatementp→q

•  Converse–  q→p

•  Contrapositive–  ¬q→¬p

•  Inverse–  ¬p→¬q

•  Examples

–  Considertheconditionalstatement•  “TheSt.LouisCardinalswinwheneveritisraining”

–  qwheneverp•  “Ifitisraining,thentheCardinalswin”

–  ifp,thenq

–  Converse•  IftheCardinalswin,thenitisraining

–  Contrapositive•  IftheCardinalsdonotwin,thenitisnotraining

–  Inverse•  Ifitisnotraining,thentheCardinalsdonotwin

Page 7: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 7 7 - CSE 240 – Logic and Discrete Mathematics

BiconditionalStatement

•  Denotedbythesymbol•  pqcorrespondsto“pifandonlyifq”

–  or“pisnecessaryandsufficientforq”–  or“piffq”

•  pqistrueonlywhenpandqhavethesametruthvalues

•  Example–  Youcantaketheflightifandonlyifyoubuyaticket

•  TruthTableforbiconditionalstatement

↔↔

p q p q

TTFF

TFTF

TFFT

Page 8: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 8 8 - CSE 240 – Logic and Discrete Mathematics

CompoundPropositions

•  Weareabletocombinemultiplepropositionstogethertobuildmorecomplicatedpropositions

•  Constructatruthtableforthefollowingproposition–  (p∧ q) → (¬p∨q)

p q ¬p p∧ q ¬p∨q (p ∧ q) → (¬p∨q)

TTFF

TFTF

T

T F

T T

T T

T T T T

F F F

F

F

Page 9: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics

LogicandBitOperations

•  Computersrepresentinformationusingbits–  Abitisasymbolwithvalues0and1

•  BooleanVariablesusevaluesofTrueorFalse–  Booleanvariablescanberepresentedwithabit

•  LogicaloperationscanbeperformedbyreplacingTandFwith1and0–  Substitute∧ ,∨, and with AND, OR, and XOR –  Example0OR1=1

•  BitStringsareasequenceof0ormorebits–  lengthisstringisthenumberofbits

•  Abletoperformbitwiseoperationsonbitstrings

•  Example111000101001111001BitwiseORBitwiseANDBitwiseXOR

TruthValue

Bit

TF

10

111 11 1101

110 11 1100001 00 0001

Ineedsomehelpwithmymath

Page 10: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 10 10 - CSE 240 – Logic and Discrete Mathematics

PropositionalLogic

•  Proofsinvolvesteppingthroughamathematicalargument

•  PropositionalLogicprovidessuchsteps

•  Todaywewilldiscusstheprocessofmovingfromonepropositiontothenexttoformamathematicalargument

Page 11: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 11 11 - CSE 240 – Logic and Discrete Mathematics

•  Challenge:Trytofindapropositionthatisequivalenttop→ q,butthatusesonlytheconnectives¬,∧,and∨

p q p→ q

TTFF

TFTF

TFTT

p q ¬p ¬pvq

TTFF

TFTF

FFTT

TFTT

LogicalEquivalence

•  p→ qislogicallyequivalentto¬p∨q•  orp→ q≡¬p∨ q

Page 12: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 12 12 - CSE 240 – Logic and Discrete Mathematics

•  Contrapositives:p→qand¬q→¬pEx. “Ifitisnoon,thenIamhungry.” “IfIamnothungry,thenitisnotnoon.”

•  Converses:p→qandq→p

Ex.“Ifitisnoon,thenIamhungry.” “IfIamhungry,thenitisnoon.”

•  Inverses:p→qand¬p→¬q

Ex.“Ifitisnoon,thenIamhungry.” “Ifitisnotnoon,thenIamnothungry.”

Aretheseequivalent?

Let’stakeavote

Page 13: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 13 13 - CSE 240 – Logic and Discrete Mathematics

•  Contrapositives:p→q≡¬q→¬p?Ex. “Ifitisnoon,thenIamhungry.” “IfIamnothungry,thenitisnotnoon.”

•  Converses:p→q≡q→p?

Ex.“Ifitisnoon,thenIamhungry.” “IfIamhungry,thenitisnoon.

•  Inverses:p→q≡¬p→¬q?

Ex.“Ifitisnoon,thenIamhungry.” “Ifitisnotnoon,thenIamnothungry.”

YES

NO

NO

Aretheseequivalent?

Page 14: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 14 14 - CSE 240 – Logic and Discrete Mathematics

Atautologyisapropositionthat’salwaysTRUE. Acontradictionisapropositionthat’salwaysFALSE.

p ¬p p ∨ ¬p p ∧ ¬p

T F F T

T T

F F

Definitions

Page 15: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 15 15 - CSE 240 – Logic and Discrete Mathematics

•  Identity•  Domination

•  Idempotent

p ∧ T ≡ pp ∨ F ≡ p

p ∨ T ≡ Tp ∧ F ≡ F

p ∨ p ≡ pp ∧ p ≡ p

p T p ∧ T

T T T F T F

LogicalEquivalences

Page 16: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 16 16 - CSE 240 – Logic and Discrete Mathematics

•  ExcludedMiddle

•  Uniqueness•  Doublenegation

p ∨ ¬p ≡ T

¬(¬p) ≡ p

p ∧ ¬p ≡ F

LogicalEquivalencesContinued

Page 17: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 17 17 - CSE 240 – Logic and Discrete Mathematics

•  Commutativity

•  Associativity•  Distributivity

p ∨ q ≡

(p ∨ q) ∨ r ≡

p ∧ q ≡q ∨ p q ∧ p

(p ∧ q) ∧ r ≡p ∨ (q ∨ r) p ∧ (q ∧ r)

p ∨ (q ∧ r) ≡ p ∧ (q ∨ r) ≡

(p ∨ q) ∧ (p ∨ r) (p ∧ q) ∨ (p ∧ r)

LogicalEquivalencesContinued

Page 18: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 18 18 - CSE 240 – Logic and Discrete Mathematics

p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r)

p q r q ∧ r p ∨ (q ∧ r) p ∨ q p ∨ r (p ∨ q) ∧ (p ∨ r)

T T T T T T T T

T T F F T T T T

T F T F T T T T

T F F F T T T T

F T T T T T T T

F T F F F T F F

F F T F F F T F

F F F F F F F F

ProofofDistributivity

Page 19: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 19 19 - CSE 240 – Logic and Discrete Mathematics

•  DeMorgan’sI

•  DeMorgan’sII

¬(p ∨ q) ≡ ¬p ∧ ¬q

¬(p ∧ q) ≡ ¬p ∨ ¬q

DeMorgan’s

Page 20: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 20 20 - CSE 240 – Logic and Discrete Mathematics

ExampleofDeMorgan’s

p q

¬(p ∨ q) ≡ ¬p ∧ ¬q¬(p ∧ q) ≡ ¬p ∨ ¬q

Page 21: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 21 21 - CSE 240 – Logic and Discrete Mathematics

•  DeMorgan’sII

¬(p ∧ q) ≡ ¬p ∨ ¬q

¬(p ∧ q) ≡ ¬(¬¬p ∧ ¬¬q) Doublenegation

≡ ¬¬(¬p ∨ ¬q) DeMorgan’s I

≡ (¬p ∨ ¬q) Doublenegation

DeMorgan’sContinued

Page 22: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 22 22 - CSE 240 – Logic and Discrete Mathematics

¬(p ∧ ¬q) ∨ q ≡ ¬p ∨ q

if NOT (blue AND NOT red) OR red then…

¬(p ∧ ¬q) ∨ q (¬p ∨ ¬¬q) ∨ q

(¬p ∨ q) ∨ q

¬p ∨ (q ∨ q)

¬p ∨ q

DeMorgan’sII

Doublenegation

Associativity

Idempotent

Proofequivalence

Page 23: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 23 23 - CSE 240 – Logic and Discrete Mathematics

Showthat[p∧(p→q)]→qisatautologyWeuse≡toshowthat[p∧(p→q)]→q≡T

substitution for → [p ∧ (p → q)] → q

distributiveuniquenessidentitysubstitution for →De Morgan’s IIassociativeexcluded middledomination

AnotherExample

≡ [p ∧ (¬p ∨ q)] → q ≡ [(p ∧ ¬p) ∨ (p ∧ q)] → q ≡ [ F ∨ (p ∧ q)] → q ≡ (p ∧ q) → q ≡ ¬(p ∧ q) ∨ q ≡ (¬p ∨ ¬q) ∨ q ≡ ¬p ∨ (¬q ∨ q )≡ ¬p ∨ T≡ T

Page 24: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 24 24 - CSE 240 – Logic and Discrete Mathematics

AnotherExample

•  Considerthenewspaperheadline:“LegislatureFailstoOverrideGovernor’sVetoofBilltoCancelSalesTaxReform”

Didthelegislaturevoteinfavoroforagainstthesalestaxreform?

Page 25: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 25 25 - CSE 240 – Logic and Discrete Mathematics

AnotherExample

•  Considerthenewspaperheadline:“LegislatureFailstoOverrideGovernor’sVetoofBilltoCancelSalesTaxReform”

Didthelegislaturevoteinfavoroforagainstthesalestaxreform?

A)ThelegislatureDIDvoteinfavorB)ThelegislatureDIDNOTvoteinfavor

Let’stakeavote

Page 26: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 26 26 - CSE 240 – Logic and Discrete Mathematics

AnotherExample•  Considerthenewspaperheadline:“LegislatureFailstoOverrideGovernor’sVetoofBilltoCancelSalesTaxReform”Didthelegislaturevoteinfavoroforagainstthesalestaxreform?Letsstandfor“salestaxreform”Unraveloneatatime.

-Thebilltocancelsalestaxreformis¬s-Thegovernorsvetoofthebillis¬¬s-Overridingthismeans¬¬¬s-Thedoublenegationcancelout,leavingjust¬sThereforethelegislaturedoesnotsupportsalestaxreform.Hevotedinfavorof

thebill(tocancelit).

Page 27: CSE 240 Logic and Discrete Mathematicsbaruah/... · Extensible Networking Platform 9 9 - CSE 240 – Logic and Discrete Mathematics Logic and Bit Operations • Computers represent

Extensible Networking Platform 27 27 - CSE 240 – Logic and Discrete Mathematics

GroupExercise

•  Breakupintogroupsof2or3people

•  Solvethefollowingproblem:

•  ProveDeMorgan’sILawbymanipulatingsymbols(notatruthtable)

•  Hint-SimilartotheproofofDeMorgan’sIILaw

•  Reminder–  DeMorgan’sII

¬(p ∨ q) ≡ ¬p ∧ ¬q

¬(p ∧ q) ≡ ¬p ∨ ¬q