Manuscript Offprint
arXiv:2611.02451Vectorizing Recurrences over Semirings
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
YIHONG ZHANG, University of Washington, USA
BALA VINAITHIRTHAN, Stanford University, USA
KARIMA MA, Adobe, USA
ZACHARY TATLOCK, University of Washington, USA
MAAZ BIN SAFEER AHMAD and ANDREW ADAMS, Adobe, USA
Recurrences are ubiquitous in signal and image processing, bioinformatics, numerical computing, combinatorial optimization, and many other domains. Because recurrences seem inherently sequential, they are often implemented serially and thus do not leverage vector instructions in modern hardware. This leaves much of the available, often highly parallel, hardware underutilized.
In this paper, we present an algebra of recurrences over semirings and study algebraic identities that enable vectorization. Using our algebraic framework, we present a number of vectorizing transformations that yield efficient, vectorized implementations across various settings. These transformations naturally extend to 2D recurrences and mutual recurrences.
We implement the recurrence algebra and the vectorizing transformations in a compiler called VecRec. VecRec compiles recurrence programs to efficient vectorized C++ implementations. The generated kernels can achieve up to an order-of-magnitude speedup over serial implementations across a wide variety of recurrences. A case study in bioinformatics shows that they are competitive with, and in many cases better than, existing libraries with manually-crafted vectorization.
CCS Concepts: • Do Not Use This Code → Generate the Correct Terms for Your Paper; Generate the Correct Terms for Your Paper; Generate the Correct Terms for Your Paper; Generate the Correct Terms for Your Paper.
Additional Key Words and Phrases: Vectorization, Recurrences, Domain-specific languages, Compilers
1 Introduction
A recurrence defines a sequence of values, where each value depends on previous values (e.g., ). Recurrences are ubiquitous in many computational domains. The simplest form of a recurrence is a prefix sum of an input sequence :
(Prefix Sum)
In signal processing, many classical filters can be expressed as recurrences. They are known as infinite-impulse response (IIR) filters. For example,
(A Band-Pass Filter)
In computer graphics, an approximate distance transform is a recurrence with min and +:
(Distance Transform)
Sequence alignment algorithms in bioinformatics have a similar pattern, where is a score matrix and is a constant gap penalty:
(Needleman-Wunsch)
Even dynamic programming problems on LeetCode often reduce to computing recurrences:
(LeetCode 188. Buy/Sell Stock)
Authors' Contact Information: Yihong Zhang, yz489@cs.washington.edu, University of Washington, Seattle, USA; Bala Vinaithirthan, Stanford University, Stanford, USA; Karima Ma, Adobe, USA; Zachary Tatlock, ztatlock@cs.washington.edu, University of Washington, Seattle, USA; Maaz Bin Safeer Ahmad; Andrew Adams, Adobe, USA.
Zhang et al.
These tasks from signal processing, graphics, bioinformatics, and LeetCode are all instances of the same problem: computing an that satisfies
over a semiring . In this definition, is a convolution kernel (a finite array of coefficients, or taps), is the input signal (a stream of values), is the output signal, and convolution computes a sliding weighted sum of the signal by the kernel. For example, by instantiated the recurrence over the arithmetic (semi)ring and letting be the kernel , we obtain the band-pass filter above. Similarly, if we use the (min, +)-semiring and set the (2D) kernel to , we obtain the distance transform.
These recurrence relations are fundamental building blocks in their respective domains. Computing them efficiently is important, yet difficult. While modern vector instruction sets like AVX-512 allow computing 16 values at a time, these recurrences enforce dependencies on previous output values (e.g., depends on ), forcing a serial implementation.
Previous work has studied different aspects of speeding up these recurrences, such as multi-threading [4, 29], tiling [33], and data layout transformations [11]. This work takes a different approach: we vectorize recurrences through algebraic transformations. Unlike prior approaches that are tailored to specific application domains, our approach is general: we can vectorize a wide class of recurrences, including all those in our examples, with speedups of up to an order of magnitude. Core to our approach are the algebraic structures of the recurrences . We define an algebra for recurrences parametrized by a semiring . This algebra abstracts over the orders of recurrences, the numerical values of coefficients, and the concrete operators, retaining only their algebraic properties. We then present algebraic identities for recurrences over different semirings that enable vectorization for a wide range of real-world recurrences.
We instantiate the recurrence algebra and vectorizing transformations in a compiler dubbed VecRec. Given an input expression, VecRec exhaustively applies the transformation schemes to derive a set of vectorization-friendly alternative forms. It generates an efficient vectorized C++ kernel for each form and picks the best-performing kernel based on runtime. The generated kernels are significantly faster on a diverse set of recurrences and, in the bioinformatic domain, outperform state-of-the-art vectorized libraries.
2.1 Vectorizing a second-order digital filter
Consider the following band-pass filter again:
As written, this recurrence is not directly vectorizable: the data dependence of on prevents computing consecutive outputs in a single SIMD vector.
To break this dependence, we expand and simplify:
The convolution in this paper should not be confused with matrix multiplication. Intuitively, , where and are semiring operations.
The order of a recurrence is how far back it looks (Section 3.3). For example, prefix sum is a first-order recurrence.

