You are on page 1of 43

TRIBHUVAN UNIVERSITY

EVEREST INNOVATIVE
COLLEGE
 SOALTEEMODE, KATHMANDU

NEPAL

LAB NO: 1
LAB REPORT TO CONSTRUCT SWI PROLOG PROGRAM TO REPRESENT THE
RAMAYAN FAMILY TREE
Date:- 2079/9/8  

Submitted By:                                       Submitted To:

Name: Apeksha Kafle       Department of BCA

Roll No: 1                                       Sujan Shrestha

Faculty: Humanities

Year/Part: VII
TITLE: LAB REPORT TO CONSTRUCT SWI PROLOG PROGRAM TO REPRESENT
THE RAMAYAN FAMILY TREE
OBJECTIVE:
1. To prove relations among various family members of Ramayan.
THEORY:
The prolog family tree, defined as the prolog, is a logical programming language with symbolic
and non-numeric data processing. It is especially well suited for solving problems that require
objects and relationships between the objects. It is a user-friendly programming language
because it uses logic in its programming, prolog family trees can be constructed by using the
facts, rules, and queries, collection of facts and rules is called a knowledge-base, which describe
the relationship of their objects. The prolog programming is all about knowledge- base and by
posing queries means by asking questions to prolog about the information stored in knowledge-
base.
The program in prolog specifies the relationship between objects and the properties of objects;
the family trees tell us how to construct a database of family. There are many types of
relationships; some of them are ruled by using rules in the program, we can find the relationship
between objects used, and it is not defined as a fact. Tree diagrams are very good in
representations the information is clearly mentioned, and due to that, users can understand easily,
our programs in prolog are the sets of clauses.
SOURCE CODE:
OUTPUT:

DISCUSSION:
Swi Prolog was launched on our laptop. We wrote the family tree's source code using the
Ramayan as our guide. To produce the desired results, the source code was first compiled and
then ran. There were no mistakes in our code, which was correct. The outcome, which was in our
favor, also came to pass. By employing codes in Swi Prolog, we were able to portray the
hierarchical tree of the Ram family in this manner. Assigning the relationships between various
Ramayan relatives allowed us to determine whether or not other relationships between certain
Ram family members were real.
CONCLUSION:
Hence, we constructed family tree of Ramayan using Swi prolog program.
TRIBHUVAN UNIVERSITY
EVEREST INNOVATIVE
COLLEGE
 SOALTEEMODE, KATHMANDU

NEPAL

LAB NO: 2
LAB REPORT TO CONSTRUCT SWI PROLOG PROGRAM TO REPRESENT THE
FAMILY TREE
Date:- 2079/9/8  

Submitted By:                                       Submitted To:

Name: Apeksha Kafle       Department of BCA

Roll No: 1                                       Sujan Shrestha

Faculty: Humanities

Year/Part: VII
TITLE: LAB REPORT TO CONSTRUCT SWI PROLOG PROGRAM TO REPRESENT
THE FAMILY TREE
OBJECTIVE:
1. To prove relations among various family members
THEORY:
The prolog family tree, defined as the prolog, is a logical programming language with symbolic
and non-numeric data processing. It is especially well suited for solving problems that require
objects and relationships between the objects. It is a user-friendly programming language
because it uses logic in its programming, prolog family trees can be constructed by using the
facts, rules, and queries, collection of facts and rules is called a knowledge-base, which describe
the relationship of their objects. The prolog programming is all about knowledge- base and by
posing queries means by asking questions to prolog about the information stored in knowledge-
base.
The program in prolog specifies the relationship between objects and the properties of objects;
the family trees tell us how to construct a database of family. There are many types of
relationships; some of them are ruled by using rules in the program, we can find the relationship
between objects used, and it is not defined as a fact. Tree diagrams are very good in
representations the information is clearly mentioned, and due to that, users can understand easily,
our programs in prolog are the sets of clauses.
SOURCE CODE:
OUTPUT:

