Tractable Shape Grammars

In this paper we explore the theoretical basis for a concept of ‘computation-friendly’ shape grammars, through a formal examination of tractability of the grammar formalism. Although a variety of shape grammar definitions have evolved over time, it is possible to unify these to be backwards compatible. Under this unified definition, a shape grammar can be constructed to simulate any Turing machine from which it follows that: A shape grammar may not halt; its language space can be exponentially large; and in general, its membership problem is unsolvable. Moreover, parametric subshape recognition is shown to be NP. This implies that it is unlikely, in general, to find a polynomial-time algorithm to interpret parametric shape grammars, and that more pragmatic approaches need to be sought. Factors that influence the tractability of shape grammars are identified and discussed.


Introduction
Implementing a parametric shape grammar interpreter has long been considered difficult (Chau et al, 2004;Gips, 1999) for reasons not always apparent. In this paper we consider the issue of implementation through a formal examination of tractability of the shape grammar formalism for which we invoke both formal language theory and asymptotic analyses of algorithms. Specifically, a computational problem is deemed tractable whenever there is a polynomial algorithm; and intractable when it requires superpolynomial, typically, exponential, time. As a result we are better positioned to formulate a concept for a shape grammar that is 'computation friendly'.
The basic formalism of a shape grammar has remained largely unchanged, although, over time there have been changes in definition and development. Factors that have influenced these changes relate to the scope of permissible shape elements and possible augmentations. The early focus in shape grammars was on two-dimensional shapes made up from finite lines, specified, representationally, in terms of maximal elements (Stiny, 1980a). In the kindergarten grammar (Stiny, 1980b), basic shapes were extended to three-dimensional rectilinear solids, albeit drawn as line shapes. In a subsequent paper Stiny (1991) considered shapes made up from points, lines, planes, or solids as the main elements for a shape grammar. Krishnamurti (1992a) examined shape arithmetic for shapes made up from finite planes; with Earl (Krishnamurti and Earl, 1992) he considered subshape recognition for three-dimensional shapes under linear transformations; and with Stouffs (Krishnamurti and Stouffs, 2004) he extended the arithmetic to higher-dimensional shape algebras, described algorithms for three-dimensional shape arithmetic and analyzed their computational complexity (Stouffs and Krishnamurti, 2006), and considered subshape recognition over the Cartesian products of differently dimensioned shapes (Krishnamurti and Stouffs, 1997). A three-dimensional shape grammar implementation based on a commercial solid modeling kernel has been described 2.1 SG- DEF-1971 The earliest definition for a shape grammar comes from the seminal article by Stiny and Gips (1971), who employ an analogy to phrase structure grammars (also known as generative grammars).
Here, the marker set M is a finite set of shapes that is distinct from the vocabulary set S. Each rule (u, v) satisfies the following: u is a shape in (x ! S * ) × M, and (i) v is x or, (ii) v is x augmented by a shape in M [that is, x ! ({s} × M )] or, (iii) v is x augmented by a shape in S * × M. That is, v ! [(7y, x 3 y ! S * ) × M ]. I is a shape in S * × M.
In many ways this definition reflects the infancy of shape grammars in the sense that grammars are purely shape based, daringly moving away from symbols in a direct manner. Markers, which are used to guide the application of shape rules, are also shapes distinguishable from the principal shape, avoiding the use of any nonshape symbols. There are no restrictions on the types of shapes used; that is, in principle, shapes can be combinations of straight lines or curves, two-dimensional or three-dimensional, or whatever. Analogous to phrasestructure grammars, the * operator is defined over S, and is interpreted as a finite arrangement of elements of S under transformations of similarity, including the empty shape ø. (2) This enables one to define a shape vocabulary succinctly. However, on careful examination, there is no * operator defined over M-in all probability, this was a typographic errorhowever, this results in a definition that is not completely consistent with the shape grammar examples (Urform I, II, and III) given in the paper. In particular, the marker for RULE 1 (page 1461) changes in size as well as orientation and the set M is defined to contain a single marker. Noticeably, here shape rules can, in effect, only add more terminal shapes, with no capacity for subtraction, although markers can be eliminated, revised, or exchanged during the application of shape rules. Implicitly, the application of a shape rule involves the shape operations of Boolean sum and difference; moreover, recursive application of shape rules requires that both Boolean operations be closed over the types of shapes involved.

