An overview of Prolog - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

An overview of Prolog

Description:

Imagine how difficult it would be to use global variables with non-determinism. ... Self-help. Clearly, you need to concentrate on learning unification. Use the ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 13
Provided by: csBh
Category:

less

Transcript and Presenter's Notes

Title: An overview of Prolog


1
An overview of Prolog
  • This lecture will cover
  • the execution of a basic non-deterministic
    program showing
  • the role of the stack
  • exploration of alternative solutions
  • binding of variables
  • a discussion of the consequences of Prologs
    execution strategy.

2
Components need to run a Prolog program - 1
  • a Prolog program
  • consisting of clauses
  • clauses are either
  • facts or
  • rules
  • a query
  • which is also a clause

3
Components need to run a Prolog program - 2
  • a Prolog system (compiler or interpreter)
  • includes
  • an internal stack
  • a matching algorithm
  • a mechanism for placing and removing items on and
    from the stack (scheduling algorithm).

4
The workings of a simple program
  • Consider the following simple program
  • likes(max, julia).
  • and the query
  • ?- likes(max, julia).
  • The Prolog system
  • examines the query
  • selects all matching clauses in the program and
    places them on the stack
  • pops one clause at a time from the stack and
    decides if it satisfies the query.

5
Using variables in queries
  • Consider the following simple program
  • likes(max, julia).
  • and the query
  • ?- likes(max, Who).
  • The Prolog system
  • examines the query
  • selects all matching clauses in the program and
    places them on the stack
  • pops one clause at a time from the stack and
    decides if it satisfies the query and reports the
    variable bindings.

6
What happens when there is more than one
solution?
  • Consider the following simple program
  • likes(max, julia).
  • likes(max, amabel).
  • and the query
  • ?- likes(max, Who).
  • The Prolog system
  • examines, selects, pops and decides as before,
  • but
  • what does it do to recognise that there is more
    than one solution?

7
Defining more complicated situations - rules
  • Consider the following simple program
  • likes(max, julia).
  • likes(max, amabel).
  • jealous(Jealous, Victim) -
  • likes(Person, Jealous),
  • likes(Person, Victim).
  • and the query ?- jealous(julia, Who).
  • The Prolog system
  • examines and selects as before, but
  • it needs a way of deciding about the lines in the
    body of rules

8
Some consequences of Prologs execution method -
1
  • Determinism and non-determinism
  • Prolog can easily compute solutions to problems
    where there is more than one solution.
  • Search process
  • As Prolog runs on a digital computer, its search
    must be implemented as a program. This must work
    predictably under any situation and must give all
    possible results.
  • In other words it is an algorithm.

9
Some consequences of Prologs execution method -
2
  • All variables have local scope
  • Imagine how difficult it would be to use global
    variables with non-determinism.

10
Prolog needs a brilliant matching algorithm
  • Fortunately, it has one - unification
  • Unification is the name for the process that
  • matches all Prolog data types
  • instantiates empty variables.
  • unifies one empty variable with another to
    create chains of instantiation.
  • An understanding of unification is vital to be
    able to program in Prolog.

11
Summary
  • Prolog has three parts
  • unification 60
  • search - 30
  • the rest - 10

12
Self-help
  • Clearly, you need to concentrate on learning
    unification.
  • Use the WWW page
  • http//www.cs.bham.ac.uk/mgl/prolog/
  • to view the suggested individual study associated
    with this lecture.
Write a Comment
User Comments (0)
About PowerShow.com