occam-verify-cli 0.0.1248 → 0.0.1249

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.
Files changed (51) hide show
  1. package/lib/constants.js +9 -1
  2. package/lib/context/file.js +76 -12
  3. package/lib/context/local.js +16 -4
  4. package/lib/dom/conclusion.js +1 -7
  5. package/lib/dom/consequent.js +1 -7
  6. package/lib/dom/declaration.js +59 -102
  7. package/lib/dom/frame.js +91 -105
  8. package/lib/dom/judgement.js +4 -2
  9. package/lib/dom/label.js +17 -9
  10. package/lib/dom/metavariable.js +18 -16
  11. package/lib/dom/reference.js +29 -41
  12. package/lib/dom/rule.js +7 -9
  13. package/lib/dom/statement.js +54 -54
  14. package/lib/dom/topLevelAssertion.js +13 -6
  15. package/lib/dom/topLevelMetaAssertion.js +10 -11
  16. package/lib/dom/variable.js +6 -6
  17. package/lib/equivalence.js +3 -3
  18. package/lib/equivalences.js +2 -2
  19. package/lib/substitution/term.js +8 -1
  20. package/lib/substitution.js +15 -1
  21. package/lib/substitutions.js +27 -11
  22. package/lib/unifier/intrinsicLevel.js +6 -6
  23. package/lib/unifier/metaLevel.js +3 -3
  24. package/lib/utilities/unification.js +17 -36
  25. package/package.json +1 -1
  26. package/src/constants.js +2 -0
  27. package/src/context/file.js +59 -10
  28. package/src/context/local.js +5 -1
  29. package/src/dom/conclusion.js +0 -2
  30. package/src/dom/consequent.js +0 -2
  31. package/src/dom/declaration.js +88 -92
  32. package/src/dom/frame.js +111 -125
  33. package/src/dom/judgement.js +3 -1
  34. package/src/dom/label.js +17 -4
  35. package/src/dom/metavariable.js +17 -13
  36. package/src/dom/reference.js +45 -47
  37. package/src/dom/rule.js +11 -7
  38. package/src/dom/statement.js +68 -66
  39. package/src/dom/topLevelAssertion.js +11 -5
  40. package/src/dom/topLevelMetaAssertion.js +10 -13
  41. package/src/dom/variable.js +7 -7
  42. package/src/equivalence.js +1 -1
  43. package/src/equivalences.js +1 -1
  44. package/src/substitution/term.js +8 -0
  45. package/src/substitution.js +13 -0
  46. package/src/substitutions.js +31 -11
  47. package/src/unifier/intrinsicLevel.js +5 -7
  48. package/src/unifier/metaLevel.js +2 -4
  49. package/src/utilities/unification.js +29 -67
  50. package/lib/unifier/reference.js +0 -145
  51. package/src/unifier/reference.js +0 -56
@@ -3,6 +3,7 @@
3
3
  import { arrayUtilities } from "necessary";
4
4
 
5
5
  import Equivalences from "../equivalences";
6
+ import Substitutions from "../substitutions";
6
7
  import topLevelVerifier from "../verifier/topLevel";
7
8
 
8
9
  import { objectType } from "../dom/type";
@@ -373,6 +374,32 @@ export default class FileContext {
373
374
  return label;
374
375
  }
375
376
 