SG-DEF-1975
In his PhD thesis Stiny (1975) investigated the concept of shape grammars in terms of two models, pictorial and formal. The definition of shape grammars in the pictorial model is essentially the same as Gips's (1974) definition, SG-DEF-1974. However, the definition for the formal model (SG-DEF-1975) is 'custom designed' for analysis, analogously to phrasestructure grammars. Here, a shape is restricted to consist of only line segments. Such shapes are most common, and have certain nice properties. For example, all shapes belong to the set defined by a unit line segment under the * operator. In contrast, this is not the case for shapes made out of arcs. As before, a shape grammar is a 4-tuple: GS, M, P, I H, with the following conditions: each production in P is of the form Gs u , u 1 , …, u n H " In comparison with SG- DEF-1971 andSG-DEF-1974, the R operator, which enforces shapes to be in a reduced form (maximal lines), is new in this definition. Implicit in the definition of the R operator is the notion of embedded shapes, more specifically of proper line (segments) embedded in the maximal lines. A subshape of a shape is then made up from these embedded (line) segments. The restriction of shapes made out of straight lines makes it nearly impossible to distinguish S * from M * . The technique to deal with such difficulty is to employ shapes with multiple tuples; that is, shapes on different tuples are on different 'channels', thereby not interfering with one another. The use of n +1 tuples of shapes, together with the (2) Notationally, we distinguish between Ø and ø, the empty set and empty shape, respectively. symbol e (which behaves as the empty shape ø), enables shape grammars to be combined to form a new shape grammar. However, to our knowledge, no further work along these lines can be found in the subsequent literature.
This definition also distinguishes a special case of shape-rule application. When the union of the left-hand side of a shape rule has fewer than two points of intersection, there are potentially infinitely many ways to apply such a shape rule. It appears that Stiny, at the time, regarded the 'infinitely many ways' unfavorably, defining the transformation to be the one which transforms the left-hand side in such a way that each element has an identical, rather than a subshape, counterpart in the configuration.
With this definition, Stiny was able to show that shape grammars so defined are as equally powerful as Turing machines. Algorithms for shape-rule application, and Church's thesis demonstrate that a Turing machine can simulate any shape grammar so defined. Likewise, a shape grammar can be constructed to simulate any Turing machine.

SG-DEF-1977
In his paper on Chinese ice-ray lattice grammars, Stiny (1977) introduces labeled shapes and parametric shape grammars briefly explaining the corresponding definition for nonparametric shape grammars in the appendix. As parametric shape grammars are further elaborated in a subsequent paper (Stiny, 1980a), we postpone discussion to subsection 2.4 (SG- DEF-1980); the focus here is on labels and markers.
In this definition, shapes are finite arrangements of straight lines of limited but nonzero length specified in some Cartesian coordinate system, assumed given. A family of shapes is defined by associating parametric expressions satisfying certain conditions with a limited number of points coincident with the lines in a given shape. A particular member of this family is specified, by giving an assignment of real values to parameters that satisfies the conditions. The result of applying an assignment g to a parameterized shape s is the shape denoted by g(s). A nonparameterized shape is a special case of a parameterized shape-here g is always the identity assignment, that is, s = g(s). In this case, s has no variables.
The set M consists of labeled points of the form p:m, where p is a point with the symbol m associated with it. It is not necessary for labeled points to be coincident with lines in a shape. A transformation t of a labeled point p:m is the labeled point t( p):m, where t( p) is the image of p under t. A labeled shape, v = Gs, lH, consists of a shape s and an unordered set of labeled points, l. Note that an unlabeled shape s is the labeled shape with an empty set of labeled points; that is, s . Gs, ØH. When s or l are parameterized, v = Gs, lH is a labeled parameterized shape. An assignment g to the parameters in s and l specify a specific labeled shape g(v) in the family of labeled shapes defined by v.
Here, a parametric shape grammar has five parts: GS, M, P, I, T H. T is a collection of allowable transformations. Here, M is a finite unordered set of labeled points. P is a set of shape rules u " v where u and v are labeled parameterized shapes in S + × M * and S * × M * respectively. M * = M + , {e}, where e denotes the empty labeled point. The initial shape is an element of S + × M * . Again, shapes are generated by a shape grammar by beginning with the initial shape I, and recursively applying the shape rules in the set P.
A shape rule u " v applies to a labeled shape s when there is an assignment g and a transformation t such that t[g(u)] G s. The result of applying shape rule u " v to labeled shape s under g and t is the labeled shape given by [s -t[g(u)]] + t [g(v)]. The expression for rule application for a nonparametric shape grammar is obtained by substituting the identity function by g. That is, applying u " v to a shape s under t is the shape given by [s -t(u) This definition of shape grammars uses labeled points instead of markers, in contrast to definitions SG- DEF-1971, SG-DEF-1974, and SG-DEF-1975. Nevertheless, labels and markers are equivalent to some extent. Stiny explains that labeled points function in the same way as markers to guide shape generation; however, labels are invariant under Euclidean transformations whereas markers are not. However, such a distinction might be construed as overly simple, and depends on the design of shape rules. For example, in SG- DEF-1974, Gips (1974 employs certain geometrical characteristics, such as the asymmetry of the markers, to control shape-rule application. By replacing markers with labels, the only important geometry information is position. As most grammars do not rely on the geometric characteristics of markers or labels beyond their position, we may use markers and labels interchangeably unless stated otherwise; consequently, the phrases 'marker driven' and 'label driven' mean exactly the same thing. Knight (1983) provides an extensive discussion on the usage of labels. Labels in a shape rule normally supply additional information not provided by the shapes themselves and indicate (1) how, (2) where, or (3) when a shape rule may apply to the design being generated. How labels specify under which Euclidean transformations a rule can apply (usually by altering the symmetry). Where labels specify the subshapes in the design to which a shape rule can apply. When labels are associated with the design instead of with any particular point or points. When labeling is most frequently used to indicate successive stages in the generation of a design. Here, labels serve as status markers, regulating the sequence and repetition of rule applications. How and where labels are spatial as their location is important. When labels are nonspatial as their presence rather than location is more important.

