File size: 4,376 Bytes
97c3405 | 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
|