A basket from the market
Amara and her grandfather have come home from the market with a big basket. There are bananas and lemons, apples and strawberries, a cucumber, a pear, an orange and a carrot.
"Let's put everything away," says Grandfather. "But where does each thing go?"
To tidy up, Amara needs a rule — a way of deciding where each thing belongs. Mathematicians do this all the time. They gather things into collections.
Sort the basket
Try sorting the basket yourself. First sort by colour. Then start again and sort by shape.
The market sorting game
Pick something from the basket, then pick the box it belongs in.
The basket
Choose something from the basket.
Did you notice the box for blue things? Nothing went inside it. Is it still a collection? Keep reading to find out!
Big ideas
Definition— collection
A collection is a group of things that we think about together. The things in a collection are called its members.
When something is in a collection, we say it belongs to the collection. The banana belongs to the collection of yellow things. The apple does not.
Definition— the same collection
Two collections are the same when they have exactly the same members. It does not matter what order the members are in.
Definition— the empty collection
A collection with no members at all is called the empty collection. The box of blue things is empty — but it is still a collection!
Let's practise together
Example— Does it belong?
Here is a collection: 🍎 🍌 🍐.
- Is the 🍌 a member? Yes — it is right there.
- Is the 🍋 a member? No — look carefully. There is no lemon.
Example— The same, or different?
Kenji's box has 🍎 and 🍌. Lucía's box has 🍌 and 🍎.
They have the same members, just in a different order. So they are the same collection.
Example— How many?
Count the collection 🍊 🍋 🍎 🍓. Touch each one once and say a number: one, two, three, four. There are 4 members.
Now count them starting from the strawberry instead. You still get 4!
Why counting always gives the same answer
When we count, we match each thing with exactly one counting word: one, two, three, four. Each thing gets one word, and no word is used twice.
If you start somewhere else, you make a different matching — but you still use up the same counting words, because there are just as many things as before. Nothing was added and nothing was taken away.
For grown-ups · what this idea becomes
The idea that "counting is matching" is the seed of a deep idea in mathematics: two collections have the same number of members exactly when their members can be paired off one-to-one. Much later, this pairing idea lets mathematicians compare the sizes of infinite collections.
Gideon's yes-or-no game
Gideon likes statements that are clearly true or clearly false. Look at the collection of yellow things: 🍌 🍋. Is each statement true or false?
- "The banana belongs to the yellow collection." — True.
- "Every member of the yellow collection is long." — False! The lemon is round. One example that breaks a rule is enough to show it is false.
- "There is a member of the blue collection." — False. The blue collection is empty.
For grown-ups · the same ideas in Lean, a proof checker
Computer proof assistants such as Lean can check statements like these. Below, a basket is written as a Lean list. Lean checks that the mango belongs to the basket, that the basket has 3 members, and that nothing belongs to the empty list.
/-- There is a mango in the basket: it is the very first thing in the list. -/
theorem mango_in_basket : "mango" ∈ basket :=
List.Mem.head ["orange", "banana"]/-- The basket holds three pieces of fruit. Lean counts them itself, so `rfl` is enough. -/
theorem basket_count : basket.length = 3 := rfl/-- The empty list has no members at all. -/
theorem nothing_in_empty : ∀ x : String, x ∉ ([] : List String) := by
intro x h
-- A proof of `x ∈ []` would have to come from one of the ways of building membership,
-- but none of them produces an empty list, so there is no case left to consider.
cases hLists remember order, so Lean says the list [1, 2] is different from [2, 1] — but they have exactly the same members. A collection that forgets order is what mathematicians call a set, the subject of the next lesson.
/-- For lists, order matters: `[1, 2]` and `[2, 1]` are different lists.
`decide` asks Lean to compare the two lists element by element. -/
theorem order_matters_for_lists : ([1, 2] : List Nat) ≠ [2, 1] := by decide/-- …but `[1, 2]` and `[2, 1]` have exactly the same members. As *sets* they would be equal;
as *lists* they are not (see `order_matters_for_lists`). -/
theorem same_members : ∀ x : Nat, x ∈ [1, 2] ↔ x ∈ [2, 1] := by
intro x
-- Being in a list means being equal to one of its entries:
-- `x ∈ [1, 2]` unfolds to `x = 1 ∨ x = 2`, and `x ∈ [2, 1]` to `x = 2 ∨ x = 1`.
simp only [List.mem_cons, List.not_mem_nil, or_false]
-- "or" does not care about order.
exact Or.commMargaret counts the market basket
For grown-ups · Margaret's program
This Python program sorts a market basket by kind and by colour, and counts each group. Press Run to try it in your browser. It also tries all 720 orders of a 6-item basket. That checks this basket only; the explanation above tells us why it works for every basket.
"""Sorting and counting a market basket.
A *collection* here is a basket of items. Two mangoes are two different items
that happen to share a name, so the basket is a list (order and repeats are
recorded), not a set. We sort the basket by a property, count each group, and
check that the counts do not depend on the order in which the items were
picked.
Runs unchanged in the browser (Pyodide) using only the standard library.
"""
from collections import Counter
from itertools import permutations
from math import factorial
import textwrap
#: The basket, in the order the items were picked. Each item is
#: (name, kind, colour). Repeated names are separate items.
BASKET = (
("mango", "fruit", "yellow"),
("okra", "vegetable", "green"),
("banana", "fruit", "yellow"),
("lime", "fruit", "green"),
("carrot", "vegetable", "orange"),
("mango", "fruit", "yellow"),
("aubergine", "vegetable", "purple"),
("orange", "fruit", "orange"),
("lime", "fruit", "green"),
("yam", "vegetable", "brown"),
)
#: Positions of each property inside an item tuple.
PROPERTIES = {"name": 0, "kind": 1, "colour": 2}
def value(item, prop):
"""Return the value of property ``prop`` ("name", "kind" or "colour") of an item."""
try:
return item[PROPERTIES[prop]]
except KeyError:
raise ValueError(f"unknown property {prop!r}; expected one of {sorted(PROPERTIES)}") from None
def sort_by(items, *props):
"""Return a new list of the items sorted by the given properties, in priority order.
The original collection is not changed. With no properties, items are sorted
by (name, kind, colour) as plain tuples.
"""
if not props:
return sorted(items)
return sorted(items, key=lambda item: tuple(value(item, p) for p in props))
def group_by(items, prop):
"""Group items by a property: return {value: [items with that value]} with keys sorted."""
groups = {}
for item in items:
groups.setdefault(value(item, prop), []).append(item)
return {key: groups[key] for key in sorted(groups)}
def count_by(items, prop):
"""Count how many items have each value of ``prop``: {value: count}, keys sorted."""
counts = Counter(value(item, prop) for item in items)
return {key: counts[key] for key in sorted(counts)}
def distinct_values(items, prop):
"""Return the set of different values of ``prop`` that occur in the collection."""
return {value(item, prop) for item in items}
def counts_same_in_every_order(items, prop):
"""Check every ordering of ``items``: do the group counts by ``prop`` ever change?
Returns ``(orders_checked, all_same)``. The number of orders is n!, so this
is only practical for small collections (n <= 8 or so).
"""
items = list(items)
reference = count_by(items, prop)
checked = 0
for order in permutations(items):
checked += 1
if count_by(order, prop) != reference:
return checked, False
return checked, True
def format_counts(counts):
"""Format {value: count} as 'a 2, b 3' with the total in brackets."""
parts = ", ".join(f"{key} {n}" for key, n in counts.items())
return f"{parts} (total {sum(counts.values())})"
def main():
basket = list(BASKET)
print(f"A market basket of {len(basket)} items, in the order they were picked:")
print(" " + ", ".join(value(item, "name") for item in basket))
print()
print("Sorted by kind, then colour, then name:")
print(f" {'kind':<10} {'colour':<8} name")
for item in sort_by(basket, "kind", "colour", "name"):
print(f" {value(item, 'kind'):<10} {value(item, 'colour'):<8} {value(item, 'name')}")
print()
by_kind = count_by(basket, "kind")
by_colour = count_by(basket, "colour")
print("Counts by kind: " + format_counts(by_kind))
print("Counts by colour: " + format_counts(by_colour))
sums = " + ".join(str(n) for n in by_kind.values())
print(f"Every item lands in exactly one group, so the groups add up: {sums} = {len(basket)}.")
names = distinct_values(basket, "name")
print(f"Different names: {len(names)} (two mangoes are two items with one name).")
print()
small = basket[:6]
n_orders = factorial(len(small))
print(f"Does order matter? Take the first {len(small)} items and try all {len(small)}! = {n_orders} orders:")
for prop in ("kind", "colour"):
checked, same = counts_same_in_every_order(small, prop)
print(f" counts by {prop:<6} identical in all {checked} orders: {same}")
print()
print(textwrap.fill(
"Epistemic status: the counts above are exact, and all "
f"{n_orders} orders of the 6-item basket were checked, which proves "
"order-independence for that basket only. Why it holds for every finite "
"collection (counting pairs items with 1, 2, 3, ...) is explained in the "
"lesson, not by this program.",
width=78,
))
if __name__ == "__main__":
main()Your turn
Take your time. You can ask for a hint whenever you like.
1. Collections
Warm-upHumanHere is a collection: 🍎 🍌 🍐. Which one is a member of this collection?
2. Collections
Warm-upHumanHow many members does this collection have? 🍊 🥕 🍋 🍎 🍐
3. Collections
CoreHumanKenji's box has 🍎 🍌 🍐. Lucía's box has 🍐 🍎 🍌. Are they the same collection?
4. Collections
CoreHumanThe box for blue fruit is empty. How many members does the empty collection have?
5. Collections
CoreFormalGideon's game: the collection is 🍌 🍋 🥒. Is this statement true or false? "Every member of this collection is yellow."
6. Collections
StretchHumanFor older children: from apple, banana, strawberry and lemon, write the collection of red things. Use words separated by commas, like {kiwi, plum}.
Things that trip people up
Misconception
"An empty box isn't a collection." It is! The empty collection is a real collection — it just has no members. Mathematicians find it very useful.
Misconception
"If I move things around, I get a different collection." Moving members around changes the order, not the collection. Same members means same collection.
Misconception
"Bigger things count more." A big coconut and a small strawberry each count as one member.
Wonder further
Can you put a box inside a box? What is inside a box that holds only an empty box? Follow this trail if you are curious — it is completely optional.
Wonder Trail · Optional · never gradedBoxes inside boxesWhat is inside a box that contains only an empty box? Is it empty? And can every description you can think of make a collection?Follow the trailWhere collections lead
In the next lesson, collections get a grown-up name: sets. Mathematicians write a set with curly brackets, like , and they write the empty set as .
The rule "two collections are the same when they have the same members" is one of the most important rules about sets. It is called the principle of extensionality.
For grown-ups · sorting rules are functions
A sorting rule that sends every item to exactly one box is an example of a function — the subject of lesson 4. Functions, and the ways they combine, eventually lead to category theory. Young learners do not need any of these words; sorting is enough.
Counting around the world, long ago
People have been counting collections for a very long time.
- In southern Africa, a baboon bone with notches cut into it — the Lebombo bone — is more than 40,000 years old. Some researchers think the notches were tally marks for counting, though nobody knows for certain.
- In the Andes mountains of South America, Inca record-keepers used khipu: cords with knots tied in them to record numbers of people, animals and goods.
- Many cultures counted with fingers, toes, pebbles and knots. The word calculate comes from the Latin word for a small pebble.
For grown-ups: further reading
- Paul R. Halmos, Naive Set Theory (1960) — a classic, readable introduction to sets for adults.
- Activities for young children exploring sorting and counting can be found on many free educational sites, such as NRICH's early years collection (nrich.maths.org).
Optional Christian reflection · every one counts
A reflection from the Christian tradition that inspires The Lumenary. It is not part of the mathematics and you are welcome to skip it.
In one of Jesus' parables, a shepherd has a hundred sheep. When one wanders away, he notices — because he knows his flock, one by one — and he goes out to find it (Luke 15:3–7). In that story, counting is a form of care: each member of the collection matters. Mathematics teaches the same habit of attention, and every learner, everywhere, counts.