PROLOG.

Slides:



Advertisements
Similar presentations
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
Advertisements

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).
COSC 120 Computer Programming
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Automation Testing- QTP Rajesh Charles Batch No: Date: jan
DEDUCTIVE DATABASE.
Formal Models of Computation Part II The Logic Model
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Evolution of Programming Languages Generations of PLs.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
ProLog PROgramming in LOGic. Description of Prolog Prolog stands for PROgramming in LOGic. It is a nonprocedural and declarative language.
Expert System Development Tools Sean Lydon Daniel Nelson Emily Schwarz.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
F28PL1 Programming Languages Lecture 16: Prolog 1.
Getting Started with Visual Prolog
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Programming Languages. A Logic Programming Language: Prolog This lesson describes the basic structures and functions of the logic programming language:
Practical Erlang Programming Basic Erlang. © Erlang Training and Consulting Ltd2Basic Erlang Practical Erlang Programming.
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
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?
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CS 403: Programming Languages Lecture 18 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Logic Programming Dr. Yasser Nada Fall 2010/2011 Lecture 1 1 Logic Programming.
ISBN Chapter 16 Logic Programming Languages.
Knowledge Based Information System
Scion Macros How to make macros for Scion The Fast and Easy Guide.
Prolog Overview Syntax Mechanism Summary. Overview PROLOG : Programming with Logic Uses predicate (first-order) calculus History: Roots: J.A. Robinson.
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
Automation Testing- QTP Rajesh Charles Batch No: Date: jan
The purpose of a CPU is to process data Custom written software is created for a user to meet exact purpose Off the shelf software is developed by a software.
Section 16.5, 16.6 plus other references
Web Database Programming Using PHP
Numbers in ‘C’ Two general categories: Integers Floats
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
VBA - Excel VBA is Visual Basic for Applications
Chapter 2: Input, Processing, and Output
Web Database Programming Using PHP
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
Testing and Debugging.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
CSCI 161: Introduction to Programming
ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1.
Tests, Backtracking, and Recursion
Control Structures – Selection
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Erlang 15-Nov-18.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Artificial Intelligence CS370D
PHP.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong.
Web DB Programming: PHP
Chapter Two: Syntax and Meaning of Prolog Programs
Dr. Yasser Nada Fall 2010/2011 Lecture 1
Logic Programming Language
WEEK-2.
Chapter 2: Input, Processing, and Output
Chapter 2: Prolog (Introduction and Basic Concepts)
CPS125.
PROLOG.
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

PROLOG

PROLOG a general-purpose logic programming language associated with artificial intelligence and computational linguistics was first conceived by a group around Alain Colmerauer in Marseille, France, in the early 1970s has been used for theorem proving, expert systems, term rewriting, type inference, and automated planning, natural language processing

INSTALLATION For MAC Go to brew.sh and download homebrew Then go to your terminal and type brew install gun-prolog Then go to directory that has prolog files or prolog database Then type in gprolog

INSTALLATION For Windows Go to cygwin.com/install.html and click on install cygwin Then click on setup-x86 64.exe Now, we have to install Prolog and so go to www.gprolog.org/#download and click on Windows intel 64 bits auto-install setup link And prolog console is ready

FACTS AND RULES A prolog program is a collection of facts and rules Some examples of facts:

FACTS AND RULES A rule is more complex than a fact, it relates various facts An example of a rule relating the previous facts: This rule states that a Thing is expensive (has the property expensive) if the Thing is a car (has the car property) and the Thing is red (has the red property) Notice that :- means if and , means and

FACTS AND RULES Collectively, facts and rules are known as clauses A collection of clauses constitute a program The above clauses would be written in a file and the file loaded into the prolog interpreter

FACTS AND RULES Within the prolog interpreter, type car(dino). at the ?- prompt The ?- prompt is also known as the query prompt

FACTS AND RULES The interpreter reads the query and extracts the functor (property) car and the object dino Then It goes through each line of the program, always starting from the first line to find a fact that has the same functor as the query, i.e. car Prolog replies No. Because it cannot find a match in any of the rows of the program

VARIABLES X is a variable and stands for any object that has the car property Variables are always written with an upper case initial letter Objects or constants are written with a lower case initial letter Thing is a variable because of the initial upper case T In response to the above query, prolog replies

VARIABLES A variable without a value is called unbound A variable with a value is called bound In db.pl In prolog console

VARIABLES In db.pl: In prolog console:

VARIABLES In db.pl: In prolog console:

SYNTAX The Prolog data structure is the term Terms are nested structures defined recursively as Constant: Integer, Real, Atom Variable: named (initial letter upper case), (anonymous) Structure: functor with parameters or components, each of which may be a term likes (fred, whisky(malt, 12), X) where likes and whisky are functors of arity 3 and 2 respectively An atom is a functor of arity 0 Prolog has built-in binary operators, so that we may write 3+4*5 Prolog has no global variables

PROLOG CONSOLE Facts and rules are stored in a file called either the database or knowledge base: i.e. db.pl ?- [db]. (to load your knowledge base inside prolog console) Ex: ?- ['C:/Users/username/Desktop/db.pl']. ?- consult(‘db.pl’). (to load your knowledge base inside prolog console) ?- halt. (to exit out of the G prolog) $ gprolog (to return to your terminal) ?- listing. (it’s going to show a whole bunch of information about the contents of the database)

PROLOG

PROLOG ~w  If you want to put in a variable here ~s  If you want to transpose a string inside of here

PROLOG

CASE STATEMENTS In db.pl: In prolog console:

PROLOG

PROLOG

COMPARING VALUES In prolog console: \+ means not equal

DEBUGGING Trace is used debugging inside of prolog

DEBUGGING Notrace is used to switch off the debugger.

PROLOG

PROLOG Prolog has built-in binary operators =:=  checks equality =\=  checks inequality

INPUT/OUTPUT Reading input from user nl means new line read(X) and get(X) is used for this

FILE OPERATIONS

RECURSION

LOOP

NAME FUNCTION name take a string and convert it into a series of ASCII characters name also converts ASCII characters into a string