15

10.1.1.51.5266

Embed Size (px)

Citation preview

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 1/15

C o u n t i n g I s E a s y  

J o e l I . S e i f e r a s  

C o m p u t e r S c i e n c e D e p a r t m e n t  

U n i v e r s i t y o f R o c h e s t e r  

R o c h e s t e r , N e w Y o r k , U . S . A . 1 4 6 2 7  

P a u l M . B . V i t  a n y i  

C e n t r e f o r M a t h e m a t i c s a n d C o m p u t e r S c i e n c e  

P . O . B o x 4 0 7 9  

1 0 0 9 A B A m s t e r d a m , T h e N e t h e r l a n d s  

A u g u s t , 1 9 8 5 ; r e v i s e d S e p t e m b e r , 1 9 8 7 , a n d M a y , 1 9 8 8  

A b s t r a c t .   F o r a n y x e d   k  , a r e m a r k a b l y s i m p l e s i n g l e - t a p e T u r i n g m a c h i n e  

c a n s i m u l a t e   k  i n d e p e n d e n t c o u n t e r s i n r e a l t i m e .  

C a t e g o r i e s a n d S u b j e c t D e s c r i p t o r s :   F . 1 . 1 C o m p u t a t i o n b y A b s t r a c t  

D e v i c e s ] : M o d e l s o f C o m p u t a t i o n | r e l a t i o n s a m o n g m o d e l s ; b o u n d e d - a c t i o n d e -  

v i c e s ; E . 2 D a t a ] : D a t a S t o r a g e R e p r e s e n t a t i o n s | c o n t i g u o u s r e p r e s e n t a t i o n s ; F . 2 . 2  

A n a l y s i s o f A l g o r i t h m s a n d P r o b l e m C o m p l e x i t y ] : N o n n u m e r i c a l A l g o r i t h m s a n d  

P r o b l e m s | s e q u e n c i n g a n d s c h e d u l i n g ; G . 2 . 1 D i s c r e t e M a t h e m a t i c s ] : C o m b i n a t o r -  

i c s | c o m b i n a t o r i a l a l g o r i t h m s ; F . 2 . 2 A n a l y s i s o f A l g o r i t h m s a n d P r o b l e m C o m -  

p l e x i t y ] : T r a d e o s a m o n g C o m p l e x i t y M e a s u r e s  

G e n e r a l T e r m s :   T h e o r y , A l g o r i t h m s , D e s i g n , V e r i c a t i o n  

A d d i t i o n a l K e y W o r d s a n d P h r a s e s :   C o u n t e r , a b s t r a c t s t o r a g e u n i t ,  

c o u n t e r m a c h i n e , m u l t i c o u n t e r m a c h i n e , o n e - t a p e T u r i n g m a c h i n e , s i m u l a t i o n b e -  

t w e e n m o d e l s , r e a l - t i m e s i m u l a t i o n , o n - l i n e s i m u l a t i o n , o b l i v i o u s s i m u l a t i o n , r e d u n -  

d a n t n u m b e r r e p r e s e n t a t i o n , s i g n e d - d i g i t n u m b e r r e p r e s e n t a t i o n , r e c u r s i o n e l i m i -  

n a t i o n  

1 . I n t r o d u c t i o n  

I n t h i s p a p e r w e d e s c r i b e a r e m a r k a b l y s i m p l e r e a l - t i m e s i m u l a t i o n , b a s e d o n j u s t  

v e s i m p l e r e w r i t i n g r u l e s , o f a n y x e d n u m b e r   k  o f i n d e p e n d e n t c o u n t e r s . O n a T u r i n g  

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

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

t o (  k  +    ) l o g  

n  b i t s f o r t h e r s t   n  c o m m a n d s , f o r a n y s p e c i e d   >  0 . C o n s e q u e n c e s a n d  

a p p l i c a t i o n s a r e d i s c u s s e d i n 1 0 { 1 1 ] , w h e r e t h e r s t s i n g l e - t a p e , r e a l - t i m e s i m u l a t i o n o f  

m u l t i p l e c o u n t e r s w a s r e p o r t e d .  

I n f o r m a l l y , a   c o u n t e r   i s a s t o r a g e u n i t t h a t m a i n t a i n s a s i n g l e i n t e g e r ( i n i t i a l l y 0 ) , i n c r e -  

m e n t i n g i t , d e c r e m e n t i n g i t , o r r e p o r t i n g i t s s i g n ( p o s i t i v e , n e g a t i v e , o r z e r o ) o n c o m m a n d .  

T h e w o r k o f t h e r s t a u t h o r w a s s u p p o r t e d i n p a r t b y t h e N a t i o n a l S c i e n c e F o u n d a t i o n u n d e r  

g r a n t M C S - 8 1 1 0 4 3 0 .  

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 2/15

A n y a u t o m a t o n t h a t r e s p o n d s t o e a c h s u c c e s s i v e c o m m a n d a s a c o u n t e r w o u l d i s s a i d t o  

s i m u l a t e   a c o u n t e r . ( O n l y f o r a s i g n i n q u i r y i s t h e r e s p o n s e o f i n t e r e s t , o f c o u r s e . A n d  

z e r o n e s s i s t h e o n l y r e a l i s s u e , s i n c e a s i m u l a t o r c a n r e a d i l y u s e z e r o d e t e c t i o n t o k e e p t r a c k  

o f p o s i t i v i t y a n d n e g a t i v i t y i n n i t e - s t a t e c o n t r o l . ) T o s i m u l a t e   k  i n d e p e n d e n t c o u n t e r s ,  

a n a u t o m a t o n m u s t r e s p o n d t o 3  k  c o m m a n d s : \ i n c r e m e n t c o u n t e r n u m b e r   i  " , \ d e c r e m e n t  

c o u n t e r n u m b e r   i  " , a n d \ r e p o r t t h e s i g n o f c o u n t e r n u m b e r   i  " ( 1    i    k  ) . I f t h e r e i s s o m e  

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

r e c e i v e s , t h e n i t s i m u l a t e s i n   r e a l t i m e  . 

O u r r e a l - t i m e   k  - c o u n t e r s i m u l a t o r w i l l b e a   s i n g l e - t a p e T u r i n g m a c h i n e   . S u c h a n a u -  

t o m a t o n c o n s i s t s o f a n i t e - s t a t e c o n t r o l u n i t w i t h r e a d - w r i t e a c c e s s t o a n i n n i t e b u t  

i n i t i a l l y b l a n k b i n a r y s t o r a g e t a p e ( 0 i n e v e r y b i t p o s i t i o n ) . E a c h n e x t s t e p i s d e t e r m i n e d  

b y t h e c u r r e n t c o n t r o l s t a t e , t h e b i t c u r r e n t l y s c a n n e d b y t h e r e a d - w r i t e h e a d o n t h e s t o r a g e  

t a p e , a n d t h e m o s t r e c e n t l y r e c e i v e d i n p u t s y m b o l ( i n o u r c a s e , t h e l a s t c o m m a n d n o t y e t  

r e s p o n d e d t o ) . E a c h s t e p c a n i n v o l v e a n y o f t h e f o l l o w i n g a c t i o n s : a c h a n g e t o t h e b i t  

s c a n n e d b y t h e h e a d o n t h e s t o r a g e t a p e , a s h i f t l e f t o r r i g h t b y t h a t h e a d t o a n a d j a c e n t  

b i t p o s i t i o n , e m i s s i o n o f a n o u t p u t s y m b o l ( i n o u r c a s e , a c o m m a n d r e s p o n s e ) , a n d a s t a t e  

t r a n s i t i o n b y t h e n i t e - s t a t e c o n t r o l u n i t .  

A n a p p a r e n t l y s t r o n g e r n o t i o n o f r e a l - t i m e s i m u l a t i o n w o u l d r e q u i r e r e s p o n s e t o e a c h  

s u c c e s s i v e c o m m a n d j u s t   o n e  s t e p a f t e r s u b m i s s i o n . I n t h e s p e c i a l c a s e o f   c o u n t e r   s i m u l a t i o n ,  

h o w e v e r ,   a n y  r e a l - t i m e s i m u l a t i o n a c t u a l l y d o e s a l s o y i e l d a r e a l - t i m e s i m u l a t i o n i n w h i c h  

t h e c o m m a n d - r e s p o n s e d e l a y i s j u s t 1 . ( I t i s w e l l k n o w n t h a t a l a r g e r d e l a y c a n b e \ s w e p t  

u n d e r t h e r u g " b y i n c r e a s i n g t h e s i z e o f t h e a l p h a b e t u s e d o n t h e s t o r a g e t a p e , b u t t h a t i s  

n o t n e c e s s a r y i n o u r c a s e . )  

P r o p o s i t i o n .   I f a s i n g l e - t a p e T u r i n g m a c h i n e c a n s i m u l a t e   k  c o u n t e r s i n r e a l t i m e w i t h  

c o m m a n d - r e s p o n s e d e l a y b o u n d   d  , t h e n a s i m i l a r s i n g l e - t a p e T u r i n g m a c h i n e ( s t i l l w i t h o n l y  

b i n a r y t a p e a l p h a b e t ) c a n d o s o w i t h d e l a y b o u n d   1  . 

P r o o f :   T h e r o u g h i d e a i s f o r t h e d e l a y - 1 s i m u l a t i o n t o u s e a d e l a y -  d  s i m u l a t i o n t o s t o r e a n  

a p p r o p r i a t e    f r a c t i o n   o f e a c h o f i t s c o u n t e r s ' c o n t e n t s , a n d t o m a i n t a i n a l l t h e r e m a i n d e r s i n  

n i t e - s t a t e c o n t r o l .  

M o r e a c c u r a t e l y a n d p r e c i s e l y , t h e d e l a y - 1 s i m u l a t i o n c a n o p e r a t e i n \ p h a s e s " o f 2  k d 

s t e p s , m a i n t a i n i n g t h e f o l l o w i n g i n v a r i a n t f r o m p h a s e t o p h a s e , f o r t h e a b s o l u t e v a l u e   j  c  j  o f 

e a c h c o u n t   c  : 

j  c  j  =  c 

+  c 

( 2  k d  )  ; 

w h e r e e i t h e r  

>  0 a n d 2  k d    c 

  8  k d ; 

o r 

= 0 a n d 0    c 

  8  k d ; 

a n d w h e r e   c 

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

a r e s t o r e d i n n i t e - s t a t e c o n t r o l , a n d   c 

i s s t o r e d  

i n t h e c o r r e s p o n d i n g c o u n t e r o f t h e d e l a y -  d  s i m u l a t i o n . T h e 2  k d  c o m m a n d s r e c e i v e d i n  

e a c h p h a s e c a n b e h a n d l e d w i t h i n n i t e - s t a t e c o n t r o l , i n c r e a s i n g o r d e c r e a s i n g e a c h   c 

b y 

a t m o s t 2  k d  . M e a n w h i l e , t h e 2  k d  s t e p s a r e e n o u g h f o r o n e i n c r e m e n t o r d e c r e m e n t o f a n d  

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

. I n e a c h c a s e , t h e s i m u l a t i o n s h o u l d   i n c r e m e n t   c 

, a s p a r t o f a  

\ c a r r y " f r o m   c 

, i f  c 

>  6  k d  h e l d w h e n t h e p h a s e b e g a n ; a n d i t s h o u l d   d e c r e m e n t   c 

, a s p a r t  

o f a \ b o r r o w " f o r   c 

, i f  c 

<  4  k d  h e l d w h e n t h e p h a s e b e g a n , u n l e s s   c 

w a s a l r e a d y z e r o . F o r  

e a c h c o u n t , i f   c 

w a s p o s i t i v e w h e n t h e p h a s e b e g a n , t h e n 2  k d    c 

  8  k d  w i l l h o l d w h e n i t  

e n d s . I f   c 

w a s z e r o w h e n t h e p h a s e b e g a n , h o w e v e r ,  c 

m i g h t \ u n d e r o w " a l m o s t t o   ?  2  k d  ; 

b u t , i n t h a t c a s e ,   c 

w i l l r e m a i n z e r o , s o t h a t a s i g n c h a n g e i n n i t e - s t a t e c o n t r o l w i l l s u c e  

t o r e s t o r e t h e i n v a r i a n t . F i n a l l y , n o t e t h a t t h e r e w i l l a l w a y s b e e n o u g h i n f o r m a t i o n i n n i t e -  

