Docsity

Chomsky Normal Form & Turing Machines: Transforming Grammars & Understanding Turing, Summaries of Ethics

Partial preview of the text

Download Chomsky Normal Form & Turing Machines: Transforming Grammars & Understanding Turing and more Summaries Ethics in PDF only on Docsity!

Chomsky Normal Form

and

TURING MACHINES

TUESDAY Feb 4

CHOMSKY NORMAL FORM

A context-free grammar is in Chomsky normal

form if every rule is of the form:

A → BC

A → a

S → ε

B and C aren’t start variables

a is a terminal

S is the start variable

Any variable A that is not the start variable

can only generate strings of length > 0

Theorem: If G is in CNF, w ∈ L(G) and |w| > 0,

then any derivation of w in G has length 2|w| - 1

Proof (by induction on |w|):

Base Case: If |w| = 1, then any derivation of

w must have length 1 (A → a)

Inductive Step: (^) Assume true for any string

of length at most k ≥ 1, and let |w| = k+

Since |w| > 1, derivation starts with A → BC

So w = xy where B ⇒* x, |x| > 0 and C ⇒* y, |y| > 0

By the inductive hypothesis, the length of

any derivation of w must be

1 + (2|x| - 1) + (2|y| - 1) = 2(|x| + |y|) - 1

Theorem: Any context-free language

can be generated by a context-free

grammar in Chomsky normal form

“Can transform any CFG into

Chomsky normal form”

  1. Add a new start variable S 0

and add the rule S 0

→ S

S → 0S

S → T#T

T → ε

S

0

→ S

  1. Remove all A → ε rules

(where A is not S 0

For each occurrence of A on right

hand side of a rule, add a new rule

with the occurrence deleted

If we have the rule B → A, add

B → ε , unless we have

previously removed B → ε

S → T

  1. Remove unit rules A → B

Whenever B → w appears, add

the rule A → w unless this was

a unit rule previously removed

S → T#

S → #T

S →

S → ε

S → 01

S

0

→ ε

S

0

→ 0S

S → 0S

S → T#T

S → T#

S → #T

S →

S → 01

S

0

→ ε

S

0

→ 0S

S

0

→ T#T

S

0

→ T#

S

0

→ #T

S

0

S

0

  1. Convert all remaining rules into the

proper form:

S

0

→ 0S

S

0

→ A

1

A

2

A

1

A

2

→ SA

3

A

3

S

0

S

0

→ A

1

A

3

S → 01

S → A

1

A

3

TURING MACHINE

FINITE

STATE

CONTROL

INFINITE TAPE

I N P U T

q 0

A

q 1

TURING MACHINE

FINITE

STATE

CONTROL

INFINITE TAPE

I N P U T

q 0

q 1

A

0 → 0, R

read write move

→ , R

q accept

q reject

0 → 0 , R

→ , R

0 → 0 , R

→ , L

0 → 0, R

read write move

→ , R

q accept

0 → 0 , R

→ , R

0 → 0 , R

→ , L

Definition: A Turing Machine is a 7-tuple

T = (Q, Σ , Γ , δ, q 0

, q accept

, q reject

), where:

Q is a finite set of states

Γ is the tape alphabet, where ∈ Γ and Σ ⊆ Γ

q 0

∈ Q is the start state

Σ is the input alphabet, where ∉ Σ

δ : Q × Γ → Q × Γ × {L, R}

q accept

∈ Q is the accept state

q reject

∈ Q is the reject state, and q reject

≠ q accept

CONFIGURATIONS

11010 q

q 7

corresponds to:

A Turing Machine M accepts input w if there is a

sequence of configurations C 1

, … , C

k

such that

1. C

1

is a start configuration of M on input w, ie C 1

is q 0

w

  1. each C i

yields C i+

, ie M can legally go from C i

to

C

i+

in a single step

3. C

k

is an accepting configuration, ie the state of

the configuration is q accept

A TM recognizes a language iff it accepts all

and only those strings in the language

A TM decides a language L iff it accepts all

strings in L and rejects all strings not in L

A language L is called Turing-recognizable

or recursively enumerable or semi-decidable

iff some TM recognizes L

A language L is called decidable or recursive

iff some TM decides L