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

Size: px
Start display at page:

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

Transcription

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

2 Anatomy of a Program We discussed the three main constructs of a Prolog program Facts contain a property or state a relationship between two or more objects. These are considered always true. parents(jim,jane,john). Its cold!. Rules allow us to infer that a property or relationship hold based on preconditions. child(x,y) :- parents(y,_,x). child(x,y) :- parents(_,y,x). Queries ask question that causes an answer to be deduced from the facts and rules given in the program.?- child(john,jane). Yes

3 Predicate Logic Rules and facts use predicate definitions In a given clause from Prolog: parent(larry,john). the predicate is defined as the label in front of the parentheses. In this case, parents is the predicate. The predicate defines a property about the given constants or variables. This property is similar to predicates in the English language: the predicate is verb that states something about its subject. Parent defines a parent - child relationship to the given information. Predicate logic allows for all relationships to be used inductively. grandparent(x,y) :- parent(x,z), parent(z,y).

4 Predicates need Clauses A predicate definition uses clauses. All clauses have a Head and/or Body. Every clause has a Head, but not every clause has a Body. Facts are constant and therefore only have a body. Whereas Rules have a Head that contains the predicate and a Body that contains the actual Rule. (left side of the :- is the Head, right side is the body. Fact: parent(jim,john). %has a head Rule: child(x,y):- parent(y,x). %has head and body

5 Arguments Arguments can be found within the Head as the subject to the predicate or the objects listed in parentheses and separated by commas. Arguments found in the Body can be a constant, or a variable, or reference another predicate. child(jackie,jane). parent(x,y) :- child(y,x). parent(x,y) :- parent(child(z,y),x). Arguments would be: jackie, jane, X, Y, Z, child(z,y). The following can be arguments: All Types Variables Predicates

6 Types Weakly typed: Types are never declared in Prolog. Integers and Floating Points: 5, 87, -15, Non-numeric types or atoms: must start with a lowercase letter and can contain any characters afterwards with the exception of a space. parent, youngest_child. String: can be defined as any combination of letters, spaces, or characters between apostrophes. Anything goes here 12@#$*

7 Variables Variables start with an upper case alphabetic character or an underscore. Other than the first character they can be made up of any mixture of letters, digits, and underscores. e.g. X, Index, _7blah41, _any_thing_here There are no types for variables (or constants) a variable can take any value. All Prolog variables have a local scope: they only keep the same value within a clause; the same variable used outside of a clause does not change to the new value.

8 Arity The number of arguments given defines the arity of a function or predicate in Prolog. parents(jim,jane,john). % arity = 3 parent(jane,john). % arity = 2 child(john). % arity=1

9 Unification When one term instantiates another as the same they are considered unified. (i.e. the two are congruent)?- parent(jane,x) = parent(y,jackie). X = jackie, Y = jane yes Terms that won t unify fred = jim. Hey you = Hey me. frou(frou) = f(frou). foo(bar) = foo(bar,bar). foo(n,n) = foo(bar,rab). Unified terms Outcome fred = fred. yes. Hey you = Hey you. yes fred=x. X=fred. X=Y. Y = X. foo(x) = foo(bar). X=bar. foo(n,n) = foo(bar,x). N=bar, X=bar. foo(foo(bar)) = foo(x) X = foo(bar)

10 Have a conversation Using predicates and the write and read commands, the user can create conversation with the program. Program hello :- write( Hi, what is your name? ), nl, read(x), write( Nice to meet you ), write(x). Command Line?- hello. Hi, what is your name? : forrest. Nice to meet you forrest

11 Recursion Prolog does not use loops in its language but instead relies on recursive calls to the original predicate. While recursion is not as efficient, the code is very concise and intuitive. Using tail recursion increases the efficiency. Base case is defined by a fact, b/c facts are always true. A rule must also be written using the same predicate. The rule would then execute a boolean and a set of commands including a call back to its own predicate.

12 Base_two This recursive function returns 2 to the power of X degree. base_two(0,1). base_two(x,y) :- X > 0, X2 is X-1, base_two(x2,y2), Y is 2 * Y2.?- base_two(3,y). Y=8

13 Factorial! factorial(0,1). factorial(x,y) :- X > 0, X2 is X-1, factorial(x2,y2), Y is X *Y2.?- factorial(3,y). Y = 6

14 Homework 1. Use class_ex.pl from class on Wednesday. Complete the rule for cousins. (this may require editing other rules) 2. Write a recursive function for the fibonacci sequence.

Prolog (cont d) Remark. Using multiple clauses. Intelligent Systems and HCI D7023E

Prolog (cont d) Remark. Using multiple clauses. Intelligent Systems and HCI D7023E Intelligent Systems and HCI D703E Lecture : More Prolog Paweł Pietrzak Prolog (cont d) 1 Remark The recent version of SWI- Prolog displays true and false rather than and no Using multiple clauses Different

More information

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

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy Topics Chapter 16 Logic Programming Summary (resolution, unification, Prolog search strategy ) Disjoint goals The cut operator Negative goals Predicate fail Debugger / tracer Lists 2 Resolution Resolution

More information

Week 7 Prolog overview

Week 7 Prolog overview Week 7 Prolog overview A language designed for A.I. Logic programming paradigm Programmer specifies relationships among possible data values. User poses queries. What data value(s) will make this predicate

More information

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

Programming Language Concepts Logic Programming Prolog. Janyl Jumadinova 14 March, 2017 Programming Language Concepts Logic Programming Prolog Janyl Jumadinova 14 March, 2017 Background Japan s Fifth Generation project 1982: (https: //en.wikipedia.org/wiki/fifth_generation_computer) These

More information

Logic Languages. Hwansoo Han

Logic Languages. Hwansoo Han Logic Languages Hwansoo Han Logic Programming Based on first-order predicate calculus Operators Conjunction, disjunction, negation, implication Universal and existential quantifiers E A x for all x...

More information

PROgramming in LOGic PROLOG Recursion, Lists & Predicates

PROgramming in LOGic PROLOG Recursion, Lists & Predicates PROgramming in LOGic PROLOG Recursion, Lists & Predicates CSC9Y4 1 Recursion Recursion in Prolog means placing in the body of a rule a call to the predicate which occurs in the head of the rule. Here is

More information

INTRODUCTION TO PROLOG

INTRODUCTION TO PROLOG INTRODUCTION TO PROLOG PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/44 STRUCTURE OF A PROLOG PROGRAM Where, declaratively, Haskell expresses a computation as a system

More information

Introduction to predicate calculus

Introduction to predicate calculus Logic Programming Languages Logic programming systems allow the programmer to state a collection of axioms from which theorems can be proven. Express programs in a form of symbolic logic Use a logical

More information

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

CS 360: Programming Languages Lecture 10: Logic Programming with Prolog CS 360: Programming Languages Lecture 10: Logic Programming with Prolog Geoffrey Mainland Drexel University Section 1 Administrivia Midterm Tuesday Midterm is Tuesday, February 14! Study guide is on the

More information

Predicate Calculus. Problems? Syntax. Atomic Sentences. Complex Sentences. Truth

Predicate Calculus. Problems? Syntax. Atomic Sentences. Complex Sentences. Truth Problems? What kinds of problems exist for propositional logic? Predicate Calculus A way to access the components of an individual assertion Predicate Calculus: used extensively in many AI programs, especially

More information

Prolog. Artificial Intelligence. Lecture 2 Karim Bouzoubaa

Prolog. Artificial Intelligence. Lecture 2 Karim Bouzoubaa Prolog Artificial Intelligence Lecture 2 Karim Bouzoubaa Content Introduction Declarative and logic programming Example Computational model Prolog reasoning Structure of prolog programs Prolog concepts

More information

Topic 1: Introduction to Knowledge- Based Systems (KBSs)

Topic 1: Introduction to Knowledge- Based Systems (KBSs) Topic 1: Introduction to Knowledge- Based Systems (KBSs) 1.5 Introduction to Logic Programming (Prolog) 32 Simple example: Algorithm for checking sorted list? We all know how to check if a list is sorted:

More information

Topic A: Introduction to Prolog

Topic A: Introduction to Prolog Topic A: Introduction to Prolog Recommended Exercises and Readings From Programming in Prolog (5 th Ed.) Exercises: 1.2, 1.3, 1.4, Readings: Chapters 1 and 2 1 2 Prolog Prolog: Programming in Logic A logic

More information

CMSC 331 Final Exam Section 0201 December 18, 2000

CMSC 331 Final Exam Section 0201 December 18, 2000 CMSC 331 Final Exam Section 0201 December 18, 2000 Name: Student ID#: You will have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for

More information

Software Paradigms (Lesson 6) Logic Programming

Software Paradigms (Lesson 6) Logic Programming Software Paradigms (Lesson 6) Logic Programming Table of Contents 1 Introduction... 2 2 Facts... 3 3 Predicates (Structured Terms)... 4 3.1 General Structures... 4 3.2 Predicates (Syntax)... 4 3.3 Simple

More information

will take you everywhere.

will take you everywhere. Prolog COMP360 Logic will get you from A to B. Imagination will take you everywhere. Albert Einstein Prolog Assignment A programming assignment in Prolog has been posted on Blackboard Upload your.pl file

More information

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

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation Topics Chapter 16 Logic Programming Proving Theorems Resolution Instantiation and Unification Prolog Terms Clauses Inference Process Backtracking 2 Predicate Calculus and Proving Theorems A use of propositions

More information

Introduction to Prolog

Introduction to Prolog Introduction to Prolog David Woods dwoods@scss.tcd.ie Week 3 - HT Declarative Logic The Prolog programming language is, at its theoretical core, a declarative language. This is unlike more commonly used

More information

First-Order Logic (FOL)

First-Order Logic (FOL) First-Order Logic (FOL) FOL consists of the following parts: Objects/terms Quantified variables Predicates Logical connectives Implication Objects/Terms FOL is a formal system that allows us to reason

More information

Wan Hussain Wan Ishak

Wan Hussain Wan Ishak February 2 nd Session 2014/2015 (A142) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com

More information

Wan Hussain Wan Ishak

Wan Hussain Wan Ishak September 1 st Session 2014/2015 (A141) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com

More information

Brief Introduction to Prolog

Brief Introduction to Prolog CSC384: Intro to Artificial Intelligence Brief Introduction to Prolog Prolog Programming for Artificial Intelligence by Ivan Bratko. Prolog is a language that is useful for doing symbolic and logic based

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

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

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. 1 Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. Satisfying goals 2 Prolog A standard free Prolog can be downloaded from http://www.swi-prolog.org

More information

Prolog 2. Unification and Recursion

Prolog 2. Unification and Recursion Prolog 2 Unification and Recursion The Notion of Unification Unification is when two things become one Unification is kind of like assignment Unification is kind of like equality in algebra Unification

More information

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

CSEN403 Concepts of Programming Languages. Topics: Logic Programming Paradigm: PROLOG Search Tree Recursion Arithmetic CSEN403 Concepts of Programming Languages Topics: Logic Programming Paradigm: PROLOG Search Tree Recursion Arithmetic Prof. Dr. Slim Abdennadher 8.2.2015 c S. Abdennadher 1 Logic Programming versus Prolog

More information

Logic - CM0845 Introduction to Prolog

Logic - CM0845 Introduction to Prolog Logic - CM0845 Introduction to Prolog Diego Alejandro Montoya-Zapata EAFIT University Semester 2016-1 Diego Alejandro Montoya-Zapata (EAFIT University) Logic - CM0845 Introduction to Prolog Semester 2016-1

More information

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

This lecture covers: Prolog s execution strategy explained more precisely. Revision of the elementary Prolog data types This lecture covers: Prolog s execution strategy explained more precisely The execution strategy has been presented as simply placing all matching clauses onto the stack. In fact, Prolog is slightly more

More information

Programming Languages Prolog Programming Project Due Wednesday, December 5 th, 2001

Programming Languages Prolog Programming Project Due Wednesday, December 5 th, 2001 Programming Languages Prolog Programming Project Due Wednesday, December 5 th, 2001 How Prolog Works Although Prolog is a very powerful and expressive programming environment, it is surprisingly easy to

More information

Fundamentals of Prolog

Fundamentals of Prolog Fundamentals of Prolog Prof. Geraint A. Wiggins Centre for Cognition, Computation and Culture Goldsmiths College, University of London Contents Summary of Lecture 1 What makes a good Prolog program? What

More information

Prolog. IFT 6802 Introduction to Prolog. Declarative programming LOGIC PROGRAMMING BASICS. LOGIC PROGRAMMING BASICS (suite) Facts

Prolog. IFT 6802 Introduction to Prolog. Declarative programming LOGIC PROGRAMMING BASICS. LOGIC PROGRAMMING BASICS (suite) Facts Prolog IFT 6802 Introduction to Prolog Par Jean Vaucher (& Laurent Magnin) A programming language based on the formalism and the concepts of formal logic. PROgrammation LOGique Robinson (resolution) Kowalski

More information

Inference rule for Induction

Inference rule for Induction Inference rule for Induction Let P( ) be a predicate with domain the positive integers BASE CASE INDUCTIVE STEP INDUCTIVE Step: Usually a direct proof Assume P(x) for arbitrary x (Inductive Hypothesis),

More information

Lecture 16: Logic Programming in Prolog

Lecture 16: Logic Programming in Prolog Lecture 16: Logic Programming in Prolog COMP 524 Programming Language Concepts Stephen Olivier March 26, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of

More information

Prolog Programming. Chapter 2. Syntax and Meaning of Prolog Programs 1/16/2010

Prolog Programming. Chapter 2. Syntax and Meaning of Prolog Programs 1/16/2010 Prolog Programming Chapter 2 Syntax and Meaning of Prolog Programs 1/16/2010 1 Chapter 2 Syntax and Meaning of Prolog Programs Data Objects Matching Declarative meaning of Prolog programs Procedural meaning

More information

COP4020 Programming Languages. Logical programming with Prolog Prof. Xin Yuan

COP4020 Programming Languages. Logical programming with Prolog Prof. Xin Yuan COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan Topics Logic programming with Prolog COP4020 Spring 2013 2 Definitions: Prolog Terms Terms are symbolic expressions that are

More information

Defining Functions. CSc 372. Comparative Programming Languages. 5 : Haskell Function Definitions. Department of Computer Science University of Arizona

Defining Functions. CSc 372. Comparative Programming Languages. 5 : Haskell Function Definitions. Department of Computer Science University of Arizona Defining Functions CSc 372 Comparative Programming Languages 5 : Haskell Function Definitions Department of Computer Science University of Arizona collberg@gmail.com When programming in a functional language

More information

Advanced Logic and Functional Programming

Advanced Logic and Functional Programming Advanced Logic and Functional Programming Lecture 1: Programming paradigms. Declarative programming. From first-order logic to Logic Programming. Programming paradigms Programming paradigm (software engineering)

More information

Concepts of programming languages

Concepts of programming languages Concepts of programming languages Prolog Winand, Roald, Sjoerd, Alexey and Anvar 1 What is logic programming? Logic programming is a type of programming paradigm which is largely based on formal logic.

More information

Chapter 16. Logic Programming Languages ISBN

Chapter 16. Logic Programming Languages ISBN Chapter 16 Logic Programming Languages ISBN 0-321-49362-1 Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming

More information

ITS336 Lecture 7 Prolog

ITS336 Lecture 7 Prolog Lecture 7 Prolog Prolog is a language for logic programming. Its concept is based on the First Order Logic. 7.1 Prolog Syntax Constant Symbols a word starting with a lowercase letter, or numbers e.g. john,

More information

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION Alessandro Artale UniBZ - http://www.inf.unibz.it/ artale/ SECTION 5.9 General Recursive Definitions and Structural Induction Copyright Cengage

More information

ACSC300: Logic Programming

ACSC300: Logic Programming ACSC300: Logic Programming Lecture 1: Introduction to Logic Programming and Prolog Harris Papadopoulos Course Aims This course aims to help you to: Understand a radically different programming paradigm:

More information

CMSC 331 Final Exam Section 0201 December 18, 2000

CMSC 331 Final Exam Section 0201 December 18, 2000 CMSC 331 Final Exam Section 0201 December 18, 2000 Name: nswers Student ID#: You will have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points

More information

COSC441. Lecture 8 Introduction to Erlang

COSC441. Lecture 8 Introduction to Erlang COSC441 Lecture 8 Introduction to Erlang Approach The reference book is Learn You Some Erlang for Great Good! by Fred Hébert. http://learnyousomeerlang.com lets you read it free on-line. What I am going

More information

Chapter 16. Logic Programming Languages

Chapter 16. Logic Programming Languages Chapter 16 Logic Programming Languages Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming The Origins of

More information

Symbolic Programming Declarative Programming

Symbolic Programming Declarative Programming 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

More information

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321 Sketchpad Graphics Language Reference Manual Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321 October 20, 2013 1. Introduction This manual provides reference information for using the SKL (Sketchpad

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

Prolog Programming. Lecture Module 8

Prolog Programming. Lecture Module 8 Prolog Programming Lecture Module 8 Prolog Language Prolog is unique in its ability to infer facts from the given facts and rules. In Prolog, an order of clauses in the program and goals in the body of

More information

Constraint Solving. Systems and Internet Infrastructure Security

Constraint Solving. Systems and Internet Infrastructure Security Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA Constraint Solving Systems

More information

Logic Programming Languages

Logic Programming Languages Logic Programming Languages Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical inferencing process to

More information

Lecture 11: Feb. 10, 2016

Lecture 11: Feb. 10, 2016 CS323: AI (Hands on with Prolog) Spring 2016 Lecturer: K.R. Chowdhary Lecture 11: Feb. 10, 2016 : Professor of CS (VF) Disclaimer: These notes have not been subjected to the usual scrutiny reserved for

More information

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion simple and/or composition of goals hides complex control patterns not easily represented by traditional

More information

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

More information

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

For Wednesday. No reading Chapter 9, exercise 9. Must be proper Horn clauses For Wednesday No reading Chapter 9, exercise 9 Must be proper Horn clauses Same Variable Exact variable names used in sentences in the KB should not matter. But if Likes(x,FOPC) is a formula in the KB,

More information

CS 320: Concepts of Programming Languages

CS 320: Concepts of Programming Languages CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 04: Basic Haskell Continued o Polymorphic Types o Type Inference with Polymorphism o Standard

More information

Derived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses

Derived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses Prolog Programming Derived from PROgramming in LOGic (1972) Good at expressing logical relationships between concepts Prolog and LISP - two most popular AI languages Execution of a Prolog program is a

More information

Programming Paradigms

Programming Paradigms David Ng June 30, 2017 Contents 1 May 17, 2017 3 1.1 Programming Paradigm............................ 3 1.2 Languages.................................... 3 1.3 Haskell.....................................

More information

Prolog. Intro to Logic Programming

Prolog. Intro to Logic Programming Prolog Logic programming (declarative) Goals and subgoals Prolog Syntax Database example rule order, subgoal order, argument invertibility, backtracking model of execution, negation by failure, variables

More information

Exercises on the Fundamentals of Prolog

Exercises on the Fundamentals of Prolog 1 Introduction Exercises on the Fundamentals of Prolog These exercises are intended to help reinforce material taught in the lectures of CIS335 course in Prolog. They do not contribute any marks to the

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion simple and/or composition of goals hides complex control patterns not easily represented by traditional

More information

Java+- Language Reference Manual

Java+- Language Reference Manual Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect

More information

Program Analysis in Datalog

Program Analysis in Datalog CS 510/08 Program Analysis in Datalog Majority of the slides compiled from John Whaley s Outline Challenges Essential Background Using the Tools Developing Advanced Analyses Challenges Most DF analyses

More information

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 506 Comparative Programming Languages. Programming Language Paradigm CPS 506 Comparative Programming Languages Logic Programming Language Paradigm Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic

More information

6. Inference and resolution

6. Inference and resolution Computer Science and Software Engineering University of Wisconsin - Platteville 6. Inference and resolution CS 3030 Lecture Notes Yan Shi UW-Platteville Read: Textbook Chapter 8 Part of the slides are

More information

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong

LING/C SC/PSYC 438/538. Lecture 20 Sandiway Fong LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong Today's Topics SWI-Prolog installed? We will start to write grammars today Quick Homework 8 SWI Prolog Cheatsheet At the prompt?- 1. halt. 2. listing. listing(name).

More information

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

Prolog. Prolog: Programmation en Logique R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp. Prolog Prolog: Programmation en Logique 1974 - R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp. 569-574: First-order predicate logic for the specification of data and relationships

More information

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 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 Programming Logic Programming = ex) factorial program query fac(1,1) fac(n-1,m) fac(n,n m)?- fac(5,120). yes?- fac(5,x). X=120 cf) in procedural programming x=1; for (i=1;i

More information

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0)) SCHEME 0 COMPUTER SCIENCE 6A July 26, 206 0. Warm Up: Conditional Expressions. What does Scheme print? scm> (if (or #t (/ 0 (/ 0 scm> (if (> 4 3 (+ 2 3 4 (+ 3 4 (* 3 2 scm> ((if (< 4 3 + - 4 00 scm> (if

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

UNIT 2 A. I. LANGUAGES-2: PROLOG

UNIT 2 A. I. LANGUAGES-2: PROLOG UNIT 2 A. I. LANGUAGES-2: Structure Page Nos. 2.0 Introduction 42 2.1 Objectives 43 2.2 Foundations of Prolog 43 2.3 Notations in Prolog for Building Blocks 46 2.4 How Prolog System Solves Problems 50

More information

Artificial Intelligence Course Sharif University of Technology

Artificial Intelligence Course Sharif University of Technology Artificial Intelligence Course Sharif University of Technology Outline Data objects Matching Declarative meaning of Prolog programs Procedural meaning Example: monkey and banana Order of clauses and goals

More information

Logical Decision Rules: Teaching C4.5 to Speak Prolog

Logical Decision Rules: Teaching C4.5 to Speak Prolog Logical Decision Rules: Teaching C4.5 to Speak Prolog Kamran Karimi and Howard J. Hamilton Department of Computer Science University of Regina Regina, Saskatchewan Canada S4S 0A2 {karimi,hamilton}@cs.uregina.ca

More information

Syntax and Meaning of Prolog Programs

Syntax and Meaning of Prolog Programs Chapter 2 Syntax and Meaning of Prolog Programs Data Objects Matching Declarative meaning of Prolog programs Procedural meaning Example : monkey and banana Order of clauses and goals The relation between

More information

Using Prolog as a CAS

Using Prolog as a CAS Using Prolog as a CAS Kharkiv Pedagogical University A. Stolyarevska July 2002 References 1) Robinson J.A. A machine-oriented logic based on the resolution principle. J. ACM, 12, 23-41. 2) Colmerauer A.

