Download presentation
Presentation is loading. Please wait.
Published byClaude Mathews Modified over 9 years ago
1
1 Computability Five lectures. Slides available from my web page http://www.dcs.gla.ac.uk/~muffy/teaching.html There is some formality, but it is gentle, have courage. The lectures that will change your life.
2
2 Computability What is a computer? What can the black box do? Which functions can be expressed as programs? Is there any limit to the kinds of programs you can write (except for your own proficiency at programming)? Operational approach Mathematical approach Alan Turing 1936 Alonzo Church 1936 Turing computable Effectively computable Church-Turing thesis Every computer algorithm can be implemented as a TM Black box Input x output f(x)
3
3 Some fundamentals What is a language? A set of (finite) strings/words over an alphabet. Most interesting languages are infinite, i.e. they consist of an infinite number of finite words. e.g. L = {a, aa, aaa, aaaa, aaaaa, …} How do you represent a language? What is a finite representation of an infinite language? (a grammar) (an algorithm which determines whether a word is in the language) Does there exist a finite representation for every language? (No) What can be said about the languages for which there is a finite representation? That’s the topic of these lectures!
4
4 More fundamentals What is an algorithm/procedure/mc? A procedure is a finite sequence of instructions that can be mechanically executed (on a mc). An algorithm is a procedure that terminates. Example procedures: determine whether or not an integer is a prime determine whether or not there is a perfect number greater than i (Perfect no is a no. which is equal to the sum of all divisors, e.g. 6 = 1+2+3)
5
5 Example procedures start start j=2 k=i is j>=i halt k=k+1 i is prime is i/j integer? halt sum=0 i is not prime j=j+1 j=1 is j<k does sum=k? j=j+1 is k/j halt integer? there is a perfect no>i sum=sum+j yes no yes no determine whether or not an integer is a prime determine whether or not there is a perfect number greater than i The lhs is an algorithm. Termination of the rhs depends on number theory: is there an infinite number of perfect numbers?
6
6 Questions - Design a mc/prog to recognise the language {a, aa, aaa, …} i.e. a +. - Design a mc/prog to recognise the language {aba, aabaa, aaabaaa, …} i.e. a n ba n. - Design a mc/prog to recognise the language {abc, aabbcc, aaabbbccc, …} i.e. a n b n c n. - Design a mc/prog to recognise whether or not a Java program has any type errors. - Design a mc/prog to recognise whether or not a Java program will terminate, for a given input. Aims of course: to answer these questions and give you an… –appreciation of which functions are computable –appreciation of link between languages and machines –appreciation of Chomsky hierarchy
7
7 Outline Lectures –Regular languages and FSA –Context-free, context-sensitive languages and Pushdown automata –Turing machines –Extended Turing machines, universal Turing machines –Halting problem, undecidability Tutorial –Surprise Disclaimer: These lecture notes are not pretty, nor animated, but they contain the core material!
8
8 Grammars and Languages A language is generated by a grammar, G= (N, T, P, S), consisting of T terminal symbols (alphabet, characters) e.g. {a,b} N nonterminal symbols (which stand for strings of characters) e.g. S, A P production rules (which describe how the language is generated) S a special start symbol. All sets are finite. Example -- Language {ab,abab, ababab, …} T = {a,b} N= {S} S = {S} P = S -> ab | abS | or S -> ab S -> abS A derivation of a string in L(G) is S => abS => ababS => ababab Another one is S => ab NB.Finite set of terminals, finite set of strings, but infinitely many strings. Much more in Prog. Lang. 3!
9
9 A Regular language is generated by a regular grammar G= (N, T, P, S) with restrictions on the form of productions 1. If there is an -production, then it has form S-> and S does not appear on the rhs of any other production 2. All other productions have form A -> a, A N, a T or A -> aB, A,B N, a T. Regular expressions (RE) are alternative way to define regular languages. Given an alphabet , is a RE. For all a , a RE. 2. If and are REs, then so too are U (union), (concatenation), and * (Kleene star). 3.No other string is a RE. If is a RE, then L( ) is defined by L( ) = { } L(a) = {a} for a L( U ) = L( ) U L( ) L( ) = {uv| u L( ),v L( )} L( *) = { } U U U e.g. L(a*b*) = { ,b,a, ab, aa, aab, abb, …}, ba L(a*b*) How do you know which strings are in this language? How do you recognise L(a*b*)? How do you compute L(a*b*)? grep == get RE pattern
10
10 Deterministic Finite State Automata (FSA) States Q and transition relation (Q x ) -> Q, represented as directed graph. Nodes represent states. Arrows represent the transitions and are labelled by characters from (input alphabet). Start state >. Accepting state(s). (favoured states or favored states, yuk) Accepts the language a n b m ( is {a,b}). Think of the input as a one-way, read-only tape a a b b b … NB. One automaton. Several automata. a a b a a b >
11
11 b a b a a Accepts the language of strings containing two consecutive a’s. (a*b*)* aa (a*b*)*. > b b a b a a Accepts the complement i.e. language of strings which do not containing two consecutive a’s. > b
12
12 FSAs recognise Regular languages; they are as expressive as each other. FSA Regular Languages (machine) (language) But what if we add nondeterminism to FSAs?
13
13 Nondeterminism can yield a more efficient machine, but it does not increase any computational power. Any nondeterministic FSA can be converted (by an algorithm) into a deterministic FSA. b b a A nondeterministic FSA to recognise strings which start and end with a b. i.e. b (a|b)* b. But this can be converted into a deterministic FSA: > b b a b > b a
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.