Pebble Minimization of Polyregular Functions
aa r X i v : . [ c s . F L ] J un Pebble Minimization of Polyregular Functions
Nathan Lhote
University of WarsawPoland [email protected]
Abstract
We show that a polyregular word-to-word function is regu-lar if and only if its output size is at most linear in its inputsize. Moreover a polyregular function can be realized by: atransducer with two pebbles if and only if its output hasquadratic size in its input, a transducer with three pebblesif and only if its output has cubic size in its input, etc .Moreover the characterization is decidable and, given apolyregular function, one can compute a transducer realiz-ing it with the minimal number of pebbles.We apply the result to mso interpretations from wordsto words. We show that mso interpretations of dimension k exactly coincide with k -pebble transductions. CCS Concepts: • Theory of computation → Transduc-ers . Keywords: pebble transducers, polyregular functions, min-imization, MSO interpretations
ACM Reference Format:
Nathan
Lhote. 2020. Pebble Minimization of Polyregular Functions.In
Proceedings of the 35th Annual ACM/IEEE Symposium on Logic inComputer Science (LICS ’20), July 8–11, 2020, Saarbrücken, Germany.
ACM, New York, NY, USA, 10 pages. https://doi.org/10.1145/3373718.3394804
Acknowledgments
The author is supported by the ERC Consolidator grant LIPA683080, as well as ANR DELTA (grant ANR-16-CE40-0007).
Thanks
I would like to thank Amina Doumane for her very valuableinvolvement in the early stages of this work. Thanks also toMikołaj Bojańczyk for introducing me to this problem, andfor insightful discussions on this and other topics.
Permission to make digital or hard copies of all or part of this work forpersonal or classroom use is granted without fee provided that copies arenot made or distributed for profit or commercial advantage and that copiesbear this notice and the full citation on the first page. Copyrights for com-ponents of this work owned by others than the author(s) must be honored.Abstracting with credit is permitted. To copy otherwise, or republish, topost on servers or to redistribute to lists, requires prior specific permissionand/or a fee. Request permissions from [email protected].
LICS ’20, July 8–11, 2020, Saarbrücken, Germany © https://doi.org/10.1145/3373718.3394804 Introduction
Regular and polyregular functions This article is about word-to-word (partial) functions, which we often call transduc-tions. Regular functions constitute an extensively studiedclass of functions which is characterized by many differ-ent computation models: two-way deterministic automatawith outputs, streaming string transducers [Alur and Cerný2010], mso -transductions [Engelfriet and Hoogeboom 2001,Theorem 10], regular combinators [Alur et al. 2014, Theo-rem 15] and regular list functions [Bojańczyk et al. 2018, The-orem 4.3].In this article we consider pebble transducers which wereproposed in [Milo et al. 2003], following the earlier work of[Globerman and Harel 1996]. A pebble transducer is a de-terministic finite state device which can mark a boundednumber of positions of its input with pebbles. These peb-bles follow a stack discipline , which means that only themost recently placed pebble can be moved. This restrictionensures that the model only recognizes regular languages[Globerman and Harel 1996, Theorem 4.2]. On every transi-tion the machine may append a finite word to the output.In [Bojańczyk 2018] the author provides three equivalentcharacterizations of functions realized by pebble transduc-ers, which are called polyregular functions : an imperativeprogramming language with for loops, a functional program-ming language with limited access to recursion ( e.g. map but not fold ), compositions of simple basic functions usinga Krohn-Rhodes-like decomposition.Another characterization, in terms of mso interpretations,is shown in [Bojańczyk et al. 2019, Theorem 7].One difference between regular and polyregular functionsis that regular functions have linear growth ( i.e. the imageof a word of length n has length in O( n ) ) while polyregu-lar functions may have, as the name suggests, polynomialgrowth. In fact, as we will see, this is the only difference.Growth rate We study the growth of polyregular functions.One of our main motivations was the following question:can one decide if a polyregular function is regular?The output size of a k -pebble transducer over an input ofsize n is in O( n k ) . This can be easily seen since the number ofconfigurations (state and positions of pebbles) is in O( n k ) . Inparticular, a regular function has linear growth since a two-way transducer is nothing more than a -pebble transducer.Our first main result is to show that the converse holds aswell. This means in particular that a polyregular function isregular if and only if its growth is linear. ICS ’20, July 8–11, 2020, Saarbrücken, Germany Nathan Lhote
Our second result is a procedure to minimize the numberof pebbles needed to realize a polyregular function. In par-ticular this gives a way to decide if a polyregular functionis regular.In [Bojańczyk et al. 2019, Theorem 7], the authors showthat mso interpretations capture exactly the polyregular func-tions. Their construction goes from an mso interpretationof dimension k to a pebble transducer with many more peb-bles. However one can easily see that an mso interpretationof dimension k has growth in O( n k ) . Applying our result weobtain that the blow-up in dimension is not necessary andan mso -interpretation of dimension k can always be com-puted by a k -pebble transducer. Since mso interpretations ofdimension k can express k -pebble transductions we obtainour third result: mso interpretations of dimension k exacltycapture polyregular functions of growth O( n k ) .Outline In Section 1 we give the definition of polyregularfunction and pebble transducer. In Section 2 we state ourmain results. In Section 3 we introduce the techniques usedin this paper, and we show how to decide if a regular func-tion is bounded. In Section 4 we extend these techniques toshow the main technical lemma of the article, which we callthe dichotomy Lemma: one can decide if a transducer with k + -pebbles can be turned into an equivalent transducerwith only k -pebbles. In Section 5, using the dichotomy Lemma,we are able to prove the main theorems presented in Sec-tion 2. Polyregular functions have been shown to be characterizedby many different computational models [Bojańczyk 2018;Bojańczyk et al. 2019]. The model we are interested in is thatof pebble transducers which are automata that can placepebbles on a bounded number of positions following a stackdiscipline, meaning that only the most recently placed peb-ble can be moved. We consider in this section the model ofpebble transducers and start with -pebble transducers (usu-ally called two-way transducers) which characterize the reg-ular functions. -pebble transducers A -pebble transducer, (usually knownas a two-way transducer) over input alphabet Σ and outputalphabet Γ is a two-way automaton (meaning that it has areading head, called here a pebble, which can scan the wordin both directions) which reads words over Σ ∗ , and has theability to output words over Γ ∗ on every transition. The out-put of a -pebble transducer over some word is the concate-nation of the outputs of its transitions along a run. In Fig-ure 1 we represent a configuration of a -pebble transducer: Definition 1 (1-pebble transducer) . A -pebble transduceris a tuple ( Σ , Γ , Q , q I , q F , δ ) , which consists of: • a finite input alphabet Σ and a finite output alphabet Γ ; • a finite set of states Q ; ⊢ a a c b a b ⊣ q control stateendmarkers Figure 1.
Configuration of a -pebble transducer. • two designated states q I and q F : the initial and finalone; • a transition function of type δ : ( Σ ∪ {⊢ , ⊣}) × Q → Q × { _ , ^ } × Γ ∗ The symbols ⊢ and ⊣ are the endmarkers of the word.We assume that the transducer can only move to the rightwhen it is on the left endmarker ⊢ , and only to the left whenit is on the right endmarker ⊣ . We also assume, without lossof generality, that the endmarkers don’t output anything,meaning δ ( Q × {⊢ , ⊣}) ⊆ Q × { _ , ^ } × { ϵ } .Let us define the behavior of the transducer over an in-put word w ∈ Σ ∗ . The transducer actually reads the word ⊢ w ⊣ ; and we denote by Σ ⊢⊣ the set Σ ∪ {⊢ , ⊣} . A configura-tion is seen as a word over the alphabet Σ ⊢⊣ × Q such thatthe first letter is in {⊢} × Q , the last one in {⊣} × Q and,only one position has a non-empty Q component which isa singleton. In the following, in order to simplify notations,we will denote a pair ( a , ∅ ) simply by a and a pair ( a , { q }) by (cid:20) aq (cid:21) , keeping the braces to indicate that it is a single letter.In Figure 2 we represent a configuration. ⊢ a a c (cid:20) bq (cid:21) a b ⊣ Figure 2.
Configuration of a -pebble transducer.The successor configuration of a configuration c , when itexists, is obtained in the following way: apply δ to the pair ( a , q ) corresponding to the unique letter (cid:20) aq (cid:21) in the configu-ration, update the state and move the position of the pebbleto the right or to the left accordingly depending on δ . Theoutput of c is the word in Γ ∗ obtained by applying δ . A run on w is a sequence of configurations related by the succes-sor relation defined above. The output of a run is the wordobtained by concatenating the outputs of its configurations.A configuration in (cid:20) ⊢ q I (cid:21) Σ ∗ ⊣ is called initial , and a config-uration in ⊢ Σ ∗ (cid:20) ⊣ q F (cid:21) is called final . A run is accepting if thefirst configuration is initial, the last one is final, and no other ebble Minimization of Polyregular Functions LICS ’20, July 8–11, 2020, Saarbrücken, Germany configuration is final. The accepting run over a word w , if itexists, is the unique (thanks to determinism) accepting runstarting in (cid:20) ⊢ q I (cid:21) w ⊣ . A pair ( w , v ) is realized by the trans-ducer if v is the output of the accepting run of w .A (partial) function is called regular if it is realized by a -pebble transducer. Example 2.
Let us give an example of a transducer over al-phabet { a , b } which writes in unary in { ♦ } the length of theprefix of a ’s of a word. We draw in Figure 3 the sequence ofconfigurations of the run over the word aaba , whose imageis ♦♦ . (cid:20) ⊢ q I (cid:21) aaba ⊣ ⊢ (cid:20) aq I (cid:21) aba ⊣ ⊢ a (cid:20) aq I (cid:21) ba ⊣⊢ aa (cid:20) bq I (cid:21) a ⊣ ⊢ aab (cid:20) aq F (cid:21) ⊣ ⊢ aaba (cid:20) ⊣ q F (cid:21) ϵ ♦♦ ϵ ϵ Figure 3.
Sequence of configurations.Nested transducers In the literature (see e.g. [Bojańczyk 2018]),a k -pebble transducer is a transducer with k reading heads.The movement of these heads is subject to a stack discipline:only the pebble on top of the stack can move. In this paper,we will work with a different yet equivalent model called k -nested transducers . Here a k -nested transducer is a collec-tion of k distinct -pebble transducers. The idea is that thetransducer number k can, along its run, call transducer k − to run over its current configuration. Then transducer k − can itself call transducer k − to run over its current configu-ration, and so on. This is analogous of program composition:when a program A calls a program B as a subroutine, firstprogram B is executed on the current state of program A ,then program A resumes its computation. Definition 3. A k -nested transducer of input alphabet Σ and output alphabet Γ is a tuple T = h T , . . . , T k i such thatfor every i ∈ { , . . . , n } : • T i is a 1-pebble transducer, whose set of states is de-noted Q i ; • The input alphabet of T i is Σ with additional predi-cates in Q > i ( Q > i = Ð j > i Q j ); • The output alphabet of T i is Γ ∪ { call , . . . , call i − } .In particular, the input alphabet of T k is Σ and the outputalphabet of T is Γ .The output letter call j is to be interpreted as the trans-ducer calling T j to run over its current configuration. Forevery i ∈ { , . . . , k } , the sequence h T , . . . , T i i can be seenas an i -pebble transducer, of input alphabet Σ i = Σ × Q > i and output alphabet Γ . We denote this transducer by T i . Definition 4.
We define, by induction on k , the functionrealized by a k -nested transducer. The case k = has beentreated in Definition 1.Consider a k + -nested transducer T = h T , . . . , T k + i ,and let Q i be the set of states of T i , for i ≤ k . By inductionlet f i : Σ ∗ i → Γ ∗ denote the transduction realized by T i , for i ∈ { , . . . , k } . Let us define the image of a word w of Σ ∗ bythe transduction realized by T : • Let r = c , . . . , c n + be the accepting run of T k + over w and γ , . . . , γ n be the outputs of the correspondingconfigurations. • For every j ∈ { , . . . , n } , let u j be the word obtainedfrom γ j by replacing each occurrence of a letter call i ∈{ call , . . . , call k } by f i ( c ′ j ) (where c ′ j is c j without end-markers).The image of w by T is the word u · · · u n . Example 5.
Let us consider the -nested transducer T = h T , T i , where T realizes a function f pref similar to the onedefined in Example 2: it makes a number of calls to T corre-sponding the length of the a -prefix of the input (separatedby ♯ symbols). T realizes the transduction f : ({ a , b } × { q I , q F } ) ∗ _ { a , b } ∗ that copies a word, but erases the statepredicates. Then the transduction realized by T is the func-tion f : w
7→ ( w ♯ ) | f pref ( w )| . The function f copies an inputword as many times as the length of the prefix of the wordwith only a ’s.The picture from Figure 4 illustrates the behavior of T :first T runs over the input word, and each time T producesa call , this is interpreted as a call to T to run over the cur-rent configuration. (cid:20) ⊢ q I (cid:21) aaba ⊣ ⊢ (cid:20) aq I (cid:21) aba ⊣ ⊢ a (cid:20) aq I (cid:21) ba ⊣ ⊢ aa (cid:20) bq I (cid:21) a ⊣⊢ aab (cid:20) aq F (cid:21) ⊣ ⊢ aaba (cid:20) ⊣ q F (cid:21) ϵ call ♯ call ♯ ϵϵ z }| { T ( (cid:20) aq I (cid:21) aba ) z }| { T ( a (cid:20) aq I (cid:21) ba ) Figure 4.
Run of a -pebble transducer.By definition f ({ aq I } aba ) = f ( a { aq I } ba ) = aaba , hencewe obtain f ( aaba ) = aaba ♯ aaba ♯ . Remark . We don’t give the definition of a k -pebble trans-ducer and refer the reader to [Bojańczyk 2018, Definition 2.5]for a definition of the model. The fact that k -pebble transduc-ers and k -nested transducers are equivalent is trivial and itsproof is left to the reader. From this fact we can call a func-tion polyregular if it is realized by a nested transducer. Note ICS ’20, July 8–11, 2020, Saarbrücken, Germany Nathan Lhote also that, thanks to this equivalence, we will often makestatements about pebble transducers, while the proofs willbe done using nested transducers, since pebble transducersare the more commonly known model.
Proposition 7.
A transduction can be realized by a k -nestedtransducer if and only if it can be realized by a k -pebble trans-ducer. Terminology 8.
Let f : Σ ∗ → Γ ∗ be a word to word func-tion. We say that f has degree k growth (or, abusing nota-tions, that it is in O( n k ) ) if the size of the image of a word ofsize n is in O( n k ) . For degrees , we shall use respectivelythe terms bounded and linear growth .The number of pebbles bounds in an obvious way the de-gree of a polyregular function: Proposition 9.
A function realized by a transducer with k pebbles is in O( n k ) .Proof. We prove the result for k -nested transducers. This iseasily shown by observing that the number of configura-tions of a -pebble transducer over a word of size n is in O( n ) , hence a regular function is linear. Thus we get that a k + -nested transducer is linear in the number of calls of a k -nested transducer which has growth in O( n k ) , by induc-tion. (cid:3) We start by stating our results. Note that we state the re-sults in terms of pebble transducers, as opposed to nestedtransducers, because they are the more commonly knownmodel. First, the growth degree characterizes the number ofnecessary pebbles:
Theorem 10 (Characterization) . A polyregular function isin O( n k ) if and only if it can be realized by a transducer with k pebbles. Moreover, the characterization above is decidable and onecan actually minimize the number of pebbles:
Theorem 11 (Minimization) . Given a polyregular function f , one can compute an equivalent pebble transducer with theminimal number of pebbles. In particular, one can decide if apolyregular function is regular. Finally as a consequence (using the result from [Bojańczyk et al.2019, Theorem 7]) we obtain a correspondence between thedimension of mso interpretations and the number of pebblesof pebble transducers.
Theorem 12 ( mso -dimension) . A word-to-word function canbe defined by an mso interpretation of dimension k if and onlyif it can be realized by a k -pebble transducer. We now spend the rest of the article showing the aboveresults. We start by introducing our main tool, the notion of transition morphism of a -pebble transducer. We first char-acterize the regular functions, then we tackle the generalcase of degree k growth.We show in Section 3 how to decide if a regular function isbounded. In Section 4 we prove the dichotomy Lemma whichtells, given a k -pebble transducer, if one can construct anequivalent k − -pebble transducer. Then, using the dichotomy Lemma,we prove the theorems above as corollaries. We start by showing how to decide if a regular function isbounded or not. This not very deep result will serve as a step-ping stone (as well as a warm-up) for the main contributionof the article. To characterize bounded regular function, ourmain tool will be the usual notion of transition morphismof a 1-pebble transducer.
We present here the tool used to summarize the behaviorof a -pebble transducer, called its transition monoid (resp.morphism). We map each word w to an element of the monoidwhich gives the following kind of information e.g. : if the au-tomaton enters the word from the left in state q , then it exitsto the left in state q ′ , etc . Moreover, we will sometimes needto record information about the output produced in such apass of the transducer; this information can be for instancethe whole output (in which case the monoid is infinite) orinformation of the kind “a letter a has been produced at leastonce” (here we recover finiteness). Definitions 13 (Transition monoid/morphism) . Let T be a1-pebble transducer with set of states Q and output alphabet Γ . We define the (infinite) transition monoid M of T as fol-lows: • its elements are functions of the form f : Q × { _ , ^ } → Q × { _ , ^ } × Γ ∗ ; • the composition · is defined as follows. Let f , д be twoelements of M , q ∈ Q and d ∈ { _ , ^ } . We definethe transition sequence between f and д starting from ( q , d ) and its output sequence to be respectively the se-quences ( q i , d i ) i ∈[ , n ] and ( w i ) i ∈[ , n ] satisfying the fol-lowing conditions: – ( q , d ) = ( q , d ) ; – two cases: ∗ either n = and d , d ∗ or, d = d , d n − = d n and d i , d i + for every i ∈ [ , n − ] ; – if d = _ then for every even i , f ( q i , d i ) = ( q i + , d i + , w i + ) and for every odd i , д ( q i , d i ) = ( q i + , d i + , w i + ) ; – if d = ^ then for every even i , д ( q i , d i ) = ( q i + , d i + , w i + ) and for every odd i , f ( q i , d i ) = ( q i + , d i + , w i + ) . ebble Minimization of Polyregular Functions LICS ’20, July 8–11, 2020, Saarbrücken, Germany We set ( f · д )( q , d ) to be ( q n , d n , w · · · · · w n ) .We give in Fig 5 an illustration of the transition sequence of f , д starting in ( q , _ ) . q q q q q q q w w w w w w f д Figure 5.
Transition sequence of f , д starting in ( q , _ ) .We now define the transition morphism associated withtransducer T . Let µ : ( Σ ⊢⊣ ) ∗ → M be defined as follows:For every d ∈ { _ , ^ } µ ( a )( q , d ) = δ ( a , q ) Finally, let a ∈ Γ , we consider the morphism χ a : Γ ∗ →{ , } defined by χ a ( a ) = , and χ a ( b ) = if b , a , whichsays if a word contains at least one letter a . We can naturallyextend this to a morphism χ a : M → M { , } , with M { , } = Q ×{ _ , ^ } → Q ×{ _ , ^ }×{ , } . In explicit terms, for f ∈ M , if f ( p , d ) = ( q , e , w ) we have χ a ( f )( p , d ) = ( q , e , χ a ( w )) .We denote by µ a the composition χ a ◦ µ , and we call this the a -transition morphism of T . Example 14.
Let us consider the transducer given in Exam-ple 2. Its transition function is: δ : (⊢ , q I ) 7→ ( q I , _ , ϵ )( a , q I ) 7→ ( q I , _ , ♦ ) ( a , q F ) 7→ ( q F , _ , ϵ )( b , q I ) 7→ ( q F , _ , ϵ ) ( b , q F ) 7→ ( q F , _ , ϵ )(⊣ , q I ) 7→ ( q F , _ , ϵ ) (⊣ , q F ) 7→ ( q F , _ , ϵ ) As an example let us consider f = µ ♦ ( ab ) = µ ♦ ( aaababa ) ,then f : ( q I , _ ) 7→ ( q F , _ , ) . This means that the word ab (as well as the word aaababa ) goes from q I to q F from leftto right, producing at least one symbol ♦ . Now that we have defined the transition morphism of a 1-pebble transducer, we can introduce the notion of producingtriple which characterizes non-boundedness. Intuitively, aproducing triple means a loop in the run of the transducerthat produces a non-empty output and can thus be pumpedto produce arbitrarily large outputs.
Definition 15 (Producing triple) . Let T = ( Σ , Γ , Q , q I , q F , δ ) be a 1-pebble transducer, and let a ∈ Γ . Let ( x , e , y ) ∈ µ a (⊢ Σ ∗ )× µ a ( Σ + ) × µ a ( Σ ∗ ⊣) .We say that the triple ( x , e , y ) is a -producing if the transi-tion sequence of ( xe , ey ) starting from ( q I , _ ) , ( q i , d i ) i ∈[ , n ] satisfies the following conditions: • ( q n , d n ) = ( q F , _ ) ; • e is idempotent i.e. e · e = e ; • there exists i ∈ [ , n − ] such that e ( q i , d i ) is of theform ( q , d , ) . Example 16.
Using the same transducer as in Example 14,we have that ( µ ♦ (⊢ aa ) , µ ♦ ( aba ) , µ ♦ ( ba ⊣)) , for instance, is a ♦ -producing triple. Definition 17.
Let f : Σ ∗ → Γ ∗ be a function and a ∈ Γ . Wesay that f is bounded (resp. linear , etc ) in a if π a ◦ f : Σ ∗ → a ∗ is bounded (resp. linear, etc ), where π a : Γ ∗ → a ∗ is themorphism erasing non a letters: π a ( b ) = a if b = a = ϵ otherwise.The following lemma states that having a producing triplecharacterizes the functions that are unbounded. Lemma 18. A -pebble transducer is bounded in a if and onlyif it has no a -producing triples. For the proof of the lemma, we will use a notion of factor-ization in a morphism, which will also be used in Section 4.
Definitions 19.
Let µ : Σ ∗ → M be a monoid morphismand let w be in Σ ∗ . An (idempotent) k -factorization of w in the morphism µ is given as a tuple of non-empty words ( w , x , w , . . . , x k , w k ) in Σ + verifying: • w = w x w · · · x k w k • for all i ∈ [ , k ] , µ ( x i ) = µ ( x i x i ) We also generalize this definition to a k , r -factorization , whichis a k -factorization so that each idempotent factor x i is it-self the product of r identical non-empty idempotent factors, i.e. x i = x i , · · · x i , r with x i , j , ϵ and µ ( x i , j ) = µ ( x i ) for all i ∈ { , . . . , k } , j ∈ { , . . . , r } .We say that such a factorization is according to the tuple ( m , e , m , . . . , e k , m k ) if for all i ∈ [ , k ] , µ ( w i ) = m i andfor all i ∈ [ , k ] , µ ( x i ) = e i .Given a morphism µ : Σ ∗⊢⊣ → M , we will denote in the fol-lowing by P k the set of tuples of M k + such that some wordin ⊢ Σ ∗ ⊣ has a factorization according to it (the morphism µ being clear from context).The next claim is a Ramsey-type argument which saysthat the set of words which do not admit a factorization isfinite. Claim 20.
Let µ : Σ ∗ → M be a morphism with M finite andlet k , r ≥ . The set of words without any k , r -factorization isfinite.Proof. Let R ( c , r ) be the number such that, according to Ram-sey’s theorem, an R ( c , r ) -clique with edges colored using c distinct colors contains a monochromatic clique of size r .Let µ : Σ ∗ → M be a morphism with M finite. To aword w ∈ Σ , we associate the complete graph over | w | ver-tices. Given ≤ i < j ≤ | w | the edge ( i , j ) is colored ICS ’20, July 8–11, 2020, Saarbrücken, Germany Nathan Lhote with µ ( w [ i , j [) . Let us consider a monochromatic clique ofsize r > , i < i < . . . < i r in this graph. Let w = w [ i , i [ , w = w [ i , i [ , . . . , w k − = w [ i r − , i r [ , we have that µ ( w ) = µ ( w ) = . . . = µ ( w r − ) = µ ( w w ) hence we havefound r − consecutive identical non-empty idempotent fac-tors in w .Hence, any word of length greater than kR (| M | , r + ) must have a k , r -factorization. (cid:3) Proof of Lemma 18.
We know that a -pebble transducer re-alizes a linear function, from Proposition 9. Let T be a -pebble transducer realizing a function f : Σ ∗ → Γ ∗ , andwithout loss of generality, we can assume that Γ = { a } since we only care about the size of outputs. Let µ a be the a -transition monoid morphism of T .Let us first assume that there exists an a -producing triple ( m , e , m ) ∈ P , and let w be a word such that ⊢ w ⊣ has a , -factorization ( w , x , y , z , w ) according to this triple.Then we show that since ( m , e , m ) is a -producing, | f ( w x y n z w )| = Θ ( n ) . By definition of a -producing triple, the output whilereading a y factor is non-empty, hence f is not bounded.Let us now assume that there are no a -producing triplesin P . Using Claim 20, there exists an integer d such that anyword of length greater than d has a , -factorization. Let w be a word with a , -factorization ( w , x , y , z , w ) . Sincethere are no a -producing triples, ( µ a ( w ) , µ a ( y ) , µ a ( w )) isnot a -producing. This means that the outputs correspond-ing to the factor y in the run over w are all empty, and thuswe have | f ( w x y z w )| = | f ( w x z w )| . Hence we have {| f ( w )| | w ∈ Σ ∗ } = (cid:8) | f ( w )| | w ∈ Σ ≤ d (cid:9) , and f is bounded. (cid:3) O( n k ) Now that we have solved the case of 1-pebble transducers,we move on to general case: deciding if a k + -pebble trans-duction can be realized by a k -pebble transducer. The mainidea is, given h T , . . . , T k + i , to modify T k + so that it calls T k only when “necessary”. Then, if this modified T k + isbounded in { call k } , it means that the function can actuallybe realized by a transducer with k pebbles.In order to obtain the dichotomy Lemma, which is themain lemma of the section (actually of the article), we needseveral tools which we present below.One first useful tool we will be using is that of mso -labellingof words, i.e. labelling each letter with some regular infor-mation. More formally an mso -labelling is a function of type ℓ : Σ ∗ → ( Σ × L ) ∗ , which does not change the Σ component.It is given by some unary mso -formulas ϕ ( x ) , · · · , ϕ p ( x ) and a function д : { ,..., p } → L . Given a word u ∈ Σ ∗ we define v = ℓ ( u ) by v [ i ] = ( u [ i ] , l ) , with l = д ( I ) such that u | = Ó j ∈ I ϕ j ( i ) Ó j < I ¬ ϕ j ( i ) . We show that pre-compositionwith mso -labelling does not change the number of neededpebbles to realize a function. Proposition 21.
Transductions realized by k -nested trans-ducers are closed under pre-composition with mso -labelling.Proof. We show the result by induction on k . For k = , weuse that mso -labelling are a particular case of regular func-tions, and that regular functions are closed under composi-tion.We assume that the proposition holds for k . Let T = h T , . . . , T k , T k + i be a k + -nested transducer realizing afunction f : ( Σ × L ) ∗ → Γ ∗ . To simplify the proof and with-out loss of generality we assume that T k + only makes callsto T k , i.e. does not make calls to transducers with smallerindices and does not output anything in Γ . Let f k : ( Σ × L × Q ) ∗ → Γ ∗ be the function realized by T k , with Q the statespace of T k + . Let ℓ : Σ ∗ → ( Σ × L ) ∗ be an mso -labelling,our goal is to show that f ◦ ℓ can be realized by a k + -nested transducer. We extend ℓ naturally to ˆ ℓ : ( Σ × Q ) ∗ →( Σ × L × Q ) ∗ , just by ignoring the Q component. Using theinduction assumption, we can obtain T ′ k a k -nested trans-ducer realizing f k ◦ ˆ ℓ .To obtain the result, we use the construction from [Engelfriet and Hoogeboom2001, Lemma 6] which shows that 1-pebble transducers with mso look-around are as expressive as 1-pebble transducers.Thus we can define a transducer T ′ k + which simulates T k + over words in Σ ∗ , using the mso look-around. This trans-ducer can call T ′ k at the right moments which itself simu-lates T k over words in Σ ∗ , and thus f ◦ ℓ can be realized bya k + -pebble transducer. (cid:3) The next claim says that if a k + -nested transducer h T , . . . , T k + i only makes a bounded number of calls to T k , then one nest-ing is superfluous. Intuitively, instead of calling transducer T k , transducer T k + can simulate it since it only needs to doit a bounded number of times. Claim 22.
Let h T , . . . , T k + i be a nested transducer realizinga function f , such that T k + is bounded in call k . Then f canbe realized by a k -nested transducer.Proof. Let T = h T , . . . , T k + i be a nested transducer realiz-ing a function f , such that T k + is bounded in call k . Let N besuch that the number of call k output over any word is ≤ N .For all i ∈ { , . . . , N } there is a formula ϕ i ( x ) such that forany word w , w | = ϕ i ( j ) if and only if the i th call k in therun of T k + over w is output at position j . We thus definethe associated mso -labelling ℓ which tells at each positionof w the subset of { , . . . , N } of call k output by T k + at thisposition. Let д = f ◦ ℓ − denote the function f extended tolabelled words just by ignoring the labelling. We define a k -nested transducer (cid:10) T ′ , . . . , T ′ k (cid:11) realizing д , which simulates T using the extra labelling information.Let us describe the behavior of transducer T ′ k : it simulates T k + and has an additional counter, initialized at , whichcounts how many call k have been output. Instead of out-putting call k , it increments the counter value from let us say i to i + , keeps in memory the current state q of T k + . Then, ebble Minimization of Polyregular Functions LICS ’20, July 8–11, 2020, Saarbrücken, Germany it simulates T k using the fact that some position is labelledby i + and that it has q in memory. Once the runs of T k is done, it resumes the run of T k + in state q at the positionlabelled with i + .We have provided a k -nested transducer realizing д , andfrom Proposition 21 the function д ◦ ℓ = f ◦ ℓ − ◦ ℓ = f canalso be realized by a k -pebble transducer. (cid:3) Claim 23.
Let ( M , ·) be a monoid and µ : Σ ∗ → M be a mor-phism. Let w , w , w ∈ Σ ∗ such that there exists x , y , z , t , e , f ∈ M satisfying: • µ ( w w ) = x · e and µ ( w ) = e · y , • µ ( w ) = z · f and µ ( w w ) = f · t , • e and f are idempotent.For every u , v ∈ Σ ∗ such that µ ( u ) = e and µ ( v ) = f we havethat: • µ ( w vw ) = x · e , • µ ( w uw ) = f · t .Proof. We have that µ ( w v ) = z · f · f = z · f = µ ( w ) . Thus µ ( w vw ) = µ ( w v )· µ ( w ) = µ ( w )· µ ( w ) = µ ( w · w ) = x · e .We proceed in the same way for the other equality. (cid:3) The following lemma is the technical core of this article.It basically says that the domain of a k -pebble transductioncan be decomposed into two parts: one part where any wordcan be pumped in such a way that causes a growth in Θ ( n k ) ,and a second part over which the transduction can be real-ized with only k − pebbles. The result given in the lemmaactually needs to be a bit stronger than that, in order to makethe induction work. Lemma 24 (Dichotomy Lemma) . Let T = h T , . . . , T k i be anested transducer over input alphabet Σ realizing a function f . There exists a morphism in a finite monoid µ : ( Σ ⊢⊣ ) ∗ → M and a set P ⊆ P k such that: • For any w ∈ Σ ∗ with ( w , x , w , . . . , x k , w k ) a k -factorizationaccording to an element of P , we have | f ( w x n w · · · x nk w k )| = Θ ( n k )• f restricted to words without k , r -factorization accord-ing to any element of P can be realized by a k − -nestedtransducer.Proof. This is shown by induction on k . For k = , it is aconsequence of the proof of Lemma 18, with the conven-tion that a bounded regular function is a -nested trans-duction. Indeed any factorization according to a producingtriple yields a linear growth. Conversely let L r be the lan-guage of words without any , r -factorization according toany producing tuple, then in any , r -factorization one canremove one of the idempotent factors without changing theoutput size. According to Claim 20, there is an integer d suchthat any word larger than d has a , r -factorization. Thus {| f ( w )| | w ∈ L r } = (cid:8) | f ( w )| | w ∈ Σ ≤ d (cid:9) , which means that f restricted to L r is bounded.We assume that the lemma holds for k , let us show that itholds for k + . Let T = h T , . . . , T k , T k + i be a nested trans-ducer realizing a function f : Σ ∗ → Γ ∗ , and let r > . Let T k = h T , . . . , T k i and let f k : Σ ∗ k → Γ ∗ be the function real-ized by T k . We consider µ call k : Σ ∗⊢⊣ → N the call k -transitionmorphism of T k + .Let us apply the induction assumption to T k , and let µ : ( Σ k , ⊢⊣ ) ∗ → M and P be given as in the lemma. For any s > let S s be a k − -nested transducer realizing the func-tion f k restricted to words without any k , s -factorization ac-cording to elements of P , and let д s denote the function itrealizes. We choose s to be large enough, namely larger thanmax ( R (| M | , r + ) , R (| N | , r + )) .The main idea of the proof is to modify the transducer T k + into a new transducer which only outputs call k whenit is absolutely necessary , i.e. when the word can be factor-ized in such a way that, by pumping idempotents, one canobtain an output in Θ ( n k ) . Otherwise, we have accordingto the lemma that we can outsource the computation to atransducer with only k − R k + which behaves as T k + , except that at each step where it should output theletter call k , it checks, using some regular look-around if theword has a k , s -factorization according to an element of P .If yes then it outputs call k normally, calling T k , otherwise itcalls S s instead. Note that the head movement of R k + alonga run is the same as the head movement of T k + .The look-around is implemented by an mso labelling ℓ which labels each position by additional information. Let L = Q k + → {S s , T k } be the labelling alphabet, then ℓ : ( Σ ) ∗ → ( Σ × L ) ∗ is defined as follows: Let w ∈ ( Σ ) ∗ , the word z = ℓ ( w ) has the same size as w and z [ i ] = ( w [ i ] , h ) with h ( q ) = T k if and only if the word obtained by replacing w [ i ] with (cid:20) w [ i ] q (cid:21) has a k , s -factorization according to an elementof P . Let Λ = Σ × L in the following. Transducer R k + thusreads words over alphabet Λ . Claim 25.
Let u = ℓ ( v ) be in Λ ∗ . Let us consider ( w , x , . . . , x s , w ) a , s -factorization of v in µ call k . There exists i , j ∈ { , . . . , s } such that the following holds. Let y = x · · · x i − , z = x i · · · x j , t = x j + · · · x s let v n = w yz n tw , then there exists α , β , γ ∈ Λ ∗ such that u n = ℓ ( v n ) = α β n γ , for all n ∈ N .Claim 25. Since s has been chosen large enough, we canchoose i , j so that x i · · · x j can be decomposed into r consec-utive identical non-empty idempotent factors according to µ . Using Claim 23, we see that pumping a factor of u whichis idempotent for µ , we do not affect the existence of a k , s -factorization of a word. (cid:3) ICS ’20, July 8–11, 2020, Saarbrücken, Germany Nathan Lhote
From the above claim, we have that one can pump anidempotent of N as without affecting the labelling, as longas this idempotent appears at least s times.We now consider the producing triples of R k + . If a wordcan be factorized into a producing triple of R k + this meansit can also be factorized according to a tuple of P . Howeverthe two factorizations need not be compatible as in the fol-lowing picture.Here the red factor represents the idempotent in the pro-ducing triple of R k + . The blue factors correspond to theidempotents of the factorization according to µ . The ideais that if we ask the red factor to repeat at least three times,then we can be sure that the middle factor does not inter-sect with the blue factors, since the blue factors cannot com-pletely cover the red factor (because only one position canhave a state label).Let N k + denote the transition monoid of R k . We conside aslighty different monoid which gives the following informa-tion about an idempotent word: for any context the subsetof tuples t ∈ P so that a call k is output using a factorizationaccording to t . Let us consider the monoid M k + which isequal to the product of M and N k + . We define the set P k + as the tuples of M k + that correspond to triples of N k + thatare producing triples and tuples t of P , so that the produc-ing triple outputs a call k on a position such that the corre-spond configuration has a k , s -factorization according to t .By construction and using Claim 25 we have that iteratingthe corresponding idempotents must result in a growth in Θ ( n k + ) .The only thing remaining is to show that the functionrestricted to words without any k + , s ′ -factorization ac-cording to an element of P k + can be realized by a trans-ducer with only k pebbles, for any s ′ . Let s ′′ be chosen largeenough, we define R s ′′ k + which behaves just as R k + exceptthat it asks for k , s ′′ -factorizations according to P . We wantto show that a word without any k + , s ′ -factorization ac-cording to P k + does not have any 1 , r ′′ -factorization ac-cording to a producing tuple of R s ′′ k + , which will concludethe proof from Claim 22. The construction of R s ′′ k + ensuresthat a call k is produced only when a k , s ′′ -factorization ispresent, and if s ′′ is large enough, we can assume that it isa k , s ′ -factorization according to a tuple of M k + . Taking r ′′ large enough similarly ensures that the idempotent of theproducing triple appears at least s ′ + k + , s ′ -factorization according to atuple of M k + is in particular included in the language ofwords without 1 , r ′′ -factorization according to a producingtriple of R s ′′ k + , which means that the transduction restrictedto this language can be realized with only k pebbles. Finally we show that we can remove the look-ahead, us-ing Proposition 21, concluding the proof. (cid:3) In this section we use the dichotomy Lemma to show theresults given in Section 2.
Theorem 10 (Characterization) . A polyregular function isin O( n k ) if and only if it can be realized by a transducer with k pebbles.Proof. From Proposition 9, we already have that k -pebbletransductions are in O( n k ) . To show the converse we usethe dichotomy Lemma. Let T be a j -pebble transducer real-izing a function f in O( n k ) . If j ≤ k then f can be realized bya k -pebble transducer. If j > k , then we only need to showthat we can obtain a j − f . Us-ing the dichotomy Lemma, we know there is a morphism µ : ( Σ ⊢⊣ ) ∗ _ M and a set P such that any word with a j -factorization according to an element of P can be pumpedto obtain growth in Θ ( n j ) . The transduction over all otherwords can be realized by a transducer with j − f is in O( n k ) , P has to be empty. Thus f restricted towords without j -factorization according to any element of P is just f . Hence f can be realized by a j − j = k we show that f can be realized bya k -pebble transducer. (cid:3) Theorem 11 (Minimization) . Given a polyregular function f , one can compute an equivalent pebble transducer with theminimal number of pebbles. In particular, one can decide if apolyregular function is regular.Proof. We only need to show given a k -pebble transducerrealizing a function how to obtain, if possible, an equivalenttransducer with k − T = h T , . . . , T k i be a pebble transducer over inputalphabet Σ realizing a function f .Using the dichotomy Lemma, we know there is a mor-phism µ : ( Σ ⊢⊣ ) ∗ _ M and a set P such that any word with a k -factorization according to an element of P can be pumpedto obtain growth in Θ ( n k ) . The transduction over all otherwords can be realized by a transducer with k − P is non-empty and f is in Θ ( n k ) andthus cannot be realized by a k − P isempty and f can be realized by a k − (cid:3) Theorem 12 ( mso -dimension) . A word-to-word function canbe defined by an mso interpretation of dimension k if and onlyif it can be realized by a k -pebble transducer.Proof. An mso interpretation T from Σ ∗ to Γ ∗ of dimension k is given by the following: ebble Minimization of Polyregular Functions LICS ’20, July 8–11, 2020, Saarbrücken, Germany • a finite number c , denoting the number of copies; • for each i ∈ { , . . . , c } a formula ϕ i U ( x , . . . , x k ) calledthe universe formulas; • for each i ∈ { , . . . , c } and each γ ∈ Γ a formula ϕ iγ ( x , . . . , x k ) ; • for each i , j ∈ { , . . . , c } a formula ϕ i , j ≤ ( x , . . . , x k , y , . . . , y k ) where formulas are over words over the alphabet Σ .Let u ∈ Σ ∗ , seen as a logical structure, we define v ∈ Γ ∗ a logical structure which is the image of u by T . The universeof v is defined as U v = (cid:8) ( i , ( n , . . . , n k )) | u | = ϕ i U ( n , . . . , n k ) (cid:9) .For any γ ∈ Γ , the γ predicate in v is defined as the set: γ v = Ø i ∈{ ,..., c } n ( i , ( n , . . . , n k )) ∈ U v | u | = ϕ iγ ( n , . . . , n k ) o Finally the linear order over U is defined as the relation: ≤ v = (cid:8) ( i , ( n , . . . , n k )) , ( j , ( m , . . . , m k )) ∈ U v | u | = ϕ i , j ≤ ( n , . . . , n k , m , . . . , m k ) o In [Bojańczyk et al. 2019, Theorem 7], the authors show that mso interpretations are equivalent to pebble transduc-ers. One way is easier than the other: in [Bojańczyk 2018,Lemma 2.3] it is already shown that any k -pebble transducercan be expressed by an mso interpretation of dimension k (more precisely, that the reachability relation of configura-tions is mso -definable). The other direction however is muchmore complicated and does not provide any explicit boundon the number of pebbles needed to simulate an mso inter-pretation of dimension k .However, one can easily see that an mso interpretation ofdimension k has growth in O( n k ) which means, accordingto Theorem 10, that it can be realized by a k -pebble trans-ducer. Hence we obtain our result: mso interpretations ofdimension k capture the same functions as k -pebble trans-ducers (cid:3) Conclusion
We have shown that the number of pebbles of pebble trans-ducers exactly coincides with the growth degree of polyreg-ular functions. As a corollary, using [Bojańczyk et al. 2019],we obtain that mso interpretations of dimension k computethe same functions as k -pebble transducers. Moreover, wehave shown how to minimize the number of pebbles of peb-ble transducers. The two results put together entail that wecan decide if a polyregular function is regular. Overall wehave obtained a quite satisfying understanding of the growthof polyregular functions, at least in two of the five differ-ent models presented in [Bojańczyk 2018; Bojańczyk et al.2019]. The definition of mso interpretation used in [Bojańczyk et al. 2019] isslightly different: they do not make use of copying. This difference doesnot change expressiveness, up to increasing the dimension by . One natural extension of this work would be to study thegrowth of polyregular functions in terms of the other mod-els. A first observation in that direction is that any func-tion realized by a k -pebble transducer can be obtained asthe composition of two functions: first the power k function,generalizing the square function in [Bojańczyk 2018], whichproduces n k − copies of an input of size n , each with k un-derlined positions, concatenated in lexicographic order; andsecond a regular function. This means that up to extendingthe basis of atomic functions with these power k functions(on top of the square ) the atomic functions, as well as thepolyregular list functions, enjoy a characterization in termsof growth degree, like pebble transducers and mso interpre-tations (See appendix A for more details). Only one modelseems not to fit that pattern: for programs. The nestingdepth of for loops in a for program gives an upper boundon the growth degree of the function. However regular func-tions require an unbounded nesting depth of for loops, since for programs are inherently one-way and they need nestingto simulate head-reversal. This means that the nesting depthof for programs yields a different hierarchy of polyregularfunctions, which may be worth investigating further.A minimization procedure for pebble transducers, not interms of pebbles but in terms of state space, is another in-teresting research question. However, it seems out of reachfor now for at least two reasons: 1) equivalence of pebbletransducers is not known to be decidable, and minimizationprocedures often come from canonical models, which wouldgive an algorithm for testing equivalence 2) already for regu-lar functions no canonical model procedure is known, whileequivalence is decidable. ICS ’20, July 8–11, 2020, Saarbrücken, Germany Nathan Lhote
References
Rajeev Alur and Pavol Cerný. 2010. Expressiveness of stream-ing string transducers. In
IARCS Annual Conference on Foun-dations of Software Technology and Theoretical Computer Sci-ence, FSTTCS 2010, December 15-18, 2010, Chennai, India . 1–12. https://doi.org/10.4230/LIPIcs.FSTTCS.2010.1
Rajeev Alur, Adam Freilich, and Mukund Raghothaman. 2014. Regu-lar combinators for string transformations. In
Joint Meeting of theTwenty-Third EACSL Annual Conference on Computer Science Logic(CSL) and the Twenty-Ninth Annual ACM/IEEE Symposium on Logicin Computer Science (LICS), CSL-LICS ’14, Vienna, Austria, July 14 -18, 2014 , Thomas A. Henzinger and Dale Miller (Eds.). ACM, 9:1–9:10. https://doi.org/10.1145/2603088.2603151
Mikołaj Bojańczyk. 2018. Polyregular Functions.
CoRR abs/1810.08760(2018). arXiv:1810.08760 http://arxiv.org/abs/1810.08760
Mikolaj Bojańczyk, Laure Daviaud, and Shankara Narayanan Krishna. 2018.Regular and First-Order List Functions. In
Proceedings of the 33rd AnnualACM/IEEE Symposium on Logic in Computer Science, LICS 2018, Oxford,UK, July 09-12, 2018 , Anuj Dawar and Erich Grädel (Eds.). ACM, 125–134. https://doi.org/10.1145/3209108.3209163
Mikołaj Bojańczyk, Sandra Kiefer, and Nathan Lhote. 2019. String-to-String Interpretations With Polynomial-Size Output. In , Christel Baier, IoannisChatzigiannakis, Paola Flocchini, and Stefano Leonardi (Eds.), Vol. 132.Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, 106:1–106:14. https://doi.org/10.4230/LIPIcs.ICALP.2019.106
Joost Engelfriet and Hendrik Jan Hoogeboom. 2001. MSO definable stringtransductions and two-way finite-state transducers.
ACM Trans. Com-put. Log.
2, 2 (2001), 216–254. https://doi.org/10.1145/371316.371512
Noa Globerman and David Harel. 1996. Complexity Results for Two-Wayand Multi-Pebble Automata and their Logics.
Theor. Comput. Sci. https://doi.org/10.1016/S0304-3975(96)00119-3
Tova Milo, Dan Suciu, and Victor Vianu. 2003. Typechecking forXML transformers.
J. Comput. Syst. Sci.
66, 1 (2003), 66–97. https://doi.org/10.1016/S0022-0000(02)00030-2
A Epilogue
Here we give another characterization of polyregular func-tions. It is not a particularly hard result but it gives anotheraspect of polyregular functions. Let w ∈ Σ ∗ be a word oflength n , let k > t ∈ { , . . . , n } k − . We denote by w ( t ) the word over ( Σ ⊎ ♯ ) × { ,..., k − } such that the i thposition of ♯ w is labelled by the set of { j | t ( j ) = i } (with theconvention that the ♯ is position 0). We define the function power k : w Ö t ∈{ ,..., n } k − w ( t ) with the product being in the lexicographic order. As a con-vention, power is just the identity function. We denote by reg ◦ power k the set of function that can be obtained bycomposing power k with a regular function. Example 26.
Let w = aaba , then: power ( w ) = ♯ aaba ♯ a aba ♯ aa ba ♯ aab a ♯ aaba Theorem 27.
A transduction is in reg ◦ power k if and onlyif it is definable by a transducer with k pebbles. Proof sketch. Clearly a function in reg ◦ power k has growthdegree k , thus from Theorem 10 any such function can berealized by a k -pebble transducer.Conversely let us consider T a k -pebble transducer real-izing a function f . We will show that f can be realized byapplying regular functions to power k , which will concludethe proof, since regular functions are closed under composi-tion. Let Q be the state space of T , we assume without lossof generality that when a pebble is pushed, it appears on thefirst position of the input.Let w in Σ ∗ , we see each position in w ( t ) as a placementof the pebbles over w , the position in w ( t ) labelled by i rep-resents the position of pebble i and the position itself rep-resents the position of pebble k . The position with a ♯ cor-responds to pebbles that are not placed. Note that not allpositions are legal pebble placements since they are not nec-essarily nested.We want to define an mso -transduction that inputs power k ( w ) and defines the successor relation over configurations, as en-coded earlier. We need Q copies of each position in order toencode the state of configurations. Then we show that thesuccessor relation over configurations is mso -definable. Letus first consider a configuration where all pebbles are placed.Let us consider a configuration of T , which we encode asa pair given by a state in Q and a position in power k ( w ) .We want to show that the successor configuration is defin-able in mso . If the configuration has i -pebbles placed andthe transition function gives a pop , then the next configu-ration corresponds to the first position to the left with i − push we simply move to the next position to the right with i + e.g. to the right, then we move to the next positionto the right with i pebbles placed.Thus we can obtain a function in reg ◦ power k that over w outputs the run of T over w . By composition with a mor-phism, we thus get that f is in reg ◦ power k ..