Professional Documents
Culture Documents
Syntax:
:- op(+Precedence, +Type, :Name).
The first piece of information required for each operator (whether
pre, in or post -fix) is a number between 1 and 1200 called
the precedence of the operator.
When combining different operators together, the principal
functor of a term represented by a series of operators is the
operator with highest precedence.
For example, suppose + is defined to have precedence 500
and * is defined to have precedence 400. Consider:
a + b * cWe start reading from the left. + has higher precedence,
so it must be the principal functor of the constructed term.
Therefore the term must be:
'+'(a, '*'(b, c))This corresponds naturally to the high school
algebra rule "do multiplications first".
4.1.2 Conditional Expression
Operator which attempts goals conditionally ?-
X -> Y; Z. Keywords: or, conditional,
conditional statement, arrow, operator,
symbol
POPLOG Prolog allows for a simple form of
"conditional statement" in Prolog programs.
The goal:
?- X -> Y; Z. means if X can be satisfied (only
consider its first solution), attempt Y,
otherwise attempt Z.
Note: The conditional cannot appear in a top-
level goal.
4.2.1 Selection Statement
We axiomatize the Prolog selection rule which
always selects the leftmost literal in a goal.
We introduce a new completion of a logic
program which we call the ?-completion of the
program. The ?-completion is formulated as a
first-order theory in a language extended by
new predicate symbols which express
success, failure and left-termination of
queries. The main results of the paper are the
following. If a query succeeds, fails or is left-
terminating under the Prolog selection rule,
then the corresponding formula in the
extended language is provable from the ?-
completion. Conversely, if a logic program
and a query are correct with respect to some
mode assignment and if one can prove in
the ?-completion that the query succeeds and
is leftterminating, then the goal is successful
and Prolog, using its depth first search, will
compute an answer substitution for the goal.
4.2.2 Recursion & Iteration
int Result = 1;
return(Result);
}
execute as following:
Result * Num -> 1*5 = 5 (5 is stored in 'Result' variable)
variable)
Result * Num -> 120*1 = 120 (120 is stored in 'Result'
Sample Logic In Prolog
love(cats)
love(dogs)
animalsthatilove(X):-love(X)
will show:
cats
dogs
loverelations(cats,dogs)
loveofrelated(X):-loverelations(cats,X)
will show:
dogs
End
of
Presentation