occam-verify-cli 0.0.1073 → 0.0.1075

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/lib/assertion/type.js +47 -54
  2. package/lib/assignment/equality.js +8 -2
  3. package/lib/assignment/variable.js +2 -2
  4. package/lib/axiom.js +9 -12
  5. package/lib/combinator/bracketed.js +3 -2
  6. package/lib/combinator.js +6 -6
  7. package/lib/conclusion.js +2 -3
  8. package/lib/conjecture.js +10 -15
  9. package/lib/consequent.js +2 -3
  10. package/lib/constructor/bracketed.js +3 -2
  11. package/lib/constructor.js +6 -6
  12. package/lib/context/file.js +48 -107
  13. package/lib/context/local.js +52 -73
  14. package/lib/declaration/combinator.js +5 -5
  15. package/lib/declaration/constructor.js +5 -5
  16. package/lib/declaration/metavariable.js +4 -5
  17. package/lib/declaration/type.js +3 -3
  18. package/lib/declaration/variable.js +5 -5
  19. package/lib/declaration.js +6 -2
  20. package/lib/derivation.js +6 -2
  21. package/lib/equality.js +53 -22
  22. package/lib/equivalence.js +22 -24
  23. package/lib/frame.js +11 -13
  24. package/lib/index.js +13 -1
  25. package/lib/judgement.js +11 -8
  26. package/lib/label.js +6 -7
  27. package/lib/lemma.js +10 -15
  28. package/lib/metaLemma.js +15 -15
  29. package/lib/metatheorem.js +9 -14
  30. package/lib/metavariable.js +17 -23
  31. package/lib/mixins/statement/qualified/unify.js +2 -2
  32. package/lib/mixins/statement/verify.js +8 -12
  33. package/lib/mixins/term/verify.js +4 -4
  34. package/lib/premise.js +2 -3
  35. package/lib/proof.js +8 -4
  36. package/lib/proofStep.js +10 -8
  37. package/lib/reference.js +3 -3
  38. package/lib/rule.js +11 -16
  39. package/lib/statement/qualified.js +6 -2
  40. package/lib/statement/unqualified.js +1 -1
  41. package/lib/statement.js +5 -5
  42. package/lib/subDerivation.js +6 -2
  43. package/lib/subproof.js +10 -7
  44. package/lib/substitution/statementForMetavariable.js +14 -15
  45. package/lib/substitution.js +13 -13
  46. package/lib/substitutions.js +51 -47
  47. package/lib/supposition.js +2 -3
  48. package/lib/term.js +5 -5
  49. package/lib/theorem.js +10 -15
  50. package/lib/topLevelAssertion.js +3 -3
  51. package/lib/type.js +15 -22
  52. package/lib/unifier/equality.js +2 -2
  53. package/lib/unifier/metaLevel.js +6 -6
  54. package/lib/unifier/metavariable.js +5 -5
  55. package/lib/unifier/statementWithCombinator.js +2 -2
  56. package/lib/utilities/brackets.js +2 -2
  57. package/lib/utilities/equivalences.js +8 -8
  58. package/lib/utilities/node.js +2 -7
  59. package/lib/utilities/nominal.js +26 -0
  60. package/lib/utilities/subproof.js +2 -2
  61. package/lib/utilities/tokens.js +3 -7
  62. package/lib/variable.js +13 -9
  63. package/lib/verifier/metaLevel.js +2 -2
  64. package/lib/verifier/statementAsCombinator.js +2 -2
  65. package/lib/verifier/termAsConstructor.js +2 -2
  66. package/lib/verifier/topLevel.js +9 -15
  67. package/package.json +1 -1
  68. package/src/assertion/type.js +52 -57
  69. package/src/assignment/equality.js +3 -1
  70. package/src/assignment/variable.js +2 -1
  71. package/src/axiom.js +6 -8
  72. package/src/combinator/bracketed.js +6 -3
  73. package/src/combinator.js +4 -4
  74. package/src/conclusion.js +2 -2
  75. package/src/conjecture.js +8 -11
  76. package/src/consequent.js +2 -2
  77. package/src/constructor/bracketed.js +6 -3
  78. package/src/constructor.js +4 -4
  79. package/src/context/file.js +46 -90
  80. package/src/context/local.js +51 -90
  81. package/src/declaration/combinator.js +5 -4
  82. package/src/declaration/constructor.js +5 -4
  83. package/src/declaration/metavariable.js +3 -4
  84. package/src/declaration/type.js +2 -2
  85. package/src/declaration/variable.js +5 -4
  86. package/src/declaration.js +7 -1
  87. package/src/derivation.js +7 -1
  88. package/src/equality.js +80 -27
  89. package/src/equivalence.js +30 -28
  90. package/src/frame.js +10 -9
  91. package/src/index.js +12 -0
  92. package/src/judgement.js +11 -5
  93. package/src/label.js +5 -5
  94. package/src/lemma.js +8 -11
  95. package/src/metaLemma.js +13 -11
  96. package/src/metatheorem.js +6 -10
  97. package/src/metavariable.js +18 -34
  98. package/src/mixins/statement/qualified/unify.js +1 -2
  99. package/src/mixins/statement/verify.js +19 -18
  100. package/src/mixins/term/verify.js +4 -3
  101. package/src/premise.js +2 -2
  102. package/src/proof.js +10 -3
  103. package/src/proofStep.js +12 -7
  104. package/src/reference.js +3 -2
  105. package/src/rule.js +10 -12
  106. package/src/statement/qualified.js +7 -1
  107. package/src/statement/unqualified.js +0 -1
  108. package/src/statement.js +3 -3
  109. package/src/subDerivation.js +8 -2
  110. package/src/subproof.js +12 -5
  111. package/src/substitution/statementForMetavariable.js +12 -12
  112. package/src/substitution.js +9 -9
  113. package/src/substitutions.js +42 -34
  114. package/src/supposition.js +2 -2
  115. package/src/term.js +3 -3
  116. package/src/theorem.js +8 -11
  117. package/src/topLevelAssertion.js +3 -2
  118. package/src/type.js +15 -28
  119. package/src/unifier/equality.js +1 -1
  120. package/src/unifier/metaLevel.js +8 -10
  121. package/src/unifier/metavariable.js +5 -5
  122. package/src/unifier/statementWithCombinator.js +5 -5
  123. package/src/utilities/brackets.js +2 -2
  124. package/src/utilities/equivalences.js +9 -9
  125. package/src/utilities/node.js +1 -10
  126. package/src/utilities/nominal.js +14 -0
  127. package/src/utilities/subproof.js +2 -2
  128. package/src/utilities/tokens.js +2 -9
  129. package/src/variable.js +16 -11
  130. package/src/verifier/metaLevel.js +2 -2
  131. package/src/verifier/statementAsCombinator.js +3 -3
  132. package/src/verifier/termAsConstructor.js +2 -2
  133. package/src/verifier/topLevel.js +15 -14
  134. package/lib/assignment/metavariable.js +0 -62
  135. package/lib/unifier/intrinsicLevel.js +0 -144
  136. package/lib/utilities/unify.js +0 -24
  137. package/lib/verifier/intrinsicLevel.js +0 -140
  138. package/src/assignment/metavariable.js +0 -30
  139. package/src/unifier/intrinsicLevel.js +0 -54
  140. package/src/utilities/unify.js +0 -23
  141. package/src/verifier/intrinsicLevel.js +0 -42