More information

Programming Paradigms Written Exam (6 CPs)

Programming Paradigms Written Exam (6 CPs) Programming Paradigms Written Exam (6 CPs) 06.07.2016 First name Student number Last name Signature Instructions for Students Write your name and student number on the exam sheet and on every solution

More information

Introduction to Logic Programming in Prolog 1 / 39

Introduction to Logic Programming in Prolog 1 / 39 Introduction to Logic Programming in Prolog 1 / 39 Outline Programming paradigms Logic programming basics Introduction to Prolog Predicates, queries, and rules Understanding the query engine Goal search

More information

10 Recursive Programming in Prolog

10 Recursive Programming in Prolog 10 Recursive Programming in Prolog What's in This Set of Notes? Examples Transforming Recursion to Iteration Recursive Comparison Joining Structures Accumulators Mapping Problems 10.1 Examples select_first(x,xs,ys)

More information

Chapter 16. Logic Programming Languages ISBN

Chapter 16. Logic Programming Languages ISBN Chapter 16 Logic Programming Languages ISBN 0-321-49362-1 Chapter 16 Topics Introduction A Brief Introduction to Predicate Calculus Predicate Calculus and Proving Theorems An Overview of Logic Programming

More information

Shell CSCE 314 TAMU. Haskell Functions

