1 / 17

Artificial Intelligence

Artificial Intelligence. Lecture 6. In the introduction it has been said that Prolog is a declarative (or descriptive) language. Programming in Prolog means describing the world. Using such programs means asking the world is by stating facts, like this one: bigger(elephant, horse).

guido
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 Lecture 6

  2. In the introduction it has been said that Prolog is a declarative (or descriptive) language. • Programming in Prolog means describing the world. Using such programs means asking the world is by stating facts, like this one: bigger(elephant, horse).

  3. bigger(elephant, horse). • bigger(horse, donkey). • bigger(donkey, dog). • bigger(donkey, monkey).

  4. Prolog Syntax • Terms central data structure in Prolog • Types of terms atoms, numbers, variables, and compound terms • Atoms and numbers are sometimes grouped together and called atomic terms. • Atoms strings made up of lower- and uppercase letters, digits, and the underscore, starting with a lowercase letter • The following are all valid Prolog atoms: elephant, b, abcXYZ, x_123, another_pint_for_me_please

  5. Numbers All Prolog implementations have an integer type: a sequence of digits • Variables strings of letters, digits, and the underscore, starting with a capital letter or an underscore. Examples: X, Elephant, _4711, X_1_2, MyVariable • Compound terms Compound terms are made up of a functor and a number of arguments Example: is_bigger(horse, X), f(g(X, _), 7), 'My Functor'(dog)

  6. Basic constructs in Prolog • facts, rules, and queries • A collection of facts and rules is called a knowledge base (or a database) and Prolog programming is all about writing knowledge bases

  7. Facts • Facts are used to state things that are unconditionally true of the domain of interest • For example, we can state that Mia, Jody, and Yolanda are women, and that Jody plays air guitar woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). • A fact is a predicate followed by a full stop

  8. Rules • Rules consists of a head (a predicate) and a body (a sequence of predicates separated by commas). • Head and body are separated by the sign :- and, like everyProlog expression, a rule has to be terminated by a full stop. • Examples: is_smaller(X, Y) :- is_bigger(Y, X). aunt(Aunt, Child) :- sister(Aunt, Parent), parent(Parent, Child).

  9. Programs is a sequence of clauses. • Queries After compilation a Prolog program is run by submitting queries • A query has the same structure as the body of a rule

  10. Section of programs • Domains • Predicates • Clauses

  11. domains person, activity = symbol predicates likes(person,activity) clauses likes(ellen,tennis). likes(john,football). likes(tom,baseball). likes(eric,swimming). likes(mark,tennis). • The clauses section contains a collection of facts and rules • correspond to these statements in English: ellenlikes tennis. john likes football. tom likes baseball. ericlikes swimming. mark likes tennis

  12. How to use prolog • We can ask Prolog whether Tom likes baseball by posing the query: ?-likes(tom,baseball) • Prolog will answer yes • for the obvious reason that this is one of the facts explicitly recorded in KB. • Incidentally, we don’t type in the ?-. This symbol is the prompt symbol that the Prolog interpreter displays when it is waiting to evaluate a query. We just type in the actual query followed by . (a full stop).

More Related