Symbolic Programming Declarative Programming

Similar documents
Logic Programming. fac(n-1,m) fac(n,n m) fac(1,1) ex) factorial program query. cf) in procedural programming. ?- fac(5,120). yes?- fac(5,x).

Logic as a Programming Language

First-Order Logic (FOL)

Chapter 16. Logic Programming. Topics. Logic Programming. Logic Programming Paradigm

First-Order Logic. Cholwich Nattee. Sirindhorn International Institute of Technology Thammasat University. Lecture 9: First-Order Logic 1/60

Syntax and Meaning of Prolog Programs

Introduction to predicate calculus

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation

COMP219: Artificial Intelligence. Lecture 6: Recursion in Prolog

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy

CS 321 Programming Languages and Compilers. Prolog

Last Week COMP219: Artificial Intelligence Lecture 8 Prolog Lecture 2 Recursive Definitions Recursion The Ancestor Relation

Programming Language Concepts (20013) Preparation for the Final Exam

Prolog. Reading: Sethi, Chapter 11. Overview. Predicate Calculus. Substitution and Unication. Introduction to Prolog. Prolog Inference Rules

The current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday.

CS 360: Programming Language Concepts Lecture 15 Logic Programming

PROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012.

Resolution (14A) Young W. Lim 6/14/14

Prolog. Prolog: Programmation en Logique R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp.

will take you everywhere.

Advanced Logic and Functional Programming

CS 360: Programming Languages Lecture 10: Logic Programming with Prolog

CSC4504/Prolog. : Formal Languages & Applications. J Paul Gibson, D311. An Introduction To Prolog

For Wednesday. No reading Chapter 9, exercise 9. Must be proper Horn clauses

Chapter 16. Logic Programming Languages ISBN

Programming Language Concepts (20013) Preparation for the Final Exam

PROgramming in LOGic. Part II. By Forrest Pepper 12/7/07

Programming in Prolog. CSE 505 Computing with Logic Stony Brook University

Lecture 4: January 12, 2015

Programming Paradigms

An introduction to Prolog. P. Cabalar ( Department Prolog of Computer Science University of Corunna, FebruarySPAIN 8, 2016)

6. Inference and resolution

Sec Negative Goals ( Not ) 21

ACSC300: Logic Programming

Prolog. Logic Programming vs Prolog

THE PREDICATE CALCULUS

Logic Languages. CSE 307 Principles of Programming Languages Stony Brook University

ITS336 Lecture 7 Prolog

Notes for Chapter 12 Logic Programming. The AI War Basic Concepts of Logic Programming Prolog Review questions

CPS 506 Comparative Programming Languages. Programming Language Paradigm

Programming Language Concepts Logic Programming Prolog. Janyl Jumadinova 14 March, 2017

CS 4700: Artificial Intelligence

Symbolic AI. Andre Freitas. Photo by Vasilyev Alexandr

Chapter 16. Logic Programming Languages ISBN

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

2 Spatial Representation of Rule Bases A Horn clause rulebase consists of a set of clauses. Each clause comprising an antecedent and a consequent such

Logic Programming Languages

Week 7 Prolog overview

An introduction to logic programming with Prolog

Artificial Intelligence

Lecture 7: January 15, 2014

Chapter 16. Logic Programming Languages

Logic (or Declarative) Programming Foundations: Prolog. Overview [1]

Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg

IF/Prolog V5.3. User s Guide. Siemens AG Austria

Visual Prolog Tutorial

PROLOG PROgramming in LOGic

Using Prolog as a CAS

Last Week. Today. Prolog: recursion examples. Recursion in Prolog. CSC326 Programming Languages (Week 12,Friday)

First-Order Predicate Logic. Introduction to Intelligent Systems

1.2 Commercial Products of AI Robotics device. Vision systems that recognize shapes & objects.

Quick n Dirty Prolog Tutorial

/99/$ IEEE

CSEN403 Concepts of Programming Languages. Topics: Logic Programming Paradigm: PROLOG Search Tree Recursion Arithmetic

CSC384: Intro to Artificial Intelligence Prolog Tutorials 3&4. Hojjat Ghaderi, Fall 2006, University of Toronto

Database Theory VU , SS Introduction to Datalog. Reinhard Pichler. Institute of Logic and Computation DBAI Group TU Wien

PROgramming in LOGic PROLOG Recursion, Lists & Predicates

Automated Reasoning Systems

UNIVERSITETET I OSLO

Logic Languages. Hwansoo Han

to read: Chapter 10, Russel & Norvig

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3.

Operators (2A) Young Won Lim 10/2/13

CSE 452: Programming Languages. Prolog Statements. Loading the Knowledge Base. Logical Programming Languages Part 2

Lecture 6: Inductive Logic Programming

Multi-agent and Semantic Web Systems: Representation