Shell CSCE 314 TAMU. Haskell Functions 1 CSCE 314: Programming Languages Dr. Dylan Shell Haskell Functions 2 Outline Defining Functions List Comprehensions Recursion 3 Conditional Expressions As in most programming languages, functions can

More information

COMP219: Artificial Intelligence. Lecture 6: Recursion in Prolog

COMP219: Artificial Intelligence. Lecture 6: Recursion in Prolog COMP219: Artificial Intelligence Lecture 6: Recursion in Prolog 1 Overview Last time Introduction to Prolog: facts, rules, queries; family tree program Today: Recursive rules in Prolog; writing and evaluating

More information

Logic Programming Paradigm

Logic Programming Paradigm Logic Programming Paradigm Sample Courseware Logic Programming Paradigm Logic programming offers a formalism for specifying a computation in terms of logical relations between entities. A logic program

More information

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

CSC4504/Prolog. : Formal Languages & Applications. J Paul Gibson, D311. An Introduction To Prolog CSC4504/Prolog. : Formal Languages & Applications J Paul Gibson, D311 paul.gibson@telecom-sudparis.eu http://www-public.telecom-sudparis.eu/~gibson/teaching/csc4504/ An Introduction To Prolog /~gibson/teaching/csc4504/problem8-prolog.pdf

