P
Protoman
I'm writing a program to calc truth tables of arguments to prove that
they are logically valid. Currently, I have to tell the program to
print a truth table, and check it by hand to prove it's valid. I'm
tired of doing this. I need to write a fn that, given three
functions/one function and two variables or anyother combo, run through
all four rows, and determine if it's valid. An argument is invalid iff
any row has true premises and a false conclusion or vice versa.
Here's a truth table for an invalid arg:
Denying the Antecedent T-Table:
A B A->B ~A .:~B
--------------------------------------------------------------
1 1 1 0 0
0 1 1 1 0
1 0 0 0 1
0 0 1 1 1
And here's my code:
//operators.hpp
#pragma once
bool NOT(bool A);
bool AND(bool A,bool B);
bool OR(bool A, bool B);
bool XOR(bool A, bool B);
bool NAND(bool A,bool B);
bool NOR(bool A, bool B);
bool XNOR(bool A, bool B);
bool IF(bool A, bool B);
bool IMP(bool A, bool B);
bool NIF(bool A, bool B);
bool NIMP(bool A, bool B);
//operators.cpp
#include "operators.hpp"
bool NOT(bool A)
{
if(A==true)
return false;
else return true;
}
bool AND(bool A,bool B)
{
if(A==true&&B==true)
return true;
else if(A==false&&B==true)
return false;
else if(A==true&&B==false)
return false;
else return false;
}
bool OR(bool A, bool B)
{
if(A==true&&B==true)
return true;
else if(A==false&&B==true)
return true;
else if(A==true&&B==false)
return true;
else return false;
}
bool XOR(bool A, bool B)
{
if(A==true&&B==true)
return false;
else if(A==false&&B==true)
return true;
else if(A==true&&B==false)
return true;
else return false;
}
bool NAND(bool A,bool B){return NOT(AND(A,B));}
bool NOR(bool A, bool B){return NOT(OR(A,B));}
bool XNOR(bool A, bool B){return NOT(XOR(A,B));}
bool IF(bool A, bool B){return NOT(AND(A,NOT(B)));}
bool IMP(bool A, bool B){return NOT(AND(B,NOT(A)));}
bool NIF(bool A, bool B){return NOT(IF(A,B));}
bool NIMP(bool A, bool B){return NOT(IMP(A,B));}
//main.cpp
#include "operators.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
bool A=true,B=true;
cout << "A" << " " << "B" << " " << "A->B" <<" " << "A" << ".:B" <<
endl;
cout << "----------------------" << endl;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
A=false;B=true;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
A=true;B=false;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
A=false;B=false;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Could you please tell me how to write an IsValid fn? Thanks!!!!!!!
they are logically valid. Currently, I have to tell the program to
print a truth table, and check it by hand to prove it's valid. I'm
tired of doing this. I need to write a fn that, given three
functions/one function and two variables or anyother combo, run through
all four rows, and determine if it's valid. An argument is invalid iff
any row has true premises and a false conclusion or vice versa.
Here's a truth table for an invalid arg:
Denying the Antecedent T-Table:
A B A->B ~A .:~B
--------------------------------------------------------------
1 1 1 0 0
0 1 1 1 0
1 0 0 0 1
0 0 1 1 1
And here's my code:
//operators.hpp
#pragma once
bool NOT(bool A);
bool AND(bool A,bool B);
bool OR(bool A, bool B);
bool XOR(bool A, bool B);
bool NAND(bool A,bool B);
bool NOR(bool A, bool B);
bool XNOR(bool A, bool B);
bool IF(bool A, bool B);
bool IMP(bool A, bool B);
bool NIF(bool A, bool B);
bool NIMP(bool A, bool B);
//operators.cpp
#include "operators.hpp"
bool NOT(bool A)
{
if(A==true)
return false;
else return true;
}
bool AND(bool A,bool B)
{
if(A==true&&B==true)
return true;
else if(A==false&&B==true)
return false;
else if(A==true&&B==false)
return false;
else return false;
}
bool OR(bool A, bool B)
{
if(A==true&&B==true)
return true;
else if(A==false&&B==true)
return true;
else if(A==true&&B==false)
return true;
else return false;
}
bool XOR(bool A, bool B)
{
if(A==true&&B==true)
return false;
else if(A==false&&B==true)
return true;
else if(A==true&&B==false)
return true;
else return false;
}
bool NAND(bool A,bool B){return NOT(AND(A,B));}
bool NOR(bool A, bool B){return NOT(OR(A,B));}
bool XNOR(bool A, bool B){return NOT(XOR(A,B));}
bool IF(bool A, bool B){return NOT(AND(A,NOT(B)));}
bool IMP(bool A, bool B){return NOT(AND(B,NOT(A)));}
bool NIF(bool A, bool B){return NOT(IF(A,B));}
bool NIMP(bool A, bool B){return NOT(IMP(A,B));}
//main.cpp
#include "operators.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
bool A=true,B=true;
cout << "A" << " " << "B" << " " << "A->B" <<" " << "A" << ".:B" <<
endl;
cout << "----------------------" << endl;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
A=false;B=true;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
A=true;B=false;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
A=false;B=false;
cout << A << " " << B << " " << IF(A,B) << " " << A << " " << B <<
endl;
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Could you please tell me how to write an IsValid fn? Thanks!!!!!!!