Języki, automaty i obliczenia/Ćwiczenia 12: Języki kontekstowe i automat liniowo ograniczony. Maszyna Turinga: Różnice pomiędzy wersjami
Nie podano opisu zmian |
m Zastępowanie tekstu – „,↵</math>” na „</math>,” |
||
(Nie pokazano 19 wersji utworzonych przez 5 użytkowników) | |||
Linia 1: | Linia 1: | ||
==Ćwiczenia 12== | |||
= | {{cwiczenie|1|| | ||
Rozważmy maszynę Turinga <math>TM_2</math> z wykładu (Przykład 1.2) akceptującą | |||
język palindromów, czyli: | |||
<center><math> | |||
L=\left\{w \overleftarrow{w} \ : : \ : w\in \left\{0,1\right\}^*\right\}</math></center> | |||
Sprawdź, że: | |||
# <math>101101\in L(TM_2)</math> | |||
oraz że | |||
L | # <math>1010101\not\in L(TM_2)</math>. | ||
}} | }} | ||
<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>\sharp \ : s_0 1 \ : 01101 | |||
<math> | \sharp</math>, a następnie wykonuj przejścia, zgodnie z diagramem przejść | ||
maszyny <math>TM_2</math> z wykładu. | |||
</div></div> | </div></div> | ||
<div class="mw-collapsible mw-made=collapsible mw-collapsed"><span class="mw-collapsible-toogle mw-collapsible-toogle-default style="font-variant:small-caps">Rozwiązanie </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">Rozwiązanie </span><div class="mw-collapsible-content" style="display:none"> | ||
'''(Ad. 1)''' Wykonujemy symulację maszyny <math>TM_2</math> na pierwszym ze | |||
słów: | |||
<center><math> | |||
\begin{array} {c c c c c c c c} | |||
&\sharp \ :s_0 1\ : 01101 \sharp & \mapsto & \sharp \sharp \ : r_1 0\ : | |||
1101 \sharp &\mapsto & \sharp \sharp 0 \ : r_1' 1\ : 101 \sharp | |||
&\mapsto & \sharp \sharp 01 \ : r_1' 1\ : 01 \sharp | |||
\\ | |||
\mapsto & \sharp \sharp 011 \ : r_1' 0\ : 1 \sharp & \mapsto & \sharp | |||
\sharp 0110 \ : r_1' 1 \ : \sharp &\mapsto & \sharp \sharp 0110 1 \ : | |||
r_1' \sharp &\mapsto & \sharp 0110 | |||
\ : q_1 1\ : \sharp | |||
\\ | |||
\mapsto & \sharp \sharp 011 \ : l 0\ : \sharp \sharp & \mapsto & | |||
\sharp \sharp 01 \ : l 1\ : 0 \sharp \sharp &\mapsto & \sharp \sharp 0 | |||
\ : l 1\ : 10 \sharp \sharp &\mapsto & \sharp \sharp \ : l 0\ : 110 | |||
\sharp \sharp | |||
\\ | |||
\mapsto & \sharp \ : l \sharp\ : 0110 \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 1 \ : r_0' 1\ : 0 \sharp\sharp | |||
\\ | |||
\mapsto & \sharp\sharp\sharp 11 \ : r_0' 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 1 \ : l 1\ : \sharp\sharp\sharp | |||
\\ | |||
\mapsto & \sharp\sharp\sharp \ : l 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\sharp \ : r_1 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 \ : l \sharp \ : | |||
\sharp\sharp\sharp\sharp &\mapsto & \sharp\sharp\sharp\sharp \ : s_0 | |||
\sharp\ : \sharp\sharp\sharp | |||
\\ | |||
\mapsto & \sharp\sharp\sharp\sharp \ : s_A \sharp\ : | |||
\sharp\sharp\sharp & \circlearrowleft& | |||
\end{array} | |||
</math></center> | |||
Wykazaliśmy, że <math>\sharp \ :s_0 1\ : 01101 \sharp \mapsto^* | |||
\sharp\sharp\sharp\sharp \ : s_A \sharp\ : \sharp\sharp\sharp</math>. Stan | |||
<math>s_A\in S_F</math>, zatem wprost z definicji <math>101101\in L(TM_2)</math>. | |||
'''(Ad. 2)''' Wykonujemy identyczną symulację na drugim ze słów: | |||
<center><math> | |||
\begin{array} {c c c c c c c c c} | |||
&\sharp \ :s_0 1\ : 010101 \sharp & \mapsto & \sharp \sharp \ : r_1 | |||
0\ : 10101 \sharp &\mapsto & \sharp \sharp 0 \ : r_1' 1\ : 0101 \sharp | |||
&\mapsto & \sharp \sharp 01 \ : r_1' 0\ : 101 \sharp | |||
&\\ | |||
\mapsto & \sharp \sharp 010 \ : r_1' 1\ : 01 \sharp & \mapsto & | |||
\sharp \sharp 0101 \ : r_1' 0\ : 1 \sharp & \mapsto & \sharp \sharp | |||
01010 \ : r_1' 1 \ : \sharp &\mapsto & \sharp \sharp 01010 1 \ : r_1' | |||
{ | \sharp | ||
&\\ | |||
\mapsto & \sharp 01010 \ : q_1 1\ : \sharp& \mapsto & \sharp \sharp | |||
0101 \ : l 0\ : \sharp \sharp & \mapsto & \sharp \sharp 010 \ : l 1\ : 0 | |||
\sharp \sharp &\mapsto & \sharp \sharp 0 1\ : l 0\ : 10 \sharp | |||
\sharp | |||
&\\ | |||
\mapsto & \sharp \sharp 0 \ : l 1\ : 010 \sharp \sharp& \mapsto & | |||
\sharp \sharp \ : l 0\ : 1010 \sharp \sharp& \mapsto & \sharp \ : l | |||
\sharp\ : 01010 \sharp \sharp & \mapsto & \sharp\sharp \ : s_0 0\ : 1010 | |||
\sharp\sharp | |||
&\\ | |||
\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 10 \ : r_0' 1\ : 0 \sharp\sharp & \mapsto & | |||
\sharp\sharp\sharp 101 \ : r_0' 0\ : \sharp\sharp | |||
&\\ | |||
\mapsto & | |||
\sharp\sharp\sharp 1010 \ : r_0' \sharp\ : \sharp & | |||
\mapsto & \sharp\sharp\sharp 101 \ : q_0 0\ : \sharp\sharp & \mapsto & | |||
\sharp\sharp\sharp 10 \ : l 1\ : \sharp\sharp\sharp & \mapsto & | |||
\sharp\sharp\sharp \ : 1 l 0\ : 1\sharp\sharp\sharp | |||
&\\ | |||
\mapsto & | |||
\sharp\sharp\sharp \ : l 1\ : 01\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\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 01 \ : r_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 \ : l \sharp \ : 0 \sharp\sharp\sharp\sharp & | |||
\mapsto & \sharp\sharp\sharp\sharp \ : s_0 0 \ : \sharp | |||
\sharp\sharp\sharp & | |||
\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\\ | |||
\end{array} | |||
</math></center> | |||
< | Na ostatniej otrzymanej konfiguracji maszyna się zatrzymuje (następne konfiguracje są identyczne). | ||
Zatem konfiguracja początkowa <math>\sharp \ :s_0 1\ : 010101 \sharp</math> prowadzić może poprzez relację <math>\mapsto^*</math> tylko do | |||
konfiguracji (obliczeń wykonanych) wypisanych powyżej. Żadna z otrzymanych konfiguracji pośrednich | |||
nie zawiera stanu ze zbioru <math>S_F</math>. To z kolei oznacza, że <math>1010101\not\in L(TM_2)</math>. | |||
</div></div> | </div></div> | ||
{{cwiczenie|2|| | |||
Niech będzie dany alfabet <math>\Sigma_I =\left\{0,1,\clubsuit\right\}</math>. Zaprojektuj maszynę Turinga akceptująca język postaci: | |||
<center><math> | |||
L=\left\{u\clubsuit w\ : : \ : u,w\in \left\{0,1\right\}^*\right\}</math></center> | |||
Zaprojektuj maszynę Turinga <math>\mathcal{M}=(\Sigma _{T},S,f,s_{0},S_{F})</math>, która akceptuje język <math>L</math>. Następnie: | |||
</ | # Wypisz elementy składowe maszyny <math>\mathcal{M}</math>, tzn. zbiory <math>\Sigma_T,S,S_{F}</math> oraz funkcję przejścia <math>f</math> (zapewnij, aby <math>s_0\in S</math>). | ||
# Wykonaj symulację maszyny <math>\mathcal{M}</math> na słowie <math>w_1=1100\clubsuit 11</math>, | |||
# na słowie <math>w_2=\clubsuit 01 \clubsuit</math>, | |||
# oraz na słowie <math>w_3=0000110</math>. | |||
}} | }} | ||
<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"> | ||
Projektowana maszyna może działać według schematu: | |||
# Przejdź słowo wejściowe od lewego do prawego ogranicznika. | |||
# Jeśli napotkasz symbol <math>\clubsuit</math>, oznacz to w stanach maszyny. | |||
# Jeśli napotkasz symbol <math>\clubsuit</math> ponownie, to odrzuć. | |||
# Gdy dotarłeś do prawego ogranicznika i nie napotkałeś <math>\clubsuit</math>, to odrzuć; w przeciwnym przypadku akceptuj. | |||
</div></div> | </div></div> | ||
<div class="mw-collapsible mw-made=collapsible mw-collapsed"><span class="mw-collapsible-toogle mw-collapsible-toogle-default style="font-variant:small-caps">Rozwiązanie </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">Rozwiązanie </span><div class="mw-collapsible-content" style="display:none"> | ||
'''(Ad. 1)''' Wypiszemy maszynę <math>\mathcal{M}=(\Sigma _{T},S,f,s_{0},S_{F})</math> działającą według zaproponowanego we wskazówce schematu. | |||
Zbiór <math>\Sigma_I</math> oraz stan początkowy <math>s_0</math> zostały narzucone treścią zadania. Oznaczamy kolejno: | |||
<center><math> | |||
\Sigma_T=\left\{0,1,\clubsuit,\sharp\right\}\quad,\quad S=\left\{s_0,s_1,s_R,s_A\right\}\quad,\quad S_F=\left\{s_A\right\} | |||
</math></center> | </math></center> | ||
oraz definiujemy funkcję przejścia według tabeli: | |||
{| border=1 align=center | |||
|- | |||
< | | <math>(s_0,0)\mapsto (s_0,0,1)</math> || <math>(s_0,1)\mapsto (s_0,1,1)</math> || <math>(s_0,\clubsuit)\mapsto (s_1,\clubsuit,1)</math> | ||
|| <math>(s_0,\sharp)\mapsto (s_R,\sharp,0)</math> | |||
|- | |||
| <math>(s_1,0)\mapsto (s_1,0,1)</math> || <math>(s_1,1)\mapsto (s_1,1,1)</math> || <math>(s_1,\clubsuit)\mapsto (s_R,\clubsuit,0)</math> || | |||
<math>(s_1,\sharp)\mapsto (s_A,\sharp,0)</math> | |||
|- | |||
| || || <math>(s_R,\clubsuit)\mapsto (s_R,\clubsuit,0)</math> || <math>(s_R,\sharp)\mapsto (s_R,\sharp,0)</math> | |||
|- | |||
| || || || <math>(s_A,\sharp)\mapsto (s_A,\sharp,0)</math> | |||
|} | |||
< | Wykonujemy kolejno symulację maszyny Turinga <math>\mathcal{M}</math> na słowach:<br> | ||
'''(Ad. 2)''' <math>w_1=1100\clubsuit 11</math><br> | |||
<center><math> | |||
<center><math>\ | \begin{array} {c c c c c c c c} | ||
&\sharp s_0 1100\clubsuit 11\sharp & \mapsto & \sharp 1 s_0 100\clubsuit 11\sharp &\mapsto & | |||
\sharp 11 s_0 00\clubsuit 11\sharp &\mapsto & \sharp 110 s_0 0\clubsuit 11\sharp | |||
\\ | |||
\mapsto & \sharp 1100 s_0 \clubsuit 11\sharp & \mapsto & \sharp 1100\clubsuit s_1 11\sharp &\mapsto & | |||
\sharp 1100\clubsuit 1 s_1 1\sharp &\mapsto & \sharp 1100\clubsuit 11 s_1 \sharp | |||
\\ | |||
\mapsto & \sharp 1100\clubsuit 11 s_A \sharp & \circlearrowleft | |||
\end{array} | |||
</math></center> | </math></center> | ||
Konfiguracja końcowa jest akceptująca, zatem rzeczywiście <math>w_1\in L(\mathcal{M})</math>. | |||
</ | <br> | ||
'''(Ad. 3)''' <math>w_2=\clubsuit 01 \clubsuit</math><br> | |||
<center><math> | |||
\begin{array} {c c c c c c c c} | |||
<center><math> | & \sharp s_0 \clubsuit 01 \clubsuit \sharp & \mapsto & \sharp\clubsuit s_1 01 \clubsuit\sharp &\mapsto & | ||
\sharp\clubsuit 0 s_1 1 \clubsuit\sharp &\mapsto & \sharp\clubsuit 01 s_1 \clubsuit\sharp | |||
\\ | |||
\mapsto & \sharp\clubsuit 01 s_R \clubsuit\sharp & \circlearrowleft | |||
\end{array} | |||
</math></center> | </math></center> | ||
} | Żadna z otrzymanych konfiguracji nie była akceptująca, zatem <math>w_2\not\in L(\mathcal{M})</math>. | ||
< | <br> | ||
'''(Ad. 4)''' <math>w_3=0000110</math><br> | |||
< | <center><math> | ||
\begin{array} {c c c c c c c c} | |||
& \sharp s_0 0000110 \sharp & \mapsto & \sharp 0 s_0 000110 \sharp &\mapsto & \sharp 00 s_0 00110 \sharp &\mapsto & | |||
\sharp 000 s_0 0110 \sharp | |||
\\ | |||
\mapsto & \sharp 0000 s_0 110 \sharp & \mapsto & \sharp 00001 s_0 10 \sharp &\mapsto & \sharp 000011 s_0 0 \sharp &\mapsto & | |||
\sharp 0000110 s_0 \sharp | |||
\\ | |||
\mapsto & \sharp 0000110 s_R \sharp & \circlearrowleft | |||
\end{array} | |||
</math></center> | |||
Tak jak w poprzednim przypadku <math>w_3\not\in L(\mathcal{M})</math>. | |||
</div></div> | </div></div> | ||
{{cwiczenie||| | {{cwiczenie|3|| | ||
W trakcie wykładu rozważaliśmy | W trakcie wykładu rozważaliśmy język | ||
<center><math> | |||
L=\{3^k\ : : \ : k=i\cdot j\text{ dla pewnych } i,j> 1\}</math>,</center> | |||
wykazując, że <math>L\in</math> '''NP''' . | |||
<math>\ | Uzasadnij, że także <center><math>L\in</math> '''P''' <math></math>.</center> | ||
}} | }} | ||
<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"> | ||
Zastanów się, ile maksymalnie trzeba wykonać mnożeń, aby zweryfikować istnienie <math>i,j>1</math>, dla których | |||
<math>k=i\cdot j</math>. | |||
</div></div> | </div></div> | ||
<div class="mw-collapsible mw-made=collapsible mw-collapsed"><span class="mw-collapsible-toogle mw-collapsible-toogle-default style="font-variant:small-caps">Rozwiązanie </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">Rozwiązanie </span><div class="mw-collapsible-content" style="display:none"> | ||
Sprawdzamy wszystkie możliwości. Musimy wykonać maksymalnie <math>k^2</math> (wielomianową ilość) mnożeń. Sama weryfikacja | |||
zależności <math>k=i\cdot j</math> (według uzasadnienia z wykładu) jest wykonywana w czasie wielomianowym. | |||
Pozostaje zaprojektować deterministyczną maszynę generującą ciągi. Można to zrobić według schematu | |||
(maszyna czterotaśmowa): | |||
to | # Taśma nr <math>1</math> jest tylko do odczytu. Mamy na niej słowo <math>3^k</math>. | ||
# Rozpocznij od zapisania słowa <math>11</math> na taśmie nr <math>2</math> i słowa <math>22</math> na taśmie nr <math>3</math>. | |||
# {{kotwica|prz.3|}}Przepisz słowa na taśmę nr <math>4</math> według kolejności taśm <math>2,3,1</math>. | |||
</ | # Sprawdź na taśmie nr <math>4</math> czy <math>k=i\cdot j</math>. Jeśli tak, to akceptuj. Inaczej krok następny. | ||
# Dopisz symbol <math>1</math> na taśmie nr <math>2</math>. Gdy powstało słowo dłuższe niż <math>k</math>, dopisz symbol <math>2</math> na taśmie nr <math>3</math>, a słowo na taśmie nr <math>2</math> usuń i zapisz na niej słowo <math>11</math>. | |||
# Jeśli słowo na taśmie nr <math>3</math> jest dłuższe niż <math>k</math>, to odrzuć. W przeciwnym przypadku przejdź do kroku [[#prz.3|3]]. | |||
Idea tej maszyny jest bardzo prosta. Wykorzystaj taśmy nr <math>2</math> (licznik 1) i <math>3</math> (licznik 2) jako liczniki, a na taśmie <math>4</math> wykonuj symulacje. | |||
Zacznij od stanu liczników na <math>2</math> i zwiększaj kolejno licznik 1, a po jego przepełnieniu zeruj go (do wartości początkowej <math>2</math>) | |||
i zwiększ licznik <math>2</math>. Gdy on także się przepełni, to iloczyn stanów liczników przekracza <math>k</math>, zatem można zakończyć generowanie ciągów. | |||
( | |||
< | |||
( | |||
< | |||
< | |||
W oczywisty sposób otrzymujemy, że ilość wymaganych kroków czasowych maszyny jest ograniczona przez wielomian (dla dużych <math>n</math>). | |||
Dla małych <math>n</math> możemy zawsze rozbudować maszynę tak, aby akceptowała słowa bez żadnego testowania. | |||
Zatem <math>L\in</math> '''P''' . | |||
</math> | |||
''' | |||
</div></div> | </div></div> | ||
{{cwiczenie||| | {{cwiczenie|4|| | ||
Uzasadnij, że funkcja <math>s(n)=3n</math> jest konstruowalna pamięciowo. | |||
}} | }} | ||
<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"> | ||
Przypomnij sobie uzasadnienie dla funkcji <math>2n</math> z wykładu. | |||
</div></div> | </div></div> | ||
<div class="mw-collapsible mw-made=collapsible mw-collapsed"><span class="mw-collapsible-toogle mw-collapsible-toogle-default style="font-variant:small-caps">Rozwiązanie </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">Rozwiązanie </span><div class="mw-collapsible-content" style="display:none"> | ||
Bierzemy maszynę <math>MT_4</math> z wykładu konstruującą funkcję <math>2n</math>. Dodajemy jedną dodatkową taśmę (oznaczmy taśmy przez <math>I</math> oraz <math>S</math>). | |||
<math> | Drugą taśmę realizujemy poprzez rozszerzenie alfabetu. Jest to spowodowane faktem, że w definicji konstruowalności | ||
pamięciowej wymagane jest istnienie jednotaśmowej deterministycznej maszyny Turinga. | |||
Konstruujemy maszynę <math>\mathcal{M}</math> według schematu: | |||
# Jeśli słowo wejściowe jest puste, to stop. | |||
# Jeśli słowo wejściowe jest inne niż <math>1^n</math>, to odrzuć. | |||
# Przepisz słowo wejściowe tak, aby znajdowało się na taśmie <math>I</math>, a taśma <math>S</math> była pusta (gdy zaczynamy symulować dwie taśmy musimy przejść do innego zestawu symboli, w którym rozróżniamy taśmy). | |||
# Kopiujemy słowo wejściowe na taśmę <math>S</math>. | |||
niż | # Symulujemy maszynę <math>MT_4</math> na taśmie <math>S</math>. | ||
# | # Dopisujemy do taśmy <math>S</math> słowo wejściowe. W tym momencie zaznaczyliśmy dokładnie <math>3n</math> komórek taśmy. | ||
< | # Zamieniamy symbole na <math>1</math> (zapominamy o symulacji taśm), wracamy do lewego markera i przechodzimy do konfiguracji końcowej <math>s_1\in S_F</math>. | ||
( | |||
< | |||
</math> | |||
< | |||
< | |||
</math> | |||
Po zakończeniu cyklu doszliśmy do konfiguracji <math>\sharp s_1 1^{3n} \sharp</math>, co było wymagane w definicji. | |||
</div></div> | </div></div> | ||
{{cwiczenie|5|| | |||
Uzasadnij, że funkcja <math>s(n)=3^n</math> jest konstruowalna pamięciowo. | |||
{{cwiczenie||| | |||
}} | }} | ||
<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"> | |||
Wykorzystaj konstruowalność pamięciową funkcji <math>g(n)=3n</math>. | |||
< | </div></div> | ||
< | |||
</ | |||
<div class="mw-collapsible mw-made=collapsible mw-collapsed"><span class="mw-collapsible-toogle mw-collapsible-toogle-default style="font-variant:small-caps">Rozwiązanie </span><div class="mw-collapsible-content" style="display:none"> | |||
<math>\ | Wykorzystujemy trzy taśmy (<math>I</math>, <math>C</math>, <math>S</math>) oraz maszynę <math>\mathcal{M}</math> konstruującą pamięciowo funkcję <math>g(n)=3n</math>. | ||
Docelowa maszyna <math>\mathcal{N}</math> działa według schematu. | |||
# Jeśli słowo początkowe jest puste, wypisz <math>1</math> i zatrzymaj się. W przeciwnym wypadku, wykonaj następny krok. | |||
# Jeśli słowo wejściowe jest inne niż <math>1^n</math>, to odrzuć. | |||
# Na taśmie <math>I</math> wypisz słowo wejściowe, na taśmach <math>C</math> i <math>S</math> wypisz słowo <math>1</math>. | |||
# {{kotwica|prz.4|}}Wykonaj symulację maszyny <math>\mathcal{M}</math> na taśmie <math>S</math> oraz dopisz symbol <math>1</math> do taśmy <math>C</math> (po jednym przebiegu ilość symboli na taśmie <math>S</math> wzrasta trzykrotnie) | |||
# Jeśli słowo na taśmie <math>C</math> jest krótsze niż słowo na taśmie <math>I</math>, wykonaj ponownie krok [[#prz.4|4]]. | |||
# W tym momencie na taśmie <math>S</math> zostało zaznaczone <math>3^n</math> komórek. | |||
Zamieniamy wypisane symbole na <math>1</math> (zapominamy o symulacji taśm), wracamy nad pierwszy symbol (przed lewym markerem) | |||
i przechodzimy do konfiguracji końcowej <math>s_1\in S_F</math>. | |||
Po zakończeniu cyklu doszliśmy do konfiguracji <math>\sharp s_1 1^{3^n} \sharp</math>, co było wymagane w definicji konstruowalności | |||
pamięciowej. | |||
</div></div> | |||
<center>Zadania domowe</center> | |||
{{cwiczenie||| | {{cwiczenie|6|| | ||
Skonstruuj maszynę Turinga <math>\mathcal{MT}</math> akceptującą język: | |||
}} | <center><math> | ||
L_1=\left\{www\ : : \ : w\in \left\{\circ,\bullet,\star\right\}^*\right\}</math></center> | |||
}} | }} | ||
{{cwiczenie||| | {{cwiczenie|7|| | ||
Uzasadnij, że język | |||
<center><math> | |||
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\} | |||
<center><math> | |||
{ | |||
</math></center> | </math></center> | ||
{ | jest rozpoznawany przez pewną niedeterministyczna maszynę Turinga <math>\mathcal{NMT}</math>. <br> | ||
''' | ''Podpowiedź:'' wykorzystaj konstrukcję z wyrocznią. Dla słowa wejściowego <math>w</math> przeprowadź weryfikację w trzech | ||
etapach: konstrukcja słów <math>w_1, \dots ,w_n</math>, gdzie <math>n< |w|</math> (wyrocznia), sklejanie, weryfikacja, czy <math>w=w_1w_1 w_2 w_2 \dots w_n w_n</math>. | |||
}} | }} |
Aktualna wersja na dzień 21:49, 11 wrz 2023
Ćwiczenia 12
Ćwiczenie 1
Rozważmy maszynę Turinga z wykładu (Przykład 1.2) akceptującą język palindromów, czyli:
Sprawdź, że:
oraz że
- .
Ćwiczenie 2
Niech będzie dany alfabet . Zaprojektuj maszynę Turinga akceptująca język postaci:
Zaprojektuj maszynę Turinga , która akceptuje język . Następnie:
- Wypisz elementy składowe maszyny , tzn. zbiory oraz funkcję przejścia (zapewnij, aby ).
- Wykonaj symulację maszyny na słowie ,
- na słowie ,
- oraz na słowie .
Ćwiczenie 3
W trakcie wykładu rozważaliśmy język
wykazując, że NP .
Uzasadnij, że takżeĆwiczenie 4
Uzasadnij, że funkcja jest konstruowalna pamięciowo.
Ćwiczenie 5
Uzasadnij, że funkcja jest konstruowalna pamięciowo.
Ćwiczenie 6
Skonstruuj maszynę Turinga akceptującą język:
Ćwiczenie 7
Uzasadnij, że język
jest rozpoznawany przez pewną niedeterministyczna maszynę Turinga .
Podpowiedź: wykorzystaj konstrukcję z wyrocznią. Dla słowa wejściowego przeprowadź weryfikację w trzech etapach: konstrukcja słów , gdzie (wyrocznia), sklejanie, weryfikacja, czy .