occam-verify-cli 0.0.1067 → 0.0.1069

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 (137) hide show
  1. package/bin/action/verify.js +3 -2
  2. package/lib/assertion/contained.js +2 -2
  3. package/lib/assertion/defined.js +2 -2
  4. package/lib/assertion/subproof.js +3 -3
  5. package/lib/assignment/judgement.js +3 -3
  6. package/lib/axiom.js +11 -6
  7. package/lib/combinator.js +9 -9
  8. package/lib/conclusion.js +13 -10
  9. package/lib/conjecture.js +11 -6
  10. package/lib/consequent.js +13 -10
  11. package/lib/constructor.js +9 -9
  12. package/lib/context/file.js +34 -126
  13. package/lib/context/local.js +16 -5
  14. package/lib/context/release.js +2 -3
  15. package/lib/declaration.js +96 -2
  16. package/lib/equivalence.js +2 -2
  17. package/lib/frame.js +179 -98
  18. package/lib/index.js +22 -6
  19. package/lib/judgement.js +84 -5
  20. package/lib/label.js +12 -8
  21. package/lib/lemma.js +12 -12
  22. package/lib/metaLemma.js +120 -8
  23. package/lib/metaType.js +24 -3
  24. package/lib/metatheorem.js +145 -9
  25. package/lib/metavariable.js +128 -43
  26. package/lib/mixins/statement/qualified/unify.js +6 -10
  27. package/lib/mixins/statement/unify.js +4 -19
  28. package/lib/mixins/statement/verify.js +13 -13
  29. package/lib/mixins/term/unify.js +2 -2
  30. package/lib/premise.js +21 -13
  31. package/lib/reference.js +17 -17
  32. package/lib/rule.js +28 -40
  33. package/lib/statement/unqualified.js +34 -9
  34. package/lib/statement.js +7 -5
  35. package/lib/substitution/frameForMetavariable.js +75 -70
  36. package/lib/substitution/statementForMetavariable.js +83 -42
  37. package/lib/substitution/termForVariable.js +65 -68
  38. package/lib/substitution.js +46 -43
  39. package/lib/substitutions.js +52 -40
  40. package/lib/supposition.js +15 -11
  41. package/lib/term.js +6 -11
  42. package/lib/theorem.js +11 -6
  43. package/lib/topLevelAssertion.js +24 -42
  44. package/lib/type.js +5 -12
  45. package/lib/unifier/intrinsicLevel.js +4 -4
  46. package/lib/unifier/metaLevel.js +11 -7
  47. package/lib/unifier/metavariable.js +6 -6
  48. package/lib/unifier/statementWithCombinator.js +16 -16
  49. package/lib/unifier/termWithConstructor.js +7 -7
  50. package/lib/utilities/brackets.js +10 -10
  51. package/lib/utilities/json.js +493 -0
  52. package/lib/utilities/node.js +26 -19
  53. package/lib/utilities/release.js +53 -0
  54. package/lib/utilities/releaseContext.js +4 -15
  55. package/lib/utilities/tokens.js +8 -1
  56. package/lib/variable.js +14 -15
  57. package/lib/verifier/topLevel.js +5 -5
  58. package/package.json +1 -1
  59. package/src/assertion/contained.js +1 -1
  60. package/src/assertion/defined.js +1 -1
  61. package/src/assertion/subproof.js +2 -3
  62. package/src/assignment/judgement.js +3 -4
  63. package/src/axiom.js +14 -6
  64. package/src/combinator.js +12 -13
  65. package/src/conclusion.js +16 -13
  66. package/src/conjecture.js +14 -6
  67. package/src/consequent.js +16 -13
  68. package/src/constructor.js +11 -13
  69. package/src/context/file.js +94 -202
  70. package/src/context/local.js +8 -6
  71. package/src/context/release.js +2 -3
  72. package/src/declaration.js +126 -45
  73. package/src/equivalence.js +2 -2
  74. package/src/frame.js +225 -141
  75. package/src/index.js +17 -1
  76. package/src/judgement.js +109 -3
  77. package/src/label.js +15 -10
  78. package/src/lemma.js +17 -10
  79. package/src/metaLemma.js +102 -1
  80. package/src/metaType.js +29 -3
  81. package/src/metatheorem.js +143 -2
  82. package/src/metavariable.js +189 -66
  83. package/src/mixins/statement/qualified/unify.js +7 -19
  84. package/src/mixins/statement/unify.js +3 -25
  85. package/src/mixins/statement/verify.js +15 -13
  86. package/src/mixins/term/unify.js +1 -1
  87. package/src/premise.js +31 -16
  88. package/src/reference.js +18 -18
  89. package/src/rule.js +40 -58
  90. package/src/statement/unqualified.js +41 -11
  91. package/src/statement.js +6 -3
  92. package/src/substitution/frameForMetavariable.js +85 -98
  93. package/src/substitution/statementForMetavariable.js +109 -45
  94. package/src/substitution/termForVariable.js +83 -94
  95. package/src/substitution.js +36 -34
  96. package/src/substitutions.js +53 -46
  97. package/src/supposition.js +22 -14
  98. package/src/term.js +5 -15
  99. package/src/theorem.js +14 -6
  100. package/src/topLevelAssertion.js +38 -64
  101. package/src/type.js +5 -20
  102. package/src/unifier/intrinsicLevel.js +4 -3
  103. package/src/unifier/metaLevel.js +19 -7
  104. package/src/unifier/metavariable.js +5 -5
  105. package/src/unifier/statementWithCombinator.js +19 -19
  106. package/src/unifier/termWithConstructor.js +7 -7
  107. package/src/utilities/brackets.js +5 -5
  108. package/src/utilities/json.js +551 -0
  109. package/src/utilities/node.js +28 -23
  110. package/src/{verify → utilities}/release.js +5 -1
  111. package/src/utilities/releaseContext.js +2 -2
  112. package/src/utilities/tokens.js +10 -0
  113. package/src/variable.js +18 -19
  114. package/src/verifier/topLevel.js +6 -4
  115. package/lib/argument.js +0 -106
  116. package/lib/metaTypes.js +0 -19
  117. package/lib/unify/metavariableWithFrame.js +0 -40
  118. package/lib/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +0 -31
  119. package/lib/unify/statementWithSttaemetnGivenEquivalences.js +0 -45
  120. package/lib/verify/declaration.js +0 -83
  121. package/lib/verify/frame.js +0 -120
  122. package/lib/verify/judgement.js +0 -88
  123. package/lib/verify/metaLemma.js +0 -49
  124. package/lib/verify/metatheorem.js +0 -48
  125. package/lib/verify/metavariableGivenMetaType.js +0 -44
  126. package/lib/verify/release.js +0 -50
  127. package/src/argument.js +0 -79
  128. package/src/metaTypes.js +0 -11
  129. package/src/unify/metavariableWithFrame.js +0 -40
  130. package/src/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +0 -27
  131. package/src/unify/statementWithSttaemetnGivenEquivalences.js +0 -51
  132. package/src/verify/declaration.js +0 -113
  133. package/src/verify/frame.js +0 -157
  134. package/src/verify/judgement.js +0 -127
  135. package/src/verify/metaLemma.js +0 -72
  136. package/src/verify/metatheorem.js +0 -67
  137. package/src/verify/metavariableGivenMetaType.js +0 -45
