File size: 15,145 Bytes
cdec422 | 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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | import Mathlib.Analysis.Convex.Function
import Mathlib.Analysis.Convex.Topology
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.SpecialFunctions.Log.Basic
import Mathlib.Topology.Order.Monotone
import Mathlib.Topology.Semicontinuity.Basic
import Mathlib.Topology.Instances.Real.Lemmas
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
namespace OAI
/-! Finite entropy, rate estimates and ordered asymptotic limits. -/
noncomputable section
open Set Filter
open scoped Topology BigOperators
namespace MatrixMultiplication.Foundation
theorem unitInterval_subset_closure_rat :
Icc (0 : ℝ) 1 ⊆ closure (((↑) : ℚ → ℝ) '' Icc 0 1) := by
have hinterior : Ioo (0 : ℝ) 1 ⊆ closure (((↑) : ℚ → ℝ) '' Icc 0 1) := by
intro x hx
rw [mem_closure_iff]
intro U hU hxU
obtain ⟨z, hz, hzrat⟩ := Rat.denseRange_cast.inter_open_nonempty
(U ∩ Ioo (0 : ℝ) 1) (hU.inter isOpen_Ioo) ⟨x, hxU, hx⟩
obtain ⟨q, rfl⟩ := hzrat
refine ⟨(q : ℝ), hz.1, q, ?_, rfl⟩
constructor
· exact Rat.cast_nonneg.mp hz.2.1.le
· exact Rat.cast_le.mp (by simpa using hz.2.2.le)
have hclosed := closure_minimal hinterior isClosed_closure
simpa only [closure_Ioo (show (0 : ℝ) ≠ 1 by norm_num)] using hclosed
structure FiniteConstructionRates where
occurrences : ℕ
multiplicity : ℕ
auxiliaryRank : ℕ
volume : ℕ
occurrences_pos : 0 < occurrences
multiplicity_pos : 0 < multiplicity
auxiliaryRank_pos : 0 < auxiliaryRank
volume_pos : 0 < volume
def FiniteConstructionRates.score (r : FiniteConstructionRates) (β : ℝ) : ℝ :=
(Real.log r.multiplicity - Real.log r.auxiliaryRank +
(β / 3) * Real.log r.volume) / r.occurrences
structure AttainableFamily (C X : Type*) where
law : C → X
score : C → ℝ
def finiteConstructionFamily {C X : Type*} (β : ℝ) (law : C → X)
(rates : C → FiniteConstructionRates) : AttainableFamily C X :=
⟨law, fun c => (rates c).score β⟩
namespace AttainableFamily
variable {C X : Type*} [TopologicalSpace X] (A : AttainableFamily C X)
def pairs : Set (X × ℝ) :=
{p | ∃ c, A.law c = p.1 ∧ p.2 ≤ A.score c}
def closedPairs : Set (X × ℝ) := closure A.pairs
def fiber (x : X) : Set ℝ := {t | (x, t) ∈ A.closedPairs}
def value (x : X) : ℝ := sSup (A.fiber x)
theorem finite_mem_closedPairs (c : C) : (A.law c, A.score c) ∈ A.closedPairs :=
subset_closure ⟨c, rfl, le_rfl⟩
theorem closedPairs_law_mem_of_isClosed {s : Set X} (hs : IsClosed s)
(hlaw : ∀ c, A.law c ∈ s) : ∀ p ∈ A.closedPairs, p.1 ∈ s := by
apply closure_minimal
· rintro p ⟨c, hc, _⟩
change p.1 ∈ s
rw [← hc]
exact hlaw c
· exact hs.preimage continuous_fst
theorem closedPairs_downward {x : X} {u v : ℝ}
(hu : (x, u) ∈ A.closedPairs) (hvu : v ≤ u) :
(x, v) ∈ A.closedPairs := by
let T : X × ℝ → X × ℝ := fun p => (p.1, p.2 - (u - v))
have hT : Continuous T :=
continuous_fst.prodMk (continuous_snd.sub continuous_const)
have himage : T '' A.pairs ⊆ A.pairs := by
rintro _ ⟨p, ⟨c, hc, hscore⟩, rfl⟩
exact ⟨c, hc, by dsimp [T]; linarith⟩
have hmem : T (x, u) ∈ closure (T '' A.pairs) :=
image_closure_subset_closure_image hT ⟨(x, u), hu, rfl⟩
have := closure_mono himage hmem
simpa [T, closedPairs] using this
theorem isClosed_fiber (x : X) : IsClosed (A.fiber x) :=
isClosed_closure.preimage (continuous_const.prodMk continuous_id)
theorem value_mem_closedPairs (x : X) (hne : (A.fiber x).Nonempty)
(hbound : BddAbove (A.fiber x)) : (x, A.value x) ∈ A.closedPairs :=
(A.isClosed_fiber x).csSup_mem hne hbound
theorem mem_closedPairs_iff_le_value (x : X) (hne : (A.fiber x).Nonempty)
(hbound : BddAbove (A.fiber x)) (t : ℝ) :
(x, t) ∈ A.closedPairs ↔ t ≤ A.value x := by
constructor
· exact fun ht => le_csSup hbound ht
· exact fun ht => A.closedPairs_downward (A.value_mem_closedPairs x hne hbound) ht
theorem closedPairs_le_continuous_cap (H : X → ℝ) (hH : Continuous H)
(hcap : ∀ c, A.score c ≤ H (A.law c)) :
∀ p ∈ A.closedPairs, p.2 ≤ H p.1 := by
apply closure_minimal
· rintro p ⟨c, hc, ht⟩
exact ht.trans (hc ▸ hcap c)
· exact isClosed_le continuous_snd (hH.comp continuous_fst)
theorem value_le_continuous_cap (H : X → ℝ) (hH : Continuous H)
(hcap : ∀ c, A.score c ≤ H (A.law c)) (x : X)
(hne : (A.fiber x).Nonempty) : A.value x ≤ H x :=
csSup_le hne (fun _ ht => A.closedPairs_le_continuous_cap H hH hcap _ ht)
theorem value_nonneg (x : X) (hzero : (x, 0) ∈ A.closedPairs)
(hbound : BddAbove (A.fiber x)) : 0 ≤ A.value x :=
le_csSup hbound hzero
theorem upperSemicontinuous_value
(hne : ∀ x, (A.fiber x).Nonempty) (hbound : ∀ x, BddAbove (A.fiber x)) :
UpperSemicontinuous A.value := by
intro x b hb
have hnot : (x, b) ∉ A.closedPairs := by
intro hmem
exact (not_le_of_gt hb)
((A.mem_closedPairs_iff_le_value x (hne x) (hbound x) b).mp hmem)
have hclosed : IsClosed {y : X | (y, b) ∈ A.closedPairs} :=
isClosed_closure.preimage (continuous_id.prodMk continuous_const)
have hnear : ∀ᶠ y in 𝓝 x, (y, b) ∉ A.closedPairs :=
hclosed.isOpen_compl.mem_nhds hnot
filter_upwards [hnear] with y hy
exact lt_of_not_ge (fun hle =>
hy ((A.mem_closedPairs_iff_le_value y (hne y) (hbound y) b).mpr hle))
theorem upperSemicontinuous_value_comp {Y : Type*} [TopologicalSpace Y]
(α : Y → X) (hα : Continuous α)
(hne : ∀ y, (A.fiber (α y)).Nonempty)
(hbound : ∀ y, BddAbove (A.fiber (α y))) :
UpperSemicontinuous (fun y => A.value (α y)) := by
intro y b hb
have hnot : (α y, b) ∉ A.closedPairs := by
intro hmem
exact (not_le_of_gt hb)
((A.mem_closedPairs_iff_le_value (α y) (hne y) (hbound y) b).mp hmem)
have hclosed : IsClosed {z : Y | (α z, b) ∈ A.closedPairs} :=
isClosed_closure.preimage (hα.prodMk continuous_const)
have hnear : ∀ᶠ z in 𝓝 y, (α z, b) ∉ A.closedPairs :=
hclosed.isOpen_compl.mem_nhds hnot
filter_upwards [hnear] with z hz
exact lt_of_not_ge (fun hle =>
hz ((A.mem_closedPairs_iff_le_value (α z) (hne z) (hbound z) b).mpr hle))
theorem exists_finite_in_open_gt {x : X} {b : ℝ} (hne : (A.fiber x).Nonempty)
(hb : b < A.value x) {U : Set X} (hU : IsOpen U) (hx : x ∈ U) :
∃ c, A.law c ∈ U ∧ b < A.score c := by
obtain ⟨t, ht, hbt⟩ := exists_lt_of_lt_csSup hne hb
have hopen : IsOpen (U ×ˢ Ioi b) := hU.prod isOpen_Ioi
obtain ⟨p, hpU, hpA⟩ := mem_closure_iff.mp ht (U ×ˢ Ioi b) hopen ⟨hx, hbt⟩
obtain ⟨c, hc, hscore⟩ := hpA
refine ⟨c, hc.symm ▸ hpU.1, lt_of_lt_of_le hpU.2 hscore⟩
theorem exists_finite_gt {x : X} {b : ℝ} (hne : (A.fiber x).Nonempty)
(hb : b < A.value x) : ∃ c, b < A.score c := by
obtain ⟨c, _, hc⟩ := A.exists_finite_in_open_gt hne hb isOpen_univ (mem_univ x)
exact ⟨c, hc⟩
section Concavity
variable [AddCommGroup X] [Module ℝ X]
theorem concaveOn_value (s : Set X) (hs : Convex ℝ s)
(hne : ∀ x ∈ s, (A.fiber x).Nonempty)
(hbound : ∀ x ∈ s, BddAbove (A.fiber x))
(hmix : Convex ℝ A.closedPairs) : ConcaveOn ℝ s A.value := by
refine ⟨hs, ?_⟩
intro x hx y hy a b ha hb hab
have hpair := hmix (A.value_mem_closedPairs x (hne x hx) (hbound x hx))
(A.value_mem_closedPairs y (hne y hy) (hbound y hy)) ha hb hab
exact le_csSup (hbound _ (hs hx hy ha hb hab)) hpair
end Concavity
section RationalMixtures
variable [AddCommGroup X] [Module ℝ X] [ContinuousAdd X] [ContinuousSMul ℝ X]
theorem closedPairs_convex_of_rational_mixing
(hmix : ∀ c d : C, ∀ q : ℚ, q ∈ Icc 0 1 →
(q : ℝ) • (A.law c, A.score c) +
(1 - (q : ℝ)) • (A.law d, A.score d) ∈ A.pairs) :
Convex ℝ A.closedPairs := by
have hfull : ∀ c d : C, ∀ t : ℝ, t ∈ Icc 0 1 →
t • (A.law c, A.score c) + (1 - t) • (A.law d, A.score d) ∈
A.closedPairs := by
intro c d t ht
let T : ℝ → X × ℝ := fun u =>
u • (A.law c, A.score c) + (1 - u) • (A.law d, A.score d)
have hT : Continuous T :=
(continuous_id.smul continuous_const).add
((continuous_const.sub continuous_id).smul continuous_const)
have himage : T '' (((↑) : ℚ → ℝ) '' Icc 0 1) ⊆ A.pairs := by
rintro _ ⟨_, ⟨q, hq, rfl⟩, rfl⟩
exact hmix c d q hq
exact closure_mono himage
(image_closure_subset_closure_image hT ⟨t, unitInterval_subset_closure_rat ht, rfl⟩)
intro x hx y hy a b ha hb hab
have hb_eq : b = 1 - a := by linarith
subst b
have ha1 : a ≤ 1 := by linarith
let T : (X × ℝ) → (X × ℝ) → X × ℝ := fun p q => a • p + (1 - a) • q
have hT : Continuous (Function.uncurry T) := by
change Continuous (fun p : (X × ℝ) × (X × ℝ) => a • p.1 + (1 - a) • p.2)
have hfst : Continuous (fun p : (X × ℝ) × (X × ℝ) => a • p.1) :=
continuous_fst.const_smul a
have hsnd : Continuous (fun p : (X × ℝ) × (X × ℝ) => (1 - a) • p.2) :=
continuous_snd.const_smul (1 - a)
exact hfst.add hsnd
have hseed : ∀ p ∈ A.pairs, ∀ q ∈ A.pairs, T p q ∈ A.closedPairs := by
rintro p ⟨c, hc, hp⟩ q ⟨d, hd, hq⟩
have h := hfull c d a ⟨ha, ha1⟩
have hlaw : a • A.law c + (1 - a) • A.law d =
a • p.1 + (1 - a) • q.1 := by rw [hc, hd]
have hscore : a * p.2 + (1 - a) * q.2 ≤
a * A.score c + (1 - a) * A.score d :=
add_le_add (mul_le_mul_of_nonneg_left hp ha)
(mul_le_mul_of_nonneg_left hq hb)
change (a • A.law c + (1 - a) • A.law d,
a * A.score c + (1 - a) * A.score d) ∈ A.closedPairs at h
rw [hlaw] at h
exact A.closedPairs_downward h hscore
have hresult : T x y ∈ closure A.closedPairs := map_mem_closure₂ hT hx hy hseed
simpa only [closedPairs, closure_closure] using hresult
end RationalMixtures
end AttainableFamily
private abbrev realSimplex (ι : Type*) [Fintype ι] : Set (ι → ℝ) :=
{weights | (∀ index, 0 ≤ weights index) ∧ ∑ index, weights index = 1}
private theorem convex_realSimplex (ι : Type*) [Fintype ι] :
Convex ℝ (realSimplex ι) := by
intro left hleft right hright leftWeight rightWeight hleftWeight hrightWeight hsum
refine ⟨fun index => add_nonneg (mul_nonneg hleftWeight (hleft.1 index))
(mul_nonneg hrightWeight (hright.1 index)), ?_⟩
simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Finset.sum_add_distrib,
← Finset.mul_sum, hleft.2, hright.2, mul_one, hsum]
theorem simplex_residual {ι : Type*} [Fintype ι] {x y : ι → ℝ}
(hx : x ∈ realSimplex ι) (hy : y ∈ realSimplex ι)
{ε : ℝ} (hε : 0 < ε) (hdom : ∀ i, (1 - ε) * x i ≤ y i) :
(fun i => (y i - (1 - ε) * x i) / ε) ∈ realSimplex ι := by
refine ⟨fun i => div_nonneg (sub_nonneg.mpr (hdom i)) hε.le, ?_⟩
rw [← Finset.sum_div, Finset.sum_sub_distrib, ← Finset.mul_sum, hx.2, hy.2]
field_simp [ne_of_gt hε]
ring
theorem concave_simplex_domination {ι : Type*} [Fintype ι] {F : (ι → ℝ) → ℝ}
(hF : ConcaveOn ℝ (realSimplex ι) F)
(hzero : ∀ x ∈ realSimplex ι, 0 ≤ F x)
{x y : ι → ℝ} (hx : x ∈ realSimplex ι) (hy : y ∈ realSimplex ι)
{ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1)
(hdom : ∀ i, (1 - ε) * x i ≤ y i) : (1 - ε) * F x ≤ F y := by
let r : ι → ℝ := fun i => (y i - (1 - ε) * x i) / ε
have hr : r ∈ realSimplex ι := simplex_residual hx hy hε hdom
have hmix : (1 - ε) • x + ε • r = y := by
funext i
dsimp [r]
field_simp [ne_of_gt hε]
ring
have hconc := hF.2 hx hr (sub_nonneg.mpr hε1) hε.le (by ring)
rw [hmix] at hconc
change (1 - ε) * F x + ε * F r ≤ F y at hconc
exact le_trans (le_add_of_nonneg_right (mul_nonneg hε.le (hzero r hr))) hconc
theorem lowerSemicontinuousOn_nonneg_concave_simplex {ι : Type*} [Fintype ι]
{F : (ι → ℝ) → ℝ} (hF : ConcaveOn ℝ (realSimplex ι) F)
(hzero : ∀ x ∈ realSimplex ι, 0 ≤ F x) :
LowerSemicontinuousOn F (realSimplex ι) := by
intro x hx b hb
by_cases hb0 : b < 0
· filter_upwards [self_mem_nhdsWithin] with y hy
exact lt_of_lt_of_le hb0 (hzero y hy)
have hbnonneg : 0 ≤ b := le_of_not_gt hb0
have hxpos : 0 < F x := lt_of_le_of_lt hbnonneg hb
let ε : ℝ := (F x - b) / (2 * F x)
have hden : 0 < 2 * F x := mul_pos (by norm_num) hxpos
have hε : 0 < ε := div_pos (sub_pos.mpr hb) hden
have hε1 : ε ≤ 1 := by
apply (div_le_iff₀ hden).2
linarith
have hεeq : ε * (2 * F x) = F x - b := div_mul_cancel₀ _ (ne_of_gt hden)
have hgap : b < (1 - ε) * F x := by nlinarith
have hdom : ∀ᶠ y in 𝓝[realSimplex ι] x, ∀ i, (1 - ε) * x i ≤ y i := by
apply Filter.eventually_all.2
intro i
by_cases hxi : x i = 0
· filter_upwards [self_mem_nhdsWithin] with y hy
simpa [hxi] using hy.1 i
have hxipos : 0 < x i := lt_of_le_of_ne (hx.1 i) (Ne.symm hxi)
have hlt : (1 - ε) * x i < x i := by nlinarith
have hev : ∀ᶠ y : ι → ℝ in 𝓝 x, (1 - ε) * x i < y i :=
(continuous_apply i).continuousAt.eventually (lt_mem_nhds hlt)
exact (hev.filter_mono nhdsWithin_le_nhds).mono (fun _ h => h.le)
filter_upwards [self_mem_nhdsWithin, hdom] with y hy hdomy
exact lt_of_lt_of_le hgap (concave_simplex_domination hF hzero hx hy hε hε1 hdomy)
theorem lowerSemicontinuous_comp_of_mem {X Y : Type*} [TopologicalSpace X]
[TopologicalSpace Y] {s : Set X} {F : X → ℝ}
(hF : LowerSemicontinuousOn F s) (α : Y → X) (hα : Continuous α)
(hmem : ∀ y, α y ∈ s) : LowerSemicontinuous (fun y => F (α y)) := by
intro y b hb
have ht : Tendsto α (𝓝 y) (𝓝[s] α y) :=
tendsto_nhdsWithin_iff.mpr ⟨hα.continuousAt, Eventually.of_forall hmem⟩
exact ht.eventually (hF (α y) (hmem y) b hb)
theorem AttainableFamily.continuous_value_on_simplex_chart {C Y ι : Type*}
[TopologicalSpace Y] [Fintype ι] (A : AttainableFamily C (ι → ℝ))
(hzero : ∀ x ∈ realSimplex ι, (x, 0) ∈ A.closedPairs)
(hbound : ∀ x ∈ realSimplex ι, BddAbove (A.fiber x))
(hmix : Convex ℝ A.closedPairs)
(α : Y → (ι → ℝ)) (hα : Continuous α)
(hmem : ∀ y, α y ∈ realSimplex ι) :
Continuous (fun y => A.value (α y)) := by
have hne : ∀ x ∈ realSimplex ι, (A.fiber x).Nonempty :=
fun x hx => ⟨0, hzero x hx⟩
have hconc := A.concaveOn_value _ (convex_realSimplex ι) hne hbound hmix
have hnonneg : ∀ x ∈ realSimplex ι, 0 ≤ A.value x :=
fun x hx => A.value_nonneg x (hzero x hx) (hbound x hx)
exact continuous_iff_lower_upperSemicontinuous.mpr
⟨lowerSemicontinuous_comp_of_mem
(lowerSemicontinuousOn_nonneg_concave_simplex hconc hnonneg) α hα hmem,
A.upperSemicontinuous_value_comp α hα
(fun y => hne _ (hmem y)) (fun y => hbound _ (hmem y))⟩
end MatrixMultiplication.Foundation
end
end OAI
|