54
Chapter 1, Part II: Predicate Logic With Question/Answer Animations

Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Chapter1,PartII:PredicateLogic

WithQuestion/AnswerAnimations

Page 2: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Summary PredicateLogic(First‐OrderLogic(FOL),PredicateCalculus(notcovered)) TheLanguageofQuantifiers LogicalEquivalences NestedQuantifiers TranslationfromPredicateLogictoEnglish TranslationfromEnglishtoPredicateLogic

Page 3: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Section1.4

Page 4: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Sec*onSummary Predicates Variables Quantifiers

 UniversalQuantifier ExistentialQuantifier

 NegatingQuantifiers DeMorgan’sLawsforQuantifiers

 TranslatingEnglishtoLogic

Page 5: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Proposi*onalLogicNotEnough Ifwehave:

“Allmenaremortal.”“Socratesisaman.”

 Doesitfollowthat“Socratesismortal?” Can’tberepresentedinpropositionallogic.Needalanguagethattalksaboutobjects,theirproperties,andtheirrelations.

 Laterwe’llseehowtodrawinferences.

Page 6: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

IntroducingPredicateLogic Predicatelogicusesthefollowingnewfeatures:

 Variables:x,y,z Predicates:P(x),M(x) Quantifiers(tobecoveredinafewslides):

 Propositionalfunctionsareageneralizationofpropositions. Theycontainvariablesandapredicate,e.g.,P(x) Variablescanbereplacedbyelementsfromtheirdomain.

Page 7: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Proposi*onalFunc*ons Propositionalfunctionsbecomepropositions(andhavetruthvalues)whentheirvariablesareeachreplacedbyavaluefromthedomain(orboundbyaquantifier,aswewillseelater).

 ThestatementP(x)issaidtobethevalueofthepropositionalfunctionPatx.

 Forexample,letP(x)denote“x>0”andthedomainbetheintegers.Then:P(‐3)isfalse.P(0)isfalse.P(3)istrue.

 OftenthedomainisdenotedbyU.SointhisexampleUistheintegers.

Page 8: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

ExamplesofProposi*onalFunc*ons  Let“x+y=z”bedenotedbyR(x,y,z)andU(forallthreevariables)bethe

integers.Findthesetruthvalues:R(2,-1,5)

Solution:FR(3,4,7)

Solution:TR(x,3,z)

Solution:NotaProposition  Nowlet“x‐y=z”bedenotedbyQ(x,y,z),withUastheintegers.Findthese

truthvalues:Q(2,-1,3)

Solution:TQ(3,4,7)

Solution:FQ(x,3,z)

Solution:NotaProposition

Page 9: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

CompoundExpressions Connectivesfrompropositionallogiccarryovertopredicate

logic.  IfP(x)denotes“x>0,”findthesetruthvalues:

P(3)∨ P(-1) Solution: T P(3)∧ P(-1) Solution: F P(3)→ P(-1) Solution: F P(3)→ P(-1) Solution: T

  Expressionswithvariablesarenotpropositionsandthereforedonothavetruthvalues.Forexample,P(3)∧ P(y) P(x)→ P(y)

 Whenusedwithquantifiers(tobeintroducednext),theseexpressions(propositionalfunctions)becomepropositions.

Page 10: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Quan*fiers WeneedquantifierstoexpressthemeaningofEnglishwords

includingallandsome:  “AllmenareMortal.”  “Somecatsdonothavefur.”

  Thetwomostimportantquantifiersare:  UniversalQuantifier,“Forall,”symbol:∀  ExistentialQuantifier,“Thereexists,”symbol:∃

 Wewriteasin∀xP(x)and∃xP(x). ∀xP(x)assertsP(x)istrueforeveryxinthedomain.  ∃xP(x)assertsP(x)istrueforsomexinthedomain.  Thequantifiersaresaidtobindthevariablexinthese

expressions.

CharlesPeirce(1839‐1914)

Page 11: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

