码迷,mamicode.com
首页 > 其他好文 > 详细

最小联结词组

时间:2015-11-24 20:20:25      阅读:1010      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

This is only ok in Binary Logic.

There are 16 pairs Minimal association phrases.

 1 not (a or b) , 
 2 not (a => b) , not b , 
 3 not b , not (b => a) , 
 4 not (a => b) , not a , 
 5 not (b => a) , not a , 
 6 not (a and b) , 
 7 not b , a and b , 
 8 not a , a and b , 
 9 not (a => b) , not (a xor b) , 
10 not (b => a) , not (a xor b) , 
11 false , a and b , not (a xor b) , 
12 a xor b , a and b , not (a xor b) , 
13 false , b => a , 
14 not (a => b) , b => a , 
15 not b , b => a , 
16 not (b => a) , b => a , 
17 not a , b => a , 
18 a xor b , b => a , 
19 false , a => b , 
20 not (a => b) , a => b , 
21 not b , a => b , 
22 not (b => a) , a => b , 
23 not a , a => b , 
24 a xor b , a => b , 
25 not b , a or b , 
26 not a , a or b , 
27 false , not (a xor b) , a or b , 
28 a xor b , not (a xor b) , a or b , 
29 not (a => b) , true , 
30 not (b => a) , true , 
31 a xor b , a and b , true , 
32 a xor b , a or b , true , 

I got this result by a violent method:If you run this program ,you can see more things.

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string.h>
 4 using namespace std; 
 5 typedef unsigned short set;//Every bit is a flag.
 6 const int N=1<<16;//There are 65536 probability.
 7 bool a[16][4]; //A 10 B 12
 8 const char *desc[16]={"false","not (a or b)",
 9     "not (a => b)","not b",
10     "not (b => a)","not a",
11     "a xor b","not (a and b)",
12     "a and b","not (a xor b)",
13     "a","b => a",
14     "b","a => b",
15     "a or b","true"};
16 void init(){
17     for(int i=0;i<16;i++){
18         int x=i;
19         for(int j=0;j<4;j++){
20             a[i][j]=x&1;
21             x>>=1;
22         }
23     }
24 }
25 void show(int n){ 
26     printf("\t%-16s",desc[n]);
27     for(int i=0;i<4;i++)printf("%2d",a[n][i]);
28     puts("");
29 }
30 void table(){ 
31     show(10),show(12);
32     puts("\t---------------------------");
33     for(int i=0;i<16;i++)show(i);
34 }
35 
36 set ans[N];
37 int book[N][16][3];
38 int ai=0;
39 bool ok(set n){ 
40     int temp=n;
41     n|=(1<<10)|(1<<12); 
42     again: 
43     for(int i=0;i<16;i++)
44         if(n&(1<<i))
45             for(int j=0;j<16;j++)
46                 if(n&(1<<j))
47                     for(int k=0;k<16;k++)
48                         if(n&(1<<k)){
49                             int t=0;
50                             for(int l=0;l<4;l++)
51                                 t|=(a[k][a[i][l]+a[j][l]*2]<<l);
52                             if((n&(1<<t))==0){
53                                 n|=(1<<t);
54                                 book[temp][t][0]=i,book[temp][t][1]=j,book[temp][t][2]=k;
55                                 goto again;
56                             }
57                         }
58     return n==N-1;
59 } 
60 void print(set n){
61     for(int j=0;j<16;j++){ 
62         if(n&(1<<j)){
63             printf("%-15s|",desc[j]);
64         }
65     }
66     puts("");
67     for(int i=0;i<16;i++){
68         if((n&(1<<i))||i==10||i==12)continue;
69         printf("\t\t%-15s = %-15s [%-15s] %-15s\n",desc[i],desc[book[n][i][0]],desc[book[n][i][2]],desc[book[n][i][1]]);
70     }
71     puts("");
72 }
73 int main(){  
74     init(); 
75     table();
76     memset(book,-1,sizeof(book));
77     for(int i=0;i<N;i++){
78         int j;
79         for(j=0;j<ai;j++)
80             if((ans[j]&i)==ans[j])
81                 break;
82         if(j!=ai)continue;
83         if(ok(i)) ans[ai++]=i;
84     }
85     for(int i=0;i<ai;i++){
86         print(ans[i]);
87     }
88     return 0;
89 }

 

最小联结词组

标签:

原文地址:http://www.cnblogs.com/weidiao/p/4992596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!