DISCUSSION: Swi Prolog was launched on our laptop. The family tree's source code was
created by us. To produce the desired results, the source code was first compiled and then ran.
There were no mistakes in our code, which was correct. The outcome, which was in our favor,
also came to pass. We used codes in Swi Prolog to portray the hierarchical tree of our family in
this way. We allocated the relationships between the various individuals and used the data to
determine whether or not other relationships held true.
CONCLUSION: Hence, we constructed family tree using Swi prolog program.

TRIBHUVAN UNIVERSITY
EVEREST INNOVATIVE
COLLEGE
 SOALTEEMODE, KATHMANDU

NEPAL
LAB NO: 3
LAB REPORT ON RESOLUTION
Date:- 2079/9/5

Submitted By:                                       Submitted To:

Name: Apeksha Kafle       Department of BCA

Roll No: 1                                       Sujan Shrestha

Faculty: Humanities

Year/Part: VII

TITLE: LAB REPORT ON RESOLUTION

OBJECTIVE:

1. To convert given problem to CNF, FOL and resolution graph and solve the problem.
2. To use prolog to solve resolution problem.

THEORY: Resolution method is an inference rule which is used in both Propositional as well as
First-order Predicate Logic in different ways. This method is basically used for proving the
satisfy ability of a sentence. In resolution method, we use Proof by Refutation technique to prove
the given statement.

The key idea for the resolution method is to use the knowledge base and negated goal to obtain
null clause (which indicates contradiction). Resolution method is also called Proof by Refutation.
Since the knowledge base itself is consistent, the contradiction must be introduced by a negated
goal. As a result, we have to conclude that the original goal is true.
Steps to perform resolution

 Convert given facts into FOL


 Convert FOL into CNF
 Negate the statement to be proved.
 Draw Resolution Graph.

Solution 1:

1. Cats like fish

2. Cat eat everything they like.

3. Upsa is a cat.

To prove upsa eat’s fish.

Step 1: Convert statement into FOL

1. x:cat(x) → like (x, fish)

2.  x [ y(cat (x)) ^ like ( x, y) → eat (x, y)]

3. cat (Upsa)

Step 2: Convert FOL to CNF

1. ¬ cat (x)  like (x, fish)

2. ¬ ((cat (x)) ^ like ( x, y))  eat (x, y)

¬ cat (x)  ¬ like (x,y)  eat (x, y)

3. cat (Upsa)

Step 3: Negate the question

¬ eat (Uspa, fish)


SOURCE CODE:
OUTPUT:

DISCUSSION AND CONCLUSION: In order to demonstrate the above claim, we have


learned how to describe the given scenario's lines in FOL and CNF as well as how to construct a
resolution graph. By uploading the CNF of the lines of scenarios on the right format of
conclusion then procedure, we learned how to utilize prolog to prove the supplied statement.
Predicate, relation, and object in the aforementioned query are maintained as eat(upsa, fish), and
the CNF is written as cat if the object has just one character (upsa). The preset assertion that was
supposed to be proven is then produced by the contradicting claims.

As a result, with the aid of the Proof by Contradiction/resolution approach, we have


accomplished the stated objective. It is therefore established that upsa eats fish.
Solution 2:

1. Everyone passing the exam and winning the lottery is happy.

2. Everyone who studies or lucky can pass the exam.

3. Ram didn't study but he is lucky.

4. Everyone who is lucky wins the lottery.

To prove Ram is happy

Step 1: Convert statement into FOL

1.  x : (pass (x, exam)) ^ win (x, lottery)) → happy(x)

2.  x : (study (x)  lucky (x)) → pass(x, exam)

3. ¬study (Ram) ^ lucky (ram)

4.  x : lucky (x) → wins (x, lottery)

Step 2: Step 2 Converting FOL into CNF

1. ¬ pass (x, exam)  ¬ win (x, lottery)  happy (x)