377
+ findMetaLemmaByReference(reference) {
378
+ const metaLemmas = this.getMetaLemmas(),
379
+ metaLemma = metaLemmas.find((metaLemma) => {
380
+ const referenceMatches = metaLemma.matchReference(reference);
381
+
382
+ if (referenceMatches) {
383
+ return true;
384
+ }
385
+ }) || null;
386
+
387
+ return metaLemma;
388
+ }
389
+
390
+ findMetatheoremByReference(reference) {
391
+ const metatheorems = this.getMetatheorems(),
392
+ metatheorem = metatheorems.find((metatheorem) => {
393
+ const referenceMatches = metatheorem.matchReference(reference);
394
+
395
+ if (referenceMatches) {
396
+ return true;
397
+ }
398
+ }) || null;
399
+
400
+ return metatheorem;
401
+ }
402
+
376
403
  findRuleByReference(reference) {
377
404
  const rules = this.getRules(),
378
405
  metavariableName = reference.getMetavariableName(),
@@ -462,9 +489,10 @@ export default class FileContext {
462
489
 
463
490
  filter(metaLemmas, (metaLemma) => {
464
491
  const context = this, ///
465
- metaLemmaUnified = reference.unifyMetaLemma(metaLemma, context);
492
+ metaLemmaMetaTheorem = metaLemma, ///
493
+ metaLemmaMetatheoremUnified = reference.unifyMetaLemmaMetatheorem(metaLemmaMetaTheorem, context);
466
494
 
467
- if (metaLemmaUnified) {
495
+ if (metaLemmaMetatheoremUnified) {
468
496
  return true;
469
497
  }
470
498
  });
@@ -475,11 +503,12 @@ export default class FileContext {
475
503
  findMetatheoremsByReference(reference) {
476
504
  const metatheorems = this.getMetatheorems();
477
505
 
478
- filter(metatheorems, (metatheorem) => {
506
+ filter(metatheorems, (metatheorem) => {
479
507
  const context = this, ///
480
- metatheoremUnified = reference.unifyMetatheorem(metatheorem, context);
508
+ metaLemmaMetaTheorem = metatheorem, ///
509
+ metaLemmaMetatheoremUnified = reference.unifyMetaLemmaMetatheorem(metaLemmaMetaTheorem, context);
481
510
 
482
- if (metatheoremUnified) {
511
+ if (metaLemmaMetatheoremUnified) {
483
512
  return true;
484
513
  }
485
514
  });
@@ -487,6 +516,25 @@ export default class FileContext {
487
516
  return metatheorems;
488
517
  }
489
518
 
519
+ findMetaLemmaMetatheoremByReference(reference) {
520
+ const metaLemma = this.findMetaLemmaByReference(reference),
521
+ metatheorem = this.findMetatheoremByReference(reference),
522
+ metaLemmaMetatheorem = (metaLemma || metatheorem); ///
523
+
524
+ return metaLemmaMetatheorem;
525
+ }
526
+
527
+ findMetaLemmaMetatheoremsByReference(reference) {
528
+ const metaLemmas = this.findMetaLemmasByReference(reference),
529
+ metatheorems = this.findMetatheoremsByReference(reference),
530
+ metaLemmaMetatheorems = [
531
+ ...metaLemmas,
532
+ ...metatheorems
533
+ ];
534
+
535
+ return metaLemmaMetatheorems;
536
+ }
537
+
490
538
  findAxiomLemmaTheoremConjectureByReference(reference) {
491
539
  const axiom = this.findAxiomByReference(reference),
492
540
  lemma = this.findLemmaByReference(reference),
@@ -571,10 +619,10 @@ export default class FileContext {
571
619
  return label;
572
620
  }
573
621
 
574
- findLabelByMetavariableNode(metavariableNode) {
622
+ findLabelByMetavariable(metavariable) {
575
623
  const labels = this.getLabels(),
576
624
  label = labels.find((label) => {
577
- const metavariableNodeMatches = label.matchMetavariableNode(metavariableNode);
625
+ const metavariableNodeMatches = label.matchMetavariable(metavariable);
578
626
 
579
627
  if (metavariableNodeMatches) {
580
628
  return true;
@@ -643,8 +691,8 @@ export default class FileContext {
643
691
  return labelPresent;
644
692
  }
645
693
 
646
- isLabelPresentByMetavariableNode(metavariableNode) {
647
- const label = this.findLabelByMetavariableNode(metavariableNode),
694
+ isLabelPresentByMetavariable(metavariable) {
695
+ const label = this.findLabelByMetavariable(metavariable),
648
696
  labelPresent = (label !== null);
649
697
 
650
698
  return labelPresent;
@@ -661,7 +709,8 @@ export default class FileContext {
661
709
  const labels = this.getLabels(),
662
710
  labelPresent = labels.some((label) => {
663
711
  const context = this, ///
664
- labelUnified = reference.unifyLabel(label, context);
712
+ substitutions = Substitutions.fromNothing(),
713
+ labelUnified = reference.unifyLabel(label, substitutions, context);
665
714
 
666
715
  if (labelUnified) {
667
716
  return true;
@@ -235,6 +235,10 @@ class LocalContext {
235
235
 
236
236
  findMetatheoremsByReference(reference) { return this.context.findMetatheoremsByReference(reference); }
237
237
 
238
+ findMetaLemmaMetatheoremByReference(reference) { return this.context.findMetaLemmaMetatheoremByReference(reference); }
239
+
240
+ findMetaLemmaMetatheoremsByReference(reference) { return this.context.findMetaLemmaMetatheoremsByReference(reference); }
241
+
238
242
  findVariableByVariableName(variableName, nested = true) {
239
243
  const variables = this.getVariables(nested),
240
244
  variable = variables.find((variable) => {
@@ -296,7 +300,7 @@ class LocalContext {
296
300
 
297
301
  isLabelPresentByMetavariableName(metavariableName) { return this.context.isLabelPresentByMetavariableName(metavariableName); }
298
302
 
299
- isLabelPresentByMetavariableNode(metavariableNode) { return this.context.isLabelPresentByMetavariableNode(metavariableNode); }
303
+ isLabelPresentByMetavariable(metavariable) { return this.context.isLabelPresentByMetavariable(metavariable); }
300
304
 
301
305
  isMetavariablePresentByMetavariableName(metavariableNode) { return this.context.isMetavariablePresentByMetavariableName(metavariableNode); }
302
306
 
@@ -19,8 +19,6 @@ export default domAssigned(class Conclusion {
19
19
  return this.statement;
20
20
  }
21
21
 
22
- matchStatementNode(statementNode) { return this.statement.matchStatementNode(statementNode); }
23
-
24
22
  unifyStatement(statement, substitutions, generalContext, specificContext) {
25
23
  let statementUnified;
26
24
 
@@ -19,8 +19,6 @@ export default domAssigned(class Consequent {
19
19
  return this.statement;
20
20
  }
21
21
 
22
- matchStatementNode(statementNode) { return this.statement.matchStatementNode(statementNode); }
23
-
24
22
  unifyStatement(statement, substitutions, generalContext, specificContext) {
25
23
  let statementUnified;
26
24
 
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  import dom from "../dom";
4
+ import Substitutions from "../substitutions";
4
5
 
5
6
  import { nodeQuery } from "../utilities/query";
6
7
  import { domAssigned } from "../dom";
8
+ import { unifyStatementIntrinsically } from "../utilities/unification";
7
9
  import { stripBracketsFromStatementNode } from "../utilities/brackets";
8
- import metaLemma from "./metaLemma";
9
10
 
10
11
  const statementNodeQuery = nodeQuery("/declaration/statement");
11
12
 
@@ -28,6 +29,28 @@ export default domAssigned(class Declaration {
28
29
  return this.statement;
29
30
  }
30
31
 
32
+ matchSubstitution(substitution, context) {
33
+ let substitutionMatches;
34
+
35
+ const declarationString = this.string, ///
36
+ substitutionString = substitution.getString();
37
+
38
+ context.trace(`Matching the '${substitutionString}' substitution with the '${declarationString}' declaration...`);
39
+
40
+ const statement = substitution.getStatement(),
41
+ metavariable = substitution.getMetavariable(),
42
+ statementMatches = this.statement.match(statement),
43
+ metavariableMatchesReference = this.reference.matchMetavariable(metavariable);
44
+
45
+ substitutionMatches = (metavariableMatchesReference && statementMatches);
46
+
47
+ if (substitutionMatches) {
48
+ context.debug(`...matched the '${declarationString}' substitution with the '${substitutionString}' declaration.`);
49
+ }
50
+
51
+ return substitutionMatches;
52
+ }
53
+
31
54
  verify(frame, assignments, stated, context) {
32
55
  let verified = false;
33
56
 
@@ -46,12 +69,8 @@ export default domAssigned(class Declaration {
46
69
 
47
70
  if (stated) {
48
71
  verifiedWhenStated = this.verifyWhenStated(frame, assignments, context);
49
-
50
- verified = verifiedWhenStated; ///
51
72
  } else {
52
- verifiedWhenDerived = this.verifyWhenDerived(context);
53
-
54
- verified = verifiedWhenDerived; ///
73
+ verifiedWhenDerived = this.verifyWhenDerived(frame, context);
55
74
  }
56
75
 
57
76
  if (verifiedWhenStated || verifiedWhenDerived) {
@@ -117,21 +136,16 @@ export default domAssigned(class Declaration {
117
136
  if (metavariablePresent) {
118
137
  verifiedWhenStated = true;
119
138
  } else {
120
- const metaLemmas = context.findMetaLemmasByReference(this.reference),
121
- metatheorems = context.findMetatheoremsByReference(this.reference),
122
- metaLemmaMetatheorems = [
123
- ...metaLemmas,
124
- ...metatheorems
125
- ],
126
- metaLemmaMetatheoremsVerifiedWhenStated = metaLemmaMetatheorems.every((metaLemmaMetatheorem) => {
127
- const metaLemmaMetatheoremVerifiedWhenStated = metaLemmaMetatheorem.verifyWhenStated(this.statement, this.reference, context);
128
-
129
- if (metaLemmaMetatheoremVerifiedWhenStated) {
139
+ const metaLemmaMetatheorems = context.findMetaLemmaMetatheoremsByReference(this.reference),
140
+ metaLemmaMetatheoremsUnified = metaLemmaMetatheorems.every((metaLemmaMetatheorem) => {
141
+ const metaLemmaMetatheoremUnified = this.unifyMetaLemmaMetatheorem(metaLemmaMetatheorem, context);
142
+
143
+ if (metaLemmaMetatheoremUnified) {
130
144
  return true;
131
145
  }
132
146
  });
133
147
 
134
- verifiedWhenStated = metaLemmaMetatheoremsVerifiedWhenStated; ///
148
+ verifiedWhenStated = metaLemmaMetatheoremsUnified; ///
135
149
  }
136
150
 
137
151
  if (verifiedWhenStated) {
@@ -148,47 +162,14 @@ export default domAssigned(class Declaration {
148
162
 
149
163
  context.trace(`Verifying the '${declarationString}' derived declaration...`);
150
164
 
151
- debugger
152
-
153
- // const metaLemmas = context.findMetaLemmasByReference(this.reference),
154
- // metatheorems = context.findMetatheoremsByReference(this.reference),
155
- // metaLemmaMetatheorems = [
156
- // ...metaLemmas,
157
- // ...metatheorems
158
- // ],
159
- // metaLemmaMetatheoremUnified = metaLemmaMetatheorems.some((metaLemmaMetatheorem) => {
160
- // let metaLemmaMetatheoremUnified = true;
161
- //
162
- // if (metaLemmaMetatheoremUnified) {
163
- // metaLemmaMetatheoremUnified = frame.unifyMetaLemmaMetatheorem(metaLemmaMetatheorem, context);
164
- // }
165
- //
166
- // if (metaLemmaMetatheoremUnified) {
167
- // metaLemmaMetatheoremUnified = this.unifyMetaLemmaMetatheorem(metaLemmaMetatheorem, context);
168
- // }
169
- //
170
- // if (metaLemmaMetatheoremUnified) {
171
- // return true;
172
- // }
173
- // });
174
- //
175
- // if (metaLemmaMetatheoremUnified) {
176
- // verifiedWhenDerived = true;
177
- // } else {
178
- // const axiom = context.findAxiomByReference(this.reference),
179
- // lemma = context.findLemmaByReference(this.reference),
180
- // theorem = context.findTheoremByReference(this.reference),
181
- // conjecture = context.findConjectureByReference(this.reference),
182
- // axiomLemmaTheoremConjecture = (axiom || lemma || theorem || conjecture);
183
- //
184
- // if (axiomLemmaTheoremConjecture !== null) {
185
- // const axiomLemmaTheoremConjectureUnified = this.unifyAxiomLemmaTheoremConjecture(axiomLemmaTheoremConjecture, context);
186
- //
187
- // if (axiomLemmaTheoremConjectureUnified) {
188
- // verifiedWhenDerived = true;
189
- // }
190
- // }
191
- // }
165
+ const metaLemmaMetatheorem = context.findMetaLemmaMetatheoremByReference(this.reference);
166
+
167
+ if (metaLemmaMetatheorem !== null) {
168
+ const substitutions = metaLemmaMetatheorem.getSubstitutions(),
169
+ substitutionsMatches = frame.matchSubstitutions(substitutions, context);
170
+
171
+ verifiedWhenDerived = substitutionsMatches; ///
172
+ }
192
173
 
193
174
  if (verifiedWhenDerived) {
194
175
  context.trace(`...verified the '${declarationString}' derived declaration.`);
@@ -197,69 +178,84 @@ export default domAssigned(class Declaration {
197
178
  return verifiedWhenDerived;
198
179
  }
199
180
 
200
- unifyStatement(statement, context) {
181
+ unifyStatement(statement, substitutions, generalContext, specificContext) {
201
182
  let statementUnified;
202
183
 
203
- const statementString = statement.getString(),
204
- declarationStatementString = this.statement.getString(); ///
184
+ const context = generalContext, ///
185
+ statementString = statement.getString(),
186
+ declarationString = this.string, ///
187
+ declarationStatementString = this.statement.getString();
205
188
 
206
- context.trace(`Unifying the '${statementString}' statement with the '${declarationStatementString}' statement...`);
189
+ context.trace(`Unifying the '${statementString}' statement with the '${declarationString}' declaration's '${declarationStatementString}' statement...`);
207
190
 
208
- let statementNode = statement.getNode();
191
+ const generalStatement = this.statement,
192
+ specificStatement = statement, ///
193
+ statementUUnifiedIntrinsically = unifyStatementIntrinsically(generalStatement, specificStatement, substitutions, generalContext, specificContext);
209
194
 
210
- statementNode = stripBracketsFromStatementNode(statementNode); ///
211
-
212
- const statementNodeMatches = this.statement.matchStatementNode(statementNode);
213
-
214
- statementUnified = statementNodeMatches; ///
195
+ statementUnified = statementUUnifiedIntrinsically; ///
215
196
 
216
197
  if (statementUnified) {
217
- context.debug(`...unified the '${statementString}' statement with the '${declarationStatementString}' statement.`);
198
+ context.debug(`...unified the '${statementString}' statement with the '${declarationString}' declaration's '${declarationStatementString}' statement.`);
218
199
  }
219
200
 
220
201
  return statementUnified;
221
202
  }
222
203
 
223
- unifyMetavariable(metavariable, context) {
224
- let metavariableUnified;
204
+ unifyLabelWithReference(label, substitutions, generalContext, specificContext) {
205
+ let labelUnifiedWithReference;
225
206
 
226
- const referenceString = this.reference.getString(),
227
- metavariableString = metavariable.getString();
207
+ const context = generalContext, ///
208
+ labelString = label.getString(),
209
+ referenceString = this.reference.getString(),
210
+ declarationString = this.string; ///
228
211
 
229
- context.trace(`Unifying the '${metavariableString}' metavariable with the '${referenceString}' reference...`);
212
+ context.trace(`Unifying the '${labelString}' label with the '${declarationString}' declaration's '${referenceString}' reference...`);
230
213
 
231
- const metavariableNode = metavariable.getNode(),
232
- metavariableNodeMatches = this.reference.matchMetavariableNode(metavariableNode);
214
+ const labelUnified = this.reference.unifyLabel(label, substitutions, context);
233
215
 
234
- metavariableUnified = metavariableNodeMatches; ///
216
+ labelUnifiedWithReference = labelUnified; ///
235
217
 
236
- if (metavariableUnified) {
237
- context.debug(`...unified the '${metavariableString}' metavariable with the '${referenceString}' reference.`);
218
+ if (labelUnifiedWithReference) {
219
+ context.debug(`...unified the '${labelString}' label with the '${declarationString}' declaration's '${referenceString}' reference.`);
238
220
  }
239
221
 
240
- return metavariableUnified;
222
+ return labelUnifiedWithReference;
241
223
  }
242
224
 
243
- unifySubstitution(substitution, context) {
244
- let substitutionUnified;
225
+ unifyMetaLemmaMetatheorem(metaLemmaMetatheorem, context) {
226
+ let metaLemmaMetatheoremUnified;
245
227
 
246
228
  const declarationString = this.string, ///
247
- substitutionString = substitution.getString();
229
+ metaLemmaMetatheoremString = metaLemmaMetatheorem.getString();
248
230
 
249
- context.trace(`Unifying the '${substitutionString}' substitution with the '${declarationString}' declaration...`);
231
+ context.trace(`Unifying the '${metaLemmaMetatheoremString}' meta-lemma or metatheorem with the '${declarationString}' declaration...`);
250
232
 
251
- const statement = substitution.getStatement(),
252
- metavariable = substitution.getMetavariable(),
253
- statementUnified = this.unifyStatement(statement, context),
254
- metavariableUnified = this.unifyMetavariable(metavariable, context);
233
+ const fileContext = metaLemmaMetatheorem.getFileContext(),
234
+ generalContext = context, ///
235
+ specificContext = fileContext,
236
+ labelSubstitutions = Substitutions.fromNothing(),
237
+ label = metaLemmaMetatheorem.getLabel(),
238
+ substitutions = labelSubstitutions, ///
239
+ labelUnifiedWithReference = this.unifyLabelWithReference(label, substitutions, generalContext, specificContext);
240
+
241
+ if (labelUnifiedWithReference) {
242
+ const statementSubstitutions = Substitutions.fromNothing(),
243
+ statement = metaLemmaMetatheorem.getStatement(),
244
+ substitutions = statementSubstitutions, ///
245
+ statementUUnified = this.unifyStatement(statement, substitutions, generalContext, specificContext);
255
246
 
256
- substitutionUnified = (metavariableUnified && statementUnified);
247
+ if (statementUUnified) {
248
+ const labelSubstitutionsMatchStatementSubstitutions = labelSubstitutions.matchSubstitutions(statementSubstitutions);
249
+
250
+ metaLemmaMetatheoremUnified = labelSubstitutionsMatchStatementSubstitutions; ///
251
+ }
252
+ }
257
253
 
258
- if (substitutionUnified) {
259
- context.debug(`...unified the '${declarationString}' substitution with the '${substitutionString}' declaration.`);
254
+ if (metaLemmaMetatheoremUnified) {
255
+ context.trace(`...unified the '${metaLemmaMetatheoremString}' meta-lemma or metatheorem with the '${declarationString}' declaration...`);
260
256
  }
261
257
 
262
- return substitutionUnified;
258
+ return metaLemmaMetatheoremUnified;
263
259
  }
264
260
 
265
261
  static name = "Declaration";