Boolean Basics - Parenthesis
Does anyone out there remember PEMDAS? I remember learning it back in grade school as a way to remember order of operations… but I never thought it would be helpful as an adult!
If I’m being honest I never thought it would be useful, ever, since I wasn’t into math… that said - I do NOW find it helpful!
Specifically the “P”, which stands for Parenthesis, is the part we’ll dig into today.
As a quick reminder, PEMDAS details the order in which specific mathamatical operations occur in an equation or statement. The letters stand for :
P - Parenthesis
E - Exponents
M - Multiplication
D - Divison
A - Addition
S - Subtraction
So if I remember 5th grade math correctly, any time I see multiplication in a math problem, I do that BEFORE I do any addition. Any time I see exponents, I should figure those out BEFORE I multiply anything… and so on.
Parenthesis, being the first letter, are done before annnnything else. In practice this means you take anything found inside a parenthesis and do it ALL before anything else. For example if we have
3 * ( 5 + 2 )
Then we first do the bit in the parenthesis like this:
3 * ( 5 +2) → 3 * 7
Then the rest
3 * 7 → 21
That’s a simple one… it gets gnarlier if the parenthesis are nested - that is parenthesis inside parenthesis… for example:
(3 * (5 + 2) ) * 3 + ( 2 + 1)
First we would find the “inner most” parenthesis -
(3 * (5 + 2) ) * 3 + ( 2 + 1) → (3 * 7 ) * 3 + ( 2 + 1)
And then the next layer
(3 * 7 ) * 3 + ( 2 + 1) → 21 * 3 + 3
And then the next operation (multiplication)
21 * 3 +3 → 63 + 3
And then addition
63 + 3 → 66
This means we need to be REALLY careful when parenthesis are involved, since if we don’t do those things FIRST, we’ll get a different answer. For most queries this isn’t too complex, as MOST queries only have none, or one, layer of parenthesis.
For the more complex ones, however, it can be beneficial to break them down (similarly to what I did above) to understand how they work.
A general rule I follow is that if I see ANY parenthesis, I take a moment to understand what they’re doing, even if things seem simple. Taking just a moment to unpack what they’re doing will save you a LOT of headache later!