# Formula Bro > Plain-English explanations of 161 formulas from AI and machine learning, computer science, electricity and quantum mechanics. Every page defines each symbol with its unit, says how to read the formula aloud, and works one numeric example whose numbers are recomputed by script on every build. A side project developed by Yunus Emre Vurgun (https://yunusemrevurgun.com). Quote freely with a link to the page you used. Content last updated 2026-10-22. Every HTML page has a Markdown copy at the same path with .md instead of the trailing slash (for example https://formulabro.yunusemrevurgun.com/ai-ml/softmax.md). Machine-readable copies: [all pages in one file](https://formulabro.yunusemrevurgun.com/llms-full.txt), [JSON of every formula with LaTeX and symbols](https://formulabro.yunusemrevurgun.com/formulas.json), [sitemap](https://formulabro.yunusemrevurgun.com/sitemap.xml), [Atom feed](https://formulabro.yunusemrevurgun.com/feed.xml), [notes for AI agents](https://formulabro.yunusemrevurgun.com/for-ai-agents/). ## AI & Machine Learning Hub: [AI & Machine Learning formulas](https://formulabro.yunusemrevurgun.com/ai-ml/). The formulas behind machine learning, from the artificial neuron and loss functions to Adam, attention and Q-learning, in plain English with worked examples. - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/): An artificial neuron multiplies each input by a weight, adds them up with a bias, and then decides how strongly to fire. Formula: $z = \sum_{i=1}^{n} w_i x_i + b, \quad a = f(z)$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron.md - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/): The sigmoid takes any number, however big or small, and squeezes it into a value between 0 and 1 that can be read as a chance. Formula: $\sigma(z) = \frac{1}{1 + e^{-z}}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function.md - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/): Softmax takes a list of scores, any numbers at all, and turns them into percentages that add up to 100%. Formula: $\operatorname{softmax}(z)_i = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/softmax.md - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/): Mean squared error measures how wrong a model's guesses are by squaring each miss, so big misses count much more, and then averaging them. Formula: $\mathrm{MSE} = \frac{1}{n}\sum_{i=1}^{n} (y_i - \hat{y}_i)^2$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error.md - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/): Cross-entropy loss gives a small score when the model was confident in the right answer and a big score when it was not. Formula: $L = -\sum_{i=1}^{K} y_i \ln(\hat{y}_i)$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss.md - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/): Gradient descent nudges a model's settings a small step in the direction that lowers the error, then repeats until the error stops falling. Formula: $\theta_{\text{new}} = \theta_{\text{old}} - \eta \, \nabla L(\theta_{\text{old}})$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent.md - [Bayes' Theorem](https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem/): Bayes' theorem tells you how much to change your belief in something after you see new evidence. Formula: $P(A \mid B) = \frac{P(B \mid A)\, P(A)}{P(B)}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem.md - [Scaled Dot-Product Attention](https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention/): Attention lets a model look at every item in a list and decide how much each one matters for the item it is working on. Formula: $\operatorname{Attention}(Q, K, V) = \operatorname{softmax}\left(\frac{Q K^{\top}}{\sqrt{d_k}}\right) V$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention.md - [Linear Regression](https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression/): Linear regression predicts a number by drawing the straight line that sits closest to the data points, so you can read off a guess for any new input. Formula: $\hat{y} = w x + b$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression.md - [Logistic Regression](https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression/): Logistic regression takes the same weighted sum as a straight line, then squeezes it through an S-shaped curve so the result is a probability between 0 and 1. Formula: $p = \sigma(w x + b) = \frac{1}{1 + e^{-(w x + b)}}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression.md - [ReLU Activation](https://formulabro.yunusemrevurgun.com/ai-ml/relu-activation/): ReLU passes positive numbers through unchanged and replaces every negative number with zero, like a switch that is on for positive input and off otherwise. Formula: $\text{ReLU}(z) = \max(0, z)$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/relu-activation.md - [Tanh Activation](https://formulabro.yunusemrevurgun.com/ai-ml/tanh-activation/): Tanh squashes any input into a number between minus 1 and plus 1, with zero at the center, so a negative input gives a negative output. Formula: $\tanh(z) = \frac{e^{z} - e^{-z}}{e^{z} + e^{-z}}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/tanh-activation.md - [Mean Absolute Error (MAE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-absolute-error/): Mean absolute error measures how far off a model's guesses are on average, counting each miss by its size only, so one wild miss does not dominate the score. Formula: $\mathrm{MAE} = \frac{1}{n}\sum_{i=1}^{n} |y_i - \hat{y}_i|$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/mean-absolute-error.md - [Huber Loss](https://formulabro.yunusemrevurgun.com/ai-ml/huber-loss/): Huber loss scores small misses by squaring them, as mean squared error does, and large misses with a straight-line penalty, so outliers cannot take over the score. Formula: $L_{\delta}(a) = \begin{cases} \frac{1}{2} a^{2} & \text{if } |a| \le \delta \\ \delta \left(|a| - \frac{1}{2}\delta\right) & \text{otherwise} \end{cases}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/huber-loss.md - [Hinge Loss](https://formulabro.yunusemrevurgun.com/ai-ml/hinge-loss/): Hinge loss gives no penalty to an answer that is correct with room to spare, and a growing penalty as an answer gets wrong or too close to the boundary. Formula: $L = \max(0,\ 1 - y\, f(x))$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/hinge-loss.md - [L2 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization/): L2 regularization adds a penalty for large weights, so the model prefers small, gentle weights that tend to generalize better to new data. Formula: $J(w) = L(w) + \lambda \sum_{j} w_j^{2}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization.md - [L1 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l1-regularization/): L1 regularization adds a penalty proportional to each weight's size, which encourages the model to drop unneeded inputs by setting their weights to exactly zero. Formula: $J(w) = L(w) + \lambda \sum_{j} |w_j|$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/l1-regularization.md - [Momentum Optimizer](https://formulabro.yunusemrevurgun.com/ai-ml/momentum-optimizer/): Momentum lets gradient descent remember its recent steps, so it speeds up where the slope keeps pointing the same way and wobbles less where it flips. Formula: $v_t = \beta \, v_{t-1} + \nabla L(\theta_{t-1}) \qquad \theta_t = \theta_{t-1} - \eta \, v_t$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/momentum-optimizer.md - [Adam Optimizer](https://formulabro.yunusemrevurgun.com/ai-ml/adam-optimizer/): Adam keeps a running average of each setting's slope and of how big those slopes have been, then uses both to choose a step size for every setting. Formula: $\theta_t = \theta_{t-1} - \eta \, \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/adam-optimizer.md - [Backpropagation and the Chain Rule](https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule/): Backpropagation finds how much each weight affects the error by multiplying the small slopes along the chain from the weight to the loss. Formula: $\frac{\partial L}{\partial w} = \frac{\partial L}{\partial \hat y} \, \frac{\partial \hat y}{\partial z} \, \frac{\partial z}{\partial w}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule.md - [Batch Normalization](https://formulabro.yunusemrevurgun.com/ai-ml/batch-normalization/): Batch normalization rescales the values in a group of examples so they are centered near zero with a steady spread, then lets the network choose its own scale and offset. Formula: $\hat x_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}} \qquad y_i = \gamma \, \hat x_i + \beta$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/batch-normalization.md - [Layer Normalization](https://formulabro.yunusemrevurgun.com/ai-ml/layer-normalization/): Layer normalization centers and scales the numbers that describe one example, so its values stay in a steady range no matter what other examples are in the batch. Formula: $\hat x_i = \frac{x_i - \mu}{\sqrt{\sigma^2 + \epsilon}} \qquad y_i = \gamma_i \, \hat x_i + \beta_i$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/layer-normalization.md - [Dropout](https://formulabro.yunusemrevurgun.com/ai-ml/dropout/): Dropout randomly switches off some neurons on each training pass, and scales up the ones that stay on, so the network learns patterns that do not rely on any single neuron. Formula: $\tilde h_i = \frac{m_i \, h_i}{1 - p} \qquad m_i \sim \text{Bernoulli}(1 - p)$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/dropout.md - [Precision and Recall](https://formulabro.yunusemrevurgun.com/ai-ml/precision-and-recall/): Precision asks how many of the items a model flagged were right, and recall asks how many of the real cases it managed to find. Formula: $\text{Precision} = \frac{TP}{TP + FP} \qquad \text{Recall} = \frac{TP}{TP + FN}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/precision-and-recall.md - [F1 Score](https://formulabro.yunusemrevurgun.com/ai-ml/f1-score/): The F1 score is one number from 0 to 1 that stays low unless both precision and recall are reasonably high. Formula: $F_1 = \frac{2 \cdot P \cdot R}{P + R}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/f1-score.md - [Classification Accuracy](https://formulabro.yunusemrevurgun.com/ai-ml/classification-accuracy/): Accuracy is the share of a model's guesses that were right, out of all the guesses it made. Formula: $\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/classification-accuracy.md - [Cosine Similarity](https://formulabro.yunusemrevurgun.com/ai-ml/cosine-similarity/): Cosine similarity scores how closely two lists of numbers point the same way, from -1 for opposite directions to 1 for the same direction. Formula: $\cos\theta = \frac{\mathbf{A}\cdot\mathbf{B}}{\|\mathbf{A}\|\,\|\mathbf{B}\|}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/cosine-similarity.md - [Euclidean Distance](https://formulabro.yunusemrevurgun.com/ai-ml/euclidean-distance/): Euclidean distance is the straight-line distance between two points, found by squaring the gaps, adding them up and taking the square root. Formula: $d(\mathbf{p}, \mathbf{q}) = \sqrt{\sum_{i=1}^{n} (p_i - q_i)^2}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/euclidean-distance.md - [k-Means Clustering](https://formulabro.yunusemrevurgun.com/ai-ml/k-means-clustering/): k-means clustering sorts points into K groups by moving each group's center to its middle and reassigning every point to its nearest center. Formula: $J = \sum_{k=1}^{K} \sum_{\mathbf{x} \in C_k} \|\mathbf{x} - \boldsymbol{\mu}_k\|^2$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/k-means-clustering.md - [Kullback-Leibler Divergence](https://formulabro.yunusemrevurgun.com/ai-ml/kl-divergence/): KL divergence measures how badly a set of guessed probabilities fits the real probabilities. Formula: $D_{\mathrm{KL}}(P \,\|\, Q) = \sum_x P(x) \log \frac{P(x)}{Q(x)}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/kl-divergence.md - [Naive Bayes Classifier](https://formulabro.yunusemrevurgun.com/ai-ml/naive-bayes-classifier/): Naive Bayes guesses the most likely class by multiplying how common the class is by how well each clue fits it. Formula: $P(y \mid x_1, \dots, x_n) \propto P(y) \prod_{i=1}^{n} P(x_i \mid y)$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/naive-bayes-classifier.md - [Gini Impurity](https://formulabro.yunusemrevurgun.com/ai-ml/gini-impurity/): Gini impurity is a score for how mixed the classes are in a group: 0 means every item in the group belongs to the same class. Formula: $G = 1 - \sum_{k=1}^{K} p_k^2$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/gini-impurity.md - [Information Gain](https://formulabro.yunusemrevurgun.com/ai-ml/information-gain/): Information gain tells you how many bits of guessing a split removes, so a tree can ask the question that sorts the examples best. Formula: $\mathrm{IG} = H(\text{parent}) - \sum_{k} \frac{n_k}{n}\, H(\text{child}_k)$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/information-gain.md - [Softmax Temperature](https://formulabro.yunusemrevurgun.com/ai-ml/softmax-temperature/): Temperature is a dial that makes a model's choices more focused when it is low and more varied when it is high. Formula: $p_i = \frac{e^{z_i / T}}{\sum_{j=1}^{K} e^{z_j / T}}$. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/softmax-temperature.md - [Perplexity](https://formulabro.yunusemrevurgun.com/ai-ml/perplexity/): Perplexity counts how many words a language model is, on average, torn between each time it guesses the next word. Lower is better. Formula: $\text{PPL} = \exp\left(-\frac{1}{N}\sum_{i=1}^{N} \ln p(w_i \mid w_{ 0,\ n_0 \text{ such that } 0 \le f(n) \le c\, g(n) \text{ for all } n \ge n_0$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/big-o-notation.md - [Master Theorem](https://formulabro.yunusemrevurgun.com/computer-science/master-theorem/): The master theorem gives the running time of a divide-and-conquer algorithm by comparing the work at each split with the work at the bottom of the recursion. Formula: $T(n) = a\, T(n/b) + f(n)$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/master-theorem.md - [Sum of the First n Integers](https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers/): This formula adds the counting numbers from 1 to n in one step, so you never have to add them one at a time. Formula: $\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers.md - [Geometric Series](https://formulabro.yunusemrevurgun.com/computer-science/geometric-series/): A geometric series adds terms where each one is the last one times a fixed ratio, and this formula adds them all in one step. Formula: $\sum_{k=0}^{n-1} r^{k} = \frac{1 - r^{n}}{1 - r} \quad (r \neq 1)$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/geometric-series.md - [Permutations](https://formulabro.yunusemrevurgun.com/computer-science/permutations/): A permutation is an ordered arrangement, and this formula counts how many ways you can pick k items from n and line them up. Formula: $P(n, k) = \frac{n!}{(n-k)!}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/permutations.md - [Combinations](https://formulabro.yunusemrevurgun.com/computer-science/combinations/): A combination counts how many different groups you can pick from a set of items when the order of the picks does not matter. Formula: $C(n,k) = \binom{n}{k} = \frac{n!}{k!\,(n-k)!}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/combinations.md - [Pigeonhole Principle](https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle/): If you put more things than boxes into the boxes, at least one box must hold two or more things. Formula: $\max_{j}\, b_j \ge \left\lceil \frac{n}{m} \right\rceil$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle.md - [Inclusion-Exclusion Principle](https://formulabro.yunusemrevurgun.com/computer-science/inclusion-exclusion-principle/): Inclusion-exclusion counts how many items belong to at least one group by adding the groups and then removing the overlaps that were counted twice. Formula: $|A \cup B| = |A| + |B| - |A \cap B|$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/inclusion-exclusion-principle.md - [Hash Table Load Factor](https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor/): The load factor is how full a hash table is on average: the number of keys divided by the number of buckets. Formula: $\alpha = \frac{n}{m}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor.md - [Birthday Problem](https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem/): The birthday problem asks how likely it is that some pair of items in a random group matches, and the answer rises faster than most people expect. Formula: $P(\text{no collision}) = \prod_{k=0}^{n-1}\left(1 - \frac{k}{N}\right) \approx e^{-n(n-1)/(2N)}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem.md - [Bloom Filter False Positive Rate](https://formulabro.yunusemrevurgun.com/computer-science/bloom-filter-false-positive-rate/): The false positive rate of a Bloom filter is the chance that it wrongly says an item is present, and it depends on the bits, the items and the hash functions. Formula: $p \approx \left(1 - e^{-kn/m}\right)^{k}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/bloom-filter-false-positive-rate.md - [Modulo Operation](https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation/): The modulo operation gives the leftover amount after you divide one whole number by another as many full times as you can. Formula: $a \bmod n = a - n \left\lfloor \frac{a}{n} \right\rfloor$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation.md - [Euclidean Algorithm](https://formulabro.yunusemrevurgun.com/computer-science/euclidean-algorithm-gcd/): The Euclidean algorithm finds the largest number that divides two numbers evenly, by replacing the pair with a smaller pair again and again. Formula: $\gcd(a, b) = \gcd(b,\ a \bmod b), \qquad \gcd(a, 0) = a$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/euclidean-algorithm-gcd.md - [RSA Encryption](https://formulabro.yunusemrevurgun.com/computer-science/rsa-encryption/): RSA lets anyone lock a message with a public key while only the owner can unlock it with a private key, because undoing a product of two secret primes is very hard. Formula: $c = m^{e} \bmod n, \qquad m = c^{d} \bmod n$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/rsa-encryption.md - [Hamming Distance](https://formulabro.yunusemrevurgun.com/computer-science/hamming-distance/): Hamming distance counts how many positions two equal-length codes differ in, and that count tells you how many errors a code can catch. Formula: $d(x, y) = \sum_{i=1}^{n} [x_i \ne y_i]$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/hamming-distance.md - [Password Entropy](https://formulabro.yunusemrevurgun.com/computer-science/password-entropy/): Password entropy is a number of bits that measures how many possible passwords a random generator could have produced, and so how hard guessing one is. Formula: $H = L \log_2 N$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/password-entropy.md - [Data Transfer Time](https://formulabro.yunusemrevurgun.com/computer-science/data-transfer-time/): Data transfer time tells you how long a file takes to send: divide its size by the link's speed, using units that match. Formula: $t = \frac{S}{B}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/data-transfer-time.md - [Bandwidth-Delay Product](https://formulabro.yunusemrevurgun.com/computer-science/bandwidth-delay-product/): The bandwidth-delay product tells you how much data must be in transit at once to keep a network link full. Formula: $\text{BDP} = B \times \text{RTT}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/bandwidth-delay-product.md - [Nyquist Sampling Theorem](https://formulabro.yunusemrevurgun.com/computer-science/nyquist-sampling-theorem/): The Nyquist sampling theorem tells you how fast you must sample a signal, at more than twice its highest frequency, to capture it without distortion. Formula: $f_s > 2 f_{\max}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/nyquist-sampling-theorem.md - [Shannon-Hartley Theorem](https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem/): The Shannon-Hartley theorem gives the highest error-free bit rate a noisy channel can carry, from its bandwidth and how strong the signal is compared with the noise. Formula: $C = B \log_2\left(1 + \frac{S}{N}\right)$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem.md - [Average Memory Access Time](https://formulabro.yunusemrevurgun.com/computer-science/average-memory-access-time/): Average memory access time, or AMAT, is the average time one memory read takes, given how often the cache finds the data and how costly a miss is. Formula: $\text{AMAT} = t_{\text{hit}} + r_{\text{miss}} \times t_{\text{penalty}}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/average-memory-access-time.md - [CPU Time Equation](https://formulabro.yunusemrevurgun.com/computer-science/cpu-time-equation/): The CPU time equation tells you how long a program takes on a processor, from how many instructions it runs, how many cycles each one needs and how fast the clock ticks. Formula: $T_{\text{CPU}} = IC \times CPI \times t_{\text{clock}} = \frac{IC \times CPI}{f}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/cpu-time-equation.md - [Gustafson's Law](https://formulabro.yunusemrevurgun.com/computer-science/gustafsons-law/): Gustafson's law estimates how much more work a parallel computer finishes in the same time when the job grows with the number of processors. Formula: $S = N - s\,(N - 1)$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/gustafsons-law.md - [System Availability](https://formulabro.yunusemrevurgun.com/computer-science/system-availability/): System availability tells you the fraction of time a system is working, based on how often it breaks and how long the repair takes. Formula: $A = \frac{\text{MTBF}}{\text{MTBF} + \text{MTTR}}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/system-availability.md - [M/M/1 Queue](https://formulabro.yunusemrevurgun.com/computer-science/mm1-queue/): The M/M/1 formula tells you how long, on average, an item spends in a line with one server, based on how fast items arrive and how fast the server works. Formula: $W = \frac{1}{\mu - \lambda}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/mm1-queue.md - [Perfect Binary Tree Nodes](https://formulabro.yunusemrevurgun.com/computer-science/perfect-binary-tree-nodes/): The formula counts the nodes in a perfect binary tree from its height, by doubling the number of nodes on each level. Formula: $N = 2^{h+1} - 1$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/perfect-binary-tree-nodes.md - [Complete Graph Edges](https://formulabro.yunusemrevurgun.com/computer-science/complete-graph-edges/): A complete graph joins every pair of points with one line, and this formula counts how many lines that takes. Formula: $E = \frac{n(n-1)}{2}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/complete-graph-edges.md - [Euler's Formula for Planar Graphs](https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs/): Euler's formula says that if you draw a connected network on a flat sheet with no crossing lines, counting corners, lines and regions always gives 2. Formula: $V - E + F = 2$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs.md - [PageRank](https://formulabro.yunusemrevurgun.com/computer-science/pagerank/): PageRank gives each web page a score based on how many good pages link to it, so each link acts like a vote with a weight. Formula: $PR(p) = \frac{1 - d}{N} + d \sum_{q \to p} \frac{PR(q)}{L(q)}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/pagerank.md - [TF-IDF](https://formulabro.yunusemrevurgun.com/computer-science/tf-idf/): TF-IDF gives a word a high score in a document when the word appears often there but rarely in the other documents. Formula: $\text{tfidf}(t, d) = \text{tf}(t, d) \times \ln\frac{N}{\text{df}(t)}$. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/tf-idf.md ## Electricity Hub: [Electricity formulas](https://formulabro.yunusemrevurgun.com/electricity/). Electricity formulas for beginners: Ohm's law, power, dividers, capacitors, inductors, AC circuits, transformers and magnetism, each with a worked example. - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/): Ohm's law says the push on a wire, the voltage, equals the flow through it, the current, times how hard that flow is to get through, the resistance. Formula: $V = I R$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/ohms-law.md - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/): Electric power tells you how fast a device uses energy, and you get it by multiplying the volts by the amps to get watts. Formula: $P = V I$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/electric-power.md - [Energy and Kilowatt-Hours](https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours/): Energy is power multiplied by time, so a heater that uses 2 kilowatts for 3 hours uses 6 kilowatt-hours of energy. Formula: $E = P \, t$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours.md - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/): Resistors in a line add up, and resistors side by side always give a total smaller than the smallest one. Formula: $R_{\text{series}} = R_1 + R_2 + \cdots + R_n \qquad \frac{1}{R_{\text{parallel}}} = \frac{1}{R_1} + \frac{1}{R_2} + \cdots + \frac{1}{R_n}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel.md - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/): Kirchhoff's current law says that whatever electricity flows into a junction has to flow out again, because nothing piles up there. Formula: $\sum I_{\text{in}} = \sum I_{\text{out}}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law.md - [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/): The RC time constant tells you how long a capacitor takes to fill up through a resistor: multiply the resistance by the capacitance. Formula: $\tau = R C$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant.md - [Coulomb's Law](https://formulabro.yunusemrevurgun.com/electricity/coulombs-law/): Coulomb's law tells you how hard two electric charges push or pull each other, and the force gets weaker fast as they move apart. Formula: $F = k_e \frac{|q_1 q_2|}{r^2}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/coulombs-law.md - [Charge and Current](https://formulabro.yunusemrevurgun.com/electricity/charge-and-current/): Electric current is how much charge passes a point each second, so the same charge moving faster means more current. Formula: $I = \frac{Q}{t}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/charge-and-current.md - [Kirchhoff's Voltage Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-voltage-law/): Kirchhoff's voltage law says that if you walk all the way around a circuit loop, the voltage gained equals the voltage lost. Formula: $\sum_{k} V_k = 0$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-voltage-law.md - [Voltage Divider](https://formulabro.yunusemrevurgun.com/electricity/voltage-divider/): A voltage divider uses two resistors in series to take a smaller share of a supply voltage, with the share set by their ratio. Formula: $V_{\text{out}} = V_{\text{in}} \frac{R_2}{R_1 + R_2}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/voltage-divider.md - [Current Divider](https://formulabro.yunusemrevurgun.com/electricity/current-divider/): A current divider splits a total current between two parallel resistors, and the smaller resistor always takes the bigger share. Formula: $I_1 = I_{\text{total}} \frac{R_2}{R_1 + R_2}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/current-divider.md - [Resistivity](https://formulabro.yunusemrevurgun.com/electricity/resistivity/): A wire's resistance grows with its length, shrinks with its thickness, and depends on what the wire is made of. Formula: $R = \rho \frac{L}{A}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/resistivity.md - [Temperature Coefficient of Resistance](https://formulabro.yunusemrevurgun.com/electricity/temperature-coefficient-of-resistance/): Most metals get harder to push current through as they get hotter, and this formula estimates how much the resistance rises. Formula: $R = R_0\left[1 + \alpha (T - T_0)\right]$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/temperature-coefficient-of-resistance.md - [Drift Velocity](https://formulabro.yunusemrevurgun.com/electricity/drift-velocity/): Electrons in a copper wire drift along at a fraction of a millimetre per second, even though the electric signal races along the wire. Formula: $v_d = \frac{I}{n q A}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/drift-velocity.md - [Internal Resistance](https://formulabro.yunusemrevurgun.com/electricity/internal-resistance/): A real battery has a small resistance inside it, so its output voltage drops when it pushes a current through a load. Formula: $V = \varepsilon - I r$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/internal-resistance.md - [Maximum Power Transfer](https://formulabro.yunusemrevurgun.com/electricity/maximum-power-transfer/): A load receives the most power when its resistance matches the source's resistance, but then half the power is lost inside the source. Formula: $R_L = R_S \qquad P_{\max} = \frac{V_S^2}{4 R_S}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/maximum-power-transfer.md - [Wheatstone Bridge](https://formulabro.yunusemrevurgun.com/electricity/wheatstone-bridge/): A Wheatstone bridge finds an unknown resistance by adjusting a known one until the meter between two midpoints reads zero, then doing one multiply and one divide. Formula: $\frac{R_1}{R_2} = \frac{R_3}{R_x}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/wheatstone-bridge.md - [Battery Capacity and Runtime](https://formulabro.yunusemrevurgun.com/electricity/battery-capacity-runtime/): Divide a battery's capacity by the current the device draws, and you get roughly how many hours the battery will run it. Formula: $t = \frac{C}{I}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/battery-capacity-runtime.md - [Capacitance](https://formulabro.yunusemrevurgun.com/electricity/capacitance/): Capacitance tells you how much electric charge a capacitor stores for each volt across it. Formula: $Q = C V$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/capacitance.md - [Parallel-Plate Capacitor](https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor/): The parallel-plate formula says a capacitor holds more charge per volt when its plates are bigger, closer together, or separated by a material with a higher permittivity. Formula: $C = \frac{\varepsilon_0 \varepsilon_r A}{d}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor.md - [Capacitors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/capacitors-in-series-and-parallel/): Capacitors side by side add their capacitance, while capacitors chained end to end give a smaller total that is found with reciprocals. Formula: $C_{\text{par}} = C_1 + C_2 + \cdots \qquad \frac{1}{C_{\text{ser}}} = \frac{1}{C_1} + \frac{1}{C_2} + \cdots$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/capacitors-in-series-and-parallel.md - [Energy Stored in a Capacitor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor/): A charged capacitor stores energy in the electric field between its plates, and the amount grows with the square of the voltage. Formula: $E = \frac{1}{2} C V^2$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor.md - [Inductor Voltage](https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage/): An inductor pushes back against changes in current, and the voltage across it is set by how fast the current is changing. Formula: $V = L \frac{dI}{dt}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage.md - [Energy Stored in an Inductor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor/): A coil with current flowing through it stores energy in its magnetic field, and the amount grows with the square of the current. Formula: $E = \frac{1}{2} L I^2$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor.md - [RL Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rl-time-constant/): The RL time constant tells you how long current takes to build up in a coil connected through a resistor: divide the inductance by the resistance. Formula: $\tau = \frac{L}{R}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rl-time-constant.md - [Capacitive Reactance](https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance/): Capacitive reactance tells you how hard a capacitor pushes back against alternating current, and it gets smaller as the frequency goes up. Formula: $X_C = \frac{1}{2\pi f C}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance.md - [Inductive Reactance](https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance/): Inductive reactance tells you how hard a coil pushes back against alternating current, and it gets bigger as the frequency goes up. Formula: $X_L = 2\pi f L$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance.md - [Series RLC Impedance](https://formulabro.yunusemrevurgun.com/electricity/rlc-impedance/): Impedance is the total opposition a series circuit of a resistor, a coil and a capacitor gives to alternating current. Formula: $Z = \sqrt{R^2 + (X_L - X_C)^2}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rlc-impedance.md - [Resonant Frequency](https://formulabro.yunusemrevurgun.com/electricity/resonant-frequency/): The resonant frequency is the one frequency where a coil and a capacitor trade energy back and forth most easily, and radios use it to tune in stations. Formula: $f_0 = \frac{1}{2\pi\sqrt{LC}}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/resonant-frequency.md - [RMS Voltage](https://formulabro.yunusemrevurgun.com/electricity/rms-voltage/): RMS voltage is the steady voltage that heats a resistor as much as an AC sine wave does, and you get it by dividing the peak voltage by the square root of 2. Formula: $V_{\text{rms}} = \frac{V_{\text{peak}}}{\sqrt{2}}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rms-voltage.md - [AC Power Factor](https://formulabro.yunusemrevurgun.com/electricity/ac-power-factor/): Power factor tells you what share of the current in an AC circuit does useful work, and it is the ratio of real power to apparent power. Formula: $P = V_{\text{rms}} I_{\text{rms}} \cos\varphi$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/ac-power-factor.md - [Three-Phase Power](https://formulabro.yunusemrevurgun.com/electricity/three-phase-power/): Three-phase power tells you how much real power a balanced three-wire AC load uses, and you get it from the line voltage, the line current and the power factor. Formula: $P = \sqrt{3}\, V_L I_L \cos\varphi$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/three-phase-power.md - [Transformer Turns Ratio](https://formulabro.yunusemrevurgun.com/electricity/transformer-turns-ratio/): A transformer changes an AC voltage up or down in the same ratio as the number of wire turns on its two coils. Formula: $\frac{V_s}{V_p} = \frac{N_s}{N_p}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/transformer-turns-ratio.md - [Electric Field of a Point Charge](https://formulabro.yunusemrevurgun.com/electricity/electric-field-of-point-charge/): The electric field around a charge tells you the push that a small test charge would feel at each point in space. Formula: $E = \frac{k_e\, q}{r^2}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/electric-field-of-point-charge.md - [Electric Potential](https://formulabro.yunusemrevurgun.com/electricity/electric-potential/): Electric potential tells you how much energy each unit of charge would have at a spot in space, measured in volts. Formula: $V = \frac{k_e\, q}{r}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/electric-potential.md - [Magnetic Force on a Moving Charge](https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge/): A magnetic field pushes a moving charge sideways, and the push is biggest when the charge moves straight across the field lines. Formula: $F = |q|\, v\, B \sin\theta$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge.md - [Force on a Current-Carrying Wire](https://formulabro.yunusemrevurgun.com/electricity/force-on-current-carrying-wire/): A wire carrying current is pushed sideways by a magnetic field, and the push grows with the current, the wire length and the field strength. Formula: $F = B\, I\, L \sin\theta$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/force-on-current-carrying-wire.md - [Magnetic Field of a Straight Wire](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire/): A current in a straight wire makes a magnetic field that wraps around the wire, and the field gets weaker the farther away you measure it. Formula: $B = \frac{\mu_0 I}{2\pi r}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire.md - [Magnetic Field of a Solenoid](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid/): A long coil of wire makes a strong, nearly uniform magnetic field along its middle, and the field depends on how many turns are packed into each meter. Formula: $B = \mu_0\, n\, I$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid.md - [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/): A changing magnetic field through a loop of wire pushes a voltage into the wire, and that is how generators make electricity. Formula: $\varepsilon = -N\, \frac{d\Phi_B}{dt}$. Markdown: https://formulabro.yunusemrevurgun.com/electricity/faradays-law.md ## Quantum Mechanics Hub: [Quantum Mechanics formulas](https://formulabro.yunusemrevurgun.com/quantum-mechanics/). Quantum formulas for beginners: photons, matter waves, uncertainty, atoms, spin, tunneling, qubits and quantum statistics, each with a worked example. - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/): E = hf says each packet of light carries energy in proportion to its frequency: higher frequency means more energy per packet, and brightness does not change it. Formula: $E = h f$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation.md - [Photoelectric Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/): Light can knock electrons out of a metal, but only if each packet of light carries enough energy, and the leftover energy becomes the electron's speed. Formula: $K_{\max} = h f - \phi$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect.md - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/): Every moving object has a wavelength, and the heavier or faster it moves, the shorter that wavelength gets. Formula: $\lambda = \frac{h}{p} = \frac{h}{m v}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength.md - [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/): The more tightly a particle's position is pinned down, the more its speed must spread out, and no instrument can beat that trade-off. Formula: $\Delta x \, \Delta p \ge \frac{\hbar}{2}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle.md - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/): The Born rule says the chance of finding a particle at a spot, or of getting an outcome, is the squared size of its wave at that spot. Formula: $P(x) = |\psi(x)|^2$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule.md - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/): The Schrödinger equation says how a quantum particle's wave changes over time, the way Newton's laws say how a moving ball changes its position. Formula: $i \hbar \frac{\partial \psi}{\partial t} = \hat{H} \psi$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation.md - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/): A hydrogen electron can only sit on certain energy steps, and every jump between steps gives off or takes in light of one exact color. Formula: $E_n = -\frac{13.6\ \text{eV}}{n^2}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels.md - [Photon Momentum](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum/): A photon has no mass, yet it carries momentum, so light can push on objects, and the shorter its wavelength, the harder each photon pushes. Formula: $p = \frac{h}{\lambda} = \frac{E}{c}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum.md - [Compton Scattering](https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering/): When an X-ray bounces off an electron it loses some energy, so its wavelength gets longer, and the amount depends only on the angle it bounces through. Formula: $\lambda' - \lambda = \frac{h}{m_e c}\left(1 - \cos\theta\right)$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering.md - [Planck's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law/): Planck's law says how bright a hot object glows at each wavelength, and the mix of colors depends on its temperature. Formula: $B_\lambda(\lambda, T) = \frac{2 h c^2}{\lambda^5} \cdot \frac{1}{e^{h c / (\lambda k_B T)} - 1}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law.md - [Wien's Displacement Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wiens-displacement-law/): Wien's law says a hotter object is brightest at a shorter wavelength, and the peak wavelength is a fixed constant divided by the temperature. Formula: $\lambda_{\max} = \frac{b}{T}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/wiens-displacement-law.md - [Stefan-Boltzmann Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law/): The Stefan-Boltzmann law says a hot surface gives off radiated power that grows with the fourth power of its absolute temperature. Formula: $P = \varepsilon \sigma A T^4$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law.md - [Rydberg Formula](https://formulabro.yunusemrevurgun.com/quantum-mechanics/rydberg-formula/): The Rydberg formula predicts the exact color of light a hydrogen atom gives off when its electron drops from one energy level to a lower one. Formula: $\frac{1}{\lambda} = R_H\left(\frac{1}{n_1^2} - \frac{1}{n_2^2}\right)$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/rydberg-formula.md - [Bohr Radius](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius/): The Bohr radius is the natural size of a hydrogen atom, about 0.0529 nanometers, built from fixed physical constants. Formula: $a_0 = \frac{4\pi \varepsilon_0 \hbar^2}{m_e e^2}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius.md - [Hydrogen-Like Atom Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy/): An atom or ion with only one electron has energy levels that follow the hydrogen pattern, scaled up by the square of its nuclear charge. Formula: $E_n = -\frac{Z^2}{n^2} \times 13.605693\ \text{eV}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy.md - [Electron Shell Capacity](https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity/): The shell with number n can hold at most twice n squared electrons, because it has n squared places and each place takes two electrons. Formula: $N_{\max} = 2 n^2$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity.md - [Particle in a Box](https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box/): A particle trapped between two walls can only have certain energies, and this formula gives them: the narrower the box, the higher the energies. Formula: $E_n = \frac{n^2 h^2}{8 m L^2}, \qquad n = 1, 2, 3, \dots$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box.md - [Quantum Harmonic Oscillator](https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-harmonic-oscillator/): A quantum particle on a spring can only have energies in equal steps, and even its lowest step sits above zero. Formula: $E_n = \hbar \omega \left(n + \frac{1}{2}\right), \qquad n = 0, 1, 2, \dots$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-harmonic-oscillator.md - [Quantum Tunneling Probability](https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-tunneling-probability/): A quantum particle can sometimes pass through a barrier that is too high for it to climb over, and this formula estimates how often. Formula: $T \approx e^{-2\kappa L}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-tunneling-probability.md - [Wave Function Normalization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization/): Normalizing a wave function means scaling it so the chances of finding the particle, added over every place, total exactly one. Formula: $\int_{-\infty}^{\infty} |\psi(x)|^2\, dx = 1$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization.md - [Expectation Value](https://formulabro.yunusemrevurgun.com/quantum-mechanics/expectation-value/): The expectation value is the average result you would get if you repeated a measurement many times on identical particles. Formula: $\langle x \rangle = \int_{-\infty}^{\infty} x\, |\psi(x)|^2\, dx$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/expectation-value.md - [Qubit State](https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state/): A qubit is a quantum bit that can hold a mix of 0 and 1, described by two amplitudes whose squared sizes give the chances of each result. Formula: $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle, \qquad |\alpha|^2 + |\beta|^2 = 1$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state.md - [Bloch Sphere](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere/): The Bloch sphere is a ball whose points are all the possible single-qubit states, with the top and bottom poles as 0 and 1. Formula: $|\psi\rangle = \cos\frac{\theta}{2}|0\rangle + e^{i\varphi}\sin\frac{\theta}{2}|1\rangle, \qquad P(0) = \cos^2\frac{\theta}{2}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere.md - [Stationary State Time Evolution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stationary-state-time-evolution/): A stationary state has one fixed energy, and its chances of finding the particle stay the same even though its phase keeps turning. Formula: $\Psi(x, t) = \psi(x)\, e^{-i E t/\hbar}, \qquad |\Psi(x, t)|^2 = |\psi(x)|^2$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/stationary-state-time-evolution.md - [Energy-Time Uncertainty Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/energy-time-uncertainty/): A state that lasts only a short time cannot have one sharp energy, so the light it gives off has a blurred color. Formula: $\Delta E \, \Delta t \gtrsim \frac{\hbar}{2}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/energy-time-uncertainty.md - [Canonical Commutation Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/canonical-commutation-relation/): In quantum mechanics the order of measuring position and momentum changes the result, and that mismatch is the root of the uncertainty trade-off. Formula: $[\hat{x}, \hat{p}] = \hat{x}\hat{p} - \hat{p}\hat{x} = i\hbar$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/canonical-commutation-relation.md - [Orbital Angular Momentum Quantization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/angular-momentum-quantization/): An electron's orbital motion around a nucleus can only take certain fixed sizes and directions, like steps on a staircase. Formula: $|\mathbf{L}| = \sqrt{\ell(\ell + 1)}\,\hbar \qquad L_z = m_\ell\,\hbar \qquad m_\ell = -\ell, \ldots, \ell$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/angular-momentum-quantization.md - [Spin One-Half](https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/): An electron has a built-in angular momentum that can be measured along any direction as only one of two values, up or down. Formula: $S_z = m_s\,\hbar, \qquad m_s = \pm\frac{1}{2}, \qquad |\mathbf{S}| = \frac{\sqrt{3}}{2}\,\hbar$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half.md - [Zeeman Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect/): A magnetic field shifts an atom's energy levels by small equal steps, so one spectral line splits into several. Formula: $\Delta E = m_\ell\,\mu_B\,B$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect.md - [Fine-Structure Constant](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fine-structure-constant/): The fine-structure constant is a pure number that sets how strongly charged particles and light interact, and its value is close to 1 over 137. Formula: $\alpha = \frac{e^2}{4\pi\varepsilon_0\,\hbar c} \approx \frac{1}{137.036}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fine-structure-constant.md - [Double-Slit Interference](https://formulabro.yunusemrevurgun.com/quantum-mechanics/double-slit-interference/): Waves from two narrow openings overlap, and at certain places they add into bright bands while at others they cancel into dark ones. Formula: $d \sin\theta = m\lambda$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/double-slit-interference.md - [Bragg's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bragg-law/): Waves bounce off the evenly spaced layers of a crystal, and they add into a strong reflection only at certain angles. Formula: $n\lambda = 2d\sin\theta$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bragg-law.md - [Thermal de Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/thermal-de-broglie-wavelength/): When a gas gets cold enough, each atom's wave grows so long that neighboring atoms overlap, and quantum rules take over. Formula: $\lambda_{\text{th}} = \frac{h}{\sqrt{2\pi m k_B T}}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/thermal-de-broglie-wavelength.md - [Energy-Momentum Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/relativistic-energy-momentum/): Energy, momentum and mass are linked by one equation, and a particle with no mass always carries energy only through its momentum. Formula: $E^2 = (p c)^2 + (m c^2)^2$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/relativistic-energy-momentum.md - [Pair Production Threshold](https://formulabro.yunusemrevurgun.com/quantum-mechanics/pair-production-threshold/): A gamma ray with at least twice the rest energy of an electron can turn into an electron and its antiparticle, a positron. Formula: $E_\gamma \ge 2 m_e c^2 \approx 1.022 \text{ MeV}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/pair-production-threshold.md - [Radioactive Decay Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/radioactive-decay-law/): An unstable sample loses a fixed fraction of its atoms in each time interval, so the count falls off in an exponential curve. Formula: $N(t) = N_0\, e^{-\lambda t}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/radioactive-decay-law.md - [Fermi-Dirac Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution/): For electrons and other fermions, it gives the chance that an energy level is filled, from 1 for full down to 0 for empty. Formula: $f(E) = \frac{1}{e^{(E - \mu)/(k_B T)} + 1}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution.md - [Bose-Einstein Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution/): For bosons such as photons, it gives the average number of particles that share a single energy level. Formula: $n(E) = \frac{1}{e^{(E - \mu)/(k_B T)} - 1}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution.md - [Fermi Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy/): In a metal, electrons fill energy levels from the bottom up, and the Fermi energy is the height of the last level filled. Formula: $E_F = \frac{\hbar^2}{2 m}\left(3\pi^2 n\right)^{2/3}$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy.md - [CHSH Inequality](https://formulabro.yunusemrevurgun.com/quantum-mechanics/chsh-inequality/): A Bell test combines four measurements into one number, and any theory with pre-set local answers must keep its size at 2 or below. Formula: $S = E(a,b) - E(a,b') + E(a',b) + E(a',b')$. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/chsh-inequality.md ## Optional - [About Formula Bro](https://formulabro.yunusemrevurgun.com/about/): What Formula Bro is, who made it, how every formula page is written and checked, and how to report a mistake. - [Notes for AI Agents](https://formulabro.yunusemrevurgun.com/for-ai-agents/): How AI assistants, crawlers and agents can read Formula Bro: Markdown copies, llms.txt, a JSON file of every formula, URL patterns and citation rules. --- # AI & Machine Learning Formulas Machine learning looks like magic from the outside. Inside it is a list of formulas used over and over: a weighted sum, a squashing function, a way to measure how wrong a guess was, a rule for getting a little less wrong each time, and a few scores that say how good a model is. Read them in this order and the whole field gets a lot smaller. Page: https://formulabro.yunusemrevurgun.com/ai-ml/ Updated: 2026-10-22 ## [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) $$ z = \sum_{i=1}^{n} w_i x_i + b, \quad a = f(z) $$ An artificial neuron multiplies each input by a weight, adds them up with a bias, and then decides how strongly to fire. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron.md ## [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) $$ \sigma(z) = \frac{1}{1 + e^{-z}} $$ The sigmoid takes any number, however big or small, and squeezes it into a value between 0 and 1 that can be read as a chance. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function.md ## [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) $$ \operatorname{softmax}(z)_i = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}} $$ Softmax takes a list of scores, any numbers at all, and turns them into percentages that add up to 100%. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/softmax.md ## [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) $$ \mathrm{MSE} = \frac{1}{n}\sum_{i=1}^{n} (y_i - \hat{y}_i)^2 $$ Mean squared error measures how wrong a model's guesses are by squaring each miss, so big misses count much more, and then averaging them. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error.md ## [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) $$ L = -\sum_{i=1}^{K} y_i \ln(\hat{y}_i) $$ Cross-entropy loss gives a small score when the model was confident in the right answer and a big score when it was not. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss.md ## [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) $$ \theta_{\text{new}} = \theta_{\text{old}} - \eta \, \nabla L(\theta_{\text{old}}) $$ Gradient descent nudges a model's settings a small step in the direction that lowers the error, then repeats until the error stops falling. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent.md ## [Bayes' Theorem](https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem/) $$ P(A \mid B) = \frac{P(B \mid A)\, P(A)}{P(B)} $$ Bayes' theorem tells you how much to change your belief in something after you see new evidence. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem.md ## [Scaled Dot-Product Attention](https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention/) $$ \operatorname{Attention}(Q, K, V) = \operatorname{softmax}\left(\frac{Q K^{\top}}{\sqrt{d_k}}\right) V $$ Attention lets a model look at every item in a list and decide how much each one matters for the item it is working on. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention.md ## [Linear Regression](https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression/) $$ \hat{y} = w x + b $$ Linear regression predicts a number by drawing the straight line that sits closest to the data points, so you can read off a guess for any new input. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression.md ## [Logistic Regression](https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression/) $$ p = \sigma(w x + b) = \frac{1}{1 + e^{-(w x + b)}} $$ Logistic regression takes the same weighted sum as a straight line, then squeezes it through an S-shaped curve so the result is a probability between 0 and 1. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression.md ## [ReLU Activation](https://formulabro.yunusemrevurgun.com/ai-ml/relu-activation/) $$ \text{ReLU}(z) = \max(0, z) $$ ReLU passes positive numbers through unchanged and replaces every negative number with zero, like a switch that is on for positive input and off otherwise. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/relu-activation.md ## [Tanh Activation](https://formulabro.yunusemrevurgun.com/ai-ml/tanh-activation/) $$ \tanh(z) = \frac{e^{z} - e^{-z}}{e^{z} + e^{-z}} $$ Tanh squashes any input into a number between minus 1 and plus 1, with zero at the center, so a negative input gives a negative output. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/tanh-activation.md ## [Mean Absolute Error (MAE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-absolute-error/) $$ \mathrm{MAE} = \frac{1}{n}\sum_{i=1}^{n} |y_i - \hat{y}_i| $$ Mean absolute error measures how far off a model's guesses are on average, counting each miss by its size only, so one wild miss does not dominate the score. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/mean-absolute-error.md ## [Huber Loss](https://formulabro.yunusemrevurgun.com/ai-ml/huber-loss/) $$ L_{\delta}(a) = \begin{cases} \frac{1}{2} a^{2} & \text{if } |a| \le \delta \\ \delta \left(|a| - \frac{1}{2}\delta\right) & \text{otherwise} \end{cases} $$ Huber loss scores small misses by squaring them, as mean squared error does, and large misses with a straight-line penalty, so outliers cannot take over the score. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/huber-loss.md ## [Hinge Loss](https://formulabro.yunusemrevurgun.com/ai-ml/hinge-loss/) $$ L = \max(0,\ 1 - y\, f(x)) $$ Hinge loss gives no penalty to an answer that is correct with room to spare, and a growing penalty as an answer gets wrong or too close to the boundary. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/hinge-loss.md ## [L2 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization/) $$ J(w) = L(w) + \lambda \sum_{j} w_j^{2} $$ L2 regularization adds a penalty for large weights, so the model prefers small, gentle weights that tend to generalize better to new data. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization.md ## [L1 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l1-regularization/) $$ J(w) = L(w) + \lambda \sum_{j} |w_j| $$ L1 regularization adds a penalty proportional to each weight's size, which encourages the model to drop unneeded inputs by setting their weights to exactly zero. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/l1-regularization.md ## [Momentum Optimizer](https://formulabro.yunusemrevurgun.com/ai-ml/momentum-optimizer/) $$ v_t = \beta \, v_{t-1} + \nabla L(\theta_{t-1}) \qquad \theta_t = \theta_{t-1} - \eta \, v_t $$ Momentum lets gradient descent remember its recent steps, so it speeds up where the slope keeps pointing the same way and wobbles less where it flips. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/momentum-optimizer.md ## [Adam Optimizer](https://formulabro.yunusemrevurgun.com/ai-ml/adam-optimizer/) $$ \theta_t = \theta_{t-1} - \eta \, \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon} $$ Adam keeps a running average of each setting's slope and of how big those slopes have been, then uses both to choose a step size for every setting. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/adam-optimizer.md ## [Backpropagation and the Chain Rule](https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule/) $$ \frac{\partial L}{\partial w} = \frac{\partial L}{\partial \hat y} \, \frac{\partial \hat y}{\partial z} \, \frac{\partial z}{\partial w} $$ Backpropagation finds how much each weight affects the error by multiplying the small slopes along the chain from the weight to the loss. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule.md ## [Batch Normalization](https://formulabro.yunusemrevurgun.com/ai-ml/batch-normalization/) $$ \hat x_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}} \qquad y_i = \gamma \, \hat x_i + \beta $$ Batch normalization rescales the values in a group of examples so they are centered near zero with a steady spread, then lets the network choose its own scale and offset. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/batch-normalization.md ## [Layer Normalization](https://formulabro.yunusemrevurgun.com/ai-ml/layer-normalization/) $$ \hat x_i = \frac{x_i - \mu}{\sqrt{\sigma^2 + \epsilon}} \qquad y_i = \gamma_i \, \hat x_i + \beta_i $$ Layer normalization centers and scales the numbers that describe one example, so its values stay in a steady range no matter what other examples are in the batch. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/layer-normalization.md ## [Dropout](https://formulabro.yunusemrevurgun.com/ai-ml/dropout/) $$ \tilde h_i = \frac{m_i \, h_i}{1 - p} \qquad m_i \sim \text{Bernoulli}(1 - p) $$ Dropout randomly switches off some neurons on each training pass, and scales up the ones that stay on, so the network learns patterns that do not rely on any single neuron. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/dropout.md ## [Precision and Recall](https://formulabro.yunusemrevurgun.com/ai-ml/precision-and-recall/) $$ \text{Precision} = \frac{TP}{TP + FP} \qquad \text{Recall} = \frac{TP}{TP + FN} $$ Precision asks how many of the items a model flagged were right, and recall asks how many of the real cases it managed to find. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/precision-and-recall.md ## [F1 Score](https://formulabro.yunusemrevurgun.com/ai-ml/f1-score/) $$ F_1 = \frac{2 \cdot P \cdot R}{P + R} $$ The F1 score is one number from 0 to 1 that stays low unless both precision and recall are reasonably high. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/f1-score.md ## [Classification Accuracy](https://formulabro.yunusemrevurgun.com/ai-ml/classification-accuracy/) $$ \text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN} $$ Accuracy is the share of a model's guesses that were right, out of all the guesses it made. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/classification-accuracy.md ## [Cosine Similarity](https://formulabro.yunusemrevurgun.com/ai-ml/cosine-similarity/) $$ \cos\theta = \frac{\mathbf{A}\cdot\mathbf{B}}{\|\mathbf{A}\|\,\|\mathbf{B}\|} $$ Cosine similarity scores how closely two lists of numbers point the same way, from -1 for opposite directions to 1 for the same direction. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/cosine-similarity.md ## [Euclidean Distance](https://formulabro.yunusemrevurgun.com/ai-ml/euclidean-distance/) $$ d(\mathbf{p}, \mathbf{q}) = \sqrt{\sum_{i=1}^{n} (p_i - q_i)^2} $$ Euclidean distance is the straight-line distance between two points, found by squaring the gaps, adding them up and taking the square root. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/euclidean-distance.md ## [k-Means Clustering](https://formulabro.yunusemrevurgun.com/ai-ml/k-means-clustering/) $$ J = \sum_{k=1}^{K} \sum_{\mathbf{x} \in C_k} \|\mathbf{x} - \boldsymbol{\mu}_k\|^2 $$ k-means clustering sorts points into K groups by moving each group's center to its middle and reassigning every point to its nearest center. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/k-means-clustering.md ## [Kullback-Leibler Divergence](https://formulabro.yunusemrevurgun.com/ai-ml/kl-divergence/) $$ D_{\mathrm{KL}}(P \,\|\, Q) = \sum_x P(x) \log \frac{P(x)}{Q(x)} $$ KL divergence measures how badly a set of guessed probabilities fits the real probabilities. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/kl-divergence.md ## [Naive Bayes Classifier](https://formulabro.yunusemrevurgun.com/ai-ml/naive-bayes-classifier/) $$ P(y \mid x_1, \dots, x_n) \propto P(y) \prod_{i=1}^{n} P(x_i \mid y) $$ Naive Bayes guesses the most likely class by multiplying how common the class is by how well each clue fits it. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/naive-bayes-classifier.md ## [Gini Impurity](https://formulabro.yunusemrevurgun.com/ai-ml/gini-impurity/) $$ G = 1 - \sum_{k=1}^{K} p_k^2 $$ Gini impurity is a score for how mixed the classes are in a group: 0 means every item in the group belongs to the same class. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/gini-impurity.md ## [Information Gain](https://formulabro.yunusemrevurgun.com/ai-ml/information-gain/) $$ \mathrm{IG} = H(\text{parent}) - \sum_{k} \frac{n_k}{n}\, H(\text{child}_k) $$ Information gain tells you how many bits of guessing a split removes, so a tree can ask the question that sorts the examples best. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/information-gain.md ## [Softmax Temperature](https://formulabro.yunusemrevurgun.com/ai-ml/softmax-temperature/) $$ p_i = \frac{e^{z_i / T}}{\sum_{j=1}^{K} e^{z_j / T}} $$ Temperature is a dial that makes a model's choices more focused when it is low and more varied when it is high. Markdown: https://formulabro.yunusemrevurgun.com/ai-ml/softmax-temperature.md ## [Perplexity](https://formulabro.yunusemrevurgun.com/ai-ml/perplexity/) $$ \text{PPL} = \exp\left(-\frac{1}{N}\sum_{i=1}^{N} \ln p(w_i \mid w_{ 0,\ n_0 \text{ such that } 0 \le f(n) \le c\, g(n) \text{ for all } n \ge n_0 $$ Big O notation says that one function never grows faster than a fixed multiple of another, once the inputs are large enough. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/big-o-notation.md ## [Master Theorem](https://formulabro.yunusemrevurgun.com/computer-science/master-theorem/) $$ T(n) = a\, T(n/b) + f(n) $$ The master theorem gives the running time of a divide-and-conquer algorithm by comparing the work at each split with the work at the bottom of the recursion. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/master-theorem.md ## [Sum of the First n Integers](https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers/) $$ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} $$ This formula adds the counting numbers from 1 to n in one step, so you never have to add them one at a time. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers.md ## [Geometric Series](https://formulabro.yunusemrevurgun.com/computer-science/geometric-series/) $$ \sum_{k=0}^{n-1} r^{k} = \frac{1 - r^{n}}{1 - r} \quad (r \neq 1) $$ A geometric series adds terms where each one is the last one times a fixed ratio, and this formula adds them all in one step. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/geometric-series.md ## [Permutations](https://formulabro.yunusemrevurgun.com/computer-science/permutations/) $$ P(n, k) = \frac{n!}{(n-k)!} $$ A permutation is an ordered arrangement, and this formula counts how many ways you can pick k items from n and line them up. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/permutations.md ## [Combinations](https://formulabro.yunusemrevurgun.com/computer-science/combinations/) $$ C(n,k) = \binom{n}{k} = \frac{n!}{k!\,(n-k)!} $$ A combination counts how many different groups you can pick from a set of items when the order of the picks does not matter. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/combinations.md ## [Pigeonhole Principle](https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle/) $$ \max_{j}\, b_j \ge \left\lceil \frac{n}{m} \right\rceil $$ If you put more things than boxes into the boxes, at least one box must hold two or more things. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle.md ## [Inclusion-Exclusion Principle](https://formulabro.yunusemrevurgun.com/computer-science/inclusion-exclusion-principle/) $$ |A \cup B| = |A| + |B| - |A \cap B| $$ Inclusion-exclusion counts how many items belong to at least one group by adding the groups and then removing the overlaps that were counted twice. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/inclusion-exclusion-principle.md ## [Hash Table Load Factor](https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor/) $$ \alpha = \frac{n}{m} $$ The load factor is how full a hash table is on average: the number of keys divided by the number of buckets. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor.md ## [Birthday Problem](https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem/) $$ P(\text{no collision}) = \prod_{k=0}^{n-1}\left(1 - \frac{k}{N}\right) \approx e^{-n(n-1)/(2N)} $$ The birthday problem asks how likely it is that some pair of items in a random group matches, and the answer rises faster than most people expect. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem.md ## [Bloom Filter False Positive Rate](https://formulabro.yunusemrevurgun.com/computer-science/bloom-filter-false-positive-rate/) $$ p \approx \left(1 - e^{-kn/m}\right)^{k} $$ The false positive rate of a Bloom filter is the chance that it wrongly says an item is present, and it depends on the bits, the items and the hash functions. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/bloom-filter-false-positive-rate.md ## [Modulo Operation](https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation/) $$ a \bmod n = a - n \left\lfloor \frac{a}{n} \right\rfloor $$ The modulo operation gives the leftover amount after you divide one whole number by another as many full times as you can. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation.md ## [Euclidean Algorithm](https://formulabro.yunusemrevurgun.com/computer-science/euclidean-algorithm-gcd/) $$ \gcd(a, b) = \gcd(b,\ a \bmod b), \qquad \gcd(a, 0) = a $$ The Euclidean algorithm finds the largest number that divides two numbers evenly, by replacing the pair with a smaller pair again and again. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/euclidean-algorithm-gcd.md ## [RSA Encryption](https://formulabro.yunusemrevurgun.com/computer-science/rsa-encryption/) $$ c = m^{e} \bmod n, \qquad m = c^{d} \bmod n $$ RSA lets anyone lock a message with a public key while only the owner can unlock it with a private key, because undoing a product of two secret primes is very hard. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/rsa-encryption.md ## [Hamming Distance](https://formulabro.yunusemrevurgun.com/computer-science/hamming-distance/) $$ d(x, y) = \sum_{i=1}^{n} [x_i \ne y_i] $$ Hamming distance counts how many positions two equal-length codes differ in, and that count tells you how many errors a code can catch. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/hamming-distance.md ## [Password Entropy](https://formulabro.yunusemrevurgun.com/computer-science/password-entropy/) $$ H = L \log_2 N $$ Password entropy is a number of bits that measures how many possible passwords a random generator could have produced, and so how hard guessing one is. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/password-entropy.md ## [Data Transfer Time](https://formulabro.yunusemrevurgun.com/computer-science/data-transfer-time/) $$ t = \frac{S}{B} $$ Data transfer time tells you how long a file takes to send: divide its size by the link's speed, using units that match. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/data-transfer-time.md ## [Bandwidth-Delay Product](https://formulabro.yunusemrevurgun.com/computer-science/bandwidth-delay-product/) $$ \text{BDP} = B \times \text{RTT} $$ The bandwidth-delay product tells you how much data must be in transit at once to keep a network link full. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/bandwidth-delay-product.md ## [Nyquist Sampling Theorem](https://formulabro.yunusemrevurgun.com/computer-science/nyquist-sampling-theorem/) $$ f_s > 2 f_{\max} $$ The Nyquist sampling theorem tells you how fast you must sample a signal, at more than twice its highest frequency, to capture it without distortion. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/nyquist-sampling-theorem.md ## [Shannon-Hartley Theorem](https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem/) $$ C = B \log_2\left(1 + \frac{S}{N}\right) $$ The Shannon-Hartley theorem gives the highest error-free bit rate a noisy channel can carry, from its bandwidth and how strong the signal is compared with the noise. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem.md ## [Average Memory Access Time](https://formulabro.yunusemrevurgun.com/computer-science/average-memory-access-time/) $$ \text{AMAT} = t_{\text{hit}} + r_{\text{miss}} \times t_{\text{penalty}} $$ Average memory access time, or AMAT, is the average time one memory read takes, given how often the cache finds the data and how costly a miss is. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/average-memory-access-time.md ## [CPU Time Equation](https://formulabro.yunusemrevurgun.com/computer-science/cpu-time-equation/) $$ T_{\text{CPU}} = IC \times CPI \times t_{\text{clock}} = \frac{IC \times CPI}{f} $$ The CPU time equation tells you how long a program takes on a processor, from how many instructions it runs, how many cycles each one needs and how fast the clock ticks. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/cpu-time-equation.md ## [Gustafson's Law](https://formulabro.yunusemrevurgun.com/computer-science/gustafsons-law/) $$ S = N - s\,(N - 1) $$ Gustafson's law estimates how much more work a parallel computer finishes in the same time when the job grows with the number of processors. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/gustafsons-law.md ## [System Availability](https://formulabro.yunusemrevurgun.com/computer-science/system-availability/) $$ A = \frac{\text{MTBF}}{\text{MTBF} + \text{MTTR}} $$ System availability tells you the fraction of time a system is working, based on how often it breaks and how long the repair takes. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/system-availability.md ## [M/M/1 Queue](https://formulabro.yunusemrevurgun.com/computer-science/mm1-queue/) $$ W = \frac{1}{\mu - \lambda} $$ The M/M/1 formula tells you how long, on average, an item spends in a line with one server, based on how fast items arrive and how fast the server works. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/mm1-queue.md ## [Perfect Binary Tree Nodes](https://formulabro.yunusemrevurgun.com/computer-science/perfect-binary-tree-nodes/) $$ N = 2^{h+1} - 1 $$ The formula counts the nodes in a perfect binary tree from its height, by doubling the number of nodes on each level. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/perfect-binary-tree-nodes.md ## [Complete Graph Edges](https://formulabro.yunusemrevurgun.com/computer-science/complete-graph-edges/) $$ E = \frac{n(n-1)}{2} $$ A complete graph joins every pair of points with one line, and this formula counts how many lines that takes. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/complete-graph-edges.md ## [Euler's Formula for Planar Graphs](https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs/) $$ V - E + F = 2 $$ Euler's formula says that if you draw a connected network on a flat sheet with no crossing lines, counting corners, lines and regions always gives 2. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs.md ## [PageRank](https://formulabro.yunusemrevurgun.com/computer-science/pagerank/) $$ PR(p) = \frac{1 - d}{N} + d \sum_{q \to p} \frac{PR(q)}{L(q)} $$ PageRank gives each web page a score based on how many good pages link to it, so each link acts like a vote with a weight. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/pagerank.md ## [TF-IDF](https://formulabro.yunusemrevurgun.com/computer-science/tf-idf/) $$ \text{tfidf}(t, d) = \text{tf}(t, d) \times \ln\frac{N}{\text{df}(t)} $$ TF-IDF gives a word a high score in a document when the word appears often there but rarely in the other documents. Markdown: https://formulabro.yunusemrevurgun.com/computer-science/tf-idf.md --- # Electricity Formulas Every circuit, from a flashlight to a power grid, follows a short list of rules about voltage, current and resistance, and a few more about capacitors, coils and magnets. Learn these and you can read a power bill, size a resistor for an LED, see why a capacitor takes time to charge and why a transformer only works on AC. Page: https://formulabro.yunusemrevurgun.com/electricity/ Updated: 2026-10-22 ## [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) $$ V = I R $$ Ohm's law says the push on a wire, the voltage, equals the flow through it, the current, times how hard that flow is to get through, the resistance. Markdown: https://formulabro.yunusemrevurgun.com/electricity/ohms-law.md ## [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) $$ P = V I $$ Electric power tells you how fast a device uses energy, and you get it by multiplying the volts by the amps to get watts. Markdown: https://formulabro.yunusemrevurgun.com/electricity/electric-power.md ## [Energy and Kilowatt-Hours](https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours/) $$ E = P \, t $$ Energy is power multiplied by time, so a heater that uses 2 kilowatts for 3 hours uses 6 kilowatt-hours of energy. Markdown: https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours.md ## [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) $$ R_{\text{series}} = R_1 + R_2 + \cdots + R_n \qquad \frac{1}{R_{\text{parallel}}} = \frac{1}{R_1} + \frac{1}{R_2} + \cdots + \frac{1}{R_n} $$ Resistors in a line add up, and resistors side by side always give a total smaller than the smallest one. Markdown: https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel.md ## [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) $$ \sum I_{\text{in}} = \sum I_{\text{out}} $$ Kirchhoff's current law says that whatever electricity flows into a junction has to flow out again, because nothing piles up there. Markdown: https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law.md ## [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/) $$ \tau = R C $$ The RC time constant tells you how long a capacitor takes to fill up through a resistor: multiply the resistance by the capacitance. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant.md ## [Coulomb's Law](https://formulabro.yunusemrevurgun.com/electricity/coulombs-law/) $$ F = k_e \frac{|q_1 q_2|}{r^2} $$ Coulomb's law tells you how hard two electric charges push or pull each other, and the force gets weaker fast as they move apart. Markdown: https://formulabro.yunusemrevurgun.com/electricity/coulombs-law.md ## [Charge and Current](https://formulabro.yunusemrevurgun.com/electricity/charge-and-current/) $$ I = \frac{Q}{t} $$ Electric current is how much charge passes a point each second, so the same charge moving faster means more current. Markdown: https://formulabro.yunusemrevurgun.com/electricity/charge-and-current.md ## [Kirchhoff's Voltage Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-voltage-law/) $$ \sum_{k} V_k = 0 $$ Kirchhoff's voltage law says that if you walk all the way around a circuit loop, the voltage gained equals the voltage lost. Markdown: https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-voltage-law.md ## [Voltage Divider](https://formulabro.yunusemrevurgun.com/electricity/voltage-divider/) $$ V_{\text{out}} = V_{\text{in}} \frac{R_2}{R_1 + R_2} $$ A voltage divider uses two resistors in series to take a smaller share of a supply voltage, with the share set by their ratio. Markdown: https://formulabro.yunusemrevurgun.com/electricity/voltage-divider.md ## [Current Divider](https://formulabro.yunusemrevurgun.com/electricity/current-divider/) $$ I_1 = I_{\text{total}} \frac{R_2}{R_1 + R_2} $$ A current divider splits a total current between two parallel resistors, and the smaller resistor always takes the bigger share. Markdown: https://formulabro.yunusemrevurgun.com/electricity/current-divider.md ## [Resistivity](https://formulabro.yunusemrevurgun.com/electricity/resistivity/) $$ R = \rho \frac{L}{A} $$ A wire's resistance grows with its length, shrinks with its thickness, and depends on what the wire is made of. Markdown: https://formulabro.yunusemrevurgun.com/electricity/resistivity.md ## [Temperature Coefficient of Resistance](https://formulabro.yunusemrevurgun.com/electricity/temperature-coefficient-of-resistance/) $$ R = R_0\left[1 + \alpha (T - T_0)\right] $$ Most metals get harder to push current through as they get hotter, and this formula estimates how much the resistance rises. Markdown: https://formulabro.yunusemrevurgun.com/electricity/temperature-coefficient-of-resistance.md ## [Drift Velocity](https://formulabro.yunusemrevurgun.com/electricity/drift-velocity/) $$ v_d = \frac{I}{n q A} $$ Electrons in a copper wire drift along at a fraction of a millimetre per second, even though the electric signal races along the wire. Markdown: https://formulabro.yunusemrevurgun.com/electricity/drift-velocity.md ## [Internal Resistance](https://formulabro.yunusemrevurgun.com/electricity/internal-resistance/) $$ V = \varepsilon - I r $$ A real battery has a small resistance inside it, so its output voltage drops when it pushes a current through a load. Markdown: https://formulabro.yunusemrevurgun.com/electricity/internal-resistance.md ## [Maximum Power Transfer](https://formulabro.yunusemrevurgun.com/electricity/maximum-power-transfer/) $$ R_L = R_S \qquad P_{\max} = \frac{V_S^2}{4 R_S} $$ A load receives the most power when its resistance matches the source's resistance, but then half the power is lost inside the source. Markdown: https://formulabro.yunusemrevurgun.com/electricity/maximum-power-transfer.md ## [Wheatstone Bridge](https://formulabro.yunusemrevurgun.com/electricity/wheatstone-bridge/) $$ \frac{R_1}{R_2} = \frac{R_3}{R_x} $$ A Wheatstone bridge finds an unknown resistance by adjusting a known one until the meter between two midpoints reads zero, then doing one multiply and one divide. Markdown: https://formulabro.yunusemrevurgun.com/electricity/wheatstone-bridge.md ## [Battery Capacity and Runtime](https://formulabro.yunusemrevurgun.com/electricity/battery-capacity-runtime/) $$ t = \frac{C}{I} $$ Divide a battery's capacity by the current the device draws, and you get roughly how many hours the battery will run it. Markdown: https://formulabro.yunusemrevurgun.com/electricity/battery-capacity-runtime.md ## [Capacitance](https://formulabro.yunusemrevurgun.com/electricity/capacitance/) $$ Q = C V $$ Capacitance tells you how much electric charge a capacitor stores for each volt across it. Markdown: https://formulabro.yunusemrevurgun.com/electricity/capacitance.md ## [Parallel-Plate Capacitor](https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor/) $$ C = \frac{\varepsilon_0 \varepsilon_r A}{d} $$ The parallel-plate formula says a capacitor holds more charge per volt when its plates are bigger, closer together, or separated by a material with a higher permittivity. Markdown: https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor.md ## [Capacitors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/capacitors-in-series-and-parallel/) $$ C_{\text{par}} = C_1 + C_2 + \cdots \qquad \frac{1}{C_{\text{ser}}} = \frac{1}{C_1} + \frac{1}{C_2} + \cdots $$ Capacitors side by side add their capacitance, while capacitors chained end to end give a smaller total that is found with reciprocals. Markdown: https://formulabro.yunusemrevurgun.com/electricity/capacitors-in-series-and-parallel.md ## [Energy Stored in a Capacitor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor/) $$ E = \frac{1}{2} C V^2 $$ A charged capacitor stores energy in the electric field between its plates, and the amount grows with the square of the voltage. Markdown: https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor.md ## [Inductor Voltage](https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage/) $$ V = L \frac{dI}{dt} $$ An inductor pushes back against changes in current, and the voltage across it is set by how fast the current is changing. Markdown: https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage.md ## [Energy Stored in an Inductor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor/) $$ E = \frac{1}{2} L I^2 $$ A coil with current flowing through it stores energy in its magnetic field, and the amount grows with the square of the current. Markdown: https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor.md ## [RL Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rl-time-constant/) $$ \tau = \frac{L}{R} $$ The RL time constant tells you how long current takes to build up in a coil connected through a resistor: divide the inductance by the resistance. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rl-time-constant.md ## [Capacitive Reactance](https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance/) $$ X_C = \frac{1}{2\pi f C} $$ Capacitive reactance tells you how hard a capacitor pushes back against alternating current, and it gets smaller as the frequency goes up. Markdown: https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance.md ## [Inductive Reactance](https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance/) $$ X_L = 2\pi f L $$ Inductive reactance tells you how hard a coil pushes back against alternating current, and it gets bigger as the frequency goes up. Markdown: https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance.md ## [Series RLC Impedance](https://formulabro.yunusemrevurgun.com/electricity/rlc-impedance/) $$ Z = \sqrt{R^2 + (X_L - X_C)^2} $$ Impedance is the total opposition a series circuit of a resistor, a coil and a capacitor gives to alternating current. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rlc-impedance.md ## [Resonant Frequency](https://formulabro.yunusemrevurgun.com/electricity/resonant-frequency/) $$ f_0 = \frac{1}{2\pi\sqrt{LC}} $$ The resonant frequency is the one frequency where a coil and a capacitor trade energy back and forth most easily, and radios use it to tune in stations. Markdown: https://formulabro.yunusemrevurgun.com/electricity/resonant-frequency.md ## [RMS Voltage](https://formulabro.yunusemrevurgun.com/electricity/rms-voltage/) $$ V_{\text{rms}} = \frac{V_{\text{peak}}}{\sqrt{2}} $$ RMS voltage is the steady voltage that heats a resistor as much as an AC sine wave does, and you get it by dividing the peak voltage by the square root of 2. Markdown: https://formulabro.yunusemrevurgun.com/electricity/rms-voltage.md ## [AC Power Factor](https://formulabro.yunusemrevurgun.com/electricity/ac-power-factor/) $$ P = V_{\text{rms}} I_{\text{rms}} \cos\varphi $$ Power factor tells you what share of the current in an AC circuit does useful work, and it is the ratio of real power to apparent power. Markdown: https://formulabro.yunusemrevurgun.com/electricity/ac-power-factor.md ## [Three-Phase Power](https://formulabro.yunusemrevurgun.com/electricity/three-phase-power/) $$ P = \sqrt{3}\, V_L I_L \cos\varphi $$ Three-phase power tells you how much real power a balanced three-wire AC load uses, and you get it from the line voltage, the line current and the power factor. Markdown: https://formulabro.yunusemrevurgun.com/electricity/three-phase-power.md ## [Transformer Turns Ratio](https://formulabro.yunusemrevurgun.com/electricity/transformer-turns-ratio/) $$ \frac{V_s}{V_p} = \frac{N_s}{N_p} $$ A transformer changes an AC voltage up or down in the same ratio as the number of wire turns on its two coils. Markdown: https://formulabro.yunusemrevurgun.com/electricity/transformer-turns-ratio.md ## [Electric Field of a Point Charge](https://formulabro.yunusemrevurgun.com/electricity/electric-field-of-point-charge/) $$ E = \frac{k_e\, q}{r^2} $$ The electric field around a charge tells you the push that a small test charge would feel at each point in space. Markdown: https://formulabro.yunusemrevurgun.com/electricity/electric-field-of-point-charge.md ## [Electric Potential](https://formulabro.yunusemrevurgun.com/electricity/electric-potential/) $$ V = \frac{k_e\, q}{r} $$ Electric potential tells you how much energy each unit of charge would have at a spot in space, measured in volts. Markdown: https://formulabro.yunusemrevurgun.com/electricity/electric-potential.md ## [Magnetic Force on a Moving Charge](https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge/) $$ F = |q|\, v\, B \sin\theta $$ A magnetic field pushes a moving charge sideways, and the push is biggest when the charge moves straight across the field lines. Markdown: https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge.md ## [Force on a Current-Carrying Wire](https://formulabro.yunusemrevurgun.com/electricity/force-on-current-carrying-wire/) $$ F = B\, I\, L \sin\theta $$ A wire carrying current is pushed sideways by a magnetic field, and the push grows with the current, the wire length and the field strength. Markdown: https://formulabro.yunusemrevurgun.com/electricity/force-on-current-carrying-wire.md ## [Magnetic Field of a Straight Wire](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire/) $$ B = \frac{\mu_0 I}{2\pi r} $$ A current in a straight wire makes a magnetic field that wraps around the wire, and the field gets weaker the farther away you measure it. Markdown: https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire.md ## [Magnetic Field of a Solenoid](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid/) $$ B = \mu_0\, n\, I $$ A long coil of wire makes a strong, nearly uniform magnetic field along its middle, and the field depends on how many turns are packed into each meter. Markdown: https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid.md ## [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/) $$ \varepsilon = -N\, \frac{d\Phi_B}{dt} $$ A changing magnetic field through a loop of wire pushes a voltage into the wire, and that is how generators make electricity. Markdown: https://formulabro.yunusemrevurgun.com/electricity/faradays-law.md --- # Quantum Mechanics Formulas Quantum mechanics describes things so small that light comes in lumps and particles behave like waves. The formulas are shorter than their reputation. Each page here says what the symbols mean, what the formula predicts and what it does not say. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/ Updated: 2026-10-22 ## [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) $$ E = h f $$ E = hf says each packet of light carries energy in proportion to its frequency: higher frequency means more energy per packet, and brightness does not change it. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation.md ## [Photoelectric Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/) $$ K_{\max} = h f - \phi $$ Light can knock electrons out of a metal, but only if each packet of light carries enough energy, and the leftover energy becomes the electron's speed. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect.md ## [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) $$ \lambda = \frac{h}{p} = \frac{h}{m v} $$ Every moving object has a wavelength, and the heavier or faster it moves, the shorter that wavelength gets. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength.md ## [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/) $$ \Delta x \, \Delta p \ge \frac{\hbar}{2} $$ The more tightly a particle's position is pinned down, the more its speed must spread out, and no instrument can beat that trade-off. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle.md ## [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) $$ P(x) = |\psi(x)|^2 $$ The Born rule says the chance of finding a particle at a spot, or of getting an outcome, is the squared size of its wave at that spot. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule.md ## [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) $$ i \hbar \frac{\partial \psi}{\partial t} = \hat{H} \psi $$ The Schrödinger equation says how a quantum particle's wave changes over time, the way Newton's laws say how a moving ball changes its position. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation.md ## [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) $$ E_n = -\frac{13.6\ \text{eV}}{n^2} $$ A hydrogen electron can only sit on certain energy steps, and every jump between steps gives off or takes in light of one exact color. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels.md ## [Photon Momentum](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum/) $$ p = \frac{h}{\lambda} = \frac{E}{c} $$ A photon has no mass, yet it carries momentum, so light can push on objects, and the shorter its wavelength, the harder each photon pushes. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum.md ## [Compton Scattering](https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering/) $$ \lambda' - \lambda = \frac{h}{m_e c}\left(1 - \cos\theta\right) $$ When an X-ray bounces off an electron it loses some energy, so its wavelength gets longer, and the amount depends only on the angle it bounces through. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering.md ## [Planck's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law/) $$ B_\lambda(\lambda, T) = \frac{2 h c^2}{\lambda^5} \cdot \frac{1}{e^{h c / (\lambda k_B T)} - 1} $$ Planck's law says how bright a hot object glows at each wavelength, and the mix of colors depends on its temperature. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law.md ## [Wien's Displacement Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wiens-displacement-law/) $$ \lambda_{\max} = \frac{b}{T} $$ Wien's law says a hotter object is brightest at a shorter wavelength, and the peak wavelength is a fixed constant divided by the temperature. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/wiens-displacement-law.md ## [Stefan-Boltzmann Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law/) $$ P = \varepsilon \sigma A T^4 $$ The Stefan-Boltzmann law says a hot surface gives off radiated power that grows with the fourth power of its absolute temperature. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law.md ## [Rydberg Formula](https://formulabro.yunusemrevurgun.com/quantum-mechanics/rydberg-formula/) $$ \frac{1}{\lambda} = R_H\left(\frac{1}{n_1^2} - \frac{1}{n_2^2}\right) $$ The Rydberg formula predicts the exact color of light a hydrogen atom gives off when its electron drops from one energy level to a lower one. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/rydberg-formula.md ## [Bohr Radius](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius/) $$ a_0 = \frac{4\pi \varepsilon_0 \hbar^2}{m_e e^2} $$ The Bohr radius is the natural size of a hydrogen atom, about 0.0529 nanometers, built from fixed physical constants. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius.md ## [Hydrogen-Like Atom Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy/) $$ E_n = -\frac{Z^2}{n^2} \times 13.605693\ \text{eV} $$ An atom or ion with only one electron has energy levels that follow the hydrogen pattern, scaled up by the square of its nuclear charge. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy.md ## [Electron Shell Capacity](https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity/) $$ N_{\max} = 2 n^2 $$ The shell with number n can hold at most twice n squared electrons, because it has n squared places and each place takes two electrons. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity.md ## [Particle in a Box](https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box/) $$ E_n = \frac{n^2 h^2}{8 m L^2}, \qquad n = 1, 2, 3, \dots $$ A particle trapped between two walls can only have certain energies, and this formula gives them: the narrower the box, the higher the energies. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box.md ## [Quantum Harmonic Oscillator](https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-harmonic-oscillator/) $$ E_n = \hbar \omega \left(n + \frac{1}{2}\right), \qquad n = 0, 1, 2, \dots $$ A quantum particle on a spring can only have energies in equal steps, and even its lowest step sits above zero. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-harmonic-oscillator.md ## [Quantum Tunneling Probability](https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-tunneling-probability/) $$ T \approx e^{-2\kappa L} $$ A quantum particle can sometimes pass through a barrier that is too high for it to climb over, and this formula estimates how often. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-tunneling-probability.md ## [Wave Function Normalization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization/) $$ \int_{-\infty}^{\infty} |\psi(x)|^2\, dx = 1 $$ Normalizing a wave function means scaling it so the chances of finding the particle, added over every place, total exactly one. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization.md ## [Expectation Value](https://formulabro.yunusemrevurgun.com/quantum-mechanics/expectation-value/) $$ \langle x \rangle = \int_{-\infty}^{\infty} x\, |\psi(x)|^2\, dx $$ The expectation value is the average result you would get if you repeated a measurement many times on identical particles. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/expectation-value.md ## [Qubit State](https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state/) $$ |\psi\rangle = \alpha|0\rangle + \beta|1\rangle, \qquad |\alpha|^2 + |\beta|^2 = 1 $$ A qubit is a quantum bit that can hold a mix of 0 and 1, described by two amplitudes whose squared sizes give the chances of each result. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state.md ## [Bloch Sphere](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere/) $$ |\psi\rangle = \cos\frac{\theta}{2}|0\rangle + e^{i\varphi}\sin\frac{\theta}{2}|1\rangle, \qquad P(0) = \cos^2\frac{\theta}{2} $$ The Bloch sphere is a ball whose points are all the possible single-qubit states, with the top and bottom poles as 0 and 1. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere.md ## [Stationary State Time Evolution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stationary-state-time-evolution/) $$ \Psi(x, t) = \psi(x)\, e^{-i E t/\hbar}, \qquad |\Psi(x, t)|^2 = |\psi(x)|^2 $$ A stationary state has one fixed energy, and its chances of finding the particle stay the same even though its phase keeps turning. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/stationary-state-time-evolution.md ## [Energy-Time Uncertainty Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/energy-time-uncertainty/) $$ \Delta E \, \Delta t \gtrsim \frac{\hbar}{2} $$ A state that lasts only a short time cannot have one sharp energy, so the light it gives off has a blurred color. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/energy-time-uncertainty.md ## [Canonical Commutation Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/canonical-commutation-relation/) $$ [\hat{x}, \hat{p}] = \hat{x}\hat{p} - \hat{p}\hat{x} = i\hbar $$ In quantum mechanics the order of measuring position and momentum changes the result, and that mismatch is the root of the uncertainty trade-off. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/canonical-commutation-relation.md ## [Orbital Angular Momentum Quantization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/angular-momentum-quantization/) $$ |\mathbf{L}| = \sqrt{\ell(\ell + 1)}\,\hbar \qquad L_z = m_\ell\,\hbar \qquad m_\ell = -\ell, \ldots, \ell $$ An electron's orbital motion around a nucleus can only take certain fixed sizes and directions, like steps on a staircase. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/angular-momentum-quantization.md ## [Spin One-Half](https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/) $$ S_z = m_s\,\hbar, \qquad m_s = \pm\frac{1}{2}, \qquad |\mathbf{S}| = \frac{\sqrt{3}}{2}\,\hbar $$ An electron has a built-in angular momentum that can be measured along any direction as only one of two values, up or down. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half.md ## [Zeeman Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect/) $$ \Delta E = m_\ell\,\mu_B\,B $$ A magnetic field shifts an atom's energy levels by small equal steps, so one spectral line splits into several. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect.md ## [Fine-Structure Constant](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fine-structure-constant/) $$ \alpha = \frac{e^2}{4\pi\varepsilon_0\,\hbar c} \approx \frac{1}{137.036} $$ The fine-structure constant is a pure number that sets how strongly charged particles and light interact, and its value is close to 1 over 137. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fine-structure-constant.md ## [Double-Slit Interference](https://formulabro.yunusemrevurgun.com/quantum-mechanics/double-slit-interference/) $$ d \sin\theta = m\lambda $$ Waves from two narrow openings overlap, and at certain places they add into bright bands while at others they cancel into dark ones. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/double-slit-interference.md ## [Bragg's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bragg-law/) $$ n\lambda = 2d\sin\theta $$ Waves bounce off the evenly spaced layers of a crystal, and they add into a strong reflection only at certain angles. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bragg-law.md ## [Thermal de Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/thermal-de-broglie-wavelength/) $$ \lambda_{\text{th}} = \frac{h}{\sqrt{2\pi m k_B T}} $$ When a gas gets cold enough, each atom's wave grows so long that neighboring atoms overlap, and quantum rules take over. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/thermal-de-broglie-wavelength.md ## [Energy-Momentum Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/relativistic-energy-momentum/) $$ E^2 = (p c)^2 + (m c^2)^2 $$ Energy, momentum and mass are linked by one equation, and a particle with no mass always carries energy only through its momentum. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/relativistic-energy-momentum.md ## [Pair Production Threshold](https://formulabro.yunusemrevurgun.com/quantum-mechanics/pair-production-threshold/) $$ E_\gamma \ge 2 m_e c^2 \approx 1.022 \text{ MeV} $$ A gamma ray with at least twice the rest energy of an electron can turn into an electron and its antiparticle, a positron. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/pair-production-threshold.md ## [Radioactive Decay Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/radioactive-decay-law/) $$ N(t) = N_0\, e^{-\lambda t} $$ An unstable sample loses a fixed fraction of its atoms in each time interval, so the count falls off in an exponential curve. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/radioactive-decay-law.md ## [Fermi-Dirac Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution/) $$ f(E) = \frac{1}{e^{(E - \mu)/(k_B T)} + 1} $$ For electrons and other fermions, it gives the chance that an energy level is filled, from 1 for full down to 0 for empty. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution.md ## [Bose-Einstein Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution/) $$ n(E) = \frac{1}{e^{(E - \mu)/(k_B T)} - 1} $$ For bosons such as photons, it gives the average number of particles that share a single energy level. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution.md ## [Fermi Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy/) $$ E_F = \frac{\hbar^2}{2 m}\left(3\pi^2 n\right)^{2/3} $$ In a metal, electrons fill energy levels from the bottom up, and the Fermi energy is the height of the last level filled. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy.md ## [CHSH Inequality](https://formulabro.yunusemrevurgun.com/quantum-mechanics/chsh-inequality/) $$ S = E(a,b) - E(a,b') + E(a',b) + E(a',b') $$ A Bell test combines four measurements into one number, and any theory with pre-set local answers must keep its size at 2 or below. Markdown: https://formulabro.yunusemrevurgun.com/quantum-mechanics/chsh-inequality.md --- # Artificial Neuron (Weighted Sum) > An artificial neuron multiplies each input by a weight, adds them up with a bias, and then decides how strongly to fire. Page: https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ z = \sum_{i=1}^{n} w_i x_i + b, \quad a = f(z) $$ Read it out loud: "z equals the sum, for i from 1 to n, of weight i times input i, plus the bias b. Then the output a equals f of z, where f is the activation function." ## What each symbol means - $x_i$: One input number, for example a pixel brightness or a sensor reading. The neuron has $n$ inputs in total. - $w_i$: The weight for input $i$. A large positive weight pushes the neuron toward firing, and a negative weight pushes against it. Training is the process that adjusts the weights. - $i$: The position of one input in the list, counting from 1 up to $n$. - $n$: How many inputs the neuron has. - $b$: The bias, one extra number added at the end. It shifts the threshold up or down, so the neuron can fire or stay quiet no matter what the inputs are. - $\sum_{i=1}^{n}$: "Add up for every $i$ from 1 to $n$": multiply each input by its weight and total all the results. - $z$: The weighted sum plus the bias: the raw total before the activation function is applied. - $f$: The activation function, a rule that turns the total $z$ into the final output. Two common examples are ReLU and the sigmoid. - $a$: The output of the neuron, also called its activation. It is the number passed on to the next layer. ## What the formula is doing In machine learning, an artificial neuron is a small function. It takes a list of numbers $x_1, \dots, x_n$ as inputs. Each input comes with a weight $w_i$, a number that says how much that input matters. Large weights matter a lot, and negative weights work against the output. The first step is the weighted sum. Multiply each input by its weight, add all the products together, and then add the bias $b$. The bias is one extra number that is not tied to any input. The result is $z$, the raw total. Nothing has been clipped or squashed yet. The second step is the activation function $f$. It takes $z$ and turns it into the output $a = f(z)$. Without this step, a neuron would only compute a straight-line rule, and stacking many such neurons would still give a straight-line rule. The activation function adds the bend that lets networks learn patterns that are not straight lines. Training is the process of finding good values for the weights and the bias. The formula itself does not change. Only those numbers do. Gradient descent is one common way to adjust them. ## An everyday picture Think of a voter weighing several opinions. Each friend's advice counts for a different amount: a trusted friend counts a lot, and a friend who is usually wrong counts for less. The voter adds up the weighted opinions, adds a personal tilt for or against the idea, and then decides whether the total is enough to say yes. The decision step plays the role of the activation function. ## Worked example: One neuron with two inputs Two inputs $x = (2, 3)$ with weights $w = (0.5, -1)$ and bias $b = 1$. The activation function is ReLU, which returns $\max(0, z)$: a negative total becomes 0, and a positive total passes through unchanged. All values are unitless in this example. 1. Multiply each input by its weight: $0.5 \times 2 = 1$ and $(-1) \times 3 = -3$. 2. Add the products and the bias: $z = 1 + (-3) + 1 = -1$. 3. Apply ReLU: $a = \max(0, -1) = 0$. **Answer:** The neuron outputs **0**. Its weighted total was negative, so ReLU silenced it. A negative total always becomes 0 under ReLU, and only a positive total gets through. ## Common mistakes - Forgetting the bias $b$. Without it, the boundary the neuron can draw is forced through the origin, which is a real limit on what it can learn. - Mixing up the weights and the inputs. The $w_i$ are the numbers the network learns, and the $x_i$ are the data that come in. A new example changes the inputs but not the weights. - Treating the output $a$ as if it were the sum $z$. The activation function sits between them, so a negative $z$ can become 0 and a large $z$ can be squashed. - Assuming someone picks the weights by hand. In real networks they start with random values, and training adjusts them. ## Where you will meet it - The units of fully connected layers in a multilayer perceptron, the basic feedforward neural network. - The filters of convolutional neural networks, which apply the same weighted sum to every small patch of an image. - The feed-forward blocks inside transformer language models, which follow the same weighted-sum-then-activation pattern. - Logistic regression, the classic model for yes-or-no questions, which is one neuron with a sigmoid activation. ## Questions people ask ### Is an artificial neuron the same as a real brain cell? No. It borrows the idea of inputs that add up toward a threshold, but it is a small math function. Real neurons are far more complicated, so the model is a simplified picture, not a copy. ### What does ReLU actually do? ReLU, short for rectified linear unit, is the rule $\max(0, z)$. Positive values pass through unchanged and negative values become 0. It is cheap to compute, which is one reason it is common in deep networks. ### Why does the neuron need a bias if it already has weights? The weights set how strongly each input pushes. The bias sets where the threshold sits, so the neuron can shift its decision point even when the inputs are all zero. ### Do the weights stay the same forever? No. Training changes them after examples are processed, based on how wrong the output was. The gradient descent rule explains how that adjustment works. ## Related formulas - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Artificial neuron, Wikipedia](https://en.wikipedia.org/wiki/Artificial_neuron) - [Rectifier (neural networks), Wikipedia](https://en.wikipedia.org/wiki/Rectifier_(neural_networks)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Sigmoid Function > The sigmoid takes any number, however big or small, and squeezes it into a value between 0 and 1 that can be read as a chance. Page: https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \sigma(z) = \frac{1}{1 + e^{-z}} $$ Read it out loud: "Sigma of z equals one divided by the quantity one plus e to the power of negative z." ## What each symbol means - $\sigma(z)$: The sigmoid of $z$: the output. It is always strictly between 0 and 1. - $z$: The input number, a raw score. It can be any real number: positive, negative or zero. It has no unit in most models. - $e$: Euler's number, about 2.718. Here it is raised to the power $-z$. ## What the formula is doing Many models need an output they can read as a probability, and a probability has to sit between 0 and 1. A raw score, however, can be any number at all, such as $-40$ or $+300$. The sigmoid is the rule that bridges the two: whatever number goes in, a value between 0 and 1 comes out. Here is what happens step by step. The term $e^{-z}$ is the same as $1 / e^{z}$. When $z$ is a large positive number, $e^{-z}$ is almost 0, so the fraction is almost $1 / 1 = 1$. When $z$ is a large negative number, $e^{-z}$ is huge, so the fraction is almost 0. When $z$ is exactly 0, $e^{0} = 1$ and the answer is $1/2$. The curve has an S shape. It climbs smoothly from near 0 on the left to near 1 on the right, and it passes through 0.5 when $z = 0$. Inputs near the middle change the output the most. Very large inputs in either direction land close to 0 or 1 and barely move after that. The sigmoid is also a smooth curve with no sharp corners. Training methods rely on that smoothness, because they measure how a small change in $z$ changes the output. That is why the sigmoid appears in logistic regression and in early neural networks. ## An everyday picture Think of a dimmer switch with a stop at each end. Turn it all the way one way and the light is fully off; turn it all the way the other way and it is fully on. Around the middle, a small turn changes the brightness a lot, while near the ends you can turn much further without any visible change. The sigmoid turns a raw input into a brightness somewhere between off (0) and fully on (1). ## Worked example: Three inputs: positive, zero and negative Apply the sigmoid to three raw scores: $z = 2$, $z = 0$ and $z = -2$. All values are unitless here. 1. For $z = 2$: $\sigma(2) = \frac{1}{1 + e^{-2}} = \frac{1}{1 + 0.1353} \approx 0.881$. 2. For $z = 0$: $\sigma(0) = \frac{1}{1 + e^{0}} = \frac{1}{1 + 1} = 0.5$. 3. For $z = -2$: $\sigma(-2) = \frac{1}{1 + e^{2}} = \frac{1}{1 + 7.389} \approx 0.119$. **Answer:** A raw score of $+2$ becomes about **0.881**, a score of 0 lands exactly on **0.5**, and a score of $-2$ drops to about **0.119**. Positive scores lean toward 1, negative scores lean toward 0, and 0 sits in the middle. ## Common mistakes - Mixing up $e^{-z}$ with $e^{z}$. The minus sign decides whether big inputs push the output toward 1 or toward 0. With $z = 2$ the answer must be above 0.5. - Expecting the output to be exactly 0 or exactly 1. The sigmoid gets close to 0 or 1 but never reaches them for any finite input. - Treating every output between 0 and 1 as a well-calibrated probability. A model can output 0.9 for answers that turn out right only half the time. - Using the sigmoid for a whole list of scores that must add up to 1. The sigmoid works on one score at a time; for a list, use softmax. ## Where you will meet it - Logistic regression, the classic model for yes-or-no questions, which passes a weighted sum through a sigmoid. - The output layer of a binary neural network classifier, such as a spam-or-not-spam score. - The gates inside LSTM recurrent networks, which use sigmoids to decide how much information to keep or forget. - Early neural networks, before ReLU became the usual choice in deep networks. ## Questions people ask ### Why is it called sigmoid? Sigmoid means S-shaped. Plot the curve and it looks like a stretched letter S. ### How is the sigmoid different from softmax? The sigmoid works on one score and gives one number between 0 and 1. Softmax works on a whole list and makes the list add up to 1. See the softmax page for that rule. ### Can the sigmoid output be negative? No. Because $e^{-z}$ is always positive, the bottom of the fraction is always bigger than 1, so the result stays strictly between 0 and 1. ### Where is the sigmoid steepest? Right in the middle, at $z = 0$. That is where a small change in the input moves the output the most. Far out on either side, the curve is almost flat. ## Related formulas - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) ## Sources - [Sigmoid function, Wikipedia](https://en.wikipedia.org/wiki/Sigmoid_function) - [Logistic function, Wikipedia](https://en.wikipedia.org/wiki/Logistic_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Softmax > Softmax takes a list of scores, any numbers at all, and turns them into percentages that add up to 100%. Page: https://formulabro.yunusemrevurgun.com/ai-ml/softmax/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \operatorname{softmax}(z)_i = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}} $$ Read it out loud: "The softmax of score number i equals e to the power of that score, divided by the sum of e to the power of every score." ## What each symbol means - $z$: The list of raw scores (also called **logits**). A model produces one score per possible answer. They can be any real numbers, even negative. - $z_i$: One score from the list, the one for answer number $i$. - $K$: How many scores are in the list, so how many possible answers there are. - $e$: Euler's number, about 2.718. Raising $e$ to a power makes every number positive. - $\sum_{j=1}^{K}$: "Add up for every $j$ from 1 to $K$": go through the whole list and total it. - $\operatorname{softmax}(z)_i$: The result for answer $i$: a number between 0 and 1, read as the probability of that answer. ## What the formula is doing A classifier, for example a model that looks at a photo and decides between *cat*, *dog* and *bird*, first produces one raw score per answer. The scores are not probabilities yet: they can be negative, they can be huge, and they do not add up to anything in particular. Softmax fixes that in two moves. First it raises $e$ to the power of every score. That turns every number positive, and it stretches the gaps: a score that is a bit bigger becomes a lot bigger after $e^{z}$. Second, it divides each of those positive numbers by their total. Dividing by the total is what makes the results add up to exactly 1, the same way you turn counts into percentages by dividing by the overall count. The order never changes: the biggest score always gets the biggest probability. Only the sizes change. Adding the same number to every score changes nothing at all, because that factor appears on the top and the bottom and cancels out. ## An everyday picture Think of a talent show where judges hand out raw points. Softmax is the host who converts those points into each act's share of the audience vote. Everybody gets a slice, the slices fill the whole pie, and the act with the most points gets the biggest slice, a little bigger than the raw points alone would suggest. ## Worked example: A photo classifier choosing between cat, dog and bird The model gives the scores $z = (2.0,\ 1.0,\ 0.1)$ for *cat*, *dog* and *bird*. 1. Raise $e$ to each score: $e^{2.0} \approx 7.389$, $e^{1.0} \approx 2.718$, $e^{0.1} \approx 1.105$. 2. Add them up: $7.389 + 2.718 + 1.105 = 11.213$. 3. Divide each one by the total: $$\frac{7.389}{11.213} \approx 0.659, \quad \frac{2.718}{11.213} \approx 0.242, \quad \frac{1.105}{11.213} \approx 0.099$$ 4. Check: $0.659 + 0.242 + 0.099 = 1.000$. **Answer:** The model says *cat* with about **65.9%** confidence, *dog* 24.2% and *bird* 9.9%. The cat score was only twice the dog score, but its probability is almost three times bigger: that is the stretching effect of $e^{z}$. ## Common mistakes - Dividing each score by the plain sum of scores. That breaks with negative scores and is not softmax; the $e^{z}$ step comes first. - Computing $e^{z}$ directly for big scores like 1000. The number overflows. Real code subtracts the largest score from every score first, which gives the same answer (see the last paragraph above) without the overflow. - Reading the output as the model's true certainty. Softmax always produces confident-looking percentages, even for a photo of something the model has never seen. - Applying softmax twice, for example inside the model and again inside the loss function. Many libraries' cross-entropy functions already include softmax. ## Where you will meet it - The last layer of almost every image, text and speech classifier, to turn scores into class probabilities. - Large language models, which use it to turn a score for every word in the vocabulary into the probability of the next word. - The attention mechanism in transformers, where softmax decides how much each word should look at every other word. - Reinforcement learning, where a softmax over action values picks actions at random but favors the better ones. ## Questions people ask ### Why use e and not 2 or 10? Any base above 1 would turn scores into positive numbers and keep their order. Base $e$ is used because its derivative is itself, which makes the math of training (gradients) short and clean. ### What is the difference between softmax and sigmoid? Sigmoid squeezes **one** score into a number between 0 and 1. Softmax handles a **whole list** and makes the results add up to 1. With exactly two answers, softmax gives the same result as a sigmoid of the difference between the two scores. ### What is temperature in softmax? Dividing every score by a number $T$ before softmax. $T$ above 1 flattens the percentages (more random choices), $T$ below 1 sharpens them toward the top answer. Chatbots expose this as the *temperature* setting. ### Why is it called softmax? A hard max would put 100% on the biggest score and 0% on the rest. Softmax does a soft version of that: the biggest score wins most, but every answer keeps a share. ## Related formulas - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Scaled Dot-Product Attention](https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention/) ## Sources - [Softmax function, Wikipedia](https://en.wikipedia.org/wiki/Softmax_function) - [Goodfellow, Bengio and Courville, Deep Learning, chapter 6.2.2.3 (Softmax units)](https://www.deeplearningbook.org/contents/mlp.html) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Mean Squared Error (MSE) > Mean squared error measures how wrong a model's guesses are by squaring each miss, so big misses count much more, and then averaging them. Page: https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \mathrm{MSE} = \frac{1}{n}\sum_{i=1}^{n} (y_i - \hat{y}_i)^2 $$ Read it out loud: "M S E equals one over n, times the sum, for i from 1 to n, of the true value y i minus the predicted value y hat i, all squared." ## What each symbol means - $\mathrm{MSE}$: The mean squared error: one number that sums up how wrong the predictions are. It is in squared units, so if the values are in meters, the MSE is in square meters. - $n$: How many predictions you are scoring. - $i$: The position of one prediction in the list, counting from 1 up to $n$. - $\sum_{i=1}^{n}$: "Add up for every $i$ from 1 to $n$": go through all the predictions and total the results. - $y_i$: The true value for case $i$, the answer you know is correct. - $\hat{y}_i$: The predicted value for case $i$, the model's guess. The hat over the $y$ is the usual sign for a prediction. ## What the formula is doing A model makes a guess for each case, and for each case you know the true answer. The error for one case is the gap between them: true value minus prediction. The gap can be positive or negative, depending on which way the miss went. Squaring each gap fixes two problems. It makes every error positive, so a miss of $-2$ and a miss of $+2$ do not cancel out. It also makes big misses count far more: a gap of 4 adds 16 to the total, while a gap of 2 adds only 4. Next, the formula adds up all the squared gaps and divides by $n$, the number of cases. Dividing turns the total into an average, so the score does not grow merely because you tested more cases. A smaller MSE means the predictions sit closer to the truth. An MSE of 0 means every prediction was exactly right. Because of the squaring, the result is in squared units and is harder to read than the original values. The square root of the MSE, called RMSE, brings it back to the original units. ## An everyday picture Think of a darts coach scoring practice throws. Each throw's distance from the bullseye is recorded, and a throw that lands far off costs much more than one that lands close. The coach averages those penalties across all the throws, so one wild throw shows up clearly in the score even when the rest are good. ## Worked example: Three temperature predictions A model predicts the temperature in three cities, in degrees Celsius. The true temperatures are $y = (3, 5, 2)$ and the predictions are $\hat{y} = (2, 6, 4)$. 1. Find each gap: $3 - 2 = 1$, $5 - 6 = -1$ and $2 - 4 = -2$. 2. Square each gap: $1^2 = 1$, $(-1)^2 = 1$ and $(-2)^2 = 4$. 3. Add the squares: $1 + 1 + 4 = 6$. 4. Divide by the number of predictions, $n = 3$: $\mathrm{MSE} = \frac{6}{3} = 2.0$. **Answer:** The MSE is **2.0 square degrees Celsius**. The biggest miss, the $-2$ for the third city, contributed 4 of the 6 squared points, so it dominates the score. A perfect model would score 0. ## Common mistakes - Squaring after averaging, or averaging after taking the gaps without squaring. The order is: gap, square, add, divide by $n$. - Adding up the squared gaps and forgetting to divide by $n$. The score then grows with the size of the test set, and two models can no longer be compared fairly. - Comparing MSE values across problems with different units. An MSE of 2 square degrees means nothing next to an MSE of 2 square dollars. - Expecting an MSE of 0 on real data. A score of 0 means every prediction was exact, which almost never happens outside toy examples. ## Where you will meet it - Linear regression, where the line is chosen to make the MSE as small as possible. - Training neural networks for regression tasks, such as predicting a price or a temperature. - Image compression and signal processing, where MSE measures how far the output is from the original. - Evaluating forecasts, such as weather or energy-demand predictions. ## Questions people ask ### Why square the errors instead of taking absolute values? Squaring gives a smooth curve with no sharp corner at zero, which makes it easier for gradient descent to follow. Squaring also punishes large misses more heavily. Some problems want that, and some do not. ### What is the difference between MSE and RMSE? RMSE is the square root of MSE. It comes back to the same units as the original values, so it is easier to read. ### Is a small MSE always good? Not always. A small MSE on the data used for training can hide a model that fails on new data. Check the score on data the model has not seen. ### Can MSE be used for yes-or-no answers? It can, but it is usually a poor choice. For classes, cross-entropy loss is the usual choice, because it punishes confident wrong answers much harder. ## Related formulas - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) ## Sources - [Mean squared error, Wikipedia](https://en.wikipedia.org/wiki/Mean_squared_error) - [Loss function, Wikipedia](https://en.wikipedia.org/wiki/Loss_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Cross-Entropy Loss > Cross-entropy loss gives a small score when the model was confident in the right answer and a big score when it was not. Page: https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ L = -\sum_{i=1}^{K} y_i \ln(\hat{y}_i) $$ Read it out loud: "L equals minus the sum, for i from 1 to K, of y i times the natural log of y hat i." ## What each symbol means - $L$: The loss: one number that says how wrong the model was. Lower is better, and 0 is a perfect score. With the natural log, the unit is the nat. - $K$: The number of possible classes, such as cat, dog and bird. - $i$: The position of one class in the list, counting from 1 up to $K$. - $\sum_{i=1}^{K}$: "Add up for every $i$ from 1 to $K$": total the terms for all the classes. - $y_i$: The true label for class $i$: 1 for the correct class and 0 for every other class. This is called a one-hot label. - $\hat{y}_i$: The probability the model gave to class $i$. It is a number between 0 and 1. - $\ln$: The natural logarithm, which asks: what power of $e$ gives this number? Any number between 0 and 1 gives a negative log, which is why the formula has a minus sign in front. ## What the formula is doing A classifier outputs a probability for each class, such as the probabilities produced by softmax, explained on its own page. The loss asks one question: how much probability did the model give to the answer that was actually right? With a one-hot label, every $y_i$ is 0 except the correct class, where it is 1. In the sum, every term with $y_i = 0$ drops out, so only one term is left: $-\ln(\hat{y}_c)$, where $c$ is the correct class. The loss is minus the natural log of the probability given to the correct answer. The log is what makes the score behave well. When the probability is close to 1, the log is close to 0, so the loss is close to 0. When the probability is close to 0, the log becomes a large negative number, so the loss becomes large. A confident wrong answer is punished hard, and the penalty grows without limit as the probability heads toward 0. The minus sign turns the negative logs into positive losses, so a lower loss means a better model. Training pushes the loss down, which pushes the probability of the correct answer up. ## An everyday picture Think of a bet where you must put all your money on one horse. If you put a lot of your money on the horse that wins, you lose little. If you put almost nothing on the winner, you lose heavily. Cross-entropy charges the model according to how little it put on the correct answer: a tiny share costs a lot, and the charge rises faster the smaller that share gets. ## Worked example: Cat, dog or bird, with a different correct answer The softmax example gave the probabilities cat 0.659, dog 0.242 and bird 0.099. Each case below uses a one-hot label, so only the correct class has $y = 1$. 1. If the correct answer is cat, only the cat term survives: $L = -\ln(0.659) \approx 0.417$. 2. If the correct answer had been bird, only the bird term survives: $L = -\ln(0.099) \approx 2.313$. 3. The other terms are all 0, because their $y_i$ values are 0. **Answer:** When the model was right about cat, the loss is a small **0.417**. When the true answer was bird, the model had put only 9.9% on it, and the loss jumps to **2.313**. The less probability the model gave to the truth, the faster the loss rises. ## Common mistakes - Dropping the minus sign. Without it the loss would be negative, and training would push the model toward giving the correct answer less probability. - Using a different log base and comparing the result with a loss from another source. This page uses the natural log. Other bases give other numbers, so the values are not directly comparable. - Feeding probabilities into a loss function that expects raw scores, or the reverse. Many libraries take raw scores and apply softmax inside, so check the documentation before adding softmax yourself. - Thinking a loss of 0 is normal on real data. A loss of 0 means the model gave probability 1 to the right answer for every case, which is rare. ## Where you will meet it - Training image classifiers, where the softmax outputs of the last layer are compared with the true class. - Language models, which score the probability of the correct next word at each position in a text. - Logistic regression for yes-or-no questions, which uses the two-class form of cross-entropy. - Information theory, where cross-entropy measures how many bits or nats are needed to encode data with a model's probabilities. ## Questions people ask ### Why not use mean squared error for classes? Cross-entropy matches how probabilities are scored, and it punishes confident wrong answers much harder than squared error does. Mean squared error is built for numbers; see its page for the details. ### What does ln mean? The natural log asks which power of $e$ gives a number. $\ln(1) = 0$, and any number between 0 and 1 gives a negative log. That is why the formula has a minus sign. ### Is the loss the same as accuracy? No. Accuracy only asks whether the top answer was right. The loss also counts how confident the model was, so two models with the same accuracy can have different losses. ### What is the loss for a yes-or-no question? It is the two-class form $-[y \ln(\hat{y}) + (1 - y)\ln(1 - \hat{y})]$. It uses the same idea with two classes instead of many. ## Related formulas - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Cross-entropy, Wikipedia](https://en.wikipedia.org/wiki/Cross-entropy) - [Loss function, Wikipedia](https://en.wikipedia.org/wiki/Loss_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Gradient Descent > Gradient descent nudges a model's settings a small step in the direction that lowers the error, then repeats until the error stops falling. Page: https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \theta_{\text{new}} = \theta_{\text{old}} - \eta \, \nabla L(\theta_{\text{old}}) $$ Read it out loud: "Theta new equals theta old, minus eta times the gradient of L, evaluated at theta old." ## What each symbol means - $\theta$: The settings the model learns, such as its weights and biases. When there are many settings, they are gathered into one list. Training means finding good values for them. - $\theta_{\text{old}}$: The current settings, before this update step. - $\theta_{\text{new}}$: The settings after one update step. - $\eta$: The learning rate, the Greek letter eta: a small positive number that sets how big each step is. - $L$: The loss function, which scores how wrong the model is at a given set of settings. Lower is better. - $\nabla L$: The gradient of the loss: the slope of the loss in each direction. It points the way the loss rises fastest. ## What the formula is doing Training a model means finding settings $\theta$ that make the loss $L$ small. The loss is a score built from the model's errors, and it depends on the settings. Picture the loss as a landscape of hills and valleys, where the height is the loss and each position is one choice of settings. The gradient $\nabla L$ tells you the slope at your current position. It points uphill, in the direction the loss rises fastest. To lower the loss, the update goes the opposite way, and that is the minus sign in the formula. The learning rate $\eta$ controls the size of each step. A small $\eta$ takes safe, tiny steps that can be slow. A large $\eta$ takes big steps that can jump over the valley and make the loss worse. A good value is usually found by trying a few. The formula is applied again and again. Each step moves the settings a little downhill. As the slope flattens near the bottom, the steps shrink and the loss stops falling much. That is the sign that training has reached a low point. ## An everyday picture Think of walking down a foggy hill in the dark. You cannot see the bottom, but you can feel which way the ground slopes under your feet. You take a step downhill, feel the slope again, and repeat. Long strides get you down quickly but risk stumbling past the bottom; short steps are safe but slow. ## Worked example: Finding the bottom of a simple bowl The loss is $L(w) = (w - 3)^2$, a bowl whose lowest point is at $w = 3$. Its gradient is $\frac{dL}{dw} = 2(w - 3)$. Start at $w = 0$ with learning rate $\eta = 0.1$. All values are unitless here. 1. First step: the gradient at $w = 0$ is $2(0 - 3) = -6$. The update is $w = 0 - 0.1 \times (-6) = 0.6$. 2. Second step: the gradient at $w = 0.6$ is $2(0.6 - 3) = -4.8$. The update is $w = 0.6 - 0.1 \times (-4.8) = 1.08$. 3. Third step: the gradient at $w = 1.08$ is $2(1.08 - 3) = -3.84$. The update is $w = 1.08 - 0.1 \times (-3.84) = 1.464$. **Answer:** After three steps the setting is $w = 1.464$, closer to the bottom at 3 than the start was. Each step is smaller than the one before, because the slope gets gentler as $w$ nears 3. ## Common mistakes - Adding the gradient instead of subtracting it. That climbs the hill, so the loss grows. - Using a learning rate that is too big. In the bowl above, with $\eta = 1.1$, the first step jumps from $w = 0$ to $w = 6.6$, and the loss rises from 9 to 12.96. The next step lands at $w = -1.32$, and the steps keep growing, so training blows up instead of settling. - Using a learning rate that is too small and not noticing. Training crawls, looks stuck, and wastes time. Watch how the loss changes over the steps. - Confusing the loss with the gradient. The loss is one number for a given setting. The gradient is the slope, and it changes as the setting changes. ## Where you will meet it - Training the weights of nearly every neural network, usually in a variant called stochastic gradient descent. - Fitting linear and logistic regression models. - Large language and image models, which run huge numbers of these updates during training. - Curve fitting in science and engineering, where the parameters of a model are tuned to match measured data. ## Questions people ask ### How do you know the learning rate is right? Watch the loss. If it falls steadily, the rate is fine. If it bounces up and down or grows, the rate is too big. If it falls very slowly, the rate is probably too small. ### Does gradient descent always find the best answer? No. On a bumpy landscape it can settle into a low point that is not the lowest one. On a simple bowl like the example, it reaches the bottom if the steps are small enough. ### Where does the gradient come from? From calculus. It is the set of partial derivatives of the loss with respect to each setting. Backpropagation is the method neural networks use to compute them efficiently. ### What is stochastic gradient descent? It is the same update, but the gradient is estimated from a small random batch of data rather than the whole dataset. Each step is cheaper, and the noise in the estimate often helps. ## Related formulas - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) ## Sources - [Gradient descent, Wikipedia](https://en.wikipedia.org/wiki/Gradient_descent) - [Backpropagation, Wikipedia](https://en.wikipedia.org/wiki/Backpropagation) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bayes' Theorem > Bayes' theorem tells you how much to change your belief in something after you see new evidence. Page: https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P(A \mid B) = \frac{P(B \mid A)\, P(A)}{P(B)} $$ Read it out loud: "The probability of A given B equals the probability of B given A, times the probability of A, divided by the probability of B." ## What each symbol means - $P(A \mid B)$: The probability that $A$ is true once you know that $B$ happened. This is the updated belief, the answer you want. - $P(B \mid A)$: The probability of seeing the evidence $B$ if $A$ is true. It is often the number that is easiest to measure. - $P(A)$: The prior: the probability of $A$ before you see any evidence. - $P(B)$: The overall probability of seeing the evidence $B$, counting every way it can happen. - $A$: The thing you want to know about, such as a person being sick. - $B$: The evidence you have recently observed, such as a positive test result. ## What the formula is doing Bayes' theorem connects two conditional probabilities that are easy to mix up. $P(B \mid A)$ asks: if $A$ is true, how likely is this evidence? $P(A \mid B)$ asks the reverse: now that we have the evidence, how likely is $A$? These are different numbers, and mixing them up leads to bad decisions. The formula starts from the prior $P(A)$, your belief before the evidence. It multiplies that by $P(B \mid A)$, which measures how well the evidence fits $A$. Then it divides by $P(B)$, the overall chance of seeing that evidence at all. The division keeps the result a proper probability between 0 and 1. The division by $P(B)$ does important work. It counts the evidence coming from every source, not only from $A$. When the evidence is common in general, $P(B)$ is large and the update is small. When the evidence is rare, the update can be large. Bayes' theorem is a rule for updating beliefs. Once you have the updated belief, it can serve as the prior for the next piece of evidence, so a belief can be refined step by step as new information arrives. ## An everyday picture Think of a detective weighing a clue. A muddy boot print points more strongly to a suspect if muddy boots are rare in town. If everyone owns muddy boots, the print tells the detective very little. Bayes' theorem weighs the clue against how common it is overall, not only against how well it fits the suspect. ## Worked example: A medical test for a rare disease Let $A$ be the event that a person is sick and $B$ be the event that the test is positive. Suppose 1% of people are sick, so $P(A) = 0.01$. The test is positive for 90% of sick people, so $P(B \mid A) = 0.9$. It is also positive for 9% of healthy people, so the false positive rate is $0.09$. A random person tests positive. What is the chance they are sick? 1. Find the overall chance of a positive test, $P(B)$. Add the two ways to test positive: being sick and testing positive, and being healthy and testing positive. $P(B) = 0.9 \times 0.01 + 0.09 \times 0.99 = 0.009 + 0.0891 = 0.0981$. 2. Apply Bayes' theorem: $P(A \mid B) = \frac{0.9 \times 0.01}{0.0981} = \frac{0.009}{0.0981} \approx 0.092$. **Answer:** Even after a positive result, the chance of being sick is only about **9.2%**. The test is good, but the disease is rare, so most positive results come from the much larger group of healthy people. ## Common mistakes - Swapping $P(A \mid B)$ and $P(B \mid A)$. A test that catches 90% of sick people does not mean a positive result is 90% likely to be sick. - Forgetting the prior. Ignoring how rare the disease is makes a positive test look far more conclusive than it is. - Leaving the false positives out of $P(B)$. The denominator must count every way the evidence can show up, including healthy people who test positive. - Reading a probability of 9.2% as a verdict on one person. It describes a group of cases that look like this one, not a certain answer. ## Where you will meet it - Medical testing, where a test result and the disease rate are combined into the chance that a patient is actually sick. - Naive Bayes spam filters, which estimate how likely an email is to be spam given the words it contains. - Robot localization, where a robot updates its guess of its own position with each new sensor reading. - Bayesian statistics, where a prior belief is updated with data to give a posterior belief. ## Questions people ask ### What is a prior? The prior is your starting belief before the new evidence. It can come from past data, expert knowledge or a rough estimate. The updated belief after the evidence is called the posterior. ### What does naive mean in naive Bayes? It assumes the features, such as the words in an email, are independent of each other once the class is known. That assumption is rarely exactly true in real text, but the method still works well for spam filtering. ### Why can P(B) be hard to compute? When the evidence can come from many different causes, adding up every way it can happen takes work. Many methods avoid computing it directly by comparing the ratios of the possible answers. ### Is Bayes' theorem only for medical tests? No. It works for any question where a belief is updated with evidence, such as spam filters or robot localization. ## Related formulas - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) ## Sources - [Bayes' theorem, Wikipedia](https://en.wikipedia.org/wiki/Bayes%27_theorem) - [Naive Bayes spam filtering, Wikipedia](https://en.wikipedia.org/wiki/Naive_Bayes_spam_filtering) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Scaled Dot-Product Attention > Attention lets a model look at every item in a list and decide how much each one matters for the item it is working on. Page: https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \operatorname{Attention}(Q, K, V) = \operatorname{softmax}\left(\frac{Q K^{\top}}{\sqrt{d_k}}\right) V $$ Read it out loud: "Attention of Q, K and V equals softmax of Q times K transposed, divided by the square root of d k, all times V." ## What each symbol means - $\operatorname{Attention}(Q, K, V)$: The output: for each query, a blend of the values, weighted by how well that query matches each key. - $Q$: The queries: one row per item, describing what that item is looking for. Each row is a short list of numbers called a vector. - $K$: The keys: one row per item, describing what that item offers. Queries are matched against keys. - $V$: The values: one row per item, holding the content that gets passed along when the item is attended to. - $K^{\top}$: The keys turned on their side (the transpose), so that every query can be dotted with every key. - $d_k$: The length of each key vector, meaning how many numbers it holds. - $\sqrt{d_k}$: The square root of $d_k$. Dividing by it keeps the match scores from growing too large as the vectors get longer. - $\operatorname{softmax}$: The softmax rule: it turns a list of scores into positive weights that add up to 1. ## What the formula is doing Attention works on a list of items, such as the words in a sentence. Each item is turned into three vectors. The query says what the item is looking for. The key says what the item offers. The value holds the content the item contributes. All three come from the same words through weight matrices that the model learns. The first step is matching. Take the query of one item and take the dot product with the key of every item in the list. A dot product is large when the two vectors point in similar directions, and small or negative when they point apart. The result is one raw score for each item. The scores are then divided by $\sqrt{d_k}$. Dot products grow as the vectors get longer, so long keys would give huge scores. Huge scores push softmax to put almost all of its weight on one item, and learning slows down. Dividing by $\sqrt{d_k}$ keeps the scores at a sensible size. Softmax turns the scores into weights that are positive and add up to 1. The output for the query is the weighted sum of the values. Items that match the query well contribute more of their value, and items that match poorly contribute little. ## An everyday picture Think of searching a library. Your question is the query. Each book's catalog card is its key, and the book's contents are its value. You compare your question with every card and give each book a score for how well it matches. Then you read a mix of the books in proportion to those scores, mostly from the best matches and a little from the rest. ## Worked example: One query and two keys One query $q = (1, 0)$, two keys $k_1 = (1, 0)$ and $k_2 = (0, 1)$, and two values $v_1 = (10, 0)$ and $v_2 = (0, 10)$. Each key has length $d_k = 2$. All numbers are unitless here. 1. Dot the query with each key: $q \cdot k_1 = 1 \times 1 + 0 \times 0 = 1$ and $q \cdot k_2 = 1 \times 0 + 0 \times 1 = 0$. 2. Divide by $\sqrt{d_k} = \sqrt{2} \approx 1.414$: $1 / 1.414 \approx 0.707$ and $0 / 1.414 = 0$. 3. Apply softmax. Raise $e$ to each scaled score: $e^{0.707} \approx 2.028$ and $e^{0} = 1$, which add up to $3.028$. The weights are $\frac{2.028}{3.028} \approx 0.670$ and $\frac{1}{3.028} \approx 0.330$. 4. Take the weighted sum of the values: $0.670 \times (10, 0) + 0.330 \times (0, 10) = (6.70, 3.30)$. **Answer:** The output is **(6.70, 3.30)**. It is mostly the first value, because the query matched the first key better. The second key still gets about a third of the weight, so its value is not ignored. ## Common mistakes - Leaving out the division by $\sqrt{d_k}$. With long vectors the scores become huge, and the weights collapse onto a single item. - Mixing up the roles of Q, K and V. Queries and keys decide how much each item attends to the others; values are the content that gets copied into the output. - Thinking attention reads the items in order. Plain attention looks at all items at once, so word order has to be added separately, for example with positional encodings. - Expecting the output to be a copy of the best-matching value. The output is a blend of all the values, weighted by the scores. ## Where you will meet it - The original transformer translation model in Vaswani et al. (2017), the paper that introduced the transformer. - Large language models, where many attention layers let each word use context from the words that came before it. - Vision transformers, which apply attention to small patches of an image. - Speech recognition systems built on transformer architectures, which attend across the whole audio sequence. ## Questions people ask ### Why are there three vectors instead of one? Separate roles let the model learn what to look for, what to advertise and what to pass along. A single vector would have to do all three jobs at once. ### Why is it called self-attention? When the queries, keys and values all come from the same sequence, the items attend to each other. That is called self-attention. In cross-attention, the queries come from one sequence while the keys and values come from another. ### Is attention the same as softmax? No. Softmax is one step inside attention. Attention also includes the dot products that score the matches, the scaling and the final weighted sum. ### Why do long inputs make attention expensive? The score table has one entry for every pair of items, so its size grows quickly as the list gets longer. That is one reason long inputs cost so much for transformers. ## Related formulas - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) ## Sources - [Vaswani et al., Attention Is All You Need (arXiv:1706.03762)](https://arxiv.org/abs/1706.03762) - [Attention (machine learning), Wikipedia](https://en.wikipedia.org/wiki/Attention_(machine_learning)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Linear Regression > Linear regression predicts a number by drawing the straight line that sits closest to the data points, so you can read off a guess for any new input. Page: https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \hat{y} = w x + b $$ Read it out loud: "y hat equals w times x, plus b. The predicted y is the slope w times the input x, plus the intercept b." ## What each symbol means - $\hat{y}$: The **predicted** output, the number the line gives for a chosen input $x$. The hat over the $y$ marks it as a guess, not a measured value. - $x$: The **input**, a number you already know, such as hours of study. It has whatever unit the input is measured in. - $w$: The **slope** (also called the weight): how much the prediction changes when $x$ goes up by one unit. A slope of 0.7 means the prediction rises by 0.7 for each extra unit of $x$. - $b$: The **intercept** (also called the bias): the prediction when $x$ is 0. It sets the height where the line crosses the vertical axis. ## What the formula is doing Linear regression is the simplest way to use one number to predict another. You start with pairs of values: an input $x$ and the output $y$ that you actually observed. The formula $\hat{y} = w x + b$ describes a straight line. For any input $x$, multiply by the slope $w$, add the intercept $b$, and you get the predicted output $\hat{y}$. The hard part is choosing $w$ and $b$. The usual rule is **least squares**. For each data point, the **residual** is the observed value minus the predicted value, $y_i - \hat{y}_i$. Least squares picks the line that makes the sum of the squared residuals as small as possible. Squaring stops positive and negative misses from cancelling out, and it punishes big misses more than small ones. There is a direct formula for the best slope. Let $\bar{x}$ and $\bar{y}$ be the averages of the inputs and the outputs, and let the sums run over every data point $i$. Then $$w = \frac{\sum_{i} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i} (x_i - \bar{x})^2}$$ The top adds up how the inputs and outputs move together. The bottom adds up how much the inputs spread out. The intercept follows from the averages: $b = \bar{y} - w \bar{x}$. The fitted line always passes through the point $(\bar{x}, \bar{y})$. A positive slope means the output tends to rise as the input rises. A negative slope means it tends to fall. A slope near zero says the input tells you little about the output. The line is only as good as the data behind it: when the real relationship curves, a straight line will miss the pattern. ## An everyday picture Think of a teacher with a scatter of dots on graph paper, one dot per student, with hours studied across the bottom and quiz score up the side. Linear regression is the ruler laid across the dots so the line sits as close to all of them as possible. To estimate a new student's score, find their hours along the bottom and read the height of the ruler above that spot. ## Worked example: Predicting a quiz score from hours of study Four students report their study hours $x$ and get a quiz score $y$ out of 10. The data are $x = (1, 2, 3, 4)$ hours and $y = (2, 4, 5, 4)$ points. Find the best line and predict the score for a student who studies 5 hours. 1. Find the averages: $\bar{x} = \frac{1 + 2 + 3 + 4}{4} = 2.5$ hours and $\bar{y} = \frac{2 + 4 + 5 + 4}{4} = 3.75$ points. 2. Find the top of the slope formula, the sum of $(x_i - \bar{x})(y_i - \bar{y})$: $(-1.5)(-1.75) + (-0.5)(0.25) + (0.5)(1.25) + (1.5)(0.25) = 3.5$. 3. Find the bottom, the sum of $(x_i - \bar{x})^2$: $2.25 + 0.25 + 0.25 + 2.25 = 5.0$. 4. Divide for the slope: $w = \frac{3.5}{5.0} = 0.7$ points per hour. 5. Find the intercept: $b = \bar{y} - w \bar{x} = 3.75 - 0.7 \times 2.5 = 2.0$ points. 6. Predict for 5 hours: $\hat{y} = 0.7 \times 5 + 2.0 = 5.5$ points. **Answer:** The best line is $\hat{y} = 0.7x + 2.0$. A student who studies 5 hours is predicted to score about **5.5 points** out of 10. Each extra hour adds about 0.7 points to the prediction. Four data points is far too few for a real study, so treat this as a demonstration of the method. ## Common mistakes - Swapping the input and the output. The line predicts $y$ from $x$, so the value you know goes in as $x$ and the value you want to predict is $\hat{y}$. - Forgetting to subtract the averages in the slope formula. Using the raw $x_i$ and $y_i$ gives a different, wrong slope. - Predicting far outside the data. A line fitted to 1 to 4 hours of study says little about 40 hours, because the pattern may not continue that far. - Expecting a straight line to fit curved data. Linear regression always draws a straight line, even when the real pattern bends. ## Where you will meet it - Predicting house prices from floor area, where the slope gives a rough price per square meter. - Forecasting sales, demand or energy use from a steady trend over time. - Calibrating sensors, such as turning a voltage reading into a temperature by fitting a line to known reference points. - Serving as the baseline model in statistics and data science courses, which more complex models must beat. ## Questions people ask ### What does least squares mean? It is the rule for choosing the line. Among all straight lines, pick the one that makes the sum of the squared vertical distances from the points to the line as small as possible. ### Is linear regression the same as correlation? No. Correlation measures how tightly the points cluster around a line, on a scale from $-1$ to $1$. Regression gives the actual line, with a slope and an intercept you can use to predict. ### How is linear regression different from logistic regression? Linear regression predicts a number such as a score or a price. Logistic regression predicts the probability of a yes-or-no outcome, using an S-shaped curve. ### Why is it called linear? The prediction changes at a constant rate. Each extra unit of $x$ adds the same amount, $w$, to the prediction, which is exactly what a straight line does. ## Related formulas - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) - [Logistic Regression](https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression/) - [L2 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization/) ## Sources - [Linear regression, Wikipedia](https://en.wikipedia.org/wiki/Linear_regression) - [Least squares, Wikipedia](https://en.wikipedia.org/wiki/Least_squares) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Logistic Regression > Logistic regression takes the same weighted sum as a straight line, then squeezes it through an S-shaped curve so the result is a probability between 0 and 1. Page: https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ p = \sigma(w x + b) = \frac{1}{1 + e^{-(w x + b)}} $$ Read it out loud: "p equals sigma of w x plus b, which equals one over one plus e to the power of minus the quantity w x plus b." ## What each symbol means - $p$: The **probability** that the outcome is class 1, for example that a student passes. It is always between 0 and 1. Multiply by 100 to read it as a percentage. - $\sigma$: The **sigmoid** (logistic) function. It takes any real number and returns a value between 0 and 1. - $w$: The **weight**, how strongly the input pushes the probability up or down. A positive weight means a larger $x$ gives a higher probability. - $x$: The **input**, such as hours of study. Its unit depends on what you measure. - $b$: The **bias** (intercept): it shifts the whole curve left or right. It sets the input where the probability crosses 0.5. - $e$: Euler's number, about 2.718. It appears because the sigmoid is built from exponentials. ## What the formula is doing Linear regression predicts a number, but many questions have a yes-or-no answer: will the student pass, is the email spam, will the loan be repaid. For these you want a probability. Logistic regression starts from the same weighted sum as a straight line, $z = w x + b$, and then passes it through the sigmoid function $\sigma(z) = \frac{1}{1 + e^{-z}}$. The value $z$ is called the **log-odds**, a raw score that can be any size. The sigmoid does the squeezing. When $z$ is a large positive number, $e^{-z}$ is tiny and the output is close to 1. When $z$ is a large negative number, $e^{-z}$ is huge and the output is close to 0. When $z$ is exactly 0, the output is exactly 0.5. The curve rises smoothly between those extremes, so a small change in the input gives a small change in the probability. The weights $w$ and $b$ are learned from labeled examples, usually by maximum likelihood, which is the same as minimizing the cross-entropy loss. Once the model is trained, a yes-or-no answer comes from a threshold: predict class 1 when $p \ge 0.5$ and class 0 otherwise. Because $\sigma(0) = 0.5$, that rule is the same as asking whether $w x + b \ge 0$. The threshold of 0.5 is a default, not a law. When a false alarm costs more than a miss, as in some medical screening, a different threshold is wiser. With one input, the boundary between the two classes is the single point where $z = 0$, which is $x = -b / w$. ## An everyday picture Think of a sliding scale that runs from very unlikely to very likely. The weighted sum is a raw score that can be any size, like points on a scoreboard. The sigmoid is the translator that turns any score into a position on the 0 to 100 percent scale. A score of zero lands exactly in the middle, at 50 percent. ## Worked example: Will a student pass a test after studying? A model uses hours studied $x$. It has learned the weight $w = 0.8$ per hour and the bias $b = -3$. Find the probability of passing for a student who studies 5 hours and for one who studies 2 hours. Use a threshold of 0.5. 1. Compute the weighted sum for 5 hours: $z = 0.8 \times 5 - 3 = 1.0$. 2. Apply the sigmoid: $p = \frac{1}{1 + e^{-1.0}} = \frac{1}{1 + 0.3679} \approx 0.731$. 3. Compare with the threshold: $0.731 \ge 0.5$, so the model predicts **pass**. 4. Repeat for 2 hours: $z = 0.8 \times 2 - 3 = -1.4$, so $p = \frac{1}{1 + e^{1.4}} = \frac{1}{1 + 4.055} \approx 0.198$. That is below 0.5, so the model predicts **fail**. **Answer:** A student who studies 5 hours has about a **73.1%** chance of passing, so the model predicts pass. A student who studies 2 hours has about **19.8%**, so the model predicts fail. The 0.5 boundary falls at 3.75 hours of study, where $z = 0$. ## Common mistakes - Treating the output as a straight-line prediction. The sigmoid bends the line, so one extra hour does not change the probability by the same amount everywhere. - Expecting the output to be a yes-or-no answer. The result is a probability. You must apply a threshold to turn it into a label. - Dropping the minus sign in the exponent. The formula uses $e^{-z}$, so a large positive $z$ gives a probability close to 1. - Assuming the word regression means a numeric prediction. Logistic regression is a classifier: it predicts a class, through a probability. ## Where you will meet it - Spam filters, which estimate the chance that an email is spam from the words it contains. - Medical risk scores, which estimate the probability of a condition from measurements such as age and blood pressure. - Credit scoring, which estimates the chance that a loan applicant will default. - Baseline models for any yes-or-no prediction, such as whether a customer will click an advertisement. ## Questions people ask ### How is logistic regression different from linear regression? Linear regression predicts a number, such as a price. Logistic regression predicts a probability for a class, and the sigmoid keeps the output between 0 and 1. ### Why is it called logistic? The sigmoid curve it uses is also called the logistic function, and that is where the name comes from. ### Can the output ever be exactly 0 or 1? Not in exact arithmetic. The sigmoid gets very close to 0 for large negative scores and very close to 1 for large positive scores, but it never reaches either end. ### Can logistic regression handle more than two classes? Yes. The method is extended to several classes, usually by using softmax in place of the sigmoid. ## Related formulas - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Linear Regression](https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) ## Sources - [Logistic regression, Wikipedia](https://en.wikipedia.org/wiki/Logistic_regression) - [Logistic function, Wikipedia](https://en.wikipedia.org/wiki/Logistic_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # ReLU Activation > ReLU passes positive numbers through unchanged and replaces every negative number with zero, like a switch that is on for positive input and off otherwise. Page: https://formulabro.yunusemrevurgun.com/ai-ml/relu-activation/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{ReLU}(z) = \max(0, z) $$ Read it out loud: "ReLU of z equals the larger of zero and z." ## What each symbol means - $\text{ReLU}(z)$: The **rectified linear unit** output: the value the neuron passes on to the next layer. - $z$: The **input** to the activation, usually the weighted sum of a neuron's inputs plus its bias. It can be any real number, positive or negative. - $\max(0, z)$: The larger of the two numbers 0 and $z$. If $z$ is positive, the result is $z$. If $z$ is negative, the result is 0. ## What the formula is doing An activation function sits at the output of a neuron and decides what gets passed on. A neuron first computes a weighted sum $z$ of its inputs, then applies the activation. Without a non-linear activation, a stack of layers collapses into one big linear formula, and that formula cannot learn curved patterns. ReLU, short for rectified linear unit, is the simplest useful choice. It has two cases. If $z$ is positive, the output equals $z$, a straight line with slope 1. If $z$ is zero or negative, the output is 0. The output never goes below zero. The main advantage is cheap computation. Producing the output takes one comparison, with no exponentials. For positive inputs the slope is always 1, so the learning signal does not shrink there the way it can with saturating curves such as the sigmoid. That is a large part of why deep networks train well with it. The known drawback is the **dying ReLU** problem. A neuron whose input stays negative outputs 0 and receives no gradient, so it can stop learning for good. Variants such as the leaky ReLU keep a small slope on the negative side to avoid this. ## An everyday picture Think of a one-way valve on a water pipe. Water pushing forward flows through unchanged, so a bigger push gives a bigger flow. Water pushing backward meets a closed valve and stops at zero. The neuron lets through only the part of the signal that points in the forward direction. ## Worked example: One neuron with two inputs A neuron has inputs $x_1 = 3$ and $x_2 = 1$, weights $w_1 = 0.5$ and $w_2 = -2$, and bias $b = 0.25$. Find its output with ReLU. Then change the second input to $x_2 = 0.5$ and find the output again. 1. Compute the weighted sum: $z = 0.5 \times 3 + (-2) \times 1 + 0.25 = 1.5 - 2 + 0.25 = -0.25$. 2. Apply ReLU: $\text{ReLU}(-0.25) = \max(0, -0.25) = 0$. 3. Change the second input to $x_2 = 0.5$: $z = 0.5 \times 3 + (-2) \times 0.5 + 0.25 = 1.5 - 1 + 0.25 = 0.75$. 4. Apply ReLU again: $\text{ReLU}(0.75) = \max(0, 0.75) = 0.75$. **Answer:** With $x_2 = 1$ the neuron is switched off and outputs **0**. With $x_2 = 0.5$ the weighted sum is positive, so the neuron passes on **0.75** unchanged. ## Common mistakes - Thinking ReLU is a curve that dips below zero. The output is never negative: every negative input becomes exactly 0. - Applying ReLU to the inputs instead of to the weighted sum. The activation goes on the neuron's output, after the weights and bias. - Expecting a neuron to recover on its own after it outputs 0. If its input stays negative, its gradient is zero and it can stop learning. - Using ReLU as the output of a yes-or-no classifier. Its output is not a probability, so use a sigmoid or a softmax at the output instead. ## Where you will meet it - Hidden layers of convolutional networks for image recognition, where it is a common default. - Hidden layers of fully connected networks for regression and classification tasks. - Output layers of networks that must predict a value that is never negative, such as a count or a length. - Introductory deep learning courses, where it is usually the first activation function students meet after the sigmoid. ## Questions people ask ### Why not use a straight line instead? A stack of straight-line layers is still one straight line overall. The bend that ReLU adds is what lets stacked layers represent curved patterns. ### What is the derivative of ReLU? It is 1 for positive inputs and 0 for negative inputs. The point exactly at zero is handled by convention in code, usually as 0. ### Why is ReLU so popular? It is fast to compute, it does not squeeze large values the way a sigmoid does, and it trains well in deep networks. Those three points together made it a common default for hidden layers. ## Related formulas - [Tanh Activation](https://formulabro.yunusemrevurgun.com/ai-ml/tanh-activation/) - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) - [Backpropagation and the Chain Rule](https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule/) ## Sources - [Rectifier (neural networks), Wikipedia](https://en.wikipedia.org/wiki/Rectifier_%28neural_networks%29) - [Activation function, Wikipedia](https://en.wikipedia.org/wiki/Activation_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Tanh Activation > Tanh squashes any input into a number between minus 1 and plus 1, with zero at the center, so a negative input gives a negative output. Page: https://formulabro.yunusemrevurgun.com/ai-ml/tanh-activation/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \tanh(z) = \frac{e^{z} - e^{-z}}{e^{z} + e^{-z}} $$ Read it out loud: "tanh of z equals e to the power of z, minus e to the power of minus z, all divided by e to the power of z, plus e to the power of minus z." ## What each symbol means - $\tanh(z)$: The **hyperbolic tangent** of $z$. Its value always lies strictly between $-1$ and $1$. - $z$: The **input**, usually a weighted sum inside a neuron. It can be any real number, positive or negative. - $e$: Euler's number, about 2.718. Raising $e$ to the power $z$ gives a positive number for any $z$. ## What the formula is doing Tanh is a smooth S-shaped activation function, like the sigmoid but centered on zero. Its formula compares $e^{z}$ with $e^{-z}$. The numerator is the difference between those two exponentials, and the denominator is their sum. The sigmoid is built from the same pair, so the two curves are closely related. The output always lies between $-1$ and $+1$. For a large positive $z$, $e^{-z}$ is tiny, so the ratio approaches $+1$. For a large negative $z$, the ratio approaches $-1$. At $z = 0$ the numerator is zero, so the output is exactly 0. There is a direct link to the sigmoid: $\tanh(z) = 2\sigma(2z) - 1$. The sigmoid rises from 0 to 1, and tanh is the same shape stretched to run from $-1$ to $1$, with its middle moved to zero. Because the output is centered on zero, the next layer receives inputs that average out near zero, which often makes training go more smoothly than with the sigmoid. Tanh still saturates. For large positive or negative $z$ the curve flattens, its slope $1 - \tanh^{2}(z)$ approaches zero, and learning through that neuron slows. The slope is at its largest, 1, exactly at $z = 0$. ## An everyday picture Think of a dial that runs from full cold to full hot, with neutral in the middle. Turning the dial further in either direction changes the output less and less, and a dial at neutral reads zero. Tanh behaves like that dial: a large input nearly maxes out on its side, and an input of zero sits in the balanced middle. ## Worked example: Tanh of a neuron's weighted sum A neuron has the weighted sum $z = 0.5$. Find $\tanh(0.5)$ from the exponential formula, then check the answer with the sigmoid relation $\tanh(z) = 2\sigma(2z) - 1$. 1. Find the exponentials: $e^{0.5} \approx 1.6487$ and $e^{-0.5} \approx 0.6065$. 2. Numerator: $1.6487 - 0.6065 = 1.0422$. Denominator: $1.6487 + 0.6065 = 2.2552$. 3. Divide: $\tanh(0.5) = \frac{1.0422}{2.2552} \approx 0.4621$. 4. Check with the sigmoid: $\sigma(1) = \frac{1}{1 + e^{-1}} \approx 0.7311$, so $2 \times 0.7311 - 1 = 0.4621$. **Answer:** $\tanh(0.5) \approx 0.462$. The output is positive because the input is positive, and it sits well inside the range from $-1$ to $1$. The sigmoid check gives the same value, which confirms $\tanh(z) = 2\sigma(2z) - 1$. ## Common mistakes - Mixing tanh up with the sigmoid. Tanh outputs values from $-1$ to $1$, while the sigmoid outputs values from 0 to 1. - Expecting tanh of a negative number to be positive. Tanh is odd, so $\tanh(-z) = -\tanh(z)$: a negative input gives a negative output. - Forgetting that tanh flattens for large inputs. Far from zero its slope is close to 0, so training through that neuron is slow. - Treating tanh as the automatic best choice. It is a common option for hidden layers, but the right activation depends on the model and on training results. ## Where you will meet it - The gates of older recurrent networks, such as LSTM and GRU cells, where tanh squashes the cell's values. - Hidden layers of early multilayer neural networks, where tanh was a standard alternative to the sigmoid. - Mathematics and physics, where the hyperbolic tangent appears in the formulas for many systems. ## Questions people ask ### What is the difference between tanh and the sigmoid? The sigmoid outputs values from 0 to 1, and tanh outputs values from $-1$ to $1$. Tanh is centered on zero, which is its main practical advantage. ### Why is it called the hyperbolic tangent? It is built from the exponentials $e^{z}$ and $e^{-z}$, in the same way that the ordinary tangent is built from sine and cosine. It belongs to the family of hyperbolic functions. ### Does tanh suffer from the vanishing gradient problem? Yes, at the far ends. Its slope $1 - \tanh^{2}(z)$ approaches zero for large inputs, so the network learns slowly through those neurons. ## Related formulas - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) - [ReLU Activation](https://formulabro.yunusemrevurgun.com/ai-ml/relu-activation/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) - [Logistic Regression](https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression/) ## Sources - [Hyperbolic functions, Wikipedia](https://en.wikipedia.org/wiki/Hyperbolic_functions) - [Activation function, Wikipedia](https://en.wikipedia.org/wiki/Activation_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Mean Absolute Error (MAE) > Mean absolute error measures how far off a model's guesses are on average, counting each miss by its size only, so one wild miss does not dominate the score. Page: https://formulabro.yunusemrevurgun.com/ai-ml/mean-absolute-error/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \mathrm{MAE} = \frac{1}{n}\sum_{i=1}^{n} |y_i - \hat{y}_i| $$ Read it out loud: "M A E equals one over n, times the sum, for i from 1 to n, of the absolute value of y i minus y hat i." ## What each symbol means - $\mathrm{MAE}$: The mean absolute error: one number that sums up how far off the predictions are, on average. It is in the same units as the data. - $n$: How many predictions you are scoring. - $i$: The position of one prediction in the list, counting from 1 up to $n$. - $\sum_{i=1}^{n}$: "Add up for every $i$ from 1 to $n$": go through all the predictions and total the results. - $y_i$: The true value for case $i$, the answer you know is correct. - $\hat{y}_i$: The predicted value for case $i$, the model's guess. The hat over the $y$ is the usual sign for a prediction. - $|y_i - \hat{y}_i|$: The **absolute value** of the miss: its size with the sign removed. For example, $|-2| = 2$ and $|2| = 2$. ## What the formula is doing A model makes a guess $\hat{y}_i$ for each case, and the true value is $y_i$. The miss for one case is $y_i - \hat{y}_i$, which can be positive or negative. Mean absolute error removes the sign by taking the absolute value $|y_i - \hat{y}_i|$, then averages those sizes over all $n$ cases. Because the misses are not squared, each one counts in proportion to its size. A miss of 4 counts as 4, which is twice as much as a miss of 2. Mean squared error would count the miss of 4 as 16, four times the miss of 2. That gives MAE a gentler reaction to rare, very large errors, which are called outliers. MAE is the better choice when a few extreme values should not dominate the score, for example house prices in a data set with a few mansions. Its drawback is the sharp corner at zero, where the slope of the absolute value jumps from $-1$ to $+1$. Training methods that rely on smooth slopes handle this less neatly than they handle squared error. MAE is in the same units as the data. An MAE of 1.33 degrees means the average miss is 1.33 degrees. An MAE of 0 means every prediction was exact. ## An everyday picture Think of a delivery company judged on how many minutes late each parcel arrives. A parcel 10 minutes late counts 10 minutes, and a parcel 5 minutes late counts 5. MAE is the average of those minutes across all parcels. It treats a 10-minute delay as exactly twice as bad as a 5-minute delay, with no extra penalty for one huge delay. ## Worked example: The same temperatures as the MSE example Use the same three predictions as the mean squared error example. The true temperatures are $y = (3, 5, 2)$ and the predictions are $\hat{y} = (2, 6, 4)$, in degrees Celsius. Find the MAE, then see what a larger miss does to it. 1. Find each miss and its absolute value: $|3 - 2| = 1$, $|5 - 6| = 1$ and $|2 - 4| = 2$. 2. Add them: $1 + 1 + 2 = 4$. 3. Divide by $n = 3$: $\mathrm{MAE} = \frac{4}{3} \approx 1.33$. 4. Now suppose the third miss had been 10 degrees instead of 2. The absolute misses are $1$, $1$ and $10$, which total 12, so $\mathrm{MAE} = \frac{12}{3} = 4.0$. **Answer:** The MAE is about **1.33 degrees Celsius**, so the average prediction is off by about 1.3 degrees. The MSE for the same data was 2.0 square degrees. If the third miss grows to 10 degrees, the MAE rises to 4.0 while the MSE jumps to 34, so the squared score reacts much more strongly to one large error. ## Common mistakes - Averaging the misses without taking absolute values. Positive and negative misses cancel out, which can make a poor model look nearly perfect. - Forgetting to divide by $n$. The total grows with the number of cases, so scores from different test sets cannot be compared. - Assuming MAE punishes big misses the way MSE does. A miss of 10 counts only 10 times as much as a miss of 1 under MAE, but 100 times as much under MSE. - Comparing MAE values across problems with different units. An MAE of 1.3 degrees and an MAE of 1.3 dollars measure different things. ## Where you will meet it - Reporting forecast accuracy for demand, weather or energy, where an average miss is easy to explain. - Regression models where a few unusual values should not dominate the score, such as house prices. - Scoring predicted delivery or travel times, where each minute of error counts the same. - Training regression networks with the L1 loss, which is another name for MAE. ## Questions people ask ### Is MAE better than MSE? Neither is better in every case. MAE is easy to read and less upset by outliers. MSE punishes large misses harder, which can be the right choice when big errors are much worse than small ones. ### What is the difference between MAE and RMSE? RMSE is the square root of MSE. Both are in the units of the data, but RMSE weights large misses more heavily than MAE does. ### Why is MAE robust to outliers? Each miss enters the average in proportion to its size, not its square. One huge miss adds only its own size to the total, so it cannot take over the score the way it can with squared error. ## Related formulas - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) - [Huber Loss](https://formulabro.yunusemrevurgun.com/ai-ml/huber-loss/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Mean absolute error, Wikipedia](https://en.wikipedia.org/wiki/Mean_absolute_error) - [Mean squared error, Wikipedia](https://en.wikipedia.org/wiki/Mean_squared_error) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Huber Loss > Huber loss scores small misses by squaring them, as mean squared error does, and large misses with a straight-line penalty, so outliers cannot take over the score. Page: https://formulabro.yunusemrevurgun.com/ai-ml/huber-loss/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ L_{\delta}(a) = \begin{cases} \frac{1}{2} a^{2} & \text{if } |a| \le \delta \\ \delta \left(|a| - \frac{1}{2}\delta\right) & \text{otherwise} \end{cases} $$ Read it out loud: "L sub delta of a equals one half a squared if the size of a is at most delta. Otherwise it equals delta times the size of a, minus one half of delta." ## What each symbol means - $L_{\delta}(a)$: The **Huber loss** for one miss $a$: the penalty the model pays. It is in squared units of the data, the same kind of unit as mean squared error. - $a$: The **residual** (miss): the true value minus the prediction, $a = y - \hat{y}$. It is in the units of the data. - $\delta$: The **threshold** (the Greek letter delta), a positive number you choose. Misses no bigger than $\delta$ get the squared treatment, and bigger misses get the linear one. It is in the same units as $a$. - $|a|$: The **absolute value** of the miss: its size with the sign removed. ## What the formula is doing Mean squared error is smooth and easy to optimize, but one very wrong point can dominate it. Mean absolute error is robust to outliers, but its sharp corner at zero makes it awkward for some training methods. Huber loss tries to keep the strengths of both, and it does so with a single threshold $\delta$. Let $a = y - \hat{y}$ be the miss. If the miss is small, $|a| \le \delta$, the loss is $\frac{1}{2}a^{2}$, the same shape as squared error. If the miss is large, the loss switches to $\delta(|a| - \frac{1}{2}\delta)$, which grows in a straight line with $|a|$, the way absolute error does. The two pieces meet smoothly at $|a| = \delta$. Both give the value $\frac{1}{2}\delta^{2}$ there, and their slopes match too. That join means the function has no sharp corner, so gradient-based training works smoothly everywhere. The threshold $\delta$ sets the switch point. A small $\delta$ makes most misses count in a straight line, which is more robust to outliers. A large $\delta$ makes almost every miss count as squared, so the loss approaches mean squared error. Choose $\delta$ by trying a few values on held-out data. ## An everyday picture Think of a teacher grading essays. For small slips, the penalty grows faster as the slip grows, so each extra mistake costs more. For a really bad error, the penalty switches to a steady number of points per mistake, so one disaster does not wipe out the whole grade. ## Worked example: Two misses with a threshold of 1 A model's misses are $a = 0.5$ for one case and $a = 4$ for another, in the units of the data. Use $\delta = 1$ in the same units. Find the Huber loss for each miss and then the average. 1. Small miss: $|0.5| = 0.5 \le 1$, so use the squared piece. $\frac{1}{2}(0.5)^{2} = 0.125$. 2. Large miss: $|4| = 4 > 1$, so use the linear piece. $1 \times \left(4 - \frac{1}{2} \times 1\right) = 3.5$. 3. Average the two losses: $\frac{0.125 + 3.5}{2} = 1.8125$. 4. For comparison, pure squared error with the same $\frac{1}{2}$ factor would charge $\frac{1}{2}(4)^{2} = 8$ for the large miss. **Answer:** The average Huber loss is **1.8125**. The large miss costs 3.5 here instead of 8, so one outlier does not take over the score. The small miss is still scored smoothly as a squared error. ## Common mistakes - Using the squared piece for every miss. Huber loss switches to the linear piece once $|a|$ is larger than $\delta$. - Dropping the $\frac{1}{2}$ in either piece. Without it the two pieces no longer meet at $|a| = \delta$, and the loss stops being smooth there. - Choosing $\delta$ without looking at the data. The right threshold depends on the size of typical misses, and the same number means different things in different units. - Mixing the units of $\delta$ and $a$. The threshold must be in the same units as the misses, or the switch point lands in the wrong place. ## Where you will meet it - Robust regression, where a few outliers in the data should not pull the fitted line too far. - Training object detectors to predict box coordinates, where smooth L1 losses, a Huber-style form, are common. - Reinforcement learning, where a Huber loss is often applied to temporal-difference errors to limit the effect of large surprises. - Predicting prices or durations in data sets that contain a few extreme values. ## Questions people ask ### What is a good value for delta? There is no single right value. Pick it in the same units as your data, based on what counts as a normal miss. Many people try several values and keep the one that works best on held-out data. ### Is Huber loss the same as smooth L1 loss? They are closely related. Smooth L1 uses the same two pieces with $\delta = 1$, which makes it a common special case of the Huber loss. ### Why not use MAE instead? MAE has a sharp corner at zero, which makes gradient-based training less smooth. Huber loss keeps MAE's robustness for large misses and stays smooth near zero. ## Related formulas - [Mean Absolute Error (MAE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-absolute-error/) - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Huber loss, Wikipedia](https://en.wikipedia.org/wiki/Huber_loss) - [Loss function, Wikipedia](https://en.wikipedia.org/wiki/Loss_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Hinge Loss > Hinge loss gives no penalty to an answer that is correct with room to spare, and a growing penalty as an answer gets wrong or too close to the boundary. Page: https://formulabro.yunusemrevurgun.com/ai-ml/hinge-loss/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ L = \max(0,\ 1 - y\, f(x)) $$ Read it out loud: "L equals the larger of zero and one minus y times f of x." ## What each symbol means - $L$: The **hinge loss** for one example: the penalty, which is never below zero. It is zero when the example is correct and far enough from the boundary. - $y$: The **true label**, either $+1$ or $-1$. Those two values name the two classes. - $f(x)$: The model's **raw score** for the input $x$. Its sign gives the predicted class: positive means $+1$, negative means $-1$. Its size shows how confident the model is. - $1$: The **margin**: a correct point should have a score of at least 1 in the right direction, not merely a positive one. - $\max$: Takes the larger of the numbers inside the brackets, so any negative result is cut off to 0. ## What the formula is doing A support vector machine is a classifier that separates two classes with a boundary that leaves the widest possible gap between them, called the margin. Hinge loss is the penalty it uses while learning. The labels are $y = +1$ or $y = -1$, and the model computes a raw score $f(x)$ for each input. Positive scores lean toward $+1$ and negative scores lean toward $-1$. Multiply the label by the score to get $y f(x)$. When the sign of $f(x)$ matches $y$ and the score is at least 1 in size, $y f(x) \ge 1$, so $1 - y f(x) \le 0$ and the loss is $\max(0, 1 - y f(x)) = 0$. The point is correct and far enough from the boundary, so no penalty applies. When the point is correct but too close to the boundary, $0 < y f(x) < 1$, the loss is positive but small. When the point is on the wrong side, $y f(x) < 0$, the loss is greater than 1 and grows in a straight line as the score moves further the wrong way. Hinge loss therefore asks for more than a correct sign: it asks for a margin. The loss is convex, so training it has no bad local minima to get stuck in. It has a sharp corner at $y f(x) = 1$, where the slope jumps, which makes it less smooth than squared error. It is the standard loss for linear support vector machines, and variants of it appear in other models. ## An everyday picture Think of a line judge in tennis who checks which side of the line a ball lands on. A ball that lands comfortably inside the line earns no penalty. A ball that lands right on the line counts as a small problem. A ball that lands outside is a fault, and the farther outside it lands, the bigger the fault. ## Worked example: Three points near an SVM boundary An SVM gives raw scores to three points. Their true labels are $y = +1$, $y = +1$ and $y = -1$, and their scores are $f(x) = 2.0$, $f(x) = 0.3$ and $f(x) = 0.5$. Find the hinge loss of each point and then the average. 1. Point 1: $y f(x) = (+1)(2.0) = 2.0$, so $1 - 2.0 = -1.0$ and $\max(0, -1.0) = 0$. It is correct and beyond the margin, so there is no penalty. 2. Point 2: $y f(x) = (+1)(0.3) = 0.3$, so $1 - 0.3 = 0.7$ and $\max(0, 0.7) = 0.7$. It is on the correct side but inside the margin. 3. Point 3: $y f(x) = (-1)(0.5) = -0.5$, so $1 - (-0.5) = 1.5$ and $\max(0, 1.5) = 1.5$. It is on the wrong side of the boundary. 4. Average the three losses: $\frac{0 + 0.7 + 1.5}{3} \approx 0.733$. **Answer:** The average hinge loss is about **0.733**. The first point costs nothing. The second is on the correct side but too close, so it costs 0.7. The third is on the wrong side and costs 1.5, the largest penalty of the three. ## Common mistakes - Using labels of 0 and 1. Hinge loss needs labels of $-1$ and $+1$, and with 0 and 1 the sign test gives wrong results. - Leaving out the $\max(0, \cdot)$ step. Without it, a correct point with a large margin gets a negative loss, which rewards it without limit. - Reading the raw score as a probability. The score $f(x)$ is not between 0 and 1, and hinge loss does not produce probabilities. - Assuming a loss of 0 means the model is perfect. Zero means only that this point is correct with a margin of at least 1, not that every point is correct. ## Where you will meet it - Training linear support vector machines for classification, where hinge loss is the standard loss. - Kernel support vector machines, which apply the same loss in a transformed feature space. - Margin-based ranking and retrieval models, where a matching pair should score above a non-matching pair by a set margin. - Some neural network classifiers, which use a hinge loss at the output in place of cross-entropy. ## Questions people ask ### Why are the labels -1 and +1 instead of 0 and 1? The product $y f(x)$ needs the sign of the label to match the sign of the score. With labels of $-1$ and $+1$, a correct prediction gives a positive product and a wrong one gives a negative product. ### How does hinge loss differ from logistic loss? Hinge loss is exactly zero for any point beyond the margin, so it ignores easy points. Logistic loss never reaches zero, so it keeps pushing a little on every point. Hinge loss also gives no probabilities. ### Why is the margin 1? It is a scaling convention. Multiplying the weights and the score by the same factor changes the margin, so fixing it at 1 is a choice of units. The geometry of the boundary is what matters. ## Related formulas - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Logistic Regression](https://formulabro.yunusemrevurgun.com/ai-ml/logistic-regression/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) - [L2 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization/) ## Sources - [Hinge loss, Wikipedia](https://en.wikipedia.org/wiki/Hinge_loss) - [Support vector machine, Wikipedia](https://en.wikipedia.org/wiki/Support_vector_machine) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # L2 Regularization > L2 regularization adds a penalty for large weights, so the model prefers small, gentle weights that tend to generalize better to new data. Page: https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ J(w) = L(w) + \lambda \sum_{j} w_j^{2} $$ Read it out loud: "J of w equals L of w, plus lambda times the sum, over j, of w j squared." ## What each symbol means - $J(w)$: The **total cost** that training tries to make small: the data loss plus the penalty. - $L(w)$: The **data loss**: how wrong the model is on the training examples. It can be any loss, such as squared error or cross-entropy. - $\lambda$: The **regularization strength** (the Greek letter lambda), a number you choose that is zero or more. Zero means no penalty, and a bigger value pulls the weights harder toward zero. - $\sum_{j}$: "Add up for every weight $j$": the sum runs over all the weights in the model. - $w_j$: One weight in the model, the number that scales input number $j$. - $w$: The whole list of weights, $w = (w_1, w_2, \ldots)$. ## What the formula is doing A model fitted only to its training data can memorize noise. It may draw a wiggly curve through every point, with large weights that chase each bump. Such a model does well on the data it has seen and badly on new data. This is called overfitting. Regularization fixes this by adding a penalty to the loss. The L2 penalty is $\lambda \sum_{j} w_j^{2}$: square each weight, add up the squares, and multiply by $\lambda$. Large weights now cost a lot, so training has to balance fitting the data against keeping the weights small. Squaring makes the penalty grow fast for big weights. A weight of 4 costs 16 times as much penalty as a weight of 1, so the pressure falls hardest on the largest weights. During training this shows up as **weight decay**: each update shrinks every weight a little toward zero, in proportion to its size, before the data pulls it back. The main decision is the strength $\lambda$. If $\lambda$ is zero, you get the plain model. If it is too large, the weights are squeezed so hard that the model underfits and misses real patterns. Try several values and keep the one that does best on validation data. For linear regression, L2 regularization is known as ridge regression. ## An everyday picture Think of a student who studies by memorizing last year's answer key. A tutor adds a rule: any study method that depends on very strong, specific shortcuts costs points. The student now spreads effort more evenly across the material, so the skill carries over to new questions. The penalty stops the model from leaning too hard on any single input. ## Worked example: Comparing two models with an L2 penalty Model A has weights $w = (2, -0.5)$ and data loss $L = 0.30$. Model B has weights $w = (1, -0.5)$ and data loss $L = 0.35$. Use $\lambda = 0.1$. Which model has the lower total cost $J(w)$? 1. Model A: the sum of squared weights is $2^{2} + (-0.5)^{2} = 4.25$. 2. Model A penalty: $0.1 \times 4.25 = 0.425$, so $J = 0.30 + 0.425 = 0.725$. 3. Model B: the sum of squared weights is $1^{2} + (-0.5)^{2} = 1.25$. 4. Model B penalty: $0.1 \times 1.25 = 0.125$, so $J = 0.35 + 0.125 = 0.475$. **Answer:** Model B has the lower total cost, **0.475** against **0.725**. Model A fits the training data slightly better, but its large weight costs more than the extra fit is worth, so the penalty prefers the smaller weights of Model B. ## Common mistakes - Setting $\lambda$ too large. A huge penalty crushes all the weights toward zero, and the model underfits, doing badly even on the training data. - Penalizing the bias term along with the weights. The bias sets the level of the output and is usually left out of the penalty. - Comparing total costs as if they were pure data losses. The total includes the penalty, so compare the data loss separately when you want to judge the fit. - Skipping input scaling. The penalty treats every weight equally, so inputs measured on very different scales get penalized unevenly. ## Where you will meet it - Ridge regression, the linear regression version with an L2 penalty, which stays stable when inputs are strongly correlated. - Neural networks, where the same penalty is applied during training under the name weight decay. - Logistic regression and linear support vector machines, where the penalty keeps the boundary from relying on a single feature. - Smoothing flexible models such as polynomial fits, where the penalty limits wiggles in the curve. ## Questions people ask ### What is the difference between L2 and L1 regularization? L2 penalizes squared weights and shrinks all of them toward zero, usually without making any exactly zero. L1 penalizes absolute weights and can push some weights to exactly zero. ### Why is it called weight decay? Each training step multiplies the weights by a factor slightly less than 1 before the data update. Over time the weights decay toward zero unless the data keeps them large. ### Is a larger lambda always better? No. A lambda that is too large underfits, and one that is too small allows overfitting. The best value sits in between and is found with validation data. ## Related formulas - [L1 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l1-regularization/) - [Linear Regression](https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Tikhonov regularization, Wikipedia](https://en.wikipedia.org/wiki/Tikhonov_regularization) - [Ridge regression, Wikipedia](https://en.wikipedia.org/wiki/Ridge_regression) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # L1 Regularization > L1 regularization adds a penalty proportional to each weight's size, which encourages the model to drop unneeded inputs by setting their weights to exactly zero. Page: https://formulabro.yunusemrevurgun.com/ai-ml/l1-regularization/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ J(w) = L(w) + \lambda \sum_{j} |w_j| $$ Read it out loud: "J of w equals L of w, plus lambda times the sum, over j, of the absolute value of w j." ## What each symbol means - $J(w)$: The **total cost** that training tries to make small: the data loss plus the penalty. - $L(w)$: The **data loss**: how wrong the model is on the training examples. It can be any loss, such as squared error or cross-entropy. - $\lambda$: The **regularization strength** (the Greek letter lambda), a number you choose that is zero or more. Zero means no penalty, and a bigger value pulls the weights harder toward zero. - $\sum_{j}$: "Add up for every weight $j$": the sum runs over all the weights in the model. - $|w_j|$: The **absolute value** of weight number $j$: its size with the sign removed. For example, $|-0.5| = 0.5$ and $|2| = 2$. - $w$: The whole list of weights, $w = (w_1, w_2, \ldots)$. ## What the formula is doing Like L2, L1 regularization adds a penalty to the loss so the model does not fit noise. Here the total cost is $J(w) = L(w) + \lambda \sum_{j} |w_j|$. The data loss $L(w)$ measures the fit, and $\lambda$ sets how strong the penalty is. The penalty is the sum of the absolute values of the weights, which is called the L1 norm of the weights. The difference from L2 is the shape of the penalty. L2 charges by the square, so the charge for a small weight is tiny and the pull toward zero fades as the weight shrinks. L1 charges by the absolute value, so every nonzero weight feels the same steady pull toward zero, whether it is big or small. That steady pull can push a weight all the way to exactly zero. Once a weight reaches zero and the data does not pull it back out, it stays there, and the input it multiplies is effectively removed from the model. L1 therefore doubles as feature selection: the weights that survive are the ones the data really needs. The price is the sharp corner at zero, where the slope of the penalty jumps from $-1$ to $+1$. Training handles that corner with a subgradient or a proximal step. For linear regression, L1 regularization is known as the **lasso**, short for least absolute shrinkage and selection operator. The strength $\lambda$ still matters: too large and every weight is zeroed, too small and nothing is removed. ## An everyday picture Think of a budget where every minute a player spends on the field costs the same flat fee, however good the player is. The coach benches anyone whose contribution is not worth the fee, and some players end up with zero minutes. L1 works the same way on weights: every unit of weight costs the same, so weak inputs can drop to exactly zero. ## Worked example: The same two models with an L1 penalty Use the same two models as the L2 example. Model A has $w = (2, -0.5)$ and data loss $L = 0.30$. Model B has $w = (1, -0.5)$ and data loss $L = 0.35$. Use $\lambda = 0.1$ and compare the total cost with the L1 penalty. 1. Model A: the sum of absolute weights is $|2| + |-0.5| = 2.5$. 2. Model A penalty: $0.1 \times 2.5 = 0.25$, so $J = 0.30 + 0.25 = 0.55$. 3. Model B: the sum of absolute weights is $|1| + |-0.5| = 1.5$. 4. Model B penalty: $0.1 \times 1.5 = 0.15$, so $J = 0.35 + 0.15 = 0.50$. **Answer:** Model B has the lower total cost, **0.50** against **0.55**. The L1 penalty charges a flat rate per unit of weight, so the gap between the two models is smaller than it was with the squared penalty of L2. ## Common mistakes - Squaring the weights, which turns the penalty into L2. The L1 penalty uses absolute values, with no square. - Expecting L1 to shrink every weight by the same ratio. It shrinks each nonzero weight by a fixed amount and can remove the weak ones entirely. - Putting the bias term in the penalty. As with L2, the bias is usually left out. - Reading a zero weight as proof that the feature is useless. Correlated inputs can compete, and L1 may keep one of them and zero out another that carries the same information. ## Where you will meet it - The lasso, the linear regression version with an L1 penalty, used when you want a model that depends on only a few inputs. - Feature selection on data with thousands of columns, such as gene measurements or word counts, where most inputs are irrelevant. - Compressing neural networks by pruning, where many weights are set to zero to make the model smaller. - Compressed sensing and sparse signal recovery, where the L1 norm favors solutions with few nonzero parts. ## Questions people ask ### Why does L1 set weights to exactly zero but L2 usually does not? The L1 penalty has a constant slope away from zero, so its pull stays the same as a weight gets small and can reach zero. The L2 pull fades as the weight shrinks, so weights get close to zero without landing on it. ### Should I use L1 or L2? Use L1 when you suspect many inputs are useless and want a smaller model. Use L2 when you expect many inputs to matter a little and you want stable, shrunken weights. Testing both on validation data is common practice. ### What is the lasso? The lasso is linear regression with an L1 penalty. Its name stands for least absolute shrinkage and selection operator, which describes both the shrinking and the selection of inputs. ## Related formulas - [L2 Regularization](https://formulabro.yunusemrevurgun.com/ai-ml/l2-regularization/) - [Linear Regression](https://formulabro.yunusemrevurgun.com/ai-ml/linear-regression/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Lasso (statistics), Wikipedia](https://en.wikipedia.org/wiki/Lasso_%28statistics%29) - [Regularization (mathematics), Wikipedia](https://en.wikipedia.org/wiki/Regularization_%28mathematics%29) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Momentum Optimizer > Momentum lets gradient descent remember its recent steps, so it speeds up where the slope keeps pointing the same way and wobbles less where it flips. Page: https://formulabro.yunusemrevurgun.com/ai-ml/momentum-optimizer/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ v_t = \beta \, v_{t-1} + \nabla L(\theta_{t-1}) \qquad \theta_t = \theta_{t-1} - \eta \, v_t $$ Read it out loud: "v sub t equals beta times v sub t minus 1, plus the gradient of L at theta sub t minus 1. Then theta sub t equals theta sub t minus 1, minus eta times v sub t." ## What each symbol means - $\theta$: The settings the model learns, such as its weights and biases. Training adjusts them. - $\theta_{t-1}$: The settings before step $t$. The slope is measured here. - $\theta_t$: The settings after step $t$. - $L$: The loss function, which scores how wrong the model is at a given set of settings. Lower is better. - $\nabla L(\theta_{t-1})$: The gradient of the loss at the settings before step $t$: the slope, which points the way the loss rises fastest. - $\eta$: The learning rate, a small positive number that sets how far the settings move for each unit of velocity. - $\beta$: The momentum coefficient, a number from 0 to 1 that sets how much of the old velocity is kept. A common starting value is 0.9. - $v_t$: The velocity after step $t$: a running total of recent gradients, with newer gradients counting most. It has the same units as the gradient. - $v_{t-1}$: The velocity before step $t$. It starts at zero. ## What the formula is doing Plain gradient descent moves by the slope at the current spot and nothing else. On a long, narrow valley the slope points mostly across the valley, so the steps zigzag from wall to wall while the progress along the valley is slow. Momentum fixes this by keeping a velocity $v$ that remembers past steps. The first line of the formula updates the velocity. The old velocity $v_{t-1}$ is multiplied by $\beta$, so it fades slowly, and the new slope $\nabla L(\theta_{t-1})$ is added to it. Steps that keep pointing the same way add up, so the velocity grows. The second line moves the settings. The velocity is multiplied by the learning rate $\eta$ and subtracted from the current settings, the same minus sign as in plain gradient descent. Across the valley the pushes point in opposite directions and cancel out. Along the valley they agree and add up, which is why the zigzag shrinks. Some books write the update slightly differently. One version scales the gradient by $(1 - \beta)$ inside the velocity. Another puts $\eta$ inside the velocity and drops it from the last line. These give the same direction of motion and differ only in the size of the learning rate. Check which form a library uses before you copy a learning rate from a different source. ## An everyday picture Think of a heavy ball rolling down a bowl. The ball does not turn sharply at every small bump. It builds speed while it keeps rolling downhill, and it carries on through shallow ripples that would stop a lighter object. The friction in the formula, the factor $\beta$ below 1, keeps the ball from speeding up forever. ## Worked example: Two steps on a bowl with momentum Use the loss $L(\theta) = (\theta - 3)^2$ from the gradient descent page, so the gradient is $\nabla L(\theta) = 2(\theta - 3)$. Start at $\theta_0 = 0$ with velocity $v_0 = 0$, momentum $\beta = 0.9$ and learning rate $\eta = 0.1$. All values are unitless. 1. Step 1: the gradient at $\theta_0 = 0$ is $2(0 - 3) = -6$. The velocity is $v_1 = 0.9 \times 0 + (-6) = -6$. The settings move to $\theta_1 = 0 - 0.1 \times (-6) = 0.6$. 2. Step 2: the gradient at $\theta_1 = 0.6$ is $2(0.6 - 3) = -4.8$. The velocity is $v_2 = 0.9 \times (-6) + (-4.8) = -10.2$. The settings move to $\theta_2 = 0.6 - 0.1 \times (-10.2) = 1.62$. 3. Step 3: the gradient at $\theta_2 = 1.62$ is $2(1.62 - 3) = -2.76$. The velocity is $v_3 = 0.9 \times (-10.2) + (-2.76) = -11.94$. The settings move to $\theta_3 = 1.62 - 0.1 \times (-11.94) = 2.814$. **Answer:** After two steps the settings are at $\theta_2 = 1.62$. Plain gradient descent with the same learning rate reached $1.08$ in two steps, so momentum is ahead. After three steps the settings are at $2.814$, close to the lowest point at 3. The velocity grows because each gradient points the same way. ## Common mistakes - Using only the new gradient and forgetting the old velocity. Each step must multiply the old velocity by $\beta$ and add the new gradient to it. - Setting $\beta$ very close to 1, such as 0.999. The velocity then builds up for a long time and can overshoot the lowest point, then swing back. - Copying a learning rate from a book that scales the gradient by $(1 - \beta)$ or puts $\eta$ inside the velocity. The same number then gives a different step size in this form. - Expecting momentum to cure a learning rate that is far too big. The steps still overshoot, and the velocity can make the overshoot larger. ## Where you will meet it - Training deep neural networks, where stochastic gradient descent with momentum is a standard option in deep learning libraries. - Training convolutional networks for image recognition, a common setting for the momentum coefficient near 0.9. - Problems with long, narrow valleys in the loss, where plain gradient descent zigzags and makes slow progress. - Adam and related optimizers, which keep a running average of the gradient in a form close to momentum. ## Questions people ask ### Is momentum the same as the learning rate? No. The learning rate $\eta$ sets how big each step is. Momentum $\beta$ sets how much of the past steps carries forward. The two work together, so changing one often means adjusting the other. ### What value should beta be? A common starting value is 0.9. Values closer to 0 act more like plain gradient descent. Values closer to 1 keep more of the past velocity. ### Does momentum guarantee the lowest point? No. On a bumpy landscape it can still settle into a low point that is not the lowest one. On a simple bowl it reaches the bottom when the steps are small enough. ### Why does momentum help in a narrow valley? The sideways pushes point in opposite directions from one step to the next, so they cancel in the velocity. The push along the valley points the same way every step, so it adds up. ## Related formulas - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) - [Adam Optimizer](https://formulabro.yunusemrevurgun.com/ai-ml/adam-optimizer/) - [Backpropagation and the Chain Rule](https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule/) ## Sources - [Why Momentum Really Works, Distill (2017)](https://distill.pub/2017/momentum/) - [Stochastic gradient descent, Wikipedia](https://en.wikipedia.org/wiki/Stochastic_gradient_descent) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Adam Optimizer > Adam keeps a running average of each setting's slope and of how big those slopes have been, then uses both to choose a step size for every setting. Page: https://formulabro.yunusemrevurgun.com/ai-ml/adam-optimizer/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \theta_t = \theta_{t-1} - \eta \, \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon} $$ Read it out loud: "Theta sub t equals theta sub t minus 1, minus eta times m-hat sub t, divided by the square root of v-hat sub t, plus epsilon." ## What each symbol means - $\theta_t$: The settings of the model after step $t$. The step counter $t$ starts at 1. - $\theta_{t-1}$: The settings before step $t$. - $\eta$: The learning rate, the base size of each step. The Adam paper suggests 0.001 as a starting value. - $\hat m_t$: The bias-corrected average of the gradient, a running average that shows the direction the slope has been pointing. - $\hat v_t$: The bias-corrected average of the squared gradient, a running average that shows how large the slopes have been. - $\epsilon$: A tiny positive number, about $10^{-8}$, added to the denominator so the step never divides by zero. - $m_t$: The running average of the gradient, before bias correction. It is also written with $\beta_1$ and $g_t$ in the explanation below. - $v_t$: The running average of the squared gradient, before bias correction. - $g_t$: The gradient at step $t$, the slope of the loss at the settings $\theta_{t-1}$. - $\beta_1$: The decay rate for the gradient average, usually 0.9. - $\beta_2$: The decay rate for the squared-gradient average, usually 0.999. ## What the formula is doing Adam keeps two running averages for every setting. The first, $m_t$, is an average of the gradients, so it shows which way the slope has been pointing. The second, $v_t$, is an average of the squared gradients, so it shows how large the slopes have been. They are updated as $m_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t$ and $v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2$, where $g_t$ is the gradient at step $t$. Both averages start at zero, so early on they are too small. The bias correction fixes this: $\hat m_t = m_t / (1 - \beta_1^t)$ and $\hat v_t = v_t / (1 - \beta_2^t)$. The denominators are small at the start and approach 1 as $t$ grows, so the correction matters mostly for the first steps. The update line divides the averaged gradient $\hat m_t$ by the square root of the averaged squared gradient, $\sqrt{\hat v_t}$. Each setting therefore moves by roughly the size of $\eta$, whatever the raw size of its gradient was. Settings with steady, large slopes do not take huge steps, and settings with small slopes still move. The tiny $\epsilon$ only stops a division by zero. The Adam paper by Kingma and Ba reports the defaults $\beta_1 = 0.9$, $\beta_2 = 0.999$ and $\epsilon = 10^{-8}$, with $\eta = 0.001$, as good settings for the problems it tested. Many libraries use the same defaults. They are a starting point, not a guarantee of the best result on a new problem. ## An everyday picture Picture a driver who remembers two things about the road: which way it has been bending, and how bumpy the ride has been. On a smooth stretch the driver steers firmly. On a rough stretch the driver takes smaller, careful steps. Adam gives each setting in the model its own memory of how bumpy its road has been. ## Worked example: Two steps on one setting Use the loss $L(\theta) = (\theta - 3)^2$ again, so $g = 2(\theta - 3)$. Start at $\theta_0 = 0$ with $m_0 = 0$ and $v_0 = 0$. Use the defaults $\beta_1 = 0.9$, $\beta_2 = 0.999$ and $\epsilon = 10^{-8}$, and a learning rate $\eta = 0.1$ so the numbers stay easy to follow. All values are unitless. 1. Step 1: the gradient at $\theta_0 = 0$ is $g_1 = 2(0 - 3) = -6$. The averages are $m_1 = 0.9 \times 0 + 0.1 \times (-6) = -0.6$ and $v_1 = 0.999 \times 0 + 0.001 \times 36 = 0.036$. 2. Bias correction for step 1: $\hat m_1 = -0.6 / (1 - 0.9) = -6$ and $\hat v_1 = 0.036 / (1 - 0.999) = 36$. 3. Update for step 1: $\theta_1 = 0 - 0.1 \times (-6) / (\sqrt{36} + 10^{-8}) \approx 0.1$. The first step moves by almost exactly the learning rate, because $\hat m_1 / \sqrt{\hat v_1} = -1$. 4. Step 2: the gradient at $\theta_1 = 0.1$ is $g_2 = 2(0.1 - 3) = -5.8$. The averages are $m_2 = 0.9 \times (-0.6) + 0.1 \times (-5.8) = -1.12$ and $v_2 = 0.999 \times 0.036 + 0.001 \times 33.64 = 0.069604$. 5. Bias correction for step 2: $\hat m_2 = -1.12 / (1 - 0.81) \approx -5.8947$ and $\hat v_2 = 0.069604 / (1 - 0.998001) \approx 34.8194$. 6. Update for step 2: $\theta_2 = 0.1 - 0.1 \times (-5.8947) / (\sqrt{34.8194} + 10^{-8}) \approx 0.1 + 0.0999 = 0.1999$. **Answer:** After two steps the setting is $\theta_2 \approx 0.1999$. Both steps are about the size of $\eta = 0.1$, even though the raw gradient was 6 at step 1 and 5.8 at step 2. Adam sets the size from the ratio of the averaged gradient to its typical size, not from the raw gradient alone. ## Common mistakes - Skipping the bias correction. Because $m_t$ and $v_t$ start at zero, the early steps come out much too small without it. - Expecting every step to be exactly $\eta$. The step is about $\eta$ only when the gradients are steady. Noisy gradients make $\hat m_t$ small compared with $\sqrt{\hat v_t}$, and the step shrinks. - Setting $\epsilon$ too large. When $\sqrt{\hat v_t}$ is small, a big $\epsilon$ dominates the denominator and quietly shrinks every step, most of all for settings with small gradients. - Keeping the default learning rate without checking it. The defaults come from the paper's test problems and are a starting point, not a rule for every model. ## Where you will meet it - Training transformers and large language models, where Adam or a close variant such as AdamW is a common choice. - Training image and speech models, including many deep convolutional networks. - Deep learning libraries, where Adam is one of the built-in optimizers. - Fine-tuning pretrained models, where a small learning rate and Adam are often used together. ## Questions people ask ### Why is it called Adam? The name comes from adaptive moment estimation. The first moment is the averaged gradient and the second is the averaged squared gradient. ### Does Adam always beat plain gradient descent? No. Adam often trains quickly with little tuning, but on some problems plain stochastic gradient descent with momentum reaches a better final result. Try both when the model matters. ### What is the difference between m and v? $m_t$ is the average of the gradient itself, which carries the direction. $v_t$ is the average of the squared gradient, which carries the size. Adam uses both. ### Do I need to change beta_1 and beta_2? Usually not at first. The defaults 0.9 and 0.999 are the starting point in most libraries. ## Related formulas - [Momentum Optimizer](https://formulabro.yunusemrevurgun.com/ai-ml/momentum-optimizer/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) - [Backpropagation and the Chain Rule](https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule/) ## Sources - [Adam: A Method for Stochastic Optimization, Kingma and Ba (arXiv:1412.6980)](https://arxiv.org/abs/1412.6980) - [Stochastic gradient descent, Wikipedia](https://en.wikipedia.org/wiki/Stochastic_gradient_descent) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Backpropagation and the Chain Rule > Backpropagation finds how much each weight affects the error by multiplying the small slopes along the chain from the weight to the loss. Page: https://formulabro.yunusemrevurgun.com/ai-ml/backpropagation-chain-rule/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \frac{\partial L}{\partial w} = \frac{\partial L}{\partial \hat y} \, \frac{\partial \hat y}{\partial z} \, \frac{\partial z}{\partial w} $$ Read it out loud: "The partial derivative of L with respect to w equals the partial derivative of L with respect to y-hat, times the partial derivative of y-hat with respect to z, times the partial derivative of z with respect to w." ## What each symbol means - $L$: The loss, a single number that scores how wrong the prediction is. Lower is better. - $\frac{\partial L}{\partial w}$: How much the loss changes when $w$ changes a little, with every other setting held fixed. Gradient descent uses this slope to update $w$. - $x$: The input to the neuron, a number that is given to it. - $w$: The weight, a setting of the neuron that training adjusts. - $b$: The bias, a second setting that is added to the weighted input. - $z$: The weighted sum before the activation, $z = wx + b$. It is also called the pre-activation. - $\hat y$: The prediction, the neuron's output after the sigmoid: $\hat y = \sigma(z)$. It is a number between 0 and 1. - $y$: The target, the correct answer the neuron should output. The example uses $y = 1$. - $\sigma$: The sigmoid function, $\sigma(z) = 1 / (1 + e^{-z})$. Its slope is $\sigma(z)(1 - \sigma(z))$. - $\frac{\partial \hat y}{\partial z}$: How much the prediction changes when the weighted sum changes a little. - $\frac{\partial z}{\partial w}$: How much the weighted sum changes when the weight changes a little. For $z = wx + b$ it equals the input $x$. ## What the formula is doing A neural network is a chain of simple steps. Here one neuron takes an input $x$, forms $z = wx + b$, and passes $z$ through a sigmoid to get a prediction $\hat y$. The loss $L$ depends on $\hat y$, $\hat y$ depends on $z$, and $z$ depends on $w$. To learn, training needs to know how the loss changes when $w$ changes. Backpropagation answers that by following the chain backward. The chain rule from calculus says that when one quantity depends on a second, which depends on a third, the slopes multiply. The first factor, $\partial L / \partial \hat y$, is how fast the loss changes with the prediction. The second, $\partial \hat y / \partial z$, is how fast the prediction changes with the weighted sum. The third, $\partial z / \partial w = x$, is how fast the weighted sum changes with the weight. For the squared error $L = (\hat y - y)^2$ and a sigmoid output, the three factors are $2(\hat y - y)$, $\sigma(z)(1 - \sigma(z))$ and $x$. Each one is a short formula. Their product is the gradient for $w$. The bias $b$ is handled the same way, except that its last factor is $\partial z / \partial b = 1$ instead of $x$. A network with many layers repeats the same idea. The slope at the output is passed backward one layer at a time, and each layer multiplies it by its own local slope. Every layer reuses the result from the layer after it, which is why the method is efficient. The resulting slopes are then fed to gradient descent, which updates the weights. ## An everyday picture Think of a row of gears. Turn the first gear and the second turns by its ratio, and the third turns by its own ratio. To find how far the last gear moves when you turn the first, multiply the ratios along the chain. Backpropagation does the same with slopes: it multiplies the small effect of each step to find the effect of one weight on the final loss. ## Worked example: One sigmoid neuron with squared error Input $x = 2$, weight $w = 0.5$, bias $b = -0.5$, target $y = 1$. The neuron computes $z = wx + b$ and $\hat y = \sigma(z)$, and the loss is $L = (\hat y - y)^2$. Use a learning rate of $0.1$. Everything is unitless. 1. Forward pass: $z = 0.5 \times 2 + (-0.5) = 0.5$. Then $\hat y = \sigma(0.5) = 1 / (1 + e^{-0.5}) \approx 0.6225$. The loss is $L = (0.6225 - 1)^2 \approx 0.1425$. 2. First factor: $\frac{\partial L}{\partial \hat y} = 2(\hat y - y) = 2(0.6225 - 1) \approx -0.7551$. 3. Second factor: $\frac{\partial \hat y}{\partial z} = \hat y (1 - \hat y) = 0.6225 \times 0.3775 \approx 0.2350$. 4. Third factor: $\frac{\partial z}{\partial w} = x = 2$. 5. Multiply the three: $\frac{\partial L}{\partial w} = (-0.7551) \times 0.2350 \times 2 \approx -0.3549$. 6. One gradient descent update: $w_{\text{new}} = 0.5 - 0.1 \times (-0.3549) \approx 0.5355$. With the new weight the loss is about $0.1303$, lower than $0.1425$. **Answer:** The gradient is negative, so increasing $w$ lowers the loss. The update raises the weight from 0.5 to about 0.5355 and the loss falls from about 0.1425 to 0.1303. Raising $w$ raises $z$, which moves $\hat y$ closer to the target 1. ## Common mistakes - Leaving out a factor. The three slopes form a chain, so all three must be multiplied. The last factor is $x$ for the weight, not 1. - Using the wrong sigmoid slope. The derivative of $\sigma$ is $\sigma(z)(1 - \sigma(z))$, not $\sigma(z)$ alone. - Using the weight's chain for the bias without changing the last factor. For the bias, $\partial z / \partial b = 1$. - Applying the gradient with the wrong sign. The gradient here is negative, and the minus sign in gradient descent turns that into an increase of $w$. ## Where you will meet it - Training every layer of a neural network, from one neuron to models with billions of weights. - Automatic differentiation in deep learning libraries such as PyTorch and TensorFlow, which apply the chain rule for you. - Computing the gradients that gradient descent uses to update the weights. - Recurrent networks and transformers, where the chain runs through many time steps or layers. ## Questions people ask ### Why is it called backpropagation? The error is passed backward through the network, from the loss toward the inputs, one layer at a time. Each step multiplies the slopes it passes through. ### Is the chain rule the same as backpropagation? No. The chain rule is a fact of calculus. Backpropagation is the method that applies it to a network and reuses intermediate results, so the work stays efficient. ### Why does the sigmoid slope matter? When $z$ is very large or very small, the sigmoid is nearly flat, so its slope is close to 0. Multiplying by a tiny slope shrinks the gradient, which can slow learning in deep networks. ### Do I have to compute these by hand? Usually not. Libraries compute them automatically. Working through one neuron by hand shows what the library does behind the scenes. ## Related formulas - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) ## Sources - [Backpropagation, Wikipedia](https://en.wikipedia.org/wiki/Backpropagation) - [Chain rule, Wikipedia](https://en.wikipedia.org/wiki/Chain_rule) - [Sigmoid function, Wikipedia](https://en.wikipedia.org/wiki/Sigmoid_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Batch Normalization > Batch normalization rescales the values in a group of examples so they are centered near zero with a steady spread, then lets the network choose its own scale and offset. Page: https://formulabro.yunusemrevurgun.com/ai-ml/batch-normalization/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \hat x_i = \frac{x_i - \mu_B}{\sqrt{\sigma_B^2 + \epsilon}} \qquad y_i = \gamma \, \hat x_i + \beta $$ Read it out loud: "x-hat sub i equals x sub i minus mu sub B, divided by the square root of sigma sub B squared plus epsilon. Then y sub i equals gamma times x-hat sub i, plus beta." ## What each symbol means - $x_i$: One input value from the mini-batch, for example one neuron's value for one example in the batch. - $\mu_B$: The mean of the values in the mini-batch $B$: their average, in the same units as $x_i$. - $\sigma_B^2$: The variance of the values in the mini-batch: the average of the squared distances from the mean. It measures spread, in squared units. - $\epsilon$: A tiny positive constant, often about $10^{-5}$, that keeps the division safe when the variance is very small. - $\hat x_i$: The normalized value, which has mean 0 and variance close to 1 across the batch. - $\gamma$: A learned scale factor. Training sets it, and it lets the layer choose its own spread. - $\beta$: A learned shift. Training sets it, and it lets the layer choose its own center. - $y_i$: The output after the scale and shift. It is passed on to the next layer. ## What the formula is doing Inside a deep network, the values that flow into a layer keep changing as the layers before it learn. Batch normalization rescales each mini-batch so its values have mean 0 and variance 1. It is applied to each feature, or each neuron, separately, using the statistics of the mini-batch $B$. The mean $\mu_B$ is the average of the batch. The variance $\sigma_B^2$ is the average of the squared distances from that mean. Subtracting $\mu_B$ centers the values, and dividing by the square root of the variance sets their spread. The small $\epsilon$ sits inside the root so that a batch with almost no spread does not cause a division by zero. Forcing every layer to mean 0 and variance 1 can remove useful information. So each layer also gets two learned numbers, $\gamma$ and $\beta$. The output $y_i = \gamma \hat x_i + \beta$ can take whatever mean and spread training finds useful. If $\gamma = 1$ and $\beta = 0$, the output equals the normalized values. The paper that introduced batch normalization reported faster training, and the method became common in image models. Predictions are often made one example at a time, so the layer then uses running averages of the mean and variance collected during training instead of the statistics of a batch. ## An everyday picture Think of a class of students whose test scores drift upward from one test to the next. Before comparing the results, a teacher rescales each test so the average is 0 and the spread is 1, which puts every test on the same footing. The learned $\gamma$ and $\beta$ are like the teacher then choosing the grading scale that works best. ## Worked example: Four values in one mini-batch A mini-batch of four values for one feature: $x = (2, 4, 6, 8)$. Use $\epsilon = 0.001$ and the learned values $\gamma = 2$ and $\beta = 1$. The values are unitless. 1. Mean: $\mu_B = (2 + 4 + 6 + 8) / 4 = 5$. 2. Variance: the squared distances from the mean are $(-3)^2, (-1)^2, 1^2, 3^2 = 9, 1, 1, 9$, so $\sigma_B^2 = (9 + 1 + 1 + 9) / 4 = 5$. 3. Denominator: $\sqrt{5 + 0.001} \approx 2.2363$. 4. Normalized values: $\hat x = (-3, -1, 1, 3) / 2.2363 \approx (-1.3415,\ -0.4472,\ 0.4472,\ 1.3415)$. 5. Scale and shift: $y_i = 2 \hat x_i + 1$, which gives $y \approx (-1.6833,\ 0.1056,\ 1.8944,\ 3.6833)$. 6. Mean of the outputs: $(-1.6833 + 0.1056 + 1.8944 + 3.6833) / 4 = 1.0$, which equals $\beta$. **Answer:** The four outputs have mean $\beta = 1$ and a spread set by $\gamma = 2$. The batch supplied the mean and variance, and the learned $\gamma$ and $\beta$ set the final scale and center. ## Common mistakes - Taking the statistics across the features of one example. Batch normalization averages across the batch, for each feature. Layer normalization is the version that averages across features. - Using a batch of one or two examples. The mean and variance are then very noisy, and the normalization can make training worse. - Forgetting the running averages at prediction time. Single examples should use the stored statistics, not a batch of one. - Dropping $\epsilon$ when the values in a batch are all equal. The variance is then zero, and the division fails. ## Where you will meet it - Convolutional networks for image classification, where a normalization step often follows each convolution. - Residual image networks, which commonly place batch normalization between their convolution layers. - Models trained with large mini-batches, where the batch statistics are most reliable. - Sequence models, which often use layer normalization instead because batch statistics are awkward for variable-length inputs. ## Questions people ask ### What is a mini-batch? A small group of examples that the network processes together in one training step, such as 32 or 64 images. The batch statistics are taken from that group. ### Why does batch normalization need a batch? Its mean and variance come from the examples in the batch. With one example there is no spread to measure, so at prediction time the layer switches to stored statistics. ### Does batch normalization replace the learning rate? No. It changes the scale of the values each layer sees, which often allows larger learning rates, but the learning rate still matters. ### What do gamma and beta do? They are learned along with the other weights. They let each layer choose its own center and spread, so normalizing does not force one fixed scale. ## Related formulas - [Layer Normalization](https://formulabro.yunusemrevurgun.com/ai-ml/layer-normalization/) - [Dropout](https://formulabro.yunusemrevurgun.com/ai-ml/dropout/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) ## Sources - [Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift, Ioffe and Szegedy (arXiv:1502.03167)](https://arxiv.org/abs/1502.03167) - [Batch normalization, Wikipedia](https://en.wikipedia.org/wiki/Batch_normalization) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Layer Normalization > Layer normalization centers and scales the numbers that describe one example, so its values stay in a steady range no matter what other examples are in the batch. Page: https://formulabro.yunusemrevurgun.com/ai-ml/layer-normalization/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \hat x_i = \frac{x_i - \mu}{\sqrt{\sigma^2 + \epsilon}} \qquad y_i = \gamma_i \, \hat x_i + \beta_i $$ Read it out loud: "x-hat sub i equals x sub i minus mu, divided by the square root of sigma squared plus epsilon. Then y sub i equals gamma sub i times x-hat sub i, plus beta sub i." ## What each symbol means - $x_i$: One feature of the example: one number in its vector of features, for example one entry of a word's vector. - $\mu$: The mean of the features of this one example: their average, in the same units as $x_i$. - $\sigma^2$: The variance of the features of this one example: the average of the squared distances from $\mu$. It measures spread, in squared units. - $\epsilon$: A tiny positive constant that keeps the division safe when the spread is very small. - $\hat x_i$: The normalized feature, which has mean 0 and variance close to 1 across the features of the example. - $\gamma_i$: A learned scale for feature $i$. Each feature has its own. - $\beta_i$: A learned shift for feature $i$. Each feature has its own. - $y_i$: The output for feature $i$ after the scale and shift. ## What the formula is doing Layer normalization uses the same arithmetic as batch normalization, with one change: the statistics come from one example, not from the whole batch. The mean $\mu$ and variance $\sigma^2$ are taken over the features of that example, the numbers in its vector. Nothing depends on the other examples, so the result for an example is the same whether it is alone or in a batch. This matters for sequences. In a transformer, each word in a sentence is represented by a vector of features, and layer normalization works on each word's vector separately. Sentences have different lengths, and batch statistics are awkward for them. The per-example version avoids both problems. Each feature still gets its own learned scale $\gamma_i$ and shift $\beta_i$, as in batch normalization. These let the layer keep whatever center and spread it needs. Common starting values are 1 for every scale and 0 for every shift. The paper that introduced layer normalization, by Ba, Kiros and Hinton, studied recurrent networks, where batch statistics were hard to use. It is now a standard part of transformer blocks, where it is placed before or after the attention and feed-forward sublayers, depending on the design. ## An everyday picture Think of grading one student's report card against that student's own average and spread, instead of against the whole class. Each subject's marks are rescaled using that one student's numbers. The rescaled marks mean the same thing no matter which other students happen to be in the room. ## Worked example: One word vector with four features One example, a vector of four features $x = (2, 4, 6, 8)$, for example one word in a sentence. Use $\epsilon = 0.001$, and the starting values $\gamma_i = 1$ and $\beta_i = 0$ for every feature. The values are unitless. 1. Mean over the features: $\mu = (2 + 4 + 6 + 8) / 4 = 5$. 2. Variance over the features: $\sigma^2 = ((-3)^2 + (-1)^2 + 1^2 + 3^2) / 4 = 5$. 3. Denominator: $\sqrt{5 + 0.001} \approx 2.2363$. 4. Normalized vector: $\hat x \approx (-1.3415,\ -0.4472,\ 0.4472,\ 1.3415)$. With $\gamma_i = 1$ and $\beta_i = 0$, the output equals these values. **Answer:** The normalized vector has mean 0 and a variance of about 1. These are the same numbers as in the batch normalization example, but here they are four features of one example, so the statistics come from this vector alone. Adding other examples to a batch would not change the answer. ## Common mistakes - Averaging over the batch instead of over the features. That is batch normalization, and the result then changes when the other examples change. - Taking the mean across the words of a sentence instead of across the features of each word. Layer normalization works on one vector at a time. - Expecting one shared scale and shift for all features. Each feature has its own $\gamma_i$ and $\beta_i$. - Dropping $\epsilon$ when every feature of a vector is equal. The variance is then zero, and the division fails. ## Where you will meet it - Transformer models for language, such as the encoder and decoder blocks in many large language models. - Vision transformers and other attention-based image models. - Recurrent neural networks, the setting the original paper studied. - Models that process one example at a time, such as live prediction, where no batch of examples exists. ## Questions people ask ### Why do transformers use layer normalization instead of batch normalization? The statistics for batch normalization depend on the other examples in the batch, and sentences have different lengths. Layer normalization works on one vector at a time, so it avoids both problems. ### How is it different from batch normalization in practice? Batch normalization needs a batch and keeps running statistics for prediction. Layer normalization gives the same result during training and prediction, with no running averages. ### What is a feature here? One number in the vector that describes an example. For a word, the vector might hold many numbers that represent its meaning in the model. ### Does layer normalization change the order of the features? No. Each feature keeps its place. The mean and variance only set the center and spread of the whole vector. ## Related formulas - [Batch Normalization](https://formulabro.yunusemrevurgun.com/ai-ml/batch-normalization/) - [Scaled Dot-Product Attention](https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) ## Sources - [Layer Normalization, Ba, Kiros and Hinton (arXiv:1607.06450)](https://arxiv.org/abs/1607.06450) - [Layer normalization, Wikipedia](https://en.wikipedia.org/wiki/Layer_normalization) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Dropout > Dropout randomly switches off some neurons on each training pass, and scales up the ones that stay on, so the network learns patterns that do not rely on any single neuron. Page: https://formulabro.yunusemrevurgun.com/ai-ml/dropout/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \tilde h_i = \frac{m_i \, h_i}{1 - p} \qquad m_i \sim \text{Bernoulli}(1 - p) $$ Read it out loud: "h-tilde sub i equals m sub i times h sub i, divided by one minus p. Here m sub i is a random value that is 1 with probability one minus p, and 0 otherwise." ## What each symbol means - $h_i$: The activation of neuron $i$ before dropout: the number that neuron produces for the current input. - $\tilde h_i$: The activation after dropout during training. It is either 0, or the original value scaled up. - $m_i$: A random mask for neuron $i$: 1 means keep it, 0 means drop it. Each neuron gets a fresh draw on every training pass. - $p$: The drop probability, a number from 0 to 1. For example, $p = 0.5$ drops about half the neurons. It has no unit. - $1 - p$: The keep probability: the chance that a neuron is kept on a given pass. - $\text{Bernoulli}(1 - p)$: A random draw that gives 1 with probability $1 - p$ and 0 with probability $p$. ## What the formula is doing A network with many weights can memorize its training data instead of learning general patterns. Dropout is a training technique against this. On each training pass, every neuron is switched off at random with probability $p$. The neurons that remain have to carry the signal, so no single neuron can become essential. The mask $m_i$ is 1 for a kept neuron and 0 for a dropped one. Multiplying $h_i$ by $m_i$ removes the dropped neurons. Each neuron is kept with probability $1 - p$, so on average a fraction $1 - p$ of the activations survive. Dividing by $1 - p$ scales up the kept activations. Without this step the total signal would be smaller during training than at prediction time, and the next layer would see inputs that are too weak. This form is called inverted dropout. Over many random masks, the average value of $\tilde h_i$ equals $h_i$, so the average signal does not change. At prediction time dropout is turned off. Every neuron is kept, and the activations are used as they are, with no mask and no scaling. The original paper scaled the weights at prediction time instead, which gives an approximation of the same average signal. Most libraries use the inverted form, so the prediction code stays simple. ## An everyday picture Think of a sports team that practices with random players sitting out each drill. Every player has to learn to play well with different teammates, so no one player becomes a crutch. On game day everyone plays, and the team is ready even when a key player is missing. ## Worked example: Four activations with half of them dropped A layer outputs $h = (0.5,\ 2.0,\ 1.0,\ 4.0)$. The drop probability is $p = 0.5$, so each neuron is kept with probability $0.5$. The random draw gives the mask $m = (1, 0, 1, 0)$, which keeps neurons 1 and 3 and drops neurons 2 and 4. The values are unitless. 1. Scale factor for kept neurons: $\frac{1}{1 - p} = \frac{1}{0.5} = 2$. 2. Neuron 1 is kept: $\tilde h_1 = 1 \times 0.5 \times 2 = 1.0$. 3. Neuron 2 is dropped: $\tilde h_2 = 0 \times 2.0 \times 2 = 0$. 4. Neuron 3 is kept: $\tilde h_3 = 1 \times 1.0 \times 2 = 2.0$. 5. Neuron 4 is dropped: $\tilde h_4 = 0 \times 4.0 \times 2 = 0$. **Answer:** During this training pass the output is $(1.0,\ 0,\ 2.0,\ 0)$. Two neurons were switched off and the kept ones were doubled. Over many random masks, each neuron's average output equals its original value, because it is kept half the time and doubled when kept. At prediction time the layer outputs $(0.5,\ 2.0,\ 1.0,\ 4.0)$ unchanged. ## Common mistakes - Dropping neurons at prediction time. Dropout is a training tool. At prediction time the full network is used, and keeping the random mask would make the answers change from run to run. - Forgetting the $1 / (1 - p)$ scaling in inverted dropout. Then the signal is too weak during training, and the outputs no longer match at prediction time. - Setting $p$ too high, such as 0.9. Most neurons are switched off on every pass, so the network learns slowly and can underfit. - Expecting dropout to add capacity. It is a regularizer that helps when a model overfits. It does not make a small model bigger. ## Where you will meet it - Fully connected layers in image and text classifiers, where the 2014 paper showed it reduces overfitting. - Transformer models, which apply dropout to attention weights and sublayer outputs during training. - Recurrent networks and other models trained on limited data, where overfitting is a risk. - Monte Carlo dropout, where dropout stays on at prediction time so that repeated predictions show the model's uncertainty. ## Questions people ask ### Is p the keep probability or the drop probability? Here $p$ is the drop probability, and the keep probability is $1 - p$. Some papers use $p$ for the keep probability instead, so check the definition in each source. ### What is a good value of p? Many classifiers use values between 0.1 and 0.5. The best value depends on the model and the data, so tune it on validation data. ### Why does dropout make a network more robust? Each neuron has to be useful alongside a different set of partners on each pass. The network cannot lean on any one neuron, so the features it learns are spread across many neurons. ## Related formulas - [Batch Normalization](https://formulabro.yunusemrevurgun.com/ai-ml/batch-normalization/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) ## Sources - [Dropout: A Simple Way to Prevent Neural Networks from Overfitting, Srivastava et al., JMLR 15 (2014)](https://jmlr.org/papers/v15/srivastava14a.html) - [Dilution (neural networks), Wikipedia](https://en.wikipedia.org/wiki/Dilution_(neural_networks)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Precision and Recall > Precision asks how many of the items a model flagged were right, and recall asks how many of the real cases it managed to find. Page: https://formulabro.yunusemrevurgun.com/ai-ml/precision-and-recall/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{Precision} = \frac{TP}{TP + FP} \qquad \text{Recall} = \frac{TP}{TP + FN} $$ Read it out loud: "Precision equals true positives divided by the sum of true positives and false positives. Recall equals true positives divided by the sum of true positives and false negatives." ## What each symbol means - $\text{Precision}$: Of the items the model flagged as positive, the share that really are positive. It answers: when the model says yes, how often is it right? - $\text{Recall}$: Of all the real positive items, the share the model found. It answers: how many of the real cases did it catch? - $TP$: True positives: items flagged as positive that really are positive. This is a count. - $FP$: False positives: items flagged as positive that are really negative. This is a count. - $FN$: False negatives: real positive items the model missed. This is a count. ## What the formula is doing Many classifiers answer yes or no. A spam filter says spam or not spam, and a medical test says positive or negative. Accuracy alone can hide problems when one answer is rare. Precision and recall look at the positive answers in two different ways. Start with a table of outcomes. A flagged item that really is positive is a true positive, $TP$. A flagged item that is really negative is a false positive, $FP$. A real positive that the model missed is a false negative, $FN$. Precision divides $TP$ by everything the model flagged, which is $TP + FP$. Recall divides $TP$ by every real positive, which is $TP + FN$. It measures how much of the real positives the model caught. A filter that flags only one email it is sure about has high precision, but its recall can be terrible, because it misses almost all the spam. The two numbers trade off. Flagging more items usually catches more real positives, which raises recall, but it also brings in more false alarms, which lowers precision. The right balance depends on what each kind of mistake costs. A screening test for a serious disease should favor recall, while a spam filter that hides real email should favor precision. ## An everyday picture Think of a fishing net. Precision asks: of the fish you pulled up, how many were the kind you wanted? Recall asks: of all the wanted fish in the lake, how many did your net catch? A tiny net full of the right fish has high precision and low recall. A huge net catches most of the wanted fish, but it also brings up a lot of junk. ## Worked example: A spam filter on one day of email A spam filter flags 50 emails as spam. Of those, 40 really are spam, so $TP = 40$, and 10 are real emails, so $FP = 10$. It misses 20 spam emails that reached the inbox, so $FN = 20$. The counts are unitless. 1. Precision: $\frac{40}{40 + 10} = \frac{40}{50} = 0.80$. So 80% of the flagged emails were spam. 2. Recall: $\frac{40}{40 + 20} = \frac{40}{60} \approx 0.667$. So the filter found about 66.7% of all the spam. 3. Both numbers use the same 40 correct catches. The difference is the denominator: flagged emails for precision, and all real spam for recall. **Answer:** Precision is 80% and recall is about 66.7%. When the filter says spam, it is usually right, but about one spam email in three still reaches the inbox. ## Common mistakes - Putting true negatives into the formulas. True negatives do not appear in precision or recall, so a large number of correct rejections does not raise either one. - Swapping the denominators. Precision divides by the flagged items, and recall divides by the real positives. - Reporting only one of the two. A model can have high precision and terrible recall, and the reverse is also true. - Forgetting that both numbers depend on the threshold. Changing the cutoff for a yes answer usually moves precision and recall in opposite directions. ## Where you will meet it - Evaluating spam filters, fraud detectors and medical screening tests. - Search engines, where precision is the share of results that are relevant and recall is the share of all relevant pages that were found. - Object detection and information retrieval benchmarks. - Choosing the threshold of a classifier by plotting a precision-recall curve. ## Questions people ask ### Which is more important, precision or recall? It depends on what each mistake costs. Use recall when missing a real case is costly. Use precision when a false alarm is costly. ### How is this different from accuracy? Accuracy counts every correct answer, including true negatives. When positives are rare, a model that always answers no can have high accuracy and zero recall. ### What is a confusion matrix? A table that counts $TP$, $FP$, $FN$ and $TN$ for a classifier. Precision and recall are read straight from its rows and columns. ### What if the model flags nothing? Then $TP + FP = 0$, and precision has a zero denominator, so it is undefined. Libraries usually report it as 0 or skip it. ## Related formulas - [F1 Score](https://formulabro.yunusemrevurgun.com/ai-ml/f1-score/) - [Bayes' Theorem](https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem/) - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) ## Sources - [Precision and recall, Wikipedia](https://en.wikipedia.org/wiki/Precision_and_recall) - [Confusion matrix, Wikipedia](https://en.wikipedia.org/wiki/Confusion_matrix) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # F1 Score > The F1 score is one number from 0 to 1 that stays low unless both precision and recall are reasonably high. Page: https://formulabro.yunusemrevurgun.com/ai-ml/f1-score/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ F_1 = \frac{2 \cdot P \cdot R}{P + R} $$ Read it out loud: "F sub 1 equals 2 times P times R, divided by P plus R. Here P is precision and R is recall." ## What each symbol means - $F_1$: The F1 score: one number from 0 to 1 that combines precision and recall. Higher is better, and 1 is perfect. - $P$: Precision: the share of flagged items that are correct, from 0 to 1. - $R$: Recall: the share of real positive items that were found, from 0 to 1. ## What the formula is doing Precision and recall often pull in opposite directions, so it helps to have one number that reflects both. The F1 score is that number. It is the harmonic mean of precision $P$ and recall $R$, a kind of average that suits rates and ratios like these. A harmonic mean stays close to the smaller of its two inputs. A plain average, $(P + R) / 2$, would let a high value hide a low one. The F1 score does not. If either precision or recall is near zero, the F1 score is near zero too. The formula also has a form that uses only counts: $F_1 = \frac{2TP}{2TP + FP + FN}$, where $TP$, $FP$ and $FN$ are the true positives, false positives and false negatives from the precision and recall page. The two forms give the same number, so use whichever one matches the numbers you have. The plain F1 score treats precision and recall as equally important. When one of them matters more, the F-beta score weights recall more or less. F1 is the standard choice when the two are equally important. ## An everyday picture Imagine a job that needs two skills, and you are graded on both. A plain average of a perfect score and a very weak one looks fine at 55 out of 100. A harmonic-style average drops to about 18 out of 100, which shows the weak skill straight away. The F1 score grades precision and recall this way. ## Worked example: Combining the spam filter's precision and recall From the precision and recall example, the filter has $P = 0.80$ and $R = 40 / 60 \approx 0.6667$. The counts are $TP = 40$, $FP = 10$ and $FN = 20$. The values are unitless. 1. Precision and recall form: $F_1 = \frac{2 \times 0.80 \times 0.6667}{0.80 + 0.6667} = \frac{1.0667}{1.4667} \approx 0.7273$. 2. Count form: $F_1 = \frac{2 \times 40}{2 \times 40 + 10 + 20} = \frac{80}{110} \approx 0.7273$, the same answer. 3. For comparison, the plain average is $(0.80 + 0.6667) / 2 \approx 0.7333$. The F1 score is a little lower, because it is pulled toward the smaller value, recall. **Answer:** The F1 score is about 0.727. It sits between the precision of 0.80 and the recall of 0.667, and it leans toward the lower of the two. ## Common mistakes - Averaging precision and recall with a plain mean. A high precision can hide a near-zero recall, and the plain mean stays high while the F1 score drops. - Mixing inputs between the two forms. The precision and recall form needs $P$ and $R$, and the count form needs $TP$, $FP$ and $FN$. Use one set of counts for both. - Treating F1 as the answer to every question. It weights precision and recall equally, which may not match what each mistake costs in your problem. - Reporting F1 alone. Two models can have the same F1 score and very different precision and recall, so report both when the difference matters. ## Where you will meet it - Text classifiers and named entity recognition, where F1 is a standard benchmark measure. - Information retrieval and search evaluation, where it balances how precise and how complete the results are. - Medical and fraud detection models, where both false alarms and missed cases matter. - Comparing models in machine learning papers and public leaderboards. ## Questions people ask ### Is F1 the same as accuracy? No. Accuracy counts every correct answer, including true negatives. F1 ignores true negatives and focuses on the positive class. ### What is the F-beta score? A weighted version: $F_\beta = \frac{(1 + \beta^2) P R}{\beta^2 P + R}$. A $\beta$ above 1 gives recall more weight, and a $\beta$ below 1 gives precision more weight. F1 is the case $\beta = 1$. ### Can F1 be zero? Yes. If either precision or recall is 0, the numerator is 0, so the F1 score is 0. ## Related formulas - [Precision and Recall](https://formulabro.yunusemrevurgun.com/ai-ml/precision-and-recall/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Bayes' Theorem](https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem/) ## Sources - [F-score, Wikipedia](https://en.wikipedia.org/wiki/F-score) - [Precision and recall, Wikipedia](https://en.wikipedia.org/wiki/Precision_and_recall) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Classification Accuracy > Accuracy is the share of a model's guesses that were right, out of all the guesses it made. Page: https://formulabro.yunusemrevurgun.com/ai-ml/classification-accuracy/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN} $$ Read it out loud: "Accuracy equals true positives plus true negatives, divided by true positives plus true negatives plus false positives plus false negatives." ## What each symbol means - $\text{Accuracy}$: The share of predictions that were correct. It is a number from 0 to 1, often written as a percentage. It has no unit. - $TP$: True positives: the model said positive and the answer really was positive, such as a spam email correctly flagged as spam. It is a count of examples. - $TN$: True negatives: the model said negative and the answer really was negative, such as a normal email correctly left in the inbox. It is a count of examples. - $FP$: False positives: the model said positive but the answer was negative, such as a normal email wrongly flagged as spam. Also called a false alarm. It is a count of examples. - $FN$: False negatives: the model said negative but the answer was positive, such as a spam email that got through. Also called a miss. It is a count of examples. ## What the formula is doing A classifier puts each example into a class, such as spam or not spam. For a yes-or-no question, every prediction lands in one of four boxes. The *positive* class is the one you are looking for, here spam. The counts $TP$, $TN$, $FP$ and $FN$ record how many predictions landed in each box. Together they form a table called a confusion matrix. The top of the fraction, $TP + TN$, counts the correct answers. The bottom counts every answer the model gave, right and wrong. Dividing one by the other gives the share of right answers, which is what accuracy means. The result is a number from 0 to 1. A value of $0.9$ means 90% of the predictions were right. Accuracy gives every mistake the same weight. A missed spam email and a wrongly flagged normal email each count as one error. That equal weighting is the weak point when one class is much bigger than the other. Suppose 99 of every 100 emails are normal. A model that always answers not spam is right 99% of the time, yet it catches no spam at all. Accuracy looks excellent while the model fails at its real job. In that case, check the errors for each class separately, for example with precision and recall. ## An everyday picture Think of a spelling test with 100 words. If you spell 90 words correctly, your score is 90 out of 100, and accuracy works the same way. The difference is that a classifier's test set may hold mostly one kind of case, so a high score can hide a failure on the rare kind. ## Worked example: A spam filter that checks 100 emails A made-up test set of 100 emails: 20 are spam and 80 are not spam. The filter catches $TP = 15$ spam emails, misses $FN = 5$ spam emails, keeps $TN = 75$ normal emails in the inbox and wrongly flags $FP = 5$ normal emails. All these numbers are invented for the example. 1. Count the correct predictions: $TP + TN = 15 + 75 = 90$. 2. Count all the predictions: $TP + TN + FP + FN = 15 + 75 + 5 + 5 = 100$. 3. Divide: $\text{Accuracy} = \frac{90}{100} = 0.90$, which is 90%. 4. Compare with a model that always answers not spam. It gets all 80 normal emails right and all 20 spam emails wrong, so its accuracy is $\frac{80}{100} = 0.80$. It catches zero spam. **Answer:** The filter's accuracy is **90%**. That sounds strong, but a model that always answers not spam reaches 80% and catches no spam at all. When one class is much more common, accuracy alone can hide the errors that matter. ## Common mistakes - Reading 99% accuracy as success without checking the class counts. If 99% of the data belongs to one class, a model that always guesses that class scores 99%. - Mixing up false positives and false negatives. They are different errors: a false positive hides a good email, and a false negative lets spam through. - Measuring accuracy only on the training data. Scores on examples the model has already learned from are too optimistic. Use a separate test set. - Dividing by the wrong total. The bottom of the fraction must count every prediction, not only the correct ones or only the positive examples. ## Where you will meet it - Quick first checks of image classifiers, such as sorting photos of handwritten digits from 0 to 9, where the classes are fairly balanced. - Benchmark leaderboards for image classification, where top-1 accuracy is the share of test images whose best predicted label is correct. - Summary scores for spam filters and other yes-or-no tools, often shown next to precision and recall. - Comparison tables in research papers, where each model's accuracy is reported on the same test set. ## Questions people ask ### What is a confusion matrix? A table that counts the four outcomes: true positives, true negatives, false positives and false negatives. In the usual layout, accuracy is the diagonal of the table added up and divided by the total. ### What counts as a good accuracy? There is no universal number. Compare the score with a baseline, such as always guessing the most common class. An accuracy of 80% means little if that baseline already reaches 80%. ### Is accuracy the same as the error rate? They are linked. The error rate is $\frac{FP + FN}{TP + TN + FP + FN}$, and it always equals $1 - \text{Accuracy}$. ### When should I avoid relying on accuracy? When one class is rare, or when the two kinds of mistake have very different costs. In medical screening, for example, a missed case can matter far more than a false alarm. ## Related formulas - [Precision and Recall](https://formulabro.yunusemrevurgun.com/ai-ml/precision-and-recall/) - [F1 Score](https://formulabro.yunusemrevurgun.com/ai-ml/f1-score/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) ## Sources - [Confusion matrix, Wikipedia](https://en.wikipedia.org/wiki/Confusion_matrix) - [Accuracy and precision, Wikipedia](https://en.wikipedia.org/wiki/Accuracy_and_precision) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Cosine Similarity > Cosine similarity scores how closely two lists of numbers point the same way, from -1 for opposite directions to 1 for the same direction. Page: https://formulabro.yunusemrevurgun.com/ai-ml/cosine-similarity/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \cos\theta = \frac{\mathbf{A}\cdot\mathbf{B}}{\|\mathbf{A}\|\,\|\mathbf{B}\|} $$ Read it out loud: "Cosine of theta equals the dot product of vector A and vector B, divided by the length of vector A times the length of vector B." ## What each symbol means - $\cos\theta$: The cosine similarity: a number from -1 to 1. It has no unit. - $\theta$: The angle between the two vectors. $0^\circ$ means they point the same way, $90^\circ$ means they are unrelated, and $180^\circ$ means they point opposite ways. - $\mathbf{A}$: The first vector: a list of numbers, such as the embedding of one sentence. Each number is one component. - $\mathbf{B}$: The second vector. It must have the same number of components as $\mathbf{A}$. - $\mathbf{A}\cdot\mathbf{B}$: The dot product: multiply the components in each position and add the results, $\sum_i A_i B_i$. It is large when both vectors are long and point the same way. - $\|\mathbf{A}\|$: The length (also called the norm or magnitude) of $\mathbf{A}$: the square root of the sum of its squared components. - $\|\mathbf{B}\|$: The length of $\mathbf{B}$, found the same way. ## What the formula is doing Many AI systems turn words, sentences or images into *embeddings*. An embedding is a vector, a list of numbers. Items with similar meanings tend to get vectors that point in similar directions. Cosine similarity measures how close those directions are. The top of the fraction is the dot product $\mathbf{A}\cdot\mathbf{B}$. It grows when the matching components are both large and of the same sign. The bottom divides out the length of each vector. After that division only the angle is left, and the result always lies between $-1$ and $1$. Length is removed on purpose. A long document that uses many words about cats and a short note about cats point the same way. Their raw vectors differ in size, but their cosine similarity is high. For text built from word counts, that is usually what you want. Read the value like this. A value near $1$ means the vectors point almost the same way. A value near $0$ means they are unrelated, at a right angle to each other. A value near $-1$ means they point in opposite directions. For vectors with no negative numbers, such as word counts, the value stays between $0$ and $1$. ## An everyday picture Picture two arrows drawn from the same point on a table. If they point the same way, the arrows agree, even when one is ten times longer than the other. Cosine similarity reads only the gap between the directions and ignores the arrows' lengths. ## Worked example: Two made-up 2-D vectors Two vectors $\mathbf{A} = (3, 4)$ and $\mathbf{B} = (4, 3)$. Each is a made-up two-number embedding for this example. 1. Dot product: $\mathbf{A}\cdot\mathbf{B} = 3 \times 4 + 4 \times 3 = 12 + 12 = 24$. 2. Lengths: $\|\mathbf{A}\| = \sqrt{3^2 + 4^2} = \sqrt{25} = 5$ and $\|\mathbf{B}\| = \sqrt{4^2 + 3^2} = \sqrt{25} = 5$. 3. Divide: $\cos\theta = \frac{24}{5 \times 5} = \frac{24}{25} = 0.96$. 4. Length check: double every component of $\mathbf{B}$ to get $(8, 6)$. The dot product becomes $3 \times 8 + 4 \times 6 = 48$ and the length becomes $\sqrt{8^2 + 6^2} = 10$. The score is $\frac{48}{5 \times 10} = 0.96$ again, so making a vector longer without changing its direction does not change the score. **Answer:** The cosine similarity is **0.96**, close to 1, so the two vectors point almost the same way. The angle between them is about 16.3 degrees. Doubling $\mathbf{B}$ did not change the score. ## Common mistakes - Skipping the division by the lengths. The dot product alone grows with the size of the vectors, so it cannot compare directions fairly. - Comparing vectors from different embedding models. Each model builds its own space, so the numbers do not line up across models. - Reading 0.5 as 50% alike. Cosine values are not percentages. Test the score on pairs you already know are similar or different to learn what a good value looks like for your model. - Dividing by a zero length. A zero vector has no direction, so the formula breaks down. Check for zero vectors first. ## Where you will meet it - Semantic search, which ranks documents by how closely their embedding vectors point toward the vector of the search query. - Recommendation systems, which compare the embedding of a user with the embeddings of items. - Retrieval for chatbots, where the passages closest to a question are fetched before the model writes its answer. - Comparing documents by word counts or TF-IDF vectors, for example to spot near-duplicate text. ## Questions people ask ### How is cosine similarity different from Euclidean distance? Euclidean distance measures how far apart two points are, so length matters. Cosine similarity ignores length and measures only the angle between the vectors. ### Can cosine similarity be negative? Yes. A value of $-1$ means the vectors point in exactly opposite directions. Vectors with only zero or positive numbers, such as word counts, cannot go below $0$. ### What is a good cosine similarity score? It depends on the model. Different embedding models produce scores in different ranges, so the reliable way to choose a cutoff is to test it on pairs you already know are similar or different. ### Do the two vectors have to be the same length? Yes, in the sense of having the same number of components. The dot product matches components position by position, so both vectors need the same positions. ## Related formulas - [Euclidean Distance](https://formulabro.yunusemrevurgun.com/ai-ml/euclidean-distance/) - [Scaled Dot-Product Attention](https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention/) - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) ## Sources - [Cosine similarity, Wikipedia](https://en.wikipedia.org/wiki/Cosine_similarity) - [Dot product, Wikipedia](https://en.wikipedia.org/wiki/Dot_product) - [Word embedding, Wikipedia](https://en.wikipedia.org/wiki/Word_embedding) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Euclidean Distance > Euclidean distance is the straight-line distance between two points, found by squaring the gaps, adding them up and taking the square root. Page: https://formulabro.yunusemrevurgun.com/ai-ml/euclidean-distance/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ d(\mathbf{p}, \mathbf{q}) = \sqrt{\sum_{i=1}^{n} (p_i - q_i)^2} $$ Read it out loud: "d of p and q equals the square root of the sum, for i from 1 to n, of p sub i minus q sub i, all squared." ## What each symbol means - $d(\mathbf{p}, \mathbf{q})$: The distance between points $\mathbf{p}$ and $\mathbf{q}$. It has the same unit as the features, such as metres for positions measured in metres. - $\mathbf{p}$: The first point, written as a list of $n$ numbers, one for each feature. - $\mathbf{q}$: The second point, with the same $n$ features. - $n$: The number of features, which is also the number of dimensions. Two features give a flat plane; three give ordinary 3-D space. It has no unit. - $i$: The position of one feature in the list, counting from 1 to $n$. - $p_i$: The value of point $\mathbf{p}$ for feature number $i$. - $q_i$: The value of point $\mathbf{q}$ for feature number $i$. - $\sum_{i=1}^{n}$: Add up for every $i$ from 1 to $n$: total the squared gaps over all the features. ## What the formula is doing A point is a list of numbers. A house could be described by its size and its number of bedrooms, and each house is then one point. The Euclidean distance tells you how far apart two points are, in the straight-line sense you would measure with a ruler. With two features, the formula is the Pythagorean theorem. The gap along the first feature and the gap along the second are the two short sides of a right triangle, and the distance is the long side. The formula extends that same idea to any number of features, even though no ruler can draw that many directions. Each gap $p_i - q_i$ is squared. Squaring removes the sign, so a gap of $-3$ and a gap of $+3$ count the same, and big gaps count much more than small ones. The squared gaps are added, and the square root at the end brings the answer back to the original units. Every feature enters the sum, so the scale of each feature matters. A feature measured in dollars, with values in the thousands, will swamp a feature counting bedrooms, whose values are near 3. Rescale the features first so that no single one dominates. In k-nearest neighbors, the closest known points decide the label of a new point, so this scaling directly changes the answer. ## An everyday picture A bird flying straight from one city to another covers the Euclidean distance. It ignores roads and turns. The bird's path is the shortest line between the two points, which is exactly what the formula measures. ## Worked example: Finding the nearest neighbor Three known points, each with a label: $\mathbf{P}_1 = (4, 6)$ labeled *red*, $\mathbf{P}_2 = (2, 3)$ labeled *blue* and $\mathbf{P}_3 = (0, 0)$ labeled *red*. A new point $\mathbf{q} = (1, 2)$ needs a label. Use the nearest neighbor rule: copy the label of the closest known point. All the numbers are invented for this example. 1. Distance to $\mathbf{P}_1$: $\sqrt{(1 - 4)^2 + (2 - 6)^2} = \sqrt{9 + 16} = \sqrt{25} = 5$. 2. Distance to $\mathbf{P}_2$: $\sqrt{(1 - 2)^2 + (2 - 3)^2} = \sqrt{1 + 1} = \sqrt{2} \approx 1.414$. 3. Distance to $\mathbf{P}_3$: $\sqrt{(1 - 0)^2 + (2 - 0)^2} = \sqrt{1 + 4} = \sqrt{5} \approx 2.236$. 4. The smallest distance is about 1.414, to $\mathbf{P}_2$, so $\mathbf{q}$ takes the label *blue*. **Answer:** The new point is labeled **blue**, because its nearest known point is $\mathbf{P}_2$, at a distance of about 1.41. The two red points are farther away, at about 5 and 2.24. ## Common mistakes - Leaving out the square root. The squared distance ranks neighbors in the same order, but it is not the distance, so do not report it as one. - Mixing units. Subtracting a height in centimeters from a weight in kilograms gives a number with no meaning. Put every feature on a comparable footing first. - Skipping feature scaling. A feature with large numbers dominates the distance, and the other features barely matter. - Using category names as numbers. Coding red as 1 and blue as 2 creates distances that have no real meaning. Encode categories in a different way. ## Where you will meet it - k-nearest neighbors, which finds the closest known points to a new point and lets them vote on its label. - k-means clustering, which assigns each point to the nearest center using the squared form of this distance. - Nearest-neighbor search in image retrieval, where feature vectors of images are compared to find the most similar ones. - Measuring the error between a predicted position and the true position in robotics and mapping. ## Questions people ask ### Why square the gaps and then take a square root? Squaring turns every gap into a positive number, so gaps in opposite directions do not cancel. The square root undoes the squaring, so the answer is in the same units as the original numbers. ### Is this the same as the Pythagorean theorem? Yes for two points in two dimensions, where the formula gives the long side of a right triangle. The formula extends the same idea to more dimensions. ### Why should I scale the features before using it? Because a feature with large values dominates the sum. Rescaling, for example by subtracting the mean and dividing by the standard deviation, gives each feature a fair say. ### How is it different from Manhattan distance? Manhattan distance adds the absolute gaps instead. It does not square the gaps or take a square root, and it measures the distance you would walk along a city grid. ## Related formulas - [Cosine Similarity](https://formulabro.yunusemrevurgun.com/ai-ml/cosine-similarity/) - [k-Means Clustering](https://formulabro.yunusemrevurgun.com/ai-ml/k-means-clustering/) - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) ## Sources - [Euclidean distance, Wikipedia](https://en.wikipedia.org/wiki/Euclidean_distance) - [K-nearest neighbors algorithm, Wikipedia](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) - [Pythagorean theorem, Wikipedia](https://en.wikipedia.org/wiki/Pythagorean_theorem) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # k-Means Clustering > k-means clustering sorts points into K groups by moving each group's center to its middle and reassigning every point to its nearest center. Page: https://formulabro.yunusemrevurgun.com/ai-ml/k-means-clustering/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ J = \sum_{k=1}^{K} \sum_{\mathbf{x} \in C_k} \|\mathbf{x} - \boldsymbol{\mu}_k\|^2 $$ Read it out loud: "J equals the sum, for k from 1 to K, of the sum over every point x in cluster k of the squared distance from x to the center mu sub k." ## What each symbol means - $J$: The objective: the total of all squared distances from each point to its cluster center. Smaller means tighter clusters. Its unit is the square of the unit of the data. - $K$: The number of clusters. You choose it before the algorithm starts. It has no unit. - $k$: The number of one cluster, counting from 1 to $K$. - $C_k$: The set of points assigned to cluster $k$. - $\mathbf{x}$: One data point, written as a list of numbers, such as a customer's total spending and number of visits. - $\boldsymbol{\mu}_k$: The center (centroid) of cluster $k$: the average of all the points in $C_k$, computed one feature at a time. - $\|\mathbf{x} - \boldsymbol{\mu}_k\|^2$: The squared distance from point $\mathbf{x}$ to the center of its own cluster. - $\sum_{\mathbf{x} \in C_k}$: Add up over every point $\mathbf{x}$ that belongs to cluster $k$. ## What the formula is doing k-means is unsupervised: the points have no labels, and the algorithm finds the groups on its own. You choose $K$, the number of groups, before you start. Each group is called a cluster, and each cluster has a center called its centroid. The objective $J$ measures how tight the clusters are. For each point, take the squared distance to the center of its cluster, then add up all of those numbers. A small $J$ means every point sits close to its own center. Finding the assignments and centers that give the smallest possible $J$ is hard to do exactly, so the algorithm uses a shortcut. The shortcut alternates two easy steps. First, assign each point to the nearest center. Second, move each center to the mean of the points assigned to it. The mean is the point that makes the sum of squared distances smallest for its group, so the second step cannot raise $J$. The first step cannot raise $J$ either, because each point picks the closest center. The algorithm stops when the assignments no longer change. It reaches a local minimum of $J$, and the result depends on the starting centers, so practitioners often run it several times from different starts. ## An everyday picture Imagine opening K coffee shops in a town. Each resident walks to the nearest shop. Then each shop moves to the middle of its customers. Residents check again which shop is nearest, and the shops move again. Eventually nobody changes shops and the shops stop moving. ## Worked example: One iteration on four points on a line Four points on a line: $1, 2, 6, 8$. Use $K = 2$ and start with centers at $\mu_1 = 0$ and $\mu_2 = 5$, chosen by hand. The points are one-dimensional, so the squared distance is $(x - \mu)^2$. 1. Assign each point to the nearest center. The point 1 is distance 1 from 0 and 4 from 5, so it joins cluster 1. The point 2 is distance 2 from 0 and 3 from 5, so it joins cluster 1. The point 6 is distance 6 from 0 and 1 from 5, so it joins cluster 2. The point 8 is distance 8 from 0 and 3 from 5, so it joins cluster 2. 2. Compute $J$ with the starting centers: $J = (1-0)^2 + (2-0)^2 + (6-5)^2 + (8-5)^2 = 1 + 4 + 1 + 9 = 15$. 3. Move each center to the mean of its cluster: $\mu_1 = \frac{1 + 2}{2} = 1.5$ and $\mu_2 = \frac{6 + 8}{2} = 7$. 4. Compute $J$ with the new centers: $J = (1-1.5)^2 + (2-1.5)^2 + (6-7)^2 + (8-7)^2 = 0.25 + 0.25 + 1 + 1 = 2.5$. 5. Assign again. Each point is still closest to the same center, so the clusters do not change and the algorithm stops. **Answer:** One iteration cut $J$ from **15** to **2.5**. The clusters are $\{1, 2\}$ and $\{6, 8\}$, with centers at 1.5 and 7. Because the assignments no longer change, the algorithm has reached a local minimum. ## Common mistakes - Picking $K$ without checking it. A value that is too small merges different groups, and a value that is too large cuts one real group into pieces. - Expecting the same answer every run. The result depends on the starting centers, so run the algorithm several times and compare the final $J$. - Using features on very different scales. Distances are dominated by the feature with the largest numbers, so rescale the features first. - Assuming clusters are round and of similar size. k-means works best when clusters are roughly ball-shaped and alike in size. Long, curved or very uneven clusters can be split or merged in the wrong way. ## Where you will meet it - Customer segmentation, grouping shoppers by their spending and visit patterns so a store can tailor offers to each group. - Color reduction in image compression, where an image is reduced to $K$ representative colors. - Grouping documents or news articles by topic, after each text has been turned into a vector. - Exploring measurements from scientific experiments, to see whether the samples fall into natural groups. ## Questions people ask ### How do I choose K? A common method is the elbow method. Run the algorithm for several values of $K$, plot $J$ against $K$, and look for a bend where extra clusters stop helping much. Domain knowledge, such as how many customer types a business expects, matters too. ### Is k-means the same as k-nearest neighbors? No. k-means is unsupervised: it finds groups without labels. k-nearest neighbors is supervised: it uses labeled examples to predict a label for a new point. The letter k means something different in each. ### Does k-means always find the best clusters? No. It finds a local minimum of $J$, which may not be the global minimum. Better starting centers, such as those chosen by the k-means++ method, and several runs reduce this risk. ### Why is the mean the center of a cluster? The mean is the one center that makes the sum of squared distances to the group as small as possible. That is why the update step moves each center to the mean of its points. ## Related formulas - [Euclidean Distance](https://formulabro.yunusemrevurgun.com/ai-ml/euclidean-distance/) - [Cosine Similarity](https://formulabro.yunusemrevurgun.com/ai-ml/cosine-similarity/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [K-means clustering, Wikipedia](https://en.wikipedia.org/wiki/K-means_clustering) - [Lloyd's algorithm, Wikipedia](https://en.wikipedia.org/wiki/Lloyd%27s_algorithm) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Kullback-Leibler Divergence > KL divergence measures how badly a set of guessed probabilities fits the real probabilities. Page: https://formulabro.yunusemrevurgun.com/ai-ml/kl-divergence/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ D_{\mathrm{KL}}(P \,\|\, Q) = \sum_x P(x) \log \frac{P(x)}{Q(x)} $$ Read it out loud: "D K L of P and Q equals the sum, over every outcome x, of P of x times the log of P of x divided by Q of x." ## What each symbol means - $D_{\mathrm{KL}}(P \,\|\, Q)$: The Kullback-Leibler divergence of $Q$ from $P$. It is zero only when the two distributions are identical. Its unit is the nat when the natural log is used, and the bit when log base 2 is used. - $P$: The true or reference distribution: the probability of each outcome as it really happens. - $Q$: The approximating distribution: the probabilities a model or a guess assigns to the same outcomes. - $x$: One possible outcome, such as heads or tails. - $P(x)$: The probability of outcome $x$ under $P$: a number from 0 to 1. - $Q(x)$: The probability of outcome $x$ under $Q$. It must be greater than 0 wherever $P(x)$ is greater than 0. - $\log$: The logarithm. This page uses the natural log, $\ln$, which gives nats. A log base 2 gives bits instead. - $\sum_x$: Add up over every possible outcome $x$. ## What the formula is doing A probability distribution gives a probability to every outcome, and the probabilities add up to 1. Suppose the real world follows $P$, but you describe it with $Q$. KL divergence measures the cost of that mismatch: the extra surprise, on average, from using $Q$ when $P$ is the truth. Each term in the sum does one job. The factor $P(x)$ says how often outcome $x$ really happens, so common outcomes count more. The ratio $\frac{P(x)}{Q(x)}$ compares the two probabilities. It is bigger than 1 when $Q$ is too small for that outcome and less than 1 when $Q$ is too large. The logarithm of that ratio is the difference in surprise between the two descriptions, and the sum averages it over the outcomes. The result is never negative. It is exactly zero only when $Q$ matches $P$ for every outcome. It is not symmetric, though. $D_{KL}(P \| Q)$ and $D_{KL}(Q \| P)$ are usually different numbers, because the average is weighted by $P$. For this reason KL divergence is not a true distance. The base of the logarithm only changes the unit. The natural log gives nats, and log base 2 gives bits. One nat is about 1.443 bits, so multiply a value in nats by 1.443 to get bits. Use one unit consistently when you compare numbers. ## An everyday picture Think of a weather forecast as a guess $Q$ for how often each kind of day happens. The real climate is $P$. KL divergence is the average extra surprise you feel by planning with the forecast's odds instead of the real ones. The closer the guess matches the real odds, the smaller the surprise. ## Worked example: A fair coin and a biased guess The real coin is fair: $P(\text{heads}) = 0.5$ and $P(\text{tails}) = 0.5$. A model guesses $Q(\text{heads}) = 0.9$ and $Q(\text{tails}) = 0.1$. Use the natural log, so the answer is in nats. 1. Heads term: $P(\text{heads}) \ln \frac{P(\text{heads})}{Q(\text{heads})} = 0.5 \ln \frac{0.5}{0.9} = 0.5 \times (-0.5878) = -0.2939$. 2. Tails term: $P(\text{tails}) \ln \frac{P(\text{tails})}{Q(\text{tails})} = 0.5 \ln \frac{0.5}{0.1} = 0.5 \times 1.6094 = 0.8047$. 3. Add the terms: $D_{KL}(P \| Q) = -0.2939 + 0.8047 = 0.5108$ nats, which is about $0.737$ bits. 4. Swap the roles to check the asymmetry: $D_{KL}(Q \| P) = 0.9 \ln \frac{0.9}{0.5} + 0.1 \ln \frac{0.1}{0.5} = 0.5290 - 0.1609 = 0.3681$ nats. **Answer:** The divergence of the guess $Q$ from the truth $P$ is about **0.511 nats**. The reverse direction gives about **0.368 nats**. The two numbers differ, which is why KL divergence is not symmetric and not a distance. ## Common mistakes - Treating KL divergence as a distance. It is not symmetric, so $D_{KL}(P \| Q)$ and $D_{KL}(Q \| P)$ can differ, and it does not obey the triangle inequality. - Mixing up the order. The first distribution is the one the average is weighted by. Swapping the arguments answers a different question, as the example shows. - Putting a zero in $Q$ where $P$ is not zero. The term $\ln(P/0)$ is infinite, so the divergence becomes infinite. Models often add a tiny amount to every probability to avoid this. - Comparing a value in nats with a value in bits. They differ by a factor of about 1.443, so the units must match before you compare. ## Where you will meet it - Training variational autoencoders, where a KL term keeps the learned distribution close to a simple prior distribution. - Knowledge distillation, where a small student model is trained to match the output probabilities of a larger teacher model. - Fine-tuning large language models, where a KL penalty often keeps the tuned model close to a reference model. - Information theory, where it measures the extra bits needed to encode data with the wrong probabilities. ## Questions people ask ### Why is it not symmetric? Because the average is weighted by $P$. Changing which distribution is the weight changes the answer. In many machine learning uses, $P$ is the data and $Q$ is the model. ### Can KL divergence be negative? No. It is always 0 or more, and it is 0 only when $P$ and $Q$ are the same. This follows from Gibbs' inequality, a standard result in information theory. ### What is the Jensen-Shannon divergence? It averages the KL divergences from $P$ and from $Q$ to their common mixture. The result is symmetric and always finite, and the square root of it is a true distance. ### How does KL divergence relate to cross-entropy? Cross-entropy equals the entropy of $P$ plus $D_{KL}(P \| Q)$. When $P$ is fixed, minimizing cross-entropy is the same as minimizing the KL divergence. ## Related formulas - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) ## Sources - [Kullback-Leibler divergence, Wikipedia](https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence) - [Entropy (information theory), Wikipedia](https://en.wikipedia.org/wiki/Entropy_(information_theory)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Naive Bayes Classifier > Naive Bayes guesses the most likely class by multiplying how common the class is by how well each clue fits it. Page: https://formulabro.yunusemrevurgun.com/ai-ml/naive-bayes-classifier/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P(y \mid x_1, \dots, x_n) \propto P(y) \prod_{i=1}^{n} P(x_i \mid y) $$ Read it out loud: "The probability of class y, given features x 1 through x n, is proportional to the probability of y, times the product, for i from 1 to n, of the probability of x sub i given y." ## What each symbol means - $P(y \mid x_1, \dots, x_n)$: The probability of class $y$ after you see all the features. This is the score you care about. The features are the clues, such as the words in an email. - $\propto$: Is proportional to. The two sides differ only by a constant factor that is the same for every class. Divide all the scores by their total to get real probabilities. - $y$: One class label, such as spam or not spam. - $x_1, \dots, x_n$: The features: the $n$ clues observed for one example, such as whether the word *free* appears in an email. - $n$: The number of features. It has no unit. - $P(y)$: The prior: the share of training examples that belong to class $y$, before looking at the features. - $\prod_{i=1}^{n}$: Multiply together, for every $i$ from 1 to $n$. - $P(x_i \mid y)$: The likelihood: how often feature $x_i$ shows up among the examples of class $y$. ## What the formula is doing Naive Bayes is a classifier built on Bayes' theorem. For each possible class $y$, it asks: given the features I can see, how probable is this class? It then picks the class with the highest score. Training is fast, and the method often works well on text. It starts with the prior $P(y)$, the share of training examples in that class. A class that is common in the training data begins with a higher score. Then, for each feature, it multiplies by the likelihood $P(x_i \mid y)$, which measures how typical that feature is for the class. The word *naive* refers to an assumption: once the class is known, the features are treated as independent of one another. That lets the joint likelihood split into a product of separate terms, one per feature. In real text, words are not independent, so the assumption is wrong. The classifier often still ranks the classes well. The $\propto$ sign hides a constant. The probability of the features, $P(x_1, \dots, x_n)$, is the same for every class, so it can be dropped when you only need to compare scores. To get actual probabilities, divide each class score by the sum of all the class scores. In practice, sums of logarithms replace the products, which avoids numbers too tiny for a computer to store. ## An everyday picture A doctor starts with how common each illness is in the clinic, then adjusts for each symptom: some symptoms are common with one illness and rare with another. The illness with the highest adjusted score is the first guess. Naive Bayes does the same with classes and word clues in an email. ## Worked example: Spam or not spam, with made-up word statistics All numbers here are made up for this example and are not measured from real email. Assume the training data is 40% spam and 60% not spam. Assume the email contains two words, *free* and *prize*, with these invented probabilities: $P(\text{free} \mid \text{spam}) = 0.30$, $P(\text{free} \mid \text{not spam}) = 0.02$, $P(\text{prize} \mid \text{spam}) = 0.10$ and $P(\text{prize} \mid \text{not spam}) = 0.01$. 1. Spam score: $P(\text{spam}) \times P(\text{free} \mid \text{spam}) \times P(\text{prize} \mid \text{spam}) = 0.4 \times 0.30 \times 0.10 = 0.012$. 2. Not spam score: $P(\text{not spam}) \times P(\text{free} \mid \text{not spam}) \times P(\text{prize} \mid \text{not spam}) = 0.6 \times 0.02 \times 0.01 = 0.00012$. 3. Add the scores: $0.012 + 0.00012 = 0.01212$. 4. Divide each score by the total: $P(\text{spam} \mid \text{words}) = \frac{0.012}{0.01212} \approx 0.990$, and $P(\text{not spam} \mid \text{words}) \approx 0.010$. **Answer:** Under these invented numbers, the filter gives the email about a **99% chance** of being spam. Both words are far more common in the made-up spam examples, so the spam score wins easily, even though spam is the smaller class in the training data. ## Common mistakes - Forgetting the prior. Ignoring how common each class is throws away information about the base rates. - Letting one unseen word wipe out a class. If a word never appears in the training spam, its probability is 0 and the whole product becomes 0. Smoothing, such as adding a small count to every word, avoids this. - Multiplying many small probabilities directly. Long emails produce numbers too small for a computer to store accurately. Add logarithms instead of multiplying. - Reading the raw class scores as probabilities. The scores must be divided by their total before they add up to 1. ## Where you will meet it - Email spam filtering, the classic early use of this method. - Sentiment analysis of short reviews, as a fast baseline before trying heavier models. - Sorting news articles or support tickets into topics, using the words each message contains. - Real-time text classification on small devices, because prediction needs only a few lookups and multiplications. ## Questions people ask ### Why is it called naive? Because it assumes the features are independent once the class is known. That assumption is often false, for example when words tend to appear together, but the method is still useful. ### How is it different from logistic regression? Naive Bayes models how each feature appears within each class and then applies Bayes' theorem. Logistic regression learns weights that separate the classes directly and does not assume independence. Both can give probabilities. ### Does it need a lot of training data? It often works with modest amounts of data, because it estimates the probability of each feature separately. The estimates are still noisy when a class has very few examples. ### Why do we not divide by the probability of the features? That probability is the same for every class. Dividing by it changes all the scores by the same factor, so it does not change which class wins. It is needed only when you want exact probabilities. ## Related formulas - [Bayes' Theorem](https://formulabro.yunusemrevurgun.com/ai-ml/bayes-theorem/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) ## Sources - [Naive Bayes classifier, Wikipedia](https://en.wikipedia.org/wiki/Naive_Bayes_classifier) - [Naive Bayes spam filtering, Wikipedia](https://en.wikipedia.org/wiki/Naive_Bayes_spam_filtering) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Gini Impurity > Gini impurity is a score for how mixed the classes are in a group: 0 means every item in the group belongs to the same class. Page: https://formulabro.yunusemrevurgun.com/ai-ml/gini-impurity/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ G = 1 - \sum_{k=1}^{K} p_k^2 $$ Read it out loud: "G equals 1 minus the sum, for k from 1 to K, of p sub k squared." ## What each symbol means - $G$: The Gini impurity of one node. It is 0 for a pure node and largest when all classes are equally common. It has no unit. - $K$: The number of classes, such as red and blue, or cat, dog and bird. - $k$: The number of one class, counting from 1 to $K$. - $p_k$: The share of examples in the node that belong to class $k$. It is a number from 0 to 1, and all the shares add up to 1. - $\sum_{k=1}^{K}$: Add up for every class $k$ from 1 to $K$. ## What the formula is doing A decision tree splits its examples with questions, such as is the height above 150 cm. Ideally, each group of examples at a node contains one class only. Gini impurity measures how far a node is from that ideal. Its value runs from 0 up to $1 - 1/K$. Each $p_k$ is the share of class $k$. Squaring a share makes big shares count much more than small ones. If one class fills the node, one $p_k$ is 1 and the rest are 0. The squares add up to 1, so $G = 0$: a pure node. If the classes are evenly mixed, the squares add up to less, so $G$ rises. With $K$ equal shares the sum is $1/K$, which gives the maximum $G = 1 - 1/K$. There is a useful way to read $G$. The sum $\sum_k p_k^2$ is the chance that two examples drawn at random from the node, with replacement, belong to the same class. So $G$ is the chance that two random draws come from different classes. A split is judged by the weighted average of the Gini values of its child nodes, with each child weighted by its number of examples. The tree picks the split that lowers this average the most. The CART method, used by many decision tree libraries, works this way for classification. ## An everyday picture Picture a bag of marbles. Draw one marble, note its color, put it back and draw again. Gini impurity is the chance that the second marble has a different color from the first. A bag with only red marbles never gives a different color, so its impurity is 0. A bag with equal numbers of two colors gives a different color half the time. ## Worked example: A split that separates the colors A node holds 10 examples: 6 red and 4 blue. A question splits them into a left child with 5 red and 0 blue, and a right child with 1 red and 4 blue. 1. Parent node: $p_{\text{red}} = 0.6$ and $p_{\text{blue}} = 0.4$, so $G = 1 - (0.6^2 + 0.4^2) = 1 - (0.36 + 0.16) = 0.48$. 2. Left child: 5 red and 0 blue, so $p_{\text{red}} = 1$ and $G = 1 - 1^2 = 0$. It is pure. 3. Right child: 1 red and 4 blue out of 5, so $p_{\text{red}} = 0.2$ and $p_{\text{blue}} = 0.8$. Then $G = 1 - (0.2^2 + 0.8^2) = 1 - (0.04 + 0.64) = 0.32$. 4. Weighted average of the children: each child holds 5 of the 10 examples, so the average is $\frac{5}{10} \times 0 + \frac{5}{10} \times 0.32 = 0.16$. 5. Impurity drop: $0.48 - 0.16 = 0.32$. **Answer:** The split lowers the Gini impurity from **0.48** to **0.16**, a drop of **0.32**. The left child is pure and the right child is mostly blue. Among candidate splits, a tree would prefer the one with the lowest weighted Gini. ## Common mistakes - Confusing Gini impurity with the Gini coefficient, a different measure of income inequality. They share a name but not a purpose. - Forgetting to weight the children. A tiny pure child should not count as much as a large mixed one. - Treating $G$ as the error rate. $G$ measures mixing, not the share of wrong predictions. Predicting the majority class gives an error rate of $1 - \max_k p_k$, which is a different number. - Using Gini to score a regression tree. Regression trees use a different measure, such as the variance of the target values in each node. ## Where you will meet it - CART decision trees, which use Gini impurity to choose each split for classification. - Random forests, which build many decision trees and often use Gini impurity to score their splits. - The decision tree classifier in scikit-learn, where Gini is the default split criterion. ## Questions people ask ### Is Gini impurity the same as entropy? No, but both measure how mixed a node is. Entropy uses logarithms, while Gini uses squares, and entropy's maximum is $\log_2 K$ bits instead of $1 - 1/K$. The two often choose the same split. The information gain page on this site covers the entropy version. ### What is the largest possible Gini value? It is $1 - 1/K$, reached when all $K$ classes have equal shares. With two classes that is 0.5, and with three classes it is about 0.667. ### What does a Gini value of 0 mean? The node is pure: every example belongs to one class. No split can lower its impurity, so a tree stops splitting that branch. ### Is a low Gini always good? A low value at a leaf looks good on the training data, but a tree that splits until every leaf is pure can memorize noise. Limits such as a maximum depth guard against that. ## Related formulas - [Information Gain](https://formulabro.yunusemrevurgun.com/ai-ml/information-gain/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Classification Accuracy](https://formulabro.yunusemrevurgun.com/ai-ml/classification-accuracy/) ## Sources - [Decision tree learning, Wikipedia](https://en.wikipedia.org/wiki/Decision_tree_learning) - [Decision Trees, scikit-learn user guide](https://scikit-learn.org/stable/modules/tree.html) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Information Gain > Information gain tells you how many bits of guessing a split removes, so a tree can ask the question that sorts the examples best. Page: https://formulabro.yunusemrevurgun.com/ai-ml/information-gain/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \mathrm{IG} = H(\text{parent}) - \sum_{k} \frac{n_k}{n}\, H(\text{child}_k) $$ Read it out loud: "Information gain equals the entropy of the parent node, minus the sum over every child k of n sub k over n, times the entropy of child k." ## What each symbol means - $\mathrm{IG}$: Information gain: the drop in entropy caused by the split, measured in bits because entropy uses log base 2. For a split of this kind it is never negative. - $H(\text{parent})$: The entropy of the node before the split, in bits. - $H(\text{child}_k)$: The entropy of child node $k$ after the split, in bits. - $H$: Entropy in bits: $H = -\sum_j p_j \log_2 p_j$, where $p_j$ is the share of class $j$ in the node. A pure node has $H = 0$. An even split between two classes has $H = 1$ bit. - $n$: The number of examples in the parent node, before the split. It has no unit. - $n_k$: The number of examples the split sends to child $k$. - $k$: The index of a child node, counting from 1 to the number of children. - $\sum_{k}$: Add up over every child $k$. ## What the formula is doing A decision tree splits its examples into groups with questions. Information gain asks how much a question reduces the uncertainty about the class. The uncertainty of a node is measured by its entropy $H$, in bits. A node with one class has entropy 0. A node that is evenly mixed between two classes has entropy 1 bit. Entropy is $H = -\sum_j p_j \log_2 p_j$, where $p_j$ is the share of class $j$. Each term takes a share, multiplies it by the logarithm of that share and flips the sign. The logarithm is base 2, so the unit is the bit: one bit is the uncertainty removed by one fair yes-or-no answer. The gain starts from the entropy of the parent node. It then subtracts the average entropy of the children. Each child's entropy is weighted by $\frac{n_k}{n}$, the fraction of examples sent to that child, so a large mixed child counts for more than a tiny one. The gain is the uncertainty removed. If the children are purer than the parent, the weighted average is lower and the gain is positive. A split that leaves the class mix unchanged has a gain of 0. For splits like this one, the weighted child average never exceeds the parent's entropy, so the gain is never negative. ## An everyday picture Think of a game of twenty questions. The best question splits the remaining candidates close to evenly, so its answer removes the most uncertainty. A question whose answer you already know removes nothing. Information gain scores each possible question this way, and the tree asks the highest-scoring one first. ## Worked example: One split of ten examples A node holds 10 examples: 6 red and 4 blue. A question sends 5 examples to the left child, all red, and the other 5 to the right child, which has 1 red and 4 blue. 1. Parent entropy: $H(\text{parent}) = -(0.6 \log_2 0.6 + 0.4 \log_2 0.4) \approx 0.971$ bits. 2. Left child, 5 red and 0 blue: it is pure, so $H = 0$. Its weight is $\frac{5}{10} = 0.5$. 3. Right child, 1 red and 4 blue: $H = -(0.2 \log_2 0.2 + 0.8 \log_2 0.8) \approx 0.722$ bits. Its weight is $\frac{5}{10} = 0.5$. 4. Weighted average of the children: $0.5 \times 0 + 0.5 \times 0.722 \approx 0.361$ bits. 5. Information gain: $\mathrm{IG} = 0.971 - 0.361 \approx 0.610$ bits. **Answer:** The split removes about **0.61 bits** of uncertainty about the color. The left branch is pure, and the right branch still has some mixing. A decision tree would compare this gain with the gain of every other candidate question and keep the largest. ## Common mistakes - Forgetting the weights. The child entropies must be averaged with weights $\frac{n_k}{n}$, not with a plain average over the children. - Leaving out the parent entropy. The gain is the drop from the parent's entropy, so the children's entropy alone does not give you the gain. - Favoring questions with many answers. A question that splits examples into many small groups can score well without generalizing. The C4.5 algorithm corrects this with a measure called gain ratio. - Mixing log bases. Entropy in bits uses $\log_2$. Using the natural log gives nats, which are a different unit and cannot be compared directly. ## Where you will meet it - The ID3 and C4.5 decision tree algorithms, which choose splits by information gain. C4.5 uses a normalized version called gain ratio. - Feature selection, where features are ranked by how much they tell you about the class. The same quantity is called mutual information. - Decision tree libraries with an entropy option, such as scikit-learn when the split criterion is set to entropy. ## Questions people ask ### Why use log base 2? Because one bit is the uncertainty removed by one fair yes-or-no answer. Base 2 makes entropy count bits, which is the natural unit for questions like these. ### Can information gain be zero? Yes. If the child nodes have the same class mix as the parent, the weighted average equals the parent's entropy, so the gain is 0. Such a split tells the tree nothing new. ### How does it compare with Gini impurity? Both measure impurity, and both are used to pick tree splits. Entropy uses a logarithm and Gini uses squares. The two often choose the same split. The Gini impurity page on this site covers the other measure. ### Is information gain only for decision trees? No. The same quantity is called mutual information. It measures how much knowing one variable tells you about another, and it is used in feature selection and in communication theory. ## Related formulas - [Gini Impurity](https://formulabro.yunusemrevurgun.com/ai-ml/gini-impurity/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Kullback-Leibler Divergence](https://formulabro.yunusemrevurgun.com/ai-ml/kl-divergence/) ## Sources - [Decision tree learning, Wikipedia](https://en.wikipedia.org/wiki/Decision_tree_learning) - [Entropy (information theory), Wikipedia](https://en.wikipedia.org/wiki/Entropy_(information_theory)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Softmax Temperature > Temperature is a dial that makes a model's choices more focused when it is low and more varied when it is high. Page: https://formulabro.yunusemrevurgun.com/ai-ml/softmax-temperature/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ p_i = \frac{e^{z_i / T}}{\sum_{j=1}^{K} e^{z_j / T}} $$ Read it out loud: "The probability p sub i equals e to the power of z sub i divided by T, all divided by the sum, over every score j, of e to the power of z sub j divided by T." ## What each symbol means - $p_i$: The probability of answer number $i$ after the temperature is applied. It is a number between 0 and 1, and all the probabilities add up to 1. - $z_i$: The raw score (logit) for answer number $i$. It can be any real number, even a negative one. - $T$: The **temperature**, a positive number with no unit. $T = 1$ gives the ordinary softmax. A smaller $T$ sharpens the output, and a larger $T$ flattens it. - $K$: How many answers there are, so how many scores are in the list. - $\sum_{j=1}^{K}$: "Add up for every $j$ from 1 to $K$": the total over all the scaled scores, used as the bottom of the fraction. - $e$: Euler's number, about 2.718. Raising it to a power keeps every result positive. ## What the formula is doing Softmax turns a list of raw scores into probabilities. Temperature adds one more knob. Before the usual softmax steps, every score is divided by $T$. That is the only change: the formula is still $e$ raised to each scaled score, divided by the total. A small $T$ makes the gaps between the scores bigger. Dividing by $0.5$ doubles every score, so the best answer pulls further ahead of the rest. The output becomes sharper, and the most likely answer takes most of the probability. As $T$ shrinks toward zero, the top answer gets almost everything. A large $T$ does the opposite. Dividing by $2$ halves every score, so the gaps shrink and the probabilities move toward equal shares. A large temperature makes the choices more varied, because lower-ranked answers get picked more often. The ranking never changes. Any positive $T$ keeps the best answer on top and the worst at the bottom. Temperature only changes how much of the probability goes to the top answer. ## An everyday picture Think of a spotlight on a stage. At a low temperature the beam is narrow, so only the brightest performer is lit. At a high temperature the beam spreads out, and every performer on stage gets some light. The performers and their order stay the same; only the amount of light changes. ## Worked example: Choosing the next word at two temperatures A language model scores three possible next words, *cat*, *dog* and *bird*, with raw scores $z = (2.0,\ 1.0,\ 0.1)$. At the usual $T = 1$, the probability of *cat* is 65.9%. Now try $T = 0.5$ and $T = 2$. 1. For $T = 0.5$, divide each score by $0.5$: $z / T = (4.0,\ 2.0,\ 0.2)$. 2. Raise $e$ to each new score: $e^{4.0} \approx 54.598$, $e^{2.0} \approx 7.389$ and $e^{0.2} \approx 1.221$. Their total is $63.209$. 3. Divide each one by the total: $\frac{54.598}{63.209} \approx 0.864$ for *cat*, $\frac{7.389}{63.209} \approx 0.117$ for *dog* and $\frac{1.221}{63.209} \approx 0.019$ for *bird*. Check: $0.864 + 0.117 + 0.019 = 1.000$. 4. For $T = 2$, divide by $2$ instead: $z / T = (1.0,\ 0.5,\ 0.05)$. Raising $e$ to these gives about $2.718$, $1.649$ and $1.051$, with a total of $5.418$. Dividing gives *cat* $\approx 0.502$, *dog* $\approx 0.304$ and *bird* $\approx 0.194$. **Answer:** At $T = 0.5$, *cat* rises to about **86.4%** and *bird* falls to 1.9%. At $T = 2$, *cat* drops to about **50.2%** and *bird* rises to 19.4%. *Cat* is the top answer at both temperatures; only the spread changes. ## Common mistakes - Setting $T = 0$ and dividing by it. The temperature must be greater than zero. Code that wants only the top answer uses an argmax instead. - Expecting a high temperature to keep the top answer dominant. A higher $T$ spreads the probability out, so the top answer loses its lead even though it stays on top. - Applying the temperature to the finished probabilities. The division has to happen on the raw scores, before the $e$ step. Dividing the probabilities by $T$ does not give the same result. - Thinking a temperature setting makes the model smarter or more accurate. It changes only how the same scores are turned into probabilities. ## Where you will meet it - Sampling text from large language models, where a temperature setting controls how predictable or varied the output is. - Knowledge distillation, where a teacher model's scores are softened with a high temperature so a smaller student model can learn from how the wrong answers rank. - Temperature scaling, a method for adjusting how confident a trained classifier's probabilities look. - Exploration in reinforcement learning, where a softmax over action values, with a temperature, picks better actions more often without always picking the best one. ## Questions people ask ### What is the temperature for, in one sentence? It divides every raw score by $T$ before softmax, so a small $T$ makes the top answer stand out and a large $T$ makes the choices more even. ### Which temperature is normal? $T = 1$. With that value the formula is the ordinary softmax, with no change to the scores. ### Can temperature change which answer wins? No. Dividing every score by the same positive number keeps their order. Only the spread of the probabilities changes. ### What happens as $T$ gets very close to zero? The biggest score takes almost all the probability, so the output approaches picking the top answer every time. ## Related formulas - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Perplexity](https://formulabro.yunusemrevurgun.com/ai-ml/perplexity/) ## Sources - [Softmax function, Wikipedia](https://en.wikipedia.org/wiki/Softmax_function) - [Knowledge distillation, Wikipedia](https://en.wikipedia.org/wiki/Knowledge_distillation) - [Hinton, Vinyals and Dean, Distilling the Knowledge in a Neural Network (arXiv:1503.02531)](https://arxiv.org/abs/1503.02531) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Perplexity > Perplexity counts how many words a language model is, on average, torn between each time it guesses the next word. Lower is better. Page: https://formulabro.yunusemrevurgun.com/ai-ml/perplexity/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{PPL} = \exp\left(-\frac{1}{N}\sum_{i=1}^{N} \ln p(w_i \mid w_{ Positional encoding stamps each word with a pattern of waves that says where it sits in the sentence. Page: https://formulabro.yunusemrevurgun.com/ai-ml/positional-encoding/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{PE}_{(pos,\,2i)} = \sin\left(\frac{pos}{10000^{2i/d}}\right) \qquad \text{PE}_{(pos,\,2i+1)} = \cos\left(\frac{pos}{10000^{2i/d}}\right) $$ Read it out loud: "PE at position pos, index 2i, equals the sine of pos divided by 10000 to the power 2i over d. PE at index 2i plus 1 equals the cosine of the same angle." ## What each symbol means - $\text{PE}_{(pos,\,2i)}$: The encoding value at position $pos$ in an even dimension, $2i$. It is a plain number with no unit, and it is added to the word embedding. - $\text{PE}_{(pos,\,2i+1)}$: The encoding value at the same position in the next, odd dimension. Each even and odd pair shares the same frequency. - $pos$: The position of the word in the sequence, starting from 0 for the first word. - $i$: The index of a pair of dimensions, running from 0 up to $d/2 - 1$. A small $i$ gives a fast wave, and a large $i$ gives a slow wave. - $d$: The size of the encoding, the same number of dimensions as the word embedding. It is an even number, such as 512 in the base model of the original paper. - $10000$: A fixed constant from the original paper. It sets how long the slowest wave is. It has no unit. ## What the formula is doing A transformer reads all the words at once, so attention on its own has no sense of order. Without extra information, *dog bites man* and *man bites dog* would look like the same set of vectors. Positional encoding fixes that by adding a position signal to each word's embedding. Each position $pos$ gets a vector with $d$ numbers, the same size as the word embedding. The numbers come in pairs. Dimensions $2i$ and $2i+1$ share one frequency, set by $10000^{2i/d}$. The first number of each pair is a sine and the second is a cosine, so each pair traces a point around a circle as the position grows. The frequencies form a geometric series, so the waves run from fast to slow. Low-index pairs change quickly from one position to the next, which separates nearby words. High-index pairs change slowly, which tracks position across long spans. Together they give each position its own pattern. The vector is added to the embedding rather than appended to it. Vaswani et al. chose sine and cosine because they hypothesized the model could then learn to attend by relative position: for any fixed offset, the encoding at one position can be written as a linear function of the encoding at another. They also hoped the pattern would let the model handle sequences longer than those seen in training. ## An everyday picture Think of a clock with several hands that turn at different speeds. The fastest hand tells you small differences in time, and the slowest hand tells you where you are in a long day. Read all the hands together and the time is unique. Positional encoding works the same way: the fast waves tell neighboring positions apart, and the slow waves place words far down the sentence. ## Worked example: Encoding position 2 in a four-number vector Use $d = 4$, so each position gets four numbers in two pairs. Find the encoding for position $pos = 2$. 1. Work out each pair's divisor. For $i = 0$: $10000^{0/4} = 1$. For $i = 1$: $10000^{2/4} = 100$. 2. Pair 0 (dimensions 0 and 1) uses the angle $2 / 1 = 2$ radians. So $\text{PE}_{(2,0)} = \sin(2) \approx 0.9093$ and $\text{PE}_{(2,1)} = \cos(2) \approx -0.4161$. 3. Pair 1 (dimensions 2 and 3) uses the angle $2 / 100 = 0.02$ radians. So $\text{PE}_{(2,2)} = \sin(0.02) \approx 0.0200$ and $\text{PE}_{(2,3)} = \cos(0.02) \approx 0.9998$. 4. Stack the four values. The encoding for position 2 is $(0.9093,\ -0.4161,\ 0.0200,\ 0.9998)$, and it is added to the embedding of the word at position 2. **Answer:** The position vector for position 2 is **(0.9093, -0.4161, 0.0200, 0.9998)**. The first pair changes quickly from one position to the next, so it separates neighboring words. The second pair changes slowly, so it carries a longer-range signal. ## Common mistakes - Adding a plain position number, such as 2, to the embedding. A single number is not bounded and carries no pattern across dimensions, so the formula spreads position over many waves instead. - Using an odd embedding size. The sine and cosine values come in pairs that share a frequency, so $d$ should be even. - Assuming sinusoidal encodings are the only option. Many models learn their position vectors during training, and others use rotary methods that build position into the attention itself. - Believing the formula alone limits how long the input can be. It gives a value for any position, but a model may still handle very long inputs poorly. ## Where you will meet it - The original transformer for machine translation in Vaswani et al. (2017), which adds these sine and cosine vectors to the input embeddings. - Early transformer language models and other sequence models that need order information, since attention alone treats its inputs as an unordered set. - Newer position methods, such as learned position vectors and rotary encodings, which many later models use instead of the fixed sine and cosine pattern. - Any transformer that reads a sequence all at once, such as models for text, audio or time series, wherever the order of the steps matters. ## Questions people ask ### Why use sine and cosine instead of plain numbers? Sine and cosine stay between $-1$ and $1$, so the values never grow with the position. Mixing many frequencies also gives each position its own pattern. ### Why does each pair have both a sine and a cosine? A sine alone repeats, so two different angles can give the same value. Pairing it with a cosine places each pair on a circle, so the angle, and therefore the position, can be read without confusion. ### Is the encoding learned during training? Not in the original paper. The formula is fixed. Other models learn their position vectors as part of training. ### Does the encoding change the meaning of a word? It shifts the word's vector by a position-dependent amount. The model learns to use both the meaning part and the position part when it attends to other words. ## Related formulas - [Scaled Dot-Product Attention](https://formulabro.yunusemrevurgun.com/ai-ml/scaled-dot-product-attention/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Perplexity](https://formulabro.yunusemrevurgun.com/ai-ml/perplexity/) ## Sources - [Vaswani et al., Attention Is All You Need (arXiv:1706.03762)](https://arxiv.org/abs/1706.03762) - [Transformer (deep learning), Wikipedia](https://en.wikipedia.org/wiki/Transformer_(deep_learning)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Convolution Output Size > This formula counts how many spots a small sliding window can land on across an image, so you know how big a convolution layer's output will be. Page: https://formulabro.yunusemrevurgun.com/ai-ml/convolution-output-size/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ O = \left\lfloor \frac{W - K + 2P}{S} \right\rfloor + 1 $$ Read it out loud: "O equals the floor of W minus K plus 2 P, all divided by S, then plus 1. The floor means round down to a whole number." ## What each symbol means - $O$: The **output size**: how many values the layer produces along one side, such as its width. A whole number of pixels. - $W$: The **input size** along the same side, such as the width of the image in pixels. - $K$: The **kernel size**, the width of the sliding window, in pixels. - $P$: The **padding**, the number of extra pixels added on each side of the input, in pixels. - $S$: The **stride**, how many pixels the window jumps between positions, in pixels. - $\left\lfloor x \right\rfloor$: The **floor** of $x$: the largest whole number that is not greater than $x$. It rounds down, so $15.5$ becomes $15$. ## What the formula is doing A convolutional layer slides a small window, the kernel, across its input. At each stop it multiplies and adds the values under the window. The output size $O$ is how many stops fit along one side. The input size is $W$, the kernel is $K$ pixels wide, the padding is $P$ pixels on each side and the stride is $S$ pixels per jump. Start with $W - K + 2P$. The window has to fit inside the padded input. The padded input is $W + 2P$ pixels long and the window covers $K$ of them, so the room left for the window to move is $W + 2P - K$. Padding adds room on both sides, which is why it appears twice. Divide by $S$ to count the jumps. Each jump moves the window $S$ pixels, so the room is divided by the jump size. The floor drops any partial jump, because a window that cannot fit completely is not used. Finally add 1, because the first position at the very start also counts. Padding and stride are the two knobs. Padding keeps the edge pixels in play and, with the right amount, keeps the output the same size as the input. A stride of 2 makes the window jump two pixels at a time, so the output is about half as wide and half as tall. ## An everyday picture Think of a cardboard frame of fixed width that slides along a shelf, taking a snapshot at each stop. The frame may only stop where it fits entirely on the shelf. Padding is like adding a little extra shelf at each end. The stride is how far you slide between snapshots, and the number of snapshots is the output size. ## Worked example: Output width of a 3 by 3 convolution on a 32-pixel image The input is $W = 32$ pixels wide. The kernel is $K = 3$ pixels wide, the padding is $P = 1$ pixel on each side and the stride is $S = 2$ pixels. 1. Subtract the kernel and add the padding on both sides: $W - K + 2P = 32 - 3 + 2 \times 1 = 31$. 2. Divide by the stride: $\frac{31}{2} = 15.5$. 3. Round down with the floor: $\lfloor 15.5 \rfloor = 15$. 4. Add 1: $O = 15 + 1 = 16$. **Answer:** The output is **16 pixels** wide. The stride of 2 roughly halves the width. For comparison, with stride 1 and the same padding, the output would be 32 pixels wide, the same as the input. ## Common mistakes - Forgetting the floor when the division is not exact. $31 / 2$ is not a whole number, so round it down to 15 before adding 1. - Adding $2P$ when the padding is on one side only. The formula assumes the same padding on both sides. - Forgetting the $+1$. The first position counts too, so 5 pixels with no padding, a kernel of 3 and stride 1 give 3 positions, not 2. - Using this formula for dilated or transposed convolutions. Dilation makes the window larger, and transposed convolutions run the other way, so they need their own size rules. ## Where you will meet it - Designing image classifiers layer by layer, to track how the height and width shrink through the network. - Choosing padding so a layer keeps its input size, which is what 'same' padding means in many deep learning libraries. - Pooling layers, which use the same kind of arithmetic with their own window size and stride. - Checking the shape of a network's output before training, so that the next layer receives the size it expects. ## Questions people ask ### What is a kernel? The small grid of weights that slides over the input. A $3 \times 3$ kernel covers 3 pixels in each direction at every stop. ### Does the formula work for height and width separately? Yes. Apply it to the height and to the width on their own. If the input, kernel, padding and stride are the same in both directions, the output is square. ### Why does a stride of 2 roughly halve the size? Dividing by 2 halves the number of jumps the window can make, so the output is about half as wide and half as tall. ### What if the result is not a whole number? The floor rounds it down. The last partial window does not fit, so the formula does not count it. ## Related formulas - [Artificial Neuron (Weighted Sum)](https://formulabro.yunusemrevurgun.com/ai-ml/artificial-neuron/) - [Sigmoid Function](https://formulabro.yunusemrevurgun.com/ai-ml/sigmoid-function/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Convolutional neural network, Wikipedia](https://en.wikipedia.org/wiki/Convolutional_neural_network) - [Stanford CS231n, Convolutional Neural Networks notes](https://cs231n.github.io/convolutional-networks/) - [Dumoulin and Visin, A guide to convolution arithmetic for deep learning (arXiv:1603.07285)](https://arxiv.org/abs/1603.07285) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # R-Squared > R-squared is a score that says how much of the ups and downs in the data a model predicts correctly. A perfect model scores 1. Page: https://formulabro.yunusemrevurgun.com/ai-ml/r-squared/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ R^2 = 1 - \frac{SS_{res}}{SS_{tot}} $$ Read it out loud: "R squared equals 1 minus the ratio of SS res to SS tot. SS res is the sum of the squared gaps between each actual value and its prediction. SS tot is the sum of the squared gaps between each actual value and the mean." ## What each symbol means - $R^2$: **R-squared**, the coefficient of determination. A plain number with no unit. 1 means perfect predictions, and 0 means no better than always guessing the average. - $SS_{res}$: The **residual sum of squares**, $\sum_i (y_i - \hat y_i)^2$: the total squared miss of the model's predictions. Its unit is the square of the output's unit. - $SS_{tot}$: The **total sum of squares**, $\sum_i (y_i - \bar y)^2$: the total squared distance of the actual values from their mean. Its unit is the square of the output's unit. - $y_i$: The actual value for data point number $i$, such as a quiz score in points. - $\hat y_i$: The model's predicted value for data point $i$, read as y hat. Same unit as $y_i$. - $\bar y$: The mean (average) of all the actual values $y_i$. Same unit as $y_i$. - $\sum_i$: "Add up for every data point $i$": the total over all the points. ## What the formula is doing R-squared compares the model with the simplest possible guess. That guess is the average of all the actual values, $\bar y$, used for every point. The total squared distance of the values from that average is $SS_{tot} = \sum (y_i - \bar y)^2$. It is the error the simplest guess makes. The model's own error is $SS_{res} = \sum (y_i - \hat y_i)^2$, the squared gap between each actual value and its prediction. Squaring makes every miss count as positive, and it punishes big misses more than small ones. The ratio $\frac{SS_{res}}{SS_{tot}}$ is the share of the spread that the model failed to explain. Subtracting it from 1 gives the share it did explain. A model with perfect predictions has $SS_{res} = 0$, so $R^2 = 1$. A model that predicts only the average has $SS_{res} = SS_{tot}$, so $R^2 = 0$. R-squared can go below zero. That happens when the predictions are worse than always guessing the average, for example a badly chosen line, or a model checked on new data it was not built on. For a least-squares line with an intercept, measured on the data it was fitted to, the value sits between 0 and 1. ## An everyday picture Think of guessing the heights of everyone in a class. Your baseline is to guess the class average for every student. R-squared asks how much of that baseline error your smarter guesses removed. Remove all of it and you score 1. Remove none and you score 0. Make things worse and the score drops below zero. ## Worked example: Predicting four quiz scores Four students scored $y = (3,\ 5,\ 7,\ 9)$ points on a quiz. A model predicted $\hat y = (2.5,\ 5.5,\ 7,\ 9.5)$. How well does it explain the scores? 1. Find the average of the actual scores: $\bar y = \frac{3 + 5 + 7 + 9}{4} = 6$ points. 2. Find the total spread around that average: $SS_{tot} = (3 - 6)^2 + (5 - 6)^2 + (7 - 6)^2 + (9 - 6)^2 = 9 + 1 + 1 + 9 = 20$. 3. Find the model's squared misses. The errors are $0.5$, $-0.5$, $0$ and $-0.5$, so $SS_{res} = 0.25 + 0.25 + 0 + 0.25 = 0.75$. 4. Put them together: $R^2 = 1 - \frac{0.75}{20} = 1 - 0.0375 = 0.9625$. **Answer:** **R-squared is 0.9625**, about 0.96. The model explains about 96% of the spread in the scores. It still misses a little, but almost all of the variation is captured. ## Common mistakes - Reading R-squared as proof that the model is right or that one thing causes another. It only measures how closely the predictions follow the data. - Comparing R-squared values across datasets with different outputs. The total spread changes with the data, so the scores are not on a shared scale. - Adding up plain errors instead of squared errors. Positive and negative misses cancel, so the total can be zero even when the predictions are poor. - Expecting R-squared to stay between 0 and 1 for every model. A model worse than the average, or one tested on new data, can give a negative score. ## Where you will meet it - Reporting how well a straight-line or multiple regression fits its data, in statistics textbooks and in spreadsheet trendline displays. - Scoring regression models in machine learning libraries, such as the r2_score function in scikit-learn. - Economics and the social sciences, where a model's R-squared summarizes how much of the variation it accounts for. - Checking how closely a calibration curve follows reference measurements in a laboratory. ## Questions people ask ### Is R-squared the same as correlation? For a straight-line fit with one input, R-squared equals the square of the correlation coefficient $r$. With more inputs or other kinds of model, that shortcut no longer holds. ### What counts as a good R-squared? It depends on the field. Noisy data, such as human behavior, often gives much lower values than a careful physics measurement. Compare it with other models on the same data rather than with a fixed cutoff. ### Why can R-squared be negative? Because $SS_{res}$ can be bigger than $SS_{tot}$. That happens when the predictions are worse than always guessing the average. ### Does adding more inputs always raise R-squared? On the training data, it never goes down when you add an input, even a useless one. Check the score on new data as well before trusting a bigger model. ## Related formulas - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) - [Z-Score Standardization](https://formulabro.yunusemrevurgun.com/ai-ml/z-score-standardization/) ## Sources - [Coefficient of determination, Wikipedia](https://en.wikipedia.org/wiki/Coefficient_of_determination) - [Linear regression, Wikipedia](https://en.wikipedia.org/wiki/Linear_regression) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Q-Learning Update > Q-learning lets an agent improve its guess about how good an action is, a little at a time, using the reward it received on the latest step. Page: https://formulabro.yunusemrevurgun.com/ai-ml/q-learning-update/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ Q(s,a) \leftarrow Q(s,a) + \alpha\left[r + \gamma \max_{a'} Q(s',a') - Q(s,a)\right] $$ Read it out loud: "Q of s, a becomes Q of s, a plus alpha times a bracket. Inside the bracket: the reward r, plus gamma times the largest Q of s prime and a prime, minus Q of s, a." ## What each symbol means - $Q(s,a)$: The agent's current estimate of how good it is to take action $a$ in state $s$: the total future reward it expects. It has no unit and is measured in reward points. - $s$: The **state**, the situation the agent is in now, such as a square in a maze. - $a$: The **action** the agent takes in state $s$, such as moving right. - $r$: The **reward** received right after taking action $a$, in reward points. - $s'$: The **next state**, where the agent ends up after the action. The prime mark means next. - $\max_{a'} Q(s',a')$: The best value available from the next state: the largest $Q$ over all the actions $a'$ the agent could take there. - $\alpha$: The **learning rate**, between 0 and 1. It sets how big a step each update takes. No unit. - $\gamma$: The **discount factor**, between 0 and 1. It sets how much future reward counts compared with reward now. No unit. ## What the formula is doing The agent keeps a table with one number for every pair of state and action, written $Q(s,a)$. Each number is its estimate of the total future reward it can expect after taking action $a$ in state $s$ and playing well afterward. At the start the numbers are guesses. Learning means improving them. After the agent acts, it gets a reward $r$ and lands in a new state $s'$. The best it can expect from there is $\max_{a'} Q(s',a')$. Adding the reward and the discounted best future value gives a new target, $r + \gamma \max_{a'} Q(s',a')$. The target uses one real reward, so it carries more information than the old guess. The bracket is the **TD error**, the gap between the target and the old estimate. The update moves the old estimate a fraction $\alpha$ of the way toward the target. A small $\alpha$ changes the estimate slowly and smooths out noise. A large $\alpha$ reacts quickly but can jump around. The discount factor $\gamma$ sets how far ahead the agent looks. With $\gamma = 0$ only the immediate reward counts. As $\gamma$ nears 1, rewards far in the future count almost as much as rewards now. The update uses the best action in the next state, whatever the agent does next, which is why Q-learning is called off-policy. ## An everyday picture Think of rating a move in a board game. You know what the move gained right away, and you know the best you can expect from the position it leads to. Each time you play, you move your old rating a bit toward the sum of those two. Over many games the ratings settle near the true value of each move. ## Worked example: One update in a grid world The agent is in state $s$ and takes action $a$. Its current estimate is $Q(s,a) = 2.0$. The action gives reward $r = 1.0$ and leads to state $s'$, where the best action has value $\max_{a'} Q(s',a') = 4.0$. Use $\alpha = 0.5$ and $\gamma = 0.9$. 1. Discount the best future value: $\gamma \max_{a'} Q(s',a') = 0.9 \times 4.0 = 3.6$. 2. Add the reward to get the target: $r + \gamma \max_{a'} Q(s',a') = 1.0 + 3.6 = 4.6$. 3. Find the TD error: $4.6 - 2.0 = 2.6$. 4. Update the estimate: $Q(s,a) \leftarrow 2.0 + 0.5 \times 2.6 = 3.3$. **Answer:** The new estimate is **$Q(s,a) = 3.3$**. It moved halfway from 2.0 toward the target of 4.6, because $\alpha = 0.5$. The next time the agent visits this pair, the estimate will be a little closer to the target again. ## Common mistakes - Using the action the agent actually takes next instead of the best one. That is a different method, SARSA, and it gives different values. - Setting $\gamma = 1$ for a task with no end. Future rewards then add up without limit, and the estimates can grow forever. - Adding the reward to the value of the wrong pair. The reward belongs to the step from $s$ to $s'$, so it goes into the update for $Q(s,a)$. - Expecting one update to settle the value. Each update is a small nudge controlled by $\alpha$, and the values improve over many visits. ## Where you will meet it - Teaching agents to move through grids and mazes, a standard example in reinforcement learning courses and textbooks. - Deep Q-networks, which keep the same kind of target but learn the Q values with a neural network instead of a table. - Robot control and scheduling problems, where an agent learns which action pays off most over a long run. - Game-playing agents in research, which estimate the value of each move from the reward and the best next move. ## Questions people ask ### What does the learning rate $\alpha$ do? It sets how big a step each update takes. With $\alpha = 0$ nothing is learned. With $\alpha = 1$ the old estimate is replaced by the target completely. ### Why use the max over the next actions? The estimate should describe the best play from here on. Using the largest next value gives that, so the table can learn the best policy even while the agent sometimes explores at random. ### What happens when an episode ends? There is no next state to value, so the future term is set to zero. The update then uses the reward alone: $Q(s,a) \leftarrow Q(s,a) + \alpha\,[r - Q(s,a)]$. ### Who first described Q-learning? Chris Watkins introduced it in 1989, in his thesis *Learning from Delayed Rewards*. ## Related formulas - [Discounted Return](https://formulabro.yunusemrevurgun.com/ai-ml/discounted-return/) - [Softmax Temperature](https://formulabro.yunusemrevurgun.com/ai-ml/softmax-temperature/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Q-learning, Wikipedia](https://en.wikipedia.org/wiki/Q-learning) - [Reinforcement learning, Wikipedia](https://en.wikipedia.org/wiki/Reinforcement_learning) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Discounted Return > The discounted return is the total reward an agent can expect from now on, where rewards that arrive later count for a little less. Page: https://formulabro.yunusemrevurgun.com/ai-ml/discounted-return/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ G_t = \sum_{k=0}^{\infty} \gamma^{k} r_{t+k+1} $$ Read it out loud: "G sub t equals the sum, for k from 0 to infinity, of gamma to the power k, times the reward r at time t plus k plus 1." ## What each symbol means - $G_t$: The **return** at time $t$: the total discounted reward from that moment onward. Measured in reward points. - $\sum_{k=0}^{\infty}$: "Add up for every $k$ from 0 to infinity": the sum runs over all the future steps. In practice it stops when the rewards run out. - $k$: How many steps after time $t$ a reward arrives. $k = 0$ is the very next step. - $\gamma$: The **discount factor**, with $0 \le \gamma < 1$. It sets how much less a reward counts for each step it is delayed. No unit. - $r_{t+k+1}$: The reward received after the step taken at time $t+k$, measured in reward points. ## What the formula is doing A reinforcement learning agent acts, the world answers with rewards, and the agent wants to collect as much reward as possible over time. The return $G_t$ is the total reward from time $t$ onward. The formula adds the rewards in order: the first one, $r_{t+1}$, then $r_{t+2}$, and so on. Each future reward is multiplied by $\gamma^{k}$, where $k$ counts how many steps away it arrives. The discount factor $\gamma$ is between 0 and 1. With $\gamma = 0.9$, a reward two steps after the first counts for $0.9^2 = 0.81$ of its face value, and one three steps after counts for $0.9^3 = 0.729$. Rewards far in the future count less. Because $\gamma$ is below 1, each step further away is multiplied by a smaller factor. If every reward has size at most $R$, the infinite sum is at most $\frac{R}{1 - \gamma}$, so the return stays a finite number. That makes returns comparable and gives learning methods something finite to estimate. The sum also has a shortcut. The return at time $t$ equals the next reward plus $\gamma$ times the return one step later: $G_t = r_{t+1} + \gamma G_{t+1}$. Learning methods use this form to update their estimates one step at a time. ## An everyday picture Think of a promise of money. A dollar in hand today is worth more than a promised dollar next year, because you could invest the first one and because promises can fall through. The discount factor is the rate at which you trust a distant reward less than a near one. ## Worked example: A robot's rewards over four steps A robot receives these rewards after each of its next four steps: 1, 0, 2 and 5 points, and nothing after that. Use $\gamma = 0.9$ and time $t = 0$. 1. Multiply each reward by its discount: $1 \times 0.9^0 = 1$, $0 \times 0.9^1 = 0$, $2 \times 0.9^2 = 1.62$ and $5 \times 0.9^3 = 3.645$. 2. Add the four values: $G_0 = 1 + 0 + 1.62 + 3.645 = 6.265$. 3. Check with the shortcut, starting from the last reward: $G_3 = 5$, then $G_2 = 2 + 0.9 \times 5 = 6.5$, then $G_1 = 0 + 0.9 \times 6.5 = 5.85$, and finally $G_0 = 1 + 0.9 \times 5.85 = 6.265$. **Answer:** The discounted return is **6.265 points**. The 5-point reward arrives three steps after the first one, so it is multiplied by $0.9^3 = 0.729$ and counts for 3.645 points. The shortcut gives the same total. ## Common mistakes - Starting the sum at $r_t$ instead of $r_{t+1}$. The reward for the step taken at time $t$ arrives right after that step, so the sum starts one index later. - Using $\gamma = 1$ for a task that never ends. The sum can then grow without limit when rewards keep coming. - Starting the discount at $\gamma^1$. The first reward in the sum is multiplied by $\gamma^0 = 1$. - Comparing returns computed with different discount factors. Changing $\gamma$ changes the numbers, so the values are not on the same scale. ## Where you will meet it - The target in temporal-difference learning, where the return is estimated from one reward plus the value of the next state. - Policy-gradient methods, which weight each action by the return that followed it. - Game-playing and robot agents that must trade off a reward now against rewards later. - Business valuation, where a stream of future payments is discounted to a value today, using the same kind of sum. ## Questions people ask ### What does a discount factor of 0 mean? The agent cares only about the next reward. Every later term is multiplied by $0^k = 0$ for $k \geq 1$, so the return is $r_{t+1}$ alone. ### Why must $\gamma$ stay below 1? With $\gamma < 1$ and bounded rewards, the sum has a finite limit. With $\gamma = 1$ in an endless task, the return can grow without limit. ### Is the return the same as the reward? No. The reward is what the agent gets from one step. The return adds up all the rewards from time $t$ onward, each one discounted. ### Who chooses $\gamma$? The designer of the agent. It is a setting, like a learning rate, and it changes what the agent cares about. ## Related formulas - [Q-Learning Update](https://formulabro.yunusemrevurgun.com/ai-ml/q-learning-update/) - [Softmax Temperature](https://formulabro.yunusemrevurgun.com/ai-ml/softmax-temperature/) ## Sources - [Reinforcement learning, Wikipedia](https://en.wikipedia.org/wiki/Reinforcement_learning) - [Markov decision process, Wikipedia](https://en.wikipedia.org/wiki/Markov_decision_process) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Z-Score Standardization > A z-score says how far a number is from the average, measured in typical steps of spread, so different features can be compared fairly. Page: https://formulabro.yunusemrevurgun.com/ai-ml/z-score-standardization/ Category: AI & Machine Learning Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ z = \frac{x - \mu}{\sigma} $$ Read it out loud: "z equals x minus mu, all divided by sigma. The z-score of x is its distance from the mean, divided by the standard deviation." ## What each symbol means - $z$: The **z-score**, the new value after standardization. It is a plain number with no unit: how many standard deviations $x$ sits from the mean. - $x$: The original value of one feature, in its own units, such as hours or dollars. - $\mu$: The **mean** of the feature, the average over the training data, in the same units as $x$. - $\sigma$: The **standard deviation**, the typical distance of the values from the mean, in the same units as $x$. It must be greater than zero. ## What the formula is doing Many learning methods work better when the input features sit on similar scales. If one feature is a salary in dollars and another is an age in years, the salary numbers are much bigger and dominate distances and gradients. Standardizing each feature puts them on one common scale. The mean $\mu$ is the average of the feature. The standard deviation $\sigma$ measures the typical distance of values from that average. Subtracting $\mu$ moves the center of the data to zero. Dividing by $\sigma$ makes one typical step of spread equal to 1. So $z$ tells you how many standard deviations $x$ lies above or below the average. Compute $\mu$ and $\sigma$ from the training data only, then use those same two numbers on the validation and test data. Computing them from the whole dataset leaks information from the test set into training, which makes the results look better than they are. The transform changes the location and scale of the values, not their shape. A skewed feature stays skewed, and an outlier stays an outlier. Whatever the shape of the data, at most one value in nine can lie three or more standard deviations from the mean, by Chebyshev's inequality. ## An everyday picture Think of grading on a curve. Instead of raw scores, you report how far each student is from the class average, in units of the class's typical spread. A student who studies 13 hours a week, in a group whose typical spread is 2 hours, sits 1.5 units above the average, whatever units the original numbers were in. ## Worked example: Standardizing weekly study hours Five students study these hours per week: $7$, $9$, $10$, $11$ and $13$. Standardize the value $x = 13$. 1. Find the mean: $\mu = \frac{7 + 9 + 10 + 11 + 13}{5} = 10$ hours. 2. Find the squared deviations: $(7 - 10)^2 = 9$, $(9 - 10)^2 = 1$, $(10 - 10)^2 = 0$, $(11 - 10)^2 = 1$ and $(13 - 10)^2 = 9$. Their average is $\frac{20}{5} = 4$, so $\sigma = \sqrt{4} = 2$ hours. 3. Standardize the value: $z = \frac{13 - 10}{2} = 1.5$. 4. Check the whole set: the five z-scores are $-1.5$, $-0.5$, $0$, $0.5$ and $1.5$. They add up to 0, and their squares average to 1. **Answer:** The z-score of 13 hours is **1.5**. That student studies 1.5 standard deviations above the group average. After standardizing, the whole set has mean 0 and standard deviation 1. ## Common mistakes - Computing $\mu$ and $\sigma$ on all the data, including the test set. Fit them on the training data only. - Standardizing new data with its own mean and standard deviation. Use the numbers saved from the training data, so every input is scaled the same way. - Reading a z-score as a probability. A z-score of 1.5 is a distance in standard deviations, not a chance of anything. - Standardizing category codes such as 1 for red and 2 for blue. Those numbers have no real distance between them, so the result means nothing. ## Where you will meet it - Scaling features before distance-based methods such as k-nearest neighbors, k-means clustering and support vector machines. - Preparing inputs for gradient descent in linear, logistic and neural network models, where similar scales make training more stable. - Flagging unusual values in data pipelines, where a z-score far from zero marks a candidate outlier. - Comparing results measured on different scales, such as standard scores that put different tests on one common scale. ## Questions people ask ### Does z-scoring change the shape of the data? No. It shifts and scales the values. A skewed feature stays skewed, and outliers stay far from the center. ### How is this different from min-max scaling? Min-max scaling squeezes values into a fixed range, such as 0 to 1. A z-score centers on the mean and uses standard deviations, so its range is not fixed. ### Which standard deviation does scikit-learn use? Its StandardScaler divides by the population standard deviation, the version with $n$ in the denominator. Both versions are common, so use the same one for training and new data. ### Do I need to standardize every model's inputs? Not always. Decision trees split one feature at a time, so scaling does not change their splits. Distance-based and gradient-based methods usually need it. ## Related formulas - [Mean Squared Error (MSE)](https://formulabro.yunusemrevurgun.com/ai-ml/mean-squared-error/) - [R-Squared](https://formulabro.yunusemrevurgun.com/ai-ml/r-squared/) - [Gradient Descent](https://formulabro.yunusemrevurgun.com/ai-ml/gradient-descent/) ## Sources - [Standard score, Wikipedia](https://en.wikipedia.org/wiki/Standard_score) - [Feature scaling, Wikipedia](https://en.wikipedia.org/wiki/Feature_scaling) - [scikit-learn, StandardScaler documentation](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Binary Number Value > Binary uses only the digits 0 and 1, and this formula turns a row of those digits into the ordinary number they stand for. Page: https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ N = \sum_{i=0}^{n-1} b_i \cdot 2^{i} $$ Read it out loud: "N equals the sum, for every position i from 0 up to n minus 1, of bit b sub i times 2 to the power of i." ## What each symbol means - $N$: The ordinary (decimal) number that the bits stand for. - $n$: How many bits the number has. An 8-bit number has $n = 8$. - $i$: The position of a bit, counted from the right and starting at 0. Position 0 is the rightmost bit. - $b_i$: The bit at position $i$. It is always either 0 or 1. - $2^{i}$: The place value of position $i$: 1, 2, 4, 8, 16 and so on. Each place is worth twice the place on its right. - $\sum_{i=0}^{n-1}$: "Add up the terms for every position $i$ from 0 to $n - 1$": go through all the bits and total their values. ## What the formula is doing In everyday life we count with ten digits, 0 to 9, so our system is called *decimal*. Computer memory has two easy states, off and on, so computers count with two digits, 0 and 1. That system is called *binary*. Each binary digit is called a **bit**, short for binary digit. A digit's place decides how much it is worth. In decimal the places are ones, tens and hundreds, and each place is ten times the one on its right. In binary each place is worth two times the place on its right, so the places are 1, 2, 4, 8, 16 and so on. To find the value, look at each bit. If it is 1, add the place value under it. If it is 0, add nothing. The formula writes exactly that: $b_i$ is 0 or 1, and $2^{i}$ is the place value, so each term is either 0 or a place value, and the sum is the number. The formula has this shape because every place is a power of two. With $n$ bits the largest value is $2^{n} - 1$, and counting starts at 0, so $n$ bits give $2^{n}$ different values in total. ## An everyday picture Think of a row of light switches on a wall. The first switch controls one bulb, the next controls two, then four, then eight. Turning a switch on adds its bulbs to the total. A binary number works the same way: every bit that is on adds its place value, and the total of the lit bulbs is the number. ## Worked example: Reading the binary number 1011 The bits are $1011$, read from left to right. That is 4 bits, so $n = 4$. The place values from left to right are $8$, $4$, $2$ and $1$. 1. Write the place values from left to right: $2^{3} = 8$, $2^{2} = 4$, $2^{1} = 2$, $2^{0} = 1$. 2. Pair each bit with its place: the 1 sits in the 8 place, the 0 in the 4 place, the 1 in the 2 place and the 1 in the 1 place. 3. Multiply each bit by its place value and add: $1 \cdot 8 + 0 \cdot 4 + 1 \cdot 2 + 1 \cdot 1 = 8 + 0 + 2 + 1$. 4. Total: $8 + 0 + 2 + 1 = 11$. 5. A byte is 8 bits. Its places run from $2^{7}$ down to $2^{0}$, and setting all eight bits to 1 gives the largest value, $2^{8} - 1 = 255$. Zero is the smallest, so one byte holds 256 different values. **Answer:** The binary number $1011$ is the ordinary number **11**. One byte can hold the whole numbers from **0 to 255**, which is 256 values in all. ## Common mistakes - Adding the bits without their place values, so $1011$ becomes $1 + 0 + 1 + 1 = 3$. Each bit must be multiplied by its power of 2 first. - Using a digit larger than 1 in a binary number. Binary digits are only 0 or 1, so $1012$ is not a binary number. - Starting the positions at 1 instead of 0. The rightmost bit has position 0 and place value $2^{0} = 1$. - Mixing up binary and decimal. The digits $1010$ mean ten in binary and one thousand and ten in decimal. Write the base when it is unclear, as in $1011_2$. ## Where you will meet it - Computer memory and storage, where every bit is kept as one of two electrical states. - IPv4 internet addresses, which are 32 bits long and are usually written as four decimal numbers from 0 to 255. - Colors on a screen, where a red, green or blue channel is often stored as one 8-bit byte from 0 to 255. - Machine code, where each CPU instruction is a pattern of bits that the processor reads as a number. ## Questions people ask ### Why do computers use binary and not decimal? Electronic circuits can tell two states apart reliably: a voltage is high or low, and a switch is on or off. Ten different voltage levels are much harder to keep apart. Two states keep the hardware simple and dependable. ### What is a byte? A group of 8 bits. One byte can hold 256 different values, the whole numbers from 0 to 255. ### How do I convert a decimal number to binary? Divide by 2 again and again and write down each remainder. Read the remainders from the last one to the first. For example, 11 divided by 2 leaves remainders 1, 1, 0 and 1. Read backwards, they give $1011$. ## Related formulas - [Binary Search Steps](https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/) - [De Morgan's Laws](https://formulabro.yunusemrevurgun.com/computer-science/de-morgans-laws/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) ## Sources - [Binary number, Wikipedia](https://en.wikipedia.org/wiki/Binary_number) - [Byte, Wikipedia](https://en.wikipedia.org/wiki/Byte) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Binary Search Steps > Binary search finds an item in a sorted list by checking the middle and throwing away half, and this formula counts how many checks that takes at most. Page: https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{steps} = \lceil \log_2 (n + 1) \rceil $$ Read it out loud: "The number of steps equals the ceiling of the base-2 logarithm of n plus 1. The ceiling means round up to the next whole number." ## What each symbol means - $\text{steps}$: The worst-case number of comparisons: how many checks you might need before you know whether the item is in the list. - $n$: How many items are in the sorted list. - $\log_2 x$: The base-2 logarithm: how many times you must halve $x$ to get down to 1. For powers of 2 it is exact, so $\log_2 8 = 3$ because $8 \to 4 \to 2 \to 1$ takes 3 halvings. - $\lceil x \rceil$: The ceiling of $x$: round $x$ up to the next whole number. For example $\lceil 19.93 \rceil = 20$. ## What the formula is doing Suppose you look for a name in a phone book with 1,000,000 names in alphabetical order. You do not start at the first page. You open the book near the middle, see where your name falls, and ignore the half that cannot contain it. Then you repeat the same move on the half that is left. Each check cuts the remaining pages in half. Start with $n$ names. After one check about half remain, after two checks about a quarter remain, and so on. The search is over when only one name is left to check, or sooner if you find the name. The number of checks is the number of halvings until one item is left, and that count is a logarithm: $\log_2 n$ counts the halvings. The formula uses $n + 1$ and rounds up with the ceiling. That covers lists that do not split evenly, and it gives the worst-case count for every list length. The shape matters because every extra step lets you handle a list twice as long. A list twice as long needs only one extra check, which is why binary search stays fast even when the list is huge. ## An everyday picture A phone book is the perfect picture. Open it in the middle, decide which half your name is in, and ignore the other half. You never page through the whole book one name at a time. With a million names you need only about 20 looks. ## Worked example: Finding one name among 1000000 sorted items A sorted list has $n = 1000000$ items. We want the worst-case number of comparisons for binary search, and we compare it with a plain linear scan that checks one item at a time. 1. Add 1: $n + 1 = 1000001$. 2. Take the base-2 logarithm: $\log_2 1000001 \approx 19.93$. So you need about 20 halvings to get down to one item. 3. Round up with the ceiling: $\lceil 19.93 \rceil = 20$ steps. 4. A linear scan may check all $1000000$ items in the worst case. The ratio is $\frac{1000000}{20} = 50000$, so binary search does about 50,000 times fewer checks here. **Answer:** In the worst case, binary search needs **20 comparisons** to find an item in a sorted list of one million items. A linear scan may need up to **1,000,000**. The gap grows fast as the list grows. ## Common mistakes - Running binary search on a list that is not sorted. The halving only works when you know which side of the middle the item is on, and that needs sorted data. - Reading the formula as the number of checks you always need. It gives the worst case. Sometimes the item turns up on the first check. - Leaving out the ceiling and reporting 19.93 steps. Steps are whole checks, so round up to 20. - Using the natural logarithm when the halving is in base 2. Use $\log_2$, or convert from another base with a division. ## Where you will meet it - Searching sorted arrays in programming libraries, for example Python's `bisect` module, which uses binary search. - Looking up values in sorted data, such as a sorted list of names or timestamps. - Debugging with `git bisect`, which halves the list of commits to find the one that introduced a bug. - The classic guessing game: if you guess a number from 1 to 100 and get higher-or-lower hints, binary search needs at most 7 guesses. ## Questions people ask ### Why does the formula use $n + 1$ and not $n$? The $+1$ makes the formula give the worst-case count for every list length, including lists that do not split evenly. A list of 1 item gives $\lceil \log_2 2 \rceil = 1$ check, and a list of 3 items gives $\lceil \log_2 4 \rceil = 2$ checks. ### Is binary search always faster than a linear scan? On a sorted list it is never slower in the worst case, and for long lists it is far faster. For 10 items the gap is small in absolute terms, because a linear scan may need 10 checks and binary search at most 4. The gap grows quickly as the list grows. ### Does binary search need the list to be sorted first? Yes. The halving depends on knowing which side of the middle the item is on, and only sorted data guarantees that. Sorting costs time up front, so it pays off when you search the same list many times. ## Related formulas - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Little's Law](https://formulabro.yunusemrevurgun.com/computer-science/littles-law/) - [Amdahl's Law](https://formulabro.yunusemrevurgun.com/computer-science/amdahls-law/) ## Sources - [Binary search algorithm, Wikipedia](https://en.wikipedia.org/wiki/Binary_search_algorithm) - [Logarithm, Wikipedia](https://en.wikipedia.org/wiki/Logarithm) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Shannon Entropy > Shannon entropy is one number, in bits, that says how unpredictable a source is. The more predictable it is, the less space its messages need. Page: https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ H = -\sum_{i=1}^{n} p_i \log_2 p_i $$ Read it out loud: "H equals minus the sum, for every outcome i from 1 to n, of p sub i times the base-2 logarithm of p sub i. The answer is measured in bits." ## What each symbol means - $H$: The entropy of the source, in **bits**. One bit is the information in one fair yes-or-no answer. - $n$: How many different possible outcomes there are, such as 2 for a coin or 6 for a die. - $i$: Which outcome we are looking at, counted from 1 to $n$. - $p_i$: The probability of outcome $i$: a number from 0 to 1. All the $p_i$ together add up to 1. - $\log_2 p_i$: The base-2 logarithm of the probability. It is zero or negative for any probability at most 1, which is why the formula has a minus sign in front. - $-\sum_{i=1}^{n}$: "Add up the terms for every outcome, then flip the sign." Flipping the sign makes the final answer zero or positive. ## What the formula is doing Shannon entropy answers one simple question: on average, how surprised should you be by the next message from a source? A source that always sends the same message gives no surprise at all. A source where every choice is equally likely gives the most surprise it can. Rare outcomes are surprising and common ones are not. The surprise of an outcome with probability $p$ is $\log_2 \frac{1}{p}$, which gets bigger as $p$ gets smaller. The formula then averages those surprises, weighting each one by how often it happens. The minus sign is there because $\log_2 p$ is negative for $p$ below 1, and surprise should be positive. A fair coin has two outcomes that are equally likely, so its average surprise is exactly 1 bit: one yes-or-no answer. A biased coin that lands heads 90% of the time is less surprising on average, so its entropy is lower. Entropy also sets a limit for compression. It is the lowest average number of bits per symbol that any lossless code can reach in the long run. Data with a strong pattern has low entropy, so it can be packed into fewer bits. Claude Shannon introduced the idea in his 1948 paper "A Mathematical Theory of Communication". ## An everyday picture Think of a weather report for a desert where it is sunny every single day. Saying "sunny" again tells you nothing new, so the report can be made very short. Now compare a place where the weather flips between sun, rain, snow and fog. Each report carries real news, so it needs more space. Entropy is the average amount of news per report. ## Worked example: Entropy of a fair coin, a biased coin and a die Three sources, each described by its outcome probabilities. We work out the entropy of each one in bits. 1. Fair coin: $p = (0.5,\ 0.5)$. Each term is $0.5 \cdot \log_2 0.5 = 0.5 \cdot (-1) = -0.5$. Adding the two terms gives $-1$, and flipping the sign gives $H = 1$ bit. 2. Biased coin: $p = (0.9,\ 0.1)$. The terms are $0.9 \cdot \log_2 0.9 \approx 0.9 \cdot (-0.152) = -0.137$ and $0.1 \cdot \log_2 0.1 \approx 0.1 \cdot (-3.322) = -0.332$. Their sum is $-0.469$, so $H = 0.469$ bits. 3. Fair six-sided die: six outcomes, each with $p = \frac{1}{6}$. The six equal terms add up to $6 \cdot \frac{1}{6} \log_2 \frac{1}{6} = -\log_2 6$, so $H = \log_2 6 \approx 2.585$ bits. 4. Biased coin over 1000 flips: $1000 \cdot 0.469 = 469$ bits, instead of 1000 bits for a fair coin. **Answer:** A fair coin carries **1 bit** of surprise per flip. The biased coin carries only **0.469 bits**, because it is usually heads. A fair die carries **2.585 bits**, a little more than 2, because six equal outcomes need a little more than two yes-or-no questions. A good code can average about 0.469 bits per flip for the biased coin, which is why predictable data compresses so well. ## Common mistakes - Leaving out the minus sign. Each $\log_2 p$ is zero or negative, so without the minus the answer would come out negative, and entropy is never negative. - Using the natural logarithm $\ln$ and calling the result bits. The answer is in bits only when you use $\log_2$. - Using probabilities that do not add up to 1. The formula assumes the probabilities cover every possible outcome. - Assuming that the number of outcomes alone sets the entropy. A loaded die with six faces can have lower entropy than a fair die, because some faces come up more often than others. ## Where you will meet it - Data compression tools such as ZIP and PNG, which store predictable data in fewer bits. - Measuring how predictable text is, for example how well a language model guesses the next letter or word. - Decision trees in machine learning, where a split is chosen to reduce entropy as much as possible. - Cryptography, where a secret key needs high entropy so that an attacker cannot guess it easily. ## Questions people ask ### What does "bits" mean here? A bit is the information in one fair yes-or-no question. A fair coin flip has entropy 1 bit, because one answer, heads or tails, settles it. ### Why is the entropy of a sure thing zero? If one outcome has probability 1, every other probability is 0, and only the term for $p = 1$ is left. Since $\log_2 1 = 0$, the entropy is 0. A message that always says the same thing tells you nothing new. ### Who invented Shannon entropy? Claude Shannon introduced it in his 1948 paper "A Mathematical Theory of Communication." That paper founded the field of information theory. ## Related formulas - [Cross-Entropy Loss](https://formulabro.yunusemrevurgun.com/ai-ml/cross-entropy-loss/) - [Softmax](https://formulabro.yunusemrevurgun.com/ai-ml/softmax/) - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) ## Sources - [Entropy (information theory), Wikipedia](https://en.wikipedia.org/wiki/Entropy_(information_theory)) - [A Mathematical Theory of Communication, Wikipedia](https://en.wikipedia.org/wiki/A_Mathematical_Theory_of_Communication) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Amdahl's Law > Amdahl's law tells you how much faster a whole program gets when you speed up only part of its work, and why the part you leave alone caps the gain. Page: https://formulabro.yunusemrevurgun.com/computer-science/amdahls-law/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ S = \frac{1}{(1 - p) + \frac{p}{s}} $$ Read it out loud: "S equals one divided by the quantity one minus p, plus p divided by s." ## What each symbol means - $S$: The overall speedup: how many times faster the whole job runs. A value of 1 means no change and a value of 2 means twice as fast. - $p$: The fraction of the work that can be sped up, from 0 to 1. For example $p = 0.9$ means 90% of the job. - $s$: The speedup of that part alone. With 8 cores on a perfectly split job, $s = 8$. - $1 - p$: The fraction of the work that stays the same, the part that cannot be sped up. - $\frac{p}{s}$: The time the sped-up part now takes, as a fraction of the original total time. ## What the formula is doing Imagine a program whose total running time is 1 unit. A fraction $p$ of that time is work that can be split across several processors. The rest, $1 - p$, must run one step after another and cannot be split. Without any speedup the program takes $p + (1 - p) = 1$ unit. With the speedup, the splittable part takes $\frac{p}{s}$ of the original time, and the part that cannot be split still takes $1 - p$. The new total time is $(1 - p) + \frac{p}{s}$. Speedup is the old time divided by the new time. The old time is 1, so the speedup is $S = \frac{1}{(1 - p) + \frac{p}{s}}$. That is the formula. The shape explains a hard limit. As $s$ grows, $\frac{p}{s}$ shrinks toward 0, but the $1 - p$ part never shrinks. So the speedup can never be bigger than $\frac{1}{1 - p}$, however many processors you add. ## An everyday picture Think of cooking a holiday dinner. Chopping the vegetables can be shared among four helpers, which speeds that part up a lot. The oven still needs its one hour, and no helper can make it bake faster. The dinner cannot be ready sooner than the oven allows, however many people chop. ## Worked example: A program that is 90% parallel on 8 cores A program spends 90% of its time on work that can be split across cores, so $p = 0.9$. That part runs $s = 8$ times faster on 8 cores. The other 10% is serial and stays the same. 1. Serial part: $1 - p = 1 - 0.9 = 0.1$ of the original time. 2. Parallel part on 8 cores: $\frac{p}{s} = \frac{0.9}{8} = 0.1125$ of the original time. 3. New total time: $0.1 + 0.1125 = 0.2125$, compared with 1 before. 4. Speedup on 8 cores: $S = \frac{1}{0.2125} \approx 4.71$. 5. Limit with unlimited cores: the parallel part takes almost no time, so the total time is close to $0.1$ and $S = \frac{1}{0.1} = 10$. **Answer:** On 8 cores the program runs about **4.71 times faster**, not 8 times faster. Even with unlimited cores it can never get more than **10 times** faster, because the 10% serial part still takes its full time. ## Common mistakes - Assuming 8 cores give 8 times the speed. Only the parallel part gets faster, so the total speedup is always smaller than the number of cores. - Entering $p$ as a percentage, such as 90, instead of a fraction, such as 0.9. The formula needs $p$ between 0 and 1. - Forgetting the serial part. The $1 - p$ term is what limits the speedup, and it is easy to leave out of the calculation. - Reading the law as saying parallel work is useless. It says the gain is limited by the serial fraction. More cores still help, but each extra core helps a little less. ## Where you will meet it - Deciding how many CPU cores or threads a program should use, and when adding more stops helping. - Planning parallel jobs on supercomputers and GPUs, to judge whether a program is worth rewriting for parallel hardware. - Performance tuning, where engineers measure a program and speed up the part that takes the most time first. - Comparing multicore chip designs, where it shows how much a serial part limits the benefit of extra cores. ## Questions people ask ### Does Amdahl's law mean parallel computing is pointless? No. It means the serial part sets a ceiling. When $p$ is small, the gain is small, and when $p$ is close to 1, many cores pay off well. The law tells you where the ceiling is, so you know which part to work on. ### What is a serial part? Work that must be done in order, where each step needs the result of the step before it, such as a calculation that builds on the previous answer. ### Is the speedup ever equal to the number of cores? Only when the whole job can be split perfectly, which is rare. For any job with a serial part, the speedup is smaller than the number of cores. ## Related formulas - [Little's Law](https://formulabro.yunusemrevurgun.com/computer-science/littles-law/) - [Binary Search Steps](https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/) ## Sources - [Amdahl's law, Wikipedia](https://en.wikipedia.org/wiki/Amdahl%27s_law) - [Parallel computing, Wikipedia](https://en.wikipedia.org/wiki/Parallel_computing) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # De Morgan's Laws > De Morgan's laws say that a NOT in front of a group of AND or OR conditions flips the group: AND becomes OR, and OR becomes AND. Page: https://formulabro.yunusemrevurgun.com/computer-science/de-morgans-laws/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \neg(A \land B) = \neg A \lor \neg B \qquad \neg(A \lor B) = \neg A \land \neg B $$ Read it out loud: "Not, open bracket, A and B, close bracket, equals not A or not B. And not, open bracket, A or B, close bracket, equals not A and not B." ## What each symbol means - $A$: A statement that is either true or false, such as "it is raining". - $B$: A second statement that is either true or false, such as "it is cold". - $\neg$: NOT. It flips a statement: true becomes false and false becomes true. - $\land$: AND. The result is true only when both statements are true. - $\lor$: OR. The result is true when at least one of the statements is true. ## What the formula is doing Programmers write conditions with three words: NOT, AND and OR. A condition such as *not (raining and cold)* can be hard to read at a glance. De Morgan's laws give an equal form that is often easier to understand or to code. The first law reads: NOT (A AND B) means the same as (NOT A) OR (NOT B). The NOT moves inside the bracket and the AND turns into an OR. The second law works the other way: NOT (A OR B) equals (NOT A) AND (NOT B), so the OR turns into an AND. The reason is plain English. "Not both" means at least one of them fails, which is the same as saying "at least one is not true". "Not either" means neither one holds, which means both are not true. The laws hold for every combination of true and false. You can check that with a truth table that lists all four combinations of A and B, which the example does. Both sides agree in every row, so the two forms are the same condition. ## An everyday picture Think of a club rule: you get in only if you are a member and you are over 18. Being turned away means you are not a member, or you are not over 18. Saying "not both" in the rule turns into "at least one missing" when you turn it around. That is De Morgan's first law in everyday words. ## Worked example: Rewriting a rain-and-cold rule in code A park app runs a walking tour when $\neg(A \land B)$ is true. Here $A$ means it is raining and $B$ means it is cold. So the tour runs unless it is both raining and cold. 1. Apply the first law: $\neg(A \land B) = \neg A \lor \neg B$. In words, the tour runs when it is not raining, or it is not cold. 2. In code, `if not (raining and cold):` becomes `if (not raining) or (not cold):`. Both lines give the same answer every time. 3. Row 1, not raining and not cold ($A$ false, $B$ false): left side $\neg(F \land F) = \neg F = T$. Right side $\neg F \lor \neg F = T \lor T = T$. They match. 4. Row 2, not raining and cold ($A$ false, $B$ true): left side $\neg(F \land T) = \neg F = T$. Right side $\neg F \lor \neg T = T \lor F = T$. They match. 5. Row 3, raining and not cold ($A$ true, $B$ false): left side $\neg(T \land F) = \neg F = T$. Right side $\neg T \lor \neg F = F \lor T = T$. They match. 6. Row 4, raining and cold ($A$ true, $B$ true): left side $\neg(T \land T) = \neg T = F$. Right side $\neg T \lor \neg T = F \lor F = F$. They match. **Answer:** The two forms are the same rule. The tour runs in three of the four weather cases and is off only when it is both raining and cold. Both versions of the code give that same result in all four cases, so you can pick whichever one reads more clearly. ## Common mistakes - Moving the NOT but forgetting to flip the AND or OR. $\neg(A \land B)$ is not $\neg A \land \neg B$, and the two can give different answers. - Dropping the brackets. $\neg A \land B$ flips only A, while $\neg(A \land B)$ flips the whole group. - Reading "not both" as "neither". "Not both" means at least one fails, while "neither" means both fail. - Checking only one row of the truth table. A single example can look right by accident, so check all four combinations. ## Where you will meet it - Writing `if` statements in most programming languages, to make long conditions easier to read. - Digital logic design, where a NAND gate gives the same result as an OR gate with inverted inputs. - Search and database queries, where a NOT around several conditions is rewritten to make the query clearer. - Set theory in mathematics, where the complement of an intersection equals the union of the complements. ## Questions people ask ### What is the difference between AND and OR? AND is true only when both parts are true. OR is true when at least one part is true. For example, "has a ticket AND is over 12" needs both, while "has a ticket OR has a pass" needs only one. ### Why are they called De Morgan's laws? They are named after Augustus De Morgan, a British mathematician of the 1800s who described them in his work on formal logic. ### Do the laws work for more than two statements? Yes. NOT (A AND B AND C) equals NOT A OR NOT B OR NOT C, and the same pattern works for OR. Each NOT flips one statement and the operator flips too. ## Related formulas - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Binary Search Steps](https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/) ## Sources - [De Morgan's laws, Wikipedia](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) - [Truth table, Wikipedia](https://en.wikipedia.org/wiki/Truth_table) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Little's Law > Little's law says the number of things inside a system equals how fast they arrive, multiplied by how long each one stays. Page: https://formulabro.yunusemrevurgun.com/computer-science/littles-law/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ L = \lambda W $$ Read it out loud: "L equals lambda times W. The average number of items in the system equals the arrival rate times the average time each item spends in it." ## What each symbol means - $L$: The average number of items inside the system at any moment, such as customers in a shop or requests in a server. - $\lambda$: The arrival rate: how many items enter the system per unit of time, such as customers per hour. - $W$: The average time one item spends in the system, from arrival to departure. Use the same time unit as $\lambda$, for example hours. ## What the formula is doing Picture a queue. People walk in at a steady pace, and each one stays for some time before leaving. At any moment, the number of people inside depends on two things: how fast they come in, and how long each one stays. If customers arrive twice as fast and stay for the same time, there are twice as many inside. If they arrive at the same speed but each stays twice as long, there are again twice as many. So $L$ grows in proportion to both, and the formula is a product: $L = \lambda W$. The law does not need to know how arrivals are spread out. They can come in bursts or evenly, and stays can be short or long. The system only needs to be steady, meaning it is not slowly filling up forever. Then the long-run average count equals the rate times the average time. The units must match. If $\lambda$ is in customers per hour, $W$ must be in hours. Six minutes is 0.1 hours, so using 6 would give an answer 60 times too big. ## An everyday picture Think of an escalator in a shopping mall. Shoppers step on at a steady rate, and each rides for about the same time. The number of people standing on the escalator at any moment is how fast they step on, multiplied by how long each ride lasts. ## Worked example: Customers in a coffee shop A coffee shop gets $\lambda = 30$ customers per hour. Each customer stays $W = 6$ minutes on average. We need the same time unit as the rate, so we use hours. 1. Convert the time: $6$ minutes $= \frac{6}{60}$ hours $= 0.1$ hours. 2. Apply the law: $L = \lambda W = 30 \cdot 0.1 = 3$ customers. 3. Second case, a web server: $\lambda = 200$ requests per second and $W = 0.05$ seconds. So $L = 200 \cdot 0.05 = 10$ requests in flight. **Answer:** On average **3 customers** are inside the coffee shop at any moment. The same rule says a web server that gets 200 requests per second, each taking 0.05 seconds, has about **10 requests** in progress at once. Both results are averages, not exact counts. ## Common mistakes - Mixing time units, such as customers per hour with minutes. Convert the time first, or the answer is off by a factor of 60. - Treating $L$ as the number of items that arrive in total. $L$ counts items inside the system at one moment, not everyone who ever came in. - Expecting an exact count. Little's law gives an average over a long period, so the number inside will go up and down around that average. - Using the law for a system that is growing without limit. It needs a steady state, where the average does not keep climbing. ## Where you will meet it - Estimating how many requests a web server or database handles at once, from its request rate and response time. - Staffing a checkout or call center, to estimate how many people are waiting or being served on average. - Manufacturing and project management, where work in progress equals throughput times the time each job spends in the process. - Queueing theory, the study of waiting lines, where the law is one of the most used results. ## Questions people ask ### Does Little's law need the arrivals to be evenly spaced? No. It works with averages over a long time, so bursts and quiet periods are fine. It does need the system to be steady, which means it is not filling up forever. ### What if I know the count and the time but not the rate? Rearrange the formula to $\lambda = \frac{L}{W}$. For example, if 3 customers are inside on average and each stays 0.1 hours, then $\frac{3}{0.1} = 30$ customers arrive per hour. ### Why is it called Little's law? It is named after John D. C. Little, who published a general proof of the formula in 1961. ## Related formulas - [Amdahl's Law](https://formulabro.yunusemrevurgun.com/computer-science/amdahls-law/) - [Binary Search Steps](https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/) ## Sources - [Little's law, Wikipedia](https://en.wikipedia.org/wiki/Little%27s_law) - [Queueing theory, Wikipedia](https://en.wikipedia.org/wiki/Queueing_theory) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Hexadecimal Number Value > Hexadecimal counts in sixteens using the digits 0 to 9 and A to F, and this formula turns a hex number into the ordinary number it stands for. Page: https://formulabro.yunusemrevurgun.com/computer-science/hexadecimal-number-value/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ N = \sum_{i=0}^{n-1} d_i \cdot 16^{i} $$ Read it out loud: "N equals the sum, for every position i from 0 up to n minus 1, of digit d sub i times 16 to the power of i." ## What each symbol means - $N$: The ordinary (decimal) number that the hex digits stand for. - $n$: How many hex digits the number has. The number 2F has $n = 2$. - $i$: The position of a digit, counted from the right and starting at 0. Position 0 is the rightmost digit. - $d_i$: The digit at position $i$. Hex digits run from 0 to 15: the digits 0 to 9 are worth 0 to 9, and A, B, C, D, E and F are worth 10, 11, 12, 13, 14 and 15. - $16^{i}$: The place value of position $i$: 1, 16, 256, 4096 and so on. Each place is worth sixteen times the place on its right. - $\sum_{i=0}^{n-1}$: \"Add up the terms for every position $i$ from 0 to $n - 1$\": go through all the digits and total their values. ## What the formula is doing Decimal uses ten digits, 0 to 9. Binary uses two. *Hexadecimal*, or *hex* for short, uses sixteen. It needs six more symbols after 0 to 9, so it borrows the letters A to F. The letter A means 10, B means 11, and so on up to F, which means 15. Hex is handy because one hex digit stands for exactly four bits, since $16 = 2^{4}$. Each place is worth sixteen times the place on its right. The places are 1, 16, 256, 4096 and so on. A two-digit number such as 2F has a sixteens place and a ones place. The formula writes that rule in one line: $d_i$ is the digit at position $i$, and $16^{i}$ is its place value. Each digit is multiplied by its place value, and the products are added. The formula has this shape because every place value is a power of sixteen, and each digit can be any value from 0 to 15. With $n$ digits the largest value is $16^{n} - 1$. For two digits that is $16^{2} - 1 = 255$. That is why one byte, which is eight bits, fits exactly in two hex digits, from 00 to FF. The prefix 0x in front of a number such as 0x2F is a common sign that the digits are hexadecimal. The prefix is not part of the value. Hex is easier to read than long binary strings. The 8-bit pattern $11111111$ is written $FF$ in hex, and both mean 255. Converting between hex and binary is quick, because each hex digit maps to exactly four bits. ## An everyday picture Think of an odometer with wheels that have sixteen marks instead of ten. When a wheel passes F it rolls back to 0 and carries one to the wheel on its left, the same way a decimal odometer carries after 9. Each wheel is worth sixteen times the wheel on its right. ## Worked example: Reading the hex number 2F The hex number is $2F$, with two digits, so $n = 2$. The digit $2$ sits in the sixteens place, and the digit $F$ sits in the ones place. $F$ means 15 in decimal. 1. Write the place values from right to left: $16^{0} = 1$ and $16^{1} = 16$. 2. Convert each digit to decimal: $2$ stays $2$, and $F$ becomes $15$. 3. Multiply each digit by its place value and add: $2 \cdot 16 + 15 \cdot 1 = 32 + 15$. 4. Total: $32 + 15 = 47$. 5. Check in binary: $2$ is $0010$ and $F$ is $1111$, so $2F$ is $00101111$. Reading that as binary gives $32 + 8 + 4 + 2 + 1 = 47$, the same number. **Answer:** The hex number **2F** is the ordinary number **47**. The largest two-digit hex number is **FF**, which is $15 \cdot 16 + 15 = 255$, so two hex digits can name any of the 256 values in one byte. ## Common mistakes - Treating the letters as special symbols that cannot be added. $A$ means 10 and $F$ means 15, so $1A$ is $1 \cdot 16 + 10 = 26$, not 11. - Using 10 as the place value instead of 16. The number $2F$ is $2 \cdot 16 + 15 = 47$, not $2 \cdot 10 + 15 = 35$. - Counting the letters from the wrong starting point. $A$ is 10, so $B$ is 11, $C$ is 12, $D$ is 13, $E$ is 14 and $F$ is 15. Do not read $F$ as 6. - Using a symbol that is not a hex digit, such as $G$. Hex digits run from 0 to F, so $G$ is not a valid digit. - Mixing up the base. The digits $10$ mean sixteen in hex and ten in decimal. Write the base when it is unclear, as in $10_{16}$. ## Where you will meet it - Web colors, written as #RRGGBB, where each pair of hex digits is one byte from 00 to FF. For example, #FF0000 is pure red. - MAC addresses, which are 48 bits written as six pairs of hex digits, for example 00:1A:2B:3C:4D:5E. - Memory addresses in debuggers and crash logs, which often show values such as 0x7FFF. - Unicode code points, the numbers that identify each character. The letter é, for example, is U+00E9. ## Questions people ask ### Why do programmers use hex instead of binary? Hex is shorter. One hex digit stands for four bits, so a 32-bit number fits in eight hex digits, while it takes 32 binary digits. Hex is also easy to convert to and from binary, one digit at a time. ### Why base 16 and not base 10? Sixteen is $2^{4}$, a power of two, so each hex digit lines up with exactly four bits. Base ten does not line up with binary like that. ### How do I convert hex to decimal? Multiply each digit by its place value, which is a power of 16, and add the results. For example, $2F$ gives $2 \cdot 16 + 15 = 47$. ## Related formulas - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Two's Complement](https://formulabro.yunusemrevurgun.com/computer-science/twos-complement/) - [Floating-Point Value](https://formulabro.yunusemrevurgun.com/computer-science/floating-point-value/) - [Bits Needed](https://formulabro.yunusemrevurgun.com/computer-science/bits-needed/) ## Sources - [Hexadecimal, Wikipedia](https://en.wikipedia.org/wiki/Hexadecimal) - [Positional notation, Wikipedia](https://en.wikipedia.org/wiki/Positional_notation) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Two's Complement > Two's complement is the usual way computers write negative whole numbers in binary, and this formula reads a bit pattern as a positive or negative number. Page: https://formulabro.yunusemrevurgun.com/computer-science/twos-complement/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ N = -b_{n-1} \cdot 2^{n-1} + \sum_{i=0}^{n-2} b_i \cdot 2^{i} $$ Read it out loud: "N equals minus b sub n minus 1, times 2 to the power of n minus 1, plus the sum, for every position i from 0 up to n minus 2, of b sub i times 2 to the power of i." ## What each symbol means - $N$: The signed whole number that the bit pattern stands for. It can be negative. - $n$: How many bits the pattern has. An 8-bit pattern has $n = 8$. - $b_{n-1}$: The leftmost bit, called the sign bit. If it is 1, the number is negative. - $2^{n-1}$: The place value of the sign bit. For 8 bits it is $2^{7} = 128$, but the sign bit counts as minus this value. - $i$: The position of a bit, counted from the right and starting at 0. - $b_i$: The bit at position $i$, which is either 0 or 1. - $2^{i}$: The place value of position $i$: 1, 2, 4, 8 and so on. - $\sum_{i=0}^{n-2}$: \"Add up the terms for every position $i$ from 0 to $n - 2$\": the sum covers all bits except the sign bit. ## What the formula is doing Computers store numbers as bits, and a bit can only be 0 or 1. To store negative numbers, one common method gives the leftmost bit a negative value. That method is called two's complement. In an $n$-bit pattern the leftmost bit, $b_{n-1}$, is the sign bit. It is worth $-2^{n-1}$ instead of $+2^{n-1}$, and the other bits count as usual. Look at the formula. The first term, $-b_{n-1} \cdot 2^{n-1}$, is the sign bit. If that bit is 0, it adds nothing, and the number is zero or positive. If it is 1, it subtracts $2^{n-1}$, and the number is negative. The sum adds the remaining bits with their place values, the same way as plain binary. To negate a number, invert every bit and add 1. Each bit of $x$ plus its inverted bit makes 1 in every place, so $x$ plus its inverted pattern is all ones. All ones is $-1$ in two's complement. So the inverted pattern is $-x - 1$, and adding 1 gives $-x$. For 8 bits the range runs from $-2^{7} = -128$ to $2^{7} - 1 = 127$. There is one more negative value than positive value, because $-128$ has no positive partner in 8 bits. The design has a useful side effect. Addition works the same way for positive and negative numbers, so one adding circuit handles both. Subtracting $b$ from $a$ becomes adding $a$ to the two's complement of $b$. ## An everyday picture Think of a five-digit odometer that wraps around. Going one mile back from 00000 lands on 99999, so 99999 can stand for the number $-1$. Going two miles back lands on 99998, and so on. Two's complement uses the same wrap-around on bit patterns. In 8 bits, 11111111 stands for $-1$ and 11111110 stands for $-2$. ## Worked example: Storing -5 in 8 bits Write $-5$ as an 8-bit two's complement pattern. Start with $+5$, which is $00000101$ in 8 bits, because $4 + 1 = 5$. 1. Write $+5$ in 8 bits: $00000101$, which is $4 + 1 = 5$. 2. Invert every bit: $00000101$ becomes $11111010$. 3. Add 1: $11111010 + 1 = 11111011$. This pattern stands for $-5$. 4. Check with the formula. The sign bit $b_{7} = 1$ gives $-1 \cdot 2^{7} = -128$. The other seven bits, $1111011$, give $64 + 32 + 16 + 8 + 0 + 2 + 1 = 123$. The total is $-128 + 123 = -5$. 5. The same pattern read without a sign is $251$. The two's complement reading uses $-128$ for the leftmost bit instead of $+128$. **Answer:** The 8-bit two's complement pattern for **-5** is **11111011**. Read without a sign, the same bits mean 251. The 8-bit range is **-128 to 127**. ## Common mistakes - Reading the leftmost bit as $+128$. In two's complement a leading 1 makes the number negative, so $11111011$ is $-5$, not $251$. - Negating by inverting bits and forgetting the $+1$. Inverting $00000101$ gives $11111010$, which is $-6$, not $-5$. - Assuming the range is symmetric. An 8-bit number runs from $-128$ to $127$. There is no $+128$, so negating $-128$ overflows and stays $-128$. - Mixing signed and unsigned readings. The same bits mean $251$ or $-5$. Decide which reading applies before you read the number. ## Where you will meet it - Signed integers in most modern processors, including the x86 and ARM families. - Programming languages such as Java, where the `int` and `long` types are two's complement integers. - Audio samples, where 16-bit signed sound values run from $-32768$ to $32767$. - Integer overflow, where $127 + 1$ in an 8-bit signed byte wraps around to $-128$. ## Questions people ask ### Why not use the leftmost bit as a plain minus sign? That design, called sign-and-magnitude, has two zeros, $+0$ and $-0$, and needs extra circuits to add positive and negative numbers. Two's complement has one zero and lets the same adder handle both signs. ### How do I tell if a two's complement number is negative? Look at the leftmost bit. If it is 1, the number is negative. To find its size, invert the bits, add 1 and read the result as a positive number. For $11111011$ that gives $00000101$, which is 5, so the number is $-5$. ### Is there a shortcut for subtraction? Yes. To compute $a - b$, add $a$ to the two's complement of $b$. The adding circuit does the work, so the computer needs no separate subtraction circuit. ## Related formulas - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Hexadecimal Number Value](https://formulabro.yunusemrevurgun.com/computer-science/hexadecimal-number-value/) - [Floating-Point Value](https://formulabro.yunusemrevurgun.com/computer-science/floating-point-value/) - [Bits Needed](https://formulabro.yunusemrevurgun.com/computer-science/bits-needed/) ## Sources - [Two's complement, Wikipedia](https://en.wikipedia.org/wiki/Two%27s_complement) - [Signed number representations, Wikipedia](https://en.wikipedia.org/wiki/Signed_number_representations) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Floating-Point Value > A floating-point number stores a value as a sign, a power of two and a binary fraction, and this formula turns those three parts back into the number. Page: https://formulabro.yunusemrevurgun.com/computer-science/floating-point-value/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ x = (-1)^{s} \times 1.f \times 2^{e - 127} $$ Read it out loud: "x equals negative one to the power of s, times 1 point f, times 2 to the power of e minus 127. This form covers normal single-precision numbers." ## What each symbol means - $x$: The number that the 32 bits stand for. - $(-1)^{s}$: The sign factor: $+1$ when $s = 0$ and $-1$ when $s = 1$. - $s$: The sign bit. It is 0 for a positive number and 1 for a negative number. - $1.f$: The significand. The leading 1 is implied and is not stored. The 23 stored fraction bits $f$ come after it, so $1.f$ is a binary number from 1 up to nearly 2. - $f$: The 23 stored fraction bits. Bit by bit, they are worth $\frac{1}{2}$, $\frac{1}{4}$, $\frac{1}{8}$ and so on. - $e$: The exponent field: 8 stored bits read as a whole number from 0 to 255. The real power of two is $e - 127$, because of the bias 127. - $2^{e - 127}$: The scale factor. A stored exponent of 130 gives $2^{3} = 8$. ## What the formula is doing A computer has a fixed number of bits for each number, so it cannot store every real number exactly. Floating point covers a huge range with a fixed number of bits. It is the binary form of scientific notation: a sign, a string of digits and a power that sets the scale. The most common format is IEEE 754 single precision, which uses 32 bits: 1 sign bit, 8 exponent bits and 23 fraction bits. The formula builds the number from those three parts. The sign bit $s$ picks the sign with $(-1)^{s}$. The significand $1.f$ is a binary number between 1 and 2. Its leading 1 is always there, so it is not stored, and the 23 stored bits give the fraction after it. The exponent is stored with a bias of 127, so the real power of two is $e - 127$. A stored exponent of 130, for example, means $2^{3}$. Here is why 0.1 is not exact. In binary, $0.1$ is $\frac{1}{10}$, and the denominator $10 = 2 \cdot 5$ has a factor of 5. A fraction has a finite binary form only when its reduced denominator is a power of 2, so $0.1$ repeats forever in binary: $0.0001100110011\ldots$. The 32-bit pattern for 0.1 is 0x3DCCCCCD, and the repeating bits are rounded to fit the 23 fraction bits. The stored value is $0.100000001490116\ldots$. That is very close to 0.1, but it is not equal to it. Floating point has limits. A single-precision value keeps about 7 decimal digits. Whole numbers are exact only up to $2^{24} = 16{,}777{,}216$. Very large values reach about $3.4 \times 10^{38}$. Exponent values 0 and 255 are reserved for zero, very small numbers, infinity and not-a-number, so the normal formula above covers exponents 1 to 254. ## An everyday picture Scientific notation on a calculator is the closest everyday idea. The display has room for a fixed number of digits, such as $6.02 \times 10^{23}$, and the exponent moves the decimal point to the right size. Floating point does the same with bits. The 23 fraction bits are the fixed digits, and the exponent is the power of two that sets the scale. ## Worked example: Decoding a 32-bit float The 32 bits are $0\ 10000001\ 10000000000000000000000$: sign, exponent and fraction, in that order, with 23 fraction bits. So $s = 0$, the stored exponent is $e = 129$, and the fraction bits are $0.1000\ldots$ in binary, which is one half. 1. Sign: $s = 0$, so $(-1)^{0} = 1$ and the number is positive. 2. Exponent: $10000001$ is $129$. The real power is $129 - 127 = 2$, so the scale is $2^{2} = 4$. 3. Significand: the fraction bits give $0.5$, so $1.f = 1 + 0.5 = 1.5$. 4. Multiply: $x = 1 \cdot 1.5 \cdot 4 = 6$. **Answer:** The 32 bits store exactly **6**. Most decimal values, such as 0.1, have no exact binary form, so they are stored as the nearest pattern instead. ## Common mistakes - Expecting decimals to be stored exactly. In Python, $0.1 + 0.2$ with ordinary 64-bit floats gives $0.30000000000000004$, not $0.3$, because each value is rounded to binary first. - Forgetting the implied leading 1. The stored fraction bits are not the whole significand. An all-zero fraction means $1.0$, not $0$. - Forgetting the bias. The stored exponent is $e = 130$ for a real exponent of 3, so subtract 127 before you use it as a power of two. - Assuming every whole number is exact. Single precision stores whole numbers exactly only up to $2^{24} = 16{,}777{,}216$. The value $16{,}777{,}217$ rounds to $16{,}777{,}216$. - Testing floats with $==$ after arithmetic. Compare with a small tolerance, because rounding errors add up. ## Where you will meet it - Graphics and game engines, where positions, colors and lighting values are often 32-bit floats. - Scientific computing in Python, such as NumPy's `float32` and `float64` types. - Machine learning, where model weights and activations are often stored as 32-bit or 16-bit floats. - Java's `float` and `double` types, which follow IEEE 754. ## Questions people ask ### Why is 0.1 not exact in binary? Because $\frac{1}{10}$ has a factor of 5 in its denominator, and a fraction has a finite binary form only when its reduced denominator is a power of 2. Decimal has the same kind of problem with $\frac{1}{3} = 0.333\ldots$, which never ends. ### What is the difference between single and double precision? Double precision uses 64 bits: 1 sign bit, 11 exponent bits and 52 fraction bits. It keeps about 15 to 16 decimal digits, compared with about 7 for single precision. ### Should I use floats for money? Not for exact totals. Store amounts as whole cents in an integer, or use a decimal type designed for money. Binary rounding can make totals a cent off. ## Related formulas - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Two's Complement](https://formulabro.yunusemrevurgun.com/computer-science/twos-complement/) - [Hexadecimal Number Value](https://formulabro.yunusemrevurgun.com/computer-science/hexadecimal-number-value/) - [Bits Needed](https://formulabro.yunusemrevurgun.com/computer-science/bits-needed/) ## Sources - [IEEE 754, Wikipedia](https://en.wikipedia.org/wiki/IEEE_754) - [Single-precision floating-point format, Wikipedia](https://en.wikipedia.org/wiki/Single-precision_floating-point_format) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bits Needed > This formula counts the fewest bits you need to give each of N items its own binary code. Page: https://formulabro.yunusemrevurgun.com/computer-science/bits-needed/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ b = \lceil \log_2 N \rceil $$ Read it out loud: "b equals the ceiling of the base-2 logarithm of N. The ceiling means round up to the next whole number." ## What each symbol means - $b$: The number of bits needed. It is always a whole number. - $N$: How many different items need their own code. - $\log_2 N$: The base-2 logarithm: the power you raise 2 to in order to get $N$. For example, $\log_2 8 = 3$ because $2^{3} = 8$. - $\lceil x \rceil$: The ceiling of $x$: round $x$ up to the next whole number. For example, $\lceil 9.97 \rceil = 10$. ## What the formula is doing Every bit doubles the number of patterns you can make. One bit gives 2 patterns, 0 and 1. Two bits give 4 patterns, 00, 01, 10 and 11. With $b$ bits there are $2^{b}$ patterns in total. To give $N$ items their own codes, you need $2^{b} \geq N$. Solve that inequality for $b$. Taking the base-2 logarithm of both sides gives $b \geq \log_2 N$. A number of bits must be a whole number, so you round up with the ceiling: $b = \lceil \log_2 N \rceil$. Rounding down would leave too few patterns. Nine bits give 512 codes, which is not enough for 1000 items. The codes are usually numbered from 0 up to $N - 1$, and the only requirement is enough patterns. Some codes may stay unused. A set of 1000 items uses 10 bits, which gives 1024 patterns and leaves 24 unused. The formula counts labels, not digits. It does not give the number of bits needed to write the number $N$ itself. It gives the bits needed to give each item a distinct label. This idea sits behind fixed-length codes such as ID numbers, product codes and palette indexes. ## An everyday picture Think of a row of light switches. Each switch is one bit, and each is either on or off. Three switches show $2^{3} = 8$ different patterns, so eight guests can each have their own pattern. A ninth guest needs a fourth switch. ## Worked example: Coding 1000 products A shop has $N = 1000$ different products, and each product needs its own binary code. We want the fewest bits per code. 1. Take the base-2 logarithm: $\log_2 1000 \approx 9.966$. 2. Round up with the ceiling: $\lceil 9.966 \rceil = 10$ bits. 3. Check 9 bits: $2^{9} = 512$, which is less than 1000, so 9 bits are not enough. 4. Check 10 bits: $2^{10} = 1024$, which is at least 1000. Ten bits give every product its own code, with 24 codes left over. **Answer:** Each product needs **10 bits**. Ten bits give **1024** codes, which covers the **1000** products with 24 codes to spare. ## Common mistakes - Rounding down. The floor of $\log_2 1000$ is 9, but 9 bits give only 512 codes. Always round up with the ceiling. - Adding 1 to $N$ when $N$ is a power of 2. Eight items need $\lceil \log_2 8 \rceil = 3$ bits, since $2^{3} = 8$. Using $N + 1 = 9$ would wrongly give 4 bits. - Using the natural logarithm. $\ln 1000 \approx 6.9$ gives the wrong answer. The formula needs the base-2 logarithm, $\log_2$. - Confusing bits with bytes. The answer 10 is a count of bits. Ten bits is not ten bytes, and it fits in two bytes. ## Where you will meet it - Color depth in images, where 8 bits per channel give $2^{8} = 256$ levels for red, green and blue. - Network packet fields, such as the 12-bit VLAN ID field in Ethernet frames, which has 4096 possible values. - Analog-to-digital converters, where a 10-bit converter has 1024 levels. - Database and program design, where a field with 16 categories needs $\lceil \log_2 16 \rceil = 4$ bits. ## Questions people ask ### Why round up instead of to the nearest whole number? A code needs enough patterns. Rounding to the nearest whole number can round down. For example, $\log_2 600 \approx 9.23$ would round to 9, which gives only 512 codes for 600 items. Rounding up always gives enough patterns. ### Is this the same as the number of bits needed to write $N$? Not always. The formula counts codes for items numbered 0 to $N - 1$. Writing the number $N$ itself can need one more bit. The number 1024 needs 11 bits to write, but 1024 items need only 10 bits, since their codes run from 0 to 1023. ### How many bits do I need for one item? Zero bits, because $\lceil \log_2 1 \rceil = 0$. There is nothing to tell apart. Real systems often still use at least one bit for a field. ## Related formulas - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Two's Complement](https://formulabro.yunusemrevurgun.com/computer-science/twos-complement/) - [Hexadecimal Number Value](https://formulabro.yunusemrevurgun.com/computer-science/hexadecimal-number-value/) ## Sources - [Binary logarithm, Wikipedia](https://en.wikipedia.org/wiki/Binary_logarithm) - [Floor and ceiling functions, Wikipedia](https://en.wikipedia.org/wiki/Floor_and_ceiling_functions) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Big O Notation > Big O notation says that one function never grows faster than a fixed multiple of another, once the inputs are large enough. Page: https://formulabro.yunusemrevurgun.com/computer-science/big-o-notation/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ f(n) = O(g(n)) \iff \exists\, c > 0,\ n_0 \text{ such that } 0 \le f(n) \le c\, g(n) \text{ for all } n \ge n_0 $$ Read it out loud: "f of n is big O of g of n if and only if there exist a positive constant c and a starting point n sub 0 such that, for every n at least n sub 0, zero is at most f of n, and f of n is at most c times g of n." ## What each symbol means - $f(n)$: The function you want to bound, such as the number of steps an algorithm takes on an input of size $n$. - $g(n)$: The simpler reference function, such as $n$, $n^{2}$ or $\log n$. - $O(g(n))$: \"Big O of $g(n)$\": the set of functions that grow no faster than a fixed multiple of $g(n)$. - $n$: The size of the input, a whole number that can grow without limit. - $c$: A positive constant that scales $g(n)$ up. It is fixed and does not depend on $n$. - $n_0$: A starting point. The bound only has to hold for $n$ at or beyond $n_0$, so small inputs can be ignored. - $\iff$: \"If and only if\": the statement on the left holds exactly when the statement on the right holds. - $\exists$: \"There exists\": at least one choice of $c$ and $n_0$ works. ## What the formula is doing Big O notation describes how the work of an algorithm grows as its input gets bigger. It describes a shape, not an exact count. An algorithm that takes $3n + 5$ steps and one that takes $3n$ steps have the same shape, a straight line in $n$. Both are described as $O(n)$. The letter O stands for order, as in the order of growth. The definition has three parts. The function $f(n)$ must stay between 0 and $c \cdot g(n)$ for every large enough $n$. The constant $c$ absorbs any fixed multiplier, so $3n$ and $100n$ are both $O(n)$. The starting point $n_0$ lets you ignore small inputs, where the exact behavior can look different. Together they say that past some point, $f$ never climbs above a fixed multiple of $g$. Why are lower terms dropped? For large $n$, the biggest term decides almost everything. Take $n^{2} + 1000n$. At $n = 10{,}000$, the term $n^{2}$ is $100{,}000{,}000$, while $1000n$ is only $10{,}000{,}000$. So the growth is $O(n^{2})$, and the $1000n$ part does not change the class. The notation sorts algorithms by how they scale. An $O(n \log n)$ method beats an $O(n^{2})$ method on large inputs, even when the $O(n^{2})$ method has a smaller constant. Constants and small inputs still matter in practice, so big O is the first comparison, not the last. ## An everyday picture Think of a kitchen. Making $n$ sandwiches takes time that grows in a straight line. Whether each sandwich needs 3 steps or 4, and whether there is a 5-minute setup at the start, the line has the same shape, so the job is $O(n)$. Big O asks about the shape, not the exact number of steps. ## Worked example: Showing 3n + 5 is O(n) Let $f(n) = 3n + 5$ and $g(n) = n$. We need a constant $c$ and a starting point $n_0$ so that $0 \le 3n + 5 \le c \cdot n$ for every $n \ge n_0$. 1. Pick $c = 4$. We need $3n + 5 \le 4n$. Subtract $3n$ from both sides to get $5 \le n$. 2. So $n_0 = 5$ works. For every $n \ge 5$, we have $5 \le n$, so $3n + 5 \le 4n$. 3. Check the starting point. At $n = 5$, $3 \cdot 5 + 5 = 20$ and $4 \cdot 5 = 20$. The two sides are equal, which the definition allows. 4. Check a larger value. At $n = 10$, $3 \cdot 10 + 5 = 35$ and $4 \cdot 10 = 40$, so $35 \le 40$. 5. The lower bound $0 \le 3n + 5$ holds for every $n \ge 0$, so both parts of the definition are met. **Answer:** With $c = 4$ and $n_0 = 5$, the definition holds, so $3n + 5$ is **O(n)**. The $+5$ and the factor 3 do not change the shape of the growth. The work is a straight line in $n$. ## Common mistakes - Thinking $O(n)$ means exactly $n$ steps. Big O is an upper bound on growth. Both $3n + 5$ and $n / 2$ are $O(n)$. - Keeping constants and lower terms. Write $O(n^{2})$, not $O(3n^{2} + 5n + 2)$, and write $O(n)$, not $O(3n)$. - Judging small inputs by big O. At $n = 10$, an $O(n^{2})$ method with a tiny constant can beat an $O(n)$ method with a large one. Big O is about large $n$. - Confusing big O with the case being measured. Big O can describe the best, average or worst case of an algorithm. Name the case as well, such as worst-case $O(n^{2})$. ## Where you will meet it - Comparing sorting methods, such as merge sort at $O(n \log n)$ and bubble sort at $O(n^{2})$ in the worst case. - Choosing data structures, such as a hash table lookup that takes $O(1)$ time on average and a linear search that takes $O(n)$. - Database indexes, where a B-tree lookup takes $O(\log n)$ time. - Analyzing loops and recursion in textbooks and programming interviews. ## Questions people ask ### Why are constant factors ignored? The constant $c$ absorbs them. A faster computer changes the constant but not the shape of the growth. Big O compares how methods scale, and constant factors depend on the machine. ### What is the difference between O, Omega and Theta? Big O is an upper bound. Omega, written $\Omega$, is a lower bound. Theta, written $\Theta$, is a tight bound: the function is both $O$ and $\Omega$ of the same $g(n)$. ### Is an $O(n)$ method always faster than an $O(n^{2})$ method? Not for small inputs. At $n = 10$, an $n^{2}$ method with a small constant can finish first. For large $n$ the $O(n)$ method wins, because its growth is much slower. ## Related formulas - [Master Theorem](https://formulabro.yunusemrevurgun.com/computer-science/master-theorem/) - [Sum of the First n Integers](https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers/) - [Geometric Series](https://formulabro.yunusemrevurgun.com/computer-science/geometric-series/) - [Binary Search Steps](https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/) ## Sources - [Big O notation, Wikipedia](https://en.wikipedia.org/wiki/Big_O_notation) - [Time complexity, Wikipedia](https://en.wikipedia.org/wiki/Time_complexity) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Master Theorem > The master theorem gives the running time of a divide-and-conquer algorithm by comparing the work at each split with the work at the bottom of the recursion. Page: https://formulabro.yunusemrevurgun.com/computer-science/master-theorem/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ T(n) = a\, T(n/b) + f(n) $$ Read it out loud: "T of n equals a times T of n divided by b, plus f of n. Here a is the number of smaller pieces, and b is how much smaller each piece is." ## What each symbol means - $T(n)$: The running time of the algorithm on an input of size $n$, counted in basic steps. - $n$: The size of the input. - $a$: The number of smaller subproblems made at each step. It is a whole number, at least 1. - $b$: The factor by which the input shrinks for each subproblem. Each subproblem has size $n/b$, and $b > 1$. - $T(n/b)$: The running time of one subproblem, which has size $n/b$. - $f(n)$: The extra work at one level, outside the recursive calls: splitting the input and combining the answers. ## What the formula is doing Many fast algorithms use divide and conquer. They split a problem of size $n$ into $a$ smaller problems, each of size $n/b$, solve those pieces with the same method, and combine the answers. The recurrence $T(n) = a\,T(n/b) + f(n)$ adds up the time: the time for the $a$ smaller pieces, plus $f(n)$ for the splitting and combining. The master theorem gives the answer for this form without drawing the whole recursion tree. Picture the recursion as a tree. The top problem has size $n$. After $k$ levels there are $a^{k}$ subproblems, each of size $n / b^{k}$. The tree bottoms out after $\log_b n$ levels, where each piece has size 1. The bottom level has $a^{\log_b n} = n^{\log_b a}$ pieces, so $n^{\log_b a}$ measures the work at the bottom. The question is which is larger: the bottom work $n^{\log_b a}$, or the splitting work $f(n)$ at each level. There are three cases. If $f(n)$ grows clearly more slowly than $n^{\log_b a}$, the bottom dominates, and $T(n) = \Theta(n^{\log_b a})$. If $f(n)$ grows at the same rate as $n^{\log_b a}$, each of the $\log_b n$ levels costs about the same, so $T(n) = \Theta(n^{\log_b a} \log n)$. If $f(n)$ grows clearly faster, the top level dominates, and $T(n) = \Theta(f(n))$. That last case also needs a mild regularity condition on $f$, which holds for the usual textbook functions such as $n^{2}$. The theorem covers only this exact shape. Every subproblem has the same size $n/b$, the numbers $a$ and $b$ are constants, and $f$ is a simple function of $n$. A recurrence such as $T(n) = T(n-1) + n$ subtracts instead of dividing, so it needs a different method. ## An everyday picture Think of a company where a boss splits a project between 2 managers, and each manager splits their part between 2 teams, down to single workers. You can ask where most of the effort goes: to the many small jobs at the bottom, to the middle levels, or to the planning and reporting at the top. The master theorem asks the same question about the recursion tree. ## Worked example: Merge sort: T(n) = 2T(n/2) + n Merge sort splits a list of $n$ numbers into 2 halves, sorts each half, and merges the two sorted halves in time proportional to $n$. So $a = 2$, $b = 2$ and $f(n) = n$, which gives $T(n) = 2\,T(n/2) + n$. 1. Find the bottom exponent: $\log_b a = \log_2 2 = 1$, so $n^{\log_b a} = n^{1} = n$. 2. Compare: $f(n) = n$ and $n^{\log_b a} = n$ grow at exactly the same rate. This is the middle case. 3. Apply the middle case: $T(n) = \Theta(n^{\log_b a} \log n) = \Theta(n \log n)$. 4. Check with $n = 1024$. There are $\log_2 1024 = 10$ levels, and each level does about $1024$ units of merging work, so the total is about $10 \cdot 1024 = 10{,}240$ units. 5. For comparison, $1024^{2} = 1{,}048{,}576$, which is about 100 times more work than $10{,}240$. **Answer:** Merge sort takes $\Theta(n \log n)$ time. For 1024 items that is about **10,240** units of work, not the **1,048,576** units that $n^{2}$ would need. ## Common mistakes - Mixing up $a$ and $b$. The number $a$ counts subproblems, and $b$ says how much smaller each one is. Merge sort has $a = 2$ and $b = 2$. - Treating $f(n)$ as the total running time. $f(n)$ is only the work done at one level, outside the recursive calls. - Stopping at the middle case too early. When $f(n)$ matches $n^{\log_b a}$, multiply by $\log n$. The answer is $\Theta(n^{\log_b a} \log n)$, not $\Theta(n^{\log_b a})$. - Using the theorem on a recurrence that does not fit, such as $T(n) = T(n-1) + n$. That one subtracts 1 each time instead of dividing by $b$. ## Where you will meet it - Analyzing merge sort, which splits a list in half, sorts each half and merges the results. - Binary search, where $T(n) = T(n/2) + 1$ gives $\Theta(\log n)$ time. - Strassen's matrix multiplication, where $T(n) = 7\,T(n/2) + \Theta(n^{2})$ gives about $n^{2.81}$ time. - Karatsuba multiplication of large numbers, where $T(n) = 3\,T(n/2) + O(n)$ gives about $n^{1.585}$ time. ## Questions people ask ### Does the master theorem work for every recurrence? No. It applies to recurrences of the form $T(n) = a\,T(n/b) + f(n)$, with constant $a \geq 1$ and $b > 1$. Other recurrences need a recursion tree or the substitution method. ### How do I compare $f(n)$ with $n^{\log_b a}$? Compute the exponent $\log_b a$ first. For $a = 7$ and $b = 2$ it is $\log_2 7 \approx 2.81$, so the bottom work is about $n^{2.81}$. Then compare growth rates. Since $n^{2}$ grows more slowly than $n^{2.81}$, the first case applies to $f(n) = n^{2}$. ### Why does the middle case have a log n factor? The recursion has $\log_b n$ levels, and each level does about the same total work. Multiplying the work per level by the number of levels gives the extra $\log n$ factor. ## Related formulas - [Big O Notation](https://formulabro.yunusemrevurgun.com/computer-science/big-o-notation/) - [Sum of the First n Integers](https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers/) - [Geometric Series](https://formulabro.yunusemrevurgun.com/computer-science/geometric-series/) - [Binary Search Steps](https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/) ## Sources - [Master theorem (analysis of algorithms), Wikipedia](https://en.wikipedia.org/wiki/Master_theorem_(analysis_of_algorithms)) - [Merge sort, Wikipedia](https://en.wikipedia.org/wiki/Merge_sort) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Sum of the First n Integers > This formula adds the counting numbers from 1 to n in one step, so you never have to add them one at a time. Page: https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} $$ Read it out loud: "The sum, for every whole number i from 1 up to n, of i equals n times n plus 1, divided by 2." ## What each symbol means - $\sum_{i=1}^{n} i$: The total of all the whole numbers from 1 up to $n$: $1 + 2 + \cdots + n$. - $i$: The counter. It takes each whole number from 1 to $n$ in turn. - $n$: The last number in the list, a whole number that is 0 or more. - $\frac{n(n+1)}{2}$: The closed form: multiply $n$ by the next number, $n + 1$, then divide by 2. ## What the formula is doing The sum $1 + 2 + 3 + \cdots + n$ appears whenever a task takes one step for the first item, two for the second, and so on up to $n$. Adding the numbers one at a time takes $n$ additions. The formula gives the total in one step, with one multiplication and one division. Here is why it works. Write the list twice, once forward and once backward, and add the two copies column by column. The first number and the last make $1 + n$. The second and the second to last make $2 + (n - 1)$. Each column adds to $n + 1$. There are $n$ columns, so both copies together add to $n(n+1)$. One copy is half of that, which gives $\frac{n(n+1)}{2}$. The result grows like $\frac{n^{2}}{2}$. The later terms are large and the early terms are small, so the total is about half of $n^{2}$. This matters for nested loops. A loop over $i$ from 1 to $n$ that runs an inner loop $i$ times does $\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$ steps in all. That is about half of $n^{2}$, which is still $O(n^{2})$ in big O notation. ## An everyday picture Think of stacking cans in a triangle. The top row has 1 can, the next row has 2, and the bottom row has $n$. The total is the sum. Copy the triangle, flip the copy and fit it against the original. Together they form a rectangle $n$ rows tall and $n + 1$ cans wide. The rectangle holds $n(n+1)$ cans, so one triangle holds half of them. ## Worked example: Adding 1 to 100 Add the whole numbers from 1 to $n = 100$. Then count the steps of a nested loop that uses the same total. 1. Find the next number: $n + 1 = 101$. 2. Multiply: $n(n + 1) = 100 \cdot 101 = 10{,}100$. 3. Divide by 2: $\frac{10{,}100}{2} = 5{,}050$. So $1 + 2 + \cdots + 100 = 5{,}050$. 4. Nested loop: an outer loop runs $i$ from 1 to 100, and the inner loop runs $i$ times for each $i$. The inner body runs $1 + 2 + \cdots + 100 = 5{,}050$ times in total. 5. Compare with $n^{2} = 10{,}000$. The nested loop does about half that work, so it is still $O(n^{2})$. **Answer:** The sum of the whole numbers from 1 to 100 is **5,050**. A nested loop whose inner body runs $i$ times for each $i$ up to 100 does **5,050** steps, which is about half of $100^{2}$. ## Common mistakes - Using $\frac{n(n-1)}{2}$ for the sum from 1 to $n$. That formula stops at $n - 1$. The sum up to $n$ uses $\frac{n(n+1)}{2}$. - Forgetting the division by 2. The product $n(n+1)$ counts both copies of the list, so it is twice the sum. - Using the triangle formula for a fixed inner loop. If the inner loop always runs $n$ times, the total is $n^{2}$, not $\frac{n(n+1)}{2}$. The formula needs the inner count to grow with $i$. - Expecting an exact $n^{2}$ result. The sum is $\frac{n^{2}}{2} + \frac{n}{2}$, so the lower term $\frac{n}{2}$ is not zero. Big O drops it, but the exact count keeps it. ## Where you will meet it - Counting comparisons in bubble sort, where each pass checks one fewer pair than the pass before. - Counting handshakes: in a group of $n$ people, where each pair shakes hands once, there are $\frac{n(n-1)}{2}$ handshakes, which is the sum of the first $n - 1$ integers. - Triangular numbers, such as the number of cans in a stacked triangle. - Analyzing the cost of algorithms that check every pair of items in a list. ## Questions people ask ### Why is there a divide by 2? Every value is counted twice when you write the list forward and backward. Dividing by 2 removes the double count. ### Does the formula work when $n = 0$? Yes. An empty sum is 0, and $\frac{0 \cdot 1}{2} = 0$. ### How does this connect to big O? The sum grows like $\frac{n^{2}}{2}$, so it is $O(n^{2})$. Big O drops the constant $\frac{1}{2}$ and the lower term. ## Related formulas - [Big O Notation](https://formulabro.yunusemrevurgun.com/computer-science/big-o-notation/) - [Geometric Series](https://formulabro.yunusemrevurgun.com/computer-science/geometric-series/) - [Master Theorem](https://formulabro.yunusemrevurgun.com/computer-science/master-theorem/) ## Sources - [Triangular number, Wikipedia](https://en.wikipedia.org/wiki/Triangular_number) - [Summation, Wikipedia](https://en.wikipedia.org/wiki/Summation) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Geometric Series > A geometric series adds terms where each one is the last one times a fixed ratio, and this formula adds them all in one step. Page: https://formulabro.yunusemrevurgun.com/computer-science/geometric-series/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \sum_{k=0}^{n-1} r^{k} = \frac{1 - r^{n}}{1 - r} \quad (r \neq 1) $$ Read it out loud: "The sum, for k from 0 up to n minus 1, of r to the power of k, equals one minus r to the power of n, divided by one minus r. This works when r is not equal to 1." ## What each symbol means - $\sum_{k=0}^{n-1}$: \"Add up the terms for every $k$ from 0 to $n - 1$\". That is $n$ terms in all. - $k$: The step counter, starting at 0. The first term is $r^{0} = 1$. - $r^{k}$: The term at step $k$: $r$ multiplied by itself $k$ times. - $r$: The common ratio. Each term is the one before it times $r$. The formula needs $r \neq 1$. - $n$: The number of terms in the series. - $\frac{1 - r^{n}}{1 - r}$: The closed form for the sum. The division by $1 - r$ is why $r = 1$ is excluded. ## What the formula is doing A geometric series is a list of terms where each term is the one before it times a fixed number $r$. The number $r$ is the common ratio. With $r = 2$ the list is $1, 2, 4, 8, 16$, and each term doubles the last one. The formula adds the first $n$ terms, starting from $r^{0} = 1$. The trick is to multiply the sum by $r$ and subtract. Call the sum $S$. Then $rS$ is the same list shifted one place along, so almost every term cancels in $S - rS$. What is left is $S - rS = 1 - r^{n}$. Dividing by $1 - r$ gives $S = \frac{1 - r^{n}}{1 - r}$. The division needs $r \neq 1$. If $r = 1$, every term is 1 and the sum is $n$. The behavior depends on whether $r$ is bigger or smaller than 1. If $r > 1$, the last term is the biggest, and for large $n$ the sum is close to $\frac{r^{n}}{r - 1}$. If $0 < r < 1$, the terms shrink, and the sum settles toward $\frac{1}{1 - r}$ as $n$ grows. For $r = \frac{1}{2}$, the sum $1 + \frac{1}{2} + \frac{1}{4} + \cdots$ approaches 2. This is why doubling is cheap on average. The early steps are small, and the total is less than twice the final size. In the example below, the copies made while a list doubles add up to less than twice the number of items. The last step alone is about half of all the work. ## An everyday picture Think of a savings plan that doubles each week. You save 1 dollar in week 1, 2 dollars in week 2, 4 dollars in week 3, and so on. After $n$ weeks your total is one dollar less than twice what you saved in the last week. ## Worked example: Copies in a doubling array A dynamic array starts with room for 1 item. When it is full and a new item arrives, it builds a new array with twice the room and copies every item across. We add $n = 10$ items and count the copies. 1. Each resize happens when the array is full. Adding item 2 copies 1 item into a room of 2. Adding item 3 copies 2 items into a room of 4. Adding item 5 copies 4 items into a room of 8. Adding item 9 copies 8 items into a room of 16. 2. The copies form a geometric series with $r = 2$: $1 + 2 + 4 + 8$. That is 4 terms. 3. Apply the formula with $r = 2$ and 4 terms: $\frac{1 - 2^{4}}{1 - 2} = \frac{1 - 16}{-1} = 15$ copies. 4. Compare with the list size: $2 \cdot 10 = 20$, and $15 < 20$. The copies stay below twice the number of items. **Answer:** Inserting 10 items causes **15** copies in total, which is less than $2 \cdot 10 = 20$. In general, doubling keeps the total copying below twice the number of items, so each insert costs about 2 copies or fewer on average. ## Common mistakes - Using the formula with $r = 1$. The denominator $1 - r$ becomes zero. When $r = 1$, every term is 1, so the sum is $n$. - Miscounting the terms. The sum from $k = 0$ to $n - 1$ has $n$ terms. The sum from $k = 1$ to $n$ is different: it equals $r \cdot \frac{1 - r^{n}}{1 - r}$. - Flipping the sign. Write $\frac{1 - r^{n}}{1 - r}$, not $\frac{r^{n} - 1}{1 - r}$, which is the negative of the sum. - Mixing up $r$ and $n$. The ratio $r$ is how much each term multiplies, and $n$ is how many terms there are. ## Where you will meet it - Dynamic arrays that double in size, where the total copying stays below twice the final size. - Compound growth, such as an amount that is multiplied by the same factor each period. - Discounted rewards in reinforcement learning, where a reward received $k$ steps later is multiplied by $\gamma^{k}$, so the total is a geometric series. - Full binary trees, where level $k$ holds $2^{k}$ nodes, so the total node count is a geometric series. ## Questions people ask ### What happens when $r$ is greater than 1? The formula still works. For $r = 2$ and 10 terms it gives $\frac{1 - 2^{10}}{1 - 2} = 1023$, which is $1 + 2 + \cdots + 512$. The last term is about half of the total. ### Why does the sum settle when $r$ is between 0 and 1? Each power $r^{n}$ shrinks toward 0 as $n$ grows, so the top of the formula goes to 1. The sum then goes to $\frac{1}{1 - r}$. For $r = \frac{1}{2}$, that limit is 2. ### Why is $r = 1$ a special case? The formula divides by $1 - r$, which is zero when $r = 1$. In that case each term is 1, and the sum is $n$. ## Related formulas - [Sum of the First n Integers](https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers/) - [Big O Notation](https://formulabro.yunusemrevurgun.com/computer-science/big-o-notation/) - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) ## Sources - [Geometric series, Wikipedia](https://en.wikipedia.org/wiki/Geometric_series) - [Dynamic array, Wikipedia](https://en.wikipedia.org/wiki/Dynamic_array) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Permutations > A permutation is an ordered arrangement, and this formula counts how many ways you can pick k items from n and line them up. Page: https://formulabro.yunusemrevurgun.com/computer-science/permutations/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P(n, k) = \frac{n!}{(n-k)!} $$ Read it out loud: "P of n, k, equals n factorial, divided by n minus k factorial." ## What each symbol means - $P(n, k)$: The number of permutations: the ordered ways to choose and arrange $k$ items out of $n$ different items. - $n$: How many different items are available. - $k$: How many items you pick and arrange. When items cannot repeat, $k$ cannot be larger than $n$. - $n!$: The factorial of $n$: $n \cdot (n-1) \cdots 2 \cdot 1$. For example, $4! = 24$. By convention, $0! = 1$. - $(n-k)!$: The factorial of the number of items left out. Dividing by it cancels the orderings of the leftover part. ## What the formula is doing A permutation is an ordered arrangement. Order matters, so the arrangement $ABC$ is different from $BCA$. Suppose you have $n$ different items and want to fill $k$ spots in order. The question is how many different ways there are to fill those spots. Fill the spots one at a time. The first spot can take any of the $n$ items. The second spot can take any of the other $n - 1$ items. The third spot has $n - 2$ choices, and the $k$th spot has $n - k + 1$ choices. Multiply the choices together to get $n(n-1)(n-2)\cdots(n-k+1)$. The factorial form writes that product compactly. $n!$ is the product of all $n$ numbers, $n \cdot (n-1) \cdots 1$. Dividing by $(n-k)!$ removes the factors from $n - k$ down to 1, which leaves exactly the $k$ factors from $n$ down to $n - k + 1$. Two edge cases check the formula. When $k = n$ the answer is $n!$, the count of all full arrangements. When $k = 0$ the answer is 1, the single empty arrangement. The rule changes when items can repeat, such as the digits in a PIN. Each spot then has all $n$ choices, so there are $n^{k}$ arrangements. The permutation formula is only for items that cannot repeat. ## An everyday picture Think of a playlist. You have 10 songs and want a 3-song playlist played in order. The first slot has 10 choices, the second has 9, and the third has 8. The playlist that plays A, B, C is different from the one that plays B, A, C, even though both use the same songs. So the count is $10 \cdot 9 \cdot 8 = 720$. ## Worked example: Podium places in an 8-runner race Eight runners race, and the top three finishers take gold, silver and bronze. Those are different places, so order matters. Here $n = 8$ runners and $k = 3$ podium places. 1. Write the formula: $P(8, 3) = \frac{8!}{(8-3)!} = \frac{8!}{5!}$. 2. Compute the factorials: $8! = 40{,}320$ and $5! = 120$. 3. Divide: $\frac{40{,}320}{120} = 336$. 4. Check by filling the spots: gold has 8 choices, silver has 7 and bronze has 6, so $8 \cdot 7 \cdot 6 = 336$. **Answer:** There are **336** different ways to fill gold, silver and bronze from 8 runners. Each different order of the top three is a different result. ## Common mistakes - Ignoring order. Counting the podium as a set of three runners gives a smaller number, because gold-silver-bronze and bronze-silver-gold are different results. When order does not matter, use combinations instead. - Multiplying $n$ by $k$. $P(8, 3)$ is $8 \cdot 7 \cdot 6 = 336$, not $8 \cdot 3 = 24$. Count down from $n$ for $k$ spots. - Using the formula when items can repeat. A four-digit PIN can repeat digits, so it has $10^{4} = 10{,}000$ options, not $P(10, 4) = 5{,}040$. - Asking for more items than exist. With 3 items and no repeats, there are no ways to arrange 5 of them. Make sure $k \leq n$. ## Where you will meet it - Race results and rankings, where first, second and third place are different outcomes. - Counting anagrams. The word CAT has $3! = 6$ arrangements of its three different letters: CAT, CTA, ACT, ATC, TAC and TCA. - Brute-force search in computing, where a program tries every order of a list of distinct items, such as the stops on a delivery route. - Counting codes or passwords that cannot repeat a character, where the first character has $n$ choices and the next has one fewer. ## Questions people ask ### What is the difference between a permutation and a combination? In a permutation the order matters. In a combination it does not. Each group of $k$ items can be arranged in $k!$ orders, so the number of combinations is $\frac{P(n, k)}{k!}$. ### Why is $0! = 1$? It is a convention that keeps formulas like this one working. With $k = n$, the formula gives $P(n, n) = \frac{n!}{0!}$, and that must equal $n!$ because every item is used. ### How many ways can I arrange all $n$ items? There are $n!$ ways. Five books on a shelf can be arranged in $5! = 120$ orders. That is the same as $P(5, 5)$. ## Related formulas - [Big O Notation](https://formulabro.yunusemrevurgun.com/computer-science/big-o-notation/) - [Bits Needed](https://formulabro.yunusemrevurgun.com/computer-science/bits-needed/) - [Sum of the First n Integers](https://formulabro.yunusemrevurgun.com/computer-science/sum-of-first-n-integers/) ## Sources - [Permutation, Wikipedia](https://en.wikipedia.org/wiki/Permutation) - [Factorial, Wikipedia](https://en.wikipedia.org/wiki/Factorial) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Combinations > A combination counts how many different groups you can pick from a set of items when the order of the picks does not matter. Page: https://formulabro.yunusemrevurgun.com/computer-science/combinations/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ C(n,k) = \binom{n}{k} = \frac{n!}{k!\,(n-k)!} $$ Read it out loud: "C of n, k, equals n choose k, which equals n factorial divided by k factorial times n minus k factorial. The order of the picks does not matter." ## What each symbol means - $C(n,k)$: The number of **combinations**, read as 'n choose k'. It counts groups, so it has no unit. The same number is also written $\binom{n}{k}$. - $n$: The total number of items to pick from. It is a whole number, 0 or more. - $k$: How many items you pick. It is a whole number from 0 to $n$. - $n!$: The **factorial** of $n$: $n \times (n-1) \times \cdots \times 2 \times 1$. For example $4! = 24$. By convention, $0! = 1$. ## What the formula is doing A combination answers one question: how many different groups of $k$ items can you pick from $n$ items, when the order of the picks does not matter? Picking Ana and then Ben gives the same group as picking Ben and then Ana, so only one of those counts. The answer is a whole number with no unit. Start with the ordered case. The first pick has $n$ choices, the second has $n-1$, and so on down to $n-k+1$ for the last pick. That gives $\frac{n!}{(n-k)!}$ ordered picks. Each group of $k$ items shows up in $k!$ different orders, so the ordered count repeats every group $k!$ times. Dividing by $k!$ removes those repeats, which leaves $\frac{n!}{k!\,(n-k)!}$. The factorials make the pattern easy to read. The $(n-k)!$ part cancels the factors for the items you did not pick. A useful fact follows from the formula: $\binom{n}{k} = \binom{n}{n-k}$. Choosing the $k$ items you want is the same as choosing the $n-k$ items you leave out. Use combinations when a group matters and a list does not, such as a team, a set of toppings or a poker hand. When the order does matter, for example for first, second and third place, use permutations instead. For the same $n$ and $k$, permutations always give at least as many answers, because each group can be ordered in $k!$ ways. ## An everyday picture Think of picking a team of three friends from five for a board game. Ana, Ben and Cy is the same team as Cy, Ben and Ana, so the order you chose them in does not count. A combination counts the teams, not the orders in which each team was picked. ## Worked example: Picking a team of 3 from 5 friends You have 5 friends and want a team of 3 for a board game. The order you pick them in does not matter, so we need the number of combinations $C(5,3)$. 1. Count the ordered picks. The first pick has 5 choices, the second has 4 and the third has 3, so there are $5 \cdot 4 \cdot 3 = 60$ ordered picks. 2. Count the orders inside one team. A team of 3 can be lined up in $3! = 3 \cdot 2 \cdot 1 = 6$ ways, so each team shows up 6 times among the 60. 3. Divide out the repeats: $C(5,3) = \frac{60}{6} = 10$. 4. Check with the formula: $C(5,3) = \frac{5!}{3!\,2!} = \frac{120}{6 \cdot 2} = \frac{120}{12} = 10$. **Answer:** There are **10 different teams** of 3 friends. The ordered count of 60 is six times too big, because each team appears in six different orders. ## Common mistakes - Counting order. Ana then Ben and Ben then Ana are one combination, not two. If your count is about $k!$ times too big, you have counted the orders. - Letting $k$ be bigger than $n$. You cannot pick 4 items from 3, so the number of groups is 0. - Mixing up combinations and permutations. A race with first, second and third place needs permutations, because the order of finish matters. - Forgetting that $0! = 1$. It matters for $C(n,0) = 1$ and $C(n,n) = 1$: picking nothing, or picking everything, each has exactly one answer. ## Where you will meet it - Counting poker hands and lottery draws, where the cards or numbers in one hand or draw form a group, not a list. - Choosing toppings, side dishes or committee members when the order of choosing does not matter. - Probability, where the chance of an event is the number of favorable groups divided by the number of all possible groups. - Pascal's triangle and the binomial theorem, where the numbers $\binom{n}{k}$ are the coefficients of $(a+b)^n$. ## Questions people ask ### What is the difference between combinations and permutations? A permutation counts ordered arrangements, such as first, second and third place. A combination counts groups where the order is ignored. For the same $n$ and $k$, the permutation count is $k!$ times the combination count. ### Why do the factorials give a whole number? Every group is counted $k!$ times in the ordered count, so dividing by $k!$ leaves exactly one count per group. The result is always a whole number. ### What are $C(n,0)$ and $C(n,n)$? Both equal 1. There is exactly one way to pick nothing, and exactly one way to pick everything. ## Related formulas - [Permutations](https://formulabro.yunusemrevurgun.com/computer-science/permutations/) - [Inclusion-Exclusion Principle](https://formulabro.yunusemrevurgun.com/computer-science/inclusion-exclusion-principle/) - [Pigeonhole Principle](https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle/) ## Sources - [Combination, Wikipedia](https://en.wikipedia.org/wiki/Combination) - [Binomial coefficient, Wikipedia](https://en.wikipedia.org/wiki/Binomial_coefficient) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Pigeonhole Principle > If you put more things than boxes into the boxes, at least one box must hold two or more things. Page: https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \max_{j}\, b_j \ge \left\lceil \frac{n}{m} \right\rceil $$ Read it out loud: "The largest number of items in any box is at least the ceiling of n over m. The ceiling means n divided by m, rounded up to the next whole number." ## What each symbol means - $\max_{j}\, b_j$: The number of items in the **fullest box**. The letter $j$ names a box, and $b_j$ is how many items box $j$ holds. - $n$: The number of items being placed into the boxes. It is a whole number. - $m$: The number of boxes. It is a whole number, at least 1. - $\left\lceil x \right\rceil$: The **ceiling** of $x$: $x$ rounded up to the next whole number. For example $\lceil 2.08 \rceil = 3$ and $\lceil 4 \rceil = 4$. ## What the formula is doing The pigeonhole principle is a rule about counting. Put $n$ items into $m$ boxes. If $n$ is bigger than $m$, then at least one box must hold two or more items. The general form is stronger: the fullest box holds at least $\left\lceil \frac{n}{m} \right\rceil$ items, where the ceiling rounds $\frac{n}{m}$ up to the next whole number. Here is why it must be true. Suppose every box held at most $\left\lceil \frac{n}{m} \right\rceil - 1$ items. Then the boxes would hold at most $m$ times that number in total. But $\left\lceil \frac{n}{m} \right\rceil - 1$ is less than $\frac{n}{m}$, so that total is less than $n$. That leaves some items with nowhere to go, which is a contradiction. So some box must hold at least $\left\lceil \frac{n}{m} \right\rceil$ items. The rule says nothing about which box is crowded, or how the items got there. It only promises that one box is full enough. That is what makes it useful: you can prove that a repeat or a collision must happen without finding the example itself. The simplest case is $n = m + 1$. Then $\frac{m+1}{m}$ is a little over 1, and its ceiling is 2, so some box holds two items. The guaranteed crowding only goes up when the number of items passes a multiple of the number of boxes. ## An everyday picture Think of a coat rack with 4 hooks and 5 coats. Hang every coat on a hook, and one hook must carry at least two coats, because there is no way to avoid it. You do not have to see which hook it is to be sure a crowded hook exists. ## Worked example: Birthday months in a club A club has 25 members, and each one has a birthday in one of 12 months. The months are the boxes and the members are the items. What is the least number of members that the fullest month must hold? 1. Divide the members by the months: $\frac{25}{12} \approx 2.08$. 2. Round up to the next whole number: $\left\lceil 2.08 \right\rceil = 3$. 3. Check the reasoning. If every month held at most 2 members, the total would be at most $12 \cdot 2 = 24$. But there are 25 members, so at least one month must hold 3. **Answer:** The fullest month holds **at least 3 members**. The principle proves this for any club of 25 people, without knowing a single birthday. ## Common mistakes - Expecting the principle to name the crowded box. It proves that a box with at least 3 members exists, but it does not say which month it is. - Rounding down. The floor of $\frac{25}{12}$ is 2, which is too small. The ceiling, 3, is the guaranteed value. - Thinking every box must hold something. Some boxes may stay empty. The rule only sets a lower bound for the fullest box. - Swapping the counts. The items go into the boxes, so $n$ is the number of items and $m$ is the number of boxes. ## Where you will meet it - Hash tables: once there are more keys than buckets, at least two keys must share a bucket, which is a collision. - Lossless compression: no method can shrink every file of a fixed length, because there are fewer shorter bit strings than files of that length. - Number theory proofs, such as showing that among any 5 whole numbers, two have the same remainder when divided by 4. - Scheduling and seating puzzles, where a limited number of slots forces at least one slot to be shared. ## Questions people ask ### Does the principle say which box is crowded? No. It only proves that some box holds at least $\left\lceil \frac{n}{m} \right\rceil$ items. It does not name the box. ### Where does the name come from? The picture is pigeons flying into pigeonholes, the small compartments in a desk or cabinet. With more pigeons than holes, one hole has to hold two pigeons. ### How does it apply to hash collisions? A hash table with $m$ buckets that stores $n > m$ keys must have at least one bucket with two or more keys. The collision cannot be avoided once the keys outnumber the buckets. ## Related formulas - [Hash Table Load Factor](https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor/) - [Birthday Problem](https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem/) - [Combinations](https://formulabro.yunusemrevurgun.com/computer-science/combinations/) ## Sources - [Pigeonhole principle, Wikipedia](https://en.wikipedia.org/wiki/Pigeonhole_principle) - [Floor and ceiling functions, Wikipedia](https://en.wikipedia.org/wiki/Floor_and_ceiling_functions) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Inclusion-Exclusion Principle > Inclusion-exclusion counts how many items belong to at least one group by adding the groups and then removing the overlaps that were counted twice. Page: https://formulabro.yunusemrevurgun.com/computer-science/inclusion-exclusion-principle/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ |A \cup B| = |A| + |B| - |A \cap B| $$ Read it out loud: "The size of A union B equals the size of A, plus the size of B, minus the size of A intersect B." ## What each symbol means - $|A \cup B|$: The number of items in **either** set $A$ or set $B$, or in both, with each item counted once. The vertical bars mean the size, or count, of a set. - $|A|$: The number of items in set $A$. - $|B|$: The number of items in set $B$. - $|A \cap B|$: The number of items in **both** $A$ and $B$. Those items were counted in $|A|$ and again in $|B|$, so they are subtracted once. ## What the formula is doing Inclusion-exclusion counts a union of sets without double counting. Adding $|A|$ and $|B|$ counts every item in both sets twice. So the overlap $|A \cap B|$ is subtracted once to fix that. The result is the number of items in $A$ or $B$, with each item counted exactly once. The same idea works for three sets. The formula is $$|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C|$$ Adding the three sizes counts each item once for every set it is in. Subtracting the three pairwise overlaps removes the extra counts. But an item in all three sets was counted 3 times and then subtracted 3 times, so it now counts as zero. The triple overlap is added back once to fix that. The signs alternate: add the single sets, subtract the pairs, add the triples, and so on for more sets. Each extra set adds more terms, so the method is most useful when the overlaps are easy to count. This is the tool for questions that ask how many items have at least one property. Counting each property on its own and then correcting the overlaps is often easier than counting the mixed cases one at a time. ## An everyday picture Think of two guest lists for a party, one for a chess club and one for a choir. Some people are on both lists. Adding the two list lengths counts those people twice. Subtract the people who are on both lists, and you have the number of different people who came from at least one list. ## Worked example: Students in three school activities A school has 60 students. Let $A$ be the chess club (30 students), $B$ the choir (25 students) and $C$ the robotics team (20 students). Overlaps: 10 students are in $A$ and $B$, 8 are in $A$ and $C$, 6 are in $B$ and $C$, and 4 are in all three. How many students are in at least one activity, and how many are in none? 1. Add the three single counts: $|A| + |B| + |C| = 30 + 25 + 20 = 75$. 2. Subtract the three pairwise overlaps: $10 + 8 + 6 = 24$, so $75 - 24 = 51$. 3. Add back the triple overlap: $51 + 4 = 55$. So $|A \cup B \cup C| = 55$. 4. Students in no activity: $60 - 55 = 5$. **Answer:** **55 students** are in at least one activity, and **5 students** are in none. The 4 students in all three activities are counted exactly once in the final total. ## Common mistakes - Forgetting to subtract the overlap. Adding $|A| + |B|$ alone counts shared items twice, so the union comes out too big. - Stopping after the pairs when there are three sets. The triple overlap must be added back, or the students in all three activities disappear from the count. - Confusing $\cup$ and $\cap$. The union $\cup$ means "or", and the intersection $\cap$ means "and". - Assuming the sets do not overlap. If they do, you must subtract. The plain sum is only right when every overlap is zero. ## Where you will meet it - Counting the whole numbers from 1 to 100 that are divisible by 2 or by 5. Here $50 + 20 - 10 = 60$ numbers qualify. - Probability: the chance of $A$ or $B$ is $P(A) + P(B) - P(A \text{ and } B)$, the same formula with probabilities in place of counts. - Counting derangements, the arrangements where no item stays in its original place. - Counting passwords or codes that meet at least one rule, such as containing a digit or a capital letter. ## Questions people ask ### Why do we subtract the overlap instead of counting each set once? An item in both sets gets added twice, once for each set. Subtracting the overlap once leaves each item counted exactly one time. ### Does the formula always subtract? For two sets, the overlap is always subtracted. For three sets the signs alternate: add the singles, subtract the pairs, then add the triple overlap. ### What happens when the sets do not overlap? Then $|A \cap B| = 0$ and the formula reduces to $|A| + |B|$, the ordinary sum. ## Related formulas - [De Morgan's Laws](https://formulabro.yunusemrevurgun.com/computer-science/de-morgans-laws/) - [Combinations](https://formulabro.yunusemrevurgun.com/computer-science/combinations/) - [Pigeonhole Principle](https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle/) ## Sources - [Inclusion-exclusion principle, Wikipedia](https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle) - [Union (set theory), Wikipedia](https://en.wikipedia.org/wiki/Union_(set_theory)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Hash Table Load Factor > The load factor is how full a hash table is on average: the number of keys divided by the number of buckets. Page: https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \alpha = \frac{n}{m} $$ Read it out loud: "alpha equals n over m. The load factor equals the number of keys divided by the number of buckets." ## What each symbol means - $\alpha$: The **load factor**, a plain number with no unit. It says how many keys there are, on average, for each bucket. - $n$: The number of keys stored in the table. - $m$: The number of **buckets**, the slots that keys are sorted into by the hash function. ## What the formula is doing A hash table sorts each key into a bucket. A hash function turns the key into a bucket number, and the table has $m$ buckets. The load factor $\alpha = \frac{n}{m}$ divides the number of stored keys $n$ by the number of buckets $m$. A load factor of 0.5 means there is about half a key per bucket, on average. With chaining, each bucket holds a short list of the keys that landed there. If the hash function spreads keys evenly, the average list has length $\alpha$. An unsuccessful lookup, one that finds nothing, checks about $\alpha$ keys on average. So the work per lookup depends on $\alpha$, not on the total size of the table. A small load factor means short lists and fast lookups. A large one means long lists and slow lookups. A table cannot stay small forever. As keys are added, $\alpha$ rises, so the table must grow. A common plan is to choose a threshold, such as 0.75, and resize when $\alpha$ passes it. Doubling the number of buckets cuts $\alpha$ in half, and every key is then moved to its new bucket. The Java HashMap class uses a default load factor of 0.75 and starts with 16 buckets. Once it holds more than 12 entries, it doubles the table. Other designs choose their own threshold, because a lower one uses more memory and a higher one makes lookups slower. ## An everyday picture Think of a row of 100 coat hooks at a party. The load factor is the number of coats divided by the number of hooks. With 80 coats on 100 hooks, each hook holds less than one coat on average. Hang far more coats per hook and each hook becomes a tall stack, so finding one coat takes longer. Then you add more hooks. ## Worked example: A table with 80 keys A hash table has $m = 100$ buckets and stores $n = 80$ keys. It resizes when the load factor passes 0.75. We find the load factor now, and then the load factor after the table doubles. 1. Load factor now: $\alpha = \frac{80}{100} = 0.8$. That is above 0.75, so the table must resize. 2. Average chain length with chaining: about 0.8 keys per bucket. An unsuccessful lookup checks about 0.8 keys on average. 3. Double the buckets to $m = 200$. The load factor becomes $\alpha = \frac{80}{200} = 0.4$. **Answer:** The load factor is **0.8**, which passes the 0.75 threshold, so the table doubles to 200 buckets. The load factor then drops to **0.4**, and a lookup checks about 0.4 keys on average. ## Common mistakes - Swapping the two counts. The load factor is keys divided by buckets, so $n/m$ and $m/n$ mean different things. - Thinking a load factor above 1 is an error. With chaining, $\alpha$ can go above 1. The lists get longer, and lookups slow down. - Expecting no collisions at a low load factor. Even at $\alpha = 0.5$, some buckets get two keys, because a hash function scatters keys at random. - Forgetting to resize. Without resizing, the lists keep growing and every lookup gets slower. ## Where you will meet it - The HashMap class in Java, which resizes when the load factor passes a set threshold. - Symbol tables in compilers and interpreters, where lookups must stay fast as the number of names grows. - In-memory key-value stores, which balance memory use against lookup speed by choosing a load factor. - Choosing the starting size of a map before loading a large batch of data, so the table does not resize many times. ## Questions people ask ### Can the load factor be greater than 1? With chaining, yes. $\alpha = 2$ means two keys per bucket on average, and the lists are twice as long. With open addressing, where each key takes its own slot, $\alpha$ can never go above 1. ### What is a good load factor? It depends on the design. Java's 0.75 is a common choice for chained tables. A lower value makes lookups faster but uses more memory. ### Why does resizing double the table? Doubling cuts the load factor in half in one step. Moving every key costs time, but doubling means the table is rebuilt only rarely, so that cost averages out over many inserts. ## Related formulas - [Birthday Problem](https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem/) - [Pigeonhole Principle](https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle/) - [Bloom Filter False Positive Rate](https://formulabro.yunusemrevurgun.com/computer-science/bloom-filter-false-positive-rate/) ## Sources - [Hash table, Wikipedia](https://en.wikipedia.org/wiki/Hash_table) - [HashMap (Java SE 21 documentation)](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/HashMap.html) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Birthday Problem > The birthday problem asks how likely it is that some pair of items in a random group matches, and the answer rises faster than most people expect. Page: https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P(\text{no collision}) = \prod_{k=0}^{n-1}\left(1 - \frac{k}{N}\right) \approx e^{-n(n-1)/(2N)} $$ Read it out loud: "The chance of no collision equals the product, for k from 0 to n minus 1, of one minus k over N. That is roughly e to the power of minus n times n minus 1, over 2 N." ## What each symbol means - $P(\text{no collision})$: The probability that every item gets a different value, so no two match. It is a number from 0 to 1. For birthdays, a collision is a shared birthday. - $n$: The number of items drawn at random, such as the number of people in a room. - $N$: The number of equally likely values, such as 365 birthdays in a year, or $2^{32}$ possible 32-bit hash values. - $k$: The counter in the product, running from 0 to $n-1$. The factor $1 - \frac{k}{N}$ is the chance that the next item avoids the $k$ values already taken. - $\prod$: Multiply together the factors for every $k$ from 0 to $n-1$. - $e$: Euler's number, about 2.718, the base of the natural logarithm. ## What the formula is doing Draw $n$ items at random, each from one of $N$ equally likely values. The birthday problem asks for the chance that no two of them match. With 365 days in a year, a group of only 23 people already has better than even odds of a shared birthday, which surprises most people. Build the answer one item at a time. The first item cannot clash with anything, so its factor is 1. The second item must avoid one taken value, which has chance $1 - \frac{1}{N}$. The third must avoid two values, with chance $1 - \frac{2}{N}$. The $k$th factor is $1 - \frac{k}{N}$, and multiplying all the factors gives the chance that every item is different. Multiplying many numbers close to 1 by hand is slow. Each factor is close to $e^{-k/N}$, and the sum of $k$ from 0 to $n-1$ is $\frac{n(n-1)}{2}$. That gives the shortcut $P \approx e^{-n(n-1)/(2N)}$, which is accurate when $n$ is small compared with $N$. The chance of at least one match is $1 - P(\text{no collision})$. For 23 people and 365 days, the exact value is about 50.7%, and the shortcut gives about 50.0%, which is close but not exact. The number of items needed grows with the square root of $N$, not with $N$ itself, so collisions come much sooner than intuition suggests. ## An everyday picture Think of guests at a party who each pick a random day of the year as their birthday. The first guest's day cannot match anyone yet. Each new guest has one more day already taken, so the chance of avoiding all of them shrinks. The number of pairs grows much faster than the number of guests, and each pair is another chance for a match. ## Worked example: A shared birthday in a group of 23 A group of $n = 23$ people is picked at random. Each birthday is one of $N = 365$ equally likely days, and leap years are ignored. What is the chance that at least two people share a birthday? 1. Chance that no two share a birthday: $P(\text{no collision}) = \prod_{k=0}^{22}\left(1 - \frac{k}{365}\right) \approx 0.4927$. 2. Chance of at least one shared birthday: $1 - 0.4927 = 0.5073$, which is about **50.7%**. 3. Shortcut: $e^{-23 \cdot 22 / (2 \cdot 365)} = e^{-0.6932} \approx 0.5000$, which gives 50.0%. That is close to the exact value. **Answer:** With only **23 people**, the chance of a shared birthday is about **50.7%**, which is more than even odds. With 50 people the chance rises to about 97%. ## Common mistakes - Confusing a shared birthday with a match for one person. For a fixed person, a match with any of 22 others is about 6%. A 50% chance that someone shares *your* birthday needs about 253 other people. - Forgetting to subtract from 1. The product gives the chance of no match. The chance of a match is one minus that number. - Using the shortcut for very large $n$ without checking. It is close when $n$ is small compared with $N$; the exact product is safer. ## Where you will meet it - Estimating how many random hash values can be stored before a collision is likely. A 32-bit hash needs about 77,000 random keys before a collision reaches roughly a 50% chance. - Checking the risk of duplicate IDs when random identifiers are generated, such as random 64-bit or 128-bit IDs. - Cryptography, where a birthday attack finds two inputs with the same hash value faster than trying every possible input. - Teaching probability, as a classic case where intuition about chance fails. ## Questions people ask ### How many people give a better than even chance of a shared birthday? 23 is the smallest group where the chance passes one half. With 22 people the chance is about 47.6%, and with 23 it is about 50.7%. ### What does N mean for hash collisions? $N$ is the number of possible hash values. For a 32-bit hash, $N = 2^{32}$, and about 77,000 random keys give roughly a 50% chance of a collision. ### Does the formula assume people are random? It assumes each birthday is equally likely and independent of the others. Real birthdays are not perfectly even across the year, and uneven spreads make matches a little more likely. ## Related formulas - [Pigeonhole Principle](https://formulabro.yunusemrevurgun.com/computer-science/pigeonhole-principle/) - [Hash Table Load Factor](https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor/) - [Bloom Filter False Positive Rate](https://formulabro.yunusemrevurgun.com/computer-science/bloom-filter-false-positive-rate/) ## Sources - [Birthday problem, Wikipedia](https://en.wikipedia.org/wiki/Birthday_problem) - [Birthday attack, Wikipedia](https://en.wikipedia.org/wiki/Birthday_attack) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bloom Filter False Positive Rate > The false positive rate of a Bloom filter is the chance that it wrongly says an item is present, and it depends on the bits, the items and the hash functions. Page: https://formulabro.yunusemrevurgun.com/computer-science/bloom-filter-false-positive-rate/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ p \approx \left(1 - e^{-kn/m}\right)^{k} $$ Read it out loud: "p is about one minus e to the power of minus k n over m, all raised to the power k. The best number of hash functions is m over n times the natural log of 2." ## What each symbol means - $p$: The **false positive rate**: the chance that the filter says an item is present when it was never added. It is a number from 0 to 1. - $m$: The number of bits in the filter's bit array. - $n$: The number of items added to the filter. - $k$: The number of hash functions. Each added item sets $k$ bits in the array. - $e$: Euler's number, about 2.718. - $\ln 2$: The natural logarithm of 2, about 0.693. It sets the best number of hash functions, $k = \frac{m}{n}\ln 2$. ## What the formula is doing A Bloom filter is an array of $m$ bits, all starting at 0. To add an item, run it through $k$ different hash functions and set those $k$ bits to 1. To test an item, check its $k$ bits. If any bit is 0, the item was definitely never added. If all $k$ bits are 1, the item is probably present, but other items may have set those same bits by chance. The filter never misses an item it was given, so it has no false negatives. Its only mistake is a false positive: an item that was never added whose $k$ bits all happen to be 1. The formula gives the chance of that mistake. After $n$ items are added, a given bit is still 0 only if every bit-setting operation missed it. Each one misses with chance $1 - \frac{1}{m}$, so after $kn$ operations the chance of missing is about $e^{-kn/m}$ for large $m$. That means about $1 - e^{-kn/m}$ of the bits are 1. A new item is a false positive when all of its $k$ bits land on 1s, which has chance about $\left(1 - e^{-kn/m}\right)^{k}$. More bits per item lower the rate. The number of hash functions matters too: too few leave the test weak, and too many fill the array quickly. The rate is smallest when $k = \frac{m}{n}\ln 2$, which is about 0.69 times the number of bits per item. At that best $k$, about half the bits are 1, and the rate is about $\left(\frac{1}{2}\right)^{k}$. ## An everyday picture Think of a wall of 10,000 tiny lights. Each guest turns on a few lights chosen by their name. To check whether a guest came, look at their lights. If any light is off, that guest certainly did not come. If all of them are on, the guest probably came, but other guests may have turned on the same lights by chance. ## Worked example: A filter with 10,000 bits and 1,000 items A Bloom filter has $m = 10000$ bits and holds $n = 1000$ items. The best number of hash functions is $k = \frac{m}{n}\ln 2$, rounded to a whole number. We find $k$ and then the false positive rate $p$. 1. Best number of hash functions: $\frac{10000}{1000} \cdot \ln 2 = 10 \cdot 0.6931 \approx 6.93$. Rounded to a whole number, $k = 7$. 2. Fraction of bits set to 1 with $k = 7$: $1 - e^{-7 \cdot 1000 / 10000} = 1 - e^{-0.7} \approx 1 - 0.4966 = 0.5034$. 3. False positive rate: $p \approx (0.5034)^{7} \approx 0.00819$, which is about 0.82%. **Answer:** With 7 hash functions, about **0.82%** of items that were never added are reported as present. That is about 1 false alarm in every 122 checks. ## Common mistakes - Expecting zero false positives. The filter can say yes for an item that was never added. Only a no answer is guaranteed to be right. - Using too many hash functions. Each extra hash function sets more bits and fills the array faster, which raises the rate once you pass the best value. - Sizing the filter for fewer items than you add. The rate climbs quickly when more items go in than planned. With 5,000 items in the same 10,000 bits and $k = 7$, the rate rises to about 81%. ## Where you will meet it - Databases such as Cassandra, which keep a Bloom filter for each data file (an SSTable) so they can skip reading files that cannot hold the key. - Caches that check a filter first, so a request for a missing key is answered without a slow lookup. - Web crawlers that remember which pages they have already visited, using a small filter to skip most repeats. - Teaching the trade-off between memory and accuracy, since a Bloom filter gives up exact answers for a much smaller size. ## Questions people ask ### Why can a Bloom filter say yes when the answer is no? Different items can set the same bits. If all the bits an item checks were set by other items, the filter cannot tell that item apart from a real match, so it reports a false positive. ### Can a Bloom filter delete an item? A standard Bloom filter cannot. Clearing a bit could also erase a record for another item. A counting Bloom filter, a variant that keeps a count in each slot, does allow deletion. ### How many bits do I need per item? Pick the false positive rate you can accept, then solve for the size. At the best $k$, the bits per item are $\frac{m}{n} = \frac{-\ln p}{(\ln 2)^2}$. A rate of 1% needs about 9.6 bits per item. ## Related formulas - [Hash Table Load Factor](https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor/) - [Birthday Problem](https://formulabro.yunusemrevurgun.com/computer-science/birthday-problem/) - [Modulo Operation](https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation/) ## Sources - [Bloom filter, Wikipedia](https://en.wikipedia.org/wiki/Bloom_filter) - [Hash table, Wikipedia](https://en.wikipedia.org/wiki/Hash_table) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Modulo Operation > The modulo operation gives the leftover amount after you divide one whole number by another as many full times as you can. Page: https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ a \bmod n = a - n \left\lfloor \frac{a}{n} \right\rfloor $$ Read it out loud: "a mod n equals a minus n times the floor of a over n. The floor means rounding down to the nearest whole number." ## What each symbol means - $a \bmod n$: The **modulo**: the remainder after dividing $a$ by $n$. It has no unit. For a positive $n$, it is always between 0 and $n-1$. - $a$: The number being divided. It can be negative. - $n$: The divisor, a positive whole number. - $\left\lfloor x \right\rfloor$: The **floor** of $x$: the largest whole number less than or equal to $x$. The floor of $-2.33$ is $-3$. ## What the formula is doing The modulo operation gives the remainder after division. Divide $a$ by $n$, keep the whole number of full groups, and look at what is left over. Seventeen cookies packed into bags of five make 3 full bags with 2 cookies left over, so $17 \bmod 5 = 2$. The formula makes the rule exact: $a \bmod n = a - n \left\lfloor \frac{a}{n} \right\rfloor$. The floor $\lfloor x \rfloor$ rounds $x$ down to a whole number. The number of full groups is $\lfloor a/n \rfloor$, and the remainder is what is left after taking $n$ away for each of those groups. For a positive $n$, the answer always lands from 0 up to $n-1$. Negative numbers show where languages differ. Take $-7 \bmod 3$. The quotient $\frac{-7}{3} \approx -2.33$ rounds down to $-3$, so the answer is $-7 - 3 \cdot (-3) = 2$. Python uses this rule. C, C++ and Java use truncation toward zero instead, which gives $-1$ for the same expression. Check which rule your language uses. The modulo operation appears wherever a count wraps around, such as clocks, weekdays and array indexes. It is also a key step in hashing and in cryptography, where a huge number is reduced to a small range. ## An everyday picture Think of a clock with 12 hours. If it is 10 o'clock and you wait 5 hours, the clock shows 3, not 15. The hour wraps back around after each full lap of 12. The modulo is the number left after removing those full laps, so adding 5 hours is the same as adding 5 mod 12. ## Worked example: Days of the week and negative remainders Monday is day 0, Tuesday is day 1, and so on up to Sunday, which is day 6. We want the weekday 40 days after a Monday. We also check $-7 \bmod 3$ to see how negative numbers behave. 1. Divide 40 by 7 and round down: $\left\lfloor \frac{40}{7} \right\rfloor = 5$, since $\frac{40}{7} \approx 5.71$. 2. Find the remainder: $40 \bmod 7 = 40 - 7 \cdot 5 = 5$. 3. Count 5 days after Monday, which is day 0: Tuesday is 1, Wednesday 2, Thursday 3, Friday 4 and Saturday 5. So the answer is Saturday. 4. Negative case with $n = 3$: $-7 \bmod 3 = -7 - 3 \cdot \left\lfloor \frac{-7}{3} \right\rfloor = -7 - 3 \cdot (-3) = 2$. **Answer:** 40 days after a Monday is a **Saturday**, since $40 \bmod 7 = 5$. With the floored rule, $-7 \bmod 3 = 2$, which lies between 0 and 2 as the rule promises. ## Common mistakes - Expecting a negative answer for negative numbers in every language. Python gives $-7 \bmod 3 = 2$, but C and Java give $-1$ for the same expression. - Confusing the quotient with the remainder. $\frac{40}{7} \approx 5.71$ is the quotient. The modulo is what remains after the whole groups are removed. - Using truncation for negative numbers. Rounding toward zero and rounding down agree for positive numbers, but they give different answers for negative ones. ## Where you will meet it - Clocks and calendars, where hours and weekdays wrap around after each full cycle. - Hash tables, where a hash value is turned into a bucket number with $h \bmod m$. - Checking whether a whole number is even: $a \bmod 2 = 0$ means $a$ is even. - Cryptography such as RSA, where arithmetic is done modulo a large number $n$. ## Questions people ask ### What is the difference between mod and remainder? For positive numbers they match. For negative numbers the floored modulo always lands between 0 and $n-1$, while a truncated remainder can be negative, as in C and Java. ### What is $a \bmod n$ when $a$ is a multiple of $n$? It is 0. Then $\frac{a}{n}$ is a whole number, and subtracting $n$ times that number leaves nothing. ### Why does the formula need a floor? The floor rounds the quotient down, and that choice decides what happens with negative numbers. The floor of $-2.33$ is $-3$, which makes the remainder come out as 2. ## Related formulas - [Euclidean Algorithm](https://formulabro.yunusemrevurgun.com/computer-science/euclidean-algorithm-gcd/) - [Hash Table Load Factor](https://formulabro.yunusemrevurgun.com/computer-science/hash-table-load-factor/) - [RSA Encryption](https://formulabro.yunusemrevurgun.com/computer-science/rsa-encryption/) ## Sources - [Modulo, Wikipedia](https://en.wikipedia.org/wiki/Modulo) - [Floor and ceiling functions, Wikipedia](https://en.wikipedia.org/wiki/Floor_and_ceiling_functions) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Euclidean Algorithm > The Euclidean algorithm finds the largest number that divides two numbers evenly, by replacing the pair with a smaller pair again and again. Page: https://formulabro.yunusemrevurgun.com/computer-science/euclidean-algorithm-gcd/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \gcd(a, b) = \gcd(b,\ a \bmod b), \qquad \gcd(a, 0) = a $$ Read it out loud: "The greatest common divisor of a and b equals the greatest common divisor of b and a mod b. The greatest common divisor of a and zero is a." ## What each symbol means - $\gcd(a, b)$: The **greatest common divisor**: the largest whole number that divides both $a$ and $b$ with no remainder. It has no unit. - $a$: A whole number, 0 or more. It is the first number in the pair. - $b$: A whole number, 0 or more. The rule replaces the pair $(a, b)$ with the smaller pair $(b, a \bmod b)$. - $a \bmod b$: The remainder when $a$ is divided by $b$. It is always less than $b$, which is why the numbers keep shrinking. ## What the formula is doing The greatest common divisor, or GCD, of two whole numbers is the largest number that divides both of them with no remainder. The Euclidean algorithm finds it without listing every divisor. It replaces the pair $(a, b)$ with the pair $(b, a \bmod b)$, which has the same GCD, and repeats until the remainder is 0. Why does the GCD stay the same? Any number that divides both $a$ and $b$ also divides $a - qb$ for any whole number $q$. The remainder $a \bmod b$ has this form, with $q$ equal to the number of full copies of $b$ in $a$. So the common divisors of $a$ and $b$ are exactly the common divisors of $b$ and $a \bmod b$, and the largest one is the same. The numbers shrink at each step, because a remainder is always smaller than the divisor. When the remainder reaches 0, the last nonzero number is the answer, since $\gcd(a, 0) = a$. Euclid described this method in Book VII of his *Elements*, written around 300 BC. The method is fast. The number of division steps is at most about five times the number of digits in the smaller number, so two 100-digit numbers need at most about 500 steps. Listing every divisor of a 100-digit number would take far longer. ## An everyday picture Imagine two paper strips, 48 cm and 18 cm long. Cut as many 18 cm pieces as you can from the long strip, and 12 cm is left over. Now the strips are 18 cm and 12 cm. Cut 12 cm from the 18 cm strip, and 6 cm is left. The 6 cm piece fits into the 12 cm strip exactly twice, so 6 cm is the longest piece that measures both strips evenly. ## Worked example: GCD of 48 and 18 We want the greatest common divisor of $a = 48$ and $b = 18$. The algorithm repeats the rule until the remainder is 0. 1. Divide 48 by 18: $48 = 2 \cdot 18 + 12$, so $48 \bmod 18 = 12$. Then $\gcd(48, 18) = \gcd(18, 12)$. 2. Divide 18 by 12: $18 = 1 \cdot 12 + 6$, so $18 \bmod 12 = 6$. Then $\gcd(18, 12) = \gcd(12, 6)$. 3. Divide 12 by 6: $12 = 2 \cdot 6 + 0$, so $12 \bmod 6 = 0$. Then $\gcd(12, 6) = \gcd(6, 0)$. 4. Use $\gcd(a, 0) = a$: $\gcd(6, 0) = 6$. **Answer:** The greatest common divisor of 48 and 18 is **6**. The algorithm needed 3 division steps, and it never listed a single divisor. ## Common mistakes - Stopping at the wrong number. The answer is the last nonzero remainder, which is 6 here. The 12 is a remainder too early, and the 0 is never the answer. - Confusing the GCD with the least common multiple. The GCD of 48 and 18 is 6, while their least common multiple is 144. - Testing every number up to the smaller one. That works for small numbers, but it is far slower than the Euclidean algorithm when the numbers have many digits. ## Where you will meet it - Simplifying fractions: dividing the top and bottom of $\frac{48}{18}$ by their GCD, 6, gives $\frac{8}{3}$. - RSA encryption, which checks that the public exponent shares no factor with $\varphi(n)$ by computing a GCD. - Finding modular inverses with the extended Euclidean algorithm, which cryptography uses to build private keys. - Computer algebra and number libraries, which reduce fractions with very large numerators and denominators. ## Questions people ask ### Why does the algorithm stop when the remainder is 0? When the remainder is 0, the last divisor divides the number before it with nothing left over. That divisor is the largest common divisor, and $\gcd(a, 0) = a$ records that final step. ### What is the GCD of 0 and 0? Every number divides 0, so there is no largest common divisor to pick. By convention the GCD of 0 and 0 is defined as 0. ### Is the algorithm fast for huge numbers? Yes. The number of steps grows with the number of digits, not with the size of the numbers. Even 100-digit numbers need at most about 500 division steps. ## Related formulas - [Modulo Operation](https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation/) - [RSA Encryption](https://formulabro.yunusemrevurgun.com/computer-science/rsa-encryption/) ## Sources - [Euclidean algorithm, Wikipedia](https://en.wikipedia.org/wiki/Euclidean_algorithm) - [Euclid's Elements, Wikipedia](https://en.wikipedia.org/wiki/Euclid%27s_Elements) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # RSA Encryption > RSA lets anyone lock a message with a public key while only the owner can unlock it with a private key, because undoing a product of two secret primes is very hard. Page: https://formulabro.yunusemrevurgun.com/computer-science/rsa-encryption/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ c = m^{e} \bmod n, \qquad m = c^{d} \bmod n $$ Read it out loud: "c equals m to the power e, mod n. To decrypt, m equals c to the power d, mod n. Here n is p times q, and e times d is one more than a multiple of phi of n." ## What each symbol means - $c$: The **ciphertext**, the scrambled whole number that is sent. It is between 0 and $n-1$. - $m$: The **message**, written as a whole number between 0 and $n-1$. Text must be turned into numbers before it is encrypted. - $e$: The **public exponent**, shared with everyone. Real systems often use 65537, and the toy example below uses 17. - $d$: The **private exponent**, kept secret. It is the inverse of $e$ modulo $\varphi(n)$. - $n$: The **modulus**, the product $n = pq$ of two secret primes. The public key is the pair $(n, e)$. - $\bmod n$: Take the remainder after dividing by $n$. Every power in RSA is reduced mod $n$. - $p, q$: Two different secret prime numbers. Their product is $n$. - $\varphi(n)$: **Euler's totient** of $n$. For $n = pq$ with primes $p$ and $q$, it equals $(p-1)(q-1)$. ## What the formula is doing RSA is a public-key method. Each person has a **public key**, which anyone may use to encrypt a message, and a **private key**, which only the owner keeps. The public key is the pair $(n, e)$, and the private key is the pair $(n, d)$. A message is a whole number $m$ smaller than $n$. Encryption turns it into $c = m^{e} \bmod n$, and the result $c$ is sent. Decryption reverses the scrambling with $m = c^{d} \bmod n$. This works because of how the numbers were chosen. The modulus $n = pq$ comes from two secret primes. The exponents satisfy $ed \equiv 1 \pmod{\varphi(n)}$, where $\varphi(n) = (p-1)(q-1)$. So $ed$ is one more than a multiple of $\varphi(n)$. Raising $m$ to the power $ed$ and reducing mod $n$ gives back $m$, by Euler's theorem. The security comes from one hard step. If someone can split $n$ back into $p$ and $q$, they can compute $\varphi(n)$ and then $d$. Multiplying two primes is easy, but factoring a large product into its primes is very hard for ordinary computers. Real keys use primes of hundreds of digits. The toy numbers below are far too small to protect anything. Powers like $65^{17}$ are much too large to compute in full. Software reduces mod $n$ at every multiplication, so the numbers stay small. This method is called modular exponentiation. ## An everyday picture Think of a padlock that anyone can snap shut, but only the owner can open. Anyone can close the lock, which is the public part. The owner alone knows the secret combination, which is the private key. The math behind the lock is multiplying two secret primes, which is easy to do but very hard to undo. ## Worked example: Toy RSA with p = 61 and q = 53 Use two small primes, $p = 61$ and $q = 53$. The public key is $(n, e) = (3233, 17)$ and the private exponent is $d = 2753$. Encrypt the message $m = 65$ and then decrypt the result. 1. Modulus and totient: $n = pq = 61 \cdot 53 = 3233$ and $\varphi(n) = (61 - 1)(53 - 1) = 60 \cdot 52 = 3120$. 2. Check the exponents: $e \cdot d = 17 \cdot 2753 = 46801$, and $46801 = 15 \cdot 3120 + 1$. So $ed \equiv 1 \pmod{3120}$. 3. Encrypt: $c = 65^{17} \bmod 3233 = 2790$. The computer reduces mod 3233 along the way, so the huge power is never written out in full. 4. Decrypt: $m = 2790^{2753} \bmod 3233 = 65$, which is the original message. **Answer:** The ciphertext is **2790**. Decrypting it with $d = 2753$ returns the original message **65**. These numbers are tiny, so anyone who can factor 3233 can break this key, which is why real keys are far larger. ## Common mistakes - Using the same exponent for both directions. Encryption uses $e$ and decryption uses $d$. Swapping them returns a different number, not the message. - Using toy primes in real life. With $n = 3233$, trial division finds the factors 61 and 53 in moments, so the key gives no secrecy. Real keys need far larger primes. - Computing $65^{17}$ in full before reducing mod $n$. That number has 31 digits. Reduce mod $n$ at each step instead. - Using $n - 1$ for $\varphi(n)$. For $n = pq$, $\varphi(n) = (p-1)(q-1)$, which is 3120 here, not 3232. ## Where you will meet it - Digital certificates and signatures, which prove that a website or file came from who it claims. - Secure email and file-signing tools, which often use RSA keys. - Older secure connection setups, where RSA protects a shared session key while it is sent. - Teaching public-key cryptography, since RSA is the classic first example and its steps are ordinary arithmetic. ## Questions people ask ### Why is it called public-key encryption? The encryption key $(n, e)$ can be shared openly. Anyone can encrypt with it, but only the holder of the secret exponent $d$ can decrypt. ### Why does RSA need two primes? Its security rests on $n = pq$ being hard to factor. If you know $p$ and $q$, you can compute $\varphi(n)$ and $d$. Two large random primes keep that secret out of reach. ### How big are real RSA keys? A common size is 2048 bits. That makes $n$ about 617 decimal digits long, and each of its two primes about 309 digits long. ## Related formulas - [Modulo Operation](https://formulabro.yunusemrevurgun.com/computer-science/modulo-operation/) - [Euclidean Algorithm](https://formulabro.yunusemrevurgun.com/computer-science/euclidean-algorithm-gcd/) - [Password Entropy](https://formulabro.yunusemrevurgun.com/computer-science/password-entropy/) ## Sources - [RSA cryptosystem, Wikipedia](https://en.wikipedia.org/wiki/RSA_cryptosystem) - [Euler's totient function, Wikipedia](https://en.wikipedia.org/wiki/Euler%27s_totient_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Hamming Distance > Hamming distance counts how many positions two equal-length codes differ in, and that count tells you how many errors a code can catch. Page: https://formulabro.yunusemrevurgun.com/computer-science/hamming-distance/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ d(x, y) = \sum_{i=1}^{n} [x_i \ne y_i] $$ Read it out loud: "d of x, y equals the sum, for i from 1 to n, of one if x sub i is not equal to y sub i, and zero if they are equal." ## What each symbol means - $d(x, y)$: The Hamming distance between the strings $x$ and $y$: the number of positions where they differ. It has no unit. - $x$: The first string, a list of $n$ symbols such as bits (0 or 1). - $y$: The second string. It must have the same length as $x$. - $n$: The length of both strings, which is the number of positions compared. - $i$: The position being checked, counted from 1 to $n$. - $x_i$: The symbol in position $i$ of $x$, such as the bit 0 or 1. - $y_i$: The symbol in position $i$ of $y$. - $[x_i \ne y_i]$: The Iverson bracket. It is 1 when the two symbols differ and 0 when they match. - $\sum_{i=1}^{n}$: Add up the values for every position from 1 to $n$. ## What the formula is doing Hamming distance answers a simple question: how many positions do two strings differ in? The strings must be the same length, such as two 7-bit binary words. You line them up position by position and count each place where the symbols do not match. The formula does exactly that. For each position $i$ from 1 to $n$, the bracket $[x_i \ne y_i]$ gives 1 when the two symbols differ and 0 when they match. Adding up all the 1s gives $d(x, y)$. The result is a whole number from 0 to $n$, with no unit. The distance is 0 only when the two strings are identical, and it is the same in both directions: the distance from $x$ to $y$ equals the distance from $y$ to $x$. Two strings that differ in every position have distance $n$. The distance matters for error correction. When a message is sent, a few bits can flip along the way. If every valid codeword is at least $d$ apart, a code with minimum distance $d$ can detect up to $d - 1$ errors and correct up to $\lfloor (d - 1)/2 \rfloor$ errors. The further apart valid codewords are, the more damage a message can take before it turns into another valid message. ## An everyday picture Imagine two rows of square tiles, each tile showing one letter or bit, laid side by side. Slide one row over the other and count the columns where the tiles show different symbols. That count is the Hamming distance. Two identical rows give 0, and rows that differ in every column give the full row length. ## Worked example: Distance between two 7-bit codewords Compare the binary words $x = 1011101$ and $y = 1001001$. Both have $n = 7$ positions. 1. Line them up position by position: 1 vs 1, 0 vs 0, 1 vs 0, 1 vs 1, 1 vs 0, 0 vs 0, 1 vs 1. 2. Only positions 3 and 5 differ, so $[x_3 \ne y_3] = 1$ and $[x_5 \ne y_5] = 1$, and every other term is 0. 3. Add the terms: $d(x, y) = 0 + 0 + 1 + 0 + 1 + 0 + 0 = 2$. 4. Check with XOR, which gives 1 exactly where the bits differ: $1011101 \oplus 1001001 = 0010100$. That binary value is 20 in decimal and has two 1 bits. **Answer:** The two words differ in **2 positions**, so $d(x, y) = 2$. A code with minimum distance 2 can detect a single flipped bit, but it cannot correct it. ## Common mistakes - Comparing strings of different lengths. Hamming distance is defined only when both strings have the same number of positions. - Counting the 1s in each word instead of comparing position by position. The words 1100 and 0011 both have two 1s, but they differ in all 4 positions, so $d = 4$. - Measuring the difference in value. The binary numbers 1000 and 0111 are only 1 apart as numbers, but they differ in all 4 positions, so $d = 4$. - Saying a code with distance 2 corrects one error. Distance 2 only detects one error. Correction needs a minimum distance of at least 3. ## Where you will meet it - Error-correcting memory, where extra check bits let a computer spot and fix a single flipped bit. - Data transmission and storage, where codes are designed so that valid messages are far apart in Hamming distance. - Comparing aligned DNA or protein sequences of equal length, where each position holds one base or amino acid. - Matching binary fingerprints, such as image hashes, to find near-duplicates by counting the bits that differ. ## Questions people ask ### What is the difference between Hamming distance and Hamming weight? Hamming weight counts the 1s in one string. Hamming distance compares two strings. The distance between $x$ and $y$ equals the weight of $x \oplus y$, which marks the positions where they differ. ### Why is it called a distance? It behaves like a distance. It is zero only when two strings are identical, it is never negative, and the distance from $x$ to $y$ is the same as the distance from $y$ to $x$. ### How many errors can a code with minimum distance 3 correct? One error, because $\lfloor (3 - 1)/2 \rfloor = 1$. The same code detects up to two errors. The Hamming (7,4) code is a well-known example with minimum distance 3. ## Related formulas - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Shannon-Hartley Theorem](https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem/) ## Sources - [Hamming distance, Wikipedia](https://en.wikipedia.org/wiki/Hamming_distance) - [Error detection and correction, Wikipedia](https://en.wikipedia.org/wiki/Error_detection_and_correction) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Password Entropy > Password entropy is a number of bits that measures how many possible passwords a random generator could have produced, and so how hard guessing one is. Page: https://formulabro.yunusemrevurgun.com/computer-science/password-entropy/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ H = L \log_2 N $$ Read it out loud: "H equals L times the base-2 logarithm of N. H is measured in bits." ## What each symbol means - $H$: The password entropy, in **bits**. Each extra bit doubles the number of possible passwords. - $L$: The length of the password: how many characters it has. Every character is chosen at random. - $N$: The number of symbols each character is picked from, such as 62 for lowercase letters, uppercase letters and digits together. - $\log_2$: The base-2 logarithm. It turns a count of choices into a number of bits. ## What the formula is doing Entropy here measures how many different passwords could have been produced. A character picked uniformly at random from $N$ symbols is one of $N$ equally likely results. A password of $L$ such characters has $N^L$ possible values, and the base-2 logarithm turns that count into bits: $\log_2 N^L = L \log_2 N$. Each character adds $\log_2 N$ bits, and the bits add up along the password. Every bit doubles the number of possible passwords, so the more characters or the larger the symbol set, the higher the entropy. The formula holds only when every password is equally likely. That is true when a computer or a set of dice picks each character at random. A password a person invents is not random. People favor words, names, dates and common substitutions such as p@ssw0rd, which guessing tools try first. For a human-chosen password, the real strength is far lower than the formula suggests. Entropy describes the method that made the password, not the password itself. A high number means the password came from a process with that many choices. It does not prove that a particular password is safe, because an attacker who knows the method can count the same possibilities. ## An everyday picture Think of a combination lock with several dials, each with 62 positions. Every extra dial multiplies the number of combinations, so the lock gets harder to open. A random password works the same way, with each random character acting as one more dial. A password built from a familiar phrase is like a lock whose combination is written on the case. ## Worked example: An 8-character random password, then 12 characters Each character is picked at random from $N = 62$ symbols: 26 lowercase letters, 26 uppercase letters and 10 digits. 1. Bits per character: $\log_2 62 \approx 5.954$ bits. 2. Eight characters: $H = 8 \times 5.954 \approx 47.63$ bits. 3. Twelve characters: $H = 12 \times 5.954 \approx 71.45$ bits. **Answer:** An 8-character random password has about **47.6 bits** of entropy. Four more random characters raise it to about **71.45 bits**, because each character adds about 5.95 bits. ## Common mistakes - Using the formula for a password a person chose. Names, dates and common words are guessed far sooner than a random string of the same length. - Counting length without the symbol set. A 12-character random password from 26 lowercase letters has $H = 12 \log_2 26 \approx 56.4$ bits, much less than the 71.45 bits of 12 characters from 62 symbols. - Using the natural logarithm, $\ln$, instead of $\log_2$. The answer is in bits only with base 2. - Assuming a password is strong because it has many symbol types. Predictable substitutions, such as replacing a with @, add little, because attackers try them too. ## Where you will meet it - Random password generators, which pick characters uniformly so that the formula's assumption holds. - Passphrase generators built on word lists, such as the diceware list of 7776 words. - Security policies that set a minimum password length or require a larger set of character types. - Cryptography, where keys and secrets must come from a random source with enough entropy. ## Questions people ask ### Is a long password always strong? Not always. Length helps when the characters are random. A long password built from a familiar phrase or pattern has far fewer real possibilities than the formula suggests. ### Why use base 2 for the logarithm? Computers store information in bits, and each bit doubles the number of possibilities. Base 2 gives the answer directly as a number of bits. ### Does this formula tell me how long guessing will take? Not directly. It counts possibilities. The time to guess depends on how fast an attacker can test each one and on whether the attack tries the most likely candidates first. ## Related formulas - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Hamming Distance](https://formulabro.yunusemrevurgun.com/computer-science/hamming-distance/) ## Sources - [Password strength, Wikipedia](https://en.wikipedia.org/wiki/Password_strength) - [Entropy (information theory), Wikipedia](https://en.wikipedia.org/wiki/Entropy_(information_theory)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Data Transfer Time > Data transfer time tells you how long a file takes to send: divide its size by the link's speed, using units that match. Page: https://formulabro.yunusemrevurgun.com/computer-science/data-transfer-time/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ t = \frac{S}{B} $$ Read it out loud: "t equals S divided by B. The time in seconds is the size of the data divided by the bandwidth, using matching units." ## What each symbol means - $t$: The transfer time, in **seconds**. - $S$: The size of the data, in **bits** or bytes. Use bits when $B$ is in bits per second. - $B$: The bandwidth: the rate the link can carry, in **bits per second**. Network speeds such as 100 Mbps are given in bits per second. ## What the formula is doing Transfer time answers one practical question: how long will it take to send a file? You divide the amount of data by the rate at which the link moves it. The result is in seconds only when the units match, such as bits divided by bits per second. The formula $t = \frac{S}{B}$ shows two simple effects. Doubling the bandwidth halves the time, and doubling the file size doubles it. Bandwidth is the rate the link can carry, not a speed every transfer reaches, so a real transfer often runs slower. Bits and bytes cause most of the mistakes. A byte is 8 bits, so 1 MB (megabyte) equals 8 Mb (megabits). File sizes are usually given in bytes, while network speeds are given in bits per second. Multiply the size in megabytes by 8 to get megabits before dividing by a speed in megabits per second. The formula leaves out latency, the delay before the first bit arrives. A fuller estimate is $t_{\text{total}} \approx \text{latency} + \frac{S}{B}$. For one large file, latency is a small part of the total. For many small files, each one pays the delay, and latency can take up most of the time. ## An everyday picture Think of filling a bathtub from a tap. The amount of water is the file size, and the tap's flow rate is the bandwidth. A bigger tub at the same flow takes longer, and a stronger tap fills the same tub sooner. The time to fill is the amount divided by the flow rate. ## Worked example: Downloading a 500 MB file on a 100 Mbps link A 500 MB file is sent over a link that carries 100 megabits per second (100 Mbps). Ignore latency and protocol overhead. 1. Convert the size to bits: $500 \text{ MB} \times 8 = 4000 \text{ Mb}$. 2. Divide by the bandwidth: $t = \frac{4000 \text{ Mb}}{100 \text{ Mb/s}} = 40 \text{ s}$. 3. Mixing units gives $\frac{500}{100} = 5$ s, which is wrong by a factor of 8. A 50 ms latency would add only 0.05 s to the 40 s here. **Answer:** The download takes about **40 seconds**. Dividing 500 MB by 100 Mbps directly would give 5 seconds, which is off by a factor of 8, because the size is in bytes and the speed is in bits. ## Common mistakes - Mixing bits and bytes. Dividing 500 MB by 100 Mbps gives 5 seconds, which is wrong by a factor of 8. Convert the file size to megabits first. - Confusing megabit (Mb) with megabyte (MB). One megabyte is 8 megabits, so a 100 Mbps link moves about 12.5 MB per second at most. - Forgetting latency for many small transfers. A thousand small files each wait for a delay, which can take far longer than the total size suggests. - Treating the advertised bandwidth as the speed you always get. Congestion, Wi-Fi and protocol overhead all lower the real rate. ## Where you will meet it - Estimating how long a software update or video download will take on a home connection. - Planning backups, where a large data set must finish within a fixed time window. - Sizing network links between data centers, and deciding when shipping disks is faster than sending data over the network. - Checking whether a video stream's bit rate fits within a connection's bandwidth. ## Questions people ask ### Why is my download slower than the advertised speed? The advertised figure is the link's rated bandwidth $B$. Congestion, Wi-Fi, server limits and protocol overhead reduce the rate you really get, so the real time is longer than $\frac{S}{B}$. ### How many bits are in a byte? Eight. So 1 MB is 8 megabits, and a speed of 8 Mbps moves about 1 MB per second before overhead. ### Is a megabyte 1,000,000 bytes or 1,048,576 bytes? In storage and network speeds, 1 MB is usually 1,000,000 bytes. The binary unit, 1 MiB, is 1,048,576 bytes. Some operating systems display sizes in binary units under the name MB, so the numbers can differ. ## Related formulas - [Bandwidth-Delay Product](https://formulabro.yunusemrevurgun.com/computer-science/bandwidth-delay-product/) - [Shannon-Hartley Theorem](https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem/) - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) ## Sources - [Bit rate, Wikipedia](https://en.wikipedia.org/wiki/Bit_rate) - [Byte, Wikipedia](https://en.wikipedia.org/wiki/Byte) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bandwidth-Delay Product > The bandwidth-delay product tells you how much data must be in transit at once to keep a network link full. Page: https://formulabro.yunusemrevurgun.com/computer-science/bandwidth-delay-product/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{BDP} = B \times \text{RTT} $$ Read it out loud: "BDP equals B times RTT. The result is the amount of data that fills the link, in bits, or in bytes after dividing by eight." ## What each symbol means - $\text{BDP}$: The bandwidth-delay product: the amount of data that can be in transit on the link at one time. Measure it in **bits**, or in **bytes** after dividing by 8. - $B$: The bandwidth, the link's rate, in **bits per second**. - $\text{RTT}$: The round-trip time, in **seconds**: the time for a message to reach the other end and a reply to come back. - $\times$: Multiply the rate by the time. ## What the formula is doing The bandwidth-delay product measures how much data can be in flight on a link at once. A sender puts data on the link and then waits for an acknowledgment, which takes a full round trip. During that wait the sender keeps transmitting, so a stretch of data is always travelling toward the receiver. The formula $\text{BDP} = B \times \text{RTT}$ multiplies the rate by the time. A link that carries $B$ bits per second, with a round-trip time of $\text{RTT}$ seconds, holds $B \times \text{RTT}$ bits in flight when it is full. Dividing by 8 gives bytes, which is the unit TCP window sizes use. To keep the link busy, the sender must have at least one BDP of unacknowledged data outstanding. In TCP, that amount is limited by the window. If the window is smaller than the BDP, the sender runs out of data to send and waits for acknowledgments, so throughput falls below the link rate. The product explains why long, fast paths need large windows and buffers. Raising the bandwidth or the round-trip time raises the BDP. A satellite link with a long round-trip time needs a much larger window than a short local link of the same speed. ## An everyday picture Think of a long pipe carrying water. Water flows in at a steady rate and takes time to reach the far end. The water inside the pipe at any moment equals the flow rate times the travel time. The bandwidth-delay product is the same idea for data on a network link. ## Worked example: A 100 Mbps link with a 50 ms round trip A link carries $B = 100$ Mbps, and the round-trip time is 50 ms, which is $\text{RTT} = 0.05$ s. 1. Bits in flight: $\text{BDP} = 100 \times 10^6 \text{ bit/s} \times 0.05 \text{ s} = 5 \times 10^6$ bits. 2. Bytes in flight: $\frac{5 \times 10^6}{8} = 625{,}000$ bytes. 3. Window limit: the TCP window field is 16 bits, so without window scaling the window tops out at 65,535 bytes. Over 0.05 s that allows $\frac{65{,}535 \times 8}{0.05} \approx 10.49 \times 10^6$ bit/s, about 10.49 Mbps, far below the link's 100 Mbps. **Answer:** The link needs about **625,000 bytes** (5 megabits) in flight to stay full. A 65,535-byte window would cap throughput near **10.49 Mbps** on this path, so window scaling is needed to use the full link. ## Common mistakes - Using milliseconds for the round-trip time. The 50 ms must be converted to 0.05 s, or the result is 1000 times too large. - Mixing bits and bytes. Bandwidth is in bits per second, but TCP windows are in bytes. Divide by 8 at the end. - Using the one-way delay. The data must travel out and the acknowledgment must travel back, so the full round-trip time counts. - Assuming a bigger window always helps. Beyond one BDP the link is already full, so extra window only adds queueing delay in the buffers. ## Where you will meet it - Sizing TCP send and receive buffers on fast or long-distance links. - Designing satellite and intercontinental links, where the round-trip time is long. - Tuning file transfer and backup tools, which decide how much data to send before waiting for acknowledgments. - Checking measured throughput against the limit set by window size and round-trip time. ## Questions people ask ### What is RTT? The round-trip time: how long a message takes to reach the other end and a reply to come back. The ping command reports it for a network path. ### Does a bigger window always make a connection faster? Only up to one BDP. Once the window covers the BDP, the link is full, and a larger window does not raise throughput. The link's own rate is then the limit. ### Should the BDP be in bits or bytes? Either, as long as the units match. Bandwidth in bits per second times seconds gives bits. Divide by 8 to get the bytes that TCP buffers and windows are sized in. ## Related formulas - [Data Transfer Time](https://formulabro.yunusemrevurgun.com/computer-science/data-transfer-time/) - [Little's Law](https://formulabro.yunusemrevurgun.com/computer-science/littles-law/) - [Shannon-Hartley Theorem](https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem/) ## Sources - [Bandwidth-delay product, Wikipedia](https://en.wikipedia.org/wiki/Bandwidth-delay_product) - [Transmission Control Protocol, Wikipedia](https://en.wikipedia.org/wiki/Transmission_Control_Protocol) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Nyquist Sampling Theorem > The Nyquist sampling theorem tells you how fast you must sample a signal, at more than twice its highest frequency, to capture it without distortion. Page: https://formulabro.yunusemrevurgun.com/computer-science/nyquist-sampling-theorem/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ f_s > 2 f_{\max} $$ Read it out loud: "f sub s is greater than two times f sub max. The sampling rate must be more than twice the highest frequency in the signal." ## What each symbol means - $f_s$: The sampling rate: how many samples are taken each second, in **hertz** (Hz). - $f_{\max}$: The highest frequency present in the signal, in **hertz**. A 20 kHz tone has $f_{\max} = 20$ kHz. - $2$: A fixed factor. The sampling rate must be more than twice the highest frequency, which gives at least two samples per cycle. ## What the formula is doing Sampling means measuring a signal at regular times, a fixed number of times per second. Between two samples the value of the signal is unknown. The question is how often you must sample so that the wave can be rebuilt from the measurements. The sampling rate $f_s$ is the number of samples per second, in hertz. The theorem says that a signal whose highest frequency is $f_{\max}$ can be recovered exactly from its samples when $f_s > 2 f_{\max}$. Each cycle needs at least two samples, one near a peak and one near a trough, to be captured. If the rule is broken, high frequencies do not vanish. They fold down and appear as a false lower frequency, called aliasing. A 30 kHz tone sampled at 44.1 kHz shows up as a 14.1 kHz tone in the recording. That is why an anti-aliasing filter removes frequencies above half the sampling rate before the signal is sampled. The factor of 2 is a minimum, not a target. Real filters cannot cut off sharply, so practical systems sample a little faster. CD audio uses 44.1 kHz, which leaves room above the roughly 20 kHz upper limit of human hearing. ## An everyday picture Think of a strobe light on a spinning fan. If the flashes come too slowly, the blades seem to move slowly, or even backward. Sampling a sound wave too slowly does the same thing to the wave, so a fast sound looks like a slow one in the recording. ## Worked example: Sampling a 30 kHz tone on a CD at 44.1 kHz Compact disc audio uses a sampling rate of $f_s = 44.1$ kHz. We ask three questions: the highest frequency it can represent, the rate needed for 20 kHz, and what happens to a 30 kHz tone that is not filtered out. 1. Highest frequency that can be represented: $f_{\max} = \frac{f_s}{2} = \frac{44.1}{2} = 22.05$ kHz. 2. Minimum rate for hearing up to 20 kHz: $2 \times 20 = 40$ kHz. Since $44.1 > 40$, the rule holds with room to spare. 3. Alias of a 30 kHz tone: $|30 - 44.1| = 14.1$ kHz. Without filtering, the 30 kHz tone appears in the recording as 14.1 kHz. **Answer:** The sampling rate can represent frequencies up to **22.05 kHz**. A 30 kHz tone above that limit folds down into the audible range as **14.1 kHz**, which is why audio is filtered before it is sampled. ## Common mistakes - Sampling at exactly the highest frequency. For a 20 kHz top frequency, a rate of 20 kHz is not enough, because the rule needs more than twice that. - Applying the rule to the average frequency instead of the highest frequency present in the signal. - Confusing sampling rate with bit depth. The sampling rate sets which frequencies can be captured. Bit depth sets how precisely each sample is measured. - Skipping the anti-aliasing filter. A fast enough sampling rate does not help if the input still contains frequencies above half the rate. ## Where you will meet it - Digital audio, where CD quality uses 44.1 kHz and many studio formats use 48 kHz. - Vibration and condition monitoring, where sensors must sample faster than twice the fastest vibration they need to see. - Software-defined radio and signal processing, where the digitizer's rate limits which frequencies can be captured. - Digital video, where frames are taken at a fixed rate, and that rate limits how fast motion can be captured without distortion. ## Questions people ask ### Why does CD audio use 44.1 kHz and not exactly 40 kHz? Filters that remove frequencies above half the sampling rate cannot cut off sharply. The gap between 20 kHz and 22.05 kHz gives the filter room to roll off, so it can remove the frequencies that would alias without cutting into what people hear. ### Does the theorem apply only to pure sine waves? No. It applies to any signal with a known highest frequency. Real sounds contain many frequencies, and the highest one sets the required sampling rate. ### What happens at exactly twice the highest frequency? The theorem asks for a rate strictly greater than $2 f_{\max}$. At exactly twice, samples of a sine wave can land on its zero crossings and miss its shape, depending on phase, so a margin is needed. ## Related formulas - [Shannon-Hartley Theorem](https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Data Transfer Time](https://formulabro.yunusemrevurgun.com/computer-science/data-transfer-time/) ## Sources - [Nyquist-Shannon sampling theorem, Wikipedia](https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem) - [Aliasing, Wikipedia](https://en.wikipedia.org/wiki/Aliasing) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Shannon-Hartley Theorem > The Shannon-Hartley theorem gives the highest error-free bit rate a noisy channel can carry, from its bandwidth and how strong the signal is compared with the noise. Page: https://formulabro.yunusemrevurgun.com/computer-science/shannon-hartley-theorem/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ C = B \log_2\left(1 + \frac{S}{N}\right) $$ Read it out loud: "C equals B times the base-2 logarithm of one plus S over N. C is the channel capacity in bits per second." ## What each symbol means - $C$: The channel capacity: the highest error-free bit rate the channel can carry, in **bits per second**. - $B$: The bandwidth of the channel, in **hertz** (Hz). - $S$: The average power of the signal, in **watts**. - $N$: The average power of the noise, in **watts**. - $\frac{S}{N}$: The signal-to-noise ratio, a plain number with no unit. Because it is a ratio of powers, 1000 means the signal is 1000 times as strong as the noise. - $\log_2$: The base-2 logarithm. Using base 2 makes the answer count bits. ## What the formula is doing Every communication channel, whether a phone line, a Wi-Fi link or a fiber, can carry only so much information each second. The Shannon-Hartley theorem gives that limit, called the channel capacity $C$, for a channel with bandwidth $B$ and the usual kind of random noise. Bandwidth sets how much room the channel has in frequency. The signal-to-noise ratio $\frac{S}{N}$ sets how clearly the receiver can tell the signal apart from the noise. The logarithm turns that clarity into bits, so the answer is a rate in bits per second. The $1 +$ inside the logarithm keeps the result at zero when the signal is absent. Power ratios are often given in decibels (dB). The conversion is $\text{dB} = 10 \log_{10} \frac{S}{N}$, so $\frac{S}{N} = 10^{\text{dB}/10}$. For example, 30 dB means a power ratio of $10^3 = 1000$. An increase of about 3 dB roughly doubles the power ratio. The result is a limit, not a promise. No coding scheme can send faster than $C$ over that channel with arbitrarily small error. Doubling the bandwidth doubles $C$. Doubling the signal-to-noise ratio adds only about one bit per hertz once the ratio is large. Modern codes come close to this limit. ## An everyday picture Think of a busy city street where you try to be heard. The number of lanes is the bandwidth, and the traffic is the noise. Your message gets through clearly only when it stands out from the traffic. More lanes and a clearer message let more messages reach the other side each second. ## Worked example: A 3 kHz phone line with a 30 dB signal-to-noise ratio A voice channel has bandwidth $B = 3000$ Hz. Its signal-to-noise ratio is 30 dB. 1. Convert decibels to a plain ratio: $\frac{S}{N} = 10^{30/10} = 10^{3} = 1000$. 2. Compute the logarithm: $\log_2(1 + 1000) = \log_2 1001 \approx 9.9672$. 3. Multiply by the bandwidth: $C = 3000 \times 9.9672 \approx 29{,}902$ bits per second. 4. Double the bandwidth to 6000 Hz: $C = 6000 \times 9.9672 \approx 59{,}803$ bits per second. **Answer:** The channel can carry at most about **29.9 kilobits per second**. Doubling the bandwidth doubles that limit to about **59.8 kilobits per second**, if the signal-to-noise ratio stays the same. ## Common mistakes - Putting decibels straight into the formula. Convert first: 30 dB is a power ratio of 1000, not 30. - Mixing up bandwidth and bit rate. $B$ is in hertz, and $C$ is in bits per second. - Treating $C$ as the speed you will get. It is an upper limit for the stated noise model, and real links run below it. - Using a logarithm base other than 2. Base 2 gives the answer in bits. The natural logarithm gives nats, not bits. ## Where you will meet it - Planning DSL, cable and Wi-Fi links, where engineers estimate the best rate a channel can reach. - Designing cellular and satellite links, where bandwidth and received signal strength set the capacity. - Deep-space radio design, where very weak signals make the signal-to-noise ratio the key limit. - Research on error-correcting codes, which try to get as close to this limit as possible. ## Questions people ask ### What is a signal-to-noise ratio? The ratio of signal power $S$ to noise power $N$. A larger ratio means the signal stands out more from the background noise. It has no unit, because both values are powers. ### Why does capacity grow slowly with signal power? The logarithm flattens the curve. When the ratio is large, each tenfold increase in power adds only about 3.3 bits per hertz, so more power brings smaller and smaller gains. ### Can a real modem beat this limit? Not on the same channel with the same noise. Under the stated noise model, no code can send reliably above $C$. Real modems run below the limit because of hardware and channel losses. ## Related formulas - [Nyquist Sampling Theorem](https://formulabro.yunusemrevurgun.com/computer-science/nyquist-sampling-theorem/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) - [Bandwidth-Delay Product](https://formulabro.yunusemrevurgun.com/computer-science/bandwidth-delay-product/) ## Sources - [Shannon-Hartley theorem, Wikipedia](https://en.wikipedia.org/wiki/Shannon%E2%80%93Hartley_theorem) - [Decibel, Wikipedia](https://en.wikipedia.org/wiki/Decibel) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Average Memory Access Time > Average memory access time, or AMAT, is the average time one memory read takes, given how often the cache finds the data and how costly a miss is. Page: https://formulabro.yunusemrevurgun.com/computer-science/average-memory-access-time/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{AMAT} = t_{\text{hit}} + r_{\text{miss}} \times t_{\text{penalty}} $$ Read it out loud: "AMAT equals the hit time plus the miss rate times the miss penalty. Use the same time unit for both times." ## What each symbol means - $\text{AMAT}$: The average time for one memory access, in the same unit as the times below, such as nanoseconds or clock cycles. - $t_{\text{hit}}$: The time to read data that is already in the cache: the hit time. - $r_{\text{miss}}$: The miss rate: the fraction of accesses that are not found in the cache. It is a number from 0 to 1, so 5% is 0.05. - $t_{\text{penalty}}$: The miss penalty: the extra time to fetch the data from the next, slower level of memory after a miss. - $\times$: Multiply the miss rate by the miss penalty. ## What the formula is doing A processor reads memory through a cache, a small and fast store close to the core. A read that finds its data in the cache is a hit, and it takes $t_{\text{hit}}$. A read that does not find it is a miss. The miss must wait for the next, slower level, which adds the miss penalty $t_{\text{penalty}}$ on top of the hit time. Every access pays $t_{\text{hit}}$, because the cache must be checked first. Only the misses also pay the penalty. Multiplying the miss rate by the penalty gives the average extra time per access, and adding the hit time gives the average total. Misses are rare but expensive, so a small change in the miss rate can matter a lot. In the example below, a 5% miss rate adds 5 ns on average, as much as the hit time itself. Halving the miss rate to 2.5% would save 2.5 ns per access. A two-level cache makes the penalty itself an average. Let $t_{L1}$ and $t_{L2}$ be the hit times of the first and second levels, let $r_{L1}$ and $r_{L2}$ be their local miss rates, and let $t_{\text{mem}}$ be the time for main memory. Then $\text{AMAT} = t_{L1} + r_{L1}\left(t_{L2} + r_{L2}\, t_{\text{mem}}\right)$. With $t_{L1} = 1$ ns, $r_{L1} = 0.05$, $t_{L2} = 10$ ns, $r_{L2} = 0.2$ and $t_{\text{mem}} = 100$ ns, this gives $1 + 0.05 \times (10 + 20) = 2.5$ ns. ## An everyday picture Think of a reference desk in a library. Most of the books you need are already on the desk, which is quick. Sometimes you must walk to the back stacks, which is slow. The average time per request is the desk time, plus the share of requests that walk to the stacks, times the walk. ## Worked example: A cache with a 5% miss rate and a 100 ns penalty A cache has a hit time of $t_{\text{hit}} = 1$ ns. Five percent of accesses miss, so $r_{\text{miss}} = 0.05$. A miss costs $t_{\text{penalty}} = 100$ ns to fetch from main memory. 1. Average cost of misses: $r_{\text{miss}} \times t_{\text{penalty}} = 0.05 \times 100 = 5$ ns. 2. Add the hit time: $\text{AMAT} = 1 + 5 = 6$ ns. **Answer:** The average memory access takes **6 ns**, six times the 1 ns hit time. Only 5% of accesses miss, but those misses add 5 ns to the average. ## Common mistakes - Writing the miss rate as a percentage. Use 0.05 for 5%, or the penalty term is 100 times too large. - Leaving out the hit time. The formula adds $t_{\text{hit}}$ to every access, including the ones that hit. - Using the hit rate where the miss rate belongs. A 95% hit rate means a 5% miss rate, and the formula needs the miss rate. - Mixing units, such as nanoseconds for the hit time and clock cycles for the penalty. ## Where you will meet it - Comparing cache sizes and designs in computer architecture, to see whether a bigger cache is worth its cost. - Designing multi-level cache hierarchies in processors. - Tuning software for memory locality, where better access patterns lower the miss rate. - Explaining why a program slows down when its data no longer fits in the cache. ## Questions people ask ### What is a cache miss penalty? The extra time spent waiting for data that is not in the cache. It is measured from the miss until the data arrives from the next, slower level of memory. ### Why does the miss rate multiply the penalty? Only misses pay the penalty, so the average penalty is the fraction of misses times the penalty. If 5% of accesses pay 100 ns, the average extra cost is $0.05 \times 100 = 5$ ns per access. ### Does AMAT tell me the time of each access? No. It is an average over many accesses. Each single access takes either the hit time or the hit time plus the penalty. ## Related formulas - [CPU Time Equation](https://formulabro.yunusemrevurgun.com/computer-science/cpu-time-equation/) - [Amdahl's Law](https://formulabro.yunusemrevurgun.com/computer-science/amdahls-law/) ## Sources - [Cache (computing), Wikipedia](https://en.wikipedia.org/wiki/Cache_(computing)) - [CPU cache, Wikipedia](https://en.wikipedia.org/wiki/CPU_cache) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # CPU Time Equation > The CPU time equation tells you how long a program takes on a processor, from how many instructions it runs, how many cycles each one needs and how fast the clock ticks. Page: https://formulabro.yunusemrevurgun.com/computer-science/cpu-time-equation/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ T_{\text{CPU}} = IC \times CPI \times t_{\text{clock}} = \frac{IC \times CPI}{f} $$ Read it out loud: "T CPU equals I C times C P I times t clock, which is the same as I C times C P I divided by f. The result is in seconds." ## What each symbol means - $T_{\text{CPU}}$: The CPU time: the number of **seconds** the processor spends running the program. - $IC$: The instruction count: how many instructions the program executes. It is a count, with no unit. - $CPI$: Cycles per instruction: the average number of clock cycles one instruction takes in this program. It has no unit. - $t_{\text{clock}}$: The clock period: the length of one clock cycle, in **seconds**. It equals $\frac{1}{f}$. - $f$: The clock frequency, in **hertz** (cycles per second). A 2 GHz clock has $f = 2 \times 10^9$ Hz. ## What the formula is doing The CPU time equation splits the running time of a program into three factors: how many instructions it executes, how many clock cycles each one takes on average, and how long each cycle lasts. It is often called the iron law of processor performance. Multiplying the first two factors gives the total number of cycles, $IC \times CPI$. Each cycle lasts $t_{\text{clock}} = \frac{1}{f}$ seconds, so multiplying the cycle count by $t_{\text{clock}}$ gives the time. Replacing $t_{\text{clock}}$ with $\frac{1}{f}$ gives the second form, $\frac{IC \times CPI}{f}$. Cycles divided by cycles per second leave seconds. Each factor is a lever. A compiler can change $IC$ by producing fewer instructions, and the processor design and the instruction mix change $CPI$. The clock frequency $f$ sets how fast cycles come. The levers can cancel: lowering $CPI$ while cutting the clock rate by the same factor leaves $T_{\text{CPU}}$ unchanged. The equation is an average-based model. The $CPI$ must reflect the real instruction mix and any stalls, such as waiting for memory, so it should come from measuring the actual program. A faster clock alone does not guarantee a faster program. ## An everyday picture Think of printing a stack of pages. The total print time depends on the number of pages, the number of passes each page needs through the press, and how fast the press runs. Total time equals pages times passes, divided by the press speed. The CPU time equation works the same way, with instructions, cycles and clock rate. ## Worked example: A program of 4 billion instructions on a 2 GHz processor A program runs $IC = 4 \times 10^9$ instructions with an average $CPI = 1.2$ on a processor with a clock of $f = 2$ GHz, which is $2 \times 10^9$ cycles per second. 1. Total cycles: $IC \times CPI = 4 \times 10^9 \times 1.2 = 4.8 \times 10^9$ cycles. 2. Clock period: $t_{\text{clock}} = \frac{1}{2 \times 10^9}$ s $= 0.5$ ns. 3. CPU time: $T_{\text{CPU}} = \frac{4.8 \times 10^9}{2 \times 10^9} = 2.4$ s. 4. The same program on a 4 GHz clock: $T_{\text{CPU}} = \frac{4.8 \times 10^9}{4 \times 10^9} = 1.2$ s. **Answer:** The program takes **2.4 seconds** on the 2 GHz processor. Doubling the clock to 4 GHz halves the time to **1.2 seconds**, if the instruction count and CPI stay the same. ## Common mistakes - Multiplying by the clock frequency instead of dividing. Time is cycles divided by frequency, so a faster clock gives less time. - Mixing up IC and CPI. IC is a count of instructions, and CPI is cycles per instruction. Their product is a count of cycles. - Using the clock period and the frequency together. Use either $t_{\text{clock}}$ or $f$, not both, since $t_{\text{clock}} = 1/f$. - Taking CPI from a different program or a spec sheet. CPI depends on the code, so measure it on the real workload. ## Where you will meet it - Comparing processors in benchmarks and reviews, where clock speed and CPI both differ. - Compiler optimization, which tries to cut the instruction count or the cycles per instruction. - Processor design, where features such as pipelining and caches are judged by their effect on CPI. - Explaining why a higher clock rate does not always give a faster program. ## Questions people ask ### What is CPI? Cycles per instruction: the average number of clock cycles one instruction takes in a given program. Modern processors can finish more than one instruction in a cycle, so their CPI can be below 1. The inverse, $1 / \text{CPI}$, is the instructions per cycle (IPC). ### Is a higher clock rate always better? Not on its own. The clock rate matters together with $IC$ and $CPI$. A processor with a higher clock can still be slower if its $CPI$ is much higher. ### Where does the instruction count come from? It depends on the algorithm, the compiler and the input. Profilers and hardware performance counters can measure it for a real run. ## Related formulas - [Amdahl's Law](https://formulabro.yunusemrevurgun.com/computer-science/amdahls-law/) - [Average Memory Access Time](https://formulabro.yunusemrevurgun.com/computer-science/average-memory-access-time/) - [Little's Law](https://formulabro.yunusemrevurgun.com/computer-science/littles-law/) ## Sources - [Cycles per instruction, Wikipedia](https://en.wikipedia.org/wiki/Cycles_per_instruction) - [Iron law of processor performance, Wikipedia](https://en.wikipedia.org/wiki/Iron_law_of_processor_performance) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Gustafson's Law > Gustafson's law estimates how much more work a parallel computer finishes in the same time when the job grows with the number of processors. Page: https://formulabro.yunusemrevurgun.com/computer-science/gustafsons-law/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ S = N - s\,(N - 1) $$ Read it out loud: "S equals N minus s times the quantity N minus 1. S is the scaled speedup, N is the number of processors, and s is the serial fraction of the parallel run." ## What each symbol means - $S$: The scaled speedup: how many times longer one processor would take to do the same enlarged job. A value of 7.3 means the parallel run finishes about 7.3 times as much work in the same time. - $N$: The number of processors working in parallel. For example $N = 8$ means eight processors. - $s$: The serial fraction: the share of the parallel run's time spent on work that cannot be split, from 0 to 1. For example $s = 0.1$ means 10% of the run is serial. ## What the formula is doing Amdahl's law assumes the job stays the same size while you add processors. Gustafson's law looks at the problem from the other side. In many real programs the problem grows with the machine: a bigger simulation, more data or more users. The useful question becomes how much more work fits into the same time. Measure the job on the parallel machine. Its run takes 1 unit of time. A fraction $s$ of that time is serial work, which runs on one processor. The rest, $1 - s$, is parallel work, and each of the $N$ processors does an equal share of it. Now ask how long one processor would need for the same enlarged job. It does the serial part once, which takes $s$. It must also do all the parallel work. Each processor's share took $1 - s$, and there are $N$ of them, so one processor needs $N(1 - s)$ more. The total is $s + N(1 - s)$. Expanding that gives $S = N - s(N - 1)$, the formula above. The shape shows why this view is more hopeful than Amdahl's law. Each extra processor adds $1 - s$ to the speedup, so the speedup keeps rising as $N$ grows instead of stopping at a fixed ceiling. The catch is that the serial part still costs something. The larger the serial share, the smaller the gain from each new processor. ## An everyday picture Think of a bakery that adds ovens to fill a bigger order. In the same afternoon it bakes many more loaves, so the total output grows with the number of ovens. One step, such as mixing the dough in a single bowl, still takes its usual time, and that step is the serial part. ## Worked example: A parallel run on 8 processors with 10% serial work A program runs on $N = 8$ processors. On this parallel run, 10% of the time is serial work, so $s = 0.1$. The same 0.1 is used in Amdahl's law below only so the two answers can be compared. 1. Parallel share on each processor: $1 - s = 1 - 0.1 = 0.9$ of the parallel run time. 2. Time one processor needs for the same job: the serial part once, plus $N(1 - s) = 8 \cdot 0.9 = 7.2$ for all the parallel work. The total is $0.1 + 7.2 = 7.3$ time units. 3. Formula check: $S = N - s(N - 1) = 8 - 0.1 \cdot 7 = 8 - 0.7 = 7.3$. 4. Amdahl's law for the same 10% serial share and a fixed job: $S = \frac{1}{s + \frac{1 - s}{N}} = \frac{1}{0.1 + 0.1125} \approx 4.71$. **Answer:** With 8 processors and 10% serial work, one processor would take about **7.3 times** as long to do the same enlarged job. If the job must stay the same size, Amdahl's law gives only about **4.71 times** speedup for the same 10% serial share. ## Common mistakes - Mixing up the two serial fractions. In Amdahl's law the serial share is measured on one processor for a fixed job. In Gustafson's law it is measured on the parallel run. - Expecting the speedup to equal $N$. Whenever $s > 0$ and $N > 1$, the result is smaller than $N$, because the serial part still takes its share of time. - Using Gustafson's law for a job that does not grow. If the job stays the same size, Amdahl's law is the right model. - Entering $s$ as a percentage, such as 10, instead of a fraction, such as 0.1. ## Where you will meet it - Estimating how large a simulation or data job can become on a bigger machine while the run time stays fixed. - Weak scaling tests in high-performance computing, where the work per processor is kept fixed as processors are added. - Planning cluster sizes for batch jobs, such as processing more data inside the same nightly window. - Comparing fixed-size and growing-size views of speedup, to decide whether a program should be made bigger or made faster. ## Questions people ask ### When should I use Gustafson's law instead of Amdahl's law? Use Amdahl's law when the job has a fixed size and you want to know how fast it finishes. Use Gustafson's law when the job grows with the machine, such as a bigger grid, more data or more users, and you want to know how much more work fits in the same time. ### Does Gustafson's law say serial work is harmless? No. Each extra processor adds only $1 - s$ to the speedup, so a larger serial share means smaller gains from every new processor. ### Who is the law named after? It is named after John L. Gustafson, who described this view of scaled speedup in a 1988 paper that revisited Amdahl's law. ## Related formulas - [Amdahl's Law](https://formulabro.yunusemrevurgun.com/computer-science/amdahls-law/) - [Little's Law](https://formulabro.yunusemrevurgun.com/computer-science/littles-law/) ## Sources - [Gustafson's law, Wikipedia](https://en.wikipedia.org/wiki/Gustafson%27s_law) - [Amdahl's law, Wikipedia](https://en.wikipedia.org/wiki/Amdahl%27s_law) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # System Availability > System availability tells you the fraction of time a system is working, based on how often it breaks and how long the repair takes. Page: https://formulabro.yunusemrevurgun.com/computer-science/system-availability/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ A = \frac{\text{MTBF}}{\text{MTBF} + \text{MTTR}} $$ Read it out loud: "A equals MTBF divided by the quantity MTBF plus MTTR. A is availability, MTBF is the mean time between failures, and MTTR is the mean time to repair." ## What each symbol means - $A$: Availability: the fraction of time the system is up and working, from 0 to 1. Multiply by 100 to get a percentage, so 0.998 means 99.8%. - $\text{MTBF}$: Mean time between failures: the average time the system runs before it fails, in hours for example. Larger is better. - $\text{MTTR}$: Mean time to repair: the average time needed to bring the system back after a failure. Use the same unit as MTBF. ## What the formula is doing Every system breaks sometimes. Availability asks how much of the time it is up. Two averages describe that: how long it runs between failures, called the mean time between failures or $\text{MTBF}$, and how long a repair takes, called the mean time to repair or $\text{MTTR}$. Think of one cycle. The system runs for about $\text{MTBF}$ hours, then it is down for about $\text{MTTR}$ hours while it is repaired. It works only during the first part. The fraction of time it works is the up time divided by the whole cycle, which gives $A = \frac{\text{MTBF}}{\text{MTBF} + \text{MTTR}}$. The share of time that is down is $1 - A = \frac{\text{MTTR}}{\text{MTBF} + \text{MTTR}}$. When repairs are short compared with the up time, this is close to $\frac{\text{MTTR}}{\text{MTBF}}$. So halving the repair time roughly halves the downtime, and failing less often has the same kind of effect. Availability is often quoted as a percentage with a count of nines. 99.9% is 'three nines'. A year has 8,760 hours, so 99.9% allows about $0.001 \times 8760 = 8.76$ hours of downtime. Each extra nine cuts the allowed downtime by a factor of ten. Parts combine in two ways, assuming their failures are independent. In series, every part must work, so the availabilities multiply: $A = A_1 \times A_2$. Two 99% parts in series give $0.99 \times 0.99 = 0.9801$. In redundant parallel, the system works if either part works, so $A = 1 - (1 - A_1)(1 - A_2)$. Two 99% parts in parallel give $1 - 0.01 \times 0.01 = 0.9999$. ## An everyday picture Think of a bus route. The bus runs for long stretches, then breaks down for a short time before it runs again. Availability is the share of the day the bus is actually on the road. A bus that breaks down rarely and is repaired quickly spends most of the day on the road. ## Worked example: One server that fails rarely A server fails on average every 1,000 hours of running, so $\text{MTBF} = 1000$ hours. A repair takes 2 hours on average, so $\text{MTTR} = 2$ hours. 1. One full cycle, from one failure to the next: $1000 + 2 = 1002$ hours on average. 2. Availability: $A = \frac{1000}{1002} \approx 0.998$, which is 99.8%. 3. Downtime per year: $(1 - A) \times 8760 = \frac{2}{1002} \times 8760 \approx 17.5$ hours. 4. Compare with a 99.9% target, which allows $0.001 \times 8760 = 8.76$ hours of downtime per year. This server would miss that target. **Answer:** The server is up about **99.8%** of the time, which is about **17.5 hours** of downtime per year. That is more than the 8.76 hours allowed by a 99.9% target, so the server would miss it. ## Common mistakes - Mixing units, such as MTBF in days and MTTR in hours. Convert both to the same unit before dividing. - Looking only at MTBF. A system that rarely fails but takes a week to repair can still have poor availability. - Forgetting that the result is a fraction. A value of 0.998 means 99.8%, not 0.998%. - Multiplying availabilities for redundant parts. Redundant parts in parallel are combined with $1 - (1 - A_1)(1 - A_2)$, which is higher than either part alone. ## Where you will meet it - Service level agreements for cloud and hosting providers, where uptime targets are written as percentages. - Planning backup and failover systems, to see how much redundancy a service needs to reach a target. - Reliability engineering for hardware such as power supplies, disks and network equipment. - Setting the downtime budget for a website or online service over a month or a year. ## Questions people ask ### Can a system reach 100% availability? No real system is always up. Designers aim for many nines and plan for failures instead of assuming they never happen. ### What is a nine? Each nine is a digit of the availability written as a run of nines. 99% is two nines, 99.9% is three nines and 99.99% is four nines. Each extra nine divides the yearly downtime by ten. ### Is a higher MTBF always enough? No. Availability depends on both numbers. A long time between failures can be cancelled out by a long repair, so both MTBF and MTTR matter. ## Related formulas - [M/M/1 Queue](https://formulabro.yunusemrevurgun.com/computer-science/mm1-queue/) - [Gustafson's Law](https://formulabro.yunusemrevurgun.com/computer-science/gustafsons-law/) ## Sources - [Reliability engineering, Wikipedia](https://en.wikipedia.org/wiki/Reliability_engineering) - [Mean time between failures, Wikipedia](https://en.wikipedia.org/wiki/Mean_time_between_failures) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # M/M/1 Queue > The M/M/1 formula tells you how long, on average, an item spends in a line with one server, based on how fast items arrive and how fast the server works. Page: https://formulabro.yunusemrevurgun.com/computer-science/mm1-queue/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ W = \frac{1}{\mu - \lambda} $$ Read it out loud: "W equals one divided by the quantity mu minus lambda. W is the average time an item spends in the system, mu is the service rate, and lambda is the arrival rate." ## What each symbol means - $W$: The average time one item spends in the system, from arrival until it is served, including any waiting. Use the same time unit as the rates, such as seconds. - $\lambda$: The arrival rate: how many items arrive per unit of time, such as requests per second. Must be smaller than $\mu$. - $\mu$: The service rate: how many items the server can finish per unit of time, in the same units as $\lambda$, such as requests per second. - $\rho$: The utilization: the fraction of time the server is busy, $\rho = \frac{\lambda}{\mu}$. It has no unit and must be below 1. - $L$: The average number of items in the system at one moment, waiting or being served. $L = \frac{\rho}{1 - \rho}$. ## What the formula is doing An M/M/1 queue has one server, one line, and items that arrive at random. The first M means the arrivals follow a Poisson process, which is the standard model of random arrivals. The second M means the service times follow an exponential distribution. The 1 means there is one server. Real queues are rarely this neat, but the model is a useful first estimate. Two rates describe the line. $\lambda$ is how fast items arrive, and $\mu$ is how fast the server can finish them. Their ratio is the utilization $\rho = \frac{\lambda}{\mu}$, the share of time the server is busy. If $\rho = 0.5$, the server is busy half the time. The average time in the system, $W$, has two parts: the time spent waiting in line and the time spent being served. The waiting part is $\frac{\rho}{\mu - \lambda}$ and the service part is $\frac{1}{\mu}$. Added together they give $W = \frac{1}{\mu - \lambda}$. The term $\mu - \lambda$ is the spare capacity, so the wider the gap between the service rate and the arrival rate, the shorter $W$ becomes. The formula only works when $\lambda < \mu$. If items arrive faster than the server can finish them, the line grows without limit and the average has no finite value. As $\lambda$ gets close to $\mu$, both $W$ and $L = \frac{\rho}{1 - \rho}$ grow very fast. This is why queues blow up near full load. The count $L$ agrees with Little's law, $L = \lambda W$. Multiplying the arrival rate by the average time gives the same number of items in the system, which is a useful check on any answer. ## An everyday picture Think of a checkout with one cashier. Shoppers arrive at random, and the cashier works at a steady pace. If shoppers arrive almost as fast as the cashier can serve them, the line gets long, and each new shopper waits far longer than the time the checkout itself takes. ## Worked example: One server handling 8 requests per second Requests arrive at $\lambda = 8$ per second, and the server can finish $\mu = 10$ requests per second. Both rates use the same unit, so the times come out in seconds. 1. Utilization: $\rho = \frac{\lambda}{\mu} = \frac{8}{10} = 0.8$, so the server is busy 80% of the time. 2. Average time in the system: $W = \frac{1}{\mu - \lambda} = \frac{1}{10 - 8} = 0.5$ seconds. 3. Average number in the system: $L = \frac{\rho}{1 - \rho} = \frac{0.8}{0.2} = 4$ requests. 4. Little's law check: $\lambda W = 8 \cdot 0.5 = 4$, the same count. 5. Heavier load for comparison: if requests arrive at 9.5 per second, then $W = \frac{1}{10 - 9.5} = 2$ seconds. **Answer:** The server is busy 80% of the time, each request spends **0.5 seconds** in the system on average, and about **4 requests** are in the system at any moment. A small rise in arrivals to 9.5 per second makes the average time jump to **2 seconds**. ## Common mistakes - Using the formula when $\lambda \geq \mu$. The server cannot keep up, so the queue is unstable and the formula gives a meaningless negative or undefined answer. - Treating $W$ as only the waiting time. $W$ also includes the time being served, so it is always larger than the time spent in line. - Mixing rates in different units, such as arrivals per minute and service per second. Convert them to one unit first. - Treating $\rho$ as a count of items. Utilization is a fraction between 0 and 1. ## Where you will meet it - Estimating response times for a single web server or API endpoint under a steady load. - Early estimates for a help desk with one agent or a checkout with one cashier. - Network design, to estimate the delay on one link or router queue when traffic is random and steady. - Teaching queueing theory, as the simplest model that shows how waiting time grows near full load. ## Questions people ask ### Why does the wait grow so fast near full load? Because the spare capacity $\mu - \lambda$ shrinks. When the server is 99% busy, $W$ is 100 times the service time $\frac{1}{\mu}$, since $\frac{\mu}{\mu - \lambda} = \frac{1}{1 - \rho} = 100$. ### What if the arrivals are not random? The formulas assume random arrivals and exponential service times. If the pattern is very different, such as fixed-length jobs or sudden bursts, the real waiting times can differ, and another queueing model may fit better. ### How is $W$ different from $L$? $W$ is the time one item spends in the system. $L$ is the number of items in the system at one moment. Little's law connects them: $L = \lambda W$. ## Related formulas - [Little's Law](https://formulabro.yunusemrevurgun.com/computer-science/littles-law/) - [System Availability](https://formulabro.yunusemrevurgun.com/computer-science/system-availability/) ## Sources - [M/M/1 queue, Wikipedia](https://en.wikipedia.org/wiki/M/M/1_queue) - [Queueing theory, Wikipedia](https://en.wikipedia.org/wiki/Queueing_theory) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Perfect Binary Tree Nodes > The formula counts the nodes in a perfect binary tree from its height, by doubling the number of nodes on each level. Page: https://formulabro.yunusemrevurgun.com/computer-science/perfect-binary-tree-nodes/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ N = 2^{h+1} - 1 $$ Read it out loud: "N equals 2 to the power of h plus 1, minus 1. N is the number of nodes and h is the height of the tree." ## What each symbol means - $N$: The total number of nodes in the tree, counting the root, the inner nodes and the leaves. - $h$: The height of the tree: the number of edges on the longest path from the root down to a leaf. The root alone has height 0. ## What the formula is doing A binary tree is a set of nodes where each node has at most two children. A perfect binary tree is one where every inner node has exactly two children and every leaf sits at the same depth. Drawn in levels, every level is completely full. Define the height $h$ as the number of edges from the root to the bottom. The root alone has height 0. A root with two children has height 1, and so on. Level $k$ is the set of nodes $k$ edges below the root, so level 0 is the root. Each node on one level has two children on the next level, so level $k$ holds $2^k$ nodes. Level 0 has $2^0 = 1$ node, level 1 has $2^1 = 2$ nodes, and level 2 has $2^2 = 4$ nodes. The bottom level, the leaves, holds $2^h$ nodes. Adding every level from 0 to $h$ gives $1 + 2 + 4 + \cdots + 2^h$. This is a geometric series, and its sum is $2^{h+1} - 1$. Check with $h = 2$: $1 + 2 + 4 = 7 = 2^3 - 1$. The count grows fast because each new level doubles the number of nodes at the bottom. A perfect binary tree of height 20 already has $2^{21} - 1 = 2{,}097{,}151$ nodes. ## An everyday picture Think of a knockout tournament bracket with eight teams. There are 4 first-round games, 2 semifinals and 1 final, which is 7 games in total. That matches $2^3 - 1$, where the 8 teams are the leaves and each game is an inner node. ## Worked example: A perfect binary tree of height 3 A perfect binary tree has height $h = 3$. From the root, the longest path down to a leaf has 3 edges, so the tree has 4 levels, numbered 0 to 3. 1. Level 0, the root: $2^0 = 1$ node. 2. Level 1: $2^1 = 2$ nodes. 3. Level 2: $2^2 = 4$ nodes. 4. Level 3, the leaves: $2^3 = 8$ nodes. 5. Total: $1 + 2 + 4 + 8 = 15$ nodes. 6. Formula in one step: $N = 2^{3+1} - 1 = 2^4 - 1 = 16 - 1 = 15$. **Answer:** The tree has **15 nodes** in total, and **8 leaves** on its bottom level. The formula gives the total in one step, so you do not have to add up the levels. ## Common mistakes - Counting the root as height 1. Height counts edges, so the root alone has height 0. This off-by-one error is the most common one. - Leaving out the $+1$ in the exponent. Using $2^h - 1$ gives 7 for $h = 3$ instead of 15. - Using the formula for a tree that is not perfect. If some leaves sit higher than others, the tree has fewer nodes than the formula gives. - Mixing up nodes and edges. A tree with $N$ nodes always has $N - 1$ edges. ## Where you will meet it - Analyzing binary search trees and heaps, where the height decides how many steps a search or insert takes. - Tournament brackets and other knockout trees, where each leaf is a competitor and each inner node is a match. - Estimating the memory a tree of fixed height needs, since each node takes the same amount of space. - Proving facts about tree-shaped data structures by counting levels, as in the textbook arguments for tree operations. ## Questions people ask ### Is a perfect binary tree the same as a complete binary tree? No. A perfect tree has every level full. A complete tree fills every level except possibly the last, and the last level fills from the left. Every perfect tree is complete, but not every complete tree is perfect. ### How many leaves does a perfect binary tree have? $2^h$ leaves for height $h$. Height 3 gives 8 leaves, and height 10 gives $2^{10} = 1024$ leaves. ### Why is there a $+1$ in the exponent? Because height counts edges, a tree of height $h$ has $h + 1$ levels. The levels run from 0 to $h$, and the sum of all of them is $2^{h+1} - 1$. ## Related formulas - [Binary Search Steps](https://formulabro.yunusemrevurgun.com/computer-science/binary-search-steps/) - [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/) - [Euler's Formula for Planar Graphs](https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs/) ## Sources - [Binary tree, Wikipedia](https://en.wikipedia.org/wiki/Binary_tree) - [Tree (data structure), Wikipedia](https://en.wikipedia.org/wiki/Tree_%28data_structure%29) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Complete Graph Edges > A complete graph joins every pair of points with one line, and this formula counts how many lines that takes. Page: https://formulabro.yunusemrevurgun.com/computer-science/complete-graph-edges/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E = \frac{n(n-1)}{2} $$ Read it out loud: "E equals n times the quantity n minus 1, divided by 2. E is the number of edges and n is the number of vertices." ## What each symbol means - $E$: The number of edges: the lines that join pairs of vertices. Each edge joins exactly two vertices. - $n$: The number of vertices, the points or nodes of the graph. A complete graph with $n$ vertices is written $K_n$. ## What the formula is doing A graph is a set of vertices, the dots, joined by edges, the lines. In a complete graph, every pair of different vertices is joined by exactly one edge. There are no missing links and no doubled links. The complete graph with $n$ vertices is written $K_n$. Each vertex has $n - 1$ edges leaving it, because it joins every other vertex. Adding this over all $n$ vertices gives $n(n - 1)$. But each edge was counted twice, once from each of its two ends, so the true count is half of that. This gives $E = \frac{n(n-1)}{2}$. The same count appears in the handshake problem: if $n$ people each shake hands once with everyone else, there are $\frac{n(n-1)}{2}$ handshakes, and each handshake is one edge. The number grows quickly. Because $n(n - 1)$ is close to $n^2$, doubling the number of vertices roughly quadruples the number of edges. That is why a full mesh of many machines needs far more links than a tree or a ring. ## An everyday picture Think of a video call with five people in which everyone is connected directly to everyone else, with no one passing messages through a third person. Each person needs one connection to each of the other four, and each connection is shared by two people. ## Worked example: Ten computers in a full mesh Ten computers are linked so that every computer has a direct cable to every other computer. That gives $n = 10$ vertices, and each cable is one edge. 1. Cables from one computer: $n - 1 = 10 - 1 = 9$. 2. Cable ends across all computers: $n(n - 1) = 10 \cdot 9 = 90$. 3. Each cable has two ends, so the number of cables is $E = \frac{90}{2} = 45$. 4. Formula in one step: $E = \frac{10 \cdot 9}{2} = 45$. **Answer:** The full mesh needs **45 cables**. Adding an eleventh computer raises the count to 55, so the new computer needs **10 new cables**, one to each machine already in the mesh. ## Common mistakes - Forgetting to divide by 2. Counting from each vertex counts every edge twice. - Using $n$ instead of $n - 1$ for the edges at one vertex. A vertex is not joined to itself, so it has $n - 1$ edges. - Using the formula for a graph that is not complete. If some pairs are not joined, there are fewer edges than the formula gives. - Thinking the count is $n^2$. The true count is about half of $n^2$, because each edge is shared by two vertices. ## Where you will meet it - Sizing a full-mesh network, where every device has a direct link to every other device. - Solving handshake problems, where each pair of people shakes hands once. - Round-robin tournaments, where each pair of teams plays exactly one game. - Graph theory, where complete graphs are the standard examples of graphs with the most possible edges. ## Questions people ask ### Is a complete graph the same as a cycle? No. In a cycle each vertex has 2 edges, joining the vertices in a loop. In a complete graph each vertex has $n - 1$ edges, because every pair is joined. Five vertices make a cycle with 5 edges, but a complete graph on five vertices has 10. ### Does direction matter in this formula? Not here. The formula counts undirected edges, where each edge joins two vertices with no direction. A directed version, with arrows in both directions for every pair, has $n(n - 1)$ arrows. ### How many edges does a graph with one vertex have? Zero. A single vertex has no pair to connect, and $\frac{1 \cdot 0}{2} = 0$. ## Related formulas - [Euler's Formula for Planar Graphs](https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs/) - [PageRank](https://formulabro.yunusemrevurgun.com/computer-science/pagerank/) - [Perfect Binary Tree Nodes](https://formulabro.yunusemrevurgun.com/computer-science/perfect-binary-tree-nodes/) ## Sources - [Complete graph, Wikipedia](https://en.wikipedia.org/wiki/Complete_graph) - [Handshaking lemma, Wikipedia](https://en.wikipedia.org/wiki/Handshaking_lemma) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Euler's Formula for Planar Graphs > Euler's formula says that if you draw a connected network on a flat sheet with no crossing lines, counting corners, lines and regions always gives 2. Page: https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ V - E + F = 2 $$ Read it out loud: "V minus E plus F equals 2. V is the number of vertices, E is the number of edges, and F is the number of faces." ## What each symbol means - $V$: The number of vertices: the corner points or dots of the graph. - $E$: The number of edges: the lines that join the vertices. Each edge joins two vertices. - $F$: The number of faces: the regions the drawing cuts the plane into. The outer region outside the drawing counts as one face. ## What the formula is doing A graph is a set of vertices joined by edges. It is planar when it can be drawn on a flat sheet so that no two edges cross, except at a shared vertex. It is connected when you can walk from any vertex to any other along the edges. Draw the graph on paper and count three things: the dots, the lines, and the regions the drawing divides the paper into. Those regions are the faces, and the big region outside the drawing counts as one too. A triangle has 3 vertices, 3 edges and 2 faces: the inside and the outside. For every connected planar drawing, the three counts satisfy $V - E + F = 2$. Changing the shape of the drawing changes the individual counts, but not the answer. If you know two of the numbers, the third follows, so $F = 2 - V + E$. The 2 comes from the shape of the sphere. A flat drawing of a graph can be wrapped onto a ball like a map, and the sphere has Euler characteristic 2. That is why the same count of corners, edges and faces also works for solid shapes such as cubes. The formula needs the graph to be connected. If the graph falls into several separate pieces, the total is 1 plus the number of pieces, so check the connection before you use the value 2. ## An everyday picture Think of a map of a few countries drawn on a flat sheet. The borders are edges, the points where borders meet are vertices, and each country is a face. The sea outside the map is one more face, and the counts still follow the same rule. ## Worked example: A cube as a planar graph A cube has 8 corners, 12 edges and 6 square faces. Draw its frame on paper as one square inside another, with the corners joined. The outer region outside the drawing counts as one of the faces. 1. Vertices: $V = 8$ corners. 2. Edges: $E = 12$ lines. 3. Faces: $F = 6$ regions, which are the 4 trapezoids between the squares, the inner square and the outside. 4. Euler's formula: $V - E + F = 8 - 12 + 6 = 2$. 5. Solving for a missing count: if a connected planar graph has $V = 8$ and $E = 12$, then $F = 2 - 8 + 12 = 6$. **Answer:** The cube frame gives $8 - 12 + 6 = 2$, as the formula says. Knowing any two of $V$, $E$ and $F$ tells you the third, so a connected planar drawing with 8 vertices and 12 edges must have **6 faces**. ## Common mistakes - Leaving out the outer face. A triangle has 2 faces, not 1, because the outside is a face too. - Using the formula on a graph that is not connected. Then the total is 1 plus the number of separate pieces, not 2. - Using the formula on a drawing with crossing edges. A drawing with crossings is not a planar drawing, so the formula does not apply to it as drawn. - Mixing up faces and edges. Edges are the lines and faces are the regions between them. ## Where you will meet it - Checking whether a network can be laid out on a flat sheet without crossings, a central question in planar graph theory. - Proving facts about polyhedra, since the cube, the tetrahedron and the icosahedron all satisfy the formula. - Mesh processing in computer graphics, where the Euler characteristic is used to check the shape of a 3D surface. - Proofs that some graphs cannot be drawn without crossings, such as the complete graph $K_5$. ## Questions people ask ### Why does a triangle have 2 faces? The triangle's three edges split the paper into two regions, the inside and the outside. Both count as faces, so $F = 2$ and $3 - 3 + 2 = 2$. ### Does the drawing change the answer? No. You can move or stretch the drawing, and the counts of vertices, edges and faces stay the same, so $V - E + F$ stays 2 for any valid planar drawing. ### Who is the formula named after? It is named after Leonhard Euler, the Swiss mathematician who studied it. The same name is also used for a different formula about complex numbers, so this page means the planar graph version. ## Related formulas - [Complete Graph Edges](https://formulabro.yunusemrevurgun.com/computer-science/complete-graph-edges/) - [PageRank](https://formulabro.yunusemrevurgun.com/computer-science/pagerank/) - [Perfect Binary Tree Nodes](https://formulabro.yunusemrevurgun.com/computer-science/perfect-binary-tree-nodes/) ## Sources - [Planar graph, Wikipedia](https://en.wikipedia.org/wiki/Planar_graph) - [Euler characteristic, Wikipedia](https://en.wikipedia.org/wiki/Euler_characteristic) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # PageRank > PageRank gives each web page a score based on how many good pages link to it, so each link acts like a vote with a weight. Page: https://formulabro.yunusemrevurgun.com/computer-science/pagerank/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ PR(p) = \frac{1 - d}{N} + d \sum_{q \to p} \frac{PR(q)}{L(q)} $$ Read it out loud: "PR of p equals one minus d, divided by N, plus d times the sum, over every page q that links to p, of PR of q divided by L of q. d is the damping factor, usually 0.85." ## What each symbol means - $PR(p)$: The PageRank of page $p$: its score. When all scores are scaled to add up to 1, each score is a number between 0 and 1. - $N$: The total number of pages in the set being ranked. - $d$: The damping factor, usually 0.85. It is the chance a random surfer follows a link instead of jumping to a random page. - $q \to p$: The sum runs over every page $q$ that links to $p$, the incoming links. - $PR(q)$: The current score of a page $q$ that links to $p$. - $L(q)$: The number of outgoing links on page $q$, the links that leave it. ## What the formula is doing The idea is a vote with weight. A link from page $q$ to page $p$ counts as a vote for $p$. A vote from a page with a high score counts for more, and a page with many links spreads its score across them. Each page $q$ passes its score to the pages it links to, split equally among its $L(q)$ outgoing links. Each linked page receives $\frac{PR(q)}{L(q)}$. Adding these shares over every page that links to $p$ gives the link part of $p$'s score. The damping factor $d$, usually 0.85, mixes in a small base. A random surfer follows a link with probability $d$ and jumps to a random page with probability $1 - d$. The term $\frac{1 - d}{N}$ is the random-jump share, and every page receives it, so no page ends up with a score of zero. The formula refers to other pages' scores, so it is solved by repetition. Start every page at $\frac{1}{N}$, apply the formula to all pages, and repeat. The scores change less each round and settle. The idea and the formula come from the 1998 paper by Brin and Page cited below. ## An everyday picture Think of a town where recommendations count for more when they come from respected people. A recommendation from a well-regarded neighbor is worth more than one from a stranger, and a neighbor who recommends ten shops gives each shop only a tenth of their weight. ## Worked example: Three pages that link to each other A tiny web has $N = 3$ pages: A, B and C. A links to B and C, B links to C, and C links to A. So $L(A) = 2$, $L(B) = 1$ and $L(C) = 1$. Start every page at $\frac{1}{3}$, use $d = 0.85$, and work through one round of updates. 1. Base term for every page: $\frac{1 - d}{N} = \frac{0.15}{3} = 0.05$. 2. Page A gets a vote only from C, since C links to A: $PR(A) = 0.05 + 0.85 \cdot \frac{1/3}{1} = 0.05 + 0.2833 = 0.3333$. 3. Page B gets a vote only from A, which splits its score over 2 links: $PR(B) = 0.05 + 0.85 \cdot \frac{1/3}{2} = 0.05 + 0.1417 = 0.1917$. 4. Page C gets votes from A, split two ways, and from B: $PR(C) = 0.05 + 0.85 \cdot \left(\frac{1/3}{2} + \frac{1/3}{1}\right) = 0.05 + 0.85 \cdot 0.5 = 0.475$. 5. Check: $0.3333 + 0.1917 + 0.4750 = 1.0000$, so the scores still add up to 1. **Answer:** After one round, C has the highest score, **0.475**, because two pages vote for it. A has **0.3333** and B has **0.1917**. The next round starts from these new scores, and they keep changing until they settle. ## Common mistakes - Forgetting to divide by $L(q)$. A page with many outgoing links gives each target a smaller share, not its full score. - Using $d$ for the base term. The base term is $1 - d$, which is 0.15 when $d = 0.85$. - Summing over the outgoing links of $p$. The sum runs over the pages that link to $p$, the incoming links. - Expecting one round to give the final scores. Repeat the update until the scores stop changing. ## Where you will meet it - Ranking pages in the Google search engine, the link-analysis method described in the 1998 Brin and Page paper. - Ranking scientific papers by their citation links, where a paper cited by highly ranked papers scores higher. - Finding influential users or accounts in social networks, using the same link-based scores. - Teaching graph theory and Markov chains, since PageRank is the long-run distribution of a random surfer on the link graph. ## Questions people ask ### Why is $d$ set to 0.85? It is the value most descriptions use. It means a random surfer follows links about 85% of the time and jumps to a random page the rest of the time. Other values work, and the scores shift a little when $d$ changes. ### Do the scores have to add up to 1? With this version of the formula, yes, as the example shows. Some texts write the base term as $1 - d$ with no division by $N$, and then the scores add up to $N$ instead. ### What about a page with no outgoing links? It is called a dangling page, and its score would leak out of the system. Practical versions share such a page's score across all pages. This page does not cover that case. ## Related formulas - [TF-IDF](https://formulabro.yunusemrevurgun.com/computer-science/tf-idf/) - [Complete Graph Edges](https://formulabro.yunusemrevurgun.com/computer-science/complete-graph-edges/) - [Euler's Formula for Planar Graphs](https://formulabro.yunusemrevurgun.com/computer-science/eulers-formula-for-planar-graphs/) ## Sources - [PageRank, Wikipedia](https://en.wikipedia.org/wiki/PageRank) - [Brin and Page, The Anatomy of a Large-Scale Hypertextual Web Search Engine (1998)](https://doi.org/10.1016/S0169-7552%2898%2900110-X) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # TF-IDF > TF-IDF gives a word a high score in a document when the word appears often there but rarely in the other documents. Page: https://formulabro.yunusemrevurgun.com/computer-science/tf-idf/ Category: Computer Science Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \text{tfidf}(t, d) = \text{tf}(t, d) \times \ln\frac{N}{\text{df}(t)} $$ Read it out loud: "tf-idf of t and d equals tf of t and d, times the natural log of N divided by df of t. t is a term, d is a document, and N is the number of documents." ## What each symbol means - $t$: A term: the word or phrase being scored, such as the word cat. - $d$: One document, such as one web page or one article. - $N$: The total number of documents in the collection. - $\text{tf}(t, d)$: Term frequency: how many times term $t$ appears in document $d$. This page uses the raw count. - $\text{df}(t)$: Document frequency: how many documents in the collection contain term $t$ at least once. - $\text{tfidf}(t, d)$: The score of term $t$ in document $d$. A higher score means the word says more about that document. ## What the formula is doing Search engines need a way to tell which words matter in a document. Common words such as the or and appear in almost every document, so they say little. A word such as cat that appears often in one document and rarely in others says a lot about it. TF-IDF combines these two ideas. The first part, the term frequency $\text{tf}(t, d)$, counts how many times the term appears in the document. More mentions mean the term is more about that document. Other versions divide by the document length or use a different scale, but this page uses the plain count. The second part is the inverse document frequency, $\ln\frac{N}{\text{df}(t)}$. The ratio $\frac{N}{\text{df}(t)}$ is large when few documents contain the term, so the score grows as the word gets rarer. A word that appears in every document has $\frac{N}{\text{df}} = 1$ and $\ln 1 = 0$, so it counts for nothing. The TF-IDF score is the product of the two parts. A word must be frequent in this document and rare across the collection to score high. The logarithm here is the natural log, $\ln$, with base $e \approx 2.718$. Some tools use log base 10 or add smoothing, which changes the numbers but not the idea. ## An everyday picture Think of a class of students writing essays about a topic. The word photosynthesis used ten times in one biology essay is a strong clue to that essay's subject, because most other essays do not use it. The word the appears in every essay and tells you nothing, so TF-IDF rewards the first and ignores the second. ## Worked example: Two words in a collection of 100 documents A collection has $N = 100$ documents. The word cat appears in $\text{df} = 4$ of them, and the word the appears in 99 of them. In one document $d$, cat appears 3 times and the appears 5 times. The log is the natural log. 1. Inverse document frequency of cat: $\ln\frac{100}{4} = \ln 25 \approx 3.2189$. 2. TF-IDF of cat in $d$: $3 \cdot 3.2189 \approx 9.66$. 3. Inverse document frequency of the: $\ln\frac{100}{99} \approx 0.01005$. 4. TF-IDF of the in $d$: $5 \cdot 0.01005 \approx 0.0503$. **Answer:** The word **cat** scores about **9.66** in this document, while **the** scores about **0.0503**. Cat scores high because it is frequent here and rare across the collection. The scores almost zero for the, because it appears in nearly every document. ## Common mistakes - Mixing up the two parts. Term frequency counts occurrences inside one document, and document frequency counts documents across the whole collection. - Flipping the ratio. It must be $N$ divided by $\text{df}$, so that rare words get a large number. - Expecting every tool to give the same numbers. Some versions use other logs, smoothing or normalized term frequencies, so check which one is in use before comparing scores. - Thinking a word in every document is important. Its score is $\ln 1 = 0$, which is correct, because such a word cannot tell documents apart. ## Where you will meet it - Ranking documents for a search query in classic information retrieval systems, where matching words are weighted by TF-IDF. - Finding keywords in a document by picking the terms with the highest scores. - Text classification and document clustering, where TF-IDF vectors are the inputs to a model. - Comparing how similar two documents are, often by computing cosine similarity between their TF-IDF vectors. ## Questions people ask ### Why is there a logarithm? Without it, the ratio $\frac{N}{\text{df}}$ can become very large, so a rare word would completely dominate the score. The logarithm keeps the idf part on a scale closer to the term frequency. ### What if a word is not in the collection at all? Then $\text{df}(t) = 0$ and the ratio divides by zero. Real systems avoid this by scoring only terms that appear in the collection, or by adding 1 to the document frequency. ### Is TF-IDF the same as a word count? No. A word count uses only the term frequency. TF-IDF also lowers the score of words that appear in many documents, so common words count for less. ## Related formulas - [PageRank](https://formulabro.yunusemrevurgun.com/computer-science/pagerank/) - [Shannon Entropy](https://formulabro.yunusemrevurgun.com/computer-science/shannon-entropy/) ## Sources - [Tf-idf, Wikipedia](https://en.wikipedia.org/wiki/Tf%E2%80%93idf) - [Information retrieval, Wikipedia](https://en.wikipedia.org/wiki/Information_retrieval) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Ohm's Law > Ohm's law says the push on a wire, the voltage, equals the flow through it, the current, times how hard that flow is to get through, the resistance. Page: https://formulabro.yunusemrevurgun.com/electricity/ohms-law/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ V = I R $$ Read it out loud: "V equals I times R. Voltage equals current times resistance." ## What each symbol means - $V$: **Voltage**, the electrical push across the part, measured in volts (V). More voltage pushes more current through. - $I$: **Current**, the flow of electric charge through the part, measured in amperes (A). One ampere is one coulomb of charge per second. - $R$: **Resistance**, how strongly the part opposes the flow, measured in ohms ($\Omega$). A bigger number means less current for the same voltage. ## What the formula is doing Three quantities are linked here: voltage $V$ in volts (V), current $I$ in amperes (A) and resistance $R$ in ohms ($\Omega$). Ohm's law says that the voltage across a part equals the current through it multiplied by its resistance. If you know any two of the three, you can work out the third. Rearranged, the same rule reads $I = \frac{V}{R}$ and $R = \frac{V}{I}$. Those versions answer the questions people usually ask. Double the voltage on the same resistor and the current doubles. Keep the voltage the same and double the resistance, and the current is cut in half. A resistor is the everyday part that follows this rule. Its resistance is set by its material and shape, and it does not change when you change the voltage. The unit of resistance is named after the physicist Georg Ohm. Ohm's law has limits. It describes **ohmic** parts, where the current rises in a straight line with the voltage. Diodes and LEDs are not ohmic. An LED drops about 2 V and then lets the current climb steeply, so the ratio $V / I$ is not a fixed number. For those parts you still use the voltage and current, but you need a separate curve or a series resistor to control the current. ## An everyday picture Think of water in a pipe. The voltage is the water pressure that pushes the water, the current is how much water flows past each second, and the resistance is how narrow the pipe is. Higher pressure pushes more water through. A narrower pipe lets less through for the same pressure. In this picture Ohm's law reads: flow equals pressure divided by how narrow the pipe is, so the pressure needed for a given flow equals the flow times the narrowness. ## Worked example: Choosing a resistor for an LED on a 5 V supply A 5 V supply powers a red LED that drops 2 V when lit. The LED should run at 20 mA, which is the current the designer wants. The resistor in series with the LED takes the leftover voltage. What resistance should it be? 1. The resistor sees the supply voltage minus the LED voltage: $V_R = 5\ \text{V} - 2\ \text{V} = 3\ \text{V}$. 2. Convert the current to amperes: $20\ \text{mA} = 0.02\ \text{A}$. 3. Rearrange Ohm's law to $R = \frac{V}{I}$ and fill in the numbers: $R = \frac{3\ \text{V}}{0.02\ \text{A}} = 150\ \Omega$. 4. Check the power the resistor turns into heat: $P = V_R \times I = 3\ \text{V} \times 0.02\ \text{A} = 0.06\ \text{W}$. **Answer:** Use a **150 ohm** resistor. It drops the leftover 3 V, so the LED gets its 2 V and the circuit carries 20 mA. The resistor turns about 0.06 W into heat, so a standard 1/4 W resistor is enough. ## Common mistakes - Using milliamps as if they were amps. 20 mA is 0.02 A. Plugging in 20 gives a resistance 1000 times too small. - Using the full supply voltage instead of the voltage across the resistor. The LED takes its own share, so the resistor sees only the difference. - Treating an LED or a diode as a plain resistor. These parts are not ohmic, so one fixed resistance does not describe them. - Thinking that a bigger resistor lets more current through. For the same voltage, a bigger resistance gives less current. ## Where you will meet it - Choosing the resistor for an LED, an indicator light or a button backlight so the current stays safe. - Working out the resistance of a wire, heater or sensor from a voltmeter and an ammeter reading. - Estimating the voltage lost along a long cable, which is the current times the cable resistance. - Designing the bias networks and dividers that set the operating point of transistors and sensors. ## Questions people ask ### Why is the formula V = I R and not I = V R? Current goes up when the voltage goes up and goes down when the resistance goes up. So the voltage is on top when you solve for current, $I = \frac{V}{R}$, and multiplying back gives $V = I R$. ### What is an ohm? One ohm ($\Omega$) is the resistance that lets 1 A flow when 1 V is across it. It is $1\ \Omega = 1\ \text{V} / 1\ \text{A}$. ### Does Ohm's law work for every device? No. It works for ohmic parts such as ordinary resistors. LEDs, diodes and transistors do not follow a straight line, so you need their own datasheet curves for them. ### If an LED has its own resistance, why does it still need a resistor? Past its forward voltage, the current in an LED climbs very fast for a small change in voltage. A series resistor limits the current, so a small change in the supply does not destroy the LED. ## Related formulas - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) ## Sources - [Ohm's law, Wikipedia](https://en.wikipedia.org/wiki/Ohm%27s_law) - [Electrical resistance and conductance, Wikipedia](https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance) - [Light-emitting diode, Wikipedia](https://en.wikipedia.org/wiki/Light-emitting_diode) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Electric Power > Electric power tells you how fast a device uses energy, and you get it by multiplying the volts by the amps to get watts. Page: https://formulabro.yunusemrevurgun.com/electricity/electric-power/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P = V I $$ Read it out loud: "P equals V times I. Power in watts equals volts times amps." ## What each symbol means - $P$: **Power**, how fast electrical energy is used or delivered, measured in watts (W). One watt is one joule of energy per second. - $V$: **Voltage**, the electrical push across the device, measured in volts (V). - $I$: **Current**, the flow of charge through the device, measured in amperes (A). ## What the formula is doing Power is a rate: it says how much energy a device uses or delivers each second. Its unit is the watt (W), named after James Watt. A device rated at 2000 W uses 2000 joules of energy every second while it runs. The formula $P = V I$ says power is the voltage times the current. Voltage $V$ is the push, in volts (V). Current $I$ is the flow, in amperes (A). A bigger push or a bigger flow gives more power, and multiplying the two gives watts. Ohm's law lets you rewrite the same formula with resistance $R$ in ohms ($\Omega$). Since $V = I R$, you get $P = I^2 R$ when you know the current, and $P = \frac{V^2}{R}$ when you know the voltage. All three versions give the same answer for a resistor, so use whichever pair of numbers you already have. Mains voltage is dangerous. It is 230 V in much of the world and 120 V in North America, and it can cause a lethal shock. Do not open mains devices such as kettles, heaters or chargers to test them, and get a qualified person to repair them. ## An everyday picture Think of a water wheel. The voltage is how high the water falls, the current is how much water flows past each second, and the power is how hard the wheel turns. A tall fall with a big flow turns the wheel hard. A tall fall with a trickle, or a big flow over a short drop, does much less. ## Worked example: A 2000 W kettle on 230 V and on 120 V A kettle is rated at $P = 2000\ \text{W}$. Mains supplies vary by region: first the kettle runs on a 230 V supply, then the same 2000 W is needed from a 120 V supply. How much current does it draw in each case? Do not open the kettle to check; the wiring is at mains voltage. 1. Rearrange $P = V I$ to get the current: $I = \frac{P}{V}$. 2. On 230 V: $I = \frac{2000\ \text{W}}{230\ \text{V}} \approx 8.70\ \text{A}$. 3. On 120 V: $I = \frac{2000\ \text{W}}{120\ \text{V}} \approx 16.7\ \text{A}$. 4. Check the 230 V case: $8.70\ \text{A} \times 230\ \text{V} = 2001\ \text{W}$, which is 2000 W with rounding. **Answer:** The kettle draws about **8.70 A** on 230 V. The same 2000 W on 120 V draws about **16.7 A**, nearly twice the current, so the wiring has to carry much more current for the same power. ## Common mistakes - Mixing up watts and watt-hours. A watt is a rate, while a watt-hour is an amount of energy. The page on energy and kilowatt-hours explains the difference. - Forgetting to convert units. 20 mA is 0.02 A, not 20 A, so convert milliamps to amps before you multiply. - Assuming the power stays the same when the voltage changes. For a fixed resistance, power grows with the square of the voltage, $P = V^2 / R$, so a small change in voltage makes a big difference. - Opening a mains device to measure its power. The voltage can cause a lethal shock, and the wiring stays dangerous even when the device is switched off. ## Where you will meet it - Appliance labels and electricity bills, where each device is rated in watts. - Choosing a fuse, circuit breaker or power supply that can carry the current a device will draw. - Rating solar panels, batteries and chargers, which list their output power in watts. - Heaters and electric motors, where the power rating shows how much heat or work the device can deliver. ## Questions people ask ### What is the difference between a volt and a watt? A volt measures the push (voltage). A watt measures the rate of energy use (power). A device can have a high voltage and still use little power if very little current flows. ### Can I use P = V I for a battery? Yes. For a battery, $V$ is the voltage it delivers and $I$ is the current it supplies, so $P$ is the power it hands to the device. ### How many watts are in a kilowatt? One kilowatt (kW) is 1000 W. A 2 kW heater uses 2000 W while it runs. ### Are $P = V I$ and $P = I^2 R$ different formulas? They are the same formula for a resistor, because Ohm's law links $V$ and $I$ through $R$. Pick whichever pair of numbers you have. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Energy and Kilowatt-Hours](https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) ## Sources - [Electric power, Wikipedia](https://en.wikipedia.org/wiki/Electric_power) - [Watt, Wikipedia](https://en.wikipedia.org/wiki/Watt) - [Volt, Wikipedia](https://en.wikipedia.org/wiki/Volt) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Energy and Kilowatt-Hours > Energy is power multiplied by time, so a heater that uses 2 kilowatts for 3 hours uses 6 kilowatt-hours of energy. Page: https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E = P \, t $$ Read it out loud: "E equals P times t. Energy equals power times time." ## What each symbol means - $E$: **Energy**, the total amount of electricity used or delivered. Measured in joules (J), or in watt-hours (Wh) and kilowatt-hours (kWh) for electricity bills. - $P$: **Power**, how fast energy is used, measured in watts (W). - $t$: **Time**, how long the device runs, measured in seconds (s) or hours (h), as long as the units match the power. ## What the formula is doing Energy is the total amount of work electricity can do or the total heat it can make. The SI unit of energy is the joule (J). One joule is the energy used by a 1 W device running for one second. Power $P$ is how fast energy is used, in watts (W). Time $t$ is how long the device runs. Multiply power by time and you get the total energy used: $E = P\,t$. If the time doubles at the same power, the energy doubles too. A watt-hour (Wh) is energy measured in a bigger unit: one watt running for one hour. One hour is 3600 seconds, so 1 Wh = 3600 J. A kilowatt-hour (kWh) is 1000 Wh. Power companies bill in kilowatt-hours, because a joule is far too small a unit to count on a bill: 1 kWh is 3.6 million joules, or 3.6 MJ. Watts and kilowatt-hours answer different questions. Watts describe a rate, like speed. Kilowatt-hours describe a total, like the distance traveled. A 2000 W heater uses 2 kWh in one hour and 6 kWh in three hours. Heaters run on mains voltage, so do not open them, and keep them away from water. ## An everyday picture Think of a tap filling a bucket. The flow rate, in liters per minute, is like power, because it says how fast water arrives. The amount of water in the bucket is like energy. Run the tap twice as long and the bucket holds twice as much. A kilowatt-hour is a standard-size bucket of electricity, and the power company counts how many of those buckets you used. ## Worked example: A heater, an LED bulb and what they cost A 2000 W heater runs for 3 hours on a mains supply. A 10 W LED bulb runs for 10 hours. For the cost, use an example price of 0.15 dollars per kWh. This price is only for the arithmetic: it is not a real tariff, and real prices vary by country and provider. Heaters run on mains voltage, so do not open one to check it. 1. Heater energy: $E = P\,t = 2000\ \text{W} \times 3\ \text{h} = 6000\ \text{Wh} = 6\ \text{kWh}$. 2. Heater cost at the example price: $6\ \text{kWh} \times 0.15\ \frac{\text{dollars}}{\text{kWh}} = 0.90\ \text{dollars}$. 3. LED energy: $E = 10\ \text{W} \times 10\ \text{h} = 100\ \text{Wh} = 0.1\ \text{kWh}$. 4. Check the unit: $1\ \text{kWh} = 1000\ \text{W} \times 3600\ \text{s} = 3\,600\,000\ \text{J} = 3.6\ \text{MJ}$. **Answer:** The 2000 W heater uses **6 kWh** and costs **0.90 dollars** at the example price. The 10 W LED bulb uses only **0.1 kWh**, even though it ran for longer. Power sets how fast energy is used, and time sets how much is used in total. ## Common mistakes - Confusing watts with watt-hours. A watt is a rate, while a watt-hour is an amount. A 2000 W heater uses 2 kWh in one hour, so the rate and the total are different numbers. - Forgetting to convert minutes to hours. Thirty minutes is 0.5 h, so a 2000 W heater for 30 minutes uses 1 kWh. - Multiplying the price by the power instead of the energy. Bills charge per kWh, so multiply the kWh used by the price per kWh. - Treating the example price as a real tariff. Electricity prices vary by country, provider and time of day, so check your own bill. ## Where you will meet it - Electricity bills, which charge for the kilowatt-hours used in each billing period. - Appliance energy labels, where a fridge or washing machine is compared by its energy use over a year, in kilowatt-hours. - Battery capacity, where home and car batteries are rated in kilowatt-hours. - Physics and engineering, where energy is counted in joules and 1 kWh = 3.6 MJ links the two units. ## Questions people ask ### What is the difference between a watt and a watt-hour? A watt (W) is a rate: how fast energy is used. A watt-hour (Wh) is an amount: 1 W running for 1 hour. A 60 W bulb uses 60 Wh in one hour. ### Why do bills use kilowatt-hours and not joules? A joule is a tiny amount. One kilowatt-hour is 3.6 million joules, so kilowatt-hours give manageable numbers, such as 6 kWh for a heater running 3 hours. ### How do I work out what an appliance costs to run? Multiply the power in kilowatts by the hours used to get kWh. Then multiply the kWh by your price per kWh, and check your bill for the real price. ### Is energy the same as power? No. Power is a rate and energy is a total. Two devices can have the same power, but the one that runs longer uses more energy. ## Related formulas - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) ## Sources - [Kilowatt-hour, Wikipedia](https://en.wikipedia.org/wiki/Kilowatt-hour) - [Watt-hour, Wikipedia](https://en.wikipedia.org/wiki/Watt-hour) - [Joule, Wikipedia](https://en.wikipedia.org/wiki/Joule) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Resistors in Series and Parallel > Resistors in a line add up, and resistors side by side always give a total smaller than the smallest one. Page: https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ R_{\text{series}} = R_1 + R_2 + \cdots + R_n \qquad \frac{1}{R_{\text{parallel}}} = \frac{1}{R_1} + \frac{1}{R_2} + \cdots + \frac{1}{R_n} $$ Read it out loud: "R series equals R 1 plus R 2 plus all the way to R n. One over R parallel equals one over R 1 plus one over R 2 plus all the way to one over R n." ## What each symbol means - $R_1$: The resistance of the first resistor, in ohms ($\Omega$). - $R_2$: The resistance of the second resistor, in ohms ($\Omega$). - $R_n$: The resistance of the last resistor in the group, in ohms ($\Omega$). The number $n$ counts how many resistors there are. - $R_{\text{series}}$: The total resistance when the resistors are in series, in ohms ($\Omega$). - $R_{\text{parallel}}$: The total resistance when the resistors are in parallel, in ohms ($\Omega$). ## What the formula is doing A resistor limits current. When several resistors are wired together, you can replace the whole group with one equivalent resistor that behaves the same way. There are two basic ways to connect them: in **series** and in **parallel**. In **series**, the resistors sit one after another on a single path, so the same current flows through each one. Their resistances add: $R_{\text{series}} = R_1 + R_2 + \cdots + R_n$. Two 100 ohm resistors in series act like one 200 ohm resistor. Adding any resistor in series always increases the total. In **parallel**, the resistors share the same two connection points, so each one has the same voltage across it and the current splits between them. Use the reciprocals instead of the values: $\frac{1}{R_{\text{parallel}}} = \frac{1}{R_1} + \frac{1}{R_2} + \cdots + \frac{1}{R_n}$. The reciprocal $\frac{1}{R}$ is called the conductance, and it is measured in siemens (S). The total resistance in parallel is always smaller than the smallest resistor in the group. Each extra branch gives the current another path to flow through. Two equal resistors in parallel give half the value of one of them. For exactly two resistors there is a shortcut: $R_{\text{parallel}} = \frac{R_1 R_2}{R_1 + R_2}$, which is the same formula written as a product over a sum. ## An everyday picture Series is like people lining up for one turnstile: everyone passes through the same gate, and the waiting times add up. Parallel is like several checkout lanes in a supermarket: shoppers spread across the lanes, so the store as a whole gets through more people than one lane alone. ## Worked example: A 100 ohm and a 300 ohm resistor Two resistors, $R_1 = 100\ \Omega$ and $R_2 = 300\ \Omega$, are used first in series and then in parallel. Find the total resistance in each case. 1. Series: $R_{\text{series}} = 100\ \Omega + 300\ \Omega = 400\ \Omega$. 2. Parallel, add the reciprocals: $\frac{1}{R_{\text{parallel}}} = \frac{1}{100} + \frac{1}{300} = \frac{3}{300} + \frac{1}{300} = \frac{4}{300}$. 3. Flip the fraction to get the resistance: $R_{\text{parallel}} = \frac{300}{4} = 75\ \Omega$. 4. Check the shortcut: $\frac{100 \times 300}{100 + 300} = \frac{30000}{400} = 75\ \Omega$, the same answer. **Answer:** In series the total is **400 ohm**. In parallel the total is **75 ohm**, which is smaller than the smallest resistor, 100 ohm. The parallel path gives the current a second route, so the total drops. ## Common mistakes - Adding resistors in parallel as if they were in series. 100 ohm and 300 ohm in parallel give 75 ohm, not 400 ohm. - Stopping after adding the reciprocals. The sum is $1/R$, not $R$. For 100 ohm and 300 ohm it is 0.0133 per ohm, and the answer is its reciprocal, 75 ohm. - Expecting a parallel total bigger than the smallest resistor. It can never be bigger, because each new branch only adds a path for current. - Using the two-resistor shortcut for three or more resistors. The product-over-sum form works only for two; for more, add the reciprocals. ## Where you will meet it - Voltage dividers, where two resistors in series share a supply voltage to give a smaller voltage for a sensor or an input pin. - Household wiring, where outlets and appliances are connected in parallel so that each one gets the full mains voltage. - Circuit analysis, where a group of resistors is replaced by one equivalent resistor to make the rest of the calculation simpler. - Meter design, where extra resistors in series or a low-resistance shunt in parallel set the range of a measuring instrument. ## Questions people ask ### How do I know whether two resistors are in series or in parallel? Trace the current path. If there is only one route through both resistors, they are in series. If both share the same two connection points, they are in parallel. ### Why is the parallel total always smaller? The current has more than one way to go. More paths mean less opposition overall, so the total resistance drops below the smallest branch. ### Can I use the shortcut $\frac{R_1 R_2}{R_1 + R_2}$ for three resistors? No. For three or more, add the reciprocals: $\frac{1}{R} = \frac{1}{R_1} + \frac{1}{R_2} + \frac{1}{R_3}$, then flip the total. ### Do capacitors follow the same rules? No, the rules are reversed. Capacitances add in parallel, while in series you add the reciprocals, as you do for resistors in parallel. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) - [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/) ## Sources - [Series and parallel circuits, Wikipedia](https://en.wikipedia.org/wiki/Series_and_parallel_circuits) - [Electrical resistance and conductance, Wikipedia](https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance) - [Electrical network, Wikipedia](https://en.wikipedia.org/wiki/Electrical_network) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Kirchhoff's Current Law > Kirchhoff's current law says that whatever electricity flows into a junction has to flow out again, because nothing piles up there. Page: https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \sum I_{\text{in}} = \sum I_{\text{out}} $$ Read it out loud: "The sum of the currents into a junction equals the sum of the currents out of it." ## What each symbol means - $\sum$: The sum sign: add up every term of the kind that follows, for every wire that touches the junction. - $I_{\text{in}}$: A current flowing **into** the junction, measured in amperes (A). - $I_{\text{out}}$: A current flowing **out of** the junction, measured in amperes (A). - $I$: Any current in a wire, which is the flow of charge through that wire, measured in amperes (A). One ampere is one coulomb of charge per second. ## What the formula is doing A **junction**, also called a node, is a point where three or more wires meet. Charge does not pile up at a junction, so whatever flows in must flow out again. This is the conservation of charge, and Kirchhoff's current law (often shortened to KCL) is the rule that applies it to every junction. Current $I$ is the flow of charge, in amperes (A). If 5 A flows into a junction, the currents leaving it must add up to 5 A. The formula writes that balance as the sum of the currents in, $\sum I_{\text{in}}$, equal to the sum of the currents out, $\sum I_{\text{out}}$. Some people prefer one sign convention. Choose a direction for each current, count the currents going in as positive and the currents going out as negative, and the total is zero: $\sum I = 0$. Both versions give the same answer, so use whichever is easier to read. KCL does not say how the current divides between the branches. For that you also need the resistance of each branch and Ohm's law. KCL only says that the total must balance at every junction. ## An everyday picture Think of a road junction. If 500 cars per hour come in from the north road, then the cars leaving by the east and south roads must also add up to 500 per hour, assuming no car parks or disappears on the way. A tee in a water pipe works the same way: the water that enters the tee has to leave through its outlets. ## Worked example: A junction with 5 A in, then a three-way split Step 1: 5 A flows into a junction on one wire, and 2 A leaves on a second wire. The current on the third wire, $I_3$, is unknown. Step 2: 10 A flows into a second junction and splits into three branches carrying 3 A and 4 A, and an unknown current $I_3$. 1. Step 1: write the balance. $5\ \text{A} = 2\ \text{A} + I_3$. 2. Solve for the unknown: $I_3 = 5\ \text{A} - 2\ \text{A} = 3\ \text{A}$. 3. Step 2: write the balance. $10\ \text{A} = 3\ \text{A} + 4\ \text{A} + I_3$. 4. Solve for the unknown: $I_3 = 10\ \text{A} - 3\ \text{A} - 4\ \text{A} = 3\ \text{A}$. 5. Check: the three outgoing currents add up to $3\ \text{A} + 4\ \text{A} + 3\ \text{A} = 10\ \text{A}$, which equals the 10 A that came in. **Answer:** In step 1 the unknown wire carries **3 A**. In step 2 the third branch also carries **3 A**, so the three branches share the 10 A exactly. Charge is conserved at both junctions. ## Common mistakes - Forgetting a wire. A junction with three branches has three currents, not two. Count every wire that touches the junction before you write the balance. - Thinking the current gets used up at a junction. Charge is not consumed there; the total current in always equals the total current out. - Using KCL to find voltages or resistances. KCL only balances currents at a junction; use Ohm's law for the voltage across a part. - Assigning a current direction and then forgetting it. A negative answer means the current flows opposite to the direction you chose, so keep the signs consistent. ## Where you will meet it - Circuit analysis of printed circuit boards, where every junction has to balance its currents. - Electrical power grids, where the currents at each substation must match the flows on the lines that connect to it. - Nodal analysis, a standard method for solving circuits with many branches, which is built on KCL. - Water and gas pipe networks, which use the same conservation idea for the flow at each junction. ## Questions people ask ### Does current get used up at a junction? No. The current leaving a junction equals the current entering it. What the circuit does with the energy is a different question, and it is answered by the resistors and the voltages. ### What is a node in a circuit? A node is a point where wires meet. Some textbooks use node for any connection point, and KCL is written for each node. ### Is Kirchhoff's current law the same as Ohm's law? No. Ohm's law links voltage, current and resistance inside one part. Kirchhoff's current law balances the current at a junction. Most circuit problems use both rules. ### Why do some currents come out negative? If you use signs, you pick a direction for each current first. A current that comes out negative flows opposite to the direction you picked. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) - [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/) ## Sources - [Kirchhoff's circuit laws, Wikipedia](https://en.wikipedia.org/wiki/Kirchhoff%27s_circuit_laws) - [Electrical network, Wikipedia](https://en.wikipedia.org/wiki/Electrical_network) - [Electric current, Wikipedia](https://en.wikipedia.org/wiki/Electric_current) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # RC Time Constant > The RC time constant tells you how long a capacitor takes to fill up through a resistor: multiply the resistance by the capacitance. Page: https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \tau = R C $$ Read it out loud: "Tau equals R times C. The time constant equals resistance times capacitance." ## What each symbol means - $\tau$: The **time constant** (the Greek letter tau), measured in seconds (s). It sets how fast the capacitor charges or discharges. - $R$: **Resistance** of the resistor in the circuit, measured in ohms ($\Omega$). - $C$: **Capacitance**, how much charge the capacitor holds for each volt, measured in farads (F). A microfarad is $10^{-6}$ F. ## What the formula is doing A capacitor stores electric charge, a bit like a small reservoir. When a capacitor is connected through a resistor to a battery, it does not fill up at once. The resistor limits how fast charge can flow in, so the voltage across the capacitor rises gradually. The product $\tau = R C$ is the time constant, in seconds. Ohms times farads give seconds, because $\Omega \cdot \text{F} = \text{s}$. After one time constant the capacitor voltage has reached about 63.2% of the supply voltage. The charging curve is $V_C(t) = V_s \left(1 - e^{-t/\tau}\right)$, where $V_C(t)$ is the capacitor voltage at time $t$, $V_s$ is the supply voltage and $e$ is Euler's number, about 2.718. The curve is steep at the start and flattens out as it nears the supply voltage. After about five time constants the capacitor is more than 99% charged, which is why five time constants is a common rule of thumb for full charge. Bigger numbers mean slower charging. A larger resistor limits the current more, and a larger capacitor holds more charge and takes longer to fill. Doubling either $R$ or $C$ doubles $\tau$. ## An everyday picture Think of filling a bucket through a hose. The resistor is the hose: a narrower hose fills the bucket more slowly. The capacitor is the bucket: a bigger bucket takes longer to fill. The time constant is the time it takes the water level to rise most of the way up. ## Worked example: Charging a 100 microfarad capacitor through 10 kiloohm A 5 V supply charges a capacitor with $C = 100\ \mu\text{F}$ through a resistor with $R = 10\ \text{k}\Omega$, which is 10 000 ohm. Find the time constant, then the capacitor voltage after 1 s and after 5 s. 1. Time constant: $\tau = R C = 10 \times 10^{3}\ \Omega \times 100 \times 10^{-6}\ \text{F} = 1\ \text{s}$. 2. Fraction charged after 1 s: $1 - e^{-1} \approx 1 - 0.3679 = 0.632$, so 63.2%. 3. Voltage after 1 s: $V_C(1\ \text{s}) = 5\ \text{V} \times 0.632 \approx 3.16\ \text{V}$. 4. Fraction charged after 5 s: $1 - e^{-5} \approx 1 - 0.0067 = 0.993$, so 99.3%. 5. Voltage after 5 s: $V_C(5\ \text{s}) = 5\ \text{V} \times 0.993 \approx 4.97\ \text{V}$. **Answer:** The time constant is **1 s**. After 1 s the capacitor is at **3.16 V**, which is 63.2% of 5 V. After 5 s it is at **4.97 V**, which is 99.3% of the supply, so it is almost fully charged. ## Common mistakes - Forgetting the prefixes. 100 microfarad is $100 \times 10^{-6}$ F, and 10 kiloohm is 10 000 ohm. Skipping either one changes the answer by a factor of a thousand or a million. - Thinking the capacitor is full after one time constant. After one $\tau$ it is only at about 63.2%, and it takes about five $\tau$ to get above 99%. - Using the supply voltage for the capacitor voltage at every moment. The capacitor starts at 0 V and only reaches the supply voltage after a long time. - Using $\tau = R C$ with the capacitance in farads and the resistance in kiloohms without converting. Convert to ohms and farads first, or the time comes out in the wrong scale. ## Where you will meet it - Simple timing circuits, such as the delay in a blinking LED circuit or a short timed switch. - Power supply smoothing and audio filters, where a resistor and capacitor set the frequency at which the signal starts to be cut. - Button debouncing, where the slow charging of a capacitor smooths out the rapid switching when mechanical contacts bounce. - Sensors that measure a resistance by timing how long a capacitor takes to charge. ## Questions people ask ### What is a farad? A farad (F) is one coulomb of charge stored per volt. Real capacitors are often rated in microfarads ($\mu\text{F}$) or picofarads, because one whole farad is a very large capacitor. ### When is the capacitor fully charged? Not after one time constant. After about five time constants it is more than 99% charged, which is the usual rule of thumb for fully charged. ### Does the capacitor discharge with the same time constant? Yes. Its voltage falls as $V_C(t) = V_0 e^{-t/\tau}$, and after one time constant it has dropped to about 36.8% of its starting voltage. ### Why does the formula have an e in it? The charging speed is proportional to how much voltage is still missing. A rule like that gives an exponential curve, and $e$ is the natural base for exponential curves. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) ## Sources - [RC circuit, Wikipedia](https://en.wikipedia.org/wiki/RC_circuit) - [Capacitor, Wikipedia](https://en.wikipedia.org/wiki/Capacitor) - [Exponential decay, Wikipedia](https://en.wikipedia.org/wiki/Exponential_decay) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Coulomb's Law > Coulomb's law tells you how hard two electric charges push or pull each other, and the force gets weaker fast as they move apart. Page: https://formulabro.yunusemrevurgun.com/electricity/coulombs-law/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ F = k_e \frac{|q_1 q_2|}{r^2} $$ Read it out loud: "F equals k sub e times the size of q 1 times q 2, divided by r squared." ## What each symbol means - $F$: **Force** between the two charges, measured in newtons (N). The size is given by the formula; the sign of the charges gives the direction. - $k_e$: The **Coulomb constant**, $k_e = 8.9875517923 \times 10^{9}\ \text{N}\,\text{m}^2/\text{C}^2$. It sets the strength of the electric force in SI units. - $q_1$: The charge on the first object, measured in coulombs (C). - $q_2$: The charge on the second object, measured in coulombs (C). - $r$: The distance between the two charges, measured in meters (m). ## What the formula is doing Electric charge comes in two kinds, positive and negative. Charges of the same sign push each other apart, and charges of opposite sign pull each other together. Coulomb's law gives the size of that push or pull for two point charges. The force $F$ is measured in newtons (N). Its size depends on the product of the two charges, $|q_1 q_2|$, where the charges are in coulombs (C). The bars around the product mean we use only its size, so the signs do not change the number. The signs decide the direction: repulsion for like charges, attraction for unlike charges. Double one charge and the force doubles. The force falls off with the square of the distance $r$, in meters (m). Double the distance and the force becomes one quarter of its old value. Triple the distance and it becomes one ninth. This pattern is called an inverse-square law. The constant $k_e = 8.9875517923 \times 10^{9}\ \text{N}\,\text{m}^2/\text{C}^2$ sets the units and the strength. Gravity has the same shape, with masses in place of charges, but gravity only pulls. Coulomb's law can push or pull, and between two protons the electric force is far stronger than gravity. ## An everyday picture Think of a flashlight shining on a wall. The farther the wall is, the wider the same light is spread over it. A point charge sends its influence out in every direction, over the surface of a growing sphere. A sphere's surface grows with the square of its radius, so at twice the distance the same influence is spread over four times the area, and the force is one quarter. ## Worked example: Two 1 microcoulomb charges 10 cm apart Two positive point charges, each with $q = 1\ \mu\text{C}$ (which is $1 \times 10^{-6}$ C), sit 10 cm apart. Find the force between them, then the force when they are moved to 20 cm apart. 1. Convert the distance: $r = 10\ \text{cm} = 0.10\ \text{m}$, so $r^2 = 0.01\ \text{m}^2$. 2. Multiply the charges: $|q_1 q_2| = (1 \times 10^{-6}\ \text{C})(1 \times 10^{-6}\ \text{C}) = 1 \times 10^{-12}\ \text{C}^2$. 3. Plug into the formula: $F = 8.9875517923 \times 10^{9} \times \frac{10^{-12}}{0.01} \approx 0.899\ \text{N}$. 4. At 20 cm, $r^2 = 0.04\ \text{m}^2$ is four times bigger, so the force is one quarter: $F = \frac{0.899\ \text{N}}{4} \approx 0.225\ \text{N}$. **Answer:** At 10 cm the two charges push each other apart with a force of about **0.899 N**. Like charges repel, so this force is repulsive. At 20 cm the force is about **0.225 N**, one quarter of the first. ## Common mistakes - Forgetting to convert centimeters to meters. Using 10 instead of 0.10 m makes $r^2$ 10 000 times too big, so the force comes out 10 000 times too small. - Forgetting to square the distance. The force depends on $r^2$, not on $r$, so doubling the distance does not halve the force. - Reading the sign of the charges as part of the size. Use the size of the product for the number, then decide push or pull from the signs. - Applying the formula to large or irregular objects without care. It is exact for point charges and for spheres with evenly spread charge, measured from their centers. ## Where you will meet it - Chemistry, where the attraction between electrons and the nucleus, and between ions, helps explain how atoms bond. - Static electricity, such as a balloon sticking to a wall or hair standing up after it is rubbed. - Inkjet printing, where electric forces steer tiny charged droplets onto the paper. - Electrostatic spray painting, where charged paint droplets are drawn toward a grounded object. ## Questions people ask ### Why do like charges repel and unlike charges attract? This is the observed behavior that Coulomb's law describes. The formula gives the size of the force, and the signs of the charges give its direction. ### What is a coulomb? The SI unit of charge. A single electron carries about $1.6 \times 10^{-19}$ C, so one coulomb is a very large amount of charge. ### Why is the distance squared? The force spreads out over the surface of a sphere around the charge, and a sphere's surface grows with the square of its radius. ### Is Coulomb's law the same as the law of gravity? The shape is the same, with a square of distance in the bottom. Gravity uses masses and only attracts, while Coulomb's law uses charges and can push or pull. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/) - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) ## Sources - [Coulomb's law, Wikipedia](https://en.wikipedia.org/wiki/Coulomb%27s_law) - [Coulomb constant, Wikipedia](https://en.wikipedia.org/wiki/Coulomb_constant) - [Electric charge, Wikipedia](https://en.wikipedia.org/wiki/Electric_charge) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Charge and Current > Electric current is how much charge passes a point each second, so the same charge moving faster means more current. Page: https://formulabro.yunusemrevurgun.com/electricity/charge-and-current/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ I = \frac{Q}{t} $$ Read it out loud: "I equals Q over t. Current equals charge divided by time." ## What each symbol means - $I$: **Current**, the flow of electric charge past a point, measured in amperes (A). One ampere is one coulomb of charge per second. - $Q$: **Charge**, the amount of electric charge that has moved, measured in coulombs (C). - $t$: **Time**, the length of time the charge takes to pass, measured in seconds (s). - $e$: **Elementary charge**, the size of the charge on one electron, $e = 1.602176634 \times 10^{-19}$ C. It is used to count electrons. ## What the formula is doing Electric charge $Q$ is measured in coulombs (C). Charge comes in units, and the carriers in a metal wire are electrons, each with a tiny charge. A coulomb is a very large number of electrons, about $6.24 \times 10^{18}$ of them. Current $I$ tells you how fast that charge moves past a point. You find it by dividing the charge that passed by the time it took: $I = \frac{Q}{t}$. The unit is the ampere (A), and $1\ \text{A} = 1\ \text{C/s}$. So a current of 2 A means 2 coulombs pass every second. The formula also works backward. If you know the current and the time, the charge is $Q = I t$. A wire carrying 0.5 A for 4 seconds moves $0.5 \times 4 = 2$ C of charge past any point. To count electrons, divide the charge by the charge of one electron: the number of electrons per second is $\frac{I}{e}$. A current of 1 A is about $6.24 \times 10^{18}$ electrons every second. Electrons move slowly, so the current is a steady flow of a huge number of them. ## An everyday picture Think of a turnstile at a stadium gate. Each person who passes through is one unit of charge, and the total number of people who pass is $Q$. The number of people passing per second is the current $I$. Ten people in one second is a bigger current than ten people in five seconds, even though the total count is the same. ## Worked example: How much charge flows through a wire A wire carries a steady current of 0.5 A for 4 seconds. How much charge passes any point in the wire, and how many electrons is that? 1. Find the charge with $Q = I t$: $Q = 0.5\ \text{A} \times 4\ \text{s} = 2\ \text{C}$. 2. Divide by the charge of one electron to count electrons: $N = \frac{Q}{e} = \frac{2\ \text{C}}{1.602 \times 10^{-19}\ \text{C}} \approx 1.25 \times 10^{19}$. 3. Check the other way: $I = \frac{Q}{t} = \frac{2\ \text{C}}{4\ \text{s}} = 0.5\ \text{A}$, which matches the start. **Answer:** **2 coulombs** of charge pass each point in 4 seconds. That is about **$1.25 \times 10^{19}$ electrons**, a huge number even for a small current. ## Common mistakes - Mixing up charge and current. Charge is the total that moved, in coulombs; current is the rate, in amperes. - Forgetting that milliamps are not amps. 20 mA is 0.02 A, so 20 mA for 4 s is 0.08 C, not 80 C. - Multiplying when you should divide. To find current, divide the charge by the time. Multiply only to find the charge from the current and the time. - Thinking a bigger current means electrons move faster in the wire. A bigger current can come from more electrons moving, and electrons drift very slowly. ## Where you will meet it - Rating batteries in ampere-hours (Ah) or milliampere-hours (mAh), which are amounts of charge that a battery can deliver. - Choosing fuses and circuit breakers, which are rated in amperes, the current they can carry before they cut the circuit. - Electroplating and electrolysis, where the mass of metal deposited depends on the total charge that flows. - Measuring currents with an ammeter, which reports how much charge passes per second. ## Questions people ask ### What is the difference between charge and current? Charge is an amount, measured in coulombs. Current is the rate at which charge flows, measured in amperes. One coulomb per second is one ampere. ### How many electrons is one coulomb? About $6.24 \times 10^{18}$ electrons. It is $1 / e$, where $e = 1.602176634 \times 10^{-19}$ C is the charge of one electron. ### Do electrons move as fast as the current? No. The current is a flow rate, but the electrons themselves drift slowly through the wire. See the drift velocity page for the numbers. ### Is a current of 1 A a lot? It depends on the circuit. A phone charger can supply about 1 A or more, and a small LED often uses about 0.02 A, which is 20 mA. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Drift Velocity](https://formulabro.yunusemrevurgun.com/electricity/drift-velocity/) - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) ## Sources - [Electric current, Wikipedia](https://en.wikipedia.org/wiki/Electric_current) - [Electric charge, Wikipedia](https://en.wikipedia.org/wiki/Electric_charge) - [Ampere, Wikipedia](https://en.wikipedia.org/wiki/Ampere) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Kirchhoff's Voltage Law > Kirchhoff's voltage law says that if you walk all the way around a circuit loop, the voltage gained equals the voltage lost. Page: https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-voltage-law/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \sum_{k} V_k = 0 $$ Read it out loud: "The sum over k of V sub k equals zero. Add up all the voltages around any closed loop, and the total is zero." ## What each symbol means - $\sum_{k}$: The sum sign: add up the voltage of every element $k$ that you pass on the way around the loop. - $V_k$: The voltage across element $k$, measured in volts (V). Count it as positive when you walk through a rise, such as a battery pushing you up, and negative when you walk through a drop, such as a resistor. ## What the formula is doing A **loop** is any closed path through a circuit that starts and ends at the same point. Kirchhoff's voltage law (KVL) says that the voltage changes around a loop add up to zero. Each element in the loop is a battery, a resistor or some other part, and $V_k$ is the voltage across it. Voltage is the energy given to each unit of charge as it moves between two points, measured in volts (V). A charge that goes all the way around a loop ends up back where it started. It cannot keep gaining energy from nothing, so the energy it gains must equal the energy it loses. That balance is the voltage law. To use the law, pick a direction and walk around the loop. Count a battery as a rise if you walk from its negative terminal to its positive terminal, and count it as a drop if you walk the other way. Count a resistor as a drop when you walk in the direction of the current. Then add the signed numbers. Walking the loop in the opposite direction flips every sign, but the total is still zero. KVL is most useful in a series circuit, where all the parts share one current. The voltage from the source is shared out among the resistors, and the drops must add up to the source voltage. This is the same balance that lets you find an unknown voltage when the others are known. ## An everyday picture Think of a hike around a hill that ends where it started. You climb some slopes and go down others. The total height you gained on the way up has to equal the total height you lost on the way down, because you finish at the same altitude you began. Voltage around a circuit loop works the same way. ## Worked example: Finding the voltage across a second resistor A 12 V battery drives two resistors in series. The first resistor, $R_1 = 100\ \Omega$, has a voltage drop of 4 V across it. What is the voltage drop across the second resistor, and what is its resistance? The same current flows through both resistors. 1. Walk around the single loop from the battery's negative terminal, through the battery, the two resistors and back. The battery is a rise of $+12\ \text{V}$, the first resistor is a drop of $-4\ \text{V}$ and the second resistor is a drop of $-V_2$. 2. Apply the voltage law: $12\ \text{V} - 4\ \text{V} - V_2 = 0$, so $V_2 = 8\ \text{V}$. 3. Find the current from the first resistor with Ohm's law: $I = \frac{4\ \text{V}}{100\ \Omega} = 0.04\ \text{A}$. 4. Find the second resistance: $R_2 = \frac{V_2}{I} = \frac{8\ \text{V}}{0.04\ \text{A}} = 200\ \Omega$. **Answer:** The second resistor has a drop of **8 V** and a resistance of **200 ohms**. The 12 V rise is exactly used up by the 4 V and 8 V drops, which is the voltage law at work. ## Common mistakes - Mixing up the signs. A battery and a resistor push the energy count in opposite directions, so a rise and a drop must carry opposite signs. - Forgetting one element in the loop. Every part you pass on the way around the loop has to be counted, including the second battery if there is one. - Using KVL on a path that does not close. The law only holds for a loop that returns to its starting point. - Confusing KVL with Kirchhoff's current law. KVL balances the voltages around a loop, while the current law balances the currents at a junction. ## Where you will meet it - Mesh analysis, a standard method for solving circuits with several loops, which writes one KVL equation per loop. - Checking the voltages in a battery pack, where cell voltages in series add up to the pack voltage. - Analysing power supplies and filters, where each stage takes a share of the input voltage. - Designing printed circuit boards, where engineers check that the supply voltage is shared out correctly among the parts. ## Questions people ask ### Does the direction I walk around the loop matter? The total is zero in either direction. Walking the other way flips every sign, so the result is the same. ### Is KVL the same as Ohm's law? No. Ohm's law gives the voltage across one resistor from the current and the resistance. KVL says that the voltages around a whole loop add to zero. Most circuit problems use both. ### Does KVL work when a loop has two batteries? Yes. Count each battery with its own sign, depending on which terminal you pass first, and the sum is still zero. ### Why does a loop have to add to zero? Voltage is energy per unit charge. A charge that returns to its starting point has no net change in energy, so the gains and losses must balance. ## Related formulas - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Voltage Divider](https://formulabro.yunusemrevurgun.com/electricity/voltage-divider/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) ## Sources - [Kirchhoff's circuit laws, Wikipedia](https://en.wikipedia.org/wiki/Kirchhoff%27s_circuit_laws) - [Voltage, Wikipedia](https://en.wikipedia.org/wiki/Voltage) - [Electric potential, Wikipedia](https://en.wikipedia.org/wiki/Electric_potential) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Voltage Divider > A voltage divider uses two resistors in series to take a smaller share of a supply voltage, with the share set by their ratio. Page: https://formulabro.yunusemrevurgun.com/electricity/voltage-divider/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ V_{\text{out}} = V_{\text{in}} \frac{R_2}{R_1 + R_2} $$ Read it out loud: "V out equals V in times R 2 over R 1 plus R 2. The output voltage is the input voltage times R 2 divided by the total of R 1 and R 2." ## What each symbol means - $V_{\text{out}}$: The **output voltage**, the voltage across $R_2$, measured in volts (V). - $V_{\text{in}}$: The **input voltage**, the supply voltage across both resistors together, measured in volts (V). - $R_1$: The resistance of the top resistor, between the input and the output, measured in ohms ($\Omega$). - $R_2$: The resistance of the bottom resistor, between the output and ground, measured in ohms ($\Omega$). ## What the formula is doing Two resistors connected in series form a chain. The same current flows through both, so the voltage across each one depends on its resistance. The supply voltage $V_{\text{in}}$ is shared between $R_1$ and $R_2$, and the output is the voltage across $R_2$. Because the current is the same in both resistors, the voltage across each one is proportional to its resistance. The bottom resistor takes the share $\frac{R_2}{R_1 + R_2}$ of the total. If $R_1$ and $R_2$ are equal, the output is exactly half the input. If $R_2$ is small compared with $R_1$, the output is a small fraction of the input. The divider only gives a clean output when nothing else draws current from the middle point. If you connect a **load**, such as a sensor or another resistor, from the output to ground, it sits in parallel with $R_2$. That lowers the effective resistance of the bottom half, and the output drops below the value the formula predicts. As a rule of thumb, keep the load resistance much larger than $R_2$, for example at least ten times larger, or put a buffer stage such as a voltage follower between the divider and the load. The rule of thumb is a practical guide, and the exact effect depends on the circuit. ## An everyday picture Think of a tall pole with a clip that can slide along it. The total length of the pole is the input voltage. The clip sits at a point along the pole, and the length of the lower part, as a share of the whole, is the output voltage. Move the clip and the share changes. ## Worked example: A divider that halves the voltage, then loads it A 9 V supply feeds a divider with $R_1 = 20\ \text{k}\Omega$ and $R_2 = 10\ \text{k}\Omega$. First find the output with nothing connected. Then connect a sensor that draws as if it were a $10\ \text{k}\Omega$ resistor from the output to ground, and find the new output. 1. Unloaded: $V_{\text{out}} = V_{\text{in}} \frac{R_2}{R_1 + R_2} = 9\ \text{V} \times \frac{10\ \text{k}\Omega}{20\ \text{k}\Omega + 10\ \text{k}\Omega} = 9\ \text{V} \times \frac{1}{3} = 3\ \text{V}$. 2. Loaded: the sensor sits in parallel with $R_2$, so the bottom half becomes $\frac{10 \times 10}{10 + 10} = 5\ \text{k}\Omega$. 3. Use the same formula with the new bottom resistance: $V_{\text{out}} = 9\ \text{V} \times \frac{5\ \text{k}\Omega}{20\ \text{k}\Omega + 5\ \text{k}\Omega} = 9\ \text{V} \times 0.2 = 1.8\ \text{V}$. **Answer:** With nothing connected the output is **3 V**. With the 10 k$\Omega$ sensor attached, the output falls to **1.8 V**, so the load pulled the output down by 1.2 V. ## Common mistakes - Putting the resistors in the wrong place in the formula. The output is across $R_2$, so $R_2$ goes on top of the fraction. - Forgetting the load. Any device connected to the output draws current and changes the result, often by a large amount. - Using the divider to supply a large current. A divider sets a voltage, but it wastes power and cannot supply much current without the output dropping. - Using the formula for resistors that are not in series. The formula assumes the same current flows through both resistors. ## Where you will meet it - Reading a sensor, such as a thermistor or a light-dependent resistor, with a microcontroller that measures voltage. - Setting the bias voltage at the base of a transistor in an amplifier. - A potentiometer, which is a variable divider, used as a volume control or a dial. - Scaling a high voltage down to a level that a measuring instrument can read safely. ## Questions people ask ### Why does the output go down when I connect something? The load draws current from the middle point. That current flows through $R_1$, so the voltage across $R_1$ rises and the output falls. ### Can a voltage divider power a motor or LED? Usually not well. The divider sets a voltage, but the current it can supply is small and the output moves when the load changes. A resistor in series with the LED, or a proper driver, is the better choice. ### Does the divider need a battery? It needs a voltage across the two resistors. The supply can be a battery, a power supply or a signal source. ### How do I pick the resistor values? Choose the ratio for the output you want, then pick values that are large enough to keep the wasted current small and small enough that the load does not change the output much. ## Related formulas - [Current Divider](https://formulabro.yunusemrevurgun.com/electricity/current-divider/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Kirchhoff's Voltage Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-voltage-law/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) ## Sources - [Voltage divider, Wikipedia](https://en.wikipedia.org/wiki/Voltage_divider) - [Potentiometer, Wikipedia](https://en.wikipedia.org/wiki/Potentiometer) - [Electrical load, Wikipedia](https://en.wikipedia.org/wiki/Electrical_load) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Current Divider > A current divider splits a total current between two parallel resistors, and the smaller resistor always takes the bigger share. Page: https://formulabro.yunusemrevurgun.com/electricity/current-divider/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ I_1 = I_{\text{total}} \frac{R_2}{R_1 + R_2} $$ Read it out loud: "I 1 equals I total times R 2 over R 1 plus R 2. The current in branch 1 is the total current times R 2 divided by the total of R 1 and R 2." ## What each symbol means - $I_1$: The **current through $R_1$**, the branch being found, measured in amperes (A). - $I_{\text{total}}$: The **total current** entering the pair of parallel resistors, measured in amperes (A). - $R_1$: The resistance of the first branch, measured in ohms ($\Omega$). - $R_2$: The resistance of the second branch, measured in ohms ($\Omega$). ## What the formula is doing Two resistors in parallel have the same voltage across them, because both connect the same two points. The total current splits between the two branches, and the split depends on the resistances. This is the current version of the voltage divider. Each branch current follows Ohm's law, $I = \frac{V}{R}$, with the same voltage $V$ in both. So the branch with the smaller resistance carries more current. The current through $R_1$ is $\frac{I_{\text{total}} R_2}{R_1 + R_2}$, which means the other resistor, $R_2$, appears on top. A bigger $R_2$ pushes more current into $R_1$. The formula works for two resistors only. For any number of parallel branches, the share in each branch is its conductance divided by the total conductance, where conductance is $1/R$. For two resistors, that gives the same result as the formula above. The two branch currents add up to the total, so $I_1 + I_2 = I_{\text{total}}$. You can check any answer with this sum, and the voltage across the pair is $I_1 R_1$, which must equal $I_2 R_2$. ## An everyday picture Think of a river that splits around an island. Both channels start at the same point upstream and meet again downstream, so they share the same drop in height. The wide channel, like a low resistance, carries most of the water. The narrow channel carries less, and the split depends on how wide each channel is. ## Worked example: Splitting 10 mA between a 100 ohm and a 400 ohm resistor A total current of 10 mA flows into two resistors in parallel, $R_1 = 100\ \Omega$ and $R_2 = 400\ \Omega$. Find the current in each branch. 1. Convert the total current: $I_{\text{total}} = 10\ \text{mA} = 0.01\ \text{A}$. 2. Find the current through $R_1$: $I_1 = I_{\text{total}} \frac{R_2}{R_1 + R_2} = 0.01\ \text{A} \times \frac{400\ \Omega}{500\ \Omega} = 0.008\ \text{A}$. 3. Find the current through $R_2$: $I_2 = I_{\text{total}} \frac{R_1}{R_1 + R_2} = 0.01\ \text{A} \times \frac{100\ \Omega}{500\ \Omega} = 0.002\ \text{A}$. 4. Check with Ohm's law: the parallel pair is $\frac{100 \times 400}{500} = 80\ \Omega$, so the shared voltage is $0.01\ \text{A} \times 80\ \Omega = 0.8\ \text{V}$, and $0.8\ \text{V} / 100\ \Omega = 0.008\ \text{A}$ as before. **Answer:** The 100 ohm branch carries **8 mA** and the 400 ohm branch carries **2 mA**. The smaller resistor takes four times the current, and the two branches add up to the 10 mA that came in. ## Common mistakes - Swapping the resistors in the formula. The current through $R_1$ has $R_2$ on top, so a bigger $R_2$ sends more current into $R_1$. - Using the formula for resistors in series. In series the same current flows through both, so there is nothing to split. - Forgetting the total. The formula gives one branch current, so use the total current, not the current in one branch, as the starting value. - Mixing up the units. Convert milliamps to amps before you multiply, or the answer is off by a factor of 1000. ## Where you will meet it - Shunt resistors in ammeters, which send most of the current around a sensitive meter movement. - Estimating how the current from a supply divides between two parallel loads, such as two lamps or two heater elements. - Biasing transistor and op-amp circuits, where a resistor pair sets how current splits between branches. - Checking whether a parallel branch will overheat, by working out the current it carries. ## Questions people ask ### Why does the smaller resistor get more current? Both branches have the same voltage across them. By Ohm's law, the current is voltage divided by resistance, so a smaller resistance gives a larger current. ### Is the current divider the same as the voltage divider? They are mirror images. The voltage divider splits a voltage across resistors in series, while the current divider splits a current between resistors in parallel. ### Can I use the formula with three resistors? Not in this two-resistor form. Use the general rule, where the share in each branch is its conductance, $1/R$, divided by the total of all the conductances. ### What if one branch is a short circuit? A resistance of zero takes all the current, so the other branch gets none. The formula gives this result when you put $R_1 = 0$. ## Related formulas - [Voltage Divider](https://formulabro.yunusemrevurgun.com/electricity/voltage-divider/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) ## Sources - [Current divider, Wikipedia](https://en.wikipedia.org/wiki/Current_divider) - [Ammeter, Wikipedia](https://en.wikipedia.org/wiki/Ammeter) - [Series and parallel circuits, Wikipedia](https://en.wikipedia.org/wiki/Series_and_parallel_circuits) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Resistivity > A wire's resistance grows with its length, shrinks with its thickness, and depends on what the wire is made of. Page: https://formulabro.yunusemrevurgun.com/electricity/resistivity/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ R = \rho \frac{L}{A} $$ Read it out loud: "R equals rho times L over A. Resistance equals resistivity times length divided by cross-sectional area." ## What each symbol means - $R$: **Resistance** of the wire, measured in ohms ($\Omega$). - $\rho$: **Resistivity**, a property of the material, measured in ohm metres ($\Omega\ \text{m}$). Copper at 20 $^\circ$C is about $1.68 \times 10^{-8}\ \Omega\ \text{m}$. - $L$: **Length** of the wire along the direction of the current, measured in metres (m). - $A$: **Cross-sectional area**, the area of a slice through the wire, measured in square metres (m$^2$). For a round wire, $A = \pi r^2$ where $r$ is the radius. ## What the formula is doing The resistance of a wire depends on three things: the material it is made of, how long it is and how thick it is. The formula $R = \rho \frac{L}{A}$ puts those three together. Resistance is in ohms ($\Omega$), and the quantity $\rho$ is the resistivity of the material. Resistivity $\rho$ belongs to the material, not to the wire. Copper, silver and aluminum each have their own value, and a poor conductor has a large one. Its unit is the ohm metre ($\Omega\ \text{m}$). Copper's value of about $1.68 \times 10^{-8}\ \Omega\ \text{m}$ at 20 $^\circ$C is small, which is why copper is used for most household wiring. Length and area work in opposite ways. Double the length and the resistance doubles, because the current has to push through twice as much material. Double the cross-sectional area and the resistance halves, because there is twice as much room for the current to flow. The formula assumes the material is the same all the way along, and that the current flows evenly through the cross section. It also assumes a fixed temperature, because resistivity changes with temperature. The next pages on temperature and drift velocity cover those effects. ## An everyday picture Think of a garden hose. A long hose makes the water work harder to get through, and a thin hose lets less water through for the same pressure. Changing the hose material, such as rubber versus steel, changes how easily water moves through it, even at the same length and width. ## Worked example: Resistance of a 10 m copper wire A copper wire is 10 m long and has a diameter of 1.0 mm, so its radius is 0.5 mm. Copper has a resistivity of $1.68 \times 10^{-8}\ \Omega\ \text{m}$ at 20 $^\circ$C. What is the resistance of the wire? 1. Convert the radius to metres: $r = 0.5\ \text{mm} = 0.0005\ \text{m}$. 2. Find the cross-sectional area: $A = \pi r^2 = \pi \times (0.0005\ \text{m})^2 \approx 7.85 \times 10^{-7}\ \text{m}^2$. 3. Apply the formula: $R = \rho \frac{L}{A} = 1.68 \times 10^{-8}\ \Omega\ \text{m} \times \frac{10\ \text{m}}{7.85 \times 10^{-7}\ \text{m}^2} \approx 0.214\ \Omega$. **Answer:** The wire has a resistance of about **0.214 ohms**. Doubling its length would double this to about 0.43 ohms, and doubling its diameter would cut it to about 0.053 ohms. ## Common mistakes - Using the diameter where the radius belongs. The area is $\pi r^2$, so a 1.0 mm diameter means $r = 0.5$ mm, not 1.0 mm. - Mixing units. Resistivity uses metres, so convert the length and the diameter to metres before you divide. - Confusing resistivity with conductivity. Conductivity is the reciprocal, $1/\rho$, so a good conductor has a small resistivity. - Forgetting that the value of $\rho$ depends on temperature. The table values are quoted at a stated temperature, usually 20 $^\circ$C. ## Where you will meet it - Choosing the wire gauge for house wiring, so the cable does not heat up or lose too much voltage over its length. - Designing heating elements, which use alloys with high resistivity, such as nichrome, so they warm up when current flows. - Building strain gauges, where stretching a thin wire makes it longer and thinner, and its resistance changes in a measurable way. - Designing thin-film and integrated resistors, where the length and width of a strip set its resistance. ## Questions people ask ### What is the unit of resistivity? The ohm metre, written $\Omega\ \text{m}$. Multiplying it by a length in metres and dividing by an area in square metres gives ohms. ### Why is the length on top and the area on the bottom? A longer wire has more material for the current to push through, so resistance goes up. A bigger area gives the current more room, so resistance goes down. ### Is copper the best conductor? Silver has a lower resistivity than copper, but it costs much more. Copper is an excellent conductor and is cheap enough for most wiring. ### Does the formula work for any shape of conductor? It works best for a uniform wire with a constant cross section. For a shape that changes along its length, you add up small slices, each with its own area. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Temperature Coefficient of Resistance](https://formulabro.yunusemrevurgun.com/electricity/temperature-coefficient-of-resistance/) - [Drift Velocity](https://formulabro.yunusemrevurgun.com/electricity/drift-velocity/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) ## Sources - [Electrical resistivity and conductivity, Wikipedia](https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity) - [Electrical resistance and conductance, Wikipedia](https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance) - [Copper, Wikipedia](https://en.wikipedia.org/wiki/Copper) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Temperature Coefficient of Resistance > Most metals get harder to push current through as they get hotter, and this formula estimates how much the resistance rises. Page: https://formulabro.yunusemrevurgun.com/electricity/temperature-coefficient-of-resistance/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ R = R_0\left[1 + \alpha (T - T_0)\right] $$ Read it out loud: "R equals R zero times the quantity one plus alpha times the quantity T minus T zero. Resistance at a temperature equals the reference resistance times one plus the coefficient times the temperature change." ## What each symbol means - $R$: **Resistance** at the new temperature $T$, measured in ohms ($\Omega$). - $R_0$: **Reference resistance**, the resistance measured at the reference temperature $T_0$, in ohms ($\Omega$). - $\alpha$: **Temperature coefficient of resistance**, how fast the resistance changes per degree, in per degree Celsius (1/$^\circ$C). Copper near 20 $^\circ$C is about $0.00393$ per $^\circ$C. - $T$: The **new temperature**, measured in degrees Celsius ($^\circ$C). - $T_0$: The **reference temperature** where $R_0$ was measured, usually 20 $^\circ$C, in degrees Celsius ($^\circ$C). ## What the formula is doing Metals are made of atoms in a regular pattern, and electrons carry the current through that pattern. When a metal is hot, its atoms vibrate more. The electrons bump into them more often, so the metal's resistance goes up. The formula estimates that rise with a straight-line rule. The formula uses the temperature change $T - T_0$, measured from a reference point. The coefficient $\alpha$ says how big the change is for each degree. For copper near 20 $^\circ$C, $\alpha$ is about 0.00393 per $^\circ$C, so the resistance rises by about 0.393% for every degree above 20 $^\circ$C. The rule is a linear approximation. It works well for modest temperature changes, such as room temperature up to about 100 $^\circ$C. Over a very large range the resistance curve bends, so the straight-line estimate becomes less accurate. The value of $\alpha$ also depends on the reference temperature, so use the value quoted for the same $T_0$. Not every material behaves this way. Carbon and many semiconductors have a negative $\alpha$, so their resistance falls as they heat up. That is why a thermistor, a resistor made from a semiconductor, can be used as a sensitive temperature sensor. ## An everyday picture Think of a crowded hallway. When the people in it are calm, they walk through with few bumps. When they get restless and start moving around more, they bump into each other more often and progress slows. Hotter metal behaves like the restless crowd, with more bumps for the electrons. ## Worked example: A copper coil heated from 20 to 70 degrees A copper coil has a resistance of 10 $\Omega$ at 20 $^\circ$C. Its temperature rises to 70 $^\circ$C. Using $\alpha = 0.00393$ per $^\circ$C, what is its resistance now? 1. Find the temperature change: $T - T_0 = 70\ ^\circ\text{C} - 20\ ^\circ\text{C} = 50\ ^\circ\text{C}$. 2. Multiply by the coefficient: $\alpha (T - T_0) = 0.00393 \times 50 = 0.1965$, which is a 19.65% rise. 3. Apply the formula: $R = R_0 [1 + 0.1965] = 10\ \Omega \times 1.1965 \approx 11.97\ \Omega$. **Answer:** At 70 $^\circ$C the coil has a resistance of about **11.97 ohms**, which is roughly 2 ohms more than at 20 $^\circ$C. The estimate is good for this range of temperatures. ## Common mistakes - Using the temperature itself instead of the change. The formula needs $T - T_0$, not $T$ on its own. - Using one $\alpha$ for every material. Each metal and each alloy has its own coefficient, and a semiconductor can have a negative one. - Using the formula far outside its range. For very large temperature changes the straight line is no longer a good estimate. - Forgetting the reference temperature. The value of $\alpha$ is quoted for a particular $T_0$, so check that it matches the data. ## Where you will meet it - Platinum resistance thermometers, which measure temperature by tracking how the resistance of a platinum wire changes. - Estimating the winding temperature of an electric motor from the change in the resistance of its copper windings. - Explaining why a tungsten filament in an old incandescent bulb has a much lower resistance when it is cold than when it is glowing. - Designing temperature sensors and compensation circuits, where a known coefficient corrects a reading for heat. ## Questions people ask ### Why does the resistance go up when a metal gets hot? The atoms vibrate more at high temperature. The moving electrons collide with them more often, and each collision slows the flow of current. ### What is the unit of alpha? Per degree Celsius, written 1/$^\circ$C. A change of one degree is the same size in kelvin, so the same number works in kelvin. ### Does a thermistor follow this formula? Not in this straight-line form. Thermistors are semiconductors with a large and often negative coefficient, and their resistance changes far more steeply, so they need their own model. ### Is the formula exact? No. It is a straight-line estimate. It is accurate for small changes and becomes less accurate as the temperature moves further from $T_0$. ## Related formulas - [Resistivity](https://formulabro.yunusemrevurgun.com/electricity/resistivity/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) ## Sources - [Temperature coefficient, Wikipedia](https://en.wikipedia.org/wiki/Temperature_coefficient) - [Electrical resistivity and conductivity, Wikipedia](https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity) - [Resistance thermometer, Wikipedia](https://en.wikipedia.org/wiki/Resistance_thermometer) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Drift Velocity > Electrons in a copper wire drift along at a fraction of a millimetre per second, even though the electric signal races along the wire. Page: https://formulabro.yunusemrevurgun.com/electricity/drift-velocity/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ v_d = \frac{I}{n q A} $$ Read it out loud: "v d equals I over n times q times A. Drift velocity equals current divided by the carrier density times the charge per carrier times the cross-sectional area." ## What each symbol means - $v_d$: **Drift velocity**, the average speed the charge carriers move along the wire, in metres per second (m/s). - $I$: **Current** through the wire, measured in amperes (A). - $n$: **Carrier density**, the number of free charge carriers per unit volume, in per cubic metre (m$^{-3}$). Copper has about $8.5 \times 10^{28}$ free electrons per m$^3$. - $q$: **Charge per carrier**, measured in coulombs (C). For electrons its size is $e = 1.602176634 \times 10^{-19}$ C. - $A$: **Cross-sectional area** of the wire, measured in square metres (m$^2$). ## What the formula is doing Current is the amount of charge that passes a point each second. Inside a copper wire, that charge is carried by free electrons. The formula $v_d = \frac{I}{n q A}$ gives the average speed at which those electrons drift along the wire in one direction. This speed is called the drift velocity. The formula has three parts that set the speed. A bigger current pushes the speed up. More carriers per cubic metre, $n$, spread the same charge over more electrons, so each one moves more slowly. A wider wire, with a bigger area $A$, gives the carriers more room, so again each one moves more slowly. The charge per carrier, $q$, is the size of the electron's charge. Electrons in a metal move in every direction at high speed, far faster than the drift speed. Their random motion cancels out, so the net flow is only the slow drift. The drift is what carries the current. The signal that tells a circuit to switch on travels through the electric field along the wire, at a large fraction of the speed of light. The drift speed is small for ordinary currents. In a typical household wire it is well under a millimetre per second, so the electrons take a long time to move even a metre. The current is still large, because the number of electrons is huge. ## An everyday picture Think of a packed hallway where people shuffle forward. The current is the number of people who pass a doorway each second. If the hallway is very crowded, each person can only move a tiny step at a time. The people push forward slowly, but a long line of people still delivers a steady flow at the far end. ## Worked example: How fast electrons move in a 1 A copper wire A copper wire with a diameter of 1.0 mm carries a steady current of 1 A. Copper has about $8.5 \times 10^{28}$ free electrons per m$^3$. Find the drift velocity, and how long the electrons would take to move 1 m. 1. Find the cross-sectional area from the radius, 0.5 mm: $A = \pi (0.0005\ \text{m})^2 \approx 7.85 \times 10^{-7}\ \text{m}^2$. 2. Find the product $n q A = 8.5 \times 10^{28}\ \text{m}^{-3} \times 1.602 \times 10^{-19}\ \text{C} \times 7.85 \times 10^{-7}\ \text{m}^2 \approx 1.07 \times 10^{4}\ \text{C/m}$. 3. Apply the formula: $v_d = \frac{1\ \text{A}}{1.07 \times 10^{4}\ \text{C/m}} \approx 9.35 \times 10^{-5}\ \text{m/s}$, which is about 0.09 mm/s. 4. Time to move 1 m: $\frac{1\ \text{m}}{9.35 \times 10^{-5}\ \text{m/s}} \approx 10\,700\ \text{s}$, which is about 3 hours. **Answer:** The electrons drift at about **0.09 mm/s**, so one electron would take roughly **3 hours** to move 1 m. The electrical signal still reaches the far end of the wire almost instantly on the scale of human experience. ## Common mistakes - Thinking the electrons move at the speed of the current or at the speed of the signal. The drift is slow, and the signal is fast. - Mixing up the units of $n$. Copper's density is about $8.5 \times 10^{28}$ per m$^3$, which is $8.5 \times 10^{22}$ per cm$^3$. Using the cm$^3$ number in an m$^3$ formula makes the answer a million times too large. - Using the diameter as the radius when finding the area. The area is $\pi r^2$, so convert the diameter to a radius first. - Assuming the formula gives the speed of random motion. The electrons move randomly at much higher speeds, and only the small net drift makes the current. ## Where you will meet it - Explaining why a light switch turns a lamp on at once even though the electrons in the wire move slowly. - The Hall effect, where measuring a small voltage across a conductor in a magnetic field gives the carrier density $n$ and the carrier type. - Checking the current density, $I/A$, in wire design, which is the number that limits how hot a conductor can get. - Modelling conduction in semiconductors, where electrons and holes each have their own density and drift speed. ## Questions people ask ### How fast do electrons move in a wire? Usually a fraction of a millimetre per second for ordinary currents. The exact value depends on the current, the wire size and the material. ### If electrons are so slow, why does a light turn on instantly? The electric field that drives the electrons travels along the wire at a large fraction of the speed of light. Every electron starts moving almost at once, even though each one moves only a tiny distance. ### Does drift velocity depend on the length of the wire? No. The formula has no length in it. A longer wire needs a longer time for the drift to cover the distance, but the drift speed is the same. ### Why is the formula written with q and not e? The letter $q$ stands for the charge of the carrier. For electrons in a metal $q$ equals $e$ in size, but for other carriers, such as holes in a semiconductor, the charge can differ. ## Related formulas - [Charge and Current](https://formulabro.yunusemrevurgun.com/electricity/charge-and-current/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Resistivity](https://formulabro.yunusemrevurgun.com/electricity/resistivity/) - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) ## Sources - [Drift velocity, Wikipedia](https://en.wikipedia.org/wiki/Drift_velocity) - [Electric current, Wikipedia](https://en.wikipedia.org/wiki/Electric_current) - [Hall effect, Wikipedia](https://en.wikipedia.org/wiki/Hall_effect) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Internal Resistance > A real battery has a small resistance inside it, so its output voltage drops when it pushes a current through a load. Page: https://formulabro.yunusemrevurgun.com/electricity/internal-resistance/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ V = \varepsilon - I r $$ Read it out loud: "V equals epsilon minus I r. The terminal voltage equals the emf minus the current times the internal resistance." ## What each symbol means - $V$: **Terminal voltage**, the voltage across the battery's output terminals while it supplies current, measured in volts (V). - $\varepsilon$: **Electromotive force (emf)**, the voltage of the battery when no current flows, measured in volts (V). - $I$: **Current** the battery supplies to the circuit, measured in amperes (A). - $r$: **Internal resistance** of the battery, the resistance inside the cell itself, measured in ohms ($\Omega$). ## What the formula is doing An ideal battery would hold its voltage at $\varepsilon$ no matter how much current you drew. A real battery is not ideal. It has a small resistance $r$ inside it, made of the electrolyte, the electrodes and the connections. This resistance is called the internal resistance. When current $I$ flows out of the battery, it also flows through $r$. By Ohm's law, that causes a voltage drop of $I r$ inside the battery. The voltage left at the terminals is therefore $V = \varepsilon - I r$. The more current you draw, the lower the terminal voltage. With no current flowing, the drop is zero, so the terminal voltage equals the emf. This is why a voltmeter across a battery that is not connected to anything reads close to its full rating. Under a heavy load, the same battery can read noticeably lower. The emf is the energy the battery gives to each coulomb of charge, measured in volts. It is not a force, even though the name suggests one. Internal resistance grows as a battery ages, so an old battery sags more under the same load, and the current through $r$ also turns some energy into heat inside the cell. ## An everyday picture Think of a tank of water with a pump that pushes water out through a pipe. The pump gives the water its push, which is the emf. When the water flows fast, some of that push is used up forcing the water through a narrow outlet inside the tank. The pressure you measure at the tap is lower than the pump's full push, and the faster the flow, the bigger the loss. ## Worked example: A 9 V battery with internal resistance driving a load A battery has an emf of 9 V and an internal resistance of 0.5 $\Omega$. It drives a load resistor of 4.5 $\Omega$. Find the current, the terminal voltage and the power that turns into heat inside the battery. 1. Find the total resistance in the circuit: $R + r = 4.5\ \Omega + 0.5\ \Omega = 5\ \Omega$. The current is $I = \frac{\varepsilon}{R + r} = \frac{9\ \text{V}}{5\ \Omega} = 1.8\ \text{A}$. 2. Find the terminal voltage: $V = \varepsilon - I r = 9\ \text{V} - 1.8\ \text{A} \times 0.5\ \Omega = 9\ \text{V} - 0.9\ \text{V} = 8.1\ \text{V}$. 3. Check with the load: $V = I R = 1.8\ \text{A} \times 4.5\ \Omega = 8.1\ \text{V}$, which matches. 4. Find the power inside the battery: $P = I^2 r = (1.8\ \text{A})^2 \times 0.5\ \Omega = 1.62\ \text{W}$. **Answer:** The battery supplies **1.8 A** and its terminal voltage falls to **8.1 V**, which is 0.9 V below the emf. About **1.62 W** is lost as heat inside the battery itself. ## Common mistakes - Using the emf as the voltage you measure under load. Under load the terminal voltage is lower by $I r$. - Forgetting that the internal resistance is in series with the load. Both resistances share the same current, so add them together for the total. - Thinking a short circuit draws an infinite current. A real battery is limited by $r$, so the short-circuit current is $\varepsilon / r$, which is large but finite. - Assuming a battery's label voltage is always what it delivers. Under heavy load the output can sag well below the label. ## Where you will meet it - Testing a battery's health by measuring its voltage under a known load. A large sag points to high internal resistance. - Car starter batteries, which sag noticeably while the starter motor draws a large current. - Designing power supplies and battery packs, where the output resistance sets how much the voltage drops with load. - Estimating the heating in a battery that delivers high current, which is $I^2 r$ inside the cell. ## Questions people ask ### Why does my battery read a full voltage on a meter but drop when it runs a device? The meter draws almost no current, so there is almost no drop across the internal resistance. When the device draws current, the drop $I r$ pulls the terminal voltage down. ### Is internal resistance the same as a resistor in the circuit? It is a resistance, so it behaves the same way in Ohm's law, but it sits inside the battery and is not a part you add. You cannot remove it. ### What is emf? The electromotive force is the energy the source gives each coulomb of charge, measured in volts. It is the battery's voltage with no current flowing. ### Does internal resistance make a battery hot? Yes, a little. The current through $r$ turns $I^2 r$ watts into heat inside the cell, and this is more noticeable at high currents. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Maximum Power Transfer](https://formulabro.yunusemrevurgun.com/electricity/maximum-power-transfer/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [Kirchhoff's Voltage Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-voltage-law/) ## Sources - [Electromotive force, Wikipedia](https://en.wikipedia.org/wiki/Electromotive_force) - [Battery (electricity), Wikipedia](https://en.wikipedia.org/wiki/Battery_(electricity)) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Maximum Power Transfer > A load receives the most power when its resistance matches the source's resistance, but then half the power is lost inside the source. Page: https://formulabro.yunusemrevurgun.com/electricity/maximum-power-transfer/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ R_L = R_S \qquad P_{\max} = \frac{V_S^2}{4 R_S} $$ Read it out loud: "R L equals R S. The maximum power equals V S squared over 4 times R S." ## What each symbol means - $R_L$: The **load resistance**, the resistance of the device that receives the power, measured in ohms ($\Omega$). - $R_S$: The **source resistance**, the resistance inside the source, such as a battery's internal resistance, measured in ohms ($\Omega$). - $V_S$: The **source voltage**, the open-circuit voltage of the source with no load attached, measured in volts (V). - $P_{\max}$: The **maximum power** delivered to the load, measured in watts (W). ## What the formula is doing A source with voltage $V_S$ and internal resistance $R_S$ drives a load $R_L$ in series. The current is $I = \frac{V_S}{R_S + R_L}$, and the power delivered to the load is $P_L = I^2 R_L$. Both quantities depend on how big the load is, so the power changes as you change $R_L$. If $R_L$ is very small, the current is large, but the load gets little voltage, so the power is small. If $R_L$ is very large, the load gets nearly all the voltage, but the current is tiny, so the power is again small. Between those two extremes the power peaks. Setting the derivative of $P_L$ with respect to $R_L$ to zero shows that the peak is at $R_L = R_S$. At that peak, the power in the load is $P_{\max} = \frac{V_S^2}{4 R_S}$. The source resistance also converts power into heat, and at the match it turns exactly as much power into heat inside the source as the load receives. The efficiency, the fraction of power that reaches the load, is therefore 50%. The rule answers a narrow question: how to get the most power into one load. It is not the rule for the most efficient or the most useful design. A power supply that must hold its voltage steady uses a low source resistance, because a large resistance wastes power and drops the voltage under load. ## An everyday picture Think of a water pump pushing water through a pipe. If the pipe is far too narrow, the pump pushes hard but little water flows. If the pipe is far too wide, lots of water flows but the pump has little push. The most water is delivered when the pipe's resistance matches the pump's own internal resistance, although half the pump's work goes into its own internals. ## Worked example: Choosing a load for a 12 V source with 4 ohm resistance A source has a voltage of 12 V and an internal resistance of 4 $\Omega$. Compare the power delivered to a 4 $\Omega$ load with the power delivered to an 8 $\Omega$ load. 1. Matched load, $R_L = 4\ \Omega$: the total resistance is $4 + 4 = 8\ \Omega$, so $I = \frac{12\ \text{V}}{8\ \Omega} = 1.5\ \text{A}$. The load power is $P_L = I^2 R_L = (1.5\ \text{A})^2 \times 4\ \Omega = 9\ \text{W}$. 2. Check with the formula: $P_{\max} = \frac{V_S^2}{4 R_S} = \frac{(12\ \text{V})^2}{4 \times 4\ \Omega} = \frac{144}{16} = 9\ \text{W}$. 3. Larger load, $R_L = 8\ \Omega$: the total resistance is $4 + 8 = 12\ \Omega$, so $I = \frac{12\ \text{V}}{12\ \Omega} = 1\ \text{A}$. The load power is $P_L = (1\ \text{A})^2 \times 8\ \Omega = 8\ \text{W}$. 4. Efficiency at the match: the total power is $I^2 (R_S + R_L) = (1.5\ \text{A})^2 \times 8\ \Omega = 18\ \text{W}$, so the efficiency is $\frac{9\ \text{W}}{18\ \text{W}} = 50\%$. **Answer:** The matched 4 $\Omega$ load receives the most power, **9 W**. The 8 $\Omega$ load receives only **8 W**. At the match, half of the 18 W from the source is wasted inside the source, so the efficiency is **50%**. ## Common mistakes - Thinking maximum power means maximum efficiency. At the match the efficiency is only 50%, so a design that needs efficiency uses a much smaller source resistance. - Using $V_S$ where $V_S^2$ belongs in the formula. The maximum power depends on the square of the voltage. - Forgetting the source resistance in the current. The current is set by the total of $R_S$ and $R_L$, not by $R_L$ alone. - Applying the rule to every circuit. It is about getting the most power into one load, which is different from holding a steady voltage for many loads. ## Where you will meet it - Radio and microwave links, where the transmitter and antenna are matched to a common impedance, often 50 $\Omega$, so the most power reaches the antenna. - Designing the input of a sensor or receiver, so that the most signal power reaches the amplifier stage. - Analysing how a battery with internal resistance delivers power to a load, as in the internal resistance page. - Teaching impedance matching, which is the general form of the same idea for circuits with reactance as well as resistance. ## Questions people ask ### Does maximum power transfer mean the most efficient setup? No. At the match, half the power is lost in the source, so the efficiency is 50%. A design that needs high efficiency keeps the source resistance much smaller than the load. ### Why is the efficiency exactly 50% at the match? With $R_L = R_S$, the load and the source have equal resistance, so they share the same current and drop equal amounts of the same power. Half the power ends up in each. ### Is the source resistance the same as internal resistance? For a battery, yes. The internal resistance is the source resistance in this model. The formula applies to any source that can be drawn as a voltage in series with a resistance. ### Is maximum power transfer used in power grids? Usually not. Grids are designed to deliver voltage with low losses, so they keep the source resistance very small compared with the load. ## Related formulas - [Internal Resistance](https://formulabro.yunusemrevurgun.com/electricity/internal-resistance/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Voltage Divider](https://formulabro.yunusemrevurgun.com/electricity/voltage-divider/) ## Sources - [Maximum power transfer theorem, Wikipedia](https://en.wikipedia.org/wiki/Maximum_power_transfer_theorem) - [Impedance matching, Wikipedia](https://en.wikipedia.org/wiki/Impedance_matching) - [Electric power, Wikipedia](https://en.wikipedia.org/wiki/Electric_power) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Wheatstone Bridge > A Wheatstone bridge finds an unknown resistance by adjusting a known one until the meter between two midpoints reads zero, then doing one multiply and one divide. Page: https://formulabro.yunusemrevurgun.com/electricity/wheatstone-bridge/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \frac{R_1}{R_2} = \frac{R_3}{R_x} $$ Read it out loud: "R one over R two equals R three over R x. The bridge is balanced when the ratio of the left arm equals the ratio of the right arm." ## What each symbol means - $R_1$: The **top resistor of the left arm**, a known value in ohms ($\Omega$). - $R_2$: The **bottom resistor of the left arm**, a known value in ohms ($\Omega$). - $R_3$: The **top resistor of the right arm**, a known value in ohms ($\Omega$). You adjust it until the meter reads zero. - $R_x$: The **bottom resistor of the right arm**, the unknown resistance in ohms ($\Omega$) that you want to find. ## What the formula is doing A Wheatstone bridge is four resistors joined in a diamond. A supply, such as a battery, connects across the top and bottom corners. A sensitive meter, usually a galvanometer, connects the two side corners. The left side of the diamond has $R_1$ on top and $R_2$ below. The right side has $R_3$ on top and $R_x$ below. The meter joins the point between $R_1$ and $R_2$ to the point between $R_3$ and $R_x$. Each side of the diamond is a voltage divider, so the supply voltage is shared between its two resistors. The voltage at the middle point of the left side depends only on the ratio $R_1 / R_2$. The voltage at the middle point of the right side depends only on $R_3 / R_x$. When those two middle voltages are equal, no current flows through the meter, and the bridge is **balanced**. That gives $\frac{R_1}{R_2} = \frac{R_3}{R_x}$. Solving for the unknown gives $R_x = R_3 \times \frac{R_2}{R_1}$. Since $R_1$, $R_2$ and $R_3$ are known, one multiplication and one division find $R_x$. In a lab, $R_3$ is often a decade box, a set of switches that you turn until the meter reads zero. The supply voltage does not appear in the balance rule, so you do not need to know it. The method is precise because the meter only has to detect zero, not measure a voltage or a current. Bridges like this are used with strain gauges, where a tiny change in resistance shows up as a small unbalance on the meter. ## An everyday picture Think of a seesaw with two pivots. Each side of the bridge is a seesaw that splits the supply voltage, and the meter is a plank that tips when the two sides disagree. Move the known weight until the plank stays level, and the two sides match, so the unknown can be read from the known ones. ## Worked example: Finding an unknown resistor The left arm has $R_1 = 100\ \Omega$ on top and $R_2 = 200\ \Omega$ below. The right arm has a decade box $R_3 = 350\ \Omega$ on top and the unknown $R_x$ below. The meter reads zero, so the bridge is balanced. Find $R_x$. 1. Write the balance rule: $\frac{R_1}{R_2} = \frac{R_3}{R_x}$. 2. Rearrange it to get $R_x$: $R_x = R_3 \times \frac{R_2}{R_1}$. 3. Fill in the numbers: $R_x = 350\ \Omega \times \frac{200\ \Omega}{100\ \Omega} = 350\ \Omega \times 2 = 700\ \Omega$. 4. Check the two ratios: $\frac{100}{200} = 0.5$ and $\frac{350}{700} = 0.5$. They match, so the bridge is balanced. **Answer:** The unknown resistor is **700 ohm**, which is 0.7 kiloohm. Both ratios equal 0.5, and that equality is the balance condition. ## Common mistakes - Swapping $R_3$ and $R_x$ between the top and bottom of the right arm. The balance rule depends on which resistor sits where, so the wrong layout gives the wrong formula. - Multiplying by $R_1 / R_2$ instead of $R_2 / R_1$. In the example, $350\ \Omega \times 0.5 = 175\ \Omega$, which is not the balanced value. - Reading the balance from the supply voltage. The balance rule does not contain the supply voltage. What matters is that the meter reads zero. - Using the formula when the meter shows a current. A current through the meter means the bridge is not balanced, so the formula does not apply yet. ## Where you will meet it - Strain gauges, where a bridge turns the tiny resistance change caused by bending into a measurable signal. - Resistance temperature detectors (RTDs), whose resistance changes with temperature and is read with a bridge. - Pressure transducers that use four resistive strain gauges wired as a bridge. - Precision lab measurements that compare an unknown resistor against a known standard. ## Questions people ask ### Who is the Wheatstone bridge named after? It is named after Charles Wheatstone. The circuit is a simple diamond of four resistors and a meter, and the name is the only part of its history that matters for using it. ### Do I need to know the battery voltage? No. At balance the meter reads zero whatever the supply voltage is, so the voltage drops out of the balance rule. ### What happens when the bridge is not balanced? Current flows through the meter. Its direction tells you whether $R_3$ should go up or down to reach balance. ### Why not measure the voltage across $R_x$ directly? A voltage reading depends on the supply voltage and on the accuracy of the meter. At balance you only need to see zero, and a meter can detect zero very sensitively. ## Related formulas - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Voltage Divider](https://formulabro.yunusemrevurgun.com/electricity/voltage-divider/) - [Kirchhoff's Current Law](https://formulabro.yunusemrevurgun.com/electricity/kirchhoffs-current-law/) ## Sources - [Wheatstone bridge, Wikipedia](https://en.wikipedia.org/wiki/Wheatstone_bridge) - [Strain gauge, Wikipedia](https://en.wikipedia.org/wiki/Strain_gauge) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Battery Capacity and Runtime > Divide a battery's capacity by the current the device draws, and you get roughly how many hours the battery will run it. Page: https://formulabro.yunusemrevurgun.com/electricity/battery-capacity-runtime/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ t = \frac{C}{I} $$ Read it out loud: "t equals C over I. Runtime equals battery capacity divided by current." ## What each symbol means - $t$: **Runtime**, how long the battery lasts, in hours (h) when $C$ is in ampere-hours and $I$ is in amperes. - $C$: **Capacity** of the battery, in ampere-hours (Ah) or milliampere-hours (mAh). A 2000 mAh battery holds 2 Ah. - $I$: **Current** the device draws from the battery, in amperes (A) or milliamperes (mA). Use the same prefix for both values, so that mAh divided by mA gives hours. ## What the formula is doing A battery's capacity is the amount of charge it can supply, measured in ampere-hours (Ah). One ampere-hour is one ampere flowing for one hour. A milliampere-hour (mAh) is one thousandth of that. Most batteries, power banks and battery packs print their capacity on the label. If a device draws a steady current $I$, the ideal runtime is $t = \frac{C}{I}$ hours. The units work out because ampere-hours divided by amperes gives hours. Using the same prefix on both gives the same answer: 2000 mAh divided by 250 mA is 8 hours, the same as 2 Ah divided by 0.25 A. Energy is a better measure when two batteries have different voltages. Energy in watt-hours (Wh) is the capacity in ampere-hours times the battery voltage, $E = C \times V$. A 2 Ah battery at 3.7 V stores 7.4 Wh. A 2 Ah battery at 1.5 V stores only 3 Wh, even though the two labels show the same Ah. The formula is an ideal estimate, and real runtime is usually shorter. Many batteries give less usable capacity at high current. This is called the Peukert effect, and it is most noticeable in lead-acid batteries. The device also stops when the battery voltage falls to its cutoff voltage, which happens before the battery is completely empty. ## An everyday picture Think of a water tank with a tap. The capacity is how many litres the tank holds, the current is how fast the tap runs, and the runtime is how long until the tank is empty. A bigger tank or a slower tap lasts longer. A tank that is drained quickly may give you less water than its label says, which is the real-world version of the Peukert effect. ## Worked example: Runtime of a small battery pack A battery pack is rated at 2000 mAh and 3.7 V. A small device draws a steady 250 mA from it. Find the ideal runtime, and the energy stored in the pack. 1. Runtime: $t = \frac{C}{I} = \frac{2000\ \text{mAh}}{250\ \text{mA}} = 8\ \text{h}$. 2. Convert the capacity to ampere-hours: $2000\ \text{mAh} = 2\ \text{Ah}$. 3. Energy: $E = C \times V = 2\ \text{Ah} \times 3.7\ \text{V} = 7.4\ \text{Wh}$. 4. Check the power: $P = V \times I = 3.7\ \text{V} \times 0.25\ \text{A} = 0.925\ \text{W}$. Then $7.4\ \text{Wh} / 0.925\ \text{W} = 8\ \text{h}$, the same runtime. **Answer:** The ideal runtime is **8 hours**, and the pack stores **7.4 Wh**. The real runtime will be shorter, because the pack does not give its full capacity at this current and the device stops at its cutoff voltage. ## Common mistakes - Mixing prefixes. Dividing 2000 mAh by 0.25 A gives a number 1000 times too big. Use mAh with mA, or Ah with A. - Treating the ideal answer as the real runtime. The formula assumes the full capacity is available at the current you use, and that is often not true. - Comparing batteries by Ah alone. Two batteries with the same Ah can store different energy if their voltages differ. Compare watt-hours instead. - Using a peak current from a datasheet for a steady load. The average current decides the runtime for a steady load, and peak values last only for short bursts. ## Where you will meet it - Phone, laptop and power bank labels, which list capacity in mAh or Wh. - Estimating how long a battery-powered sensor or remote control runs before its cells need replacing. - Comparing battery packs for electric tools, drones and e-bikes by their energy in watt-hours. - Sizing a backup battery for a device that must keep working through a short power cut. ## Questions people ask ### What is a milliampere-hour? One thousandth of an ampere-hour. A 3000 mAh battery holds 3 Ah, which is 3 amperes for 1 hour, or 1 ampere for 3 hours. ### Why does a battery seem to last less time than the formula says? The formula assumes a steady current and full use of the capacity. Real batteries give less usable energy at high current, and the device stops when the voltage reaches its cutoff. ### What is the difference between Ah and Wh? Ah measures charge. Wh measures energy, and it equals Ah times the voltage. Two batteries with the same Ah can store different energy when their voltages differ. ## Related formulas - [Energy and Kilowatt-Hours](https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [Internal Resistance](https://formulabro.yunusemrevurgun.com/electricity/internal-resistance/) ## Sources - [Battery (electricity), Wikipedia](https://en.wikipedia.org/wiki/Battery_(electricity)) - [Peukert's law, Wikipedia](https://en.wikipedia.org/wiki/Peukert%27s_law) - [Watt-hour, Wikipedia](https://en.wikipedia.org/wiki/Watt-hour) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Capacitance > Capacitance tells you how much electric charge a capacitor stores for each volt across it. Page: https://formulabro.yunusemrevurgun.com/electricity/capacitance/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ Q = C V $$ Read it out loud: "Q equals C times V. Charge equals capacitance times voltage." ## What each symbol means - $Q$: **Charge** stored on one plate of the capacitor, in coulombs (C). One coulomb is about $6.24 \times 10^{18}$ elementary charges. - $C$: **Capacitance**, the charge stored per volt, in farads (F). Real capacitors are usually rated in microfarads ($\mu\text{F}$) or picofarads (pF). - $V$: **Voltage** across the capacitor, in volts (V). ## What the formula is doing A capacitor is two conductors close together, separated by an insulator. When a voltage is applied, one plate collects positive charge and the other collects an equal amount of negative charge. The charge $Q$ on each plate depends on the voltage $V$ and on how large the capacitor is. The number that links them is the capacitance $C$. The rule is $Q = C V$. If the capacitance stays the same, doubling the voltage doubles the stored charge. A capacitor with a bigger $C$ holds more charge at the same voltage. Solving for $C$ gives $C = \frac{Q}{V}$, which is why capacitance is measured in charge per volt. The unit is the farad (F), named after Michael Faraday. One farad is one coulomb per volt. That is a very large amount, so practical capacitors are usually rated in microfarads ($1\ \mu\text{F} = 10^{-6}$ F) or picofarads ($1\ \text{pF} = 10^{-12}$ F). The value of $C$ comes from the size, spacing and material of the capacitor. The voltage does not change it. Changing the voltage changes only the charge, while the capacitance stays fixed by the build. ## An everyday picture Think of a capacitor as a tank whose water level is the voltage. The capacitance is how much water the tank holds for each unit of level. A wide tank needs more water to raise its level by one unit, so a wide tank has a large capacitance. The water in the tank is the charge. ## Worked example: Charge on a 100 microfarad capacitor A capacitor with $C = 100\ \mu\text{F}$ is charged to $5\ \text{V}$. How much charge is stored on each plate? 1. Write the rule: $Q = C V$. 2. Convert the capacitance to farads: $100\ \mu\text{F} = 100 \times 10^{-6}\ \text{F} = 1 \times 10^{-4}\ \text{F}$. 3. Multiply: $Q = 1 \times 10^{-4}\ \text{F} \times 5\ \text{V} = 5 \times 10^{-4}\ \text{C}$. 4. Convert to microcoulombs: $5 \times 10^{-4}\ \text{C} = 500\ \mu\text{C}$. **Answer:** The capacitor stores **0.0005 C**, which is **500 microcoulombs**, on each plate. The opposite plate holds the same amount with the opposite sign. ## Common mistakes - Forgetting the micro prefix. $100\ \mu\text{F}$ is $10^{-4}$ F, not 100 F. A factor of a million is easy to miss. - Mixing up the letters. The symbol $C$ stands for capacitance, and it is also the symbol for the coulomb unit. $Q$ is the charge in coulombs. - Thinking a higher voltage changes the capacitance. Voltage changes the charge, while capacitance depends on the build of the capacitor. - Treating charge as current. Charge is an amount stored, in coulombs. Current is the rate at which charge flows, in amperes. ## Where you will meet it - Energy stores in camera flashes and power supply filter capacitors, where the stored charge is what gets delivered in a burst. - Touch screens and some proximity sensors, which detect a finger by measuring a small change in capacitance. - Variable capacitors in radio tuners, where changing the capacitance selects a station. - Circuit board design, where each decoupling capacitor is specified by its capacitance in microfarads or nanofarads. ## Questions people ask ### What is a farad? A farad (F) is one coulomb of charge per volt. It is named after Michael Faraday. Most real capacitors are much smaller, so microfarads and picofarads are common. ### Does a capacitor store charge or energy? Both. The charge is $Q = C V$, and the energy stored is $\frac{1}{2} C V^2$, which has its own page. ### Does the capacitance change when the voltage changes? No. The capacitance is set by the size, spacing and material of the capacitor. A change in voltage changes only the charge on the plates. ### Is charge the same as current? No. Charge is an amount, measured in coulombs. Current is the flow of charge per second, measured in amperes. ## Related formulas - [Parallel-Plate Capacitor](https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor/) - [Capacitors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/capacitors-in-series-and-parallel/) - [Energy Stored in a Capacitor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor/) ## Sources - [Capacitance, Wikipedia](https://en.wikipedia.org/wiki/Capacitance) - [Farad, Wikipedia](https://en.wikipedia.org/wiki/Farad) - [Capacitor, Wikipedia](https://en.wikipedia.org/wiki/Capacitor) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Parallel-Plate Capacitor > The parallel-plate formula says a capacitor holds more charge per volt when its plates are bigger, closer together, or separated by a material with a higher permittivity. Page: https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ C = \frac{\varepsilon_0 \varepsilon_r A}{d} $$ Read it out loud: "C equals epsilon zero times epsilon r times A over d. Capacitance equals the permittivity of free space, times the relative permittivity, times the plate area, divided by the plate gap." ## What each symbol means - $C$: **Capacitance**, in farads (F). - $\varepsilon_0$: The **permittivity of free space**, a constant equal to $8.8541878128 \times 10^{-12}$ F/m (farads per metre). - $\varepsilon_r$: The **relative permittivity** of the material between the plates. It is a plain number with no unit. It is exactly 1 for vacuum and very close to 1 for air. Larger values raise the capacitance. - $A$: **Area** of one plate, in square metres (m$^2$). - $d$: **Separation**, the gap between the plates, in metres (m). ## What the formula is doing A parallel-plate capacitor is two flat conducting plates facing each other, with a thin gap between them. When a voltage is applied, charge builds up on the plates. The electric field across the gap is what holds that charge. The formula $C = \frac{\varepsilon_0 \varepsilon_r A}{d}$ has three parts. The area $A$ is on top, so a bigger plate holds more charge for the same voltage. The gap $d$ is on the bottom, so moving the plates apart lowers the capacitance. Halving the gap doubles it. The constant $\varepsilon_0$ is the permittivity of free space, and it sets the scale in SI units. The relative permittivity $\varepsilon_r$ is a plain multiplier. A dielectric, which is an insulating material placed between the plates, has $\varepsilon_r$ greater than 1, so it multiplies the capacitance by that factor. Vacuum has $\varepsilon_r$ exactly 1. The formula is an approximation. It works well when the plates are large compared with the gap, so the field between them is nearly uniform. Near the edges the field spreads out, which adds a small extra capacitance that the formula leaves out. ## An everyday picture Think of two large trays facing each other with a small gap. Wider trays can hold more charge for the same push. Closer trays pull on each other's charge more strongly, so each volt can push more charge onto them. Slide them apart and the same voltage holds less. ## Worked example: A small capacitor from two plates Two flat plates each have area $A = 0.01\ \text{m}^2$, which is 100 cm$^2$, a square about 10 cm on each side. They are separated by a gap $d = 1\ \text{mm} = 0.001\ \text{m}$ that is filled with a material of relative permittivity $\varepsilon_r = 4$. Find the capacitance. 1. Write the formula: $C = \frac{\varepsilon_0 \varepsilon_r A}{d}$. 2. Multiply the two permittivities: $\varepsilon_0 \varepsilon_r = 8.8541878128 \times 10^{-12}\ \text{F/m} \times 4 = 3.5417 \times 10^{-11}\ \text{F/m}$. 3. Multiply by the area and divide by the gap: $C = \frac{3.5417 \times 10^{-11}\ \text{F/m} \times 0.01\ \text{m}^2}{0.001\ \text{m}} = 3.5417 \times 10^{-10}\ \text{F}$. 4. Convert to picofarads: $3.5417 \times 10^{-10}\ \text{F} = 354\ \text{pF}$. **Answer:** The capacitance is about **354 pF**, which is $3.54 \times 10^{-10}$ F. Doubling the plate area would double it, and halving the gap would double it too. ## Common mistakes - Using centimetres in the formula. Convert to metres first. $1\ \text{cm}^2 = 10^{-4}\ \text{m}^2$, so 100 cm$^2$ is 0.01 m$^2$, not 100 m$^2$. - Leaving out $\varepsilon_r$ or setting it to 0. If the gap holds only vacuum or air, use $\varepsilon_r = 1$. - Thinking the capacitance grows when the plates move apart. The gap is on the bottom of the formula, so a bigger gap gives a smaller capacitance. - Using the formula for plates that are far apart or curved. Large gaps and curved electrodes need a different calculation. ## Where you will meet it - A first estimate for thin-film capacitors built on circuit boards and in chips. - Capacitive touch and proximity sensors, which detect a finger by the change in capacitance it causes. - Capacitive microphones and pressure sensors, where a thin membrane moves and changes the gap between plates. - Variable capacitors in radio tuners, where the overlap of the plate area is changed to tune the circuit. ## Questions people ask ### What is permittivity? Permittivity describes how much a material is polarized by an electric field, which weakens the field inside it for a given charge. Vacuum is the reference value, $\varepsilon_0$, and materials multiply it by $\varepsilon_r$. ### Does the formula work for round capacitors? Not exactly. The formula assumes flat plates close together. Cylindrical and spherical capacitors need their own formulas. ### Is a bigger capacitor always better? Not always. A bigger plate area gives more capacitance, but a larger capacitor takes more space, and its voltage rating and leakage also matter. ## Related formulas - [Capacitance](https://formulabro.yunusemrevurgun.com/electricity/capacitance/) - [Capacitors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/capacitors-in-series-and-parallel/) - [Energy Stored in a Capacitor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor/) ## Sources - [Capacitor, Wikipedia](https://en.wikipedia.org/wiki/Capacitor) - [Vacuum permittivity, Wikipedia](https://en.wikipedia.org/wiki/Vacuum_permittivity) - [Permittivity, Wikipedia](https://en.wikipedia.org/wiki/Permittivity) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Capacitors in Series and Parallel > Capacitors side by side add their capacitance, while capacitors chained end to end give a smaller total that is found with reciprocals. Page: https://formulabro.yunusemrevurgun.com/electricity/capacitors-in-series-and-parallel/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ C_{\text{par}} = C_1 + C_2 + \cdots \qquad \frac{1}{C_{\text{ser}}} = \frac{1}{C_1} + \frac{1}{C_2} + \cdots $$ Read it out loud: "Parallel: C par equals C one plus C two, and so on. Series: one over C ser equals one over C one plus one over C two, and so on." ## What each symbol means - $C_{\text{par}}$: The **total capacitance** of capacitors connected in parallel, in farads (F). - $C_{\text{ser}}$: The **total capacitance** of capacitors connected in series, in farads (F). - $C_1$: The capacitance of the first capacitor, in farads (F). The same idea applies to $C_2$ and any others. - $C_2$: The capacitance of the second capacitor, in farads (F). ## What the formula is doing Capacitors combine in the opposite way to resistors. For resistors, series connections add and parallel connections use reciprocals. For capacitors it is the other way around: parallel connections add directly, and series connections use the reciprocal rule. In parallel, every capacitor sits across the same voltage. Each one stores its own charge, $Q_i = C_i V$, and the total charge is the sum of those charges. Since $C = Q / V$, the total is $C_{\text{par}} = C_1 + C_2 + \cdots$. The parallel total is always bigger than the largest single capacitor. In series, the capacitors form a chain. The two plates facing each other across a joint between capacitors are isolated, so each capacitor in the chain ends up with the same charge $Q$. The voltages across the capacitors add up to the supply voltage, $V = V_1 + V_2 + \cdots$. Since $V_i = Q / C_i$, this gives $\frac{1}{C_{\text{ser}}} = \frac{1}{C_1} + \frac{1}{C_2} + \cdots$. The series total is always smaller than the smallest capacitor in the chain. Real circuits often mix both kinds of connection. Solve them one small group at a time, starting with the innermost group and working outwards. ## An everyday picture Think of a capacitor as a tank that holds charge for each volt of push. Tanks placed side by side on one pipe have their capacities added together. A series chain is like tanks stacked one after another: each one holds the same amount of charge, but the voltages across them add up, so the whole chain holds less than its smallest tank. ## Worked example: A 10 microfarad and a 30 microfarad capacitor Two capacitors, $C_1 = 10\ \mu\text{F}$ and $C_2 = 30\ \mu\text{F}$, are first wired in parallel and then in series. Find the total capacitance in each case. 1. Parallel: $C_{\text{par}} = C_1 + C_2 = 10\ \mu\text{F} + 30\ \mu\text{F} = 40\ \mu\text{F}$. 2. Series: $\frac{1}{C_{\text{ser}}} = \frac{1}{10\ \mu\text{F}} + \frac{1}{30\ \mu\text{F}} = \frac{3 + 1}{30\ \mu\text{F}} = \frac{4}{30\ \mu\text{F}} \approx 0.1333\ \frac{1}{\mu\text{F}}$. 3. Flip the reciprocal to get the total: $C_{\text{ser}} = \frac{30}{4}\ \mu\text{F} = 7.5\ \mu\text{F}$. 4. Check: 7.5 $\mu$F is smaller than the smallest capacitor, 10 $\mu$F, as a series total should be. **Answer:** In parallel the total is **40 µF**. In series the total is **7.5 µF**, which is less than either capacitor on its own. ## Common mistakes - Using the series rule for parallel capacitors, or the parallel rule for series ones. The rules are the opposite of the resistor rules, so it is easy to swap them. - Forgetting to flip the reciprocal. The sum $0.1333$ is not the answer. The answer is $1 / 0.1333 = 7.5\ \mu\text{F}$. - Adding series capacitors directly. A series total is always smaller than the smallest capacitor, so a sum that is too big is a sign of a mistake. - Mixing units partway through. Work in one unit, such as microfarads, for the whole calculation. ## Where you will meet it - Power supplies, where many filter capacitors are placed in parallel to add up to a large capacitance that smooths the output. - Series strings of capacitors used to share a high voltage rating. Balancing resistors are usually added so that the voltage is shared evenly. - Filter and timing circuits, where the right total capacitance is built from standard values. - Decoupling on circuit boards, where capacitors of several values in parallel each cover a different range of frequencies. ## Questions people ask ### Why do parallel capacitors add when parallel resistors do not? Parallel capacitors share the same voltage, so each one adds its own charge to the total. For resistors it is the current that adds, and that gives the reciprocal rule. ### Why is a series total always smaller than the smallest capacitor? Each capacitor in the chain takes part of the total voltage. For the same charge, a larger total voltage means a smaller capacitance, so the chain is smaller than any single part. ### Is there a quick rule for two capacitors in series? Yes. $C_{\text{ser}} = \frac{C_1 C_2}{C_1 + C_2}$, which is the product over the sum. For 10 $\mu$F and 30 $\mu$F, that is $300 / 40 = 7.5\ \mu\text{F}$. ## Related formulas - [Capacitance](https://formulabro.yunusemrevurgun.com/electricity/capacitance/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) - [Parallel-Plate Capacitor](https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor/) ## Sources - [Series and parallel circuits, Wikipedia](https://en.wikipedia.org/wiki/Series_and_parallel_circuits) - [Capacitor, Wikipedia](https://en.wikipedia.org/wiki/Capacitor) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Energy Stored in a Capacitor > A charged capacitor stores energy in the electric field between its plates, and the amount grows with the square of the voltage. Page: https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E = \frac{1}{2} C V^2 $$ Read it out loud: "E equals one half C V squared. Energy equals one half times capacitance times voltage squared." ## What each symbol means - $E$: **Energy** stored in the capacitor, in joules (J). - $C$: **Capacitance**, in farads (F). - $V$: **Voltage** across the capacitor, in volts (V). It is squared in the formula. ## What the formula is doing A charged capacitor holds energy in the electric field between its plates. The energy stays there while the capacitor is charged, and it can be released when the capacitor discharges through a circuit. Energy is measured in joules, the same unit used for every other form of energy. The formula $E = \frac{1}{2} C V^2$ has the voltage squared. Double the voltage on the same capacitor, and the energy goes up by four. Triple it, and the energy goes up by nine. This is why capacitors rated for high voltage can hold a large amount of energy. The one half comes from the way the capacitor charges up. Charge is added a little at a time, and the voltage rises in step with the charge. The average voltage during charging is half the final voltage, and that average is what gives the one half. Two other forms give the same energy: $\frac{Q^2}{2C}$ and $\frac{1}{2} Q V$. They agree because $Q = C V$. Use whichever pair of quantities you know. ## An everyday picture Think of a stretched spring. The energy stored in a spring grows with the square of how far it is stretched, $\frac{1}{2} k x^2$. The voltage plays the part of the stretch, and the capacitance plays the part of the spring's stiffness. ## Worked example: Energy in a 1000 microfarad capacitor at 12 V A capacitor with $C = 1000\ \mu\text{F}$ is charged to $12\ \text{V}$. How much energy is stored? Find the charge first, then check the answer with $\frac{Q^2}{2C}$. 1. Convert the capacitance: $1000\ \mu\text{F} = 1000 \times 10^{-6}\ \text{F} = 1 \times 10^{-3}\ \text{F}$. 2. Energy: $E = \frac{1}{2} C V^2 = \frac{1}{2} \times 10^{-3}\ \text{F} \times (12\ \text{V})^2 = \frac{1}{2} \times 10^{-3} \times 144\ \text{J} = 0.072\ \text{J}$. 3. Charge: $Q = C V = 10^{-3}\ \text{F} \times 12\ \text{V} = 0.012\ \text{C}$. 4. Check with the other form: $\frac{Q^2}{2C} = \frac{(0.012\ \text{C})^2}{2 \times 10^{-3}\ \text{F}} = \frac{1.44 \times 10^{-4}}{2 \times 10^{-3}}\ \text{J} = 0.072\ \text{J}$. **Answer:** The capacitor stores **0.072 J**, which is **72 millijoules**. The charge on each plate is 0.012 C, and both energy formulas give the same result. ## Common mistakes - Using $V$ instead of $V^2$. Doubling the voltage quadruples the energy, so the answer does not merely double. - Forgetting the one half. Without it the answer is twice the true energy. - Forgetting the micro prefix. $1000\ \mu\text{F}$ is $10^{-3}$ F. Skipping the prefix changes the answer by a factor of a million. - Treating the capacitor like a battery. A capacitor's voltage falls as it discharges, so it does not supply a steady voltage the way a battery does. ## Where you will meet it - Camera flashes, which store energy in a capacitor and release it in a short burst of light. - Defibrillators, which store energy in high voltage capacitors before delivering a shock. - Power supply smoothing, where stored energy carries a device through brief dropouts in the input. - Capacitor discharge spot welders and pulsed lasers, which release a large store of energy very quickly. ## Questions people ask ### Why is the voltage squared? Charge grows in step with voltage, and energy is voltage times charge. Two factors that both grow with $V$ give $V^2$ when multiplied together. ### Is the energy lost when the capacitor is disconnected? No. An ideal capacitor keeps its charge and its energy. Real capacitors leak slowly, so the stored energy falls over time. ### Can a capacitor stay dangerous after the power is off? Yes. High voltage capacitors can keep a dangerous charge after the power is switched off, so they must be discharged safely before anyone works on them. ## Related formulas - [Capacitance](https://formulabro.yunusemrevurgun.com/electricity/capacitance/) - [Energy Stored in an Inductor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) ## Sources - [Capacitor, Wikipedia](https://en.wikipedia.org/wiki/Capacitor) - [Capacitance, Wikipedia](https://en.wikipedia.org/wiki/Capacitance) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Inductor Voltage > An inductor pushes back against changes in current, and the voltage across it is set by how fast the current is changing. Page: https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ V = L \frac{dI}{dt} $$ Read it out loud: "V equals L times d I over d t. Voltage equals inductance times the rate of change of current." ## What each symbol means - $V$: **Voltage** across the inductor, in volts (V). - $L$: **Inductance**, a measure of how strongly the coil opposes changes in current, in henries (H). A millihenry is $10^{-3}$ H. - $I$: **Current** through the inductor, in amperes (A). - $t$: **Time**, in seconds (s). ## What the formula is doing An inductor is a coil of wire, often wound around a core. When current flows through it, the coil stores energy in its magnetic field. The key rule is that the coil resists changes in current. To change the current quickly you need a large voltage. To hold the current steady, an ideal inductor needs no voltage at all. The formula $V = L \frac{dI}{dt}$ says the voltage across the inductor equals its inductance times the rate of change of current. The term $\frac{dI}{dt}$ is how many amperes per second the current changes. A current that rises by 2 A every second needs a voltage of $L \times 2\ \text{A/s}$. The unit of inductance is the henry (H), named after Joseph Henry. One henry is one volt-second per ampere, so a 1 H coil needs 1 V to make its current rise by 1 A each second. Most small coils are rated in millihenries or microhenries. Switching off is where this rule causes trouble. If the current drops to zero very quickly, $\frac{dI}{dt}$ is large and negative, so the voltage across the coil is large too, with the opposite polarity. This spike can damage a switch or a transistor. A diode placed across the coil, called a flyback or freewheeling diode, gives the current a safe path to keep circulating, so the voltage stays near the forward drop of that diode. ## An everyday picture Think of a heavy cart on a track. The cart resists being sped up or slowed down, and the faster you try to change its speed, the harder you must push. Here the inductance plays the part of the mass, the current plays the part of the speed, and the voltage plays the part of the force. The shape of $V = L \frac{dI}{dt}$ matches Newton's second law, $F = m a$. ## Worked example: Voltage across a 10 millihenry coil A coil with $L = 10\ \text{mH}$ has its current ramped steadily from 0 A to 2 A in 1 ms. Find the voltage across the coil during the ramp. 1. Convert the units: $L = 10\ \text{mH} = 0.01\ \text{H}$ and $t = 1\ \text{ms} = 0.001\ \text{s}$. 2. Find the rate of change of current: $\frac{dI}{dt} = \frac{2\ \text{A}}{0.001\ \text{s}} = 2000\ \text{A/s}$. 3. Apply the formula: $V = L \frac{dI}{dt} = 0.01\ \text{H} \times 2000\ \text{A/s} = 20\ \text{V}$. **Answer:** The coil needs **20 V** across it to make its current rise steadily from 0 to 2 A in 1 ms. A faster ramp needs more voltage, and a steady 2 A needs none. ## Common mistakes - Forgetting the milli prefix. $10\ \text{mH}$ is 0.01 H, not 10 H. Using 10 gives a voltage 1000 times too big. - Treating the inductor like a resistor. A resistor's voltage depends on the current itself, but an inductor's voltage depends on how fast the current changes. A steady current gives zero voltage. - Ignoring the spike when the current is cut. Switching off a coil makes the voltage jump in the opposite direction, which can destroy the switch unless a flyback diode is fitted. - Confusing the units. The henry is volt-seconds per ampere, not ohms. ## Where you will meet it - Relay and solenoid coils, which need a flyback diode across them because switching them off creates a voltage spike. - Switching power supplies such as buck and boost converters, where an inductor controls how the current rises and falls. - Car ignition coils, which make a high voltage spark by quickly interrupting the current through the coil. - Filters in audio crossovers and power line filters, where inductors resist fast changes in current. ## Questions people ask ### What is a henry? The henry (H) is the unit of inductance. It equals one volt-second per ampere, so a 1 H inductor needs 1 V to make its current change by 1 A each second: $1\ \text{H} = 1\ \text{V} \cdot \text{s} / \text{A}$. ### Why is there no voltage when the current is steady? When the current stops changing, $\frac{dI}{dt} = 0$, so $V = L \times 0 = 0$. An ideal inductor therefore acts like a plain wire for steady direct current. ### Why does switching off a coil create such a big voltage? The current wants to fall to zero in a very short time, which makes $\frac{dI}{dt}$ huge. The coil pushes back with a large voltage in the opposite direction to keep the current flowing. ## Related formulas - [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/) - [RL Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rl-time-constant/) - [Energy Stored in an Inductor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor/) ## Sources - [Inductor, Wikipedia](https://en.wikipedia.org/wiki/Inductor) - [Inductance, Wikipedia](https://en.wikipedia.org/wiki/Inductance) - [Freewheeling diode, Wikipedia](https://en.wikipedia.org/wiki/Freewheeling_diode) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Energy Stored in an Inductor > A coil with current flowing through it stores energy in its magnetic field, and the amount grows with the square of the current. Page: https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E = \frac{1}{2} L I^2 $$ Read it out loud: "E equals one half L I squared. Energy equals one half times inductance times current squared." ## What each symbol means - $E$: **Energy** stored in the magnetic field of the inductor, in joules (J). - $L$: **Inductance**, in henries (H). - $I$: **Current** through the inductor, in amperes (A). It is squared in the formula. ## What the formula is doing When current flows through a coil, it creates a magnetic field, and that field stores energy. The energy is there as long as the current keeps flowing. Building up the current in a coil means the source does work against the coil's resistance to change, and that work is stored as magnetic energy. The formula $E = \frac{1}{2} L I^2$ has the current squared. Doubling the current makes the stored energy four times bigger. A larger inductance stores more energy at the same current, because the coil opposes changes in current more strongly. The one half comes from building the current up from zero. The voltage the source must supply is $L \frac{dI}{dt}$, and the power is that voltage times $I$. Adding up that power as the current rises gives a total of $\frac{1}{2} L I^2$. This stored energy explains why switching off a coil causes a voltage spike. When the current is cut, the energy has to go somewhere. It is dissipated in a flyback diode or a resistor, or in an arc at the switch, and the coil produces a large voltage to push the current through that path. ## An everyday picture Think of a moving car. Its kinetic energy is one half $m v^2$, so going twice as fast takes four times the energy. Here the inductance plays the part of the mass and the current plays the part of the speed. The magnetic field is the stored motion. ## Worked example: Energy in a 10 millihenry coil carrying 2 A The same $10\ \text{mH}$ coil from the inductor voltage example now carries a steady current of $2\ \text{A}$. How much energy is stored in its magnetic field? Then find the energy if the current doubles to 4 A. 1. Convert the inductance: $L = 10\ \text{mH} = 0.01\ \text{H}$. 2. Square the current: $I^2 = (2\ \text{A})^2 = 4\ \text{A}^2$. 3. Energy: $E = \frac{1}{2} L I^2 = \frac{1}{2} \times 0.01\ \text{H} \times 4\ \text{A}^2 = 0.02\ \text{J}$. 4. Double the current to 4 A: $E = \frac{1}{2} \times 0.01\ \text{H} \times (4\ \text{A})^2 = 0.08\ \text{J}$, which is four times the first answer. **Answer:** The coil stores **0.02 J** (20 millijoules) at 2 A. At 4 A it stores **0.08 J**, four times as much. ## Common mistakes - Forgetting the square. Energy goes with $I^2$, so doubling the current quadruples the energy. - Forgetting the one half. Without it the answer is twice the true energy. - Using the capacitor formula for a coil. The inductor formula uses current and inductance, while the capacitor formula uses voltage and capacitance. - Thinking the stored energy is zero when there is no voltage. For a steady current, an ideal inductor has no voltage across it, but its magnetic field still holds energy. ## Where you will meet it - Switching power supplies, where an inductor stores energy in its field during one part of each switching cycle and delivers it during another. - Car ignition coils, which store energy in a magnetic field and release it as a high voltage spark. - Relay and solenoid coils, whose stored energy must be removed safely with a diode when the coil is switched off. - Tuned radio circuits, where energy swings back and forth between a coil and a capacitor. ## Questions people ask ### Why does the energy depend on the current squared? Building the current up requires a voltage that grows with the current, and power is voltage times current. Both factors grow with $I$, so the energy grows with $I^2$. ### Is the energy in an inductor stored the same way as in a capacitor? The two formulas have the same shape. A capacitor stores $\frac{1}{2} C V^2$ in its electric field, and an inductor stores $\frac{1}{2} L I^2$ in its magnetic field. ### Where does the energy go when the current stops? It is released into the circuit. It often ends up as heat in a resistor or a diode, or as a spark at a switch. A flyback diode gives it a gentle path to dissipate. ## Related formulas - [Energy Stored in a Capacitor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor/) - [Inductor Voltage](https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage/) - [RL Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rl-time-constant/) ## Sources - [Inductor, Wikipedia](https://en.wikipedia.org/wiki/Inductor) - [Inductance, Wikipedia](https://en.wikipedia.org/wiki/Inductance) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # RL Time Constant > The RL time constant tells you how long current takes to build up in a coil connected through a resistor: divide the inductance by the resistance. Page: https://formulabro.yunusemrevurgun.com/electricity/rl-time-constant/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \tau = \frac{L}{R} $$ Read it out loud: "Tau equals L over R. The time constant equals inductance divided by resistance." ## What each symbol means - $\tau$: The **time constant** (the Greek letter tau), measured in seconds (s). It sets how fast the current rises or falls. - $L$: **Inductance** of the coil, measured in henries (H). - $R$: **Resistance** of the resistor in series with the coil, measured in ohms ($\Omega$). ## What the formula is doing An inductor is a coil that resists changes in current. When a coil is connected through a resistor to a battery, the current does not jump straight to its final value. The coil opposes the rise, so the current climbs slowly, starting from zero. The time constant is $\tau = \frac{L}{R}$, in seconds. Henries divided by ohms give seconds, because $\text{H} = \Omega \cdot \text{s}$. The current is $I(t) = \frac{V}{R}\left(1 - e^{-t/\tau}\right)$, where $I(t)$ is the current at time $t$, $V$ is the supply voltage and $V/R$ is the final current. After one time constant the current has reached about 63.2% of its final value. The curve is steep at the start and flattens out as it nears the final value. After about five time constants the current is more than 99% of its final value, which is the same rule of thumb used for an RC circuit. A bigger inductance makes the current rise more slowly, so $\tau$ grows. A bigger resistance lets the current reach its final value sooner, so $\tau$ shrinks. Doubling $L$ doubles $\tau$, and doubling $R$ halves it. ## An everyday picture Think of pushing a heavy cart up to speed. The heavy cart takes time to get moving, which is like a big inductance. Friction limits its top speed. More friction means the cart settles at its steady speed sooner, which is like a bigger resistance giving a shorter time constant. ## Worked example: A 2 henry coil with a 10 ohm resistor on a 5 V supply A coil with $L = 2\ \text{H}$ and a resistor with $R = 10\ \Omega$ are connected in series to a 5 V supply at $t = 0$. Find the time constant, the final current and the current at $t = 0.2\ \text{s}$ and $t = 1\ \text{s}$. 1. Time constant: $\tau = \frac{L}{R} = \frac{2\ \text{H}}{10\ \Omega} = 0.2\ \text{s}$. 2. Final current, when the coil no longer changes: $I_\infty = \frac{V}{R} = \frac{5\ \text{V}}{10\ \Omega} = 0.5\ \text{A}$. 3. At $t = 0.2\ \text{s}$, which is one time constant: $I = 0.5\ \text{A} \times (1 - e^{-1}) \approx 0.5 \times 0.632 = 0.316\ \text{A}$. 4. At $t = 1\ \text{s}$, which is five time constants: $I = 0.5\ \text{A} \times (1 - e^{-5}) \approx 0.5 \times 0.993 = 0.497\ \text{A}$. **Answer:** The time constant is **0.2 s**. The current reaches **0.316 A** after 0.2 s, which is 63.2% of the final **0.5 A**. After 1 s it is **0.497 A**, more than 99% of the way to the final value. ## Common mistakes - Assuming the current starts at its final value. Right after the switch closes the current is 0 A, not $V/R$. - Thinking the current is final after one time constant. After one $\tau$ it is only about 63.2% of the final value, and it takes about five $\tau$ to get above 99%. - Writing the formula upside down as $\tau = R / L$. A bigger coil is slower and a bigger resistor is faster, and only $L/R$ shows both effects. - Entering millihenries as henries. A 2 mH coil has $L = 0.002$ H, and skipping the conversion changes $\tau$ by a factor of 1000. ## Where you will meet it - Relay and solenoid circuits, where the coil current rises over a short, known time after switch-on. - Motor windings, where the slow build-up of current after switch-on sets how quickly the motor reaches its running current. - Switching power supplies and DC-DC converters, which store energy in an inductor as its current rises. - Lab experiments that measure the inductance of a coil by timing how fast its current rises. ## Questions people ask ### Is the RL time constant the same as the RC time constant? The formulas differ: $\tau = L/R$ for an RL circuit and $\tau = RC$ for an RC circuit. In both, the change reaches about 63.2% of its final value after one time constant. ### Why does the coil slow the current down? A changing current induces a voltage across the coil that opposes the change. The effect is strongest right after switch-on, which is why the current starts at zero. ### What happens when the supply is switched off? The current decays with the same time constant, falling to about 36.8% of its starting value after one $\tau$. The coil's stored energy has to go somewhere, which is why a switch can spark when it opens. ### Why is the time constant L over R? A bigger inductance means the coil opposes change for longer, so the time constant grows. A bigger resistance limits the current more quickly, so the time constant shrinks. ## Related formulas - [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Inductive Reactance](https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance/) ## Sources - [RL circuit, Wikipedia](https://en.wikipedia.org/wiki/RL_circuit) - [Inductance, Wikipedia](https://en.wikipedia.org/wiki/Inductance) - [Exponential decay, Wikipedia](https://en.wikipedia.org/wiki/Exponential_decay) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Capacitive Reactance > Capacitive reactance tells you how hard a capacitor pushes back against alternating current, and it gets smaller as the frequency goes up. Page: https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ X_C = \frac{1}{2\pi f C} $$ Read it out loud: "X C equals one divided by two pi times f times C. Capacitive reactance equals one over two pi f C." ## What each symbol means - $X_C$: **Capacitive reactance**, the opposition a capacitor gives to alternating current, measured in ohms ($\Omega$). It is not resistance, because the capacitor does not turn the energy into heat. - $\pi$: The number pi, about 3.14159. It has no unit. - $f$: **Frequency** of the alternating current, measured in hertz (Hz). One hertz is one cycle per second. - $C$: **Capacitance**, how much charge the capacitor holds for each volt, measured in farads (F). A microfarad is $10^{-6}$ F. ## What the formula is doing A capacitor is two conductors separated by an insulator. Steady direct current cannot pass through it once it is charged. Alternating current seems to pass, because the current charges and discharges the plates on every cycle. The capacitor still limits that flow, and the limit is called capacitive reactance, written $X_C$. It is measured in ohms, like resistance. The formula $X_C = \frac{1}{2\pi f C}$ says the reactance is one divided by the frequency times the capacitance. The factor $2\pi f$ turns cycles per second into radians per second, which is the natural rate for a sine wave. The result is in ohms. Frequency has the biggest effect. Double the frequency and the reactance halves. The current reverses more often, so the capacitor moves more charge each second and passes more current for the same voltage. A very fast signal sees a small reactance. At zero frequency, which is steady DC, the reactance is infinite, and the capacitor blocks the current. A bigger capacitance lowers the reactance. A larger capacitor holds more charge for each volt, so it can move more charge on each cycle and pass more current. ## An everyday picture Think of a rubber sheet stretched across a pipe. Water cannot pass through the sheet, but water pushed back and forth makes the sheet bulge in and out. If you push slowly, the sheet barely moves and little water flows. If you push quickly, the sheet bulges more often each second, so more water flows through. The sheet is the capacitor, and a faster push means a smaller reactance. ## Worked example: A 100 microfarad capacitor at 50 Hz and 500 Hz A capacitor with $C = 100\ \mu\text{F}$ is connected to an AC supply. Find its reactance at $f = 50\ \text{Hz}$, then at $f = 500\ \text{Hz}$. 1. Convert the capacitance: $C = 100 \times 10^{-6}\ \text{F}$. 2. At 50 Hz, the product is $2\pi f C = 2\pi \times 50\ \text{Hz} \times 100 \times 10^{-6}\ \text{F} \approx 0.03142\ \text{S}$, where S (siemens) is one over an ohm. 3. So $X_C = \frac{1}{0.03142\ \text{S}} \approx 31.8\ \Omega$. 4. At 500 Hz the frequency is ten times higher, so the product is ten times bigger: $2\pi \times 500\ \text{Hz} \times 100 \times 10^{-6}\ \text{F} \approx 0.3142\ \text{S}$. Then $X_C = \frac{1}{0.3142\ \text{S}} \approx 3.18\ \Omega$. **Answer:** At 50 Hz the capacitor has a reactance of about **31.8 Ω**. At 500 Hz it drops to about **3.18 Ω**, ten times smaller, because the frequency is ten times higher. ## Common mistakes - Leaving out the conversion to farads. 100 microfarad is $100 \times 10^{-6}$ F, not 100 F, and the answer is off by a factor of a million without it. - Dropping the $2\pi$ factor. Without it the answer is about six times too small, because $2\pi$ is about 6.28. - Treating reactance as resistance. A capacitor stores energy and gives it back on each cycle, so an ideal capacitor does not heat up the way a resistor does. - Assuming the reactance is fixed. The same capacitor has a very different reactance at 50 Hz and at 500 Hz. ## Where you will meet it - Filter circuits, where a capacitor passes high frequencies and blocks low ones, or the other way round. - Audio crossover networks, which help send low notes to a woofer and high notes to a tweeter. - Power factor correction banks, which add capacitors to offset the current drawn by motors and other inductive loads. - Radio tuning circuits, where a capacitor and a coil together select one frequency. ## Questions people ask ### Why does a capacitor let AC through but not DC? Once a capacitor charges to the supply voltage, steady DC current stops. Alternating current keeps reversing, so the capacitor charges and discharges on each cycle, and current appears to flow through it. ### What unit is reactance measured in? Reactance is measured in ohms ($\Omega$), the same unit as resistance. It is a separate quantity, though, and in a circuit it combines with resistance in a different way. ### Why does reactance go down when frequency goes up? A faster signal reverses direction more often, so it moves more charge through the capacitor each second. More current for the same voltage means less opposition. ### Does a capacitor use up energy in an AC circuit? An ideal capacitor stores energy during one part of the cycle and gives it back in the next, so it uses no net energy over a full cycle. Real capacitors lose a little energy as heat. ## Related formulas - [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Resistors in Series and Parallel](https://formulabro.yunusemrevurgun.com/electricity/resistors-in-series-and-parallel/) ## Sources - [Electrical reactance, Wikipedia](https://en.wikipedia.org/wiki/Electrical_reactance) - [Capacitor, Wikipedia](https://en.wikipedia.org/wiki/Capacitor) - [Alternating current, Wikipedia](https://en.wikipedia.org/wiki/Alternating_current) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Inductive Reactance > Inductive reactance tells you how hard a coil pushes back against alternating current, and it gets bigger as the frequency goes up. Page: https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ X_L = 2\pi f L $$ Read it out loud: "X L equals two pi times f times L. Inductive reactance equals two pi f L." ## What each symbol means - $X_L$: **Inductive reactance**, the opposition a coil gives to alternating current, measured in ohms ($\Omega$). It is not resistance, because the coil stores energy instead of turning it into heat. - $\pi$: The number pi, about 3.14159. It has no unit. - $f$: **Frequency** of the alternating current, measured in hertz (Hz). One hertz is one cycle per second. - $L$: **Inductance**, how strongly the coil opposes a change in its current, measured in henries (H). A millihenry is $10^{-3}$ H. ## What the formula is doing An inductor is a coil of wire. When the current through it changes, the coil produces a voltage that opposes the change. Steady direct current does not change, so the coil barely affects it. Alternating current is always changing, so the coil keeps pushing back. That push-back is inductive reactance, written $X_L$, and it is measured in ohms. The formula $X_L = 2\pi f L$ says the reactance is the frequency times the inductance, times $2\pi$. The factor $2\pi f$ turns cycles per second into radians per second, which is the natural rate for a sine wave. Both $f$ and $L$ multiply, so a rise in either one raises the reactance. Frequency has a big effect. Double the frequency and the reactance doubles, because the current changes twice as fast and the induced voltage depends on how fast the current changes. At zero frequency, which is steady DC, the reactance is zero, so an ideal coil acts like a plain wire. Inductance sets the scale. A coil with more turns, or with a core that concentrates its magnetic field, has a larger inductance and a larger reactance at the same frequency. ## An everyday picture Think of a heavy flywheel that you try to speed up and slow down by hand. The flywheel resists every change in its speed, and the faster you try to change it back and forth, the harder it resists. A coil resists changes in current in the same way, so a fast alternating current meets more opposition than a slow one. ## Worked example: A 0.1 henry coil at 50 Hz and 500 Hz A coil with $L = 0.1\ \text{H}$ is connected to an AC supply. Find its reactance at $f = 50\ \text{Hz}$, a common mains frequency, then at $f = 500\ \text{Hz}$. 1. At 50 Hz: $X_L = 2\pi \times 50\ \text{Hz} \times 0.1\ \text{H}$. 2. Multiply: $2\pi \approx 6.283$, and $6.283 \times 50 \times 0.1 \approx 31.4$, so $X_L \approx 31.4\ \Omega$. 3. At 500 Hz the frequency is ten times higher, so $X_L = 2\pi \times 500\ \text{Hz} \times 0.1\ \text{H} \approx 314\ \Omega$. 4. Units check: $\text{Hz} \times \text{H} = \Omega$, because $\text{H} = \Omega \cdot \text{s}$ and $\text{Hz} = 1/\text{s}$. **Answer:** At 50 Hz the coil has a reactance of about **31.4 Ω**. At 500 Hz it rises to about **314 Ω**, ten times larger, so the coil passes far less alternating current at the higher frequency. ## Common mistakes - Mixing up inductance and inductive reactance. Inductance $L$ is a property of the coil, in henries, while reactance $X_L$ is the opposition at one frequency, in ohms. - Expecting a coil to block DC. A coil opposes changes in current, not steady current, so steady DC passes through it almost unaffected. - Dropping the $2\pi$ factor. Without it the answer is about six times too small. - Entering millihenries as henries. A 100 mH coil has $L = 0.1$ H, not 100 H. ## Where you will meet it - Radio tuning circuits, where a coil and a capacitor are chosen to pick out one station. - Ballasts in fluorescent lights, where a coil limits the current through the lamp on AC mains. - Audio crossover filters, where a coil in series with a woofer lets low frequencies through and blocks high ones. - Smoothing chokes in power supplies, which resist the ripple current that would otherwise pass through. ## Questions people ask ### Why does a coil resist alternating current? The current in an AC coil keeps changing, and a changing current induces a voltage in the coil that opposes the change. That opposing voltage limits the current. ### How is inductive reactance different from resistance? A resistor turns electrical energy into heat. An ideal coil stores energy in its magnetic field and gives it back on each cycle, so it does not heat up on average. ### What is a henry? A henry (H) is the unit of inductance. A coil has an inductance of one henry when a current changing at one ampere per second induces one volt across it. ### Why are coils used in filters? Their reactance rises with frequency, so they pass low frequencies more easily than high frequencies. That behavior makes them useful in crossovers and other filters. ## Related formulas - [Capacitive Reactance](https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [RC Time Constant](https://formulabro.yunusemrevurgun.com/electricity/rc-time-constant/) ## Sources - [Electrical reactance, Wikipedia](https://en.wikipedia.org/wiki/Electrical_reactance) - [Inductance, Wikipedia](https://en.wikipedia.org/wiki/Inductance) - [Alternating current, Wikipedia](https://en.wikipedia.org/wiki/Alternating_current) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Series RLC Impedance > Impedance is the total opposition a series circuit of a resistor, a coil and a capacitor gives to alternating current. Page: https://formulabro.yunusemrevurgun.com/electricity/rlc-impedance/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ Z = \sqrt{R^2 + (X_L - X_C)^2} $$ Read it out loud: "Z equals the square root of R squared plus the quantity X L minus X C, all squared." ## What each symbol means - $Z$: **Impedance**, the total opposition to alternating current in the series circuit, measured in ohms ($\Omega$). - $R$: **Resistance** of the resistor, measured in ohms ($\Omega$). - $X_L$: **Inductive reactance** of the coil, measured in ohms ($\Omega$). See the page on inductive reactance. - $X_C$: **Capacitive reactance** of the capacitor, measured in ohms ($\Omega$). See the page on capacitive reactance. ## What the formula is doing A series RLC circuit has a resistor, a coil and a capacitor connected one after another in a single loop. Each part opposes alternating current in its own way. The resistor turns energy into heat. The coil and the capacitor store energy and give it back, so they cause reactance instead of heat. The coil's reactance $X_L$ and the capacitor's reactance $X_C$ work in opposite directions. The coil makes the voltage lead the current, and the capacitor makes the current lead the voltage. The net reactance is therefore $X_L - X_C$, and that difference is what the formula uses. The impedance $Z$ does not add resistance and net reactance as plain numbers. They are out of step by a quarter cycle, so they combine like the two shorter sides of a right triangle. That is why the formula has a square root of squares: $Z = \sqrt{R^2 + (X_L - X_C)^2}$. The impedance is the ratio $Z = V/I$ of the voltage to the current, both in rms or both in peak values. The phase angle $\varphi$ says how far the voltage leads or lags the current, using $\tan\varphi = \frac{X_L - X_C}{R}$. A positive angle means the coil dominates and the voltage leads. A negative angle means the capacitor dominates and the current leads. Zero means the two reactances cancel. ## An everyday picture Think of a hiker who walks 3 km east and then 4 km north. The hiker's distance from the start is 5 km, not 7 km, because east and north are at right angles. In the circuit, the resistance is the east step, the net reactance is the north step, and the impedance is the straight-line distance. ## Worked example: A 30 ohm resistor, a 0.1 H coil and a 50 microfarad capacitor at 50 Hz A series circuit has $R = 30\ \Omega$, $L = 0.1\ \text{H}$ and $C = 50\ \mu\text{F}$, driven at $f = 50\ \text{Hz}$ by a 10 V rms supply. Find $X_L$, $X_C$, the impedance, the phase angle and the rms current. 1. Coil reactance: $X_L = 2\pi f L = 2\pi \times 50\ \text{Hz} \times 0.1\ \text{H} \approx 31.42\ \Omega$. 2. Capacitor reactance: $X_C = \frac{1}{2\pi f C} = \frac{1}{2\pi \times 50\ \text{Hz} \times 50 \times 10^{-6}\ \text{F}} \approx 63.66\ \Omega$. 3. Net reactance: $X_L - X_C \approx 31.42\ \Omega - 63.66\ \Omega = -32.25\ \Omega$. The minus sign means the capacitor dominates. 4. Impedance: $Z = \sqrt{R^2 + (X_L - X_C)^2} = \sqrt{30^2 + 32.25^2} = \sqrt{900 + 1040} \approx 44.0\ \Omega$. 5. Phase angle: $\tan\varphi = \frac{-32.25\ \Omega}{30\ \Omega} \approx -1.075$, so $\varphi \approx -47.1^\circ$. 6. Current: $I = \frac{V}{Z} = \frac{10\ \text{V}}{44.0\ \Omega} \approx 0.227\ \text{A}$. **Answer:** The impedance is about **44.0 Ω**. The capacitor dominates, so the current leads the supply voltage by about **47.1°**, and the rms current is about **0.227 A**. ## Common mistakes - Adding the reactances instead of subtracting them. $X_L$ and $X_C$ pull in opposite directions, so the net reactance is $X_L - X_C$. - Adding resistance and reactance as plain numbers. Because they are a quarter cycle apart, $Z$ comes from the square root of the squares, not from $R + X$. - Forgetting the sign of the phase angle. A negative angle means the capacitor dominates and the current leads the voltage. - Mixing rms and peak values. Use rms with rms, or peak with peak, so that $Z = V/I$ holds. ## Where you will meet it - Radio receivers and transmitters, where a series RLC circuit is tuned to one chosen frequency. - Audio and power filters, which pass some frequencies and block others. - Power factor analysis of motors and other inductive loads, which uses the phase angle between voltage and current. - Impedance matching, where a designer picks parts so the circuit's impedance suits the source. ## Questions people ask ### Why is impedance not the sum of resistance and reactance? Resistance and reactance are out of step by a quarter cycle, so they add like the sides of a right triangle. That is why the formula uses a square root. ### What does the phase angle tell me? It tells you how far the voltage leads or lags the current. A positive angle means the voltage leads, and a negative angle means the voltage lags, as in a capacitor-dominated circuit. ### What happens at resonance? When $X_L = X_C$ the reactances cancel, so $Z$ equals $R$ and the current is at its largest. The resonant frequency page explains how to find that frequency. ### Is impedance the same as resistance? No. Resistance is the opposition that turns energy into heat. Impedance also includes reactance, and it changes with frequency, while the resistance of an ideal resistor does not. ## Related formulas - [Capacitive Reactance](https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance/) - [Inductive Reactance](https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) ## Sources - [RLC circuit, Wikipedia](https://en.wikipedia.org/wiki/RLC_circuit) - [Electrical impedance, Wikipedia](https://en.wikipedia.org/wiki/Electrical_impedance) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Resonant Frequency > The resonant frequency is the one frequency where a coil and a capacitor trade energy back and forth most easily, and radios use it to tune in stations. Page: https://formulabro.yunusemrevurgun.com/electricity/resonant-frequency/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ f_0 = \frac{1}{2\pi\sqrt{LC}} $$ Read it out loud: "f zero equals one divided by two pi times the square root of L times C. Resonant frequency equals one over two pi root L C." ## What each symbol means - $f_0$: **Resonant frequency**, the frequency at which the LC circuit resonates, measured in hertz (Hz). - $\pi$: The number pi, about 3.14159. It has no unit. - $L$: **Inductance** of the coil, measured in henries (H). - $C$: **Capacitance** of the capacitor, measured in farads (F). ## What the formula is doing A coil and a capacitor connected together form an LC circuit. The capacitor stores energy in its electric field, and the coil stores energy in its magnetic field. Energy can slosh back and forth between them, like a pendulum that trades height for speed. Each part sets how quickly that exchange happens. The formula $f_0 = \frac{1}{2\pi\sqrt{LC}}$ shows that a bigger $L$ or a bigger $C$ makes the exchange slower, so the resonant frequency is lower. The square root means that doubling $L$ or $C$ lowers the frequency by a factor of $\sqrt{2}$, not by 2. In a series RLC circuit, the coil's and the capacitor's reactances are equal at resonance and cancel, which leaves only the resistance. That makes the current largest at this frequency. A circuit with low resistance has a sharp peak at its resonant frequency, so it picks out a narrow band of frequencies. A radio needs that sharpness to separate one station from the next. ## An everyday picture Think of pushing a child on a swing. Push at the swing's natural rhythm and each push adds height quickly. Push at a very different rhythm and the pushes cancel out. An LC circuit has its own natural rhythm, and a signal at that rhythm builds up the most. ## Worked example: A 250 microhenry coil and a 100 picofarad capacitor A tuning circuit has $L = 250\ \mu\text{H}$ and $C = 100\ \text{pF}$. Find its resonant frequency. A microhenry is $10^{-6}$ H and a picofarad is $10^{-12}$ F. 1. Convert the units: $L = 250 \times 10^{-6}\ \text{H} = 2.5 \times 10^{-4}\ \text{H}$ and $C = 100 \times 10^{-12}\ \text{F} = 1.0 \times 10^{-10}\ \text{F}$. 2. Multiply: $LC = 2.5 \times 10^{-4} \times 1.0 \times 10^{-10} = 2.5 \times 10^{-14}\ \text{s}^2$. 3. Square root: $\sqrt{LC} = \sqrt{2.5 \times 10^{-14}} \approx 1.581 \times 10^{-7}\ \text{s}$. 4. Resonant frequency: $f_0 = \frac{1}{2\pi \sqrt{LC}} = \frac{1}{2\pi \times 1.581 \times 10^{-7}\ \text{s}} \approx 1.007 \times 10^{6}\ \text{Hz}$. **Answer:** The circuit resonates at about **1.01 MHz**, which falls in the AM broadcast band. Turning the capacitor or moving the coil changes this frequency. ## Common mistakes - Mixing up the units of $L$ and $C$. Microhenries and picofarads must be converted to henries and farads first, or the frequency is off by a large factor. - Putting the square root on the wrong part. The formula is $1/(2\pi\sqrt{LC})$, with the square root over the whole product $LC$. - Treating $f_0$ as angular frequency. The formula gives hertz, which is cycles per second. The angular frequency is $\omega = 2\pi f$, in radians per second. - Expecting a circuit to resonate at any frequency you pick. A tuned circuit has one natural resonant frequency, set by its $L$ and $C$. ## Where you will meet it - Radio receivers, where a tuning circuit selects one station from many. - Clock and signal oscillators, where an LC circuit sets the frequency of the signal. - Wireless power transfer systems, which tune a coil and capacitor to a shared frequency. - Induction cooktops and heaters, which use resonant LC circuits to drive their coils. ## Questions people ask ### What does resonance mean in a circuit? It means the energy exchange between the coil and the capacitor matches the natural rhythm of the circuit, so a signal at that frequency builds up the most. ### Why is the frequency lower when the capacitor is bigger? A bigger capacitor holds more charge, so it takes longer to fill and empty. A bigger coil also takes longer to change its current, so the same rule applies to $L$. ### Is the resonant frequency the same as the frequency of the current? Only when you drive the circuit at that frequency. The resonant frequency depends on the $L$ and $C$ values, and the circuit responds most strongly when the drive matches it. ### How does this formula apply to radio tuning? Turning a variable capacitor changes $C$, which moves $f_0$. The radio then picks out the station whose frequency matches the new resonant frequency. ## Related formulas - [Series RLC Impedance](https://formulabro.yunusemrevurgun.com/electricity/rlc-impedance/) - [Inductive Reactance](https://formulabro.yunusemrevurgun.com/electricity/inductive-reactance/) - [Capacitive Reactance](https://formulabro.yunusemrevurgun.com/electricity/capacitive-reactance/) ## Sources - [LC circuit, Wikipedia](https://en.wikipedia.org/wiki/LC_circuit) - [Resonance, Wikipedia](https://en.wikipedia.org/wiki/Resonance) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # RMS Voltage > RMS voltage is the steady voltage that heats a resistor as much as an AC sine wave does, and you get it by dividing the peak voltage by the square root of 2. Page: https://formulabro.yunusemrevurgun.com/electricity/rms-voltage/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ V_{\text{rms}} = \frac{V_{\text{peak}}}{\sqrt{2}} $$ Read it out loud: "V r m s equals V peak divided by the square root of 2. RMS voltage equals peak voltage over root two." ## What each symbol means - $V_{\text{rms}}$: **RMS voltage**, the root mean square value of an AC voltage, measured in volts (V). It is the steady DC voltage that gives the same heating effect. - $V_{\text{peak}}$: **Peak voltage**, the largest value the AC voltage reaches, measured in volts (V). ## What the formula is doing Mains electricity is alternating: the voltage rises, falls, goes negative and repeats. Its average over a full cycle is zero, so the average does not describe how much heat it can produce. Engineers use the root mean square, or RMS, value instead. To find the RMS value, square the voltage at each moment, take the average, then take the square root. For a sine wave the result is the peak voltage divided by $\sqrt{2}$: $V_{\text{rms}} = \frac{V_{\text{peak}}}{\sqrt{2}}$. The number $\sqrt{2}$ is about 1.414, so the RMS value is about 70.7% of the peak. The RMS value is the steady DC voltage that gives the same heating in a resistor. A 120 V rms supply heats a resistor as much as 120 V DC does, even though the AC voltage swings well above and below that number. Mains voltages are quoted as RMS values, not peak values. A 120 V supply in the US has a peak of about 170 V, and a 230 V supply in Europe has a peak of about 325 V. Insulation and components must handle the peak, not only the RMS value. ## An everyday picture Think of a stove burner that switches on and off very quickly. The average power, not the peak power, decides how hot a pan gets. RMS is the AC version of that idea: one effective number that matches the heating the voltage can produce. ## Worked example: Peak voltage of 120 V and 230 V mains A US outlet is rated at $120\ \text{V}$ rms, and a European outlet is rated at $230\ \text{V}$ rms. Find the peak voltage of each. 1. Rearrange the formula: $V_{\text{peak}} = V_{\text{rms}} \times \sqrt{2}$. 2. US: $V_{\text{peak}} = 120\ \text{V} \times 1.4142 \approx 169.7\ \text{V}$, which is about 170 V. 3. Europe: $V_{\text{peak}} = 230\ \text{V} \times 1.4142 \approx 325.3\ \text{V}$, which is about 325 V. 4. Check the US case: $169.7\ \text{V} / \sqrt{2} \approx 120\ \text{V}$, which returns the rms value. **Answer:** The US peak is about **170 V** and the European peak is about **325 V**. These peaks are why AC insulation must be rated well above the rms number on the label. ## Common mistakes - Using the peak value as if it were the RMS value, or the reverse. A 120 V rms supply is not a 120 V peak supply. - Averaging the AC voltage over a cycle to find its effective value. The average of a sine wave is zero, so the root mean square is needed instead. - Confusing peak with peak-to-peak. The peak-to-peak voltage of a 120 V rms supply is about 340 V, which is twice the peak. - Assuming a meter shows the peak voltage. Many AC meters read the rms value, so the peak is about 1.414 times larger. ## Where you will meet it - Mains voltage labels, where 120 V in the US and 230 V in Europe are rms values. - Choosing the voltage ratings of cables, capacitors and transformers, which must handle the peak voltage. - Power calculations for AC heaters and lamps, where the rms voltage gives the average power. - Audio and signal measurements, where an rms level describes the strength of a waveform. ## Questions people ask ### Why not use the average voltage? The average of a sine wave over a full cycle is zero, because the positive and negative halves cancel. The RMS value avoids that cancellation, so it measures the heating effect of the voltage. ### Is the RMS value the same for every waveform? No. The $1/\sqrt{2}$ rule works for a pure sine wave. A square wave, for example, has an RMS value equal to its peak. ### Why is it called 120 V if the voltage reaches about 170 V? Because 120 V is the rms value. The voltage reaches about 170 V at the peak of each half cycle, but its heating effect matches 120 V DC. ### Which value is on a mains label? The label usually gives the rms value, because that is the number that matches the power delivered. The peak is higher, and it sets the insulation and component ratings. ## Related formulas - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) - [Energy and Kilowatt-Hours](https://formulabro.yunusemrevurgun.com/electricity/energy-and-kilowatt-hours/) ## Sources - [Root mean square, Wikipedia](https://en.wikipedia.org/wiki/Root_mean_square) - [Mains electricity, Wikipedia](https://en.wikipedia.org/wiki/Mains_electricity) - [Alternating current, Wikipedia](https://en.wikipedia.org/wiki/Alternating_current) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # AC Power Factor > Power factor tells you what share of the current in an AC circuit does useful work, and it is the ratio of real power to apparent power. Page: https://formulabro.yunusemrevurgun.com/electricity/ac-power-factor/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P = V_{\text{rms}} I_{\text{rms}} \cos\varphi $$ Read it out loud: "P equals V r m s times I r m s times cos phi. Real power equals rms voltage times rms current times the cosine of phi." ## What each symbol means - $P$: **Real power**, the power that does useful work, such as heat or motion, measured in watts (W). - $V_{\text{rms}}$: **RMS voltage** of the supply, measured in volts (V). - $I_{\text{rms}}$: **RMS current** through the load, measured in amperes (A). - $\cos\varphi$: **Power factor**, the cosine of the phase angle $\varphi$ between voltage and current. It is a number from 0 to 1 with no unit. ## What the formula is doing In a DC circuit, power is voltage times current. In an AC circuit, the voltage and the current can be out of step. When a coil or a capacitor is part of the load, the current peaks at a different moment from the voltage. The phase angle $\varphi$ measures that delay, in degrees. Real power $P$ is the power that does useful work, in watts. It is found from the rms values and the cosine of the phase angle: $P = V_{\text{rms}} I_{\text{rms}} \cos\varphi$. The product $V_{\text{rms}} I_{\text{rms}}$ is the apparent power $S$, measured in volt-amperes (VA). The power factor is $\cos\varphi$, a number between 0 and 1. It equals $P/S$, the share of the apparent power that is real power. A power factor of 1 means the voltage and the current are in step, so all the apparent power does useful work. A power factor of 0.8 means only 80% of the apparent power is real power. The rest of the apparent power is reactive power, which moves back and forth between the source and the coil or capacitor and does no net work. Motors and transformers draw reactive power, which is why some utilities charge large customers extra for a low power factor. ## An everyday picture Think of a glass of beer with foam on top. The beer is the real power you can drink, the foam fills the glass but gives you nothing to drink, and the full glass is the apparent power. The power factor is the fraction of the glass that is beer. ## Worked example: A 120 V motor drawing 5 A at a power factor of 0.8 A motor runs on a 120 V rms supply and draws 5 A rms. Its power factor is 0.8. Find the apparent power, the real power and the reactive power. 1. Apparent power: $S = V_{\text{rms}} I_{\text{rms}} = 120\ \text{V} \times 5\ \text{A} = 600\ \text{VA}$. 2. Real power: $P = S \cos\varphi = 600\ \text{VA} \times 0.8 = 480\ \text{W}$. 3. Phase angle: $\varphi = \arccos(0.8) \approx 36.9^\circ$, so $\sin\varphi = 0.6$. 4. Reactive power: $Q = S \sin\varphi = 600\ \text{VA} \times 0.6 = 360\ \text{var}$. **Answer:** The apparent power is **600 VA**, the real power is **480 W** and the power factor is **0.8**. The remaining **360 var** is reactive power, which goes back and forth and does no net work. ## Common mistakes - Using $P = V I$ for an AC load with a power factor below 1. That product gives the apparent power, and the real power is smaller. - Mixing up VA and W. Volt-amperes measure apparent power and watts measure real power, and the two are equal only when the power factor is 1. - Using peak values in $P = V_{\text{rms}} I_{\text{rms}} \cos\varphi$. The formula needs the rms values for both the voltage and the current. - Thinking a low power factor means the device uses more energy. The extra current is reactive and returns to the source, but it still heats the supply wires. ## Where you will meet it - Utility bills and tariffs, where some large industrial customers pay extra for a low power factor. - Sizing cables, transformers and generators, which must carry the full apparent power in VA, not only the real power in W. - Power factor correction, where capacitors are added to a building or factory to offset the reactive power of motors. - Appliance and motor ratings, where a value in VA or a power factor tells you how much current the device draws. ## Questions people ask ### Why is apparent power bigger than real power? The current and the voltage are out of step, so part of the current carries reactive power that does no net work. Apparent power counts the whole product of the rms values. ### What is a var? A var, short for volt-ampere reactive, is the unit of reactive power. It is the part of the apparent power that does not do useful work. ### Does a power factor of 1 mean a device is efficient? It means the voltage and the current are in step, so all of the apparent power is real power. It does not tell you how much energy the device wastes as heat, which depends on its design. ### How is a low power factor improved? Power factor correction adds capacitors to a circuit with inductive loads, such as motors. The capacitors supply some of the reactive power locally, so less current flows through the supply wires. ## Related formulas - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [RMS Voltage](https://formulabro.yunusemrevurgun.com/electricity/rms-voltage/) - [Series RLC Impedance](https://formulabro.yunusemrevurgun.com/electricity/rlc-impedance/) ## Sources - [Power factor, Wikipedia](https://en.wikipedia.org/wiki/Power_factor) - [Reactive power, Wikipedia](https://en.wikipedia.org/wiki/Reactive_power) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Three-Phase Power > Three-phase power tells you how much real power a balanced three-wire AC load uses, and you get it from the line voltage, the line current and the power factor. Page: https://formulabro.yunusemrevurgun.com/electricity/three-phase-power/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P = \sqrt{3}\, V_L I_L \cos\varphi $$ Read it out loud: "P equals the square root of 3 times V L times I L times cos phi. Three-phase power equals root three times line voltage, times line current, times the cosine of phi." ## What each symbol means - $P$: **Real power** of the whole three-phase load, measured in watts (W). - $\sqrt{3}$: The square root of 3, about 1.732. It has no unit. - $V_L$: **Line voltage**, the voltage between two of the three line wires, measured in volts (V). - $I_L$: **Line current**, the current in one of the three line wires, measured in amperes (A). - $\cos\varphi$: **Power factor** of each phase, the cosine of the phase angle between voltage and current. It is a number from 0 to 1 with no unit. ## What the formula is doing A three-phase supply uses three alternating voltages, each a third of a cycle apart, carried on three wires. Factories and large motors use it because, for a balanced load, the total power is steady rather than pulsing, and the three wires carry more power for their size than a single-phase supply does. The formula $P = \sqrt{3}\, V_L I_L \cos\varphi$ uses line quantities. $V_L$ is the voltage between two line wires, and $I_L$ is the current in one line wire. The factor $\sqrt{3}$, about 1.732, comes from the 120 degree spacing of the three voltages: the voltage between two lines is $\sqrt{3}$ times the voltage from one line to neutral. The angle $\varphi$ is the phase angle of each phase, and $\cos\varphi$ is its power factor, as on the page on AC power factor. A balanced load means all three phases carry the same current and have the same power factor, so the numbers for one phase describe the whole load. The same formula works for both star (wye) and delta connections, as long as $V_L$ and $I_L$ are the line values measured on the wires. The voltages and currents inside the load are different, but you do not need them. ## An everyday picture Think of three rowers in a boat, each pulling with the same strength and taking turns in an even rhythm. Because they pull evenly, the boat moves along smoothly. A balanced three-phase load works the same way: three equal contributions from three wires add up to a steady total. ## Worked example: A 400 V three-phase motor drawing 10 A at a power factor of 0.8 A balanced three-phase motor is supplied at a line voltage of $V_L = 400\ \text{V}$. Each line draws $I_L = 10\ \text{A}$, and the power factor is $\cos\varphi = 0.8$. Find the real power. 1. Factor for three phases: $\sqrt{3} \approx 1.732$. 2. Multiply the line quantities: $\sqrt{3} \times 400\ \text{V} \times 10\ \text{A} \approx 6928\ \text{VA}$. 3. Multiply by the power factor: $6928\ \text{VA} \times 0.8 \approx 5543\ \text{W}$. 4. Convert to kilowatts: $5543\ \text{W} = 5.54\ \text{kW}$. **Answer:** The motor uses about **5.54 kW** of real power. Its apparent power is about **6.93 kVA**, and the power factor of 0.8 means the real power is 80% of that. ## Common mistakes - Using the voltage from one line to neutral as $V_L$. The formula needs the voltage between two lines, which is $\sqrt{3}$ times larger in a star-connected supply. - Using 3 instead of $\sqrt{3}$. That overstates the power by about 73%. - Using the formula for an unbalanced load. It assumes the three phases carry equal currents and have equal power factors. - Mixing up line current and phase current in a delta load. The formula uses the current in the line wire, which differs from the current inside each winding. ## Where you will meet it - Industrial motors and pumps, which are rated in kilowatts and run on a three-phase supply. - Power distribution in factories and large buildings, where three-phase supply carries heavy loads. - Sizing three-phase cables, breakers and transformers, which must carry the line current. - Heavy electric vehicle chargers and large heat pumps, which often run on a three-phase supply. ## Questions people ask ### What is line voltage? Line voltage is the voltage between two line wires. In a common European 400 V three-phase supply, the voltage from each line to neutral is about 230 V, while the voltage between two lines is 400 V. ### Why is three-phase power steady? The three voltages are spaced a third of a cycle apart. For a balanced load, the power from the three phases adds up to a steady total, instead of rising and falling with every cycle as single-phase power does. ### Is the formula different for a delta connection? The same formula works for both star and delta loads, because it uses the line values you measure on the wires. The voltages and currents inside the load are different, but you do not need them. ### Why do the line current and power factor both appear? The line current sets how much current flows in the wires, and the power factor sets how much of the apparent power is real power. Together they give the real power the load uses. ## Related formulas - [AC Power Factor](https://formulabro.yunusemrevurgun.com/electricity/ac-power-factor/) - [RMS Voltage](https://formulabro.yunusemrevurgun.com/electricity/rms-voltage/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) ## Sources - [Three-phase electric power, Wikipedia](https://en.wikipedia.org/wiki/Three-phase_electric_power) - [Power factor, Wikipedia](https://en.wikipedia.org/wiki/Power_factor) - [Electric power, Wikipedia](https://en.wikipedia.org/wiki/Electric_power) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Transformer Turns Ratio > A transformer changes an AC voltage up or down in the same ratio as the number of wire turns on its two coils. Page: https://formulabro.yunusemrevurgun.com/electricity/transformer-turns-ratio/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \frac{V_s}{V_p} = \frac{N_s}{N_p} $$ Read it out loud: "V sub s over V sub p equals N sub s over N sub p. The secondary voltage divided by the primary voltage equals the secondary turns divided by the primary turns." ## What each symbol means - $V_s$: **Secondary voltage**, the voltage across the output coil, measured in volts (V). - $V_p$: **Primary voltage**, the voltage across the input coil, measured in volts (V). - $N_s$: **Secondary turns**, the number of wire loops on the output coil. Turns are counted, so this has no unit. - $N_p$: **Primary turns**, the number of wire loops on the input coil. Turns are counted, so this has no unit. - $I_s$: **Secondary current**, the current in the output coil, measured in amperes (A). - $I_p$: **Primary current**, the current in the input coil, measured in amperes (A). ## What the formula is doing A transformer has two coils of wire wound on a shared iron core. The **primary** coil is connected to the input, and the **secondary** coil feeds the output. The formula links the voltage on each coil to the number of turns on it: $V_s / V_p = N_s / N_p$. Here $V$ is in volts (V), and $N$ counts loops of wire, so it has no unit. The ratio of the voltages equals the ratio of the turns. A secondary with ten times as many turns gives ten times the voltage. A secondary with one tenth the turns gives one tenth the voltage. The transformer is a **step-up** transformer when $N_s > N_p$ and a **step-down** transformer when $N_s < N_p$. Currents go the other way. For an ideal transformer, $I_s / I_p = N_p / N_s$, with the currents in amperes (A). A step-up transformer raises the voltage and lowers the current by the same factor, so the power on the two sides stays the same. An ideal transformer loses nothing in the core or the wire, so the power in equals the power out. Real transformers lose some power as heat. A transformer works only with AC, or with any voltage that keeps changing. A changing current in the primary makes a changing magnetic field in the core, and that changing field induces a voltage in the secondary. A steady DC current makes a steady field, which induces nothing, so the secondary voltage is zero. ## An everyday picture Think of the gears on a bicycle. A large front gear turning a small back gear makes the wheel spin fast with little force, and a small front gear turning a large back gear makes it turn slowly with more force. A transformer trades voltage against current in the same way that the gears trade speed against force, and the power on each side stays about the same. ## Worked example: Stepping 120 V down to 12 V The primary coil of a transformer has $N_p = 500$ turns and sits on a 120 V AC supply. The primary draws $I_p = 0.5\ \text{A}$. The secondary coil has $N_s = 50$ turns. Find the secondary voltage and current, then check the power on each side. 1. Find the secondary voltage from the turns: $V_s = V_p \times \frac{N_s}{N_p} = 120\ \text{V} \times \frac{50}{500} = 12\ \text{V}$. 2. Find the secondary current from the current rule: $I_s = I_p \times \frac{N_p}{N_s} = 0.5\ \text{A} \times \frac{500}{50} = 5\ \text{A}$. 3. Check the power on the input side: $P_{\text{in}} = V_p I_p = 120\ \text{V} \times 0.5\ \text{A} = 60\ \text{W}$. 4. Check the power on the output side: $P_{\text{out}} = V_s I_s = 12\ \text{V} \times 5\ \text{A} = 60\ \text{W}$. **Answer:** The secondary delivers **12 V** and **5 A**. The voltage went down by a factor of 10, and the current went up by the same factor. Both sides carry **60 W**, which is what an ideal transformer should do. ## Common mistakes - Using the voltage rule for the current. The voltage follows $N_s / N_p$ directly, but the current follows the flipped ratio $N_p / N_s$. Using the wrong one gives a current that is off by the square of the turns ratio, here a factor of 100. - Expecting a transformer to make energy. The power out can never be bigger than the power in, so a step-up transformer trades current for voltage. - Using a transformer with DC. A steady current makes a steady field, which induces no voltage in the secondary. - Mixing up the coils. The primary is the input coil, whatever its voltage is. Name the coils by how they are connected, not by their size. ## Where you will meet it - Power grids, where transformers step the voltage up for long-distance transmission and back down for homes. - Phone and laptop chargers, which step mains voltage down to a low voltage before rectifying it. - Doorbells and some toy power supplies, which use a small step-down transformer on the mains. - Welding equipment, where a transformer supplies the high current that a weld needs at a low voltage. ## Questions people ask ### Why does a transformer need AC? The secondary coil only gets a voltage when the magnetic field through it changes. AC keeps the field changing, while DC gives a steady field that induces nothing. ### If the voltage goes up, does the current go up too? No. For an ideal transformer the current goes the other way. A step-up transformer raises the voltage and lowers the current, so the power stays the same. ### Is a transformer the same as a generator? No. A generator turns mechanical energy into electrical energy. A transformer takes AC electrical energy that already exists and changes its voltage and current. ## Related formulas - [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/) - [Electric Power](https://formulabro.yunusemrevurgun.com/electricity/electric-power/) - [RMS Voltage](https://formulabro.yunusemrevurgun.com/electricity/rms-voltage/) - [Ohm's Law](https://formulabro.yunusemrevurgun.com/electricity/ohms-law/) ## Sources - [Transformer, Wikipedia](https://en.wikipedia.org/wiki/Transformer) - [Faraday's law of induction, Wikipedia](https://en.wikipedia.org/wiki/Faraday%27s_law_of_induction) - [Electric power transmission, Wikipedia](https://en.wikipedia.org/wiki/Electric_power_transmission) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Electric Field of a Point Charge > The electric field around a charge tells you the push that a small test charge would feel at each point in space. Page: https://formulabro.yunusemrevurgun.com/electricity/electric-field-of-point-charge/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E = \frac{k_e\, q}{r^2} $$ Read it out loud: "E equals k sub e times q, divided by r squared. The electric field equals the Coulomb constant times the charge, divided by the distance squared." ## What each symbol means - $E$: **Electric field**, the force per unit charge at a point, measured in newtons per coulomb (N/C). The same unit is volts per meter (V/m). - $k_e$: The **Coulomb constant**, $k_e = 8.9875517923 \times 10^{9}\ \text{N}\,\text{m}^2/\text{C}^2$. It sets the scale of the electric force in SI units. - $q$: The **source charge**, the charge that creates the field, measured in coulombs (C). Its size sets the strength, and its sign sets the direction. - $r$: The **distance** from the source charge to the point where the field is measured, in meters (m). ## What the formula is doing A **point charge** creates an electric field in the space around it. The field at a point is the force a small test charge would feel there, divided by the size of that test charge: $E = F / q_0$, where $q_0$ is the test charge. The field is a property of the space itself, not of the test charge. Its unit is newtons per coulomb (N/C), which is the same as volts per meter (V/m). The formula gives the size of the field a distance $r$, in meters (m), from a charge $q$, in coulombs (C). Double the charge and the field doubles. Double the distance and the field drops to one quarter, because $r$ is squared. The Coulomb constant $k_e$ sets the scale in SI units. The direction follows the sign of $q$. A positive charge pushes a positive test charge away, so the field points away from a positive source and toward a negative one. A tiny positive test charge placed near a positive source would be pushed outward, and the field arrows at that point point the same way. When several charges are present, their fields add as vectors. Each charge makes its own field, and the total at any point is the sum of those fields. The formula on this page gives the field of one point charge at a time. ## An everyday picture Think of a wind map over a city. At every spot there is a wind speed and a direction, even if nobody is standing there. The electric field is the same kind of map: at each point it says how hard, and which way, a charge placed there would be pushed. Near a strong source the arrows are long, and farther away they shrink quickly. ## Worked example: Field 0.5 m from a 2 microcoulomb charge A point charge of $q = 2\ \mu\text{C}$ (which is $2 \times 10^{-6}$ C) sits in empty space. Find the electric field at a point 0.5 m away. Then find the force on a 3 microcoulomb charge placed at that point. 1. Square the distance: $r^2 = (0.5\ \text{m})^2 = 0.25\ \text{m}^2$. 2. Put the numbers into the formula: $E = 8.9875517923 \times 10^{9} \times \frac{2 \times 10^{-6}\ \text{C}}{0.25\ \text{m}^2} \approx 7.19 \times 10^{4}\ \text{N/C}$. 3. Use the field to find the force on the 3 microcoulomb charge: $F = qE = (3 \times 10^{-6}\ \text{C}) \times (7.19 \times 10^{4}\ \text{N/C}) \approx 0.216\ \text{N}$. **Answer:** The field at 0.5 m is about $7.19 \times 10^{4}$ N/C, pointing away from the positive charge. A 3 microcoulomb charge placed there would feel a force of about **0.216 N**, pushing it away from the source. ## Common mistakes - Using microcoulombs as if they were coulombs. Write 2 microcoulombs as $2 \times 10^{-6}$ C, or the field comes out a million times too big. - Forgetting that the field falls off with $r^2$. Doubling the distance cuts the field to one quarter, not one half. - Mixing up the field and the force. The field is the force per unit charge, so the force on a charge is $F = qE$. - Giving the field a direction from its size alone. The sign of the source charge sets the direction, so a positive source points its field outward. ## Where you will meet it - Designing high-voltage equipment, where the field strength decides when air breaks down and a spark jumps. - Electron microscopes and particle accelerators, which use electric fields to steer and speed up charged particles. - Electrostatic precipitators in smokestacks, which charge dust particles and pull them out of the smoke. - Static electricity experiments, such as measuring the field around a charged balloon. ## Questions people ask ### Why is the field measured in N/C? The field is a force divided by a charge. Newtons divided by coulombs gives newtons per coulomb, and $1\ \text{N/C} = 1\ \text{V/m}$. ### Does the field depend on the test charge? No. The test charge is only used to measure the field. At a given point the field is set by the source charge and the distance, so it is a property of the space. ### Which way does the field point near a negative charge? Toward the charge. A positive test charge is pulled in, so the field arrows point inward. ## Related formulas - [Coulomb's Law](https://formulabro.yunusemrevurgun.com/electricity/coulombs-law/) - [Electric Potential](https://formulabro.yunusemrevurgun.com/electricity/electric-potential/) - [Charge and Current](https://formulabro.yunusemrevurgun.com/electricity/charge-and-current/) - [Parallel-Plate Capacitor](https://formulabro.yunusemrevurgun.com/electricity/parallel-plate-capacitor/) ## Sources - [Electric field, Wikipedia](https://en.wikipedia.org/wiki/Electric_field) - [Coulomb's law, Wikipedia](https://en.wikipedia.org/wiki/Coulomb%27s_law) - [Electric charge, Wikipedia](https://en.wikipedia.org/wiki/Electric_charge) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Electric Potential > Electric potential tells you how much energy each unit of charge would have at a spot in space, measured in volts. Page: https://formulabro.yunusemrevurgun.com/electricity/electric-potential/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ V = \frac{k_e\, q}{r} $$ Read it out loud: "V equals k sub e times q, divided by r. The electric potential equals the Coulomb constant times the charge, divided by the distance." ## What each symbol means - $V$: **Electric potential**, the energy per unit charge at a point, measured in volts (V). One volt is one joule per coulomb. - $k_e$: The **Coulomb constant**, $k_e = 8.9875517923 \times 10^{9}\ \text{N}\,\text{m}^2/\text{C}^2$. - $q$: The **source charge**, the charge that creates the potential, measured in coulombs (C). Its sign sets whether the potential is positive or negative. - $r$: The **distance** from the source charge to the point, measured in meters (m). - $\Delta U$: The **change in potential energy** of a charge moved between two points, measured in joules (J). - $\Delta V$: The **change in potential** between two points, measured in volts (V). It is the final potential minus the starting potential. ## What the formula is doing **Electric potential** $V$ is the potential energy per unit charge at a point. It answers the question: how much energy would each coulomb of charge have at this spot? Its unit is the volt (V), where $1\ \text{V} = 1\ \text{J/C}$. The usual reference is zero at a very large distance, so the formula for a point charge is written with $V = 0$ far away. For a point charge the potential is $V = k_e q / r$, with $q$ in coulombs (C) and $r$ in meters (m). The potential falls off as $1/r$, which is slower than the $1/r^2$ of the electric field. Double the distance and the potential halves. A positive source gives a positive potential, and a negative source gives a negative one. The energy involved in moving a charge depends on the change in potential. Moving a charge $q$ from one point to another changes its potential energy by $\Delta U = q\,\Delta V$, where $\Delta U$ is in joules (J) and $\Delta V$ is in volts (V). If $\Delta U$ is negative, the field does work on the charge and its energy drops. If $\Delta U$ is positive, an outside agent must do work to move the charge. Potential is a scalar, a single number at each point, so the potentials of several charges add directly. The electric field is a vector with a direction, and it can be found from how fast the potential changes with distance. ## An everyday picture Think of a ball on a hill. Height is like potential: a ball at the top has more stored energy than one at the bottom. The energy the ball gains or loses depends only on how far up or down it moves, not on the path it takes. Moving a charge between two points with different potentials works the same way, and the energy change is the charge times the difference in potential. ## Worked example: Potential energy change for a charge moved outward A point charge of $q = 5\ \text{nC}$ (which is $5 \times 10^{-9}$ C) sits at the origin. A positive charge of $2\ \mu\text{C}$ starts 0.10 m away and is moved out to 0.50 m. Find the potential at each distance, then the change in potential energy of the 2 microcoulomb charge. 1. Find the potential at 0.10 m: $V_1 = 8.9875517923 \times 10^{9} \times \frac{5 \times 10^{-9}}{0.10} \approx 449.4\ \text{V}$. 2. Find the potential at 0.50 m: $V_2 = 8.9875517923 \times 10^{9} \times \frac{5 \times 10^{-9}}{0.50} \approx 89.9\ \text{V}$. 3. Find the change in potential: $\Delta V = V_2 - V_1 \approx 89.9\ \text{V} - 449.4\ \text{V} = -359.5\ \text{V}$. 4. Multiply by the charge: $\Delta U = q\,\Delta V = (2 \times 10^{-6}\ \text{C}) \times (-359.5\ \text{V}) \approx -7.19 \times 10^{-4}\ \text{J}$. **Answer:** The potential energy of the 2 microcoulomb charge drops by about **$7.19 \times 10^{-4}$ J**, which is 0.719 millijoules. The negative sign means the repulsion from the source pushes the charge outward and does work on it, so the charge loses stored energy. ## Common mistakes - Using 10 for the distance of 10 cm. Convert to 0.10 m first, or the potential comes out 100 times too small. - Mixing up potential and potential energy. Potential is in volts and belongs to a point in space, while potential energy is in joules and belongs to a charge at that point. - Forgetting the sign of $\Delta V$. It is final minus initial, so moving toward a lower potential gives a negative change. - Adding potentials and fields the same way. Potentials are single numbers that add directly, while fields are vectors that must be added with their directions. ## Where you will meet it - Battery ratings, where one volt means one joule of energy for each coulomb of charge moved through the circuit. - Lightning and spark gaps, where the potential difference between a cloud and the ground drives the discharge. - Capacitors and high-voltage power supplies, which store energy in the potential difference between their terminals. - Cell membranes in biology, where the potential difference across the membrane helps drive nerve signals. ## Questions people ask ### Why is the potential taken as zero far away? That is the usual reference point for a point charge. Only differences in potential matter for energy, so the choice of zero does not change the energy change. ### Is voltage the same as electric potential? Almost. Electric potential at a point is measured in volts, and voltage is usually used for the potential difference between two points, such as the two ends of a battery. ### Why does the potential fall off as $1/r$ and not $1/r^2$? The field has $r^2$ in its denominator. The potential is the work per unit charge needed to bring a charge in from far away, and that work adds up along the whole path, which leaves one power of $r$. ## Related formulas - [Electric Field of a Point Charge](https://formulabro.yunusemrevurgun.com/electricity/electric-field-of-point-charge/) - [Coulomb's Law](https://formulabro.yunusemrevurgun.com/electricity/coulombs-law/) - [Energy Stored in a Capacitor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-capacitor/) ## Sources - [Electric potential, Wikipedia](https://en.wikipedia.org/wiki/Electric_potential) - [Electric potential energy, Wikipedia](https://en.wikipedia.org/wiki/Electric_potential_energy) - [Volt, Wikipedia](https://en.wikipedia.org/wiki/Volt) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Magnetic Force on a Moving Charge > A magnetic field pushes a moving charge sideways, and the push is biggest when the charge moves straight across the field lines. Page: https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ F = |q|\, v\, B \sin\theta $$ Read it out loud: "F equals the size of q times v times B times the sine of theta. The magnetic force equals the size of the charge, times the speed, times the field strength, times the sine of the angle between the velocity and the field." ## What each symbol means - $F$: **Magnetic force**, the size of the push on the charge, measured in newtons (N). - $|q|$: The **size of the charge**, measured in coulombs (C). Only the size goes into the formula; the sign of the charge sets the direction. - $v$: The **speed** of the charge, measured in meters per second (m/s). - $B$: The **magnetic field strength**, measured in tesla (T). One tesla is one newton per ampere per meter. - $\theta$: The **angle** between the velocity and the magnetic field. At 90 degrees the sine is 1, the largest push. At 0 degrees the sine is 0, and there is no push. ## What the formula is doing A magnetic field $B$, measured in tesla (T), exerts a force only on a charge that is moving. A charge at rest feels no magnetic force. The charge $|q|$ is measured in coulombs (C), and the speed $v$ is in meters per second (m/s). The bars around $q$ mean we use only the size of the charge here. The force is largest when the velocity is at right angles to the field, where $\sin\theta = 1$. If the charge moves along the field lines, $\theta = 0$ and the force is zero. At angles in between, only the part of the motion across the field matters. The force always points at right angles to both the velocity and the field. It never does work on the charge, so it can change the direction of motion but not the speed. A charge moving across a uniform field therefore travels in a circle, which is the principle behind cyclotrons and mass spectrometers. The direction follows the **right-hand rule**. In vector form the force is $\vec{F} = q\,\vec{v} \times \vec{B}$. Point your fingers along the velocity, curl them toward the field, and your thumb points where a positive charge is pushed. A negative charge, such as an electron, is pushed the opposite way. ## An everyday picture Think of a ball on a string swung in a circle. The string pulls sideways to the motion, so it bends the path without changing the speed. A magnetic field acts on a moving charge in the same way, pushing sideways and bending the path into a curve. ## Worked example: Electron crossing a magnetic field An electron moves at $v = 2.0 \times 10^{6}$ m/s through a uniform magnetic field of $B = 0.5$ T. The size of its charge is $|q| = e = 1.602176634 \times 10^{-19}$ C. Find the magnetic force when the electron moves at right angles to the field, then when it moves at 30 degrees to the field. 1. At 90 degrees, $\sin 90^\circ = 1$, so $F = |q|\, v\, B \sin 90^\circ = (1.602 \times 10^{-19}\ \text{C})(2.0 \times 10^{6}\ \text{m/s})(0.5\ \text{T})(1)$. 2. Multiply: $F = 1.602 \times 10^{-13}\ \text{N}$. 3. At 30 degrees, $\sin 30^\circ = 0.5$, so the force is half as big: $F = 1.602 \times 10^{-13}\ \text{N} \times 0.5 \approx 8.01 \times 10^{-14}\ \text{N}$. **Answer:** At right angles the magnetic force on the electron is about **$1.60 \times 10^{-13}$ N**. At 30 degrees it drops to about **$8.01 \times 10^{-14}$ N**. The force is tiny in everyday terms, but an electron has so little mass that this force bends its path strongly. ## Common mistakes - Entering the angle in degrees into a calculator set to radians. Entering 90 gives a sine of 0.89 instead of 1, so set the mode to degrees or convert to radians first. - Expecting a charge at rest to feel a magnetic force. Only moving charges feel this push. - Forgetting the sine. The force is zero when the charge moves along the field lines, which a formula without the sine would miss. - Mixing up the direction. The right-hand rule gives the direction for a positive charge, and an electron is pushed the opposite way. ## Where you will meet it - Cyclotrons and other particle accelerators, which bend charged particles into circles with magnetic fields. - Mass spectrometers, which sort ions by how much their paths bend in a magnetic field. - Older cathode ray tube screens, which steer the electron beam with magnetic fields. - Auroras, where charged particles from the Sun are funneled by Earth's magnetic field toward the poles. ## Questions people ask ### Why does a magnetic field not speed up a charge? The force is always at right angles to the motion, so it does no work on the charge. It can change the direction of travel, but it cannot change the kinetic energy. ### What is a tesla? The SI unit of magnetic field strength. Earth's magnetic field at the surface is only tens of microtesla, so a tesla is a very strong field. ### Why does the force vanish when the charge moves along the field? The sine of 0 degrees is zero. When the motion is parallel to the field there is no sideways push to bend the path. ## Related formulas - [Force on a Current-Carrying Wire](https://formulabro.yunusemrevurgun.com/electricity/force-on-current-carrying-wire/) - [Magnetic Field of a Straight Wire](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire/) - [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/) - [Electric Field of a Point Charge](https://formulabro.yunusemrevurgun.com/electricity/electric-field-of-point-charge/) ## Sources - [Lorentz force, Wikipedia](https://en.wikipedia.org/wiki/Lorentz_force) - [Right-hand rule, Wikipedia](https://en.wikipedia.org/wiki/Right-hand_rule) - [Elementary charge, Wikipedia](https://en.wikipedia.org/wiki/Elementary_charge) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Force on a Current-Carrying Wire > A wire carrying current is pushed sideways by a magnetic field, and the push grows with the current, the wire length and the field strength. Page: https://formulabro.yunusemrevurgun.com/electricity/force-on-current-carrying-wire/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ F = B\, I\, L \sin\theta $$ Read it out loud: "F equals B times I times L times the sine of theta. The force equals the magnetic field times the current times the length of the wire in the field, times the sine of the angle." ## What each symbol means - $F$: **Force** on the wire, measured in newtons (N). - $B$: **Magnetic field strength**, measured in tesla (T). - $I$: **Current** in the wire, measured in amperes (A). - $L$: **Length** of the wire that lies inside the field, measured in meters (m). - $\theta$: The **angle** between the wire and the magnetic field. The force is biggest when the wire is at right angles to the field and zero when it runs along the field. ## What the formula is doing A current is a stream of moving charges, so each charge in the wire feels the magnetic force described on the moving-charge page. Add up the forces on all the charges along the wire and you get the force on the whole wire. The formula $F = B I L \sin\theta$ gives that total in newtons (N), with $B$ in tesla (T), $I$ in amperes (A) and $L$ in meters (m). Each factor counts in the same way. Double the current and the force doubles, because twice as much charge passes through the field each second. Double the length inside the field and the force doubles, because twice as many charges are pushed. Double the field strength and the force doubles as well. The sine sets how much of the wire is pushed. A wire at right angles to the field feels the full push, and a wire that lies along the field feels none. The force is at right angles to both the wire and the field. The direction follows the right-hand rule: point the fingers of your right hand along the current, curl them toward the field, and your thumb points along the force. This is the basis of the electric motor. A coil carrying current sits between magnets, and the two sides of the coil feel forces in opposite directions. Those forces create a turning effect, called torque, that spins the shaft. Each side of the coil obeys this formula. ## An everyday picture Think of a crowd of walkers in a long hallway, all moving in the same direction, with a wind blowing sideways across the hall. The total sideways push depends on how many people walk past each second, how long the section of hallway is and how hard the wind blows. A wire is a hallway full of moving charges, and the magnetic field is the wind. ## Worked example: Force on a 30 cm wire carrying 5 A A straight wire 0.30 m long carries a current of 5 A. It sits in a uniform magnetic field of 0.2 T. Find the force when the wire is at right angles to the field, then when it is tilted to 30 degrees from the field direction. 1. At 90 degrees, $\sin 90^\circ = 1$, so $F = B I L \sin 90^\circ = (0.2\ \text{T})(5\ \text{A})(0.30\ \text{m})(1)$. 2. Multiply: $F = 0.30\ \text{N}$. 3. At 30 degrees, $\sin 30^\circ = 0.5$, so the force is half as big: $F = 0.30\ \text{N} \times 0.5 = 0.15\ \text{N}$. **Answer:** At right angles the wire feels a force of **0.30 N**, and at 30 degrees it feels **0.15 N**. The force pushes the wire sideways, not along its length. ## Common mistakes - Using the full length of the wire when only part of it is in the field. Only the length inside the field counts for $L$. - Forgetting the sine. A wire lying along the field feels no force, even though it carries current. - Assuming the force points along the wire. The force is at right angles to both the wire and the field, so it pushes the wire sideways. - Using a field in gauss without converting. One tesla equals $10^4$ gauss, so a field of 2000 gauss is 0.2 T. ## Where you will meet it - Electric motors in fans, drills, electric cars and many appliances, where forces on a coil turn the shaft. - Loudspeakers, where a voice coil sits in a magnet and is pushed back and forth by the current that carries the sound signal. - Moving-coil meters, which swing a needle in proportion to the current in a coil. - Hard disk drive actuators, where a coil in a magnet swings the read head across the disk. ## Questions people ask ### Why is the wire pushed sideways? Each moving charge in the wire feels a force at right angles to its motion and to the field. Together these forces push the whole wire sideways. ### How does this relate to the force on a single moving charge? Summing the forces on all the charges in a length $L$ of wire turns the single-charge force $qvB\sin\theta$ into $ILB\sin\theta$, because the current counts how many charges pass each second. ### What happens if I reverse the current? The force reverses too. Reversing the field also reverses it, but reversing both leaves the push in the same direction. ## Related formulas - [Magnetic Force on a Moving Charge](https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge/) - [Magnetic Field of a Straight Wire](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire/) - [Magnetic Field of a Solenoid](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid/) - [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/) ## Sources - [Electric motor, Wikipedia](https://en.wikipedia.org/wiki/Electric_motor) - [Lorentz force, Wikipedia](https://en.wikipedia.org/wiki/Lorentz_force) - [Magnetic field, Wikipedia](https://en.wikipedia.org/wiki/Magnetic_field) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Magnetic Field of a Straight Wire > A current in a straight wire makes a magnetic field that wraps around the wire, and the field gets weaker the farther away you measure it. Page: https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ B = \frac{\mu_0 I}{2\pi r} $$ Read it out loud: "B equals mu sub zero times I, divided by 2 pi times r. The magnetic field equals the permeability of free space times the current, divided by two pi times the distance." ## What each symbol means - $B$: **Magnetic field**, measured in tesla (T). The field lines are circles around the wire. - $\mu_0$: The **permeability of free space**, $\mu_0 = 1.25663706212 \times 10^{-6}\ \text{N/A}^2$. It sets how strongly a current makes a magnetic field in vacuum. - $I$: **Current** in the wire, measured in amperes (A). - $r$: **Distance** from the wire to the point where the field is measured, measured in meters (m). ## What the formula is doing A current in a wire creates a magnetic field in the space around it. For a long straight wire, the field lines are circles centered on the wire, lying in planes at right angles to it. The field $B$ is measured in tesla (T), the current $I$ in amperes (A) and the distance $r$ in meters (m). The field is proportional to the current. Double $I$ and $B$ doubles. The constant $\mu_0 = 1.25663706212 \times 10^{-6}\ \text{N/A}^2$ sets the strength of magnetism in vacuum. The $2\pi r$ in the bottom is the length of the circle of field lines around the wire at distance $r$. The field falls off as $1/r$, which is more slowly than the $1/r^2$ of an electric point charge. Double the distance and the field halves. The direction is given by the right-hand rule: point your thumb along the current, and your fingers curl in the direction of the field. The formula is for a long, straight wire, so that its ends are far away. For a wire with a round cross-section carrying current evenly, measure $r$ from the center of the wire. ## An everyday picture Picture the rings that spread out when a stone drops into a pond, but laid around a straight wire instead of across the water. Each ring circles the wire, and the rings weaken as you move farther out. The rings turn in a direction set by the current, like a screw turning as it moves in the direction of the current. ## Worked example: Field of a 10 A wire at two distances A long straight wire carries a steady current of $I = 10$ A. Find the magnetic field 5 cm from the wire, then the field 10 cm from the wire. 1. Convert the first distance: $r = 5\ \text{cm} = 0.05\ \text{m}$. 2. Put the numbers into the formula: $B = \frac{(1.25663706212 \times 10^{-6}\ \text{N/A}^2)(10\ \text{A})}{2\pi\,(0.05\ \text{m})} \approx 4.0 \times 10^{-5}\ \text{T}$. 3. At 10 cm, $r = 0.10$ m is twice as far, so the field is half as big: $B = \frac{4.0 \times 10^{-5}\ \text{T}}{2} = 2.0 \times 10^{-5}\ \text{T}$. **Answer:** At 5 cm the field is about **$4.0 \times 10^{-5}$ T**, which is 40 microtesla. At 10 cm it is about **$2.0 \times 10^{-5}$ T**. Doubling the distance halved the field, as the $1/r$ rule predicts. ## Common mistakes - Forgetting the $2\pi$. The field lines form a circle of length $2\pi r$ around the wire, so the factor belongs in the bottom of the fraction. - Using a diameter where a distance from the wire's center is needed. Check which one you have before you plug it in. - Using the point-charge rule. The field of a wire falls as $1/r$, not $1/r^2$, so doubling the distance halves the field instead of cutting it to a quarter. - Mixing up the field with the force it causes. The field is measured in tesla, and a force needs a charge or a second current inside that field. ## Where you will meet it - Clamp meters, which measure the current in a wire from the field around it without cutting the wire. - Twisted-pair network cables, where the fields of neighboring wires largely cancel to reduce interference. - Power lines and substations, where engineers estimate the magnetic field near the wires for safety and interference checks. - Circuit board layout, where designers check traces for stray magnetic fields that could disturb sensors. ## Questions people ask ### What is the unit of magnetic field strength? The tesla (T). It equals one newton per ampere per meter, so $1\ \text{T} = 1\ \text{N/(A m)}$. ### Why does the field go around the wire instead of pointing at it? A magnetic field has no source point like an electric charge. Its field lines form closed loops, and for a straight wire those loops are circles around the current. ### Does the wire's material change the field? The formula assumes vacuum or air, which is close enough for most wires. Only strongly magnetic material near the wire changes the result. ## Related formulas - [Magnetic Field of a Solenoid](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid/) - [Force on a Current-Carrying Wire](https://formulabro.yunusemrevurgun.com/electricity/force-on-current-carrying-wire/) - [Magnetic Force on a Moving Charge](https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge/) - [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/) ## Sources - [Biot-Savart law, Wikipedia](https://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law) - [Ampere's circuital law, Wikipedia](https://en.wikipedia.org/wiki/Amp%C3%A8re%27s_circuital_law) - [Vacuum permeability, Wikipedia](https://en.wikipedia.org/wiki/Vacuum_permeability) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Magnetic Field of a Solenoid > A long coil of wire makes a strong, nearly uniform magnetic field along its middle, and the field depends on how many turns are packed into each meter. Page: https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ B = \mu_0\, n\, I $$ Read it out loud: "B equals mu sub zero times n times I. The magnetic field equals the permeability of free space times the turns per meter times the current." ## What each symbol means - $B$: **Magnetic field** inside the solenoid, measured in tesla (T). - $\mu_0$: The **permeability of free space**, $\mu_0 = 1.25663706212 \times 10^{-6}\ \text{N/A}^2$. - $n$: The **turns per meter**, the number of wire loops in each meter of coil length, measured in 1/m. It equals $n = N / L$. - $I$: **Current** in the wire, measured in amperes (A). - $N$: The **total number of turns** in the coil. Turns are counted, so this has no unit. - $L$: The **length** of the coil along its axis, measured in meters (m). ## What the formula is doing A **solenoid** is a coil of wire wound into a helix that is long compared with its diameter. A current $I$, in amperes (A), flowing through the coil makes a magnetic field along its axis. Inside a long solenoid the field is nearly uniform and points along the axis, which is why solenoids are used to build magnets. The field depends on $n$, the number of turns per meter. Count the total turns $N$ and divide by the length $L$ in meters: $n = N / L$, measured in 1/m. Packing the same number of turns into a shorter coil raises $n$ and so raises the field. For a long solenoid the diameter of the coil does not appear in the formula. The field is proportional to the current. Double $I$ and the field doubles. The field inside a long solenoid is strong, while the field outside is much weaker. This is an ideal formula. It assumes the solenoid is long compared with its diameter and that you measure well inside it, away from the ends. Near the ends the field drops off, and the formula overestimates it there. The direction follows the right-hand rule: curl the fingers of your right hand along the current, and your thumb points along the field inside the coil. ## An everyday picture Imagine a rope wound around a pencil, with each loop the same size. Each loop adds its own small field, and along the middle the fields line up and add together. Pack more loops into each meter and the total grows, which is why $n$ sits in the formula. ## Worked example: Field inside a 25 cm coil with 500 turns A solenoid has $N = 500$ turns spread evenly over a length of $L = 0.25$ m, and it carries $I = 2$ A. Find the magnetic field inside the coil. 1. Find the turns per meter: $n = \frac{N}{L} = \frac{500}{0.25\ \text{m}} = 2000\ \text{turns/m}$. 2. Put the numbers into the formula: $B = \mu_0 n I = (1.25663706212 \times 10^{-6}\ \text{N/A}^2)(2000\ \text{turns/m})(2\ \text{A})$. 3. Multiply: $B \approx 5.03 \times 10^{-3}\ \text{T}$. **Answer:** The field inside the coil is about **$5.03 \times 10^{-3}$ T**, or 5.03 millitesla. It is nearly uniform along the middle of the coil, and doubling the current would double it. ## Common mistakes - Using the total turns $N$ instead of turns per meter $n$. With $L = 0.25$ m, that makes the field four times too small. - Using centimeters for the length. Convert 25 cm to 0.25 m before dividing, or $n$ is off by a factor of 100. - Using the formula at the ends or outside the coil. It describes the field inside a long coil, near its middle. - Expecting the coil's width to matter. In the ideal formula, the field depends only on $n$ and $I$, so a wider coil with the same turns per meter and current has the same field. ## Where you will meet it - MRI scanners, whose superconducting magnets are large solenoids that make a strong, uniform field for imaging. - Solenoid valves in washing machines, car fuel systems and irrigation systems, where the field pulls a plunger. - Relays and contactors, which use a small current in a coil to close a switch carrying a larger current. - Electromagnets for lifting scrap metal, which are coils wound around an iron core. ## Questions people ask ### Why does the solenoid need to be long? The formula assumes a long coil so that the field is nearly uniform in the middle. A short coil has a weaker field, and its ends change the field a lot. ### What does turns per meter mean? It is the number of loops in each meter of coil length. A coil with 1000 turns over 0.5 m has $n = 2000$ turns/m. ### Does an iron core change the field? Yes. The formula is for air or vacuum. An iron core is a magnetic material that strengthens the field a lot, which is why electromagnets use one. ## Related formulas - [Magnetic Field of a Straight Wire](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-straight-wire/) - [Faraday's Law of Induction](https://formulabro.yunusemrevurgun.com/electricity/faradays-law/) - [Energy Stored in an Inductor](https://formulabro.yunusemrevurgun.com/electricity/energy-stored-in-inductor/) - [Inductor Voltage](https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage/) ## Sources - [Solenoid, Wikipedia](https://en.wikipedia.org/wiki/Solenoid) - [Magnetic field, Wikipedia](https://en.wikipedia.org/wiki/Magnetic_field) - [Vacuum permeability, Wikipedia](https://en.wikipedia.org/wiki/Vacuum_permeability) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Faraday's Law of Induction > A changing magnetic field through a loop of wire pushes a voltage into the wire, and that is how generators make electricity. Page: https://formulabro.yunusemrevurgun.com/electricity/faradays-law/ Category: Electricity Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \varepsilon = -N\, \frac{d\Phi_B}{dt} $$ Read it out loud: "epsilon equals minus N times d Phi B over d t. The induced voltage equals minus the number of turns times the rate of change of the magnetic flux." ## What each symbol means - $\varepsilon$: The **induced emf**, the voltage pushed around the loop, measured in volts (V). - $N$: The **number of turns** of wire in the coil. Turns are counted, so this has no unit. - $\Phi_B$: The **magnetic flux** through one turn of the coil, measured in webers (Wb). One weber is one tesla times one square meter. - $t$: **Time**, measured in seconds (s). - $B$: **Magnetic field strength**, measured in tesla (T). - $A$: **Area** of the loop, measured in square meters (m^2). - $\theta$: The **angle** between the magnetic field and the normal to the loop, which is a line sticking straight out of its face. Measured in degrees or radians. ## What the formula is doing The **magnetic flux** $\Phi_B$ counts how much magnetic field passes through a loop of area $A$, measured in square meters (m^2). For a field $B$, in tesla (T), at an angle $\theta$ to the loop's normal, $\Phi_B = BA\cos\theta$, measured in webers (Wb). Think of flux as the field lines that thread through the loop. Faraday's law says that a changing flux induces an emf, which is short for electromotive force, in the loop. The emf $\varepsilon$, in volts (V), equals $N$ times the rate of change of flux, $d\Phi_B / dt$, in webers per second. A coil with $N$ turns multiplies the effect, because each turn sees the same change. A steady flux induces no emf, however strong the field is. The minus sign is **Lenz's law**. It says the induced emf drives a current whose own magnetic field opposes the change in flux. If the flux is growing, the induced current pushes back against the growth. This sign keeps energy conserved, because an induced effect that helped the change causing it would create energy from nothing. Generators apply this law. Turning a coil in a magnetic field changes its angle $\theta$, which changes the flux through the coil and produces an alternating emf. The same law explains transformers, where a changing current in one coil makes a changing flux in the other. ## An everyday picture Think of a hoop held in a stream of water. The flux is how much water passes through the hoop. Tilt the hoop and less water gets through, which is the cosine in the formula. Change the flow or the tilt quickly, and the rate of change pushes a current around the hoop. ## Worked example: Average emf from a field that grows in 0.1 s A coil with $N = 100$ turns and an area of $A = 0.01\ \text{m}^2$ (which is 100 cm^2) has its face perpendicular to a magnetic field. The field grows steadily from 0 to 0.5 T in 0.1 s. Find the size of the average induced emf. 1. The face is perpendicular to the field, so $\theta = 0$ and $\cos 0 = 1$. The flux at the end is $\Phi_B = BA = (0.5\ \text{T})(0.01\ \text{m}^2) = 0.005\ \text{Wb}$. 2. The change in flux is $\Delta\Phi_B = 0.005\ \text{Wb} - 0 = 0.005\ \text{Wb}$, over $\Delta t = 0.1\ \text{s}$, so the rate of change is $0.05\ \text{Wb/s}$. 3. Multiply by the number of turns: $|\varepsilon| = N \frac{\Delta\Phi_B}{\Delta t} = 100 \times 0.05\ \text{Wb/s} = 5\ \text{V}$. 4. The minus sign in the formula only sets the direction, so the induced current opposes the growth in flux. **Answer:** The average induced emf has a size of **5 V**. Its sign is negative, so by Lenz's law the induced current flows in the direction that opposes the growing flux through the coil. ## Common mistakes - Forgetting the number of turns. A 100 turn coil has 100 times the emf of a single loop in the same change. - Expecting a steady field to induce an emf. An emf needs a change in flux, so a constant field through a still coil induces nothing. - Using square centimeters without converting. 100 cm^2 is 0.01 m^2, so using 100 would make the emf 10 000 times too big. - Ignoring the angle. If the coil is turned edge-on to the field, $\cos\theta$ is zero and the flux is zero, however strong the field is. ## Where you will meet it - Electric generators in power stations, where spinning coils in magnetic fields produce the alternating voltage of the grid. - Induction cooktops, where a changing magnetic field induces currents in the metal of the pan, which heat it. - Wireless phone chargers, which use a changing field in one coil to induce a current in a coil inside the phone. - Metal detectors, which sense the changing flux from the currents induced in nearby metal. ## Questions people ask ### Why does the emf depend on the rate of change and not on the field itself? A steady field gives a steady flux, and a steady flux induces nothing. The emf comes from the change, so a field that grows quickly induces more emf than one that grows slowly. ### What is a weber? The SI unit of magnetic flux. One weber is one tesla times one square meter, so $1\ \text{Wb} = 1\ \text{T m}^2$. ### Why is there a minus sign in the formula? The minus sign is Lenz's law. The induced current always acts to oppose the change that causes it, which keeps energy conserved. ## Related formulas - [Transformer Turns Ratio](https://formulabro.yunusemrevurgun.com/electricity/transformer-turns-ratio/) - [Magnetic Field of a Solenoid](https://formulabro.yunusemrevurgun.com/electricity/magnetic-field-of-solenoid/) - [Inductor Voltage](https://formulabro.yunusemrevurgun.com/electricity/inductor-voltage/) - [Magnetic Force on a Moving Charge](https://formulabro.yunusemrevurgun.com/electricity/magnetic-force-on-moving-charge/) ## Sources - [Faraday's law of induction, Wikipedia](https://en.wikipedia.org/wiki/Faraday%27s_law_of_induction) - [Lenz's law, Wikipedia](https://en.wikipedia.org/wiki/Lenz%27s_law) - [Magnetic flux, Wikipedia](https://en.wikipedia.org/wiki/Magnetic_flux) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Planck-Einstein Relation (E = hf) > E = hf says each packet of light carries energy in proportion to its frequency: higher frequency means more energy per packet, and brightness does not change it. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E = h f $$ Read it out loud: "E equals h times f. E is the energy of one photon, h is Planck's constant, and f is the frequency of the light." ## What each symbol means - $E$: The energy of **one** photon, a single packet of light, in joules (J). Atomic physics often uses electron volts (eV) instead: $1\ \text{eV} = 1.602176634 \times 10^{-19}$ J. - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s (joule seconds). Its value is exact by definition in the SI system. - $f$: The frequency of the light, in hertz (Hz), which means waves per second. ## What the formula is doing In 1900 Max Planck found that the radiation from hot objects only fits the measurements if energy is exchanged in fixed steps. In 1905 Albert Einstein went further and proposed that light itself arrives in packets, now called photons. Each photon carries a fixed amount of energy, and the formula $E = hf$ says how much. The frequency $f$ counts how many wave crests pass a point each second. Double the frequency and each photon carries twice the energy. Nothing else about the light changes that number: the energy of one photon depends only on its frequency. Brightness is a different quantity. A brighter light has more photons arriving each second, so it carries more energy in total, but every photon is as energetic as before. Brightness answers the question how many, and frequency answers the question how much energy in each one. This explains a practical difference. Ultraviolet photons carry enough energy each to break chemical bonds, including bonds in the DNA of skin cells, which is why UV light can cause sunburn. Red photons carry much less energy each, too little to do that, so even a very bright red lamp does not cause sunburn. ## An everyday picture Think of a vending machine that accepts only coins. Each coin type has a fixed value. A dollar coin is worth more than a dime, however many dimes you feed in. Frequency is the value of each coin, and brightness is how many coins arrive each second. ## Worked example: Green light at 540 THz Green light has a frequency of $f = 5.4 \times 10^{14}$ Hz, which is 540 THz. Use $h = 6.62607015 \times 10^{-34}$ J s. 1. Multiply by Planck's constant: $E = hf = (6.62607015 \times 10^{-34}\ \text{J s})(5.4 \times 10^{14}\ \text{Hz}) \approx 3.578 \times 10^{-19}$ J. 2. Convert joules to electron volts by dividing by $1.602176634 \times 10^{-19}$ J per eV: $\frac{3.578 \times 10^{-19}}{1.602176634 \times 10^{-19}} \approx 2.233$ eV. 3. Find the wavelength with $\lambda = c / f = (2.998 \times 10^{8}\ \text{m/s}) / (5.4 \times 10^{14}\ \text{Hz}) \approx 5.55 \times 10^{-7}$ m, or about 555 nm. **Answer:** Each photon of this green light carries about $3.58 \times 10^{-19}$ J, or **2.23 eV**. A lamp that sends out a million times more photons per second carries a million times more energy each second, but each photon still has the same 2.23 eV. ## Common mistakes - Thinking brightness changes the energy of each photon. Brightness changes how many photons arrive per second. Frequency sets the energy of each one. - Plugging a wavelength into $E = hf$. The formula needs the frequency in hertz. If you only have the wavelength, first find $f = c / \lambda$. - Forgetting the units. $E = hf$ gives joules, not electron volts. Divide by $1.602176634 \times 10^{-19}$ to convert. - Imagining that the energy of a light beam is spread evenly over time and space, like water in a bucket. Each photon is a whole packet that is absorbed in one piece or not at all. ## Where you will meet it - Photoelectric effect calculations, the work that earned Einstein the 1921 Nobel Prize in Physics. - LED and laser design, where the color of the light is set by the energy gap of the semiconductor. - Spectroscopy, where the energies of absorbed or emitted light reveal which atoms and molecules are present. - Radiation safety, where the energy of each photon decides whether the light can break chemical bonds. ## Questions people ask ### Does E = hf mean light is a particle? Light shows both wave and particle behavior. Spreading out and interfering are wave behaviors. Being absorbed in packets is particle-like. The formula links the two: the frequency belongs to the wave, and the energy belongs to each packet. ### What unit is h in? $h$ is in joule seconds (J s). A frequency is in hertz, which is per second, so $hf$ comes out in joules because the seconds cancel. ### What happens if the frequency is too low? Then each photon carries too little energy for the job. In the photoelectric effect, for example, a photon that is too weak cannot free an electron, however many arrive. See the photoelectric effect page for details. ## Related formulas - [Photoelectric Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/) - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) ## Sources - [Planck relation, Wikipedia](https://en.wikipedia.org/wiki/Planck_relation) - [Photon, Wikipedia](https://en.wikipedia.org/wiki/Photon) - [Fundamental physical constants, NIST](https://physics.nist.gov/cuu/Constants/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Photoelectric Effect > Light can knock electrons out of a metal, but only if each packet of light carries enough energy, and the leftover energy becomes the electron's speed. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ K_{\max} = h f - \phi $$ Read it out loud: "K max equals h times f minus phi. K max is the largest kinetic energy of an ejected electron, h is Planck's constant, f is the light's frequency, and phi is the metal's work function." ## What each symbol means - $K_{\max}$: The largest kinetic energy (energy of motion) an ejected electron can have, in joules (J) or electron volts (eV). - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s (joule seconds). - $f$: The frequency of the light, in hertz (Hz). Each photon of frequency $f$ can free at most one electron. - $\phi$: The work function of the metal: the minimum energy needed to pull an electron out of its surface, in joules or electron volts. Each metal has its own value. ## What the formula is doing Physicists noticed in the late 1800s that light shining on a metal can knock electrons out of it, and Heinrich Hertz reported the effect in 1887. Wave theory predicted that brighter light, which carries more energy, should eject electrons with more energy, and that dim light should work if it shines long enough. Experiments showed otherwise. The frequency of the light decided whether electrons came out at all, while brightness only changed how many came out. In 1905 Einstein explained this with photons. One photon hits one electron and hands over all of its energy $hf$. Part of that energy pays the cost of escaping the metal, the work function $\phi$. The rest becomes the electron's kinetic energy, the energy of its motion. That gives the formula $K_{\max} = hf - \phi$. If $hf$ is less than $\phi$, the photon cannot pay the cost, the formula would give a negative number, and no electron escapes. Brightness does not help, because it changes the number of photons, not the energy of each one. The word max is needed because electrons start at different depths in the metal. An electron from deeper inside loses some energy on its way out, so only the electrons that lose the least reach the surface with the full $hf - \phi$. Those are the fastest ones. Einstein received the 1921 Nobel Prize in Physics for his discovery of the law of the photoelectric effect. ## An everyday picture Think of a turnstile that opens only for a coin worth at least the toll. The toll is the work function. A coin worth exactly the toll gets you through with nothing left over. A bigger coin gets you through, and the difference comes back as change, which is the electron's kinetic energy. A smaller coin does not open the gate, and feeding in many small coins one at a time does not open it either, because each coin is used on its own. ## Worked example: Violet light and red light on the same metal A metal with work function $\phi = 2.3$ eV, close to the value for potassium (2.29 eV). Two lights shine on it: violet light at a wavelength of 400 nm and red light at 700 nm. The photon energy is $hf = hc/\lambda$, with $hc = 1239.84$ eV nm. 1. Violet light: $hf = \frac{1239.84\ \text{eV nm}}{400\ \text{nm}} \approx 3.10$ eV. 2. Maximum kinetic energy of the ejected electrons: $K_{\max} = hf - \phi = 3.10 - 2.3 = 0.80$ eV. 3. Red light: $hf = \frac{1239.84\ \text{eV nm}}{700\ \text{nm}} \approx 1.77$ eV. 4. Compare with the work function: $1.77 - 2.3 \approx -0.53$ eV. The result is below zero, so one red photon cannot pay the cost of escape, and no electron leaves the metal. **Answer:** Violet light ejects electrons with up to **0.80 eV** of kinetic energy. Red light at 700 nm ejects no electrons at all, however bright it is, because no single red photon has the 2.3 eV needed to escape the metal. More red light only adds more photons, and each one is still too weak. ## Common mistakes - Thinking brighter light fixes a light that is too red. Brightness adds photons, but a 700 nm photon at 1.77 eV still cannot pay a 2.3 eV work function. - Forgetting to subtract the work function. The formula gives the kinetic energy left after the cost of escape, not the photon energy $hf$. - Reading $K_{\max}$ as the energy of every electron. Most ejected electrons have less energy. $K_{\max}$ describes only the fastest ones. - Using $hc = 1239.84$ eV nm with the wavelength in meters or micrometers. That constant gives electron volts only when the wavelength is in nanometers. ## Where you will meet it - Light meters and photodetectors, where light frees electrons that are then counted or amplified. - Solar cells, which rely on a close relative of the same idea: photons free electrons inside a semiconductor. - Surface science, where photoelectron spectroscopy shines light on a material and measures the energies of the electrons it ejects. - Image sensors in cameras, where each pixel turns the light that reaches it into a count of electrons. ## Questions people ask ### Why does brightness not change the energy of the electrons? Brightness sets how many photons arrive each second. Each electron is knocked out by a single photon, and that photon's energy depends only on its frequency. More photons give more electrons, all with the same maximum energy for a given frequency. ### What is a work function in plain words? It is the cost of leaving the metal. Each metal holds its electrons with a different strength, and $\phi$ is the minimum energy an electron needs to escape the surface. ### Did Einstein discover the photoelectric effect? No. Heinrich Hertz reported it in 1887. Einstein's 1905 explanation, which uses photons, is what the 1921 Nobel Prize honored. ## Related formulas - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) ## Sources - [Photoelectric effect, Wikipedia](https://en.wikipedia.org/wiki/Photoelectric_effect) - [Work function, Wikipedia](https://en.wikipedia.org/wiki/Work_function) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # De Broglie Wavelength > Every moving object has a wavelength, and the heavier or faster it moves, the shorter that wavelength gets. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \lambda = \frac{h}{p} = \frac{h}{m v} $$ Read it out loud: "Lambda equals h divided by p, which is h divided by m times v. Lambda is the wavelength, h is Planck's constant, p is momentum, m is mass and v is speed." ## What each symbol means - $\lambda$: The de Broglie wavelength: the distance over which the matter wave repeats, in meters (m). - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s (joule seconds). - $p$: The momentum of the particle, in kilogram meters per second (kg m/s). Momentum is mass times speed, the amount of motion. - $m$: The mass of the particle, in kilograms (kg). - $v$: The speed of the particle, in meters per second (m/s). ## What the formula is doing In 1924 Louis de Broglie proposed, in his PhD thesis, that particles such as electrons also have a wave side, as light has a particle side. The idea was a bold extension of the photon picture. Electron waves were observed in 1927 by Davisson and Germer, and independently by G. P. Thomson. The formula says the wavelength depends on momentum, $p = mv$. Heavier or faster objects have shorter wavelengths. Multiply the mass by the speed to get the momentum $p$, then divide Planck's constant $h$ by $p$ to get the wavelength $\lambda$. Because $h$ is so small, the wave is only noticeable for very light particles moving slowly, such as electrons. For everyday objects the wavelength is far too small to detect. The example shows both ends of the range. An electron moving at $1.0 \times 10^{6}$ m/s has a wavelength of about 0.727 nm, a few times the width of one atom. A baseball has a wavelength far too small to ever measure. This wave is not a ripple in some material. In modern quantum mechanics it is part of the wave function, the object that predicts probabilities for the particle. ## An everyday picture Think of a ping-pong ball and a bowling ball rolling at the same speed. The bowling ball carries far more motion, so its wave is far shorter. A wave only shows its effects when its wavelength is comparable to the things around it, and for everyday objects that never happens, while for an electron in an atom it does. ## Worked example: An electron and a baseball Electron: mass $m_e = 9.1093837 \times 10^{-31}$ kg, speed $v = 1.0 \times 10^{6}$ m/s. Baseball: mass $m = 0.145$ kg, speed $v = 40$ m/s. Use $h = 6.62607015 \times 10^{-34}$ J s. 1. Electron momentum: $p = m_e v = (9.1093837 \times 10^{-31})(1.0 \times 10^{6}) = 9.1093837 \times 10^{-25}$ kg m/s. 2. Electron wavelength: $\lambda = \frac{h}{p} = \frac{6.62607015 \times 10^{-34}}{9.1093837 \times 10^{-25}} \approx 7.27 \times 10^{-10}$ m, which is 0.727 nm. 3. Baseball momentum: $p = 0.145 \times 40 = 5.8$ kg m/s. 4. Baseball wavelength: $\lambda = \frac{6.62607015 \times 10^{-34}}{5.8} \approx 1.14 \times 10^{-34}$ m. **Answer:** The electron's wave is about 0.727 nm long, which is a few times the width of one atom, so wave behavior matters for electrons in atoms. The baseball's wave is $1.14 \times 10^{-34}$ m long. That is about $10^{-24}$ times the width of an atom, far too small for any experiment to see. The same formula gives very different results because the wave matters only when the mass is tiny. ## Common mistakes - Using speed where momentum belongs. The formula needs $p = mv$, so the mass matters too. Leaving the mass out gives a wrong answer by the mass ratio. - Using grams instead of kilograms. Planck's constant is in SI units, so 145 g must become 0.145 kg before you divide. - Treating the wavelength as the size of the particle. The wavelength describes the wave that goes with the particle. It is not the particle's radius. - Assuming everyday objects show wave effects. A wavelength only matters when it is comparable to the size of the things the wave meets, which is almost never true for everyday objects. ## Where you will meet it - Electron diffraction experiments, which confirmed the wave nature of electrons in 1927. - Electron microscopes, which use fast electrons with wavelengths in the picometer range to image very small structures. - Neutron scattering, where neutrons with wavelengths close to atomic spacings reveal the structure of crystals. - Quantum mechanics textbooks, where wave packets are built from many waves with different momenta to describe a localized particle. ## Questions people ask ### Does a baseball really have a wavelength? Yes, the formula gives every moving object a de Broglie wavelength. For a baseball it is far too small to measure, so it has no practical effect. ### Is the electron a wave or a particle? In quantum mechanics it is detected as a whole particle, but its behavior in experiments such as diffraction follows wave rules. Both pictures are useful, and each one describes a different side of the same measurements. ### Why is the wavelength so tiny for most objects? Because $h = 6.6 \times 10^{-34}$ J s is so small, the wavelength $h/p$ is tiny unless the momentum $p$ is tiny too. Small masses moving slowly have small momentum, which is why they show wave behavior. ## Related formulas - [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) ## Sources - [Matter wave, Wikipedia](https://en.wikipedia.org/wiki/Matter_wave) - [Louis de Broglie, Wikipedia](https://en.wikipedia.org/wiki/Louis_de_Broglie) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Heisenberg Uncertainty Principle > The more tightly a particle's position is pinned down, the more its speed must spread out, and no instrument can beat that trade-off. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \Delta x \, \Delta p \ge \frac{\hbar}{2} $$ Read it out loud: "Delta x times delta p is greater than or equal to h-bar divided by two. Delta x is the spread in position, delta p is the spread in momentum, and h-bar is the reduced Planck constant." ## What each symbol means - $\Delta x$: The spread in position measurements (the standard deviation of position), in meters (m). The delta means a spread here, not a single error. - $\Delta p$: The spread in momentum measurements, in kilogram meters per second (kg m/s). - $\ge$: "Greater than or equal to": the product of the two spreads can never be smaller than the number on the right. - $\hbar$: The reduced Planck constant, $h / 2\pi = 1.054571817 \times 10^{-34}$ J s (joule seconds). ## What the formula is doing The principle says that the position and the momentum of a particle cannot both be pinned down exactly at the same time. Here $\Delta x$ is the spread in position and $\Delta p$ is the spread in momentum. Squeeze one spread smaller and the other must grow, so their product never falls below $\hbar/2$. This is not only a problem with clumsy instruments. Better tools cannot beat the limit, because it comes from the wave nature of the particle. A wave confined to a small region must be built from a range of wavelengths. Each wavelength carries its own momentum through $p = h/\lambda$, so the momentum spreads out. The sharper the confinement, the wider the spread. A particle in an exact position state does not have a sharp momentum, even before anyone measures it. The uncertainty belongs to the state of the particle, and every measurement has to respect it. The size of the limit matters. $\hbar/2$ is about $5.27 \times 10^{-35}$ J s. For a baseball the limit is so small that it has no practical effect. For an electron confined to an atom, the same limit is large enough to set a real minimum amount of motion. Electrons in atoms are confined to roughly $10^{-10}$ m. The uncertainty principle then gives a rough minimum for the electron's momentum and energy, which is one reason an atom does not collapse into its nucleus. This is an estimate that shows the scale, not a full calculation. ## An everyday picture Think of a short clap compared with a long tone. A very short clap has no clear pitch, because a clear pitch needs the sound to last long enough to repeat. Making the sound shorter blurs its pitch, and a better microphone cannot undo that blur. The same kind of trade-off links position and momentum for a quantum particle. ## Worked example: An electron squeezed into an atom An electron is confined to a region of width $\Delta x = 1.0 \times 10^{-10}$ m, about the width of an atom. Use $\hbar = 1.054571817 \times 10^{-34}$ J s and $m_e = 9.1093837 \times 10^{-31}$ kg. 1. Rearrange the limit to find the smallest momentum spread: $\Delta p \ge \frac{\hbar}{2\,\Delta x}$. 2. Plug in the numbers: $\Delta p \ge \frac{1.054571817 \times 10^{-34}\ \text{J s}}{2 \times 1.0 \times 10^{-10}\ \text{m}} \approx 5.27 \times 10^{-25}$ kg m/s. 3. Divide by the electron mass to get the smallest speed spread: $\Delta v = \frac{\Delta p}{m_e} \ge \frac{5.27 \times 10^{-25}}{9.1093837 \times 10^{-31}} \approx 5.79 \times 10^{5}$ m/s. **Answer:** The electron's speed must be spread out by at least about $5.79 \times 10^{5}$ m/s, roughly 0.19% of the speed of light. Being squeezed into atom-sized space means the electron cannot have one sharp speed. This comes from the wave itself, not from a poor ruler. ## Common mistakes - Thinking the limit is about bad instruments. A better instrument cannot beat it, because the limit describes the particle's wave, not the device. - Reading $\Delta x$ as the error of one measurement. It is the spread across many measurements on identically prepared particles. - Forgetting to divide by the mass when turning a momentum spread into a speed spread. Use $\Delta v = \Delta p / m$. - Using $h$ where $\hbar$ belongs. The principle uses $\hbar = h / 2\pi$, which is about 6.3 times smaller than $h$. ## Where you will meet it - Atomic physics, where a quick estimate of atom size and electron energy comes from this limit. - Squeezed light in gravitational-wave detectors, where the trade-off is used to reduce noise in one measured property at the cost of another. - Wave packets in quantum mechanics, where a localized particle is built from many waves with different momenta. - Textbook problems on confinement, such as an electron trapped in a nanometer-scale box, where the limit sets a minimum energy. ## Questions people ask ### Is this only a measuring problem? No. Measuring tools do disturb systems, but this principle is a limit on the particle itself. A particle with a sharp position has no sharp momentum, whether or not anyone measures it. ### Does it mean I can never know where something is? You can know the position of a baseball, a car or a grain of dust to any precision that matters in daily life. The limit only becomes important for very small masses confined to very small regions, such as electrons in atoms. ### What does the h-bar symbol mean? $\hbar$ (read 'h-bar') is $h$ divided by $2\pi$. It shows up whenever angles or angular frequencies are involved, which is natural for waves. ## Related formulas - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) ## Sources - [Uncertainty principle, Wikipedia](https://en.wikipedia.org/wiki/Uncertainty_principle) - [Fundamental physical constants, NIST](https://physics.nist.gov/cuu/Constants/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Born Rule > The Born rule says the chance of finding a particle at a spot, or of getting an outcome, is the squared size of its wave at that spot. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P(x) = |\psi(x)|^2 $$ Read it out loud: "P of x equals the absolute value of psi of x, squared. P of x is the probability density at position x, and psi is the wave function." ## What each symbol means - $P(x)$: The probability density at position $x$: probability per unit length, so per meter in one dimension. To get a real probability, multiply by a width and add up over a region. - $x$: A position. In one dimension it is measured in meters (m). - $\psi(x)$: The wave function at position $x$. It is a complex number, not a probability. In one dimension its units are $\text{m}^{-1/2}$. - $|\psi(x)|^2$: The squared size of the wave function. The size (absolute value) removes the phase, and squaring makes the result positive. - $c_i$: The amplitude (a complex number) for possible outcome number $i$, in a state written as a sum of possible outcomes. - $P_i$: The probability of outcome number $i$: a number between 0 and 1. ## What the formula is doing The wave function $\psi$ describes the state of a particle, but $\psi$ itself is a complex number, so it cannot be a probability. In 1926 Max Born proposed that the probability is given by the squared size of $\psi$. For a particle in one dimension, $P(x) = |\psi(x)|^2$ is a probability density: the probability per unit length near position $x$. A density is not a probability by itself. To get the chance that the particle is in a region, add up $P(x)$ over that region, which is what an integral does. Over all of space the total must be exactly 1, because the particle is somewhere. For a set of possible outcomes the rule is simpler. Suppose the state has one amplitude $c_i$ for each possible outcome $i$. Then $P_i = |c_i|^2$: take the size of the amplitude and square it. The amplitudes must be chosen so that $\sum_i |c_i|^2 = 1$. Amplitudes are complex, so each one has a direction (its phase) as well as a size. The probability uses only the size, but the phase decides how different possibilities add or cancel when they combine. That cancellation is behind interference patterns. The rule does not say which outcome you will get. It gives only the probabilities. One measurement gives one outcome, chosen at random with those probabilities, and repeating the experiment on identical states reveals the pattern. ## An everyday picture Think of a crowd spread over a park. The number of people per square meter is the density, and the spot with the most people is the spot where you are most likely to find someone. The Born rule sets the crowd density at each spot to the squared size of the wave there. The wave itself can dip below zero or point in different directions, but its squared size is always positive, as a crowd count always is. ## Worked example: A qubit with two possible outcomes A qubit is in a state with amplitudes $c_0 = 0.6$ for outcome 0 and $c_1 = 0.8i$ for outcome 1. Here $i$ is the imaginary unit, with $i^2 = -1$. 1. Size of the second amplitude: $|c_1|^2 = |0.8i|^2 = 0.8^2 = 0.64$. 2. Size of the first amplitude: $|c_0|^2 = 0.6^2 = 0.36$. 3. Apply the rule: $P(0) = |c_0|^2 = 0.36$ and $P(1) = |c_1|^2 = 0.64$. 4. Check the total: $0.36 + 0.64 = 1$, so the two outcomes cover every possibility. **Answer:** Outcome 0 has probability **0.36** (36%) and outcome 1 has probability **0.64** (64%). The $i$ in $c_1$ does not change these numbers, because only the size of $c_1$ is squared. The phase would matter if the state were measured in a different way, where the two amplitudes could combine. ## Common mistakes - Squaring the amplitude instead of its size. For a complex number, $|c|^2$ is not $c^2$. For $c = 0.8i$, $c^2 = -0.64$, which is negative and cannot be a probability. - Treating $\psi$ itself as the probability. $\psi$ can be negative or complex. Only $|\psi|^2$ is a probability density. - Reading $P(x)$ as a chance at one exact point. For continuous position, the chance of exactly one point is zero. You need a small interval, so multiply the density by its width or add it up over a region. - Forgetting that the probabilities must total 1. If they do not, divide each amplitude by the square root of the total probability to normalize the state. ## Where you will meet it - Chemistry, where the squared wave function of an electron gives the electron density shown in orbital pictures. - Quantum computing, where the chance of each measurement result on a qubit comes from squared amplitudes. - Particle physics, where the probability of a scattering process is computed from the square of its amplitude. - Quantum tunneling, where the chance of finding a particle beyond a barrier is computed from the squared wave function. ## Questions people ask ### Why square the size instead of using it directly? Squaring always gives a positive number and works for complex amplitudes. In the standard formulation of quantum mechanics the rule is a basic postulate, and experiments have checked it in many settings. ### Does measuring collapse the wave function? Standard quantum mechanics says a measurement gives one outcome, chosen with the probabilities above, and the state afterward matches that outcome. What exactly happens during a measurement is an open question that the interpretations of quantum mechanics answer differently. ### Why must the probabilities add up to 1? The particle must be found somewhere, so one of the listed outcomes must happen. The total chance of all outcomes is 100%, which is written as 1. ## Related formulas - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) - [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/) - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) ## Sources - [Born rule, Wikipedia](https://en.wikipedia.org/wiki/Born_rule) - [Max Born, Wikipedia](https://en.wikipedia.org/wiki/Max_Born) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Schrödinger Equation > The Schrödinger equation says how a quantum particle's wave changes over time, the way Newton's laws say how a moving ball changes its position. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ i \hbar \frac{\partial \psi}{\partial t} = \hat{H} \psi $$ Read it out loud: "i times h-bar times the partial derivative of psi with respect to t equals H-hat times psi. Psi is the wave function, t is time, and H-hat is the energy operator." ## What each symbol means - $i$: The imaginary unit, with $i^2 = -1$. It is what makes the phase of the wave function turn as time passes. - $\hbar$: The reduced Planck constant, $1.054571817 \times 10^{-34}$ J s (joule seconds). - $\frac{\partial \psi}{\partial t}$: How fast the wave function changes at one fixed point as time passes. The partial derivative means only time is changing here. - $\psi$: The wave function, a complex number at each position and time. Its squared size gives a probability density (see the Born rule). - $\hat{H}$: The Hamiltonian, the energy operator. For one particle of mass $m$ in a potential $V$, $\hat{H} = -\frac{\hbar^2}{2m}\nabla^2 + V$. Its result is in joules (J). - $t$: Time, in seconds (s). - $m$: The mass of the particle, in kilograms (kg). - $\nabla^2$: The Laplacian, the sum of second spatial derivatives. In one dimension it is $\partial^2 / \partial x^2$, in units of 1/m^2. - $V$: The potential energy at each position, in joules (J). It is the landscape the particle moves through. - $E$: The energy of a state, in joules (J), in the time-independent form $\hat{H}\psi = E\psi$. ## What the formula is doing The Schrödinger equation is the basic equation for how a quantum state changes with time. It does for the wave function what Newton's second law does for motion. If you know the state now and the potential acting on the particle, it predicts the state later. Read the left side as how fast the wave changes at each point, and the right side as applying the energy operator to the wave. The operator $\hat{H}$ has two parts: $-\frac{\hbar^2}{2m}\nabla^2$, which describes motion, and $V$, which describes the potential energy at each position. The factor $i$ makes the phase of the wave turn as time passes. When the energy is fixed, the time-independent form $\hat{H}\psi = E\psi$ applies. Its solutions are the states with a definite energy $E$. Those states keep the same probability pattern as time passes, which is why they are called stationary states. Solving the equation means finding wave functions that obey it and the conditions of the situation, such as walls where the wave must vanish. Only certain energies pass that test. That is why a particle that is trapped has discrete energy levels, as the box and hydrogen examples show. The equation is linear. If two solutions exist, their sum is also a solution. That is why a particle can be in a combination of several energy states, and why the energy of such a combination is not fixed. ## An everyday picture Think of a guitar string clamped at both ends. Only certain wave patterns fit between the clamps, so only certain pitches can sound. A particle trapped in a box is like that string: only certain energy patterns fit inside the walls, and each one has its own energy. ## Worked example: An electron in a 1 nm box An electron (mass $m = 9.1093837 \times 10^{-31}$ kg) is trapped in a one-dimensional box of width $L = 1.0$ nm $= 1.0 \times 10^{-9}$ m, with walls too high to escape. Its allowed energies are $E_n = \frac{n^2 h^2}{8 m L^2}$ for $n = 1, 2, 3, \dots$, with $h = 6.62607015 \times 10^{-34}$ J s. 1. Compute the energy for $n = 1$: $E_1 = \frac{h^2}{8 m L^2} = \frac{(6.62607015 \times 10^{-34})^2}{8 (9.1093837 \times 10^{-31})(1.0 \times 10^{-9})^2} \approx 6.02 \times 10^{-20}$ J. 2. Convert to electron volts: $E_1 = \frac{6.02 \times 10^{-20}}{1.602 \times 10^{-19}} \approx 0.376$ eV. 3. Next level, $n = 2$: $E_2 = 2^2 E_1 = 4 E_1 \approx 1.50$ eV. 4. Level $n = 3$: $E_3 = 3^2 E_1 = 9 E_1 \approx 3.38$ eV. **Answer:** In this box the electron can have energies of 0.376 eV, 1.50 eV, 3.38 eV and so on. The lowest energy, 0.376 eV, is not zero, because confining a particle always costs some energy. ## Common mistakes - Forgetting that the box width is in meters. Convert 1 nm to $1.0 \times 10^{-9}$ m before squaring. The $L^2$ in the denominator is what makes these energies small. - Believing the lowest energy is zero. The lowest level is $n = 1$, and it is above zero because confining a particle costs energy. - Using $n = 0$. For this box the quantum number starts at 1, because $n = 0$ would mean no wave at all. - Treating $\hat{H}\psi = E\psi$ as the whole story. That form describes states of fixed energy. The full time-dependent equation is needed to see how a state changes in time. ## Where you will meet it - Chemistry, where solutions for the hydrogen atom and other atoms give orbital shapes and energy levels. - Quantum dots and semiconductor design, where electrons trapped in tiny regions follow box-like energy levels. - Tunneling calculations, where solutions of the equation predict how electrons cross energy barriers. - Quantum chemistry software, which solves the equation approximately to predict the energy levels of molecules. ## Questions people ask ### Is the Schrödinger equation the same as Newton's law? They play the same kind of role: given a starting state, they predict what comes next. Newton's law tracks position and speed, while the Schrödinger equation tracks the wave function, which gives probabilities. ### Where does the i come from? The factor $i$ makes the wave evolve by turning its phase over time. This keeps the total probability constant, which is what a physical theory needs. ### Can I solve it by hand? Only for simple cases such as the box, the harmonic oscillator and the hydrogen atom. For most real systems, computers solve it approximately. ## Related formulas - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) ## Sources - [Schrödinger equation, Wikipedia](https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation) - [Particle in a box, Wikipedia](https://en.wikipedia.org/wiki/Particle_in_a_box) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Hydrogen Energy Levels > A hydrogen electron can only sit on certain energy steps, and every jump between steps gives off or takes in light of one exact color. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E_n = -\frac{13.6\ \text{eV}}{n^2} $$ Read it out loud: "E sub n equals negative 13.6 electron volts divided by n squared. E sub n is the energy of level n, and n is a whole number: 1, 2, 3 and so on." ## What each symbol means - $E_n$: The energy of the electron in level $n$, in electron volts (eV). The negative sign means the electron is bound to the proton. - $n$: The principal quantum number: a whole number 1, 2, 3 and so on. A larger $n$ means a larger orbit and a level closer to zero energy. - $13.6\ \text{eV}$: The rounded ionization energy of hydrogen from the ground state, 13.6 electron volts. ## What the formula is doing Hydrogen is one electron bound to one proton. Solving the Schrödinger equation for this system gives a set of allowed energies, labeled by the whole number $n$. The Bohr model reaches the same formula with a simpler picture, and the formula above gives those allowed energies. The number $n$ sets the level. For $n = 1$ the electron is in its lowest level, at $-13.6$ eV. For $n = 2$ the energy is $-3.4$ eV, and for $n = 3$ it is about $-1.51$ eV. Higher levels are closer to zero, and the gaps between them shrink as $n$ grows. The negative sign means the electron is bound. Raising the energy from the ground level to zero takes 13.6 eV, which is the ionization energy. At zero energy the electron is free and no longer tied to the proton. When an electron falls from a higher level to a lower one, it emits one photon whose energy equals the gap between the two levels, following $E = hf$. When it climbs, it absorbs a photon of exactly that energy. Each gap gives one specific wavelength, so hydrogen light is made of sharp lines rather than a smooth rainbow. The first Balmer lines, which end on $n = 2$, are visible light. The red H-alpha line at about 656 nm comes from the jump from $n = 3$ to $n = 2$. Jumps that end on $n = 1$ (the Lyman series) are in the ultraviolet. ## An everyday picture Think of a staircase where each step is closer to the next as you go up, and the top is the free electron at zero energy. The electron can stand only on the steps, never between them. Dropping down a few steps releases a fixed amount of energy, and that amount sets the color of the light that comes out. ## Worked example: The red H-alpha line, from n = 3 to n = 2 An electron falls from level $n = 3$ to level $n = 2$. Use $E_n = -13.6\ \text{eV} / n^2$ and $hc = 1239.84$ eV nm. 1. Energy of level 3: $E_3 = -\frac{13.6}{3^2} \approx -1.51$ eV. 2. Energy of level 2: $E_2 = -\frac{13.6}{2^2} = -3.40$ eV. 3. Energy of the photon, the upper level minus the lower level: $E_{\text{photon}} = E_3 - E_2 = (-1.51) - (-3.40) \approx 1.89$ eV. 4. Wavelength: $\lambda = \frac{hc}{E_{\text{photon}}} = \frac{1239.84\ \text{eV nm}}{1.89\ \text{eV}} \approx 656$ nm. **Answer:** The electron emits a photon of 1.89 eV, which has a wavelength of about 656 nm. That is the red H-alpha line, one of the reasons hydrogen gas glows red-pink in discharge tubes. Ionizing a hydrogen atom from its lowest level would take 13.6 eV instead. ## Common mistakes - Dropping the minus sign. The energies are negative, so $n = 1$ is the lowest level: $-13.6$ eV is less than $-3.4$ eV. - Subtracting in the wrong order. The photon energy is the upper-level energy minus the lower-level energy. Doing it the other way gives a negative photon energy. - Assuming every jump gives visible light. Only jumps that land on $n = 2$ are in the visible range. The jumps that land on $n = 1$ are in the ultraviolet. - Getting the ionization sign wrong. Ionizing from $n = 1$ takes the electron from $-13.6$ eV up to zero, which is $+13.6$ eV of energy added. ## Where you will meet it - Astronomy, where the hydrogen lines of the Balmer series identify hydrogen in stars and nebulae. - Spectroscopy labs, where students measure the red H-alpha line to check the formula against an experiment. - Gas-discharge lamps, where excited hydrogen atoms emit their characteristic lines. - Introductory quantum mechanics, where the hydrogen atom is the standard worked example for energy levels. ## Questions people ask ### Why is the energy negative? The zero point is set at a free electron, far away from the proton. A bound electron has less energy than that, so its energy is negative. ### Why do the levels get closer together as n grows? The gap between level $n$ and level $n+1$ shrinks, because $1/n^2$ changes less and less for large $n$. Levels near zero are packed tightly, and very high levels blur into the free state. ### Is 13.6 eV exact? No, 13.6 eV is a rounded value. For a hydrogen-like atom with an infinitely heavy nucleus the precise value is 13.6057 eV, and using the real proton mass changes it only slightly. ## Related formulas - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) - [Photoelectric Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/) ## Sources - [Hydrogen spectral series, Wikipedia](https://en.wikipedia.org/wiki/Hydrogen_spectral_series) - [Bohr model, Wikipedia](https://en.wikipedia.org/wiki/Bohr_model) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Photon Momentum > A photon has no mass, yet it carries momentum, so light can push on objects, and the shorter its wavelength, the harder each photon pushes. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ p = \frac{h}{\lambda} = \frac{E}{c} $$ Read it out loud: "p equals h over lambda, which also equals E over c. p is the momentum of one photon, h is Planck's constant, lambda is the wavelength, E is the photon's energy, and c is the speed of light." ## What each symbol means - $p$: The **momentum** of one photon, in kilogram meters per second (kg m/s). Ordinary momentum is mass times velocity, but a photon has no rest mass, so this formula is the one to use. - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s (joule seconds). Its value is exact by definition in the SI system. - $\lambda$: The **wavelength** of the light, in meters (m). - $E$: The **energy** of one photon, in joules (J). - $c$: The speed of light in vacuum, $2.99792458 \times 10^{8}$ m/s, exact by definition. ## What the formula is doing A photon is one packet of light. Photons have no rest mass, yet they still carry momentum, which means they can push on things. The formula $p = h / \lambda$ gives that momentum from the wavelength $\lambda$. Shorter wavelengths carry more momentum for each photon. The second form, $p = E / c$, links momentum to energy. For one photon, $E = hc / \lambda$, so dividing that energy by $c$ gives the same $h / \lambda$. The two forms are the same photon described two ways, and in both a photon with more energy pushes harder. Light pushes when it is absorbed or reflected. An absorbed photon hands its momentum to the surface it hits. A reflected photon reverses direction, so the surface receives about twice the push. This steady pressure from light is called radiation pressure. The push is tiny for everyday light. A 1 W beam that is fully absorbed pushes with a force of $P / c$, about $3.3 \times 10^{-9}$ N, or about three billionths of a newton. Solar sails use this small steady push, acting over long times, to change the speed of a spacecraft without fuel. ## An everyday picture Think of a tennis ball hitting a wall. The ball pushes the wall when it hits, and a ball that bounces straight back pushes harder than one that sticks. A photon works the same way. Each one is far too light to notice, but a steady stream of them can push a thin sheet of material. ## Worked example: Momentum of a 500 nm photon Green light has a wavelength of $\lambda = 500$ nm, which is $5.00 \times 10^{-7}$ m. Use $h = 6.62607015 \times 10^{-34}$ J s and $c = 2.99792458 \times 10^{8}$ m/s. 1. Momentum from the wavelength: $p = \frac{h}{\lambda} = \frac{6.62607015 \times 10^{-34}\ \text{J s}}{5.00 \times 10^{-7}\ \text{m}} \approx 1.325 \times 10^{-27}\ \text{kg m/s}$. 2. Energy of the same photon: $E = \frac{hc}{\lambda} = \frac{(6.62607015 \times 10^{-34})(2.99792458 \times 10^{8})}{5.00 \times 10^{-7}} \approx 3.973 \times 10^{-19}$ J. 3. Check with $E / c$: $\frac{3.973 \times 10^{-19}\ \text{J}}{2.998 \times 10^{8}\ \text{m/s}} \approx 1.325 \times 10^{-27}\ \text{kg m/s}$, the same answer. **Answer:** One 500 nm photon has a momentum of about $1.325 \times 10^{-27}$ kg m/s and an energy of about 2.48 eV. That push is far too small to feel, but a beam of billions of photons per second adds up. ## Common mistakes - Using the frequency where the formula needs the wavelength. The formula $p = h / \lambda$ takes the wavelength in meters. - Giving the photon a rest mass and using $p = mv$. A photon has zero rest mass, so use $p = h / \lambda$ or $p = E / c$ instead. - Forgetting to convert nanometers to meters. 500 nm is $5.00 \times 10^{-7}$ m, not 500 m. - Thinking light cannot push because it has no mass. Momentum does not need mass, and a photon's momentum is real and measurable. ## Where you will meet it - Solar sail design, where sunlight pushes a large thin reflector to change a spacecraft's speed without fuel. - Optical tweezers, which trap and move tiny particles using the momentum carried by focused laser light. - Comet tails, where sunlight pushes dust grains away from the Sun through radiation pressure. - Laser physics and quantum optics, where photon momentum is used when atoms absorb and emit light. ## Questions people ask ### Does light really push things? Yes. Light carries momentum, so absorbing or reflecting it exerts a force. The push from sunlight on a sail is small, but it is real and it can be measured. ### Why does the formula appear with wavelength in one place and energy in another? They are the same photon. Its energy is $E = hc / \lambda$, so dividing by $c$ gives $h / \lambda$. Use whichever quantity you already know. ### Why does a reflected photon push harder than an absorbed one? An absorbed photon hands over its momentum once. A reflected photon bounces back, so the surface gets the momentum going in and the momentum coming out, which is about twice the push. ## Related formulas - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) - [Compton Scattering](https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering/) - [Photoelectric Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/) ## Sources - [Radiation pressure, Wikipedia](https://en.wikipedia.org/wiki/Radiation_pressure) - [Photon, Wikipedia](https://en.wikipedia.org/wiki/Photon) - [Solar sail, Wikipedia](https://en.wikipedia.org/wiki/Solar_sail) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Compton Scattering > When an X-ray bounces off an electron it loses some energy, so its wavelength gets longer, and the amount depends only on the angle it bounces through. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \lambda' - \lambda = \frac{h}{m_e c}\left(1 - \cos\theta\right) $$ Read it out loud: "lambda prime minus lambda equals h over m e c, times one minus cosine theta. Lambda is the wavelength before scattering, lambda prime is the wavelength after, and theta is the scattering angle." ## What each symbol means - $\lambda$: The wavelength of the X-ray or gamma-ray photon **before** it hits the electron, in meters (m). - $\lambda'$: The wavelength **after** scattering, in meters. It is never shorter than $\lambda$. - $\theta$: The **scattering angle**: the angle between the photon's original direction and its new direction. - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s. - $m_e$: The **mass of the electron**, $9.1093837 \times 10^{-31}$ kg. - $c$: The speed of light in vacuum, $2.99792458 \times 10^{8}$ m/s. ## What the formula is doing In 1923 Arthur Compton studied X-rays that had hit a target and found that some of the scattered X-rays had a longer wavelength than the original ones. Classical wave theory could not explain that change. Treating the X-ray as a photon that collides with an electron explains it, and the formula $\lambda' - \lambda$ gives the size of the change. The collision works like a billiard ball hitting another ball. The photon gives some energy and momentum to the electron, so the photon leaves with less energy. Because $E = hc / \lambda$, less energy means a longer wavelength. The shift depends only on the angle. The fixed factor $h / (m_e c)$ is the Compton wavelength of the electron, about $2.426 \times 10^{-12}$ m. The factor $1 - \cos\theta$ is zero when the photon goes straight on, and it reaches its largest value of 2 when the photon bounces straight back, at $\theta = 180^\circ$. The shift does not depend on the original wavelength, so an X-ray of 0.07 nm and one of 0.5 nm gain the same absolute shift at the same angle. The shift is easiest to see when the wavelength is close to the Compton wavelength, which is why the effect matters most for X-rays and gamma rays. The formula assumes a free electron at rest, so it is an approximation for electrons bound in atoms. ## An everyday picture Think of a cue ball hitting a resting ball on a pool table. The cue ball slows down and leaves at an angle, and some of its energy moves into the ball it hit. The photon plays the cue ball and the electron plays the ball it hits. A photon that gives away energy leaves with a longer wavelength. ## Worked example: An X-ray bouncing off an electron at 90 degrees An X-ray with wavelength $\lambda = 0.0700$ nm scatters off a free electron at $\theta = 90^\circ$. Use the Compton wavelength $h / (m_e c) = 2.426 \times 10^{-12}$ m. 1. Shift factor: $1 - \cos 90^\circ = 1 - 0 = 1$. 2. Wavelength shift: $\lambda' - \lambda = (2.426 \times 10^{-12}\ \text{m})(1) = 2.426 \times 10^{-12}$ m, which is 0.002426 nm. 3. New wavelength: $\lambda' = 0.0700\ \text{nm} + 0.002426\ \text{nm} \approx 0.07243$ nm. **Answer:** The scattered X-ray has a wavelength of about 0.07243 nm, which is 2.426 picometers longer than before. The change is tiny, but it is measurable, and classical wave theory predicts no such change at this angle. ## Common mistakes - Using degrees where the calculator is in radians mode. Check the mode, because $\cos 90^\circ = 0$ but $\cos 90$ radians is about $-0.448$. - Thinking the scattered photon can have a shorter wavelength. It gives energy to the electron, so the new wavelength is equal to or longer than the old one. - Assuming the shift depends on the starting wavelength. For a given angle, the change $\lambda' - \lambda$ is the same for any X-ray. - Forgetting the units. The Compton wavelength is about $2.4 \times 10^{-12}$ m, which is 2.4 picometers, a very small length. ## Where you will meet it - Gamma-ray and X-ray detectors, where Compton scattering sets the energy that the detector records. - Radiation shielding calculations, since Compton scattering is one of the main ways gamma rays lose energy in matter. - Astrophysics, where high-energy photons gain energy by scattering off fast electrons. - Physics teaching, where the Compton shift is standard evidence that light behaves as a particle with momentum. ## Questions people ask ### What is the Compton wavelength? It is $h / (m_e c)$, about $2.426 \times 10^{-12}$ m. It is set by the electron's mass. The largest shift happens at $180^\circ$, where it equals twice the Compton wavelength. ### Why does the photon lose energy? Energy and momentum must both be conserved in the collision. The electron gains some momentum and kinetic energy, so the photon has less energy left, and a longer wavelength. ### Does visible light show this effect? The shift is the same size, about 2.4 picometers, but a visible wavelength is about 500 nm. The change is far too small to see, so the effect matters mainly for X-rays and gamma rays. ## Related formulas - [Photon Momentum](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) - [Photoelectric Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/) ## Sources - [Compton scattering, Wikipedia](https://en.wikipedia.org/wiki/Compton_scattering) - [Compton wavelength, Wikipedia](https://en.wikipedia.org/wiki/Compton_wavelength) - [Arthur Compton, Wikipedia](https://en.wikipedia.org/wiki/Arthur_Compton) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Planck's Law > Planck's law says how bright a hot object glows at each wavelength, and the mix of colors depends on its temperature. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ B_\lambda(\lambda, T) = \frac{2 h c^2}{\lambda^5} \cdot \frac{1}{e^{h c / (\lambda k_B T)} - 1} $$ Read it out loud: "B lambda of lambda and T equals two h c squared over lambda to the fifth, times one over e to the power of h c over lambda k B T, minus one. B lambda is the brightness at wavelength lambda, and T is the absolute temperature in kelvin." ## What each symbol means - $B_\lambda$: The **spectral radiance**: the power emitted per unit area, per unit solid angle, per unit wavelength, in watts per square meter, per steradian, per meter (W sr$^{-1}$ m$^{-3}$). - $\lambda$: The **wavelength** of the light, in meters (m). - $T$: The **absolute temperature** of the object, in kelvin (K). Celsius cannot be used directly. - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s. - $c$: The speed of light in vacuum, $2.99792458 \times 10^{8}$ m/s. - $k_B$: The **Boltzmann constant**, $1.380649 \times 10^{-23}$ J/K, which links temperature to energy. ## What the formula is doing Every hot object glows. A hot solid such as a furnace wall or a light bulb filament emits light across a range of wavelengths, and the mix depends mainly on its temperature. Planck's law gives the brightness at each wavelength $\lambda$ for a body at temperature $T$. An ideal absorber that emits this light is called a blackbody. Max Planck derived the law in 1900 by assuming that energy is exchanged in fixed steps of size $hf$. That assumption introduced Planck's constant $h$ and began quantum theory. The formula is the tool used today, whatever the details of Planck's original reasoning. The exponential term controls the shape. When $h c / (\lambda k_B T)$ is large, the denominator is huge, so the brightness drops sharply. When that quantity is small, the formula approaches the older Rayleigh-Jeans law, which works only at long wavelengths. Raising the temperature increases the brightness at every wavelength, and the peak moves toward shorter wavelengths. The peak position is given by Wien's displacement law. Adding up the brightness over all wavelengths gives the total power, which is the Stefan-Boltzmann law. ## An everyday picture Think of an iron poker left in a fire. At first it glows a dull red, then orange, then white as it heats up. Each temperature has its own mix of colors, and Planck's law is the recipe that gives the brightness of every color for a given temperature. ## Worked example: Brightness at 500 nm for a 5772 K surface The Sun's effective surface temperature is about 5772 K. Find the spectral radiance at $\lambda = 500$ nm. Use $h = 6.62607015 \times 10^{-34}$ J s, $c = 2.99792458 \times 10^{8}$ m/s and $k_B = 1.380649 \times 10^{-23}$ J/K. 1. Find the exponent: $x = \frac{h c}{\lambda k_B T} = \frac{(6.62607015 \times 10^{-34})(2.99792458 \times 10^{8})}{(5.00 \times 10^{-7})(1.380649 \times 10^{-23})(5772)} \approx 4.985$. 2. Denominator of the formula: $e^{x} - 1 = e^{4.985} - 1 \approx 145.3$. 3. Prefactor: $\frac{2 h c^2}{\lambda^5} = \frac{2 (6.62607015 \times 10^{-34})(2.99792458 \times 10^{8})^2}{(5.00 \times 10^{-7})^5} \approx 3.811 \times 10^{15}$ W sr$^{-1}$ m$^{-3}$. 4. Divide: $B_\lambda = \frac{3.811 \times 10^{15}}{145.3} \approx 2.624 \times 10^{13}$ W sr$^{-1}$ m$^{-3}$. **Answer:** At 500 nm a 5772 K surface emits a spectral radiance of about $2.62 \times 10^{13}$ W sr$^{-1}$ m$^{-3}$. This is close to the peak of the Sun's spectrum, which is why sunlight looks white with a slight green peak. ## Common mistakes - Using degrees Celsius for $T$. Convert to kelvin first: 25 degrees Celsius is 298.15 K. - Writing $\lambda$ in nanometers in the formula. Convert to meters, so 500 nm becomes $5.00 \times 10^{-7}$ m, or the fifth power will be wrong by a huge factor. - Expecting the peak to stay in the same place when the object heats up. The peak moves to shorter wavelengths as $T$ rises. - Treating every glowing object as a perfect blackbody. Real surfaces emit less than the ideal curve, and their emission can vary with wavelength. ## Where you will meet it - Estimating the surface temperature of stars from the shape of their spectra, since starlight is close to a blackbody curve. - Designing furnaces, infrared heaters and incandescent lamps, where the emitted spectrum depends on temperature. - Measuring high temperatures with pyrometers, which compare the brightness of a hot body at chosen wavelengths. - Cosmology, where the cosmic microwave background follows a nearly perfect blackbody curve at about 2.7 K. ## Questions people ask ### Why is it called a blackbody? An ideal blackbody absorbs all the light that falls on it, so it looks black when cold. When it is hot, it emits light with the spectrum that Planck's law describes. ### Why is the Sun's spectrum not a perfect blackbody? The Sun's outer layers absorb light at specific wavelengths, which carves dark lines into the spectrum. Overall the shape is close to a blackbody at about 5772 K. ### Does this law describe ordinary light bulbs? Roughly. A glowing filament is close to a blackbody, but it is not perfect, so its brightness varies somewhat from the ideal curve. ## Related formulas - [Wien's Displacement Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wiens-displacement-law/) - [Stefan-Boltzmann Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) ## Sources - [Planck's law, Wikipedia](https://en.wikipedia.org/wiki/Planck%27s_law) - [Black body, Wikipedia](https://en.wikipedia.org/wiki/Black_body) - [Max Planck, Wikipedia](https://en.wikipedia.org/wiki/Max_Planck) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Wien's Displacement Law > Wien's law says a hotter object is brightest at a shorter wavelength, and the peak wavelength is a fixed constant divided by the temperature. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/wiens-displacement-law/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \lambda_{\max} = \frac{b}{T} $$ Read it out loud: "lambda max equals b over T. Lambda max is the wavelength where the glow is brightest, b is Wien's constant, and T is the absolute temperature in kelvin." ## What each symbol means - $\lambda_{\max}$: The **peak wavelength**: the wavelength at which the emitted light is brightest, in meters (m). - $b$: **Wien's displacement constant**, $2.897771955 \times 10^{-3}$ m K (meter kelvin). - $T$: The **absolute temperature** of the object, in kelvin (K). ## What the formula is doing A hot object glows across many wavelengths, and its spectrum has a single highest point. Wien's displacement law gives the wavelength of that peak. The formula $\lambda_{\max} = b / T$ says the peak wavelength is inversely proportional to the absolute temperature $T$. Because the relation is an inverse, a hotter object peaks at a shorter wavelength. Doubling the temperature cuts the peak wavelength in half. A heated iron bar that glows dull red, then orange, then white is following this trend, as its brightest light moves toward the short-wavelength end. The constant $b$ comes from Planck's law. Setting the slope of Planck's curve to zero with respect to wavelength finds the peak, and $b$ is the constant that results. The value is fixed by the same constants that appear in Planck's law. The law only describes the peak. It does not give the total energy an object emits or the full shape of its spectrum. For the total power, use the Stefan-Boltzmann law, and for the full curve, use Planck's law. ## An everyday picture Think of the stove burner in a kitchen. As it heats up, it goes from a faint dark red to a bright orange, and its color moves toward the shorter-wavelength end of the spectrum. The formula is a dial: turn the temperature up and the peak color slides toward blue. ## Worked example: Peak of the Sun's light and a 3000 K filament The Sun's effective surface temperature is about 5772 K. A warm lamp filament is about 3000 K. Use $b = 2.897771955 \times 10^{-3}$ m K. 1. Sun: $\lambda_{\max} = \frac{2.897771955 \times 10^{-3}\ \text{m K}}{5772\ \text{K}} \approx 5.020 \times 10^{-7}$ m. 2. Convert to nanometers: $5.020 \times 10^{-7}$ m $= 502.0$ nm, which is in the green part of the visible range. 3. Filament: $\lambda_{\max} = \frac{2.897771955 \times 10^{-3}\ \text{m K}}{3000\ \text{K}} \approx 9.659 \times 10^{-7}$ m, or about 966 nm. **Answer:** The Sun's peak falls near 502 nm, in the green part of the visible range. The 3000 K filament peaks near 966 nm, in the infrared, so most of its radiated energy is infrared rather than visible light. ## Common mistakes - Using degrees Celsius for $T$. Wien's law needs kelvin, so 25 degrees Celsius must become 298.15 K. - Treating the peak as the only light an object emits. The peak is only the highest point of a curve that covers many wavelengths. - Forgetting to convert meters to nanometers. $5.02 \times 10^{-7}$ m is 502 nm. - Thinking a hotter object peaks at a longer wavelength. The relation is an inverse, so the peak moves to shorter wavelengths as the temperature rises. ## Where you will meet it - Estimating stellar surface temperatures from the color of their light. - Thermal cameras and infrared thermometers, where a body near room temperature peaks at about 9 to 10 micrometers. - Heater and furnace design, to predict whether a hot surface glows in visible light or mostly emits infrared. - Cosmology, where the cosmic microwave background at about 2.7 K peaks near 1 mm. ## Questions people ask ### Is it $b / T$ or $T / b$? It is $b / T$. A higher temperature gives a shorter peak wavelength, so the wavelength must fall as $T$ rises. Dividing by $T$ does that. ### Why must the temperature be in kelvin? The kelvin scale starts at absolute zero, so a temperature in kelvin is proportional to the thermal energy of the object. Celsius has an arbitrary zero point, so the ratio would be wrong. ### Does this law work for stars that are not perfect blackbodies? As an estimate, yes. Real stars are close to blackbodies, so Wien's law gives a good approximation of surface temperature from the peak color. ## Related formulas - [Planck's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law/) - [Stefan-Boltzmann Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) ## Sources - [Wien's displacement law, Wikipedia](https://en.wikipedia.org/wiki/Wien%27s_displacement_law) - [Black body, Wikipedia](https://en.wikipedia.org/wiki/Black_body) - [Fundamental physical constants, NIST](https://physics.nist.gov/cuu/Constants/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Stefan-Boltzmann Law > The Stefan-Boltzmann law says a hot surface gives off radiated power that grows with the fourth power of its absolute temperature. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ P = \varepsilon \sigma A T^4 $$ Read it out loud: "P equals epsilon sigma A T to the fourth. P is the radiated power, epsilon is the emissivity, sigma is the Stefan-Boltzmann constant, A is the surface area, and T is the absolute temperature in kelvin." ## What each symbol means - $P$: The **radiated power**: the total energy emitted per second, in watts (W). - $\varepsilon$: The **emissivity**, a number from 0 to 1. A perfect blackbody has $\varepsilon = 1$, and real surfaces are lower. - $\sigma$: The **Stefan-Boltzmann constant**, $5.670374419 \times 10^{-8}$ W m$^{-2}$ K$^{-4}$. - $A$: The **surface area** in square meters (m$^2$). - $T$: The **absolute temperature** in kelvin (K). The formula uses $T^4$, so it must be in kelvin. ## What the formula is doing A hot surface radiates energy in all directions. The Stefan-Boltzmann law gives the total power radiated, added up over every wavelength. The formula $P = \varepsilon \sigma A T^4$ says the power grows with the surface area $A$ and with the fourth power of the absolute temperature $T$. The fourth power is the striking part. Doubling the temperature multiplies the power by $2^4 = 16$. A modest rise in temperature therefore changes how much heat an object loses by glowing a great deal. The emissivity $\varepsilon$ adjusts the formula for real surfaces. A dull black painted surface has an emissivity close to 1, while a polished metal has a much lower one. A surface with lower emissivity radiates less than an ideal blackbody at the same temperature. The constant $\sigma$ is not arbitrary. It is built from $\pi$, $k_B$, $h$ and $c$, which means the law is the sum of the Planck curve over all wavelengths. The law is named after Josef Stefan and Ludwig Boltzmann. ## An everyday picture Think of a radiator or a campfire. Turning the heat up a little makes the surface glow noticeably brighter and throw off much more heat, because the fourth power works like a volume knob that gets much louder with a small turn. Emissivity is how well the surface radiates: a shiny mirror sends less heat away than a dull black surface at the same temperature. ## Worked example: Radiated power from a 1 m$^2$ surface at 300 K A 1.00 m$^2$ perfect blackbody, so $\varepsilon = 1$, is held at 300 K, close to room temperature. Use $\sigma = 5.670374419 \times 10^{-8}$ W m$^{-2}$ K$^{-4}$. 1. Fourth power of the temperature: $T^4 = 300^4 = 8.1 \times 10^{9}$ K$^4$. 2. Power per square meter: $\sigma T^4 = (5.670374419 \times 10^{-8})(8.1 \times 10^{9}) \approx 459.3$ W/m$^2$. 3. Multiply by emissivity and area: $P = \varepsilon \sigma A T^4 = (1)(459.3\ \text{W/m}^2)(1.00\ \text{m}^2) \approx 459.3$ W. **Answer:** The surface radiates about 459.3 W. Nearly all of that is infrared light, which our eyes cannot see. A real surface with emissivity 0.5 would radiate about half as much at the same temperature. ## Common mistakes - Using degrees Celsius for $T$. Convert first: 27 degrees Celsius is 300.15 K, and 27 is not the right input. - Using $T$ directly instead of $T^4$. Doubling $T$ multiplies the power by 16, not by 2. - Giving emissivity a value above 1. The emissivity of a real surface is between 0 and 1, and an ideal blackbody is exactly 1. - Mixing up power and energy. The law gives watts, which are joules per second. Multiply by time to get the energy emitted. ## Where you will meet it - Estimating a star's surface temperature from its total brightness and its size. - Thermal design of spacecraft and radiators, which shed heat by radiation because there is no air to carry it away. - Heat loss from furnaces, incandescent filaments and people, where radiation is a major part of the heat balance. - Climate science, where Earth's radiated power must balance the sunlight it absorbs. ## Questions people ask ### Why must the temperature be in kelvin? The formula holds only when $T$ is measured from absolute zero. Celsius and Fahrenheit have arbitrary zero points, so they would give meaningless powers. ### What is emissivity? It is the ratio of the radiation from a surface to the radiation from a perfect blackbody at the same temperature. It runs from 0 to 1 and depends on the material and the surface finish. ### Does this law tell me the color of the light? No. It gives the total power across all wavelengths. For the peak color, use Wien's displacement law. ## Related formulas - [Planck's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law/) - [Wien's Displacement Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wiens-displacement-law/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) ## Sources - [Stefan-Boltzmann law, Wikipedia](https://en.wikipedia.org/wiki/Stefan%E2%80%93Boltzmann_law) - [Emissivity, Wikipedia](https://en.wikipedia.org/wiki/Emissivity) - [Fundamental physical constants, NIST](https://physics.nist.gov/cuu/Constants/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Rydberg Formula > The Rydberg formula predicts the exact color of light a hydrogen atom gives off when its electron drops from one energy level to a lower one. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/rydberg-formula/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \frac{1}{\lambda} = R_H\left(\frac{1}{n_1^2} - \frac{1}{n_2^2}\right) $$ Read it out loud: "One over lambda equals R H times, in brackets, one over n 1 squared minus one over n 2 squared. Lambda is the wavelength, R H is the Rydberg constant for hydrogen, and n 1 and n 2 are whole numbers, with n 2 larger than n 1." ## What each symbol means - $\lambda$: The **wavelength** of the emitted or absorbed light, in meters (m). - $R_H$: The **Rydberg constant for hydrogen**, $1.09678 \times 10^{7}$ m$^{-1}$. The infinite-nucleus-mass value is $R_\infty = 1.0973731568 \times 10^{7}$ m$^{-1}$, and the small difference comes from the proton's finite mass. - $n_1$: The **lower** energy level, a whole number 1, 2, 3 and so on. - $n_2$: The **higher** energy level, a whole number greater than $n_1$. ## What the formula is doing When the electron in a hydrogen atom drops from a higher level $n_2$ to a lower level $n_1$, it emits light at one exact wavelength. The Rydberg formula gives that wavelength. The left side is $1 / \lambda$, so a bigger number on the left means a shorter wavelength. The constant $R_H$ sets the scale, and the bracket depends only on the two levels. Jumps that end on $n_1 = 2$ give the Balmer series, which is mostly visible light. Jumps that end on $n_1 = 1$ form the Lyman series in the ultraviolet, and jumps that end on $n_1 = 3$ form the Paschen series in the infrared. Johannes Rydberg gave the general form of this pattern from measured spectral lines. Quantum theory later explained why hydrogen follows it, because the energy levels of the atom are the origin of the formula. The formula is most accurate for hydrogen and other one-electron ions. Atoms with several electrons have extra effects that shift their lines, so the simple formula is no longer exact for them. ## An everyday picture Think of a staircase with uneven steps. Each step has a fixed height, and a jump from one step to another releases a fixed amount of energy. The Rydberg formula is a table of those step heights, and from the table you can work out the color of the light that each jump gives off. ## Worked example: The H-alpha line, from n = 3 down to n = 2 An electron falls from $n_2 = 3$ to $n_1 = 2$ in a hydrogen atom. Use $R_H = 1.09678 \times 10^{7}$ m$^{-1}$. 1. Bracket: $\frac{1}{2^2} - \frac{1}{3^2} = \frac{1}{4} - \frac{1}{9} = \frac{5}{36} \approx 0.13889$. 2. Multiply by $R_H$: $\frac{1}{\lambda} = (1.09678 \times 10^{7}\ \text{m}^{-1})(0.13889) \approx 1.5233 \times 10^{6}$ m$^{-1}$. 3. Invert to get the wavelength: $\lambda = \frac{1}{1.5233 \times 10^{6}\ \text{m}^{-1}} \approx 6.565 \times 10^{-7}$ m, which is 656.5 nm. **Answer:** The jump emits light of wavelength about 656.5 nm, the red H-alpha line. It is one of the reasons hydrogen gas glows red-pink in discharge tubes. ## Common mistakes - Swapping the levels. $n_2$ must be the higher level. Putting the larger number in the $n_1$ place makes the bracket negative and the wavelength meaningless. - Stopping at the bracket. The bracket is only part of the answer. Multiply by $R_H$, then invert to get $\lambda$. - Forgetting that the left side is $1 / \lambda$, not $\lambda$. Inverting too early gives the wrong number. - Using a wavelength in nanometers inside the formula. $R_H$ is in per meter, so the answer comes out in meters, which you then convert. ## Where you will meet it - Identifying hydrogen in stars and nebulae, using the Balmer lines in their light. - Spectroscopy labs, where students calculate line wavelengths and compare them with a measured spectrum. - Predicting the lines of other one-electron ions, such as singly ionized helium, by scaling the constant. - Calibrating spectrometers, since the hydrogen lines are sharp, well known reference wavelengths. ## Questions people ask ### What are $n_1$ and $n_2$? They are the two levels involved in the jump. $n_2$ is the higher level the electron starts from, and $n_1$ is the lower level it falls to. Both are whole numbers, and $n_2$ is always larger. ### Why does the formula use one over the wavelength? The energy of a photon is proportional to $1 / \lambda$. Written this way, the energy gap between two levels becomes a simple difference of $1 / n^2$ terms. ### Does the same formula describe absorption? Yes. An electron absorbs a photon of the same energy when it jumps up, so the same wavelengths appear as dark lines in an absorption spectrum. ## Related formulas - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) - [Hydrogen-Like Atom Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) ## Sources - [Rydberg formula, Wikipedia](https://en.wikipedia.org/wiki/Rydberg_formula) - [Hydrogen spectral series, Wikipedia](https://en.wikipedia.org/wiki/Hydrogen_spectral_series) - [Fundamental physical constants, NIST](https://physics.nist.gov/cuu/Constants/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bohr Radius > The Bohr radius is the natural size of a hydrogen atom, about 0.0529 nanometers, built from fixed physical constants. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ a_0 = \frac{4\pi \varepsilon_0 \hbar^2}{m_e e^2} $$ Read it out loud: "a sub zero equals four pi epsilon sub zero h-bar squared, over m sub e times e squared. a sub zero is the Bohr radius, about 0.0529 nanometers." ## What each symbol means - $a_0$: The **Bohr radius**, about $5.29 \times 10^{-11}$ m, or 0.0529 nm. - $\varepsilon_0$: The **vacuum permittivity**, $8.8541878128 \times 10^{-12}$ F/m. It sets the strength of electric forces. - $\hbar$: The **reduced Planck constant**, $1.054571817 \times 10^{-34}$ J s, which equals $h / 2\pi$. - $m_e$: The **mass of the electron**, $9.1093837 \times 10^{-31}$ kg. - $e$: The **elementary charge**, $1.602176634 \times 10^{-19}$ C, the charge of one proton. ## What the formula is doing In the Bohr model of the hydrogen atom, the electron circles the proton, and the smallest allowed orbit has radius $a_0$. The formula combines the constants that set the size of atoms: the electron's mass and charge, the strength of electric force in $\varepsilon_0$, and the quantum scale $\hbar$. Put in the measured constants and the formula gives $5.29 \times 10^{-11}$ m. That is a tenth of a nanometer, which is why atomic sizes are usually quoted in tenths of a nanometer or in picometers. In the Bohr model, the orbit for level $n$ has radius $r_n = n^2 a_0$. The level-2 orbit is four times as wide as the level-1 orbit, and the level-3 orbit is nine times as wide. This is a useful picture, but it is only a model. The modern picture is different. In the quantum theory of hydrogen, the electron in the 1s ground state has no fixed orbit. Its distance from the proton is spread out, and the most probable distance is exactly $a_0$, while its average distance is $1.5 a_0$. So $a_0$ remains the natural size of hydrogen, but the electron is not a planet on a circle. ## An everyday picture Think of a standard ruler sized to the atom. The Bohr radius is the unit of length for hydrogen, and other distances in the atom are counted in multiples of it. A level-2 orbit in the old model is 4 of these units wide. ## Worked example: Size of the n = 2 orbit in the Bohr model Find the radius of the second Bohr orbit in hydrogen, $n = 2$. Use $a_0 = 5.29 \times 10^{-11}$ m, the Bohr radius. 1. Use $r_n = n^2 a_0$ with $n = 2$: $r_2 = 2^2 a_0 = 4 a_0$. 2. Multiply: $r_2 = 4 \times 5.29 \times 10^{-11}\ \text{m} = 2.116 \times 10^{-10}$ m. 3. Convert to nanometers: $2.116 \times 10^{-10}$ m $= 0.2116$ nm. **Answer:** The n = 2 orbit in the Bohr model has a radius of about 0.2116 nm, four times the Bohr radius. This is a model size, not a measured orbit of an electron. ## Common mistakes - Treating the Bohr radius as a fixed orbit that the electron travels on. In quantum mechanics the electron's distance from the proton is spread out. - Confusing $\hbar$ with $h$. The $\hbar$ in this formula is $h / 2\pi$, which is about $1.05 \times 10^{-34}$ J s. - Misplacing the level number. The orbit radius is $n^2 a_0$, so $n = 2$ gives $4 a_0$, not $2 a_0$. - Forgetting that the answer is in meters. $5.29 \times 10^{-11}$ m is 0.0529 nm. ## Where you will meet it - Estimating the size of atoms and the spread of electron clouds in chemistry and solid-state physics. - Atomic units, where distances in hydrogen are measured in multiples of $a_0$ and many formulas become simpler. - Estimating the size of exotic atoms, such as positronium or muonic hydrogen, by scaling $a_0$ with the mass of the orbiting particle. - Textbook quantum mechanics, where the hydrogen wave functions are written in terms of $a_0$. ## Questions people ask ### Is the Bohr radius a measured size? It is calculated from fixed constants. Measurements of hydrogen's typical size agree with it, so it is a meaningful scale even though the Bohr orbit picture is not exact. ### Why does the formula have so many constants? Atomic size comes from a balance between electric attraction, set by $\varepsilon_0$ and $e$, and the wave nature of the electron, set by $\hbar$. The electron mass $m_e$ sets how heavy the electron is in that balance. ### Does the Bohr radius change for other atoms? For a one-electron ion with nuclear charge $Z$, the typical size shrinks to $a_0 / Z$. Heavier atoms with many electrons are more complicated. ## Related formulas - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) - [Hydrogen-Like Atom Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy/) - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) ## Sources - [Bohr radius, Wikipedia](https://en.wikipedia.org/wiki/Bohr_radius) - [Bohr model, Wikipedia](https://en.wikipedia.org/wiki/Bohr_model) - [Fundamental physical constants, NIST](https://physics.nist.gov/cuu/Constants/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Hydrogen-Like Atom Energy > An atom or ion with only one electron has energy levels that follow the hydrogen pattern, scaled up by the square of its nuclear charge. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E_n = -\frac{Z^2}{n^2} \times 13.605693\ \text{eV} $$ Read it out loud: "E sub n equals negative Z squared over n squared, times 13.605693 electron volts. E sub n is the energy of level n, Z is the nuclear charge, and n is the level number." ## What each symbol means - $E_n$: The **energy** of the electron in level $n$, in electron volts (eV). It is negative because the electron is bound to the nucleus. - $Z$: The **nuclear charge** in units of the proton charge, which equals the number of protons in the nucleus. Hydrogen has $Z = 1$, and singly ionized helium, He$^+$, has $Z = 2$. - $n$: The **principal quantum number**, a whole number 1, 2, 3 and so on. A larger $n$ means a higher level. - $13.605693\ \text{eV}$: The **Rydberg energy**, the ionization energy of hydrogen from its ground state, in electron volts (eV). ## What the formula is doing The hydrogen energy formula extends to any atom stripped down to a single electron. Examples are He$^+$, Li$^{2+}$ and C$^{5+}$, which are called hydrogen-like or one-electron ions. The electron still sees one nucleus, so the same kind of energy ladder applies, with the strength of the pull set by $Z$. The energies scale with $Z^2$. A nucleus with more protons pulls harder, and each orbit is smaller, so the electron is bound more tightly. Going from hydrogen ($Z = 1$) to He$^+$ ($Z = 2$) multiplies every energy level by $2^2 = 4$. Levels are still numbered by $n$, and they still crowd together as $n$ grows. For a given $Z$, the energy needed to go from level 1 to level 2 is $\frac{3}{4} Z^2 \times 13.6$ eV. The lowest level, $n = 1$, is the most tightly bound. The formula neglects small corrections, so it is approximate for heavier ions. For He$^+$ its ground-state energy is within about a hundredth of a percent of the measured value, which is far more precise than most uses need. ## An everyday picture Think of the staircase from the hydrogen atom, built in a stronger building. More protons in the nucleus means a stronger pull, so every step sits deeper below the zero line. The steps keep their shape, but each one is scaled by $Z^2$. ## Worked example: Ground state and first jump of He$^+$ Find the ground-state energy of He$^+$, which has $Z = 2$ and $n = 1$, and the energy of the photon emitted when its electron falls from $n = 2$ to $n = 1$. Use 13.605693 eV for the constant. 1. Ground state: $E_1 = -\frac{2^2}{1^2} \times 13.605693\ \text{eV} = -54.4228$ eV. 2. Level 2: $E_2 = -\frac{2^2}{2^2} \times 13.605693\ \text{eV}$, or $E_2 = -13.6057$ eV for $Z = 2$ at $n = 2$. 3. Photon energy: $E_{\text{photon}} = E_2 - E_1 = (-13.6057) - (-54.4228) \approx 40.8171$ eV. 4. Wavelength: $\lambda = \frac{1239.84\ \text{eV nm}}{40.8171\ \text{eV}} \approx 30.38$ nm. **Answer:** The He$^+$ ground state is $-54.42$ eV. The jump from $n = 2$ to $n = 1$ emits a photon of about 40.82 eV with a wavelength near 30.38 nm, in the extreme ultraviolet. Hydrogen's same jump is only about 10.2 eV, since the He$^+$ energies are four times larger. ## Common mistakes - Using $Z = 1$ for every ion. Count the protons in the nucleus, not the electrons: He$^+$ has $Z = 2$. - Forgetting the $Z^2$. Doubling $Z$ makes every energy four times bigger, not twice as big. - Dropping the minus sign. The bound levels are negative, so the lowest level has the most negative energy. - Using this formula for a neutral atom with several electrons. It needs exactly one electron, so neutral helium does not follow it. ## Where you will meet it - Astronomy, where lines from ionized helium identify very hot gas around stars and in the Sun's atmosphere. - Plasma physics and fusion research, where the spectra of highly ionized atoms show the temperature of the plasma. - Estimating ionization energies of hydrogen-like heavy ions, which grow with $Z^2$. - Introductory atomic physics, where the one-electron ions are the first step beyond hydrogen. ## Questions people ask ### What is a hydrogen-like atom? It is an atom or ion with only one electron, such as He$^+$, Li$^{2+}$ or C$^{5+}$. The nucleus has charge $+Ze$, and the single electron feels that charge. ### Why does the energy scale with $Z^2$? The electron's potential energy grows with $Z$, and each orbit shrinks as $1 / Z$. Together these make the energy scale as $Z^2$. ### Can I use this for a molecule? No. Molecules have several nuclei and several electrons, so the one-nucleus formula does not apply. ## Related formulas - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) - [Rydberg Formula](https://formulabro.yunusemrevurgun.com/quantum-mechanics/rydberg-formula/) - [Bohr Radius](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius/) ## Sources - [Hydrogen-like atom, Wikipedia](https://en.wikipedia.org/wiki/Hydrogen-like_atom) - [Bohr model, Wikipedia](https://en.wikipedia.org/wiki/Bohr_model) - [Rydberg formula, Wikipedia](https://en.wikipedia.org/wiki/Rydberg_formula) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Electron Shell Capacity > The shell with number n can hold at most twice n squared electrons, because it has n squared places and each place takes two electrons. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ N_{\max} = 2 n^2 $$ Read it out loud: "N max equals 2 times n squared. N max is the most electrons a shell can hold, and n is the shell number: 1, 2, 3 and so on." ## What each symbol means - $N_{\max}$: The **maximum number of electrons** that the shell with number $n$ can hold. It is a whole number. - $n$: The **shell number**, the principal quantum number: 1, 2, 3 and so on. Shell 1 is closest to the nucleus. ## What the formula is doing Electrons in an atom occupy shells, labeled by the whole number $n$. The formula $N_{\max} = 2 n^2$ gives the most electrons a shell can hold. Shell 1 holds 2 electrons, shell 2 holds 8, shell 3 holds 18, and shell 4 holds 32. The $n^2$ comes from counting orbitals. Shell $n$ has $n^2$ orbitals, the places an electron's wave can occupy. Shell 2 has four: one 2s orbital and three 2p orbitals. Each orbital holds at most two electrons, and the two must have opposite spin, which gives the factor of 2. Shells are not filled one at a time. Electrons go into the lowest-energy subshells first, following the aufbau principle and the Madelung rule. The 4s subshell fills before the 3d subshell, even though 3d belongs to the third shell. So a shell can still be partly filled while the next one has already started. The count is a maximum, not a fixed number. Many atoms have fewer electrons in a shell than the limit, and the outer shell is often only partly full. The formula gives the limit, and the filling order tells you where the electrons actually go. ## An everyday picture Think of a building with floors of apartments. Floor $n$ has $n^2$ rooms, and each room fits two people as long as they differ in one small way, the spin. Floor 1 has 1 room, floor 2 has 4 rooms and floor 3 has 9 rooms. The capacity of a floor is twice its room count, which is $2 n^2$. ## Worked example: Electrons in potassium, element 19 A neutral potassium atom has 19 electrons. The shell limits are $N_{\max} = 2 n^2$, which gives 2 for shell 1, 8 for shell 2, 18 for shell 3 and 32 for shell 4. Find how the 19 electrons fill the shells. 1. Shell 1 holds up to 2 electrons. Put 2 in it, leaving $19 - 2 = 17$. 2. Shell 2 holds up to 8 electrons. Put 8 in it, leaving $17 - 8 = 9$. 3. Shell 3 could hold 18, but the 4s subshell fills before the last 3d subshell. Put 8 in shell 3 (2 in 3s and 6 in 3p), leaving $9 - 8 = 1$. 4. The last electron goes into the 4s subshell of shell 4. **Answer:** Potassium's 19 electrons are arranged 2, 8, 8, 1 across the first four shells. Shell 3 has room for 18 but holds only 8, because the last electron goes into 4s rather than 3d. The configuration is written $1s^2\ 2s^2\ 2p^6\ 3s^2\ 3p^6\ 4s^1$. ## Common mistakes - Using $2n$ instead of $2n^2$. Shell 3 holds 18 electrons, not 6. - Assuming shell 3 must be full before shell 4 starts. In potassium the last electron sits in 4s while 3d is still empty. - Confusing shells with subshells. Shell 2 has a 2s subshell with 2 electrons and a 2p subshell with 6, which add up to 8. - Expecting the simple filling order to hold for every element. Chromium and copper are exceptions, because one electron moves from 4s to 3d, which makes a half-full or full d subshell more stable. ## Where you will meet it - Chemistry courses, where the shell limits explain how many electrons an atom can hold in each layer. - Explaining the rows of the periodic table, which are 2, 8, 8, 18, 18 and 32 elements long because of the subshell filling order. - Predicting the outer-shell electrons that control chemical bonding. - Atomic spectroscopy, where the energy levels of shells and subshells produce the lines seen in spectra. ## Questions people ask ### Why does a shell hold $2n^2$ and not $n$ electrons? Each shell has $n^2$ orbitals, and each orbital holds two electrons with opposite spins. Shell 2 has four orbitals, so it holds eight electrons. ### Why does 4s fill before 3d? The Madelung rule ranks subshells by $n + l$, where $l$ is the orbital shape number. For 4s, $n + l = 4$, and for 3d, $n + l = 5$, so 4s comes first in a neutral atom. ### Are the numbers 2, 8, 18 and 32 exact? They are the maximum counts given by the counting rule. Real atoms can have fewer electrons in a shell, and the exceptions to the filling order show that the simple rule is an approximation. ## Related formulas - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) - [Bohr Radius](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius/) - [Spin One-Half](https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/) ## Sources - [Electron shell, Wikipedia](https://en.wikipedia.org/wiki/Electron_shell) - [Aufbau principle, Wikipedia](https://en.wikipedia.org/wiki/Aufbau_principle) - [Electron configuration, Wikipedia](https://en.wikipedia.org/wiki/Electron_configuration) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Particle in a Box > A particle trapped between two walls can only have certain energies, and this formula gives them: the narrower the box, the higher the energies. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E_n = \frac{n^2 h^2}{8 m L^2}, \qquad n = 1, 2, 3, \dots $$ Read it out loud: "E sub n equals n squared times h squared, divided by 8 times m times L squared. E sub n is the energy of level n, n is the level number starting at 1, h is Planck's constant, m is the particle's mass and L is the width of the box." ## What each symbol means - $E_n$: The energy of level $n$, in joules (J). Atoms and molecules are often described in electron volts (eV) instead, where $1\ \text{eV} = 1.602 \times 10^{-19}$ J. - $n$: The level number, a whole number starting at 1: $n = 1, 2, 3, \dots$. It counts the half-waves that fit inside the box. - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s (joule seconds). Its value is exact by definition in the SI system. - $m$: The mass of the particle, in kilograms (kg). For an electron, $m = 9.1093837 \times 10^{-31}$ kg. - $L$: The width of the box, in meters (m). The walls sit at the two ends, and the particle stays between them. ## What the formula is doing A particle trapped between two walls is one of the first problems in quantum mechanics. Its wave must be zero at both walls, and only certain wave patterns fit between them. Each pattern has one energy, so the particle can have only certain energies, called energy levels. It cannot take any value it likes. The formula $E_n = \frac{n^2 h^2}{8 m L^2}$ gives those levels. The level number $n$ counts the half-waves that fit in the box: level 1 has one half-wave, level 2 has two, and so on. More half-waves means shorter waves, and shorter waves carry more energy. The energy grows as $n^2$, not as $n$. Level 2 is four times as high as level 1, and level 3 is nine times as high. The gaps between neighboring levels therefore get larger as you go up. The $L^2$ in the bottom line matters most. Halving the width makes every energy four times larger. A heavier particle has lower energies, because $m$ is in the bottom line too. This is why the formula matters at the nanometer scale, where electron energies are in the electron-volt range, and why a box one meter wide has levels packed so close that they act like a continuous range. This is an idealized model. Real walls are not infinitely high, so the wave leaks into them a little and the levels shift. The formula is exact only for the ideal box, but it is a good first picture of electrons confined in tiny regions. ## An everyday picture Think of a ladder whose rungs spread out as you climb. The particle can stand only on the rungs, never between them. The first rung sits low, the second is four times as high above the floor, and the third is nine times as high. A narrower box is like a ladder with wider gaps between the rungs, so every energy is higher and the steps between them are bigger. ## Worked example: An electron in a 1.0 nm box An electron (mass $m = 9.1093837 \times 10^{-31}$ kg) is trapped in a box of width $L = 1.0$ nm $= 1.0 \times 10^{-9}$ m. Find the energies of the first three levels in electron volts (eV), and the energy needed to move from level 1 to level 2. 1. Level 1 in joules: $E_1 = \frac{h^2}{8 m L^2} = \frac{(6.62607015 \times 10^{-34})^2}{8 (9.1093837 \times 10^{-31})(1.0 \times 10^{-9})^2} \approx 6.02 \times 10^{-20}$ J. 2. Convert to electron volts: $E_1 = \frac{6.02 \times 10^{-20}}{1.602 \times 10^{-19}} \approx 0.376$ eV. 3. Level 2: $E_2 = 2^2 E_1 = 4 E_1 \approx 1.50$ eV. 4. Level 3: $E_3 = 3^2 E_1 = 9 E_1 \approx 3.38$ eV. 5. Energy to go from level 1 to level 2: $E_2 - E_1 = 3 E_1 \approx 1.13$ eV. **Answer:** The first three levels of this electron are **0.376 eV**, **1.50 eV** and **3.38 eV**. Moving from level 1 to level 2 takes about **1.13 eV**. The lowest level is above zero, because a wave that must vanish at both walls cannot be flat. ## Common mistakes - Leaving the width in nanometers. Convert 1.0 nm to $1.0 \times 10^{-9}$ m before squaring. Using $L = 1.0$ instead makes the energy $10^{18}$ times too small. - Assuming the lowest energy can be zero. Level $n = 1$ is above zero, because a wave that must vanish at both walls cannot be flat. - Starting the count at $n = 0$. That would give zero energy and a wave that is zero everywhere, which means no particle. The level numbers start at 1. - Doubling the energy when $n$ doubles. The energy depends on $n^2$, so $E_2 = 4 E_1$ and $E_3 = 9 E_1$, not $2 E_1$ and $3 E_1$. ## Where you will meet it - Quantum dots, tiny semiconductor crystals whose color depends on their size, because the size sets how far apart the confined electron levels are. - Quantum well lasers and LEDs, which use thin semiconductor layers to trap electrons in one direction, with energy levels set by the same idea. - Estimating the energies of the electrons that move along the carbon chains of conjugated dye molecules, using a one-dimensional box as a simple model. ## Questions people ask ### Why does the level count start at 1 and not 0? With $n = 0$ the wave would be zero everywhere, so there would be no particle in the box. The lowest allowed wave has one half-wave, which is $n = 1$. ### Why does the energy grow as $n^2$? The wave number $k$, which measures how fast the wave's phase turns per meter, is $k = \frac{n\pi}{L}$ for level $n$. Energy depends on $k^2$, so it grows as $n^2$. ### Is a real electron trapped in a box like this? Not exactly. Real walls are finite, so the levels shift a little and the wave leaks into the walls. The ideal box is the simplest model that shows why energy comes in discrete levels. ## Related formulas - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) - [Quantum Harmonic Oscillator](https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-harmonic-oscillator/) - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) ## Sources - [Particle in a box, Wikipedia](https://en.wikipedia.org/wiki/Particle_in_a_box) - [Planck constant, Wikipedia](https://en.wikipedia.org/wiki/Planck_constant) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Quantum Harmonic Oscillator > A quantum particle on a spring can only have energies in equal steps, and even its lowest step sits above zero. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-harmonic-oscillator/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E_n = \hbar \omega \left(n + \frac{1}{2}\right), \qquad n = 0, 1, 2, \dots $$ Read it out loud: "E sub n equals h-bar times omega times the quantity n plus one half. E sub n is the energy of level n, h-bar is the reduced Planck constant, omega is the angular frequency, and n is the level number, starting at 0." ## What each symbol means - $E_n$: The energy of level $n$, in joules (J). For molecules, electron volts (eV) are more convenient: $1\ \text{eV} = 1.602 \times 10^{-19}$ J. - $n$: The level number, $n = 0, 1, 2, \dots$. Level 0 is the ground state, the lowest energy the oscillator can have. - $\hbar$: The reduced Planck constant, $1.054571817 \times 10^{-34}$ J s (joule seconds). - $\omega$: The angular frequency, in radians per second (rad/s). It equals $2\pi f$, where $f$ is the ordinary frequency in hertz (Hz). ## What the formula is doing A harmonic oscillator is a particle pulled back toward a fixed point by a force that grows with its distance, like a mass on a spring. Atoms in molecules and in crystals behave this way for small vibrations, so the model appears throughout physics. In classical physics the energy of such an oscillator can take any value. In quantum physics it cannot. The formula $E_n = \hbar\omega\left(n + \frac{1}{2}\right)$ says the levels are evenly spaced. Each step up adds one unit, $\hbar\omega$, and that unit depends only on the angular frequency. For a mass $m$ on a spring of stiffness $k$, $\omega = \sqrt{k/m}$. A stiffer spring or a lighter mass gives a higher $\omega$ and bigger steps. The lowest level is $n = 0$, and its energy is $\frac{1}{2}\hbar\omega$, not zero. This is the zero-point energy. A particle sitting at rest at the bottom of the bowl would have a definite position and a definite momentum of zero, and the uncertainty principle does not allow both. So the lowest state keeps some energy. In molecules, the bonds between atoms act like springs. A molecule can absorb a photon whose energy equals one step, $\hbar\omega = hf$, and move up one level. That is why infrared light is absorbed at the frequencies of molecular vibrations. The formula is an approximation. Real bonds stretch further and eventually break, so at high energy the steps get smaller than the formula predicts. The harmonic model works best for small vibrations near the bottom of the energy well. ## An everyday picture Think of a staircase with evenly spaced steps. You can stand on a step but never between two steps. In the quantum version of a bowl, the lowest step is not on the floor. It sits half a step up, because the particle can never come to a complete rest at the bottom. A stiffer bond or a lighter atom makes the steps taller, so the staircase rises faster. ## Worked example: Vibration of a C-H bond A carbon-hydrogen (C-H) bond in a molecule vibrates with a frequency of about $f = 9.0 \times 10^{13}$ Hz. That is close to the stretching frequency of C-H bonds, about 3000 waves per centimeter in spectroscopy units. Find the zero-point energy and the energy of the first excited level, in electron volts (eV). 1. Angular frequency: $\omega = 2\pi f = 2\pi (9.0 \times 10^{13}\ \text{Hz}) \approx 5.65 \times 10^{14}$ rad/s. 2. Energy step: $\hbar\omega = (1.054571817 \times 10^{-34})(5.65 \times 10^{14}) \approx 5.96 \times 10^{-20}$ J. 3. In electron volts: $\hbar\omega \approx \frac{5.96 \times 10^{-20}}{1.602 \times 10^{-19}} \approx 0.372$ eV. 4. Zero-point energy: $E_0 = \frac{1}{2}\hbar\omega \approx 0.186$ eV. 5. First excited level: $E_1 = \frac{3}{2}\hbar\omega \approx 0.558$ eV. 6. Wavelength of a photon with energy $\hbar\omega = hf$: $\lambda = \frac{c}{f} = \frac{3.00 \times 10^{8}\ \text{m/s}}{9.0 \times 10^{13}\ \text{Hz}} \approx 3.33 \times 10^{-6}$ m. **Answer:** The lowest vibrational energy of this bond is **0.186 eV**, and the energy steps are **0.372 eV**. A photon with that energy has a wavelength of about **3.3 micrometers**, in the infrared, which is why bonds like this absorb infrared light. ## Common mistakes - Thinking the ground state has zero energy. The lowest level is $n = 0$, with energy $\frac{1}{2}\hbar\omega$, which is above zero. - Dropping the one half and writing $E_n = n\hbar\omega$. That formula puts the ground state at zero and gets every level wrong. - Using the ordinary frequency $f$ where the formula needs the angular frequency $\omega$. Since $\omega = 2\pi f$, the energies come out about $2\pi$ times too small. - Using the harmonic formula for large vibrations. Real bonds stretch and break, so at high energy the levels are closer together than the formula predicts. ## Where you will meet it - Infrared spectroscopy, where molecules absorb infrared light at frequencies that match the spacing between their vibrational levels. - Modeling the vibrations of atoms in crystals as quantized sound waves, called phonons. - Quantum field theory, where each mode of a field is treated as a harmonic oscillator. - Quantum chemistry programs, which often start from the harmonic approximation to estimate molecular vibration frequencies. ## Questions people ask ### Why is there energy even in the ground state? A particle at the exact bottom of the bowl, with no motion, would have a definite position and a definite momentum of zero. The uncertainty principle does not allow that, so the lowest state keeps the zero-point energy $\frac{1}{2}\hbar\omega$. ### Why are the energy steps all the same size? For an ideal spring-like force the levels are equally spaced. That is why one photon with energy $hf = \hbar\omega$ moves the oscillator from one level to the next. ### Are molecules really harmonic oscillators? Only approximately. The model is good for small vibrations near the bottom of the energy well. At higher energy, real bonds stretch further and the levels bunch together. ## Related formulas - [Particle in a Box](https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) - [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/) ## Sources - [Quantum harmonic oscillator, Wikipedia](https://en.wikipedia.org/wiki/Quantum_harmonic_oscillator) - [Zero-point energy, Wikipedia](https://en.wikipedia.org/wiki/Zero-point_energy) - [Infrared spectroscopy, Wikipedia](https://en.wikipedia.org/wiki/Infrared_spectroscopy) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Quantum Tunneling Probability > A quantum particle can sometimes pass through a barrier that is too high for it to climb over, and this formula estimates how often. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-tunneling-probability/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ T \approx e^{-2\kappa L} $$ Read it out loud: "T is approximately e to the power of minus 2 kappa L. T is the chance that the particle gets through the barrier, kappa is how fast the wave fades inside the barrier, and L is the width of the barrier." ## What each symbol means - $T$: The transmission probability, the chance that the particle gets through the barrier. It is a number from 0 to 1 and has no units. - $e$: Euler's number, about 2.718, the base of natural logarithms. It is not the elementary charge. - $\kappa$: The decay constant inside the barrier, in 1/m. It equals $\kappa = \frac{\sqrt{2m(V_0 - E)}}{\hbar}$. A large $\kappa$ means the wave dies out quickly as it enters the barrier. - $L$: The width of the barrier, in meters (m). - $m$: The mass of the particle, in kilograms (kg). - $E$: The energy of the particle, in joules (J). The formula assumes $E < V_0$, so the particle does not have enough energy to go over the barrier. - $V_0$: The height of the barrier, in joules (J). It is the potential energy at the top of the barrier. - $\hbar$: The reduced Planck constant, $1.054571817 \times 10^{-34}$ J s. ## What the formula is doing In everyday life, a ball that lacks the energy to roll over a hill stays on its side. In quantum mechanics, the wave of a particle does not stop sharply at the edge of a barrier. It fades inside the barrier, and a small part of it can reach the far side. The formula $T \approx e^{-2\kappa L}$ estimates the chance $T$ that the particle gets through. The energy $E$ is the particle's energy and $V_0$ is the barrier height. Their difference, $V_0 - E$, is the energy the particle is missing. The decay constant $\kappa = \frac{\sqrt{2m(V_0 - E)}}{\hbar}$ grows with the square root of the mass and with the missing energy. Heavy particles and tall barriers therefore tunnel less. The exponent $-2\kappa L$ does most of the work. The chance falls exponentially with the width $L$, so each extra bit of width multiplies $T$ by the same fraction. In this approximation, doubling the width squares $T$, which makes the chance drop very fast. This is a thick-barrier estimate. For a thick rectangular barrier, the exact result carries an extra prefactor, $\frac{16E}{V_0}\left(1 - \frac{E}{V_0}\right)$, which the formula drops. That prefactor is close to 1 when $E$ is about 7 percent of $V_0$, as in the example below, but it is far from 1 for much smaller or larger ratios. The exponential part is the part that changes most from one barrier to the next. ## An everyday picture Think of the sound of a neighbor's music through a wall. A thin wall lets through plenty of bass, while a thick wall removes much more. Each extra bit of thickness takes away the same fraction of what is left, though a little always gets through. Tunneling works the same way: the wave fades exponentially inside the barrier, so a thicker barrier lets far less through, but never exactly nothing. ## Worked example: An electron meets a 3.0 eV barrier An electron with energy $E = 0.20$ eV meets a barrier of height $V_0 = 3.0$ eV and width $L = 0.30$ nm $= 3.0 \times 10^{-10}$ m. The electron mass is $m = 9.1093837 \times 10^{-31}$ kg. Estimate the chance $T$ that the electron tunnels through. 1. Missing energy: $V_0 - E = 3.0$ eV $- 0.20$ eV $= 2.8$ eV $= 2.8 \times 1.602 \times 10^{-19}$ J $\approx 4.486 \times 10^{-19}$ J. 2. Decay constant: $\kappa = \frac{\sqrt{2 m (V_0 - E)}}{\hbar} = \frac{\sqrt{2 (9.1093837 \times 10^{-31})(4.486 \times 10^{-19})}}{1.054571817 \times 10^{-34}} \approx 8.573 \times 10^{9}\ \text{m}^{-1}$. 3. Width times decay constant: $\kappa L \approx (8.573 \times 10^{9}\ \text{m}^{-1})(3.0 \times 10^{-10}\ \text{m}) \approx 2.572$. 4. Exponent: $2\kappa L \approx 2 \times 2.572 = 5.144$. 5. Estimate: $T \approx e^{-5.144} \approx 0.0058$, or about 0.58 percent. 6. Prefactor check: $\frac{16E}{V_0}\left(1 - \frac{E}{V_0}\right) = 16 \times \frac{0.20}{3.0} \times \frac{2.8}{3.0} \approx 0.996$, so the dropped prefactor is almost exactly 1 here. **Answer:** The chance that the electron tunnels is about **0.58 percent**, or roughly **1 in 170**. That is small but not zero. Doubling the barrier width to 0.60 nm would make the chance roughly 170 times smaller. ## Common mistakes - Thinking a particle with less energy than the barrier can never get through. Quantum particles have a small chance of tunneling, and the formula estimates that chance. - Using the barrier height $V_0$ where the formula needs the missing energy $V_0 - E$. Subtract first, then take the square root. - Leaving the energies in electron volts. The formula needs joules, so convert $V_0 - E$ with $1\ \text{eV} = 1.602 \times 10^{-19}$ J. Skipping this makes $\kappa$ about $2.5 \times 10^{9}$ times too large. - Treating the answer as exact. The formula drops a prefactor, so it estimates the exponential part only, and it can be off by a factor of a few for some energies. ## Where you will meet it - Scanning tunneling microscopes, which pass a tiny current across a gap of about one nanometer. The current depends steeply on the gap, which lets the microscope image single atoms. - Alpha decay, where an alpha particle escapes a heavy nucleus by tunneling through the energy barrier that holds it inside. - Nuclear fusion in the Sun, where protons must tunnel through their electrical repulsion to get close enough to fuse. - Flash memory, where electrons tunnel through a thin insulating oxide layer to store or erase data. ## Questions people ask ### Does tunneling mean the particle borrows energy? No. In this picture the particle keeps its energy $E$, and tunneling is not a way of climbing over the barrier. The wave has a small chance of reaching the far side. ### Why does a thicker barrier block so much more? The chance depends on $e^{-2\kappa L}$, so every extra nanometer of barrier multiplies the chance by the same factor. In the example, $2\kappa L$ grows by about 1.7 for each extra 0.1 nm, which cuts the chance to about 0.18 of its value. ### Is the formula exact? No. It is a thick-barrier estimate, and it drops a prefactor that the exact result contains. For the example here the estimate and the exact value differ by less than 0.2 percent, but for other energies the difference can be larger. ## Related formulas - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) ## Sources - [Quantum tunnelling, Wikipedia](https://en.wikipedia.org/wiki/Quantum_tunnelling) - [Scanning tunneling microscope, Wikipedia](https://en.wikipedia.org/wiki/Scanning_tunneling_microscope) - [Alpha decay, Wikipedia](https://en.wikipedia.org/wiki/Alpha_decay) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Wave Function Normalization > Normalizing a wave function means scaling it so the chances of finding the particle, added over every place, total exactly one. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \int_{-\infty}^{\infty} |\psi(x)|^2\, dx = 1 $$ Read it out loud: "The integral from minus infinity to plus infinity of the squared size of psi of x, times d x, equals 1. In words: add up the probability density over every position, and the total must be exactly one." ## What each symbol means - $\int_{-\infty}^{\infty}$: The integral over all positions, from minus infinity to plus infinity. It adds up many thin slices, each of width $dx$. - $|\psi(x)|^2$: The probability density at position $x$, the squared size of the wave function. In one dimension it has units of $\text{m}^{-1}$. - $\psi(x)$: The wave function at position $x$. It is a complex number with units of $\text{m}^{-1/2}$ in one dimension. - $x$: The position along a line, in meters (m). - $dx$: A very thin slice of position, of width $dx$, in meters (m). The integral adds these slices up. ## What the formula is doing The wave function $\psi(x)$ does not give a probability directly. Its squared size, $|\psi(x)|^2$, is a probability density, meaning the chance per unit length. To get the chance of finding the particle in a region, add up the density over that region. The particle has to be somewhere, so the total over all positions must be exactly 1. That total is the integral $\int_{-\infty}^{\infty} |\psi(x)|^2\, dx$. Think of it as adding up many thin slices. Each slice has density $|\psi|^2$ and width $dx$, so it holds a small piece of probability. The sum over all the slices is the total chance. A wave function with a total of exactly 1 is called normalized. Units check the rule. The density $|\psi|^2$ is in $\text{m}^{-1}$ and $dx$ is in meters, so their product is a pure number, which can be 1. That is why $\psi$ itself has units of $\text{m}^{-1/2}$ in one dimension. If the integral comes out to some other number $N$, the wave function is not normalized yet. Divide $\psi$ by $\sqrt{N}$. The new integral is $\frac{1}{N}$ times the old one, which equals 1. Multiplying $\psi$ by a constant changes its size but not its shape, so the relative probabilities stay the same. Normalization is also kept over time. The Schrödinger equation conserves the total probability, so a normalized wave function stays normalized as it evolves. ## An everyday picture Imagine spreading a bag of flour along a long table. The amount in each centimeter is the density, and adding up all the centimeters gives the whole bag. If the table holds two bags' worth, you scale every amount down until the total is exactly one bag. Normalizing a wave function does the same thing to its squared size. ## Worked example: A particle spread over a 2.0 m track A particle moves along a track 2.0 m long. Its wave function is a constant $C$ between $x = 0$ and $x = 2.0$ m, and zero everywhere else. Find the value of $C$ that normalizes the wave function, then find the chance that the particle is in the first meter of the track. 1. Only the track contributes, because $\psi = 0$ outside it: $\int_{-\infty}^{\infty} |\psi|^2\, dx = \int_{0}^{2.0} C^2\, dx = 2.0\, C^2$. 2. Set the total to 1: $2.0\, C^2 = 1$, so $C^2 = 0.5$. 3. Take the square root: $C = \sqrt{0.5} \approx 0.707\ \text{m}^{-1/2}$. 4. Chance in the first meter: $\int_{0}^{1.0} C^2\, dx = C^2 \times 1.0\ \text{m} = 0.5 \times 1.0 = 0.5$. **Answer:** The normalizing constant is $C \approx 0.707\ \text{m}^{-1/2}$. The chance of finding the particle in the first meter is **0.5**, or **50 percent**, which is half the track, as an even spread would give. ## Common mistakes - Normalizing $\psi$ instead of $|\psi|^2$. The rule is about the squared size. For a complex wave function, $\psi$ can be complex or negative, so $\int \psi\, dx = 1$ is the wrong test. - Dividing by the integral instead of its square root. If $\psi$ is multiplied by $c$, the integral is multiplied by $c^2$. So the correct divisor is $\sqrt{N}$, not $N$. - Integrating over only part of space and calling the result 1. The integral must cover all positions. In the example it covers only the track, because the wave is zero everywhere else. - Trying to normalize a wave with the same size everywhere on an infinite line. Its integral is infinite, so no constant can make it equal 1. Physicists use wave packets or boxes to get normalizable waves. ## Where you will meet it - Quantum chemistry programs, which normalize each orbital before computing the electron density around atoms and molecules. - Textbook solutions for the particle in a box and the harmonic oscillator, where a normalization constant appears in every wave function. - Computer simulations of wave packets, which check that the total probability on the grid stays at 1 as time passes. - Any probability calculation from a wave function, because the chance of a region is an integral of $|\psi|^2$ that gives a true probability only for a normalized wave. ## Questions people ask ### Why can't a wave function be any function? Its squared size must add up to a finite total that can be scaled to exactly 1. A function whose squared size adds up to infinity cannot be scaled that way, so it cannot be the wave function of one particle in the usual sense. ### Does normalizing change the physics? No. Multiplying by a constant changes the overall scale of the wave function, not the relative chances. Two wave functions that differ only by a constant factor describe the same state. ### Why integrate instead of add? Position is continuous, so there are infinitely many positions. The integral is the continuous version of adding up many small pieces. For a list of separate outcomes, the same idea is a sum, as in the expectation value example. ## Related formulas - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [Expectation Value](https://formulabro.yunusemrevurgun.com/quantum-mechanics/expectation-value/) - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) ## Sources - [Wave function, Wikipedia](https://en.wikipedia.org/wiki/Wave_function) - [Born rule, Wikipedia](https://en.wikipedia.org/wiki/Born_rule) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Expectation Value > The expectation value is the average result you would get if you repeated a measurement many times on identical particles. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/expectation-value/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \langle x \rangle = \int_{-\infty}^{\infty} x\, |\psi(x)|^2\, dx $$ Read it out loud: "The expectation value of x, written with angle brackets, equals the integral from minus infinity to plus infinity of x times the squared size of psi of x, times d x. It gives the average position." ## What each symbol means - $\langle x \rangle$: The expectation value of position: the average position over many measurements on identical particles, in meters (m). - $x$: The position, in meters (m). Inside the integral it is the value being averaged. - $|\psi(x)|^2$: The probability density at position $x$, which acts as the weight for each position. Its units are $\text{m}^{-1}$. - $\psi(x)$: The wave function at position $x$, a complex number. Its squared size gives the probability density. - $dx$: A thin slice of position, of width $dx$, in meters (m). The integral adds these slices up. - $\int_{-\infty}^{\infty}$: The integral over all positions. It is the continuous version of a sum. - $a_i$: The possible result number $i$ of a measurement, such as one energy value. In the discrete version these are the only values that can come out. - $P(a_i)$: The probability of result $a_i$. All the probabilities add up to 1. ## What the formula is doing The expectation value $\langle A \rangle$ of a quantity is the average you get when you measure it many times on identical systems. It is not one measured result. Each possible result counts in proportion to how likely it is, so the average leans toward the common outcomes. When the possible results are separate values, the rule is a weighted sum: $\langle a \rangle = \sum_i a_i P(a_i)$. Multiply each possible result $a_i$ by its probability $P(a_i)$, then add. The probabilities must add to 1, so each weight is a fair share of the whole. Position is continuous, so there is no list of separate results. The sum becomes an integral, and the density $|\psi(x)|^2$ plays the role of the probabilities. In $\langle x \rangle = \int x\, |\psi(x)|^2\, dx$, each position $x$ is weighted by the density at that spot, and the thin slices $dx$ add up over the whole line. For the lowest state of a box of width $L$, the density is symmetric about the middle of the box. The average position is therefore $\langle x \rangle = \frac{L}{2}$, the center of the box. Symmetry gives the answer without doing the integral. An expectation value is an average, so it does not show how far single results scatter. Pair it with the spread, the standard deviation, to see how far single measurements land from the average. The expectation value can also be a number that no single measurement can give, as the example below shows. ## An everyday picture Think of a class test. If half the students score 1, 30 percent score 2 and 20 percent score 4, the class average is 1.9, even though no student scored 1.9. Each score counts in proportion to how many students got it. The expectation value works the same way, weighting each possible result by its probability. ## Worked example: Average energy from a measurement A measurement of the energy of a particle gives one of three values. The value 1 eV has probability 0.5, the value 2 eV has probability 0.3, and the value 4 eV has probability 0.2. Find the expectation value of the energy. 1. Check the probabilities: $0.5 + 0.3 + 0.2 = 1.0$. 2. Multiply each value by its probability: $1 \times 0.5 = 0.5$ eV, $2 \times 0.3 = 0.6$ eV and $4 \times 0.2 = 0.8$ eV. 3. Add the three products: $\langle E \rangle = 0.5 + 0.6 + 0.8 = 1.9$ eV. **Answer:** The expectation value of the energy is **1.9 eV**. No single measurement gives 1.9 eV, because the possible results are only 1, 2 and 4 eV. Over many measurements, though, the average of the results gets close to 1.9 eV. ## Common mistakes - Averaging the possible results without weights. The plain average of 1, 2 and 4 is 2.33, which is the wrong answer here. Each result must be weighted by its probability. - Expecting the answer to be one of the possible results. The value 1.9 eV is not a result that a single measurement can give. It is an average. - Using $\psi$ in place of $|\psi|^2$ in the integral. The probability density is the squared size of $\psi$, and $\psi$ itself can be negative or complex. - Leaving out the factor $x$ and integrating only $|\psi|^2$. That gives the total probability, which is 1, not the average position. ## Where you will meet it - Quantum chemistry, where the expectation value of the energy for a trial wave function gives an upper bound on the lowest possible energy. - Quantum computing, where algorithms such as the variational quantum eigensolver estimate expectation values of molecular energies. - Experiments with atoms, photons and spins, where many repeated measurements are averaged and compared with a calculated expectation value. ## Questions people ask ### Is the expectation value the most likely result? Not always. The most likely result is the peak of the probability distribution. The expectation value is the average, which can sit away from the peak, especially when the distribution is lopsided. ### Does one measurement give the expectation value? No. One measurement gives one of the possible results. The expectation value shows up as the average of many measurements on identical systems. ### How many measurements does the average need? The more measurements you average, the closer the result gets to the expectation value. The random scatter of the average shrinks roughly as $\frac{1}{\sqrt{N}}$ for $N$ measurements. ## Related formulas - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [Wave Function Normalization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization/) - [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/) ## Sources - [Expectation value (quantum mechanics), Wikipedia](https://en.wikipedia.org/wiki/Expectation_value_(quantum_mechanics)) - [Expected value, Wikipedia](https://en.wikipedia.org/wiki/Expected_value) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Qubit State > A qubit is a quantum bit that can hold a mix of 0 and 1, described by two amplitudes whose squared sizes give the chances of each result. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ |\psi\rangle = \alpha|0\rangle + \beta|1\rangle, \qquad |\alpha|^2 + |\beta|^2 = 1 $$ Read it out loud: "Ket psi equals alpha times ket 0, plus beta times ket 1, where the squared size of alpha plus the squared size of beta equals 1. Psi is the qubit state, alpha and beta are its amplitudes, and 0 and 1 are the two basis states." ## What each symbol means - $|\psi\rangle$: The state of the qubit, written in Dirac's ket notation. It is described by two complex numbers, the amplitudes $\alpha$ and $\beta$. - $|0\rangle$: The basis state 0, one of the two outcomes you can measure. Like a classical bit, it is one definite value. - $|1\rangle$: The basis state 1, the other possible measurement outcome. - $\alpha$: The amplitude of $|0\rangle$. It is a complex number, with a size and a phase. Its squared size $|\alpha|^2$ is the probability of measuring 0. - $\beta$: The amplitude of $|1\rangle$, also complex. Its squared size $|\beta|^2$ is the probability of measuring 1. - $|\alpha|^2 + |\beta|^2$: The total probability. It must equal 1, because a measurement always gives 0 or 1. ## What the formula is doing A classical bit is either 0 or 1. A qubit is the quantum version: a two-level system whose state can mix 0 and 1. Its state is written $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$. The basis states $|0\rangle$ and $|1\rangle$ are the two outcomes a measurement can give, and $\alpha$ and $\beta$ say how much of each the state contains. The amplitudes $\alpha$ and $\beta$ are complex numbers, and they are not probabilities. The probability of each outcome comes from the Born rule: $P(0) = |\alpha|^2$ and $P(1) = |\beta|^2$. For example, $\alpha = 0.6$ gives a 36 percent chance of measuring 0, not 60 percent. The rule $|\alpha|^2 + |\beta|^2 = 1$ is the same idea as normalization for a wave function. The two probabilities must add to 1, because a measurement always gives 0 or 1. A pair of amplitudes that breaks this rule is not a valid qubit state. A state with both $\alpha$ and $\beta$ nonzero is called a superposition. It does not mean the qubit holds both answers that you can read out at once. One measurement still gives a single answer. The phases of $\alpha$ and $\beta$ do not change the odds of a single measurement in the 0 and 1 basis, but they decide how qubits interfere when they are combined or rotated. ## An everyday picture Think of one hour split between two tasks. Each task gets a share of the hour, and the shares must add up to exactly one hour. A qubit works like that split for the odds of each outcome. The share for 0 is $|\alpha|^2$, the share for 1 is $|\beta|^2$, and together they make a whole. The analogy leaves out phase, the turn carried by each amplitude, which matters when qubits interact. ## Worked example: Measurement odds for an unequal qubit A qubit is prepared in the state $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$, with $\alpha = \frac{1}{\sqrt{3}}$ and $\beta = i\sqrt{\frac{2}{3}}$, where $i$ is the imaginary unit with $i^2 = -1$. Check that the state is valid, then find the chance of measuring 0 and the chance of measuring 1. 1. Probability of 0: $|\alpha|^2 = \left(\frac{1}{\sqrt{3}}\right)^2 = \frac{1}{3} \approx 0.333$. 2. Probability of 1: $|\beta|^2 = \left|i\sqrt{\frac{2}{3}}\right|^2 = \frac{2}{3} \approx 0.667$. The factor $i$ has size 1, so it does not change the size of $\beta$. 3. Check the total: $\frac{1}{3} + \frac{2}{3} = 1$, so the state is normalized and valid. **Answer:** The state is valid. There is a **33.3 percent** chance of measuring 0 and a **66.7 percent** chance of measuring 1. The factor $i$ in $\beta$ does not change either number. ## Common mistakes - Thinking a qubit is 0 and 1 at the same time, with both answers showing up in one measurement. A single measurement gives one result, 0 or 1, chosen with the probabilities above. - Treating $\alpha$ as a probability. With $\alpha = 0.6$, the chance of measuring 0 is $0.6^2 = 0.36$, not 0.6. - Forgetting the normalization rule. If $|\alpha|^2 + |\beta|^2$ is not 1, the state is not valid and the odds will not add up to 100 percent. - Assuming the phase of $\beta$ changes the measured odds. For a measurement in the 0 and 1 basis, only the sizes of the amplitudes matter. Phases show up when qubits are rotated or combined. ## Where you will meet it - Quantum computers, where each qubit is held in a state like this and quantum gates change the amplitudes $\alpha$ and $\beta$. - Quantum key distribution, such as the BB84 protocol, which can encode bits in the polarization of single photons. - Electron spin qubits in semiconductor devices, which encode 0 and 1 in the spin of a single electron. - Photon polarization experiments in optics, where horizontal and vertical polarization can serve as the two basis states. ## Questions people ask ### Can I read out α and β directly? Not from one qubit. A single measurement gives 0 or 1, and measuring disturbs the state. To estimate $|\alpha|^2$, prepare many identical qubits and count how often you get 0. ### Why are the amplitudes complex numbers? The phase of each amplitude matters when states are combined or rotated, and complex numbers store both size and phase. The Bloch sphere page shows how that phase is drawn. ### Is a qubit the same as a random bit? No. A random bit is either 0 or 1 with a known chance. A qubit's amplitudes carry phase, which changes how quantum operations combine them, so the state is more than a coin flip. ## Related formulas - [Bloch Sphere](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere/) - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [Wave Function Normalization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization/) ## Sources - [Qubit, Wikipedia](https://en.wikipedia.org/wiki/Qubit) - [Bra-ket notation, Wikipedia](https://en.wikipedia.org/wiki/Bra%E2%80%93ket_notation) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bloch Sphere > The Bloch sphere is a ball whose points are all the possible single-qubit states, with the top and bottom poles as 0 and 1. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ |\psi\rangle = \cos\frac{\theta}{2}|0\rangle + e^{i\varphi}\sin\frac{\theta}{2}|1\rangle, \qquad P(0) = \cos^2\frac{\theta}{2} $$ Read it out loud: "Ket psi equals cosine of theta over 2, times ket 0, plus e to the i phi times sine of theta over 2, times ket 1. The chance of measuring 0 is cosine squared of theta over 2. Theta is the angle from the top pole, and phi is the angle around the vertical axis." ## What each symbol means - $|\psi\rangle$: The qubit state. On the Bloch sphere, each point stands for one state, up to an overall phase that has no physical effect. - $\theta$: The polar angle, measured from the top pole $|0\rangle$ down to the bottom pole $|1\rangle$. It runs from 0 to $\pi$ radians, which is 0 to 180 degrees. - $\varphi$: The azimuthal angle, the angle around the vertical axis. It sets the relative phase between $|0\rangle$ and $|1\rangle$, and runs from 0 to $2\pi$ radians. - $|0\rangle$: The basis state at the top pole, where $\theta = 0$. - $|1\rangle$: The basis state at the bottom pole, where $\theta = \pi$. - $\cos\frac{\theta}{2}$: The amplitude of $|0\rangle$. Its squared size is the probability of measuring 0. - $e^{i\varphi}$: A phase factor with size 1. It turns the phase of the $|1\rangle$ amplitude by the angle $\varphi$ without changing its size. - $\sin\frac{\theta}{2}$: The size of the amplitude of $|1\rangle$. Its squared size is the probability of measuring 1. - $P(0)$: The probability of measuring 0. It equals $\cos^2\frac{\theta}{2}$. ## What the formula is doing Every single-qubit state can be drawn as a point on a sphere of radius 1, called the Bloch sphere. It is named after the physicist Felix Bloch. Two angles locate the point. The angle $\theta$ measures how far the point is from the top pole, and $\varphi$ measures how far it has turned around the vertical axis. An overall phase on the whole state has no physical effect, so the picture leaves it out. The poles are the basis states. At $\theta = 0$ the formula gives $|0\rangle$, and at $\theta = \pi$ it gives $|1\rangle$. Points on the equator, where $\theta = \frac{\pi}{2}$, are equal mixes of 0 and 1, each with probability one half. Their angle $\varphi$ tells you where around the equator they sit. The probabilities come from the half angle $\frac{\theta}{2}$. The chance of measuring 0 is $P(0) = \cos^2\frac{\theta}{2}$, and the chance of measuring 1 is $\sin^2\frac{\theta}{2}$. The two add to 1. The height of the point is $z = \cos\theta$, and this equals $P(0) - P(1)$, so the height shows the difference between the two odds. The angle $\varphi$ does not change $P(0)$ or $P(1)$, because $|e^{i\varphi}|^2 = 1$. It does change the state, and it shows up in measurements along other axes, such as the horizontal axis of the sphere. Quantum gates act as rotations of this sphere. A gate that swaps 0 and 1 is a half turn that moves the top pole to the bottom. That is why the sphere is a useful picture for single-qubit operations. ## An everyday picture Think of a globe. A point on the globe is located by its angle from the North Pole and its longitude around the axis. The North Pole is $|0\rangle$ and the South Pole is $|1\rangle$. Points near the top are mostly 0, points near the bottom are mostly 1, and points on the equator are an even mix. The angle from the pole plays the role of $\theta$, and longitude plays the role of $\varphi$. ## Worked example: A qubit at 60 degrees A qubit has $\theta = 60^\circ$ and $\varphi = 90^\circ$. Find the probability of measuring 0 and the probability of measuring 1. Start with the half angle, $\frac{\theta}{2} = 30^\circ$. 1. Half angle: $\frac{\theta}{2} = \frac{60^\circ}{2} = 30^\circ$. 2. Amplitude of $|0\rangle$: $\cos 30^\circ = \frac{\sqrt{3}}{2} \approx 0.866$. 3. Probability of 0: $P(0) = \cos^2 30^\circ = \frac{3}{4} = 0.75$. 4. Probability of 1: $\sin^2 30^\circ = \frac{1}{4} = 0.25$, which also equals $1 - 0.75$. 5. The angle $\varphi = 90^\circ$ gives $e^{i\varphi} = i$. This factor has size 1, so it does not change either probability. **Answer:** The chance of measuring 0 is **75 percent**, and the chance of measuring 1 is **25 percent**. The point sits closer to the top pole. Its height is $z = \cos 60^\circ = 0.5$, which equals $0.75 - 0.25$. ## Common mistakes - Using $\cos^2\theta$ instead of $\cos^2\frac{\theta}{2}$. The probability uses the half angle. With $\theta = 60^\circ$ the wrong formula gives 0.25 instead of 0.75. - Feeding degrees into a function that expects radians. Python's math.cos expects radians, so convert with math.radians first. Passing 30 directly gives the cosine of 30 radians, about 0.154, not 0.866. - Thinking $\varphi$ changes the measured odds of 0 and 1. For measurements along the vertical axis it does not, because $|e^{i\varphi}| = 1$. It matters for measurements along other axes. - Treating the sphere as ordinary three-dimensional space. Its points are quantum states, not locations in a room. ## Where you will meet it - Quantum computing, where each single-qubit gate is a rotation of the Bloch sphere, which makes the effect of the gate easy to picture. - Describing noise in qubits: noise pulls the point inside the sphere, which records a loss of quantum coherence. - Nuclear magnetic resonance, where the same picture describes how nuclear spins rotate under radio-frequency pulses. - Designing control pulses that rotate a qubit from $|0\rangle$ to $|1\rangle$ in superconducting circuits and trapped-ion hardware. ## Questions people ask ### Why is the sphere's radius 1? Because valid amplitudes satisfy $|\alpha|^2 + |\beta|^2 = 1$. Every valid qubit state fits on a sphere of radius 1, and every point on that sphere is a valid state. ### Is the Bloch sphere a real sphere in space? No. It is an abstract picture of the state space of one qubit. A point on it is a quantum state, not a place in the room, although the picture is drawn in three dimensions. ### Why does the overall phase not matter? An overall phase multiplies both amplitudes by the same factor. The probabilities depend only on squared sizes, so every measurement result stays the same. Only the relative phase between $|0\rangle$ and $|1\rangle$ is physical. ## Related formulas - [Qubit State](https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state/) - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [Wave Function Normalization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/wave-function-normalization/) ## Sources - [Bloch sphere, Wikipedia](https://en.wikipedia.org/wiki/Bloch_sphere) - [Qubit, Wikipedia](https://en.wikipedia.org/wiki/Qubit) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Stationary State Time Evolution > A stationary state has one fixed energy, and its chances of finding the particle stay the same even though its phase keeps turning. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/stationary-state-time-evolution/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \Psi(x, t) = \psi(x)\, e^{-i E t/\hbar}, \qquad |\Psi(x, t)|^2 = |\psi(x)|^2 $$ Read it out loud: "Psi of x and t equals psi of x, times e to the power of minus i times E times t over h-bar. The probability density, the squared size of psi of x and t, equals the squared size of psi of x, so it does not change with time. Psi is the full wave function, psi is its position part, E is the energy and t is time." ## What each symbol means - $\Psi(x, t)$: The full wave function, which depends on both position $x$ and time $t$. In one dimension its units are $\text{m}^{-1/2}$. - $\psi(x)$: The position part of the wave function. It does not depend on time and solves $\hat{H}\psi = E\psi$. - $e^{-i E t/\hbar}$: The time-dependent phase factor. It has size 1 at every time, so it only turns the phase of the wave. - $E$: The fixed energy of the stationary state, in joules (J). It is the same at every time. - $t$: Time, in seconds (s). - $\hbar$: The reduced Planck constant, $1.054571817 \times 10^{-34}$ J s. It makes $E t / \hbar$ a pure number. - $|\Psi(x, t)|^2$: The probability density at position $x$ and time $t$. For a stationary state it equals $|\psi(x)|^2$ at every time. ## What the formula is doing A stationary state is a solution of the Schrödinger equation with one definite energy $E$. Its wave function splits into a position part, $\psi(x)$, and a time part, the phase factor $e^{-iEt/\hbar}$. The position part solves the time-independent equation $\hat{H}\psi = E\psi$, which fixes the energy. To check this, put $\Psi = \psi\, e^{-iEt/\hbar}$ into the time-dependent Schrödinger equation $i\hbar\,\partial\Psi/\partial t = \hat{H}\Psi$. The time derivative brings down the factor $-iE/\hbar$, and multiplying by $i\hbar$ turns that into $E$. Both sides then equal $E\psi$ times the phase factor, so the equation holds whenever $\psi$ solves $\hat{H}\psi = E\psi$. The density is $|\Psi|^2 = |\psi|^2\, |e^{-iEt/\hbar}|^2 = |\psi|^2$. A phase factor of the form $e^{i(\text{real angle})}$ always has size 1, so the time part drops out of the density. The chance of finding the particle at each place stays the same at every time. The phase still turns. At a fixed spot, the complex value of $\Psi$ keeps rotating even though its size does not change. Any quantity built only from $|\Psi|^2$, such as the average position, is also fixed in time for a stationary state. Motion needs a mix of states. If the state is a superposition of two stationary states with different energies $E_1$ and $E_2$, their relative phase $e^{-i(E_2 - E_1)t/\hbar}$ changes with time. That makes the density move, as in a wave packet. Real excited atoms also decay by emitting light, which this model leaves out. ## An everyday picture Think of a clock hand of fixed length turning around the face. Its tip moves around a circle, so the direction keeps changing, but the length of the hand never changes. The turning is the phase factor. The length is the size of the wave, and its square, the probability density, stays put. ## Worked example: A box electron at two times The electron in the lowest state of a 1.0 nm box has energy $E = 6.02 \times 10^{-20}$ J (0.376 eV). Its position part is $\psi(x) = \sqrt{2/L}\,\sin(\pi x / L)$ with $L = 1.0$ nm. Compare the probability density at $x = L/4$ at time $t = 0$ and at time $t = 1.0$ fs ($1.0 \times 10^{-15}$ s). 1. Phase angle after 1.0 fs: $\frac{E t}{\hbar} = \frac{(6.02 \times 10^{-20}\ \text{J})(1.0 \times 10^{-15}\ \text{s})}{1.054571817 \times 10^{-34}\ \text{J s}} \approx 0.571$ rad, about 33 degrees. 2. Position part at $x = L/4$: $\psi = \sqrt{\frac{2}{L}}\sin\frac{\pi}{4} \approx 3.16 \times 10^{4}\ \text{m}^{-1/2}$, so $|\psi|^2 = 1.00 \times 10^{9}\ \text{m}^{-1}$. 3. At $t = 0$ the phase factor is 1, so $|\Psi|^2 = |\psi|^2 = 1.00 \times 10^{9}\ \text{m}^{-1}$. 4. At $t = 1.0$ fs, $\Psi = \psi\, e^{-0.571 i}$, so $|\Psi|^2 = \psi^2\left(\cos^2 0.571 + \sin^2 0.571\right) = \psi^2 = 1.00 \times 10^{9}\ \text{m}^{-1}$. **Answer:** The density at $x = L/4$ is the same at both times, **$1.00 \times 10^{9}\ \text{m}^{-1}$**. The phase of $\Psi$ has turned by 0.571 rad, but the probability density has not changed. ## Common mistakes - Thinking the wave function stops changing. For a stationary state only the probability density is fixed. The complex wave function keeps turning in phase. - Using $e^{+iEt/\hbar}$ instead of $e^{-iEt/\hbar}$. With the standard form of the Schrödinger equation, the minus sign is required. The plus sign does not solve that equation. - Assuming every state has a fixed density. The result holds for one stationary state. A superposition of two states with different energies has a density that changes in time. - Mixing units in the phase. $E$ must be in joules and $\hbar$ in J s. Putting $E$ in electron volts makes the phase about $6 \times 10^{18}$ times too large. ## Where you will meet it - Atomic and molecular physics, where, in the simplest model, the ground-state orbitals of an atom are stationary states with fixed probability clouds. - Spectroscopy, where the energy difference $\Delta E$ between two stationary states sets the frequency of the light, $\Delta E = hf$, that an atom emits or absorbs. - Wave packets in simulations, which are built from superpositions of stationary states, so their motion comes from the changing relative phases. - Quantum chemistry programs, which compute stationary states of molecules to predict their energy levels and orbital shapes. ## Questions people ask ### If the density never changes, is the state frozen? No. The phase keeps turning, so the state is evolving the whole time. What stays fixed is the probability of finding the particle at each place, and the energy. ### When does the density change? When the state is a superposition of stationary states with different energies. The relative phase between the pieces changes with time, and the density moves with it, as in a wave packet. ### Are stationary states realistic? They are exact solutions of the model, but real atoms and molecules interact with light and with each other. An excited state in a real atom eventually decays, which this model does not include. ## Related formulas - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) - [Particle in a Box](https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box/) - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) ## Sources - [Schrödinger equation, Wikipedia](https://en.wikipedia.org/wiki/Schr%C3%B6dinger_equation) - [Stationary state, Wikipedia](https://en.wikipedia.org/wiki/Stationary_state) - [Wave packet, Wikipedia](https://en.wikipedia.org/wiki/Wave_packet) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Energy-Time Uncertainty Relation > A state that lasts only a short time cannot have one sharp energy, so the light it gives off has a blurred color. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/energy-time-uncertainty/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \Delta E \, \Delta t \gtrsim \frac{\hbar}{2} $$ Read it out loud: "Delta E times delta t is greater than or about equal to h-bar divided by two. Delta E is the spread in energy, delta t is the time scale of the change, and h-bar is the reduced Planck constant." ## What each symbol means - $\Delta E$: The spread in energy of the state, in joules (J) or electron volts (eV). - $\Delta t$: A time scale, in seconds (s). Read it as a lifetime, or as the time the state needs to change noticeably. - $\gtrsim$: "Greater than or about equal to": the product can be a little smaller in rough estimates, but the number on the right sets the scale. - $\hbar$: The reduced Planck constant, $h / 2\pi = 1.054571817 \times 10^{-34}$ J s (joule seconds). ## What the formula is doing The relation links two spreads. $\Delta E$ is how far the energy of a state can spread, and $\Delta t$ is a time scale for that state. The product of the two cannot be much smaller than $\hbar/2$. A short time forces a wide spread in energy, and a long time allows a narrow one. This relation is different from the position and momentum version. In standard quantum mechanics time is a parameter that runs the Schrödinger equation, not a measurable quantity with its own operator. So $\Delta t$ is read as a lifetime or as the time a state takes to change noticeably. Consider an excited atom. It stays in its excited state for a short time, then emits light and falls to a lower state. Because the state does not last forever, its energy is not one sharp number. The emitted light covers a small band of frequencies, and that band is the line width in a spectrum. The bound is a minimum. Real spectral lines are often wider, because collisions between atoms and the motion of the atoms (the Doppler effect) also broaden them. The lifetime sets the narrowest possible line, called the natural line width. Energy and frequency are linked by $\Delta E = h\,\Delta\nu$, so a short lifetime also means a wide spread in frequency. Using $\Delta t = \tau$ for a lifetime $\tau$, the smallest frequency spread is $\Delta\nu \gtrsim \frac{1}{4\pi\tau}$. ## An everyday picture Think of a bell that is struck and then quickly silenced. A short thud has no clear pitch, because a clear pitch needs the sound to last long enough to repeat. A bell that rings for a long time has a sharp pitch. The shorter the sound lasts, the wider the range of pitches it contains. ## Worked example: The line width of a short-lived excited atom An excited atomic state has a lifetime of $\tau = 1.0 \times 10^{-8}$ s. This is an assumed round number for the example, not a measured value. Use $\hbar = 1.054571817 \times 10^{-34}$ J s, $h = 6.62607015 \times 10^{-34}$ J s and $e = 1.602176634 \times 10^{-19}$ C. 1. Smallest energy spread: $\Delta E \gtrsim \frac{\hbar}{2\,\tau} = \frac{1.054571817 \times 10^{-34}\ \text{J s}}{2 \times 1.0 \times 10^{-8}\ \text{s}} \approx 5.27 \times 10^{-27}$ J. 2. Convert to electron volts: $\frac{5.27 \times 10^{-27}\ \text{J}}{1.602176634 \times 10^{-19}\ \text{J/eV}} \approx 3.29 \times 10^{-8}$ eV. 3. Frequency spread: $\Delta \nu = \frac{\Delta E}{h} = \frac{5.27 \times 10^{-27}\ \text{J}}{6.62607015 \times 10^{-34}\ \text{J s}} \approx 7.96 \times 10^{6}$ Hz, about 8 MHz. 4. Compare with the light itself. Light at 500 nm has a frequency of $c / \lambda = 299792458 / 5.00 \times 10^{-7} \approx 6.0 \times 10^{14}$ Hz, so the spread is a fraction $7.96 \times 10^{6} / 6.0 \times 10^{14} \approx 1.3 \times 10^{-8}$ of the light's frequency. **Answer:** The light from this state covers a frequency range of at least about 8 MHz. That is about 1.3 parts in 100 million of the light's own frequency, so the line is very narrow but not infinitely sharp. A shorter lifetime would give a wider line. ## Common mistakes - Looking for a time operator with its own spread, as position and momentum have. Time is a parameter in standard quantum mechanics, so the relation is read as a lifetime or a time scale. - Treating the bound as the width of every spectral line. Collisions and Doppler motion usually add width on top of the natural line width. - Mixing up joules and electron volts. Convert with $1\ \text{eV} = 1.602176634 \times 10^{-19}$ J before you compare energies. - Dropping the 2 in $\hbar/2$ or the $2\pi$ in $h$. Either change shifts the answer by a factor of two or more. ## Where you will meet it - Spectroscopy, where the natural width of a spectral line is set by the lifetime of the excited state. - Nuclear and particle physics, where a short-lived particle has a spread in mass set by its lifetime. - Atomic clocks, where long-lived states give very sharp energies and frequencies. - Quantum mechanics textbooks, in problems about decaying or unstable states. ## Questions people ask ### Why is time treated differently from position? In standard quantum mechanics, position is an operator with a spread of values. Time is a parameter that controls how a state changes. That is why the energy-time relation is read as a lifetime or a time scale. ### Does this mean an instrument cannot measure the energy of a short-lived state? A short-lived state has a broad energy, and that breadth is a property of the state itself. Better equipment cannot make the energy sharper than the lifetime allows. ### What is a spectral line width? The width of a spectral line is the range of frequencies (or energies) in the light an atom emits or absorbs. A short lifetime gives a wide line, and a long lifetime gives a narrow one. ## Related formulas - [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/) - [Stationary State Time Evolution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stationary-state-time-evolution/) - [Radioactive Decay Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/radioactive-decay-law/) ## Sources - [Uncertainty principle, Wikipedia](https://en.wikipedia.org/wiki/Uncertainty_principle) - [Spectral line, Wikipedia](https://en.wikipedia.org/wiki/Spectral_line) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Canonical Commutation Relation > In quantum mechanics the order of measuring position and momentum changes the result, and that mismatch is the root of the uncertainty trade-off. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/canonical-commutation-relation/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ [\hat{x}, \hat{p}] = \hat{x}\hat{p} - \hat{p}\hat{x} = i\hbar $$ Read it out loud: "The commutator of x-hat and p-hat, which is x-hat times p-hat minus p-hat times x-hat, equals i times h-bar. Position and momentum do not commute, and the difference is i times h-bar." ## What each symbol means - $\hat{x}$: The position operator. An operator is a rule that acts on a wave function. Position is measured in meters (m). - $\hat{p}$: The momentum operator, which acts as $-i\hbar\, d/dx$ on a wave function. Momentum is measured in kilogram meters per second (kg m/s). - $[\hat{x}, \hat{p}]$: The commutator: the result of applying $\hat{x}\hat{p}$ minus the result of applying $\hat{p}\hat{x}$. It measures how much the order of the two operations matters. - $i$: The imaginary unit, with $i^2 = -1$. It is part of the result, so the commutator is a complex number. - $\hbar$: The reduced Planck constant, $h / 2\pi = 1.054571817 \times 10^{-34}$ J s (joule seconds). ## What the formula is doing In quantum mechanics position and momentum are operators, not plain numbers. An operator is a rule that takes a wave function and returns a new one. The commutator tells you whether the order of two operators matters. For position and momentum the answer is $i\hbar$, which is not zero, so the order matters. You can check this with a wave function $\psi(x)$. Applying $\hat{p}$ and then $\hat{x}$ gives a different result from applying them in the other order. The difference is $[\hat{x}, \hat{p}]\psi = i\hbar\,\psi$ for any wave function. The product rule for derivatives produces the extra $\psi$ term that makes the result nonzero. The commutator is the reason position and momentum cannot both be sharp. A general result, called the Robertson inequality, says that the spreads satisfy $\sigma_x \sigma_p \ge \frac{1}{2}\left|\langle [\hat{x}, \hat{p}] \rangle\right| = \frac{\hbar}{2}$. This is the Heisenberg uncertainty principle written in its general form. The number $i\hbar$ is fixed by nature. If $\hbar$ were zero, the two operators would commute, and there would be no trade-off. Its tiny size is why the effect is invisible for everyday objects. ## An everyday picture Think of putting on socks and shoes. Putting on socks and then shoes gives a different result from putting on shoes and then socks. Two actions that do not commute depend on their order. A left shoe and a right shoe do commute, because the order does not change the outcome. Position and momentum are like socks and shoes, so their order changes the result. ## Worked example: A minimum spread for a particle localized to 2.0 $\times 10^{-10}$ m A particle has a position spread of $\sigma_x = 2.0 \times 10^{-10}$ m. Use $h = 6.62607015 \times 10^{-34}$ J s and $m_e = 9.1093837 \times 10^{-31}$ kg. Find the smallest momentum spread allowed by the commutator, and the matching speed spread for an electron. 1. Find $\hbar$ from $h$: $\hbar = \frac{h}{2\pi} = \frac{6.62607015 \times 10^{-34}}{2\pi} \approx 1.054571817 \times 10^{-34}$ J s. 2. Use the Robertson bound $\sigma_x \sigma_p \ge \frac{\hbar}{2}$, so $\sigma_p \ge \frac{\hbar}{2\,\sigma_x} = \frac{1.054571817 \times 10^{-34}\ \text{J s}}{2 \times 2.0 \times 10^{-10}\ \text{m}} \approx 2.64 \times 10^{-25}$ kg m/s. 3. Divide by the electron mass to get the speed spread: $\sigma_v = \frac{\sigma_p}{m_e} = \frac{2.64 \times 10^{-25}}{9.1093837 \times 10^{-31}} \approx 2.89 \times 10^{5}$ m/s. **Answer:** The momentum spread must be at least about $2.64 \times 10^{-25}$ kg m/s, which means the electron's speed spread is at least about $2.89 \times 10^{5}$ m/s. Squeezing the position spread in half would double the minimum momentum spread, because the bound is a product. ## Common mistakes - Treating position and momentum as ordinary numbers that can be multiplied in either order. Their order matters, and the commutator measures that. - Thinking the commutator is zero for position and momentum. It equals $i\hbar$, which is not zero. - Dropping the $i$. The result is the complex number $i\hbar$, not the real number $\hbar$. - Using $h$ where $\hbar$ belongs. The relation uses $\hbar = h / 2\pi$, which is about 6.3 times smaller than $h$. ## Where you will meet it - Deriving the Heisenberg uncertainty principle from the Robertson inequality. - Writing the momentum operator as $-i\hbar\, d/dx$ in the Schrödinger equation for a particle in one dimension. - Building the raising and lowering operators of the quantum harmonic oscillator from position and momentum. - Angular momentum, where the components of angular momentum obey a similar commutation rule. ## Questions people ask ### What is an operator? An operator is a rule that takes a wave function and returns a new one. For example, the momentum operator differentiates the wave function, and the position operator multiplies it by $x$. ### Why does an $i$ appear? The momentum operator contains $-i\hbar$ in front of a derivative. The imaginary unit $i$ carries over to the commutator, which is why the result is complex. ### Does this mean position can never be measured accurately? No. You can measure position as accurately as your instrument allows. The commutator sets the trade-off: a sharper position forces a wider momentum spread. ## Related formulas - [Heisenberg Uncertainty Principle](https://formulabro.yunusemrevurgun.com/quantum-mechanics/heisenberg-uncertainty-principle/) - [Schrödinger Equation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/schrodinger-equation/) - [Expectation Value](https://formulabro.yunusemrevurgun.com/quantum-mechanics/expectation-value/) - [Energy-Time Uncertainty Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/energy-time-uncertainty/) ## Sources - [Canonical commutation relation, Wikipedia](https://en.wikipedia.org/wiki/Canonical_commutation_relation) - [Uncertainty principle, Wikipedia](https://en.wikipedia.org/wiki/Uncertainty_principle) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Orbital Angular Momentum Quantization > An electron's orbital motion around a nucleus can only take certain fixed sizes and directions, like steps on a staircase. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/angular-momentum-quantization/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ |\mathbf{L}| = \sqrt{\ell(\ell + 1)}\,\hbar \qquad L_z = m_\ell\,\hbar \qquad m_\ell = -\ell, \ldots, \ell $$ Read it out loud: "The length of L equals the square root of l times l plus one, times h-bar. The z component of L equals m sub l times h-bar, where m sub l runs in whole steps from minus l up to plus l." ## What each symbol means - $|\mathbf{L}|$: The length (magnitude) of the orbital angular momentum, in joule seconds (J s). - $\ell$: The orbital quantum number: a whole number 0, 1, 2, 3 and so on. It sets the size of the angular momentum. It has no unit. - $L_z$: The component of the angular momentum along the chosen z axis, in joule seconds (J s). - $m_\ell$: The magnetic quantum number: a whole number from $-\ell$ to $+\ell$. It sets the z component. It has no unit. - $\hbar$: The reduced Planck constant, $h / 2\pi = 1.054571817 \times 10^{-34}$ J s (joule seconds). ## What the formula is doing The orbital angular momentum of an electron in an atom is quantized. Its size is fixed by the whole number $\ell$ through $|\mathbf{L}| = \sqrt{\ell(\ell+1)}\,\hbar$. The values of $\ell$ are 0, 1, 2 and so on. Spectroscopists label them s, p, d and f for $\ell = 0, 1, 2, 3$. Only one direction can be sharp at a time, by convention the z axis. Its value is $L_z = m_\ell \hbar$. The number $m_\ell$ is a whole number from $-\ell$ to $+\ell$, which gives $2\ell + 1$ allowed values. For $\ell = 1$ there are three: $-1$, $0$ and $+1$. The total length is never equal to the largest $L_z$. Because $\sqrt{\ell(\ell+1)}$ is always bigger than $\ell$, the vector is longer than its largest z component. For $\ell = 1$ the length is $\sqrt{2}\,\hbar \approx 1.41\,\hbar$, while the largest $L_z$ is $\hbar$. So the angular momentum can never point exactly along the z axis. These rules come from solving the Schrödinger equation for the hydrogen atom in spherical coordinates. The same rules hold for any electron in a spherically symmetric potential, which is why they describe orbitals in all atoms. ## An everyday picture Think of a staircase rather than a ramp. A ramp lets you stand at any height, but a staircase lets you stand only on its steps. Orbital angular momentum stands only on steps set by $\hbar$. The size of the step pattern comes from $\ell$, and the z component can only sit on one of a few marked positions along the axis. ## Worked example: A d electron with $\ell = 2$ A d electron has orbital quantum number $\ell = 2$. Use $\hbar = 1.054571817 \times 10^{-34}$ J s. Find the length of its angular momentum, the number of allowed z values, and the largest z value. 1. Length: $|\mathbf{L}| = \sqrt{2 \times 3}\,\hbar = \sqrt{6}\,\hbar \approx 2.449\,\hbar$. 2. In joule seconds: $2.449 \times 1.054571817 \times 10^{-34}\ \text{J s} \approx 2.58 \times 10^{-34}$ J s. 3. Allowed values: $m_\ell = -2, -1, 0, 1, 2$, which is $2 \times 2 + 1 = 5$ values. 4. Largest z component: $L_z = 2\hbar = 2 \times 1.054571817 \times 10^{-34}\ \text{J s} \approx 2.11 \times 10^{-34}$ J s. **Answer:** The d electron has angular momentum of length about $2.58 \times 10^{-34}$ J s. It has five allowed z values, from $-2\hbar$ to $+2\hbar$. The largest z value, $2.11 \times 10^{-34}$ J s, is smaller than the full length, so the vector cannot point exactly along z. ## Common mistakes - Taking the length as $\ell\hbar$. The correct value is $\sqrt{\ell(\ell+1)}\,\hbar$, which is larger. - Counting only positive values of $m_\ell$. There are $2\ell + 1$ values, including zero and both negative values. - Thinking the angular momentum can point exactly along the z axis. Only its z component has a sharp value, and the full vector is longer. - Confusing $\ell$ with $m_\ell$. The quantum number $\ell$ sets the size, and $m_\ell$ sets the z component. ## Where you will meet it - Atomic orbitals, labeled s, p, d and f for $\ell = 0$ to $3$. - Counting electron states in an atom, since each subshell with quantum number $\ell$ holds $2\ell + 1$ orbitals. - The Zeeman effect, where the energy shift in a magnetic field depends on $m_\ell$. - Selection rules for light emission from atoms, where $\ell$ changes by one in the usual dipole transitions. ## Questions people ask ### What is the difference between $\ell$ and $m_\ell$? The orbital quantum number $\ell$ sets the length of the angular momentum. The magnetic quantum number $m_\ell$ sets its z component, and it can take any whole-number value from $-\ell$ to $+\ell$. ### Does the electron physically spin around the nucleus? The picture of a little orbit is a helpful model, but the rule is about the allowed values. Orbital angular momentum is a quantum property with fixed sizes, and it does not match a classical orbit exactly. ### Why is the magnitude a square root? The length of the angular momentum comes from adding its components in the quantum way. The result is $\sqrt{\ell(\ell+1)}$ times $\hbar$, which is why the square root and the product $\ell(\ell+1)$ appear. ## Related formulas - [Spin One-Half](https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/) - [Zeeman Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect/) - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) - [Electron Shell Capacity](https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity/) ## Sources - [Angular momentum operator, Wikipedia](https://en.wikipedia.org/wiki/Angular_momentum_operator) - [Azimuthal quantum number, Wikipedia](https://en.wikipedia.org/wiki/Azimuthal_quantum_number) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Spin One-Half > An electron has a built-in angular momentum that can be measured along any direction as only one of two values, up or down. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ S_z = m_s\,\hbar, \qquad m_s = \pm\frac{1}{2}, \qquad |\mathbf{S}| = \frac{\sqrt{3}}{2}\,\hbar $$ Read it out loud: "S z equals m sub s times h-bar, where m sub s is plus or minus one half. The length of S equals the square root of three over two, times h-bar." ## What each symbol means - $S_z$: The component of the spin angular momentum along the chosen z axis, in joule seconds (J s). - $m_s$: The spin projection quantum number. For an electron it is $+\frac{1}{2}$ or $-\frac{1}{2}$. It has no unit. - $|\mathbf{S}|$: The length (magnitude) of the spin angular momentum, in joule seconds (J s). - $\hbar$: The reduced Planck constant, $h / 2\pi = 1.054571817 \times 10^{-34}$ J s (joule seconds). ## What the formula is doing Electrons carry an intrinsic angular momentum called spin. The spin quantum number is $s = \frac{1}{2}$ for an electron. The word spin is a label. It does not mean a tiny ball turning on its axis, and spin is a property the electron has even when it is at rest. Measured along any chosen axis, the z axis for example, spin gives only two values: $S_z = +\frac{\hbar}{2}$ or $S_z = -\frac{\hbar}{2}$. These are the two values of $m_s$ multiplied by $\hbar$. There is no value in between. The total length of the spin is $\sqrt{s(s+1)}\,\hbar = \frac{\sqrt{3}}{2}\,\hbar \approx 0.866\,\hbar$. This is larger than the largest z value $\frac{\hbar}{2} = 0.5\,\hbar$, so the spin can never point exactly along the chosen axis. In 1922 Otto Stern and Walther Gerlach sent a beam of silver atoms through a magnetic field that varied in strength. The beam split into two separate spots, not a smooth smear. The two spots were later understood as the two spin values of an electron. This was one of the first clear signs of spin. The Dirac equation, the relativistic wave equation for the electron, gives spin one-half naturally. Particles with half-integer spin, including electrons, protons and neutrons, are called fermions. ## An everyday picture Think of a light switch with exactly two positions, up and down. Measuring spin along an axis is like checking the switch: you always find one of the two positions, and nothing in between. The switch can be turned to point in any direction, but each check still gives up or down. ## Worked example: How far the spin is tilted from the z axis An electron has spin $s = \frac{1}{2}$, so its length is $|\mathbf{S}| = \frac{\sqrt{3}}{2}\hbar$. In the most extreme case its z component is $S_z = +\frac{\hbar}{2}$. Find the angle between the spin vector and the z axis, using the classical vector picture. 1. Use the cosine of the angle: $\cos\theta = \frac{S_z}{|\mathbf{S}|} = \frac{\hbar/2}{(\sqrt{3}/2)\hbar} = \frac{1}{\sqrt{3}} \approx 0.577$. 2. Take the inverse cosine: $\theta = \arccos(0.577) \approx 54.7^\circ$. 3. Check the ratio: the largest z value is $0.5\,\hbar$ and the length is $0.866\,\hbar$, so the z value is about 58% of the length, which matches $0.577$. **Answer:** In the vector picture the spin is tilted about $54.7^\circ$ from the z axis. This angle is a picture to help you think, not a measured direction. Only the z component has a sharp value, and the spin has no sharp direction. ## Common mistakes - Thinking spin is a literal spinning ball. The name is a label, and the spin is an intrinsic property with fixed values. - Using $m_s = 0$ or $1$ for an electron. For spin one-half the only values are $+\frac{1}{2}$ and $-\frac{1}{2}$. - Taking the length of the spin to be $\frac{\hbar}{2}$. The length is $\frac{\sqrt{3}}{2}\hbar$, and $\frac{\hbar}{2}$ is only the largest z value. - Assuming spin can be sharp along two axes at once. A sharp value along z means the spin along x is not sharp. ## Where you will meet it - Electron configurations, where the Pauli exclusion principle allows two electrons in each orbital, one for each spin value. - Magnetic resonance imaging (MRI) and nuclear magnetic resonance (NMR), which use the spin of hydrogen nuclei (protons), also spin one-half. - Quantum computing, where a qubit is often built from a spin one-half system and drawn on the Bloch sphere. - The Stern-Gerlach experiment and other spin measurements in quantum mechanics textbooks. ## Questions people ask ### Does spin mean the electron rotates? Not in the everyday sense. Spin is an angular momentum built into the electron, and its measured values are fixed. A rotating ball picture is misleading if taken literally. ### Why does an electron have spin one-half and not a whole number? The Dirac equation for the electron gives spin one-half. Particles with half-integer spin are called fermions, and they obey the Pauli exclusion principle. ### Why did the Stern-Gerlach beam split into two spots? A classical spinning magnet would give a continuous spread of directions. Two spots mean that only two values of the spin component along the field direction are possible. ## Related formulas - [Orbital Angular Momentum Quantization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/angular-momentum-quantization/) - [Zeeman Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect/) - [Bloch Sphere](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere/) - [Qubit State](https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state/) ## Sources - [Spin (physics), Wikipedia](https://en.wikipedia.org/wiki/Spin_%28physics%29) - [Stern-Gerlach experiment, Wikipedia](https://en.wikipedia.org/wiki/Stern%E2%80%93Gerlach_experiment) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Zeeman Effect > A magnetic field shifts an atom's energy levels by small equal steps, so one spectral line splits into several. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \Delta E = m_\ell\,\mu_B\,B $$ Read it out loud: "Delta E equals m sub l times mu sub B times B. The energy shift equals the magnetic quantum number times the Bohr magneton times the magnetic field." ## What each symbol means - $\Delta E$: The energy shift of the level caused by the magnetic field, in joules (J) or electron volts (eV). - $m_\ell$: The magnetic quantum number: a whole number from $-\ell$ to $+\ell$. It has no unit. - $\mu_B$: The Bohr magneton, a natural unit of magnetic moment for an electron, $\mu_B = 9.2740100783 \times 10^{-24}$ J/T (joules per tesla). - $B$: The magnetic field strength, in tesla (T). Earth's field at the surface is only tens of microtesla. ## What the formula is doing When an atom sits in a magnetic field $B$, its energy levels shift. The shift depends on how the orbital motion of the electron lines up with the field. Each allowed value of $m_\ell$ corresponds to one level, and the shift for that level is $\Delta E = m_\ell\,\mu_B\,B$. The Bohr magneton is $\mu_B = \frac{e\hbar}{2m_e}$, built from the electron charge $e$, the reduced Planck constant $\hbar$ and the electron mass $m_e$. Its value is $9.2740100783 \times 10^{-24}$ J/T. A stronger field gives a bigger step, and a bigger $|m_\ell|$ gives a bigger shift. Each level moves by the same step, $\mu_B B$. For $\ell = 1$ there are three levels, shifted by $-\mu_B B$, $0$ and $+\mu_B B$. A single spectral line in zero field therefore splits into three lines in a field. This pattern is called the normal Zeeman effect. It was named after Pieter Zeeman, who observed the splitting of spectral lines in 1896. Real atoms also have electron spin, which adds its own magnetic effect. That gives a more complicated pattern, called the anomalous Zeeman effect. The formula on this page covers the normal case, where spin is ignored. ## An everyday picture Think of a set of stairs inside the atom, where each step is the same height. The magnetic field sets the height of one step, and $m_\ell$ says how many steps up or down a level sits. Stronger fields make the steps taller, so the levels spread further apart. ## Worked example: The energy step in a 1 tesla field A magnetic field of $B = 1$ T acts on an atom. Use $\mu_B = 9.2740100783 \times 10^{-24}$ J/T and $e = 1.602176634 \times 10^{-19}$ C. Find the energy step for $m_\ell = +1$ in eV, and the matching frequency step. 1. Energy shift in joules: $\Delta E = m_\ell\,\mu_B\,B = 1 \times 9.2740100783 \times 10^{-24}\ \text{J/T} \times 1\ \text{T} = 9.27 \times 10^{-24}$ J. 2. Convert to electron volts: $\frac{9.2740100783 \times 10^{-24}\ \text{J}}{1.602176634 \times 10^{-19}\ \text{J/eV}} \approx 5.79 \times 10^{-5}$ eV. 3. Frequency step: $\frac{\Delta E}{h} = \frac{9.27 \times 10^{-24}\ \text{J}}{6.62607015 \times 10^{-34}\ \text{J s}} \approx 1.40 \times 10^{10}$ Hz, about 14 GHz. **Answer:** In a 1 T field each step is about $5.79 \times 10^{-5}$ eV. That is very small compared with the energies of atomic transitions, which are a few electron volts, so the splitting needs a sensitive spectrometer to see. The frequency step is about 14 GHz. ## Common mistakes - Using gauss or millitesla without converting. One tesla equals 10,000 gauss, so a field given in gauss must be divided by 10,000 first. - Mixing joules and electron volts in the same sum. Convert both to one unit before you compare them. - Reading a negative $m_\ell$ as an error. A negative value means the level shifts down, which is a normal result. - Using the normal formula for a real atom with spin. Spin changes the pattern, and that case is the anomalous Zeeman effect. ## Where you will meet it - Laboratory spectroscopy, where splitting measured in a known field shows how the levels move. - Astronomy, where splitting of spectral lines in the Sun reveals magnetic fields in sunspots. - Electron spin resonance, a close relative, where the same Bohr magneton sets the energy steps of electron spins. - Quantum mechanics textbooks, in problems about atoms in magnetic fields. ## Questions people ask ### What is a Bohr magneton? It is a natural unit of magnetic moment for an electron, $\mu_B = \frac{e\hbar}{2m_e}$. It sets the size of the energy steps in the Zeeman effect. ### Are the levels split when there is no magnetic field? In this simple picture, no. Levels with different $m_\ell$ have the same energy until a field is applied. The field is what separates them. ### Why is one tesla such a large field? Earth's magnetic field at the surface is only tens of microtesla. A field of one tesla is tens of thousands of times stronger, which is why it is used in laboratories to make the splitting clear. ## Related formulas - [Orbital Angular Momentum Quantization](https://formulabro.yunusemrevurgun.com/quantum-mechanics/angular-momentum-quantization/) - [Spin One-Half](https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/) - [Hydrogen Energy Levels](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-energy-levels/) - [Fine-Structure Constant](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fine-structure-constant/) ## Sources - [Zeeman effect, Wikipedia](https://en.wikipedia.org/wiki/Zeeman_effect) - [Bohr magneton, Wikipedia](https://en.wikipedia.org/wiki/Bohr_magneton) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Fine-Structure Constant > The fine-structure constant is a pure number that sets how strongly charged particles and light interact, and its value is close to 1 over 137. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fine-structure-constant/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \alpha = \frac{e^2}{4\pi\varepsilon_0\,\hbar c} \approx \frac{1}{137.036} $$ Read it out loud: "Alpha equals e squared divided by four pi times epsilon zero times h-bar times c. It is approximately one divided by one hundred thirty seven point zero three six." ## What each symbol means - $\alpha$: The fine-structure constant. It is a pure number with no units, about $1/137.036$. - $e$: The elementary charge, the charge of a proton, $1.602176634 \times 10^{-19}$ C (coulombs). It is exact by definition. - $\varepsilon_0$: The vacuum permittivity, $8.8541878128 \times 10^{-12}$ F/m (farads per meter). - $\hbar$: The reduced Planck constant, $1.054571817 \times 10^{-34}$ J s (joule seconds). - $c$: The speed of light in vacuum, $299792458$ m/s. It is exact by definition. - $\pi$: The number pi, about 3.14159. It has no unit. ## What the formula is doing The fine-structure constant $\alpha$ is a dimensionless number. Its value is about $0.0072974$, or $1/137.036$. Because it has no units, it gives the same number in any system of units, which is what makes it a fundamental constant. The formula combines the charge $e$, the vacuum permittivity $\varepsilon_0$, the constant $\hbar$ and the speed of light $c$. The combination $e^2/(4\pi\varepsilon_0)$ has units of energy times length, and $\hbar c$ has the same units. Dividing one by the other cancels every unit, so $\alpha$ is a pure number. The value is small. Small means that light and charged particles interact weakly, so the simple steps of atomic theory work well and each correction is a small nudge. Quantum electrodynamics, the theory of light and charge, uses $\alpha$ as the size of its correction steps. The constant sets the scale of many atomic effects. The ground-state energy of hydrogen is $\alpha^2 m_e c^2/2$, which is about 13.6 eV. The fine structure of spectral lines, which gave the constant its name, is also set by $\alpha$. Current theory does not predict the value of $\alpha$. It is measured in experiments, such as measurements of the electron's magnetic moment and of atomic recoil, and the measured value agrees with the formula above. ## An everyday picture Think of $\alpha$ as a dial that sets how strongly charged particles and light exchange energy. At about 1/137 the dial sits low, so each interaction is a small nudge. That is why atoms can be described as a set of small steps that add up to the observed spectrum. ## Worked example: Computing alpha from the constants, then the hydrogen energy Use $e = 1.602176634 \times 10^{-19}$ C, $\varepsilon_0 = 8.8541878128 \times 10^{-12}$ F/m, $\hbar = 1.054571817 \times 10^{-34}$ J s, $c = 299792458$ m/s and $m_e = 9.1093837 \times 10^{-31}$ kg. First find $\alpha$, then use it to find the hydrogen ground-state energy. 1. Numerator: $e^2 = (1.602176634 \times 10^{-19})^2 \approx 2.56697 \times 10^{-38}$ C$^2$. 2. Denominator: $4\pi\varepsilon_0\hbar c = 4\pi \times 8.8541878128 \times 10^{-12} \times 1.054571817 \times 10^{-34} \times 299792458 \approx 3.51767 \times 10^{-36}$ (units J m). 3. Divide: $\alpha = \frac{2.56697 \times 10^{-38}}{3.51767 \times 10^{-36}} \approx 0.00729735$, which means $1/\alpha \approx 137.036$. 4. Hydrogen ground-state energy: $\frac{\alpha^2 m_e c^2}{2}$, with $m_e c^2 = 8.18711 \times 10^{-14}$ J. This gives $\frac{(0.00729735)^2 \times 8.18711 \times 10^{-14}}{2} \approx 2.17987 \times 10^{-18}$ J, which is about 13.6 eV. **Answer:** The constant is $\alpha \approx 0.00729735$, or $1/137.036$, a pure number. Using it, the hydrogen ground-state binding energy is about 13.6 eV, the value expected for an electron held by a single proton. ## Common mistakes - Leaving out the $4\pi$ in the SI formula. Without it the number is $4\pi$ times too large. - Using $h$ where $\hbar$ belongs. Since $h = 2\pi\hbar$, that mistake makes $\alpha$ about $2\pi$ times too small. - Thinking $\alpha$ has a unit or depends on the unit system. It is dimensionless, so its value is the same in every system. - Confusing $\alpha$ with the fine-structure splitting itself. $\alpha$ is the constant, and the splitting is an effect that depends on it. ## Where you will meet it - The fine-structure splitting of hydrogen spectral lines. - Quantum electrodynamics, where $\alpha$ is the size of the expansion steps for corrections. - Precision tests of the electron's magnetic moment, which measure $\alpha$ with high accuracy. - Quick estimates of atomic sizes and energies, such as the Bohr radius, which is $a_0 = \hbar/(m_e c\,\alpha)$. ## Questions people ask ### Why is it called the fine-structure constant? It sets the size of the small splitting of spectral lines known as fine structure. That splitting was observed in hydrogen, and $\alpha$ controls how large it is. ### Is alpha really about 1 over 137? Yes. The measured value is $1/137.036$, or about $0.0072974$. The number 137 is a coincidence of the constants, not a rule in itself. ### Does alpha change over time? Experiments so far have found no change. The constant is measured, not defined, so its value rests on those measurements. ## Related formulas - [Bohr Radius](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bohr-radius/) - [Hydrogen-Like Atom Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/hydrogen-like-atom-energy/) - [Rydberg Formula](https://formulabro.yunusemrevurgun.com/quantum-mechanics/rydberg-formula/) - [Zeeman Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/zeeman-effect/) ## Sources - [Fine-structure constant, Wikipedia](https://en.wikipedia.org/wiki/Fine-structure_constant) - [Fundamental physical constants, NIST](https://physics.nist.gov/cuu/Constants/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Double-Slit Interference > Waves from two narrow openings overlap, and at certain places they add into bright bands while at others they cancel into dark ones. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/double-slit-interference/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ d \sin\theta = m\lambda $$ Read it out loud: "d times sine theta equals m times lambda. d is the distance between the slits, theta is the angle to a bright fringe, m is a whole number, and lambda is the wavelength." ## What each symbol means - $d$: The distance between the centers of the two slits, in meters (m). It is not the width of one slit. - $\theta$: The angle from the center line to the bright fringe, measured from the slits. Use radians or degrees, as long as the calculator matches. - $m$: The order of the bright fringe: a whole number 0, 1, 2 and so on, with sign for the side of the center. It is not a mass. - $\lambda$: The wavelength of the wave, in meters (m). - $\Delta y$: The distance between neighboring bright fringes on a screen, in meters (m), used for small angles. - $L$: The distance from the slits to the screen, in meters (m). ## What the formula is doing A wave passing through two narrow slits spreads out from each slit. The two spreading waves overlap on a screen. Where a crest meets a crest, the waves add and the spot is bright. Where a crest meets a trough, they cancel and the spot is dark. The bright spots are called fringes. The rule for a bright fringe is $d\sin\theta = m\lambda$. The number $d\sin\theta$ is the extra distance one wave travels compared with the other. When that extra distance equals a whole number of wavelengths, the two waves arrive in step and add. Dark fringes sit halfway between, where $d\sin\theta = (m + \tfrac{1}{2})\lambda$. For small angles, $\sin\theta \approx \tan\theta = y/L$, so the bright fringes are evenly spaced: $\Delta y = \frac{\lambda L}{d}$. A longer wavelength or a longer distance to the screen spreads the pattern out. Slits placed farther apart pack the pattern closer together. The same pattern appears when particles pass through the slits one at a time. Each particle lands at a single spot, but the spots build up over time into the fringe pattern. The wave function predicts the chance of landing at each place, and that chance follows the bright and dark bands. Thomas Young's interference experiments with light in the early 1800s helped show that light behaves as a wave. The same pattern for electrons and other particles is strong evidence that matter also has wave behavior. ## An everyday picture Think of two stones dropped into a still pond at the same time. Ripples spread out from each stone and overlap. In some spots the peaks meet and make a tall wave, and in others a peak meets a dip and the water stays flat. The double-slit pattern is the same overlap of ripples, drawn on a screen. ## Worked example: Fringe spacing for green light Green light of wavelength $\lambda = 500$ nm passes through two slits with $d = 0.50$ mm. The screen is $L = 1.0$ m away. Find the spacing between bright fringes on the screen, and the angle of the first bright fringe. 1. Convert the units: $\lambda = 500\ \text{nm} = 5.00 \times 10^{-7}$ m and $d = 0.50\ \text{mm} = 5.0 \times 10^{-4}$ m. 2. Fringe spacing: $\Delta y = \frac{\lambda L}{d} = \frac{5.00 \times 10^{-7}\ \text{m} \times 1.0\ \text{m}}{5.0 \times 10^{-4}\ \text{m}} = 1.0 \times 10^{-3}$ m, which is 1.0 mm. 3. First bright fringe ($m = 1$): $\sin\theta = \frac{\lambda}{d} = \frac{5.00 \times 10^{-7}}{5.0 \times 10^{-4}} = 1.0 \times 10^{-3}$, so $\theta \approx 1.0 \times 10^{-3}$ rad, about 0.057 degrees. **Answer:** On a screen 1 m away, the bright fringes are about 1.0 mm apart. The first bright fringe sits at an angle of about 0.057 degrees from the center. The small angle is why the even spacing formula works here. ## Common mistakes - Mixing units, such as using 500 for nanometers without converting to meters. Every length must be in meters before the formula is used. - Reading $d$ as the width of each slit. It is the distance between the slit centers. - Using $\Delta y = \lambda L / d$ for large angles. The formula needs the angle to be small. - Confusing bright and dark fringes. Bright fringes need a whole number of wavelengths, and dark fringes need a half-integer number. ## Where you will meet it - Interference demonstrations in physics teaching labs, following Young's experiment. - Diffraction gratings in spectrometers, which use the same bright-fringe rule with many slits. - Electron and neutron interferometry, which confirm the wave behavior of matter. - Optical measurements of very small distances, where the fringe spacing reveals a wavelength or a slit separation. ## Questions people ask ### If particles arrive one at a time, why does a pattern form? Each particle lands at one spot, and the chance of landing at each spot follows the wave pattern. Many single arrivals build up the bright and dark bands. ### Does the pattern come from particles hitting each other? No. The pattern still forms when particles pass through one at a time, so it is not caused by collisions between them. ### What happens if one slit is covered? The bands disappear, and the screen shows a single broad spread instead. The interference needs both paths to be open. ### Is $m$ the same as mass? No. In this formula $m$ is the order of the fringe, which is a whole number such as 0, 1 or 2. The mass of the particle does not appear in the formula. ## Related formulas - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [Bragg's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bragg-law/) ## Sources - [Double-slit experiment, Wikipedia](https://en.wikipedia.org/wiki/Double-slit_experiment) - [Thomas Young (scientist), Wikipedia](https://en.wikipedia.org/wiki/Thomas_Young_%28scientist%29) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bragg's Law > Waves bounce off the evenly spaced layers of a crystal, and they add into a strong reflection only at certain angles. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bragg-law/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ n\lambda = 2d\sin\theta $$ Read it out loud: "n times lambda equals two times d times sine theta. n is a whole number, lambda is the wavelength, d is the spacing between the crystal planes, and theta is the glancing angle." ## What each symbol means - $n$: The order of the reflection: a positive whole number 1, 2, 3 and so on. It is not the refractive index. - $\lambda$: The wavelength of the incoming wave, in meters (m). For X-rays it is often about $10^{-10}$ m. - $d$: The spacing between neighboring parallel planes of atoms in the crystal, in meters (m). - $\theta$: The glancing angle: the angle between the incoming beam and the planes, not the surface normal. Use degrees or radians, as long as the calculator matches. ## What the formula is doing A crystal is a regular arrangement of atoms that forms parallel planes. The planes are separated by a fixed distance $d$. When an X-ray, electron or neutron beam hits the crystal, each plane reflects a small part of the wave. Reflections from neighboring planes travel different distances. The extra path is $2d\sin\theta$. When that extra distance equals a whole number of wavelengths, $n\lambda$, the reflections add into a strong peak. At other angles they cancel, and no peak appears. Measuring the angles of the strong peaks gives the spacing $d$ when the wavelength is known, or the wavelength when the spacing is known. This is how X-ray crystallography works out the arrangement of atoms in crystals, including many minerals and proteins. The law is not limited to light. Any wave whose wavelength is close to the spacing between atoms will diffract from a crystal. In 1927 Clinton Davisson and Lester Germer scattered electrons from a nickel crystal and found peaks at the angles the law predicts. This confirmed the wave nature of electrons. Electrons have a de Broglie wavelength, so a beam of electrons with the right speed has a wavelength close to atomic spacings. That is why the same rule works for electrons and for X-rays. ## An everyday picture Think of a stack of evenly spaced shelves. A ball bounced off each shelf travels a little farther when it bounces off a lower shelf. When that extra distance matches a whole number of wavelengths, the bounces line up and a strong reflection comes back at that angle. At other angles they cancel out. ## Worked example: First-order peak from an X-ray on a crystal An X-ray beam with wavelength $\lambda = 0.150$ nm hits a crystal whose atomic planes are spaced $d = 0.250$ nm apart. Find the glancing angle of the first-order peak, $n = 1$, and the second-order peak, $n = 2$. 1. Solve for the sine: $\sin\theta = \frac{n\lambda}{2d}$. For $n = 1$: $\sin\theta = \frac{1 \times 0.150\ \text{nm}}{2 \times 0.250\ \text{nm}} = 0.300$. 2. Take the inverse sine: $\theta = \arcsin(0.300) \approx 17.5^\circ$. 3. Second order, $n = 2$: $\sin\theta = \frac{2 \times 0.150}{2 \times 0.250} = 0.600$, so $\theta = \arcsin(0.600) \approx 36.9^\circ$. **Answer:** The first-order peak appears at a glancing angle of about $17.5^\circ$, and the second-order peak at about $36.9^\circ$. If $n\lambda$ were larger than $2d$, the sine would be above 1 and no peak could appear at any angle. ## Common mistakes - Measuring the angle from the surface normal. The glancing angle is measured between the beam and the planes. - Forgetting the factor of 2 in $2d\sin\theta$. Without it the angle comes out far too small. - Entering degrees into a calculator set to radians, or the reverse. The sine of 17.5 radians is not the sine of 17.5 degrees. - Assuming a peak appears at every angle. Only angles that satisfy the rule give a strong reflection. ## Where you will meet it - X-ray crystallography, which identifies the arrangement of atoms in crystals, minerals and proteins. - Electron diffraction, which confirmed the wave nature of electrons in 1927 with the Davisson-Germer experiment. - Neutron diffraction, which locates light atoms such as hydrogen inside crystals. - Materials science, where diffraction peaks identify the crystal phase and check the quality of a sample. ## Questions people ask ### Why does the X-ray reflect from inside the crystal? The reflection comes from many planes at once. The waves from different planes add only at the angles that satisfy the rule, and they cancel at the others. ### What does $n$ mean? It is the order of the peak. The first peak has $n = 1$, the next has $n = 2$, and so on. It is a whole number, not the refractive index. ### Why does the rule also work for electrons? Electrons have a de Broglie wavelength. When they have the right speed, that wavelength is close to atomic spacings, so the electrons diffract like X-rays. ## Related formulas - [Double-Slit Interference](https://formulabro.yunusemrevurgun.com/quantum-mechanics/double-slit-interference/) - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) ## Sources - [Bragg's law, Wikipedia](https://en.wikipedia.org/wiki/Bragg%27s_law) - [Davisson-Germer experiment, Wikipedia](https://en.wikipedia.org/wiki/Davisson%E2%80%93Germer_experiment) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Thermal de Broglie Wavelength > When a gas gets cold enough, each atom's wave grows so long that neighboring atoms overlap, and quantum rules take over. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/thermal-de-broglie-wavelength/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ \lambda_{\text{th}} = \frac{h}{\sqrt{2\pi m k_B T}} $$ Read it out loud: "Lambda th equals h divided by the square root of 2 pi times m times k B times T. Lambda th is the thermal wavelength, h is Planck's constant, m is the mass of one particle, k B is the Boltzmann constant and T is the absolute temperature." ## What each symbol means - $\lambda_{\text{th}}$: The thermal de Broglie wavelength, in meters (m). It is a typical size of the quantum wave of a particle in a gas at temperature $T$. - $h$: Planck's constant, $6.62607015 \times 10^{-34}$ J s (joule seconds). - $m$: The mass of one particle, in kilograms (kg). - $k_B$: The Boltzmann constant, $1.380649 \times 10^{-23}$ J/K (joules per kelvin). It converts temperature into energy. - $T$: The absolute temperature, in kelvin (K). Zero kelvin is absolute zero. ## What the formula is doing Every atom in a gas has a de Broglie wavelength, the length of its matter wave. Cool the gas and the atoms slow down, so their waves grow longer. The thermal de Broglie wavelength $\lambda_{\text{th}}$ gives a typical value of that wavelength for particles at temperature $T$. The formula has $h$ on top and a square root on the bottom. The bottom holds the mass $m$ and the temperature $T$, multiplied by $k_B$ and $2\pi$. A heavier particle or a higher temperature makes the bottom larger, so the wavelength gets shorter. A light particle at low temperature has the longest wave. Quantum effects matter when this wavelength is comparable to the spacing between particles. If a gas has $n$ particles per cubic meter, a typical spacing is $n^{-1/3}$. When $\lambda_{\text{th}}$ is much smaller than that spacing, the particles act like separate small balls, and classical statistics works well. When $\lambda_{\text{th}}$ becomes comparable to the spacing, the waves overlap and the particles must be treated as quantum objects. This overlap regime is where Bose-Einstein condensates form. For bosons, cooling and crowding the gas until the waves overlap leads many atoms to occupy the same lowest quantum state. Cold-atom experiments use this comparison to decide how cold a gas must be before quantum behavior shows up. ## An everyday picture Think of people standing in a wide stadium and then in a packed elevator. When people are far apart, each one can move freely without bumping into anyone. When they are packed close together, the space each person needs overlaps with everyone else's space. The thermal wavelength measures how much room each atom's wave needs, and the overlap starts when that room becomes as large as the gaps between atoms. ## Worked example: Rubidium-87 atoms at 100 nK A rubidium-87 atom has mass $m = 1.443 \times 10^{-25}$ kg. Cool the gas to $T = 100$ nK, which is $100 \times 10^{-9}$ K. Use $k_B = 1.380649 \times 10^{-23}$ J/K and $h = 6.62607015 \times 10^{-34}$ J s. For comparison, take a density of $n = 10^{20}$ atoms per cubic meter, a value chosen for this example. 1. Temperature in kelvin: $T = 100 \times 10^{-9}$ K $= 1.00 \times 10^{-7}$ K. 2. Product under the square root: $2\pi m k_B T = 2\pi (1.443 \times 10^{-25})(1.380649 \times 10^{-23})(1.00 \times 10^{-7}) \approx 1.25 \times 10^{-54}$ kg J. Its square root is about $1.12 \times 10^{-27}$. 3. Thermal wavelength: $\lambda_{\text{th}} = \frac{6.62607015 \times 10^{-34}}{1.12 \times 10^{-27}} \approx 5.92 \times 10^{-7}$ m, which is 0.592 $\mu$m. 4. Spacing between atoms: $n^{-1/3} = (10^{20})^{-1/3} \approx 2.15 \times 10^{-7}$ m. The ratio $\lambda_{\text{th}} / n^{-1/3} \approx 2.75$. **Answer:** At 100 nK the thermal wavelength is about 0.592 $\mu$m, about 2.75 times the spacing between atoms, so the atomic waves overlap and the gas is in the quantum regime. The same atom at 300 K has a thermal wavelength about 55,000 times shorter, because the wavelength scales with the inverse square root of the temperature. ## Common mistakes - Using degrees Celsius instead of kelvin. The formula needs absolute temperature, so 20 degrees Celsius must become 293 K before you use it. - Forgetting the square root. The wavelength depends on the square root of $m k_B T$, not on $m k_B T$ itself. - Treating the thermal wavelength as the size of an atom. It describes the spread of the atom's quantum wave, which is far larger than the atom. - Deciding quantum behavior from temperature alone. The test compares the wavelength with the spacing between particles, so the density matters as well. ## Where you will meet it - Bose-Einstein condensate experiments, where the phase-space density is compared with a threshold set by this wavelength. - Cold-atom physics, where the thermal wavelength decides whether a dilute gas can be described by classical statistics. - Semiconductor physics, where effective densities of electrons and holes are written in terms of a thermal wavelength. ## Questions people ask ### Why is it called thermal? It depends on the temperature $T$ of the gas. It is the de Broglie wavelength of a typical particle at that temperature, using a typical momentum $\sqrt{2\pi m k_B T}$. ### Is the thermal wavelength the same as the de Broglie wavelength? They are closely related. The de Broglie wavelength $h/p$ uses one particle's momentum, while the thermal wavelength uses a typical momentum set by the temperature. ### Why do scientists cool atoms to nanokelvin temperatures? A colder gas has a longer thermal wavelength, so the waves overlap at a lower density. Cooling to around 100 nK makes the quantum regime reachable in a gas that can still be studied in a lab. ## Related formulas - [De Broglie Wavelength](https://formulabro.yunusemrevurgun.com/quantum-mechanics/de-broglie-wavelength/) - [Bose-Einstein Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution/) - [Fermi-Dirac Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution/) - [Fermi Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy/) ## Sources - [Bose-Einstein condensate, Wikipedia](https://en.wikipedia.org/wiki/Bose%E2%80%93Einstein_condensate) - [Thermal de Broglie wavelength, Wikipedia](https://en.wikipedia.org/wiki/Thermal_de_Broglie_wavelength) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Energy-Momentum Relation > Energy, momentum and mass are linked by one equation, and a particle with no mass always carries energy only through its momentum. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/relativistic-energy-momentum/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E^2 = (p c)^2 + (m c^2)^2 $$ Read it out loud: "E squared equals the quantity p c, squared, plus the quantity m c squared, squared. E is the total energy, p is momentum, m is the rest mass and c is the speed of light." ## What each symbol means - $E$: The total energy of the particle, in joules (J). Particle physicists often quote energy in electronvolts (eV) or MeV. - $p$: The momentum of the particle, in kilograms meters per second (kg m/s). - $c$: The speed of light in vacuum, $299792458$ m/s. It is exact by definition of the meter. - $m$: The rest mass of the particle, in kilograms (kg). It is the mass the particle has when it is not moving. ## What the formula is doing Newton's formula for kinetic energy, $\frac{1}{2} m v^2$, works at everyday speeds but fails near the speed of light. Einstein's special relativity replaces it with a rule that holds at every speed. This formula is that rule, written in terms of total energy $E$ and momentum $p$. The equation adds two squared terms. The term $(pc)^2$ grows with momentum, and $(mc^2)^2$ is fixed by the rest mass $m$. The total energy $E$ is the square root of their sum. Both $pc$ and $mc^2$ are energies, so $c$ appears wherever momentum or mass is converted into energy. Two special cases are useful. A particle at rest has $p = 0$, so $E = mc^2$, which is its rest energy. A photon has zero rest mass, so $m = 0$ and the equation gives $E = pc$. Light carries energy only through its momentum. A moving particle has energy beyond its rest energy. The difference $E - mc^2$ is its kinetic energy. At low speeds this difference matches the familiar $\frac{1}{2} m v^2$, which is why the older formula works for everyday objects. ## An everyday picture Think of walking 3 blocks east and then 4 blocks north. The straight-line distance back to the start is 5 blocks, which is the square root of $3^2 + 4^2$. The energy-momentum relation has the same shape: the total energy $E$ is the long side of a right triangle, while $pc$ and $mc^2$ are the two shorter sides, so you add their squares and then take the root. ## Worked example: An electron with momentum 0.75 MeV/c An electron has rest energy $m c^2 = 0.51099895$ MeV and momentum energy $p c = 0.75$ MeV. Find its total energy $E$ and its kinetic energy $K = E - m c^2$. 1. Square the momentum term: $(pc)^2 = 0.75^2 = 0.5625$ MeV$^2$. 2. Square the rest energy: $(mc^2)^2 = 0.51099895^2 \approx 0.261119$ MeV$^2$. 3. Add and take the square root: $E = \sqrt{0.5625 + 0.261119} = \sqrt{0.823619} \approx 0.9075$ MeV. 4. Kinetic energy: $K = E - mc^2 = 0.9075 - 0.5110 \approx 0.3965$ MeV. **Answer:** The electron's total energy is about 0.908 MeV. About 0.397 MeV of that is motion energy on top of its 0.511 MeV rest energy. The energies do not add directly, because the squares must be added before the root is taken. ## Common mistakes - Using $\frac{1}{2} m v^2$ near the speed of light. The old formula is accurate only when the speed is far below $c$. Near that speed, use the full relation. - Adding the energies directly. The equation adds squares, so $E$ is not $pc + mc^2$. Square each term, add them, and take the square root. - Mixing units. If $p$ is in kg m/s, multiply by $c$ to get $pc$ in joules. Keeping both $pc$ and $mc^2$ in MeV avoids this step. - Thinking a photon must have mass because it has energy. With $m = 0$, the energy comes entirely from momentum, $E = pc$. ## Where you will meet it - Particle accelerators, which convert measured energies and momenta into particle masses. - Nuclear and particle physics, where energies are quoted in MeV and GeV with $mc^2$ as the rest energy. - Photon physics, where $E = pc$ gives the momentum of light from its energy. - Decay calculations, where the relation shows how the energy of a decay is shared among the products. ## Questions people ask ### Why does the formula contain $c$? The speed of light links energy and momentum to mass. In SI units $c$ turns mass into energy through $mc^2$, and it turns momentum into energy through $pc$. ### What happens when the momentum is zero? The momentum term vanishes and the energy becomes $E = mc^2$, the rest energy. A particle that is not moving still carries this energy. ### Do I need this for everyday objects? No. At everyday speeds the momentum term is so small compared with $mc^2$ that the older formula $\frac{1}{2} m v^2$ is accurate enough. ## Related formulas - [Photon Momentum](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) - [Compton Scattering](https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering/) - [Pair Production Threshold](https://formulabro.yunusemrevurgun.com/quantum-mechanics/pair-production-threshold/) ## Sources - [Energy-momentum relation, Wikipedia](https://en.wikipedia.org/wiki/Energy%E2%80%93momentum_relation) - [Mass-energy equivalence, Wikipedia](https://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Pair Production Threshold > A gamma ray with at least twice the rest energy of an electron can turn into an electron and its antiparticle, a positron. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/pair-production-threshold/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E_\gamma \ge 2 m_e c^2 \approx 1.022 \text{ MeV} $$ Read it out loud: "E gamma is greater than or equal to 2 times m e c squared, which is about 1.022 MeV. E gamma is the photon energy, m e is the electron mass and c is the speed of light." ## What each symbol means - $E_\gamma$: The energy of the photon, also called a gamma ray, in MeV (million electronvolts) or joules (J). - $m_e$: The mass of the electron, $9.1093837 \times 10^{-31}$ kg. The electron and the positron each have this mass. - $c$: The speed of light in vacuum, $299792458$ m/s. ## What the formula is doing Pair production turns light into matter. A high-energy photon can change into an electron and a positron, which is the electron's antiparticle with the same mass and an opposite, positive charge. The energy of the photon becomes the rest energy of the pair plus their motion energy, through $E = mc^2$. Making the pair needs at least the rest energy of both particles, which is $2 m_e c^2$. The electron's rest energy is $m_e c^2 = 0.51099895$ MeV, so the threshold is $2 \times 0.51099895 = 1.0219979$ MeV, or about 1.022 MeV. A photon with less energy than this cannot make a pair. Any energy above the threshold becomes kinetic energy of the pair. Energy alone is not enough. A photon in empty space cannot make a pair, because momentum must also be conserved, and a lone photon cannot share its energy and momentum in the right way. A nearby nucleus takes up the extra momentum and recoils, while taking very little energy, because it is so heavy. At high photon energies, pair production is a major way gamma rays lose energy in dense material. This is one reason heavy materials are used to shield against gamma rays. ## An everyday picture Think of a club with an entry fee. Two guests can get in only if you have paid at least the combined price of two tickets. Pay less and you cannot get in, and any money above the price is handed back to the guests as spending money. ## Worked example: Gamma rays at 0.8 MeV and 1.5 MeV Compare two gamma rays near a nucleus, one with energy 0.8 MeV and one with energy 1.5 MeV. Use $m_e c^2 = 0.51099895$ MeV for the electron rest energy. 1. Threshold: $2 m_e c^2 = 2 \times 0.51099895 = 1.0219979$ MeV, or about 1.022 MeV. 2. The 0.8 MeV photon: $0.8 - 1.022 = -0.222$ MeV. The energy is below the threshold, so it cannot make a pair. 3. The 1.5 MeV photon: $1.5 - 1.022 = 0.478$ MeV is left over after the rest energy of the pair is paid. The energy is above the threshold, so it can make a pair. 4. The leftover 0.478 MeV is shared as kinetic energy of the electron and positron, while the nucleus takes a negligible share. **Answer:** The 0.8 MeV gamma ray cannot create an electron-positron pair. The 1.5 MeV gamma ray can, and about 0.478 MeV is left over as motion energy of the pair. ## Common mistakes - Expecting a lone photon to make a pair in empty space. Momentum must be conserved, so a nearby nucleus is needed to absorb the extra momentum. - Using the wrong particle mass. The pair here is an electron and a positron, so the electron mass is the right one, not the proton mass. - Thinking the energy above the threshold is lost. It becomes kinetic energy of the electron and positron. - Comparing joules with MeV directly. Convert first, using $1 \text{ MeV} = 1.602176634 \times 10^{-13}$ J, before comparing the two energies. ## Where you will meet it - Gamma-ray shielding design, where pair production sets how strongly high-energy gamma rays are absorbed in dense materials. - Particle physics experiments, which create electron-positron pairs from high-energy photons to study matter and antimatter. - Medical and nuclear physics, where pair production is one of the interactions that decide how high-energy gamma rays deposit energy in matter. ## Questions people ask ### What is a positron? A positron is the antiparticle of the electron. It has the same mass as the electron and an opposite, positive charge. ### Why does the photon need a nucleus nearby? Momentum must be conserved. A photon has momentum but no rest mass, so a lone photon cannot give the pair both its energy and momentum. A nearby nucleus can take up the extra momentum while taking very little energy. ### Does the threshold change for different nuclei? To a very good approximation, the threshold is $2 m_e c^2$ for any nucleus. The nucleus affects how likely the process is, not the minimum energy needed. ## Related formulas - [Energy-Momentum Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/relativistic-energy-momentum/) - [Compton Scattering](https://formulabro.yunusemrevurgun.com/quantum-mechanics/compton-scattering/) - [Photon Momentum](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photon-momentum/) - [Photoelectric Effect](https://formulabro.yunusemrevurgun.com/quantum-mechanics/photoelectric-effect/) ## Sources - [Pair production, Wikipedia](https://en.wikipedia.org/wiki/Pair_production) - [Positron, Wikipedia](https://en.wikipedia.org/wiki/Positron) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Radioactive Decay Law > An unstable sample loses a fixed fraction of its atoms in each time interval, so the count falls off in an exponential curve. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/radioactive-decay-law/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ N(t) = N_0\, e^{-\lambda t} $$ Read it out loud: "N of t equals N zero times e to the power of negative lambda t. N of t is the number of atoms left after time t, N zero is the starting number, e is Euler's number, lambda is the decay constant and t is the time." ## What each symbol means - $N(t)$: The number of undecayed atoms left at time $t$. It is a count, with no unit. - $N_0$: The number of undecayed atoms at time zero, when counting starts. - $\lambda$: The decay constant: the chance per unit time that an atom decays. Its unit is the inverse of the time unit, such as per year. - $t$: The time elapsed, in the same units as $\lambda$'s time, such as years. - $e$: Euler's number, about 2.71828. It is the base of natural logarithms. - $t_{1/2}$: The half-life: the time for half of the atoms to decay. It is related to the decay constant by $t_{1/2} = \frac{\ln 2}{\lambda}$. ## What the formula is doing Each unstable atom has a fixed chance per unit time of decaying, and the decay constant $\lambda$ sets that chance. An atom does not age or remember how long it has existed. The fraction of atoms that decay in a short interval is the same at every moment. The formula says the number of atoms left, $N(t)$, falls exponentially. Start with $N_0$ atoms and multiply by $e^{-\lambda t}$. This factor is always between 0 and 1, so the count shrinks over time and never becomes negative. The half-life $t_{1/2} = \frac{\ln 2}{\lambda}$ is the time for half of the atoms to decay. After one half-life, $N$ is half of $N_0$. After two half-lives, a quarter remains. Half-lives are often easier to read from data than the decay constant. The decay law is statistical. It predicts how many atoms remain in a large sample, not when one particular atom will decay. Each atom's decay time is random, and only the average over many atoms follows the smooth curve. ## An everyday picture Imagine a concert hall where each person has the same chance of leaving in any given minute. In the first stretch of time, about half the crowd leaves. In the next stretch, half of those still inside leave, and so on. The crowd shrinks by the same fraction in each equal interval, which is exactly the behavior of the decay law. ## Worked example: Carbon-14 after 10,000 years Carbon-14 has a half-life of about 5730 years. Start with $N_0 = 1.0 \times 10^{6}$ carbon-14 atoms and find how many remain after $t = 10{,}000$ years. 1. Decay constant: $\lambda = \frac{\ln 2}{t_{1/2}} = \frac{0.693147}{5730} \approx 1.21 \times 10^{-4}$ per year. 2. Exponent: $\lambda t = 1.20968 \times 10^{-4} \times 10000 \approx 1.2097$. 3. Remaining fraction: $e^{-1.2097} \approx 0.2983$. 4. Remaining atoms: $N = 1.0 \times 10^{6} \times 0.2983 \approx 298{,}300$. **Answer:** About 298,300 carbon-14 atoms remain, roughly 30 percent of the starting sample. The time is about 1.75 half-lives, and the fraction left lies between one half and one quarter, as the half-life idea predicts. ## Common mistakes - Using the half-life where the decay constant belongs. The formula needs $\lambda$, so convert first with $\lambda = \frac{\ln 2}{t_{1/2}}$. - Subtracting half-lives instead of multiplying by one half. After each half-life the count is multiplied by one half, so after two half-lives a quarter remains, not zero. - Mixing time units. If the half-life is in years, the time $t$ and the decay constant $\lambda$ must also be in years. - Treating the formula as a prediction for one atom. It describes large numbers of atoms, because a single atom's decay time is random. ## Where you will meet it - Radiocarbon dating, which uses the decay of carbon-14 to estimate the age of organic remains. - Nuclear medicine, where the decay of short-lived tracer isotopes sets how much activity remains over time. - Nuclear waste planning, where isotope half-lives set how long a material must be stored before it is safe to handle. ## Questions people ask ### Does a half-life mean half the atoms are gone after that time? Yes, for a large sample. After one half-life, half of the original atoms have decayed. After another half-life, half of the remaining atoms decay, leaving a quarter of the original. ### Can the count reach zero? The curve gets closer and closer to zero but never reaches it. In practice the count is a whole number, so the last atom decays at some finite time. ### Does temperature or pressure change the half-life? For most radioactive decays, no. Decay happens inside the nucleus, and ordinary changes in temperature and pressure hardly affect it. ## Related formulas - [Quantum Tunneling Probability](https://formulabro.yunusemrevurgun.com/quantum-mechanics/quantum-tunneling-probability/) - [Energy-Time Uncertainty Relation](https://formulabro.yunusemrevurgun.com/quantum-mechanics/energy-time-uncertainty/) - [Planck-Einstein Relation (E = hf)](https://formulabro.yunusemrevurgun.com/quantum-mechanics/planck-einstein-relation/) ## Sources - [Radioactive decay, Wikipedia](https://en.wikipedia.org/wiki/Radioactive_decay) - [Half-life, Wikipedia](https://en.wikipedia.org/wiki/Half-life) - [Carbon-14, Wikipedia](https://en.wikipedia.org/wiki/Carbon-14) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Fermi-Dirac Distribution > For electrons and other fermions, it gives the chance that an energy level is filled, from 1 for full down to 0 for empty. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ f(E) = \frac{1}{e^{(E - \mu)/(k_B T)} + 1} $$ Read it out loud: "f of E equals 1 divided by the quantity e to the power of E minus mu, divided by k B times T, plus 1. f of E is the chance that a state is occupied, E is the energy of the state, mu is the chemical potential, k B is the Boltzmann constant and T is the absolute temperature." ## What each symbol means - $f(E)$: The occupation probability of a single state with energy $E$. It is a number from 0 (empty) to 1 (full), with no unit. - $E$: The energy of the state, in joules (J) or electronvolts (eV). - $\mu$: The chemical potential, an energy in joules or electronvolts. A state at $E = \mu$ is occupied with probability one half at any temperature. - $k_B$: The Boltzmann constant, $1.380649 \times 10^{-23}$ J/K (joules per kelvin). - $T$: The absolute temperature, in kelvin (K). ## What the formula is doing Fermions are particles such as electrons, protons and neutrons. They have half-integer spin and obey the Pauli exclusion principle, which says two identical fermions cannot share the same quantum state. This rule shapes how electrons fill energy levels in atoms, metals and stars. The formula gives the probability that a state at energy $E$ is occupied, a number from 0 to 1. The chemical potential $\mu$ marks the middle of the transition. At $E = \mu$ the exponent is zero, so $f = \frac{1}{2}$ at any temperature. Well below $\mu$, the exponent is large and negative, so $f$ is close to 1, and those states are almost certainly full. Well above $\mu$, the exponent is large and positive, so $f$ is close to 0. The temperature sets how sharp this step is. Near absolute zero it is a sharp cutoff, and at higher temperature it spreads out. The product $k_B T$ is the typical thermal energy at temperature $T$. Compare $E - \mu$ with $k_B T$. If the difference is a few times $k_B T$, the state is mostly empty or mostly full. At room temperature $k_B T$ is only about 0.026 eV. The plus sign in the denominator means $f$ can never exceed 1, which is a direct result of the exclusion principle. ## An everyday picture Think of a theater where each seat holds one person at most. Seats near the stage fill first and the back rows stay empty, with a boundary between full and empty seats. The chemical potential is the place where that boundary sits, and the temperature decides how blurry the boundary is, because a more energetic crowd shuffles more. ## Worked example: An electron state at room temperature Take $T = 300$ K and a state with energy $E = \mu + 0.1$ eV, which is 0.1 eV above the chemical potential. Use $k_B = 1.380649 \times 10^{-23}$ J/K and $e = 1.602176634 \times 10^{-19}$ C to convert joules into electronvolts. 1. Thermal energy in eV: $k_B T = \frac{1.380649 \times 10^{-23} \times 300}{1.602176634 \times 10^{-19}} \approx 0.025852$ eV. 2. Exponent: $\frac{E - \mu}{k_B T} = \frac{0.1}{0.025852} \approx 3.868$. 3. Exponential: $e^{3.868} \approx 47.85$, so the denominator is $47.85 + 1 = 48.85$. 4. Occupation: $f = \frac{1}{48.85} \approx 0.0205$. **Answer:** A state 0.1 eV above $\mu$ is occupied with probability about 0.0205, or about 2 percent, at room temperature. The state is almost always empty. ## Common mistakes - Reversing the sign of the exponent. Above $\mu$ the occupation is small. Below $\mu$ it is close to 1. - Mixing joules and electronvolts. Convert $k_B T$ into eV, or convert $E$ and $\mu$ into joules, before dividing. - Reading $f$ as a number of electrons. It is a probability for one state, between 0 and 1. Multiply by the number of states to get an expected count. - Using this formula for bosons. Electrons follow Fermi-Dirac statistics, while photons follow Bose-Einstein statistics. ## Where you will meet it - Metals and semiconductors, where the electron occupation near the Fermi level sets electrical and thermal properties. - White dwarf stars, where degenerate electrons follow Fermi-Dirac statistics and their pressure holds the star up. - Nuclear physics, where nucleons fill energy levels inside a nucleus following the same exclusion rule. ## Questions people ask ### What is the chemical potential? It is the energy at which a state has a 50 percent chance of being occupied. In a metal at absolute zero, the chemical potential equals the Fermi energy. ### What happens at absolute zero? The curve becomes a sharp step. States below $\mu$ are all full, and states above $\mu$ are all empty. ### Why can two electrons not share one state? The Pauli exclusion principle forbids two identical fermions from occupying the same quantum state. That is why the distribution never goes above 1. ## Related formulas - [Fermi Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy/) - [Bose-Einstein Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution/) - [Electron Shell Capacity](https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity/) - [Spin One-Half](https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/) ## Sources - [Fermi-Dirac statistics, Wikipedia](https://en.wikipedia.org/wiki/Fermi%E2%80%93Dirac_statistics) - [Pauli exclusion principle, Wikipedia](https://en.wikipedia.org/wiki/Pauli_exclusion_principle) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Bose-Einstein Distribution > For bosons such as photons, it gives the average number of particles that share a single energy level. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ n(E) = \frac{1}{e^{(E - \mu)/(k_B T)} - 1} $$ Read it out loud: "n of E equals 1 divided by the quantity e to the power of E minus mu, divided by k B times T, minus 1. n of E is the average number of particles in a state, E is the energy of the state, mu is the chemical potential, k B is the Boltzmann constant and T is the absolute temperature." ## What each symbol means - $n(E)$: The average number of bosons in one quantum state with energy $E$. It is a pure number with no unit, and it can be larger than 1. - $E$: The energy of the state, in joules (J) or electronvolts (eV). - $\mu$: The chemical potential, an energy in joules or electronvolts. For bosons it must stay below the lowest state energy. For photons it is zero. - $k_B$: The Boltzmann constant, $1.380649 \times 10^{-23}$ J/K (joules per kelvin). - $T$: The absolute temperature, in kelvin (K). ## What the formula is doing Bosons are particles with whole-number spin, such as photons and some atoms. Unlike fermions, any number of identical bosons can share one quantum state. The Bose-Einstein distribution gives the average number that occupy a state at energy $E$. The minus sign in the denominator is the key difference from the Fermi-Dirac formula. It lets $n$ grow large when $E$ is close to $\mu$, which allows many bosons to crowd into one low-energy state. For the denominator to stay positive, the exponent must be positive, so $E$ must be larger than $\mu$ for every state. For light, the chemical potential is zero, and the formula becomes $n = \frac{1}{e^{E/(k_B T)} - 1}$. This is the Planck distribution for photons. Higher temperature spreads bosons over more energy states, while lower temperature packs them into the lowest ones. When $E - \mu$ is well above $k_B T$, $n$ becomes small and the formula approaches the classical Boltzmann result. ## An everyday picture Think of a hotel where guests are allowed to share rooms. In the Fermi-Dirac case each room holds at most one guest. For bosons any number of guests can share a room, so a cheap, popular room can hold a crowd. The Bose-Einstein formula gives the average crowd size in each room. ## Worked example: A photon mode at 300 K Take a mode, or state, with energy $E = 0.05$ eV at $T = 300$ K. For light the chemical potential is zero, so $\mu = 0$. At room temperature the thermal energy is $k_B T \approx 0.025852$ eV. 1. Exponent: $\frac{E - \mu}{k_B T} = \frac{0.05}{0.025852} \approx 1.934$. 2. Exponential: $e^{1.934} \approx 6.921$, so the denominator is $6.921 - 1 = 5.921$. 3. Average occupation: $n = \frac{1}{5.921} \approx 0.169$. **Answer:** This mode holds about 0.169 photons on average, so it is mostly empty. Unlike electrons, a bosonic mode can hold more than one particle, and lower-energy modes can hold more than one on average. ## Common mistakes - Using the Fermi-Dirac plus sign. With $+1$ the result can never exceed 1, which is right for fermions but wrong for bosons. - Forgetting that $\mu = 0$ for photons. Photon numbers are not conserved, so their chemical potential is zero, which gives the Planck form. - Letting $E$ fall to $\mu$ or below. The denominator would then be zero or negative, and the formula stops making physical sense. - Reading $n$ as a probability. It is an average occupation number, and it can be larger than 1. ## Where you will meet it - Blackbody radiation, where the Bose-Einstein distribution with zero chemical potential gives the spectrum of thermal light. - Bose-Einstein condensates, where ultracold bosonic atoms pile into the lowest quantum state. - Lattice vibrations in solids, where phonons, the quanta of vibration in a crystal, follow this distribution. ## Questions people ask ### Why can bosons share a state? Identical bosons have no exclusion rule. Their wave functions can combine so that any number of them occupy the same state. ### Is this the same as Planck's law? Planck's law is the Bose-Einstein distribution for photons, with $\mu = 0$, combined with the number of available modes to give the energy spectrum. ### Can the average number be above 1? Yes. For bosons $n$ can be 2, 10 or more when $E$ is close to $\mu$. This is what makes Bose-Einstein condensation possible. ## Related formulas - [Planck's Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/plancks-law/) - [Fermi-Dirac Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution/) - [Fermi Energy](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy/) - [Stefan-Boltzmann Law](https://formulabro.yunusemrevurgun.com/quantum-mechanics/stefan-boltzmann-law/) ## Sources - [Bose-Einstein statistics, Wikipedia](https://en.wikipedia.org/wiki/Bose%E2%80%93Einstein_statistics) - [Planck's law, Wikipedia](https://en.wikipedia.org/wiki/Planck%27s_law) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # Fermi Energy > In a metal, electrons fill energy levels from the bottom up, and the Fermi energy is the height of the last level filled. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-energy/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ E_F = \frac{\hbar^2}{2 m}\left(3\pi^2 n\right)^{2/3} $$ Read it out loud: "E F equals h bar squared divided by 2 m, times the quantity 3 pi squared n, raised to the power of two thirds. E F is the Fermi energy, h bar is the reduced Planck constant, m is the electron mass, pi is about 3.14159 and n is the electron density." ## What each symbol means - $E_F$: The Fermi energy, the energy of the highest filled electron level at absolute zero, in joules (J) or electronvolts (eV). - $\hbar$: The reduced Planck constant, $1.054571817 \times 10^{-34}$ J s. - $m$: The mass of an electron, $9.1093837 \times 10^{-31}$ kg. - $n$: The electron density: the number of free electrons per cubic meter (m$^{-3}$). - $\pi$: The ratio of a circle's circumference to its diameter, about 3.14159. ## What the formula is doing A metal's outer electrons are free to move through the crystal, and together they behave like a gas of fermions. The exclusion principle allows two electrons, one for each spin, in each spatial state. At absolute zero the electrons fill the lowest states first, one level after another, up to a top level. The Fermi energy $E_F$ is the energy of that top filled level. The formula depends on the electron density $n$, the number of free electrons per cubic meter. More electrons in the same volume means more states must be filled, so the top level sits higher. The power $\frac{2}{3}$ comes from counting states. The number of states with momentum up to a value $k$ grows like $k^3$, and the energy grows like $k^2$. Combining these gives an energy that scales with $n^{2/3}$. The formula assumes free electrons in a simple metal. Real metals differ in detail, because the crystal lattice and electron interactions change the levels, but the formula is a good first estimate. The Fermi energy also sets the scale of the Fermi-Dirac distribution: electrons far below it are full, and those far above it are empty. ## An everyday picture Think of a parking garage that fills from the bottom floor upward, with two cars allowed per space. The garage fills floor by floor until the cars run out. The height of the highest occupied floor is the Fermi energy, and it rises when more cars must be parked in the same garage. ## Worked example: Free electrons in copper Copper has an electron density of about $n = 8.5 \times 10^{28}$ m$^{-3}$. Use $\hbar = 1.054571817 \times 10^{-34}$ J s, $m = 9.1093837 \times 10^{-31}$ kg and $1$ eV $= 1.602176634 \times 10^{-19}$ J. 1. Inside the bracket: $3\pi^2 n = 3 \times 9.8696 \times 8.5 \times 10^{28} \approx 2.517 \times 10^{30}$ m$^{-3}$. 2. Two thirds power: $(2.517 \times 10^{30})^{2/3} \approx 1.850 \times 10^{20}$ m$^{-2}$. 3. Prefactor: $\frac{\hbar^2}{2m} = \frac{(1.054571817 \times 10^{-34})^2}{2 \times 9.1093837 \times 10^{-31}} \approx 6.104 \times 10^{-39}$ J m$^2$. 4. Multiply: $E_F \approx 6.104 \times 10^{-39} \times 1.850 \times 10^{20} \approx 1.129 \times 10^{-18}$ J, which is $1.129 \times 10^{-18} / 1.602 \times 10^{-19} \approx 7.05$ eV. **Answer:** The Fermi energy of copper's free electrons is about 7.05 eV. Even at absolute zero, the most energetic electrons in copper move with this much energy. Dividing by the Boltzmann constant gives a temperature of about 82,000 K, which is why this energy is not a temperature. ## Common mistakes - Using per cubic centimeter for the density. The formula needs electrons per cubic meter, and per cubic centimeter numbers are a million times too small. - Forgetting the two thirds power. The energy depends on $n^{2/3}$, not directly on $n$. - Treating the Fermi energy as the average electron energy. For a free electron gas at absolute zero, the average energy is three fifths of $E_F$. - Reading $E_F$ as a temperature. Dividing by $k_B$ gives a temperature, about 82,000 K for copper, which is far above the melting point of the metal and shows the energy is not a temperature. ## Where you will meet it - Solid-state physics, where the Fermi energy sets the energy scale of electrons in metals. - Electrical conduction theory, where electrons near the Fermi energy carry most of the current. - White dwarf and neutron star physics, where degenerate fermions hold up the star against gravity. - Semiconductor physics, where the Fermi level marks the balance between electrons and holes. ## Questions people ask ### Is the Fermi energy the same as the Fermi level? They are closely related. The Fermi level is the chemical potential, and at absolute zero it equals the Fermi energy in a metal. ### Does the Fermi energy change with temperature? The formula gives the value at absolute zero. At room temperature the electron distribution changes only slightly, so the formula remains a good estimate. ### Why is the energy so large for electrons in metals? Electrons are packed into a small space at high density, so many must sit in high-energy states. Even at absolute zero, the top electrons carry several electronvolts of kinetic energy. ## Related formulas - [Fermi-Dirac Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/fermi-dirac-distribution/) - [Particle in a Box](https://formulabro.yunusemrevurgun.com/quantum-mechanics/particle-in-a-box/) - [Electron Shell Capacity](https://formulabro.yunusemrevurgun.com/quantum-mechanics/electron-shell-capacity/) - [Bose-Einstein Distribution](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bose-einstein-distribution/) ## Sources - [Fermi energy, Wikipedia](https://en.wikipedia.org/wiki/Fermi_energy) - [Free electron model, Wikipedia](https://en.wikipedia.org/wiki/Free_electron_model) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # CHSH Inequality > A Bell test combines four measurements into one number, and any theory with pre-set local answers must keep its size at 2 or below. Page: https://formulabro.yunusemrevurgun.com/quantum-mechanics/chsh-inequality/ Category: Quantum Mechanics Published: 2026-10-22 Updated: 2026-10-22 ## Formula $$ S = E(a,b) - E(a,b') + E(a',b) + E(a',b') $$ Read it out loud: "S equals E of a b, minus E of a b prime, plus E of a prime b, plus E of a prime b prime. S is the CHSH sum. E of two settings is the average correlation of the two measurements, from minus 1 to plus 1. Local hidden variable theories keep the size of S at 2 or less, while quantum mechanics can reach 2 times the square root of 2." ## What each symbol means - $S$: The CHSH sum, a pure number with no unit. Its size is at most 4 by construction and at most $2\sqrt{2}$ in quantum mechanics. - $E(a,b)$: The correlation for detector settings $a$ and $b$: the average of the product of the two results, each +1 or -1, over many paired trials. It ranges from $-1$ to $+1$. - $a$: The first of two possible settings on the first detector, such as a polarizer angle or a magnet direction. - $a'$: The second setting on the first detector. - $b$: The first of two possible settings on the second detector. - $b'$: The second setting on the second detector. ## What the formula is doing In a Bell test, two particles are created together and sent to two distant detectors. Each detector has two possible settings, and each measurement returns +1 or -1. The correlation $E(a,b)$ is the average of the product of the two results over many trials, so it always lies between $-1$ and $+1$. The CHSH sum combines four correlations, using two settings on each side. Local hidden variable theories assume each particle carries predetermined answers, and that one detector's setting cannot change the other detector's result. Under these assumptions every set of answers gives $|S| \le 2$. Quantum mechanics predicts a larger value. For a singlet pair of spin-one-half particles, the correlation is $E(a,b) = -\cos(\theta_a - \theta_b)$, where $\theta$ is the detector angle. With well-chosen settings the sum reaches $2\sqrt{2} \approx 2.828$, the Tsirelson bound. Experiments with entangled photons and other systems have measured $|S|$ above 2, in line with quantum mechanics, and later experiments closed the main loopholes. The 2022 Nobel Prize in Physics went to Alain Aspect, John Clauser and Anton Zeilinger for experiments with entangled photons that established violations of Bell inequalities. ## An everyday picture Think of two players who each get a random yes-or-no question from a referee and cannot talk to each other. Without shared quantum links, their best strategy wins about 75 percent of rounds. With entangled particles, they can win about 85 percent. The CHSH sum is the same kind of comparison, written as one number. ## Worked example: Singlet detectors at 0, 90, 45 and 135 degrees For a singlet pair the correlation is $E(a,b) = -\cos(\theta_a - \theta_b)$. Use detector angles $a = 0^\circ$, $a' = 90^\circ$, $b = 45^\circ$ and $b' = 135^\circ$. 1. Correlation $E(a,b)$: the angle difference is $0 - 45 = -45^\circ$, so $E(a,b) = -\cos(45^\circ) \approx -0.7071$. 2. Correlation $E(a,b')$: the difference is $0 - 135 = -135^\circ$, so $E(a,b') = -\cos(-135^\circ) \approx +0.7071$. 3. Correlation $E(a',b)$: the difference is $90 - 45 = 45^\circ$, so $E(a',b) = -\cos(45^\circ) \approx -0.7071$. 4. Correlation $E(a',b')$: the difference is $90 - 135 = -45^\circ$, so $E(a',b') = -\cos(45^\circ) \approx -0.7071$. 5. Sum: $S = (-0.7071) - (+0.7071) + (-0.7071) + (-0.7071) \approx -2.828$, so $|S| \approx 2.828 = 2\sqrt{2}$. **Answer:** The size $|S| = 2\sqrt{2} \approx 2.828$ is above the local limit of 2, which is the violation a Bell test looks for. The minus sign only reflects the sign convention and the chosen settings, so the size is the number that matters. Other settings give a smaller $|S|$, so the choice of angles matters. ## Common mistakes - Mixing up the signs. The sum subtracts the second term, so $-E(a,b')$ is added. A sign error changes the result, even when each correlation is right. - Using angles from a photon experiment with the spin formula. For polarized photons the correlation is $E = \cos 2(\alpha - \beta)$, so the best polarizer angles (0, 45, 22.5 and 67.5 degrees) are half the spin angles used here. - Treating a correlation as a single measurement. $E$ is an average over many paired trials, not one result. - Reading a value above 2 as proof of one particular theory. It rules out local hidden variable theories under the test's assumptions, and experiments must close loopholes carefully. ## Where you will meet it - Quantum information, where Bell tests certify the entanglement used in quantum key distribution and quantum networks. - Experimental tests of quantum foundations, including the photon experiments recognized by the 2022 Nobel Prize in Physics. - Device-independent cryptography, where a violation of the CHSH sum can certify that a key was produced with genuine quantum randomness. ## Questions people ask ### Why is 2 the limit for local theories? If each particle carries fixed answers for every setting, each correlation term is either +1 or -1. Arranged this way, the four terms give a sum of size exactly 2 or less, and never more. ### Does a violation prove quantum mechanics is right? A violation rules out local hidden variable theories under the test's assumptions. Quantum mechanics predicts the violation, and the experiments recognized by the 2022 Nobel Prize confirmed it. ### What is a singlet? A singlet is a pair of particles, such as two electrons, whose total spin is zero. Measured along the same direction, their results are always opposite. ## Related formulas - [Born Rule](https://formulabro.yunusemrevurgun.com/quantum-mechanics/born-rule/) - [Spin One-Half](https://formulabro.yunusemrevurgun.com/quantum-mechanics/spin-one-half/) - [Qubit State](https://formulabro.yunusemrevurgun.com/quantum-mechanics/qubit-state/) - [Bloch Sphere](https://formulabro.yunusemrevurgun.com/quantum-mechanics/bloch-sphere/) ## Sources - [CHSH inequality, Wikipedia](https://en.wikipedia.org/wiki/CHSH_inequality) - [Bell's theorem, Wikipedia](https://en.wikipedia.org/wiki/Bell%27s_theorem) - [The Nobel Prize in Physics 2022](https://www.nobelprize.org/prizes/physics/2022/summary/) From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com. --- # About Formula Bro Page: https://formulabro.yunusemrevurgun.com/about/ Updated: 2026-10-22 Formula Bro is a small website that explains well-known formulas to people who never got along with formulas. It covers four subjects: [AI and machine learning](/ai-ml/), [computer science](/computer-science/), [electricity](/electricity/) and [quantum mechanics](/quantum-mechanics/). It is a side project developed by [Yunus Emre Vurgun](https://yunusemrevurgun.com/). The cat on the home page is the site mascot, also called Formula Bro. ## How a page is written Every formula page follows the same order, so you always know where to look: 1. The formula in one sentence, before any math. 2. The formula itself, and how to read it out loud. 3. A table with every symbol, what it stands for and its unit. 4. What the formula is doing, step by step, and an everyday picture of it. 5. One worked example with small, friendly numbers. 6. The mistakes beginners make, where the formula shows up in real life, questions people ask, and the sources. ## How a page is checked - Every number in every worked example is recomputed by a script each time the site is built. If one is off, the site does not publish. - Physical constants use the official SI and CODATA values. - Each page lists two or three sources, mostly encyclopedia articles and original papers, that state the same formula. - The pages are drafted with the help of AI tools and then reviewed against those sources. ## Found a mistake? Formulas are easy to get subtly wrong. If something on a page is wrong or unclear, send a note through the [contact page on yunusemrevurgun.com](https://yunusemrevurgun.com/contact) with the page address. ## The plain look The site uses your computer's own fonts, no scripts and no tracking code, so pages load fast on any connection and print cleanly. Formulas are written in MathML, the math language browsers understand natively, so you can select and copy them. --- # Notes for AI Agents Page: https://formulabro.yunusemrevurgun.com/for-ai-agents/ Updated: 2026-10-22 Formula Bro is written to be easy for language models and agents to read, quote and cite. Everything below is public and needs no key. ## Machine-readable files | File | What is in it | | --- | --- | | [/llms.txt](/llms.txt) | Short index of the site in the llms.txt format: every formula with its one-line meaning and LaTeX. | | [/llms-full.txt](/llms-full.txt) | Every page of the site as Markdown, in one file. | | [/formulas.json](/formulas.json) | Every formula as JSON: id, title, LaTeX, symbols with meanings, worked example, related pages, sources. | | [/sitemap.xml](/sitemap.xml) | Every HTML page with the date its content last changed. | | [/feed.xml](/feed.xml) | Atom feed of formula pages, newest first. | ## URL patterns - A subject hub: `/ai-ml/`, `/computer-science/`, `/electricity/`, `/quantum-mechanics/`. - A formula page: `///`, for example `/ai-ml/softmax/`. - The Markdown copy of any page: the same path with `.md` in place of the trailing slash, for example `/ai-ml/softmax.md`. Formulas in the Markdown copies are LaTeX between `$` or `$$`. - Every HTML page also points to its Markdown copy with ``. ## What each formula page contains The formula in LaTeX and MathML (the MathML carries the original LaTeX as an annotation), a definition of every symbol with units, a plain-English explanation, an analogy, a worked example whose numbers are recomputed on every build, common mistakes, uses, questions and answers, related formulas and two or three sources. Structured data on each page uses schema.org `Article`, `LearningResource`, `BreadcrumbList` and `FAQPage`. ## Using the content - Crawling, indexing, quoting and answering questions from these pages are allowed (`Content-Signal: search=yes, ai-input=yes, ai-train=yes` in [robots.txt](/robots.txt)). - When you quote a page, link to its canonical URL (the HTML page, with the trailing slash). - When a formula matters for safety, money or exams, tell the reader to check it against the sources listed at the bottom of the page. - Report a wrong formula or number through the [contact page on yunusemrevurgun.com](https://yunusemrevurgun.com/contact).