Programming in Logic: Prolog

Similar documents
WUENIC A Case Study in Rule-based Knowledge Representation and Reasoning

TAKING AND DEFENDING DEPOSITIONS

Information sheet. (as at January 2019) 1.1 In what cases was citizenship deprived on political, racial, or religious grounds?

East Georgia State College Social Sciences Division POLITICAL SCIENCE 1101 (CRN 20369; ; M/W/F) AMERICAN GOVERNMENT

PSC 305: Judicial Politics

INTL 3300: Introduction to Comparative Politics Fall Dr. Molly Ariotti M W F : 10:10-11 am Location: Candler Hall, Room 214 (BLDG 0031, RM 0214)

INTL 3300: Introduction to Comparative Politics Fall Dr. Molly Ariotti M W F : 10:10-11 am Location: Candler Hall, Room 214 (BLDG 0031, RM 0214)

AP United States Government and Politics Syllabus

Many-Valued Logics. A Mathematical and Computational Introduction. Luis M. Augusto

Mojdeh Nikdel Patty George

MAC 2311 CALCULUS 1 FALL SEMESTER 2015

H.B. 69 Feb 13, 2019 HOUSE PRINCIPAL CLERK

Development of a Background Knowledge-Base about Transportation and Smuggling

REMITTANCES TO ETHIOPIA

CS 5523: Operating Systems

Phrases. A group of words that does not have a subject and a verb

GENERAL ASSEMBLY OF NORTH CAROLINA SESSION 2017 HOUSE BILL DRH10050-BK-2 (02/13) Short Title: Nonpartisan Redistricting Commission.

PS Introduction to American Government

Court of Protection Application form

Shanghai Jiao Tong University. LA200 Business Law

American National Government Spring 2008 PLS

Pretrial Litigation Guidelines Fall Wednesday Class 6-9 p.m. Rm TBA

CANADA S RESPONSE TO THE DESCHENEAUX DECISION: Bill S-3 and the Collaborative Process. January 2018

WESTERN ILLINOIS UNIVERSITY DEPARTMENT OF POLITICAL SCIENCE

Computerized Knowledge Representation and Common Law Reasoning, 9 Computer L.J. 223 (1989)

Guide on Firearms Licensing Law

CS 2461: Computer Architecture I

SCHOOLMASTER. Appointment Scheduling. Student Information Systems. Revised - August Schoolmaster is SIF Certified

Submission of written evidence to the Home Affairs Select Committee s Prostitution Inquiry. Dr. Mary Laing (Northumbria University)

Lecture 7 Act and Rule Utilitarianism. Based on slides 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Arguments and Artifacts for Dispute Resolution

OFFICE CONSOLIDATION BY-LAW

PA 372 Comparative and International Administration

Hoboken Public Schools. AP Calculus Curriculum

Application form. Court of Protection

Amended and Restated By-Laws of L. I. Harley Riders, Inc.

IBPS CWE (PO/MT) Previous Year Exam Paper 2012 Subject: Reasoning

IN THE HIGH COURT OF JUSTICE (PROBATE) Ms. Jenny Lindsay for the Appellant Mr. Simeon Fleming. 2014: January 28 RULING

Questionnaire to Accompany Study Visa Applications

LEG 283T.01: Trial Preparation

FA1. Application packet. Application for family reunification of spouses

GENERAL ASSEMBLY OF NORTH CAROLINA THIRD EXTRA SESSION 2016 HOUSE BILL DRH30015-LU-3 (12/13)

IBM Cognos Open Mic Cognos Analytics 11 Part nd June, IBM Corporation

Globalization, Causes and Effects: The US in Comparative Perspective Gov. 312L, Spring 2013

Project Lost In Translation

American Government I GOVT 2301 Collin College, Spring Creek

POLI SCI 101. Syllabus and Schedule

National Survey Report. May, 2018

Introduction: Data & measurement

WESTERN ILLINOIS UNIVERSITY DEPARTMENT OF POLITICAL SCIENCE

Ballot Reconciliation Procedure Guide


ProbLog Technology for Inference in a Probabilistic First Order Logic

CROSS USER GUIDE. Global Remittance Service Your Remiitance Hero, CROSS

Online Ballots. Configuration and User Guide INTRODUCTION. Let Earnings Edge Assist You with Your Online Ballot CONTENTS

Frequently Asked Questions

