Logic Programming and Prolog - PowerPoint PPT Presentation

About This Presentation
Title:

Logic Programming and Prolog

Description:

'The use of mathematical logic for computer programming.' ( Wikipedia) ... http://dictionary.reference.com/browse/logic programming. Pages 45-46 of our textbook ... – PowerPoint PPT presentation

Number of Views:151
Avg rating:3.0/5.0
Slides: 24
Provided by: Owne313
Learn more at: https://www.cse.unr.edu
Category:

less

Transcript and Presenter's Notes

Title: Logic Programming and Prolog


1
Logic Programmingand Prolog
  • Danielle and Joseph Bennett
  • 24 April 2007

2
What is Logic Programming?
3
What is Logic Programming?
  • The use of mathematical logic for computer
    programming. (Wikipedia)
  • A declarative, relational style of programming
    based on first-order logic. (Dictionary.com)

4
History of Logic Programming
  • Came about in 1960s and 1970s due to debates
    about using declarative or procedural
    representations in AI
  • Stanford and Edinburgh declarative
  • MIT - procedural
  • Developed Planner in 1969 (first language in the
    proceduralistic paradigm).

5
Systems for Logic Programming
  • ALF
  • CLP
  • ECLiPSe
  • Elf
  • Fish
  • Flang
  • Gödel
  • KLIC
  • LIFE
  • MONA
  • Oz System
  • RELFUN
  • SAMPLE
  • XSB
  • Just to name a few.

6
Systems for Logic Programming, cont.
  • Prolog is the most common system
  • Prolog has many variations
  • -Prolog, And-parallel Prolog.
  • ACE, And-Or-parallel Prolog.
  • Actor Prolog
  • Andorra-I, an Or- and (deterministic)
    and-parallel Prolog.
  • Aurora, Or-parallel Prolog.
  • cu-Prolog, a constraint logic programming
    language
  • lambda Prolog
  • LeanTaP, a small theorem prover written in
    SICStus Prolog.
  • Logtalk, an extension for Object-Oriented
    Programming in Prolog.
  • Mixtus, an automatic partial evaluator for full
    Prolog.
  • Muse, Or-parallel Prolog.

7
All About Prolog
8
All About Prolog
  • Developed in 1972 by Alain Colmerauer and
    Philippe Roussel
  • Name comes from PROgramming in LOGic
  • A solution to the debate about which kinds of
    logic to use

9
Prolog Structure
  • Prolog facts a database of predicates and
    associations.
  • Prolog rules define new predicates by using
    Prolog facts.
  • Note Prolog considers capital letters to denote
    variables, not predicates.

10
Prolog Structure Queries
  • A query searches the database for the first fact
    that satisfies its goal.
  • If a fact is found it either unifies the variable
    with a constant or returns yes.
  • If a fact is not found that meets that condition
    it returns no.

11
Prolog Structure Queries, cont.
  • Use a semi-colon to request subsequent answers.
  • In other words, a semi-colon signifies
    disjunction.
  • A comma signifies conjunction.

12
Prolog Structure - Unification
  • A query resolves by unifying all of its elements.
  • A constant unifies with itself and any variable.
  • Scope is limited to the rule in which a variable
    occurs.
  • When a variable is unified with a constant in a
    rule, all instances of that variable in that rule
    are unified to that constant.

13
Prolog Structure - Backtracking
  • In more complex examples, Prolog uses
    backtracking to find possible solutions.
  • Prolog will attempt to resolve the first fact of
    its rule, unifying any variables with the first
    constant that satisfies that fact
  • It then attempts to resolve the rest of that
    rules facts.
  • If it is unable to do so under those conditions
    it backs up and tries again with the next
    available unifying constant.

