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.
- package/lib/assertion/contained.js +52 -30
- package/lib/assertion/defined.js +45 -23
- package/lib/assertion/subproof.js +46 -30
- package/lib/context/local.js +5 -5
- package/lib/declaration.js +5 -8
- package/lib/equality.js +2 -2
- package/lib/equivalence.js +8 -21
- package/lib/metavariable.js +6 -5
- package/lib/mixins/statement/resolve.js +54 -0
- package/lib/mixins/statement/unify.js +2 -2
- package/lib/mixins/statement/verify.js +16 -46
- package/lib/premise.js +36 -15
- package/lib/proofStep.js +61 -23
- package/lib/rule.js +56 -20
- package/lib/statement/qualified.js +3 -3
- package/lib/statement/unqualified.js +15 -1
- package/lib/statement.js +23 -1
- package/lib/substitution/statementForMetavariable.js +23 -13
- package/lib/substitutions.js +23 -3
- package/lib/supposition.js +29 -21
- package/lib/term.js +15 -8
- package/lib/topLevelAssertion.js +11 -5
- package/lib/type.js +1 -8
- package/lib/utilities/equivalences.js +3 -3
- package/lib/utilities/substitutions.js +77 -0
- package/lib/variable.js +2 -2
- package/lib/verifier/statementAsCombinator.js +4 -11
- package/lib/verifier/termAsConstructor.js +3 -3
- package/package.json +1 -1
- package/src/assertion/contained.js +69 -37
- package/src/assertion/defined.js +65 -34
- package/src/assertion/subproof.js +61 -42
- package/src/context/local.js +3 -3
- package/src/declaration.js +5 -8
- package/src/equality.js +3 -2
- package/src/equivalence.js +6 -18
- package/src/metavariable.js +5 -8
- package/src/mixins/statement/resolve.js +68 -0
- package/src/mixins/statement/unify.js +2 -2
- package/src/mixins/statement/verify.js +23 -77
- package/src/premise.js +52 -20
- package/src/proofStep.js +89 -28
- package/src/rule.js +61 -22
- package/src/statement/qualified.js +2 -4
- package/src/statement/unqualified.js +18 -0
- package/src/statement.js +30 -0
- package/src/substitution/statementForMetavariable.js +31 -16
- package/src/substitutions.js +34 -12
- package/src/supposition.js +48 -33
- package/src/term.js +17 -7
- package/src/topLevelAssertion.js +14 -6
- package/src/type.js +0 -6
- package/src/utilities/equivalences.js +2 -2
- package/src/utilities/substitutions.js +77 -0
- package/src/variable.js +1 -1
- package/src/verifier/statementAsCombinator.js +3 -17
- package/src/verifier/termAsConstructor.js +2 -2
- package/lib/verifier/metaLevel.js +0 -147
- package/src/verifier/metaLevel.js +0 -54
package/src/rule.js
CHANGED
|
@@ -14,7 +14,7 @@ import { labelsFromJSON,
|
|
|
14
14
|
premisesToPremisesJSON,
|
|
15
15
|
conclusionToConclusionJSON } from "./utilities/json";
|
|
16
16
|
|
|
17
|
-
const { reverse,
|
|
17
|
+
const { extract, reverse, backwardsEvery } = arrayUtilities;
|
|
18
18
|
|
|
19
19
|
const proofNodeQuery = nodeQuery("/rule/proof"),
|
|
20
20
|
labelNodesQuery = nodesQuery("/rule/label"),
|
|
@@ -68,24 +68,17 @@ class Rule {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
unifyStatement(statement, localContext) {
|
|
71
|
-
let statementUnified
|
|
71
|
+
let statementUnified;
|
|
72
72
|
|
|
73
73
|
const { Substitutions } = shim,
|
|
74
|
-
proofSteps = localContext.getProofSteps(),
|
|
75
74
|
substitutions = Substitutions.fromNothing(),
|
|
76
|
-
|
|
75
|
+
conclusionUnified = this.unifyConclusion(statement, substitutions, localContext);
|
|
77
76
|
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
77
|
+
if (conclusionUnified) {
|
|
78
|
+
const premisesUnified = this.unifyPremises(substitutions, localContext);
|
|
80
79
|
|
|
81
|
-
if (
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
localContext = LocalContext.fromFileContext(this.fileContext);
|
|
85
|
-
|
|
86
|
-
const localContextA = localContext; ///
|
|
87
|
-
|
|
88
|
-
const substitutionsResolved = substitutions.resolve(localContextA, localContextB);
|
|
80
|
+
if (premisesUnified) {
|
|
81
|
+
const substitutionsResolved = substitutions.areResolved();
|
|
89
82
|
|
|
90
83
|
statementUnified = substitutionsResolved; ///
|
|
91
84
|
}
|
|
@@ -94,24 +87,70 @@ class Rule {
|
|
|
94
87
|
return statementUnified;
|
|
95
88
|
}
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
let
|
|
90
|
+
unifyConclusion(statement, substitutions, localContext) {
|
|
91
|
+
let conclusionUnified;
|
|
92
|
+
|
|
93
|
+
const conclusionString = this.conclusion.getString();
|
|
94
|
+
|
|
95
|
+
localContext.trace(`Unifying the '${conclusionString}' conclusion...`);
|
|
96
|
+
|
|
97
|
+
const statementUnified = this.conclusion.unifyStatement(statement, substitutions, localContext); ///
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
conclusionUnified = statementUnified; ///
|
|
101
100
|
|
|
102
|
-
|
|
101
|
+
if (conclusionUnified) {
|
|
102
|
+
localContext.debug(`...unified the '${conclusionString}' conclusion`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return conclusionUnified;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
unifyPremises(substitutions, localContext) {
|
|
109
|
+
let proofSteps = localContext.getProofSteps();
|
|
103
110
|
|
|
104
111
|
proofSteps = reverse(proofSteps); ///
|
|
105
112
|
|
|
106
|
-
|
|
107
|
-
const
|
|
113
|
+
const premisesUnified = backwardsEvery(this.premises, (premise) => {
|
|
114
|
+
const premiseUnified = this.unifyPremise(premise, proofSteps, substitutions, localContext);
|
|
108
115
|
|
|
109
|
-
if (
|
|
116
|
+
if (premiseUnified) {
|
|
110
117
|
return true;
|
|
111
118
|
}
|
|
112
119
|
});
|
|
113
120
|
|
|
114
|
-
return
|
|
121
|
+
return premisesUnified;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
unifyPremise(premise, proofSteps, substitutions, localContext) {
|
|
125
|
+
let premiseUnified =false;
|
|
126
|
+
|
|
127
|
+
const premiseString = premise.getString();
|
|
128
|
+
|
|
129
|
+
localContext.trace(`Unifying the '${premiseString}' premise...`);
|
|
130
|
+
|
|
131
|
+
const premiseResolvedIndependently = premise.resolveIndependently(substitutions, localContext);
|
|
132
|
+
|
|
133
|
+
if (premiseResolvedIndependently) {
|
|
134
|
+
premiseUnified = true;
|
|
135
|
+
} else {
|
|
136
|
+
const proofStep = extract(proofSteps, (proofStep) => {
|
|
137
|
+
const proofStepUnified = premise.unifyProofStep(proofStep, substitutions, localContext);
|
|
138
|
+
|
|
139
|
+
if (proofStepUnified) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (proofStep !== null) {
|
|
145
|
+
premiseUnified = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (premiseUnified) {
|
|
150
|
+
localContext.debug(`...unified the '${premiseString}' premise.`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return premiseUnified;
|
|
115
154
|
}
|
|
116
155
|
|
|
117
156
|
verify() {
|
|
@@ -71,7 +71,7 @@ class QualifiedStatement {
|
|
|
71
71
|
return statementUnified;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
verify(substitutions, localContext) {
|
|
74
|
+
verify(substitutions, assignments, stated, localContext) {
|
|
75
75
|
let verified;
|
|
76
76
|
|
|
77
77
|
const qualifiedStatementString = this.string; ///
|
|
@@ -79,9 +79,7 @@ class QualifiedStatement {
|
|
|
79
79
|
if (this.statement !== null) {
|
|
80
80
|
localContext.trace(`Verifying the '${qualifiedStatementString}' qualified statement...`);
|
|
81
81
|
|
|
82
|
-
const
|
|
83
|
-
assignments = [],
|
|
84
|
-
statementVerified = this.statement.verify(assignments, stated, localContext);
|
|
82
|
+
const statementVerified = this.statement.verify(assignments, stated, localContext);
|
|
85
83
|
|
|
86
84
|
if (statementVerified) {
|
|
87
85
|
const unified = this.unify(substitutions, localContext);
|
|
@@ -74,6 +74,24 @@ class UnqualifiedStatement {
|
|
|
74
74
|
return statementUnified;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
resolveIndependently(substitutions, localContextA, localContextB) {
|
|
78
|
+
let resolveIndependently;
|
|
79
|
+
|
|
80
|
+
const unqualifiedStatementString = this.getString(); ///
|
|
81
|
+
|
|
82
|
+
localContextB.trace(`Resolving the '${unqualifiedStatementString}' unqualified statement independently...`);
|
|
83
|
+
|
|
84
|
+
const statementResolvedIndependently = this.statement.resolveIndependently(substitutions, localContextA, localContextB);
|
|
85
|
+
|
|
86
|
+
resolveIndependently = statementResolvedIndependently; ///
|
|
87
|
+
|
|
88
|
+
if (resolveIndependently) {
|
|
89
|
+
localContextB.debug(`...resolved the '${unqualifiedStatementString}' unqualified statement independently.`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return resolveIndependently;
|
|
93
|
+
}
|
|
94
|
+
|
|
77
95
|
unifyStatementWithProofSteps(statement, assignments, stated, localContext) {
|
|
78
96
|
let statementUnifiedWithProofSteps;
|
|
79
97
|
|
package/src/statement.js
CHANGED
|
@@ -4,6 +4,7 @@ import shim from "./shim";
|
|
|
4
4
|
import unifyMixins from "./mixins/statement/unify";
|
|
5
5
|
import verifyMixins from "./mixins/statement/verify";
|
|
6
6
|
import LocalContext from "./context/local";
|
|
7
|
+
import resolveMixins from "./mixins/statement/resolve";
|
|
7
8
|
import metaLevelUnifier from "./unifier/metaLevel";
|
|
8
9
|
import statementAsCombinatorVerifier from "./verifier/statementAsCombinator";
|
|
9
10
|
|
|
@@ -105,6 +106,35 @@ class Statement {
|
|
|
105
106
|
return statementNodeMatches;
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
resolveIndependently(substitutions, localContextA, localContextB) {
|
|
110
|
+
let resolvedIndependently;
|
|
111
|
+
|
|
112
|
+
const statement = this, ///
|
|
113
|
+
statementString = this.string; ///
|
|
114
|
+
|
|
115
|
+
localContextB.trace(`Resolving the '${statementString}' statement independently...`);
|
|
116
|
+
|
|
117
|
+
const context = localContextA; ///
|
|
118
|
+
|
|
119
|
+
localContextA = LocalContext.fromContextAndTokens(context, this.tokens);
|
|
120
|
+
|
|
121
|
+
const resolved = resolveMixins.some((resolveMixin) => {
|
|
122
|
+
const resolved = resolveMixin(statement, substitutions, localContextA, localContextB);
|
|
123
|
+
|
|
124
|
+
if (resolved) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
resolvedIndependently = resolved; ///
|
|
130
|
+
|
|
131
|
+
if (resolvedIndependently) {
|
|
132
|
+
localContextB.debug(`...resolved the '${statementString}' statement independently.`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return resolvedIndependently;
|
|
136
|
+
}
|
|
137
|
+
|
|
108
138
|
unifyStatement(statement, substitutions, localContextA, localContextB) {
|
|
109
139
|
let statementUnified;
|
|
110
140
|
|
|
@@ -9,14 +9,19 @@ import { stripBracketsFromStatementNode } from "../utilities/brackets";
|
|
|
9
9
|
import { statementFromJSON, statementToStatementJSON, metavariableFromJSON, metavariableToMetavariableJSON } from "../utilities/json";
|
|
10
10
|
|
|
11
11
|
export default class StatementForMetavariableSubstitution extends Substitution {
|
|
12
|
-
constructor(string, statement, metavariable, substitution) {
|
|
12
|
+
constructor(string, resolved, statement, metavariable, substitution) {
|
|
13
13
|
super(string);
|
|
14
14
|
|
|
15
|
+
this.resolved = resolved;
|
|
15
16
|
this.statement = statement;
|
|
16
17
|
this.metavariable = metavariable;
|
|
17
18
|
this.substitution = substitution;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
isResolved() {
|
|
22
|
+
return this.resolved;
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
getStatement() {
|
|
21
26
|
return this.statement;
|
|
22
27
|
}
|
|
@@ -42,27 +47,23 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
resolve(substitutions, localContextA, localContextB) {
|
|
45
|
-
let resolved = false;
|
|
46
|
-
|
|
47
50
|
const substitutionString = this.string;
|
|
48
51
|
|
|
49
|
-
localContextB.trace(`Resolving the ${substitutionString} substitution...`);
|
|
50
|
-
|
|
51
52
|
const metavariableNode = this.getMetavariableNode(),
|
|
52
53
|
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariableNode(metavariableNode);
|
|
53
54
|
|
|
54
55
|
if (simpleSubstitution !== null) {
|
|
56
|
+
localContextB.trace(`Resolving the ${substitutionString} substitution...`);
|
|
57
|
+
|
|
55
58
|
const substitution = simpleSubstitution, ///
|
|
56
59
|
substitutionResolved = substitution.resolveSubstitution(this.substitution, this.statement, substitutions, localContextA, localContextB);
|
|
57
60
|
|
|
58
|
-
resolved = substitutionResolved; ///
|
|
59
|
-
}
|
|
61
|
+
this.resolved = substitutionResolved; ///
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
if (this.resolved) {
|
|
64
|
+
localContextB.debug(`...resolved the ${substitutionString} substitution.`);
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
|
-
|
|
65
|
-
return resolved;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
resolveSubstitution(substitution, statement, substitutions, localContextA, localContextB) {
|
|
@@ -82,10 +83,21 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
82
83
|
|
|
83
84
|
substitutions.snapshot();
|
|
84
85
|
|
|
85
|
-
const
|
|
86
|
-
|
|
86
|
+
const substitutionNodeA = substitutionA.getSubstitutionNode(), ///
|
|
87
|
+
substitutionNodeB = substitutionB.getSubstitutionNode(), ///
|
|
88
|
+
substitutionStringA = localContextA.nodeAsString(substitutionNodeA),
|
|
89
|
+
substitutionStringB = localContextB.nodeAsString(substitutionNodeB);
|
|
90
|
+
|
|
91
|
+
localContextB.trace(`Unifying the '${substitutionStringB}' substitution with the '${substitutionStringA}' substitution...`);
|
|
92
|
+
|
|
93
|
+
const nodeA = substitutionNodeA, ///
|
|
94
|
+
nodeB = substitutionNodeB, ///
|
|
87
95
|
unifiedAtMetaLevel = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
|
|
88
96
|
|
|
97
|
+
if (unifiedAtMetaLevel) {
|
|
98
|
+
localContextB.trace(`...unified the '${substitutionStringB}' substitution with the '${substitutionStringA}' substitution.`);
|
|
99
|
+
}
|
|
100
|
+
|
|
89
101
|
unifiedAtMetaLevel ?
|
|
90
102
|
substitutions.continue() :
|
|
91
103
|
substitutions.rollback(localContextB);
|
|
@@ -171,10 +183,11 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
171
183
|
|
|
172
184
|
static fromJSON(json, fileContext) {
|
|
173
185
|
const { string } = json,
|
|
186
|
+
resolved = true,
|
|
174
187
|
statement = statementFromJSON(json, fileContext),
|
|
175
188
|
metavariable = metavariableFromJSON(json, fileContext),
|
|
176
189
|
substitution = null, ///
|
|
177
|
-
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statement, metavariable, substitution);
|
|
190
|
+
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, resolved, statement, metavariable, substitution);
|
|
178
191
|
|
|
179
192
|
return statementForMetavariableSubstitution;
|
|
180
193
|
}
|
|
@@ -189,8 +202,9 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
189
202
|
statement = Statement.fromStatementNode(statementNode, localContext);
|
|
190
203
|
|
|
191
204
|
const substitution = null,
|
|
205
|
+
resolved = true,
|
|
192
206
|
string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext),
|
|
193
|
-
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statement, metavariable, substitution);
|
|
207
|
+
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, resolved, statement, metavariable, substitution);
|
|
194
208
|
|
|
195
209
|
return statementForMetavariableSubstitution;
|
|
196
210
|
}
|
|
@@ -205,7 +219,8 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
205
219
|
statement = Statement.fromStatementNode(statementNode, localContext);
|
|
206
220
|
|
|
207
221
|
const string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext),
|
|
208
|
-
|
|
222
|
+
resolved = false,
|
|
223
|
+
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, resolved, statement, metavariable, substitution);
|
|
209
224
|
|
|
210
225
|
return statementForMetavariableSubstitution;
|
|
211
226
|
}
|
package/src/substitutions.js
CHANGED
|
@@ -224,24 +224,46 @@ class Substitutions {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
resolve(localContextA, localContextB) {
|
|
227
|
+
const metavariableNodes = this.getMetavariableNodes();
|
|
228
|
+
|
|
229
|
+
metavariableNodes.forEach((metavariableNode) => {
|
|
230
|
+
const complexSubstitutions = this.findComplexSubstitutionsByMetavariableNode(metavariableNode),
|
|
231
|
+
complexSubstitutionsResolved = complexSubstitutions.everySubstitution((complexSubstitution) => {
|
|
232
|
+
let resolved;
|
|
233
|
+
|
|
234
|
+
const substitutions = this,
|
|
235
|
+
substitution = complexSubstitution; ///
|
|
236
|
+
|
|
237
|
+
resolved = substitution.isResolved();
|
|
238
|
+
|
|
239
|
+
if (!resolved) {
|
|
240
|
+
substitution.resolve(substitutions, localContextA, localContextB);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
if (complexSubstitutionsResolved) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
areResolved() {
|
|
227
251
|
const metavariableNodes = this.getMetavariableNodes(),
|
|
228
252
|
resolved = metavariableNodes.every((metavariableNode) => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (substitutionResolved) {
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
if (complexSubstitutionsResolved) {
|
|
253
|
+
const complexSubstitutions = this.findComplexSubstitutionsByMetavariableNode(metavariableNode),
|
|
254
|
+
complexSubstitutionsResolved = complexSubstitutions.everySubstitution((complexSubstitution) => {
|
|
255
|
+
const complexSubstitutionResolved = complexSubstitution.isResolved();
|
|
256
|
+
|
|
257
|
+
if (complexSubstitutionResolved) {
|
|
241
258
|
return true;
|
|
242
259
|
}
|
|
243
260
|
});
|
|
244
261
|
|
|
262
|
+
if (complexSubstitutionsResolved) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
245
267
|
return resolved;
|
|
246
268
|
}
|
|
247
269
|
|
package/src/supposition.js
CHANGED
|
@@ -59,37 +59,6 @@ class Supposition {
|
|
|
59
59
|
return verified;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
unifySubproof(subproof, substitutions, localContext) {
|
|
63
|
-
let subproofUnified = false;
|
|
64
|
-
|
|
65
|
-
const supposition = this, ///
|
|
66
|
-
subproofString = subproof.getString(),
|
|
67
|
-
suppositionStatement = supposition.getStatement(),
|
|
68
|
-
suppositionStatementString = suppositionStatement.getString();
|
|
69
|
-
|
|
70
|
-
localContext.trace(`Unifying the '${subproofString}' subproof with the supposition's '${suppositionStatementString}' statement...`);
|
|
71
|
-
|
|
72
|
-
const statement = this.unqualifiedStatement.getStatement(),
|
|
73
|
-
statementNode = statement.getNode(),
|
|
74
|
-
statementTokens = statement.getTokens(),
|
|
75
|
-
context = this.fileContext, ///
|
|
76
|
-
tokens = statementTokens; ///
|
|
77
|
-
|
|
78
|
-
localContext = LocalContext.fromContextAndTokens(context, tokens); ///
|
|
79
|
-
|
|
80
|
-
const subproofAssertion = SubproofAssertion.fromStatementNode(statementNode, localContext);
|
|
81
|
-
|
|
82
|
-
if (subproofAssertion !== null) {
|
|
83
|
-
subproofUnified = subproofAssertion.unifySubproof(subproof, substitutions, this.fileContext, localContext);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (subproofUnified) {
|
|
87
|
-
localContext.debug(`...unified the '${subproofString}' subproof with the supposition's '${suppositionStatementString}' statement.`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return subproofUnified;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
62
|
unifyProofStep(proofStep, substitutions, localContext) {
|
|
94
63
|
let proofStepUnified = false;
|
|
95
64
|
|
|
@@ -98,12 +67,27 @@ class Supposition {
|
|
|
98
67
|
|
|
99
68
|
substitutions.snapshot();
|
|
100
69
|
|
|
70
|
+
let subproofUnified = false,
|
|
71
|
+
statementUnified = false;
|
|
72
|
+
|
|
101
73
|
if (false) {
|
|
102
74
|
///
|
|
103
75
|
} else if (subproof !== null) {
|
|
104
|
-
|
|
76
|
+
subproofUnified = this.unifySubproof(subproof, substitutions, localContext);
|
|
105
77
|
} else if (statement !== null) {
|
|
106
|
-
|
|
78
|
+
statementUnified = this.unifyStatement(statement, substitutions, localContext);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (subproofUnified || statementUnified) {
|
|
82
|
+
const localContextB = localContext; ///
|
|
83
|
+
|
|
84
|
+
localContext = LocalContext.fromFileContext(this.fileContext);
|
|
85
|
+
|
|
86
|
+
const localContextA = localContext; ///
|
|
87
|
+
|
|
88
|
+
substitutions.resolve(localContextA, localContextB);
|
|
89
|
+
|
|
90
|
+
proofStepUnified = true;
|
|
107
91
|
}
|
|
108
92
|
|
|
109
93
|
proofStepUnified ?
|
|
@@ -136,6 +120,37 @@ class Supposition {
|
|
|
136
120
|
return statementUnified;
|
|
137
121
|
}
|
|
138
122
|
|
|
123
|
+
unifySubproof(subproof, substitutions, localContext) {
|
|
124
|
+
let subproofUnified = false;
|
|
125
|
+
|
|
126
|
+
const supposition = this, ///
|
|
127
|
+
subproofString = subproof.getString(),
|
|
128
|
+
suppositionStatement = supposition.getStatement(),
|
|
129
|
+
suppositionStatementString = suppositionStatement.getString();
|
|
130
|
+
|
|
131
|
+
localContext.trace(`Unifying the '${subproofString}' subproof with the supposition's '${suppositionStatementString}' statement...`);
|
|
132
|
+
|
|
133
|
+
const statement = this.unqualifiedStatement.getStatement(),
|
|
134
|
+
statementNode = statement.getNode(),
|
|
135
|
+
statementTokens = statement.getTokens(),
|
|
136
|
+
context = this.fileContext, ///
|
|
137
|
+
tokens = statementTokens; ///
|
|
138
|
+
|
|
139
|
+
localContext = LocalContext.fromContextAndTokens(context, tokens); ///
|
|
140
|
+
|
|
141
|
+
const subproofAssertion = SubproofAssertion.fromStatementNode(statementNode, localContext);
|
|
142
|
+
|
|
143
|
+
if (subproofAssertion !== null) {
|
|
144
|
+
subproofUnified = subproofAssertion.unifySubproof(subproof, substitutions, this.fileContext, localContext);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (subproofUnified) {
|
|
148
|
+
localContext.debug(`...unified the '${subproofString}' subproof with the supposition's '${suppositionStatementString}' statement.`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return subproofUnified;
|
|
152
|
+
}
|
|
153
|
+
|
|
139
154
|
toJSON() {
|
|
140
155
|
const unqualifiedStatementJSON = unqualifiedStatementToUnqualifiedStatementJSON(this.unqualifiedStatement),
|
|
141
156
|
unqualifiedStatement = unqualifiedStatementJSON, ///
|
package/src/term.js
CHANGED
|
@@ -42,13 +42,6 @@ class Term {
|
|
|
42
42
|
this.type = type;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
match(term) {
|
|
46
|
-
const node = term.getNode(),
|
|
47
|
-
matches = this.node.match(node);
|
|
48
|
-
|
|
49
|
-
return matches;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
45
|
getVariable(localContext) {
|
|
53
46
|
let variable = null;
|
|
54
47
|
|
|
@@ -98,6 +91,23 @@ class Term {
|
|
|
98
91
|
return grounded;
|
|
99
92
|
}
|
|
100
93
|
|
|
94
|
+
isEqualTo(term) {
|
|
95
|
+
let equalTo = false;
|
|
96
|
+
|
|
97
|
+
const termNode = term.getNode(),
|
|
98
|
+
termNodeMatches = this.node.match(termNode);
|
|
99
|
+
|
|
100
|
+
if (termNodeMatches) {
|
|
101
|
+
const termType = term.getType();
|
|
102
|
+
|
|
103
|
+
if (this.type === termType) {
|
|
104
|
+
equalTo = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return equalTo;
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
matchTermNode(termNode) {
|
|
102
112
|
const termNodeMatches = this.node.match(termNode);
|
|
103
113
|
|
package/src/topLevelAssertion.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { arrayUtilities } from "necessary";
|
|
4
4
|
|
|
5
5
|
import shim from "./shim";
|
|
6
|
+
import LocalContext from "./context/local";
|
|
6
7
|
|
|
7
8
|
import { EMPTY_STRING } from "./constants";
|
|
8
9
|
import { labelsFromJSON,
|
|
@@ -61,15 +62,22 @@ export default class TopLevelAssertion {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
unifyStatement(statement, localContext) {
|
|
64
|
-
let statementUnified
|
|
65
|
+
let statementUnified;
|
|
65
66
|
|
|
66
67
|
const { Substitutions } = shim,
|
|
67
|
-
|
|
68
|
-
substitutions = Substitutions.fromNothing(),
|
|
69
|
-
proofStepsUnified = this.unifyProofSteps(proofSteps, substitutions, localContext);
|
|
68
|
+
substitutions = Substitutions.fromNothing();
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
statementUnified = this.consequent.unifyStatement(statement, substitutions, localContext);
|
|
71
|
+
|
|
72
|
+
if (statementUnified) {
|
|
73
|
+
const proofSteps = localContext.getProofSteps(),
|
|
74
|
+
proofStepsUnified = this.unifyProofSteps(proofSteps, substitutions, localContext);
|
|
75
|
+
|
|
76
|
+
if (proofStepsUnified) {
|
|
77
|
+
const substitutionsResolved = substitutions.areResolved();
|
|
78
|
+
|
|
79
|
+
statementUnified = substitutionsResolved; ///
|
|
80
|
+
}
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
return statementUnified;
|
package/src/type.js
CHANGED
|
@@ -57,9 +57,9 @@ export function findEquivalenceByType(equivalences, type) {
|
|
|
57
57
|
|
|
58
58
|
export function findEquivalenceByTerm(equivalences, term) {
|
|
59
59
|
const equivalence = equivalences.find((equivalence) => {
|
|
60
|
-
const
|
|
60
|
+
const termEquates = equivalence.equateTerm(term);
|
|
61
61
|
|
|
62
|
-
if (
|
|
62
|
+
if (termEquates) {
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
65
|
}) || null;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { nodeQuery } from "../utilities/query";
|
|
4
|
+
import { variableNameFromVariableNode } from "../utilities/name";
|
|
5
|
+
|
|
6
|
+
const variableNodeQuery = nodeQuery("/term/variable!"),
|
|
7
|
+
metavariableNodeQuery = nodeQuery("/*/metavariable!");
|
|
8
|
+
|
|
9
|
+
export function termFromTermAndSubstitutions(term, substitutions) {
|
|
10
|
+
if (term !== null) {
|
|
11
|
+
const termNode = term.getNode(),
|
|
12
|
+
variableNode = variableNodeQuery(termNode);
|
|
13
|
+
|
|
14
|
+
if (variableNode !== null) {
|
|
15
|
+
const variableName = variableNameFromVariableNode(variableNode),
|
|
16
|
+
substitution = substitutions.findSubstitution((substitution) => {
|
|
17
|
+
const variableNameMatches = substitution.matchVariableName(variableName);
|
|
18
|
+
|
|
19
|
+
if (variableNameMatches) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (substitution !== null) {
|
|
25
|
+
term = substitution.getTerm();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return term;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function frameFromFrameAndSubstitutions(frame, substitutions) {
|
|
34
|
+
if (frame !== null) {
|
|
35
|
+
const frameNode = frame.getNode(),
|
|
36
|
+
metavariableNode = metavariableNodeQuery(frameNode);
|
|
37
|
+
|
|
38
|
+
if (metavariableNode !== null) {
|
|
39
|
+
const substitution = substitutions.findSubstitution((substitution) => {
|
|
40
|
+
const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
|
|
41
|
+
|
|
42
|
+
if (metavariableNodeMatches) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (substitution !== null) {
|
|
48
|
+
frame = substitution.getTerm();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return frame;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function statementFromStatementAndSubstitutions(statement, substitutions) {
|
|
57
|
+
if (statement !== null) {
|
|
58
|
+
const statementNode = statement.getNode(),
|
|
59
|
+
metavariableNode = metavariableNodeQuery(statementNode);
|
|
60
|
+
|
|
61
|
+
if (metavariableNode !== null) {
|
|
62
|
+
const substitution = substitutions.findSubstitution((substitution) => {
|
|
63
|
+
const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
|
|
64
|
+
|
|
65
|
+
if (metavariableNodeMatches) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (substitution !== null) {
|
|
71
|
+
statement = substitution.getStatement();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return statement;
|
|
77
|
+
}
|
package/src/variable.js
CHANGED
|
@@ -164,7 +164,7 @@ class Variable {
|
|
|
164
164
|
variable = variableFromVariableNode(variableNode, localContext),
|
|
165
165
|
termVariable = termVariableFromTermNode(termNode, localContext);
|
|
166
166
|
|
|
167
|
-
if (variable === termVariable) {
|
|
167
|
+
if ((variable !== null) && (variable === termVariable)) {
|
|
168
168
|
termUnified = true;
|
|
169
169
|
} else {
|
|
170
170
|
const variable = this, ///
|