Entropy, Information, and Coding TODO
Concept
The information content of an event is defined as the log of the reciprocal of its probability, and entropy is the expected value of that quantity — the average uncertainty of a distribution. When the log base is 2, the unit is bits, and for a fixed number of outcomes, entropy is maximized by the uniform distribution. The source coding theorem says the average length of a lossless code can never be shorter than the entropy, and Huffman or arithmetic coding can approach that limit arbitrarily closely. Relative entropy (KL divergence) is the extra cost paid for encoding under an incorrect assumed distribution, and mutual information is how much one variable's uncertainty is reduced by knowing another. This maximum-entropy view is the standard by which key and randomness strength is measured, in bits.
The theoretical limits of compression, the actual entropy of seeds and passwords, and judging the information content of logs or features all hinge on this — overestimating entropy leads to using randomness that feels secure but isn't.
Code & Formula
# 엔트로피·정보·코딩 — 사건 하나의 정보량 -log2(p), 그리고 분포 전체의 섀넌 엔트로피.
import math
def entropy(probs: list[float]) -> float:
return -sum(p * math.log2(p) for p in probs if p > 0)
fair_coin = [0.5, 0.5]
biased_coin = [0.9, 0.1]
fair_die = [1 / 6] * 6
for name, dist in [("공정한 동전", fair_coin), ("치우친 동전(0.9/0.1)", biased_coin), ("주사위", fair_die)]:
h = entropy(dist)
print(f"{name:20} H = {h:.4f} bits (최대 = log2({len(dist)}) = {math.log2(len(dist)):.4f})")
# 치우친 분포일수록 "다음 결과가 뭘지 이미 어느 정도 안다" → 엔트로피(불확실성)가 낮다.
Exercise
Compute the entropy from character frequencies in a text file, compare it to its gzip compression ratio, and directly calculate the entropy in bits carried by a 12-word mnemonic.
Practical Connection
The security of private keys and seeds is ultimately defined by their entropy in bits, and the fact that LMSR's cost function takes a log-sum-exp form comes from the same mathematical root — entropy and exponential families.
If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.