{"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":"rates-of-change-before-derivatives","title":"Slope, before anyone says the word derivative","url":"https://addaly.com/learn/maths-you-need/rates-of-change-before-derivatives","position":19,"of":76,"minutes":8,"answer":"A derivative is the slope between two points as you shrink the gap between them, and you can compute a usable one with two evaluations and a small number.","keyIdea":"A derivative is the slope between two points as you shrink the gap between them, and you can compute a usable one with two evaluations and a small number."},"body":{"format":"markdown","text":"## Two points and a division\n\nForget calculus for a moment. You have a function (anything that takes a number and returns a number) and you want to know whether it goes up or down near some point, and how steeply.\n\nPick your point, take a small step, and divide:\n\n```\nslope = ( f(x + h) - f(x) ) / h\n```\n\nThat is the average rate of change over the step. Now shrink `h`. Take `f(x) = x^2` at `x = 3`:\n\n```\nh = 1:      (16 - 9) / 1        = 7\nh = 0.1:    (9.61 - 9) / 0.1    = 6.1\nh = 0.01:   (9.0601 - 9) / 0.01 = 6.01\nh = 0.001:  (9.006001 - 9)/.001 = 6.001\n```\n\nThe numbers are converging on 6. That limit is the derivative of `x²` at 3, and the general formula `2x` gives `2 × 3 = 6`. No mystery: a derivative is the slope between two points, with the gap taken to zero.\n\n## Why it matters that it converges\n\nThe reason a derivative is useful is that it turns a question about a whole function into a single number at one point. Ask \"if I nudge this weight up a little, does the loss go up or down, and how fast?\" and the derivative answers it. Every training step is that question, asked millions of times.\n\nThe sign carries the direction and the magnitude carries the urgency. Derivative +6 means going right increases the value at six times the rate you go. Derivative 0 means flat, at least locally: a peak, a trough or a plateau.\n\n## Do not shrink h too far\n\nHere is the practical wrinkle that a maths course will not tell you and a debugging session will. The formula gets more accurate as `h` shrinks, right up until floating-point arithmetic ruins it.\n\n`f(x + h)` and `f(x)` are nearly equal for tiny `h`, so subtracting them cancels the leading digits and leaves you dividing noise by a very small number. With 64-bit floats the two effects balance around `h ≈ 1e-8`; go smaller and the answer gets *worse*.\n\n```python\ndef f(x): return x**2\nx = 3.0\nfor h in (1e-4, 1e-8, 1e-12, 1e-16):\n    print(h, (f(x+h) - f(x)) / h)\n# 1e-04  6.000100000012054\n# 1e-08  5.999999963900386\n# 1e-12  6.000533403494046      <- getting worse\n# 1e-16  0.0                    <- x + h rounds back to x\n```\n\nThe last line is the whole lesson in one number. `3.0 + 1e-16` is exactly `3.0` in double precision, the numerator is zero, and the derivative comes back as zero. This is called catastrophic cancellation and it is why nobody computes gradients this way in production.\n\n## The version that is actually used for checking\n\nA better finite difference uses a step in both directions:\n\n```\ncentral difference = ( f(x + h) - f(x - h) ) / (2h)\n```\n\nIts error shrinks with `h²` rather than `h`, so at `h = 1e-5` it is typically accurate to seven or eight digits. This is the standard gradient check: compute the analytic gradient your code produces, compute the central difference, and compare. If they disagree by more than about `1e-5` relative, your backward pass has a bug.\n\nIt is worth knowing this exists because a wrong gradient does not crash. It trains: badly, mysteriously, in a way that looks like a hyperparameter problem for a week.\n\n## Derivatives you should be able to write down\n\nFive cover most of what you meet, and it is worth being able to produce them without looking:\n\n- `f(x) = c` (a constant): derivative 0. A flat line has no slope.\n- `f(x) = x^n`: derivative `n x^(n-1)`. So `x²` gives `2x`, `x³` gives `3x²`, and `x` gives 1.\n- `f(x) = e^x`: derivative `e^x`. It is its own derivative, which is why `e` shows up everywhere in this subject.\n- `f(x) = ln(x)`: derivative `1/x`. Steep near zero, nearly flat for large x.\n- `f(x) = 1/(1 + e^(-x))` (the sigmoid): derivative `f(x) (1 - f(x))`. Worth remembering as written, because it says the slope is computable from the output alone.\n\nThat last one has a consequence you will meet in this module. The sigmoid's output is between 0 and 1, so `f(1 − f)` is at most 0.25, at `f = 0.5`, and approaches zero at both ends. A sigmoid that has saturated has almost no gradient, and stacking several multiplies those small numbers together.\n\n## The two rules for combinations\n\n- **Sum:** the derivative of `f + g` is the derivative of f plus the derivative of g. Slopes add.\n- **Constant multiple:** the derivative of `3f` is 3 times the derivative of f.\n\nTogether with the list above these let you differentiate most simple expressions. `f(x) = 3x² + 5x − 7` has derivative `6x + 5`; the constant vanishes because a constant has no slope.\n\nThe one remaining rule, for functions inside functions, is the chain rule, and it gets its own lesson because it is the entire mechanism of training a neural network.\n\n## The rule to keep\n\nA derivative is a slope, computed by shrinking a gap. You can always check one numerically with a central difference at `h = 1e-5`, and doing so is the fastest way to find out whether a hand-written backward pass is right."},"check":{"question":"An engineer verifies a hand-written gradient by finite differences and, wanting maximum accuracy, uses h = 1e-15 with 64-bit floats. The check reports gradients of exactly zero everywhere and they conclude the backward pass is broken. What has actually happened?","options":[{"text":"The step is so small that f(x+h) rounds to f(x) in floating point, so the numerator is zero regardless of the true slope.","correct":true},{"text":"h = 1e-15 is below the smallest representable double, so it is treated as zero.","correct":false,"tempting":"Doubles go down to roughly 1e-308; 1e-15 is perfectly representable on its own, and the problem is the addition, not the number."},{"text":"The forward pass must be returning constants, since a correct function would show some change at any step size.","correct":false,"tempting":"Assumes infinite precision; a correct, varying function still shows no change when the step falls below the spacing of representable values near x."},{"text":"Finite differences only work for convex functions, and the loss surface is not convex.","correct":false,"tempting":"Finite differences approximate a local slope and do not care about convexity at all."}]},"prev":{"slug":"singular-values-and-svd","title":"Singular values, and the honest measure of importance","url":"https://addaly.com/learn/maths-you-need/singular-values-and-svd"},"next":{"slug":"derivatives-and-descent","title":"Slopes, and why training is walking downhill","url":"https://addaly.com/learn/maths-you-need/derivatives-and-descent"},"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) 'Slope, before anyone says the word derivative', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/rates-of-change-before-derivatives (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":"Slope, before anyone says the word derivative","courseTitle":"The Maths You Actually Need","module":{"index":3,"slug":"change-and-descent","title":"Change, slopes and the walk downhill"},"answer":null,"keyIdea":"A derivative is the slope between two points as you shrink the gap between them, and you can compute a usable one with two evaluations and a small number.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"two-points-and-a-division","runs":[{"text":"Two points and a division"}]},{"t":"p","runs":[{"text":"Forget calculus for a moment. You have a function (anything that takes a number and returns a number) and you want to know whether it goes up or down near some point, and how steeply."}]},{"t":"p","runs":[{"text":"Pick your point, take a small step, and divide:"}]},{"t":"code","lang":"","label":"Text","text":"slope = ( f(x + h) - f(x) ) / h"},{"t":"p","runs":[{"text":"That is the average rate of change over the step. Now shrink "},{"text":"h","code":true},{"text":". Take "},{"text":"f(x) = x^2","code":true},{"text":" at "},{"text":"x = 3","code":true},{"text":":"}]},{"t":"code","lang":"","label":"Text","text":"h = 1:      (16 - 9) / 1        = 7\nh = 0.1:    (9.61 - 9) / 0.1    = 6.1\nh = 0.01:   (9.0601 - 9) / 0.01 = 6.01\nh = 0.001:  (9.006001 - 9)/.001 = 6.001"},{"t":"p","runs":[{"text":"The numbers are converging on 6. That limit is the derivative of "},{"text":"x²","code":true},{"text":" at 3, and the general formula "},{"text":"2x","code":true},{"text":" gives "},{"text":"2 × 3 = 6","code":true},{"text":". No mystery: a derivative is the slope between two points, with the gap taken to zero."}]},{"t":"h2","id":"why-it-matters-that-it-converges","runs":[{"text":"Why it matters that it converges"}]},{"t":"p","runs":[{"text":"The reason a derivative is useful is that it turns a question about a whole function into a single number at one point. Ask “if I nudge this weight up a little, does the loss go up or down, and how fast?” and the derivative answers it. Every training step is that question, asked millions of times."}]},{"t":"p","runs":[{"text":"The sign carries the direction and the magnitude carries the urgency. Derivative +6 means going right increases the value at six times the rate you go. Derivative 0 means flat, at least locally: a peak, a trough or a plateau."}]},{"t":"h2","id":"do-not-shrink-h-too-far","runs":[{"text":"Do not shrink h too far"}]},{"t":"p","runs":[{"text":"Here is the practical wrinkle that a maths course will not tell you and a debugging session will. The formula gets more accurate as "},{"text":"h","code":true},{"text":" shrinks, right up until floating-point arithmetic ruins it."}]},{"t":"p","runs":[{"text":"f(x + h)","code":true},{"text":" and "},{"text":"f(x)","code":true},{"text":" are nearly equal for tiny "},{"text":"h","code":true},{"text":", so subtracting them cancels the leading digits and leaves you dividing noise by a very small number. With 64-bit floats the two effects balance around "},{"text":"h ≈ 1e-8","code":true},{"text":"; go smaller and the answer gets "},{"text":"worse","i":true},{"text":"."}]},{"t":"code","lang":"python","label":"Python","text":"def f(x): return x**2\nx = 3.0\nfor h in (1e-4, 1e-8, 1e-12, 1e-16):\n    print(h, (f(x+h) - f(x)) / h)\n# 1e-04  6.000100000012054\n# 1e-08  5.999999963900386\n# 1e-12  6.000533403494046      <- getting worse\n# 1e-16  0.0                    <- x + h rounds back to x"},{"t":"p","runs":[{"text":"The last line is the whole lesson in one number. "},{"text":"3.0 + 1e-16","code":true},{"text":" is exactly "},{"text":"3.0","code":true},{"text":" in double precision, the numerator is zero, and the derivative comes back as zero. This is called catastrophic cancellation and it is why nobody computes gradients this way in production."}]},{"t":"h2","id":"the-version-that-is-actually-used-for-checking","runs":[{"text":"The version that is actually used for checking"}]},{"t":"p","runs":[{"text":"A better finite difference uses a step in both directions:"}]},{"t":"code","lang":"","label":"Text","text":"central difference = ( f(x + h) - f(x - h) ) / (2h)"},{"t":"p","runs":[{"text":"Its error shrinks with "},{"text":"h²","code":true},{"text":" rather than "},{"text":"h","code":true},{"text":", so at "},{"text":"h = 1e-5","code":true},{"text":" it is typically accurate to seven or eight digits. This is the standard gradient check: compute the analytic gradient your code produces, compute the central difference, and compare. If they disagree by more than about "},{"text":"1e-5","code":true},{"text":" relative, your backward pass has a bug."}]},{"t":"p","runs":[{"text":"It is worth knowing this exists because a wrong gradient does not crash. It trains: badly, mysteriously, in a way that looks like a hyperparameter problem for a week."}]},{"t":"h2","id":"derivatives-you-should-be-able-to-write-down","runs":[{"text":"Derivatives you should be able to write down"}]},{"t":"p","runs":[{"text":"Five cover most of what you meet, and it is worth being able to produce them without looking:"}]},{"t":"ul","items":[[{"text":"f(x) = c","code":true},{"text":" (a constant): derivative 0. A flat line has no slope."}],[{"text":"f(x) = x^n","code":true},{"text":": derivative "},{"text":"n x^(n-1)","code":true},{"text":". So "},{"text":"x²","code":true},{"text":" gives "},{"text":"2x","code":true},{"text":", "},{"text":"x³","code":true},{"text":" gives "},{"text":"3x²","code":true},{"text":", and "},{"text":"x","code":true},{"text":" gives 1."}],[{"text":"f(x) = e^x","code":true},{"text":": derivative "},{"text":"e^x","code":true},{"text":". It is its own derivative, which is why "},{"text":"e","code":true},{"text":" shows up everywhere in this subject."}],[{"text":"f(x) = ln(x)","code":true},{"text":": derivative "},{"text":"1/x","code":true},{"text":". Steep near zero, nearly flat for large x."}],[{"text":"f(x) = 1/(1 + e^(-x))","code":true},{"text":" (the sigmoid): derivative "},{"text":"f(x) (1 - f(x))","code":true},{"text":". Worth remembering as written, because it says the slope is computable from the output alone."}]]},{"t":"p","runs":[{"text":"That last one has a consequence you will meet in this module. The sigmoid’s output is between 0 and 1, so "},{"text":"f(1 − f)","code":true},{"text":" is at most 0.25, at "},{"text":"f = 0.5","code":true},{"text":", and approaches zero at both ends. A sigmoid that has saturated has almost no gradient, and stacking several multiplies those small numbers together."}]},{"t":"h2","id":"the-two-rules-for-combinations","runs":[{"text":"The two rules for combinations"}]},{"t":"ul","items":[[{"text":"Sum:","b":true},{"text":" the derivative of "},{"text":"f + g","code":true},{"text":" is the derivative of f plus the derivative of g. Slopes add."}],[{"text":"Constant multiple:","b":true},{"text":" the derivative of "},{"text":"3f","code":true},{"text":" is 3 times the derivative of f."}]]},{"t":"p","runs":[{"text":"Together with the list above these let you differentiate most simple expressions. "},{"text":"f(x) = 3x² + 5x − 7","code":true},{"text":" has derivative "},{"text":"6x + 5","code":true},{"text":"; the constant vanishes because a constant has no slope."}]},{"t":"p","runs":[{"text":"The one remaining rule, for functions inside functions, is the chain rule, and it gets its own lesson because it is the entire mechanism of training a neural network."}]},{"t":"h2","id":"the-rule-to-keep","runs":[{"text":"The rule to keep"}]},{"t":"p","runs":[{"text":"A derivative is a slope, computed by shrinking a gap. You can always check one numerically with a central difference at "},{"text":"h = 1e-5","code":true},{"text":", and doing so is the fastest way to find out whether a hand-written backward pass is right."}]}],"check":{"question":[{"text":"An engineer verifies a hand-written gradient by finite differences and, wanting maximum accuracy, uses h = 1e-15 with 64-bit floats. The check reports gradients of exactly zero everywhere and they conclude the backward pass is broken. What has actually happened?"}],"options":[{"text":[{"text":"The step is so small that f(x+h) rounds to f(x) in floating point, so the numerator is zero regardless of the true slope."}],"correct":true,"tempting":null},{"text":[{"text":"h = 1e-15 is below the smallest representable double, so it is treated as zero."}],"correct":false,"tempting":[{"text":"Doubles go down to roughly 1e-308; 1e-15 is perfectly representable on its own, and the problem is the addition, not the number."}]},{"text":[{"text":"The forward pass must be returning constants, since a correct function would show some change at any step size."}],"correct":false,"tempting":[{"text":"Assumes infinite precision; a correct, varying function still shows no change when the step falls below the spacing of representable values near x."}]},{"text":[{"text":"Finite differences only work for convex functions, and the loss surface is not convex."}],"correct":false,"tempting":[{"text":"Finite differences approximate a local slope and do not care about convexity at all."}]}],"order":[1,3,2,0],"why":null},"prev":{"slug":"singular-values-and-svd","title":"Singular values, and the honest measure of importance","minutes":10},"next":{"slug":"derivatives-and-descent","title":"Slopes, and why training is walking downhill","minutes":9}}}