Języki, automaty i obliczenia/Ćwiczenia 12: Języki kontekstowe i automat liniowo ograniczony. Maszyna Turinga: Różnice pomiędzy wersjami

Z Studia Informatyczne
Przejdź do nawigacjiPrzejdź do wyszukiwania
m Zastępowanie tekstu - "\:" na "\ :"
Linia 5: Linia 5:
język palindromów, czyli:
język palindromów, czyli:
<center><math>\displaystyle  
<center><math>\displaystyle  
L=\left\{w \overleftarrow{w} \: : \: w\in \left\{0,1\right\}^*\right\}.
L=\left\{w \overleftarrow{w} \ : : \ : w\in \left\{0,1\right\}^*\right\}.
</math></center>
</math></center>


Linia 16: Linia 16:


<div class="mw-collapsible mw-made=collapsible mw-collapsed"><span class="mw-collapsible-toogle mw-collapsible-toogle-default style="font-variant:small-caps">Wskazówka </span><div class="mw-collapsible-content" style="display:none">   
<div class="mw-collapsible mw-made=collapsible mw-collapsed"><span class="mw-collapsible-toogle mw-collapsible-toogle-default style="font-variant:small-caps">Wskazówka </span><div class="mw-collapsible-content" style="display:none">   
Aby wykonać (1), rozpocznij od konfiguracji <math>\displaystyle \sharp \: s_0 1 \: 01101
Aby wykonać (1), rozpocznij od konfiguracji <math>\displaystyle \sharp \ : s_0 1 \ : 01101
\sharp</math>, a następnie wykonuj przejścia, zgodnie z diagramem przejść
\sharp</math>, a następnie wykonuj przejścia, zgodnie z diagramem przejść
maszyny <math>\displaystyle TM_2</math> z wykładu.
maszyny <math>\displaystyle TM_2</math> z wykładu.
Linia 26: Linia 26:
<center><math>\displaystyle  
<center><math>\displaystyle  
\begin{array} {c c c c c c c c}
\begin{array} {c c c c c c c c}
&\sharp \:s_0 1\: 01101 \sharp & \mapsto & \sharp  \sharp \: r_1 0\:
&\sharp \ :s_0 1\ : 01101 \sharp & \mapsto & \sharp  \sharp \ : r_1 0\ :
1101 \sharp &\mapsto & \sharp  \sharp 0 \: r_1' 1\: 101 \sharp
1101 \sharp &\mapsto & \sharp  \sharp 0 \ : r_1' 1\ : 101 \sharp
&\mapsto & \sharp  \sharp 01 \: r_1' 1\: 01 \sharp
&\mapsto & \sharp  \sharp 01 \ : r_1' 1\ : 01 \sharp
\\
\\
\mapsto & \sharp  \sharp 011 \: r_1' 0\: 1 \sharp & \mapsto & \sharp
\mapsto & \sharp  \sharp 011 \ : r_1' 0\ : 1 \sharp & \mapsto & \sharp
\sharp 0110 \: r_1' 1 \: \sharp &\mapsto & \sharp \sharp 0110  1 \:
\sharp 0110 \ : r_1' 1 \ : \sharp &\mapsto & \sharp \sharp 0110  1 \ :
r_1' \sharp &\mapsto & \sharp 0110
r_1' \sharp &\mapsto & \sharp 0110
\: q_1 1\: \sharp
\ : q_1 1\ : \sharp
\\
\\
\mapsto & \sharp \sharp 011 \: l 0\: \sharp \sharp & \mapsto &
\mapsto & \sharp \sharp 011 \ : l 0\ : \sharp \sharp & \mapsto &
\sharp \sharp 01 \: l 1\: 0 \sharp \sharp &\mapsto & \sharp \sharp 0
\sharp \sharp 01 \ : l 1\ : 0 \sharp \sharp &\mapsto & \sharp \sharp 0
\: l 1\: 10 \sharp \sharp &\mapsto & \sharp \sharp \: l 0\: 110
\ : l 1\ : 10 \sharp \sharp &\mapsto & \sharp \sharp \ : l 0\ : 110
\sharp \sharp
\sharp \sharp
\\
\\
\mapsto & \sharp  \: l \sharp\: 0110 \sharp \sharp & \mapsto &
\mapsto & \sharp  \ : l \sharp\ : 0110 \sharp \sharp & \mapsto &
\sharp\sharp \: s_0 0\: 110 \sharp\sharp  &\mapsto &
\sharp\sharp \ : s_0 0\ : 110 \sharp\sharp  &\mapsto &
\sharp\sharp\sharp \: r_0 1\: 10 \sharp\sharp &\mapsto &
\sharp\sharp\sharp \ : r_0 1\ : 10 \sharp\sharp &\mapsto &
\sharp\sharp\sharp 1 \: r_0' 1\: 0 \sharp\sharp
\sharp\sharp\sharp 1 \ : r_0' 1\ : 0 \sharp\sharp
\\
\\
\mapsto & \sharp\sharp\sharp 11 \: r_0' 0\:  \sharp\sharp & \mapsto
\mapsto & \sharp\sharp\sharp 11 \ : r_0' 0\ :  \sharp\sharp & \mapsto
& \sharp\sharp\sharp 110 \: r_0' \sharp\: \sharp &\mapsto &
& \sharp\sharp\sharp 110 \ : r_0' \sharp\ : \sharp &\mapsto &
\sharp\sharp\sharp 11 \: q_0 0\: \sharp\sharp &\mapsto &
\sharp\sharp\sharp 11 \ : q_0 0\ : \sharp\sharp &\mapsto &
\sharp\sharp\sharp 1 \: l 1\: \sharp\sharp\sharp
\sharp\sharp\sharp 1 \ : l 1\ : \sharp\sharp\sharp
\\
\\
\mapsto & \sharp\sharp\sharp \: l 1\: 1\sharp\sharp\sharp & \mapsto
\mapsto & \sharp\sharp\sharp \ : l 1\ : 1\sharp\sharp\sharp & \mapsto
& \sharp\sharp \: l \sharp \: 1 1\sharp\sharp\sharp &\mapsto &
& \sharp\sharp \ : l \sharp \ : 1 1\sharp\sharp\sharp &\mapsto &
\sharp\sharp\sharp \: s_0 1\: 1\sharp\sharp\sharp &\mapsto &
\sharp\sharp\sharp \ : s_0 1\ : 1\sharp\sharp\sharp &\mapsto &
\sharp\sharp\sharp\sharp \: r_1 1\: \sharp\sharp\sharp
\sharp\sharp\sharp\sharp \ : r_1 1\ : \sharp\sharp\sharp
\\
\\
\mapsto & \sharp\sharp\sharp\sharp 1 \: r_1' \sharp\: \sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp 1 \ : r_1' \sharp\ : \sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp  \: q_1 1\: \sharp\sharp\sharp
\mapsto & \sharp\sharp\sharp\sharp  \ : q_1 1\ : \sharp\sharp\sharp
&\mapsto & \sharp\sharp\sharp \: l \sharp \:
&\mapsto & \sharp\sharp\sharp \ : l \sharp \ :
\sharp\sharp\sharp\sharp &\mapsto & \sharp\sharp\sharp\sharp  \: s_0
\sharp\sharp\sharp\sharp &\mapsto & \sharp\sharp\sharp\sharp  \ : s_0
\sharp\: \sharp\sharp\sharp
\sharp\ : \sharp\sharp\sharp
\\
\\
\mapsto & \sharp\sharp\sharp\sharp \: s_A \sharp\:
\mapsto & \sharp\sharp\sharp\sharp \ : s_A \sharp\ :
\sharp\sharp\sharp & \circlearrowleft&
\sharp\sharp\sharp & \circlearrowleft&
\end{array}  
\end{array}  
</math></center>
</math></center>