UniversalQuan*fier ∀xP(x)isreadas“Forallx,P(x)”or“Foreveryx,P(x)”Examples:

1)  IfP(x)denotes“x>0” and U is the integers, then ∀xP(x)isfalse.

2)  IfP(x)denotes“x>0” and U is the positive integers, then ∀xP(x)istrue.

3)  IfP(x)denotes“xiseven” and U is the integers, then ∀xP(x)isfalse.

Page 12: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Existen*alQuan*fier ∃xP(x)isreadas“Forsomex,P(x)”,oras“ThereisanxsuchthatP(x),”or“Foratleastonex,P(x).”Examples:

1.  IfP(x)denotes“x>0” and U is the integers, then ∃xP(x)istrue.ItisalsotrueifUisthepositiveintegers.

2.  IfP(x)denotes“x<0” and U is the positive integers, then ∃xP(x)isfalse.

3.  IfP(x)denotes“xiseven” and U is the integers, then ∃xP(x)istrue.

Page 13: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

UniquenessQuan*fier(op#onal)  ∃!xP(x)meansthatP(x)istrueforoneandonlyonex inthe

universeofdiscourse.  ThisiscommonlyexpressedinEnglishinthefollowing

equivalentways:  “ThereisauniquexsuchthatP(x).”  “ThereisoneandonlyonexsuchthatP(x)”

  Examples:1.  IfP(x)denotes“x+1=0” and U is the integers, then ∃!xP(x)istrue.

2. ButifP(x)denotes“x>0,” then ∃!xP(x)isfalse.  Theuniquenessquantifierisnotreallyneededastherestriction

thatthereisauniquexsuchthatP(x)canbeexpressedas:∃x(P(x)∧∀y(P(y)→ y =x))

Page 14: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

ThinkingaboutQuan*fiers Whenthedomainofdiscourseisfinite,wecanthinkof

quantificationasloopingthroughtheelementsofthedomain.  Toevaluate∀xP(x)loopthroughallxinthedomain.

  IfateverystepP(x)istrue,then∀xP(x)istrue.  IfatastepP(x)isfalse,then∀xP(x)isfalseandtheloopterminates.

  Toevaluate∃xP(x)loopthroughallxinthedomain.  Ifatsomestep,P(x)istrue,then∃xP(x)istrueandtheloopterminates.

  IftheloopendswithoutfindinganxforwhichP(x)istrue,then∃xP(x)isfalse.

  Evenifthedomainsareinfinite,wecanstillthinkofthequantifiersthisfashion,buttheloopswillnotterminateinsomecases.

Page 15: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Proper*esofQuan*fiers Thetruthvalueof∃x P(x)and∀ x P(x) depend on both

the propositional function P(x) and on the domain U.  Examples:

1.  IfUisthepositiveintegersandP(x)isthestatement“x<2”,then∃x P(x)istrue,but∀ x P(x) is false.

2.  IfUisthenegativeintegersandP(x)isthestatement“x<2”,thenboth∃x P(x)and∀ x P(x) are true.

3.  IfUconsistsof3,4,and5,andP(x)isthestatement“x>2”,thenboth∃x P(x)and∀ x P(x) are true. But if P(x)isthestatement“x<2”,thenboth∃x P(x)and∀ x P(x) are false.

Page 16: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

PrecedenceofQuan*fiers Thequantifiers∀and∃havehigherprecedencethanallthelogicaloperators.

 Forexample,∀x P(x) ∨ Q(x) means (∀x P(x))∨ Q(x) ∀x (P(x) ∨ Q(x)) means something different.  Unfortunately, often people write ∀x P(x) ∨ Q(x)

when they mean ∀ x (P(x) ∨ Q(x)).

Page 17: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*ngfromEnglishtoLogicExample1:Translatethefollowingsentenceintopredicatelogic:“EverystudentinthisclasshastakenacourseinJava.”

Solution:FirstdecideonthedomainU.

Solution1:IfUisallstudentsinthisclass,defineapropositionalfunctionJ(x)denoting“xhastakenacourseinJava”andtranslateas∀x J(x).

Solution2: ButifUisallpeople,alsodefineapropositionalfunctionS(x)denoting“xisastudentinthisclass”andtranslateas∀x (S(x)→ J(x)). ∀x (S(x) ∧ J(x)) is not correct. What does it mean?

Page 18: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*ngfromEnglishtoLogicExample2:Translatethefollowingsentenceintopredicatelogic:“SomestudentinthisclasshastakenacourseinJava.”

Solution:FirstdecideonthedomainU.

Solution1:IfUisallstudentsinthisclass,translateas ∃x J(x) Solution1:ButifUisallpeople,thentranslateas∃x (S(x) ∧ J(x)) ∃x (S(x)→ J(x)) is not correct. What does it mean?

Page 19: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

ReturningtotheSocratesExample IntroducethepropositionalfunctionsMan(x)denoting“xisaman”andMortal(x)denoting“xismortal.”Specifythedomainasallpeople.

 Thetwopremisesare:

 Theconclusionis:

 Laterwewillshowhowtoprovethattheconclusionfollowsfromthepremises.

Page 20: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

EquivalencesinPredicateLogic Statementsinvolvingpredicatesandquantifiersarelogicallyequivalentifandonlyiftheyhavethesametruthvalue  foreverypredicatesubstitutedintothesestatementsand

  foreverydomainofdiscourseusedforthevariablesintheexpressions.

 ThenotationS≡T indicates that S and T are logically equivalent.

 Example: ∀x ¬¬S(x) ≡ ∀x S(x)

Page 21: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

ThinkingaboutQuan*fiersasConjunc*onsandDisjunc*ons  Ifthedomainisfinite,auniversallyquantifiedpropositionis

equivalenttoaconjunctionofpropositionswithoutquantifiersandanexistentiallyquantifiedpropositionisequivalenttoadisjunctionofpropositionswithoutquantifiers.

  IfUconsistsoftheintegers1,2,and3:

  Evenifthedomainsareinfinite,youcanstillthinkofthequantifiersinthisfashion,buttheequivalentexpressionswithoutquantifierswillbeinfinitelylong.

Page 22: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Nega*ngQuan*fiedExpressions Consider∀x J(x)

“EverystudentinyourclasshastakenacourseinJava.”HereJ(x)is“xhastakenacourseincalculus”andthedomainisstudentsinyourclass.

 Negatingtheoriginalstatementgives“ItisnotthecasethateverystudentinyourclasshastakenJava.”Thisimpliesthat“Thereisastudentinyourclasswhohasnottakencalculus.”

Symbolically ¬∀x J(x) and ∃x ¬J(x) are equivalent

Page 23: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Nega*ngQuan*fiedExpressions(con#nued) NowConsider∃ x J(x)

“ThereisastudentinthisclasswhohastakenacourseinJava.”

WhereJ(x)is“xhastakenacourseinJava.” Negatingtheoriginalstatementgives“ItisnotthecasethatthereisastudentinthisclasswhohastakenJava.”Thisimpliesthat“EverystudentinthisclasshasnottakenJava”

Symbolically ¬∃ x J(x) and ∀ x ¬J(x) are equivalent

Page 24: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

DeMorgan’sLawsforQuan*fiers Therulesfornegatingquantifiersare:

 Thereasoninginthetableshowsthat:

 Theseareimportant.Youwillusethese.

Page 25: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*onfromEnglishtoLogicExamples:1.  “SomestudentinthisclasshasvisitedMexico.”

Solution:LetM(x)denote“xhasvisitedMexico”andS(x)denote“xisastudentinthisclass,”andU be all people.

∃x (S(x) ∧ M(x))2.  “EverystudentinthisclasshasvisitedCanadaor

Mexico.”Solution:AddC(x)denoting“xhasvisitedCanada.” ∀x (S(x)→ (M(x)∨C(x)))

Page 26: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

SomeFunwithTransla*ngfromEnglishintoLogicalExpressions U={fleegles,snurds,thingamabobs}

F(x):xisafleegleS(x):xisasnurdT(x):xisathingamabob

Translate“Everythingisafleegle”

Solution:∀x F(x)

Page 27: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*on(cont) U={fleegles,snurds,thingamabobs}

F(x):xisafleegleS(x):xisasnurdT(x):xisathingamabob

“Nothingisasnurd.”

Solution:¬∃x S(x) What is this equivalent to? Solution:∀x ¬ S(x)

Page 28: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*on(cont) U={fleegles,snurds,thingamabobs}

F(x):xisafleegleS(x):xisasnurdT(x):xisathingamabob

“Allfleeglesaresnurds.”

Solution:∀x (F(x)→ S(x))

Page 29: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*on(cont) U={fleegles,snurds,thingamabobs}

F(x):xisafleegleS(x):xisasnurdT(x):xisathingamabob

“Somefleeglesarethingamabobs.”

Solution:∃x (F(x) ∧ T(x))

Page 30: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*on(cont) U={fleegles,snurds,thingamabobs}

F(x):xisafleegleS(x):xisasnurdT(x):xisathingamabob

“Nosnurdisathingamabob.”

Solution:¬∃x (S(x) ∧ T(x)) What is this equivalent to?

Solution:∀x (¬S(x) ∨ ¬T(x))

Page 31: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*on(cont) U={fleegles,snurds,thingamabobs}

F(x):xisafleegleS(x):xisasnurdT(x):xisathingamabob

“Ifanyfleegleisasnurdthenitisalsoathingamabob.”

Solution:∀x ((F(x) ∧ S(x))→ T(x))

Page 32: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

SystemSpecifica*onExample  Predicatelogicisusedforspecifyingpropertiesthatsystemsmustsatisfy.  Forexample,translateintopredicatelogic:

  “Everymailmessagelargerthanonemegabytewillbecompressed.”  “Ifauserisactive,atleastonenetworklinkwillbeavailable.”

  Decideonpredicatesanddomains(leftimplicithere)forthevariables:  LetL(m,y)be“Mailmessagemislargerthanymegabytes.”  LetC(m)denote“Mailmessagemwillbecompressed.”  LetA(u)represent“Useruisactive.”  LetS(n,x)represent“Networklinknisstatex.

  Nowwehave:

Page 33: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

LewisCarrollExample  Thefirsttwoarecalledpremisesandthethirdiscalledthe

conclusion.1.  “Alllionsarefierce.”2.  “Somelionsdonotdrinkcoffee.”3.  “Somefiercecreaturesdonotdrinkcoffee.”

  Hereisonewaytotranslatethesestatementstopredicatelogic.LetP(x),Q(x),andR(x)bethepropositionalfunctions“xisalion,”“xisfierce,”and“xdrinkscoffee,”respectively.

1.  ∀x (P(x)→ Q(x)) 2.  ∃x (P(x) ∧ ¬R(x)) 3.  ∃x (Q(x) ∧ ¬R(x))

  Laterwewillseehowtoprovethattheconclusionfollowsfromthepremises.

CharlesLutwidgeDodgson(AKALewisCaroll)(1832‐1898)

Page 34: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

SomePredicateCalculusDefini*ons(op#onal) Anassertioninvolvingpredicatesandquantifiersisvalidifitistrue

  foralldomains  everypropositionalfunctionsubstitutedforthepredicatesinthe

assertion.Example:

 Anassertioninvolvingpredicatesissatisfiableifitistrue  forsomedomains  somepropositionalfunctionsthatcanbesubstitutedforthe

predicatesintheassertion.Otherwiseitisunsatisfiable.Example:notvalidbutsatisfiableExample:unsatisfiable

Page 35: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

MorePredicateCalculusDefini*ons(op#onal) Thescopeofaquantifieristhepartofanassertioninwhichvariablesareboundbythequantifier.Example:xhaswidescope

Example:xhasnarrowscope

Page 36: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

LogicProgramming(op*onal) Prolog(fromProgramminginLogic)isaprogramminglanguagedevelopedinthe1970sbyresearchersinartificialintelligence(AI).

 PrologprogramsincludePrologfactsandPrologrules. AsanexampleofasetofPrologfactsconsiderthefollowing: instructor(chan, math273). instructor(patel, ee222). instructor(grossman, cs301). enrolled(kevin, math273). enrolled(juna, ee222). enrolled(juana, cs301). enrolled(kiko, math273). enrolled(kiko, cs301).

 Herethepredicatesinstructor(p,c)andenrolled(s,c)representthatprofessorpistheinstructorofcoursecandthatstudentsisenrolledincoursec.

Page 37: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

LogicProgramming(cont) InProlog,namesbeginningwithanuppercaseletterarevariables.

 Ifwehaveapredicateteaches(p,s)representing“professorpteachesstudents,”wecanwritetherule:

teaches(P,S) :- instructor(P,C), enrolled(S,C).  ThisPrologrulecanbeviewedasequivalenttothefollowingstatementinlogic(usingourconventionsforlogicalstatements).∀p ∀c ∀s(I(p,c) ∧ E(s,c)) → T(p,s))

Page 38: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

LogicProgramming(cont) PrologprogramsareloadedintoaProloginterpreter.TheinterpreterreceivesqueriesandreturnsanswersusingthePrologprogram.

 Forexample,usingourprogram,thefollowingquerymaybegiven:

?enrolled(kevin,math273).  Prologproducestheresponse:yes  Notethatthe? isthepromptgivenbytheProloginterpreterindicatingthatitisreadytoreceiveaquery.

Page 39: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

LogicProgramming(cont) Thequery:?enrolled(X,math273). producestheresponse:X = kevin; X = kiko; no

 Thequery: ?teaches(X,juana).

producestheresponse:X = patel; X = grossman; no

TheProloginterpretertriestofindaninstantiationforX.Itdoessoandreturns X = kevin. Thentheusertypesthe; indicatingarequestforanotheranswer.WhenPrologisunabletofindanotheransweritreturnsno.

Page 40: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

LogicProgramming(cont) Thequery: ?teaches(chan,X).

producestheresponse:X = kevin; X = kiko; no

 AnumberofverygoodPrologtextsareavailable.LearnPrologNow!isonesuchtextwithafreeonlineversionathttp://www.learnprolognow.org/

 ThereismuchmoretoPrologandtotheentirefieldoflogicprogramming.

Page 41: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Section1.4

Page 42: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Sec*onSummary NestedQuantifiers OrderofQuantifiers TranslatingfromNestedQuantifiersintoEnglish TranslatingMathematicalStatementsintoStatementsinvolvingNestedQuantifiers.

 TranslatedEnglishSentencesintoLogicalExpressions.

 NegatingNestedQuantifiers.

Page 43: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

NestedQuan*fiers NestedquantifiersareoftennecessarytoexpressthemeaningofsentencesinEnglishaswellasimportantconceptsincomputerscienceandmathematics.

Example:“Everyrealnumberhasaninverse”is ∀x ∃y(x + y = 0) where the domains of x and y are the real

numbers. Wecanalsothinkofnestedpropositionalfunctions:

∀x ∃y(x + y = 0) canbeviewedas∀x Q(x) whereQ(x) is∃y P(x, y) whereP(x, y) is (x + y = 0)

Page 44: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

ThinkingofNestedQuan*fica*on  NestedLoops

  Toseeif∀x∀yP (x,y) is true, loop through the values of x :   At each step, loop through the values for y.  Ifforsomepairofx andy, P(x,y) isfalse,then∀x ∀yP(x,y) isfalseandboththe

outerandinnerloopterminate. ∀x ∀y P(x,y) istrue if the outer loop ends after stepping through

each x.   Toseeif∀x ∃yP(x,y) is true, loop through the values of x:

 At each step, loop through the values for y.  The inner loop ends when a pair x and y is found such that P(x, y) is true.  If no y is found such that P(x, y) is true the outer loop terminates as ∀x ∃yP(x,y)

hasbeenshowntobefalse. ∀x ∃y P(x,y) istrue if the outer loop ends after stepping through

each x.   Ifthedomainsofthevariablesareinfinite,thenthisprocesscannot

actuallybecarriedout.

Page 45: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

OrderofQuan*fiersExamples:1.  LetP(x,y) bethestatement“x + y = y + x.”Assume

thatUistherealnumbers.Then∀x ∀yP(x,y) and∀y ∀xP(x,y) havethesametruthvalue.

2.  LetQ(x,y) bethestatement“x + y = 0.”AssumethatUistherealnumbers.Then∀x ∃yP(x,y) istrue,but∃y∀xP(x,y) isfalse.

Page 46: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Ques*onsonOrderofQuan*fiersExample1:LetUbetherealnumbers,DefineP(x,y):x∙y=0 Whatisthetruthvalueofthefollowing:

1.  ∀x∀yP(x,y)Answer:False

2.  ∀x∃yP(x,y)Answer:True

3.  ∃x∀y P(x,y)Answer:True

4.  ∃x ∃ y P(x,y)Answer:True

Page 47: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Ques*onsonOrderofQuan*fiersExample2:LetUbetherealnumbers,DefineP(x,y):x/y=1 Whatisthetruthvalueofthefollowing:

1.  ∀x∀yP(x,y)Answer:False

2.  ∀x∃yP(x,y)Answer:True

3.  ∃x∀y P(x,y)Answer:False

4.  ∃x ∃ y P(x,y)Answer:True

Page 48: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Quan*fica*onsofTwoVariables

Statement WhenTrue? WhenFalse

P(x,y)istrueforeverypairx,y.

Thereisapairx,yforwhichP(x,y)isfalse.

ForeveryxthereisayforwhichP(x,y)istrue.

ThereisanxsuchthatP(x,y)isfalseforeveryy.

ThereisanxforwhichP(x,y)istrueforeveryy.

ForeveryxthereisayforwhichP(x,y)isfalse.

Thereisapairx,yforwhichP(x,y)istrue.

P(x,y)isfalseforeverypairx,y

Page 49: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*ngNestedQuan*fiersintoEnglishExample1:Translatethestatement ∀x (C(x )∨ ∃y (C(y ) ∧ F(x, y))) whereC(x)is“xhasacomputer,”andF(x,y)is“xandyarefriends,”andthedomainforbothxandyconsistsofallstudentsinyourschool.

Solution:Everystudentinyourschoolhasacomputerorhasafriendwhohasacomputer.

Example1:Translatethestatement ∃x∀y ∀z ((F(x, y)∧ F(x,z) ∧ (y ≠z))→¬F(y,z)) Solution:Everystudentnoneofwhosefriendsarealsofriendswitheachother.

Page 50: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*ngMathema*calStatementsintoPredicateLogicExample:Translate“Thesumoftwopositiveintegersisalwayspositive”intoalogicalexpression.

Solution:1.  Rewritethestatementtomaketheimpliedquantifiersand

domainsexplicit:“Foreverytwointegers,iftheseintegersarebothpositive,thenthe

sumoftheseintegersispositive.”2.  Introducethevariablesxandy,andspecifythedomain,to

obtain:“Forallpositiveintegersxandy,x+yispositive.”

3.  Theresultis: ∀x ∀ y ((x > 0)∧ (y> 0)→ (x + y> 0)) where the domain of both variables consists of all integers

Page 51: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Transla*ngEnglishintoLogicalExpressionsExampleExample:Usequantifierstoexpressthestatement“Thereisawomanwhohastakenaflightoneveryairlineintheworld.”

Solution:1.  LetP(w,f)be“whastakenf ”andQ(f,a) be“fisa

flightona .”2.  Thedomainofwisallwomen,thedomainoffisall

flights,andthedomainofaisallairlines.3.  Thenthestatementcanbeexpressedas:∃w ∀a ∃f (P(w,f) ∧ Q(f,a))

Page 52: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Ques*onsonTransla*onfromEnglishChoosetheobviouspredicatesandexpressinpredicatelogic.Example1:“Brothersaresiblings.”Solution:∀x∀y(B(x,y)→ S(x,y))Example2:“Siblinghoodissymmetric.”Solution:∀x∀y(S(x,y)→ S(y,x))Example3:“Everybodylovessomebody.”Solution:∀x∃yL(x,y)Example4:“Thereissomeonewhoislovedbyeveryone.”Solution:∃y∀xL(x,y)Example5:“Thereissomeonewholovessomeone.”Solution:∃x∃yL(x,y)Example6:“Everyoneloveshimself”Solution:∀xL(x,x)

Page 53: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

Nega*ngNestedQuan*fiersExample1:Recallthelogicalexpressiondevelopedthreeslidesback:∃w ∀a ∃f (P(w,f ) ∧ Q(f,a))Part1:Usequantifierstoexpressthestatementthat“Theredoesnotexistawomanwho

hastakenaflightoneveryairlineintheworld.”Solution:¬∃w ∀a ∃f (P(w,f ) ∧ Q(f,a)) Part2:NowuseDeMorgan’sLawstomovethenegationasfarinwardsaspossible.Solution:1.  ¬∃w ∀a ∃f (P(w,f ) ∧ Q(f,a)) 2.  ∀w ¬ ∀a ∃f (P(w,f ) ∧ Q(f,a)) by De Morgan’s for ∃ 3.  ∀w ∃ a ¬ ∃f (P(w,f ) ∧ Q(f,a)) by De Morgan’s for ∀ 4.  ∀w ∃ a ∀f ¬ (P(w,f ) ∧ Q(f,a)) by De Morgan’s for ∃ 5.  ∀w ∃ a ∀f (¬ P(w,f ) ∨ ¬ Q(f,a)) by De Morgan’s for ∧.Part3:CanyoutranslatetheresultbackintoEnglish?Solution:“Foreverywomanthereisanairlinesuchthatforallflights,thiswomanhasnottaken

thatflightorthatflightisnotonthisairline”

Page 54: Chapter 1, Part II: Predicate Logicuser.ceng.metu.edu.tr/~mutlu/teaching/kesikliMatematik/Chapter1p2… · Logic Predicate logic uses the following new features: Variables: x, y,

SomeQues*onsaboutQuan*fiers(op#onal)  Canyouswitchtheorderofquantifiers?

  Isthisavalidequivalence?Solution:Yes!Theleftandtherightsidewillalwayshavethesametruthvalue.The

orderinwhichxandyarepickeddoesnotmatter.  Isthisavalidequivalence?Solution:No!Theleftandtherightsidemayhavedifferenttruthvaluesforsome

propositionalfunctionsforP.Try“x+y=0”forP(x,y)withUbeingtheintegers.Theorderinwhichthevaluesofxandyarepickeddoesmatter.

  Canyoudistributequantifiersoverlogicalconnectives?  Isthisavalidequivalence?Solution:Yes!Theleftandtherightsidewillalwayshavethesametruthvalueno

matterwhatpropositionalfunctionsaredenotedbyP(x)andQ(x).  Isthisavalidequivalence?Solution:No!Theleftandtherightsidemayhavedifferenttruthvalues.Pick“xisa

fish”forP(x)and“xhasscales”forQ(x)withthedomainofdiscoursebeingallanimals.Thentheleftsideisfalse,becausetherearesomefishthatdonothavescales.Buttherightsideistruesincenotallanimalsarefish.