1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.

Slides:



Advertisements
Similar presentations
Chapter 3: Lists, Operators, Arithmetic Part 1. Outline Representation of lists Some operations in lists Operator notation Arithmetic.
Advertisements

8 Queens. Problem: Placing 8 queens on a chessboard such that they don’t attack each other Three different Prolog programs are suggessted as solutions.
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.
Chapter Three: Lists, Operators, Arithmetic 1. Chapter three: 3.1Representation of lists 3.2Some operations on lists 2.
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).
INTRODUCTION TO PROLOG. PROLOG BASICS Atoms - most primitive terms that the language manipulates start with lower case letter includes strings (‘inside.
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
SPARQL for Querying PML Data Jitin Arora. Overview SPARQL: Query Language for RDF Graphs W3C Recommendation since 15 January 2008 Outline: Basic Concepts.
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/29.
1 Predicates and quantifiers Chapter 8 Formal Specification using Z.
1 Artificial Intelligence CSC 361 Prof. Mohamed Batouche Department of Computer Science CCIS – King Saud University Riyadh, Saudi Arabia
Exam 3 Material Inequalities and Absolute Value
1. a < b means a is less than b
Formal Models of Computation Part II The Logic Model
LING 388: Language and Computers Sandiway Fong Lecture 4.
COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan.
1-1 Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical.
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.
Chapter P Prerequisites: Fundamental Concepts of Algebra 1 Copyright © 2014, 2010, 2007 Pearson Education, Inc. 1 P.9 Linear Inequalities and Absolute.
Chapter 9: Functional Programming in a Typed Language.
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
UNIVERSITI TENAGA NASIONAL CMPB454 ARTIFICIAL INTELLIGENCE (AI) CHAPTER 6 LOGIC PROGRAMMING USING PROLOG CHAPTER 6 LOGIC PROGRAMMING USING PROLOG Instructor:
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
Lists in Prolog Sections 3.1, 3.2. Lists n List = sequence of values –[1, 2, 3, 4, 5] –[bob, brian, cathy, mark, david, loretta] –[birds(4, calling),
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
ISBN Chapter 16 Logic Programming Languages.
9.3 Equations and Absolute Value Goal(s): To solve equations involving absolute value.
Artificial Intelligence CS370D
1-1 An Introduction to Logical Programming Sept
For Friday No reading Prolog Handout 2. Homework.
Prolog 3 Tests and Backtracking 1. Arithmetic Operators Operators for arithmetic and value comparisons are built-in to Prolog = always accessible / don’t.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
C H A P T E R N I N E Logic Programming Part 2 Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Functional Programming Lecture 3 - Lists Muffy Calder.
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:... :-....
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Section 16.5, 16.6 plus other references
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Prolog Concepts.
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Equations and Inequalities
Artificial Intelligence CS370D
3-6 Compound Inequalities
Artificial Intelligence CS370D
Artificial Intelligence CS370D
Order Properties of the Real Numbers
Scheme: Basic Functionality
Chapter 3: Prolog (Lists, Arithmetic, Operators)
Back to “Serious” Topics…
CSCE 314: Programming Languages Dr. Dylan Shell
Programming Techniques
Prolog Concepts.
Chapter 2: Analysis and Verification of Non-Real-Time Systems
Chapter 2: Prolog (Introduction and Basic Concepts)
Prolog Concepts.
PROLOG.
Logical Agents Prof. Dr. Widodo Budiharto 2018
Presentation transcript:

1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.

Outline: Declarative meaning of Prolog programs. Examples of conjunction. Examples of disjunction. List. Exemples of lists. List representation. List representation examples. 2

3 Declarative meaning of Prolog programs: AND operator: More than one relation can be included as the “goal” of a query. A comma (“,”) is used as an AND operator to indicate a conjunction of goals—all must be satisfied by a solution to the query. OR operator: Prolog also accepts the disjunction (OR) of goals (“ ; ”). Any one of the goals in a disjunction has to be true.

4 Example of conjunction: following facts which define “fatherOf” and “motherOf” relations. fatherOf(ahmed,salih). fatherOf(salih,ali). fatherOf(sara,ali). motherOf(ahmed,judy). motherOf(salih,maryam). motherOf(sara,maryam). The symbols fatherOf and motherOf are predicates. The symbols ahmed, salih, ali, judy, maryam and sara are atoms.

5 Example of conjunction:(cont) Questions: 1- fatherOf(sara,X),motherOf(sara,Y). X = ali, Y = maryam ; no 2- fatherOf(ahmed,X),fatherOf(X,ali). X = salih ; no

6 Example of disjunction: 1) happy1(X) :- rich(X) ; famous(X). 2) happy2(X) :- attractive(X), ( rich(X) ; famous(X) ). 3) A:- (B, C); (D, E, F).

7 List: A list is written as a sequence of values, known as list elements, separated by commas and enclosed in square brackets. e.g. [dog,cat,fish]. A list element does not have to be an atom. It can be any Prolog term, including variable or another list. e.g:[X,Y,[dog,cat,fish],elephant]. A list element that is itself a list is known as a sublist like [dog,cat,fish].

8 (cont.) List: Lists can have any number of elements, including zero. The list with no elements is known as the empty list and is written as []. For non-empty lists, the first element is known as the head. The list remaining after the first element is removed is called the tail. The notation [H|T] represents a list with H matching the head of the list and T matching the rest of the list. The head can be any Prolog object and The tail has to be list. For example: the head of the list [dog,cat,fish] is the atom dog and the tail is the list [cat,fish].

Exemples of lists: 9

List representation: The head and the tail can be combined into a structure by a special functor ‘. ’.(Head,Tail) The tail is a list, it is either empty or it has its own head and tail. The previous list can be represented as the term:.(dog,.(cat,.(fish,.(elephant, [])))) 10

List representation:(cont) The element of a list can be object of any kind; it can be also list e.g L= [a,b,c] can be written as: Tail=[b,c] and then L=.(a, Tail) To express it in the square bracket notation we can use vertical bar that separate the head and tail: L=[a|Tail] Alternative ways of writing the list L are: [a,b,c]=[a|[b,c]]=[a,b|[c]]=[a,b,c|[]] 11

List representation examples: ?- L1=[1,2,3],L2=.(1,[2,3]). L1= [1,2,3] L2=[1,2,3] ?- Cities1=.(london,.(tokyo,[])), Cities2=[paris,madrid], L=[ann,cities1,tom,cities2]. Cities1=[london,tokyo] Cities2=[paris,madrid] L=[ann,[london,tokyo],tom,[paris,madrid]] 12

List representation examples: Given the fact p([1,2,3,4]). ?- p([X|Y]). Answer: X = 1, Y = [2,3,4] ?- p([_,_,X|Y]). Answer: X = 3, Y = [4] ?- Tail=[c,d,e], L=[a|Tail]. Answer: Tail = [c, d, e], L = [a, c, d, e] 13