Transcript
Page 1: The Shortest Way to Draw a Connected Picture

319

The Shortest Way to Draw a Connected Picture

Patrice Seebold* and Karine Slowinski‡

Abstract

With any word over the alphabet we asso- ciate a connected picture in the following manner: the read- ing of each letter of this word induces a unit line: respectively) stands for a right (left, up, down respectively) move. We present a rewriting system which can yield, from any word over all the words describing the same picture. Particularly, we give an algorithm to find a minimal word describing a given picture: this word represents the shortest way to draw this picture without ‘pen-up’ .

1. Introduction

result which can be helpful to improve the use of plotters, for example pen plotters, can be also useful in such domains as graph theory or pattern recognition. Moreover, it can be easily generalized to the case of any even number of moves (for example 8 or 16 as in some sophisticated plotters). This method can also be compared with the encoding established by Freeman1 to facilitate the process- ing of geometric configurations by means of a digital com- puter.

This approach (the description of pictures by words), which uses results and techniques from formal language theory (see Harrison2, or Salomaa3 ), was initiated by

All random plotters accept the general commands lower pen, raise pen, move one unit left (right) and move one unit up (down). If we restrict ourselves to the case of pictures drawn without raising the pen, it is possible to represent any sequence of commands move one unit left, right, up or down as a word over a four letter alphabet, each letter cod- ing for a unit move. We call such words picture words.

The aim of this paper is to study the set of all the pic- ture words describing a given picture (drawn without pen- up). However, these words are in general redundant since some segments are drawn several times: for example, the sequence ‘move one unit left, move one unit right, move one unit left’ corresponds to three drawings of the same segment; it can be replaced by the single command ‘move one unit left’ which has the same effect: the segment is drawn and the pen stays in the same position at the end of the drawing, Thus, it is possible to ‘improve’ the represen- tation of the sequence of moves associated with the draw- ing of a given picture and we present an algorithm to con- struct, from any picture word describing a given picture, a word of minimal length describing the same picture. This

*C.N.R.S. - U.A. 369, L.I.F.L. Université de Lille 1 59655 Villeneuve d’Ascq Cedex, France Present address: C.N.R.S. - LA 248, L.I.T.P. Université de Paris 7 2 Place Jussieu, 75251 Pans Cedex 05, France

‡C.N.R.S. - U.A. 369, L.I.F.L. Université de Lille 1 Cite‘ scientifique, Bât M3 59655 Villeneuve d’Ascq Cedex, France

This work was partially supported by the Programme de Re- cherche Coordonnée ‘Mathematiques et Informatique’ of the Ministere de la Recherche et de la Technologie.

Maurer, Rozenberg and Welz14. They established many results about different classes of picture languages and they in particular introduced the concept of ‘retreat’ which was studied by Hinz5 and is the starting point of our work. More precisely, we construct a rewriting system which can obtain, from a given word describing a picture, all the words describing the same picture and can find algorithm- icly a minimal word. Moreover, our results complete recent works. Gutbrod6, in particular, supplied a similar system which obtains all the words describing a same picture. However, his system has not the notion of a simple word and thus, does not realize an algorithm to find a minimal word. As for Brandenburg and Dassow7, they introduced a rewriting system able to reduce words but not to minimize them. Note that Brandenburg8 showed, using graph theory, that it is possible to compute a minimal word for a given picture in polynomial time (but he did not give any algo- rithm to achieve this).

Our results also remain true (and the same system can be used) if we increase the number of elementary moves in the plane and it seems they could stay available if we con- sider spaces with more than two dimensions.

This paper is organized as follows: after preliminaries and basic notions for the construction of picture languages, the first part is dedicated to the introduction of the rewriting system and the proof of the main results, the second part dealing with the notion of basic pictures. We conclude with some interesting open questions.

2. Preliminaries

We assume the reader to be familiar with basic formal language theory (see Harrison2 or Salomaa3), and we just recall several notations.

Let A be a finite set called an alphabet. The elements of A are letters and finite strings over A are words. A* is

North-Holland Computer Graphics Forum 10 (1991) 319-327

Page 2: The Shortest Way to Draw a Connected Picture

