Why is it usually important to use cuts in logic programs?
Because it makes the logic of programs easier to understand.
Because it greatly reduces the memory utilization.
Because cuts tend to make predicates run in many modes.
Because cuts are necessary to achieve backtracking.
Unification is a form of pattern matching. Which of
the following is {\it not\/} a characteristic of unification?
Unification involves backtracking; if one branch
does not succeed, the unification algorithm tries
another branch.
Unification is permanent; once a unification is
done, it cannot be undone by a later unification.
Unification is symmetric; unifying A with B has
exactly the same effect as unifying B with A.
Unification is active; it can modify the data structures
that are involved in the unification, making later
unifications impossible.
In Prolog, predicates can run in many modes. What
does that mean?
A predicate can have more than one meaning.
A predicate can perform cuts, which limit the size
of search trees.
A predicate can employ backtracking, which allows
it to search for many different solutions.
A predicate can treat different parameters as
inputs or outputs, depending on the context in which it is used.
Prolog data structures can contain variables. A
variable in a data structure represents
a lazy part of a structure, which is computed when
needed by a predicates stored with the variable.
a box whose contents can be changed over time, and
that can take on many different values during the course
of a single successful branch of a computation.
an unknown part of a structure, which will be
typically be filled in later when more information is obtained.
a part of the structure that will never be known,
and will always represent all possible data structures.
In a Prolog goal (or query), unbound variables are
implicitly existentially quantified, with the
system asked to find their values.
implicitly universally quantified, with the system
asked to prove the goal for all values of the variables.
not allowed.
allowed only if the programmer has declared them.
In Prolog, it is not possible to write a function
that performs computation. All computation is performed
by predicates. In general, how can computation of a function be
simulated, using a predicate?
Show the Prolog search tree for goal (X = [1,2],
member(a,X)). Note that a is a constant, not a
variable. The definition of the member predicate is as follows.
Notation [A|B] is Prolog's way of writing A::B. :- is Prolog's
way of writing <=.
Suppose that you know a list Y.
Using only the append predicate, write a goal that
is satisfied just when list Y has the form X ++ X, for
some list X. (Here, ++ means concatenation of lists.)
For example, if Y = [2,4,5,2,4,5], the
goal would succeed, but if Y = [2,4,3,4,6], the goal would fail.
Suppose that you have a value N and a list X.
Using only the append predicate and notation [A|B] for
the list A::B, write a goal that is true just when N is a member
of list X.
The Scheme function assoc can be mimicked by a predicate in Prolog.
Write a Prolog definition of predicate assoc such that
assoc(K,V,X) is true if X is a list of the form [...,(K,V),...].
For example, assoc(4, 7, [(3,6),(4,7),(9,2)]) is true, but
assoc(4, 7, [(3,6),(4,8),(9,2)]) is false. You assoc predicate
should be capable of running in a mode where it tells the value
of V, given the values of K and X.