1 Introduction

The challenge of building molecular robots has many moving parts, as the saying goes. These include molecular parts that move relative to each other; units needing some sort of memory state; the ability to transition between states; and perhaps even the ability to use computation to drive robotic movements. Here we consider a simple algorithmic model of robotic reconfiguration called Turning Machines.

The main ethos behind our work is the notion of having a reconfigurable structure where component monomers actuate their position relative to their neighbours and governed by simple actuation rules. Volume exclusion applies (two monomers can not occupy the same position in space), almost for free we get massive parallelism and asynchronicity, and the complexity of allowable state changes is small: unit monomers start with a natural number and decrement step-by-step to zero. The Turning Machine model embodies these concepts.

On the one hand, there are a number of senses in which molecular systems are better suited to robotic-style reconfiguration than macro-scale robotic systems: there is no gravity nor friction fighting against components’ actuation, and should we know how to exploit them, randomness, freely diffusing fuel (robots need not carry all their fuel) and large numbers of components are all readily available as resources. On the other hand, building nanoscale components presents a number of challenges including implementing computational controllers at the nanoscale, as well as designing systems that self-assemble and interact in a regime where we can not easily send in human mechanics to diagnose and fix problems (Fig. 1).

Fig. 1
figure 1

Turning Machine motivation: what shapes can be made by autonomously folding structures using simple local turning rules that effect non-local movement? Finding suitable abstract models and characterising their ability helps us to step back and create a vision of where we can go

1.1 Turning machines

Monomers are the atomic components of a Turning Machine and are arranged in a connected chain on the triangular grid \(G_\triangle\), with each monomer along the chain pointing at the next (Fig. 2). In an initial instance, the chain of monomers are sitting on the x-axis all pointing to the east. Each monomer has an initial (input) integer turning number \(s\in {\mathbb {Z}}\), the monomer’s ultimate goal is to set that number to 0: if s is positive, the monomer tries to simultaneously decrement s and turn anti-clockwise by an angle of \(\pi /3\) (Fig. 2b), if s is negative, it tries to increment and turn clockwise by \(\pi /3\).Footnote 1 If \(s=0\) the monomer has reached its target orientation and does not turn again (Fig. 2b).

A key point is that although a monomer actuates by rotating the direction in which it points, when it does so it “drags” (translates) all monomers that come after it in the chain in the same way the rotation motion of a human arm (around a shoulder) appears to translate a flag through the air, or the way a cam in a combustion engine converts rotational shaft motion to translational piston motion (Figs. 2c and 3). Sect. 2 gives the precise model definition.

Fig. 2
figure 2

Turning Machine model. a Triangular grid conventions. A configuration showing a single monomer on the triangular grid \(G_\triangle\), along with axes x, y and w. b Local movement (rotation): A monomer in state 3 pointing to the east undergoes three turning rule applications finishing in state 0 with no more applicable rules. Locally, the monomer effects a rotation motion. c Global movement (translation): Left: Example initial configuration. Middle: A movement rule applied to a monomer in state 3 decrements the state to 2 and translates all subsequent monomers by \(+\vec {w}\). Right: A second state-3 monomer moves. d Blocking: Monomers are not permitted to make movements that would result in a self-intersecting configuration. The monomer \(m_j\) is said to be blocked because if it were to move, then \(m_k\) would move to overlap \(m_i\), but such self-intersections are not permitted

1.1.1 The main challenge: blocking

Programming the model simply requires annotating an east-pointing line of monomers with turning numbers; an incredibly simple programming syntax.

Locally, individual monomers exhibit a small rotation, but globally this effects a large translation, or dragging, of many monomers (Fig. 2c). Thus globally, the main challenge is how to effect global rotations—in other words how to use translation to simulate rotation. In particular, how to do this when lots of monomers are asynchronously moving and bumping into each other, potentially blocking each other from moving.

Blocking is illustrated in Fig. 2d and comes in two forms. Temporary blocking where one monomer is in the way of another, but eventually will get out of the way, and permanent blocking where all monomers block each other in a locked configuration that will never free itself. We say that a target structure is foldable if all possible system trajectories lead to that structure, i.e. permanent blocking does not occur on any trajectory. A foldable structure may exhibit temporary blocking on some trajectories, indeed most of the work for our positive results in this paper comes down to showing that for certain folding tasks, any blockings that happen are merely temporary kinks in the chain that are eventually worked out. We measure the amount of blocking by considering the completion time: a foldable structure where temporarily blocked monomers can quickly become unblocked finishes faster than one where blocking takes a while to sort out. Our model of time assumes that the time to apply a turning rule to a given unblocked monomer is an exponential random variable with rate 1, and the system evolves as a continuous time Markov chain with the discrete events being rules applied asynchronously and in parallel.

Given a shape and a best-guess at an initial (input) state sequence to fold that shape, the main challenge often lies in showing that all trajectories lead to the desired shape, i.e. that permanent blocking never occurs. If we succeed in this, a second challenge is to analyse the time to completion—with speed of completion being a measure of efficiency and parallelism.

1.2 Results: line rotations and shape building

After defining the Turning Machines model (Sect. 2), and giving technical lemmas for reasoning about it (Sect. 4), in Sect. 5 we fully characterise the line rotation capabilities of the model, in two senses. First, we show that for each of the angles \(\theta \in \{ \pi /3, 2\pi /3, \pi , 4\pi /3, 5\pi /3 \}\), and any number of monomers \(n\in {\mathbb {N}}\) there is a Turning Machine with n monomers that starts on the x-axis and ends rotated by \(\theta\) radians. We show this is the best one can do, that is, that rotation of \(\theta \ge 2\pi\) is impossible (for any \(n>7\), there are always some trajectories that are permanently blocked). Second, line rotation is fast: Up to constant factors the speed is optimal, completing in expected time \(O(\log n)\). This shows that despite the fact that line rotations in the range \(\pi \le \theta \le 5\pi /3\) experience large number of blockings along their trajectories, these blockings are all temporary, and do not conspire to slow the system down by more than a constant factor on average.

In Sect. 6, we go on to give results on the shape-building abilities of Turning Machines. To do this, we build on previous technical tools to show that so-called zig-zag paths (paths that wind over and back parallel to the x axis) are foldable, and in merely logarithmic expected time (Theorem 21). We use that result to prove that \(n \times n\) squares, rastered in a zig-zag fashion, are foldable, and time-efficiently so (Corollary 22). By allowing error in the folding of a shape (the error is the symmetric difference between the set of points of the shape and points in the folding), any shape is trivially foldable, albeit with error up to the area of the shape, by simply folding the entire bounding box of the shape.Footnote 2 This means that there are shapes, that are not Hamiltonian but are foldable with large error (e.g. a cross with thin arms, Fig. 9 and Theorem 25). What shapes can be folded with small error? We show that any shape from a wide class called y-monotone shapes is foldable in optimalFootnote 3 expected time \(O(\log n)\), and with error no more than the perimeter of the shape and no more than the perimeter of the folding (Theorem 24). Certain classes of shapes can be folded with zero error: Theorem 33 shows that there are shapes, that we call, y-monotone with a yw-separator, that are are foldable at scale factor 2. Finally, one can ask if every shape that has a Hamiltonian path is foldable. The answer is no: our main negative result (Theorem 38) gives a classes of shapes (thin spirals with a gap between their arms) and proves that they are not foldable.

We would argue that programming in this model is deceptively simple: if a shape has a Hamiltonian path, it is typically straightforward to trace that path while assigning turning numbers to an initial configuration such that there is some trajectory that folds the shape. However, making the step forward to then show that all trajectories fold that shape may involve significant and subtle argumentation, or may be impossible. Programming in the model seems simple, the analysis may not be. This has the benefit of pulling hardness away from the molecular robot design and implementation problem (which is a rather challenging experimental problem) and instead pushing it towards a theoretical geometric analysis problem, exactly where we’d prefer it to be.

1.3 Related and future work

Besides finding insights at the interface of computation and geometry, another ultimate aim of this kind of work is to bridge the gap between what we can imagine in theory and what we can engineer in the lab (Ramezani and Dietz 2019). Biological systems actuated at the molecular scale provide inspiration: in the gastrulation phase of embryonic development of the model organism Drosophila melanogaster, large-scale rearrangements of the embryo are effected by thousands of (nanoscale) molecular motors working together to rapidly push and pull the embryo into a target shape (Dawes-Hoang et al. 2005; Martin et al. 2008).

Our Turning Machine model is a restriction of the nubot model (Woods et al. 2013), a molecular robotic model with many features including self-assembly capabilities, random agitation (jiggling) of monomers, the ability to execute cellular automata style rules, and floppy/rigid molecular bonds. The parallel computing capabilities (Chen et al. 2014b), and construction using random agitation and self-assembly (Chen et al. 2014a) have been studied. Dabby and Chen consider related (experimental and theoretical) systems that use an insertion primitive to quickly grow long (possibly floppy) linear structures (Dabby and Chen 2012), later tightly characterised by Hescott et al. (2017); Hescott et al. (2018) in terms of number of monomer types and time. Hou and Chen (2019) show that the nubot model can display exponential growth without needing to exploit state changes. Chin et al. (2018) look at both minimising numbers of state changes and number of ‘2D layers’ to assembly 1D structures. There are a number related autonomous self-folding models, both 1D to 2D (Cheung et al. 2011) and 2D to 3D (Connelly et al. 2010), and reconfigurable robotic/programmable matter systems, e.g. (Aloupis et al. 2009, 2008; Demaine et al. 2018; Geary et al. 2016; Gmyr et al. 2019; Michail et al. 2019).

There are several avenues for future work.

  • Concretely, it remains to fully characterise the classes of shapes foldable with zero error (Open Problem 26). For example, can our main negative result showing the impossibility of folding spirals be generalised to give impossibility result for wider classes of shapes? Can we find new techniques to increase the class of shapes that are foldable (with zero error), beyond the zig-zag rastering techniques we heavily use in Sects. 6.16.3 (to fold \(n \times n\) squares, and certain other y-monotone shapes including those with a yw-separator at scale factor 2).

  • Establishing error bounds for various classes of shapes, including trade-offs between notions of shape complexity and error could be another avenue to explore. It seems interesting to consider folding where we permit a small number of trajectories to be permanently blocked.

  • In this paper, our positive results are mainly for model instances with either positive integer states, which define an anti-clockwise rotation-and-translation motion about the origin, or with negative integer states which define a clockwise motion; our negative results hold for both directions. Does the combination of both anti-clockwise (positive) and clockwise (negative) turning rules strictly increase the expressivity of the model?

  • Using a variant (Woods et al. 2013; Chen et al. 2014a) of the model with random agitation of monomers would side-step our negative result about the impossibility of reaching a full \(2\pi\) line rotation, essentially by allowing reversible movement out of blocked configurations (although upon reaching the target configuration, the Turing machine would also immediately reverse out it). We don’t know if adding agitation to the model can help increase the set of foldable shapes, however since it is a somewhat natural physical notion it is worth investigating—either with or without the notion of locking into position when a monomer has completed all of its movements by reaching state 0. Indeed, the analysis of such systems would provide intellectual fruit by mixing probability, geometry and computation.

  • As indicated in Fig. 1, it is straightforward to generalise the model to (say) 2D trees folding into 3D shapes.

  • We know that certain kinds of zig-zag paths (e.g. over-and-back parallel to x-axis, while moving monotonically either positive or negative along the y axis, see for example Fig. 8) are efficiently foldable, and under certain conditions mixing of two kinds of of zig-zag paths are foldable (e.g. prooxf of Theorem 33 and Fig. 10).

In all of these cases fully characterising the classes of shapes that can be folded, and characterising the time to fold such classes of structures, provides questions whose answers would expand our understanding of the capabilities of simple reconfigurable robotic systems.

2 Turning machine model definition

In this section we define the Turning Machine model. Formally speaking, the model is a restriction of the Nubot model (Woods et al. 2013), for simplicity we instead use a custom formalism.

Grid. Positions are pairs in \({\mathbb {Z}}^2\) defined on a two-dimensional (2D) triangular grid \(G_\triangle\) using x and y axes as shown in Fig. 2. We use the notation \({\mathbb {N}}^2\) to denote points in the positive orthant, or positive sextant, of the 2D triangular grid. For convenience, we define a third axis, w, centred on the origin and running through the point \((x,y) = (-1,1)\). We let \(\pm \vec {x}, \pm \vec {y}, \pm \vec {w}\) denote the unit vectors along the x, y and w axes.

