occam-verify-cli 0.0.1072 → 0.0.1074

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/src/equality.js CHANGED
@@ -3,10 +3,12 @@
3
3
  import shim from "./shim";
4
4
  import equalityUnifier from "./unifier/equality";
5
5
  import EqualityAssignment from "./assignment/equality";
6
+ import VariableAssignment from "./assignment/variable";
6
7
 
7
8
  import { nodeQuery } from "./utilities/query";
8
9
 
9
- const leftTermNodeQuery = nodeQuery("/equality/term[0]"),
10
+ const variableNodeQuery = nodeQuery("/term/variable!"),
11
+ leftTermNodeQuery = nodeQuery("/equality/term[0]"),
10
12
  rightTermNodeQuery = nodeQuery("/equality/term[1]");
11
13
 
12
14
  export default class Equality {
@@ -28,6 +30,25 @@ export default class Equality {
28
30
  return this.rightTerm;
29
31
  }
30
32
 
33
+ getType() {
34
+ let type;
35
+
36
+ const leftTermType = this.leftTerm.getType(),
37
+ rightTermType = this.rightTerm.getType(),
38
+ leftTermTypeEqualToOrSubTypeOfRightTermType = leftTermType.isEqualToOrSubTypeOf(rightTermType),
39
+ rightTermTypeEqualToOrSubTypeOfLeftTermType = rightTermType.isEqualToOrSubTypeOf(leftTermType);
40
+
41
+ if (leftTermTypeEqualToOrSubTypeOfRightTermType) {
42
+ type = leftTermType; ///
43
+ }
44
+
45
+ if (rightTermTypeEqualToOrSubTypeOfLeftTermType) {
46
+ type = rightTermType; ///
47
+ }
48
+
49
+ return type;
50
+ }
51
+
31
52
  isReflexive() {
32
53
  const leftTermMatchesRightTerm = this.leftTerm.match(this.rightTerm),
33
54
  reflexive = leftTermMatchesRightTerm; ///
@@ -51,25 +72,57 @@ export default class Equality {
51
72
 
52
73
  localContext.trace(`Verifying the '${equalityString}' equality...`);
53
74
 
54
- let verifiedWhenStated = false,
55
- verifiedWhenDerived = false;
56
-
57
- if (stated) {
58
- verifiedWhenStated = this.verifyWhenStated(localContext);
59
- } else {
60
- verifiedWhenDerived = this.verifyWhenDerived(localContext);
61
- }
75
+ const termsVerified = this.verifyTerms(localContext);
62
76
 
63
- if (verifiedWhenStated || verifiedWhenDerived) {
64
- if (assignments !== null) {
65
- const equality = this, //
66
- equalityAssignment = EqualityAssignment.fromEquality(equality),
67
- assignment = equalityAssignment; ///
77
+ if (termsVerified) {
78
+ let verifiedWhenStated = false,
79
+ verifiedWhenDerived = false;
68
80
 
69
- assignments.push(assignment);
81
+ if (stated) {
82
+ verifiedWhenStated = this.verifyWhenStated(localContext);
83
+ } else {
84
+ verifiedWhenDerived = this.verifyWhenDerived(localContext);
70
85
  }
71
86
 
72
- verified = true;
87
+ if (verifiedWhenStated || verifiedWhenDerived) {
88
+ if (assignments !== null) {
89
+ const { Variable } = shim,
90
+ type = this.getType(),
91
+ leftTermNode = this.leftTerm.getNode(),
92
+ rightTermNode = this.rightTerm.getNode(),
93
+ leftVariableNode = variableNodeQuery(leftTermNode),
94
+ rightVariableNode = variableNodeQuery(rightTermNode),
95
+ leftVariable = Variable.fromVariableNodeAndType(leftVariableNode, type, localContext),
96
+ rightVariable = Variable.fromVariableNodeAndType(rightVariableNode, type, localContext);
97
+
98
+ let assignment;
99
+
100
+ if (leftVariable !== null) {
101
+ const leftVariableAssignment = VariableAssignment.fromVariable(leftVariable);
102
+
103
+ assignment = leftVariableAssignment; ///
104
+
105
+ assignments.push(assignment);
106
+ }
107
+
108
+ if (rightVariable !== null) {
109
+ const rightVariableAssignment = VariableAssignment.fromVariable(rightVariable);
110
+
111
+ assignment = rightVariableAssignment; ///
112
+
113
+ assignments.push(assignment);
114
+ }
115
+
116
+ const equality = this, //
117
+ equalityAssignment = EqualityAssignment.fromEquality(equality);
118
+
119
+ assignment = equalityAssignment; ///
120
+
121
+ assignments.push(assignment);
122
+ }
123
+
124
+ verified = true;
125
+ }
73
126
  }
74
127
 
75
128
  if (verified) {
@@ -122,9 +175,7 @@ export default class Equality {
122
175
 
123
176
  localContext.trace(`Verifying the '${equalityString}' stated equality...`);
124
177
 
125
- const termsVerified = this.verifyTerms(localContext);
126
-
127
- verifiedWhenStated = termsVerified; ///
178
+ verifiedWhenStated = true;
128
179
 
129
180
  if (verifiedWhenStated) {
130
181
  localContext.debug(`...verified the '${equalityString}' stated equality.`);
@@ -134,19 +185,15 @@ export default class Equality {
134
185
  }
135
186
 
136
187
  verifyWhenDerived(localContext) {
137
- let verifiedWhenDerived = false;
188
+ let verifiedWhenDerived;
138
189
 
139
190
  const equalityString = this.string; ///
140
191
 
141
192
  localContext.trace(`Verifying the '${equalityString}' derived equality...`);
142
193
 
143
- const termsVerified = this.verifyTerms(localContext);
194
+ const equal = this.isEqual(localContext);
144
195
 
145
- if (termsVerified) {
146
- const equal = this.isEqual(localContext);
147
-
148
- verifiedWhenDerived = equal; ///
149
- }
196
+ verifiedWhenDerived = equal; ///
150
197
 
151
198
  if (verifiedWhenDerived) {
152
199
  localContext.debug(`...verified the '${equalityString}' derived equality.`);
@@ -2,7 +2,6 @@
2
2
 
3
3
  import { nodeQuery } from "./utilities/query";
4
4
  import { stripBracketsFromTermNode } from "./utilities/brackets";
5
- import { variableNameFromVariableNode } from "./utilities/name";
6
5
 
7
6
  const variableNodeQuery = nodeQuery("/term/variable!");
8
7
 
@@ -15,17 +14,18 @@ export default class Equivalence {
15
14
  return this.terms;
16
15
  }
17
16
 
18
- setTerms(terms) {
19
- this.terms = terms;
20
- }
17
+ addTerm(term, localContext) {
18
+ const termString = term.getString(),
19
+ equivalenceString = this.asString(); ///
20
+
21
+ localContext.trace(`Adding the '${termString}' term to the '${equivalenceString}' equivalence.`);
21
22
 
22
- addTerm(term) {
23
23
  this.terms.push(term);
24
24
  }
25
25
 
26
- getType(localContext) {
26
+ getType() {
27
27
  const type = this.terms.reduce((type, term) => {
28
- const termType = termTypeFromTerm(term, localContext);
28
+ const termType = term.getType();
29
29
 
30
30
  if (type === null) {
31
31
  type = termType; ///
@@ -43,10 +43,10 @@ export default class Equivalence {
43
43
  return type;
44
44
  }
45
45
 
46
- matchType(type, localContext) {
46
+ matchType(type) {
47
47
  const typeA = type; ///
48
48
 
49
- type = this.getType(localContext);
49
+ type = this.getType();
50
50
 
51
51
  const typeB = type; ///
52
52
 
@@ -198,6 +198,27 @@ export default class Equivalence {
198
198
  return implicitlyGroundedTerms;
199
199
  }
200
200
 
201
+ asString() {
202
+ let string;
203
+
204
+ string = this.terms.reduce((string, term) => {
205
+ const termString = term.getString();
206
+
207
+ string = (string === null) ?
208
+ termString :
209
+ `${string} ${termString}`;
210
+
211
+ return string;
212
+ }, null);
213
+
214
+ const type = this.getType(),
215
+ typeString = type.getString();
216
+
217
+ string = `${string}:${typeString}`;
218
+
219
+ return string;
220
+ }
221
+
201
222
  static merge(leftEquivalence, rightEquivalence) {
202
223
  const leftEquivalenceTerms = leftEquivalence.getTerms(),
203
224
  rightEquivalenceTerms = rightEquivalence.getTerms(),
@@ -220,22 +241,3 @@ export default class Equivalence {
220
241
  return equivalence;
221
242
  }
222
243
  }
223
-
224
- function termTypeFromTerm(term, localContext) {
225
- let termType;
226
-
227
- const termNode = term.getNode(),
228
- variableNode = variableNodeQuery(termNode);
229
-
230
- if (variableNode !== null) {
231
- const variableName = variableNameFromVariableNode(variableNode),
232
- variable = localContext.findVariableByVariableName(variableName),
233
- variableType = variable.getType();
234
-
235
- termType = variableType; ///
236
- } else {
237
- termType = term.getType();
238
- }
239
-
240
- return termType;
241
- }
@@ -4,7 +4,7 @@ import Variable from "../../variable";
4
4
 
5
5
  import { nodeQuery } from "../../utilities/query";
6
6
 
7
- const variableNodeQuery = nodeQuery("/term/variable");
7
+ const variableNodeQuery = nodeQuery("/term/variable!");
8
8
 
9
9
  function verifyTermAsVariable(term, localContext, verifyAhead) {
10
10
  let termVerifiedAsVariable = false;
package/src/proofStep.js CHANGED
@@ -7,6 +7,7 @@ import QualifiedStatement from "./statement/qualified";
7
7
  import UnqualifiedStatement from "./statement/unqualified";
8
8
 
9
9
  import { nodeQuery } from "./utilities/query";
10
+ import { assignAssignments } from "./utilities/assignments";
10
11
 
11
12
  const subproofNodeQuery = nodeQuery("/proofStep|lastProofStep/subproof"),
12
13
  qualifiedStatementNodeQuery = nodeQuery("/proofStep|lastProofStep/qualifiedStatement"),
@@ -91,7 +92,13 @@ class ProofStep {
91
92
  assignments = [],
92
93
  unqualifiedStatementVerified = this.unqualifiedStatement.verify(assignments, stated, localContext);
93
94
 
94
- verified = unqualifiedStatementVerified; ///
95
+ if (unqualifiedStatementVerified) {
96
+ const assignmentsAssigned = assignAssignments(assignments, localContext);
97
+
98
+ if (assignmentsAssigned) {
99
+ verified = true;
100
+ }
101
+ }
95
102
  }
96
103
 
97
104
  if (verified) {
@@ -50,7 +50,6 @@ class UnqualifiedStatement {
50
50
  if (verified) {
51
51
  localContext.debug(`...verified the '${unqualifiedStatementString}' unqualified statement.`);
52
52
  }
53
-
54
53
  } else {
55
54
  localContext.debug(`Cannot verify the '${unqualifiedStatementString}' unqualified statement because it is nonsense.`);
56
55
  }
package/src/type.js CHANGED
@@ -36,37 +36,24 @@ class Type {
36
36
  }
37
37
 
38
38
  isSubTypeOf(type) {
39
- let subTypeOf = false;
40
-
41
- let superType = this.superType;
42
-
43
- while (superType !== null) {
44
- if (superType === type) {
45
- subTypeOf = true;
46
-
47
- break;
48
- }
49
-
50
- superType = superType.getSuperType();
39
+ let subTypeOf;
40
+
41
+ if (false) {
42
+ ///
43
+ } else if (this === objectType) {
44
+ subTypeOf = false;
45
+ } else if (this.superType === type) {
46
+ subTypeOf = true;
47
+ } else {
48
+ subTypeOf = this.superType.isSubTypeOf(type);
51
49
  }
52
50
 
53
51
  return subTypeOf;
54
52
  }
55
53
 
56
54
  isSuperTypeOf(type) {
57
- let superTypeOf = false;
58
-
59
- let superType = type.getSuperType();
60
-
61
- while (superType !== null) {
62
- if (superType === this) {
63
- superTypeOf = true;
64
-
65
- break;
66
- }
67
-
68
- superType = superType.getSuperType();
69
- }
55
+ const subTypeOf = type.isSubTypeOf(this),
56
+ superTypeOf = subTypeOf; ///
70
57
 
71
58
  return superTypeOf;
72
59
  }
@@ -6,9 +6,9 @@ import Equivalence from "../equivalence";
6
6
 
7
7
  const { push, compress, separate } = arrayUtilities;
8
8
 
9
- export function mergeEquivalences(equivalencesA, equivalencesB, localContext) {
10
- const typesA = typesFromEquivalences(equivalencesA, localContext),
11
- typesB = typesFromEquivalences(equivalencesB, localContext),
9
+ export function mergeEquivalences(equivalencesA, equivalencesB) {
10
+ const typesA = typesFromEquivalences(equivalencesA),
11
+ typesB = typesFromEquivalences(equivalencesB),
12
12
  types = [
13
13
  ...typesA,
14
14
  ...typesB
@@ -23,8 +23,8 @@ export function mergeEquivalences(equivalencesA, equivalencesB, localContext) {
23
23
  const equivalences = types.map((type) => {
24
24
  let equivalence;
25
25
 
26
- const equivalenceA = findEquivalenceByType(equivalencesA, type, localContext),
27
- equivalenceB = findEquivalenceByType(equivalencesB, type, localContext);
26
+ const equivalenceA = findEquivalenceByType(equivalencesA, type),
27
+ equivalenceB = findEquivalenceByType(equivalencesB, type);
28
28
 
29
29
  if ((equivalenceA !== null) && (equivalenceB !== null)) {
30
30
  const leftEquivalence = equivalenceA, ///
@@ -43,9 +43,9 @@ export function mergeEquivalences(equivalencesA, equivalencesB, localContext) {
43
43
  return equivalences;
44
44
  }
45
45
 
46
- export function findEquivalenceByType(equivalences, type, localContext) {
46
+ export function findEquivalenceByType(equivalences, type) {
47
47
  const equivalence = equivalences.find((equivalence) => {
48
- const equivalenceMatchesType = equivalence.matchType(type, localContext);
48
+ const equivalenceMatchesType = equivalence.matchType(type);
49
49
 
50
50
  if (equivalenceMatchesType) {
51
51
  return true;
@@ -127,9 +127,9 @@ export function groundedTermsAndDefinedVariablesFromFromEquivalences(equivalence
127
127
  }
128
128
  }
129
129
 
130
- function typesFromEquivalences(equivalences, localContext) {
130
+ function typesFromEquivalences(equivalences) {
131
131
  const types = equivalences.map((equivalence) => {
132
- const type = equivalence.getType(localContext);
132
+ const type = equivalence.getType();
133
133
 
134
134
  return type;
135
135
  });
package/src/variable.js CHANGED
@@ -70,14 +70,14 @@ class Variable {
70
70
  variableName = variableNameFromVariableNode(variableNode),
71
71
  variable = localContext.findVariableByVariableName(variableName);
72
72
 
73
- if (variable === null) {
74
- localContext.debug(`The '${variableString}' variable is not present.`);
75
- } else {
73
+ if (variable !== null) {
76
74
  const type = variable.getType();
77
75
 
78
76
  this.type = type;
79
77
 
80
78
  verified = true;
79
+ } else {
80
+ localContext.debug(`The '${variableString}' variable is not present.`);
81
81
  }
82
82
 
83
83
  if (verified) {
@@ -248,11 +248,16 @@ class Variable {
248
248
  }
249
249
 
250
250
  static fromVariableNodeAndType(variableNode, type, localContext) {
251
- const node = variableNode, ///
252
- variableName = variableNameFromVariableNode(variableNode),
253
- string = localContext.nodeAsString(node),
254
- name = variableName, ///
255
- variable = new Variable(localContext, string, node, name, type);
251
+ let variable = null;
252
+
253
+ if (variableNode !== null) {
254
+ const node = variableNode, ///
255
+ variableName = variableNameFromVariableNode(variableNode),
256
+ string = localContext.nodeAsString(node),
257
+ name = variableName; ///
258
+
259
+ variable = new Variable(localContext, string, node, name, type);
260
+ }
256
261
 
257
262
  return variable;
258
263
  }