# pl06prolog - Logic Programming Logic Programming Logic...

• Test Prep
• rafan
• 59

This preview shows pages 1–16. Sign up to view the full content.

Logic Programming 高雄大學資工系 嚴力行

This preview has intentionally blurred sections. Sign up to view the full version.

Logic Programming Logic programming deals with relations rather than functions father(tom, bob). father(bob, john). mother(tom, ann). mother(bob, liz). tom bob ann john liz facts
child(X, Y) :- father(Y, X). child(X, Y) :- mother(Y, X). parent(X, Y) :- child(Y, X). grandfather(X, Y) :- father(X, Z), father(Z, Y). rules Goal: child(john,bob). Yes Goal: grandfather(tom, Who). Who=john 1 Solution Goal: parent(bob,X). X=john X=liz 2 Solutions queries

This preview has intentionally blurred sections. Sign up to view the full version.

Relations and Facts Relations – represented by n -tuple ( a 1 , a 2 , …, a n ) • fact : all a i ’s are concrete terms – concrete term begins with a lower-case letter father(tom, bob). father(bob, john). symbols, numbers, (symbols) tom, bob, john are all symbols. a predicate predicate name indicates which relation the tuple indicates what objects are involved in the relation
Rules some relation or part of a relation can be defined with rules handptright P if Q 1 and Q 2 and … and Q k . handptright capitalized symbol represents variables P :- Q 1 , Q 2 , …, Q k . grandfather( X , Y ) :- father( X , Z ), father( Z , Y ). likes(tom, W hich) :- likes(john, W hich).

This preview has intentionally blurred sections. Sign up to view the full version.

Goals Goal: Queries about relations – whether a particular tuple belongs to a relation? yes/fail answers rather than yes/no “fail” means “not found” – queries containing variables a request for suitable values for the variables in the relation contains no variables
Prolog (PROgramming in LOGic) developed in 1972 a declarative language – describe what the problem is rather than how the problem is to be solved suitable for processing symbols or non- numerical data concentrates on objects and their relationship

This preview has intentionally blurred sections. Sign up to view the full version.

Prolog Environment Prolog (A Inference Engine) facts rules Knowledge base queries result programming running
Prolog Applications expert systems natural language interface customized knowledge base

This preview has intentionally blurred sections. Sign up to view the full version.

Turbo Prolog • Goal – provide queries (optional) • Clauses – describe facts and rules in predicate form – dot (“.”) is used to separate clauses domains ... predicates goal clauses Program structure cannot be run under 64-bit Win7
• Domains – type definition (optional) • Predicates – predicate declaration domains brand, color = symbol age, price = integer mileage = real predicates car(brand,mileage,age,color,price) predicates car(symbol,real,integer,symbol,integer) predicate: name of relation symbol, integer, and real are built-in types.

This preview has intentionally blurred sections. Sign up to view the full version.

Some Syntax Rule handptright names of objects and predicates begin with a lower-case letter handptright variable names are capitalized handptright anonymous variables (“_”) can be used wherever a variable can be used handptright comments are enclosed within “/*” and “*/” likes(tom,_). /* tom likes everyone */ lives(_). /* everyone lives */
Prolog Vs. Turbo Prolog Words In Prolog Also in Turbo Prolog If :- if And , and Or ; or Query ?- Goal:

This preview has intentionally blurred sections. Sign up to view the full version.

Program Writing: An example An BNF statement <var> a | b | c | d Equivalent Prolog statement var(X) :- X = a; X = b; X = c; X = d.
Using Turbo Prolog Turbo Prolog have four main windows

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Spring '12
• Tom, Closure, Free variables and bound variables, John …

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern