TuringSim
C++ framework to simulate abstract computing models
utm.cpp
1 #include <machine/Turing/utm.h>
2 
5  TransitionSetType transitions;
6  transitions.merge(makeFind());
7  transitions.merge(makeErase());
8  transitions.merge(makePrintAtEnd());
9  transitions.merge(makeFindAndMove());
10  transitions.merge(makeCopy());
11  transitions.merge(makeCopyAndErase());
12  transitions.merge(makeReplace());
13  transitions.merge(makeComparison());
14  transitions.merge(makeFindLast());
15  transitions.merge(makeE());
16  transitions.merge(makeCon());
17  transitions.merge(makeInit());
18  transitions.merge(makeSim());
19  transitions.merge(makeMf());
20  transitions.merge(makeSh());
21  transitions.merge(makeInst());
22 
23  UtmType machine {
24  {std::make_shared<const State::MConfiguration::MConfiguration<std::string>>("b")},
25  {},
26  {transitions.begin(), transitions.end()}
27  };
28  return machine;
29  }
30 
32  TransitionSetType transitions{
33  {"f(_E, _B, _a)", "|", "L", "#", "f1(_E, _B, _a)"},
34  {"f(_E, _B, _a)", "non(|)", "L", "#", "f(_E, _B, _a)"},
35  {"f1(_E, _B, _a)", "none", "R", "#", "f2(_E, _B, _a)"},
36  {"f1(_E, _B, _a)", "_a", "", "#", "_E"},
37  {"f1(_E, _B, _a)", "non(_a, none)", "R", "#", "f1(_E, _B, _a)"},
38  {"f2(_E, _B, _a)", "none", "R", "#", "_B"},
39  {"f2(_E, _B, _a)", "_a", "N", "#", "_E"},
40  {"f2(_E, _B, _a)", "non(_a, none)", "R", "#", "f1(_E, _B, _a)"},
41  };
42  return transitions;
43  }
44 
46  TransitionSetType transitions{
47  {"e(_E, _B, _a)", "", "", "#", "f(e1(_E, _B, _a), _B, _a)"},
48  {"e1(_E, _B, _a)", "", "E", "#", "_E"},
49  {"e(_B, _a)", "", "", "#", "e(e(_B, _a), _B, _a)"},
50  };
51  return transitions;
52  }
53 
55  TransitionSetType transitions{
56  {"pe(_E, _b)", "", "", "#", "f(pe1(_E, _b), _E, |)"},
57  {"pe1(_E, _b)", "none", "I _b", "#", "_E"},
58  {"pe1(_E, _b)", "any", "R, R", "#", "pe1(_E, _b)"},
59  {"pe2(_E, _a, _b)", "", "", "#", "pe(pe(_E, _b), _a)"},
60  };
61  return transitions;
62  }
63 
65  TransitionSetType transitions{
66  {"l(_E)", "", "L", "#", "_E"},
67  {"r(_E)", "", "R", "#", "_E"},
68  {"f'(_E, _B, _a)", "", "", "#", "f(l(_E), _B, _a)"},
69  {"f''(_E, _B, _a)", "", "", "#", "f(r(_E), _B, _a)"},
70  };
71  return transitions;
72  }
73 
75  TransitionSetType transitions{
76  {"c(_E, _B, _a)", "", "", "#", "f'(c1(_E), _B, _a)"},
77  {"c1(_E)", "", "", "#", "pe(_E, _#)"},
78  };
79  return transitions;
80  }
81 
83  TransitionSetType transitions{
84  {"ce(_E, _B, _a)", "", "", "#", "c(e(_E, _B, _a), _B, _a)"},
85  {"ce(_B, _a)", "", "", "#", "ce(ce(_B, _a), _B, _a)"},
86  {"ce(_B, _a)", "", "", "#", "ce(ce(_B, _a), _B, _a)"},
87  {"ce2(_B, _a, _b)", "", "", "#", "ce(ce(_B, _b), _a)"},
88  {"ce3(_B, _a, _b, _c)", "", "", "#", "ce(ce2(_B, _b, _c), _a)"},
89  {"ce4(_B, _a, _b, _c, _d)", "", "", "#", "ce(ce3(_B, _b, _c, _d), _a)"},
90  {"ce5(_B, _a, _b, _c, _d, _e)", "", "", "#", "ce(ce4(_B, _b, _c, _d, _e), _a)"},
91 
92  };
93  return transitions;
94  }
95 
97  TransitionSetType transitions{
98  {"re(_E, _B, _a, _b)", "", "", "#", "f(re1(_E, _B, _a, _b), _B, _a)"},
99  {"re1(_E, _B, _a, _b)", "", "E, I _b", "#", "_E"},
100  {"re(_B, _a, _b)", "", "", "#", "re(re(_B, _a, _b), _B, _a, _b)"},
101  };
102  return transitions;
103  }
104 
106  TransitionSetType transitions{
107  {"cp(_E1, _U, _E, _a, _b)", "", "", "#", "f'(cp1(_E1, _U, _b), f(_U, _E, _b), _a)"},
108  {"cp1(_E, _U, _b)", "", "", "#", "f'(cp2(_E, _U, _#), _U, _b)"},
109  {"cp2(_E, _U, _c)", "_c", "", "#", "_E"},
110  {"cp2(_E, _U, _c)", "non(_c, none)", "", "#", "_U"},
111  {"cpe(_E1, _U, _E, _a, _b)", "", "", "#", "cp(e(e(_E1, _E, _b), _E, _a), _U, _E, _a, _b)"},
112  {"cpe(_U, _E, _a, _b)", "", "", "#", "cpe(cpe(_U, _E, _a, _b), _U, _E, _a, _b)"},
113  };
114  return transitions;
115  }
116 
118  TransitionSetType transitions{
119  {"q(_E)", "none", "R", "#", "q1(_E)"},
120  {"q(_E)", "any", "R", "#", "q(_E)"},
121  {"q1(_E)", "none", "R", "#", "_E"},
122  {"q1(_E)", "any", "", "#", "q(_E)"},
123  {"q(_E, _a)", "", "", "#", "q(q1(_E, _a))"},
124  {"q1(_E, _a)", "_a", "", "#", "_E"},
125  {"q1(_E, _a)", "non(_a)", "L", "#", "q1(_E, _a)"},
126  };
127  return transitions;
128  }
129 
131  TransitionSetType transitions{
132  {"e(anf)", "|", "R", "#", "e1(anf)"},
133  {"e(anf)", "non(|)", "L", "#", "e(anf)"},
134  {"e1(anf)", "none", "", "#", "anf"},
135  {"e1(anf)", "any", "R, E, R", "#", "e1(anf)"},
136  };
137  return transitions;
138  }
139 
141  TransitionSetType transitions{
142  {"con(_E, _a)", "non(A)", "R, R", "#", "con(_E, _a)"},
143  {"con(_E, _a)", "A", "L, I _a, R", "#", "con1(_E, _a)"},
144  {"con1(_E, _a)", "A", "R, I _a, R", "#", "con1(_E, _a)"},
145  {"con1(_E, _a)", "C", "R, I _a, R", "#", "con2(_E, _a)"},
146  {"con1(_E, _a)", "none", "I C, R, I _a, R, R, R", "#", "_E"},
147  {"con2(_E, _a)", "B", "R, I _a, R", "#", "con2(_E, _a)"},
148  {"con2(_E, _a)", "non(B)", "R, R", "#", "_E"},
149  };
150  return transitions;
151  }
152 
154  TransitionSetType transitions{
155  {"b", "", "", "#", "f(b1, b1, +)"},
156  {"b1", "", "R, R, I(:, ., C, ., A)", "#", "anf"},
157  {"anf", "", "", "#", "q(anf1, :)"},
158  {"anf1", "", "", "#", "con(fom, y)"},
159  {"fom", ";", "R, I z, L", "#", "con(fmp, x)"},
160  {"fom", "z", "L, L", "#", "fom"},
161  {"fom", "non(;, z)", "L", "#", "fom"},
162  {"fmp", "", "", "#", "cpe(e(e(anf, y), x), sim, x, y)"},
163  };
164  return transitions;
165  }
166 
168  TransitionSetType transitions{
169  {"sim", "", "", "#", "f'(sim1, sim1, z)"},
170  {"sim1", "", "", "#", "con(sim2, blank)"},
171  {"sim2", "A", "", "#", "sim3"},
172  {"sim2", "non(A)", "L, I u, R, R, R", "#", "sim2"},
173  {"sim3", "non(A)", "L, I y", "#", "e(mf, z)"},
174  {"sim3", "A", "L, I y, R, R, R", "#", "sim3"},
175  };
176  return transitions;
177  }
178 
180  TransitionSetType transitions{
181  {"mf", "", "", "#", "q(mf1, :)"},
182  {"mf1", "A", "L, L, L, L", "#", "mf2"},
183  {"mf1", "non(A)", "R, R", "#", "mf1"},
184  {"mf2", "B", "R, I x, L, L, L", "#", "mf2"},
185  {"mf2", ":", "", "#", "mf4"},
186  {"mf2", "C", "R, I x, L, L, L", "#", "mf3"},
187  {"mf3", "non(:)", "R, I v, L, L, L", "#", "mf3"},
188  {"mf3", ":", "", "#", "mf4"},
189  {"mf4", "", "", "#", "con(l(l(mf5)), blank)"},
190  {"mf5", "any", "R, I w, R", "#", "mf5"},
191  {"mf5", "none", "I :", "#", "sh"},
192  };
193  return transitions;
194  }
195 
197  TransitionSetType transitions{
198  {"sh", "", "", "#", "f(sh1, inst, u)"},
199  {"sh1", "", "L, L, L", "#", "sh2"},
200  {"sh2", "C", "R, R, R, R", "#", "sh3"},
201  {"sh2", "non(C)", "", "#", "inst"},
202  {"sh3", "B", "R, R", "#", "sh4"},
203  {"sh3", "non(B)", "", "#", "inst"},
204  {"sh4", "B", "R, R", "#", "sh5"},
205  {"sh4", "non(B)", "", "#", "pe2(inst, 0, :)"},
206  {"sh5", "B", "", "#", "inst"},
207  {"sh5", "non(B)", "", "#", "pe2(inst, 1, :)"},
208  };
209  return transitions;
210  }
211 
213  TransitionSetType transitions{
214  {"inst", "", "", "#", "q(l(inst1), u)"},
215  {"inst1", "", "R, E", "#", "inst1(_#)"},
216  {"inst1(G)", "", "", "#", "ce5(ov, v, y, x, u, w)"},
217  {"inst1(D)", "", "", "#", "ce5(ov, v, x, u, y, w)"},
218  {"inst1(N)", "", "", "#", "ce5(ov, v, x, y, u, w)"},
219  {"ov", "", "", "#", "e(anf)"},
220  };
221  return transitions;
222  }
223 }
TuringSim::Machine::Turing::Utm::makePrintAtEnd
static TransitionSetType makePrintAtEnd()
Build the print at end function.
Definition: utm.cpp:54
TuringSim::Machine::Turing::Utm::makeFind
static TransitionSetType makeFind()
Build the find function.
Definition: utm.cpp:31
TuringSim::Machine::Turing::Utm::makeReplace
static TransitionSetType makeReplace()
Build the replace function.
Definition: utm.cpp:96
TuringSim::Machine::Turing::Utm::makeE
static TransitionSetType makeE()
Build the e table of the UTM.
Definition: utm.cpp:130
TuringSim::Machine::Turing::Utm::makeCopyAndErase
static TransitionSetType makeCopyAndErase()
Build the copy and erase function.
Definition: utm.cpp:82
TuringSim::Machine::Turing::Utm::makeInst
static TransitionSetType makeInst()
Build the inst_n table of the UTM.
Definition: utm.cpp:212
TuringSim::Machine::Turing::Utm::makeComparison
static TransitionSetType makeComparison()
Build the comparison function.
Definition: utm.cpp:105
TuringSim::Machine::Turing::Utm::makeFindLast
static TransitionSetType makeFindLast()
Build the find last function.
Definition: utm.cpp:117
TuringSim::Machine::Turing::DeterministicTuringStyleMConfigurationTuringMachine
Deterministic machines whose transitions are Transition::TuringStyleMConfigurationTuringMachineTransi...
Definition: deterministicTuringStyleMConfigurationTuringMachine.h:24
TuringSim::Machine::Turing::Utm::makeSim
static TransitionSetType makeSim()
Build the sim_n table of the UTM.
Definition: utm.cpp:167
TuringSim::Machine::Turing::Utm::makeCopy
static TransitionSetType makeCopy()
Build the copy function.
Definition: utm.cpp:74
TuringSim::Machine::Turing::Utm::makeFindAndMove
static TransitionSetType makeFindAndMove()
Build the find and move function.
Definition: utm.cpp:64
TuringSim::Machine::Turing
Namespace of Turing machines, that is whose storage is a tape.
Definition: deterministicSimpleTuringMachine.h:8
TuringSim::Machine::Turing::Utm::makeMf
static TransitionSetType makeMf()
Build the mf_n table of the UTM.
Definition: utm.cpp:179
TuringSim::Machine::Turing::Utm::makeUtm
static UtmType makeUtm()
Build a new UTM.
Definition: utm.cpp:4
TuringSim::Machine::Turing::Utm::TransitionSetType
std::set< TransitionType > TransitionSetType
Sets of TransitionType.
Definition: utm.h:38
TuringSim::Machine::Turing::Utm::makeErase
static TransitionSetType makeErase()
Build the erase function.
Definition: utm.cpp:45
TuringSim::Machine::Turing::Utm::makeInit
static TransitionSetType makeInit()
Build the init table of the UTM.
Definition: utm.cpp:153
TuringSim::Machine::Turing::Utm::makeCon
static TransitionSetType makeCon()
Build the con table of the UTM.
Definition: utm.cpp:140
TuringSim::Machine::Turing::Utm::makeSh
static TransitionSetType makeSh()
Build the sh_n table of the UTM.
Definition: utm.cpp:196