Formal Foundations and Proofs
The chapter on the algebra of regular time series defines the operators and their equations. This page presents their justification: the connection to covering-system theory and proofs of properties used to interpret and optimize query plans. The final section on the connection to the implementation explains which properties have been formalized in Lean and how tests compare the model with C++ functions.
ℹ️ Info
The rational variant matters for the implementation. Beatty’s theorem describes a partition for irrational parameters, while Fraenkel’s generalization also admits rational parameters. The proofs below show that sample-position selection by interleaving and de-interleaving can be computed exactly in this domain, without floating-point approximations.
Covering systems as the foundation
The literature on covering systems [4] belongs to combinatorics and cryptanalysis within number theory. The problem under consideration is how to determine a partition of the set of positive natural numbers. We say that two sequences partition the set of positive natural numbers if the sets formed from the elements of these sequences have an empty intersection, and their union forms the set of positive natural numbers.
The basis for these considerations is the parameterized Beatty sequence. In its general form it is written using the floor function:
\[ \mathcal{B}(\alpha ,\alpha ^{\prime }) := \left( \left\lfloor \frac{n-\alpha ^{\prime }}{\alpha }\right\rfloor \right) _{n=1}^{\infty } \]
This single definition generates an entire family of sequences. Partition results always concern a pair of its instances with different parameters: we write the pair as B(α, α′) and B(β, β′), where the second notation denotes the complementary term.
The parameters of this sequence have a clear geometric interpretation:
- α denotes the density of the sequence,
- 1/α denotes the slope,
- α′ denotes the offset,
- −α′/α denotes the y-intercept (the point where it crosses the y-axis).
The Beatty theorem guarantees a partition of the set for irrational numbers. The Fraenkel theorem is a generalization that - crucially for us - also allows rational numbers, provided five postulates are satisfied (quoted in the introductory chapter). An accessible proof of Fraenkel’s theorem can be found in K. O’Bryant’s paper “Fraenkel’s partition and Brown’s decomposition” [23].
The remainder of this page boils down to a single idea: showing that the stream operators are, in essence, machines generating Beatty sequences that partition (cover) the set of natural numbers.
Tools: floor and ceiling properties
The proofs rely almost exclusively on the floor function (⌊x⌋ - the integer part) and the ceiling function (⌈x⌉ - the smallest integer not less than x). I therefore first present a set of identities that will be used repeatedly. Let x ∈ ℝ, and let C denote an integer:
\[ \left\lfloor x\right\rfloor = \left\lceil x\right\rceil \iff x \in \mathbb{Z} \]
\[ \left\lfloor x\right\rfloor + 1 = \left\lceil x\right\rceil \iff x \in \mathbb{R} \setminus \mathbb{Z} \]
The second of these identities carries over directly to Beatty sequences themselves. The ceiling variant of the sequence, B′α(n) = ⌈nα⌉, is - for irrational α - merely a shifted version of the floor variant:
\[ B_{\alpha}^{\prime}(n) = \left\lceil n\alpha \right\rceil = \left\lfloor n\alpha \right\rfloor + 1 \]
In the classical Beatty theorem, α is irrational, so nα is not an integer for any n > 0. The second identity therefore applies to every term: the ceiling variant raises each term of the floor variant by exactly 1. For rational α, nα can be an integer, in which case ⌈nα⌉ = ⌊nα⌋. The relationship must then be checked term by term. Part three of the proof of Theorem 2 (de-interleaving satisfies Fraenkel’s postulates) performs this case analysis using gcd(a, b).
\[ \left\lfloor x + C\right\rfloor = \left\lfloor x\right\rfloor + C \]
(the last identity holds for every C ∈ ℤ). Additionally, in analyzing the residue of the de-interleaving sequence we will use relationships tying the greatest common divisor (gcd) to the domain of the quotient a/b. For a, b ∈ ℕ>0:
\[ \operatorname{gcd}(a,b) = b \iff \frac{a}{b} \in \mathbb{N} \]
and otherwise:
\[ 1 \leq \operatorname{gcd}(a,b) \leq \min(a,b) \]
These two cases disjointly cover the entire domain of interest to us - which will let us carry out a proof “by cases.”
Operators in formal notation
The operators introduced in the query language have their formal counterparts. The table below ties the formal notation (used in the proofs) to the symbols found in the query language:
| Operation | Formal symbol | Symbol in the query language |
|---|---|---|
| Projection | π | field list after SELECT |
| Selection | σ | logical condition |
| Sum | Σ | + |
| Difference | δ | - |
| Interleaving | φ | # |
| De-interleaving and its complement | Θ, ∼Θ | & , % |
| Aggregation and serialization (AGSE) | Ψ | @ |
| Shift | τ | > |
For the proofs to be self-contained, I restate two definitions I will refer to directly.
Interleaving φ(A, B) produces an output stream whose successive tuples are determined by the rule:
\[ c_{n}= \left\{ \begin{array}{cc} b_{n-\left\lfloor n z \right\rfloor } & \left\lfloor n z \right\rfloor = \left\lfloor \left( n+1\right) z \right\rfloor \\ a_{\left\lfloor n z \right\rfloor } & \left\lfloor n z \right\rfloor \neq \left\lfloor \left( n+1\right) z \right\rfloor \end{array} \right. , \ z = \frac{\Delta _{b}}{\Delta _{a}+\Delta _{b}}, \ \Delta _{c}=\frac{\Delta _{a}\Delta _{b}}{\Delta _{a}+\Delta _{b}} \]
De-interleaving is defined by two complementary formulas - operator Θ, which recovers the original stream, and operator ∼Θ, which determines the “remainder” of the de-interleaving:
\[ a_{n} = c_{n+ \left\lceil \frac{(n+1)\Delta _{a}}{\Delta _{b}} \right\rceil },\ \Delta _{a}=\frac{\Delta _{c}\Delta _{b}}{\left\vert \Delta _{c}-\Delta _{b}\right\vert } \]
\[ b_{n} = c_{n+\left\lfloor \frac{n\Delta_{b}}{\Delta_{a}}\right\rfloor},\ \Delta_{b}=\frac{\Delta_{c}\Delta_{a}}{\left\vert \Delta_{c}-\Delta_{a}\right\vert } \]
Theorem 1: interleaving guarantees set coverage
✅ Note
Theorem. The interleaving operation guarantees sequential coverage of both index sets of the data streams that are its arguments: every element of stream A and every element of stream B is selected exactly once, in order, without gaps and without repetition.
Proof. Since 0 < z < 1, the increment
\[ d_{n} := \left\lfloor \left( n+1\right) z \right\rfloor - \left\lfloor n z \right\rfloor \]
equals 0 or 1 for every n ≥ 0. The interleaving equation selects an element of stream B exactly at those steps where dn = 0 (the equality branch), and an element of stream A exactly at steps where dn = 1.
Consider the selection index for sequence B: xn = n − ⌊nz⌋. In a single step, xn+1 − xn = 1 − dn: the index increases by exactly 1 at every step selecting from B, and otherwise remains unchanged. So if n < n′ are two consecutive steps selecting from B, then xn′ = xn + 1. The first step selecting from B is n = 0, since 0 < z < 1 implies ⌊0⌋ = ⌊z⌋ = 0, i.e. d0 = 0, and x0 = 0. Selections from sequence B therefore use indices 0, 1, 2, … in order, without gaps or repetitions.
Symmetrically: the selection index for sequence A, i.e. ⌊nz⌋, increases by exactly 1 at every step selecting from A (dn = 1), and otherwise remains unchanged; at the first such step its value is 0 (all earlier steps have d = 0). The elements of sequence A are therefore also selected exactly once each, in order. ∎
Theorem 2: de-interleaving satisfies Fraenkel’s postulates
The theorem connects both sample-selection sequences in de-interleaving to Beatty sequences satisfying Fraenkel’s postulates for rational parameters. It thereby establishes the exact inversion of interleaving.
✅ Note
Theorem. Let a, b ∈ ℕ>0 represent the rational ratio of the rates of the component streams, ∆a/∆b = a/b. Both tuple-selection sequences describing the de-interleaving operation are - up to the index alignment shown in the proof - a special case of Beatty sequences satisfying the postulates of Fraenkel’s theorem for rational parameters. Consequently they partition the set ℕ₀ := ℕ ∪ {0}, i.e. the index set of the interleaved stream, and de-interleaving exactly inverts interleaving using rational-number arithmetic alone.
Proof - part one (reduction to Beatty form). The tuple-selection sequence for the de-interleaving residue (operator ∼Θ) has the form:
\[ \left( n + \left\lfloor \frac{nb}{a} \right\rfloor \right) _{n=0}^{\infty } \]
Its initial term (n = 0) equals 0; the terms for n ≥ 1 form the Beatty part. For n ∈ ℕ, by the property ⌊x + C⌋ = ⌊x⌋ + C, we have n + ⌊nb/a⌋ = ⌊n + nb/a⌋, so we seek α, α′ such that:
\[ \left( \left\lfloor \frac{n-\alpha ^{\prime }}{\alpha }\right\rfloor \right) _{n=1}^{\infty } = \left( \left\lfloor n\frac{a + b}{a} \right\rfloor \right) _{n=1}^{\infty } \]
Reading off the slope and the offset: with a shift of α′ = 0 we obtain α = a/(a+b), and the selection sequence restricted to n ≥ 1 is exactly:
\[ \mathcal{B}\!\left( \frac{a}{a + b}, 0 \right) = \left( \left\lfloor n\frac{a + b}{a} \right\rfloor \right) _{n=1}^{\infty } \]
Proof - part two (verifying the five postulates and determining the residue). We check the postulates of Fraenkel’s theorem in turn for α = a/(a+b), α′ = 0:
- The value α = a/(a+b) for a, b > 0 is greater than zero and less than one.
- The condition α + β = 1 is satisfied for β = b/(a+b).
- For α′ = 0 the postulate is equivalent to postulate 1.
- The postulate is vacuous, since α is a rational number.
- The smallest number q for which qα ∈ ℕ is q = (a+b)/gcd(a,b); then the condition 1/q ≤ α + α′ = α is satisfied, and the condition ⌈qα′⌉ + ⌈qβ′⌉ = 1 with α′ = 0 forces ⌈qβ′⌉ = 1, i.e. 0 < β′ ≤ gcd(a,b)/(a+b). Every admissible value generates the same sequence (the complement of the sequence B(a/(a+b), 0) in ℕ is unique); we take β′ = gcd(a,b)/(a+b).
The sequence complementing B(a/(a+b), 0) in the sense of Fraenkel’s postulates is therefore:
\[ \mathcal{B}\!\left( \frac{b}{a + b}, \frac{\operatorname{gcd}(a, b)}{a + b} \right) \]
After reindexing n ↦ n + 1, so that it runs from n = 0 - matching the selection sequences in the definition of de-interleaving - it takes the form:
\[ \left( \left\lfloor \frac{(n + 1) - \frac{\operatorname{gcd}(a,b)}{a+b}}{\frac{b}{a+b}} \right\rfloor \right) _{n=0}^{\infty } \]
Expanding the above expression:
\[ \left\lfloor \frac{(n + 1) - \frac{\operatorname{gcd}(a,b)}{a+b}}{\frac{b}{a+b}} \right\rfloor = \left\lfloor n\frac{a}{b} + n + \frac{a}{b} + 1 - \frac{\operatorname{gcd}(a, b)}{b} \right\rfloor \]
Comparing this - term by term for n ≥ 0 - with the tuple-selection sequence of the recovered stream (operator Θ):
\[ \left( n + \left\lceil \frac{(n + 1)a}{b} \right\rceil \right) _{n=0}^{\infty } \]
and factoring out the integer part n + 1 via the property ⌊x + C⌋ = ⌊x⌋ + C, the claim reduces (after substituting n for n + 1, so that n ranges over ℕ>0) to the identity:
\[ \left\lfloor n\frac{a}{b} - \frac{\operatorname{gcd}(a, b)}{b} \right\rfloor + 1 = \left\lceil n\frac{a}{b} \right\rceil ,\quad n \in \mathbb{N}_{>0} \]
Proof - part three (case analysis). Using the properties of the coefficient gcd(a, b), we consider two disjoint cases covering the entire domain.
Case 1: gcd(a, b) = b, i.e. a/b ∈ ℕ. Then n·a/b ∈ ℕ, so by the identity ⌊x⌋ = ⌈x⌉ ⟺ x ∈ ℤ we have ⌈n·a/b⌉ = ⌊n·a/b⌋, and by ⌊x + C⌋ = ⌊x⌋ + C:
\[ \left\lfloor n\frac{a}{b} - 1 \right\rfloor + 1 = \left\lfloor n\frac{a}{b} \right\rfloor \]
Both sides of the identity being proved coincide.
Case 2: b ∤ a, i.e. 1 ≤ gcd(a, b) < b and 0 < gcd(a,b)/b < 1.
If n·a/b ∉ ℤ, then by ⌊x⌋ + 1 = ⌈x⌉ ⟺ x ∈ ℝ ∖ ℤ we have ⌈n·a/b⌉ = ⌊n·a/b⌋ + 1. The fractional part of n·a/b is a nonzero multiple of gcd(a,b)/b, and hence at least gcd(a,b)/b; subtracting gcd(a,b)/b from n·a/b therefore cannot drop below the integer ⌊n·a/b⌋, whence:
\[ \left\lfloor n\frac{a}{b} - \frac{\operatorname{gcd}(a, b)}{b} \right\rfloor = \left\lfloor n\frac{a}{b} \right\rfloor \]
and the identity being proved holds.
If n·a/b ∈ ℤ, then ⌈n·a/b⌉ = n·a/b, and since 0 < gcd(a,b)/b < 1:
\[ \left\lfloor n\frac{a}{b} - \frac{\operatorname{gcd}(a, b)}{b} \right\rfloor = n\frac{a}{b} - 1 \]
which again gives the identity being proved.
Both selection sequences describing the de-interleaving operation are therefore - up to the unit reindexing from part two - Beatty sequences satisfying Fraenkel’s postulates for rational parameters: the pair B(a/(a+b), 0) and B(b/(a+b), gcd(a,b)/(a+b)) partitions the set ℕ, and together with the initial residue term 0 from part one - the set ℕ₀, the full index set of the interleaved stream. The recovered stream and the residue are therefore exact. ∎
✅ Note
Corollary (exact invertibility over the rationals). For streams with rational rates, the operators Θ and ∼Θ recover the component streams of φ(A, B) exactly (bit for bit): no tuple is lost, duplicated, or reordered relative to its component stream. The pair (φ; Θ, ∼Θ) therefore behaves like multiplication and division, and the pair (Σ; δ) like addition and subtraction, on the set of regular time series.
⚠️ Warning
The practical takeaway from this proof: the implementation must never leave the domain of rational numbers, not even momentarily. An implicit cast of an intermediate result to a floating-point number breaks the assumptions of the theorem above. Materialization into floating-point form must be deferred until an explicit application of the floor or ceiling operation.
Operator properties used in optimization
Based on the algebra presented, a number of properties of data streams can be shown. They have direct application in the data-management system - during query-plan optimization and result interpretation.
Disruption of event ordering
✅ Note
Theorem. The order of elements in a stream does not reflect the actual order in which the elements occurred in the real world.
Proof (by counterexample). Consider two streams:
Alpha(char),2: {1,2,3,4,5,6,...}
Epsilon(char),3: {a,b,c,d,e,f,...}
The expression φ(Epsilon, Alpha) produces the output stream:
Tau(char),6/5: {1,2,a,3,b,4,5,c,6,d,...}
In stream Tau, the tuple labeled c occurs after the tuple labeled 5. Yet tuple c appears in stream Epsilon at second 9, while tuple 5 appears in stream Alpha at second 10. The natural order of events has been violated in the resulting stream. Conclusion: when analyzing time embedded in streams, applying the de-interleaving operation is necessary to recover the original form of the data streams. ∎
Commutativity of summation
✅ Note
Theorem. The stream-summation operation, disregarding attribute order, is commutative.
Proof. Assume ∆a ≤ ∆b; the opposite case is symmetric. The first case of the sum definition gives, as the n-th element of stream Σ(A, B), the tuple:
\[ c_{n} = \left( a_{n},\ b_{\left\lfloor n\Delta_{a}/\Delta_{b} \right\rfloor} \right) \]
whereas for Σ(B, A) the roles of the arguments are swapped, and its second case applies (or, at ∆a = ∆b, its first), giving as the n-th element:
\[ c_{n} = \left( b_{\left\lfloor n\Delta_{a}/\Delta_{b} \right\rfloor},\ a_{n} \right) \]
Both streams carry ∆c = ∆a. They therefore coincide up to the order of the joined attributes. ∎
Interleaving alignment method
The interleaving operation is not commutative in general: since 0 < z < 1, at n = 0 the equality branch of the interleaving definition always applies, so the stream φ(A, B) begins with element b₀, while the stream φ(B, A) begins with element a₀. Interleaving is, however, equivariant with respect to time shifts matched to the streams’ rates - which is valuable for query-plan optimization.
In the causal realization a stream has the form \(\widehat{S}=((s_n,\Delta),W_S)\), where \(W_S\) is its startup tail.
The tail of an interleave with interval \(\Delta_c=\Delta_a\Delta_b/(\Delta_a+\Delta_b)\) follows from the operator definition.
Record \(i\) of \(\varphi(A,B)\) carries the content of record \(j(i)\) of exactly one component - the one the interleave definition selects in slot \(i\). Write \(\Delta_{s(i)}\) and \(W_{s(i)}\) for the interval and tail of the selected component. Record \(j(i)\) is determined at time \(\bigl(j(i)+1+W_{s(i)}\bigr)\Delta_{s(i)}\), while consumer slot \(i\) ends at \((i+1+W)\Delta_c\). The causality condition for every \(i\) is:
\[ W\ge \left\lceil\frac{\bigl(j(i)+1+W_{s(i)}\bigr)\Delta_{s(i)}}{\Delta_c}\right\rceil -1-i \]
Let \(\Delta_a/\Delta_b=p/q\), where \(p,q\in\mathbb{N}_{>0}\) and \(\gcd(p,q)=1\). Both the component selection and the residue determining \(j(i)\) repeat with period \(p+q\), so the maximum of the right-hand side over one period is the maximum over all records:
\[ W_{\varphi(A,B)} =\max_{0\le i<p+q}\left( \left\lceil\frac{\bigl(j(i)+1+W_{s(i)}\bigr)\Delta_{s(i)}}{\Delta_c}\right\rceil -1-i \right) \]
The formula is exact: it neither overshoots nor undershoots the event-model bound. Periodicity of the requirements means that the maximum over \([0,,p+q)\) equals the maximum over every full period starting at any threshold, including the stream’s logical origin.
For \(L=p+q\) and nonnegative tails \(W_A,W_B\), this maximum has a closed form:
\[ W_{\varphi(A,B)} =\max\left( \left\lceil\frac{W_A L}{q}\right\rceil,; \left\lceil\frac{(1+W_B)L+p-1}{p}\right\rceil-1 \right) \]
To derive it, consider the positions of each component’s records in the interleave:
\[ r_A(j)=\left\lceil\frac{(j+1)L}{q}\right\rceil-1, \qquad r_B(k)=\left\lfloor\frac{kL}{p}\right\rfloor \]
Substituting \(r_A(j)\) into the availability condition gives a difference of two ceilings. Its maximum is \(\lceil W_A L/q\rceil\), attained at \(j=q-1\), in the period’s last slot. For B the requirement is \(\lceil(k+1+W_B)L/p\rceil-1-\lfloor kL/p\rfloor\). Since \(\gcd(L,p)=1\), the residue \(kL\bmod p\) visits every value from 0 to \(p-1\). The maximum occurs at residue \(p-1\) and gives the formula’s second term. This also covers \(p=1\), whose only residue is 0.
exactInterleaveTail_closed in InterleaveTailExact.lean formalizes equality with the phase maximum; exactInterleaveTail_exact states that the maximum is the smallest tail satisfying the availability condition from any threshold onward. HashStartupLatency() computes the closed form for every period without scanning it. For zero input tails, \(W_{\varphi(A,B)}=\lceil(L-1)/p\rceil\).
The shift \(\tau_m\) does not change the emitted record sequence, but it does change the index at which that sequence appears: record \(n\) carries the content of record \(n-m\). Records with an index below \(O_S+m\) have no definition, hence
\[ O_{\tau_m(S)}=O_S+m, \qquad W_{\tau_m(S)}=\max\left(0,;W_S-m\right) \]
The tail decreases: record \(n-m\) is older than the current one and therefore all the more available - the slot deficit is \(W_S-m\) and is constant. Details and measurement: Tails, logical origins and operator observability.
✅ Note
Theorem (R1, commuting a shift with an interleave). If numbers i, k ∈ ℕ are chosen such that i·∆a = k·∆b (both arguments shifted by the same amount of time), then interleaving the shifted streams and the interleaving of the original streams shifted by the sum of these numbers have the same record sequence, the same interval and the same logical origin. Their tails satisfy an inequality - the factored side is never the later one.
Formally, with \(L:=i+k\):
\[ \operatorname{Obs}\Bigl(\varphi\bigl(\tau_{i}(A),\tau_{k}(B)\bigr)\Bigr) =\operatorname{Obs}\Bigl(\tau_{i+k}\bigl(\varphi(A,B)\bigr)\Bigr), \qquad i\Delta_{a}=k\Delta_{b},\quad i,k\in\mathbb{N} \]
\[ W_{\mathrm{RHS}}=\max\left(0,;W_{\varphi(A,B)}-L\right)\le W_{\mathrm{LHS}} \]
where \(\operatorname{Obs}\) is the value part of the observation (interval, logical origin, record sequence with its NULL map, descriptor, gap trace, materialization policy) - see Tails, logical origins and operator observability.
Proof.
Interval. Both sides arise from the same interleave, so both have \(\Delta_c=\Delta_a\Delta_b/(\Delta_a+\Delta_b)\).
Auxiliary step. From i·∆a = k·∆b it follows that
\[ \frac{i\Delta_a}{\Delta_c} =\frac{i\Delta_a(\Delta_a+\Delta_b)}{\Delta_a\Delta_b} =\frac{i\Delta_a}{\Delta_b}+i =k+i =L\in\mathbb{N}, \]
and symmetrically \(k\Delta_b/\Delta_c=L\). Shifting each argument by its own number of slots therefore corresponds to the same number \(L\) of result slots.
Record sequence and logical origin. Within one period the interleave takes \(i\) records from A and \(k\) records from B, filling exactly \(L=i+k\) slots of C. Shifting A by \(i\) and B by \(k\) therefore moves the mapping threshold of both components by exactly \(L\) result slots without changing their relative phase: \(O_{\mathrm{LHS}}=O_{\varphi(A,B)}+L=O_{\mathrm{RHS}}\). The content of a record at a given logical index is the same on both sides, because the choice of component depends only on phase, which is unchanged.
Tails. Let \(s(n)\in\{A,B\}\) denote the component selected in phase \(n\), and \(j(n)\) its index. Write the shifts as \(t_A=i\) and \(t_B=k\). After shifting, the component tail is \(W_s^{\prime}=\max(0,W_s-t_s)\ge W_s-t_s\). The intervals and the choice of component and its index in each interleave phase remain unchanged. Let \(R_n\) be the availability requirement from the phase formula above for tails \(W_A,W_B\), and \(R_n^{\prime}\) the requirement for \(W_A^{\prime},W_B^{\prime}\). The auxiliary step gives \(t_s\Delta_s/\Delta_c=L\in\mathbb{N}\) for both components. Monotonicity of the ceiling and its compatibility with shifts by the integer \(L\) give, in every phase:
\[ \begin{aligned} R_n^{\prime} &=\left\lceil \frac{(j(n)+1+W_{s(n)}^{\prime})\Delta_{s(n)}}{\Delta_c} \right\rceil-1-n\\ &\ge\left\lceil \frac{(j(n)+1+W_{s(n)}-t_{s(n)})\Delta_{s(n)}}{\Delta_c} \right\rceil-1-n =R_n-L. \end{aligned} \]
We take the maximum over the same full period \(p+q\), since the shifts do not change the interval ratio. Using nonnegativity of tails as well, we obtain:
\[ W_{\mathrm{LHS}} \ge\max\left(0,\max_{0\le n<p+q}R_n-L\right) =\max\left(0,W_{\varphi(A,B)}-L\right) =W_{\mathrm{RHS}}. \]
The closed form equals the phase maximum for every period, so this argument covers all interval ratios. ∎
⚠️ Scope of the theorem
Equality of tails does not hold. Counterexample: \(\Delta_a=1/10\), \(\Delta_b=1/5\), \(W_A=W_B=0\), \(W_{\varphi(A,B)}=2\), \(i=2\), \(k=1\), \(L=3\). Then \(W_{\mathrm{LHS}}=2\) while \(W_{\mathrm{RHS}}=\max(0,2-3)=0\). The unfactored side reads its components after their own shift, so it waits longer for the same content; the factored side reads it directly from the interleave.
Practical consequence: the rewrite rule \(\varphi(\tau_i(A),\tau_k(B))\to\tau_{i+k}(\varphi(A,B))\) is a latency optimization, not a neutral rewrite. It preserves the entire value part of the observation and never emits a record before its dependencies are determined, but the result is ready sooner.
In RQL, preserving values while shortening a tail depends on each record’s value coming solely from the records it reads. A
?VARread also depends on previous slots, so the compiler skips R1 in any plan that declares aVAR. This includes plans that can receive aDO SETrule later. See Compilation Passes.Regressions guarding this scope:
it_r1_identity_nulls,it_optimizer_ablation-factor-name-collision-semantic.
In the compiler, additional invariants preserve public stream field names, null value maps, and the materialization policy.
Why this matters
These properties establish the boundaries of correct stream transformations:
- Theorems 1 and 2 establish coverage of sample positions by interleaving and recovery of both components by de-interleaving, preserving the order within each component.
- The rational variant allows exact index mappings. The implementation must also check the limits of its numeric representation.
- Operator properties determine permitted rewrites and limits on interpretation. In particular, R1 preserves the value part of the observation but may reduce the startup tail, while interleaving does not preserve the general event order across its components.
The branch of mathematics in which these equations are situated is the theory of covering systems [4] within number theory. The paper A Deterministic Method for Processing Data Sequences [3] presents the historical derivation of the method.
ℹ️ Info
A numerical verification of the equations above - Python prototypes operating on rational numbers (the
Fractionlibrary) - can be found on the Model Implementation page and in the repository github.com/michalwidera/equations.
Connecting proofs to the implementation
The mathematical proofs concern the operator model. Their Lean formalization and the engine tests provide further levels of verification with distinct scopes. The sources are in the code repository’s math_proofs directory; the Lean project guide describes tool setup, proof checking, and Verso document generation.
| Property | Formalization in math_proofs/Profs/ |
|---|---|
| Sequential coverage by interleaving | InterleaveCovering.lean |
| Position partition and de-interleaving mappings | BeattyPartition.lean, Deinterleave.lean |
| Exact invertibility | ExactInvertibility.lean |
| Event-order counterexample and sum commutativity | EventOrder.lean, SumCommutativity.lean |
| Matched shifts R1 and causal execution | ShiftMatching.lean, CausalShift.lean |
| Periodicity, minimality, and closed form of the interleave tail | InterleaveTailExact.lean |
| Origins and minimum tails of sum, difference, deinterleave, AGSE, projection, and record windows | StartupBoundaries.lean |
| Composition of origin and tail rules across a plan graph, with operator instances | PlanComposition.lean, PlanInstances.lean |
| Value preservation after subplan substitution, including R1 | PlanValues.lean |
Machine-arithmetic counterparts of SOperations.hpp functions | CppArith.lean, EngineRules.lean |
For the whole plan, plan_defined_iff_origin characterizes where records are defined and plan_rules_least gives the least admissible tails. plan_tail_mono shows that increasing source tails cannot shorten plan tails. The model schedules record n at (n+1+W)·Δ for tail W and interval Δ. Theorems plan_substitution and r1_plan_admissible extend value preservation and non-increasing tails to downstream nodes, including public outputs. They assume EvalLocal, meaning that a record’s value depends only on the records it reads, and agreement between the unchanged nodes in both plans.
The rewrites in EngineRules.lean model selected C++ functions using checked int, int64, and __int128 arithmetic. Theorems establish agreement with the model under stated assumptions, including positive normalized intervals and indices in int range. They account for saturation at INT64_MAX where C++ applies it. The theorems that connect deinterleave to the affine model assume the interval relationship of an interleave.
- Check in Lean. Run
lake build Profsinmath_proofsto check the proofs../render.shalso checks the axiom dependencies of theorems fromProfs.*. The allowed axioms arepropext,Classical.choice, andQuot.sound. The proof of the positive-position partition uses Mathlib’s generalized Rayleigh theorem and covers the rational case needed by interleave. - Generate the oracle.
./gen-oracle.shrunsprofs_oracleand writes tables and hashes of source and toolchain inputs totest/UnitTest/proofOracle.hpp. The tables use model definitions and machine-arithmetic rewrites. They include small values and boundary points such as those nearINT_MAXandINT64_MAX. Rows for which the model yieldsnoneare marked, and tests omit C++ calls for those rows. - Compare with C++.
ut_proofOraclechecks the tables against functions fromSOperations.hpp, verifies the emission schedule, and checks the effects of R1 at compiled plan outputs. Agreement between the rewrites and the C++ and Boost code is checked by review and by tests over a finite set of cases. - Check for drift.
proof_driftchecks the oracle-input hashes and maps every theorem to a test or an explicit coverage status. Regenerate the oracle after changing proofs or tool versions. Proof manifest.
The proofs cover the plan model and rewrites of selected functions. The implementation of the compiler passes and the execution loop, VAR state, ad hoc changes, plan replacement, retention, and the timing of clock and DEVICE operations fall outside this model. Agreement of descriptors, NULL maps, gaps, materialization, and other C++ execution paths requires separate unit and integration checks. Integration Tests explains their role and distinguishes a coverage description from an execution result.