Chapter Two: Syntax and Meaning of Prolog Programs

Slides:



Advertisements
Similar presentations
© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Advertisements

Lexical Analysis Consider the program: #include main() { double value = 0.95; printf("value = %f\n", value); } How is this translated into meaningful machine.
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Prolog.1 Prolog. Prolog.2 Textbook and Software  Title PROLOG programming for artificial intelligence  Author Ivan Bratko  Get the software – windows.
1 Part 1 The Prolog Language Chapter 2 Syntax and Meaning of Prolog programs.
Prolog.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
1 Logic Programming. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
2. Syntax and Meaning. Contents Data Objects Matching Declarative meaning of Prolog Procedural meaning Example: monkey and banana Order of clauses and.
1 COMP313A Programming Languages Logic Programming (3)
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
4. PROLOG Data Objects And PROLOG Arithmetic
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Syntax and Meaning of Prolog Programs Notes for Ch.2 of Bratko For CSCE 580.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
1 Artificial Intelligence CSC 361 Prof. Mohamed Batouche Department of Computer Science CCIS – King Saud University Riyadh, Saudi Arabia
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 13 Slides Courtesy to: Peter LO.
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
Introduction to Prolog Terms & Matching Math. Atoms and Terms n mark, alex, di, bob are atoms –Not variables –Not strings –Just things – simple things.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
Logic Programming Dr. Yasser Ahmed Nada Fall 2010/2011 Lecture 2 1 Logic Programming.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
CS Jan 2007 Chapter 2 sections 1, 2, 4 – 6, 8,
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Artificial Intelligence CS370D
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
For Friday No reading Prolog Handout 2. Homework.
Chapter 2 Syntax and meaning of prolog programs Part 1.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Chapter Three: Operators, Arithmetic 1. Chapter three: 3.3Operator notation 3.4Arithmetic 2.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
Constants, Data Types and Variables
علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !
Unit 2 Technology Systems
A Conjunction is a logical operator that connects two logical terms.
BASIC ELEMENTS OF A COMPUTER PROGRAM
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Variables and Primative Types
PROLOG.
Prolog programming Introduction to Prolog (part2)
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Introduction to the C Language
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Artificial Intelligence CS370D
Prolog syntax + Unification
Prolog programming Introduction to Prolog (part3)
Chapter 3: Prolog (Lists, Arithmetic, Operators)
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Chapter # 2 Part 2 Programs And data
Chapter 2: Introduction to C++.
Chapter 2 Syntax and meaning of prolog programs
C# Revision Cards Data types
Clauses and Predicates
DATA TYPES AND OPERATIONS
Chapter 2: Prolog (Introduction and Basic Concepts)
PROLOG.
Constants, Variables and Data Types
Presentation transcript:

Chapter Two: Syntax and Meaning of Prolog Programs

Chapter two: 2.1 Data objects data objects simple objects constants atoms numbers variable structures

2.1 Data objects 2.1.1 Constants: atoms String of letters, digits and the underscore character ‘_’ starting with a lower- case letter e.g. anna x25 x_34a x___y3 miss_Jones String of special characters e.g. <----> ===> … ::= note: when using atoms of this form, be careful because some of strings already have a predefined meaning e.g. ‘:-‘ String of characters enclosed in single quotes e.g. ‘Tom’ ‘tom’ ‘SarahJones’ data objects simple objects constants atoms numbers variable structures

The lexical scope of atom names is the whole program. This means that for example if the atom bob appeared in two clauses , then it always represents the same object in both clauses

2.1 Data objects 2.1.1 Constants: numbers Integer numbers simple objects constants atoms numbers variable structures 2.1.1 Constants: numbers Integer numbers e.g. 1 133 0 -97 Real numbers e.g. 3.14 -0.0035 100.2

2.1 Data objects 2.1.2 Variables Variables are strings of letters, digits and underscores characters, starting with upper-case letter or an underscore. e.g. X , Result , Object2 , _23 Shopping_list _  (“the underscore” is the anonymous variable) data objects simple objects constants atoms numbers variable structures

But each occurrence of X in the same clause means the same variable. The lexical scope of variable names is one clause except the anonymous variable. This means that for example if the variable X appeared in two clauses then it signifies two different variables . eg: offspring (X , Y) :- parent (Y , X) mother (X , Y) :- parent (X , Y) , female (X) But each occurrence of X in the same clause means the same variable. X in the first clause is different from X in the second one Each X in this clause has the same value

somebody_has_child:-parent(_,_). somebody_has_child:-parent(X,Y). The anonymous variable signifies new variable each time it occurs even in the same clause. somebody_has_child:-parent(_,_). somebody_has_child:-parent(X,Y). somebody_has_child:-parent(X,X). If the anonymous variable appears in a query then its value will not be output when Prolog answers the query. eg: if we are interested in people who have children but not in the names of the children, then we can ask ?- parent (X , _)

2.1 Data objects 2.1.3 Structures Structures are objects that have several components which can be structures themselves. e.g. date (1, may, 2001) to represent any day in may; day is variable date (Day, may, 2001) All structures can be pictured as tree. Each functor is defined by name and arity (#of arguments) data objects simple objects constants atoms numbers variable structures functor arguments (all are constants) date may 1 2001

2.1 Data objects 2.1.3 Structures Example: how structures can be used to represent the following geometric objects ? A point in 2 dimensional space A line segment A triangle Draw the tree structures that correspond to them.

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) m point (7,1))

Represent the following equation as a structure and draw the tree structure that corresponds to : (a + b) * (c - 5) * ( + (a , b) , - (c , 5))