TExcelTAD

Addition

Addition combines amounts into a total. It is the first operation everyone learns, and it is worth looking at again with fresh eyes: the column method with carrying is a genuine algorithm, the same one a computer's processor runs in binary billions of times a second.

Words and symbols

In 23+19=4223 + 19 = 42, the numbers being added (23 and 19) are the addends or terms, and the result (42) is the sum or total. On the number line, adding a positive number means moving right: start at 23, take 19 steps right, land on 42.

Two facts make addition flexible:

  • Order does not matter: 19+23=23+1919 + 23 = 23 + 19 (the commutative property).
  • Grouping does not matter: (5+7)+3=5+(7+3)(5 + 7) + 3 = 5 + (7 + 3) (the associative property).

They get their own lesson in Properties of Operations. For now they explain why you can add a shopping list in any order.

Column addition with carrying

To add larger numbers by hand, line them up by place value and add each column from right to left. When a column adds up to 10 or more, write the ones digit and carry the tens digit into the next column.

text
    ¹ ¹
    4 7 8
  + 3 6 5
  -------
    8 4 3

ones:     8 + 5     = 13 → write 3, carry 1
tens:     7 + 6 + 1 = 14 → write 4, carry 1
hundreds: 4 + 3 + 1 = 8  → write 8

The carry is place value at work: 13 ones are 1 ten and 3 ones, so the extra ten moves to the tens column.

Here is the same algorithm in Python, working on lists of digits the way you would on paper:

python · try it yourself
def column_add(a, b):
    da = [int(c) for c in str(a)][::-1]   # digits, ones first
    db = [int(c) for c in str(b)][::-1]
    result, carry = [], 0
    for i in range(max(len(da), len(db))):
        x = da[i] if i < len(da) else 0
        y = db[i] if i < len(db) else 0
        s = x + y + carry
        result.append(s % 10)      # digit to write
        carry = s // 10            # digit to carry
        print(f"column {i}: {x} + {y} + carry -> {s}, write {s % 10}, carry {carry}")
    if carry:
        result.append(carry)
    return int("".join(str(d) for d in reversed(result)))

print("478 + 365 =", column_add(478, 365), "check:", 478 + 365)
column 0: 8 + 5 + carry -> 13, write 3, carry 1
column 1: 7 + 6 + carry -> 14, write 4, carry 1
column 2: 4 + 3 + carry -> 8, write 8, carry 0
478 + 365 = 843 check: 843

The % 10 and // 10 from Place Value do the "write" and "carry" steps.

Mental addition tricks

  • Make a ten: 8+7=8+2+5=158 + 7 = 8 + 2 + 5 = 15 (split 7 into 2 and 5 to complete the ten).
  • Round and adjust: 47+29=47+30−1=7647 + 29 = 47 + 30 - 1 = 76.
  • Add the big places first: 340+280=500+120=620340 + 280 = 500 + 120 = 620.
  • Pair friendly numbers: 17+36+23+4=(17+23)+(36+4)=40+40=8017 + 36 + 23 + 4 = (17 + 23) + (36 + 4) = 40 + 40 = 80.

The last trick uses both properties above: you may reorder and regroup however you like.

Adding many numbers

Python's sum adds a whole list. A running total (also called a cumulative sum) shows the total after each step, like a bank statement balance:

python · try it yourself
from itertools import accumulate

steps = [4200, 6100, 3850, 7020, 5400]   # steps walked each day
print("week total:", sum(steps))
print("running totals:", list(accumulate(steps)))
print("sum of 1..100:", sum(range(1, 101)))
week total: 26570
running totals: [4200, 10300, 14150, 21170, 26570]
sum of 1..100: 5050

The sum 1+2+…+100=50501 + 2 + \ldots + 100 = 5050 has a famous shortcut: pair the first and last numbers (1+1001 + 100), the second and second-last (2+992 + 99), and so on. That gives 50 pairs each worth 101, so 50×101=505050 \times 101 = 5050. In general 1+2+…+n=n×(n+1)÷21 + 2 + \ldots + n = n \times (n + 1) \div 2.

In software

  • Processors add in binary with exactly this carry algorithm, built from logic gates (a "ripple-carry adder"). The carry out of the top column is why fixed-size integers can overflow.
  • Big-number libraries (Python's unlimited ints, cryptography code) add numbers too large for hardware by splitting them into chunks and carrying between chunks.
  • Running totals power progress bars, account balances and the prefix-sum trick in algorithms, which answers "what is the total of items 3 to 7?" with one subtraction.

Exercises

Exercise 1: Column addition

Add 5 896+2 4375\,896 + 2\,437 by hand, showing each carry.

Answer

8 333

Solution
text
ones:      6 + 7     = 13 → write 3, carry 1
tens:      9 + 3 + 1 = 13 → write 3, carry 1
hundreds:  8 + 4 + 1 = 13 → write 3, carry 1
thousands: 5 + 2 + 1 = 8  → write 8
result: 8 333

Exercise 2: Mental math

Use a mental trick to compute 198+357198 + 357.

Answer

555

Solution

Round and adjust: 198=200−2198 = 200 - 2, so 198+357=200+357−2=557−2=555198 + 357 = 200 + 357 - 2 = 557 - 2 = 555.

Exercise 3: Gauss's shortcut

Find 1+2+…+601 + 2 + \ldots + 60 with the formula n(n+1)÷2n(n + 1) \div 2, then check it with sum.

Answer

1 830

Solution
n=60:60×61÷2=3 660÷2=1 830n = 60{:}\quad 60 \times 61 \div 2 = 3\,660 \div 2 = 1\,830
python · try it yourself
n = 60
print(n * (n + 1) // 2, sum(range(1, n + 1)))
1830 1830

Exercise 4: Count the carries

Change column_add (or write your own loop) to count how many carries happen when adding 99 999+199\,999 + 1.

Answer

5 carries; the sum is 100 000.

Solution

Every column gives 9+0+carry=109 + 0 + \text{carry} = 10 except the first (9+1=109 + 1 = 10), so each of the five columns carries 1.

python · try it yourself
a, b = 99999, 1
carries, carry = 0, 0
while a > 0 or b > 0:
    s = a % 10 + b % 10 + carry
    carry = s // 10
    carries += carry
    a, b = a // 10, b // 10
print("carries:", carries, " sum:", 99999 + 1)
carries: 5  sum: 100000

Test yourself

In 365+478365 + 478, what is carried into the tens column?

  1. 0
  2. 1
  3. 3
  4. 13

Which is the quickest way to compute 26+39+7426 + 39 + 74 in your head?

  1. Add left to right: 26+3926 + 39 first
  2. Pair 26+74=10026 + 74 = 100, then add 39
  3. Multiply 26×3926 \times 39
  4. Round everything to the nearest thousand

What is 1+2+3+…+201 + 2 + 3 + \ldots + 20?

  1. 200
  2. 400
  3. 210
  4. 220