One View Watchlists Implementation Guide Release 9.2

Criminal Statutes of Limitations Missouri

Course Description and Objectives. Course Requirements

Office: Classroom Building 347 Tues. 10:30-12:30, POLI 110: Governmental Power and the Constitution Spring 2011

RODUCTION TO BROADCAST NEWS

McGILL UNIVERSITY Department of Economics ECON POLITICAL ECONOMY OF TRADE POLICY 1 WINTER 2018

Political Science 513 / Women s Studies 513 Women, Government, and Public Policy Spring Ohio State University

Richard David [as Personal Representative of Angelina Madonna Mitchel] And Geraldine David Vital

POLI 3531: The UN and World Politics

Comparison Sorts. EECS 2011 Prof. J. Elder - 1 -

2302: 2006 TR: 12:30-1:45PM (CBW

WRITTEN STATEMENT OF THE AMERICAN CIVIL LIBERTIES UNION. For a Hearing on. President Obama s Executive Overreach on Immigration

The table below presents the data as entered.

TULANE LAW REVIEW ONLINE

Hoboken Public Schools. Project Lead The Way Curriculum Grade 8

Political Economics II Spring Lectures 4-5 Part II Partisan Politics and Political Agency. Torsten Persson, IIES

AAMVA 2017 Region I Conference. Timothy Benz, SAVE Program FY17 Program Updates

Introduction to American Government and Politics

ECONOMICS 215: Economic History of the Middle East

Federalism is. Head a piece of paper as you see below in your spiral. Today s Music Requests:

IBM BOARD CORPORATE GOVERNANCE GUIDELINES. Effective Date: July 25, 2017

Office: Social Sciences & Management 304B Tues. & Thurs. 1-2, POLI 110: Governmental Power and the Constitution Spring 2014

Computational social choice Combinatorial voting. Lirong Xia

Course Syllabus Template

RPOS 334 American Political Parties and Groups. Location: SS 256

Understanding Patent Issues During Accellera Systems Initiative Standards Development

58 th Mid-Year Meeting Introducing Evidence in Family Court

TRM 2.0 Test Results Manager

Fact Sheet: Missing and Murdered Aboriginal Women and Girls in Saskatchewan

Logic-based Argumentation Systems: An overview

Political Science 1 Government of the United States and California Tuesday/Thursday 11:15-12:40 Section #2646 SOCS 212 Spring 2014

GVPT 221 SPRING 2018 INTRODUCTION TO FORMAL THEORIES OF POLITICAL BEHAVIOR AND POLITICS

Specifying and Analysing Agent-based Social Institutions using Answer Set Programming. Owen Cliffe, Marina De Vos, Julian Padget

POLA 210: American Government, Spring 2008

University at Albany, State University of New York

Instructor: Dr. Carol Walker Office: TBD Office Hours: Please contact instructor to make an appointment.

Chapter 8: Recursion

CRJU (POLS) 4424 Judicial Process Fall 2013 Course Syllabus. CRN or semester credit hours Prerequisite: POLS 1101

NUMERICAL QUANTIFIERS AND THEIR USE IN REASONING WITH NEGATIVE INFORMATION

Political Science 245: The United States in World Politics

TO: Chair and Members REPORT NO. CS Committee of the Whole Operations & Administration

The Biology of Politics Fall 2016 Monday & Wednesdays, 11:00am - 12:15pm

COURSE SYLLABUS PREREQUISITE: 6 SEMESTER HOURS OF LOWER-DIVISION COURSEWORK IN GOVERNMENT, INCLUDES CROSS-CULTURAL CONTENT.

Professional Practice 544

Transcription:

Programming in Logic: Prolog Introduction Reading: Read Chapter 1 of Bratko MB: 26 Feb 2001 CS 360 - Lecture 1 1

Overview Administrivia Knowledge-Based Programming Running Prolog Programs Prolog Knowledge Base Anatomy MB: 26 Feb 2001 CS 360 - Lecture 1 2

Administrivia: Contact Info Instructor: Mike Barley Office: Rm 253 Math/Physics Bldg Phone: x6133 Email: barley@cs.auckland.ac.nz Office Hours: Tues 1-3:00 MB: 26 Feb 2001 CS 360 - Lecture 1 3

Administrivia: Assessment 2 Homework assignments: 5% each Assignment 1 Handed out: 5 March Due back: 19 March Assignment 2 Handed out: 19 March Due back: 2 April Test: 10% - 2 May Exam: 30% MB: 26 Feb 2001 CS 360 - Lecture 1 4

Administrivia: Which Version of Prolog? A copy of SICStus Prolog 3.3 is on cs26. Its path is: /usr/local/bin/prolog Assignments will be marked using this Prolog. Warning: Different versions of Prolog handle certain things slightly differently. Evaluation copies of SICStus Prolog 3.8 are freely available from www.sics.se but they are only good for a month. MB: 26 Feb 2001 CS 360 - Lecture 1 5

Administrivia: Textbook Bratko, Programming for Artificial Intelligence, 3rd edition. Required. MB: 26 Feb 2001 CS 360 - Lecture 1 6

Administrivia: Prerequisites Understand syntax, semantics, and some basic results of first-order predicate calculus (PC). For example, DeMorgan s law applied to quantifiers: ~( x y loves(y,x) hates(y,x)) A) x y ~loves(y,x) ~hates(y,x) B) x y ~loves(y,x) ~hates(y,x) MB: 26 Feb 2001 CS 360 - Lecture 1 7

