Documentation

CslibFrontier.Languages.Probabilistic.Oracle.Lipschitz

Lipschitz oracle programs #

A program program : ProbOracleComp spec α is K-Lipschitz at an oracle oracle (ProbOracleComp.LipschitzAt K oracle program) when replacing oracle by any oracle whose reply to every query is within statistical distance ε moves the output law of program by at most K * ε. Private samples are uniform and each external query is answered by an independent draw from the oracle's reply law (OracleComp.evalWith).

This is the stability condition under which stochastic oracle debate is correct [BrownCohenIrvingPiliouras2024, Definition 6.1], stated for every reply and output type. On Bool replies and a Bool output it is the source's condition (lipschitzAt_bool_iff): the probability of outputting true moves by at most K times the largest difference, over queries, of the probabilities of replying true.

A program making at most n external queries is n-Lipschitz at every oracle (LipschitzAt.of_isQueryBounded), by replacing replies one query at a time. The constant can be much smaller than the number of queries: a program that queries many times but returns only its first reply is 1-Lipschitz.

Main definitions #

Main results #

References #

def Cslib.ProbOracleComp.LipschitzAt {Query α : Type} {spec : Query → Type} (K : NNReal) (oracle : (q : Query) → PMF (spec q)) (program : ProbOracleComp spec α) :

program is K-Lipschitz at the oracle oracle: against any oracle oracle' whose reply law at every query is within statistical distance ε of oracle's, the output law of program is within K * ε of its output law against oracle.

The condition is relative to the one oracle oracle, as in [BrownCohenIrvingPiliouras2024, Definition 6.1], and quantifies over the tolerance ε in place of the supremum distance between oracles. The source writes a strict inequality, which no machine satisfies (take oracle' = oracle); the bound here is non-strict, as in the Lean formalization accompanying the source (google-deepmind/debate, Oracle.lipschitz). The source takes K > 0; K = 0 is admitted here and says that the output law does not depend on the oracle.

theorem Cslib.ProbOracleComp.LipschitzAt.mono {Query α : Type} {spec : Query → Type} {K₁ K₂ : NNReal} {oracle : (q : Query) → PMF (spec q)} {program : ProbOracleComp spec α} (h : LipschitzAt K₁ oracle program) (hK : K₁ ≤ K₂) :
LipschitzAt K₂ oracle program

A larger constant is still a Lipschitz constant.

theorem Cslib.ProbOracleComp.LipschitzAt.of_isQueryBounded {Query α : Type} {spec : Query → Type} {program : ProbOracleComp spec α} {n : ℕ} (h : program.IsQueryBounded n) (oracle : (q : Query) → PMF (spec q)) :
LipschitzAt (↑n) oracle program

Query-bounded programs. A program making at most n external queries on every path is n-Lipschitz at every oracle: replacing the replies one query at a time moves the output law by at most ε per query, and private samples are answered identically on both sides.

theorem Cslib.ProbOracleComp.LipschitzAt.bind {Query α β : Type} {spec : Query → Type} {K₁ K₂ : NNReal} {oracle : (q : Query) → PMF (spec q)} {program : ProbOracleComp spec α} {next : α → ProbOracleComp spec β} (h : LipschitzAt K₁ oracle program) (hnext : ∀ (a : α), LipschitzAt K₂ oracle (next a)) :
LipschitzAt (K₁ + K₂) oracle (program >>= next)

Sequencing. If program is K₁-Lipschitz at oracle and every continuation is K₂-Lipschitz there, the sequenced program is (K₁ + K₂)-Lipschitz at oracle.

theorem Cslib.ProbOracleComp.LipschitzAt.map {Query α β : Type} {spec : Query → Type} {K : NNReal} {oracle : (q : Query) → PMF (spec q)} (f : α → β) {program : ProbOracleComp spec α} (h : LipschitzAt K oracle program) :
LipschitzAt K oracle (f <$> program)

Deterministic postprocessing keeps the constant.

theorem Cslib.ProbOracleComp.lipschitzAt_bool_iff {Query : Type} {oracle : Query → PMF Bool} {program : ProbOracleComp (fun (x : Query) => Bool) Bool} {K : NNReal} :
LipschitzAt K oracle program ↔ ∀ (oracle' : Query → PMF Bool), |((OracleComp.evalWith (OracleComp.sumHandler ProbComp.unifOracle oracle) program) true).toReal - ((OracleComp.evalWith (OracleComp.sumHandler ProbComp.unifOracle oracle') program) true).toReal| ≤ ↑K * ⨆ (q : Query), |((oracle q) true).toReal - ((oracle' q) true).toReal|

Agreement with the source on Bool. For Bool replies, a Bool output and a finite constant K, being K-Lipschitz at oracle is [BrownCohenIrvingPiliouras2024, Definition 6.1]: against every other oracle, the probability of outputting true moves by at most K times the largest difference, over queries, of the probabilities of replying true.

theorem Cslib.ProbOracleComp.closeTo_run_of_isQueryBounded {Query β : Type} {spec : Query → Type} (oracle₁ oracle₂ : (q : Query) → ProbComp (spec q)) {prog : ProbOracleComp spec β} {Q : ℕ} (hQ : prog.IsQueryBounded Q) {ε : ENNReal} (hclose : ∀ (q : Query), Probability.CloseTo (oracle₁ q).eval (oracle₂ q).eval ε) :
Probability.CloseTo (prog.run oracle₁).eval (prog.run oracle₂).eval (↑Q * ε)

Replacing an oracle oracle₁ by an ε-close probabilistic oracle oracle₂ moves the output law of any Q-query ProbOracleComp program by at most Q * ε.