occam-verify-cli 0.0.538 → 0.0.540

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 (91) hide show
  1. package/bin/action/verify.js +7 -24
  2. package/bin/actions.js +20 -6
  3. package/lib/axiom.js +7 -7
  4. package/lib/axiomLemmaTheoremConjecture.js +33 -30
  5. package/lib/combinator.js +4 -4
  6. package/lib/conclusion.js +8 -8
  7. package/lib/conjecture.js +7 -7
  8. package/lib/consequence.js +3 -3
  9. package/lib/constructor.js +6 -6
  10. package/lib/context/file.js +215 -45
  11. package/lib/context/metaproof.js +3 -3
  12. package/lib/context/release.js +215 -2
  13. package/lib/kinds.js +13 -1
  14. package/lib/label.js +4 -4
  15. package/lib/lemma.js +7 -7
  16. package/lib/metaType.js +201 -0
  17. package/lib/metavariable.js +81 -0
  18. package/lib/premise.js +12 -12
  19. package/lib/rule.js +42 -35
  20. package/lib/ruleNames.js +16 -4
  21. package/lib/supposition.js +8 -8
  22. package/lib/theorem.js +7 -7
  23. package/lib/type.js +7 -7
  24. package/lib/utilities/node.js +17 -3
  25. package/lib/utilities/query.js +13 -2
  26. package/lib/variable.js +18 -12
  27. package/lib/verifier/metastatementForMetavariable.js +8 -8
  28. package/lib/verifier/statementForMetavariable.js +9 -9
  29. package/lib/verifier/termForVariable.js +22 -11
  30. package/lib/verifier.js +1 -1
  31. package/lib/verify/assertion/type.js +2 -2
  32. package/lib/verify/axiom.js +2 -2
  33. package/lib/verify/conjecture.js +2 -2
  34. package/lib/verify/declaration/metavariable.js +26 -0
  35. package/lib/verify/declaration/topLevel.js +7 -3
  36. package/lib/verify/lemma.js +2 -2
  37. package/lib/verify/metastatement/qualified.js +3 -3
  38. package/lib/verify/metastatement.js +147 -3
  39. package/lib/verify/metavariable.js +34 -0
  40. package/lib/verify/rule.js +2 -2
  41. package/lib/verify/statement/qualified.js +7 -7
  42. package/lib/verify/statement.js +6 -6
  43. package/lib/verify/theorem.js +2 -2
  44. package/lib/verify/variable.js +4 -4
  45. package/package.json +3 -3
  46. package/src/axiom.js +2 -2
  47. package/src/axiomLemmaTheoremConjecture.js +31 -32
  48. package/src/combinator.js +3 -3
  49. package/src/conclusion.js +11 -7
  50. package/src/conjecture.js +2 -2
  51. package/src/consequence.js +2 -2
  52. package/src/constructor.js +5 -5
  53. package/src/context/file.js +248 -45
  54. package/src/context/metaproof.js +1 -1
  55. package/src/context/release.js +254 -2
  56. package/src/kinds.js +3 -0
  57. package/src/label.js +3 -3
  58. package/src/lemma.js +2 -2
  59. package/src/metaType.js +81 -0
  60. package/src/metavariable.js +39 -0
  61. package/src/premise.js +19 -11
  62. package/src/rule.js +37 -32
  63. package/src/ruleNames.js +4 -1
  64. package/src/supposition.js +11 -7
  65. package/src/theorem.js +2 -2
  66. package/src/type.js +5 -5
  67. package/src/utilities/node.js +32 -2
  68. package/src/utilities/query.js +14 -0
  69. package/src/variable.js +12 -8
  70. package/src/verifier/metastatementForMetavariable.js +7 -7
  71. package/src/verifier/statementForMetavariable.js +8 -8
  72. package/src/verifier/termForVariable.js +33 -13
  73. package/src/verifier.js +1 -1
  74. package/src/verify/assertion/type.js +3 -3
  75. package/src/verify/axiom.js +1 -1
  76. package/src/verify/conjecture.js +2 -1
  77. package/src/verify/declaration/metavariable.js +20 -0
  78. package/src/verify/declaration/topLevel.js +9 -2
  79. package/src/verify/lemma.js +1 -1
  80. package/src/verify/metastatement/qualified.js +3 -2
  81. package/src/verify/metastatement.js +65 -2
  82. package/src/verify/metavariable.js +32 -0
  83. package/src/verify/rule.js +1 -1
  84. package/src/verify/statement/qualified.js +7 -6
  85. package/src/verify/statement.js +14 -14
  86. package/src/verify/theorem.js +2 -1
  87. package/src/verify/variable.js +4 -4
  88. package/lib/context/release/directory.js +0 -313
  89. package/lib/context/release/file.js +0 -387
  90. package/src/context/release/directory.js +0 -251
  91. package/src/context/release/file.js +0 -312
