Introduction to Game Programming with C++ (Wordware Game Developers Library)
2.2 Rules of Algebra
Arithmetic is governed by a number of operations, namely addition, subtraction, multiplication, and division, all of which need to be performed in a particular way. Algebra also has laws of its own and specific orders of operation.
2.2.1 Parentheses
-
(2 + 5) − 5
The bracket symbols () are called parentheses and are used to enclose part or parts of an expression as illustrated above. When faced with parentheses, it means we are to treat the expression enclosed inside the brackets as a single number. In other words, we must first add 2 and 5 before subtracting 5. So the above expression could be written as 7 − 5 = 2. So, parentheses indicate priority.
Note | This is an important rule because 10 − (3 + 5) is not the same as 10 − 3 + 5. 10− (3 + 5) leads to 10 − 8 = 2. But 10 − 3 + 5 leads to 7 + 5 = 12. |
2.2.2 Multiplication and Factors
As mentioned in the previous chapter, when numbers are multiplied their result is the product. The numbers that were multiplied are called factors, and the product is a multiple of them. In multiplication, the order of factors does not matter-it is said to be commutative.In other words:
-
2 × 3 × 5 × 7 is the same as 3 × 2 × 7 × 5
2.2.3 Distributive Multiplication
-
2 × 5 = 10 is the same as (2 × 3) + (2 × 2) = 10
Since this is true, then when faced with the following:
-
2 × (5 + 10)
it can be seen as (2 × 5) + (2 × 10)
-
10 + 20 = 30
The factor of 2 is distributed to both 2 and 5, and the sum of the products is added. This is called the distributive rule. The result would have been the same if we had added 5 + 10 first and then multiplied by 2. When all the numbers are known, it doesn't matter whether the numbers inside parentheses are added first or not, but as we shall see, in algebra, where some numbers might be letters, it becomes an important law. The following algebraic expression shows this:
-
A × (B + C) = (A × B) + (A × C)
2.2.4 Division and Multiplication
If a number A is divided by another B and the result is C, then if C is multiplied by B, the result will be A. I have intentionally written this in an algebraic form. This statement, in other words, means that a number will not change if it is divided and then multiplied by the same number.
-
(4/2) × 2 = 4
2.2.5 Multiplication Notation
In arithmetic where numbers are known, multiplication is written with a cross symbol × (such as 2 × 3). In algebra, multiplication between two unknown numbers or one known and one unknown number is not written with the cross. Instead, the numbers can be placed side by side without a symbol and multiplication is automatically implied, such as:
-
ab = a × b
-
2b = 2 × b
-
2ab = 2 × a × b
Note | If two numbers are known, such as 2 × 5, then the cross symbol can be used. Often, however, a middle dot symbol (·) is used so that no confusion arises between x as a letter and × as a multiplication symbol. So, in algebra 2 × 5 would be 2 · 5. If the two factors were known, such as the case here, they would be simplified; therefore, 2 × 5 would be written as 10. |
2.2.6 Indices or Exponents
A number is said to be squared when multiplied by itself. 2 × 2 is called "2 squared" and 2 × 2 × 2 is called "2 cubed." Whenever a number is multiplied in this way it is said to be raised to a power. The first few powers of 2 are: 2 × 2 = 4, 2 × 2 × 2 = 8, 2 × 2 × 2 × 2 = 16, and so on. 2 × 2 is therefore said to be 2 to the power of 2, and 2 × 2 × 2 is said to be 2 to the power of 3. Rather than write this repeated multiplication as 2 × 2 × 2, such expressions are abbreviated using a superscript number. So 2 × 2 × 2 is instead written as 23, and 2 × 2 × 2 × 2 is written as 24. This small number, which indicates the power a number is raised to, is called the exponent or index (plural: indices). In this book we use the term exponent. The number itself, in this case 2, is called the base.
-
52 (5 is the base and 2 is the exponent)
-
a2 (a is the base and 2 is the exponent)
-
5a2 (a is the base and 2 is the exponent)
-
(5a)3 (5a is the base and 3 is the exponent)
There are some basic rules to follow when working with exponents.
-
Multiplying the same base numbers with exponents
-
a3 × a9 = a3+9 = a12
If two numbers of the same base have exponents and the two base numbers are being multiplied, then the exponents can be added. So, 28 × 23 = 211, because 8 + 3 = 11.
-
-
Factors raised to powers
-
(ab)2 = a2b2
If the base consists of factors (numbers multiplied together), then each factor must be raised to that power. So (2 × 7)2 = 4 × 49.
-
-
Powers raised to powers
-
(25)5 = 25×5 = 225
If a power is raised to a power, the exponents must be multiplied.
-
-
Division of numbers with exponents
-
a5 / a3 = a5−3 = a2
If multiplication of two powers leads to adding exponents, then since division is said to be the inverse of multiplication, division of powers leads to subtracting their exponents.
-
-
Power of 0
-
a0 = 1
Any number raised to the power of 0 is 1. This is because, as seen in division with exponents: 21 = 2 and 21 / 21 = 1. But 21 / 21 = 21−1 = 20. Therefore, 20 = 1.
-
Note | There are other aspects related to exponents, namely negative exponents and fractional exponents, that are beyond the scope of this book. See the books listed in Appendix F for more information. |
Категории