如何将简单的英语转化为组合的逻辑条件?
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您没有指定上下文,因此我将根据您的标签并假设您正在用 Java 编写此内容。下面是您用来评估您提出的 2 个条件测试的代码。
对于“A 和 B 中的至少一个”:
对于“C 以及 A 和 B 中的至少一个为真”(将其解读为 A 和 B 变量被作为一个进行测试):
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":
For "C and at least one of A and B is true" (reading this as A & B variables are being tested as one):
至少一个意味着你必须对它们进行或操作,
这样你的第一个条件就是 (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)
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) ) )
((A1 || A2 || A3) && (B1 || B2 || B3)) && C
(A1 || A2 || A3) && (B1 || B2 || B3)
((A1 || A2 || A3) && (B1 || B2 || B3)) && C
“至少一个”= OR =
||
“and” = AND =
&&
因此,这两部分是:
(A1 || A2 || A3) && (B1 || B2 || B3)
或
C && (A1 || A2 || A3 || B1 || B2 || B3)
因此:
对眼睛(也许还有大脑)来说稍微容易一些:
"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:
Slightly easier on the eye (and, perhaps, the mind):
“至少一个”也可以写成“不是没有”,所以:
这也可以写成(应用 德摩根规则):
您指定的其余内容或多或少可以直接翻译,适当使用
&&
、||
和括号来解决歧义。"At least one of" can also be written as "not none of", so:
This can also be written as (applying De Morgan's Rule):
The rest of what you've specified can more or less be translated directly, with appropriate use of
&&
,||
, and parentheses to resolve ambiguity.例如:
第二部分的问题不是很清楚:
C 和 A 和 B 中的至少一个 = C 或 A 中的至少一个和 B 中的至少一个?
如果是这样的话,有些答案是不正确的。
C 和(A1 和 !B1)应计算为 False,而答案中的某些表达式将计算为 true。
Something like:
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.