Tutorial Prolog
Patrick Blackburn, Johan Bos and Kristina Striegnitz
q
Table of Contents 1 Facts, Rules, and Queries 2 Matching and Proof Search 3 Recursion 4 Lists 5 Arithmetic 6 More Lists 7 Definite Clause Grammars 8 More Definite Clause Grammars 9 A Closer Look at Terms 10 Cuts and Negation 11 Database Manipulation and Collecting Solutions 12 Working With Files
q
q
q
q
q
q
q
q
q
q
Patrick Blackburn, Johan Bos and Kristina Striegnitz
Version 1.2.5 (20030212)
- Up -
Next >>
Table of Contents
q q
q
q
q
q
q
Table of Contents 1 Facts, Rules, and Queries r 1.1 Some simple examples s 1.1.1 Knowledge Base 1 s 1.1.2 Knowledge Base 2 s 1.1.3 Knowledge Base 3 s 1.1.4 Knowledge Base 4 s 1.1.5 Knowledge Base 5 r1.2 Prolog Syntax s 1.2.1 Atoms s 1.2.2 Numbers s 1.2.3 Variables s 1.2.4 Complex terms r 1.3 Exercises r 1.4 Practical Session 1 2 Matching and Proof Search r 2.1 Matching s 2.1.1 Examples s 2.1.2 The occurs check s 2.1.3 Programming with matching r 2.2 Proof Search r 2.3 Exercises r 2.4 Practical Session 2 3 Recursion r 3.1 Recursive definitions s 3.1.1 Example 1: Eating s 3.1.2 Example 2:Descendant s 3.1.3 Example 3: Successor s 3.1.4 Example 3: Addition r 3.2 Clause ordering, goal ordering, and termination r 3.3 Exercises r 3.4 Practical Session 3 4 Lists r 4.1 Lists r 4.2 Member r 4.3 Recursing down lists r 4.4 Exercises r 4.5 Practical Session 4 5 Arithmetic r 5.1 Arithmetic in Prolog r 5.2 A closer look r 5.3 Arithmetic and lists r 5.4 Comparing integers r 5.5 Exercises r 5.6Practical Session 5 6 More Lists
q
q
q
q
q
6.1 Append s 6.1.1 Defining append s 6.1.2 Using append r 6.2 Reversing a list s 6.2.1 Naive reverse using append s 6.2.2 Reverse using an accumulator r 6.3 Exercises r 6.4 Practical Session 6 7 Definite Clause Grammars r 7.1 Context free grammars s 7.1.1 CFG recognition using append s 7.1.2 CFG recognition using difference lists r 7.2Definite clause grammars s 7.2.1 A first example s 7.2.2 Adding recursive rules s 7.2.3 A DCG for a simple formal language r 7.3 Exercises r 7.4 Practical Session 7 8 More Definite Clause Grammars r 8.1 Extra arguments s 8.1.1 Context free grammars with features s 8.1.2 Building parse trees s 8.1.3 Beyond context free languages r 8.2 Extra goals s 8.2.1 Separating rules and lexicon r 8.3 Concludingremarks r 8.4 Exercises r 8.5 Practical Session 8 9 A Closer Look at Terms r 9.1 Comparing terms r 9.2 Terms with a special notation s 9.2.1 Arithmetic terms s 9.2.2 Lists as terms r 9.3 Examining Terms s 9.3.1 Types of Terms s 9.3.2 The Structure of Terms r 9.4 Operators s 9.4.1 Properties of operators s 9.4.2 Defining operators r 9.5 Exercises r 9.6 Practical Session 10 Cuts and Negation r 10.1 Thecut r 10.2 If-then-else r 10.3 Negation as failure r 10.4 Exercises r 10.5 Practical Session 10 11 Database Manipulation and Collecting Solutions r 11.1 Database manipulation r 11.2 Collecting solutions s 11.2.1 findall/3 s 11.2.2 bagof/3 s 11.2.3 setof/3 r 11.3 Exercises r 11.4 Practical Session 11
r
q
12 Working With Files r 12.1 Splitting Programs Over Files s 12.1.1 Reading inPrograms s 12.1.2 Modules s 12.1.3 Libraries r 12.2 Writing To and Reading From Files r 12.3 Practical Session s 12.3.1 Step 1 s 12.3.2 Step 2 s 12.3.3 Step 3 s 12.3.4 Step 4 s 12.3.5 Step 5 s 12.3.6 Step 6
- Up -
Next >>
Patrick Blackburn, Johan Bos and Kristina Striegnitz
Version 1.2.5 (20030212)
>
1 Facts, Rules, and Queries
This introductory lecture has two main goals: 1. To givesome simple examples of Prolog programs. This will introduce us to the three basic constructs in Prolog: facts, rules, and queries. It will also introduce us to a number of other themes, like the role of logic in Prolog, and the idea of performing matching with the aid of variables. 2. To begin the systematic study of Prolog by defining terms, atoms, variables and other syntactic concepts.
q...
Regístrate para leer el documento completo.