More information

Prolog. Logic Programming vs Prolog

Prolog. Logic Programming vs Prolog Language constructs Prolog Facts, rules, queries through examples Horn clauses Goal-oriented semantics Procedural semantics How computation is performed? Comparison to logic programming 1 Logic Programming

More information

CSC 270 Survey of Programming Languages. Basic Constructs of Prolog

CSC 270 Survey of Programming Languages. Basic Constructs of Prolog CSC 270 Survey of Programming Languages Prolog Lecture 1 Facts, Rules, and Queries Basic Constructs of Prolog Prolog has only three basic constructs: Facts statements that are unconditionally true Rules

More information

Research Report AI A Numerical Equation Solver in Prolog Michael A. Covington Artificial Intelligence Programs The University of Georgia

Research Report AI A Numerical Equation Solver in Prolog Michael A. Covington Artificial Intelligence Programs The University of Georgia Research Report AI 1989 02 A Numerical Equation Solver in Prolog Michael A. Covington Artificial Intelligence Programs The University of Georgia Athens, Georgia 30602 U.S.A. A Numerical Equation Solver

More information

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1 A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

More information

4.2 Function definitions the basics

4.2 Function definitions the basics 4.2. FUNCTION DEFINITIONS THE BASICS 89 4.2 Function definitions the basics There are three questions you must answer before you can write a function definition: What will the function do? What inputs

