Reminder

• Final exam Unrestricted Grammars – The date for the Final has been decided:

– Saturday, November 16th – 12:30pm – 2:30pm – 07 – 1420

Homework Announcement

• Homework #7 • October 31st (today) is halloween – Help after lecture – Why isn’t anyone dressed as Kleene?!?!

– Refreshments at CS Offices • After this course

– Remember…valuable prizes.

Plan for today Before We Start

• Relating CFL to Recursive Languages • An example of computing a numerical – Unrestricted Grammars function with a TM

1 Computation with Turing Machines Computation with Turing Machines

• Computing functions with TMs • A TM that computes n mod 2 – Formally, – n is input on the tape as a sequence of n 1’s Σ Γ δ – Solution will be the number of 1’s remaining on the • Let T = (Q, , , q0, ) be a TM and let f be a partial function on Σ*. We say T computes f if for tape when the machine halts. every x ∈Σ* where f is defined: – Basic idea: ∆ * ∆ • Machine makes a pass from left to right to first blank. –(q0, x) a (h, f(x)) • And for every other x, T fails to halt on input x. • Move left, “erasing” 1’s two at a time • If n is odd, a single 1 will be left on the tape • Otherwise no 1’s will be left on the tape.

Computation with Turing Machines Computation with Turing Machines

• You know you want to see it… 1/1,R Odd # of 1’s – A final JFLAP run 1/ ∆,L ∆/ ∆,R ∆ ∆ ∆/ ∆,L / ,R ∆ / 1,L 1/ ∆,L

∆ / ∆,S

Move to right Even # of 1’s of string Read 1’s two by two

Grammars Languages

• Now back to our regularly scheduled • You are the weakest link! lecture. – What is a language? – What is a class of languages?

2 Now we have 2 pictures…this And this one… one

Context Free Languages Recursively Deterministic Context Free Languages Enumerable

Regular Languages Recursive

Finite Languages

How do these 2 relate

Unrestricted grammars Context Free Grammars

• To answer this we’ll have to take another • Let’s formalize this a bit: look at grammars. – A context free grammar (CFG) is a 4-tuple: (V, Σ, S, P) where • V is a set of variables • Σ is a set of terminals • V and Σ are disjoint (I.e. V ∩Σ= ∅) •S ∈V, is your start symbol

Context Free Grammars Context Free Grammars

• Let’s formalize this a bit: • Let’s formalize this a bit: – Production rules – Production rules →β •Of the form A where • We say that the grammar is context-free since this ∈ –A V substitution can take place regardless of where A is. – β∈(V ∪∑)* string with symbols from V and ∑ α⇒* γ γ α • We say that γ can be derived from α in one step: • We write if can be derived from in zero –A →βis a rule or more steps. α α α – = 1A 2 γ α βα – = 1 2 – α⇒γ

3 Unrestricted Grammars Unrestricted grammars

• With unrestricted grammars, there is no • Let’s formalize this a bit: restriction on the length of the left hand side – An unrestricted (or phase-structure) grammar is of a production. a 4-tuple: (V, Σ, S, P) where • The only rule is that the left hand side must • V is a set of variables contain at least 1 varaible • Σ is a set of terminals – Example: • V and Σ are disjoint (I.e. V ∩Σ= ∅) • ABC → aB •S ∈V, is your start symbol •Ba→ ACA •aAa → b

Unrestricted grammars Unrestricted grammar

• Let’s formalize this a bit: •Example – Production rules –L = { aibici | i ≥ 1 } note: this is not a CFL →Α •Of the form α→βwhere –S 1BCS1 | A1BC (1) → – α , β∈(V ∪∑)* string with symbols from V and ∑ –S1 ABCS1 | ABC (2) – α contains at least 1 variable. –BA → AB (3) CA → AC (4) •If α→βis a rule , we say that γ can be derived – CB → BC (5) cC → cc (6) from α in one step: –bC→ bc (7) bB → bb (8) – By replacing a occurrence of α on the right hand side with → → β –aB ab (9) aA aa (10) Α → – 1 a (11)

Unrestricted grammar Unrestricted grammar

• Derive aabbcc • Derive aabbcc →Α –S 1BCS1 (1) – → aABACBCBC →Α – 1BCABCS (2) – → aAABCBCBC (3) →Α – 1BCABCABC (2) – → aAABBCCBC (5) – → aBCABCABC (11) – → aAABBCBCC (5) – → aBACBCABC (4) – → aAABBBCCC (5) – → aABCBCABC (3) → – → aABCBACBC (4) – aaABBBCCC (10) → – → aABCABCBC (3) – aaaBBBCCC (10) – → aABACBCBC (4) – → aaabBBCCC (9)

4 Unrestricted grammar Context Sensitive Grammar

• Derive aabbcc • Context Sensitive Grammars – → aaabBBCCC – Productions – → aaabbBCCC (8) • α→β where α contains at least 1 variable – → aaabbbCCC (8) • And | α | ≤ | β | – → aaabbbcCC (7) – A variable can only be replaced in the context – → aaabbbccC (6) of other symbols – → aaabbbccc (6) – A language derived fron a context sensitive grammar is a context sensitive language. • Questions? • The last example was a context sensitive language

Context Sensitive Grammar It can be shown that:

• Do Context Sensitive Languages have a • Every Context Free Language is Context Sensitive corresponding machine ? – By definition of the grammars – Of course, all language classes do. • Every Context Sensitive Language is Recursive – Linear Bounded Automata – Minor modification to turn an LBA into a TM that • Like a TM except always halts. – Has two additional symbols 〈 and 〉 • There is a that is not Context 〈 〉 – The LBA’s starting configuration is (q0, x ) – The machine cannot move left of the 〈 or right of the 〉 Sensitive – An LBA can only use n cells on the tape where n is the – One of those strange diagonal type languages. size of the input string. –Captain Kirk → Robot → BOOM.

Our complete picture: Context Sensitive Languages Recursively Enumerable Recursive • Fun facts – Context Sensitive Languages are closed under Context Sensitive • Union, Intersection, and Concatenation… Context Free • If L is context sensitive, so is L+ Deterministic Context Free • Complement…Open question for quite some time – Turns out to be yes.

Finite • Still unknown if every CSL can be accepted by a Regular DETERMINISTIC Linear Bounded Automata.

5 Context Sensitive Languages It also can be shown:

• More fun facts • Every recursively enumerable language can – Most “practical” languages are context be generated by an unrestricted grammar. sensitive. • In fact, Chomksy (the grammar guy), set out • Programming languages to define the four language classes: • Spoken languages – Regular, CF, CS, Recursively Enumerable – By just using grammars.

Theory Hall of Fame (1956, 1959)

• Noam Chomsky – The Grammar Guy – 1928 – – b. Philadelphia, PA

– PhD – UPenn (1955) • Linguistics – Prof at MIT (Linguistics) (1955 - present)

– Probably more famous for his leftist political views.

Summary

• Unrestricted Grammars • Context Sensitive Grammars • Linear Bounded Automata • Chomsky Hierarchy

• Questions? – Next time…Computability

6