s t a t e c o n t r o l t o d e t e r m i n e w h e t h e r a c o u n t i s c u r r e n t l y z e r o : E a c h c o u n t w i l l b e z e r o j u s t  

w h e n i t s   c 

i s z e r o a n d i t s   c 

w a s z e r o w h e n t h e c u r r e n t p h a s e b e g a n .  

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 3/15

P r i o r t o t h e b r e a k t h r o u g h i n 1 0 { 1 1 ] , t h e r e w e r e a t l e a s t t h r e e w e a k e r s i m u l a t i o n s i n  

t h e l i t e r a t u r e . M . F i s c h e r a n d R o s e n b e r g 4 ] s h o w e d t h a t t h e s i m u l a t i o n i s p o s s i b l e i n t h e  

c a s e t h a t o n l y   s i m u l t a n e o u s   z e r o n e s s o f t h e   k  c o u n t e r s h a s t o b e r e p o r t e d . P . F i s c h e r ,  

M e y e r , a n d R o s e n b e r g 5 ] s h o w e d t h a t a f u l l s i m u l a t i o n i s p o s s i b l e i n c u m u l a t i v e   l i n e a r  

t i m e ( i . e . , w i t h   a v e r a g e   d e l a y b o u n d e d b y a c o n s t a n t , b u t w i t h n o x e d b o u n d o n t h e  

d e l a y f o r e a c h i n d i v i d u a l c o m m a n d ) . A w h i l e l a t e r , t h e l a t t e r a u t h o r s s h o w e d t h a t    f o u r  

T u r i n g - m a c h i n e t a p e s a r e a s e c i e n t a s   k  c o u n t e r s , f o r   s e q u e n c e g e n e r a t i o n   6 ] . F  u r e r ' s  

f u l l l i n e a r - t i m e s i m u l a t i o n 7 ] r e q u i r e s m o r e t h a n o n e t a p e , b u t t w o s u c e   e v e n i f t h e y a r e  

o t h e r w i s e o c c u p i e d  . 

2 . A P e e k a t a n O b l i v i o u s S o l u t i o n  

U s i n g a s t r a i g h t f o r w a r d u n a r y , o r \ t a l l y " , n o t a t i o n , a n a u t o m a t o n w i t h j u s t o n e s t o r a g e  

t a p e ( i . e . , a s i n g l e - t a p e T u r i n g m a c h i n e ) o b v i o u s l y c a n s i m u l a t e a s i n g l e c o u n t e r i n r e a l t i m e .  

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

s p a c e o n t h e s t o r a g e t a p e 4 ] .  

T o s i m u l a t e m o r e t h a n o n e c o u n t e r i n r e a l t i m e u s i n g a s i n g l e t a p e i s m u c h h a r d e r . F o r  

a n y  k  , i n f a c t , i t i s h a r d t o i m a g i n e h o w f e w e r t h a n   k  s e p a r a t e t a p e s c a n s u c e t o s i m u l a t e  

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

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

t h e s e p a r a t e c o u n t e r s s e p a r a t e l y , s a y o n   k  s e p a r a t e \ t r a c k s " o f t h e o n e a v a i l a b l e t a p e . T h e  

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

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

s i m u l a t e d c o u n t e r s .  

E a c h \ s e p a r a t e h a n d l i n g " a b o v e i s e s s e n t i a l l y a r e a l - t i m e s i m u l a t i o n o f o n e c o u n t e r .  

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

c l e a r l y i f o u r c o u n t e r s a r e \ e n h a n c e d " t o h a n d l e o n e a d d i t i o n a l c o m m a n d , a c o m m a n d t o  

\ d o n o t h i n g " . ( A n y e c i e n t s i m u l a t i o n o f a n u n e n h a n c e d c o u n t e r t r i v i a l l y y i e l d s a n e c i e n t  

s i m u l a t i o n o f a n e n h a n c e d o n e , a n y w a y : S i m p l y h a n d l e e a c h \ d o n o t h i n g " a s i f i t w e r e a n  

\ i n c r e m e n t " f o l l o w e d b y a \ d e c r e m e n t " . ) T h e n w e c a n v i e w e a c h c o m m a n d t o a m u l t i p l e -  

c o u n t e r s t o r a g e u n i t a s a t u p l e o f c o m m a n d s , o n e t o e a c h s e p a r a t e c o u n t e r . W h a t w e n e e d ,  

t h e r e f o r e , i s a r e a l - t i m e s i n g l e - c o u n t e r s i m u l a t i o n t h a t i s \ o b l i v i o u s " i n t h e s e n s e t h a t n e i t h e r  

i t s h e a d p o s i t i o n n o r i t s t i m e s o f i n t e r a c t i o n w i t h t h e o u t s i d e w o r l d ( t o r e s p o n d t o c o m m a n d s  

a n d t o r e c e i v e n e w o n e s ) d e p e n d a t a l l o n t h e p a r t i c u l a r c o m m a n d s e q u e n c e . O u r r e a l - t i m e  

s i m u l a t i o n o f a   k  - c o u n t e r s t o r a g e u n i t i s i n d e e d b a s e d o n p e r f o r m i n g , o n a s e p a r a t e t r a c k  

o f t h e o n e a v a i l a b l e s t o r a g e t a p e , j u s t s u c h a s i m u l a t i o n f o r e a c h o f t h e   k  s i m u l t a n e o u s  

c o m m a n d s t r e a m s .  

I n t h e r e s t o f t h i s s e c t i o n , w i t h o u t f u r t h e r m o t i v a t i o n , w e p r e v i e w t h e e n t i r e o b l i v i o u s  

s i m u l a t i o n o f a s i n g l e c o u n t e r . I n t h e f o l l o w i n g s e c t i o n s , o n t h e o t h e r h a n d , w e w i l l r e t u r n  

t o a n e v o l u t i o n a r y t o p - d o w n d e v e l o p m e n t o f t h e s i m u l a t i o n , w i t h e a c h s u c c e s s i v e r e n e m e n t  

m o t i v a t e d b y s o m e o u t s t a n d i n g i n a d e q u a c y o r l o o s e e n d . H a v i n g p r e v i e w e d t h e n a l c o n c r e t e  

r e s u l t , t h e r e a d e r w i l l b e t t e r a p p r e c i a t e t h e d i r e c t i o n a n d p r o g r e s s o f t h a t e v o l u t i o n .  

F o r t r a n s p a r e n c y , w e a c t u a l l y i m p l e m e n t o u r o b l i v i o u s o n e - c o u n t e r s i m u l a t i o n o n a  

s i n g l e - t a p e T u r i n g m a c h i n e m o d e l t h a t i s a p p a r e n t l y s t r o n g e r t h a n t h e o n e d e n e d a b o v e .  

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

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

s o m e s m a l l   n e i g h b o r h o o d   o f t h e h e a d p o s i t i o n o n t h e s t o r a g e t a p e . B y c o d i n g i n b i n a r y , a n d  

b y c o n c e d i n g a s o m e w h a t l a r g e r ( b u t s t i l l x e d ) b o u n d o n c o m m a n d - r e s p o n s e d e l a y t i m e ,  

h o w e v e r , w e c o u l d s t r a i g h t f o r w a r d l y r e p l a c e a n y s u c h o b l i v i o u s r e a l - t i m e s i m u l a t o r b y a n  

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

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 4/15

E a c h n o n b l a n k s t o r a g e t a p e s y m b o l u s e d b y t h e s i m u l a t o r i n c l u d e s a b a s e s y m b o l f r o m  

t h e s e t   f  - 3  ;  - 2  ;  - 1  ;  0  ;  1  ;  2  ;  3  ;  g  a n d a l e f t o r r i g h t o v e r a r r o w . O p t i o n a l l y , i t c a n a l s o i n c l u d e a n  

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

o f t h e r e a d - w r i t e h e a d . T h e i n i t i a l s t o r a g e c o n t e n t s i s t r e a t e d a s i f i t w e r e  

 

? ! 

 

? ! 

? ! 

? ! 

0    : 

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

t h i n g i n n i t e - s t a t e c o n t r o l | a s i n g l e s t a t e w i l l s u c e . T h e r e f o r e , s i n c e e v e n t h e h e a d  

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

a s e t o f c o n t e x t - s e n s i t i v e r u l e s f o r r e w r i t i n g t h e s t o r a g e t a p e . W e p r o m i s e d v e s u c h r u l e s ,  

b u t t h e y a r e a c t u a l l y v e e n t i r e   s c h e m e s  : 

  c 

? ! 

  b c 

? ! 

  c  )  c 

? ! 

 

b  , p r o p a g a t i n g i n t o   b  , a n d t h e n f r o m   b  t o  c 

  c  )  a c 

0 0 

? ! 

 

b  , p r o p a g a t i n g i n t o   b  , a n d t h e n f r o m   b  t o  a 

  c 

0 0 

d  )  b 

 

? ! 

d c 

, p r o p a g a t i n g f r o m   d  t o  c 

  c 

0 0 

? ! 

d e  )  b 

 

? ! 

d c 

0 0 

e  , p r o p a g a t i n g f r o m   d  t o  e 

E a c h o f   a  ,  b  ,  c  ,  d  , a n d   e  c a n b e a n y m e m b e r o f   f  - 3  ;  - 2  ;  - 1  ;  0  ;  1  ;  2  ;  3  g  . E x c e p t o n t h e s y m b o l  

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

n o t s h o w n a r e u n c h a n g e d b y t h e t r a n s i t i o n s . T h e m i r r o r - i m a g e r e e c t i o n s o f t h e r u l e s  

d e s c r i b e t h e t r a n s i t i o n s w h e n     l i e s b e n e a t h a   r i g h t   a r r o w ; t h u s , f o r e x a m p l e , t h e v e r y r s t  

t r a n s i t i o n i s a c c o r d i n g t o t h e r s t o f t h e v e s c h e m e s , y i e l d i n g  

 

? ! 

 

? ! 

? ! 

0    : 

N o t e t h a t t h e r u l e f o r e a c h n e x t t r a n s i t i o n w i l l b e d e t e r m i n e d b y t h e n u m b e r o f p r i m e s  

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

w i l l b e d e t e r m i n e d b y t h e d i r e c t i o n o f t h e a r r o w o v e r     . I t r e m a i n s o n l y t o g i v e t h e r u l e s  

f o r i n f o r m a t i o n \ p r o p a g a t i o n " , f o r m a i n t e n a n c e o f t h e u n d e r l i n e s ( n o t s h o w n i n t h e r u l e  

s c h e m e s ) , a n d f o r g e n e r a t i o n o f r e s p o n s e s t o t h e c o m m a n d s .  

\ P r o p a g a t i o n f r o m   b  t o  c  " i s e s s e n t i a l l y a \ c a r r y " o r \ b o r r o w " o p e r a t i o n : I f   b  i s 3 , t h e n  

r e d u c e i t b y 4 ( t o - 1 ) a n d a d d 1 t o   c  . I f  b  i s - 3 , t h e n i n c r e a s e i t b y 4 ( t o 1 ) a n d s u b t r a c t 1  

f r o m   c  . I f e i t h e r o f t h e s e a c t i o n s c h a n g e s   c  t o  0 , a n d   c  w a s n o t u n d e r l i n e d , t h e n r e m o v e t h e  

u n d e r l i n e f r o m   b  ; a n d , i f e i t h e r a c t i o n c h a n g e s   c   f r o m   0 , a n d   b  w a s n o t u n d e r l i n e d , t h e n a d d  

a n u n d e r l i n e t o   b  . L e a v e a l l o t h e r u n d e r l i n i n g u n c h a n g e d .  

\ P r o p a g a t i o n i n t o   b  " d e p e n d s o n t h e n e x t i n p u t c o m m a n d . O n a c o m m a n d t o i n c r e m e n t  

o r d e c r e m e n t t h e c o u n t e r ,   b  i s i n c r e m e n t e d o r d e c r e m e n t e d a c c o r d i n g l y . T h e r e s u l t i s a c o u n t  

o f z e r o i f a n d o n l y i f t h e r e s u l t i n g   b  i s 0 , w i t h o u t a n u n d e r l i n e .  

T h e d e l a y b e t w e e n t h e h a n d l i n g o f s u c c e s s i v e i n p u t c o m m a n d s i s a t m o s t t h r e e s t e p s ,  

