Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logic Programming and Declarative Paradigm. Declarative Programming Declare goals, not actions Query by Example HTML Prolog –AI work –Natural Language.

Similar presentations


Presentation on theme: "Logic Programming and Declarative Paradigm. Declarative Programming Declare goals, not actions Query by Example HTML Prolog –AI work –Natural Language."— Presentation transcript:

1 Logic Programming and Declarative Paradigm

2 Declarative Programming Declare goals, not actions Query by Example HTML Prolog –AI work –Natural Language Community –Japanese 5’th Generation

3 Logic Programming Resolution Principle – Alan Robinson 1965 Restriction to Horn Clauses Kowalski of U. of Edinburgh and Colmerauer of U. Aix-Marseille developed Prolog

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25 Horn Clauses If x1  x2 & x3 Then r1 r1 :- x1, x2, x3.

26 Prolog Syntax parent(X,Y) :- mother(X, Y). mother(jane, bill). Note Prolog does not “understand” parent or mother!

27 Why do we like Prolog?

28 Lists [a,b,c,d] – a list [X1 | X2] - concatenations

29 Append Append([],Y,Y). Append([X1|X2],Y,[X1|Z]) :- Append(X2,Y,Z).

30 B-Prolog Version 4.0 #3 (C) Neng-Fa Zhou 1994-2000. | ?- consult(app). consulting....app.pl yes | ?- trace yes {Debug mode} | ?- app([a,b],[c,d],Ans). Call: app([a,b],[c,d],_860124) ? Call: app([b],[c,d],_860250) ? Call: app([],[c,d],_8602c4) ? Exit: app([],[c,d],[c,d]) ? Exit: app([b],[c,d],[b,c,d]) ? Exit: app([a,b],[c,d],[a,b,c,d]) ? Ans = [a,b,c,d]?

31 | ?- app([a,b,c],Ans,[a,b,c,d,f]). Call: app([a,b,c],_8600fc,[a,b,c,d,f]) ? Call: app([b,c],_8600fc,[b,c,d,f]) ? Call: app([c],_8600fc,[c,d,f]) ? Call: app([],_8600fc,[d,f]) ? Exit: app([],[d,f],[d,f]) ? Exit: app([c],[d,f],[c,d,f]) ? Exit: app([b,c],[d,f],[b,c,d,f]) ? Exit: app([a,b,c],[d,f],[a,b,c,d,f]) ? Ans = [d,f]? yes

32 d(X, U+V, DU+DV) :- d(X, U, DU), d(X, V, DV). d(X, U-V, DU-DV) :- d(X, U, DU), d(X, V, DV). d(X, U*V, U*DV + V*DU) :- d(X, U, DU), d(X, U, DU), d(X, V, DV). d(X, U/V, (V*DU - U*DU) / ( V*V)) :- d(X, U, DU), d(X, V, DV). d(X, C, 0) :- atomic(C), C\=X. d(X, X, 1). dc/dx = 0 dx/dx = 1 d/dx(u+v) = du/dx + dv/dx d/dx(u-v) = du/dx – dv/dx d/dx(uv) = u dv/dx + v du/dx d/dx(u/v) = (v du/dx – u dv/dx) / v*v Symbolic Differentiation

33 | ?- d(x,2*x+1,Ans). Call: d(x,2*x+1,_860114) ? Call: d(x,2*x,_86029c) ? Call: d(x,2,_860350) ? Call: atomic(2) ? Exit: atomic(2) ? Call: 2\=x ? Exit: 2\=x ? Exit: d(x,2,0) ? Call: d(x,2,0) ? Call: atomic(2) ? Exit: atomic(2) ? Call: 2\=x ? Exit: 2\=x ? Exit: d(x,2,0) ? Call: d(x,x,_860340) ? Call: atomic(x) ? Exit: atomic(x) ?

34 Call: x\=x ? Fail: x\=x ? Redo: atomic(x) ? Fail: atomic(x) ? Exit: d(x,x,1) ? Exit: d(x,2*x,2*1+x*0) ? Call: d(x,1,_8602a0) ? Call: atomic(1) ? Exit: atomic(1) ? Call: 1\=x ? Exit: 1\=x ? Exit: d(x,1,0) ? Exit: d(x,2*x+1,2*1+x*0+0) ? Ans = 2*1+x*0+0?

35 Search Bottom-up resolution – forward search –Rules, facts  goal Top-down resolution – backward search –Goal -> rules, facts

36 Prolog Issues Resolution Order Control Closed World Assumption Negation Problem

37 Expert Systems In the knowledge is the Power CLIPS Prolog based

38 Implementation of Prolog Warren’s Abstract Machine A Tutorial Reconstruction by Hassan Ait- Kaci

39 Unify Constant c2Variable x2Structure g(r1,…rk) Constant c1 {} If c1 == c2, else fail {x2/c1}fail Variable x1 {x1/c2}{x1/x2} if (x1 != x2, else fail {x2/g(r1,..rk)} if x2 does not occur in g(…) else fail Structure f(s1,…sn ) fail{x2/f(s1,..sn)} if x2 does not occur in f(…) else fail Unify ((s1,..sk)(r1..rn)) if f==g and n==k else fail

40 Execution WAM!


Download ppt "Logic Programming and Declarative Paradigm. Declarative Programming Declare goals, not actions Query by Example HTML Prolog –AI work –Natural Language."

Similar presentations


Ads by Google