3 ms·
There is: The neutral element for + is 0 (x + 0 = x for any x). The neutral element for * is 1 (x * 1 = x for any x). Furthermore, you have arithmetic proper
by layer8 3y ago
There is:
The neutral element for + is 0 (x + 0 = x for any x).
The neutral element for * is 1 (x * 1 = x for any x).
Furthermore, you have arithmetic properties like x * 0 = 0 for any x (annulation) or (x + y) * z = (x * z) + (y * z) for any x, y, z (distributivity).
Similarly:
The neutral element for OR is false (x OR false = x for any x).
The neutral element for AND is true (x AND true = x for any x).
Furthermore, x AND false = false for any x, and (x OR y) AND z = (x AND z) OR (y AND z) for any x, y, z.
So OR works very much like + algebraically, and AND works very much like *.
When using 0 and 1 for false and true, AND is exactly the same as multiplication, and OR is like addition with saturation arithmetics (i.e. 1 + 1 = 1).
The common precedence rules stem from those parallels.
- threatofrain 3y agoI've never heard of saturation arithmetic and now it all makes sense. Otherwise I thought it was more common to think of XOR as boolean addition, and OR would be represented as xy + x + y.
- layer8 3y agoYes, true and false with AND and XOR form a mathematical ring [0]. Still, OR is also an additive operation. IMO one could give OR and XOR the same precedence. On the other hand, there is no strict need to have a dedicated boolean XOR operator, as it works the same as = (equals). [0] https://en.wikipedia.org/wiki/Ring_(mathematics) https://en.wikipedia.org/wiki/Ring_(mathematics)
- orlp 3y agoMore than just a ring, it is the simplest finite field.
- o11c 3y agoSaturation is actually the wrong way to think about bools when other operations get involved: saturate(0 - 1) = 0 bool(0 - 1) = 1
- dataflow 3y agoFun (but not particularly useful fact) is you can also represent x OR y as 1 - (1 - x)(1 - y). This shouldn't be too weird since x OR y is equal to NOT ((NOT x) AND (NOT y)).
- nostrademons 3y agoThere's also a connection to probability: if you want the probability of A and B and C happening and they're independent, it's P(A) * P(B) * P(C). If you want the probability of A or B or C happening and they're mutually exclusive, it's P(A) + P(B) + P(C). Similar analogue for set theory, as another commenter pointed out.