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
I was wondering if the books.pl file is supposed to hold the atomic statements and the books.txt file is supposed to hold the queries and the output from the computer.
A4
Yes, you can do this.

Q5
For Question 2 and 3 for part 1 of the assignment you ask to query for the book with a long title such as Artificial Intelligence: A Modern Approach. However Prolog does not allow us to input atomic statements which start with capital letters or spaces. Thus, the query will always fail unless the title of the book is modified. Clarification would be appreciated.
A5
Any abbreviation of the title is acceptable, as long as it is a constant that has correct syntax from Prolog's point of view and TA can understand what your abbreviation means.

Q6
Can we use the symbol ";" in the bodies of our rules?
A6
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.

Q7
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.
A7
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.

Q8
Can we use loops or lists to formulate queries in Part 1 of the assignment?
A8
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.

Q9
In Q10, to find the best price, do we only need to make it so that it finds the best price 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 1 harry potter book store or 50 harry potter book store or more)
A9
Your query should find the best bookstore in a general case, i.e., for any set of atomic statements.

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

Q11
In Part 1 of the assignment, queries 9 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.
A11
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 9 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.

Q12
I was wondering how detailed does the knowledge base need to be? for instance, in question 1, number 4: "is there a bookstore that is shipping books for less than 10 to cities other than Toronto " I'm confused as to how the predicates should work. Do I just randomly make 'city' atoms? Can I introduce my own predicates?
A12
Read the assignment carefully: your KB should be written using the predicates given to you: hasBook, lives, shipping. It is up to you what facts are you going to include in your KB. But you cannot use any other predicates in Part1 except of those given to you. In your queries, you can also use equality and inequality relations. When you write your KB, you might wish to group all your hasBook atomic statements together, also write consecutively all your lives facts, and group together your shipping facts. Otherwise, if you mix these facts, so that the predicates are not consecutive, then you have to tell the compiler that these predicates are dynamic (this is the keyword to the compiler). Read the handout on ECLiPSe Prolog.

Q13
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.
A13
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 the slide 17 (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.

Q16
What kind of graph am I supposed to draw in Part 3 to explain my answer?
A16
A simple graph with r1, r2, r3, goal in the verticies and the edges between these vertices. As an explanation, you have to write a brief essay 5-10 sentences explaining informally why the answers that you got are correct, and to argue that you found all the answers, i.e., none is missing. Do not provide any back-chaining trees. An informal, but convincing argument in English is expected.

Q17
For question 2, if you didn't specify the region X and Y are distinct should we make that assumptions for our rules?! such as in partOf(), touch(), overlap() and etc.
A17
When you write a rule implementing a new predicate in Part 2, the condition whether 2 regions must be distinct or not usually follows implicitly from the context provided by specification in English. For example, in the case of partOf() the regions can be distinct or not, but in the case of touch() they must obviously be distinct.

Q18
For the partOf(X,Y) predicate of Part 2, you gave the following hint: "... this is true if there is no region Z such that Z is connected with X, but Z is not connected with Y." You also stated that r2 is not a part of r4 (looking at the picture, this must be the case, as it is a region that clearly lies outside of r4). However, X (r2 in this case) does not have any regions connected to it at all, meaning it should pass the hint. Could you clarify this part please?
A18
I guess you interpret the given diagram differently. The region r2 is a large rectangle in the middle-top part of the diagram, and region r4 is an elongated rectangle intersecting with r1, r2 and r3. These intersections are called r14, r24, r34, respectively. In the assignment, it is clear that r2 and r4 are connected, namely, they overlap, and the region r24 is their intersection. Therefore, X=r2 is not part of Y=r4, since there is a region, namely the bottom edge of r2, called r2bt such that
connected(r2bt,r2bt).
connected(r2bt,r2). connected(r2,r2bt).
but this bottom edge r2bt is not connected with r4. In all cases, if you would like to check details of each definition given in the Part 2 of the assignment, consult the file connected.txt posted on D2L in the Assignments folder.

Q19
What constitutes a region? For example, is r24mid a region?
A19
Everything that is an argument of the predicate connected() is considered a region. For simplicity, assume that a region is a part of the given drawing that is internally connected and closed. Some regions are two-dimensional, some other regions are one-dimensional. But the middle point r24mid (not shown explicitly in the drawing) is also deemed to be a region. The white space outside of the 10 regions named in the given diagram is not a region.

Q20
Are we allowed to write additional atomic statements for part 2 or only rules?
A20
If you feel it is really nessesary to add more regions, you can add a few atomic statements. However, in Part 2, all you have to do is to implement rules described in the assignment. The specifications of predicates are written in way to make translation from English to Prolog easy. You get marks mostly for correct Prolog rules and some marks for testing of your rules. Note that the TA will be testing your Prolog program in Part 2 using his own queries, and he will be looking for expected answers based on the regions defined in the file connected.txt

Q21
Just a quick question for part 2, is r5 inside r6?. The reason I ask is I don't understand what constitutes "sharing a border", i.e. in my mind I don't believe a circular border touching a square border constitutes sharing a border.
A21
I queried my program, and the answer is no, i.e., r5 is not inside r6. This is because there is a common region r9 on their borders, see the previous item "tangentPartOf" for clarifications.

Q25

A25


CPS721