SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
EXP NO. 1
STUDY OF PROLOG, its insatllation procedure and working.
Prolog – Programming in Logic
PROLOG stands for Programming In Logic – an idea that emerged in the early 1970s to use logic
as programming language. PROLOG is a programming language centered around a small set of
basic mechanisms, including pattern matching, tree-based data structuring and automatic
backtracking.
FACTS , RULES AND QUERIES
Programming in PROLOG is accomplished by creating a database of facts and rules about objects,
their properties, and their relationships to other objects. Queries then can be posed about the objects
and valid conclusions will be determined and returned by the program.
For example:
1. Facts : Some facts about family relationships could be written as :
sister(sue, bill)
parent(ann, sam)
parent(joe,ann)
male(joe)
female(ann)
2. Rules : To represent the general rule for grandfather , we write :
Grandfather(X,Z):-
parent(X,Y),
parent(Y,Z),
male(X).
3. Queries : Given a data of facts and rules such as that above, we mat make queries by tying after
a query symbol ‘?_’ statements such as :
?_parent(X,sam)
X=ann
?_male(joe)
true
?_grandfather(X,Y)
X=joe;
Y=sam
?_female(joe)
false
Installation & Working with Prolog:
1. Download swi-prolog stable version
2. Run the installer
3. After SWI-Prolog has been installed on a Windows system, the following important new
things are available to the user:
➢ A folder (called directory in the remainder of this document) called swipl containing
the executables, libraries, etc., of the system. No files are installed outside this
directory.
➢ A program swipl-win.exe, providing a window for interaction with Prolog. The
program swipl.exe is a version of SWI-Prolog that runs in a console window.
➢ The file extension .pl is associated with the program swipl-win.exe. Opening a .pl file
will cause swipl-win.exe to start, change directory to the directory in which the file to
open resides, and load this file.
4. Create a notepad file with extension <filename>.pl, which consists of set of procedures
and each procedure consists of clauses. There are two types of clauses: facts and rules.
Order of these clauses are important.
➢ facts: That does not depend on any other information. A fact must start with a
predicate (which is an atom) and end with a fullstop.
➢ predicates: That provide information about individuals.A predicate can take any fixed
number of ARGUMENTS (parameters).
➢ The arguments can be atoms (in this case, these atoms are treated as constants),
numbers, variables or lists. Arguments are separated by commas.
The number of arguments that a predicate takes is called its ARITY ( like unary,
binary, ternary, and the like). Two distinct predicates can have the same name if they
have different arities; thus you might have both:
-- mother(melody), meaning Melody is a mother, and
-- mother(melody,sharon), meaning Melody is the mother of Sharon.
In a Prolog program, a presence of a fact indicates a statement that is true. An absence
of a fact indicates a statement that is not true.
➢ rules: the real power of Prolog is in rules. While facts state the relation explicitely,
rules define the relation in a more general way. Each rule has its head - name of the
defined relation, and its body - a real definition of the relation. A rule can be viewed as
an extension of a fact with added conditions that also have to be satisfied for it to be
true. In other words, A rule is a predicate expression that uses logical implication (:-) to
describe a relationship among facts.
Thus a Prolog rule takes the form left_hand_side :- right_hand_side .
This sentence is interpreted as: left_hand_side if right_hand_side.
The left_hand_side is restricted to a single, positive, literal, which means it must
consist of a positive atomic expression. It cannot be negated and it cannot contain
logical connectives.
➢ Goals: A goal is a statement starting with a predicate and probably followed by its
arguments. In a valid goal, the predicate must have appeared in at least one fact or
rule in the consulted program, and the number of arguments in the goal must be the
same as that appears in the consulted program. Also, all the arguemnts (if any) are
constants.
The purpose of submitting a goal is to find out whether the statement represented by
the goal is true according to the knowledge database (i.e. the facts and rules in the
consulted program).
➢ Queries: A query is a statement starting with a predicate and followed by its
arguments, some of which are variables. Similar to goals, the predicate of a valid
query must have appeared in at least one fact or rule in the consulted program, and
the number of arguments in the query must be the same as that appears in the
consulted program.
The purpose of submitting a query is to find values to substitute into the variables in
the query such that the query is satisfied. This is similar to asking a question, asking
for "what values will make my statement true".
5. In prolog window run [<filename>]. or consult [<filename>]. Result should be 'true'. If file
doesnot exist there, it will result 'false'].
if you want to enter fully qualified file name, then enter ['path..to..file/filename.pl'].
6. (dot). mark the end of command.
7. listing. displays the content of loaded program.
8. use command 'halt' with a . (dot) to stop the prolog system.
EXP NO. 2
Write a prolog code having facts and rules about students and the courses they are studying.
Query about the connection among students of different courses.
PROLOG CODE:
/* Facts */
studies(kanika,cse).
studies(niharika,cse).
studies(shivani,cse).
studies(rakhi,cse).
studies(chanchal, cse).
studies(akram, cse).
studies(alka, cse).
studies(shabistan, cse).
studies(prince, ece).
/* Rules */
batchmate(X,Y):­ studies(X,Z),studies(Y,Z).
OUTPUT
EXP NO. 3
Find all paths between any two vertices in the given graph:
PROLOG CODE:
/* facts: */
edge(1,2). 
edge(1,3). 
edge(1,4). 
edge(2,3). 
edge(2,5). 
edge(3,4). 
edge(3,5). 
edge(4,5). 
/* rules: */
connected(X,Y) :­ edge(X,Y) ; edge(Y,X). 
path(A,B,Path) :­
travel(A,B,[A],Q),
    reverse(Q,Path).