320 P. Seebold et al. / The Shortest Way to Draw a Connected Picture

the semi-group generated by A with the operation of concatenation (the neutral element is the empty word E).

For a word w over A denotes its length, i.e. the number of letters of this word (in particular, and, for any is the number of occurrences of the letter x within w. A word is a factor (left fac- tor respectively) of the word w E A* if there exists

respectively) and such that

Before giving formally the basic notions and definitions, we start with an informal description of the representation of pictures by words.

A picture word is a word over the alphabet (i.e. an element of The letter r stands for ‘move

one unit right’ and u stands for ‘move one unit u p ’ . For convenience, we denote by the opposite of r (‘move one unit left’) and by U the opposite of u (‘move one unit down’).

Different words can describe the same picture: for instance and describe the same picture, and also if the starting and ending points are not important.

3. Basic Notions

Let be the Cartesian plane and a four letter alphabet. With each letter from we associate a unit move in as follows: respectively) induces a unit move to the right (left, up, down respectively). Thus, we define a morphism e (non injective) which associates with any word over an integer pair representing the associated move in

A segment is the portion of straight line between the points (i,j) and An oriented segment

is the oriented trace of the move between the points (i,j) and

Remark: To any segment correspond two oriented seg- ments and with x = t and

Drawing Convention

In any representation of a picture associated with a word, we will use the following conventions:

full point

overlapping lines (i.e. different drawings of the same segment) are represented by closely drawn parallel lines.

For example, the word will be represented by word by (see also examples above).

and the

However, this is just a representation given to ‘show’

and the drawing: the ‘real’ picture corresponding to is |to is

4. Part 1 - Drawn Pictures

We associate with any word over a unique picture as follows:

the word is read, letter by letter, from left to right;

the starting point is the point (0, 0);

for each letter, we draw the associated oriented seg- ment whose ending point is the starting point of the next segment.

Remark: The ending point of the picture is the point with coordinates Such a picture is

drawn without pen-up. For any word

respectively) denotes the set of (oriented respectively) seg- ments of the picture associated with w.

Example: With one associates the following picture: ( o denotes the starting point and the ending point)

the starting point of the drawing is represented by an empty point o

the ending point of the drawing is represented by a

Page 3: The Shortest Way to Draw a Connected Picture

P. Seebold et al. / The Shortest Way to Draw a Connected Picture 321

Example:

is not. Conversely, any picture can be considered as a set of seg- ments S. If this picture is connected and if we choose in it astarting point St and an ending point E, a word describing this picture will be just an element of with the follow- ing properties: if a picture associated with this word is drawn from the point St, each segment of S is drawn at least once (and as many times as is necessary), no other segment is drawn and the drawing stops on the point E.

is minimal,

Remark: In general, there are several minimal words which describe a given picture.

The aim of this paper is to describe an algorithm such that one can obtain, from any word a minimal word w‘ such that This algorithm is based on the use of a rewritingsystem.

For example, the two words and describe the same picture: 5. The Rewriting System R

We introduce in this section a rewriting system R which can obtain from any word w over all the words of describing the same picture (in particular, all the minimal words).

Definitions: Let A be an alphabet. A rewriting system R over A is a subset of Each element is called a rule and is denoted by One step derivation

but the word does not describe the same picture as relation is defined by: and (because of the starting and ending points):

denotes the transitive and reflexive closure of

If we say that

w is an ancestor of v (by R) v i s a descendant of w (by R). or

Two facts here are important: For further details about rewriting systems, see Jantzen9.

Let inv(w) denotes the inverse of w defined even if a given segment is drawn several times, it appears only once in the picture. Thus, a given picture is associated with an infinite number of words over

For example, for any the picture associ- ated with the word is the same as that associated with

the words describing a given picture will be the same whatever is the starting point of this picture (what is

by:

Convention: In what follows, we write instead of

A loop is a word 1 over such that e(1) = (0, 0) (i.e. important is the position of the ending point to that of the starting point). the starting and ending points of the picture associated with

1 are the same). L is the set of all the loops Over part 1, the starting point will always be (0, 0).