Wykazaliśmy, że <math>\displaystyle \sharp \:s_0 1\: 01101 \sharp \mapsto^*
Wykazaliśmy, że <math>\displaystyle \sharp \ :s_0 1\ : 01101 \sharp \mapsto^*
\sharp\sharp\sharp\sharp \: s_A \sharp\: \sharp\sharp\sharp</math>. Stan
\sharp\sharp\sharp\sharp \ : s_A \sharp\ : \sharp\sharp\sharp</math>. Stan
<math>\displaystyle s_A\in S_F</math>, zatem wprost z definicji <math>\displaystyle 101101\in L(TM_2)</math>.
<math>\displaystyle s_A\in S_F</math>, zatem wprost z definicji <math>\displaystyle 101101\in L(TM_2)</math>.


Linia 73: Linia 73:
<center><math>\displaystyle  
<center><math>\displaystyle  
\begin{array} {c c c c c c c c c}
\begin{array} {c c c c c c c c c}
&\sharp \:s_0 1\: 010101 \sharp & \mapsto & \sharp  \sharp \: r_1
&\sharp \ :s_0 1\ : 010101 \sharp & \mapsto & \sharp  \sharp \ : r_1
0\: 10101 \sharp &\mapsto & \sharp  \sharp 0 \: r_1' 1\: 0101 \sharp
0\ : 10101 \sharp &\mapsto & \sharp  \sharp 0 \ : r_1' 1\ : 0101 \sharp
&\mapsto & \sharp  \sharp 01 \: r_1' 0\: 101 \sharp
&\mapsto & \sharp  \sharp 01 \ : r_1' 0\ : 101 \sharp
&\\
&\\
\mapsto & \sharp  \sharp 010 \: r_1' 1\: 01 \sharp & \mapsto &
\mapsto & \sharp  \sharp 010 \ : r_1' 1\ : 01 \sharp & \mapsto &
\sharp \sharp 0101 \: r_1' 0\: 1 \sharp & \mapsto & \sharp \sharp
\sharp \sharp 0101 \ : r_1' 0\ : 1 \sharp & \mapsto & \sharp \sharp
01010 \: r_1' 1 \: \sharp &\mapsto & \sharp \sharp 01010  1 \: r_1'
01010 \ : r_1' 1 \ : \sharp &\mapsto & \sharp \sharp 01010  1 \ : r_1'
\sharp
\sharp
&\\
&\\
\mapsto & \sharp 01010 \: q_1 1\: \sharp& \mapsto & \sharp \sharp
\mapsto & \sharp 01010 \ : q_1 1\ : \sharp& \mapsto & \sharp \sharp
0101 \: l 0\: \sharp \sharp & \mapsto & \sharp \sharp 010 \: l 1\: 0
0101 \ : l 0\ : \sharp \sharp & \mapsto & \sharp \sharp 010 \ : l 1\ : 0
\sharp \sharp &\mapsto & \sharp \sharp 0 1\: l 0\: 10 \sharp
\sharp \sharp &\mapsto & \sharp \sharp 0 1\ : l 0\ : 10 \sharp
\sharp
\sharp
&\\
&\\
\mapsto & \sharp \sharp 0 \: l 1\: 010 \sharp \sharp& \mapsto &
\mapsto & \sharp \sharp 0 \ : l 1\ : 010 \sharp \sharp& \mapsto &
\sharp \sharp \: l 0\: 1010 \sharp \sharp& \mapsto & \sharp \: l
\sharp \sharp \ : l 0\ : 1010 \sharp \sharp& \mapsto & \sharp \ : l
\sharp\: 01010 \sharp \sharp & \mapsto & \sharp\sharp \: s_0 0\: 1010
\sharp\ : 01010 \sharp \sharp & \mapsto & \sharp\sharp \ : s_0 0\ : 1010
\sharp\sharp
\sharp\sharp
&\\
&\\
\mapsto & \sharp\sharp\sharp \: r_0 1\: 010 \sharp\sharp & \mapsto &
\mapsto & \sharp\sharp\sharp \ : r_0 1\ : 010 \sharp\sharp & \mapsto &
\sharp\sharp\sharp 1 \: r_0' 0\: 10 \sharp\sharp & \mapsto &
\sharp\sharp\sharp 1 \ : r_0' 0\ : 10 \sharp\sharp & \mapsto &
\sharp\sharp\sharp 10 \: r_0' 1\: 0 \sharp\sharp & \mapsto &
\sharp\sharp\sharp 10 \ : r_0' 1\ : 0 \sharp\sharp & \mapsto &
\sharp\sharp\sharp 101 \: r_0' 0\:  \sharp\sharp
\sharp\sharp\sharp 101 \ : r_0' 0\ :  \sharp\sharp
&\\
&\\
\mapsto &
\mapsto &
\sharp\sharp\sharp 1010 \: r_0' \sharp\: \sharp &
\sharp\sharp\sharp 1010 \ : r_0' \sharp\ : \sharp &
\mapsto & \sharp\sharp\sharp 101 \: q_0 0\: \sharp\sharp & \mapsto &
\mapsto & \sharp\sharp\sharp 101 \ : q_0 0\ : \sharp\sharp & \mapsto &
\sharp\sharp\sharp 10 \: l 1\: \sharp\sharp\sharp & \mapsto &
\sharp\sharp\sharp 10 \ : l 1\ : \sharp\sharp\sharp & \mapsto &
\sharp\sharp\sharp \: 1 l 0\: 1\sharp\sharp\sharp
\sharp\sharp\sharp \ : 1 l 0\ : 1\sharp\sharp\sharp
&\\
&\\
\mapsto &
\mapsto &
\sharp\sharp\sharp \: l 1\: 01\sharp\sharp\sharp &
\sharp\sharp\sharp \ : l 1\ : 01\sharp\sharp\sharp &
\mapsto & \sharp\sharp \: l \sharp \: 101\sharp\sharp\sharp &
\mapsto & \sharp\sharp \ : l \sharp \ : 101\sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp \: s_0 1\: 01\sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp \ : s_0 1\ : 01\sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp \: r_1 0\: 1 \sharp\sharp\sharp
\mapsto & \sharp\sharp\sharp\sharp \ : r_1 0\ : 1 \sharp\sharp\sharp
&\\
&\\
\mapsto & \sharp\sharp\sharp\sharp 0 \: r_1 1\: \sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp 0 \ : r_1 1\ : \sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp 01 \: r_1' \sharp\: \sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp 01 \ : r_1' \sharp\ : \sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp  0\: q_1 1\: \sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp  0\ : q_1 1\ : \sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp  \: l 0\: \sharp \sharp\sharp\sharp
\mapsto & \sharp\sharp\sharp\sharp  \ : l 0\ : \sharp \sharp\sharp\sharp
&\\
&\\
\mapsto & \sharp\sharp\sharp \: l \sharp \: 0 \sharp\sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp \ : l \sharp \ : 0 \sharp\sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp  \: s_0 0 \: \sharp
\mapsto & \sharp\sharp\sharp\sharp  \ : s_0 0 \ : \sharp
\sharp\sharp\sharp &
\sharp\sharp\sharp &
\mapsto & \sharp\sharp\sharp\sharp \sharp \: r_0 \sharp \: \sharp\sharp\sharp & \mapsto&
\mapsto & \sharp\sharp\sharp\sharp \sharp \ : r_0 \sharp \ : \sharp\sharp\sharp & \mapsto&
\sharp\sharp\sharp\sharp \sharp \: s_R \sharp \: \sharp\sharp\sharp& \circlearrowleft\\
\sharp\sharp\sharp\sharp \sharp \ : s_R \sharp \ : \sharp\sharp\sharp& \circlearrowleft\\
\end{array}  
\end{array}  
</math></center>
</math></center>