c o u n t s o f z e r o a r e d e t e c t e d c o r r e c t l y , a n d n o b a s e s y m b o l i s e v e r r e q u i r e d t o o v e r o w p a s t 3  

o r t o u n d e r o w p a s t - 3 , a l t h o u g h t h e s e f a c t s a r e n o t a t a l l c l e a r f r o m j u s t t h e r u l e s . I t   i s 

c l e a r f r o m t h e r u l e s t h a t t h e s i m u l a t i o n i s b o t h d e t e r m i n i s t i c a n d o b l i v i o u s .  

A s a n e x a m p l e , s u p p o s e e v e r y c o m m a n d i s t o   i n c r e m e n t   t h e c o u n t e r . T h e n t h e r e s u l t s  

o f t h e r s t s i x t r a n s i t i o n s a r e a s f o l l o w s :  

 

? ! 

 

? ! 

? ! 

? ! 

? ! 

0    ( b y r u l e 1 ) ,  

 

? ! 

? ! 

 

? ! 

? ! 

? ! 

0    ( b y r u l e 2 ) ,  

 

? ! 

 

? ! 

? ! 

? ! 

0    ( b y r u l e 1 ) ,  

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 5/15

 

? ! 

?! 

0 0 

? ! 

 

? ! 

? ! 

0    ( b y r u l e 3 ) ,  

 

? ! 

? ! 

 

? ! 

? ! 

0    ( b y r u l e 4 ) ,  

 

? ! 

? ! 

- 1 

 

? ! 

? ! 

0    ( b y r u l e 2 ) .  

C o n t i n u i n g i n t h i s w a y , t h e r e s u l t o f t h e r s t 2 , 9 8 0 , 0 0 0 t r a n s i t i o n s , i n c l u d i n g t h e e x e c u t i o n  

o f 1 , 1 9 1 , 9 9 3 c o m m a n d s t o i n c r e m e n t t h e c o u n t e r , i s  

 

? ! 

? ! 

? ! 

?! 

0 0 

? ! 

? ! 

? ! 

- 1 

0 0 

? ! 

 

? ! 

0 0 

? ! 

- 1 

? ! 

? ! 

0    : 

( F o r n o w , t h i s s h o u l d s e e m p r e t t y o b s c u r e a s a r e p r e s e n t a t i o n f o r 1 , 1 9 1 , 9 9 3 . I t w i l l t u r n o u t  

t h a t t h e b a s e s y m b o l s a r e a s c r a m b l e d r a d i x - 4 r e p r e s e n t a t i o n f o r t h a t n u m b e r :  

1 0 2 1 ( - 1 ) 0 0 1 ( - 1 ) 2 1  

 

1 1 9 1 9 9 3  

 

1 0 

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

r a d i x - 4 d i g i t s a r e s i g n i c a n t , e x c e p t t h a t t h e   l e a d i n g   s i g n i c a n t d i g i t i s   n o t  u n d e r l i n e d . ( I n  

a r a d i x n u m b e r , a d i g i t i s   s i g n i c a n t   a s l o n g a s i t i s n o t a l e a d i n g 0 . ) )  

3 . O b l i v i o u s C o u n t i n g  

T h e r e i s a r e l a t i v e l y f a m i l i a r t e c h n i q u e t h a t m a k e s i t p o s s i b l e t o m a i n t a i n a c o u n t e r  

o b l i v i o u s l y i n r e a l t i m e   i f  t h e o b l i v i o u s o r d e r o f p o s i t i o n a c c e s s c a n b e n o n s e q u e n t i a l . T h e  

o b l i v i o u s v e r s i o n 9 ] o f t h e c l a s s i c a l t w o - t a p e s i m u l a t i o n 8 ] o f m u l t i p l e T u r i n g - m a c h i n e t a p e s  

i s b a s e d i m p l i c i t l y o n t h e t e c h n i q u e . T h e t e c h n i q u e i n v o l v e s a l i b e r a l i z a t i o n o f o r d i n a r y x e d -  

r a d i x n o t a t i o n , a l l o w i n g a n e x p a n d e d r a n g e o f \ s i g n e d d i g i t s " i n e a c h p o s i t i o n 2 , 1 ] . T h i s ,  

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

p r o p a g a t i o n . T o m a i n t a i n s u c h a r e p r e s e n t a t i o n a s t h e r e p r e s e n t e d n u m b e r i s i n c r e m e n t e d  

a n d d e c r e m e n t e d , w e n e e d o n l y v i s i t t h e v a r i o u s p o s i t i o n s o f t e n e n o u g h t o a v o i d o v e r o w a n d  

u n d e r o w . T h e f o l l o w i n g t w o r e q u i r e m e n t s , w h i c h a r e o b l i v i o u s t o t h e p a r t i c u l a r s e q u e n c e  

o f c o m m a n d s , a r e s u c i e n t f o r s u c h a s c h e m e t o b e a b l e t o h a n d l e c o m m a n d s i n r e a l t i m e :  

1 . T h e r e i s a c h a n c e ( \ 0 - o p p o r t u n i t y " ) t o p r o p a g a t e i n f o r m a t i o n ( i n c r e m e n t s a n d d e c r e -  

m e n t s ) i n t o p o s i t i o n 0 a t l e a s t o n c e e v e r y   O  ( 1 ) s t e p s .  

2 . T h e r e i s a c h a n c e ( \ (  i  + 1 ) - o p p o r t u n i t y " ) t o p r o p a g a t e i n f o r m a t i o n ( c a r r i e s a n d b o r r o w s )  

f r o m p o s i t i o n   i  i n t o p o s i t i o n   i  + 1 a t l e a s t o n c e e v e r y   O  ( 1 ) t i m e s t h e r e i s a n   i  - o p p o r t u n i t y .  

T h e s e r e q u i r e m e n t s a r e m e t , f o r e x a m p l e , b y a s c h e d u l e t h a t p r o v i d e s a 0 - o p p o r t u n i t y e v e r y  

o t h e r s t e p , a 1 - o p p o r t u n i t y e v e r y o t h e r r e m a i n i n g s t e p , a 2 - o p p o r t u n i t y e v e r y o t h e r s t i l l  

r e m a i n i n g s t e p , e t c . :  

0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 5 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2   : : : :  

T h i s i s t h e s e q u e n c e o f c a r r y p r o p a g a t i o n d i s t a n c e s w h e n w e c o u n t i n b i n a r y , s o l e t u s c a l l  

i t t h e   b i n a r y c a r r y s c h e d u l e  . 

T o s e e t h a t t h e r e q u i r e m e n t s s u c e , c o n s i d e r u s i n g a r a d i x   r  t h a t i s l a r g e c o m p a r e d t o  

t h e c o n s t a n t s ( \  O  ( 1 ) " ) w i t h w h i c h t h e r e q u i r e m e n t s a r e s a t i s e d . S y m m e t r i c a l l y a l l o w a s  

\ d i g i t s " a l l i n t e g e r s   d  s a t i s f y i n g   ?  r < d <   +  r  . ( F o r o u r u l t i m a t e u s e , t h e r a d i x   r  = 4 w i l l b e  

l a r g e e n o u g h ; t h i s e x p l a i n s t h e u s e o f t h e d i g i t s e t   f  - 3  ;  - 2  ;  - 1  ;  0  ;  1  ;  2  ;  3  g  i n S e c t i o n 2 ' s p r e v i e w  

o f t h e s i m u l a t i o n . ) A s s u g g e s t e d i n S e c t i o n 2 , m a i n t a i n a n u n d e r l i n e b e n e a t h e a c h s i g n i c a n t  

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 6/15

d i g i t e x c e p t f o r t h e l e a d i n g o n e . P r o p a g a t e i n f o r m a t i o n f r o m p o s i t i o n   i  t o p o s i t i o n   i  + 1 

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

\ C a r r y " i f t h e d i g i t i s g r e a t e r t h a n   r =  2 . 

\ B o r r o w " i f t h e d i g i t i s l e s s t h a n   ?  r =  2 . 

D o n o t h i n g i f t h e d i g i t i s b o u n d e d b y   r =  2 i n a b s o l u t e v a l u e .  

( T o \ c a r r y " , r e d u c e t h e d i g i t i n p o s i t i o n   i  b y  r  , a n d i n c r e m e n t t h e d i g i t i n p o s i t i o n   i  + 1 b y 1 .  

T o \ b o r r o w " , r e d u c e t h e d i g i t i n p o s i t i o n   i  + 1 b y 1 , a n d i n c r e m e n t t h e d i g i t i n p o s i t i o n   i 

b y  r  . ) B y i n d u c t i o n , t h e p r o p e r t i e s o f t h e m a i n t e n a n c e s c h e d u l e a s s u r e t h a t n o d i g i t w i l l  

h a v e t o e x c e e d   r  ?  1 i n a b s o l u t e v a l u e . A s a c o n s e q u e n c e , t h e o n l y d i g i t t h a t m i g h t c h a n g e  

f r o m z e r o t o n o n z e r o , o r v i c e v e r s a , i s a t p o s i t i o n   i  + 1 a b o v e , s o t h a t o n l y t h e u n d e r l i n i n g a t  

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

a n y a d d i t i o n a l a c c e s s t o t h e d i g i t s o f t h e c o u n t e r . A s a n o t h e r c o n s e q u e n c e , t h e l e a d i n g  

s i g n i c a n t d i g i t ( i f t h e r e i s o n e ) w i l l a l w a y s c o r r e c t l y i n d i c a t e t h e s i g n o f t h e e n t i r e c o u n t ,  

s o t h a t t h e c o u n t w i l l b e 0 o n l y w h e n t h e f r e q u e n t l y o b s e r v e d d i g i t a t p o s i t i o n 0 i s a 0 w i t h  

n o u n d e r l i n e .  

4 . P e r m u t a t i o n f o r S e q u e n t i a l A c c e s s  

W i t h o n l y   s e q u e n t i a l   a c c e s s , i t s e e m s i m p o s s i b l e t o v i s i t t h e p o s i t i o n s o f a r a d i x n u m b e r  

a c c o r d i n g t o t h e s c h e d u l i n g r e q u i r e m e n t s a b o v e . T h e r s t r e q u i r e m e n t k e e p s u s c l o s e t o t h e  

l o w - o r d e r d i g i t , w h i l e t h e s e c o n d r e q u i r e m e n t d r a w s u s t o a r b i t r a r i l y - h i g h - o r d e r d i g i t s . T h i s  

i n t u i t i o n i s w r o n g , h o w e v e r ; e v e n w i t h t h e s t r i c t l y s e q u e n t i a l a c c e s s a v a i l a b l e o n a s i n g l e  

T u r i n g m a c h i n e t a p e , w e   c a n  s a t i s f y t h e r e q u i r e m e n t s . T h e t r i c k i s t o m a i n t a i n , o n t h e  

m a i n t r a c k o f t h e t a p e , a n a p p r o p r i a t e , d y n a m i c a l l y ( b u t o b l i v i o u s l y ) c h a n g i n g   p e r m u t a t i o n  

o f t h e r a d i x p o s i t i o n s . W e t u r n n o w t o a t o p - d o w n d e v e l o p m e n t a n d i m p l e m e n t a t i o n o f a  

s u i t a b l e p e r m u t a t i o n p r o c e d u r e .  

S i n c e t h e p e r m u t a t i o n p r o c e d u r e w i l l b e o b l i v i o u s t o t h e a c t u a l c o n t e n t s o f t h e r a d i x  

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

w e w i l l s p e a k a s i f w e a r e p e r m u t i n g t h e p o s i t i o n n u m b e r s t h e m s e l v e s . I t i s i m p o r t a n t t o  

r e m e m b e r , h o w e v e r , t h a t i t w i l l b e i m p o s s i b l e w i t h a n y n i t e t a p e a l p h a b e t f o r o u r s i m u l a t o r  

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

t i m e . T o r e c o g n i z e w h a t m a y b e o b v i o u s f r o m t h e p o s i t i o n n u m b e r s , t h e u l t i m a t e s i m u l a t o r  

w i l l h a v e t o c l e v e r l y m a i n t a i n a u x i l i a r y m a r k e r s f r o m s o m e n i t e a l p h a b e t ( p r i m e s , d o u b l e  

p r i m e s , a n d o v e r a r r o w s i n t h e s i m u l a t i o n w e d e s c r i b e ) o n a n a u x i l i a r y t r a c k o f i t s t a p e .  

C o n s i d e r t h e p r o b l e m o f v i s i t i n g t h e p o s i t i o n s o f a r a d i x n u m b e r a c c o r d i n g t o t h e b i n a r y  

c a r r y s c h e d u l e . T h e k e y t o t h e s c h e d u l e i s t h a t i t b r a c k e t s e a c h v i s i t t o p o s i t i o n   i  + 1 b y  

f u l l \ t o u r s " o f p o s i t i o n s 0 ,   : : :  ,  i  , d e n o t e d b y   t o u r   (  i  ) : 

t o u r   (  i  + 1 ) :   t o u r   ( 0 ) :  

t o u r   (  i  ) v i s i t 0  

v i s i t   i  + 1 

t o u r   (  i  ) 

N o t i n g t h a t a p p e n d i n g \ v i s i t   i  + 1 ;  t o u r   (  i  ) " o n t o t h e e n d o f  t o u r   (  i  ) a l w a y s g i v e s   t o u r   (  i  + 1 ) ,  

w e s e e t h a t   t o u r   (  1  ) m a k e s s e n s e :  

t o u r   (  1  ) : 

v i s i t 0  

v i s i t 1 ;   t o u r   ( 0 ) 

v i s i t 2 ;   t o u r   ( 1 ) 

v i s i t 3 ;   t o u r   ( 2 ) 

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 7/15

I n f a c t   t o u r   (  1  ) i s p r e c i s e l y t h e e n t i r e b i n a r y c a r r y s c h e d u l e .  

F o r a T u r i n g m a c h i n e i m p l e m e n t a t i o n o f a l l t h i s t o u r i n g , w e m u s t p e r m u t e t o k e e p t h e  

h e a d , r e p r e s e n t e d b y     a s i n S e c t i o n 2 , a l w a y s n e a r p o s i t i o n n u m b e r 0 . T h u s w e m i g h t t r y  

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

t o u r   (  i  ) :    0 1 2  : : : i  (  i  + 1 )  )  i : : :  2 1 0    (  i  + 1 ) 

