-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
197 lines (197 loc) · 12.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lambda</title>
<link rel="icon" href="./images/favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./style.css">
<script>
const Lambda = '\u03bb';
//const Bottom = '\u22a5';
</script>
<script src="./lambda.js" type="module"></script>
<script src="./eval-lambda.js" type="module"></script>
<script src="./formulas.js" type="module"></script>
<script src="./dropdown-toggle.js" defer></script>
<script src="./load-formulas.js" defer></script>
</head>
<body>
<h1 class="center">Lambda Calculus</h1>
<div class="padded">
<h2>Formulæ <button class="button dropdown-toggle" data-div-id="formulae" data-up-icon=">" data-down-icon="v">></button></h2>
<div id="formulae" style="display:none">
<table>
<tbody id="formula-list"></tbody>
</table>
<h3><button class="button dropdown-toggle" data-div-id="formula-help" data-up-icon="?" data-down-icon="?">?</button></h3>
<div id="formula-help" style="display:none;margin-left:5%;font-size:14px">
These are formulas that can be used in your λ-expressions.
They are formatted
<blockquote style="color:grey">
(λ*.*
<span style="color:aquamarine">expression</span>)
λ<b style="color:aquamarine">name</b>.
</blockquote>
where each <b style="color:aquamarine">name</b> corresponds to an <span style="color:aquamarine">expression</span>.
Each time one the above names is encountered in a λ-term, it is substituted for its corresponding expression.<br>
You can create your own formulas using the "Add Formula" button below.
<br>
Note that due to the fact that λ-terms are <i>anonymous</i> functions, formulas can only refer to previous formulas – circular definitions are impossible and will yield unexpected results if attempted.
</div>
</div>
</div>
<br><br>
<div class="center padded">
<form id="lambda-form" name="lambda-form" onsubmit="event.preventDefault(); displayEvalLambda()" spellcheck="false">
<label for="lambda-input">Enter a λ-expression:</label><br><br>
<input type="button" title="clear" value="x" class="button" style="color: orangered" onclick="
document.getElementById('lambda-input').value = '';
document.getElementById('lambda-input').focus();
">
<input type="text" autocomplete="off" id="lambda-input" name="lambda-input" class="input" style="width: 50%" onkeypress="
if (event.which != 92) return;
const start = this.selectionStart;
const end = this.selectionEnd;
this.value = this.value.slice(0, start) + Lambda + this.value.slice(end);
this.setSelectionRange(start + 1, start + 1);
return false;
">
<input type="submit" value="Evaluate" class="button" style="color:palegreen">
<input type="button" value="SKI" class="button" style="color:bisque" onclick="displaySKI(document.getElementById('lambda-input').value)">
<input type="button" value="Add Formula" class="button" onclick="document.getElementById('add-formula').style.display = 'block'; document.getElementById('formula-name-input').focus()">
</form>
<br>
<div id="add-formula" style="display:none">
<form onsubmit="
event.preventDefault();
const name = document.getElementById('formula-name-input').value;
addFormula(
name,
document.getElementById('lambda-input').value,
() => {
document.getElementById('add-formula').style.display = 'none';
document.getElementById('lambda-input').value = '';
document.getElementById('formula-name-input').value = '';
alert(`Formula \u0022${name}\u0022 added`);
}
);
" spellcheck="false">
<label for="formula-name-input">Enter a name for this formula:</label>
<input type="text" value="" autocomplete="off" id="formula-name-input" name="formula-name-input" class="input">
<input type="submit" value="Add" class="button" style="color:palegreen">
<input type="button" value="Cancel" class="button" style="color:orangered" onclick="document.getElementById('formula-name-input').value = ''; document.getElementById('add-formula').style.display = 'none'"></button>
</form>
</div>
<div id="lambda-result" class="text" style="display:none">
<h2>Result</h2>
<table style="margin-left: auto; margin-right: auto; border-collapse: separate; border-spacing: 0.5em">
<thead>
<tr id="lambda-result-expr">
<td></td>
<th id="lambda-result-expr-content"></th>
<td>
<button class="button" title="Copy" onclick="navigator.clipboard.writeText(document.getElementById('lambda-result-expr-content').textContent)">📋</button>
</td>
</tr>
</thead>
<tbody>
<tr id="lambda-result-ski" style="display: none">
<td style="color: aquamarine">≡<sub>SKI</sub></td>
<td id="lambda-result-ski-content" style="color: bisque"></td>
<td>
<button class="button" title="Copy" onclick="navigator.clipboard.writeText(document.getElementById('lambda-result-ski-content').textContent)">📋</button>
</td>
</tr>
<tr id="lambda-result-beta" style="display: none">
<td style="color: aquamarine">≡<sub>β</sub></td>
<td id="lambda-result-beta-content"></td>
<td>
<button class="button" title="Copy" onclick="navigator.clipboard.writeText(document.getElementById('lambda-result-beta-content').textContent)">📋</button>
</td>
</tr>
<tr id="lambda-result-eta" style="display: none">
<td style="color: aquamarine">≡<sub>η</sub></td>
<td id="lambda-result-eta-content"></td>
<td>
<button class="button" title="Copy" onclick="navigator.clipboard.writeText(document.getElementById('lambda-result-eta-content').textContent)">📋</button>
</td>
</tr>
<tr id="lambda-result-alpha" style="display: none">
<td style="color: aquamarine">≡<sub>α</sub></td>
<td id="lambda-result-alpha-content"></td>
</tr>
</tbody>
</table>
<br>
<button class="button" style="color:red" onclick="clearLambdaResult();">Clear</button>
</div>
</div>
<br><br>
<div class="padded" style="font-size:14px">
<h2>Guide <button class="button dropdown-toggle" data-div-id="guide" data-up-icon=">" data-down-icon="v" data-default-open="true">v</button></h2>
<div id="guide">
<ul>
<li>
Enter a <span style="color:aquamarine">λ-expression</span> into the input field
<ul>
<li>
To enter the character <span style="color:aquamarine">'λ'</span>,
simply use the backslash key <span style="color:aquamarine">'\'</span>
</li>
<li>
Hit <span style="color:aquamarine">enter</span> or press <span style="color:palegreen">Evaluate</span> to evaluate the λ-expression
</li>
<li>
The evaluation will yield <span style="color:aquamarine">β-</span> and <span style="color:aquamarine">η-reductions</span> of the entered expression, as well as any <span style="color:aquamarine">α-equivalent</span> terms present in the <b>Formulæ</b> list
</li>
<li>
Any λ-expressions that take longer than <span style="color:aquamarine">100 ms</span> to evaluate, or that result in a stack overflow will yield <span style="color:aquamarine">⊥</span>, which represents an <span style="color:red">irreducible</span> term
<ul>
<li>
Due to the way browsers run this script (most likely on a <span style="color:aquamarine">low-priority thread</span>), λ-expressions may sometimes take longer than 100 ms to evaluate, and time out, yielding <span style="color:aquamarine">⊥</span>, regardless of whether they are theoretically reducible or not
</li>
<li>
This is especially the case when switching back to this tab after spending (CPU) time elsewhere – the tab would be backgrounded, and thus would take extremely long (<span style="color:red">> 100 ms</span>) to compute λ-evaluations
</li>
<li>
The solution is simple – keep hitting <span style="color:palegreen">Evaluate</span> until the tab is foregrounded again and yields the correct evaluation
</li>
</ul>
</li>
</ul>
</li>
<li>
<span style="color:aquamarine">Formulas</span> that can be used in λ-expressions are found in the <b>Formulæ</b> dropdown
<ul>
<li>
A formula is an alias for an expression;
It's a variable that is substituted for its corresponding expression during evaluation
</li>
<li>
An assortment of combinators are already preloaded into the list
</li>
<li>
Custom formulas can be added using the <u>Add Formula</u> button
</li>
</ul>
</li>
<li>
A λ-expression can be converted to an expression containing only the <span style="color:aquamarine">S</span>, <span style="color:aquamarine">K</span> & <span style="color:aquamarine">I</span> combinators using the <span style="color:bisque">SKI</span> button
<ul>
<li>
Definitions for these combinators (the so-called <span style="color:bisque">SKI calculus</span>) can be found in <b>Formulæ</b> section
</li>
</ul>
</li>
<li>
The <span style="color:aquamarine">source code</span> for this website can be found at <a href="https://github.com/freddycoppa/lambda-js">github.com/freddycoppa/lambda-js</a>
</li>
</ul>
</div>
</div>
</body>
</html>