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.
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
2
 
3
- import { arrayUtilities } from "necessary";
4
-
5
3
  import elements from "../elements";
6
4
 
7
5
  import { descend } from "./context";
8
6
 
9
- const { backwardsSome } = arrayUtilities;
10
-
11
7
  async function unifyStepWithRule(step, context) {
12
8
  let stepUnifiesWithRule = false;
13
9
 
14
- const qualified = step.isQualified();
10
+ const reference = step.getReference();
15
11
 
16
- if (qualified) {
17
- const reference = step.getReference(),
18
- rule = context.findRuleByReference(reference);
12
+ if (reference !== null) {
13
+ const rule = context.findRuleByReference(reference);
19
14
 
20
15
  if (rule !== null) {
21
16
  const stepString = step.getString(),
@@ -42,11 +37,10 @@ async function unifyStepWithRule(step, context) {
42
37
  async function unifyStepWithReference(step, context) {
43
38
  let stepUnifiesWithReference = false;
44
39
 
45
- const qualified = step.isQualified();
40
+ const reference = step.getReference();
46
41
 
47
- if (qualified) {
48
- const reference = step.getReference(),
49
- stepString = step.getString(),
42
+ if (reference !== null) {
43
+ const stepString = step.getString(),
50
44
  referenceString = reference.getString();
51
45
 
52
46
  context.trace(`Unifying the '${stepString}' step with the '${referenceString}' reference...`);
@@ -83,79 +77,13 @@ async function unifyStepWithReference(step, context) {
83
77
  return stepUnifiesWithReference;
84
78
  }
85
79
 
86
- async function unifyStepAsSignatureAssertion(step, context) {
87
- let stepUnifiesAsSignatureAssertion = false;
88
-
89
- const { SignatureAssertion } = elements;
90
-
91
- const signatureAssertion = SignatureAssertion.fromStep(step, context);
92
-
93
- if (signatureAssertion !== null) {
94
- const stepString = step.getString();
95
-
96
- context.trace(`Unifying the '${stepString}' step as a signature assertion...`);
97
-
98
- descend((context) => {
99
- signatureAssertion.verifySignature(context);
100
- }, context);
101
-
102
- const unqualified = step.isUnqualified();
103
-
104
- if (unqualified) {
105
- const subproofOrProofAssertions = context.getSubproofOrProofAssertions();
106
-
107
- stepUnifiesAsSignatureAssertion = backwardsSome(subproofOrProofAssertions, (stepsOrSubproof) => {
108
- const stepOrSubProofUnifiesWIthSignatureAssertion = stepsOrSubproof.unifyWithSignatureAssertion(signatureAssertion, context);
109
-
110
- if (stepOrSubProofUnifiesWIthSignatureAssertion) {
111
- return true;
112
- }
113
- });
114
- } else {
115
- const reference = signatureAssertion.getReference(),
116
- topLevelAssertion = context.findTopLevelAssertionByReference(reference);
117
-
118
- if (topLevelAssertion !== null) {
119
- const axiom = context.findAxiomByReference(reference);
120
-
121
- if (axiom !== null) {
122
- const satisfiable = axiom.isSatisfiable();
123
-
124
- if (satisfiable) {
125
- const topLevelAssertionUnifies = axiom.unifyTopLevelAssertion(topLevelAssertion, context);
126
-
127
- if (topLevelAssertionUnifies) {
128
- const substitutionsCorrelates = signatureAssertion.correlateSubstitutions(substitutions, context);
129
-
130
- if (substitutionsCorrelates) {
131
- stepUnifiesAsSignatureAssertion = true;
132
- }
133
- }
134
- } else {
135
- const axiomString = axiom.getString();
136
-
137
- context.debug(`Unable to unify with the '${axiomString}' because it is not satisfiable.`)
138
- }
139
- }
140
- }
141
- }
142
-
143
- if (stepUnifiesAsSignatureAssertion) {
144
- context.debug(`...unified the '${stepString}' step as a signature assertion.`);
145
- }
146
- }
147
-
148
- return stepUnifiesAsSignatureAssertion;
149
- }
150
-
151
80
  async function unifyStepWithTopLevelAssertion(step, context) {
152
81
  let stepUnifiesWithTopLevelAssertion = false;
153
82
 
154
- const qualified = step.isQualified();
83
+ const reference = step.getReference();
155
84
 
156
- if (qualified) {
157
- const reference = step.getReference(),
158
- topLevelAssertion = context.findTopLevelAssertionByReference(reference);
85
+ if (reference !== null) {
86
+ const topLevelAssertion = context.findTopLevelAssertionByReference(reference);
159
87
 
160
88
  if (topLevelAssertion !== null) {
161
89
  const stepString = step.getString(),
@@ -179,8 +107,34 @@ async function unifyStepWithTopLevelAssertion(step, context) {
179
107
  return stepUnifiesWithTopLevelAssertion;
180
108
  }
181
109
 
182
- async function unifyStepAsEquality(step, context) {
183
- let stepUnifiesAEquality = false;
110
+ async function unifyStepWithSignatureAssertion(step, context) {
111
+ let stepUnifiesWithSignatureAssertion = false;
112
+
113
+ const signatureAssertion = step.getSignatureAssertion();
114
+
115
+ if (signatureAssertion !== null) {
116
+ const stepString = step.getString(),
117
+ signatureAssertionString = signatureAssertion.getString();
118
+
119
+ context.trace(`Unifying the '${stepString}' step with the '${signatureAssertionString}' signature assertion...`);
120
+
121
+ const subproofOrProofAssertions = context.getSubproofOrProofAssertions(),
122
+ stepAndSubproofOrProofAssertionsUnify = await signatureAssertion.unifyStepAndSubproofOrProofAssertions(step, subproofOrProofAssertions, context);
123
+
124
+ if (stepAndSubproofOrProofAssertionsUnify) {
125
+ stepUnifiesWithSignatureAssertion = true;
126
+ }
127
+
128
+ if (stepUnifiesWithSignatureAssertion) {
129
+ context.debug(`...unified the '${stepString}' step with the '${signatureAssertionString}' signature assertion.`);
130
+ }
131
+ }
132
+
133
+ return stepUnifiesWithSignatureAssertion;
134
+ }
135
+
136
+ async function unifyStepAsUnqualifiedEquality(step, context) {
137
+ let stepUnifiesAUnqualifiedEquality = false;
184
138
 
185
139
  const unqualified = step.isUnqualified();
186
140
 
@@ -192,25 +146,21 @@ async function unifyStepAsEquality(step, context) {
192
146
  if (equality !== null) {
193
147
  const stepString = step.getString();
194
148
 
195
- context.trace(`Unifying the '${stepString}' step as an equality...`);
149
+ context.trace(`Unifying the '${stepString}' step as an unqualified equality...`);
196
150
 
197
- const equalityEqual = equality.isEqual(context);
151
+ stepUnifiesAUnqualifiedEquality = true;
198
152
 
199
- if (equalityEqual) {
200
- stepUnifiesAEquality = true;
201
- }
202
-
203
- if (stepUnifiesAEquality) {
204
- context.debug(`...unified the '${stepString}' step as an equality.`);
153
+ if (stepUnifiesAUnqualifiedEquality) {
154
+ context.debug(`...unified the '${stepString}' step as an unqualified equality.`);
205
155
  }
206
156
  }
207
157
  }
208
158
 
209
- return stepUnifiesAEquality;
159
+ return stepUnifiesAUnqualifiedEquality;
210
160
  }
211
161
 
212
- async function unifyStepAsJudgement(step, context) {
213
- let stepUnifiesAsJudgement = false;
162
+ async function unifyStepAsUNqualifiedJudgement(step, context) {
163
+ let stepUnifiesAsUnqualifiedJudgement = false;
214
164
 
215
165
  const unqualified = step.isUnqualified();
216
166
 
@@ -222,21 +172,21 @@ async function unifyStepAsJudgement(step, context) {
222
172
  if (judgement !== null) {
223
173
  const stepString = step.getString();
224
174
 
225
- context.trace(`Unifying the '${stepString}' step as a judgement...`);
175
+ context.trace(`Unifying the '${stepString}' step as an unqualified judgement...`);
226
176
 
227
- stepUnifiesAsJudgement = true;
177
+ stepUnifiesAsUnqualifiedJudgement = true;
228
178
 
229
- if (stepUnifiesAsJudgement) {
230
- context.debug(`...unified the '${stepString}' step as a judgement.`);
179
+ if (stepUnifiesAsUnqualifiedJudgement) {
180
+ context.debug(`...unified the '${stepString}' step as an unqualified judgement.`);
231
181
  }
232
182
  }
233
183
  }
234
184
 
235
- return stepUnifiesAsJudgement;
185
+ return stepUnifiesAsUnqualifiedJudgement;
236
186
  }
237
187
 
238
- async function unifyStepAsTypeAssertion(step, context) {
239
- let stepUnifiesAsTypeAssertion = false;
188
+ async function unifyStepAsUnqualifiedTypeAssertion(step, context) {
189
+ let stepUnifiesAsUnqualifiedTypeAssertion = false;
240
190
 
241
191
  const unqualified = step.isUnqualified();
242
192
 
@@ -248,19 +198,21 @@ async function unifyStepAsTypeAssertion(step, context) {
248
198
  if (typeAssertion !== null) {
249
199
  const stepString = step.getString();
250
200
 
251
- context.trace(`Unifying the '${stepString}' step as a type assertion...`);
201
+ context.trace(`Unifying the '${stepString}' step as an unqualified type assertion...`);
252
202
 
253
- stepUnifiesAsTypeAssertion = true;
203
+ stepUnifiesAsUnqualifiedTypeAssertion = true;
254
204
 
255
- context.debug(`...unified the '${stepString}' step as a type assertion.`);
205
+ if (stepUnifiesAsUnqualifiedTypeAssertion) {
206
+ context.debug(`...unified the '${stepString}' step as an unqualified type assertion.`);
207
+ }
256
208
  }
257
209
  }
258
210
 
259
- return stepUnifiesAsTypeAssertion;
211
+ return stepUnifiesAsUnqualifiedTypeAssertion;
260
212
  }
261
213
 
262
- async function unifyStepAsPropertyAssertion(step, context) {
263
- let stepUnifiesAsPropertyAssertion = false;
214
+ async function unifyStepAsUnqualifiedPropertyAssertion(step, context) {
215
+ let stepUnifiesAsUnqualifiedPropertyAssertion = false;
264
216
 
265
217
  const unqualified = step.isUnqualified();
266
218
 
@@ -272,59 +224,78 @@ async function unifyStepAsPropertyAssertion(step, context) {
272
224
  if (propertyAssertion !== null) {
273
225
  const stepString = step.getString();
274
226
 
275
- context.trace(`Unifying the '${stepString}' step as a property assertion...`);
227
+ context.trace(`Unifying the '${stepString}' step as an unqualified property assertion...`);
276
228
 
277
- const term = propertyAssertion.getTerm(),
278
- equivalence = context.findEquivalenceByTerm(term);
229
+ stepUnifiesAsUnqualifiedPropertyAssertion = true;
279
230
 
280
- if (equivalence !== null) {
281
- const propertyAssertionMatches = equivalence.someOtherTerm(term, (term) => { ///
282
- const propertyRelation = propertyAssertion.getPropertyRelation(),
283
- comparesToTermAndPropertyRelation = context.compareTermAndPropertyRelation(term, propertyRelation);
231
+ if (stepUnifiesAsUnqualifiedPropertyAssertion) {
232
+ context.debug(`...unified the '${stepString}' step as an unqualified property assertion.`);
233
+ }
234
+ }
235
+ }
284
236
 
285
- if (comparesToTermAndPropertyRelation) {
286
- return true;
287
- }
288
- });
237
+ return stepUnifiesAsUnqualifiedPropertyAssertion;
238
+ }
289
239
 
290
- if (propertyAssertionMatches) {
291
- stepUnifiesAsPropertyAssertion = true;
292
- }
293
- }
240
+ async function unifyStepAsUnqualifiedSignatureAssertion(step, context) {
241
+ let stepUnifiesAsUnqualifiedSignatureAssertion = false;
294
242
 
295
- if (stepUnifiesAsPropertyAssertion) {
296
- context.debug(`...unified the '${stepString}' step as a property assertion.`);
243
+ const unqualified = step.isUnqualified();
244
+
245
+ if (unqualified) {
246
+ const { SignatureAssertion } = elements,
247
+ statement = step.getStatement(),
248
+ signatureAssertion = SignatureAssertion.fromStatement(statement, context);
249
+
250
+ if (signatureAssertion !== null) {
251
+ const stepString = step.getString();
252
+
253
+ context.trace(`Unifying the '${stepString}' step as a signature assertion...`);
254
+
255
+ stepUnifiesAsUnqualifiedSignatureAssertion = true;
256
+
257
+ if (stepUnifiesAsUnqualifiedSignatureAssertion) {
258
+ context.debug(`...unified the '${stepString}' step as a signature assertion.`);
297
259
  }
298
260
  }
299
261
  }
300
262
 
301
- return stepUnifiesAsPropertyAssertion;
263
+ return stepUnifiesAsUnqualifiedSignatureAssertion;
302
264
  }
303
265
 
304
- async function unifyStepWithSignatureAssertion(step, context) {
305
- let stepUnifiesWithSignatureAssertion = false;
266
+ async function unifyStepAsSignatureAssertionWithReference(step, context) {
267
+ let stepUnifiesAsSignatureAssertionWithReference = false;
306
268
 
307
- const signatureAssertion = step.getSignatureAssertion();
269
+ const reference = step.getReference();
308
270
 
309
- if (signatureAssertion !== null) {
310
- const stepString = step.getString(),
311
- signatureAssertionString = signatureAssertion.getString();
271
+ if (reference !== null) {
272
+ const topLevelAssertion = context.findTopLevelAssertionByReference(reference);
312
273
 
313
- context.trace(`Unifying the '${stepString}' step with the '${signatureAssertionString}' signature assertion...`);
274
+ if (topLevelAssertion !== null) {
275
+ const statementNode = step.getStatementNode(),
276
+ signatureAssertionNode = statementNode.getSignatureAssertionNode();
314
277
 
315
- const subproofOrProofAssertions = context.getSubproofOrProofAssertions(),
316
- stepUnifies = signatureAssertion.unifyStepAndSubproofOrProofAssertions(step, subproofOrProofAssertions, context);
278
+ if (signatureAssertionNode !== null) {
279
+ const stepString = step.getString(),
280
+ referenceString = reference.getString(),
281
+ signatureAssertion = context.findAssertionByAssertionNode(signatureAssertionNode);
317
282
 
318
- if (stepUnifies) {
319
- stepUnifiesWithSignatureAssertion = true;
320
- }
283
+ context.trace(`Unifying the '${stepString}' step as a signature assertion with the '${referenceString}' reference...`);
321
284
 
322
- if (stepUnifiesWithSignatureAssertion) {
323
- context.debug(`...unified the '${stepString}' step with the '${signatureAssertionString}' signature assertion.`);
285
+ const unifyTopLevelAssertion = await signatureAssertion.unifyTopLevelAssertion(topLevelAssertion, context);
286
+
287
+ if (unifyTopLevelAssertion) {
288
+ stepUnifiesAsSignatureAssertionWithReference = true;
289
+ }
290
+
291
+ if (stepUnifiesAsSignatureAssertionWithReference) {
292
+ context.debug(`...unified the '${stepString}' step as a signature assertion with the '${referenceString}' reference.`);
293
+ }
294
+ }
324
295
  }
325
296
  }
326
297
 
327
- return stepUnifiesWithSignatureAssertion;
298
+ return stepUnifiesAsSignatureAssertionWithReference;
328
299
  }
329
300
 
330
301
  async function compareStepWithSubproofOrProofAssertions(step, context) {
@@ -355,12 +326,13 @@ async function compareStepWithSubproofOrProofAssertions(step, context) {
355
326
  export const unifySteps = [
356
327
  unifyStepWithRule,
357
328
  unifyStepWithReference,
358
- unifyStepAsSignatureAssertion,
359
329
  unifyStepWithTopLevelAssertion,
360
- unifyStepAsEquality,
361
- unifyStepAsJudgement,
362
- unifyStepAsTypeAssertion,
363
- unifyStepAsPropertyAssertion,
364
330
  unifyStepWithSignatureAssertion,
331
+ unifyStepAsUnqualifiedEquality,
332
+ unifyStepAsUNqualifiedJudgement,
333
+ unifyStepAsUnqualifiedTypeAssertion,
334
+ unifyStepAsUnqualifiedPropertyAssertion,
335
+ unifyStepAsUnqualifiedSignatureAssertion,
336
+ unifyStepAsSignatureAssertionWithReference,
365
337
  compareStepWithSubproofOrProofAssertions
366
338
  ];