Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial.
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: ?-
Getting started with Prolog
Logic Programming Lecture 1: Course orientation; Getting started with Prolog.
1 Logic Programming School of Informatics, University of Edinburgh Logic Programming in 50 Minutes The purpose of this lecture is to explain why logic.
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 12: Working with Files This lecture is concerned with various aspects of file handling and.
Chapter 11 :: Logic Languages
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
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).
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/25.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
1 About Prolog Lu Han Written at Modified at
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 13 Slides Courtesy to: Peter LO.
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
1 Prolog I. 2 Syllogisms “Prolog” is all about programming in logic. –Socrates is a man. –All men are mortal. –Therefore, Socrates is mortal.
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
Logic Programming Programming Lecture 1: Getting started with Prolog.
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: ?-
Java CGI Lecture notes by Theodoros Anagnostopoulos.
F28PL1 Programming Languages Lecture 16: Prolog 1.
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
Artificial Intelligence Programming in Prolog Lecture 1: An Introduction 23/09/04.
For Wednesday No new reading Prolog handout 2 Chapter 9, exercise 4.
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.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
Introduction to Prolog Facts, Questions & Rules Atoms & Variables.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
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?
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Logical and Functional Programming
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
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)
Logic Programming Dr. Yasser Ahmed Nada Fall 2010/2011 Lecture 2 1 Logic Programming.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
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.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Knowledge Based Information System
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
For Friday No reading Prolog Handout 2. Homework.
Logic Programming Lecture 8: Term manipulation & Meta-programming.
For Wednesday No reading Prolog handout 2 Chapter 9, exercise 4.
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.
Section 16.5, 16.6 plus other references
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
PROLOG.
ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1.
Prolog programming Introduction to Prolog (part2)
PROLOG PROgramming in LOGic
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong.
Dr. Yasser Nada Fall 2010/2011 Lecture 1
Introduction to Computer Science
Clauses and Predicates
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

Logic Programming Lecture 1: Getting started

Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines

Hello World Prolog is an interactive language. $ sicstus

Hello World Prolog is an interactive language. $ sicstus ?- Prompt

Hello World Prolog is an interactive language. $ sicstus ?- print(’hello world’). Goal

Hello World Prolog is an interactive language. $ sicstus ?- print(’hello world’). hello world yes Output response

Atoms An atom is a sequence of alphanumeric characters usually starting with lower case letter or, a string enclosed in single quotes Examples: homer marge lisa bart ‘Mr. Burns’ ’Principal Skinner’

Variables A variable is a sequence of alphanumeric characters usually starting with an uppercase letter Examples: X Y Z Parent Child Foo

Predicates A predicate has the form p(t1,...,tn) where p is an atom and t1...tn are terms (For now a term is just an atom or variable) Examples: father(homer, bart) mother(marge, bart)

Predicates (2) Predicates have a name = atom p in p(t1,...,tn) and an arity = number of arguments (n) Predicates with same name but different arity are different We write foo/1, foo/2,... to refer to these different predicates

Facts A fact is an assertion that a predicate is true: father(homer, bart). mother(marge, bart). A collection of facts is sometimes called a knowledge base (or database). Punctuation is important!

Goals A goal is a sequence of predicates p(t1,...,tn),..., q(t1',...,tn'). We interpret “,” as conjunction Logically, read as "p holds of t1...tn and... and q holds of t1'...tm'"

Answers Given a goal, Prolog searches for answer(s) “yes” (possibly with substitution) “no” Substitutions are bindings of variables that make goal true Use “;” to see more answers

Rules A rule is an assertion of the form p(ts) :- q(ts’),..., r(ts’’). where ts, ts’, ts’’ are sequences of terms “p(ts) holds if q(ts’) holds and... and r(ts’’) holds” Example: sibling(X,Y) :- parent(Z,X), parent(Z,Y).

Tracing trace/0 turns on tracing notrace/0 turns tracing off debugging/0 shows tracing status

Consulting A Prolog program is a collection of facts and rules, or clauses stored in one or more files The predicate consult/1 loads the facts/rules in a file ?- consult(‘simpsons.pl’).

Consulting (2) If the file name ends with '.pl', can just write: ?- consult(simpsons). Also, can just write ?- [foo].

Simple I/O read/1: reads a term from input and binds its argument write/1: writes a term to output Example: loop :- read(X), process(X,Y), write(Y), loop. For most programming problems you can just work interactively

Further reading Quick Prolog notes (Dave Robertson) Learn Prolog Now! (Blackburn, Bos, Striegnitz) online, free Programming in Prolog (Clocksin & Mellish) a standard/classic text, many library copies

Next time Compound terms Equality and unification How Prolog searches for answers

Exercises Using simpsons.pl, write goal bodies for: classmate(X,Y) employer(X) parent(X,Y) grandparent(X,Y) More in tutorial problems handout