Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
aa:lab:3 [2023/10/22 13:36] ioana.dabelea |
aa:lab:3 [2024/10/31 20:08] (current) stefan.sterea [Exerciții] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Reduceri Turing ====== | + | ====== Reduceri ====== |
- | /* | + | |
- | <hidden> | + | Reducerile sunt o unealtă folositoare pentru a demonstra (ne)decidabilitatea/acceptabilitatea unor probleme. Vom folosi în mod predominant reducerile pentru a demonstra prin absurd că o problemă nouă $ f$ nu este decidabilă, atfel: |
- | <note important> | + | |
- | Solutii: https://drive.google.com/file/d/1RUCQaVsHkMbFLBojUJ7ok5gy5Mq6-ce8/view?usp=sharing | + | |
- | </note> | + | |
- | </hidden> | + | |
- | */ | + | |
- | Reducerile Turing sunt o unealtă folositoare pentru a demonstra (ne)decidabilitatea/acceptabilitatea unor probleme. Vom folosi în mod predominant reducerile pentru a demonstra prin absurd că o problemă nouă $ f$ nu este decidabilă, atfel: | + | |
* presupunem că $ f$ e decidabilă, deci există o mașină $ M_f$ care o decide | * presupunem că $ f$ e decidabilă, deci există o mașină $ M_f$ care o decide | ||
Line 24: | Line 18: | ||
* $ f_{111}(M) = TRUE \iff M[111] \rightarrow TRUE$ | * $ f_{111}(M) = TRUE \iff M[111] \rightarrow TRUE$ | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{111}$. | ||
- | |||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{111}$: | ||
- | $ M, w \to t \to M^*$ | ||
- | |||
- | După ce am găsit asta, mai ramane de demonstrat doar: $ f_{h}(M, w) = TRUE \iff f_{111}(M^*) = TRUE$ | ||
- | |||
- | $ M^*(x):$ | ||
- | <code> | ||
- | run M[w] | ||
- | return x == 111 | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{se termină} \Rightarrow \text{vom returna x == 111} \Rightarrow \text{când x este 111}, M^* \text{va tranziţiona în Y} => M^*[111] \rightarrow TRUE \Rightarrow f_{111}(M^*) = TRUE$ | ||
- | - $ f_{111}(M^*) = TRUE \Rightarrow M^*[111] \rightarrow TRUE \Rightarrow \text{am ajuns la return} \Rightarrow \text{run M[w] din }M^* \text{nu a ciclat} \Rightarrow \text{M[w] s-a oprit} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | |||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{111}$. | ||
- | </hidden> | ||
* $ f_{p}(M) = TRUE \iff \forall w, M \text{ decide dacă w e palindrom} $ | * $ f_{p}(M) = TRUE \iff \forall w, M \text{ decide dacă w e palindrom} $ | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{p}$. | ||
- | |||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{p}$: | ||
- | $ M, w \to t \to M^*$ | ||
- | |||
- | $ M^*(x):$ | ||
- | <code> | ||
- | run M[w] | ||
- | check if x is palindrome | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{se termină} \Rightarrow \text{o sa verificăm dacă x este palindrom} \Rightarrow \text{când x este palindrom}, M^* \text{va tranziţiona în Y} \Rightarrow f_{p}(M^*) = TRUE$ | ||
- | - $ f_{p}(M^*) = TRUE \Rightarrow M^*[x] \text{decide daca x este palindrom } \forall x \Rightarrow \text{am ajuns la return} \Rightarrow \text{run M[w] din }M^* \text{nu a ciclat} \Rightarrow \text{M[w] s-a oprit} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{p}$. | ||
- | </hidden> | ||
* $ f_{rev}(M) = TRUE \iff \forall w, M \text{ computează inversul lui w}$ | * $ f_{rev}(M) = TRUE \iff \forall w, M \text{ computează inversul lui w}$ | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{rev}$. | ||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{rev}$: | ||
- | $ M, w \to t \to M^*$ | ||
- | |||
- | $ M^*(x):$ | ||
- | <code> | ||
- | run M[w] | ||
- | return rev(x) | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{se termină} \Rightarrow \text{o sa calculeze rev(x) deoarece ajunge la return} \Rightarrow f_{rev}(M^*) = TRUE$ | ||
- | - $ f_{rev}(M^*) = TRUE \Rightarrow M^*[x] \text{calculeaza rev(x) } \forall x \forall x \Rightarrow \text{am ajuns la return} \Rightarrow \text{run M[w] din }M^* \text{nu a ciclat} \Rightarrow \text{M[w] s-a oprit} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | |||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{rev}$. | ||
- | </hidden> | ||
* $ f_{own}(M) = TRUE \iff M[enc(M)] \rightarrow TRUE$ | * $ f_{own}(M) = TRUE \iff M[enc(M)] \rightarrow TRUE$ | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{own}$. | ||
- | |||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{own}$: | ||
- | $ M, w \to t \to M^*$ | ||
- | |||
- | $ M^*(x):$ | ||
- | <code> | ||
- | if x == enc(M*): | ||
- | run M[w] | ||
- | else: | ||
- | nu se termină | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{se termină} \Rightarrow M^*[enc(M^*)] \text{se termina} \Rightarrow f_{own}(M^*) = TRUE$ | ||
- | - $ f_{own}(M^*) = TRUE \Rightarrow M^*[enc(M^*)] \text{se termina} \Rightarrow \text{run M[w] din }M^* \text{nu a ciclat} \Rightarrow \text{M[w] s-a oprit} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | |||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{own}$. | ||
- | </hidden> | ||
* $ f_{finite}(M) = TRUE \iff M \text{ se oprește pentru un număr finit de cuvinte}$ | * $ f_{finite}(M) = TRUE \iff M \text{ se oprește pentru un număr finit de cuvinte}$ | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{finite}$. | ||
- | |||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{finite}$: | ||
- | $ M, w \to t \to M^*$ | ||
- | |||
- | $ M^*(x):$ | ||
- | <code> | ||
- | run M[w] pentru maxim |x| paşi | ||
- | dacă M[w] s-a oprit: | ||
- | nu se termina | ||
- | else: | ||
- | se termina | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{ se termină in n paşi} \Rightarrow M^*[w] \text{se opreşte } \forall x \text{, |x| < n}, \text{ciclează } \forall x \text{, |x| >= n} \Rightarrow f_{finite}(M^*) = TRUE$ | ||
- | - $ f_{finite}(M^*) = TRUE \Rightarrow M^*[x] \text{ se opreşte după un număr finit de cuvinte }\Rightarrow \text{M[w] s-a oprit după un număr finit de paşi} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{finite}$. | ||
- | </hidden> | ||
* $ f_{set}(A, M) = TRUE \iff \forall w \in A, M[w] \text{ halts}$ | * $ f_{set}(A, M) = TRUE \iff \forall w \in A, M[w] \text{ halts}$ | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{set}$. | ||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{set}$: | ||
- | $ M, w \to t \to A, M^*$ | ||
- | |||
- | A = {101} | ||
- | $ M^*(x):$ | ||
- | <code> | ||
- | if x is in A: | ||
- | run M[w] | ||
- | else: | ||
- | nu se termină | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{se termină} \Rightarrow \text{cum } M^* \text{se poate opri doar pentru x = 101} \Rightarrow f_{set}(A, M^*) = TRUE$ | ||
- | - $ f_{set}(M^*) = TRUE \Rightarrow M^*[x] \text{o să se oprească pentru orice x din A} \Rightarrow \text{M[w] s-a oprit} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | |||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{set}$. | ||
- | </hidden> | ||
* $ f_{x}(M) = TRUE \iff \exists w, M[w] \text{ scrie un x pe bandă la un moment dat}$ | * $ f_{x}(M) = TRUE \iff \exists w, M[w] \text{ scrie un x pe bandă la un moment dat}$ | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{x}$. | ||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{x}$: | ||
- | $ M, w \to t \to M^*$ | ||
- | |||
- | $ M^*(x):$ | ||
- | <code> | ||
- | run M[w] | ||
- | print x | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{se termină} \Rightarrow \text{cum } M^* \text{printează x la final} \Rightarrow f_{x}(M^*) = TRUE$ | ||
- | - $ f_{x}(M^*) = TRUE \Rightarrow M^*[x] \text{ajunge să printeze x pe bandă} \Rightarrow \text{M[w] s-a oprit} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | |||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{x}$. | ||
- | </hidden> | ||
* $ f_{eq}(M_1, M_2) = TRUE \iff \forall w, M_1[w] \equiv M_2[w]$; i.e. mașinile au același comportament (fie acceptă, fie resping, fie computează aceeași valoare, fie nu se termină) pentru orice cuvânt. | * $ f_{eq}(M_1, M_2) = TRUE \iff \forall w, M_1[w] \equiv M_2[w]$; i.e. mașinile au același comportament (fie acceptă, fie resping, fie computează aceeași valoare, fie nu se termină) pentru orice cuvânt. | ||
- | <hidden> | ||
- | O să încercăm să arătăm că $ f_{h} \le_m f_{eq}$. | ||
- | |||
- | Trebuie să găsim o transformare t care primeşte inputul lui Halting Problem şi întoarce un input pentru $ f_{eq}$: | ||
- | $ M, w \to t \to M_{1}, M_{2}$ | ||
- | |||
- | $ M_{1}[x]: $ | ||
- | <code> | ||
- | acceptă | ||
- | </code> | ||
- | |||
- | $ M_{2}[x]: $ | ||
- | <code> | ||
- | run M[w] | ||
- | acceptă | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{h}(M, w) = TRUE \Rightarrow M[w] \text{se termină} \Rightarrow M_{2} \text{acceptă orice x, iar } M_{1}[x] \text{deja acceptă orice x din construcţie} \Rightarrow M_1[w] \equiv M_2[w] \Rightarrow f_{eq}(M_{1}, M_{2}) = TRUE$ | ||
- | - $ f_{eq}(M_{1}, M_{2}) = TRUE \Rightarrow M_1[w] \equiv M_2[w] \Rightarrow \text{stim din construcţie că} M_{1} \text{acceptă orice x} \Rightarrow M_{2} \text{acceptă orice x} \Rightarrow M[w] \text{se opreşte} \Rightarrow f_{h}(M, w) = TRUE$ | ||
- | Din cele 2 direcţii ale demonstraţiei $\Rightarrow f_{h} \le_m f_{eq}$. | ||
- | </hidden> | ||
<note tip> | <note tip> | ||
În continuare, problemele $ f_{all}$ și $ f_{any}$ sunt cunoscute ca nedecidabile: | În continuare, problemele $ f_{all}$ și $ f_{any}$ sunt cunoscute ca nedecidabile: | ||
Line 200: | Line 41: | ||
* $ f_{all} \le_m f_{eq}$ | * $ f_{all} \le_m f_{eq}$ | ||
- | <hidden> | ||
- | $ M \to t \to M_{1}, M_{2}$ | ||
- | Trebuie să construim o transformare t, astfel încât să obţinem 2 maşini cu acelaşi comportament doar dacă M[w] se opreşte **pentru orice** w | ||
- | |||
- | $ M_{1}[x]: $ | ||
- | <code> | ||
- | acceptă | ||
- | </code> | ||
- | |||
- | $ M_{2}[x]: $ | ||
- | <code> | ||
- | run M[x] | ||
- | acceptă | ||
- | </code> | ||
- | **Atenţie** acest exercitiu are transformarea diferită faţă de exerciţiul 1, subpunctul 8. | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{all}(M) = M \Rightarrow \forall x, M[x] \text{se termină} \Rightarrow M_{2} \text{ acceptă orice x, iar} M_{1} \text{deja acceptă orice x din construcţie} \Rightarrow M_1[w] \equiv M_2[w] \Rightarrow f_{eq}(M_{1}, M_{2}) = TRUE$ | ||
- | - $ f_{eq}(M_{1}, M_{2}) = TRUE \Rightarrow M_1[w] \equiv M_2[w] \text{, ştim din construcţie că } M_{1} \text{ acceptă orice x} \Rightarrow M_{2} \text{ acceptă orice x} \Rightarrow M[x] \text{se opreşte pentru orice x} \Rightarrow f_{all}(M, w) = TRUE$ | ||
- | </hidden> | ||
* $ f_{any} \le_m f_{eq}$ | * $ f_{any} \le_m f_{eq}$ | ||
- | <hidden> | ||
- | $ M \to t \to M_{1}, M_{2}$ | ||
- | |||
- | $ M_{1}[x]: $ | ||
- | <code> | ||
- | acceptă | ||
- | </code> | ||
- | |||
- | $ M_{2}[x]: $ | ||
- | <code> | ||
- | k = 1 | ||
- | inputs = [0] | ||
- | while true { | ||
- | for w in inputs: | ||
- | step(M[w]) // rulam o singura tranzitie | ||
- | if(M[w] s-a oprit) | ||
- | accepta | ||
- | k++ | ||
- | inputs.append(k) | ||
- | } | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{any}(M) = M \Rightarrow \exists w, M[w] \text{se termină} \Rightarrow M_{2} \text{ acceptă orice x, iar} M_{1} \text{deja acceptă orice x din construcţie} \Rightarrow M_1[w] \equiv M_2[w] \Rightarrow f_{eq}(M_{1}, M_{2}) = TRUE$ | ||
- | - $ f_{eq}(M_{1}, M_{2}) = TRUE \Rightarrow M_1[w] \equiv M_2[w] \text{, ştim din construcţie că } M_{1} \text{ acceptă orice x} \Rightarrow M_{2} \text{ acceptă orice x} \Rightarrow \exists w \text{ astfel încât } M[w] \text{ se opreşte} \Rightarrow f_{any}(M, w) = TRUE$ | ||
- | </hidden> | ||
* $ f_{p} \le_m f_{eq}$ | * $ f_{p} \le_m f_{eq}$ | ||
- | <hidden> | ||
- | $ M \to t \to M_{1}, M_{2}$ | ||
- | $ M_{1}[x]: $ | ||
- | <code> | ||
- | acceptă | ||
- | </code> | ||
- | |||
- | $ M_{2}[x]: $ | ||
- | <code> | ||
- | run M[x] | ||
- | if M decide corect daca x este palindrom: | ||
- | accepta | ||
- | else: | ||
- | nu accepta | ||
- | </code> | ||
- | |||
- | Demonstraţii: | ||
- | - $ f_{p} = TRUE \Rightarrow \forall x M \text{decide daca e palindrom} \Rightarrow M_{2} \text{ acceptă orice x, iar} M_{1} \text{deja acceptă orice x din construcţie} \Rightarrow M_1[w] \equiv M_2[w] \Rightarrow f_{eq}(M_{1}, M_{2}) = TRUE$ | ||
- | - $ f_{eq}(M_{1}, M_{2}) = TRUE \Rightarrow M_1[w] \equiv M_2[w] \text{, ştim din construcţie că } M_{1} \text{ acceptă orice x} \Rightarrow M_{2} \text{ acceptă orice x} \Rightarrow M \text{ decide corect dacă x este palindrom} \Rightarrow f_{p} = TRUE$ | ||
- | </hidden> | ||
* $ f_{own} \le_m f_{eq}$ | * $ f_{own} \le_m f_{eq}$ | ||
- | <hidden> | ||
- | $ M \to t \to M_{1}, M_{2}$ | ||
- | |||
- | $ M_{1}[x]: $ | ||
- | <code> | ||
- | acceptă | ||
- | </code> | ||
- | |||
- | $ M_{2}[x]: $ | ||
- | <code> | ||
- | if x == enc(M): | ||
- | run M[x] | ||
- | accepta | ||
- | </code> | ||
- | Demonstraţii: | ||
- | - $ f_{own} = TRUE \Rightarrow M[enc(M)] \text{ se termină} \Rightarrow M_{2} \text{ acceptă orice x, iar} M_{1} \text{deja acceptă orice x din construcţie} \Rightarrow M_1[w] \equiv M_2[w] \Rightarrow f_{eq}(M_{1}, M_{2}) = TRUE$ | ||
- | - $ f_{eq}(M_{1}, M_{2}) = TRUE \Rightarrow M_1[w] \equiv M_2[w] \text{, ştim din construcţie că } M_{1} \text{ acceptă orice x} \Rightarrow M_{2} \text{ acceptă orice x} \Rightarrow M[enc(M)] \text{ se termină} \Rightarrow f_{own} = TRUE$ | ||
- | </hidden> | ||
<note tip> | <note tip> | ||
Dacă $ t_{1}$ şi $ t_{2}$ sunt două funcţii computabile $ \Rightarrow t = t_{1} \circ t_{2} $ este computabilă. | Dacă $ t_{1}$ şi $ t_{2}$ sunt două funcţii computabile $ \Rightarrow t = t_{1} \circ t_{2} $ este computabilă. | ||
Line 296: | Line 53: | ||
3. Demonstrați că relația $ \le_m$ e reflexivă și tranzitivă. | 3. Demonstrați că relația $ \le_m$ e reflexivă și tranzitivă. | ||
- | <hidden> | ||
- | Demonstrăm că $ \le_m$ e reflexivă | ||
- | Fie o problemă $ f$ şi o transformare $ t: \Sigma^* \rightarrow \Sigma^*, t(w) = w$ | + | <note tip> |
- | + | Soluțiile acestui laborator se găsesc [[aa:lab:sol:3|aici]] | |
- | $ f(w) = True \iff f(t(w)) = TRUE$ deci $ f \le_m f$ | + | </note> |
- | + | ||
- | + | ||
- | Demonstrăm că $ \le_m$ e tranzitivă | + | |
- | + | ||
- | Fie probleme de decizie f, g, h astfel încât: | + | |
- | + | ||
- | $ f \le_m g$ (deci există o transformare $ t_{1}$ a.î. $ f(w) = TRUE \iff g(t_{1}(w)) = TRUE$) | + | |
- | + | ||
- | $ g \le_m h$ (deci există o transformare $ t_{2}$ a.î. $ g(w) = TRUE \iff h(t_{2}(w)) = TRUE$) | + | |
- | + | ||
- | + | ||
- | Luăm transformarea $ t = t_{1} \circ t_{2}$: | + | |
- | + | ||
- | $ f(w) = TRUE \iff h(t_{2}(t_{1}(w))) = TRUE$ | + | |
- | + | ||
- | $ f(w) = TRUE \iff h(t(w))) = TRUE \Rightarrow f \le_m h$ | + | |
- | </hidden> |