Back to Blog

Math — Calculus

·Reha Tuncer·Math
View source on GitHub

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
1Evaluate summations using Σ\Sigma (sigma) notation
2Evaluate products using Π\Pi (pi) notation
3Compute derivatives of polynomial, exponential, and logarithmic functions
4Compute partial derivatives of multivariable functions
5Evaluate indefinite and definite integrals
6Evaluate double integrals over rectangular regions
7Implement polynomial derivative calculation in Python
8Implement polynomial integral (antiderivative) calculation in Python
9Apply the closed-form formula for i=1ni2\sum_{i=1}^{n} i^2

Module Structure

This module contains two types of tasks:

TypeFilesDescription
Computation Exercises0–8, 11–16Hand-calculated answers stored as single-number files
Python Implementations9, 10, 17Functions 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.

TaskFileTopicConcept Tested
00-sigma_is_for_sumSigma notationi=25i\sum_{i=2}^{5} i
11-seegmaSigma notationk=14k2\sum_{k=1}^{4} k^2
22-pi_is_for_productPi notationi=14i\prod_{i=1}^{4} i
33-peePi notationProduct with expressions
44-hello_derivativesDerivativesf(x)f'(x) for polynomial ff
55-log_on_fireDerivativesDerivative of ln(x)\ln(x) and exe^x
66-voltaireDerivativesDerivative at a specific point
77-partial_truthsPartial derivativesfx\frac{\partial f}{\partial x}
88-all-togetherMixed derivativesCombined partial derivative evaluation
1111-integralIndefinite integralsxndx\int x^n \, dx
1212-integralIndefinite integralsexdx\int e^x \, dx
1313-definiteDefinite integralsabf(x)dx\int_a^b f(x) \, dx
1414-definiteDefinite integralsArea under a curve
1515-definiteDefinite integralsDefinite integral with substitution
1616-doubleDouble integralsf(x,y)dxdy\iint f(x,y) \, dx \, dy

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:

StageTasksTopicWhat you practice
10–1Sigma (Σ\Sigma) notationSumming sequences: i=abf(i)\sum_{i=a}^{b} f(i) — the foundation of series and integrals
22–3Pi (Π\Pi) notationMultiplying sequences: i=abf(i)\prod_{i=a}^{b} f(i) — used in likelihood products and combinatorial formulas
34–6DerivativesPower rule ddxxn=nxn1\frac{d}{dx}x^n = nx^{n-1}, derivative of lnx\ln x, derivative of exe^x, evaluating at a point
47–8Partial derivativesTreating other variables as constants: xf(x,y)\frac{\partial}{\partial x}f(x,y), mixed partials
511–12Indefinite integralsReverse power rule xndx=xn+1n+1+C\int x^n dx = \frac{x^{n+1}}{n+1} + C, exdx=ex+C\int e^x dx = e^x + C
613–15Definite integralsFundamental Theorem of Calculus: abf(x)dx=F(b)F(a)\int_a^b f(x)dx = F(b) - F(a), substitution
716Double integralsIterated integration — integrate inner variable first, then outer: f(x,y)dxdy\iint f(x,y)\,dx\,dy

Key formulas used across these tasks:

OperationFormulaWhen to use
Power rule (derivative)ddxxn=nxn1\frac{d}{dx} x^n = n x^{n-1}Polynomial differentiation
Derivative of lnx\ln xddxlnx=1x\frac{d}{dx} \ln x = \frac{1}{x}Logarithmic differentiation
Derivative of exe^xddxex=ex\frac{d}{dx} e^x = e^xExponential functions
Partial derivativexf(x,y)\frac{\partial}{\partial x} f(x,y) — treat yy as constantMultivariable functions
Power rule (integral)xndx=xn+1n+1+C\int x^n dx = \frac{x^{n+1}}{n+1} + CPolynomial integration
Integral of exe^xexdx=ex+C\int e^x dx = e^x + CExponential integration
Fundamental Theorem of Calculusabf(x)dx=F(b)F(a)\int_a^b f(x)dx = F(b) - F(a)Definite integrals
Double integralf(x,y)dxdy=(f(x,y)dx)dy\iint f(x,y)\,dx\,dy = \int \left(\int f(x,y)\,dx\right)dyArea/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 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 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} using integer arithmetic. Validate that nn is a positive integer. Use // for floor division since the numerator is always divisible by 6.

New techniques introduced:

TechniquePurpose
i=1ni2=n(n+1)(2n+1)6\sum_{i=1}^{n} i^2 = \frac{n(n+1)(2n+1)}{6}Closed-form sum of squares — O(1) instead of O(n)
// integer floor divisionGuarantee integer result when numerator is divisible by denominator
Input validation: isinstance(n, int) and n >= 1Reject non-integer and non-positive inputs
return None for invalid inputSentinel 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] representing a0+a1x+a2x2+a_0 + a_1x + a_2x^2 + \dots, the derivative is a1+2a2x+3a3x2+a_1 + 2a_2x + 3a_3x^2 + \dots. For each coefficient at index ii, multiply by ii (the power) and shift left by 1 position. Handle edge cases: empty list → None, constant polynomial → [0].

New techniques introduced:

TechniquePurpose
Power rule: ddx(aixi)=iaixi1\frac{d}{dx}(a_i x^i) = i \cdot a_i x^{i-1}Derivative of each term is coefficient × power
Coefficient list representationIndex = power, value = coefficient
poly[i] * i for derivative coefficientMultiply 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^n is nanxn1n \cdot a_n x^{n-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_i at index ii (representing aixia_i x^i), the integral term is aii+1xi+1\frac{a_i}{i+1} x^{i+1}. Store at index i+1i+1 in the output. The constant CC goes at index 0. Use integer simplification: if the division is exact, store as int; otherwise store as float.

New techniques introduced:

TechniquePurpose
Reverse power rule: aixidx=aii+1xi+1+C\int a_i x^i \, dx = \frac{a_i}{i+1} x^{i+1} + CIntegral of each term divides by the new exponent
C as the integration constantArbitrary 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 checkHandle the case where C is a float that represents a whole number

Key takeaway: Integration is the inverse of differentiation. Each term axna x^n becomes an+1xn+1\frac{a}{n+1} x^{n+1}. The integration constant CC represents the family of all antiderivatives. Don't forget to shift indices — integrating increases each power by 1.


Technique Inventory

TaskNew technique summarizedCategory
0–8Manual computation: Σ\Sigma, Π\Pi, derivatives, partial derivativesManual Calculus
9Closed-form i2\sum i^2 formula, // integer divisionSummation
10Polynomial derivative via power rule, coefficient list representationDerivatives
11–16Manual computation: indefinite, definite, double integralsManual Calculus
17Polynomial integral via reverse power rule, integration constant CCIntegration

Resources