B :- A
Implication, A -> B
,
And
;
Or
Atom
Number
Any sequence of numbers, possibly containing a dot
Variable
A sequence of letters, digits or underscores that starts with an upper case letter or an underscore (Car)
_ is the anonymous variable
A term is defined recursively:
Predicate
Any constant or compound term
Fact
A predicate immediately followed by a dot
Rule
A predicate is a rule if:
A0 is the head, A1, …, An is the body of the rule
Clause
Any fact or rule,
Are universal
Definition of a predicate
The set of all facts and rules that use a certain predicate P,
if there is no definition in a certain program, P is called undefined
Built in predicate
Defined by SWI Prolog (member/2)
Query
Defined as ?-p
Where p is some predicate known as a goal
Constant
Atoms and numbers
Two terms t1 and t2 match iff
=/2
Matching predicate, binds variables using the most general unifier
=/2
Can be used to check terms that do not match
/+
Negationwith finite failure
/+ f is true in program P iff f cannot be derived from P and the program terminates
/+ G can be derived from P iff the search tree of P for G is finitely failed
Its not saying f is false, it is saying there is not enough information to prove f is true
A search tree for a program for a goal is called finitely failed when:
=:=
Checks if computation on the left is equal to computation on the right
(4+3=:=5+2 evaluated to True)
==
Checks if the computation on the left differs from the computation on the right
4+3==5+2 evaluates to false
4+3==2+2 evaluates to true
is operator
Has an arithmetic expression on the right side, evaluates it and unifies the result with the variables in the left side
Left side:
- variable
- it checks if this value matches the evaluated result of the expression the right
(X is 2+2 evaluates X=4)
Lists
Store compound terms
Symbol:
[] (empty list has no head or tail)
Have a head (term) and a tail (list)
Head is the first element alone, tail is the rest of the body
[Head|Tail]