Questions related to the 1st assignment

Questions about the 1st assignment and answers to them will be linked from this page.

Q1
I was just wondering if its ok to work on the assignments with other people ?
A1
You can work on the assignments with any students registered in cps721, but the number of people in your team must be less than or equal to 3.

Q2
I was wondering where I can find the handouts you were using in class.
A2
Take notes in class: write down the most important definitions and ideas. Also, visit cps721 folder on D2L to download copies of slides.

Q3
I was wondering if you want us to buy both textbooks, and if so, do you have some sort of recommended readings/chapters for each book that relates to this course, or do you expect us to read both the entire books?
A3
As I mentioned in class, you have to buy only one textbook: Hector Levesque's "Thinking as Computation". The bookstore has many copies. All other books are supplementary reading. Some of their sections assume that the reader has a certain level of mathematical maturity.

Q4
Can we use the symbol ";" in the bodies of our rules?
A4
No, you are not allowed to use ";" and you also are not allowed to use symbols "->" and "!" when you work on your assignments. Note that any rule with disjunction (i.e., with ";") in its body can be written as a couple of rules with the same predicate in the head, but with different bodies.

Q5
Suppose we have the following clauses (taken from KB5 in the online Prolog tutorial):

 loves(vincent,mia).
 loves(marcellus,mia).
 loves(pumpkin,honey_bunny).
 loves(honey_bunny,pumpkin).
 jealous(X,Y) :- loves(X,Z),loves(Y,Z).
So, if I do this:
?- jealous(marcellus,W).
Then the answer will certainly be:
W = vincent
Because according to the tutorial, we are looking for an individual W such as that marcellus is jealous of W, and apparently vincent satisfies this, which is why W = vincent. Now, having said that, I tried the opposite:
?- jealous(vincent,W).
Ideally I would expect Prolog to give: W = marcellus. Yet, it turns out that Prolog gives: W = vincent which is clearly wrong. Could you please explain to me as to why this happens? As a sidenote, I tried switching the order between the first two lines of the program, and when I try:
?- jealous(vincent,W).

then Prolog correctly returns: W = marcellus. However if I do the opposite:
?- jealous(marcellus,W).

Prolog incorrectly returns: W = marcellus.
A5
The back-chaining procedure must consider all atomic statements and rules in a specific order when it is searching for an answer to a query. This guarantees that all atomic and conditional statements will be considered exhaustively and the correct answer will not be missed. In particular, the back-chaining procedure consideres atomic and conditional statements always from the top of the file to the bottom.
However, if a Prolog program is well written, then the answers to queries will not change no matter in which order a programmer writes atomic statements. So, you are right in pointing out that something unexpected happens in this example (perhaps, because it was simplified to illustrate programs without negation). The programming style of this example can be easily corrected:
         jealous(X,Y) :- loves(X,Z), loves(Y,Z),  not X=Y.
This means that the values of variables X and Y must NOT be equal (this is assumed implicitly when we think about "jealous"). Using different names of variables in any rule does not guarantee that their values must be different: we have to say this explicitly in the rule. If you will use this corrected conditional statement, then no matter in which order you will write atomic statements, the answer to both queries
?- jealous(marcellus,W).
?- jealous(vincent,W).
will be correct and will correspond to what you expect.

Q6
Can we use loops or lists to formulate queries in Part 1 of the assignment?
A6
No, you can use only Prolog constructs that we already studied in class: conjunction, negation, predicates given to you (they may have variables and constants as their arguments), equality and inequality (<) between arithmetical expressions. In Q10, you can use also the addition operator (+) because you have to compare the sum of the list price and shipping cost from one bookstore with the sum of the list price and shipping cost from another bookstore.

Q7
In Part1, Query 11, to find the last album, do we only need to make it so that it finds the last album in our own set of atomic statments, or goes it have to work in a general case (ie the query should work with any other set of atomic statments whether there are 5 Drake's albums or 50 Drake's albums or more)
A7
Your query should find the latest Drake's album in a general case, i.e., for an arbitrary set of atomic statements.

Q8
Can we use anonymous variables in our queries?
A8
No, to avoid confusion, please try using named variables only to formulate queries as it was discussed in class.

Q9
In Part 1 of the assignment, queries 11 and 10 are difficult to write in Prolog. Can I write them using rules with recursion? If not, please give me a hint on how can I write these queries.
A9
In Part 1, you can write queries only. So, you are not allowed to write any rules (recursive, or otherwise). If you cannot formulate quires 11 and 10 in Prolog directly, think how you can reformulate them in English so that the reformulated query is easy to express in Prolog. Make sure that you do logically equivalent transformation when you transform one logical statement in English into another statement in English.

Q10
is there a way to stop repetitive results from occuring? (i.e. X=a,Y=b followed by Y=b,X=a). I'm finding that some of the later questions produce far more results then they really need to.
A10
In Part 1 of the assignment, the most important is to make sure that your queries are rendered in Prolog correctly. Repetitions in answers are fine. We discussed in class when and why this happens when I was talking about queries in Prolog with equality in "Prolog basics". The issue of how to prevent repetitive answers to a given query is beyond the scopes of this assignment. You are only responsible to make sure that all the answers are correct with respect to your KB.

Q11

A11

Q12

A12

Q13

A13

Q14

A14

Q15

A15

Q16

A16

Q17

A17

Q18

A18

Q19

A19

Q20

A20

Q21

A21

Q25

A25


CPS721