Manuscript Offprint
arXiv:2608.13408Solving Square-Submatrix Equation Systems
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
We consider systems of submatrix equations, that is, sets of equality constraints over square submatrices of the input. By generalising the recursive algorithm of Gawrychowski et al. [TCS’20] to two dimensions, we obtain a linear-time procedure that finds a solution for any such input system. As an immediate by-product, this yields an optimal-time algorithm for decompressing any two-dimensional macro scheme based on copy operations of sub-squares.
Keywords:
Two-dimensional equation systemsTwo-dimensional macro schemesTwo-dimensional data compressionRepetitiveness Measures
The above results suggest that SESs constitute an interesting compression tool and deserve further investigations. In this paper we study square-submatrix equation systems (SSES), that is two-dimensional SESs made of equations over square submatrices of the input. We show that the recursive algorithm in [4] can be generalised to find a generic solution of any SSES in time where is the matrix size. Next, following [6] we consider SSESs as compression tools with the inclusion of explicit symbol assignments. We compare SSESs with the two-dimensional macro schemes as defined in [1] where the input matrix is parsed into, possibly overlapping square phrases. We show that every 2D macro scheme can be naturally transformed into an equivalent SSES of the same size in linear time. This fact, together with our resolution algorithm, shows that every valid two-dimensional macro scheme of size for an matrix can be decompressed in optimal time.
2 Notation
We denote with the set of all matrices from a finite alphabet . For every integer , is the set . We assume matrices are -indexed. Given we write to refer the submatrix of with top-left cell at and bottom-right cell at for any and . Given any submatrix, we number its vertices anticlockwise starting from top-left one.
A square bidirectional macro scheme [1] for an matrix consists of a partition of into (possibly overlapping) square submatrices, called phrases, such that each submatrix is either an explicit symbol (i.e. it is has size ) or it is a copy of another submatrix (called source). Because of possible phrase overlaps, the same position can be contained in different phrases and its value can be copied from different sources. Formally, we define a multi-valued function , where is the power set of . The value is a set whose size is equal to the number of phrases containing . For each phrase containing : if we add to , otherwise if the phrase is copied from we add to . The scheme is valid if we can eventually retrieve the value of any entry in , that is, for every there must exists a sequence of pairs such that
We denote by the size of the smallest valid bidirectional scheme for .
Definition 1 (Square Submatrix Equation System)
A Square Submatrix Equation System (SSES) for a matrix, is a set of submatrix equality constraints (equations) of the form for some and referred in the following as . A solution for is any matrix satisfying all the constraints in simultaneously.
Note that every matrix containing only one symbol would be a solution. We are interested in a solution containing a maximal number of different characters since any other solution can be obtained from by remapping alphabet symbols. A solution can be obtained by means of the position graph introduced in [4] for strings. is an undirected graph whose nodes are the positions and whose arcs represent the position-wise equalities described by the equations in .
Example 1
Let and let consists of the equations and , i.e.
Each equation induces position equalities, so has edges as shown in Fig. 1.
0,0$$1,0$$2,0$$3,0$$0,1$$1,1$$2,1$$3,1$$0,2$$1,2$$2,2$$3,2$$0,3$$1,3$$2,3$$3,3$$e_{A} (4 edges) (4 edges)
a$$b$$a$$b$$c$$d$$c$$d$$a$$b$$e$$f$$c$$d$$g$$hsourcee_{A}$$e_{B}
Figure 1: The position graph for Example 1 (left) and the corresponding generic solution (right).
We can obtain a solution by computing the connected components of and by assigning a distinct symbol to each connected component. In the example shown in Figure 1, has connected components so the generic solution is the one in Figure 1 (right). This procedure is correct since any two distinct positions of contain the same symbol, if and only if they belong to the same connected component of the position graph. Since an equation generates edges, the size of the position graph could be so the above approach could be inefficient with respect to the optimal solution of cost time described in the next section.
3 Optimal resolution of SSES
In this section we prove the following theorem, which is a generalization to two dimensions of Theorem 16 in [4].
Theorem 3.1
Given a submatrix equation system for an matrix, we can find a generic solution in optimal time.
In this section we consider a typed representations of s. To represent any equation in we permit tuples to store the coordinates of any pair of homologue corners of the two matching squares and we add an additional component in to denote the reference corner. For example the equation can be stored as , where 0 denotes the upper-left corner, or as where 2 denotes the bottom-right corner. In the following we say that an equation with has type . The reason for introducing types, will be apparent after Definition 4.
Definition 2 (Equation graph)
Given an , the (typed) equation graph is the undirected labeled graph defined as follow. For every typed equation we add the pairs and to the vertex set and the arc with label to the arcs set .
Note that, contrary to , the equation graph has size . Since there is a bijection between (typed) s and (typed) equation graphs, we use these objects interchangeably and when clear from the context, we write and for the corresponding graphs induced by .
The next two definitions extend the notion of -special and -short equations in [4] to two-dimensional square equations using base .
Definition 3
An integer is -special in base if all the less significant hexadecimal digits of are non-zero. We denote with the set of all the integers that are -special in base and we define where . Note that (see [4, Fact 11a]) and hold.
Definition 4
We say that an equation is -short if and that is -special if . We say that a system of equations is -special/-short if all its equations are -special/-short.
A -special equation has a constraint on the coordinates of the reference corner . Indeed, we use types because we need equations which are -special with respect to any corner (see the proofs of Lemmas 8 9).
We say that is equivalent to , and write , if . We call type-acyclic if for every equation type the equation graph does not contain any cycle formed by type- edges.
Lemma 1
If is -special and type-acyclic then .
Proof
Since is is type-acyclic, for every , the number of type- edges in is at most so has at most edges. Since is also -special it is by Definition 3.∎
Before entering the technical details we sketch the idea behind the proof of Theorem 3.1 that follows the approach in [4]. Given we compute an equivalent system with equations of size at most . For such an computing using its position graph, as described in Section 2, takes optimal time. To build we find smaller equivalent equations partitioning squares into smaller squares. Since this increases the number of equations the algorithm alternates two type of operations. The Split operations lower the side length of the equations while Reduce operations discard redundant equations and keeps their number under control. Redundant equations are discarded using maximum spanning forests (MSFs) since the shortest equation on a typed-cycle, is implied by the others (Lemma 6). To bound the overall cost, we restrict where equations are anchored: the splits procedures force the equations to have a corner located at a -special position and we exploit the fact that -special integers decays geometrically. The core of the procedure is the recursive routine Shorten which turns a -special, type-acyclic system into an equivalent one which is also -short. For Shorten accepts any equation system (all integers are 0-special) and returns equations of size at most 2 from which we can derive in time with the naive algorithm of Section 2.
Lemma 2 (Reduce)
Given an equation system we can compute in time a type-acyclic system such that . If is -special then .
Proof
We use Lemma 6 and set . The time bound follows by observing that the MSF algorithm in [3] takes linear time. To prove the second part, observe that since , if is -special the same is true for hence, by Lemma 1, it is as claimed.∎
The following pseudocode of Shorten is that in [4], with our 2D-adapted implementations of the Split (Lemmas 8 9) and Reduce (Lemma 2) operations.
Algorithm 1 Shorten
1: function Shorten() must be -special and type-acyclic
2: if then return
3:
4:
5:
6:
7:
8: return is -short, -special and type-acyclic, and
Lemma 3
Algorithm 1 is correct and terminates in time.
Proof
We prove the Lemma by backward induction on . The base case is any , for which the algorithm is correct since . Now consider a generic and assume is type-acyclic and -special. At line 3 SpecialSplit (Lemma 8) partitions every -special equation into equations that are either -short or anchored at a ()-special position. The latter are pruned (Line 4) using Lemma 2 and passed to the recursive call at depth , which makes them -short (Line 5). All the -short pieces are collected and brought down to size by the SimpleSplit call (Lemma 9), and a final Reduce call restores type-acyclicity. Since the number of equations alive at depth is bounded by , the work per level shrinks geometrically and for the whole recursion costs time.∎
Proof of Theorem 3.1 Given , after an one-time pre-processing step that removes the need for any subsequent vertex relabeling as in [4], we compute such that and is type acyclic (and 0-special) in time (Lemma 2). Then, in time (Lemma 3) we compute . By Lemma 3 , and is 0-short (equations have size at most ) and type acyclic (). Hence, we can compute in additional time by building and computing its connect components as outlined in Section 2.∎
4 Applications to repetitiveness measures
As in [6], we use SSES to define a repetitiveness measure by introducing character assignments, and we compare this measure with 2D bidirectional macro schemes.
Definition 5
A SSES representation for a matrix is a quadruplet where is a set of square submatrix equations, and is a set of character assignments of the form with , , . The size of the representation is , and the measure is defined as the size of the smallest SSES representation whose unique solution is the matrix .
For example, for the matrix in Fig. 1, it is easy to see that the smallest SSES representation is the one shown in the figure and has size 10.
Lemma 4
For any valid squared bidirectional macro scheme for a matrix , there exists an SSES representation of size whose unique solution is the matrix . Given , we can compute in time.
Proof
For a copied phrase with origin and destination with top left corner in and respectively we add to the equation . For any explicit symbol in we add to the corresponding character assignment. Since uniquely represents the same is true for .∎
Lemma 5
For every matrix it is .
Proof
The inequality on the left derives from Lemma 4. To prove the other one, given any SSES representation for , we build a valid macro scheme of size for . For every symbol assignment in we add the corresponding explicit symbol to . For every we add to the two phrases and , each using the other as its source. is valid for since for every in the path leading to a symbol assignment corresponds to a sequence that satisfies (1).∎
Because of phrase overlapping, to decompress a 2D macro scheme , a naive algorithm will visit the graph induced by the function . The visit could take time proportional to the size of the graph that in some cases could be . From Lemma 4 and Theorem 3.1, we get an optimal decompression algorithm.
Corollary 1
We can decompress any valid two-dimensional macro scheme of size of an matrix in time.
References
[1] Lorenzo Carfagna and Giovanni Manzini. The landscape of compressibility measures for two-dimensional data. IEEE Access, 12:87268–87283, 2024.
[2] Lore Depuydt, Travis Gagie, Ben Langmead, Giovanni Manzini, and Nicola Prezza. Suffixient sets. CoRR, abs/2312.01359, 2023.
[3] Michael L. Fredman and Dan E. Willard. Trans-dichotomous algorithms for minimum spanning trees and shortest paths. Journal of Computer and System Sciences, 48(3):533–551, 1994.
[4] Paweł Gawrychowski, Tomasz Kociumaka, Jakub Radoszewski, Wojciech Rytter, and Tomasz Waleń. Universal reconstruction of a string. Theoretical Computer Science, 812:174–186, 2020. In memoriam Danny Breslauer (1968-2017).
[5] Dominik Kempa and Nicola Prezza. At the roots of dictionary compression: string attractors. In STOC, pages 827–840, New York, 2018. ACM.
[6] Hiroki Shibata and Hideo Bannai. String representation in suffixient set size space. (arXiv:2604.04377), April 2026. arXiv:2604.04377 [cs].
[7] James A. Storer and Thomas G. Szymanski. Data compression via textual substitution. Journal of the ACM, 29(4):928–951, 1982.
Appendix 0.A Technical lemmas
The next lemma extends the result in [4, Lemma 5] to our typed two-dimensional equation systems.
Lemma 6
Let be an equation system and for let be the subgraph of formed by all its type- edges. It holds that where is the maximum spanning forest of a graph.
Proof
It suffices to prove that . Consider any not in . Adding to must form a cycle where every has type and weight and corresponds to . By the properties of the maximum spanning forest, it holds that , thus by transitivity is implied by equations in the path of since its squares are included in those of and have the same type.∎
In the following for we denote with the hexadecimal representation of , and we denote with the -th digit, so that . For and we write to denote the positive integer consisting of hexadecimal digits equal to , that is, .
Finally, with where and we denote the numbers in the set .
Lemma 7
Given non-negative integers and , let . For any of the following statements and we can find in time and additional space an integer with such that the statement holds:
- are -special;
- if , then and are -special;
- if then are -special.
Proof
Recall that an integer is -special if none of its less significant hexadecimal digits is zero. We exhibit the proof of 2 since 1 and 3 are analogous. We preliminary observe that given any hexadecimal digits there exists a value in every range , such that and hold for every and . To see this, note that there are 4 constraints and 5 possible values in . We precompute for every possible value of an array storing the minimum admissible for every quadruple of hexadecimal digits .
Next, we derive the desired by computing in time its hexadecimal digits right to left starting from the less significant. The bounds on the size of will follow from the observation that it consists of hexadecimal digits between and . Let denote the value of obtained after we computed digits.
We prove the correctness of our procedure by induction on . For , with the precomputed arrays we find in time such that and are -special by using the four digits and we set . Note that so borrowing is possible, if needed, since by hypothesis. Now assume the statement holds for , in particular holds by induction. Similarly to the base case, we retrieve from the precomputed arrays, using the -st digit of and . By hypothesis it is thus borrowing, if needed, is possible. We set . The values and are -special since by adding/subtracting to the values obtained in the previous iteration, we make all the -st digits non-zero without modifying any digit at positions which are all non-zero by the induction.∎
Next we show that [4, Lemma 12] holds also in two dimensions with our definition of 2D -special and -short equations (see Definition 4), but with a multiplicative time factor.
Lemma 8 (SpecialSplit)
Given any set of -special equations, we can build in time two sets of equations such that: 1) is -short and -special 2) is -special 3) and 4) .
Proof
To prove the claim we split every in time into equations that together are equivalent to . Each such equation satisfies condition or and is added to or accordingly. Let be a -special equation in and assume , the proofs for are analogous. If is already -short, we add it to . If this is not the case, but one of its corners is -special, we change the type of accordingly (if needed) and we add it to . In either case, we are done. Otherwise we replace with new equations that together are equivalent to . Equation is -special and -short so we will add it to while the remaining ones are all -special and thus we will add them to . Let denote the integer obtained in time by applying Lemma 7 part 1 to the integers with and parameter . Note that by the lemma it is ; since is not -short, . We set , thus is -special and -short as claimed. Next, we set , which by Lemma 7 is -special.
The derivation of the last two equations is more complex: they are of type 3 and 1 and we need them to cover respectively the rectangles and of Fig. 2 to ensure that . To compute we consider the four integers which are the coordinates of the upper right corners of . Applying Lemma 7 part 2 with and parameter we find an integer such that
are -special. Hence if we set
by construction is -special. By Lemma 7 we also have which ensures that covers , i.e. that . The construction of to cover is analogous starting with the lower right corners of .∎
Figure 2: Construction of the equations used in Lemma 8 that together with (not shown) are equivalent to . The requirement is that the union of the submatrices associated with coincides with the submatrix associated to . The parameters and are chosen to ensure that is -short and the reference corner of the type- equations are -special.
The next lemma extends [4, Lemma 13] to two-dimensional equation systems. Again we have an additional multiplicative factor in the time.
Lemma 9 (SimpleSplit)
Given any set of -special and -short equations, we can build in time an equivalent -special and -short system of size .
Proof
Let be any equation in that we assume w.l.o.g. to be of type . The proofs for the other types are symmetrical. If is already -short we have done, otherwise hold and we cover the two matching squares and corresponding to as follows. We add -short equations of the form for every integers . These equations are -special because and adding multiples of does not change the -specialty of the coordinates. If , the above equations partition and and are equivalent to . Thus next we assume and . In this case, rectangles are left uncovered in the bottom and right edges of and , plus squares in their bottom-right corners. To cover the squares we add a type- equation matching them which is already -special and -short. Now consider any two matching rectangles and in the bottom-edge of and , excluding the rightmost ones. These rectangles have size with and their bottom-left corners are anchored at the positions and respectively, for some . To cover and , we start from the squares with top-right corners at and , that respectively include and . Then by using Lemma 7 part 2 with and parameter , we find a nonnegative such that the integers , , and are all -special. The resulting -special and -short equation is . Similarly, to cover the rightmost rectangles in the bottom-edge of and , we still consider the squares and including them, but now with and we refer the coordinates of their top-left corners. We find an using Lemma 7 part 3 with and parameter such that , , and are all -special. In this case the added equation is which is -special and -short. See Figure 3 for a graphical representation of the partitioning. We can handle similarly all the rectangles on the right edge of and . With the above procedure we add equations in total, each generated in time, thus the claimed time and space follows.
Figure 3: Partitioning of a -special and -short equation as described in Lemma 9, here where is the equation length. The two squares in the figure represents i.e. one of the two matching squares corresponding to . The square in the bottom-right corner and all the squares are -special and -short. In the figure on the right, the square , which covers the rightmost rectangle in the bottom edge, is extended along its anti-diagonal while the remaining rectangles are covered as shown in the figure on the left.