SG-DEF-1980
Stiny (1980a) elaborates on labeled shapes, and nonparametric and parametric shape grammars. This version (SG-DEF-1980) has subsequently become the standard definition, and is most widely quoted. In this definition, a shape is specified by its maximal line representation, and every line (segment) of a subshape of a shape is embedded in a maximal line of the shape. As before, a labeled shape consists of two parts: a shape and a set of labeled points. Parameterized labeled shapes are similarly defined. Labeled points may be parameterized. That is, the coordinates of a labeled point may be variables Unlike SG-DEF-1977, in this definition, a shape grammar reverts back to comprising four components: S, a finite set of shapes; M, a finite set of labels; P, a finite set of rules of the form u " v, where u is a labeled shape in (S, M) + , and v is a labeled shape in (S, M) * ; and I, the initial shape, a labeled shape in (S, M) + .
For nonparametric shape grammars, a shape rule u " v applies to a labeled shape s when there is a transformation t such that t(u) is a subshape of s. The labeled shape produced by applying the shape rule u " v to the labeled shape s under the transformation t is given by [s -t(u)] + t(v). Parametric shape grammars are extensions of nonparametric shape grammars in which shape rules are defined by filling the open terms (point variables) of a general schema.
A shape rule schema u " v comprises a pair of parameterized labeled shapes, u and v, where no member of the family of labeled shapes specified by u is the empty labeled shape. When specific values are given to the variables of u and v by an assignment g, to determine specific labeled shapes, a new shape rule g(u) " g(v) is defined. This shape rule can then be used to change a given labeled shape into a new shape in the usual way. That is, rule application is expressed as [s -t(g(u))] + t(g(v)).
In comparison with SG- DEF-1975 andSG-DEF-1977, this definition is much more succinct and allows for more flexible shape rules. In SG- DEF-1975, markers are just shapes on different channels from the principal configuration, and labeling is implicit. In SG-DEF-1977, labels replace markers. In this definition, shape rules without symbols are supported; subshape matching drives shape-rule application rather than markers or labels, whereupon, shape emergence becomes the factor to be considered during shape-rule application. While this allows new types of shape rules, there is a price to pay. Computationally, determining applicability of shape rules as well as their corresponding transformations become much more complicated.
Note that, in this definition, the allowable transformations can be restricted to special kinds, although this facility seldom features in the subsequent literature. The restriction on the transformations in the case of the infinitely many ways of applying a shape rule, which appears in SG- DEF-1975, is not singled out here.
The introduction of parametric shape grammars basically extends the scope of allowable transformations. While providing for more flexible and natural design of shape rules, function g for assigning parameters implicitly implies computational difficulty. Such functions are those allowing the points of a shape as variables (open terms) and the space of such functions is infinitely large. This means searching an infinite space. Indeed, Stiny (2006, page 280) states that devising an algorithm to find the transformations under which a parametric shape rule applies to a configuration is an open question. As shown in this paper, the number of candidates to be tested increases exponentially fast as the number of open terms increases, making this problem NP (Garey and Johnson, 1979), perhaps NP-hard, in general.

SG-DEF-1991
An obvious deficiency of SG-DEF-1980 is the limitation on shapes requiring them to be composed of straight lines. Shapes, in general, are formed as arrangements of points, lines, planes, solids, and even exotic curves and surfaces. Stiny (1991) generalizes definition SG-DEF-1980 in terms of shape algebras.
Mathematically, if there is a t such that t(u) G s is satisfied, then an object is produced according to the formula [s -t(u)] + t(v). Operators t, G, +, and -are defined over a shape algebra, where t is a transformation function over a shape and can be generalized as a being alike function, G is a partial order relation in terms of subshape, and + and -are Boolean sum and difference. All these operators are applied recursively until reaching the basic elements, on which these operators are directly defined.
In short, in a shape grammar, any pair of objects u and v defines a rule u " v. The rule applies to an object s in a two-stage process involving a transformation t. The transformation is used in both stages, once with the subshape relation G to distinguish some part of s, and then again with the arithmetic operations + and -to replace the part that has been picked out.
Under this definition, shapes are readily extensible. A shape can be simple-formed from basic elements of a single kind; or compound-a mix of various elements, optionally augmented in some way, for example, by colors. The only condition is that the operators of any shape algebra are defined on all its elementary objects, are recursively applicable, and are closed. In contrast to definition SG- DEF-1980, indeterminacy, that is, the infinitely many ways of applying a shape rule, is encouraged rather than restricted. While this causes little trouble for designers, indeterminacy is a tough issue for computer implementations. Additionally, shape emergence is regarded as a way of producing novel designs. As an extension to this definition, SG-DEF-1992 (Stiny, 1992) formally includes labels and weights in algebraic terms.

SG-DEF-2006
In his monograph, Shape: Talking About Seeing and Doing, Stiny (2006) discusses shape grammars in terms of drawing shapes and calculating by seeing. The historical analogy of shape grammars to phrase-structure grammars is reexamined, with the conclusion that the analogy is inappropriate; it implies a lot more than it should. As a matter of fact, during the design process, a designer's vocabulary of shapes is typically not prescribed; instead, new types of shapes are defined on the fly. Noticeably, in this book, a definition for a shape grammar is actually never given, and only alluded to informally, with the basic formalism remaining the same as SG-DEF-1992.

