proofs
Provedunbiased-gradientscounterexamplereview-response

Counterexample: reusing the forward samples in the backward pass biases the gradient: E[ô·d̂] = p(1−p)/2, but the dense gradient is p²(1−p) (3/32 vs 3/64 at p = 1/4)

For all p∈R\htmlData{mx=1}{p \in \htmlData{mx=0}{\mathbb{R}}}:

(∑x:Bool⁡×Bool⁡({pif x11−potherwise)⋅({pif x21−potherwise)⋅(({1if x10otherwise)+({1if x20otherwise)2)=p)∧(∑x:Bool⁡×Bool⁡({pif x11−potherwise)⋅({pif x21−potherwise)⋅((({1if x10otherwise)−({1if x20otherwise))22)=p⋅(1−p))∧(∑x:Bool⁡×Bool⁡({pif x11−potherwise)⋅({pif x21−potherwise)⋅(({1if x10otherwise)+({1if x20otherwise)2⋅((({1if x10otherwise)−({1if x20otherwise))22))=p⋅(1−p)2)∧(p=14  ⟹  p⋅(1−p)2=332∧p2⋅(1−p)=364)\begin{aligned} & \left(\right. \htmlData{mx=24}{\sum_{x : \htmlData{mx=4}{\htmlData{mx=2}{\operatorname{Bool}} \times \htmlData{mx=3}{\operatorname{Bool}}}} \htmlData{mx=23}{\htmlData{mx=15}{\left(\htmlData{mx=9}{\begin{cases} \htmlData{mx=5}{p} & \text{if } \htmlData{mx=6}{x_{1}} \\ \htmlData{mx=8}{1 - \htmlData{mx=7}{p}} & \text{otherwise} \end{cases}}\right) \cdot \left(\htmlData{mx=14}{\begin{cases} \htmlData{mx=10}{p} & \text{if } \htmlData{mx=11}{x_{2}} \\ \htmlData{mx=13}{1 - \htmlData{mx=12}{p}} & \text{otherwise} \end{cases}}\right)} \cdot \left(\htmlData{mx=22}{\frac{\htmlData{mx=21}{\left(\htmlData{mx=18}{\begin{cases} \htmlData{mx=16}{1} & \text{if } \htmlData{mx=17}{x_{1}} \\ 0 & \text{otherwise} \end{cases}}\right) + \left(\htmlData{mx=20}{\begin{cases} 1 & \text{if } \htmlData{mx=19}{x_{2}} \\ 0 & \text{otherwise} \end{cases}}\right)}}{2}}\right)}} \\ & \quad \htmlData{mx=1}{=} \htmlData{mx=25}{p} \left.\right) \\ & \htmlData{mx=0}{\land} \left(\right. \htmlData{mx=50}{\sum_{x : \htmlData{mx=29}{\htmlData{mx=27}{\operatorname{Bool}} \times \htmlData{mx=28}{\operatorname{Bool}}}} \htmlData{mx=49}{\htmlData{mx=40}{\left(\htmlData{mx=34}{\begin{cases} \htmlData{mx=30}{p} & \text{if } \htmlData{mx=31}{x_{1}} \\ \htmlData{mx=33}{1 - \htmlData{mx=32}{p}} & \text{otherwise} \end{cases}}\right) \cdot \left(\htmlData{mx=39}{\begin{cases} \htmlData{mx=35}{p} & \text{if } \htmlData{mx=36}{x_{2}} \\ \htmlData{mx=38}{1 - \htmlData{mx=37}{p}} & \text{otherwise} \end{cases}}\right)} \cdot \left(\htmlData{mx=48}{\frac{\htmlData{mx=47}{\left(\htmlData{mx=46}{\left(\htmlData{mx=43}{\begin{cases} \htmlData{mx=41}{1} & \text{if } \htmlData{mx=42}{x_{1}} \\ 0 & \text{otherwise} \end{cases}}\right) - \left(\htmlData{mx=45}{\begin{cases} 1 & \text{if } \htmlData{mx=44}{x_{2}} \\ 0 & \text{otherwise} \end{cases}}\right)}\right)^{2}}}{2}}\right)}} \\ & \quad \htmlData{mx=26}{=} \htmlData{mx=54}{\htmlData{mx=51}{p} \cdot (\htmlData{mx=53}{1 - \htmlData{mx=52}{p}})} \left.\right) \\ & \htmlData{mx=0}{\land} \left(\right. \htmlData{mx=87}{\sum_{x : \htmlData{mx=58}{\htmlData{mx=56}{\operatorname{Bool}} \times \htmlData{mx=57}{\operatorname{Bool}}}} \htmlData{mx=86}{\htmlData{mx=69}{\left(\htmlData{mx=63}{\begin{cases} \htmlData{mx=59}{p} & \text{if } \htmlData{mx=60}{x_{1}} \\ \htmlData{mx=62}{1 - \htmlData{mx=61}{p}} & \text{otherwise} \end{cases}}\right) \cdot \left(\htmlData{mx=68}{\begin{cases} \htmlData{mx=64}{p} & \text{if } \htmlData{mx=65}{x_{2}} \\ \htmlData{mx=67}{1 - \htmlData{mx=66}{p}} & \text{otherwise} \end{cases}}\right)} \cdot \left(\htmlData{mx=85}{\htmlData{mx=76}{\frac{\htmlData{mx=75}{\left(\htmlData{mx=72}{\begin{cases} \htmlData{mx=70}{1} & \text{if } \htmlData{mx=71}{x_{1}} \\ 0 & \text{otherwise} \end{cases}}\right) + \left(\htmlData{mx=74}{\begin{cases} 1 & \text{if } \htmlData{mx=73}{x_{2}} \\ 0 & \text{otherwise} \end{cases}}\right)}}{2}} \cdot \left(\htmlData{mx=84}{\frac{\htmlData{mx=83}{\left(\htmlData{mx=82}{\left(\htmlData{mx=79}{\begin{cases} \htmlData{mx=77}{1} & \text{if } \htmlData{mx=78}{x_{1}} \\ 0 & \text{otherwise} \end{cases}}\right) - \left(\htmlData{mx=81}{\begin{cases} 1 & \text{if } \htmlData{mx=80}{x_{2}} \\ 0 & \text{otherwise} \end{cases}}\right)}\right)^{2}}}{2}}\right)}\right)}} \\ & \quad \htmlData{mx=55}{=} \htmlData{mx=92}{\frac{\htmlData{mx=91}{\htmlData{mx=88}{p} \cdot (\htmlData{mx=90}{1 - \htmlData{mx=89}{p}})}}{2}} \left.\right) \\ & \htmlData{mx=0}{\land} \left(\htmlData{mx=93}{p} \mathrel{\htmlData{mx=95}{=}} \htmlData{mx=94}{\frac{1}{4}} \mathrel{\htmlData{mx=111}{\implies}} \htmlData{mx=100}{\frac{\htmlData{mx=99}{\htmlData{mx=96}{p} \cdot (\htmlData{mx=98}{1 - \htmlData{mx=97}{p}})}}{2}} \mathrel{\htmlData{mx=102}{=}} \htmlData{mx=101}{\frac{3}{32}} \mathbin{\htmlData{mx=110}{\land}} \htmlData{mx=107}{\htmlData{mx=104}{\htmlData{mx=103}{p}^{2}} \cdot (\htmlData{mx=106}{1 - \htmlData{mx=105}{p}})} \mathrel{\htmlData{mx=109}{=}} \htmlData{mx=108}{\frac{3}{64}}\right) \end{aligned}
What the notation means · or point at any symbol
RReal numbers
The real numbers: every point on the number line. (ℝ)
∑Summation
Add up p if x.1, else 1 − p · p if x.2, else 1 − p · ((1 if x.1, … for every x in Bool × Bool. (∑ x : Bool × Bool, (if x.1 then p else …)
=Equality
∑ x, p if x.1, else 1 − p · p if x.2, else 1 − p · ((1 if … and p are the same. (∑ x : Bool × Bool, (if x.1 then p else …)
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
Pairs of an element of Bool and an element of Bool. (Bool × Bool)
·Multiplication
p if x.1, else 1 − p times p if x.2, else 1 − p. ((if x.1 then p else 1 - p) * (if x.2 th…)
{ a if c; b otherwiseCases (if … then … else)
p when x.1, and 1 − p otherwise. (if x.1 then p else 1 - p)
p₁Component
The first component of the pair x. (x.1)
-Subtraction
1 minus p. On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (1 - p)
a/bDivision
1 if x.1, else 0 + 1 if x.2, else 0 divided by 2. In Lean, dividing by 0 gives 0. (((if x.1 then (1 : ℝ) else 0) + (if x.2…)
+Addition
1 if x.1, else 0 plus 1 if x.2, else 0. ((if x.1 then (1 : ℝ) else 0) + (if x.2 …)
(x : T)As real numbers
1 read as an element of real numbers. Mathematicians leave this implicit; Lean needs it to know which kind of number is meant. ((1 : ℝ))
aᵇPower
1 if x.1, else 0 − 1 if x.2, else 0 raised to the power 2. (((if x.1 then (1 : ℝ) else 0) - (if x.2…)
⟹Implies
If p = 1/4, then p · (1 − p)/2 = 3/32 ∧ p^2 · (1 − p) = 3/64. (Between types, A → B is the type of functions from A to B.) (p = 1 / 4 → p * (1 - p) / 2 = 3 / 32 ∧ …)
∧And
Both hold: p · (1 − p)/2 = 3/32, and p^2 · (1 − p) = 3/64. (p * (1 - p) / 2 = 3 / 32 ∧ p ^ 2 * (1 -…)

Two keys with scores (0, θ), values (0, 1), loss ℓ(o) = o²/2, so o = p = σ(θ) and the dense gradient is p²(1−p). Two exact samples X₁, X₂ ~ Bernoulli(p): the forward estimate ô = (X₁+X₂)/2 is unbiased, the local derivative estimate d̂ = (X₁−X₂)²/2 is unbiased for p(1−p), but their product has mean p(1−p)/2, twice the dense gradient at p = 1/4. Unbiased forward and local-derivative estimates do not give an unbiased gradient of the dense loss when the upstream derivative depends on the same samples. Counterexample supplied by an external review (2026-10-05); it bounds the scope of op-one-pass-gradient-unbiased (fixed upstream vector).

How it was proved

Proved
5 October 2026
By
Ajax, with the agent “Baguette math & proofs (Claude Code, 2026-10-03)”
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
16 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.

More proved statements