File size: 4,376 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 | import OAI.Combinatorics.ContingencyTables.Dense.DenseRational
namespace OAI
/-! # Natural arithmetic for the dense acceptance exponent
Each integral completion entry is represented by a difference of two
natural numbers. The rational floor in the geometric definition is then
an ordinary natural quotient, including zero denominators.
-/
namespace ContingencyTables.GridBoundary
open scoped BigOperators Classical
def componentExponent (d s positive negative : β) : β :=
(d^4*d^8*negative-d^4*(d^8*positive+d*s))/(s*d^8)
lemma floor_signed_quotient (positive negative denominator : β) :
β((positive : β)-negative)/denominatorββ =
(positive-negative)/denominator := by
rw [Nat.floor_div_natCast,Nat.floor_sub_natCast,Nat.floor_natCast]
lemma componentExponent_eq (d s positive negative : β) :
componentExponent d s positive negative =
β(d : β)^4*(-((positive : β)-negative)/s-(d : β)/(d : β)^8)ββ := by
by_cases hd : d=0
Β· simp [hd,componentExponent]
by_cases hs : s=0
Β· simp only [hs,componentExponent,Nat.zero_mul,Nat.div_zero,Nat.cast_zero,
div_zero,zero_sub]
symm
apply Nat.floor_of_nonpos
apply mul_nonpos_of_nonneg_of_nonpos (by positivity)
exact neg_nonpos.mpr (by positivity)
have hdq : (d : β)β 0 := by exact_mod_cast hd
have hsq : (s : β)β 0 := by exact_mod_cast hs
have he : (d : β)^4*(-((positive : β)-negative)/s-(d : β)/(d : β)^8)=
(((d^4*d^8*negative : β) : β)-((d^4*(d^8*positive+d*s) : β) : β))/
((s*d^8 : β) : β) := by
push_cast
field_simp [hdq,hsq]
ring
rw [he,floor_signed_quotient]
rfl
variable {I J : Type*} [Fintype I] [Fintype J]
def integerParts (R : Option I β β) (P : Option J β β) (z : IΓJ β β) :
Option I β Option J β βΓβ
| some i,some j => (z (i,j),0)
| some i,none => (R (some i),β j,z (i,j))
| none,some j => (P (some j),β i,z (i,j))
| none,none => (R none+β i,β j,z (i,j),β j,P (some j))
lemma integerParts_sub (R : Option I β β) (P : Option J β β)
(z : IΓJ β β) (i : Option I) (j : Option J) :
((integerParts R P z i j).1 : β€)-(integerParts R P z i j).2=
DenseAffine.integerTable R P z i j := by
cases i <;> cases j
all_goals simp only [integerParts,DenseAffine.integerTable,Nat.cast_zero,sub_zero,
Nat.cast_sum,Nat.cast_add]
ring
lemma integerParts_sub_rat (R : Option I β β) (P : Option J β β)
(z : IΓJ β β) (i : Option I) (j : Option J) :
((integerParts R P z i j).1 : β)-(integerParts R P z i j).2=
(DenseAffine.integerTable R P z i j : β) := by
exact_mod_cast integerParts_sub R P z i j
variable {q K : β}
def arithmeticExponentAt (R : Option I β β) (P : Option J β β) (d : β)
(e : IΓJ β Fin q) (a : Grid (I := Fin q) K) :
Option (Option IΓOption J) β β
| none => 0
| some g =>
let parts := integerParts R P (cornerFree R P d e a) g.1 g.2
componentExponent d (min (R g.1) (P g.2)) parts.1 parts.2
lemma arithmeticExponentAt_eq (R : Option I β β) (P : Option J β β) (d : β)
(e : IΓJ β Fin q) (a : Grid (I := Fin q) K)
(g : Option (Option IΓOption J)) :
arithmeticExponentAt R P d e a g=
β(d : β)^4*rationalComponent R P d e a gββ := by
cases g with
| none => simp [arithmeticExponentAt,rationalComponent]
| some g =>
simp only [arithmeticExponentAt,componentExponent_eq,integerParts_sub_rat,
rationalComponent]
/-- A finite maximum of explicitly computable natural quotients is exactly
the exponent used in the dense Metropolis acceptance probability. -/
theorem denseExponent_eq_arithmetic (R : Option I β β) (P : Option J β β) (d : β)
(e : IΓJ β Fin q) (a : Grid (I := Fin q) K) :
denseExponent R P d e a=
Finset.univ.sup' Finset.univ_nonempty (arithmeticExponentAt R P d e a) := by
have hm : Monotone (fun x : β => β(d : β)^4*xββ) := by
intro x y hxy
exact Nat.floor_mono (mul_le_mul_of_nonneg_left hxy (by positivity))
unfold denseExponent rationalPenalty
rw [Finset.apply_sup'_eq_sup'_comp _ (fun x : β => β(d : β)^4*xββ) hm.map_sup]
apply Finset.sup'_congr Finset.univ_nonempty rfl
intro g _
exact (arithmeticExponentAt_eq R P d e a g).symm
end ContingencyTables.GridBoundary
end OAI
|