• No se han encontrado resultados

Junta de Govern

In document Memòria del curs acadèmic 1996 1997 (página 39-46)

In a ranked tree, each symbol ahas a fixed arity k, and ana-labeled node has exactly

k children. Ranked trees can encode terms, and existing literature on tree transducers focuses primarily on ranked trees. Ranked trees can be encoded as nested words of a special form, and the definition of an STT can be simplified to use this structure. For simplicity of notation, we assume that there is a single 0-ary symbol0 6∈Σ, and every symbol inΣis binary. The setBT(Σ)ofbinary treesover the alphabetΣis then a subset of nested words defined by the grammarT := 0| ha T T ai, fora ∈ Σ. We will use the more familiar tree notationahtl,tri, instead ofha tltrai, to denote a binary tree witha- labeled root and subtreestlandtras children. The definition of an STT can be simplified in the following way if we know that the input is a binary tree. First, we do not need to

worry about processing of internal symbols. Second, we restrict to bottom-up STTs due to their similarity to bottom-up tree transducers, where the transducer returns, along with the state, values for variables ranging over output nested words, as a result of processing a subtree. Finally, at a call, we know that there are exactly two subtrees, and hence, the propagation of information across matching calls and returns using a stack can be combined into a unified combinator: the transition function computes the result corresponding to a treeahtl,tribased on the symbola, and the results of processing the subtreestl andtr.

Abottom-up ranked-tree transducer(BRTT) § from binary trees over Σ to nested words

over Γ consists of a finite set of states Q; an initial stateq0 ∈ Q; a finite set of typed

variables X equipped with a conflict relation η; a partial output function F : Q 7→

E0(X,Γ) such that for each state q, the expression F(q) is consistent with η; a state-

combinator functionδ : Q×Q×Σ 7→ Q; and a variable-combinator functionρ : Q×

Q×Σ 7→ A(X,Xl ∪Xr,η,Γ), where Xl denotes the set of variables {xl|x ∈ X}, Xr denotes the set of variables {xr|x ∈ X}, and the conflict relation η extends to these sets naturally: for every x,y ∈ X, if η(x,y), then η(xl,yl), and η(xr,yr). The state- combinator extends to trees inBT(Σ): δ∗(0) =q0andδ∗(ahtl,tri) = δ(δ∗(tl),δ∗(tr),a). The variable-combinator is used to map trees to valuations forX: α∗(0) = α0, where

α0 maps each type-0 variable to ε and each type-1 variable to ?, and α∗(ahtl,tri) = ρ(δ∗(tl),δ∗(tr),a)[Xl 7→ α∗(tl)][Xr 7→ α∗(tr)]. That is, to obtain the result of processing the tree t with a-labeled root and subtrees tl and tr, consider the states ql = δ∗(tl) andqr = δ∗(tr), and valuationsαl = α∗(tl)andαr = α∗(tr), obtained by processing the subtrees tl andtr. The state corresponding to t is given by the state-combinator δ(ql,qr,a). The value α∗(x) of a variable x corresponding to t is obtained from the right-hand sideρ(ql,qr,a)(x)by setting variables inXlto values given byαland setting variables inXrto values given byαr. Note that the consistency with the conflict relation ensures that each value gets used only once. Given a treet ∈ BT(Σ), letδ∗(t)beqand letα∗(t)beα. Then, if F(q)is undefined then [[S]](t)is undefined, else[[S]](t)equals α(F(q))obtained by evaluating the expressionF(q)according to valuationα.

Theorem 5.17(Expressiveness of ranked tree transducers). A partial function from BT(Σ) to W0(Γ)is STT-definable iff it is BRTT-definable.

Proof. From STT to BRTT ⇒. Using Theorem 5.7, let S = (Q,P,q0,X,F,η,δ,ρ) be a

binary bottom-up STT. We construct a BRTTS0 = (Q0,q0

0,X0,F0,η0,δ0,ρ0)equivalent to

S. We can assume w.l.o.g. that the set of variablesXis partitioned into two disjoint sets

Xl = {x1L, . . . ,xnL}andXr = {xR1, . . . ,xnR}such that, given a treet = ahtl,tri, 1) after processing the left childtl, all the variables in Xl depend on the run overtl, while all the variables in Xr are reset to their initial values, and 2) after processing the second

child, the values ofXronly depend ontr(do not use any variablexp ∈ Xp), and every variable x ∈ Xl is exactly assigned the corresponding value xp stored on the stack. In summary, every variable inXronly depends on the second child, and every variable in

XLonly depends on the first child. Such variables can only be combined at the return

aiat the end oft. An STT of this form can be obtained by delaying the variable update at the return at the endtrto the next step in whichaiis read.

Now that we are given a bottom-up STT, the construction ofS0 is similar to the one showed in Theorem 5.7. Each stateq∈ Q0 contains a function f : Q 7→ Q, that keeps track of the executions ofSfor every possible starting state. After processing a treet,

