occam-verify-cli 0.0.863 → 0.0.865

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.
@@ -8,6 +8,7 @@ import Variable from "../variable";
8
8
  import Conjecture from "../conjecture";
9
9
  import Combinator from "../combinator";
10
10
  import Constructor from "../constructor";
11
+ import Metatheorem from "../metatheorem";
11
12
  import Metavariable from "../metavariable";
12
13
 
13
14
  import { push } from "../utilities/array";
@@ -21,7 +22,7 @@ const metaTypes = [
21
22
  ];
22
23
 
23
24
  export default class FileContext {
24
- constructor(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, theorems, variables, conjectures, combinators, constructors, metavariables) {
25
+ constructor(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, theorems, variables, conjectures, combinators, constructors, metatheorems, metavariables) {
25
26
  this.releaseContext = releaseContext;
26
27
  this.filePath = filePath;
27
28
  this.tokens = tokens;
@@ -35,6 +36,7 @@ export default class FileContext {
35
36
  this.conjectures = conjectures;
36
37
  this.combinators = combinators;
37
38
  this.constructors = constructors;
39
+ this.metatheorems = metatheorems;
38
40
  this.metavariables = metavariables;
39
41
  }
40
42
 
@@ -244,6 +246,20 @@ export default class FileContext {
244
246
  return constructors;
245
247
  }
246
248
 
249
+ getMetatheorems(includeRelease = true) {
250
+ const metatheorems = [];
251
+
252
+ push(metatheorems, this.metatheorems);
253
+
254
+ if (includeRelease) {
255
+ const releaseContextMetatheorems = this.releaseContext.getMetatheorems();
256
+
257
+ push(metatheorems, releaseContextMetatheorems);
258
+ }
259
+
260
+ return metatheorems;
261
+ }
262
+
247
263
  getMetavariables(includeRelease = true) {
248
264
  return this.metavariables;
249
265
  }
@@ -389,6 +405,20 @@ export default class FileContext {
389
405
  return metavariable;
390
406
  }
391
407
 
408
+ findMetatheoremByReferenceName(referenceName) {
409
+ const labelName = referenceName, ///
410
+ metatheorems = this.getMetatheorems(),
411
+ metatheorem = metatheorems.find((metatheorem) => {
412
+ const metatheoremMatchesLabelName = metatheorem.matchLabelName(labelName);
413
+
414
+ if (metatheoremMatchesLabelName) {
415
+ return true;
416
+ }
417
+ }) || null;
418
+
419
+ return metatheorem;
420
+ }
421
+
392
422
  isTermGrounded(term) {
393
423
  const termGrounded = false; ///
394
424
 
@@ -500,6 +530,10 @@ export default class FileContext {
500
530
  this.constructors.push(constructor);
501
531
  }
502
532
 
533
+ addMetatheorem(metatheorem) {
534
+ this.metatheorems.push(metatheorem);
535
+ }
536
+
503
537
  addMetavariable(metavariable) {
504
538
  let metavariableAdded = false;
505
539
 
@@ -598,6 +632,13 @@ export default class FileContext {
598
632
 
599
633
  return constructor;
600
634
  }),
635
+ metatheorems = this.metatheorems.map((metatheorem) => {
636
+ const metatheoremJSON = metatheorem.toJSON(this.tokens);
637
+
638
+ metatheorem = metatheoremJSON; ///
639
+
640
+ return metatheorem;
641
+ }),
601
642
  metavariables = this.metavariables.map((metavariable) => {
602
643
  const metavariableJSON = metavariable.toJSON(this.tokens);
603
644
 
@@ -616,6 +657,7 @@ export default class FileContext {
616
657
  conjectures,
617
658
  combinators,
618
659
  constructors,
660
+ metatheorems,
619
661
  metavariables
620
662
  };
621
663
 
@@ -623,27 +665,19 @@ export default class FileContext {
623
665
  }
624
666
 
625
667
  initialise(json) {
626
- const fileContext = this, ///
627
- { types,
628
- rules,
629
- axioms,
630
- lemmas,
631
- theorems,
632
- variables,
633
- conjectures,
634
- combinators,
635
- constructors,
636
- metavariables } = json,
637
- typesJSON = types,
638
- rulesJSON = rules,
639
- axiomsJSON = axioms,
640
- lemmasJSON = lemmas,
641
- theoremsJSON = theorems,
642
- variablesJSON = variables,
643
- conjecturesJSON = conjectures,
644
- combinatorsJSON = combinators,
645
- constructorsJSON = constructors,
646
- metavariablesJSON = metavariables;
668
+ const { types, rules, axioms, lemmas, theorems, variables, conjectures, combinators, constructors, metatheorems, metavariables } = json,
669
+ fileContext = this, ///
670
+ typesJSON = types, ///
671
+ rulesJSON = rules, ///
672
+ axiomsJSON = axioms, ///
673
+ lemmasJSON = lemmas, ///
674
+ theoremsJSON = theorems, ///
675
+ variablesJSON = variables, ///
676
+ conjecturesJSON = conjectures, ///
677
+ combinatorsJSON = combinators, ///
678
+ constructorsJSON = constructors, ///
679
+ metatheoremsJSON = metatheorems, ///
680
+ metavariablesJSON = metavariables; ///
647
681
 
648
682
  typesJSON.forEach((typeJSON) => {
649
683
  const json = typeJSON, ///
@@ -708,6 +742,13 @@ export default class FileContext {
708
742
  this.constructors.push(constructor);
709
743
  });
710
744
 
745
+ metatheoremsJSON.forEach((metatheoremJSON) => {
746
+ const json = metatheoremJSON, ///
747
+ metatheorem = Metatheorem.fromJSONAndFileContext(json, fileContext);
748
+
749
+ this.metatheorems.push(metatheorem);
750
+ });
751
+
711
752
  metavariablesJSON.forEach((metavariableJSON) => {
712
753
  const json = metavariableJSON, ///
713
754
  metavariable = Metavariable.fromJSONAndFileContext(json, fileContext);
@@ -729,8 +770,9 @@ export default class FileContext {
729
770
  conjectures = [],
730
771
  combinators = [],
731
772
  constructors = [],
773
+ metatheorems = [],
732
774
  metavariables = [],
733
- fileContext = new FileContext(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, variables, theorems, conjectures, combinators, constructors, metavariables);
775
+ fileContext = new FileContext(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, variables, theorems, conjectures, combinators, constructors, metatheorems, metavariables);
734
776
 
735
777
  fileContext.initialise(json);
736
778
 
@@ -751,8 +793,9 @@ export default class FileContext {
751
793
  conjectures = [],
752
794
  combinators = [],
753
795
  constructors = [],
796
+ metatheorems = [],
754
797
  metavariables = [],
755
- fileContext = new FileContext(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, variables, theorems, conjectures, combinators, constructors, metavariables);
798
+ fileContext = new FileContext(releaseContext, filePath, tokens, node, types, rules, axioms, lemmas, variables, theorems, conjectures, combinators, constructors, metatheorems, metavariables);
756
799
 
757
800
  return fileContext;
758
801
  }
@@ -270,6 +270,30 @@ export default class ReleaseContext {
270
270
  return constructors;
271
271
  }
272
272
 
273
+ getMetatheorems(includeDependencies = true) {
274
+ const metatheorems = [];
275
+
276
+ this.fileContexts.forEach((fileContext) => {
277
+ const includeRelease = false,
278
+ fileContextMetatheorems = fileContext.getMetatheorems(includeRelease);
279
+
280
+ push(metatheorems, fileContextMetatheorems);
281
+ });
282
+
283
+ if (includeDependencies) {
284
+ const dependencyReleaseContexts = this.getDependencyReleaseContexts();
285
+
286
+ dependencyReleaseContexts.forEach((releaseContext) => {
287
+ const includeDependencies = false,
288
+ releaseContextMetatheorems = releaseContext.getMetatheorems(includeDependencies);
289
+
290
+ push(metatheorems, releaseContextMetatheorems);
291
+ });
292
+ }
293
+
294
+ return metatheorems;
295
+ }
296
+
273
297
  addFileContext(fileContext) {
274
298
  this.fileContexts.push(fileContext);
275
299
  }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ import AxiomLemmaTheoremConjecture from "./axiomLemmaTheoremConjecture";
4
+
5
+ export default class Metatheorem extends AxiomLemmaTheoremConjecture {
6
+ static fromJSONAndFileContext(json, fileContext) { return AxiomLemmaTheoremConjecture.fromJSONAndFileContext(Metatheorem, json, fileContext); }
7
+
8
+ static fromLabelsSuppositionsConsequentAndLocalContext(labels, suppositions, consequent, localContext) { return AxiomLemmaTheoremConjecture.fromLabelsSuppositionsConsequentAndLocalContext(Metatheorem, labels, suppositions, consequent, localContext); }
9
+ }
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+
3
+ import Label from "./label";
4
+ import Premise from "./premise";
5
+ import Conclusion from "./conclusion";
6
+
7
+ import { prune } from "./utilities/array";
8
+ import { someSubArray } from "./utilities/array";
9
+
10
+ export default class RuleMetatheorem {
11
+ constructor(labels, premises, conclusion, fileContext) {
12
+ this.labels = labels;
13
+ this.premises = premises;
14
+ this.conclusion = conclusion;
15
+ this.fileContext = fileContext;
16
+ }
17
+
18
+ getLabels() {
19
+ return this.labels;
20
+ }
21
+
22
+ getPremises() {
23
+ return this.premises;
24
+ }
25
+
26
+ getConclusion() {
27
+ return this.conclusion;
28
+ }
29
+
30
+ getFileContext() {
31
+ return this.fileContext;
32
+ }
33
+
34
+ matchLabelName(labelName) {
35
+ const labelNameMatches = this.labels.some((label) => {
36
+ const name = labelName, ///
37
+ labelMatchesName = label.matchName(name);
38
+
39
+ if (labelMatchesName) {
40
+ return true;
41
+ }
42
+ });
43
+
44
+ return labelNameMatches;
45
+ }
46
+
47
+ matchStatement(statementNode, statementLocalContext) {
48
+ let statementNatches;
49
+
50
+ const premisesLength = this.premises.length;
51
+
52
+ if (premisesLength === 0) {
53
+ const substitutions = [],
54
+ conclusionMatches = matchConclusion(this.conclusion, statementNode, substitutions, this.fileContext, statementLocalContext);
55
+
56
+ statementNatches = conclusionMatches; ///
57
+ } else {
58
+ const proofSteps = statementLocalContext.getProofSteps();
59
+
60
+ statementNatches = someSubArray(proofSteps, premisesLength, (proofSteps) => {
61
+ let premisesMatchConclusion = false;
62
+
63
+ const substitutions = [],
64
+ premisesMatch = matchPremises(this.premises, proofSteps, substitutions, this.fileContext, statementLocalContext);
65
+
66
+ if (premisesMatch) {
67
+ const conclusionMatches = matchConclusion(this.conclusion, statementNode, substitutions, this.fileContext, statementLocalContext);
68
+
69
+ premisesMatchConclusion = conclusionMatches; ///
70
+ }
71
+
72
+ if (premisesMatchConclusion) {
73
+ return true;
74
+ }
75
+ });
76
+ }
77
+
78
+ return statementNatches;
79
+ }
80
+
81
+ matchMetastatement(metastatementNode, metastatementLocalMetaContext) {
82
+ let metastatementNatches;
83
+
84
+ const premisesLength = this.premises.length;
85
+
86
+ if (premisesLength === 0) {
87
+ const substitutions = [],
88
+ conclusionMatches = metaMatchConclusion(this.conclusion, metastatementNode, substitutions, this.fileContext, metastatementLocalMetaContext);
89
+
90
+ metastatementNatches = conclusionMatches; ///
91
+ } else {
92
+ const metaproofSteps = metastatementLocalMetaContext.getMetaproofSteps();
93
+
94
+ metastatementNatches = someSubArray(metaproofSteps, premisesLength, (metaproofSteps) => {
95
+ let premisesMatchConclusion = false;
96
+
97
+ const substitutions = [],
98
+ premisesMatch = metaMatchPremises(this.premises, metaproofSteps, substitutions, this.fileContext, metastatementLocalMetaContext);
99
+
100
+ if (premisesMatch) {
101
+ const conclusionMatches = metaMatchConclusion(this.conclusion, metastatementNode, substitutions, this.fileContext, metastatementLocalMetaContext);
102
+
103
+ premisesMatchConclusion = conclusionMatches; ///
104
+ }
105
+
106
+ if (premisesMatchConclusion) {
107
+ return true;
108
+ }
109
+ });
110
+ }
111
+
112
+ return metastatementNatches;
113
+ }
114
+
115
+ toJSON(tokens) {
116
+ const labelsJSON = this.labels.map((label) => {
117
+ const labelJSON = label.toJSON(tokens);
118
+
119
+ return labelJSON;
120
+ }),
121
+ premisesJSON = this.premises.map((premise) => {
122
+ const premiseJSON = premise.toJSON(tokens);
123
+
124
+ return premiseJSON;
125
+ }),
126
+ conclusionJSON = this.conclusion.toJSON(tokens),
127
+ labels = labelsJSON, ///
128
+ premises = premisesJSON, ///
129
+ conclusion = conclusionJSON, ///
130
+ json = {
131
+ labels,
132
+ premises,
133
+ conclusion
134
+ };
135
+
136
+ return json;
137
+ }
138
+
139
+ static fromJSONAndFileContext(json, fileContext) {
140
+ let rule;
141
+
142
+ let { labels } = json;
143
+
144
+ const labelsJSON = labels; ///
145
+
146
+ labels = labelsJSON.map((labelJSON) => {
147
+ const json = labelJSON, ///
148
+ label = Label.fromJSONAndFileContext(json, fileContext);
149
+
150
+ return label;
151
+ });
152
+
153
+ let { premises } = json;
154
+
155
+ const premisesJSON = premises; ///
156
+
157
+ premises = premisesJSON.map((premiseJSON) => {
158
+ const json = premiseJSON, ///
159
+ premise = Premise.fromJSONAndFileContext(json, fileContext);
160
+
161
+ return premise;
162
+ });
163
+
164
+ let { conclusion } = json;
165
+
166
+ const conclusionJSON = conclusion; ///
167
+
168
+ json = conclusionJSON; ///
169
+
170
+ conclusion = Conclusion.fromJSONAndFileContext(json, fileContext);
171
+
172
+ rule = new Rule(labels, premises, conclusion, fileContext);
173
+
174
+ return rule;
175
+ }
176
+
177
+ static fromLabelsPremisesConclusionAndFileContext(labels, premises, conclusion, fileContext) {
178
+ const rule = new Rule(labels, premises, conclusion, fileContext);
179
+
180
+ return rule;
181
+ }
182
+ }
183
+
184
+ function matchPremise(premise, proofSteps, substitutions, fileContext, statementLocalContext) {
185
+ const proofStep = prune(proofSteps, (proofStep) => {
186
+ const subproofNode = proofStep.getSubproofNode(),
187
+ statementNode = proofStep.getStatementNode()
188
+
189
+ if (subproofNode !== null) {
190
+ const subProofNodeMatches = premise.matchSubproofNode(subproofNode, substitutions, fileContext, statementLocalContext);
191
+
192
+ if (!subProofNodeMatches) { ///
193
+ return true;
194
+ }
195
+ }
196
+
197
+ if (statementNode !== null) {
198
+ const statementNodeMatches = premise.matchStatementNode(statementNode, substitutions, fileContext, statementLocalContext);
199
+
200
+ if (!statementNodeMatches) { ///
201
+ return true;
202
+ }
203
+ }
204
+ }) || null;
205
+
206
+ const premiseMatches = (proofStep !== null);
207
+
208
+ return premiseMatches;
209
+ }
210
+
211
+ function matchPremises(premise, proofSteps, substitutions, fileContext, statementLocalContext) {
212
+ const premisesMatch = premise.every((premise) => {
213
+ const premiseMatches = matchPremise(premise, proofSteps, substitutions, fileContext, statementLocalContext);
214
+
215
+ if (premiseMatches) {
216
+ return true;
217
+ }
218
+ });
219
+
220
+ return premisesMatch;
221
+ }
222
+
223
+ function matchConclusion(conclusion, statementNode, substitutions, fileContext, statementLocalContext) {
224
+ const statementNodeMatches = conclusion.matchStatementNode(statementNode, substitutions, fileContext, statementLocalContext),
225
+ conclusionMatches = statementNodeMatches; ///
226
+
227
+ return conclusionMatches;
228
+ }
229
+
230
+ function metaMatchPremise(premise, metaproofSteps, substitutions, fileContext, metastatementLocalMetaContext) {
231
+ const metaproofStep = prune(metaproofSteps, (metaproofStep) => {
232
+ const ruleSubproofNode = metaproofStep.getRuleSubproofNode(),
233
+ metastatementNode = metaproofStep.getMetastatementNode()
234
+
235
+ if (ruleSubproofNode !== null) {
236
+ const ruleSubProofNodeMatches = premise.matchRuleSubproofNode(ruleSubproofNode, substitutions, fileContext, metastatementLocalMetaContext);
237
+
238
+ if (!ruleSubProofNodeMatches) { ///
239
+ return true;
240
+ }
241
+ }
242
+
243
+ if (metastatementNode !== null) {
244
+ const metastatementNodeMatches = premise.matchMetastatementNode(metastatementNode, substitutions, fileContext, metastatementLocalMetaContext);
245
+
246
+ if (!metastatementNodeMatches) { ///
247
+ return true;
248
+ }
249
+ }
250
+ }) || null;
251
+
252
+ const premiseMatches = (metaproofStep !== null);
253
+
254
+ return premiseMatches;
255
+ }
256
+
257
+ function metaMatchPremises(premise, metaproofSteps, substitutions, fileContext, metastatementLocalMetaContext) {
258
+ const premisesMatch = premise.every((premise) => {
259
+ const premiseMatches = metaMatchPremise(premise, metaproofSteps, substitutions, fileContext, metastatementLocalMetaContext);
260
+
261
+ if (premiseMatches) {
262
+ return true;
263
+ }
264
+ });
265
+
266
+ return premisesMatch;
267
+ }
268
+
269
+ function metaMatchConclusion(conclusion, metastatementNode, substitutions, fileContext, metastatementLocalMetaContext) {
270
+ const metastatementNodeMatches = conclusion.matchMetastatementNode(metastatementNode, substitutions, fileContext, metastatementLocalMetaContext),
271
+ conclusionMatches = metastatementNodeMatches; ///
272
+
273
+ return conclusionMatches;
274
+ }
@@ -31,7 +31,7 @@ export default class NodesVerifier {
31
31
  }
32
32
 
33
33
  verifyChildNodes(childNodesA, childNodesB, ...remainingArguments) {
34
- let childNodesVerify = false;
34
+ let childNodesVerified = false;
35
35
 
36
36
  const childNodesALength = childNodesA.length,
37
37
  childNodesBLength = childNodesB.length;
@@ -45,11 +45,11 @@ export default class NodesVerifier {
45
45
  const index = 0,
46
46
  childNodesVerifyAhead = this.verifyChildNodesAhead(index, childNodesA, childNodesB, ...remainingArguments);
47
47
 
48
- childNodesVerify = childNodesVerifyAhead; ///
48
+ childNodesVerified = childNodesVerifyAhead; ///
49
49
  }
50
50
  }
51
51
 
52
- return childNodesVerify;
52
+ return childNodesVerified;
53
53
  }
54
54
 
55
55
  verifyTerminalNode(terminalNodeA, terminalNodeB, ...remainingArguments) { ///
@@ -74,16 +74,16 @@ export default class NodesVerifier {
74
74
  nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
75
75
  childNodesA = nonTerminalNodeAChildNodes, ///
76
76
  childNodesB = nonTerminalNodeBChildNodes, ///
77
- childNodesVerify = this.verifyChildNodes(childNodesA, childNodesB, ...remainingArguments);
77
+ childNodesVerified = this.verifyChildNodes(childNodesA, childNodesB, ...remainingArguments);
78
78
 
79
- nonTerminalNodeVerified = childNodesVerify; ///
79
+ nonTerminalNodeVerified = childNodesVerified; ///
80
80
  }
81
81
 
82
82
  return nonTerminalNodeVerified;
83
83
  }
84
84
 
85
85
  verifyChildNodesAhead(index, childNodesA, childNodesB, ...remainingArguments) {
86
- let childNodesVerify;
86
+ let childNodesVerified;
87
87
 
88
88
  const verifyAhead = remainingArguments.pop(), ///
89
89
  childNodesALength = childNodesA.length;
@@ -91,7 +91,7 @@ export default class NodesVerifier {
91
91
  if (index === childNodesALength) {
92
92
  const verifiedAhead = verifyAhead();
93
93
 
94
- childNodesVerify = verifiedAhead; ///
94
+ childNodesVerified = verifiedAhead; ///
95
95
  } else {
96
96
  const childNodeA = childNodesA[index],
97
97
  childNodeB = childNodesB[index],
@@ -106,9 +106,9 @@ export default class NodesVerifier {
106
106
  return childNodesVerifyAhead;
107
107
  });
108
108
 
109
- childNodesVerify = nodeVerified; ///
109
+ childNodesVerified = nodeVerified; ///
110
110
  }
111
111
 
112
- return childNodesVerify;
112
+ return childNodesVerified;
113
113
  }
114
114
  }
@@ -12,16 +12,17 @@ export default function verifyMetavariableDeclaration(metavariableDeclarationNod
12
12
 
13
13
  const metaTypeNode = metaTypeNodeQuery(metavariableDeclarationNode),
14
14
  metavariableNode = metavariableNodeQuery(metavariableDeclarationNode),
15
- metavariableString = fileContext.nodeAsString(metaTypeNode);
15
+ metaTypeString = fileContext.nodeAsString(metaTypeNode),
16
+ metavariableString = fileContext.nodeAsString(metavariableNode);
16
17
 
17
- fileContext.trace(`Verifying the '${metavariableString}' metavariable declaration...`, metavariableDeclarationNode);
18
+ fileContext.trace(`Verifying the '${metavariableString}:${metaTypeString}' metavariable declaration...`, metavariableDeclarationNode);
18
19
 
19
20
  const metavariableVVerified = verifyMetavariable(metavariableNode, metaTypeNode, fileContext);
20
21
 
21
22
  metavariableDeclarationVerified = metavariableVVerified; ///
22
23
 
23
24
  if (metavariableDeclarationVerified) {
24
- fileContext.debug(`...verified the '${metavariableString}' metavariable declaration.`, metavariableDeclarationNode);
25
+ fileContext.debug(`...verified the '${metavariableString}:${metaTypeString}' metavariable declaration.`, metavariableDeclarationNode);
25
26
  }
26
27
 
27
28
  return metavariableDeclarationVerified;