{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"counting-before-probability","title":"Counting, and the size of the spaces involved","url":"https://addaly.com/learn/maths-you-need/counting-before-probability","position":28,"of":76,"minutes":8,"answer":"Probability is counting favourable cases over possible ones, and in language and search the possible ones outnumber anything that could ever be enumerated.","keyIdea":"Probability is counting favourable cases over possible ones, and in language and search the possible ones outnumber anything that could ever be enumerated."},"body":{"format":"markdown","text":"## Probability starts as division\n\nThe oldest definition of a probability is a fraction: the number of outcomes you care about, divided by the number of outcomes there are, when all outcomes are equally likely. Rolling a six on a fair die is 1/6. Drawing a heart from a shuffled pack is 13/52.\n\nThe definition is only useful if you can count both numbers, so counting comes first.\n\n## The three counting rules\n\n**Multiplication.** If one choice has `m` options and an independent second choice has `n`, together they have `m × n`. A four-digit PIN has `10 × 10 × 10 × 10 = 10,000` possibilities. Add a fifth digit and it becomes 100,000; each extra position multiplies rather than adds, which is why password length beats password complexity.\n\n**Permutations: order matters.** The number of ways to arrange `k` items chosen from `n`:\n\n```\nP(n, k) = n! / (n - k)!\n```\n\nThe number of ways to rank the top 3 of 10 candidates is `10 × 9 × 8 = 720`.\n\n**Combinations: order does not matter.** The number of ways to choose `k` from `n` disregarding order:\n\n```\nC(n, k) = n! / (k! (n - k)!)\n```\n\nChoosing any 3 of 10 candidates is `720 / 6 = 120`, because each set of three was counted `3! = 6` times in the permutation count.\n\nWorked example with a use: how many ways can you pick 2 features from 20 to test for an interaction? `C(20, 2) = 190`. Test all of them at the usual 5 per cent significance level and you should expect about 9 or 10 to look significant purely by chance. That arithmetic is a whole lesson later in this course, and it starts here.\n\n## The number that should change how you think about language\n\nNow apply multiplication to text. A model with a 50,000-token vocabulary generating a 20-token sentence has\n\n```\n50,000^20 = about 10^94\n```\n\npossible outputs. For scale, there are roughly `10^80` atoms in the observable universe.\n\nTwo consequences follow immediately, and both matter.\n\n**No model has memorised the space.** It could not have. The training data contains perhaps `10^13` tokens, which is a vanishing fraction of `10^94`. Whatever a language model is doing, exhaustive lookup is not available to it, and any explanation of the form \"it just retrieves what it saw\" fails on arithmetic alone. What it does instead is compress the structure of the space into weights, which is why it can produce fluent sentences nobody has ever written.\n\n**Exhaustive search is impossible for generation.** You cannot score all continuations and choose the best. Decoding must be greedy or sampled, one token at a time, which is why the sequence a model produces is generally *not* the highest-probability sequence available. Beam search widens the search a little (keeping perhaps 4 or 8 candidates) and even that is a rounding error against `10^94`.\n\n## The birthday problem, because your intuition is wrong\n\nTwenty-three people in a room. What is the chance two share a birthday? Most people guess a few per cent. The answer is 50.7 per cent.\n\nThe mechanism is that you are not comparing one person against the others; you are comparing every *pair*. With 23 people there are `C(23, 2) = 253` pairs, and 253 chances at 1-in-365 each adds up quickly. Compute it as the complement:\n\n```\nP(no match) = (365/365)(364/365)(363/365) ... (343/365) = 0.493\nP(at least one match) = 1 - 0.493 = 0.507\n```\n\nThis is not a party trick. It is the reason hash collisions appear far earlier than the hash space suggests (a 64-bit hash starts colliding around `2^32` items, not `2^64`) and the reason near-duplicate documents in a corpus are far more common than a per-document duplicate rate implies. Whenever your quantity of interest is about pairs, the count grows with the square.\n\n## Counting with the computer\n\nThe formulas are in the standard library, and you should not implement factorials yourself.\n\n```python\nfrom math import comb, perm, factorial\nprint(comb(20, 2))            # 190\nprint(perm(10, 3))            # 720\nprint(comb(50, 25))           # 126,410,606,437,752\n```\n\nThat last number is worth staring at. Choosing half of a set of 50 has more than 126 trillion possibilities, which is why \"just try all the subsets of features\" is never a plan.\n\n## The limit of the counting definition\n\nEverything above assumes equally likely outcomes, and almost nothing in machine learning has them. The tokens a model might emit are not equally likely; the documents in a corpus are not equally likely queries. The counting definition is where probability starts historically and where it stops being sufficient almost immediately.\n\nWhat replaces it is the idea already introduced in this course: a probability as a stated degree of belief, judged by calibration over many cases. Counting remains useful for sizing a space and for knowing when exhaustive anything is off the table. It is a tool for the denominators, not for the beliefs.\n\n## The rule to keep\n\nMultiply for independent choices, use combinations when order does not matter, and check the size of the space before proposing to search it. When the count involves pairs, expect coincidences far sooner than the raw space size suggests."},"check":{"question":"A deduplication pipeline hashes 5 billion documents with a 64-bit hash and treats a hash match as a duplicate. Roughly when should collisions between genuinely different documents start appearing, and why?","options":[{"text":"Around 2^64 documents, since that is the number of distinct hash values available.","correct":false,"tempting":"Counts values rather than pairs; the first collision is expected far earlier than the space is full."},{"text":"Never in practice, since 64 bits gives 1.8e19 values and 5 billion is a tiny fraction of it.","correct":false,"tempting":"The tiny-fraction reasoning is exactly what the birthday argument overturns, and 5 billion is already past the threshold."},{"text":"Around 2^32, roughly 4.3 billion documents, because the number of pairs grows with the square of the count and collisions are a statement about pairs.","correct":true},{"text":"Only if the hash function is poorly distributed; a good hash avoids collisions entirely below its capacity.","correct":false,"tempting":"Even a perfectly uniform hash collides at this rate; uniformity is what the birthday calculation assumes."}]},"prev":{"slug":"finding-the-learning-rate","title":"The one hyperparameter worth your afternoon","url":"https://addaly.com/learn/maths-you-need/finding-the-learning-rate"},"next":{"slug":"probability-as-belief","title":"Probability is a degree of belief","url":"https://addaly.com/learn/maths-you-need/probability-as-belief"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Counting, and the size of the spaces involved', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/counting-before-probability (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Counting, and the size of the spaces involved","courseTitle":"The Maths You Actually Need","module":{"index":4,"slug":"probability-you-can-rely-on","title":"Probability you can rely on"},"answer":null,"keyIdea":"Probability is counting favourable cases over possible ones, and in language and search the possible ones outnumber anything that could ever be enumerated.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"probability-starts-as-division","runs":[{"text":"Probability starts as division"}]},{"t":"p","runs":[{"text":"The oldest definition of a probability is a fraction: the number of outcomes you care about, divided by the number of outcomes there are, when all outcomes are equally likely. Rolling a six on a fair die is 1/6. Drawing a heart from a shuffled pack is 13/52."}]},{"t":"p","runs":[{"text":"The definition is only useful if you can count both numbers, so counting comes first."}]},{"t":"h2","id":"the-three-counting-rules","runs":[{"text":"The three counting rules"}]},{"t":"p","runs":[{"text":"Multiplication.","b":true},{"text":" If one choice has "},{"text":"m","code":true},{"text":" options and an independent second choice has "},{"text":"n","code":true},{"text":", together they have "},{"text":"m × n","code":true},{"text":". A four-digit PIN has "},{"text":"10 × 10 × 10 × 10 = 10,000","code":true},{"text":" possibilities. Add a fifth digit and it becomes 100,000; each extra position multiplies rather than adds, which is why password length beats password complexity."}]},{"t":"p","runs":[{"text":"Permutations: order matters.","b":true},{"text":" The number of ways to arrange "},{"text":"k","code":true},{"text":" items chosen from "},{"text":"n","code":true},{"text":":"}]},{"t":"code","lang":"","label":"Text","text":"P(n, k) = n! / (n - k)!"},{"t":"p","runs":[{"text":"The number of ways to rank the top 3 of 10 candidates is "},{"text":"10 × 9 × 8 = 720","code":true},{"text":"."}]},{"t":"p","runs":[{"text":"Combinations: order does not matter.","b":true},{"text":" The number of ways to choose "},{"text":"k","code":true},{"text":" from "},{"text":"n","code":true},{"text":" disregarding order:"}]},{"t":"code","lang":"","label":"Text","text":"C(n, k) = n! / (k! (n - k)!)"},{"t":"p","runs":[{"text":"Choosing any 3 of 10 candidates is "},{"text":"720 / 6 = 120","code":true},{"text":", because each set of three was counted "},{"text":"3! = 6","code":true},{"text":" times in the permutation count."}]},{"t":"p","runs":[{"text":"Worked example with a use: how many ways can you pick 2 features from 20 to test for an interaction? "},{"text":"C(20, 2) = 190","code":true},{"text":". Test all of them at the usual 5 per cent significance level and you should expect about 9 or 10 to look significant purely by chance. That arithmetic is a whole lesson later in this course, and it starts here."}]},{"t":"h2","id":"the-number-that-should-change-how-you-think-about-language","runs":[{"text":"The number that should change how you think about language"}]},{"t":"p","runs":[{"text":"Now apply multiplication to text. A model with a 50,000-token vocabulary generating a 20-token sentence has"}]},{"t":"code","lang":"","label":"Text","text":"50,000^20 = about 10^94"},{"t":"p","runs":[{"text":"possible outputs. For scale, there are roughly "},{"text":"10^80","code":true},{"text":" atoms in the observable universe."}]},{"t":"p","runs":[{"text":"Two consequences follow immediately, and both matter."}]},{"t":"p","runs":[{"text":"No model has memorised the space.","b":true},{"text":" It could not have. The training data contains perhaps "},{"text":"10^13","code":true},{"text":" tokens, which is a vanishing fraction of "},{"text":"10^94","code":true},{"text":". Whatever a language model is doing, exhaustive lookup is not available to it, and any explanation of the form “it just retrieves what it saw” fails on arithmetic alone. What it does instead is compress the structure of the space into weights, which is why it can produce fluent sentences nobody has ever written."}]},{"t":"p","runs":[{"text":"Exhaustive search is impossible for generation.","b":true},{"text":" You cannot score all continuations and choose the best. Decoding must be greedy or sampled, one token at a time, which is why the sequence a model produces is generally "},{"text":"not","i":true},{"text":" the highest-probability sequence available. Beam search widens the search a little (keeping perhaps 4 or 8 candidates) and even that is a rounding error against "},{"text":"10^94","code":true},{"text":"."}]},{"t":"h2","id":"the-birthday-problem-because-your-intuition-is-wrong","runs":[{"text":"The birthday problem, because your intuition is wrong"}]},{"t":"p","runs":[{"text":"Twenty-three people in a room. What is the chance two share a birthday? Most people guess a few per cent. The answer is 50.7 per cent."}]},{"t":"p","runs":[{"text":"The mechanism is that you are not comparing one person against the others; you are comparing every "},{"text":"pair","i":true},{"text":". With 23 people there are "},{"text":"C(23, 2) = 253","code":true},{"text":" pairs, and 253 chances at 1-in-365 each adds up quickly. Compute it as the complement:"}]},{"t":"code","lang":"","label":"Text","text":"P(no match) = (365/365)(364/365)(363/365) ... (343/365) = 0.493\nP(at least one match) = 1 - 0.493 = 0.507"},{"t":"p","runs":[{"text":"This is not a party trick. It is the reason hash collisions appear far earlier than the hash space suggests (a 64-bit hash starts colliding around "},{"text":"2^32","code":true},{"text":" items, not "},{"text":"2^64","code":true},{"text":") and the reason near-duplicate documents in a corpus are far more common than a per-document duplicate rate implies. Whenever your quantity of interest is about pairs, the count grows with the square."}]},{"t":"h2","id":"counting-with-the-computer","runs":[{"text":"Counting with the computer"}]},{"t":"p","runs":[{"text":"The formulas are in the standard library, and you should not implement factorials yourself."}]},{"t":"code","lang":"python","label":"Python","text":"from math import comb, perm, factorial\nprint(comb(20, 2))            # 190\nprint(perm(10, 3))            # 720\nprint(comb(50, 25))           # 126,410,606,437,752"},{"t":"p","runs":[{"text":"That last number is worth staring at. Choosing half of a set of 50 has more than 126 trillion possibilities, which is why “just try all the subsets of features” is never a plan."}]},{"t":"h2","id":"the-limit-of-the-counting-definition","runs":[{"text":"The limit of the counting definition"}],"role":"limit"},{"t":"p","runs":[{"text":"Everything above assumes equally likely outcomes, and almost nothing in machine learning has them. The tokens a model might emit are not equally likely; the documents in a corpus are not equally likely queries. The counting definition is where probability starts historically and where it stops being sufficient almost immediately."}]},{"t":"p","runs":[{"text":"What replaces it is the idea already introduced in this course: a probability as a stated degree of belief, judged by calibration over many cases. Counting remains useful for sizing a space and for knowing when exhaustive anything is off the table. It is a tool for the denominators, not for the beliefs."}]},{"t":"h2","id":"the-rule-to-keep","runs":[{"text":"The rule to keep"}]},{"t":"p","runs":[{"text":"Multiply for independent choices, use combinations when order does not matter, and check the size of the space before proposing to search it. When the count involves pairs, expect coincidences far sooner than the raw space size suggests."}]}],"check":{"question":[{"text":"A deduplication pipeline hashes 5 billion documents with a 64-bit hash and treats a hash match as a duplicate. Roughly when should collisions between genuinely different documents start appearing, and why?"}],"options":[{"text":[{"text":"Around 2^64 documents, since that is the number of distinct hash values available."}],"correct":false,"tempting":[{"text":"Counts values rather than pairs; the first collision is expected far earlier than the space is full."}]},{"text":[{"text":"Never in practice, since 64 bits gives 1.8e19 values and 5 billion is a tiny fraction of it."}],"correct":false,"tempting":[{"text":"The tiny-fraction reasoning is exactly what the birthday argument overturns, and 5 billion is already past the threshold."}]},{"text":[{"text":"Around 2^32, roughly 4.3 billion documents, because the number of pairs grows with the square of the count and collisions are a statement about pairs."}],"correct":true,"tempting":null},{"text":[{"text":"Only if the hash function is poorly distributed; a good hash avoids collisions entirely below its capacity."}],"correct":false,"tempting":[{"text":"Even a perfectly uniform hash collides at this rate; uniformity is what the birthday calculation assumes."}]}],"order":[1,0,2,3],"why":null},"prev":{"slug":"finding-the-learning-rate","title":"The one hyperparameter worth your afternoon","minutes":9},"next":{"slug":"probability-as-belief","title":"Probability is a degree of belief","minutes":7}}}