File size: 8,021 Bytes
2f887db | 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | import Lean.Elab.Tactic.Omega
import OAI.Computability.PerfectCompleteness.Foundations.HierarchicalFrozenTablesLemmas
namespace OAI
section
namespace PerfectCompleteness.GeometricPrefixSplit
open RecursiveSpaces DescendantSpaces
open GeometricCutSplit (Prefix PrefixDepth prefixPathDepth prefixPath castPath prefixLaw)
open UniqueGamesTheorem.Foundations.Games
open scoped BigOperators Classical
variable {branch : Nat → Nat}
def depthEquiv (low b : Nat) : (a : Nat) →
PrefixDepth branch low (b + a) ≃
PrefixDepth branch (low + b) a × PrefixDepth branch low b
| 0 =>
{ toFun := fun x => ((), x)
invFun := Prod.snd
left_inv := fun _ => rfl
right_inv := by rintro ⟨⟨⟩, x⟩; rfl }
| a + 1 =>
((Equiv.cast (congrArg (fun h => Fin (branch h))
(Nat.add_assoc low b a).symm)).prodCongr (depthEquiv low b a)).trans
(Equiv.prodAssoc _ _ _).symm
private theorem castPath_step {x y low : Nat} (h : x = y)
(c : Fin (branch x)) (p : Path branch x low) :
castPath (congrArg Nat.succ h) (.step c p) =
.step (Equiv.cast (congrArg (fun n => Fin (branch n)) h) c)
(castPath h p) := by
cases h
rfl
theorem depthEquiv_path (low b a : Nat)
(x : PrefixDepth branch low (b + a)) :
castPath (Nat.add_assoc low b a).symm (prefixPathDepth low (b + a) x) =
(prefixPathDepth (low + b) a (depthEquiv low b a x).1).append
(prefixPathDepth low b (depthEquiv low b a x).2) := by
revert x
induction a with
| zero => intro x; rfl
| succ a ih =>
intro x
change castPath (congrArg Nat.succ (Nat.add_assoc low b a).symm)
(.step x.1 (prefixPathDepth low (b + a) x.2)) = _
rw [castPath_step (Nat.add_assoc low b a).symm x.1
(prefixPathDepth low (b + a) x.2)]
exact congrArg (Path.step _) (ih x.2)
private theorem castPath_trans {x y z low : Nat} (h : x = y) (g : y = z)
(p : Path branch x low) :
castPath g (castPath h p) = castPath (h.trans g) p := by
cases h
cases g
rfl
private theorem prefixPathDepth_cast {low d e : Nat} (h : d = e)
(x : PrefixDepth branch low d) :
prefixPathDepth low e (Equiv.cast (congrArg (PrefixDepth branch low) h) x) =
castPath (congrArg (fun n => low + n) h) (prefixPathDepth low d x) := by
cases h
rfl
private theorem castPath_append {x y mid low : Nat} (h : x = y)
(p : Path branch x mid) (q : Path branch mid low) :
castPath h (p.append q) = (castPath h p).append q := by
cases h
rfl
private theorem castPath_depth_append {x y low : Nat} (h : x = y) (a : Nat)
(upper : PrefixDepth branch x a) (lower : Path branch x low) :
castPath (congrArg (fun n => n + a) h)
((prefixPathDepth x a upper).append lower) =
(prefixPathDepth y a
(Equiv.cast (congrArg (fun n => PrefixDepth branch n a) h) upper)).append
(castPath h lower) := by
cases h
rfl
variable {root mid low : Nat}
def splitEquiv (hlow : low ≤ mid) (hmid : mid ≤ root) :
Prefix branch root low ≃ Prefix branch root mid × Prefix branch mid low :=
(Equiv.cast (congrArg (PrefixDepth branch low)
(show root - low = (mid - low) + (root - mid) by omega))).trans
((depthEquiv low (mid - low) (root - mid)).trans
((Equiv.cast (congrArg (fun n => PrefixDepth branch n (root - mid))
(Nat.add_sub_of_le hlow))).prodCongr (Equiv.refl _)))
def joinEquiv (hlow : low ≤ mid) (hmid : mid ≤ root) :
Prefix branch root mid × Prefix branch mid low ≃ Prefix branch root low :=
(splitEquiv hlow hmid).symm
@[simp] theorem split_join (hlow : low ≤ mid) (hmid : mid ≤ root)
(pair : Prefix branch root mid × Prefix branch mid low) :
splitEquiv hlow hmid (joinEquiv hlow hmid pair) = pair :=
(splitEquiv hlow hmid).apply_symm_apply pair
@[simp] theorem join_split (hlow : low ≤ mid) (hmid : mid ≤ root)
(pref : Prefix branch root low) :
joinEquiv hlow hmid (splitEquiv hlow hmid pref) = pref :=
(splitEquiv hlow hmid).symm_apply_apply pref
theorem prefixPath_split (hlow : low ≤ mid) (hmid : mid ≤ root)
(pref : Prefix branch root low) :
prefixPath (hlow.trans hmid) pref =
(prefixPath hmid (splitEquiv hlow hmid pref).1).append
(prefixPath hlow (splitEquiv hlow hmid pref).2) := by
let a := root - mid
let b := mid - low
have hd : root - low = b + a := by dsimp [a, b]; omega
have hm : low + b = mid := Nat.add_sub_of_le hlow
let x : PrefixDepth branch low (b + a) :=
Equiv.cast (congrArg (PrefixDepth branch low) hd) pref
calc
prefixPath (hlow.trans hmid) pref =
castPath (Nat.add_sub_of_le hmid)
(castPath (congrArg (fun n => n + a) hm)
(castPath (Nat.add_assoc low b a).symm
(prefixPathDepth low (b + a) x))) := by
dsimp only [x]
rw [prefixPathDepth_cast hd pref]
simp only [castPath_trans]
rfl
_ = castPath (Nat.add_sub_of_le hmid)
(castPath (congrArg (fun n => n + a) hm)
((prefixPathDepth (low + b) a (depthEquiv low b a x).1).append
(prefixPathDepth low b (depthEquiv low b a x).2))) := by
rw [depthEquiv_path]
_ = castPath (Nat.add_sub_of_le hmid)
((prefixPathDepth mid a
(Equiv.cast (congrArg (fun n => PrefixDepth branch n a) hm)
(depthEquiv low b a x).1)).append
(castPath hm (prefixPathDepth low b (depthEquiv low b a x).2))) := by
rw [castPath_depth_append]
_ = (prefixPath hmid (splitEquiv hlow hmid pref).1).append
(prefixPath hlow (splitEquiv hlow hmid pref).2) := by
rw [castPath_append]
rfl
theorem prefixPath_split_spec (hlow : low ≤ mid) (hmid : mid ≤ root)
(pref : Prefix branch root low) :
(⟨low, prefixPath (hlow.trans hmid) pref⟩ : Σ height, Path branch root height) =
⟨low, (prefixPath hmid (splitEquiv hlow hmid pref).1).append
(prefixPath hlow (splitEquiv hlow hmid pref).2)⟩ :=
congrArg (fun p : Path branch root low =>
(⟨low, p⟩ : Σ height, Path branch root height)) (prefixPath_split hlow hmid pref)
theorem prefixPath_join (hlow : low ≤ mid) (hmid : mid ≤ root)
(upper : Prefix branch root mid) (lower : Prefix branch mid low) :
prefixPath (hlow.trans hmid) (joinEquiv hlow hmid (upper, lower)) =
(prefixPath hmid upper).append (prefixPath hlow lower) := by
simpa only [split_join] using
prefixPath_split hlow hmid (joinEquiv hlow hmid (upper, lower))
noncomputable section
theorem law_split (hlow : low ≤ mid) (hmid : mid ≤ root)
(hbranch : ∀ k < root, 0 < branch k) :
(prefixLaw (hlow.trans hmid) hbranch).pushforward (splitEquiv hlow hmid) =
(prefixLaw hmid hbranch).product
(prefixLaw hlow (fun k hk => hbranch k (Nat.lt_of_lt_of_le hk hmid))) := by
rw [← FiniteDistribution.transport_eq_pushforward]
apply FiniteDistribution.eq_of_weight_eq
intro pair
change (1 : ℝ) / (Fintype.card (Prefix branch root low) : ℝ) =
((1 : ℝ) / (Fintype.card (Prefix branch root mid) : ℝ)) *
((1 : ℝ) / (Fintype.card (Prefix branch mid low) : ℝ))
rw [Fintype.card_congr (splitEquiv (branch := branch) hlow hmid),
Fintype.card_prod, Nat.cast_mul]
simp only [one_div_mul_one_div]
theorem expectation_split (hlow : low ≤ mid) (hmid : mid ≤ root)
(hbranch : ∀ k < root, 0 < branch k)
(f : Prefix branch root mid → Prefix branch mid low → ℝ) :
(prefixLaw (hlow.trans hmid) hbranch).expectation
(fun pref => f (splitEquiv hlow hmid pref).1 (splitEquiv hlow hmid pref).2) =
(prefixLaw hmid hbranch).expectation (fun upper =>
(prefixLaw hlow (fun k hk => hbranch k (Nat.lt_of_lt_of_le hk hmid))).expectation
(f upper)) := by
rw [← FiniteDistribution.expectation_pushforward
(prefixLaw (hlow.trans hmid) hbranch) (splitEquiv hlow hmid)
(fun pair => f pair.1 pair.2), law_split, FiniteDistribution.expectation_product]
end
end PerfectCompleteness.GeometricPrefixSplit
end
end OAI
|