-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
371 lines (328 loc) · 20.3 KB
/
index.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html lang="en">
<head>
<title>Turing Machine–Lambda Calculus Converter</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- JQuery CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.31.1/css/jquery.terminal.min.css" rel="stylesheet"/>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Internal CSS -->
<link rel="stylesheet" href="index.css"/>
<!-- FullPage CSS -->
<link rel="stylesheet" type="text/css" href="javascripts/fullpage.css" />
</head>
<body>
<div id="fullpage">
<div class="section">
<div class="contents">
<!-- Lambda Calculus Interpreter -->
<div class="col-md-8 quarter left justify-content-center" style="background-color:#B3B3B3;">
<div class="container-fluid m-0 p-0" style="height: 100%;">
<div class="title" id="lambdatitle">LAMBDA CALCULUS INTERPRETER</div>
<div id="terminal"></div>
</div>
</div>
<!-- Lambda Calculus Description -->
<div class="col-md-4 quarter right" style="background-color:#B3B3B3; padding-right: 40px;">
<div class="container p-4 overflow-hidden">
<h2>LAMBDA CALCULUS INTERPRETER</h2>
<hr style="width:50%; border-color:black; background-color:black; border:1px solid black;">
<p>
<b>LAMBDA CALCULUS</b> (also written as λ-calculus) is a system in mathematical logic for expressing computation using function abstraction and application. The system captures the notion of computation; it is computationally equivalent to the Turing Machine and can therefore model any Turing machine program.
</p>
<p>
The system was defined in the 1930s by Alonzo Church in his paper "An Unsolvable Problem of Elementary Number Theory" as part of
his research in the foundations of mathematics.
</p>
<h2>EXAMPLES</h2>
<hr style="width: 50%; border: 1px solid black;">
<p>
Here are a few input examples for the interpreter:
</p>
<ul>
<li><code>(\x.x)(\y.y)(\z.z)</code></li>
<li><code>(\x.(\y.xy))y</code></li>
<li><code>(\x.(\x.x))(\x.xy)y</code></li>
</ul>
<p>
The Wikipedia article for the lambda calculus system can be found <a href="https://en.wikipedia.org/wiki/Lambda_calculus" style="color: crimson;">here</a>.
</p>
</div>
</div>
</div>
</div>
<div class="section">
<div class="contents">
<!-- Turing Machine Interpreter -->
<div class="col-md-8 quarter left" style="background-color: #B3B3B3;">
<div class="container-fluid overflow-hidden" style="background-color: #404040; height: 90%; width: 95%; margin-top: 2.5%; padding-top: 8px;">
<form>
<div class="row">
<div class="col-5">
<div class="form-group">
<label for="exampleFormControlTextarea1" id="formtitle">RULESET</label>
<textarea class="form-control rounded-0" id="ruleset" name="ruleset" rows="17">{ "S1": { "0": ["S1", "0", "R"], "1": ["S1", "1", "R"], "B": ["S2", "B", "L"] }, "S2": { "0": ["S3", "1", "L"], "1": ["S2", "0", "L"], "B": ["S3", "1", "L"] }, "S3": { "0": ["S3", "0", "L"], "1": ["S3", "1", "L"], "B": ["SH", "B", "R"] } }</textarea>
</div>
</div>
<div class="col">
<div class="row">
<div class="col-6">
<label class="sr-only" for="tape" id="formtitle">TAPE</label>
<input type="text" class="form-control mb-2 rounded-0" id="tape" name="tape" value="@ λ > 0 λ > 0">
<label class="sr-only" for="head" id="formtitle">HEAD SETTING (STATE + POSITION)</label>
<input type="text" class="form-control mb-2 rounded-0" id="head" name="head" value="S1 0">
</div>
<div class="col-6">
<button type="submit" class="btn btn-dark rounded-0" id="tape_button" style="width: auto;">RUN</button>
<select class="form-select btn-dark mb-3 rounded-0" aria-label=".form-select-lg example" id="dropdown-button" style="width: 180px;">
<option> </option>
<option value = "binary increment">binary increment</option>
<option value = "divisible by 3">divisible by 3</option>
<option value = "copy 1s">copy 1s</option>
<option value = "palindrome">palindrome</option>
<option value = "binary addition">binary addition</option>
<option value = "powers of two length">powers of two length</option>
<option value = "repeat 0 1">repeat 0 1</option>
</select>
</div>
</div>
<div class="row d-flex justify-content-center" style="margin-top: 48px; color: white; background-color: #626262; margin-right: auto;" id="TuringMachineState"></div>
<div class="row d-flex justify-content-center" style="margin-top: 48px; color: white; background: #626262; margin-right: auto;" id="TuringMachineTape"></div>
</div>
</div>
</form>
</div>
</div>
<!-- Turing Machine Description -->
<div class="col-md-4 quarter right" style="background-color:#B3B3B3; padding-right: 50px;">
<div class="container p-4 overflow-hidden">
<h2>TURING MACHINE INTERPRETER</h2>
<hr style="width: 50%; border: 1px solid black;">
<p>
<b>TURING MACHINES</b> are a system that represent computation as states on an abstract tape machine. Compared to the lambda calculus, Turing machines are a much more abstract, semi-physical model of computation. Despite the system's simplicity, Turing machines can simulate the entire class of computations and are therefore equivalent in power to the lambda calculus.
</p>
<p>
The system was defined by Alan Turing in the 1930s in his paper “On Computable Numbers with an Application to the Entscheidungsproblem”.
</p>
<h2>EXAMPLES</h2>
<hr style="width: 50%; border: 1px solid black;">
<p>
Use the dropdown menu on the top-right of the machine to select an exemplar Turing machine.
</p>
<p>
The Wikipedia article for Turing machines can be found <a href="https://en.wikipedia.org/wiki/Turing_machine" style="color: crimson;">here</a>.
</p>
</div>
</div>
</div>
</div>
<div class="section">
<div class="contents">
<!-- MULTI-TAPE Turing Machine Interpreter -->
<div class="col-md-6 quarter left" style="background-color: #B3B3B3;">
<div class="container-fluid overflow-hidden" style="background-color: #404040; height: 90%; width: 95%; margin-top: 2.5%; padding-top: 8px;">
<form>
<div class="row">
<div class="col">
<div class="row">
<div class="col-6">
<label class="sr-only" for="tape" id="formtitle">TAPE</label>
<input type="text" class="form-control mb-2 rounded-0" id="tape" name="tape" value="@ λ > 0 λ > 0">
</div>
<div class="col-6">
<button type="submit" class="btn btn-dark rounded-0" id="multi_tape_button" style="width: 80px;">RUN</button>
</div>
</div>
</div>
</div>
</form>
<div class="row d-flex justify-content-center" style="font-family: monospace; font-size: 25px; color: white; background: #626262; margin-right: auto; margin-left: auto; height: 40px;" id="M_STATE"></div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">CURRENT</label>
</div>
<div class="col-9">
<div class="row d-flex align-items-center justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="CURRENT"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">PREREDEX</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="PREREDEX"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">FUNCTIONAL</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="FUNCTIONAL"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">ARGUMENT</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="ARGUMENT"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">POSTREDEX</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="POSTREDEX"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">REDUCT</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="REDUCT"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">STACKTERM</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="STACKTERM"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">STACKREDEX</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="STACKREDEX"></div>
</div>
</div>
<div class="row tape-row">
<div class="col-3 d-flex align-items-center justify-content-center" style="padding-right: 0px;">
<label id="tape_title">COUNTER</label>
</div>
<div class="col-9">
<div class="row d-flex justify-content-center overflow-hidden text-nowrap" style="font-family: monospace; margin-top: 10px; color: white; background: #626262; margin-right: auto; margin-left: auto;" id="COUNTER"></div>
</div>
</div>
</div>
</div>
<!-- MULTI-TAPE Turing Machine Description -->
<div class="col-md-6 quarter right" style="background-color:#B3B3B3; padding-right: 50px;">
<div class="container p-4 overflow-hidden">
<h2>MULTI-TAPE INTERPRETER</h2>
<hr style="width: 50%; border: 1px solid black;">
<p>
<b>MULTI-TAPE TURING MACHINES</b> are a variant of the original Turing machine. As the name suggests, a multi-tape Turing machine hosts multiple tapes.
</p>
<p>
In the paper <a href="https://www.researchgate.net/publication/220152286_The_weak_lambda_calculus_as_a_reasonable_machines" style="color: crimson;">"The Weak Lambda Calculus as a Reasonable Machine"</a>, Dal Lago and Martini make it clear that the usual notation for the lambda calculus does "not take into account the complexity of handling variables, and substitutions". They therefore introduce a notation where binary integers are used to describe the number of binders.
</p>
<p>
In this new notation, the term (\x.x) converts to λ > 0, where 0 denotes the number of binders between the variable in its parameter and the argument. The term (λx.x)(λx.x) converts to @ λ > 0 λ > 0, where @ denotes an application and where > denotes the beginning of a free or bound variable.
</p>
<h2>DESCRIPTION</h2>
<hr style="width: 50%; border: 1px solid black;">
<p>
The interpreter here is necessary to simulate the lambda calculus in a Turing machine as described in <a href="https://www.researchgate.net/publication/220152286_The_weak_lambda_calculus_as_a_reasonable_machines" style="color: crimson;">"The Weak Lambda Calculus as a Reasonable Machine"</a>.
</p>
<p>
To simulate the correct lambda term, enter a term in the lambda calculus interpreter on the first page. The term entered will then be updated into its appropriate notation in the multi-tape interpreter's form. After that, click run to simulate the lambda calculus term in the multi-tape Turing machine interpreter.
</p>
</div>
</div>
</div>
</div>
</div>
<!-- FullPage JS -->
<script type="text/javascript" src="javascripts/fullpage.js"></script>
<!-- JQuery Terminal JS -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://unpkg.com/jquery.terminal@2.x.x/js/jquery.terminal.min.js"></script>
<!-- Lambda Calculus Interpreter JS -->
<script src="javascripts/lambda_calculus_interpreter.js"></script>
<!-- Turning Machine JS -->
<script src="javascripts/simulation_TM_to_lambda_calculus.js"></script>
<script src="javascripts/single_tape_TM_interpreter.js"></script>
<script src="javascripts/multi_tape_TM_interpreter.js"></script>
<script>
$('#dropdown-button').on('change', function() {
machine = $(this).val();
if (machine == 'binary increment') {
$('#ruleset').val('{ "S1": { \n "0": ["S1", "0", "R"], \n "1": ["S1", "1", "R"], \n "B": ["S2", "B", "L"] }, \n "S2": { \n "0": ["S3", "1", "L"], \n "1": ["S2", "0", "L"], \n "B": ["S3", "1", "L"] }, \n "S3": { \n "0": ["S3", "0", "L"], \n "1": ["S3", "1", "L"], \n "B": ["SH", "B", "R"] \n} }');
$('#tape').val('1 0 1 1');
$('#head').val('S1 0');
}
if (machine == 'divisible by 3') {
$('#ruleset').val('{ "Q0": { \n "0": ["Q0", "0", "R"], \n "1": ["Q1", "1", "R"], \n "B": ["ACCEPT", "B", ""] }, \n "Q1": { \n "0": ["Q2", "0", "R"], \n "1": ["Q0", "1", "R"], \n "B": ["REJECT", "B", ""] }, \n "Q2": { \n "0": ["Q1", "0", "R"], \n "1": ["Q2", "1", "R"], \n "B": ["REJECT", "B", ""] \n} }');
$('#tape').val('1 0 0 1');
$('#head').val('Q0 0');
}
if (machine == 'copy 1s') {
$('#ruleset').val('{ "EACH": { \n "B": ["H", "B", "R"], \n "1": ["SEP", "B", "R"] }, \n "SEP": { \n "B": ["ADD", "B", "R"], \n "1": ["SEP", "1", "R"] }, \n "ADD": { \n "B": ["SEPL", "1", "L"], \n "1": ["ADD", "1", "R"] }, \n "SEPL": { \n "B": ["NEXT", "B", "L"], \n "1": ["SEPL", "1", "L"] }, \n "NEXT": { \n "B": ["EACH", "1", "R"], \n "1": ["NEXT", "1", "L"] \n} }');
$('#tape').val('1 1 1');
$('#head').val('EACH 0');
}
if (machine == 'palindrome') {
$('#ruleset').val('{ "START": { \n "a": ["HAVEA", "B", "R"], \n "b": ["HAVEB", "B", "R"], \n "B": ["ACCEPT", "B", "_"] }, \n "HAVEA": { \n "a": ["HAVEA", "a", "R"], \n "b": ["HAVEA", "b", "R"], \n "B": ["MATCHA", "B", "L"] }, \n "HAVEB": { \n "a": ["HAVEB", "a", "R"], \n "b": ["HAVEB", "b", "R"], \n "B": ["MATCHB", "B", "L"] }, \n "MATCHA": { \n "a": ["BACK", "B", "L"], \n "b": ["REJECT", "b", "_"], \n "B": ["ACCEPT", "B", "_"] }, \n "MATCHB": { \n "a": ["REJECT", "a", "_"], \n "b": ["BACK", "B", "L"], \n "B": ["ACCEPT", "B", "_"] }, \n "BACK": { \n "a": ["BACK", "a", "L"], \n "b": ["BACK", "b", "L"], \n "B": ["START", "B", "R"] } }');
$('#tape').val('a b b a');
$('#head').val('START 0');
}
if (machine == 'binary addition') {
$('#ruleset').val('{ "RIGHT": { \n "0": ["RIGHT", "0", "R"], \n "1": ["RIGHT", "1", "R"], \n "+": ["RIGHT", "+", "R"], \n "B": ["READ", "B", "L"] }, \n "READ": { \n "0": ["HAVE0", "c", "L"], \n "1": ["HAVE1", "c", "L"], \n "+": ["REWRITE", "B", "L"] }, \n "HAVE0": { \n "0": ["HAVE0", "0", "L"], \n "1": ["HAVE0", "1", "L"], \n "+": ["ADD0", "+", "L"] }, \n "HAVE1": { \n "0": ["HAVE1", "0", "L"], \n "1": ["HAVE1", "1", "L"], \n "+": ["ADD1", "+", "L"] }, \n "ADD0": { \n "0": ["BACK0", "0", "R"], \n "B": ["BACK0", "0", "R"], \n "1": ["BACK0", "I", "R"], \n "O": ["ADD0", "O", "L"], \n "I": ["ADD0", "O", "O"] }, \n "ADD1": { \n "0": ["BACK1", "I", "R"], \n "B": ["BACK1", "I", "R"], \n "1": ["CARRY", "O", "L"], \n "O": ["ADD1", "O", "L"], \n "I": ["ADD1", "I", "L"] }, \n "CARRY": { \n "0": ["BACK1", "I", "R"], \n "B": ["BACK1", "I", "R"], \n "1": ["CARRY", "0", "L"] }, \n "BACK0": { \n "0": ["BACK0", "0", "R"], \n "1": ["BACK0", "1", "R"], \n "O": ["BACK0", "O", "R"], \n "I": ["BACK0", "I", "R"], \n "+": ["BACK0", "+", "R"], \n "c": ["READ", "0", "L"] }, \n "BACK1": { \n "0": ["BACK1", "0", "R"], \n "1": ["BACK1", "1", "R"], \n "O": ["BACK1", "O", "R"], \n "I": ["BACK1", "I", "R"], \n "+": ["BACK1", "+", "R"], \n "c": ["READ", "1", "L"] }, \n "REWRITE": { \n "O": ["REWRITE", "0", "L"], \n "I": ["REWRITE", "1", "L"], \n "0": ["REWRITE", "0", "L"], \n "1": ["REWRITE", "1", "L"], \n "B": ["DONE", "B", "R"] \n } }');
$('#tape').val('1 0 1 + 1 0');
$('#head').val('RIGHT 0');
}
if (machine == 'powers of two length') {
$('#ruleset').val('{ "ZERO": { \n "0": ["ONE", "B", "R"], \n "B": ["REJECT", "B", "_"] }, \n "ONE": { \n "0": ["EVEN", "x", "R"], \n "B": ["ACCEPT", "B", "_"], \n "x": ["ONE", "B", "R"] }, \n "EVEN": { \n "0": ["ODD", "0", "R"], \n "B": ["BACK", "B", "L"], \n "x": ["EVEN", "x", "R"] }, \n "ODD": { \n "0": ["EVEN", "x", "R"], \n "B": ["REJECT", "B", "_"], \n "x": ["ODD", "x", "R"] }, \n "BACK": { \n "B": ["ONE", "B", "R"], \n "0": ["BACK", "0", "L"], \n "x": ["BACK", "x", "L"] \n } }');
$('#tape').val('0 0 0 0');
$('#head').val('ZERO 0');
}
if (machine == 'repeat 0 1') {
$('#ruleset').val('{ "B": { \n "B": ["C", "0", "R"] }, \n "C": { \n "B": ["E", "B", "R"] }, \n "E": { \n "0": ["F", "1", "R"] }, \n "F": { \n "B": ["B", "B", "R"] \n } }');
$('#tape').val('B');
$('#head').val('B 0');
}
});
new fullpage('#fullpage', {
licenseKey: 'gplv3-license',
navigation: true,
responsiveWidth: 700,
anchors: ['home', 'about-us', 'contact'],
parallax: true,
onLeave: function(origin, destination, direction){
console.log("Leaving section" + origin.index);
},
});
var terminal = $('#terminal').terminal(function(command, term) {
switch(command) {
default:
if (command.includes('T')) {
this.echo('[[;white;black]TAPE = ][[;teal;black]' + command + ' ---\> ' + interpret_TM(command) + ']');
break;
}
this.echo('[[;teal;black]------------\n' + interpret(command) + ']');
break;
case 'help':
this.echo('[[;teal;black]COMMANDS:\nhelp\nclear\nclear-history\n\nLAMBDA CALCULUS EXAMPLES:\n(\\x\.x)\n(\\x\.x)y\n\n(\\x\.xx)y\n(\\x\.x)(\\y\.y)(\\z\.z)\n(\\x\.(\\y\.xy))z\n\nLAMBDA CALCULUS SYNTAX:\nterm ------- variable | abstraction | application\nvariable ------- IDENTIFIER\nIDENTIFIER ------- a-zA-Z \nabstraction -------\n\nSTANDARD TERMS:\nI ------- (λx.x)\nS ------- (λx.λy.λz.xz(yz))\nK ------- (λx.λy.x)\nB ------- (λx.λy.λz.x(yz))\nC ------- (λx.λy.λz.xzy)\nW ------- (λx.λy.xyy)]');
break;
}
},{
greetings: '',
name: 'Lambda Calculus Interpreter',
});
terminal_print = function(str, bool=true) {
terminal.echo('[[;teal;black]' + str + ']', {newline: bool});
};
</script>
<!-- Bootstrap Bundle with Popper JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>