hw15 - CS 61A HOMEWORK = 4.56 Week 15 Solutions (and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 61A Week 15 Solutions HOMEWORK ======== 4.56 (and (supervisor ?x (Bitdiddle Ben)) (address ?x ?y)) (and (salary ?x ?s1) (salary (Bitdiddle Ben) ?s2) (lisp-value < ?s1 ?s2)) (and (supervisor ?who ?boss) (not (job ?boss (computer . ?y))) (job ?boss ?z)) The key point here is that we use the same variable name twice if we want it to match the same item both times. 4.57 (rule (same ?x ?x)) ;; Don't use (lisp-value eq? . ...) (rule (replace ?p1 ?p2) (and (or (and (job ?p1 ?x) (job ?p2 ?x)) (and (job ?p1 ?x) (job ?p2 ?y) (can-do-job ?x ?y))) (not (same ?p1 ?p2)))) (replace ?x (Fect Cy D)) (and (replace ?x ?y) (salary ?x ?s1) (salary ?y ?s2) (lisp-value < ?s1 ?s2)) 4.58 Note the definition of a sub-rule to make things more manageable. (rule (sup-in-div ?p ?x) (and (supervisor ?p ?boss) (job ?boss (?x . ?z)))) (rule (big-shot ?person ?division) (and (job ?person (?division . ?x)) (not (sup-in-div ?person ?division)))) 4.65 This problem requires understanding the basic idea of how the query system works (read Section 4.4.3). To respond to a query, the query system generates a stream of frames which are then used to "instantiate" the query. In this case, the stream will include frames containing all bindings of ?middle-manager, ?person and ?x satisfying the body of the rule, and also with ?who bound to ?person.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Since Warbucks supervises Bitdiddle and Scrooge, each of who manages other people, there will be more than one of these frames. Hence Warbucks appears more than once in the output. Extra for Experts ================= Here's the REVERSE from lecture: (assert! (rule (reverse (?a . ?x) ?y) (and (reverse ?x ?z) (append ?z (?a) ?y) ))) (assert! (reverse () ())) Why won't this run backwards? It's important to understand this, in order to solve the problem. Unfortunately there are a lot of details, so here's a preview of the punch line: It'll turn out that the query system tries to use the recursive rule over and over, in effect constructing longer and longer lists whose elements aren't known, and never realizing that they can't possibly be the reverse of the given list. Let's try to work out what happens if we give the simplest possible
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2011 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 6

hw15 - CS 61A HOMEWORK = 4.56 Week 15 Solutions (and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online