Back to Blog

Math — Calculus

·Reha Tuncer·Math
CalculusDerivativesIntegralsMathPythonPolynomials
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

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