Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Heaven's Light is Our Guide

RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY


Department of Computer Science & Engineering
Lab Report

Course Code : CSE 2102


Course Name : Discrete Mathematics Sessional
Lab No : 01
Lab Subject : Propositional Logic
Date of Lab : 04 December 2023

Submitted by Submitted to
Md. Tamim Iqbal Suhrid Shakhar Ghosh
Roll : 2103094 Assistant Professor
Section : B Department of CSE
Series : 21 RUET

Date of Submission: 11 December 2023


Chapter 1: Logic & Proofs

Part I: Propositional Logic

Problem I: Generate A truth Table for all compound Propositions.

Code:
#include<bits/stdc++.h>
using namespace std;

int neg(int a){


return (!a);
}
int con(int a,int b){
return (a&b);
}
int dis(int a, int b){
return (a|b);
}
int imp(int a, int b){
if(a==0) return 1;
else {
if(b) return 1;
else return 0;
}
}
int bicnd(int p,int q){
return (con(imp(p,q),imp(q,p)));
}
int main(){
cout<<"p\t"<<"q\t"<<"!p\tp^q\tp|q\tp->q\tp<->q"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<i<<"\t"<<j<<"\t"<<neg(i)<<"\t"<<con(i,j)<<"\t"<<dis(i,j)<<"\t"<<
imp(i,j)<<"\t"<<bicnd(i,j)<<endl;
}
}
}
Output:

Analysis:
The provided C++ code generates a truth table for compound propositions
involving two Boolean variables, P and Q. It defines functions for negation,
conjunction, disjunction, implication, and biconditional operations. The main
function utilizes nested loops to systematically iterate through all possible
truth values for P and Q. The output is a well-formatted table presenting the
results of these logical operations.

This truth table serves as a valuable tool for examining the behavior of
compound propositions under diverse truth conditions. Through the concise
tabular format, the code effectively illustrates the logical relationships
between Boolean variables P and Q. In summary, the code provides a clear and
organized representation of the outcomes of different logical operations,
enhancing understanding of Boolean logic.

Problem II: Generate A truth Table to show Equivalent Propositions between


𝑃 → (𝑄 ∧ 𝑅) & (𝑃 → 𝑄) ∧ 𝑅
Code:
#include<bits/stdc++.h>
using namespace std;
int con(int a,int b){
return (a&b);
}
int dis(int a, int b){
return (a|b);
}
int imp(int a, int b){
if(a==0) return 1;
else {
if(b) return 1;
else return 0;
}
}

int main(){
bool ans=true;
cout<<"p\tQ\tR\tP->(Q^R)\t(P->Q)^R"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
int a=imp(i,con(j,k));
int b=con(imp(i,j),k);
cout<<i<<"\t"<<j<<"\t"<<k<<"\t "<<a<<"\t\t
"<<b<<endl;
if(a!=b) ans=false;
}
}
}
if(ans) cout<<"YES"<<endl;
else cout<<"NO"<<endl;

}
Output:
Analysis:
This C++ code generates a truth table for compound propositions
involving three Boolean variables P, Q, and R. It evaluates the
expressions P->(Q^R) and (P->Q)^R for all possible truth values of P,
Q, and R, and then checks if the two expressions always produce the
same result.

You might also like