Be able to translate English into PC and vice versa, e.g., no one loves everyone. A) x y ~loves(x, y) B) ~ x y loves(x, y) Know the difference between: x y loves(x, y) x y loves(x, y) MB: 26 Feb 2001 CS 360 - Lecture 1 8

Administrivia: Course Goals Give a glimpse of the beauty of logic programming. Give a taste of knowledge-based programming. Develop ability to write declarative specifications of program in Prolog. Develop ability to incrementally optimise a Prolog program. MB: 26 Feb 2001 CS 360 - Lecture 1 9

Administrivia: Syllabus Pure Prolog: Chapters 1-3.3, 4 Purely Declarative Features Prolog: Chapters 3.4, 5, 6, 7 Introducing Control Features Advanced Features: Chapters 8.5, 9, 14 More of both MB: 26 Feb 2001 CS 360 - Lecture 1 10

Declarative Programming Declarative programming describes what to compute rather than how to compute it. E.g., blueprints for a house are declarative, they describe what to build not how to build it. Describing what is often much easier than describing how (but not always). Algorithm = Logic + Control (R. Kowalski, 1979) Logic expressions are declarative. MB: 26 Feb 2001 CS 360 - Lecture 1 11

Advantages of Declarative Style of Programming Simply encode your knowledge without worrying how the knowledge will be used. The underlying inference engine uses that knowledge to answer the user s queries. Knowledge can be used in many ways: Is Mary Peter s sister? Who is Peter s sister? Who is whose sister? MB: 26 Feb 2001 CS 360 - Lecture 1 12

Knowledge Bases A Knowledge Base has: Knowledge in the form of: Facts (e.g., Socrates is a man) Rules (e.g., All men are mortals) An inference engine A Knowledge Base uses its facts, rules, and inference engine to answer questions. Is Socrates mortal? yes MB: 26 Feb 2001 CS 360 - Lecture 1 13

Logic Programming & Knowledge Bases Logic programming languages are one way to implement knowledge bases. Encode your knowledge base and your queries then the underlying inference engine will attempt to answer your queries. The inference engine answers your queries by building constructive proofs that your queries are entailed by the knowledge base. MB: 26 Feb 2001 CS 360 - Lecture 1 14

Simple Example: Families Define the relevant relationships: mother, father, brother, sister, aunt, uncle, cousin, ancestor, descendant Store the basic facts: parents, siblings, and gender Ask your queries: Who is whose sister? MB: 26 Feb 2001 CS 360 - Lecture 1 15

Some Rules motherof(m,o) :- parentof(m,o), female(m). sisterof(s,p) :- siblingof(s,p), female(s). auntof(a,n) :- sisterof(a,x), parentof(x,n). grandmotherof(g,p) :- motherof(g,x), parentof(p). ancestor(a,p) :- parentof(a,p). ancestor(a,p) :- parentof(a,x), ancestor(x,p).... MB: 26 Feb 2001 CS 360 - Lecture 1 16

Some Facts male(john). female(mary). male(peter). parentof(john, mary). siblingof(mary, peter). parentof(ann, john). parentof(mark, ann).... MB: 26 Feb 2001 CS 360 - Lecture 1 17

