1.23k likes | 1.4k Views
Example. Find a DTM that computes the language L = { a n b n : n ≥ 0}. High level program: Repeat Erase an a. Pass along the rest of as. Erase a b Pass along the rest of bs . Go to the beginning of the input.
E N D
Example • Find a DTM that computes the language L = {anbn : n ≥ 0}. High level program: • Repeat • Erase an a. • Pass along the rest of as. • Erase a b • Pass along the rest of bs. • Go to the beginning of the input. • Until either the whole input is erased (accept) or you find unmatched as or bs (reject).
Example • Find a DTM that computes the language L = {anbn : n ≥ 0}. Answer: a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Testing Test the machine for several possible inputs to see if it works as it should. Test inputs: • ε (it should accept) • aaabbb (it should accept) • aaabb (it should reject) • aabbb (it should reject) • aabba (it should reject)
Test input: ε … … a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: ε … … a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … a a a b b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a b b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a b b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a b b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x a a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x b b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x a x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x b a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L
Test input: aaabbb … … x x x x x x a → a , R x → x , R x → x, R b → b , R a → x, R b → x, R q0 q1 q2 □ → □ , R □ → □ , L □ → □ , R qf q3 a → a , L b → b , L x → x , L