package/src/conjecture.js CHANGED
@@ -7,7 +7,7 @@ import { CONJECTURE_KIND } from "./kinds";
7
7
  export default class Conjecture extends AxiomLemmaTheoremConjecture {
8
8
  static kind = CONJECTURE_KIND;
9
9
 
10
- static fromJSON(json, context) { return AxiomLemmaTheoremConjecture.fromJSON(Conjecture, json, context); }
10
+ static fromJSONAndFileContext(json, fileContext) { return AxiomLemmaTheoremConjecture.fromJSONAndFileContext(Conjecture, json, fileContext); }
11
11
 
12
- static fromLabelsSuppositionsAndConsequence(labels, suppositions, consequence) { return AxiomLemmaTheoremConjecture.fromLabelsSuppositionsAndConsequence(Conjecture, labels, suppositions, consequence); }
12
+ static fromLabelsSuppositionsConsequenceAndProofContext(labels, suppositions, consequence, proofContext) { return AxiomLemmaTheoremConjecture.fromLabelsSuppositionsConsequenceAndProofContext(Conjecture, labels, suppositions, consequence, proofContext); }
13
13
  }
@@ -13,10 +13,10 @@ export default class Consequence {
13
13
  return this.statementNode;
14
14
  }
15
15
 
16
- matchStatementNode(statementNode, substitutions) {
16
+ matchStatementNode(statementNode, substitutions, proofContext) {
17
17
  const nonTerminalNodeA = this.statementNode, ///
18
18
  nonTerminalNodeB = statementNode, ///
19
- nonTerminalNodeVerified = consequenceTermForVariableVerifier.verifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions),
19
+ nonTerminalNodeVerified = consequenceTermForVariableVerifier.verifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, proofContext),
20
20
  statementNodeMatches = nonTerminalNodeVerified; ///
21
21
 
22
22
  return statementNodeMatches;
@@ -54,11 +54,11 @@ export default class Constructor {
54
54
  return json;
55
55
  }
56
56
 
