File size: 4,147 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | import Mathlib
namespace OAI
/-!
# Finite cut hashes and averaged separation
-/
namespace EditCutHash
attribute [local instance] Classical.propDecidable
open scoped BigOperators
open Finset
noncomputable def sep {X : Type*} (x y : X) : β := if x = y then 0 else 1
lemma sep_nonneg {X : Type*} (x y : X) : 0 β€ sep x y := by unfold sep; split <;> norm_num
lemma sep_le_one {X : Type*} (x y : X) : sep x y β€ 1 := by unfold sep; split <;> norm_num
@[simp] lemma sep_self {X : Type*} (x : X) : sep x x = 0 := by simp [sep]
lemma sep_eq_one {X : Type*} {x y : X} (h : x β y) : sep x y = 1 := by simp [sep,h]
section Hash
variable {I X : Type*} [Fintype I]
noncomputable def distance (w : I β β) (c : I β X β Bool) (x y : X) : β :=
β i, w i * sep (c i x) (c i y)
lemma distance_nonneg {w : I β β} (hw : β i, 0 β€ w i) (c : I β X β Bool) (x y : X) :
0 β€ distance w c x y := sum_nonneg (fun i _ => mul_nonneg (hw i) (sep_nonneg _ _))
noncomputable def coin (w : I β β) (a : β) (i : I) (b : Bool) : β :=
if b then 1-Real.exp (-a*w i) else Real.exp (-a*w i)
noncomputable def probability (w : I β β) (a : β) (h : I β Bool) : β :=
β i, coin w a i (h i)
def key (c : I β X β Bool) (h : I β Bool) (x : X) : I β Bool :=
fun i => h i && c i x
omit [Fintype I] in
lemma coin_sum (w : I β β) (a : β) (i : I) : β b : Bool, coin w a i b = 1 := by
simp [coin]
lemma probability_nonneg {w : I β β} (hw : β i, 0 β€ w i) {a : β} (ha : 0 β€ a)
(h : I β Bool) : 0 β€ probability w a h := by
apply prod_nonneg
intro i _
unfold coin
split
Β· have hb : Real.exp (-a*w i) β€ 1 := Real.exp_le_one_iff.mpr (by nlinarith [hw i])
linarith
Β· exact (Real.exp_pos _).le
lemma probability_sum (w : I β β) (a : β) : β h : I β Bool, probability w a h = 1 := by
classical
unfold probability
rw [βFintype.prod_sum]
simp only [coin_sum,prod_const_one]
lemma collision_indicator (c : I β X β Bool) (h : I β Bool) (x y : X) :
(if key c h x = key c h y then (1 : β) else 0) =
β i, if (h i && c i x) = (h i && c i y) then (1 : β) else 0 := by
classical
by_cases he : key c h x = key c h y
Β· rw [ite_eq_left he]
have hh (i : I) : (h i && c i x) = (h i && c i y) := congrFun he i
simp only [hh,ite_true,prod_const_one]
Β· rw [ite_eq_right he]
have hex : β i, (h i && c i x) β (h i && c i y) := by
by_contra hn
push Not at hn
exact he (funext hn)
obtain β¨i,hiβ© := hex
symm
exact prod_eq_zero (mem_univ i) (ite_eq_right hi)
theorem collision_probability (w : I β β) (a : β) (c : I β X β Bool) (x y : X) :
(β h : I β Bool, probability w a h *
if key c h x = key c h y then (1 : β) else 0) = Real.exp (-a*distance w c x y) := by
classical
simp_rw [collision_indicator,probability,βprod_mul_distrib]
rw [βFintype.prod_sum (fun (i : I) (b : Bool) => coin w a i b *
(if (b && c i x) = (b && c i y) then (1 : β) else 0))]
have hf (i : I) : (β b : Bool, coin w a i b *
if (b && c i x) = (b && c i y) then (1 : β) else 0) =
Real.exp (-a*(w i*sep (c i x) (c i y))) := by
cases hx : c i x <;> cases hy : c i y <;> simp [coin,sep]
simp_rw [hf]
rw [βReal.exp_sum]
congr 1
simp only [distance,mul_sum]
lemma separation_probability (w : I β β) (a : β) (c : I β X β Bool) (x y : X) :
(β h : I β Bool, probability w a h * sep (key c h x) (key c h y)) =
1-Real.exp (-a*distance w c x y) := by
classical
have hs (h : I β Bool) : sep (key c h x) (key c h y) =
1-(if key c h x = key c h y then (1 : β) else 0) := by
unfold sep
split <;> norm_num
simp_rw [hs,mul_sub,mul_one]
rw [sum_sub_distrib,probability_sum,collision_probability]
lemma separation_bound (w : I β β) (a : β) (c : I β X β Bool) (x y : X) :
(β h : I β Bool, probability w a h * sep (key c h x) (key c h y)) β€
a*distance w c x y := by
rw [separation_probability]
have hh := Real.add_one_le_exp (-a*distance w c x y)
linarith
end Hash
end EditCutHash
end OAI
|