Trends in the development of shape grammars
The evolutionary development of shape grammars falls into two categories: marker-driven and subshape-driven grammars. Computationally, this distinction is important; in comparison with marker-driven shape grammars, there are more difficult computational issues with subshape-drive shape grammars: in particular, parametric subshape recognition and indeterminacy.
The first four definitions: SG- DEF-1971, SG-DEF-1974, SG-DEF-1975, and SG-DEF-1977 belong to the former category in the sense that shape-rule application in grammars so defined are controlled by markers. It is the markers that play a pivotal role in determining both the applicability of shape rules and their corresponding transformation. Markers can be designed in such a way that the determination of applicability and transformation is relatively straightforward to compute. In later developments of shape grammars markers evolve as alphanumeric symbols, which make determination even simpler (albeit while losing power). All subsequent definitions belong to the subshape-driven category during which markerdriven (also label-driven) and subshape-driven rule application can coexist. In other words, the definitions support both marker-driven and subshape-driven shape grammars. This coexistence between marker-driven and subshape-driven rules is explicit in SG- DEF-1975. Chronologically, the above definitions exhibit backwards compatibility. That is DEF-2006, where the right-hand side of % is more general than the left-hand side. Historically, it is significant to note that SG- DEF-1971% SG-DEF-1974 However, there is a discrepancy between SG- DEF-1974 andSG-DEF-1975. They were developed independently by the two principal authors of shape grammars, for very distinct research purposes, albeit from the same root, SG- DEF-1971. The discrepancy is reflected in the evolutionary development of shape-grammar definitions.
The evolutionary development shows a trend from 'rigid' to 'soft'. 'Rigid' here means that the shape grammars are defined in a way that is closer to phrase-structure grammars. Such shape grammars are more machine bound in the sense that they are relatively easy to carry out (compute) on a computer, but harder to use to generate novel designs. As a matter of fact, there is very limited novelty involved. SG-DEF-1974 falls within this category. A recent series of notable shape grammar implementations based on the CGA shape falls within the rigid category of shape grammars (Müller et al, 2006;Watson et al, 2008;Weber et al, 2009).
On the other hand, 'soft' is more human centered, showing more concern and consideration on how to use shape grammars to generate novel designs. This explains, in part, the importance of subshape-driven grammars, concepts of indeterminacy and shape emergence, and the support for ambiguity in shape-grammar research. Humans have little trouble handling such concepts. Moreover, human designers actually benefit from them. However, these concepts are problematical when considering computer implementation. Recent developments attempt to subvert some of the more difficult issues through alternative representations (Keles et al, 2010). The features are summarized in figure 1.

A unified definition of shape grammars
Traditionally, the nonparametric shape grammars formalism is defined as follows: for a shape rule u " v and a configuration c, if t(u) G c, then the result of applying the shape rule on c is [c -t(u)] + t(v), where t is a transformation of similarity, G is a part relation, -is the operation of Boolean difference, and + is the operation of Boolean sum. Note that, the operations of Boolean sum and difference implicitly involve an operation of reduction R, which is used to maintain the maximal representation (Krishnamurti, 1992b).
For parametric shape grammars, the formalism is defined as follows: for a shape rule schema u(x) " v(x) and a configuration c, if t[g(u(x))] G c, then the result of applying the shape rule on c is [c -t[g(u(x))]] + t[g(v(x))], where g is a function which makes an assignment to the open terms (variables) of the schema.
Since t can be generalized to a being-alike function (Stiny, 1991), the function g can be combined with, thus subsumed by, t to form a new being-alike function. In this way, the formalisms of nonparametric and parametric shape grammars are unified.
Definition For a shape rule u " v and a configuration c, if t(a) G c, then the result of applying the shape rule on c is [c -t(u)]+t(v), where t is a being-alike function, G is a part relation, -is the operation of Boolean difference, + is the operation of Boolean sum.
Implicit in this definition, as the last step in applying a shape rule, is the reduction operator, R, which is needed to maintain a maximal representation.
Following this definition, the scope of basic shape elements can be extended arbitrarily; the bottom line is that all operators of t, G, -, +, and R are well defined. In particular, elements are implicitly typed in a way that operators of G, -, +, and R only operate on two elements of the same type (that is, the elements are coequal); for example, for two line segments, these operators are only meaningful when two have the same slope. The unified definition above is backwards compatible with the other definitions reviewed in this section.

Definition Features
Marker-driven shape grammars

SG-DEF-1971
Based on shapes as both vocabulary and marker elements. Introduces the analogy to generative string grammars. Emergent shapes are implicit in 'surprises'.

SG-DEF-1974
Based on closed polygons, curves. No treatment of emergent shapes. Theoretical basis of the first ever shape-grammar interpreter implemented (Gips, 1974). Certain elements of the shape grammar were treated symbolically in Gips' implementation.

SG-DEF-1977
Introduces labels and labeled points. Outlines the elements of parametric shape grammars.
(Above) Marker-driven shape grammars based on an analogy to generative grammars. Grammars tend to be more tractable and easier to implement.

SG-DEF-1975
Based on two-dimensional rectilinear shapes. Implicit introduction to maximal lines. Mainly used to prove equivalence between shape grammars and other formal language formalisms. Emergent shapes are referred to as 'surprises.' Theoretical basis of the first shape-grammar interpreter that properly took into consideration emergent shapes (Krishnamurti, 1982).
Subshape-driven shape grammars (Below) Subshape-driven shape grammars. Progressively shy away from the generative grammar analogy. Grammars tend to be human-centered, less tractable, and harder to implement. Emergence is central to such grammars.

SG-DEF-1980
Introduces parametric shape-grammar definition for shapes based on a maximal line representation. First definition for rule application explicitly based on the subshape relationship.

SG-DEF-1991
Extends the definition to apply to shapes defined on different algebras, for example, points, lines, planes and volumes. Introduces a being-alike function.

SG-DEF-1992
Extends the algebraic definition to include weighted shapes. This definition subsumes a host of other independently defined weighted shape grammars, for example, color grammars (Knight, 1989).

