Download presentation
Presentation is loading. Please wait.
Published byAlexander Hall Modified over 8 years ago
1
Chapter 5 Recursive and recursively enumerable functions Phrase-structure grammars
2
TM Computer read-only input tape read/write work tape δ: Q (Σ {ε}) Γ → (Q {h}) (Γ {L, R}) (Σ {ε}) input tape alphabet work tape alphabet → assume read head always moves right ← → write-only output tape → assume output head always moves right output tape alphabet work tape symbols states M input output # Σ
3
Partial Recursive functions Definition: A partial function f: Σ* → Δ* is partial recursive if it can be computed by a machine with input and output. If the machine doesn’t halt on input w, then f(w) = ↑ is undefined. Theorem: A function f is partial recursive iff its graph G f = { 〈 x, y 〉 : f(x) = y} is accepted by a machine. M xf(x)f(x) M 〈 x, y 〉 yes, if y = f(x)
4
Partial Recursive Proof: ( ⇒ ) Suppose there is a machine M which computes f. Here is a machine which accepts G f : Proof: ( ⇐ ) Suppose there is a machine M which accepts G f. Here is a machine which computes f: M x x, y =? y Only accepts when y = f(x). f(x)f(x) x, y print y y accept generator x M reject next k time bound guess Only prints when y = f(x). yes
5
Recursive Functions Definition: A (total) function f: Σ* → Δ* is (total) recursive if it can be computed by a TM with input and output. Note the machine must always halt. Theorem: A function f is recursive iff its graph G f = { 〈 x, y 〉 : f(x) = y} is decided by a machine. Proof: Same proof, except the time bound is not necessary. f(x) = y ⇔ M xy
6
Phrase-Structure Grammars A grammar with productions such that the left-hand side is any string of variables V and terminals T containing at least one variable: α → βα ∈ (V ∪ T)* \ T* β ∈ (V ∪ T)* We say γαδ ⇒ γβδ and define A ∈ V ⇒ * w ∈ T* as before. A context-sensitive grammar (CSG) has |β| ≥ |α|.
7
Context-Sensitive Grammar Example:equal numbers of three symbols. L = {w ∈ {a, b, c}* : w has an equal number of each} S → SABC | εA → aB → bC → c AB → BAAC → CABC → CB BA → ABCA → ACCB → BC Explanation: Every permutation can be generated by a product of adjacent transpositions (combinatorics).
8
TM → PSG Theorem: Every language accepted by a TM can be generated by a phrase-structure grammar. Proof: Take M = (Q, Σ, δ, s), # Σ is blank symbol, h Q is halt state. M accepts its input by erasing its tape. Suppose we have a grammar for generating strings. |T| = 3|Σ| + 2 S * w [ sn …… n ] where σ 1 … σ m = w σ1σ1 σ2σ2 σmσm s indicating the start state, and n indicating “no head”. The symbolsand, [, ] are variables σ Σ q Q {h} n Q {h} qn σσ “M in state q reading σ” “no head on this square”
9
TM → PSG Proof, cont. Add the following productions which will allow the grammar to keep track of the ID of M. ] ↔ n ] add or subtact as many blanks as desired # q → p if δ(q, a) = (p, b) ab qn → np if δ(q, a) = (p, R) abab nq → pn if δ(q, a) = (p, L) baba [ h ] → ε erase if tape is empty and M halts # □ a, b Σ q Q p Q {h}
10
PSG → TM Theorem: Every phrase-structure language can be accepted by some TM. Proof: We will construct a machine M with two tapes: (1) to hold the input, and (2) to hold a derivation α from the grammar. Starting with S on (2), non-deterministically do the following: (1) w (2) ←replace→ α β↓γβ↓γ i shift → or ←
11
PSG → TM Proof (A) Guess a position i in α to move to. AB R N finite control: (B) Guess a production β → γ of the grammar. (finite number of productions, finite number of choices): (C) If β appears in α at position i, replace β by γ by shifting over the remainder if necessary (α′). i.e. σ 1 … σ i −1 β α′ V TV T D L L A if match, R no match Repeat until this tape is all terminals. Then see if it matches the original input. (1) w (2) ←replace→ α β↓γβ↓γ shift → or ← i
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.