A linear-time algorithm that avoids inverses and computes Jackknife (leave-one-out) products like convolutions or other operators in commutative semigroups

Background Data about herpesvirus microRNA motifs on human circular RNAs suggested the following statistical question. Consider independent random counts, not necessarily identically distributed. Conditioned on the sum, decide whether one of the counts is unusually large. Exact computation of the p-value leads to a specific algorithmic problem. Given \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n$$\end{document}n elements \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$g_{0} ,g_{1} , \ldots ,g_{n - 1}$$\end{document}g0,g1,…,gn-1 in a set \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$G$$\end{document}G with the closure and associative properties and a commutative product without inverses, compute the jackknife (leave-one-out) products \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\bar{g}_{j} = g_{0} g_{1} \cdots g_{j - 1} g_{j + 1} \cdots g_{n - 1}$$\end{document}g¯j=g0g1⋯gj-1gj+1⋯gn-1 (\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$0 \le j < n$$\end{document}0≤j<n). Results This article gives a linear-time Jackknife Product algorithm. Its upward phase constructs a standard segment tree for computing segment products like \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$g_{{\left[ {i,j} \right)}} = g_{i} g_{i + 1} \cdots g_{j - 1}$$\end{document}gi,j=gigi+1⋯gj-1; its novel downward phase mirrors the upward phase while exploiting the symmetry of \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$g_{j}$$\end{document}gj and its complement \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\bar{g}_{j}$$\end{document}g¯j. The algorithm requires storage for \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$2n$$\end{document}2n elements of \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$G$$\end{document}G and only about \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$3n$$\end{document}3n products. In contrast, the standard segment tree algorithms require about \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n$$\end{document}n products for construction and \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\log_{2} n$$\end{document}log2n products for calculating each \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\bar{g}_{j}$$\end{document}g¯j, i.e., about \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n\log_{2} n$$\end{document}nlog2n products in total; and a naïve quadratic algorithm using \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n - 2$$\end{document}n-2 element-by-element products to compute each \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\bar{g}_{j}$$\end{document}g¯j requires \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n\left( {n - 2} \right)$$\end{document}nn-2 products. Conclusions In the herpesvirus application, the Jackknife Product algorithm required 15 min; standard segment tree algorithms would have taken an estimated 3 h; and the quadratic algorithm, an estimated 1 month. The Jackknife Product algorithm has many possible uses in bioinformatics and statistics.

