34
Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 1 CMPUT 272 CMPUT 272 Formal Systems & Logic in Formal Systems & Logic in CS CS I. E. Leonard University of Alberta http://www.cs.ualberta.ca/~isaac/ cmput272/f03

Sept 16, 2003© Vadim Bulitko : CMPUT 272, Fall 2003, UofA1 CMPUT 272 Formal Systems & Logic in CS I. E. Leonard University of Alberta isaac/cmput272/f03

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 1

CMPUT 272CMPUT 272Formal Systems & Logic in Formal Systems & Logic in

CSCS

CMPUT 272CMPUT 272Formal Systems & Logic in Formal Systems & Logic in

CSCS

I. E. LeonardUniversity of Alberta

http://www.cs.ualberta.ca/~isaac/cmput272/f03

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 2

TodayTodayTodayToday

Chapter 2.1

All

imag

es

are

cop

yri

gh

ted

to t

heir

resp

ect

ive c

op

yri

gh

t h

old

ers

an

d r

ep

rod

uce

d h

ere

for

aca

dem

ic p

urp

ose

s u

nd

er

the c

on

dit

ion

of

“fair

usi

ng

”.

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 3

AnnouncementAnnouncementAnnouncementAnnouncement

It is Ok for an assignment problem to refer to the material that is:

Not covered in class by the due dateNot covered in class at all

Why?

Because the lectures only highlight the material in the textbookThey are not a substitute for reading the text

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 4

The Big PictureThe Big PictureThe Big PictureThe Big Picture

Logic is being used to verify validity of arguments

An argument is valid iff its conclusion logically follows from the premises

Derivations are used to prove validity

Inference rules are used as part of derivations

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 5

SummarySummarySummarySummary

Logical implication/entailment:A entails/logically implies BB follows from AAB is a valid argumentA is a sufficient condition for BB is a necessary condition for AIf A holds then B holdsA may be “stronger than” BFormula F=(AB) is a tautology

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 6

SummarySummarySummarySummary

Equivalence:A BA holds iff B holdsA is a criterion for B, B is a criterion for AA B, B AA and B are “equivalently strong”Formula F=(AB) is a tautology

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 7

Clarification #1Clarification #1Clarification #1Clarification #1

We have used the following expressions synonymously:

A entails BA logically implies B(A therefore B) is a valid argumentB logically follows from A

In reality there are some subtle differencesTechnically we mean:

“A logically implies B”Every model for A is also a model for B

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 8

Clarification #2Clarification #2Clarification #2Clarification #2

Can computers generate a derivation/proof given a conclusion and a set of premises?

Propositional logic is decidable:the tabular methodapplication of inference rules

Predicate logic is semi-decidableIf a proof exists then it can (theoretically) be found by machinesIf the proof doesn’t exist then the algorithm may not stop

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 9

Clarification #3Clarification #3Clarification #3Clarification #3

Derivation of a statement: a sequence of statementsstart with the premiseseach statement logically follows from the previous statementsat some point the conclusion is arrived at

Derivations are annotated with the inference rules used

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 10

Questions?Questions?Questions?Questions?

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 11

De Morgan’s LawsDe Morgan’s LawsDe Morgan’s LawsDe Morgan’s Laws

Let’s get some practice in deriving Theorem 1.1.1 equivalences from Boolean algebra

Page 14 in the text

A solution is posted on my webpage under the “Notes” section

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 12

Questions?Questions?Questions?Questions?

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 13

Limitations of Propositional Limitations of Propositional LogicLogic

Limitations of Propositional Limitations of Propositional LogicLogic

Let’s get back to Socrates“All people are mortal”“Socrates is a man”“Socrates is mortal”

Can we formalize this in propositional logic?Our previous attempt was:

“If Socrates is a man then Socrates is mortal”“Socrates is a man”“Socrates is mortal”

Clearly NOT the same!

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 14

What is the matter?What is the matter?What is the matter?What is the matter?

The problem is:We operate with constant objects onlyWe have no domain context and no domain variablesWe cannot say “all”, “is a”, etc.

Solution?Predicate Logic

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 15

Predicate LogicPredicate LogicPredicate LogicPredicate LogicLogic objects (constants/variables):

P, Q, R, …true, false

Connectives:&, v, , …

Domain objects (constants/variables):Socrates, CMPUT272

Predicates:Mortal(Socrates)TaughtAtUofA(CMPUT272)Happened(snow,yesterday)

Quantifiers:For all, There exist

Statements/formulae:Atomic, conjunctive, etc.Quantified (universally / existentially)

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 16

Translation ExamplesTranslation ExamplesTranslation ExamplesTranslation Examples

“Every man is mortal”x [man(X) mortal(x)]

“Socrates is a man”man(Socrates)

“Socrates is mortal”mortal(Socrates)

The last statement logically follows from the premises (by universal elimination)

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 17

Translation ExamplesTranslation ExamplesTranslation ExamplesTranslation Examples

“Nothing is better than God”~[x better-than(x,God)]

“A sandwich is better than nothing”x [sandwich(x) better-than(x,Nothing)]

“A sandwich is better than God”x [sandwich(x) better-than(x,God)]

The last statement does not logically follow from the premises

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 18

More translationsMore translationsMore translationsMore translations

“Ducks fly”x [duck(x) flies(x)]

“F-16s fly”x [F-16(x) flies(x)]

