Assignment 6: Logic Programming
CSE 415: Introduction to Artificial Intelligence
The University of Washington, Seattle, Autumn 2011
Due Friday, November 18 through Catalyst CollectIt at 2:00 PM.

You should turn in three files. First is A6-1.pl containing your answer to problem 1. Second is A6-2.pdf containing your answers to question 2. Third is A6-3.pl with your new version of the ISA.pl Prolog program.

Reference material for this assignment is (a) The SWI-Prolog website, and (b) pages 1-16 of this tutorial by James Lu and Jerud J. Mead, which can be found online: tutorial.
Problems (Total: 100 points).
  1. (20 points) Express the following facts and rule in Prolog.
    F1.  Bigjaws is a shark.
    F2.  Bubbles is a fish.
    F3.  Bubbles doubts that she is well fitted out.
    
    R1:  No shark ever doubts that he is well fitted out.
    R2:  A fish, that cannot dance a minuet, is contemptible.
    R3:  No fish is quite certain that it is well fitted out, unless it has three rows of teeth.
    R4:  All fishes, except sharks, are kind to children.
    R5:  No heavy fish can dance a minuet.
    R6:  A fish with three rows of teeth is not to be despised.
    
    You should make up your own predicate symbols to represent the predicate relations in these premises.

    Make up three "interesting" queries that you run against the database of facts and rules that you create. Include a transcript of making these queries and the responses you get to them in comments in your file.

    We are planning for this problem to be graded in two phases. In the first phase, we will consult your file to check that you have followed Prolog syntax. We may also try one or more of your three proposed queries. Thus you should make sure that your program will load without error into the SWI-Prolog interpreter. If it does not load when we consult it, points will be deducted.

    In the second grading phase, we plan to run a short peer-grading session as part of an upcoming class. Your program will then be graded for semantic content and human readability by an arbitrarily chosen classmate. There will be an appeal process in case of grades that don't seem fair.

  2. (20 points) 2. Consult the ISA.pl PROLOG program in SWI-Prolog.
    1. Issue the query
       isa(great_blue_heron, X).
      
      Copy all the answers that you get.
    2. Issue the query
       isa(X, Y).
      
      How many different answers do you get?
    3. Issue the query
      why(great_blue_heron, bird, Reason).
      
      Explain the answer that you get.

      (Before doing this, you will probably need to go into the Settings menu of SWI-Prolog (not SWI-Prolog-editor), select "User init file ...", and then search for the following lines.

      % :- set_prolog_flag(toplevel_print_options,
            [quoted(true), portray(true), max_depth(10)]).
      
      Change the max_depth value from 10 to 50. Then uncomment the line by removing the percent sign. Save the file. The new value should take effect the next time you launch SWI-Prolog (either directly or from SWI-Prolog-Editor). This will allow list answers of up to around 50 elements to print out without ellipsis.

     
  3. (60 points) Modify the ISA.pl program to obtain a new program that you should name A6-3.pl.
    Add a collection of facts to the database to represent:
    A bird has a wing.
    A bird has a bird_head.
    A bird_head has a beak.
    
    An animal has a body.
    A living thing has a cell.
    A cell has a cell_nucleus.
    A cell_nucleus is organic_matter.
    
    Add rules so that any implied HAS relationships can be inferred automatically.
    You should be able to handle the queries:
    ?- has(great_blue_heron, beak).
    ?- has(aquatic_bird, X).
    ?- has(living_thing, organic_matter).
    
    You should also be able to handle whyhas queries such as
    ?- whyhas(great_blue_heron, organic_matter, Reason).
    
Updates and Corrections If necessary, updates and corrections will be posted here and mentioned in class or on the mailing list. This page was last updated Nov. 8, 2011.