Fig. 1. Vectorization techniques proposed in this paper. Fast associative scan and path-based decomposition apply to any recurrence, while dilation requires a time-invariant kernel over a ring or an idempotent semiring. VecRec use all applicable transformations and use profiling to find the fastest kernel.
After this substitution, no longer depends on , so we can compute two consecutive outputs in a single vector, as the following “vectorized” pseudocode shows:
Repeating this process for , , ..., lets us compute n elements in parallel.
This approach, however, creates too much extra work. Each substitution lets us compute one more element in parallel, but it also incurs one fused multiply-add (fma) with a non-recursive g term (e.g., ). The original recurrence takes 2 fmas to compute one element, while the n-times-substituted version takes vectorized fmas to compute elements in parallel, so we reduce the number of fmas used by times.
To do better, observe that by rearranging Equation 1, can be defined using and :
Using this to eliminate in Equation 2, we obtain a definition of in terms of and ,
Computing the auxiliary costs 2 additional fmas. We can apply the trick again to : expand , define in terms of and , and substitute. We now define in terms of and , moving the self-dependency from 2 to 4 elements away. In effect, this procedure doubles the distances between a recurrence's coefficients. We call it dilation.
By repeatedly applying dilation, we obtain a tower of definitions:
Here is the length-two vector of consecutive outputs (half-open, Python-style slice notation), is elementwise multiplication with scalars broadcast over vectors, and + is elementwise addition.
Zhang et al.
Each layer of the tower doubles the distance between coefficients. Moreover, since the definition of each does not depend on itself, we can compute the elements of in parallel, for any . In total, this tower of definitions requires vectorized fmas, but it can compute elements at once. In other words, steps of dilation reduce the number of fmas by .
This trick is known as scattered-lookahead [25] in digital circuit design but is largely overlooked in software, where it can yield significant speedups, as we will show: on an AMD Zen 5 CPU, dilating the above filter four times achieves a 4.86× speedup.
In this work, we systematically study such vectorization techniques. Dilation for arithmetic recurrences is just one of many transformations that enable vectorization; Figure 1 organizes the full set used in this paper by the algebraic property each exploits.
2.2 The recurrence algebra
We propose an algebra of linear, fixed-order recurrences, inspired by the Z-transform [24]. Central to our recurrence algebra are two types of values, kernels and signals, and two types of operations, convolution () and (pointwise) addition ().
Under this algebra, a recurrence is defined as a signal that satisfies . Here, and are the input and output signals, and is a convolution kernel. That is, is defined as the convolution of itself with a kernel , plus an external input . To avoid self-dependency (i.e., depending on ), we require the kernel to be causal: it is zero at the origin, i.e., .
The recurrence algebra is parametrized by the semiring it operates over. For instance, we can also interpret over the tropical semiring (, min, +, ), where is minimum and is addition. Tropical recurrences capture DP-style optimization problems such as the distance transform in image processing and sequence alignment in bioinformatics.
2.3 Identities of the recurrence algebra
The identities of the recurrence algebra express the vectorizing transformations in Section 2.1 cleanly. For instance, arithmetic is not just a semiring but a ring, so it has an additive inverse (subtraction), denoted as . This allows us to perform the following derivation.
Given a time-invariant arithmetic kernel , let us define and as the even and odd terms of , i.e., and , such that . We have
where is the identity kernel . This is exactly the dilation of Section 2.1: for , , , the new kernel matches the coefficients in Equation 5, but the algebraic form generalizes to kernels with any number of taps.
Similarly, we derive vectorizing transformations for idempotent, time-varying, and mutual recurrences from identities in our algebraic framework.
2.4 A vectorizing compiler for recurrences
We instantiate the recurrence algebra and the vectorizing transformations in a compiler, dubbed VecRec. Given an input recurrence, VecRec automatically synthesizes several equivalent, vectorization-friendly forms, emits efficient vectorized C++ code for each form, and selects the best-performing form by throughput. The generated kernel is efficient and pluggable into existing systems.
2.5 Paper organization
The rest of the paper is organized as follows. Section 3 introduces the syntax and semantics of the recurrence algebra and discusses the properties of and . Section 4 discusses the algebraic identities of the recurrence operator. Section 5 presents the vectorizing transformations of recurrences and extensions to two-dimensional recurrences and mutual recurrences. Section 6 describes our compiler implementation that generates vectorized kernels for recurrences. Section 7 evaluates our compiler on a diverse range of recurrences and presents a case study on bioinformatic recurrences.
3 Syntax and Semantics
This section formally defines the recurrence algebra, which captures convolutions and (linear) recurrences over different semirings and lays the foundation for our transformations. After defining its syntax and semantics, we present the properties of its non-recursive fragment.
3.1 Semirings and rings
The recurrence algebra is parametrized by a commutative semiring . A semiring is a tuple such that is a commutative monoid, is a monoid, distributes over on both sides, and is absorbing for ; that is:
An idempotent semiring, also known as a dioid, is a semiring that satisfies . A commutative semiring is a semiring that satisfies . A ring is a semiring in which every element has an additive inverse with .
Example 1 (Arithmetic ring). The real numbers form a commutative ring, with , and additive inverse . Recurrences over the arithmetic ring capture many recursive filters in signal processing.
Example 2 (Tropical semiring). The min-plus tropical semiring is , with , and . Addition is idempotent (), so this is an idempotent commutative semiring. It is not a ring because has no inverse. The tropical semiring appears in many combinatorial optimization problems, e.g., in bioinformatics. Similarly, the max-plus tropical semiring is defined as .
A (left) semimodule over a semiring consists of a set with an addition , a zero , and a scalar multiplication such that is a commutative monoid and the scalar multiplication is compatible with the semiring structure; that is, for all
Zhang et al.
and :
When is commutative, we call M a commutative semimodule.
3.2 Syntax
Fix a commutative semiring . The syntax of kernels and signals is shown in Figure 2. For the purpose of this section, kernels and signals are -dimensional. Section 6 specializes to 1D and 2D kernels and signals and discusses their efficient code generation. Throughout the paper we use as metavariables for signals and for kernels. We often denote by the external input signal and by the computed output signal.
A signal is either an input variable , a constant signal for (with slightly abused notation), an impulse , a pointwise addition , a pointwise multiplication , a convolution , a recurrence , or if is a ring. Note that convolutions and recurrences are defined between kernels and signals.
Fig. 2. Syntax for signals and kernels.
Fig. 3. The order defines the domain of a kernel. In the context of kernel orders, max is interpreted as the dimension-wise maximum of two vectors. Similarly, we say if is less than or equal to in every dimension.
A kernel is a finite -dimensional array of signals . We call the signals of a kernel its taps. A kernel is called a singleton if it only has one tap. Kernels can be tap-wise added or convolved . A kernel can be additively inverted if is a ring. We call the identity kernel and the zero kernel 0. The order defines the domain of a kernel and is shown in Figure 3. We define the time-delay kernel so that and is everywhere else. For instance, the one-dimensional delay kernel is defined as , and in the degenerate case . We use to denote convolved with itself times, , and . This notation will be justified later as we show convolution is associative (Section 3.4).
3.3 Semantics
The semantics of a signal over semiring is a mathematical function that maps each time index to a value in , and the semantics of a kernel is a finite, multi-dimensional array of signals, indexable by an offset . We say the signals in the array the taps of the kernel. Fix an environment that maps variables to semantic signal . We write and for the semantics of signal and kernel , respectively. Figure 4 shows the definitions of and .
Fig. 4. Semantics for signals and kernels.
We say a signal is time-invariant if its semantics is a constant function, i.e., . . We say a kernel is time-invariant if all of its taps are time-invariant. Otherwise the kernel is called time-varying.
Signals. Signals evaluate to functions from time indices to values in . They evaluate to at any negative index. A signal variable is evaluated by looking up the environment , and a constant signal is evaluated to at every non-negative index. The impulse is at the origin and elsewhere. Tap selection returns the taps of kernel at offset if defined and the zero signal otherwise. The operators and lift and to signals pointwise.
The expression convolves kernel A with signal F: it slides A across F, multiplying each tap by the correspondingly shifted signal and summing. At time n,
Convolving with the delay kernel delays the signal by i time steps, so is F shifted forward in time by i. In fact, any convolution can be written in terms of convolution with the delay kernel, i.e., .
Example 3. A finite impulse response (FIR) filter in signal processing is a convolution between a time-invariant kernel A and a signal G over the arithmetic ring. Consider the moving
Zhang et al.
sum . This is represented in the recurrence algebra as .
The recurrence denotes the unbounded sum . Equivalently, it computes the signal satisfying . The infinite sum is well-defined when is at offset 0. We call this condition causality, and it ensures that the recurrence does not depend on its own current value. We defer a detailed discussion of operator to Section 4.
Example 4. An infinite impulse response (IIR) filter in signal processing is a recurrence between a time-invariant kernel and an input signal over the arithmetic ring. Our band-pass IIR filter is represented in the recurrence algebra as , which is a second-order, time-invariant recurrence.
Kernels. A kernel denotes an array of signals: a literal denotes the array of denotations of its taps adds the kernels tap-wise (widening to the higher order), and negates tap-wise.
convolves the two kernels. The -th tap of the convolution collects every way of splitting across the two operands; it pairs a tap at delay with a tap at delay for . This splitting also shifts when the second coefficient is read. Recall that a tap at index denotes a contribution from steps back. Since the tap of already sits steps in the past, the coefficient of that meets it is taken from steps earlier as well, hence . If is time-invariant, its coefficients do not depend on time, so the delay has no effect and the expression recovers the familiar convolution sum. Putting everything together, we have the convolution evaluates to . at tap . Equivalently, we can also use the delay kernel to denote the time shift and denote the tap of the convolution as . This form is handy for algebraic simplification.
Example 5. Consider time-varying kernels and . The convolution is equivalent to
3.4 Properties of and
From the semantics, we can derive the algebraic properties of and .
Proposition 3.1. The operators and have the following properties:
If A and B are time-invariant, we additionally have commutativity .
Convolution is associative across both kernel-kernel and kernel-signal products, and it distributes over addition on both sides. Convolution is in general not commutative, because the order in which a tap is applied determines the time index at which its coefficient is read; when both kernels are time-invariant, however, convolution becomes commutative.
In fact, kernels form a semiring, and the time-invariant kernels form a commutative sub-semiring.
Proposition 3.2. Let be the set of all kernels. is a semiring. Additionally, let be the set of time-invariant kernels. Then is a commutative semiring.
Kernel-signal convolution connects kernels with signals, and it is naturally compatible with the kernel semiring. Indeed, the signals form a semimodule over the kernel semiring.
Proposition 3.3. Let be the set of all signals. forms a semimodule over the semiring , and it forms a commutative semimodule over the semiring .
To summarize, semirings and semimodules capture the algebraic structure of kernels and signals. The following example demonstrates the algebraic properties.
Example 6 (Convolving with time-invariant kernels). Consider again the 4-tap moving sum with . We can factor the kernel into and , and . By associativity, we have . Additionally, because and are time-invariant, we also have by commutativity. They correspond to different implementations of the moving sum. For instance, corresponds to a cascade of two filters: the inner filter first computes the pointwise sums , and the outer filter then adds pairs of that are two elements apart, i.e., .
A one-dimensional time-invariant kernel corresponds to a polynomial: is the coefficient list of , and convolution of time-invariant kernels is multiplication of their polynomials. By the fundamental theorem of algebra, any real polynomial factors into real factors of degree at most two, which bounds the order of a kernel's factors.
Lemma 3.4. Under the arithmetic ring over real numbers, any one-dimensional time-invariant kernel of order can be factored as where each has order less than or equal to 2.
See Appendix A for the proof. Signal processing often uses this factoring to trade off numerical stability and performance in filter design. For example, the moving-sum kernel is the polynomial , which is exactly the factorization above.
The following example shows why convolutions in general do not commute.
Example 7 (Convolving with time-varying kernels). Consider again time-varying kernels and . Let . By associativity, . Meanwhile, computes a different signal.
To confirm this in the explicit indexed form, let denote .
The functions and match the definitions of and , and they are not equivalent.
To summarize, this section presents the syntax and semantics of the recurrence algebra together with the properties of and . Next, we turn to the recurrence operator.
4 The recurrence operator
The recurrence operator Rec reifies the fixed point computation of recurrences into the language of kernels and signals. We first show that the semantics of is well defined and is equivalent to finding an that satisfies .
Zhang et al.
| Any commutative semiring | ||
|---|---|---|
| Unrolling | ||
| (A,B t.i.) | Commuting recurrence with convolution | |
| (A,B t.i.) | Commuting recurrences | |
| Ring (e.g., arithmetic ring) | ||
| Inverse of Recurrence | ||
| Fusion of Stacked Ring Recurrences | ||
| (A,B t.i.) | ||
| Fusion of Parallel Ring Recurrences | ||
| (A,B t.i.) | Dilation with Additive Inverse | |
| Decomposition of Squared Kernels | ||
| Change of Basis | ||
| Idempotent semiring (e.g., tropical semiring) | ||
| (A,B t.i.) | Dilation with Idempotence | |
| (A,B t.i.) | Fusion of Idempotent Recurrences | |
Fig. 5. Recurrence identities grouped by the class of semirings. "t.i." abbreviates time-invariant.
Lemma 4.1 (Equivalent definitions of Rec). Suppose is causal. is well-defined, and iff .
In the rest of the section, we present the algebraic identities of the Rec operator. We start with identities that hold for any semiring and then specialize to rings and idempotent semirings. Some of these identities directly enable vectorization, while others capture and give insight into transformations that practitioners use. Figure 5 summarizes these identities. We comment on their contexts and implications when applicable. The proofs are algebraic and deferred to the appendix.
4.1 Identities for recurrences over any semiring
We start with identities that hold over any semiring. First, we can unroll a recurrence.
Lemma 4.2 (Unrolling). For kernel A and signal G over any semiring,
Intuitively, instead of advancing the recurrence one step at a time with , we may take steps at once using the unrolled kernel , after pre-accumulating the contributions of the intermediate steps, , into the input.
The next two lemmas concern the commutativity of recurrences. Recall that time-invariant convolutions commute with each other. Indeed, time-invariant convolutions also commute with time-invariant recurrences, and time-invariant recurrences commute with each other.
Lemma 4.3 (Commutativity of recurrences). For time-invariant kernels A and B and signal G over any semiring,
These identities are helpful when implementing cascades of convolutions and recurrences.
Example 8. In image processing, repeated applications of box filters [8] are often used to approximate Gaussian filters. A box filter can be efficiently implemented as a cascade of a recurrence and a convolution: , where the 2D kernel computes the summed area table of the input image, and the 2D kernel computes the difference of the summed area table. Therefore, a Gaussian filter can be approximated as . Using commutativity, we can freely reorder the recurrences and convolutions in the cascade. For instance, we can fuse the convolutions together and derive .
4.2 Identities for recurrences over a ring
This section presents the identities that hold for recurrences over a ring.
Lemma 4.4 (Inverse of Recurrence). For kernel A and signal G over a ring,
The above lemma shows that when restricted to rings, convolution by is precisely the inverse to the recurrence . As an analogy, we can view as algebraically similar to computing the geometric series , and it holds that when the series converges. Similarly, applying undoes the recurrence and recovers the original input.
The next identity flattens a stack of ring recurrences into a single recurrence with a larger kernel.
Lemma 4.5 (Fusion of Stacked Ring Recurrences). For kernels A and B and signal G over a ring,
Sometimes we apply this identity in the opposite direction, decomposing a single recurrence into a stack of recurrences with smaller kernels.
Example 9. In the repeated box filter example, the recurrence kernel can be decomposed into a horizontal kernel and a vertical kernel using Lemma 4.5. Therefore, the implementation space of the repeated box filter consists of permutations of repeated convolutions with and repeated recurrences with and .
As a small digression, by the fundamental theorem of algebra, we can always decompose a one-dimensional time-invariant recurrence over the reals.
Lemma 4.6. Under the arithmetic ring over real numbers, the recurrence for which is a 1D time-invariant kernel of order can be decomposed into a stack of recurrences where each has order at most 2.
For time-invariant kernels, we have a similar identity for fusing a parallel sum of recurrences.
Lemma 4.7 (Fusion of Parallel Ring Recurrences). For time-invariant kernels A and B and signals G and H over a ring,
Applying the above lemma in the opposite direction decomposes a time-invariant recurrence into a parallel sum of recurrences. This is known as partial fraction expansion. Partial fraction expansion can help parallelize a high-order recurrence by decomposing it into simpler independent recurrences. Practitioners use the fusion and decomposition of stacked and parallel recurrences to trade off performance, parallelism, and numerical stability in digital filter design.
The next identity is the foundation for time-invariant ring recurrences.
Zhang et al.
Lemma 4.8 (Dilation with Additive Inverse). For time-invariant kernels A and B and signal G over a ring,
This identity proves the transformation in the motivating example in Section 2.1 by treating A and B as the even and odd splits of the original kernel.
The next two identities show how to decompose a recurrence with and how to change the kernel used in a recurrence; both follow from the identities above.
Lemma 4.9 (Decomposition of Squared Kernels). For kernel A and signal G over a ring,
Lemma 4.10 (Change of Basis). For kernels A and B and signal G over a ring,
4.3 Identities for recurrences over an idempotent semiring
The idempotence of addition, , enables a different set of identities. The identity below dilates recurrences over idempotent semirings.
Lemma 4.11 (Dilation with Idempotence). For time-invariant kernels A and B and signal G over an idempotent semiring,
This identity allows us to break a kernel into a sum of sub-kernels and dilate them independently.
Example 10. Consider distance transform over the -semiring. Let and , the dilation identity gives us . Applying the identity again by setting B to be the two other taps of the original kernel, we get
This computes two consecutive elements (i.e., and ) at a time. Moreover, because the new no longer depends on itself from the previous row, two rows can be computed in parallel with multi-cores. By choosing which tap to dilate, we obtain the desired shape of parallelism. For instance, dilating the tap at the zeroth row again computes four horizontal elements at a time with vectorization, while leaving the multi-core parallelism unchanged.
We can also fuse stacked recurrences by simply summing the kernels in the idempotent semirings.
Lemma 4.12 (Fusion of Idempotent Recurrences). For time-invariant kernels A and B and signal G over an idempotent semiring,
Compare this with fusion of stacked recurrence over a ring. In general, a stack of recurrences can double count the contribution of an algebraic path. For rings, this is corrected using subtraction, whereas for idempotent rings, double counting does not change the result.
5 Techniques for Vectorizing Recurrences
We now present techniques for vectorizing different types of recurrences. This section focuses on 1D recurrences and defers higher-dimensional recurrences to Section 5.3. We present four techniques: dilation for ring recurrences, dilation for idempotent recurrences, fast associative scan, and path-based decomposition. The first two follow from the algebraic identities of the previous section, and they apply only when the kernel is time-invariant and the semiring satisfies certain properties. Fast associative scan builds on a general transformation for prefix scans over associative operations [2, 17]. Path-based decomposition views convolution as aggregating over algebraic paths, and decomposes those paths by divide-and-conquer to expose vectorizable work. Unlike dilations, the latter two techniques apply to any type of recurrence, at the cost of smaller speedup.
Some of these techniques are not new. They have appeared in various forms in the literature, for example in multi-core parallelism or digital signal processing, usually within a specific domain. In relation to these works, our contribution is twofold: (1) we show that these techniques apply to SIMD vectorization, and (2) we distill them into an algebraic framework and, in some cases, generalize them. Section 8 discusses related work and our extensions to it.
5.1 Dilations for Time-invariant Recurrences
We present two dilation techniques, one for recurrences over rings and the other over idempotent semirings. Both require the recurrence to be time-invariant, because the underlying identities rely on commutativity. We call these techniques dilation because both transform a recurrence into another that doubles the strides between, or “dilates”, the taps of the kernel. Formally, we define the stride s of a 1D kernel K as the largest integer such that evaluates to the constant signal for all i not divisible by s. For instance, the stride of kernel is 1, and the stride of kernel is 2.
Ring recurrences. We use the identity in Lemma 4.8 to dilate ring recurrences. Recall that for time-invariant kernels and . Let be a kernel with stride and . Define as the kernel that only contains the taps of at multiples of 2s, and as the kernel that only contains the taps of at indices that are modulo 2s. We have . Applying the dilation identity yields . We claim that the new kernel has a stride of . To see this, first, has a stride of , and so does . Second, suppose has a non-zero tap at index . There must exist with such that are non-zero. As and , it follows that , so also has a stride of . Together, the new recurrence kernel has a stride of 2s, which doubles the stride of the original kernel .
We can likewise analyze the number of taps in the new term. If the original kernel has taps at indices , then the new recurrence kernel also has taps in general, at indices , and the new convolution kernel has taps.
If we apply dilation times, we obtain a new recurrence of the form where has taps that are strided by and has taps for . This allows us to compute elements of the recurrence in parallel.
A delay can further aid the dilation scheme. Consider the change of basis again. Let be the singleton kernel containing the first tap of . Then effectively removes the first tap of while respecting the stride of . In other words, the new recurrence kernel keeps the same number of taps and the same stride, but widens the vectorizable work from to , as dilation does. Unlike dilation, however, the new convolution kernel has only two taps.
Zhang et al.
Example 11. Consider the recurrence , where . Let . Applying the change of basis, the rewritten recurrence kernel is , and the incurred convolution kernel is . This lets us compute four values of at a time, at the cost of an additional two-tap convolution. Dilating this kernel instead would yield a convolution with , which has three taps.
Unlike dilation, applying delaying again does not double the vectorizable work, so it is best used as a replacement for the last step of dilation, saving taps in the convolution. In practice, the work saved by delaying may be offset by the less regular vector-shuffling patterns, so our compiler tries both dilation and delaying as the last step and picks the faster implementation based on profiling.
Idempotent recurrences. To dilate time-invariant idempotent recurrences, we use Lemma 4.11, which states that for time-invariant kernels and . Generalizing this identity, we have . This identity lets us extract a set of singleton kernels from a kernel and dilate them independently.
Unlike the dilation for ring recurrences, which works only in the 1D case, the dilation for idempotent recurrences extends naturally to 2D. For example, Example 10 showed how dilation can expose opportunities for multi-core parallelism across rows. Our compiler currently focuses only on vectorization and does not exploit such opportunities.
5.2 General Recurrences
We now describe techniques for vectorizing general recurrences. Unlike the previous section, we assume neither time invariance nor any additional property of the semiring. The two techniques below vectorize time-varying recurrences as well as time-invariant recurrences over semirings that lack additive inverses or are not idempotent. Neither technique dominates the other, and the best choice depends on the target architecture. For example, in our experience, Apple Silicon tends to prefer fast associative scan while AMD Zen family tends to prefer path decomposition.
5.2.1 Fast Associative Scan. Kogge and Stone [17] first observed that an -th order linear, time-invariant recurrence can be computed in parallel in logarithmic steps. The key idea is a general transformation that parallelizes prefix scans of arbitrary associative operators [2]; we show that it can also be used to vectorize recurrence relations. To illustrate, let where is a -tap kernel . Let us define @ as the matrix-vector and matrix-matrix multiply using , i.e., and . One step of the recurrence computation can be modeled as multiplication by a matrix:
Denote this matrix by M. Applying the transformation n times, we obtain
The @ operator is associative, which follows because distributes over and is associative. Hence, the identity above can be written as
, and the repeated @-product can be computed in steps using the standard fast exponentiation trick (i.e., ).
The power of can be used for vectorization in different ways. For example, on an architecture with vector lanes, a naive approach computes in steps and then computes as the dot product of the first row of with . Since the nearest self-dependency in the dot product is , vector instructions can compute values of at once. In pseudocode, this is expressed as
This form, however, uses only the first row of , even though each row of can compute at a different index. Ideally, with vector lanes, the power matrix should compute outputs in parallel .
We propose a more efficient scheme that interleaves the output computation. We compute only every -th value of the power matrix , which suffices to produce the full stream of . Specifically, we first de-interleave the stream of the initial tap matrix into streams, each produced at the rate of the original stream. We then fold over the de-interleaved streams to compute , and use fast exponentiation to compute . All of are produced at rate , so this does only the work of computing the full stream of . Finally, each matrix computes values of in parallel, and we interleave these to produce the stream of output values at the original rate. Figure 6 illustrates this computation scheme. Our compiler uses the WindowMap operator to encapsulate this interleave/de-interleave scheme (Section 6).

