{"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":"power-laws-and-log-log-plots","title":"Power laws, and the straight line on a log-log plot","url":"https://addaly.com/learn/maths-you-need/power-laws-and-log-log-plots","position":48,"of":76,"minutes":9,"answer":"A power law is a straight line on log-log axes whose slope is the exponent, so a slope of −0.5 means quadrupling the input halves the output.","keyIdea":"A power law is a straight line on log-log axes whose slope is the exponent, so a slope of −0.5 means quadrupling the input halves the output, and a straight line over two decades is weak evidence for extrapolating that promise further."},"body":{"format":"markdown","text":"## Two shapes that look alike and are not\n\nAn exponential, `y = c × b^x`, grows or decays by a fixed factor for each fixed *step* in `x`. A power law, `y = c × x^k`, changes by a fixed factor for each fixed *ratio* in `x`: doubling `x` always multiplies `y` by `2^k`, whether `x` goes from 1 to 2 or from a million to two million. Both curve on ordinary axes, and both are easily mistaken for each other by eye.\n\nLogs separate them. Take logs of the power law:\n\n```\nlog y = log c + k × log x\n```\n\nThat is a straight line in `log x` with slope `k`. So a power law is a straight line on **log-log** axes, and the exponent is the slope you can read off with a ruler. An exponential is a straight line on **log-linear** axes, y logged and x not. Plot the data both ways; whichever is straight tells you which law you have.\n\n## Reading the slope\n\nTwo points on a log-log plot, `(10, 500)` and `(1000, 5)`:\n\n```\nk = (log 5 − log 500) / (log 1000 − log 10)\n  = (0.699 − 2.699) / (3 − 1)\n  = −2 / 2 = −1\n```\n\nSo `y ∝ 1/x`. The base of the log does not matter, since it cancels in the ratio. Any two points far enough apart give the slope; use points at least a decade apart, because near points make the slope hostage to noise.\n\nA slope is a promise about doubling. A slope of `−0.5` says that quadrupling `x` halves `y`, since `4^(−0.5) = 0.5`. A slope of `−0.05` says doubling `x` cuts `y` by `2^(−0.05)`, a factor of 0.966: three and a half per cent. Small exponents are the mathematical form of diminishing returns, and they are what the loss-versus-compute curves in `how-llms-work` look like. Read the slope before you read the headline.\n\n## Zipf, and why the vocabulary has a tail\n\nRank the words of a large English text by frequency. The most common, \"the\", is about 7 per cent of all words. The second is about half that, the tenth about a tenth, the hundredth about a hundredth. Frequency is roughly proportional to `1 / rank`, a power law with exponent `−1`, and it holds across languages and across centuries of text. This is Zipf's law.\n\n> Figure: Zipf's law: a straight line whose slope is the exponent. Line chart of Log base ten of its count per million words against Log base ten of the word's frequency rank: English word frequencies, rank 1 to 10,000 (0, 4.845) (1, 3.845) (2, 2.845) (3, 1.845) (4, 0.845). A slope of minus one means frequency is proportional to one over rank, so the hundredth commonest word appears about a hundredth as often as the first. Read the slope with a ruler, then ask what the line is being asked to promise beyond the points it was drawn through.\n\nIt has consequences you have met. A tokeniser gives short, single tokens to common words because they pay for themselves, and splits rare words into pieces because a vocabulary slot for each would be wasted; that is the head of the distribution being served and the tail being approximated. It also means the tail is enormous: with exponent `−1`, half of all the *distinct* words in a corpus appear once, and no amount of data gets the model many examples of any one of them. Rare-word failures are not a bug in a particular model. They are the arithmetic of the distribution the model was trained on.\n\n## Power laws and heavy tails\n\nThe heavy-tailed distributions of module 4 are usually power laws in their tails. A Pareto distribution with tail exponent `α` has infinite variance when `α ≤ 2` and no finite mean at all when `α ≤ 1`. City sizes, wealth, file sizes, the number of followers an account has, and the length of the longest request in a day all sit in this family, which is why their averages misbehave and their percentiles do not. When you see a straight line on a log-log histogram, expect the mean to be unreliable, and expect the largest observation to grow as you collect more data rather than settling down.\n\n## Where the straight line lies\n\nA straight line over one or two decades is weak evidence of a power law. A log-normal distribution looks straight on log-log axes over a limited range; so do several others. The distinguishing region is the far tail, which is exactly where you have the fewest points. Three specific cautions:\n\n- **Do not fit the exponent by least squares on a log-log histogram.** Binning and logging make the noise unequal across the line, and the fit is biased. The maximum-likelihood estimate for a tail exponent from `n` values above a threshold `x_min` is one formula: `α = 1 + n / Σ ln(x_i / x_min)`. It takes one line and it is what the `powerlaw` package computes.\n- **Do not extrapolate the line.** A slope measured between `10^3` and `10^5` says nothing about `10^7`. The curves you will most want to extrapolate, of loss against scale, are the ones with the fewest points at the far end.\n- **Check the exponent's uncertainty.** With twenty points, the slope carries an error bar of several tenths, and a slope of `−1.1` against `−0.9` is not a distinction the data can make.\n\n## In code\n\n```python\nimport numpy as np, matplotlib.pyplot as plt\nplt.loglog(x, y, \"o\")                        # straight means power law\nk, logc = np.polyfit(np.log(x), np.log(y), 1) # slope k; fine for a curve, not a histogram\n```\n\nThe `polyfit` on logs is acceptable for a smooth curve such as a loss against dataset size, where each point is a measurement rather than a count. For a histogram of a heavy-tailed quantity, use the likelihood formula. Both are free, and both fit on a laptop. The skill being trained is the one you use every time a paper shows a straight line on log axes: find the slope, find its uncertainty, and ask what the line is being asked to promise beyond the data it was drawn through."},"check":{"question":"Error against dataset size is a straight line on log-log axes with slope −0.5. What does going from 10,000 to 40,000 examples buy?","options":[{"text":"Error halves.","correct":true},{"text":"Error falls by 0.5, since that is the slope.","correct":false,"tempting":"Reads the slope as a linear change in the error rather than an exponent; on log-log axes the slope multiplies, it does not subtract."},{"text":"Error falls to a quarter, because the dataset grew four times.","correct":false,"tempting":"Applies the growth factor directly; the factor is raised to the exponent, and 4 to the power −0.5 is one half, not one quarter."},{"text":"It cannot be said without the line's intercept.","correct":false,"tempting":"The intercept sets the absolute error, but the ratio between two sizes depends only on the slope."}]},"prev":{"slug":"log-sum-exp-and-stable-softmax","title":"The log-sum-exp trick, and why exp(1000) is not a number","url":"https://addaly.com/learn/maths-you-need/log-sum-exp-and-stable-softmax"},"next":{"slug":"estimators-and-why-n-minus-one","title":"An estimator is a recipe, and why the variance divides by n − 1","url":"https://addaly.com/learn/maths-you-need/estimators-and-why-n-minus-one"},"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) 'Power laws, and the straight line on a log-log plot', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/power-laws-and-log-log-plots (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":"Power laws, and the straight line on a log-log plot","courseTitle":"The Maths You Actually Need","module":{"index":5,"slug":"logs-information-and-loss","title":"Logarithms, information and the shape of a loss"},"answer":null,"keyIdea":"A power law is a straight line on log-log axes whose slope is the exponent, so a slope of −0.5 means quadrupling the input halves the output, and a straight line over two decades is weak evidence for extrapolating that promise further.","hero":{"kind":"figure","figure":{"t":"figure","label":"Figure","figure":{"caption":"A slope of minus one means frequency is proportional to one over rank, so the hundredth commonest word appears about a hundredth as often as the first. Read the slope with a ruler, then ask what the line is being asked to promise beyond the points it was drawn through.","series":[{"label":"English word frequencies, rank 1 to 10,000","points":[[0,4.845],[1,3.845],[2,2.845],[3,1.845],[4,0.845]]}],"title":"Zipf’s law: a straight line whose slope is the exponent","type":"line","xLabel":"Log base ten of the word’s frequency rank","yLabel":"Log base ten of its count per million words"},"alt":"Figure: Zipf’s law: a straight line whose slope is the exponent. Line chart of Log base ten of its count per million words against Log base ten of the word’s frequency rank: English word frequencies, rank 1 to 10,000 (0, 4.845) (1, 3.845) (2, 2.845) (3, 1.845) (4, 0.845). A slope of minus one means frequency is proportional to one over rank, so the hundredth commonest word appears about a hundredth as often as the first. Read the slope with a ruler, then ask what the line is being asked to promise beyond the points it was drawn through."}},"blocks":[{"t":"h2","id":"two-shapes-that-look-alike-and-are-not","runs":[{"text":"Two shapes that look alike and are not"}]},{"t":"p","runs":[{"text":"An exponential, "},{"text":"y = c × b^x","code":true},{"text":", grows or decays by a fixed factor for each fixed "},{"text":"step","i":true},{"text":" in "},{"text":"x","code":true},{"text":". A power law, "},{"text":"y = c × x^k","code":true},{"text":", changes by a fixed factor for each fixed "},{"text":"ratio","i":true},{"text":" in "},{"text":"x","code":true},{"text":": doubling "},{"text":"x","code":true},{"text":" always multiplies "},{"text":"y","code":true},{"text":" by "},{"text":"2^k","code":true},{"text":", whether "},{"text":"x","code":true},{"text":" goes from 1 to 2 or from a million to two million. Both curve on ordinary axes, and both are easily mistaken for each other by eye."}]},{"t":"p","runs":[{"text":"Logs separate them. Take logs of the power law:"}]},{"t":"code","lang":"","label":"Text","text":"log y = log c + k × log x"},{"t":"p","runs":[{"text":"That is a straight line in "},{"text":"log x","code":true},{"text":" with slope "},{"text":"k","code":true},{"text":". So a power law is a straight line on "},{"text":"log-log","b":true},{"text":" axes, and the exponent is the slope you can read off with a ruler. An exponential is a straight line on "},{"text":"log-linear","b":true},{"text":" axes, y logged and x not. Plot the data both ways; whichever is straight tells you which law you have."}]},{"t":"h2","id":"reading-the-slope","runs":[{"text":"Reading the slope"}]},{"t":"p","runs":[{"text":"Two points on a log-log plot, "},{"text":"(10, 500)","code":true},{"text":" and "},{"text":"(1000, 5)","code":true},{"text":":"}]},{"t":"code","lang":"","label":"Text","text":"k = (log 5 − log 500) / (log 1000 − log 10)\n  = (0.699 − 2.699) / (3 − 1)\n  = −2 / 2 = −1"},{"t":"p","runs":[{"text":"So "},{"text":"y ∝ 1/x","code":true},{"text":". The base of the log does not matter, since it cancels in the ratio. Any two points far enough apart give the slope; use points at least a decade apart, because near points make the slope hostage to noise."}]},{"t":"p","runs":[{"text":"A slope is a promise about doubling. A slope of "},{"text":"−0.5","code":true},{"text":" says that quadrupling "},{"text":"x","code":true},{"text":" halves "},{"text":"y","code":true},{"text":", since "},{"text":"4^(−0.5) = 0.5","code":true},{"text":". A slope of "},{"text":"−0.05","code":true},{"text":" says doubling "},{"text":"x","code":true},{"text":" cuts "},{"text":"y","code":true},{"text":" by "},{"text":"2^(−0.05)","code":true},{"text":", a factor of 0.966: three and a half per cent. Small exponents are the mathematical form of diminishing returns, and they are what the loss-versus-compute curves in "},{"text":"how-llms-work","code":true},{"text":" look like. Read the slope before you read the headline."}]},{"t":"h2","id":"zipf-and-why-the-vocabulary-has-a-tail","runs":[{"text":"Zipf, and why the vocabulary has a tail"}]},{"t":"p","runs":[{"text":"Rank the words of a large English text by frequency. The most common, “the”, is about 7 per cent of all words. The second is about half that, the tenth about a tenth, the hundredth about a hundredth. Frequency is roughly proportional to "},{"text":"1 / rank","code":true},{"text":", a power law with exponent "},{"text":"−1","code":true},{"text":", and it holds across languages and across centuries of text. This is Zipf’s law."}]},{"t":"p","runs":[{"text":"It has consequences you have met. A tokeniser gives short, single tokens to common words because they pay for themselves, and splits rare words into pieces because a vocabulary slot for each would be wasted; that is the head of the distribution being served and the tail being approximated. It also means the tail is enormous: with exponent "},{"text":"−1","code":true},{"text":", half of all the "},{"text":"distinct","i":true},{"text":" words in a corpus appear once, and no amount of data gets the model many examples of any one of them. Rare-word failures are not a bug in a particular model. They are the arithmetic of the distribution the model was trained on."}]},{"t":"h2","id":"power-laws-and-heavy-tails","runs":[{"text":"Power laws and heavy tails"}]},{"t":"p","runs":[{"text":"The heavy-tailed distributions of module 4 are usually power laws in their tails. A Pareto distribution with tail exponent "},{"text":"α","code":true},{"text":" has infinite variance when "},{"text":"α ≤ 2","code":true},{"text":" and no finite mean at all when "},{"text":"α ≤ 1","code":true},{"text":". City sizes, wealth, file sizes, the number of followers an account has, and the length of the longest request in a day all sit in this family, which is why their averages misbehave and their percentiles do not. When you see a straight line on a log-log histogram, expect the mean to be unreliable, and expect the largest observation to grow as you collect more data rather than settling down."}]},{"t":"h2","id":"where-the-straight-line-lies","runs":[{"text":"Where the straight line lies"}]},{"t":"p","runs":[{"text":"A straight line over one or two decades is weak evidence of a power law. A log-normal distribution looks straight on log-log axes over a limited range; so do several others. The distinguishing region is the far tail, which is exactly where you have the fewest points. Three specific cautions:"}]},{"t":"ul","items":[[{"text":"Do not fit the exponent by least squares on a log-log histogram.","b":true},{"text":" Binning and logging make the noise unequal across the line, and the fit is biased. The maximum-likelihood estimate for a tail exponent from "},{"text":"n","code":true},{"text":" values above a threshold "},{"text":"x_min","code":true},{"text":" is one formula: "},{"text":"α = 1 + n / Σ ln(x_i / x_min)","code":true},{"text":". It takes one line and it is what the "},{"text":"powerlaw","code":true},{"text":" package computes."}],[{"text":"Do not extrapolate the line.","b":true},{"text":" A slope measured between "},{"text":"10^3","code":true},{"text":" and "},{"text":"10^5","code":true},{"text":" says nothing about "},{"text":"10^7","code":true},{"text":". The curves you will most want to extrapolate, of loss against scale, are the ones with the fewest points at the far end."}],[{"text":"Check the exponent’s uncertainty.","b":true},{"text":" With twenty points, the slope carries an error bar of several tenths, and a slope of "},{"text":"−1.1","code":true},{"text":" against "},{"text":"−0.9","code":true},{"text":" is not a distinction the data can make."}]]},{"t":"h2","id":"in-code","runs":[{"text":"In code"}]},{"t":"code","lang":"python","label":"Python","text":"import numpy as np, matplotlib.pyplot as plt\nplt.loglog(x, y, \"o\")                        # straight means power law\nk, logc = np.polyfit(np.log(x), np.log(y), 1) # slope k; fine for a curve, not a histogram"},{"t":"p","runs":[{"text":"The "},{"text":"polyfit","code":true},{"text":" on logs is acceptable for a smooth curve such as a loss against dataset size, where each point is a measurement rather than a count. For a histogram of a heavy-tailed quantity, use the likelihood formula. Both are free, and both fit on a laptop. The skill being trained is the one you use every time a paper shows a straight line on log axes: find the slope, find its uncertainty, and ask what the line is being asked to promise beyond the data it was drawn through."}]}],"check":{"question":[{"text":"Error against dataset size is a straight line on log-log axes with slope −0.5. What does going from 10,000 to 40,000 examples buy?"}],"options":[{"text":[{"text":"Error halves."}],"correct":true,"tempting":null},{"text":[{"text":"Error falls by 0.5, since that is the slope."}],"correct":false,"tempting":[{"text":"Reads the slope as a linear change in the error rather than an exponent; on log-log axes the slope multiplies, it does not subtract."}]},{"text":[{"text":"Error falls to a quarter, because the dataset grew four times."}],"correct":false,"tempting":[{"text":"Applies the growth factor directly; the factor is raised to the exponent, and 4 to the power −0.5 is one half, not one quarter."}]},{"text":[{"text":"It cannot be said without the line’s intercept."}],"correct":false,"tempting":[{"text":"The intercept sets the absolute error, but the ratio between two sizes depends only on the slope."}]}],"order":[2,3,1,0],"why":null},"prev":{"slug":"log-sum-exp-and-stable-softmax","title":"The log-sum-exp trick, and why exp(1000) is not a number","minutes":9},"next":{"slug":"estimators-and-why-n-minus-one","title":"An estimator is a recipe, and why the variance divides by n − 1","minutes":9}}}