occam-verify-cli 0.0.1075 → 0.0.1078

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 (59) hide show
  1. package/lib/assertion/contained.js +52 -30
  2. package/lib/assertion/defined.js +45 -23
  3. package/lib/assertion/subproof.js +46 -30
  4. package/lib/context/local.js +5 -5
  5. package/lib/declaration.js +5 -8
  6. package/lib/equality.js +2 -2
  7. package/lib/equivalence.js +8 -21
  8. package/lib/metavariable.js +6 -5
  9. package/lib/mixins/statement/resolve.js +54 -0
  10. package/lib/mixins/statement/unify.js +2 -2
  11. package/lib/mixins/statement/verify.js +16 -46
  12. package/lib/premise.js +36 -15
  13. package/lib/proofStep.js +61 -23
  14. package/lib/rule.js +56 -20
  15. package/lib/statement/qualified.js +3 -3
  16. package/lib/statement/unqualified.js +15 -1
  17. package/lib/statement.js +23 -1
  18. package/lib/substitution/statementForMetavariable.js +23 -13
  19. package/lib/substitutions.js +23 -3
  20. package/lib/supposition.js +29 -21
  21. package/lib/term.js +15 -8
  22. package/lib/topLevelAssertion.js +11 -5
  23. package/lib/type.js +1 -8
  24. package/lib/utilities/equivalences.js +3 -3
  25. package/lib/utilities/substitutions.js +77 -0
  26. package/lib/variable.js +2 -2
  27. package/lib/verifier/statementAsCombinator.js +4 -11
  28. package/lib/verifier/termAsConstructor.js +3 -3
  29. package/package.json +1 -1
  30. package/src/assertion/contained.js +69 -37
  31. package/src/assertion/defined.js +65 -34
  32. package/src/assertion/subproof.js +61 -42
  33. package/src/context/local.js +3 -3
  34. package/src/declaration.js +5 -8
  35. package/src/equality.js +3 -2
  36. package/src/equivalence.js +6 -18
  37. package/src/metavariable.js +5 -8
  38. package/src/mixins/statement/resolve.js +68 -0
  39. package/src/mixins/statement/unify.js +2 -2
  40. package/src/mixins/statement/verify.js +23 -77
  41. package/src/premise.js +52 -20
  42. package/src/proofStep.js +89 -28
  43. package/src/rule.js +61 -22
  44. package/src/statement/qualified.js +2 -4
  45. package/src/statement/unqualified.js +18 -0
  46. package/src/statement.js +30 -0
  47. package/src/substitution/statementForMetavariable.js +31 -16
  48. package/src/substitutions.js +34 -12
  49. package/src/supposition.js +48 -33
  50. package/src/term.js +17 -7
  51. package/src/topLevelAssertion.js +14 -6
  52. package/src/type.js +0 -6
  53. package/src/utilities/equivalences.js +2 -2
  54. package/src/utilities/substitutions.js +77 -0
  55. package/src/variable.js +1 -1
  56. package/src/verifier/statementAsCombinator.js +3 -17
  57. package/src/verifier/termAsConstructor.js +2 -2
  58. package/lib/verifier/metaLevel.js +0 -147
  59. package/src/verifier/metaLevel.js +0 -54
@@ -250,7 +250,7 @@ class LocalContext {
250
250
  return termGrounded;
251
251
  }
252
252
 