Prolog. GNU Prolog ( SWI-Prolog (

CS Introduction to Artificial Intelligence

COMP219: Artificial Intelligence. Lecture 14: Knowledge Representation

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms

Cost Models. Chapter Twenty-One Modern Programming Languages, 2nd ed. 1

Research in the Logic Group

Introduction (1A) Young Won Lim 9/12/13

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

Structured Knowledge Representation

UNIT 2 A. I. LANGUAGES-2: PROLOG

Part I CHR tutorial. Cambridge University Press Constraint Handling Rules Thom Fruhwirth Excerpt More information

This lecture covers: Prolog s execution strategy explained more precisely. Revision of the elementary Prolog data types

Using Prolog as a CAS

Com S 541. Programming Languages I

Software Paradigms (Lesson 6) Logic Programming

(Refer Slide Time: 05:25)

Declarative Programming Prolog CS360

Amalgamating Multiple Programming Paradigms in Prolog. Yoshiyuki Koseki

has to choose. Important questions are: which relations should be dened intensionally,

Chapter 1. An introduction to Prolog

The Logic Paradigm. Joseph Spring. 7COM1023 Programming Paradigms

Scalable Data Exchange with Functional Dependencies

Logical reasoning systems

Coding Categorical Variables in Regression: Indicator or Dummy Variables. Professor George S. Easton

Transcription:

CS370 Symbolic Programming Declarative Programming LECTURE 2: Introduction to Prolog park@cs.kaist.ac.kr Computer Science Department Korea Advanced Institute of Science and Technology http://nlp.kaist.ac.kr/~cs370

Overview Primer Introduction to Prolog 2 Symbolic Programming

Primer Symbolic Programming cf. numeric computation There are well-known examples of symbolic computation whose implementation in other standard languages took tens of pages of indigestible code. When the same algorithms were implemented in Prolog, the result was a crystal-clear program easily fitting on one page. 3 Symbolic Programming

Primer Declarative Programming cf. procedural programming Many believe that every student of computer science should learn something about Prolog at some point because Prolog enforces a different problem-solving paradigm complementary to other programming languages. 4 Symbolic Programming

Primer Logic Programming cf. functional programming Prolog stands for programming in logic, emerging from the idea of using logic as a programming language. But Prolog is a general programming language and any algorithm can be programmed in it. 5 Symbolic Programming

Primer Prerequisites none No particular programming experience is required. In fact, plentiful experience and devotion to procedural programming - for example in C or Pascal - might even be an impediment to the fresh way of thinking Prolog requires. 6 Symbolic Programming

Introduction to Prolog Defining relations by facts Defining relations by rules Recursive rules How Prolog answers questions Declarative and procedural meaning of programs 7 Symbolic Programming

Defining relations by facts Example Sentence Tom is a parent of Bob. Example Representation parent(tom,bob). Are there any other ways? tom-is-a-parent-of-bob. parent-of-bob(tom). relation(parent,tom,bob). relation(parent,2,tom,bob). What are the pros and cons? generality, extensibility, indexibility 8 Symbolic Programming

Defining relations by facts Questions Who is Tom a parent of??- parent(tom,x). X = bob yes Who else is Tom a parent of? parent(tom,bob). parent(tom,liz).?- parent(tom,x). X = bob; X = liz; no 9 Symbolic Programming

Defining relations by facts Question Who is a grandparent of Jim? parent(tom,bob). parent(tom,liz). parent(bob,jim).?- parent(x,y), parent(y,jim). X = tom, Y = bob yes Any other possibilities? 10 Symbolic Programming

Defining relations by rules Encoding gender information female(liz). Are there any other ways? gender(liz,feminine). person(liz,female,21,...). female([liz,sue,mary]). X is a male if it is not a female. What are the pros and cons? issues? 11 Symbolic Programming

Defining relations by rules Other relations the offspring relation Method 1: offspring(liz,tom). Method 2: offspring(y,x) :- parent(x,y). the mother relation mother(x,y) :- parent(x,y), female(x). the grandparent relation grandparent(x,z) :- parent(x,y), parent(y,z). Are there any other ways? 12 Symbolic Programming

Defining relations by rules Defining the sister relation sister(x,y) :- parent(z,x), parent(z,y), female(x). Any problems? Liz is a sister of herself? One possible solution sister(x,y) :- parent(z,x), parent(z,y), female(x), different(x,y). 13 Symbolic Programming

Recursive rules What is recursion? definition Why do we need recursion? reason Example: the predecessor relation predecessor(x,z) :- parent(x,z). predecessor(x,z) :- parent(x,y), predecessor(y,z). 14 Symbolic Programming

How Prolog answers questions Terminologies predicate, argument, clause, procedure fact, rule, head and body, goal, question Sample Interaction Axioms fallible(x) :- man(x). % All men are fallible. man(socrates). % Socrates is a man. Is this a theorem??- fallible(socrates). % Is Socrates fallible? yes 15 Symbolic Programming

How Prolog answers questions Another sample interaction?- predecessor(tom,pat). backtracking parent(pam,bob). parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim). female(pam). male(tom). male(bob). female(liz). female(ann). female(pat). male(jim). offspring(y,x) :- parent(x,y). mother(x,y) :-.... sister(x,y) :-.... grandparent(x,z) :- parent(x,y), parent(y,z). predecessor(x,z) :- parent(x,z). predecessor(x,z) :- parent(x,y), predecessor(y,z). 16 Symbolic Programming

Meaning of programs Declarative meaning concerned with the relations defined by the program determines what will be the output of the program Procedural meaning determines how this output is obtained (or, how the relations are actually evaluated by the Prolog system) 17 Symbolic Programming

Summary Prolog programming consists of defining relations and querying about relations. A program consists of clauses. These are of three types: facts, rules and questions. A relation can be specified by facts, or by stating rules about the relation. A procedure is a set of clauses about the same relation. 18 Symbolic Programming