discrete mathematics for computer science prof. raissa...

45
B P M /92 Module #1 - Logic B P M /92 Module #1 - Logic UC Davis ECS20, Winter 2017 Discrete Mathematics for Computer Science Prof. Raissa D’Souza (slides adopted from Michael Frank and Haluk Bingöl)

Upload: others

Post on 22-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

UCDavisECS20,Winter2017DiscreteMathematicsforComputerScience

Prof.RaissaD’Souza(slidesadoptedfromMichaelFrankandHalukBingöl)

Page 2: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Calculusisforcontinuoussystems • Calculusf(x)versusx,considersacon/nuousvariablex.•  Con/nuousnumbers:xisanumberwhichcanhaveanynumberofdecimalplaces,•  E.g.3.1415•  Transcendentalnumbers:pi=3.1415926…..

Page 3: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Examplesofdiscretesystems?• Discrete=consis2ngdis2nctorindividualunits;o:encomesinintegerquan22es.

•  .….•  ……•  …..

Page 4: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

2

What is Mathematics,

really?

• It’s not just about numbers!

• Mathematics is much more than that:

• But, these concepts can be about numbers, symbols,

objects, images, sounds, anything!

Mathematics is, most generally, the study of any and all absolutely certain truths about

any and all perfectly well-defined concepts.

Page 5: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

5

So, what’s this class

about?

What are “discrete structures” anyway?

• “Discrete” (≠ “discreet”!) - Composed of distinct,

separable parts. (Opposite of continuous.)

discrete:continuous :: digital:analog

• “Structures” - Objects built up from simpler objects

according to some definite pattern.

• “Discrete Mathematics” - The study of discrete,

mathematical objects and structures.

Page 6: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

6

Discrete Structures

We’ll Study• Propositions

• Predicates

• Proofs

• Sets

• Functions

• Orders of Growth

• Algorithms

• Integers

• Summations

• Sequences

• Strings

• Permutations

• Combinations

• Relations

• Graphs

• Trees

• Logic Circuits

• Automata

Page 7: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Exampleproblems• Given8leIers,howmanypossiblepasswords?•  Encryp/on(mappingonesymboltoanother)•  Sor/ngalist• Howlikelyisyourpokerhand?

Page 8: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

7

Some Notations We’ll

Learn

9

Uses for Discrete Math in Computer

Science

• Advanced algorithms & data structures

• Programming language compilers & interpreters.

• Computer networks

• Operating systems

• Computer architecture

• Database management

systems

• Cryptography

• Error correction codes

• Graphics & animation

algorithms, game

engines, etc.…

• I.e., the whole field!

Page 9: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

12

Course Objectives

• Upon completion of this course, the student should be able to:

• Check validity of simple logical arguments (proofs).

• Check the correctness of simple algorithms.

• Creatively construct simple instances of valid logical arguments and correct algorithms.

• Describe the definitions and properties of a variety of specific types of discrete structures.

• Correctly read, represent and analyze various types of discrete structures using standard notations.

Think!

Page 10: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Module#1:FoundationsofLogic(§§1.1-1.3,~3lectures)• Mathema2calLogicisatoolforworkingwithelaboratecompoundstatements.

•  Itincludes:• Aformallanguageforexpressingthem.• Aconcisenota/onforwri/ngthem.• Amethodologyforobjec/velyreasoningabouttheirtruthorfalsity.

• Itisthefounda/onforexpressingformalproofsinallbranchesofmathema/cs.

Page 11: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Examples:Englishisambiguous

• Areyounotgoingtothepartytonight?•  Youmustbeatleast5feettallorovertheageof14toridetherollercoaster.

•  Thelawniswet,soeitheritrainedlastnightorthesprinklerswentonthismorning,butnotbothhappened.

Page 12: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

FoundationsofLogic:Overview•  Proposi/onallogic(§1.1-1.2):

–  Basicdefini/ons.(§1.1)–  Equivalencerules&deriva/ons.(§1.2)

•  Predicatelogic(§1.3-1.4)–  Predicates.–  Quan/fiedpredicateexpressions.–  Equivalences&deriva/ons.

Page 13: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

PropositionalLogic(§1.1)• Proposi2onalLogicisthelogicofcompoundstatementsbuiltfromsimplerstatementsusingso-calledBooleanconnec2ves.

• Someapplica/onsincomputerscience• Designofdigitalelectroniccircuits.• Expressingcondi/onsinprograms.• Queriestodatabases&searchengines.

Topic #1 – Propositional Logic

George Boole (1815-1864)

Chrysippus of Soli (ca. 281 B.C. – 205 B.C.)

Page 14: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