© The Author(s) 2020. This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/. The Creative Commons Public Domain Dedication waiver (http://creativecommons.org/publicdomain/zero/1.0/) applies to the data made available in this article, unless otherwise stated in a credit line to the data.

A biological question
Circular RNAs (circRNAs) are single-stranded noncoding RNAs that can inhibit another RNA molecule by binding to it, mopping it up like a sponge. During herpesvirus infection, human hosts produce circRNAs with target sites that may bind herpesvirus microRNA (miRNA) [1] (see Fig. 1). Given a sequence motif, e.g., a target site for a miRNA, researchers counted how many times the motif occurs in each circRNA sequence. They then posed a question: is the motif unusually enriched in any of the circRNAs, i.e., does any circRNA have too many occurrences of the motif to be explained by chance alone? If "yes", the researchers could then focus their further experimental efforts on those circRNAs. Figure 1 illustrates a set of circRNAs with varying length, with a single miRNA motif occurring as indicated on each circRNA. Let i = 0, 1 . . . , n − 1 index the circRNAs; the random variate X i count the motif occurrences in the i-th circRNA; k(i) equal the observed count for X i ; and the sum S = n−1 i=0 X i count the total motif occurrences among the circRNAs, with observed total K = n−1 i=0 k(i). The following set-up provides a general statistical test for deciding the biological question. Let {X i : i = 0, 1, . . . , n − 1} represent independent random counts (i.e., non-negative integer random variates), not necessarily identically distributed, with sum S = n−1 i=0 X i . Given observed values X i = k(i) : i = 0, 1, . . . , n − 1 with observed sum K = n−1 i=0 k(i) , consider the computation of the conditional p-values P X i ≥ k(i)|S = K ( i = 0, 1, . . . , n − 1 ). The conditional p-values can decide the question: "Is any term in the sum unusually large relative to the others?"

A statistical answer
The abstract question in the previous paragraph generalizes some common tests. For example, the standard 2 × 2 Fisher exact test [2, p. 96] answers the question in the special case of n = 2 categories: each X i has a binomial distribution with common success probability p , conditional on known numbers of trials N i ( i = 0, 1 ). Although the Fisher exact test generalizes directly to a single exact p-value for a 2 × n table [3], the generalization can require prohibitive amounts of computation. The abstract question corresponds to a computationally cheaper alternative that also decides which columns in the 2 × n table are unusual [4].
To derive an expression for the conditional p-value, therefore, let g i [k] = P X i = k be given, so the array gives the distribution of X i , truncated at the observed total K = n−1 i=0 k(i) . Because g i is a truncated probability distribution, g i ∈ G , the set of all real ( K + 1)-tuples g[0], g [1], The truncation still permits exact calculation of the probabilities below. To calculate the distribution of the sum S = n−1 i=0 X i for S ≤ K , define the truncated convolution operation g = g ′ • g ′′ , for which Hereafter, the operation " • " is often left implicit: g ′ • g ′′ = g ′ g ′′ .
With the jackknife products in hand, the conditional p-values are a straightforward computation: With respect to Eq. (1) and the biological question in Fig. 1, Appendix B gives the count ḡ[K ] of the ways that n circRNAs of known but varying length may contain K miRNA motifs of equal length, the count g i [k] of the ways that the i th circRNA may contain k motifs, and the count ḡ i [K − k] of the ways that all circRNAs but the i th may contain K − k motifs. Appendix B derives the count g i [k] for circRNAs from the easier count for placing motifs on a linear RNA molecule. For combinatorial probabilities like P X i ≥ k(i)|S = K , Eq. (1) remains relevant, even if g i [k] are counts instead of probabilities. The biological question therefore exemplifies a commonplace computational need in applied combinatorial probability.
The Discussion indicates that in our application, transform methods can encounter substantial obstacles when computing Eq. (1) (e.g., see [6]), because the quantities in Eq. (1) can range over many orders of magnitude. This article therefore pursues direct exact calculation of P X i ≥ k(i)|S = K . The product forms of ḡ and ḡ j suggest that any efficient algorithm may be abstracted to broaden its applications, as follows. .

Semigroups, groups, and commutative groups
Let (G, •) denote a set G with a binary product g • g ′ on its elements. Let " g ∈ G " denote " g is an element of G ", and consider the following properties [7].
(1) Closure g • g ′ ∈ G for every g, g ′ ∈ G (2) Associative g • g ′ • g ′′ = g • g ′ • g ′′ for every g, g ′ , g ′′ ∈ G (3) Identity There exists an identity element e ∈ G , such that e • g = g • e = g for every g ∈ G (4) Commutative g • g ′ = g ′ • g for every g, g ′ ∈ G If the Closure and Associative properties hold, (G, •) is a semigroup. Without loss of generality, we assume below that the Identity property holds. If not, adjoin an element e ∈ G , such that e • g = g • e = g for every g ∈ G .
In addition, if the Commutative property holds for every g, g ′ ∈ G , the semigroup (G, •) is commutative. Unless stated otherwise hereafter, (G, •) denotes a commutative semigroup. The Jackknife Product algorithm central to this article is correct in a commutative semigroup.
As shown later, the Jackknife Product algorithm does not require the Inverse property. In passing, note that the convolution semigroup relevant to the circRNA-miRNA application lacks the Inverse property, as does any convolution semigroup for calculating p-values, e.g., the ones relevant to sequence motif matching [6]. To demonstrate, let X, Y ≥ 0 be independent integer random variates. The identity e for convolution corresponds to the variate Z = 0 , because 0 + X = X + 0 = X for every variate X . If X + Y = 0 , however, the independence of X and Y implies that both are constant and therefore X = Y = 0 . In the relevant convolution semigroup, therefore, all elements except the identity e lack an inverse.
The non-zero real numbers under ordinary multiplication form a commutative semigroup (G, •) with the Inverse property. They provide a familiar setting for discussing some algorithmic issues when computing ḡ j . Let ḡ = g 0 g 1 · · · g n−1 be the usual product of n real numbers, and consider the toy problem of computing all jackknife products ḡ j that omit a single factor g j ( 0 ≤ j < n ) from ḡ . Inverses g −1 j are available, so an obvious algorithm computes ḡ and then ḡ j =ḡg −1 j with n inverses and 2n − 1 = (n − 1) + n products. If the inverses were unavailable, however, the naïve algorithm using n − 2 element-by-element products to compute each ḡ j would require n(n − 2) products. The quadratic time renders the naïve algorithm impractical for many applications. Figure 1 illustrates a standard data structure called a segment tree, omitting the root at the top of the segment tree. Algorithms based solely on a segment tree can calculate the jackknife products ḡ j in time O n log n , fast enough for many applications. The segment tree computes segment products like g [i,j) = g i g i+1 · · · g j−1 without using the commutative property, so it can similarly compute jackknife products like ḡ j = g [0,j) g [j+1,n) . If the semigroup (G, •) is commutative, however, a Jackknife Product algorithm can avoid inverses and reduce the computational time further, from O n log n to O(n) . With in-place computations requiring only the space for the segment tree, the Jackknife Product algorithm avoids inverses yet still requires only about 3n products and storage for 2n numbers. It is therefore surprisingly economical, even when compared to the obvious algorithm using inverses. Indeed, our application to circular RNA required some economy, with its convolution of n = 3086 distributions, some truncated only after K = 997 terms. In a general statistical setting, convolutions form a commutative semigroup (G, •) without inverses, so our application already indicates that the Jackknife Product algorithm has broad applicability.

Theory
Appendix A proves the correctness of the Jackknife Product algorithm given below.

The Jackknife Product algorithm
Let (G, •) be a commutative semigroup. The Jackknife Product algorithm has three phases: upward, downward, and transposition. Its upward phase simply constructs a segment tree (see Fig. 1); its downward phase exploits the symmetry of g j and its complement ḡ j to mirror the upward phase while computing ḡ j (see Fig. 2); and its final transposition phase then swaps successive pairs in an array (not pictured). As Figs. 1 and 2 suggest, the three phases yield a simpler algorithm if n = n * = 2 m is a binary power. To recover the n * = 2 m algorithm from them, pad g j on the right with copies of the identity e up to n * elements, where n * = 2 m is the smallest binary power greater than or equal to n , i.e., replace g j with g 0 , g 1 . . . , g n−1 , e, . . . , e , with n * − n copies of e . The n * = 2 m algorithm can therefore pad any input of n elements up to n * = 2 m elements without loss of generality. The algorithm given below is therefore slightly more intricate than the n * = 2 m algorithm, but it may save almost a factor of 2 in storage and time by omitting the padded copies of e . In any case, the simpler algorithm can always be recovered from the phases for general n given here, if desired. We start with notational preliminaries. Define the floor function ⌊x⌋ = max j : j ≤ x and the ceiling function ⌈x⌉ = min j : x ≤ j (both standard); and the binary right-shift function ρ j = j/2 . Other quantities also smooth our presentation. Given a product ḡ = g 0 g 1 · · · g n−1 of interest, define m = log 2 n and n k = n2 −k for 0 ≤ k < m . Below, the symbol "□" connotes the end of a proof.

omments
(1) If n = n * = 2 m is a binary power, ρ n k−1 = n k = 2 m−k and the final line in the upward phase can be omitted. (2) Of some peripheral interest, Laaksonen [8] gives the algorithm in a different context, embedding a binary tree in a single array of length O(n) . If any L 0 [j] = g j changes, he also shows how to update the single array with O log n multiplications. If the downward phase (next) does not overwrite the segment tree {L k } by using in-place computation, it permits a similar update.

The downward phase
The transposition function We also require α k j = min τρ j , n k − 1 for 0 ≤ j < n k−1 and 1 ≤ k < m , the index of "aunts", as illustrated by Fig. 2. Just as Fig. 1 illustrates a rootless segment tree in the upward phase, Fig. 2 illustrates the corresponding rootless complementary segment tree in the downward phase.
In the next row up, as indicated by the arrow pairs leading into each circle, the array L 1 contains consecutive sums of consecutive disjoint pairs in L 0 , e.g., L 1[ 0] = 13 = 5 + 8 . The rest of the segment tree is constructed recursively upward to L m−1 , just as L 1 was constructed from L 0 . Here, 2 copies of the additive identity e = 0 pad out L 0 on the right. Padded on the right, the copies contribute literally nothing to the segment tree above them. Their non-contributions have dotted outlines  Fig. 3, e.g., contain 22 and 11. For each L k−1 j in Fig. 3, downward arrows run from L k α k (j) to L k−1 j . As they indicate, each node in L k contributes to its 2 "nieces" in Fig. 2 to produce the next row down in Fig. 3, e.g., L 2[ 1] = 11 contributes to its nieces L 1[ 0] = 13 and L 1[ 1] = 9 in the segment, to produce L 1[ 0] = 13 + 11 = 24 and L 1[ 1] = 9 + 11 = 20 in the complementary segment tree. The rest of the complementary segment tree is constructed recursively downward to L 0 , just as L 1 was constructed from L 2 . In Fig. 2, the elements of L 0 (in squares) total 33. To demonstrate the effect of the Jackknife Product algorithm, subtract in turn in Fig. 3 each  element (25, 28, 30, 27, 26, 29, 33, 33) in the bottom row L 0 from the total 33. The result (8, 5, 3, 6, 7, 4, 0, 0) is the bottom row L 0 in Fig. 2 with successive pairs transposed, so L 0 j =ḡ τ (j) , or equivalently ḡ j =L 0 τ (j) As Appendix A proves, the final array L 0 has elements L 0 τ j =ḡ j ( 0 ≤ j < 2ρ(n) ), with an additional final element L 0 [n − 1] =ḡ n−1 if n 0 = n is odd, so the Jackknife Product algorithm ends with a straightforward transposition phase.

Comments
The transposition phase can permit an in-place calculation of ḡ j to overwrite L 0 .

Computational time and storage
Note n j = n2 −j , so 0 ≤ n j − n2 −j < 1 . To compute L k from L k−1 or to compute L k from L k and L k+1 , the Jackknife Product algorithm requires n k products. For large n , therefore, the upward phase computing the segment tree requires about m−1 j=1 n j ≈ ∞ j=1 n2 −j = n products; the downward phase, about m−2 j=0 n j ≈ 2n products. Likewise, if the downward and transposition phases compute in place by replacing L k with L k and L 0 with ḡ j , the algorithm storage is m−1 j=0 n j ≈ 2n semigroup elements. Each of the three estimates just given for products and storage have an error bounded by m = log 2 n . Although the case of general n could be handled by the algorithm for binary powers n * = 2 m by setting m = log 2 n and g n = g n+1 = . . . = g n * −1 = e , the truncated arrays in the Jackknife Product algorithm for general n save about a factor of 1 ≤ n * /n < 2 in both products and storage.
As written, the conditional copy statements at the end of the upward and downward phases replicate elements already in storage. If the downward phase of the Jackknife Product algorithm is implemented with in-place computation of L k−1 [j] from L k−1 [j] , the copy statements ensure that the algorithm never overwrites any array element it needs later. Some statements may copy some elements more than once (and therefore unnecessarily), but a negligible m = log 2 n copies at most are unnecessary.
The complementary segment tree in Fig. 2 implicitly indicates the nodes in the segment tree required to compute L 0 τ j =ḡ j for each ḡ j , i.e., exactly one node in each row L k ( k = 0, 1, . . . , m − 1 ). Alone, the segment tree therefore requires at least n log 2 n multiplications to compute ḡ j .

Results
Appendix B gives the combinatorics relevant to the cir-cRNA-miRNA application described in "Background" section. As is typical in combinatorial probability, the quantities g i [k] were counts of configurations, here, the ways of placing miRNA motifs on circRNAs. The length of each motif was m = 7; the largest circRNA (hsacirc-0003473) contained I = 158,565 nt, and the most abundant motif (CCC AGC U, for the m12-9star miRNA family) appeared K = 997 times, so the g i [k] spanned thousands of orders of magnitude in Eq. (13) of Appendix B, from g i [0] = 1 to g I [K ] ≈ 10 2608 . In Eq. (1), the dimension K controls the number of terms in the convolutions. In the application, over each miRNA motif examined, the maximum number of motif occurrences on the circR-NAs was K = 997 . An Intel Core i7-3770 CPU computed the p-value relevant to the biological application on June 17, 2015. To compare later with estimated times for competing algorithms, the Jackknife Product algorithm with n = 3086 computed the relevant p-values in about 45 min, requiring about 3n products. In the application, therefore, n products required about 15 min.
The application of this article to circRNA-miRNA data appears elsewhere [1].

Discussion
This article has presented a Jackknife Product algorithm, which applies to any commutative semi-group (G, •) . The biological application to a circRNA-miRNA system exemplifies a general statistical method in combinatorial probability. In turn, the application in combinatorial probability exemplifies an even more general statistical test for whether a term in a sum of independent counting variates (not necessarily identically distributed) is unusually large. Many biological contexts lead naturally to sums of independent counting variates. Domain alignments of proteins from cancer patients, e.g., display point mutations in their columns. For a given domain, a column with an excess of mutations might be inferred to cause cancer [9]. The Background section gives the pattern: let X i represent the mutation count in column i = 0, 1, . . . , n − 1 , with total mutations S = n−1 i=0 X i . Given observed mutation counts X i = k(i) : i = 0, 1, . . . , n − 1 with observed sum K = n−1 i=0 k(i) , the conditional p-values P X i ≥ k(i)|S = K ( i = 0, 1, . . . , n − 1 ) can decide the question: "Does any column have an excess of mutations?" The actual application used other, very different statistical methods [9]. Unlike those methods, however, our methods can incorporate information from control (non-cancer) protein sequences to set column-specific background distributions for {X i }.
The Benjamini-Hochberg procedure for controlling the false discovery rate in multiple tests requires either independent p-values [10] or dependent p-values with a positive regression dependency property [11]. Loosely, the positive regression dependency property means that the p-values tend to be small together, i.e., under the null hypothesis, given that one p-value is small, then the other p-values tend to be smaller also. Inconveniently, our null hypothesis posits a fixed sum of independent counting variates, so if one variate is large and has a small p-value, it tends to reduce the other variates and increase their p-values. The circRNA-miRNA application therefore violates the statistical hypotheses of the Benjamini-Hochberg procedure. Fortunately, in the circRNA-miRNA application, a Bonferroni multiple test correction [12] sufficed because empirically, any p-value was either close to 1 or extremely small.
The Results state that for n = 3086 , the Jackknifed Product algorithm computed the relevant p-values in about 45 min, with n products requiring about 15 min of computation. In contrast, the naïve algorithm avoiding inverses and requiring n(n − 2) products would have taken about 3086 * 15 min, i.e., about 1 month. As explained under the "Computational Time and Storage" heading in the Theory section, without exploiting the special form of the jackknife products ḡ j , a segment tree requires about n products for its construction and at least n log 2 n products for the computation of the products ḡ j . Alone, segment tree algorithms would therefore have taken a minimum of about 1 + log 2 3086 * 15 min, i.e., about 3 h.
The convolutions in Eq. (1) might suggest that jackknife products are susceptible to computation with Fourier or Laplace transforms, which convert convolutions into products. "Results" section notes that in the biological application, however, g i [k] in Eq. (1) spanned thousands of orders of magnitude, at least from g i [0] = 1 to g I [K ] ≈ 10 2608 , obstructing the direct use of transforms (e.g., see [6]). On one hand, the widely varying magnitudes necessitated an internal logarithmic representation of g i [k] in the computer, a minor inconvenience for direct computation with the Jackknife Product algorithm. On the other hand, they might have presented a substantial obstacle for transforms. The famous Feynman anecdote about Paul Olum's tan 10 100 problem indicates the reason [13]: So Paul is walking past the lunch place and these guys are all excited. "Hey, Paul!" they call out. "Feynman's terrific! We give him a problem that can be stated in ten seconds, and in a minute he gets the answer to 10 percent. Why don't you give him one?" Without hardly stopping, he says, "The tangent of 10 to the 100th. " I was sunk: you have to divide by pi to 100 decimal places! It was hopeless.
The Jackknife Product algorithm also abstracts to any commutative semigroup (G, •) , broadening its applicability enormously. As usual, abstraction eases debugging. Consider, e.g., the commutative semigroup consisting of all bit strings of length n under the bitwise "or" operation. If the bit string g j has 1 in the j-th position and 0 s elsewhere, then the segment product g [i,j) equals the bit string with 1 s in positions [i, j = i, i + 1, . . . , j − 1 and 0 s elsewhere. Similarly, the complementary segment product g [i,j) = g [0,i) g [j,n) equals the bit string with 0 s in positions [i, j = i, i + 1, . . . , j − 1 and 1 s elsewhere. The Jackknife Product algorithm is easily debugged with output consisting of the segment and complementary segment trees for the bit strings.
As a final note, even if a semigroup (G, •) lacks the Commutative property, the general product algorithm for a segment tree can still compute ḡ j = g [0,j) g [j+1,n) in time O n log n . In a commutative semigroup (G, •) , however, the downward phase of the Jackknife Product algorithm exploits the special form of the products ḡ j to decrease the time to O(n).

Conclusions
This article has presented a Jackknife Product algorithm, which applies to any commutative semi-group (G, •) . The biological application to a circRNA-miRNA system uses a commutative semigroup of truncated convolutions to exemplify a specific application to combinatorial probabilities. In turn, the specific application in combinatorial probability exemplifies an even more general statistical test for whether a term in a sum of independent counting variates (not necessarily identically distributed) is unusually large. The general statistical test can evaluate the results of searching for a sequence or structure motif, or several motifs simultaneously. As "Discussion" section explains, the test violates the hypotheses of the Benjamini-Hochberg procedure for estimating false discovery rates, but fortunately the Bonferroni and other multipletest corrections remain available to control familywise errors. Abstraction from convolutions to commutative semi-groups broadens the algorithm's applicability even further. If an application only requires jackknife products ḡ j and their number n is large enough, "Results" and "Theory" sections show that the linear time of the Jackknife Product algorithm can make it well worth the programming effort.
like the corresponding set-theoretic complements of intervals.
The Commutative property is required to justify the correspondence between set-theoretic operations and products, e.g., the equality [i, j • [i, k) = [j, k commutes the segment products: examine, e.g., the second equality in the equation Proof See Fig. 1. The array L * 0 at generation k = 0 initializes the upward phase, where Thus, Proposition 2 is true for k = 0 . Given the array L * k−1 at generation k − 1 in the upward phase, the array L * k at level k contains products of successive adjacent pairs of elements in L * k−1 : for 0 ≤ j < n * k = n * k−1 /2 . The upward phase terminates with L * m−1 = 0, 2 m−1 , 2 m−1 , 2 m , so Proposition 2 is true for 0 ≤ k < m . □

Proposition 3
For
Proof See Fig. 2. For 0 ≤ j < n * m−1 = 2 , the first two lines of pseudo-code in the downward phase and Proposition 2 for k = m − 1 show that for j ∈ {0, 1}, (4) so Proposition 3 holds for k = m − 1 . We proceed by descending induction on k.
Proof of correctness for general n ≥ 2 : For general n ≥ 2 , initialize the upward phase with L 0 = g 0 , g 1 , . . . , g n−1 . To apply the results of the previous subsection, let n * = 2 m be the smallest binary power greater than or equal to n , i.e., let m = log 2 n . If n < n * , set g n = g n+1 = · · · = g n * −1 = e , with the arrays L * k and L * k of length n * k ( 0 ≤ k < m ) as above. For general n ≥ 2 , consider the computation of the arrays L k ( 0 < k < m ) in the upward phase of the pseudocode above.
We prove Proposition P(k) (next) by induction on the level 0 ≤ k < m.
for 0 ≤ j < n k , and L * k [j] = e for n k ≤ j < n * k .
Proof See Fig. 1. By construction, P(0) holds. With P(k − 1) in hand, the upward phase and Eq. (4) show that L k [j] = L * k [j] for 0 ≤ j < ρ n k−1 . On one hand, if n k−1 is even, ρ n k−1 = n k , yielding P(k − 1) immediately. On the other hand, if n k−1 is odd, ρ n k−1 = n k−1 /2 − 1 = n k − 1 , so the second equality reflecting the copy of the final element of L k−1 in the pseudocode; the third and fifth, P(k − 1) ; and the sixth, Eq. (4). Equation (8) completes the proof that L k [j] = L * k [j] for 0 ≤ j < n k . For the remaining indices n k ≤ j < n * k of L * k , note that In the downward phase, the transposition function τ in Eq. (7) facilitates in-place computation for L * k−1 [j] in Eq. (7). Similarly, the minimization in the accessory index α k j = min τρ j , n k − 1 within L k avoids storing a superfluous element ḡ of L * k within the penultimate element of any truncated complementary array L k (see L * 1 [3] , the dotted circle in Fig. 2). We prove Proposition P (k) (next) by descending induction on the level 0 ≤ k < m.
for 0 ≤ j < n k , unless n k is odd and j = n k − 1 , in which case L k [n k − 1] =L * k [n k ].
If 0 ≤ j < n k−1 , then 0 ≤ ρ j < n k−1 /2 = n k . For every j , either: (1) n k is odd and ρ j = n k − 1 ; (2) n k is odd and ρ j < n k − 1 ; or (3) n k is even. In Case 1, τρ j = n k but α k j = n k − 1 . Because n k is odd, P (k) implies L k α k j =L k [n k − 1] =L * k [n k ] =L * k τρ j . In Case 2, 0 ≤ α k j = τρ j < n k − 1 , or in Case 3, 0 ≤ α k j = τρ j < n k and n k is even. In either case, P (k) implies L k α k j =L k τρ j =L * k τρ j . Thus, regardless of whether Case 1, 2, or 3 pertains, L k α k j =L * k τρ j for every 0 ≤ j < n k−1 .

Appendix B
This appendix gives combinatoric calculations for the circRNA-miRNA application in "Background" section. It therefore has some peripheral interest to this article.

Motifs on a single circle
Consider r points equally spaced around a circle (a "ring"). Call a set of m consecutive points on the ring a "motif ". The following fixes m , so the notation can leave it implicit. Let C r,k count the ways of choosing k nonoverlapping motifs around the ring (i.e., the motifs have no point in common). Note: C r,k = 0 if r < mk or k < 0 . Define the factorial function n! = n(n − 1) · · · 1 and the binomial (combinatorial or Pascal) coefficient for 0 ≤ k ≤ n and 0 otherwise.
Theorem Clearly, C r,k = 1 when r = mk . For r > mk, counts the ways of placing k motifs around the ring. For convenience below and for consistency with Eq. (13), C r,0 = 1 for r ≥ 0.