Logic in Programming (PROLOG)
Logic in Programming (PROLOG)
(PROLOG)
• Prolog is a logic programming language.
• It has important role in artificial intelligence.
Unlike many other programming languages,
Prolog is intended primarily as a declarative
programming language.
• In prolog, logic is expressed as relations (called as
Facts and Rules).
• Core heart of prolog lies at the logic being
applied.
• Formulation or Computation is carried out by
running a query over these relations.
Syntax and Basic Fields
• [] % empty list
• [a] % singleton list
• [hello, world] % 2 element list
• [[1,2,3,4], p, this] % 3 element list
• [[[1, 2], [3, 4]], [[a, b], [x, y]]]. % nested list
(3 level nesting)
Membership checking
• ?- list_member(b,[a,b,c]).
true
• ?- list_member(v,[a,b,c]).
false.
Append
• The append works on the list in prolog, which
means that append working on combining
two lists or joining two lists together, for
example, if we have two lists and we have to
combine that into one list then append has that
syntax to join two that lists together, we can
also say that append is a relation between lists.
• ?- append([a,b], [c], X).
X = [a,b,c].
• ?- append(X, [Last], [a,b,c]).
X = [a,b], Last = c.
?- append([a,b], More, List).
List = [a,b|More].