occam-verify-cli 0.0.1077 → 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 +47 -27
- package/lib/assertion/defined.js +44 -22
- package/lib/context/local.js +5 -5
- package/lib/equality.js +2 -2
- package/lib/equivalence.js +8 -21
- package/lib/mixins/statement/resolve.js +54 -0
- package/lib/premise.js +18 -1
- package/lib/rule.js +54 -16
- package/lib/statement/unqualified.js +15 -1
- package/lib/statement.js +23 -1
- package/lib/substitution/statementForMetavariable.js +2 -2
- package/lib/term.js +15 -8
- package/lib/type.js +1 -8
- package/lib/utilities/equivalences.js +3 -3
- package/lib/utilities/substitutions.js +77 -0
- package/package.json +1 -1
- package/src/assertion/contained.js +62 -32
- package/src/assertion/defined.js +63 -32
- package/src/context/local.js +3 -3
- package/src/equality.js +3 -2
- package/src/equivalence.js +6 -18
- package/src/mixins/statement/resolve.js +68 -0
- package/src/premise.js +24 -0
- package/src/rule.js +60 -16
- package/src/statement/unqualified.js +18 -0
- package/src/statement.js +30 -0
- package/src/substitution/statementForMetavariable.js +2 -2
- package/src/term.js +17 -7
- package/src/type.js +0 -6
- package/src/utilities/equivalences.js +2 -2
- package/src/utilities/substitutions.js +77 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
frameFromFrameAndSubstitutions: function() {
|
|
13
|
+
return frameFromFrameAndSubstitutions;
|
|
14
|
+
},
|
|
15
|
+
statementFromStatementAndSubstitutions: function() {
|
|
16
|
+
return statementFromStatementAndSubstitutions;
|
|
17
|
+
},
|
|
18
|
+
termFromTermAndSubstitutions: function() {
|
|
19
|
+
return termFromTermAndSubstitutions;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
var _query = require("../utilities/query");
|
|
23
|
+
var _name = require("../utilities/name");
|
|
24
|
+
var variableNodeQuery = (0, _query.nodeQuery)("/term/variable!"), metavariableNodeQuery = (0, _query.nodeQuery)("/*/metavariable!");
|
|
25
|
+
function termFromTermAndSubstitutions(term, substitutions) {
|
|
26
|
+
if (term !== null) {
|
|
27
|
+
var termNode = term.getNode(), variableNode = variableNodeQuery(termNode);
|
|
28
|
+
if (variableNode !== null) {
|
|
29
|
+
var variableName = (0, _name.variableNameFromVariableNode)(variableNode), substitution = substitutions.findSubstitution(function(substitution) {
|
|
30
|
+
var variableNameMatches = substitution.matchVariableName(variableName);
|
|
31
|
+
if (variableNameMatches) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (substitution !== null) {
|
|
36
|
+
term = substitution.getTerm();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return term;
|
|
41
|
+
}
|
|
42
|
+
function frameFromFrameAndSubstitutions(frame, substitutions) {
|
|
43
|
+
if (frame !== null) {
|
|
44
|
+
var frameNode = frame.getNode(), metavariableNode = metavariableNodeQuery(frameNode);
|
|
45
|
+
if (metavariableNode !== null) {
|
|
46
|
+
var substitution = substitutions.findSubstitution(function(substitution) {
|
|
47
|
+
var metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
|
|
48
|
+
if (metavariableNodeMatches) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (substitution !== null) {
|
|
53
|
+
frame = substitution.getTerm();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return frame;
|
|
58
|
+
}
|
|
59
|
+
function statementFromStatementAndSubstitutions(statement, substitutions) {
|
|
60
|
+
if (statement !== null) {
|
|
61
|
+
var statementNode = statement.getNode(), metavariableNode = metavariableNodeQuery(statementNode);
|
|
62
|
+
if (metavariableNode !== null) {
|
|
63
|
+
var substitution = substitutions.findSubstitution(function(substitution) {
|
|
64
|
+
var metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
|
|
65
|
+
if (metavariableNodeMatches) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (substitution !== null) {
|
|
70
|
+
statement = substitution.getStatement();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return statement;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsaXRpZXMvc3Vic3RpdHV0aW9ucy5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcblxuaW1wb3J0IHsgbm9kZVF1ZXJ5IH0gZnJvbSBcIi4uL3V0aWxpdGllcy9xdWVyeVwiO1xuaW1wb3J0IHsgdmFyaWFibGVOYW1lRnJvbVZhcmlhYmxlTm9kZSB9IGZyb20gXCIuLi91dGlsaXRpZXMvbmFtZVwiO1xuXG5jb25zdCB2YXJpYWJsZU5vZGVRdWVyeSA9IG5vZGVRdWVyeShcIi90ZXJtL3ZhcmlhYmxlIVwiKSxcbiAgICAgIG1ldGF2YXJpYWJsZU5vZGVRdWVyeSA9IG5vZGVRdWVyeShcIi8qL21ldGF2YXJpYWJsZSFcIik7XG5cbmV4cG9ydCBmdW5jdGlvbiB0ZXJtRnJvbVRlcm1BbmRTdWJzdGl0dXRpb25zKHRlcm0sIHN1YnN0aXR1dGlvbnMpIHtcbiAgaWYgKHRlcm0gIT09IG51bGwpIHtcbiAgICBjb25zdCB0ZXJtTm9kZSA9IHRlcm0uZ2V0Tm9kZSgpLFxuICAgICAgICAgIHZhcmlhYmxlTm9kZSA9IHZhcmlhYmxlTm9kZ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FTyxTQUFTakIsdUNBQXVDc0IsU0FBUyxFQUFFaEIsYUFBYTtJQUM3RSxJQUFJZ0IsY0FBYyxNQUFNO1FBQ3RCLElBQU1DLGdCQUFnQkQsVUFBVWQsT0FBTyxJQUNqQ1csbUJBQW1CZixzQkFBc0JtQjtRQUUvQyxJQUFJSixxQkFBcUIsTUFBTTtZQUM3QixJQUFNUCxlQUFlTixjQUFjTyxnQkFBZ0IsQ0FBQyxTQUFDRDtnQkFDbkQsSUFBTVEsMEJBQTBCUixhQUFhUyxxQkFBcUIsQ0FBQ0Y7Z0JBRW5FLElBQUlDLHlCQUF5QjtvQkFDM0IsT0FBTztnQkFDVDtZQUNGO1lBRUEsSUFBSVIsaUJBQWlCLE1BQU07Z0JBQ3pCVSxZQUFZVixhQUFhWSxZQUFZO1lBQ3ZDO1FBQ0Y7SUFDRjtJQUVBLE9BQU9GO0FBQ1QifQ==
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import shim from "../shim";
|
|
4
4
|
|
|
5
5
|
import { isAssertionNegated } from "../utilities/assertion";
|
|
6
|
+
import { termFromTermAndSubstitutions, frameFromFrameAndSubstitutions, statementFromStatementAndSubstitutions } from "../utilities/substitutions";
|
|
6
7
|
|
|
7
8
|
export default class ContainedAssertion {
|
|
8
9
|
constructor(string, node, term, frame, negated, statement) {
|
|
@@ -38,6 +39,27 @@ export default class ContainedAssertion {
|
|
|
38
39
|
return this.statement;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
resolve(substitutions, localContext) {
|
|
43
|
+
let resolved;
|
|
44
|
+
|
|
45
|
+
const containedAssertionString = this.string; ///
|
|
46
|
+
|
|
47
|
+
localContext.trace(`Resolving the '${containedAssertionString}' contained assertion...`);
|
|
48
|
+
|
|
49
|
+
const term = termFromTermAndSubstitutions(this.term, substitutions),
|
|
50
|
+
frame = frameFromFrameAndSubstitutions(this.frame, substitutions),
|
|
51
|
+
statement = statementFromStatementAndSubstitutions(this.statement, substitutions),
|
|
52
|
+
verifiedWhenDerived = verifyWhenDerived(term, frame, statement, this.negated, localContext);
|
|
53
|
+
|
|
54
|
+
resolved = verifiedWhenDerived; ///
|
|
55
|
+
|
|
56
|
+
if (resolved) {
|
|
57
|
+
localContext.debug(`...resolved the '${containedAssertionString}' contained assertion.`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return resolved;
|
|
61
|
+
}
|
|
62
|
+
|
|
41
63
|
verify(assignments, stated, localContext) {
|
|
42
64
|
let verified = false;
|
|
43
65
|
|
|
@@ -108,43 +130,13 @@ export default class ContainedAssertion {
|
|
|
108
130
|
}
|
|
109
131
|
|
|
110
132
|
verifyWhenDerived(localContext) {
|
|
111
|
-
let verifiedWhenDerived
|
|
133
|
+
let verifiedWhenDerived;
|
|
112
134
|
|
|
113
135
|
const containedAssertionString = this.string; ///
|
|
114
136
|
|
|
115
137
|
localContext.trace(`Verifying the '${containedAssertionString}' derived contained assertion...`);
|
|
116
138
|
|
|
117
|
-
|
|
118
|
-
const variable = this.term.getVariable(localContext);
|
|
119
|
-
|
|
120
|
-
if (variable !== null) {
|
|
121
|
-
const variableContained = this.statement.isVariableContained(variable, localContext);
|
|
122
|
-
|
|
123
|
-
if (!this.negated && variableContained) {
|
|
124
|
-
verifiedWhenDerived = true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (this.negated && !variableContained) {
|
|
128
|
-
verifiedWhenDerived = true;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (this.frame !== null) {
|
|
134
|
-
const metavariable = this.frame.getVariable(localContext);
|
|
135
|
-
|
|
136
|
-
if (metavariable !== null) {
|
|
137
|
-
const metavariableContained = this.statement.isMetavariableContained(metavariable, localContext);
|
|
138
|
-
|
|
139
|
-
if (!this.negated && metavariableContained) {
|
|
140
|
-
verifiedWhenDerived = true;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (this.negated && !metavariableContained) {
|
|
144
|
-
verifiedWhenDerived = true;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
139
|
+
verifiedWhenDerived = verifyWhenDerived(this.term, this.frame, this.statement, this.negated, localContext);
|
|
148
140
|
|
|
149
141
|
if (verifiedWhenDerived) {
|
|
150
142
|
localContext.debug(`...verified the '${containedAssertionString}' derived contained assertion.`);
|
|
@@ -172,3 +164,41 @@ export default class ContainedAssertion {
|
|
|
172
164
|
return containedAssertion;
|
|
173
165
|
}
|
|
174
166
|
}
|
|
167
|
+
|
|
168
|
+
function verifyWhenDerived(term, frame, statement, negated, localContext) {
|
|
169
|
+
let verifiedWhenDerived = false;
|
|
170
|
+
|
|
171
|
+
if (term !== null) {
|
|
172
|
+
const variable = term.getVariable(localContext);
|
|
173
|
+
|
|
174
|
+
if (variable !== null) {
|
|
175
|
+
const variableContained = statement.isVariableContained(variable, localContext);
|
|
176
|
+
|
|
177
|
+
if (!negated && variableContained) {
|
|
178
|
+
verifiedWhenDerived = true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (negated && !variableContained) {
|
|
182
|
+
verifiedWhenDerived = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (frame !== null) {
|
|
188
|
+
const metavariable = frame.getMetavariable(localContext);
|
|
189
|
+
|
|
190
|
+
if (metavariable !== null) {
|
|
191
|
+
const metavariableContained = statement.isMetavariableContained(metavariable, localContext);
|
|
192
|
+
|
|
193
|
+
if (!negated && metavariableContained) {
|
|
194
|
+
verifiedWhenDerived = true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (negated && !metavariableContained) {
|
|
198
|
+
verifiedWhenDerived = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return verifiedWhenDerived;
|
|
204
|
+
}
|
package/src/assertion/defined.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import shim from "../shim";
|
|
4
4
|
|
|
5
|
+
import { nodeQuery } from "../utilities/query";
|
|
5
6
|
import { isAssertionNegated } from "../utilities/assertion";
|
|
7
|
+
import { variableNameFromVariableNode } from "../utilities/name";
|
|
8
|
+
import { termFromTermAndSubstitutions, frameFromFrameAndSubstitutions } from "../utilities/substitutions";
|
|
9
|
+
|
|
10
|
+
const variableNodeQuery = nodeQuery("/term/variable!"),
|
|
11
|
+
metavariableNodeQuery = nodeQuery("/frame/metavariable!");
|
|
6
12
|
|
|
7
13
|
export default class DefinedAssertion {
|
|
8
14
|
constructor(string, node, term, frame, negated) {
|
|
@@ -33,6 +39,26 @@ export default class DefinedAssertion {
|
|
|
33
39
|
return this.negated;
|
|
34
40
|
}
|
|
35
41
|
|
|
42
|
+
resolve(substitutions, localContext) {
|
|
43
|
+
let resolved;
|
|
44
|
+
|
|
45
|
+
const definedAssertionString = this.string; ///
|
|
46
|
+
|
|
47
|
+
localContext.trace(`Resolving the '${definedAssertionString}' defined assertion...`);
|
|
48
|
+
|
|
49
|
+
const term = termFromTermAndSubstitutions(this.term, substitutions),
|
|
50
|
+
frame = frameFromFrameAndSubstitutions(this.frame, substitutions),
|
|
51
|
+
verifiedWhenDerived = verifyWhenDerived(term, frame, this.negated, localContext);
|
|
52
|
+
|
|
53
|
+
resolved = verifiedWhenDerived; ///
|
|
54
|
+
|
|
55
|
+
if (resolved) {
|
|
56
|
+
localContext.debug(`...resolved the '${definedAssertionString}' defined assertion.`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return resolved;
|
|
60
|
+
}
|
|
61
|
+
|
|
36
62
|
verify(assignments, stated, localContext) {
|
|
37
63
|
let verified = false;
|
|
38
64
|
|
|
@@ -98,43 +124,13 @@ export default class DefinedAssertion {
|
|
|
98
124
|
}
|
|
99
125
|
|
|
100
126
|
verifyWhenDerived(localContext) {
|
|
101
|
-
let verifiedWhenDerived
|
|
127
|
+
let verifiedWhenDerived;
|
|
102
128
|
|
|
103
129
|
const definedAssertionString = this.string; ///
|
|
104
130
|
|
|
105
131
|
localContext.trace(`Verifying the '${definedAssertionString}' derived defined assertion...`);
|
|
106
132
|
|
|
107
|
-
|
|
108
|
-
const { Variable } = shim,
|
|
109
|
-
termNode = this.term.getNode(),
|
|
110
|
-
variable = Variable.fromTermNode(termNode, localContext),
|
|
111
|
-
variableDefined = localContext.isVariableDefined(variable);
|
|
112
|
-
|
|
113
|
-
if (!this.negated && variableDefined) {
|
|
114
|
-
verifiedWhenDerived = true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (this.negated && !variableDefined) {
|
|
118
|
-
verifiedWhenDerived = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (this.frame!== null) {
|
|
123
|
-
debugger
|
|
124
|
-
|
|
125
|
-
const { Metavariable } = shim,
|
|
126
|
-
frameNode = this.frame.getNode(),
|
|
127
|
-
metavariable = Metavariable.fromTermNode(frameNode, localContext),
|
|
128
|
-
metavariableDefined = localContext.isMetametavariableDefined(metavariable);
|
|
129
|
-
|
|
130
|
-
if (!this.negated && metavariableDefined) {
|
|
131
|
-
verifiedWhenDerived = true;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (this.negated && !metavariableDefined) {
|
|
135
|
-
verifiedWhenDerived = true;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
133
|
+
verifiedWhenDerived = verifyWhenDerived(this.term, this.frame, this.negated, localContext);
|
|
138
134
|
|
|
139
135
|
if (verifiedWhenDerived) {
|
|
140
136
|
localContext.debug(`...verified the '${definedAssertionString}' derived defined assertion.`);
|
|
@@ -161,3 +157,38 @@ export default class DefinedAssertion {
|
|
|
161
157
|
return definedAssertion;
|
|
162
158
|
}
|
|
163
159
|
}
|
|
160
|
+
|
|
161
|
+
function verifyWhenDerived(term, frame, negated, localContext) {
|
|
162
|
+
let verifiedWhenDerived = false;
|
|
163
|
+
|
|
164
|
+
if (term !== null) {
|
|
165
|
+
const termNode = term.getNode(),
|
|
166
|
+
variableNode = variableNodeQuery(termNode),
|
|
167
|
+
variableName = variableNameFromVariableNode(variableNode),
|
|
168
|
+
variableDefined = localContext.isVariableDefinedByVariableName(variableName);
|
|
169
|
+
|
|
170
|
+
if (!negated && variableDefined) {
|
|
171
|
+
verifiedWhenDerived = true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (negated && !variableDefined) {
|
|
175
|
+
verifiedWhenDerived = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (frame!== null) {
|
|
180
|
+
const frameNode = frame.getNode(),
|
|
181
|
+
metavariableNode = metavariableNodeQuery(frameNode),
|
|
182
|
+
metavariableDefined = localContext.isJudgementPresentByMetavariableNode(metavariableNode);
|
|
183
|
+
|
|
184
|
+
if (!negated && metavariableDefined) {
|
|
185
|
+
verifiedWhenDerived = true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (negated && !metavariableDefined) {
|
|
189
|
+
verifiedWhenDerived = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return verifiedWhenDerived;
|
|
194
|
+
}
|
package/src/context/local.js
CHANGED
|
@@ -250,7 +250,7 @@ class LocalContext {
|
|
|
250
250
|
return termGrounded;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
|
|
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
|
|
262
|
+
const definedVariableName = definedVariable.getName();
|
|
263
263
|
|
|
264
|
-
if (
|
|
264
|
+
if (definedVariableName === variableName) {
|
|
265
265
|
return true;
|
|
266
266
|
}
|
|
267
267
|
}),
|
package/src/equality.js
CHANGED
|
@@ -50,8 +50,9 @@ class Equality {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
isReflexive() {
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
const rightTermNode = this.rightTerm.getNode(),
|
|
54
|
+
leftTermNodeMatchesRightTermNode = this.leftTerm.matchTermNode(rightTermNode),
|
|
55
|
+
reflexive = leftTermNodeMatchesRightTermNode; ///
|
|
55
56
|
|
|
56
57
|
return reflexive;
|
|
57
58
|
}
|
package/src/equivalence.js
CHANGED
|
@@ -56,30 +56,18 @@ export default class Equivalence {
|
|
|
56
56
|
return typeMatches;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
equateTerm(term) {
|
|
60
60
|
const termA = term, ///
|
|
61
|
-
|
|
61
|
+
termEquates = this.terms.some((term) => {
|
|
62
62
|
const termB = term, ///
|
|
63
|
-
|
|
63
|
+
termAEqualToTermB = termA.isEqualTo(termB);
|
|
64
64
|
|
|
65
|
-
if (
|
|
65
|
+
if (termAEqualToTermB) {
|
|
66
66
|
return true;
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
return
|
|
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);
|
|
@@ -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;
|
package/src/premise.js
CHANGED
|
@@ -28,6 +28,30 @@ class Premise {
|
|
|
28
28
|
|
|
29
29
|
getStatement() { return this.unqualifiedStatement.getStatement(); }
|
|
30
30
|
|
|
31
|
+
resolveIndependently(substitutions, localContext) {
|
|
32
|
+
let resolvedIndependently;
|
|
33
|
+
|
|
34
|
+
const premiseString = this.getString();
|
|
35
|
+
|
|
36
|
+
const localContextB = localContext; ///
|
|
37
|
+
|
|
38
|
+
localContext = LocalContext.fromFileContext(this.fileContext);
|
|
39
|
+
|
|
40
|
+
const localContextA = localContext; ///
|
|
41
|
+
|
|
42
|
+
localContextB.trace(`Resolving the '${premiseString}' premise independently...`);
|
|
43
|
+
|
|
44
|
+
const unqualifiedStatementResolvedIndependently = this.unqualifiedStatement.resolveIndependently(substitutions, localContextA, localContextB);
|
|
45
|
+
|
|
46
|
+
resolvedIndependently = unqualifiedStatementResolvedIndependently; ///
|
|
47
|
+
|
|
48
|
+
if (resolvedIndependently) {
|
|
49
|
+
localContextB.trace(`...resolved the '${premiseString}' premise independently.`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return resolvedIndependently;
|
|
53
|
+
}
|
|
54
|
+
|
|
31
55
|
unifyProofStep(proofStep, substitutions, localContext) {
|
|
32
56
|
let proofStepUnified = false;
|
|
33
57
|
|
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"),
|
|
@@ -71,15 +71,13 @@ class Rule {
|
|
|
71
71
|
let statementUnified;
|
|
72
72
|
|
|
73
73
|
const { Substitutions } = shim,
|
|
74
|
-
substitutions = Substitutions.fromNothing()
|
|
74
|
+
substitutions = Substitutions.fromNothing(),
|
|
75
|
+
conclusionUnified = this.unifyConclusion(statement, substitutions, localContext);
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
if (conclusionUnified) {
|
|
78
|
+
const premisesUnified = this.unifyPremises(substitutions, localContext);
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
const proofSteps = localContext.getProofSteps(),
|
|
80
|
-
proofStepsUnified = this.unifyProofSteps(proofSteps, substitutions, localContext);
|
|
81
|
-
|
|
82
|
-
if (proofStepsUnified) {
|
|
80
|
+
if (premisesUnified) {
|
|
83
81
|
const substitutionsResolved = substitutions.areResolved();
|
|
84
82
|
|
|
85
83
|
statementUnified = substitutionsResolved; ///
|
|
@@ -89,24 +87,70 @@ class Rule {
|
|
|
89
87
|
return statementUnified;
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
let
|
|
90
|
+
unifyConclusion(statement, substitutions, localContext) {
|
|
91
|
+
let conclusionUnified;
|
|
92
|
+
|
|
93
|
+
const conclusionString = this.conclusion.getString();
|
|
94
|
+
|
|
95
|
+
localContext.trace(`Unifying the '${conclusionString}' conclusion...`);
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
const statementUnified = this.conclusion.unifyStatement(statement, substitutions, localContext); ///
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
conclusionUnified = statementUnified; ///
|
|
100
|
+
|
|
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();
|
|
98
110
|
|
|
99
111
|
proofSteps = reverse(proofSteps); ///
|
|
100
112
|
|
|
101
|
-
|
|
102
|
-
const
|
|
113
|
+
const premisesUnified = backwardsEvery(this.premises, (premise) => {
|
|
114
|
+
const premiseUnified = this.unifyPremise(premise, proofSteps, substitutions, localContext);
|
|
103
115
|
|
|
104
|
-
if (
|
|
116
|
+
if (premiseUnified) {
|
|
105
117
|
return true;
|
|
106
118
|
}
|
|
107
119
|
});
|
|
108
120
|
|
|
109
|
-
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;
|
|
110
154
|
}
|
|
111
155
|
|
|
112
156
|
verify() {
|
|
@@ -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
|
|