2. (¬ study (x) ^ ¬lucky (x))  pass (x, exam)

(¬ study (x)  pass (x, exam)) ^

(¬ lucky (x)  pass (x, exam))

i) ¬ study (x) pass (x, exam)

ii) ¬ lucky (x)  pass (x, exam)

3. i) ¬ study (Ram)

ii) lucky (Ram)

4. ¬lucky (x)  win (x, lottery)


Step 3:

¬happy (Ram)
Resolution Graph:

SOURCE CODE:

OUTPUT:
DISCUSSION AND CONCLUSION: We have learned to define the supplied scenario's lines
in FOL and CNF and to create a resolution graph in order to demonstrate the claimed statement.
We discovered how to use prolog to support the given claim by publishing the CNF of the
scenario's lines on the appropriate conclusion and method structure. In the preceding sentence,
the conditions are for the person to pass the exam and for the person to win the lottery, and the
conclusion is that the person is happy. The condition is that the candidate studies and is
fortunate, and the result is that the candidate passes the exam. Similar to how the lottery winner
is the conclusion, being lucky is the condition.

As a result, with the aid of the Proof by Contradiction/resolution approach, we have


accomplished the stated objective. So it is established that the ram is content.
Solution 3:

a) Ravi likes all kind of food.

b) Apple and chicken are food.

c) Anything anyone eats and is not killed is food.

d) Ajay eats peanuts and still alive.

e) Rita eats that Ajay eats.

To prove ravi likes peanuts.

Step 1: Convert statement into FOL

a.  X : food(x) → likes(Ravi,x)
b. Food (apple)
Food (chicken)
c.  y [ x : eats(y, x) ∧ Ꞁ killed(y) food(x)]
 y [ x : eats(y, x) ∧ alive(y) → food(x)]
d. Eats(ajay, peanuts) ∧ alive (ajay)
e.  X :Eats(Ajay, x) → eats(Rita,x)

Step 2: Converting FOL into CNF

a. Ꞁ food(x) V likes(Ravi,x)
b. Food (apple) Food (chicken)
c. Ꞁ eats(y,x) V Ꞁ alive(y) V food(x)
d. Eats(ajay, peanuts)
alive (ajay)
e. Ꞁ Eats(Ajay, x) V eats(Rita,x)

Step 3: Negate to prove statement.

Ꞁ Likes(Ravi, Peanuts)
Resolution Graph:

SOURCE CODE:

OUTPUT:

DISCUSSION AND CONCLUSION: We have studied the technique of transforming the given
scenario lines to FOL, CNF, and resolution graphs in order to logically support the offered
statement. We learned how to use prolog to validate the given statement by uploading the CNF
of the lines of scenario-based scenarios on the proper structure of conclusion and procedure. In
the solution above predicate, relation and object are retained like eat(ajay, peanuts) (ajay,
peanuts). Additionally, the CNF is written as alive(ajay), food(apple), food if the item only
contains one character (chicken). Furthermore, if X is a food, ravi enjoys X. X must be a food if
Y guys consume it and Y men are alive. Ajay consumes X if Rita does, too.

Hence, we have achieved the given goal with the help of Proof by Contradiction/ resolution
method. Thus, it is proved that ravi likes peanuts.
TRIBHUVAN UNIVERSITY
EVEREST INNOVATIVE
COLLEGE
 SOALTEEMODE, KATHMANDU

NEPAL

LAB NO: 4
LAB REPORT TO SOLVE THE GIVEN CRYPT-ARITHMETIC PROBLEMS
Date:- 2079/9/8  

Submitted By:                                       Submitted To:

Name: Apeksha Kafle       Department of BCA

Roll No: 1                                       Sujan Shrestha

Faculty: Humanities

Year/Part: VII
TITLE: SOLVE THE GIVEN CRYPT-ARITHMETIC PROBLEM: LOGIC + LOGIC =
PROLOG SIXTY USING PROLOG.

