Bandits.TS.integral_regret_le
If Thompson sampling has the correct prior over environments and every environment has K
actions, each of which has a corresponding reward between l and u that is sub-Gaussian with
variance proxy Ο2 after its mean is subtracted, then the Bayesian regret at time n is at most
(2 * K + 1) * (u - l) + 8 * β(Ο2 * K * n * Real.log n).
-
Ξ© : Type u_1MeasurableSpace Ξ©A measurable space is a space equipped with a Ο-algebra. -
π : Type u_2MeasurableSpace πStandardBorelSpace πA standard Borel space is a measurable space arising as the Borel sets of some Polish topology.Nonempty π
-
K : βNonempty (Fin K) -
l : β -
u : β -
Ο2 : β -
Q : MeasureTheory.Measure πA measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure.MeasureTheory.IsProbabilityMeasure QA measureΞΌis called a probability measure ifΞΌ univ = 1. -
ΞΊ : ProbabilityTheory.Kernel (π Γ Fin K) βA kernel from a measurable spaceΞ±to another measurable spaceΞ²is a measurable functionΞΊ : Ξ± β Measure Ξ².ProbabilityTheory.IsMarkovKernel ΞΊA kernel is a Markov kernel if every measure in its image is a probability measure. -
E : Ξ© β π -
A : β β Ξ© β Fin K -
R : β β Ξ© β β -
P : MeasureTheory.Measure Ξ©MeasureTheory.IsProbabilityMeasure P -
n : β
-
hK : 0 < K -
h : Learning.IsBayesAlgEnvSeq Q ΞΊ (tsAlgorithm hK Q ΞΊ) E A R PIsBayesAlgEnvSeq Q ΞΊ alg E A Y Pstates that there is a measureP : Measure Ξ©such that the parameterE : Ξ© β πhas lawQand that the sequences of actionsA : β β Ξ© β πand feedbacksY : ββ¦ -
hlu : l β€ u -
hm : β (e : π) (a : Fin K), β« (x : β), id x βΞΊ (e, a) β Set.Icc l u -
hΟ2 : 0 < Ο2 -
hs : β (e : π) (a : Fin K), ProbabilityTheory.HasSubgaussianMGF (fun x => x - β« (x : β), id x βΞΊ (e, a)) β¨Ο2, β―β© (ΞΊ (e, a))A random variableXhas a sub-Gaussian moment-generating function with parametercwith respect to a measureΞΌif for allt : β,exp (t * X)isΞΌ-integrable and the moment-generating functβ¦
β« (x : Ξ©), Learning.IsBayesAlgEnvSeq.regret ΞΊ E A n x βP β€ (2 * βK + 1) * (u - l) + 8 * β(Ο2 * βK * βn * Real.log βn)MeasurableSpace : Type u_6 β Type u_6A measurable space is a space equipped with a Ο-algebra.
StandardBorelSpace : (Ξ± : Type u_1) β [MeasurableSpace Ξ±] β PropA standard Borel space is a measurable space arising as the Borel sets of some Polish topology. This is useful in situations where a space has no natural topology or the natural topology in a space is non-Polish. To endow a standard Borel space `Ξ±` with a compatible Polish topology, use `letI := upgradeStandardBorel Ξ±`. One can then use `eq_borel_upgradeStandardBorel Ξ±` to rewrite the `MeasurableSpace Ξ±` instance to `borel Ξ± t`, where `t` is the new topology.
Nonempty : Sort u β Prop`Nonempty Ξ±` is a typeclass that says that `Ξ±` is not an empty type, that is, there exists an element in the type. It differs from `Inhabited Ξ±` in that `Nonempty Ξ±` is a `Prop`, which means that it does not actually carry an element of `Ξ±`, only a proof that *there exists* such an element. Given `Nonempty Ξ±`, you can construct an element of `Ξ±` *nonconstructively* using `Classical.choice`.
Fin : β β TypeNatural numbers less than some upper bound. In particular, a `Fin n` is a natural number `i` with the constraint that `i < n`. It is the canonical type with `n` elements.
Nat : TypeThe natural numbers, starting at zero. This type is special-cased by both the kernel and the compiler, and overridden with an efficient implementation. Both use a fast arbitrary-precision arithmetic library (usually [GMP](https://gmplib.org/)); at runtime, `Nat` values that are sufficiently small are unboxed.
Real : TypeThe type `β` of real numbers constructed as equivalence classes of Cauchy sequences of rational numbers.
MeasureTheory.IsProbabilityMeasure : {Ξ± : Type u_1} β {m0 : MeasurableSpace Ξ±} β MeasureTheory.Measure Ξ± β PropA measure `ΞΌ` is called a probability measure if `ΞΌ univ = 1`.
MeasureTheory.Measure : (Ξ± : Type u_5) β [MeasurableSpace Ξ±] β Type u_5A measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. The measure of a set `s`, denoted `ΞΌ s`, is an extended nonnegative real. The real-valued version is written `ΞΌ.real s`.
ProbabilityTheory.IsMarkovKernel : {Ξ± : Type u_1} β
{Ξ² : Type u_2} β {mΞ± : MeasurableSpace Ξ±} β {mΞ² : MeasurableSpace Ξ²} β ProbabilityTheory.Kernel Ξ± Ξ² β PropA kernel is a Markov kernel if every measure in its image is a probability measure.
ProbabilityTheory.Kernel : (Ξ± : Type u_1) β (Ξ² : Type u_2) β [MeasurableSpace Ξ±] β [MeasurableSpace Ξ²] β Type (max u_1 u_2)A kernel from a measurable space `Ξ±` to another measurable space `Ξ²` is a measurable function `ΞΊ : Ξ± β Measure Ξ²`. The measurable space structure on `MeasureTheory.Measure Ξ²` is given by `MeasureTheory.Measure.instMeasurableSpace`. A map `ΞΊ : Ξ± β MeasureTheory.Measure Ξ²` is measurable iff `β s : Set Ξ², MeasurableSet s β Measurable (fun a β¦ ΞΊ a s)`.
Prod : Type u β Type v β Type (max u v)The product type, usually written `Ξ± Γ Ξ²`. Product types are also called pair or tuple types. Elements of this type are pairs in which the first element is an `Ξ±` and the second element is a `Ξ²`. Products nest to the right, so `(x, y, z) : Ξ± Γ Ξ² Γ Ξ³` is equivalent to `(x, (y, z)) : Ξ± Γ (Ξ² Γ Ξ³)`. Conventions for notations in identifiers: * The recommended spelling of `Γ` in identifiers is `Prod`.
LT.lt : {Ξ± : Type u} β [self : LT Ξ±] β Ξ± β Ξ± β PropThe less-than relation: `x < y` Conventions for notations in identifiers: * The recommended spelling of `<` in identifiers is `lt`.
Learning.IsBayesAlgEnvSeq : {π : Type u_1} β
{π : Type u_2} β
{π¨ : Type u_3} β
{Ξ© : Type u_4} β
[inst : MeasurableSpace π] β
[inst_1 : MeasurableSpace π] β
[inst_2 : MeasurableSpace π¨] β
[inst_3 : MeasurableSpace Ξ©] β
MeasureTheory.Measure π β
ProbabilityTheory.Kernel (π Γ π) π¨ β
Learning.Algorithm π π¨ ββ¦`IsBayesAlgEnvSeq Q ΞΊ alg E A Y P` states that there is a measure `P : Measure Ξ©` such that the parameter `E : Ξ© β π` has law `Q` and that the sequences of actions `A : β β Ξ© β π` and feedbacks `Y : β β Ξ© β π¨` are generated by the algorithm `alg : Algorithm π π¨` interacting with an underlying environment that depends on `E` and `ΞΊ` (`stationaryEnv (ΞΊ.sectR (E Ο))`).Go to its page
Bandits.tsAlgorithm : {K : β} β
{π : Type u_1} β
[inst : MeasurableSpace π] β
[StandardBorelSpace π] β
[Nonempty π] β
0 < K β
(Q : MeasureTheory.Measure π) β
[MeasureTheory.IsProbabilityMeasure Q] β
(ΞΊ : ProbabilityTheory.Kernel (π Γ Fin K) β) β
[ProbabilityTheory.IsMarkovKernel ΞΊ] β Learning.Algorithm (Fin K) βThe Thompson sampling algorithm with actions in `Fin K`, where `Q : Measure π` is a prior distribution over parameters, and `ΞΊ : Kernel (π Γ Fin K) β` is a Markov kernel that defines the stationary environment `stationaryEnv (ΞΊ.sectR e)` that corresponds to a parameter `e : π`. At every time `n`, the Thompson sampling policy uses the posterior over the parameters given the history up to time `n` to derive the probability of each action being optimal. The action for time `n` is sampled according to these probabilities.Go to its page
LE.le : {Ξ± : Type u} β [self : LE Ξ±] β Ξ± β Ξ± β PropThe less-equal relation: `x β€ y` Conventions for notations in identifiers: * The recommended spelling of `β€` in identifiers is `le`.
Membership.mem : {Ξ± : outParam (Type u)} β {Ξ³ : Type v} β [self : Membership Ξ± Ξ³] β Ξ³ β Ξ± β PropThe membership relation `a β s : Prop` where `a : Ξ±`, `s : Ξ³`. Conventions for notations in identifiers: * The recommended spelling of `β` in identifiers is `mem`.
MeasureTheory.integral : {Ξ± : Type u_6} β
{G : Type u_7} β
[inst : NormedAddCommGroup G] β [NormedSpace β G] β {x : MeasurableSpace Ξ±} β MeasureTheory.Measure Ξ± β (Ξ± β G) β GThe Bochner integral
id : {Ξ± : Sort u} β Ξ± β Ξ±The identity function. `id` takes an implicit argument `Ξ± : Sort u` (a type in any universe), and an argument `a : Ξ±`, and returns `a`. Although this may look like a useless function, one application of the identity function is to explicitly put a type on an expression. If `e` has type `T`, and `T'` is definitionally equal to `T`, then `@id T' e` typechecks, and Lean knows that this expression has type `T'` rather than `T`. This can make a difference for typeclass inference, since `T` and `T'` may have different typeclass instances on them. `show T' from e` is sugar for an `@id T' e` expression.
Prod.mk : {Ξ± : Type u} β {Ξ² : Type v} β Ξ± β Ξ² β Ξ± Γ Ξ²Constructs a pair. This is usually written `(x, y)` instead of `Prod.mk x y`. Conventions for notations in identifiers: * The recommended spelling of `(a, b)` in identifiers is `mk`.
Set.Icc : {Ξ± : Type u_1} β [Preorder Ξ±] β Ξ± β Ξ± β Set Ξ±`Icc a b` is the left-closed right-closed interval $[a, b]$.
ProbabilityTheory.HasSubgaussianMGF : {Ξ© : Type u_1} β
{mΞ© : MeasurableSpace Ξ©} β
(Ξ© β β) β NNReal β autoParam (MeasureTheory.Measure Ξ©) ProbabilityTheory.HasSubgaussianMGF._auto_1 β PropA random variable `X` has a sub-Gaussian moment-generating function with parameter `c` with respect to a measure `ΞΌ` if for all `t : β`, `exp (t * X)` is `ΞΌ`-integrable and the moment-generating function of `X` is bounded by `exp (c * t ^ 2 / 2)` for all `t : β`. This implies in particular that `X` has expectation 0. This is equivalent to `Kernel.HasSubgaussianMGF X c (Kernel.const Unit ΞΌ) (Measure.dirac ())`, as proved in `HasSubgaussianMGF_iff_kernel`. Properties about sub-Gaussian moment-generating functions should be proved first for `Kernel.HasSubgaussianMGF` when possible.
HSub.hSub : {Ξ± : Type u} β {Ξ² : Type v} β {Ξ³ : outParam (Type w)} β [self : HSub Ξ± Ξ² Ξ³] β Ξ± β Ξ² β Ξ³`a - b` computes the difference of `a` and `b`. The meaning of this notation is type-dependent. * For natural numbers, this operator saturates at 0: `a - b = 0` when `a β€ b`. Conventions for notations in identifiers: * The recommended spelling of `-` in identifiers is `sub` (when used as a binary operator).
Subtype.mk : {Ξ± : Sort u} β {p : Ξ± β Prop} β (val : Ξ±) β p val β Subtype pLearning.IsBayesAlgEnvSeq.regret : {π : Type u_1} β
{π : Type u_2} β
{Ξ© : Type u_4} β
[inst : MeasurableSpace π] β
[inst_1 : MeasurableSpace π] β ProbabilityTheory.Kernel (π Γ π) β β (Ξ© β π) β (β β Ξ© β π) β β β Ξ© β βA random variable that gives the regret at time `n`.Go to its page
HMul.hMul : {Ξ± : Type u} β {Ξ² : Type v} β {Ξ³ : outParam (Type w)} β [self : HMul Ξ± Ξ² Ξ³] β Ξ± β Ξ² β Ξ³`a * b` computes the product of `a` and `b`. The meaning of this notation is type-dependent. Conventions for notations in identifiers: * The recommended spelling of `*` in identifiers is `mul`.
HAdd.hAdd : {Ξ± : Type u} β {Ξ² : Type v} β {Ξ³ : outParam (Type w)} β [self : HAdd Ξ± Ξ² Ξ³] β Ξ± β Ξ² β Ξ³`a + b` computes the sum of `a` and `b`. The meaning of this notation is type-dependent. Conventions for notations in identifiers: * The recommended spelling of `+` in identifiers is `add`.
Real.sqrt : β β βThe square root of a real number. This returns 0 for negative inputs. This has notation `βx`. Note that `βxβ»ΒΉ` is parsed as `β(xβ»ΒΉ)`.
Real.log : β β βThe real logarithm function, equal to the inverse of the exponential for `x > 0`, to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to `(-β, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and the derivative of `log` is `1/x` away from `0`.
Code
theorem integral_regret_le (hK : 0 < K) (h : IsBayesAlgEnvSeq Q ΞΊ (tsAlgorithm hK Q ΞΊ) E A R P)
(hlu : l β€ u) (hm : β e a, (ΞΊ (e, a))[id] β (Set.Icc l u)) (hΟ2 : 0 < Ο2)
(hs : β e a, HasSubgaussianMGF (fun x β¦ x - (ΞΊ (e, a))[id]) β¨Ο2, hΟ2.leβ© (ΞΊ (e, a))) (n : β) :
P[IsBayesAlgEnvSeq.regret ΞΊ E A n]
β€ (2 * K + 1) * (u - l) + 8 * β(Ο2 * K * n * Real.log n)Proof
by
by_cases hn : n = 0
Β· simp [hn, IsBayesAlgEnvSeq.regret, Bandits.regret]
nlinarith
have hΞ΄ : (0 : β) < 1 / n ^ 2 := by positivity
calc P[IsBayesAlgEnvSeq.regret ΞΊ E A n]
= _ :=
integral_regret_eq_add hK h hm n
_ β€ _ :=
add_le_add
(integral_sum_range_actionMean_bestAction_sub_ucb_bestAction_le h hlu hm hΟ2 hs hΞ΄ n)
(integral_sum_range_ucb_action_sub_actionMean_action_le h hlu hm hΟ2 hs hΞ΄ n)
_ = K * (u - l) + (K + 1) * (u - l) * ((n - 1) / n)
+ 4 * β((2 : β) ^ 2 * (Ο2 * K * n * Real.log n)) := by
field_simp
rw [Real.log_pow]
ring_nf
_ = K * (u - l) + (K + 1) * (u - l) * ((n - 1) / n) + 8 * β(Ο2 * K * n * Real.log n) := by
rw [Real.sqrt_mul (by positivity), Real.sqrt_sq (by norm_num)]
ring
_ β€ K * (u - l) + (K + 1) * (u - l) * 1 + 8 * β(Ο2 * K * n * Real.log n) := by -- loose
have : 0 β€ u - l := sub_nonneg.2 hlu
gcongr
rw [div_le_one (by positivity)]
linarith
_ = _ := by
ringActions: Source Β· Open Issue
Meaning last changed in v4.34.0-rc2-39-gb743f31 (2026-09-08), the 5th recorded change.
Self-contained, with its dependencies inlined and proofs replaced by sorry: download the raw file Β· open it in the Lean web editor.
Dependency graph
Audit surface: 25 project declarations, 140 external constants
β Proved: no sorry anywhere in its closure
This is the tool's own reading of one build's recorded axioms, and it is not robust against an author who wants it to pass. Checking meant to be relied on should go through Comparator, which replays the proof through the kernel from an export against an explicit list of permitted axioms.