Weighted counts of independent events #
The computations with weighted counts
(DescriptiveComplexity.weightedCount) that make a query safe: its weighted
count, a sum over exponentially many valuations, is a product and a sum over
the variables.
DescriptiveComplexity.weightedCount_forall: an event that constrains each variable separately has a product as weighted count.DescriptiveComplexity.weightedCount_sum_type: conditioning on the values of one group of variables.DescriptiveComplexity.weightedCount_add_not: an event and its complement share the total weight.DescriptiveComplexity.prod_add_eq_prod_add_sum: the first success identity. WithF ithe weight of a failure atiandS ithat of a success, the total weight∏ (F i + S i)is the weight∏ F iof failing everywhere, plus, for eachi, the weight of failing beforei, succeeding ati, and doing anything after. It turns the difference∏ (F i + S i) - ∏ F i, the weight of succeeding somewhere, into a sum of products: no subtraction is left, which is what a quantitative term needs.
theorem
DescriptiveComplexity.weightedCount_add_not
{X : Type}
[Fintype X]
[DecidableEq X]
(a c : X → ℕ)
(f : (X → Bool) → Bool)
:
An event and its complement share the total weight.
Dependency graph
theorem
DescriptiveComplexity.weightedCount_forall
{X : Type}
[Fintype X]
[DecidableEq X]
(a c : X → ℕ)
(ok : X → Bool → Bool)
:
An event constraining each variable separately: its weighted count is the product, over the variables, of the weights of the values it allows.
Dependency graph
theorem
DescriptiveComplexity.weightedCount_sum_type
{X : Type}
[Fintype X]
[DecidableEq X]
(a c : X → ℕ)
{Y : Type}
[Fintype Y]
[DecidableEq Y]
(a' c' : Y → ℕ)
(f : (X ⊕ Y → Bool) → Bool)
:
weightedCount (Sum.elim a a') (Sum.elim c c') f = ∑ vX : X → Bool, valWeight a c vX * weightedCount a' c' fun (vY : Y → Bool) => f (Sum.elim vX vY)
Conditioning on a group of variables: the weighted count over two groups is the sum, over the valuations of the first, of their weight times the weighted count over the second.
Dependency graph
First success #
theorem
DescriptiveComplexity.prod_add_eq_prod_add_sum
{I : Type}
[Fintype I]
[LinearOrder I]
(F S : I → ℕ)
:
The first success identity: the total weight is the weight of failing everywhere, plus the weights of failing before an index, succeeding at it, and doing anything after.