OBJECTIVES:

i. To understand crypt-arithmetic problem.


ii. To solve given problem using prolog.

THEORY:

Crypt-Arithmetic Problem is a type of Constraint Satisfactory problem in Artificial Intelligence.


The crypt-arithmetic problem deals with the converting of the message from the readable plain
text to the non-readable cipher text. The problem can be solved using following rules:

i. First letter must be non-zero.


ii. Each variable must be unique.
iii. Carry over must be taken into account if Nothing is mentioned.
iv. Need to be careful about symbol of the operation.

The given problem is: LOGIC + LOGIC = PROLOG

The given constraint is:

i. Set of variables, X = {L, O, G, I, C, P, R}.


ii. Set of domain, D = {0,1,2,3,4,5,6,7,8,9}.
iii. The given problem can be written as:
a) C + C = 10 * C1 + G
b) I + I + C1= 10 * C2 + O
c) G + G + C2=10 * C3 + L
d) O + O + C3 = 10 * C4 + O
e) L + L + C4 = 10 * C5 + R
f) C5 = 10 * C6 + P

SOURCE CODE:

digit (0).
digit (1).
digit (2).
digit (3).
digit (4).
digit (5).
digit (6).
digit (7).
digit (8).
digit (9).

solution(A): - digit(L), L>0, digit(O), digit(G), digit(I), digit(C), digit(P), P>0, digit(R),
10000*L+1000*O+100*G+10*I+C+10000*L+1000*O+100*G+10*I+C =: =
100000*P+10000*R+1000*O+100*L+10*O+G,
A= [L, O, G, I, C, P, R],
different(A).
different ([]).
different([X|R]): -not (member (X, R)), different(R).

OUTPUT:

DISCUSSION:

We learned to represent the given set of problem in prolog program. Every alphabet is assigned
with unique digits from 0 to 9. The given crypt-arithmetic problem is solved by passing a set of
list containing the alphabets. Then we got the result as: L = 9, O = 0, G = 4, I = 5, C = 2, P = 1, R
= 8.

LOGIC + LOGIC = PROLOG : 9041 + 9041 = 180904

CONCLUSION

Hence, we solved the given crypt-arithmetic using prolog.


TITLE: SOLVE THE GIVEN CRYPT-ARITHMETIC PROBLEM: WRONG + WRONG
= RIGHT USING PROLOG.

OBJECTIVES:

i. To understand crypt-arithmetic problem.


ii. To solve given problem using prolog.

THEORY:

Crypt-Arithmetic Problem is a type of Constraint Satisfactory problem in Artificial Intelligence.


The crypt-arithmetic problem deals with the converting of the message from the readable plain
text to the non-readable cipher text. The problem can be solved using following rules:

i. First letter must be non-zero.


ii. Each variable must be unique.
iii. Carry over must be taken into account if Nothing is mentioned.
iv. Need to be careful about symbol of the operation.

The given problem is: WRONG + WRONG = RIGHT

The given constraint is:

i. Set of variables, X = {W, R, O, N, G, I, H, T}.


ii. Set of domain, D = {0,1,2,3,4,5,6,7,8,9}.
iii. The given problem can be written as:
a) G + G = 10 * C1 + T
b) N + N + C1= 10 * C2 + H
c) O + O + C2=10 * C3 + G
d) R + R + C3 = 10 * C4 + I
e) W + W + C4 = 10 * C5 + R

SOURCE CODE:

digit (0).
digit (1).
digit (2).
digit (3).
digit (4).
digit (5).
digit (6).
digit (7).
digit (8).
digit (9).
solution(Y): -digit(W), W>0, digit(O), digit(N), digit(G), digit(R), R>0, digit(I), digit(H),
digit(T), 10000*W+1000*R+100*O+10*N+G+10000*W+1000*R+100*O+10*N+G =: =
10000*R+1000*I+100*G+10*H+T,
Y= [W, R, O, N, G, I, H, T],
different(Y).
different ([]).
different([X|R]): -not (member (X, R)), different(R).

