occam-verify-cli 0.0.842 → 0.0.844
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/context/file.js +8 -1
- package/lib/context/local.js +22 -21
- package/lib/equivalence.js +24 -14
- package/lib/log.js +2 -2
- package/lib/substitution/statementForMetavariable.js +67 -10
- package/lib/substitution/termForVariable.js +56 -1
- package/lib/term.js +22 -17
- package/lib/utilities/array.js +11 -1
- package/lib/utilities/equivalences.js +83 -67
- package/lib/verifier/nodes/metaLevelToIntrinsicLevel.js +69 -18
- package/lib/verify/defining.js +41 -13
- package/package.json +1 -1
- package/src/context/file.js +6 -0
- package/src/context/local.js +29 -41
- package/src/equivalence.js +26 -14
- package/src/log.js +3 -1
- package/src/substitution/statementForMetavariable.js +70 -6
- package/src/substitution/termForVariable.js +77 -1
- package/src/term.js +29 -23
- package/src/utilities/array.js +6 -0
- package/src/utilities/equivalences.js +114 -67
- package/src/verifier/nodes/metaLevelToIntrinsicLevel.js +44 -26
- package/src/verify/defining.js +49 -14
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { push,
|
|
3
|
+
import { push, compress, separate } from "../utilities/array";
|
|
4
|
+
|
|
5
|
+
export function mergeEquivalences(equivalencesA, equivalencesB, localContext) {
|
|
6
|
+
const typesA = typesFromEquivalences(equivalencesA, localContext),
|
|
7
|
+
typesB = typesFromEquivalences(equivalencesB, localContext),
|
|
8
|
+
types = [
|
|
9
|
+
...typesA,
|
|
10
|
+
...typesB
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
compress(types, (typeA, typeB) => {
|
|
14
|
+
if (typeA === typeB) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const equivalences = types.map((type) => {
|
|
20
|
+
let equivalence;
|
|
21
|
+
|
|
22
|
+
const equivalenceA = findEquivalenceByType(equivalencesA, type, localContext),
|
|
23
|
+
equivalenceB = findEquivalenceByType(equivalencesB, type, localContext);
|
|
24
|
+
|
|
25
|
+
if ((equivalenceA !== null) && (equivalenceB !== null)) {
|
|
26
|
+
const leftEquivalence = equivalenceA, ///
|
|
27
|
+
rightEquivalence = equivalenceB; ///
|
|
28
|
+
|
|
29
|
+
equivalence = Equivalence.merge(leftEquivalence, rightEquivalence);
|
|
30
|
+
} else if (equivalenceA !== null) {
|
|
31
|
+
equivalence = equivalenceA; ///
|
|
32
|
+
} else if (equivalenceB !== null) {
|
|
33
|
+
equivalence = equivalenceB; ///
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return equivalence;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return equivalences;
|
|
40
|
+
}
|
|
4
41
|
|
|
5
42
|
export function areTermNodesEqual(leftTermNode, rightTermNode, equivalences) {
|
|
6
43
|
let termNodesEqual;
|
|
@@ -46,87 +83,62 @@ export function findEquivalenceByTerm(equivalences, term) {
|
|
|
46
83
|
return equivalence;
|
|
47
84
|
}
|
|
48
85
|
|
|
49
|
-
export function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
...typesB
|
|
55
|
-
];
|
|
86
|
+
export function groundedTermsAndDefinedVariablesFromFromEquivalences(equivalences, groundedTerms, definedVariables, context) {
|
|
87
|
+
let groundedEquivalences,
|
|
88
|
+
remainingEquivalences,
|
|
89
|
+
initiallyGroundedEquivalences,
|
|
90
|
+
implicitlyGroundedEquivalences;
|
|
56
91
|
|
|
57
|
-
|
|
58
|
-
if (typeA === typeB) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
92
|
+
remainingEquivalences = [];
|
|
62
93
|
|
|
63
|
-
|
|
64
|
-
let equivalence;
|
|
94
|
+
initiallyGroundedEquivalences = [];
|
|
65
95
|
|
|
66
|
-
|
|
67
|
-
equivalenceB = findEquivalenceByType(equivalencesB, type, localContext);
|
|
96
|
+
separateInitiallyGroundedEquivalences(equivalences, remainingEquivalences, initiallyGroundedEquivalences, context);
|
|
68
97
|
|
|
69
|
-
|
|
70
|
-
const leftEquivalence = equivalenceA, ///
|
|
71
|
-
rightEquivalence = equivalenceB; ///
|
|
98
|
+
const initiallyGroundedEquivalencesLength = initiallyGroundedEquivalences.length;
|
|
72
99
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
equivalence = equivalenceA; ///
|
|
76
|
-
} else if (equivalenceB !== null) {
|
|
77
|
-
equivalence = equivalenceB; ///
|
|
78
|
-
}
|
|
100
|
+
if (initiallyGroundedEquivalencesLength > 0) {
|
|
101
|
+
groundedEquivalences = initiallyGroundedEquivalences; ///
|
|
79
102
|
|
|
80
|
-
|
|
81
|
-
});
|
|
103
|
+
let implicitlyGroundedEquivalencesLength = 1;
|
|
82
104
|
|
|
83
|
-
|
|
84
|
-
|
|
105
|
+
while (implicitlyGroundedEquivalencesLength > 0) {
|
|
106
|
+
let definedVariablesLength = 0,
|
|
107
|
+
previousDefinedVariablesLength = -1;
|
|
85
108
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const equivalenceInitiallyGrounded = equivalence.isInitiallyGrounded();
|
|
109
|
+
while (definedVariablesLength > previousDefinedVariablesLength) {
|
|
110
|
+
previousDefinedVariablesLength = definedVariablesLength; ///
|
|
89
111
|
|
|
90
|
-
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
112
|
+
groundedTermsFromGroundedEquivalencesAndDefinedVariables(groundedEquivalences, definedVariables, groundedTerms, context);
|
|
95
113
|
|
|
96
|
-
|
|
97
|
-
compress(definedVariables, (definedVariableA, definedVariableB) => {
|
|
98
|
-
if (definedVariableA === definedVariableB) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
114
|
+
definedVariablesFromGroundedTerms(groundedTerms, definedVariables, context);
|
|
103
115
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const variables = groundedEquivalence.getVariables(context);
|
|
116
|
+
definedVariablesLength = definedVariables.length;
|
|
117
|
+
}
|
|
107
118
|
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
}
|
|
119
|
+
equivalences = remainingEquivalences; ///
|
|
111
120
|
|
|
112
|
-
|
|
113
|
-
const implicitlyGroundedEquivalences = [];
|
|
121
|
+
remainingEquivalences = [];
|
|
114
122
|
|
|
115
|
-
|
|
116
|
-
const remainingEquivalenceImplicitlyGrounded = remainingEquivalence.isImplicitlyGrounded(definedVariables);
|
|
123
|
+
implicitlyGroundedEquivalences = [];
|
|
117
124
|
|
|
118
|
-
|
|
119
|
-
const implicitlyGroundedEquivalence = remainingEquivalence; ///
|
|
125
|
+
separateImplicitlyGroundedEquivalences(equivalences, remainingEquivalences, implicitlyGroundedEquivalences, definedVariables, context);
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
}
|
|
127
|
+
push(groundedEquivalences, implicitlyGroundedEquivalences);
|
|
123
128
|
|
|
124
|
-
|
|
125
|
-
return true;
|
|
129
|
+
implicitlyGroundedEquivalencesLength = implicitlyGroundedEquivalences.length; ///
|
|
126
130
|
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function typesFromEquivalences(equivalences, localContext) {
|
|
135
|
+
const types = equivalences.map((equivalence) => {
|
|
136
|
+
const type = equivalence.getType(localContext);
|
|
137
|
+
|
|
138
|
+
return type;
|
|
127
139
|
});
|
|
128
140
|
|
|
129
|
-
return
|
|
141
|
+
return types;
|
|
130
142
|
}
|
|
131
143
|
|
|
132
144
|
function findEquivalenceByTermNodes(equivalences, termNodes) {
|
|
@@ -141,12 +153,47 @@ function findEquivalenceByTermNodes(equivalences, termNodes) {
|
|
|
141
153
|
return equivalence;
|
|
142
154
|
}
|
|
143
155
|
|
|
144
|
-
function
|
|
145
|
-
const
|
|
146
|
-
|
|
156
|
+
function definedVariablesFromGroundedTerms(groundedTerms, definedVariables, context) {
|
|
157
|
+
const terms = groundedTerms, ///
|
|
158
|
+
variables = definedVariables; ///
|
|
147
159
|
|
|
148
|
-
|
|
160
|
+
terms.forEach((term) => {
|
|
161
|
+
const termVariables = term.getVariables(context);
|
|
162
|
+
|
|
163
|
+
termVariables.forEach((termVariable) => {
|
|
164
|
+
const variablesIncludesTermVariable = variables.includes(termVariable);
|
|
165
|
+
|
|
166
|
+
if (!variablesIncludesTermVariable) {
|
|
167
|
+
const variable = termVariable; ///
|
|
168
|
+
|
|
169
|
+
variables.push(variable);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
149
172
|
});
|
|
173
|
+
}
|
|
150
174
|
|
|
151
|
-
|
|
175
|
+
function separateInitiallyGroundedEquivalences(equivalences, remainingEquivalences, initiallyGroundedEquivalences, context) {
|
|
176
|
+
separate(equivalences, remainingEquivalences, initiallyGroundedEquivalences, (equivalence) => {
|
|
177
|
+
const equivalenceInitiallyGrounded = equivalence.isInitiallyGrounded(context);
|
|
178
|
+
|
|
179
|
+
if (!equivalenceInitiallyGrounded) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function separateImplicitlyGroundedEquivalences(equivalences, remainingEquivalences, implicitlyGroundedEquivalences, definedVariables, context) {
|
|
186
|
+
separate(equivalences, remainingEquivalences, implicitlyGroundedEquivalences, (equivalence) => {
|
|
187
|
+
const equivalenceImplicitlyGrounded = equivalence.isImplicitlyGrounded(definedVariables, context);
|
|
188
|
+
|
|
189
|
+
if (!equivalenceImplicitlyGrounded) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function groundedTermsFromGroundedEquivalencesAndDefinedVariables(groundedEquivalences, definedVariables, groundedTerms, context) {
|
|
196
|
+
groundedEquivalences.forEach((groundedEquivalence) => {
|
|
197
|
+
groundedEquivalence.getGroundedTerms(definedVariables, groundedTerms, context);
|
|
198
|
+
});
|
|
152
199
|
}
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import LocalContext from "../../context/local";
|
|
4
4
|
import NodesVerifier from "../../verifier/nodes";
|
|
5
|
+
import TermForVariableSubstitution from "../../substitution/termForVariable";
|
|
5
6
|
import intrinsicLevelNodesVerifierMixins from "../../mixins/nodesVerifier/intrinsiclevel";
|
|
6
7
|
import StatementForMetavariableSubstitution from "../../substitution/statementForMetavariable";
|
|
7
8
|
|
|
8
9
|
import { nodeQuery } from "../../utilities/query";
|
|
10
|
+
import { matchStatementNode } from "../../substitution/statementForMetavariable";
|
|
9
11
|
import { TERM_RULE_NAME, STATEMENT_RULE_NAME, METASTATEMENT_RULE_NAME, META_ARGUMENT_RULE_NAME } from "../../ruleNames";
|
|
10
12
|
|
|
11
|
-
const
|
|
12
|
-
variableNodeQuery = nodeQuery("/*/variable!"),
|
|
13
|
+
const variableNodeQuery = nodeQuery("/*/variable!"),
|
|
13
14
|
statementNodeQuery = nodeQuery("/metaArgument/statement"),
|
|
14
15
|
metavariableNodeQuery = nodeQuery("/metastatement/metavariable!"),
|
|
15
16
|
substitutionNodeQuery = nodeQuery("/metastatement/substitution!");
|
|
@@ -83,22 +84,8 @@ class MetaLevelToIntrinsicLevelNodesVerifier extends NodesVerifier {
|
|
|
83
84
|
metavariableNodeA = metavariableNodeQuery(metastatementNodeA);
|
|
84
85
|
|
|
85
86
|
if ((metavariableNodeA !== null) && (statementNodeB !== null)) {
|
|
86
|
-
const substitutionNodeA = substitutionNodeQuery(metastatementNodeA)
|
|
87
|
-
|
|
88
|
-
if (substitutionNodeA !== null) {
|
|
89
|
-
const variableNode = variableNodeQuery(substitutionNode),
|
|
90
|
-
variable = fileContextA.findVariableByVariableNode(variableNode);
|
|
91
|
-
|
|
92
|
-
if (variable !== null) {
|
|
93
|
-
const termNode = termNodeQuery(substitutionNode);
|
|
94
|
-
|
|
95
|
-
debugger
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const metavariableNodeVerified = this.verifyMetavariableNode(metavariableNodeA, statementNodeB, substitutions, fileContextA, localContextB, verifyAhead);
|
|
87
|
+
const substitutionNodeA = substitutionNodeQuery(metastatementNodeA),
|
|
88
|
+
metavariableNodeVerified = this.verifyMetavariableNode(metavariableNodeA, substitutionNodeA, statementNodeB, substitutions, fileContextA, localContextB, verifyAhead);
|
|
102
89
|
|
|
103
90
|
metaArgumentNodeVerified = metavariableNodeVerified; ///
|
|
104
91
|
}
|
|
@@ -106,7 +93,7 @@ class MetaLevelToIntrinsicLevelNodesVerifier extends NodesVerifier {
|
|
|
106
93
|
return metaArgumentNodeVerified;
|
|
107
94
|
}
|
|
108
95
|
|
|
109
|
-
verifyMetavariableNode(metavariableNodeA, statementNodeB, substitutions, fileContextA, localContextB, verifyAhead) {
|
|
96
|
+
verifyMetavariableNode(metavariableNodeA, substitutionNodeA, statementNodeB, substitutions, fileContextA, localContextB, verifyAhead) {
|
|
110
97
|
let metavariableNodeVerified;
|
|
111
98
|
|
|
112
99
|
const substitution = substitutions.find((substitution) => {
|
|
@@ -118,15 +105,28 @@ class MetaLevelToIntrinsicLevelNodesVerifier extends NodesVerifier {
|
|
|
118
105
|
}) || null;
|
|
119
106
|
|
|
120
107
|
if (substitution !== null) {
|
|
121
|
-
const statementNode =
|
|
122
|
-
|
|
108
|
+
const statementNode = substitution.getStatementNode(),
|
|
109
|
+
localContextA = LocalContext.fromFileContext(fileContextA);
|
|
123
110
|
|
|
124
|
-
|
|
111
|
+
if (substitutionNodeA !== null) {
|
|
112
|
+
const substitutionNode = substitutionNodeA, ///
|
|
113
|
+
termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionNode(substitutionNode),
|
|
114
|
+
substitution = termForVariableSubstitution, ///
|
|
115
|
+
statementNodeA = statementNode, ///
|
|
116
|
+
statementNodeMatches = matchStatementNode(statementNodeA, statementNodeB, substitution, substitutions, localContextA, localContextB);
|
|
117
|
+
|
|
118
|
+
metavariableNodeVerified = statementNodeMatches; ///
|
|
119
|
+
} else {
|
|
120
|
+
const statementNode = statementNodeB, ///
|
|
121
|
+
statementNodeMatches = substitution.matchStatementNode(statementNode, substitutions, localContextA, localContextB);
|
|
122
|
+
|
|
123
|
+
metavariableNodeVerified = statementNodeMatches; ///
|
|
124
|
+
}
|
|
125
125
|
} else {
|
|
126
|
-
const
|
|
126
|
+
const substitutionNode = substitutionNodeA, ///
|
|
127
|
+
metavariableNode = metavariableNodeA, ///
|
|
127
128
|
statementNode = statementNodeB, ///
|
|
128
|
-
|
|
129
|
-
substitution = statementForMetavariableSubstitution; ///
|
|
129
|
+
substitution = substitutionFromSubstitutionNodeMetavariableNodeAndStatementNode(substitutionNode, metavariableNode, statementNode);
|
|
130
130
|
|
|
131
131
|
substitutions.push(substitution);
|
|
132
132
|
|
|
@@ -142,7 +142,8 @@ class MetaLevelToIntrinsicLevelNodesVerifier extends NodesVerifier {
|
|
|
142
142
|
const metavariableNodeA = metavariableNodeQuery(metastatementNodeA);
|
|
143
143
|
|
|
144
144
|
if (metavariableNodeA !== null) {
|
|
145
|
-
const
|
|
145
|
+
const substitutionNodeA = null, ///
|
|
146
|
+
metavariableNodeVerified = this.verifyMetavariableNode(metavariableNodeA, substitutionNodeA, statementNodeB, substitutions, fileContextA, localContextB, verifyAhead);
|
|
146
147
|
|
|
147
148
|
statementNodeVerified = metavariableNodeVerified; ///
|
|
148
149
|
} else {
|
|
@@ -194,3 +195,20 @@ Object.assign(MetaLevelToIntrinsicLevelNodesVerifier.prototype, intrinsicLevelNo
|
|
|
194
195
|
const metaLevelToIntrinsicLevelNodesVerifier = new MetaLevelToIntrinsicLevelNodesVerifier();
|
|
195
196
|
|
|
196
197
|
export default metaLevelToIntrinsicLevelNodesVerifier;
|
|
198
|
+
|
|
199
|
+
function substitutionFromSubstitutionNodeMetavariableNodeAndStatementNode(substitutionNode, metavariableNode, statementNode) {
|
|
200
|
+
let statementForMetavariableSubstitution;
|
|
201
|
+
|
|
202
|
+
if (substitutionNode !== null) {
|
|
203
|
+
const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionNode(substitutionNode),
|
|
204
|
+
substitution = termForVariableSubstitution; ///
|
|
205
|
+
|
|
206
|
+
statementForMetavariableSubstitution = StatementForMetavariableSubstitution.fromMetavariableNodeStatementNodeAndSubstitution(metavariableNode, statementNode, substitution);
|
|
207
|
+
} else {
|
|
208
|
+
statementForMetavariableSubstitution = StatementForMetavariableSubstitution.fromMetavariableNodeAndStatementNode(metavariableNode, statementNode);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const substitution = statementForMetavariableSubstitution; ///
|
|
212
|
+
|
|
213
|
+
return substitution;
|
|
214
|
+
}
|
package/src/verify/defining.js
CHANGED
|
@@ -1,32 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import verifyTerm from "./term";
|
|
4
|
+
|
|
4
5
|
import { DEFINED } from "../constants";
|
|
5
6
|
import { nodeQuery } from "../utilities/query";
|
|
7
|
+
import { first, second } from "../utilities/array";
|
|
6
8
|
|
|
7
|
-
const
|
|
9
|
+
const termNodeQuery = nodeQuery("/argument/term!"),
|
|
10
|
+
variableNodeQuery = nodeQuery("/argument/term/variable!");
|
|
8
11
|
|
|
9
12
|
export default function verifyDefining(argumentNode, definingNode, context) {
|
|
10
13
|
let definingVerified = false;
|
|
11
14
|
|
|
12
|
-
const
|
|
15
|
+
const defined = definedFromDefiningNode(definingNode),
|
|
16
|
+
termNode = termNodeQuery(argumentNode),
|
|
17
|
+
variableNode = variableNodeQuery(argumentNode);
|
|
18
|
+
|
|
19
|
+
if (false) {
|
|
20
|
+
///
|
|
21
|
+
} else if (variableNode !== null) {
|
|
22
|
+
const variable = context.findVariableByVariableNode(variableNode);
|
|
13
23
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
variableNode = definedVariableNode, ///
|
|
17
|
-
variableDefined = context.isVariableDefined(variableNode);
|
|
24
|
+
if (variable !== null) {
|
|
25
|
+
const variableDefined = context.isVariableDefined(variable);
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
if (defined) {
|
|
28
|
+
if (variableDefined) {
|
|
29
|
+
definingVerified = true;
|
|
30
|
+
}
|
|
22
31
|
}
|
|
23
|
-
}
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
if (!defined) {
|
|
34
|
+
if (!variableDefined) {
|
|
35
|
+
definingVerified = true;
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
}
|
|
39
|
+
} else if (termNode !== null) {
|
|
40
|
+
const terms = [],
|
|
41
|
+
termVerified = verifyTerm(termNode, terms, context, () => {
|
|
42
|
+
let verifiedAhead;
|
|
43
|
+
|
|
44
|
+
const firstTerm = first(terms),
|
|
45
|
+
term = firstTerm, ///
|
|
46
|
+
termGrounded = context.isTermGrounded(term);
|
|
47
|
+
|
|
48
|
+
if (defined) {
|
|
49
|
+
if (termGrounded) {
|
|
50
|
+
verifiedAhead = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!defined) {
|
|
55
|
+
if (!termGrounded) {
|
|
56
|
+
verifiedAhead = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return verifiedAhead;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
definingVerified = termVerified; ///
|
|
64
|
+
|
|
30
65
|
}
|
|
31
66
|
|
|
32
67
|
return definingVerified;
|