So, the picture associated with ally word is com- pletely defined by the pair (S(w), e(w)). In what follows, we will denote this picture by pict(w). With the above

Remark: The loops are the words from in which occur as many r as and as many u as

example, one has and for any

Since the number of words describing a given picture is infinite, there exist such words shorter than the others. The shortest are called minimal. Formally, a word i s minimal if

We define the rewriting system R over as

with

in of

Page 4: The Shortest Way to Draw a Connected Picture

322 P. Seebold et al. / The Shortest Way to Draw a Connected Picture

Property: R preserves pictures (i.e. for any word v descen- dant of w, one has and

Two facts here are very important:

each rule of these sets of rules is context-free. This means that it can be used freely in any context without any effect on the other parts of the words (even if the fact that it is applied or not depends on a particular context).

although a rule as seems to be ‘natural’, it cannot be used here: indeed a fundamental property needed for our rewriting system (to be able to obtain all of the words describing a given picture) is that any application of any of its rules preserves pictures; it is clear that a rule as does not have this pro- perty.

Remark: Gutbrod6 introduced a similar system working on words. We can easily show that every transformation of his system can be simulated by a combination of rules from R. Moreover, Gutbrod does not give an algorithm to obtain a minimal word.

The next sets of rules can be simulated by rules from R:

Convention: In what follows, we use the term ‘ r u l e ’ instead of ‘set of rules’. So, we write ‘the rule R1’ instead of ‘ o n e rule from the set of rules R1’.

6. Results and Proofs

In this section, we use the system R to show that for any word there exists a minimal word m that derives from w (theorem 1). The proof is constructive and needs only a finite number of derivations: thus it provides an algorithm (corollary 1) (this result is not evident since the system R is not noetherien: because of the rule R 2 ‘ , there exist infinite derivations). Another important result is that, using the system R, one can obtain from any word all the words such that pict(w’) = pict(w) (propo- sition 2). In the second part, we will show that these results remain true even if we consider pictures just as sets of seg- ments (i.e. the starting and ending points are not taken into account).

For any word (the multiplicity of the segment s relative to the word w) is the number of times the segment s is drawn during the construction of pict(w) (of course, if and only if

A word is simple if for any is 1 or 2 (each segment of pict(w) i s drawn at most twice). As for the minimal words, there are in general several sim- ple words which describe a given picture.

Example: The words and describe the same picture.

not simple simple not minimal not minimal

simple

minimal simple minimal

Lemma 1: Let For any segment such that there exists derived from w such that:

for any

Observe that

Proof Let and be a segment such that (i.e. the segment s is drawn at least three times

during the construction of pict(w)). Assume that w = with and

where a, a’ and a” represent in this order the three first pas- sages on s. Four cases are possible, depending on the values of a’ and a”. These four cases are similar, so we establish the result only for one of them.

For instance, suppose a‘ = a and a” = a: w = with (we also have

and

w is derived as follows:

Theorem 1: For any word there exists a minimal word m that derives from w.

The proof is in two major steps (corollary 1.2 and 3.3) and involves an intermediate normal form for pictures which we call simple.

(the notation

in this derivation step).

indicates that only the rule Ri is involved

Page 5: The Shortest Way to Draw a Connected Picture

P. Seebold et al. / The Shortest Way to Draw a Connected Picture 323

R4 is simulated only by R1 which does not change the multiplicity of segments. As R2 is just used once, only the multiplicity of s decreases by 2. Consequently,

The two following corollaries are direct consequences of lemma 1.

Corollary 1.1: A minimal word is simple

Proof Suppose w is minimal and not simple. There exists a segment s from S(w) such that Applying lemma 1, we get a word strictly shorter than w and describ- ing the same picture. Contradiction.

Corollary 1.2: For any word there exists a simple word p that derives from w.

Proof Let as long as there exists a segment with multiplicity superior or equal to 3, we apply lemma 1. We get a word p describing the same picture as w, but all seg- ments in S(p) have a multiplicity inferior or equal to 2: p is simple.

Remark: Brandenburg and Dassow7 got a similar result using a rewriting system. However, their system which can be simulated by R1 and R2, does not allow obtaining all the simple words and in particular, the minimal words.

The next result is not used to prove theorem 1, but it is interesting because it indicates that every picture can be drawn with ut most one passage in each direction on each segment: this is a new version and proof of Euler’s theorem which establishes that a connected graph can be traversed by travelling along each edge at most once in each direc- tion.

Proposition 1: For any word there exists a word t that derives from w and that has the following property: for

any or

Proof We assume that with is simple [corollary 1.2]. We construct a word t =

as follows: we read w, letter by letter, from left to right. For each letter a,, we give to the value of a, and:

- if a, induces a segment of multiplicity 1 or if a, induces the second passage on a segment, we read the next letter;

if a, induces the first passage on a segment of multi- plicity 2, we have to transform the part of w not yet read, so that the second passage on this segment will be drawn in the opposite way.

The transformation is done as follows: two cases are possible eti respectively) denotes the (oriented respec- tively) segment described by ai):

-

a) The two passages on this segment are drawn in the same way. We have with and