OUTPUT:
DISCUSSION:

We learned to represent the given set of problem in prolog program. Every alphabet is assigned
with unique digits from 0 to 9. The given crypt-arithmetic problem is solved by passing a set of
list containing the alphabets. Then we got the result as:

 Twenty-one different unique solutions to this problem.


 WRONG + WRONG = RIGHT: 49306 + 49306 = 98312

CONCLUSION

Hence, we solved the given crypt-arithmetic using prolog.


TITLE: SOLVE THE GIVEN CRYPT-ARITHMETIC PROBLEM: SEND + MORE =
MONEY USING PROLOG.

OBJECTIVES:

i. To understand crypt-arithmetic problem.


ii. To solve given problem using prolog.

THEORY:

Crypt-Arithmetic Problem is a type of Constraint Satisfactory problem in Artificial Intelligence.


The crypt-arithmetic problem deals with the converting of the message from the readable plain
text to the non-readable cipher text. The problem can be solved using following rules:

i. First letter must be non-zero.


ii. Each variable must be unique.
iii. Carry over must be taken into account if Nothing is mentioned.
iv. Need to be careful about symbol of the operation.

The given problem is: SEND + MORE = MONEY

The given constraint is:

i. Set of variables, X = {S, E, N, D, M, O, R, N, Y}.


ii. Set of domain, D = {0,1,2,3,4,5,6,7,8,9}.
iii. The given problem can be written as:
f) D + E = 10 * C1 + Y
g) N + R + C1= 10 * C2 + E
h) E + O + C2=10 * C3 + N
i) S + M + C3 = 10 * C4 + O
j) C4 = 10 * C5 + M

SOURCE CODE:

digit (0).
digit (1).
digit (2).
digit (3).
digit (4).
digit (5).
digit (6).
digit (7).
digit (8).
digit (9).
solution(L): -digit(S), S>0, digit(E), digit(N), digit(D), digit(M), M>0, digit(O), digit(R),
digit(Y), 1000*S+100*E+10*N+D+1000*M+100*O+10*R+E =: =
10000*M+1000*O+100*N+10*E+Y,
L= [S, E, N, D, M, O, R, Y],
different(L).
different ([]).
different([X|R]): -not (member (X, R)), different(R).
OUTPUT:

DISCUSSION:

We learned to represent the given set of problem in prolog program. Every alphabet is assigned
with unique digits from 0 to 9. The given crypt-arithmetic problem is solved by passing a set of
list containing the alphabets. Then we got the result as: S = 9, E = 5, N = 6, D = 7, M = 1, O = 0,
R = 8, Y = 2.

SEND + MORE = MONEY: 9567 + 1085 = 10652

CONCLUSION

Hence, we solved the given crypt-arithmetic using prolog.


TITLE: SOLVE THE GIVEN CRYPT-ARITHMETIC PROBLEM: BASE + BALL =
GAMES USING PROLOG.

OBJECTIVES:

i. To understand crypt-arithmetic problem.


ii. To solve given problem using prolog.

THEORY:

Crypt-Arithmetic Problem is a type of Constraint Satisfactory problem in Artificial Intelligence.


The crypt-arithmetic problem deals with the converting of the message from the readable plain
text to the non-readable cipher text. The problem can be solved using following rules:

i. First letter must be non-zero.


ii. Each variable must be unique.
iii. Carry over must be taken into account if Nothing is mentioned.
iv. Need to be careful about symbol of the operation.

The given problem is: BASE + BALL = GAMES

The given constraint is:

i. Set of variables, X = {B, A, S, E, L, G, M}.


