1 TP #1: What is a Prolog program? n The SWI Prolog interpreter; n How to load a Prolog program in the interpreter; n Asking questions to the program (execution).

Slides:



Advertisements
Similar presentations
© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Advertisements

Prolog Nonmonotonic logic.
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
1 Logic Programming. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
1 TP #3:List and Database manipulation n Last TP exercises solved; n Lists and their predefined predicates; n Prolog as a Database: predefined predicates.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 27: Prolog’s Resolution and Programming Techniques COMP 144 Programming Language.
1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.
An ide for teaching and learning prolog
AlgoTutor Tutorial (3) Program Pad J. Yoo, S. Yoo, C. Pettey, S. Seo, and Z. Dong MTSU Computer Science Department Making the transition from the algorithm.
Rounding Click Me to Practice When To Round When the question asks: – “Estimate how many…” – “About how many…” – Can you think of anymore?
Prolog programming Introduction to Prolog CS370d - CS 461.
PROLOG KAIST Gunwoo Park 1. What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is.
Formal Models of Computation Part II The Logic Model
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
LING 388: Language and Computers Sandiway Fong Lecture 4.
1 Lecture 15: Introduction to Logic Programming with Prolog (Section 11.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
Getting Started with Visual Prolog
ITEC 380 Organization of programming languages Lecture 7 – Prolog.
Chapter 2 Syntax and meaning of Prolog Programs LP and Prolog Chapter 22 PROLOG domains variable name = type predicates relation(variable name,
Prolog Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
Prolog. Syllogisms “Prolog” is all about programming in logic. –Socrates is a man. –All men are mortal. –Therefore, Socrates is mortal.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Logic Programming Dr. Yasser Nada Fall 2010/2011 Lecture 1 1 Logic Programming.
Knowledge Based Information System
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
1 TP #2: How does Prolog answer questions? n Miscellaneous info; n Last TP exercises solved; n How does Prolog answer questions? n Recursive Prolog programs;
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
Logic Programming Dr. Yasser Nada Fall 2010/2011 Lecture 3 1 Logic Programming.
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
1 TP #4: Control Facilities n Last TP exercises solved; n Don’t care variables « _ »; n Or « ; »; n Cut.
Problem Solving Procedure. When solving word problems in class, you are to use the G.U.E.S.S. Method. I don’t mean just taking a stab in the dark.
Objective #20: Solve systems of equations by substitution
Set. Words from the Fry List set put end.
Rounding Click Me to Practice.
The Distributive Property
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
An introduction to programming Created by Dr. Randy Pausch
Solving Two- Step Equations
Rules of Exponents Multiplying and powers
ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1.
Solving Two- Step Equations
Solving One Step Equations
Solving Two- Step Equations
INFLECTED ENDINGS.
Adding & Subtracting Integers
Solving Two- Step Equations
Prolog programming Introduction to Prolog
Prolog programming Introduction to Prolog (part3)
Warm up The chart is made of INDEPENDENT clauses.
Dr. Yasser Nada Fall 2010/2011 Lecture 1
State Name Interact with
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
5 сәуір Сынып жұмысы WordPad қолданбасымен танысу.
Solving Linear Equations
ONE STEP EQUATIONS Addition and Subtraction
Clauses and Predicates
over know only new place little new place little sound years work
Chapter 2: Prolog (Introduction and Basic Concepts)
CMPT 120 Lecture 3 - Introduction to Computing Science – Programming language, Variables, Strings, Lists and Modules.
Rounding Click Me to Practice.
Solving Linear Equations
4.4 – List vs Array Exercise 4.1: Array Variables
PROLOG.
Presentation transcript:

1 TP #1: What is a Prolog program? n The SWI Prolog interpreter; n How to load a Prolog program in the interpreter; n Asking questions to the program (execution). n Facts & Rules (some theory); n Exercise

© L.Lúcio, The SWI Prolog interpreter n SWI-Prolog ( is the Prolog interpreter we are going to use. u For Windows (at the university): F « Démarrer->Programmes->Programmation->SWIProlog2.8.0 » F Available text editor: Notepad, Wordpad u For Linux (at the university): F « /unige/SWI-Prolog/bin/pl » F Available text editor: emacs n Difference between Compilers and Interpreters?

© L.Lúcio, How to load a Prolog program n There are several ways: u Load directly from the OS: F In windows: double click on the program file; F In linux: « /unige/SWI-Prolog/bin/pl your_code.pl » u Load from the interpreter itself: F « ?- consult ‘path_to_code’ » or simpler F [‘path_to_code’] n Download the example at « »

© L.Lúcio, The first Prolog program… ?- consult(‘animals.pl’). ?- listing. habitat(bear,forest). habitat(elephant,savanah). habitat(cat,house). brown(bear). black(cat). gray(elephant). dark(Z) :- black(Z). dark(Z) :- brown(Z). n A Prolog program is composed of facts (faits) and rules (règles). n After defining all the facts and rules, it is possible to ask the interpreter questions (requêtes). } } The facts define what the system knows its true. The rules define how new facts can be created

© L.Lúcio, Asking questions n We can now ask questions to the program: ?- black(cat). yes. It is a fact. The program knows it. ?- brown(cat). ?- no. The program never heard about brown cats, so it replies ‘no’. ?- habitat(X, house). X = bear. yes. To the question « Who lives in a house? » or «Which X lives in a house? », there is one solution (X = cat). X is a variable for which the program tries to find a solution.

© L.Lúcio, Asking questions (2) ?- dark(bear). Yes. There is no fact stating that a bear is dark. But the rule « dark(X) :- brown (X) » means « all the X that are brown are also dark ». ?- dark(X). Who is dark? What would be the answer to this one? n How would we ask the program the following question: « From all the animals, give me those who are dark and live in the forest ». u Hint: comma (virgule) defines the conjunction between questions

© L.Lúcio, Prolog’s syntax n From the example, we can see that: u Atoms (atomes) always start with small letters. Atoms are used for defining basic Facts or to name relations: F Basic fact: bear F Relation: habitat(bear,forest) In this case « habitat » is the Predicate of the relation. u Variables always start with capital letters: F Example: X, Animal, _variable u Atoms and Variables define Terms (termes): F Example: X, 5, bear, black(cat), habitat(X,forest) u The comma (virgule) defines conjunction between terms; F Example: brown(Animal), habitat(Animal,forest) means Animal is brown AND Animal lives in the forest.

© L.Lúcio, Prolog’s syntax (2) u A Fact is a Term with no Variables: F Example: cat, black(cat), habitat(elephant,savanah) u Rules (Régles) are defined by a head (one term) followed by « :- » followed by a conjunction of terms which are the conditions that make the head true: F Example: dark(Z) :- brown(Z). scary(Animal) :- dark(Animal),habitat(Animal,forest). u A Question or Goal (requête) is a conjuction of terms: F Example: dark(Animal),habitat(Animal,forest). u And, don’t forget: a Prolog Fact or Rule (also called Clauses) always ends with a dot «. ».

© L.Lúcio, Exercise n Add new facts to the program stating the size of an animal (ex: big, small); n Add a new rule saying that a scary animal is one who is dark, big and lives in the forest; n When you are done try adding more animals and playing with the program…