Języki, automaty i obliczenia/Ćwiczenia 7: Twierdzenie Kleene'ego. Własności języków i gramatyk regularnych: Różnice pomiędzy wersjami

Z Studia Informatyczne
Przejdź do nawigacjiPrzejdź do wyszukiwania
m Zastępowanie tekstu – „,</math>” na „</math>,”
m Zastępowanie tekstu – „ </math>” na „</math>”
Linia 12: Linia 12:
\hline a & s_2 & s_1 & s_2 \\ \hline b & s_1 & s_1 & s_2\\  
\hline a & s_2 & s_1 & s_2 \\ \hline b & s_1 & s_1 & s_2\\  
\hline \end{array}  \begin{array} {c|c|c|} f_{\mathcal C} &s_{\mathcal C} &s \\ \hline a & s & s \\  
\hline \end{array}  \begin{array} {c|c|c|} f_{\mathcal C} &s_{\mathcal C} &s \\ \hline a & s & s \\  
\hline b & s_{\mathcal C} & s_{\mathcal C} \\ \hline \end{array} </math></center>
\hline b & s_{\mathcal C} & s_{\mathcal C} \\ \hline \end{array} </math></center>


skonstruuj automat <math>\mathcal A</math> taki, że <center><math>L({\mathcal A}) = L({\mathcal B}) \cap L({\mathcal C})</math>,</center>
skonstruuj automat <math>\mathcal A</math> taki, że <center><math>L({\mathcal A}) = L({\mathcal B}) \cap L({\mathcal C})</math>,</center>
Linia 39: Linia 39:
<center><math>\begin{array} {c|c|c|c|} f_{\mathcal B} &s_{\mathcal B} &s_1 & s_2 \\  
<center><math>\begin{array} {c|c|c|c|} f_{\mathcal B} &s_{\mathcal B} &s_1 & s_2 \\  
\hline a & s_1 & s_2 & s_2 \\ \hline b & s_1 & s_{\mathcal{B}} & s_1\\  
\hline a & s_1 & s_2 & s_2 \\ \hline b & s_1 & s_{\mathcal{B}} & s_1\\  
\hline \end{array} </math></center>
\hline \end{array} </math></center>


skonstruuj automat deterministyczny <math>\mathcal A</math> taki, że  
skonstruuj automat deterministyczny <math>\mathcal A</math> taki, że  
Linia 93: Linia 93:
# Jeśli <math>|w|>p</math>, to z lematu o pompowaniu wynika, że <math>\exists v_1 v_2 \in A^*</math>, <math>\exists u \in A^+</math> takie, że <math>w=v_1 uv_2</math>,  <math>v_1 v_2 \in L(\mathcal{C})</math> i <math>|v_1v_2|<|w|</math>.
# Jeśli <math>|w|>p</math>, to z lematu o pompowaniu wynika, że <math>\exists v_1 v_2 \in A^*</math>, <math>\exists u \in A^+</math> takie, że <math>w=v_1 uv_2</math>,  <math>v_1 v_2 \in L(\mathcal{C})</math> i <math>|v_1v_2|<|w|</math>.
<center><math>(f\times g)((s_0,t_0),w) =  (f\times g)((s_0,t_0),v_1 v_2)=(f(s_0,v_1v_2),g(t_0,v_1v_2))
<center><math>(f\times g)((s_0,t_0),w) =  (f\times g)((s_0,t_0),v_1 v_2)=(f(s_0,v_1v_2),g(t_0,v_1v_2))
\in S\times F \cup T\times Q   </math></center>
\in S\times F \cup T\times Q   </math></center>
Mamy dwie możliwości:
Mamy dwie możliwości:


