布尔功能中的香农扩展

发布于 2025-02-04 03:58:51 字数 927 浏览 3 评论 0原文

根据此页面的wikipedia( https:> https:> https://en.wikipedia.org/wikipedia.org/wiki/wiki/boole/boole/boolem_exterem_exterem_exterem_theorm__theorm__theorm__theorm _theorm__theorm; )香农的扩展或分解定理,也称为Boole的扩展定理是一种身份,允许任何逻辑函数扩展以分解为各个部分。换句话说:

F = X . F (X = 1) + X' . F (X = 0)

因此,我试图用简单的C ++代码实现此逻辑,但它不起作用,这是我尝试的:

#include <iostream>
#define f(x,y,z) (((x) & (y)) | ((x) & (z)))
using namespace std;
int main()
{
    unsigned int a = 0x215f8;
    unsigned int b = 0x77012;
    unsigned int c = 0x33548;

    cout << f(a,b,c) << endl;
    cout << (((~a) & f(0,b,c)) | ((a) & f(1,b,c))) << endl;
    return 0;
}

我缺少什么?

编辑

该程序的输出是:

136536

0

According to this page in Wikipedia (https://en.wikipedia.org/wiki/Boole%27s_expansion_theorem) The Shannon expansion or decomposition theorem, also known as Boole's expansion theorem is an identity that allows the expansion of any logic function to broken down into parts. in other word:

F = X . F (X = 1) + X' . F (X = 0)

so I tried to implement this logic in a simple C++ code and it didn't work, here is what I tried:

#include <iostream>
#define f(x,y,z) (((x) & (y)) | ((x) & (z)))
using namespace std;
int main()
{
    unsigned int a = 0x215f8;
    unsigned int b = 0x77012;
    unsigned int c = 0x33548;

    cout << f(a,b,c) << endl;
    cout << (((~a) & f(0,b,c)) | ((a) & f(1,b,c))) << endl;
    return 0;
}

what I'm I missing?

EDIT:

the output of the program is:

136536

0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

西瓜 2025-02-11 03:58:51

我正在做的错误是,我正在以dodamental形式使用香农扩展定理,香农扩展应在集合B = {0,1}上工作,因此当我们尝试将此想法扩展到整数时,我们应该考虑所有方面的所有方面扩展名,布尔空间中的香农溢出是f(a,b,c)= a'.f(0,b,c) + af(1,b,c)我的错误是我使用f(a,b,c)= a'.f(0,b,c) + af(max_unsigned_int,b,c),我使用该精确表格。不断使用所有1,这起作用:

#include <iostream>
#include <limits.h>
#define f(x,y,z) (((x) & (y)) | ((x) & (z)))
using namespace std;
int main()
{
    unsigned int a = 0x215f8;
    unsigned int b = 0x77012;
    unsigned int c = 0x33548;

    cout << f(a,b,c) << endl;
    cout << (((~a) & f(0,b,c)) | ((a) & f(UINT_MAX,b,c))) << endl;
    return 0;
}

the mistake I was doing is that I was using Shannon expansion theorem in it's fondamental form, the shannon expansion should work on the set B={0,1} so when we try to extend this idea to integers we should consider all aspects of that extension, the shannon expasion in the boolean space is f(a,b,c) = a'.f(0,b,c) + a.f(1,b,c) my mistake is that I used that exact form while I should instead use f(a,b,c) = a'.f(0,b,c) + a.f(MAX_UNSIGNED_INT,b,c) which will put a constant with all 1's in it, this works:

#include <iostream>
#include <limits.h>
#define f(x,y,z) (((x) & (y)) | ((x) & (z)))
using namespace std;
int main()
{
    unsigned int a = 0x215f8;
    unsigned int b = 0x77012;
    unsigned int c = 0x33548;

    cout << f(a,b,c) << endl;
    cout << (((~a) & f(0,b,c)) | ((a) & f(UINT_MAX,b,c))) << endl;
    return 0;
}
-黛色若梦 2025-02-11 03:58:51

您的意思是使用操作员:|| &amp;&amp;吗?如果是这样,以下代码似乎可以工作:

#include <iostream>
#define f(x,y,z) (((x) && (y)) || ((x) && (z)))
using namespace std;
int main()
{
    unsigned int a = 0x215f8;
    unsigned int b = 0x77012;
    unsigned int c = 0x33548;

    cout << f(a,b,c) << endl;
    cout << (((~a) && f(0,b,c)) || ((a) && f(1,b,c))) << endl;
    return 0;
}

输出为1。

Do you mean to use the operators: || &&? If so the following code seems to work:

#include <iostream>
#define f(x,y,z) (((x) && (y)) || ((x) && (z)))
using namespace std;
int main()
{
    unsigned int a = 0x215f8;
    unsigned int b = 0x77012;
    unsigned int c = 0x33548;

    cout << f(a,b,c) << endl;
    cout << (((~a) && f(0,b,c)) || ((a) && f(1,b,c))) << endl;
    return 0;
}

Output is 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文