More information

Introducing Prolog. Chapter THE IDEA OF PROLOG

Introducing Prolog. Chapter THE IDEA OF PROLOG Chapter 1 Introducing Prolog 1.1. THE IDEA OF PROLOG Until recently, programming a computer meant giving it a list of things to do, step by step, in order to solve a problem. In Prolog, this is no longer

More information

Operational Semantics

Operational Semantics 15-819K: Logic Programming Lecture 4 Operational Semantics Frank Pfenning September 7, 2006 In this lecture we begin in the quest to formally capture the operational semantics in order to prove properties

More information

Procedures, Parameters, Values and Variables. Steven R. Bagley

Procedures, Parameters, Values and Variables. Steven R. Bagley Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.

More information

The Logic Paradigm. Joseph Spring. 7COM1023 Programming Paradigms

The Logic Paradigm. Joseph Spring. 7COM1023 Programming Paradigms The Logic Paradigm Joseph Spring 7COM1023 Programming Paradigms 1 Discussion The Logic Paradigm Propositional and Predicate Logic See also notes and slides on PP website Horn Clauses Definition, Examples

More information

CAP 5602 Summer, Lesson 4: Loops. The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop

CAP 5602 Summer, Lesson 4: Loops. The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop CAP 5602 Summer, 2011 Lesson 4: Loops The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop 1. The cut The cut (!) is a way of controlling backtracking. If a rule contains a