travel(A,B,P,[B|P]) :­
connected(A,B).
travel(A,B,Visited,Path) :­
connected(A,C),
C == B,
    not(member(C,Visited)), 
    travel(C,B,[C|Visited],Path). 
OUTPUT
EXP NO. 4
"MURDER MYSTERY" Problem
Alice, her husband, son, daughter, and brother are involved in a murder. One of the five killed
one of the other four. Who was the killer?
1. A man and a woman were together in the bar at the time of the murder.
2. The victim and the killer were together on the beach at the time of the murder.
3. One of the children was alone at the time of the murder.
4. Alice and her husband were not together at the time of the murder.
5. The victim's twin was innocent.
6. The killer was younger than the victim.
PROLOG CODE
/*­­­­­ Facts ­­­­­*/
person(alice).
person(husband).
person(son).
person(daughter).
person(brother).
child(son).
child(daughter).
male(husband).
male(son).
male(brother).
female(alice).
female(daughter).
twin(alice,    brother).
twin(brother,  alice).
twin(son,      daughter).
twin(daughter, son).
/*­­­­­ Rules ­­­­­*/
istwin(X) :­ twin(X, _).
older(alice,   son).
older(alice,   daughter).
older(husband, son).
older(husband, daughter).
inbar(M, N) :­ person(M), person(N),
               male(M),   female(N).
together(S, T) :­ S=alice, T=husband.
together(S, T) :­ T=alice, S=husband.
alone(P) :­ person(P), child(P).
/*­­­­­ Rule Combining Clues ­­­­­*/
solution(Killer, Victim, InBarA, InBarB, Alone) :­
    person(Killer), person(Victim),
    /* The victim's twin was innocent. */
        istwin(Victim), + twin(Victim, Killer),
    /* The killer was younger than the victim. */
+ older(Killer, Victim),
    /* not the same as "older(Victim, Killer)"! */
    /* Alice and her husband were not together 
       at the time of the murder. */
        + together(Killer, Victim), Killer = Victim,
    /* A man and a woman were together in the 
       at the time of the murder. */
        inbar(InBarA, InBarB),
InBarA = Killer, InBarB = Killer,
InBarA = Victim, InBarB = Victim,
    /* Alice and her husband were not together 
       at the time of the murder. */
        + together(InBarA, InBarB),
    /* One of the children was alone at the 
       time of the murder. */
alone(Alone),
Alone = InBarA, Alone = InBarB,
Alone = Killer, Alone = Victim.
/*­­­­­ Goal ­­­­­*/
print_solution :­
    /* Find the solution */
        solution(Killer, Victim, InBarA, InBarB, Alone),
    /* Write solution */
nl,
                write(Killer),   write('   killed   '),   write(Victim),
