proofs
Provedattentionresidual-seriesexternal-review-4

Residual series: exact finite-history key, value and completion counts

For all J∈Type⁡\htmlData{mx=1}{J \in \htmlData{mx=0}{\operatorname{Type}}}, r:J→R\htmlData{mx=3}{r : \htmlData{mx=0}{J} \mathrel{\htmlData{mx=2}{\to}} \htmlData{mx=1}{\mathbb{R}}} and ρ∈R\htmlData{mx=1}{\rho \in \htmlData{mx=0}{\mathbb{R}}}, if ∑jr(j)=1\htmlData{mx=3}{\sum_{j} \htmlData{mx=2}{\htmlData{mx=0}{r}(\htmlData{mx=1}{j})}} \mathrel{\htmlData{mx=4}{=}} 1 and ρ≠1\htmlData{mx=0}{\rho} \mathrel{\htmlData{mx=1}{\neq}} 1 (given Fintype⁡ J\htmlData{mx=2}{\htmlData{mx=0}{\operatorname{Fintype}}\,\htmlData{mx=1}{J}}), then

∀L∈N,(∑f:Fin⁡ L→J×Bool⁡(∏ir(f(i))1⋅({ρif f(i)21−ρotherwise))⋅foldr⁡(ofFn⁡(f))(z,tail↦1+{tailif z20otherwise,0))=1−ρL1−ρ∧(∑f:Fin⁡ L→J×Bool⁡(∏ir(f(i))1⋅({ρif f(i)21−ρotherwise))⋅foldr⁡(ofFn⁡(f))(z,tail↦{tailif z21otherwise,0))=1−ρL∧(∑f:Fin⁡ L→J×Bool⁡(∏ir(f(i))1⋅({ρif f(i)21−ρotherwise))⋅foldr⁡(ofFn⁡(f))(z,tail↦{tailif z20otherwise,1))=ρL\begin{aligned} & \htmlData{mx=0}{\forall} L \in \htmlData{mx=1}{\mathbb{N}}, \\ & \quad \left(\htmlData{mx=81}{\sum_{f : \htmlData{mx=45}{\htmlData{mx=43}{\operatorname{Fin}}\,\htmlData{mx=44}{L}} \mathrel{\htmlData{mx=49}{\to}} \htmlData{mx=48}{\htmlData{mx=46}{J} \times \htmlData{mx=47}{\operatorname{Bool}}}} \htmlData{mx=80}{\left(\htmlData{mx=65}{\prod_{i} \htmlData{mx=64}{\htmlData{mx=55}{\htmlData{mx=54}{\htmlData{mx=50}{r}(\htmlData{mx=53}{\htmlData{mx=51}{f}(\htmlData{mx=52}{i})})}_{1}} \cdot \left(\htmlData{mx=63}{\begin{cases} \htmlData{mx=56}{\rho} & \text{if } \htmlData{mx=60}{\htmlData{mx=59}{\htmlData{mx=57}{f}(\htmlData{mx=58}{i})}_{2}} \\ \htmlData{mx=62}{1 - \htmlData{mx=61}{\rho}} & \text{otherwise} \end{cases}}\right)}}\right) \cdot \htmlData{mx=79}{\htmlData{mx=72}{\operatorname{foldr}\left(\htmlData{mx=71}{\htmlData{mx=69}{\operatorname{ofFn}}(\htmlData{mx=70}{f})}\right)}\left(\htmlData{mx=78}{z, \mathit{tail} \mapsto \htmlData{mx=76}{1 + \htmlData{mx=75}{\begin{cases} \htmlData{mx=73}{\mathit{tail}} & \text{if } \htmlData{mx=74}{z_{2}} \\ 0 & \text{otherwise} \end{cases}}}}, 0\right)}}}\right) \\ & \quad \quad \htmlData{mx=3}{=} \htmlData{mx=88}{\frac{\htmlData{mx=85}{1 - \htmlData{mx=84}{\htmlData{mx=82}{\rho}^{\htmlData{mx=83}{L}}}}}{\htmlData{mx=87}{1 - \htmlData{mx=86}{\rho}}}} \\ & \quad \htmlData{mx=2}{\land} \left(\htmlData{mx=165}{\sum_{f : \htmlData{mx=130}{\htmlData{mx=128}{\operatorname{Fin}}\,\htmlData{mx=129}{L}} \mathrel{\htmlData{mx=134}{\to}} \htmlData{mx=133}{\htmlData{mx=131}{J} \times \htmlData{mx=132}{\operatorname{Bool}}}} \htmlData{mx=164}{\left(\htmlData{mx=150}{\prod_{i} \htmlData{mx=149}{\htmlData{mx=140}{\htmlData{mx=139}{\htmlData{mx=135}{r}(\htmlData{mx=138}{\htmlData{mx=136}{f}(\htmlData{mx=137}{i})})}_{1}} \cdot \left(\htmlData{mx=148}{\begin{cases} \htmlData{mx=141}{\rho} & \text{if } \htmlData{mx=145}{\htmlData{mx=144}{\htmlData{mx=142}{f}(\htmlData{mx=143}{i})}_{2}} \\ \htmlData{mx=147}{1 - \htmlData{mx=146}{\rho}} & \text{otherwise} \end{cases}}\right)}}\right) \cdot \htmlData{mx=163}{\htmlData{mx=157}{\operatorname{foldr}\left(\htmlData{mx=156}{\htmlData{mx=154}{\operatorname{ofFn}}(\htmlData{mx=155}{f})}\right)}\left(\htmlData{mx=162}{z, \mathit{tail} \mapsto \htmlData{mx=160}{\begin{cases} \htmlData{mx=158}{\mathit{tail}} & \text{if } \htmlData{mx=159}{z_{2}} \\ 1 & \text{otherwise} \end{cases}}}, 0\right)}}}\right) \\ & \quad \quad \htmlData{mx=89}{=} \htmlData{mx=169}{1 - \htmlData{mx=168}{\htmlData{mx=166}{\rho}^{\htmlData{mx=167}{L}}}} \\ & \quad \htmlData{mx=2}{\land} \left(\htmlData{mx=246}{\sum_{f : \htmlData{mx=211}{\htmlData{mx=209}{\operatorname{Fin}}\,\htmlData{mx=210}{L}} \mathrel{\htmlData{mx=215}{\to}} \htmlData{mx=214}{\htmlData{mx=212}{J} \times \htmlData{mx=213}{\operatorname{Bool}}}} \htmlData{mx=245}{\left(\htmlData{mx=231}{\prod_{i} \htmlData{mx=230}{\htmlData{mx=221}{\htmlData{mx=220}{\htmlData{mx=216}{r}(\htmlData{mx=219}{\htmlData{mx=217}{f}(\htmlData{mx=218}{i})})}_{1}} \cdot \left(\htmlData{mx=229}{\begin{cases} \htmlData{mx=222}{\rho} & \text{if } \htmlData{mx=226}{\htmlData{mx=225}{\htmlData{mx=223}{f}(\htmlData{mx=224}{i})}_{2}} \\ \htmlData{mx=228}{1 - \htmlData{mx=227}{\rho}} & \text{otherwise} \end{cases}}\right)}}\right) \cdot \htmlData{mx=244}{\htmlData{mx=238}{\operatorname{foldr}\left(\htmlData{mx=237}{\htmlData{mx=235}{\operatorname{ofFn}}(\htmlData{mx=236}{f})}\right)}\left(\htmlData{mx=243}{z, \mathit{tail} \mapsto \htmlData{mx=241}{\begin{cases} \htmlData{mx=239}{\mathit{tail}} & \text{if } \htmlData{mx=240}{z_{2}} \\ 0 & \text{otherwise} \end{cases}}}, 1\right)}}}\right) \\ & \quad \quad \htmlData{mx=170}{=} \htmlData{mx=249}{\htmlData{mx=247}{\rho}^{\htmlData{mx=248}{L}}} \end{aligned}
What the notation means · or point at any symbol
Type
Type: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Type)
Fintype
Fintype: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Fintype)
f(x)Function application
Fintype applied to J. Lean writes f x; papers write f(x). (Fintype J)
⟹Implies
If J, then ℝ. (Between types, A → B is the type of functions from A to B.) (J → ℝ)
∑Summation
Add up r(j) for every j. (∑ j, r j)
=Equality
∑ j, r(j) and 1 are the same. (∑ j, r j = 1)
≠Not equal
ρ and 1 are different. (ρ ≠ 1)
∀For all
The statement after the comma holds for every L. (∀ L : ℕ, (∑ f : Fin L → J × Bool, (∏ i,…)
RReal numbers
The real numbers: every point on the number line. (ℝ)
NNatural numbers
The natural numbers 0, 1, 2, …. In Lean they start at 0. (ℕ)
Fin
Fin: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Fin)
×Product
Pairs of an element of J and an element of Bool. (J × Bool)
Bool
Bool: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Bool)
∏Product
Multiply together r(f(i)).1 · ρ if f(i).2, else 1 − ρ for every i. (∏ i, r (f i).1 * (if (f i).2 then ρ els…)
p₁Component
Component 1 of r(f(i)) (the first). (r (f i).1)
·Multiplication
r(f(i)).1 times ρ if f(i).2, else 1 − ρ. (r (f i).1 * (if (f i).2 then ρ else 1 -…)
{ a if c; b otherwiseCases (if … then … else)
ρ when f(i).2, and 1 − ρ otherwise. (if (f i).2 then ρ else 1 - ρ)
-Subtraction
1 minus ρ. On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (1 - ρ)
e.ffoldr
foldr of ofFn(f): Lean's dot notation e.foldr means foldr applied to e. ((List.ofFn f).foldr)
ofFn
List.ofFn: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (List.ofFn)
x ↦ f(x)Function (λ-abstraction)
The function sending z, tail to 1 + tail if z.2, else 0. Lean writes fun x => …; papers write x ↦ …. (fun z (tail : ℝ) => 1 + if z.2 then tai…)
+Addition
1 plus tail if z.2, else 0. (1 + if z.2 then tail else 0)
a/bDivision
1 − ρ^L divided by 1 − ρ. In Lean, dividing by 0 gives 0. ((1 - ρ ^ L) / (1 - ρ))
aᵇPower
ρ raised to the power L. (ρ ^ L)
∧And
Both hold: (∑ f, (∏ i, r(f(i)).1 · ρ if f(i).2, else 1 − ρ) · foldr(o…, and (∑ f, (∏ i, r(f(i)).1 · ρ if f(i).2, else 1 − ρ) · foldr(o…. ((∑ f : Fin L → J × Bool, (∏ i, r (f i).…)

Defines folds counting sampled keys, terminal sampled values and dense completion on the same finite product paths. Derives their exact weighted expectations; normalization is assumed through sum r=1. Probability nonnegativity and variance are established by the separate history target. No hardware traffic or latency claim.

How it was proved

Proved
6 October 2026
By
Ajax
Checked by
Lean's kernel (Lean 4.33.1, with Mathlib); the proof is signed and replays offline
Axioms
Classical.choice, Quot.sound, propext
Proof
57 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.

More proved statements