Aim of this lecture LPN Ch. 1-3 After this lecture, you should be able to explain the meaning of the following key notions and their relation to Prolog: –logic programming –facts, rules and queries (horn clauses) –unification –(most general) unifier (mgu) –backtracking, depth-first search, forward & backward chaining Important: I will not discuss everything from the book in the lectures, but it is to be studied for the exam (to the extent indicated on blackboard)! I strongly advise you to read the relevant parts of the book before the practical sessions.
It is the knowledge representation language of GOAL, which will be used to program UT2004 agents in Q4 Different programming paradigm It is a challenge! One of the most well-known AI languages Learn fundamental programming concepts, in particular recursion and recursive data structures WARNING: it seems easy at first
Prolog Development Center advanced scheduling systems and speech based applications for manufacturing, retail and service businesses, larger public institutions, airlines and airports http://www.pdc.dk/
Visual Prolog support industrial strength programming of complex knowledge emphasized problems. combining the very best features of logical, functional and object-oriented programming paradigms in a consistent and elegant way. http://www.visual-prolog.com/
Clarissa at ISS fully voice-operated procedure browser, enabling astronauts to be more efficient with their hands and eyes and to give full attention to the task while they navigate through the procedure using spoken commands http://ti.arc.nasa.gov/project/clarissa/
OntoDLV OntoDLV is an intelligent ally for quickly and easily developing powerful knowledge-based applications and decision support systems (e.g. Planning, Customer Profiling or Workforce Scheduling) that otherwise require complex and labourious programming. http://www.exeura.com/
Ontological Logic Programming Murat Sensoy, Geeth de Mel, Wamberto W. Vasconcelos and Timothy J. Norman, "Position Paper: Ontological Logic Programming", Proceedings of the 3rd International Workshop on Semantic Sensor Networks (SSN10), 2010.
Alle mensen zijn sterfelijk m(socrates). s(X) :- m(X). M(socrates), ∀ x(M(x) → S(x)) fact rule Variables capitalized, predicates lower case Implication ( :- ) from right to left Each clause is terminated with a full stop. Clauses are implicitly universally quantified. horn clauses
Head and Body of Rule m(socrates). s(X) :- m(X). fact rule Variables capitalized, predicates lower case Implication ( :- ) from right to left Each clause is terminated with a full stop. Clauses are implicitly universally quantified. body head
Is socrates sterfelijk? m(socrates). s(X) :- m(X). M(socrates), ∀ x(M(x) → S(x)) |= S(socrates) “?-” is the SWI-Prolog prompt asking whether a goal formula logically follows from the knowledge base ?- s(socrates). query
Is socrates sterfelijk? m(socrates). s(X) :- m(X). ∀ → “?-” is the SWI-Prolog prompt asking whether a goal formula logically follows from the knowledge base ?- s(socrates). yes ?-
A Few Remarks Be careful: terminology in Learn Prolog Now differs (somewhat) from standard terminology in predicate logic (in particular atom and term)! Prolog atoms (constants) start with lower case, but can also be an arbitrary sequence of characters enclosed in single quotes Examples: 'Vincent', 'Five dollar shake', '@$%’ Variables start with upper case or underscore
From Redeneren en Logica: A subsitution that makes two literals equal is called a unifier. Searching such a substitution is unification. A most general unifier (mgu) is a unifier θ for which it holds that every unifier is an “extension” of θ. Unification is a fundamental computation mechanism in Prolog! The unifier resulting from unification is what gives Prolog its programming power.
int myInt; myInt = 42; Unification is not Assignment The result of assignment is the assignment of a value to a variable. variablevalue myInt(X) = myInt(42). AssignmentUnification term The result of unification is an mgu or failure if no mgu exists.
int myInt; myInt = 42; Unification is not Assignment The result of assignment is the assignment of a value to a variable. variablevalue MyInt = 42. AssignmentUnification term The result of unification is an mgu or failure if no mgu exists.
int myInt; myInt = 3; myInt = 42; Unification is not Assignment The result of assignment is the assignment of a value to a variable. MyInt = 3, MyInt = 42. AssignmentUnification The result of unification is an mgu or failure if no mgu exists.
Logic & Prolog Kowalski, Predicate Logic as Programming Language, In Proceedings IFIP Congress, pp. 569-574. 1974. LogicProlog Sentences in predicate logic (horn clauses) Program Derivation (using resolution and unification) Computation Proof proceduresExecutors of logic programs
Resolution & Proof Search (1) Predicate logic: ¬B ∨ ¬C ∨ A ¬D ∨ B ¬E ∨ C D E ¬A (¬ conclusion) ¬B ∨ ¬C ∨ A & ¬A = ¬B ∨ ¬C ¬B ∨ ¬C & ¬D ∨ B = ¬C ∨ ¬D ¬C ∨ ¬D & D = ¬C ¬C & ¬E ∨ C = ¬E ¬E & E = ☐ Prolog program: a :- b, c. b :- d. c :- e. d. e. ?- a. ➟ [a] (list of query goals) [b,c] (a :- b, c.) [d,c](b :- d.) [c](d.) [e](c :- e.) true.(e.)
Resolution & Proof Search (2) ResolutionProof search in Prolog find two clauses that can be resolved find a rule with head that unifies with current goal calculate resolventupdate goal list by replacing unified goal with body of rule repeat But: Prolog fixes order in which resolvents are computed. This can influence the result of proof search! That is, procedural meaning can differ from declarative (logical) meaning !
Why learn about proof search? declarative vs. procedural meaning of programs writing correct programs debugging Prolog does it for me, so why should I know how it works?
Key Notions Prolog uses backward chaining, i.e., it only computes if a query is made! linear (top-to-bottom) search for unifying facts or heads of rules depth-first search strategy backtracking if goal fails Important: you should be able to explain using these notions how Prolog searches for a proof of a query!
Backward Chaining Backward chaining: ?- a. true Forward chaining: b. c. a. Prolog uses backward chaining: only computes if a query is made! Alternative is forward chaining, i.e., take the facts and keep on firing rules until no rule can be fired anymore. a :- b, c. b :- d. c :- e. d. e.
Depth-first Search If [q1, …, qn] is the list of query goals, then select the head of the list, i.e., q1 to search for a matching clause. If q1 :- p1, p2, …,pm is the selected unified clause, then update list of query goals to [p1, p2, …, pm, q2, …, qn] and find a matching clause for p1 a :- b, c. b :- d. c :- e. d. e. a.a. b.b.c. d.e.