14
More Than Just Information
  • Prolog rules can also be used write programs that
    do more than find the answers to simple database
    queries.
  • append(, L, L).
  • append(HT, L, HL1)-append(T, L, L1).
  • This will append a list to another list
    recursively.
  • A binary tree can be defined as follows
  • tree(nil).
  • tree(node(_, Left, Right)-tree(left),
    tree(right).

15
How Prolog Works
  • Example from pages 45-46 of our text
  • instructor (bebis, cs365)
  • instructor (looney, cs311)
  • instructor (yuksel, cs446)
  • enrolled (joseph, cs311)
  • enrolled (joseph, cs365)
  • enrolled (joseph, cs446)
  • enrolled (danielle, cs365)
  • enrolled (danielle, cs446)
  • This is the database of Prolog facts.

16
How Prolog Works, cont.
  • Prolog rules
  • teaches (P,S) - instructor (P,C), enrolled
    (S,C)
  • This is to say that an instructor only teaches
    if he teaches a class and students are enrolled
    in that class.

17
How Prolog Works, cont.
  • Prolog answers queries based off of the database
    that has been given.
  • ?enrolled (joseph, cs365)
  • yes
  • ?enrolled (X, cs365)
  • joseph
  • danielle
  • ?teaches (X, joseph)
  • bebis
  • looney
  • yuksel

18
How Prolog Works, cont.
  • Imagine what happens if we expand the database
  • instructor (bebis, cs365)
  • instructor (looney, cs311)
  • instructor (yuksel, cs446)
  • instructor (helfand, cs493)
  • instructor (quint, math486)
  • enrolled (ben, cs365)
  • enrolled (bill, cs365)
  • enrolled (bill, cs446)
  • enrolled (brian, cs311)
  • enrolled (brian, cs365)
  • enrolled (brittney, cs311)
  • enrolled (brittney, cs365)
  • enrolled (brittney, cs446)
  • enrolled (cody, cs311)
  • enrolled (cody, cs365)
  • enrolled (danielle, cs365)
  • enrolled (danielle, cs446)
  • enrolled (joel, cs365)
  • enrolled (joseph, cs311)
  • enrolled (joseph, cs365)
  • enrolled (joseph, cs446)
  • enrolled (joseph, cs493)
  • enrolled (joseph, math486)
  • enrolled (kellen, cs365)
  • enrolled (matts, cs311)
  • enrolled (matts, cs365)
  • enrolled (mattw, cs311)
  • enrolled (mattw, cs365)
  • enrolled (mattw, cs446)
  • enrolled (miran, cs365)
  • enrolled (ryan, cs365)
  • enrolled (samuel, cs365)

19
How Prolog Works, cont.
  • ?enrolled (X, cs365)
  • ben
  • bill
  • brian
  • brittney
  • cody
  • danielle
  • david
  • javier
  • jeffrey
  • joel
  • joseph
  • kellen
  • matts
  • mattw
  • miran
  • ryan
  • samuel
  • shane
  • This list now gives us the entire roster of
    students in CS 365.

20
How Prolog Works, cont.
  • Queries can be more complicated to compare more
    data
  • classmates (S1, S2) - enrolled (S1, C), enrolled
    (S2, C)
  • ?classmates (joseph, danielle)
  • yes
  • ?classmates (joseph, jessica)
  • yes
  • ?classmates (jessica, danielle)
  • no

21
How Prolog Works, cont.
  • classmates (S1, S2, C) - enrolled (S1, C),
    enrolled (S2, C)
  • ?classmates (joseph, danielle, C)
  • cs365
  • cs446
  • cs493
  • no
  • ?classmates (joseph, jessica, C)
  • math
  • ?classmates (jessica, danielle, C)
  • no

22
Free Prolog Access
  • SWI-Prolog
  • http//www.swi-prolog.org/
  • YAProlog
  • http//www.ncc.up.pt/vsc/Yap/
  • Strawberry Prolog
  • http//www.dobrev.com/

23
Sources
  • http//www.afm.sbu.ac.uk/logic-prog/
  • http//en.wikipedia.org/wiki/Logic_programming
  • http//dictionary.reference.com/browse/logic20pro
    gramming
  • Pages 45-46 of our textbook
  • CS 326 lectures on Prolog (written by Dr. Mircea
    Nicolescu)
Write a Comment
User Comments (0)
About PowerShow.com