2. PROLOG for Knowledge Representation (KR) / Processing (KP) – Introduction
Objectives of this class:
• Introduction into Logic Programming
• Building Knowledge-Based Systems with PROLOG –
First Steps
PROLOG as a Programming Language – Brief History
• Founded in 1970-71 by A. Colmerauer, Marseilles
(“PROgrammation en LOGique” – PROgramming in LOGic).
• First implementation under Philippe Roussel in 1972.
• In the late Eighties of the last century, the language of XS and AI (Artificial Intelligence).
• A non-deterministic and typeless language, mostly interpretative implemented.
• Strong interest from declarative programming, software engineering, and knowledge processing (XS).
• Also used for software and test specification, prototyping,
constraints, natural language processing, VLSI design, etc.
Clauses and Terms – Syntax
• PROLOG programs consist of
– clauses (called also statements), and – terms.
Both clauses and terms can have arguments.
• Clauses can be
– procedure definitions
• facts,
• rules
– procedure calls:
• queries.
• Terms form (are used in) clauses, and can be (incomplete list) – variables (start with upper case letters)
– constants (start with lower case letters)
• atoms: predicates, operators, …
• Integers
– trees, and – lists
Clauses
• Clauses can (should) be sequenced and executed arbitrarily (also concurrently) – leading to the results when interpreted (non-deterministic execution, but
determinable result).
• Clauses end with “.” (dot).
• They consist of literals (predicates
• Control structures in PROLOG are
– sequential/concurrent execution/interpretation, – binding,
– backtracking,
– CUT (“!”), Univ (“=..”), – Input / output
– ...
• Writing a PROLOG program is writing the clauses (procedure definition(s)).
• Running (executing) a PROLOG program is asking questions (query/queries).
• When executed, a PROLOG program – verifies an assumption, or
• Examplesfor facts:
is_female(utta). /* could mean: “Utta is female.” */
loves(utta, otto). /* could mean: “Uttas loves Otto.” */
are_parents(utta, gustav, otto).
/* could mean: “Utta and Gustav are parents of Otto.” */
are_parents(utta, gustav, utta).
/* could mean: “Utta and Gustav are parents of Utta.” */
• Examplesfor rules:
is_sister(Sister, Sistered) :- /* Sister is sister of Sistered if -- */
is_female(Sister), /* Sister is female and */
are_parents(Ma, Pa, Sister), /* Ma/Pa is mother/father of Sister */
are_parents(Ma, Pa, Sistered). /* Ma/Pa is mother/father of Sistered */
• Examplesfor queries:
?- is_female(utta).
true. /* confirm */
?- is_female(otto).
fail. /* refute */
?- is_sister(utta, otto).
true ; fail.
?- is_sister(otto, utta).
But also answer generation (instantiation) possible:
?- is_sister(OTTOS_SCHWESTER, otto).
OTTOS_SCHWESTER=utta ; /* Answer generation */
fail. /* weitere Schwester? */