-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsheffer.html
276 lines (221 loc) · 8.3 KB
/
sheffer.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sheffer Stroke Converter</title>
<script src='truthtable.js' type="text/javascript"></script>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet">
<style type="text/css">
body {
font-family: "Open Sans", Verdana, Helvetica, sans-serif;
color:#444444;
height:100%;
background-color:white;
margin: 0px;
padding: 0px;
}
a:link {color:#4B2EDE;text-decoration:none;} /* unvisited link */
a:visited {color:#4B2EDE;text-decoration:none;} /* visited link */
a:hover {color:#9D90DC;text-decoration:none;} /* mouse over link */
a:active {color:#FFA04D;text-decoration:none;} /* selected link */
#container {
width:90%;
max-width: 800px;
position: relative;
min-height: 100vh;
margin-right:auto;
margin-left:auto;
font-size:16px;
padding-bottom:40px;
}
#location {
color:#999999;
font-size:14px;
padding-top:5px;
}
#location a {
color:#999999;
}
#githublink {
position:absolute;
top:5px;
right:5px;
}
#title {
text-align:center;
font-size:26px;
margin-top:15px;
margin-bottom:15px;
}
.ttinput {
margin-left:auto;
margin-right:auto;
padding-top:5px;
padding-bottom:5px;
}
.tt {
width:100%;
margin-left:auto;
margin-right:auto;
margin-top: 20px;
margin-bottom: 20px;
border-top:solid 1px #d3d3d3;
border-bottom:solid 1px #d3d3d3;
min-height:80px;
}
.tt p {
text-align:center;
}
td.connective {
padding-right:1em;
}
footer {
font-size:85%;
color:#aaaaaa;
text-align:center;
position:absolute;
bottom:0;
width:100%;
padding:5px;
}
</style>
<script type="text/javascript">
var nandneg = "(p|p)";
var nandcon = "((p|q)|(p|q))";
var nanddis = "((p|p)|(q|q))";
var nandimp = "(p|(q|q))";
var nandbic = "(((p|(q|q))|(q|(p|p)))|((p|(q|q))|(q|(p|p))))";
var nandnand = "(p|q)";
var nandnor = "(((p|p)|(q|q))|((p|p)|(q|q)))";
var norneg = "(p!p)";
var norcon = "((p!p)!(q!q))";
var nordis = "((p!q)!(p!q))";
var norimp = "(((p!p)!q)!((p!p)!q))";
var norbic = "(((p!p)!((q!q)!(q!q)))!((q!q)!((p!p)!(p!p))))";
var nornand = "(((p!p)!(q!q))!((p!p)!(q!q)))";
var nornor = "(p!q)";
function constructnand() {
var formula = document.getElementById('in1').value.replace(/ /g,'');// remove whitespace
if(formula=='') {return alert("You have to enter a formula.");};
var r = badchar(formula);
if(r>=0) {return alert("The string you entered contains the following unrecognized symbol: "+formula[r]);};
var tree = parse(formula);
if(tree.length==0) {
formula = '('+formula+')';
tree = parse(formula);
}
if(tree.length==0) { // checks if any formulas are still malformed
return alert("The formula you entered is not well formed");
}
var schemas = [nandneg,nandcon,nanddis,nandimp,nandbic,nandnand,nandnor];
var translation = translate(tree,schemas);
document.getElementById('tt1').innerHTML = "<p>"+translation+"</p>";
}
function constructnor() {
var formula = document.getElementById('in2').value.replace(/ /g,'');// remove whitespace
if(formula=='') {return alert("You have to enter a formula.");};
var r = badchar(formula);
if(r>=0) {return alert("The string you entered contains the following unrecognized symbol: "+formula[r]);};
var tree = parse(formula);
if(tree.length==0) {
formula = '('+formula+')';
tree = parse(formula);
}
if(tree.length==0) { // checks if any formulas are still malformed
return alert("The formula you entered is not well formed");
}
var schemas = [norneg,norcon,nordis,norimp,norbic,nornand,nornor];
var translation = translate(tree,schemas);
document.getElementById('tt2').innerHTML = "<p>"+translation+"</p>";
}
function translate(t,s) {
var schema = "";
var out = "";
if(t.length==5) {
var lh = translate(t[1],s);
var rh = translate(t[3],s);
if(t[2]=='&') {
schema = s[1].split('');
schema = schema.map((el) => el=='p' ? lh : (el=='q' ? rh : el));
return schema.join("");
} else if(t[2]=='v') {
schema = s[2].split('');
schema = schema.map((el) => el=='p' ? lh : (el=='q' ? rh : el));
return schema.join("");
} else if(t[2]=='>') {
schema = s[3].split('');
schema = schema.map((el) => el=='p' ? lh : (el=='q' ? rh : el));
return schema.join("");
} else if(t[2]=='<>') {
schema = s[4].split('');
schema = schema.map((el) => el=='p' ? lh : (el=='q' ? rh : el));
return schema.join("");
} else if(t[2]=='|') {
schema = s[5].split('');
schema = schema.map((el) => el=='p' ? lh : (el=='q' ? rh : el));
return schema.join("");
} else if(t[2]=='!') {
schema = s[6].split('');
schema = schema.map((el) => el=='p' ? lh : (el=='q' ? rh : el));
return schema.join("");
}
} else if(t.length==2) {
var rh = translate(t[1],s);
schema = s[0].split('');
schema = schema.map((el) => el=='p' ? rh : el);
return schema.join("");
} else if(t.length==1) {
return t[0];
}
}
</script>
</head>
<body>
<div id='container'>
<div id='location'><a href='../index.html'>Home</a> > <a href='../etc/index.html'>Etc</a> > <a href='truthtable.html'>Truth Table Generator</a> > <a href='sheffer.html'>Sheffer Stroke Converter</a></div>
<div id='githublink'><a href='https://github.com/mrieppel/TruthTableGenerator'><img src='github.png' style="height:25px;"></a></div>
<div id='title'>Sheffer Stroke Converter</div>
<p>This page contains a program that will convert a formula of truth-functional logic into an equivalent formula that uses only the <a href='http://en.wikipedia.org/wiki/Sheffer_stroke'>Sheffer Stroke</a> (representing the NAND operation). It won't generally be the <i>shortest</i> equivalent formula, though! Try out ~(A&B), for example. You can generate truth tables for the converted formulas <a href='truthtable.html'>here</a>. See below for the keyboard symbols to use for the logical connectives.</p>
<div class="ttinput">
<input type="text" class="in" id="in1" size="40">
<input type="button" value="Convert" onclick="constructnand();">
</div>
<div class="tt" id="tt1"></div>
<p>Wittgenstein famously used the Sheffer stroke in the <a href="https://en.wikipedia.org/wiki/Tractatus_Logico-Philosophicus">Tractatus</a>, but there it represents the <a href="https://en.wikipedia.org/wiki/Logical_NOR">NOR operation</a> (rather than NAND). So here is another converter, this time one that will output an equivalent formula using only a NOR-stroke (here represented using '!'). So (A!B) means ~(AvB) or, equivalently, (~A&~B) i.e. the joint denial of A and B. In the Tractatus Wittgenstein generalized this into his N operator, which forms the joint denial of any collection of propositions. You can read more about that <a href="https://www.jstor.org/stable/3327740?seq=1">here</a>.
<div class="ttinput">
<input type="text" class="in" id="in2" size="40">
<input type="button" value="Convert" onclick="constructnor();">
</div>
<div class="tt" id="tt2"></div>
<p><b>Symbols:</b> use the following keyboard symbols in your input for the various logical connectives:</p>
<table>
<tr><td class="connective">~</td><td>for negation</td></tr>
<tr><td class="connective">&</td><td>for conjunction</td></tr>
<tr><td class="connective">v</td><td>for disjunction</td></tr>
<tr><td class="connective">></td><td>for the conditional</td></tr>
<tr><td class="connective">< ></td><td>for the biconditional</td></tr>
<tr><td class="connective">#</td><td>for absurdity</td></tr>
<tr><td class="connective">|</td><td>for NAND (aka the Sheffer Stroke)</td></tr>
<tr><td class="connective">!</td><td>for NOR (Wittgenstein's Sheffer Stroke)</td></tr>
</table>
<br>
<p>Here are some examples of well-formed inputs the program will accept:</p>
<ul style="list-style-type:none;padding:0;">
<li>~A</li>
<li>(A & B)</li>
<li>(A & (~B > C))</li>
<li>(# > (B v ~A))</li>
<li>(A|B) <> ~(A & B)</li>
<li>~((A v D) <> (B & C))
</li>
</ul>
<p>The source code is available on GitHub, just click the icon at the top right corner of the page.
<footer>© 2010-2022 Michael Rieppel</footer>
</div>
<!-- Close container div -->
<!-- Start of StatCounter Code for Default Guide -->
<!-- End of StatCounter Code for Default Guide -->
</body>
</html>