occam-verify-cli 0.0.1077 → 0.0.1079

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
@@ -14,7 +14,7 @@ import { labelsFromJSON,
14
14
  premisesToPremisesJSON,
15
15
  conclusionToConclusionJSON } from "./utilities/json";
16
16
 
17
- const { reverse, correlate } = arrayUtilities;
17
+ const { extract, reverse, backwardsEvery } = arrayUtilities;
18
18
 
19
19
  const proofNodeQuery = nodeQuery("/rule/proof"),
20
20
  labelNodesQuery = nodesQuery("/rule/label"),
@@ -71,15 +71,13 @@ class Rule {
71
71
  let statementUnified;
72
72
 
73
73
  const { Substitutions } = shim,
74
- substitutions = Substitutions.fromNothing();
74
+ substitutions = Substitutions.fromNothing(),
75
+ conclusionUnified = this.unifyConclusion(statement, substitutions, localContext);
75
76
 
76
- statementUnified = this.conclusion.unifyStatement(statement, substitutions, localContext); ///
77
+ if (conclusionUnified) {
78
+ const premisesUnified = this.unifyPremises(substitutions, localContext);
77
79
 
78
- if (statementUnified) {
79
- const proofSteps = localContext.getProofSteps(),
80
- proofStepsUnified = this.unifyProofSteps(proofSteps, substitutions, localContext);
81
-
82
- if (proofStepsUnified) {
80
+ if (premisesUnified) {
83
81
  const substitutionsResolved = substitutions.areResolved();
84
82
 
85
83
  statementUnified = substitutionsResolved; ///
@@ -89,24 +87,70 @@ class Rule {
89
87
  return statementUnified;
90
88
  }
91
89
 
92
- unifyProofSteps(proofSteps, substitutions, localContext) {
93
- let proofStepsUnified;
90
+ unifyConclusion(statement, substitutions, localContext) {
91
+ let conclusionUnified;
92
+
93
+ const conclusionString = this.conclusion.getString();
94
+
95
+ localContext.trace(`Unifying the '${conclusionString}' conclusion...`);
94
96
 
95
- let premises = this.premises;
97
+ const statementUnified = this.conclusion.unifyStatement(statement, substitutions, localContext); ///
96
98
 
97
- premises = reverse(premises); ///
99
+ conclusionUnified = statementUnified; ///
100
+
101
+ if (conclusionUnified) {
102
+ localContext.debug(`...unified the '${conclusionString}' conclusion`);
103
+ }
104
+
105
+ return conclusionUnified;
106
+ }
107
+
108
+ unifyPremises(substitutions, localContext) {
109
+ let proofSteps = localContext.getProofSteps();
98
110
 
99
111
  proofSteps = reverse(proofSteps); ///
100
112
 
101
- proofStepsUnified = correlate(premises, proofSteps, (premise, proofStep) => {
102
- const proofStepUnified = premise.unifyProofStep(proofStep, substitutions, localContext);
113
+ const premisesUnified = backwardsEvery(this.premises, (premise) => {
114
+ const premiseUnified = this.unifyPremise(premise, proofSteps, substitutions, localContext);
103
115
 
104
- if (proofStepUnified) {
116
+ if (premiseUnified) {
105
117
  return true;
106
118
  }
107
119
  });
108
120
 
109
- return proofStepsUnified;
121
+ return premisesUnified;
122
+ }
123
+
124
+ unifyPremise(premise, proofSteps, substitutions, localContext) {
125
+ let premiseUnified =false;
126
+
127
+ const premiseString = premise.getString();
128
+
129
+ localContext.trace(`Unifying the '${premiseString}' premise...`);
130
+
131
+ const premiseResolvedIndependently = premise.resolveIndependently(substitutions, localContext);
132
+
133
+ if (premiseResolvedIndependently) {
134
+ premiseUnified = true;
135
+ } else {
136
+ const proofStep = extract(proofSteps, (proofStep) => {
137
+ const proofStepUnified = premise.unifyProofStep(proofStep, substitutions, localContext);
138
+
139
+ if (proofStepUnified) {
140
+ return true;
141
+ }
142
+ });
143
+
144
+ if (proofStep !== null) {
145
+ premiseUnified = true;
146
+ }
147
+ }
148
+
149
+ if (premiseUnified) {
150
+ localContext.debug(`...unified the '${premiseString}' premise.`);
151
+ }
152
+
153
+ return premiseUnified;
110
154
  }
111
155
 
112
156
  verify() {
@@ -74,6 +74,24 @@ class UnqualifiedStatement {
74
74
  return statementUnified;
75
75
  }
76
76
 
77
+ resolveIndependently(substitutions, localContextA, localContextB) {
78
+ let resolveIndependently;
79
+
80
+ const unqualifiedStatementString = this.getString(); ///
81
+
82
+ localContextB.trace(`Resolving the '${unqualifiedStatementString}' unqualified statement independently...`);
83
+
84
+ const statementResolvedIndependently = this.statement.resolveIndependently(substitutions, localContextA, localContextB);
85
+
86
+ resolveIndependently = statementResolvedIndependently; ///
87
+
88
+ if (resolveIndependently) {
89
+ localContextB.debug(`...resolved the '${unqualifiedStatementString}' unqualified statement independently.`);
90
+ }
91
+
92
+ return resolveIndependently;
93
+ }
94
+
77
95
  unifyStatementWithProofSteps(statement, assignments, stated, localContext) {
78
96
  let statementUnifiedWithProofSteps;
79
97
 
package/src/statement.js CHANGED
@@ -4,6 +4,7 @@ import shim from "./shim";
4
4
  import unifyMixins from "./mixins/statement/unify";
5
5
  import verifyMixins from "./mixins/statement/verify";
6
6
  import LocalContext from "./context/local";
7
+ import resolveMixins from "./mixins/statement/resolve";
7
8
  import metaLevelUnifier from "./unifier/metaLevel";
8
9
  import statementAsCombinatorVerifier from "./verifier/statementAsCombinator";
9
10
 
@@ -105,6 +106,35 @@ class Statement {
105
106
  return statementNodeMatches;
106
107
  }
107
108
 
109
+ resolveIndependently(substitutions, localContextA, localContextB) {
110
+ let resolvedIndependently;
111
+
112
+ const statement = this, ///
113
+ statementString = this.string; ///
114
+
115
+ localContextB.trace(`Resolving the '${statementString}' statement independently...`);
116
+
117
+ const context = localContextA; ///
118
+
119
+ localContextA = LocalContext.fromContextAndTokens(context, this.tokens);
120
+
121
+ const resolved = resolveMixins.some((resolveMixin) => {
122
+ const resolved = resolveMixin(statement, substitutions, localContextA, localContextB);
123
+
124
+ if (resolved) {
125
+ return true;
126
+ }
127
+ });
128
+
129
+ resolvedIndependently = resolved; ///
130
+
131
+ if (resolvedIndependently) {
132
+ localContextB.debug(`...resolved the '${statementString}' statement independently.`);
133
+ }
134
+
135
+ return resolvedIndependently;
136
+ }
137
+
108
138
  unifyStatement(statement, substitutions, localContextA, localContextB) {
109
139
  let statementUnified;
110
140
 
@@ -88,6 +88,8 @@ export default class FrameForMetavariableSubstitution extends Substitution {
88
88
 
89
89
  matchFrameNode(frameNode) { return this.frame.matchFrameNode(frameNode); }
90
90
 
91
+ matchMetavariableNode(metavariableNode) { return this.metavariable.matchMetavariableNode(metavariableNode); }
92
+
91
93
  matchMetavariableName(metavariableName) {
92
94
  let metavariableNameMatches;
93
95
 
@@ -201,9 +201,9 @@ export default class StatementForMetavariableSubstitution extends Substitution {
201
201
 
202
202
  statement = Statement.fromStatementNode(statementNode, localContext);
203
203
 
204
- const string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext),
204
+ const substitution = null,
205
205
  resolved = true,
206
- substitution = null,
206
+ string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext),
207
207
  statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, resolved, statement, metavariable, substitution);
208
208
 
209
209
  return statementForMetavariableSubstitution;
package/src/term.js CHANGED
@@ -42,13 +42,6 @@ class Term {
42
42
  this.type = type;
43
43
  }
44
44
 
45
- match(term) {
46
- const node = term.getNode(),
47
- matches = this.node.match(node);
48
-
49
- return matches;
50
- }
51
-
52
45
  getVariable(localContext) {
53
46
  let variable = null;
54
47
 
@@ -98,6 +91,23 @@ class Term {
98
91
  return grounded;
99
92
  }
100
93
 
94
+ isEqualTo(term) {
95
+ let equalTo = false;
96
+
97
+ const termNode = term.getNode(),
98
+ termNodeMatches = this.node.match(termNode);
99
+
100
+ if (termNodeMatches) {
101
+ const termType = term.getType();
102
+
103
+ if (this.type === termType) {
104
+ equalTo = true;
105
+ }
106
+ }
107
+
108
+ return equalTo;
109
+ }
110
+
101
111
  matchTermNode(termNode) {
102
112
  const termNodeMatches = this.node.match(termNode);
103
113
 
package/src/type.js CHANGED
@@ -83,12 +83,6 @@ class Type {
83
83
  return equalToOrSuperTypeOf;
84
84
  }
85
85
 
86
- match(type) {
87
- const matches = (type === this); ///
88
-
89
- return matches;
90
- }
91
-
92
86
  matchName(name) {
93
87
  const nodeMatches = (this.name === name);
94
88
 
@@ -57,9 +57,9 @@ export function findEquivalenceByType(equivalences, type) {
57
57
 
58
58
  export function findEquivalenceByTerm(equivalences, term) {
59
59
  const equivalence = equivalences.find((equivalence) => {
60
- const equivalenceMatchesTerm = equivalence.matchTerm(term);
60
+ const termEquates = equivalence.equateTerm(term);
61
61
 
62
- if (equivalenceMatchesTerm) {
62
+ if (termEquates) {
63
63
  return true;
64
64
  }
65
65
  }) || null;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ import { nodeQuery } from "../utilities/query";
4
+ import { variableNameFromVariableNode } from "../utilities/name";
5
+
6
+ const variableNodeQuery = nodeQuery("/term/variable!"),
7
+ metavariableNodeQuery = nodeQuery("/*/metavariable!");
8
+
9
+ export function termFromTermAndSubstitutions(term, substitutions) {
10
+ if (term !== null) {
11
+ const termNode = term.getNode();
12
+
13
+ term = null;
14
+
15
+ const variableNode = variableNodeQuery(termNode);
16
+
17
+ if (variableNode !== null) {
18
+ const variableName = variableNameFromVariableNode(variableNode),
19
+ substitution = substitutions.findSubstitution((substitution) => {
20
+ const variableNameMatches = substitution.matchVariableName(variableName);
21
+
22
+ if (variableNameMatches) {
23
+ return true;
24
+ }
25
+ });
26
+
27
+ if (substitution !== null) {
28
+ term = substitution.getTerm();
29
+ }
30
+ }
31
+ }
32
+
33
+ return term;
34
+ }
35
+
36
+ export function frameFromFrameAndSubstitutions(frame, substitutions) {
37
+ if (frame !== null) {
38
+ const frameNode = frame.getNode();
39
+
40
+ frame = null;
41
+
42
+ const metavariableNode = metavariableNodeQuery(frameNode);
43
+
44
+ if (metavariableNode !== null) {
45
+ const substitution = substitutions.findSubstitution((substitution) => {
46
+ const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
47
+
48
+ if (metavariableNodeMatches) {
49
+ return true;
50
+ }
51
+ });
52
+
53
+ if (substitution !== null) {
54
+ frame = substitution.getFrame();
55
+ }
56
+ }
57
+ }
58
+
59
+ return frame;
60
+ }
61
+
62
+ export function statementFromStatementAndSubstitutions(statement, substitutions) {
63
+ if (statement !== null) {
64
+ const statementNode = statement.getNode();
65
+
66
+ statement = null;
67
+
68
+ const metavariableNode = metavariableNodeQuery(statementNode);
69
+
70
+ if (metavariableNode !== null) {
71
+ const substitution = substitutions.findSubstitution((substitution) => {
72
+ const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
73
+
74
+ if (metavariableNodeMatches) {
75
+ return true;
76
+ }
77
+ });
78
+
79
+ if (substitution !== null) {
80
+ statement = substitution.getStatement();
81
+ }
82
+ }
83
+ }
84
+
85
+ return statement;
86
+ }