Monomer, configuration, trajectory. A monomer is a pair \(m = (s(m), \mathrm{pos}(m)\)) where \(s(m) \in {\mathbb {Z}}\) is a state and \(\mathrm{pos}(m_i) \in {\mathbb {Z}}^2\) is a position. A configuration, of length \(n\in {\mathbb {N}}\), is a tuple of monomers \(c = ( m_0, m_1, \ldots , m_{n-1})\) whose positions \(\sigma (c) = \mathrm{pos}(m_0), \mathrm{pos}(m_1), \ldots ,\) \(\mathrm{pos}(m_{n-1})\) define a length \(n-1\) simple directed path (or non-self-intersecting chain) in \({\mathbb {Z}}^2\) (on the grid \(G_\triangle\)) and where \(\mathrm{pos}(m_0) = (0,0)\).Footnote 4

A configuration is a tuple of \(n \in {\mathbb {N}}\) monomers \((m_0,m_1,\ldots , m_{n-1})\). A final configuration has all monomers in state 0. A pair of configurations \((c_i, c_{i+1})\) is said to be a step if \(c_i\) yields \(c_{i+1}\) via a single rule application (defined below) which we write as \(c_i\rightarrow c_{i+1}\). A trajectory, of length k, is a sequence of configurations \(c_0, c_1,\ldots ,c_{k-1}\) where, for each \(i\in \{0,1,\ldots ,k-2\}\) the pair \((c_i, c_{i+1})\) is a step \(c_i \rightarrow c_{i+1}\). A Turning Machine initial configuration \(c_0\) is said to compute the target configuration \(c_t\) if all trajectories that start at \(c_0\) lead to \(c_t\), and is said to compute its target configuration if it reaches the configuration with all monomers in state 0. A Turning Machine instance is an initial configuration. For a monomer \(m_i\), we let \(s_0(m_i)\) denote its state in the initial configuration, and we let \(\ell _i\) denote the horizontal line through \(\mathrm{pos}(m_i)\). Given a monomer \(m_i\) in configuration c we say that for \(0\le i \le n-2\) monomer \(m_i\) points in direction \(\vec d \in \{\pm \vec {x}, \pm \vec {y}, \pm \vec {w}\}\) if \(\mathrm{pos}(m_{i+1}) - \mathrm{pos}(m_i) = \vec d\). By convention, monomer \(m_{n-1}\) does not point in any direction, and whenever we say all monomers point in some direction \(\vec d\), we mean all except \(m_{n-1}\). A configuration \(c'\) is reachable from configuration c if there is at least one sequence of rule applications from c to \(c'\) (if c is not specified we mean the initial configuration \(c_0\)).

Turning rule: state decrement/increment. Let \(S_{\mathrm{init}} \subsetneq \mathrm{Z}\) be the set of states that appear in the initial configuration. Let \(s_{\min } = \min ({ S_{\mathrm{init}} \cup \{ 0 \} })\) and \(s_{\max } = \max ({ S_{\mathrm{init}} \cup \{ 0 \} })\), and let \(S = \{s_{\min }, s_{\min }+1,\ldots , s_{\max } \}\) be the called the Turning Machine state set. The turning rules of a Turning Machine are defined by a function r such that for all states \(s \in ( S \setminus \{ 0 \} )\):

