Artificial Intelligence CS370D

Slides:



Advertisements
Similar presentations
COMPILER CONSTRUCTION WEEK-2: LANGUAGE DESCRIPTION- SYNTACTIC STRUCTURE:
Advertisements

Prolog Programming (Volume 2) Dr W.F. Clocksin. Lists Lists are the same as other languages (such as ML) in that a list of terms of any length is composed.
Prolog.1 Prolog. Prolog.2 Textbook and Software  Title PROLOG programming for artificial intelligence  Author Ivan Bratko  Get the software – windows.
SLD-resolution Introduction Most general unifiers SLD-resolution
Notes for CS3310 Artificial Intelligence Part 5: Prolog arithmetic and lists Prof. Neil C. Rowe Naval Postgraduate School Version of July 2009.
1 Part 1 The Prolog Language Chapter 2 Syntax and Meaning of Prolog programs.
Prolog.
AR for Horn clause logic Introducing: Unification.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
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.
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
4. PROLOG Data Objects And PROLOG Arithmetic
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.
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.
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 13 Slides Courtesy to: Peter LO.
Formal Models of Computation Part II The Logic Model
Introduction to Prolog Terms & Matching Math. Atoms and Terms n mark, alex, di, bob are atoms –Not variables –Not strings –Just things – simple things.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
F28PL1 Programming Languages Lecture 16: Prolog 1.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 21.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
Artificial Intelligence CS370D
Prolog 3 Tests and Backtracking 1. Arithmetic Operators Operators for arithmetic and value comparisons are built-in to Prolog = always accessible / don’t.
Chapter 2 Syntax and meaning of prolog programs Part 1.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Matching Matching and unification. Rules for matching terms. Examples of matching. –The most general instantiation. Computation using matching.
Warm-Up 11/19 Which equation is in Standard Form? (also called general form) Convert the equations to slope-intercept form (That means solve for y) x =
Section 1.2 Functions and Graphs.
A Conjunction is a logical operator that connects two logical terms.
tautology checking continued
Simplifying Radical Expressions (10-2)
10 Quadratic Equations.
Rational Expressions and Equations
Please close your laptops
PROLOG.
Tests, Backtracking, and Recursion
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Chapter 11 :: Logic Languages
Artificial Intelligence CS370D
Antiderivatives as Areas
Artificial Intelligence CS370D
Prolog syntax + Unification
Five-Minute Check (over Lesson 2–4) Then/Now New Vocabulary
Equations and Inequalities
Prolog programming Introduction to Prolog (part3)
Artificial Intelligence Chapter 15. The Predicate Calculus
Chapter 12 :: Logic Languages
Chapter 3: Prolog (Lists, Arithmetic, Operators)
On the Geodesic Centers of Polygonal Domains
Chapter Two: Syntax and Meaning of Prolog Programs
Logics for Data and Knowledge Representation
SECTION 2-4 : SOLVING EQUATIONS WITH THE VARIABLE ON BOTH SIDES
Chapter 2 Syntax and meaning of prolog programs
Graphing a Linear Equation
Objectives The student will be able to:
6.8 Solving Equations by Factoring
Chapter 2: Prolog (Introduction and Basic Concepts)
Triangles.
Representations & Reasoning Systems (RRS) (2.2)
Chapter 12 :: Logic Languages
PROLOG.
Presentation transcript:

Artificial Intelligence CS370D Prolog programming Syntax and meaning of prolog programs

Outline: Data Objects. Lexical Scope. Structured Objects. Examples of Structured Objects. Matching. Examples of matching.

Data Objects: In Previous lab: Variables start with upper-case letters Atoms start with lower-case letters data objects variables constants structures simple objects numbers atoms

Lexical Scope: The lexical scope of variable names is one clause. If the name X occurs in two clauses, then it signifies two different variables. hasachild(X) :- parent( X, Y). isapoint(X) :- point( X, Y, Z). But each occurrence of X with in the same clause means the same variables. hasachild( X) :- parent( X, Y). The same atom always means the same object in any clause throughout the whole program.

Structured Objects: Structured objects are objects that have several components. All structured objects can be pictured as trees. The root of the tree is the functor. The offsprings of the root are the components. Components can also be variables or atoms. date( Day, September,2015) Example: date( 18, September, 2015) All data objects in Prolog are terms. date 18 September 2015 (functor, root) (arguments)

Structured Objects (cont): Each functor is defined by two things: The name, whose syntax of atoms; The arity—that is, the number of arguments. For example: point( X1, Y1) and point( X, Y, Z) are different. The Prolog system will recognize the difference by the number of arguments, and will interpret this name as two functors.

Examples of Structured Objects: The tree structure corresponding to the arithmetic expression (a + b)*(c - 5). Using the simples ‘*’,’+’ and ‘-’ as functors In fact, Prolog also allows us to use the infix notation. *(+( a, b), -( c, 5)) ?- X = *(+( a, b), -( c, 5)). ?- X is *(+( 3, 4), -( 6, 5)). + a b - c 5 * + 3 4 - 6 5 *

Examples of Structured Objecs: Choose the following functors: point for points, seg for line segments, and triangle for triangles. Representation: 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)) P1=(1,1) (4,2) (7,1) (6,4) P2=(2,3) T S

Examples of Structured Objects: Tree representation of the objects: P1 = point( 1, 1) S = seg( P1, P2) = seg( point(1,1), point(2,3)) T = triangle( point(4,2), point(6,4), point(7,1)) point 4 2 6 T=triangle 7 1 Principal functor point 1 2 3 S=seg P1=point 1 9

Matching: The most important operation on terms is matching. Matching is a process that takes as input two terms and checks whether they match. Fails: if the terms do not match Succeeds: if the terms do match Given two terms, we say that they match if: they are identical , or the variable 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. For example: the terms date( D, M, 2001) and date( D1, may, Y1) match the terms date( D, M, 2001) and date( D1, M1, 1444) do not match

Examples of matching: The request for matching, using the operator ‘=‘: Examples: ?- date( D, M, 2001) = date(D1, may, Y1). D = D1,M = may,Y1 = 2001. ?- date( D, M, 2015) = date(D1, may, Y1), date( D, M, 2015) = date( 15, M, Y). D = D1, D1 = 15,M = may,Y1 = Y, Y = 2015.

Examples of matching (cont): ?- triangle( point(1,1), A, point(2,3))=triangle( X, point(4,Y), point(2,Z)). A = point(4,Y),X = point(1,1),Z = 3 point 1 A triangle 2 3 X point 4 Y triangle 2 Z

Examples of matching (cont): An example: point(1,1). point(1,2). point(2,4). seg(point(1,1), point(1,2)). seg(point(1,1), point(2,4)). seg(point(1,2), point(2,4)). vertical( seg( point( X, Y), point( X, Y1))). horizontal( seg( point( X, Y), point( X1, Y))). ?- vertical( seg( point(1,1), point( 1,2))). true ?- vertical( seg( point(1,Y), point(2,Y))). false ?- horizontal( seg( point(1,1), point(2,Y))). Y = 1

Examples of matching (cont): ?- horizontal( seg( point(1,1), P)). P = point(_,1) P = point(_G1088, 1).* ?- vertical( seg( point(1,1), P)). P = point(1,_) P = point(1, _G1077). * The answer means: Yes, any segment that ends at any point (1,_), which means anywhere on the vertical line x =1. ?- vertical( S), horizontal( S). S = seg( point( A,B), point( A,B)) S = seg(point(_G1097, _G1098), point(_G1097, _G1098)).* The answer means: Yes, any segment that is degenerated to a point has the property of being vertical and horizontal at the same time.