Linia 124: Linia 124:
Udowodnij, że następujące języki nie są regularne:
Udowodnij, że następujące języki nie są regularne:
# <math>L = \{a^n : n \; \text{nie jest liczbą pierwszą;} \}</math>,
# <math>L = \{a^n : n \; \text{nie jest liczbą pierwszą;} \}</math>,
# <math>L=\left\{ a^{n}b^{m}:0\leq n,m;\;n\neq m\right\} </math>.
# <math>L=\left\{ a^{n}b^{m}:0\leq n,m;\;n\neq m\right\}</math>.


}}
}}
Linia 132: Linia 132:
\; \text{ jest liczbą pierwszą;} \}</math> nie jest akceptowany (
\; \text{ jest liczbą pierwszą;} \}</math> nie jest akceptowany (
ćwiczenie 8), a więc nie  jest regularny.  
ćwiczenie 8), a więc nie  jest regularny.  
<center><math>a^*=L \cup L', L\cap L' = \emptyset, \;\text {a więc}\;L'=\overline{L}. </math></center>
<center><math>a^*=L \cup L', L\cap L' = \emptyset, \;\text {a więc}\;L'=\overline{L}.</math></center>


Ponieważ klasa języków regularnych jest zamknięta ze względu na  
Ponieważ klasa języków regularnych jest zamknięta ze względu na  
Linia 138: Linia 138:
</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 punktu 2</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 punktu 2</span><div class="mw-collapsible-content" style="display:none">
Język <math>L'=\left\{ a^{n}b^{n}:0\leq n \right\} </math> nie jest  akceptowany  
Język <math>L'=\left\{ a^{n}b^{n}:0\leq n \right\}</math> nie jest  akceptowany  
(patrz [[Języki, automaty i obliczenia/Wykład 6: Automat niedeterministyczny. Lemat o pompowaniu#przyklad_3_1|3.1. z wykładu 6]]), a więc nie  jest regularny.
(patrz [[Języki, automaty i obliczenia/Wykład 6: Automat niedeterministyczny. Lemat o pompowaniu#przyklad_3_1|3.1. z wykładu 6]]), a więc nie  jest regularny.
<center><math>a^*b^* =L \cup L',L\cap L' = \emptyset,\;\text {a więc}\;L'=a^* b^* \cap\overline{L}</math>.</center>
<center><math>a^*b^* =L \cup L',L\cap L' = \emptyset,\;\text {a więc}\;L'=a^* b^* \cap\overline{L}</math>.</center>
Linia 161: Linia 161:
\hline a & s_2 & s_1 & s_2 \\ \hline b & s_1 & s_1 & s_2\\ \hline \end{array}   
\hline a & s_2 & s_1 & s_2 \\ \hline b & s_1 & s_1 & s_2\\ \hline \end{array}   
\begin{array} {c|c|c|c|} f_{\mathcal C} &s_{\mathcal C} &{s'}_1&{s'}_2 \\ \hline a & {s'}_1 & {s'}_1& {s'}_2 \\  
\begin{array} {c|c|c|c|} f_{\mathcal C} &s_{\mathcal C} &{s'}_1&{s'}_2 \\ \hline a & {s'}_1 & {s'}_1& {s'}_2 \\  
\hline b & {s'}_2 & {s'}_1& {s'}_2 \\ \hline \end{array} </math></center>
\hline b & {s'}_2 & {s'}_1& {s'}_2 \\ \hline \end{array} </math></center>
2. <math>L({\mathcal A}) = L({\mathcal B})^*</math>, gdzie <center><math>{\mathcal B} =  
2. <math>L({\mathcal A}) = L({\mathcal B})^*</math>, gdzie <center><math>{\mathcal B} =  
(S_{\mathcal B},A,f_{\mathcal B},s_{\mathcal B},F_{\mathcal B})</math>,</center>
(S_{\mathcal B},A,f_{\mathcal B},s_{\mathcal B},F_{\mathcal B})</math>,</center>
Linia 170: Linia 170:


<center><math>\begin{array} {c|c|c|c|c|} f_{\mathcal B} &s_{\mathcal B} &s_1 & s_2 & s_3\\ \hline a & s_1 & s_3 & s_3 & s_3 \\  
<center><math>\begin{array} {c|c|c|c|c|} f_{\mathcal B} &s_{\mathcal B} &s_1 & s_2 & s_3\\ \hline a & s_1 & s_3 & s_3 & s_3 \\  
\hline b & s_3 & s_2 & s_3 &s_3\\ \hline \end{array} </math></center>
\hline b & s_3 & s_2 & s_3 &s_3\\ \hline \end{array} </math></center>


Podaj dwie konstrukcje:   
Podaj dwie konstrukcje:   
Linia 195: Linia 195:
}}
}}
<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 do punktu 2 </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 do punktu 2 </span><div class="mw-collapsible-content" style="display:none">
Wykorzystaj fakt, że język <math>\left\{ a^{n}b^{n}:n \geq 0\right\} </math> nie jest regularny oraz
Wykorzystaj fakt, że język <math>\left\{ a^{n}b^{n}:n \geq 0\right\}</math> nie jest regularny oraz
domkniętość klasy języków regularnych ze względu na homomorfizm.
domkniętość klasy języków regularnych ze względu na homomorfizm.
</div></div>
</div></div>

Wersja z 10:03, 5 wrz 2023

Ćwiczenia 7

Ćwiczenie 1

Niech A={a,b}. Dla automatów
=(S,A,f,s,F),𝒞=(S𝒞,A,f𝒞,s𝒞,F𝒞)
S={s,s1,s2},F={s2},S𝒞={s𝒞,s},F𝒞={s},

gdzie

fss1s2as2s1s2bs1s1s2f𝒞s𝒞sassbs𝒞s𝒞
skonstruuj automat 𝒜 taki, że
L(𝒜)=L()L(𝒞),
Rozwiązanie

Ćwiczenie 2

Niech A={a,b}. Dla automatu
=(S,A,f,s,F),

gdzie

S={s,s1,s2},F={s1},

a funkcja przejść zdefiniowana jest następująco:

fss1s2as1s2s2bs1ss1

skonstruuj automat deterministyczny 𝒜 taki, że

L(𝒜)=L()*.
Wskazówka
Rozwiązanie

Ćwiczenie 3

Dane są dwa automaty nad tym samym alfabetem A
𝒜=(S,f,s0,T) i =(Q,g,t0,F). Udowodnij, że istnieje liczba p0 taka, że jeśli dla każdego słowa w o długości |w|p spełniona jest implikacja wL(𝒜)wL(), to

L(𝒜)L()
Rozwiązanie

Ćwiczenie 4

Niech A będzie dowolnym alfabetem, a LA* językiem regularnym. Udowodnij, że język L={a|w|:wL} jest też językiem regularnym.

Rozwiązanie

Ćwiczenie 5

Udowodnij, że następujące języki nie są regularne:

  1. L={an:nnie jest liczbą pierwszą;},
  2. L={anbm:0n,m;nm}.
Rozwiązanie punktu 1
Rozwiązanie punktu 2
ZADANIA DOMOWE

Ćwiczenie 6

Niech A={a,b}. Skonstruuj automat 𝒜, taki że

1. L(𝒜)=L()L(𝒞), gdzie
=(S,A,f,s,F),𝒞=(S𝒞,A,f𝒞,s𝒞,F𝒞),
S={s,s1,s2},F={s2},S𝒞={s𝒞,s1,s2},F𝒞={s2},


fss1s2as2s1s2bs1s1s2f𝒞s𝒞s1s2as1s1s2bs2s1s2
2. L(𝒜)=L()*, gdzie
=(S,A,f,s,F),
S={s,s1,s2,s3},F={s2},


fss1s2s3as1s3s3s3bs3s2s3s3

Podaj dwie konstrukcje:

  1. opartą na dowodzie twierdzenia Kleene'ego,
  2. z wykorzystaniem automatu z pustymi przejściami.

Ćwiczenie 7

Skonstruuj minimalny automat 𝒜, taki że L(𝒜)=L()*, gdzie opisany jest

poniższym grafem:
Rysunek 5


Ćwiczenie 8

Udowodnij, że następujące języki nie są regularne:

  1. L={anbmcn:0<n,m},
  2. L={(ab)n(bc)n:n0}.
Wskazówka do punktu 2

Ćwiczenie 9

Zbuduj automat akceptujący język będący ogółem skończonych sekwencji binarnych, w których liczba zer jest podzielna przez dwa, a liczba jedynek przez 3, a następnie gramatykę generującą ten język.

Wskazówka