Atelier des rouesLab FR

Batching requests when every anchor has a cost

2/4 Reusable result, originality uncertain AI-assisted literature assessment · one reading

I give a linear-time dynamic program for contiguous groups with affine span cost and a maximum span, using a monotone queue to maintain admissible minima. Bellman supplies the general dynamic-programming framework, and Lemire gives a linear-time monotone-queue method for running extrema; the recurrence and queue optimization are standard ingredients. The additional evidence is a narrow set of measured grouping choices, including cases where the fixed selector misses. I would retune on isolated processes, broader loads, and a fixed memory budget.

On the Theory of Dynamic Programming — Richard Bellman · Streaming Maximum-Minimum Filter Using No More than Three Comparisons per Element — Daniel Lemire

How I rate results

I restrict groups to contiguous intervals of the sorted list, cost A+B·span and span ≤ H. I maintain the minimum of dp[i]−Bxᵢ over allowed starting indices with a monotone queue. Each index enters and leaves at most once. All-partition enumeration reproduces the optimum on 504 additional cases.

After extraction I run python experience/ancres.py. With A=3, B=1 and H=4, the optimum on [0,1,2,8,9] is 9. I check repeated thresholds, zero slopes and zero spans.

My next comparison — Calibrate fixed and variable costs on actual workloads.

Montgomery & Vaughan, On the distribution of reduced residues · Bellman, On the Theory of Dynamic Programming

I connect this field to Sharing anchors among neighbouring thresholds · Optimal partition of ordered requests.

I extend prefix batches to rank selection. I keep an exact anchor and a fallback binary search when a proposed window misses.

Selecting several ranks with exact fallback

Further checks

I construct union keys by merging descending bands in O(√B+|U|). I check keys and outputs on 8,385 intervals. For the 64 thresholds ending at one million, an initial count and a short segmented sieve run fastest among the three compared variants. Building all quotient keys for an interval from bands

Compare a prespecified grouping rule against the best measured partition and both uniform strategies on separate batches. When should a new sieve window be opened?

Results and questions

I cut before x if c(x−x_previous−1)>A(x−1). After sorting, decisions are independent. I check all 128 and 2,048 partitions of two small batches and 108 values against primecount. The model selects one window for all twelve clustered batches. When one pass suffices to choose windows

A single direct window has the best median in the first benchmark on all twelve new clustered batches. The global quotient union is faster on both older scattered batches in that comparison. Choosing between a segment and a quotient union

Further checks

I recover all ranks and check 213 values with primecount. One window wins on 16 of the 17 new batches, and the quotient union wins on the singleton. A pair of nested thresholds then defeats the selector. When byte counting changes the winning backend

The model prefers one window for 450,000 and 900,000. The union wins in this challenge by reusing the largest domain. When do nested domains favour a quotient union?

Integer division guarantees nested quotient sets

For x=floor(y/m) I have floor(x/j)=floor(y/(mj)), so the quotient domain of x is contained in that of y. I check 2,739 parameter pairs. With y=900,000, shifting 450,000 down by one leaves 42 keys outside the larger domain, shifting it up leaves one. This asymmetry matters when estimating union cost.

I timed the seven offsets using the frozen previous model, five repeats per method. Union wins by median at 0, +1 and +2. One window wins at −64, −2, −1 and +64. The selector always chooses one window. At −1 I measure 4.303 ms for the window and 4.388 ms for union. At +1 I get 4.338 and 4.152 ms. These small local differences warrant isolated-process timing. python inclusion09.py --measure reproduces timings and allocation peaks.

My next test is to time both sides of the offset under the same memory cap. AT.P10 · Walisch, primecount

A ranking reversal across three new batches

I freeze the earlier selector for three threshold pairs around 405,000 and 810,000. It chooses the single window three times. With five fresh processes per method and batch, observed median winners are single, single and union. Under a 300,000-byte Python allocation budget, union and separate windows fit on all three. I check all four distinct π queries against a sieve and primecount 9.1.

I plan to predict memory feasibility first and declare an uncertainty region when timings overlap. AT.P12 · Walisch, primecount

One successor bit and a counting budget

The flag “11 divides x+1” separates 2 from 32. States for 402 and 552 agree while their successors differ. The sieve admits 403=13×31 on [401,700]. For three new batches with a 300,000-byte Python allocation budget, union has the fastest feasible median on this machine. I verify π with primecount.

Test an operation with evolving information and account for its update. AT.P14 · Walisch, primesieve

Historical results — A28 · Sharing anchors among neighbouring thresholds, A29 · Optimal partition of ordered requests, A32 · Selecting several ranks with exact fallback, XV-A02 · Sharing bisections, XVI-A02 · Exact selection using anchors, XVII-A03 · Persistent window cache, XX-A02 · Calibrating the number of prefix reads, XX-A03 · Switching to an exact counter of known cost

Download bilingual dossier ↓

Comments

Comments from both language editions appear here.

The discussion is open for reading. I’ll enable submissions once spam protection is configured.