In: Computer Science
Q1. Formulate the logical constraints for the following statements (where A, B, C, and D are all binary variables):
a. If A happens then B or C happens.
b. If A and B happen then C and D must happen.
c. If A happens or B does not happen then C or D must happen.
d. If A happens or B happens then C and D happen.
This has previously been posted before on Chegg but there are conflicting answers and comments to the questions/responses.
NOTE: All the assumed events of A, B, C, D can only have two values: true or false and hence they are binary variables.
Ans a.
A = event where value of variable 'temp' is even
B = event when 'temp' is divisible by 6.
C = event when 'temp' is divisible by 3.
if ( temp % 2 == 0 )
{
int a = temp/6; // B has occurred here then only the logic reaches this point!
}
else if ( temp % 3 == 0 )
{
int a = temp/6; // C has occurred here then only the logic reaches this point!
}
Ans b.
A = 'temp' is divisible by 2
B = 'temp' is divisible by 3
C = 'temp' is divisible by 6
D = 'temp' is divisible by multiples of 6
if (( temp % 2 == 0 ) && ( temp % 3 == 0 ))
{
int a = temp/6; // a is integer and whole number since C has occured.
int b = temp/12; // Here, 12 is a multiple of 6. Also, b is integer and while number since D has occured.
}
Ans c.
A = 'temp' is divisible by 2
B = 'temp' is divisible by 3
C = 'temp' is divisible by 7
D = 'temp' is divisible by multiples of 6
if (( temp % 2 == 0 ) || ( temp % 3 == 0 )) //only the conditional operator is changed.
{
int a = temp/7; // a is integer and whole number since C has occurred but this is false!
int b = temp/12; // Here, 12 is a multiple of 6. Also, b is integer and while number since D has occured.
}
Ans d.
A = 'temp' is divisible by 2
B = 'temp' is divisible by 3
C = 'temp' is divisible by 6
D = 'temp' is divisible by multiples of 6
if (( temp % 2 == 0 ) || ( temp % 3 == 0 )) //only the conditional operator is changed.
{
int a = temp/6; // a is integer and whole number since C has occurred.
int b = temp/12; // Here, 12 is a multiple of 6. Also, b is integer and while number since D has occured.
}
Please comment for doubts!