#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 main() { //boolean binary operation number: 0000, 0001,... 1111 int op1, op2; //true table of operation: x # y = tt1[x][y] int tt1[2][2]; int tt2[2][2]; int x, y, z; bool distr1, distr2; for(op1 = 0; op1 < 16; op1++) { //pass trivial operations if (op_trivial[op1]) continue; tt1[0][0] = op1 & 1; tt1[0][1] = (op1 >> 1) & 1; tt1[1][0] = (op1 >> 2) & 1; tt1[1][1] = (op1 >> 3) & 1; for(op2 = 0; op2 < 16; op2++) { //pass trivial operations if (op_trivial[op2]) continue; tt2[0][0] = op2 & 1; tt2[0][1] = (op2 >> 1) & 1; tt2[1][0] = (op2 >> 2) & 1; tt2[1][1] = (op2 >> 3) & 1; //check distrib. distr1 = true; distr2 = true; for (x = 0; x <= 1; x++) for (y = 0; y <= 1; y++) for (z = 0; z <= 1; z++) { if ( tt1[x][tt2[y][z]] != tt2[tt1[x][y]][tt1[x][z]] ) distr1= false; if ( tt1[tt2[x][y]][z] != tt2[tt1[x][z]][tt1[y][z]] ) distr2= false; } if (distr1) printf("x %s (y %s z) = (x %s y) %s (x %s z)\n", op_name[op1], op_name[op2], op_name[op1], op_name[op2], op_name[op1]); if (distr2) printf("(x %s y) %s z = (x %s z) %s (y %s z)\n", op_name[op2], op_name[op1], op_name[op1], op_name[op2], op_name[op1]); if (distr1 & distr2) printf("full distributive\n"); else if (distr1) printf("left distributive\n"); else if (distr2) printf("right distributive\n"); } } }