-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
418 lines (384 loc) · 16.6 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Justify</title>
<script src="formula.js"></script>
<script src="g.js"></script>
<script src="nearley.js"></script>
<script src="content.js"></script>
<link href="purple_interface.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<div class="modal_overlay" onclick="help_close()"></div>
<div class="modal">
<h2>Conventions</h2>
<div class="modalcontent">
<div class="modalblock">
<h3>About</h3>
<p>
This tool autocompletes justifications within the given first-order natural deduction.
</p>
<p>
This tool does not...
</p>
<ul>
<li>
automatically find proofs or insert helpful formulas;
</li>
<li>
enable you to input or verify your own justifications [but it does list all candidates for justifications, if you're using the same conventions].
</li>
</ul>
<p>
In short, this tool enables you to write down <b>your</b> (valid) deductions quickly.
It can also be used as a deduction verifier, but this is not really the intended use case.
Everything else mentioned is mostly doable, but there are other tools for those purposes.
</p>
</div>
<div class="modalblock">
<h3>Syntax</h3>
<p>
The following connectives and quantifiers are available:
</p>
<table>
<tr>
<td></td><td>Symbol</td><td colspan="6">In text</td>
</tr>
<tr>
<td>Logical NOT</td><td>¬</td><td>¬</td><td>~</td><td>-</td><td></td><td></td><td></td>
</tr>
<tr>
<td>Logical AND</td><td>∧</td><td>/\</td><td>&</td><td>&&</td><td>*</td><td>.</td><td></td>
</tr>
<tr>
<td>Logical OR</td><td>∨</td><td>\/</td><td>\/</td><td>+</td><td>|</td><td>||</td><td>,</td>
</tr>
<tr>
<td>Conditional</td><td>→</td><td>-></td><td>></td><td>=></td><td></td><td></td><td></td>
</tr>
<tr>
<td>Biconditional</td><td>↔</td><td><-></td><td>=</td><td><></td><td><=></td><td></td><td></td>
</tr>
<tr>
<td>Falsum</td><td>⊥</td><td>#</td><td>_|_</td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td>Universal quantifier</td><td>∀</td><td>A</td><td>@</td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td>Existential quantifier</td><td>∃</td><td>E</td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td>Relation</td><td>A—Z</td><td>A—Z</td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td title="Important: see conventions below">Variable/Constant</td><td>a—z</td><td>a—z</td><td></td><td></td><td></td><td></td><td></td>
</tr>
</table>
<p>
Deduction (Fitch-style) is a list of lines, where each line is a block of <b>|</b>'s (vertical lines) followed by a formula.
If A is an asummption, use L instead of the rightmost |.
For example: <br/>
<span style="padding-left: 1em; display: inline-block">
L ¬¬A <br/>
| A
</span>
Gentzen-style deductions are also supported, but only as an output.
</p>
</div>
<div class="modalblock">
<h3>Help and conventions</h3>
<p>
Note that relational symbols (including propositions) are limited in length to one character.
Letters 'A' and 'E' can be used for propositions (0-ary relations), but it might be confusing.
However, this tool will correctly detemine whether Ax
is universal quantification or an atomic formula, assuming there are no typos in the starting formula.
</p>
<p>
You should put brackets everywhere, except when it doesn't matter.
The only predefined precedence is that all unary operators (including quantifiers) have higher priority than binary operators.
</p>
<p>
Conventions for quantifiers:
</p>
<ul>
<li>The main restriction is that you <b>do not use the same letters for variables and (pseudo)constants.</b>
Which letters you use for what purpose is up to you.
For example, a valid proof of ∀x Px from the assumption ∀x ¬¬Px would go as follows:
∀x ¬¬Px; ¬¬Pc; Pc; ∀x Px.
This restriction is not enforced (not abiding it will not cause a syntax error).
For example, if you have Pt ∧ Px, you can deduce ∃x (Px ∧ Px).
However, if you have Px ∧ Pt, since you are trying to introduce x, and the first occurence of x in
the original formula Px ∧ Pt is Px, this situation is interpreted as replacing x with x.
With this intepretation, the second occurence of Px causes an error (it differs from Pt).
A good way to solve this would be to explicitly ask the user what term is being replaced in order to formulate a correct justification,
but making the user care about justifications is exactly what we're trying to avoid.
</li>
<li>Introducing ∀, specifically ∀x F(x), can be done given a formula F such that F is exactly like F(x),
except that all free occurences of some letter t (which may or may not actually appear in F) within F
are replaced with x.
There are the usual restrictions:
<ul>
<li>t should not be mentioned in any assumption, unless it belongs to an already completed subproof</li>
<li>F should not contain a quantifier over t whose scope contains x an occurence of x (e.g. ∀tQx)</li>
</ul>
</li>
<li>
Introducing ∃, specifically ∃x F(x), can be done given a formula F such that F is exactly like F(x),
except that all zero or more occurences of some letter t (which may or may not actually appear in F) within F
are replaced with x.
There are the usual restrictions:
<ul>
<li>F should not contain a quantifier over t whose scope contains an occurence of x (e.g. ∀tQx)</li>
</ul>
</li>
<li>Eliminating ∀, specifically ∀x F(x), is done by inserting any formula F such that
all free occurences of x (which may or may not actually appear in F(x)) within F
are replaced with t.
There are the usual restrictions:
<ul>
<li>F should not contain a quantifier over t whose scope contains x an occurence of x (e.g. ∀tQx)</li>
</ul>
</li>
<li>Eliminating ∃, specifically ∃x F(x), is done by inserting a subproof beginning with a formula F such that
all free occurences of some letter t (which may or may not actually appear in F) within F
are replaced with x.
The subproof should and with a formula not containing an occurence of t.
There are the usual restrictions:
<ul>
<li>t should not be mentioned in any preceding line, unless it belongs to an already completed subproof</li>
<li>F should not contain a quantifier over t whose scope contains x an occurence of x (e.g. ∀tQx)</li>
</ul>
</li>
</ul>
<p>
Rules for logical connectives are mostly standard.
There are some additional conventions regarding justifications that probably won't matter such as:
</p>
<ul>
<li>when introducing ∧ from lines numbered a, b; the order will be a, b if a < b, otherwise b, a</li>
<li>when eliminating → from lines a: F → G, b: F; the order will be a, b regardless of whether a < b</li>
<li>when introducting ⊥ from a: X, b: ¬X; the order will be a, b</li>
<li>similarly for other connectives</li>
</ul>
</p>
</div>
<div class="modalblock">
<h3>Author</h3>
<div>Luka Mikec, nameDOTsurnameATgmailDOTcom, and insert 1 before AT</div>
</div>
</div>
</div>
<header>
<h1>
Justify
</h1>
</header>
<div class="navigation">
<select class="button" id="format" oninput="style_click()" >
<option value="fitch" selected>Style: Fitch</option>
<option value="gentzen">Style: Gentzen</option>
</select>
<div class="button" title="Green: valid syntax & justifications found for all lines. Blue: valid syntax & missing justifications. Yellow: otherwise. ">
Status: <div id="status" style=""></div>
</div>
<div style=" flex-grow: 1 !important;"></div>
<select class="button" id="examples" oninput="example_click()" >
<option value="contrapos" selected>Example: Contraposition</option>
<option value="demorgan1">Example: De Morgan 1</option>
<option value="demorgan2">Example: De Morgan 2</option>
<option value="bicond_assoc">Example: ''Associativity'' of <-> </option>
<option value="drinker">Example: Drinker</option>
</select>
<a class="button" onclick="help_click()" >
Help
</a>
<a class="button" target="_blank" href="https://github.com/luka-mikec/justify">
Git repository
</a>
<select class="button" id="lang" oninput="lang_click()" >
<option value="en" selected>English</option>
<option value="hr">Croatian</option>
</select>
</div>
<section>
<div style="" id="inout">
<textarea id="in" rows="35" style="" oninput="in_press(event)">
</textarea>
<div id="out">
<div id="out_fitch">
<div style="display: flex;" >
<div id="out_nums" style=""></div>
<div id="out_nodes" style=""></div>
<div id="out_just" style=""></div>
</div>
</div>
<div id="out_gentz"></div>
</div>
</div>
<textarea id="out_lat" style="">b</textarea>
<div id="out_dbg" style="display: none;">c</div>
</section>
<script>
function help_click()
{
document.querySelector('.modal').style.display = 'block';
document.querySelector('.modal_overlay').style.display = 'block';
}
function help_close()
{
document.querySelector('.modal').style.display = 'none';
document.querySelector('.modal_overlay').style.display = 'none';
}
function lang_click(dont_compile)
{
window.clang = window[document.querySelector('#lang').value];
refresh_lang();
if (!dont_compile)
try_compile();
state_to_location();
}
//document.body.addEventListener('click', () => { document.querySelector('.modal').style.display = 'none'; } , true);
function wip_state()
{
status_div.style.backgroundColor = 'rgb(55,99,200)';
}
function ok_state()
{
status_div.style.backgroundColor = '#4CAF50';
}
function error_state()
{
status_div.style.backgroundColor = 'rgb(255, 213, 27)';
}
function example_click(dont_compile, dont_save)
{
in_div.value = window[document.querySelector('#examples').value].trim();
if (!dont_compile)
try_compile();
if (!dont_save)
state_to_location();
}
function style_click(dont_compile)
{
window.renderer = document.querySelector('#format').value;
out_fitch.style.display = window.renderer == 'fitch' ? 'flex' : 'none';
out_gentz.style.display = window.renderer == 'gentzen' ? 'flex' : 'none';
if (!dont_compile)
try_compile();
state_to_location();
}
function try_compile()
{
try {
if (compile())
ok_state();
else
wip_state();
} catch (e)
{
error_state();
}
}
function in_keypress(args) {
//window.setTimeout(() => console.log(a, b, c, d), 1000);
//if (args.code == "Enter")
if (args.inputType == "insertLineBreak")
{
if (in_div.selectionEnd != in_div.selectionStart)
return;
let a = in_div.selectionStart;
let line_end = in_div.value.indexOf('\n', a);
if (line_end == -1)
line_end = in_div.value.length;
if ( in_div.value.substring(a, line_end).trim() != "" )
return;
let line_start;
for (line_start = a - 1; line_start >= 0; --line_start)
{
if (in_div.value[line_start] == '\n')
{
break;
}
}
++line_start;
let cline = in_div.value.substring(line_start, a);
let indent = 0;
for (let i = 0; i < cline.length; ++i)
{
if (cline[i] == '|') ++indent;
else {
if (cline[i].toString().trim() == '')
continue;
if (cline[i] == 'L') {
++indent;
}
break;
}
}
window.setTimeout(() => {
in_div.value = in_div.value.substring(0, a) + "\n" + '|'.repeat(indent) + " " + '' + in_div.value.substring(line_end + 1);
in_div.selectionStart = in_div.selectionEnd = a + 2 + indent;
}, 20);
}
}
function in_press(args) {
state_to_location();
try_compile();
}
function state_to_location() {
let code = [
[ 'lang', document.querySelector('#lang').value ],
[ 'examples', document.querySelector('#examples').value ],
[ 'format', document.querySelector('#format').value ],
[ 'input', encodeURIComponent(in_div.value) ],
].map(arr => arr.join('=')).join('___');
let new_loc;
if (window.location.href.indexOf('#') != -1)
{
new_loc = window.location.href.substring(0,
window.location.href.indexOf('#'));
}
else
new_loc = window.location.href;
window.location.href = new_loc + '#' + code;
}
window.addEventListener('load', () => {
let had_proper_input = false;
if (window.location.href.indexOf('#') != -1)
{
let pairs = window.location.href.
substring(window.location.href.indexOf('#') + 1).
split('___');
for (let pair of pairs) {
let [key, val] = pair.split('=');
switch (key) {
case 'lang':
document.querySelector('#lang').value = val;
break;
case 'examples':
document.querySelector('#examples').value = val;
break;
case 'format':
document.querySelector('#format').value = val;
break;
case 'input':
in_div.value = decodeURIComponent(val);
had_proper_input = true;
break;
}
}
}
lang_click(true);
style_click(true);
if (!had_proper_input )
example_click(true, true);
in_div.addEventListener('beforeinput', in_keypress, true);
try_compile();
});
</script>
<script src="index.js"></script>
</body>
</html>