Assignment 4

More Prolog

Due date:
March 6. 11:59pm.

Do

  1. Write a set of prolog rules to collect all of the unique symbols in a list e.g. uniq([a,a,s,a,d,b,a,s,d], X). should yeild X=[a,s,d,b]. (Order does not matter.)
  2. Write a program that randomly selects one from among a group of facts. So, for example:
    fct(a).
    fct(b).
    fct(c).
    onefct(X) :- ....
    
    In this little set of facts and rules, the onefct should match return exactly one fact.
    You will probably find the following rule very useful.
    gtrand(X,Y) :- Y is random(X).
    
    This rule will bind to Y a random integer between 0 and (X-1).
    Hint, you will probaly find it useful to add some extra information to each of my "fct" facts above. Some other pieces of data might also be handy to have. Do not be limited by my example. The only constraint you should obey is that the "onefct" rule should take a single variable which should hold the return value. Note that instead of following the pattern I outlined, you could probably do this by keeping you facts in a list. If you use a list, the prolog "length" function will probably be helpful. You can read about it online.
  3. Write a set of rules and facts that will parse very simple english sentences. The sentences should be input as lists. The rule(s) should return "yes" is the sentence is parseable and "no" if not. The sentences it should successfully parse should be consistent with the E0 grammar of table 22.4. You may do a subset of the E0 grammar so long as you get sentences. Do not worry about efficiency (so chart parsing is unnecessary).For example, depending on the subset of E0 that you implement, the following might return "yes":
    sentence([the, breeze, is, smelly]).
    sentence([a, wumpus, shoot, the, pit]).
    
    and these might return "no"
    sentence([the, go, wumpus]).
    sentence([is, a grab]).
    

Hand in:

100 points -- The rules for each of the above tasks (33,33,and 34 points each). They can be in a single file, just be clear. Recall that "%" can be used to mark the beginning of comments in prolog.