1 Introduction

Reconstruction of finite discrete sets having prescribed projections is a challenging well-known inverse problem. In many cases, it shares its domain with Physics, Chemistry, Medical imaging and other areas where discrete models of real objects are employed. In discrete tomography, the object to be reconstructed is represented by a set of parallel slices, each modeling as a binary matrix the set of points of the object lying on the corresponding 2D plane. So, the basic problem is the reconstruction of a binary matrix from the collected projection data, that are obtained by means of X-rays in a set U of different directions.

Since the discrete sets consistent with a given set of projections are, in general, a huge number, and these can be mutually very different, further constraints are required to select only those solutions that match the structures we are concerned with.

In the literature, the connectedness constraints have been primarily investigated, and many meaningful results have been obtained, both concerning the reconstruction and the enumeration of possible solutions in such a restricted space (see [24, 25] for an overview). Differently, one can confine the investigation to a given lattice grid \({\mathcal {A}}\), so looking for uniqueness conditions inside \({\mathcal {A}}\), or in suitable subregions of \({\mathcal {A}}\) (a non-exhaustive list of useful papers is [9, 14,15,16, 22, 23, 26, 28], also including the corresponding reference sections).

In case different discrete sets \(Y_1\) and \(Y_2\) are tomographically equivalent with respect to a set U of directions, namely when \(Y_1, Y_2\) can be reconstructed by means of the same X-rays with respect to U, then there exist specific patterns, called switching components which turn \(Y_1\) into \(Y_2\). So, understanding the combinatorial and the geometric structure of the switching components is a main issue for a faithful reconstruction, largely investigated in discrete tomography, also in terms of ghosts or bad configurations (see, for instance [3, 5, 6, 8, 9, 11, 16, 18,19,20,21, 23, 27]).

The aim of the present paper falls in this area of research, and concerns finite discrete sets that are horizontally and vertically convex, and that share the same projections along those preferred directions, i.e., the horizontal and the vertical ones.

In particular, we are interested in the characterization of the switching components having a special geometrical condition, which defines a class of patterns called hv-convex switching components. It includes the classes of regular and of irregular switching components considered in [21], that, following [13], can be also defined in terms of hv-convex windows and hv-convex curls, respectively.

We show that these hv-convex switchings can be encoded by a sequence of integers. We provide a complete description of the combinatorial structures of such sequences, and an algorithm for their explicit constructions.

The paper extends and generalizes the results in [13]. It is structured as follows: in Sect. 2 we give the notations, and we provide the basic knowledge on switching components. We introduce windows and curls, then adding to both of them the hv-convex constraint, which leads to the basic Definition 5, where the notion of hv-sequence is stated. Section 3 contains one of the main results of our study, i.e. Theorem 17, which provides the characterization of the entries of the hv-convex sequences according to the number of points of the related hv-convex switching. In [13], only the easier case of hv-sequences related to windows had been focused, with a few sporadic examples concerning allowed or forbidden hv-sequences of curls. This led to [13, Problem 1], which asked for the characterization of all hv-sequences. By Theorem 17, we have completely solved Problem 1, and, as a particular case, we get also the characterization of the hv-sequences having just one odd repeated entry (Corollary 18), which provides the curl counterpart of [13, Theorem 3], holding for windows. In Sect. 4, we deeper investigate the geometric and the combinatorial structure of the hv-convex switchings. Thanks to Theorem 25 and Algorithm 1, CompSeq, we characterize and compute the exact positions, inside the hv-sequence, of the allowed entries, which frames in the proper context the sporadic cases considered in [13]. In Sect. 5, we provide a few concluding remarks, and outline some hints for possible further developments.

2 Notations and Preliminaries

We adopt the standard notation \({\mathbb {Z}}^2\) to indicate the lattice of points of the Euclidean two-dimensional space having integer coordinates. For each point \(v\in {\mathbb {Z}}^2\), we denote by \(L_h(v)\) and \(L_v(v)\) the horizontal and vertical discrete lines intersecting v, respectively. A set of points \(A \subset {\mathbb {Z}}^2\), considered up to translations, is horizontally (resp. vertically) convex if, for each \(v\in A\), the set \(L_h(v)\cap A\) (resp. \(L_v(v)\cap A\)) is connected. A set that is both horizontally and vertically convex is shortly called hv-convex. A polyomino is a finite set of points in \({\mathbb {Z}}^2\) whose elements are 4-connected.

For a finite set A, we define its horizontal (resp. vertical) projection to be the integer vector H(A) (resp. V(A)) counting the number of points of A that lie on each horizontal (resp. vertical) line intersecting A.

Given a point \(v=(i,j)\in {\mathbb {Z}}^2\), the four following closed regions are defined (with the same notations as in [12, 17]):

$$\begin{aligned} Z_0(v)= & {} \{(i',j')\in {\mathbb {Z}}^2 : i'\le i,\, j'\le j\},\\ Z_1(v)= & {} \{(i',j')\in {\mathbb {Z}}^2 : i'\ge i,\, j'\le j\},\\ Z_2(v)= & {} \{(i',j')\in {\mathbb {Z}}^2 : i'\ge i,\, j'\ge j\},\\ Z_3(v)= & {} \{(i',j')\in {\mathbb {Z}}^2 : i'\le i,\, j'\ge j\}. \end{aligned}$$

A set \(A\subset {\mathbb {Z}}^2\) is said to be quadrant convex, briefly Q-convex, (along the horizontal and vertical directions) if \(Z_k(v)\cap A\ne \emptyset \) for all \(k=0,1,2,3\) implies \(v\in A\). Figure 1 shows simple examples of the introduced sets.

Fig. 1
figure 1

a A discrete set, and the corresponding horizontal and vertical projections, that is neither horizontally nor vertically convex. b An hv-convex set. c A convex set that is not Q-convex (the dashed cell does not belong to the set)

Lemma 1

Let A be an hv-convex polyomino, and consider a point \(v\in {\mathbb {Z}}^2\). If \(w_1,w_2,w_3\in A\) exist such that \(Z_i(v)\cap \{w_1,w_2,w_3\}\ne \emptyset \) for all \(i=0,1,2,3\), then \(v\in A\).

Proof

By [7, Proposition 2.3], an hv-convex connected set is also Q-convex. The statement follows immediately by the hv-convex property of A. \(\square \)

2.1 Switching Components and the Uniqueness Problem

The following definition introduces the class of hv-switchings.

Definition 2

A pair \(S=(S^0,S^1)\) of sets of points is a hv-switching if:

  • \(S^0 \cap S^1 = \emptyset \) and \(|S^0| = |S^1|\);

  • \(H(S^0)=H(S^1)\) and \(V(S^0)=V(S^1)\), i.e., \(S^0\) and \(S^1\) have the same horizontal and vertical projections.

Each set \(S^0\) and \(S^1\) is indicated as hv-switching component.

A discrete set A contains a hv-switching component if \(S^0\subseteq A\) and \(S^1\cap A=\emptyset \). In this case, we consider \(A=Y\cup S^0\), with Y being a (possibly empty) discrete set; we define the set \(A'=Y\cup S^1\) as the dual of A, and we say that the switching S is associated to A and \(A'\).

A classical result in [27] states that if \(A_1\) and \(A_2\) are two discrete sets sharing the same horizontal and vertical projections, then \(A_2\) is the dual of \(A_1\) with respect to a hv-switching. So, for any point \(v\in S^0\) (resp. \(v\in S^1\)), there exist points \(w_1,w_2\in S^1\) (resp. \(w_1,w_2\in S^0\)) such that \(w_1\in L_h(v)\) and \(w_2\in L_v(v)\).

