Chapter 5 Computable functions Phrasestructure grammars Computers input
Chapter 5 Computable functions Phrase-structure grammars
Computers input M output What does it mean for a machine to compute a (partial) function? • Read-only input tape (assume head always moves to the right) • A read-write work tape (heads moves bi-directionally) • Write-only output tape (assume include head always moves right) δ : Q × (Σ ∪ {ε}) × Γ → (Q ∪ {h}) × (Γ ∪ {L, R}) × (Σ ∪ {ε}) # ∈ Σ = input/output alphabet; L, R ∉ Γ = work alphabet 2/23/2021 Theory of Computation: Chapter 5 2
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. x → M → f(x) Theorem: A function f is partial recursive iff its graph Gf = {�x, f(x)�} is accepted by a machine. �x, y� → M' → yes, if y = f(x) 2/23/2021 Theory of Computation: Chapter 5 3
Proof (partial recursive iff graph is acceptable) (⇒) Suppose there is a machine M (⇐) Suppose there is a machine M which computes f. Here is a which accepts Gf. Here is a machine which accepts Gf: machine which computes f: accept �x, y� x M f(x) =? yes x �x, y� time bound y y 2/23/2021 M Theory of Computation: Chapter 5 print y reject k generator next 4
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. x → M → f(x) Theorem: A function f is recursive iff its graph Gf = {�x, f(x)�} is decided by a machine. Proof: Almost the same proof, except the time bound is not necessary. 2/23/2021 Theory of Computation: Chapter 5 5
Summary of terminology Class name: Concept: Input only: (languages) Input/Output: (functions) Output only: (languages) 2/23/2021 Recursive always terminates decidable Recursively enumerable halts on success acceptable recursive partially recursive generatable enumerable Theory of Computation: Chapter 5 7
Phrase-Structure Grammars Definition: A grammar with arbitrary productions whose left-hand sides must contain at least one variable: α → β α ∈ (V ∪ T)* T* β ∈ (V ∪ T)* We say γαδ ⇒ γβδ and define A ∈ V ⇒* w ∈ T* as before. Note: A context-sensitive grammar (CSG) has |β| ≥ |α|. 2/23/2021 Theory of Computation: Chapter 5 8
Equal number of a ’s, b’s, and c’s L = {w ∈ {a, b, c}* : w has an equal number of each} S → SABC | ε A → a AB → BA BA → AB B→b C → c AC → CA BC → CB CA → AC CB → BC Explanation: Every permutation can be generated by a product of adjacent transpositions (a result from combinatorics). • This is a context-sensitive grammar. 2/23/2021 Theory of Computation: Chapter 5 9
Turing machine to phrase-structure grammar Theorem: Every language accepted by a TM can be generated by a phrase-structure grammar. Idea: Take M = �Q, Σ, δ, s� with blank symbol # ∈ Σ, and halt state h ∉ Q which accepts by erasing its tape. Let {qσ : q ∈ (Q ∪ {h}) and σ ∈ Σ} be variables representing cells of the tape containing σ where the head is present and M is in state q. Let {nσ : σ ∈ Σ} be variables representing cells of the tape without the head present, where n ∉ Q and n ≠ h. Let ‘[‘ and ‘]’ be variables indicating the beginning and end of the tape. Now suppose we have a grammar for generating all strings of the form: σ₁σ₂…σᵢ[sσ₁nσ₂…nσᵢ] 2/23/2021 Theory of Computation: Chapter 5 10
TM → PSG proof Keep track of the ID of M, where a, b ∈ Σ; q ∈ Q; p ∈ Q ∪ {h}, by rules: ] ↔ n#] qa → pb qanb → napb nbqa → pbna [h#] → ε 2/23/2021 add or remove as many blanks as desired if δ(q, a) = (p, b) if δ(q, a) = (p, R) if δ(q, a) = (p, L) erase if the tape is empty and M halts Theory of Computation: Chapter 5 11
Phrase-structure grammar to Turing machine Theorem: Every phrase-structure language is accepted by some TM. Proof: Construct a machine M with two tapes: (1) to hold the input; and (2) to hold a derivation α from the grammar. Start with S on (2), and non-deterministically repeat the following steps: • Choose a rule in the grammar β → γ (finitely many choices) • Search for an occurrence of β on tape (2). • Replace that occurrence of β by γ, shifting subsequent cells to the left or right to accommodate any difference in length between them. 2/23/2021 Theory of Computation: Chapter 5 12
PSG → TM Proof Guessing a rule β → γ in the grammar is easy (why? ). Finding an occurrence of β on the tape: R p β q Shifting cells over: (how? ) Repeat until tape (2) is all terminals. Then see if it matches tape (1). 2/23/2021 Theory of Computation: Chapter 5 13
- Slides: 12