57
- static fromJSON(json, context) {
57
+ static fromJSONAndFileContext(json, fileContext) {
58
58
  const { term } = json,
59
59
  termString = term, ///
60
- lexer = context.getLexer(),
61
- parser = context.getParser(),
60
+ lexer = fileContext.getLexer(),
61
+ parser = fileContext.getParser(),
62
62
  termNode = termNodeFromTermString(termString, lexer, parser);
63
63
 
64
64
  let { type } = json;
@@ -68,11 +68,11 @@ export default class Constructor {
68
68
 
69
69
  json = typeJSON; ///
70
70
 
71
- type = Type.fromJSON(json, context);
71
+ type = Type.fromJSONAndFileContext(json, fileContext);
72
72
 
73
73
  const typeName = type.getName();
74
74
 
75
- type = context.findTypeByTypeName(typeName); ///
75
+ type = fileContext.findTypeByTypeName(typeName); ///
76
76
  }
77
77
 
78
78
  const constructor = new Constructor(termNode, type);
@@ -2,11 +2,37 @@
2
2
 
3
3
  import { rewriteNodes } from "occam-grammar-utilities";
4
4
 
5
- import { push } from "../utilities/array";
5
+ import Type from "../type";
6
+ import Rule from "../rule";
7
+ import Axiom from "../axiom";
8
+ import Lemma from "../lemma";
9
+ import Theorem from "../theorem";
10
+ import Variable from "../variable";
11
+ import Conjecture from "../conjecture";
12
+ import Combinator from "../combinator";
13
+ import Constructor from "../constructor";
14
+ import Metavariable from "../metavariable";
15
+
16
+ import { push, filter } from "../utilities/array";
17
+ import { statementMetaType } from "../metaType";
6
18
  import { nodeAsString, nodesAsString } from "../utilities/string";
19
+ import { TYPE_KIND,
20
+ RULE_KIND,
21
+ AXIOM_KIND,
22
+ LEMMA_KIND,
23
+ THEOREM_KIND,
24
+ VARIABLE_KIND,
25
+ CONJECTURE_KIND,
26
+ COMBINATOR_KIND,
27
+ CONSTRUCTOR_KIND,
28
+ METAVARIABLE_KIND } from "../kinds";
29
+
30
+ const metaTypes = [
31
+ statementMetaType
32
+ ];
7
33
 
8
34
  export default class FileContext {
9
- constructor(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, theorems, conjectures, combinators, constructors, variables, metavariables) {
35
+ constructor(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, theorems, variables, conjectures, combinators, constructors, metavariables) {
10
36
  this.releaseContext = releaseContext;
11
37
  this.filePath = filePath;
12
38
  this.tokens = tokens;
@@ -16,10 +42,10 @@ export default class FileContext {
16
42
  this.axioms = axioms;
17
43
  this.lemmas = lemmas;
18
44
  this.theorems = theorems;
45
+ this.variables = variables;
19
46
  this.conjectures = conjectures;
20
47
  this.combinators = combinators;
21
48
  this.constructors = constructors;
22
- this.variables = variables;
23
49
  this.metavariables = metavariables;
24
50
  }
25
51
 
@@ -78,6 +104,12 @@ export default class FileContext {
78
104
  push(labels, theoremLabels);
79
105
  });
80
106
 
107
+ this.conjectures.forEach((conjecture) => {
108
+ const conjectureLabels = conjecture.getLabels();
109
+
110
+ push(labels, conjectureLabels);
111
+ });
112
+
81
113
  if (includeRelease) {
82
114
  const releaseContextLabels = this.releaseContext.getLabels();
83
115
 
@@ -157,6 +189,14 @@ export default class FileContext {
157
189
  return theorems;
158
190
  }
159
191
 
192
+ getVariables(includeRelease = true) {
193
+ return this.variables;
194
+ }
195
+
196
+ getMetaTypes(includeRelease = true) {
197
+ return metaTypes;
198
+ }
199
+
160
200
  getConjectures(includeRelease = true) {
161
201
  const conjectures = [];
162
202
 
@@ -199,39 +239,35 @@ export default class FileContext {
199
239
  return constructors;
200
240
  }
201
241
 
202
- getVariables() {
203
- return this.variables;
204
- }
205
-
206
- getMetavariables() {
242
+ getMetavariables(includeRelease = true) {
207
243
  return this.metavariables;
208
244
  }
209
245
 
210
- findTypeByTypeName(typeName) {
211
- const types = this.getTypes(),
212
- type = types.find((type) => {
213
- const matches = type.matchTypeName(typeName);
246
+ findLabelByLabelName(labelName) {
247
+ const name = labelName, ///
248
+ labels = this.getLabels(),
249
+ label = labels.find((label) => {
250
+ const matches = label.matchName(name);
214
251
 
215
252
  if (matches) {
216
253
  return true;
217
254
  }
218
255
  }) || null;
219
256
 
220
- return type;
257
+ return label;
221
258
  }
222
259
 
223
- findLabelByLabelName(labelName) {
224
- const name = labelName, ///
225
- labels = this.getLabels(),
226
- label = labels.find((label) => {
227
- const matches = label.matchName(name);
260
+ findTypeByTypeName(typeName) {
261
+ const types = this.getTypes(),
262
+ type = types.find((type) => {
263
+ const matches = type.matchTypeName(typeName);
228
264
 
229
265
  if (matches) {
230
266
  return true;
231
267
  }
232
268
  }) || null;
233
269
 
234
- return label;
270
+ return type;
235
271
  }
236
272
 
237
273
  findRuleByReferenceName(referenceName) {
@@ -290,6 +326,33 @@ export default class FileContext {
290
326
  return theorem;
291
327
  }
292
328
 
329
+ findVariableByVariableName(variableName) {
330
+ const name = variableName, ///
331
+ variables = this.getVariables(),
332
+ variable = variables.find((variable) => {
333
+ const matches = variable.matchName(name);
334
+
335
+ if (matches) {
336
+ return true;
337
+ }
338
+ }) || null;
339
+
340
+ return variable;
341
+ }
342
+
343
+ findMetaTypeByMetaTypeName(metaTypeName) {
344
+ const metaTypes = this.getMetaTypes(),
345
+ metaType = metaTypes.find((metaType) => {
346
+ const matches = metaType.matchMetaTypeName(metaTypeName);
347
+
348
+ if (matches) {
349
+ return true;
350
+ }
351
+ }) || null;
352
+
353
+ return metaType;
354
+ }
355
+
293
356
  findConjectureByReferenceName(referenceName) {
294
357
  const labelName = referenceName, ///
295
358
  conjectures = this.getConjectures(),
@@ -304,6 +367,20 @@ export default class FileContext {
304
367
  return conjecture;
305
368
  }
306
369
 
370
+ findMetavariableByMetavariableName(metavariableName) {
371
+ const name = metavariableName, ///
372
+ metavariables = this.getMetavariables(),
373
+ metavariable = metavariables.find((metavariable) => {
374
+ const matches = metavariable.matchName(name);
375
+
376
+ if (matches) {
377
+ return true;
378
+ }
379
+ }) || null;
380
+
381
+ return metavariable;
382
+ }
383
+
307
384
  isLabelPresentByLabelName(labelName) {
308
385
  const label = this.findLabelByLabelName(labelName),
309
386
  labelPresent = (label !== null);
@@ -318,43 +395,36 @@ export default class FileContext {
318
395
  return typePresent;
319
396
  }
320
397
 
321
- nodeAsString(node) {
322
- const string = nodeAsString(node, this.tokens);
398
+ isVariablePresentByVariableName(variableName) {
399
+ const variable = this.findVariableByVariableName(variableName),
400
+ variablePresent = (variable !== null);
323
401
 
324
- return string;
402
+ return variablePresent;
325
403
  }
326
404
 
327
- nodesAsString(node) {
328
- const string = nodesAsString(node, this.tokens);
405
+ isMetavariablePresentByMetavariableName(metavariableName) {
406
+ const metavariable = this.findMetavariableByMetavariableName(metavariableName),
407
+ metavariablePresent = (metavariable !== null);
329
408
 
330
- return string;
409
+ return metavariablePresent;
331
410
  }
332
411
 
333
- findVariableByVariableName(variableName) {
334
- const name = variableName, ///
335
- variables = this.getVariables(),
336
- variable = variables.find((variable) => {
337
- const matches = variable.matchName(name);
338
-
339
- if (matches) {
340
- return true;
341
- }
342
- }) || null;
412
+ matchStatement(statementNode) {
413
+ const statementMatches = false;
343
414
 
344
- return variable;
415
+ return statementMatches;
345
416
  }
346
417
 
347
- isVariablePresentByVariableName(variableName) {
348
- const variable = this.findVariableByVariableName(variableName),
349
- variablePresent = (variable !== null);
418
+ nodeAsString(node) {
419
+ const string = nodeAsString(node, this.tokens);
350
420
 
351
- return variablePresent;
421
+ return string;
352
422
  }
353
423
 
354
- matchStatement(statementNode) {
355
- const statementMatches = false;
424
+ nodesAsString(node) {
425
+ const string = nodesAsString(node, this.tokens);
356
426
 
357
- return statementMatches;
427
+ return string;
358
428
  }
359
429
 
360
430
  addType(type) {
@@ -378,9 +448,24 @@ export default class FileContext {
378
448
  }
379
449
 
380
450
  addVariable(variable) {
451
+ const variableName = variable.getName();
452
+
453
+ filter(this.variables, (variable) => {
454
+ const name = variable.getName(),
455
+ nameVariableName = (name === variableName);
456
+
457
+ if (!nameVariableName) {
458
+ return true;
459
+ }
460
+ });
461
+
381
462
  this.variables.push(variable);
382
463
  }
383
464
 
465
+ addConjecture(conjecture) {
466
+ this.conjectures.push(conjecture);
467
+ }
468
+
384
469
  addCombinator(combinator) {
385
470
  this.combinators.push(combinator);
386
471
  }
@@ -389,6 +474,21 @@ export default class FileContext {
389
474
  this.constructors.push(constructor);
390
475
  }
391
476
 
477
+ addMetavariable(metavariable) {
478
+ const metavariableName = metavariable.getName();
479
+
480
+ filter(this.metavariables, (metavariable) => {
481
+ const name = metavariable.getName(),
482
+ nameMetavariableName = (name === metavariableName);
483
+
484
+ if (!nameMetavariableName) {
485
+ return true;
486
+ }
487
+ });
488
+
489
+ this.metavariables.push(metavariable);
490
+ }
491
+
392
492
  trace(message, node) { this.releaseContext.trace(message, node, this.tokens, this.filePath); }
393
493
 
394
494
  debug(message, node) { this.releaseContext.debug(message, node, this.tokens, this.filePath); }
@@ -434,6 +534,12 @@ export default class FileContext {
434
534
  json.push(theoremJSON);
435
535
  });
436
536
 
537
+ this.variables.forEach((variable) => {
538
+ const variableJSON = variable.toJSON(this.tokens);
539
+
540
+ json.push(variableJSON)
541
+ });
542
+
437
543
  this.conjectures.forEach((conjecture) => {
438
544
  const conjectureJSON = conjecture.toJSON(this.tokens);
439
545
 
@@ -452,9 +558,106 @@ export default class FileContext {
452
558
  json.push(constructorJSON)
453
559
  });
454
560
 
561
+ this.metavariables.forEach((metavariable) => {
562
+ const metavariableJSON = metavariable.toJSON(this.tokens);
563
+
564
+ json.push(metavariableJSON)
565
+ });
566
+
455
567
  return json;
456
568
  }
457
569
 
570
+ static fromJSON(json) {
571
+ const jsonArray = json, ///
572
+ fileContext = this; ///
573
+
574
+ jsonArray.forEach((json) => {
575
+ const { kind } = json;
576
+
577
+ switch (kind) {
578
+ case TYPE_KIND: {
579
+ const type = Type.fromJSONAndFileContext(json, fileContext);
580
+
581
+ this.types.push(type);
582
+
583
+ break;
584
+ }
585
+
586
+ case RULE_KIND: {
587
+ const rule = Rule.fromJSONAndFileContext(json, fileContext);
588
+
589
+ this.rules.push(rule);
590
+
591
+ break;
592
+ }
593
+
594
+ case AXIOM_KIND: {
595
+ const axiom = Axiom.fromJSONAndFileContext(json, fileContext);
596
+
597
+ this.axioms.push(axiom);
598
+
599
+ break;
600
+ }
601
+
602
+ case LEMMA_KIND: {
603
+ const lemma = Lemma.fromJSONAndFileContext(json, fileContext);
604
+
605
+ this.lemmas.push(lemma);
606
+
607
+ break;
608
+ }
609
+
610
+ case THEOREM_KIND: {
611
+ const theorem = Theorem.fromJSONAndFileContext(json, fileContext);
612
+
613
+ this.theorems.push(theorem);
614
+
615
+ break;
616
+ }
617
+
618
+ case VARIABLE_KIND: {
619
+ const variable = Variable.fromJSONAndFileContext(json, fileContext);
620
+
621
+ this.variables.push(variable);
622
+
623
+ break;
624
+ }
625
+
626
+ case CONJECTURE_KIND: {
627
+ const conjecture = Conjecture.fromJSONAndFileContext(json, fileContext);
628
+
629
+ this.conjectures.push(conjecture);
630
+
631
+ break;
632
+ }
633
+
634
+ case COMBINATOR_KIND: {
635
+ const combinator = Combinator.fromJSONAndFileContext(json, fileContext);
636
+
637
+ this.combinators.push(combinator);
638
+
639
+ break;
640
+ }
641
+
642
+ case CONSTRUCTOR_KIND: {
643
+ const constructor = Constructor.fromJSONAndFileContext(json, fileContext);
644
+
645
+ this.constructors.push(constructor);
646
+
647
+ break;
648
+ }
649
+
650
+ case METAVARIABLE_KIND: {
651
+ const metavariable = Metavariable.fromJSONAndFileContext(json, fileContext);
652
+
653
+ this.metavariables.push(metavariable);
654
+
655
+ break;
656
+ }
657
+ }
658
+ });
659
+ }
660
+
458
661
  static fromReleaseContextAndFilePath(releaseContext, filePath) {
459
662
  const file = releaseContext.getFile(filePath),
460
663
  content = file.getContent(),
@@ -472,12 +675,12 @@ export default class FileContext {
472
675
  axioms = [],
473
676
  lemmas = [],
474
677
  theorems = [],
678
+ variables = [],
475
679
  conjectures = [],
476
680
  combinators = [],
477
681
  constructors = [],
478
- variables = [],
479
682
  metavariables = [],
480
- fileContext = new FileContext(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, theorems, conjectures, combinators, constructors, variables, metavariables);
683
+ fileContext = new FileContext(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, variables, theorems, conjectures, combinators, constructors, metavariables);
481
684
 
482
685
  return fileContext;
483
686
  }
@@ -108,7 +108,7 @@ class MetaproofContext {
108
108
  return metavariable;
109
109
  }
110
110
 
111
- isMetavariablePresentByVariableName(metavariableName) {
111
+ isMetavariablePresentByMetavariableName(metavariableName) {
112
112
  const metavariable = this.findMetavariableByMetavariableName(metavariableName),
113
113
  metavariablePresent = (metavariable !== null);
114
114