occam-verify-cli 1.0.902 → 1.0.906

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.
@@ -183,9 +183,9 @@ export default define(class Equality extends Element {
183
183
 
184
184
  const leftTermType = leftTerm.getType(),
185
185
  rightTermType = rightTerm.getType(),
186
- leftTermTypeComparableToRightTermType = leftTermType.isComparableTo(rightTermType);
186
+ leftTermTypeEqualToSubTypeOrSuperTypeOfRightTermType = leftTermType.isEqualToSubTypeOrSuperTypeOf(rightTermType);
187
187
 
188
- if (leftTermTypeComparableToRightTermType) {
188
+ if (leftTermTypeEqualToSubTypeOrSuperTypeOfRightTermType) {
189
189
  validatesForwards = true;
190
190
  }
191
191
 
@@ -6,9 +6,9 @@ import { arrayUtilities } from "necessary";
6
6
  import elements from "../elements";
7
7
 
8
8
  import { define } from "../elements";
9
- import { instantiate } from "../utilities/context";
10
9
  import { instantiateSignature } from "../process/instantiate";
11
10
  import { termsFromSignatureNode } from "../utilities/element";
11
+ import { attempt, serialise, unserialise, instantiate } from "../utilities/context";
12
12
 
13
13
  const { match, compare, correlate } = arrayUtilities;
14
14
 
@@ -37,11 +37,17 @@ export default define(class Signature extends Element {
37
37
 
38
38
  context.trace(`Verifying the '${signatureString}' signature...`);
39
39
 
40
- const signature = this.validate(context);
40
+ attempt((context) => {
41
+ const termsValidate = this.validateTerms(context);
41
42
 
42
- if (signature !== null) {
43
- verifies = true;
44
- }
43
+ if (termsValidate !== null) {
44
+ verifies = true;
45
+ }
46
+
47
+ if (verifies) {
48
+ this.commit(context);
49
+ }
50
+ }, context);
45
51
 
46
52
  if (verifies) {
47
53
  context.debug(`...verified the '${signatureString}' signature.`);
@@ -50,71 +56,33 @@ export default define(class Signature extends Element {
50
56
  return verifies;
51
57
  }
52
58
 
53
- validate(context) {
54
- let signature = null;
59
+ validateTerms(context) {
60
+ let termsValidate;
55
61
 
56
62
  const signatureString = this.getString(); ///
57
63
 
58
- context.trace(`Validating the '${signatureString}' signature...`);
59
-
60
- const terms = [],
61
- termsValidate = this.validateTerms(terms, context);
62
-
63
- if (termsValidate) {
64
- this.terms = terms;
65
-
66
- signature = this; ///
67
- }
68
-
69
- if (signature) {
70
- context.debug(`...validated the '${signatureString}' signature.`);
71
- }
72
-
73
- return signature
74
- }
64
+ context.trace(`Validating the '${signatureString}' signature's terms...`);
75
65
 
76
- validateTerm(term, terms, context) {
77
- let termValidates = false;
66
+ const terms = [];
78
67
 
79
- const termString = term.getString(),
80
- signatureString = this.getString(); ///
68
+ termsValidate = this.terms.every((term) => {
69
+ term = term.validate(context, (term) => { ///
70
+ const validatesForwards = true;
81
71
 
82
- context.trace(`Validating the '${signatureString}' signature's '${termString}' term...`);
72
+ return validatesForwards;
73
+ });
83
74
 
84
- term = term.validate(context, (term) => { ///
85
- const validatesForwards = true;
75
+ if (term !== null) {
76
+ terms.push(term);
86
77
 
87
- return validatesForwards;
78
+ return true;
79
+ }
88
80
  });
89
81
 
90
- if (term !== null) {
91
- terms.push(term);
92
-
93
- termValidates = true;
94
- }
95
-
96
- if (termValidates) {
97
- context.debug(`...validated the '${signatureString}' signature's '${termString}' term.`);
82
+ if (termsValidate) {
83
+ this.terms = terms;
98
84
  }
99
85
 
100
- return termValidates
101
- }
102
-
103
- validateTerms(terms, context) {
104
- let termsValidate;
105
-
106
- const signatureString = this.getString(); ///
107
-
108
- context.trace(`Validating the '${signatureString}' signature's terms...`);
109
-
110
- termsValidate = terms.every((term) => {
111
- const termValidates = this.validateTerm(term, terms, context);
112
-
113
- if (termValidates) {
114
- return true;
115
- }
116
- })
117
-
118
86
  if (termsValidate){
119
87
  context.debug(`...validated the '${signatureString}' signature's terms.`);
120
88
  }
@@ -219,25 +187,35 @@ export default define(class Signature extends Element {
219
187
  static name = "Signature";
220
188
 
221
189
  toJSON() {
222
- const string = this.getString(),
223
- lineIndex = this.getLineIndex(),
224
- json = {
225
- string,
226
- lineIndex
227
- };
228
-
229
- return json;
190
+ const context = this.getContext();
191
+
192
+ return serialise((context) => {
193
+ const string = this.getString(),
194
+ lineIndex = this.getLineIndex(),
195
+ json = {
196
+ context,
197
+ string,
198
+ lineIndex
199
+ };
200
+
201
+ return json;
202
+ }, context);
230
203
  }
231
204
 
232
205
  static fromJSON(json, context) {
233
- return instantiate((context) => {
234
- const { string, lineIndex } = json,
235
- signatureNode = instantiateSignature(string, context),
236
- node = signatureNode, ///
237
- terms = termsFromSignatureNode(signatureNode, context),
238
- signature = new Signature(context, string, node, lineIndex, terms);
239
-
240
- return signature;
241
- }, context);
206
+ let signature;
207
+
208
+ unserialise((json, context) => {
209
+ instantiate((context) => {
210
+ const { string, lineIndex } = json,
211
+ signatureNode = instantiateSignature(string, context),
212
+ node = signatureNode, ///
213
+ terms = termsFromSignatureNode(signatureNode, context);
214
+
215
+ signature = new Signature(context, string, node, lineIndex, terms);
216
+ }, context);
217
+ }, json, context);
218
+
219
+ return signature;
242
220
  }
243
221
  });
@@ -58,7 +58,7 @@ export default define(class Axiom extends TopLevelAssertion {
58
58
 
59
59
  context.trace(`Verifying the '${axiomString}' axiom...`);
60
60
 
61
- const signatureVerifies = this.verifySignature();
61
+ const signatureVerifies = this.verifySignature(context);
62
62
 
63
63
  if (signatureVerifies) {
64
64
  verifies = await super.verify(context);
@@ -75,16 +75,23 @@ export default define(class Axiom extends TopLevelAssertion {
75
75
  return verifies;
76
76
  }
77
77
 
78
- verifySignature() {
78
+ verifySignature(context) {
79
79
  let signatureVerifies;
80
80
 
81
81
  const satisfiable = this.isSatisfiable();
82
82
 
83
83
  if (satisfiable) {
84
- const context = this.getContext(),
85
- signature = this.getSignature();
84
+ const axiomString = this.getString(); ///
85
+
86
+ context.trace(`Verifying the '${axiomString}' axiom's signature...`);
87
+
88
+ const signature = this.getSignature();
86
89
 
87
90
  signatureVerifies = signature.verify(context);
91
+
92
+ if (signatureVerifies) {
93
+ context.trace(`...verified the '${axiomString}' axiom's signature.`);
94
+ }
88
95
  } else {
89
96
  signatureVerifies = true
90
97
  }
@@ -210,15 +210,6 @@ export default define(class Type extends Element {
210
210
  return superTypeOf;
211
211
  }
212
212
 
213
- isComparableTo(type) {
214
- const equalTo = this.isEqualTo(type),
215
- subTypeOf = this.isSubTypeOf(type),
216
- superTypeOf = this.isSuperTypeOf(type),
217
- comparableTo = (equalTo || subTypeOf || superTypeOf);
218
-
219
- return comparableTo;
220
- }
221
-
222
213
  isEqualToOrSubTypeOf(type) {
223
214
  const equalTo = this.isEqualTo(type),
224
215
  subTypeOf = this.isSubTypeOf(type),
@@ -235,6 +226,15 @@ export default define(class Type extends Element {
235
226
  return equalToOrSuperTypeOf;
236
227
  }
237
228
 
229
+ isEqualToSubTypeOrSuperTypeOf(type) {
230
+ const equalTo = this.isEqualTo(type),
231
+ subTypeOf = this.isSubTypeOf(type),
232
+ superTypeOf = this.isSuperTypeOf(type),
233
+ equalToSubTypeOrSuperTypeOf = (equalTo || subTypeOf || superTypeOf);
234
+
235
+ return equalToSubTypeOrSuperTypeOf;
236
+ }
237
+
238
238
  compareTypeName(typeName) {
239
239
  const nameTypeName = (this.name === typeName),
240
240
  comparesToTypeName = nameTypeName; ///
@@ -11,9 +11,9 @@ export function variableAssignmentFromTermAndType(term, type, context) {
11
11
 
12
12
  if (termSingular) {
13
13
  const termType = term.getType(),
14
- termTypeEqualToType = termType.isEqualTo(type);
14
+ termTypeSuperTypeOfType = termType.isSuperTypeOf(type);
15
15
 
16
- if (!termTypeEqualToType) {
16
+ if (termTypeSuperTypeOfType) {
17
17
  const variableNode = term.getVariableNode(),
18
18
  variable = variableFromVariableNode(variableNode, context);
19
19
 
@@ -1166,7 +1166,7 @@ export function frameFromJudgementNode(judgementNode, context) {
1166
1166
  }
1167
1167
 
1168
1168
  export function termsFromSignatureNode(signatureNode, context) {
1169
- const termNodes = signatureNode.getAssumptionNodes(),
1169
+ const termNodes = signatureNode.getTermNodes(),
1170
1170
  terms = termsFromTermNodes(termNodes, context);
1171
1171
 
1172
1172
  return terms;
@@ -518,11 +518,11 @@ export function referencesFromJSON(json, context) {
518
518
  let { references } = json;
519
519
 
520
520
  const { Reference } = elements,
521
- referencesJSON = references; ///
521
+ referencesJSON = references; ///
522
522
 
523
523
  references = referencesJSON.map((referenceJSON) => {
524
524
  const json = referenceJSON, ///
525
- reference = Reference.fromJSON(json, context);
525
+ reference = Reference.fromJSON(json, context);
526
526
 
527
527
  return reference;
528
528
  });
@@ -530,6 +530,22 @@ export function referencesFromJSON(json, context) {
530
530
  return references;
531
531
  }
532
532
 
533
+ export function signaturesFromJSON(json, context) {
534
+ let { signatures } = json;
535
+
536
+ const { Signature } = elements,
537
+ signaturesJSON = signatures; ///
538
+
539
+ signatures = signaturesJSON.map((signatureJSON) => {
540
+ const json = signatureJSON, ///
541
+ signature = Signature.fromJSON(json, context);
542
+
543
+ return signature;
544
+ });
545
+
546
+ return signatures;
547
+ }
548
+
533
549
  export function conjecturesFromJSON(json, context) {
534
550
  let { conjectures } = json;
535
551
 
@@ -1072,6 +1088,16 @@ export function statementsToStatementsJSON(statements) {
1072
1088
  return statementsJSON;
1073
1089
  }
1074
1090
 
1091
+ export function signaturesToSignaturesJSON(signatures) {
1092
+ const signaturesJSON = signatures.map((signature) => {
1093
+ const signatureJSON = signature.toJSON();
1094
+
1095
+ return signatureJSON;
1096
+ });
1097
+
1098
+ return signaturesJSON;
1099
+ }
1100
+
1075
1101
  export function assertionsToAssertionsJSON(assertions) {
1076
1102
  const assertionsJSON = assertions.map((assertion) => {
1077
1103
  const assertionJSON = assertion.toJSON();
@@ -74,6 +74,16 @@ export function compressStatements(statements) {
74
74
  });
75
75
  }
76
76
 
77
+ export function compressSignatures(signatures) {
78
+ compress(signatures, (signatureA, signatureB) => {
79
+ const signatureAEqualToSignatureB = signatureA.isEqualTo(signatureB);
80
+
81
+ if (!signatureAEqualToSignatureB) {
82
+ return true;
83
+ }
84
+ });
85
+ }
86
+
77
87
  export function compressReferences(references) {
78
88
  compress(references, (referenceA, referenceB) => {
79
89
  const referenceAEqualToReferenceB = referenceA.isEqualTo(referenceB);