Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -4,7 +4,7 @@ F run_utm(halt, state, Char blank; rules_in, [Char] &tape = [Char](); =pos = 0)
|
|||
tape.append(blank)
|
||||
I pos < 0
|
||||
pos += tape.len
|
||||
V rules = Dict(rules_in, r -> ((r[0], Char(r[1])), (Char(r[2]), r[3], r[4])))
|
||||
V rules = Dict(rules_in, r -> ((r[0], Char(string' r[1])), (Char(string' r[2]), r[3], r[4])))
|
||||
|
||||
L
|
||||
print(st.ljust(4), end' ‘ ’)
|
||||
|
|
@ -39,8 +39,8 @@ run_utm(
|
|||
halt' ‘qf’,
|
||||
state' ‘q0’,
|
||||
blank' Char(‘B’),
|
||||
rules_in' [‘q0 1 1 right q0’.split(‘ ’, group_delimiters' 1B),
|
||||
‘q0 B 1 stay qf’.split(‘ ’, group_delimiters' 1B)],
|
||||
rules_in' [‘q0 1 1 right q0’.split_sg(),
|
||||
‘q0 B 1 stay qf’.split_sg()],
|
||||
tape' &[‘1’, ‘1’, ‘1’]
|
||||
)
|
||||
|
||||
|
|
@ -50,12 +50,12 @@ run_utm(
|
|||
state' ‘a’,
|
||||
blank' Char(‘0’),
|
||||
rules_in'
|
||||
[‘a 0 1 right b’.split(‘ ’, group_delimiters' 1B),
|
||||
‘a 1 1 left c’.split(‘ ’, group_delimiters' 1B),
|
||||
‘b 0 1 left a’.split(‘ ’, group_delimiters' 1B),
|
||||
‘b 1 1 right b’.split(‘ ’, group_delimiters' 1B),
|
||||
‘c 0 1 left b’.split(‘ ’, group_delimiters' 1B),
|
||||
‘c 1 1 stay halt’.split(‘ ’, group_delimiters' 1B)]
|
||||
[‘a 0 1 right b’.split_sg(),
|
||||
‘a 1 1 left c’.split_sg(),
|
||||
‘b 0 1 left a’.split_sg(),
|
||||
‘b 1 1 right b’.split_sg(),
|
||||
‘c 0 1 left b’.split_sg(),
|
||||
‘c 1 1 stay halt’.split_sg()]
|
||||
)
|
||||
|
||||
print("\nsorting test\n")
|
||||
|
|
@ -64,19 +64,19 @@ run_utm(
|
|||
state' ‘A’,
|
||||
blank' Char(‘0’),
|
||||
rules_in'
|
||||
[‘A 1 1 right A’.split(‘ ’, group_delimiters' 1B),
|
||||
‘A 2 3 right B’.split(‘ ’, group_delimiters' 1B),
|
||||
‘A 0 0 left E’.split(‘ ’, group_delimiters' 1B),
|
||||
‘B 1 1 right B’.split(‘ ’, group_delimiters' 1B),
|
||||
‘B 2 2 right B’.split(‘ ’, group_delimiters' 1B),
|
||||
‘B 0 0 left C’.split(‘ ’, group_delimiters' 1B),
|
||||
‘C 1 2 left D’.split(‘ ’, group_delimiters' 1B),
|
||||
‘C 2 2 left C’.split(‘ ’, group_delimiters' 1B),
|
||||
‘C 3 2 left E’.split(‘ ’, group_delimiters' 1B),
|
||||
‘D 1 1 left D’.split(‘ ’, group_delimiters' 1B),
|
||||
‘D 2 2 left D’.split(‘ ’, group_delimiters' 1B),
|
||||
‘D 3 1 right A’.split(‘ ’, group_delimiters' 1B),
|
||||
‘E 1 1 left E’.split(‘ ’, group_delimiters' 1B),
|
||||
‘E 0 0 right STOP’.split(‘ ’, group_delimiters' 1B)],
|
||||
[‘A 1 1 right A’.split_sg(),
|
||||
‘A 2 3 right B’.split_sg(),
|
||||
‘A 0 0 left E’.split_sg(),
|
||||
‘B 1 1 right B’.split_sg(),
|
||||
‘B 2 2 right B’.split_sg(),
|
||||
‘B 0 0 left C’.split_sg(),
|
||||
‘C 1 2 left D’.split_sg(),
|
||||
‘C 2 2 left C’.split_sg(),
|
||||
‘C 3 2 left E’.split_sg(),
|
||||
‘D 1 1 left D’.split_sg(),
|
||||
‘D 2 2 left D’.split_sg(),
|
||||
‘D 3 1 right A’.split_sg(),
|
||||
‘E 1 1 left E’.split_sg(),
|
||||
‘E 0 0 right STOP’.split_sg()],
|
||||
tape' &‘2 2 2 1 2 2 1 2 1 2 1 2 1 2’.split(‘ ’).map(Char)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
private with Ada.Containers.Doubly_Linked_Lists;
|
||||
|
||||
generic
|
||||
type State is (<>); -- State'First is starting state
|
||||
type Symbol is (<>); -- Symbol'First is blank
|
||||
package Turing is
|
||||
|
||||
Start: constant State := State'First;
|
||||
Halt: constant State := State'Last;
|
||||
subtype Action_State is State range Start .. State'Pred(Halt);
|
||||
|
||||
Blank: constant Symbol := Symbol'First;
|
||||
|
||||
type Movement is (Left, Stay, Right);
|
||||
|
||||
type Action is record
|
||||
New_State: State;
|
||||
Move_To: Movement;
|
||||
New_Symbol: Symbol;
|
||||
end record;
|
||||
|
||||
type Rules_Type is array(Action_State, Symbol) of Action;
|
||||
|
||||
type Tape_Type is limited private;
|
||||
|
||||
type Symbol_Map is array(Symbol) of Character;
|
||||
|
||||
function To_String(Tape: Tape_Type; Map: Symbol_Map) return String;
|
||||
function Position_To_String(Tape: Tape_Type; Marker: Character := '^')
|
||||
return String;
|
||||
function To_Tape(Str: String; Map: Symbol_Map) return Tape_Type;
|
||||
|
||||
procedure Single_Step(Current: in out State;
|
||||
Tape: in out Tape_Type;
|
||||
Rules: Rules_Type);
|
||||
|
||||
procedure Run(The_Tape: in out Tape_Type;
|
||||
Rules: Rules_Type;
|
||||
Max_Steps: Natural := Natural'Last;
|
||||
Print: access procedure(Tape: Tape_Type; Current: State));
|
||||
-- runs from Start State until either Halt or # Steps exceeds Max_Steps
|
||||
-- if # of steps exceeds Max_Steps, Constrained_Error is raised;
|
||||
-- if Print is not null, Print is called at the beginning of each step
|
||||
|
||||
private
|
||||
package Symbol_Lists is new Ada.Containers.Doubly_Linked_Lists(Symbol);
|
||||
subtype List is Symbol_Lists.List;
|
||||
|
||||
type Tape_Type is record
|
||||
Left: List;
|
||||
Here: Symbol;
|
||||
Right: List;
|
||||
end record;
|
||||
end Turing;
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
package body Turing is
|
||||
|
||||
function List_To_String(L: List; Map: Symbol_Map) return String is
|
||||
LL: List := L;
|
||||
use type List;
|
||||
begin
|
||||
if L = Symbol_Lists.Empty_List then
|
||||
return "";
|
||||
else
|
||||
LL.Delete_First;
|
||||
return Map(L.First_Element) & List_To_String(LL, Map);
|
||||
end if;
|
||||
end List_To_String;
|
||||
|
||||
function To_String(Tape: Tape_Type; Map: Symbol_Map) return String is
|
||||
|
||||
begin
|
||||
return List_To_String(Tape.Left, Map) & Map(Tape.Here) &
|
||||
List_To_String(Tape.Right, Map);
|
||||
end To_String;
|
||||
|
||||
function Position_To_String(Tape: Tape_Type; Marker: Character := '^')
|
||||
return String is
|
||||
Blank_Map: Symbol_Map := (others => ' ');
|
||||
begin
|
||||
return List_To_String(Tape.Left, Blank_Map) & Marker &
|
||||
List_To_String(Tape.Right, Blank_Map);
|
||||
end Position_To_String;
|
||||
|
||||
function To_Tape(Str: String; Map: Symbol_Map) return Tape_Type is
|
||||
Char_Map: array(Character) of Symbol := (others => Blank);
|
||||
Tape: Tape_Type;
|
||||
begin
|
||||
if Str = "" then
|
||||
Tape.Here := Blank;
|
||||
else
|
||||
for S in Symbol loop
|
||||
Char_Map(Map(S)) := S;
|
||||
end loop;
|
||||
Tape.Here := Char_Map(Str(Str'First));
|
||||
for I in Str'First+1 .. Str'Last loop
|
||||
Tape.Right.Append(Char_Map(Str(I)));
|
||||
end loop;
|
||||
end if;
|
||||
return Tape;
|
||||
end To_Tape;
|
||||
|
||||
procedure Single_Step(Current: in out State;
|
||||
Tape: in out Tape_Type;
|
||||
Rules: Rules_Type) is
|
||||
Act: Action := Rules(Current, Tape.Here);
|
||||
use type List; -- needed to compare Tape.Left/Right to the Empty_List
|
||||
begin
|
||||
Current := Act.New_State; -- 1. update State
|
||||
Tape.Here := Act.New_Symbol; -- 2. write Symbol to Tape
|
||||
case Act.Move_To is -- 3. move Tape to the Left/Right or Stay
|
||||
when Left =>
|
||||
Tape.Right.Prepend(Tape.Here);
|
||||
if Tape.Left /= Symbol_Lists.Empty_List then
|
||||
Tape.Here := Tape.Left.Last_Element;
|
||||
Tape.Left.Delete_Last;
|
||||
else
|
||||
Tape.Here := Blank;
|
||||
end if;
|
||||
when Stay =>
|
||||
null; -- Stay where you are!
|
||||
when Right =>
|
||||
Tape.Left.Append(Tape.Here);
|
||||
if Tape.Right /= Symbol_Lists.Empty_List then
|
||||
Tape.Here := Tape.Right.First_Element;
|
||||
Tape.Right.Delete_First;
|
||||
else
|
||||
Tape.Here := Blank;
|
||||
end if;
|
||||
end case;
|
||||
end Single_Step;
|
||||
|
||||
procedure Run(The_Tape: in out Tape_Type;
|
||||
Rules: Rules_Type;
|
||||
Max_Steps: Natural := Natural'Last;
|
||||
Print: access procedure (Tape: Tape_Type; Current: State)) is
|
||||
The_State: State := Start;
|
||||
Steps: Natural := 0;
|
||||
begin
|
||||
Steps := 0;
|
||||
while (Steps <= Max_Steps) and (The_State /= Halt) loop
|
||||
if Print /= null then
|
||||
Print(The_Tape, The_State);
|
||||
end if;
|
||||
Steps := Steps + 1;
|
||||
Single_Step(The_State, The_Tape, Rules);
|
||||
end loop;
|
||||
if The_State /= Halt then
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
end Run;
|
||||
|
||||
end Turing;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
with Ada.Text_IO, Turing;
|
||||
|
||||
procedure Simple_Incrementer is
|
||||
|
||||
type States is (Start, Stop);
|
||||
type Symbols is (Blank, One);
|
||||
|
||||
package UTM is new Turing(States, Symbols);
|
||||
use UTM;
|
||||
|
||||
Map: Symbol_Map := (One => '1', Blank => '_');
|
||||
|
||||
Rules: Rules_Type :=
|
||||
(Start => (One => (Start, Right, One),
|
||||
Blank => (Stop, Stay, One)));
|
||||
Tape: Tape_Type := To_Tape("111", Map);
|
||||
|
||||
procedure Put_Tape(Tape: Tape_Type; Current: States) is
|
||||
begin
|
||||
Ada.Text_IO.Put_Line(To_String(Tape, Map) & " " & States'Image(Current));
|
||||
Ada.Text_IO.Put_Line(Position_To_String(Tape));
|
||||
end Put_Tape;
|
||||
|
||||
begin
|
||||
Run(Tape, Rules, 20, null); -- don't print the configuration during running
|
||||
Put_Tape(Tape, Stop); -- print the final configuration
|
||||
end Simple_Incrementer;
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
with Ada.Text_IO, Turing;
|
||||
|
||||
procedure Busy_Beaver_3 is
|
||||
|
||||
type States is (A, B, C, Stop);
|
||||
type Symbols is range 0 .. 1;
|
||||
package UTM is new Turing(States, Symbols); use UTM;
|
||||
|
||||
Map: Symbol_Map := (1 => '1', 0 => '0');
|
||||
|
||||
Rules: Rules_Type :=
|
||||
(A => (0 => (New_State => B, Move_To => Right, New_Symbol => 1),
|
||||
1 => (New_State => C, Move_To => Left, New_Symbol => 1)),
|
||||
B => (0 => (New_State => A, Move_To => Left, New_Symbol => 1),
|
||||
1 => (New_State => B, Move_To => Right, New_Symbol => 1)),
|
||||
C => (0 => (New_State => B, Move_To => Left, New_Symbol => 1),
|
||||
1 => (New_State => Stop, Move_To => Stay, New_Symbol => 1)));
|
||||
|
||||
Tape: Tape_Type := To_Tape("", Map);
|
||||
|
||||
procedure Put_Tape(Tape: Tape_Type; Current: States) is
|
||||
begin
|
||||
Ada.Text_IO.Put_Line(To_String(Tape, Map) & " " &
|
||||
States'Image(Current));
|
||||
Ada.Text_IO.Put_Line(Position_To_String(Tape));
|
||||
end Put_Tape;
|
||||
|
||||
begin
|
||||
Run(Tape, Rules, 20, Put_Tape'Access); -- print configuration before each step
|
||||
Put_Tape(Tape, Stop); -- and print the final configuration
|
||||
end Busy_Beaver_3;
|
||||
Loading…
Add table
Add a link
Reference in a new issue