@@ -10,14 +10,13 @@ import { mergeEquivalences, findEquivalenceByTerm, groundedTermsAndDefinedVariab
10
10
  const { last } = arrayUtilities;
11
11
 
12
12
  class LocalContext {
13
- constructor(context, tokens, variables, proofSteps, judgements, equivalences, metavariables) {
13
+ constructor(context, tokens, variables, proofSteps, judgements, equivalences) {
14
14
  this.context = context;
15
15
  this.tokens = tokens;
16
16
  this.variables = variables;
17
17
  this.proofSteps = proofSteps;
18
18
  this.judgements = judgements;
19
19
  this.equivalences = equivalences;
20
- this.metavariables = metavariables;
21
20
  }
22
21
 
23
22
  getContext() {
@@ -28,13 +27,19 @@ class LocalContext {
28
27
  return this.tokens;
29
28
  }
30
29
 
31
- getVariables() {
32
- let variables = this.context.getVariables();
30
+ getVariables(nested = true) {
31
+ let variables;
33
32
 
34
- variables = [ ///
35
- ...this.variables,
36
- ...variables
37
- ];
33
+ if (nested) {
34
+ variables = this.context.getVariables();
35
+
36
+ variables = [
37
+ ...this.variables,
38
+ ...variables
39
+ ];
40
+ } else {
41
+ variables = this.variables;
42
+ }
38
43
 
39
44
  return variables;
40
45
  }
@@ -65,25 +70,13 @@ class LocalContext {
65
70
  let equivalences = this.context.getEquivalences();
66
71
 
67
72
  const equivalencesA = this.equivalences, ///
68
- equivalencesB = equivalences,
69
- LocalContext = this; ///
73
+ equivalencesB = equivalences;
70
74
 
71
- equivalences = mergeEquivalences(equivalencesA, equivalencesB, LocalContext); ///
75
+ equivalences = mergeEquivalences(equivalencesA, equivalencesB); ///
72
76
 
73
77
  return equivalences;
74
78
  }
75
79
 
76
- getMetavariables() {
77
- let metavariables = this.context.getMetavariables();
78
-
79
- metavariables = [ ///
80
- ...this.metavariables,
81
- ...metavariables
82
- ]
83
-
84
- return metavariables;
85
- }
86
-
87
80
  getLastProofStep() {
88
81
  let lastProofStep = null;
89
82
 
@@ -112,7 +105,7 @@ class LocalContext {
112
105
 
113
106
  getConstructors() { return this.context.getConstructors(); }
114
107
 
115
- addEquality(equality) {
108
+ addEquality(equality, localContext) {
116
109
  let equalityAdded;
117
110
 
118
111
  const equalityReflexive = equality.isReflexive();
@@ -130,15 +123,15 @@ class LocalContext {
130
123
  } else if ((leftEquivalence === null) && (rightEquivalence === null)) {
131
124
  const equivalence = Equivalence.fromLeftTermAndRightTerm(leftTerm, rightTerm);
132
125
 
133
- this.addEquivalence(equivalence);
126
+ this.addEquivalence(equivalence, localContext);
134
127
 
135
128
  equalityAdded = true;
136
129
  } else if ((leftEquivalence !== null) && (rightEquivalence === null)) {
137
- leftEquivalence.addTerm(rightTerm);
130
+ leftEquivalence.addTerm(rightTerm, localContext);
138
131
 
139
132
  equalityAdded = true;
140
133
  } else if ((leftEquivalence === null) && (rightEquivalence !== null)) {
141
- rightEquivalence.addTerm(leftTerm);
134
+ rightEquivalence.addTerm(leftTerm, localContext);
142
135
 
143
136
  equalityAdded = true;
144
137
  } else if ((leftEquivalence !== null) && (rightEquivalence !== null)) {
@@ -156,9 +149,9 @@ class LocalContext {
156
149
  this.addEquivalence(equivalence);
157
150
  }
158
151
 
159
- equivalence.addTerm(leftTerm);
152
+ equivalence.addTerm(leftTerm, localContext);
160
153
 
161
- equivalence.addTerm(rightTerm);
154
+ equivalence.addTerm(rightTerm, localContext);
162
155
 
163
156
  equalityAdded = true;
164
157
  }
@@ -167,17 +160,11 @@ class LocalContext {
167
160
  return equalityAdded;
168
161
  }
169
162
 
170
- addVariable(variable) {
163
+ addVariable(variable, nested = true) {
171
164
  let variableAdded = false;
172
165
 
173
- const variableNode = variable.getNode(),
174
- variablePresent = this.variables.some((variable) => {
175
- const variableMatchesNode = variable.matchVariableNode(variableNode);
176
-
177
- if (variableMatchesNode) {
178
- return true;
179
- }
180
- });
166
+ const variableName = variable.getNode(),
167
+ variablePresent = this.isVariablePresentByVariableName(variableName, nested);
181
168
 
182
169
  if (!variablePresent) {
183
170
  this.variables.push(variable);
@@ -192,7 +179,11 @@ class LocalContext {
192
179
  this.proofSteps.push(proofStep);
193
180
  }
194
181
 
195
- addEquivalence(equivalence) {
182
+ addEquivalence(equivalence, localContext) {
183
+ const equivalenceString = equivalence.asString();
184
+
185
+ localContext.trace(`Added the '${equivalenceString}' equivalence.`);
186
+
196
187
  this.equivalences.push(equivalence);
197
188
  }
198
189
 
@@ -208,9 +199,8 @@ class LocalContext {
208
199
  let judgementAdded = false;
209
200
 
210
201
  const metavariableNode = judgement.getMetavariableNode(),
211
- metavariableName = metavariableNameFromMetavariableNode(metavariableNode),
212
- metavariableDefinedByMetavariableName = this.isMetavariableDefinedByMetavariableName(metavariableName),
213
- judgementPresent = metavariableDefinedByMetavariableName; ///
202
+ metavariableDefined = this.isMetavariableDefinedByMetavariableNode(metavariableNode),
203
+ judgementPresent = metavariableDefined; ///
214
204
 
215
205
  if (!judgementPresent) {
216
206
  this.judgements.push(judgement);
@@ -221,21 +211,6 @@ class LocalContext {
221
211
  return judgementAdded;
222
212
  }
223
213
 
224
- addMetavariable(metavariable) {
225
- let metavariableAdded = false;
226
-
227
- const metavariableName = metavariable.getName(),
228
- metavariablePresent = this.isMetavariablePresentByMetavariableName(metavariableName);
229
-
230
- if (!metavariablePresent) {
231
- this.metavariables.push(metavariable);
232
-
233
- metavariableAdded = true;
234
- }
235
-
236
- return metavariableAdded;
237
- }
238
-
239
214
  getTermType(term) {
240
215
  let termType;
241
216
 
@@ -299,35 +274,37 @@ class LocalContext {
299
274
 
300
275
  isLabelPresentByMetavariableNode(metavariableNode) { return this.context.isLabelPresentByMetavariableNode(metavariableNode); }
301
276
 
302
- isMetavariablePresentByMetavariableName(metavariableName) { return this.context.isMetavariablePresentByMetavariableName(metavariableName); }
277
+ isMetavariablePresentByMetavariableNode(metavariableNode, localContext) { return this.context.isMetavariablePresentByMetavariableNode(metavariableNode, localContext); }
303
278
 
304
- isVariablePresentByVariableName(variableName) {
305
- const variable = this.findVariableByVariableName(variableName),
279
+ isVariablePresentByVariableName(variableName, nested = true) {
280
+ const variable = this.findVariableByVariableName(variableName, nested),
306
281
  variablePresent = (variable !== null);
307
282
 
308
283
  return variablePresent;
309
284
  }
310
285
 
311
- isJudgementPresentByMetavariableName(metavariableName) {
312
- const judgement = this.findJudgementByMetavariableName(metavariableName),
286
+ isJudgementPresentByMetavariableNode(metavariableNode) {
287
+ const judgement = this.findJudgementByMetavariableNode(metavariableNode),
313
288
  judgementPresent = (judgement !== null);
314
289
 
315
290
  return judgementPresent;
316
291
  }
317
292
 
318
- isMetavariableDefinedByMetavariableName(metavariableName) {
319
- const judgementPresent = this.isJudgementPresentByMetavariableName(metavariableName),
320
- metavariableDefinedByMetavariableName = judgementPresent; ///
293
+ isMetavariableDefinedByMetavariableNode(metavariableNode) {
294
+ const judgementPresent = this.isJudgementPresentByMetavariableNode(metavariableNode),
295
+ metavariableDefined = judgementPresent; ///
321
296
 
322
- return metavariableDefinedByMetavariableName
297
+ return metavariableDefined
323
298
  }
324
299
 
325
300
  findMetaTypeByMetaTypeName(metaTypeName) { return this.context.findMetaTypeByMetaTypeName(metaTypeName); }
326
301
 
327
302
  findLabelByMetavariableNode(metavariableNode) { return this.context.findLabelByMetavariableNode(metavariableNode); }
328
303
 
329
- findVariableByVariableName(variableName) {
330
- const variables = this.getVariables(),
304
+ findMetavariableByMetavariableNode(metavariableNode, localContext) { return this.context.findMetavariableByMetavariableNode(metavariableNode, localContext); }
305
+
306
+ findVariableByVariableName(variableName, nested = true) {
307
+ const variables = this.getVariables(nested),
331
308
  variable = variables.find((variable) => {
332
309
  const nameMatches = variable.matchVariableName(variableName);
333
310
 
@@ -339,12 +316,12 @@ class LocalContext {
339
316
  return variable;
340
317
  }
341
318
 
342
- findJudgementByMetavariableName(metavariableName) {
319
+ findJudgementByMetavariableNode(metavariableNode) {
343
320
  const judgements = this.getJudgements(),
344
321
  judgement = judgements.find((judgement) => {
345
- const judgementMatchesMetavariableName = judgement.matchMetavariableName(metavariableName);
322
+ const judgementMatchesMetavariableNode = judgement.matchMetavariableNode(metavariableNode);
346
323
 
347
- if (judgementMatchesMetavariableName) {
324
+ if (judgementMatchesMetavariableNode) {
348
325
  return true;
349
326
  }
350
327
  }) || null;
@@ -352,19 +329,6 @@ class LocalContext {
352
329
  return judgement;
353
330
  }
354
331
 
355
- findMetavariableByMetavariableName(metavariableName) {
356
- const metavariables = this.getMetavariables(),
357
- metavariable = metavariables.find((metavariable) => {
358
- const nameMatches = metavariable.matchMetavariableName(metavariableName);
359
-
360
- if (nameMatches) {
361
- return true;
362
- }
363
- }) || null;
364
-
365
- return metavariable;
366
- }
367
-
368
332
  findTypeByTypeName(typeName) { return this.context.findTypeByTypeName(typeName); }
369
333
 
370
334
  findRuleByReference(reference) { return this.context.findRuleByReference(reference); }
@@ -440,8 +404,7 @@ class LocalContext {
440
404
  proofSteps = [],
441
405
  judgements = [],
442
406
  equivalences = [],
443
- metavariables = [],
444
- localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences, metavariables);
407
+ localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences);
445
408
 
446
409
  return localContext;
447
410
  }
@@ -452,10 +415,9 @@ class LocalContext {
452
415
  variables = [],
453
416
  proofSteps = [],
454
417
  judgements = [],
455
- equivalences = [],
456
- metavariables = [];
418
+ equivalences = [];
457
419
 
458
- localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences, metavariables); ///
420
+ localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences); ///
459
421
 
460
422
  return localContext;
461
423
  }
@@ -465,8 +427,7 @@ class LocalContext {
465
427
  proofSteps = [],
466
428
  judgements = [],
467
429
  equivalences = [],
468
- metavariables = [],
469
- localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences, metavariables); ///
430
+ localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences);
470
431
 
471
432
  return localContext;
472
433
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import Combinator from "../combinator";
3
+ import shim from "../shim";
4
4
 
5
5
  export default class CombinatorDeclaration {
6
6
  constructor(fileContext, combinator) {
@@ -25,9 +25,9 @@ export default class CombinatorDeclaration {
25
25
 
26
26
  this.fileContext.trace(`Verifying the '${combinatorDeclarationString}' combinator declaration...`);
27
27
 
28
- const combinatorVerifiedAtTopLevel = this.combinator.verifyAtTopLevel(this.fileContext);
28
+ const combinatorVerifiedWhenDeclared = this.combinator.verifyWhenDeclared(this.fileContext);
29
29
 
30
- if (combinatorVerifiedAtTopLevel) {
30
+ if (combinatorVerifiedWhenDeclared) {
31
31
  this.fileContext.addCombinator(this.combinator);
32
32
 
33
33
  verified = true;
@@ -41,7 +41,8 @@ export default class CombinatorDeclaration {
41
41
  }
42
42
 
43
43
  static fromCombinatorDeclarationNode(combinatorDeclarationNode, fileContext) {
44
- const combinator = Combinator.fromCombinatorDeclarationNode(combinatorDeclarationNode, fileContext),
44
+ const { Combinator } = shim,
45
+ combinator = Combinator.fromCombinatorDeclarationNode(combinatorDeclarationNode, fileContext),
45
46
  combinatorDeclaration = new CombinatorDeclaration(fileContext, combinator);
46
47
 
47
48
  return combinatorDeclaration;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import Constructor from "../constructor";
3
+ import shim from "../shim";
4
4
 
5
5
  export default class ConstructorDeclaration {
6
6
  constructor(fileContext, constructor) {
@@ -25,9 +25,9 @@ export default class ConstructorDeclaration {
25
25
 
26
26
  this.fileContext.trace(`Verifying the '${constructorDeclarationString}' constructor declaration...`);
27
27
 
28
- const constructorVerifiedAtTopLevel = this.constructor.verifyAtTopLevel(this.fileContext);
28
+ const constructorVerifiedWhenDeclared = this.constructor.verifyWhenDeclared(this.fileContext);
29
29
 
30
- if (constructorVerifiedAtTopLevel) {
30
+ if (constructorVerifiedWhenDeclared) {
31
31
  this.fileContext.addConstructor(this.constructor);
32
32
 
33
33
  verified = true;
@@ -41,7 +41,8 @@ export default class ConstructorDeclaration {
41
41
  }
42
42
 
43
43
  static fromConstructorDeclarationNode(constructorDeclarationNode, fileContext) {
44
- const constructor = Constructor.fromConstructorDeclarationNode(constructorDeclarationNode, fileContext),
44
+ const { Constructor } = shim,
45
+ constructor = Constructor.fromConstructorDeclarationNode(constructorDeclarationNode, fileContext),
45
46
  constructorDeclaration = new ConstructorDeclaration(fileContext, constructor);
46
47
 
47
48
  return constructorDeclaration;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  import shim from "../shim";
4
- import Metavariable from "../metavariable";
5
4
 
6
5
  import { nodeQuery } from "../utilities/query";
7
6
 
@@ -33,9 +32,9 @@ export default class MetavariableDeclaration {
33
32
 
34
33
  this.fileContext.trace(`Verifying the '${metavariableDeclarationString}' metavariable declaration...`);
35
34
 
36
- const metavariableVerifiedAtTopLevel = this.metavariable.verifyAtTopLevel(this.fileContext);
35
+ const metavariableVerifiedWhenDeclared = this.metavariable.verifyWhenDeclared(this.fileContext);
37
36
 
38
- if (metavariableVerifiedAtTopLevel) {
37
+ if (metavariableVerifiedWhenDeclared) {
39
38
  this.fileContext.addMetavariable(this.metavariable);
40
39
 
41
40
  verified = true;
@@ -49,7 +48,7 @@ export default class MetavariableDeclaration {
49
48
  }
50
49
 
51
50
  static fromMetavariableDeclarationNode(metavariableDeclarationNode, fileContext) {
52
- const { MetaType } = shim,
51
+ const { MetaType, Metavariable } = shim,
53
52
  metaTypeNode = metaTypeNodeQuery(metavariableDeclarationNode),
54
53
  metaType = MetaType.fromMetaTypeNode(metaTypeNode, fileContext),
55
54
  metavariable = Metavariable.fromMetavariableDeclarationNode(metavariableDeclarationNode, fileContext),
@@ -25,9 +25,9 @@ export default class TypeDeclaration {
25
25
 
26
26
  this.fileContext.trace(`Verifying the '${typeDeclarationString}' type declaration...`);
27
27
 
28
- const typeVerifiedAtTopLevel = this.type.verifyAtTopLevel(this.fileContext);
28
+ const typeVerifiedWhenDeclared = this.type.verifyWhenDeclared(this.fileContext);
29
29
 
30
- if (typeVerifiedAtTopLevel) {
30
+ if (typeVerifiedWhenDeclared) {
31
31
  this.fileContext.addType(this.type);
32
32
 
33
33
  verified = true;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import Variable from "../variable";
3
+ import shim from "../shim";
4
4
 
5
5
  import { nodeQuery } from "../utilities/query";
6
6
  import { typeNameFromTypeNode } from "../utilities/name";
@@ -33,9 +33,9 @@ export default class VariableDeclaration {
33
33
 
34
34
  this.fileContext.trace(`Verifying the '${variableDeclarationString}' variable declaration...`);
35
35
 
36
- const variableVerifiedAtTopLevel = this.variable.verifyAtTopLevel(this.fileContext);
36
+ const variableVerifiedWhenDeclared = this.variable.verifyWhenDeclared(this.fileContext);
37
37
 
38
- if (variableVerifiedAtTopLevel) {
38
+ if (variableVerifiedWhenDeclared) {
39
39
  this.fileContext.addVariable(this.variable);
40
40
 
41
41
  verified = true;
@@ -49,7 +49,8 @@ export default class VariableDeclaration {
49
49
  }
50
50
 
51
51
  static fromVariableDeclarationNode(variableDeclarationNode, fileContext) {
52
- const typeNode = typeNodeQuery(variableDeclarationNode),
52
+ const { Variable } = shim,
53
+ typeNode = typeNodeQuery(variableDeclarationNode),
53
54
  variable = Variable.fromVariableDeclarationNode(variableDeclarationNode, fileContext),
54
55
  string = stringFromVariableAndTypeNode(variable, typeNode),
55
56
  variableDeclaration = new VariableDeclaration(fileContext, string, variable);
@@ -9,7 +9,7 @@ import { stripBracketsFromStatementNode } from "./utilities/brackets";
9
9
  const referenceNodeQuery = nodeQuery("/declaration/reference"),
10
10
  statementNodeQuery = nodeQuery("/declaration/statement");
11
11
 
12
- export default class Declaration {
12
+ class Declaration {
13
13
  constructor(string, reference, statement) {
14
14
  this.string = string;
15
15
  this.reference = reference;
@@ -141,3 +141,9 @@ export default class Declaration {
141
141
  return declaration;
142
142
  }
143
143
  }
144
+
145
+ Object.assign(shim, {
146
+ Declaration
147
+ });
148
+
149
+ export default Declaration;
package/src/derivation.js CHANGED
@@ -10,7 +10,7 @@ const { last } = arrayUtilities;
10
10
 
11
11
  const proofStepNodesQuery = nodesQuery("/derivation/proofStep|lastProofStep");
12
12
 
13
- export default class Derivation {
13
+ class Derivation {
14
14
  constructor(proofSteps) {
15
15
  this.proofSteps = proofSteps;
16
16
  }
@@ -52,3 +52,9 @@ export default class Derivation {
52
52
  return derivation;
53
53
  }
54
54
  }
55
+
56
+ Object.assign(shim, {
57
+ Derivation
58
+ });
59
+
60
+ export default Derivation;
package/src/equality.js CHANGED
@@ -3,13 +3,15 @@
3
3
  import shim from "./shim";
4
4
  import equalityUnifier from "./unifier/equality";
5
5
  import EqualityAssignment from "./assignment/equality";
6
+ import VariableAssignment from "./assignment/variable";
6
7
 
7
8
  import { nodeQuery } from "./utilities/query";
8
9
 
9
- const leftTermNodeQuery = nodeQuery("/equality/term[0]"),
10
+ const variableNodeQuery = nodeQuery("/term/variable!"),
11
+ leftTermNodeQuery = nodeQuery("/equality/term[0]"),
10
12
  rightTermNodeQuery = nodeQuery("/equality/term[1]");
11
13
 
12
- export default class Equality {
14
+ class Equality {
13
15
  constructor(string,leftTerm, rightTerm) {
14
16
  this.string = string;
15
17
  this.leftTerm = leftTerm;
@@ -28,6 +30,25 @@ export default class Equality {
28
30
  return this.rightTerm;
29
31
  }
30
32
 
33
+ getType() {
34
+ let type;
35
+
36
+ const leftTermType = this.leftTerm.getType(),
37
+ rightTermType = this.rightTerm.getType(),
38
+ leftTermTypeEqualToOrSubTypeOfRightTermType = leftTermType.isEqualToOrSubTypeOf(rightTermType),
39
+ rightTermTypeEqualToOrSubTypeOfLeftTermType = rightTermType.isEqualToOrSubTypeOf(leftTermType);
40
+
41
+ if (leftTermTypeEqualToOrSubTypeOfRightTermType) {
42
+ type = leftTermType; ///
43
+ }
44
+
45
+ if (rightTermTypeEqualToOrSubTypeOfLeftTermType) {
46
+ type = rightTermType; ///
47
+ }
48
+
49
+ return type;
50
+ }
51
+
31
52
  isReflexive() {
32
53
  const leftTermMatchesRightTerm = this.leftTerm.match(this.rightTerm),
33
54
  reflexive = leftTermMatchesRightTerm; ///
@@ -51,25 +72,57 @@ export default class Equality {
51
72
 
52
73
  localContext.trace(`Verifying the '${equalityString}' equality...`);
53
74
 
54
- let verifiedWhenStated = false,
55
- verifiedWhenDerived = false;
56
-
57
- if (stated) {
58
- verifiedWhenStated = this.verifyWhenStated(localContext);
59
- } else {
60
- verifiedWhenDerived = this.verifyWhenDerived(localContext);
61
- }
75
+ const termsVerified = this.verifyTerms(localContext);
62
76
 
63
- if (verifiedWhenStated || verifiedWhenDerived) {
64
- if (assignments !== null) {
65
- const equality = this, //
66
- equalityAssignment = EqualityAssignment.fromEquality(equality),
67
- assignment = equalityAssignment; ///
77
+ if (termsVerified) {
78
+ let verifiedWhenStated = false,
79
+ verifiedWhenDerived = false;
68
80
 
69
- assignments.push(assignment);
81
+ if (stated) {
82
+ verifiedWhenStated = this.verifyWhenStated(localContext);
83
+ } else {
84
+ verifiedWhenDerived = this.verifyWhenDerived(localContext);
70
85
  }
71
86
 
72
- verified = true;
87
+ if (verifiedWhenStated || verifiedWhenDerived) {
88
+ if (assignments !== null) {
89
+ const { Variable } = shim,
90
+ type = this.getType(),
91
+ leftTermNode = this.leftTerm.getNode(),
92
+ rightTermNode = this.rightTerm.getNode(),
93
+ leftVariableNode = variableNodeQuery(leftTermNode),
94
+ rightVariableNode = variableNodeQuery(rightTermNode),
95
+ leftVariable = Variable.fromVariableNodeAndType(leftVariableNode, type, localContext),
96
+ rightVariable = Variable.fromVariableNodeAndType(rightVariableNode, type, localContext);
97
+
98
+ let assignment;
99
+
100
+ if (leftVariable !== null) {
101
+ const leftVariableAssignment = VariableAssignment.fromVariable(leftVariable);
102
+
103
+ assignment = leftVariableAssignment; ///
104
+
105
+ assignments.push(assignment);
106
+ }
107
+
108
+ if (rightVariable !== null) {
109
+ const rightVariableAssignment = VariableAssignment.fromVariable(rightVariable);
110
+
111
+ assignment = rightVariableAssignment; ///
112
+
113
+ assignments.push(assignment);
114
+ }
115
+
116
+ const equality = this, //
117
+ equalityAssignment = EqualityAssignment.fromEquality(equality);
118
+
119
+ assignment = equalityAssignment; ///
120
+
121
+ assignments.push(assignment);
122
+ }
123
+
124
+ verified = true;
125
+ }
73
126
  }
74
127
 
75
128
  if (verified) {
@@ -122,9 +175,7 @@ export default class Equality {
122
175
 
123
176
  localContext.trace(`Verifying the '${equalityString}' stated equality...`);
124
177
 
125
- const termsVerified = this.verifyTerms(localContext);
126
-
127
- verifiedWhenStated = termsVerified; ///
178
+ verifiedWhenStated = true;
128
179
 
129
180
  if (verifiedWhenStated) {
130
181
  localContext.debug(`...verified the '${equalityString}' stated equality.`);
@@ -134,19 +185,15 @@ export default class Equality {
134
185
  }
135
186
 
136
187
  verifyWhenDerived(localContext) {
137
- let verifiedWhenDerived = false;
188
+ let verifiedWhenDerived;
138
189
 
139
190
  const equalityString = this.string; ///
140
191
 
141
192
  localContext.trace(`Verifying the '${equalityString}' derived equality...`);
142
193
 
143
- const termsVerified = this.verifyTerms(localContext);
144
-
145
- if (termsVerified) {
146
- const equal = this.isEqual(localContext);
194
+ const equal = this.isEqual(localContext);
147
195
 
148
- verifiedWhenDerived = equal; ///
149
- }
196
+ verifiedWhenDerived = equal; ///
150
197
 
151
198
  if (verifiedWhenDerived) {
152
199
  localContext.debug(`...verified the '${equalityString}' derived equality.`);
@@ -173,3 +220,9 @@ export default class Equality {
173
220
  return equality;
174
221
  }
175
222
  }
223
+
224
+ Object.assign(shim, {
225
+ Equality
226
+ });
227
+
228
+ export default Equality;