CS61A Lecture 27Clicker poll Slide 3Run (query) and tell it some factsQuery system goal:PowerPoint PresentationQuery: (?who is the parent of bart)Slide 8Query: (?who is the parent of bart)Query: (marge is the parent of ?x)Query: (marge is the parent of ?x)Query:Write a query that returns 0 resultsQuery: (female ?who)Query: (female ?who)Query System: andQuery: (and (?who is the parent of bart) (female ?who))Query: (and (?who is the parent of bart);q1 (female ?who)) ;q2Query 1: (?who is the parent of bart)Query 2: (female ?who)Slide 21Slide 22Slide 23Query: (and (?who is the parent of bart);q1 (female ?who)) ;q2(and (?who is the parent of bart) (female ?who))Query: (and (mona is the parent of ?x);q1 (?x is the parent of ?y)) ;q2Slide 27Slide 28andorSlide 31Slide 32Slide 33Slide 34Slide 35rulesSlide 37Slide 38CS61A Lecture 272011-08-04Colleen Lewis1Clicker poll Have you been reading the provided solutions? A)To labs and/or homeworkB)To projectsC)To labs, homework & projectsD)No 2Clicker poll Are you familiar with the characters from the TV show the Simpsons? A)Yes – very familiarB)Yes – the main charactersC)No – I’m not familiarD)No – I’ve never heard of the Simpsons3Run (query) and tell it some factsSTk> (load "query.scm")okaySTk> (query);;; Query input:(assert! (colleen likes cookies))Assertion added to data base.;;; Query input:4Like (mce): it starts an infinite loopTell the system factsQuery system goal:•Fill in the variables in the query (with all possible sets of values)•NEVER fill in the variables with an inconsistent set of variables56Query: (?who is the parent of bart)7TWO facts match: (?who is the parent of bart) ;query(homer is the parent of bart) ;fact(?who is the parent of bart) ;query(marge is the parent of bart) ;fact8Query: (?who is the parent of bart)?who = homer?who = margeThese are frames!9All facts?who = margeQEval ?who = homerQueryQuery: (?who is the parent of bart)Query: (marge is the parent of ?x)1011All factsQEvalQueryQuery: (marge is the parent of ?x)How many things did you figure out?A. 0 B. 1 C. 2 D. 3 E. ??12All factsQEvalQueryQuery: We can write a query that returns NOTHING•NO knowledge of ANY variables, return nothing.Write a query that returns 0 results13Query: (female ?who)1415All facts?who = monaQEvalQueryQuery: (female ?who)?who = jackie?who = marge?who = patty?who = selma?who = lisa?who = maggieQuery System:and16Query: (and (?who is the parent of bart)(female ?who))17Query Goals:•Fill in the variables in the query (with all possible sets of values)•NEVER fill in the variables with an inconsistent set of variablesLeft with TWO facts: (?who is the parent of bart) ;query(homer is the parent of bart) ;fact(?who is the parent of bart) ;query(marge is the parent of bart) ;fact18Query: (and (?who is the parent of bart);q1(female ?who)) ;q2?who = homer?who = marge19All facts?who = margeQEval ?who = homerQuery1Query 1: (?who is the parent of bart)20All factsQEvalQuery2Query 2: (female ?who)?who = marge?who = homerFor EACH frame we need to compare it to EVERY fact!(female ?who)(female mona) 21Query: (and (?who is the parent of bart);q1(female ?who)) ;q2?who = marge(female ?who)(female marge) … ?who = marge?who = marge?who = mona?who = marge?who = marge(female mona)(female jackie)(female marge)(female patty)(female selma)(female lisa)(female maggie)(female ling) 22Query: (and (?who is the parent of bart);q1(female ?who)) ;q2(female mona)(female jackie)(female marge)(female patty)(female selma)(female lisa)(female maggie)(female ling) ?who = marge?who = homer23All factsQEvalQuery2Query 2: (female ?who)?who = marge?who = homerFor EACH frame we need to compare it to EVERY fact! ?who = marge?who = margeQEval24All factsQuery2?who = marge?who = homer?who = marge?who = margeQEvalAll factsQuery1Query: (and (?who is the parent of bart);q1 (female ?who)) ;q2(and (?who is the parent of bart) (female ?who));;; Query results:(and (marge is the parent of bart) (female marge))25?who = marge?who = margeQuery Goals:•Fill in the variables in the query (with all possible sets of values)•NEVER fill in the variables with an inconsistent set of variablesQEval26All factsQuery2QEvalAll factsQuery1Query: (and (mona is the parent of ?x);q1 (?x is the parent of ?y)) ;q2How many results? A. 0 B. 1 C. 2 D. 3 E.?QEval27All factsQuery2QEvalAll factsQuery1Query: (and (mona is the parent of ?x);q1 (?x is the parent of ?y)) ;q2?x = homer?x = herb?x = homer?x = homer?y = bart?x = homer?x = homer?y = lisa?x = homer?x = homer?y = maggie;;; Query input:(and (mona is the parent of ?x) (?x is the parent of ?y));;; Query results:(and (mona is the parent of homer) (homer is the parent of bart))(and (mona is the parent of homer) (homer is the parent of lisa))(and (mona is the parent of homer) (homer is the parent of maggie))28?x = homer?x = homer?y = bart?x = homer?x = homer?y = lisa?x = homer?x = homer?y = maggieQEval29All factsQuery2QEvalAll factsQuery1and30QEvalAll factsQuery1orQEvalAll factsQuery2mergemerge31QEvalAll factsQuery1QEvalAll factsQuery2mergemerge(or (?x is the parent of bart) (?x is the parent of lisa))How many results do you think there SHOULD be? A. 2 B. 4 C.?32QEvalAll factsQuery1QEvalAll factsQuery2(or (?x is the parent of bart) (?x is the parent of lisa))mergemerge?x = marge?x = homer?x = marge?x = homer?x = marge?x = homer?x = marge?x = homer;;; Query input:(or (?x is the parent of bart) (?x is the parent of lisa));;; Query results:(or (marge is the parent of bart) (marge is the parent of lisa))(or (homer is the parent of bart) (homer is the parent of lisa))(or (marge is the parent of bart) (marge is the parent of lisa))(or (homer is the parent of bart) (homer is the parent of lisa))33?x = marge?x = homer?x = marge?x = homer;;; Query input:(or (?x is the parent of bart) (?x is the parent of ling));;; Query results:34;;; Query input:(or (?x is the parent of bart) (?x is the parent of ling));;; Query results:(or (marge is the parent of bart) (marge is the parent of ling))(or (homer is the parent of bart) (homer is the parent of ling))(or (selma is the parent of bart) (selma is the parent of ling))35?x = marge?x = homer?x = selmaQEval36All factsthe-bodyQEvalAll factsQueryrules;;; Query input:(assert! (rule <the-rule> <the-body>))When a rule (a type of fact) matches, do this:rules;;; Query input:(assert! (rule (parent-of-bart ?person)
View Full Document