Data-Oblivious Stream Productivity

We are concerned with demonstrating productivity of specifications of infinite streams of data, based on orthogonal rewrite rules. In general, this property is undecidable, but for restricted formats computable sufficient conditions can be obtained. …

Authors: Joerg Endrullis, Clemens Grabmayer, Dimitri Hendriks

Data-Oblivious Stream Pro ductivit y J¨ org Endrullis 1 , Clemens Grabmay er 2 , and Dimitri Hendriks 1 1 V rij e Universiteit Amsterdam, Department of Computer Science De Bo elelaan 1081a, 1081 H V Amsterdam, The Neth erlands joerg@few. vu.nl diem@cs.vu .nl 2 Universiteit Utrec ht, Department of Philosoph y Heidelb erglaan 8, 3584 CS Utrecht, The Netherlands clemens@ph il.uu.nl Abstract. W e are concerned with demonstrating pro ductiv ity of sp ec- ifications of infinite streams of data, b ased on orthogonal rewrite rules. In general, this prop erty is undecidable, but for restricted formats com- putable sufficient conditions can b e obtained. The usu al analysis, also adopted here, disregards the iden tity of data, thus leading to approac hes that we call data-oblivious. W e present a metho d that is p ro va b ly opti- mal among all such data-ob livious approaches. This means that in order to impro ve on our algorithm one h as to p roceed in a data-aw are fashion. 3 1 In tro duction F or prog ramming with infinite s tructures, pr o ductivity is what termination is fo r progra mming with finite structures. P ro ductivit y captures the intuitiv e notion of unlimited prog ress, of ‘working’ progr ams pro ducing defined v alues indefinitely . In functional languag es, usage of infinite structures is common pra ctice. F o r the correctness of programs dealing with such structures one must guarantee that every finite part of the infinite structure can b e ev aluated, that is, the sp ecification of the infinite structure m ust b e pr o ductive. data-obliviously recognizable pure F ¬ F P ¬ P P = pro ductive F = flat Our contribution: = automated recognition = decision Fig. 1: Ma p of s tr eam s pecifica tions W e inv estigate this notion for stream sp ecifications, formalized as orthogo nal term rewr iting systems. Common to all previous appro aches for re c ognizing pro ductivity is a quan- titative ana lysis that abstr acts aw ay from the concrete v alues of stream elements. W e formalize this by a notion of ‘data-oblivious’ rewriting, and int r o duce the concept of data- oblivious pr oductivity . Data-oblivio us (non-)pro ductivity implies (non-)pr o ductivity , but neither o f the conv er se im- plications holds. Fig. 1 shows a V enn dia gram of stream specifica tions, high- lighting the subs e t of ‘da ta-obliviously recogniz a ble’ sp ecifications where (non-) 3 This research has b een partially funded by the N etherlands Organisation for S cien- tific R esearc h (NWO) under FOCUS/BRICKS grant num b er 642.000.502. 2 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks pro ductivity can b e r ecognized by a data-oblivio us a na lysis. W e ident ify tw o syntactical classes of strea m sp ecifications: ‘flat’ and ‘pure’ sp ecifications, see the description b elow. F or the first we devise a decisio n algo - rithm for da ta-oblivious (d-o) pro ductivity . This gives rise to a computable, d-o optimal, criter ion for pr o ductivity: every flat strea m sp ecification that can b e es- tablished to be pro ductive by whatever d-o argument is re c ognized a s pro ductive by this criterion (see Fig. 1). F or the sub class of pure spec ifica tions, w e establish that d-o pro ductivity coincides with pro ductivity , and thereby obtain a decision algorithm for productivity o f this class. Additionally , w e extend our criterion beyond the class o f flat stream s p ecifica tio ns, allowing for ‘frie ndly nesting’ in the sp ecification of str eam functions; here d-o optimality is not pre s erved. In defining the different formats of stream sp ecifications, we distinguish b e- t ween rules for strea m co nstant s , and rules for stream functions. Only the la tter are sub jected to syntactic restrictions . In flat s tream s p ecifica tions the defining rules fo r the strea m functions do not hav e nesting of str eam function symbols; how ever, in defining r ules for str eam co nstant s nesting of stre a m function sym- bo ls is allo wed. This format makes us e of exhaustive pattern matching on data to define s tream functions, allo wing for multiple defining rules for an individ- ual stream function sy m b ol. Since the qua n titative consumption/pro duction b e- haviour of a symbol f might differ among its defining rules, in a d-o a nalysis one has to settle for the us e of lower b ounds when tr ying to rec o gnize pro ductivity . If for all stream function symbols f in a flat sp ecification T the defining rules for f coincide, disre g arding the iden tity of da ta-elements, then T is called pure. Our decis ion algo rithm for d-o pro ductivity deter mines the tight d-o low er bo und on the production b ehaviour of every stream function, and uses these bo unds to calc ula te the d-o pro duction of str eam constants. W e br iefly explain bo th a s pects. Consider the strea m sp ecification A → 0 : f ( A ) together with the rules f ( 0 : σ ) → 1 : 0 : 1 : f ( σ ), and f ( 1 : σ ) → 0 : f ( σ ), defining the strea m 0 : 1 : 0 : 1 : . . . of alterna ting bits. The tight d-o low er b ound for f is the function id : n 7→ n . F urther note that su c : n 7→ n + 1 captur e s the quantit ative b ehaviour of the function prep ending a data ele ment to a s tream ter m. Therefor e the d-o pro duction of A can b e computed as lfp( suc ◦ id ) = ∞ , where lfp( f ) is the least fixed point of f : N → N and N := N ∪ { ∞} ; henc e A is pro ductive. As a co mparison, only a ‘data-aware’ a pproach is able to establish pr o ductivity of B → 0 : g ( B ) with g ( 0 : σ ) → 1 : 0 : g ( σ ), a nd g ( 1 : σ ) → g ( σ ). The d-o lo wer bo und of g is n 7→ 0, due to the latter rule. This makes it imp ossible for any conceiv able d-o approach to recogniz e pr o ductivity of B . W e obta in the following results: (i) F o r the class of flat stream sp ecifications we give a computable, d-o optimal, sufficient co ndition for pro ductivity . (ii) W e show decida bilit y of pro ductivity for the class of pur e stream s pecifica - tions, a n extension o f the format in [2]. (iii) Disr e g arding d-o optimality , we extend (i) to the big ger class of friendly nesting s tream sp ecifications. (iv) A tool automating (i), (ii), a nd (iii), which can be downloaded from, and used via a web int erface a t: http://infinit y.few.vu.nl/productivity . Data-Oblivious Stream Pro ductivity 3 R elate d work. Previo us appro aches [8, 3, 9 , 1] employ ed d-o r easoning (without using this name for it) to find sufficient criter ia ensur ing pr o ductivit y , but did not a im at optimality . The d-o pro duction b ehaviour of a stream function f is b ounded from b elow b y a ‘mo dulus of pro duction’ ν f : N k → N with the prop erty that the firs t ν f ( n 1 , . . . , n k ) element s of f ( t 1 , . . . , t k ) can b e computed whenever the first n i elements of t i are defined. Sijtsma develops an a ppr oach allowing arbitrar y pr o ductio n moduli ν : N k → N , which, while providing an adequate mathematical description, are less amenable to automa tion. T elford and T ur ner [9] employ pro duction mo duli o f the form ν ( n ) = n + a with a ∈ Z . Hughes, Pareto and Sabry [3] use ν ( n ) = max { c · x + d | x ∈ N , n ≥ a · x + b } ∪ { 0 } with a, b, c , d ∈ N . Both c lasses of pro duction mo duli are strictly contained in the class o f ‘p erio dica lly incre a sing’ functions which we employ in our analysis. W e show that the set of d-o low er b ounds of flat s tream function sp ecifications is exa ctly the set of p erio dically increasing functions. Buc hho lz [1] presents a t y pe system for pro ductivity , us ing unrestric ted pro duction mo duli. T o obtain an automatable metho d for a res tricted class of stream sp ecifications, he dev ises a syntactic cr iterion to ensur e pr o ductivity . This cr iter ion easily handles all the examples of [9], but fails to deal with functions that have a neg a tive effect like odd defined by o dd ( x : y : σ ) → y : o dd ( σ ) w ith a (p erio dically increas ing) mo dulus ν o dd ( n ) = ⌊ n 2 ⌋ . Overview. In Sec. 2 we define the notion of stream sp ecification, and the syntactic format of fla t and pur e sp ecifications. In Sec. 3 we formalize the notion of d-o rewriting. In Sec. 4 we introduce a pro duction ca lculus as a mea ns to compute the pro duction of the data -abstracted stream sp ecificatio ns, based on the set of p erio dically increasing functions. A translatio n o f strea m sp ecifica tio ns into pro duction terms is defined in Sec. 5. O ur main results, mentioned ab ov e, ar e collected in Sec. 6. W e conclude and discuss some future res earch topics in Sec. 8. 2 Stream Sp ecifications W e int r o duce the notio n of stre a m sp ecification. An example is given in Fig. 2, a pro ductive sp ecification of Pascal’s triang le where the rows are separated by P → 0 : s ( 0 ) : f ( P ) f ( s ( x ) : y : σ ) → a ( s ( x ) , y ) : f ( y : σ ) str e am layer f ( 0 : σ ) → 0 : s ( 0 ) : f ( σ ) a ( s ( x ) , y ) → s ( a ( x, y )) data layer a ( 0 , y ) → y Fig. 2: Example of a flat stream sp ecification. 4 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks zeros. Indeed, ev aluating this sp ecification, we get: P ։ ։ 0 : 1 : 0 : 1 : 1 : 0 : 1 : 2 : 1 : 0 : 1 : 3 : 3 : 1 : . . . , where, for n ∈ N , n is the numer al for n , defined by n := s n ( 0 ). Stream sp ecificatio ns consist of a st r e am layer (top) where stream constants and functions are sp ecified and a data layer (b ottom). The hierarchical setup of stream spe cifications is motiv ated as follows. In order to abstrac t from the terminatio n problem when investigating pro ductivity , the data lay er is a term rewriting system o n its own, and is required to be strongly normalizing. Moreover, an isolated data layer preven ts the use of stream symbols by data rules . The stream lay er may use symbols of the data lay er , but no t vice- versa. Stream dep enden t data functions, like head ( x : σ ) → x , might cause the output of undefined da ta terms. Co ns ider the fo llowing exa mples fro m [8]: S → 0 : S (6) : S T → 0 : T (7) : T , where σ ( n ) := head ( tail n ( σ )); here S is well-defined, wherea s T is not. Note that this is not a se vere restr iction, since str e a m dep endent data functions usua lly can be replaced b y pattern matching: f ( σ, τ ) → ( head ( σ ) + head ( τ )) : f ( tail ( σ ) , tail ( τ )), for example, can b e r eplaced by the b etter r eadable f ( x : σ , y : τ ) → ( x + y ) : f ( σ, τ ). Stream specifica tions are forma lized a s many-sorted, o rthogonal, constructor term rew r iting systems [10]. W e distinguish be tw e en str e am terms and data terms . F or the sake of simplicity we consider only o ne sort S for strea m terms and one sor t D for data terms. Without any complica tion, our results ex tend to stream sp ecificatio ns with multiple sorts for data terms and for s tream terms. Let U b e a finite s et of sorts . A U -sorte d set A is a family o f sets { A u } u ∈ U ; for V ⊆ U we define A V := S v ∈ V A v . A U -sorte d signatur e Σ is a U -sor ted set of function sy m b ols f , eac h equipped with an ar it y ar ( f ) = h u 1 · · · u n , u i ∈ U ∗ × U where u is the s ort of f ; we wr ite u 1 × . . . × u n → u for h u 1 · · · u n , u i . Let X b e a U -sorted set of v aria bles. The U -sorte d set of terms T er ( Σ , X ) is inductively defined by: for a ll u ∈ U , X u ⊆ T er ( Σ , X ) u , and f ( t 1 , . . . , t n ) ∈ T er ( Σ , X ) u if f ∈ Σ , ar ( f ) = u 1 × . . . × u n → u , and t i ∈ T er ( Σ , X ) u i . T er ∞ ( Σ , X ) denotes the set of (p ossibly) infinite terms over Σ and X (see [10]). Usually we keep the s et of v a riables implicit and write T er ( Σ ) and T er ∞ ( Σ ). A U -sorte d term re writing syst em (TRS) is a pair h Σ , R i cons isting of a U -sorted sig nature Σ a nd a U -sorted set R of ru les that satisfy well-sortedness , for all u ∈ U : R u ⊆ T er ( Σ , X ) u × T er ( Σ , X ) u , as well as the sta nda rd TRS requirements. Let T = h Σ , R i b e a U -sorted TRS. F or a ter m t ∈ T er ( Σ ) u where u ∈ U we denote the ro ot symbol of t by r oot ( t ). W e say that tw o o ccur r ences of s y m b ols in a term ar e n est e d if the p osition [10 , p.29] of one is a prefix of the position of the other. W e define D ( Σ ) := { r oot ( l ) | l → r ∈ R } , the set o f define d symb ols , and C ( Σ ) := Σ \ D ( Σ ), the set of c onstru ctor symb ols . Then T is calle d a c onstructor TRS if for every rewrite rule ρ ∈ R , the left-hand side is of the form f ( t 1 , . . . , t n ) with t i ∈ T er ( C ( Σ )); then ρ is called a defining ru le for f . W e call T ex haust ive for f ∈ Σ if every ter m f ( t 1 , . . . , t n ) with closed constructor terms t i is a r edex. Data-Oblivious Stream Pro ductivity 5 A str e am TRS is a finite { S , D } -so rted, o rthogonal, constructo r TRS h Σ , R i such tha t ‘:’ ∈ Σ S , the stre am c onst ructor symb ol , with arity D × S → S is the single constr uctor symbo l in Σ S . Elements o f Σ D and Σ S are called the data symb ols and the st r e am symb ols , res p ectively . W e let Σ s := Σ S \ { ‘:’ } , and, for all f ∈ Σ s , we ass ume w.l.o.g. that the s tream arguments are in fro n t: ar ( f ) ∈ S ar s ( f ) × D ar d ( f ) → S , where ar s ( f ) and ar d ( f ) ∈ N ar e ca lled the str e am arity and the data arity of f , r esp ectively . B y Σ sc on we denote the set of s y m b ols in Σ s with stream ar it y 0 , called the str e am c onstant symb ols , and Σ sfun := Σ s \ Σ sc on the set o f symbols in Σ s with stream ar it y unequal to 0 , called the str e am funct ion symb ols . By R sc on we mean the defining rules for the s y m b ols in Σ sc on . W e r epea t that the r estriction to a sing le data sort D is so lely for keeping the presentation s imple; all of the definitions and res ults in the sequel gener alize to multip le data and stre a m sor ts. F or str eam TRSs we assume non-emptyness of data s o rts, that is, for every data sor t there exists a finite, closed, contructor term of this s ort. In ca se there is only one data sort D , then the r equirement bo ils down to the existence of a nullary cons tructor symbol of this so r t. W e co me to the definition of stream sp ecifications. Definition 2.1 . A str e am sp e cific ation T is a stream TRS T = h Σ , R i such that the following conditio ns hold: (i) Ther e is a designated symbol M 0 ∈ Σ sc on with ar d ( M 0 ) = 0, the r o ot of T . (ii) h Σ D , R D i is a terminating, D - sorted TRS; R D is called the data-layer of T . (iii) T is exhaustive (for all defined sy m b ols in Σ = Σ S ⊎ Σ D ). In the s e q uel we restrict to stream sp ecifica tio ns in which all stream constants in Σ sc on are r eachable fr o m the r o ot: M ∈ Σ sc on is re achable if there is a ter m s such that M 0 → ∗ s and M o ccurs in s . Note that reachabilit y of stream constants is decidable, and that unr e achable symbols may b e neglected for in vestigating (non-)pro ductivity . Note tha t Def. 2.1 indeed imp oses a hierarchical setup; in particular, stream depe ndent da ta functions ar e excluded by item (ii). Exhaustivity for Σ D together with str ong normaliza tion o f R D guarantees that closed data terms rewrite to constructor nor mal forms, a prop erty known as sufficient completeness [4]. W e a re interested in productivity of recur sive s tream sp ecificatio ns that make use of a libr ary of ‘manag eable’ strea m functions. By this we mean a cla ss of stream functions defined by a syntactic format with the prop erty that their d-o low er b ounds are computable and contained in a se t o f pro duction mo duli that is e ffectiv ely closed under comp osition, p o in twise infimum and where least fixe d po in ts ca n b e computed. As suc h a format w e define the class of flat stre a m sp ecifications (Def. 2 .2) for which d- o low er b o unds ar e precisely the set o f ‘p e- rio dically incr easing’ functions (see Sec. 4). Thu s o nly the strea m function rules are sub ject to syntactic r estrictions. No co nditio n other than well-sortedness is impo sed on the defining rules of stream c o nstant symbols. In the seq uel let T = h Σ , R i b e a stream sp ecification. W e define the relatio n on rules in R S : for all ρ 1 , ρ 2 ∈ R S , ρ 1 ρ 2 ( ρ 1 dep ends on ρ 2 ) holds if and only if ρ 2 is the defining r ule of a stream function sym b ol on the righ t-hand 6 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks side of ρ 1 . F urthermo re, for a bina ry relation → ⊆ A × A on a set A we de fine ( a → ) := { b ∈ A | a → b } for all a ∈ A , and w e denote by → + and → ∗ the tr ansitive closur e and the r eflexive and tra ns itive closur e of → , resp ectively . Definition 2.2 . A rule ρ ∈ R S is calle d n esting if its rig h t- ha nd side contains nested o ccurr ences of stream sy m b ols fro m Σ s . W e use R nest to denote the subset of nesting r ule s of R and define R ¬ nest := R S \ R nest , the se t o f non-nesting rules . A rule ρ ∈ R S is called flat if all r ules in ( ρ ∗ ) are non- nesting. A symbo l f ∈ Σ s is called flat if all defining rules of f a re flat; the set o f flat symbols is denoted Σ flat . A s tream sp ecification T is called flat if Σ s ⊆ Σ flat ∪ Σ sc on , that is, a ll symbols in Σ s are either flat o r stream cons tan t symbols. The sp ecification given in Fig. 2 is an example o f a flat sp ecification. A s econd example is given in Fig. 3. This is a pro ductive spe c ification that defines the Q → a : Q ′ Q ′ → b : c : f ( Q ′ ) f ( a : σ ) → a : b : c : f ( σ ) str e am layer f ( b : σ ) → a : c : f ( σ ) f ( c : σ ) → b : f ( σ ) data layer Fig. 3: Example of a flat stream sp ecification. ternary Thue–Morse sequence, a square - free w or d o ver { a , b , c } ; see, e.g ., [7]. Indeed, ev alua ting this specific a tion, we get: Q ։ ։ a : b : c : a : c : b : a : b : c : b : a : c : . . . . As the basis of d- o r ewriting (see Def. 3 .3) we define the data a bs traction of terms as the res ults of r eplacing all data-subterms by the symbol • . Definition 2.3 . Let L Σ M := {•} ⊎ Σ S . F or strea m terms s ∈ T er ( Σ ) S , the data abstr action L s M ∈ T er ( L Σ M ) S is defined b y : L σ M = σ , L u : s M = • : L s M , L f ( s 1 , . . . , s n , u 1 , . . . , u m ) M = f ( L s 1 M , . . . , L s n M , • , . . . , • ) . Based on this definition of data abstracted terms, w e define the class of pure stream sp ecificatio ns, an extensio n of the equally named class in [2]. Definition 2.4 . A stream sp ecification T is ca lle d pur e if it is flat and if for every s ym b ol f ∈ Σ s the data abstractions L ℓ M → L r M o f the de fining rules ℓ → r of f coincide (mo dulo renaming of v ar iables). Data-Oblivious Stream Pro ductivity 7 Q → diff ( M ) M → 0 : zip ( inv ( M ) , tail ( M )) zip ( x : σ , τ ) → x : zip ( τ , σ ) str e am layer inv ( x : σ ) → i ( x ) : inv ( σ ) tail ( x : σ ) → σ diff ( x : y : σ ) → x ( x, y ) : diff ( y : σ ) i ( 0 ) → 1 i ( 1 ) → 0 x ( 0 , 0 ) → b x ( 0 , 1 ) → a data layer x ( 1 , 0 ) → c x ( 1 , 1 ) → b Fig. 4: Example of a pure stream sp ecification. Fig. 4 shows a n alternative sp ecification of the ternary Th ue– Morse sequence, this time constructed fro m the binar y Thue–Morse s e quence sp ecified by M . This sp ecification belo ngs to the subcla ss of pure specifica tio ns, whic h is ea sily inferr ed by the shap e of the stream layer: for ea c h s ym b ol in Σ sfun = { zip , inv , tail , diff } there is precisely one defining r ule. Another exa mple of a pure strea m sp ecification is given in Fig. 5. Both defin- M → 0 : M ′ M ′ → 1 : h ( M ′ ) str e am layer h ( 0 : σ ) → 0 : 1 : h ( σ ) h ( 1 : σ ) → 1 : 0 : h ( σ ) data layer Fig. 5: Example of a pure stream sp ecification. ing rules fo r h consume one, and pro duce tw o stream elements, that is, their data abstractions co incide. Def. 2.4 generalize s the s pecifica tions called ‘pure’ in [2 ] in four wa ys con- cerning the defining rules of stream functions: First, the requirement of right- linearity of s tream v aria bles is dropp ed, allowing for rules like f ( σ ) → g ( σ, σ ). Second, ‘additional supply’ to the stream arg umen ts is allow ed. F or instance, in the defining r ule for the function diff in Fig. 4 , the v aria ble y is ‘supplied’ to the recursive c all o f diff . Third, the use of non-pro ductive str eam functions is allow ed now, relaxing a n earlier r equirement on stream function symbols to b e ‘weakly g uarded’. Finally , defining r ules for str eam function symbols may use a restricted form of pattern matching as long as, for every str eam function f , the 8 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks d-o consumption/ pr o duction be haviour (see Sec. 3) o f all defining rules for f is the sa me. Next we define friendly ne s ting stream spec ific a tions, an e xtension of the class o f fla t strea m sp ecifications. Definition 2.5 . A rule ρ ∈ R S is called friend ly if for all rules γ ∈ ( ρ ∗ ) we hav e: (1) γ consumes in each ar gument a t most one stream elemen t, and (2) it pro duces a t least o ne. The set of friend ly nesting ru les R fnest is the la rgest extension o f the set of friendly rules by non-nesting rules fr o m R S that is closed under . A symbol f ∈ Σ s is friend ly nest ing if all defining rules of f are friendly nesting. A strea m spec ific a tion T is ca lled friend ly nest ing if Σ s ⊆ Σ fnest ∪ Σ sc on , that is, all sym b ols in Σ s are either friendly nesting or stream constant symbols. An example o f a friendly nesting stream specifica tio n is given in Fig. 6 . The r oo t nats → 0 : × ( ones , ones ) ones → s ( 0 ) : ones × ( x : σ , y : τ ) → m ( x, y ) : add ( times ( τ , x ) , × ( σ, y : τ )) times ( x : σ , y ) → m ( x, y ) : times ( σ , y ) add ( x : σ, y : τ ) → a ( x, y ) : add ( σ , τ ) str e am layer a ( 0 , y ) → y a ( s ( x ) , y ) → s ( a ( x, y )) m ( 0 , y ) → 0 m ( s ( x ) , y ) → a ( y , m ( x, y )) data layer Fig. 6: Example of a friendly nesting stream sp ecification. of this sp ecification, the constant na ts , ev alua tes to the stre a m 0 : 1 : 2 : . . . . The stream lay er sp ecifies a parameterized stream function times , which multiplies every element of a stream with the par ameter, and the binary str eam functions add for compo nent wise addition, a nd × , the c onvolution pr o duct of streams (see [6 ]), mathematically defined as a n op eration h σ , τ i 7→ σ × τ : ( σ × τ )( i ) = i X j =0 σ ( j ) · τ ( i − j ) (for all i ∈ N ). The rewrite rule for × is nesting, b ecause its right-hand has nested stream func- tion sy m b ols, b oth ti m e s and × are nested within add . Beca us e of the pr esence of a nesting rule in the stream la yer, which is not a defining rule of a stream con- stant symbol, this stream specifica tion is not fla t. How ever, the defining rules for add , times , and × ar e friendly . F or instance for the rule for × we check: in b oth arguments it consumes (at most) o ne stream element ( x and y ), it pro duces Data-Oblivious Stream Pro ductivity 9 (at least) one strea m element ( m ( x, y )), and the defining r ules of the stream function s ym b ols in the r ight - hand side ( add , times , and × ) ar e aga in friendly . Thu s the function s tr eam la yer consists of one friendly nesting rule, t wo flat (and friendly) rules, and one defining rule for a strea m constant. Ther efore this stream sp ecificatio n is frie ndly nesting. Definition 2.6 . Let A = h T er ( Σ ) S , →i b e an abstract reduction sy stem (ARS) on the set of terms ov er a stream TRS signature Σ . The pr o duction function Π A : T er ( Σ ) S → N of A is defined fo r all s ∈ T er ( Σ ) S by: Π A ( s ) := sup { n ∈ N | s → ∗ A u 1 : . . . : u n : t } . W e ca ll A pr o ductive for a str e am term s if Π A ( s ) = ∞ . A strea m sp ecification T is ca lled pr o ductive if T is pro ductive for its r o ot M 0 . The following pr opo sition justifies this definition o f pro ductivit y by stating an easy consequence: the r o ot o f a pro ductive stream sp ecification can be ev aluated contin ually in such a w ay that a uniquely determined stream in constructor normal for m is obtained as the limit. This follows easily from the fact that a stream sp ecificatio n is an orthogonal TRS, and hence ha s a confluent r ewrite relation that enjoys the prop erty UN ∞ (uniqueness of infinite no rmal form) [5]. Prop osition 2.7. A str e am sp e cific ation is pr o ductive if and only if its r o ot has an infinite c onstru ctor term of the form u 1 : u 2 : u 3 : . . . as its un ique infinite normal form. 3 Data-Oblivious Analysis W e forma lize the notion of d- o r ewriting and introduce the concept of d- o pro- ductivit y . The idea is a qua n titative r easoning where all knowledge ab out the concrete v alues of data elements during a n ev aluation seq uence is ignored. F or example, cons ider the fo llowing stream s pecifica tion: M → f ( 0 : 1 : M ) (1) f ( 0 : x : σ ) → 0 : 1 : f ( σ ) (2) f ( 1 : x : σ ) → x : f ( σ ) The sp ecification of M is pro ductive: M → 2 0 : 1 : f ( M ) → 3 0 : 1 : 0 : 1 : f ( f ( M )) → ∗ . . . . During the rewrite sequence (2) is nev er a pplied. Disregar ding the iden tity of data, how ever, (2) b ecomes applicable a nd allows for the rewrite sequence: M → f ( • : • : M ) → (2) • : f ( M ) → ∗ • : f ( • : f ( • : f ( . . . ))) , pro ducing only one element. Hence M is not d-o pr o ductiv e. D-o term rewriting can b e thought of as a tw o-play e r ga me b et ween a r ewrite player R which p erfo r ms the usual ter m rewriting, and an op p onent G which befo re ev er y rewrite step is allow ed to arbitra rily exchange da ta elemen ts for (sort-res pecting) da ta terms in constructo r no r mal form. The opp onent can ei- ther handicap or supp ort the rewrite player. Resp ectively , the d-o low er (upp er) 10 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks bo und o n the pro duction of a stream term s is the infim um (supr em um) o f the pro duction of s with resp ect to a ll p ossible strategie s for the o pp onent G . Fig. 7 depicts d-o rewr iting of the ab ov e strea m sp ecification M ; by exchanging data elements, the opp onent G enforces the applica tion o f (2). R emark 3.1. A t firs t glance it might app ear natural to mo del the o ppo nen t using a function G : T er ( Σ D ) → T er ( Σ D ) from data terms to da ta ter ms. How ever, such a p er-element deterministic exc ha nge strateg y preserves equality of data elements. The n the following sp ecification of W : W → g ( Z , Z ) Z → 0 : Z g ( 0 : σ, 0 : τ ) → 0 : g ( σ, τ ) g ( 0 : σ, 1 : τ ) → g ( σ , τ ) g ( 1 : σ, 1 : τ ) → 0 : g ( σ, τ ) g ( 1 : σ, 0 : τ ) → g ( σ , τ ) would be pro ductive for every such G , which is c le arly no t what one would exp ect of a d-o ana lysis. The opp onent can b e mo delled b y an o per ation on stream terms: T er ( Σ ) S → T er ( Σ ) S . Howev er, it can b e shown that it is sufficient to qua n tify over stra tegies for G for which G ( s ) is inv ar ia n t under exchange of data elements in s for all terms s . Therefor e w e first a bstract from the data elements in fav o ur of symbols • and then define the opp onent G on the abstracted terms, G : T er ( L Σ M ) S → T er ( Σ ) S . Definition 3.2 . Let T = h Σ , R i b e a stream sp ecification. A data-exchange function on T is a function G : T er ( L Σ M ) S → T er ( Σ ) S such that ∀ r ∈ T er ( L Σ M ) S it holds: L G ( r ) M = r , and G ( r ) is in data-co nstructor normal for m. Definition 3.3 . W e define the ARS A T , G ⊆ T er ( L Σ M ) S × T er ( L Σ M ) S for every data-exchange function G , as follows: A T , G := { s → L t M | s ∈ T er ( L Σ M ) , t ∈ T er ( Σ ) with G ( s ) → T t } . The d-o pr o duction ra n ge do T ( s ) of a da ta abstracted stream term s ∈ T er ( L Σ M ) S is defined as follows: do T ( s ) := { Π A T , G ( s ) | G a data- exchange function on T } . M M f ( 0 : 1 : M ) f ( 1 : 0 : M ) 0 : f ( M ) 0 : f ( M ) 0 : f ( f ( 0 : 1 : M )) 0 : f ( f ( 1 : 0 : M )) 0 : f ( 0 : f ( M )) . . . G R G R G R G R G Fig. 7: Data-oblivious rewriting Data-Oblivious Stream Pro ductivity 11 The d-o lower and upp er b ound on the pr o duction of s are defined by do T ( s ) := inf ( do T ( s )) , and do T ( s ) : = sup( do T ( s )) , resp ectively . These notio ns c arry ov er to strea m terms s ∈ T er ( Σ ) S by taking their da ta abstractio n L s M . A str eam sp ecification T is d-o pr o ductive ( d-o non-pr o ductive ) if do T ( M 0 ) = ∞ (if do T ( M 0 ) < ∞ ) holds. Prop osition 3.4. F or T = h Σ , R i a str e am sp e cific ation and s ∈ T er ( Σ ) S : do T ( s ) ≤ Π T ( s ) ≤ do T ( s ) . Henc e d-o pr o duct ivity implies pr o ductivity and d-o n on- pr o ductivity implies non- pr o ductivity. W e define low er and upp er b ounds on the d-o consumption/pro duction b e- haviour of str eam functions. The s e b ounds are us e d to rea son ab out d-o (non-) pro ductivity of stream c o nstants, see Sec. 6. Definition 3.5 . Let T = h Σ , R i be a stream sp ecification, g ∈ Σ s , k = ar s ( g ), and ℓ = ar d ( g ). The d-o pr o duction r ange do T ( g ) : N k → P ( N ) of g is : do T ( g )( n 1 , . . . , n k ) := do T ( g (( • n 1 : σ ) , . . . , ( • n k : σ ) , • , . . . , • | {z } ℓ -times ) ) , where • m : σ := m ti mes z }| { • : . . . : • : σ . The d-o lower and upp er b ounds on t he pr o duction of g are defined by do T ( g ) := inf ( do T ( g )) and do T ( g ) := sup( do T ( g )), resp ectively . Even simple stream function sp ecificatio ns ca n exhibit a complex d-o b e- haviour. F or example, co nsider the flat function sp ecification: f ( σ ) → g ( σ, σ ) g ( 0 : y : σ , x : τ ) → 0 : 0 : g ( σ , τ ) g ( 1 : σ , x 1 : x 2 : x 3 : x 4 : τ ) → 0 : 0 : 0 : 0 : 0 : g ( σ , τ ) Fig. 8 (left) shows a (small) selection of the p ossible function-call tra ces fo r f . In particular, it depicts the traces that contribute to the d-o lower b o und do T ( f ). The low er b ound do T ( f ), shown on the r ight, is a sup erp osition of multiple traces of f . In g e neral do T ( f ) ca n even b e a s up erp ositio n of infinitely many trace s. First Obs erv ations on Data-Oblivious Rewriti ng F or a stream function symbol g , we de fine its o ptimal pr o duction mo dulus ν g , the data-aware, qua ntitative lower b ound on the pr o duction of g , a nd c ompare it to its d-o low er b ound do T ( g ). 12 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks input 5 10 15 output 5 10 15 input 5 10 15 output 5 10 15 Fig. 8: T races Definition 3.6 . Let T = h Σ , R i b e a str eam s pecifica tion. W e define the set S n of n -define d strea m ter ms, i.e. finite strea m terms with a constructor -prefix of leng th n ∈ N : S n := { u 1 : . . . : u n : σ | u 1 , . . . , u n ∈ T er ( C ( Σ D ) , ∅ ) } , Moreov e r, let g ∈ Σ sfun with k = ar s ( g ) a nd ℓ = ar d ( g ), a nd define, for all n = n 1 , . . . , n k , the set G n of a pplica tions of g to n i -defined arg umen ts: G n := { g ( s , v ) | ∀ i. s i ∈ S n i , ∀ j. v j ∈ T er ( C ( Σ D ) , ∅ ) } , where s = s 1 , . . . , s k and v = v 1 , . . . , v ℓ . Then, the optimal pr o duction m o dulus ν g : N k → N of g is defined by: ν g ( n ) := inf { Π T ( t ) | t ∈ G n } . T o illustra te the difference betw e en the optimal pro duction mo dulus ν h and the d- o lo wer b ound do T ( h ), co nsider the follo wing str e am function sp ecification: h ( 0 : x : σ ) → x : x : h ( 0 : σ ) ( ρ h 0 ) h ( 1 : x : σ ) → x : h ( 0 : σ ) ( ρ h 1 ) with Σ D = { 0 , 1 } . T he n ν h ( n ) = 2 n . − 3 is the optimal pr o duction mo dulus o f the s tream function h . T o obtain this b ound one has to take into account that the data element 0 is supplied to the recur sive call and c onclude tha t ( ρ h 1 ) is only applicable in the first s tep of a rewrite seq uence h ( u 1 : . . . : u n : σ ) → . . . . How ever, the d-o lower b ound is do T ( h )( n ) = n . − 1, derived from r ule ( ρ h 1 ). The fo llowing lemmas state an observ ation a b out the ro le of the o pponent and the r ewrite play er. Basica lly , the oppo nen t G can sele ct the rule w hich is applicable for each p osition in the term; the rewr ite play er R can choos e which po sition to rewr ite. W e use subs c ripts for p ebbles • , for exa mple • w , to introduce ‘names’ for referring to these p ebbles. Data-Oblivious Stream Pro ductivity 13 Definition 3.7 (Instan tiation with resp ect to a rule ρ ). F or s ∈ T er ( L Σ M ) S with s ≡ f ( s 1 , . . . , s ar s ( f ) , • 1 , . . . , • ar d ( f ) ) and ρ ∈ R a defining rule of f , we define a data-e x c ha nge function G s,ρ as follows. Note that ρ is of the form: ρ : f ( u 1 : σ 1 , . . . , u n : σ n , v 1 , . . . , v ar d ( f ) ) → r ∈ R . F or i = 1 , . . . , ar s ( f ) let n i ∈ N be maxima l such that s i ≡ • i, 1 : . . . • i,n i : s ′ i . Let G s,ρ for all 1 ≤ i ≤ ar d ( f ) instantiate the p ebbles • i with closed instances of the data patters v i , a nd for all 1 ≤ i ≤ ar s ( f ), 1 ≤ j ≤ min( n i , | u i | ) insta n tia te the p ebble • i,j with clos ed instances of the data pattern u i j , resp ectively . Lemma 3.8 . L et s ∈ T er ( L Σ M ) S , s ≡ f ( s 1 , . . . , s ar s ( f ) , • 1 , . . . , • ar d ( f ) ) and ρ ∈ R a defining rule of f ; we use the notation fr om Def. 3.7. Then G s,ρ ( s ) is a r e dex if and only if for al l 1 ≤ i ≤ ar s ( f ) we have: u i ≤ n i , that is, ther e is ‘enough supply for the applic ation of ρ ’. F urthermor e if G s,ρ ( s ) is a r e dex, then it is a r e dex with re s p e ct to ρ (and no other rule fr om R by ortho gonality). Pr o of. A consequence of the fa ct that T is an orthogo nal constr uctor TRS. ⊓ ⊔ Lemma 3.9 . L et G b e a data-exchange function, t ∈ T er ( L Σ M ) a t erm and defin e P = { p | p ∈ Pos ( t ) , r oot ( t | p ) ∈ Σ } . F or every ς : P → R such that ς ( p ) is a defining ru le for r oot ( t | p ) for al l p ∈ P , ther e is a data-exchange function G t,ς such that for al l p ∈ P if the term G t,ς ( t ) | p is a r e dex, then it is an ς ( p ) -re dex, and G t,ς ( s ) ≡ G ( s ) for al l s 6≡ t . Pr o of. F or all p ∈ P a nd ς ( p ) ≡ ℓ → r we alter G to obtain a data-gues s function G t,ς as follows. If q ∈ Pos ( ℓ ) such that ℓ | q is a data term and none of the t ( q · p ′ ) with p ′ a non empty prefix of p is a symbol fro m Σ sfun , then instantiate the data term at po sition q · p in t with an instance of the data pattern ℓ | q . Then if G t,ς ( t ) is a redex, then by o rthogonality of T it can o nly b e a ℓ → r -redex. ⊓ ⊔ History Aw are Data-Exc hange Above we hav e mo delled the o pponent using history free data -exchange strate- gies and the rewr ite play er was omniscient, that is, she alwa y s chooses the b est po ssible r ewrite s equence, which pro duces the maximum po ssible num b er of el- ement s . Now we inv estig a te the robustness of our definition. W e streng then the op- po nen t, allowing for history aw a re data-exchange stra tegies, and we weaken the rewrite play er, dr opping omnisc ie nce, a s suming only an outermost-fair rewrite strategy . How ever it turns o ut that these changes do not affect the d- o pr o duc- tion rang e do T ( s ), in this w ay providing evidence for the robustness of our first definition. Definition 3.1 0. Let T = h Σ , R i b e a stre am sp ecification. A history in T is a finite list in ( T er ( Σ ) S × R × N ∗ × T er ( Σ ) S ) ∗ of the fo r m: h s 0 , ℓ 0 → r 0 , p 0 , t 0 ih s 1 , ℓ 1 → r 1 , p 1 , t 1 i . . . h s n , ℓ n → r n , p n , t n i 14 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks such that ∀ 0 ≤ i ≤ n : s i → t i by a n a pplication of r ule ℓ i → r i at p o sition p i . W e use H T to deno te the set of all historie s o f T . A function G : H T → ( T er ( L Σ M ) S → T er ( Σ ) S ) from histor ies in T to data - exchange functions on T is c alled a history-awar e data-exchange funct ion on T . F or such a function we write G h as shor thand for G ( h ) for all h ∈ H T . Definition 3.1 1. Let T = h Σ , R i be a stream sp ecification. Let G b e a history- aw are da ta -exchange function. W e define the ARS H T , G ⊆ ( T er ( L Σ M ) S × H T ) × ( T er ( L Σ M ) S × H T ) as follows: H T , G := {h L s M , h i → h L t M , h h s, ℓ → r , p, t ii | s, t ∈ T er ( Σ ), h ∈ H T , with G h ( L s M ) = s a nd s → T t } . F or B ⊆ H T , G we define the pr o duction function Π B : T er ( Σ ) S → N by: Π B ( s ) := sup { n ∈ N | h s, ǫ i → ∗ B h u 1 : . . . : u n : t, h i } , that is, the pro duction of s starting with empty history ǫ . In an ARS H T , G we a llow to write s 0 → H T , G s 1 → H T , G s 2 → H T , G . . . when we will a ctually mea n a rewrite seq uence in H T , G of the form h s 0 , h 0 i → H T , G h s 1 , h 1 i → H T , G h s 2 , h 2 i → H T , G . . . with some histor ie s h 0 , h 1 , h 2 , . . . ∈ H T . The notion of p ositions of r ewrite steps and r e dexes extends to the ARS H T , G in the obvious w ay , s ince the steps in H T , G are pro jections of steps in T . No te that the o ppo nen t can ch ange the da ta elements in H T , G at any time, therefor e the rules might change with resp ect to which a cer tain p osition is a redex. F or this reason we adapt the notion of outermo st-fairness for o ur purp oses. Intiutiv ely , a rewr ite sequenc e is outermost-fair if e v e r y p osition which is always ev e ntually an outermost redex p osition, is r ewritten infinitely often. F or mally , w e define a rewrite sequence h s 1 , h 1 i → h s 2 , h 2 i → . . . in H T , G to b e outermost-fair if it is finite, o r it is infinite and whenever p is an outer mo st redex p osition for infinitely many s n , n ∈ N , then ther e exist infinitely man y rewrite steps s m → s m +1 , m ∈ N , at p osition p . Moreov er , a stra teg y B ⊆ H T , G is outermost-fair if every rewrite se q uence with r espec t to this strateg y is outermost-fair . Prop osition 3.12 . F or every str e am sp e cific ation T = h Σ , R i t her e exists a c omputable, deterministic om-fair stra t e gy on H T , G . Definition 3.1 3. The history awar e d-o pr o duction r ange do H T ( s ) of s ∈ T er ( L Σ M ) S is defined as follows: do H T ( s ) :=  Π B ( s ) | G a histor y-aw ar e da ta-exchange function o n T , B ⊆ H T , G an outermo s t-fair strategy  . F or s ∈ T er ( Σ ) S define do H T ( s ) := do H T ( L s M ). Note that also the strategy of the rewr ite play er B ⊆ H T , G is histor y aw are since the elements o f the ARS H T , G hav e histor y a nnotations. Data-Oblivious Stream Pro ductivity 15 Lemma 3.1 4. L et T = h Σ , R i b e a str e am sp e cific ation. L et f ∈ Σ sfun with ar s ( f ) = n and ar ( f ) = n ′ , and let s 1 , . . . , s n ∈ T er ( Σ ) S , u 1 , . . . , u n ′ ∈ T er ( Σ ) D . Then it holds: do H T ( f ( s 1 , . . . , s n , u 1 , . . . , u n ′ )) = do H T ( f ( • m 1 : σ , . . . , • m n : σ , u 1 , . . . , u n ′ )) , (1) wher e m i := do H T ( s i ) for al l i ∈ { 1 , . . . , n } . Pr o of. Let T = h Σ , R i b e a str eam sp ecification. Let f ∈ Σ sfun with ar s ( f ) = n , and s 1 , . . . , s n ∈ T er ( Σ ) S . W e assume that the data ar it y of f is zer o ; in the presence o f da ta arg uments the pro of pr o ce e ds analog o usly . F urther mo re we let m i := do H T ( s i ) for i ∈ { 1 , . . . , n } . W e show (1) by demo nstrating the inequalities “ ≤ ” and “ ≥ ” in this eq uation. ≥ : Supp ose that do H T ( f ( s 1 , . . . , s n )) = Π B ( L f ( s 1 , . . . , s n ) M ) = N ∈ N for some om-fair strategy B ⊆ H T , G and so me history- aw are data-exchange function G on T . (In case that do H T ( f ( s 1 , . . . , s n )) = ∞ , nothing remains to b e shown.) Then there exists an om-fair r ewrite sequence ξ : L f ( s 1 , . . . , s n ) M → H T , G u 1 → H T , G u 2 → H T , G . . . . . . → H T , G u l → H T , G u l +1 → H T , G . . . in H T , G with lim l →∞ # : ( u l ) = N . Due to the definition of the num b e r s m i , ah history- aw are data- e x c ha nge function G ′ from H T to data-exchange functions ca n be defined that ena bles a re write sequence ξ ′ : f ( • m 1 : σ , . . . , • m n : σ ) → = H T , G ′ u ′ 1 → = H T , G ′ u ′ 2 → = H T , G ′ . . . . . . → = H T , G ′ u ′ l → = H T , G ′ u ′ l +1 → = H T , G ′ . . . with the pr o per ties that # : ( u l ) = # : ( u ′ l ) ho lds for all l ∈ N , and that ξ ′ is the pro jection of ξ to a rewr ite sequence with source f ( • m 1 : σ , . . . , • m n : σ ). More precisely , ξ ′ arises a s follows: Steps u l → H T , G u l +1 in ξ that co ntract redexes in descendants of the outermost sym b ol f in the source o f ξ give rise to s teps u ′ l → H T , G ′ u ′ l +1 that co ntract redex e s at the same p ositio n and apply the same rule. This is p ossible b ecause, due to the definition of the nu mber s m i , always enoug h pebble- supply is gua ranteed to ca rry out steps in ξ ′ corres p onding to such steps in ξ . Steps u l → H T , G u l +1 that contract redexes in descendants o f one of the subterms s 1 , . . . , s n in the source of ξ pr o ject to empty steps u ′ l = u ′ l +1 in ξ ′ . (On his tories h ∈ H T and terms r ∈ T er ( L Σ M ) S o ccurring in ξ , G ′ is defined in such a wa y as to make this pro jection p oss ible. On histor ies h and ter ms r that do not o ccur in ξ ′ , G ′ is defined arbitrarily with the only r estriction L G h ( r ) M ensuring that G ′ behaves as a history-aware da ta-exchange function on these terms.) By its co nstruction, ξ ′ is ag ain om-fair. Now let B ′ be the extension of the sub-ARS o f H T , G induced by ξ ′ to a deterministic om-fair strategy for H T , G ′ . (Cho ose an a r bitrary deterministic om-fair s trategy ˜ B on H T , G , which is 16 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks po ssible by Prop osition 3.12. On term-histor y pa irs that do not o ccur in ξ ′ , define B ′ according to ˜ B .) Then ξ ′ is also a rewrite sequence in B ′ that witnesses Π B ( f ( • m 1 : σ, . . . , • m n : σ )) = lim l →∞ # : ( u ′ l ) = lim l →∞ # : ( u l ) = N = Π B ( L f ( s 1 , . . . , s n ) M ). Now it follows: do H T ( f ( • m 1 : σ , . . . , • m n : σ )) ≤ Π B ′ ( f ( • m 1 : σ , . . . , • m n : σ )) = Π B ( L f ( s 1 , . . . , s n ) M ) = do H T ( f ( s 1 , . . . , s n )) , establishing “ ≥ ” in (1). ≤ : Supp ose that do H T ( f ( • m 1 : σ, . . . , • m n : σ )) = Π B ( f ( • m 1 : σ , . . . , • m n : σ )) = N for some N ∈ N , and an om- fa ir stra tegy B ⊆ H T , G and a histo ry-aw ar e data- exchange function G on T . (In cas e that do H T ( f ( • m 1 : σ, . . . , • m n : σ )) = ∞ , nothing remains to be shown.) Then there ex ists an om-fair rewr ite sequence ξ : f ( • m 1 : σ , . . . , • m n : σ ) → H T , G u 1 → H T , G u 2 → H T , G . . . → H T , G u l → H T , G u l +1 → H T , G . . . in H T , G with lim l →∞ # : ( u l ) = N . Let l 0 ∈ N b e minimal such tha t # : ( u l 0 ) = N . F urthermore, let, for all i ∈ { 1 , . . . , n } , m ′ i ≤ m i be minimal such that each of the topmost m ′ i symbols “ • ” of the subterm • m i : σ of the source f ( • m 1 : σ, . . . , • m n : σ ) of ξ is part o f a redex pa ttern at so me step among the first l 0 steps o f ξ . Since by assumption, we have m i := do H T ( s i ) for i ∈ { 1 , . . . , n } , there exis t, for ea c h i ∈ { 1 , . . . , n } , histor y-aw ar e data-guess functions G i , a nd om-fair strategies B i ⊆ H T , G i such tha t Π B i ( L s i M ) = m i ; let all B i and G i be chosen as such. Then there exist, for each i , om-fair rewrite sequences o f the form: ξ i : L s i M → H T , G i u i, 1 → H T , G i . . . → H T , G i u i,l i = • m ′ i : ˜ u i,l i → H T , G i . . . in H T , G with lim l →∞ # : ( u i,l ) = m i . Now it is p ossible to combine the histor y-aw are data-ex change functions G , G 1 , . . . , G n int o a function G ′ that makes it po ssible to combine the re w r ite sequences ξ and ξ 1 , . . . , ξ n int o a rewrite s e quence of the form: ξ ′ : L f ( s 1 , . . . , s n ) M → ∗ H T , G ′ f ( • m ′ 1 : u 1 ,l 1 , . . . , • m ′ n : u n,l n ) (carry out the fir st l i steps in ξ i in the context f ( 2 1 , . . . , 2 n )) → H T , G ′ u ′ 1 → H T , G ′ u ′ 2 → H T , G ′ . . . → H T , G ′ u ′ l 0 = • N : ˜ u ′ l 0 (parallel to the firs t l 0 steps o f ξ ) → H T , G ′ w 1 → H T , G ′ w 2 → H T , G ′ . . . (fair interleaving of the rests of the ξ i put in context and of steps para llel to the rest of ξ ′ ) By its construction, ξ ′ is ag a in o m-fair and it holds: lim l →∞ w l = N . Now let B ′ be the extensio n of the s ub- ARS of H T , G induced by ξ ′ to a deterministic Data-Oblivious Stream Pro ductivity 17 om-fair strategy for H T , G ′ . (Aga in choose an arbitrar y deterministic om-fair strategy ˜ B o n H T , G , which is p ossible by Pro p os itio n 3.1 2. On term-history pairs that do not o ccur in ξ ′ , define B ′ according to ˜ B .) Then ξ ′ is also a rewrite sequence in B ′ that w itnes s es Π B ( L f ( s 1 , . . . , s n ) M ) = lim l →∞ # : ( w l ) = N = Π B ( f ( • m 1 : σ , . . . , • m n : σ )). Now it follows: do H T ( f ( s 1 , . . . , s n )) ≤ Π B ( L f ( s 1 , . . . , s n ) M ) = Π B ′ ( f ( • m 1 : σ , . . . , • m n : σ )) = do H T ( f ( • m 1 : σ , . . . , • m n : σ )) , establishing “ ≤ ” in (1). ⊓ ⊔ Lemma 3.1 5. L et s ∈ T er ( L Σ M ) S b e a str e am t erm and φ : V ar S → T er ( L Σ M ) S a substitu tion of str e am variables. Then do H T ( s φ ) = do H T ( s ϕ ) wher e ϕ : V ar S → T er ( L Σ M ) S is define d by ϕ ( τ ) = • m τ : σ , and m τ := do H T ( φ ( τ )) . Pr o of. Induction using Le m. 3.14 . ⊓ ⊔ Corollary 3.1 6. L et s ∈ T er ( L Σ M ) S and φ, ϕ : V ar S → T er ( L Σ M ) S substitutions of str e am variables such that do H T ( φ ( τ )) = do H T ( ϕ ( τ )) for al l τ ∈ V ar S . Then do H T ( s φ ) = do H T ( s ϕ ) . Pr o of. Two applications of Lem. 3.15. ⊓ ⊔ W e define a histor y free data-exchange function G T such that no reduction with res pect to G T pro duces mor e than do H T ( s ) elements. Definition 3.1 7. Let a strea m sp ecification T = h Σ , R i b e given, and let > b e a w ell-founded order on R . W e define the lower b ou n d data-exchange fun ction G T : T er ( L Σ M ) S → T er ( Σ ) S as follows. Let s ∈ T er ( L Σ M ) S and f ( s 1 , . . . , s ar s ( f ) , • 1 , . . . , • ar d ( f ) ) a subterm o ccurrence of s . F or i = 1 , . . . , ar s ( f ) let n i ∈ N b e maximal such that s i ≡ • i, 1 : . . . • i,n i : s ′ i . W e define m i := do H T ( s i ) for 1 ≤ i ≤ n , then we hav e by Lem. 3.1 4: do H T ( t := f ( s 1 , . . . , s ar s ( f ) , • 1 , . . . , • ar d ( f ) )) = do H T ( t ′ := f ( • m 1 : σ , . . . , • m ar s ( f ) : σ , • 1 , . . . , • ar d ( f ) )) . W e choo se a defining rule ρ of f as follows. I n case there exists a rule γ : f ( u 1 : σ 1 , . . . , u n : σ n , v 1 , . . . , v ar d ( f ) ) → t ∈ R such that m i < | u i | for some i ∈ { 1 , . . . , n } , then let ρ := γ . In ca s e ther e a re m ultiple p ossible choices for γ , we pick the minimal γ with r esp ect to > . Otherwise in exists a history-aw ar e data -exchange function G , and an outermo s t- fair rewrite sequence σ : t ′ → H T , G . . . in H T , G pro ducing only do H T ( t ′ ) element s . F rom exhaustivity o f T we get G ( t ′ ) is not a normal form, since all rules have 18 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks enough supply . Moreover, by orthogonality e xactly one defining rule γ of f is ap- plicable, let ρ := γ . Ag a in, in ca se there a r e multiple p oss ible choices for γ , due to freedom in the choice of the data- exchange function G , we take the minimal γ with resp ect to > . W e define G T to insta n tiate: – for 1 ≤ i ≤ ar d ( f ) the o ccur rences of p ebbles • i in s , and – for 1 ≤ i ≤ ar s ( f ), 1 ≤ j ≤ n i the o ccurr ences of p ebbles • i,j in s with res pect to the rule ρ (Def. 3.7). Rewrite steps with resp ect to the low er bound data- e xch ange function G T do not change the d-o low er b ound of the pro duction o f a ter m. Lemma 3.1 8. F or al l s, s ∈ T er ( L Σ M ) S : s → A T , G T t implies do H T ( s ) = do H S ( t ) . Pr o of. W e use the notions intro duced in Def. 3.17. Note that the low er b ound data-exchange function G T is de fined in a w ay that the p ebbles a re instantiated independent of the context ab ov e the stream function sym b ol. There fo re it is sufficient to conside r rew r ite steps s → A T , G T t a t the ro ot, closur e under con tex ts follows fro m Cor. 3 .16. ⊓ ⊔ Corollary 3.1 9. F or al l s ∈ T er ( L Σ M ) S we have: Π A T , G T ( s ) = do H T ( s ) . Pr o of. Direct conseq ue nc e of Lem. 3.18. ⊓ ⊔ Hence, as a co nsequence of Cor. 3.19 , the low er b ound o f the his tory-free d-o pro duction conincides with the lower b ound of the history-aw a re d-o pro duction. Lemma 3.2 0. F or al l s ∈ T er ( Σ ) S we have: do T ( s ) = do H T ( s ) . Pr o of. The direction do T ( s ) ≥ do H T ( s ) is trivial, and do T ( s ) ≤ do H T ( s ) follows from Cor . 3.19, that is, using the history-free data -exchange function G T no reduction pro duces more than do H T ( s ) elements. ⊓ ⊔ Lemma 3.2 1. F or al l s ∈ T er ( Σ ) S we have: do T ( s ) = do H T ( s ) . Pr o of. ⊆ Let n ∈ do T ( s ). Then ther e ex ists a data - exchange function G such that Π A T , G ( s ) = n , and a rewrite sequence σ : s 0 → A T , G . . . → A T , G s m with s m ≡ u 1 : . . . : u n : t . W e define for all h ∈ H T a data-exchange function G h by setting G h ( s ) := G ( s ) fo r all s ∈ T er ( L Σ M ) S . Mo reov er, we define the strategy B ⊆ H T , G to execute σ and con tin ue outermos t- fa ir afterwards. Since s m do es not produce mor e than n elements, ev ery maximal rewrite sequence with res pect to B will pro duce exactly n elements. Hence n ∈ do H T ( s ). ⊇ Let n ∈ do H T ( s ). Then there exist data- exchange functions G h for every h ∈ H T , and an o utermost-fair strateg y B ⊆ H T , G such that Π B ( s ) = n . There exists a (p ossibly infinite) maxima l, outermost-fair r ewrite sequence σ : h s, ǫ i ≡ h s 0 , h 0 i → B . . . → B h s m , h m i → B . . . Data-Oblivious Stream Pro ductivity 19 such that s m ≡ u 1 : . . . : u n : t . Since the elements of H T , G are annotated with their histor y , we do not enco un ter rep etitions during the rewr ite sequence. Hence, w.l.o.g. we can a ssume that B is a deterministic stra tegy , a dmitting only the maximal r ewrite s e quence σ . Disregar ding the histo r y a nnotations there might exist re p etitions, that is, i < j ∈ N with s i ≡ s j . Nevertheless, from σ we ca n construct a history free data-exchange function G as follows. F or all s ∈ T er ( L Σ M ) S let S := { i ∈ N | s i ≡ s } and define: G ′ ( s ) :=      G h j ( s j ) if j := sup S < ∞ G h k ( s k ) if sup S = ∞ , k := inf S arbitrar y if ¬∃ i ∈ N . s i ≡ s ⊓ ⊔ 4 The Pro duction Calculus As a means to compute the d- o pro duction b ehaviour of strea m sp ecifications, we introduce a ‘pro ductio n ca lculus’ with p erio dica lly increasing functions a s its central ingr edien t. This calculus is the term eq uiv a len t of the calculus of pebbleflow nets that was introduced in [2], see Se c . 4.3. 4.1 P erio d i cally Increasing F unctions W e use N := N ⊎ {∞} , the extende d natu r al numb ers , with the usual ≤ , +, a nd we define ∞ − ∞ := 0 . An infinite sequence σ ∈ X ω is eventual ly p erio dic if σ = αβ β β . . . for s o me α ∈ X ∗ and β ∈ X + . A function f : N → N is eventual ly p erio dic if the sequence h f (0) , f (1 ) , f (2 ) , . . . i is even tually p erio dic. Definition 4.1 . A function g : N → N is called p erio dic al ly incr e asing if it is increasing , i.e. ∀ n. g ( n ) ≤ g ( n + 1), and the derivative of g , n 7→ g ( n + 1) − g ( n ), is even tua lly p erio dic. A function h : N → N is called p erio di- c al ly incr e asing if its restr ic tion to N is p erio dica lly increas ing and if h ( ∞ ) = lim n →∞ h ( n ). Finally , a k -ary function i : ( N ) k → N is called p erio dic al ly in- cr e asing if i ( n 1 , ..., n k ) = min( i 1 ( n 1 ) , . . . , i k ( n k )) for some unary p erio dically increasing functions i 1 , . . . , i k . Periodica lly increasing (p-i) functions can b e denoted by their v alue at 0 follow ed by a r epresentation o f their deriv ative. F or ex ample, 03 12 denotes the p-i function f : N → N with v a lues 0 , 3 , 4 , 6 , 7 , 9 , . . . . How e v e r , we use a finer and more fle x ible no ta tion ov er the alphab et { + , −} that will b e useful for computing several o per a tions on p-i functions. F or instance, we represent f as above by the ‘io-sequence’ − +++ − + − ++ = − +++ − + − ++ − + − ++ − + − + + . . . , in turn abbrevia ted by the ‘io- term’ h− +++ , − + − ++ i . 20 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Definition 4.2 . Let ± := { + , − } . An io-se quenc e is a finite ( ∈ ± ∗ ) or infinite sequence ( ∈ ± ω ) over ± , the set of io-sequences is denoted by ± ∞ := ± ∗ ∪ ± ω . W e let ⊥ denote the empty io- sequence, and use it as an ex plicit end marker. An io-term is a pair h α, β i of finite io-sequences α, β ∈ ± ∗ with β 6 = ⊥ . The set of io-ter ms is denoted b y I , a nd we use ι, κ to range ov er io-ter ms. F or a n io-sequence σ ∈ ± ω and an io-term ι = h α, β i ∈ I we say that ι denotes σ if σ = α β where β stands for the infinite sequence β β β . . . . A sequence σ ∈ ± ∞ is r ational if it is finite or if it is denoted b y an io-term. T he se t of rational io-sequences is denoted by ± ∞ R . An infinite sequence σ ∈ ± ω is pr o ductive if it contains infinitely many +’s: σ ∈ ± ω is pr o ductive ⇐ ⇒ ∀ n. ∃ m ≥ n. σ ( m ) = + . W e let ± ω P denote the set of pro ductive sequences and define ± ∞ P := ± ∗ ∪ ± ω P . The reaso n for having b oth io-terms and io-s e quences is that, dep ending on the purp ose at hand, one o r the other is mor e conv enient to work with. Op erations are often easier to unders ta nd o n io -sequences than on io - terms, where as we need finite repr esentations to b e able to compute these op erations . Definition 4.3 . W e define [ [ σ ] ] : N → N , the interpr etation of σ ∈ ± ∞ , by: [ [ ⊥ ] ]( n ) = 0 (2) [ [+ σ ] ]( n ) = 1 + [ [ σ ] ]( n ) (3) [ [ − σ ] ](0) = 0 (4) [ [ − σ ] ]( n + 1) = [ [ σ ] ]( n ) (5) for all n ∈ N , and extend it to N → N by defining [ [ σ ] ]( ∞ ) = lim n →∞ [ [ σ ] ]( n ). W e say that [ [ σ ] ] interpr ets σ , and, conversely , that σ r epr esents [ [ σ ] ]. W e overload notation and define [ [ ] ] : I → ( N → N ) b y [ [ h α, β i ] ] := [ [ αβ ] ]. It is easy to v e r ify tha t, for every σ ∈ ± ∞ , the function [ [ σ ] ] is increasing , and that, for every ι ∈ I , the function [ [ ι ] ] is p erio dica lly incr easing. F urthermor e, every increasing function is r epresented b y an io-sequence, and every p-i function is deno ted b y an io-term. Subsequently , for an e v e ntually co nstant function f : N → N , w e write f for the shortest finite io- sequence repr esent ing f (trailing − ’s can b e removed). F or an alwa ys even tually strictly increasing function f : N → N , i.e. ∀ n. ∃ m > n. f ( m ) > f ( n ), we write f for the unique io-s equence representing f ; note that then f ∈ ± ω P follows. F or a p erio dically incr easing function f : N → N , we w r ite f for the io-term ι = h α, β i such that [ [ ι ] ] = f and | α | + | β | is minimal; uniqueness follows fro m the following lemma: Lemma 4.4 . F or al l p-i functions f : N → N , the term f ∈ I is unique. Data-Oblivious Stream Pro ductivity 21 Pr o of. Co ns ider the ‘c o mpression’ TRS consisting o f the rules : h αx, β x i → h α, xβ i ( x ∈ ± ) (6) h α, β p i → h α, β i ( n > 1) (7) Clearly , ι → κ implies | ι | > | κ | wher e, for ι = h α, β i , | ι | := | α | + | β | . Hence , compressio n is terminating. There are tw o cr itical pair s due to an ov er lap of rule (7) with itself, a nd in rules (6 ) and (7): hh α, β n i , h α, β m ii orig ina ting from a term of the form h α, β n · m i , and hh α, ( xβ ) n i , h αx, β x ii originating fr om a term o f the form h αx, ( β x ) n i , r e- sp ectiv ely . Both pa irs are ea sily joinable in one step: the first to h α, β i , a nd the second to h α, xβ i . Hence, the system is lo cally confluent. Therefore, b y Newma n’s Lemma, it is a ls o co nfluen t, and no r mal forms a re unique. Finally , assume that t wo io - terms h α 1 , β 1 i , h α 2 , β 2 i ∈ I each of minimal length repr esent the sa me p-i function f . It is ea sy to see that then α 1 β 1 = α 2 β 2 . It follows that there exist h α, β i such that h α, β i → ∗ h α 1 , β 1 i and h α, β i → ∗ h α 2 , β 2 i . By confluence and termination of compre s sion it follows that they hav e the same normal form h α 0 , β 0 i . Since compression reduces the length of io-terms it must follow tha t h α 1 , β 1 i = h α 0 , β 0 i = h α 2 , β 2 i . ⊓ ⊔ Note that we hav e that [ [ f ] ] = f fo r all increa s ing functions f , and [ [ f ] ] = f for all p-i functions f . As an example one can check tha t the in ter pretation of the afor emen tio ne d io -term f = h − +++ , − + − ++ i indeed ha s the sequence 0 , 3 , 4 , 6 , 7 , 9 , . . . as its g raph. R emark 4.5. Note that Def. 4.3 is well-defined due to the pr o ductivit y requir e- men t on infinite io-s e q uences. This ca n b e seen as follows: star ting o n [ [ σ ] ]( n ), after finitely many , say m ∈ N , − ’s, we either ar r ive at rule (3) (if m ≤ n ) o r a t rule (4) (if m > n ). Had we no t r e quired infinite sequences σ ∈ ± ω to contain infinitely many + ’s, then, e.g ., the computation o f [ [ −−− . . . ] ]( ∞ ) would co nsist of applications o f r ule (5) only , and hence would not lea d to an infinite no rmal form. Prop osition 4.6. Unary p erio dic al ly incr e asing functions ar e close d under c om- p osition and p ointwise infimum. W e wan t to co nstructively define the oper ations of comp osition, p oint wise in- fim um, and least fixed p oint calculation of increa sing functions (p-i functions) on their io- sequence (io - term) r epresentations. W e first define these o per ations on io-s e quences by means of co inductiv e clauses. The op erations on io-terms are mo re in volved, beca use they require ‘lo op chec king’ on top. W e will pro ceed by showing that the operatio ns of c o mpo s ition and point wise infim um on io- sequences preser v e r ationality . This will then give r ise to the needed algorithms for computing the op erations on io - terms. 22 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Definition 4.7 . The oper ation c omp osition ◦ : ± ∞ P × ± ∞ P → ± ∞ P , h σ , τ i 7→ σ ◦ τ of (fin ite or pr o ductive) io-se quenc es is defined co inductiv e ly as follows: ⊥ ◦ τ = ⊥ (8) + σ ◦ τ = +( σ ◦ τ ) (9) − σ ◦ ⊥ = ⊥ (1 0) − σ ◦ + τ = σ ◦ τ (11) − σ ◦ − τ = − ( − σ ◦ τ ) (12) An a rgument simila r to Rem. 4.5 concer ning well-definedness applies for Def. 4.7 . R emark 4.8. Note that the defining rules (8 )– (12) ar e orthogona l and exhaust all cases. As it stands, it is not immediately clea r that this definition is well-defined (pro ductive!), the pr oblematic c a se b eing (11 ). Rule (11) is to b e thought of as an in ter nal communication b etw een comp onents σ and τ , as a silent step in the black b ox σ ◦ τ . How to guarantee tha t alwa ys , after finitely ma ny internal steps , either the pro cess ends or there will b e an ex ter nal step, in the for m o f o utput or a requir e men t for input? The recur sive call in (11) is not guarded. How ever, well-definedness o f comp osition can b e justified as follows: Consider arbitrar y sequences σ , τ ∈ ± ∞ P . B y definitio n o f ± ∞ P , ther e e x ists m ∈ N such that σ = − m + σ ′ for so me σ ′ ∈ ± ∞ P or σ = − m ⊥ ; likewise there exists n ∈ N such that τ = − n + τ ′ for some τ ′ ∈ ± ∞ P , or τ = − n ⊥ . Rules (11 ) and (12) a re decreasing with resp ect to the lexicographic order on ( m, n ). After finitely many applications of (11) and (12), one o f the r ules (8)–(10) must b e applied. Hence comp osition is well-defined and the s equence pro duced is a n element of ± ∞ P , i.e. either it is a finite seq uence or it contains an infinite nu mber o f +’s. Lemma 4.9 . Comp osition of io-se quenc es is asso ciative. Pr o of. Let R = { h σ ◦ ( τ ◦ υ ) , ( σ ◦ τ ) ◦ υ i | σ, τ , υ ∈ ± ∞ P } . T o show that R is a bisimulation, we prove that, for all σ, τ , υ , φ 1 , φ 2 ∈ ± ∞ P , if φ 1 = σ ◦ ( τ ◦ υ ) and φ 2 = ( σ ◦ τ ) ◦ υ , then either φ 1 = ⊥ = φ 2 or head ( φ 1 ) = head ( φ 2 ) and h tail ( φ 1 ) , tail ( φ 2 ) i ∈ R , by induction on the num b er n ∈ N of leading − ’s of σ 4 , and a sub-induction on the nu mber m ∈ N of leading − ’s of τ . If n = 0 a nd σ = ⊥ , then φ 1 = ⊥ = φ 2 . If σ = + σ ′ , we hav e φ 1 = +( σ ′ ◦ ( τ ◦ υ )), and φ 2 = +(( σ ′ ◦ τ ) ◦ υ ), a nd so h ta il ( φ 1 ) , tail ( φ 2 ) i ∈ R . If n > 0, then σ = − σ ′ , a nd we pr o c eed by s ub-induction o n m . If m = 0 and τ = ⊥ , then φ 1 = ⊥ = φ 2 . If τ = + τ ′ , we compute φ 1 = σ ′ ◦ ( τ ′ ◦ υ ), and φ 2 = ( σ ′ ◦ τ ′ ) ◦ υ , and conclude by IH. If m > 0 , then τ = − τ ′ , and we pro ceed by ca se distinction on υ . If υ = ⊥ , then φ 1 = ⊥ = φ 2 . If υ = + υ ′ , we compute φ 1 = σ ◦ ( τ ′ ◦ υ ′ ), a nd φ 2 = ( σ ◦ τ ′ ) ◦ υ ′ , and conclude by sub-IH. Finally , if υ = − υ ′ , then φ 1 = − ( σ ◦ ( τ ◦ υ ′ )), and φ 2 = − (( σ ◦ τ ) ◦ υ ′ ). Clear ly h tail ( φ 1 ) , tail ( φ 2 ) i ∈ R . ⊓ ⊔ 4 By definition of ± ∞ P the num b er of leading − ’s of any sequence in ± ∞ P is finite: for all σ ∈ ± ∞ P there exists n ∈ N such that either σ = − n ⊥ or σ = − n + σ ′ . Data-Oblivious Stream Pro ductivity 23 R emark 4.10. If we a llow to us e extended na tural num b ers a t pla c e s where an io-sequence is exp ected, using a co ercion n 7→ + n , with + 0 = ⊥ , o ne obser ves that the interpretation of a n io-se quence (Def. 4.3) is just a sp ecial case o f comp osition: [ [ σ ] ]( n ) = σ ◦ n . Prop osition 4.11 . F or al l incr e asing functions f , g : N → N : [ [ f ◦ g ] ] = [ [ f ] ] ◦ [ [ g ] ] . Pr o of. Immediate from Rem. 4.10 , and Lem. 4.9. ⊓ ⊔ Next, we show that c ompo sition of io-sequences pre s erves ratio na lit y . Lemma 4.1 2. If σ, τ ∈ ± ∞ R , then σ ◦ τ ∈ ± ∞ R . Pr o of. Let σ, τ ∈ ± ∞ R and set σ 0 := σ a nd τ 0 := τ . In the rewrite sequence starting with σ 0 ◦ τ 0 each of the steps is either of the form: σ n ◦ τ n → C n [ σ n +1 ◦ τ n +1 ] , (13) where σ n +1 ∈ { σ n , tail ( σ n ) } , τ n +1 ∈ { τ n , tail ( τ n ) } and C n ∈ {  , + :  , − :  } , or the rewr ite sequence ends with a step of the form: σ n ◦ τ n → ⊥ . In the latter ca se, σ ◦ τ results in a finite and he nc e rational io-sequence. Otherwise the rewrite se quence is infinite, consisting o f s teps of form (13) only . F or θ ∈ ± ∗ we define the context C θ inductively: C θ ≡  , for θ ≡ ⊥ ; and C + θ ≡ + C θ as well as C − θ ≡ − C θ , for all θ ∈ ± ∗ . Becaus e the se quences σ , τ a re rationa l, the sets { σ n | n ∈ N } and { τ n | n ∈ N } are finite. Then, the pigeonhole principle implies the existence o f i, j ∈ N such that i < j , σ i = σ j and τ i = τ j . Now let α, γ ∈ ± ∗ with γ 6 = ⊥ s uc h tha t C α ≡ C 0 [ . . . C i − 1 [ C i ] . . . ], C γ ≡ C i +1 [ . . . C j − 1 [ C j ] . . . ], and: σ 0 ◦ τ 0 → ∗ C α [ σ i ◦ τ i ] , and σ i ◦ τ i → ∗ C γ [ σ j ◦ τ j ] = C γ [ σ i ◦ τ i ] . Then we find an even tually ‘spir alling’ rewr ite seq uenc e : σ 0 ◦ τ 0 → ∗ C α [ σ i ◦ τ i ] = α ( σ i ◦ τ i ) → ∗ C α [ C γ [ σ i ◦ τ i ]] = αγ ( σ i ◦ τ i ) → ∗ C α [ C γ [ C γ [ σ i ◦ τ i ]]] = αγ γ ( σ i ◦ τ i ) , and therefore σ 0 ◦ τ 0 ։ ։ α γ . This shows that σ ◦ τ is ratio nal. ⊓ ⊔ Next, we define the op era tion of p oint wise infimum o f increa sing functions on io-se q uences. 24 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Definition 4.1 3. The op eration p ointwise infimum ∧ : ± ∞ × ± ∞ → ± ∞ , h σ , τ i 7→ σ ∧ τ of io-se quenc es is defined c o inductiv e ly by the following eq uations: ⊥ ∧ τ = ⊥ del ( ⊥ ) = ⊥ σ ∧ ⊥ = ⊥ del (+ σ ) = + del ( σ ) + σ ∧ + τ = +( σ ∧ τ ) d e l ( − σ ) = σ − σ ∧ τ = − ( σ ∧ del ( τ )) ( τ 6 = ⊥ ) σ ∧ − τ = − ( del ( σ ) ∧ τ ) ( σ 6 = ⊥ ) where del ( σ ) remov es the first r equirement of σ ∈ ± ∞ (if any). W e let ◦ bind stronger than ∧ . Requirement remov al dis tributes over p oint wise infimum: Lemma 4.1 4. F or al l σ, τ ∈ ± ∞ P , it holds that: del ( σ ∧ τ ) = del ( σ ) ∧ del ( τ ) . Pr o of. Check that {h del ( σ ∧ τ ) , del ( σ ) ∧ del ( τ ) i | σ, τ ∈ ± ∞ } ∪ {h σ , σ i | σ ∈ ± ∞ } is a bisimulation. ⊓ ⊔ Lemma 4.1 5. Infimum is idemp otent, c ommutative, and asso ciative. Pr o of. By coinduction, with the use of Lem. 4 .14 in ca se of ass o ciativity . ⊓ ⊔ In a comp osition req uirement s co me from the second co mponent: Lemma 4.1 6. F or al l σ, τ ∈ ± ∞ P , it holds that: del ( σ ◦ τ ) = σ ◦ del ( τ ) . Comp osition distributes bo th left and rig h t ov er p oint wise infimum: Lemma 4.1 7. F or al l σ, τ , υ ∈ ± ∞ P , it holds that: σ ◦ ( τ ∧ υ ) = σ ◦ τ ∧ σ ◦ υ . Pr o of. By co induction; let L = {h σ ◦ ( τ ∧ υ ) , σ ◦ τ ∧ σ ◦ υ i | σ , τ , υ ∈ ± ∞ P } . T o show tha t L is a bisim ulation, we prov e that, for all σ , τ , υ , φ 1 , φ 2 ∈ ± ∞ P , if φ 1 = σ ◦ ( τ ∧ υ ) and φ 2 = σ ◦ τ ∧ σ ◦ υ , then e ither φ 1 = ⊥ = φ 2 , or head ( φ 1 ) = head ( φ 2 ) and h tail ( φ 1 ) , tail ( φ 2 ) i ∈ L , b y induction o n the n umber n ∈ N o f leading − ’s of σ . If n = 0 and σ = ⊥ , then φ 1 = ⊥ = φ 2 . If n = 0 and σ = + σ ′ , then: φ 1 = +( σ ′ ◦ ( τ ∧ υ )), and φ 2 = +( σ ′ ◦ τ ∧ σ ′ ◦ υ ), and so h tail ( φ 1 ) , tail ( φ 2 ) i ∈ L . If n > 0 and σ = − σ ′ , we pro ceed by case ana lysis of τ and υ . If one of τ , υ is empty , then φ 1 = ⊥ = φ 2 . If τ = + τ ′ and υ = + υ ′ , then φ 1 = σ ′ ◦ ( τ ′ ∧ υ ′ ) and φ 2 = σ ◦ τ ∧ σ ◦ υ , and we conclude by the induction h y pothes is. If τ = + τ ′ and υ = − υ ′ , then φ 1 = − ( σ ◦ ( del ( τ ) ∧ υ ′ )) and φ 2 = − ( del ( σ ◦ τ ) ∧ σ ◦ υ ′ ) = − ( σ ◦ del ( τ ) ∧ σ ◦ υ ′ ) by Lem. 4.1 6. Th us h tail ( φ 1 ) , tail ( φ 2 ) i ∈ L . The case τ = − τ ′ , υ = + υ ′ is proved similarly . Finally , if τ = − τ ′ and υ = − υ ′ , w e compute φ 1 = − ( σ ◦ ( τ ′ ∧ υ ′ )) and φ 2 = − ( σ ◦ τ ′ ∧ σ ◦ υ ′ ), and conclude h tai l ( φ 1 ) , tail ( φ 2 ) i ∈ L . ⊓ ⊔ Data-Oblivious Stream Pro ductivity 25 Lemma 4.1 8. F or al l σ, τ , υ ∈ ± ∞ P , it holds that: ( τ ∧ υ ) ◦ σ = τ ◦ σ ∧ υ ◦ σ . Pr o of. Analo gous to the pro of o f Lem. 4.1 7. ⊓ ⊔ The op eration of p oint wise infim um of (p erio dically ) incr easing functions is defined on their io -sequence (io-term) representations. Prop osition 4.19 . F or al l incr e asing functions f , g : N → N : [ [ f ∧ g ] ] = [ [ f ] ] ∧ [ [ g ] ] . Pr o of. Immediate from Rem. 4.10 a nd Lem. 4.18. ⊓ ⊔ W e give a coinductive definition o f the calcula tion o f the least fixed p oint of an io-se q uence. The op eratio n del was defined in Def. 4 .13. Definition 4.2 0. The op er ation fix : ± ∞ → N c omputing the le ast fixe d p oint of a s e qu enc e σ ∈ ± ∞ , is defined, for all σ ∈ ± ∞ , by: fix ( ⊥ ) = 0 fix (+ σ ) = 1 + fix ( del ( σ )) fix ( − σ ) = 0 Remov al of a requir emen t and feeding an input hav e equal effect: Lemma 4.2 1. F or al l σ, τ ∈ ± ∞ P , it holds that: del ( σ ) ◦ τ = σ ◦ (+ τ ) . Pr o of. W e show that R = {h del ( σ ) ◦ τ , σ ◦ (+ τ ) i } ∪ {h σ , σ i} is a bis im ulatio n, b y case a nalysis of σ . F or σ = ⊥ , and σ = − σ ′ , h del ( σ ) ◦ τ , σ ◦ (+ τ ) i ∈ R follows by reflexivity . If σ = + σ ′ , then del ( σ ) ◦ τ = +( del ( σ ′ ) ◦ τ ), and σ ◦ (+ τ ) = + ( σ ′ ◦ (+ τ )). Hence, h tail ( de l ( σ ) ◦ τ ) , tail ( σ ◦ (+ τ )) i ∈ R . ⊓ ⊔ The following prop osition states that fix ( σ ) is a fixed po in t of [ [ σ ] ]: Prop osition 4.22 . F or al l σ ∈ ± ∞ P , it holds that: [ [ σ ] ]( fix ( σ )) = fix ( σ ) . Pr o of. W e prov e fi x ( σ ) = σ ◦ fix ( σ ) by case analysis and coinduction. If σ = ⊥ , then fi x ( σ ) = ⊥ = σ ◦ fix ( σ ). If σ = − σ ′ , then fix ( σ ) = ⊥ , and σ ◦ fi x ( σ ) = ( − σ ′ ) ◦ ⊥ = ⊥ . If σ = + σ ′ , then fix ( σ ) = + fix ( del ( σ ′ )) and σ ◦ fix ( σ ) = +( σ ′ ◦ (+ fix ( del ( σ ′ )))), and we have to prov e that fix ( del ( σ ′ )) = σ ′ ◦ (+ fix ( del ( σ ′ ))) which follows by an instance of Lem. 4 .21: σ ′ ◦ (+ fix ( del ( σ ′ ))) = del ( σ ′ ) ◦ fix ( del ( σ ′ )). ⊓ ⊔ Lemma 4.2 3. F or al l σ ∈ ± ∞ , it holds that: lfp([ [ σ ] ]) = fi x ( σ ) . Pr o of. 26 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks 4.2 Computing Pro duction W e intro duce a term syn tax fo r the productio n calculus and rewrite r ules for ev aluating clos e d terms. Definition 4.2 4. Let X be a set of recurs ion v aria bles . The s et of pr o duction terms P is gener ated by: p ::= k | x | • ( p ) | f ( p ) | µx.p | min ( p, p ) where x ∈ X , for k ∈ N , the symbol k is a numer al (a term representation) for k , and, for a unar y p-i function f : N → N , f ∈ I , the io -term re pr esenting f . F or every finite set P = { p 1 , . . . , p n } ⊆ P , we use min ( p 1 , . . . , p n ) and min P as shorthands fo r the pr o duction term min ( p 1 , min ( p 2 , . . . , min ( p n − 1 , p n ))). The ‘pr o duction’ [ [ p ] ] ∈ N o f a clos e d pro duction term p ∈ P is defined by induction on the term structure, interpreting µ as the least fixed po in t op erator, f as f , k as k , and min as min , as follows. Definition 4.2 5. The pr o duction [ [ p ] ] α ∈ N of a term p ∈ P w ith r esp e ct to an assignment α : X → N is defined inductively by: [ [ k ] ] α = k [ [ ι ( p )] ] α = [ [ ι ] ]([ [ p ] ] α ) [ [ x ] ] α = α ( x ) [ [ µx.p ] ] α = lfp( λn. [ [ p ] ] α [ x 7→ n ] ) [ [ • ( p )] ] α = 1 + [ [ p ] ] α [ [ min ( p 1 , p 2 )] ] α = min([ [ p 1 ] ] α , [ [ p 2 ] ] α ) where α [ x 7→ n ] denotes an up date of α , defined by α [ x 7→ n ]( y ) = n if y = x , and α [ x 7→ n ]( y ) = α ( y ) otherwise . Finally , we let [ [ p ] ] := [ [ p ] ] α 0 with α 0 defined by α 0 ( x ) = 0 for all x ∈ X . As b ecomes clear from Def. 4.25 , we could hav e done without the cla use • ( p ) in the BNF grammar for pro duction terms in Def. 4.2 4, as • can be abbrevia ted to + − +, an io -term that denotes the successo r function. How ever, w e take it up as a primitiv e constructor here in order to match with p ebbleflow nets, see Sec. 4 .3. F or faithfully mo delling the d-o low er b ounds of stream functions with strea m arity r , we employ r -a ry p-i functions, w hich we represent by ‘ r -a ry gates ’. Definition 4.2 6. An r - ary gate gate k ( σ 1 , . . . , σ r ) is defined as a pro duction term co n tex t of the for m: gate k ( σ 1 , . . . , σ r ) := min ( k , σ 1 ( 2 1 ) , . . . , σ r ( 2 r )) , where k ∈ N and σ 1 , . . . , σ r ∈ ± ∞ . W e use γ as a sy n ta c tic v ar iable for gates. The interpr etation o f a g ate γ = gate k ( σ 1 , . . . , σ r ) is de fined by: [ [ γ ] ]( n 1 , . . . , n r ) := min( k , [ [ σ 1 ] ]( n 1 ) , . . . , [ [ σ r ] ]( n r )) . In cas e k = ∞ , we simplify g ate k ( σ 1 , . . . , σ r ) to gate ( σ 1 , . . . , σ r ) := min ( σ 1 ( 2 1 ) , . . . , σ r ( 2 r )) . Data-Oblivious Stream Pro ductivity 27 It is po ssible to choose unique gate repres en ta tions f of p- i functions f that are efficiently c o mputable from other gate r epresentations, see Section 4 .3. Owing to the res tr iction to (term repres e n tatio ns o f ) p erio dically increasing functions in Def. 4.2 5 it is p ossible to calculate the pro duction [ [ p ] ] of terms p ∈ P . F or that purp ose, we define a rewr ite system which reduces any closed term to a numeral k . This system makes use of the computable op erations ◦ and fix on io-terms mentioned ab ov e. Definition 4.2 7. The r ewrite r elation → R on pr o duction terms is defined as the compa tible closure o f the following rules: • ( p ) → + − +( p ) ( R 1) ι 1 ( ι 2 ( p )) → ι 1 ◦ ι 2 ( p ) ( R 2) ι ( min ( p 1 , p 2 )) → min ( ι ( p 1 ) , ι ( p 2 )) ( R 3) µx. min ( p 1 , p 2 ) → min ( µx.p 1 , µx.p 2 ) ( R 4) µx.p → p if x 6∈ FV ( p ) ( R 5) µx.ι ( x ) → fix ( ι ) ( R 6) min ( k 1 , k 2 ) → min( k 1 , k 2 ) ( R 7) ι ( k ) → [ [ ι ] ]( k ) ( R 8) µx.x → 0 ( R 9) The following tw o lemmas establish the use fulness of the rewrite relation → R . In order to compute the pro duction [ [ p ] ] o f a pro duction term p it suffices to obtain a → R -normal form of p . Lemma 4.2 8. The r ewrite r elation → R is pr o duction pr eserving: p → R p ′ = ⇒ [ [ p ] ] = [ [ p ′ ] ] . Pr o of. It suffices to prov e: C [ ℓ σ ] → R C [ r σ ] = ⇒ ∀ α. [ [ C [ ℓ σ ]] ] α = [ [ C [ r σ ]] ] α , where ℓ → r is a rule o f the T RS given in Def. 4.27 , a nd C a unary context over P . W e pro ceed by induction o n C . F o r the base case, C = [ ], we g ive the es sent ia l pro of steps only: F o r r ule ( R 1), observe that [ [ − +] ] is the identit y funct ion on N . F o r r ule ( R 2 ), we apply Pr op. 4.11 . F or rule ( R 3) the desired equality follows from C 1 on page 31. F or rule ( R 4) we conclude by C 2 ibid. F or rule ( R 6) we use Lem. 4.23. F or the remaining rules the statemen t trivially holds. F or the induction step, the statement easily follows fro m the induction hypotheses. ⊓ ⊔ Lemma 4.2 9. The r ewrite re lation → R is terminating and c onfluent, and every close d p ∈ P has a numer al k as its unique → R -normal form. Pr o of. T o see that → R is ter minating, let w : P → N be defined by: w( x ) = 1 w( • ( p )) = 2 · w( p ) + 1 w( µx.p ) = 2 · w( p ) w( k ) = 1 w( σ ( p )) = 2 · w( p ) w( min ( p 1 , p 2 )) = w( p 1 ) + w( p 2 ) + 1 , 28 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks and obser v e that p → R q implies w( p ) > w( q ). Some of the r ules of → R ov erla p; e.g . rule ( R 2) with itself. F or each of the five critical pairs we can find a common reduct (the critical pair h σ ◦ ( τ ◦ υ ) , ( σ ◦ τ ) ◦ υ i due to a n ( R 2 )/( R 2)-ov erlap ca n b e joined b y Lem. 4.9), and hence → R is lo cally confluent, by the Critical Pairs Lemma (cf. [10 ]). B y Newman’s Le mma, we obtain that → R is confluent. Thus nor mal forms a re unique. T o s how that every closed net normalis e s to a so urce, let p b e an arbitra r y normal form. Note that the se t of free v ariables of a net is clos ed under → R , and hence p is a clo sed net. Clearly , p does not contain p ebbles, otherwis e ( R 1) would be a pplicable. T o see that p contains no subterms of the form µx.q , supp ose it do es and consider the innermost such subterm, viz. q contains no µ . If q ≡ k or q ≡ x , then ( R 5), resp. ( R 9) is a pplicable. If q ≡ σ ( q ′ ), we further distinguish four cases: if q ′ ≡ k or q ′ ≡ x , then ( R 8 ) r esp. ( R 6) is applica ble; if the r o o t symbol of q ′ is one of b ox , min , then q constitutes a redex w.r .t. ( R 2), ( R 3), resp ectively . If q ≡ min ( q 1 , q 2 ), we hav e a redex w.r.t. ( R 4). Thus, there are no s ubter ms µx.q in p , and therefore, beca use p is clo sed, also no v a riables x . T o see that p has no s ubterms of the for m σ ( q ), suppo se it do es and co ns ider the innermost such subterm. Then, if q ≡ k or q ≡ min ( q 1 , q 2 ) then ( R 8) resp. ( R 3) is applicable; other cases have bee n excluded a b ove. Finally , p do es not co n tain s ubterms of the form min ( p 1 , p 2 ). F or if it do es, conside r the inner most o ccurre nce a nd note that, since the other cases hav e been excluded already , p 1 and p 2 hav e to b e sources, and s o we hav e a r e de x w.r.t. ( R 7). W e conclude that p ≡ k for so me k ∈ N . ⊓ ⊔ 4.3 P ebbleflow Nets Pro duction terms can b e visua lized by ‘p ebbleflow nets’ in tr oduce d in [2], a nd serve as a means to mo del the ‘da ta-oblivious’ co nsumption/pro duction b e- haviour of s tream sp ecifications. The idea is to a bstract from the actual stre am elements (data) in a stream ter m in fav o ur of occur rences of the sym b ol • , which we call ‘p ebble’. Thus, a stream term u : s is tr a nslated to [ u : s ] = • ([ s ]), see Section 5 . W e give an o per ational description of p ebbleflow nets, and define the pro - duction of a net a s the n umber of pe bbles a net is able to pro duce at its output po rt. Then w e prov e that this definitio n of pr oductio n coincides with Def. 4.2 5. Pebbleflo w nets a re net works built of p ebble pro ces sing units (fans, boxes, meets, so ur ces) connected by wire s . W e us e the term syntax given in Def. 4 .24 for nets and the rules governing the flow of pebbles thr ough a net, and then give an op eratio na l meaning of the units a net is built of. Data-Oblivious Stream Pro ductivity 29 Definition 4.3 0. The p ebbleflow r ewrite r elation → P is defined as the co mpat- ible clo sure of the union of the fo llowing rules : min ( • ( p 1 ) , • ( p 2 )) → • ( min ( p 1 , p 2 )) ( P 1) µx. • ( p ( x )) → • ( µx.p ( • ( x ))) ( P 2) + σ ( p ) → • ( σ ( p )) ( P 3) − σ ( • ( p )) → σ ( p ) ( P 4) 1 + k → • ( k ) ( P 5) Wires a re unidirectio nal FIF O communication channels. They a re idealis ed in the s ense that there is no upp er b ound on the num b er of pebbles they can store; arbitrar ily long queues ar e a llow ed. Wires hav e no coun ter part on the term level; in this sense they are akin to the edges of a term tree. Wires connect b ox es , me ets , fans , and sour c es , that we descr ibe next. A me et is waiting for a p ebble at each o f its input p orts a nd only then pro duces o ne pebble a t its output p ort, see Fig. 9. Put differently , the num b er of p ebbles a meet pro duces equals the minimum of the num b ers of p ebbles av ailable at each o f its input por ts. Meets enable ex plicit branching; they are used to mo del stream functions of ar it y > 1 , as will b e expla ined b elow. A meet with an arbitrar y n umber n ≥ 1 of input p orts is implemented by using a single wire in case n = 1, and if n = k + 1 with k ≥ 1, by connecting the output po rt of a ‘ k -ary meet’ to one of the input p orts of a (binary) meet. p 1 p 2 p 1 p 2 min min Fig. 9: Rule ( P 1). p p Fig. 10: Rule ( P 2). The b ehaviour o f a fan is dual to that of a meet: a p ebble at its input p or t is duplicated along its output p orts. A fan can be seen as a n explicit sharing device, and thus enables the co nstruction of cyclic nets. More specific a lly , w e use fans only to implement feedback when dr awing nets; there is no explicit term representation for the fan in our term calculus. In Fig . 10 a p ebble is sent ov er the output wire of the net and at the same time is fed back to the ‘recursio n wire(s)’. T urning a cyclic net into a term (tree) means to intro duce a no tion of binding; certa in no des need to be la belled b y a na me ( µx ) so that a wir e p ointing 30 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks to that no de is replac ed by a name ( x ) r eferring to the la belled no de. In rule ( P 2) feedback is acco mplis hed by substituting • ( x ) for all free o ccurr e nc e s x of p . A sour c e has an output po rt only , contains a num b er k ∈ N of p ebbles, and can fire if k > 0, see Fig . 13. The re write r elation → R given in Def. 4.27 c ollapses any clos ed net (without input p orts that is) into a so ur ce. A b ox consumes p ebbles at its input p ort and pro duces p ebbles at its output po rt, controlled by an io-se q uence σ ∈ ± ∞ asso ciated with the b ox. F o r exa mple, consider the unary s tream function dup , defined a s follows, and its corresp onding io-sequence: dup ( x : σ ) = x : x : dup ( σ ) − ++ which is to b e thought of as: for dup to pr o duc e two out puts, it first has to c onsume one input, and this pr o c ess r ep e ats indefinitely . Intuitiv ely , the sy m b ol − represents a requirement for an input pebble, and + r epresents a rea dy state for an output pebble. Pebbleflow throug h boxes is visualised in Figs. 1 1 and 1 2. p p + σ σ Fig. 11: Ru le ( P 3). − σ p p σ Fig. 12: Rule ( P 4). k 1 + k Fig. 13: Ru le ( P 5). min σ 1 σ r Fig. 14: gate ( σ 1 , . . . , σ r ) The data-oblivio us production b ehaviour of stream functions f with a stream arity ar s ( f ) = r are mo delled by r -ar y gates (defined in Def. 4.2 6) that express the contribution of each individual stre a m a r - gument to the total pro duction o f f , se e Fig. 14. The precise transla tion of stream functions in to gates is given in Sec. 5, in par ticular in Def. 5.9. Lemma 4.3 1. The p ebbleflow r ewrite r elation → P is c onfluent . Pr o of. The rules of → P can b e viewed as a higher-o rder r ewriting system (HRS) that is o rthogonal. Applying Thm. 11 .6.9 in [10 ] then establishes the lemma. ⊓ ⊔ Definition 4.3 2. The pr o duction function Π : P → N of nets is defined by: Π ( p ) := sup { n ∈ N | p ։ P • n ( p ′ ) } , for all p ∈ P . Π ( p ) is called the pr o duction of p . Moreover, for a net p and a n assignment α ∈ X → N , let Π ( p, α ) := Π ( p α ) where p α denotes the net o btained by replac ing each fr ee v ariable x of p with • α ( x ) ( x ). Data-Oblivious Stream Pro ductivity 31 Note that for closed nets p (where FV ( p ) = ∅ ), p α = p and therefore [ [ p ] ] α = [ [ p ] ], for all assignments α . An impor tant pr ope r t y used in the fo llowing lemma is that functions o f the form λn ∈ N . Π ( p , α [ x 7→ n ]) are monotonic functions over N . Every mo no tonic function f : N → N in the complete chain N ha s a lea st fixed p oint lfp( f ) which can b e computed by lfp( f ) = lim n →∞ f n (0). In what follows w e employ , for monotonic f , g : N → N , tw o basic pro p erties : ∀ n, m.  f (min ( n, m )) = min( f ( n ) , f ( m ))  ( C 1 ) lfp( λn. min( f ( n ) , g ( n ))) = min(lfp ( f ) , lfp( g )) ( C 2 ) Lemma 4.3 3. F or al l nets q ∈ P and al l assignments α , we have that Π ( µx.q , α ) is the le ast fixe d p oint of λn ∈ N . Π ( q , α [ x 7→ n ]) . Pr o of. Let α : X → N b e an arbitrar y ass ignmen t a nd q 0 := q α [ x 7→ 0] . Obser v e that Π ( µx.q , α ) = Π ( µx.q 0 ) and consider a rewrite s equence of the form µx.q 0 → ∗ . . . → ∗ • n i ( µx.q i ) → ∗ • n i ( µx. • ℓ i ( q ′ i )) → ∗ • n i + ℓ i ( µx.q i +1 ) → ∗ . . . where ℓ i = Π ( q i ), n 0 = 0, n i +1 = n i + ℓ i , and q i +1 := q ′ i ( • ℓ i ( x )). Note that lim m →∞ n m = Π ( µx.q 0 ); ‘ ≤ ’ follows from ∀ m. µx.q 0 → ∗ • n m ( µx.q m ), a nd ‘ ≥ ’ since if lim m →∞ n m < ∞ then ∃ m ∈ N such that ℓ m := Π ( q m ) = 0 and therefo r e Π ( µx.q 0 ) = Π ( • n m ( µx.q m )) = n m by confluence. Let f i = λn. [ [ q i ( • n ( x ))] ], and f ′ i = λn. [ [ q ′ i ( • n ( x ))] ]. W e prov e ∀ k ∈ N . f 0 ( n m + k ) = n m + f m ( k ) ( ∗ ) by induction over m . The base ca se m = 0 is trivial, we c onsider the induction step. W e hav e q m → ∗ • ℓ m ( q ′ m ) and b y substituting • k ( x ) for x we get ∀ k ∈ N . f m ( k ) = ℓ m + f ′ m ( k ) ( ∗∗ ) Moreov e r, since f m +1 ( k ) = f ′ m ( ℓ m + k ), we get n m +1 + f m +1 ( k ) = n m +1 + f ′ m ( ℓ m + k ) = n m + ℓ m + f ′ m ( ℓ m + k ) ( ∗∗ ) = n m + f m ( ℓ m + k ) ( ∗ ) = f 0 ( n m + ℓ m + k ) = f 0 ( n m +1 + k ). Let f := f 0 . W e pro ceed with showing ∀ m. f m (0) = n m by induction ov er m ∈ N . F or the base case m = 0 we have f 0 (0) = 0 and n 0 = 0, and for the induction step we get f m +1 (0) = f ( f m (0)) IH = f ( n m ) ( ∗ ) = n m + f m (0) = n m + ℓ m = n m +1 . Hence lfp( f ) = lim m →∞ f m (0) = lim m →∞ n m = Π ( µx.q 0 ) = Π ( µx.q , α ). ⊓ ⊔ Lemma 4.3 4. F or p ∈ P , σ ∈ ± ∞ P , α : X → N : Π ( σ ( p ) , α ) = [ [ σ ] ]( Π ( p, α )) . Pr o of. W e show tha t the rela tion R ⊆ N × N defined as follows is a bisimulation: R :=  h Π ( σ ( p ) , α ) , [ [ σ ] ]( Π ( p, α )) i | σ ∈ ± ∞ P , p ∈ P , α : X → N  , 32 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks that is , we prove that, for all k 1 , k 2 ∈ N , σ ∈ ± ∞ P , p ∈ P , and α : X → N , if k 1 = Π ( σ ( p ) , α ) and k 2 = [ [ σ ] ]( Π ( p, α )), then either k 1 = k 2 = 0 or k 1 = 1 + k ′ 1 , k 2 = 1 + k ′ 2 and h k ′ 1 , k ′ 2 i ∈ R . Let k 1 , k 2 ∈ N , σ ∈ ± ∞ P , p ∈ P , a nd α : X → N , b e suc h that k 1 = Π ( σ ( p ) , α ) and k 2 = [ [ σ ] ]( Π ( p, α )). By definition o f ± ∞ , we have that σ ≡ − n + τ for so me n ∈ N a nd τ ∈ ± ∞ . W e pro ceed by induction on n . If n = 0, then k 1 = 1 + k ′ 1 with k ′ 1 = Π ( τ ( p ) , α ) a nd k 2 = 1 + k ′ 2 with k ′ 2 = [ [ τ ] ]( Π ( p, α )), and h k ′ 1 , k ′ 2 i ∈ R . If n = n ′ + 1, we distinguish cases: If Π ( p, α ) = 0, then k 1 = k 2 = 0. If Π ( p, α ) = 1 + m , then p ։ P • ( q ) for some q ∈ P with Π ( q , α ) = m . Thus we get k 1 = Π ( − n ′ + τ ( q ) , α ) and k 2 = [ [ − n ′ + τ ] ]( Π ( q , α )), and h k 1 , k 2 i ∈ R b y induction hypothesis. ⊓ ⊔ Next w e s how that productio n of a term p ∈ P (Def. 4.25) coincides with the maximal num b er of p ebbles pro duced by the ne t p via the r ewrite relatio n → P (Def. 4 .32). Lemma 4.3 5. F or al l n et s p and assignment s α , it holds Π ( p, α ) = [ [ p ] ] α . Pr o of. The statement of the lemma can b e pr ov ed by a straig h tfor w a rd induction on the n um b er of µ -bindings of a net p , with a subinduction on the size of p . In the case s p ≡ σ ( p ′ ) and p ≡ µx.p ′ Lem. 4.34 and Lem. 4.3 3 are applied, resp ectively . ⊓ ⊔ Subsequently , we will use the interpretation of ter ms in P and the pr o ductio n of p ebbleflow nets, [ [ ] ] and Π , interchangeably . 5 T ran slation in to Pr o duction T erms In this section we define a tr anslation from s tream constants in flat or friendly nesting sp ecifications to pro duction ter ms. In pa r ticular, the ro ot M 0 of a sp ec- ification T is mapped b y the translation to a pro duction term [ M 0 ] with the prop erty that if T is fla t (friendly nesting), then the d-o lower b ound o n the pro duction of M 0 in T equals (is b ounded from b elow by) the pro duction o f [ M 0 ]. 5.1 T ranslation of Flat and F riendl y Nes ting Sym b ols As a first step of the transla tion, we describ e how for a flat (or friendly nesting) stream function symbol f in a stream sp ecifica tion T a p erio dically increa sing function h f i can b e c alculated that is (that b ounds from b elow) the d-o low er bo und on the pro duction of f in T . Let us ag ain consider the rules (i) f ( s ( x ) : y : σ ) → a ( s ( x ) , y ) : f ( y : σ ), and (ii) f ( 0 : σ ) → 0 : s ( 0 ) : f ( σ ) fro m Fig. 2. W e mo del the d-o lower b o und o n the pro duction o f f by a function from N to N defined a s the unique solution for X f of the following system of equations. W e disr egard what the concrete s tream elements a re, and ther efore we ta ke the infimum ov e r all p ossible tra ces: X f ( n ) = inf  X f , (i ) ( n ) , X f , (i i) ( n )  Data-Oblivious Stream Pro ductivity 33 where the solutions fo r X f , (i ) and X f , (i i) are the d-o lower b ounds of f assuming that the fir st rule applied in the rewrite sequence is (i) or (ii), resp ectively . The rule (i) consumes t wo elemen ts, pro duces one elemen t and feeds one element back to the re cursive c a ll. F o r rule (ii) these num b ers ar e 1, 2 , 0 respectively . Therefore we get: X f , (i ) ( n ) = let n ′ := n − 2 , if n ′ < 0 then 0 else 1 + X f (1 + n ′ ) , X f , (i i) ( n ) = let n ′ := n − 1 , if n ′ < 0 then 0 else 2 + X f ( n ′ ) . The unique solution for X f is n 7→ n . − 1, represe n ted by the io -term −− +. In g eneral, functions may have m ultiple arguments, which during rewr iting may get p ermuted, deleted or duplicated. The idea is to trace sing le arg umen ts, and to take the infimum over trace s in case an arg umen t is duplicated. In the definition of the trans lation of stre a m functions, we ne e d to distinguish the ca ses acc o rding to whether a symbol is weakly g uarded o r not: O n Σ s we define ; : = {h r oot ( ℓ ) , r oot ( r ) i | ℓ → r ∈ R S , ‘:’ 6 = r oot ( r ) ∈ Σ s } . the dep en- dency r elation betw een s y m b ols in Σ s . W e s ay tha t a symbol f ∈ Σ s is we akly guar de d if f is strongly normalising with respe c t to ; and ungu ar de d , other wise. Note that since Σ s is finite it is (easily) decidable whether a symbo l f ∈ Σ s is weakly guar ded or ungua rded. The tr anslation o f a str e am function symbol is defined a s the unique so lutio n of a (usually infinite) s y stem of defining equations where the unknowns are functions. More precisely , for ea c h symbol f ∈ Σ fnest ⊇ Σ sfun of a flat or friendly nesting stream sp ecification, this system ha s a p-i function h f i as the s olution for X f , which is unique among the co n tinuous functions. Later we will see (Pr op. 5.14 and Lem. 5.15) that the tra ns lation h f i of a flat (friendly nesting) str eam function symbol f coincides with (is a lower b ound fo r ) the d-o low er b ound do T ( f ) o f f . Definition 5.1 . Let T = h Σ , R i b e a stream sp ecification. F or each flat or friendly nes ting symbo l f ∈ Σ fnest ⊇ Σ flat with arities k = ar s ( f ) and ℓ = ar d ( f ) we define h f i : N k → N , called the (p-i function) tr anslation of f in T , a s the unique solutio n s X f for X f of the following system of defining equations , where the solution of an equation of the form X ( n 1 , . . . , n k ) = . . . is a function s X : N k → N (it is to b e understo o d that s X ∈ N if k = 0): F or all n 1 , . . . , n k ∈ N , i ∈ { ⋆, 1 , . . . , k } , a nd n ∈ N : X f ( n 1 , . . . , n k ) = min( X f ,⋆ , X f , 1 ( n 1 ) , . . . , X f ,k ( n k )) , X f ,⋆ = ( inf  X f ,⋆, ρ | ρ a de fining rule of f  if f is weakly g ua rded, 0 if f is ung uarded, X f ,i ( n ) = ( inf  X f ,i,ρ ( n ) | ρ a defining rule o f f  if f is weakly g ua rded, 0 if f is ung uarded. W e write u i : σ i for u i, 1 : . . . : u i,p : σ i , and | u i | for p . F or sp ecifying X f ,i,ρ we distinguish the p ossible forms the rule ρ can ha ve. If ρ is nes ting , then X f ,⋆, ρ = ∞ , 34 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks and X f ,i,ρ ( n ) = n for all n ∈ N . Other wise, ρ is non-nesting and of the for m: f (( u 1 : σ 1 ) , . . . , ( u k : σ k ) , v 1 , . . . , v ℓ ) → w 1 : . . . : w m : s , where either (a) s ≡ σ j , or (b) s ≡ g (( u ′ 1 : σ φ (1) ) , . . . , ( u ′ k ′ : σ φ ( k ′ ) ) , v ′ 1 , . . . , v ′ ℓ ′ ) with k ′ = ar s ( g ), ℓ ′ = ar d ( g ), and φ : { 1 , . . . , k ′ } → { 1 , . . . , k } . Let: X f ,⋆, ρ = ( ∞ case (a) m + X g ,⋆ case (b) X f ,i,ρ ( n ) = let n ′ := n − | u i | , if n ′ < 0 then 0 else m +      n ′ case (a), i = j ∞ case (a), i 6 = j inf  X g ,j ( n ′ + | u ′ j | ) | j ∈ φ − 1 ( i )  case (b) where we agree inf ∅ = ∞ . W e mention a useful intuition for understa nding the fabric of the for mal definition ab ov e of the translation h f i of a stream function f , the solution s X f for X f of the system of equa tions in Def. 5.1 . F or e a ch i ∈ { 1 , . . . , k } where k = ar s ( f ) the solution s X f ,i for X f ,i (a unary p-i function) in this system describ es to what extent consumption from the i - th co mp onent of f ‘delays’ the ov er a l pro duction. Since in a d-o rewr ite seq uence fro m f ( • n 1 : σ 1 , . . . , • n k : σ k ) it may happ en that all strea m v aria ble s σ 1 , . . . , σ k are eras e d at some po in t, and that the sequence subsequently contin ues rewriting stream co nstants, monitoring the delays caused by indiv idua l arguments is not sufficient alone to define the pro duction function of f . This is the reaso n for the use, in the definition of h f i , of the so lutio n s X f ,⋆ for the v ariable X f ,⋆ , which defines a ‘glas s ceiling’ for the not adequa te ‘overall delay’ function min( s X f , 1 ( n 1 ) , . . . , s X f ,k ( n k ) ), ta k ing account of s ituations in which in d-o rewr ite seq uences from terms f ( • n 1 : σ 1 , . . . , • n k : σ k ) all input comp onent s hav e b een er a sed. Concerning non-nesting r ules on which defining rules for frie ndly nesting symbols dep end via , this translation uses the fact that their pro duction is bo unded below by ‘min ’. These b ounds are not necessar ily optimal, but can b e used to show pr o ductivit y of exa mples like X → 0 : f ( X ) with f ( x : σ ) → x : f ( f ( σ )). Def. 5 .1 can b e used to define, for every fla t or friendly nesting symbol f ∈ Σ sfun in a str e am sp e cification T , a ‘gate trans lation’ of f : b y defining this translation by choos ing a gate that repre s en ts the p-i function h f i . How ever, it is desir able to define this tr anslation also in a n equiv alent wa y that lends itself b etter for co mputation, and wher e the result directly is a pro - duction term (gate) re presentation of a p-i function: b y sp ecifying the io-terms in a g ate tra nslation as denotatio ns of rationa l io-sequences that are the solutions of ‘io-seq uence specifications ’. In particular , the gate translatio n o f a symbol f ∈ Σ sfun will b e defined in ter ms of the solutions, for each a rgument place of a stream function symbol f , of a finite io- sequence sp ecification that is extr acted from an infinite one which precis ely determines the d-o lower bo und of f in that argument pla ce. Data-Oblivious Stream Pro ductivity 35 Definition 5.2 . Let X be a set of v ariables. The set of io-se qu enc e sp e cific ation expr essions over X is defined b y the following gr ammar: E ::= ⊥ | X | − E | + E | E ∧ E where X ∈ X . Guardedness is defined b y induction: An io -sequence sp ecification expression is called guar de d if it is of o ne of the for ms ⊥ , − E 0 , or + E 0 , or if it is o f the form E 1 ∧ E 2 for gua r ded E 1 and E 2 . Suppo se that X = { X α | α ∈ A } for some (countable) set A . Then by an io-se quenc e sp e cific ation over (the set of re cursion vari ables) X w e mean a family { X α = E α } α ∈ A of r e cu rsion e quat ions , where, fo r all α ∈ A , E α is a n io- sequence s pecifica tion expres sion ov er X . Let E b e an io-seque nce sp ecification. If E consists of finitely many recursion eq uations, then it is called finite . E is called guar de d ( we akly guar de d ) if the r ight -hand side of every recur sion equatio n in E is gua rded (or r esp e ctiv ely , can b e rewritten, using equa tional log ic a nd the equations o f E , to a gua r ded io -sequence sp ecification expressio n). Let E = { X α = E α } α ∈ A an io- sequence sp ecificatio n. F ur ther more let α 0 ∈ A and τ ∈ ± ω . W e say that τ is a s olut ion of E for X α 0 if there exist io-sequences { σ α } α ∈ A such that σ α 0 = τ , and all of the recursion eq uations in E ar e true statements (under the interpretation o f ∧ as defined in Def. 4.13), when, for all α ∈ A , σ α is subs tituted for X α , re s pectively . It turns out that weakly g uarded io- sequence sp ecifications hav e unique so lu- tions, and tha t the solutions of finite, w e a kly gua r ded io -sequence sp ecificatio ns are r ational io-sequences . Lemma 5.3 . F or every we akly guar de d io-se qu enc e sp e cific ation E and r e cursion variable X of E , t her e exists a unique solution σ ∈ ± ∞ of E for X . Mor e over, if E is fin ite then the solut ion σ of E for X is a r ational io-se quenc e, and an io-term that denotes σ c an b e c ompute d on the input of E and X . Let T b e a stream sp ecification, and f ∈ Σ sfun . By exha ustiv eness of T for f , ther e is at least o ne defining rule for f in T . Since T is a co nstructor stream TRS, it follows tha t every defining rule ρ for f is of the form: f ( p 1 , . . . , p ar s ( f ) , q 1 , . . . , q ar d ( f ) ) → u 1 : . . . : u m : s ( ρ ) with p 1 , . . . , p ar s ( f ) ∈ T er ( C ( Σ )) S , q 1 , . . . , q ar d ( f ) ∈ T er ( C ( Σ )) D , u 1 , . . . , u m ∈ T er ( Σ ) D and s ∈ T er ( Σ ) S where r oot ( s ) 6 = ‘:’. If ρ is non-nesting then either s ≡ σ j or s ≡ g ( w 1 : σ φ (1) , . . . , w ar s ( g ) : σ φ ( ar s ( g )) , u ′ 1 , . . . , u ′ ar d ( g ) ) where w i : σ i is shorthand for w i, 1 : . . . : w i,m i : σ i , and φ : { 1 , . . . , ar s ( g ) } → { 1 , . . . , ar s ( f ) } is a function that descr ib es how the stream arg umen ts a re p ermuted and replicated. W e now define, for every g iven strea m sp ecification T , an infinite io-s equence sp ecification E T that will b e instrumental for defining gate translations of the stream function symbols in T . 36 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Definition 5.4 . Let T = h Σ , R i b e a stream sp ecification. Bas e d on the set: A := {h ǫ, −i , h ǫ, + i , h ǫ , − + i} ∪ n h f , ⋆ i , h f , ⋆ , ρ i , h f , i, q i , h f , i, q , ρ i    f ∈ Σ fnest , q ∈ N , ρ defining r ule for f , 1 ≤ i ≤ ar s ( f ) o of tuples we define the infinite io-seq uence sp ecification E T = { X α = E α } α ∈ A by listing the eq uations of E T . W e start with the equations X h ǫ, −i = ⊥ , X h ǫ, + i = + X h ǫ, + i , X h ǫ, − + i = − + X h ǫ, − + i . Then we le t, for all friendly nesting (or flat) f ∈ Σ sfun with arities k = ar s ( f ) and ℓ = ar d ( f ): X h f , ⋆ i = ( min  X h f , ⋆, ρ i | ρ a defining rule o f f  if f is weakly g uarded, X h ǫ, −i if f is unguar ded, and for all 1 ≤ i ≤ ar s ( f ), and q ∈ N : X h f , i, q i = ( V  X h f , i, q , ρ i | ρ a de fining rule of f  if f is weakly g ua rded, X h ǫ, −i if f is ung uarded. F or sp ecifying X h f , ⋆, ρ i and X h f , i, q, ρ i we dis tinguish the p ossible forms the rule ρ can hav e. In doing so , we abbreviate ter ms u i, 1 : . . . : u i,p : σ i with σ i a v aria ble of so rt s tream by u i : σ i and let | u i | := p . If ρ is nesting, then we let X h f , ⋆, ρ i = X h ǫ, + i , X h f , i, q , ρ i = X h ǫ, − + i . Otherwise, ρ is no n-nesting and o f the form: f (( u 1 : σ 1 ) , . . . , ( u k : σ k ) , v 1 , . . . , v ℓ ) → w 1 : . . . : w m : s , where either (a) s ≡ σ j , or (b) s ≡ g (( u ′ 1 : σ φ (1) ) , . . . , ( u ′ k ′ : σ φ ( k ′ ) ) , v ′ 1 , . . . , v ′ ℓ ′ ) with k ′ = ar s ( g ), ℓ ′ = ar d ( g ), and φ : { 1 , . . . , k ′ } → { 1 , . . . , k } . Let: X h f , ⋆, ρ i = ( X h ǫ, + i case (a) + m X h g , ⋆ i case (b) X h f , i, q, ρ i = let p := | u i | . − q , q ′ := q . − | u i | in − p + m      + q ′ X h ǫ, − + i case (a), i = j X h ǫ, + i case (a), i 6 = j V  X h g , j , q ′ + | u ′ j |i | j ∈ φ − 1 ( i )  case (b) where we agree V ∅ := X h ǫ, + i . W e formally state an ea sy o bserv ation about the sys tem E T defined in Def. 5.9, and an immediate c o nsequence due to Lem. 5 .3. Data-Oblivious Stream Pro ductivity 37 Prop osition 5.5. L et T b e a str e am sp e cific ation. The io-se quenc e sp e cific a- tion E T (define d in Def. 5.9) is we akly gu ar de d. As a c onse quenc e, E T has a unique solution in ± ∞ for every variable X in E T . Another eas y obser v a tion is that the solutions for the v ariables X h f , ⋆ i in a system E T corres p ond very directly to num b ers in N . Prop osition 5.6. L et T b e a st r e am sp e cific ation and f ∈ Σ sfun . The unique solution of E T (define d in D ef. 5.9) for X h f , ⋆ i is of the form + ω or + n ⊥ . F urthermore observe that E T is infinite in case that Σ sfun 6 = ∅ , and hence t y pically is infinite. Wherea s Lem. 5 .3 implies unique solv ability of E T for indi- vidual v ar iables in view o f (the fir s t statement in) Pr op. 5.5, it will usually not guarantee that these unique s olutions are r ational io-sequences . Nevertheless it can be shown that all solutions of E T are r ational io -sequences. F or our purp oses it will suffice to show this only for the solutions of E T for certain of its v ariables . W e will only b e int e rested in the solutions of E T for v ariables X h f , i, 0 i and X h f , ⋆ i . It turns o ut that from E T a finite weakly g uarded specifica tion E ′ T can b e extracted that, fo r each of the v ar iables X h f , i, 0 i and X h f , ⋆ i , ha s the same solution as E T , r espe ctiv ely . Lem. 5.7 b elow states that, for a stream sp ecification T , the finite io-sequence specifica tio n E ′ T can alw ays b e obtained algor ithmically , which together with L e m. 5.3 implies that the unique solutio ns o f E T for the v ariables X h f , i, 0 i and X h f , ⋆ i are r ational io -sequences for which representing io-terms ca n be computed. As a conseq uence these solutions, for a stream sp ecification T , of the rec ur sion system E T , ca n b e v iew e d to r epresent p-i functions: the p-i func- tions that are r epresented b y the io-term de no ting the resp ective solution, a rational io-s equence. As an e xample let us c onsider an io -sequence sp ecification that corres ponds to the defining rule s for f in Fig. 2 : X = − ++ X ∧ −− + Y Y = ++ X ∧ − + Y . The unique s olution for X of this system is the r a tional io- sequence (and res pec- tively , io- term) − − +, which is the transla tion o f f (as mentioned ea rlier). Lemma 5.7 . L et T b e a str e am sp e cific ation. Ther e exists an io-se quenc e sp e c- ific ation E ′ T = { X α = E ′ α } α ∈ A ′ such that: (i) E ′ T is finite and we akly guar de d; (ii) {h f , i, 0 i , h f , ⋆ i | f ∈ Σ sfun , i, q ∈ N , i ∈ { 1 , . . . , ar s ( f ) } } ⊆ A ′ ; for e ach f ∈ Σ sfun ∩ Σ fnest and i ∈ { 1 , . . . , ar s ( f ) } , E ′ T has t he same solution for X h f , i, 0 i , and r esp e ctively for X h f , ⋆ i , as the io-se quenc e sp e cific ations E T (se e Def. 5.4); (iii) on the input of T , E ′ T c an b e c omput e d. Pr o of (S ketch). An algor ithm for obtaining E ′ T from E T can b e obtained as follows. On the input of E T , set E := E T and rep eat the following step on E a s long as it is applicable: 38 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks (RPC) Detect and remov e a r e achable non-c onsuming pseudo-cycle from the io- sequence sp ecificatio n E : Supp ose that, for a function sy m b ol h , for j, k , l ∈ N , and for a recurs ion v ariable X h h , j , k i that is r eachable from X h f , i, 0 i , we hav e X h h , j , k i w − → X h h , j , l i (from the recursion v aria ble X h h , j , k i the v aria ble X h h , j , l i is reachable via a path in the sp ecification on which the finite io- sequence w is enco un ter e d as the word formed by consecutive labels ), where k < l a nd w only contains sym b ols ‘+’. Then modify E by setting X h h , j , k i = X h ǫ, + i . It is not difficult to show that a step (RPC) preser v e s weakly g ua rdedness and the unique solution of E T , a nd that, on the input o f E T , the algorithm terminates in finitely many steps, having pro duced an io-seq ue nce s pecifica tion E ′ T with [ f ] i as the solution for X h f , i, 0 i and the pro per t y that only finitely many recursion v ariables are reachable in E ′ T from X h f , i, 0 i . ⊓ ⊔ As an immediate consequence of Le m. 5.7, and of Lem. 5.3 w e obtain the following lemma. Lemma 5.8 . L et T b e a st r e am sp e cific ation, and let f ∈ Σ sfun . (i) F or e ach i ∈ { 1 , . . . , ar s ( f ) } ther e is pr e cisely one io-se quenc e σ t hat solves E T for X h f , i, 0 i ; furthermor e, σ is r ational. Mor e over t her e ex ists an algorithm that, on the input of T , f , and i , c omputes the shortest io-term that denotes the solution of E T for X h f , i, 0 i . (ii) Ther e is pr e cisely one io-se quenc e σ that s olves E T for X h f , ⋆ i ; this io-se quenc e is r ational. And ther e is an algorithm that, on the input of T and f , c omputes the shortest io-term that denotes the solut ion of E T for X h f , ⋆ i . Lem. 5.8 g uarantees the well-definedness in the definition below of the ‘g ate translation’ for flat or friendly nesting s tream functions in a stream sp ecificatio n. Definition 5.9 . Let T = h Σ , R i b e a str e am definitio n. F or each flat or friendly nesting symbol f ∈ Σ sfun ∩ Σ fnest with stream arity k = ar s ( f ) we define the gate tr anslation [ f ] of f by: [ f ] := g ate [ f ] ⋆ ([ f ] 1 , . . . , [ f ] ar s ( f ) ) , where [ f ] ⋆ ∈ N is defined by: [ f ] ⋆ := ( n the unique solution of E T for X h f , ⋆ i is + n ⊥ ∞ the unique s o lution of E T for X h f , ⋆ i is + ω and, for 1 ≤ i ≤ ar s ( f ), [ f ] i is the shortest io- term that deno tes the unique solu- tion for X h f , i, 0 i of the weakly g ua rded io-sequence spe c ific a tion E T in Def. 5.4. F rom Lem. 5.8 w e also obtain that, for ev er y stream sp ecifica tio n, the function which ma ps stream function symbols to their gate tr a nslations is computable. Data-Oblivious Stream Pro ductivity 39 Lemma 5.1 0. Ther e is an algorithm t hat, on the input of a stre am sp e cific a- tion T , and a flat or friend ly n esting symb ol f ∈ Σ sfun ∩ Σ fnest , c omputes the gate tr anslation [ f ] of f . Example 5.11. Consider a flat s tream sp ecification co nsisting of the rules: f ( x : σ ) → x : g ( σ, σ, σ ) , g ( x : y : σ , τ , υ ) → x : g ( y : τ , y : υ , y : σ ) . The translation of f is [ f ] = gate ([ f ] 1 ), where [ f ] 1 is the unique so lution for X h f , 1 , 0 i of the io-seq ue nc e sp ecificatio n E T : X h f , 1 , 0 i = − +( X h g , 1 , 0 i ∧ X h g , 2 , 0 i ∧ X h g , 3 , 0 i ) X h g , 1 , 0 i = −− + X h g , 3 , 1 i X h g , 1 , 1 i = − + X h g , 3 , 1 i X h g , 1 , q i = + X h g , 3 , q − 1 i ( q ≥ 2) X h g , 2 , q i = + X h g , 1 , q +1 i ( q ∈ N ) X h g , 3 , q i = + X h g , 2 , q +1 i ( q ∈ N ) By the algor ithm referre d to in Lem. 5.10 this infinite sp ecification can be turned int o a finite one. T he ‘no n-consuming pseudo cycle’ X h g , 3 , 1 i +++ − → X h g , 3 , 2 i justifies the mo dification o f E T by s etting X h g , 3 , 1 i = + X h g , 3 , 1 i ; likewise we set X h g , 3 , 0 i = + X h g , 3 , 0 i . F ur thermore a ll equations not reachable from X h f , 1 , 0 i are remov ed (garbag e collection), and we o bta in a finite sp ecification E ′ T , which, by Lem. 5.3 , has a p erio dically incr easing solution, with io -term-denotation [ f ] 1 = h− + −− , + i . The reader may try to ca lculate the gate corresp onding to g , it is: [ g ] = gate ( −− + , + − + , +). Second, cons ide r the flat strea m sp ecification with data constructor symbols 0 and 1 : f ( 0 : σ ) → g ( σ ) , f ( 1 : x : σ ) → x : g ( σ ) , g ( x : y : σ ) → x : y : g ( σ ) , denoted ρ f 0 , ρ f 1 , and ρ g , resp ectively . Then, [ f ] 1 is the solution for X h f , 1 , 0 i of X h f , 1 , 0 i = X h f , 1 , 0 , ρ f 0 i ∧ X h f , 1 , 0 , ρ f 1 i X h f , 1 , 0 , ρ f 0 i = − X h g , 1 , 0 i X h f , 1 , 0 , ρ f 1 i = −− + X h g , 1 , 0 i X h g , 1 , 0 i = −− ++ X h g , 1 , 0 i . Example 5.12. Consider a pure stream sp ecification with the function layer: f ( x : σ ) → x : g ( σ, σ, σ ) , g ( x : y : σ , τ , υ ) → x : g ( y : τ , y : υ , y : σ ) . 40 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks The tra nslation of f is h f i , the unique solution for X f of the system: X f ( n ) = min( X f ,⋆ (0) , X f , 1 ( n )) X f , 1 ( n ) = let n ′ := n − 1 if n ′ < 0 then 0 else 1 + inf  X g , 1 ( n ′ ) , X g , 2 ( n ′ ) , X g , 3 ( n ′ )  X f ,⋆ ( n ) = 1 + X g ,⋆ (0) X g , 1 ( n ) = let n ′ := n − 2 , if n ′ < 0 then 0 else 1 + X g , 3 (1 + n ′ ) X g , 2 ( n ) = 1 + X g , 1 (1 + n ) X g , 3 ( n ) = 1 + X g , 2 (1 + n ) X g ,⋆ ( n ) = 1 + X f ,⋆ (0) An algor ithm for solving such s ystems of e quations is describ ed in (the pro of of ) Lemma 5.7 ; here w e solve the system dire ctly . Note that X g , 3 ( n ) = 1 + X g , 2 ( n + 1) = 2 + X g , 1 ( n + 2) = 3 + X g , 3 ( n ), hence ∀ n ∈ N . X g , 3 ( n ) = ∞ . Likewise we obtain X g , 2 ( n ) = ∞ if n ≥ 1 a nd 1 for n = 0 , and X g , 1 ( n ) = ∞ if n ≥ 2 a nd 0 for n ≤ 1. Then we get h f i (0) = 0, h f i (1) = h f i (2) = 1, a nd h f i ( n ) = ∞ for all n ≥ 2, represented by the ga te h f i = gate ( − + −− +). The gate cor resp onding to g is h g i = gate ( −− + , + − + , +). Example 5.13. Consider a flat strea m function sp ecification with the following rules which use pa tter n matching on the data constr uctors 0 and 1 : f ( 0 : σ ) → g ( σ ) f ( 1 : x : σ ) → x : g ( σ ) g ( x : y : σ ) → x : y : g ( σ ) denoted ρ f 0 , ρ f 1 , and ρ g , re s pectively . Then, h f i is the so lution for X f , 1 of: X f ( n ) = min( X f ,⋆ (0) , X f , 1 ( n )) X f , 1 ( n ) = inf  X f , 1 ,ρ f 0 ( n ) , X f , 1 ,ρ f 1 ( n )  X f , 1 ,ρ f 0 ( n ) = let n ′ := n − 1 , if n ′ < 0 then 0 else X g , 1 ( n ′ ) X f , 1 ,ρ f 1 ( n ) = let n ′ := n − 2 , if n ′ < 0 then 0 else 1 + X g , 1 ( n ′ ) X f ,⋆ ( n ) = min( X g ,⋆ (0) , 1 + X g ,⋆ (0)) X g , 1 ( n ) = let n ′ := n − 2 , if n ′ < 0 then 0 else 2 + X g , 1 ( n ′ ) X g ,⋆ ( n ) = 2 + X g ,⋆ (0) . As solution we obtain a n ov erla pping of bo th traces h f i 1 ,ρ f 0 and h f i 1 ,ρ f 1 , that is , h f i 1 ( n ) = n . − 2 re presented by the gate h f i = gate ( −−− +). The following prop osition explains the c orresp ondence b etw een Def. 5.1 a nd Def. 5.9. Prop osition 5.14 . L et T b e a str e am sp e cific ation. F or e ach f ∈ Σ sfun it holds: h f i ( n 1 , . . . , n k ) = [ [[ f ]] ]( n 1 , . . . , n k ) (for al l n 1 , . . . , n k ∈ N ), wher e k = ar s ( f ) . That is, the p-i fun ction tr anslation h f i of f c oincides with the p-i function t hat is r epr esente d by the gate tr anslation [ f ] . Data-Oblivious Stream Pro ductivity 41 The following lemma sta tes that the tra nslation h f i of a flat stream function symbol f (as defined in Def. 5.1) is the d-o lower b ound on the pro duction function of f . F or friendly nesting stre am symbols f it states that h f i p oint wisely bo unds from below the d-o low e r b ound on the pro duction function of f . Lemma 5.1 5. L et T b e a str e am sp e cific ation, and let f ∈ Σ fnest ⊇ Σ flat . (i) If f is flat, then: h f i = do T ( f ) . H enc e, do T ( f ) is p erio dic al ly incr e asing. (ii) If f is friend ly nesting, then it holds: h f i ≤ do T ( f ) (p ointwise ine quality). 5.2 T ranslation of Stream Constants In the seco nd step, we now define a translatio n of strea m cons ta n ts in a fla t o r friendly nesting stream sp ecifica tio n into pro duction terms under the a ssump- tion that gate tr a nslations for the stream functions are g iven. Her e the idea is that the recursive definition of a strea m co nstant M is unfolded step by step; the terms thus aris ing are tra nslated accor ding to their structure using gate tra ns - lations o f the s tream function symbols from a given family of g ates; whenever a stream constant is met that has b een unfolded b efore, the trans lation stops after establishing a binding to a µ -binder created ea rlier. Definition 5.1 6. Let T = h Σ , R i be a stream sp ecification, and F = { γ f } f ∈ Σ sfun a family of gates that a re asso cia ted with the sy mbo ls in Σ sfun . Let T er ( Σ ) 0 S be the set of terms in T of sor t strea m that do not co ntain v ariables o f sort stream. The tra ns lation function [ · ] F : T er ( Σ ) 0 S → P is defined by s 7→ [ s ] F := [ s ] F ∅ based on the following definition of expressions [ s ] F α , where α ⊆ Σ sc on , by induction o n the structur e of s ∈ T er ( Σ ) 0 S , using the cla uses: [ M ( u )] F α := ( µM . mi n { [ r ] F α ∪{ M } | M ( v ) → r ∈ R } if M 6∈ α M if M ∈ α [ u : s ] F α := • ([ s ] F α ) [ f ( s 1 , . . . , s ar s ( f ) , u 1 , . . . , u ar d ( f ) )] F α := γ f ([ s 1 ] F α , . . . , [ s ar s ( f ) ] F α ) where M ∈ Σ sc on , u = h u 1 , . . . , u ar d ( M ) i a vector o f terms in T er ( Σ ) D , f ∈ Σ sfun , s, s 1 , . . . s ar s ( f ) ∈ T er ( Σ ) 0 S , and u, u 1 , . . . , u ar d ( f ) ∈ T er ( Σ ) D . Note that the defi- nition of [ M ( u )] F α do es not dep end o n the vector u of terms in T er ( Σ ) D . There- fore we define, for all M ∈ Σ sc on , the tr anslation of M with r esp e ct to F b y [ M ] F := [ M ( x )] F ∅ ∈ P where x = h x 1 , . . . , x ar d ( M ) i is a vector of data v ariables. The fo llowing lemma is the basis of our result in Sec. 6, Thm. 6.1 , concerning the decidability of d-o pr o ductivit y for flat s tream sp ecifications. In pa rticular the le mma states that if we us e gates that repr e sent d-o optimal lower b ounds on the pro duction of the strea m functions, then the tr anslation of a strea m constant M yie lds a pro duction term that rewrites to the d-o low er b ound of the pro duction of M . 42 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Lemma 5.1 7. L et T = h Σ , R i b e a stre am sp e cific ation, and F = { γ f } f ∈ Σ sfun b e a family of gates such t hat, for al l f ∈ Σ sfun , the arity of γ f e quals the stre am arity of f . Then t he fol lowing st atemen ts hold: (i) S upp ose that [ [ γ f ] ] = do T ( f ) holds for al l f ∈ Σ sfun . Then for al l M ∈ Σ sc on and ve ctors u = h u 1 , . . . , u ar d ( M ) i of data t erms [ [[ M ] F ] ] = do T ( M ( u )) holds. And c onse qu en t ly, T is d-o pr o ductive if and only if [ [[ M 0 ] F ] ] = ∞ . (ii) Su pp ose that [ [ γ f ] ] = do T ( f ) holds for al l f ∈ Σ sfun . Then for al l M ∈ Σ sc on and ve ctors u = h u 1 , . . . , u ar d ( M ) i of data t erms [ [[ M ] F ] ] = do T ( M ( u )) holds. And c onse qu en t ly, T is d-o non-pr o ductive if and only if [ [[ M 0 ] F ] ] < ∞ . Lem. 5 .17 is an immediate consequence of the following lemma, whic h also is the basis o f our result in Sec. 6 conc e rning the recogniza bilit y o f pro ductivity for flat and friendly nesting stream specific a tions. In particular the lemma b elow as s erts that if we us e gates that r epresent p-i functions which are low er b ounds o n the pro duction of the str e am functions, then the tra nslation of a stream constant M yields a pro duction term that rewrites to a num b er in N s ma ller or equa l to the d-o low e r b ound of the pro duction of M . Lemma 5.1 8. L et T b e a str e am s p e cific ation, and let F = { γ f } f ∈ Σ sfun b e a family of gates such that, for al l f ∈ Σ sfun , the arity of γ f e quals the str e am arity of f . Supp ose t hat one of t he fol lowing st atements holds: (a) [ [ γ f ] ] ≤ do T ( f ) for al l f ∈ Σ sfun ; (b) [ [ γ f ] ] ≥ do T ( f ) for al l f ∈ Σ sfun ; (c) do T ( f ) ≤ [ [ γ f ] ] for al l f ∈ Σ sfun ; (d) do T ( f ) ≥ [ [ γ f ] ] for al l f ∈ Σ sfun . Then, for al l M ∈ Σ sc on and ve ctors u = h u 1 , . . . , u ar d ( M ) i of data terms in T , the c orr esp onding one of t he fol lowing statements holds: (a) [ [[ M ] F ] ] ≤ do T ( M ( u )) ; (b) [ [[ M ] F ] ] ≥ do T ( M ( u )) ; (c) do T ( M ( u )) ≤ [ [[ M ] F ] ] ; (d) do T ( M ( u )) ≥ [ [[ M ] F ] ] . 6 Deciding Data-Oblivious Pro ductivit y In this section we assemble our res ults concerning decis ion of d-o pr o ductivit y , and automata ble recognitio n of pro ductivity . W e define metho ds: ( DOP ) for deciding d-o pro ductivity o f flat stre am sp ecifications, ( DP ) for deciding pro ductivity of pure stre a m sp ecifications, a nd ( RP ) for rec o gnising pr o ductivity of friendly nes ting stream s pecifica tions, that pro cee d in the following steps: Data-Oblivious Stream Pro ductivity 43 (i) T a ke a s input a ( DOP ) flat, ( DP ) pure, or ( RP ) fr iendly nesting s tream sp eci- fication T = h Σ , R i . (ii) T r anslate the stream function symbols int o ga tes F := {h f i } f ∈ Σ sfun (Def. 5.1 ). (iii) Co nstruct the pr oductio n term [ M 0 ] F with res pect to F (Def. 5.16). (iv) Co mpute the pro duction k of [ M 0 ] F using → R (Def. 4.27 ). (v) Give the fo llowing output: ( DOP ) “ T is d-o pr o ductive” if k = ∞ , else “ T is not d-o pr o ductive”. ( DP ) “ T is pro ductive” if k = ∞ , else “ T is not pro ductive”. ( RP ) “ T is pro ductive” if k = ∞ , else “don’t know”. Note that all o f thes e steps are automa table (cf. o ur pro ductivity to ol, Sec. 8 ). Our main r esult states that d-o pr o ductivity is de c ida ble for flat stream sp ec- ifications. It rests o n the fact tha t the a lgorithm DOP o btains the low er b ound do T ([ M 0 ]) on the pro duction of M 0 in T . Since d-o productivity implies pro- ductivit y (Pr op. 3.4), we obtain a computable, d-o o ptimal, sufficient condition for pro ductivity o f flat stream s pecifica tions, which canno t b e impr ov ed by any other d-o a na lysis. Seco nd, since for pure stream sp ecifications d-o pro ductivity and pro ductivity are the same, we get that pro ductivity is decida ble for them. Theorem 6.1. (i) D OP de cides d-o pr o ductivity of flat str e am sp e cific ations, (ii) DP de cides pr o ductivity of pur e stre am sp e cific ations. Pr o of. Let k b e the pro ductio n of the term [ M 0 ] F ∈ P in step (iv) of DOP / DP . (i) By Lem. 5.15 (i), L e m. 5.17 (i), Lem. 4.28, Lem. 4.2 9 w e find: k = do T ( M 0 ). (ii) F o r pure sp ecifica tio ns we additionally no te: Π T ( M 0 ) = do T ( M 0 ). ⊓ ⊔ Third, w e obtain a computable, sufficient conditio n for pro ductivity o f friendly nesting strea m sp ecifications. Theorem 6.2. A friend ly nesting (flat) str e am sp e cific ation T is pr o ductive if the algorithm R P ( DO P ) r e c o gnizes T as pr o ductive. Pr o of. Let k b e the pro ductio n of the term [ M 0 ] F ∈ P in step (iv) of RP / DO P . B y Lem. 5.1 5 (ii), Lem. 5.1 8 (a), Lem. 4.28 a nd Lem. 4.29 : k ≤ do T ( M 0 ) ≤ Π T ( M 0 ). ⊓ ⊔ Example 6.3. W e illustra te the translation and decision o f d-o pro ductivit y by means o f Pascal’s triangle, Fig. 2. The trans lation of the stream function sym- bo ls is F = {h f i } with h f i = gate ( −− +), see page 32. W e calculate [ P ] F , the translation of P , a nd reduce it to normal form with re spect to → R : [ P ] F = µP . • ( • ( − − +( P ))) ։ R µP. + + −− +( P ) → R ∞ Hence do T ( P ) = ∞ , and P is d-o pro ductive a nd therefore pr o ductive. 44 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks 7 Examples Pro ductivity o f all of the follo wing exa mples is recognized fully automatica lly by a Haskell implementation of our decision algo rithm for data-o blivious pro duc- tivit y . The to ol and a num b er o f examples can b e fo und at: http://inf inity.few.vu.nl/pr o ductivity . In Subsections 7.1–7.6 b elow, we give p ossible input-r epresentations a s well as the to ol-output for the exa mples of stream sp ecificatio ns in Section 2 a nd for an example of a str e am function sp ecifica tio n in Section 3. 7.1 Example in Fig. 2 on P age 3 F or applying the automated pro ductivity prover to the flat s tream spe cification in Fig. 2 on page 2 of the stream o f rows in Pascal’s triangle, one can use the input: Signature( P : stream(nat ), 0 : nat, f : stream(nat ) -> stream(nat), a : nat -> nat -> nat, s : nat -> nat ) P = 0:s(0):f(P ) f(s(x):y:s igma) = a(s(x),y):f(y :sigma) f(0:sigma) = 0:s(0):f(s igma) a(s(x),y) = s(a(x,y)) a(0,y) = y On this input the automated pro ductivit y prov e r pro duces the following output: The a uto mated pro ductivity prover has been applied to : Signature( -- stream symbols -- P : stream(nat ), f : stream(nat ) -> stream(nat), -- data symbol s -- 0 : nat, a : nat -> nat -> nat, s : nat -> nat ) -- stream layer -- P = 0:s(0):f(P ) f(s(x):y:s igma) = a(s(x),y):f(y :sigma) Data-Oblivious Stream Pro ductivity 45 f(0:sigma) = 0:s(0):f(s igma) -- data layer -- a(s(x),y) = s(a(x,y)) a(0,y) = y T ermination o f the data lay er ha s b een proven automatically . The function s ym b ol f is flat, we can compute the precis e data-o blivious low er bo und: [ f ] = g ate ([ f ] ⋆, 0 ( 0 ) , [ f ] 1 , 0 ) [ f ] 1 , 0 = µ f 1 , 0 . ∧          −− + ∧    µ f 1 , 1 . ∧    − + ∧ n f 1 , 1 ++ ∧ n f 1 , 0 − ++ ∧ n f 1 , 0 = − − + [ f ] ⋆, 0 = µ f ⋆, 0 . ∧ ( + f ⋆, 0 ++ f ⋆, 0 = + P dep ends o nly on flat stream functions, we ca n decide data-obli vious pro- ductivit y . W e tra nslate P into a p ebbleflow net a nd colla ps e it to a sour c e : 5 [ P ] = µP. • ( • ([ f ]( P ))) = µP . • ( • ( −− +( P ))) ։ R µP. + − +( • ( −− +( P ))) ։ R µP. + − +(+ − +( −− +( P ))) ։ R µP. + + − ( −− +( P )) ։ R µP. + + −− +( P ) ։ R ∞ The sp ecificatio n of P is pr o ductive. 7.2 Example in Fig. 3 on P age 6 F or applying the automated pro ductivity prover to the flat s tream spe cification in Fig. 3 o n page 6 of the ternary T hue-Morse sequence , one can use the input: Signature( Q, Qprime : stream (char), 46 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks f : stream(cha r) -> stream(char ), a, b, c: char ) Q = a:Qprime Qprime = b:c:f(Qpr ime) f(a:sigma) = a:b:c:f(si gma) f(b:sigma) = a:c:f(sigm a) f(c:sigma) = b:f(sigma) On this input the automated pro ductivit y prov e r pro duces the following output: The a uto mated pro ductivity prover has been applied to : Signature( -- stream symbols -- Q : stream(cha r), Qprime : stream(ch ar), f : stream(cha r) -> stream(char ), -- data symbol s -- a : char, b : char, c : char ) -- stream layer -- Q = a:Qprime Qprime = b:c:f(Qpr ime) f(a:sigma) = a:b:c:f(si gma) f(b:sigma) = a:c:f(sigm a) f(c:sigma) = b:f(sigma) -- data layer -- Data-Oblivious Stream Pro ductivity 47 The function s ym b ol f is flat, we can compute the precis e data-o blivious low er bo und: [ f ] = g ate ([ f ] ⋆, 0 ( 0 ) , [ f ] 1 , 0 ) [ f ] 1 , 0 = µ f 1 , 0 . ∧          − +++ ∧ n f 1 , 0 − ++ ∧ n f 1 , 0 − + ∧ n f 1 , 0 = − + [ f ] ⋆, 0 = µ f ⋆, 0 . ∧      +++ f ⋆, 0 ++ f ⋆, 0 + f ⋆, 0 = + Q depe nds only on flat str eam functions, we can decide data-oblivio us pro- ductivit y . W e tra nslate Q into a p ebbleflow net and colla ps e it to a sourc e: 6 [ Q ] = µQ. • ( µQpr ime. • ( • ([ f ]( Qpr ime ))) ) = 1 µQ. • ( µQpr ime. • ( • ( − +( Qpri me )))) ։ R µQ. + − +( µQpri me. • ( • ( − +( Qpr ime )))) ։ R µQ. + − +( µQpri me. + − +( • ( − +( Qpr ime )))) ։ R µQ. + − +( µQpri me. + − +(+ − +( − +( Qpr ime )))) ։ R µQ. + − +( µQpri me. ++ − ( − +( Qpr ime ))) ։ R µQ. + − +( µQpri me. ++ − ( Qpr ime )) ։ R µQ. + − +( ∞ ) ։ R µQ. ∞ ։ R ∞ The sp ecificatio n of Q is pro ductive. Qpr i me dep ends only on flat str eam functions, we ca n decide data-oblivious pro ductivit y . 48 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks W e tra nslate Qprime into a pe bbleflow net and co llapse it to a so urce: 7 [ Qpr i me ] = µQpr i me. • ( • ([ f ]( Qpr ime ))) = µQpr ime. • ( • ( − +( Qpr ime ))) ։ R µQpr ime. + − +( • ( − +( Qpri me ))) ։ R µQpr ime. + − +(+ − +( − +( Qpr ime ))) ։ R µQpr ime. ++ − ( − +( Qpr ime )) ։ R µQpr ime. + + − ( Qpri me ) ։ R ∞ The sp ecificatio n of Qprime is pro ductive. 7.3 Example in Fig. 4 on P age 7 F or a pplying the automated pro ductivit y prov er to the pure stream specifica tion in Fig. 4 o n page 7 of the ternary T hue-Morse sequence , one can use the input: Signature( Q : stream(cha r), M : stream(bit ), zip : stream(x ) -> stream(x) -> stream(x), inv : stream(b it) -> stream(bit ), tail : stream( x) -> stream(x), diff : stream( bit) -> stream(char), i : bit -> bit, X : bit -> bit -> char, 0, 1 : bit, a,b,c : char ) Q = diff(M) M = 0:zip(inv( M),tail(M)) zip(x:s,t) = x:zip(t,s) inv(x:s) = i(x):inv(s) tail(x:s) = s diff(x:y:s ) = X(x,y):diff(y :s) i(0) = 1 i(1) = 0 X(0,0) = b X(0,1) = a X(1,0) = c X(1,1) = b The a uto mated pro ductivity prover then gives the following o utput: Data-Oblivious Stream Pro ductivity 49 The a uto mated pro ductivity prover has been applied to : Signature( -- stream symbols -- Q : stream(cha r), M : stream(bit ), zip : stream(x ) -> stream(x) -> stream(x), inv : stream(b it) -> stream(bit ), tail : stream( x) -> stream(x), diff : stream( bit) -> stream(char), -- data symbol s -- i : bit -> bit, X : bit -> bit -> char, 0 : bit, 1 : bit, a : char, b : char, c : char ) -- stream layer -- Q = diff(M) M = 0:zip(inv( M),tail(M)) zip(x:s,t) = x:zip(t,s) inv(x:s) = i(x):inv(s) tail(x:s) = s diff(x:y:s ) = X(x,y):diff(y :s) -- data layer -- i(0) = 1 i(1) = 0 X(0,0) = b X(0,1) = a X(1,0) = c X(1,1) = b T ermination o f the data lay er ha s b een proven automatically . 50 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks The function sy m b ol zip is pure, we can compute its precise pr o ductio n mo dulus: [ zip ] = gate ([ zip ] ⋆, 0 ( 0 ) , [ zip ] 1 , 0 , [ zip ] 2 , 0 ) [ zip ] 1 , 0 = µ zip 1 , 0 . ∧ n − + ∧ n µ zip 2 , 0 . ∧ n + ∧ n zip 1 , 0 = − + + [ zip ] 2 , 0 = µ zip 2 , 0 . ∧ n + ∧ n µ zip 1 , 0 . ∧ n − + ∧ n zip 2 , 0 = + − + [ zip ] ⋆, 0 = µ zip ⋆, 0 . ∧ n + zip ⋆, 0 = + The function symbol inv is pure, we can compute its precis e pr o duction mo dulus: [ inv ] = gate ([ inv ] ⋆, 0 ( 0 ) , [ inv ] 1 , 0 ) [ inv ] 1 , 0 = µ inv 1 , 0 . ∧ n − + ∧ n inv 1 , 0 = − + [ inv ] ⋆, 0 = µ inv ⋆, 0 . ∧ n + inv ⋆, 0 = + The function s y m b ol tail is pure, we can compute its precise pro ductio n mo dulus: [ tail ] = gate ([ tail ] ⋆, 0 ( 0 ) , [ tail ] 1 , 0 ) [ tail ] 1 , 0 = µ tail 1 , 0 . ∧ n − µx. − + x = −− + [ tail ] ⋆, 0 = µ tail ⋆, 0 . ∧ n µx. + x = + The function symbol di ff is pure, we can co mpute its precise pro duction mo dulus: [ diff ] = g ate ([ diff ] ⋆, 0 ( 0 ) , [ diff ] 1 , 0 ) [ diff ] 1 , 0 = µ diff 1 , 0 . ∧ n −− + ∧ n µ diff 1 , 1 . ∧ n − + ∧ n diff 1 , 1 = − − + [ diff ] ⋆, 0 = µ diff ⋆, 0 . ∧ n + diff ⋆, 0 = + Data-Oblivious Stream Pro ductivity 51 Q dep ends only on pure s tr eam functions , we can de cide pro ductivit y . W e tra nslate Q into a p ebbleflow net and colla ps e it to a sourc e: 8 [ Q ] = µQ. [ diff ]( µM . • ([ zip ]([ inv ]( M ) , [ tail ]( M )))) = µQ. −− +( µM . • ( min ( − ++( − +( M )) , + − +( −− + ( M ))))) ։ R µQ. − − +( µM . • ( mi n ( − ++( M ) , + −− ++ ( M )))) ։ R µQ. −− +( µM . + − +( min ( − ++( M ) , + −− ++( M )))) ։ R µQ. − − +( µM . min (+ − +( − ++( M )) , + − +(+ −− ++( M )))) ։ R µQ. −− +( µM . min (+ − +( M ) , ++ −− ++( M ))) ։ R µQ. −− +( min ( µM . + − +( M ) , µM . + + −− ++( M ))) ։ R µQ. min ( − − +( µM . + − +( M )) , −− +( µM . ++ −− ++( M ))) ։ R min ( µQ. −− +( µM . + − +( M )) , µQ. −− +( µM . ++ −− ++( M ))) ։ R min ( µQ. − − +( ∞ ) , µQ. −− +( ∞ )) ։ R min ( µQ. ∞ , µQ. ∞ ) ։ R min ( ∞ , ∞ ) ։ R ∞ The sp ecificatio n of Q is pro ductive. M dep ends o nly on pure strea m functions, we can decide pro ductivit y . W e tra nslate M into a p ebbleflow net a nd collapse it to a so urce: 8 [ M ] = µM . • ([ zip ]([ inv ]( M ) , [ tail ]( M ))) = µM . • ( min ( − ++( − +( M )) , + − +( −− +( M )))) ։ R µM . • ( min ( − ++( M ) , + −− ++( M ))) ։ R µM . + − +( min ( − ++( M ) , + −− ++( M ))) ։ R µM . mi n (+ − +( − ++( M )) , + − +(+ −− ++( M ))) ։ R µM . mi n ( + − +( M ) , ++ −− ++( M )) ։ R min ( µM . + − +( M ) , µM . + + −− ++( M )) ։ R min ( ∞ , ∞ ) ։ R ∞ The sp ecificatio n of M is pro ductive. 7.4 Example in Fig. 5 on P age 7 F or a pplying the automated pro ductivit y prov er to the pure stream specifica tion in Fig. 5 on page 7 of the Thue–Morse sequence using the D0L-system 0 7→ 01, 1 7→ 10, one can use the input: Signature( 52 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks M : stream(bit ), Mprime : stream(bi t), h : stream(bit ) -> stream(bit), 0, 1 : bit ) M = 0:Mprime Mprime = 1:h(Mprim e) h(0:sigma) = 0:1:h(sigm a) h(1:sigma) = 1:0:h(sigm a) The a uto mated pro ductivity prover then gives the following o utput: The a uto mated pro ductivity prover has been applied to : Signature( -- stream symbols -- M : stream(bit ), Mprime : stream(bi t), h : stream(bit ) -> stream(bit), -- data symbol s -- 0 : bit, 1 : bit ) -- stream layer -- M = 0:Mprime Mprime = 1:h(Mprim e) h(0:sigma) = 0:1:h(sigm a) h(1:sigma) = 1:0:h(sigm a) -- data layer -- The function symbol h is pur e, we ca n compute its precise pro duction mo dulus: [ h ] = gate ([ h ] ⋆, 0 ( 0 ) , [ h ] 1 , 0 ) [ h ] 1 , 0 = µ h 1 , 0 . ∧    − ++ ∧ n h 1 , 0 − ++ ∧ n h 1 , 0 = − ++ [ h ] ⋆, 0 = µ h ⋆, 0 . ∧ ( ++ h ⋆, 0 ++ h ⋆, 0 = + M dep ends o nly on pure strea m functions, we can decide pro ductivit y . Data-Oblivious Stream Pro ductivity 53 W e tra nslate M into a p ebbleflow net a nd collapse it to a so urce: 9 [ M ] = µM . • ( µM p rime . • ([ h ]( M pr ime ))) = µM . • ( µM pri me. • ( − ++( M prime ))) ։ R µM . + − +( µM pri me. • ( − ++( M prime ))) ։ R µM . + − +( µM pr ime. + − +( − ++( M pr ime ))) ։ R µM . + − +( µM pri me. + − +( M prime )) ։ R µM . + − +( ∞ ) ։ R µM . ∞ ։ R ∞ The sp ecificatio n of M is pro ductive. Mprime dep ends only on pure s tream functions, we can decide pro ductivit y . W e tra nslate Mprime in to a p ebbleflow net and collapse it to a sour c e : 9 [ Mprime ] = µM pr ime. • ([ h ]( M pri me )) = µM pr i me. • ( − ++( M pr ime )) ։ R µM p r ime. + − +( − ++( M p r ime )) ։ R µM p r ime. + − +( M pri me ) ։ R ∞ The sp ecificatio n of Mprime is pr o ductive. 7.5 Example in Fig. 6 on P age 8 F or a pplying the automated pro ductivit y prov er to the pure stream specifica tion in Fig. 6 on page 8 of the Thue–Morse sequence using the D0L-system 0 7→ 01, 1 7→ 10, one can use the input: Signature( nats, ones : stream(nat ), conv, add : stream (nat) -> stream(nat) -> stream(nat), times : stream (nat) -> nat -> stream(nat ), 0 : nat, s : nat -> nat, a, m : nat -> nat -> nat ) nats = 0:conv(ones ,ones) ones = s(0):ones conv(x:sig ma,y:tau) = m(x,y):add(tim es(tau,x),conv(sigma,y:tau)) times(x:si gma,y) = m(x,y):times (sigma,y) add(x:sigm a,y:tau) = a(x,y):add(sigm a,tau) 54 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks a(0,y) = y a(s(x),y) = s(a(x,y)) m(0,y) = 0 m(s(x),y) = a(y,m(x,y)) The a uto mated pro ductivity gives as output: The a uto mated pro ductivity prover has been applied to : Signature( -- stream symbols -- nats : stream( nat), ones : stream( nat), conv : stream( nat) -> stream(nat) -> stream(nat), add : stream(n at) -> stream(nat ) -> stream(nat), times : stream (nat) -> nat -> stream(nat ), -- data symbol s -- 0 : nat, s : nat -> nat, a : nat -> nat -> nat, m : nat -> nat -> nat ) -- stream layer -- nats = 0:conv(ones ,ones) ones = s(0):ones conv(x:sig ma,y:tau) = m(x,y):add(tim es(tau,x),conv(sigma,y:tau)) times(x:si gma,y) = m(x,y):times (sigma,y) add(x:sigm a,y:tau) = a(x,y):add(sigm a,tau) -- data layer -- a(0,y) = y a(s(x),y) = s(a(x,y)) m(0,y) = 0 m(s(x),y) = a(y,m(x,y)) T ermination o f the data lay er ha s b een proven automatically . The function symbol co nv is friendly nesting , we can compute a data -oblivious Data-Oblivious Stream Pro ductivity 55 low er b ound: [ conv ] = gate ([ conv ] ⋆, 0 ( 0 ) , [ conv ] 1 , 0 , [ conv ] 2 , 0 ) [ conv ] 1 , 0 = µ c onv 1 , 0 . ∧ n µx. − + x = − + [ conv ] 2 , 0 = µ c onv 2 , 0 . ∧ n µx. − + x = − + [ conv ] ⋆, 0 = µ c onv ⋆, 0 . ∧ n µx. − + x = − + The function symbol ad d is pure, we can compute its precise pro duction mo dulus: [ add ] = gate ([ add ] ⋆, 0 ( 0 ) , [ add ] 1 , 0 , [ add ] 2 , 0 ) [ add ] 1 , 0 = µ add 1 , 0 . ∧ n − + ∧ n add 1 , 0 = − + [ add ] 2 , 0 = µ add 2 , 0 . ∧ n − + ∧ n add 2 , 0 = − + [ add ] ⋆, 0 = µ add ⋆, 0 . ∧ n + add ⋆, 0 = + The function symbol times is pure, we can compute its prec is e pro duction mo d- ulus: [ times ] = gate ([ times ] ⋆, 0 ( 0 ) , [ times ] 1 , 0 ) [ times ] 1 , 0 = µ times 1 , 0 . ∧ n − + ∧ n times 1 , 0 = − + [ times ] ⋆, 0 = µ times ⋆, 0 . ∧ n + times ⋆, 0 = + nats dep ends only o n flat strea m functions, we try to pro ve pro ductivit y . 56 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks W e tra nslate nats into a p ebbleflow net and collapse it to a sour c e: 10 [ nats ] = µnats. • ([ co n v ]( µones. • ( ones ) , µones. • ( ones ))) = µnats. • ( min ( − +(0) , min ( − +( µones. • ( ones )) , − +( µones. • ( ones ))))) ։ R µnats. + − +( min ( − +(0) , min ( − +( µone s. • ( ones )) , − +( µones. • ( ones ))))) ։ R µnats. min (+ − +( − +(0)) , + − +( min ( − +( µones. • ( ones )) , − +( µones. • ( ones ))))) ։ R µnats. min (+ − (0) , + − +( min ( − +( µone s. • ( ones )) , − +( µones. • ( ones ))))) ։ R min ( µnats. + − (0) , µnats. + − +( min ( − +( µones. • ( ones )) , − +( µones. • ( ones ))))) ։ R min ( µnats. 1 , µnats. min (+ − +( − +( µone s. • ( ones ))) , + − +( − +( µones. • ( ones ))))) ։ R min ( µnats. 1 , µnats. min (+ − ( µones. • ( ones )) , + − ( µones. • ( ones )))) ։ R min (1 , min ( µnats. + − ( µones. • ( one s )) , µnats. + − ( µones. • ( ones )))) ։ R min (1 , min ( µnats. + − ( µones. + − +( ones )) , µnats. + − ( µones. + − +( ones )))) ։ R min (1 , min ( µnats. + − ( ∞ ) , µnats. + − ( ∞ ))) ։ R min (1 , min ( µnats. ∞ , µna ts. ∞ )) ։ R min (1 , min ( ∞ , ∞ )) ։ R min (1 , ∞ ) ։ R 1 F ailed to prov e pro ductivity of n a ts . ones dep ends only on pure s tream functions, we can decide pro ductivity . W e tra nslate ones into a p ebbleflow net a nd colla ps e it to a sourc e: 10 [ ones ] = µones. • ( ones ) = µones. • ( ones ) ։ R µones. + − +( ones ) ։ R ∞ The sp ecificatio n of ones is pro ductive. 7.6 Example on P age 12 Now we consider the strea m function s p ecifica tio n b elow Def. 3.5 on page 12, which is not a stream sp ecification b ecaus e it do es not contain a stream co nstant as its ro ot. Still, the automated pr o ductivit y prov er can b e used to co mpute the precise data -oblivious low er b ound of the stream function f . On the input: Signature( f : stream(bit ) -> stream(bit), g : stream(bit ) -> stream(bit) -> stream(bit ), 0, 1 : bit ) Data-Oblivious Stream Pro ductivity 57 f(s) = g(s,s) g(0:y:s,x: t) = 0:0:g(s,t) g(1:s,x1:x 2:x3:x4:t) = 0:0:0:0:0:g(s ,t) the pro ductivity prov er g enerates the following output: The a uto mated pro ductivity prover has been applied to : Signature( -- stream symbols -- f : stream(bit ) -> stream(bit), g : stream(bit ) -> stream(bit) -> stream(bit ), -- data symbol s -- 0 : bit, 1 : bit ) -- stream layer -- f(s) = g(s,s) g(0:y:s,x: t) = 0:0:g(s,t) g(1:s,x1:x 2:x3:x4:t) = 0:0:0:0:0:g(s ,t) -- data layer -- The function s ym b ol f is flat, we can compute the precis e data-o blivious low er bo und: [ f ] = gate ([ f ] ⋆, 0 ( 0 ) , [ f ] 1 , 0 ) [ f ] 1 , 0 = µ f 1 , 0 . ∧                ∧                µ g 1 , 0 . ∧    −− ++ ∧ n g 1 , 0 − +++++ ∧ n g 1 , 0 µ g 2 , 0 . ∧    − ++ ∧ n g 2 , 0 −−−− +++++ ∧ n g 2 , 0 = −− −− ++ − ++ − + −− ++ − + − ++ − [ f ] ⋆, 0 = µ f ⋆, 0 . ∧ ( µ g ⋆, 0 . ∧ ( ++ g ⋆, 0 +++++ g ⋆, 0 = + 58 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks The function symbol g is fla t, we can compute the precis e data-oblivio us low e r bo und: [ g ] = g a t e ([ g ] ⋆, 0 ( 0 ) , [ g ] 1 , 0 , [ g ] 2 , 0 ) [ g ] 1 , 0 = µ g 1 , 0 . ∧    −− ++ ∧ n g 1 , 0 − +++++ ∧ n g 1 , 0 = −− ++ [ g ] 2 , 0 = µ g 2 , 0 . ∧    − ++ ∧ n g 2 , 0 −−−− +++++ ∧ n g 2 , 0 = −− −− ++ − ++ − + [ g ] ⋆, 0 = µ g ⋆, 0 . ∧ ( ++ g ⋆, 0 +++++ g ⋆, 0 = + 8 Conclusion and F urther W ork In order to for malize quantitativ e appro aches fo r r ecognizing pro ductivity of stream s pecifica tions, we defined the notion of d-o r ewriting and in vestigated d-o pro ductivity . F or the sy n ta c tic clas s o f flat s tr eam s pecifica tions (that employ pattern matching on data), we devised a decision a lg orithm for d-o pro ductiv- it y . In this wa y we settled the pro ductivity r ecognition problem for flat stream sp ecifications from a d-o p ersp ective. F or the e v e n larg er class including friendly nesting stream function rules , we obtained a co mputable sufficient co nditio n for pro ductivity . F or the sub class of pure str eam s pecifica tions (a substantial exten- sion of the cla ss given in [2]) we s how ed that pro ductivity and d- o pro ductivity coincide, and ther e b y obtained a decision algor ithm for pr o ductivit y of pure sp ecifications. W e hav e implemented in Haskell the decision algorithm for d- o pro ductivity . This tool, together with more information including a man ual, examples, our related papers, and a compa rison of our criteria with those o f [3 , 9, 1] can b e found at our web page http://infinity.few .vu.nl/productivity . The rea de r is invited to exp eriment with our to ol. It is no t p ossible to obtain a d-o optimal criterio n for non-pro ductivit y of flat sp ecifications in an analogo us wa y to how we es tablished such a criterion for pro ductivity . This is b ecause d-o upp er b ounds on the pro duction of str eam functions in flat stre am sp ecifications are not in ge ne r al p erio dica lly increasing Data-Oblivious Stream Pro ductivity 59 functions. F o r example, fo r the fo llowing strea m function sp ecificatio n: f ( x : σ , τ ) → x : f ( σ , τ ) , f ( σ, y : τ ) → y : f ( σ, τ ) , it holds that do ( f )( n 1 , n 2 ) = n 1 + n 2 , which is not p-i. While this example is not orthogo nal, do ( f ) is als o no t p-i for the following simila r orthog onal exa mple: f ( 0 : x : σ , y : τ ) → x : f ( σ , τ ) , f ( 1 : σ , x : y : τ ) → y : f ( σ , τ ) . Currently we are developing a metho d tha t g o es b eyond a d-o ana lysis, one that would, e.g., pr ov e pro ductivity of the example B given in the intro duction. Moreov e r, we study a refined pro duction calculus that accounts for the delay of ev alua tio n of str eam elements, in o rder to obtain a faithful mo delling of la zy ev aluation, needed for example for S on pag e 4, where the first element dep ends on a ‘future’ e x pansion of S . A cknow le dgement. W e thank J an Willem K lop, Car los Lombardi, Vincent v an Oostro m, and Ro el de V rijer for useful dis c us sions. References 1. W. Buchholz. A T erm Calculus for (Co-)Recursive Defin itions on Streamlike Data Structures. Anna l s of Pur e and Applie d Lo gic , 136(1-2):75–90, 2005. 2. J. En d rullis, C. Grabmay er, D. H endriks, A. Isihara, and J.W. Klop. Pro ductivity of Stream D efinitions. I n Pr o c. of F CT 2007 , LNCS, pages 274–2 87. Sp ringer, 2007. 3. J. Hughes, L. Pareto, and A . Sabry . Proving the Correctness of R eactiv e Systems Using S ized T y p es. In POPL ’96 , p ages 410–423, 1996. 4. D. Kapu r, P . Narendran, D.J. Rosenkrantz, and H. Zhang. Sufficient-Completeness, Ground-Redu cibilit y and their Complexity. A cta Inf ormatic a , 28(4):311– 350, 1991. 5. J.W. Klop and R . de V rijer. Infi nitary Normalization. In S. Arte- mo v , H. Barringer, A.S. d’Avila Garcez, L.C. Lamb, and J. W o od s, editors, We W il l Show Them: Essa ys in Honour of Dov Gabb ay , vol u me 2, pages 169–192. College Publications, 2005. Item 95 at http://web .mac.com/janwillem klo p/iWeb/Site/Bibliography.html . 6. J.J.M. M. Rutten . Beha vioural Differential Equ ations: a Coinductive Calculus of Streams, Automata, and Po wer Series. The or etic al Computer Scienc e , 308(1-3):1– 53, 2003. 7. A. Salomaa. Jewels of F ormal L anguage The ory . Pitman Publishing, 1981. 8. B.A. Sijtsma. On the Prod uctivity of R ecursive List Definitions. ACM T r ansactions on Pr o gr amming L anguages and Systems , 11(4):633– 649, 1989. 9. A. T elford and D. T urn er. Ensuring Streams Flo w. In AMAST , pages 509– 523, 1997. 10. T erese. T erm R ewriting Systems , volume 55 of Cambridge T r acts i n The or etic al Computer Scienc e . Cambridge Universit y Press, 2003. 60 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks App endix A Solving W eakly Guarded IO-T erm Sp ecifications (Lemma 5.3) Let E = { X α = E α } α ∈ A be a weakly guarded finite io-sequence s pecifica tion, r o ot ∈ A , and σ r oot the unique solution o f E for X r oot . Definition A.1. W e define a finite, ro oted gra ph G E = hV , L , v r oot i that repre- sents traces through the expressions in E . The set of no des V co nsists o f all pa ir s of α ∈ A tog ether with po s itions in E α , the right-hand side o f the corr e spo nding equation in E : V = {h α, p i | α ∈ A, p ∈ Pos ( E α ) } . Note that the set of no des V is finite. The ro ot no de v r oot is h r o ot , hii . The set of lab elled edg es L ⊆ V × {− , + , ǫ } × V is the smallest set such that: for all α ∈ A , and every p osition p ∈ Pos ( E α ) the following conditions hold: (i) if E α | p = X α ′ then h α, p i ǫ → h α ′ , hii ∈ L ; (ii) if E α | p = − E ′ then h α, p i − → h α, p · 1 i ∈ L ; (iii) if E α | p = + E ′ then h α, p i + → h α, p · 1 i ∈ L ; (iv) if E α | p = E ′ ∧ E ′′ then h α, p i ǫ → h α, p · 1 i and h α, p i ǫ → h α, p · 2 i ∈ L . where we hav e written v ℓ → w to denote h v , ℓ, w i ∈ L . Mo reov er, for ℓ ∈ {− , + , ǫ } , we let ℓ → denote the rela tion {h v , w i | v ℓ → w } . Note that by weak guardedness o f E the relation ǫ → is terminating. W e pro ceed by defining the set of traces T ( G E , v ) thro ugh the gr a ph G E starting a t no de v ∈ V . Definition A.2. F or a path ρ : v 1 l 1 → v 2 l 2 → . . . in G E , where l 1 , l 2 , . . . ∈ {− , + , ǫ } , we use t r ac e ( ρ ) to denote l 1 · l 2 · · · ∈ ± ∞ , the word obtained by concatenating the symbo ls ‘ − ’ and ‘+’ along the path ρ , thus treating the lab el ‘ ǫ ’ as the empt y word. Note that tra c e ( ρ ) ∈ ± ω whenever the path ρ is infinite by weak guardedness of E . The set o f tra ces T ( G E , v ) ⊆ ± ω through G E from v ∈ V is defined as follows: T ( G E , v ) := { tr ac e ( ρ ) | ρ is an infinite path starting from no de v in G E } . F or Z ≡ { τ 1 , . . . , τ n } ⊆ ± ω , let V τ ∈ Z τ denote τ 1 ∧ . . . ∧ τ n , where ∧ is the binary o p era tion defined in Def. 4 .13. If Z = ∅ , w e set V τ ∈ Z τ = +. The following lemma establishes a cor resp ondence b etw een the sp ecification E and the g r aph G E , in particular it implies that the unique solution σ r oot of E for X r oot equals the infimum over all tr aces through G E from the ro ot no de. Lemma A.3. F or α ∈ A , p ∈ Pos ( E α ) , let σ ( α, p ) ∈ ± ω denote the u nique solu- tion for the ex pr ession E α | p in E , and let τ ( α, p ) b e shorthand for V τ ∈ T ( G E , h α, p i ) τ . Then, for al l α ∈ A , p ∈ Pos ( E α ) , we have σ ( α, p ) = τ ( α, p ) . Data-Oblivious Stream Pro ductivity 61 Pr o of. By coinduction, i.e., we show that the relatio n R ∈ ± ω × ± ω defined by: R := {h σ ( α, p ) , τ ( α, p ) i | α ∈ A, p ∈ Pos ( E α ) } is a bisimulation. W e pro ceed b y well-founded induction on pairs h α, p i with resp ect to ǫ → . (Base) If v := h α, p i is in norma l for m with r esp ect to ǫ → , then v has pre c is ely one outg o ing edge: v − → o r v + → . In case v − → , we hav e that E α | p = − E ′ , and therefore σ ( α, p ) = − σ ( α, p · 1). F urther more, w e hav e τ ( α, p ) = − τ ( α, p · 1), and clearly h σ ( α, p · 1) , τ ( α, p · 1 ) i ∈ R . The pro of for case v + → pro ceeds ana logously . (Step) If v := h α, p i is not a normal form with r e spect to ǫ → , then either v has one o utgoing edge v ǫ → v ′ or tw o outgo ing edges v ǫ → v ′ and v ǫ → v ′′ . In the first case we have E α | p = X α ′ , and then v ′ = h α ′ , hii , σ ( α, p ) = σ ( α ′ , hi ) and τ ( α, p ) = τ ( α ′ , hi ), and we conclude by a n application of the induction hypothesis for h α ′ , hii . In the second ca se we hav e tha t E α | p = E ′ ∧ E ′′ , a nd then v ′ = h α, p · 1 i and v ′′ = h α, p · 2 i . Thus we ge t σ ( α, p ) = σ ( α, p · 1) ∧ σ ( α, p · 2 ), and, by ass o ciativity of ∧ , τ ( α, p ) = τ ( α, p · 1) ∧ τ ( α, p · 2). W e conclude b y a double a pplication of the induction h y p othesis . ⊓ ⊔ The set T ( G E , v ) consists of infinite, p ossibly non-pro ductive io-sequences. Therefore w e adopt the definition of the pro duction function [ [ σ ] ] : N → N to b e applicable to non-pro ductive io -sequences σ by dropping ∞ from the domain. Definition A.4. The pr o duction funct ion ˜ π σ of a sequence σ ∈ ± ω is corecur - sively defined by , for all n ∈ N , ˜ π σ ( n ) := ˜ π ( σ, n ): ˜ π (+ σ, n ) = 1 + ˜ π ( σ, n ) , ˜ π ( − σ , 0 ) = 0 , ˜ π ( − σ, n + 1) = ˜ π ( σ, n ) . A pr o per t y o f the o p era tion ∧ given in Def. 4.13 is tha t the mapping [ [ ] ] : ± ∞ → N → N preser ves infim um, see Prop. 4.19 . Clearly , a simila r pr op erty holds for ˜ π : for all σ 1 , σ 2 ∈ ± ω , w e hav e: ˜ π σ 1 ∧ σ 2 = ˜ π σ 1 ∧ ˜ π σ 2 . Then, the fo llowing coro llary dire ctly follows fr om Lemma A.3. Corollary A.5. F or al l n ∈ N we have ˜ π σ ro ot ( n ) = inf { ˜ π τ ( n ) | τ ∈ T ( G E , v r oot ) } . Mor e over, given n ∈ N , we c an always pick a tr ac e τ ∈ T ( G E , v r oot ) such that ˜ π τ ( n ) = ˜ π σ ro ot ( n ) . Using G E we define a ‘tw o-dimensiona l dia g ram’ D E ⊆ V × N × N re pr esenting the traces o f E star ting fro m X r oot as step functions. F or v ∈ V , x, y ∈ N let v x,y be shorthand for h v , x, y i . The ho rizontal axis ( x -axis) of T co rresp onds to input, and the vertical a xis ( y -axis) to output; that is, a ‘ − ’ in the trace yields a step to the right in the dia gram and ‘+’ a s tep upw ards . 62 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Definition A.6. F or U ⊆ V × N × N w e define G E ( U ) ⊆ V × N × N , the one-step closur e of U under G E , as follows: G E ( U ) := U ∪ G E ,ǫ ( U ) ∪ G E , + ( U ) ∪ G E , − ( U ) G E ,ǫ ( U ) := { w x,y | v x,y ∈ U, v ǫ → w ∈ L} G E , + ( U ) := { w x,y +1 | v x,y ∈ U, v + → w ∈ L} G E , − ( U ) := { w x +1 ,y | v x,y ∈ U, v − → w ∈ L} F urthermore we define G ∗ E ( U ) := [ n ∈ N G n E ( U ) , the many-step closur e of U under G E . Definition A.7. W e define D E ⊆ V × N × N as D E := G ∗ E ( { v r oot 0 , 0 } ). The dia g ram D E contains the traces throug h G E starting from v r oot as ‘step functions’. Lemma A.8. F or al l v ∈ V , x, y ∈ N we have v x,y ∈ D E if and only if ther e exists a p ath ρ : v r oot → ∗ v in G E such that x = # − ( tr ac e ( ρ )) , y = # + ( tr ac e ( ρ )) . Pr o of. F ollows immediately from the definition of D E . ⊓ ⊔ W e pro ceed by showing that the so lutio n σ r oot of E for X r oot coincides with the ‘low er b ound’ o f the traces in D E . Definition A.9. F or U ⊆ V × N × N a nd G E = hV , L , v r oot i as a bove, w e define low U : N → N , the lower b ound of U , as follows: low U ( x ) := inf { y ∈ N | v x,y ∈ U, ∃ w. v − → w ∈ L} , where inf ∅ = ∞ . Lemma A.10 . The lower b ound of D E is the solut ion σ r oot of E for X r oot : ∀ n ∈ N . low D E ( n ) = ˜ π σ ro ot ( n ) Pr o of. Let n ∈ N , we show ˜ π σ ro ot ( n ) ≥ low D E ( n ) and ˜ π σ ro ot ( n ) ≤ low D E ( n ). ≥ F or ˜ π σ ro ot ( n ) = ∞ the pr o o f oblig a tion is trivial, thus as sume ˜ π σ ro ot ( n ) < ∞ . F rom Coro llary A.5 it follows that there exists a seq uenc e τ ∈ T ( G E , v r oot ) such that ˜ π τ ( n ) = ˜ π σ ro ot ( n ). Since ˜ π τ ( n ) < ∞ and τ ∈ ± ω , there exis ts m ∈ N with # − ( τ 0 ...m − 1 ) = n < n + 1 = # − ( τ 0 ...m ), and # + ( τ 0 ...m − 1 ) = ˜ π τ ( n ). Then ther e is a path ρ : v r oot → ∗ v − → v ′ in G E such that tr ac e ( ρ ) = τ 0 ...m . B y Lemma A.8 we hav e v n, ˜ π σ ro ot ( n ) ∈ D E , and together with v − → v ′ we conclude ˜ π σ ro ot ( n ) ≥ low D E ( n ) acco rding to Definition A.9. Data-Oblivious Stream Pro ductivity 63 ≤ Assume low D E ( n ) < ∞ . F r om Definition A.9 it follows that there exist no des v , v ′ ∈ V with v n, low D E ( n ) ∈ D E and v − → v ′ . Co nsequently by Lemma A.8 there exists a pa th ρ : v r oot → ∗ v − → v ′ in G E such that # − ( tr ac e ( ρ )) = n + 1 and # + ( tr ac e ( ρ )) = low D E ( n ). W e c ho os e a τ ∈ ± ω that has tr ac e ( ρ ) as a pre fix, so that ˜ π τ ( n ) = low D E ( n ). Then, by Corolla ry A.5, we know that ˜ π σ ro ot ( n ) ≤ low D E ( n ). W e co nc lude ˜ π σ ro ot ( n ) = low D E ( n ). ⊓ ⊔ Although in principle D E could be used to calculate σ r oot for every n ∈ N , it remains to be shown how a rationa l representation of the solution σ r oot of E for X r oot can b e obtained. F or this purp ose w e construct a ‘simpler’ dia gram D 0 E ⊆ D E that has the sa me low er b ound. W e construct D 0 E such tha t there a re only finitely many no des o n each vertical line; ther e by we employ the idea that whenever ther e are t wo no des w x,y , w x,y ′ with y < y ′ , then we can omit the upper occur rence w x,y ′ (including all traces r ising from w x,y ′ ) without having an influence on the low er b ound low D E ( x ). Definition A.11 . W e define functions G 0 E , omit : ( V × N × N ) → ( V × N × N ): G 0 E ( U ) := U ∪ G E ,ǫ ( U ) ∪ G E , + ( U ) omit ( U ) := { v x,y | v x,y ∈ U, ¬∃ y ′ < y . v x,y ′ ∈ U } Let D 0 E ( n ) ⊆ V × N × N for all n ∈ N be defined as follows: D 0 E (0) := vclosur e ( { v r oot 0 , 0 } ) D 0 E ( n + 1) := D 0 E ( n ) ∪ D 0 E | n +1 D 0 E | n +1 := vclosur e ( step right ( n )) step righ t ( n ) := { w n +1 ,y | v n,y ∈ D 0 E ( n ) , v − → w ∈ L} , where vclosur e ( U ) ⊆ V × N × N is defined to b e vc o m ( U ) for the s mallest m ∈ N such that vc o m +1 ( U ) = vc o m ( U ) where vc o := omit ◦ G 0 E , the vertical one-step closure follow ed by an application of omit . F urthermore w e define D 0 E := S n ∈ N D 0 E ( n ) . Note that D 0 E ( n ) is finite for all n ∈ N . The impo rtant step in the constr uction is the termination of vclosur e ( ) which is gua ranteed by the following lemma. Lemma A.12 . The c omputation of vclosur e ( U ) is terminating for finite sets U ⊆ V × N × N , that is, t her e exists m ∈ N su ch that vc o m +1 ( U ) = vc o m ( U ) . Pr o of. F or U ⊆ V × N × N we intro duce auxiliar y definitions : X ( U ) := { x ∈ N | ∃ v ∈ V , y ∈ N . v x,y ∈ U } ⊆ N V ( U, x ) := { v ∈ V | ∃ y ∈ N . v x,y ∈ U } ⊆ V Y ( U, x, v ) := { y ∈ N | v x,y ∈ U } ⊆ N y ( U, x, v ) := min( Y ( U, x, v )) ∈ N . 64 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Note that Y ( W , x, v ) = { y ( W, x, v ) } is a singleton se t for every W := omit ( U ), x ∈ X ( W ) a nd v ∈ V ( W, x ) with U ⊆ V × N × N arbitra ry . Let U ⊆ V × N × N . W e define U 0 := U a nd for n = 1 , 2 , . . . let U n := vc o ( U n − 1 ) . Note that U n = vc o n ( U ). F rom the definition of G 0 E and omit it follows that: (i) ∀ n ∈ N . X ( U n ) = X ( U ), (ii) ∀ n ∈ N . U n ⊆ G 0 E ( U n ), (iii) ∀ n ∈ N , x ∈ X ( U ) . V ( U n , x ) ⊆ V ( U n +1 , x ), since V ( U n , x ) ⊆ V ( G 0 E ( U n ) , x ) = V ( vc o ( U n ) , x ) = V ( U n +1 , x ) (iv) ∀ n ≥ 1 , x ∈ X ( U ) . |V ( U n , x ) | ≤ |V | . By (iii) and (iv) we conclude that there exists n 0 ∈ N : ∀ n ≥ n 0 , x ∈ X ( U ) . V ( U n , x ) = V ( U n 0 , x ) , (1) that is, the s e t of no des V ( U n , x ) on ea c h vertical str ip x b ecomes fixed after n 0 steps. F ur thermore by (ii) and the definition of omit we get ∀ n ∈ N , x ∈ X ( U ) , v ∈ V ( U n , x ) . y ( U n +1 , x, v ) ≤ y ( U n , x, v ) , (2) that is , the heigh ts of the no des are non- inc r easing. Therefor e for ea ch x ∈ X ( U ) and no de v ∈ V ( U n 0 , v ) there ex is ts m x,v ≥ n 0 such that: ∀ n ≥ m x,v . y ( U n , x, v ) = y ( U m x,v , x, v ) Let m := max { m x,v | x ∈ X ( U ) , v ∈ V ( U n 0 , v ) } , then the heights of all no des are fixed from m onw ards a nd consequently we hav e ∀ n ≥ m. U n = U m . ⊓ ⊔ Lemma A.13 . D E and D 0 E have the same lower b ound, that is, low D E = low D 0 E . Pr o of. Now w e constr uct a rational r epresentation of the low e r bo und of D 0 E , which by Le mma A.13 and A.10 is the solution σ r oot of E for X r oot . The co nstruction is based on a ‘rep etition search’ o n D 0 E , that is, w e search tw o v er tical strips x 1 and x 2 that contain similar constellatio ns of no des allowing to conclude that from the vertical po sition x 1 onw ards the low er b ound is ‘quasi per io dic’. Definition A.14 . F or x ∈ N , v ∈ V let V ( x ) := { v ∈ V | ∃ y ∈ N . v x,y ∈ D 0 E ( x ) } ⊆ V y ( x, v ) := ( y if there exists y ∈ N with v x,y ∈ D 0 E ( x ) ∞ otherw is e . Note that y ( x, v ) is well-defined since there ex ists at most one s uch y ∈ N . Data-Oblivious Stream Pro ductivity 65 Definition A.15 . F or x ∈ N we define h ( x ) := min { y ( x, v ) | v ∈ V } , the height of the low est no de on the vertical strip x . Definition A.16 . F or x ∈ N , v ∈ V let y r ( x, v ) := y ( x, v ) − h ( x ) , the height of the no de v relative to the low est no de on str ip x . Definition A.17 . F or x 1 < x 2 ∈ N with V ( x 1 ) 6 = ∅ a nd V ( x 2 ) 6 = ∅ let d ( x 1 , x 2 ) := h ( x 2 ) − h ( x 1 ) , the height difference betw ee n the vertical strips x 1 and x 2 . Definition A.18 . F or x 1 < x 2 ∈ N , v ∈ V with v ∈ V ( x 1 ) and v ∈ V ( x 2 ) let d ( x 1 , x 2 , v ) := y ( x 2 , v ) − y ( x 1 , v ) , the height difference of the no de v b et ween the vertical str ips x 1 and x 2 , and d r ( x 1 , x 2 , v ) := h ( x 1 , x 2 , v ) − d ( x 1 , x 2 ) , the relative heig h t difference of the no de v b etw een the vertical strips x 1 and x 2 . Lemma A.19 . F or x 1 , x 2 ∈ N , v ∈ V ( x 1 ) it holds: y r ( x 2 , v ) = y r ( x 1 , v ) + d r ( x 1 , x 2 , v ) . Pr o of. Immediately from the definitions. ⊓ ⊔ W e pro ceed with the definition of ‘pseudo rep etitions’ h x 1 , x 2 i ∈ N 2 . That is, we require that the vertical strips x 1 and x 2 po ssess a s imila r constella tion of no des. A pse udo repetition do es not yet guar antee ‘qua si per io dicit y ’ of the lower bo und (having found the cyclic pa rt of the io-se quence), as will b e explained a fter the definition. Definition A.20 . A pseudo r ep etition is a pair h x 1 , x 2 i ∈ N 2 such that: (i) The vertical s trips x 1 and x 2 contain the s a me set of no des v ∈ V : V ( x 1 ) = V ( x 2 ) (ii) F r o m strip x 1 to x 2 all no des have increased their height by at least d ( x 1 , x 2 ): ∀ v ∈ V . d r ( x 1 , x 2 , v ) ≥ 0 66 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks F or a pseudo r epe titio n h x 1 , x 2 i we c an dis tinguish b etw een no des v for which d r ( x 1 , x 2 , v ) = 0 a nd those with d r ( x 1 , x 2 , v ) > 0. If for a ll no des v ∈ V ( x 1 ) it holds that d r ( x 1 , x 2 , v ) = 0 then we ha ve an exact r epetitio n, yielding ‘quasi per io dicit y ’ of the low er b ound. On the other hand assume that there is a no de v ∈ V ( x 1 ) which increases its relative height and c o n tr ibutes to the low er b ound betw een the vertical s tr ips x 1 and x 2 . Then we do not yet have a ‘quasi per io dic’ low er b o und, b ecause due to the increas ing relative height of v , the contribution v to the low er bo und will change. F or this rea s on we will later strengthen the conditions on ps eudo rep etitions, yielding ‘rep etitions’ which then will guara n tee ‘quasi p erio dicity’, see Definition A.27. Lemma A.21 . Ther e exist pseudo r ep etitions in D 0 E . Pr o of. F or every x ∈ N we hav e V ( x ) ∈ P ( V ) and P ( V ) is a finite s et. Hence it follows fro m the Pigeonho le Principle tha t ther e exist indices i 1 < i 2 < i 3 < . . . with V ( i 1 ) = V ( i 2 ) = V ( i 3 ) = . . . , let V ′ := V ( i 1 ) = { v 1 , . . . , v k } with k = |V ( i 1 ) | . Let ≤ on N k be defined as follows: ( a 1 , . . . , a l ) ≤ ( b 1 , . . . , b l ) ⇔ a 1 ≤ b 1 ∧ . . . ∧ a l ≤ b l . F or x ∈ { i 1 , i 2 , . . . } we define the tuple t x := ( y r ( x, v 1 ) , . . . , y r ( x, v k )) ∈ N k . It is a well-known fact that ≤ is an almost full relation on N k , see [10]. Hence there exist x 1 , x 2 ∈ { i 1 , i 2 , . . . } with t x 1 ≤ t x 2 . Then d r ( x 1 , x 2 , v ) ≥ 0 for all v ∈ V ′ which es tablishes that h x 1 , x 2 i is a pseudo rep etition. ⊓ ⊔ The following definitions and lemmas a re auxilia ry for the purp ose of proving Lemma A.26. Definition A.22 . F or U , W ⊆ V × N × N and d x , d y ∈ N we define U ≤ d x ,d y W ⇐ ⇒ ∀ v x,y ∈ W. ∃ y ′ < y − d. v x − d x ,y ′ ∈ U . Lemma A.23 . F or x 1 < x 2 ∈ N and d y ∈ N we have: D 0 E | x 1 ≤ x 2 − x 1 ,d y D 0 E | x 2 ⇐ ⇒ ∀ v ∈ V ( x 1 ) . y ( x 2 , v ) ≥ d y + y ( x 1 , v ) Pr o of. F ollows from the definitions. ⊓ ⊔ Lemma A.24 . If U 1 , U 2 ⊆ V × N × N , d x , d y ∈ N with U 1 ≤ d x ,d y U 2 then: (i) vc o ( U 1 ) ≤ d x ,d y vc o ( U 2 ) , and (ii) vclosur e ( U 1 ) ≤ d x ,d y vclosur e ( U 2 ) . Pr o of. F r o m U 1 ≤ d x ,d y U 2 it follows that G 0 E ( U 1 ) ≤ d x ,d y G 0 E ( U 2 ) holds, and then we get omit ◦ G 0 E ( U 1 ) ≤ d x ,d y omit ◦ G 0 E ( U 2 ) by definition of omit . By induction w e get ∀ n ∈ N . vc o n ( U 1 ) ≤ d x ,d y vc o n ( U 2 ). F urthermor e ther e exist m 1 , m 2 ∈ N such that vclosur e ( U i ) = vc o m i ( U i ) for i ∈ { 1 , 2 } b y definition. F rom ∀ m ′ i ≥ m i . vc o m ′ i ( U i ) = vc o m i ( U i ) it follows that for i ∈ { 1 , 2 } we hav e vclosur e ( U i ) = vc o max( m 1 ,m 2 ) ( U i ). Hence vclosur e ( U 1 ) ≤ d x ,d y vclosur e ( U 2 ). ⊓ ⊔ Data-Oblivious Stream Pro ductivity 67 Lemma A.25 . If x 1 < x 2 ∈ N with V ( x 1 ) = V ( x 2 ) , then V ( x 1 + 1 ) = V ( x 2 + 1 ) . If mor e over D 0 E | x 1 ≤ x 2 − x 1 ,d y D 0 E | x 2 for d y ∈ N , then D 0 E | x 1 +1 ≤ x 2 − x 1 ,d y D 0 E | x 2 +1 . Pr o of. F r o m V ( x 1 ) = V ( x 2 ) and the definitio ns of D 0 E ( x 1 + 1) and D 0 E ( x 2 + 1) it follows that V ( x 1 + 1) = V ( x 2 + 1). Assume D 0 E | x 1 ≤ x 2 − x 1 ,d y D 0 E | x 2 and consider Definition A.1 1. Then it follows that step right ( x 1 ) ≤ x 2 − x 1 ,d y step right ( x 2 ). W e conclude with a n application of Lemma A.24 yielding D 0 E | x 1 +1 ≤ x 2 − x 1 ,d y D 0 E | x 2 +1 . ⊓ ⊔ Lemma A.26 . L et h x 1 , x 2 i b e a pseudo r ep etition. Then t he p air h x 1 + m, x 2 + m i is a pseudo r ep etition for al l m ∈ N . Pr o of. It suffices to show that h x 1 + 1 , x 2 + 1 i is a ps e udo rep etition, for m > 1 the claim follows by induction. W e g et V ( x 1 + 1) = V ( x 2 + 1) by Lemma A.25. F urthermore b y the definition of pseudo rep etition we hav e ∀ v ∈ V ( x 1 ) . d r ( x 1 , x 2 , v ) ≥ 0, which is equiv alen t to D 0 E | x 1 ≤ x 2 − x 1 ,d ( x 1 ,x 2 ) D 0 E | x 2 since V ( x 1 ) = V ( x 2 ). Emloying Le mma A.25 we get D 0 E | x 1 +1 ≤ x 2 − x 1 ,d ( x 1 ,x 2 ) D 0 E | x 2 +1 , that is ∀ v ∈ V ( x 1 + 1) . d r ( x 1 + 1 , x 2 + 1 , v ) ≥ 0. Hence h x 1 + 1 , x 2 + 1 i is a pseudo rep etition. ⊓ ⊔ W e pro ceed with the definition of ‘rep etitions’. Then we show that rep etitions exist a nd that these indeed gua rantee quasi p erio dicity of the low er b ound. Definition A.27 . A r ep etition is a pseudo re p etition h x 1 , x 2 i if: (i) h x 1 , x 2 i is a pseudo rep etition (ii) Let I ( x 1 , x 2 ) := { v x,y | v x,y ∈ T 0 , x = x 1 , i ( x 1 , x 2 , p ) = 0 } . W e req uire that only no des from I ( x 1 , x 2 ) contribute to the lower b ound b etw een x 1 and x 2 and these no des r econstruct themselfs o n the str ip x 2 : ∀ x ∈ N , x 1 ≤ x ≤ x 2 . low G E ( I ) ( x ) = low T 0 ( x ) (3) ∀ v x,y ∈ I ( x 1 , x 2 ) . v x 2 ,y + d ( x 1 ,x 2 ) ∈ G E ( I ) (4) Both conditions can b e effectively chec ked since G E ( I ) | ≤ n can b e computed for every n ∈ N . Having suc h a re p etition is is easy to see that the low er b ounds behaves ‘quas i p erio dic’ fro m this po in t onw ards, that is the io-sequence is in- deed ra tional. This is b ecause the the nodes with i ( x 1 , x 2 , v ) = 0 consitute a exactly r epea ting pattern. F urthermore the no des with increa sing rela tiv e heig h t i ( x 1 , x 2 , v ) > 0 do not contribute to the low er b ound betw een x 1 and x 2 , a nd since their height ca nno t decrea se they will a lso not co n tribute in the future. It remains to show that we indeed a lw ays encounter a rep etition h x 1 , x 2 i . W e know that there exists a pseudo rep etition h x 1 , x 2 i . Then we have for a ll m ∈ N we hav e h x 1 + m · ( x 2 − x 1 ) , x 2 + m · ( x 2 − x 1 ) i is a pseudo r e petition. F or all m ∈ N and v ∈ V we have i ( x 1 + m · ( x 2 − x 1 ) , x 2 + m · ( x 2 − x 1 ) , v ) ≥ 0, therefore it follows that there ar e some no des for which the relative height incr ease will even tually stay a t 0 while o ther no des contin ue increasing their rela tiv e height. The la tter will from some p oint on no longer contribute to the lower bo und and the pattern. Hence there e x ists m 0 for which h x 1 + m 0 · ( x 2 − x 1 ) , x 2 + m 0 · ( x 2 − x 1 ) i is a rep etition. 68 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks App endix B T ermination of the F unction La yer T ranslation (Lemma 5.10) It suffices to show that, for every stream function symbol f and ar gument p osition i of f , the infinite io-sequence sp ecificatio n E T defined in Def. 5.4 that has [ f ] i as unique solution for the recurs io n v ariable X h f , i, 0 i can be transformed in finitely many steps into a n io-sequence specific a tion E ′ with the same so lution for the recursion v aria ble X h f , i, 0 i and the pro p erty that only finitely man y r e cursion v ariables are re a chable in E ′ from X h f , i, 0 i . (This is b ecaus e from such a n io - sequence sp ecification E ′ even tually a finite io-sequence sp ecification E ′ 0 with [ f ] i as unique s olution for X h f , i, 0 i can b e e x tracted.) An a lgorithm for this purp ose is o btained as follows. On the input of E T , set E := E T and rep eat the following step o n E a s long a s it is applicable: (RPC) Detect and remov e a r e achable non-c onsuming pseudo-cycle from the io- sequence sp ecificatio n E : Supp ose that, for a function sy m b ol h , for j, k , l ∈ N , and for a recurs ion v ariable X h h , j , k i that is r eachable from X h f , i, 0 i , we hav e X h h , j , k i w − → X h h , j , l i (from the recursion v aria ble X h h , j , k i the v aria ble X h h , j , l i is reachable via a path in the sp ecification on which the finite io- sequence w is enco un ter e d as the word formed by consecutive labels ), where l < k a nd w only contains sym b ols ‘+’. Then modify E by setting X h h , j , k i = + X h h , j , k i . It is not difficult to show that a step (RPC) preser v e s weakly g ua rdedness and the unique solution of E , and tha t, o n input E T , the algo rithm terminates in finitely man y steps, pr oducing an io-sequence sp ecification E ′ with [ f ] i as the solution for X h f , i, 0 i and the prop erty that only finitely many r ecursion v ar iables are r eachable in E ′ from X h f , i, 0 i . Data-Oblivious Stream Pro ductivity 69 App endix C Soundness of the F unct ion La yer T ranslation Throughout, let T = h Σ , R i b e a fixed strea m sp ecification. Fir st w e intro duce a few axillary lemmas and definitio ns. Definition C.1 . F or all stream ter ms t ∈ T er ( L Σ M ) we define by # • ( t ) : = sup { n ∈ N | t = • k ( t ′ ) } the nu mb er of le ading s t r e am p ebbles of t . Definition C.2 . Let h ∈ Σ sfun be a a stream function symbol and j, k ∈ N . W e define h j,k := h ( . . . • ∞ . . . , • k ( σ ) , . . . • ∞ . . . ) ∈ T er ( L Σ M ) wher e the j -th ar g umen t po sition is • k ( σ ) while all other ar gument s a re • ∞ . Definition C.3 . F or terms s ≡ g ( • n 1 ( σ ) , . . . , • n k ( σ )) ∈ T er ( L Σ M ) t ≡ h ( • m 1 ( σ ) , . . . , • m k ( σ )) ∈ T er ( L Σ M ) with n 1 , . . . , n k , m 1 , . . . , m k ∈ N , we write s ⊳ t if n i ≤ m i for all i . Lemma C.4 . If s, t ∈ T er ( L Σ M ) as in Def. C.3 with s ⊳ t then do T ( s ) ≤ do T ( t ) . Pr o of. Immediately from the definition. ⊓ ⊔ W e pro o f the soundness o f the function layer translatio n, that is: Lemma C.5 . L et T b e a st r e am definition, and let f ∈ Σ sfun . (i) If T is flat, t hen it holds: [ [[ f ]] ] = do T ( f ) . Henc e, do T ( f ) is a p erio dic al ly incr e asing function. (ii) If T is friend ly nest ing, then it holds: [ [[ f ]] ] ≤ do T ( f ) . Pr o of. W e start w ith (i). Le t E T be the weakly gua rded io-sequence s p ecifica tio n (ov er v ar iables X ) obta ined from the tr a nslation. Let V : X → ( N → N ) be the unique solutio n o f E T , which exists b y Lemma 5 .3. Then by de finitio n we hav e [ [[ f ]] ] = min( V ( X h f , 1 , 0 i ) , . . . , V ( X h f , n, 0 i )). Assume f is not weakly g uarded. There e x ists g ∈ Σ sfun and γ : f ; ∗ g ; + g without pro duction; let Σ γ be the set of sym b ols o ccurr ing in γ and ρ 1 ,. . . , ρ n ∈ R the rules applied in γ (all having zer o pro duction). W e define T γ as the set of terms t ∈ T er ( L Σ M ) with r oot ( t ) ∈ Σ γ . Accor ing to Lemma 3.9 we can contruct a data- exchange function G such that fo r e very term t ∈ T γ either G ( t ) is not a r e dex or a redex with res pect to a ρ i . Then every r educt of a term t ∈ T γ in A T ( G ) as aga in in T γ and has ther efore no pro duction. Hence do T ( f ) = 0 and by definition [ [[ f ]] ] = 0 since X h f , i, 0 i = X h ǫ, −i for all 1 ≤ i ≤ ar s ( f ). The r emaining pro o f obligation is [ [[ f ]] ] = do T ( f ) for w ea kly gua rded f . W e start with [ [[ f ]] ] ≥ do T ( f ). Let p 1 , . . . , p ar s ( f ) ∈ N a nd define o := [ [[ f ]] ]( p 1 , . . . , p ar s ( f ) ). W e have V ( X h f , i, 0 i )( p i ) = o for some 1 ≤ i ≤ ar s ( f ). Note tha t do T ( f )( p 1 , . . . , p i , . . . , p ar s ( f ) ) ≤ do T ( f )( . . . ∞ . . . , p i , . . . ∞ . . . ) = do T ( f i,p i ) . 70 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Hence it suffices to show do T ( g i,q + p ) ≤ V ( X h g , i, q i )( p ) for a ll g ∈ Σ sfun , argument po sitions 1 ≤ i ≤ ar s ( g ) ∈ N and q , p ∈ N . F or the case V ( X h g , i, q i )( p ) = ∞ there is no thing to b e shown, hence let V ( X h g , i, q i )( p ) < ∞ . E mploying well-founded induction with r e s pect to the ordering > ov er tuples h g , i , q , p i with V ( X h g , i, q i )( p ) < ∞ we constr uct a data-exchange function G together with an outermost-fair rewrite sequence in A T ( G ) sta rting from g i,p + q as witness of do T ( g i,q + p ) ≤ V ( X h g , i, q i )( p ). The o r dering > is defined as follows: h g , i , q , p i > h g ′ , i ′ , q ′ , p ′ i ⇐ ⇒ g is weakly-guarded ∧ ( o > o ′ ∨ ( o = o ′ ∧ g ; + g ′ )) where o := V ( X h g , i, q i )( p ) , o ′ := V ( X h g ′ , i ′ , q ′ i )( p ′ ) Let G be an ar bitrary data-exchange function. The induction basis consists of the tuples h g , i, q , p i wher e – g is not weakly guar de d, or – V ( X h g , i, q i )( p ) = 0 a nd g is a norma l for m with resp ect to ; + . The not weakly guarded symbo ls hav e be en discussed a bove, therefore let g b e a normal for m with resp ect to ; + . By definition X h g , i, q i = V ρ ∈ R g X h g , i, q, ρ i , and hence V ( X h g , i, q, ρ i )( p ) = 0 for so me ρ ∈ R sfun . Then X h g , i, q, ρ i is either of s hape (shap e 1) − in ( ρ,i ) . − q + . . . or (shape 2 ) − ( in ( ρ,i ) . − q ) +1 + . . . T o see this cons ider the c a se distinction in the definitio n of X h g , i, q, ρ i : X h g , i, q, ρ i = − in ( ρ,i ) . − q + out ( ρ )      V j ∈ φ − 1 ( i ) X h h , j , ( q . − in ( ρ,i ))+ su ( ρ,j ) i for (a) ( C 1) + q . − in ( ρ,i ) X h ǫ, − + i for (b) if j = i ( C 2) X h ǫ, + i for (b) if j 6 = i ( C 3) W e have (shap e 1) in cas e of: – (C1) since g being a ; normal form and therefore out ( ρ ) > 0 , – (C2) if out ( ρ ) + ( q . − in ( ρ, i )) > 0, and – (C3) The (shap e 2) o ccurs in c ase (C2) if out ( ρ ) + ( q . − in ( ρ, i )) = 0. Let t ≡ g i,q + p and G ′ = G ( t, ρ ), then: Data-Oblivious Stream Pro ductivity 71 – Assu me X h g , i, q, ρ i is of (shap e 1). F rom V ( X h g , i, q , ρ i )( p ) = 0 it fo llows in ( ρ, i ) . − q > p and hence in ( ρ, i ) > q + p . G ′ ( t ) cannot b e a ρ -redex since ρ has at a rgument p o sition i a co nsumption greater than q + p . Hence g i,q + p is a normal form in A T ( G ′ ) by Lem. 3.9 and it follows that do T ( g i,q + p ) = 0. – Assu me X h g , i, q, ρ i is of (shap e 2). Then we have out ( ρ ) + ( q . − in ( ρ, i )) = 0 , hence out ( ρ ) = 0 and q ≤ in ( ρ, i ). F rom V ( X h g , i, q, ρ i )( p ) = 0 it follows that ( in ( ρ, i ) . − q ) + 1 = in ( ρ, i ) − q + 1 > p and therefore in ( ρ, i ) ≥ q + p . Then g i,q + p is a normal form if in ( ρ, i ) > q + p or g i,q + p → σ if in ( ρ, i ) = q + p in A T ( G ′ ); in b oth cas es do T ( g i,q + p ) = 0. This co ncludes the ba se case of the induction. Now we consider the induction step. By definition X h g , i, q i = V ρ ∈ R g X h g , i, q, ρ i , and hence V ( X h g , i, q i )( p ) = V ( X h g , i, q, ρ i )( p ) for some ρ ∈ R sfun . Let t ≡ g i,q + p and G ′ = G ( t, ρ ). Again we co nsider the case distinctio n (C1),(C2) and (C3) in the definition of X h g , i, q, ρ i . If in ( ρ, i ) . − q > p then in all ca s es V ( X h g , i, q, ρ i )( p ) = 0 and g i,q + p is a nor mal form in A T ( G ′ ), consequently do T ( g i,q + p ) = 0. Therefo re assume in ( ρ, i ) . − q ≤ p . (C1) X h g , i, q, ρ i = − in ( ρ,i ) . − q + out ( ρ ) V j ∈ φ − 1 ( i ) X h h , j , ( q . − in ( ρ,i ))+ su ( ρ,j ) i There exists j ∈ φ − 1 ( i ) with V ( X h g , i, q, ρ i )( p ) = e V ( p ) where e := − in ( ρ,i ) . − q + out ( ρ ) X h h , j , q ′ i q ′ := ( q . − in ( ρ, i )) + su ( ρ, j ) . Since in ( ρ, i ) . − q ≤ p , let p ′ := p − ( in ( ρ, i ) . − q ). W e get V ( X h g , i, q, ρ i )( p ) = out ( ρ ) + V ( X h h , j , q ′ i )( p ′ ) . (5) G ′ ( g i,q + p ) is a ρ -redex by Lem. 3.9, hence g i,q + p → A T ( G ′ ) • out ( ρ ) ( h ( • n 1 ( σ ) , . . . , • n ar s ( h ) ( σ ))) where by definition of ρ : n j = su ( ρ, j ) + ( q + p − in ( ρ, i )) = q ′ + p ′ . Therefore h ( • n 1 ( σ ) , . . . , • n ar s ( h ) ( σ )) ⊳ h j,q ′ + p ′ . W e hav e V ( X h g , i, q, ρ i )( p ) > V ( X h h , j , q ′ , ρ i )( p ′ ) or g ; h by (5 ), ther efore we get do T ( h j,q ′ + p ′ ) ≤ V ( X h h , j , q ′ i )( p ′ ) by induction hypo thes is and do T ( g i,q + p ) ≤ out ( ρ ) + do T ( h j,q ′ + p ′ ) ≤ out ( ρ ) + V ( X h h , j , q ′ i )( p ′ ) = V ( X h g , i, q, ρ i )( p ) = V ( X h g , i, q i )( p ) which pr ov es the claim. 72 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks (C2) X h g , i, q, ρ i = − in ( ρ,i ) . − q + out ( ρ ) + q . − in ( ρ,i ) X h ǫ, − + i Then V ( X h g , i, q, ρ i )( p ) = out ( ρ ) + ( q . − in ( ρ, i )) + V ( X h ǫ, − + i )( p − ( in ( ρ, i ) . − q )) = out ( ρ ) + ( q . − in ( ρ, i )) + ( p − ( in ( ρ, i ) . − q )) = out ( ρ ) + q + p − in ( ρ, i ) F urthermore in cas e (C2) ρ is collaps ing with i = j , therefore g i,q + p → A T ( G ′ ) • out ( ρ )+( q + p − in ( ρ,i )) ( σ ) . Hence do T ( g i,q + p ) ≤ out ( ρ ) + q + p − in ( ρ, i ) = V ( X h g , i, q, ρ i )( p ) . (C3) X h g , i, q, ρ i = − in ( ρ,i ) . − q + out ( ρ ) X h ǫ, + i Then V ( X h g , i, q, ρ i )( p ) = ∞ = do T ( g i,q + p ) since ρ is collaps ing with i 6 = j . This co ncludes the dir ection [ [[ f ]] ] ≥ do T ( f ). The rema ining pro of oblig ation is [ [[ f ]] ] ≤ do T ( f ). Let p 1 , . . . , p ar s ( f ) ∈ N and define o := do T ( f )( p 1 , . . . , p ar s ( f ) ) = do T ( f ( • p 1 , . . . , • p ar s ( f ) )). Assume o < ∞ , otherwis e there is nothing to b e shown. Then there exists a data-exchange function G and a finite r eduction sequence f ( • p 1 ( σ ) , . . . , • p ar s ( f ) ( σ )) → n A T ( G ′ ) • o ( t ) such that do T ( t ) = 0 and in particular – t is a normal for m in A T ( G ′ ), or – g is not weakly guar de d. W.l.o.g. choo se G and the reduction seq uence such that n is minimal. W e apply induction on the length of the re ductio n n to show – There exists 1 ≤ i ≤ ar s ( f ) such that do T ( f ( • p 1 ( σ ) , . . . , • p ar s ( f ) ( σ ))) = do T ( f ( • ∞ , . . . , • p i , . . . , • ∞ )) , – and [ [[ f ]] ] ≤ do T ( f ( • p 1 ( σ ) , . . . , • p ar s ( f ) ( σ ))). Data-Oblivious Stream Pro ductivity 73 App endix D Soundness of the Str eam La y er T ranslation (Lemma 5.17 and Lemma 5.18) D.1 Pro of Sk etch of Lemm a 5. 17 W e o nly s ketch a pro of of statement (i) o f Lem. 5.17 b ecause item (ii) o f this lemma ca n b e demonstr ated analog ously . Pr o of (of L em. 5.17, (i)). Let T b e an SCS, a nd let F = { γ f } f ∈ Σ sfun be a family of g ates such that, fo r all f ∈ Σ sfun , [ [ γ f ] ] = do T ( f ). W e give the ideas for the pro ofs of the inequations “ ≤ ” and “ ≥ ” that make part of the eq ua tion do T ( M 0 ) = [ [[ M 0 ] F ] ] . (6) W e assume, without loss of ge ner ality , that every f ∈ Σ sfun has prec isely one o ccurrence in the SCS- layer. Note that, by replacing for every f ∈ Σ sfun the individual o ccurrences of f in the SCS-lay er o f T b y individual o ccurrences of the s ym b ols f , f ′ , f ′′ , . . . , resp ectively , and intro ducing defining rules for f ′ , f ′′ , . . . in the SFS-part analogous to the defining rules for f that ar e a lready present there, an SCS T ′ is obtained that satisfies the restr iction, and for whic h it is easy to establish that it holds: do T ( M 0 ) = do T ′ ( M 0 ), [ M 0 ] F = [ M 0 ] F ′ , and henc e [ [[ M 0 ] F ] ] = [ [[ M 0 ] F ′ ] ], where F ′ = { γ f } f ∈ Σ ′ sfun is the family of gates ( Σ ′ sfun is the stream function signature of T ′ ) b y adding to F , for all symbo ls f ∈ Σ sfun , the corres p onding copies γ f ′ , γ f ′′ , . . . o f γ f . Note that we also hav e, for all f ′ ∈ Σ ′ sfun , [ [ γ f ′ ] ] = do T ( f ′ ). “ ≤ ”: W e only have to consider the ca se in which for k := [ [[ M 0 ] F ] ] it ho lds k < ∞ . Hence we assume that k < ∞ . Then ther e exists a finite rewrite s equence ρ : [ M 0 ] F ։ P • k ( p ′ ) . Then with p := [ M 0 ] F it follows that p ′ has the sa me ‘g ate structure’ as p , but po ssibly the io-sequences in the gates hav e changed, a nd there are likely to appea r many p ebbles queuing inside p ′ . By the definition of k it follows that [ [ p ′ ] ] = 0. Without loss of genera lit y , we ass ume that during ρ a ll extractable pe bbles have b een extracted from ‘inside’ the gates in p ′ , tha t is, there is no o ccurr e nce of a r edex in p ′ with re spect to the p ebbleflow rule min ( • ( p 1 ) , • ( p 2 )) → • ( min ( p 1 , p 2 )). Note that the o nly o ccurrence s of the symbol min in terms of ρ are pa r t of ga tes. (If this would not b e the case fo r ρ , then we would extend ρ by finitely many → P -steps to a r ewrite sequence ρ ′ which ha s this pr op e r t y , and base the further a rgumentation on ρ ′ .) Due to the ass umption that function sym b ols in Σ sfun only o ccur o nce in the SCS-lay er, to every f ∈ Σ sfun there cor resp onds in p (via the net translation in Def. 5.16) a unique gate γ f = [ f ]. W e now monitor, for every ga te γ f in p , the co nsumption/pro duction b ehaviour dur ing ρ . Let f ∈ Σ sfun . Suppo se that dur ing ρ , γ f consumes n 1 , . . . , n ar s ( f ) pebbles from its input comp onents, resp ectively , a nd that in total it pro duces n p ebbles. B y the assumption 74 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks that no extractable p ebbles ar e stuck inside γ f at the end of ρ , in par ticu- lar, [ [ γ f ] ]( n 1 , . . . , n ar s ( f ) ) = n follows. Mo reov er, by the a ssumption that the data-oblivio us lower bound do T ( f ) o f a sy m b ol f ∈ Σ sfun coincides with the pro duction function o f the gate γ f , we g et do T ( f )( n 1 , . . . , n ar s ( f ) ) = n . As a consequence, ther e is a rewrite sequence: ˜ ρ f : f ( • n 1 : σ 1 , . . . , • n ar s ( f ) : σ ar s ( f ) , • , . . . , • | {z } ar d ( f ) ) ։ A T , G • n : t in an ARS A T , G such that ˜ ρ f can b e extended to an outermost-fair re write sequence that do es not pro duce further pebbles. Then fro m ˜ ρ f we extra ct a rational gate ˜ γ f with the prop erties: (a) ˜ γ f precisely describ es the con- sumption/pro duction behaviour that happ ens during ˜ ρ f , (b) therea fter ˜ γ f contin ues like the gate corresp onding to f in p ′ . W e gather the new gates in the new fa mily of g ates: ˜ F := { ˜ γ f } f ∈ Σ sfun . Note that, for all f ∈ Σ sfun , [ [ γ f ] ] ≤ [ [ ˜ γ f ] ] holds . Nevertheless, it can be shown that there is actually also a rewrite se q uence: ˜ ρ : [ M 0 ] ˜ F ։ P • k ( ˜ p ′ ) . such that [ [ ˜ p ′ ] ] = 0. Using this p ebbleflow r e w r ite sequence ˜ ρ as well as the rewrite sequences ˜ ρ f on the abs tracted versions o f T , it is p ossible to obtain a rewr ite sequence in an ARS A T , G of the form: ¯ ρ : T T ( M 0 ) ։ ։ mω A T , G • k : s , where m is the le ng th of the r eduction seq ue nc e ˜ ρ , that can b e extended in A T , G to a rewrite seq uence ¯ ¯ ρ which consists of outer most-fair sequences of rewrite sequence s of length ω in which r e s pectively , for some g ∈ Σ sfun , g -r edexes ar e reduced uniformously in all unfoldings, and s uc h that further- more ¯ ¯ ρ do es not contain terms with a prefix of more than k p ebbles. The existence o f the rewrite sequence ¯ ¯ ρ on M 0 in an ARS A T , G demonstrates that do T ( M 0 ) ≤ k . “ ≥ ”: This dir e ction o f the pro o f is a c o nsequence o f three s tatemen ts tha t a re men tioned b elow. First, it holds that: F or all p ∈ P : [ [ T ( p )] ] = [ [ p ] ] , (7) where T ( p ) denotes the infinite unfolding of p into a p ossibly infinite ‘p eb- bleflow tree’. Second: F or all stream ter ms s in T : Π T ( s ) = Π T ( T T ( s )) , (8) where by s ∈ T er ( Σ ) we mean the result of infinitely unfolding all stream constants in s . Finally , third, it holds that: F or all strea m terms s in T : do T ( T T ( s )) ≥ [ [ T ([ s ] F )] ] . (9) Putting (7), (8), and (9) tog e ther , we obtain: do T ( M 0 ) = do T ( T T ( M 0 )) ≥ [ [ T ([ M 0 ] F )] ] = [ [[ M 0 ] F ] ] , which s hows “ ≥ ”. Data-Oblivious Stream Pro ductivity 75 This co ncludes our sketc h of the pro of of Lem. 5.1 7 (i). D.2 Pro of of Lemma 5 .18 Let T be a stream sp ecificatio n, and let F = { γ f } f ∈ Σ sfun be a fa mily of gates such that, for all f ∈ Σ sfun , the arity o f γ f equals the strea m ar it y o f f . Supp ose that one of the following sta temen ts holds: (a) [ [ γ f ] ] ≤ do T ( f ) for all f ∈ Σ sfun ; (b) [ [ γ f ] ] ≥ do T ( f ) for all f ∈ Σ sfun ; (c) do T ( f ) ≤ [ [ γ f ] ] for all f ∈ Σ sfun ; (d) do T ( f ) ≥ [ [ γ f ] ] for all f ∈ Σ sfun . In this s ection we show that then, for a ll M ∈ Σ sc on , the co rresp onding one of the following statements holds: (a) [ [[ M ] F ] ] ≤ do T ( M ) ; (b) [ [[ M ] F ] ] ≥ do T ( M ) ; (c) do T ( M ) ≤ [ [[ M ] F ] ] ; (d) do T ( M ) ≥ [ [[ M ] F ] ] . Multiple Numbe red Co n texts Definition D.1. L et T = h Σ , R i b e a str e am sp e cific ation, and k , l ∈ N . A (multiple numb er e d) str eam co n tex t C [ ] over str e am holes 2 1 , . . . , 2 k , and data holes 2 · 1 , . . . , 2 · ℓ is a (str e am) term C [ ] ∈ T er ∞ ( Σ ⊎ { 2 1 , . . . , 2 k } ⊎ { 2 · 1 , . . . , 2 · ℓ } , X ) S wher e the 2 i :: S and 2 · i :: D ar e distinct c onstant symb ols not o c curring in Σ . We denote by C [ t 1 , . . . , t k ; u 1 , . . . , u ℓ ] the r esu lt of r eplacing the o c curre n c es of 2 i by s i and 2 · j by t j in C [ ] T , r esp e ctively. R emark D.2. Each of the hole symbols 2 1 , . . . , 2 k , and 2 · 1 , . . . , 2 · ℓ may have m ultiple o ccurrences in a s tream co n text C [ ] o ver 2 1 , . . . , 2 k and 2 · 1 , . . . , 2 · ℓ , and this includes the case that it do es not o ccur in C [ ] at a ll. Example D.3. Let T b e a stream sp ecification with data constants b and c , a unary strea m function symbol f , and a bina ry stream function symbol g . Then the expression b : f ( c : g ( 2 · 1 : 2 1 , g ( 2 2 , g ( 2 1 , 2 3 )))) is a stream context ov er 2 1 , 2 2 , 2 3 and 2 · 1 . Also f ( b : 2 3 ) is a str eam co n text ov er 2 1 , 2 2 , 2 3 and 2 · 1 . But b : 2 1 : σ is no t a str eam context over 2 1 , b ecaus e the symbol 2 1 o ccurs at a ‘data po sition’ (this is excluded by ma n y- sortedness, : :: D → S → S and 2 1 :: S ). W e extend the d-o pr o duction function of stream function symbols f ∈ Σ sfun , Def. 3.5, to multiple num b ered contexts. 76 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks Definition D.4. Let T = h Σ , R i b e a str eam sp ecification, and C [ ] a mu l- tiple num b ered stream cont ext over stream holes 2 1 , . . . , 2 k , a nd data holes 2 · 1 , . . . , 2 · ℓ . The d-o pr o duction ra n ge do T ( C [ ] ) : N k → N of t he c ontext C [ ] is: do T ( C [ ] )( n 1 , . . . , n k ) := do T ( L C [ ] M (( • n 1 : σ ) , . . . , ( • n k : σ )) ) , where • m : σ := m time s z }| { • : . . . : • : σ . The d-o lower and u pp er b ounds on the pr o duction of g are defined by do T ( C [ ] ) : = inf ( do T ( C [ ] )) and do T ( C [ ] ) := sup( do T ( C [ ] )), resp ectively . Note that it is indeed a n extension o f Def. 3 .5, for every g ∈ Σ sfun we hav e do T ( g ) = do T ( g ( 2 1 , . . . , 2 ar s ( g ) , 2 · 1 , . . . , 2 · ar d ( g ) )) . The following lemma states that data- oblivious lower and upp e r b ounds a re reachable. Lemma D.5. L et T = h Σ , R i b e a str e am sp e cific ation, and s ∈ T er ∞ ( Σ ) S . Colouring T erms, T racing Data Fl ow F or the purp ose of trac ing the flow of data-elements during rewrite sequences , we introduce auxiliary ‘tracker symbols’ and partitio n ter ms in to ‘co loured’ multip le num b ered co n texts. Usua l rewriting will then b e allowed o nly within contexts. Rewrite s teps cross ing the b order betw een contexts are prohibited. In order to cir c umven t the loss of po ssible reduction steps, we introduce r ules for exchanging p ebbles b etw een neighboring contexts (rec olouring of the p ebbles). W e int r o duce aux ilia ry , unary function symbols ⋄ c and ⋄ · c in the pe bbleflow rewrite s ystem as w ell as in the str eam sp ecification T . The symbols ⋄ c mark the top of a context o f colo ur c a nd at the sa me time terminate the context ab ov e it. The symbols ⋄ · c only close, but do not o p en a context. W e call them t ra cker symb ols in the sequel, since they are also used to track p ebble/data exchange betw een neighbo r ing cont ex ts. Therefore we enrich the p ebbleflow rewrite system with the following rules ⋄ c ( • ( p )) → • ( ⋄ c ( p )) ⋄ · c ( • ( p )) → • ( ⋄ · c ( p )) (10) and the stream sp ecification T with rules ⋄ c ( t : σ ) → t : ⋄ c ( σ ) ⋄ · p ( t : σ ) → t : ⋄ · c ( σ ) (11) for every function symbol ⋄ c and ⋄ · c . W e define ⋄ c , ⋄ · c :: stream → stream , that is, the tra cker symbols ca nno t b e pla ced at data po sitions. Definition D.6. F or terms s, t we say that t is an enrichment of s with tr acker symb ols , denoted s ∠ t , if s ca n b e obtained from t b y removing tracker s ym b ols, that is, t → ∗ s via r ules ⋄ c ( u ) → u a nd ⋄ · c ( u ) → u . Data-Oblivious Stream Pro ductivity 77 Lemma D.7. Every p ebbleflow r e duction c an b e lifte d to en richte d terms: ∀ s, s ′ ∈ P , s ։ P s ′ , s ∠ t. ∃ t ′ . t ։ P ⋄ t ′ ∧ s ′ ∠ t ′ and str e am sp e cific ations T Every p ebbleflow rewr ite s equence a nd every stream sp ecifica tion rewrite sequence c an be lifted to enriched terms, i.e. ∀ s ′ և s ∠ t. ∃ t ′ . t ; ∗ t ′ ∧ s ′ ∠ t ′ where ; = → ∪ → (10) (or ; = → ∪ → (11) ). Sometimes the tra c ker symbols are in the wa y of rule application, but, bec a use of the spec ia l structure of p ebbleflow (resp. SCS) rules, it is alwa ys p ossible to move them awa y using rules (10 ) (resp. (11)). Now we s ket ch the pr o of for the inequalities “ ≤ ” (i) and “ ≥ ” (ii). “ ≤ ”: W e need to show [ [[ M ] F ] ] ≤ Π T ( M ). F or the pro of of (i) we map a given fi- nite p ebbleflow r ewrite seq ue nce on [ M ] F pro ducing n p ebbles to a T rewrite sequence o n the infinite unfolding of M that pro duces a t least n data ele- men ts. (F or (ii) the pro of pro ce e ds the other wa y a rround.) Thereby no t every rewrite step will be mapp ed, but we trace ‘essential’ steps and map them to a man y- step (possibly infinite) reductio n on ‘the other side’. F or this pur pos e we partition the p ebbleflow term [ M ] F as well a s infinite unfolding of M into co loured co n texts (using the same c olours for the net and the unfolding of M ). The pa rtitioning is arr anged in such a wa y tha t contexts o f the s ame colour ha ve the same pro duction function. In the sequel we will refer to this pro per t y as the c ontext pr o duction pr op erty (CPP ). Usual r ewriting will then b e allow ed only within contexts. Rewrite s teps crossing the bo rder b et ween co n tex ts are prohibited. In order to circumv ent the los s of p ossible reduction s teps , we in tro duce additional rules for e x - changing p ebbles b et ween neighboring contexts (reco louring o f the p ebbles). The construction o f the mapp ed reduction sequence will b e driven b y the g o al to uphold CPP . It can b e shown p ebbleflow rewr iting and SCS r ewriting do es not change the pro duction function of a context. Hence in order to maintain CPP it is not necessa ry to map internal steps o cur ring within co n tex ts . The ‘essential’ s teps are the exchange steps b etw een the contexts. W e us e C P c to refer to the context of co lour c in the p ebbleflow net [ M ] F . Likewise we use C T c for the co n tex t of colour c in the infinite unfolding of the stream co ns tan t M . Although there may be multiple, typically infinitely many , o ccur rences of a context with c o lour c o n the ter m level, contexts with the same colour are syntactically equal. Initially all contexts are of one of the following (simple) shap es: Clearly [ [ ] ] C P c = [ [ ] ] C T c for case 1. An impo rtant step in the pro of is to show that the tra nslation of functions s ym b ols into rational gates pre serves the quantitativ e pro ductio n be haviour, yielding [ [ ] ] C P c = [ [ ] ] C T c for cas e 2 . The pr o of now co n tinues as follows. Every p ebble exchange step in the p eb- bleflow net is mapp ed to a n infinite rewrite sequence on the co rresp onding coloured SCS term. F or the definition of these corr esp onding re w r ite s teps we apply the assumption [ [ ] ] C P c = [ [ ] ] C T c guaranteeing that a data element 78 J¨ org En drullis, Clemens Grabmay er, and D imitri Hendriks case C P c C T c 1 • ( 2 1 ) d : 2 1 2 min ( σ f , 1 ( 2 1 ) , . . . , σ f ,r ( 2 r )) f ( 2 1 , . . . , 2 r ) Fig. 15: Initial context configurations can also b e extracted from the cont e x t on SCS term le vel, and that after the step we hav e again [ [ ] ] C P c = [ [ ] ] C T c for all colours c . In this way , we define a rewrite sequence ρ T in T by induction on the num b er of re w r ite steps of the given p ebbleflow reduction ρ such that ρ T and ρ pro duce the s ame amount of data elements and p ebbles, resp ectively . “ ≥ ”: Here w e need to show [ [[ M ] F ] ] ≥ Π T ( M ). T he pr oo f of this inequalit y pro ceeds similarly to that of “ ≤ ” . Let ρ T in T b e a r eduction se quence in T . In o rder to ma p ρ T back to a p ebbleflow rewrite sequence ρ it is crucial that the co n texts of one colour are c hanged synchronously and in the sa me w ay . It cannot b e assumed that ρ T po sesses this pr ope r t y . F or this purp ose ρ T is transformed into a sequence ρ ′ T of complete dev elopments. This is always p ossible since c o mplete dev e lo pmen ts in orthogo nal TRSs a re a cofinal rewrite str ategy . F or ma pping ρ ′ T to a rewrite s equence ρ with the same pr o ductio n o n the p ebbleflow net, we can then pro ceed by induction on the length o f ρ ′ T , in co n verse direction to the a rgument for “ ≤ ”, ab ov e.

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment