Prolog - PowerPoint PPT Presentation

About This Presentation
Title:

Prolog

Description:

Colmerauer: early 70's Developed early version of Prolog for natural language ... Probabilities: What is likelihood of fire destroying Julian? ... – PowerPoint PPT presentation

Number of Views:236
Avg rating:3.0/5.0
Slides: 17
Provided by: ics5
Learn more at: https://ics.uci.edu
Category:
Tags: julian | prolog

less

Transcript and Presenter's Notes

Title: Prolog


1
Prolog
  • The language of logic

2
History
  • Kowalski late 60s Logician who showed logical
    proof can support computation.
  • Colmerauer early 70s Developed early version of
    Prolog for natural language processing, mainly
    multiple parses.
  • Warren mid 70s First version of Prolog that was
    efficient.

3
Characteristics
  • Prolog approximates first-order logic.
  • Every program is a set of Horn clauses.
  • Inference is by resolution.
  • Search is by backtracking with unification.
  • Basic data structure is term or tree.
  • Variables are unknowns not locations.
  • Prolog does not distinguish between inputs and
    outputs. It solves relations/predicates.

4
SWI-Prolog Notes
  • Free! Down Loadable
  • To load a file
  • consult( C\\kibler\\prolog\\test).
  • For help
  • help(predicate-name).
  • will give you next solution.
  • listing(member) will give definition.

5
Example
  • Facts ()
  • likes(john,mary).
  • likes(john,X). Variables begin with capital
  • Queries
  • ?- likes(X,Y).
  • Xjohn, yMary. hit for more
  • ?- likes(X,X).
  • Xjohn.

6
Example
  • Rules
  • likes(john,X) - likes(X,wine). - if
  • likes(john,X)- female(X), likes(X,john).
  • Note variables are dummy. Standarized apart
  • Some Facts
  • likes(bill,wine). female(mary). female(sue).
  • Query ? - likes(john,Y).
  • Y bill
  • no.

7
Family
  • father(a,b).
  • father(e,d).
  • mother(c,b).
  • mother(d,f).
  • parent(X,Y) - father(X,Y).
  • parent(X,Y) - mother(X,Y).
  • grandfather(X,Y)- father(X,Z),parent(Z,Y).
  • Do your own for practice.

8
Informal Summary
  • Program is facts rules. (horn clauses).
  • Query conjunct of predicates.
  • First set of bindings for variables that solve
    query are reported. If none, then Prolog returns
    no.
  • Use to get other solutions.
  • Can be viewed as constraint satisfaction program.

9
MapColoring
  • color(r). color(g). color(b).
  • colormap(C1,C2,C3)-color(C1),color(C2),color(C3),
    C1\C2,
  • C1\C3, C2\C3.
  • Query colormap(X,Y,Z).
  • X r, Y g, Zb.
  • Is that it. Yes! Turn on trace.

10
Unification (matching) terms
  • Two terms UNIFY if there is a common substitution
    for all variables which makes them identical.
  • f(g(X),Y) f(Z,Z). cheap unification
  • X _G225, Yg(_G225).
  • Look at parse tree for each term.
  • variables match
  • variable matches anything (set the binding)
  • function symbols only match identical function
    symbols.

11
Satisfiability uses unification
  • sat(true). base case
  • sat(not(false)). base case
  • sat(or(X,Y))- sat(X).
  • sat(or(X,Y))-sat(Y).
  • sat(and(X,Y))-sat(X),sat(Y).
  • test1(X,Y)- sat(and(not(X),X)).
  • test2(X,Y)- sat(and(X,not(Y))).

12
List Operator H T
  • a,b,c is a list in Prolog.
  • HT a,b,c results in
  • H a i.e. the head of list
  • T b,c i.e. the tail of the list.
  • membership definition
  • member(H,HT). base case first. Why?
  • member(H,_T)- member(H,T).
  • Use it.

13
Member Tests
  • ?- member(3,X).
  • X 3 _G109. _G.., system generated
    variable
  • X _G11,3 _. etc.
  • ?- member(X,Y).
  • X _G131, Y _G131, _G321.

14
Permutation Insert
  • insert(X,L, XL).
  • insert(X,HT,HT1)- insert(X,T,T1).
  • perm(,).
  • perm(HT,P)-perm(T,T1),insert(H,T1,P).

15
DFS
  • solve(goal, solution Path)
  • s(state, successor-state)
  • dfs(N,N) - goal(N).
  • dfs(N,NSol1)- s(N,N1), dfs(N1,Sol1).
  • s(a,b). s(a,c). s(b,d). s(b,e). s(c,f).
  • s(c,g). s(d,h). s(e,i). s(e,j). s(f,k).
  • goal(i). goal(f).
  • ?- dfs(a,N).
  • N a, b, e, i
  • N a, c, f

16
Limitations
  • 2nd order Cant ask what is relationship between
    heart and lungs?
  • Probabilities What is likelihood of fire
    destroying Julian?
Write a Comment
User Comments (0)
About PowerShow.com