-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturing-add.txt
67 lines (46 loc) · 1.33 KB
/
turing-add.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
stype Tape = +{ 0: Tape, 1: Tape, $: 1 }
proc hd WRITE :: {Tape -| Tape} =
{ caseR of
0 => 1 – (hd ERASE)
| 1 => 1 – (hd ERASE)
| $ => waitR; (hd WRITE) – 0 – $ }
proc hd ERASE :: {Tape -| Tape} =
{ caseR of
0 => 0 – (hd WRITE)
| 1 => 0 – (hd WRITE)
| $ => waitR; (hd ERASE) – 0 – $ }
stype Tape = +{ 0: Tape, 1: Tape, $: 1 }
stype Tape' true = &{ 0: Tape' false, 1: Tape' true }
| Tape' false = &{ 0: Tape, 1: Tape' false }
proc 0 :: {Tape -| Tape} =
{ selectL 0; <-> }
proc 1 :: {Tape -| Tape} = ...
proc $ :: {Tape -|} =
{ selectL $; closeL }
proc 0' true :: {Tape' false -| Tape' true} =
{ selectR 0; <-> }
proc 0' false :: {Tape -| Tape' false} =
{ selectR 0; <-> }
proc 1' :: {Tape' z? -| Tape' z?} =
{ selectR 1; <-> }
proc hd COPY :: {Tape -| Tape} =
{ caseR of
0 => <->
| 1 => (0' false) – (hd (MVR false))
| $ => waitR; (hd COPY) – 0 – $ }
proc hd (MVR z?) :: {Tape' z? -| Tape} =
{ caseR of
0 => if z?
then (hd (MVL true)) – 1
else (0' true) – (hd (MVR true))
| 1 => (1' z?) – (hd (MVR z?))
| $ => waitR; (hd (MVR z?)) – 0 – $ }
proc hd (MVL z?) :: {Tape' z? -| Tape} =
{ caseL of
0 => if z?
then (hd (MVL false)) – 0
else 1 – (hd COPY)
| 1 => (hd (MVL z?)) – 1 }
proc hd S =
{ caseR of
0 => (hd S') –