ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1.

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

Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial.
AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 2
Logic Programming Two possible work modes: 1.At the lab: Use SICstus Prolog. To load a prolog file (*.pl or *.pro extension) to the interpreter, use: ?-
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
Introducing JavaScript
Prolog.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
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).
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
PROLOG Basics A Prolog program consists of a database of facts and rules, and queries (questions). Fact:.... Rule:... :-.... Query: ?-.... Variables: must.
LING 388 Language and Computers Lecture 3 9/09/03 Sandiway FONG.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
DEDUCTIVE DATABASE.
PROLOG KAIST Gunwoo Park 1. What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is.
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
Tutorial 6 CSCI3230 ( First Term) Hands on
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.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Getting Started with Visual Prolog
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
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.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
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?
By: Cory Canter CSC 415 Programming Languages. History  Created by Alain Colmerauer, Phillipe Roussel and Robert Kowalski in 1971  Started as a natural.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
Logic Programming Dr. Yasser Nada Fall 2010/2011 Lecture 1 1 Logic Programming.
ISBN Chapter 16 Logic Programming Languages.
Knowledge Based Information System
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
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).
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Section 16.5, 16.6 plus other references
Chapter 2 - Introduction to C Programming
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Computer Programming I
CS 115 Lecture 8 Structured Programming; for loops
PROLOG.
Chapter 2 - Introduction to C Programming
Microsoft Access Illustrated
Tests, Backtracking, and Recursion
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Dr. Yasser Nada Fall 2010/2011 Lecture 1
Logic Programming Language
Chapter 2 - Introduction to C Programming
Clauses and Predicates
Chapter 2: Prolog (Introduction and Basic Concepts)
PROLOG.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1

Outline SWI-Prolog Setup IDE Prolog Basic 2

SWI-Prolog 1. Download (Official) (Portable) 2. After installation, open 3 User query and interpreter output

Your First Prolog Program 4

Create and Consult 5 Consult Save (Ctrl-S)

Query 6 Have I taken the course wp? What courses have I taken? Press. to end the query Press ; to backtrack Have I taken the course wp1?

Modify Prolog File Editor Use Compile buffer to consult the whole Prolog file again and update the Prolog database Use Consult selection to consult the Prolog file partially Highlight when there is syntax error Query Window Use Reload modified files to reload the whole Prolog file (useful when you are using other editors) 7 New fact

1. Prolog Basics An atom is a bunch of alphanumeric characters (the underscore character( _) is also treated as an alphanumeric character), starting with a lowercase letter.Some atoms are constants, while others are predicates. A variable is a bunch of alphanumeric characters, starting with a capital letter or the bottom line character ( _ ). In Prolog, variables and constants need not be declared. Constants and variables are called terms. Uppercase and lowercase letters are different in Prolog. In addition to atoms and variables, Prolog can handle numbers as well. 8

1. Prolog Basics 9 Non-variable Atomic Atom Number Compound Variable csci3230 dept [] 100 f(f(a),f(X)) [1, 2, 3, 4] [[eric, kate], [[peter, mary]] X Csci3230 Dept (Person,Food) Terms: Data Objects

1. Prolog Basics: Fact Facts should always begin with a lowercase letter and end with a full stop. The facts themselves can consist of any letter or number combination, as well as the underscore _ character. However, names containing the characters -,+,*,/, or other mathematical operators should be avoided. Examples of Simple Facts john_is_cold. /* john is cold */ raining. /* it is raining */ fred_lost_his_car_keys. /* fred lost is car keys */ peter_footballer. /* peter plays football */ 10

1. Prolog Basics: Fact More complicated facts consist of a relation and the items that this refers to. These items are called arguments. Facts can have arbitrary number of arguments from zero upwards. A general model is shown below: relation(,,...., ). Example eats(fred,oranges). /* "Fred eats oranges" */ eats(fred,t_bone_steaks). /* "Fred eats T-bone steaks" */ eats(tony,apples). /* "Tony eats apples" */ 11

1. Prolog Basics: Fact 12 Example 1 %Fact leo_is_handsome. %Fact_with_Arguments handsome(leo). ?- leo_is_handsome. true. ?- leo_is_not_handsome. ERROR: Undefined procedure: leo_is_not_handsome/0 ?- handsome(leo). true. ?- handsome(tom). false. ?- handsome(X). X = leo.

Statements FACTS states a predicate holds between terms. 13 Example 2 father(harry,james).%Fact 1 mother(harry,lily).%Fact 2 ?- father(harry,james). true.

1. Prolog Basics: Variable 14 Example 1 %Fact_with_Arguments_including_atom_and_number age(leo, 26). age(sun, 26). age(peter, 27). ?- age(leo, 26). true. ?- age(leo, 16). false. ?- age(X, 26). X = leo; X = sun.

1. Prolog Basics: Variable 15 Example 1 %Fact_with_Arguments_including_atom_and_number age(leo, 26). age(sun, 26). age(peter, 27). ?- age(X, Y). X = leo, Y = 26 ; X = sun, Y = 26 ; X = peter, Y = 27.

1. Prolog Basics: Rule Rules allow us to make conditional statements about our world. Each rule can have several variations, called clauses. These clauses give us different choices about how to perform inference about our world. 16

1. Prolog Basics: Rule 17 %Rules_Examples likes(mary,apple). likes(mary,orange). likes(mary,lemon). likes(tom,X):-likes(mary,X). ?- likes(mary,apple). true. ?- likes(tom,apple). true. ?- likes(tom,banana). false. If

1. Prolog Basics: Rule 18 %Rules_Examples likes(mary,apple). likes(mary,orange). likes(mary,lemon). likes(tom,X):-likes(mary,X). likes(kate,grape). likes(kate,orange). taste(F):-likes(mary,F);likes(kate,F). buy(F):-likes(mary,F),likes(kate,F). ?- taste(apple). true. ?- buy(apple). false. ?- buy(orange). true. Or And

1. Prolog Basics: Rule RULES defines the relationship 19 MeaningPredicate CalculusPROLOG And, Or; if:- Notnot r(…) :- conditions for r(…) be true. body head

Debug Prolog 20 Open the GUI Debugger

Debug Prolog 21 Example likes(mary,apple). likes(mary,orange). likes(mary,lemon). likes(kate,grape). likes(kate,orange). buy(F):-likes(mary,F),likes(kate,F). ?- spy(likes/2). %Start the Graphical Debugger first true. [debug] ?- buy(F). %See the Graphical Debugger F = orange. [trace] ?- notrace. %Exit the trace mode true. [debug] ?- nodebug. %Exit the debug mode true.

22 Step Unification Green indicates true. Red indicates false. Skip this goal Finish the selected goal Call stack

Reference Reference manual of SWI-Prolog More advanced Prolog The Craft of Prolog by Richard A. O'Keefe ogpages/index.html#menu 23