File size: 6,244 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | import OAI.Combinatorics.ContingencyTables.Counting.CompanionCellCatalogProgram
import OAI.Combinatorics.ContingencyTables.Counting.CompanionCanonicalEncoding
namespace OAI
/-! # Initialization from the computed small-cell catalog
The proof-level equivalence follows the actual catalog program. It is
used only to identify the output of the binary list initializer with a
paired transversal and to transfer its distributional error bound.
-/
namespace ContingencyTables.CompanionComputedInitial
open MatchingFPRAS.TreeTyped CompanionFactorialApplication
open InitialTransversals InitialFactorialBits CompanionInitialDraw
open FirstSuccess ResidualMixture TwoLiftStates CommonBasesFPRAS
open CompanionArithmeticProposal
open scoped BigOperators Classical
abbrev ProgramInput := (CompanionCellCatalog.Input×ℕ)×List Bool
def initialProgram (z : ProgramInput) : List ℕ :=
CanonicalInitialEncoding.initialCode ((CompanionCellCatalog.capacities z.1.1,z.1.2),z.2)
def initialProgramRealizer : Realizer initialProgram :=
composition (pair (pair
(composition (composition first first) CompanionCellCatalog.capacitiesRealizer)
(composition first second)) second) CanonicalInitialEncoding.initialCodeRealizer
theorem polynomial_initialProgram : PolynomialTime initialProgramRealizer :=
polynomial_composition (polynomial_pair (polynomial_pair
(polynomial_composition (polynomial_composition polynomial_first polynomial_first)
CompanionCellCatalog.polynomial_capacities)
(polynomial_composition polynomial_first polynomial_second)) polynomial_second)
CanonicalInitialEncoding.polynomial_initialCode
noncomputable section
variable {m n : ℕ} (A : Instance (Fin m) (Fin n))
def cellOrder : SmallCell A ≃ Fin (CompanionCellCatalog.catalog (CompanionCellCatalog.input A)).length :=
(CompanionCellCatalog.cellEquiv A).symm
def capacities (i : Fin (CompanionCellCatalog.catalog (CompanionCellCatalog.input A)).length) : ℕ :=
A.b ((cellOrder A).symm i).val.1 ((cellOrder A).symm i).val.2
def wordLength (B : ℕ) : ℕ := bitCount (capacities A) B
def initialDraw (B : ℕ) (bits : Fin (wordLength A B) → Bool) :
PlainIndex (pairs : List ((Labels A×Bool)×(Labels A×Bool))) :=
indexEquiv A (transversalDraw (fun s : SmallCell A => A.b s.val.1 s.val.2)
(cellOrder A) B bits)
def copyOrder : Labels A ≃ Copy (capacities A) := Equiv.sigmaCongrLeft' (cellOrder A)
def pairOrder : (Labels A×Bool) ≃ (Copy (capacities A)×Bool) :=
Equiv.prodCongr (copyOrder A) (Equiv.refl Bool)
def coordinateOrder : (Labels A×Bool) ≃ Fin (CanonicalInitialEncoding.pairOrder (capacities A)).length :=
(pairOrder A).trans (CanonicalInitialEncoding.coordinateEquiv (capacities A))
lemma encodeSet_reindex (S : Set (Labels A×Bool)) :
encodeSet (coordinateOrder A) S=
encodeSet (CanonicalInitialEncoding.coordinateEquiv (capacities A))
((pairOrder A).symm ⁻¹' S) := rfl
lemma draw_preimage (B : ℕ) (bits : Fin (wordLength A B) → Bool) :
(pairOrder A).symm ⁻¹' (initialDraw A B bits).val.val=
encode (capacities A) (drawChoices (capacities A) B bits) := by
ext p
rcases p with ⟨⟨i,k⟩,side⟩
have hc := Equiv.piCongrLeft'_symm_apply_apply
(fun s : SmallCell A => Finset (Fin (A.b s.val.1 s.val.2)))
(cellOrder A) (drawChoices (capacities A) B bits) i
cases side
· change k∈(choiceEquiv (fun s : SmallCell A => A.b s.val.1 s.val.2)
(cellOrder A) (drawChoices (capacities A) B bits)) ((cellOrder A).symm i) ↔
k∈drawChoices (capacities A) B bits i
exact Iff.of_eq (congrArg (fun S => k∈S) hc)
· change k∉(choiceEquiv (fun s : SmallCell A => A.b s.val.1 s.val.2)
(cellOrder A) (drawChoices (capacities A) B bits)) ((cellOrder A).symm i) ↔
k∉drawChoices (capacities A) B bits i
exact Iff.of_eq (congrArg (fun S => k∉S) hc)
/-- The complete program computes the semantic initializer with the
coordinate order recovered from the program's own catalog. -/
theorem initialProgram_eq (B : ℕ) (hB : 0<B) (bits : Fin (wordLength A B) → Bool) :
initialProgram ((CompanionCellCatalog.input A,B),List.ofFn bits)=
encodeSet (coordinateOrder A) (initialDraw A B bits).val.val := by
unfold initialProgram
rw [CompanionCellCatalog.capacities_eq]
rw [encodeSet_reindex,draw_preimage]
exact CanonicalInitialEncoding.initialCode_ofFn (capacities A) B hB bits
lemma catalog_count_le : (CompanionCellCatalog.catalog (CompanionCellCatalog.input A)).length≤A.d := by
have hc := Fintype.card_congr (CompanionCellCatalog.cellEquiv A)
simpa only [Fintype.card_fin] using hc.trans_le (cellCount_bound A)
theorem wordLength_bound (B : ℕ) : wordLength A B≤A.d*(A.W+1)*B := by
have hh := bitCount_bound (capacities A) B A.W (fun i =>
(A.hsmall _ _ ((cellOrder A).symm i).property).le)
exact hh.trans (Nat.mul_le_mul_right B
(Nat.mul_le_mul_right (A.W+1) (catalog_count_le A)))
/-- The computed-order initializer has the same μ₀ reference law and
error guarantee as the abstract-order initializer. -/
theorem initialDraw_error (B : ℕ) :
variation (mapLaw (uniformLaw (α := Fin (wordLength A B) → Bool)) (initialDraw A B))
(idealLaw A)≤(A.d:ℚ)*(3*A.W+1)/(2*(2:ℚ)^B) := by
unfold initialDraw wordLength capacities
have he := mapLaw_equiv_output (indexEquiv A)
(uniformLaw (α := Fin (bitCount
(fun i => A.b ((cellOrder A).symm i).val.1 ((cellOrder A).symm i).val.2) B) → Bool))
(transversalDraw (fun s : SmallCell A => A.b s.val.1 s.val.2) (cellOrder A) B)
rw [he,idealLaw,variation_equiv]
have ht := transversalDraw_error (fun s : SmallCell A => A.b s.val.1 s.val.2)
(cellOrder A) B A.W (fun s => (A.hsmall _ _ s.property).le)
apply ht.trans
apply div_le_div_of_nonneg_right _ (by positivity)
apply mul_le_mul_of_nonneg_right _ (by positivity)
exact_mod_cast catalog_count_le A
theorem initialDraw_precision (h : ℕ) :
variation (mapLaw (uniformLaw (α := Fin (wordLength A (precision A h)) → Bool))
(initialDraw A (precision A h))) (idealLaw A)≤1/(2:ℚ)^h :=
(initialDraw_error A (precision A h)).trans (precision_error A h)
end
end ContingencyTables.CompanionComputedInitial
end OAI
|