Recognition and Analysis of Image Patterns Based on Latin Squares by Means of Computational Algebraic Geometry

: With the particular interest of being implemented in cryptography, the recognition and analysis of image patterns based on Latin squares has recently arisen as an efﬁcient new approach for classifying partial Latin squares into isomorphism classes. This paper shows how the use of a Computer Algebra System (CAS) becomes necessary to delve into this aspect. Thus, the recognition and analysis of image patterns based on these combinatorial structures beneﬁts from the use of computational algebraic geometry to determine whether two given partial Latin squares describe the same afﬁne algebraic set. This paper delves into this topic by focusing on the use of a CAS to characterize when two partial Latin squares are either partial transpose or partial isotopic. isotopic


Introduction
An n × n array is said to be a partial Latin square of order n if each one of its cells either is empty or contains an element of a finite set of n symbols so that each symbol occurs at most once in each row and at most once in each column. If there are no empty cells, then the array is called a Latin square. Latin squares play a relevant role in cryptography [1][2][3]. Of particular interest for the aim of this paper, the generation of scramblers in symmetric cryptography by means of encryption-decryption processes having Latin squares as cryptographic keys is remarkable [4][5][6][7][8]. The exponential growth of Latin squares [9][10][11] ensures the robustness of these symmetric-key algorithms against brute force and statistical attacks. In addition, appropriate choices of Latin squares produce effective symmetric-key algorithms with high period growths [12]. In this regard, the distribution of Latin squares into isomorphism classes play a fundamental role. It is so that pseudo-random sequences derived from non-isomorphic Latin squares give rise to certain image patterns [13,14], whose algebraic and geometrical properties enable one to distinguish between fractal and non-fractal Latin squares [15,16].
Distributing (partial) Latin squares into isomorphism classes indeed constitutes a main problem in the theory of (partial) Latin squares. Currently, only the number of isomorphism classes of Latin squares of order n ≤ 11 is known [9][10][11], as well as that of partial Latin squares of order n ≤ 6 [17,18]. To obtain these last values, the computation of reduced Gröbner bases of ideals associated to partial Latin squares has played a relevant role. Such a computation is, however, extremely sensitive to the number of involved variables and the length and degree of the corresponding generators [19][20][21][22]. Thus , although distinct techniques concerning computational algebraic geometry have been implemented since the original work of Bayer [23] for solving the classical problems of counting, enumerating and classifying partial Latin squares [17,18,[24][25][26][27][28][29] and solving related problems such as completing sudokus [30][31][32], their computational cost makes it very difficult to deal with partial Latin squares of high orders.
The study of new invariants concerning partial Latin square isomorphisms has turned out to be an optimal approach to reduce this computational cost [33][34][35]. This paper delves in particular into those invariants that are related to affine algebraic sets associated to the partial Latin squares under consideration. In this regard, let us recall that the affine algebraic set in a multivariate polynomial ring K[{x 1 , . . . , x n }] of a partial Latin square L = (l i,j ) of order n, with set of symbols [n] := {1, . . . , n}, was defined by Falcón, R.M. et al [36] as the set of zeros of the binomial ideal I(L) := x i x j − x l i,j : 1 ≤ i, j, l i,j ≤ n . (1) Isomorphic partial Latin squares give rise to isomorphic affine algebraic sets. Thus, Gröbner bases have played a relevant role for distinguishing, in a computationally fast way, image patterns arisen from non-isomorphic Latin squares. In any case, the study of affine algebraic sets associated to Latin squares is still in the very initial stage. Thus, for instance, their distribution into isomorphism classes is only known for n ≤ 3 [36]. To deal with higher orders, it is necessary to delve into two new ways of classifying partial Latin squares. More specifically, it is necessary to characterize when two partial Latin squares are partial transpose and/or partial isotopic. In both cases, the partial Latin squares under consideration may give rise to the same affine algebraic set.
The paper is organized as follows. Section 2 deals with some preliminary concepts and results on partial Latin squares and computational algebraic geometry that are used throughout the paper. In Section 3, the notion of standard set of image patterns associated to a Latin square is introduced, which may constitute a fast computational way for distinguishing non-isomorphic Latin squares. To this end, the use of a new affine algebraic set associated to each of these image patterns is proposed. Finally, two new ideals are described in Section 4, whose respective affine algebraic sets are uniquely identified with the set of partial Latin squares that are partial transpose of another given partial Latin square, and the set of partial isotopisms between two given partial Latin squares of the same order and weight.

Preliminaries
Let us review some basic concepts and results on partial Latin squares and computational algebraic geometry that are used throughout the paper. We refer the reader to the monographs of [37] and [38] for more details on both topics.

Partial Latin Squares
Let L n be the set of partial Latin squares of order n having the already mentioned set [n] as set of symbols. Every partial Latin square L = (l i,j ) ∈ L n is determined by its set of entries Therefore, the cardinality of this set coincides with the number of non-empty cells within the partial Latin square L. It is termed the weight of L. From here on, let L n;m denote the subset of partial Latin squares in the set L n of weight m.
Let S n denote the symmetric group on the set [n]. Every triple θ = ( f , g, h) ∈ S 3 n preserves the set L n;m . It constitutes an isotopism of partial Latin squares, where the bijections f , g and h correspond, respectively, to a permutation of rows, a permutation of columns and a permutation of symbols of the partial Latin square under consideration. More specifically, the isotopism θ acts on any given partial Latin square L ∈ L n;m by giving rise to its isotopic partial Latin square L θ ∈ L n;m , where then the isotopism θ constitutes an isomorphism. In such a case, the partial Latin squares L and L θ are said to be isomorphic. Throughout this paper, the computation of isotopisms and isomorphisms among partial Latin squares is done by making respective use of the procedures isot and isom of the library pls.lib, available online at http://personales.us.es/raufalgan/LS/pls.lib (accessed on 28 February 2021), for the open Computer Algebra System (CAS) for polynomial computations SINGULAR [39].
Isotopic and isomorphic are equivalence relations among partial Latin squares. The distribution into such classes is known for order n ≤ 11 in the case of dealing with Latin squares [9][10][11] and for order n ≤ 6 in the case of dealing with partial Latin squares [17,18]. Partial transpose are partial isotopic are two other binary relations among partial Latin squares of the same order and weight, whose study is still in teh very initial stage. Although the original definitions were established by Falcón, R.M. et al [36] as equivalence relations, it is not so. In what follows, we particularize both definitions in order to obtain two new equivalence relations among partial Latin squares of the same order and weight. To this end, let us consider two partial Latin squares L 1 and L 2 in L n;m .
We say that L 2 is partial transpose of L 1 if and only if the following two conditions hold.

2.
For each entry (i, j, k) ∈ Ent(L 1 ) \ Ent(L 2 ), we have that (j, i, k) ∈ Ent(L 2 ). Being partial transpose generalizes, therefore, the classical concept of being transpose. Notice that the second condition that we have just described was not explicitly indicated by Falcón, R.M. et al [36]. Nevertheless, as is illustrated in the following example, this condition is mandatory in order to obtain a symmetric relation. both of them in L 4;8 , satisfy the first described condition in order to ensure that L 2 is partial transpose of L 1 . Nevertheless, such a condition is not satisfied for ensuring that L 1 is partial transpose of L 2 , because the entry (2, 4, 3) ∈ Ent(L 1 ) \ Ent(L 2 ) and (4, 2, 3) ∈ Ent(L 2 ). Now, let P ⊆ Ent(L 1 ) ∩ Ent(L 2 ). We say that L 2 is P-partial isotopic to L 1 if there exists an isotopism ( f , g, h) ∈ S 3 n such that In such a case, we say that the triple ( f , g, h) is a P-partial isotopism (a partial isotopism, when there is no place for confusion) from L 1 to L 2 . The just described binary relation of being P-partial isotopic constitutes an equivalence relation among partial Latin squares of the same order and weight, as well as containing the subset P in their respective sets of entries. Further, if two partial Latin squares are isotopic, then they are ∅-partial isotopic. More specifically, every isotopism from L 1 to L 2 is also a partial isotopism between such partial Latin squares.
The subset P ⊆ Ent(L 1 ) ∩ Ent(L 2 ) was not established as an essential part of the original definition of being partial isotopic introduced by Falcón, R.M. et al [36]. Nevertheless, if it is not considered as such, then the resulting binary relation is intransitive. The following example illustrates this fact. In this example, and from now on, to make much clearer the understanding of the subset P associated to any given partial isotopism in S 3 n , we denote L(P) the partial Latin square of order n satisfying that Ent(L(P)) = P. are isotopic (and, hence, ∅-partial isotopic) by means of the isotopism ((34), Id, Id) ∈ S 3 4 , that is, by switching their third and fourth rows. It is readily verified that the Latin square L 2 is P-partial isotopic to To this end, it is enough to consider, for instance, the partial isotopism ((23), Id, Id) ∈ S 3 4 . Nevertheless, as shown in Example 8, no partial isotopism exists from L 1 to L 3 .
The following example illustrates all the previous definitions in case of dealing with partial Latin squares with empty cells. The second condition holds similarly. In addition, one can find a partial isotopism between both partial Latin squares L 1 and L 2 . To this end, it is enough to consider the isotopism θ = ((1423), (1324), Id) ∈ S 3 and the subset P = Ent(L 1 ) ∩ Ent(L 2 ). That is, In particular, Notice that both partial Latin squares L 1 and L 2 are neither transpose nor isotopic of each other.
Let us finish this subsection by focusing on the description of the image patterns based on a given Latin square. To this end, let us recall that every Latin square in the set L n;n 2 constitutes the multiplication table of a quasigroup ([n], ·), where the set [n] is endowed with a binary operation · so that the equations a · x = b and y · a = b have unique solutions for x and y in [n], for all a, b ∈ [n]. Equivalently, the set [n] is endowed with a left-division \ and a right-division /, so that x = a\b in the first equation, and y = b/a in the second one.
Let T = t 1 t 2 . . . t m be a plaintext, with t i ∈ [n], for all i ≤ m. For each positive integer s ≤ n, it is defined [6][7][8] the encrypted string The resulting string can be desencrypted by means of a decryption map D s based on the already mentioned left-division. More specifically, The sequential implementation of the just described encryption may give rise to image patterns with certain fractal properties [13][14][15][16]. More specifically, if S = (s 1 , . . . , s r−1 ) is an (r − 1)-tuple of positive integers such that s i ≤ n, for all i < r, then the r × m image pattern P S,T (L) = (p i,j ) is defined as the r × m array satisfying that, for each positive integer j ≤ m, we have that The image patterns arisen from the set of Latin squares of a given order only depend on the distribution of the latter into isomorphism classes. More specifically, the following result is known. Lemma 1 ([36]). Let L 1 and L 2 be two Latin squares in L n;n 2 that are isomorphic by means of an isomorphism ( f , f , f ) ∈ S 3 n . Let S = (s 1 , . . . , s r−1 ) and f (S) = ( f (s 1 ), . . . , f (s r−1 )) be two (r − 1)-tuples of positive integers, such that s i ≤ n, for all i < r, and let T = t 1 . . . t m and f (T) = f (t 1 ) . . . f (t m ) be two plaintexts, with t i ∈ [n], for all i ≤ m. Then, the r × m image patterns P S,T (L 1 ) = (p i,j ) and P f (S), f (T) (L 2 ) = (p i,j ) coincide up to permutation of symbols. More specifically, p i,j = f (p i,j ), for all positive integers i ≤ r and j ≤ m.

Computational Algebraic Geometry
From here on, let K[X] denote the multivariate polynomial ring over a field K that is defined on a finite set X of n variables. A point P ∈ K n is a zero of a set S ⊆ K[X] if f (P) = 0, for all f ∈ S. The set of all these zeros constitutes an affine algebraic set in K n . It is irreducible if it cannot be decomposed into two nonempty proper affine algebraic sets. The dimension dim(V) of an affine algebraic set V is the maximal number of its irreducible components minus one. Further, two affine algebraic sets V 1 and V 2 in K n are isomorphic if there exists a bijective map φ : V 1 → V 2 such that φ(P) = ( f 1 (P), . . . , f n (P)) and φ −1 (Q) = (g 1 (Q), . . . , g n (Q)), for all (P, , for all i ≤ n. The map φ constitutes an isomorphism from V 1 to V 2 . An isomorphism invariant of affine algebraic sets is any property of the latter that is preserved by isomorphisms.
An ideal of the multivariate polynomial ring K[X] is a subset I ⊆ K[X] such that 0 ∈ I; p + q ∈ I, for all p, q ∈ I; and p · q ∈ I, for all p ∈ I and q ∈ K[X]. It is said to be generated by a set of polynomials {p 1 , . . . , p k } ⊆ K[X] if it is defined as

It is
binomial if all its generators are. Further, it is radical if p ∈ I, for all p ∈ K[X] such that p m ∈ I, for some positive integer m. Finally, it is zero-dimensional if dim(V K (I)) = 0, where V K (I) is the affine algebraic set in K n formed by all the zeros of the polynomials within I. This dimension can be obtained from the reduced Gröbner basis of the ideal I [40][41][42]. Let us recall in this regard that the leading monomial of a polynomial is its largest monomial with respect to a given multiplicative well-ordering whose smallest element is the constant monomial 1. Then, a Gröbner basis of an ideal I is any subset within I whose leading monomials generate the so-called initial ideal, which is generated in turn by all the leading monomials of the non-zero polynomials of I. If the ideal I is zero-dimensional and radical, then the number of monomials that are not contained in its initial ideal coincides with the cardinality of V K (I). Further, a Gröbner basis is reduced if all its polynomials are monic and no monomial of its polynomials is generated by the leading monomials of the rest of polynomials. The reduced Gröbner basis of an ideal is unique. It can always be computed from Buchberger's algorithm [43]. Arisen from this algorithm, one can find the more efficient direct methods described by the algorithms F 4 and F 5 [44,45] and the algorithm slimgb [46].
Throughout this paper, all the computations concerning Gröbner bases are carried out on an Intel Core i7-8750H CPU (6 cores), with a 2.2 GHz processor and 8 GB of RAM, with a maximum running time of less than 1 s. All of them are done by making use of the algorithm slimgb that is implemented in the CAS SINGULAR. As multiplicative wellordering, it has been chosen the degree reverse lexicographical ordering. Finally, all the computations are done on either the field Q of rational numbers or the field C of complex numbers. In the first case, the following result holds. Theorem 1 ([22]). The arithmetic complexity of computing the reduced Gröbner basis of a zero-dimensional ideal I = p 1 , . . . , p m ⊂ Q[{x 1 , . . . , x n }] is bounded above by the value where h i denotes the maximum size of the coefficients of the generator p i , and d i denotes its maximum degree, for all i ≤ m.
The following example focuses on the computation of the affine algebraic set of a partial Latin square, which is described in the Introduction.

Example 4.
Let us consider the partial Latin square L 1 ∈ L 4;8 described in Example 3. To compute the affine algebraic set in the multivariate polynomial ring Q[{x 1 , x 2 , x 3 , x 4 }] of L 1 , we obtain from Definition 1 the binomial ideal I(L 1 ) defined as A reduced Gröbner basis of this binomial ideal is the subset Hence, the ideal I(L 1 ) is zero-dimensional. Its associated affine algebraic set is Being partial transpose and being P-partial isotopic, for some , are two equivalence relations in the set L n;m that give rise to identical affine algebraic sets. Concerning the first of them, the following direct result is known.

Lemma 2 ([36]
). If two partial Latin squares of the same order and weight are partial transpose of each other, then their related affine algebraic sets coincide.
Nevertheless, some assumptions are required for the second equivalence relation. In this regard, let us recall that the binomial ideal I(L) associated to a partial Latin square L ∈ L n determines the following partition of the set [n].
Then, the following result holds.

Example 5. Let us consider again the multivariate polynomial ring
Since the partial Latin squares L 1 and L 2 described in Example 3 are partial transpose of each other, Lemma 2 implies that V Q (I(L 2 )) = V Q (I(L 1 )), which is described in Example 4. Now, let us consider the following three partial Latin squares in L 4;8 .
Proposition 1 also enables us to ensure that V Q (I(L 2 )) = V Q (I(L 1 )), but, here, the reduced Gröbner basis of the binomial ideal I(L 2 ) differs from that one of I(L 1 ). More specifically, the reduced Gröbner basis of I(L 2 ) is the subset Finally, the reduced Gröbner basis of the binomial ideal I(L 2 ) is the subset

Standard Image Patterns Associated to Latin Squares
Lemma 1 establishes the existing relationship among image patterns arisen from Latin squares and the distribution into isomorphism classes of the latter. This section focuses on a particular subset of image patterns, which may enable one to determine, even from a visual way, whether two Latin squares are not isomorphic. In this regard, let m, n, r and s be four positive integers such that s ≤ n. We define the s-standard r × m image pattern associated to a Latin square L ∈ L n;n 2 as P r,m;s (L) := P S,T (L), where S is the constant (r − 1)-tuple (s, . . . , s) and T is the constant plaintext s . . . s of length m. We call it constant if all its entries coincide. In addition, we term the set {P r,m;s : s ∈ [n]} the standard set of r × m image patterns associated to L. From Lemma 1, if the standard sets of r × m image patterns associated to two Latin squares do not coincide up to permutation of symbols, then these Latin squares are not isomorphic. As such, the analysis of standard sets turns out to be of particular interest for distinguishing non-isomorphic Latin squares even from a simple visual way.
To illustrate this fact, let us focus on the standard 90 × 90 image patterns associated to each one of the 35 isomorphism classes in which the set of Latin squares of order n = 4 is distributed. (The case n = 3 was already analyzed by Falcón, R.M. et al [36].) A representative of each one of these classes is described in Figure 1. Their respective standard image patterns are shown in Figure 2. It is formed by four collages in form of 7 × 5 arrays. They were created by means of the commands Colorize and ImageAssemble in WOLFRAM MATHEMATICA [47]. Each standard image pattern is represented as a pixel array so that each symbol is uniquely replaced by a color within a given palette of four colors. Each cell within any of these arrays constitutes the corresponding standard image pattern that is associated to the Latin square described at the same position within Figure 1. The union of the four standard images patterns associated to such a Latin square constitutes its standard set of 90 × 90 image patterns.
These standard sets can be distributed according to the following classification.

Constant standard image patterns.
A simple observation of the monochromatic cells in Figure 2 enables us to determine this type of standard image patterns. Notice that the s-standard image pattern of a Latin square L = (l i,j ) is constant if and only if l s,s = s.

2.
Fractal standard image patterns. From a simple visual inspection, one can observe that some of the cells in Figure 2 have a fractal character. It is the case, for instance, of the 2-standard image pattern associated to the Latin square L 4.1 .

3.
Non-fractal standard image patterns. The remaining cells do not have a clear fractal character. Their spectrum goes from what one may label as a chaotic behavior (see, for instance, the 2-standard image pattern associated to L 4.30 ) to a shadow of fractal behavior (see, for instance, the 2-standard image pattern related to L 4.11 ). In any case, we do not distinguish in this paper the fractal gradation of the image patterns under consideration.  1 2 4 3  3 4 2 1  2 3 1 4  4 1 3 2   1 2 4 3  3 4 2 1  4 1 3 2  2 3 1 4   1 2 4 3  3 4 2 1  4 3 1 2  2 1 3 4   1 3 4 2  2 1 3 4  3 4 2 1  4 2 1 3   1 3 4 2  2 1 3 4  4 2 1 Table 1 shows the values cs i and fs i corresponding, respectively, to the number of constant and fractal standard image patterns within the standard set of 90 × 90 image patterns of the Latin square L 4.i in Figure 1, for every positive integer i ≤ 35. As introduced above, the number of its non-fractal standard image patterns would be, therefore, 4 − cs i − fs i . Notice that the first parameter characterizes the isomorphism classes having L 4.17 and L 4.24 as representatives, which are the only ones containing respectively three and four constant standard image patterns.
In addition, the representative L 4.11 is the only one that is associated to two constant and two non-fractal standard image patterns. The remaining standard sets are not easy to distinguish visually, particularly those ones containing non-fractal standard image patterns. An alternative approach to deal with these cases consists of making use of different techniques concerning computational algebraic geometry [36].  1  1  3  13  1  0  25  0  0  2  1  3  14  2  1  26  0  0  3  1  0  15  2  2  27  0  0  4  1  1  16  1  0  28  0  4  5  1  3  17  3  0  29  0  0  6  1  3  18  2  2  30  0  0  7  1  3  19  1  1  31  0  4  8  1  3  20  1  0  32  0  4  9  1  3  21  1  3  33  0  4  10  1  0  22  2  2  34  1  3  11  2  0  23  1  3  35  1  3  12  2  1  24  4  0 Let us define the affine algebraic set associated to the s-standard r × m image pattern P r,m;s (L) = (p i,j ) of a Latin square L ∈ L n;n 2 in the multivariate polynomial ring Q[{x 1 , . . . , x n }] as the set of zeros of the binomial ideal From (1) and (2), it is I(P r,m;s (L)) ⊆ I(L) and hence, V Q (I(L)) ⊆ V Q (I(P r,m;s (L))). Example 6. Let us consider the Latin square L 4.12 described in Figure 1 and the multivariate polynomial ring C[{x 1 , x 2 , x 3 , x 4 }]. The reduced Gröbner basis associated to the binomial ideal I(L 4.12 ) is the subset whereas that one associated to the ideal I(P 90,90;4 (L 4.12 )) is the subset Of course, if the standard sets of r × m image patterns associated to two Latin squares of the same order n coincide, up to permutation of symbols, then the multisets formed by the respective cardinalities of each one of the n affine algebraic sets related to their standard image patterns must also coincide. In particular, from Lemma 1, these multisets coincide for any two isomorphic Latin squares. To illustrate these aspects, Table 2 shows all these cardinalities for the standard image patterns described in Figure 2. It is so that there exist ten isomorphism classes of Latin squares of order four that are related to the multiset {2, 2, 2, ∞}, nine classes to {2, 2, 2, 2}, six classes to {3, 3, ∞, ∞}, four classes to {2, 2, ∞, ∞}, two classes to {2, 3, ∞, ∞} and another two classes to {∞, ∞, ∞, ∞}. Moreover, there are two isomorphism classes that are characterized by their respective multisets. Their representatives are the Latin squares L 4.17 and L 4.35 , which are, respectively, associated to the multisets {2, ∞, ∞, ∞} and {5, 5, ∞, ∞}. In addition, notice that the combination of Tables 1 and 2 characterizes the isomorphism class having the Latin square L 4.34 as its representative. Table 2. Cardinalities ( V i,s ) of the affine algebraic set V Q (I(P 90,90;s (L 4.i ))), for all positive integers i ≤ 35 and s ≤ 4.
To facilitate the recognition and analysis of similar standard sets for distinguishing non-isomorphic Latin squares of the same order n, even from a simple visual observation, one may focus on those ones having exactly the same positive number of fractal standard image patterns, as well as the same number of constant standard image patterns and the same multisets of cardinalities of their related affine algebraic sets. Let us illustrate this fact with the case n = 4, by means of the values in Tables 1 and 2  A more interesting case is that one concerning the eleven isomorphism classes whose respective standard sets contain exactly one constant and three fractal standard image patterns. Table 2 partitions them into four disjoint subsets. Two of them have already been characterized by these parameters. They correspond to the Latin squares L 4.34 and L 4. 35 . The other two subsets are the following ones.  Figure 2 is not so evident. It is so that all their 2-standard image patterns coincide and a much more detailed observation of their 3-and 4-standard sets is required for ensuring that their standard sets are pairwise distinct.
• A detailed observation is also required for distinguishing visually the standard sets of the Latin squares L 4.12 and L 4.14 , both of them containing exactly two constant and one fractal standard image pattern. More specifically, it may be checked (either visually or by making use of Definition 2) that the second row of the fractal standard image pattern of L 4.12 contains all the four colors or symbols under consideration, whereas that one of L 4.14 only contains two of them.
None of the standard sets of the remaining ten isomorphism classes contains fractal standard image patterns, which makes much more difficult their visual distinction. According to their respective parameters, they can be partitioned into the following two sets. A possible approach to analyze the non-fractal standard image patterns of both subsets is reducing their dimension, which is equivalent to zoom in to the left upper corner of the original standard image patterns. Based on this approach, it is simply verified from the results in Figures 3 and 4 that the standard sets of 3 × 3 image patterns associated to these two subsets are pairwise distinct, even allowing a possible permutation of symbols.

A Computational Algebraic Geometry Approach to Deal with Being Either Partial Transpose or Partial Isotopic
We show in Section 3 how the computation of isomorphism invariants concerning affine algebraic sets based on a set of Latin squares plays a fundamental role in the recognition and analysis of their related image patterns. Apart from these invariants, the existence of certain equivalence relations among partial Latin squares of the same order and weight is also known [36], which give rise to the same or isomorphic affine algebraic sets. It is the case of being partial transpose and being P-partial isotopic, for some subset P ⊂ [n] × [n] × [n] (see Lemma 2 and Proposition 1). Let us finish this paper by showing how computational algebraic geometry is also an interesting approach to deal with both equivalence relations. To this end, let us introduce a pair of ideals within a multivariate polynomial ring, whose respective affine algebraic sets are respectively identified with the set of partial Latin squares that are partial transpose of another given partial Latin square, and the set of partial isotopisms between two partial Latin squares.
Firstly, for each positive integer n, we consider the set of n 3 variables Then, for each positive integer m ≤ n 2 , it is known [18] (see also [27,29] for a pair of first approaches in this regard) that the set L n;m is uniquely identified with the set of zeros of the affine algebraic set of the following ideal in Q[X PT n ].
Let us recall here that the sum of two ideals I and J is the ideal I + J = {i + j : i ∈ I, j ∈ J}. Each addend constitutes a subideal of the resulting ideal. Hence, our ideal I n is the sum of four subideals. The first one implies that any zero of I n is of the form (a 111 , . . . , a nnn ) ∈ {0, 1} n 3 . The remaining subideals imply that this zero is uniquely identified with a partial Latin square L = (l i,j ) ∈ L n;m such that l i,j = k ∈ [n] if and only if a ijk = 1. Now, for each partial Latin square L ∈ L n;m , let us define the following ideal in the multivariate polynomial ring Q[X PT n ].
Lemma 3. The set of partial Latin squares that are partial transpose to a partial Latin square L ∈ L n;m is uniquely identified with the affine algebraic set of the ideal I PT (L).
Proof. Let (a 111 , . . . , a nnn ) ∈ {0, 1} n 3 be a zero of the ideal I PT (L). In particular, it must be a zero of the ideal I n;m and, hence, it is uniquely identified with a partial Latin square L ∈ L n;m such that (i, j, k) ∈ Ent(L ) if and only if a ijk = 1. From the subideal we have that, if (i, j, k) ∈ Ent(L), then either a ijk = 1 or a jik = 1. As a consequence, if (i, j, k) ∈ Ent(L) \ Ent(L ), then (j, i, k) ∈ Ent(L ). Now, let (i, j, k) ∈ Ent(L ) \ Ent(L). In particular, it must be a ijk = 1. If (j, i, k) ∈ Ent(L), then the last subideal describing I PT (L) implies that a ijk = 0, which is a contradiction. Hence, (j, i, k) ∈ Ent(L). Therefore, the partial Latin squares L and L are partial transpose of each other. The reduced Gröbner basis of the ideal I PT (L) ⊂ Q[X PT 3 ] is the subset Hence, the affine algebraic set of the ideal I PT (L) is formed by four points that are uniquely associated to L and the following three partial Latin squares. From Lemma 3, computational algebraic geometry can be used for distributing partial Latin squares of the same order n according to the equivalence relation of being partial transpose. The following result establishes the computational cost that is required to this end in case of being n ≥ 2. (The case n = 1 is trivial.) Theorem 2. Let L ∈ L n , with n ≥ 2. The arithmetic complexity of computing the reduced Gröbner basis of the ideal I PT (L) over the field Q is bounded above by where Thus, the result holds from Theorem 1 and the generators of this ideal, whose coefficients have all of them size one. To see it, Table 3 shows the maximum degree of each one of these generators, together with the number of generators of each type. Then, the result follows because, from Theorem 1, the required arithmetic complexity is bounded above by the maximum value between n 3 3n 3 − 3n 2 + 9n + |Ent(L)| n 3 + 2 n 3 + (α 1 + 2α 2 + 1)(n 3 + 1) and 2 3n 3 − 3n 2 + 9n + |Ent(L)| + α 1 + 2α 2 + 1 3n 3 − 3n 2 + 9n + |Ent(L)| + α 1 + 2α 2 + 1 n 3 . Table 3. Study of the generators of the ideal I PT (L).

Generator Type Maximum Degree Number of Generators
A computational algebraic geometry approach can also be described in the case of dealing with the equivalence relation of being P-partial isotopic, for some subset P ⊂ [n] × [n] × [n]. It follows similarly to the approach concerning the equivalence relation of being isotopic, which was described in (Theorem 13, [18]). To this end, for each positive integer n, let us consider the set of 3n 2 variables X PI n := x ij , y ij , z ij : 1 ≤ i, j ≤ n . Then, for each pair of partial Latin squares L 1 = (l i,j ) and L 2 = (l i,j ) in the set L n;m , let us define the following ideal in the multivariate polynomial ring Q[X PI n ]. Proof. Let us suppose the existence of a zero (a 11 , . . . , a nn , b 11 , . . . , b nn , c 11 , . . . , c nn ) ∈ {0, 1} 3n 2 of the ideal I PI (L 1 , L 2 ). The first three subideals describing this ideal imply that this zero is uniquely related to an isotopism ( f , g, h) ∈ S 3 n such that, for each pair of positive integers i, j ≤ n, the following assertions hold. The fourth subideal implies that this isotopism constitutes a one-to-one map from Ent(L 1 ) \ Ent(L 2 ) to Ent(L 2 ). The fifth one implies that, if the cell (i, j) is empty in L 1 but not in L 2 , then the former cannot be mapped to a non-empty cell in L 2 . Further, the sixth subideal implies that, if the cell (i, j) is empty in both L 1 and L 2 , then it cannot be mapped to a non-empty cell in L 2 . Finally, the last subideal implies that, if the cell (i, j) contains distinct symbols in L 1 and L 2 , then it cannot be mapped to an empty cell in L 2 . Under such assumptions, it is readily verified that the zero under consideration is uniquely identified with a P-partial isotopism from L 1 to L 2 , where P ⊆ Ent(L 1 ) ∩ Ent(L 2 ).  L 3 ). Thus, the related affine algebraic set is empty and hence, no partial isotopism exists between L 1 and L 3 . Hence, the affine algebraic set of the ideal I PI (L 1 , L 2 ) is formed by two points that are uniquely associated to the isotopisms ((1423), (1324), (12)) and ((1423), (1324), Id) in S 3 4 . Both of them constitute P-partial isotopisms from L 1 to L 2 , where P = Ent(L 1 ) ∩ Ent(L 2 ).
From Lemma 4, computational algebraic geometry can be used for distributing partial Latin squares according to the equivalence relation of being P-partial isotopic, for some subset P ⊂ [n] × [n] × [n]. The following result establishes the computational cost that is required to this end in case of being n > 2. (The case n = 1 is trivial.) Theorem 3. Let L 1 and L 2 be two partial Latin squares in L n , with n ≥ 2. The arithmetic complexity of computing the reduced Gröbner basis of the ideal I PI (L 1 , L 2 ) over the field Q is bounded above by where Proof. The ideal I PI (L 1 , L 2 ) is zero-dimensional, because V Q (I PI (L)) ⊂ {0, 1} 3n 2 . Then, similarly to the proof of Theorem 2, the result holds from Theorem 1 and the generators of this ideal, whose coefficients have all of them size one. To see it, Table 4 shows the maximum degree of each one of these generators, together with the number of generators of each type. Then, the result holds because, from Theorem 2, the required arithmetic complexity is bounded above by the maximum value between 3n 2 β 1 3n 2 + 3 3n 2 + (3n 2 + β 2 + β 3 + β 4 ) 3n 2 + 2 3n 2 + 6n(3n 2 + 1) . and 3β 1 + 2(3n 2 + β 2 + β 3 + β 4 ) + 6n Table 4. Study of the generators of the ideal I PI (L 1 , L 2 ).

Conclusions and Further Work
In this paper, we show the relevant role that computational algebraic geometry plays in the recognition and analysis of image patterns associated to Latin squares. To this end, we introduce the concepts of standard image pattern and standard set of a given Latin square. Moreover, a new affine algebraic set associated to any such image pattern is described, whose isomorphism invariants can be used for distinguishing different standard sets and hence, for determining in a computationally fast way (even visually) whether two Latin squares are not isomorphic.
The main limitation of the methodology here proposed is the exponential complexity for computing Gröbner bases, which is highly dependent on the number of underlying variables. This number coincides in our case with the order of the Latin square under consideration. Due to it, this limitation is not an inconvenience at all for dealing with the smallest orders for which no results on the distribution of Latin squares into isomorphism classes is known (n ≥ 12). In fact, this computational approach turns out to be an efficient way for dealing with Latin squares of much higher orders. To illustrate this fact, let us consider the Latin square of order 256 that is represented by colors in Figure 5. It was randomly constructed by following Algorithm 1 in [48], which gives rise to random Latin squares with possible implementation in cryptography. Notice in any case that every Latin square generated in this way is isotopic to a diagonally cyclic Latin square [49]. Figure 6 shows the running time required by an Intel Core i7-8750H CPU (6 cores), with a 2.2 GHz processor and 8 GB of RAM for computing both the reduced Gröbner basis of the binomial ideal associated to the s-standard 90 × 90 image pattern of this Latin square described in Figure 5, for every positive integer s ≤ 256, together with the cardinality of its related affine algebraic set. The maximum running time was 3.45 s, which is reached for s = 101.  It is remarkable that the methodology here described may be particularized in order to make more efficient the computation of group isomorphisms. Let us recall in this regard that every associative quasigroup constitutes a group. To illustrate this fact, let us consider both the dihedral and the abelian groups of order six, whose respective multiplication tables are the Latin squares Their respective standard sets of 90 × 90 image patterns are shown in the 2 × 6 collage of Figure 7. Both standard sets are formed by a constant and five fractal standard image patterns. It is readily verified from a visual way that the standard set of the dihedral group (top row of the collage) does not coincide with the standard set of the abelian group (bottom row of the collage), even allowing a possible permutation of symbols. In this simple way, we may ensure that these two groups are not isomorphic. A similar conclusion arises from the computation of the reduced Gröbner bases concerning both types of affine algebraic sets associated to the dihedral and the abelian group of order six. From this computation, we have that |V C (I(D 6 ))| = 3 and |V C (I(Z 6 ))| = 7.
Further, the methodology here described can be generalized for other types of arrays non-subjected to the Latin square condition. In this regard, it would be interesting to delve, for instance, into the study of standard sets of image patterns associated to (partial) semigroups or, more generally, to (partial) magmas. Even if they may not be endowed with a left or right division (as quasigroups are), their multiplication tables enable us to define r × m image patterns based on these algebraic structures by making use to this end of the corresponding conditions described in (2) (see [50], for a first approach in this regard in case of dealing with magmas).
These conditions may be taken into account to deal also with arrays related to other types of mathematical structures, not only algebraic ones. To illustrate this aspect, let us focus on the classical problem in graph theory of determining whether two given graphs are isomorphic or not. Every adjacency matrix of a given simple graph of order n is a binary symmetric n × n array with main diagonal of zeros. It may be considered the multiplication table of a finite magma of set of symbols {0, 1, . . . , n − 1} from which one could define r × m image patterns satisfying the corresponding conditions in (2). Then, standard sets of s-standard image patterns, with s ∈ {0, 1 . . . , n − 1}, could be defined similarly to those ones described in Section 3. In this way, the standard set of two isomorphic regular graphs would always coincide, up to permutations of symbols. This fact may therefore be used for distinguishing non-isomorphic regular graphs, even from a visual way. Thus, for instance, the following two arrays constitute respective incidence matrices of the complete graph K 4 and the cycle C 4 . The standard sets of the 90 × 90 image patterns associated to both graphs are shown in the 2 × 4 collage of Figure 8. Notice that the standard set of the complete graph K 4 (top row of the collage) is formed by one constant and three fractal image patterns, whereas that one of the cycle C 4 is formed by one constant, two fractal and one almost constant (except for its first row, the 3-standard image pattern is monochromatic) image patterns. Hence, these two regular graphs are not isomorphic. These examples illustrate the relevance that standard sets of image patterns may have for distributing distinct types of algebraic and combinatorial structures into isomorphism classes. A much more comprehensive study dealing with their recognition and analysis is required in any case. It is established as further work. Similar to the methodology here implemented, computational algebraic geometry may be an interesting approach to this end. Furthermore, notice that this paper has not dealt with the fractal gradation of the image patterns under consideration. A comprehensive analysis of their fractal dimensions is of particular interest in order to improve the efficiency of this computational approach.
This paper also focuses on the possible use of computational algebraic geometry for dealing with the distribution of partial Latin squares according to the equivalence relations of being either partial transpose or P-partial isotopic, for some subset P ⊂ [n] × [n] × [n]. An exhaustive enumeration of these classes is also established as further work. Concerning the distribution into P-partial isotopism classes, it is required to delve into the study of P-partial autotopisms (that is, P-partial isotopisms from a partial Latin square to itself) and make use of the Orbit-Stabilizer Theorem in a similar way to the already studied distribution of partial Latin squares into isotopism classes [18].
Again, the main limitation of the methodology here introduced is the high dependence on the number of variables required by each one of the affine algebraic sets under consideration. To see it, it has been made use of the already mentioned Algorithm 1 described in [48] in order to obtain random Latin squares on which the computational efficiency of using Gröbner bases has been checked for determining both the set of Latin squares that are partial transpose of another given Latin square, and the set of partial autotopisms of a Latin square. Figure 9 shows the running time required by our computer system for computing both the reduced Gröbner basis of the corresponding ideal, together with the cardinality of its related affine algebraic set. Notice that only the relationship of being partial transpose seems to be useful for dealing by itself with the smallest orders for which no results on the distribution of Latin squares into isomorphism classes is known (n ≥ 12). It is not the case of the equivalence relation of being P-partial isotopic, for some subset P ⊂ [n] × [n] × [n], whose exponential growth starts visibly much before, even from order n = 5. It agrees with the fact that this equivalence relation comprehends that one of being isotopic, for which previous studies [18] have already revealed the advantages of using some extra Latin square isomorphism invariant for reducing the computational cost of an analogous algebraic geometry approach. Similar studies concerning this new equivalence relation are, therefore, required and established as further work. In this regard, the joint use of the Latin square isomorphism invariants recently introduced in [34,35] may be of particular interest. It is also interesting to illustrate the computational efficiency of these two approaches in case of dealing with partial Latin squares with empty cells, whose distribution into isomorphism classes is only known [17,18] for order n ≤ 6. Firstly, let us focus on the use of Gröbner bases for determining the set of partial Latin squares that are partial transpose of another given partial Latin square. To this end, a partial Latin square in the set L 10;m was randomly constructed, for each positive integer m ≤ 100, by means of Method (A) described in [34]. The latter consists of adding sequentially a set of feasible random entries to an empty partial Latin square until the desired weight is reached. Figure 10 shows the running time required by our computer system for determining both the reduced Gröbner basis of the corresponding ideals and the cardinalities of their related affine algebraic sets. The maximum running time was 13.99 s, which is reached for m = 50. It is remarkable the slightly decreasing tendency of this running time with respect to the weight of the partial Latin square under consideration. Figure 10. Running time (in seconds) required for computing the cardinality of the set V Q (I PT (L)), for random partial Latin squares L ∈ L 10;m , with 1 ≤ m ≤ 100. Now, to illustrate the computational efficiency of using Gröbner bases for determining the set of P-partial isotopisms between two given partial Latin squares, for some subset P ⊂ [n] × [n] × [n], the mentioned method of adding random entries has been used to construct a pair of random partial Latin squares in the set L 7;m , for each positive integer m ≤ 49. (Recall that n = 7 is the first order for which no result on the distribution into isotopism classes is known.) Figure 11 shows the running time required by our computer system for determining both the reduced Gröbner basis of the corresponding ideals and the cardinalities of their related affine algebraic sets. The maximum running time has been 102.43 s, which is reached for m = 49 (the Latin square case). The fast exponential growth of running time is remarkable for dense partial Latin squares. Partial Latin squares with either only one filled cell of with more or less the same number of empty and filled cells seem also to require more running time. All these cases turned out to be related to a high number of partial isotopisms. In any case, a much more comprehensive computational analysis concerning orders, weights and particular isomorphism classes of partial Latin squares is required for distinguishing potential bottlenecks in the computation of related Gröbner bases. Figure 11. Running time (in seconds) required for computing the cardinality of the set V Q (I PI (L, L)), for random partial Latin squares L ∈ L 7;m , with 1 ≤ m ≤ 49.
Let us finish this section by establishing the following open problems to deal also with as further work on this topic.

Problem 1.
What are the minimum and maximum numbers of partial Latin squares that are partial transpose of a partial Latin square in L n;m ? Problem 2. What are the minimum and the maximum numbers of distinct partial Latin squares for which there is at least one P-partial isotopism to a partial Latin square in L n;m , for some subset P ⊂ [n] × [n] × [n]? Problem 3. What is the maximum cardinality of a subset P ⊂ [n] × [n] × [n] for which a P-partial isotopism exists between two distinct partial Latin squares in L n;m ?
Funding: This research received no external funding.

Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.