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

Size: px
Start display at page:

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

Transcription

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

2 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 Prolog and logic 2

3 2.1 Data objects Atoms and Variables can be strings of the following: upper-case letters A,B,,Z lower-case letters a,b,,z digit 0,1,,9 special characters such as + - * / < > = :. & _ ~ 3

4 Data Objects in Prolog 4

5 Atoms Atoms can be constructed in three ways: String of letters, digits and the underscore character, _, starting with a lower-case letter : anna nil x_25 x_25ab x_ miss_jones Strings of special characters: <---> ======>.:. ::= Strings of character enclosed in single quotes Tom South_America Sarah Jones 5

6 Numbers Integer Numbers (limited range) Real Numbers (not used heavily)

7 Variables Variables are strings of letters, digits and underscore characters. They start with an upper-case letter or an underscore character: X Result Object2 Participant_list _x23 _23 7

8 Anonymous variable When a variable appears in a clause once only, we do not have to invent a name for it. Example, For all X, X has a child if X is a parent of some Y. In this case, it does not depend on the name of the child. In Prolog, hasachild(x) :- parent(x,y). can be written as hasachild(x) :- parent(x,_). 8

9 More Anonymous Example There is somebody who has a child if there are two objects such that one is a parent of the other: somenody_has_child :- parent(_,_). is equivalent to somenody_has_child :- parent(x,y). 9

10 Questions with Anonymous If the anonymous variable appears in a question clause then its value is not output Example to find the people who have children but not in the names of children?- parent(x,_). 10

11 Lexical Scope of Variables and Constants lexical scope of variable names is one clause That means, if X1 occurs in two clauses, then it signifies two different variables. Each occurrence of X1 within the same clause means the same variable The same atom always means the same object in any clause, that is, throughout the whole program 11

12 Structures Structured objects (structures) are objects that have several components Components themselves can, in turn, be structures. Structures treated in the program as single objects Functor to combine the components into a single object Example, date is a functor date(1, may, 2003) 12

13 More Structures Components can also be variables or other structures Example, any day in the month of May date(day, may, 2003) Day is a variable and can be instantiated in the execution. 13

14 terms All data objects in Prolog are terms Example, may and date(1,may,2003) are terms 14

15 Example ---Structured Objects P1=point(1,1) P2=point(2,3) S=seg(P1,P2)=seg(point(1,1),point(2,3)) T=triangle(point(4,2),point(6,4),point(7,1)) 15

16 Note about functors If the same name is defined for two different roles such as point(x1,y1) and point(x,y,z) Prolog system will recognize the difference by the number of arguments and will interpret this name as two funtors: one of them with two arguments and the other with three arguments. 16

17 Structures Representation For arithmetic expression such as (a+b) * (c-5) can be written as *(+ (a,b) - (c,5) ) 17

18 Tree structure for (a+b) * (c - 5) 18

19 More Tree Structures 19

20 Tree structure representations For (a) (b) (c) and (d) can be written as seq(r1,r2) par(r1,r2) par(r1,par(r2,r3)) par(r1,seq(par(r2,r3),r4)) 20

21 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 Prolog and logic 21

22 2.2 Matching Given two terms match if they are identical or the variables in both terms can be instantiated to objects in such a way that after the substitution of variables by these objects the terms become identical 22

23 Example?- date(d,m,2001) = date(15,may,y1). Prolog system will answer: D = 15 M = may Y1 = 2001 yes 23

24 The general rules to decide whether two terms, S and T match are as follows: If S and T are constants then S and T match only if they are the same objects If S is a variable and T is anything, then they match and S is instantiated to T. Conversely, if T is a variable then T is instantiated to S. If S and T are structures then they match only if S and T have the same principle functor and all their corresponding components match The resulting instantiation is determined by the matching of the components. 24

25 Illustration for matching Facts vertical(seg(point(x,y),point(x,y1))). % same X value horizontal(seg(point(x,y),point(x1,y))). % same Y value Questions?- vertical(seg(point(1,1),point(1,2))). yes?- vertical(seg(point(1,1),point(2,y))). no?- horizontal(seg(point(1,1),point(2,y))). Y = 1 yes 25