Some Queries?- sisterof(mary, peter).?- sisterof(mary, Who).?- sisterof(sis, peter).?- sisterof(sister, Sibling).?- ancestorof(a,p). MB: 26 Feb 2001 CS 360 - Lecture 1 18

Their Answers?- sisterof(mary, peter). yes?- sisterof(mary, Who). Who = peter? ; no?- sisterof(sis, peter). Sis = mary? ; no MB: 26 Feb 2001 CS 360 - Lecture 1 19

More Answers?- sisterof(sister, Sibling). Sibling = peter, Sister = mary? ; no MB: 26 Feb 2001 CS 360 - Lecture 1 20

Last Answer?- ancestorof(a,p). A = john, P = mary? ; A = ann, P = john? ; A = mark, P = ann? ; A = ann, P = mary? ;... MB: 26 Feb 2001 CS 360 - Lecture 1 21

Running Prolog Create knowledge base using favorite editor. Type /usr/local/bin/prolog on cs26. Load that knowledge base into Prolog: [ myknowledgebase.pl ]. Ask queries: sisterof(x,y). Exit Prolog: halt. MB: 26 Feb 2001 CS 360 - Lecture 1 22

Prolog Knowledge Base Anatomy Knowledge Base Relations Clauses Terms MB: 26 Feb 2001 CS 360 - Lecture 1 23

Terms Terms are things like atoms, numbers, variables, and structures: tom, 25.3, X, name(mike, barley) In happy(p) :- paid(p, X), spend(p,y), X>Y happy(p), :-, paid(p, X), spend(p,y), X>Y, P, X, and Y are all terms. MB: 26 Feb 2001 CS 360 - Lecture 1 24

Anatomy of a Clause All clauses terminated by full-stop(. ). Clauses have the form: head :- body. MB: 26 Feb 2001 CS 360 - Lecture 1 25

Head of a Clause The head may be the relation name with arguments or may be missing, Examples: likes(x,z) :- likes(x,y), likes(y,z). likes(mike,x) :- true. :- write(***). likes(mike,x) :- true. likes(mike,x). Clauses with missing bodies are called facts. Facts with variables are called universal facts. MB: 26 Feb 2001 CS 360 - Lecture 1 26

Body of a Clause Body is an expression composed of terms. When the clause head is missing then the body is executed at load-time. MB: 26 Feb 2001 CS 360 - Lecture 1 27

Anatomy of a Relation A relation is identified by its name and its arity (# of arguments) - name /arity likes/2 is a different relation from likes/3 A relation is defined by the clauses whose heads match the relation id, e.g., the clause ancestor(a, P) :- parentof(a, P). is part of the definition of ancestor/2 MB: 26 Feb 2001 CS 360 - Lecture 1 28

Anatomy of a Query Queries are input by the user (rather than part of the knowledge base). Queries have clause body syntax & semantics, notably variables are existentially quantified. When query has variables, & Prolog succeeds in proving it follows from KB, Prolog displays variable bindings used in proof. MB: 26 Feb 2001 CS 360 - Lecture 1 29

Quick Quiz What do you ignore (at least initially) in declarative-style programming? What are the two main components of a knowledge-based system? What is the type of knowledge encoded in a Prolog knowledge base? MB: 26 Feb 2001 CS 360 - Lecture 1 30

Quick Quiz cont d By what two things are relations identified? In a Prolog knowledge base, what constitutes the definition of a relation? What forms can a clause take? What are the two parts of a clause? What terminates a clause? Give examples of different types of terms. MB: 26 Feb 2001 CS 360 - Lecture 1 31

Summary Declarative programming focuses on specifying what you want, not on how to get it. Knowledge based systems provide an underlying inference engine, the user provides (in declarative form) the knowledge and the queries. Prolog can be viewed as a type of knowledge based programming system. MB: 26 Feb 2001 CS 360 - Lecture 1 32

Summary cont d Prolog knowledge base = relation collection. Relation identified by name/arity. Relation defined by clauses whose heads agree with that id (i.e., name & number of arguments) MB: 26 Feb 2001 CS 360 - Lecture 1 33

Summary cont d Clauses have following forms: head :- body. head. :- body. Queries are entered by the user (i.e., not in knowledge base) and have form of clause body. MB: 26 Feb 2001 CS 360 - Lecture 1 34