Logic Programming Lecture 1: Course orientation; Getting started with Prolog.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

Introduction to LISP Programming of Pathway Tools Queries and Updates.
© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Foundations of Programming and Problem Solving Introduction.
Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
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
1 Logic Programming School of Informatics, University of Edinburgh Logic Programming in 50 Minutes The purpose of this lecture is to explain why logic.
Logic Programming Lecture 9: Constraint logic programming.
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
Lecture 1: IntroductionIntro to IT COSC1078 Introduction to Information Technology Lecture 1 Introduction James Harland
COSC1078 Introduction to Information Technology Lecture 2 Overview
CS101: Introduction to Computer programming
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Introduction to Python
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Chapter 11 :: Logic Languages
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 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
Lecture 2 Introduction to C Programming
Introduction to C Programming
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
CS 331 / CMPE 334 – Intro to AI CS 531 / CMPE AI Course Outline.
Proof System HY-566. Proof layer Next layer of SW is logic and proof layers. – allow the user to state any logical principles, – computer can to infer.
Symbolic AI weeks of even numbers Lecture Monday 13:00-14:00 (2Q50) Lab Sessions (five groups, all in 2Q52) Monday.
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
Project Management Take a Tour of the Online Course.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Formal Models of Computation Part II The Logic Model
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
OPERATING SYSTEMS AND LANGUAGE TRANSLATORS CIS 2380 TERM 2 – LANGUAGE TRANSLATORS Lee McCluskey – 23/09/20151.
COSC 2P93 Logic Programming Instructor: Brian Ross Instructor: Brian Ross Texts: Texts: Prolog Programming for Artificial Intelligence,4e, Ivan Bratko,
Logic Programming Programming Lecture 1: Getting started with Prolog.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
F28PL1 Programming Languages Lecture 16: Prolog 1.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Artificial Intelligence Programming in Prolog Lecture 1: An Introduction 23/09/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.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
CPSC 121: Models of Computation Unit 0 Introduction George Tsiknis Based on slides by Patrice Belleville and Steve Wolfman.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Logical and Functional Programming
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 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
For Friday No reading Prolog Handout 2. Homework.
Logic Programming Lecture 8: Term manipulation & Meta-programming.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
Logic Programming Lecture 8: Term manipulation & Meta-programming.
Logic Programming Lecture 8: Term manipulation & Meta-programming.
Logic Programming Lecture 2: Unification and proof search.
Functional Programming Lecture 1 - Introduction Professor Muffy Calder.
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Welcome to CS 1010! Algorithmic Problem Solving.
Dr. Yasser Nada Fall 2010/2011 Lecture 1
Chapter 2: Prolog (Introduction and Basic Concepts)
Representations & Reasoning Systems (RRS) (2.2)
CS313T Advanced Programming language
Presentation transcript:

Logic Programming Lecture 1: Course orientation; Getting started with Prolog

James CheneyLogic ProgrammingSeptember 19, 2011 What is Logic Programming? Logic Programming is a programming paradigm cf. object-oriented or functional programming Not a particular language (like Java or Haskell) Declarative philosophy specify problem, let computer search for answer

James CheneyLogic ProgrammingSeptember 19, 2011 The declarative dream Slogan: "Algorithm = Logic + Control" Would like to write a program that describes the solutions to the problem Computer then finds answers Programmer shouldn't have to think about how the system works

James CheneyLogic ProgrammingSeptember 19, 2011 The reality Purely declarative programming can only get you so far I/O, interaction with outside world, seem inherently "imperative" For efficiency/termination, sometimes need finer-grained control over search

James CheneyLogic ProgrammingSeptember 19, 2011 Prolog Prolog is the best-known LP language Core based on first-order (predicate) logic Algorithmic realization via unification, search Many implementations that make it into a full-fledged programming language I/O, primitive ops, efficiency issues complicate declarative story

James CheneyLogic ProgrammingSeptember 19, 2011 Why learn LP? LP often great for rapidly prototyping algorithms/search strategies "Declarative" ideas arise in many areas of CS LP concepts very important in AI, databases, PL SAT solvers, model-checking, constraint programming Becoming important in program analysis, Semantic Web Learning a very different "way to think about problems" makes you a better programmer