26 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 Prolog and logic 26

27 2.3 Declarative meaning of Prolog programs Declarative meaning To determine whether a given goal is true and if so, for what values it is true Instance An instance of a clause C is the clause C with each of its variables substituted by some term Variant Variant of a clause C is such an instance of the clause C where each variable is substituted by another variable 27

28 Example For a clause hasachild(x) :- parent(x,y). Two variants of the clause are: hasachild(a) :- parent(a,b). hasachild(x1) :- parent(x1,x2). Instances of this clause are: hasachild(peter) :- parent(peter,z). hasachild(barry) :- parent(barry,small(caroline)). 28

29 The declarative meaning Given a program and a goal A goal G is true ( that is, satisfiable, or logically follows from the program) if and only if: there is a clause C in the program such that there is a clause instance I of C such that the head of I is identical to G, and all the goals in the body of I are true 29

30 Difference between declarative and procedural meanings For a clause P :- Q, R. Declarative reading (two alternatives) P is true if Q and R is true From Q and R follows P Procedural reading (two alternatives) to solve problem P, first solve the sub-problem Q and then the sub-problem R to satisfy P, first satisfy Q and then R 30

31 Conjunction and Disjunction Conjunction (comma) P :- Q, R. both Q and R must be true to satisfy P Disjunction (semicolon) P :- Q ; R. any one of the goals, that is, Q or R has to be true 31

32 Comma is stronger than Semicolon P :- Q, R ; S, T, U. That means, P :- (Q, R) ; (S, T, U). Another way with two clauses P :- Q, R. P :- S, T, U. 32

33 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 Prolog and logic 33

34 2.4 Procedural meaning How Prolog answers questions to answer a question means to try to satisfy a list of goals executing a list of goals with respect to a given program execute goals means to try to satisfy them 34

35 Procedure execution Input : a program and a goal list Output a success/failure indicator and an instantiation of variables 35

36 The meaning of the two output results The success/failure indicator is yes if the goals are satisfiable and no otherwise An instantiation of variables is only produced in the case of a successful termination: in the case of failure there is no instantiation 36

37 Example to illustrate the procedural meaning Program big(bear). % Clause 1 big(elephant). % Clause 2 small(cat). % Clause 3 brown(bear). % Clause 4 black(cat). % Clause 5 gray(elephant). % Clause 6 dark(z) :- black(z). % Clause 7 dark(z) :- brown(z). % Clause 8 Question?- dark(x), big(x). % who is dark and big? 37

38 Execution Trace Step (1) Initial goal list : Step (2) dark(x), big(x). Scan the program from top to bottom match the first goal dark(x) in Clause 7 dark(z) :- black(z). replace the first goal by the instantiated body of clause 7, giving a new goal list: black(x), big(x). 38

39 Execution Trace Continue: Step (3) Scan the program to find a match with black(x). Clause 5 found black(cat). Since there is no body, the goal is instantiated X = cat and the goal list shrinks to : Step (4) big(cat). Scan the program for the goal big(cat). No Clause found. Backtrack to step 3 and undo the instantiation X = cat. Now the goal list is again : black(x), big(x). 39

40 Execution Trace Continue... Step (4) continue... Continue scanning the program below clause 5. No clause found. Backtrack to step (2) and continue scanning below clause 7. Clause 8 is found. dark(z) :- brown(z). Replace the first goal in the goal list by brown(x) : brown(x), big(x). 40

41 Execution Trace Continue... Step (5) Scan the program to match brown(x), finding brown(bear). Since this clause has no body, the goal list shrinks to : Step (6) big(bear). Scan the program and find clause big(bear). It has no body, so the goal list shrinks to empty. This indicates successful termination and the variable instantiation is : X = bear 41

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

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

PROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012. PROLOG Prolog is a programming language for symbolic, n-numeric computations. It is specially well suited for solving problems that involve objects and relation between objects. First simple Prolog Program

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

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