Na ostatniej otrzymanej konfiguracji maszyna się zatrzymuje (następne konfiguracje są identyczne).
Na ostatniej otrzymanej konfiguracji maszyna się zatrzymuje (następne konfiguracje są identyczne).
Zatem konfiguracja początkowa <math>\displaystyle \sharp \:s_0 1\: 010101 \sharp</math> prowadzić może poprzez relację <math>\displaystyle \mapsto^*</math> tylko do
Zatem konfiguracja początkowa <math>\displaystyle \sharp \ :s_0 1\ : 010101 \sharp</math> prowadzić może poprzez relację <math>\displaystyle \mapsto^*</math> tylko do
konfiguracji (obliczeń wykonanych) wypisanych powyżej. Żadna z otrzymanych konfiguracji pośrednich
konfiguracji (obliczeń wykonanych) wypisanych powyżej. Żadna z otrzymanych konfiguracji pośrednich
nie zawiera stanu ze zbioru <math>\displaystyle S_F</math>. To z kolei oznacza, że <math>\displaystyle 1010101\not\in L(TM_2)</math>.
nie zawiera stanu ze zbioru <math>\displaystyle S_F</math>. To z kolei oznacza, że <math>\displaystyle 1010101\not\in L(TM_2)</math>.
Linia 131: Linia 131:
Niech będzie dany alfabet <math>\displaystyle \Sigma_I =\left\{0,1,\clubsuit\right\}</math>. Zaprojektuj maszynę Turinga akceptująca język postaci:
Niech będzie dany alfabet <math>\displaystyle \Sigma_I =\left\{0,1,\clubsuit\right\}</math>. Zaprojektuj maszynę Turinga akceptująca język postaci:
<center><math>\displaystyle  
<center><math>\displaystyle  
L=\left\{u\clubsuit w\: : \: u,w\in \left\{0,1\right\}^*\right\}.
L=\left\{u\clubsuit w\ : : \ : u,w\in \left\{0,1\right\}^*\right\}.
</math></center>
</math></center>


