Viasual Prolog

Páginas: 51 (12647 palabras) Publicado: 11 de abril de 2011
Visual Prolog Tutorial

Jim Mims
April 2008

Contents
Preface 5
What is Prolog? 5
What are strengths and Weaknesses? 5
Section 1: Introduction 6
The Compiler 6
Horn Clause Logic 6
PIE: Prolog Inference Engine 8
Extending the Family Theory 10
Prolog is a Programming Language 11
Failing 13
Backtracking 13
Improving the Family Theory 16
Recursion 17
Side Effects 19
Conclusion 20Section 2: A First Example 21
Open Visual Prolog 21
Section 3: Getting Started 24
Typing in a Prolog program 24
Starting Prolog 24
Loading the Program 24
Running a query 25
Section 4: Facts and Rules 26
The Rules 26
The Family Tree Example 26
Section 5: Operators and Arithmetic 29
Some Prolog Details 29
Arity 29
Spaces 29
Comments 29
Simple I/O in Prolog 29
Arithmetic in Prolog30
Built-In Predicates 30
Arithmetic Operators 30
Some queries: 31
Defining your own relations 31
Exercises 32
Section 6: Recursion 34
Using Recursion 34
Some Examples 34
Exercise: 35
The Towers of Hanoi 35
The Grid Example 36
Section 7: Structures 38
The General Form of a Structure 38
Arithmetic "Functions" and Structures 38
A simple example of using structures 38
Exercises 39Section 8: Recursive Structures 41
Inserting an element 41
Exercises 42
Binary Trees 42
Exercise 42
Section 9: Introducing Lists 44
Format of Lists 44
Empty and Non-Empty Lists 44
Some Examples 45
The length of a list 45
Summing a list 46
List Membership 46
Exercises 46
Section 10: Lists as Accumulators 48
Collecting information 48
Joining two lists 49
Reversing a List 49
Exercises51
Built-In list predicates 51
Section 11: Backtracking and Cut 52
Analysing Cases 52
An Example Of Using The Cut 53
The First Cut 54
Another Cut 54
Yet Another Cut 55
Exercises 55
Section 12: More Control Features 57
Kinds of cut 57
Green cuts 57
Red cuts 57
Negation as Failure 57
Warning! 58
If-then-else in Prolog 58
The repeat predicate 59
Section 13: Input and Output 61
Moreon I/O 61
File I/O 61
Saving and Restoring a Knowledge-Base 61
Other Approaches to I/O 62
An Exercise 62

Preface

What is Prolog?

Programming in Logic.
Edinburgh syntax is the basis of ISO standard.
High-level interactive language.
Logic Programming Language
Based on Horn clauses

What are strengths and Weaknesses?

Good at
Grammars and Language processing
Knowledgerepresentation and reasoning
Pattern matching
Symbolic AI

Poor at
Repetitive number crunching
Input/Output

Section 1: Introduction

 

The Compiler

 
A disk with Visual Prolog 7.1 Personal Edition will be distributed in class. It will also be placed on selected computers in the lab.

( Run setup to install the program - works under XP and Vista
( To create a link to the executable(assuming you accepted the default locations) go to
c:\program files.\visual prolog 7.1\bin\vip
( When the program opens, click on Help at the top, then Visual Prolog Help - good
explanations are provided
 
Visual Prolog is object oriented, strictly typed and mode checked.  You will of course have to master all this to write Visual Prolog programs.  But here we will focus on the core ofthe code, i.e. the code when disregarding classes, types and modes.

For this purpose we will use the PIE example that is included in the Visual Prolog distribution.  PIE is a "classical" Prolog interpreter, by using this you can learn and experiment with Prolog without being concerned with classes, types, etc.

Horn Clause Logic

Visual Prolog and other Prolog dialects are based on HornClause logic.  Horn Clause logic is a formal system for reasoning about things and the way they relate to each other. In natural language I can express a statement like:

John is the father of Bill.
 
Here I have two "things": John and Bill, and a "relation" between these, namely that one is the father of the other. In Horn Clause Logic I can formalize this statement in the following way:
 ...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Prolog
  • prologo
  • Prologo
  • Prologo
  • Prólogo
  • Prolog
  • El prologo
  • Prologo

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS