{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture11.6

Lecture11.6 - 1 Copyright Materials by N Ramsey& al 1...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 12/5/06 Copyright Materials by N. Ramsey & al. 1 DPL-11: Prolog and Logic Programming Prolog Expressive Power : Logic programming, extensions Programming Methodology : Data as relations (unit clauses) of First Order Logic. Code as Well- Formed Formulae of F.O.L. Can give multiple answers No static type system No modularity Two phases to a program: consult data and program, solve a goal Answers are terms that unify with variables. 12/5/06 Copyright Materials by N. Ramsey & al. 2 DPL-11: Prolog and Logic Programming Prolog Implementation : Uni¡cation plus backtracking Ef¡ciency concerns Horn Clause subset of logic No occurs check in most systems Operational semantics dictates a particular search strategy 12/5/06 Copyright Materials by N. Ramsey & al. 3 DPL-11: Prolog and Logic Programming Prolog Prolog programs in two parts: database of "rules" (De¡nite Clauses) each of the form "infer conclusion from premises". If the premises are empty, then we have axioms (Unit Clauses) "query" against database (Goal Clause) 12/5/06 Copyright Materials by N. Ramsey & al. 4 DPL-11: Prolog and Logic Programming Prolog mercury.cs.uml.edu> pl 1 ? consult(user) |: man(socrates). |: mortal(X) :- man(X). |: ^D % user://1 compiled 0.00 sec, 504 bytes Yes ?- mortal(socrates). Yes ?- mortal(Who). Who = socrates; No ?- 12/5/06 Copyright Materials by N. Ramsey & al. 5 DPL-11: Prolog and Logic Programming Prolog More usually consult('my_program.pl'). or ['my_program.pl']. 12/5/06 Copyright Materials by N. Ramsey & al. 6 DPL-11: Prolog and Logic Programming Prolog Syntax vs Logic Horn Clauses: De¡nite clause l 1 ∨ ¬ l 2 ∨ … ∨ ¬ l n A.k.a. "rule" l 1 is called the "head" of the rule Implication ( l 2 ∧ … ∧ l n ) → l 1 Prolog l1 :- l2, … , ln. example mortal(X) :- man(X). A.k.a. "fact" Unit clause l 1 Implication → l 1 Prolog l1. example man(socrates). 2 12/5/06 Copyright Materials by N. Ramsey & al. 7 DPL-11: Prolog and Logic Programming Prolog Syntax vs Logic Goal clause ( ¬ l 1 ∨ … ∨ ¬ l n ) A.k.a. "query" Implication ( l 1 ∧ … ∧ l n ) → Prolog ?- l1, …, ln. example ?- mortal(socrates). 12/5/06 Copyright Materials by N. Ramsey & al. 8 DPL-11: Prolog and Logic Programming Logical Interpretation of Prolog Semantics. If n = 0 the clause G is always true. We can then think of a Prolog program as a proof tree for a "semantic judgment". To prove G , prove, in sequence, H 1 , …, H n , carrying along the transformations built along the way. If the proof of H n succeeds, then apply the transformation to the variables in G . We will now go through a bit of "review" of some parts of the previous lecture - more speciFcally tailored to the semantics of Prolog....
View Full Document

{[ snackBarMessage ]}

Page1 / 11

Lecture11.6 - 1 Copyright Materials by N Ramsey& al 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online