{'fraction_non_alphanumeric': 0.056798516687268236, 'fraction_numerical': 0.008220024721878863, 'mean_word_length': 4.350859788359788, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Corrections to the results derived in"A Unified Approach to Algorithms Generating Unrestricted and Restricted Integer Compositions and Integer Partitions"'; and a comparison of four restricted integer composition generation algorithms

In this note, I discuss results on integer compositions/partitions given in the paper"A Unified Approach to Algorithms Generating Unrestricted and Restricted Integer Compositions and Integer Partitions". I also experiment with four different generation algorithms for restricted integer compositions and find the algorithm designed in the named paper to be pretty slow, comparatively. Some of my comments may be subjective.


Introduction
A few years ago, I became interested in the subject of restricted integer compositions because they arise in the context of generalized sequence alignment algorithms. In particular, I wanted a possibly fast algorithm for generating all compositions of an integer n with k parts, each in the discrete interval {a, a + 1, . . . , b}. Googling, I found both a Matlab implementation and a paper reference, [7]. In its abstract, the algorithm was praised as "reasonably fast with good time complexity" and also as solving the "open problem of counting the number of integer compositions doubly restricted in this manner". After some experimentation, however, it appeared to me that not only is the discussed algorithm slow but, in addition, the paper makes many (at best) misleading statements concerning (mathematical) results on restricted integer compositions.
In this note, I outline my objections to the Opdyke algorithm and the paper's theoretical results and explain why I think the algorithm and its underlying results are problematic. I first briefly summarize my points of critique, before I introduce notation and definitions and, subsequently, detail my concerns. Finally, I run the algorithm and compare it with other (simple and not so simple) algorithms for generating restricted (and unrestricted) integer compositions, where each part lies in an arbitrary interval as outlined above. These experiments reveal that, in fact, the algorithm's run time appears to be pretty bad, exponentially worse (in one of the input parameters) than a competitor algorithm's designed in [8].
1. Paper [7] claims to provide "closed form solution [s] to the open problem of counting the number of [doubly restricted] integer compositions". I argue that, on the contrary, the recursions that the paper indicates as closed-form solutions are (1) elementary, (2) long known, and (3) special cases of results developed in the literature paper [7] cites.
2. Paper [7] claims to generalize earlier approaches to the restricted integer composition/partition problem by allowing both lower and upper bounds on the value of parts in integer compositions/partitions. I argue that, on the contrary, general lower and upper bounds, a and b, may, without loss of generality, be reduced to the special case a = 0. Thus, in this respect, paper [7] is just as specific as other work in this field.
3. Paper [7] claims to generalize earlier approaches to the restricted integer composition/partition problem by allowing both lower and upper bounds on the number of parts in integer compositions/partitions. I argue that, on the contrary, this is merely a trick to feign generality. What the paper does is simply to provide a wrapper function (sic!) around its integer composition/partition generation module, invoking it with different parameter values for the number of parts.
4. Paper [7] claims that its outlined algorithm is, "given its generality, [...] reasonably fast with good time complexity". I argue that, on the contrary, the paper's methodology is not general at all (as outlined), and hence, its time complexity is bad.
5. Paper [7] claims that it "unifies" the generation approach to the integer composition/partition problem. I argue that such a 'unification' need hardly be surprising given that compositions and partitions are so closely related. I illustrate by providing other links between compositions and partitions.
An integer composition of a nonnegative integer n is a tuple (π 1 , . . . , π k ) of nonnegative integers such that n = π 1 + · · · + π k . 1 The π i 's are usually called the parts of the composition. We call an integer composition A-restricted, for a subset A of the nonnegative integers, if each part lies in A. If π 1 ≥ π 2 ≥ · · · ≥ π k , then (π 1 , . . . , π k ) is called an integer partition. We denote by C A (n, k) the set of restricted integer compostions of n with fixed number k of parts, each in the set A. Analogously, we denote by P A (n, k) the set of restricted integer partitions of n with fixed number k of parts, each in the set A. By c A (n, k) and p A (n, k), we denote the respective cardinalities. Throughtout, we typically consider A = [a, b] = {a, a + 1, . . . , b}. In the latter cases, we also write c(n, k, a, b) and p(n, k, a, b), respectively. I now address several issues discussed in paper [7]. and, on p.67, Formulae (2), (3), and (4) mirror the analogous solutions for counting doubly restricted integer partitions presented later in the paper. Although their recursive nature makes these formulae less convenient than, say, a simple combinatoric equation or sum, they still provide closed form solutions to problems which had none before, and their calculation is not onerous.
On p.77, the paper continues [...] which is probably why their important link to the completely original, analogous solutions of (2), (3), and (4) for compositions has been missed until now.
Denoting by c(n, a, b) the number of integer compositions of n with arbitrary number of parts, each between a and b, and by c(n, k 0 ≤ k ≤ k 1 , a, b) the number of integer compositions of n with k parts, for k 0 ≤ k ≤ k 1 , each between a and b, these closed form solutions are (we shift equation numbers to match those of the paper in question): Here, I(·) denotes the indicator function, which is 1 or 0, depending on whether the expression in brackets is true or not. I argue that these three results are (1) elementary, (2) long known, and (3) given in the references the paper under scrutiny, [7], cites.
First, for Equation (4), there is nothing to prove since this formula is, by definition, just the sum, over the number of parts, of the formula given in Equation (3). To prove results (2) and (3), note that any A-restricted integer composition of n is obtained by adding x to a composition of n − x, for x ∈ A. In other words, denoting by c A (n) the number of A-restricted integer compositions, we have: Hence, if we specialize to A = {a, a + 1, . . . , b}, Equations (2) and (3) are retrieved. This shows that all three equations are elementary.
Concerning the counting formulae for restricted integer partitions, I admit that I am not familiar with the literature on integer partitions. However, the formulae that paper [7] derives probably are given in any work on the topic (the author cites [1] as a reference). Namely, the formulae are (I omit the formula that sums over different parts because it is trivial). Deriving (8) (and (7)) is also simple. Each partition must end, in its final part, with a number x, for some x ∈ A. Since x is (weakly) the smallest part of the partition, the remaining k − 1 parts must have size at least x and they must sum to n − x. Hence, where A x = {y ∈ A | y ≥ x}. This generalizes formula (8). Formula (7) is completely analogous.

Lower and upper bound restrictions?
Is it necessary to consider both lower and upper bounds in integer compositions and partitions? A well-known fact of restricted compositions and partitions is the following (see [6], who states this as well-known, without proof, only for compositions; however, partitions are of course analogous in this respect).
Since order didn't matter for our argument, the same conclusion holds for compositions. 3. Restrictions on part number? Paper [7] claims that it allows for another generality: Allowing to compute all compositions/partitions of n with k parts, each between a and b, where k ranges from some k Min to some k Max . This may be an interesting problem, but not so if the solution is to apply the original algorithm A(n, k, a, b) in the form: A(n, k Min , a, b), A(n, k Min+1 , a, b), . . . , A(n, k Max , a, b), that is, if the original algorithm A(n, k, a, b) is invoked simply with different input arguments for the parameter k. Doing it in this way generates no additional efficiencies and is also independent of algorithm A -a faster algorithm would be a better choice for A than a slower one.
In fact, to actually understand the dimension of the suggested approach of simply invoking A(n, k, a, b) for different values of k, consider another trivial generalization of the mentioned type. We could, for example, define the quadruply restricted integer composition/partition problem of generating all integer compositions/partitions of n ∈ N with parts k ∈ K, lower bounds a ∈ A and upper bounds b ∈ B, where N, K, A, B are arbitrary sets. This may be an interesting problem, but solving it via the algorithm for n in N for k in K for a in A for b in B A(n,k,a,b) is simply a trivial solution that is not worth mentioning. Again, faster algorithms A(n, k, a, b) should then always be preferred over slower algorithms A(n, k, a, b).

Speed?
As mentioned, the algorithm designed in [7] is slow. It takes time O(k) per composition and is therefore inefficient (see, e.g., [8]).

5.
A "generalized" and "unified" approach? In mathworks comments, the author of [7] argued that while his algorithm is slow, it trades this off by generality: It solves a generalized problem with varying number of parts and arbitrary upper and lower bounds. However, I have outlined that these are not generalizations. In essence, thus, the algorithm is as specific as any algorithm that solves the restricted integer composition/partition problem. Only, it is so at a worse runtime.
Besides this, the author claimed that his approach is "unified" in the sense that few modifications are necessary to transform the composition algorithm into a partition algorithm and vice versa, and in that his recursions outline fundamental links between integer compositions and partitions. In my opinion, this is a weak argument. From a practical point of view, I'd rather have two fast and very distinct algorithms than two slow ones that are very similar, wouldn't I?
From a theoretical perspective, what is so surprising about two similar algorithms (or, recursions) for the integer composition and partition problem? After all, compositions are ordered partitions, so similarities, per se, should not come as a surprise.
To illustrate, note the following property of restricted integer compositions/partitions. In writing n = π 1 + · · · + π k , with each π i ∈ [a, b], one can use b either 0 times, 1 time, ..., up to ⌊n/b⌋ times. If one uses b exactly i times (as first part(s)), one is left with the problem of solving n−bi = q 1 +. . .+q k−i , where q 1 , . . . , q k−i ∈ [a, b − 1]. Hence, restricted integer partitions satisfy the 'recursion' If one redistributes the i b's among the total of k parts, one sees that restricted integer compositions satisfy the 'recursion' where, sloppy, we let k i C [a,b−1] (n − bi, k − i) denote the distribution of the i parts among k. Hence, the following recursion formulae exist: These recursions also immediately 'show' a similarity between integer compostions and partitions and they seem at least as useful to demonstrate this relationship as are the formulas in (3) and (8). In fact, these two recursive relationships can immediately be used for providing an algorithm for the restricted integer composition/partition problem (incidentally, this was my hand-coded approach that was faster than the algorithm in [7] ...). Still, this "unifying" principle among the two recursions is, as it seems to me, not yet justified in suggesting, on a journal level, yet another algorithm for the restricted integer composition/partition problem.

Experiments
To compare algorithms for generating restricted integer compositions, we run the following experiments. We generate all restricted integer compositions of n with k parts, each between a and b, via two naïve generation algorithms, as well as via the Opdyke algorithm [7] and the algorithm suggested in [8]. The two naïve algorithms are: (i) The algorithm that generates all compositions of n with k parts, each between a and b, by recursively generating all compositions of n − x with k − 1 parts and then adding x to these, for x ∈ [a, b]. This is a direct implementation of recursion (6). Note that a naïve implementation of the latter recursion is clearly inefficient, since it computes the same things over and over again, as we illustrate in the generation tree in Figure 4.
Note that all four compared algorithms are fully general in the sense of paper [7] in that they generate all restricted integer compositions in the interval [a, b] and in that they can also be invoked with different values of the number of parts parameter k (what paper [7] calls a 'double restriction'). The naïve algorithms can also easily be adapted to generate restricted integer partitions, as outlined above. We abbreviate the algorithms as (V) for the algorithm suggested in [8], (O) for the Opdyke algorithm, and (6) and (10) for the algorithms based on direct implementations of recursions (6) and (10), respectively. All implementations are our own Python implementations. In the case of algorithms (V) and (O), we directly implement the pseudo-code given in the respective papers. We run the experiments on a 2.4 GHz processor.
In Figure 2, we plot how our results depend on the number of parts k, fixing n at n = 22. We see that as k is small, the algorithms (V), (O), and (10) are all roughly equally fast (run time is in fractions of seconds), but, as k increases, the algorithms (O) and (6)  Why is the algorithm designed in [7] so slow? In the end, it is because it makes too many recursive calls; in particular, it repeatedly recursively calls itself with the same input parameters, a feature it shares with algorithm (6). To see this, if recursion (6) is invoked with some input parameters n and k, then c A (n, k) will recurse to c A (n − a, k − 1), for a ∈ A. This, in turn, will recurse to c A (n − a − b, k − 2), for b ∈ A. However, the algorithm will, in this way, recompute the value c A (n − a − b, k − 2) for all summations of a + b. For instance, if A = [1,2], then c A (n, k) will call c A (n − 1, k − 1) and c A (n − 2, k − 1). The former will call c A (n − 2, k − 2) and c A (n − 3, k − 2), while the latter will call c A (n − 3, k − 2) (again!) and c A (n − 4, k − 2) (repetitions in bold), and so on. Of course, this redundancy is given in each part of the generation tree, making algorithm (6) highly inefficient. If indeed the algorithm designed in [7] is based on formula (6), it is not surprising that it is also highly inefficient.
Finally, there is no need to also experiment with the integer partition generation algorithm designed in [7], precisely because it is so similar to the composition generation algorithm and accordingly shares all its inefficiencies. Algorithm (10), or rather its partition analogue as outlined above (given in Equation (9)), will surely be more efficient and the partition analogue of recursion (6) will be less efficient. More specialized partition generation algorithms, in turn, will be superior (even) to algorithm (10).
Summary: In my opinion, the Opdyke algorithm is not general, and merely slow. The recursion formulae are appealing, if only they were not so well-known and simple. In my view, it has been unfortunate to describe these recursions as 'solutions to open problems', when in fact the integer composition recursions are outlined on the second page of bibliography the author cites. Possibly, the paper can make other contributions to this field in the future, but, in my opinion, these would still have to be unveiled. 3  (6). The numbers in the nodes refer to input parameters of the algorithms in the recursive calls.