Linia 222: Linia 222:
W trakcie wykładu rozważaliśmy język
W trakcie wykładu rozważaliśmy język
<center><math>\displaystyle  
<center><math>\displaystyle  
L=\left\{3^k\: : \: k=i\cdot j  </math>  dla pewnych  <math>\displaystyle  i,j> 1\right\},
L=\left\{3^k\ : : \ : k=i\cdot j  </math>  dla pewnych  <math>\displaystyle  i,j> 1\right\},
</math></center>
</math></center>


Linia 310: Linia 310:
Skonstruuj maszynę Turinga <math>\displaystyle \mathcal{MT}</math> akceptującą język:
Skonstruuj maszynę Turinga <math>\displaystyle \mathcal{MT}</math> akceptującą język:
<center><math>\displaystyle  
<center><math>\displaystyle  
L_1=\left\{www\: : \: w\in \left\{\circ,\bullet,\star\right\}^*\right\}.
L_1=\left\{www\ : : \ : w\in \left\{\circ,\bullet,\star\right\}^*\right\}.
</math></center>
</math></center>


Linia 318: Linia 318:
Uzasadnij, że język
Uzasadnij, że język
<center><math>\displaystyle  
<center><math>\displaystyle  
L_2=\left\{w_1 w_1 w_2 w_2 \dots w_n w_n \: : \: w_i \in \left\{\circ,\bullet\right\}^+, n>0 \right\}
L_2=\left\{w_1 w_1 w_2 w_2 \dots w_n w_n \ : : \ : w_i \in \left\{\circ,\bullet\right\}^+, n>0 \right\}
</math></center>
</math></center>



