Introduction to prolog (1). Introduction to Prolog 2 Overviews Interacting with Prolog Terms Existential Queries Universal Facts and Rules Negation as.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

1. An Overview of Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 27: Prolog’s Resolution and Programming Techniques COMP 144 Programming Language.
1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.
Introduction to C Programming
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Logic Programming Languages
Sequence Control Chapter 6. 2 l Control structures: the basic framework within which operations and data are combined into programs. Sequence control.
Formal Models of Computation Part II The Logic Model
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
Using the selection structure (Unit 7) Visual Basic for Applications.
CS 2104 – Prog. Lang. Concepts Logic Programming - II Dr. Abhik Roychoudhury School of Computing.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Linux Operations and Administration
F28PL1 Programming Languages Lecture 16: Prolog 1.
Prolog Programming. 2 DATA STRUCTURES IN PROLOG PROGRAMMING TECHNIQUES CONTROL IN PROLOG CUTS.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
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 Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
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?
Copyright © Cengage Learning. All rights reserved. 1 Functions and Their Graphs.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Logical and Functional Programming
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
Prolog Harry R. Erwin, PhD COMM2M University of Sunderland.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
Programming Languages Third Edition Chapter 4 Logic Programming.
Principles of programming languages 12: Logic programming Isao Sasano Department of Information Science and Engineering.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
Solving Linear Systems by Substitution
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Dr. Muhammed Al-Mulhem ICS An Introduction to Prolog.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Solving Equations Using Logs. True or False? 1.Log 4 = log Log 15 = log 3 x log 5 3.Log 4 = log 8 – log 2 4.Log 64 = 2 log 8 5.Log 64 = 8 log 2.
1-1 An Introduction to Prolog Sept Prolog statements Like other programming languages, Prolog consists of collection of statements. Prolog.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 - Introduction to C Programming
Introduction to Algebra
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Solve a system of linear equation in two variables
Chapter 8: Advanced Pattern Matching
Chapter 2 - Introduction to C Programming
Function notation & evaluating functions
Chapter 2 - Introduction to C Programming
Logic Programming Language
Linux Shell Script Programming
Overview of Programming Paradigms
Chapter 2 Syntax and meaning of prolog programs
Chapter 2 - Introduction to C Programming
OBJ first-order functional language based on equational logic
Chapter 2: Prolog (Introduction and Basic Concepts)
PROLOG.
Presentation transcript:

Introduction to prolog (1)

Introduction to Prolog 2 Overviews Interacting with Prolog Terms Existential Queries Universal Facts and Rules Negation as Failure Unification Arithmetic

Introduction to Prolog 3 Interacting with Prolog When started, the system responds with the “prompt” (?-) characters All command must end with full-stop mark. Any parameter of command must be in between parentheses. Prolog filename have extension.pl ls.List file in current directory. pwd.display current directory path. Cd( ).Move in wish directory Consult(filename no extension).Read prolog filename

Introduction to Prolog 4 Terms Facts, rules, and queries are specified using terms A simple term is a number, a variable starting with an uppercase letter, or an atom standing for itself. Examples of simple terms 0 and 1972 are numbers X and Source are variables lisp and algol60 are atoms X Source lisp algol60

Introduction to Prolog 5 Compound Term A compound term consists of an atom followed by a parenthesized sequence of subterms. The atom is called a functor and The subterms are called arguments special variable “_” is a placeholder for an unnamed term. All occurrences of “_” are independent of each other. animal(dog)

Introduction to Prolog 6 Basic syntax of facts, rules and queries in Edinburgh Prolog ::=. ::= :-. ::=. ::= | | | ( ) ::= |,

Introduction to Prolog 7 Links between languages Algol 60 CPL BCPL C C++ Simula67 Smalltalk-80 Fortran

Introduction to Prolog 8 Facts and rules in file “links.pl” link(fortran, algol60). link(algol60, cpl). link(cpl, bcpl). link(bcpl, c). link(c, cplusplus). link(algol60, simula67). link(simula67, cplusplus). link(simula67, smalltalk80). path(L,L). path(L,M) :- link(L,X), path(X,M).

Introduction to Prolog 9 Existential Queries A query for k>=1, corresponds to the following pseudocode : Queries are also called goals.,,...,. and and... and ?

Introduction to Prolog 10 Query Example Type “links.pl” by using notepad and save it in drive C:\Prolog\

Introduction to Prolog 11 Query Example Do command following ?-link(fortran,algol60) ?-link(cpl,bcpl), link(bcpl,c). ?-link(algo60, L), link(L,M).

Introduction to Prolog 12 Do when Query We have 2 actions to do  Type “Enter” Button. Prolog responds with yes to indicate that there might be more solutions. It then immediately prompts for the next query.  Type a semicolon and a carriage return. Prolog responds with another solution, or with no to indicate that no further solutions can be found.

Introduction to Prolog 13 Universal Facts and Rules A rules for k>=1, corresponds to the following pseudocode: The term of the left of the :- is called the head The terms to the right of the :- are called conditions A fact has a head and no conditions :-,,...,. if and... and.

Introduction to Prolog 14 Fact and Rules in file “links.pl” The following fact and rule specify a relation path: The idea is that a path consists of zero or more links. We take a path of zero link to be from L to itself. A path from L to M begins with a link to some X and continues along the path from X to M Path(L, L). Path(L, M) :- link(L, X), path(X, M).

Introduction to Prolog 15 Fact and Rules in file “links.pl” Path(L, L). Path(L, M) :- link(L, X), path(X, M). For all L, path(L,L). For all L and M, path(L,M) if there exists X such that link(L,X) and path(X,M).

Introduction to Prolog 16 Negation as Failure Prolog answers no to a query if it fails to satisfy the query. It mean “If I can’t prove it, it must be false.” link(lisp,scheme). Answer: no link(L, N), link(M, N). link(L, N), link(M, N), not(L=M). Not(L=M), link(L, N), link(M, N).

Introduction to Prolog 17 Unification How does Prolog solve equations of the following form Deduction in Prolog is based on the concept of unification. ?- f(X,b) = f(a,Y). X = a Y = b Thus, f(a,b) is an instance of f(X,b) because subterm a substitutes for variable X in f(X,b) and subterm b substitues for variable Y in f(a,Y). Another example, g(a,a) is an instance of g(X, X) or g(h(b),h(b)) g(a,b) is not an instance of g(X,X)

Introduction to Prolog 18 Arithmetic The = operator stands for unification in Prolog, so The infix “is” operator evaluates an expression: However ?- X = 2+3. X = 2+3 ?- X is 2+3. X = 5 simply binds variable X to the term 2+3. since the “is” operator binds X to 5. ?- X is 2+3, X = 2+3.