Learn how small changes help AI improve, and how adding up tiny pieces gives totals.
Calculus studies how quantities change and how small pieces add up. Derivatives measure change; AI training uses them to adjust numbers and reduce mistakes. Integrals add up tiny pieces into a total; AI uses them for probabilities, averages and model scores. We will work one small step at a time.
Free preview — no account needed. This is the Basic level of a Mathematical Foundations lesson from the AI Professional Series. The Intermediate and Advanced levels, with 20 more practice exercises and a Concept Quiz, are part of AI Professional. Optional practice only: it does not affect course totals, exams or certificates.
See AI Professional plansThis is the Basic level. There are 10 practice exercises, each with a hint and a full worked solution.
Start here if calculus is new to you. Learn input and output, slopes, simple derivatives, and what an integral (area under a curve) means.
A function is a rule that gives one output for each allowed input. The letter x stands for an input number. The notation f(x) means the output of the function named f for input x.
In everyday words: A ticket machine takes a number of tickets and returns their total price.
f(x) = 3 × x + 2Read it as: The output is three times the input, plus two.
Worked example: Find f(4) when f(x) = 3 × x + 2.
Answer: f(4) = 14.
Why it matters in AI: An AI model is a function that turns inputs into predictions.
A rate of change compares a change in output with a change in input. For a straight line, this rate is called slope and stays the same everywhere. Rise means the change in output y. Run means the change in input x, which must not be zero when we divide.
In everyday words: A ramp that rises 2 meters over 4 horizontal meters has a slope of one half.
slope = (y₂ − y₁) / (x₂ − x₁)Read it as: Subtract the first output from the second, then divide by the second input minus the first. The small labels identify the two points.
Worked example: A line passes through (1, 3) and (4, 9). Find its slope.
Answer: The output increases by 2 per input unit.
Why it matters in AI: Slope tells us how strongly a prediction changes when an input changes.
A curve can have a different slope at each point. A derivative gives this local slope, meaning the slope right at a chosen input. We write it as f′(x), read as f prime of x. Slopes between closer and closer nearby points can approach this value when the derivative exists.
In everyday words: A car's speed display reports your rate of travel now, not your average over the whole trip.
For f(x) = x², f′(x) = 2 × xRead it as: For input squared, the slope at an input is twice that input.
Worked example: Compare nearby slopes for f(x) = x² at x = 2 with the derivative.
Answer: The slope at x = 2 is 4.
def f(x):
return x ** 2
x = 2
h = 0.1
print((f(x + h) - f(x)) / h) # approximately 4.1
print(2 * x) # exact slope: 4Why it matters in AI: Training uses local slopes to choose how to change a model's numbers.
A power repeats multiplication: x² means x × x, and x³ means x × x × x. Differentiating means finding a derivative. For these powers, bring the power number in front and lower it by one. A constant is a fixed output, so its derivative is zero.
In everyday words: A fixed delivery fee does not change as your basket grows. Its change per extra item is zero.
(x²)′ = 2 × x; (x³)′ = 3 × x²; (7)′ = 0Read it as: The derivative of x squared is twice x. The derivative of x cubed is three times x squared. The derivative of a constant is zero.
Worked example: Find the derivatives of x², x³, and 7 at x = 2.
Answer: The derivatives at 2 are 4, 12, and 0, respectively.
Why it matters in AI: These small rules are building blocks for derivatives of training formulas.
A derivative breaks change into tiny moments. An integral does the opposite: it adds up many tiny pieces to get a total. On a graph, the integral of f from a to b is the area between the curve and the horizontal axis, from input a to input b. We can estimate it by cutting the area into thin strips and adding up height × width for each strip; thinner strips give a better answer.
In everyday words: A car's trip counter adds up your speed moment by moment to give total distance. Driving 60 km per hour for 2 hours adds up to 120 km, which is the area of a 60-by-2 rectangle under the speed graph.
∫ from a to b of f(x) dx ≈ sum of (strip height × strip width)Read it as: The tall curly S, ∫, means add up. Read it as: the integral from a to b of f of x. The dx means the strips are very thin pieces of input.
Worked example: Find the area under f(x) = 2 × x from x = 0 to x = 3.
Answer: The integral from 0 to 3 of 2 × x is 9.
def f(x):
return 2 * x
strips = 1000
width = 3 / strips
total = 0
for i in range(strips):
middle = (i + 0.5) * width # middle of each strip
total += f(middle) * width # height × width
print(round(total, 4)) # 9.0Why it matters in AI: In AI, the chance that a value falls in a range is an area under a probability curve, and a popular model score called AUC is literally an area under a curve.
Try each one on paper first. Use the hint if you get stuck, then check the full solution.
Exercise 1. For f(x) = x + 3, find f(2).
Exercise 2. Find the slope through (1, 2) and (3, 6).
Exercise 3. Find the slope through (0, 8) and (2, 4).
Exercise 4. A straight-line cost rises from 6 dollars at 2 items to 15 dollars at 5 items. Find the rate per item.
Exercise 5. For f(x) = x², find the slope at x = 3.
Exercise 6. For g(x) = x³, find g′(2).
Exercise 7. For h(x) = 9, find its derivative at x = 4.
Exercise 8. For f(x) = x², compare the slope from x = 2 to x = 4 with the slope at x = 2.
Exercise 9. A robot moves at a steady 5 meters per second for 6 seconds. Use the area under its speed graph to find how far it travels.
Exercise 10. Find the area under f(x) = 2 × x from x = 0 to x = 4 (the integral from 0 to 4 of 2 × x).