17 LogicProg - 1 Logic Programming Scott Chapter 11 2 Logic...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Logic Programming Scott, Chapter 11 2 Logic Programming • Recall – functional programming • computing with functions • foundation: lambda calculus – imperative programming • computing with side effects • Turing machine 3 • Logic programming – computing with relations – foundation: predicate calculus – while functional and imperative languages implement the full power of the lambda calculus or Turing machine, logic programming only implements a restriction of the predicate calculus – logic programming is still surprisingly powerful 4 • The most widely used logic programming language is Prolog (1972) – Roussel and Colmerauer at Aix-Marseille – Kowalski at Edinburgh • We will focus on Prolog 5 • Computing in Prolog: – The programmer provides database of facts and rules of inference – Queries formulated as assertions involving facts in database – Program execution = attempting to prove an assertion. 6 Synax <term> ::= <constant> | <variable> | <structure> <constant> ::= <number> | <atom> <structure> ::= <functor> ( <term>(,<term>)* ) <functor> ::= <atom> <atom> ::= <lowercase>(<letter>| some other things )* <variable> ::= <uppercase>(<letter>| some other things )* Example: near (house, X, 22, distance(Y)) constants: house, 22 variables: X,Y functors: distance, near structures: distance(Y), near (house, X, 22, distance(Y)) 7 • A database is constructed out of facts and rules – constants representing people: tom,dick,harry, jane, judy, mary – predicates: fatherOf, motherOf, parentOf, grandparentOf, siblingOf Facts: fatherOf(tom,dick). %read “the father of tom is dick” fatherOf(dick,harry). fatherOf(jane,harry). motherOf(tom,judy). motherOf(dick,mary). motherOf(jane,mary). %period terminates facts and rules, %which may use more than one line 8 • While we choose the facts to have some interpretation, to Prolog, they are just structural building blocks with no meaning except the explicitly stated relationships • We can think of fatherOf(tom,dick) as a predicate asserting that tom is the father of dick, or a data structure (tree) where the functor fatherOf is the root, and tom and dick are children. 9 query: request to prove an assertion built of predicates ?- fatherOf(dick,harry). Yes ?- fatherOf(harry,tom). No Database fatherOf(tom,dick). fatherOf(dick,harry). fatherOf(jane,harry). motherOf(tom,judy). motherOf(dick,mary). motherOf(jane,mary). 10 • Queries may contain variables. – Prolog tries to find an assignment of variables that make the predicate true. – One solution is given. The user may type ; to get another. ?- fatherOf(X,harry) X = dick ; X = jane ; No ?- motherOf(X,Y) X = tom, Y = judy ; X = dick, Y = mary ; X = jane, Y = mary No Database fatherOf(tom,dick)....
View Full Document

This note was uploaded on 12/09/2009 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 76

17 LogicProg - 1 Logic Programming Scott Chapter 11 2 Logic...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online