130 likes | 320 Views
Artificial Intelligence. Prolog Facts, Rules and Queries Lecture Three. What is Prolog?. Programming languages are of two kinds: Procedural (BASIC, ForTran , C++, Pascal, Java); Declarative (LISP, Prolog, ML). In procedural programming, we tell the computer how to solve a problem.
E N D
Artificial Intelligence Prolog Facts, Rules and Queries Lecture Three
What is Prolog? • Programming languages are of two kinds: • Procedural (BASIC, ForTran, C++, Pascal, Java); • Declarative (LISP, Prolog, ML). • In procedural programming, we tell the computer how to solve a problem. • In declarative programming, we tell the computer what problem we want solved.
All About Knowledge Bases • -There are only three basic constructs in Prolog: facts, rules, and queries. • A collection of facts and rules is called a knowledge base (or a database) . • We usea Prolog program by posing queries.
Prolog Syntax • There are four kinds of terms in Prolog: atoms, numbers, variables, and complex terms (or structures). Complex Terms Simple Terms Constants Variables Atoms Numbers
Atoms (1) • A string of characters made up of upper-case letters, lower-case letters, digits, and the underscore character, that begins with a lower-case letter. For example: • Ahmed • big_cheese_burger • ahmed_Khalid2
Atoms (2) • An arbitrary sequence of characters enclosed in single quotes. For example • ’Hassan’ • ’The Chosen One’ • ’Five_SDG’ • ’&^%&#@$ &*’ • ’ ’ • The characters between the single quotes is called the atom name. Note that we are allowed to use spaces in such atoms.
Numbers • Prolog do support floats (e.g. 1657.3087 or π) we are not going to discuss them in this course. • But integers (... -2, -1, 0, 1, 2, 3, ...) are useful for such tasks as counting the elements of a list. Their Prolog syntax is the obvious one: 23, 1001, 0, -365, and so on.
Variables • A string of upper-case letters, lower-case letters, digits and underscore characters that starts either with an upper-case letter or with underscore. • For example, X, Y, Variable, _tag, X_526, and List, List24, _head, Tail, _input and Output are all Prolog variables • The anonymous variable _
Complex Terms functor ( arg1 , arg2 ) Must be an atom can be any kind of term
Complex Term Arity • The number of arguments that a complex term has is called its arity. • man( mohammed ) • is a complex term with arity 1 • friendOf ( hassan , mohammed ) • is a complex term with arity 2
Complex Term Arity • We can define two predicates with the same functor but with a different number of arguments (different arity) • The following are two different predicates: • friendOf ( hassan , mohammed ) • friendOf ( hassan , ammar , mohammed)
Arity Annotation • readsPoems • happy • writesPoems • readsPoems/1 • happy/1 • writesPoems/1 Prolog can’t get confused about a knowledge base containing the two predicates with the same functor with a different arity.
THANK YOU See you next Monday Insha2 Allah