AI & Coding Real-World Use

AI, Deep Learning & 3D Game Engine Math Applications

Discover how textbook math equations directly power Large Language Models, 3D game shaders, quant finance, and modern cryptography with live code snippets.

The Mathematical Pipeline Behind ChatGPT & Claude Token Generation
Attention⁡(Q,K,V)=softmax⁡ ⁣(QKTdk)V\operatorname{Attention}(Q,K,V) = \operatorname{softmax}\!\left(\frac{QK^T}{\sqrt{d_k}}\right)V
  • Dot Product (#L02): Measures Query-Key semantic alignment across tokens
  • Matrix Multiplication (#L04): Parallelizes multi-head projection on GPU Tensor Cores
  • Softmax (#P10): Converts raw logits into temperature-controlled token probabilities
  • Cross-Entropy (#P09) & Chain Rule (#C03): Evaluates loss and backpropagates gradients

Large Language Models (LLM & Transformer)

Computes contextual token similarity via scaled dot products, normalizes weights with Softmax, and backpropagates Cross-Entropy Loss via the Chain Rule.

#L02 · Linear Alg

Dot Product & Cosine Similarity

a⋅b=∑i=1naibi=∥a∥∥b∥cos⁡θ\mathbf{a} \cdot \mathbf{b} = \sum_{i=1}^{n} a_i b_i = \|\mathbf{a}\|\|\mathbf{b}\|\cos\theta

LLM Transformer Attention (Q·K^T), RAG vector DB cosine search, and 3D Lambertian lighting (N·L)

const cosSim = (a:number[], b:number[]) => dot(a,b) / (norm(a) * norm(b));
#L04 · Linear Alg

Matrix Multiplication & Linear Transformation

(AB)ij=∑k=1nAikBkj(AB)_{ij} = \sum_{k=1}^{n} A_{ik} B_{kj}

90% of NVIDIA GPU Tensor Core compute in Deep Learning (Y = XW) and 3D graphics MVP pipelines

const matMul2 = (A:number[][], B:number[][]) => [[A[0][0]*B[0][0]+A[0][1]*B[1][0], A[0][0]*B[0][1]+A[0][1]*B[1][1]]];
#P02 · Prob & AI

Conditional Probability & Chain Rule

P(A∣B)=P(A∩B)P(B),P(A∩B)=P(B)P(A∣B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}, \quad P(A \cap B) = P(B)P(A \mid B)

Core equation of autoregressive LLMs (like GPT), predicting the next token via P(w_t | w_1...w_{t-1}).

const pAgivenB = (pAB, pB) => pB > 0 ? pAB / pB : 0;
#P09 · Prob & AI

Shannon Entropy & Cross-Entropy Loss

H(P,Q)=−∑xP(x)log⁡Q(x)=H(P)+DKL(P∥Q)H(P, Q) = -\sum_x P(x) \log Q(x) = H(P) + D_{\mathrm{KL}}(P \parallel Q)

The universal training loss function (Cross-Entropy Loss) for LLMs, image classifiers, and decision tree Information Gain.

const bceLoss = (y, yHat) => -(y * Math.log(yHat + 1e-9) + (1 - y) * Math.log(1 - yHat + 1e-9));
#P10 · Prob & AI

Softmax Function & Stochastic Gradient Descent

σ(z)i=ezi/T∑j=1Kezj/T,θt+1=θt−η∇θL(θt)\sigma(\mathbf{z})_i = \frac{e^{z_i / T}}{\sum_{j=1}^K e^{z_j / T}}, \quad \theta_{t+1} = \theta_t - \eta \nabla_\theta \mathcal{L}(\theta_t)

The beating heart of Transformer Self-Attention, LLM Temperature sampling, and all deep learning optimizers (SGD, AdamW).

const softmax = (zs, T=1) => { const exps = zs.map(z => Math.exp(z/T)); const s = exps.reduce((a,b)=>a+b,0); return exps.map(e => e/s); };
#C03 · Calculus

Product Rule & Chain Rule (Backpropagation Core)

dydx=dydu⋅dudx,(uv)′=u′v+uv′\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx},\quad (uv)' = u'v + uv'

Deep neural network Backpropagation and PyTorch/TensorFlow Autograd computational graphs

const dL_dw = dL_dy * dy_du * du_dw; // Backpropagation Chain Rule

Complete 50-Formula Developer Code & AI Matrix

#Linear Layer y=wx+b#UI Lerp Animation#Constraint Solver

Single perceptron linear layer (y = wx + b) in AI and UI layout linear interpolation (Lerp)

const solveLinear = (a: number, b: number) => -b / a;
#Polynomial Kernel SVM#Symbolic Algebra#Completing Square

Polynomial Kernel (SVM) feature expansion in ML and symbolic computer algebra systems

const sqSum = (a: number, b: number) => a*a + 2*a*b + b*b;
#IEEE 754 Float#Shader Gamma Correction#Exponential Scaling

IEEE 754 floating-point exponent encoding and 3D shader gamma correction (c^(1/2.2))

const gammaCorrect = (c: number, g = 2.2) => Math.pow(c, 1 / g);
#3D Ray Tracing#Physics Collision#Optimization Parabola

3D Ray-Sphere intersection in ray tracing shaders and projectile trajectory impact time calculation

const D = b*b - 4*a*c; const x1 = (-b + Math.sqrt(D)) / (2*a);
#Matrix Trace & Det#Control Theory Poles#Symmetric Polynomials

Control theory pole stability checks and matrix eigenvalue trace/determinant verification

const sumRoots = -b / a; const prodRoots = c / a;
#O(log N) Complexity#Log-Likelihood AI#Information Theory

Binary search O(log₂ N) complexity and preventing numerical underflow via Log-Likelihood in AI

const logBase = (a: number, x: number) => Math.log(x) / Math.log(a);
#RL Discounted Return#Quant Finance DCF#Algorithm Loop Analysis

Reinforcement Learning discounted return (∑ γ^t R_t) convergence and compound interest valuation

const geoSum = (a: number, r: number, n: number) => a * (1 - Math.pow(r, n)) / (1 - r);
#Bernstein Basis#Dynamic Programming#Combinatorial AI

Bernstein basis polynomials for 3D Bézier curves and ensemble classifier majority voting

const nCr = (n: number, k: number): number => k === 0 ? 1 : (n * nCr(n - 1, k - 1)) / k;
#Quantum Computing#RF Signal DSP#2D Rotation

FFT audio/RF signal processing, quantum computing qubit amplitudes, and fractal rendering

const mag = Math.hypot(re, im); const phase = Math.atan2(im, re);
#RSA Cryptography#Blockchain Security#Hash Table Modulo

HTTPS/TLS RSA public-key encryption, blockchain digital signatures, and hash table indexing

const modPow = (a: bigint, e: bigint, m: bigint): bigint => /* binary exp */
#Game Physics Distance#L2 Metric Foundation#CAD Geometry

2D/3D game collision distance (Math.hypot) and foundational L2 metric in AI vector spaces

const hypotenuse = (a: number, b: number) => Math.hypot(a, b);
#K-Means & KNN ML#A* Pathfinding#3D Spatial Query

KNN / K-Means clustering distance metric in ML and A* pathfinding heuristic in 3D games

const dist3D = (dx: number, dy: number, dz: number) => Math.hypot(dx, dy, dz);
#Three.js Radians#Robotics Odometry#Shader Angles

Standard angle unit for Three.js/WebGL shaders, Math.sin/cos, and robotics wheel odometry (l = rθ)

const degToRad = (deg: number) => (deg * Math.PI) / 180;
#LLM RoPE Encoding#Wave Shader#Circular Orbit

Transformer LLM Sinusoidal/RoPE Positional Encoding and 3D game wave/orbit animation shaders

const posOnCircle = (r: number, rad: number) => ({ x: r * Math.cos(rad), y: r * Math.sin(rad) });
#Inverse Kinematics IK#GPS Triangulation#Vector Dot Product

Robotics & 3D character Inverse Kinematics (IK) joint angle solver and GPS triangulation

const cosC = (a*a + b*b - c*c) / (2 * a * b);
#Rotation Matrix Proof#5G QAM Modulation#Audio DSP

Deriving 2D/3D rotation matrix composition R(α)R(β)=R(α+β) and RF QAM signal demodulation

const sinAdd = (a: number, b: number) => Math.sin(a)*Math.cos(b) + Math.cos(a)*Math.sin(b);
#Kepler Orbit Sim#Mahalanobis Ellipse#Antenna Optics

Kepler satellite orbit simulation and Multivariate Gaussian covariance ellipses in ML

const eccentricity = (a: number, b: number) => Math.sqrt(1 - (b*b)/(a*a));
#3D Globe Mapping#OrbitControls Camera#Spherical Harmonics

3D globe 360° UV texture mapping, Three.js OrbitControls camera, and quantum spherical harmonics

const toXYZ = (r:number, th:number, ph:number) => [r*Math.sin(ph)*Math.cos(th), r*Math.cos(ph), r*Math.sin(ph)*Math.sin(th)];
#3D Mesh Topology#Graph Theory#CAD Manifold Check

3D polygon manifold mesh validation in Blender/Unreal and VLSI planar graph routing

const eulerChar = (V: number, E: number, F: number) => V - E + F;
#SVG & Font Rendering#CSS cubic-bezier#3D Camera Splines

SVG paths, CSS cubic-bezier easing, TrueType fonts, and autonomous vehicle / 3D camera path planning

const quadBezier = (p0:number, p1:number, p2:number, t:number) => (1-t)*(1-t)*p0 + 2*(1-t)*t*p1 + t*t*p2;
#Sigmoid & Softmax#Continuous Compounding#Calculus Foundation

Deep learning activations (Sigmoid, Softmax, GELU) and continuous compounding e^(rt) in quant finance

const approxE = (n: number) => Math.pow(1 + 1 / n, n);
#Numerical Differentiation#Physics Velocity#Optimization Extremum

Physics engine velocity/acceleration finite differences and neural network loss slope

const diff = (f: (x:number)=>number, x: number, h = 1e-5) => (f(x + h) - f(x - h)) / (2 * h);
#Deep Learning Backprop#PyTorch Autograd#Neural Net Training

Deep neural network Backpropagation and PyTorch/TensorFlow Autograd computational graphs

const dL_dw = dL_dy * dy_du * du_dw; // Backpropagation Chain Rule
#Physics RK4 Integrator#3D Rendering Equation#Probability CDF

Physics engine velocity-to-position integration, 3D ray marching rendering equation, and probability CDF

const simpson = (f:(x:number)=>number, a:number, b:number) => ((b-a)/6)*(f(a)+4*f((a+b)/2)+f(b));
#FEM Physics Sim#Fourier Transform Proof#Signal Laplace

Finite Element Method (FEM weak formulation) physics simulation and Laplace/Fourier derivative rules

const intXeX = (x: number) => (x - 1) * Math.exp(x) + 1; // ∫_0^x t*e^t dt
#XGBoost 2nd-Order Loss#CPU/GPU Fast Math#Physics Linearization

CPU/GPU fast Math.sin/exp approximation and XGBoost / Newton-Raphson 2nd-order optimization

const sinTaylor = (x: number) => x - (x**3)/6 + (x**5)/120 - (x**7)/5040;
#LLM RoPE e^(imθ)#Fourier Basis#Quantum Phase

LLM Rotary Position Embedding (RoPE e^(imθ)), FFT complex basis, and quantum phase gates

const eulerCis = (theta: number) => ({ re: Math.cos(theta), im: Math.sin(theta) });
#Gradient Descent -∇L#Computer Vision Sobel#Physics Field ∇

LLM/Deep Learning loss optimization (-∇L) and computer vision Sobel edge detection gradients

const grad2D = (a:number, b:number, x:number, y:number) => ({ gx: 2*a*x, gy: 2*b*y });
#Audio AI Spectrogram#5G/Wi-Fi OFDM#JPEG/MP3 Compression

Speech AI (Whisper Mel-Spectrograms), MP3/JPEG compression, 5G/Wi-Fi OFDM, and MRI reconstruction

const dftBin = (sig: number[], k: number) => sig.reduce((s, x, n) => s + x * Math.cos(2*Math.PI*k*n/sig.length), 0);
#Diffusion AI ODE#Spring Physics UI#Control Engineering

Generative AI Diffusion ODE solvers, React-Spring UI physics animations, and vehicle suspension control

const zeta = c / (2 * Math.sqrt(m * k)); const w0 = Math.sqrt(k / m);
#L1/L2 Regularization#3D Vector Normalize#Embedding Norm

Deep learning L1/L2 Weight Decay regularization, LayerNorm, and 3D game movement vector normalization

const norm2 = Math.hypot(vx, vy, vz); const unit = [vx/norm2, vy/norm2, vz/norm2];
#LLM Self-Attention Q·K#RAG Vector DB#3D Lighting Shader

LLM Transformer Attention (Q·K^T), RAG vector DB cosine search, and 3D Lambertian lighting (N·L)

const cosSim = (a:number[], b:number[]) => dot(a,b) / (norm(a) * norm(b));
#3D Surface Normal#Physics Torque r×F#Back-face Culling

3D mesh triangle surface normals, back-face culling, and physics torque (τ = r × F) calculation

const cross = (a:number[], b:number[]) => [a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0]];
#GPU Tensor Cores GEMM#Deep Learning Y=XW#3D MVP Pipeline

90% of NVIDIA GPU Tensor Core compute in Deep Learning (Y = XW) and 3D graphics MVP pipelines

const matMul2 = (A:number[][], B:number[][]) => [[A[0][0]*B[0][0]+A[0][1]*B[1][0], A[0][0]*B[0][1]+A[0][1]*B[1][1]]];
#3D Mouse Raycasting#Jacobian Determinant#Normalizing Flows

3D mouse raycasting unprojection (MVP⁻¹) in games and Jacobian determinants in Normalizing Flow AI

const det2 = (a:number, b:number, c:number, d:number) => a * d - b * c;
#Linear Solver Ax=b#SPICE Circuit Sim#Normal Equations

SPICE circuit simulation, structural mechanics solvers, and Least Squares Normal Equations

const det = a1*b2 - b1*a2; const x = (c1*b2 - b1*c2)/det; const y = (a1*c2 - c1*a2)/det;
#3D Engine Rotation#LiDAR Point Cloud#Orthogonal Matrix SO(3)

Three.js/Unreal/Unity 3D object & camera rotation and LiDAR point-cloud alignment (ICP)

const rot2D = (x:number, y:number, r:number) => ({ x: x*Math.cos(r) - y*Math.sin(r), y: x*Math.sin(r) + y*Math.cos(r) });
#Google PageRank#Quantum Mechanics Hψ=Eψ#Spectral Graph Theory

Google PageRank algorithm, quantum mechanics Hamiltonian energy states (Hψ=Eψ), and structural resonance

const tr = a + d; const det = a*d - b*c; const l1 = (tr + Math.sqrt(tr*tr - 4*det))/2;
#LLM LoRA Fine-Tuning#PCA Dimensionality#Recommender System

LLM Low-Rank Adaptation (LoRA), PCA dimensionality reduction, recommender systems, and image compression

const explainedRatio = (s1:number, s2:number, s3:number) => (s1*s1) / (s1*s1 + s2*s2 + s3*s3);
#Three.js Quaternion#Gimbal Lock Free#Aerospace Attitude

Three.js/Unity/Unreal skeletal animation (Quaternion SLERP) and spacecraft/drone attitude control

const quatFromAxisZ = (rad: number) => ({ w: Math.cos(rad/2), x: 0, y: 0, z: Math.sin(rad/2) });
#Combinatorics#Search Space#Algorithm Complexity#Feature Selection

Used in algorithm search-space complexity analysis, hyperparameter grid search sizing, and feature subset selection.

const nCr = (n, r) => Array.from({length: r}, (_, i) => (n - i) / (i + 1)).reduce((a, b) => a * b, 1);
#LLM Next-Token#Autoregressive AI#Markov Chains#Probabilistic Graphical Models

Core equation of autoregressive LLMs (like GPT), predicting the next token via P(w_t | w_1...w_{t-1}).

const pAgivenB = (pAB, pB) => pB > 0 ? pAB / pB : 0;
#Spam Filter#Bayesian Inference#Medical AI Diagnosis#Kalman Filter

Powers spam email filtering (Naive Bayes), medical AI diagnostic calibration, autonomous driving Kalman/particle filters, and Bayesian optimization.

const bayes = (prior, sens, fpr) => (sens * prior) / (sens * prior + fpr * (1 - prior));
#Reinforcement Learning#Batch Normalization#Quant Risk#Weight Initialization

Core to Reinforcement Learning expected reward maximization, Batch/Layer Normalization, and Xavier/He weight initialization.

const mean = xs.reduce((a,b)=>a+b,0)/xs.length; const variance = xs.reduce((s,x)=>s+(x-mean)**2,0)/xs.length;
#A/B Testing#Dropout Regularization#CTR Modeling#Game Gacha Math

Used in ad CTR A/B testing, neural network Dropout masking probability modeling, and game gacha drop-rate simulation.

const binomPMF = (n, k, p) => nCr(n, k) * Math.pow(p, k) * Math.pow(1 - p, n - k);
#Diffusion Models#3D Gaussian Splatting#VAE Latent Space#Anomaly Detection

Powers Diffusion Models (Stable Diffusion) Gaussian noise scheduling, Variational Autoencoders (VAE), and 3D Gaussian Splatting (3DGS).

const normalPDF = (x, mu, sig) => Math.exp(-0.5 * ((x - mu) / sig) ** 2) / (sig * Math.sqrt(2 * Math.PI));
#Mini-Batch SGD#Monte Carlo Ray Tracing#Confidence Intervals#Statistical Inference

Explains the 1/√n variance reduction in Mini-Batch SGD gradients and Monte Carlo Ray Tracing error bounds.

const stdError = (sigma, n) => sigma / Math.sqrt(n); const ci95 = (mean, se) => [mean - 1.96*se, mean + 1.96*se];
#Linear Regression#Supervised ML#Quant Finance Beta#Feature Engineering

Foundation of supervised machine learning linear predictors, quant finance portfolio Beta (β), and feature correlation analysis.

const slope = covXY / varX; const intercept = meanY - slope * meanX; const r = covXY / Math.sqrt(varX * varY);
#Cross-Entropy Loss#LLM Pretraining#Information Theory#KL Divergence

The universal training loss function (Cross-Entropy Loss) for LLMs, image classifiers, and decision tree Information Gain.

const bceLoss = (y, yHat) => -(y * Math.log(yHat + 1e-9) + (1 - y) * Math.log(1 - yHat + 1e-9));
#Transformer Attention#Deep Learning Optimizer#LLM Temperature#Backpropagation

The beating heart of Transformer Self-Attention, LLM Temperature sampling, and all deep learning optimizers (SGD, AdamW).

const softmax = (zs, T=1) => { const exps = zs.map(z => Math.exp(z/T)); const s = exps.reduce((a,b)=>a+b,0); return exps.map(e => e/s); };