DeYinitionofaProposition• Defini&on:Aproposi2on(denotedp,q,r,…)issimply:• Adeclara2vestatementwithsomedefinitemeaning,(notvagueorambiguous)

• havingatruthvaluethatiseithertrue(T)orfalse(F)•  itisneverboth,neither,orsomewhere“inbetween”

•  However,youmightnotknowtheactualtruthvalue,•  and,thetruthvaluemightdependonthesitua/onorcontext.

•  Later,wewillstudyprobabilitytheory,inwhichweassigndegreesofcertainty(“between” TandF)toproposi/ons.•  Butfornow:thinkTrue/Falseonly!

Topic #1 – Propositional Logic

Page 15: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

ExamplesofPropositions• “BeijingisthecapitalofChina.”•  “1+2=5” • “Itisraining.”(T/Fassessedgivensitua/on.)

• But,thefollowingareNOTproposi/ons:• “Who’sthere?”(interroga/ve,ques/on)• “Lalalalala.”(meaninglessinterjec/on)• “Justdoit!”(impera/ve,command)• “1+2”(expressionwithanon-true/falsevalue;doesnotassertanything)

Topic #1 – Propositional Logic

Page 16: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Absurdstatementscanbepropositions

•  “Pigscanfly”

•  “Themoonismadeofgreencheese”

•  “1+1=10”

Page 17: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Example–Arethesestatementspropositions?

•  “Thisstatementistrue”•  “Thisstatementisfalse”

Page 18: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Example–Arethesestatementspropositions?

•  “Thisstatementistrue”•  Yes,andthetruthvalueisT

•  “Thisstatementisfalse”

• No,notaproposi2on;cannotassignTorF

Page 19: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Operators/Connectives•  Anoperatororconnec2vecombinesoneormoreoperandexpressionsintoalargerexpression.(E.g.,“+”innumericexpressions.)–  Unaryoperatorstake1operand(e.g.,−3);–  binaryoperatorstake2operands(eg3×4).

•  Proposi2onalorBooleanoperatorsoperateonproposi/ons(ortheirtruthvalues)insteadofonnumbers.

Topic #1.0 – Propositional Logic: Operators

Page 20: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

SomePopularBooleanOperators

Formal Name Nickname Arity Symbol

Negation operator NOT Unary ¬

Conjunction operator AND Binary ∧

Disjunction operator OR Binary ∨

Exclusive-OR operator XOR Binary ⊕

Implication operator IMPLIES Binary →

Biconditional operator IFF Binary ↔

Topic #1.0 – Propositional Logic: Operators

Page 21: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Truthtables

•  To evaluate the T or F status of a compound proposition

•  Enumerate over all T and F combinations of all the propositions

•  If an outcome of a compound proposition is F is this violates logic.

Page 22: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

TheNegationOperator•  Theunarynega2onoperator“¬”(NOT)transformsaprop.intoitslogicalnega2on.

•  E.g.Ifp=“Ihavebrownhair.”•  then¬p=“Idonothavebrownhair.” •  ThetruthtableforNOT:

p ¬p T F F T

T :≡ True; F :≡ False “:≡” means “is defined as”

Operand column

Result column

Page 23: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

TheConjunctionOperator•  Thebinaryconjunc2onoperator“∧”(AND)combinestwoproposi/onstoformtheirlogicalconjunc2on.

•  E.g.Ifp=“Iwillhavesaladforlunch.”andq=“Iwillhavesteakfordinner.”,

•  thenp∧q=“IwillhavesaladforlunchandIwillhavesteakfordinner.”

Remember: “∧” points up like an “A”, and it means “∧ND”

∧ND

Page 24: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

ConjunctionTruthTable•  In-classexerciseontheboard:Truthtablefor“p^q”

•  Comparelengthofthe“not”(unary)to“and”(binary)truthtables.

•  Howmanyrowsinthetruthtableifthecompoundproposi/oninvolvesthreebasicproposi/ons,p,q,r?

•  Howmanyrowsinthetruthtableifthecompoundproposi/oninvolvesNbasicproposi/ons?

Page 25: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

ConjunctionTruthTable• Notethataconjunc/onp1∧p2∧…∧pnofnproposi/onswillhave2nrowsinitstruthtable.

• Remark.¬and∧opera/onstogetheraresufficienttoexpressanyBooleantruthtable!

p q p∧q F F F F T F T F F T T T

Operand columns

Topic #1.0 – Propositional Logic: Operators

Page 26: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

TheDisjunctionOperator•  Thebinarydisjunc2onoperator“∨”(OR)combinestwoproposi/onstoformtheirlogicaldisjunc2on.

