occam-verify-cli 0.0.478 → 0.0.480

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.
package/src/rule.js CHANGED
@@ -40,6 +40,40 @@ export default class Rule {
40
40
  return matchesLabelName;
41
41
  }
42
42
 
43
+ matchStatement(statementNode, proofContext) {
44
+ let statementNatches;
45
+
46
+ const premisesLength = this.premises.length;
47
+
48
+ if (premisesLength === 0) {
49
+ const substitutions = [],
50
+ conclusionMatches = matchConclusion(this.conclusion, statementNode, substitutions);
51
+
52
+ statementNatches = conclusionMatches; ///
53
+ } else {
54
+ const proofSteps = proofContext.getProofSteps();
55
+
56
+ statementNatches = someSubArray(proofSteps, premisesLength, (proofSteps) => {
57
+ let premisesMatchConclusion = false;
58
+
59
+ const substitutions = [],
60
+ premisesMatch = matchPremises(this.premises, proofSteps, substitutions);
61
+
62
+ if (premisesMatch) {
63
+ const conclusionMatches = matchConclusion(this.conclusion, statementNode, substitutions);
64
+
65
+ premisesMatchConclusion = conclusionMatches; ///
66
+ }
67
+
68
+ if (premisesMatchConclusion) {
69
+ return true;
70
+ }
71
+ });
72
+ }
73
+
74
+ return statementNatches;
75
+ }
76
+
43
77
  matchMetastatement(metastatementNode, metaproofContext) {
44
78
  let metastatementNatches;
45
79
 
@@ -47,7 +81,7 @@ export default class Rule {
47
81
 
48
82
  if (premisesLength === 0) {
49
83
  const metaSubstitutions = [],
50
- conclusionMatches = matchConclusion(this.conclusion, metastatementNode, metaSubstitutions);
84
+ conclusionMatches = metaMatchConclusion(this.conclusion, metastatementNode, metaSubstitutions);
51
85
 
52
86
  metastatementNatches = conclusionMatches; ///
53
87
  } else {
@@ -57,10 +91,10 @@ export default class Rule {
57
91
  let premisesMatchConclusion = false;
58
92
 
59
93
  const metaSubstitutions = [],
60
- premisesMatches = matchPremises(this.premises, metaproofSteps, metaSubstitutions);
94
+ premisesMatch = metaMatchPremises(this.premises, metaproofSteps, metaSubstitutions);
61
95
 
62
- if (premisesMatches) {
63
- const conclusionMatches = matchConclusion(this.conclusion, metastatementNode, metaSubstitutions);
96
+ if (premisesMatch) {
97
+ const conclusionMatches = metaMatchConclusion(this.conclusion, metastatementNode, metaSubstitutions);
64
98
 
65
99
  premisesMatchConclusion = conclusionMatches; ///
66
100
  }
@@ -145,23 +179,69 @@ export default class Rule {
145
179
  }
146
180
  }
147
181
 
148
- function matchPremise(premise, metaproofSteps, metaSubstitutions) {
182
+ function matchPremise(premise, proofSteps, substitutions) {
183
+ const proofStep = prune(proofSteps, (proofStep) => {
184
+ const subproofNode = proofStep.getSubproofNode(),
185
+ statementNode = proofStep.getStatementNode()
186
+
187
+ if (subproofNode !== null) {
188
+ const subProofNodeMatches = premise.matchSubproofNode(subproofNode, substitutions);
189
+
190
+ if (!subProofNodeMatches) { ///
191
+ return true;
192
+ }
193
+ }
194
+
195
+ if (statementNode !== null) {
196
+ const statementNodeMatches = premise.matchStatementNode(statementNode, substitutions);
197
+
198
+ if (!statementNodeMatches) { ///
199
+ return true;
200
+ }
201
+ }
202
+ }) || null;
203
+
204
+ const premiseMatches = (proofStep !== null);
205
+
206
+ return premiseMatches;
207
+ }
208
+
209
+ function matchPremises(premise, proofSteps, substitutions) {
210
+ const premisesMatch = premise.every((premise) => {
211
+ const premiseMatches = matchPremise(premise, proofSteps, substitutions);
212
+
213
+ if (premiseMatches) {
214
+ return true;
215
+ }
216
+ });
217
+
218
+ return premisesMatch;
219
+ }
220
+
221
+ function matchConclusion(conclusion, statementNode, substitutions) {
222
+ const statementNodeMatches = conclusion.matchStatementNode(statementNode, substitutions),
223
+ conclusionMatches = statementNodeMatches; ///
224
+
225
+ return conclusionMatches;
226
+ }
227
+
228
+ function metaMatchPremise(premise, metaproofSteps, metaSubstitutions) {
149
229
  const metaproofStep = prune(metaproofSteps, (metaproofStep) => {
150
230
  const metaSubproofNode = metaproofStep.getMetaSubproofNode(),
151
231
  metastatementNode = metaproofStep.getMetastatementNode()
152
232
 
153
233
  if (metaSubproofNode !== null) {
154
- const metaSubProofMatches = premise.matchMetaSubproofNode(metaSubproofNode, metaSubstitutions);
234
+ const metaSubProofNodeMatches = premise.matchMetaSubproofNode(metaSubproofNode, metaSubstitutions);
155
235
 
156
- if (!metaSubProofMatches) { ///
236
+ if (!metaSubProofNodeMatches) { ///
157
237
  return true;
158
238
  }
159
239
  }
160
240
 
161
241
  if (metastatementNode !== null) {
162
- const metastatementMatches = premise.matchMetastatementNode(metastatementNode, metaSubstitutions);
242
+ const metastatementNodeMatches = premise.matchMetastatementNode(metastatementNode, metaSubstitutions);
163
243
 
164
- if (!metastatementMatches) { ///
244
+ if (!metastatementNodeMatches) { ///
165
245
  return true;
166
246
  }
167
247
  }
@@ -172,21 +252,21 @@ function matchPremise(premise, metaproofSteps, metaSubstitutions) {
172
252
  return premiseMatches;
173
253
  }
174
254
 
175
- function matchPremises(premise, metaproofSteps, metaSubstitutions) {
176
- const premisesMatches = premise.every((premise) => {
177
- const premiseMatches = matchPremise(premise, metaproofSteps, metaSubstitutions);
255
+ function metaMatchPremises(premise, metaproofSteps, metaSubstitutions) {
256
+ const premisesMatch = premise.every((premise) => {
257
+ const premiseMatches = metaMatchPremise(premise, metaproofSteps, metaSubstitutions);
178
258
 
179
259
  if (premiseMatches) {
180
260
  return true;
181
261
  }
182
262
  });
183
263
 
184
- return premisesMatches;
264
+ return premisesMatch;
185
265
  }
186
266
 
187
- function matchConclusion(conclusion, metastatementNode, metaSubstitutions) {
188
- const nonTerminalNodeMatches = conclusion.matchMetastatementNode(metastatementNode, metaSubstitutions),
189
- conclusionMatches = nonTerminalNodeMatches; ///
267
+ function metaMatchConclusion(conclusion, metastatementNode, metaSubstitutions) {
268
+ const metastatementNodeMatches = conclusion.matchMetastatementNode(metastatementNode, metaSubstitutions),
269
+ conclusionMatches = metastatementNodeMatches; ///
190
270
 
191
271
  return conclusionMatches;
192
272
  }
package/src/ruleNames.js CHANGED
@@ -4,12 +4,13 @@ export const TERM_RULE_NAME = "term";
4
4
  export const TYPE_RULE_NAME = "type";
5
5
  export const LABEL_RULE_NAME = "label";
6
6
  export const ARGUMENT_RULE_NAME = "argument";
7
+ export const SUBPROOF_RULE_NAME = "subproof";
8
+ export const STATEMENT_RULE_NAME = "statement";
7
9
  export const METAVARIABLE_RULE_NAME = "metavariable";
8
10
  export const METASTATEMENT_RULE_NAME = "metastatement";
9
11
  export const META_SUBPROOF_RULE_NAME = "metaSubproof";
12
+ export const QUALIFIED_STATEMENT_RULE_NAME = "qualifiedStatement";
10
13
  export const UNQUALIFIED_STATEMENT_RULE_NAME = "unqualifiedStatement";
11
14
  export const CONDITIONAL_INDICATIVE_RULE_NAME = "conditionalIndicative";
12
- export const COMBINATOR_DECLARATION_RULE_NAME = "combinatorDeclaration";
13
- export const CONSTRUCTOR_DECLARATION_RULE_NAME = "constructorDeclaration";
14
15
  export const QUALIFIED_METASTATEMENT_RULE_NAME = "qualifiedMetastatement";
15
16
  export const UNQUALIFIED_METASTATEMENT_RULE_NAME = "unqualifiedMetastatement";
@@ -1,59 +1,63 @@
1
1
  "use strict";
2
2
 
3
- import { matchNodes, bracketedChildNodeFromChildNodes } from "./utilities/node";
3
+ import { STATEMENT_RULE_NAME } from "./ruleNames";
4
+ import { matchNode, bracketedNonTerminalChildNodeFromChildNodes } from "./utilities/node";
4
5
 
5
6
  export default class Substitution {
6
- constructor(variableName, nodes) {
7
- this.variableName = variableName;
8
- this.nodes = nodes;
7
+ constructor(metavariableName, statementNode) {
8
+ this.metavariableName = metavariableName;
9
+ this.statementNode = statementNode;
9
10
  }
10
11
 
11
- getVariableName() {
12
- return this.variableName;
12
+ getMetavariableName() {
13
+ return this.metavariableName;
13
14
  }
14
15
 
15
- getNodes() {
16
- return this.nodes;
16
+ getStatementNode() {
17
+ return this.statementNode;
17
18
  }
18
19
 
19
- matchNodes(nodes) {
20
- let matches;
20
+ matchStatementNode(statementNode) {
21
+ let matchesStatementNode;
21
22
 
22
- const nodesA = this.nodes, ///
23
- nodesB = nodes,
24
- metaSubstitutionNodesMatch = matchNodes(nodesA, nodesB);
23
+ const nodeA = this.statementNode, ///
24
+ nodeB = statementNode,
25
+ nodeMatches = matchNode(nodeA, nodeB);
25
26
 
26
- matches = metaSubstitutionNodesMatch; ///
27
+ matchesStatementNode = nodeMatches; ///
27
28
 
28
- if (!matches) {
29
- const childNodes = nodes, ///
30
- bracketedChildNode = bracketedChildNodeFromChildNodes(childNodes);
29
+ if (!matchesStatementNode) {
30
+ const nonTerminalNode = statementNode, ///
31
+ childNodes = nonTerminalNode.getChildNodes(), ///
32
+ ruleName = STATEMENT_RULE_NAME;
31
33
 
32
- if (bracketedChildNode !== null) {
33
- const nonTerminalNode = bracketedChildNode, ///
34
- childNodes = nonTerminalNode.getChildNodes(),
35
- nodesB = childNodes, ///
36
- nodesMatch = matchNodes(nodesA, nodesB);
34
+ statementNode = bracketedNonTerminalChildNodeFromChildNodes(childNodes, ruleName); ///
37
35
 
38
- matches = nodesMatch; ///
36
+ if (statementNode !== null) {
37
+ const nodeA = this.statementNode, ///
38
+ nodeB = statementNode,
39
+ nodeMatches = matchNode(nodeA, nodeB);
40
+
41
+ matchesStatementNode = nodeMatches; ///
39
42
  }
40
43
  }
41
44
 
42
- return matches;
45
+ return matchesStatementNode;
43
46
  }
44
47
 
45
- static fromMetavariableNameAndNodes(variableName, nodes) {
46
- const bracketedChildNode = bracketedChildNodeFromChildNodes(nodes);
48
+ static fromMetavariableNameAndStatementNode(metavariableName, statementNode) {
49
+ let substitution = new Substitution(metavariableName, statementNode);
47
50
 
48
- if (bracketedChildNode !== null) {
49
- const nonTerminalNode = bracketedChildNode, ///
50
- childNodes = nonTerminalNode.getChildNodes();
51
+ const nonTerminalNode = statementNode, ///
52
+ childNodes = nonTerminalNode.getChildNodes(),
53
+ ruleName = STATEMENT_RULE_NAME;
51
54
 
52
- nodes = childNodes; ///
53
- }
55
+ statementNode = bracketedNonTerminalChildNodeFromChildNodes(childNodes, ruleName); ///
54
56
 
55
- const metaSubstitution = new Substitution(variableName, nodes);
57
+ if (statementNode !== null) {
58
+ substitution = new Substitution(metavariableName, statementNode);
59
+ }
56
60
 
57
- return metaSubstitution;
61
+ return substitution;
58
62
  }
59
63
  }
package/src/type.js CHANGED
@@ -17,39 +17,45 @@ export default class Type {
17
17
  }
18
18
 
19
19
  isEqualTo(type) {
20
- const equalToType = (this === type);
20
+ const equalTo = (this === type);
21
21
 
22
- return equalToType;
22
+ return equalTo;
23
23
  }
24
24
 
25
25
  isSubTypeOf(type) {
26
- let subTypeOfType = false;
26
+ let subTypeOf = false;
27
27
 
28
- if (this.superType === type) {
29
- subTypeOfType = true;
30
- } else {
31
- if (this.superType !== null) {
32
- subTypeOfType = this.superType.isSubTypeOf(type);
28
+ let superType = this.superType;
29
+
30
+ while (superType !== null) {
31
+ if (superType === type) {
32
+ subTypeOf = true;
33
+
34
+ break;
33
35
  }
36
+
37
+ superType = superType.getSuperType();
34
38
  }
35
39
 
36
- return subTypeOfType;
40
+ return subTypeOf;
37
41
  }
38
42
 
39
43
  isSuperTypeOf(type) {
40
- let superTypeOfType = false;
44
+ let superTypeOf = false;
41
45
 
42
- const superType = type.getSuperType();
46
+ let superType = type.getSuperType();
43
47
 
44
- if (superType === this) {
45
- superTypeOfType = true;
46
- } else {
47
- if (superType !== null) {
48
- superTypeOfType = superType.isSuperTypeOf(this);
48
+ while (superType !== null) {
49
+ if (superType === this) {
50
+ superTypeOf = true;
51
+
52
+ break;
49
53
  }
54
+
55
+ superType = superType.getSuperType();
50
56
  }
51
57
 
52
- return superTypeOfType;
58
+ return superTypeOf;
53
59
  }
54
60
 
55
61
  isEqualToOrSubTypeOf(type) {
@@ -68,13 +74,13 @@ export default class Type {
68
74
  return equalToTypeOrSuperTypeOf;
69
75
  }
70
76
 
71
- isEqualToSubTypeOfOrSuperTypeOf(type) {
77
+ match(type) {
72
78
  const equalToType = this.isEqualTo(type),
73
79
  subTypeOfType = this.isSubTypeOf(type),
74
80
  superTypeOfType = this.isSuperTypeOf(type),
75
- equalToTypeSubTypeOfOrSuperTypeOf = (equalToType || subTypeOfType || superTypeOfType);
81
+ matches = (equalToType || subTypeOfType || superTypeOfType);
76
82
 
77
- return equalToTypeSubTypeOfOrSuperTypeOf;
83
+ return matches;
78
84
  }
79
85
 
80
86
  matchName(name) {
@@ -61,10 +61,10 @@ export function matchBracketedNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB
61
61
  if (!bracketedNodeMatches) {
62
62
  const nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),
63
63
  childNodesA = nonTerminalNodeAChildNodes, ///
64
- bracketedChildNodeA = bracketedChildNodeFromChildNodes(childNodesA);
64
+ bracketedNonTerminalChildNodeA = bracketedNonTerminalChildNodeFromChildNodes(childNodesA);
65
65
 
66
- if (bracketedChildNodeA !== null) {
67
- const nodeA = bracketedChildNodeA, ///
66
+ if (bracketedNonTerminalChildNodeA !== null) {
67
+ const nodeA = bracketedNonTerminalChildNodeA, ///
68
68
  nodeB = nonTerminalNodeB, ///
69
69
  nodeMatches = matchNode(nodeA, nodeB);
70
70
 
@@ -75,10 +75,10 @@ export function matchBracketedNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB
75
75
  if (!bracketedNodeMatches) {
76
76
  const nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
77
77
  childNodesB = nonTerminalNodeBChildNodes, ///
78
- bracketedChildNodeB = bracketedChildNodeFromChildNodes(childNodesB);
78
+ bracketedNonTerminalChildNodeB = bracketedNonTerminalChildNodeFromChildNodes(childNodesB);
79
79
 
80
- if (bracketedChildNodeB !== null) {
81
- const nodeB = bracketedChildNodeB, ///
80
+ if (bracketedNonTerminalChildNodeB !== null) {
81
+ const nodeB = bracketedNonTerminalChildNodeB, ///
82
82
  nodeA = nonTerminalNodeA, ///
83
83
  nodeMatches = matchNode(nodeA, nodeB);
84
84
 
@@ -89,8 +89,8 @@ export function matchBracketedNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB
89
89
  return bracketedNodeMatches;
90
90
  }
91
91
 
92
- export function bracketedChildNodeFromChildNodes(childNodes) {
93
- let bracketedChildNode = null;
92
+ export function bracketedNonTerminalChildNodeFromChildNodes(childNodes, ruleName = METASTATEMENT_RULE_NAME) {
93
+ let bracketedNonTerminalChildNode = null;
94
94
 
95
95
  const childNodesLength = childNodes.length;
96
96
 
@@ -109,17 +109,17 @@ export function bracketedChildNodeFromChildNodes(childNodes) {
109
109
  nonTerminalNodeRuleName = nonTerminalNode.getRuleName(),
110
110
  firstTerminalNodeContent = firstTerminalNode.getContent(),
111
111
  secondTerminalNodeContent = secondTerminalNode.getContent(),
112
+ nonTerminalNodeRuleNameRuleName = (nonTerminalNodeRuleName === ruleName),
112
113
  firstTerminalNodeContentLeftBracket = (firstTerminalNodeContent === LEFT_BRACKET),
113
- secondTerminalNodeContentRightBracket = (secondTerminalNodeContent === RIGHT_BRACKET),
114
- nonTerminalNodeRuleNameMetastatementRuleName = (nonTerminalNodeRuleName === METASTATEMENT_RULE_NAME);
114
+ secondTerminalNodeContentRightBracket = (secondTerminalNodeContent === RIGHT_BRACKET);
115
115
 
116
- if (firstTerminalNodeContentLeftBracket && nonTerminalNodeRuleNameMetastatementRuleName && secondTerminalNodeContentRightBracket) {
117
- bracketedChildNode = nonTerminalNode; ///
116
+ if (nonTerminalNodeRuleNameRuleName && firstTerminalNodeContentLeftBracket && secondTerminalNodeContentRightBracket) {
117
+ bracketedNonTerminalChildNode = nonTerminalNode; ///
118
118
  }
119
119
  }
120
120
  }
121
121
 
122
- return bracketedChildNode;
122
+ return bracketedNonTerminalChildNode;
123
123
  }
124
124
 
125
125
  function matchTerminalNode(terminalNodeA, terminalNodeB) {
package/src/variable.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  export default class Variable {
4
- constructor(type, name, value) {
4
+ constructor(type, name, termNode) {
5
5
  this.type = type;
6
6
  this.name = name;
7
- this.value = value;
7
+ this.termNode = termNode;
8
8
  }
9
9
 
10
10
  getType() {
@@ -15,18 +15,12 @@ export default class Variable {
15
15
  return this.name;
16
16
  }
17
17
 
18
- getValue() {
19
- return this.value;
18
+ getTermNode() {
19
+ return this.termNode;
20
20
  }
21
21
 
22
- isDefined() {
23
- const defined = (this.value !== undefined);
24
-
25
- return defined;
26
- }
27
-
28
- setValue(value) {
29
- this.value = value;
22
+ setTermNode(termNode) {
23
+ this.termNode = termNode;
30
24
  }
31
25
 
32
26
  matchName(name) {
@@ -41,9 +35,9 @@ export default class Variable {
41
35
  if (variable === this) {
42
36
  equalTo = true;
43
37
  } else {
44
- const value = variable.getValue();
38
+ const termNode = variable.getTermNode();
45
39
 
46
- if (value === this.value) {
40
+ if (termNode === this.termNode) {
47
41
  equalTo = true;
48
42
  }
49
43
  }
@@ -66,8 +60,8 @@ export default class Variable {
66
60
  }
67
61
 
68
62
  static fromTypeAndName(type, name) {
69
- const value = undefined,
70
- variable = new Variable(type, name, value);
63
+ const termNode = null,
64
+ variable = new Variable(type, name, termNode);
71
65
 
72
66
  return variable;
73
67
  }
@@ -22,9 +22,14 @@ export default function verifyQualifiedStatement(qualifiedStatementNode, proofCo
22
22
 
23
23
  qualifiedStatementVerified = statementVerified; ///
24
24
  } else {
25
- const referenceName = referenceNameFromReferenceNode(referenceNode);
25
+ const referenceName = referenceNameFromReferenceNode(referenceNode),
26
+ rule = proofContext.findRuleByReferenceName(referenceName);
26
27
 
27
- debugger
28
+ if (rule !== null) {
29
+ const ruleMatchesStatement = rule.matchStatement(statementNode, proofContext);
30
+
31
+ qualifiedStatementVerified = ruleMatchesStatement; ///
32
+ }
28
33
  }
29
34
  }
30
35
 
@@ -1,35 +1,33 @@
1
1
  "use strict";
2
2
 
3
- import verifyEquality from "../verify/equality";
4
- import verifyTypeAssertion from "../verify/assertion/type";
3
+ import verifyStatementAsEquality from "../verify/statementAsEquality";
4
+ import verifyStatementTypeAssertion from "../verify/statementTypeAssertion";
5
5
 
6
- import { nodeQuery } from "../utilities/query";
7
6
  import { nodeAsString } from "../utilities/string";
8
7
 
9
- const equalityNodeQuery = nodeQuery("/statement/equality!"),
10
- typeAssertionNodeQuery = nodeQuery("/statement/typeAssertion!");
11
-
12
8
  export default function verifyStatement(statementNode, proofContext) {
13
9
  let statementVerified = false;
14
10
 
15
11
  proofContext.begin(statementNode);
16
12
 
17
- const equalityNode = equalityNodeQuery(statementNode),
18
- statementString = nodeAsString(statementNode),
19
- typeAssertionNode = typeAssertionNodeQuery(statementNode);
13
+ const statementString = nodeAsString(statementNode);
20
14
 
21
15
  proofContext.debug(`Verifying the '${statementString}' statement...`);
22
16
 
23
- if (equalityNode !== null) {
24
- const equalityVerified = verifyEquality(equalityNode, proofContext);
17
+ if (!statementVerified) {
18
+ const equalityVerifiedAsEquality = verifyStatementAsEquality(statementNode, proofContext);
25
19
 
26
- statementVerified = equalityVerified; ///
20
+ statementVerified = equalityVerifiedAsEquality; ///
27
21
  }
28
22
 
29
- if (typeAssertionNode !== null) {
30
- const typeAssertionVerified = verifyTypeAssertion(typeAssertionNode, proofContext);
23
+ if (!statementVerified) {
24
+ const statementTypeAssertionVerified = verifyStatementTypeAssertion(statementNode, proofContext);
25
+
26
+ statementVerified = statementTypeAssertionVerified; ///
27
+ }
31
28
 
32
- statementVerified = typeAssertionVerified; ///
29
+ if (!statementVerified) {
30
+ statementVerified = true; ///
33
31
  }
34
32
 
35
33
  statementVerified ?