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 , 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: (the commutative property).
- Grouping does not matter: (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.
¹ ¹
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 8The 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:
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: (split 7 into 2 and 5 to complete the ten).
- Round and adjust: .
- Add the big places first: .
- Pair friendly numbers: .
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:
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 has a famous shortcut: pair the first and last numbers (), the second and second-last (), and so on. That gives 50 pairs each worth 101, so . In general .
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 by hand, showing each carry.
Answer
8 333
Solution
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 333Exercise 2: Mental math
Use a mental trick to compute .
Answer
555
Solution
Round and adjust: , so .
Exercise 3: Gauss's shortcut
Find with the formula , then check it with sum.
Answer
1 830
Solution
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 .
Answer
5 carries; the sum is 100 000.
Solution
Every column gives except the first (), so each of the five columns carries 1.
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 , what is carried into the tens column?
- 0
- 1
- 3
- 13
Which is the quickest way to compute in your head?
- Add left to right: first
- Pair , then add 39
- Multiply
- Round everything to the nearest thousand
What is ?
- 200
- 400
- 210
- 220