Page 211 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 211
Unit 14: Prolog
Notes
Notes Observe that the semicolon in Goal1 -> Goal2 ; Goal3 is not the normal disjunction
operator; if it were, you would be capable to obtain solutions to Goal1 -> Goal2 and then,
upon backtracking, also obtain solutions to Goal3. But this never happens. Rather, -> and;
have to be interpreted as a unit.
!
Caution We do not suggest mixing cuts with if–then or if–then–else structures.
14.5.4 Variable Goals and Calls
Variables can be utilized as goals. A term G which is a variable appearing representing a goal is
transformed to the goal call(G). Note that call is not clear to cuts.
14.5.5 Repeat
The predicate repeat functions in the traditional manner, i.e., whenever backtracking reaches it,
execution continues forward again via the same clauses as if another substitute had been found.
14.5.6 Once
The query once(Goal) locates exactly one solution to Goal. It is comparable to call((Goal,!)) and
is opaque to cuts.
14.5.7 Negation
The negation predicate is written \+ and is obscure to cuts. That is, \+ Goal is like call(Goal)
apart from its success or failure is the opposite.
Note that extra parentheses are needed around compound goals (e.g., \+ (this, that)).
Self Assessment
Fill in the blanks:
8. The predicate ...................... functions in the traditional manner, i.e., whenever backtracking
reaches it, execution continues forward again via the same clauses as if another substitute
had been found.
9. The query ...................... locates exactly one solution to Goal. It is comparable to call((Goal,!))
and is opaque to cuts.
14.6 Arithmetic Operators
Prolog has the usual range of Arithmetic Operators (+, -, =, * ..)
Prolog must be able to manage arithmetic in order to be a functional general
purpose programming language. Though, arithmetic does not fit well into the logical plan of
things.
LOVELY PROFESSIONAL UNIVERSITY 205