James CheneyLogic ProgrammingSeptember 19, 2011 Course objectives Theory first-order logic, semantics of LP unification, resolution proof search Programming basic LP techniques in Prolog how to use LP to solve interesting problems AI, parsing, search, symbolic processing

James CheneyLogic ProgrammingSeptember 19, 2011 Organization Lectures M,Th 15:00 Programming Monday (James Cheney) Theory Thursday (Alex Simpson) No lectures week of October Tutorial/lab sessions: TBA, from week 3 Assignment 1 (programming) due: October 24 Assignment 2 (theory) due: November 14 Slides, tutorial problems posted on course web page:

James CheneyLogic ProgrammingSeptember 19, 2011 Evaluation 10 point UG3 course Coursework There will be two formatively assessed assignments Marking/feedback provided but not part of final grade Tutorial participation strongly encouraged Final exam: Programming 50% Theory 50% Tutorial, coursework exercises representative of exam problems UG3 students: pass mark 40% MSc students: pass mark 50%

James CheneyLogic ProgrammingSeptember 19, 2011 Getting started We’ll use SICStus Prolog Available on all DICE machines Tutorials, exams will be based on this version Windows, Mac version free for UofE students Can request through Computing Support Online documentation

James CheneyLogic ProgrammingSeptember 19, 2011 Hello World Prolog is an interactive language. $ sicstus

James CheneyLogic ProgrammingSeptember 19, 2011 Hello World Prolog is an interactive language. $ sicstus ?- Prompt

James CheneyLogic ProgrammingSeptember 19, 2011 Hello World Prolog is an interactive language. $ sicstus ?- print(’hello world’). Goal

James CheneyLogic ProgrammingSeptember 19, 2011 Hello World Prolog is an interactive language. $ sicstus ?- print(’hello world’). hello world yes Output response

James CheneyLogic ProgrammingSeptember 19, 2011 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’

James CheneyLogic ProgrammingSeptember 19, 2011 Variables A variable is a sequence of alphanumeric characters usually starting with an uppercase letter Examples: X Y Z Parent Child Foo

James CheneyLogic ProgrammingSeptember 19, 2011 Predicates A predicate has the form p(t 1,...,t n ) where p is an atom and t 1...t n are terms (For now a term is just an atom or variable) Examples: father(homer, bart) mother(marge, bart)

James CheneyLogic ProgrammingSeptember 19, 2011 Predicates (2) A predicate has a name = atom p in p(t 1,...,t n ) 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

James CheneyLogic ProgrammingSeptember 19, 2011 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!

James CheneyLogic ProgrammingSeptember 19, 2011 Goals A goal is a sequence of predicates p(t 1,...,t n ),..., q(t 1 ',...,t n '). We interpret “,” as conjunction Logically, read as "p holds of t 1...t n and... and q holds of t 1 '...t m '" Predicates can be 0-ary Some built-ins: true, false, fail

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

James CheneyLogic ProgrammingSeptember 19, 2011 Examples ?- father(X,bart). X = homer ; no ?- father(X,Z), mother(Y,Z). X = homer, Y = marge, Z = bart ; X = homer, Y = marge, Z = lisa ; X = homer, Y = marge, Z = maggie ; no

James CheneyLogic ProgrammingSeptember 19, 2011 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).

James CheneyLogic ProgrammingSeptember 19, 2011 Miscellaneous Comments % single line comment /* multiple line comment */ To quit Sicstus, type ?- exit. (or just control-D)

James CheneyLogic ProgrammingSeptember 19, 2011 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’).

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

James CheneyLogic ProgrammingSeptember 19, 2011 A complete program /* hello.pl * James Cheney * Sept. 20, 2010 */ main :- print('hello world').

James CheneyLogic ProgrammingSeptember 19, 2011 Tracing trace/0 turns on tracing notrace/0 turns tracing off debugging/0 shows tracing status

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

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

James CheneyLogic ProgrammingSeptember 19, 2011 Next time Compound terms Equality and unification How Prolog searches for answers