Page 84 - DCAP310_INTRODUCTION_TO_ARTIFICIAL_INTELLIGENCE_AND_EXPERT_SYSTEMS
P. 84
Introduction to Artificial Intelligence & Expert Systems
Notes through the fact and rule data base while unification is used for pattern matching and returns the
bindings that make an expression true.
Notes The unifier is applied on two terms and tries to combine them both to form a new
term. If unification is not possible, then unification is said to have failed. If the two terms
contain no variables, then unification actually reduces to checking whether the terms are
equal.
Prolog is a general purpose logic programming language associated with artificial intelligence
and computational linguistics. Prolog has its roots in first-order logic, a formal logic, and unlike
many other programming languages, Prolog is declarative: the program logic is expressed in
terms of relations, represented as facts and rules. A computation is initiated by running a query
over these relations. Prolog was one of the first logic programming languages and remains the
most popular among such languages today with many free and commercial implementations
available. While initially aimed at natural language processing, the language has since then
stretched far into other areas like theorem proving, expert systems, games, automated answering
systems, ontologism and sophisticated control systems. Modern Prolog environments support
creating graphical user interfaces, as well as administrative and networked applications.
5.6.1 Prolog Lists
Lists themselves have the following syntax. They always start and end with square brackets, and
each of the items they contain is separated by a comma. Here is a simple list
[a,freddie,A_Variable,apple]
Prolog also has a special facility to split the first part of the list (called the head) away from the
rest of the list (known as the tail). We can place a special symbol | (pronounced ‘bar’) in the list
to distinguish between the first item in the list and the remaining list. For example, consider the
following.
[first,second,third] = [A|B]
where A = first and B=[second,third]
The unification here succeeds. A is bound to the first item in the list, and B to the remaining list.
Example 1: Here are some example simple lists
[a,b,c,d,e,f,g]
[apple,pear,bananas,breadfruit]
[ ]/* this is a special list, it is called the empty list because it contains nothing */
Now lets consider some comparisons of lists:
[a,b,c] unifies with [Head|Tail] resulting in Head=a and Tail=[b,c]
[a] unifies with [H|T] resulting in H=a and T=[]
[a,b,c] unifies with [a|T] resulting in T=[b,c]
[a,b,c] doesn’t unify with [b|T]
It doesn’t unify with [H|T]
It unifies with []. Two empty lists always match
78 LOVELY PROFESSIONAL UNIVERSITY