SG-DEF-2006
Implicit definition of shape grammars considered in Stiny (2006). Essentially dismantles any vestiges of a connection to generative grammars. Indeed, generative grammars can be considered as a special case of shape grammars. The unified definition holds for shape rules defined across shape algebras. In a recent article, Stiny (2011) considers the specification of shape rules in terms of general transformations, part and boundary relationships. In his classification, Stiny considers three basic kinds of rule constructs: x " t(x), x " prt(x) or x " b(x), where t(x) represents a transformation, typically geometrical, in general, a parametric variation of x; in other words, t is a beingalike function. The part relation satisfies prt(x) G x with the reduction operation R relying on there being a shape y such that x = prt( y), or y = prt -1 (x). The inverse part relationship prt -1 is computationally interesting as it essentially specifies a data structure that hosts any of its embedded shapes. Certain prt -1 relations have been referred to as carriers (Krishnamurti and Stouffs, 2004). An example is shown in figure 2. Elements of prt -1 (x) share descriptors with subshapes of carrier(x), which can be effectively employed in computation (Stouffs and Krishnamurti, 2006).
Note that carrier(x) is a restriction on prt -1 (x). There are subshapes y of carrier(x) that are not elements of prt -1 (x). However, since x + y is an element of prt -1 (x), carrier(x) enables us to explore shapes that appear 'unrelated' to x so to speak, that is, even having no shape in common with x. However, these shapes are parts of the same carrier, and this opens up an interesting question, which is beyond the scope of this paper to address. As Stiny (2004, page 64) concludes, Figure 2. A shape x, a shape in prt -1 (x), the carrier of x, and interesting subshapes of carrier(x). "seeing makes it worthwhile to calculate with shapes'', it is worth exploring calculations with the 'unrelated' shapes of a shape. The answer may well lie within the carriers of shapes. For example, in figure 2, for the top left shape, from among possible shapes we see immediately, are the star, five triangles, the pentagon in the middle, ten distinct points of intersection, and at least twenty-five different angles. Some shapes are seen in combination with parts of the top left shape; others have an identity all their own.
The boundary is a cross algebra operator. The b operator and its inverse b -1 define a shape, may resolve parameters, and can be used in conjunction with t, prt, and prt -1 to specify particular shapes. Computationally, in a maximal element representation, the combination of a b and a prt -1 operator specify a shape (Krishnamurti and Stouffs, 2004). Other kinds of shape rules such as erasure, identity, and in general, unrestricted parametric rules can be created from these basic constructs. See Stiny (2011).

Three corollaries
In his dissertation Stiny (1975) concluded that for shape grammars under SG-DEF-1975, theorems on Turing machines naturally hold. Certain direct extensions of theorems on Turing machines to shape grammars are helpful in understanding their computational complexity. These are worth discussing in some detail. Using constructions similar to Stiny's, it is possible to show that a shape grammar under the unified definition can be constructed to simulate any Turing machine. For this, it is essential to consider four aspects. The following briefly explain each and illustrate the corresponding simulation.

Aspect 1. The states of a Turing machine can be encoded as shapes in reduced form, such that no two similar shapes represent distinct states. The set of shapes corresponding to the set of states of the Turing machine will form the main part of the set of markers for the constructed shape grammar.
Consider a Turing machine with states q i , 0 G i G n. Each state q i can be encoded by a triangle shape s i with points {G0, pH, G p, pH, G i p 1 + H, 0H}, where 0 G i G n, p ! 0. Notice that for states q i and q j , if q i ! q j , then s i is not similar to s j . For the shape rules simulating transitions, the states serve as markers. Figure 3(a) shows an example of one such state.

Aspect 2. The tape symbols, including the blank symbol, of a Turing machine can be encoded as shapes in reduced form such that no two similar shapes represent different tape symbols. The set of shapes corresponding to the set of tape symbols of the Turing machine form the main part of the set of terminals for the constructed shape grammar.
Tape symbols can be defined similarly to state symbols. Assume the Turing machine to have the set of tape symbols ∑ = {a i |1 G i G m}. Let the blank symbol be a 0 . Each symbol in the set ∑ , {a 0 } can be uniquely encoded by a triangle with points in the set {G0, pH, G p, pH, G i p 1 + , 2pH}, where 0 G i G m, p ! 0. Figure 3b is an example of such a symbol.

Aspect 3. Turing machine tapes and configurations can be represented by shape grammars.
Consider the Turing machine tape a a i i k 0 f where all symbols to the left of a i0 and to the right of a ik are the blank tape symbol a 0 . The tape can be represented by the shape t i0 , trans(t i1 , p) , f , trans(t ik , p k ), where trans(t , x) means translating shape t by x along the x-axis. Figure 3(c) illustrates an example of such a tape.
Assume that the Turing machine is in state q i and is scanning the tape symbol a ij occurring in the tape j a a a i i i k 0 f f . The configuration can be represented by the pair of shapes GT, trans(s i , p j )H where T is the shape representing the tape a i 0 … a i j … a i k . Figure 3(d) illustrates an example of such a configuration.

Aspect 4. Turing machine transitions can be represented as shape rules. The set of shape rules corresponding to the set of transitions of the Turing machine form the main part of the set of shape rules for the constructed shape grammar.
A transition Gq i , a j , a j' , q i' , LH, which reflects a Turing machine in state q i scanning symbol a j , replacing it by symbol a j' , subsequently going into state q i' , and moving its tape one tape cell to the left, can be represented by the shape rule Gt j , s i H " Gt j' , trans(s i' , p)H. Figure 4 depicts two shape rules that simulate such transitions.
With the above setup, it is easy to see that the constructed parametric shape grammar simulates the computation of a Turing machine by derivation. The following are three relevant direct extensions from the theory of formal languages (Harry and Christos, 1997).
Firstly, it is well known that a Turing machine may not halt. Assume there is a computer program, which recursively applies the shape rules of a shape grammar until no shape rules can apply. As a result, this computer program will not halt for any shape grammar that simulates a nonhalting Turing machine. In other words, there are nonhalting shape grammars.
Secondly, a simulation of a nondeterministic Turing machine (NTM) with n steps by a deterministic Turing machine (DTM) requires exponentially many steps in n. . Encoding symbols and states for a Turing machine by parametric shapes. (a) Parametric shape encoding state q i ; (b) parametric shape encoding symbol a i ; (c) parametric shape encoding the tape a 1 a 2 a 1 a 2 ; (d) parametric shape encoding a configuration a 1 a 2 a 1 a 2 in state q 1 . Adapted from Stiny (1975). Naturally, a shape grammar can be designed in a nondeterministic fashion, for example, the sports-figure grammar (Carlson et al, 1991). Thus, a shape grammar can be designed to simulate any NTM in a fashion similar to simulating a DTM. This is equivalent to the problem of simulating an NTM by a DTM; that is, the language space of a shape grammar can be exponentially large.
Lastly, another well-known theorem for unrestricted string grammars is that the membership problem-that is determining whether a string belongs to the language defined by a grammar or not-is undecidable. A shape grammar can be designed to simulate a string grammar in a similar manner to simulating a Turing machine. For such a shape grammar, the membership problem is equally undecidable-the proof, by contradiction, is trivial. In other words, in general, determining whether a configuration (a shape) belongs to the language defined by the shape grammar is unsolvable; that is, the problem of parsing a configuration against a shape grammar is, in general, unsolvable. Whether it is possible to restrict shape rules to restriction categories similar to those defined for string grammars, for example, context-free grammars, remains an open problem.

Recognition in parametric shape grammars
The three corollaries show that, in principle, there are shape grammars which do not halt and whose language spaces are exponentially large. Such shape grammars are unquestionably intractable. The following question is immediate: are all halting shape grammars with (even large) polynomial language space tractable? For ease of discussion, such grammars are termed practical shape grammars (see figure 5). (b) a i , q j "a k , q l move left. Adapted from Stiny (1975).
A shape grammar is interpreted through the application of its shape rules. A shape grammar contains a finite set of shape rules. This fact underlies the fundamental basis for a shape grammar, namely, that of using a small number of shape rules to realize many, potentially, infinitely many, design possibilities (Stiny, 2006). For practical shape grammars this fact implies that shape rules are applicable in, at most, polynomial time. It therefore follows that tractability is determined by the application of each shape rule. However, it is known that parametric subshape recognition is difficult.
Below, the tractability of a specific problem, that is, subshape recognition of parametric shape grammars over two-dimensional rectilinear shapes, is examined. This is done by considering a polynomial-time reduction on the maximum clique problem (Cormen et al, 2004). The conclusion reached is that it is computationally expensive even for shapes of a relatively small size, and it is NP-hard for shapes with an arbitrary number of open terms.

Parametric two-dimensional rectilinear subshape recognition
For nonparametric subshape recognition of two-dimensional rectilinear shapes, the transformation t can be determined by matching three distinguishable points of a left-hand side shape u to three distinguishable points of a configuration c (Krishnamurti, 1981). In fact, two points are all that are required with a third distinguishable point constructed from these two in four possible ways by considering reflections about the axis through the two distinguishable points. However, for parametric subshape recognition this is not necessarily the case.
It is possible that the parametric shape u has a certain number of fixed points (nonopen terms). If there are more than two fixed points (distinguishable by definition), the above threepoint algorithm is still applicable, with O(n 2 ) possibilities to initially test against. For shapes with a single fixed point, this is identical to the situation when all points are open as similarity is subsumed by the assignment. When there are open points, the shape transformation may not be describable by a homogeneous transformation matrix. For example, figure 6(a) matches figure 6(b) under a parametric shape rule, but there is no 3 × 3 homogeneous matrix which describes the transformation. In every case, open terms have to be determined, point by point, for each candidate subshape in c. In general, when there are k open terms, there are n k j, or O(n k ) possibilities. Even assuming that testing against each possibility costs unit time (typically, this is much more expensive in reality), when k is close to n/2, the time complexity is a superpolynomial. To illustrate with concrete examples, the possible number of tests is 7.5 × 10 7 when k = 5, n = 100; 1.7 × 10 13 when k = 10, n = 100; and 1.0 × 10 29 when k = 50, n = 100. It takes a computer with performance of thousands of millions of instructions per second several minutes to test all the possibilities when k = 10, n = 100. Note that when k > n/2, the number of possible tests begins to decrease. It should be noted that in practice n and k are small numbers.

Parametric subshape recognition (PSR) is NP
Suppose that a subshape s is found under a parametric schema function t. We need to verify that s is the same as the left-hand side shape u under t. Let n be the maximum of the number of points in s and u. As both shapes are two-dimensional and rectilinear, the verification algorithm first computes u' = t(u) by applying t to each point in u. This takes O(n) time, and u' so obtained has at most n points. The verification algorithm picks a point p in s, and compares the neighbors of p against the neighbors of point p' in u', which has the same coordinates as p. This process ends when all points of s have been compared. For each point p in s, it takes O(n) time to find the corresponding point p' in u'. Since there are at most (n -1) edges incident with p as well as p', it takes O(n 2 ) time to verify equality of neighborhoods. Therefore, in total, it takes n[O(n) + O(n 2 )] = O(n 3 ) time to verify the equality of s and u'. That is, verification takes polynomial time.
We next show that PSR in general is NP by reducing the problem of finding certain cliques in a graph to the problem of PSR. That is, if we can solve PSR in polynomial time, then we can solve the graph-theoretical clique problem in polynomial time, which is known to be NP, actually NP-hard (Cormen et al, 2004).
A clique in an undirected graph G = (V, E) is a subset of vertices, V' ,3 V, in which each vertex pair is connected by an edge in E. That is, a clique is a complete subgraph of G. The size of a clique is the number of its vertices. Figure 7(c) is an example of a clique of size 4. The clique problem corresponds to the optimization problem of finding a clique of maximum size in a graph. For example, in the graph of figure 7(a), the maximum clique is 4. The subgraph is shown bold.
Firstly, let us preprocess graph G [figure 7(a)] to get G' [figure 7(b)] by treating vertices in G as end points of incident edges, assigning unique x and y coordinates to all vertices so that no three vertices are collinear, and enforcing all arcs to be straight lines. This can be done in O(|V | 2 ) time. Note that G' is actually a two-dimensional shape, and we can use it as the configuration shape c.
We generate a complete graph G k with k vertices [figure 7(c)] and similarly preprocess it to obtain G k l [ figure 7(d)]. This can be done in O(k 2 ) time. Note that G k l is another twodimensional shape, and we may use it as the left side shape u. The points of u have their counterparts in the vertices of G k . Note that as u is a parametric shape, certain points, hence certain vertices in G k , have coordinates with open terms.
If there is an algorithm capable of detecting the existence of subshape g(u) in c by automatically finding an appropriate assignment of g in a polynomial time, then we can use the algorithm to detect the existence of subshape g(G k l ) in G' by automatically finding an appropriate assignment of g in a polynomial time, say, T k . By the particular way that we processed graph G and G k , the existence of subshape g(G k l ) in G' is identical to the existence of G k in G. That is, we can use the algorithm to detect the existence of G k in G in a polynomial time of T k plus an added preprocessing time.
By the above preprocessing, and detecting sequentially for k = {1 … |V |} until the answer is false, we can find a clique of maximum size in time of which is a polynomial. This is a contradiction since the clique problem is known to be NP.
However, this result is not as bleak as it seems. The above proof is based on the assumption that the number of open terms k, and the number of points n, n H k, against which these open terms are matched are unbounded. In fact, the proof relies on the fact that n and k be as large as possible. Typically, n and k are bounded-we can employ a variant of the subgraph isomorphism algorithm, which, using brute-force comparison, in the worst case requires O(n k ) time. However, as n grows indefinitely large subgraph isomorphism too tends to be exponential in time.
In reality the open terms are topologically (and geometrically) dependent on the fixed terms. Matching can be resolved by following procedure. We first match the subshape constructed from the fixed points. This yields a mapping between a spanning forest of the fixed points and corresponding points in the given shape, where two points are adjacent whenever there is a line in the shape between them. Next, the open terms are resolved by depth-first search to grow this spanning forest. Implicit in this two-step matching process is a tree isomorphism test, which, if successful, is followed by a graph isomorphism check in the form of a simpler test for subshape relationship (Krishnamurti and Stouffs, 2004). We leave the details to the reader.
On the other hand, there are subshape situations which do require exponential time. As a concrete example, consider a shape with 2n points such that it contains no n-sided polygon. It is possible to construct such a polygon quite easily. Let the points be numbered 1, 2, …, 2n. Construct lines pairwise among points i, i + 1, …, i + (n -2) mod 2n and ensure that i and i + (n -1) are not connected by a line. Then, for any sequence of n points it will not contain a line between, at least, one pair of points. That is, there are no n-gons in this polygon. However, determining that the shape does not contain an n-gon will require looking at n 2 ǹ j possible candidates, which requires O(2 n ) time.
The above example illustrates a situation where there are no matching subshapes. We have yet to find an example where a matching subshape exists but which requires exponential time to determine, although if the above example was reconstructed so that there was a single n-sided polygon, it is possible that it may still require O(2 n ) time to determine the subshape. (3) Taken altogether, we can conclude that PSR is NP in terms of the number of open terms. That is, in general, it is unlikely that there is a polynomial algorithm for PSR for two-dimensional rectilinear shapes. From this, we know formally that the problem of implementing a parametric shape grammar interpreter is NP, as PSR is a necessary step.
(3) It is possible that we may not be able to construct just one single n-sided polygon within this configuration.
Thus, it follows that some practical shape grammars are likely to be intractable. It is therefore important to know the factors that influence shape grammar tractability. In doing so, we would be in a position to manage and control the design of shape grammars to avoid these possible intractable situations.

Factors influencing tractability
The following analysis is built on top of the unified definition for shape grammars so that the results are as general as possible; that is, the factors influencing tractability are applicable to a variety of different types of shape grammars.
For practical shape grammars, tractability is determined by shape-rule application. By definition, application of a shape rule involves operations of t, -, +, G, and R on elementary objects. If any of these operations takes superpolynomial time, then the shape-rule application becomes intractable. In common design practice the complexity of these operations may seem trivial, since the operations are not difficult to specify for rectilinear shapes. As shown by Stouffs and Krishnamurti (1993), the asymptotic upper bounds of comparing two coequal spatial elements in d-dimensional space, 0 G d G 3, is a polynomial in the maximum boundary element size n. In particular, when d = 0 or 1, the upper bound is a constant; for However, for certain types of shape objects, some of these operations can be difficult, even intractable. An example is the Boolean operation on two solids with rational curved surfaces, which involves finding the intersection of two rational surfaces. The intersection of two smooth surfaces is one of the following: (1) empty; (2) a collection of points; (3) a collection of smooth curves; (4) a collection of smooth surfaces; or, (5) any combination of (2), (3), and (4) (Barnhill et al, 1987). Traditionally, analytical approaches by variable elimination have been the means of solving this type of intersection problem. However, the degree of the resulting polynomial can be too high to solve. For instance, two generic bicubic patches can intersect in a curve of degree 324. Moreover, it has been shown that the intersection curves cannot be represented exactly by parametric equations even of degree 324 (Katz and Sederberg, 1988). Therefore, numerical methods have to be used and only curves under certain approximations are obtained. Although surface-to-surface intersection is still an active area of research (Hur et al, 2009;Patrikalakis et al, 2004) there are no good, general solvers for solving systems of multivariate polynomial equations, the equivalent problem to surface-to-surface intersection (Press et al, 2007).
The implication of this is that one cannot arbitrarily expand the scope of shapes. Basic operations of certain shape elements can become so complicated as to make them intractable. As a guideline, in order to design tractable shape grammars, the basic operations of the allowable elementary objects are required to take polynomial time. In the following discussion, we assume that this is the case.
The application of a shape rule u " v to configuration c involves two steps: searching the configuration c for applicable regions according to the left-hand side u, and rewriting the configuration with the right-hand side v. Rewriting a configuration involves two steps: subtracting (-) the left-hand shape under a known t, and adding (+) the right-hand shape under the same t. By our previous assumption, the operations of −, +, t, and R for each allowable elementary object are in polynomial time. As there is a fixed number of elementary objects involved, the overall time complexity of rewriting still has an upper bound in polynomial time. It should be noted that the algorithm here is brute force, given simply for the purpose of deriving a polynomial upper bound-seeking efficient, uniform algorithms for rewriting is still valid research (Jowers, 2006;Stouffs, 1994). In our discussion, however, rewriting is 'easier' in the sense that there is always a brute-force polynomial algorithm.
On the other hand, searching a configuration for possible rule applications can be much 'harder'. In effect, the searching procedure includes two steps: using certain criteria to identify possible matching candidates, and then verifying the exact matching of each candidate under all allowable t. Even with the optimal searching criteria, the number of matching candidates can be superpolynomial. This is exactly the case for PSR over two-dimensional rectilinear shapes; the number of candidates increases exponentially as the number of open terms increases.
In the verification step for exact matching of a candidate, it is possible that there are infinitely many t's, which are impossible to compute in finite time. For example, for the candidate shape found in figure 8 (marked with a dashed circle), the possible transformations, up to scale, are indefinitely many. This phenomenon is known in the literature as indeterminacy, and viewed as an advantage where unexpected variations can be introduced (Stiny, 1991). However, it is hard for a computer implementation to appreciate this advantage. The basic question then is: which is the best way to choose one or a subset of possible candidates from infinitely many? Random choice provides a solution, but relying upon randomness to create novel designs is probably not always a good idea. Manual selection is another option, although this is counter to the goal of a computer implementation. What is certain is that it is impossible to elaborate all the indefinitely many possibilities; we have to assume that the grammar designer specifies a way of selecting a finite subset so that the implementation is tractable.
To sum up, there are three factors which influence tractability of a shape grammar: (i) computational complexity of the basic operations t, -, +, G, and R; (ii) number of matching candidates; (iii) indeterminacy-number of possible ts for each matching candidate.
Factor (i) is the most controllable in terms of computer implementation by ensuring that the system only supports basic elementary objects for which there are efficient algorithms (at most polynomial-time complexity) for these operations. Factor (ii) probably influences certain extreme cases. In general, the number of open terms in parametric shape rules is usually small enough for their time complexity to be relatively inexpensive, thereby making shape recognition still tractable. Factor (iii) is somewhat controllable. As Stiny (1991) remarks, detailed conditions for indeterminacy are more complicated and vary from algebra to algebra and from dimension to dimension; Cartesian products are recommended as a useful way to avoid indeterminacy in general. However, in practice, chances for indeterminacy are much less. Shape grammars are seldom designed purely on the basis of geometry-typically, they are imbued with semantics in the form of labeled points or elements. The semantics are usually sufficiently rich to permit only a limited number of possible transformations.

Computation-friendly shape grammars
The existence of both tractable and intractable shape grammars, together with other computation difficulties mentioned at the beginning of this paper, negates the possibility of a single general shape grammar interpreter. As is shown in (Yue, 2009), characteristics of tractable shape grammars can vary significantly. In response, a paradigm for practical, 'general', shape grammar interpretation is proposed in a sequel (Yue and Krishnamurti, 2013), and shape grammars following such a paradigm can be said to be computation friendly-that is, tractable with polynomial-time and language-space complexity.