Pengantar Kecerdasan Buatan Pengantar Prolog LIST Prologs List
Pengantar Kecerdasan Buatan Pengantar Prolog (LIST)
Prolog’s List � Simple data structure to process non-numeric � A list is a set of ordered sequential elements [2, 2, 1, 1, 4, 4, 5, 6] [b, u, d, i] [budi, iwan, wati] � How to use a list? Simple case: empty [] Ordered element: [head|tail] ▪ [2, 2, 1, 1, 4, 4, 5, 6] [ 2 | [2, 1, 1, 4, 4, 5, 6] ] relation
Rules on Prolog’s List • [a, b, c] unifies with [Head|Tail] resulting in Head=a and Tail=[b, c] • [a] unifies with [H|T] resulting in H=a and T=[] • [a, b, c] unifies with [a|T] resulting in T=[b, c] • [a, b, c] doesn't unify with [b|T] • [] doesn't unify with [H|T] • [] unifies with []. Two empty lists always can be unified.
Example “Member List” Predicate: member(X, List). X is a member of List, in case of: 1. X is a head, or 2. X is a member of the tail member(X, [X|Tail]). member(X, [Head|Tail]): - member(X, Tail).
Example “Reverse” reverse([], X, X). reverse([X|Y], Z, W) : - reverse(Y, [X|Z], W). reverse([1, 2, 3], [], A) reverse([2, 3], [1], A) reverse([3], [2, 1], A) reverse([], [3, 2, 1], A) true A = [3, 2, 1]
Please try this (1): How does Prolog’s react? 1. [a, b, c, d]=[a, [b, c, d]]. 2. [a, b, c, d]=[a|[b, c, d]]. 3. [a, b, c, d]=[a, b, [c, d]]. 4. [a, b, c, d]=[a, b|[c, d]]. 5. [a, b, c, d]=[a, b, c, [d]]. 6. [a, b, c, d]=[a, b, c|[d]]. 7. [a, b, c, d]=[a, b, c, d, []]. 8. [a, b, c, d]=[a, b, c, d|[]]. 9. []=_. 10. []=[_]. 11. []=[_|[]].
Please try this (2) • Develop a dictionary to translate number 1. . 10 from Indonesian to English and vice versa, example: Translate([satu, sembilan], Y). Y = [one, nine] • Translate(Z, [one]). Z = [satu] • Translate([], []). •
8 Referensi • Russell, Stuart J. & Norvig, Peter. Artificial Intelligence: A Modern Approach (3 rd ed. ). Prentice Hall. 2009 • Luger, George F. Artificial Intelligence: Structures and Strategies for Complex Problem Solving. 6 th Edition. Addison Wesley. 2008. • Watson, Mark. , Practical Artificial Intelligence Programming in Java, Open Content – Free e. Book (CC License), 2005. • Machine Learning : Tom Mitchel. OSCAR KARNALIM, S. T. , M. T.
- Slides: 9