If \(A_1\) and \(A_2\) are hv-convex sets, then, due to Lemma 1, for any \(v\in S\) there exists one and only one \(i\in \{0,1,2,3\}\) such that \(Z_i(v)\cap S\) consists of points all belonging to the same component of S as v. The quadrant \(Z_i(v)\) is said to be the free region of v, or the S-free region of v in case we wish to emphasize that the free region relates to the switching S. We denote by F(v) (or by \(F_S(v)\)) the free region of \(v\in S\). Also, \(F_i(S)\) denotes the subset of S consisting of all points having free region \(Z_i(v)\), namely \(F_i(S)=\{v\in S,\,F_S(v)=Z_i(v)\}\), \(i\in \{0,1,2,3\}\).

We have the following result from [12]

Lemma 3

Let \(S=(S^0,S^1)\) be a hv-switching. Then, the following conditions are equivalent

$$\begin{aligned}&\displaystyle {\bigcup _{i=0}^3F_i(S)=S.} \end{aligned}$$
(1)
$$\begin{aligned}&v,w\in F_i(S), i\in \{0,1,2,3\}, v\in S^0,\nonumber \\&w\in S^1 \Rightarrow \,v\notin Z_j(w),\nonumber \\&\,w\notin Z_j(v), j=i+2\,(\mathrm{mod}\, 4). \end{aligned}$$
(2)

Let \(S=(S^0,S^1)\) be a hv-switching.

The following definition introduces the subclass of hv-switching we wish to deal with.

Definition 4

A hv-switching S is said to be a hv-convex switching if the equivalent conditions of Lemma 3 hold.

In the literature, hv-convex switchings have been deeply studied when related to hv-convex polyominoes (for basic definitions and main results see [24, 25]). In this context, it holds that if \(S=(S^0,S^1)\) is a hv-switching associated to a pair of hv-convex polyominoes, then (1) holds, so S is an hv-convex switching. However, the converse is not necessarily true, namely two polyominoes \(P_1\) and \(P_2\) can exist such that one is the dual of the other with respect to an hv-convex switching S, and such that one or both of them are not hv-convex. An interesting case is Fig. 23 in [21], or Fig. 2.

Fig. 2
figure 2

a an hv-convex switching S where the two components \(S_0\) and \(S_1\) have different colors. b and c are two dual sets with respect to S such that (b) is not hv-convex while (c) is (Color figure online)

In the sequel, we focus on the problem of characterizing the class of hv-convex switchings by integers’ sequences, say hv-sequences, as defined below. Let us start by recalling the following classification of hv-convex switchings introduced in [12, 13].

A closed polygonal curve K in \({\mathbb {R}}^2\) is said to be a squared spiral if K consists of segments having, alternatively, horizontal and vertical direction. Their endpoints form the set of vertices of the polygonal. Assume to travel K according to a prescribed orientation. A vertex v of K is said to be a counterclockwise point if, crossing v, implies a counterclockwise change of direction. Differently, v is a clockwise point. Of course, by reversing the traveling orientation, clockwise and counterclockwise vertices mutually exchange.

Windows and curls.

A squared spiral W is said to be a window if it can be traveled by turning always clockwise, or always counterclockwise. Otherwise, the squared spiral is said to be a curl. Therefore, traveling a curl needs changes of turning direction. From now on, we will consider spirals whose vertices have integer coordinates.

We underline that the set of vertices of a window or a curl forms a hv-switching \(S=(S^0,S^1)\) by considering the vertices alternatively belonging to \(S^0\) and \(S^1\).

Figure 3 shows an example of window and curl pointing out the elements belonging to different hv-switching components.

Fig. 3
figure 3

Examples of squared spirals: a a window, and b a curl. In each spiral, the vertices belonging to the same component of the hv-switching have the same color and the same pattern (full colored and contour colored) (Color figure online)

Let S be a squared spiral (window or curl). Suppose to select any vertex v, and start traveling S moving from v clockwise (or counterclockwise). So, visiting one vertex after the other, we can group them in ordered lists of consecutive clockwise and counterclockwise points.

Definition 5

Once an orientation of a squared spiral S has been chosen, let v be a vertex where the orientation changes. Starting from v, compute the lengths \(k_1, k_2,...,k_n \) of the lists of consecutive vertices having, alternatively, the same and the opposite orientation as v. The resulting sequence of integers \(\pi =(k_1, k_2,...,k_n)\) is said to be the hv-sequence associated to S.

