Atelier des rouesLab FR
Applications/Scheduling

Counting slots with noncoprime periods

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

I retain the index that counts common instants before X by grouping residues modulo the gcd, then updates the bit index through word changes and a Fenwick tree. Gibson’s Density CRT already counts compatible residue pairs by gcd fibres; Bettini, Mascetti, and Wang compile calendar expressions to minimal periodic sets, while Pibiri and Kanda study mutable bitmap rank/select. My difference is the prefix query and measured update/query trade-off, useful for repeated availability checks. The evidence remains synthetic masks and one Python/CPU setup, not a validated real-calendar crossover.

A Density Chinese Remainder Theorem — D. Jason Gibson · Supporting Temporal Reasoning by Mapping Calendar Expressions to Minimal Periodic Sets — Claudio Bettini, Sergio Mascetti, and X. Sean Wang · Rank/Select Queries over Mutable Bitmaps — Giulio Ermanno Pibiri and Shunsuke Kanda

How I rate results

How long must I keep two delay changes apart to recover the one-change guarantee?

Increasing the minimum dwell removes adversarial scenarios. I can find the first threshold by bisection and check both sides. At period 6 I also sweep every dwell with the exhaustive control. For periods 6, 12, 17 and 31 I recover the guarantee at dwell lengths 1, 15, 318 and 504 on their respective common cycles.

I will test a third change on a cycle small enough to enumerate. AT.EX21.04 · Try the experiment

Keith Conrad · The Chinese remainder theorem

Spacing two schedule changes

I choose a phase before the delay changes twice. What minimum dwell between changes protects joint slots?

I minimize overlap over delays and cuts using prefix sums. I include zero- and one-change cases and compare the small case to direct enumeration. At period 12 and jitter 1 I guarantee two slots with one change. With two changes the guarantee drops to one for h = 1 or 8 and returns to two at h = 16.

I will find the first dwell time that restores the guarantee for each period. AT.EX20.04 · Change the inputs.

Keith Conrad · The Chinese remainder theorem

Counting slots with noncoprime periods

Choose a robust offset

For periods 24 and 8 with two ticks of jitter, nominal offset 0 may fall to one slot. Offset 6 guarantees two. I checked 882 counts by scanning timestamps. Interactive experiment · AT.EX18.04

The XI pilot selected slots under six coprime periods using partial lists. I now use two masks with periods m and n and a possibly nontrivial gcd g. The model uses integer ticks and periodic availability.

From compatibility to strict prefixes

Phases a and b are compatible exactly when they share a residue c modulo g. Write x=a+mt. In one full period t is the residue of ((b−c)/g−(a−c)/g) times the inverse of m/g modulo n/g. If n/g is one the only residue is zero. This is the generalised Chinese remainder theorem. Compatibility statement

For each c I sort the transformed b values once. For fixed a, x<X selects a circular interval in that list. Two binary searches and a wraparound correction give its population. I sum over compatible a. With A and B input phases this implementation takes O(A log A + B log B) arithmetic operations to prepare, O(A+B) storage and O(A log(B+1)+A) operations per prefix. Binary search on the period then selects an address. Building each half-mask from multiple constraints can itself be expensive. Horowitz and Sahni on half-list methods

Checks and next question

I compared every prefix across three periods and all ranks in one cycle against a scan of 432 small calendars, including empty masks. For periods 6,060 and 6,180, the 4,075,344 possible phase pairs yield 67,922 slots per period of 624,180. Rank 33,961 gives tick 312,116, confirmed by a full scan. I address setup costs and updates in the comparison below.

Reproduce

After extracting the kit I run python experience.py with Python 3.10 or newer and compare its output with resultats.json.

When does the index pay for itself?

I measure total time to count half-open windows [a,b) with three methods. A scan checks both masks at each tick. A bitmap materialises one period and stores a cumulative count for every 64-bit word. My gcd index counts in lists of compatible phases. Rank on a bit vector is an established technique. Vigna, Broadword Implementation of Rank/Select Queries

For periods 251 and 257, five phases per mask and windows of width 4,096, eight queries without updates cost 55 µs in total with the gcd index, 201 µs with the bitmap and 2,868 µs with scanning. At 64 queries the bitmap leads, 270 µs against 377 µs for the gcd index. Flipping one left phase every eight queries gives seven rebuilds and returns the lead to the gcd index, 764 µs against 1,886 µs. For one 32-tick window the scan takes 5 µs. Initial peak traced Python allocation, with input masks already available, is 616 bytes for the scan, 3,232 for the gcd index and 17,216 for the bitmap.

I publish all five total times per method for 48 workloads. By median total time the scan is fastest in 18, the gcd index in 11 and the bitmap in 19. Changing the period pair from (251, 257) to (240, 272) changes both the gcd and the combined period, so this design cannot isolate the gcd alone. Target densities are 2% and 45%, widths 32 and 4,096, and starting ticks use a fixed seed. I rebuild both indexes completely after a change. Updating only the affected part is the next comparison.