•  p=“Mycarhasabadengine.”•  q=“Mycarhasabadcarburetor.”•  p∨q=“Eithermycarhasabadengine,ormycarhasabadcarburetor.”

After the downward- pointing “axe” of “∨” splits the wood, you can take 1 piece OR the other, or both.

Topic #1.0 – Propositional Logic: Operators

Meaning is like “and/or” in English.

Page 27: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

DisjunctionTruthTable

•  In-classexerciseontheboard:truthtablefor“pvq”

Page 28: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

DisjunctionTruthTable

•  Notethatp∨qmeansthatpistrue,orqistrue,orbotharetrue!

•  So,thisopera/onisalsocalledinclusiveor,becauseitincludesthepossibilitythatbothpandqaretrue.

•  Remark.“¬”and“∨”togetherarealsouniversal.(WecanwriteanyBooleanlogicfunc/onintermsofthoseoperators.)

p q p∨qF F FF T TT F TT T T

Note difference from AND

Topic #1.0 – Propositional Logic: Operators

Page 29: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

NestedPropositionalExpressions•  Useparenthesestogroupsub-expressions:“Ijustsawmyoldfriend,andeitherhe’sgrownorI’veshrunk.”

•  First break it down into propositions: •  f = “Ijustsawmyoldfriend”•  g = “he’s grown” •  s = “I’ve shrunk”

•  =f∧(g∨s)•  (f∧g)∨swouldmeansomethingdifferent•  f∧g∨swouldbeambiguous

•  Byconven/on,“¬”takesprecedenceoverboth“∧”and“∨”.•  ¬s∧fmeans(¬s)∧f,not¬(s∧f)

Topic #1.0 – Propositional Logic: Operators

Page 30: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

ASimpleExercise•  Letp=“Itrainedlastnight”,q=“Thesprinklerscameonlastnight,”r=“Thelawnwaswetthismorning.”

•  TranslateeachofthefollowingintoEnglish:•  ¬p=•  r∧¬p=•  ¬r∨p∨q=

Topic #1.0 – Propositional Logic: Operators

Page 31: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

TheExclusiveOrOperator•  Thebinaryexclusive-oroperator“⊕”(XOR)combinestwoproposi/onstoformtheirlogical“exclusiveor”(exclusivedisjunc/on)

•  p=“IwillearnanAinthiscourse,”•  q=“Iwilldropthiscourse,”•  p⊕q=“IwilleitherearnanAinthiscourse,orIwilldropit(butnotboth!)”

•  A more common phrase: “Your entrée comes with either soup of salad”

Topic #1.0 – Propositional Logic: Operators

Page 32: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Exclusive-OrTruthTable

• Notethatp⊕qmeansthatpistrue,orqistrue,butnotboth!

•  Thisopera/oniscalledexclusiveor,becauseitexcludesthepossibilitythatbothpandqaretrue.

• Remark.“¬”and“⊕”togetherarenotuniversal.

p q p⊕qF F FF T TT F TT T F Note

difference from OR.

Topic #1.0 – Propositional Logic: Operators

Page 33: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

NaturalLanguageisAmbiguous

• NotethatEnglish“or”canbeambiguousregardingthe“both”case!

• “PatisasingerorPatisawriter.”-

• “PatisaliveorPatisdeceased.”-

• Needcontexttodisambiguatethemeaning!•  Forthisclass,assume“or”meansinclusive.

p q p "or" qF F FF T TT F TT T ?

Topic #1.0 – Propositional Logic: Operators

Page 34: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

TheImplicationOperator

•  Theimplica2onp→qstatesthatpimpliesq.

•  i.e.,Ifpistrue,thenqistrue;butifpisnottrue,thenqcouldbeeithertrueorfalse.

•  E.g.,letp=“YoumasterECS20.”q=“Youwillgetagoodjob.”

•  p→q=“IfyoumasterECS20,thenyouwillgetagoodjob.”

(else,itcouldgoeitherway;somegreatjobsdonotrequirediscretemath)

Topic #1.0 – Propositional Logic: Operators

antecedent consequent

Page 35: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

ImplicationTruthTable• p→qisfalseonlywhenpistruebutqisnottrue.

• p→qdoesnotsaythatpcausesq!

• p→qdoesnotrequirethatporqareevertrue!

•  E.g.“(1=0)→pigscanfly”isTRUE!

p q p→q F F T F T T T F F T T T

The only False case!

Topic #1.0 – Propositional Logic: Operators

Page 36: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

ExamplesofImplications• “Ifthislectureeverends,thenthesunwillrisetomorrow.” TrueorFalse?

• “IfTuesdayisadayoftheweek,thenIamapenguin.” TrueorFalse?