“F-16s are ducks”x [F-16(x) duck(x)]

The last statement does not logically follow from the premises

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 19

Translation ExamplesTranslation ExamplesTranslation ExamplesTranslation Examples

“No man lives forever”~[x [man(x) & lives-forever(x)]]x [man(x) ~lives-forever(x)]

“Every person is a Knave or a Knight”x [person(x) [Knave(x) v Knight(x)]]

“Every person is a Knave or a Knight but not both”

x [person(x) [Knave(x) v Knight(x)] & ~[Knave(x) & Knight(x)]]

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 20

Questions?Questions?Questions?Questions?

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 21

Predicate LogicPredicate LogicPredicate LogicPredicate LogicLogic objects (constants/variables):

P, Q, R, …true, false

Connectives:&, v, , …

Domain objects (constants/variables):Socrates, CMPUT272

Predicates:Mortal(Socrates)TaughtAtUofA(CMPUT272)Happened(snow,yesterday)

Quantifiers:For all, Exists

Statements/formulae:Atomic, conjunctive, etc.Quantified (universally / existentially)

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 22

Domain ObjectsDomain ObjectsDomain ObjectsDomain Objects

We can now have variables and constants of a non-Boolean nature:

Socrates is a constant (a specific member) in the set of all peopleX is a variable over the set of people

i.e., X can be any personWe can instantiate X=Socrates

Domain of a variable is the set of values it can take on

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 23

PredicatesPredicatesPredicatesPredicates

Predicates map from the domain sets of predicate variables to {true,false}General form:

P(v1,…,vN)

Example:Mortal(X)Mortal is the predicate nameX is the predicate variable runs over people and elvesMortal(X) maps X to true/false depending on whether X is mortal or not

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 24

PredicatesPredicatesPredicatesPredicates

In other words:Predicates take domain objects and map them to true/false depending on the properties of the objectsThus, a predicate with all its variables instantiated is a statement (i.e., true/false)

Example:BetterThan(v1,v2)BetterThan(Ferrari,nothing)=true

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 25

Truth SetTruth SetTruth SetTruth Set

Suppose P(x) is “x is a factor of 8”So how about the following:

P(1)TrueP(2)TrueP(0)False

The set of all x such that P(x) holds is called the truth set of P(x)

Here it would be {1,2,4,8}

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 26

ExamplesExamplesExamplesExamples

Suppose P(x,y,r) is “x2+y2=r2”What is the truth set of P(x,y,5)?

Circle with the radius of 5 centered in the origin

Suppose P(n) is “n is an even three-digit prime number”What is the truth set of P(n)?

An empty set

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 27

Questions?Questions?Questions?Questions?

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 28

A Lost Love?A Lost Love?A Lost Love?A Lost Love?

But what about our dearly beloved propositional statements?

P v Q

Here P and Q are propositional/Boolean variables/statementsThey don’t take any domain objectsThey simply hold or don’t hold

How can we have them in the predicate logic?

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 29

Fear Not!Fear Not!Fear Not!Fear Not!

A Boolean variable/constant (e.g., P=true) is simply a 0-arity predicate:

P()

So propositional logic is back!Example: propositional Modus Ponens:

P Q P() Q()P P()Thus, Q Thus, Q()

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 30

Predicate FormulaePredicate FormulaePredicate FormulaePredicate Formulae

Everything from propositional logicBoolean variables become 0-arity predicates…

Additionally:Predicates, e.g.:

Mortal(x)

Universally quantified formulae, e.g.:x [man(x) mortal(x)]

Existentially quantified formulae, e.g.:x [man(x) & likes272(x)]

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 31

Recall: interpretationRecall: interpretationRecall: interpretationRecall: interpretation

In propositional logic interpretation is a mapping/assignment of all propositional variables to true/false

Example:Formula: A v BInterpretation: II(A)=trueI(B)=falseI(A v B)=true

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 32

Extended Extended InterpretationsInterpretations

Extended Extended InterpretationsInterpretations

In predicate calculus to specify an interpretation we need to:

Select domain sets Assign all domain constantsAssign semantics to all predicates

Example:Predicate formula: F=(x [likes(x,c272)])A possible interpretation assigns:

Domain set for x : peopleDomain value for 2nd argument of likes(a,b) : thingsDomain value for constant c272 : class CMPUT 272Semantics for predicate likes(a,b) : holds iff person a likes thing b

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 33

Evaluating formulaeEvaluating formulaeEvaluating formulaeEvaluating formulae

Predicate formula: F=(x [likes(x,c272)])A possible interpretation assigns:Domain set for x : peopleDomain value for 2nd argument of likes(a,b) : thingsDomain value for constant c272 : class CMPUT 272Semantics for predicate likes(a,b) : holds iff person a likes thing b

So what is the value of formula F given the interpretation? True/false?

How can we tell?

Sept 16, 2003 © Vadim Bulitko : CMPUT 272, Fall 2003, UofA 34

Evaluating FormulaEvaluating FormulaEvaluating FormulaEvaluating Formula

0-arity predicate : P()Interpretation directly

Predicate with variables : P(x)Use the assignment of x and the semantics of P()

Universally quantified formula : x P(x)Evaluates to true iff P(x) holds on all possible values of x

Existentially quantified formulae : x P(x)Evaluates to true iff P(x) holds on at least one possible value of x