arXiv:2611.02451cs.PLNov 2026

Manuscript Offprint

arXiv:2611.02451

Vectorizing Recurrences over Semirings

Yihong Zhang, Bala Vinaithirthan, Karima Ma, Zachary Tatlock, Maaz Bin Safeer Ahmad, Andrew Adams

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 f(x)f(x) depends on previous values (e.g., f(x−1)f(x-1)). Recurrences are ubiquitous in many computational domains. The simplest form of a recurrence is a prefix sum of an input sequence gg:

f(x)=f(x−1)+g(x).f(x) = f(x-1) + g(x).

(Prefix Sum)

In signal processing, many classical filters can be expressed as recurrences. They are known as infinite-impulse response (IIR) filters. For example,

f(x)=1.8⋅f(x−1)−0.9⋅f(x−2)+g(x).f(x) = 1.8 \cdot f(x-1) - 0.9 \cdot f(x-2) + g(x).

(A Band-Pass Filter)

In computer graphics, an approximate distance transform is a recurrence with min and +:

f(x,y)=min⁡(f(x−1,y)+1,f(x,y−1)+1,f(x−1,y−1)+2,g(x,y)).f(x, y) = \min(f(x-1, y) + 1, f(x, y-1) + 1, f(x-1, y-1) + \sqrt{2}, g(x, y)).

(Distance Transform)

Sequence alignment algorithms in bioinformatics have a similar pattern, where ss is a score matrix and cgapc_{\text{gap}} is a constant gap penalty:

f(x,y)=max⁡(f(x−1,y−1)+s(x,y),f(x−1,y)+cgap,f(x,y−1)+cgap).f(x, y) = \max(f(x-1, y-1) + s(x, y), f(x-1, y) + c_{\text{gap}}, f(x, y-1) + c_{\text{gap}}).

(Needleman-Wunsch)

Even dynamic programming problems on LeetCode often reduce to computing recurrences:

f1(x,y)=max⁡(f1(x,y−1),f2(x−1,y−1)−g(y)),f_1(x, y) = \max(f_1(x, y-1), f_2(x-1, y-1) - g(y)), f2(x,y)=max⁡(f1(x,y−1)+g(y),f2(x,y−1)).f_2(x, y) = \max(f_1(x, y-1) + g(y), \quad f_2(x, y-1)).

(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 FF that satisfies

F=A⊗F⊕GF = A \otimes F \oplus G

over a semiring τ\tau. In this definition, AA is a convolution kernel (a finite array of coefficients, or taps), GG is the input signal (a stream of values), FF is the output signal, and convolution ⊗\otimes computes a sliding weighted sum of the signal by the kernel1^1. For example, by instantiated the recurrence over the arithmetic (semi)ring and letting AA be the kernel [0,1.8,−0.9][0, 1.8, -0.9], we obtain the band-pass filter above. Similarly, if we use the (min, +)-semiring and set the (2D) kernel to [∞,11,2]\begin{bmatrix} \infty, 1 \\ 1, \sqrt{2} \end{bmatrix}, 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., f(x)f(x) depends on f(x−1)f(x-1)), 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 F=A⊗F⊕GF = A \otimes F \oplus G. We define an algebra for recurrences parametrized by a semiring τ\tau. This algebra abstracts over the orders of recurrences2^2, 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.

References (23)