write('.'), nl,
write(InBarA), write(' and '), write(InBarB),
write(' were together in the bar.'), nl,
write(Alone), write(' was alone.'), nl, nl.
?­ print_solution.
OUTPUT
EXP NO. 5
Missionaries and cannibals. Suppose 3 missionaries and 3 cannibals are walking together
through the forest. They arrive at a river they have to cross, but there is only one boat, and
that boat can carry at most 2 people. Of course, for the boat to cross the river, there should be
at least one person (missionary or cannibal) in the boat (to row the boat). The problem is that
if there are more cannibals than missionaries at any place, they will eat the missionaries.
Write a program that finds a strategy for the six people to cross the river without a missionary
being eaten.
PROLOG CODE
start([3,3,left,0,0]).
goal([0,0,right,3,3]).
legal(CL,ML,CR,MR) :­
/* is this state a legal one? */
ML>=0, CL>=0, MR>=0, CR>=0,
(ML>=CL ; ML=0),
(MR>=CR ; MR=0).
/* Possible moves: */
move([CL,ML,left,CR,MR],[CL,ML2,right,CR,MR2]):­
/* Two missionaries cross left to right. */
MR2 is MR+2,
ML2 is ML­2,
legal(CL,ML2,CR,MR2).
move([CL,ML,left,CR,MR],[CL2,ML,right,CR2,MR]):­
/* Two cannibals cross left to right. */
CR2 is CR+2,
CL2 is CL­2,
legal(CL2,ML,CR2,MR).
move([CL,ML,left,CR,MR],[CL2,ML2,right,CR2,MR2]):­
/* One missionary and one cannibal cross left to right. */
CR2 is CR+1,
CL2 is CL­1,
MR2 is MR+1,
ML2 is ML­1,
legal(CL2,ML2,CR2,MR2).
move([CL,ML,left,CR,MR],[CL,ML2,right,CR,MR2]):­
/* One missionary crosses left to right. */
MR2 is MR+1,
ML2 is ML­1,
legal(CL,ML2,CR,MR2).
move([CL,ML,left,CR,MR],[CL2,ML,right,CR2,MR]):­
/* One cannibal crosses left to right. */
CR2 is CR+1,
CL2 is CL­1,
legal(CL2,ML,CR2,MR).
move([CL,ML,right,CR,MR],[CL,ML2,left,CR,MR2]):­
/* Two missionaries cross right to left. */
MR2 is MR­2,
ML2 is ML+2,
legal(CL,ML2,CR,MR2).
move([CL,ML,right,CR,MR],[CL2,ML,left,CR2,MR]):­
/* Two cannibals cross right to left. */
CR2 is CR­2,
CL2 is CL+2,
legal(CL2,ML,CR2,MR).
move([CL,ML,right,CR,MR],[CL2,ML2,left,CR2,MR2]):­
/* One missionary and one cannibal cross right to left. */
CR2 is CR­1,
CL2 is CL+1,
MR2 is MR­1,
ML2 is ML+1,
legal(CL2,ML2,CR2,MR2).
move([CL,ML,right,CR,MR],[CL,ML2,left,CR,MR2]):­
/* One missionary crosses right to left. */
MR2 is MR­1,
ML2 is ML+1,
legal(CL,ML2,CR,MR2).
move([CL,ML,right,CR,MR],[CL2,ML,left,CR2,MR]):­
/* One cannibal crosses right to left. */
CR2 is CR­1,
CL2 is CL+1,
legal(CL2,ML,CR2,MR).
/* Recursive call to solve the problem */
path([CL1,ML1,B1,CR1,MR1],[CL2,ML2,B2,CR2,MR2],Explored,MovesList)
:­ 
   move([CL1,ML1,B1,CR1,MR1],[CL3,ML3,B3,CR3,MR3]), 
   not(member([CL3,ML3,B3,CR3,MR3],Explored)),
      path([CL3,ML3,B3,CR3,MR3],[CL2,ML2,B2,CR2,MR2],
[[CL3,ML3,B3,CR3,MR3]|Explored],[   [[CL3,ML3,B3,CR3,MR3],
[CL1,ML1,B1,CR1,MR1]] | MovesList ]).
/* Solution found */
path([CL,ML,B,CR,MR],[CL,ML,B,CR,MR],_,MovesList):­ 
output(MovesList).
/* Printing */
output([]) :­ nl. 
output([[A,B]|MovesList]) :­ 
output(MovesList), 
    write(B), write(' ­> '), write(A), nl.
