Math — Calculus
A progressive journey through single-variable and multivariable calculus — from summation and product notation to derivatives, integrals, and Python implementations of polynomial differentiation and integration.
Learning Objectives
| # | Concept |
|---|---|
| 1 | Evaluate summations using Σ\SigmaΣ (sigma) notation |
| 2 | Evaluate products using Π\PiΠ (pi) notation |
| 3 | Compute derivatives of polynomial, exponential, and logarithmic functions |
| 4 | Compute partial derivatives of multivariable functions |
| 5 | Evaluate indefinite and definite integrals |
| 6 | Evaluate double integrals over rectangular regions |
| 7 | Implement polynomial derivative calculation in Python |
| 8 | Implement polynomial integral (antiderivative) calculation in Python |
| 9 | Apply the closed-form formula for ∑i=1ni2\sum_{i=1}^{n} i^2∑i=1ni2 |
Module Structure
This module contains two types of tasks:
| Type | Files | Description |
|---|---|---|
| Computation Exercises | 0–8, 11–16 | Hand-calculated answers stored as single-number files |
| Python Implementations | 9, 10, 17 | Functions that compute sums, derivatives, and integrals programmatically |
Computation Exercises (Tasks 0–8, 11–16)
These tasks build calculus intuition through manual computation. Each file stores the numeric answer.
| Task | File | Topic | Concept Tested |
|---|---|---|---|
| 0 | 0-sigma_is_for_sum | Sigma notation | ∑i=25i\sum_{i=2}^{5} i∑i=25i |
| 1 | 1-seegma | Sigma notation | ∑k=14k2\sum_{k=1}^{4} k^2∑k=14k2 |
| 2 | 2-pi_is_for_product | Pi notation | ∏i=14i\prod_{i=1}^{4} i∏i=14i |
| 3 | 3-pee | Pi notation | Product with expressions |
| 4 | 4-hello_derivatives | Derivatives | f′(x)f'(x)f′(x) for polynomial fff |
| 5 | 5-log_on_fire | Derivatives | Derivative of ln(x)\ln(x)ln(x) and exe^xex |
| 6 | 6-voltaire | Derivatives | Derivative at a specific point |
| 7 | 7-partial_truths | Partial derivatives | ∂f∂x\frac{\partial f}{\partial x}∂x∂f |
| 8 | 8-all-together | Mixed derivatives | Combined partial derivative evaluation |
| 11 | 11-integral | Indefinite integrals | ∫xn dx\int x^n \, dx∫xndx |
| 12 | 12-integral | Indefinite integrals | ∫ex dx\int e^x \, dx∫exdx |
| 13 | 13-definite | Definite integrals | ∫abf(x) dx\int_a^b f(x) \, dx∫abf(x)dx |
| 14 | 14-definite | Definite integrals | Area under a curve |
| 15 | 15-definite | Definite integrals | Definite integral with substitution |
| 16 | 16-double | Double integrals | ∬f(x,y) dx dy\iint f(x,y) \, dx \, dy∬f(x,y)dxdy |
Computation Exercises Approach
These 14 tasks build calculus intuition through hand computation before code — each file stores a single numeric answer, and the real learning happens in the manual work that produced it.
Purpose: Before implementing differentiation and integration in Python (Tasks 9, 10, 17), you work through the core calculus operations by hand. This mirrors the machine learning workflow: understand the math on paper first, then automate it. The manual computation builds the intuition that makes the code meaningful rather than mechanical.
Learning progression:
| Stage | Tasks | Topic | What you practice |
|---|---|---|---|
| 1 | 0–1 | Sigma (Σ\SigmaΣ) notation | Summing sequences: ∑i=abf(i)\sum_{i=a}^{b} f(i)∑i=abf(i) — the foundation of series and integrals |
| 2 | 2–3 | Pi (Π\PiΠ) notation | Multiplying sequences: ∏i=abf(i)\prod_{i=a}^{b} f(i)∏i=abf(i) — used in likelihood products and combinatorial formulas |
| 3 | 4–6 | Derivatives | Power rule ddxxn=nxn−1\frac{d}{dx}x^n = nx^{n-1}dxdxn=nxn−1, derivative of lnx\ln xlnx, derivative of exe^xex, evaluating at a point |
| 4 | 7–8 | Partial derivatives | Treating other variables as constants: ∂∂xf(x,y)\frac{\partial}{\partial x}f(x,y)∂x∂f(x,y), mixed partials |
| 5 | 11–12 | Indefinite integrals | Reverse power rule ∫xndx=xn+1n+1+C\int x^n dx = \frac{x^{n+1}}{n+1} + C∫xndx=n+1xn+1+C, ∫exdx=ex+C\int e^x dx = e^x + C∫exdx=ex+C |
| 6 | 13–15 | Definite integrals | Fundamental Theorem of Calculus: ∫abf(x)dx=F(b)−F(a)\int_a^b f(x)dx = F(b) - F(a)∫abf(x)dx=F(b)−F(a), substitution |
| 7 | 16 | Double integrals | Iterated integration — integrate inner variable first, then outer: ∬f(x,y) dx dy\iint f(x,y)\,dx\,dy∬f(x,y)dxdy |
Key formulas used across these tasks:
| Operation | Formula | When to use |
|---|---|---|
| Power rule (derivative) | ddxxn=nxn−1\frac{d}{dx} x^n = n x^{n-1}dxdxn=nxn−1 | Polynomial differentiation |
| Derivative of lnx\ln xlnx | ddxlnx=1x\frac{d}{dx} \ln x = \frac{1}{x}dxdlnx=x1 | Logarithmic differentiation |
| Derivative of exe^xex | ddxex=ex\frac{d}{dx} e^x = e^xdxdex=ex | Exponential functions |
| Partial derivative | ∂∂xf(x,y)\frac{\partial}{\partial x} f(x,y)∂x∂f(x,y) — treat yyy as constant | Multivariable functions |
| Power rule (integral) | ∫xndx=xn+1n+1+C\int x^n dx = \frac{x^{n+1}}{n+1} + C∫xndx=n+1xn+1+C | Polynomial integration |
| Integral of exe^xex | ∫exdx=ex+C\int e^x dx = e^x + C∫exdx=ex+C | Exponential integration |
| Fundamental Theorem of Calculus | ∫abf(x)dx=F(b)−F(a)\int_a^b f(x)dx = F(b) - F(a)∫abf(x)dx=F(b)−F(a) | Definite integrals |
| Double integral | ∬f(x,y) dx dy=∫(∫f(x,y) dx)dy\iint f(x,y)\,dx\,dy = \int \left(\int f(x,y)\,dx\right)dy∬f(x,y)dxdy=∫(∫f(x,y)dx)dy | Area/volume under surfaces |
Relationship to Python tasks: Tasks 9, 10, and 17 implement programmatically what these 14 exercises compute by hand:
- Task 9 (
9-sum_total.py) automates the ∑i2\sum i^2∑i2 closed form you work through in Tasks 0–1 - Task 10 (
10-matisse.py) implements the power rule for derivatives that Tasks 4–6 practice manually - Task 17 (
17-integrate.py) implements the reverse power rule and integration constant that Tasks 11–16 build intuition for
The manual work teaches you what the answer should be; the Python code teaches you how to compute it at scale.
---\n\n## Task-by-Task Reference (Python Implementations)
Each task below highlights the unique challenge it posed and the new technique introduced.
Task 9 — Summation Formula (9-sum_total.py)
Challenge: Compute ∑i=1ni2\sum_{i=1}^{n} i^2∑i=1ni2 efficiently without a loop — introducing the closed-form mathematical formula.
Approach: Implement the formula n(n+1)(2n+1)6\frac{n(n+1)(2n+1)}{6}6n(n+1)(2n+1) using integer arithmetic. Validate that nnn is a positive integer. Use // for floor division since the numerator is always divisible by 6.
New techniques introduced:
| Technique | Purpose |
|---|---|
| ∑i=1ni2=n(n+1)(2n+1)6\sum_{i=1}^{n} i^2 = \frac{n(n+1)(2n+1)}{6}∑i=1ni2=6n(n+1)(2n+1) | Closed-form sum of squares — O(1) instead of O(n) |
// integer floor division | Guarantee integer result when numerator is divisible by denominator |
Input validation: isinstance(n, int) and n >= 1 | Reject non-integer and non-positive inputs |
return None for invalid input | Sentinel pattern for invalid parameters |
Key takeaway: Mathematical formulas can replace loops. The sum of squares formula is a classic closed form — knowing it turns an O(n) problem into O(1).
Task 10 — Polynomial Derivative (10-matisse.py)
Challenge: Compute the derivative of a polynomial represented as a list of coefficients — implementing the power rule programmatically.
Approach: Given coefficients [a0,a1,a2,… ][a_0, a_1, a_2, \dots][a0,a1,a2,…] representing a0+a1x+a2x2+…a_0 + a_1x + a_2x^2 + \dotsa0+a1x+a2x2+…, the derivative is a1+2a2x+3a3x2+…a_1 + 2a_2x + 3a_3x^2 + \dotsa1+2a2x+3a3x2+…. For each coefficient at index iii, multiply by iii (the power) and shift left by 1 position. Handle edge cases: empty list → None, constant polynomial → [0].
New techniques introduced:
| Technique | Purpose |
|---|---|
| Power rule: ddx(aixi)=i⋅aixi−1\frac{d}{dx}(a_i x^i) = i \cdot a_i x^{i-1}dxd(aixi)=i⋅aixi−1 | Derivative of each term is coefficient × power |
| Coefficient list representation | Index = power, value = coefficient |
poly[i] * i for derivative coefficient | Multiply by the exponent (index) |
all(x == 0 for x in out) → return [0] | Handle the zero-polynomial edge case |
Key takeaway: The derivative of anxna_n x^nanxn is n⋅anxn−1n \cdot a_n x^{n-1}n⋅anxn−1. In a coefficient list, you multiply each coefficient by its index (the power) and shift left. The constant term (index 0) is dropped.
Task 17 — Polynomial Integral (17-integrate.py)
Challenge: Compute the indefinite integral (antiderivative) of a polynomial — implementing the reverse power rule with an integration constant.
Approach: For each coefficient aia_iai at index iii (representing aixia_i x^iaixi), the integral term is aii+1xi+1\frac{a_i}{i+1} x^{i+1}i+1aixi+1. Store at index i+1i+1i+1 in the output. The constant CCC goes at index 0. Use integer simplification: if the division is exact, store as int; otherwise store as float.
New techniques introduced:
| Technique | Purpose |
|---|---|
| Reverse power rule: ∫aixi dx=aii+1xi+1+C\int a_i x^i \, dx = \frac{a_i}{i+1} x^{i+1} + C∫aixidx=i+1aixi+1+C | Integral of each term divides by the new exponent |
C as the integration constant | Arbitrary constant added to every indefinite integral |
| Index shift: input[i] → output[i+1] | The integral increases each term's degree by 1 |
int(val) if exact else float(val) | Preserve exact integer results, use float for fractions |
C.is_integer() float check | Handle the case where C is a float that represents a whole number |
Key takeaway: Integration is the inverse of differentiation. Each term axna x^naxn becomes an+1xn+1\frac{a}{n+1} x^{n+1}n+1axn+1. The integration constant CCC represents the family of all antiderivatives. Don't forget to shift indices — integrating increases each power by 1.
Technique Inventory
| Task | New technique summarized | Category |
|---|---|---|
| 0–8 | Manual computation: Σ\SigmaΣ, Π\PiΠ, derivatives, partial derivatives | Manual Calculus |
| 9 | Closed-form ∑i2\sum i^2∑i2 formula, // integer division | Summation |
| 10 | Polynomial derivative via power rule, coefficient list representation | Derivatives |
| 11–16 | Manual computation: indefinite, definite, double integrals | Manual Calculus |
| 17 | Polynomial integral via reverse power rule, integration constant CCC | Integration |