当前位置: 首页 > news >正文

最小联结词组

695653-20170217144414269-747191010.png
This is only ok in Binary Logic.
有17个最小联结词组(如果认为包含true和false的不是最小联结词组,那么最小联结词组只有11个)

not(or)        |
not(=>)        |not            |
not(and)       |
not            |and            |
not(=>)        |not(xor)       |
false          |and            |not(xor)       |
xor            |and            |not(xor)       |
false          |=>             |
not(=>)        |=>             |
not            |=>             |
xor            |=>             |
not            |or             |
false          |not(xor)       |or             |
xor            |not(xor)       |or             |
not(=>)        |true           |
xor            |and            |true           |
xor            |or             |true           |

整理一下

not(or)
not(and)

not,or
not,and
not,=>
not,not(=>)

not(=>),=>
not(=>),true 
not(=>),not(xor)  
=>,false
=>,xor

xor,and,not(xor)
xor,or,not(xor)
xor,and,true  
xor,or,true

not(xor),and,false
not(xor),or,false  

xor功能比false更丰富,因为false = a xor a,所以一切出现false的地方都可以用xor取代

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

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<list>
using namespace std;
const int N = 1 << 16;//There are 65536 probability.
bool a[16][4]; //A 10 B 12
const char *desc[16] = { "false", "not (a or b)",
"not (a => b)", "not b",
"not (b => a)", "not a",
"a xor b", "not (a and b)",
"a and b", "not (a xor b)",
"a", "b => a",
"b", "a => b",
"a or b", "true" };
const char*desc_simple[16] = { "false", "not(or)", "not(=>)", "not", "not(=>)", "not", "xor", "not(and)", "and", "not(xor)", "a", "=>", "b", "=>", "or", "true" };
/*
上表中,只有条件运算符和非条件运算符是不满足交换律,但是它们是等价的
也就是说:2,4等价,11,13等价,3,5等价
*/
int eq[] = { 2, 4, 11, 13, 3, 5 }, eq_size = 3;
void init(){//初始化16个逻辑词
    for (int i = 0; i < 16; i++){
        int x = i;
        for (int j = 0; j < 4; j++){
            a[i][j] = x & 1;
            x >>= 1;
        }
    }
}
void show(int n){
    printf("\t%-16s", desc[n]);
    for (int i = 0; i < 4; i++)printf("%2d", a[n][i]);
    puts("");
}
void table(){
    show(10), show(12);//10和12代表着原始的a和b
    puts("\t---------------------------");
    for (int i = 0; i < 16; i++)show(i);
}

int ans[N], ai = 0;//存储全部的答案
int book[N][16][3];//对于N中逻辑词组,16个逻辑词来源于三个人:a,b,操作 
//判断集合set是否是完备的逻辑词组
bool ok(int n){
    int temp = n;
    n |= (1 << 10) | (1 << 12);
again:
    for (int i = 0; i < 16; i++)
    if (n&(1 << i))
    for (int j = 0; j < 16; j++)
    if (n&(1 << j))
    for (int k = 0; k < 16; k++)
    if (n&(1 << k)){
        //i,j分别操作数,k表示操作符,也就是k表示运算法则
        int t = 0;//t表示运算结果
        for (int l = 0; l < 4; l++)//将四位分别进行运算
            t |= (a[k][a[i][l] + a[j][l] * 2] << l);
        if ((n&(1 << t)) == 0){
            n |= (1 << t);
            book[temp][t][0] = i, book[temp][t][1] = j, book[temp][t][2] = k;
            goto again;
        }
    }
    return n == N - 1;
}
void print(bool detail){
    for (int i = 0; i < ai; i++){
        int n = ans[i];
        for (int j = 0; j < 16; j++){
            if (n&(1 << j)){
                const char*des = detail ? desc[j] : desc_simple[j];
                printf("%-15s|", des);
            }
        }
        puts("");
        if (detail){
            for (int i = 0; i < 16; i++){
                if ((n&(1 << i)) || i == 10 || i == 12)continue;
                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]]);
            }
            puts("");
        }
    }
}
//根据eq数组去掉等价的元素
void simple(){
    for (int i = 0; i < ai; i++){
        int n = ans[i];
        for (int j = 0; j < eq_size; j++){
            if (n&(1 << eq[j << 1 | 1])){
                n &= ~(1 << eq[j << 1 | 1]);
                n |= (1 << eq[j << 1]);
            }
        }
        ans[i] = n;
        for (int j = 0; j < i; j++)
        if (ans[i] == ans[j])
            ans[i] = -1;
    }
    int ind = 0;
    for (int i = 0; i < ai; i++)
    if (ans[i] != -1)ans[ind++] = ans[i];
    ai = ind;
}
bool visited(int x){
    for (int i = 0; i < ai; i++)
    if ((ans[i] & x) == ans[i])
        return true;
    return false;
}
int main(){
    init();
    table();//打印表,说清逻辑运算及其对应的编码
    memset(book, -1, sizeof(book));
    for (int i = 0; i < N; i++){
        //先判断i的某个子集是否已经是最小逻辑词组,如果是,则i必然不是最小逻辑词组
        if (visited(i))continue;
        if (ok(i)) ans[ai++] = i;
    }
    simple();
    print(false);
    return 0;
}