ii. Set of domain, D = {0,1,2,3,4,5,6,7,8,9}.
iii. The given problem can be written as:
k) E+ L = 10 * C1 + S
l) S + L + C1= 10 * C2 + E
m) A + A + C2=10 * C3 + M
n) B + B + C3 = 10 * C4 + A
o) C4 = 10 * C5 + G

SOURCE CODE:

digit (0).
digit (1).
digit (2).
digit (3).
digit (4).
digit (5).
digit (6).
digit (7).
digit (8).
digit (9).

solution(L): -digit(B), B>0, digit(A), digit(S), digit(E), digit(L), digit(G), G>0, digit(M),
1000*B+100*A+10*S+E+1000*B+100*A+10*L+L =: = 10000*G+1000*A+100*M+10*E+S,
L= [B, A, S, E, L, G, M],
different(L).
different ([]).
different([X|R]): -not (member (X, R)), different(R).
OUTPUT:

DISCUSSION:

We learned to represent the given set of problem in prolog program. Every alphabet is assigned
with unique digits from 0 to 9. The given crypt-arithmetic problem is solved by passing a set of
list containing the alphabets. Then we got the result as: B = 7, A =4, S = 8, E = 3, L = 5, G = 1,
M=9

BASE + BALL = GAMES : 7483+ 7455 = 14938

CONCLUSION

Hence, we solved the given crypt-arithmetic using prolog.


TRIBHUVAN UNIVERSITY
EVEREST INNOVATIVE
COLLEGE
 SOALTEEMODE, KATHMANDU

NEPAL

LAB NO: 5
LAB REPORT TO CONSTRUCT BREADTH FIRST SEARCH ALGORITHM
Date:- 2079/9/8  

Submitted By:                                       Submitted To:

Name: Apeksha Kafle       Department of BCA

Roll No: 1                                       Sujan Shrestha

Faculty: Humanities

Year/Part: VII
TITLE: LAB REPORT TO CONSTRUCT BREADTH FIRST SEARCH ALGORITHM
OBJECTIVE:
1. To search elements using BFS algorithm
THEORY:
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data
structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a
‘search key’), and explores all of the neighbor nodes at the present depth prior to moving on to
the nodes at the next depth level. It is implemented using a queue.

For example, after searching A, then B, then C, the search proceeds with D,E,F,G.
Algorithm : Breadth first search (Graph G, Souce_Vertex S)

1.    Create a queue Q to store the vertices.


2.    Push the source vertex S in the queue Q.
3.    Mark S as visited.
4.    While the queue Q is not empty
5.    Remove vertex U from the front of the queue. i.e Vertex U = Q.front(), Q.pop()
6.    For every vertex V adjacent to the vertex U
7.    If the vertex V is not visited Then
8.    Explore the vertex V and mark V as visited.
9.    Push the vertex V in the queue Q.
SOURCE CODE:

OUTPUT:

DISCUSSION:
We opened JupyterLab to run the source code of BFS algorithm. We run the source code in the
application. The result came out in our favor. We got to learn the process of breadth first search
practically.
CONCLUSION:
Hence, we searched the elements using BFS algorithm.
TRIBHUVAN UNIVERSITY
EVEREST INNOVATIVE
COLLEGE
 SOALTEEMODE, KATHMANDU

NEPAL

LAB NO: 6
LAB REPORT TO CONSTRUCT DEPTH FIRST SEARCH ALGORITHM
Date:- 2079/9/5  

Submitted By:                                       Submitted To:

Name: Apeksha Kafle       Department of BCA

Roll No: 1                                       Sujan Shrestha

Faculty: Humanities

Year/Part: VII
TITLE: LAB REPORT TO CONSTRUCT DEPTH FIRST SEARCH ALGORITHM
OBJECTIVE:
1. To search elements using DFS algorithm
THEORY:
DFS is known as the Depth First Search Algorithm which provides the steps to traverse each and
every node of a graph without repeating any node. This algorithm is the same as Depth First
Traversal for a tree but differs in maintaining a Boolean to check if the node has already been
visited or not. This is important for graph traversal as cycles also exist in the graph. A stack is
maintained in this algorithm to store the suspended nodes while traversal. It is named so because
we first travel to the depth of each adjacent node and then continue traversing another adjacent
node.

