Sie können versuchen, Pushdown-Automaten zu verwenden. Mit einem Pushdown-Automaten für die Originalsprache konstruieren wir einen für die zyklische Verschiebung. Der neue Automat arbeitet in zwei Stufen, die dem y- und dem x- Teil des Wortes y x entsprechen (wobei x y in der Originalsprache ist). In der ersten Stufe kann der Automat, wann immer er ein Nicht-Terminal A platzen lassen möchte , stattdessen ein Nicht-Terminal A ' drücken ; Die Idee ist, dass der Stapel am Ende der ersten Stufe in umgekehrter Reihenfolge die Symbole enthält, die nach dem Lesen von x im Stapel gefunden werdenyxyxxyAA′xdurch den ursprünglichen Automaten. In der zweiten Stufe (der Schalter ist nicht deterministisch) dürfen wir , anstatt ein Nicht-Terminal A zu drücken , ein Nicht-Terminal A 'platzen lassen . Wenn der ursprüngliche Automat tatsächlich den Stapel beim Lesen von x erzeugen kann , kann der neue den gesamten Stapel exakt platzen lassen.AA′x
Bearbeiten: Hier sind einige weitere Details. Angenommen, wir erhalten einen PDA mit dem Alphabet Σ , einer Menge von Zuständen Q , einer Menge von Akzeptanzzuständen F , Nichtterminals Γ , einem Anfangszustand q 0 und einer Menge zulässiger Übergänge. Jeder zulässige Übergang hat die Form ( q , a , A , q ' , α ) , was bedeutet, dass im Zustand q beim Lesen von a ∈ A (oder a = ϵ , in diesem Fall handelt es sich um einen freien Übergang) oben liegt -of-Stack ist A ∈ΣQFΓq0(q,a,A,q′,α)qa∈Aa=ϵΓ (oder A = ε , was bedeutet Stapel leer ist), dannder PDA kann (es ist ein nicht-deterministisches Modell) zu bewegen Zustand q ' , Ersetzen A mit & agr; ∈ Γ * .A∈ΓA=ϵq′Aα∈Γ∗
Der neue PDA hat eine neue nicht-terminale A ' für jedes A ∈ & Ggr; . Für jeweils zwei Zustände q , q ' ∈ Q und A ∈ & Ggr; ∪ { ε } , gibt es zwei Zustände ( q , q ' , 1 ) , ( q , q ' , 2 , A ) . Die Startzustände (der tatsächliche Startzustand wird über ϵ- Übergänge nicht deterministisch unter ihnen gewählt ) sind (A′A & egr ; & Ggr;q, q'∈ Q.A & egr ; & Ggr; ∪ { ε }( q, q', 1 ) , ( q, q', 2 , A )ϵq , q , 1 ) . Für jeden Übergang ( q , a , A , q ' , α ) gibt es entsprechende Übergänge ( ( q , q " , 1 ) , a , A , ( q ' , q " , 1 ) , α ) und ( ( q , q " , 2 , B.( q, q, 1 )( q, a , A , q', α )((q,q′′,1),a,A,(q′,q′′,1),α)) , a , A , ( q ' , q ' ' , 2 , B ) , α ) . Es gibt auch andere Übergänge.((q,q′′,2,B),a,A,(q′,q′′,2,B),α)
Für jeden Übergang ( q , a , A , q ' , α ) gibt es Übergänge ( ( q , q " , 1 ) , a , B ' , ( q ' , q " , 1 ) , B ' A ' α ). , wobei B ∈ & Ggr; ∪ { ε } , und ε ' =(q,a,A,q′,α)((q,q′′,1),a,B′,(q′,q′′,1),B′A′α)B∈Γ∪{ϵ}ϵ . Für jeden Endzustand q ∈ F gibt es Übergänge ( ( q , q " , 1 ) , ε , A , ( q 0 , q " , 2 , ε ) , A ) , wobei A ∈ & Ggr; ∪ { ε } .ϵ′=ϵq∈F((q,q′′,1),ϵ,A,(q0,q′′,2,ϵ),A)A∈Γ∪{ϵ}
Für jeden Übergang ( q , a , ϵ , q ' , α ) gibt es Übergänge ( ( q , q " , 2 , A ) , a , B ' , ( q ' , q " , 2 , A ) , B ' α ) , wobei A ∈ & Ggr; ∪ { ε } . Für jeden Übergang(q,a,ϵ,q′,α)((q,q′′,2,A),a,B′,(q′,q′′,2,A),B′α)A∈Γ∪{ϵ}(q,a,ϵ,q′,A)(q,a,ϵ,q′,A), there are transitions ((q,q″,2,B),a,A′,(q′,q″,2,A),ϵ)((q,q′′,2,B),a,A′,(q′,q′′,2,A),ϵ), where B∈Γ∪{ϵ}B∈Γ∪{ϵ}. For every transition (q,a,A,q′,B)(q,a,A,q′,B), there are "generalized transitions" ((q,q″,2,C),a,B′A,(q,q″,2,C),ϵ)((q,q′′,2,C),a,B′A,(q,q′′,2,C),ϵ); these are implemented as a sequence of two transitions through an intermediate new state. Transitions (q,a,ϵ,q′,α)(q,a,ϵ,q′,α) with |α|≥2|α|≥2 are handled similarly. For every transition (q,a,A,q′,A)(q,a,A,q′,A), there are transitions ((q,q″,2,A),a,B,(q′,q″,2,A),B)((q,q′′,2,A),a,B,(q′,q′′,2,A),B), where B∈Γ′∪{ϵ}B∈Γ′∪{ϵ}. Transitions (q,a,A,q′,Aα)(q,a,A,q′,Aα) are handled similarly. Finally, there is a sole final state ff, and transitions ((q,q,2,A),ϵ,ϵ,f,ϵ)((q,q,2,A),ϵ,ϵ,f,ϵ).
(There might be a few transitions that I missed, and some of the details that I'm omitting are somewhat messy.)
Recall we're trying to accept a word yxyx, where xyxy is accepted by the original PDA. A state (q,q′,1)(q,q′,1) means that we're at stage 1, at state qq, and the original PDA is at state q′q′ after reading xx. A state (q,q′,2,A)(q,q′,2,A) is similar, where AA corresponds to the last A′A′ that was popped. At stage 1, we are allowed to push A′A′ instead of popping AA. We do that for each non-terminal that is produced while processing xx, but only popped while processing yy. At stage 2, we are allowed to pop A′A′ instead of pushing AA. If we do this, then we have to remember that the top-of-stock is really AA; this only applies when there are no "temporary" things on the stack, which in the simulated PDA is the same as the top-of-stack being ϵϵ or of the form B′B′.
Here is a simple example. Consider an automaton for xnynxnyn that pushes AA for each xx, and pops AA for each yy. The new automaton accepts words of two forms: ykxnyn−kykxnyn−k and xkynxn−kxkynxn−k. For words of the first form, stage 1 consists of pushing kk times A′A′, stage 2 consists of popping kk times A′A′, pushing n−kn−k times AA, and popping n−kn−k times AA. For words of the second form, we first push kk times AA, then pop kk times AA, push n−kn−k times A′A′, transition to stage 2, and pop n−kn−k times A′A′.
Here is a more complicated example, for the language of balanced parentheses of various types ("()","[]","<>") such that the immediate descendants of each type of parentheses must belong to a different type. For example, "([]<>)" is OK but "()" is wrong. For each "(", we push AA if the top-of-stack isn't AA, for each ")", we pop AA. Similarly BB,CC are associated with "[]" and "<>". Here is how we accept the word ">)([()]<". We consume ">)", pushing C′A′C′A′, and transition to stage 2. We consume "(", popping A′A′ and remembering the top-of-stack AA. We consume "[()]" , pushing and popping BABA; when pushing BB, we are aware that the "real" top-of-stack is AA, and so square brackets are allowed (we wouldn't be fooled by ">)(()<"); when pushing AA, since the top-of-stack is BB (which is not ϵϵ or of the form X′X′), then we know that BB is also the "real" top-of-stack, and so round parentheses are allowed (even though the shadow top-of-stack is AA). Finally, we consume "<" and pop C′C′.
Consider Greibach normal form. To construct a shifted language you only need to change productions S→αA1…AnS→αA1…An to S→A1…AnαS→A1…Anα and add a new non-terminal S′ that behaves like S used to, in case some some production referenced S.
quelle
It turned out to be a good idea to check the old Hopcroft and Ullman classic Introduction to Automata Theory (1979). Closure under cycle is Exercise 6.4c and is marked S**. The double stars mean it is one of the most difficult problems (in the book). Fortunately the S indicates it is one of the selected problems with a solution.
The solution is as follows. Take a CFG in Chomsky normal form. Consider any derivation tree and basically turn it upside down. Consider a path S=X1,X2,…,Xn in the original tree. To the left the tree has contributions x1,x2,…,xn to the right y1,y2,…,yn, meaning the string derived equals x1x2…xnyn…y2y1. (Actually as the grammar is CNF when the path continues left, the contribution will be to the right and the corresponding xi is empty, etc.)
The tree upside down has a path S′,ˆXn,…ˆX2,ˆX1 with contributions yn,…,y2y1 to the left and xn,…,x2x1 to the right, so the result is a derivation for yn…y2y1x1x2…xn. As required.
Full details of the construction are given in the book.
Note how this reminds of the (accepted) solution by Yuval. The nonterminals that are pushed instead of popped are in the opposite order on the stack. Quite similar to upside down in the tree.
quelle