[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] /19q.html [19q.txt(Text)] [Search ]
Tue Jun 5 16:19:48 PDT 2012
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS320/19 Questions on Logic Programming

      Question 1

      a. Give the name of the language designed to support logic programming that was developed by Colmerauer, Roussel & Kowalski.

      b. Give an example of a compound term in this language. What are its parts called?

      c. Define: arity, functorial form, unification, resolution, backtracking.

      d. distinguish "functor" from "function" -- which does Prolog have?

      Question 2

      Give examples of

      Question 3

      a. Draw a diagram of the Prolog data structure used to store (1): f(1,X),
      (2): 1 + X, (3): teacher(dick), and (4): +X.

      b. Show how 1+(2*3) is stored in Prolog. Show 1+2*3. Show (1+2)*3. Which of these are identical?

      c. Draw a UML class diagram of the Prolog data structure.

      Question 4

      A friend of yours needs to learn Prolog and has sent you EMail requesting help... write a reply explaining what they need to know and giving examples they should try during their first meeting with Prolog .

      Question 5

      Give a list of simple hints that you would give to a C or C++ programmer who had to learn Prolog.

      Question 6

      Trace what happens if you input the query underlined below
                     ?- f( [1,2,3], S ).
      with a Prolog database that has the following facts and rules about f in it:
                    f( [], 0 ).
                    f ( [ H | T ], S ) :- f( T, X), S is X + H.

      Question 7

      a. What is the Closed World Assumption?

      b. Give an example of its effect.

      c. Why is this an important limitation?

      Question 8

      a. Give a list of questions that are frequently asked by C++ programmers when they are attempting to learn Prolog for the first time.

      b. Give good answers to each of the questions generated in part a above.

      Question 9 -- Is it true that GEICO can save you 15 percent

      a. Suppose you were choosing car insurance. You have collected data on a dozen companies and for each the cost of a similar car insurance policy.

      Show how you would include this data base in Prolog. As examples encode
      Table
      CompanyCost
      'Farmers'950
      'AAA'900

      (Close Table)

      b. Your current company is costing you 930. Write a query that accesses the data on 'GEICO' and tests the claim that 'GEICO' can save you 15%.

      Note: be careful of quotation marks!

      Answer to Question 3

      a. Explain how (1): f(1,X), (2): 1 + X, (3): teacher(dick), and (4): +X are stored in Prolog.

      All structures in prolog are stored in functorial form. This is a data structure where every node is an object that has one functor and zero or more parameters or arguments. The number of parameters is called the arity, In the above cases:
      Table
      ExpressionFunctorArityParameters
      1 + X+2constant 1, variable X
      f(1,X)f2constant 1, variable X
      teacher(dick)teacher1constant dick
      +X+1variable X.

      (Close Table)

      Here are the object diagrams using the UML:

      See table above

      b. Draw a diagram of 1+(2*3). Show 1+2*3. +(1, *(2,3))

      (Note. Precedence makes the first two expressions the same.... )

      c. Draw a UML class diagram of Prolog data structures.

      Atomic and Composite Terms

      Note

      This is an example of the Composite pattern.

      Answer to Question 5

      Trace what happens if you input the query underlined below
                    ?- f([1,2,3], S).
      and a Prolog data base has the following facts and rules in it:
                    f([], 0).
                    f([ H | T ], S) :- f( T, ST), S is ST+H.

      Try it on the computers!

       1 ?- trace, f([1,2,3], S).

      Here is another form of answer that shows each call and its matching exit:

           Call: f([1,2,3], S)
           |     Call: f([2,3], ST)
           |     |     Call: f([3], ST)
           |     |     | Call: f([], ST)
           |     |     | Exit: f([], 0)
           |     |     | --(ST=0)
           |     |     | Call: S is 0 + 3
           |     |     | Exit: S=3
           |     |     Exit: f([3], 3)
           |     | --(ST=3)
           |     |     Call: S is 3 + 2
           |     |     Exit: S=5
           |     Exit: f([2,3], 5)
           |     --(ST=5)
           |     Call: S is 5 + 1
           |     Exit: S=6
           Exit: f([1,2,3], 6)
           --(S=6)

    Review

End