More information

Part I Logic programming paradigm

Part I Logic programming paradigm Part I Logic programming paradigm 1 Logic programming and pure Prolog 1.1 Introduction 3 1.2 Syntax 4 1.3 The meaning of a program 7 1.4 Computing with equations 9 1.5 Prolog: the first steps 15 1.6 Two

More information

Logic Programming. Manipulating Programs. Temur Kutsia

Logic Programming. Manipulating Programs. Temur Kutsia Logic Programming Manipulating Programs Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria kutsia@risc.uni-linz.ac.at Contents Listing Writing Prolog Interpreter

More information

Prolog. (Programming in Logic) Prepared by: Tanay Kumar Saha

Prolog. (Programming in Logic) Prepared by: Tanay Kumar Saha Prolog (Programming in Logic) Prepared by: Tanay Kumar Saha Motivation for Learning Prolog Follow prolog news: http://www.swi-prolog.org/news SWI-Prolog Used For Satellite Anomaly Detection Fast cars and

More information

AI2 Remedial Prolog Tutorial 2

AI2 Remedial Prolog Tutorial 2 AI2 Remedial Prolog Tutorial 2 Rules The Prolog interpreter is able to make inferences (i.e. reasoning of the form If Alan drinks beer, then he must like it). This is done by way of using rules. There

More information

CS 381: Programming Language Fundamentals

CS 381: Programming Language Fundamentals CS 381: Programming Language Fundamentals Summer 2017 Introduction to Logic Programming in Prolog Aug 2, 2017 Outline Programming paradigms Logic programming basics Introduction to Prolog Predicates, queries

More information

CASE STUDY LOGIC PROGRAMMING

CASE STUDY LOGIC PROGRAMMING CASE STUDY LOGIC PROGRAMMING 1 OUTLINE Preliminary Concepts Horn Clauses Logic Programming in Prolog Prolog Program Elements Practical Aspects of Prolog Prolog Examples Solving Word Puzzles Natural Language

More information