/* Find the solution for the missionaries and cannibals problem */
find :­ 
   path([3,3,left,0,0],[0,0,right,3,3],[[3,3,left,0,0]],_).
OUTPUT

Mais conteúdo relacionado

Mais procurados

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Alamgir Hossain
 
Over fitting underfitting
Over fitting underfittingOver fitting underfitting
Over fitting underfittingSivapriyaS12
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMSkoolkampus
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O NotationJawad Khan
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programmingTafhim Islam
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : BasicsMitul Desai
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & ReasoningSajid Marwat
 
Spell checker using Natural language processing
Spell checker using Natural language processing Spell checker using Natural language processing
Spell checker using Natural language processing Sandeep Wakchaure
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 

Mais procurados (20)

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.
 
Over fitting underfitting
Over fitting underfittingOver fitting underfitting
Over fitting underfitting
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
AI Lecture 7 (uncertainty)
AI Lecture 7 (uncertainty)AI Lecture 7 (uncertainty)
AI Lecture 7 (uncertainty)
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : Basics
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
 
Predicate logic
 Predicate logic Predicate logic
Predicate logic
 
Spell checker using Natural language processing
Spell checker using Natural language processing Spell checker using Natural language processing
Spell checker using Natural language processing
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 

Semelhante a Ai lab manual

UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxUOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxqasim ali
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfCS With Logic
 
________ ________1.ppt
________ ________1.ppt________ ________1.ppt
________ ________1.pptSamiAAli44
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide2021uam4641
 
Introduction to logic and prolog - Part 1
Introduction to logic and prolog - Part 1Introduction to logic and prolog - Part 1
Introduction to logic and prolog - Part 1Sabu Francis
 
6&7-Query Languages & Operations.ppt
6&7-Query Languages & Operations.ppt6&7-Query Languages & Operations.ppt
6&7-Query Languages & Operations.pptBereketAraya
 
NAISTビッグデータシンポジウム - 情報 松本先生
NAISTビッグデータシンポジウム - 情報 松本先生NAISTビッグデータシンポジウム - 情報 松本先生
NAISTビッグデータシンポジウム - 情報 松本先生ysuzuki-naist
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEDrBindhuM
 

Semelhante a Ai lab manual (20)

UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxUOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
 
Deductive databases
Deductive databasesDeductive databases
Deductive databases
 
Prolog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdfProlog,Prolog Programming IN AI.pdf
Prolog,Prolog Programming IN AI.pdf
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
 
Prolog final
Prolog finalProlog final
Prolog final
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
________ ________1.ppt
________ ________1.ppt________ ________1.ppt
________ ________1.ppt
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
 
ICS1019.pdf
ICS1019.pdfICS1019.pdf
ICS1019.pdf
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
 
Chapter 5 (final)
Chapter 5 (final)Chapter 5 (final)
Chapter 5 (final)
 
Ics1019 ics5003
Ics1019 ics5003Ics1019 ics5003
Ics1019 ics5003
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
Introduction to logic and prolog - Part 1
Introduction to logic and prolog - Part 1Introduction to logic and prolog - Part 1
Introduction to logic and prolog - Part 1
 
Mcs 021
Mcs 021Mcs 021
Mcs 021
 
6&7-Query Languages & Operations.ppt
6&7-Query Languages & Operations.ppt6&7-Query Languages & Operations.ppt
6&7-Query Languages & Operations.ppt
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
NAISTビッグデータシンポジウム - 情報 松本先生
NAISTビッグデータシンポジウム - 情報 松本先生NAISTビッグデータシンポジウム - 情報 松本先生
NAISTビッグデータシンポジウム - 情報 松本先生
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULE
 

Mais de Shipra Swati

Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process SchedulingShipra Swati
 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of ProcessShipra Swati
 
Operating System-Introduction
Operating System-IntroductionOperating System-Introduction
Operating System-IntroductionShipra Swati
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Shipra Swati
 
Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Shipra Swati
 
Fundamental of Information Technology
Fundamental of Information TechnologyFundamental of Information Technology
Fundamental of Information TechnologyShipra Swati
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process SynchronizationShipra Swati
 

Mais de Shipra Swati (20)

Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of Process
 
Operating System-Introduction
Operating System-IntroductionOperating System-Introduction
Operating System-Introduction
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 
Java unit 14
Java unit 14Java unit 14
Java unit 14
 
