Recall that a proposition is a statement that is either true

Recall that a proposition is a statement that is either true or false. Propositional variables such as p, q. and r can be used to denote arbitrary propositions. A compound proposition is created by connecting individual propositions with logical operations. A literal is simply a propositional variable or its negation. For example, p.-p-q, r, and-r are literals A compound proposition is said to be in a disjunctive normal form (DNF) if it is a disjunction of terms that are themselves conjunctions of literals. A compound proposition in a DNF is a disjunction of one or more terms each of which is a conjunction of one or more literals. For example, all of the following compound propositions are in DNF (pA ) V (Here the second term is a conjunction ofjust one literal), .p vq (A disjunction of two terms each of which consists of one literal), * p ^-q ^ (Here we have a disjunction that consists of one term only). .p (Here we have a disjunction that consists of one term which consists of one literal). A compound proposition is said to be in a conjunctive normal form (CNF) if it is a conjunction of terms that are themselves disjunctions of literals. A compound proposition in a CNF is a conjunction of one or more terms each of which is a disjunction of one or more literals For example, all of the following compound propositions are in CNF q ^ (-p v r) (Here the first term is a disjunction ofjust one literal). * .p vq (Here we have conjunction that consists of one term only), p (Here we have a conjunction that consists of one term which consists of one literal). Assume that we have a truth table with 3 variables (p, q, and r) and we would like to find a compound proposition with this truth table. For ex we have the following truth table: tion Given a truth table, one can find compound propositions that have the same truth table using the following two methods. Method 1. Construct a compound proposition in DNF that has a given truth table (with at least one row with value T). To construct a DNF that has a given truth table, identify each row in the truth table for which the value of compound proposition is T. In the table above, these are rows 1, 2, 3, 4, and 6. For each such row construct a conjunction that produces T (or true) for the exact combination of truth values of p, q. and r

Solution


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class proposition {
private static char[][] symb=new char[][]{{\'p\',\'q\',\'r\'},
{\'T\',\'T\',\'T\'},
{\'T\',\'T\',\'F\'},
{\'T\',\'F\',\'T\'},
{\'T\',\'F\',\'F\'},
{\'F\',\'T\',\'T\'},
{\'F\',\'T\',\'F\'},
{\'F\',\'F\',\'T\'},
{\'F\',\'F\',\'F\'}};
  
private static String getDNF(int i)
{
String res=\"\";
if(symb[i][0]==\'T\')
res = res + symb[0][0]+\"\";
else
res = res + symb[0][0]+\"\'\";
  
if(symb[i][1]==\'T\')
res = res + symb[0][1]+\"\";
else
res = res + symb[0][1]+\"\'\";
  
if(symb[i][2]==\'T\')
res = res + symb[0][2]+\"\";
else
res = res + symb[0][2]+\"\'\";
  
return res;
}
  
private static String getCNF(int i)
{
String res=\"(\";
if(symb[i][0]==\'T\')
res = res + symb[0][0]+\"\'+\";
else
res = res + symb[0][0]+\"+\";
  
if(symb[i][1]==\'T\')
res = res + symb[0][1]+\"\'+\";
else
res = res + symb[0][1]+\"+\";
  
if(symb[i][2]==\'T\')
res = res + symb[0][2]+\"\'\";
else
res = res + symb[0][2]+\"\";
  
res=res+\")\";
  
return res;
}
  
public static void main(String args[]) throws IOException
{
String CNF=\"\",DNF=\"\";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(\"This program finds compound statements(in CNF and/or DNF) that have a given truth table\");
System.out.println(\"The statements have 3 propositional variables: p, q, and r.\");
System.out.println(\"Please enter the truth values for each row of the truth table.\");
for(int i=1;i<=8;i++)
{
System.out.print(\"p=\"+symb[i][0]+\", q=\"+symb[i][1]+\", r=\"+symb[i][2]+\". Truth value is (T/F):\");
String ch= br.readLine();
if(ch.equals(\"T\"))
{
DNF=DNF+getDNF(i)+\" + \";
}
else if(ch.equals(\"F\"))
CNF=CNF+getCNF(i)+\" \";
else
{
System.out.println(\"Invalid Input!\");
return;
}
}
  
if(CNF.isEmpty()==false)
{
System.out.println(\"CNF expression for the truth table is: \");
System.out.println(CNF);
}
  
if(DNF.isEmpty()==false)
{
System.out.println(\"DNF expression for the truth table is: \");
DNF=DNF.substring(0, DNF.length()-2);
System.out.println(DNF);
}
}
}

 Recall that a proposition is a statement that is either true or false. Propositional variables such as p, q. and r can be used to denote arbitrary propositions
 Recall that a proposition is a statement that is either true or false. Propositional variables such as p, q. and r can be used to denote arbitrary propositions

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site