Solutions to practice quiz

  1. Write a clearly legible T to the left of each of the following that is true, and a clearly legible F to the left of each that is false.
    1. T In Prolog, all computation is performed by predicates, with none performed by functions.
    2. T In Prolog, an unbound variable can be part of a data structure.
    3. F In Prolog, an unbound variable is uninitialized, and using it without initializing it usually leads to serious errors in programs.
    4. F Prolog allows axioms to be any formula of first order logic. Only atomic formulas and Horn clauses are allowed.
    5. T Variables in Prolog axioms are implicitly universally quantified.
    6. T Cuts are used to reduce memory requirements and to speed up computation. Nothing on cuts will be on the quiz.
    7. F It does not matter in what order axioms in a Prolog program are written. Axioms are tried in the order in which they are written.

  2. Unification is a form of pattern matching. Which of the following is not a characteristic of unification?

    Unification never changes the binding of a bound variable.

  3. A cut in a Prolog program

    Removes backtrack control frames from the control stack.

  4. Which of the following is not a characteristic of the Prolog append predicate?

    It should only be used in one mode because its definition includes a cut.

  5. Backtracking

    is a control structure that involves trying more than one answer to an expression or statement.

  6. In a Prolog goal (or query), unbound variables

    are implicitly existentially quantified, with the system asked to find their values.

  7. Suppose that you know a list Y and a value A. Using only the append predicate and the [|] notation, write a goal that is satisfied just when Y is nonempty and the last member of list Y is A.

    append(X,[A],Y).

  8. Write a definition in Prolog of a predicate called allare so that allare(X,A) is true just when X is a list all of whose members are A. For example, allare([3,3,3,3],3) is true, and allare([a,a],a) is true. Note that allare([],2) is true. Do not use any other basic predicates, such as append or member, for this definition.
         allare([],X).
         allare([H|T],H) :- allare(T,H).
      

  9. Show the Prolog search tree for goal (member(X,[3,4,5]), member(X,[4])), up to the point where a success is found. The definition of the member predicate is as follows.
          member(M, [M|X]).
          member(M, [X|T]) :- member(M, T).
      

                    member(X,[3,4,5]), member(X,[4])
                   /                                \
                  / X = 3                            \
                 /                                    \
         member(3,[4])                 member(X,[4,5]), member(X,[4])
              |                       /                             \
         member(3,[])                / X = 4
              |                     /
              x                member(4,[4])
                                   |
                                success