$$\begin{aligned} r(s) = {\left\{ \begin{array}{ll} s -1 \quad \text { if } s >0\,,\\ s +1 \quad \text { if } s < 0\,. \end{array}\right. } \end{aligned}$$
(1)

Let \({\mathcal {C}}\) be the set of all configurations. The turning rule \(R : {\mathcal {C}} \times {\mathbb {Z}} \rightarrow {\mathcal {C}}\) is a function and R(ci) is said to be applicable to monomer \(m_i\) in configuration c if \(s(m_i) \ne 0\) and the rule is not blocked (defined below). If the rule is applicable, we write \(R(c,i) = c'\) and say that R(ci) yields the new configuration \(c'\), and we say that \((c,c')\) is a step.

Turning rule: blocking. For \(i \in \{0,1,\ldots ,n-1 \}\), we define the head and tail of monomer \(m_i\) as \(\mathrm{head}(m_i) = m_{i+1},m_{i+2},\ldots ,m_{n-1}\) and \(\mathrm{tail}(m_i) = m_{0},m_{1},\ldots ,m_{i}\). Consider the following tuple of unit vectors: \(\vec d = ( \vec {x}, \vec {y}, \vec {w}, -\vec {x}, -\vec {y}, -\vec {w})\), and let \(\vec d_k\) denote the kth element of that tuple. Let \(\vec d_i = \mathrm{pos}(m_{i+1})-\mathrm{pos}(m_i)\) be the direction of monomer \(m_i\), and then if \(s(m_i)>0\) let \(i' \equiv (i+2)~\mathrm{mod}~6\), or if \(s(m_i)<0\) let \(i' \equiv(i - 2) ~\mathrm{mod}~6\). For a vector \(\vec d\in {\mathbb {Z}}^2\) we write \(m_i + \vec d\) to mean the monomer \(m_i\) translated by \(\vec d\). DefineFootnote 5\(\mathrm{head}^{\rightarrow }\!(m_i) = m_{i+1} + \vec d_{\!i'},\, m_{i+2}+ \vec d_{\!i'},\, \ldots , m_{n-1} + \vec d_{\!i'}.\)If the set of positions of \(\mathrm{tail}(m_i)\) has a non-empty intersection with the set of positions of \(\mathrm{head}^{\rightarrow }\!(m_i)\) we say that the rule is blocked, and the rule is not applicable. If the rule is not blocked, it is applicable and the resulting next configuration is \(c' = \mathrm{tail}(m_i)\), \(\mathrm{head}^{\rightarrow }\!(m_{i}) = m_{0},m_{1},\ldots ,m_{i}, m_{i+1} + \vec d_{i'}, m_{i+2}+ \vec d_{i'}, \ldots , m_{n-1} + \vec d_{i'}.\)

A configuration c is said to be permanently blocked if (a) not all states are 0, and (b) none of the monomers in c has an applicable rule. A monomer m within a configuration c is said to be temporarily blocked if (a) m is not in state 0, and (b) there is no rule applicable to m, and (c) there is a trajectory starting at c that reaches a configuration \(c'\) where there is a rule applicable to m.

Time. A Turning Machine evolves as a continuous time Markov process. The rate for each rule application is 1. If there are k applicable transitions for a configuration \(c_i\) (i.e. k is the sum of the number of rule applications that can be applied to all monomers in \(c_i\)), then the probability of any given transition being applied is 1/k, and the time until the next transition is applied is an exponential random variable with rate k (i.e. the expected time is 1/k). The probability of a trajectory is then the product of the probabilities of each of the transitions along the trajectory, and the expected time of a trajectory is the sum of the expected times of each transition in the trajectory. Thus, \(\sum _{t \in {\mathcal {T}}} \mathrm{Pr}[t] \cdot \mathrm{time}(t)\) is the expected time for the system to evolve from configuration \(c_i\) to configuration \(c_j\), where \({\mathcal {T}}\) is the set of all trajectories from \(c_i\) to \(c_j\), and \(\mathrm{time}(t)\) is the expected time for trajectory t.

Example. These concepts are illustrated in the proof of Lemma 4 in Appendix A, and in the example in Fig. 3.

Fig. 3
figure 3

Left: The Turning Machine \(L_{n}^{1}\) that rotates a line of \(n=11\) monomers by \(\pi /3\); illustration for Lemma 4. Four configurations are shown. The initial configuration has all monomers in state 1 sitting on the x-axis, in the final configuration all are in state 0 and sitting on the \(\pi /3\) line. Two intermediate configurations are shown, respectively after 2, and then after 5, turning rules applications. Right: A configuration of the Line rotation Turning Machine \(L^1_{11}\) with the chain running from bottom left to top right. Lemmas 4 and 5 uses the fact that \(\mathrm{tail}(m_i)\) sits on or below \(\ell _i\), \(\mathrm{head}(m_i)\) sits on or above \(\ell _i\), and \(\mathrm{head}^{\rightarrow }\!(m_i)\) sits strictly above \(\ell _i\)

3 Introduction to line rotation turning machines

Every Turning Machine analysed in this paper starts with \(n\in {\mathbb {N}}\) monomers, sitting on the x-axis, pointing to the east. We define a class of Turning Machines which we call line rotation Turning Machines.

Definition 1

(Line rotation Turning Machine) Let \(n\in {\mathbb {N}}\) and let \(L_{n}^{\sigma }\) be the Turning Machine with initial configuration of n monomers \(c_0 = m_0, m_1,\ldots , m_{n-1}\) all pointing to the east, positioned on the x-axis (\(\mathrm{pos}(m_i) = (i,0) \in {\mathbb {Z}}^2\)), and for \(0\le i\le n-2\) all monomers in the same state \(s_0(m_i) = \sigma \in {\mathbb {N}}^+\) and \(s_0(m_{n-1}) = 0\).

Remark 2

The initial monomer state \(\sigma \ge 0\) dictates that each monomer wishes to turn (have a rule applied) a total \(\sigma\) times, i.e. be rotated through an angle of \(\sigma \pi /3\).

Remark 3

(Target configuration) For intuition, if there was no notion of blocking in the Turning Machine model, that is, if the model permitted self-intersecting configurations (which it does not), then the final configuration c of the Turning Machine in Definition 1 is a straight line of monomers sitting along the ray that starts at the origin and is at an angle of \(\sigma \frac{\pi }{3}\), i.e. at positions \((0,0),(0,-1),\ldots ,(0,- (n-1) )\) and all pointing to the west. We call c the desired target configuration of the line rotation Turning Machine \(L_{n}^{\sigma }\). Also, if there was no notion of blocking: expected time to completion would be fast, \(O(\log n)\) (by a generalisation of the analysis used in the proof of Lemma 4). However, a model with no blocking would be rather uninteresting.

Figure 3 (left) illustrates Lemma 4 and Appendix A contains its straightforward, yet instructive, proof.

Lemma 4

For each \(n\in {\mathbb {N}}\), the line-rotating Turning Machine \(L_{n}^{1}\) computes its target configuration, and does so in expected \(O(\log n)\) time.

Fig. 4
figure 4

Illustration of turn angle (Definition 6). The turn angles \(\alpha _i\) and \(\alpha _{i+1}\) are positive (and to the left), and \(\alpha _j\) is negative (and to the right)

4 Tools for reasoning about turning machines

The following lemma is illustrated in Fig. 3 (right).

Lemma 5

Let \(n\in {\mathbb {N}}\) and let \(T^{\le 3}_{n}\) be a Turning Machine with initial states \(0\le s(m_i)\le 3\) for all \(0\le i\le n-1\). For any monomer \(m_i\) in a reachable configuration c of \(T^{\le 3}_{n}\), the monomers \(\mathrm{head}(m_i)\) are positioned on or above \(\ell _i\), and \(\mathrm{tail}(m_i)\) are positioned on or below \(\ell _i\), where \(\ell _i\) is a horizontal line passing through \(m_i\).

Proof

The claim follows from the fact that in any configuration of \(L_{n}^{\le 3}\), and for any \(j\in \{0,1,\ldots ,n-2\}\) the angle of the vector \(\overrightarrow{ \mathrm{pos}(m_j) \mathrm{pos}(m_{j+1}) }\) (from monomer \(m_j\) to \(m_{i+1}\)) is either \(0^\circ\), \(60^\circ\), \(120^\circ\), or \(180^\circ\) (and, in particular, is not strictly between \(180^\circ\) and \(360^\circ\)). \(\square\)

The notion of turn angle of a monomer is crucial to our analysis and is illustrated in Fig. 4.

Definition 6

(Turn angle) Let c be the configuration of an n-monomer Turning Machine and let \(0\le i < n-1\). The turn angle \(\alpha _i\) at monomer \(m_i\) is the angle between \(\overrightarrow{\mathrm{pos}(m_{i-1}) \mathrm{pos}(m_i)}\) and \(\overrightarrow{\mathrm{pos}(m_{i}) \mathrm{pos}(m_{i+1})}\), and it is the positive counterclockwise angle if the points \(\mathrm{pos}(m_{i-1}), \mathrm{pos}(m_i), \mathrm{pos}(m_{i+1})\) make a left turn,Footnote 6 and the negative clockwise angle otherwise.

For a monomer \(m_i\), the following definition gives a measure, \(\varDelta s(m_i)\), of how its state \(s(m_i)\) has progressed since the initial configuration.

Definition 7

Let c be a reachable configuration of an n-monomer Turning Machine, let \(m_i\) be a monomer with state \(s(m_i)\) in c and initial state \(s_0(m_i) \ge 0\). We define \(\varDelta s(m_i)\) to be the number of rule applications to (or, moves of) the monomer \(m_i\) from the initial configuration to c. That is, \(\varDelta s(m_i) = s_0(m_i) - s(m_i)\).

Lemma 8

(Difference of State is \(\le 2\)) Let \(n\in {\mathbb {N}}\), and let c be any reachable configuration of an n-monomer Turning Machine \(T_n\) with all monomers pointing in the same direction in its initial configuration, then

$$\begin{aligned} |\varDelta s(m_i) - \varDelta s(m_{i+1})| \le 2\,, \end{aligned}$$

for all \(0\le i<n-1\).

Proof

Let \(m_k^t\), for \(t\in {\mathbb {N}}\) and \(k \in \{0,1,\ldots ,n-1\}\), denote the \(k{\mathrm{th}}\) monomer in the \(t{\mathrm{th}}\) configuration \(c_t\). Initially, \(\varDelta s(m^0_j)=0\) for all monomers \(m_j\), and thus \({|\varDelta s(m^0_i) - \varDelta s(m^0_{i+1})|=0}\).

Observe, that \(|\varDelta s(m_i) - \varDelta s(m_{i+1})| \ne 3\) because otherwise \(\mathrm{pos}(m_i) = \mathrm{pos}(m_{i+2})\) making c a self-intersecting (non-simple) configuration, contradicting its definition.

By Eq. (1), when a rule is applied to one of \(m_i^t\) or \(m_{i+1}^t\) the absolute value of its state decreases by 1 and its \(\varDelta s(\cdot )\) increases by 1. Then \(|\varDelta s(m^t_i) - \varDelta s(m^t_{i+1})| = |\varDelta s(m^{t-1}_i) - \varDelta s(m^{t-1}_{i+1})| \pm 1\). When a rule is applied to some other monomer \(m_k\) with \(i\ne k\ne j\), then \(|\varDelta s(m^t_i) - \varDelta s(m^t_{i+1})| = |\varDelta s(m^{t-1}_i) - \varDelta s(m^{t-1}_{i+1})| \pm 0\). Thus, after each rule application the value of \(|\varDelta s(m_i) - \varDelta s(m_{i+1})|\) changes by at most 1, and as it cannot be equal to 3, we have that \(|\varDelta s(m_i) - \varDelta s(m_{i+1})|\le 2\). \(\square\)

We can now prove the following lemma, which gives a relation between the states of any two monomers of a Turning Machine and the geometry of the current configuration.

Lemma 9

Let c be any reachable configuration of an n-monomer Turning Machine \(T_n\), whose initial configuration \(c_0\) has all monomers pointing in the same direction, and let \(m_i\) and \(m_j\) be two monomers of c such that \(i<j<n-1\), then

$$\begin{aligned} \varDelta s(m_j)-\varDelta s(m_i) =\frac{3}{\pi }\sum _{k=i+1}^{j}\alpha _k\,, \end{aligned}$$

where \(\alpha _k\) is the turn angle at monomer \(m_k\).

Proof

For any intermediate configuration, the turn angle \(\alpha _{i+1}\) between monomers \(m_i\) and \(m_{i+1}\) depends only on the number of moves each monomer has made. Initially, \(\alpha _{i+1}=0\). It increases by \(\pi /3\) each time monomer \(m_i\) moves anti-clockwise or monomer \(m_{i+1}\) moves clockwise, and it decreases by \(\pi /3\) every time monomer \(m_i\) moves clockwise or monomer \(m_{i+1}\) moves anti-clockwise. By Lemma 8, for two consecutive monomers \(m_i\) and \(m_{i+1}\), in any configuration, \(|\varDelta s(m_i) - \varDelta s(m_{i+1})|\le 2\). Hence, for a pair of consecutive monomers \(m_i\) and \(m_{i+1}\), the turn angle \(\alpha _{i+1}\) is in the range \([-2\frac{\pi }{3}, 2\frac{\pi }{3}]\), and thus \(\alpha _{i+1}=\frac{\pi }{3}(\varDelta s(m_{i+1}) - \varDelta s(m_{i}))\). Summing over all i gives the lemma conclusion. \(\square\)

The following technical lemma is used extensively for our main results. Intuitively, it tells us that high-state monomers are not blocked.

Lemma 10

Let \(T^{\le 5}_{n}\) be a Turning Machine with initial state values \(0\le s(m_i)\le 5\) for all \(0 \le i < n\). In any reachable configuration c of \(T^{\le 5}_{n}\) no monomer \(m_i\) with \(\varDelta s(m_i) \le 1\) is blocked (neither temporarily blocked nor permanently blocked).

Proof

Suppose, for the sake of contradiction, there is a blocked monomer \(m_i\) with \(\varDelta s(m_i) \le ~1\). Then there exist two monomers \(m_j\in \mathrm{head}(m_i)\) and \(m_k \in \mathrm{tail}(m_i)\) such that \(\mathrm{pos}(m_k)=\mathrm{pos}'(m_j)\), where \(\mathrm{pos}'(m_j)\) is the position of \(m_j\) in \(\mathrm{head}^{\rightarrow }\!(m_i)\) (see Fig. 5).

By definition of head and tail we know that \(k\le i < j\). Consider the closed chain \(P=\mathrm{pos}(m_k),\mathrm{pos}(m_{k+1}),\ldots ,\mathrm{pos}(m_{j-1}),\mathrm{pos}(m_{j}),\mathrm{pos}(m_k)\). Since configurations are simple, P defines a simple polygon. The turn angles of a simple polygon sum to \(2\pi\) if the polygon is traversed anticlockwise (interior of P is on the left-hand side while traversing), or \(-2\pi\) if the polygon is traversed clockwise (interior of P is on the right-hand side). For P, this sum is defined as:

$$\begin{aligned} \alpha _P = \sum _{\ell =k+1}^{j-1}\alpha _{\ell } + \beta _j + \beta _k = \pm 2\pi \,, \end{aligned}$$

where \(\alpha _\ell\) is the turn angle at monomer \(m_\ell\), and \(\beta _j\) and \(\beta _k\) are the turn angles of the polygon at vertices \(\mathrm{pos}(m_j)\) and \(\mathrm{pos}(m_k)\) respectively (see Fig. 5). More precisely,

$$\begin{aligned} \begin{aligned} \alpha _\ell&= \angle (\overrightarrow{\mathrm{pos}(m_\ell )}-\overrightarrow{\mathrm{pos}(m_{\ell -1})},\overrightarrow{\mathrm{pos}(m_{\ell +1})}-\overrightarrow{\mathrm{pos}(m_\ell )})\,,\\ \beta _j&=\angle (\overrightarrow{\mathrm{pos}(m_j)}-\overrightarrow{\mathrm{pos}(m_{j-1})},\overrightarrow{\mathrm{pos}(m_k)}-\overrightarrow{\mathrm{pos}(m_j)})\,, \text { and}\\ \beta _k&=\angle (\overrightarrow{\mathrm{pos}(m_k)}-\overrightarrow{\mathrm{pos}(m_j)},\overrightarrow{\mathrm{pos}(m_{k+1})}-\overrightarrow{\mathrm{pos}(m_k)})\,. \end{aligned} \end{aligned}$$

Furthermore, by Lemma 9,

$$\begin{aligned} \varDelta s(m_{j-1})-\varDelta s(m_k) = \frac{3}{\pi }\sum _{\ell =k+1}^{j-1}\alpha _{\ell }\,. \end{aligned}$$

Thus,

$$\begin{aligned} \begin{aligned} \varDelta s(m_{j-1})&= \varDelta s(m_k) + \frac{3}{\pi }\sum _{\ell =k+1}^{j-1}\alpha _{\ell } = \varDelta s(m_k) + \frac{3}{\pi }(\pm 2\pi -\beta _j - \beta _k)\\&= \varDelta s(m_k) \pm 6 - \frac{3}{\pi }(\beta _j + \beta _k) \,. \end{aligned} \end{aligned}$$

Observe that when a monomer \(m_i\) moves, its head translates in the direction corresponding to the current direction of \(m_i\) rotated by angle \(2\pi /3\). Therefore, the state of \(m_k\) can be represented as a function of the state of \(m_i\) and the angle \(\beta _k\), more precisely

$$\begin{aligned} \varDelta s(m_k) = \varDelta s(m_i) + 2 + \frac{3}{\pi }\beta _k \,. \end{aligned}$$

(See Fig. 5 for an example.) Therefore, by the previous two equalities

$$\begin{aligned} \varDelta s(m_{j-1}) = \varDelta s(m_i) + 2 \pm 6 - \frac{3}{\pi }\beta _j \,. \end{aligned}$$

Recall, that the angle \(\beta _j \in [-2\pi /3,2\pi /3]\), that \(0 \le \varDelta s(m_i) \le 1\) by the assumption of the lemma, and that \(\varDelta s(m_{j-1}) \le s\). If the polygon defined by P is traversed anti-clockwise, then

$$\begin{aligned} \varDelta s(m_{j-1}) = \varDelta s(m_i) + 8 - \frac{3}{\pi }\beta _j \ge 0 + 8 - 2 = 6\,, \end{aligned}$$

which implies that \(s(m_{j-1})\) is out of the range of valid states, as \(m_{j-1}\) must have moved more times as its initial state. Else, if the polygon P is traversed clockwise, then

$$\begin{aligned} \varDelta s(m_{j-1}) = \varDelta s(m_i) - 4 - \frac{3}{\pi }\beta _j \le 1 - 4 + 2 = - 1\,, \end{aligned}$$

which again implies that \(s(m_{j-1})\) is out of the range of valid states, as \(m_{j-1}\) must have moved in the wrong direction. In either case we contradict that the state \(s(m_{j-1})\) is in the range of valid states, and, therefore, the monomer \(m_i\) is not blocked. \(\square\)

Fig. 5
figure 5

Illustration for Lemma 10. Monomer \(m_i\) is shown in black, \(\mathrm{head}(m_i)\) is shown in blue and \(\mathrm{tail}(m_i)\) is shown as the green curve plus the black monomer \(m_i\). Left: monomer \(m_i\) is in its initial state (\(\varDelta s(m_i)=0\)), and polygon P is traversed anti-clockwise. Right: monomer \(m_i\) has moved once (\(\varDelta s(m_i)=1\)), and polygon P is traversed clockwise

Lemma 11

Let \(L_{n}^{s}\) be a line-rotating Turning Machine with \(s\le 5\). Let c be a reachable configuration of \(L_{n}^{s}\) where each monomer \(m_i\) in c has \(s_c(m_i) < s\). Then the line-rotating Turning Machine \(L_{n}^{s-1}\) has a reachable configuration \(c'\) such that for every \(m_i\), \(s_{c'}(m_i)=s_{c}(m_i)\) and the geometry (chain of positions) of c is equal to that of the rotation of \(c'\) by \(\pi /3\) around the origin.

Proof

Consider the sequence \(\rho _c\) rule applications (moves) that brings the initial configuration of \(L_{n}^{s}\) to configuration c. We claim that \(\rho _c\) can be converted into another sequence \(\rho _{c'}\), of the same length, in which the first \(n-1\) moves are by monomers in state s.

First, we claim: for any two consecutive moves, where the second move is applied to a monomer in state s, swapping the two moves results in a valid sequence of moves transforming the Turning Machine into the same configuration. Let the first move be applied to monomer \(m_i\) which transitions from state \(s'\) to \(s'-1\), and the second move be applied to monomer \(m_j\) which transitions from state s to \(s-1\). Suppose for the sake of contradiction that swapping the moves results in at least one of the monomers \(m_i\) or \(m_j\) being blocked. We begin by attempting to apply the move to monomer \(m_j\), but, by Lemma 10, that move is not blocked. Then we attempt to apply a move to monomer \(m_i\), but that is not blocked either since the coordinates of all monomers before and after swapping the two moves are exactly the same; i.e. the resulting configuration is a valid (non-self-intersecting) configuration in both cases. Hence neither monomer is blocked.

Thus, the original sequence of moves resulting in configuration c, can be converted into another sequence where the first \(n-1\) moves are applied to monomers in state s. Then, after the first \(n-1\) moves the configuration of \(L_{n}^{s}\) is equivalent to the initial configuration of \(L_{n}^{s}\) but rotated by \(\pi /3\) and with all monomers in state \(s-1\). Hence equivalent to the initial configuration of \(L_{n}^{s-1}\) rotated by \(\pi /3\).

Applying the remaining moves to \(L_{n}^{s-1}\) transforms it into configuration \(c'\). \(\square\)

5 Line rotation: \(5\pi /3\) possible and fast, \(2\pi\) impossible

5.1 Line rotation to \(5\pi /3\)

In this section we show that for \(1\le s \le 5\) the line-rotation Turning Machine \(L_{n}^{s}\) computes its target configuration of a \(s\pi /3\) rotated line (Theorem 12), and does so in expected time \(O(\log n)\) (Theorem 13). In addition to those results for any state \(s \le 5\), in Appendix A we include stand-alone proofs for each of \(s=1\), \(s=3\), and \(s=4\) which showcase a variety of geometric techniques for analysing Turning Machine movement, but are not needed to prove our main results. Also, the cases of \(s=1\) and \(s=3\) are illustrated in Figs. 3 and 6 .

Fig. 6
figure 6

Example trajectory of the Turning Machine \(L_{n}^{3}\) that rotates a line of east-pointing monomers by an angle of \(\pi\). Illustration for Theorem 13 with \(s=3\) (and for Lemma 40 and Theorem 41 in Appendix A). Seven configurations are shown, the initial configuration has all monomers in state 3 (blue), final in state 0 (yellow). Darker shading indicates later in time. A red bond (edge) indicates a blocked monomer. The proof of Lemma 40 shows that only monomers in state 1 are ever blocked and only when they are adjacent to a monomer in state 3, and that all such blockings are temporary—if we wait long enough they become unblocked

Theorem 12

For each \(n\in {\mathbb {N}}\) and \(1 \le s\le 5\), the line-rotation Turning Machine \(L_{n}^{s}\) computes its target configuration.

Proof

We prove by induction on \(1\le s \le 5\) that any reachable configuration c of \(L_{n}^{s}\) is not permanently blocked.

Base case \(s=1\). In any configuration reachable by \(L_{n}^{1}\), monomers have either state \(s=1\) or 0. Monomers in state \(s=1\) cannot be permanently blocked by Lemma 10. Thus, any non-final configuration is not permanently blocked.

Assume for \(s-1\) the claim is true, i.e. it holds for \(L_{n}^{s-1}\). We will prove that for s it is also true, i.e. it holds for \(L_{n}^{s}\). Suppose, for the sake of contradiction, there is a permanently blocked configuration c of \(L_{n}^{s}\) for some \(n\in {\mathbb {N}}\) and \(s \le 5\). If there is no monomer in c in state s, then by Lemma 11 there exists a corresponding configuration \(c'\) in \(L_{n}^{s-1}\) with monomers \(m'_0,m'_1,\ldots ,m'_{n-1}\), such that, for any monomer \(m_i\) in c with state \(s_i < s\) the corresponding monomer \(m'_i\) in \(c'\) has the same state \(s_i\). Configurations c and \(c'\) form chains equal up to rotation by angle \(\pi /3\). Configuration \(c'\) is not blocked by the induction hypothesis, thus configuration c cannot be blocked either.

On the other hand, if there is a monomer \(m_i\) in configuration c in state s, then by Lemma 10 it is unblocked, and configuration c, again, is not blocked.

Hence the induction hypothesis holds for s, and \(L_{n}^{s}\) does not have a reachable permanently blocked configuration. \(\square\)

Theorem 13

For each \(n\in {\mathbb {N}}\) and \(1 \le s\le 5\), the line-rotation Turning Machine \(L_{n}^{s}\) computes its target configuration in expected time \(O(\log n)\).

Proof

By Theorem 12, \(L_{n}^{s}\) computes its target configuration. For the time analysis we use a proof by induction on \(u \in \{ 0,1,\ldots , s\}\), in decreasing order.

The induction hypothesis is that for a reachable configuration \(c_u\) of \(L_{n}^{s}\) with maximum state value u (there may be states \(< u\) in the configuration), the expected time to reach a configuration \(c_{u-1}\) with maximum state \(u-1\) is \(O(\log n)\).

For the base case we let \(u=s\) and assume c is such that all monomers are in state u. Hence c is an initial configuration and hence, by definition, is reachable. By Lemma 10, monomers in state s are never blocked and hence we claim that the first configuration with maximum state \(u-1\) appears after expected time \(O(\log n)\). To see this claim, note that for each monomer \(m_i\) in state \(s(m_i)=u\) the rule application that sends \(m_i\) to state \(u-1\) occurs at rate 1, independently of the states and positions of the other monomers (by Lemma 10, there is no blocking of a monomer in state \(u=s\)). Since there are n monomers in state u, the expected time for all n to transition to \(u-1\) is Graham et al. (1989):

$$\begin{aligned} \sum _{k=1}^{n} \frac{1}{k} = O(\log n) \, . \end{aligned}$$
(2)

We assume the inductive hypothesis is true for \(0< u+1 \le s\), and we will prove it holds for u. Thus, there exists a reachable configuration \(c_u\) where the maximum state value is \(u \le s\), which is reachable from \(c_{u+1}\) in expected \(O(\log n)\) time. Let there be \(n' \le n\) monomers in state u in \(c_u\). By Lemma 11, there is a line-rotating Turning Machine \(L_{n}^{u}\) that has a reachable configuration \(c'_u\) such that for every \(m_i\) in \(c_u\), \(s_{c'_u}(m_i)=s_{c_u}(m_i)\) and the positioning of \(c_u\) is equal to the rotation of \(c'_u\) by \(\pi /3\) around the origin. By Lemma 10 monomers in state u in \(L_{n}^{u}\) are never blocked, hence monomers in state u in \(c_u\) are not blocked either. Setting \(n=n'\) in Eq. (2), and noting that \(O(\log n')=O(\log n)\), proves the inductive hypothesis for u.

Since we need to apply the inductive argument at most \(s\le 5\) times, by linearity of expectation, the expected finishing time for the s processes is their sum, \(5 \cdot O(\log n) = O(\log n)\). \(\square\)

Fig. 7
figure 7

Impossibility of \(360^\circ\) line rotation (Theorem 14), by showing that for all \(n\in {\mathbb {N}}\), the line-rotation Turning Machine \(L_{n}^{6}\) has a reachable but permanently blocked configuration. Looking at the evolution of the first seven monomers (i.e. ignore the rotation of the red line segment) we see one trajectory of the Turning Machine that exhibits permanent blocking in the final (bottom-right) configuration, which has respective states 6, 4, 3, 2, 1, 0, 0. We imagine the red line segment as representing an arbitrary long sequence of monomers running collinear with it, and transitions 14–16, 22–23, and 24–25, each representing the (many step) rotation of the red line by respective angles of 180\(^\circ\), 120\(^\circ\) and \(60^\circ\). These rotations of the red line can proceed by two applications of Theorem 12 (first with \(s=3\), then with \(s=1\)) and the fact that the first monomer of the red line is strictly above, or below, the first seven monomers. Hence the final, permanently blocked, configuration is reachable no matter what length the red line is

5.2 Negative result: line rotation to \(2\pi\) is impossible

Theorem 14

For all \(n\in {\mathbb {N}}, n \ge 7\), the line-rotating Turning Machine \(L_{n}^{6}\) does not compute its target configuration. In other words, there is a permanently blocked reachable configuration.

Proof

Figure 7, looking only at the first 7 (initially blue) monomers, shows a valid trajectory of \(L_{7}^{6}\) , then ends in a permanently blocked configuration, hence the lemma holds for \(n=7\).

Let \(n>7\), and in Fig. 7 let the red line segment denote a straight line \(\ell _{n-7}\) of \(n-7\) monomers co-linear with the red line segment. By inspection, it can be verified that (a) in all 25 configurations the line \(\ell\) does not intersect any blue monomer, and moreover (b) the transitions from configurations 1 through 14, configurations 17 through 23, and configuration 24 to 25 are all valid, meaning that the length \(n-7\) line \(\ell _{n-7}\) does not block the transition. The transitions for configurations 14 through 17 are valid by Theorem 12 (with \(s=3\)) and the fact that the last blue monomer (the origin of \(\ell _{n-7}\)) is strictly above all other blue monomers (hence the \(180^\circ\) rotation of \(\ell _{n-7}\) proceeds without permanent blocking by blue monomers). The transition for configuration 23 to 24 is valid by applying Lemma 4 (or Theorem 12, with \(s=1\)) reflected through a horizontal line that runs through the last blue monomer, and the fact that the last blue monomer (the origin of \(\ell _{n-7}\)) is strictly below all other blue monomers (hence the \(60^\circ\) rotation of \(\ell _{n-7}\) proceeds without permanent blocking). Thus all transitions are valid and the permanently blocked configuration is reachable, giving the lemma statement. \(\square\)

6 Folding shapes

In this section we show how to fold certain kinds of shapes with Turning Machines, and we show that other kinds of shapes are impossible to fold, and that others are not foldable but can be approximated.

Definition 15

(Shape) A shape is a set of points in the grid \(G_\triangle\) such that its induced graph is connected (using unit length edges on \(G_\triangle\)).

Definition 16

(xy-connected shape) An xy-connected shape S is a set of points in the grid \(G_\triangle\) such that if we remove all the edges parallel to the direction \(\vec {w}\) from the induced graph of S, it remains connected.

For example squares are a classic benchmark shape in self-assembly:

Definition 17

(\(n \times n\) square) For \(n\in {\mathbb {N}}\) the \(n \times n\) square is the set of points \((x,y) \in {\mathbb {N}}^2\) such that \(0 \le x,y < n\).

Typically, we are interested in folding a shape with a Turning Machine, and ideally we’d like each monomer to sit on one point of the shape, but in the non-ideal case there are errors:

Definition 18

(Error of folding a shape) Given a shape S and Turning Machine configuration c, the error of folding of c with respect to S is the size of the symmetric difference of the shape and the positions of c (i.e., the number of positions of c that are not in S, plus the number of positions S not in c).

6.1 Folding zig-zag paths and \(n \times n\) squares

Recall that a path in \({\mathbb {Z}}^2\) is simple, connected and directed, and its length is the number of its points. Intuitively, a zig-zag path is a path that winds over and back parallel to the x axis, while heading off in one direction (positive or negative) along the other two axes. For example, Fig. 8 shows a positive zig-zag path that rasters an \(8\times 8\) square (traced out by a Turning Machine configuration).

In this section, we apply our techniques from previous sections to help us prove Theorem 21, which states that zig-zag paths (Definition 19) are foldable by Turning Machines in expected time logarithmic in path length. Since for any \(n \in {\mathbb {N}}\), an \(n \times n\) square can be rastered (traced out) using a zig-zag path, we then get that they too are efficiently foldable by Turning Machines.

Definition 19

(Zig-zag path) A positive zig-zag path, or simply zig-zag path, is a path in \({\mathbb {Z}}^2\) composed of unit length line segments that run along directions \(\pm \vec {x}\), \(+\vec {y}\) and \(+\vec {w}\). A negative zig-zag path, has unit length line segments that run along \(\pm \vec {x}\), \(-\vec {y}\) and \(-\vec {w}\).

The previous definition captures the intuition of a path that zig and zags over and back (e.g. Fig. 8) but is much more general since a positive, respectively negative, zig-zag path is any path that is monotone in y (and hence in w), respectively \(-y\) (and hence in \(-w\)).

The following lemma will find future use in showing that a Turning Machine folds a positive zig-zag path.

Lemma 20

Let c be any configuration reachable by a line-rotating Turning Machine \(L^3_n\), then there is a Turning Machine \(T_n\) that has c as its target configuration. Moreover, \(T_n\) runs in expected time \(O(\log n)\).

Proof

We first define \(T_n\) as having the initial configuration \(c_0\), of length \(n\in {\mathbb {N}}\), where for \(0 \le i \le n-1\) monomer \(m_i\) in \(c_0\) has state \(3-s_{i,c}\), where \(s_{i,c}\) is the state of monomer \(m_i\) in c. By hypothesis, c is reachable in \(L^3_n\), which means there is a trajectory (sequence of rule applications) from the initial configuration of \(L^3_n\) to c, thus applying the same sequence of moves in \(T_n\), starting with \(c_0\), also yields c. We need to show that c is the target of \(T_n\) (meaning all trajectories from \(c_0\) reach c).

We will define a “suppressed-\(L^3\)-system” to be a Turning Machine-like systemFootnote 7 that acts like \(L^3_n\) in all ways, except that for each i, after monomer \(m_i\) reaches state \(3-s_{i,c}\) any rule application to \(m_i\) is “suppressed” (not applied).Footnote 8 By Lemma 10, for any i where \(s_{i,c} \in \{ 1,2,3 \}\), monomer \(m_i\) in the suppressed-\(L^3\)-system is never blocked since to experience blocking a monomer needs be in the process of transitioning from state 1 to 0, which never happens for \(s_{i,c} \in \{ 1,2,3 \}\)). In other words, we only expect blocking to affect monomers \(m_i\) for which \(s_{i,c}=0\). Consider such a monomer \(m_i\). By applying Conclusion (i) of Lemma 40 to \(m_i\) we note that blocking only occurs if \(m_i\) is in state 1 and is adjacent to a monomer in state 3. However, such blocking is temporary, which follows from the claim that that adjacent monomer \(m_j\) eventually leaves state 3: to see the claim note that: (a) \(L^3_n\) does not experience permanent blocking (hence \(m_j\) does not) and (b) \(s_{j,c}< 3\), since otherwise two monomers would occupy the position in c which contradicts the positions of c tracing out a path (i.e. non-self-intersecting). Therefore, since there is no permanent blocking in the suppressed-\(L^3\)-system it always reaches c.

Both \(T_n\) and the restricted-\(L^3\)-system have the same set of trajectories because (a) suppressed rules in the restricted-\(L^3\)-system make no change to a configuration, and (b) for any configuration \(c'\) it has the same set of applicable (non-suppressed) rules in the restricted-\(L^3\)-system and in \(T_n\).

For the time analysis, we analyse the expected time for the restricted-\(L^3\)-system to reach c. To do that, we consider two processes (two Markov chains): the process where rules are applied/blocked and the process where rules are suppressed. Observe that suppressed rules do not change a configuration and do not change the rate of applications of rules, thus from now on in our analysis, we ignore the latter process. For the restricted-\(L^3\)-system to reach c, applicable rules are either unblocked (rate 1 per rule application) or temporarily blocked, and the latter case only occurs when a monomer \(m_i\) in state 1 is adjacent to a monomer \(m_j \in \{m_{i-1}, m_{i+1} \}\) where \(m_j\) is in state 3 and is unblocked (as argued above). Since all such \(m_j\) are unblocked, the expected time until they are all in a state \(< 3\) is \(O(\log n)\), after which there are no blocked monomers in the resulting configuration. The rule application process then completes in expected time \(O(\log n)\), giving an overall expected time of \(O(\log n)\).

\(\square\)

Theorem 21

A positive, or negative, zig-zag path P, of length n, is foldable by a Turning Machine in expected time \(O(\log n)\).

Proof

Let P be a positive zig-zag path. We begin by defining a length-n Turning Machine \(T^{\text {zz}}\) whose targetFootnote 9 configuration c traces out the zig-zag path P. By the definition of P, each monomer in c points in one of the directions \(\pm \vec x, +\vec y\) and \(+ \vec w\). For any configuration \(c'\), and \(0\le i \le n-1\), let \(m_{i,c'}\) denote monomer \(m_i\) in configuration \(c'\). In the initial configuration \(c_0\) of \(T^{\text {zz}}\), for \(i\in \{0,1,\ldots ,n-2 \}\) we define monomer \(m_{i,c_0}\) to have the state

$$\begin{aligned} s(m_{i,c_0}) = {\left\{ \begin{array}{ll} 0 &{} \text { if } \text {direction}(m_{i,c})=+\vec {x}\\ 1 &{} \text { if } \text {direction}(m_{i,c})=+\vec {y}\\ 2 &{}\text { if } \text {direction}(m_{i,c})=+\vec {w}\\ 3 &{}\text { if } \text {direction}(m_{i,c})=-\vec {x}\end{array}\right. } \end{aligned}$$
(3)

and \(s(m_{n-1,c_0})=0\), where \(\text {direction}(m_i)= \mathrm{pos}(m_{i+1}) - \mathrm{pos}(m_i)\), i.e. the direction of \(m_i\) as defined in Sect. 2. Thus the initial configuration has all states \(\le 3\).

Let \(s_i\) denote the initial state of monomer \(m_i\). Consider the line-rotating Turning Machine \(L^3_n\) in its initial configuration and consider the following trajectory. We begin by moving sequentially along the chain of monomers from left to right starting at \(m_0\), and for each monomer \(m_i\) with \(s_i>0\) we apply a turning rule to \(m_i\) once. After we reach monomer \(m_{n-1}\), we move back along the chain and for each monomer \(m_i\) such that \(s_i>1\) we apply a turning rule to it. After we get back to \(m_0\), we once again move left to right and for each \(m_i\) with \(s_i>2\) we apply a turning rule to it. Once we reach \(m_{n-1}\) again we are done. At this point each monomer \(m_i\) has had \(s_i\) turning rules applied and thus we are in a configuration which traces out the path P. Since target configuration c of \(T^{\text {zz}}\) traces out the path P, c is reachable by \(L^3_n\). Thus by Lemma 20, \(T^{\text {zz}}\) folds P in \(O(\log n)\) expected time.

For a negative zig-zag path P, we use the same proof but mirror-flipped around the x-axis, and using negative (instead of positive) turning numbers. \(\square\)

An example of an \(n\times n\) square \(n\in {\mathbb {N}}\) (Definition 17), with \(n=8\) in the example, is traced out by the path in Fig. 8 (left). Since for any n the \(n\times n\) square is traced out by a positive zig-zag path, by Theorem 21 we immediately get the following corollary:

Corollary 22

For any \(n\in {\mathbb {N}}\), the \(n \times n\) square is foldable with zero error and in expected time \(O(\log n)\).

Fig. 8
figure 8

Left: The yellow points define an \(n\times n\) zig-zag square for \(n=8\) (Definition 17). Corollary 22 states that, for any n, such a square is foldable, and the proof works by showing there is a Turning Machine \(T^{\text {zz}}\) that traces the positive zig-zag path shown (with monomer \(m_0\) at the origin). Right: An intermediate configuration of \(T^{\text {zz}}\): all initially-non-0-monomers have moved. The horizontal lines (in red) subdivide \(T^{\text {zz}} _n\) into n independent subchains each equivalent to a separate line-rotating Turning Machine \(L_{n}^{3}\), which gives some intuition that the target configuration is safely reached on all trajectories without permanent blocking (although our actual proof proceeds by a different argument)

6.2 Folding y-monotone shapes, but with error

If we permit error in a folding, by which we mean that some points of the folding are not in the shape (or vice-versa) then any shape is foldable. In particular, for any shape S there is a (boring) Turning Machine that folds a zig-zag traversal of the bounding rectangle of S. The error will be bounded by the area of S. Can we do any better? In this section, we show that, yes, the class of y-monotone shapes are foldable with error bounded merely by the perimeter of S, and if we allow spatial scaling for y-monotone shapes with the yw-separator property (see Definition 29) we have zero error.

Definition 23

We say that a shape is y-monotone if the points along each of its y-coordinates form a line segment.

The perimeter of a shape is defined as the set of points in the shape that are adjacent (in \({\mathbb {Z}}^2\)) to point(s) not in the shape, and the perimeter length is the number of points in the perimeter. A traversal is a simple path in \({\mathbb {Z}}^2\). A zig-zag traversal is a traversal that traces a positive (or negative) zig-zag path (Definition 19) such as the \(8 \times 8\) square shown in Fig. 8 (Left).

Theorem 24

Any y-monotone shape S can be folded with error no more than the perimeter length of S, and no more than the perimeter of the shape induced by the folding. Moreover, S is folded with error in expected time \(O(\log n)\).

Proof

We will give a zig-zag traversal that covers all points of the shape, as well as possibly a number of points outside the shape, but within the stated error bound. We will then show that the traversal is foldable using the techniques from Sect. 6.1.

For each y-coordinate \(y_i\) in the shape, i.e. \(y_0< y_1< \cdots < y_{H-1}\) where the shape is of height (or span) H along the y-axis, let \(\sigma _i\) denote the set of points along y. The set \(\sigma _i\) is a line segment by y-monotonicity of the shape S.

We define a zig-zag traversal \(\Sigma\) that includes all points of S: If i is an even index such that \(y_i\) is a y-coordinate of S, then let \(\Sigma _i\) include all points of \(\sigma _i\), plus any points p to the right of \(\sigma _i\) such that there is a point \(p+(0,1) \in \sigma _{i+1}\), and any points p to the left of \(\sigma _i\) such that there is \(p+(0,-1) \in \sigma _{i-1}\). Else if i is an odd index such that \(y_i\) is a y-coordinate of S, then let \(\Sigma _i\) include all points of \(\sigma _i\), plus any points p to the left of \(\sigma _i\) such that there is a point \(p+(0,1) \in \sigma _{i+1}\), and any points p to the right of \(\sigma _i\) such that there is \(p - (0,1) \in \sigma _{i-1}\).

In either case \(\Sigma _i\) is a line segment, this follows from the fact that S is connected and y-monotone. For \(j\in \{0,1,\ldots , |\Sigma _i|-1 \}\) we write \(\Sigma _i(j)\) to mean the jth point, where for even i we index from the left hand side (from smallest to largest x-coordinate), and for odd i we index from the right hand side (from largest to smallest x-coordinate) of the line segment \(\Sigma _i\).

We next claim that the sequence \(\Sigma\) is a path that includes all points of S. Writing \(\Sigma\) point-by-point:

$$\begin{aligned} \Sigma =\,&\Sigma _0(0), \Sigma _0(1), \ldots , \Sigma _0(|\Sigma _0|-1),\\&\Sigma _1(0), \Sigma _1(1), \ldots , \Sigma _1(|\Sigma _1|-1),\\&\vdots \\&\Sigma _{H-1}(0), \Sigma _{H-1}(1), \ldots , \Sigma _{H-1}(|\Sigma _{H-1}|-1) \end{aligned}$$

First, \(\Sigma\) includes all points of S because for each i where \(y_i\) is a y-coordinate of S, the set of points \(\cup _i \Sigma _i\) includes all points at y-coordinate \(y_i\) of S (because \(\cup _i \sigma _i\) does and \(\cup _i \sigma _i \subset \cup _j \Sigma _j\)). Second, we need to show that \(\Sigma\) is a simple path. \(\Sigma\) is composed of \(H-1\) non-intersecting line segments therefore is simple. To see that \(\Sigma\) is connected it suffices to observe that for each \(j\ge 0\), \(\mathrm{pos}{(\Sigma _j(|\Sigma _j|-1))} = \mathrm{pos}{(\Sigma _{j+1}(0))} - (0,1)\). This completes the claim that \(\Sigma\) is a path that includes all of S.

For the error, any point in \(\Sigma\) that is not in S is adjacent to a perimeter point of S, this follows from the definition of \(\Sigma _i\), i.e. points in \(\Sigma _i \setminus \sigma _i\) are not in S but are adjacent to points in \((\sigma _{i-1} \cup \sigma _{i+1}) \subset S\).

Also, there is no perimeter point p of S such that there are \(\ge 2\) points of \(\Sigma\) adjacent to p (if there were, this would contradict \(\Sigma\) being simple, or S being connected/y-monotone).

Since \(\Sigma\) is a zig-zag path, it is foldable in \(O(\log n)\) expected time by Theorem 21. \(\square\)

Theorem 24 states that all y-monotone shapes are foldable, albeit with some error. One might ask: Is it possible to fold y-monotone shapes without error? The answer is no, via a straightforward argument:

Fig. 9
figure 9

A foldable shape, but one that requires error \(>0\)

Theorem 25

There are y-monotone shapes that require folding error \(> 0\).

Proof

Let S be a cross shape with width-1 line segments for arms, with arm length \(>1\), as illustrated in Fig. 9.

Since S is y-monotone, by Theorem 24 it is foldable (with error) by a Turning Machine, but since it is not Hamiltonian (does not have a traversal), any folding of it has non-zero error. \(\square\)

Theorem 25 feels unsatisfactory: it is not fair to ask Turning Machines to exactly (zero error) fold shapes that don’t even have an error-free traversal. Later, in Theorem 38, we give a much stronger result: there is a class of shapes that are unfoldable (with zero error), even though each shape in the class has a (zero error) traversal, and moreover that traversal is foldable on at least one Turning Machine trajectory.

We leave the following open problem as future work:

Open Problem 26

Characterise the class of shapes that are foldable with 0 error.

In the next section we make some partial progress.

6.3 Folding scaled shapes with 0-error

In this section we present an approach to folding spatially scaled shapes with 0-error. In our setting, factor-2 scaling is sufficient. See an example in Fig. 10.

Fig. 10
figure 10

Left: an xy-connected y-monotone shape S with a yw-separator (purple). Right: \(S_{\times 2}\), a scaled version of S by a factor two, its traversal \(\Sigma\) (black) by a chain of a Turning Machine \(T^{\Sigma }\), and the cut \(\gamma\) (purple)

Definition 27

Given a shape S, we define its scaled version \(S_{\times k}\) by a factor k in the following way. Each vertex \((i,j)\in S\) is replaced by a \(k\times k\) square in shape \(S_{\times k}\). That is, for every \((i,j)\in S\), shape \(S_{\times k}\) contains all grid-vertices \(\{(ki+a,kj+b)\mid 0\le a,b<k\}\).

If we blindly attempt to take our approach of folding with error, Theorem 24, and attempt to apply it directly to fold factor-2 scaled shapes, we will fail (for example, consider a factor-2 scaled version of the cross in Fig. 9). However, in this section we introduce a sufficient property of a shape S to have, such that its scaled version \(S_{\times 2}\) is foldable by a Turning Machine (leading to Theorem 33).

Let \(C=\{c_1,c_2,\ldots ,c_k\}\) be a chain of grid-vertices in S. That is, C is a non-self-intersecting sequence of grid-points such that \(c_i\) and \(c_{i+1}\) are neighboring grid vertices, for all i.

Definition 28

We say that chain C is a yw-chain if the y-coordinates of \(c_i\) and \(c_{i+1}\) differ by exactly one.

Note that in this case C is a chain of straight-line segments parallel to one of the \(\vec y\) or \(\vec w\) directions.

Now, let S be a y-monotone shape, let \(y_\mathrm{min}\) be the y-coordinate of its bottom most row, and let \(y_\mathrm{max}\) be the y-coordinate of its topmost row.

Definition 29

We say that chain \(C=\{c_1,c_2,\ldots ,c_k\}\) is a yw-separator of a y-monotone shape S if (1) C is a yw-chain, (2) \(c_i\in S\) for all i, and (3) the y-coordinates of \(c_1\) and \(c_k\) are \(y_\mathrm{min}\) and \(y_\mathrm{max}\), respectively.

First, we prove that a scaled version of an xy-connected y-monotone shape with a yw-separator can be partitioned into two pieces with “nice” left and right boundary, respectively (see Fig. 10 (right)).

Definition 30

Define the left (right) boundary of a y-monotone shape S to be the set of the leftmost (rightmost) grid-points in every row of S.

Definition 31

Given the yw-separator C of a y-monotone shape S. Define \(C_{\times 2}\) as the set of grid points in \(S_{\times 2}\) that corresponds to C in S, that is, for each \(c_i = (x_i,y_i) \in C\), we denote the four points in \(C_{\times 2}\) corresponding to \(c_i\), as \(c_{i,(0,0)}=(2x_i,2y_i)\), \(c_{i,(1,0)}=(2x_i+1,2y_i)\), \(c_{i,(0,1)}=(2x_i,2y_i+1)\), and \(c_{i,(1,1)}=(2x_i+1,2y_i+1).\)

Consider the yw-separator C of S, where S is a xy-connected y-monotone shape, and consider the grid-points \(C_{\times 2}\) of \(S_{\times 2}\).

Fig. 11
figure 11

Left: an xy-connected y-monotone shape S containing 6 points, along with a yw-separator C (in purple). Right: grid points in black show \(S_{\times 2}\) which is the factor-2 scaling of S and the separator C (in purple) that separates \(S_{\times 2}\) into \(S'_{\times 2}\) (left) and \(S''_{\times 2}\) (right)

We cut \(S_{\times 2}\) in between the points of \(C_{\times 2}\) in the following way (refer to Fig. 11). Let \(C'\) and \(C''\) be the rightmost boundary of \(S'_{\times 2}\) and the leftmost boundary of \(S''_{\times 2}\) respectively. Assign the bottommost points \(c_{1,(0,0)}\) to \(C'\) and \(c_{1,(1,0)}\) to \(C''\).

For two consecutive points \(c_i\) and \(c_{i+1}\) on C, if \(\overline{c_i c_{i+1}}\) is parallel to \(\vec {y}\), then assign \(c_{i,(0,1)}\) and \(c_{i+1,(0,0)}\) to \(C'\), and \(c_{i,(1,1)}\) and \(c_{i+1,(1,0)}\) to \(C''\).

Otherwise, if \(\overline{c_i c_{i+1}}\) is parallel to \(\vec {w}\), then one of the following cases holds: either the point \(c_i-(1,0)\) belongs to S, or the point \(c_{i+1}+(1,0)\) belongs to S. Indeed, as S is a xy-connected y-monotone shape, one of the two points must belong to S. Then, in the first case, when \(c_i-(1,0)\) belongs to S, we assign one point \(c_{i+1,(0,0)}\) to \(C'\), and three points \(c_{i,(0,1)}\), \(c_{i,(1,1)}\), and \(c_{i+1,(1,0)}\) to \(C''\). In the second case, when \(c_{i+1}+(1,0)\) belongs to S, we assign three points \(c_{i,(0,1)}\), \(c_{i+1,(0,0)}\), and \(c_{i+1,(1,0)}\) to \(C'\), and one point \(c_{i,(1,1)}\) to \(C''\).

Finally, assign the topmost points \(c_{k,(1,0)}\) to \(C'\) and \(c_{k,(1,1)}\) to \(C''\).

In the following lemma we prove that the described method indeed partitions \(S_{\times 2}\) into two simply-connected pieces with yw-chains on the right and left boundary.

Lemma 32

Let S be an xy-connected y-monotone shape that has a yw-separator. Then \(S_{\times 2}\) can be partitioned into two simply-connected y-monotone pieces \(S'_{\times 2}\) and \(S''_{\times 2}\) such that (1) every row of \(S_{\times 2}\) is partitioned into two non-empty subsets, with the left belonging to \(S'_{\times 2}\), and the right to \(S''_{\times 2}\), and (2) the right boundary of \(S'_{\times 2}\) and the left boundary of \(S''_{\times 2}\) form yw-chains.

Proof

We argue that by splitting \(S_{\times 2}\) between the two chains \(C'\) and \(C''\) constructed above, we indeed obtain such \(S'_{\times 2}\) and \(S''_{\times 2}\).

First, observe that \(C'\) and \(C''\) are both yw-chains. Indeed, for each pair of rows in \(S_{\times 2}\) corresponding to a row in S from \(y_\mathrm{min}\) to \(y_\mathrm{max}\) both \(C'\) and \(C''\) have grid-points assigned to them (from the points corresponding to either grid-points in \(C_{\times 2}\) or adjacent grid-points in direction \(\vec {x}\) or \(-\vec {x}\)). Furthermore, by construction, for every two consecutive points \(c'_{j},c'_{j+1}\in C'\) (and \(c''_{j},c''_{j+1}\in C''\)) they differ in y-coordinate by exactly 1, and they differ in x-coordinate by 0 or \(-1\).

Furthermore, observe that \(C'\) and \(C''\) are both yw-separators of \(S_{\times 2}\), as they span from the bottommost to the topmost row of \(S_{\times 2}\).

Let \(S'_{\times 2}\) consist of \(C'\) and all the grid-points of \(S_{\times 2}\) to the left of \(C'\), and let \(S''_{\times 2}\) consist of \(C''\) and all the grid-points of \(S_{\times 2}\) to the right of \(C''\). Shapes \(S'_{\times 2}\) and \(S''_{\times 2}\) are simply-connected, as \(C'\) and \(C''\) are connected, and have yw-chains on the rightmost and the leftmost boundary respectively. \(\square\)

We next define a traversal \(\Sigma\) of \(S_{\times 2}\). Consider the shapes \(S'_{\times 2}\) and \(S''_{\times 2}\) constructed as described in the proof of the above lemma. For each pair of rows of \(S_{\times 2}\) corresponding to a row in S, we traverse the bottom of the two rows of \(S'_{\times 2}\) from the grid-point on \(C'\) left to the end of the row, and return to the grid-point on \(C'\) along the top one of the two rows (see Fig. 10). As the two leftmost grid-points of the two rows in \(S'_{\times 2}\) correspond to the same grid-point of S, the traversal from the first to the second row is valid. Similarly, we traverse the bottom of the two rows of \(S''_{\times 2}\) from the grid-point on \(C''\) right to the end of the row, and return to the grid-point on \(C''\) along the top one of the two rows. As \(C'\) and \(C''\) are yw-chains, the traversal between the two pairs of rows in \(S'_{\times 2}\) and \(S''_{\times 2}\) is valid as well. Finally, we connect the two parts of the traversal \(\Sigma\) across \(C'\) and \(C''\) in the bottommost row of \(S_{\times 2}\).

Theorem 33

Let S be an xy-connected y-monotone shape that has a yw-separator C, then \(S_{\times 2}\) is foldable by a Turning Machine in expected time \(O(\log n)\).

Proof

We prove that the Turning Machine \(T^\Sigma\) defined as follows folds the shape \(S_{\times 2}\), i.e. on all trajectories. Let \(T^{\Sigma }\) consist of n monomers \(m_0,m_1,\ldots ,m_{n-1}\), where n is the number of grid-points of \(S_{\times 2}\), and the first monomer \(m_0\) corresponds to the topmost grid-point of \(C'\) (defined above). In the folded state, \(T^{\Sigma }\) traverses \(S'_{\times 2}\) from top to bottom, and then traverses \(S''_{\times 2}\) from bottom to top. Let the initial states of the monomers forming the bottommost row (except for the rightmost one) of \(S_{\times 2}\) be 0. Applying Lemma 9 we derive the initial states of the remaining monomers (refer to Fig. 10). Let monomer \(m_j\) correspond to a grid-point \(p_j\in S'_{\times 2}\). We consider the following cases: \(p_j\) is in an odd or even row of \(S'_{\times 2}\); furthermore, we consider the cases when \(p_j\) is the leftmost point, the rightmost point, or an interior point of the row. Let \(C'=\{c'_1,c'_2,\ldots ,c'_k\}\) and \(C''=\{c''_1,c''_2,\ldots ,c''_k\}\), where \(c'_1\) and \(c''_1\) are the bottom most grid-points, and \(c'_k\) and \(c''_k\) are the top most grid-points. Let \(p_j\) be in an odd row, then

  • if \(p_j=c'_\ell \in C'\) and \(\ell >1\), then \(s(m_j)=-2\) if \(\overline{c'_{\ell -1},c_\ell }\) is parallel to \(\vec {y}\), and \(s(m_j)=-1\) if \(\overline{c'_{\ell -1},c_\ell }\) is parallel to \(\vec {w}\),

  • otherwise, if \(p_j\not \in C'\) or \(p_j=c'_1\), then \(s(m_j)=0\).

Let \(p_j\) be in an even row of \(S'_{\times 2}\), then

  • if \(p_j\) is the leftmost point in its row, then \(s(m_j)=-2\),

  • otherwise, \(s(m_j)=-3\).

Similarly, for the monomers whose final positions fall in \(S''_{\times 2}\), we specify the following initial states. Let \(p_j\) be in an even row of \(S''_{\times 2}\), then

  • \(s(m_{n-1})=0\),

  • if \(p_j=c''_\ell \in C''\) and \(\ell <k\), then \(s(m_j)=1\) if \(\overline{c''_{\ell },c''_{\ell +1}}\) is parallel to \(\vec {y}\), and \(s(m_j)=2\) if \(\overline{c'_{\ell },c''_{\ell +1}}\) is parallel to \(\vec {w}\),

  • otherwise, if \(p_j\not \in C''\), then \(s(m_j)=-3\).

Let \(p_j\) be in an odd row of \(S''_{\times 2}\), then

  • if \(p_j\) is the right point in its row, then \(s(m_j)=1\),

  • otherwise, \(s(m_j)=0\).

We claim that \(T^\Sigma\) indeed computes \(S_{\times 2}\) and does not enter a permanently blocked configuration for any sequence of transition rules (trajectory). Assume that there is a configuration c that is reachable from the initial configuration of \(T^\Sigma\) that is permanently blocked. Let \(m_i\) be the monomer corresponding to the bottommost grid-point of \(C'\), that is, \(m_i\) is the last monomer in the traversal \(\Sigma\) that is still in \(S'_{\times 2}\). Let \(T'\) and \(T''\) be Turning Machines consisting of the monomers \(\{m_0,\ldots ,m_i\}\) and \(\{m_{i+1},\ldots ,m_{n-1}\}\) correspondingly. Similarly to the proofs of Theorems 21 and 24 , we can argue that \(T'\) and \(T''\) individually compute the shapes \(S'_{\times 2}\) and \(S''_{\times 2}\), i.e., they fold without entering in a permanently blocked configuration. Thus, if \(c'\) is blocked, then for every monomer \(m_\ell\) there must be a pair of monomers \(m_j\) with \(j\le i\) and \(m_k\) with \(k>i\) that are blocking the transition of \(m_\ell\).

Consider individual folding of the Turning Machine \(T''\). Without loss of generality, let the monomer \(m_{i+1}\) be fixed in the origin of the coordinate system, and the remaining monomers move with respect to it. We consider the cut \(\gamma\) between the shapes \(S'_{\times 2}\) and \(S''_{\times 2}\) in this global coordinate system, and extend its ends to infinity along the \(\vec {y}\) direction (see Fig. 12). We claim that the monomers of \(T''\) always remain to the right of \(\gamma\). Consider how the position \(\mathrm{pos}(m_j)\) changes when the transition rules are applied to the monomers of \(T''\). The monomers of \(T''\) rotate from orientation \(\vec {x}\) to \(\vec {y}\), from \(\vec {y}\) to \(\vec {w}\), and from \(\vec {w}\) to \(-\vec {x}\). If a monomer \(m_k\) moves, where \(k\ge j\), the position of \(m_j\) does not change. If a monomer \(m_k\) moves, where \(k<j\), the position of \(m_j\) changes by one unit distance in the directions \(\vec {w}\), \(-\vec {x}\), or \(-\vec {y}\). Suppose in an intermediate configuration \(c''\) some monomer \(m_j\in T''\) has a position to the left of the cut \(\gamma\). From this moment on, the position of \(m_j\) is confined to a \(120^\circ\) with its apex in \(\mathrm{pos}(m_j)\) and the two rays emanating in the directions \(\vec {w}\) and \(\vec {-y}\). Thus, monomer \(m_j\) will never cross the cut \(\gamma\) to the right side, and thus \(T''\) does not compute \(S''_{\times 2}\).

Similarly, we argue that the monomers of \(T'\) always remain to the left of the cut \(\gamma\). This implies that there can never be a blocked pair \(m_j\) with \(j\le i\) and \(m_k\) with \(k>i\). Therefore, \(T^\Sigma\) folds \(S_{\times 2}\) on every trajectory.

For the time analysis, we note that the target configuration of \(T'\) is a negative zig-zag path, and the target configuration of \(T''\) is a positive zig-zag path. By Theorem 21, both \(T'\) and \(T''\) would each individually fold in \(O(\log n)\) expected time if they were separate Turning Machines. In the construction in this proof, we show that monomers in \(T'\) don’t block any monomers in \(T''\) (and vice-versa), hence even if both \(T'\) and \(T''\) are joined, they fold independently. Thus, \(T^\Sigma\) completes in \(O(\log n)\) expected time. \(\square\)

Fig. 12
figure 12

Folding of a Turning Machine \(T''\). Its monomers remain on the right side of the cut \(\gamma\). If monomer \(m_j\) were to the left of \(\gamma\), its further position is confined to the cone shown in green

6.4 Shapes that have a traversal, yet are not foldable: spirals

Fig. 13
figure 13

A \(k=3\)-turn, gap 1, spiral on the triangular grid \(G_\triangle\), as defined in Definition 34. The centre of the spiral is at (0,0), and the arms of the spiral turn anti-clockwise while keeping at a distance (gap) of exactly 1 from each other. The monomers framed in red are those which reside in the “almost rectangle” \(R_{k'} = R_{2}\) in Definition 34

The goal of this section is to prove Theorem 38, which gives a class of shapes that have a traversal yet are not foldable. Specifically, the following definition of k-turn, 1-gap, spiral, defines a particular kind of spiral that makes k anti-clockwise turns, and has its arms held at unit distance (gap 1) apart, as shown in Fig. 13.

Definition 34

(k-turn 1-gap spiral) For \(k\in {\mathbb {N}}^+\), define the anti-clockwise k-turn 1-gap spiral to be \(\bigcup _{k' \le k} R_{k'}\), where \(R_{k'}\) is an “almost rectangle” formally defined as follows (see Fig. 13 for a pictorial definition):

$$\begin{aligned} R_{k'}&= \{ (x,y) \mid y = \pm 2k' \text { and } -2k' \le x \le 2k'-1 \} \\&\quad \cup \{ (x,y) \mid x \in \{ -2k' , 2k'-1\} \text { and } -2k' \le y \le 2k' \} \\&\quad \cup \{ (2k'-2, -2k' + 2), (2k',-2k'),(2k'+1,-2k') \} \\&\quad \setminus \{ (2k'-1, -2k' +1 ) \}\,. \end{aligned}$$

Remark 35

For each k, the k-turn 1-gap spiral has two traversals—one starting at the centre, one ending at the centre. It can also be seen that k-turn 1-gap spiral has a Turning Machine that has a trajectory whose final configuration is the spiral—\(S_M\) starts as a line with monomer \(m_0\) at the centre of the spiral, and with initial states being turning numbersFootnote 10 for the spiral curve. One can then imagine a trajectory that folds each arm of the spiral one at a time starting at the centre and working its way out (like rolling up a piece of paper). However, despite this, in this section we show that for each \(k \in {\mathbb {N}}^+\), the k-turn 1-gap spiral is not foldable by a Turning Machine (Theorem 38). The proof shows that any Turning Machine that attempts to fold a spiral must fail by either having invalid/illegal states, or else having at least one permanently blocked reachable configuration.

The following technical definition is used in the statement of Lemma 37. The notation \([a]^b\), means \(\underbrace{a, a,\ldots , a}_{b \text { times}}\).

Definition 36

For \(k\in {\mathbb {N}}^+\), let S be a k-turn 1-gap spiral. A sequence of inside-to-outside turning numbers for S is of the form

$$\begin{aligned} T_{\mathrm{in-to-out}}(t_0)= & {} [t_0]^{1}, [t_1]^{2}, [t_2]^{3}, [t_3]^{4}, \ldots ,\\&[t_{4k-2}]^{4k-1}, [t_{4k-1}]^{4k}, [t_{4k}]^{4k+1}, t_{4k} \,, \end{aligned}$$

where \(t_0 \in {\mathbb {Z}}\) is such that \(t_0 \equiv 0~\mathrm{mod}~6\) and

$$\begin{aligned} t_i = {\left\{ \begin{array}{ll} t_{i-1} + 2 &{} \text { if } i \text { is even, } \\ t_{i-1} + 1 &{} \text { if } i \text { is odd. } \end{array}\right. } \end{aligned}$$
(4)

A sequence of outside-to-inside turning numbers for S is any sequence of the form

$$\begin{aligned} T_{\mathrm{out-to-in}}(t_0) = t_0 , [t_0]^{4k+1}, [t_1]^{4k}, [t_2]^{4k-1}, [t_3]^{4k-2}, \ldots , [t_{4k-1}]^{2} , [t_{4k}]^{1} \,, \end{aligned}$$

where \(t_0 \in {\mathbb {Z}}\) is such that \(t_0 \equiv 3~\mathrm{mod}~6\), and

$$\begin{aligned} t_i = {\left\{ \begin{array}{ll} t_{i-1} - 1 &{} \text { if } i \text { is even, } \\ t_{i-1} - 2 &{} \text { if } i \text { is odd. } \end{array}\right. } \end{aligned}$$
(5)

Lemma 37

For \(k\in {\mathbb {N}}^+\), the k-turn 1-gap spiral \(S_k\) is unfoldable by any Turning Machine M that has initial state sequence \(s_0(m_0),s_0(m_1),\ldots , s_0(m_{n-1})\) that is not one of the turning number sequences \(T_{\mathrm{in-to-out}}(s_0(m_0))\) or \(T_{\mathrm{out-to-in}}(s_0(m_0))\) from Definition 36.

Proof

From its definition, \(S_k\) has exactly \(|S_k| = 8k^2+6k+2\) points, which, by a straightforward calculation, is the same as the length of the sequences of canonical turning numbers in Definition 36. If M does not have exactly \(n = |S_k|\) monomers, does not fold \(S_k\) (either it does not cover all points of \(S_k\) or covers too many). Assume then that we are given a Turning Machine M with \(n = |S_k|\) monomers, but that do not have states given by Definition 36.

The spiral has exactly two points, namely (0, 0) and \((2k+1, -2k)\), that have degree 1 (one neighbour in \(S_k\)); we respectively call them the inside and outside start points. If the spiral were foldable, then monomer \(m_0\) is positioned on either the inside or outside start point. By Lemma 8, \(| s_0(m_i) - s_0(m_{i+1})| \le 2\) for all \(0\le i<n-1\).

Suppose \(\mathrm{pos}(m_0)\) is the inside start point. If any of the remaining claims do not hold, then the \(S_k\) is unfoldable:

Monomer \(m_0\)’s initial state is \(s_0(m_0) \equiv 0 \mod 6\), by directionality of \(m_0\) in the final configuration of M (if not, we are done because either \(m_0\) finishes in state 0 but pointing in the wrong direction and thus places \(\mathrm{pos}(m_1)\) outside of \(S_k\), or else \(m_0\) never reaches state 0 meaning \(m_0\) is permanently blocked). Also, \(s_0(m_1) \equiv 1 \mod 6\), for the same reason. But Lemma 8 tell us that \(| s_0(m_i) - s_0(m_{i+1})| \le 2\) for all \(0\le i<n-1\), hence \(s_0(m_1) = s_0(m_0) + 1\). (If not, we would get that M is blocked (by violating Lemma 8), or that M does not precisely trace the spiral (if \(s_0(m_1) \not \equiv 1 \mod 6\)). Tracing around \(S_k\) using the same reasoning for each point along \(S_k\) gives that either \(T_{\mathrm{in-to-out}}(s_0) = s_0(m_0),s_0(m_1),\ldots , s_0(m_{n-1})\) or else M does not fold \(S_k\), giving the lemma conclusion for this case.

Else, \(\mathrm{pos}(m_0)\) is on the outside start point of \(S_k\). A similar argument (to the inside case) shows that \(T_{\mathrm{out-to-in}}(s_0) = s_0(m_0),s_0(m_1),\ldots , s_0(m_{n-1})\) or else M does not fold \(S_k\), giving the lemma conclusion for this case. \(\square\)

Theorem 38

(Shapes with a traversal, but are unfoldable) For all \(k\ge 2\) the k-turn 1-gap spiral \(S_k\) is not foldable.

Fig. 14
figure 14

Illustration for Case 1 of the proof of Theorem 38, showing that a 2-turn, 1-gap, Spiral can not be folded from “inside to out”. Top left: initial configuration, monomers are co-linear, colours distinguish initial states. a Initial configuration with all states positive. First we fold the intended innermost coil/turn of the spiral, by rotating almost the full line of monomers anti-clockwise by \(\pi\), creating a small “pocket” (red, green, and blue monomers). Then the teal/grey monomers “prematurely” fold the configuration into the pocket, eventually yielding a permanently blocked configuration—to carry out the folding it suffices that the teal monomers have initial state \(\ge 6\). b Initial configuration with all states negative. The trajectory shown folds into a permanently blocked configuration similar to that in Fig. 7, but here uses clockwise turning (negative states) and has an extra long tail that needs to be folded out of the way before completing the erroneous tight spiral. The configuration in on the right is not (yet) permanently blocked, but the 7 monomers in the inner tight spiral are permanently blocked and thus all trajectories forward lead to permanently blocked configurations. c Initial configuration with strictly positive and strictly negative states. By Case 1(c) in the proof, there is a contiguous segment of monomers in state 0, here shown in purple. Monomers to the left (negative states) fold clockwise, and monomers to the right (positive states) fold anticlockwise, yielding a pincer-like permanently blocked configuration

Proof

Suppose for the sake of contradiction that there is a Turning Machine M that folds \(S_k\), \(k\ge 2\). By Lemma 37, there are two cases, either, (Case 1) M has initial states \(T_{\mathrm{in-to-out}}(s_0(m_0))\) and \(s_0(m_0) \equiv 0 \mod 6\), or (Case 2) \(T_{\mathrm{out-to-in}}(s_0(m_0))\) and \(s_0(m_0) \equiv 3 \mod 6\).

Case 1: M has initial states \(T_{\mathrm{in-to-out}}(s_0(m_0))\) for \(s_0(m_0) \equiv 0 \mod 6\) (intuitively, folding the spiral from inside to outside).

We have \(\mathrm{pos}(m_0)=(0,0)\) (at the “centre” of the spiral), otherwise if M finishes with all monomers in state 0 it would place (many) monomers outside \(S_k\) and we get the statement. There are three subcases: (a) all initial states are positive, (b) all initial states are negative, or (c) there are both strictly positive and strictly negative initial states:

  • Case 1(a): all initial states are positive (\(s_0(m_i) \ge 0\) for all \(0\le i < n\)). Here, the idea is to find a reachable configuration \(c_b\) of M that is permanently blocked, as illustrated in Fig. 14a. First, the M carries out repeated line rotations by \(\pi / 3\), until reaching a configuration where \(m_0\) is in state 0. Then the line of monomers \(m_1,m_2,m_3,\ldots\) rotates by \(\pi / 3\), which puts \(m_1,m_2\) in state 0. We next have the line of monomers \(m_3,m_4,m_5,\ldots\) rotate by \(2 \pi / 3\), which puts \(m_1,m_2\) in state 0, and parallel to the x-axis, pointing the \(-x\) direction (Fig. 14a, left). Next we apply a turning rule application to \(m_{n-2},m_{n-1}\), and then another to \(m_{n-1}\) (Fig. 14a, middle). Now we repeat the previous three steps, moving backwards along monomer indices, until we reach the configuration shown in Fig. 14a, right: i.e., for each \(j \le n-1\) (starting at \(j=n-1\)) apply one turning rule to \(m_{j-2}\), one to \(m_{j-1}\) and then one more turning rule to \(m_{j-2}\), then decrement j and repeat. Eventually we reach a value of j for which no move is possible, yielding the permanently blocked configuration shown in Fig. 14a, right.

  • Case 1(b): all initial states are negative (\(s_0(m_i) \le 0\) for all \(0\le i < n\)). Here, the intuition is to block M by using the fact that \(2\pi\) line rotation is impossible (\(k\ge 2\)), as shown in Fig. 14b. First, by Definition 36, \(t_0<t_1<\cdots <t_{4k}\) on \(T_{\mathrm{in-to-out}}(t_0)\). Moreover, for all monomer states to be negative, and by applying Eq. (4), it is case that \(t_0\le -6k\). By the definition of \(T_{\mathrm{in-to-out}}\)(\(t_0\)) and since \(k=2\), there are \(\ge 15\) monomers with initial state \(\le -6\). Next we apply the main idea used to prove Theorem 14, and illustrated in Fig. 7 (there we folded in the anticlockwise direction, here it is clockwise). Specifically, we claim that the configuration shown in Fig. 14b, right, is reachable, since the 15 monomers \(m_0, m_1,\ldots m_{14}\) have initial state \(\le -6\), hence they are able to reach the configuration shown, and since the other monomers (orange, purple) can be moved as shown to enable the tight inner spiral to form. The configuration in Fig. 14b, right is not (yet) permanently blocked, but the 7 monomers in the inner tight spiral are permanently blocked and thus all trajectories forward lead to permanently blocked configurations.

  • Case 1(c): there are both strictly positive and strictly negative initial states. We know from the definition of \(T_{\mathrm{in-to-out}}(t_0)\), and the subcase we are in, that \(t_0< 0 < t_{4k}\). Moreover, we claim that \(T_{\mathrm{in-to-out}}(t_0)\) has a contiguous subsequence \(0,0,\ldots ,0\); in other words there is an \(i \in \{1,2,\ldots ,4k-1\}\) such that the initial state sequence, \(T_{\mathrm{in-to-out}}(s_0) = T_{\mathrm{in-to-out}}(t_0) = t_0,\ldots t_{4k}\), contains the state subsequence \([t_i]^{i+1} = [0]^{i+1}\). To see the claim, first note that by Definition 36, \(t_0 \equiv 0 \mod 6\), and by Eq. (4) every 4th term \(t_{4j}\) (here, \(0< j < k\)) has the property that \(t_{4j} \equiv 0 \mod 6\). Second, since \(t_0 < 0\) and \(0 < t_{4k}\), there is some j such that \(t_{4j} = 0\), giving the claim. Let \(l_i\) denote the segment of \(i+1\) monomers with initial states \(0,0,\ldots ,0\) (Fig. 14c purple segment). Then, the preceding segment \(l_{i-1}\) has length \(|l_i|-1 = i\) and monomers all in initial state \(-2\), and all monomers preceding that have initial state \(<-2\) (by Eq. (4)). Hence the second configuration in Fig. 14c is reachable (decrement each monomer in \(l_{i-1}\) twice). The succeeding segment \(l_{i+1}\) has length \(|l_i|+1 + i+1\) and monomers all in state 1, and and all monomers succeeding that have initial state \(\ge 3\) (by Eq. (4)). Hence the third configuration in Fig. 14c is reachable (increment each monomer in \(l_{i+1}\) once, and each monomer in \(l_j\), for \(j>i+1\), three times). Figure 14c is permanently blocked.

Case 2: M has initial states \(T_{\mathrm{out-to-in}}(s_0(m_0))\) for \(s_0(m_0) \equiv 3~\mathrm{mod}~6\) (intuitively, folding the spiral from outside to inside).

We have \(\mathrm{pos}(m_0)= (2k+1, -2k)\) (at the “outside” of the spiral, bottom right corner), otherwise if M finishes with all monomers in state 0 it would place (many) monomers outside \(S_k\) and we get the statement. There are three subcases: (a) all initial states are positive, (b) all initial states are negative, or (c) there are both strictly positive and strictly negative initial states:

  • Case 2(a): all initial states are positive (\(s_0(m_i) \ge 0\) for all \(0\le i < n\)). this case is illustrated in Fig. 15a. The proof here is very similar to that of Case 1(b), in particular Fig. 15a is a reflection about the x-axis of Fig. 14b, and the only other difference here is that to reach a permanently blocked configuration we start turning from the monomers that are intended to become the shorter (rather than longer) arms of the spiral.

  • Case 2(b): all initial states are negative (\(s_0(m_i) \le 0\) for all \(0\le i < n\)). First, by Definition 36, \(t_0> t_1> \cdots > t_{4k}\) on \(T_{\mathrm{out-to-in}}(t_0)\). Moreover, for all monomer states to be negative, and by applying Eq. (5), it is case that \(t_0\le -3\). We begin by applying \(|t_0|\) turning rule applications to all monomers, until the first k monomers (i.e, \(m_0,m_1,\ldots ,m_{4k}\)) have each reached state 0. Next we apply 2 turning rules to all non-zero monomers such that monomers with initial state \(t_1\) turn to state zero (grey in Fig. 15b, left). Next we apply 1 turning rules to the remaining non zero monomers such that the monomers which were initially in state \(t_2\) are now in state zero (purple in Fig. 15b, left). Next we apply 2 turning rule applications to monomers \(m_i\) with \(12k+2<i<n\) in order to reach the ‘q-shaped’ configuration shown in Fig. 15b, right. We claim that all trajectories forward from this configuration reach a permanently blocked configuration: The first three “spiral arms” (monomers with initial states \(t_0,t_1,t_2\)) have reached state 0 and thus will not rotate any further. In order for the remaining non-0 state monomers to attempt reach the target configuration of \(S_k\), they can only make clockwise turns which results in them wrapping around the blocked inner region. Eventually all are permanently blocked

  • Case 2(c): there are both strictly positive and strictly negative initial states. This case is similar to that of Case 1(c). By the definition of \(T_{\mathrm{out-to-in}}\)(\(t_0\)), and the subcase we are in, \(t_0>0>t_{4k}\). Similarly to Case 1(c) we claim that the initial state sequence \(T_{\mathrm{out-to-in}}\)(\(s_0\)) = \(T_{\mathrm{out-to-in}}\)(\(t_0\)) contains the state sequence \([t_i]^{4k+1-i}=0\) for some \(i \in \{1,2, \ldots ,4k-1\}\). To see this we first note that by Definition 36, \(t_0\equiv 3 \mod 6\), and by Eq. (5) every 4th term after the \(2^\text {nd}\) term is congruent to \(0 \mod 6\) (that is to say \(t_i\equiv 0 \mod 6\) such that \(i \equiv 2 \mod 4\)). Thus \(t_{4j+2}\equiv 0 \mod 6\) for some j with \(0\le j < k\). We let \(l_i\) denote this segment of \(4k+1-i\) monomers each with initial state 0. (Fig. 15c dark green segment). Then the preceding segment \(l_{i-1}\) has length \(4k-i+2\) and has initial states 1 and the succeeding segment \(l_{i+1}\) of length \(4k+2\) with initial state \(-2\) by Eq. (5). Hence the second configuration in Fig. 15 is reachable. The segment \(l_{i+2}\) of length \(4k-i-1\) has initial state \(-3\) by Eq. (5). Hence the third configuration in Fig. 15c is reachable. Thus Fig. 15c is permanently blocked.

\(\square\)

Fig. 15
figure 15

Illustration for Case 2 of the proof of Theorem 38 showing that a 2-turn, 1-gap, Spiral can not be folded from “outside to in”. Top left: initial configuration, monomers are co-linear, colours distinguish initial states. a Initial configuration with all states positive. Trajectory shown folds into a permanently blocked configuration similar to that in Figs. 14b and 7 . The configuration to the right is not yet permanently blocked, but the 7 monomers in the inner tight spiral (starting at \(m_0\)) are permanently blocked and thus all trajectories from this configuration will yield permanently blocked configurations. b Initial configuration with all states negative. First we fold the outer most part of the spiral by rotating almost a full line of monomers clockwise by \(\pi\) creating a large “C shape” (dark green, gray, purple monomers). Then the remaining arm of the spiral folds such that it is anti-parallel to the y-axis (right). This arm of the spiral wishes to rotate clockwise to reach the center, but to do so would cause these monomers to intersect with the “C shape” outer coil of the spiral, thus leading to a permanently blocked configuration. c Initial configuration with both strictly positive and strictly negative initial states. This construction is similar to that used in Fig. 14c such that there is a contiguous segment of monomers with states \(0,0,\ldots ,0\), here shown in dark green. Monomers to its left (positive states) fold anti-clockwise, and monomers to the right (negative states) fold clockwise, yielding a “pincer-like” permanently blocked configuration