anon
anon

Reputation:

How to convert plain English into composed logical conditions?

I have 7 boolean variables name

A1
A2
A3

B1
B2
B3

C

Now the condition should evaluate to true if

or

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

Any hints how to start?

Upvotes: 0

Views: 266

Answers (7)

Buffalo
Buffalo

Reputation: 4052

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.

Upvotes: 0

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272717

"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.

Upvotes: 1

thkala
thkala

Reputation: 86403

  • "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));

Upvotes: 1

Femaref
Femaref

Reputation: 61497

  1. (A1 || A2 || A3) && (B1 || B2 || B3)
  2. ((A1 || A2 || A3) && (B1 || B2 || B3)) && C

Upvotes: 1

Dan
Dan

Reputation: 1002

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) ) )

Upvotes: 1

KP Taylor
KP Taylor

Reputation: 2100

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)

Upvotes: 3

flolo
flolo

Reputation: 15526

At least one means you have to OR them

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

Upvotes: 1

Related Questions