pl06prolog - Logic Programming Logic Programming Logic...

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

Logic Programming 高雄大學資工系 嚴力行
Image of page 1

Info icon 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
Image of page 2
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
Image of page 3

Info icon 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
Image of page 4
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).
Image of page 5

Info icon 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
Image of page 6
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
Image of page 7

Info icon 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
Image of page 8
Prolog Applications expert systems natural language interface customized knowledge base
Image of page 9

Info icon 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
Image of page 10
• 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.
Image of page 11

Info icon 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 */
Image of page 12
Prolog Vs. Turbo Prolog Words In Prolog Also in Turbo Prolog If :- if And , and Or ; or Query ?- Goal:
Image of page 13

Info icon 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.
Image of page 14
Using Turbo Prolog Turbo Prolog have four main windows
Image of page 15

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern