Parallel and sequential specification of a context sensitive language for straight lines on grids

Parallel and sequential specification of a context sensitive language for straight lines on grids

e()MPUTI~P~ alt.(PHICS ANt, I~.iAGF, I'Rt)CESSlNG 5, 106-12,i (197(0 Parallel and Sequential Specification of a Context Sensitive Language for Strai...

1MB Sizes 0 Downloads 11 Views

e()MPUTI~P~ alt.(PHICS ANt, I~.iAGF, I'Rt)CESSlNG 5,

106-12,i (197(0

Parallel and Sequential Specification of a Context Sensitive Language for Straight Lines on Grids ffEI~OME ~OTI~STEIN The Ohio ~tate University, Department of Computer and Information Se,ience, 202~ Nell Avenue, Columbus, Ohio ~8210 AND

CARL

WEIMAN*

Compuler Science Department, Courant Institute of Malhcmalical Sciences, 251 Mercer Street, New Yor]~ UniverMty, New York, New York 10012 Communicated by H. Freeman

Received May 28, 1975 A contexl;sensitive bmguage over {0, 1} + is described whose wm'ds represent straight lhles in the plane. Varimm generation and recognition algorithms for it are described. Afnne tram~formations correspond to simple string rewriting algorithms. Motiw~ting geometrical and number-theoretical aspects of linear geometry leading to the codes are indicated. The results are of interest for pattern recognition, computer graphics, paralh:l computation, and nenral ne~ theory. 1. INTRODUCTION A language consisting of binary code strings for straight lines ell the quadratic lattice is described. Parallel recognition algorithms for the hmguage are embodied in the design of a p o l y a u t o m a t o n ~ which recognizes straight lines. Mathematical properties of the code related to the geometry of numbers, affine transformations, Farey series, and continued fractions are described in [-20]. Here, only enough will be presented to characterize the code as a formal language over {0, 1} +. A set of M a r k o v algorithms, a recursive system, a context sensitive grammar, and a T O L system are given as alternative ways of generating the language. String rewriting rules, a linear bounded a u t o m a t o n (LBA), and a polyautomaton are given as alternative ways of recognizing it. Each code string is a description of the p a t h a line takes across lattice squares. A different code for such paths based on tracing a chain of m i n i m u m length * Research carried ou~ for Ph.D. Dissertation supervised by the senior author at Ohio State University under NSF Grant No. 534.l and a faculty developmen~ research grant from Denison University, Granville, Ohio, 1973. 1Coined by Smith FIS~ to describe generalizations of cellular automata. 106 Copyright ~ 1976 by Academic I)ress, Inc. All rights of reproduetlon in any form reserved.

CELL

CHAIN

CODE

FOR, LINES

0N

GRIDS

i07

vectors connecting the lattice points closest to the line has been given by Freeman [8] and studied by him and others in a variety of applications. Arithmetic algorithms for finding such paths when the slope of the line is given have been described by Stockton [lg] and Bresenham [8] and applied in computer graphics to drive incremental plotters. Their algorithms are based on the equation of a line in Cartesian coordinates, a fonuulation which underlies Feder's -proof [-7] that the equivalent set of chains of lattice cells crossed by straight lines constitutes a context sensitive language. The essence of his proof is that a lineal" relation between x and y coordinates requires for verification a computation space linearly related to the distance between points along the line, ergo LBA. Our recognition methods do not use algebraic-numerical computations, but rather invarianoe of the pattern class under a group of geometric transformations which can be expressed as simple code string rewriting rules. As a result, our LBA is much simpler. Embodying the rules in polyautomata designs suggests the construction of fast, parallel computers for recognizing straight lines and other patterns. A paper by Brons [4] covering some related properties of the chain encoding scheme devised by Freeman ['8] appeared after our research was completed. A crucial difference between that code and ours is that for any given line, respective periods of the two codes are out of phrase. The cyclic permutation 6f one which yields the other depends on line slope in a complicated manner, scrambling and obscuring potentially corresponding properties. The properties of our code relating to Farcy series and continued fractions appeared in [20~. An important departure in our study is the direct link between the code, affine transformations, and continued fractions with negative remainders. It greatly simplifies description of code structure, permitting straightforward construction of classical formal language recognition and generation schemes and the generalization to polyautomata designs. This structure can be exploited in the design of algorithms for generating, translGing, rotating, and affinely transforming straight lines on rasters without using matrix operations or even multiplication. The results, of obvious interest in computer graphics, will appear in a forthcoming paper. Motivation for the initial study was not computer graphics but pattern recognition. The original problem was to recognize a simple but interesting class by using local interactions of automata operating in parallel. Using simple identical automata iterated one per grid ceil, fast recognition of straight lines was accomplished; scanning and analytic geometric calculations were avoided entirely. Straight lines were chosen because they are the simplest nontrivial elements in Euclidean geometry; points are too simple because only a single detector, rather than relations between several, is involved in recognition. Straight lines correspond to the simplest functions in analytic geometry. They are central to geometric optics and Newtonian mechanics, two fields of paramount importance in the world of visual experience. Since any pattern consisting of curves can be approximated to any desired accuracy by line segments, the door is open to generalization. Furthermore, biological evidence indicates that line detection is important in vision in many higher animals. The design

108

ROTHSTEIN AND WEIMAN

of devices consisting of ~terated simple machines operating in parallel to recognize straight lines might suggest models for neurophysiological mechanisms with the same capability. 2. C O D E

DEFINITION

AND

ELEIVIENTAI{Y P R O P E R T I E S

A straight line crossing a square cuts either a pair of parallel (opposite) or a pair of perpendicular (adjacent) sides. A vertex can be assigned by convention to a side consistent with the preceding observation. In the first case three cells in a row are crossed by the line, while in the second, three cells forming an L-bend are crossed. A binary code in which these two possibilities are denoted by 0 and 1, say, needs additional bits per digit to describe the courses of general curves relative to a ruled Cartesian coordinate system, but for a n y straight line this directional information is constant, corresponding to line slope octant.

Referring now to Fig. 1, the octants of the plane are defined as the eight wedges bounded by the lines x = =t=y, x -- 0, and y = 0. They are labeled in counterclockwise order with Roman numerals, starting immediately above the positive x-axis. We now formalize the code definition for Octant I, in terms of which practically all of the discussion in this paper is given. This apparent limitation is shown not to be real by providing a simple method to translate any result to any octant. DB~INI~mN 1. Trace a ray starting at the origin in 0 c t a n t I, writing a 0 each time it crosses a cell through opposite sides and I each time it crosses an ad-

:II[ •

\ 2Z y=O I

\\

/

\

/

/

./

\ \

el "/

\

5E FIe. 1. Code definitionand octant symmetries.

Vg

CELL

CI-IAIN CODE

F01~, LINES ON (}I{IDS

109

jacent pair 2 of cells through perpendicular sides. Lattic;e points belong to the cells immediately above and to their left. Since reflecting the lattice about any of the wedge boundaries leaves it unchanged, the code of a line in Octant I subjected to such reflections is also unchanged, provided the assignment of lattice points to cells is similarly reflected. Thus, the code of a line is also the code of its kaleidoscopic images in all oetants. Figure 1 illustrates these images, the bold arrows pointing to the (;ells to which lattice points at their tails are assigned. These conventions entail the following properties for the codes. (i) The first digit of the code of a ray in any oetant starting from the origin is 0. Since the grid horizontals, which determine the position of l's in the code, cut a straight line into equal segments, the distribution of l's in its code is as homogeneous as possible. More precisely, defining a segment of code as a substring not preceded by 0 and consisting of consecutive 0's and the 1 following, the lengths of any two segments of a straight line code cannot differ by more {;hun 1. This property is hereafter referred to as the segment length constraint. The ray along y = rex, where m = p/q, a rational number expressed as the ratio of mutually prime integers, is periodic. The length of the period is q digits, prr p of which are 1% Conversely, if the code of a ray is periodic, the slope is rational. Figure 1 illustrates the first period of the code of the ray y = (~)x, x >i 0, and shows that in general, the ray of slope p / q passes through those and only those lattice points whose coordinates are (]~q, lop) lc = O, 1, 2, . . . . (2) C(msider an n • ?~ square lattice whose origin is the lower left corner (hereafter called a grid or n • n grid), and the Octant I rays on it. They cover the half of the grid beneath the line y = x and their codes all have n digits. All the rays in a wedge containing no lattice points and bounded by rays p,~ssing through lattice points have the same code as the boundary ray of lower slope. Hereafter the lower boundary, but not the upper, is to be considered part of the wedge. The boundaries (called grid rays) are precisely the rays of rational slopes p/q, 0 ~ p ~ q, q ~ n. These slopes, in increasing order, constitute the Farey series of order n [10~, namely,

0/1, 1/n, . . . , p / q , . . . ,

(n - 1)/n, 1/1

(the rational numbers in reduced form from 0 to 1, with no denominator exceeding n). This 1-to-1 correspondence between distinct codes and all terms but t h e last of the Farcy series of order equal to the grid size is of interest for number theory, geometry of numbers, theory of approximation, and parallel computation, among other things. Increasing grid size to (n + 1) X (n + 1) simply adds a digit to previous codes (part of a repetition of their periods for previous grid rays) and splits previous wedges by the interpolation of new grid rays (slopes p / ( n + 1), p < (n -t- 1), and p relatively prime to n + 1). This increased "resolving power," with no price ever paid in correcting earlier , Since such L-bend cells always occur in pairs, redundancy is avoided by using a single digit. This also leads ~o a much clearer interpretation of code properties in terms of the geometry of lines on grids, as shown in later paragraphs.

llO

I~OTHSTEIN

AND WEIMAN

code digits, mirrors the well-known optimal rational approximation to real numbers for bounded denominator possessed by Farey series described in [10]. (3) R a y codes on a grid can be interpreted as Base 2 integers or Base 2 decimals, the latter being generally more useful. With either interpretation, the corresponding number increases monotonically ~dth slope. The latter gives a bicontinuous i-to-1 mapping between the reals in the half-open interval Ell, 1) and the ray codes expressed as infinite binary decimals, where periodic codes correspond to the rational slopes and decimals. If a grid ray is arbitrarily translated in the plane and a new code generated starting from the translated origin of the ray, the new code has the same period, but the digits of each period are now cyclically permuted with respect to the old. The corresponding possible period q decimals are a set with q members, the smallest of which corresponds to the original ray code which started at (0, 0). It is infelicitous that for slope 1 the code decimal number converges to 89for the standard position (starting at the origin), but to 1 otherwise. Attempts to change t h e convention so as to avoid the initial 0 and thus make it always converge to 1 do either equivalent mischief to slope 0 or worse mischief elsewhere. It m a y be lmavoidable, being the ineliminable upper-wedge boundary (discontinuity occurs in the code dechnal for arbitrarily small changes in slope), showing up in t h e Farey series in the fact that while (.~ - 1) and ~ are always relatively prime, r~ and ~ never are, even though n can go to infinity. (4) In 0 c t a n t I, codes can be generated and slopes calculated b y the following rule. If the ray crosses no horizontal lattice line (g = integer) b e t w e e n crossings of two successive vertical lattice lines (.z = j and .z = j + 1), write 0 for the j t h digit, otherwise 1. The slope is the number of l's divided b y the number of digits in a period for a rational ray, and approximated by t h e same ratio (with period replaced b y total number of digits) otherwise. Though this is quicker for writing code than Definition 1, it often "translates" to other octants in error-prone ways through careless handling of up, down, left, right, horizontal, vertical, and assignment of lattice points to ceils. There is also a probIem, on changing octants, with the proper sign of the slope and deciding whether one should take the reciprocal rather than the slope as calculated for Octant I. A solution to all these problems is to consider the 0 a n d 1 of Definition 1 as being an ordered pair of generic binary symbols [-0, 1], which become specific special ordered pairs in the various octants. For example, Octants I and IV differ by the substitution of - z for x, which we express b y I: [0, 1 ] - - . (0, 1); IV: [0, 1 ] - + (0, 1). In 0ctant II, z and y h a v e been interchanged: II: [0, 1] --+ (1, 0). When a I or Y appears as the first component of a pair, the geometric slope is the reciprocal of the "kaleidoscopic" slope as calculated for Octant I. The presence of each bar over a component multiplies that kaleidoscopic slope by --1. Table I lists the ordered pairs for all eight octants together with the various kinds of slope information. The column headed "value" gives the actual geometric slope of all kaleidoscopic images of an Octant I ray of slope m; the quadrant column indicates to which quadrants the various octants belong and checks the slope signs (tangent and cotangent positive in I and III, negative in II and IV).

CELL

CHAIN

Tnt!e

oc~an~

CODE

FOR

LINES

,rode con'ention~

i.

GItIDS

ON

for all oetants.

[0,I]

kal. slope

geom. slope

I

(O,l)

!/o

i/0

m

II

(i,0)

o/1

1/c

:t/s

(i,~)

0"/i

-gll

-lira

i/~

~Ii

-m

v

(U,I) (U,T)

YIU

YIU

m

Vl

(Y,~)

U/Y

:~/m

VII

(Y,O)

o/Y "TI~

'~/g 0/i-

-i/m

OlY.

-m

i!z

IV

3. RECOGNITION

IIi

OF 8TilAIGHT

value

LINE

quadrant

i

II

ITI

IV

CODES

Recognition of a straight line to the limits of grid resolution constitutes answering the question "Does the code string correspond to a set of grid cells identical to those that could be crossed by a single straight line segment?" F r o m the earlier discussion it suffices to ask the question for one period 3 of the string in question, cyclically permuted to yield its minimum binary value (henceforth referred to as a period in standard form; it can be taken as the first period of its generic ray code). Our

recognition strategy

consists of applying

transformations

to a code

period which are interpretable as geometric transformations mapping lines into lines biuniquely. They are so chosen that any straight line period is ultim a t e l y reduced to a single digit. As the latter represents a straight line, so does the original code. The reduction algorithm cannot be completed if the original string is incompatible with a straight line. More specifically, a subgroup of the affine transfonuations with fixed origin is used. The generator matrices are S = They

are unimodular,

:)

and

C =

(: :)

.

and can be interpreted either' as a relabeling of the lattice

points or as transformations on geometric objects leaving lattice points fixed. Using the latter interpretation, postmultiplication of the row coordinates of t h e points of these objects by these matrices gives the new coordinates of those points. Wedges are mapped into wedges, as arc their codes. The application of S deletes 0 from each code segment and C complements each digit of t h e code except for the initial 0 and the final 1. The product S~CSC, where s is the number of O's in short segments of the code, yields the same result as replacing each long segment by 0 and each short segment by 1. The res~flting code corresponds to a line whose slope is the comple.menl (with respect to 1) of the remainder of the quotient of q by p. Repeating this code reduction proa One period of a finite string b~ ... b~ is defned as the substrh:g be ... bk-~ (0 < /~ ~ n), where n is the least integer such that b] = b] rood (/~),j = 0. . . . , n.

ROTHSTEIN

112

AND

WEIMAN

3 001

Ol

--'-

"-~

0

1

1

Ol ~-~ .

.

7

'-'-"

.

.

3--1

1

0

2--I

1

2 0

(a) CCFI~ 3

1

001

O1

O1 ~ . . . .

1

0

0

7

2 + 1

0 (b) CFR Fro. 2. Code reduction and e,ontinued fractions.

Table ~I. Symbol a ~ e ~

Turing machi~e code stz,ing recognizer,

0 , ,

! 'v

qo

0qlg

lqlL

BqoL

CqoL

ql

0q2L

lq2L

BqI3H

CqlL

q2

0q2L

lq2L

Bq3~

r'q2t'~7

q3

0q3R

I%~

Bql~

Cq3R

q4

0q3R

lqsR

Bq5L

Cq4R

q5

lq6L

Bq?R

CqsL

q~

0qsL ...... C~L.~

--

BqI4H

Cq6L

q7

0q?R

lqTR

Bq0L

CqTR

q8

0qsR

lqSR

BqgL

CqsR

~9

0ql0L

lqgL

Bql4H

CqgL

kl glO

0ql411

Iq9L

BqllR

CqloL

(i- %1

~%2R

l%la

~%L

~%IR

~12

--

CqiIR

5q0L

Cqi2 R

,

B

C

I k

Zl

iII

/ IV

u

ql3

ACCEPT

ql~

R E J I.s,! T

CELL CHAIN CODE FOg LINES ON GRIDS

113

cedure corresponds to expanding the continued fraction of the original slope using negative remainders. The process is therefore called CCFR for complemented continued fraction reduction. Ordinary (positive remainder) continued fractions are discussed in [,10]; CCF's are more closely related to semiregular continued fractions discussed b y Hurwitz [12], Barnes [-1], and Blan,ksby [-2], CCF properties relevant to the code presented here are discussed in [--20]. As each step of CCFR shortens the code, repeated applications eventually yield a single digit if and only if the original code corresponds to a straight line. If it does not, the segment length constraint is violated at some stage of CCFR; the algorithm is then undefined. Figure 2a illustrates CCFI~ and its associated continued fraction for p/q = 3/7. Note that interchanging the roles of long and short segments in rewriting steps yields another reduction based on the ordinary continued fraction (Fig. 2b). We abandon this C F R in favor of CCFlt because the latter reveals code properties related to the geometry of lines in a more natural way. Among CCF properties not shared b y CF's are that successive eonvergents increase monotonically

and

no intermediate

convergents

are skipped.

Also, the CCF

facilitates discussion of the effects of translation and rotation on a code and can be used to generate codes without explicit reference to geometry [-20]. CCFK can be expressed sequentially by specifying a Turing N[achine (The) which replaces long segments by O's and short segments by l's and checks the segment length constraint. Violation of the latter constitutes rejection, and reduction ~o a single digit, ~ acceptance of the string as being the code of a straight line in standard form. One approach is to delete O's from segments until each long segment consists of 01 and each short segment is 1. Next, delete erich 1 following a 0. Repeat these two processes until a single digit is left or the segment length constraint is violated. Table II is a list of quintuples characterizing the behavior of such a TM. Designs with fewer states and/or faster operation are possible. The TM here starts in state q0 on any tape square with only blar~ks (B's in Table II) to the right. The nonblank part of the tape consists of a string from {0, 1}% Deletion of any symbol by the T3J[ consists of replacing that symbol by C. Halting in states ql8 or qi4 constitutes acceptance or rejection, respectively. Each Roman numeral indicates a set of quintuples whose combined function is to carry out the task similarly labeled in the flowchart (Fig. 3) and described in the preceding paragraph. Since this Th{ never writes on tape cells except for those on wl~ich the original string appeared, it constitutes a linear bounded automaton (LBA). 4. FO1tl~likL GENEIs OF STIIAIGI-IT LINE CODES, AND PII00F THAT THEY CONSTITUTE A CONTEXT SENSITIVE LANGUAGE

To generate straight line codes we reverse the CCFR, in effect. There is a 1-to-1 correspondence between rationals p/q, 0 < p/q < 1, and the finite sequences of integers sl, ..., s~ which constitute the entries of their CCF represen4The sering i, though i~ol~wit,hin the octatl~, is the codeof the line y = x on its upper boundary.

R.OTHSTEIN AND WEIMAN

114

Accepl

dig~t P

Delele

each 0

ndjncent Io

precedinq n 1

yes

DeIete

~'xany

each 'I tOIIc3wmg a

o

E~s "

141..~_~/"adjocenlio

I N

o',,?

F~o. 3. Code string recogllition flowehm't. rations (all st ~> 1, j = 1, 2, . . . , N) : v/q

=

1 81

82"

8N

Use t h e notation Fsl, . . . , s~'l to represent this C C F and associate a code with it as follows. The code for [-s~q is 0'N-t1. The code change induced b y the ~ransition from rsN-~+l, sN_~+2,..., s~] to [s~_~,..., S~r-] is the single application of t h e following rewriting rules to each digit. 0 --+ 0'N-~-11.,

:1. ---', O " ' v - ; - ~ l .

(;ELL CHAIN CODE FOR LINES ON GRIDS

115

T h e final code associated with F s l , . . . , sN] is precisely that of the ray of slope p / q . I t is convenient to devise a set of Marker algorithms [15] for the preceding code construction process. We introduce an a process and a # process, with a word in {a, fl}* then defining a particular order of successive performance of the indicated processes on any valid straight line code string. The effect of ~ is to increase the number of O's in each segment by one. It replaces each 1 by 0I, leaving the O's unchanged. The effect of fl is to repIace each digit of the original string by a minimal segment (l's unchanged, each 0 replaced by 01). In terms of ~ and # the preceding transition rule from the code of Fs~_~+l, . . . , sN] to that of FsN_~, . . . , sN] is expressed by #a,N-~-2. Marker algorithms for a and fl processes are given in Table III, where a and # are now marker symbols. A T e L system (see [17] for definition and notation) whose two tables correspond to the ~ and # processes, respectively, is given by ({0, 1},0, {{0-~0, Z--01}, {0-~01, i - ~ i}}), where the triplet consists of alphabet, axiom (start symbol), and production tables in that order. All productions in a single table are to be applied simultaneously to all symbols in a string. Since it was shown earlier that the codes can be recognized by an LBA, it need only be shown that the set of codes is not context-free in order to establish context sensitivity. It is known that characteristic constants g and h exist for every context-free language such that every string z in the language of length gre~lter than g (;an be written as a concatenation of substrings of the form u v w x y , where the length of v w x is less than h, vx is not empty, and all strings uv~wz~y, i a n y integer, are in the language [-11]. We show that no such h exists for the set of codes. Note that the codes corresponding to ['si, s.~], i.e., p / f f = s2/(sls2 - 1), can be exhibited as 00...100. sl

9 ,1,

sl

, ,00.

...

9 .10.

sl

9 .1

s~-i

segment lengths.

82 T a k e s2, which is unrestricted, large enough to make the word length exceed g. TABLE III Elementary Marker Algorithmfor Code Generation =-Proces,~

~-Process

(i) ~A -~ .~

(1) #~ -~ .A

(2) ~I ~ oi~

(2) #o - , 01#

(3) s0 -~ 0~ (4) h --~ ,x

(3) # i -~ i # (4) A --~ fl

R O T H S T E I N AND WEIMAN

116 Table

IV.

ConZext

sensitive

:enerative

~amma~

a-prod~ctions

8-productions

"I 0 I

for' c o d e s .

i

S

l ! ZoZoZI

I

f

t

S + I i

Z!21 § Z!XoX 1

i

S ~ ZoZIZ 1 w

i

t

ZoZ ! + YoYIZl

ZoZ 0 ~ YoYIZo

ZoZoX 0 § Z oXoXo

YIZIZo § YIYIZo

YIZIZI ~ YiYiZ1

ZoZIX 0 § ZoXoXzX 0

ZIZoX o + ZIXoX 0

YIZoZo + YIYoYIZ 0

YIZIZI ~ YIYIZI

ZoZIX 0 -~ Z 'oXoXIX 0

Z'oX0 § XoX 0

YIZoZI + YIYoYIZ l

YIZI -~ YIYI

ZoZ 1 § Z oXoXI

t

t ZflZOX 0

§ ZoXoX 0

t

i

il ZIZIX 0

~

T

YIZoZ1 § YIYoYIZ1

ZIXoXIX 0 I

XoXoZ 0 + XoZoZ o

XoX i

XoXoZ 1 § XOZOZ 1

XoXoZ 1

XuZ 1

ZIYIY 1 § ZIZIYI

YoYI ~ ZoY1

XoZoZ ~

ZOYIY1 + ZoZIY 1

ZoYI~ 0 ~ ZoZIY 0 ZoYIY 1 § ZoZlYI

i

t

,

Ill

XoXIZ 0 § XoZIZ 0 XIXoZ O -~ XIZoZ o

XIXoZ ~

XIZoZ 1

ziYoq

X'oXoZ o

XoZoZ 0

ZIYIYo ~ ZIZIY 0

ZoYIYI ~ ZoZIY 1

ZoYIY 0 + ZoZIY O

ZIYIY 1 * ZIZIYI

§ zlz~q

f

T

XIXGZ 1 § X1ZoZ l

X'oXoZ l

XoZoZ I

X'oZ 0

t

ZoZ 0

ZO§ 0

~V

t

f

T

S -* O1

Z1 § 1 ZI~i

Z'o+O

Clearly, if the language were context-free, the only possible choices for v and x would be concatenations of some finite numbers of segments of lengths sl and sl - 1, by the segment length constraint. But there is no restriction on sl; in particular, s~ can be chosen larger than any constant h, when the length of v w x exceeds h, violating the theorem. Table IV is the set of production P of a context sensitive grammar G = ({X0, XI, Xo', XI', Yo, Y1, Y0', Y~', Zo, Z1, Z0', Z~', S}, {0, 1}, P, S) (see FllJ for notation) for the language of straight line codes, equivalent to finite sequences of applications of the Marker algorithms. The productions are grouped to illustrate the connection; those on the left do the work of the a process, those on the right that of the ~ process. The subscripts of nonterminals match the terminal symbols into which they can convert. The productions in I initiate a derivation equivalent to that performed by an a or a ;9 process as indicated. Those in II carry it out to a stage where either the productions of I I I permit restoration of conditions in which those of II iterate another derivation process (which can be of either type) or those of IV, which terminate the derivation. This grammar yields strings which consist of one period of generic code in standard form. Codes of line segments with arbitrary endpoints can be found by substituting suitable specific octant digits, concatenating periods of code, and appropriately truncating the result. k reeursive definition of the set of code words {W} can be given in terms of an N-tuplet of any positive integers (si, s~, . . . , s~), which individually exceed unity. We define W(s~, ...,

s~) =

ET'Y(~I . . . .

, s~_D]"-~W(s~,

...,

8~_~ -

1),

CELL CHAIN CODE FOR LINES ON GRIDS

117

where the exponent indicates the number of concatenations of the word defined by the indicated (N - 1)-plet; it is further concatenated with a second (N 1)-plot. The base of the recursion is given by W(si) = 0~-~1. The slope of the line whose code is W(s~, . . . , sN) is p/q, where P/q = Fsl, . . . ,

s~7.

5. POLYAUTOIYIATON TO RECOGNIZE STRAIGHT LINES

The T e L system for code generation suggests a simple parallel process for recognition. Here we describe a polyautomaton consisting of identical finite state automata distributed one per grid cell. It recognizes any configuration of cells crossed by a straight ]ine segment of arbitrary slope, position, and length. Like the LBA, it executes one of several possible code reductions. Unlike the LBA, cells must determine code string digits and operate on them by communicating with nearest neighbors in two dimensions. Since all cells are simultaneously active, the computation is much more parallel than that of the LBA. Though different cells may be in different states at any time, it is important that the same process, e.g., determining code digits or shortening code segments, is being carried out throughout the grid at one time. This is accomplished by connecting all cells to a cell synchronizer (CS) which assures that all cell transitions occur simultaneously and according to the same state transition function. CS is a finite state automaton each of whose states determines a state transition function for all grid cells. CS transitions are determined b y messages it receives from the cells. The overall operation consists of an alternation of cell and CS state transitions. The former correspond to local neighborhood information processing on the grid and the latter to executive decisions controlling the former. The CS state transition graph and intuitive meanings of states are given in Figure 4. States S and F denoting success ~nd failure (accept and reject) are omitted for clarity. Sto~l) Validating nearest ~eighbcr configuratlons

Vertical runs exist, --checking L-bend compatibility

HoPizont~l l,un~ exi~tj ~ ~checklng L-bend compatibility

?

<'l,os~ingout a O f~'om each code segment (inverse a process)

~itlng dlgit~ in place of segments (inverse ~ process)

FIG. 4. CS st,a~e t~ransit,ion graph.

118

ROTHSTEIN AND WEIMAN )Pab

celI-CS

le V,

Interactions

f o r CS S t a t e N

Boolean 'CS S t a t e xpression Transition

N e a r e s t I Cell S t a t e Neighbors Transition

~o CS

L e s s than two A ) s

A ~ E

O0

/\

A ~ O

01

Z x Zy

N ~ F

~>~

A~

0

10

~xny

N + V

A

O0

A - A

ii

A~/A

asymmetri-

A

+

~

Straight line, n o runs Configurations con f l i e r

N ~S

x x y

~ 2 y

N

+

Grid Situation

A l l runs vortical !All runs horizontal

H

ca.ilZ More ~han two A ~ O

(o)

Cells

(b)

CS

For the follo~ingdetailed description refer to Tables V-VIII. Part (a) of each shows the cell transition function for a particular CS state. The left column gives upper, lower, left ~nd right nearest-neighbors' states betwe~n the eorreTable VI.

celI-cs s

for CS in States H or V.

For CS State H

~,~e~.~e=est \E /

For CS State V

To a~-Z~ t~earest --,~~176 .l~l o~"

'T TCell ..... ~'

\A/

9.o2< ' ~ E

A

A §

01

/"

0

A ~ i

Oi

A "C

0:

A-~ i

i(

A

l0

,
Cells

c~2~

x'~.,r~+Y~,~.y ~

I

H ~ S ~

arid ~ituation

bends

(b) cs

runs only

"

C

CELL

CHAIN

Table VII.

CODE

Cell-cS

Left Neighbor

FOIt LINES

Interaction

ON

119

for CS in S t a t e x.

Cell State Transition

0

GI%IDS

TO CS

0 ~ 0

01

1



00

1

1 ~ 2

i0

B

0 4C

00

B

14

E

0 +C

E

1 4

2

i0 O0 0(]

B

(a) Cells

Boolean ~xpression

CS State Transition

~T ~ F. y

X4X

~r x 7r ~

X -~ S

Z xZy

X~F

Z X ~[y

X +W

Grid Situation 0is remain. No l's are n e x t to l's N o 0's remain ~One 1 remains O's remain. A 1 is next to a 1 N o O's remain, a 1 i s next to a 1

(b) CS

spending arms or ghe symbol X. For example,

X/

means the left neighbor

A AB

is in state A and the right is in state B. Cells in state D are omitted for clarity. The state transition resulting from the given nearest-neighbor configuration Table VIII.

Cell-Ca

Neighbors

Interaction

for CS in S t a t e W To CS

Cell State Transition B

00

-> C

Dontt 140

01

241

i0

Care

(a) Cells

Boolean Expression

CS Shate Transition

Grid Situation

ZxZy

W k> X

O's and l's e x i s t

~ x ~

W + S

All digits All digits

(b) CS

are O's; are l's

120

I'0THSTEIN AND W]9IMAN

is shown in the middle column and the two-bit message sent to CS in the right column. ~ Part (b) of each table gives CS state transitions which are determined from the cell messages as follows. Referring to the two bits from the ith cell as xi and y~, Boolean expressions over the entire set of messages are evaluated. These expressions, in the ieft column of CS transition tables, are symmetric ~dth respect to subscript values, which are assumed to constitute the index range Of all the Boolean sums (2;) and products Or). All operations are Boolean and overbars mean complements. The CS transition occurs (middle column) t'or which the Boolean expression has the value 1. Boolean symmetry assures that CS responds to combinations of events on the grid independent of their locations or populations. Informal descriptions of these combinations are given in the rightmost colmnn. Initially, cells activated by the pattern to be recognized are in state A, and connect to CS which is in state N. All other cells are in state D (dead) and do not interact with CS. Refer now to Table V. Any A cell on the end of a chain has only one A neighbor. It converts to E, an end cell which needs special t r e a t m e n t in later processing since information about a possible second-nearest neighbor is missing. An A with two symmetrically located nearest neighbors (a "run") converts to 0 (the corresponding generic code digit) sending messages to CS corresponding to the orientation (01 for horizontal, 10 for vertical) of those neighbors. An A ~dth asymmetrically located neighbors (a "bend") is not changed; such cells will be processed as generic code l's in the next time step. A n y pattern with cells having more than two excited neighbors cannot be a straight line; such cells send 11 to CS. CS responds %o any incompatibilities (presence of l's in both x and y digits) by going into state F, a terminal fail state, rejecting the pattern. If no incompatibilities and no code O's exist, the pattern is either all end cells (E) or has only two-neighbor cells corresponding to generic l's of the code. Either situation (all message digits 00) must be a straight line configuration so CS goes into state S, a terminal success state, accepting the pattern. If none of the above CS transitions occurred, either vertical or horizontal 0-type cells were found, hut not both. CS responds by going into state u or H, respectively. In Table VI, cells corresponding to generic code digit 1 are checked for octant compatibility and assigned states corresponding to their generic code digits. The transitions to state C assure that only one member of each bend pair is assigned a code digit. Note that grid symmetry is expressed b y the following relations between tables corresponding to CS states H and V. :Reflecting the nearest-neighbor configt~rations of H about the line x = y yields those of V. Reflecting the nearest-neighbor configurations of transitions yielding message 01 about the axis parallel to 0-type orientation (i.e., x-axis for I-I, y-axis for V) yields t h e nearest-neighbor configurations for the transitions yielding message 10. Considerable compaction of tables could result from carrying the reflection information in an "octant bit" table, but we do not wish to further complicate the notation here. If no bend cells occurred, all cells must be in Any cell whose s~ate and neighbor's state are not shown rernai,ls in that state and sends 00 go OS. This avoids elut~ering tables wit,h "idle" transitions.

CELL CHAIN CODE FOR LINES ON GRIDS

121

state 0 or E, and the pattern is a straight line. CS goes into state S in this case. If 10 and 01 messages arrive at CS, incompatible bends occurred, and CS goes into state F. If only one of these two message types occurred, a mixture of l's and O's of generic code exist, and CCF reduction is attempted, starting in state X. They only patterns which could have survbed to state X are those in. which each cell has exactly two active nearest neighbors (except for the two cells in the ends with one nearest neighbor each). In such patterns (called chains) any cell in state C is to be considered "conducting"; i,e., its two nearest neighbors are considered nearest neighbors of each other. Thus, regarding states of cells in a chain as symbols in a string, erasure of a symbol corresponds to conversion to C. The inverse of the a process is accomplished in this manner in Table VII. Any 0 whose left 6 neighbor is 1 converts to C; this corresponds to deleting one 0 from each segment. Any 0 whose left neighbor is E acts the same way to assure t h a t in segments not terminated by 1 on the left, 0 is also erased. Any 1 whose left neighbor is E converts to ]3, a state which acts just like a 1 until the inverse fl process begins (described later). _Any 1 whose left neighbor is 1 converts to 2. If at the instant of this conversion there is still a cell in state 0, it must be in a code segment more than one digit longer than t h a t segment in which the 2 occurred. This violates the code segment length constraint, which CS recognizes as the simultaneous presence of 10 and 01 among its messages. It responds by going into state F. If no 10 messages arrive (i.e., no cells are in state 2) ~nd ~merased cells in state 0 exist, CS stays in state X and the inverse a process repeat s as described above. If all O's are erased and no cells are in state 2, there can only have been one code digit 1, and the pattern is accepted (i.e., CS goes into state S). The only other possibility is that segment lengths are compatible and all O's have been deleted. CS responds by going into state W, where the inverse fi process will be carried out. The conversion of B to C in Table VIII yields the same effect as converting i t to E; i.e., the right neighbor of the B sees an E as a left neighbor in any case. This result is necessary because it canno~ be known whether the 1 t h a t the B converted from in Table VII terminated a Iong or short segment. The other conversions in Table VIII correspond to rewriting segments as digits and are self-explanatory. If only one ldnd of code digit is present, CS recognizes the pattern as a straight line, going into state S. Otherwise, it returns to state X and attempts to carry out another inverse a process. The preceding polyautomaton has been generalized to recognize boundaries, topological connectivity, and polygonal approximation to general curves by straight line segments [-20]. Properties of the straight line code suggest parallel numerical computation capabilities based on continued fractions. Some principles in the design of this ldnd of polyautomaton have important practical consequences for the speed and complexity of algorithms for certain parallel computations. One of these principles is the use of conducting cells~ which If code O's correspond~o vertical runs, substitute the word "lower"for "left" Jn all the following discussion.

122

IIOTHSTEIN AND WEIMAN

could have been avoided b y using propagating states such as those used in yon Neumann's self-reproducing cellular automaton [5]. As longer stringa of such cells arise, most of the machine's time would be wasted in the trivial propagation of information that requires only one time ~tep using condLmting cells. A more important principle is ~he nature of the cell-CS interaction v i a the logic bus. I t permits a division of labor in which the cells process local information and the CS processes global information. This frees cells from the burden of keeping track of the states of distant neighbors and the time delays necessary for such communication which iterative automata suffer fl'om [18]. The logic bus information processing b y CS frees it from the exponential network and eomputationM complexity of pereeptrons and neural nets which nmst somehow account for large numbers of possible configurations. It is precisely this exponential complexity which is absorbed into the symmetric Boolean function. For k cells, the number of distinct sets of 7~ two-bit messages (indexed by cell location lc, for example) is 4 ~. The number of elements of this set distinguishable by the kind of symmetric Boolean function over lc used here is only 32, however (i.e., for any digit of the pairs only the threefold distinction between (1) all O's, (2) all 1%, and (3) O's and l's, can be made). The logic bus poses no engineering difficulties. It is realizable as a simple series-parallel switching network constructed by joining simple identical elements. 6. CONCLUDING DISCUSSION We close with a list of general observations, including some on the significance of the foregoing for a number of areas in computer and information science, and in mathematics, as well as related open questions and results wc hope to publish in due course. (1) The recognition algorithm exemplifies a pattern recognition technique in which unknown samples are viewed as transformed versions of a standard one. The standard somehow encapsulates distinguishing properties of the pattern. class, and acts as a template with which the unknown is compared. T h e recognition process systematically transforms the unknown until it either coincides with the standard or is shown to be not so transformable. Al~ernatively, the standard is transformed to coincide with the unknown or is shown to be not so transformable. The latter is often called "analysis by synthesis." If the transformations form a group, the two alternatives coincide, in substance, and naturally lead to the fusion of this pattern concept with that of Itlein's characterization of a geometry as the study of properties invariant under a transformation group. If intertransformable entities are regarded as equivalent, the equivalence class can be called a geometric object or ~ pattern class (i.e., a class of objects recognized as exemplifying the same pattern). While it is clear already that the line language of this paper easily generalizes to l i n e a r subspaces of a linear space, and the same may be true for the generalization from segments to polyhedra, it seems much more difficult to formalize a language of nonlinear objects. The chief difficulty seems to be connected with

CELL CHAIN CODE FOR LINES ON GRIDS

123

the dependence of the object's description, and the accuracy thereof, on its size relative to grid cell size. In continuous geometry, cell size can be taken ,.~s infinitesimal, b u t in the present context one appears to have all the difficulties of finite differences and approximation theory where error must be taken constantly into account. These awkward pieces, under iterated transformations, grow to where t h e y make the clean group-theoretical situation murky. The situation is reminiscent of error accumulation in numerical analysis, and how best to approach it is an open question. (2) Infinite periodic continued fractions converge to quadratic irrationals. The limit of the slope of a line prepared by following the algorithm of a periodic {~,/~}+-word, as word length increases without bound, is thus also a quadratic irrational. Aperiodic words converge to reals [-6, 14]. The code algorithms yield an interesting approach to approximating reals by rationals; rapid convergence and algorithmic simplicity may make them useful in numerical analysis. The senior author, while a student, discovered the codes originally by considering a related problem, specular reflection in a square box. The motivation was to understand ergodic theory, in statistical mechanics, hi a more intuitive manner via a simple example. The reflection points are dense over the box sides except for rational slopes, and path pieces between reflection, in order~ are congruent to line pieces in successive grid cells when a line of the same slope is drawn on the lattice. (3) The code algorithms are well adapted to parallel computation. If each grid cell represents a finite state automaton which "knows" whether it is crossed b y the line or not, and nearest neighbors can exchange information, then the code algorithms can be executed by them in a highly parallel fashion E20J. The grid becomes a model of a "retina," the cells "neurons," the line a "pattern of (visual) excitation," and the excited cells organize themselves into an ad hoe LBA to perform the recognition. Many lines can be handled at once. I t appears that this kind of cellular automaton can go far to make geometrical problems accessible to computers in a way that does justice to the topology without prohibitively long, and essentially extraneous, computation. Problems of finding solutions of differential equations, geodesics, and problems in the calculus of variations can be considered as generalizations of constructing line, given two points on it, or its slope and one point (bo~mdary value and initial value problems, respectively). Here the problems appear to be amenable to a parallel approach in the spirit of the codes. Problems of scale, unlike (1) above, do not seem to differ fundamentally from those met in elementary form with straight lines. I~EFERENCES 1. E. S. Barnes and It. P. F. Swinnerton-Dyer, The inhomogeneousminima of binary quadratic forms III, Acta Math. 92, 1954, 199-234. 2. P. E. Blanksby, A restflt for semi-regular continued fraci~ions, J. A~slral. Math. ~oc. 10, 1969, 145-154. 3. J. E. Bresenham, Algorithm for computer control of a digital plotter, IBM Systems J. 4, ] 965, 25-30.

124

KOTHSTEIN AND WEIMAN

4. R. Brons, Lin~listic methods for the da~cription of a straight line on a grid, Computer Graphics Image Processing 3, 1974, 48-62. 5. A. W. Burks, Essays on Celhdar Automata, pp. 3-52, University of Illinois Press, Chicago, 197U. 6. S. Drobot, Real Numbers, pp. 49-78, Prentice-Hall, Englewood Cliffs, N. J , 1964. 7. J. Feder, Languages of encoded line patterns, Tnformation and Control 13, 1968, 230-244. 8. H. Freeman, On the encoding of nrbitrary geometric configurations, I R E Trans. Computer8 lO, 1961, 260-268. 9. J. M. Glass, A criterion for the quantization of lh~e-drawing data, Technical Report No. 400-112, Department of Electrical Engineering, New York University (NTIS Document No. AD 637 497), 1965. 10. G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, Clarendon Press, Oxford, 1965. 11. J. E. Hopcroft and J. D. Ullman, Formal Languages and Their Relation to Automata, AddisonWesley, Reading, Mass., 1969. 12. A. Hurwitz, ~ b e r eine besondere Art der Kettenbruch-Entwicklung reeller Grossen, Acta Math. 12, 1889, 367-405. 13. B. W. Jordan, Jr., and R. C. Barter, A scan conversion algorithm with reduced storage require. ments, Appendix A, Commun. ACM 16, 1973, 676-681. 14. A. N. Khovans!di, The Applieatlor~ of Continued Fractions and Their Generalizations to Problems in Approximation Theory, Noordhoff~ Groningen, The Netherlands, ]963. 15. R. R. Korfhage, Logic and Algorithms, Wiley, New York, 1966. 16. M. Minsky and S. Papert, Perceptrons, MIT Press, Cambridge, IV[a~s., 1969. 17. A. Salomaa, Formal Languages, Academic Press, New York, 1973. 18. A. R. Smith, Introduction and stn'vey of polyautomata theory. Introduction to German translation of yon Neumann's Theory of Self-Reproducing Automata (A. W. Burks, ]~d.), Verlag Rogner and Bernhard GmbH., 5'[unieh, 1975. 19. F. G. Stock,on, Algorithm 162: xymove plotting, Comm~ln. ACM 5, 1963, 16]. 20. C. F. R. Weiman and J. Rottmtein, Pattern recognition by re~ina-like devices, Technical Report No. OSU-CISRC-TI~-72-8, Department of Computer and Information Science, Ohio State University (NTIS Document No. PB 214 665/2), 1972. 21. A. Rosenfeld, Digital s~raight line segments, IE.EE Tra~. Computers C-23, 1974, 1264.-1269.