occam-verify-cli 0.0.501 → 0.0.503
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/axiom.js +4 -4
- package/lib/axiomLemmaTheorem.js +58 -58
- package/lib/consequence.js +157 -0
- package/lib/lemma.js +4 -4
- package/lib/metaSupposition.js +214 -0
- package/lib/supposition.js +214 -0
- package/lib/theorem.js +4 -4
- package/lib/verify/axiom.js +11 -11
- package/lib/verify/consequence.js +35 -0
- package/lib/verify/derivation.js +7 -7
- package/lib/verify/lemma.js +12 -12
- package/lib/verify/metaDerivation.js +7 -7
- package/lib/verify/metaSupposition.js +41 -0
- package/lib/verify/supposition.js +41 -0
- package/lib/verify/theorem.js +12 -12
- package/package.json +3 -3
- package/src/axiom.js +1 -1
- package/src/axiomLemmaTheorem.js +57 -57
- package/src/consequence.js +187 -0
- package/src/lemma.js +1 -1
- package/src/metaSupposition.js +235 -0
- package/src/supposition.js +235 -0
- package/src/theorem.js +1 -1
- package/src/verify/axiom.js +17 -17
- package/src/verify/consequence.js +34 -0
- package/src/verify/derivation.js +8 -8
- package/src/verify/lemma.js +18 -18
- package/src/verify/metaDerivation.js +8 -8
- package/src/verify/metaSupposition.js +44 -0
- package/src/verify/supposition.js +44 -0
- package/src/verify/theorem.js +18 -18
- package/lib/antecedent.js +0 -214
- package/lib/consequent.js +0 -157
- package/lib/metaAntecedent.js +0 -214
- package/lib/verify/antecedent.js +0 -41
- package/lib/verify/consequent.js +0 -35
- package/lib/verify/metaAntecedent.js +0 -41
- package/src/antecedent.js +0 -235
- package/src/consequent.js +0 -187
- package/src/metaAntecedent.js +0 -235
- package/src/verify/antecedent.js +0 -44
- package/src/verify/consequent.js +0 -34
- package/src/verify/metaAntecedent.js +0 -44
package/src/axiomLemmaTheorem.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Label from "./label";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import Consequence from "./consequence";
|
|
5
|
+
import Supposition from "./supposition";
|
|
6
6
|
|
|
7
7
|
import { prune } from "./utilities/array";
|
|
8
8
|
import { someSubArray } from "./utilities/array";
|
|
9
9
|
|
|
10
10
|
export default class AxiomLemmaTheorem {
|
|
11
|
-
constructor(labels,
|
|
11
|
+
constructor(labels, suppositions, consequence) {
|
|
12
12
|
this.labels = labels;
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
13
|
+
this.suppositions = suppositions;
|
|
14
|
+
this.consequence = consequence;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
getLabels() {
|
|
18
18
|
return this.labels;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
return this.
|
|
21
|
+
getSuppositions() {
|
|
22
|
+
return this.suppositions;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
return this.
|
|
25
|
+
getConsequence() {
|
|
26
|
+
return this.consequence;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
matchLabelName(labelName) {
|
|
@@ -42,20 +42,20 @@ export default class AxiomLemmaTheorem {
|
|
|
42
42
|
matchStatement(statementNode, proofContext) {
|
|
43
43
|
let statementNatches;
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const suppositionsLength = this.suppositions.length;
|
|
46
46
|
|
|
47
|
-
if (
|
|
47
|
+
if (suppositionsLength === 0) {
|
|
48
48
|
const substitutions = [],
|
|
49
|
-
|
|
49
|
+
consequenceMatches = matchConsequence(this.consequence, statementNode, substitutions);
|
|
50
50
|
|
|
51
|
-
statementNatches =
|
|
51
|
+
statementNatches = consequenceMatches; ///
|
|
52
52
|
} else {
|
|
53
53
|
const proofSteps = proofContext.getProofSteps();
|
|
54
54
|
|
|
55
|
-
statementNatches = someSubArray(proofSteps,
|
|
56
|
-
const
|
|
55
|
+
statementNatches = someSubArray(proofSteps, suppositionsLength, (proofSteps) => {
|
|
56
|
+
const suppositionsMatchConsequence = matchSuppositionsAndConsequence(this.suppositions, this.consequence, proofSteps, statementNode);
|
|
57
57
|
|
|
58
|
-
if (
|
|
58
|
+
if (suppositionsMatchConsequence) {
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
});
|
|
@@ -71,20 +71,20 @@ export default class AxiomLemmaTheorem {
|
|
|
71
71
|
|
|
72
72
|
return labelJSON;
|
|
73
73
|
}),
|
|
74
|
-
|
|
75
|
-
const
|
|
74
|
+
suppositionsJSON = this.suppositions.map((supposition) => {
|
|
75
|
+
const suppositionJSON = supposition.toJSON();
|
|
76
76
|
|
|
77
|
-
return
|
|
77
|
+
return suppositionJSON;
|
|
78
78
|
}),
|
|
79
|
-
|
|
79
|
+
consequenceJSON = this.consequence.toJSON(),
|
|
80
80
|
labels = labelsJSON, ///
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
suppositions = suppositionsJSON, ///
|
|
82
|
+
consequence = consequenceJSON, ///
|
|
83
83
|
json = {
|
|
84
84
|
kind,
|
|
85
85
|
labels,
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
suppositions,
|
|
87
|
+
consequence
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
return json;
|
|
@@ -102,38 +102,38 @@ export default class AxiomLemmaTheorem {
|
|
|
102
102
|
return label;
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
let {
|
|
105
|
+
let { suppositions } = json;
|
|
106
106
|
|
|
107
|
-
const
|
|
107
|
+
const suppositionsJSON = suppositions; ///
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
const json =
|
|
111
|
-
|
|
109
|
+
suppositions = suppositionsJSON.map((suppositionJSON) => {
|
|
110
|
+
const json = suppositionJSON, ///
|
|
111
|
+
supposition = Supposition.fromJSON(json, releaseContext);
|
|
112
112
|
|
|
113
|
-
return
|
|
113
|
+
return supposition;
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
let {
|
|
116
|
+
let { consequence } = json;
|
|
117
117
|
|
|
118
|
-
const
|
|
118
|
+
const consequenceJSON = consequence; ///
|
|
119
119
|
|
|
120
|
-
json =
|
|
120
|
+
json = consequenceJSON; ///
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
consequence = Consequence.fromJSON(json, releaseContext);
|
|
123
123
|
|
|
124
|
-
return new Class(labels,
|
|
124
|
+
return new Class(labels, suppositions, consequence); ///
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
static
|
|
127
|
+
static fromLabelsSuppositionsAndConsequence(Class, labels, suppositions, consequence) { return new Class(labels, suppositions, consequence); }
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
function
|
|
130
|
+
function matchSupposition(supposition, proofSteps, substitutions) {
|
|
131
131
|
const proofStep = prune(proofSteps, (proofStep) => {
|
|
132
132
|
const subproofNode = proofStep.getSubproofNode(),
|
|
133
133
|
statementNode = proofStep.getStatementNode();
|
|
134
134
|
|
|
135
135
|
if (subproofNode !== null) {
|
|
136
|
-
const subProofMatches =
|
|
136
|
+
const subProofMatches = supposition.matchSubproofNode(subproofNode, substitutions);
|
|
137
137
|
|
|
138
138
|
if (!subProofMatches) { ///
|
|
139
139
|
return true;
|
|
@@ -141,7 +141,7 @@ function matchAntecedent(antecedent, proofSteps, substitutions) {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
if (statementNode !== null) {
|
|
144
|
-
const statementMatches =
|
|
144
|
+
const statementMatches = supposition.matchStatementNode(statementNode, substitutions);
|
|
145
145
|
|
|
146
146
|
if (!statementMatches) { ///
|
|
147
147
|
return true;
|
|
@@ -150,41 +150,41 @@ function matchAntecedent(antecedent, proofSteps, substitutions) {
|
|
|
150
150
|
|
|
151
151
|
}) || null;
|
|
152
152
|
|
|
153
|
-
const
|
|
153
|
+
const suppositionMatches = (proofStep !== null);
|
|
154
154
|
|
|
155
|
-
return
|
|
155
|
+
return suppositionMatches;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
function
|
|
159
|
-
const
|
|
160
|
-
const
|
|
158
|
+
function matchSuppositions(supposition, proofSteps, substitutions) {
|
|
159
|
+
const suppositionsMatches = supposition.every((supposition) => {
|
|
160
|
+
const suppositionMatches = matchSupposition(supposition, proofSteps, substitutions);
|
|
161
161
|
|
|
162
|
-
if (
|
|
162
|
+
if (suppositionMatches) {
|
|
163
163
|
return true;
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
return
|
|
167
|
+
return suppositionsMatches;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
function
|
|
171
|
-
const nonTerminalNodeMatches =
|
|
172
|
-
|
|
170
|
+
function matchConsequence(consequence, statementNode, substitutions) {
|
|
171
|
+
const nonTerminalNodeMatches = consequence.matchStatementNode(statementNode, substitutions),
|
|
172
|
+
consequenceMatches = nonTerminalNodeMatches; ///
|
|
173
173
|
|
|
174
|
-
return
|
|
174
|
+
return consequenceMatches;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
function
|
|
178
|
-
let
|
|
177
|
+
function matchSuppositionsAndConsequence(suppositions, consequence, proofSteps, statementNode) {
|
|
178
|
+
let suppositionsMatchConsequence = false;
|
|
179
179
|
|
|
180
180
|
const substitutions = [],
|
|
181
|
-
|
|
181
|
+
suppositionsMatches = matchSuppositions(suppositions, proofSteps, substitutions);
|
|
182
182
|
|
|
183
|
-
if (
|
|
184
|
-
const
|
|
183
|
+
if (suppositionsMatches) {
|
|
184
|
+
const consequenceMatches = matchConsequence(consequence, statementNode, substitutions);
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
suppositionsMatchConsequence = consequenceMatches; ///
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
return
|
|
189
|
+
return suppositionsMatchConsequence;
|
|
190
190
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { first } from "./utilities/array";
|
|
4
|
+
import { nodeAsString } from "./utilities/string";
|
|
5
|
+
import { variableNameFromVariableNode } from "./utilities/query";
|
|
6
|
+
import { statementNodeFromStatementString } from "./utilities/string";
|
|
7
|
+
import { VARIABLE_RULE_NAME, STATEMENT_RULE_NAME } from "./ruleNames";
|
|
8
|
+
|
|
9
|
+
export default class Consequence {
|
|
10
|
+
constructor(statementNode) {
|
|
11
|
+
this.statementNode = statementNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getStatementNode() {
|
|
15
|
+
return this.statementNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
matchStatementNode(statementNode, metaSubstitutions) {
|
|
19
|
+
const nonTerminalNode = statementNode, ///
|
|
20
|
+
consequenceNonTerminalNode = this.statementNode, ///
|
|
21
|
+
consequenceNonTerminalNodeMatches = matchConsequenceNonTerminalNode(consequenceNonTerminalNode, nonTerminalNode, metaSubstitutions),
|
|
22
|
+
statementNodeMatches = consequenceNonTerminalNodeMatches; ///
|
|
23
|
+
|
|
24
|
+
return statementNodeMatches;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toJSON() {
|
|
28
|
+
const statementString = nodeAsString(this.statementNode),
|
|
29
|
+
statement = statementString, ///
|
|
30
|
+
json = {
|
|
31
|
+
statement
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return json;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static fromJSON(json, releaseContext) {
|
|
38
|
+
const { statement } = json,
|
|
39
|
+
statementString = statement, ///
|
|
40
|
+
statementNode = statementNodeFromStatementString(statementString, releaseContext),
|
|
41
|
+
consequence = new Consequence(statementNode);
|
|
42
|
+
|
|
43
|
+
return consequence;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static fromStatementNode(statementNode) {
|
|
47
|
+
const consequence = new Consequence(statementNode);
|
|
48
|
+
|
|
49
|
+
return consequence;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function matchConsequenceNode(consequenceNode, node, metaSubstitutions) {
|
|
54
|
+
let consequenceNodeMatches = false;
|
|
55
|
+
|
|
56
|
+
const nodeTerminalNode = node.isTerminalNode(),
|
|
57
|
+
ruleNodeTerminalNode = consequenceNode.isTerminalNode();
|
|
58
|
+
|
|
59
|
+
if (nodeTerminalNode === ruleNodeTerminalNode) {
|
|
60
|
+
if (nodeTerminalNode) {
|
|
61
|
+
const terminalNode = node, ///
|
|
62
|
+
consequenceTerminalNode = consequenceNode, ///
|
|
63
|
+
consequenceTerminalNodeMatches = matchConsequenceTerminalNode(consequenceTerminalNode, terminalNode, metaSubstitutions);
|
|
64
|
+
|
|
65
|
+
consequenceNodeMatches = consequenceTerminalNodeMatches; ///
|
|
66
|
+
} else {
|
|
67
|
+
const nonTerminalNode = node, ///
|
|
68
|
+
consequenceNonTerminalNode = consequenceNode, ///
|
|
69
|
+
consequenceNonTerminalNodeMatches = matchConsequenceNonTerminalNode(consequenceNonTerminalNode, nonTerminalNode, metaSubstitutions);
|
|
70
|
+
|
|
71
|
+
consequenceNodeMatches = consequenceNonTerminalNodeMatches; ///
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return consequenceNodeMatches;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function matchConsequenceNodes(consequenceNodes, nodes, metaSubstitutions) {
|
|
79
|
+
let consequenceNodesMatches = false;
|
|
80
|
+
|
|
81
|
+
const nodesLength = nodes.length,
|
|
82
|
+
consequenceNodesLength = consequenceNodes.length;
|
|
83
|
+
|
|
84
|
+
if (nodesLength === consequenceNodesLength) {
|
|
85
|
+
consequenceNodesMatches = nodes.every((node, index) => {
|
|
86
|
+
const consequenceNode = consequenceNodes[index],
|
|
87
|
+
consequenceNodeMatches = matchConsequenceNode(consequenceNode, node, metaSubstitutions);
|
|
88
|
+
|
|
89
|
+
if (consequenceNodeMatches) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return consequenceNodesMatches;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function matchConsequenceVariable(consequenceVariableNode, nodes, metaSubstitutions) {
|
|
99
|
+
let consequenceVariableMatches = true;
|
|
100
|
+
|
|
101
|
+
const consequenceVariableName = variableNameFromVariableNode(consequenceVariableNode),
|
|
102
|
+
metaSubstitution = metaSubstitutions.find((metaSubstitution) => {
|
|
103
|
+
const variableName = metaSubstitution.getVariableName();
|
|
104
|
+
|
|
105
|
+
if (variableName === consequenceVariableName) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}) || null;
|
|
109
|
+
|
|
110
|
+
if (metaSubstitution !== null) {
|
|
111
|
+
const metaSubstitutionNodesMatch = metaSubstitution.matchNodes(nodes);
|
|
112
|
+
|
|
113
|
+
consequenceVariableMatches = metaSubstitutionNodesMatch; ///
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return consequenceVariableMatches;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function matchConsequenceTerminalNode(consequenceTerminalNode, terminalNode, metaSubstitutions) {
|
|
120
|
+
const matches = consequenceTerminalNode.match(terminalNode),
|
|
121
|
+
consequenceTerminalNodeMatches = matches; ///
|
|
122
|
+
|
|
123
|
+
return consequenceTerminalNodeMatches;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function matchConsequenceNonTerminalNode(consequenceNonTerminalNode, nonTerminalNode, metaSubstitutions) {
|
|
127
|
+
let consequenceNonTerminalNodeMatches = false;
|
|
128
|
+
|
|
129
|
+
const ruleName = nonTerminalNode.getRuleName(),
|
|
130
|
+
consequenceRuleName = consequenceNonTerminalNode.getRuleName(); ///
|
|
131
|
+
|
|
132
|
+
if (ruleName === consequenceRuleName) {
|
|
133
|
+
const childNodes = nonTerminalNode.getChildNodes(),
|
|
134
|
+
consequenceChildNodes = consequenceNonTerminalNode.getChildNodes(),
|
|
135
|
+
nodes = childNodes, ///
|
|
136
|
+
consequenceNodes = consequenceChildNodes, ///
|
|
137
|
+
consequenceChildNodesMatches = matchConsequenceNodes(consequenceNodes, nodes, metaSubstitutions);
|
|
138
|
+
|
|
139
|
+
consequenceNonTerminalNodeMatches = consequenceChildNodesMatches; ///
|
|
140
|
+
|
|
141
|
+
if (!consequenceNonTerminalNodeMatches) {
|
|
142
|
+
const ruleNameStatementRuleName = (ruleName === STATEMENT_RULE_NAME);
|
|
143
|
+
|
|
144
|
+
if (ruleNameStatementRuleName) {
|
|
145
|
+
const statementNode = nonTerminalNode, ///
|
|
146
|
+
consequenceStatementNode = consequenceNonTerminalNode, ///
|
|
147
|
+
consequenceStatementNodeMatches = matchConsequenceStatementNode(consequenceStatementNode, statementNode, metaSubstitutions);
|
|
148
|
+
|
|
149
|
+
consequenceNonTerminalNodeMatches = consequenceStatementNodeMatches; ///
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return consequenceNonTerminalNodeMatches;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function matchConsequenceStatementNode(consequenceStatementNode, statementNode, metaSubstitutions) {
|
|
158
|
+
let consequenceStatementNodeMatches = false;
|
|
159
|
+
|
|
160
|
+
const consequenceNonTerminalNode = consequenceStatementNode, ///
|
|
161
|
+
consequenceChildNodes = consequenceNonTerminalNode.getChildNodes(),
|
|
162
|
+
consequenceChildNodesLength = consequenceChildNodes.length;
|
|
163
|
+
|
|
164
|
+
if (consequenceChildNodesLength === 1) {
|
|
165
|
+
const firstConsequenceChildNode = first(consequenceChildNodes),
|
|
166
|
+
consequenceChildNode = firstConsequenceChildNode, ///
|
|
167
|
+
consequenceChildNodeNonTerminalNode = consequenceChildNode.isNonTerminalNode();
|
|
168
|
+
|
|
169
|
+
if (consequenceChildNodeNonTerminalNode) {
|
|
170
|
+
const consequenceNonTerminalChildNode = consequenceChildNode, ///
|
|
171
|
+
consequenceNonTerminalChildNodeRuleName = consequenceNonTerminalChildNode.getRuleName(),
|
|
172
|
+
consequenceNonTerminalChildNodeRuleNameVariableRuleName = (consequenceNonTerminalChildNodeRuleName === VARIABLE_RULE_NAME);
|
|
173
|
+
|
|
174
|
+
if (consequenceNonTerminalChildNodeRuleNameVariableRuleName) {
|
|
175
|
+
const consequenceVariableNode = consequenceNonTerminalChildNode, ///
|
|
176
|
+
nonTerminalNode = statementNode, ///
|
|
177
|
+
childNodes = nonTerminalNode.getChildNodes(),
|
|
178
|
+
nodes = childNodes, ///
|
|
179
|
+
consequenceMetaVariableMatches = matchConsequenceVariable(consequenceVariableNode, nodes, metaSubstitutions);
|
|
180
|
+
|
|
181
|
+
consequenceStatementNodeMatches = consequenceMetaVariableMatches; ///
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return consequenceStatementNodeMatches;
|
|
187
|
+
}
|
package/src/lemma.js
CHANGED
|
@@ -9,5 +9,5 @@ export default class Lemma extends AxiomLemmaTheorem {
|
|
|
9
9
|
|
|
10
10
|
static fromJSON(json, releaseContext) { return AxiomLemmaTheorem.fromJSON(Lemma, json, releaseContext); }
|
|
11
11
|
|
|
12
|
-
static
|
|
12
|
+
static fromLabelsSuppositionsAndConsequence(labels, suppositions, consequence) { return AxiomLemmaTheorem.fromLabelsSuppositionsAndConsequence(Lemma, labels, suppositions, consequence); }
|
|
13
13
|
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import MetaSubstitution from "./metaSubstitution";
|
|
4
|
+
|
|
5
|
+
import { first } from "./utilities/array";
|
|
6
|
+
import { nodeAsString } from "./utilities/string";
|
|
7
|
+
import { nodeQuery, nodesQuery } from "./utilities/query";
|
|
8
|
+
import { metavariableNameFromMetavariableNode } from "./utilities/query";
|
|
9
|
+
import { metastatementNodeFromMetastatementString } from "./utilities/string";
|
|
10
|
+
import { METAVARIABLE_RULE_NAME, METASTATEMENT_RULE_NAME } from "./ruleNames";
|
|
11
|
+
|
|
12
|
+
const metastatementNodesQuery = nodesQuery("/metaSubproofAssertion/metastatement"),
|
|
13
|
+
metaSubproofAssertionNodeQuery = nodeQuery("/metastatement/metaSubproofAssertion!"),
|
|
14
|
+
unqualifiedMetastatementMetastatementNodesQuery = nodesQuery("/metaSubproof/unqualifiedMetastatement/metastatement!"),
|
|
15
|
+
qualifiedOrUnqualifiedMetastatementMetastatementNodeQuery = nodeQuery("/metaSubproof/subDerivation/qualifiedMetastatement|unqualifiedMetastatement[-1]/metastatement!");
|
|
16
|
+
|
|
17
|
+
export default class MetaSupposition {
|
|
18
|
+
constructor(metastatementNode) {
|
|
19
|
+
this.metastatementNode = metastatementNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getMetastatementNode() {
|
|
23
|
+
return this.metastatementNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
matchSubproofNode(metaSubproofNode, metaSubstitutions) {
|
|
27
|
+
let metaSubproofNodeMatches = false;
|
|
28
|
+
|
|
29
|
+
const metaSubproofAssertionNode = metaSubproofAssertionNodeQuery(this.metastatementNode);
|
|
30
|
+
|
|
31
|
+
if (metaSubproofAssertionNode !== null) {
|
|
32
|
+
const metaSubproofAssertionMetastatementNodes = metastatementNodesQuery(metaSubproofAssertionNode),
|
|
33
|
+
unqualifiedMetastatementMetastatementNodes = unqualifiedMetastatementMetastatementNodesQuery(metaSubproofNode),
|
|
34
|
+
qualifiedOrUnqualifiedMetastatementMetastatementNode = qualifiedOrUnqualifiedMetastatementMetastatementNodeQuery(metaSubproofNode),
|
|
35
|
+
metastatementNodes = [
|
|
36
|
+
...unqualifiedMetastatementMetastatementNodes,
|
|
37
|
+
qualifiedOrUnqualifiedMetastatementMetastatementNode
|
|
38
|
+
],
|
|
39
|
+
metastatementNodesLength = metastatementNodes.length,
|
|
40
|
+
metaSubproofAssertionMetastatementNodesLength = metaSubproofAssertionMetastatementNodes.length;
|
|
41
|
+
|
|
42
|
+
if (metastatementNodesLength === metaSubproofAssertionMetastatementNodesLength) {
|
|
43
|
+
metaSubproofNodeMatches = metaSubproofAssertionMetastatementNodes.every((metaSubproofAssertionMetastatementNode, index) => {
|
|
44
|
+
const metastatementNode = metastatementNodes[index],
|
|
45
|
+
nonTerminalNode = metastatementNode, ///
|
|
46
|
+
metaSuppositionNonTerminalNode = metaSubproofAssertionMetastatementNode, ///
|
|
47
|
+
metaSuppositionNonTerminalNodeMatches = matchMetaSuppositionNonTerminalNode(metaSuppositionNonTerminalNode, nonTerminalNode, metaSubstitutions);
|
|
48
|
+
|
|
49
|
+
if (metaSuppositionNonTerminalNodeMatches) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return metaSubproofNodeMatches;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
matchMetastatementNode(metastatementNode, metaSubstitutions) {
|
|
60
|
+
const nonTerminalNode = metastatementNode, ///
|
|
61
|
+
metaSuppositionNonTerminalNode = this.metastatementNode, ///
|
|
62
|
+
metaSuppositionNonTerminalNodeMatches = matchMetaSuppositionNonTerminalNode(metaSuppositionNonTerminalNode, nonTerminalNode, metaSubstitutions),
|
|
63
|
+
metastatementNodeMatches = metaSuppositionNonTerminalNodeMatches; ///
|
|
64
|
+
|
|
65
|
+
return metastatementNodeMatches;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
toJSON() {
|
|
69
|
+
const metastatementString = nodeAsString(this.metastatementNode),
|
|
70
|
+
metastatement = metastatementString, ///
|
|
71
|
+
json = {
|
|
72
|
+
metastatement
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return json;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static fromJSON(json, releaseContext) {
|
|
79
|
+
const { metastatement } = json,
|
|
80
|
+
metastatementString = metastatement, ///
|
|
81
|
+
metastatementNode = metastatementNodeFromMetastatementString(metastatementString, releaseContext),
|
|
82
|
+
metaSupposition = new MetaSupposition(metastatementNode);
|
|
83
|
+
|
|
84
|
+
return metaSupposition;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static fromMetastatementNode(metastatementNode) {
|
|
88
|
+
const metaSupposition = new MetaSupposition(metastatementNode);
|
|
89
|
+
|
|
90
|
+
return metaSupposition;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function matchMetaSuppositionNode(metaSuppositionNode, node, metaSubstitutions) {
|
|
95
|
+
let metaSuppositionNodeMatches = false;
|
|
96
|
+
|
|
97
|
+
const nodeTerminalNode = node.isTerminalNode(),
|
|
98
|
+
ruleNodeTerminalNode = metaSuppositionNode.isTerminalNode();
|
|
99
|
+
|
|
100
|
+
if (nodeTerminalNode === ruleNodeTerminalNode) {
|
|
101
|
+
if (nodeTerminalNode) {
|
|
102
|
+
const terminalNode = node, ///
|
|
103
|
+
metaSuppositionTerminalNode = metaSuppositionNode, ///
|
|
104
|
+
metaSuppositionTerminalNodeMatches = matchMetaSuppositionTerminalNode(metaSuppositionTerminalNode, terminalNode, metaSubstitutions);
|
|
105
|
+
|
|
106
|
+
metaSuppositionNodeMatches = metaSuppositionTerminalNodeMatches; ///
|
|
107
|
+
} else {
|
|
108
|
+
const nonTerminalNode = node, ///
|
|
109
|
+
metaSuppositionNonTerminalNode = metaSuppositionNode, ///
|
|
110
|
+
metaSuppositionNonTerminalNodeMatches = matchMetaSuppositionNonTerminalNode(metaSuppositionNonTerminalNode, nonTerminalNode, metaSubstitutions);
|
|
111
|
+
|
|
112
|
+
metaSuppositionNodeMatches = metaSuppositionNonTerminalNodeMatches; ///
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return metaSuppositionNodeMatches;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function matchMetaSuppositionNodes(metaSuppositionNodes, nodes, metaSubstitutions) {
|
|
120
|
+
let metaSuppositionNodesMatches = false;
|
|
121
|
+
|
|
122
|
+
const nodesLength = nodes.length,
|
|
123
|
+
metaSuppositionNodesLength = metaSuppositionNodes.length;
|
|
124
|
+
|
|
125
|
+
if (nodesLength === metaSuppositionNodesLength) {
|
|
126
|
+
metaSuppositionNodesMatches = nodes.every((node, index) => {
|
|
127
|
+
const metaSuppositionNode = metaSuppositionNodes[index],
|
|
128
|
+
metaSuppositionNodeMatches = matchMetaSuppositionNode(metaSuppositionNode, node, metaSubstitutions);
|
|
129
|
+
|
|
130
|
+
if (metaSuppositionNodeMatches) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return metaSuppositionNodesMatches;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function matchMetaSuppositionMetavariable(metaSuppositionMetavariableNode, nodes, metaSubstitutions) {
|
|
140
|
+
let metaSuppositionMetavariableMatches;
|
|
141
|
+
|
|
142
|
+
const metaSuppositionMetavariableName = metavariableNameFromMetavariableNode(metaSuppositionMetavariableNode),
|
|
143
|
+
metaSubstitution = metaSubstitutions.find((metaSubstitution) => {
|
|
144
|
+
const metavariableName = metaSubstitution.getMetavariableName();
|
|
145
|
+
|
|
146
|
+
if (metavariableName === metaSuppositionMetavariableName) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
}) || null;
|
|
150
|
+
|
|
151
|
+
if (metaSubstitution !== null) {
|
|
152
|
+
const metaSubstitutionNodesMatch = metaSubstitution.matchNodes(nodes);
|
|
153
|
+
|
|
154
|
+
metaSuppositionMetavariableMatches = metaSubstitutionNodesMatch; ///
|
|
155
|
+
} else {
|
|
156
|
+
const metavariableName = metaSuppositionMetavariableName, ///
|
|
157
|
+
metaSubstitution = MetaSubstitution.fromMetavariableNameAndNodes(metavariableName, nodes);
|
|
158
|
+
|
|
159
|
+
metaSubstitutions.push(metaSubstitution);
|
|
160
|
+
|
|
161
|
+
metaSuppositionMetavariableMatches = true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return metaSuppositionMetavariableMatches;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function matchMetaSuppositionTerminalNode(metaSuppositionTerminalNode, terminalNode, metaSubstitutions) {
|
|
168
|
+
const matches = metaSuppositionTerminalNode.match(terminalNode),
|
|
169
|
+
metaSuppositionTerminalNodeMatches = matches;
|
|
170
|
+
|
|
171
|
+
return metaSuppositionTerminalNodeMatches;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function matchMetaSuppositionNonTerminalNode(metaSuppositionNonTerminalNode, nonTerminalNode, metaSubstitutions) {
|
|
175
|
+
let metaSuppositionNonTerminalNodeMatches = false;
|
|
176
|
+
|
|
177
|
+
const ruleName = nonTerminalNode.getRuleName(),
|
|
178
|
+
metaSuppositionRuleName = metaSuppositionNonTerminalNode.getRuleName(); ///
|
|
179
|
+
|
|
180
|
+
if (ruleName === metaSuppositionRuleName) {
|
|
181
|
+
const childNodes = nonTerminalNode.getChildNodes(),
|
|
182
|
+
metaSuppositionChildNodes = metaSuppositionNonTerminalNode.getChildNodes(),
|
|
183
|
+
nodes = childNodes, ///
|
|
184
|
+
metaSuppositionNodes = metaSuppositionChildNodes, ///
|
|
185
|
+
metaSuppositionChildNodesMatches = matchMetaSuppositionNodes(metaSuppositionNodes, nodes, metaSubstitutions);
|
|
186
|
+
|
|
187
|
+
metaSuppositionNonTerminalNodeMatches = metaSuppositionChildNodesMatches; ///
|
|
188
|
+
|
|
189
|
+
if (!metaSuppositionNonTerminalNodeMatches) {
|
|
190
|
+
const ruleNameMetastatementRuleName = (ruleName === METASTATEMENT_RULE_NAME);
|
|
191
|
+
|
|
192
|
+
if (ruleNameMetastatementRuleName) {
|
|
193
|
+
const metastatementNode = nonTerminalNode, ///
|
|
194
|
+
metaSuppositionMetastatementNode = metaSuppositionNonTerminalNode, ///
|
|
195
|
+
metaSuppositionMetastatementNodeMatches = matchMetaSuppositionMetastatementNode(metaSuppositionMetastatementNode, metastatementNode, metaSubstitutions);
|
|
196
|
+
|
|
197
|
+
metaSuppositionNonTerminalNodeMatches = metaSuppositionMetastatementNodeMatches; ///
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return metaSuppositionNonTerminalNodeMatches;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function matchMetaSuppositionMetastatementNode(metaSuppositionMetastatementNode, metastatementNode, metaSubstitutions) {
|
|
206
|
+
let metaSuppositionMetastatementNodeMatches = false;
|
|
207
|
+
|
|
208
|
+
const metaSuppositionNonTerminalNode = metaSuppositionMetastatementNode, ///
|
|
209
|
+
metaSuppositionChildNodes = metaSuppositionNonTerminalNode.getChildNodes(),
|
|
210
|
+
metaSuppositionChildNodesLength = metaSuppositionChildNodes.length;
|
|
211
|
+
|
|
212
|
+
if (metaSuppositionChildNodesLength === 1) {
|
|
213
|
+
const firstMetaSuppositionChildNode = first(metaSuppositionChildNodes),
|
|
214
|
+
metaSuppositionChildNode = firstMetaSuppositionChildNode, ///
|
|
215
|
+
metaSuppositionChildNodeNonTerminalNode = metaSuppositionChildNode.isNonTerminalNode();
|
|
216
|
+
|
|
217
|
+
if (metaSuppositionChildNodeNonTerminalNode) {
|
|
218
|
+
const metaSuppositionNonTerminalChildNode = metaSuppositionChildNode, ///
|
|
219
|
+
metaSuppositionNonTerminalChildNodeRuleName = metaSuppositionNonTerminalChildNode.getRuleName(),
|
|
220
|
+
metaSuppositionNonTerminalChildNodeRuleNameMetavariableRuleName = (metaSuppositionNonTerminalChildNodeRuleName === METAVARIABLE_RULE_NAME);
|
|
221
|
+
|
|
222
|
+
if (metaSuppositionNonTerminalChildNodeRuleNameMetavariableRuleName) {
|
|
223
|
+
const metaSuppositionMetavariableNode = metaSuppositionNonTerminalChildNode, ///
|
|
224
|
+
nonTerminalNode = metastatementNode, ///
|
|
225
|
+
childNodes = nonTerminalNode.getChildNodes(),
|
|
226
|
+
nodes = childNodes, ///
|
|
227
|
+
metaSuppositionMetavariableMatches = matchMetaSuppositionMetavariable(metaSuppositionMetavariableNode, nodes, metaSubstitutions);
|
|
228
|
+
|
|
229
|
+
metaSuppositionMetastatementNodeMatches = metaSuppositionMetavariableMatches; ///
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return metaSuppositionMetastatementNodeMatches;
|
|
235
|
+
}
|