{ Prolog (Programming in Logic) is a programming language for AI and non-numerical

{ Prolog (Programming in Logic) is a programming language for AI and non-numerical Introduction to Prolog What is Prolog? { Prolog (Programming in Logic) is a programming language for AI and non-numerical programming in general. What is new? { Conventional (well established, standard)

More information

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

The current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday. The current topic: Prolog! Introduction! Object-oriented programming: Python! Functional programming: Scheme! Python GUI programming (Tkinter)! Types and values Logic programming: Prolog! Introduction

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

Recursion, Structures, and Lists

Recursion, Structures, and Lists Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 4 04/10/04 30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists 1 The central ideas of Prolog

More information

PROLOG programming for artificial intelligence

PROLOG programming for artificial intelligence Prolog Prolog.1 Textbook and Software Title PROLOG programming for artificial intelligence Author Ivan Bratko Get the software windows Home users: download from the course site Install software to preferred

More information

Prolog. Textbook and Software. Title PROLOG programming for artificial intelligence

Prolog. Textbook and Software. Title PROLOG programming for artificial intelligence Tutorial : Prolog Prolog Prolog.1 Textbook and Software Title PROLOG programming for artificial intelligence Author Ivan Bratko Get the software windows Download PL.zip from the course site Extract the

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 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

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

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

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

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

Topic B: Backtracking and Lists

Topic B: Backtracking and Lists Topic B: Backtracking and Lists 1 Recommended Exercises and Readings From Programming in Prolog (5 th Ed.) Readings: Chapter 3 2 Searching for the Answer In order for a Prolog program to report the correct

More information

COMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006

COMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006 OMP 9416, session 1, 2006 p. 1 Datalog OMP 9416, session 1, 2006 OMP 9416, session 1, 2006 p. 2 Atoms, integers and variables The fact "person(socrates).", the fact "sum(2,3,y)." and the rule "mortal(x)

More information

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

Programming in Prolog. CSE 505 Computing with Logic Stony Brook University Programming in Prolog CSE 505 Computing with Logic Stony Brook University http://www.cs.stonybrook.edu/~cse505 1 Relations/Predicates Predicates are building-blocks in predicate calculus: p(a 1,a 2,...,a

More information

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

Operators (2A) Young Won Lim 10/2/13 Operators (2A) Copyright (c) 2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

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

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

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

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

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

Last Week COMP219: Artificial Intelligence Lecture 8 Prolog Lecture 2 Recursive Definitions Recursion The Ancestor Relation COMP219: Artificial Intelligence Lecture 8 Prolog Lecture 2 Recursive Definitions Dr. Annabel Latham Ashton Building Room 2.05 http://www.csc.liv.ac.uk/~alatham/comp219.html Last Week Prolog programs comprised

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

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler. Name: Midterm Exam PID: This is a closed-book exam; you may not use any tools besides a pen. You have 75 minutes to answer all questions. There are a total of 75 points available. Please write legibly;

More information

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

Logic Languages. CSE 307 Principles of Programming Languages Stony Brook University Logic Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Languages Paradigms of Programming Languages: Imperative = Turing machines Functional

More information

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

PROgramming in LOGic. Part II. By Forrest Pepper 12/7/07 PROgramming in LOGic Part II By Forrest Pepper 12/7/07 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

More information

CHAD Language Reference Manual

CHAD Language Reference Manual CHAD Language Reference Manual INTRODUCTION The CHAD programming language is a limited purpose programming language designed to allow teachers and students to quickly code algorithms involving arrays,

More information

Declarative Programming Prolog CS360

Declarative Programming Prolog CS360 Declaratie Programming Prolog CS360 Terms Numerical literals String literals Ø By default, any string that starts is all lowercase Ø Use single quotes for anything else Atoms Ø Essentially, strings Ø Also,

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

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

What is Prolog? - 1. A Prolog Tutorial. What is Prolog? - 2. Prolog Programming. » Declaring some facts about objects and their relationships

What is Prolog? - 1. A Prolog Tutorial. What is Prolog? - 2. Prolog Programming. » Declaring some facts about objects and their relationships What is Prolog? - 1 Prolog is an example of a logic programming language Invented by Alain Colmeraurer in 1972 A Prolog Tutorial Based on Clocksin and Mellish Chapter 1 The version implemented at the University

More information

What is Prolog? - 1. A Prolog Tutorial. Prolog Programming. What is Prolog? - 2. » Declaring some facts about objects and their relationships

What is Prolog? - 1. A Prolog Tutorial. Prolog Programming. What is Prolog? - 2. » Declaring some facts about objects and their relationships What is Prolog? - 1 Prolog is an example of a logic programming language A Prolog Tutorial Based on Clocksin and Mellish Chapter 1 Invented by Alain Colmeraurer in 1972 The version implemented at the University

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

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

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

An introduction to logic programming with Prolog

An introduction to logic programming with Prolog An introduction to logic programming with Prolog Dr. Constantinos Constantinides Department of Computer Science and Software Engineering Concordia University A running example: A family genealogy tree

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

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

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

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

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

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

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

Expr Language Reference

Expr Language Reference Expr Language Reference Expr language defines expressions, which are evaluated in the context of an item in some structure. This article describes the syntax of the language and the rules that govern the

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

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

XQ: An XML Query Language Language Reference Manual

XQ: An XML Query Language Language Reference Manual XQ: An XML Query Language Language Reference Manual Kin Ng kn2006@columbia.edu 1. Introduction XQ is a query language for XML documents. This language enables programmers to express queries in a few simple

More information

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

Operators (2A) Young Won Lim 10/5/13 Operators (2A) Copyright (c) 2013 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version

More information

CA4003 Compiler Construction Assignment Language Definition

CA4003 Compiler Construction Assignment Language Definition CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g.

More information

CHIL CSS HTML Integrated Language

CHIL CSS HTML Integrated Language CHIL CSS HTML Integrated Language Programming Languages and Translators Fall 2013 Authors: Gil Chen Zion gc2466 Ami Kumar ak3284 Annania Melaku amm2324 Isaac White iaw2105 Professor: Prof. Stephen A. Edwards

More information

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

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

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

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

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

Language Reference Manual

Language Reference Manual TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall

More information

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; } Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas

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

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

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

Exercise: Inventing Language

Exercise: Inventing Language Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM) Exercise: Inventing Language Get a separate

More information

Prolog Introduction. Gunnar Gotshalks PI-1

Prolog Introduction. Gunnar Gotshalks PI-1 Prolog Introduction PI-1 Physical Symbol System Hypothesis A physical symbol system has the necessary and sufficient means for general intelligent action. Allen Newell and Herbert A. Simon PI-2 Physical

More information

Introduction to Prolog

Introduction to Prolog Introduction to Prolog York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 03_Prolog 1 Overview Introduction & Preliminaries Syntax Characters Constants

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

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

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Example problems. Combinatorial auction. Towers of Hanoi Rectangle packing Shortest route. 8 queens Soduko Maximizing (minimizing) costs

Example problems. Combinatorial auction. Towers of Hanoi Rectangle packing Shortest route. 8 queens Soduko Maximizing (minimizing) costs FunLog Example problems Combinatorial auction sell all the items Towers of Hanoi Rectangle packing Shortest route. 8 queens Soduko Maximizing (minimizing) costs Finding a solution with given property The

More information

Declarative Programming

Declarative Programming Declarative Programming Announcements Declarative Languages Database Management Systems Database management systems (DBMS) are important, heavily used, and interesting! A table is a collection of records,

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

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

What are Operators? - 1. Operators. What are Operators? - 2. Properties. » Position» Precedence class» associativity. » x + y * z. » +(x, *(y, z)).

What are Operators? - 1. Operators. What are Operators? - 2. Properties. » Position» Precedence class» associativity. » x + y * z. » +(x, *(y, z)). What are Operators? - 1 Functors Introduce operators to improve the readability of programs Operators syntactic sugar Based on Clocksin & Mellish Sections 2.3, 5.5 O-1 O-2 The arithmetic expression:» x

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 1999 P. N. Hilfinger CS 164: Final Examination Name: Login: Please do not discuss

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

2.2 Syntax Definition

2.2 Syntax Definition 42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

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

More Assigned Reading and Exercises on Syntax (for Exam 2)

More Assigned Reading and Exercises on Syntax (for Exam 2) More Assigned Reading and Exercises on Syntax (for Exam 2) 1. Read sections 2.3 (Lexical Syntax) and 2.4 (Context-Free Grammars) on pp. 33 41 of Sethi. 2. Read section 2.6 (Variants of Grammars) on pp.

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

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

Outcome-Oriented Programming (5/12/2004)

Outcome-Oriented Programming (5/12/2004) 1 Outcome-Oriented Programming (5/12/2004) Daniel P. Friedman, William E. Byrd, David W. Mack Computer Science Department, Indiana University Bloomington, IN 47405, USA Oleg Kiselyov Fleet Numerical Meteorology

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104) Learning Language Reference Manual 1 George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104) A. Introduction Learning Language is a programming language designed

