Download presentation
Presentation is loading. Please wait.
1
PROLOG
2
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
3
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
4
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 and click on Windows intel 64 bits auto-install setup link And prolog console is ready
5
FACTS AND RULES A prolog program is a collection of facts and rules
Some examples of facts:
6
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
7
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
8
FACTS AND RULES Within the prolog interpreter, type car(dino). at the ?- prompt The ?- prompt is also known as the query prompt
9
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
10
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
11
VARIABLES A variable without a value is called unbound
A variable with a value is called bound In db.pl In prolog console
12
VARIABLES In db.pl: In prolog console:
13
VARIABLES In db.pl: In prolog console:
14
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
15
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)
16
PROLOG
17
PROLOG ~w If you want to put in a variable here
~s If you want to transpose a string inside of here
18
PROLOG
19
CASE STATEMENTS In db.pl: In prolog console:
20
PROLOG
21
PROLOG
22
COMPARING VALUES In prolog console: \+ means not equal
23
DEBUGGING Trace is used debugging inside of prolog
24
DEBUGGING Notrace is used to switch off the debugger.
25
PROLOG
26
PROLOG Prolog has built-in binary operators =:= checks equality
=\= checks inequality
27
INPUT/OUTPUT Reading input from user nl means new line
read(X) and get(X) is used for this
28
FILE OPERATIONS
29
RECURSION
30
LOOP
31
NAME FUNCTION name take a string and convert it into a series of ASCII characters name also converts ASCII characters into a string
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.