1 / 13

Artificial Intelligence

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.

feryal
Download Presentation

Artificial Intelligence

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Artificial Intelligence Prolog Facts, Rules and Queries Lecture Three

  2. 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.

  3. 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.

  4. 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

  5. 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

  6. 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.

  7. 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.

  8. 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 _

  9. Complex Terms functor ( arg1 , arg2 ) Must be an atom can be any kind of term

  10. 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

  11. 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)

  12. 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.

  13. THANK YOU  See you next Monday Insha2 Allah

More Related