Fig. 6. Vectorization using fast associative scan.
5.2.2 Path-based Decomposition. The second approach to vectorizing general recurrences rests on the following insight: a recurrence computes the sums of all algebraic paths formed by the taps of . We can model this computation as a transition graph, in which each tap of the kernel is an edge, or a “jump”, and the values of are the initial weights. Specifically, the -th tap of represents a jump of length and weight at time .
To formalize this notion, let be the singleton kernels of , each containing one tap of . Define and for . Each is a singleton kernel
with its tap at index , and intuitively represents the sum of all algebraic paths of length . Define as the prefix scan of convolved with the input signal , i.e., . Intuitively, aggregates all algebraic paths of length up to , weighting each path by the sum of its weight and the initial weight from .
We could instead compute the full directly and use its first row to produce outputs, but this again uses only the first row and wastes work.
Zhang et al.
Example 12. Consider the kernel over the arithmetic ring. The singleton kernels are and . We have , , , and . aggregates the combinations of 's taps that sum to 3: a two-jump followed by a one-jump ( ), a one-jump followed by a two-jump ( ), and three one-jumps ( ).
Let be an input signal . . The -th value of is the sum of paths ending at . For instance, , the sum of 0-paths , 1-paths , 2-paths , and 3-paths .
The following lemma captures the intuition that the recurrence computes the sum of algebraic paths of every length.
Lemma 5.1. Let be a kernel and be a signal over any semiring. Define . We have .
The lemma follows by induction on the time index i, and the unbounded sum is well-defined by the same argument as for the well-definedness of .
Under this path-based interpretation, the following lemma states that we can decompose the computation of into two parts: a local contribution from paths of length less than , and a global contribution from paths that start outside the local -sized window. Only the global contribution has far self-references to .
Lemma 5.2. For any , we have
In this lemma, gives the local contribution, and each global contribution has the form aggregates the paths that traverse the local window, is the jump that leaves the local window, and is the continuation of the path. To enumerate the global contributions, we classify paths by the first jump out of the local window: we first enumerate , the length of that jump, and then , the position where it is made. The position must lie within the local window, i.e., , and the jump must leave it, i.e., .
The following two lemmas show how to divide-and-conquer the computation of and . Both take a similar form, classifying paths by the first jump out of the local window.
Lemma 5.3. For any where , .
Lemma 5.4. For any where , .
Taken together, these lemmas let us compute the recurrence in terms of and , and divide-and-conquer and into smaller pieces. Below, we give examples illustrating how to use these lemmas to vectorize . Figure 7 visualizes the used path decompositions.
Example 13. Consider a second-order time-varying recurrence where . Define the singleton kernels , and . We can compute in terms of :
This uses the identity to simplify the computation. The corresponding visualization shows that all algebraic paths of can be classified as paths from the local window

