#include //boolean operation names char *op_name[] = { "0", "\"!\"", "<", "~x", ">", "~y", "\"+\"", "|", "&", "<=>","y", "=>", "x", "<=", "\"V\"", "1" }; int op_trivial[] = { 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1 }; void showlaw(char *format, int op, int *tt) { char *func; if (tt[0] == 0 && tt[1] == 0) func = "0"; else if (tt[0] == 1 && tt[1] == 1) func = "1"; else if (tt[0] == 0 && tt[1] == 1) func = "x"; else func = "~x"; printf(""); printf(format, op_name[op], func); printf(""); } void main() { //boolean binary operation number: 0000, 0001,... 1111 int op; int tt[2][2]; int ttx[2]; printf("\n\n"); for(op = 0; op < 16; op++) { //pass trivial operations if (op_trivial[op]) continue; tt[0][0] = op & 1; tt[0][1] = (op >> 1) & 1; tt[1][0] = (op >> 2) & 1; tt[1][1] = (op >> 3) & 1; printf(""); //rule x#0 ttx[0] = tt[0][0]; ttx[1] = tt[1][0]; showlaw("x %s 0 = %s", op, ttx); //rule 0#x ttx[0] = tt[0][0]; ttx[1] = tt[0][1]; showlaw("0 %s x = %s", op, ttx); //rule x#1 ttx[0] = tt[0][1]; ttx[1] = tt[1][1]; showlaw("x %s 1 = %s", op, ttx); //rule 1#x ttx[0] = tt[1][0]; ttx[1] = tt[1][1]; showlaw("1 %s x = %s", op, ttx); //rule x#x ttx[0] = tt[0][0]; ttx[1] = tt[1][1]; showlaw("x %s x = %s", op, ttx); //rule x#~x ttx[0] = tt[0][1]; ttx[1] = tt[1][0]; showlaw("x %s ~x = %s", op, ttx); //rule ~x#x ttx[0] = tt[1][0]; ttx[1] = tt[0][1]; showlaw("~x %s x = %s", op, ttx); printf("\n"); } printf("
\n"); }