{"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":"norms-and-distance","title":"How long, and how far","url":"https://addaly.com/learn/maths-you-need/norms-and-distance","position":4,"of":76,"minutes":8,"answer":"A norm turns a whole vector into one number measuring size, and which norm you pick decides whether outliers dominate your answer or barely register.","keyIdea":"A norm turns a whole vector into one number measuring size, and which norm you pick decides whether outliers dominate your answer or barely register."},"body":{"format":"markdown","text":"## One number for a whole list\n\nYou have a vector. Sometimes you want a single number saying how big it is. That number is called a norm, and there is more than one sensible answer.\n\nTake `v = [3, 4]`.\n\n**The L2 norm**, also called the Euclidean norm, is the one from school geometry: square each element, add them, take the square root.\n\n```\n||v||2 = sqrt(3^2 + 4^2) = sqrt(9 + 16) = sqrt(25) = 5\n```\n\n**The L1 norm**, also called Manhattan distance, adds absolute values:\n\n```\n||v||1 = |3| + |4| = 7\n```\n\n**The L-infinity norm** takes the largest absolute value:\n\n```\n||v||inf = max(|3|, |4|) = 4\n```\n\nThree answers, all correct, all measuring something slightly different. The names come from a family: the Lp norm raises each element to the power p, sums, and takes the p-th root. L2 is p = 2; L1 is p = 1; L-infinity is the limit.\n\n## Distance is the norm of a difference\n\nDistance between two vectors is just the norm of what separates them. For `a = [1, 2, 3]` and `b = [4, 6, 3]`:\n\n```\na - b = [-3, -4, 0]\nL2 distance = sqrt(9 + 16 + 0) = 5\nL1 distance = 3 + 4 + 0 = 7\n```\n\nThe L1 name comes from walking a street grid: you cannot cut the diagonal, so you go three blocks then four blocks, seven blocks total. L2 is the crow's route, five blocks.\n\n## Why the choice changes your answer\n\nThe difference is entirely about outliers. Squaring makes a large element enormously more important than a small one. Compare `[10, 0, 0, 0]` with `[5, 5, 5, 5]`:\n\n- L1: both are 10. They look identical.\n- L2: `sqrt(100) = 10` against `sqrt(100) = 10`. Also identical, by coincidence of the numbers chosen.\n\nNow compare `[10, 0, 0, 0]` with `[3, 3, 3, 3]`:\n\n- L1: 10 against 12. The spread-out one is bigger.\n- L2: 10 against 6. The spiky one is bigger.\n\nThat reversal is the whole point. L2 says \"one big deviation is worse than four small ones\". L1 says \"add up the damage, however it is distributed\". This is why L2 loss (mean squared error) is pulled around by a single wild data point while L1 loss (mean absolute error) mostly ignores it, and why L1 regularisation drives weights exactly to zero while L2 only shrinks them.\n\n## Unit vectors: keeping the direction, dropping the size\n\nDivide a vector by its own L2 norm and you get a vector of length exactly 1, pointing the same way.\n\n```\nv = [3, 4],  ||v||2 = 5\nv_hat = [3/5, 4/5] = [0.6, 0.8]\ncheck: sqrt(0.36 + 0.64) = sqrt(1) = 1\n```\n\nThis is called normalising, and it is everywhere in machine learning. Embedding search libraries normalise every vector on insert, so that a dot product *is* a cosine and no division is needed at query time. Layer normalisation inside a transformer does a related thing to each token's activation vector on every layer.\n\nThe reason is the one from the dot-product lesson: raw dot products grow with length, so a long vector scores high against everything. Normalising strips length out and leaves only direction, which is where the meaning lives.\n\n## What normalising costs you\n\nLength is not always noise. In a bag-of-words representation, the length of a document vector carries the document's size, and sometimes a long document is a better match. In an embedding from a modern model, vector norms have been shown to correlate loosely with token frequency and with how confident the model is. Normalise, and you discard that.\n\nThere is also a practical trap. If you normalise your database vectors but forget to normalise the query, your scores are neither dot products nor cosines, and the ranking is wrong in a way that still returns plausible-looking results. This is one of the most common bugs in a hand-built search system, and it never raises an error.\n\n## The rule to keep\n\nAsk what you want the number to mean. If a single large deviation should dominate, square it: use L2. If you want a total that treats every unit of error alike, use L1. If you only care about the worst element (a latency budget, a safety margin) use L-infinity. And when you compare directions rather than sizes, normalise first, on both sides."},"check":{"question":"A search index stores 200,000 product-description embeddings, all normalised to unit length on insert. A developer adds a new query path that sends raw, un-normalised query vectors. What happens?","options":[{"text":"Every score comes back as exactly zero, because the dimensions no longer match.","correct":false,"tempting":"Confuses normalisation with dimensionality; the arithmetic still runs, which is precisely why the bug survives."},{"text":"Results are unaffected, because scaling the query by a constant scales every score by the same constant and leaves the ranking unchanged.","correct":false,"tempting":"This is actually right for a single query, and the trap is that it feels wrong; the real damage appears when scores are compared across queries or against a fixed threshold."},{"text":"Nothing detectable, and the index silently returns the reverse ranking.","correct":false,"tempting":"Multiplying by a positive constant cannot reverse an order; nothing here flips signs."},{"text":"Ranking within one query survives, but any fixed similarity threshold or cross-query score comparison becomes meaningless, and no error is ever raised.","correct":true}]},"prev":{"slug":"dot-products","title":"What a dot product measures","url":"https://addaly.com/learn/maths-you-need/dot-products"},"next":{"slug":"cosine-versus-euclidean","title":"Cosine or distance, and why it often does not matter","url":"https://addaly.com/learn/maths-you-need/cosine-versus-euclidean"},"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) 'How long, and how far', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/norms-and-distance (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":"How long, and how far","courseTitle":"The Maths You Actually Need","module":{"index":1,"slug":"vectors-and-space","title":"Vectors, and the space they live in"},"answer":null,"keyIdea":"A norm turns a whole vector into one number measuring size, and which norm you pick decides whether outliers dominate your answer or barely register.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"one-number-for-a-whole-list","runs":[{"text":"One number for a whole list"}]},{"t":"p","runs":[{"text":"You have a vector. Sometimes you want a single number saying how big it is. That number is called a norm, and there is more than one sensible answer."}]},{"t":"p","runs":[{"text":"Take "},{"text":"v = [3, 4]","code":true},{"text":"."}]},{"t":"p","runs":[{"text":"The L2 norm","b":true},{"text":", also called the Euclidean norm, is the one from school geometry: square each element, add them, take the square root."}]},{"t":"code","lang":"","label":"Text","text":"||v||2 = sqrt(3^2 + 4^2) = sqrt(9 + 16) = sqrt(25) = 5"},{"t":"p","runs":[{"text":"The L1 norm","b":true},{"text":", also called Manhattan distance, adds absolute values:"}]},{"t":"code","lang":"","label":"Text","text":"||v||1 = |3| + |4| = 7"},{"t":"p","runs":[{"text":"The L-infinity norm","b":true},{"text":" takes the largest absolute value:"}]},{"t":"code","lang":"","label":"Text","text":"||v||inf = max(|3|, |4|) = 4"},{"t":"p","runs":[{"text":"Three answers, all correct, all measuring something slightly different. The names come from a family: the Lp norm raises each element to the power p, sums, and takes the p-th root. L2 is p = 2; L1 is p = 1; L-infinity is the limit."}]},{"t":"h2","id":"distance-is-the-norm-of-a-difference","runs":[{"text":"Distance is the norm of a difference"}]},{"t":"p","runs":[{"text":"Distance between two vectors is just the norm of what separates them. For "},{"text":"a = [1, 2, 3]","code":true},{"text":" and "},{"text":"b = [4, 6, 3]","code":true},{"text":":"}]},{"t":"code","lang":"","label":"Text","text":"a - b = [-3, -4, 0]\nL2 distance = sqrt(9 + 16 + 0) = 5\nL1 distance = 3 + 4 + 0 = 7"},{"t":"p","runs":[{"text":"The L1 name comes from walking a street grid: you cannot cut the diagonal, so you go three blocks then four blocks, seven blocks total. L2 is the crow’s route, five blocks."}]},{"t":"h2","id":"why-the-choice-changes-your-answer","runs":[{"text":"Why the choice changes your answer"}]},{"t":"p","runs":[{"text":"The difference is entirely about outliers. Squaring makes a large element enormously more important than a small one. Compare "},{"text":"[10, 0, 0, 0]","code":true},{"text":" with "},{"text":"[5, 5, 5, 5]","code":true},{"text":":"}]},{"t":"ul","items":[[{"text":"L1: both are 10. They look identical."}],[{"text":"L2: "},{"text":"sqrt(100) = 10","code":true},{"text":" against "},{"text":"sqrt(100) = 10","code":true},{"text":". Also identical, by coincidence of the numbers chosen."}]]},{"t":"p","runs":[{"text":"Now compare "},{"text":"[10, 0, 0, 0]","code":true},{"text":" with "},{"text":"[3, 3, 3, 3]","code":true},{"text":":"}]},{"t":"ul","items":[[{"text":"L1: 10 against 12. The spread-out one is bigger."}],[{"text":"L2: 10 against 6. The spiky one is bigger."}]]},{"t":"p","runs":[{"text":"That reversal is the whole point. L2 says “one big deviation is worse than four small ones”. L1 says “add up the damage, however it is distributed”. This is why L2 loss (mean squared error) is pulled around by a single wild data point while L1 loss (mean absolute error) mostly ignores it, and why L1 regularisation drives weights exactly to zero while L2 only shrinks them."}]},{"t":"h2","id":"unit-vectors-keeping-the-direction-dropping-the-size","runs":[{"text":"Unit vectors: keeping the direction, dropping the size"}]},{"t":"p","runs":[{"text":"Divide a vector by its own L2 norm and you get a vector of length exactly 1, pointing the same way."}]},{"t":"code","lang":"","label":"Text","text":"v = [3, 4],  ||v||2 = 5\nv_hat = [3/5, 4/5] = [0.6, 0.8]\ncheck: sqrt(0.36 + 0.64) = sqrt(1) = 1"},{"t":"p","runs":[{"text":"This is called normalising, and it is everywhere in machine learning. Embedding search libraries normalise every vector on insert, so that a dot product "},{"text":"is","i":true},{"text":" a cosine and no division is needed at query time. Layer normalisation inside a transformer does a related thing to each token’s activation vector on every layer."}]},{"t":"p","runs":[{"text":"The reason is the one from the dot-product lesson: raw dot products grow with length, so a long vector scores high against everything. Normalising strips length out and leaves only direction, which is where the meaning lives."}]},{"t":"h2","id":"what-normalising-costs-you","runs":[{"text":"What normalising costs you"}]},{"t":"p","runs":[{"text":"Length is not always noise. In a bag-of-words representation, the length of a document vector carries the document’s size, and sometimes a long document is a better match. In an embedding from a modern model, vector norms have been shown to correlate loosely with token frequency and with how confident the model is. Normalise, and you discard that."}]},{"t":"p","runs":[{"text":"There is also a practical trap. If you normalise your database vectors but forget to normalise the query, your scores are neither dot products nor cosines, and the ranking is wrong in a way that still returns plausible-looking results. This is one of the most common bugs in a hand-built search system, and it never raises an error."}]},{"t":"h2","id":"the-rule-to-keep","runs":[{"text":"The rule to keep"}]},{"t":"p","runs":[{"text":"Ask what you want the number to mean. If a single large deviation should dominate, square it: use L2. If you want a total that treats every unit of error alike, use L1. If you only care about the worst element (a latency budget, a safety margin) use L-infinity. And when you compare directions rather than sizes, normalise first, on both sides."}]}],"check":{"question":[{"text":"A search index stores 200,000 product-description embeddings, all normalised to unit length on insert. A developer adds a new query path that sends raw, un-normalised query vectors. What happens?"}],"options":[{"text":[{"text":"Every score comes back as exactly zero, because the dimensions no longer match."}],"correct":false,"tempting":[{"text":"Confuses normalisation with dimensionality; the arithmetic still runs, which is precisely why the bug survives."}]},{"text":[{"text":"Results are unaffected, because scaling the query by a constant scales every score by the same constant and leaves the ranking unchanged."}],"correct":false,"tempting":[{"text":"This is actually right for a single query, and the trap is that it feels wrong; the real damage appears when scores are compared across queries or against a fixed threshold."}]},{"text":[{"text":"Nothing detectable, and the index silently returns the reverse ranking."}],"correct":false,"tempting":[{"text":"Multiplying by a positive constant cannot reverse an order; nothing here flips signs."}]},{"text":[{"text":"Ranking within one query survives, but any fixed similarity threshold or cross-query score comparison becomes meaningless, and no error is ever raised."}],"correct":true,"tempting":null}],"order":[1,2,3,0],"why":null},"prev":{"slug":"dot-products","title":"What a dot product measures","minutes":7},"next":{"slug":"cosine-versus-euclidean","title":"Cosine or distance, and why it often does not matter","minutes":9}}}