occam-verify-cli 0.0.453 → 0.0.455
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/bin/utilities/fileSystem.js +15 -2
- package/lib/assertion.js +8 -1
- package/lib/context/file.js +42 -6
- package/lib/context/proof.js +25 -4
- package/lib/context/release/directory.js +16 -5
- package/lib/context/release/file.js +25 -11
- package/lib/kinds.js +5 -1
- package/lib/theorem.js +146 -0
- package/lib/variable.js +8 -1
- package/lib/verify/declaration/topLevel.js +7 -3
- package/lib/verify/derivation.js +112 -0
- package/lib/verify/equality.js +3 -16
- package/lib/verify/metaDerivation.js +47 -39
- package/lib/verify/proof.js +83 -0
- package/lib/verify/statement/unqualified.js +65 -4
- package/lib/verify/statement.js +2 -2
- package/lib/verify/term.js +12 -12
- package/lib/verify/termAsConstructor.js +2 -2
- package/lib/verify/theorem.js +57 -0
- package/package.json +3 -3
- package/src/assertion.js +8 -1
- package/src/context/file.js +45 -5
- package/src/context/proof.js +8 -4
- package/src/context/release/directory.js +17 -4
- package/src/context/release/file.js +29 -12
- package/src/kinds.js +1 -0
- package/src/theorem.js +130 -0
- package/src/variable.js +6 -0
- package/src/verify/assertion/type.js +25 -12
- package/src/verify/declaration/topLevel.js +7 -0
- package/src/verify/derivation.js +156 -0
- package/src/verify/equality.js +3 -22
- package/src/verify/metaDerivation.js +57 -45
- package/src/verify/proof.js +123 -0
- package/src/verify/statement/unqualified.js +69 -2
- package/src/verify/statement.js +2 -1
- package/src/verify/term.js +16 -17
- package/src/verify/termAsConstructor.js +1 -2
- package/src/verify/theorem.js +77 -0
- package/lib/verify/assertion/type.js +0 -104
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Variable from "../../variable";
|
|
4
|
-
import verifyTerm from "../../verify/term";
|
|
5
4
|
|
|
6
5
|
import { first } from "../../utilities/array";
|
|
7
6
|
import { nodeAsString } from "../../utilities/string";
|
|
@@ -11,7 +10,7 @@ import { verifyTermAsVariable, verifyTermAgainstConstructors } from "../../verif
|
|
|
11
10
|
const termNodeQuery = nodeQuery("/typeAssertion/term"),
|
|
12
11
|
typeNodeQuery = nodeQuery("/typeAssertion/type");
|
|
13
12
|
|
|
14
|
-
export default function verifyTypeAssertion(typeAssertionNode, proofContext) {
|
|
13
|
+
export default function verifyTypeAssertion(typeAssertionNode, types, variables, proofContext) {
|
|
15
14
|
let typeAssertionVerified = false;
|
|
16
15
|
|
|
17
16
|
proofContext.begin(typeAssertionNode);
|
|
@@ -23,22 +22,37 @@ export default function verifyTypeAssertion(typeAssertionNode, proofContext) {
|
|
|
23
22
|
if (!typePresent) {
|
|
24
23
|
proofContext.error(`The ${typeName} type is not present.`);
|
|
25
24
|
} else {
|
|
25
|
+
const type = proofContext.findTypeByTypeName(typeName),
|
|
26
|
+
context = proofContext, ///
|
|
27
|
+
termNode = termNodeQuery(typeAssertionNode),
|
|
28
|
+
variables = [],
|
|
29
|
+
termString = nodeAsString(termNode),
|
|
30
|
+
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
|
|
31
|
+
|
|
32
|
+
if (termVerifiedAsVariable) {
|
|
33
|
+
types.add(type);
|
|
34
|
+
|
|
35
|
+
typeAssertionVerified = true;
|
|
36
|
+
} else {
|
|
37
|
+
const termVerifiedAgainstConstructors = verifyTermAgainstConstructors(termNode, types, values, context);
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const ;
|
|
43
|
+
|
|
44
|
+
|
|
26
45
|
const derived = proofContext.isDerived();
|
|
27
46
|
|
|
28
47
|
if (derived) {
|
|
29
48
|
debugger
|
|
30
49
|
} else {
|
|
31
|
-
const types = [],
|
|
32
|
-
values = [],
|
|
33
|
-
context = proofContext, ///
|
|
34
|
-
termNode = termNodeQuery(typeAssertionNode),
|
|
35
|
-
termString = nodeAsString(termNode),
|
|
36
|
-
termVerifiedAsVariable = verifyTermAsVariable(termNode, types, values, context);
|
|
37
50
|
|
|
38
51
|
if (termVerifiedAsVariable) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
const firstVariable = first(variables),
|
|
53
|
+
variable = firstVariable, ///
|
|
54
|
+
variableName = variable.getName(),
|
|
55
|
+
variableDefined = variable.isDefined();
|
|
42
56
|
|
|
43
57
|
if (value !== undefined) {
|
|
44
58
|
proofContext.error(`The value of the ${variableName} variable is not undefined.`);
|
|
@@ -60,7 +74,6 @@ export default function verifyTypeAssertion(typeAssertionNode, proofContext) {
|
|
|
60
74
|
}
|
|
61
75
|
}
|
|
62
76
|
} else {
|
|
63
|
-
const termVerifiedAgainstConstructors = verifyTermAgainstConstructors(termNode, types, values, context);
|
|
64
77
|
|
|
65
78
|
if (termVerifiedAgainstConstructors) {
|
|
66
79
|
const type = proofContext.findTypeByTypeName(typeName),
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import verifyRule from "../../verify/rule";
|
|
4
4
|
import verifyAxiom from "../../verify/axiom";
|
|
5
5
|
import verifyLemma from "../../verify/lemma";
|
|
6
|
+
import verifyTheorem from "../../verify/theorem";
|
|
6
7
|
import verifyTypeDeclaration from "../../verify/declaration/type";
|
|
7
8
|
import verifyVariableDeclaration from "../../verify/declaration/variable";
|
|
8
9
|
import verifyCombinatorDeclaration from "../../verify/declaration/combinator";
|
|
@@ -13,6 +14,7 @@ import { nodeQuery } from "../../utilities/query";
|
|
|
13
14
|
const ruleNodeQuery = nodeQuery("/topLevelDeclaration/rule!"),
|
|
14
15
|
axiomNodeQuery = nodeQuery("/topLevelDeclaration/axiom!"),
|
|
15
16
|
lemmaNodeQuery = nodeQuery("/topLevelDeclaration/lemma!"),
|
|
17
|
+
theoremNodeQuery = nodeQuery("/topLevelDeclaration/theorem!"),
|
|
16
18
|
typeDeclarationNodeQuery = nodeQuery("/topLevelDeclaration/typeDeclaration!"),
|
|
17
19
|
variableDeclarationNodeQuery = nodeQuery("/topLevelDeclaration/variableDeclaration!"),
|
|
18
20
|
combinatorDeclarationNodeQuery = nodeQuery("/topLevelDeclaration/combinatorDeclaration!"),
|
|
@@ -27,6 +29,7 @@ export default function verifyTopLevelDeclaration(topLevelDeclarationNode, fileC
|
|
|
27
29
|
ruleNode = ruleNodeQuery(node),
|
|
28
30
|
axiomNode = axiomNodeQuery(node),
|
|
29
31
|
lemmaNode = lemmaNodeQuery(node),
|
|
32
|
+
theoremNode = theoremNodeQuery(node),
|
|
30
33
|
typeDeclarationNode = typeDeclarationNodeQuery(node),
|
|
31
34
|
variableDeclarationNode = variableDeclarationNodeQuery(node),
|
|
32
35
|
combinatorDeclarationNode = combinatorDeclarationNodeQuery(node),
|
|
@@ -46,6 +49,10 @@ export default function verifyTopLevelDeclaration(topLevelDeclarationNode, fileC
|
|
|
46
49
|
const lemmaVerified = verifyLemma(lemmaNode, fileContext);
|
|
47
50
|
|
|
48
51
|
topLevelDeclarationVerified = lemmaVerified; ///
|
|
52
|
+
} else if (theoremNode !== null) {
|
|
53
|
+
const theoremVerified = verifyTheorem(theoremNode, fileContext);
|
|
54
|
+
|
|
55
|
+
topLevelDeclarationVerified = theoremVerified; ///
|
|
49
56
|
} else if (typeDeclarationNode !== null) {
|
|
50
57
|
const typeDeclarationVerified = verifyTypeDeclaration(typeDeclarationNode, fileContext);
|
|
51
58
|
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Assertion from "../assertion";
|
|
4
|
+
import ProofContext from "../context/proof";
|
|
5
|
+
import verifyQualifiedStatement from "../verify/statement/qualified";
|
|
6
|
+
import verifyUnqualifiedStatement from "../verify/statement/unqualified";
|
|
7
|
+
|
|
8
|
+
import { front, last } from "../utilities/array";
|
|
9
|
+
import { nodeQuery, nodesQuery } from "../utilities/query";
|
|
10
|
+
import { SUBPROOF_RULE_NAME, QUALIFIED_STATEMENT_RULE_NAME, UNQUALIFIED_STATEMENT_RULE_NAME } from "../ruleNames";
|
|
11
|
+
|
|
12
|
+
const derivationNodeQuery = nodeQuery("/subproof/derivation!"),
|
|
13
|
+
derivationChildNodesQuery = nodesQuery("/derivation/*"),
|
|
14
|
+
qualifiedStatementNodeQuery = nodeQuery("/qualifiedStatement"),
|
|
15
|
+
unqualifiedStatementNodeQuery = nodeQuery("/unqualifiedStatement!"),
|
|
16
|
+
qualifiedOrUnqualifiedStatementNodesQuery = nodesQuery("/subproof/qualifiedStatement|unqualifiedStatement")
|
|
17
|
+
|
|
18
|
+
export default function verifyDerivation(derivationNode, proofContext) {
|
|
19
|
+
let derivationVerified,
|
|
20
|
+
derived;
|
|
21
|
+
|
|
22
|
+
proofContext.begin(derivationNode);
|
|
23
|
+
|
|
24
|
+
derived = true;
|
|
25
|
+
|
|
26
|
+
proofContext.setDerived(derived);
|
|
27
|
+
|
|
28
|
+
const derivationChildNodes = derivationChildNodesQuery(derivationNode);
|
|
29
|
+
|
|
30
|
+
derivationVerified = derivationChildNodes.every((derivationChildNode) => { ///
|
|
31
|
+
const derivationChildVerified = verifyDerivationChild(derivationChildNode, proofContext);
|
|
32
|
+
|
|
33
|
+
if (derivationChildVerified) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
derived = false;
|
|
39
|
+
|
|
40
|
+
proofContext.setDerived(derived);
|
|
41
|
+
|
|
42
|
+
derivationVerified ?
|
|
43
|
+
proofContext.complete(derivationNode) :
|
|
44
|
+
proofContext.halt(derivationNode);
|
|
45
|
+
|
|
46
|
+
return derivationVerified;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function verifyDerivationChild(derivationChildNode, proofContext) {
|
|
50
|
+
let derivationChildVerified;
|
|
51
|
+
|
|
52
|
+
const ruleName = derivationChildNode.getRuleName();
|
|
53
|
+
|
|
54
|
+
switch (ruleName) {
|
|
55
|
+
case SUBPROOF_RULE_NAME: {
|
|
56
|
+
const subproofNode = derivationChildNode, ///
|
|
57
|
+
subproofVerified = verifySubproof(subproofNode, proofContext);
|
|
58
|
+
|
|
59
|
+
if (subproofVerified) {
|
|
60
|
+
const assertion = Assertion.fromSubproofNode(subproofNode);
|
|
61
|
+
|
|
62
|
+
proofContext.addAssertion(assertion);
|
|
63
|
+
|
|
64
|
+
derivationChildVerified = true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case QUALIFIED_STATEMENT_RULE_NAME: {
|
|
71
|
+
const qualifiedStatementNode = derivationChildNode, ///
|
|
72
|
+
qualifiedStatementVerified = verifyQualifiedStatement(qualifiedStatementNode, proofContext);
|
|
73
|
+
|
|
74
|
+
if (qualifiedStatementVerified) {
|
|
75
|
+
const assertion = Assertion.fromQualifiedStatementNode(qualifiedStatementNode);
|
|
76
|
+
|
|
77
|
+
proofContext.addAssertion(assertion);
|
|
78
|
+
|
|
79
|
+
derivationChildVerified = qualifiedStatementVerified; ///
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
case UNQUALIFIED_STATEMENT_RULE_NAME: {
|
|
86
|
+
const unqualifiedStatementNode = derivationChildNode, ///
|
|
87
|
+
unqualifiedStatementVerified = verifyUnqualifiedStatement(unqualifiedStatementNode, proofContext);
|
|
88
|
+
|
|
89
|
+
if (unqualifiedStatementVerified) {
|
|
90
|
+
const assertion = Assertion.fromUnqualifiedStatementNode(unqualifiedStatementNode);
|
|
91
|
+
|
|
92
|
+
proofContext.addAssertion(assertion);
|
|
93
|
+
|
|
94
|
+
derivationChildVerified = true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return derivationChildVerified;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function verifySubproof(subproofNode, proofContext) {
|
|
105
|
+
let subproofVerified = false;
|
|
106
|
+
|
|
107
|
+
proofContext = ProofContext.fromProofContext(proofContext); ///
|
|
108
|
+
|
|
109
|
+
const qualifiedOrUnqualifiedStatementNodes = qualifiedOrUnqualifiedStatementNodesQuery(subproofNode),
|
|
110
|
+
frontQualifiedOrUnqualifiedStatementNodes = front(qualifiedOrUnqualifiedStatementNodes),
|
|
111
|
+
unqualifiedStatementNodes = frontQualifiedOrUnqualifiedStatementNodes, ///
|
|
112
|
+
unqualifiedStatementsVerified = unqualifiedStatementNodes.every((unqualifiedStatementNode) => {
|
|
113
|
+
const unqualifiedStatementVerified = verifyUnqualifiedStatement(unqualifiedStatementNode, proofContext);
|
|
114
|
+
|
|
115
|
+
if (unqualifiedStatementVerified) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (unqualifiedStatementsVerified) {
|
|
121
|
+
unqualifiedStatementNodes.forEach((unqualifiedStatementNode) => {
|
|
122
|
+
const assertion = Assertion.fromUnqualifiedStatementNode(unqualifiedStatementNode);
|
|
123
|
+
|
|
124
|
+
proofContext.addAssertion(assertion);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
let derivationVerified = true;
|
|
128
|
+
|
|
129
|
+
const derivationNode = derivationNodeQuery(subproofNode);
|
|
130
|
+
|
|
131
|
+
if (derivationNode !== null) {
|
|
132
|
+
derivationVerified = verifyDerivation(derivationNode, proofContext);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (derivationVerified) {
|
|
136
|
+
const lastQualifiedOrUnqualifiedStatementNode = last(qualifiedOrUnqualifiedStatementNodes),
|
|
137
|
+
qualifiedOrUnqualifiedStatementNode = lastQualifiedOrUnqualifiedStatementNode, ///
|
|
138
|
+
qualifiedStatementNode = qualifiedStatementNodeQuery(qualifiedOrUnqualifiedStatementNode),
|
|
139
|
+
unqualifiedStatementNode = unqualifiedStatementNodeQuery(qualifiedOrUnqualifiedStatementNode);
|
|
140
|
+
|
|
141
|
+
if (qualifiedStatementNode !== null) {
|
|
142
|
+
const qualifiedStatementVerified = verifyQualifiedStatement(qualifiedStatementNode, proofContext);
|
|
143
|
+
|
|
144
|
+
subproofVerified = qualifiedStatementVerified; ///
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (unqualifiedStatementNode !== null) {
|
|
148
|
+
const unqualifiedStatementVerified = verifyUnqualifiedStatement(unqualifiedStatementNode, proofContext);
|
|
149
|
+
|
|
150
|
+
subproofVerified = unqualifiedStatementVerified; ///
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return subproofVerified;
|
|
156
|
+
}
|
package/src/verify/equality.js
CHANGED
|
@@ -14,12 +14,11 @@ export default function verifyEquality(equalityNode, proofContext) {
|
|
|
14
14
|
proofContext.begin(equalityNode);
|
|
15
15
|
|
|
16
16
|
const types = [],
|
|
17
|
-
values = [],
|
|
18
17
|
context = proofContext,
|
|
19
18
|
firstTermNode = firstTermNodeQuery(equalityNode),
|
|
20
19
|
secondTermNode = secondTermNodeQuery(equalityNode),
|
|
21
|
-
firstTermVerified = verifyTerm(firstTermNode, types,
|
|
22
|
-
secondTermVerified = verifyTerm(secondTermNode, types,
|
|
20
|
+
firstTermVerified = verifyTerm(firstTermNode, types, context),
|
|
21
|
+
secondTermVerified = verifyTerm(secondTermNode, types, context);
|
|
23
22
|
|
|
24
23
|
if (firstTermVerified && secondTermVerified) {
|
|
25
24
|
const firstType = first(types),
|
|
@@ -27,17 +26,7 @@ export default function verifyEquality(equalityNode, proofContext) {
|
|
|
27
26
|
firstTypeEqualToSubTypeOfOrSuperTypeOfSecondType = firstType.isEqualToSubTypeOfOrSuperTypeOf(secondType);
|
|
28
27
|
|
|
29
28
|
if (firstTypeEqualToSubTypeOfOrSuperTypeOfSecondType) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (derived) {
|
|
33
|
-
const termsEqual = equateTerms(firstTermNode, secondTermNode, proofContext);
|
|
34
|
-
|
|
35
|
-
if (termsEqual) {
|
|
36
|
-
equalityVerified = true;
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
equalityVerified = true;
|
|
40
|
-
}
|
|
29
|
+
equalityVerified = true;
|
|
41
30
|
}
|
|
42
31
|
}
|
|
43
32
|
|
|
@@ -47,11 +36,3 @@ export default function verifyEquality(equalityNode, proofContext) {
|
|
|
47
36
|
|
|
48
37
|
return equalityVerified;
|
|
49
38
|
}
|
|
50
|
-
|
|
51
|
-
function equateTerms(firstTermNode, secondTermNode, proofContext) {
|
|
52
|
-
let termsEqual = true; ///
|
|
53
|
-
|
|
54
|
-
debugger
|
|
55
|
-
|
|
56
|
-
return termsEqual;
|
|
57
|
-
}
|
|
@@ -16,77 +16,89 @@ const metaDerivationNodeQuery = nodeQuery("/metaSubproof/metaDerivation!"),
|
|
|
16
16
|
qualifiedOrUnqualifiedMetastatementNodesQuery = nodesQuery("/metaSubproof/qualifiedMetastatement|unqualifiedMetastatement")
|
|
17
17
|
|
|
18
18
|
export default function verifyMetaDerivation(metaDerivationNode, metaproofContext) {
|
|
19
|
-
let metaDerivationVerified
|
|
19
|
+
let metaDerivationVerified,
|
|
20
|
+
derived;
|
|
20
21
|
|
|
21
22
|
metaproofContext.begin(metaDerivationNode);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
derived = true;
|
|
24
25
|
|
|
25
26
|
metaproofContext.setDerived(derived);
|
|
26
27
|
|
|
27
|
-
const metaDerivationChildNodes = metaDerivationChildNodesQuery(metaDerivationNode)
|
|
28
|
-
metaDerivationChildNodesVerified = metaDerivationChildNodes.every((metaDerivationChildNode) => {
|
|
29
|
-
let metaDerivationChildNodeVerified;
|
|
28
|
+
const metaDerivationChildNodes = metaDerivationChildNodesQuery(metaDerivationNode);
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
metaDerivationVerified = metaDerivationChildNodes.every((metaDerivationChildNode) => { ///
|
|
31
|
+
const metaDerivationChildVerified = verifyMetaDerivationChild(metaDerivationChildNode, metaproofContext);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (metaDerivationChildVerified) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
const metaAssertion = MetaAssertion.fromMetaSubproofNode(metaSubproofNode);
|
|
38
|
+
derived = false;
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
metaproofContext.setDerived(derived);
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
metaDerivationVerified ?
|
|
43
|
+
metaproofContext.complete(metaDerivationNode) :
|
|
44
|
+
metaproofContext.halt(metaDerivationNode);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
return metaDerivationVerified;
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
qualifiedMetastatementVerified = verifyQualifiedMetastatement(qualifiedMetastatementNode, metaproofContext);
|
|
49
|
+
function verifyMetaDerivationChild(metaDerivationChildNode, metaproofContext) {
|
|
50
|
+
let metaDerivationChildVerified;
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
const metaAssertion = MetaAssertion.fromQualifiedMetastatementNode(qualifiedMetastatementNode);
|
|
52
|
+
const ruleName = metaDerivationChildNode.getRuleName();
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
switch (ruleName) {
|
|
55
|
+
case META_SUBPROOF_RULE_NAME: {
|
|
56
|
+
const metaSubproofNode = metaDerivationChildNode, ///
|
|
57
|
+
metaSubproofVerified = verifyMetaSubproof(metaSubproofNode, metaproofContext);
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
if (metaSubproofVerified) {
|
|
60
|
+
const metaAssertion = MetaAssertion.fromMetaSubproofNode(metaSubproofNode);
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
}
|
|
62
|
+
metaproofContext.addMetaAssertion(metaAssertion);
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
unqualifiedMetastatementVerified = verifyUnqualifiedMetastatement(unqualifiedMetastatementNode, metaproofContext);
|
|
64
|
+
metaDerivationChildVerified = true;
|
|
65
|
+
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
case QUALIFIED_METASTATEMENT_RULE_NAME: {
|
|
71
|
+
const qualifiedMetastatementNode = metaDerivationChildNode, ///
|
|
72
|
+
qualifiedMetastatementVerified = verifyQualifiedMetastatement(qualifiedMetastatementNode, metaproofContext);
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
if (qualifiedMetastatementVerified) {
|
|
75
|
+
const metaAssertion = MetaAssertion.fromQualifiedMetastatementNode(qualifiedMetastatementNode);
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}
|
|
77
|
+
metaproofContext.addMetaAssertion(metaAssertion);
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
metaDerivationChildVerified = qualifiedMetastatementVerified; ///
|
|
80
|
+
}
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
case UNQUALIFIED_METASTATEMENT_RULE_NAME: {
|
|
86
|
+
const unqualifiedMetastatementNode = metaDerivationChildNode, ///
|
|
87
|
+
unqualifiedMetastatementVerified = verifyUnqualifiedMetastatement(unqualifiedMetastatementNode, metaproofContext);
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
if (unqualifiedMetastatementVerified) {
|
|
90
|
+
const metaAssertion = MetaAssertion.fromUnqualifiedMetastatementNode(unqualifiedMetastatementNode);
|
|
91
|
+
|
|
92
|
+
metaproofContext.addMetaAssertion(metaAssertion);
|
|
93
|
+
|
|
94
|
+
metaDerivationChildVerified = true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return metaDerivationChildVerified;
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
function verifyMetaSubproof(metaSubproofNode, metaproofContext) {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import verifyDerivation from "../verify/derivation";
|
|
4
|
+
import verifyQualifiedStatement from "../verify/statement/qualified";
|
|
5
|
+
|
|
6
|
+
import { nodeQuery } from "../utilities/query";
|
|
7
|
+
|
|
8
|
+
const derivationNodeQuery = nodeQuery("/proof/derivation!"),
|
|
9
|
+
qualifiedStatementNodeQuery = nodeQuery("/proof/qualifiedStatement!"),
|
|
10
|
+
proofStatementNodeQuery = nodeQuery("/proof/qualifiedStatement/statement!");
|
|
11
|
+
|
|
12
|
+
export default function verifyProof(proofNode, conclusion, proofContext) {
|
|
13
|
+
let proofVerified = false;
|
|
14
|
+
|
|
15
|
+
proofContext.begin(proofNode);
|
|
16
|
+
|
|
17
|
+
const derivationNode = derivationNodeQuery(proofNode);
|
|
18
|
+
|
|
19
|
+
let derivationVerified = true;
|
|
20
|
+
|
|
21
|
+
if (derivationNode !== null) {
|
|
22
|
+
derivationVerified = verifyDerivation(derivationNode, proofContext);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (derivationVerified) {
|
|
26
|
+
const qualifiedStatementNode = qualifiedStatementNodeQuery(proofNode),
|
|
27
|
+
qualifiedStatementVerified = verifyQualifiedStatement(qualifiedStatementNode, proofContext);
|
|
28
|
+
|
|
29
|
+
if (qualifiedStatementVerified) {
|
|
30
|
+
const statementNode = conclusion.getStatementNode(),
|
|
31
|
+
proofStatementNode = proofStatementNodeQuery(proofNode),
|
|
32
|
+
proofStatementNodeMatches = matchProofStatementNode(proofStatementNode, statementNode);
|
|
33
|
+
|
|
34
|
+
proofVerified = proofStatementNodeMatches; ///
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
proofVerified ?
|
|
39
|
+
proofContext.complete(proofNode) :
|
|
40
|
+
proofContext.complete(proofNode);
|
|
41
|
+
|
|
42
|
+
return proofVerified;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function matchProofStatementNode(proofStatementNode, statementNode) {
|
|
46
|
+
const proofNonTerminalNode = proofStatementNode, ///
|
|
47
|
+
nonTerminalNode = statementNode, ///
|
|
48
|
+
proofNonTerminalNodeMatches = matchProofNonTerminalNode(proofNonTerminalNode, nonTerminalNode),
|
|
49
|
+
proofStatementNodeMatches = proofNonTerminalNodeMatches; ///
|
|
50
|
+
|
|
51
|
+
return proofStatementNodeMatches;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function matchProofNode(proofNode, node) {
|
|
55
|
+
let proofNodeMatches = false;
|
|
56
|
+
|
|
57
|
+
const nodeTerminalNode = node.isTerminalNode(),
|
|
58
|
+
ruleNodeTerminalNode = proofNode.isTerminalNode();
|
|
59
|
+
|
|
60
|
+
if (nodeTerminalNode === ruleNodeTerminalNode) {
|
|
61
|
+
if (nodeTerminalNode) {
|
|
62
|
+
const terminalNode = node, ///
|
|
63
|
+
proofTerminalNode = proofNode, ///
|
|
64
|
+
proofTerminalNodeMatches = matchProofTerminalNode(proofTerminalNode, terminalNode);
|
|
65
|
+
|
|
66
|
+
proofNodeMatches = proofTerminalNodeMatches; ///
|
|
67
|
+
} else {
|
|
68
|
+
const nonTerminalNode = node, ///
|
|
69
|
+
proofNonTerminalNode = proofNode, ///
|
|
70
|
+
proofNonTerminalNodeMatches = matchProofNonTerminalNode(proofNonTerminalNode, nonTerminalNode);
|
|
71
|
+
|
|
72
|
+
proofNodeMatches = proofNonTerminalNodeMatches; ///
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return proofNodeMatches;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function matchProofNodes(proofNodes, nodes) {
|
|
80
|
+
let proofNodesMatches = false;
|
|
81
|
+
|
|
82
|
+
const nodesLength = nodes.length,
|
|
83
|
+
proofNodesLength = proofNodes.length;
|
|
84
|
+
|
|
85
|
+
if (nodesLength === proofNodesLength) {
|
|
86
|
+
proofNodesMatches = nodes.every((node, index) => {
|
|
87
|
+
const proofNode = proofNodes[index],
|
|
88
|
+
proofNodeMatches = matchProofNode(proofNode, node);
|
|
89
|
+
|
|
90
|
+
if (proofNodeMatches) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return proofNodesMatches;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function matchProofTerminalNode(proofTerminalNode, terminalNode) {
|
|
100
|
+
const matches = proofTerminalNode.match(terminalNode),
|
|
101
|
+
proofTerminalNodeMatches = matches; ///
|
|
102
|
+
|
|
103
|
+
return proofTerminalNodeMatches;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function matchProofNonTerminalNode(proofNonTerminalNode, nonTerminalNode) {
|
|
107
|
+
let proofNonTerminalNodeMatches = false;
|
|
108
|
+
|
|
109
|
+
const ruleName = nonTerminalNode.getRuleName(),
|
|
110
|
+
proofRuleName = proofNonTerminalNode.getRuleName(); ///
|
|
111
|
+
|
|
112
|
+
if (ruleName === proofRuleName) {
|
|
113
|
+
const childNodes = nonTerminalNode.getChildNodes(),
|
|
114
|
+
proofChildNodes = proofNonTerminalNode.getChildNodes(),
|
|
115
|
+
nodes = childNodes, ///
|
|
116
|
+
proofNodes = proofChildNodes, ///
|
|
117
|
+
proofNodesMatches = matchProofNodes(proofNodes, nodes);
|
|
118
|
+
|
|
119
|
+
proofNonTerminalNodeMatches = proofNodesMatches; ///
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return proofNonTerminalNodeMatches;
|
|
123
|
+
}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import verifyStatement from "../../verify/statement";
|
|
4
4
|
|
|
5
|
+
import Assertion from "../../assertion";
|
|
6
|
+
|
|
5
7
|
import { nodeQuery } from "../../utilities/query";
|
|
8
|
+
import { nodeAsString } from "../../utilities/string";
|
|
6
9
|
|
|
7
10
|
const statementNodeQuery = nodeQuery("/unqualifiedStatement/statement!");
|
|
8
11
|
|
|
@@ -14,16 +17,80 @@ export default function verifyUnqualifiedStatement(unqualifiedStatementNode, pro
|
|
|
14
17
|
const statementNode = statementNodeQuery(unqualifiedStatementNode);
|
|
15
18
|
|
|
16
19
|
if (statementNode !== null) {
|
|
17
|
-
const
|
|
20
|
+
const derived = proofContext.isDerived();
|
|
21
|
+
|
|
22
|
+
if (derived) {
|
|
23
|
+
const assertion = Assertion.fromStatementNode(statementNode),
|
|
24
|
+
assertionMatches = proofContext.matchAssertion(assertion);
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
unqualifiedStatementVerified = assertionMatches; ///
|
|
27
|
+
} else {
|
|
20
28
|
unqualifiedStatementVerified = true;
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
31
|
|
|
32
|
+
if (unqualifiedStatementVerified) {
|
|
33
|
+
const statementString = nodeAsString(statementNode);
|
|
34
|
+
|
|
35
|
+
proofContext.debug(`Verified the '${statementString}' unqualified statement.`);
|
|
36
|
+
}
|
|
37
|
+
|
|
24
38
|
unqualifiedStatementVerified ?
|
|
25
39
|
proofContext.complete(unqualifiedStatementNode) :
|
|
26
40
|
proofContext.halt(unqualifiedStatementNode);
|
|
27
41
|
|
|
28
42
|
return unqualifiedStatementVerified;
|
|
29
43
|
}
|
|
44
|
+
|
|
45
|
+
// if (derived) {
|
|
46
|
+
// debugger
|
|
47
|
+
// } else {
|
|
48
|
+
// const types = [],
|
|
49
|
+
// context = proofContext, ///
|
|
50
|
+
// termNode = termNodeQuery(typeAssertionNode),
|
|
51
|
+
// variables = [],
|
|
52
|
+
// termString = nodeAsString(termNode),
|
|
53
|
+
// termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
|
|
54
|
+
//
|
|
55
|
+
// if (termVerifiedAsVariable) {
|
|
56
|
+
// const firstValue = first(values),
|
|
57
|
+
// variableName = termString, ///
|
|
58
|
+
// value = firstValue; ///
|
|
59
|
+
//
|
|
60
|
+
// if (value !== undefined) {
|
|
61
|
+
// proofContext.error(`The value of the ${variableName} variable is not undefined.`);
|
|
62
|
+
// } else {
|
|
63
|
+
// const type = proofContext.findTypeByTypeName(typeName),
|
|
64
|
+
// firstType = first(types),
|
|
65
|
+
// variableType = firstType, ///
|
|
66
|
+
// typeEqualToOrSubTypeOfVariableType = type.isEqualToOrSubTypeOf(variableType);
|
|
67
|
+
//
|
|
68
|
+
// if (!typeEqualToOrSubTypeOfVariableType) {
|
|
69
|
+
// proofContext.error(`The asserted type of the ${variableName} variable is not equal to or a sub-type of its declared type.`);
|
|
70
|
+
// } else {
|
|
71
|
+
// const name = variableName, ///
|
|
72
|
+
// variable = Variable.fromTypeAndName(type, name);
|
|
73
|
+
//
|
|
74
|
+
// proofContext.addVariable(variable);
|
|
75
|
+
//
|
|
76
|
+
// typeAssertionVerified = true;
|
|
77
|
+
// }
|
|
78
|
+
// }
|
|
79
|
+
// } else {
|
|
80
|
+
// const termVerifiedAgainstConstructors = verifyTermAgainstConstructors(termNode, types, values, context);
|
|
81
|
+
//
|
|
82
|
+
// if (termVerifiedAgainstConstructors) {
|
|
83
|
+
// const type = proofContext.findTypeByTypeName(typeName),
|
|
84
|
+
// firstType = first(types),
|
|
85
|
+
// termType = firstType, ///
|
|
86
|
+
// typeEqualToOrSubTypeOfTermType = type.isEqualToOrSubTypeOf(termType);
|
|
87
|
+
//
|
|
88
|
+
// if (!typeEqualToOrSubTypeOfTermType) {
|
|
89
|
+
// proofContext.error(`The asserted type of the '${termString}' term is not equal to or a sub-type of its declared type.`);
|
|
90
|
+
// } else {
|
|
91
|
+
//
|
|
92
|
+
// typeAssertionVerified = true;
|
|
93
|
+
// }
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
// }
|
package/src/verify/statement.js
CHANGED
|
@@ -27,7 +27,8 @@ export default function verifyStatement(statementNode, proofContext) {
|
|
|
27
27
|
|
|
28
28
|
statementVerified = equalityVerified; ///
|
|
29
29
|
} else if (typeAssertionNode !== null) {
|
|
30
|
-
const
|
|
30
|
+
const types = [],
|
|
31
|
+
typeAssertionVerified = verifyTypeAssertion(typeAssertionNode, types, proofContext);
|
|
31
32
|
|
|
32
33
|
statementVerified = typeAssertionVerified; ///
|
|
33
34
|
} else {
|