Wersja z 15:47, 24 wrz 2020

Ćwiczenia 12

Ćwiczenie 1

Rozważmy maszynę Turinga TM2 z wykładu (Przykład 1.2) akceptującą język palindromów, czyli:

L={ww :: :w{0,1}*}.

Sprawdź, że:

  1. 101101L(TM2)

oraz że

  1. 1010101∉L(TM2).
Wskazówka
Rozwiązanie

Ćwiczenie 2

Niech będzie dany alfabet ΣI={0,1,}. Zaprojektuj maszynę Turinga akceptująca język postaci:

L={uw :: :u,w{0,1}*}.

Zaprojektuj maszynę Turinga =(ΣT,S,f,s0,SF), która akceptuje język L. Następnie:

  1. Wypisz elementy składowe maszyny , tzn. zbiory ΣT,S,SF oraz funkcję przejścia f (zapewnij, aby s0S).
  2. Wykonaj symulację maszyny na słowie w1=110011,
  3. na słowie w2=01,
  4. oraz na słowie w3=0000110.
Wskazówka
Rozwiązanie

Ćwiczenie 3

W trakcie wykładu rozważaliśmy język

Parser nie mógł rozpoznać (błąd składni): {\displaystyle \displaystyle L=\left\{3^k\ : : \ : k=i\cdot j } dla pewnych Parser nie mógł rozpoznać (błąd składni): {\displaystyle \displaystyle i,j> 1\right\}, }

wykazując, że L NP .

Uzasadnij, że także
L P .
Wskazówka
Rozwiązanie

Ćwiczenie 4

Uzasadnij, że funkcja s(n)=3n jest konstruowalna pamięciowo.

Wskazówka
Rozwiązanie

Ćwiczenie 5

Uzasadnij, że funkcja s(n)=3n jest konstruowalna pamięciowo.

Wskazówka
Rozwiązanie
Zadania domowe

Ćwiczenie 6

Skonstruuj maszynę Turinga 𝒯 akceptującą język:

L1={www :: :w{,,}*}.

Ćwiczenie 7

Uzasadnij, że język

L2={w1w1w2w2wnwn :: :wi{,}+,n>0}

jest rozpoznawany przez pewną niedeterministyczna maszynę Turinga 𝒩𝒯.

Podpowiedź: wykorzystaj konstrukcję z wyrocznią. Dla słowa wejściowego w przeprowadź weryfikację w trzech etapach: konstrukcja słów w1,,wn, gdzie n<|w| (wyrocznia), sklejanie, weryfikacja, czy w=w1w1w2w2wnwn.