## Math for Computer Science

### Introduction

Just as addition is a shortcut for counting, multiplication is a shortcut for addition: when we need to add multiples of the same number, we can use multiplication. And, since multiplication is simply a shortcut for addition, it follows that multiplying negative numbers is similar to adding negative numbers.

Every month, many people receive bills for things like electricity, water or internet service. Each of these bills implies a debt, or money owed. If we receive 5 bills for \$10 each, then we would owe a total of \$50. Thus, multiplying a positive number (5 bills) and a negative number (-\$10) results in a negative number (-\$50). On the other hand, if we send out 5 bills for \$10 each, we would receive \$50. Thus, multiplying two negative numbers (-5 bills, -\$10) results in a positive number (\$50).

Dividing negative numbers works much the same way. If we receive 5 bills for a total of \$50, then we would owe an average of \$10 on each bill. Thus, dividing a negative number (-\$50) and a positive number (5 bills) results in a negative number (-\$10). Finally, if we send out 5 bills for a total of \$50, we would receive an average of \$10 for each bill. Thus, dividing two negative numbers (-\$50, -5 bills) results in a positive number.

How are negative numbers multiplied and divided?

Multiplying and dividing negative numbers can be summarized with the following rules:

• Multiplying a negative and a positive results in a negative
• Multiplying two negatives results in a positive
• Dividing a negative and a positive results in a negative
• Dividing two negatives results in a positive

How is the multiplication and division of negative numbers used in computer science?

Since computer programs are often used to model concepts that can be described by negative numbers like financial transactions or climate, it is common to multiply or divide negative numbers as well. In a video game, the velocity of an object might be negative, in which case it would be necessary to multiply by that negative number to calculate changes in the objects's position.

### Examples

Multiplying negative numbers

Q: 3 × (-5)

Your browser does not support the canvas element.

A: Multiplying 3 and -5 means counting 3 groups of -5. Negative 5 is represented by an arrow in the negative direction (left). Since we are multiplying by a positive number, we count in the same direction (left). Thus, 3 × (-5) is -15.

Dividing negative numbers

Q: -15 ÷ (-5)

Your browser does not support the canvas element.

A: Dividing -15 and -5 means counting groups of -5 until we get to -15. Negative 5 is represented by an arrow in the negative direction (left). Since we are counting in the same direction (left), the result must be positive. Thus, -15 ÷ (-5) is 3.