Lecture 9: A closer look at terms
|
|
- Elmer Richardson
- 5 years ago
- Views:
Transcription
1 Lecture 9: A closer look at terms Theory Introduce the == predicate Take a closer look at term structure Introduce strings in Prolog Introduce operators Exercises Exercises of LPN: 9.1, 9.2, 9.3, 9.4, 9.5 Practical session
2 Comparing terms: ==/2 Prolog contains an important predicate for comparing terms This is the identity predicate ==/2 The identity predicate ==/2 does not instantiate variables, that is, it behaves differently from =/2
3 Comparing terms: ==/2 Prolog contains an important predicate for comparing terms This is the identity predicate ==/2 The identity predicate ==/2 does not instantiate variables, that is, it behaves differently from =/2?- a==a.?- a==b. no?- a=='a'.?- a==x. X = _443 no
4 Comparing variables Two different uninstantiated variables are not identical terms Variables instantiated with a term T are identical to T
5 Comparing variables Two different uninstantiated variables are not identical terms Variables instantiated with a term T are identical to T?- X==X. X = _443?- Y==X. Y = _442 X = _443 no?- a=u, a==u. U = _443
6 Comparing terms: \==/2 The predicate \==/2 is defined so that it succeeds in precisely those cases where ==/2 fails In other words, it succeeds whenever two terms are not identical, and fails otherwise
7 Comparing terms: \==/2 The predicate \==/2 is defined so that it succeeds in precisely those cases where ==/2 fails In other words, it succeeds whenever two terms are not identical, and fails otherwise?- a \== a. no?- a \== b.?- a \== 'a'. no?- a \== X. X = _443
8 Terms with a special notation Sometimes terms look different, but Prolog regards them as identical For example: a and 'a', but there are many other cases Why does Prolog do this? Because it makes programming more pleasant More natural way of coding Prolog programs
9 Arithmetic terms Recall lecture 5 where we introduced arithmetic +, -, <, >, etc are functors and expressions such as 2+3 are actually ordinary complex terms The term 2+3 is identical to the term +(2,3)
10 Arithmetic terms Recall lecture 5 where we introduced arithmetic +, -, <, >, etc are functors and expressions such as 2+3 are actually ordinary complex terms The term 2+3 is identical to the term +(2,3)?- 2+3 == +(2,3).?- -(2,3) == 2-3.?- (4<2) == <(4,2).
11 Summary of comparison predicates = \= == \== =:= =\= Unification predicate Negation of unification predicate Identity predicate Negation of identity predicate Arithmetic equality predicate Negation of arithmetic equality predicate
12 Lists as terms Another example of Prolog working with one internal representation, while showing another to the user Using the constructor, there are many ways of writing the same list?- [a,b,c,d] == [a [b,c,d]].?- [a,b,c,d] == [a,b,c [d]].?- [a,b,c,d] == [a,b,c,d []].?- [a,b,c,d] == [a,b [c,d]].
13 Prolog lists internally Internally, lists are built out of two special terms: [] (which represents the empty list). (a functor of arity 2 used to build non-empty lists) These two terms are also called list constructors A recursive definition shows how they construct lists
14 Definition of prolog list The empty list is the term []. It has length 0. A non-empty list is any term of the form.(term,list), where term is any Prolog term, and list is any Prolog list. If list has length n, then.(term,list) has length n+1.
15 A few examples?-.(a,[]) == [a].?-.(f(d,e),[]) == [f(d,e)].?-.(a,.(b,[])) == [a,b].?-.(a,.(b,.(f(d,e),[]))) == [a,b,f(d,e)].
16 Internal list representation Works similar to the notation: It represents a list in two parts Its first element, the head the rest of the list, the tail The trick is to read these terms as trees Internal nodes are labeled with. All nodes have two daughter nodes Subtree under left daughter is the head Subtree under right daughter is the tail
17 Example of a list as tree Example: [a,[b,c],d]. a... b. d [] c []
18 Examining terms We will now look at built-in predicates that let us examine Prolog terms more closely Predicates that determine the type of terms Predicates that tell us something about the internal structure of terms
19 Type of terms Terms Simple Terms Complex Terms Constants Variables Atoms Numbers
20 Checking the type of a term atom/1 integer/1 float/1 number/1 atomic/1 var/1 nonvar/1 Is the argument an atom? an interger? a floating point number? an integer or float? a constant? an uninstantiated variable? an instantiated variable or another term that is not an uninstantiated variable
21 Type checking: atom/1?- atom(a).?- atom(7). no?- atom(x). no
22 Type checking: atom/1?- X=a, atom(x). X = a?- atom(x), X=a. no
23 Type checking: atomic/1?- atomic(mia).?- atomic(5).?- atomic(loves(vincent,mia)). no
24 Type checking: var/1?- var(mia). no?- var(x).?- X=5, var(x). no
25 Type checking: nonvar/1?- nonvar(x). no?- nonvar(mia).?- nonvar(23).
26 The structure of terms Given a complex term of unknown structure, what kind of information might we want to extract from it? Obviously: The functor The arity The argument Prolog provides built-in predicates to produce this information
27 The functor/3 predicate The functor/3 predicate gives the functor and arity of a complex predicate
28 The functor/3 predicate The functor/3 predicate gives the functor and arity of a complex predicate?- functor(friends(lou,andy),f,a). F = friends A = 2
29 The functor/3 predicate The functor/3 predicate gives the functor and arity of a complex predicate?- functor(friends(lou,andy),f,a). F = friends A = 2?- functor([lou,andy,vicky],f,a). F =. A = 2
30 functor/3 and constants What happens when we use functor/3 with constants?
31 functor/3 and constants What happens when we use functor/3 with constants??- functor(mia,f,a). F = mia A = 0
32 functor/3 and constants What happens when we use functor/3 with constants??- functor(mia,f,a). F = mia A = 0?- functor(14,f,a). F = 14 A = 0
33 functor/3 for constructing terms You can also use functor/3 to construct terms:?- functor(term,friends,2). Term = friends(_,_)
34 Checking for complex terms complexterm(x):- nonvar(x), functor(x,_,a), A > 0.
35 Arguments: arg/3 Prolog also provides us with the predicate arg/3 This predicate tells us about the arguments of complex terms It takes three arguments: A number N A complex term T The Nth argument of T
36 Arguments: arg/3 Prolog also provides us with the predicate arg/3 This predicate tells us about the arguments of complex terms It takes three arguments: A number N A complex term T The Nth argument of T?- arg(2,likes(lou,andy),a). A = andy
37 Strings Strings are represented in Prolog by a list of character codes Prolog offers double quotes for an easy notation for strings?- S = Vicky. S = [86,105,99,107,121]
38 Working with strings There are several standard predicates for working with strings A particular useful one is atom_codes/2?- atom_codes(vicky,s). S = [118,105,99,107,121]
39 Operators As we have seen, in certain cases, Prolog allows us to use operator notations that are more user friendly Recall, for instance, the arithmetic expressions such as 2+2 which internally means +(2,2) Prolog also has a mechanism to add your own operators
40 Properties of operators Infix operators Functors written between their arguments Examples: + - = ==, ;. --> Prefix operators Functors written before their argument Example: - (to represent negative numbers) Postfix operators Functors written after their argument Example: ++ in the C programming language
41 Precedence Every operator has a certain precedence to work out ambiguous expressions For instance, does 2+3*3 mean 2+(3*3), or (2+3)*3? Because the precedence of + is greater than that of *, Prolog chooses + to be the main functor of 2+3*3
42 Associativity Prolog uses associativity to disambiguate operators with the same precedence value Example: Does this mean (2+3)+4 or 2+(3+4)? Left associative Right associative Operators can also be defined as nonassociative, in which case you are forced to use bracketing in ambiguous cases Examples in Prolog: :- -->
43 Defining operators Prolog lets you define your own operators Operator definitions look like this: :- op(precedence, Type, Name). Precedence: number between 0 and 1200 Type: the type of operator
44 Types of operators in Prolog yfx xfy xfx fx fy xf yf left-associative, infix right-associative, infix non-associative, infix non-associative, prefix right-associative, prefix non-associative, postfix left-associative, postfix
45 Operators in SWI Prolog
46 Next lecture Cuts and negation How to control Prolog`s backtracking behaviour with the help of the cut predicate Explain how the cut can be packaged into a more structured form, namely negation as failure
Lecture 9. Exercises. Theory. Solutions to exercises LPN 8.1 & 8.2. Patrick Blackburn, Johan Bos & Kristina Striegnitz
Lecture 9 Exercises Solutions to exercises LPN 8.1 & 8.2 Theory Solution to Exercise 8.1 Suppose we add the noun ``men'' (which is plural) and the verb ``shoot''. Then we would want a DCG which says that
More informationWhat 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 informationOperators (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 informationWan 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 informationOperators (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 informationCombining Lists & Built-in Predicates
Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 6 11/10/04 11/10/04 AIPP Lecture 6: Built-in Predicates 1 Collecting Results Last time we
More informationWan 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 informationMore Planning and Prolog Operators
More Planning and Prolog Operators Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 16 22/11/04 22/11/04 AIPP Lecture 16: More Planning and Operators 1 Planning continued Contents
More informationDefining Binary & Unary Operators
Defining Binary & Unary Operators DO-1 English-French Dictionary Can use compound terms to represent a dictionary > list is a structure that contains an entry followed by the rest of the list > For example
More informationThe object level in Prolog. Meta-level predicates and operators. Contents. The flow of computation. The meta level in Prolog
Lecture 8 Meta-level predicates and operators Contents Object level vs. meta level Controlling flow of computation Checking and dismantling expressions Comparison operators The object level in Prolog Prolog
More informationLogic Programming (PLP 11) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing
Logic Programming (PLP 11) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing Carlos Varela Rennselaer Polytechnic Institute February 9, 2015 C. Varela 1 Arithmetic Goals N>M N
More informationDefining! Binary & Unary! Operators!
Defining! Binary & Unary! Operators! DO-1 English-French Dictionary! Can use compound terms to represent a dictionary! > list is a structure that contains an entry followed by the rest of the list! > For
More informationDefining Binary & Unary Operators DO-1
Defining Binary & Unary Operators DO-1 English-French Dictionary 1 Can use compound terms to represent a dictionary» list is a structure that contains an entry followed by the rest of the list» For example
More informationWhat s the problem? fib(1,1). fib(2,1). fib(n,x) :- N>2, N1 is N-1, N2 is N-2, fib(n1,x2), fib(n2,x2).
39 What s the problem? A Fibonacci Implementation fib(1,1). fib(2,1). fib(n,x) :- N>2, N1 is N-1, N2 is N-2, fib(n1,x2), fib(n2,x2). List Concatenation conc([],l,l). conc([x L1], L2, [X L3]) :- conc(l1,l2,l3).
More informationLogic Programming (PLP 11.3) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing
Logic Programming (PLP 11.3) Prolog: Arithmetic, Equalities, Operators, I/O, Natural Language Parsing Carlos Varela Rennselaer Polytechnic Institute February 3, 2011 C. Varela 1 Arithmetic Goals N>M N
More informationTopic 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 informationChapter 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 informationProlog (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 informationINTRODUCTION 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 informationPROLOG. 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 informationSome Applications of Stack. Spring Semester 2007 Programming and Data Structure 1
Some Applications of Stack Spring Semester 2007 Programming and Data Structure 1 Arithmetic Expressions Polish Notation Spring Semester 2007 Programming and Data Structure 2 What is Polish Notation? Conventionally,
More informationRecursion, 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 informationResearch 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 informationOverview. Declarative Languages. operation of del. Deleting an element from a list. functions using del. inserting elements with del
Overview Declarative Languages D7012E: Arithmetic and Backtracking Fredrik Bengtsson Some standard functions Operators Arithmetic The eight queens problem Controlling backtracking cut Deleting an element
More informationInput & Output. York University Department of Computer Science and Engineering. York University- CSE V. Movahedi 08_IO
Input & Output York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 08_IO 1 Read and write terms Overview Read and write characters Reading English sentences
More informationLogic Programming Prolog: Arithmetic, Equalities, Operators, I/O. (PLP 11) Databases: assert, retract. (CTM 9.6)
Logic Programming Prolog: Arithmetic, Equalities, Operators, I/O. (PLP 11) Databases: assert, retract. (CTM 9.6) Carlos Varela Rennselaer Polytechnic Institute November 24, 2015 C. Varela 1 Arithmetic
More informationInformation technology Programming languages Prolog Part 1: General core
INTERNATIONAL STANDARD ISO/IEC 13211-1:1995 TECHNICAL CORRIGENDUM 3 Published 2017-07 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE
More informationChapter 6. Predefined Predicates
Advanced Logic Programming https://sewiki.iai.uni-bonn.de/teaching/lectures/alp/2017/ Chapter 6. Predefined Predicates Updated: 12 June, 2017 Reorganized entire chapter Input and output Exception handling
More informationProgramming Languages
Programming Languages Jörg Kreiker Chair for Theoretical Computer Science Prof. Esparza TU München winter term 2010/2011 Lecture 13 Databases 3 Organizational Issues assignments corrected today: final
More information[a,b,c,d] 15/9/2013. [a,b,c,d] List. List. List. List is one of the most important Prolog data structures.
is one of the most important Prolog data structures. A list is an ordered sequence of zero or more terms written between square brackets and separated by commas. [a,b,c,d] September 1 st Session 2013/2014
More informationLecture 19: Functions, Types and Data Structures in Haskell
The University of North Carolina at Chapel Hill Spring 2002 Lecture 19: Functions, Types and Data Structures in Haskell Feb 25 1 Functions Functions are the most important kind of value in functional programming
More informationAn introduction to Prolog. P. Cabalar ( Department Prolog of Computer Science University of Corunna, FebruarySPAIN 8, 2016)
An introduction to Prolog Pedro Cabalar Department of Computer Science University of Corunna, SPAIN February 8, 2016 P. Cabalar ( Department Prolog of Computer Science University of Corunna, FebruarySPAIN
More informationLecture 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 informationLogic 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 informationLECTURE 17. Expressions and Assignment
LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)
More informationExercises 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 informationData Structures and Computation
Chapter 3 Data Structures and Computation 3.1. ARITHMETIC Here are some examples of how to do arithmetic in Prolog:.?- Y is 2+2. 4?- ~is 3+3. ~ Z 6~3571428 ~ ~ + (3.9 / 2.1). The 1~iii t4i predicate is
More informationDerived 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 informationTHE DESIGN AND IMPLEMENTATION OF A PROLOG PARSER USING JAVACC Pankaj Gupta, B.S. Thesis Prepared for the Degree of MASTER OF SCIENCE
THE DESIGN AND IMPLEMENTATION OF A PROLOG PARSER USING JAVACC Pankaj Gupta, B.S. Thesis Prepared for the Degree of MASTER OF SCIENCE UNIVERSITY OF NORTH TEXAS August 2002 APPROVED: Paul Tarau, Major Professor
More informationARM Evaluation System
reference manual ARM Evaluation System Acorn OEM Products PROLOG Part No 0448,012 Issue No 1.0 14 August 1986 @ Copyright Acorn Computers Limited 1986 Neither the whole nor any part of the information
More information3 Lists. List Operations (I)
3 Lists. List Operations (I) The list is the simplest yet the most useful Prolog structure. A list is a sequence of any number of objects. Example 3.1: L = [1, 2, 3], R = [a, b, c], T = [john, marry, tim,
More informationManipulating atomics and clauses
Manipulating atomics and clauses This lecture revisits recursion, showing how to read input. Then it introduces type testing predicates, atomic term processing term creation and decomposition and clause
More informationSnakes. Declarative Languages. Relation different. Overview. Negation as failure. Relation different
Snakes Declarative Languages D7012E: Negation and solution gathering Fredrik Bengtsson "Mary like all animals but snakes" likes(mary, X):-snake(X),!,fail. likes(mary, X):-animal(X). observe the cut before
More informationTests, Backtracking, and Recursion
Tests, Backtracking, and Recursion Artificial Intelligence Programming in Prolog Lecture 3 30/09/04 30/09/04 AIPP Lecture 3: Rules, Results, and Backtracking 1 Re-cap A Prolog program consists of predicate
More informationCS 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 informationPage 1 of 5. University of Toronto CSC326 Programming Languages, Fall 2009
University of Toronto CSC326 Programming Languages, Fall 2009 Assignment # 4 Part B (Due: Monday, Dec. 7rd 2009, 11:00am sharp) Details: - Programming in Prolog. This is the Part B of assignment 4, and
More informationScheme 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 informationDifference lists in Prolog
tmcs-csenki 2010/4/12 23:38 page 73 #1 8/1 (2010), 73 87 Difference lists in Prolog Attila Csenki Abstract. Prolog is taught at Bradford University within the two-semester module Symbolic and Declarative
More informationCOMP 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 informationFormal Languages and Automata Theory, SS Project (due Week 14)
Formal Languages and Automata Theory, SS 2018. Project (due Week 14) 1 Preliminaries The objective is to implement an algorithm for the evaluation of an arithmetic expression. As input, we have a string
More informationComputational Logic Introduction to Logic Programming
Computational Logic Introduction to Logic Programming 1 Overview 1. Syntax: data 2. Manipulating data: Unification 3. Syntax: code 4. Semantics: meaning of programs 5. Executing logic programs 2 Syntax:
More informationThis 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 informationProlog Assessed Exercise
Prolog Assessed Exercise David Eyers 21st April 2009 The purpose of this exercise is to implement in Prolog the Bellman-Ford algorithm for computing singlesource shortest paths
More informationSyntax: Terms Arity: is the number of arguments of a structure. Constructors are represented
Computational Logic Introduction to Logic Programming 1 Overview 1. Syntax: data 2. Manipulating data: Unification 3. Syntax: code 4. Semantics: meaning of programs 5. Executing logic programs 2 Syntax:
More informationUNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING
UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING Friday 20 th December 2013 14:30 to 16:30 INSTRUCTIONS TO CANDIDATES 1.
More informationCS 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 informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 6: EVALUATION of EXPRESSIONS 2018-2019 Fall Evaluation of Expressions Compilers use stacks for the arithmetic and logical expressions. Example: x=a/b-c+d*e-a*c If a=4, b=c=2,
More informationCSC324 Logic & Relational Programming Illustrated in Prolog
CSC324 Logic & Relational Programming Illustrated in Prolog Afsaneh Fazly 1 Winter 2013 1 with many thanks to Anya Tafliovich, Gerald Penn and Sheila McIlraith. 1 2 admin notes Please check your marks
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 6: EVALUATION of EXPRESSIONS 2017 Fall Evaluation of Expressions Compilers use stacks for the arithmetic and logical expressions. Example: x=a/b-c+d*e-a*c If a=4, b=c=2,
More informationProlog. 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 informationCOP4020 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 informationProgramming Paradigms
PP 2017/18 Unit 9 Prolog: Accumulators, Order of Goals/Clauses, and the Cut 1/38 Programming Paradigms Unit 9 Prolog: Accumulators, Order of Goals/Clauses, and the Cut J. Gamper Free University of Bozen-Bolzano
More informationLogic Programming. Efficiency Issues. Temur Kutsia
Logic Programming Efficiency Issues Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria kutsia@risc.uni-linz.ac.at Efficiency Issues in Prolog Narrow the
More informationProgramming Paradigms
PP 2017/18 Unit 11 Functional Programming with Haskell 1/37 Programming Paradigms Unit 11 Functional Programming with Haskell J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE
More informationIntroduction to Prolog by
to Prolog by a talk given to The Linux Supporters Group Adelaide July 2009 Slide 1 Choice Points in Prolog Slide 2 Prolog s run-time stack does not function as procedural language stacks do. It isn t even
More informationSOFTWARE ENGINEERING DESIGN I
2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique
More informationPROgramming 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 information10. Logic Programming With Prolog
Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000 10. Logic Programming With Overview Logic Programming Logic Programming Logic programming is a form of declarative programming A
More informationProlog-2 nd Lecture. Prolog Predicate - Box Model
Prolog-2 nd Lecture Tracing in Prolog Procedural interpretation of execution Box model of Prolog predicate rule How to follow a Prolog trace? Trees in Prolog use nested terms Unification Informally Formal
More informationProlog. 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 informationIntroduction 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 informationLecture 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 informationReviews. Arithmetic Operators (2)
Introduction to Prolog Useful references: Clocksin, W.F. and Mellish, C.S., Programming in Prolog: Using the ISO Standard (5th edition), 2003. Bratko, I., Prolog Programming for Artificial Intelligence
More informationProlog 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 informationSTACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:
STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The
More informationProblem Solving and Search
Problem Solving and Search Ulle Endriss Institute for Logic, Language and Computation University of Amsterdam [ http://www.illc.uva.nl/~ulle/teaching/pss/ ] Ulle Endriss 1 Table of Contents Lecture 1:
More informationHaskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.
Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
More informationProlog. the structure Ref: Learn Prolog Now! On line Prolog Documentation. Blackburn, Bos, Striegnitz.
Prolog the structure Ref: Learn Prolog Now! On line Prolog Documentation. Blackburn, Bos, Striegnitz. Prolog Summary (1 page) Prolog programs consist of Facts Rules Queries a rule with no right hand side
More informationThe 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 informationOperators in java Operator operands.
Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,
More informationWan 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 informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Final Review Part I Dr. Hyunyoung Lee 1 Programming Language Characteristics Different approaches to describe computations, to instruct computing devices E.g., Imperative,
More informationRecursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions
Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin
More informationCS 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 informationChapter 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 informationLogic Programming. April 3, 2017
Logic Programming April 3, 2017 Using Definite Clause Grammars DCG: Definite Clause Grammar is a formal language used to define other languages. Based on Horn clauses. Example: program --> rule; fact.
More informationPROGRAMMING IN HASKELL. Chapter 2 - First Steps
PROGRAMMING IN HASKELL Chapter 2 - First Steps 0 The Hugs System Hugs is an implementation of Haskell 98, and is the most widely used Haskell system; The interactive nature of Hugs makes it well suited
More informationImplementaçã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 informationIntroduction to Scheme
How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free
More informationLING/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 informationData Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1
Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Infix to Postfix Example 1: Infix to Postfix Example 2: Postfix Evaluation
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 08: Type Classes o o Review: What is a type class? Basic Type Classes: Eq, Ord, Enum, Integral,
More informationIT 4043 Data Structures and Algorithms. Budditha Hettige Department of Computer Science
IT 4043 Data Structures and Algorithms Budditha Hettige Department of Computer Science 1 Syllabus Introduction to DSA Abstract Data Types List Operation Using Arrays Stacks Queues Recursion Link List Sorting
More informationMap coloring example
Map coloring example A B C D E F Database for map coloring coloring(a,b,c,d,e,f) :- different(a,b), different(a,c), different(a,d), different(a,f), different(b,c), different(b,e), different(c,d), different(c,e),
More informationInformation technology Programming languages Prolog Part 1: General core
INTERNATIONAL STANDARD ISO/IEC 13211-1:1995 TECHNICAL CORRIGENDUM 2 Published 2012-02-15 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE
More informationHints: I used a left fold and wrote a named helper function when I created my solution.
1) [4 marks] On a particular system, a password is considered acceptable if it meets the following constraints: It is at least 8 characters in length It contains at least one uppercase letter ('A' to 'Z')
More information15 Unification and Embedded Languages in Lisp
15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed
More informationFundamentals of Programming CS-110. Lecture 3
Fundamentals of Programming CS-110 Lecture 3 Operators Operators Operators are words or symbols that cause a program to do something to variables. OPERATOR TYPES: Type Operators Usage Arithmetic + - *
More informationAssignment 1. University of Toronto, CSC384 - Introduction to Artificial Intelligence, Winter
Assignment 1. University of Toronto, CSC384 - Introduction to Artificial Intelligence, Winter 2014 1 Computer Science 384 January 26, 2014 St. George Campus University of Toronto Homework Assignment #1
More informationConcepts 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