Java unit 12
Java unit 12Java unit 12
Java unit 12
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Java unit 3
Java unit 3Java unit 3
Java unit 3
 
Java unit 2
Java unit 2Java unit 2
Java unit 2
 
Java unit 1
Java unit 1Java unit 1
Java unit 1
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6Fundamental of Information Technology - UNIT 6
Fundamental of Information Technology - UNIT 6
 
Fundamental of Information Technology
Fundamental of Information TechnologyFundamental of Information Technology
Fundamental of Information Technology
 
Disk Management
Disk ManagementDisk Management
Disk Management
 
File Systems
File SystemsFile Systems
File Systems
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Último (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

Ai lab manual

  • 1. EXP NO. 1 STUDY OF PROLOG, its insatllation procedure and working. Prolog – Programming in Logic PROLOG stands for Programming In Logic – an idea that emerged in the early 1970s to use logic as programming language. PROLOG is a programming language centered around a small set of basic mechanisms, including pattern matching, tree-based data structuring and automatic backtracking. FACTS , RULES AND QUERIES Programming in PROLOG is accomplished by creating a database of facts and rules about objects, their properties, and their relationships to other objects. Queries then can be posed about the objects and valid conclusions will be determined and returned by the program. For example: 1. Facts : Some facts about family relationships could be written as : sister(sue, bill) parent(ann, sam) parent(joe,ann) male(joe) female(ann) 2. Rules : To represent the general rule for grandfather , we write : Grandfather(X,Z):- parent(X,Y), parent(Y,Z), male(X). 3. Queries : Given a data of facts and rules such as that above, we mat make queries by tying after a query symbol ‘?_’ statements such as : ?_parent(X,sam) X=ann ?_male(joe) true ?_grandfather(X,Y) X=joe; Y=sam ?_female(joe) false Installation & Working with Prolog: 1. Download swi-prolog stable version 2. Run the installer 3. After SWI-Prolog has been installed on a Windows system, the following important new things are available to the user: ➢ A folder (called directory in the remainder of this document) called swipl containing the executables, libraries, etc., of the system. No files are installed outside this directory. ➢ A program swipl-win.exe, providing a window for interaction with Prolog. The program swipl.exe is a version of SWI-Prolog that runs in a console window. ➢ The file extension .pl is associated with the program swipl-win.exe. Opening a .pl file will cause swipl-win.exe to start, change directory to the directory in which the file to open resides, and load this file. 4. Create a notepad file with extension <filename>.pl, which consists of set of procedures and each procedure consists of clauses. There are two types of clauses: facts and rules. Order of these clauses are important.
  • 2. ➢ facts: That does not depend on any other information. A fact must start with a predicate (which is an atom) and end with a fullstop. ➢ predicates: That provide information about individuals.A predicate can take any fixed number of ARGUMENTS (parameters). ➢ The arguments can be atoms (in this case, these atoms are treated as constants), numbers, variables or lists. Arguments are separated by commas. The number of arguments that a predicate takes is called its ARITY ( like unary, binary, ternary, and the like). Two distinct predicates can have the same name if they have different arities; thus you might have both: -- mother(melody), meaning Melody is a mother, and -- mother(melody,sharon), meaning Melody is the mother of Sharon. In a Prolog program, a presence of a fact indicates a statement that is true. An absence of a fact indicates a statement that is not true. ➢ rules: the real power of Prolog is in rules. While facts state the relation explicitely, rules define the relation in a more general way. Each rule has its head - name of the defined relation, and its body - a real definition of the relation. A rule can be viewed as an extension of a fact with added conditions that also have to be satisfied for it to be true. In other words, A rule is a predicate expression that uses logical implication (:-) to describe a relationship among facts. Thus a Prolog rule takes the form left_hand_side :- right_hand_side . This sentence is interpreted as: left_hand_side if right_hand_side. The left_hand_side is restricted to a single, positive, literal, which means it must consist of a positive atomic expression. It cannot be negated and it cannot contain logical connectives. ➢ Goals: A goal is a statement starting with a predicate and probably followed by its arguments. In a valid goal, the predicate must have appeared in at least one fact or rule in the consulted program, and the number of arguments in the goal must be the same as that appears in the consulted program. Also, all the arguemnts (if any) are constants. The purpose of submitting a goal is to find out whether the statement represented by the goal is true according to the knowledge database (i.e. the facts and rules in the consulted program). ➢ Queries: A query is a statement starting with a predicate and followed by its arguments, some of which are variables. Similar to goals, the predicate of a valid query must have appeared in at least one fact or rule in the consulted program, and the number of arguments in the query must be the same as that appears in the consulted program. The purpose of submitting a query is to find values to substitute into the variables in the query such that the query is satisfied. This is similar to asking a question, asking for "what values will make my statement true". 5. In prolog window run [<filename>]. or consult [<filename>]. Result should be 'true'. If file doesnot exist there, it will result 'false']. if you want to enter fully qualified file name, then enter ['path..to..file/filename.pl']. 6. (dot). mark the end of command. 7. listing. displays the content of loaded program. 8. use command 'halt' with a . (dot) to stop the prolog system.
  • 3. EXP NO. 2 Write a prolog code having facts and rules about students and the courses they are studying. Query about the connection among students of different courses. PROLOG CODE: /* Facts */ studies(kanika,cse). studies(niharika,cse). studies(shivani,cse). studies(rakhi,cse). studies(chanchal, cse). studies(akram, cse). studies(alka, cse). studies(shabistan, cse). studies(prince, ece). /* Rules */ batchmate(X,Y):­ studies(X,Z),studies(Y,Z). OUTPUT
  • 4. EXP NO. 3 Find all paths between any two vertices in the given graph: PROLOG CODE: /* facts: */ edge(1,2).  edge(1,3).  edge(1,4).  edge(2,3).  edge(2,5).  edge(3,4).  edge(3,5).  edge(4,5).  /* rules: */ connected(X,Y) :­ edge(X,Y) ; edge(Y,X).  path(A,B,Path) :­ travel(A,B,[A],Q),     reverse(Q,Path). travel(A,B,P,[B|P]) :­ connected(A,B). travel(A,B,Visited,Path) :­ connected(A,C), C == B,     not(member(C,Visited)),      travel(C,B,[C|Visited],Path).  OUTPUT
  • 5. EXP NO. 4 "MURDER MYSTERY" Problem Alice, her husband, son, daughter, and brother are involved in a murder. One of the five killed one of the other four. Who was the killer? 1. A man and a woman were together in the bar at the time of the murder. 2. The victim and the killer were together on the beach at the time of the murder. 3. One of the children was alone at the time of the murder. 4. Alice and her husband were not together at the time of the murder. 5. The victim's twin was innocent. 6. The killer was younger than the victim. PROLOG CODE /*­­­­­ Facts ­­­­­*/ person(alice). person(husband). person(son). person(daughter). person(brother). child(son). child(daughter). male(husband). male(son). male(brother). female(alice). female(daughter). twin(alice,    brother). twin(brother,  alice). twin(son,      daughter). twin(daughter, son). /*­­­­­ Rules ­­­­­*/ istwin(X) :­ twin(X, _). older(alice,   son). older(alice,   daughter). older(husband, son). older(husband, daughter). inbar(M, N) :­ person(M), person(N),                male(M),   female(N). together(S, T) :­ S=alice, T=husband. together(S, T) :­ T=alice, S=husband. alone(P) :­ person(P), child(P). /*­­­­­ Rule Combining Clues ­­­­­*/ solution(Killer, Victim, InBarA, InBarB, Alone) :­     person(Killer), person(Victim),
  • 6.     /* The victim's twin was innocent. */         istwin(Victim), + twin(Victim, Killer),     /* The killer was younger than the victim. */ + older(Killer, Victim),     /* not the same as "older(Victim, Killer)"! */     /* Alice and her husband were not together         at the time of the murder. */         + together(Killer, Victim), Killer = Victim,     /* A man and a woman were together in the         at the time of the murder. */         inbar(InBarA, InBarB), InBarA = Killer, InBarB = Killer, InBarA = Victim, InBarB = Victim,     /* Alice and her husband were not together         at the time of the murder. */         + together(InBarA, InBarB),     /* One of the children was alone at the         time of the murder. */ alone(Alone), Alone = InBarA, Alone = InBarB, Alone = Killer, Alone = Victim. /*­­­­­ Goal ­­­­­*/ print_solution :­     /* Find the solution */         solution(Killer, Victim, InBarA, InBarB, Alone),     /* Write solution */ nl,                 write(Killer),   write('   killed   '),   write(Victim), write('.'), nl, write(InBarA), write(' and '), write(InBarB), write(' were together in the bar.'), nl, write(Alone), write(' was alone.'), nl, nl. ?­ print_solution. OUTPUT
  • 7. EXP NO. 5 Missionaries and cannibals. Suppose 3 missionaries and 3 cannibals are walking together through the forest. They arrive at a river they have to cross, but there is only one boat, and that boat can carry at most 2 people. Of course, for the boat to cross the river, there should be at least one person (missionary or cannibal) in the boat (to row the boat). The problem is that if there are more cannibals than missionaries at any place, they will eat the missionaries. Write a program that finds a strategy for the six people to cross the river without a missionary being eaten. PROLOG CODE start([3,3,left,0,0]). goal([0,0,right,3,3]). legal(CL,ML,CR,MR) :­ /* is this state a legal one? */ ML>=0, CL>=0, MR>=0, CR>=0, (ML>=CL ; ML=0), (MR>=CR ; MR=0). /* Possible moves: */ move([CL,ML,left,CR,MR],[CL,ML2,right,CR,MR2]):­ /* Two missionaries cross left to right. */ MR2 is MR+2, ML2 is ML­2, legal(CL,ML2,CR,MR2). move([CL,ML,left,CR,MR],[CL2,ML,right,CR2,MR]):­ /* Two cannibals cross left to right. */ CR2 is CR+2, CL2 is CL­2, legal(CL2,ML,CR2,MR). move([CL,ML,left,CR,MR],[CL2,ML2,right,CR2,MR2]):­ /* One missionary and one cannibal cross left to right. */ CR2 is CR+1, CL2 is CL­1, MR2 is MR+1, ML2 is ML­1, legal(CL2,ML2,CR2,MR2). move([CL,ML,left,CR,MR],[CL,ML2,right,CR,MR2]):­ /* One missionary crosses left to right. */ MR2 is MR+1, ML2 is ML­1, legal(CL,ML2,CR,MR2).
  • 8. move([CL,ML,left,CR,MR],[CL2,ML,right,CR2,MR]):­ /* One cannibal crosses left to right. */ CR2 is CR+1, CL2 is CL­1, legal(CL2,ML,CR2,MR). move([CL,ML,right,CR,MR],[CL,ML2,left,CR,MR2]):­ /* Two missionaries cross right to left. */ MR2 is MR­2, ML2 is ML+2, legal(CL,ML2,CR,MR2). move([CL,ML,right,CR,MR],[CL2,ML,left,CR2,MR]):­ /* Two cannibals cross right to left. */ CR2 is CR­2, CL2 is CL+2, legal(CL2,ML,CR2,MR). move([CL,ML,right,CR,MR],[CL2,ML2,left,CR2,MR2]):­ /* One missionary and one cannibal cross right to left. */ CR2 is CR­1, CL2 is CL+1, MR2 is MR­1, ML2 is ML+1, legal(CL2,ML2,CR2,MR2). move([CL,ML,right,CR,MR],[CL,ML2,left,CR,MR2]):­ /* One missionary crosses right to left. */ MR2 is MR­1, ML2 is ML+1, legal(CL,ML2,CR,MR2). move([CL,ML,right,CR,MR],[CL2,ML,left,CR2,MR]):­ /* One cannibal crosses right to left. */ CR2 is CR­1, CL2 is CL+1, legal(CL2,ML,CR2,MR). /* Recursive call to solve the problem */ path([CL1,ML1,B1,CR1,MR1],[CL2,ML2,B2,CR2,MR2],Explored,MovesList) :­     move([CL1,ML1,B1,CR1,MR1],[CL3,ML3,B3,CR3,MR3]),     not(member([CL3,ML3,B3,CR3,MR3],Explored)),       path([CL3,ML3,B3,CR3,MR3],[CL2,ML2,B2,CR2,MR2], [[CL3,ML3,B3,CR3,MR3]|Explored],[   [[CL3,ML3,B3,CR3,MR3], [CL1,ML1,B1,CR1,MR1]] | MovesList ]). /* Solution found */ path([CL,ML,B,CR,MR],[CL,ML,B,CR,MR],_,MovesList):­