Read Understanding Computation Online

Authors: Tom Stuart

Tags: #COMPUTERS / Programming / General

Understanding Computation (46 page)

BOOK: Understanding Computation
13.15Mb size Format: txt, pdf, ePub
ads

Now we can put everything together to implement an overall
#to_cyclic
method for a
TagRulebook
, then use it in a
TagSystem#to_cyclic
method that converts both
the rulebook and the current string to yield a complete cyclic tag
system:

class
TagRulebook
def
to_cyclic
(
encoder
)
CyclicTagRulebook
.
new
(
cyclic_rules
(
encoder
)
+
cyclic_padding_rules
(
encoder
))
end
end
class
TagSystem
def
to_cyclic
TagSystem
.
new
(
encoder
.
encode_string
(
current_string
),
rulebook
.
to_cyclic
(
encoder
))
end
end

Here’s what happens when we convert our number-incrementing tag
system and run it:

>>
cyclic_system
=
system
.
to_cyclic
=> #
>>
cyclic_system
.
run
100010000100010001000100
(
aabbbb
)
000100001000100010001000010001000010001
00100001000100010001000010001000010001
0100001000100010001000010001000010001
100001000100010001000010001000010001
(
abbbbccdd
)
00001000100010001000010001000010001
0001000100010001000010001000010001
001000100010001000010001000010001
01000100010001000010001000010001
(
bbbbccdd
)
1000100010001000010001000010001
00010001000100001000100001000100010001
0010001000100001000100001000100010001
010001000100001000100001000100010001
(
bbbccdddd
)
10001000100001000100001000100010001
0001000100001000100001000100010001
001000100001000100001000100010001
01000100001000100001000100010001
(
bbccdddd
)
1000100001000100001000100010001
00010000100010000100010001000100010001
0010000100010000100010001000100010001
010000100010000100010001000100010001
(
bccdddddd
)
10000100010000100010001000100010001
0000100010000100010001000100010001
000100010000100010001000100010001
00100010000100010001000100010001
(
ccdddddd
)
0100010000100010001000100010001
100010000100010001000100010001
00010000100010001000100010001

001
01
1
=> nil

The encoded version of the tag system’s
a
rule kicks in here.

The first full character of the simulated string has been
processed, so the following four steps use blank rules to delete the
next simulated character.

After eight steps of the cyclic tag system, one full step of the
simulated tag system is complete.

The encoded
b
rule is
triggered here…

…and again here.

Twenty-four steps into the cyclic tag system computation, and we
reach the representation of the simulated tag system’s final string,
ccdddddd
.

The simulated tag system has no rules for strings beginning with
c
or
d
, so the cyclic tag system’s current string
keeps getting shorter and shorter…

…until it becomes empty, and the system halts.

BOOK: Understanding Computation
13.15Mb size Format: txt, pdf, ePub
ads

Other books

Ball Peen Hammer by Lauren Rowe
The Arm by Jeff Passan
Healing Faith by Jennyfer Browne
From Where I Watch You by Shannon Grogan
Lunch-Box Dream by Tony Abbott
Give Me Fever by Niobia Bryant
Hours of Gladness by Thomas Fleming
Sebastian - Secrets by Rosen, Janey