occam-verify-cli 0.0.478 → 0.0.479
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/conclusion.js +113 -29
- package/lib/metaSubstitution.js +5 -5
- package/lib/premise.js +145 -39
- package/lib/rule.js +74 -16
- package/lib/ruleNames.js +13 -9
- package/lib/substitution.js +12 -12
- package/lib/type.js +22 -21
- package/lib/variable.js +12 -19
- package/lib/verify/assertion/type.js +3 -2
- package/lib/verify/equality.js +85 -20
- package/lib/verify/statement/qualified.js +6 -3
- package/lib/verify/statement.js +7 -4
- package/package.json +3 -3
- package/src/conclusion.js +181 -32
- package/src/metaSubstitution.js +2 -2
- package/src/premise.js +233 -45
- package/src/rule.js +96 -16
- package/src/ruleNames.js +3 -2
- package/src/substitution.js +8 -8
- package/src/type.js +26 -20
- package/src/variable.js +10 -16
- package/src/verify/assertion/type.js +5 -2
- package/src/verify/equality.js +79 -35
- package/src/verify/statement/qualified.js +7 -2
- package/src/verify/statement.js +6 -4
package/src/type.js
CHANGED
|
@@ -17,39 +17,45 @@ export default class Type {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
isEqualTo(type) {
|
|
20
|
-
const
|
|
20
|
+
const equalTo = (this === type);
|
|
21
21
|
|
|
22
|
-
return
|
|
22
|
+
return equalTo;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
isSubTypeOf(type) {
|
|
26
|
-
let
|
|
26
|
+
let subTypeOf = false;
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
28
|
+
let superType = this.superType;
|
|
29
|
+
|
|
30
|
+
while (superType !== null) {
|
|
31
|
+
if (superType === type) {
|
|
32
|
+
subTypeOf = true;
|
|
33
|
+
|
|
34
|
+
break;
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
superType = superType.getSuperType();
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
return
|
|
40
|
+
return subTypeOf;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
isSuperTypeOf(type) {
|
|
40
|
-
let
|
|
44
|
+
let superTypeOf = false;
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
let superType = type.getSuperType();
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
while (superType !== null) {
|
|
49
|
+
if (superType === this) {
|
|
50
|
+
superTypeOf = true;
|
|
51
|
+
|
|
52
|
+
break;
|
|
49
53
|
}
|
|
54
|
+
|
|
55
|
+
superType = superType.getSuperType();
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
return
|
|
58
|
+
return superTypeOf;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
isEqualToOrSubTypeOf(type) {
|
|
@@ -68,13 +74,13 @@ export default class Type {
|
|
|
68
74
|
return equalToTypeOrSuperTypeOf;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
match(type) {
|
|
72
78
|
const equalToType = this.isEqualTo(type),
|
|
73
79
|
subTypeOfType = this.isSubTypeOf(type),
|
|
74
80
|
superTypeOfType = this.isSuperTypeOf(type),
|
|
75
|
-
|
|
81
|
+
matches = (equalToType || subTypeOfType || superTypeOfType);
|
|
76
82
|
|
|
77
|
-
return
|
|
83
|
+
return matches;
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
matchName(name) {
|
package/src/variable.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export default class Variable {
|
|
4
|
-
constructor(type, name,
|
|
4
|
+
constructor(type, name, termNode) {
|
|
5
5
|
this.type = type;
|
|
6
6
|
this.name = name;
|
|
7
|
-
this.
|
|
7
|
+
this.termNode = termNode;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
getType() {
|
|
@@ -15,18 +15,12 @@ export default class Variable {
|
|
|
15
15
|
return this.name;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
return this.
|
|
18
|
+
getTermNode() {
|
|
19
|
+
return this.termNode;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return defined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
setValue(value) {
|
|
29
|
-
this.value = value;
|
|
22
|
+
setTermNode(termNode) {
|
|
23
|
+
this.termNode = termNode;
|
|
30
24
|
}
|
|
31
25
|
|
|
32
26
|
matchName(name) {
|
|
@@ -41,9 +35,9 @@ export default class Variable {
|
|
|
41
35
|
if (variable === this) {
|
|
42
36
|
equalTo = true;
|
|
43
37
|
} else {
|
|
44
|
-
const
|
|
38
|
+
const termNode = variable.getTermNode();
|
|
45
39
|
|
|
46
|
-
if (
|
|
40
|
+
if (termNode === this.termNode) {
|
|
47
41
|
equalTo = true;
|
|
48
42
|
}
|
|
49
43
|
}
|
|
@@ -66,8 +60,8 @@ export default class Variable {
|
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
static fromTypeAndName(type, name) {
|
|
69
|
-
const
|
|
70
|
-
variable = new Variable(type, name,
|
|
63
|
+
const termNode = null,
|
|
64
|
+
variable = new Variable(type, name, termNode);
|
|
71
65
|
|
|
72
66
|
return variable;
|
|
73
67
|
}
|
|
@@ -97,8 +97,11 @@ function verifyVariableTypeAssertion(typeAssertionNode, proofContext) {
|
|
|
97
97
|
firstVariable = first(variables),
|
|
98
98
|
variable = firstVariable, ///
|
|
99
99
|
variableName = variable.getName(),
|
|
100
|
-
variableType = variable.getType()
|
|
101
|
-
|
|
100
|
+
variableType = variable.getType();
|
|
101
|
+
|
|
102
|
+
const assertedTypeEqualToOrSubTypeOfVariableType = (variableType === null) ?
|
|
103
|
+
true : ///
|
|
104
|
+
assertedType.isEqualToOrSubTypeOf(variableType);
|
|
102
105
|
|
|
103
106
|
if (!assertedTypeEqualToOrSubTypeOfVariableType) {
|
|
104
107
|
proofContext.error(`The asserted type is not equal to or a sub-type of the '${variableName}' variable type.`);
|
package/src/verify/equality.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Equality from "../equality";
|
|
4
|
+
import Variable from "../variable";
|
|
4
5
|
import verifyTerm from "../verify/term";
|
|
5
6
|
|
|
6
7
|
import { nodeQuery } from "../utilities/query";
|
|
7
8
|
import { nodeAsString } from "../utilities/string";
|
|
8
9
|
import { first, second } from "../utilities/array";
|
|
10
|
+
import { verifyTermAsVariable } from "../verify/term";
|
|
9
11
|
import { MAXIMUM_INDEXES_LENGTH } from "../constants";
|
|
10
12
|
|
|
11
13
|
const leftTermNodeQuery = nodeQuery("/equality/term[0]"),
|
|
@@ -20,37 +22,6 @@ export default function verifyEquality(equalityNode, proofContext) {
|
|
|
20
22
|
|
|
21
23
|
proofContext.debug(`Verifying the '${equalityString}' equality...`);
|
|
22
24
|
|
|
23
|
-
const equalityTypesVerified = verifyEqualityTypes(equalityNode, proofContext);
|
|
24
|
-
|
|
25
|
-
if (equalityTypesVerified) {
|
|
26
|
-
const derived = proofContext.isDerived();
|
|
27
|
-
|
|
28
|
-
if (derived) {
|
|
29
|
-
const equality = Equality.fromEqualityNode(equalityNode),
|
|
30
|
-
proofSteps = proofContext.getProofSteps(),
|
|
31
|
-
equalities = equalitiesFromProofSteps(proofSteps),
|
|
32
|
-
equalityEquates = equality.equate(equalities, proofContext);
|
|
33
|
-
|
|
34
|
-
equalityVerified = equalityEquates; ///
|
|
35
|
-
} else {
|
|
36
|
-
equalityVerified = true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (equalityVerified) {
|
|
41
|
-
proofContext.info(`Verified the '${equalityString}' equality.`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
equalityVerified ?
|
|
45
|
-
proofContext.complete(equalityNode) :
|
|
46
|
-
proofContext.halt(equalityNode);
|
|
47
|
-
|
|
48
|
-
return equalityVerified;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function verifyEqualityTypes(equalityNode, proofContext) {
|
|
52
|
-
let equalityTypesVerified = false;
|
|
53
|
-
|
|
54
25
|
const types = [],
|
|
55
26
|
context = proofContext, ///
|
|
56
27
|
leftTermNode = leftTermNodeQuery(equalityNode),
|
|
@@ -63,14 +34,66 @@ function verifyEqualityTypes(equalityNode, proofContext) {
|
|
|
63
34
|
secondType = second(types),
|
|
64
35
|
leftType = firstType, ///
|
|
65
36
|
rightType = secondType, ///
|
|
66
|
-
|
|
37
|
+
leftTermString = nodeAsString(leftTermNode),
|
|
38
|
+
rightTermString = nodeAsString(rightTermNode);
|
|
39
|
+
|
|
40
|
+
if ((leftType === null) && (rightType === null)) {
|
|
41
|
+
proofContext.error(`The types of the '${leftTermString}' and '${rightTermString}' terms are both undefined and therefore the terms cannot be equated.`);
|
|
42
|
+
} else if (rightType === null) {
|
|
43
|
+
const type = leftType, ///
|
|
44
|
+
termNode = rightTermNode, ///
|
|
45
|
+
variable = addVariable(type, termNode, proofContext);
|
|
46
|
+
|
|
47
|
+
if (variable !== null) {
|
|
48
|
+
const leftTypeName = leftType.getName();
|
|
49
|
+
|
|
50
|
+
proofContext.info(`The '${rightTermString}' variable has been given the '${leftTypeName}' type.`);
|
|
51
|
+
|
|
52
|
+
equalityVerified = true;
|
|
53
|
+
}
|
|
54
|
+
} else if (leftType === null) {
|
|
55
|
+
const type = rightType, ///
|
|
56
|
+
termNode = leftType, ///
|
|
57
|
+
variable = addVariable(type, termNode, proofContext);
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
if (variable !== null) {
|
|
60
|
+
const rightTypeName = rightType.getName();
|
|
61
|
+
|
|
62
|
+
proofContext.info(`The '${rightTermString}' variable has been given the '${rightTypeName}' type.`);
|
|
63
|
+
|
|
64
|
+
equalityVerified = true;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const leftTypeMatchesRightType = leftType.match(rightType);
|
|
68
|
+
|
|
69
|
+
if (!leftTypeMatchesRightType) {
|
|
70
|
+
proofContext.error(`The types of the '${leftTermString}' and '${rightTermString}' terms do not match and therefore the terms cannot be equated.`);
|
|
71
|
+
} else {
|
|
72
|
+
const derived = proofContext.isDerived();
|
|
73
|
+
|
|
74
|
+
if (!derived) {
|
|
75
|
+
equalityVerified = true;
|
|
76
|
+
} else {
|
|
77
|
+
const equality = Equality.fromEqualityNode(equalityNode),
|
|
78
|
+
proofSteps = proofContext.getProofSteps(),
|
|
79
|
+
equalities = equalitiesFromProofSteps(proofSteps),
|
|
80
|
+
equalityEquates = equality.equate(equalities, proofContext);
|
|
81
|
+
|
|
82
|
+
equalityVerified = equalityEquates; ///
|
|
83
|
+
}
|
|
84
|
+
}
|
|
70
85
|
}
|
|
71
86
|
}
|
|
72
87
|
|
|
73
|
-
|
|
88
|
+
if (equalityVerified) {
|
|
89
|
+
proofContext.info(`Verified the '${equalityString}' equality.`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
equalityVerified ?
|
|
93
|
+
proofContext.complete(equalityNode) :
|
|
94
|
+
proofContext.halt(equalityNode);
|
|
95
|
+
|
|
96
|
+
return equalityVerified;
|
|
74
97
|
}
|
|
75
98
|
|
|
76
99
|
function equalitiesFromProofSteps(proofSteps) {
|
|
@@ -90,3 +113,24 @@ function equalitiesFromProofSteps(proofSteps) {
|
|
|
90
113
|
|
|
91
114
|
return equalities;
|
|
92
115
|
}
|
|
116
|
+
|
|
117
|
+
function addVariable(type, termNode, proofContext) {
|
|
118
|
+
let variable = null;
|
|
119
|
+
|
|
120
|
+
const variables = [],
|
|
121
|
+
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, proofContext);
|
|
122
|
+
|
|
123
|
+
if (termVerifiedAsVariable) {
|
|
124
|
+
const firstVariable = first(variables);
|
|
125
|
+
|
|
126
|
+
variable = firstVariable; ///
|
|
127
|
+
|
|
128
|
+
const name = variable.getName();
|
|
129
|
+
|
|
130
|
+
variable = Variable.fromTypeAndName(type, name); ///
|
|
131
|
+
|
|
132
|
+
proofContext.addVariable(variable);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return variable;
|
|
136
|
+
}
|
|
@@ -22,9 +22,14 @@ export default function verifyQualifiedStatement(qualifiedStatementNode, proofCo
|
|
|
22
22
|
|
|
23
23
|
qualifiedStatementVerified = statementVerified; ///
|
|
24
24
|
} else {
|
|
25
|
-
const referenceName = referenceNameFromReferenceNode(referenceNode)
|
|
25
|
+
const referenceName = referenceNameFromReferenceNode(referenceNode),
|
|
26
|
+
rule = proofContext.findRuleByReferenceName(referenceName);
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
if (rule !== null) {
|
|
29
|
+
const ruleMatchesStatement = rule.matchStatement(statementNode, proofContext);
|
|
30
|
+
|
|
31
|
+
qualifiedStatementVerified = ruleMatchesStatement; ///
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
|
package/src/verify/statement.js
CHANGED
|
@@ -20,16 +20,18 @@ export default function verifyStatement(statementNode, proofContext) {
|
|
|
20
20
|
|
|
21
21
|
proofContext.debug(`Verifying the '${statementString}' statement...`);
|
|
22
22
|
|
|
23
|
-
if (
|
|
23
|
+
if (false) {
|
|
24
|
+
///
|
|
25
|
+
} else if (equalityNode !== null) {
|
|
24
26
|
const equalityVerified = verifyEquality(equalityNode, proofContext);
|
|
25
27
|
|
|
26
28
|
statementVerified = equalityVerified; ///
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (typeAssertionNode !== null) {
|
|
29
|
+
} else if (typeAssertionNode !== null) {
|
|
30
30
|
const typeAssertionVerified = verifyTypeAssertion(typeAssertionNode, proofContext);
|
|
31
31
|
|
|
32
32
|
statementVerified = typeAssertionVerified; ///
|
|
33
|
+
} else {
|
|
34
|
+
statementVerified = true;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
statementVerified ?
|