w is derived as follows:

and we execute

the following steps with w’ instead of w. Indeed, R1 does not change the number of passages on the segment but only the direction of the second passage on it. Since the left factor of w is not altered, this change does not affect the part of t already built.

The two passages on this segment are drawn in opposite ways. We have with

b)

We set Two possibilities:

Either there exists a loop in v” including the letter a,. We obtain with

w is derived as follows:

Replacing w by w ‘ , we refer to the previous case.

Or there is no loop in v” including the letter it will be no more possible to generate a, applying R1 or any other rule from R. Thus, the second passage on will be obtained with

R1

Definition: To each word w E one associates its formal polynomial P(w) defined by:

Lemma 2: Two words of q and q ’ , have the same for- mal polynomial if and only if q’ is a descendant of q by R1.

Proof Since R1 does not change the multiplicity of seg- ments, the sufficient condition is obvious. The necessary condition is proved by induction on

- For n = 0 or n = 1, the claim is obvious.

- Assume the claim holds for any We will show it also holds for Two cases are possi- ble:

q and q’ start with the same letter a: so, and with and By induction, we have:

Page 6: The Shortest Way to Draw a Connected Picture

324 P. Seebold et al. / The Shortest Way to Draw a Connected Picture

In the other case, we have and with and Let t, the segment induced by b during the drawing of the picture associated with q ’ . We set

a’ represents the first passage on t during the drawing of the picture associated with q. Since the starting or the ending point o f t is the starting point of the picture (P(q) = P(q’)), we have either

or is a loop. If is a loop then a’ = b: one easily shows that there exists in q, a loop including a ’ . So, we set: q

with such that and In par-

