Weighted lists #
A weighted list is a list of pairs (weight, value) with weights in a semiring A: the list of
the outcomes of a computation that branches, each with the product of the weights along its
branch. This file has the three operations of such lists:
- the weighted sum of a function of the value;
- sequencing: a second computation at every value of the first one, where the weights multiply;
- a fold of a step over a list, from a state at the beginning.
Weighted lists with these operations are the writer monad of the multiplicative monoid of A over
lists; the file keeps the type List (A × α) of the pairs, which is what the statements about
programs use.
Main definitions #
List.weightedSum:∑ (w, a) ∈ l, w * G a.List.weightedBind: firstl, thenfat every value.List.weightedFoldl: the weighted list of a fold.
Main results #
List.weightedSum_weightedBind: the weighted sum of a sequence is the iterated weighted sum.List.weightedSum_of_fst_eq_one: with all weights1, the weighted sum is a sum.List.mem_weightedBind_iff,List.weightedBind_assoc,List.map_weightedBind,List.map_snd_weightedBind,List.fst_eq_one_of_mem_weightedBind.List.weightedFoldl_singleton_one: a fold of deterministic steps isList.foldl.List.weightedFoldl_ite: a fold of steps that reject unless a condition holds.List.mem_weightedFoldl_induction: an invariant of the steps holds at every outcome of a fold.
References #
From VP ≠ VNP over every field [Ant26], Appendix J.3 (the semantics of the
evaluator in the proof of Theorem J.3); modules Nc.Grp.Lang and Nc.Grp.Trans.
With all weights 1, the weighted sum is the sum over the values.
The weighted sum of values, each with the weight 1.
A common factor of the weights.
The weighted sum of a sequence of two computations.
A fold of steps that reject unless their element satisfies p, and otherwise go on
deterministically.
An invariant of the steps, with a counter of the steps, holds at every outcome of a fold.