Algorithm :

1. Initiate an empty stack for size of total number nodes, S.


2. For each vertex V, define V visited to be false.
3. Push the first node to be visited onto Stack S.
4. While S is not empty:
Pop the first element in S, V.
If V.visited = false, then:
V.visited = true
for each unvisited neighbor w of V:
Push w into S.
5. End process when all nodes have been visited.
SOURCE CODE:

OUTPUT:

DISCUSSION:
We opened JupyterLab to run the source code of DFS algorithm. We wrote the source code and
run the source code in the application. The result came out in our favor. We got to learn the
process of depth first search practically. Our objective of searching elements through depth first
search was met.
CONCLUSION:
Hence, we searched the elements using BFS algorithm.
TRIBHUVAN UNIVERSITY
EVEREST INNOVATIVE
COLLEGE
 SOALTEEMODE, KATHMANDU

NEPAL

LAB NO: 7
LAB REPORT TO CONSTRUCT HEBB NET AND PERCEPTRON WHICH
PERFORMS AND, OR, NAND and NOR FUNCTIONS
Date:- 2079/9/8

Submitted By:                                       Submitted To:

Name: Apeksha Kafle       Department of BCA

Roll No: 1                                       Sujan Shrestha

Faculty: Humanities

Year/Part: VII
TITLE: LAB REPORT TO CONSTRUCT HEBB NET AND PERCEPTRON WHICH
PERFORMS AND FUNCTIONS
OBJECTIVE:
i. To construct the Hebb net which performs AND function.
ii. To construct the Perceptron which performs AND function.
THEORY:
A neural network is a series of algorithms that endeavors to recognize underlying relationships
in a set of data through a process that mimics the way the human brain operates. In this sense,
neural networks refer to systems of neurons, either organic or artificial in nature.
Types
1. Feed-forward Neural Network
In this type of network information are processed in only forward direction. Eg., McCulloch and
Pitts NN, hebbian NN, Perceptron NN
2. Feed-back Neural Network
In this type of neural network information after calculating in forward direction, updated with
error in backward direction. Eg., back propagation NN
Hebbian Neural Network
The oldest and most famous of all learning rules is Hebb’s postulate of learning:
Hebb’s Algorithm
Step 0: Initialize all weights to 0
Step 1: Given a training input(s) with its target output(t)set the activations of the input units: xi =
si
Step 2: Set the activation of the output unit to the target value: y = t from training set.

Step 3: Adjust the weights: wi (new) = wi(old) + xi  y  Step 4: Adjust the bias: b(new) =
b(old) + y
Step 5: Continue until all the conditions are satisfied. Use the testing criteria to validate the
weight obtained.
Perceptron
The perceptron was suggested by Rosenblatt in 1958. It uses an iterative learning procedure
which can be proven to converge to the correct weights for linearly separable data. It has a bias
and a threshold function Θ
Perceptron Learning Rule
Weights are changed only when an error occurs. The weights are updated using the following
algorithm:
Step 0: Initialize all weights and bias randomly.
Step 1: Given a training input(s) with its target output(t) set the activations of the input units: xi
= si
Step 2: Set the activation of the output unit to the target value: y = t from training set.

Step 3: Adjust the weights: Wi (new) = Wi (old) + α  t  Xi where α is learning rate, which is
taken normally 0.1 for gate realization. If the training set increase, we take α using relation 0.01
< n α < 1 t is either +1 or -1 Xi is input

Step 4: Adjust the bias: b(new) = b(old) + α  y

Step5: Continue until all the conditions are satisfied. If an error does not occur, the weights
aren’t changed. We test the error using the formula  X1  W1 + X2  W2 +b > T 

