Professional Documents
Culture Documents
aireport
aireport
LAB REPORT
ON
ARTIFICIAL INTELLIGENCE (CACS410)
“LAB I”
Faculty of Humanities & Social Science
Department of Computer Application
In partial fulfillment of the requirements for the
Course Artificial Intelligence
Rules: Rules in Prolog are logical statements that allow for the definition of complex
relationships based on simpler ones. A rule consists of a head and a body, where the head
represents what can be inferred and the body specifies the conditions under which the
inference is valid. Through rules, Prolog can derive new information or make logical
deductions. For example, a rule might define an ancestor relationship by stating that X is an
ancestor of Y if X is a parent of Y, or if X is a parent of some Z and Z is an ancestor of Y.
Queries: Queries are the mechanism by which users interact with Prolog programs. They are
questions or goals posed to the Prolog system, asking it to find solutions or proofs based on
the facts and rules provided. Prolog attempts to satisfy queries by searching for matches in its
knowledge base and applying rules as necessary. Users can pose queries to retrieve
information or test relationships within the domain. For instance, a query might ask whether
John is the father of Jack, prompting Prolog to search for a matching fact father(john, jack) in
its database and return true or false accordingly.
Objective:
The targets of Prolog as a rationale programming language include:
4. Scalability and Modularity: Prolog means to help the improvement of versatile and
particular projects. It considers the decay of complicated issues into more modest, more
sensible units using predicates and modules, advancing code reuse and viability.
5. Integration with Other Paradigms: Prolog is much of the time utilized related to other
programming standards, for example, utilitarian programming or article situated
programming. It furnishes offices for communicating with outside code written in different
dialects, considering consistent reconciliation inside bigger programming frameworks.
6. AI and Master Systems: Prolog has been generally utilized in man-made brainpower
(simulated intelligence) and master frameworks applications because of its capacity to
address and reason about complex information and connections. It gives a characteristic
structure to communicating master information and carrying out thinking systems.
Generally, Prolog expects to give a flexible and expressive programming language for
tackling many issues, especially those including emblematic calculation, sensible induction,
and information portrayal.
1. Develop rules for the following: Jealousy between two persons if they love the same
person of opposite gender. Experiment with different forms of queries.
Source Code:
Output:
2. Develop rules for brother-in-law and sister-in-law and experiment with different
forms of queries.
Source Code:
Output:
3. Develop friendship relationship in prolog using recursive function and experiment
with different forms of queries.
Source Code:
Output:
5. Implementation of for loop in prolog and using that print multiplication table of n.
Source Code:
Output:
6. Find factorial in prolog using recursion.
Source Code:
Output:
7. Print Fibonacci series in prolog upto n terms.
Source Code:
Output:
Conclusion:
Through the exploration of various Prolog concepts and techniques, including rule-based
inference, recursion, and iterative constructs, a diverse range of problems has been
successfully addressed. The development of rules for jealousy, brother-in-law and sister-in-
law relationships, and friendship illustrates Prolog's ability to represent complex relationships
and derive logical conclusions. Additionally, the implementation of for loops facilitated tasks
like printing multiplication tables and calculating factorials, demonstrating Prolog's
versatility in handling iterative computations. Furthermore, the generation of the Fibonacci
series showcases Prolog's capability for recursive problem-solving. Overall, these exercises
highlight the effectiveness of Prolog in tackling diverse problem domains through its unique
logic-based approach.
A
LAB REPORT
ON
ARTIFICIAL INTELLIGENCE (CACS410)
“LAB II”
Faculty of Humanities & Social Science
Department of Computer Application
“KATHMANDU NATIONAL COLLEGE”
In partial fulfillment of the requirements for the
Course Artificial Intelligence
Theory:
Artificial Intelligence (AI) encompasses a diverse set of objectives aimed at creating
intelligent systems that can revolutionize technology and society. At its core, AI seeks to
automate tasks and enhance human capabilities by developing systems that can understand
and reason with complex data, learn and adapt over time, process natural language, perceive
the environment, and operate autonomously. Through automation, AI frees humans from
mundane and repetitive tasks, allowing them to focus on more creative and complex
endeavors. By augmenting human capabilities, AI enables individuals and organizations to
achieve higher levels of productivity and efficiency in various domains. AI also aims to
enable machines to learn from data and experience, continuously improving their
performance and adaptability. Natural Language Processing (NLP) technologies empower AI
systems to understand and generate human language, facilitating seamless communication
between humans and machines. Additionally, AI seeks to equip machines with perception
capabilities, enabling them to interpret and interact with the physical world autonomously.
Ultimately, AI's objectives converge to drive innovation, efficiency, and progress, shaping a
future where intelligent systems work in harmony with humans to solve complex problems
and enhance the quality of life for individuals and society as a whole.
Objective:
The objective of Artificial Intelligence (AI) is twofold: to create intelligent systems that can
automate tasks, enhance human capabilities, understand and reason with data, learn and adapt
over time, process natural language, perceive the environment, and operate autonomously. By
achieving these goals, AI aims to improve efficiency, solve complex problems, and ultimately
enhance the quality of life for individuals and society as a whole.
1. Write a program in C to implement DFS/BFS on water jug problem Given a 4-liter
jug filled with water & an empty 3-liter jug, how can one obtain exactly 2 liters in 4
liters jug. There is no measuring mark on any of them.
Source Code:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define MAX_QUEUE_SIZE 100
typedef struct
{
int j1;
int j2;
} Pair;
// Queue implementation for BFS
typedef struct
{
Pair data[MAX_QUEUE_SIZE];
int front;
int rear;
} Queue;
Output:
2. Write a program in C to calculate the heuristic value of the states for Blocks
World Problem as follows:
typedef struct
{
int id;
int support; // ID of the block this block is supported by
} Block;
Block blocks[MAX_BLOCKS];
int numBlocks;
int calculateHeuristic()
{
int heuristic = 0;
for (int i = 0; i < numBlocks; i++)
{
int correctSupport = (blocks[i].id - 1 + numBlocks) % numBlocks; //
Expected ID of supported block
int main()
{
// Initialize blocks with initial placement
numBlocks = 4;
blocks[0].id = 0;
blocks[0].support = 3; // Block b on the base
blocks[1].id = 1;
blocks[1].support = 0; // Block c on block b
blocks[2].id = 2;
blocks[2].support = 0; // Block d on block b
blocks[3].id = 3;
blocks[3].support = -1; // Block a on the base
return 0;
}
Output:
3. Write a program in C to implement steepest ascent hill climbing for 8-puzzle
problem. Develop appropriate heuristic function.
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
int initial_state[3][3] = {
{1, 2, 3},
{0, 4, 6},
{7, 5, 8}};
int goal_state[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}};
steepest_ascent_hill_climbing(initial_state, goal_state);
return 0;
}
Output:
4. Write a C program to calculate the heuristic value of the states for Tic-Tac-Toe
as follows:
Heuristic Function:
e(p)= No. of complete rows, columns or diagonals are still open for player) – (No.
of complete rows, columns or diagonals are still open for opponent)
Source Code:
#include <stdio.h>
// Check diagonals
if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) ||
(board[0][2] == player && board[1][1] == player && board[2][0] == player))
{
player_count++;
}
else if ((board[0][0] != player && board[1][1] != player && board[2][2] != player) ||
(board[0][2] != player && board[1][1] != player && board[2][0] != player))
{
opponent_count++;
}
int main()
{
char board[3][3] = {
{'X', ' ', 'O'},
{'O', 'X', ' '},
{'O', ' ', 'X'}};
char player = 'X'; // Assuming 'X' is the player symbol
return 0;
}
Output:
Output:
Conclusion:
Theory:
Machine Learning (ML):
Machine Learning is a field of artificial intelligence (AI) that focuses on developing
algorithms and techniques to enable computers to learn from data and improve
performance on specific tasks without being explicitly programmed. ML algorithms can
be broadly categorized into supervised learning, unsupervised learning, and reinforcement
learning. In supervised learning, algorithms learn from labeled data to make predictions
or classify new data points. Unsupervised learning algorithms identify patterns and
structures in unlabeled data, while reinforcement learning algorithms learn to make
decisions by interacting with an environment and receiving feedback in the form of
rewards or penalties.
Neural Networks (NNs):
Neural Networks are a class of machine learning models inspired by the structure and
function of the human brain. They consist of interconnected nodes organized into layers,
including an input layer, one or more hidden layers, and an output layer. Each node, or
neuron, applies a mathematical operation to its input and passes the result through an
activation function to produce an output. Through a process called backpropagation,
neural networks adjust the weights of connections between neurons during training to
minimize the difference between predicted and actual outputs. This enables neural
networks to learn complex patterns and relationships in data, making them effective for
tasks such as image recognition, natural language processing, and predictive modeling.
Objective:
Machine Learning (ML) and Neural Networks aim to develop algorithms and models that
learn from data to:
Predict future outcomes and classify data accurately.
Recognize patterns and structures in data for decision-making and insight generation.
Optimize model parameters to minimize errors or maximize performance.
Automate tasks and decision-making processes based on learned patterns.
Extract meaningful features from raw data and learn representations at multiple levels
of abstraction.
Approximate complex functions and adaptively improve performance over time.
Generalize well to unseen data and solve tasks efficiently in dynamic environments.
1. Write a program in C to Implement AND Gate.
Source Code:
#include <stdio.h>
int main()
{
int input1, input2;
// Validate input1
if (input1 != 0 && input1 != 1)
{
printf("Invalid input. Please enter 0 or 1.\n");
return 1; // Exit with error
}
// Validate input2
if (input2 != 0 && input2 != 1)
{
printf("Invalid input. Please enter 0 or 1.\n");
return 1; // Exit with error
}
Output:
2. Write a program in C to implement OR Gate.
Source Code:
#include <stdio.h>
int main()
{
int input1, input2;
// Validate input1
if (input1 != 0 && input1 != 1)
{
printf("Invalid input. Please enter 0 or 1.\n");
return 1; // Exit with error
}
// Validate input2
if (input2 != 0 && input2 != 1)
{
printf("Invalid input. Please enter 0 or 1.\n");
return 1; // Exit with error
}
Output:
int main()
{
int input1, input2;
// Validate input1
if (input1 != 0 && input1 != 1)
{
printf("Invalid input. Please enter 0 or 1.\n");
return 1; // Exit with error
}
// Validate input2
if (input2 != 0 && input2 != 1)
{
printf("Invalid input. Please enter 0 or 1.\n");
return 1; // Exit with error
}
return 0;}
Output:
4. Write a program in C to implement NOT Gate.
Source code:
#include <stdio.h>
int main()
{
int input;
// Validate input
if (input != 0 && input != 1)
{
printf("Invalid input. Please enter 0 or 1.\n");
return 1; // Exit with error
}
return 0;
}
Output:
Conclusion: