Hello again,
I'll post the next Part here. Once i have the format
of the web site set up properly i'll start posting
there and linking from here.
Serial: EE-Ch0001-p102-{A939C0B7-558E-4687-9271-AB92E4935FD0}
We need to establish some ground rules when evaluating
numerical expressions. These rules have long been set
almost since the dawn of man's desire to understand
the world numerically.
REPLACEMENT, ORDER OF OPERATIONS, OPERATOR PRECEDENCE
When calculating an expression, we proceed from left to right
once the precedence of all the operators is the same.
To calculate 1+2+3 we start with 1+2, and to calculate
2*3*4 we start with 2*3.
When we have to calculate a multi-term expression we cant do
the whole thing at once, we have to do two terms at a time
or evaluate a product first.
We can do:
1+3
right away without any problem because there are only two terms,
but when we go to do:
4+2+7
we have to do two terms first, then continue to the next term
something like this:
4+2 gives us 6, then 6+7 gives us 13.
Notice we had to do two terms first, then proceed to the next term
in order to calculate the whole expression. We cant add all three
numbers all at the same time really.
This becomes even more apparent when we try to add many terms:
1+2+3+4+5+6-7+9
We have to start somewhere, and the rule is we have to start at the
leftmost term and proceed to the right (once we reduce the expression
to all additions and subtractions or the operators have all the
same precedence).
If you want to keep track of intermediate results the following helps:
We start with the full expression:
1+2+3+4+5+6-7+9
Then, we start with the left most terms,
1+2
We do the operation, then replace the two terms with the
result. Since 1+2 equals 3 we replace these two terms with
the number 3, and we get:
3+3+4+5+6-7+9
Next we do '3+3' and get 6, and replace '3+3' with '6':
6+4+5+6-7+9
Next, 6+4 and replace that:
10+5+6-7+9
Likewise 10+5:
15+6-7+9
15+6:
21-7+9
21-7:
14+9
Now we are down to our last two terms, so we do the operation and
we are done...
14+9 equals 23:
23
And we have the result!
1+2+3+4+5+6-7+9=23
In each case i simply copied the remaining expression and pasted it
to the next line, then replaced the left two terms with the result
from doing the operation between those two terms.
Notice each time we do this we reduce the expression by one term.
Eventually we get all the terms combined into one single term,
which is of course the answer.
It's very important to do the left two terms before anything else,
because we MUST proceed from left to right in order to evaluate
expressions when all the operators are of the same precedence.
Now so far we've only done expressions with addition and subtraction.
When we do addition and subtraction with multiplication and division,
we have to take into account the precedence of the operators.
Precedence simply means operators with higher precedence get
calculated first. Of course we have to know the precedence of
operators in order to know which ones are higher, so here's a list:
addition 1
subtraction 1
multiplication 2
division 2
Notice some are higher then others.
Now let us see how this affects our calculations...
Calculate 1+2*3=? (the question mark indicates a number we dont know yet)
Because multiplication is higher than addition, we have to start with
that...
We start with the original expression:
1+2*3=?
calculate 2*3 and replace it with it's result, 6:
1+6=?
Now we do the last two terms and get 7, so we have the answer:
1+2*3=7
Notice that if we do the '1+2' first we would get the wrong answer:
1+2=3, and 3*3=9, and '9' is not the correct answer...
1+2*3<>9
This should show how important operator precedence is.
Self test exercises
1. compute the answer to: 3+4*5+7-2*2 = ?
2. compute the answer to: 3+4*3*8 = ?
3. compute the answer to: 2+3*5+1 = ?
4. compute the answer to: 8-3*2+3*2*3 = ?
5. compute the answer to: 8-3*2+3*2+3 = ?
6. compute the answer to: ? = 8/2+3*2+3*2-3
See ya next time,
Al