a s p r e p a r a t i o n f o r t h e r s t v i s i t t o   i  + 1 . B u t t h e n   t o u r   (  i  ) ( o r e v e n i t s s y m m e t r i c m i r r o r  

i m a g e ) w o u l d n o l o n g e r c o m p l e t e t h e d e s i r e d a n a l o g o u s p r e p a r a t i o n ( i . e . ,   t o u r   (  i  + 1 ) ) f o r  

t h e r s t v i s i t t o   i  + 2 . W i t h t h e l a t t e r g o a l i n m i n d , w e a r e l e d t o p u s h p o s i t i o n   i  + 1 l e f t  

d u r i n g t h e s e c o n d ( m i r r o r - i m a g e ) i t e r a t i o n o f   t o u r   (  i  ) a n d t o i n t r o d u c e i n t o   t o u r  (  i  + 1 ) a  

t h i r d i t e r a t i o n o f   t o u r   (  i  ) , t o g e t b a c k t o p o s i t i o n   i  + 2 . T h i s w a y , t h e p e r m u t a t i o n a l s i d e  

e e c t o f   t o u r  (  i  + 1 ) i s f r o m     0 1 2  : : : i  (  i  + 1 ) i n i t i a l l y , t o   i : : :  2 1 0    (  i  + 1 ) a f t e r t h e r s t  

i t e r a t i o n o f   t o u r  (  i  ) , t o (  i  + 1 )    0 1 2  : : : i   a f t e r t h e s e c o n d i t e r a t i o n , n a l l y t o (  i  + 1 )  i : : :  2 1 0   

a f t e r t h e t h i r d i t e r a t i o n , a s d e s i r e d . T h i s l e a d s u s t o r e n e o u r t e r m i n o l o g y , i n o r d e r t o  

r e e c t t h e t w o v a r i a n t s o f   i  - t o u r   (  t o u r   (  i  ) a b o v e ) :  

t o u r   (  i ;  ?  ) :    0 1 2  : : : i   )  i : : :  2 1 0   

t o u r   (  i ;  ?  ) :  i : : :  2 1 0  )   0 1 2  : : : i   ( m i r r o r i m a g e )  

t o u r   (  i ;  + ) :  j    0 1 2  : : : i   )  i : : :  2 1 0    j 

t o u r   (  i ;  + ) :  i : : :  2 1 0    j  )  j    0 1 2  : : : i   ( m i r r o r i m a g e )  

W e w i l l r e f e r t o t h e s e v a r i a n t s a s   n e g a t i v e   i  - t o u r s a n d   p o s i t i v e   i  - t o u r s , r e s p e c t i v e l y , d e p e n d i n g  

o n w h e t h e r s o m e p o s i t i o n   j  i s  o r  i s n o t   b e i n g \ t r a n s p o r t e d " . N o t e t h a t w e d o n o t d i s t i n g u i s h  

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

a t a t i m e , d e p e n d i n g o n t h e c u r r e n t l o c a t i o n o f p o s i t i o n 0 . S i m i l a r l y , w e d o n o t i n c o r p o r a t e  

i n t o t h e n o t a t i o n t h e p o s i t i o n   j  b e i n g t r a n s p o r t e d b y a p o s i t i v e t o u r , s i n c e t h e r e i s n e v e r  

a n y c h o i c e .  

S u p p r e s s i n g e x p l i c i t v i s i t s n o w ( s i n c e c o n v e n i e n t   i  - o p p o r t u n i t i e s w i l l a r i s e a t a d i e r e n t  

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

a n y w a y ) , w e a r r i v e a t t h e f o l l o w i n g m u t u a l l y r e c u r s i v e i m p l e m e n t a t i o n s f o r o u r e v o l v i n g  

t o u r s ( t h e p r o g r a m l o c a t i o n s a r e l a b e l e d ( a ) t h r o u g h ( e ) f o r l a t e r r e f e r e n c e ) :  

t o u r   (  i  + 1  ;  ?  ) :  ( s t a r t w i t h     0 1 2  : : : i  (  i  + 1 ) )  

t o u r   (  i ;  ?  )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 1 ) )  

( a )  t o u r   (  i ;  + )  ( p e r m u t e t o (  i  + 1 )    0 1 2  : : : i  ) 

( b )  t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :  2 1 0    ) 

t o u r   (  i  + 1  ;  + ) :  ( s t a r t w i t h   j    0 1 2  : : : i  (  i  + 1 ) )  

t o u r   (  i ;  + )  ( p e r m u t e t o   i : : :  2 1 0    j  (  i  + 1 ) )  

( c )  p u s h b a c k   ( p e r m u t e t o   i : : :  2 1 0    (  i  + 1 )  j  ) 

( d )  t o u r   (  i ;  + )  ( p e r m u t e t o (  i  + 1 )    0 1 2  : : : i j  ) 

( e )  t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :  2 1 0    j  ) 

T h e r e c u r s i v e s t r a t e g y f o r   t o u r  (  i  + 1  ;  ?  ) i s a s d e s c r i b e d p r e v i o u s l y , b u t t h e s t r a t e g y f o r  

t o u r  (  i  + 1  ;  + ) i s n e w . N o t e t h a t t h e l a t t e r r e q u i r e s a n e w p e r m u t a t i o n s t e p , c a l l e d a   p u s h b a c k   , 

t o p u s h t h e n o n z e r o p o s i t i o n c u r r e n t l y a d j a c e n t t o t h e h e a d b e y o n d t h e n e x t a d j a c e n t  

p o s i t i o n . F i n a l l y , s i n c e a p p e n d i n g  

( a )  t o u r   (  i ;  + ) ; ( b )   t o u r   (  i ;  ?  ) 

o n t o t h e e n d o f   t o u r   (  i ;  ?  ) a l w a y s g i v e s   t o u r   (  i  + 1  ;  ?  ) , w e a g a i n h a v e a w e l l - d e n e d i n n i t e  

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 8/15

l i m i t :  

t o u r   (  1  ;  ?  ) :  ( s t a r t w i t h     0 1 2 3 4 5   ) 

t o u r   ( 0  ;  ?  )  ( p e r m u t e t o 0     1 2 3 4 5   ) 

( a )  t o u r   ( 0  ;  + ) ; ( b )   t o u r   ( 0  ;  ?  )  ( p e r m u t e t o 1 0     2 3 4 5   ) 

( a )  t o u r   ( 1  ;  + ) ; ( b )   t o u r   ( 1  ;  ?  )  ( p e r m u t e t o 2 1 0     3 4 5  ) 

( a )  t o u r   ( 2  ;  + ) ; ( b )   t o u r   ( 2  ;  ?  )  ( p e r m u t e t o 3 2 1 0     4 5  ) 

I t i s   t o u r  (  1  ;  ?  ) t h a t w e a c t u a l l y i m p l e m e n t .  

5 . R e c u r s i o n E l i m i n a t i o n  

B y i n d u c t i o n , t h e e n t i r e p e r m u t a t i o n p r o c e s s   t o u r  (  1  ;  ?  ) i n v o l v e s j u s t t h r e e , s y m m e t r i c  

p a i r s o f a t o m i c m o v e s :  

t o u r   ( 0  ;  ?  ) :    0  )  0    t o u r   ( 0  ;  + ) :  j    0  )  0    j  p u s h b a c k   : 0    j i  )  0    i j 

0  )   0 0    j  )  j    0  i j    0  )  j i    0 

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

s t e p . T h e p r o b l e m i s a n a l o g o u s t o t h e d e r i v a t i o n o f a n o n r e c u r s i v e s o l u t i o n t o t h e \ T o w e r s  

o f H a n o i " p r o b l e m f r o m t h e m o r e o b v i o u s r e c u r s i v e s o l u t i o n 3 ] . I n t h i s s e c t i o n w e s o l v e  

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

p e r m u t e d .  

B e c a u s e p o s i t i o n 0 w i l l a l w a y s b e t o t h e i m m e d i a t e l e f t o r r i g h t o f t h e h e a d , t h e s i m u l a t o r  

w i l l b e a b l e t o m a i n t a i n t h e c o r r e c t c u r r e n t d i r e c t i o n t o p o s i t i o n 0 i n n i t e - s t a t e c o n t r o l ,  

n a r r o w i n g t h e p o s s i b i l i t i e s t o j u s t o n e a t o m i c m o v e f r o m e a c h p a i r a b o v e . T h e r e m a i n i n g  

p r o b l e m i s t o d e t e r m i n e w h e t h e r t h e n e x t s t e p s h o u l d b e a n e g a t i v e 0 - t o u r , a p o s i t i v e 0 - t o u r ,  

o r a p u s h b a c k .  

O b s e r v a t i o n 1 .   F o r e v e r y   i  , t h e r e s p e c t i v e r s t m o v e s o f   t o u r   (  i ;  ?  )  a n d  t o u r   (  i ;  + )  a r e 

t o u r   ( 0  ;  ?  )  a n d  t o u r   ( 0  ;  + )  . 

E x c e p t f o r t h e i n i t i a l s i t u a t i o n , w h e n   t o u r   ( 0  ;  ?  ) i s r e q u i r e d e x p l i c i t l y , p r o g r a m l o c a t i o n s  

( a ) t h r o u g h ( e ) a c c o u n t f o r a l l s i t u a t i o n s . B y O b s e r v a t i o n 1 , i t w i l l s u c e a l w a y s t o k n o w  

w h e t h e r t h e n e x t m o v e s t a r t s a n e g a t i v e t o u r ( p r o g r a m l o c a t i o n s ( b ) , ( e ) ) , s t a r t s a p o s i t i v e  

t o u r ( p r o g r a m l o c a t i o n s ( a ) , ( d ) ) , o r i s a p u s h b a c k ( p r o g r a m l o c a t i o n ( c ) ) . A g o o d c l u e  

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

h o w e v e r , s i n c e n e g a t i v e (  i  + 1 ) - t o u r s a n d p o s i t i v e (  i  + 1 ) - t o u r s b o t h e n d w i t h t h e s a m e m o v e ,  

a n e g a t i v e 0 - t o u r .  

O b s e r v a t i o n 2 .   A p o s i t i v e t o u r e n d s w i t h t h e h e a d a d j a c e n t t o t h e t r a n s p o r t e d p o s i t i o n   j  . 

O b s e r v a t i o n 3 .   B y i n d u c t i o n , a t n o t i m e p r o p e r l y w i t h i n a t o u r i s t h e h e a d a d j a c e n t t o a  

p o s i t i o n n o t e x p l i c i t l y i n v o l v e d i n t h e t o u r . ( T h e p o s i t i o n s e x p l i c i t l y i n v o l v e d i n   t o u r   (  i ;  ?  ) 

a r e  0  t h r o u g h   i  , a n d t h e o n e s e x p l i c i t l y i n v o l v e d i n   t o u r   (  i ;  + )  a r e t h e s e a n d a l s o t h e t r a n s -  

p o r t e d p o s i t i o n   j  . ) 

C o r o l l a r y .   T h e p o s i t i o n   j  t h a t g e t s p u s h e d b a c k a t t h e o u t e r m o s t l e v e l o f a p o s i t i v e t o u r  

w i l l n e x t b e a d j a c e n t t o t h e h e a d a t t h e e n d o f t h a t p o s i t i v e t o u r .  

T h i s l a s t c o r o l l a r y p r e s e n t s a n o p p o r t u n i t y t o r e c o g n i z e t h e e n d o f a p o s i t i v e t o u r : T h e  

h e a d c a n l e a v e a \ m e s s a g e " a t t a c h e d t o t h e p o s i t i o n t h a t g e t s p u s h e d b a c k , i n d i c a t i n g t h a t a  

p o s i t i v e t o u r i s i n p r o g r e s s . ( I n o u r u l t i m a t e i m p l e m e n t a t i o n , t h e m e s s a g e s w i l l b e s i n g l e a n d  

d o u b l e p r i m e s o n s y m b o l s . ) C o n s e q u e n t l y , t h e s i m u l a t o r w i l l b e a b l e t o r e c o g n i z e w h e n a  

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 9/15

p o s i t i v e t o u r i s e n d i n g , a t w h i c h t i m e i t c a n d e l e t e t h e m e s s a g e ( r e m o v e t h e s i n g l e o r d o u b l e  

p r i m e ) . ( I n t h e s p e c i a l c a s e o f t h e o n e - m o v e p o s i t i v e t o u r   t o u r   ( 0  ;  + ) , t h e r e i s n o p u s h b a c k ; i n  

t h i s c a s e , f o r u n i f o r m i t y , t h e s a m e s o r t o f m e s s a g e c a n b e a t t a c h e d t o t h e r e l e v a n t p o s i t i o n   j  , 

i n t h e o n e m o v e t h a t d o e s t a k e p l a c e . ) T h e a b s e n c e o f s u c h a m e s s a g e , t h e r e f o r e , w i l l s u r e l y  

i n d i c a t e p r o g r a m l o c a t i o n ( a ) o r ( d ) a n d h e n c e t h a t t h e n e x t m o v e s h o u l d b e   t o u r   ( 0  ;  + ) . I n  

t h e  p r e s e n c e   o f s u c h a m e s s a g e , h o w e v e r , i t s t i l l r e m a i n s t o d i s t i n g u i s h p r o g r a m l o c a t i o n ( c )  

( w h i c h i s f o l l o w e d b y a p u s h b a c k ) f r o m p r o g r a m l o c a t i o n s ( b ) a n d ( e ) ( w h i c h a r e f o l l o w e d b y  

t o u r   ( 0  ;  ?  ) ) . F o r t h i s p u r p o s e , w e i n t r o d u c e a n a u x i l i a r y d i s t i n c t i o n b e t w e e n t w o v a r i e t i e s o f  

p o s i t i v e t o u r , a d i s t i n c t i o n t h a t w e w i l l t r y t o r e c o r d a s p a r t o f t h e m e s s a g e c o r r e s p o n d i n g  

t o t h e p o s i t i v e t o u r . T h e d i s t i n c t i o n i s s i m p l y   j  =  i  + 1 v e r s u s   j > i  + 1 : 

t o u r  

(  i ;  + ) : (  i  + 1 )    0 1 2  : : : i   )  i : : :  2 1 0    (  i  + 1 ) 

t o u r  

(  i ;  + ) :  i : : :  2 1 0    (  i  + 1 )  )  (  i  + 1 )    0 1 2  : : : i  

t o u r  

0 0 

(  i ;  + ) :  j    0 1 2  : : : i   )  i : : :  2 1 0    j  (  j > i  + 1 ) 

t o u r  

0 0 

(  i ;  + ) :  i : : :  2 1 0    j  )  j    0 1 2  : : : i   (  j > i  + 1 ) 

I n t h e c o r r e s p o n d i n g l y r e v i s e d r e c u r s i o n , d o u b l y p r i m e d p o s i t i v e t o u r s a r e n e e d e d o n l y f o r  

t h e r s t s u b t o u r a t t h e o u t e r m o s t l e v e l o f e a c h p o s i t i v e t o u r . B e c a u s e d i e r e n t m e s s a g e s  

h a v e t o b e l e f t , w e b e g i n n o w t o d i s t i n g u i s h b e t w e e n s i n g l y a n d d o u b l y p r i m e d p u s h b a c k s .  

F o r u s e i n o u r a n a l y s i s , w e a d d t h e r e c u r s i o n l e v e l o f a p u s h b a c k t o t h e n o t a t i o n , e v e n t h o u g h  

i t i s n o t a l g o r i t h m i c a l l y s i g n i c a n t .  

t o u r   (  i  + 1  ;  ?  ) :  ( s t a r t w i t h     0 1 2  : : : i  (  i  + 1 ) )  

t o u r   (  i ;  ?  )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 1 ) )  

( a )  t o u r  

(  i ;  + )  ( p e r m u t e t o (  i  + 1 )    0 1 2  : : : i  ) 

( b )  t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :  2 1 0    ) 

t o u r  

(  i  + 1  ;  + ) :  ( s t a r t w i t h (  i  + 2 )    0 1 2  : : : i  (  i  + 1 ) )  

t o u r  

0 0 

(  i ;  + )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 2 ) (  i  + 1 ) )  

( c )  p u s h b a c k  

(  i  + 1 )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 1 ) (  i  + 2 ) )  

( d )  t o u r  

(  i ;  + )  ( p e r m u t e t o (  i  + 1 )    0 1 2  : : : i  (  i  + 2 ) )  

( e )  t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :  2 1 0    (  i  + 2 ) )  

t o u r  

0 0 

(  i  + 1  ;  + ) :  ( s t a r t w i t h   j    0 1 2  : : : i  (  i  + 1 ) )  

t o u r  

0 0 

(  i ;  + )  ( p e r m u t e t o   i : : :  2 1 0    j  (  i  + 1 ) )  

( c )  p u s h b a c k  

0 0 

(  i  + 1 )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 1 )  j  ) 

( d )  t o u r  

(  i ;  + )  ( p e r m u t e t o (  i  + 1 )    0 1 2  : : : i j  ) 

( e )  t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :  2 1 0    j  ) 

t o u r   (  1  ;  ?  ) :  ( s t a r t w i t h     0 1 2 3 4 5   ) 

t o u r   ( 0  ;  ?  )  ( p e r m u t e t o 0     1 2 3 4 5   ) 

( a )  t o u r  

( 0  ;  + ) ; ( b )  t o u r   ( 0  ;  ?  )  ( p e r m u t e t o 1 0     2 3 4 5   ) 

( a )  t o u r  

( 1  ;  + ) ; ( b )  t o u r   ( 1  ;  ?  )  ( p e r m u t e t o 2 1 0     3 4 5  ) 

( a )  t o u r  

( 2  ;  + ) ; ( b )  t o u r   ( 2  ;  ?  )  ( p e r m u t e t o 3 2 1 0     4 5  ) 

A s d e s i r e d , n o w , t h e e n d o f t h e d o u b l y p r i m e d v a r i e t y o f p o s i t i v e t o u r w i l l i n d i c a t e p r o g r a m  

l o c a t i o n ( c ) , a n d t h e e n d o f t h e s i n g l y p r i m e d v a r i e t y w i l l i n d i c a t e p r o g r a m l o c a t i o n ( b ) o r ( e ) .  

I t r e m a i n s t o n d a w a y t o r e c o g n i z e w h i c h v a r i e t y o f p o s i t i v e t o u r e a c h p u s h b a c k i s a  

t o p - l e v e l p a r t o f , a n d w h i c h i s t h e v a r i e t y o f e a c h p o s i t i v e 0 - t o u r , s o t h a t t h e r i g h t m e s s a g e s  

( s i n g l e o r d o u b l e p r i m e , c o r r e s p o n d i n g t o t h e s i n g l y o r d o u b l y p r i m e d v a r i e t y o f p u s h b a c k o r  

p o s i t i v e t o u r ) c a n b e r e c o r d e d . F o r t h e s e p u r p o s e s , w e w i l l m a i n t a i n w i t h e a c h p o s i t i o n t h e  

d i r e c t i o n i n t h e c u r r e n t p e r m u t a t i o n t o i t s s u c c e s s o r . ( T h i s i s t h e p u r p o s e o f t h e o v e r a r r o w s . )  

W h e n w e s u m m a r i z e i n S e c t i o n 7 , w e w i l l i n d i c a t e h o w t o k e e p t h i s i n f o r m a t i o n u p t o d a t e .  

T o s e e t h a t t h i s d i r e c t i o n a l i n f o r m a t i o n w i l l h e l p , w e n e e d o n e m o r e i n d u c t i v e o b s e r v a t i o n :  

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 10/15

O b s e r v a t i o n 4 .   I n e a c h i n v o c a t i o n o f   t o u r  

0 0 

(  i ;  + )  ( o n l y t w o p o s s i b i l i t i e s a b o v e ) , t h e r s t  

u n i n v o l v e d p o s i t i o n i n i t i a l l y b e y o n d p o s i t i o n   i  i s p o s i t i o n   i  + 1  . ( I n e i t h e r c a s e , t h e i n i t i a l  

p e r m u t a t i o n w i l l i n c l u d e   j    0 1 2  : : : i  (  i  + 1 )  o r i t s m i r r o r i m a g e . )  

I n a l l o u r i n v o c a t i o n s o f   t o u r  

0 0 

(  i  + 1  ;  + ) , t h e r e f o r e , t h e r s t u n i n v o l v e d p o s i t i o n i n i t i a l l y  

b e y o n d p o s i t i o n   i  + 1 w i l l b e p o s i t i o n   i  + 2 , s o t h a t t h e p r e c o n d i t i o n f o r   p u s h b a c k  

0 0 

(  i  + 1 ) w i l l  

a l w a y s b e 0     j  (  i  + 1 ) (  i  + 2 ) ( o r i t s m i r r o r i m a g e ) . T h e p r e c o n d i t i o n f o r   p u s h b a c k  

(  i  + 1 ) , o n  

t h e o t h e r h a n d , w i l l a l w a y s b e 0     (  i  + 2 ) (  i  + 1 ) ( o r i t s m i r r o r i m a g e ) . T h e d i s t i n c t i o n c a n b e  

r e c o g n i z e d f r o m t h e d i r e c t i o n a l i n f o r m a t i o n f o r p o s i t i o n   i  + 1 . S i m i l a r l y , t h e p r e c o n d i t i o n f o r  

t o u r  

0 0 

( 0  ;  + ) w i l l a l w a y s b e 1 0     j  ( o r i t s m i r r o r i m a g e ) , w h i l e t h e p r e c o n d i t i o n f o r   t o u r  

( 0  ;  + ) 

w i l l a l w a y s b e 0     1 ( o r i t s m i r r o r i m a g e ) , a d i s t i n c t i o n t h a t c a n b e r e c o g n i z e d f r o m t h e  

d i r e c t i o n a l i n f o r m a t i o n f o r p o s i t i o n 0 .  

I n s u m m a r y , h e r e a r e s u i t a b l e s p e c i c a t i o n s f o r t h e e v o l v e d v e r s i o n s o f a l l t h e t o u r s a n d  

p u s h b a c k s ( e x c e p t f o r m i r r o r i m a g e s ) , n o w s h o w i n g s i n g l e - a n d d o u b l e - p r i m e m e s s a g e s ( b u t  

n o t s h o w i n g o v e r a r r o w s , s i n c e w e a r e s t i l l s h o w i n g e x p l i c i t p o s i t i o n n u m b e r s ) :  

t o u r   (  i ;  ?  ) : 

  0 1 2  : : : i   )  i : : :  2 1 0   

t o u r  

(  i ;  + ) : (  i  + 1 )    0 1 2  : : : i   )  i : : :  2 1 0    (  i  + 1 ) 

t o u r  

0 0 

(  i ;  + ) :  j    0 1 2  : : : i  (  i  + 1 )  )  i : : :  2 1 0    j 

0 0 

(  i  + 1 ) (  j > i  + 1 ) 

p u s h b a c k  

(  i  ) : 0    (  i  + 1 ) 

0 0 

i  )  0    i  (  i  + 1 ) 

p u s h b a c k  

0 0 

(  i  ) : 0    j 

0 0 

i  (  i  + 1 )  )  0    i j 

0 0 

(  i  + 1 ) (  j > i  + 1 ) 

I t i s e a s y t o c h e c k i n d u c t i v e l y t h a t t h e r e c u r s i v e i m p l e m e n t a t i o n s d o m a i n t a i n t h e s p e c i -  

c a t i o n s :  

t o u r   (  i  + 1  ;  ?  ) :  ( s t a r t w i t h  

  0 1 2  : : : i  (  i  + 1 ) )  

t o u r   (  i ;  ?  )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 1 ) )  

t o u r  

(  i ;  + )  ( p e r m u t e t o (  i  + 1 ) 

  0 1 2  : : : i  ) 

t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :   2 1 0    ) 

t o u r  

(  i  + 1  ;  + ) :  ( s t a r t w i t h (  i  + 2 )    0 1 2  : : : i  (  i  + 1 ) )  

t o u r  

0 0 

(  i ;  + )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 2 ) 

0 0 

(  i  + 1 ) )  

p u s h b a c k  

(  i  + 1 )  ( p e r m u t e t o   i : : :  2 1 0    (  i  + 1 ) (  i  + 2 ) 

t o u r  

(  i ;  + )  ( p e r m u t e t o (  i  + 1 ) 

  0 1 2  : : : i  (  i  + 2 ) 

t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :   2 1 0    (  i  + 2 ) 

t o u r  

0 0 

(  i  + 1  ;  + ) :  ( s t a r t w i t h   j    0 1 2  : : : i  (  i  + 1 ) (  i  + 2 ) )  

t o u r  

0 0 

(  i ;  + )  ( p e r m u t e t o   i : : :   2 1 0    j 

0 0 

(  i  + 1 ) (  i  + 2 ) )  

p u s h b a c k  

0 0 

(  i  + 1 )  ( p e r m u t e t o   i : : :   2 1 0    (  i  + 1 )  j 

0 0 

(  i  + 2 ) )  

t o u r  

(  i ;  + )  ( p e r m u t e t o (  i  + 1 ) 

  0 1 2  : : : i j  

0 0 

(  i  + 2 ) )  

t o u r   (  i ;  ?  )  ( p e r m u t e t o (  i  + 1 )  i : : :  2 1 0    j 

0 0 

(  i  + 2 ) )  

t o u r   (  1  ;  ?  ) :  ( s t a r t w i t h  

  0 1 2 3 4 5   ) 

t o u r   ( 0  ;  ?  )  ( p e r m u t e t o 0     1 2 3 4 5   ) 

t o u r  

( 0  ;  + ) ;  t o u r   ( 0  ;  ?  )  ( p e r m u t e t o 1 0     2 3 4 5   ) 

t o u r  

( 1  ;  + ) ;  t o u r   ( 1  ;  ?  )  ( p e r m u t e t o 2 1 0     3 4 5  ) 

t o u r  

( 2  ;  + ) ;  t o u r   ( 2  ;  ?  )  ( p e r m u t e t o 3 2 1 0     4 5  ) 

6 . O p p o r t u n i t i e s T o C a r r y a n d T o B o r r o w  

W e s e e f r o m t h e a b o v e p r e c o n d i t i o n s f o r   p u s h b a c k  

(  i  + 1 ) a n d   p u s h b a c k  

0 0 

(  i  + 1 ) ( t h e  

\ (  i  + 1 ) - p u s h b a c k s " ) t h a t t h e s e o p e r a t i o n s c a n s e r v e a s (  i  + 2 ) - o p p o r t u n i t i e s . S i m i l a r l y ,  

1 0 

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 11/15

t o u r  

( 0  ;  + ) a n d   t o u r  

0 0 

( 0  ;  + ) ( t h e \ p o s i t i v e 0 - t o u r s " ) c a n s e r v e a s 1 - o p p o r t u n i t i e s . S i n c e t h e  

h e a d i s a l w a y s a d j a c e n t t o p o s i t i o n 0 , e v e r y s t e p i s a g o o d t i m e t o p r o p a g a t e i n c r e m e n t s  

a n d d e c r e m e n t s i n t o p o s i t i o n 0 ; i f w e d e s i g n a t e o n l y t h e p o s i t i v e 0 - t o u r s a s 0 - o p p o r t u n i t i e s ,  

h o w e v e r , w e w i l l u l t i m a t e l y b e a b l e t o c h o o s e a s l i g h t l y s m a l l e r r a d i x f o r o u r n o t a t i o n .  

O b s e r v a t i o n 5 .   I f w e o m i t   j  - p u s h b a c k s f o r   j > i  , t h e n   t o u r   (  1  ;  ?  )  i s a n i n n i t e c o n c a t e -  

n a t i o n o f n e g a t i v e a n d p o s i t i v e   i  - t o u r s , t h e r s t o f w h i c h i s n e g a t i v e , t h e s e c o n d o f w h i c h i s  

p o s i t i v e , a n d n o t h r e e c o n s e c u t i v e o f w h i c h a r e a l l n e g a t i v e o r a l l p o s i t i v e . ( T o s e e t h e l a s t  

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

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

- t o u r , a n d n a l l y n o t e t h a t   t o u r   (  1  ;  ?  )  i s t h e l i m i t o f t h e n e g a t i v e t o u r s . )  

C o r o l l a r y .   I n  t o u r   (  1  ;  ?  )  , o u r i n f o r m a t i o n p r o p a g a t i o n r e q u i r e m e n t s a r e s a t i s e d w i t h  

r e s p e c t i v e c o n s t a n t s   3  a n d  4  : 

1 . T h e r e i s a   0  - o p p o r t u n i t y a t l e a s t o n c e e v e r y t h r e e s t e p s .  

2 . T h e r e i s a   1  - o p p o r t u n i t y e v e r y t i m e t h e r e i s a   0  - o p p o r t u n i t y .  

3 . T h e r e a r e e x a c t l y t w o   (  i  + 1 )  - o p p o r t u n i t i e s b e f o r e t h e r s t   (  i  + 2 )  - o p p o r t u n i t y , a n d a t  

m o s t f o u r   (  i  + 1 )  - o p p o r t u n i t i e s b e t w e e n   (  i  + 2 )  - o p p o r t u n i t i e s .  

P r o o f o f t h i r d p a r t :   T h e (  i  + 1 ) - o p p o r t u n i t i e s a r e d i s t r i b u t e d o n e p e r p o s i t i v e   i  - t o u r . U s i n g  

O b s e r v a t i o n 5 t o f o c u s o n (  i  + 1 ) - t o u r s , t h e r e f o r e , w e s e e t h a t e a c h n e g a t i v e t o u r p r e s e n t s  

o n e (  i  + 1 ) - o p p o r t u n i t y a n d n o (  i  + 2 ) - o p p o r t u n i t y , a n d t h a t e a c h p o s i t i v e t o u r p r e s e n t s  

o n e (  i  + 1 ) - o p p o r t u n i t y b e f o r e i t s o n e (  i  + 2 ) - o p p o r t u n i t y a n d o n e a f t e r . T h e t w o i n i t i a l  

(  i  + 1 ) - o p p o r t u n i t i e s c o m e f r o m t h e i n i t i a l n e g a t i v e a n d p o s i t i v e t o u r s , a n d t h e m a x i m u m  

o f f o u r i n t e r v e n i n g (  i  + 1 ) - o p p o r t u n i t i e s a r i s e w h e n a c o n s e c u t i v e p a i r o f n e g a t i v e t o u r s i s  

b r a c k e t e d b y p o s i t i v e t o u r s .  

S i n c e 5 + 4     1 0  ?  1 , i t f o l l o w s t h a t   r  = 1 0 w i l l b e a l a r g e e n o u g h r a d i x . T h e m o r e c a r e f u l  

a n a l y s i s i n S e c t i o n 8 r e v e a l s t h a t e v e n   r  = 4 w i l l b e l a r g e e n o u g h .  

7 . F o r m a l S u m m a r y  

I n S e c t i o n 5 w e s h o w e d h o w t o a n n o t a t e t h e s y m b o l s b e i n g p e r m u t e d i n t h e r e c u r -  

s i v e l y d e n e d   t o u r   (  1  ;  ?  ) i n s u c h a w a y t h a t t h e v e r y s a m e p e r m u t a t i o n c a n b e c a r r i e d o u t  

n o n r e c u r s i v e l y b y a d e t e r m i n i s t i c s i n g l e - t a p e T u r i n g m a c h i n e , b a s e d e n t i r e l y o n l o c a l c u e s .  

I n S e c t i o n 6 w e o b s e r v e d t h a t t h e s a m e a n n o t a t i o n s p r o v i d e s u c i e n t c u e s f o r a d e q u a t e  

o p p o r t u n i t i e s t o p e r f o r m t h e i n c r e m e n t s , d e c r e m e n t s , c a r r i e s , a n d b o r r o w s r e q u i r e d f o r o u r  

r e a l - t i m e s i m u l a t i o n o f a c o u n t e r . I n t h i s s e c t i o n w e n a l l y r e l a t e a l l t h i s t o t h e f e w s i m p l e  

r u l e s p r e v i e w e d i n S e c t i o n 2 .  

F o r t r a n s p a r e n c y , w e w i l l s u m m a r i z e t h e r u l e s w e h a v e d e r i v e d i n t h r e e i n c r e a s i n g l y  

f o r m a l s t a g e s . I n i n c r e a s i n g o r d e r o f d i c u l t y , t h e f o u r m a i n c a s e s a r e t h e r s t m o v e , t h e  

c a s e w h e n a s i n g l e - p r i m e m e s s a g e i s r e c e i v e d , t h e c a s e w h e n n o m e s s a g e i s r e c e i v e d , a n d  

t h e c a s e w h e n a d o u b l e - p r i m e m e s s a g e i s r e c e i v e d . T h e r s t m o v e i s a l w a y s   t o u r   ( 0  ;  ?  ) . 

W h e n a s i n g l e - p r i m e m e s s a g e i s r e c e i v e d ,   t o u r   ( 0  ;  ?  ) i s a g a i n t h e c o r r e c t m o v e . W h e n n o  

m e s s a g e i s r e c e i v e d , t h e c o r r e c t m o v e i s e i t h e r   t o u r  

( 0  ;  + ) o r   t o u r  

0 0 

( 0  ;  + ) , d e p e n d i n g o n  

w h e t h e r p o s i t i o n 1 i s a d j a c e n t t o t h e h e a d o r b e y o n d p o s i t i o n 0 ; e i t h e r w a y , a c a r r y o r  

b o r r o w c a n b e p r o p a g a t e d a s d e s c r i b e d a b o v e , a n d a n i n d i c a t i v e m e s s a g e s h o u l d b e l e f t  

w i t h t h e t r a n s p o r t e d p o s i t i o n . W h e n a d o u b l e - p r i m e m e s s a g e i s r e c e i v e d , t h e c o r r e c t m o v e  

i s a s i n g l y o r d o u b l y p r i m e d p u s h b a c k , d e p e n d i n g o n d i r e c t i o n a l i n f o r m a t i o n n e a r t h e h e a d  

a s d e s c r i b e d a b o v e ; e i t h e r w a y , a c a r r y o r b o r r o w c a n b e p r o p a g a t e d a s d e s c r i b e d a b o v e ,  

a n d a n i n d i c a t i v e m e s s a g e s h o u l d b e l e f t w i t h t h e p o s i t i o n t h a t i s p u s h e d b a c k .  

I n t h e s e c o n d s t a g e , w e r e f o r m u l a t e o u r s u m m a r y v i a f o r m a l r u l e s i n t e r m s o f p o s i t i o n  

n u m b e r s . F o r t h e m e s s a g e s c o r r e s p o n d i n g t o c o m p l e t i o n o f s i n g l y a n d d o u b l y p r i m e d p o s i t i v e  

1 1 

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 12/15

t o u r s , w e u s e s i n g l e a n d d o u b l e p r i m e s o n t h e p o s i t i o n n u m b e r s . E x c e p t i n t h e c a s e o f t h e  

s p e c i a l r u l e f o r t h e v e r y r s t m o v e (     0  )  0    ) , t h e m i r r o r i m a g e o f e a c h r u l e i s a l s o a r u l e ;  

s o w e w i l l l i s t o n l y r u l e s w i t h p o s i t i o n 0 i n i t i a l l y t o t h e   l e f t   o f t h e h e a d . O n l y o n t h e   o t h e r  

s i d e o f t h e h e a d d o w e s h o w p r i m e s e x p l i c i t l y , s i n c e t h e s e p r i m e s c o n s t i t u t e t h e m e s s a g e  

b e i n g r e c e i v e d .  

s i n g l e - p r i m e m e s s a g e : n e g a t i v e 0 - t o u r  

0    i 

)   0  i 

n o m e s s a g e : p o s i t i v e 0 - t o u r  

0    1  )  1 

  0 , p r o p a g a t e i n t o 0 a n d t h e n f r o m 0 t o 1  

1 0    j  )  1  j 

