令人困惑的布尔表达式

发布于 2024-12-29 02:05:14 字数 221 浏览 2 评论 0原文

给定布尔变量 xyz 的这些值:

x = true
y = false
z = true

为什么以下逻辑表达式的计算结果为 true

(x || !y) && (!x || z)

Given these values for the boolean variables x, y, and z:

x = true
y = false
z = true

Why does the following logical expression evaluate to true?

(x || !y) && (!x || z)

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

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

发布评论

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

评论(4

坐在坟头思考人生 2025-01-05 02:05:14

代入 xyz 的值:

(true || !false) && (!true || true)

翻转否定值:

(true || true) && (false || true)

替换 ORed 语句(如果一侧为 true,则整个语句为真):

true && true

替换ANDed语句(如果两边都为真,则整个语句为真):

true

Substitute in the values of x, y, and z:

(true || !false) && (!true || true)

Flip the negated values:

(true || true) && (false || true)

Replace the ORed statements (if one side is true, the whole statement is true):

true && true

Replace the ANDed statement (if both sides are true, the whole statement is true):

true
幽梦紫曦~ 2025-01-05 02:05:14

真或假永远是真。 真||错误
真实和真实永远是真实的。 真&&正确

True or False is always True. true || false
True and True is always True. true && true

何以心动 2025-01-05 02:05:14

X 在第一个分组中为真,导致第一个分组为真。 Z 在第二分组中为真,导致第二分组为真。因此组 1 和组 2 为真。

X is true in the first grouping causing the first grouping to be true. Z is true in the second grouping causing the second grouping to be true. Therefore group 1 and group 2 are true.

狼性发作 2025-01-05 02:05:14
(x || !y) && (!x || z)
= (T || !F) && (!T || T) <-- plug in x = T, y = F, z = T
= (T || T) && (F || T) <-- !F = T, !T = F
= T && T <- T || T = T, F || T = T
= T <- T && T = T

实际上,请告诉我们到底是什么令人困惑;我有点困惑你觉得它很令人困惑。

(x || !y) && (!x || z)
= (T || !F) && (!T || T) <-- plug in x = T, y = F, z = T
= (T || T) && (F || T) <-- !F = T, !T = F
= T && T <- T || T = T, F || T = T
= T <- T && T = T

Actually, please tell us what's so confusing; I am slightly confused that you find it confusing at all.

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