Lab After 15
Lab After 15
Date:2023/10/07
Title: WAP in C/C++ to find the meet of two Boolean matrices.
Boolean matrix:
In mathematics, a Boolean matrix is a matrix with entries from a Boolean algebra. When the two-element
Boolean algebra is used, the Boolean matrix is called a logical matrix. (In some contexts, particularly computer
science, the term "Boolean matrix" implies this restriction.)
Let U be a non-trivial Boolean algebra (i.e., with at least two elements). Intersection, union, complementation,
and containment of elements are expressed in U. Let V be the collection of n × n matrices that have entries taken
from U. Complementation of such a matrix is obtained by complementing each element. The intersection or
union of two such matrices is obtained by applying the operation to entries of each pair of elements to obtain the
corresponding matrix intersection or union. A matrix is contained in another if each entry of the first is
contained in the corresponding entry of the second.
Boolean matrix:
In mathematics, a Boolean matrix is a matrix with entries from a Boolean algebra. When the two-element
Boolean algebra is used, the Boolean matrix is called a logical matrix. (In some contexts, particularly computer
science, the term "Boolean matrix" implies this restriction.)
Let U be a non-trivial Boolean algebra (i.e., with at least two elements). Intersection, union, complementation,
and containment of elements are expressed in U. Let V be the collection of n × n matrices that have entries taken
from U. Complementation of such a matrix is obtained by complementing each element. The intersection or
union of two such matrices is obtained by applying the operation to entries of each pair of elements to obtain the
corresponding matrix intersection or union. A matrix is contained in another if each entry of the first is
contained in the corresponding entry of the second.
Output:
Lab no: 17 Date: 2023/09/11
Title: WAP in C/C++ to construct the truth table of Conjunction.
Conjunction:
The conjunction can be described as a statement, which can be formed by adding two statements with the help of
connector AND. The symbol ∧ is used for the conjunction. We can read this symbol as "and". If two statements,
x, and y are joined in a statement, then the conjunction can be indicated symbolically in the form of x ∧ y. This
statement will be true when both the combined statements are true. In all the other cases, it will be false. The
conjunction of x and y is shown in the following image:
Language: C
Source Code:
#include <stdio.h>
int conjunction(int a, int b) // Function to compute the conjunction (logical AND) of two Boolean values
{
return a && b;
}
int main()
{
int a, b;
printf("Truth Table for Conjunction (AND):\n");
printf("a\tb\ta AND b\n");
printf("-----------------\n");
for (a = 0; a <= 1; a++) // Loop through all possible combinations of a and b (0 and 1)
{
for (b = 0; b <= 1; b++)
{
int result = conjunction(a, b); // Compute the result of a AND b
printf("%d\t%d\t%d\n", a, b, result); // Display the values and result
}
}
return 0;
}
Output:
Lab no: 18 Date: 2023/09/11
Title: WAP in C/C++ to construct the truth table of Disjunction.
Disjunction:
A disjunction statement of p and q is written as 𝑃 V 𝑄 .This means p or q. Statements p and q have either a
true or false value. To evaluate if a disjunction statement is true, either one or both statements need to be true. In
other words, either p or q is true. The truth values of p q are listed in the truth table below:
Output:
Lab no: 19 Date: 2023/09/11
Title: WAP in C/C++ to construct the truth table of Implication.
Implication:
An implication statement can be represented in the form "if.... then". The symbol ⇒ is used to show the
implication. Suppose there are two statements, P and Q. In this case, the statement "if P then Q" can also be
written as P ⇒ Q or P → Q, and it will be read as "P implies Q". In this implication, the statement P is a hypothesis,
which is also known as premise and antecedent, and the statement Q is conclusion, which is also known as the
consequent. The truth table of the statement "if P then Q" is described as follows:
Language: C
Source Code:
#include <stdio.h>
int implication(int a, int b) // Function to compute the implication operation
{
return (!a) || b;
}
int main()
{
int a, b;
printf("Truth Table for Implication (->):\n");
printf("A\tB\tA -> B\n");
for (a = 0; a <= 1; a++) // Loop through all possible values of A and B (0 or 1)
{
for (b = 0; b <= 1; b++)
{
printf("%d\t%d\t%d\n", a, b, implication(a, b));
}
}
return 0;
}
Output:
Lab no: 20 Date: 2023/09/11
Title: WAP in C/C++ to check the validity of arguments using truth tables.
Truth table:
A truth table is a breakdown of all the possible truth values returned by a logical expression. A truth value is
typically either true or false, or 1 or 0. In some cases, the value might be based on another binary system, such as
on and off or open and closed, but these are not as common. Truth tables are used in Boolean algebra and in other
areas of mathematics and science that rely on Boolean logic to show the possible outcomes of an expression or
operation in terms of its truth or falseness.
Output:
Lab no: 21 Date: 2023/09/11
Title: WAP in C/C++ to represent graph.
Graph:
A graph is a pictorial representation of any data in an organized manner. The graph shows the relationship
between variable quantities. In graph theory, the graph represents the set of objects that are related in some
sense to each other. The objects are basically mathematical concepts, expressed by vertices or nodes and the
relation between the pair of nodes, are expressed by edges. Formally, a graph is denoted as a pair G(V, E).
Where V represents the finite set vertices and E represents the finite set edges.
Therefore, we can say a graph includes non-empty set of vertices V and set of edges E.
Compiler: Dev C++
Language: C++
Source Code:
#include <iostream>
#include <vector>
class Graph
private:
public:
Graph(int vertices)
V = vertices;
adjList.resize(V);
void addEdge(int v1, int v2) // Function to add an edge to the graph
adjList[v1].push_back(v2);
};
int main()
g.addEdge(0, 2);
g.addEdge(1, 3);
g.addEdge(2, 3);
g.addEdge(3, 4);
return 0;
}
Output:
Lab no: 22 Date: 2023/09/11
Title: WAP in C/C++ to check if the input relation is Equivalence relation or not.
Equivalence Relation:
An equivalence relation is a kind of binary relation that should be reflexive, symmetric and transitive. The well-
known example of an equivalence relation is the “equal to (=)” relation. In other words, two elements of the
given set are equivalent to each other if they belong to the same equivalence class. A relation R on a set A is
said to be an equivalence relation if and only if the relation R is reflexive, symmetric and transitive. The
equivalence relation is a relationship on the set which is generally represented by the symbol “∼”.
Language: C
Source Code:
#include <iostream>
#include <vector>
#include <set>
found = true;
break;
if (!found)
return false;
return true;
if (pair.first != pair.second)
found = true;
break;
if (!found)
return false;
return true;
if (pair1.second == pair2.first)
found = true;
break;
if (!found)
return false;
return true;
int main()
{
int n;
cin >> n;
cout << "Enter the pairs of related elements (Enter -1 to stop):" << endl;
while (true)
int a, b;
cin >> a;
if (a == -1)
break;
cin >> b;
relation.push_back(make_pair(a, b));
if (isEquivalence)
else
cout << "The given relation is not an equivalence relation." << endl;
}
return 0;
Output: