1 / 14

Prolog

Prolog. A Prolog "program" is a collection of facts and rules. This collection is sometimes called a knowledge base . Facts represent unconditional assertions. Rules represent conditional assertions. Prolog facts.

bela
Download Presentation

Prolog

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. Prolog • A Prolog "program" is a collection of facts and rules. • This collection is sometimes called a knowledge base. • Facts represent unconditional assertions. • Rules represent conditional assertions.

  2. Prolog facts • A fact is a relational expression -- a predicate name followed by a parenthesized argument list and a period, e.g. • mother(liz, chuck). • Each of these arguments must be a term.

  3. Prolog terms • A term represents an entity (as opposed to a relation or rule). • Terms may be variables, literals, or structures. • Variables are those terms whose name begins with a capital letter or underscore.

  4. Prolog rules • A rule consists of (in order): • a head, a neck, a body, and a period. • The head is a relational expression, and represents a conclusion. • The body represents an assumption. • The neck means "if", and is spelled • :=

  5. A sample rule • One legal rule is • parent(X,Y):-mother(X,Y). • This rule says that X is the parent of Y if X is the mother of Y.

  6. Quantification • All variables in a fact are quantified universally. • Variables appearing to the left of the neck in a rule are quantified universally. • Other variables are quantified existentially.

  7. Conjunction and disjunction • A comma is used to represent conjunction of expressions. • This is common in bodies (but not heads) of rules. • Disjunction is represented by a semicolon. • But disjunctive assumptions are more naturally represented by multiple rules that share a head.

  8. Multiple rules sharing a head • Another legal rule is • parent(X,Y):-father(X,Y). • This can be added to the earlier rule • parent(X,Y):-mother(X,Y). • Both rules together say that X is the parent of Y if X is the father or the mother of Y.

  9. Logical operators • There are some subtle differences between the logical operators and, or, and not and their Prolog equivalents. • These differences are somewhat similar to those seen in short-circuit evaluation.

  10. Queries • Queries are answered based not just on what's explicitly in the knowledge base, but also on what can be inferred from the knowledge base. • The simplest form of Prolog query is syntactically identical to a fact, e.g. • mother(X, chuck). • Any argument may be a variable.

  11. Answering queries • The Prolog interpreter searches for a proof that some collection of bindings for the variables satisfies the query. • To satisfy a query means to makes the query true. • If such a collection of bindings is found, the interpreter will return it, e.g. • X = liz

  12. Multiple answers • After getting one answer, a user may ask for another answer, or quit. • A semicolon is used to continue • A return is used to quit • If there are no variables in the query, the interpreter will just answer yes or no.

  13. Bidirectionality • There is no directionality in a query. • Each of the following queries is acceptable, and can be answered • mother(liz, chuck). • mother(X, chuck). • mother(liz, X). • mother(X, Y).

  14. Data types • Prolog has numeric and atomic types (like Lisp symbols) for literals. • Variables are untyped. • A list data type is available.

More Related