#include #define MAX_VARS 4 /* Max # of variables in a product term */ typedef unsigned short WORD; /* Use 16-bit words */ struct cube { WORD t; /* Bits 1 for uncomplemented variables. */ WORD f; /* Bits 1 for complemented variables. */ }; typedef struct cube CUBE; int EqualCubes(CUBE C1, CUBE C2) /* Returns true if C1 and C2 are identical. */ { return ( (C1.t == C2.t) && (C1.f == C2.f) ); } int Oneone(WORD w) /* Returns true if w has exactly one 1 bit. */ { /* Optimizing the speed of this routine is critical */ int ones, b; /* and is left as an exercise for the hacker. */ ones = 0; for (b=0; b>1; } return((ones==1)); } int Combinable(CUBE C1, CUBE C2) /* Returns true if C1 and C2 differ in only one variable, */ { /* which appears true in one and false in the other. */ CUBE tcube; tcube.t = C1.t ^ C2.t; tcube.f = C1.f ^ C2.f; return( (tcube.t==tcube.f) && Oneone(tcube.f) ); } void Combine(CUBE C1, CUBE C2, CUBE *C3) /* Combines C1 and C2 using theorem T10, and stores the */ { /* result in C3. Assumes Combinable(C1,C2) is true. */ C3->t = C1.t & C2.t; C3->f = C1.f & C2.f; } void PrintCube(CUBE C) { printf("t:%04x f:%01x\n", C.t, C.f); } #define TRUE 1 #define FALSE 0 #define MAX_CUBES 50 void main() { CUBE cubes[MAX_VARS+1][MAX_CUBES]; int covered[MAX_VARS+1][MAX_CUBES]; int numCubes[MAX_VARS+1]; int m; /* Value of m in an m-cube, i.e., ‘‘level m.’’ */ int j, k, p; /* Indices into the cubes or covered array. */ CUBE tempCube; int found; /* Initialize number of m-cubes at each level m. */ for (m=0; m