The sequence \(\pi \) is considered cyclically arranged, namely its first entry can be selected arbitrarily among \(k_1,...,k_n\), and then listing the others preserving the given order. If the sequence \((k_1, k_2,...,k_n)\) is periodic, then we adopt the notation \((k_1,...,k_{n'})_h\), to represent the h time repetition of the sequence \((k_1,...,k_{n'})\), with \(n=n' \cdot h\); if \(h=1\), we choose to omit it (see Fig. 5 for examples).

It is worth noticing that a \((k_1,...,k_n)_h\) hv-sequence encoding a squared spiral, in general does not guarantee its hv-convexity, since the conditions in Lemma 3 do not automatically hold. Figure 4-(a) shows a (12) hv-convex windows, while, in Fig. 4b it is represented a \((7)_2\) hv-convex curl.

Note that the hv-switchings (a) (resp. (b)) in Figs. 3 and 4 are windows and curls of the same type, and have the same number of points, but only in Fig. 4 the hv-convex property holds.

Fig. 4
figure 4

a an hv-convex window. The central area, where the x points of Theorem 8 can be selected, and the four quadrants where only elements of one single component of the switching are present, are delimited by the gray shading. b a \((7)_2\) hv-convex curl is represented (Color figure online)

Our aim is to investigate the structure of the hv-sequences that are associated to hv-convex switchings, shortly the hv-convex sequences. In particular, we are concerned with the following problem.

Problem. Characterize, and explicitly reconstruct, the hv-convex sequence associated to any given window or curl.

Remark 6

The notions of hv-convex windows and hv-convex curls already appeared in the literature. For instance, these have been considered in [21] in terms of regular and of irregular switching components. Also, the staircases studied in [1], and the staircase-like structures in [2], are special cases of windows.

A straightforward property of hv-convex switchings is:

Proposition 7

Each horizontal and vertical line intersecting an hv-convex switching \(S=(S^0,S^1)\) contains precisely two points of S, one in \(S^0\) and one in \(S^1\).

The easiest case concerns the hv-convex sequences associated to windows. Let us recall the following result from [13]:

Theorem 8

Let W be a window of size \(n\ge 1\) and let \(\{w_1,w_2,...,w_{4n}\}\) be the set of its vertices as encountered when traveling W from any fixed vertex, and with a given orientation. Then, W is an hv-convex switching if and only if a point \(x\in {\mathbb {R}}^2\) exists such that \(w_i\in Z_0(x)\cup Z_2(x)\) for all the odd indices, and \(w_i\in Z_1(x)\cup Z_3(x)\) for all the even indices.

In [13, Theorem 3], a simple characterization had been given for what concerns the hv-convex sequences associated to hv-convex windows. For the convenience of the reader, we repeat below the proof.

Theorem 9

For each \(n>0\), an hv-convex switching S has hv-convex sequence \(\pi =(4n)\) if and only if S is an hv-convex window.

Proof

Suppose that S is a window. Then, there exists a point x as in Theorem 8. Note that all quadrants \(Z_i(x)\), \(i\in \{0,1,2,3\}\) contain the same number of points of S. Since S has 4n vertices, and can be traveled by turning always in the same direction, then \(\pi =(4n)\). Conversely, assume that an hv-convex sequence is \(\pi =(4n)\). Since \(\pi \) consists of a single entry, then no change of direction occurs when traveling S, so S is a window, and, from the knowledge that \(\pi \) is an hv-convex sequence, we get that S is an hv-convex window. \(\square \)

Breaking the constraint of the existence of the point \(x\in {\mathbb {R}}^2\) provides an easy way to define windows of whatever number (multiple of 4) of vertices that are hv-switchings without being hv-convex. In Figs. 3a and 4a, there are two examples of windows with the same number of vertices that are non-convex and convex hv-switchings.

Differently, the characterization of the hv-sequences associated to hv-convex switchings represented by curls, shortly hv-convex curls, represents a quite challenging task. We address this problem in the following section.

3 Structure of hv-convex Sequences Associated to Curls

We move from the following result in [12, 13]:

Theorem 10

Let C be an hv-convex curl and let v and w be two of its vertices with the same orientation. If precisely \(2n>0\) consecutive vertices between v and w exist having their opposite orientation, then C is not an hv-convex curl.

Theorem 10 implies that the elements of each hv-convex sequence related to an hv-convex curl are odd numbers. For instance, Fig. 4, (a), provides an example where the only entry 7 appears, repeated twice. Differently, in Fig. 5, examples are shown of hv-convex sequences with two different entries.

3.1 Relating hv-convex Curls to Dual Polyominoes

As a first step, let us show how an hv-convex curl can be associated to a discrete set in order to produce two dual hv-convex polyominoes. It is well known that an hv-convex polyomino has the general form as those depicted in Fig. 5. The points of an hv-convex polyomino that touch the sides of its minimal bounding rectangle are called N(orth), S(outh), E(ast) and W(est) feet, according to their positions.

We denote by XY-side the boundary of an hv-convex polyomino running from the X foot to the Y foot, with \(X \in \{N,S\}\), and \(Y \in \{E,W\}\). Also, P(S) represents an arbitrary hv-convex polyomino associated with an hv-convex switching S.

We observe that the two components of an hv-convex switching that are associated to two dual hv-convex polyominoes, must lie on the border of the two polyominoes, in order to preserve horizontal and vertical convexity for both of them, as shown in Fig. 5.

Fig. 5
figure 5

a An hv-convex polyomino where the four feet are highlighted. A \((3,1,1)_2\) hv-convex curl is shown (dashed line), and it is associated to two dual hv-convex polyominoes when adding either the full colored green points or the contour colored blue points. b The polyomino is associated to a \((5,3)_2\) hv-convex curl (dashed line). The labeling of the points of the curl is also provided (Color figure online)

Lemma 11

Let \(\pi \) be an hv-convex sequence, S be the corresponding hv-convex switching, and P(S) be an arbitrary hv-convex polyomino associated to S. Then, \(\pi \) depends only on the number of points of S lying on two consecutive sides of P(S).

Proof

The hv-convex sequence \(\pi \) encodes the alternating lists of clockwise and counterclockwise oriented vertices of S. Since S is a squared spiral, then its vertices are the endpoints of horizontal and vertical sides, and, being S a switching component of P(S), then its vertices all belong to the four sides of P(S). Since the vertices of S correspond pairwise along horizontal and vertical lines, all of them are completely determined just by the subset of vertices belonging to two consecutive sides of P(S). \(\square \)

Corollary 12

Let \(\pi \) be an hv-convex sequence associated to an hv-convex switching S. Let a an b be the number of points of S lying, respectively, on the NE-side, and on the SE-side of P(S). If \(\pi =(k_1,\ldots ,k_n)_2\), then \(k_1+\ldots +k_n=a+b\).

Proof

Since \(\pi =(k_1,\ldots ,k_n)_2\), then S has \(2(k_1+\ldots +k_n)\) vertices. By Lemma 11, the number of vertices of S is twice the number of vertices lying on the union of the NE-side and the SE-side of P(S). Therefore, we get \(k_1+\ldots +k_n=a+b\). \(\square \)

Figure 5 also shows two examples of how hv-convex sequences relate to the points on the sides of a corresponding hv-convex polyomino. In Fig. 5, (a), the hv-convex sequence \(\pi =(3,1,1)_2\) is considered. According to Corollary 12, we must have \(3+1+1=5\) points on two consecutive sides. Up to rotations, this allows four points lying on the NE-side, and one point on the SE-side. By symmetry, we also have four points on the NW-side and one point on the SW-side. In Fig. 5, (b), the sequence \((5,3)_2\) allows five points to lie both on the NE-side and on the SW-side, and three points to lie both on the NW-side and on the SE-side.

Remark 13

A curl C can be uniquely associated to a couple of integers a and b that count the number of points that lie, respectively, on the NE-side, and on the SE-side of P(C). Therefore, we can also adopt for C the notation Curl(ab).

We aim in finding an explicit way for the reconstruction of the whole hv-convex sequence related to Curl(ab) from the only knowledge of the integers a and b. To this, we introduce in the following section two important operators, acting on the labeled vertices of Curl(ab).

3.2 The Horizontal and the Vertical Shift Operators

From now on, let us label the n points of an hv-convex curl C by \(1,2,\dots ,n\), starting from the lowermost point in the NE-side of P(C), and moving counterclockwise, as depicted in Fig. 5b.

Furthermore, let a (resp. b) be the number of points of C lying on the NE-side and SW-side (resp. NW-side and SE-side) of P(C), and assume w.l.g. (by reflection along the horizontal axis) \(a \ge b\). We identify each point \(x\in C\) with its label \(\pmod {(2a+2b)}\), and we define its horizontal and vertical shifted version H(x) and V(x), respectively, as follows:

  • H(x) \(=2a+1-x \pmod {(2a+2b)}\);

  • V(x) \(=1-x \pmod {(2a+2b)}\).

We recall that in case \(a=b\), the corresponding switching component is a window whose sequence is of the form (4h).

Lemma 14

Let \(a,b\in {\mathbb {N}}\), with \(a>b\). For each point \(x \in C=Curl(a,b)\), the point of C with label H(x) lies in the same row of x, while the point of C with label V(x) lies in the same column of x.

Proof

According to the positions of x on the sides of P(C), four cases arise:

\(\mathrm{(i)}\) x lies on the NE-side of P(C): the label of the point y sharing the same row can be obtained by adding to the uppermost point of the NE-side, whose label is a, the \(a-x\) points needed to reach again the row of x, so the label of y is \(2a+1-x=H(x)\). On the other hand, the label of the point z sharing the same column with x is obtained by moving back of \(x-1\) from the last label \(2a+2b\), so \(1- x\pmod {(2a+2b)}\) is the label of V(x).

\(\mathrm{(ii)}\) x lies on the NW-side of P(C): the same argument as in case i) provides the label of y sharing the same row is again \(2a+1-x=H(x)\). The label of the point z sharing the same column with x is obtained by adding to the label \(a+b+1\) the number of points from \(a+b\) to x, i.e., \(a+b-x\). So the label of z turns out to be \(a+b+1+a+b-x=1-x \pmod {(2a+2b)}=V(x)\).

Cases \(\mathrm{(iii)}\) and \(\mathrm{(iv)}\), i.e., when x lies either on the SW-side or on the SE-side of P(C), can be treated analogously. The reader can check these remaining cases on Fig.5, (b). \(\square \)

Lemma 15

Let \(\pi \) be an hv-convex sequence corresponding to an hv-convex curl C. For every odd \(\alpha = 2h+1 \in \pi \), there exists a consecutive sequence \(x_1,\dots , x_\alpha \) of points of C traveled with the same orientation such that the label of \(x_\alpha \) is \(2hb+x_1 \pmod {(2a+2b)}\) if \(x_1\) and \(x_2\) lie in the same row, while if they lie in the same column, the label is \(2ha+x_1 \pmod {(2a+2b)}\).

Proof

Let us first assume that the path from \(x_1\) to \(x_2\) is horizontal. The points \(x_1,\dots ,x_\alpha \) have labels

$$\begin{aligned} x_1, H(x_1), VH(x_1), HVH(x_1), (VH)^2(x_1), \dots , (VH)^h(x_1). \end{aligned}$$

By Lemma 14, it holds

$$\begin{aligned}&VH(x_1)=V(2a+1-x_1) \\&\pmod {(2a+2b)}=1-2a-1+x_1 \\&\pmod {(2a+2b)}=2b+x_1 \pmod {(2a+2b)}. \end{aligned}$$

So, the label of the point \(x_\alpha \) turns out to be

$$\begin{aligned} (VH)^h(x_1)= & {} (VH)^{h-1}(2b+ x_1)\\ \pmod {(2a+2b)}= & {} \dots =2hb + x_1\\&\pmod {(2a+2b)}. \end{aligned}$$