ticular, we have - and (indeed,

q is derived as follows:

If is a loop then is derived as fol-

In both cases, we show that q can be derived as fol- lows: and by the induction hypothesis,

Corollary 2.1: If two words of q and q ‘ , have the same formal polynomial then e(q) = e(q’).

A word w describes a path C if for any left factor w‘ of w, we have where

is the sequence of nodes associated with C. Properties:

if C is Eulerian then for any

The degree relative to a word with coordinates (x, y) is denoted by It is the sum of the multiplicities of segments from S(w) including N as an extremity:

the word w describing a circuit C is unique;

if C is a cycle,

For any denotes the set of segments whose multiplicities relative to p and to q are dif- ferent.

Proof Let such that P(q) = P(q’). According to lemma 2 , q’ is a descendant of q by R. Since R preserves pictures, we have pict(q) = pict(q’) and thus e(q) = e(q’).

To establish the following result, we need some further notions. We call:

node, an element of

path, a sequence of segments such that there exists a sequence of nodes verify-

(itisunique). - -

A path is a cycle if

A path is Eulerian if it includes each segment exactly once.

circuit, an Eulerian cycle. - Two circuits are disjointed if they have no com-

mon segment (but they may have common nodes).

Example: C 1, C2 and C3 are disjointed circuits.

Proof Let be a segment from S(p, q). Set We construct a path with elements from S(p, q) as follows:

- starting from

- not including the same segment twice. One can always go away from a node with a segment not yet used: indeed, we easily verify that for each node N, the set of segments from S(p, q) which have N as an extremity, has an even number of elements. By con- struction, this path is Eulerian;

- ending in By construction, this path is a cycle.

Thus, we just have constructed a circuit. As long as the seg- ments from S(p, q) have not all been used, we choose a seg- ment from S(p, q) not yet used, and we start the same pro- cess again. By construction, all these circuits are dis- jointed.

Corollary 3.1: Let p simple. For any circuit C from S(p), a simple word can be derived from p such that:

Lemma 3: Let p and q be two simple words Over describing the same picture. The segments in S(p, q) consti- tute disjointed circuits.

Page 7: The Shortest Way to Draw a Connected Picture

P. Seebold et al. / The Shortest Way to Draw a Connected Picture 325

for any for any

As is a circuit, and can be derived as follows:

Proof Let p be a simple word over and C a circuit from S(p). is the sequence of

nodes associated with C.

We set SUCH that for any

and for any induces the first passage on a segment of C.

words over verifying:

By construction: for any for any

that we apply lemma 1. Thus, we obtain a descendant q verifying:

for any s E C if then if then

for any

We show that there exists a finite sequence ( 4 ) of p’ can be derived as follows: for any segment such

Corollary 3.2: For any simple words p and q over such that pict(p) = pict(q), q is a descendant of p by R.

Proof We apply corollary 3.1 to p for all the circuits from S(p, q) [lemma 3]. We get p ’ , descendant of p, such that: for any s E S(q), We deduce [lemma 2] that q is a descendant of

Construction:

Let is derived in as follows: by definition, there exists such that a, describes for the first time. Suppose m < k (the argu- ment is similar if m > k). -

Let a,,, describes from to . Two cases are possible: -

Corollary 3.3: For any simple word there exists a minimal word that derives from p.

Proof For any simple word there exists a minimal word m such that pict(m) = pict(p). According to corollary 1.1, m is simple. So, according to corollary 3.2, m is a des- cendant of p by R. Theorem 1 is a direct consequence of corollary 1.2 and corollary 3.3 and has two interesting corollaries.

that is to say:

So and we set

Let a, describes from to

Corollary 1: For any word a minimal word that derives from w can be obtained in finite time.

Proof The different steps of theorem 1 are summarized in the following algorithm: Let we set

-

1st step: From w, we derive a simple word p [corollary

The second corollary is an interesting improvement of pro- position 1.

Corollary 2: For any word there exists a minimal word m’ that derives from w and that has the following pro-

for any or

that is to say:

So and we set

In both cases, by construction describes the path and is derived in as follows:

In particular, we can derive p as follows:

perty: with

and describes the path

1.2].

2nd step: In S(p), we look for a circuit C such that the number of segments with multiplicity 2 is greater than the number of segments with multiplicity 1 in C. The number of segments being finite, this investigation needs finite time. If such a circuit exists, we apply corollary 3.1 and obtain a word p ’ , descendant of p, verifying We start it again taking p’ instead of p. Since strictly decreases at each step, the process is finite and the last word is minimal.

Page 8: The Shortest Way to Draw a Connected Picture

326 P. Seebold et al. / The Shortest Way to Draw a Connected Picture

Proof Let there exists a minimal word m that derives from w [theorem 1]. According to proposition 1, there exists a word m’ that derives from w and which is such that:

As m is simple [corollory 1.1], m is derived in m’ by using only rule R1 [lemma 2]. Since R1 does not change the length of the words, m’ is minimal.

According to theorem 1, for any word there exists a minimal word that derives from w. We saw that there i s an infinite number of words describing the same picture. We are interested in knowing if, from any word over we can get by R all the words describing the same picture.

Proposition 2: For any word the set of descen- dants of w by R (denoted is the set of all the words over describing the same picture as w:

Proof Since R preserves pictures, it is obvious that:

For any words v and w over such that pict(v) = pict(w), there exist simple words v‘ and w’ that derive from v and w [corollary 1.2]. Since R preserves pictures, we have pict(v’) = pict(w’) and so, v‘ is a descendant of w‘ [corollary 3.2]. To derive v in v ’ , we only use rules R1 and R2 [corollary 1.2], thus v’ can be derived in v using rules R1 and R 2 ’ .

Consequently, w can be derived as follows:

for any

and we deduce

7. Part 2 - Basic Pictures

Proof We only need to apply the following algorithm: min <- w Fori from 0 to

(* with T6 and T7 *) m minimal (* theorem 1 *)

if then

For j from 0 to do

Remark: For R ’ , R 2 ’ is not necessary because it can be simulated by a combination of the other rules and transfor- mations from R’.

Proof For any word we set with and

We simulate the derivation as follows:

8. Conclusion

In this paper, we have defined a rewriting system R and established an algorithm which allows us to get from any word over all the words of describing the same pic-

In the first part, we were interested in giving a rewriting system R and an algorithm to derive a word w over in a minimal word describing the same picture, starting and ending points being fixed. We extend our work and com- pleting R, we define now a system R’ which preserves basic

ture and in finite time, a minimal word describing this (drawn or basic) picture. That is to say, from a given (drawn or basic) picture, our algorithm computes in finite time the shortest way to draw this picture without ‘pen-up’ .

pictures (a basic picture is just a set of connected seg- ments). The aim is to get an equivalent picture, indepen- dently from the starting and ending points (then, in particu- lar, independently from the relative position of the picture in To do this, we complete R with two transformations introduced by Gutbrod6:

If we extend our work joining other elementary moves in the plane as in the above picture, the preceding results remain true using the same system R. Indeed, in the proofs, the number of possible moves from a point is never used. In this case, a minimal word could be a word such that the length of the tracing is minimal. We only need to associate with each letter the length of the segment induced by it. We show analogously that a minimal word describing a given picture can be computed in finite time. In the same way, it seems that the generalization to the third (or more) dimension should not be a problem.

2: For any word there exists a word

that derives from by the system and which is minimal in the sense of basic pictures (i.e. there is no word shorter than m describing the same basic picture).

Example:

Page 9: The Shortest Way to Draw a Connected Picture

P. Seebold et al. / The Shortest Way to Draw a Connected Picture 327

The following questions seem to be interesting for further investigations: We add to our alphabet letters which induce invisible lines. These letters will simulate the draw- ing with ‘pen-up’ (see Hinz et al. 10). Does there exist a similar rewriting system which will obtain all the words describing any given picture (not necessarily connected)? Is there a ‘clever’ algorithm to find a minimal word describing this picture? How do we choose the ‘best’ invisible lines to optimize the tracing?

Acknowledgement

The authors gratefully acknowledge an anonymous referee and Professors Jean Berstel and Michel Latteux for helpful comments on a preliminary version of this paper.

References

1. H. Freeman, “On the encoding of arbitrary geometric configurations,” IRE Transactions on Electronic Computers 10(2), pp. 260-268 (1961).

2. M. Harrison, Introduction to formal language theory, Addison-Wesley, Reading, Mass. (1978).

3. A. Salomaa, Formal languages, Academic Press, London (1973).

4. H.A. Maurer, G. Rozenberg, E. Welzl, “Using string languages to describe picture languages,” Inform. Contr. 54, pp. 155-185 (1982).

F. Hinz, “Classes of picture languages that cannot be distinguished in the chain code concept and deletion of redundant retreats,” pp. 132-143 in Proc. STACS 89, LNCS 349.

R. Gutbrod, “A transformation system for generating description languages of chain code pictures,” TCS

F.J. Brandenburg, J. Dassow, “Reduction of picture words,” MIP 8905 (Tech. Report), Univ. Passau (1989).

8. F.J. Brandenburg, “On minimal picture words,” MIP 8903 (Tech. report), Univ. Passau (1989).

9. M. Jantzen, “Confluent string rewriting,” EATCS Monographs on theoretical computer science 14, Springer-Verlag (1988).

10. F. Hinz, E. Welzl, “Regular chain code picture languages with invisible lines,” Report 252, Graz University of Technology, Institut fur Informa- tionsverarbeitung (1988).

5.

6.

68(3), pp. 239-252 (1989).

7.


Recommended