kBucketSum: k-way bucketed enumeration #
Polymorphic substrate generalising the family of bucket-aggregator patterns used in planar multi-graft proofs (Foissy 2021, Marcolli-Chomsky-Berwick 2025, Oudom-Guin 2004).
For each item in remaining, a choice from idx selects a bucket;
items accumulate into the per-bucket lists pres. At empty
remaining, the leaf function leaf : (τ → List ι) → Multiset ω
consumes the final bucket assignment and produces the output.
This unifies the previously hand-rolled hostBucketSum (2 buckets,
parallel cartesian leaf), hostTripleSum (3 buckets, parallel triple
bind leaf), and assocBucketSum (2 buckets, iterated bind leaf), and
provides a one-liner pattern for future variants like the 5-bucket
aggregator needed for the deep case of assocBucketSum's bridge.
Status #
[UPSTREAM] candidate. Sorry-free.
§1: bucketSlice — items routed to a single bucket #
The slice of items from Ts whose assignment in assn equals t.
Pairs Ts with assn, then collects items whose paired assignment
matches the target bucket label.
Equations
- RootedTree.Planar.Pathed.bucketSlice Ts assn t = List.filterMap (fun (p : ι × τ) => if p.2 = t then some p.1 else none) (Ts.zip assn)
Instances For
§2: kBucketSum — definition and basic equation lemmas #
k-way bucketed enumeration. For each item in remaining, bind
over idx to choose a bucket; the accumulator pres t for that
bucket grows by one item. At empty remaining, apply leaf.
Equations
- RootedTree.Planar.Pathed.kBucketSum idx leaf pres [] = leaf pres
- RootedTree.Planar.Pathed.kBucketSum idx leaf pres (x_1 :: rest) = (↑idx).bind fun (t : τ) => RootedTree.Planar.Pathed.kBucketSum idx leaf (Function.update pres t (pres t ++ [x_1])) rest
Instances For
§3: assignment rewrite #
Key identity: kBucketSum over remaining items Ts equals a
single bind over all length-Ts.length assignments (drawn from
idx) of the leaf applied to the accumulators augmented by the
per-bucket slice of Ts. Generalises hostBucketSum_assignment_rewrite
and assocBucketSum_assignment_rewrite.