Professional Documents
Culture Documents
AI (Lalit)
AI (Lalit)
0|Page
INDEX
Sr. No. Content Page No.
2 Write simple facts for the statements and querying it. 4-5
1|Page
1- Program to implement BFS/DFS
Traversal
DFS implementation program in a tree structure
Code:
b c
e d f g
i h
Output:
2|Page
BFS implementation in prolog
Code:
a
b c
e d f g
i h
Output:
3|Page
2- Simple fact for the statement and
querying it.
Simple Facts
In Prolog we can make some statements by using facts. Facts either consist of a particular item or a
relation between items. For example we can represent the fact that it is sunny by writing the program:
sunny.
?- sunny.
?- is the Prolog prompt. To this query, Prolog will answer yes. sunny is true because (from
above) Prolog matches it in its database of facts.
Queries
Queries are used to ask whether something is a logical consequence of a knowledge base.
With propositional queries, a user can ask yes-or-no questions. Queries with variables allow the
system to return the values of the variables that make the query a logical consequence of the
knowledge base.
4|Page
An instance of a query is obtained by substituting terms for the variables in the query. Different
occurrences of a variable must be replaced by the same term. Given a query with free variables,
an answer is either an instance of the query that is a logical consequence of the knowledge base,
or "no", meaning that no instances of the query logically follow from the knowledge base.
Instances of the query are specified by providing values for the variables in the query.
Determining which instances of a query follow from a knowledge base is known as answer
extraction.
imm_west(r101,r103).
imm_west(r103,r105).
imm_west(r105,r107).
imm_west(r107,r109).
imm_west(r109,r111).
imm_west(r131,r129).
imm_west(r129,r127).
imm_west(r127,r125).
imm_east(E,W) ←
imm_west(W,E).
next_door(E,W) ←
imm_east(E,W).
next_door(W,E) ←
imm_west(W,E).
two_doors_east(E,W) ←
imm_east(E,M) ∧
imm_east(M,W).
west(W,E) ←
imm_west(W,E).
west(W,E) ←
imm_west(W,M) ∧
west(M,E).
5|Page
3 – Family Tree
Program:
Output:
6|Page
4-Monkey Banana Problem
Code:
Output:
7|Page
5-Tic-Tac-Toe
Program:
8|Page
9|Page
10 | P a g e
11 | P a g e
Output:
12 | P a g e