Prolog

# Prolog - COP4020 Programming Languages Prolog Prof. Robert...

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

COP4020 Programming Languages Prolog Prof. Robert van Engelen

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

View Full Document
COP4020 Spring 2011 2 1/27/11 Overview ! Logic programming principles ! Prolog
COP4020 Spring 2011 3 1/27/11 Logic Programming ! Logic programming is a form of declarative programming ! A program is a collection of axioms ! Each axiom is a Horn clause of the form: H :- B 1 , B 2 , . .., B n . where H is the head term and B i are the body terms ! Meaning: H is true if all B i are true ! A user states a goal (a theorem) to be proven ! The logic programming system uses inference steps to prove the goal (theorem) is true, using a logical resolution strategy

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

View Full Document
COP4020 Spring 2011 4 1/27/11 Resolution Strategies ! To deduce a goal (theorem), the programming system searches axioms and combines sub-goals using a resolution strategy ! For example, given the axioms: C :- A , B . A :- true. D :- C . B :- true. ! Forward chaining deduces first that C is true: C :- A , B and then that D is true: D :- C ! Backward chaining finds that D can be proven if sub-goal C is true: D :- C the system then deduces that the sub-goal is C is true: C :- A , B since the system could prove C it has proven D
COP4020 Spring 2011 5 1/27/11 Prolog ! Prolog uses backward chaining, which is more efficient than forward chaining for larger collections of axioms ! Prolog is interactive (mixed compiled/interpreted) ! Example applications: " Expert systems " Artificial intelligence " Natural language understanding " Logical puzzles and games ! Popular system: SWI-Prolog " Login linprog.cs.fsu.edu " pl (or swipl ) to start SWI-Prolog " halt. to halt Prolog (period is the Prolog command terminator)

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

View Full Document
COP4020 Spring 2011 6 1/27/11 Definitions: Prolog Clauses ! A program consists of a collection of Horn clauses ! Each clause consists of a head predicate and body predicates : H :- B 1 , B 2 , . .., B n . " A clause is either a rule , e.g. snowy(X) :- rainy(X), cold(X). meaning: "If X is rainy and X is cold then this implies that X is snowy" " Or a clause is a fact , e.g. rainy(rochester). meaning "Rochester is rainy." " This fact is identical to the rule with true as the body predicate: rainy(rochester) :- true. ! A predicate is a term (an atom or a structure), e.g. " rainy(rochester) " member(X,Y) " true
COP4020 Spring 2011 7 1/27/11 Definitions: Queries and Goals ! Queries are used to "execute" goals ! A query is interactively entered by a user after a program is loaded " A query has the form ?- G 1 , G 2 , . .., G n . where G i are goals (predicates) ! A goal is a predicate to be proven true by the programming system " Example program with two facts: ! rainy(seattle). ! rainy(rochester). " Query with one goal to find which city C is rainy (if any): ?- rainy(C).

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.

## This note was uploaded on 02/01/2012 for the course COP 4020 taught by Professor Engelen during the Spring '11 term at FSU.

### Page1 / 34

Prolog - COP4020 Programming Languages Prolog Prof. Robert...

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

View Full Document
Ask a homework question - tutors are online