/ THE IDEA
AND produces true only when both of its inputs are true. OR produces true when at least one is true, including when both are true. NOT reverses one truth value. These are operations on statements, not judgements about whether the whole policy is wise or fair. Use parentheses to say which smaller rule is evaluated together. In our download example, imagine a free preview is also allowed. The intended policy might require an account for paid content while allowing previews without signing in. Writing the groups explicitly removes the ambiguity of a long sentence containing both “and” and “or”.
THE FORMAL IDEA
allow = (signed_in AND subscribed) OR preview
| signed_in, subscribed and preview each hold either true or false. | | The parenthesised pair is evaluated first. Its result is then combined with preview using OR; allow is the final decision. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Toy policy input: signed_in = true; subscribed = false; preview = false. Inside parentheses: true AND false = false. Then false OR false = false: deny. Change only preview to true: false OR true = true: allow. Alternative rule: signed_in AND (subscribed OR preview) would deny an unsigned-in visitor even for a preview.
|
The third input genuinely bypasses the paid-content requirement in the first rule. Moving the parentheses would change that policy rather than merely changing its appearance. To compare the alternatives, try signed_in = false and preview = true; they produce different answers.
/ SO WHAT?
A truth table lists every possible input combination and its result. For our three yes-or-no inputs there are eight combinations, so a complete check is small enough to do by hand. Testing only the happy path, where everything is true, would miss the difference between the two parenthesised policies.
ONE CAVEAT |
| Here the inputs are already reliable true-or-false facts. Real software must also define missing information and check who may set each input. Some languages return input values from AND or OR rather than literal Boolean values. |
KEEP THIS
Grouping changes which conditions can override others; test mixed true-and-false inputs to reveal the actual rule.
|
NEXT: Why is a door handle far from the hinges?
|