python comparaison.py --check checks all 3,656 windows against scanning, including negative ticks. python comparaison.py reruns the measurements. I time construction, updates and reads separately and take the median of each run’s total. Input generation and the common initial copy are outside the timed interval. A separate memory trace covers initial construction. The recorded timings are for Python 3.10.11 on Windows AMD64 (Ryzen Threadripper PRO 3975WX). Detailed measurements · Register

Updating a mask without rebuilding the period

I toggle left phase a. Within the joint period L only the L/m ticks a, a+m, … can change. Of these I flip only the bits whose right-hand phase is allowed. I group the bits of each 64-bit word and propagate its change in population through a Fenwick tree. If W words change out of B stored words, updating costs O(L/m + W log(B+1)). A window takes two prefix reads in O(log(B+1)). I reuse Fenwick’s cumulative frequency structure. My contribution is the comparison and the full-cost measurements on periodic masks. Fenwick

I replay all 48 AT.T2 workloads, with five repeats per method. The mutable bitmap beats full rebuilding on all 16 workloads with updates. The static bitmap costs less on all 32 without updates. Across four methods the lowest median total time goes to scanning in 18 cases, static bitmaps in 15, gcd indexing in 8 and mutable bitmaps in 7.

With periods 251 and 257, five initial phases per mask, 64 windows of width 4,096 and 63 updates, the mutable bitmap visits 16,191 ticks and changes 315 bits in 315 words, counted across updates. I measure 2.221 ms in total, against 14.171 ms for full rebuilding and 2.726 ms for gcd indexing. With no updates the same width and query volume give 0.561 ms for the mutable bitmap against 0.288 ms for the static bitmap. With seven changes, the gcd index still leads on this case. For the sparse pair of periods 240 and 272, 49 of 63 phase changes alter no intersection bits.

I supply setup, read and update measurements and five raw samples. The separate memory trace includes the index, allocations during updates and the answer list, excluding the supplied masks and common initial copy. For the 63-update example above, peak traced allocation over the run is 22,484 bytes against 38,108 for rebuilding. Query generation, checking and memory traces are outside timing. I compute median total time from per-run totals. Python 3.10.11, Windows AMD64, Ryzen Threadripper PRO 3975WX.

After extraction python dynamique.py verifies each answer, compares change counts with actual modified words and tests 8,484 additional prefixes with repeated flips, negative ticks and period wraparound. I compare the output with controle-03.json. python dynamique.py --measure reruns the timings. Two mutable masks and directly visiting compatible partners remain open follow-ups. Register · Measurements

Control from XII

I supply the common-factor fibre counter with three periods and negative ticks. I run python temoin_xii.py and compare with controle-xii.json.

Querying two periodic calendars

I provide a command accepting two integer masks, query windows and ranks in a JSON file. For periods 12 and 18 I obtain seven slots per 36 ticks and tick 13 at zero-based rank three. I check answers by a separate scan.

Time the full cost on an independent periodic workload. AT.T4 · Bettini, Mascetti & Wang, Supporting Temporal Reasoning by Mapping Calendar Expressions to Minimal Periodic Sets

I extract the Calendars kit and run python creneaux11.py --agenda agenda11.json. I replace the periods, open lists, half-open windows and zero-based ranks in the JSON.

The cost of building and querying a calendar

I fix two pairs of integer periods, masks and three profiles of 256 paired queries. Both methods give the same 1,536 count/rank pairs. On cycles of 420 and 5,063 ticks, materialisation wins on end-to-end time for all six loads. On the second cycle it uses 32,224 Python bytes to build against 3,932 for the implicit counter.

I seek a crossover at long periods and few queries, followed by a domain workload. AT.T5 · Bettini, Mascetti & Wang, Supporting Temporal Reasoning by Mapping Calendar Expressions to Minimal Periodic Sets

How many queries pay for building a calendar?

I measure five alternating repetitions on 60 workloads, two periods, two densities and three profiles. Each query checks prefix and selection. For cycle 420 the table wins at one query in all six profiles. For 5,063 the first tested winning count is four at low density and two at high density for all three localities. I publish medians with and without construction and peak Python memory.

Compare these thresholds with a dated calendar trace and cold-access costs. AT.T6 · Bettini, Mascetti & Wang, Supporting Temporal Reasoning by Mapping Calendar Expressions to Minimal Periodic Sets

Guarantee slots across a delay change

For each offset and cut I independently minimize the counts before and after the cut over integer delays in [−j,j]. Prefix sums give both counts from the same time origin. I inspect every offset of the second calendar. With periods 24 and 31 and j=2, my guarantee falls from 35 meetings to 26 in 744 slots. At offset 7, a change at time 265 from +2 to 0 attains the bound.

Change the inputs · AT.EX19.04 · Keith Conrad · The Chinese remainder theorem

I reproduce · python decalages19.py

Download bilingual starter kit ↓

Comments

Comments from both language editions appear here.

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