Reputation: 549
Consider two Boolean variables, A and B, and some logical operation(s) on these variables, resulting in C:
C = A [OP] B
where 'OP' could be any combination of '&', '|', '^', '~', etc.
The values of A and B are to be determined.
Is it possible to create a series of tests using logical operations to definitively determine the True/False value of A and B based solely on the value of C for each test?
Since the application is being developed using NumPy, I am most interested in operators found natively in this package.
Upvotes: 1
Views: 59
Reputation: 23332
No, you can't definitely determine A and B if you're simply given the value of C and the operation used.
A single counter-example is needed to disprove it:
C= True
OP= |
There's three possible valid states for A and B: A=True, B=True
, A=True, B=False
, A=False, B=True
For multiple (user-chosen) tests, we get the same result, if you restrict yourself to &
,|
and ^
(xor). It's clearly not possible in the general case - since the operations are commutative, you can't tell apart A and B.
As an example, if
A & B == False
A | B == True
A ^ B == True
both A=True, B=False
and A=False, B=True
satisfy the conditions.
If we don't apply any restriction at all on the expressions you can test, getting the values of B
(for example) is trivial: just evaluate C=(A|~A)|B
and the result will be equal to B
But then, if you don't have any restriction, you could just say C=B
and test it directly!
Upvotes: 5