/* Compiled with g++. * This is the program written to calculate the opt size of the monotone * function up to 6 variables. */ # include # include # include # include # include #define Nterm 4 #define SFT3 8 // 2^3 #define SFT4 16 // 2^4 #define SFT5 32 // 2^5 #define N_3 20 //the number of monotone functions for 3 vars #define N_4 168 //the number of monotone functions for 4 vars #define N_5 7581 //the number of monotone functions for 5 vars #define N_6 7828354 //the number of monotone functions for 5 vars #define MAX 10000 //just a large number void nrerror(char error_text[]) /*Numerical Recipes standard error handler*/ { int i; printf("\n\n"); fprintf(stderr,"Numerical Recipes run-time error...\n"); fprintf(stderr,"%s\n",error_text); fprintf(stderr,"...now exiting to system...\n"); exit(1); } int * inf_cal(unsigned long mfv,int n,int t2n,int * mindex) //mfv: monotone function's value; n: number of variables in the function; t2n: number equal to 2^n. { //to calculate the inf using the naive method, which defines the inf as a ratio of the numb of changed f(v)|v:0->1, //with the total 2^n numbers. And here the inf is defined without normalized by 2^n since one only cares the relative inf int i,j; unsigned long tmp; int indxf; long max=-1; // for (i=0;ibit 15 */ //cal the inf for each varible for(j=0;j>(n-1-j))&1))//if the var_j is 0 //this definition of j is consistent with elsewhere in this program { if((t2n-1-i)<32){ tmp=1&(mfv>>(t2n-1-i)); //get the fvalue of bit n-1-i } else{ tmp=1&(mfv>>16>>16>>(t2n-1-i-32));} indxf=(i|(1<<(n-1-j))); //flip the var_j from 0 to 1 if((t2n-1-indxf)<32){ if(tmp!=(1&(mfv>>(t2n-1-indxf))))//if the DNF changes vinf[j]++; } else{ if(tmp!=(1&(mfv>>16>>16>>(t2n-1-32-indxf))))//if the DNF changes vinf[j]++; } } }//end of the list } //end of each var loop for(j=0;jflist[M]) { L=M; } else if(fvalue=32 cnt++; } } } return cnt; } void left_right(unsigned long &left, unsigned long &right,int NV, int nv,unsigned long mf,int N1,int N2) /* * suppose that the N1=2^3 is the number of inputs of 3 var, and the N2=2^4=16 is now the number of inputs of 4 var; then * left, right; each stores the left and right subtree 3 vars monotone function * value, which is the key to find the optsize from the 3 var stored result * The nv is the nth var. For N2=16, nv=0,1,2,or 3. * NV is the # of variables in the MF * mf is the MF's value. */ { int i,j, l,r; unsigned long temp; i=nv; left=0; //need to double check the position of these two lines right=0; l=0; r=0; //the left and right counter are set to zero in the beginning for(j=0;jbit 15 */ //cout<<"j "<>(NV-i-1))&1) { //right if(j>=32) temp=mf>>N2-j-1; else temp=mf>>N2-(j+32)-1>>16>>16; if(temp&1) { right|=(1<<(N1-1-r)); //mask that bit to 1 r++; } else { //right&=(0<<(N1-1-r)); //mask that bit to 0 r++; } } else { //left if(j>=32) temp=mf>>N2-j-1; else temp=mf>>N2-(j+32)-1>>16>>16; if(temp&1) { left|=(1<<(N1-1-l)); //mask that bit to 1 l++; } else { //left&=(0<<(N1-1-l)); //mask that bit to 0 l++; } } //cout<<"left is "<=tree_size) { min=tree_size; min_index_opt=i; } //Part II, find min optsize by considering the influence of a var //if the above part I and part II give two different answer, there is a conter example found. } //send the results to storage int count=0; for(i=0;i \n"); exit(0); } //the following reads a 3 variable monotone function from a file and //stores in an array ifstream fin; fin.open(argc[1],ifstream::in); while(!fin.eof()) { fin >>monotf>>opts; mntnf[i]=monotf; optsz[i]=opts; i++; if(i>=20) break; } fin.close(); //finishing reading the file //construct the 4 var monotone function and calculate the opt size for(i=0;i