Perceptron can work for linearly separable functions like AND, OR, NOT, NAND, NOR etc
AND Truth Table
Logical conjunction is an operation on two logical values, typically the values of
two propositions, that produces a value of true if both of its operands are true.
The truth table for p AND q (also written as p ∧ q, Kpq, p & q, or p q) is as follows:
SOURCE CODE
OUTPUT

DISCUSSION
In this lab, we have learnt to construct the Hebb net which performs like an AND function. We
also learnt to construct the perceptron which performs like an AND function. For AND
operation, the output is True only if both the input values are true, else the output will be false.
The AND operator is denoted by the symbol (∧). We used Jupyter lab and wrote source code to
generate output. And we received the required output.
CONCLUSION
Hence, we performed AND function by constructing Hebb net and perceptron.
TITLE: LAB REPORT TO CONSTRUCT HEBB NET AND PERCEPTRON WHICH
PERFORMS OR FUNCTIONS
OBJECTIVE:
i. To construct the Hebb net which performs OR function.
ii. To construct the Perceptron which performs OR function.
THEORY:
OR Truth Table
Logical disjunction is an operation on two logical values, typically the values of
two propositions, that produces a value of true if at least one of its operands is true.
The truth table for p OR q (also written as p ∨ q, Apq, p || q, or p + q) is as follows:

SOURCE CODE:
OUTPUT

DISCUSSION
In this lab, we discussed to construct the Hebb net which performs like an OR function. We also
discussed to construct the perceptron which perform like an OR function. OR statement states
that if any of the two input values are True, the output result is TRUE always. It is represented
by the symbol (∨). We used Jupyter lab and wrote source code to generate output. And we
received the required output.  
CONCLUSION
Hence, we performed OR function by constructing Hebb net and perceptron.
TITLE: LAB REPORT TO CONSTRUCT HEBB NET AND PERCEPTRON WHICH
PERFORMS NAND FUNCTIONS
OBJECTIVE
i. To construct the Hebb net which performs NAND function.
ii. To construct the Perceptron which performs NAND function.
THEORY
NAND Truth Table
The logical NAND is an operation on two logical values, typically the values of
two propositions, that produces a value of false if both of its operands are true. In other words, it
produces a value of true if at least one of its operands is false.
The truth table for p NAND q (also written as p ↑ q, Dpq, or p | q) is as follows:

SOURCE CODE
OUTPUT

DISCUSSION
In this lab, we discussed to construct the Hebb net which performs like an NAND function. We
also discussed to construct the perceptron which perform like an NAND function. NAND
statement states that produces a value of false if both of its operands are true. In other words, it
produces a value of true if at least one of its operands is false.
CONCLUSION
Hence, we performed NAND function by constructing Hebb net and perceptron.
TITLE: LAB REPORT TO CONSTRUCT HEBB NET AND PERCEPTRON WHICH
PERFORMS NOR FUNCTIONS
OBJECTIVE
i. To construct the Hebb net which performs NOR function.
ii. To construct the Perceptron which performs NOR function.
THEORY
NOR Truth Table
The logical NOR is an operation on two logical values, typically the values of two propositions,
that produces a value of true if both of its operands are false. In other words, it produces a value
of false if at least one of its operands is true. ↓ is also known as the Peirce arrow after its
inventor, Charles Sanders Peirce, and is a Sole sufficient operator.
The truth table for p NOR q (also written as p ↓ q, or Xpq) is as follows:

SOURCE CODE
OUTPUT

DISCUSSION
In this lab, we discussed to construct the Hebb net which performs like an NOR function. We
also discussed to construct the perceptron which perform like an NOR function. NOR statement
states that it produces a value of true if both of its operands are false. In other words, it
produces a value of false if at least one of its operands is true. We used Jupyter lab and
wrote source code to generate output. And we received the required output.  
CONCLUSION
Hence, we performed NOR function by constructing Hebb net and perceptron.

You might also like