• “If1+1=6,thenBushispresident.”TrueorFalse?

• “Ifthemoonismadeofgreencheese,thenIamricherthanBillGates.” TrueorFalse?

Topic #1.0 – Propositional Logic: Operators

Page 37: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

ExamplesofImplications• “Ifthislectureeverends,thenthesunwillrisetomorrow.” TrueorFalse?

• “IfTuesdayisadayoftheweek,thenIamapenguin.” TrueorFalse?

• “If1+1=6,thenBushispresident.”TrueorFalse?

• “Ifthemoonismadeofgreencheese,thenIamricherthanBillGates.” TrueorFalse?

Topic #1.0 – Propositional Logic: Operators

Page 38: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Whydoesthisseemwrong?• Considerasentencelike,

• “IfIweararedshirttomorrow,thenglobalpeacewillprevail”

•  Inlogic,weconsiderthesentenceTruesolongaseitherIdon’tweararedshirt,orglobalpeaceisnotachieved.

• But,innormalEnglishconversa/on,ifIweretomakethisclaim,youwouldthinkthatIwaslying.• Whythisdiscrepancybetweenlogic&language?

•  Logicisaboutconsistency.

Page 39: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

EnglishPhrasesMeaningp→q• “pimpliesq”• “ifp,thenq”• “ifp,q”• “whenp,q”• “wheneverp,q”• “qifp”• “qwhenp”• “qwheneverp”

• “ponlyifq”• “pissufficientforq”• “qisnecessaryforp”• “qfollowsfromp”• “qisimpliedbyp”

• Wewillseesomeequivalentlogicexpressionslater.

Topic #1.0 – Propositional Logic: Operators

Page 40: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Converse,Inverse,Contrapositive

•  Someterminology,foranimplica/onp→q:•  Itsconverseis: q→p.•  Itsinverseis: ¬p→¬q.•  Itscontraposi2ve: ¬q→¬p.• Oneofthesethreehasthesamemeaning(sametruthtable)asp→q.Canyoufigureoutwhich?

(Let’sworkitoutontheboard).

Topic #1.0 – Propositional Logic: Operators

Page 41: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

• Provingtheequivalenceofp→qanditscontraposi/veusingtruthtables:

p q ¬q ¬p p→q ¬q →¬pF F T T T TF T F T T TT F T F F FT T F F T T

Topic #1.0 – Propositional Logic: Operators

Page 42: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

Thebiconditionaloperator

• Thebicondi2onalp↔qstatesthatp→qandq→p• Inotherwords,pistrueifandonlyif(IFF)qistrue.• p=“Clintonwinsthe2016elec/on.”• q=“Clintonwillbepresidentforallof2017.”• p↔q=“If,andonlyif,Clintonwinsthe2016elec/on,Clintonwillbepresidentforallof2017.”

Topic #1.0 – Propositional Logic: Operators

Page 43: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

BiconditionalTruthTable

• p↔qmeansthatpandqhavethesametruthvalue.

• Remark.Thistruthtableistheexactoppositeof⊕’s!•  Thus,p↔qmeans¬(p⊕q)

• p↔qdoesnotimplythatpandqaretrue,orthateitherofthemcausestheother,orthattheyhaveacommoncause.

p q p ↔ qF F TF T FT F FT T T

Topic #1.0 – Propositional Logic: Operators

Page 44: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

BooleanOperationsSummary• Wehaveseen1unaryoperator(outofthe4possible)and5binaryoperators(outofthe16possible).Theirtruthtablesarebelow.

p q ¬p p∧q p∨q p⊕q p→q p↔qF F T F F F T TF T T F T T T FT F F F T T F FT T F T T F T T

Topic #1.0 – Propositional Logic: Operators

Page 45: Discrete Mathematics for Computer Science Prof. Raissa D’Souzamae.engr.ucdavis.edu/dsouza/Classes/Lec1_ecs20.pdf · • “Discrete Mathematics” - The study of discrete, mathematical

Base

d on

Ros

en, D

iscr

ete

Mat

hem

atic

s &

Its

App

licat

ions

, 5e

Pr

epar

ed b

y (c

)200

1-20

04 M

icha

el P

. Fr

ank

M

odifi

ed b

y (c

) 20

04-2

005

Hal

uk B

ingö

l

‹#›/92 M

odul

e #1

- Lo

gic

SomeAlternativeNotations

Name: not and or xor implies iffPropositional logic: ¬ ∧ ∨ ⊕ → ↔Boolean algebra: p pq + ⊕C/C++/Java (wordwise): ! && || != ==C/C++/Java (bitwise): ~ & | ^Logic gates:

Topic #1.0 – Propositional Logic: Operators

End of lecture 1