On the other hand, if the path from \(x_1\) to \(x_2\) is vertical, the labels of the points \(x_1,\dots ,x_\alpha \) are

$$\begin{aligned} x_1, V(x_1), HV(x_1), VHV(x_1), (HV)^2(x_1), \dots , (HV)^h(x_1). \end{aligned}$$

Again by Lemma 14, it holds

$$\begin{aligned}&HV(x_1)=H(1-x_1 )\\&\pmod {(2a+2b)}=1+2a-1+x_1\\&\pmod {(2a+2b)}=2a+x_1\\&\pmod {(2a+2b)}. \end{aligned}$$

So, the label of the point \(x_\alpha \) turns out to be

$$\begin{aligned} (HV)^h(x_1)= & {} (HV)^{h-1}(2a+ x_1)\\ \pmod {(2a+2b)}= & {} \dots =2ha + x_1 \pmod {(2a+2b)}. \end{aligned}$$

\(\square \)

The next theorem provides a complete characterization of the combinatorial structure of Curl(ab) for any possible choice of a and b, also showing that the corresponding hv-convex sequences always consist of one or two different repeated entries.

Remark 16

For the sake of brevity, in what follows sentences of the form “the point x belongs to the XY-side of P(C)” are often simply replaced by \(x\in XY\).

Theorem 17

Let \(a,b\in {\mathbb {N}}\), with \(b<a\), and let \(\pi \) be the hv-convex sequence associated to \(C=Curl(a,b)\). Then, \(\pi \) consists of \(N_{\alpha }\) entries \(\alpha =2h+1\), and \(N_{\gamma }\) entries \(\gamma =2h+3\), where

$$\begin{aligned} N_{\alpha }= & {} 2(h+1)a-2(h+2)b \end{aligned}$$
(3)
$$\begin{aligned} N_{\gamma }= & {} 2(h+1)b-2ha \end{aligned}$$
(4)
$$\begin{aligned} h= & {} \left\lfloor \frac{b}{a-b}\right\rfloor \end{aligned}$$
(5)

Proof

Let \(x\in [1,b]\), and note that \(V(x)=1-x=2a+2b+1-x \pmod {(2a+2b)}\), so \(V(x)\in SE\) (see Remark 16). Also, \(H(x)=1+2a-x\), so, if \(x\le a-b\), then \(H(x)\in SW\). This means that each \(x\in [1, a-b]\) has orientation different from H(x), and has the same orientation of V(x), say clockwise without loss of generality. Therefore, each such x is the endpoint of a path in Curl(ab). Note that \((HV)^h(x)\in NE\) if h is even, while \((HV)^h(x)\in SW\) if h is odd. Consequently, x is the starting point of a clockwise oriented path of minimal length \(\alpha =2h+1\) if and only if the following conditions hold

  1. (i)

    \(V((HV)^h)(x)\in SW\) if \(h=2k\), for some \(k\ge 0\).

  2. (ii)

    \(V((HV)^h)(x)\in NE\) if \(h=2k-1\), for some \(k\ge 1\), .

Suppose that \(h=2k\) for some \(k\ge 0\). We have

$$\begin{aligned}&(HV)^h(x)=2ha+x\\&\pmod {(2a+2b)}=4ka+x\\&\pmod {(2a+2b)}=2k(a-b)+x, \end{aligned}$$

so \((HV)^h(x)\in NE\) provides \(1\le 2k(a-b)+x\le a\), that is

$$\begin{aligned} x\in [hb-ha+1, hb-(h-1)a]. \end{aligned}$$
(6)

Condition (i) provides

$$\begin{aligned} a+b+1\le & {} 1-(2k(a-b)+x)\\ \pmod {(2a+2b)}\le & {} 2a+b, \end{aligned}$$

that is

