We will now consider part 2 of theorem 5.1, i.e. the expressive completeness of QREs for term transducers. Since the proof very similar to the construction for string transducers, we will only highlight the differences.
5.11.1 Shapes and expression vectors
Recall the coffee shop machine from figure 3.4a. In figure 5.8, we present the summary of the string “SMCCM” starting from the stateq S. In the previous case, of string-to-string transducers, a shape was a copyless functionS:VÑV˚
.
In figure 5.8c, we summarize all paths of the form “SMCnM”: they all share the same shapetxÞÑ tx,zu,yÞÑ H,zÞÑ Hu, and are summarized by the expression vectorA:
Ax“splitpS¨MÞÑx`z,iterpCÞÑ2,`q,MÞÑ0,`q, Ay“S¨M¨C˚¨MÞÑ0, and
q S S qS M q S C q S C q S M q S x y z x y z x`z 0 0 x`z 2 1 x`z 4 1 x`z`4 0 0 (a) q S S¨M¨C¨C¨M q S x y z x`z`4 0 0 (b) q S S¨M¨Cn¨M q S x y z x`z`2n 0 0 (c)
Figure 5.8: Summarizing paths through SSTTs. We are referring to the machineM3 from
The string summary represents the final value of each register in terms of the initial register valuation. In the case of term transducers, a shapeS:VÑUpdSchemes is a function mapping each register v to an “update scheme”Spvq. The update scheme Spvq is a set of registers, where each registeruPSpvq is associated with a set of parameter substitutions
pp,Upq, wherepis a parameter andUpis itself an update scheme, indicating that during
the execution of the pathσ, the parameterpof the initial value ofvhas been substituted for some update schemeUp:
U ::“ tv1rp11:“U11,p12:“U12, . . . ,p1l:“U1ls,
v2rp21:“U21,p22:“U22, . . .s, . . .u (5.11.1)
We will only be interested in single-use update schemes and single-use shapes: note that there are only a finite number of single-use shapes over a finite set of registersV.
LetSbe a shape over the registers of an SSTTM. An expression vectorAwith shapeSis a map from each registervand update schemeUoccurring inSpvqto a consistent well-typed, single-use QRE,Av,U.
LetLĎΣ˚
be a set of paths starting from the stateqwith the same shapeS. Asummarizes
Lif: (a) for eachwPL,JAvKpwq “µpq,a,vq, and (b) for allv, DompAvq “L.
5.11.2 Ordering the registers and shapes
One subtle difficulty in the case of term transducers is that proposition 5.13 does not imme- diately carry over: since the registers are typed, it is not always feasible to respect a global ordering by renaming registers as we did in the previous construction.
We instead locally associate each stateqwith a total order over the registersĺq. A total order ĺq over a finite set of registersV permits the natural definition of “register rank”: rankq :VÑ t1, 2, . . . ,kusuch that rankqpuq ďrankqpvqiffuĺqv. A transitionqÑaq1
is upward-flowing if wheneverµpq,a,uqcontains an occurrence ofv, rankq1puq ďrankqpvq. It can be verified that if each transition of a pathσ“qÑwq1
is upward-flowing, then the whole path σis itself upward-flowing. With this finer notion of the register ordering, an equivalent of proposition 5.13 can be proved:
Proposition 5.22. For every SSTTM, there is an equivalent upward-flowing SSTTM1. Next, while our previous definitions of the ordering over shapesĎand support-equality„
in section 5.7 were quite general, we were eventually only concerned with iterating loops at a single stateqi`1. In the present setting, we can therefore restrict our attention to a per-state ordering over shapesĂq,Ďqand a per-state idea of support-equality„q. Apart from only
ordering shapes of self-loops at a single stateq, both definitions are otherwise identical to those in definition 5.14. We now have the following analogues of propositions 5.15, 5.16 and 5.17:
Proposition 5.23. Letσ“qÑwqbe aloopingpath through the SSTTMwith shapeS, and
σ1 be a sub-
Proposition 5.24. Let there bekregisters in the SSTTM. Choosek`1stringsw1,w2, . . . ,wk,w1P
Σ˚ and a
loopσ “qÑw1 qÑw2 qÑw3 ¨ ¨ ¨ Ñwk q Ñw1 qthrough the SST such that for
each i P t1, 2, . . . ,ku, the shapeSi of the sub-loop wi is support-equal to the shape Sof the entire loopσ. Then the prefix sub-loopqÑw1w2¨¨¨wk qalso has shapeS.
As before, a shapeSis stable if wheneveruÑvoccurs inS, thenvÑvalso occurs inS. Proposition 5.25. Let there bekregisters in the SSTT M. Let σ “ q Ñw1 q Ñw2 q Ñw3 ¨ ¨ ¨ Ñwk qbe a
loopthrough the SSTT such that for eachjP t1, 2, . . . ,ku, the shapeSjof the
sub-loopwjis support-equal to the shapeSof the entireloopσ. Then the shapeSis stable.
5.11.3 ComputingRpSi`1qpq,q1q
The construction ofRpSi`1qpq,q1qfor term transducers is similar to that for SSTs:
RpSi`1qpq,q1q “RSpiqpq,q1qelseCSpq,q1q, where CSpq,q1q “ ÿ tRpSiq 1pq,qi`1q ¨BS2¨R piq S3pqi`1,q 1 q |S1¨S2¨S3“Su, BS “BSelseB`S, and BS,v “ #
ÞÑv ifSis the identity shape, and
bot otherwise.
As before,BS summarizes the empty pathqi`1Ñqi`1with shapeS, andB`S summarizes
all non-empty pathsqi`1 Ñwqi`1with shapeS. We now focus on the construction ofB`S.
We proceed by induction on the pre-orderĎq`1. We already have the following expressions:
1. RpSi1qpq,q1qfor each shapeS1 and each pair of statesq,q1, and 2. BS1 for all shapesS1 ĹqS.
We construct the S-decomposition of self-loops qi`1 Ñw qi`1 exactly as before, and consider k-segments. The construction ofB`S for non-stable shapes is identical to that in
equation 5.9.1. For stable shapes, we recall the observation that for every registerusuch thatuÑvalong ak-segment,umust have been reset during the previousk-segment, and
so the value flowing intovwhile processing ws,m is entirely determined byws,m´1ws,m. We can use multi-expression iteration to capture this behavior: we include an expression
eu which computes the value ofuwhile processing eachk-segment, and the expressionev
which computesvincorporates the value ofeu. This argument can be formalized to obtain B`S and henceRpiS`q1pq,q1q
for stable shapesS.