File size: 5,999 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 114 115 116 117 118 119 120 121 122 123 124 125 126 | import OAI.Combinatorics.ContingencyTables.Model
import OAI.Combinatorics.MatchingCount.Model
namespace OAI
/-!
# Main algorithm statements for result 200
The samplers and counter use a finite transition table, independent fair
bits, binary inputs and explicit bit-operation runtime bounds. No counting or sampling oracle is part of the machine.
The exact sampler's expected runtime uses a summable tail series, avoiding
the default value of an undefined infinite sum.
-/
namespace ContingencyTables.Algorithms
open scoped BigOperators
open Filter
abbrev Machine := MatchingFPRAS.RandomMachine
abbrev Symbol := MatchingFPRAS.Symbol
def encodeMatrix {m n : β} (X : Fin m β Fin n β β) : List Symbol :=
((List.ofFn fun i => (List.ofFn fun j => MatchingFPRAS.encodeNat (X i j)).flatten)).flatten
def encodeMargins {m n : β} (r : Fin m β β) (c : Fin n β β) : List Symbol :=
MatchingFPRAS.encodeNat m ++ MatchingFPRAS.encodeNat n ++
(List.ofFn fun i => MatchingFPRAS.encodeNat (r i)).flatten ++
(List.ofFn fun j => MatchingFPRAS.encodeNat (c j)).flatten
def encodeSamplingInput {m n : β} (r : Fin m β β) (c : Fin n β β) (k : β) : List Symbol :=
encodeMargins r c ++ MatchingFPRAS.encodeNat k
def encodeCountingInput {m n : β} (r : Fin m β β) (c : Fin n β β)
(b : Fin m β Fin n β β) (Ξ΅ Ξ΄ : β) : List Symbol :=
encodeMargins r c ++ encodeMatrix b ++ MatchingFPRAS.encodeRat Ξ΅ ++ MatchingFPRAS.encodeRat Ξ΄
/-- The tape alphabet has positive cardinality. -/
theorem alphabetSize_neZero : NeZero (8 : β) := inferInstance
/-- A halted tape contains the row-major binary matrix encoding. -/
def OutputsTable (A : Machine) (input : List Symbol) {t m n : β}
(bits : Fin t β Bool) (X : Fin m β Fin n β β) : Prop :=
(MatchingFPRAS.run A input bits).state = none β§
@Turing.Tape.rightβ MatchingFPRAS.Symbol (@Fin.instInhabited 8 alphabetSize_neZero)
(MatchingFPRAS.run A input bits).tape =
@Turing.ListBlank.mk Symbol (@Fin.instInhabited 8 alphabetSize_neZero) (encodeMatrix X)
noncomputable def tableMass (A : Machine) (input : List Symbol) (t : β)
{m n : β} (X : Fin m β Fin n β β) : β := by
classical
exact ((Finset.univ.filter fun bits : Fin t β Bool => OutputsTable A input bits X).card : β) /
(2 : β) ^ t
noncomputable def haltMass (A : Machine) (input : List Symbol) (t : β) : β := by
classical
exact ((Finset.univ.filter fun bits : Fin t β Bool =>
(MatchingFPRAS.run A input bits).state = none).card : β) / (2 : β) ^ t
def samplingSize (n : β) {m : β} (r : Fin m β β) (k : β) : β :=
m + n + Nat.clog 2 ((β i, r i) + 1) + k + 1
/-- Paper 200-01, Theorem main(i): bounded runtime on every random tape
and total variation at most `2β»α΅`, with freely varying dimensions. -/
def BoundedSamplingStatement : Prop :=
β (A : Machine) (C d : β), 0 < C β§
β (m n : β) (r : Fin m β β) (c : Fin n β β),
(β i, r i) = β j, c j β β k : β, 1 β€ k β
let input := encodeSamplingInput r c k
let t := C * (samplingSize n r k) ^ d
(β bits : Fin t β Bool, β X : Table r c, OutputsTable A input bits X.val) β§
(β X : Table r c,
|tableMass A input t X.val - (Fintype.card (Table r c) : β)β»ΒΉ|) / 2 β€
((2 : β) ^ k)β»ΒΉ
/-- Paper 200-01, Theorem main(ii): every halted output is feasible, each
table has limiting mass `1/|Ξ©|`, termination has probability one, and the
expected number of bit operations is bounded by a uniform polynomial. -/
def ExactSamplingStatement : Prop :=
β (A : Machine) (C d : β), 0 < C β§
β (m n : β) (r : Fin m β β) (c : Fin n β β),
(β i, r i) = β j, c j β
let input := encodeMargins r c
let tail : β β β := fun t => 1 - haltMass A input t
(β t (bits : Fin t β Bool), (MatchingFPRAS.run A input bits).state = none β
β X : Table r c, OutputsTable A input bits X.val) β§
(β X : Table r c, Tendsto (fun t => tableMass A input t X.val) atTop
(nhds ((Fintype.card (Table r c) : β)β»ΒΉ))) β§
Tendsto (haltMass A input) atTop (nhds 1) β§
Summable tail β§
tsum tail β€ C * (samplingSize n r 0) ^ d
noncomputable def count {m n : β} (r : Fin m β β) (c : Fin n β β)
(b : Fin m β Fin n β β) : β := Fintype.card (BoundedTable r c b)
def countingTime (C d : β) {m n : β} (r : Fin m β β) (c : Fin n β β)
(b : Fin m β Fin n β β) (Ξ΅ Ξ΄ : β) : β :=
C * ((encodeCountingInput r c b Ξ΅ Ξ΄).length + βΞ΅β»ΒΉββ +
Nat.clog 2 βΞ΄β»ΒΉββ + 1) ^ d
noncomputable def goodCountingTapes (A : Machine) {m n : β}
(r : Fin m β β) (c : Fin n β β) (b : Fin m β Fin n β β)
(Ξ΅ Ξ΄ : β) (t : β) : Finset (Fin t β Bool) := by
classical
exact Finset.univ.filter fun bits => β q : β,
MatchingFPRAS.Outputs A (encodeCountingInput r c b Ξ΅ Ξ΄) bits q β§
(1 - Ξ΅) * count r c b β€ q β§ q β€ (1 + Ξ΅) * count r c b
/-- Paper 200-02, Theorem main. The input length includes the rational
accuracy parameters, and infeasible inputs always produce exactly zero. -/
def CountingStatement : Prop :=
β (A : Machine) (C d : β), 0 < C β§
β (m n : β), 0 < m β 0 < n β
β (r : Fin m β β) (c : Fin n β β) (b : Fin m β Fin n β β),
(β i, r i) = β j, c j β
β Ξ΅ Ξ΄ : β, 0 < Ξ΅ β Ξ΅ < 1 β 0 < Ξ΄ β Ξ΄ < 1 β
let input := encodeCountingInput r c b Ξ΅ Ξ΄
let t := countingTime C d r c b Ξ΅ Ξ΄
(β bits : Fin t β Bool, β q : β, 0 β€ q β§ MatchingFPRAS.Outputs A input bits q) β§
(count r c b = 0 β β bits : Fin t β Bool, MatchingFPRAS.Outputs A input bits 0) β§
((goodCountingTapes A r c b Ξ΅ Ξ΄ t).card : β) / (2 : β) ^ t β₯ 1 - Ξ΄
end ContingencyTables.Algorithms
end OAI
|