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

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.2.3 Distributive Multiplication

Since this is true, then when faced with the following:

it can be seen as (2 × 5) + (2 × 10)

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:

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.

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:

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.

There are some basic rules to follow when working with exponents.

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.

Категории