@@ -34,28 +34,28 @@ export default class Substitutions {
34
34
  return firstSubstitution;
35
35
  }
36
36
 
37
- getMetavariableNodes() {
38
- const metavariableNodes = [];
37
+ getMetavariableNames() {
38
+ const metavariableNames = [];
39
39
 
40
40
  this.forEachSubstitution((substitution) => {
41
- const metavariableNode = substitution.getMetavariableNode();
41
+ const metavariableName = substitution.getMetavariableName();
42
42
 
43
- if (metavariableNode !== null) {
44
- metavariableNodes.push(metavariableNode);
43
+ if (metavariableName !== null) {
44
+ metavariableNames.push(metavariableName);
45
45
  }
46
46
  });
47
47
 
48
- compress(metavariableNodes, (metavariableNodeA, metavariableNodeB) => {
49
- const metavariableNodeAMatchesMetavariableNodeB = metavariableNodeA.match(metavariableNodeB);
50
-
51
- if (metavariableNodeAMatchesMetavariableNodeB) {
48
+ compress(metavariableNames, (metavariableNameA, metavariableNameB) => {
49
+ if (metavariableNameA === metavariableNameB) {
52
50
  return true;
53
51
  }
54
52
  });
55
53
 
56
- return metavariableNodes;
54
+ return metavariableNames;
57
55
  }
58
56
 
57
+ mapSubstitution(callback) { return this.array.map(callback); }
58
+
59
59
  findSubstitution(callback) { return this.array.find(callback) || null; } ///
60
60
 
61
61
  someSubstitution(callback) { return this.array.some(callback); }
@@ -90,11 +90,11 @@ export default class Substitutions {
90
90
  return simpleSubstitution;
91
91
  }
92
92
 
93
- findSubstitutionByVariableNode(variableNode) {
93
+ findSubstitutionByVariableName(variableName) {
94
94
  const substitution = this.findSubstitution((substitution) => {
95
- const variableNodeMatches = substitution.matchVariableNode(variableNode);
95
+ const variableNameMatches = substitution.matchVariableName(variableName);
96
96
 
97
- if (variableNodeMatches) {
97
+ if (variableNameMatches) {
98
98
  return true;
99
99
  }
100
100
  });
@@ -102,11 +102,11 @@ export default class Substitutions {
102
102
  return substitution;
103
103
  }
104
104
 
105
- findSubstitutionByMetavariableNode(metavariableNode) {
105
+ findSubstitutionByMetavariableName(metavariableName) {
106
106
  const substitution = this.findSubstitution((substitution) => {
107
- const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
107
+ const metavariableNameMatches = substitution.matchMetavariableName(metavariableName);
108
108
 
109
- if (metavariableNodeMatches) {
109
+ if (metavariableNameMatches) {
110
110
  return true;
111
111
  }
112
112
  });
@@ -114,11 +114,11 @@ export default class Substitutions {
114
114
  return substitution;
115
115
  }
116
116
 
117
- findSubstitutionsByMetavariableNode(metavariableNode) {
117
+ findSubstitutionsByMetavariableName(metavariableName) {
118
118
  const substitutions = this.findSubstitutions((substitution) => {
119
- const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
119
+ const metavariableNameMatches = substitution.matchMetavariableName(metavariableName);
120
120
 
121
- if (metavariableNodeMatches) {
121
+ if (metavariableNameMatches) {
122
122
  return true;
123
123
  }
124
124
  });
@@ -126,8 +126,8 @@ export default class Substitutions {
126
126
  return substitutions;
127
127
  }
128
128
 
129
- findSimpleSubstitutionByMetavariableNode(metavariableNode) {
130
- const substitutions = this.findSubstitutionsByMetavariableNode(metavariableNode),
129
+ findSimpleSubstitutionByMetavariableName(metavariableName) {
130
+ const substitutions = this.findSubstitutionsByMetavariableName(metavariableName),
131
131
  simpleSubstitutions = substitutions.filterSubstitution((substitution) => {
132
132
  const substitutionSimple = substitution.isSimple();
133
133
 
@@ -141,8 +141,8 @@ export default class Substitutions {
141
141
  return simpleSubstitution;
142
142
  }
143
143
 
144
- findComplexSubstitutionsByMetavariableNode(metavariableNode) {
145
- const substitutions = this.findSubstitutionsByMetavariableNode(metavariableNode),
144
+ findComplexSubstitutionsByMetavariableName(metavariableName) {
145
+ const substitutions = this.findSubstitutionsByMetavariableName(metavariableName),
146
146
  complexSubstitutions = substitutions.filterSubstitution((substitution) => {
147
147
  const substitutionComplex = substitution.isComplex();
148
148
 
@@ -154,11 +154,11 @@ export default class Substitutions {
154
154
  return complexSubstitutions;
155
155
  }
156
156
 
157
- findSubstitutionByMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode) {
157
+ findSubstitutionByMetavariableNameAndSubstitutionNode(metavariableName, substitutionNode) {
158
158
  const substitutions = this.findSubstitutions((substitution) => {
159
- const metavariableNodeAndSubstitutionNodeMatch = substitution.matchMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode);
159
+ const metavariableNameAndSubstitutionNodeMatch = substitution.matchMetavariableNameAndSubstitutionNode(metavariableName, substitutionNode);
160
160
 
161
- if (metavariableNodeAndSubstitutionNodeMatch) {
161
+ if (metavariableNameAndSubstitutionNodeMatch) {
162
162
  return true;
163
163
  }
164
164
  }),
@@ -168,8 +168,15 @@ export default class Substitutions {
168
168
  return substitution;
169
169
  }
170
170
 
171
- isSubstitutionPresentByMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode) {
172
- const substitution = this.findSubstitutionByMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode),
171
+ isSimpleSubstitutionPresentByMetavariableName(metavariableName) {
172
+ const simpleSubstitution = this.findSimpleSubstitutionByMetavariableName(metavariableName),
173
+ simpleSubstitutionPresent = (simpleSubstitution !== null);
174
+
175
+ return simpleSubstitutionPresent;
176
+ }
177
+
178
+ isSubstitutionPresentByMetavariableNameAndSubstitutionNode(metavariableName, substitutionNode) {
179
+ const substitution = this.findSubstitutionByMetavariableNameAndSubstitutionNode(metavariableName, substitutionNode),
173
180
  substitutionPresent = (substitution !== null);
174
181
 
175
182
  return substitutionPresent;
@@ -213,24 +220,24 @@ export default class Substitutions {
213
220
  return unifiedWithEquivalences;
214
221
  }
215
222
 
216
- resolve(localContext) {
217
- const metavariableNodes = this.getMetavariableNodes(),
218
- resolved = metavariableNodes.every((metavariableNode) => {
219
- const complexSubstitutions = this.findComplexSubstitutionsByMetavariableNode(metavariableNode),
220
- complexSubstitutionsResolved = complexSubstitutions.everySubstitution((complexSubstitution) => {
221
- const substitution = complexSubstitution, ///
222
- substitutions = this, ///
223
- substitutionResolved = substitution.resolve(substitutions, localContext);
224
-
225
- if (substitutionResolved) {
226
- return true;
227
- }
228
- });
229
-
230
- if (complexSubstitutionsResolved) {
231
- return true;
232
- }
233
- });
223
+ resolve(localContextA, localContextB) {
224
+ const metavariableNames = this.getMetavariableNames(),
225
+ resolved = metavariableNames.every((metavariableName) => {
226
+ const complexSubstitutions = this.findComplexSubstitutionsByMetavariableName(metavariableName),
227
+ complexSubstitutionsResolved = complexSubstitutions.everySubstitution((complexSubstitution) => {
228
+ const substitution = complexSubstitution, ///
229
+ substitutions = this, ///
230
+ substitutionResolved = substitution.resolve(substitutions, localContextA, localContextB);
231
+
232
+ if (substitutionResolved) {
233
+ return true;
234
+ }
235
+ });
236
+
237
+ if (complexSubstitutionsResolved) {
238
+ return true;
239
+ }
240
+ });
234
241
 
235
242
  return resolved;
236
243
  }
@@ -7,10 +7,11 @@ import UnqualifiedStatement from "./statement/unqualified";
7
7
 
8
8
  import { nodeQuery } from "./utilities/query";
9
9
  import { assignAssignments } from "./utilities/assignments";
10
+ import { unqualifiedStatementFromJSON, unqualifiedStatementToUnqualifiedStatementJSON } from "./utilities/json";
10
11
 
11
12
  const unqualifiedStatementNodeQuery = nodeQuery("/supposition/unqualifiedStatement");
12
13
 
13
- export default class Supposition {
14
+ class Supposition {
14
15
  constructor(fileContext, unqualifiedStatement) {
15
16
  this.fileContext = fileContext;
16
17
  this.unqualifiedStatement = unqualifiedStatement;
@@ -71,7 +72,13 @@ export default class Supposition {
71
72
 
72
73
  const statement = this.unqualifiedStatement.getStatement(),
73
74
  statementNode = statement.getNode(),
74
- subproofAssertion = SubproofAssertion.fromStatementNode(statementNode, this.fileContext);
75
+ statementTokens = statement.getTokens(),
76
+ context = this.fileContext, ///
77
+ tokens = statementTokens; ///
78
+
79
+ localContext = LocalContext.fromContextAndTokens(context, tokens); ///
80
+
81
+ const subproofAssertion = SubproofAssertion.fromStatementNode(statementNode, localContext);
75
82
 
76
83
  if (subproofAssertion !== null) {
77
84
  subproofUnified = subproofAssertion.unifySubproof(subproof, substitutions, this.fileContext, localContext);
@@ -113,25 +120,25 @@ export default class Supposition {
113
120
  const statementString = statement.getString(),
114
121
  suppositionString = this.getString();
115
122
 
116
- localContext.trace(`Unifying the '${statementString}' statement with the '${suppositionString}' supposition...`);
117
-
118
- const localContextB = localContext;
123
+ const localContextB = localContext; ///
119
124
 
120
125
  localContext = LocalContext.fromFileContext(this.fileContext);
121
126
 
122
127
  const localContextA = localContext; ///
123
128
 
129
+ localContextB.trace(`Unifying the '${statementString}' statement with the '${suppositionString}' supposition...`);
130
+
124
131
  statementUnified = this.unqualifiedStatement.unifyStatement(statement, substitutions, localContextA, localContextB);
125
132
 
126
133
  if (statementUnified) {
127
- localContext.debug(`...unified the '${statementString}' statement with the '${suppositionString}' supposition.`);
134
+ localContextB.debug(`...unified the '${statementString}' statement with the '${suppositionString}' supposition.`);
128
135
  }
129
136
 
130
137
  return statementUnified;
131
138
  }
132
139
 
133
140
  toJSON() {
134
- const unqualifiedStatementJSON = this.unqualifiedStatement.toJSON(),
141
+ const unqualifiedStatementJSON = unqualifiedStatementToUnqualifiedStatementJSON(this.unqualifiedStatement),
135
142
  unqualifiedStatement = unqualifiedStatementJSON, ///
136
143
  json = {
137
144
  unqualifiedStatement
@@ -141,13 +148,8 @@ export default class Supposition {
141
148
  }
142
149
 
143
150
  static fromJSON(json, fileContext) {
144
- let { unqualifiedStatement } = json;
145
-
146
- json = unqualifiedStatement; ///
147
-
148
- unqualifiedStatement = UnqualifiedStatement.fromJSON(json, fileContext);
149
-
150
- const supposition = new Supposition(fileContext, unqualifiedStatement);
151
+ const unqualifiedStatement = unqualifiedStatementFromJSON(json, fileContext),
152
+ supposition = new Supposition(fileContext, unqualifiedStatement);
151
153
 
152
154
  return supposition;
153
155
  }
@@ -160,3 +162,9 @@ export default class Supposition {
160
162
  return supposition
161
163
  }
162
164
  }
165
+
166
+ Object.assign(shim, {
167
+ Supposition
168
+ });
169
+
170
+ export default Supposition;
package/src/term.js CHANGED
@@ -11,6 +11,7 @@ import { objectType } from "./type";
11
11
  import { nodeQuery, nodesQuery } from "./utilities/query"
12
12
  import { termNodeFromTermString } from "./utilities/node";
13
13
  import { variableNameFromVariableNode } from "./utilities/name";
14
+ import { typeFromJSON, typeToTypeJSON } from "./utilities/json";
14
15
 
15
16
  const { filter } = arrayUtilities;
16
17
 
@@ -236,12 +237,12 @@ class Term {
236
237
  }
237
238
 
238
239
  toJSON() {
239
- const typeJSON = this.type.toJSON(),
240
+ const typeJSON = typeToTypeJSON(this.type),
240
241
  string = this.string,
241
242
  type = typeJSON, ///
242
243
  json = {
243
- string,
244
- type
244
+ type,
245
+ string
245
246
  };
246
247
 
247
248
  return json;
@@ -249,9 +250,9 @@ class Term {
249
250
 
250
251
  static fromJSON(json, fileContext) {
251
252
  const { string } = json,
252
- termString = string, ///
253
253
  lexer = fileContext.getLexer(),
254
254
  parser = fileContext.getParser(),
255
+ termString = string, ///
255
256
  termNode = termNodeFromTermString(termString, lexer, parser),
256
257
  node = termNode, ///
257
258
  type = typeFromJSON(json, fileContext),
@@ -328,14 +329,3 @@ Object.assign(shim, {
328
329
  });
329
330
 
330
331
  export default Term;
331
-
332
- function typeFromJSON(json, fileContext) {
333
- let { type } = json;
334
-
335
- const { name } = type,
336
- typeName = name; ///
337
-
338
- type = fileContext.findTypeByTypeName(typeName);
339
-
340
- return type;
341
- }
package/src/theorem.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import shim from "./shim";
3
4
  import Label from "./label";
4
5
  import Proof from "./proof";
5
6
  import Consequent from "./consequent";
@@ -8,21 +9,21 @@ import LocalContext from "./context/local";
8
9
  import Substitutions from "./substitutions";
9
10
  import TopLevelAssertion from "./topLevelAssertion";
10
11
 
12
+ import { stringFromLabels } from "./topLevelAssertion";
11
13
  import { nodeQuery, nodesQuery } from "./utilities/query";
12
- import { labelsStringFromLabels } from "./topLevelAssertion";
13
14
 
14
15
  const proofNodeQuery = nodeQuery("/theorem/proof"),
15
16
  labelNodesQuery = nodesQuery("/theorem/label"),
16
17
  consequentNodeQuery = nodeQuery("/theorem/consequent"),
17
18
  suppositionNodesQuery = nodesQuery("/theorem/supposition");
18
19
 
19
- export default class Theorem extends TopLevelAssertion {
20
+ class Theorem extends TopLevelAssertion {
20
21
  verify() {
21
22
  let verified = false;
22
23
 
23
- const labelsString = labelsStringFromLabels(this.labels);
24
+ const theoremString = this.string; ///
24
25
 
25
- this.fileContext.trace(`Verifying the '${labelsString}' theorem...`);
26
+ this.fileContext.trace(`Verifying the '${theoremString}' theorem...`);
26
27
 
27
28
  const labelsVerifiedAtTopLevel = this.labels.every((label) => {
28
29
  const labelVVerifiedAtTopLevel = label.verifyAtTopLevel(this.fileContext);
@@ -61,7 +62,7 @@ export default class Theorem extends TopLevelAssertion {
61
62
  }
62
63
 
63
64
  if (verified) {
64
- this.fileContext.debug(`...verified the '${labelsString}' theorem.`);
65
+ this.fileContext.debug(`...verified the '${theoremString}' theorem.`);
65
66
  }
66
67
 
67
68
  return verified;
@@ -85,9 +86,16 @@ export default class Theorem extends TopLevelAssertion {
85
86
  return supposition;
86
87
  }),
87
88
  consequent = Consequent.fromConsequentNode(consequentNode, fileContext),
89
+ string = stringFromLabels(labels),
88
90
  proof = Proof.fromProofNode(proofNode, fileContext),
89
- theorem = new Theorem(fileContext, labels, suppositions, consequent, proof);
91
+ theorem = new Theorem(fileContext, string, labels, suppositions, consequent, proof);
90
92
 
91
93
  return theorem;
92
94
  }
93
95
  }
96
+
97
+ Object.assign(shim, {
98
+ Theorem
99
+ });
100
+
101
+ export default Theorem;
@@ -2,16 +2,22 @@
2
2
 
3
3
  import { arrayUtilities } from "necessary";
4
4
 
5
- import Label from "./label";
6
- import Consequent from "./consequent";
7
- import Supposition from "./supposition";
8
5
  import Substitutions from "./substitutions";
9
6
 
7
+ import { EMPTY_STRING } from "./constants";
8
+ import { labelsFromJSON,
9
+ labelsToLabelsJSON,
10
+ consequentFromJSON,
11
+ suppositionsFromJSON,
12
+ consequentToConsequentJSON,
13
+ suppositionsToSuppositionsJSON } from "./utilities/json";
14
+
10
15
  const { reverse, correlate } = arrayUtilities;
11
16
 
12
17
  export default class TopLevelAssertion {
13
- constructor(fileContext, labels, suppositions, consequent, proof) {
18
+ constructor(fileContext, string, labels, suppositions, consequent, proof) {
14
19
  this.fileContext = fileContext;
20
+ this.string = string;
15
21
  this.labels = labels;
16
22
  this.suppositions = suppositions;
17
23
  this.consequent = consequent;
@@ -22,6 +28,10 @@ export default class TopLevelAssertion {
22
28
  return this.fileContext;
23
29
  }
24
30
 
31
+ getString() {
32
+ return this.string;
33
+ }
34
+
25
35
  getLabels() {
26
36
  return this.labels;
27
37
  }
@@ -85,80 +95,44 @@ export default class TopLevelAssertion {
85
95
  }
86
96
 
87
97
  toJSON() {
88
- const labelsJSON = this.labels.map((label) => {
89
- const labelJSON = label.toJSON();
90
-
91
- return labelJSON;
92
- }),
93
- suppositionsJSON = this.suppositions.map((supposition) => {
94
- const suppositionJSON = supposition.toJSON();
95
-
96
- return suppositionJSON;
97
- }),
98
- consequentJSON = this.consequent.toJSON(),
98
+ const labelsJSON = labelsToLabelsJSON(this.labels),
99
+ consequentJSON = consequentToConsequentJSON(this.consequent),
100
+ suppositionsJSON = suppositionsToSuppositionsJSON(this.suppositions),
99
101
  labels = labelsJSON, ///
100
- suppositions = suppositionsJSON, ///
101
102
  consequent = consequentJSON, ///
103
+ suppositions = suppositionsJSON, ///
102
104
  json = {
103
105
  labels,
104
- suppositions,
105
- consequent
106
+ consequent,
107
+ suppositions
106
108
  };
107
109
 
108
110
  return json;
109
111
  }
110
112
 
111
113
  static fromJSON(Class, json, fileContext) {
112
- let rule;
113
-
114
- let { labels } = json;
115
-
116
- const labelsJSON = labels; ///
117
-
118
- labels = labelsJSON.map((labelJSON) => {
119
- const json = labelJSON, ///
120
- label = Label.fromJSON(json, fileContext);
121
-
122
- return label;
123
- });
124
-
125
- let { suppositions } = json;
126
-
127
- const suppositionsJSON = suppositions; ///
128
-
129
- suppositions = suppositionsJSON.map((suppositionJSON) => {
130
- const json = suppositionJSON, ///
131
- supposition = Supposition.fromJSON(json, fileContext);
132
-
133
- return supposition;
134
- });
135
-
136
- let { consequent } = json;
137
-
138
- const consequentJSON = consequent; ///
139
-
140
- json = consequentJSON; ///
141
-
142
- consequent = Consequent.fromJSON(json, fileContext);
143
-
144
- const proof = null;
145
-
146
- rule = new Class(fileContext, labels, suppositions, consequent, proof);
147
-
148
- return rule;
114
+ const labels = labelsFromJSON(json, fileContext),
115
+ consequent = consequentFromJSON(json, fileContext),
116
+ suppositions = suppositionsFromJSON(json, fileContext),
117
+ string = stringFromLabels(labels),
118
+ proof = null,
119
+ topLevelAssertion = new Class(fileContext, string, labels, suppositions, consequent, proof);
120
+
121
+ return topLevelAssertion;
149
122
  }
150
123
  }
151
124
 
152
- export function labelsStringFromLabels(labels) {
153
- const labelsString = labels.reduce((labelsString, label) => {
125
+ export function stringFromLabels(labels) {
126
+ const string = labels.reduce((string, label) => {
154
127
  const labelString = label.getString();
155
128
 
156
- labelsString = (labelsString === null) ?
157
- labelString: ///
158
- `${labelString}, ${labelString}`;
129
+ string = (string === EMPTY_STRING) ?
130
+ labelString: ///
131
+ `${labelString}, ${labelString}`;
132
+
133
+ return string;
134
+ }, EMPTY_STRING);
159
135
 
160
- return labelsString;
161
- }, null);
136
+ return string;
137
+ }
162
138
 
163
- return labelsString;
164
- }
package/src/type.js CHANGED
@@ -5,6 +5,7 @@ import shim from "./shim";
5
5
  import { nodeQuery } from "./utilities/query";
6
6
  import { OBJECT_TYPE_NAME } from "./typeNames";
7
7
  import { typeNameFromTypeNode } from "./utilities/name";
8
+ import { superTypeFromJSON, superTypeToSuperTypeJSON } from "./utilities/json";
8
9
 
9
10
  const typeNodeQuery = nodeQuery("/typeDeclaration/type[0]"),
10
11
  superTypeNodeQuery = nodeQuery("/typeDeclaration/type[1]");
@@ -155,9 +156,9 @@ class Type {
155
156
  }
156
157
 
157
158
  toJSON() {
158
- const superTypeJSON = this.superType.toJSON(),
159
- name = this.name,
159
+ const superTypeJSON = superTypeToSuperTypeJSON(this.superType),
160
160
  superType = superTypeJSON, ///
161
+ name = this.name,
161
162
  json = {
162
163
  name,
163
164
  superType
@@ -229,8 +230,8 @@ export default Type;
229
230
 
230
231
  class ObjectType extends Type {
231
232
  toJSON() {
232
- const name = this.name,
233
- superType = null,
233
+ const superType = null,
234
+ name = this.name,
234
235
  json = {
235
236
  name,
236
237
  superType
@@ -250,19 +251,3 @@ class ObjectType extends Type {
250
251
  }
251
252
 
252
253
  export const objectType = ObjectType.fromNothing();
253
-
254
- function superTypeFromJSON(json, fileContext) {
255
- let { superType } = json;
256
-
257
- const superTypeJSON = superType; ///
258
-
259
- json = superTypeJSON; ///
260
-
261
- const { name } = json,
262
- typeName = name, ///
263
- type = fileContext.findTypeByTypeName(typeName);
264
-
265
- superType = type; ///
266
-
267
- return superType;
268
- }
@@ -31,12 +31,13 @@ class IntrinsicLevelUnifier extends Unifier {
31
31
 
32
32
  const variableNode = termVariableNodeA, ///
33
33
  variableName = variableNameFromVariableNode(variableNode),
34
- variable = localContextA.findVariableByVariableName(variableName);
34
+ variablePresent = localContextA.isVariablePresentByVariableName(variableName);
35
35
 
36
- if (variable !== null) {
37
- const { Term } = shim,
36
+ if (variablePresent !== null) {
37
+ const { Term, Variable } = shim,
38
38
  localContext = localContextB, ///
39
39
  termNode = termNodeB, ///
40
+ variable = Variable.fromVariableNode(variableNode, localContextA),
40
41
  term = Term.fromTermNode(termNode, localContextB);
41
42
 
42
43
  termUnified = variable.unifyTerm(term, substitutions, localContext);
@@ -78,12 +78,23 @@ class MetaLevelUnifier extends Unifier {
78
78
  nodeQueryA: frameMetavariableNodeQuery,
79
79
  nodeQueryB: frameNodeQuery,
80
80
  unify: (frameMetavariableNodeA, frameNodeB, substitutions, localContextA, localContextB) => {
81
- debugger
81
+ let frameUnified = false;
82
82
 
83
- const metavariableNodeA = frameMetavariableNodeA, ///
84
- metavariableUnifiedWithFrame = unifyMetavariableWithFrame(metavariableNodeA, frameNodeB, substitutions, localContextA, localContextB);
83
+ const metavariableNode = frameMetavariableNodeA, ///
84
+ metavariableName = metavariableNameFromMetavariableNode(metavariableNode),
85
+ metavariablePresent = localContextA.isMetavariablePresentByMetavariableName(metavariableName);
85
86
 
86
- return metavariableUnifiedWithFrame;
87
+ if (metavariablePresent) {
88
+ const { Frame, Metavariable } = shim,
89
+ localContext = localContextB, ///
90
+ frameNode = frameNodeB, ///
91
+ metavariable = Metavariable.fromMetavariableNode(metavariableNode, localContextA),
92
+ frame = Frame.fromFrameNode(frameNode, localContextB);
93
+
94
+ frameUnified = metavariable.unifyFrame(frame, substitutions, localContext);
95
+ }
96
+
97
+ return frameUnified;
87
98
  }
88
99
  },
89
100
  {
@@ -94,12 +105,13 @@ class MetaLevelUnifier extends Unifier {
94
105
 
95
106
  const variableNode = termVariableNodeA, ///
96
107
  variableName = variableNameFromVariableNode(variableNode),
97
- variable = localContextA.findVariableByVariableName(variableName);
108
+ variablePresent = localContextA.isVariablePresentByVariableName(variableName);
98
109
 
99
- if (variable !== null) {
100
- const { Term } = shim,
110
+ if (variablePresent) {
111
+ const { Term, Variable } = shim,
101
112
  localContext = localContextB, ///
102
113
  termNode = termNodeB, ///
114
+ variable = Variable.fromVariableNode(variableNode, localContextA),
103
115
  term = Term.fromTermNode(termNode, localContextB);
104
116
 
105
117
  termUnified = variable.unifyTerm(term, substitutions, localContext);
@@ -24,18 +24,18 @@ class MetavariableUnifier extends Unifier {
24
24
 
25
25
  static maps = [
26
26
  {
27
- nodeQueryA: termNodeQuery,
28
- nodeQueryB: typeNodeQuery,
29
- unify: (termNodeA, typeNodeB, localContext) => {
27
+ nodeQueryA: typeNodeQuery,
28
+ nodeQueryB: termNodeQuery,
29
+ unify: (typeNodeA, termNodeB, localContext) => {
30
30
  let unified = false;
31
31
 
32
32
  const { Term } = shim,
33
- typeNode = typeNodeB, ///
33
+ typeNode = typeNodeA, ///
34
34
  typeName = typeNameFromTypeNode(typeNode),
35
35
  type = localContext.findTypeByTypeName(typeName);
36
36
 
37
37
  if (type !== null) {
38
- const termNode = termNodeA, ///
38
+ const termNode = termNodeB, ///
39
39
  term = Term.fromTermNode(termNode, localContext),
40
40
  termVerifiedGivenType = term.verifyGivenType(type, localContext);
41
41