相关文章:

  • C# 添加、获取及删除PDF附件
  • HashMap,Hashtable,ConcurrentHashMap 和 synchronized Map 的原理和区别
  • Flask 5 模板1
  • hibernate主键为字符串的注解
  • spring拦截器
  • C#实现正则表达式
  • mitmproxy
  • tableView选择多项或单选
  • ip_conntrack table full dropping packet解决方案
  • Oracle for 循环
  • c++免注册大漠插件
  • 求上限值的整数勾股数
  • 微信小程序把玩(二十二)action-sheet组件
  • Python爬虫入门六之Cookie的使用
  • mysql学习笔记(二)--- MySQL数据类型
  • (十五)java多线程之并发集合ArrayBlockingQueue
  • @angular/forms 源码解析之双向绑定
  • Android单元测试 - 几个重要问题
  • extract-text-webpack-plugin用法
  • iOS高仿微信项目、阴影圆角渐变色效果、卡片动画、波浪动画、路由框架等源码...
  • Java多态
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • node-sass 安装卡在 node scripts/install.js 解决办法
  • Octave 入门
  • Python进阶细节
  • spring + angular 实现导出excel
  • Storybook 5.0正式发布:有史以来变化最大的版本\n
  • ubuntu 下nginx安装 并支持https协议
  • 回顾2016
  • 实战:基于Spring Boot快速开发RESTful风格API接口
  • 使用 QuickBI 搭建酷炫可视化分析
  • 协程
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 优秀架构师必须掌握的架构思维
  • 阿里云ACE认证学习知识点梳理
  • ​ArcGIS Pro 如何批量删除字段
  • # 计算机视觉入门
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • (Matalb分类预测)GA-BP遗传算法优化BP神经网络的多维分类预测
  • (六)激光线扫描-三维重建
  • (免费领源码)python#django#mysql公交线路查询系统85021- 计算机毕业设计项目选题推荐
  • (三)终结任务
  • (未解决)jmeter报错之“请在微信客户端打开链接”
  • (五)关系数据库标准语言SQL
  • (中等) HDU 4370 0 or 1,建模+Dijkstra。
  • (转)ObjectiveC 深浅拷贝学习
  • .gitignore文件---让git自动忽略指定文件
  • .NET 中 GetProcess 相关方法的性能
  • .NET连接MongoDB数据库实例教程
  • ?php echo ?,?php echo Hello world!;?
  • @ResponseBody
  • @SuppressWarnings(unchecked)代码的作用
  • [ Linux 长征路第五篇 ] make/Makefile Linux项目自动化创建工具
  • [acwing周赛复盘] 第 69 场周赛20220917