Fig. 7. Visual illustration of path decompositions for . Dashed line denotes a subtracted path.
(i.e., ), paths hitting (i.e., ), and paths skipping via a two-jump (i.e., ). Similarly, we can compute from .
Take for example. The visualization suggests the local paths that aggregates can be categorized into three classes: from a local window of , from outside the window and hitting x-8, and from outside the window and skipping x-8 via a two-jump.
Example 14. If we specialize the recurrence to rings, we can use the fact that to eliminate the dependence on .
This saves the work of computing and its dependencies. Intuitively, the decomposition says that to aggregate over all paths of length 15, we can consider paths that hit x-7 and paths that hit x-8, and then subtract paths that hit both x-7 and x-8.
Example 15. If we specialize the recurrence to idempotent semirings instead, we can again avoid , this time by relying on idempotence and intentionally double-counting the path .
There are several ways to divide and conquer a recurrence, and algebraic identities can rearrange it into forms that save even more work. The general forms in Lemma 5.3 and Lemma 5.4 are often not the most efficient, as they yield quadratically many terms and can introduce too many dependencies. Our compiler hard-codes the optimal decomposition for orders of 2 or fewer over rings and idempotent semirings, which covers the most common recurrences. Scaling to higher order recurrences is left as future work.
5.3 Extensions
We now extend the techniques of Section 5 to two-dimensional and mutually recursive recurrences.
Two-dimensional recurrences. Marginalization lets us treat a higher-dimensional recurrence as a one-dimensional one. For example, consider the 2D recurrence . Although depends on itself in the preceding row and column, we can marginalize (resp. ) over x into a family of 1D signals (resp. ) indexed by x. This gives , which is a prefix sum of and we know how to
Zhang et al.
type Kernel1D, Signal1D, Kernel2D, Signal2D
TimeInv : [Number] -> Kernel1D;
TimeVar : [Signal1D] -> Kernel1D;
Var : String -> Signal1D;
Convolve : (Kernel1D, Signal1D) -> Signal1D
Recurse : (Kernel1D, Signal1D) -> Signal1D
Convolve2D : (Kernel2D, Signal2D) -> Signal1D
Recurse2D : (Kernel2D, Signal1D) -> Signal2D
WindowMap : (n: Number, [Signal1D], [[Signal1D; n]] -> Signal1D) -> Signal1D
Repeater : (Signal2D -> Signal1D) -> Signal2D
Ith : (Signal2D, Int) -> Signal1D
ConvertLanes : forall T. (T, Int) -> T
Fig. 8. The domain-specific language used in VecRec. The full version is available in the appendix.
vectorize. This also matches how 2D recurrences are computed in practice: row by row, where all earlier rows have been computed when computing the current one.
In Section 6 we discuss how to generate code for 2D recurrences using a repeater operator Repeater , which lets refer to already-computed rows via .
Mutual recurrences. Mutual recurrences are a group of recurrences that depend on each other. For example, double exponential smoothing is a method that computes the interdependent smoothed value and trend value of a time series, and it can be expressed as a mutual recurrence:
The LeetCode problem from the introduction is also mutually recursive.
Mutual recurrences fit naturally into our framework: we lift signals to vectors of signals, and kernels to matrices of kernels. For instance, the double exponential smoothing recurrence can be expressed as a recurrence vector:
The same algebraic transformations and vectorizing techniques that work for standard recurrences also apply to recurrence vectors. Matrix multiplication, however, is not commutative in general, so we no longer have for kernel matrices and , even when the kernels within and are time-invariant. Therefore, we can apply only those vectorizing transformations that do not rely on commutativity, which excludes dilation.
6 The VecRec Compiler
In this section, we introduce VecRec, our compiler instantiation of the recurrence algebra. The recurrence algebra itself leaves many details of physical implementation unspecified. We first describe VecRec's domain-specific language (DSL), which exposes details relevant to physical execution, and then the codegen process that lowers the DSL into efficient vectorized C++ implementations.
VecRec uses a streaming computation model and exposes a run method that, when called, returns the current output vector(s) and advances the internal state. This interface assumes that neither the input nor the output is stored in memory; instead, it stores internally only the vectors needed to compute the output vectors.
6.1 VecRec's domain-specific language
Figure 8 shows a fragment of the VecRec syntax; the full syntax is available in the appendix. Here we omit some pointwise operators and the syntax for mutual recurrences. Mutual recurrences are supported with kernel matrix types and signal vector types, and operators like Convolve and Recurse are overloaded to accept kernel matrices and signal vectors.
Unlike in the recurrence algebra, signal and kernel types in VecRec are refined by dimension. VecRec considers only one- and two-dimensional kernels and signals, which suffice for our applications. Kernel1D and Kernel2D represent a list of taps and a matrix of signal taps, respectively, and each tap is a 1D signal. The signal types are more interesting. The one-dimensional signal type Signal1D streams one value at a time, while the two-dimensional signal type Signal2D streams a tuple of not only the current value but also the values from the previous rows in the same column. To motivate this distinction, consider the convolution for a 2D kernel . To compute its value at a point , we must fetch the values of at not only the current row but also the previous rows , based on the window defined by . In the streaming model, we must buffer the last rows of when is not already materialized (e.g., a 2D input signal).
TimeInv (resp. TimeVar) constructs 1D time-invariant (resp. time-varying) kernels and takes numbers (resp. 1D signals) as inputs. TimeInv2D and TimeVar2D are the analogues for 2D kernels. Var and Var2D construct 1D and 2D input signals.
Convolve and Recurse express 1D convolutions and recurrences, and they take and return 1D signals. The 2D convolution and recurrence operators have interesting type signatures. Convolve2D takes a 2D signal but returns a 1D signal. This is because a physical implementation of convolution reads a 2D window of rows from the input but does not buffer by itself. Recurse2D, in contrast, takes a 1D signal but returns a 2D signal. This is because a 2D recurrence convolves with its own outputs from previous rows and must cache these rows. Meanwhile, it does not require the input signal to be buffered (hence a 1D input signal).
A Repeater turns a procedure that produces 1D signals into a 2D signal. It computes the given 1D signal one row at a time, buffers the rows already produced, and feeds them as non-recursive inputs to the current row. Repeater() binds to the 2D signal that represents the previously computed rows, which uses to compute the current row. The Repeater expression returns a 2D signal that streams both the current row and the buffered rows. Ith destructs a 2D signal and extracts a 1D signal at a given row offset. Together they enable marginalization and let us express arbitrary 2D recurrences as 1D recurrences. In fact, VecRec desugars a Recurse2D into a Repeater expression: Recurse2D() Repeater(. Recurse(, Add(Convolve(, Ith()), ...)), where is a 1D kernel representing the -th row of the 2D kernel .
WindowMap de-interleaves lists of signals and is used by the fast associative scan. Given interleave factor , it splits each input into substreams, where substream takes every -th sample from offset ; it then runs its body on the substreams and interleaves the results back to full rate.
Each operator in VecRec is implicitly annotated with the number of lanes it operates over at a time. By default, an operator is annotated with the maximum number of vector lanes available to the hardware. The number of vector lanes in a recurrence, however, is bounded by the index of the first non-zero tap of the kernel. This bound can cause the vector lanes of a node to differ from those of its child or parent. We use ConvertLanes(, 1) to explicitly convert the vector lanes of to lanes. The number of lanes of must be either a divisor or a multiple of . In the physical implementation, if has fewer lanes than the specified , we repeat the physical execution
Zhang et al.
20
of for times, where is the number of lanes of . Otherwise, we compute on every -th invocation of the operator and split the output vector among calls.
6.2 Compiler implementation
We implement the recurrence identities of Section 4 and the vectorizing transformations of Section 5 as compiler passes. These passes enumerate combinations of transformations and vectorization factors to produce a set of distinct vectorized forms. We call each form a schedule. Among the set of schedules, the compiler uses runtime profiling to select the best one.
Given a schedule, the code generator must first infer (1) the number of buffered rows for 2D signals and (2) the number of lanes for each operator. We obtain the number of buffered rows needed for a 2D signal by collecting the th references to it and taking the maximum. For vector lane annotations, we use the maximum available lanes for non-recurrence nodes. For recurrence operators, the vector lanes are given by the position of the first non-zero tap. If the vector lane annotation of a node does not match that of its child, we fork the expression into two schedules: either we wrap the child with ConvertLanes, so that the child's annotation remains unchanged, or we recursively downgrade the vector lane annotations of the children to match the parent.
Example 16. Consider the recurrence Recurse(K1, Convolve(K2, Convolve(K3, g))), where the first non-zero tap of K1 is at offset 8 and the hardware supports up to 16 vector lanes. Initially, the Recurse node is annotated with 8 lanes and the two Convolves with 16 lanes, so the lanes of Recurse and Convolve differ. The compiler generates two versions of the annotations. In the first, it inserts a ConvertLanes node between Recurse and Convolve that converts from 16 lanes to 8 lanes. In the second, it recursively pushes Recurse's annotation down to its descendants. Both versions are considered for runtime profiling. However, the compiler never inserts a ConvertLanes node between two non-recursive nodes (e.g., between two Convolve nodes). □
Once a schedule is fully annotated with buffered rows and vector lanes, we lower it into a C++ struct. The code generator keeps a C++ template library of operator structs such as Recurse and Convolve. These structs operate over a register state struct, which wraps an array of vector types⁵. Operators read input vectors and write output vectors at given offsets of this array, and maintain internal state. For example, a Convolve keeps a window of the last input vectors that is enough for the next convolution, and a Recurse similarly keeps previously computed output vectors. The code generator traverses the tree bottom up and emits an operator for each distinct node. The resulting C++ struct is initialized and called from user code.
6.3 Determining the optimal unrolling factors
For each generated kernel program, we measure its throughput on random input signals. For the top 10% of kernels, we perform an additional sweep to find the optimal unrolling factors. A VecRec program can be unrolled horizontally and, for 2D recurrences, vertically. An unrolled program produces a tile of output vectors at a time. For 2D recurrences, vertical unrolling saves memory roundtrips that horizontal unrolling cannot, because the vertical dependencies already reside in registers and need not be loaded from memory⁶. Not all 2D recurrences benefit from vertical unrolling on all architectures, however, because vectorized kernels are often bound by register pressure (from the introduced convolutions) rather than memory bandwidth. It helps most on ARM, which offers more instruction-level parallelism.
⁵We use clang's vector extensions [5]. ⁶Horizontal unrolling saves no memory roundtrips because 1D operators always keep their internal state in vector registers.
7 Evaluation
We evaluate VecRec in two parts. First, we benchmark VecRec-generated kernels against real-world recurrence applications and LeetCode DP problems. To the best of our knowledge, most real-world recurrence implementations do not vectorize⁷, except for Intel IPP and Apple Accelerate, which have vectorized implementations for biquad filters. Therefore, we compare against Intel IPP and Apple Accelerate on biquad filters. For the rest of real-world applications and all LeetCode problems, we compare against performant, unvectorized baselines. In both cases, we demonstrate significant speedups. Second, we conduct a case study of bioinformatic recurrences, which many studies have sought to speed up with vectorization [6, 11, 28, 35]. To that end, we compare the kernels with vectorized implementations from state-of-the-art libraries, and integrate them into existing systems, showing up to 28% speedup on end-to-end pipelines. Together, our evaluation shows VecRec works on a broad range of recurrences, beats hand-tuned algorithms for specific ones, and provides state-of-the-art performance on diverse hardware.
We evaluate VecRec on three platforms that span different processor generations, microarchitectures, and instruction sets: Intel Skylake (Core i9-9960X, 2018), AMD Zen 5 (Ryzen Threadripper 9970X, 2025), and Apple Silicon (M2, 2022). The first two architectures support the AVX-512 instruction set with 512-bit operations. The M2's NEON instruction set supports only 128-bit operations, but it offers better instruction-level parallelism and can issue more instructions simultaneously.
7.1 Evaluation on recurrences in the wild
Most high-performance libraries for signal processing just run recurrences as scalar code, so we compare VecRec-generated kernels with Intel IPP and Apple Accelerate, two libraries with vectorized implementations for biquad filters. Both libraries's vectorization schemes incur the additional work that grows linearly with the exposed parallelism, while in ours it grows only logarithmically. Both libraries vectorize biquad filters with a fixed width of 4. The result is shown in Table 1. VecRec is faster than both vendor libraries by up to 5.38x.
| Benchmark | Skylake | Zen 5 | Apple M2 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Intel IPP (Melem/s) | Vec | Speedup (×) | Intel IPP (Melem/s) | Vec | Speedup (×) | Apple Accelerate (Melem/s) | Vec | Speedup (×) | |
| Biquad Filter | 770.4 | 2111.8 | 2.74 | 1168.5 | 6282.3 | 5.38 | 1827.8 | 3063.2 | 1.68 |
Table 1. Speedup over baselines from vendor libraries on biquad filters. We use IPP's ippsIIR_32f and Apple Accelerate's vDSP_deq22 for the comparison.
Next, we evaluate on a large class of recurrences that arise naturally in signal processing and numerical computing, many of which are critical in their respective domains. Here we highlight two rather unexpected applications of recurrences:
- Continued fraction: A continued fraction has the form and can be computed using the Wallis-Euler recurrence, defined by
As goes to infinity, converges to the continued fraction. An example of a continued fraction is to use the ratio of two consecutive Fibonacci numbers to approximate the golden ratio: . In general the coefficients are time-varying, and VecRec can vectorize such recurrences.
⁷This includes scipy.sosfilt, DSP.jl, ffmpeg, torchaudio, Faust.
Zhang et al.
| Benchmark | Skylake | Zen 5 | Apple M2 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Serial | Base (Melem/s) | Vec | Speedup (x) | Serial | Base (Melem/s) | Vec | Speedup (x) | Serial | Base (Melem/s) | Vec | Speedup (x) | |
| First-Order High Pass Filter | 331.9 | 417.5 | 2320.9 | 5.56 | 676.9 | 676.8 | 9510.6 | 14.05 | 349.9 | 348.4 | 4678.5 | 13.37 |
| Second-Order High Pass Filter | 248.9 | 396.1 | 2020.1 | 5.10 | 403.4 | 672.3 | 5939.3 | 8.83 | 205.4 | 316.8 | 2564.3 | 8.09 |
| Second-Order Band-Pass Filter | 497.0 | 440.4 | 2186.6 | 4.40 | 773.4 | 1098.9 | 7366.4 | 6.70 | 497.0 | 717.3 | 3016.6 | 4.21 |
| Box Filter | 248.2 | 239.8 | 1967.9 | 7.93 | 1032.4 | 539.6 | 6278.9 | 6.08 | 431.5 | 416.9 | 2960.7 | 6.86 |
| Repeated Box Filter | 89.9 | 92.6 | 852.2 | 9.20 | 246.7 | 235.7 | 2037.1 | 8.26 | 119.0 | 175.6 | 896.3 | 5.10 |
| Recursive Gaussian Filter | 248.9 | 249.0 | 1884.9 | 7.57 | 361.0 | 361.1 | 5721.9 | 15.85 | 218.9 | 194.4 | 2507.1 | 11.45 |
| Non-uniform Recursive Filter | 483.0 | 482.6 | 865.3 | 1.79 | 676.3 | 720.9 | 2761.0 | 3.83 | 317.0 | 350.2 | 1656.4 | 4.73 |
| Distance Transform | 281.9 | 268.8 | 1680.5 | 5.96 | 548.3 | 409.7 | 5038.8 | 9.19 | 272.0 | 427.9 | 1985.6 | 4.64 |
| Exponential Smoothing | 497.3 | 736.3 | 2431.3 | 3.30 | 773.6 | 773.7 | 10217.1 | 13.21 | 437.9 | 697.3 | 4873.3 | 6.99 |
| Double Exponential Smoothing | 199.1 | 411.0 | 1691.5 | 4.12 | 361.1 | 545.8 | 4368.8 | 8.01 | 205.5 | 346.5 | 1880.2 | 5.43 |
| Welford Variance | 438.8 | 173.0 | 1404.7 | 3.20 | 676.0 | 354.3 | 3708.6 | 5.49 | 248.7 | 250.1 | 1778.3 | 7.11 |
| Continued Fraction | 412.3 | 386.1 | 429.5 | 1.04 | 659.1 | 686.7 | 1505.6 | 2.19 | 276.6 | 456.0 | 1087.9 | 2.39 |
Table 2. Benchmarked throughputs for recurrence applications on the serial, baseline, and vectorized implementations across architectures. Speedup is Vec over the faster of Serial and Base.
| Benchmark | Skylake | Zen 5 | Apple M2 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Serial | Base (Melem/s) | Vec | Speedup (x) | Serial | Base (Melem/s) | Vec | Speedup (x) | Serial | Base (Melem/s) | Vec | Speedup (x) | |
| 10. Regular Expression Matching | 735.2 | 183.9 | 1772.8 | 2.41 | 1499.0 | 488.9 | 4405.0 | 2.94 | 1185.0 | 331.9 | 1862.5 | 1.57 |
| 91. Decode Ways | 719.1 | 394.4 | 542.7 | 0.75 | 1086.1 | 1080.0 | 3255.6 | 3.00 | 504.0 | 738.6 | 1870.9 | 2.53 |
| 121. Buy/Sell Stock | 1450.8 | 544.5 | 2187.9 | 1.51 | 1792.8 | 983.8 | 6907.1 | 3.85 | 1606.6 | 1455.7 | 2667.2 | 1.66 |
| 188. Buy/Sell Stock IV | 437.3 | 516.9 | 2158.2 | 4.18 | 844.9 | 1257.8 | 4336.8 | 3.45 | 404.1 | 717.5 | 2432.2 | 3.39 |
| 198. House Robber | 637.7 | 591.4 | 1169.7 | 1.83 | 978.8 | 898.6 | 3676.9 | 3.76 | 447.5 | 1409.9 | 1702.0 | 1.21 |
| 221. Maximal Square | 356.0 | 387.2 | 2182.3 | 5.64 | 772.8 | 415.1 | 6688.7 | 8.66 | 701.4 | 211.2 | 2713.0 | 3.87 |
| 304. Range Sum Query 2D | 1557.0 | 646.1 | 2327.9 | 1.50 | 2679.3 | 883.0 | 6406.4 | 2.39 | 1694.1 | 2080.4 | 3943.9 | 1.90 |
| 309. Buy/Sell Stock with Cooldown | 704.1 | 529.8 | 686.8 | 0.98 | 1019.5 | 1149.4 | 1709.9 | 1.49 | 597.0 | 740.0 | 944.6 | 1.28 |
| 746. Min Cost Climbing Stairs | 599.0 | 200.6 | 1206.4 | 2.01 | 983.2 | 308.8 | 2898.7 | 2.95 | 439.2 | 704.1 | 980.6 | 1.39 |
| 1143. Longest Common Subsequence | 282.8 | 714.6 | 2330.8 | 3.26 | 378.2 | 1414.3 | 6682.2 | 4.72 | 1092.4 | 803.2 | 3291.3 | 3.01 |
| 1458. Max Dot Product of Two Subsequences | 540.1 | 602.6 | 2312.6 | 3.84 | 901.6 | 1090.2 | 9837.0 | 9.02 | 1066.3 | 761.6 | 3065.4 | 2.87 |
| 3259. Max Energy Boost From Two Drinks | 213.7 | 282.3 | 549.0 | 1.94 | 653.4 | 513.5 | 1382.5 | 2.12 | 297.6 | 852.0 | 881.0 | 1.03 |
Table 3. Benchmarked throughputs on LeetCode problems.
- Cumulative variance: Given a list of values a, Welford's algorithm [34] computes the variances of all prefixes of a in linear time. It can be defined as the following cascade of recurrences:
VecRec can represent this recurrence and generate an efficient vectorized kernel, as Mean is a first-order time-varying recurrence and is a prefix scan.
For these, our baselines are ‘Serial’, a manual C++ implementation that computes the recurrences in serial loops, and ‘Base’, a kernel that VecRec produces but with vectorization disabled. We set the problem size to and measure the throughput. Table 2 shows the runtime on recurrences that arise naturally in signal processing and numerical computing. Base sometimes achieves higher throughput than Serial because VecRec unrolls the recurrence computation using a runtime profile. Serial can be faster if it hits a better compilation path in clang. The speedup is reported as VecRec over the higher throughput of Serial and Base.
Overall, VecRec achieves a speedup of to . The speedup tends to be bigger for time-invariant recurrences where dilation applies. Additionally, many benchmarks, including continued fraction and Welford variance mentioned above, consist of both recurrence operators and expensive pointwise operators like float division. Recurrence's self-dependencies prevent the rest of the
| Benchmark | Implementation | Skylake | Zen 5 | Apple M2 | |||
|---|---|---|---|---|---|---|---|
| Melem/s | × | Melem/s | × | Melem/s | × | ||
| Edit Distance | edlib | 4677.2 | - | 9615.0 | - | 7540.3 | - |
| VecRec | 3690.6 | 0.79 | 12061.1 | 1.25 | 3030.8 | 0.40 | |
| Needleman-Wunsch | parasail_scan | 2960.1 | - | 5829.0 | - | 1903.5 | - |
| WFA2 (65%) | 1417.9 | - | 2795.4 | - | 2113.1 | - | |
| parasail_striped | 1065.9 | - | 2328.2 | - | 1273.3 | - | |
| parasail_diag | 610.3 | - | 2008.4 | - | 1010.5 | - | |
| ksw2_gg2_sse | 1189.2 | - | 2302.0 | - | 1751.8 | - | |
| seqan3 | 172.5 | - | 288.3 | - | 226.8 | - | |
| VecRec | 3676.5 | 1.24 | 12002.0 | 2.06 | 3035.9 | 1.44 | |
| WFA2 (85%)† | 6124.0 | 1.67 | 11124.1 | 0.93 | 9859.8 | 3.25 | |
| Smith-Waterman | parasail_striped | 2611.8 | - | 5246.8 | - | 2220.3 | - |
| parasail_scan | 2750.3 | - | 4503.9 | - | 1604.3 | - | |
| parasail_diag | 587.5 | - | 1869.7 | - | 915.4 | - | |
| seqan3 | 158.0 | - | 253.1 | - | 200.9 | - | |
| VecRec | 2863.5 | 1.04 | 8150.4 | 1.55 | 2276.9 | 1.03 | |
| Affine Gap | parasail_scan | 3023.9 | - | 5789.0 | - | 1934.4 | - |
| parasail_striped | 1007.4 | - | 2187.2 | - | 1284.1 | - | |
| WFA2 (65%) | 767.5 | - | 1581.6 | - | 1191.3 | - | |
| parasail_diag | 617.0 | - | 1994.0 | - | 1025.8 | - | |
| ksw2_extd2_sse | 1456.9 | - | 2756.8 | - | 1809.2 | - | |
| ksw2_extz2_sse | 1877.5 | - | 3544.4 | - | 2864.3 | - | |
| ksw2_gg2_sse | 1195.9 | - | 2170.5 | - | 1892.5 | - | |
| VecRec | 4120.0 | 1.36 | 10835.0 | 1.87 | 3025.7 | 1.06 | |
| WFA2 (85%)† | 4279.7 | 1.04 | 8241.7 | 0.76 | 7543.7 | 2.49 | |
Table 4. Comparing VecRec with state-of-the-art vectorized libraries on sequence alignment algorithms of matrix size . The speedup is measured against the best-performing baselines. Ksw2 is run on Apple M2 via sse2neon. †For WFA2, runtime is proportional to sequence similarity and the 85% similarity reports WFA2's speedup over VecRec.
kernel from being vectorized, because packing/unpacking values in and out of a vector register is often uneconomical. By widening the available parallelism for the recurrence operators, our transformations let the entire kernel use vectorized instructions, so even non-recursive operators in a recurrence kernel benefit from our vectorization techniques.
We also collect a set of 12 recurrences from dynamic programming problems on LeetCode. These problems often exhibit diverse patterns, and no baselines are available. Table 3 shows the result of VecRec-generated kernels against manual C++ implementations and unvectorized baselines.
7.2 Case study on bioinformatic recurrences
Sequence alignment is built on four core recurrences that share the same basic structure: Edit Distance, Needleman-Wunsch, Smith-Waterman, and Affine Gap. Among them, Affine Gap is the most widely used and most complex [13, 16], consisting of three mutually recursive recurrences. These recurrences take time quadratic in the sequence length, and genetic data spans billions of characters [6, 11, 21, 38], so they are often the primary bottleneck in genomics pipelines [9, 18–20].
Runtime comparison. We implement all four recurrences in VecRec and compare them with existing libraries that use hand-tuned optimizations. Our baselines include ksw2, which compresses the recurrence using score differences [20, 32], parasail's striped and scan strategies, which vectorize cells from the previous row, parasail's diagonal strategy, which vectorizes independent cells along an antidiagonal [6], and seqan3, an optimized scalar implementation [26]. We also compare against WFA [21], which is algorithmically distinct and has performance proportional to
Zhang et al.
| Dataset | Minimap2 (ksw2) | Minimap2 (VecRec) | Speedup |
|---|---|---|---|
| ecoli-ultralong | 58,235 ms | 45,624 ms | 1.28× |
| ecoli-strains | 5,226 ms | 4,183 ms | 1.25× |
| pa-strains | 1,898 ms | 1,761 ms | 1.08× |
Table 6. End-to-end alignment time on ONT workloads with approximate maximum, banding, and z-drop flags disabled. ecoli-ultralong uses ultra-long E. coli reads, ecoli-strains uses E. coli strain sequences, and pa-strains uses Pseudomonas aeruginosa strain sequences. These results were obtained on the Zen 5 microarchitecture.
sequence similarity, and Edlib, which is specialized to edit distance and uses bit-packing to compute multiple cells within a single machine word [38].
Table 4 shows the evaluation results. Vectorized methods trade parallelism against memory locality. Ksw2 and diagonal vectorize fully independent antidiagonals at the cost of scattered memory access. Striped and scan keep access contiguous within a row but don't resolve the column's serial dependency. Using dilation, VecRec can both parallelize the serial dependency and preserve memory locality, providing up to 2.4× speedup over these libraries. On the other hand, edlib and WFA can outperform VecRec under specific conditions. Edlib's bitpacking optimization applies only to edit distance. WFA is faster at high sequence similarity and with small scoring parameters, but it requires scores to be strictly positive and does not support Smith-Waterman. In practice, however, sequences are often divergent [20, 23, 32], and scores can be large and negative [7, 15].
Optimizing end-to-end pipelines. Genomics pipelines use sequence alignment recurrences in performance-critical inner loops [9, 18–20]. Minimap2, a widely used long-read alignment tool, issues thousands to millions of small affine-gap recurrence calls in parallel via its alignment library ksw2 [20].
Ksw2 exposes several alignment modes trading accuracy for speed: exact alignment, which computes the full recurrence and guarantees the optimal score, and approximations such as early termination and reduced-precision scores, which users select based on their workload's error tolerance [20]. The approximations are tied to ksw2's reformulated recurrence
and antidiagonal traversal, so VecRec cannot support them directly; instead, it serves as a drop-in accelerator for the exact mode.
We compare VecRec with ksw2 on minimap2's exact mode. Exact computation is useful for noisy reads⁸ such as Oxford Nanopore Technologies (ONT) long reads [20]. On ONT datasets, minimap2 integrated with VecRec achieves up to 1.28× speedup over stock Minimap2 (Table 6).
Comparison to Reptile [33]. We compare VecRec against Reptile, a tiling framework for recurrences. VecRec outperforms Reptile by 2.37×, because Reptile generates only scalar code (Table 5). Reptile also lets an external kernel replace its inner loop as a black box, so we composed it with VecRec for sequence alignment, but this yielded no additional speedup. Reptile's optimal tile sizes are small and is covered by the unrolling VecRec already applies.
| 1024 | 2048 | 4096 | 8192 | |
|---|---|---|---|---|
| Untiled (ms) | 1.419 | 4.996 | 19.96 | 79.65 |
| Reptile (ms) | 0.947 | 3.788 | 15.15 | 60.56 |
| VecRec (ms) | 0.393 | 1.508 | 5.871 | 23.30 |
| Speedup | 2.41× | 2.51× | 2.58× | 2.60× |
Table 5. Smith-Waterman runtime for matrices, comparing untiled code, Reptile's best tiling, and VecRec. Tile sizes were 4–512 with the best being col 16, col 16, col 16, col 16.
⁸A DNA read is a fragment of DNA sequence output by a sequencer, and a noisy read is a read with a high error rate.
| Schedule | Speedup | Relative error | ||||
|---|---|---|---|---|---|---|
| Skylake | Zen 5 | Apple M2 | ||||
| Scalar | ||||||
| Dilation | ||||||
| Dilation + Delay | ||||||
| Fast associative scan | ||||||
| Path-based decomp. | ||||||
Table 7. Vectorization schedules for the second-order filter in float32, with poles at for a fixed . Speedup is over the scalar baseline. Error is measured as the relative distance from a scalar float64 evaluation on uniform random inputs, measured on Zen 5; means the kernel overflows.
| Benchmark | Skylake | Zen 5 | Apple M2 | |||
|---|---|---|---|---|---|---|
| Scan | Path | Scan | Path | Scan | Path | |
| Continued Fraction | ||||||
| Welford Variance | ||||||
Table 8. Fast associative scan vs. path-based decomposition on two applications based on time-varying recurrences. Speedup is measured over a scalar implementation.
7.3 Understanding vectorization schedules
To understand the characteristics of individual transformations, we vectorize one representative second-order filter with each of them. Table 7 shows their achieved speedup and accuracy. We measure the accuracy using three different configurations of the radius of the filter's poles. A larger radius makes the filter harder to evaluate accurately.
The result shows that, when applicable, dilation (possibly with delay) achieves the best speedup compared to other more general transformations. Dilation makes the kernel more accurate than scalar evaluation. While dilation + delay may provide additional speedups, it can become numerically unstable as gets closer to 1.
We also evaluate the two general transformations on two time-varying applications (Table 8). Neither dominates the other, so the best schedule can only be determined through run-time profiling.
8 Related Work
Several lines of work inspired this paper. Parallel algorithms for associative scans date back to Kogge–Stone adders [17, 30] and were popularized by Blelloch [2]. Our fast associative scan (Section 5.2.1) is essentially a reformulation of recursive doubling [2, 17] in the recurrence algebra. To turn it into efficient vectorized instructions, however, we propose a hardware-efficient scheme that interleaves the computation of vector lanes.
In digital signal processing (DSP), Robelly et al. [27] applies Blelloch [2]-style parallelism in digital signal processors, and Feinberg [12] vectorize IIR filters by unrolling the recurrence definitions, i.e., delaying. Our dilation for ring recurrences is known as scattered look-ahead in DSP literature[25]; we have shown the algebraic identities behind it.
In tropical semirings, Rong and Tan [29] described jump flooding for parallelizing distance transforms. This corresponds to our dilation transformation for idempotent recurrences (Lemma 4.11). Our dilation transformation slightly generalizes jump flooding by allowing different taps to be dilated by different amounts. For instance, a variant of the distance transform used in practice is . To compute a grid in parallel, we can let the two taps with coefficients
Zhang et al.
stay undilated and only dilate the rest, leading to a recurrence kernel . This is more efficient than classical jump flooding, which dilates every term.
Beyond the generalizations to prior work, we treat vectorization schemes as generic transformations over algebraic structures (e.g., rings and tropical semirings), so they are not confined to a particular domain: jump flooding, for instance, had never been applied to bioinformatics or many other DP problems, yet we show that it achieves significant speedups there. We also build a compiler to show that these approaches yield efficient SIMD vectorization, whereas prior work largely targeted DSP design or multicore parallelism.
In signal and image processing, prior work has developed parallel algorithms for computing time-invariant recursive filters [22]. We draw inspiration from RecFilter [4], a compiler that automatically generates high-performance parallel implementations of multi-dimensional time-invariant IIR filters. Their approaches to multi-core parallelism, however, do not directly extend to vectorization, because they require simultaneously loading from non-contiguous dimensions. Multi-core parallelism for recurrences (outer-loop) is orthogonal to this work (inner-loop). In fact, they complement each other: Table 6 shows that minimap2, a multi-threaded alignment library, is further sped up by VecRec's vectorization.
Recent domain-specific compilers for recurrences include RECUMA [31], which compiles recurrences to efficient implementations over dense and sparse arrays, and REPTILE [33], which explores tiling strategies. They handle a more general class of recurrences, including ones that aggregate over all previous values, for which auto-vectorization suffices. We focus on fixed-order recurrences, which require further techniques to vectorize efficiently.
Our recurrence algebra is inspired by recent semiring-based database languages [1, 3, 14]. Interestingly, DBSP [3], a language for incremental computation, is also inspired by signal processing and uses terminology from Z-transform. Unlike these works, our algebra is a semimodule rather than a semiring, because convolution does not apply between signals. Similar to our work, Elliott [10] casts convolution in terms of semirings and semimodules, unifying signal processing, polynomial multiplication, probability, and language recognition.
Hand-optimized sequence alignment libraries use two primary vectorization paradigms. Row-based approaches (e.g., Parasail's striped and scan [6, 11]) vectorize the dependency on the previous row, whereas antidiagonal approaches (e.g., Parasail's diagonal, ksw2 [32], and WFA [21]) vectorize along independent diagonals. To maximize performance, these libraries employ specialized optimizations: ksw2 leverages score differences for int8 compression, WFA uses search-based recurrences to accelerate highly similar sequences, and Edlib [38] packs into machine words. While these frameworks are restricted to specific scoring strategies, VecRec is scoring-agnostic and supports diverse alignment and score variants. End-to-end genomic pipelines such as minimap2 [20], BWA-MEM [19], Bowtie2 [18], and STAR [9] embed these libraries to process large-scale sequence data.
Our work is also inspired by Zhang et al. [36], who sped up recursive filters by first applying scattered lookahead and then accelerating the resulting convolution using Tensor Cores. In a similar vein, our techniques may be adapted to other hardware, including SIMT GPUs and matrix accelerators.
9 Conclusion and Future Work
In this paper, we present the recurrence algebra over semirings, which captures a wide variety of recurrences in the wild, we show a set of identities and transformations that effectively vectorize them, and we build the VecRec compiler based on these ideas. Experiments show that the compiler-generated kernels can be an order of magnitude faster than non-vectorized implementations and are competitive with expert-optimized vectorized libraries.
This paper focuses on linear recurrences over semirings, so natural next steps are nonlinear recurrences, such as the Mandelbrot set or Floyd-Steinberg dithering, and recurrences not over semirings, as in certain LeetCode problems. On the implementation side, we would like to apply our framework to the GPU's SIMT model. VecRec currently supports only transformations expressible in the recurrence algebra, which are shift-invariant (e.g., and are computed using the same scheme), yet many transformations in domain-specific libraries are not, such as bitpacking in edit distance and parasail's wavefront parallelism. Future work is thus a compiler that supports and combines different vectorization and multi-core parallelism schemes, as well as other transformations like loop reordering [31] and multithreading.
Acknowledgments
We thank the anonymous reviewers for their valuable feedback, Shoaib Kamil and Dan Suciu for their feedback on early versions of this work, and Shiv Sundram and Muhammad Usman Tariq for helping with the REPTILE experiment. This material is based upon work supported by the National Science Foundation under Grant Nos. 2232339 and 2312195. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
10 Disclosure of Use of AI in Research
AI tools assisted with implementing the compiler, particularly features needed for the bioinformatics-related case studies, developing the evaluation harness, and implementing C++ scalar baselines for the LeetCode and signal processing problems. AI tools were used for formatting and proofreading prose and for producing some initial paragraph drafts; these drafts were subsequently heavily edited by the authors.
11 Data Availability Statement
The source code of the VecRec compiler is available at https://github.com/yihozhang/vec-rec. The artifact additionally includes the evaluation harness necessary to reproduce the experiment in this paper, and it is available at https://doi.org/10.5281/zenodo.23330549 [37].
Zhang et al.
References
[1] Mahmoud Abo Khamis, Hung Q. Ngo, Reinhard Pichler, Dan Suciu, and Yisu Remy Wang. 2024. Convergence of datalog over (Pre-) Semirings. J. ACM 71, 2, Article 8 (April 2024), 55 pages. doi:10.1145/3643027
[2] Guy E. Bloelloch. 1990. Prefix Sums and Their Applications. Technical Report CMU-CS-90-190. School of Computer Science, Carnegie Mellon University.
[3] Mihai Budiu, Tej Chajed, Frank McSherry, Leonid Ryzhyk, and Val Tannen. 2024. DBSP: Incremental Computation on Streams and Its Applications to Databases. SIGMOD Rec. 53, 1 (May 2024), 87–95. doi:10.1145/3665252.3665271
[4] Gaurav Chaurasia, Jonathan Ragan-Kelley, Sylvain Paris, George Drettakis, and Fredo Durand. 2015. Compiling High Performance Recursive Filters. In Proceedings of the 7th Conference on High-Performance Graphics (Los Angeles, California). 85–94. doi:10.1145/2790060.2790063
[5] Clang Developers. [n.d.]. Clang Language Extensions. https://clang.llvm.org/docs/LanguageExtensions.html. Clang 23.0.0git documentation.
[6] Jeff Daily. 2016. Parasail: SIMD C library for global, semi-global, and local pairwise sequence alignments. BMC Bioinformatics 17, 1 (2016), 81. doi:10.1186/s12859-016-0930-z
[7] Margaret O. Dayhoff, Robert M. Schwartz, and Bruce C. Orcutt. 1978. A model of evolutionary change in proteins. In Atlas of Protein Sequence and Structure, Margaret O. Dayhoff (Ed.). Vol. 5. National Biomedical Research Foundation, Washington, D.C., 345–352.
[8] R. Deriche. 1990. Fast algorithms for low-level vision. IEEE Transactions on Pattern Analysis and Machine Intelligence 12, 1 (1990), 78–87. doi:10.1109/34.41386
[9] Alexander Dobin, Carrie A. Davis, Felix Schlesinger, Jorg Drenkow, Chris Zaleski, Sonali Jha, Philippe Batut, Mark J. P. Chaisson, and Thomas R. Gingersas. 2013. STAR: ultrafast universal RNA-seq aligner. Bioinformatics 29 1 (2013), 15–21. https://api.semanticscholar.org/CorpusID:268128107
[10] Conal Elliott. 2019. Generalized Convolution and Efficient Language Recognition. CoRR abs/1903.10677 (2019). arXiv:1903.10677 http://arxiv.org/abs/1903.10677
[11] Michael Farrar. 2007. Striped Smith-Waterman speeds database searches six times over other SIMD implementations. Bioinformatics 23, 2 (01 2007), 156–161. arXiv:https://academic.oup.com/bioinformatics/article-pdf/23/2/156/49820591/bioinformatics_23_2_156.pdf doi:10.1093/bioinformatics/btl582
[12] R.B. Feinberg. 1990. Vectorizing IIR filters. In International Conference on Acoustics, Speech, and Signal Processing. 1045–1048 vol.2. doi:10.1109/ICASSP.1990.116087
[13] Osamu Gotoh. 1982. An improved algorithm for matching biological sequences. Journal of Molecular Biology 162, 3 (1982), 705–708. doi:10.1016/0022-2836(82)90398-9
[14] Todd J. Green, Grigoris Karvounarakis, and Val Tannen. 2007. Provenance semirings. In Proceedings of the Twenty-Sixth ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems (Beijing, China) (PODS '07). Association for Computing Machinery, New York, NY, USA, 31–40. doi:10.1145/1265530.1265535
[15] Steven Henikoff and Jorja G. Henikoff. 1992. Amino acid substitution matrices from protein blocks. Proceedings of the National Academy of Sciences 89, 22 (1992), 10915–10919. doi:10.1073/pnas.89.22.10915
[16] Kazutaka Katoh and Hiroyuki Toh. 2008. Recent developments in the MAFFT multiple sequence alignment program. Briefings in Bioinformatics 9, 4 (2008), 286–298. doi:10.1093/bib/bbn013
[17] Peter M. Kogge and Harold S. Stone. 1973. A Parallel Algorithm for the Efficient Solution of a General Class of Recurrence Equations. IEEE Trans. Comput. 22, 8 (Aug. 1973), 786–793. doi:10.1109/TC.1973.5009159
[18] Ben Langmead and Steven L. Salzberg. 2012. Fast gapped-read alignment with Bowtie 2. Nature methods 9 (2012), 357–359. https://api.semanticscholar.org/CorpusID:205420407
[19] Heng Li. 2013. Aligning sequence reads, clone sequences and assembly contigs with BWA-MEM. arXiv: Genomics (2013). https://api.semanticscholar.org/CorpusID:14669139
[20] Heng Li. 2018. Minimap2: pairwise alignment for nucleotide sequences. Bioinformatics 34, 18 (09 2018), 3094–3100. arXiv:https://academic.oup.com/bioinformatics/article-pdf/34/18/3094/48919122/bioinformatics_34_18_3094.pdf doi:10.1093/bioinformatics/bty191
[21] Santiago Marco-Sola, Juan Carlos Moure, Miquel Moreto, and Antonio Espinosa. 2021. Fast gap-affine pairwise alignment using the wavefront algorithm. Bioinformatics 37, 4 (05 2021), 456–463. arXiv:https://academic.oup.com/bioinformatics/article-pdf/37/4/456/50359789/btaa777.pdf doi:10.1093/bioinformatics/btaa777
[22] Diego Nehab, André Maximo, Rodolfo S. Lima, and Hugues Hoppe. 2011. GPU-efficient recursive filtering and summed-area tables. ACM Trans. Graph. 30, 6 (Dec. 2011), 1–12. doi:10.1145/2070781.2024210
[23] Marcelo A. Nobrega and Len A. Pennacchio. 2004. Comparative genomic analysis as a tool for biological discovery. The Journal of Physiology 554, 1 (2004), 31–39. doi:10.1113/jphysiol.2003.050948
[24] A.V. Oppenheim, R.W. Schafer, and J.R. Buck. 1999. Discrete-time Signal Processing. Prentice Hall. https://books.google.com/books?id=Bv1SAAAAAMAAJ
[25] K.K. Parhi and D.G. Messerschmitt. 1989. Pipeline interleaving and parallelism in recursive digital filters. I. Pipelining using scattered look-ahead and decomposition. IEEE Transactions on Acoustics, Speech, and Signal Processing 37, 7 (1989), 1099–1117. doi:10.1109/29.32286
[26] René Rahn, Stefan Budach, Pablo Costanza, Marcel Ehrhardt, Jonathan Hancox, and Knut Reinert. 2018. Generic accelerated sequence alignment in SeqAn using vectorization and multi-threading. Bioinformatics 34, 20 (2018), 3437–3445. doi:10.1093/bioinformatics/bty380
[27] J. Robelly, G. Cichon, H. Seidel, and G. Fettweis. 2004. Implementation of recursive digital filters into vector SIMD DSP architectures. In 2004 IEEE International Conference on Acoustics, Speech, and Signal Processing, Vol. 5. V–165. doi:10.1109/ICASSP.2004.1327073
[28] Torbjørn Rognes. 2011. Faster Smith-Waterman database searches with inter-sequence SIMD parallelisation. BMC Bioinformatics 12 (2011), 221 – 221. https://api.semanticscholar.org/CorpusID:1731355
[29] Guodong Rong and Tiow-Seng Tan. 2006. Jump flooding in GPU with applications to Voronoi diagram and distance transform. In Proceedings of the 2006 Symposium on Interactive 3D Graphics and Games (Redwood City, California) (I3D '06). Association for Computing Machinery, New York, NY, USA, 109–116. doi:10.1145/1111411.1111431
[30] Harold S. Stone. 1973. An Efficient Parallel Algorithm for the Solution of a Tridiagonal Linear System of Equations. J. ACM 20, 1 (Jan. 1973), 27–38. doi:10.1145/321738.321741
[31] Shiv Sundram, Muhammad Usman Tariq, and Fredrik Kjolstad. 2024. Compiling Recurrences over Dense and Sparse Arrays. Proc. ACM Program. Lang. 8, OOPSLA1, Article 103 (April 2024), 26 pages. doi:10.1145/3649820
[32] Hajime Suzuki and Masahiro Kasahara. 2018. Introducing difference recurrence relations for faster semi-global alignment of long sequences. BMC Bioinformatics 19 (2018). https://api.semanticscholar.org/CorpusID:3395471
[33] Muhammad Usman Tariq, Shiv Sundram, and Fredrik Kjolstad. 2025. REPTILE: Performant Tiling of Recurrences. Proc. ACM Program. Lang. 9, OOPSLA2, Article 296 (Oct. 2025), 27 pages. doi:10.1145/3763074
[34] B. P. Welford. 1962. Note on a Method for Calculating Corrected Sums of Squares and Products. Technometrics 4 (1962), 419–420. https://api.semanticscholar.org/CorpusID:120126049
[35] Andrzej Wozniak. 1997. Using video-oriented instructions to speed up sequence comparison. Computer applications in the biosciences : CABIOS 13 2 (1997), 145–50. https://api.semanticscholar.org/CorpusID:18620993
[36] Yihong Zhang, Derek Gerstmann, Andrew Adams, and Maaz Bin Safeer Ahmad. 2026. Pushing Tensor Accelerators beyond MatMul in a User-Schedulable Language. In 2026 IEEE/ACM International Symposium on Code Generation and Optimization (CGO). 242–254. doi:10.1109/CGO68049.2026.11395214
[37] Yihong Zhang, Bala Vinaithirthan, Karima Ma, Zachary Tatlock, Maaz Bin Safeer Ahmad, and Andrew Adams. 2026. VecRec: A vectorizing compiler for recurrence kernels. doi:10.5281/zenodo.23330549
[38] Martin Šosić and Mile Šikić. 2017. Edlib: a C/C++ library for fast, exact sequence alignment using edit distance. Bioinformatics 33, 9 (05 2017), 1394–1395. arXiv:https://academic.oup.com/bioinformatics/article-pdf/33/9/1394/49038512/bioinformatics_33_9_1394.pdf doi:10.1093/bioinformatics/btw753
Zhang et al.
A Proof of theorems concerning the recurrence algebra
Lemma A.1. In the arithmetic ring over real numbers, any one-dimensional time-invariant kernel A of order n can be factored as where each has order less than or equal to 2.
PROOF. We can write as coefficients of a generating function , where is the coefficient of the -th tap of . The fundamental theorem of algebra states that can be factored into a product of real polynomials of degree at most 2, so we have , where each is either linear or quadratic .
B Proof of theorems concerning recurrences
Lemma B.1 (Equivalent definitions of Rec). Suppose is causal. is well-defined, and iff .
PROOF. We assert if the L1 norm is smaller than for any . This can be proved by induction on . Therefore, for a given index , we can pick any satisfying , and .
Fix any such . Then is well-defined and equal to . Therefore, the semantics of the unbounded sum is well-defined for any index .
(⇐) Suppose . For any k, we have
For any n, we can choose a k with so that
( ) Conversely, if then
B.1 Algebraic identities over any semiring
Lemma B.2 (Unrolling). For kernel A and signal G over any semiring,
PROOF.
Lemma B.3 (Commuting recurrence with convolution). For time-invariant kernels A and B and signal G over any semiring,
PROOF.
Lemma B.4 (Commuting recurrences). For time-invariant kernels A and B and signal G over any semiring,
PROOF.
B.2 Algebraic identities over rings
Lemma B.5 (Inverse of Recurrence). For kernel A and signal G over a ring,
PROOF. Let , so . Then
Lemma B.6 (Fusion of Stacked Ring Recurrences). For kernels A and B and signal G over a ring,
Zhang et al.
PROOF. Let , so and hence . Therefore
Lemma B.7 (Fusion of Parallel Ring Recurrences). For time-invariant kernels A and B and signals G and H over a ring,
PROOF. Let and , so and . Setting :
\begin{align*}(I\ominus A)\otimes(I\ominus B)\otimes F&=(I\ominus B)\otimes G\oplus(I\ominus A)\otimes H\ $ I\ominus A\ominus B\oplus A\otimes B)\otimes F&=(I\ominus B)\otimes G\oplus(I\ominus A)\otimes H\\F&=Rec\big(A\oplus B\ominus A\otimes B,(I\ominus B)\otimes G\oplus(I\ominus A)\otimes H\big).\end{align*}Lemma B.8 (Dilation with Additive Inverse). For time-invariant kernels A and B and signal G over a ring,
PROOF. Let , so . Multiplying by :
Lemma B.9 (Decomposition of Squared Kernels). For kernel A and signal G over a ring,
PROOF. By Lemma 4.5 with :
Lemma B.10 (Change of Basis). For kernels A and B and signal G over a ring,
PROOF. Let , so . Multiplying by :
\begin{align*}(I\oplus B)\otimes(I\ominus A)\otimes F&=(I\oplus B)\otimes G\ $ I\ominus A\oplus B\ominus B\otimes A)\otimes F&=(I\oplus B)\otimes G\end{align*}B.3 Algebraic identities over idempotent semirings
Lemma B.11 (Dilation with Idempotence). For time-invariant kernels A and B and signal G over an idempotent semiring,
PROOF. Since A and B are time-invariant and is idempotent, the binomial expansion collapses to
and therefore
Reindexing j by parity:
Lemma B.12 (Fusion of Idempotent Recurrences). For time-invariant kernels A and B and signal G over an idempotent semiring,
PROOF. Using the same expansion as in the proof of Lemma 4.11:
C Proof of path-based decomposition
Lemma C.1. Let F be a recurrence defined by . We have
PROOF.
Zhang et al.
□
Lemma C.2. For any n, p where p < n,
PROOF.
Lemma C.3. For any p, l where l < p
PROOF.
D VecRec's domain-specific language
Zhang et al.
type Kernel, Signal, Kernels, Signals <: Any type Kernel1D, Kernel2D <: Kernel type Signal1D, Signal2D <: Signal type Mat<K> <: Kernels for K <: Kernel type Vec<S> <: Signals for S <: Signal
TimeInv : [Number] -> Kernel1D; TimeInv2D : [[Number]] -> Kernel2D TimeVar : [Signal1D] -> Kernel1D; TimeVar2D : [[Signal1D]] -> Kernel2D
Num : Number -> Signal1D; Impulse : Number -> Signal1D Var : String -> Signal1D; Var2D : String -> Signal2D
SignalVec : [S] -> Vec<S> for S <: Signal VectorAt : (Vec<S>, Int) -> S for S <: Signal KernelMat : [[K]] -> Mat<K> for K <: Kernel
Repeater : (Signal2D -> Signal1D) -> Signal2D | (Vec<Signal2D> -> Vec<Signal1D>) -> Vec<Signal2D> Ith : (Signal2D, Int) -> Signal1D
KAdd, KConvolve : (K, K) -> K for K <: Kernel or K <: Kernels KNeg : K -> K for K <: Kernel or K <: Kernels
SAdd, PointwiseMul : (Signal1D, Signal1D) -> Signal1D | (Vec<Signal1D>, Vec<Signal1D>) -> Vec<Signal1D> SNeg : Signal1D -> Signal1D | Vec<Signal1D> -> Vec<Signal1D>
Convolve, Recurse : (Kernel1D, Signal1D) -> Signal1D | (Mat<Kernel1D>, Vec<Signal1D>) -> Vec<Signal1D> Convolve2D : (Kernel2D, Signal2D) -> Signal1D | (Mat<Kernel2D>, Vec<Signal2D>) -> Vec<Signal1D> Recurse2D : (Kernel2D, Signal1D) -> Signal2D | (Mat<Kernel2D>, Vec<Signal1D>) -> Vec<Signal2D>
WindowMap : (n: Number, [S], [[S; n]] -> S) -> S for S : Signal1D | Vec<Signal1D>
ConvertLanes : (T, Int) -> T for T <: Any
Fig. 9. The domain-specific language used in VecRec.