Escolar Documentos
Profissional Documentos
Cultura Documentos
Sumário
FACIN-PPGCC 1. PANO DE FUNDO
2. LINGUAGENS
3. DEFINIÇÕES RECURSIVAS
Teoria da Computabilidade 4. EXPRESSÕES REGULARES
6. GRAFOS DE TRANSIÇÃO
Ney Laert Vilar Calazans & Avelino Zorzo 7. TEOREMA DE KLEENE
{calazans,
calazans, zorzo
zorzo}@
}@inf.pucrs.br
inf.pucrs.br 9. LINGUAGENS REGULARES
3 4
1
5 6
7 8
2
9 10
11 12
Sumário 2. Linguagens
1. PANO DE FUNDO
• Elementos definitórios de linguagens formais
2. LINGUAGENS
– Alfabeto - conjunto finito de símbolos
3. DEFINIÇÕES RECURSIVAS
– Palavra - seqüência finita de elementos do alfabeto
4. EXPRESSÕES REGULARES – Regras para a formação de palavras
5. AUTÔMATOS FINITOS – Sentença - seqüência finita de palavras
6. GRAFOS DE TRANSIÇÃO – Regras para a formação de sentenças
7. TEOREMA DE KLEENE
– Linguagem - conjunto de sentenças (ou de palavras)
8. AUTÔMATOS FINITOS COM SAÍDAS
• Linguagens Formais
– onde forma interessa, mais que o significado
9. LINGUAGENS REGULARES
• sintaxe interessa, não semântica
10. LINGUAGENS NÃO-REGULARES – “Eu comi três terça-feiras” sentença correta!
3
13 14
2. Linguagens 2. Linguagens
15 16
2. Linguagens 2. Linguagens
4
17 18
2. Linguagens 2. Linguagens
• Prova por algoritmo construtivo • Exemplo:
– Exemplo: S={xx xxx}. S* contém todas as cadeias – S={a b ab} e T={a b bb}
de x exceto a cadeia x em si. Provar! – S*=T*, porquê?
• x2 e x3 trivialmente existem em S*
• Para excluir a palavra vazia do fechamento,
• concatenando sucessivos x2 pode-se formar todas as
cadeias de comprimento par tem-se:
• concatenando sucessivos x2 a x3 pode-se formar todas as – se Σ={x}, então Σ+={x xx xxx ]} fechamento positivo
cadeias de comprimento ímpar
• Exemplo:
• Método de prova mais importante aqui! – S={w1 w2 w3}
• Se Σ=Ø, então Σ*={Λ
Λ} – S+={w1 w2 w3 w1w1 w1w2 w1w3 w2w1 w2w2 ...}
Λ}, então S*={Λ
• Se S={Λ Λ}, porque ΛΛ=Λ
ΛΛ Λ Λ, então S+={aa bbb Λ aaaa
– Se w1=aa, w2=bbb, w3=Λ
– Exceto nos dois casos acima, Kleene star é sempre aabbb ]}
conjunto infinito!
19 20
2. Linguagens Sumário
• Fechamento Kleene de um fechamento Kleene: 1. PANO DE FUNDO
5
21 22
23 24
6
25 26
9. LINGUAGENS REGULARES
11. DECIDIBILIDADE
27 28
7
29 30
31 32
8
33 34
35 36
9
37 38
39 40
Λ + a) ??
– o que produz b*(abb*)* (Λ 2. LINGUAGENS
11. DECIDIBILIDADE
10
41 42
43 44
• Definição descreve o que é autômato, não • Dada uma seqüência de letras (uma palavra)
como ele funciona. Funcionamento: – autômato aceita palavra se, partindo do estado
– a partir do estado inicial, dada um seqüência de inicial, o processamento de toda a seqüência deixa
letras de entrada, o autômato transiciona entre o autômato em algum estado final.
estados, uma para cada letra processada na • Conjunto de palavras aceitas definem a
seqüência dada. linguagem aceita pelo autômato
• Exemplo de autômato finito (FA) • Autômato aceita ou rejeita palavras
– 1. S={x, y, z}; 2. Σ={a,b}; 3. Transições:
• Autômatos podem ser vistos como
• 3.1 - de x, com entrada a, vá para y. Estado inicial
• 3.2 - de x, com entrada b, vá para z. reconhecedores de linguagens
Estados finais
• 3.3 - de y, com entrada a, vá para x. • Exercício - definir uma ER para a linguagem
• 3.4 - de y, com entrada b, vá para z.
aceita para o autômato exemplo! (aa+bb)*b
b (a
a+b
b)*
• 3.5 - de z, com qualquer entrada, permaneça em z.
11
45 46
47 48
12
49 50
b b b
– 3. – A linguagem (a+b)*(aa+bb) (a+b)*
a
a a
b
- b a +
a
b b b
a,b
51 52
13
53 54
3. DEFINIÇÕES RECURSIVAS
4. EXPRESSÕES REGULARES
5. AUTÔMATOS FINITOS
• Muito parecido com FAs, mas mais flexível
6. GRAFOS DE TRANSIÇÃO
7. TEOREMA DE KLEENE
9. LINGUAGENS REGULARES
• Mais propenso a confusões de interpretação
10. LINGUAGENS NÃO-REGULARES
11. DECIDIBILIDADE
55 56
a,b baa
- +
14
57 58
59 60
15
61 62
63 64
3. DEFINIÇÕES RECURSIVAS
4. EXPRESSÕES REGULARES
5. AUTÔMATOS FINITOS
6. GRAFOS DE TRANSIÇÃO
7. TEOREMA DE KLEENE
9. LINGUAGENS REGULARES
11. DECIDIBILIDADE
16
65 66
67 68
17
69 70
Λ b
... x ... ⇒ ... x ...
1 2 ... b
ab r3
9 r1
Λ Λ
- 3 aa
...
4 ... Λ + ... 3 7 ... ⇒ ... 3
r1+r2
7 ...
Λ aa aba
12 r2
5
b
71 72
• Terceiro passo do algoritmo (Parte 2). Itera com • Terceiro passo (continuação)
segundo passo. Sem alterar linguagem aceita: 3 ...
r3
– Eliminar todos os vértices diferentes de – e +
... 1 r1 2 r4
4 ... ⇒
... 1
r1 2 r3
3 ... ⇒ ... 1
r1r3
3 ... r2
r5 ⇓
5 ...
3 ...
r1r2*r3
... 1 r1 2 r3
3 ... ⇒ ... 1
r1r2*r3
3 ...
r1r2*r4
... 1 4 ...
r2
r1r2*r5
5 ...
18
73 74
75 76
19
77 78
79 80
20
81 82
83 84
21
85 86
87 88
b/1
22
89 90
11. DECIDIBILIDADE
91 92
23
93 94
3. DEFINIÇÕES RECURSIVAS
4. EXPRESSÕES REGULARES
5. AUTÔMATOS FINITOS
6. GRAFOS DE TRANSIÇÃO
7. TEOREMA DE KLEENE
9. LINGUAGENS REGULARES
11. DECIDIBILIDADE
95 96
3. DEFINIÇÕES RECURSIVAS
4. EXPRESSÕES REGULARES
5. AUTÔMATOS FINITOS
6. GRAFOS DE TRANSIÇÃO
7. TEOREMA DE KLEENE
9. LINGUAGENS REGULARES
11. DECIDIBILIDADE
24