filelanguage and automata 11

Embed Size (px)

Citation preview

  • 8/14/2019 filelanguage and automata 11

    1/5

  • 8/14/2019 filelanguage and automata 11

    2/5

    W e p r o v e t h e r e i s n o C p r o g r a m t o s o l v e t h a t

    p r o b l e m b y s u p p o s i n g t h a t t h e r e w e r e s u c h a

    p r o g r a m H t h e h e l l o - w o r l d - t e s t e r . "

    3 H t a k e s a s i n p u t a C p r o g r a m P a n d a n

    i n p u t l e I f o r t h a t p r o g r a m a n d t e l l s

    w h e t h e r P w i t h i n p u t I p r i n t s h e l l o

    w o r l d " b y w h i c h w e m e a n i t d o e s s o a s

    t h e r s t 1 3 c h a r a c t e r s .

    M o d i f y H t o a n e w p r o g r a m H

    1

    t h a t a c t s l i k e

    H b u t w h e n H p r i n t s n o H

    1

    p r i n t s h e l l o ,

    w o r l d .

    3 R e q u i r e s s o m e t h o u g h t : w e n e e d t o

    n d w h e r e n o i s p r i n t e d a n d c h a n g e t h e

    p r i n t f s t a t e m e n t .

    M o d i f y H

    1

    t o H

    2

    . T h i s p r o g r a m t a k e s o n l y

    o n e i n p u t P a n d a c t s l i k e H

    1

    w i t h b o t h i t s

    p r o g r a m a n d d a t a i n p u t s e q u a l t o P

    3 I . e . H2

    P = H

    1

    P P

    3 R e q u i r e s m o r e t h o u g h t : H2

    m u s t b u e r

    i t s i n p u t s o i t c a n b e u s e d a s b o t h t h e P

    a n d I i n p u t s t o H

    1

    H

    2

    c a n n o t e x i s t . I f i t d i d w h a t w o u l d H

    2

    H

    2

    d o ?

    3 I f H2

    H

    2

    = y e s t h e n H

    2

    g i v e n H

    2

    a s

    i n p u t e v i d e n t l y d o e s n o t p r i n t h e l l o ,

    w o r l d . B u t H

    2

    H

    2

    = H

    1

    H

    2

    H

    2

    =

    H H

    2

    H

    2

    a n d H

    1

    p r i n t s y e s i f a n d o n l y

    i f i t s r s t i n p u t g i v e n i t s s e c o n d i n p u t a s

    d a t a p r i n t s h e l l o , w o r l d . T h u s H

    2

    H

    2

    = y e s i m p l i e s H

    2

    H

    2

    = h e l l o , w o r l d .

    3 B u t i f H2

    H

    2

    = h e l l o , w o r l d . t h e n

    H

    1

    H

    2

    H

    2

    = h e l l o , w o r l d . a n d

    H H

    2

    H

    2

    = n o . T h u s H

    2

    H

    2

    =

    h e l l o , w o r l d . i m p l i e s H

    2

    H

    2

    6= h e l l o ,

    w o r l d .

    T h e T M

    F i n i t e - s t a t e c o n t r o l l i k e P D A .

    O n e r e a d - w r i t e t a p e s e r v e s a s b o t h i n p u t a n d

    u n b o u n d e d s t o r a g e d e v i c e .

    3 T a p e d i v i d e d i n t o c e l l s

    3 E a c h t a p e h o l d s o n e s y m b o l f r o m t h e t a p e

    a l p h a b e t

    3T a p e i s s e m i - i n n i t e " ; i t e n d s o n l y a t t h e

    l e f t .

    2

  • 8/14/2019 filelanguage and automata 11

    3/5

    T a p e h e a d m a r k s t h e c u r r e n t " c e l l w h i c h i s

    t h e o n l y c e l l t h a t c a n i n u e n c e t h e m o v e o f

    t h e T M .

    I n i t i a l l y t a p e h o l d s a

    1

    a

    2

    a

    n

    B B w h e r e

    a

    1

    a

    2

    a

    n

    i s t h e i n p u t c h o s e n f r o m a n i n p u t

    a l p h a b e t s u b s e t o f t h e t a p e a l p h a b e t a n d B

    i s t h e b l a n k

    F o r m a l T M

    M = Q , ; ; q

    0

    ; B ; F w h e r e :

    Q = n t e s e t o f s t a t e s .

    , = t a p e a l p h a b e t ; , = i n p u t a l p h a b e t .

    B i n , , = b l a n k .

    q

    0

    i n Q = s t a r t s y m b o l ; F Q = a c c e p t i n g

    s t a t e s .

    t a k e s a s t a t e a n d t a p e s y m b o l r e t u r n s a n e w

    s t a t e r e p l a c e m e n t s y m b o l e i t h e r m i g h t n o t

    c h a n g e a n d a d i r e c t i o n L = R f o r h e a d m o t i o n .

    E x a m p l e

    N o n t r i v i a l e x a m p l e s a r e h a r d t o c o m e b y . H e r e ' s a

    T M t h a t c h e c k s i t s t h i r d s y m b o l i s 0 a c c e p t s i f s o

    a n d r u n s f o r e v e r i f n o t .

    M = f p ; q ; r ; s ; t g f 0 1 g f 0 1 B g ; p ; B ; f s g

    1 p X = q ; X ; R f o r X = 0 1

    2 q X = r ; X ; R f o r X = 0 1

    3 r 0 = s 0 L

    4 r 1 = t 1 R

    5 t X = t ; X ; R f o r X = 0 1 B

    I D ' s o f a T u r i n g M a c h i n e

    T h e I D i n s t a n t a n e o u s d e s c r i p t i o n c a p t u r e s w h a t

    i s g o i n g o n a t a n y m o m e n t : t h e c u r r e n t s t a t e t h e

    c o n t e n t s o f t h e t a p e a n d t h e p o s i t i o n o f t h e t a p e

    h e a d .

    K e e p t h i n g s n i t e b y d r o p p i n g a l l s y m b o l s t o

    t h e r i g h t o f t h e h e a d a n d t o t h e r i g h t o f t h e

    r i g h t m o s t n o n b l a n k .

    3 S u b t l e p o i n t : a l t h o u g h t h e r e i s n o l i m i t

    o n h o w f a r r i g h t t h e h e a d m a y m o v e a n d

    w r i t e n o n b l a n k s a t a n y n i t e t i m e t h e

    T M h a s v i s i t e d o n l y a n i t e p r e x o f t h e

    i n n i t e t a p e .

    3

  • 8/14/2019 filelanguage and automata 11

    4/5

    N o t a t i o n : q s a y s :

    3 i s t h e t a p e c o n t e n t s t o t h e l e f t o f t h e

    h e a d .

    3 T h e s t a t e i s q

    3 i s t h e n o n b l a n k t a p e c o n t e n t s a t o r t o

    t h e r i g h t o f t h e t a p e h e a d .

    O n e m o v e i n d i c a t e d b y ; z e r o o n e o r m o r e

    m o v e s r e p r e s e n t e d b y

    *

    3 C h e c k t h e r e a d e r f o r t h e d e t a i l e d

    d e n i t i o n o f

    E x a m p l e

    W i t h i n p u t 0 1 0 1 t h e s e q u e n c e o f I D ' s o f t h e T M

    i s p 0 1 0 1 0 q 1 0 1 0 1 r 0 1 0 s 1 0 1 .

    A t t h a t p o i n t i t h a l t s s i n c e s t a t e s h a s n o

    m o v e w h e n t h e h e a d i s s c a n n i n g 1 .

    W i t h i n p u t 0 1 1 1 t h e s e q u e n c e i s : p 0 1 1 1 0 q 1 1 1

    0 1 r 1 1 0 1 1 t 1 0 1 1 1 t 0 1 1 1 B t `

    T h e T M n e v e r h a l t s b u t c o n t i n u e s t o m o v e

    r i g h t .

    A c c e p t a n c e b y F i n a l S t a t e a n d b y H a l t i n g

    O n e w a y t o d e n e t h e l a n g u a g e o f a T M i s b y

    t h e s e t o f i n p u t s t r i n g s t h a t c a u s e i t t o r e a c h a n

    a c c e p t i n g s t a t e .

    L M = f w q

    0

    w

    *

    p f o r s o m e p i n F a n d

    a n y a n d i n ,

    g

    A n o t h e r w a y i s t o d e n e t h e s e t o f s t r i n g s t h a t

    c a u s e t h e T M t o h a l t = h a v e n o n e x t m o v e .

    H M = f w q

    0

    w

    *

    p X a n d p X i s n o t

    d e n e d g

    3 S u b t l e p o i n t : a T M c a n a p p e a r t o h a l t i f

    t h e n e x t m o v e w o u l d t a k e t h e h e a d o t h e

    l e f t e n d o f t h e t a p e .

    3 G i v e n a n y T M w e c a n m a r k t h e l e f t e n d

    s o t h a t n e v e r h a p p e n s ; i . e . w e p r o d u c e

    a m o d i e d T M t h a t a c c e p t s t h e s a m e

    l a n g u a g e a n d h a l t s r a t h e r t h a n f a l l o

    t h e l e f t e n d .

    E x a m p l e

    T h e T M M o f o u r p r e v i o u s e x a m p l e h a s L M

    e q u a l t o t h o s e s t r i n g s i n t h e l a n g u a g e o f R E

    0 + 1 0 + 1 0 0 + 1

    4

  • 8/14/2019 filelanguage and automata 11

    5/5

    H M i s t h e l a n g u a g e o f + 0 + 1 + 0 + 1 0 +

    1 + 0 + 1 0 + 1 0 0 + 1

    E q u i v a l e n c e o f A c c e p t a n c e b y F i n a l S t a t e

    a n d H a l t i n g

    W e n e e d t o s h o w L i s L M

    1

    f o r s o m e T M M

    1

    i f

    a n d o n l y i f L i s H M

    2

    f o r s o m e T M M

    2

    I f

    M o d i f y M

    2

    a s f o l l o w s :

    1 . I n t r o d u c e o n e a c c e p t i n g s t a t e r

    2 . W h e n e v e r t h e r e i s n o t r a n s i t i o n f o r M

    2

    o n

    s t a t e q a n d s y m b o l X a d d a t r a n s i t i o n t o

    s t a t e r m o v i n g r i g h t s o w e c a n ' t p o s s i b l y f a l l

    o t h e l e f t e n d a n d l e a v i n g s y m b o l X

    O n l y - I f

    R o u g h l y w e l e t M

    2

    s i m u l a t e M

    1

    b u t i f M

    1

    e n t e r s

    a n a c c e p t i n g s t a t e M

    2

    h a s n o n e x t m o v e a n d s o

    h a l t s .

    M a j o r p r o b l e m : M

    1

    c o u l d h a l t w i t h o u t

    a c c e p t i n g .

    3 T o a v o i d t h i s p r o b l e m i n t r o d u c e s t a t e r

    t h a t m o v e s r i g h t o n e v e r y s y m b o l s t a y i n g

    i n s t a t e r a n d l e a v i n g t h e t a p e s y m b o l s

    u n c h a n g e d .

    3 G i v e M2

    a t r a n s i t i o n t o r m o v i n g r i g h t

    o n e v e r y s t a t e - s y m b o l c o m b i n a t i o n t h a t

    d o e s n o t h a v e a r u l e .

    A l s o r e m o v e a l l t r a n s i t i o n s w h e r e t h e s t a t e i s

    a n a c c e p t i n g s t a t e o f M

    1

    s o M

    2

    w i l l h a l t i n

    t h o s e s i t u a t i o n s .

    F a l l i n g O t h e L e f t E n d o f T a p e

    T h e r e a d e r t a l k s a b o u t t h e f u n n y s i t u a t i o n w h e r e

    t h e T M w o u l d h a l t b u t f a l l s o t h e l e f t e n d o f

    t a p e .

    T h i s s i t u a t i o n i s n o t h a l t i n g .

    N e i t h e r d o e s a T M a c c e p t i f i t t r i e s t o e n t e r

    a n a c c e p t i n g s t a t e a s i t f a l l s o t h e l e f t e n d .

    W e c a n p r e v e n t f a l l i n g o t h e l e f t e n d b y

    m a r k i n g t h e l e f t m o s t c e l l a s i n t h e r e a d e r .

    B u t i t a p p e a r s w e d o n o t n e e d t o d o

    s o i n o r d e r t o p r o v e t h e e q u i v a l e n c e o f

    h a l t i n g a c c e p t i n g s i n c e n e i t h e r o c c u r s w h e n

    t h e T M f a l l s o t h e l e f t e n d .

    5