0 0 

  0 , p r o p a g a t e i n t o 0 a n d t h e n f r o m 0 t o 1 (  j >  1 ) 

d o u b l e - p r i m e m e s s a g e : p u s h b a c k  

0    (  i  + 2 ) 

0 0 

(  i  + 1 )  )  0    (  i  + 1 ) (  i  + 2 ) 

, p r o p a g a t e f r o m   i  + 1 t o   i  + 2 

0    j 

0 0 

(  i  + 1 ) (  i  + 2 )  )  0    (  i  + 1 )  j 

0 0 

(  i  + 2 ) , p r o p a g a t e f r o m   i  + 1 t o   i  + 2 (  j > i  + 2 ) 

I n o u r n a l , u n a v o i d a b l y o b s c u r e r e f o r m u l a t i o n , w e r e p l a c e t h e p o s i t i o n n u m b e r s w i t h  

n o n n u m e r i c b a s e - s y m b o l v a r i a b l e s a n d t h e o v e r a r r o w s t h a t a r e a c t u a l l y p r e s e n t . F o r b a s e -  

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

e x p l i c i t o v e r a r r o w s f r o m t h e r u l e s . T o a v o i d e x p l i c i t r e f e r e n c e t o n i t e - s t a t e c o n t r o l , w e  

r e p l a c e t h e h e a d m a r k e r     w i t h e i t h e r  

  o r 

? ! 

  t o i n d i c a t e w h e t h e r p o s i t i o n 0 i s j u s t t o  

t h e l e f t o r j u s t t o t h e r i g h t . E x c e p t f o r t h e s t a r t r u l e (  

? ! 

  a  )  a 

  ) , e a c h r u l e a g a i n h a s a n  

i m p l i c i t s y m m e t r i c r u l e .  

  c 

? ! 

  b c 

? ! 

  c  )  c 

? ! 

 

b  , p r o p a g a t i n g i n t o   b  , a n d t h e n f r o m   b  t o  c 

  c  )  a c 

0 0 

? ! 

 

b  , p r o p a g a t i n g i n t o   b  , a n d t h e n f r o m   b  t o  a 

  c 

0 0 

d  )  b 

 

? ! 

d c 

, p r o p a g a t i n g f r o m   d  t o  c 

  c 

0 0 

? ! 

d e  )  b 

 

? ! 

d c 

0 0 

e  , p r o p a g a t i n g f r o m   d  t o  e 

T h e s t a r t r u l e c l o s e l y r e s e m b l e s ( t h e m i r r o r i m a g e o f ) t h e r s t o f t h e v e m o r e g e n e r a l r u l e s .  

I f w e i n i t i a l l y p r o v i d e a s i n g l y p r i m e d \ e n d m a r k e r " t o t h e l e f t o f t h e h e a d , t h e n t h e s e p a r a t e  

s t a r t r u l e a c t u a l l y d o e s b e c o m e r e d u n d a n t ; t h e r e s u l t , a t l e a s t i f w e u s e r a d i x   r  = 4 , i s t h e  

s i m u l a t i o n p r e v i e w e d i n S e c t i o n 2 .  

8 . S p a c e A n a l y s i s  

T h e s p a c e u s e d f o r t h e r s t   n  s t e p s o f t h e   m o s t   s p a c e - e c i e n t s i m u l a t i o n o f   k  c o u n t e r s  

i s w i t h i n a n a d d i t i v e c o n s t a n t o f   k  l o g 

n  b i t s , i n t h e w o r s t c a s e . F o r   k  l a r g e , w e w i l l s e e n o w  

t h a t a s t r a i g h t f o r w a r d i m p l e m e n t a t i o n o f o u r r e a l - t i m e , o b l i v i o u s s i m u l a t i o n r e q u i r e s o n l y  

a b o u t 2  :  5 t i m e s t h i s m u c h s p a c e .  

R e g a r d l e s s o f t h e p a r t i c u l a r ( l a r g e e n o u g h ) r a d i x u s e d , t h e n u m b e r o f d i s t i n c t   p o s i t i o n s  

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

n  . T o 

s e e t h i s , n o t e t h a t t h e p r o c e s s r s t r e a c h e s p o s i t i o n   i  + 1 a t t h e e n d o f  t o u r   (  i ;  ?  ) , a n d t h a t  

t h e n u m b e r o f s t e p s i n a n e g a t i v e   i  - t o u r i s e x a c t l y ( 5   =  4 ) 3 

?  ( 1  =  2 )  i  ?  ( 1  =  4 ) . T h e l a t t e r , a l o n g  

w i t h t h e f a c t t h a t t h e n u m b e r o f s t e p s i n a   p o s i t i v e   i  - t o u r i s e x a c t l y ( 5   =  4 ) 3 

+ ( 1  =  2 )  i  ?  ( 1  =  4 ) , 

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

1 2 

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 13/15

T o m i n i m i z e t h e s p a c e u s e d f o r e a c h p o s i t i o n , w e s h o u l d c h o o s e t h e s m a l l e s t r a d i x t h a t  

w o r k s . T h e a n a l y s i s b e l o w s h o w s t h a t 4 w o r k s . F o r e a c h a d d i t i o n a l c o u n t e r , t h e r e f o r e , t h e  

s p a c e n e e d e d f o r e a c h i n v o l v e d p o s i t i o n i s a t m o s t 4 =   d  l o g 

( 7    2 )  e  b i t s . ( E a c h o f t h e s e v e n  

s i g n e d d i g i t s h a s t w o v e r s i o n s , o n e u n d e r l i n e d a n d o n e n o t u n d e r l i n e d . ) T h e a d d i t i o n a l ,  

c o u n t e r - i n d e p e n d e n t s p a c e n e e d e d f o r e a c h p o s i t i o n i s a t m o s t 3 =   d  l o g 

( 3    2 )  e  b i t s . ( T h e  

m e s s a g e c a n b e a b s e n t , a s i n g l e p r i m e , o r a d o u b l e p r i m e ; a n d t h e o v e r a r r o w c a n p o i n t t o t h e  

l e f t o r t o t h e r i g h t . ) A l l t o g e t h e r , t h e r e f o r e , t h e s p a c e u s e d t h r o u g h s t e p   n  c a n b e b o u n d e d  

b y ( 3 + 4  k  ) l o g  

n    ( 1  :  8 9 + 2  :  5 2  k  ) l o g  

n  b i t s .  

I t r e m a i n s o n l y t o s h o w t h a t n o o v e r o w ( p a s t 3 ) o r u n d e r o w ( p a s t - 3 ) w i l l o c c u r i f w e  

u s e 4 a s t h e r a d i x i n o u r s i m u l a t i o n . U n t i l a n o v e r o w o r u n d e r o w d o e s o c c u r , e a c h (  i  + 1 ) -  

o p p o r t u n i t y ( a n d a l s o t h e i m p l i c i t i n i t i a l i z a t i o n ) w i l l l e a v e e a c h s i g n e d d i g i t i n p o s i t i o n   i  i n 

t h e r a n g e f r o m - 2 t o 2 . T h e r e f o r e , i t w i l l s u c e t o s h o w t h a t , w h i l e t h e r e m i g h t b e a s m a n y  

a s f o u r   i  - o p p o r t u n i t i e s w i t h o u t a n i n t e r v e n i n g (  i  + 1 ) - o p p o r t u n i t y , a t m o s t o n e o f t h e s e c a n  

a c t u a l l y r e s u l t i n a c a r r y ( o r , s y m m e t r i c a l l y , i n a b o r r o w ) .  

L e m m a .   F o r e a c h   i    1  , a t m o s t o n e   i  - o p p o r t u n i t y i n f o u r c a n r e s u l t i n a c a r r y . F o r e a c h  

i    0  , t h e r e f o r e , a n   (  i  + 1 )  - o p p o r t u n i t y i n t e r v e n e s b e t w e e n e v e r y p a i r o f i n c r e m e n t s t o t h e  

s i g n e d d i g i t i n p o s i t i o n   i  . ( S i m i l a r l y f o r b o r r o w s a n d d e c r e m e n t s , b y s y m m e t r y . )  

P r o o f :   F o r e a c h   i    1 , t h e s e c o n d a s s e r t i o n f o l l o w s f r o m t h e r s t b y t h e t h i r d p a r t o f t h e  

c o r o l l a r y t o O b s e r v a t i o n 5 . F o r   i  = 0 , t h e s e c o n d a s s e r t i o n i s a n i m m e d i a t e c o n s e q u e n c e o f  

t h e s e c o n d p a r t o f t h e s a m e c o r o l l a r y .  

T h e p r o o f o f t h e r s t a s s e r t i o n i s b y i n d u c t i o n o n   i    1 , a n d t h e g e n e r a l i n d u c t i o n  

s t e p i s i t s e l f a n i n d u c t i o n o n t i m e . C o n s i d e r t h e r s t o r n e x t   i  - o p p o r t u n i t y t h a t r e s u l t s i n  

a c a r r y . T h i s c a r r y l e a v e s t h e s i g n e d d i g i t - 1 = 3   ?  4 i n p o s i t i o n   i  ?  1 . B y t h e ( s e c o n d )  

a s s e r t i o n f o r   i  ?  1 , t h i s c a n i n c r e a s e t o a t m o s t 0 b y t h e n e x t   i  - o p p o r t u n i t y , t o a t m o s t 1 b y  

t h e t h i r d   i  - o p p o r t u n i t y , a n d t o a t m o s t 2 b y t h e f o u r t h   i  - o p p o r t u n i t y , n o n e o f w h i c h r e q u i r e s  

a c a r r y .  

9 . F u r t h e r O p t i m i z a t i o n  

O u r o v e r r i d i n g o b j e c t i v e s o f a r h a s b e e n t o k e e p t h e s i m u l a t i o n s i m p l e . A t t h e e x p e n s e  

o f s o m e c l a r i t y , h o w e v e r , w e c a n m a k e t h e s i m u l a t i o n e v e n m o r e e c i e n t .  

T h e r e i s o n e e a s y w a y t o s a v e s p a c e i n t h e s i m u l a t i o n a s p r e s e n t e d a b o v e . P o s i t i o n s  

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

n e e d n o t b e e n c o d e d s e p a r a t e l y . B y s u i t a b l e e n c o d i n g , t h e r e f o r e , t h e s p a c e u s e d c a n b e k e p t  

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

6 +  k  l o g 

1 4 ) l o g  

n    ( 1  :  6 3 + 2  :  4 0  k  ) l o g  

n  . 

A m o r e s u b t l e o b s e r v a t i o n l e a d s t o s a v i n g e v e n m o r e s p a c e . B e c a u s e e a c h r a d i x - 4  

s i g n e d d i g i t i s b o u n d e d b y 3 i n a b s o l u t e v a l u e , t h e n u m b e r o f   s i g n i c a n t   s i g n e d d i g i t s i n  

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

t h e c o u n t e r ' s c o n t e n t s . W i t h c a r e , t h e r e f o r e , w e m i g h t h o p e t o l i m i t t h e n u m b e r o f p o s i t i o n s  

i n v o l v e d i n o u r s i m u l a t i o n t o t h e b a s e - 4 l o g a r i t h m o f t h e l a r g e s t c o u n t e r c o n t e n t s s o f a r .  

E v e n i n t h e w o r s t c a s e t h a t t h e l a r g e s t c o u n t e r c o n t e n t s a f t e r t h e r s t   n  s t e p s i s   n  , t h i s  

w o u l d r e d u c e s p a c e u s a g e b y a f a c t o r o f l o g  

n =  l o g 

n    :  7 9 . 

O n e w a y t o t a k e a d v a n t a g e o f t h i s p o t e n t i a l i s t o i n s e r t s o m e e x t r a p a i r s o f n e g a t i v e  

i  - t o u r s r i g h t b e f o r e t h e p o s i t i v e   i  - t o u r t h a t r s t t r a n s p o r t s a n d i n v o l v e s p o s i t i o n   i  + 1 . ( T h e  

r s t h a l f o f e a c h s u c h p a i r p e r m u t e s f r o m   i : : :  2 1 0    (  i  + 1 ) (  i  + 2 )  : : :  b a c k t o t h e o r i g i n a l  

c o n g u r a t i o n     0 1 2  : : : i  (  i  + 1 ) (  i  + 2 )  : : :  , a n d t h e s e c o n d h a l f p e r m u t e s u p t o   i : : :  2 1 0   

(  i  + 1 ) (  i  + 2 )  : : :  a g a i n . ) T o d o t h i s , w e n e e d o n l y d e c i d e a t t h e t i m e w e w o u l d n o r m a l l y  

r s t i n v o l v e a n e w p o s i t i o n   i  + 1 ( w i t h a p o s i t i v e 0 - t o u r ) w h e t h e r t o s t a r t a n e g a t i v e   i  - t o u r  

i n s t e a d ( w i t h a   n e g a t i v e   0 - t o u r ) . W e w i l l w a n t t o i n v o l v e p o s i t i o n   i  + 1 i f a n d o n l y i f a  

s i g n i c a n t s i g n e d d i g i t i s a l r e a d y w i t h i n a f e w p o s i t i o n s o f p o s i t i o n   i  + 1 . 

1 3 

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 14/15

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

p o s i t i o n i s \ r i p e " f o r i n v o l v e m e n t , a n d w e n e e d a p p r o p r i a t e o p p o r t u n i t i e s t o m a r k u n i n v o l v e d  

p o s i t i o n s r i p e . I f   i  + 1 i s t h e r s t u n i n v o l v e d p o s i t i o n , t h e n s u c h a n o p p o r t u n i t y a r i s e s e a c h  

t i m e w e r e a c h t h e c o n g u r a t i o n (  i  ?  3 )  : : :  2 1 0    (  i  ?  2 ) (  i  ?  1 )  i  (  i  + 1 )  : : :  , s a y . I t f o l l o w s  

f r o m t h e e a s y - t o - c h e c k i n d u c t i v e o b s e r v a t i o n b e l o w t h a t d i r e c t i o n a l i n f o r m a t i o n w i l l s u c e  

t o i d e n t i f y t h i s s i t u a t i o n u n a m b i g u o u s l y . I f s i g n i c a n c e h a s a l r e a d y r e a c h e d p o s i t i o n   i  ?  2 , 

s a y , t h e n p o s i t i o n   i  + 1 c a n b e m a r k e d n a l l y a s r i p e f o r i n v o l v e m e n t , a n d i t w i l l b e c o m e  

i n v o l v e d i n t i m e t o r e c e i v e t h e r s t c a r r y f r o m p o s i t i o n   i  . 

O b s e r v a t i o n 6 .   A t a n y t i m e i n t h e p e r m u t a t i o n p r o c e s s , i f  

? ! 

a b  o c c u r s a n y w h e r e t o t h e  

r i g h t o f t h e h e a d ( o r , s y m m e t r i c a l l y , i f   b 

a  o c c u r s a n y w h e r e t o t h e l e f t o f t h e h e a d ) , w i t h a  

p r i m e o r d o u b l e - p r i m e m e s s a g e a t t a c h e d t o n e i t h e r   a  n o r  b  , a n d i f t h e p o s i t i o n n u m b e r o f   a 

i s  i  , t h e n t h e p o s i t i o n n u m b e r o f   b  i s  i  + 1  . 

A t t h e e x p e n s e o f o b l i v i o u s n e s s , t h i s y i e l d s a r e a l - t i m e m u l t i c o u n t e r s i m u l a t i o n t h a t u s e s  

s p a c e o n l y l o g a r i t h m i c i n t h e   m a x i m u m   c o u n t e r c o n t e n t s . I t r e d u c e s t h e w o r s t - c a s e s p a c e f o r  

a r e a l - t i m e s i m u l a t i o n o f   k  c o u n t e r s t o a b o u t ( l o g  

6 +  k  l o g 

1 5 ) l o g  

n    ( 1  :  2 9 + 1  :  9 5  k  ) l o g  

n  . 

A l t h o u g h , w i t h a s l i g h t l y d i e r e n t d e s i g n a t i o n o f   i  - o p p o r t u n i t i e s , w e c o u l d r e d u c e t h e  

r a d i x f o r o u r s i m u l a t i o n ' s r a d i x n o t a t i o n d o w n t o 3 , i t t u r n s o u t t o b e m o r e s p a c e - e c i e n t  

t o u s e a   l a r g e r   r a d i x . A t t h e m e r e e x p e n s e o f a d d i t i o n a l c o n t r o l s t a t e s , t h i s w i l l r e d u c e  

t h e n u m b e r o f b i t s u s e d f o r u n d e r l i n e s , m e s s a g e s , a n d o v e r a r r o w s . R e p e a t i n g t h e a n a l y s i s  

s k e t c h e d a b o v e , b u t n o w f o r a n a r b i t r a r y r a d i x   r  , w e g e t a s p a c e b o u n d o f  

( l o g  

6 +  k  l o g 

( 2 ( 2   r  ?  1 ) + 1 ) ) l o g  

n    (  k  + ( l o g  

6 + 2  k  )  =  l o g 

r  ) l o g  

n : 

F o r e a c h   >  0 , t h e r e f o r e , w e c a n u s e a r a d i x   r  s o l a r g e t h a t (  k  +    ) l o g  

n  b i t s w i l l s u c e  

f o r e v e r y   k  . 

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

S i n c e t h e c o u n t e r w i t h t h e l a r g e s t c o n t e n t s d e t e r m i n e s h e a d m o t i o n , t h e s i m u l a t o r w i l l b e  

o b l i v i o u s i f i t s i m u l a t e s o n e e x t r a , d o m i n a n t c o u n t e r o f i t s o w n , i n c r e m e n t i n g i t a t e v e r y  

s t e p . T h i s y i e l d s a s p a c e b o u n d o f (  k  + 1 +    ) l o g  

n  b i t s f o r o b l i v i o u s r e a l - t i m e s i m u l a t i o n  

o f  k  c o u n t e r s .  

A c k n o w l e d g m e n t s .   W e t h a n k L a u r a S a n c h i s f o r c r i t i c i z i n g a n e a r l y d r a f t o f t h e p a p e r , a n d J a n i e  

I r w i n f o r p r o v i d i n g r e f e r e n c e s 1 { 2 ] . P e t e r G  a c s r s t s u g g e s t e d t h a t t h e s p a c e u s e d b y a n o n o b l i v i o u s  

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

T h e r e s u l t o f t h e r s t 2 , 9 8 0 , 0 0 0 t r a n s i t i o n s w a s o b t a i n e d b y a n i m p l e m e n t a t i o n o f t h e s i m u l a t i o n  

i n P C S c h e m e , a n d l a t e r c h e c k e d i n d e p e n d e n t l y b y J o h n T r o m p ' s i m p l e m e n t a t i o n i n C .  

R e f e r e n c e s  

1 . D . E . A t k i n s ,   I n t r o d u c t i o n t o t h e r o l e o f r e d u n d a n c y i n c o m p u t e r a r i t h m e t i c  , C o m -  

p u t e r   8  , 6 ( J u n e 1 9 7 5 ) , 7 4 { 7 7 .  

2 . A . A v i z i e n i s ,   S i g n e d - d i g i t n u m b e r r e p r e s e n t a t i o n s f o r f a s t p a r a l l e l a r i t h m e t i c  , I R E  

T r a n s a c t i o n s o n E l e c t r o n i c C o m p u t e r s   E C - 1 0  , 3 ( S e p t e m b e r 1 9 6 1 ) , 3 8 9 { 4 0 0 .  

3 . P . C u l l a n d E . F . E c k l u n d , J r . ,   T o w e r s o f H a n o i a n d a n a l y s i s o f a l g o r i t h m s  , T h e  

A m e r i c a n M a t h e m a t i c a l M o n t h l y   9 2  , 6 ( J u n e { J u l y 1 9 8 5 ) , 4 0 7 { 4 2 0 .  

1 4 

8/6/2019 10.1.1.51.5266

http://slidepdf.com/reader/full/1011515266 15/15

4 . M . J . F i s c h e r a n d A . L . R o s e n b e r g ,  R e a l - t i m e s o l u t i o n s o f t h e o r i g i n - c r o s s i n g p r o b l e m   , 

M a t h e m a t i c a l S y s t e m s T h e o r y   2  , 3 ( S e p t e m b e r 1 9 6 8 ) , 2 5 7 { 2 6 3 .  

5 . P . C . F i s c h e r , A . R . M e y e r , a n d A . L . R o s e n b e r g ,   C o u n t e r m a c h i n e s a n d c o u n t e r  

l a n g u a g e s  , M a t h e m a t i c a l S y s t e m s T h e o r y   2  , 3 ( S e p t e m b e r 1 9 6 8 ) , 2 6 5 { 2 8 3 .  

6 . P . C . F i s c h e r , A . R . M e y e r , a n d A . L . R o s e n b e r g ,  T i m e - r e s t r i c t e d s e q u e n c e g e n e r a -  

t i o n   , J o u r n a l o f C o m p u t e r a n d S y s t e m S c i e n c e s   4  , 1 ( F e b r u a r y 1 9 7 0 ) , 5 0 { 7 3 .  

7 . M . F  u r e r ,   D a t a s t r u c t u r e s f o r d i s t r i b u t e d c o u n t i n g  , J o u r n a l o f C o m p u t e r a n d S y s t e m  

S c i e n c e s   2 8  , 2 ( A p r i l 1 9 8 4 ) , 2 3 1 { 2 4 3 .  

8 . F . C . H e n n i e a n d R . E . S t e a r n s ,   T w o - t a p e s i m u l a t i o n o f m u l t i t a p e T u r i n g m a c h i n e s  , 

J o u r n a l o f t h e A s s o c i a t i o n f o r C o m p u t i n g M a c h i n e r y   1 3  , 4 ( O c t o b e r 1 9 6 6 ) , 5 3 3 { 5 4 6 .  

9 . N . P i p p e n g e r a n d M . J . F i s c h e r ,   R e l a t i o n s a m o n g c o m p l e x i t y m e a s u r e s  , J o u r n a l o f  

t h e A s s o c i a t i o n f o r C o m p u t i n g M a c h i n e r y   2 6  , 2 ( A p r i l 1 9 7 9 ) , 3 6 1 { 3 8 1 .  

1 0 . P . M . B . V i t  a n y i ,   A n o p t i m a l s i m u l a t i o n o f c o u n t e r m a c h i n e s  , S I A M J o u r n a l o n  

C o m p u t i n g   1 4  , 1 ( F e b r u a r y 1 9 8 5 ) , 1 { 3 3 .  

1 1 . P . M . B . V i t  a n y i ,   A n o p t i m a l s i m u l a t i o n o f c o u n t e r m a c h i n e s : t h e A C M c a s e  , 

S I A M J o u r n a l o n C o m p u t i n g   1 4  , 1 ( F e b r u a r y 1 9 8 5 ) , 3 4 { 4 0 .  

1 5