如何将简单的英语转化为组合的逻辑条件?

发布于 2024-10-30 00:03:55 字数 233 浏览 0 评论 0原文

我有 7 个布尔变量 name

A1
A2
A3

B1
B2
B3

C

则条件应评估为 true

  • 现在,如果A 中至少一个和 B 中至少一个为真

,或者

  • C 且 A 和 B 中至少一个为真,

我不知道如何制作简短的组成条件:

有什么提示如何开始吗?

I have 7 boolean variables name

A1
A2
A3

B1
B2
B3

C

Now the condition should evaluate to true if

  • at least one of A and at least one of B is true

or

  • C and at least one of A and B is true

I don't know exactly how I can make a short composed condition out of this:

Any hints how to start?

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

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

发布评论

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

评论(7

埋情葬爱 2024-11-06 00:03:55

您没有指定上下文,因此我将根据您的标签并假设您正在用 Java 编写此内容。下面是您用来评估您提出的 2 个条件测试的代码。

对于“A 和 B 中的至少一个”:

bool condition1 = (A1 || A2 || A3) && (B1 || B2 || B3)

对于“C 以及 A 和 B 中的至少一个为真”(将其解读为 A 和 B 变量被作为一个进行测试):

bool condition2 = C && (A1 || A2 || A3 || B1 || B2 || B3)

You didn't specify a context, so I am going by your tags and assuming you are writing this in Java. Below is the code you would use to evaluate the 2 conditional tests you posed.

For "At least one of A and one of B":

bool condition1 = (A1 || A2 || A3) && (B1 || B2 || B3)

For "C and at least one of A and B is true" (reading this as A & B variables are being tested as one):

bool condition2 = C && (A1 || A2 || A3 || B1 || B2 || B3)
网白 2024-11-06 00:03:55

至少一个意味着你必须对它们进行或操作,

这样你的第一个条件就是 (A1 || A2 || A3) && (B1 || B2 || B3)

At least one means you have to OR them

so your first condition wouwld be (A1 || A2 || A3) && (B1 || B2 || B3)

依 靠 2024-11-06 00:03:55

A 中至少一项和 B 中至少一项为真

C 并且 A 和 B 中至少一个为真

( (a1 || a2 || a3) && (b1 || b2 || b3) ) || (c && ( (a1 || a2 || a3) && (b1 || b2 || b3) ) )

at least one of A and at least one of B is true
or

C and at least one of A and B is true

( (a1 || a2 || a3) && (b1 || b2 || b3) ) || (c && ( (a1 || a2 || a3) && (b1 || b2 || b3) ) )

深海蓝天 2024-11-06 00:03:55
  1. <代码>(A1 || A2 || A3) && (B1 || B2 || B3)
  2. ((A1 || A2 || A3) && (B1 || B2 || B3)) && C
  1. (A1 || A2 || A3) && (B1 || B2 || B3)
  2. ((A1 || A2 || A3) && (B1 || B2 || B3)) && C
妄司 2024-11-06 00:03:55
  • “至少一个”= OR = ||

  • “and” = AND = &&

因此,这两部分是:

  • (A1 || A2 || A3) && (B1 || B2 || B3)

  • C && (A1 || A2 || A3 || B1 || B2 || B3)

因此:

boolean R = ((A1 || A2 || A3) && (B1 || B2 || B3)) || (C && (A1 || A2 || A3 || B1 || B2 || B3));

对眼睛(也许还有大脑)来说稍微容易一些:

boolean T1 = (A1 || A2 || A3);
boolean T2 = (B1 || B2 || B3);

boolean R = (T1 && T2) || (C && (T1 || T2));
  • "at least one" = OR = ||

  • "and" = AND = &&

Therefore the two parts are:

  • (A1 || A2 || A3) && (B1 || B2 || B3)

or

  • C && (A1 || A2 || A3 || B1 || B2 || B3)

Therefore:

boolean R = ((A1 || A2 || A3) && (B1 || B2 || B3)) || (C && (A1 || A2 || A3 || B1 || B2 || B3));

Slightly easier on the eye (and, perhaps, the mind):

boolean T1 = (A1 || A2 || A3);
boolean T2 = (B1 || B2 || B3);

boolean R = (T1 && T2) || (C && (T1 || T2));
你怎么这么可爱啊 2024-11-06 00:03:55

“至少一个”也可以写成“不是没有”,所以:

!(!B1 && !B2 && !B3)

这也可以写成(应用 德摩根规则):

B1 || B2 || B3

您指定的其余内容或多或少可以直接翻译,适当使用 &&|| 和括号来解决歧义。

"At least one of" can also be written as "not none of", so:

!(!B1 && !B2 && !B3)

This can also be written as (applying De Morgan's Rule):

B1 || B2 || B3

The rest of what you've specified can more or less be translated directly, with appropriate use of &&, ||, and parentheses to resolve ambiguity.

够运 2024-11-06 00:03:55

例如:

isTrue = ( ((A1 || A2 || A3) && ( B1 || B2 || B3)) || 

         ( C && ( (A1 || A2 || A3) && ( B1 || B2 || B3) ) ) )

第二部分的问题不是很清楚:

C 和 A 和 B 中的至少一个 = C 或 A 中的至少一个和 B 中的至少一个?

如果是这样的话,有些答案是不正确的。

C 和(A1 和 !B1)应计算为 False,而答案中的某些表达式将计算为 true。

Something like:

isTrue = ( ((A1 || A2 || A3) && ( B1 || B2 || B3)) || 

         ( C && ( (A1 || A2 || A3) && ( B1 || B2 || B3) ) ) )

The question is not very clear for the second part:

C and at least one of A and B = C or at least one of A and at least one of B ?

If that is the case, some answers are incorrect.

C and ( A1 and !B1) should evaluate to False, while some expressions in answers will evaluate to true.

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