roseking's picture
Add lean source and binary files (part 120)
f205175 verified
Raw History Blame Contribute Delete
1.86 kB
import OAI.Probability.CubeShuffle.Basic
namespace OAI
namespace CubeShuffle.QueryTree
open scoped BigOperators
variable {ι : Type*} [DecidableEq ι]
/-- Flipping one bit is a permutation of the uniform coin space. -/
def flipCoin (i : ι) : Equiv.Perm (ι → Bool) :=
(show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by
intro ω
funext j
by_cases h : j = i
· subst j; simp
· simp [Function.update_of_ne h]).toPerm
lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by
change Function.update ω i (!(ω i)) i = _
exact Function.update_self _ _ _
lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) :
flipCoin i ω j = ω j := by
change Function.update ω i (!(ω i)) j = _
exact Function.update_of_ne h _ _
/-- Half the uniform coin assignments have a specified bit, independently of
any function which does not inspect that bit. This remains valid for adaptive
functions of all the remaining bits. -/
lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool)
(hf : ∀ ω, f (flipCoin i ω) = f ω) :
finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by
let g := fun ω : ι → Bool => if ω i = b then f ω else 0
have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by
dsimp [g]
rw [flipCoin_apply_eq, hf]
cases hω : ω i <;> cases b <;> simp
have hs := Equiv.sum_comp (flipCoin i) g
have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by
rw [← Finset.sum_add_distrib]
exact Finset.sum_congr rfl (fun ω _ => hp ω)
unfold finiteMean
change (∑ ω, g ω) / _ = _
rw [hs] at hadd
have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith
rw [hh]
ring
end CubeShuffle.QueryTree
end OAI