More information

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors. 1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

More information

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3)

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3) Declarative Computation Model Single assignment store (VRH 2.2) Kernel language syntax (VRH 2.3) Carlos Varela RPI October 6, 2009 Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL On Academic

More information

COP4020 Programming Assignment 1 - Spring 2011

COP4020 Programming Assignment 1 - Spring 2011 COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to

More information

Modelica Change Proposal MCP-0019 Flattening (In Development) Proposed Changes to the Modelica Language Specification Version 3.

Modelica Change Proposal MCP-0019 Flattening (In Development) Proposed Changes to the Modelica Language Specification Version 3. Modelica Change Proposal MCP-0019 Flattening (In Development) Proposed Changes to the Modelica Language Specification Version 3.3 Revision 1 Table of Contents Preface 3 Chapter 1 Introduction 3 Chapter

More information

ASML Language Reference Manual

ASML Language Reference Manual ASML Language Reference Manual Tim Favorite (tuf1) & Frank Smith (fas2114) - Team SoundHammer Columbia University COMS W4115 - Programming Languages & Translators 1. Introduction The purpose of Atomic

More information

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

More information

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

More information

What needs to be kept track of ffl The current substitution ffl The current goal ffl The clause currently in use ffl Backtrack Information 2

What needs to be kept track of ffl The current substitution ffl The current goal ffl The clause currently in use ffl Backtrack Information 2 Prolog Implementation ffl The Generic Idea: Everything except unification. ffl An Introduction to the WAM: Flat unification only. 1 What needs to be kept track of ffl The current substitution ffl The current

