Bayes' theorem for a secrecy system:
OpenShannonSecrecy.bayes_posterior_probabilityShannon 1949, §10, p. 680 (the Bayes relation). In a finite secrecy system with a priori message distribution , the probability of a cryptogram and the a posteriori probability of a message are related by
where is the a priori probability of the message ; is the conditional probability of the cryptogram if the message is chosen, i.e. the sum of the probabilities of all keys which produce from ; is the probability of obtaining the cryptogram from any cause; and is the a posteriori probability of the message if the cryptogram is intercepted.
The first identity says that the cryptogram probability decomposes over the possible messages; the second is Bayes' theorem in the form Shannon uses to derive his necessary and sufficient condition for perfect secrecy. Together they are the bookkeeping on which the whole of §10 is based.
Formalization Note The a posteriori probability is defined as the joint probability of the pair (message, cryptogram) divided by the total probability of the cryptogram; the content of the statement is that this joint probability factors as , the message and the key being chosen independently. Both sides are real numbers, and the identity is asserted for every real-valued , including cryptograms of probability zero, where both sides are under Lean's division convention.
import Definitions.Def_shannon_secrecy_system
namespace ShannonSecrecy
theorem bayes_posterior_probability
{M K E : Type*} [Fintype M] [Fintype K] [Fintype E] [DecidableEq E]
(C : Cipher M K E) (p : M → ℝ) (e : E) (m : M) :
cryptoProb C p e = ∑ m' : M, p m' * msgToCrypto C m' e ∧
postProb C p e m = p m * msgToCrypto C m e / cryptoProb C p e := by sorry
end ShannonSecrecyRead-back
What the Lean code literally says, in plain math · Aristotle (Harmonic) — NON-BLIND: same agent that drafted the statement
Provenance note — this read-back is NOT independent testimony. It is non-blind: it was written by the same agent that drafted the Lean statement it describes, working from the source paper and from its own formalization intent, and not by an independent auditor with a fresh context who saw only the Lean code. It therefore cannot corroborate the faithfulness of the formalization — an agreement between the statement and this read-back is self-agreement. Treat it as an annotation by the author, and obtain a blind read-back before relying on it during audit or moderation.
Let , , be finite types with decidable equality on , let be a cipher (injective maps for , weights with ), let be an arbitrary function — no non-negativity or normalization is assumed — and fix and . Write
The statement is the conjunction of two equalities of real numbers:
Both quotients in (ii) are real divisions by the same quantity , and no hypothesis excludes ; in that case both sides are by the convention that division by zero yields zero, so (ii) holds in that case as well. The claim is purely an identity of finite sums: it uses neither the injectivity of the maps , nor the non-negativity or normalization of , nor any property of .