253
- isVariableDefined(variable) {
253
+ isVariableDefinedByVariableName(variableName) {
254
254
  const context = this,
255
255
  equivalences = this.getEquivalences(),
256
256
  groundedTerms = [],
@@ -259,9 +259,9 @@ class LocalContext {
259
259
  groundedTermsAndDefinedVariablesFromFromEquivalences(equivalences, groundedTerms, definedVariables, context);
260
260
 
261
261
  const variableMatchesDefinedVariable = definedVariables.some((definedVariable) => {
262
- const variableMatchesDefinedVariable = variable.match(definedVariable);
262
+ const definedVariableName = definedVariable.getName();
263
263
 
264
- if (variableMatchesDefinedVariable) {
264
+ if (definedVariableName === variableName) {
265
265
  return true;
266
266
  }
267
267
  }),
@@ -100,17 +100,14 @@ class Declaration {
100
100
 
101
101
  localContext.trace(`Verifying the '${declarationString}' declaration...`);
102
102
 
103
- stated = true;
103
+ stated = true; ///
104
104
 
105
- assignments = null;
105
+ assignments = null; ///
106
106
 
107
- const referenceVerified = this.reference.verify(localContext);
107
+ const referenceVerified = this.reference.verify(localContext),
108
+ statementVerified = this.statement.verify(assignments, stated, localContext);
108
109
 
109
- if (referenceVerified) {
110
- const statementVerified = this.statement.verify(assignments, stated, localContext);
111
-
112
- verified = statementVerified; ///
113
- }
110
+ verified = (referenceVerified && statementVerified);
114
111
 
115
112
  if (verified) {
116
113
  localContext.debug(`...verified the '${declarationString}' declaration.`);
package/src/equality.js CHANGED
@@ -50,8 +50,9 @@ class Equality {
50
50
  }
51
51
 
52
52
  isReflexive() {
53
- const leftTermMatchesRightTerm = this.leftTerm.match(this.rightTerm),
54
- reflexive = leftTermMatchesRightTerm; ///
53
+ const rightTermNode = this.rightTerm.getNode(),
54
+ leftTermNodeMatchesRightTermNode = this.leftTerm.matchTermNode(rightTermNode),
55
+ reflexive = leftTermNodeMatchesRightTermNode; ///
55
56
 
56
57
  return reflexive;
57
58
  }
@@ -56,30 +56,18 @@ export default class Equivalence {
56
56
  return typeMatches;
57
57
  }
58
58
 
59
- matchTerm(term) {
59
+ equateTerm(term) {
60
60
  const termA = term, ///
61
- termMatches = this.terms.some((term) => {
61
+ termEquates = this.terms.some((term) => {
62
62
  const termB = term, ///
63
- termAMatchesTermB = termA.match(termB);
63
+ termAEqualToTermB = termA.isEqualTo(termB);
64
64
 
65
- if (termAMatchesTermB) {
65
+ if (termAEqualToTermB) {
66
66
  return true;
67
67
  }
68
68
  });
69
69
 
70
- return termMatches;
71
- }
72
-
73
- matchTerms(terms) {
74
- const termsMatch = terms.every((term) => {
75
- const termMatches = this.matchTerm(term);
76
-
77
- if (termMatches) {
78
- return true;
79
- }
80
- })
81
-
82
- return termsMatch;
70
+ return termEquates;
83
71
  }
84
72
 
85
73
  matchTermNode(termNode) {
@@ -206,7 +194,7 @@ export default class Equivalence {
206
194
 
207
195
  string = (string === null) ?
208
196
  termString :
209
- `${string} ${termString}`;
197
+ `${string} = ${termString}`;
210
198
 
211
199
  return string;
212
200
  }, null);
@@ -6,6 +6,7 @@ import FrameForMetavariableSubstitution from "./substitution/frameForMetavariabl
6
6
  import StatementForMetavariableSubstitution from "./substitution/statementForMetavariable";
7
7
 
8
8
  import { nodeQuery } from "./utilities/query";
9
+ import { EMPTY_STRING } from "./constants";
9
10
  import { metavariableNodeFromMetavariableString } from "./utilities/node";
10
11
  import { metaTypeFromJSON, metaTypeToMetaTypeJSON } from "./utilities/json";
11
12
  import { typeNameFromTypeNode, metavariableNameFromMetavariableNode } from "./utilities/name";
@@ -122,11 +123,9 @@ class Metavariable {
122
123
  metavariableString = this.string, ///
123
124
  substitutionString = (substitution !== null) ?
124
125
  substitution.getString() :
125
- null;
126
+ EMPTY_STRING;
126
127
 
127
- (substitutionString !== null) ?
128
- localContext.trace(`Unifying the '${statementString}' statement with the '${metavariableString}' metavariable given the ${substitutionString} substitution...`) :
129
- localContext.trace(`Unifying the '${statementString}' statement with the '${metavariableString}' metavariable...`);
128
+ localContext.trace(`Unifying the '${statementString}' statement with the '${metavariableString}${substitutionString}' metavariable...`);
130
129
 
131
130
  const statementNode = statement.getNode(),
132
131
  metavariableNode = this.node, ///
@@ -147,7 +146,7 @@ class Metavariable {
147
146
  metavariable = metavariableFromMetavariableNode(metavariableNode, localContext),
148
147
  statementMetavariable = statementMetavariableFromStatementNode(statementNode, localContext);
149
148
 
150
- if (metavariable === statementMetavariable) {
149
+ if ((metavariable !== null) && (metavariable === statementMetavariable)) {
151
150
  statementUnified = true;
152
151
  } else {
153
152
  const metavariable = this, ///
@@ -162,9 +161,7 @@ class Metavariable {
162
161
  }
163
162
 
164
163
  if (statementUnified) {
165
- (substitutionString !== null) ?
166
- localContext.debug(`...unified the '${statementString}' statement with the '${metavariableString}' metavariable given the ${substitutionString} substitution.`) :
167
- localContext.debug(`...unified the '${statementString}' statement with the '${metavariableString}' metavariable.`);
164
+ localContext.debug(`...unified the '${statementString}' statement with the '${metavariableString}${substitutionString}' metavariable.`);
168
165
  }
169
166
 
170
167
  return statementUnified;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ import DefinedAssertion from "../../assertion/defined";
4
+ import ContainedAssertion from "../../assertion/contained";
5
+
6
+ import { nodeQuery } from "../../utilities/query";
7
+
8
+ const definedAssertionNodeQuery = nodeQuery("/statement/definedAssertion"),
9
+ containedAssertionNodeQuery = nodeQuery("/statement/containedAssertion");
10
+
11
+ function resolveAsDefinedAssertion(statement, substitutions, localContextA, localContextB) {
12
+ let resolvedAsDefinedAssertion = false;
13
+
14
+ const localContext = localContextA, ///
15
+ statementNode = statement.getNode(),
16
+ definedAssertionNode = definedAssertionNodeQuery(statementNode),
17
+ definedAssertion = DefinedAssertion.fromDefinedAssertionNode(definedAssertionNode, localContext);
18
+
19
+ if (definedAssertion !== null) {
20
+ const statementString = statement.getString();
21
+
22
+ localContextB.trace(`Resolving the '${statementString}' statement as a defined assertion...`);
23
+
24
+ const localContext = localContextB, ///
25
+ definedAssertionVerified = definedAssertion.resolve(substitutions, localContext);
26
+
27
+ resolvedAsDefinedAssertion = definedAssertionVerified; ///
28
+
29
+ if (resolvedAsDefinedAssertion) {
30
+ localContextB.debug(`...resolved the '${statementString}' statement as a defined assertion.`);
31
+ }
32
+ }
33
+
34
+ return resolvedAsDefinedAssertion;
35
+ }
36
+
37
+ function resolveAsContainedAssertion(statement, substitutions, localContextA, localContextB) {
38
+ let resolvedAsContainedAssertion = false;
39
+
40
+ const localContext = localContextA, ///
41
+ statementNode = statement.getNode(),
42
+ containedAssertionNode = containedAssertionNodeQuery(statementNode),
43
+ containedAssertion = ContainedAssertion.fromContainedAssertionNode(containedAssertionNode, localContext);
44
+
45
+ if (containedAssertion !== null) {
46
+ const statementString = statement.getString();
47
+
48
+ localContextB.trace(`Resolving the '${statementString}' statement as a contained assertion...`);
49
+
50
+ const localContext = localContextB, ///
51
+ containedAssertionVerified = containedAssertion.resolve(substitutions, localContext);
52
+
53
+ resolvedAsContainedAssertion = containedAssertionVerified; ///
54
+
55
+ if (resolvedAsContainedAssertion) {
56
+ localContextB.debug(`...resolved the '${statementString}' statement as a contained assertion.`);
57
+ }
58
+ }
59
+
60
+ return resolvedAsContainedAssertion;
61
+ }
62
+
63
+ const resolveMixins = [
64
+ resolveAsDefinedAssertion,
65
+ resolveAsContainedAssertion
66
+ ];
67
+
68
+ export default resolveMixins;
@@ -28,10 +28,10 @@ function unifyWithCombinators(statement, assignments, stated, localContext) {
28
28
 
29
29
  const combinators = localContext.getCombinators();
30
30
 
31
- assignments = null; ///
32
-
33
31
  stated = true; ///
34
32
 
33
+ assignments = null; ///
34
+
35
35
  unifiedWithCombinators = combinators.some((combinator) => {
36
36
  const unifiedWithCombinator = unifyStatementWithCombinator(statement, combinator, assignments, stated, localContext);
37
37
 
@@ -8,10 +8,8 @@ import ContainedAssertion from "../../assertion/contained";
8
8
 
9
9
  import { nodeQuery } from "../../utilities/query";
10
10
 
11
- const frameNodeQuery = nodeQuery("/statement/frame"),
12
- equalityNodeQuery = nodeQuery("/statement/equality"),
11
+ const equalityNodeQuery = nodeQuery("/statement/equality"),
13
12
  judgementNodeQuery = nodeQuery("/statement/judgement"),
14
- declarationNodeQuery = nodeQuery("/statement/declaration"),
15
13
  metavariableNodeQuery = nodeQuery("/statement/metavariable!"),
16
14
  typeAssertionNodeQuery = nodeQuery("/statement/typeAssertion"),
17
15
  definedAssertionNodeQuery = nodeQuery("/statement/definedAssertion"),
@@ -68,31 +66,6 @@ function verifyAsEquality(statement, assignments, stated, localContext) {
68
66
  return verifiedAsEquality;
69
67
  }
70
68
 
71
- function verifyAsFrame(statement, assignments, stated, localContext) {
72
- let verifiedAsFrame = false;
73
-
74
- const { Frame } = shim,
75
- statementNode = statement.getNode(),
76
- frameNode = frameNodeQuery(statementNode),
77
- frame = Frame.fromFrameNode(frameNode, localContext);
78
-
79
- if (frame !== null) {
80
- const statementString = statement.getString();
81
-
82
- localContext.trace(`Verifying the '${statementString}' statement as a frame...`);
83
-
84
- const frameVerified = frame.verify(assignments, stated, localContext);
85
-
86
- verifiedAsFrame = frameVerified; ///
87
-
88
- if (verifiedAsFrame) {
89
- localContext.debug(`...verified the '${statementString}' statement as a frame.`);
90
- }
91
- }
92
-
93
- return verifiedAsFrame;
94
- }
95
-
96
69
  function verifyAsJudgement(statement, assignments, stated, localContext) {
97
70
  let verifiedAsJudgement = false;
98
71
 
@@ -118,31 +91,6 @@ function verifyAsJudgement(statement, assignments, stated, localContext) {
118
91
  return verifiedAsJudgement;
119
92
  }
120
93
 
121
- function verifyAsDeclaration(statement, assignments, stated, localContext) {
122
- let verifiedAsDeclaration = false;
123
-
124
- const { Declaration } = shim,
125
- statementNode = statement.getNode(),
126
- declarationNode = declarationNodeQuery(statementNode),
127
- declaration = Declaration.fromDeclarationNode(declarationNode, localContext);
128
-
129
- if (declaration !== null) {
130
- const statementString = statement.getString();
131
-
132
- localContext.trace(`Verifying the '${statementString}' statement as a declaration...`);
133
-
134
- const declarationVerified = declaration.verify(assignments, stated, localContext);
135
-
136
- verifiedAsDeclaration = declarationVerified; ///
137
-
138
- if (verifiedAsDeclaration) {
139
- localContext.debug(`...verified the '${statementString}' statement as a declaration.`);
140
- }
141
- }
142
-
143
- return verifiedAsDeclaration;
144
- }
145
-
146
94
  function verifyAsTypeAssertion(statement, assignments, stated, localContext) {
147
95
  let verifiedAsTypeAssertion = false;
148
96
 
@@ -191,60 +139,58 @@ function verifyAsDefinedAssertion(statement, assignments, stated, localContext)
191
139
  return verifiedAsDefinedAssertion;
192
140
  }
193
141
 
194
- function verifyAsSubproofAssertion(statement, assignments, stated, localContext) {
195
- let verifiedAsSubproofAssertion = false;
142
+ function verifyAsContainedAssertion(statement, assignments, stated, localContext) {
143
+ let verifiedAsContainedAssertion = false;
196
144
 
197
145
  const statementNode = statement.getNode(),
198
- subproofAssertionNode = subproofAssertionNodeQuery(statementNode),
199
- subproofAssertion = SubproofAssertion.fromSubproofAssertionNode(subproofAssertionNode, localContext);
146
+ containedAssertionNode = containedAssertionNodeQuery(statementNode),
147
+ containedAssertion = ContainedAssertion.fromContainedAssertionNode(containedAssertionNode, localContext);
200
148
 
201
- if (subproofAssertionNode !== null) {
149
+ if (containedAssertion !== null) {
202
150
  const statementString = statement.getString();
203
151
 
204
- localContext.trace(`Verifying the '${statementString}' statement as a subproof assertion...`);
152
+ localContext.trace(`Verifying the '${statementString}' statement as a contained assertion...`);
205
153
 
206
- const subproofAssertionVerified = subproofAssertion.verify(assignments, stated, localContext);
154
+ const containedAssertionVerified = containedAssertion.verify(assignments, stated, localContext);
207
155
 
208
- verifiedAsSubproofAssertion = subproofAssertionVerified; ///
156
+ verifiedAsContainedAssertion = containedAssertionVerified; ///
209
157
 
210
- if (verifiedAsSubproofAssertion) {
211
- localContext.debug(`...verified the '${statementString}' statement as a subproof assertion.`);
158
+ if (verifiedAsContainedAssertion) {
159
+ localContext.debug(`...verified the '${statementString}' statement as a contained assertion.`);
212
160
  }
213
161
  }
214
162
 
215
- return verifiedAsSubproofAssertion;
163
+ return verifiedAsContainedAssertion;
216
164
  }
217
165
 
218
- function verifyAsContainedAssertion(statement, assignments, stated, localContext) {
219
- let verifiedAsContainedAssertion = false;
166
+ function verifyAsSubproofAssertion(statement, assignments, stated, localContext) {
167
+ let verifiedAsSubproofAssertion = false;
220
168
 
221
169
  const statementNode = statement.getNode(),
222
- containedAssertionNode = containedAssertionNodeQuery(statementNode),
223
- containedAssertion = ContainedAssertion.fromContainedAssertionNode(containedAssertionNode, localContext);
170
+ subproofAssertionNode = subproofAssertionNodeQuery(statementNode),
171
+ subproofAssertion = SubproofAssertion.fromSubproofAssertionNode(subproofAssertionNode, localContext);
224
172
 
225
- if (containedAssertion !== null) {
173
+ if (subproofAssertionNode !== null) {
226
174
  const statementString = statement.getString();
227
175
 
228
- localContext.trace(`Verifying the '${statementString}' statement as a contained assertion...`);
176
+ localContext.trace(`Verifying the '${statementString}' statement as a subproof assertion...`);
229
177
 
230
- const containedAssertionVerified = containedAssertion.verify(assignments, stated, localContext);
178
+ const subproofAssertionVerified = subproofAssertion.verify(assignments, stated, localContext);
231
179
 
232
- verifiedAsContainedAssertion = containedAssertionVerified; ///
180
+ verifiedAsSubproofAssertion = subproofAssertionVerified; ///
233
181
 
234
- if (verifiedAsContainedAssertion) {
235
- localContext.debug(`...verified the '${statementString}' statement as a contained assertion.`);
182
+ if (verifiedAsSubproofAssertion) {
183
+ localContext.debug(`...verified the '${statementString}' statement as a subproof assertion.`);
236
184
  }
237
185
  }
238
186
 
239
- return verifiedAsContainedAssertion;
187
+ return verifiedAsSubproofAssertion;
240
188
  }
241
189
 
242
190
  const verifyMixins = [
243
191
  verifyAsMetavariable,
244
192
  verifyAsEquality,
245
- verifyAsFrame,
246
193
  verifyAsJudgement,
247
- verifyAsDeclaration,
248
194
  verifyAsTypeAssertion,
249
195
  verifyAsDefinedAssertion,
250
196
  verifyAsSubproofAssertion,
package/src/premise.js CHANGED
@@ -28,35 +28,28 @@ class Premise {
28
28
 
29
29
  getStatement() { return this.unqualifiedStatement.getStatement(); }
30
30
 
31
- unifySubproof(subproof, substitutions, localContext) {
32
- let subproofUnified = false;
31
+ resolveIndependently(substitutions, localContext) {
32
+ let resolvedIndependently;
33
33
 
34
- const premise = this, ///
35
- subproofString = subproof.getString(),
36
- premiseStatement = premise.getStatement(),
37
- premiseStatementString = premiseStatement.getString();
34
+ const premiseString = this.getString();
38
35
 
39
- localContext.trace(`Unifying the '${subproofString}' subproof with the premise's '${premiseStatementString}' statement...`);
36
+ const localContextB = localContext; ///
40
37
 
41
- const statement = this.unqualifiedStatement.getStatement(),
42
- statementNode = statement.getNode(),
43
- statementTokens = statement.getTokens(),
44
- context = this.fileContext, ///
45
- tokens = statementTokens; ///
38
+ localContext = LocalContext.fromFileContext(this.fileContext);
46
39
 
47
- localContext = LocalContext.fromContextAndTokens(context, tokens); ///
40
+ const localContextA = localContext; ///
48
41
 
49
- const subproofAssertion = SubproofAssertion.fromStatementNode(statementNode, localContext);
42
+ localContextB.trace(`Resolving the '${premiseString}' premise independently...`);
50
43
 
51
- if (subproofAssertion !== null) {
52
- subproofUnified = subproofAssertion.unifySubproof(subproof, substitutions, this.fileContext, localContext);
53
- }
44
+ const unqualifiedStatementResolvedIndependently = this.unqualifiedStatement.resolveIndependently(substitutions, localContextA, localContextB);
54
45
 
55
- if (subproofUnified) {
56
- localContext.debug(`...unified the '${subproofString}' subproof with the premise's '${premiseStatementString}' statement.`);
46
+ resolvedIndependently = unqualifiedStatementResolvedIndependently; ///
47
+
48
+ if (resolvedIndependently) {
49
+ localContextB.trace(`...resolved the '${premiseString}' premise independently.`);
57
50
  }
58
51
 
59
- return subproofUnified;
52
+ return resolvedIndependently;
60
53
  }
61
54
 
62
55
  unifyProofStep(proofStep, substitutions, localContext) {
@@ -79,6 +72,14 @@ class Premise {
79
72
  }
80
73
 
81
74
  if (subproofUnified || statementUnified) {
75
+ const localContextB = localContext; ///
76
+
77
+ localContext = LocalContext.fromFileContext(this.fileContext);
78
+
79
+ const localContextA = localContext; ///
80
+
81
+ substitutions.resolve(localContextA, localContextB);
82
+
82
83
  proofStepUnified = true;
83
84
  }
84
85
 
@@ -112,6 +113,37 @@ class Premise {
112
113
  return statementUnified;
113
114
  }
114
115
 
116
+ unifySubproof(subproof, substitutions, localContext) {
117
+ let subproofUnified = false;
118
+
119
+ const premise = this, ///
120
+ subproofString = subproof.getString(),
121
+ premiseStatement = premise.getStatement(),
122
+ premiseStatementString = premiseStatement.getString();
123
+
124
+ localContext.trace(`Unifying the '${subproofString}' subproof with the premise's '${premiseStatementString}' statement...`);
125
+
126
+ const statement = this.unqualifiedStatement.getStatement(),
127
+ statementNode = statement.getNode(),
128
+ statementTokens = statement.getTokens(),
129
+ context = this.fileContext, ///
130
+ tokens = statementTokens; ///
131
+
132
+ localContext = LocalContext.fromContextAndTokens(context, tokens); ///
133
+
134
+ const subproofAssertion = SubproofAssertion.fromStatementNode(statementNode, localContext);
135
+
136
+ if (subproofAssertion !== null) {
137
+ subproofUnified = subproofAssertion.unifySubproof(subproof, substitutions, this.fileContext, localContext);
138
+ }
139
+
140
+ if (subproofUnified) {
141
+ localContext.debug(`...unified the '${subproofString}' subproof with the premise's '${premiseStatementString}' statement.`);
142
+ }
143
+
144
+ return subproofUnified;
145
+ }
146
+
115
147
  verify(localContext) {
116
148
  let verified = false;
117
149
 
package/src/proofStep.js CHANGED
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
 
3
+ import { arrayUtilities } from "necessary";
4
+
3
5
  import shim from "./shim";
6
+ import metaLevelUnifier from "./unifier/metaLevel";
4
7
 
5
8
  import { nodeQuery } from "./utilities/query";
6
9
  import { assignAssignments } from "./utilities/assignments";
7
10
 
11
+ const { match } = arrayUtilities;
12
+
8
13
  const subproofNodeQuery = nodeQuery("/proofStep|lastProofStep/subproof"),
9
14
  qualifiedStatementNodeQuery = nodeQuery("/proofStep|lastProofStep/qualifiedStatement"),
10
15
  unqualifiedStatementNodeQuery = nodeQuery("/proofStep|lastProofStep/unqualifiedStatement");
@@ -45,56 +50,112 @@ class ProofStep {
45
50
  unifyStatement(statement, localContext) {
46
51
  let statementUnified = false;
47
52
 
48
- const { Substitutions } = shim,
49
- substitutions = Substitutions.fromNothing();
53
+ if ((this.qualifiedStatement !== null) || (this.unqualifiedStatement !== null !== null)) {
54
+ const statementString = statement.getString();
50
55
 
51
- if (this.qualifiedStatement !== null) {
52
- const localContextA = localContext, ///
53
- localContextB = localContext; ///
56
+ localContext.trace(`Unifying the '${statementString}' statement...`);
54
57
 
55
- statementUnified = this.qualifiedStatement.unifyStatement(statement, substitutions, localContextA, localContextB);
56
- }
58
+ const { Substitutions } = shim,
59
+ localContextA = localContext, ///
60
+ localContextB = localContext, ///
61
+ substitutions = Substitutions.fromNothing();
57
62
 
58
- if (this.unqualifiedStatement !== null) {
59
- const localContextA = localContext, ///
60
- localContextB = localContext; ///
63
+ if (this.qualifiedStatement !== null) {
64
+ statementUnified = this.qualifiedStatement.unifyStatement(statement, substitutions, localContextA, localContextB);
65
+ }
61
66
 
62
- statementUnified = this.unqualifiedStatement.unifyStatement(statement, substitutions, localContextA, localContextB);
63
- }
67
+ if (this.unqualifiedStatement !== null) {
68
+ statementUnified = this.unqualifiedStatement.unifyStatement(statement, substitutions, localContextA, localContextB);
69
+ }
64
70
 
65
- const substitutionsLength = substitutions.getLength();
71
+ const substitutionsLength = substitutions.getLength();
66
72
 
67
- if (substitutionsLength > 0) {
68
- statementUnified = false;
73
+ if (substitutionsLength > 0) {
74
+ statementUnified = false;
75
+ }
76
+
77
+ if (statementUnified) {
78
+ localContext.debug(`...unified the '${statementString}' statement.`);
79
+ }
69
80
  }
70
81
 
71
82
  return statementUnified;
72
83
  }
73
84
 
85
+ unifySubproofAssertion(subproofAssertion, localContext) {
86
+ let subproofAssertionUnified = false;
87
+
88
+ if (this.subproof !== null) {
89
+ const subproofString = this.subproof.getString(),
90
+ subproofAssertionString = subproofAssertion.getString();
91
+
92
+ localContext.trace(`Unifying the '${subproofAssertionString}' subproof assertion with the '${subproofString}' subproof...`);
93
+
94
+ const { Substitutions } = shim,
95
+ substitutions = Substitutions.fromNothing(),
96
+ subproofStatements = this.subproof.getStatements(),
97
+ subproofAssertionStatements = subproofAssertion.getStatements();
98
+
99
+ subproofAssertionUnified = match(subproofAssertionStatements, subproofStatements, (subproofAssertionStatement, subproofStatement) => {
100
+ const subproofAssertionStatementNode = subproofAssertionStatement.getNode(),
101
+ subproofStatementNode = subproofStatement.getNode(),
102
+ nodeA = subproofAssertionStatementNode, ///
103
+ nodeB = subproofStatementNode, ///
104
+ localContextA = localContext, ///
105
+ localContextB = localContext, ///
106
+ unifiedAtMetaLevel = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
107
+
108
+ if (unifiedAtMetaLevel) {
109
+ return true;
110
+ }
111
+ });
112
+
113
+ if (subproofAssertionUnified) {
114
+ const substitutionsLength = substitutions.getLength();
115
+
116
+ if (substitutionsLength > 0) {
117
+ subproofAssertionUnified = false;
118
+ }
119
+ }
120
+
121
+ if (subproofAssertionUnified) {
122
+ localContext.trace(`...unified the '${subproofAssertionString}' subproof assertion with the '${subproofString}' subproof.`);
123
+ }
124
+ }
125
+
126
+ return subproofAssertionUnified;
127
+ }
128
+
74
129
  verify(substitutions, localContext) {
75
130
  let verified = false;
76
131
 
132
+ let stated = false;
133
+
134
+ const assignments = [];
135
+
136
+ let subproofVerified = false,
137
+ qualifiedStatementVerified = false,
138
+ unqualifiedStatementVerified = false;
139
+
77
140
  if (false) {
78
141
  ///
79
142
  } else if (this.subproof !== null) {
80
- const subproofVerified = this.subproof.verify(substitutions, localContext);
81
-
82
- verified = subproofVerified; ///
143
+ subproofVerified = this.subproof.verify(substitutions, localContext);
83
144
  } else if (this.qualifiedStatement !== null) {
84
- const qualifiedStatementVerified = this.qualifiedStatement.verify(substitutions, localContext);
145
+ stated = true;
85
146
 
86
- verified = qualifiedStatementVerified; ///
147
+ qualifiedStatementVerified = this.qualifiedStatement.verify(substitutions, assignments, stated, localContext);
87
148
  } else if (this.unqualifiedStatement !== null) {
88
- const stated = false,
89
- assignments = [],
90
- unqualifiedStatementVerified = this.unqualifiedStatement.verify(assignments, stated, localContext);
149
+ stated = false;
150
+
151
+ unqualifiedStatementVerified = this.unqualifiedStatement.verify(assignments, stated, localContext);
152
+ }
91
153
 
92
- if (unqualifiedStatementVerified) {
93
- const assignmentsAssigned = assignAssignments(assignments, localContext);
154
+ if (subproofVerified || qualifiedStatementVerified || unqualifiedStatementVerified) {
155
+ const assignmentsAssigned = assignAssignments(assignments, localContext);
94
156
 
95
- if (assignmentsAssigned) {
96
- verified = true;
97
- }
157
+ if (assignmentsAssigned) {
158
+ verified = true;
98
159
  }
99
160
  }
100
161