occam-verify-cli 1.0.913 → 1.0.919

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.
@@ -3,7 +3,7 @@
3
3
  import Assertion from "../assertion";
4
4
 
5
5
  import { define } from "../../elements";
6
- import { instantiate } from "../../utilities/context";
6
+ import { join, reconcile, instantiate } from "../../utilities/context";
7
7
  import { instantiateSignatureAssertion } from "../../process/instantiate";
8
8
  import { signatureFromSignatureAssertionNode, referenceFromSignatureAssertionNode, signatureAssertionFromStatementNode } from "../../utilities/element";
9
9
 
@@ -30,10 +30,6 @@ export default define(class SignatureAssertion extends Assertion {
30
30
  return signatureAssertionNode;
31
31
  }
32
32
 
33
- compareSubstitutions(substitutions, context) { return this.signature.compareSubstitutions(substitutions, context); }
34
-
35
- correlateSubstitutions(substitutions, context) { return this.signature.correlateSubstitutions(substitutions, context); }
36
-
37
33
  validate(context) {
38
34
  let signatureAssertion = null;
39
35
 
@@ -118,7 +114,7 @@ export default define(class SignatureAssertion extends Assertion {
118
114
  const satisfiable = axiom.isSatisfiable();
119
115
 
120
116
  if (satisfiable) {
121
- const signatureUnifies = axiom.unifySignature(this.signature, context);
117
+ const signatureUnifies = this.unifySignature(context);
122
118
 
123
119
  if (signatureUnifies) {
124
120
  this.reference = reference;
@@ -130,7 +126,6 @@ export default define(class SignatureAssertion extends Assertion {
130
126
 
131
127
  context.debug(`The '${axiomString}' axiom is not satisfiable.`);
132
128
  }
133
-
134
129
  } else {
135
130
  const referencdString = reference.getString();
136
131
 
@@ -145,46 +140,64 @@ export default define(class SignatureAssertion extends Assertion {
145
140
  return referenceVerifies;
146
141
  }
147
142
 
148
- unifyStepAndSubproofOrProofAssertions(step, subproofOrProofAssertions, context) {
149
- let stepAndSubproofOrProofAssertionsUnify = false;
143
+ unifySignature(context) {
144
+ let signatureUnifies;
145
+
146
+ const signatureAssertionString = this.getString(); ///
147
+
148
+ context.trace(`Unifying the '${signatureAssertionString}' signature assertion's signature...`);
150
149
 
151
- const steptString = step.getString(),
152
- signatureAssertionString = this.getString(); ///
150
+ const axiom = context.findAxiomByReference(this.reference);
153
151
 
154
- context.trace(`Unifying the '${steptString}' step with the '${signatureAssertionString}' signature assertion...`);
152
+ context = this.signature.getContext();
153
+
154
+ reconcile((context) => {
155
+ signatureUnifies = axiom.unifySignature(this.signature, context);
156
+ }, context);
157
+
158
+ if (signatureUnifies) {
159
+ context.debug(`...unified the '${signatureAssertionString}' signature assertion's signature.`);
160
+ }
161
+
162
+ return signatureUnifies;
163
+ }
155
164
 
156
- this.signature.validate(context);
165
+ async unifyTopLevelAssertion(topLevelAssertion, context) {
166
+ let topLevelAssertionUnifies;
157
167
 
158
168
  const axiom = context.findAxiomByReference(this.reference),
159
- satisfiable = axiom.isSatisfiable();
169
+ signatureContext = this.signature.getContext(),
170
+ specificContext = signatureContext; ///
160
171
 
161
- if (satisfiable) {
162
- const axiomComparesToSignature = axiom.compareSignature(this.signature, context);
172
+ await join(async (specificContext) => {
173
+ const context = specificContext; ///
163
174
 
164
- if (axiomComparesToSignature) {
165
- const substitutionsB = substitutions; ///
175
+ await reconcile(async (context) => {
176
+ axiom.unifySignature(this.signature, context);
166
177
 
167
- stepAndSubproofOrProofAssertionsUnify = unifyStepAndSubproofOrProofAssertions(step, subproofOrProofAssertions, context);
178
+ topLevelAssertionUnifies = await axiom.unifyTopLevelAssertion(topLevelAssertion, context);
179
+ }, context);
180
+ }, specificContext, context);
168
181
 
169
- if (stepAndSubproofOrProofAssertionsUnify) {
170
- const substitutionsA = substitutions, ///
171
- substitutionsCorrelate = substitutionsA.correlateSubstitutions(substitutionsB);
182
+ return topLevelAssertionUnifies;
183
+ }
172
184
 
173
- if (!substitutionsCorrelate) {
174
- const substitutionsAString = substitutionsA.asString(),
175
- substitutionsBString = substitutionsB.asString();
185
+ async unifyStepAndSubproofOrProofAssertions(step, subproofOrProofAssertions, context) {
186
+ let stepAndSubproofOrProofAssertionsUnify;
176
187
 
177
- context.trace(`THe signature's ${substitutionsBString} substitutions do not correlate with the unification's ${substitutionsAString} substitutions.`);
188
+ const axiom = context.findAxiomByReference(this.reference),
189
+ signatureContext = this.signature.getContext(),
190
+ specificContext = signatureContext; ///
178
191
 
179
- stepAndSubproofOrProofAssertionsUnify = false;
180
- }
181
- }
182
- }
183
- }
192
+ await join(async (specificContext) => {
193
+ const context = specificContext; ///
184
194
 
185
- if (stepAndSubproofOrProofAssertionsUnify) {
186
- context.debug(`...unified the '${steptString}' step with the '${signatureAssertionString}' signature assertion.`);
187
- }
195
+ await reconcile(async (context) => {
196
+ axiom.unifySignature(this.signature, context);
197
+
198
+ stepAndSubproofOrProofAssertionsUnify = await axiom.unifyStepAndSubproofOrProofAssertions(step, subproofOrProofAssertions, context);
199
+ }, context);
200
+ }, specificContext, context);
188
201
 
189
202
  return stepAndSubproofOrProofAssertionsUnify;
190
203
  }
@@ -4,7 +4,7 @@ import { Element } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
6
  import { instantiateDeduction } from "../process/instantiate";
7
- import { declare, attempt, descend, serialise, unserialise, instantiate } from "../utilities/context";
7
+ import { join, declare, attempt, descend, reconcile, serialise, unserialise, instantiate } from "../utilities/context";
8
8
 
9
9
  export default define(class Deduction extends Element {
10
10
  constructor(context, string, node, lineIndex, statement) {
@@ -130,23 +130,33 @@ export default define(class Deduction extends Element {
130
130
  return stepUnifies;
131
131
  }
132
132
 
133
- unifyDeduction(deduction, substitutions, generalContext, specificContext) {
133
+ unifyDeduction(deduction, context) {
134
134
  let deductionUnifies = false;
135
135
 
136
- const context = specificContext, ///
137
- generalDeduction = this, ///
136
+ const generalDeduction = this, ///
138
137
  specificDeduction = deduction, ///
139
138
  generalDeductionString = generalDeduction.getString(),
140
139
  specificDeductionString = specificDeduction.getString();
141
140
 
142
141
  context.trace(`Unifying the '${specificDeductionString}' deduction with the '${generalDeductionString}' deduction...`);
143
142
 
144
- const statement = specificDeduction.getStatement(),
145
- statementUnifies = this.unifyStatement(statement, substitutions, generalContext, specificContext);
143
+ const specificDeductionContext = specificDeduction.getContext(),
144
+ generalDeductionContext = generalDeduction.getContext(),
145
+ specificContext = specificDeductionContext, ///
146
+ generalContext = generalDeductionContext; ///
146
147
 
147
- if (statementUnifies) {
148
- deductionUnifies = true;
149
- }
148
+ join((specificContext) => {
149
+ reconcile((specificContext) => {
150
+ const statement = specificDeduction.getStatement(),
151
+ statementUnifies = this.statement.unifyStatement(statement, generalContext, specificContext);
152
+
153
+ if (statementUnifies) {
154
+ specificContext.commit();
155
+
156
+ deductionUnifies = true;
157
+ }
158
+ }, specificContext);
159
+ }, specificContext, context);
150
160
 
151
161
  if (deductionUnifies) {
152
162
  context.debug(`...unified the '${specificDeductionString}' deduction with the '${generalDeductionString}' deduction.`);
@@ -50,7 +50,7 @@ export default define(class Step extends ProofAssertion {
50
50
  }
51
51
 
52
52
  isQualified() {
53
- const qualified = (this.reference !== null);
53
+ const qualified = ((this.reference !== null) || (this.signatureAssertion !== null));
54
54
 
55
55
  return qualified;
56
56
  }
@@ -164,29 +164,6 @@ export default define(class Step extends ProofAssertion {
164
164
  return validates;
165
165
  }
166
166
 
167
- validateReference(context) {
168
- let referenceValidates = true; ///
169
-
170
- if (this.reference !== null) {
171
- const stepString = this.getString(), ///
172
- referenceString = this.reference.getString();
173
-
174
- context.trace(`Validating the '${stepString}' step's '${referenceString}' reference... `);
175
-
176
- const reference = this.reference.validate(context);
177
-
178
- if (reference === null) {
179
- referenceValidates = false;
180
- }
181
-
182
- if (referenceValidates) {
183
- context.debug(`...validated the '${stepString}' step's '${referenceString}' reference. `);
184
- }
185
- }
186
-
187
- return referenceValidates;
188
- }
189
-
190
167
  validateStatement(context) {
191
168
  let statementValidates = false;
192
169
 
@@ -211,8 +188,35 @@ export default define(class Step extends ProofAssertion {
211
188
  return statementValidates;
212
189
  }
213
190
 
191
+ validateReference(context) {
192
+ let referenceValidates = false;
193
+
194
+ if (this.reference !== null) {
195
+ const stepString = this.getString(), ///
196
+ referenceString = this.reference.getString();
197
+
198
+ context.trace(`Validating the '${stepString}' step's '${referenceString}' reference... `);
199
+
200
+ const reference = this.reference.validate(context);
201
+
202
+ if (reference !== null) {
203
+ this.reference = reference;
204
+
205
+ referenceValidates = true;
206
+ }
207
+
208
+ if (referenceValidates) {
209
+ context.debug(`...validated the '${stepString}' step's '${referenceString}' reference. `);
210
+ }
211
+ } else {
212
+ referenceValidates = true;
213
+ }
214
+
215
+ return referenceValidates;
216
+ }
217
+
214
218
  validateSignatureAssertion(context) {
215
- let signatureAssertionValidates = true; ///
219
+ let signatureAssertionValidates = false;
216
220
 
217
221
  if (this.signatureAssertion !== null) {
218
222
  const stepString = this.getString(), ///
@@ -222,13 +226,17 @@ export default define(class Step extends ProofAssertion {
222
226
 
223
227
  const signatureAssertion = this.signatureAssertion.validate(context);
224
228
 
225
- if (signatureAssertion === null) {
226
- signatureAssertionValidates = false;
229
+ if (signatureAssertion !== null) {
230
+ this.signatureAssertion = signatureAssertion;
231
+
232
+ signatureAssertionValidates = true;
227
233
  }
228
234
 
229
235
  if (signatureAssertionValidates) {
230
- context.debug(`...validating the '${stepString}' step's '${signatureAssertionString}' signature assertion. `);
236
+ context.debug(`...validated the '${stepString}' step's '${signatureAssertionString}' signature assertion. `);
231
237
  }
238
+ } else {
239
+ signatureAssertionValidates = true;
232
240
  }
233
241
 
234
242
  return signatureAssertionValidates;
@@ -264,36 +272,5 @@ export default define(class Step extends ProofAssertion {
264
272
  return unifies;
265
273
  }
266
274
 
267
- unifyWithSignatureAssertion(signatureAssertion, context) {
268
- let unifiesWithSignatureAssertion = false;
269
-
270
- const stepString = this.getString(), ///
271
- signatureAssertionString = signatureAssertion.getString();
272
-
273
- context.trace(`Unifying the '${stepString}' step with the '${signatureAssertionString}' signature assertion...`);
274
-
275
- const reference = signatureAssertion.getReference(),
276
- axiom = context.findAxiomByReference(reference);
277
-
278
- if (axiom !== null) {
279
- const step = this, ///
280
- stepUnifies = axiom.unifyStep(step, context);
281
-
282
- if (stepUnifies) {
283
- const substitutionsCompare = signatureAssertion.compareSubstitutions(context);
284
-
285
- if (substitutionsCompare) {
286
- unifiesWithSignatureAssertion = true;
287
- }
288
- }
289
- }
290
-
291
- if (unifiesWithSignatureAssertion) {
292
- context.debug(`...unified the '${stepString}' step with the '${signatureAssertionString}' signature assertion.`);
293
- }
294
-
295
- return unifiesWithSignatureAssertion;
296
- }
297
-
298
275
  static name = "Step";
299
276
  });
@@ -6,9 +6,9 @@ import { arrayUtilities } from "necessary";
6
6
  import { define } from "../elements";
7
7
  import { instantiateSignature } from "../process/instantiate";
8
8
  import { signatureFromSignatureNode } from "../utilities/element";
9
- import { attempt, reconcile, serialise, unserialise, instantiate, ablate } from "../utilities/context";
9
+ import { join, ablate, attempt, reconcile, serialise, unserialise, instantiate } from "../utilities/context";
10
10
 
11
- const { match, compare, correlate } = arrayUtilities;
11
+ const { match } = arrayUtilities;
12
12
 
13
13
  export default define(class Signature extends Element {
14
14
  constructor(context, string, node, lineIndex, terms) {
@@ -173,48 +173,52 @@ export default define(class Signature extends Element {
173
173
  return termsValidate
174
174
  }
175
175
 
176
- unifySignature(signature, context) {
177
- let signatureUnifies = false;
176
+ unifySignature(signature, generalContext, specificContext) {
177
+ let signatureUnifies;
178
178
 
179
- const generalSignature = this,
179
+ const context = specificContext, ///
180
+ generalSignature = this,
180
181
  specificSignature = signature, ///
181
182
  generalSignatureString = generalSignature.getString(),
182
183
  specificSignatureString = specificSignature.getString();
183
184
 
184
185
  context.trace(`Unifying the '${specificSignatureString}' signature with the '${generalSignatureString}' signature...`);
185
186
 
186
- context = specificSignature.getContext();
187
-
188
- const specificContext = context; ///
189
-
190
- context = this.getContext();
191
-
192
- const generalContext = context; ///
193
-
194
- context = specificContext; ///
195
-
196
- reconcile((specificContext) => {
197
- const generalSignatureTerms = generalSignature.getTerms(),
198
- specificSignatureTerms = specificSignature.getTerms(),
199
- generalTerms = generalSignatureTerms, ///
200
- specificTerms = specificSignatureTerms; ///
201
-
202
- signatureUnifies = match(generalTerms, specificTerms, (generalTerm, specificTerm) => {
203
- let termUnifies;
204
-
205
- reconcile((specificContext) => {
206
- termUnifies = generalTerm.unifyTerm(specificTerm, generalContext, specificContext);
187
+ const generalSignatureTerms = generalSignature.getTerms(),
188
+ specificSignatureTerms = specificSignature.getTerms(),
189
+ generalSignatureContext = generalSignature.getContext(),
190
+ specificSignatureContext = specificSignature.getContext(),
191
+ generalTerms = generalSignatureTerms, ///
192
+ specificTerms = specificSignatureTerms, ///
193
+ generalContexts = [
194
+ generalSignatureContext,
195
+ generalContext
196
+ ],
197
+ specificContexts = [
198
+ specificSignatureContext,
199
+ specificContext
200
+ ];
201
+
202
+ join((generalContext) => {
203
+ join((specificContext) => {
204
+ signatureUnifies = match(generalTerms, specificTerms, (generalTerm, specificTerm) => {
205
+ let termUnifies;
206
+
207
+ reconcile((specificContext) => {
208
+ termUnifies = generalTerm.unifyTerm(specificTerm, generalContext, specificContext);
209
+
210
+ if (termUnifies) {
211
+ specificContext.commit();
212
+ }
213
+ }, specificContext);
207
214
 
208
215
  if (termUnifies) {
209
- specificContext.commit();
216
+ return true;
210
217
  }
211
- }, specificContext);
218
+ });
219
+ }, ...specificContexts);
220
+ }, ...generalContexts);
212
221
 
213
- if (termUnifies) {
214
- return true;
215
- }
216
- });
217
- }, specificContext);
218
222
 
219
223
  if (signatureUnifies) {
220
224
  context.debug(`...unified the '${specificSignatureString}' signature with the '${generalSignatureString}' signature.`);
@@ -223,64 +227,6 @@ export default define(class Signature extends Element {
223
227
  return signatureUnifies;
224
228
  }
225
229
 
226
- compareSubstitutions(substitutions, context) {
227
- let substitutionsCompares = false;
228
-
229
- const signatureString = this.getString(), ///
230
- substitutionsString = substitutions.asString();
231
-
232
- context.trace(`Comparing the '${substitutionsString}' substitutions against the '${signatureString}' signature...`);
233
-
234
- const array = substitutions.getArray(),
235
- compares = compare(this.terms, array, (term, substitution) => {
236
- const substitutionTerm = substitution.getTerm(),
237
- substitutionTermEqualToTerm = substitutionTerm.isEqualTo(term);
238
-
239
- if (substitutionTermEqualToTerm) {
240
- return true;
241
- }
242
- });
243
-
244
- if (compares) {
245
- substitutionsCompares = true;
246
- }
247
-
248
- if (substitutionsCompares) {
249
- context.debug(`...compared the '${substitutionsString}' substitutions against the '${signatureString}' signature.`);
250
- }
251
-
252
- return substitutionsCompares;
253
- }
254
-
255
- correlateSubstitutions(substitutions, context) {
256
- let substitutionsCorrelates = false;
257
-
258
- const signatureString = this.getString(), ///
259
- substitutionsString = substitutions.asString();
260
-
261
- context.trace(`Correlating the '${substitutionsString}' substitutions against the '${signatureString}' signature...`);
262
-
263
- const array = substitutions.getArray(),
264
- correlates = correlate(this.terms, array, (term, substitution) => {
265
- const substitutionTerm = substitution.getTerm(),
266
- substitutionTermEqualToTerm = substitutionTerm.isEqualTo(term);
267
-
268
- if (substitutionTermEqualToTerm) {
269
- return true;
270
- }
271
- });
272
-
273
- if (correlates) {
274
- substitutionsCorrelates = true;
275
- }
276
-
277
- if (substitutionsCorrelates) {
278
- context.debug(`...correlated the '${substitutionsString}' substitutions against the '${signatureString}' signature.`);
279
- }
280
-
281
- return substitutionsCorrelates;
282
- }
283
-
284
230
  static name = "Signature";
285
231
 
286
232
  toJSON() {
@@ -112,40 +112,5 @@ export default define(class Subproof extends Element {
112
112
  return subDerivationVerifies;
113
113
  }
114
114
 
115
- unifyWithSignatureAssertion(signatureAssertion, context) {
116
- let unifiesWithSignatureAssertion = false;
117
-
118
- const subproofString = this.getString(), ///
119
- signatureAssertionString = signatureAssertion.getString();
120
-
121
- context.trace(`Unifying the '${subproofString}' subproof with the '${signatureAssertionString}' signature assertion...`)
122
-
123
- const reference = signatureAssertion.getReference(),
124
- axiom = context.findAxiomByReference(reference);
125
-
126
- if (axiom !== null) {
127
- const axiomSatisfiable = axiom.isSatisfiable();
128
-
129
- if (axiomSatisfiable) {
130
- const subproof = this, ///
131
- statementUnifies = axiom.unifySubproof(subproof, context);
132
-
133
- if (statementUnifies) {
134
- const substitutionsCompare = signatureAssertion.compareSubstitutions(substitutions, context);
135
-
136
- if (substitutionsCompare) {
137
- unifiesWithSignatureAssertion = true;
138
- }
139
- }
140
- }
141
- }
142
-
143
- if (unifiesWithSignatureAssertion) {
144
- context.debug(`...unified the '${subproofString}' subproof with the '${signatureAssertionString}' signature assertion.`)
145
- }
146
-
147
- return unifiesWithSignatureAssertion;
148
- }
149
-
150
115
  static name = "Subproof";
151
116
  });