More information

Implementação de Linguagens 2016/2017

Implementação de Linguagens 2016/2017 Implementação de Linguagens Ricardo Rocha DCC-FCUP, Universidade do Porto ricroc @ dcc.fc.up.pt Ricardo Rocha DCC-FCUP 1 Logic Programming Logic programming languages, together with functional programming

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

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2 Jim Lambers ENERGY 211 / CME 211 Autumn Quarter 2007-08 Programming Project 2 This project is due at 11:59pm on Friday, October 17. 1 Introduction In this project, you will implement functions in order

More information

Functional programming with Common Lisp

Functional programming with Common Lisp Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions

More information

Chapter 6 Fundamentals of the Logical Paradigm. Programming Languages and Paradigms J. Fenwick, B. Kurtz, C. Norris (to be published in 2012)

Chapter 6 Fundamentals of the Logical Paradigm. Programming Languages and Paradigms J. Fenwick, B. Kurtz, C. Norris (to be published in 2012) Chapter 6 Fundamentals of the Logical Paradigm Programming Languages and Paradigms J. Fenwick, B. Kurtz, C. Norris (to be published in 2012) Introduction In this second part of chapter 6 you will learn

More information

Logisimple. Language Reference Manual. October 16, Introduction 3

Logisimple. Language Reference Manual. October 16, Introduction 3 Logisimple Language Reference Manual Yuanxia Lee (yl3262): yl3262@columbia.edu Sarah Walker (scw2140): scw2140@columbia.edu Kundan Guha (kg2632): kundan.guha@columbia.edu Hannah Pierce-Hoffman (hrp2112):

More information