-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoalCommands.js
288 lines (278 loc) · 9.02 KB
/
GoalCommands.js
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
// Goal menu commands
"use strict";
function doDirContrap(doDirect) {
if (doDirect) {
helpURL = "help/Direct.html";
commandName = "Direct";
} else {
helpURL = "help/Contrapos.html";
commandName = "Contrapositive";
}
if (!gapSelected(true)) {
useError();
return;
}
var theGap = selectedStep;
var goalVariant = getGoalVariant(cond, true);
if (goalVariant == null) {
useError();
return;
}
prepareStep();
var conditional = goalVariant.theForm;
var newGivenFormula, newGoalFormula;
if (doDirect) {
newGivenFormula = conditional.left.cloneForm();
newGoalFormula = conditional.right.cloneForm();
newGivenFormula.parens = null;
newGoalFormula.parens = null;
} else {
newGivenFormula = negate(conditional.right.cloneForm());
newGoalFormula = negate(conditional.left.cloneForm());
}
var newGiven = makeStmnt(newGivenFormula);
var newGoal = makeStmnt(newGoalFormula);
var theInference = inferenceBySubproof(theGap, null, null, [newGiven], newGoal, null, null, true);
theGap.parentNode.replaceChild(theInference, theGap);
}
function doBicond() {
helpURL = "help/Bicond.html";
commandName = "Biconditional";
if (!gapSelected(true)) {
useError();
return;
}
var goalVariant = getGoalVariant(bicond, true);
if (goalVariant == null) {
useError();
return;
}
var theGap = selectedStep;
prepareStep();
var biconditional = goalVariant.theForm;
var leftSide = biconditional.left;
var rightSide = biconditional.right;
var ltor = new CompoundFormula(cond, bool, leftSide.cloneForm(), rightSide.cloneForm());
var rtol = new CompoundFormula(cond, bool, rightSide.cloneForm(), leftSide.cloneForm());
var theInference = inferenceBySubproof(theGap, null, null, null,
makeStmnt(ltor), null, "\u2192:", true);
var firstSubpf = theInference.firstChild;
var rtolStmnt = makeStmnt(rtol);
var subpfData = getData(firstSubpf);
var nextSubpf = makeSubproof(null, null, rtolStmnt, subpfData.casePrefix,
subpfData.lemmaDepth, "\u2190:");
nextSubpf.lastChild.appendChild(updateGoalGap(theGap, null, null, rtolStmnt));
theInference.insertBefore(nextSubpf, firstSubpf.nextSibling);
theGap.parentNode.replaceChild(theInference, theGap);
}
function doConj(conjoin) {
var usedStmnts, stillToProve, conjuncts, varPane, backwards, numSelected, i, s;
if (conjoin) {
helpURL = "help/Conjoin.html";
commandName = "Conjoin";
} else {
helpURL = "help/Conjunction.html";
commandName = "Conjunction";
}
usedStmnts = [];
numSelected = selection.length;
backwards = ((numSelected == 0) || (getVarKind(selection[0]) != given));
if (!gapSelected(backwards)) {
useError();
return;
}
if (backwards) {
if (conjoin && (numSelected <= 1)) {
useError();
return;
}
var conjFWT = getGoalVariant(conj, false);
if (conjFWT == null) {
useError();
return;
}
conjuncts = conjFWT.theForm.args.slice(0);
for (i = 1; i < numSelected; i++) {
varPane = selection[i];
s = getData(varPane.parentNode).theStmnt;
if (!cutFromList(s[getData(varPane).variant].theForm, conjuncts, conj)) {
useError();
return;
}
if (!usedStmnts.includes(s)) {
usedStmnts.push(s);
}
}
var numConjuncts = conjuncts.length;
if (numConjuncts == 0) {
stillToProve = null;
} else {
stillToProve = [];
for (i = 0; i < numConjuncts; i++) {
var concForm = conjuncts[i].cloneForm();
concForm.parens = null;
s = makeStmnt(concForm);
stillToProve.push(s);
usedStmnts.push(s);
}
}
backwardStep(selectedStep, null, stillToProve, usedStmnts, null);
} else {
if (!conjoin || (numSelected == 1)) {
useError();
return;
}
conjuncts = [];
for (i = 0; i < numSelected; i++) {
varPane = selection[i];
s = getData(varPane.parentNode).theStmnt;
var givenForm = s[getData(varPane).variant].theForm.cloneForm();
addToList(givenForm, conjuncts, conj);
if (!usedStmnts.includes(s)) {
usedStmnts.push(s);
}
}
var infStmnt = makeStmnt(new MultiCompoundFormula(conj, bool, conjuncts));
forwardStep(selectedStep, null, usedStmnts, null, [infStmnt], null, false);
}
}
function doDisj() {
var goalVariant, theDialog, disjPane, disjList, numDisjuncts, i;
var okButton, negateBox;
var selDisj = null;
function selectDisj(e) {
if (selDisj != null) {
selDisj.classList.remove("selected");
}
selDisj = e;
selDisj.classList.add("selected");
okButton.disabled = false;
}
function finishDisj() {
hideDialog();
var theGap = selectedStep;
prepareStep();
var toProveFWT = getData(selDisj).formWithText;
var toProveStmnt = [toProveFWT];
if (negateBox.checked) {
var newPremises = [];
var nextPrem = disjPane.firstChild;
do {
if (nextPrem != selDisj) {
newPremises.push(makeStmnt(negate(getData(nextPrem).formWithText.theForm)));
}
nextPrem = nextPrem.nextSibling;
} while (nextPrem != null);
var theInference = inferenceBySubproof(theGap, null, null, newPremises,
toProveStmnt, null, null, true);
theGap.parentNode.replaceChild(theInference, theGap);
} else {
backwardStep(theGap, null, [toProveStmnt], [toProveStmnt], null);
}
}
helpURL = "help/Disjunction.html";
commandName = "Disjunction";
if (!gapSelected(true)) {
useError();
return;
}
goalVariant = getGoalVariant(disj, false);
if (goalVariant == null) {
useError();
return;
}
if (selection.length > 2) {
useError();
return;
}
if (selection.length == 2) {
finishByAddition(goalVariant.theForm);
return;
}
theDialog = makeDialog(32);
theDialog.appendChild(makeTextPane("Which statement are you going to prove?", 0, 0.66));
disjPane = document.createElement("DIV");
disjPane.className = "list-pane";
disjPane.style.height = (6 * (lineHeight + 0.1)) + "em";
theDialog.appendChild(disjPane);
disjList = goalVariant.theForm.args;
numDisjuncts = disjList.length;
for (i = 0; i < numDisjuncts; i++) {
var theDisj = disjList[i].cloneForm();
theDisj.parens = null;
var theDisjFWT = {theForm: theDisj, theText: theDisj.toText()};
var elem = textToElem(theDisjFWT.theText, "DIV", false);
var disjData = makeData(elem);
disjData.formWithText = theDisjFWT;
elem.onclick = function() {selectDisj(this)};
elem.classList.add("list-element");
elem.style.height = (lineHeight + 0.1) + "em";
disjPane.appendChild(elem);
}
var negatePane = document.createElement("LABEL");
negatePane.style.margin = "0.66em 0em 0.66em";
negateBox = document.createElement("INPUT");
negateBox.type = "checkbox";
negateBox.checked = true;
negatePane.appendChild(negateBox);
var negateLabel = document.createElement("SPAN");
negateLabel.innerHTML = "Assume negations of others.";
negateLabel.style.marginLeft = radioCheckSpace + "em";
negatePane.appendChild(negateLabel);
theDialog.appendChild(negatePane);
var okCancelPanel = makeButtonPanel(["OK", "Cancel"]);
theDialog.appendChild(okCancelPanel);
okButton = okCancelPanel.firstChild;
var cancelButton = okButton.nextSibling;
okButton.disabled = true;
okButton.onclick = finishDisj;
cancelButton.onclick = function() {hideDialog()};
showDialog(theDialog, okButton, true);
}
function doExistUnique() {
helpURL = "help/ExistUnique.html";
commandName = "Existence & Uniqueness";
if (!gapSelected(true)) {
useError();
return;
}
var goalVariant = getGoalVariant(unique, true);
if (goalVariant == null) {
useError();
return;
}
var theGap = selectedStep;
prepareStep();
var existGoal = goalVariant.theForm.cloneForm();
existGoal.kind = exist;
var avoidVars = willBeDefined(theGap, false);
addSetToSet(avoidVars, getData(theGap).defined);
existGoal.addVars(avoidVars, false);
var qScope = existGoal.scope.cloneForm();
var qBound = existGoal.from;
if (qBound != null) {
qBound = qBound.cloneForm();
}
var uniqueGoal = qScope.assertUnique(2, existGoal.bdVar, qBound, avoidVars, false);
var uniqueStmnt = makeStmnt(uniqueGoal);
var theInference = inferenceBySubproof(theGap, null, null, null,
makeStmnt(existGoal), null, "Existence", true);
var firstSubpf = theInference.firstChild;
var pfData = getData(firstSubpf);
var nextSubpf = makeSubproof(null, null, uniqueStmnt,
pfData.casePrefix, pfData.lemmaDepth, "Uniqueness");
theInference.insertBefore(nextSubpf, firstSubpf.nextSibling);
nextSubpf.lastChild.appendChild(updateGoalGap(theGap, null, null, uniqueStmnt));
theGap.parentNode.replaceChild(theInference, theGap);
}
// goalForm is a disjunction, one given also selected. See if we can finish by addition.
function finishByAddition(goalForm) {
var givenStmnt = getData(selection[1].parentNode).theStmnt;
var givenForm = givenStmnt[getData(selection[1]).variant].theForm;
var goalArgs = goalForm.args.slice(0);
if (!cutFromList(givenForm, goalArgs, disj) || (goalArgs.length == 0)) {
useError();
} else {
backwardStep(selectedStep, null, null, [givenStmnt], null);
}
}