$$\begin{aligned} \left\{ \begin{array}{l} x\ge 1-2k(a-b)-2a-b\pmod {(2a+2b)} \\ \quad =1+(2k+1)b-2ka>(2k+1)b-2ka\\ x\le -2k(a-b)-a-b\pmod {(2a+2b)}\\ \quad =-2k(a-b)+a+b=(2k+1)b-(2k-1)a, \end{array}\right. \end{aligned}$$

so that x ranges in the interval \(((2k+1)b-2ka,(2k+1)b-(2k-1)a]=((h+1)b-ha,hb-ha+a+b]\). Matching with (6), and with \(x\in [1, a-b]\), we obtain

$$\begin{aligned} \left\{ \begin{array}{l} (h+1)b-ha\ge 0\\ (h+1)b-ha<a-b\\ hb-ha+a+b\le a-b, \end{array}\right. \end{aligned}$$

which provides

$$\begin{aligned} \frac{h}{h+1}a\le b<\frac{h+1}{h+2}a. \end{aligned}$$
(7)

This implies

$$\begin{aligned} \frac{b}{a-b}-1<h\le \frac{b}{a-b}, \end{aligned}$$

and (5) follows.

Therefore, if \(h=2k\), and \(x\in ((h+1)b-ha,(h+1)b-(h-1)a]\), there exist \(N_{\alpha _1}=(h+1)a-(h+2)b\) entries of \(\pi \) equal to \(\alpha =2h+1\). Differently, if \(h=2k\), and \(x\in [1,(h+1)b-ha]\), any clockwise oriented path starting at x, must have length \(2h'+1\ne \alpha \), and consequently \(h'>h\), due to the minimal assumption on \(\alpha \). Let us consider \(h'=h+1\). Then, \(h'\) is odd, so \(HV^{h'}(x)\in SW\). Since h is even, it is \(-ha=hb \pmod {(2a+2b)}\), so, also exploiting (7), we get

$$\begin{aligned} V((HV)^{h'}(x))&=1-(2(h+1)a+x)\\&=-ha+(h+2)b+1-x\\&\le -ha+(h+2)b<-ha+(h+1)a=a. \end{aligned}$$

Therefore, \(V((HV)^{h'}(x))\in NE\), which implies that the orientation of \(V((HV)^{h'}(x))\) differs from that of \((HV)^{h'}(x)\). This means that any \(x\in [1,(h+1)b-ha]\) is the starting point of a path of length \(\gamma =2h'+1=2h+3\). Therefore, there exist \(N_{\gamma _1}=(h+1)b-ha\) entries of \(\pi \) equal to \(\gamma =2h+3\).

When \(x\in [1, a-b]\), we get \(N_{\alpha _1}+N_{\gamma _1}\) entries of \(\pi \), corresponding to disjoint paths of length \(\alpha \) and \(\gamma \), respectively. These paths include a number of points of Curl(ab) given by

$$\begin{aligned}&\alpha N_{\alpha _1}+\gamma N_{\gamma _1}\\&\quad =(2h+1)[(h+1)a-(h+2)b] \\&\quad \quad +(2h+3)[(h+1)b-ha]=a+b. \end{aligned}$$

By symmetry, the same arguments can be applied to paths having starting points at \(x\in [a+b+1,2a]\), which provides \(N_{\alpha _2}=N_{\alpha _1}\) paths of length \(\alpha \), for \(x\in (a+b+(h+1)b-ha,2a]\), and \(N_{\gamma _2}=N_{\gamma _1}\) paths of length \(\gamma \), for \(x\in [a+b+1,a+b+(h+1)b-ha]\). These paths include \(a+b\) additional points of Curl(ab). Consequently, we have \(N_{\alpha }=N_{\alpha _1}+N_{\alpha _2}=2[(h+1)a-(h+2)b]\) entries of \(\pi \) equal to \(\alpha =2h+1\), and \(N_{\gamma }=N_{\gamma _1}+N_{\gamma _2}=2[(h+1)b-ha]\) entries of \(\pi \) equal to \(\gamma =2h+3\). These entries correspond to paths of Curl(ab) which include \(2a+2b\) different points. Since Curl(ab) contains exactly \(2a+2b\) points, then the sequence \(\pi \) cannot have any further entry, and the statement follows.

Suppose now that \(x\in [1, a-b]\), and \(h=2k-1\) for some \(k\ge 1\). Then, we can write

$$\begin{aligned} (HV)^h(x)&=2ha+x\pmod {(2a+2b)}\\&=4ka-2a+x\pmod {(2a+2b)}\\&=2k(a-b)+2b+x, \end{aligned}$$

so \((HV)^h(x)\in SW\) provides \(1+a+b\le 2k(a-b)+2b+x\le 2a+b\), that is

$$\begin{aligned} x&\in [(2k-1)b-(2k-1)a+1, (2k-1)b-2(k-1)a] \nonumber \\&=[hb-ha+1,hb-ha+a] \end{aligned}$$
(8)

Condition (ii) provides

$$\begin{aligned} 1\le 1-(2k(a-b)+2b+x)\pmod {(2a+2b)}\le a, \end{aligned}$$

that is

$$\begin{aligned} \left\{ \begin{array}{l} x\ge 1-2k(a-b)-2b-a\pmod {(2a+2b)}\\ \quad =1-2ka+2kb+a>2kb-(2k-1)a\\ x\le -2k(a-b)-2b\pmod {(2a+2b)}\\ \quad =2kb-2ka+2a, \end{array}\right. \end{aligned}$$

so that x ranges in the interval \((hb-ha+b, hb-ha+a+b]\). Matching with (8), and with \(x\in [1,a-b]\), we get \(x\in (hb-ha+b,a-b]\), under conditions (5). This provides again \(N_{\alpha _1}=(h+1)a-(h+2)b\) as in the case when h is even.

Therefore, if \(h=2k-1\), and \(x\in (hb-ha+b,a -b]\), then there exist \(N_{\alpha _1}=(h+1)a-(h+2)b\) entries of \(\pi \) equal to \(\alpha =2h+1\).

Differently, if \(h=2k-1\), and \(x\in [1,hb-ha+b]\), any clockwise oriented path starting at x, must have length \(2h^{\prime }+1\ne \alpha \), and consequently \(h'>h\), due to the minimal assumption on \(\alpha \). Let us consider \(h'=h+1\). Then, \(h'\) is odd, so \((HV)^{h'}(x)\in NE\). Being \(h'=h+1\) even, we can write

$$\begin{aligned}&V((HV)^{h'}(x)) = 1-(2(h+1)a+x)\\&\pmod {(2a+2b)} = (h+2)b-ha+a+b+1-x. \end{aligned}$$

Since \(x\in [1,hb-ha+b]\), then by (5), we get

$$\begin{aligned} \begin{array}{l} V((HV)^{h'}(x))\ge a+2b+1>a+b+1\\ V((HV)^{h'}(x))<a+a+b+1-x\le 2a+b.\end{array} \end{aligned}$$

Therefore, \(V((HV)^{h'}(x))\in SW\), which implies that the orientation of \(V((HV)^{h'}(x))\) differs from that of \((HV)^{h'}(x)\). This means that any \(x\in [1,(h+1)b-ha]\), is the starting point of a path of length \(\gamma =2h'+1=2h+3\). Therefore, there exist

$$\begin{aligned} N_{\gamma _1}=(h+1)b-ha \end{aligned}$$

entries of \(\pi \) equal to \(\gamma =2h+3\).

Consequently, for any \(x\in [1,a-b]\), we have the same results as in the case h even. By symmetry, the same holds also for \(x\in [a+b+1,2a]\), and the statement follows. \(\square \)

The following corollary characterizes the hv-sequences having just one odd repeated entry, so it represents a kind of curl counterpart of the case of windows according to Theorem 9.

Corollary 18

For any \(a,b\in {\mathbb {N}}\), \(a>b\), the entries of the hv-convex sequence \(\pi \) associated to Curl(ab) are all equal if and only if \(\frac{b}{a-b}\) is an integer. In addition, the \(2(a-b)\) entries in this case are all equal to \(\frac{a+b}{a-b}\).

Proof

If \(\frac{b}{a-b}\) is an integer, then, by (5), \(h=\frac{b}{a-b}\), so (4) provides \(N_{\gamma }=0\), and, by (3), \(N_{\alpha }=2ha+2a-2hb-4b=2(a-b)\), which proves the statement.

Conversely, suppose that \(\pi \) consists of just one repeated odd entry. Then, by Theorem 17, one of \(N_{\alpha }\) or \(N_{\gamma }\) must be equal to 0. Note that \(N_{\alpha }=0\) implies \(h=\frac{b}{a-b}-1\), which contradicts (5). Therefore, it must be \(N_{\alpha }\ne 0\), so \(N_{\gamma }=0\)., and consequently \(h=\frac{b}{a-b}\). This implies that \(\frac{b}{a-b}\) is an integer, and that \(\pi \) has \(N_{\alpha }=2(h+1)a-2(h+2)b=2a-2b\) entries equal to \(\alpha =2h+1=\frac{a+b}{a-b}\). \(\square \)

Remark 19

By Theorem 17 we get the simple procedure CompSeqEntries, that computes the values of \(\alpha \), \(\gamma \), \(N_\alpha \) and \(N_\gamma \) from arbitrarily chosen integers a and b, with \(a>b\), namely

CompSeqEntries

  • set \(h=\left\lfloor \frac{b}{a-b} \right\rfloor \)

  • return \(\alpha =2h+1\) \(\gamma =2h+3\) \(N_\alpha =2(h+1)a-2(h+2)b\) \(N_\gamma =2(h+1)b-2ha\)

Example 20

Assuming \(a=28, b=5\), the procedure CompSeqEntries in Remark 19, we have \(h=0\), \(\alpha =1\), \(\gamma =3\), \(N_1=2a-4b=36\) and \(N_3=2b=10\). The related hv-convex sequence is \(\pi =(3,1^4,3,1^4,3,1^3,3,1^4,3,1^3)_2\) where \(1^j\) means that the entry 1 is repeated j times. In Fig. 6, a part of the corresponding hv-convex switching C is shown.

Fig. 6
figure 6

A hv-convex switching C with \(a=28\) and \(b=5\)

Remark 21

The case \(a>2b\) is the only one that allows entries equal to 1 to appear in the hv-convex sequence.

Example 22

Assuming \(a=27, b=19\), the procedure CompSeqEntries in Remark19 finds \(\frac{2}{3}a<b<\frac{3}{4}a\), so \(h=2\), and returns \(\alpha =5\), \(\gamma =7\), \(N_5=6a-8b=10\), \(N_7=6b-4a=6\).

4 The Structure of hv-convex Switchings

Theorem 17 shows that any hv-convex sequence consists of one or two repeated entries. Corollary 18 characterizes the case when the hv-convex sequence consists of just one repeated entry. Differently, the problem of understanding how the entries \(\alpha \) and \(\gamma \) mutually alternate in \(\pi \) becomes relevant. To this, we need to know the labels of the endpoints of the paths having lengths \(\alpha \) and \(\gamma \).

Remark 23

In what follows, all the involved intervals consist of just integer labels, even if the simplified “continuous” notation (ab], (instead of \((a,b]\cap {\mathbb {N}}\)) is adopted.

To address the above problem, we first apply CompSeqEntries as pointed out in Remark 19, in order to prove the following.

Lemma 24

Let \(N_\gamma =2(h+1)b-2ha\) be computed by CompSeqEntries. According to the parity of h, it holds

  • \(h\ge 0\) even: \(\frac{N_\gamma }{2} \pmod {(2a+2b)} = -2ha-2a-b \pmod {(2a+2b)}\);

  • h odd: \(\frac{N_\gamma }{2} \pmod {(2a+2b)} = -2ha-a \pmod {(2a+2b)}\).

Proof

\(h\ge 0\) even: it holds

$$\begin{aligned}&-2ha -2a- b\pmod {(2a+2b)} \\&\quad =-2ha-2a-b+(h+2)(a+b)\\&\quad \pmod {(2a+2b)} =(h+1)b-ha=\frac{N_\gamma }{2}. \end{aligned}$$

h odd: it holds

$$\begin{aligned}&-2ha -a \pmod {(2a+2b)} \\&\quad =-(h+1)a-(h-1)a-a \\&\pmod {(2a+2b)}=(h+1)b-(h-1)a-a \\&\pmod {(2a+2b)}=\frac{N_\gamma }{2}.\square \end{aligned}$$

Theorem 25

Let us consider two integers a and b such that \(a>b\). According to what defined in Theorem 17, let C and P(C) be the hv-convex curl and the hv-convex polyomino associated to a and b, and compute the values of h, \(\alpha \), \(\gamma \), \(N_\alpha \) and \(N_\gamma \). We define the following sets of (integer) labels:

  • \(I_\alpha \): \(\left( \frac{N_\gamma }{2},\frac{N_\alpha + N_\gamma }{2} \right] \cup \left( b,\frac{N_\alpha }{2}+b \right] \cup \left( a+b+\frac{N_\gamma }{2},a+b+\frac{N_\alpha + N_\gamma }{2} \right] \cup \left( a+2b,\frac{N_\alpha }{2}+a+2b \right] \);

  • \(I_\gamma \): \(\left[ 1,\frac{N_\gamma }{2} \right] \cup \left[ a+1- \frac{N_\gamma }{2},a \right] \cup \left[ a+b+1,a+b+\frac{N_\gamma }{2}\right] \cup \left[ 2a+b+1-\frac{N_\gamma }{2},2a+b \right] \).

It holds that the elements of \(I_\alpha \) (resp. \(I_\gamma \)) are exactly (the labels of) the endpoints of the same-oriented paths of length \(\alpha \) (resp. \(\gamma \)) of the hv-convex curl C.

Proof

Let us assume w.l.g. that the point with label x lies in the NE-side of P(C) and it is the first point of a path traveled clockwise. From this assumption, it immediately follows that \(H(x)\in SW\), with \(H(x)\le H(1)\), i.e., \(a+b+1\le 1+2a-x\le 2a\), and, consequently, \(x\le a-b=\frac{N_\alpha +N_\gamma }{2}\). So, such a path has a vertical first side. Lemma 15 assures that the last point of the path is \((HV)^h(x)=2ha + x \pmod {(2a+2b)}\) if and only if its length is \(\alpha =2h+1\). The following two cases arise:

  • h even: \((HV)^{h}(x)\in NE\) and \(V(HV)^{h}(x)\in SW\), between V(a) and \(2a+b\). It follows the inequality

    $$\begin{aligned}&2a+2b-a+1 \pmod {(2a+2b)} \le 1-2ha-x \\&\pmod {(2a+2b)} \le 2a+b \pmod {(2a+2b)}, \end{aligned}$$

    and by Lemma 24

    $$\begin{aligned} \left\{ \begin{array}{l} x\le -2ha -a-2b \, (\mathrm{mod}~(2a+2b))= \frac{N_\gamma }{2}+a-b\\ \quad =\frac{N_\gamma +N_\alpha }{2} \\ x \ge 1-2ha -2a -b~(\mathrm{mod}~(2a+2b))=1+\frac{N_\gamma }{2}. \end{array} \right. \qquad \end{aligned}$$

    As a consequence, the previous condition \(x\in \left[ 1,\frac{N_\alpha +N_\gamma }{2}\right] \) restricts to \(x\in \left( \frac{N_\gamma }{2}, \frac{N_\alpha +N_\gamma }{2}\right] \).

  • h odd: \((HV)^{h}(x)\in SW\), and \(V(HV)^{h}(x)\in NE\), between a and \(V(2a+b)\). It follows the inequality

    $$\begin{aligned}&1-2a-b (\mathrm{mod} \,2a+2b)\\&\quad \le 1-2ha-x\\&\pmod {(2a+2b)} \le {a}\!\!\!\!\!{\pmod {(2a+2b)}}, \end{aligned}$$

    and furthermore, \(1+b\le 1-2ha-x \, (\mathrm{mod}~(2a+2b))\le a\) and by Lemma 24

    $$\begin{aligned} \left\{ \begin{array}{l} x\le -2ha -b \, (\mathrm{mod}~(2a+2b)) = 2h b -b \\ \quad \pmod {(2a+2b)} \\ x \ge 1-2ha -a~(\mathrm{mod}~(2a+2b))=1+\frac{N_\gamma }{2}. \end{array} \right. \end{aligned}$$

    Since it also holds \(h \le 1 \) and \(2h b -b \ge b\), then the first inequality is always verified. Again, by the second inequality, the condition \(x\in \left[ 1,\frac{N_\alpha +N_\gamma }{2}\right] \) restricts to \(x\in \left( \frac{N_\gamma }{2}, \frac{N_\alpha +N_\gamma }{2}\right] \).

Summing up, if a path of length \(\alpha \) has starting point x in the NE-side of P(C), then it holds \(x\in \left( \frac{N_\gamma }{2}, \frac{N_\alpha +N_\gamma }{2}\right] \).

Let us now focus on the final point \((HV)^{h}(x)\) of the path: it lies on the NE-side of P(C) when h is even, and it lies on the SW-side of P(C), otherwise. Again, let us analyze the two cases more precisely:

  • h even: by Lemma 24 it holds \(2ha\, (\mathrm{mod}~(2a+2b))=-\frac{N_\gamma }{2}+b\), so \(x\in \left( \frac{N_\gamma }{2}, \frac{N_\alpha +N_\gamma }{2}\right] \) implies

    $$\begin{aligned} (HV)^{h}(x)\in \left( b, \frac{N_\alpha }{2}+b\right] . \end{aligned}$$
  • h odd: a similar computation as in the previous case, from \(x\in \left( \frac{N_\gamma }{2}, \frac{N_\alpha +N_\gamma }{2}\right] \) leads to

    $$\begin{aligned} (HV)^{h}(x)\in \left( a+2b,\frac{N_\alpha }{2}+a+2b\right] . \end{aligned}$$

In case the path is traveled counterclockwise and/or the starting point of the path lies on the SW-side of P(C), then the previous results continue holding, up to a rearrangement of the starting and the ending points. These computations show that the point x can also belong to the interval \(\left( a+b+\frac{N_\gamma }{2}, a+b+\frac{N_\alpha +N_\gamma }{2}\right] \), while the ending point \((HV)^{h}(x)\) can belong either to \(\left( a+2b, a+2b+\frac{N_\alpha }{2}\right] \) or to \(\left( b, b+\frac{N_\alpha }{2}\right] \) according to the parity of h. So, the extremal points of the paths of length \(\alpha \) correspond to the set \(I_\alpha \).

Concerning the set \(I_\gamma \), we suppose that the final point of a path starting in x is of the form \((HV)^{h+1}(x)=2(h+1)a-x \pmod {(2a+2b)}\), i.e., its length is \(\gamma =2h+3\).

The same reasoning as for the case of the \(\alpha \) length paths can be used after updating h with \(h+1\) and up to exchanging the NW-side and the SE-side of P(C). More precisely:

  • h even: \((HV)^{h+1}(x)\) lies on the SW-side of P(C) and \(V(HV)^{h+1}(x)\) lies on the NE-side of P(C) between and a. It follows the inequality

    $$\begin{aligned} 1-2a-b \pmod {(2a+2b)}&\le 1-2(h+1)a-x\\ \pmod {(2a+2b)}&\le a \pmod {(2a+2b)}, \end{aligned}$$

    and by Lemma 24

    $$\begin{aligned} \left\{ \begin{array}{l} x\le -2ha +b \pmod {(2a+2b)} = \frac{N_\gamma }{2} \\ x \ge 1-2ha -3a \pmod {(2a+2b)}=1+\frac{N_\gamma }{2} \\ \qquad +b-a=1-\frac{N_\alpha }{2}. \end{array} \right. \end{aligned}$$

    Since \(1-\frac{N_\alpha }{2}<0\) the second inequality is always verified, so the first inequality allows the condition \(x\in \left[ 1,\frac{N_\alpha +N_\gamma }{2}\right] \) to restrict to \(x\in \left[ 1, \frac{N_\gamma }{2}\right] \).

  • h odd: \((HV)^{h+1}(x)\in NE\), and \(V(HV)^{h+1}(x)\in SW\), between V(a) and \(2a+b\). It follows the inequality

    $$\begin{aligned}&1-a \pmod {(2a+2b)} \\&\quad \le 1-2(h+1)a-x \\&\qquad \pmod {(2a+2b)} \le 2a+b \pmod {(2a+2b)}, \end{aligned}$$

    and, by Lemma 24,

    $$\begin{aligned} \left\{ \begin{array}{l} x\le -2ha -a \pmod {(2a+2b)} = \frac{N_\gamma }{2} \\ x \ge -2ha -4a -b \pmod {(2a+2b)}= \frac{N_\gamma }{2}\\ \qquad -3a+b \pmod {(2a+2b)}=\frac{N_\gamma }{2}-a+b. \end{array} \right. \end{aligned}$$

    Since \(\frac{N_\gamma }{2}-a+b=-\frac{N_\alpha }{2}<0\), then the second inequality is always verified. Again, by the first inequality, the condition \(x\in \left[ 1,\frac{N_\alpha +N_\gamma }{2}\right] \) restricts to \(x\in \left[ 1, \frac{N_\gamma }{2}\right] \).

Summing up, if a \(\gamma \) length path starts from a point x in the NE-side of P(C), then \(x\in \left[ 1, \frac{N_\gamma }{2}\right] \). The last point of the path \((HV)^{h+1}(x)\) lies on the SW-side of P(C) if h is even, and on the NE-side of P(C) otherwise:

  • h even: by Lemma 24 it holds \(2ha\pmod {(2a+2b)}=-\frac{N_\gamma }{2}+b\), so \(x\in \left[ 1, \frac{N_\gamma }{2}\right] \) implies

    $$\begin{aligned} (HV)^{h+1}(x)\in \left[ 2a+b+1-\frac{N_\gamma }{2}, 2a+b\right] . \end{aligned}$$
  • h odd: a similar computation leads to

    $$\begin{aligned} (HV)^{h+1}(x)\in \left[ a+1-\frac{N_\gamma }{2}, a\right] . \end{aligned}$$

In case the path is traveled counterclockwise and/or the starting point of the path lies on the SW-side of P(C), then the previous results continue holding, up to a rearrangement of the starting and the ending points. These computations show that the point x can also belong to the interval \(\left[ a+b+1,a+b+\frac{N_\gamma }{2} \right] \), while the ending point \((HV)^{h+1}(x)\) can belong either to \(\left[ a+1-\frac{N_\gamma }{2}, a\right] \) or to \(\left[ 2a+ b-\frac{N_\gamma }{2}, 2a+b\right] \) according to the parity of h. So, the extremal points of the paths of length \(\gamma \) correspond to the set \(I_\gamma \). \(\square \)

Denote by \(\pi _j\) the subsequence of \(\pi \) consisting of its first j-entries.

The following theorem provides the answer to how the entries \(\alpha \) and \(\gamma \) mutually alternate in the hv-convex sequence S.

Theorem 26

Let \(a,b\in {\mathbb {N}}\), with \(a>b\), and let \(d=\gcd (a,b)\). Then, the hv-convex sequence \(\pi \) associated to Curl(ab) is \(\pi =(\pi _{\frac{a-b}{d}})_{2d}\)

Proof

Let us consider the function \(f_{\lambda }(x)=(HV)^{\lambda }(x)=2\lambda a+x \), where

$$\begin{aligned} \begin{array}{ll} \lambda =\frac{N_{\alpha }}{2}h+\frac{N_{\gamma }}{2}(h+1)+\frac{N_{\alpha }+N_{\gamma }}{4} &{}\text {if }\frac{N_{\alpha }+N_{\gamma }}{2} \text { is even}\\ \lambda =\frac{N_{\alpha }}{2}h+\frac{N_{\gamma }}{2}(h+1)+ \frac{1}{2}\left( \frac{N_{\alpha }+N_{\gamma }}{2}-1\right) &{}\text {if }\frac{N_{\alpha }+N_{\gamma }}{2} \text { is odd} \end{array} \end{aligned}$$

Note that \(\frac{N_{\alpha }+N_{\gamma }}{2} =a-b\), and

$$\begin{aligned} \frac{N_{\alpha }}{2}h+\frac{N_{\gamma }}{2}(h+1)= & {} \frac{N_{\alpha }+N_{\gamma }}{2}h+\frac{N_{\gamma }}{2}\\= & {} (a-b)h+(h+1)b-ha=b, \end{aligned}$$

so that

$$\begin{aligned} \begin{array}{ll} \lambda = b +\frac{1}{2}\frac{N_{\alpha }+N_{\gamma }}{2} &{}\text {if }a-b \text { is even}\\ \lambda =b+\frac{1}{2}\left( \frac{N_{\alpha }+N_{\gamma }}{2}-1\right) &{}\text {if }a-b \text { is odd} \end{array} \end{aligned}$$

Consequently, we get

$$\begin{aligned} f_{\lambda }(x)= & {} 2a\left( b +\frac{1}{2}\frac{N_{\alpha }+N_{\gamma }}{2} \right) +x=a^2+ab+x \nonumber \\&\text {if }a-b \text { is even} \end{aligned}$$
(9)
$$\begin{aligned} f_{\lambda }(x)= & {} 2a\left( b+\frac{1}{2}\left( \frac{N_{\alpha }+N_{\gamma }}{2}-1\right) \right) +x\nonumber \\= & {} a^2+ab-a+x~\text {if }a-b \text { is odd} \end{aligned}$$
(10)

Let \(j\in \left[ 1, \frac{N_{\alpha }+N_{\gamma }}{2} \right] \), and let \(x_j\) be the starting point of the \(j-th\) walked path. Then, the label of the starting point of the \((a-b+j)-th\) traveled path is \(y_j=f_{\lambda }(x_j) \pmod {(2a+2b)}\) if \(a-b\) is even, and \(y_j=V(f_{\lambda }(x_j))=1- f_{\lambda }(1) \pmod {(2a+2b)}\) if \(a-b\) is odd.

Assume \(d=1\), and compute \( f_{\lambda }(x_j) \) in the different allowed cases. We have

  1. (i)

    If \(a-b\) is even, then, being \(d=1\), both a and b are odd integers, so \(a>b\) implies \(a>1\), and consequently \(a^2+ab=(a-1)(a+b)+a+b=a+b \pmod {(2a+2b)}\), and we can write

    $$\begin{aligned}&f_{\lambda }(x_j) \pmod {(2a+2b)} \nonumber \\&\quad =a+b+x_j \pmod {(2a+2b)}, \end{aligned}$$
    (11)
  2. (ii)

    If \(a-b\) is odd, we consider two subcases.

    1. 1.

      a is even and b is odd. We have

      $$\begin{aligned}&a^2+ab-a=a(a+b)-a\\&=-a \pmod {(2a+2b)}=a+2b. \end{aligned}$$

      Therefore, we get

      $$\begin{aligned}&1-f_{\lambda }(x_j) \pmod {(2a+2b)} \nonumber \\&=a+2b+x_j \pmod {(2a+2b)}. \end{aligned}$$
      (12)
    2. 2.

      a is odd and b is even. We have

      $$\begin{aligned}&a^2+ab-a=(a-1)(a+b)+b \\&=b \pmod {(2a+2b)}. \end{aligned}$$

      Consequently, we can write

      $$\begin{aligned}&1-f_{\lambda }(x_j) \pmod {(2a+2b)} \nonumber \\&=b+x_j \pmod {(2a+2b)}. \end{aligned}$$
      (13)

In all the cases, by Theorem 25 it follows that \(x_j\in I_{\alpha }\) if and only if \(y_j\in I_{\alpha }\), and \(x_j\in I_{\gamma }\) if and only if \(y_j\in I_{\gamma }\). Consequently, the entries of \(\pi \) repeat after the first \(\frac{N_{\alpha }+N_{\gamma }}{2} =a-b\), which implies that \(\pi =(\pi _{a-b})_2\). If \(d>1\), let \(a^{\prime }=\frac{a}{d}\) and \(b^{\prime }=\frac{b}{d}\). Then, with the same arguments, we obtain that the sequence associated to \(Curl(a',b')\) is \((\pi _{a^{\prime }-b^{\prime }})_2\). Therefore, the sequence \(\pi \) associated to Curl(ab) is obtained by repeating \((\pi _{a^{\prime }-b^{\prime }})_2\) for d times, namely \(\pi =(\pi _{a^{\prime }-b^{\prime }})_{2d}\), and the statement follows. \(\square \)

Theorems 25 and 26 lead to algorithm CompSeq, which returns the hv-convex sequence \(\pi \) consisting of entries \(\alpha \) and \(\gamma \), and associated to Curl(ab), for any pair of integers ab, \(a>b\). The algorithm also exploits the procedure CompSeqEntries defined in Remark 19.

figure c
Fig. 7
figure 7

The Curl(27,19), with a few labeled points and two paths of lengths \(\alpha \) (dashed line) and \(\gamma \) (solid line) shown

Fig. 8
figure 8

Two distinct hv-convex curls each having sequence \((5)_2\) denoted by full green colored squares (bold dashed lines) and contour blue colored squares (thin dashed lines). After exchanging one of the coordinates of the two neighbor points inside the circle, we merge them into one single curl that preserves the hv-convexity and whose sequence is \((5)_4\) (Color figure online)

Example 27

Let us show the run of CompSeq on input \(a=27\) and \(b=19\) (see Fig. 7). CompSeqEntries(27, 19) outputs \(h=2\), \(\alpha =5\), \(\gamma =7\), \(N_\alpha =10\), and \(N_\gamma =6\). Then, we have

$$\begin{aligned}&I_\alpha =(3,8] \cup (19,24]\cup (49,54]\cup (65,70] \text{ and } \\&I_\gamma =[1,3] \cup [25,27]\cup [47,49]\cup [71,73]. \end{aligned}$$

The for loop runs from 1 to \(a-b=8\) setting the elements in \(\pi \) as follows:

  • \(i=1\): initializes \(x=1\) and, since \(1\in I_\gamma \), it sets \(\pi (1)=7\). Then, \(y=(HV)^3(1)=71\) and, since \(i=1\) is odd \(x=V(71)=1-71=-70\pmod {92}=22\);

  • \(i=2\): since \(22\in I_\alpha \), then \(\pi (2)=5\). Then, \(y=(VH)^2(22)=98\pmod {92}=6\) and, since \(i=2\) is even, \(x=H(6)=55-6=49\);

  • \(i=3\): since \(49\in I_\gamma \), then \(\pi (3)=7\). Then, \(y=(HV)^3(49)=70+49\pmod {92}=27\) and, since \(i=3\) is odd, \(x=V(27)=1-27 \pmod {92}=66\);

  • \(i=\dots \):

The for loop ends providing the vector \(\pi _8=(7,5,7,5,5,7,5,5)\) , and the final output is \(\pi =(\pi _8)_2\).

Remark 28

Let \(C_1\) and \(C_2\) be two hv-convex curls having the same hv-convex sequence \(\pi \). Then, \(C_1\) and \(C_2\) can be merged into one single hv-convex curl whose hv-convex sequence is \((\pi )_2\).

The proof is straightforward. Figure 8 shows an example of the merging process: the curls \(C_1\) and \(C_2\) are placed one next to the other as shown in Fig. 8, (a), and two of their neighbors points belonging to the same switching component (in Fig. 8 the points inside the red circle) exchange one of their coordinates.

We underline that the merging process can be iterated when more than two hv-convex curls are involved. Again the process ends up in one single hv-convex curl.

Example 29

Assume \(a=24\) and \(b=15\), so CompSeq(24, 15) computes \(d=3\), updates ab with 8 and 5, respectively, and exploits CompSeqEntries(8, 5), which outputs \(h=1\), \(\alpha =3\), \(\gamma =5\), \(N_\alpha =2\), and \(N_\gamma =4\). Then, we have

$$\begin{aligned}&I_\alpha =(2,3] \cup (5,6]\cup (15,16]\cup (18,19] \text{ and } \\&I_\gamma =[1,2] \cup [7,8]\cup [14,15]\cup [20,21]. \end{aligned}$$

The for loop runs from 1 to \(a-b=3\) setting the elements in \(\pi \) as follows:

  • \(i=1\): initializes \(x=1\) and, since \(1\in I_\gamma \), it sets \(\pi (1)=5\). Then, \(y=(HV)^2(1)=7\) and, since \(i=1\) is odd \(x=V(7)=1-7=-6\pmod {26}=20\);

  • \(i=2\): since \(20\in I_\gamma \), then \(\pi (2)=5\). Then, \(y=(VH)^2(20)=40 \pmod {26}=14\) and, since \(i=2\) is even, \(x=H(14)=17-14=3\);

  • \(i=3\): since \(3\in I_\alpha \), then \(\pi (3)=3\), \(y=HV(3)=19\) and the for loop stops.

The vector \(\pi _3=(5,5,3)\) is obtained, and, being \(d=3\), the final output is \(\pi =(\pi _3)_6\)

5 Concluding Remarks

In this paper, we have considered hv-convex switching components, namely the switching components under the prior knowledge that the object to be reconstructed is convex along the horizontal and the vertical directions. These are separated in two different geometric classes, windows and curls respectively (see [12, 13]), and can be encoded as special sequences of integer numbers, called hv-sequences. We have provided a detailed investigation of hv-sequences, so obtaining a complete combinatorial description. In case of windows, the related hv-sequences are quite simple, since reduce to a single multiple of 4, that can be easily determined by the geometric structure of the switching component. Differently, for curls, hv-sequences consist of alternating strings of odd entries \(\alpha , \gamma \). The numerical values of \(\alpha \) and \(\gamma \), as well as the lengths of each string occurring in a given hv-sequence, can be exactly computed by exploiting two integer numbers ab, that are related to the geometric structure of the curl (denoted by Curl(ab) for such a reason). A polynomial-time algorithm in ab has been provided, which explicitly reconstructs the hv-sequence related to Curl(ab), and several examples have been shown and discussed in detail.

The knowledge of the combinatorial structure of hv-convex sequences, and consequently the geometric properties of the hv-convex switching components, is of main relevance for the faithful reconstruction of hv-convex polyominoes.

Furthermore, it is well known that small modifications of the projections may lead to dramatic changes in the reconstructed object. The reconstruction process is called stable if a small amount of noise can only lead to small differences in the reconstruction So, it is of primary relevance to understand both the structure and the size of the switching components of a reconstructed object to estimate how far it is from the original one, when noisy projections are provided (the reconstruction process is called stable if a small amount of noise produces small differences in the reconstruction).

We feel that the obtained results provide additional knowledge on the geometric and combinatorial properties of the switching components, which could be exploited and incorporated in the tomographic problem in view of a reduction of the number of allowed solutions. Also, this could reveal of interest when used in combination with the system of clauses involved in the P-time reconstruction process defined in [4], in order to possibly reduce them to a 2-SAT formula.

A final possible challenging problem consists in relating the geometrical and the combinatorial structure of the hv-convex switching components and sequences to the degree of convexity of the associated hv-convex polyominoes, according to the definition in [10]. In particular, it is interesting to investigate the possible co-existence of hv-convex windows and curls in a same hv-convex polyomino, aiming at deriving some limitations on the number and the type of allowed switching components (see also [21]), in view of a solution of the computational complexity problem of the reconstruction of digital convex polyomino from two projections.