S0 is in state f, such that for everyq Q, f(q) = q0 iff whenSreads the treetstarting in state q, it will end up in stateq0. Similarly, the BRTT S0 uses multiple variables to keep track of all the possible states with which a symbol could have been processed. The BRTTS0 has set of variablesX0 ={xq|x X,q Q}. After processing a treet, for everyx ∈X, andq∈ Q, if, afterSprocesseststarting in stateq,xcontains the values, thenxqalso contains the values.

Next we describe how these components are updated. Let fl and fr be the states ofS0 after processing the childrentl andtrof a treeahtl,tri. We denote with f0the new state after readinga. For every stateq,∈ Q, and variablex ∈X, ifδc(q,ha) = (q1,p), fl(q1) =

q2, fr(q2) = q3, and δr(q3,p,ha) = q4, then f0(q) = q4, and xq is assigned the value ρ(q3,p,ha,x), in which every variable inXl andXris replaced with the corresponding variables inX0

l andXR0. For every state f, the output function ofF0 ofS0is then defined asF0(f) =F(f(q0)). The conflict relationη0ofS0has the following rules:

1. for everyx,y ∈X, andq6=q0 Q,η0(xq,yq0);

2. for everyq∈ Q, andx,y∈X, ifη(x,y), thenη0(xq,yq). The proof of consistency is the same as for Theorem 5.7.

From BRTT to STT ⇐. Given a BRTT S = (Q,q0,X,F,η,δ,ρ), we construct an STT

S0 = (Q0,P0,q0

0,X0,F0,η0,δ0,ρ0)equivalent toS. The STTS0 simulates the execution ofS

while reading the input nested word. The states and stack states ofS0 are used to keep track of whether the current child is a first or second child. The STTS0 has set of states

Q0 = Q×({l,r} ∪Q), initial stateq0

0 = (q0,l), and set of stack state P0 = Q× {l,r}.

Given a treeha tl,trai, the STTS0maintains the following invariant: • right before processing the first childtl,S0 is in state(q0,l);

• right after processing the second childtr,S0 is in state(q1,q2).

We now define the transition relation δ0 that preserves the invariant defined above.

Let’s assumeS0is in stateq= (q1,d), and it is processing the symbola.

a is a callhb: the STTS0 resets the control to the initial state and pushesq1on the stack:

δ0(q1,b) = (q00,q1).

a is a return bi: we first of all observe that, since the input is a binary tree, d cannot

have valuerwhen reading a return symbol. If the state popped from the stack is

p= (qp,dp)we have the following cases.

End of First Child: ifdp =lwe have two cases:

Leaf: ifd=l, andδ(q0,q0,b) =q2thenδ0(q,p,b) = (q2,r);

Not a Leaf: ifd=q2∈ Q, andδ(q1,q2,b) =q3, thenδ0(q,p,b) = (q3,r).

End of Second Child: ifdp =rwe have two cases:

Leaf: ifd=l, andδ(q0,q0,b) =q2, thenδ0(q,p,b) = (qp,q2);

Not a Leaf: ifd=q2∈ Q, andδ(q1,q2,b) =q3, thenδ0(q,p,b) = (qp,q3).

The STTS0 has set of variables X0 = X0

l ∪Xr0, whereXd0 = {xd | x ∈ X}. We use one set of variablesXl for the variable values after processing the left child, andXrfor the variable values after processing the right child. The variables inXlandXrare combined when processing the parent. The STTS0 maintains the following invariant: given a tree

ha tl,tr ai, and d ∈ {l,r}, after processing the child td, every variable xd ∈ Xd0 will contain the value ofxcomputed bySafter processing the treetd.

We can now describe the variable update functionρ0ofS0. Given a variablex ∈ X0, let the functionINI(x)be the function that returns the initial value of a variablex, that is

defined as: 1) ifxis a type-0 variable, then INI(x) = ε, and 2) ifx is a type-1 variable,

thenINI(x) =?. Let’s assumeS0is in stateq= (q1,d), it is processing the symbola, and

updating the variablexX0:

a is a callhb: every variable is copied on the stackρ0(q,b,x) =x;

a is a return bi: if the state popped from the stack isp= (qp,dp), we have the following

cases.

End of First Child: ifdp =lwe have two cases:

• ifx ∈XLwe have two more cases

Not a Leaf: ifd =q2∈ Q, thenρ0(q,p,b,x) =ρ(q1,q2,b,x).

• ifx ∈XR, thenρ0(q,p,b,x) =INI(x).

End of Second Child: ifdp =rwe have two cases

• ifx ∈XL, thenρ0(q,p,b,x) =xp; • ifx ∈XRwe have two more cases:

Leaf: ifd=l, thenρ0(q,p,b,x) =ρ(q0,q0,b,x);

Not a Leaf: ifd =q2∈ Q, thenρ0(q,p,b,x) =ρ(q1,q2,b,x).

The conflict relationη0 ofS0 is defined as: for everyx,y∈ X, andd∈ {L,R}, ifη(x,y),

then η0(xd,yd). The consistency of η is trivial. Finally, the output function F0 is de- fined as follows. For every state(q,d) ∈ Q0, ifd = r, F0(q,d) = F(q), otherwiseF0 is undefined.

In document Memòria del curs acadèmic 1996 1997 (página 39-46)

Documento similar