From leavens@larch.cs.iastate.edu Tue Oct 12 11:40:12 2004 Date: Tue, 12 Oct 2004 11:40:12 -0500 (CDT) From: Gary T. Leavens To: Daniel Patanroi Subject: Re: CS541 HW3 Hi Daniel, On Tue, 12 Oct 2004, Daniel Patanroi wrote: > Dr. Leavens, > > I am working on #6. > What kind of facts and rules I should use here? > Is is like the following: > > facts: > I should take 511,531, etc (according to my POS) in order to graduate. > I took 511,531, etc (the classes I have taken) > I take 541, 661 etc (the classes I currently take) > credit 541 3 (course 541 has credit 3) > score 541 A (course 541 has a score of A, hopefully :) > ... > > rules > to graduate, the following has to be satisfied: > - both 511 531 are B- or better > - have taken 591 > - etc > > > I guess I am not clear how deep I should do this problem. > Please kindly explain. I was thinking that you would basically just code the facts about what you are taking, when you took it etc. I didn't intend for you to try to code up all the rules for what it takes to graduate (that would be too much). So just encode what you've taken and information about that. I can give extra credit, say 40 points, for coding the rules for what one has to do to graduate. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------- From leavens@larch.cs.iastate.edu Tue Oct 12 21:28:32 2004 Date: Tue, 12 Oct 2004 21:28:32 -0500 (CDT) From: Gary T. Leavens To: rhe@cs.iastate.edu Subject: Re: Questions in Homework 3 Hi Ru, On Tue, 12 Oct 2004 rhe@cs.iastate.edu wrote: > Could you be kind enough to answer my following questions in Homework 3? Of course. > I have read your answer to Daniel. But I still have some doubts in the > requirement of Question 6. > > In your reply, you seperate what one has taken and what > one has to take in the future. Do you mean that we basically just need to > provide the information of the course we have taken? > Or we need to provide information for both the courses we have taken and ones we > are going to take in the future? I don't want to be too specific, but imagine that one would ask if you have taken various specific courses, and when you took them, and what grades you got. This kind of information is on the POS form. However, I would say give the information for both the ones you have taken and are planning to take. > If we just need to provide the information of the course we have taken, how > could we set the rules for the graduation if the courses we have taken are not > enough? You don't have to code up the rules for graduation, unless you want to do the extra credit. > Could you give some basic framewrok about how detailed we should set the rules > for the graduation? For the extra credit work, this should be more or less a translation of the rules from the department's graduate handbook. See the web page. I think it should have all the rules that are there, ideally. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------------- From leavens@larch.cs.iastate.edu Tue Oct 12 21:38:26 2004 Date: Tue, 12 Oct 2004 21:38:26 -0500 (CDT) From: Gary T. Leavens To: Neeraj Khanolkar Subject: Re: Speciying Set observers Hi Neeraj, On Tue, 12 Oct 2004, Neeraj Khanolkar wrote: > This question relates to problem 8 on hw3. > > Is it OK if we specify the delete operation to produce a 'bad' set i.e. > one in which some elements are repeated. For example if we begin with a > 'bad' set then delete all occurrences of a certain element X, there may > still be other elements that are repeated in the result set. The problem says that you are to specify the mathematical content, even if the same element is repeated. So I don't think it would be right to only take out the first occurrence in a set term of an element that is being removed. But it's fine to leave other repeats of elements that aren't deleted. > Should we care about maintaining the purity of the internal represenation > as long as our observers are specified mathematically correct? What internal representation? I think there are only set terms. > So for example in Union can I just throw the 2 sets together without > caring to remove repetions either existing originally or formed due to > this union? If that works properly with the other operations, that's fine then. > The size operation will still give the mathematically correct > answer on the result set and the result set will satisfy the property that > every element in it, is in one set or the other in the union. Then that sounds fine. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------- From leavens@larch.cs.iastate.edu Tue Oct 12 22:30:26 2004 Date: Tue, 12 Oct 2004 22:30:26 -0500 (CDT) From: Gary T. Leavens To: rhe@cs.iastate.edu Subject: Re: Questions in Homework 3 Hi Ru, On Tue, 12 Oct 2004 rhe@cs.iastate.edu wrote: > Thank you for your quick reply. Could you be kind enough to answer my following > questions? Sure. > Are there any operators in lambda-Prolog providing the function like "==" and > "!=" to compare the terms of any polymorphic type A? > > Like > type '!=' A -> A -> o. The = operator in lambda Prolog has the type A -> A -> o. It compares terms to see if they unify. There is no != operator in lambda Prolog, although some Prologs do have such an operator. You can use (x \ y \ not (x = y)) in some circumstances, but beware of applying not to terms that contain logical variables (as we will discuss in class later). Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------------- From leavens@larch.cs.iastate.edu Thu Oct 14 18:19:08 2004 Date: Thu, 14 Oct 2004 18:19:07 -0500 (CDT) From: Gary T. Leavens To: Daniel Patanroi Subject: Re: coms541 hw3 Hi Dan, On Thu, 14 Oct 2004, Daniel Patanroi wrote: > Is there a way to store some predefined variables/constants for > debugging purposes? > > For example, on the 'set' problem, is it possible to store > (set_insert(set_insert emptyset 5)6) as setA? Yes, the trick is to make a predicate that unifies a logical variable in a query with the term you don't want to retype during testing. So I would do this as follows. Make a module, set_test, say, and in the signature file put sig set_test. accum_sig set. type setA, setB (set int) -> o. and then in the module put module set_test accumulate set. setA (set_insert(set_insert emptyset 5)6). setB X :- setA Y, set_union Y Y X. And then you can do queries like: ?- setA SETA, has 5 SETA. etc. I often find indexing tests by integers to be handy. See, for example the following (more in the operational-semantics directory under the course lecture notes): sig while_test. accum_sig while. type test int -> command -> o. % runs the ith test. type run int -> store int -> o. module while_test. accumulate while. run I Sigma :- test I C, meaning C Sigma. test 1 (semi (assign (loc 1) (num 1)) (assign (loc 2) (num 2))). test 2 (semi (assign (loc 1) (num 1)) (if (deref (loc 1)) (assign (loc 1) (num 3)) (assign (loc 1) (num 4)))). test 3 (semi (assign (loc 1) (num 1)) (while (deref (loc 1)) (assign (loc 1) (num 0)))). > What does it mean by running backward? We usually consider the last "argument" to a predicate to be the result; and thus running backwards is when the last argument is a ground term, instead of a logical variable. > Suppose I run > ?- set_intersect Set (set_insert emptyset 5) (set_insert emptyset 5) > Should it give some answers? It's not required in this homework that that work. However, my solution gives: [set] ?- set_intersect Set (set_insert emptyset 5) (set_insert emptyset 5). The answer substitution: Set = set_insert emptyset 5 so you may be interested in trying it... Like lazy evaluation making things work for infinite lists, Prolog makes running backwards work a surprising amount of time. But generally speaking, making predicate run backwards is more a curiosity than something very useful; although it can save coding inverse functions and thus lead to less coding. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------------- From leavens@larch.cs.iastate.edu Thu Oct 14 18:20:58 2004 Date: Thu, 14 Oct 2004 18:20:58 -0500 (CDT) From: Gary T. Leavens To: Daniel Patanroi Subject: Re: coms541 hw3 Hi Dan, On Thu, 14 Oct 2004, Daniel Patanroi wrote: > Sorry, I have one more question. No apology needed, I'm happy to help. > For dequeue on #11, do we ignore the occurrence of duplicates? > In specific, deq_size and deq_count should count two occurrences of > item A twice. > Is that true? Yes, in queues, unlike sets, something can appear in the queue multiple times. Three cans of coke in a line are different than two cans of coke in a line. :-) Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------