Given the Prolog facts in Example 28 what would Prolog return given these querie

Given the Prolog facts in Example 28 what would Prolog return given these queries?a) ?instructor(chanmath273)b) ?instructor(patelcs301)c) ?enrolled(Xcs301)d) ?enrolled(kikoY)e) ?teaches(grossmanY)Example 28 Consider a Prolog program given facts telling it the instructor of each class and in which classes students are enrolled. The program uses these facts to answer queries concerning the professors who teach particular students. Such a program could use the predicates instructor(p c) and enrolled(s c) to represent that professor p is the instructor of course c and that student s is enrolled in course c respectively. For example the Prolog facts in such a program might include:instructor(chanmath273)instructor(patelee222)instructor(grossmancs301)enrolled(kevinmath273)enrolled(juanaee222)enrolled(juanacs301)enrolled(kikomath273)enrolled(kikocs301)(Lowercase letters have been used for entries because Prolog considers names beginning with an uppercase letter to be variables.)A new predicate teaches(p s) representing that professor p teaches student s can be defined using the Prolog ruleteaches(PS) :- instructor(PC) enrolled(SC)which means that teaches(p s) is true if there exists a class c such that professor p is the instructor of class c and student s is enrolled in class c. (Note that a comma is used to represent a conjunction of predicates in Prolog. Similarly a semicolon is used to represent a disjunction of predicates.)Prolog answers queries using the facts and rules it is given. For example using the facts and rules listed the query?enrolled(kevinmath273)produces the responseyesbecause the fact enrolled(kevin math273) was provided as input. The query?enrolled(Xmath273)produces the responsekevinkikoTo produce this response Prolog determines all possible values of X for which enrolled(X math273) has been included as a Prolog fact. Similarly to find all the professors who are instructors in classes being taken by Juana we use the query?teaches(Xjuana)This query returnspatelgrossman

You can leave a response, or trackback from your own site.
error: Content is protected !!