occam-verify-cli 0.0.843 → 0.0.844

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.
@@ -107,35 +107,47 @@ export default class Equivalence {
107
107
  return termNodesMatch;
108
108
  }
109
109
 
110
- getVariables(context) {
111
- const variables = [];
112
-
110
+ getGroundedTerms(definedVariables, groundedTerms, context) {
113
111
  this.terms.forEach((term) => {
114
- term.getVariables(variables, context);
115
- });
112
+ const termGrounded = term.isGrounded(definedVariables, context);
113
+
114
+ if (termGrounded) {
115
+ const termMatchesGroundedTerm = groundedTerms.some((groundedTerm) => {
116
+ const termMatchesGroundedTerm = term.match(groundedTerm);
117
+
118
+ if (termMatchesGroundedTerm) {
119
+ return true;
120
+ }
121
+ })
116
122
 
117
- return variables;
123
+ if (!termMatchesGroundedTerm) {
124
+ const groundedTerm = term;
125
+
126
+ groundedTerms.push(groundedTerm);
127
+ }
128
+ }
129
+ });
118
130
  }
119
131
 
120
- isInitiallyGrounded() {
121
- const initiallyGroundedTerms = this.getInitiallyGroundedTerms(),
132
+ isInitiallyGrounded(context) {
133
+ const initiallyGroundedTerms = this.getInitiallyGroundedTerms(context),
122
134
  initiallyGroundedTermsLength = initiallyGroundedTerms.length,
123
135
  initiallyGrounded = (initiallyGroundedTermsLength > 0);
124
136
 
125
137
  return initiallyGrounded;
126
138
  }
127
139
 
128
- isImplicitlyGrounded(definedVariables) {
129
- const implicitlyGroundedTerms = this.getImplicitlyGroundedTerms(definedVariables),
140
+ isImplicitlyGrounded(definedVariables, context) {
141
+ const implicitlyGroundedTerms = this.getImplicitlyGroundedTerms(definedVariables, context),
130
142
  implicitlyGroundedTermsLength = implicitlyGroundedTerms.length,
131
143
  implicitlyGrounded = (implicitlyGroundedTermsLength > 0);
132
144
 
133
145
  return implicitlyGrounded;
134
146
  }
135
147
 
136
- getInitiallyGroundedTerms() {
148
+ getInitiallyGroundedTerms(context) {
137
149
  const initiallyGroundedTerms = this.terms.reduce((initiallyGroundedTerms, term) => {
138
- const termInitiallyGrounded = term.isInitiallyGrounded();
150
+ const termInitiallyGrounded = term.isInitiallyGrounded(context);
139
151
 
140
152
  if (termInitiallyGrounded) {
141
153
  const initiallyGroundedTerm = term; ///
@@ -149,9 +161,9 @@ export default class Equivalence {
149
161
  return initiallyGroundedTerms;
150
162
  }
151
163
 
152
- getImplicitlyGroundedTerms(definedVariables) {
164
+ getImplicitlyGroundedTerms(definedVariables, context) {
153
165
  const implicitlyGroundedTerms = this.terms.reduce((implicitlyGroundedTerms, term) => {
154
- const termImplicitlyGrounded = term.isImplicitlyGrounded(definedVariables);
166
+ const termImplicitlyGrounded = term.isImplicitlyGrounded(definedVariables, context);
155
167
 
156
168
  if (termImplicitlyGrounded) {
157
169
  const implicitlyGroundedTerm = term; ///
package/src/term.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import { filter } from "./utilities/array";
3
4
  import { nodesQuery } from "./utilities/query"
4
5
 
5
6
  const variableNodesQuery = nodesQuery("//variable");
@@ -25,8 +26,9 @@ export default class Term {
25
26
  return matches;
26
27
  }
27
28
 
28
- getVariables(variables, context) {
29
- const variableNodes = variableNodesQuery(this.node);
29
+ getVariables(context) {
30
+ const variables = [],
31
+ variableNodes = variableNodesQuery(this.node);
30
32
 
31
33
  variableNodes.forEach((variableNode) => {
32
34
  const variable = context.findVariableByVariableNode(variableNode),
@@ -40,31 +42,35 @@ export default class Term {
40
42
  return variables;
41
43
  }
42
44
 
43
- isInitiallyGrounded() {
44
- const definedVariables = [],
45
- implicitlyGrounded = this.isImplicitlyGrounded(definedVariables),
46
- initiallyGrounded = implicitlyGrounded; ///
45
+ isGrounded(definedVariables, context) {
46
+ const variables = this.getVariables(context);
47
+
48
+ filter(variables, (variable) => {
49
+ const definedVariablesIncludesVariable = definedVariables.includes(variable);
50
+
51
+ if (!definedVariablesIncludesVariable) {
52
+ return true;
53
+ }
54
+ });
55
+
56
+ const undefinedVariables = variables, ///
57
+ undefinedVariablesLength = undefinedVariables.length,
58
+ grounded = (undefinedVariablesLength <= 1);
59
+
60
+ return grounded;
61
+ }
62
+
63
+ isInitiallyGrounded(context) {
64
+ const variables = this.getVariables(context),
65
+ variablesLength = variables.length,
66
+ initiallyGrounded = (variablesLength === 0);
47
67
 
48
68
  return initiallyGrounded;
49
69
  }
50
70
 
51
- isImplicitlyGrounded(definedVariables) {
52
- const variableNodes = variableNodesQuery(this.node),
53
- variables = definedVariables, ///
54
- nodes = variableNodes, ///
55
- implicitlyGrounded = nodes.every((node) => {
56
- const variableMatchesNode = variables.some((variable) => {
57
- const variableMatchesNode = variable.matchNode(node);
58
-
59
- if (variableMatchesNode) {
60
- return true;
61
- }
62
- });
63
-
64
- if (variableMatchesNode) {
65
- return true;
66
- }
67
- });
71
+ isImplicitlyGrounded(definedVariables, context) {
72
+ const grounded = this.isGrounded(definedVariables, context),
73
+ implicitlyGrounded = grounded; ///
68
74
 
69
75
  return implicitlyGrounded;
70
76
  }
@@ -29,6 +29,12 @@ export function someSubArray(array, subArrayLength, callback) {
29
29
  permutations = permutationsMatrix[indexesLength][permutationLength];
30
30
  }
31
31
 
32
+ if (subArrayLength === 4) {
33
+ permutations = [
34
+ [ 0, 2, 3, 4 ]
35
+ ];
36
+ }
37
+
32
38
  if (permutations !== null) {
33
39
  found = permutations.some((permutation) => {
34
40
  if (permutation !== null) {
@@ -1,6 +1,43 @@
1
1
  "use strict";
2
2
 
3
- import { push, filter, compress, separate } from "../utilities/array";
3
+ import { push, compress, separate } from "../utilities/array";
4
+
5
+ export function mergeEquivalences(equivalencesA, equivalencesB, localContext) {
6
+ const typesA = typesFromEquivalences(equivalencesA, localContext),
7
+ typesB = typesFromEquivalences(equivalencesB, localContext),
8
+ types = [
9
+ ...typesA,
10
+ ...typesB
11
+ ];
12
+
13
+ compress(types, (typeA, typeB) => {
14
+ if (typeA === typeB) {
15
+ return true;
16
+ }
17
+ });
18
+
19
+ const equivalences = types.map((type) => {
20
+ let equivalence;
21
+
22
+ const equivalenceA = findEquivalenceByType(equivalencesA, type, localContext),
23
+ equivalenceB = findEquivalenceByType(equivalencesB, type, localContext);
24
+
25
+ if ((equivalenceA !== null) && (equivalenceB !== null)) {
26
+ const leftEquivalence = equivalenceA, ///
27
+ rightEquivalence = equivalenceB; ///
28
+
29
+ equivalence = Equivalence.merge(leftEquivalence, rightEquivalence);
30
+ } else if (equivalenceA !== null) {
31
+ equivalence = equivalenceA; ///
32
+ } else if (equivalenceB !== null) {
33
+ equivalence = equivalenceB; ///
34
+ }
35
+
36
+ return equivalence;
37
+ });
38
+
39
+ return equivalences;
40
+ }
4
41
 
5
42
  export function areTermNodesEqual(leftTermNode, rightTermNode, equivalences) {
6
43
  let termNodesEqual;
@@ -46,87 +83,62 @@ export function findEquivalenceByTerm(equivalences, term) {
46
83
  return equivalence;
47
84
  }
48
85
 
49
- export function mergeEquivalences(equivalencesA, equivalencesB, localContext) {
50
- const typesA = typesFromEquivalences(equivalencesA, localContext),
51
- typesB = typesFromEquivalences(equivalencesB, localContext),
52
- types = [
53
- ...typesA,
54
- ...typesB
55
- ];
86
+ export function groundedTermsAndDefinedVariablesFromFromEquivalences(equivalences, groundedTerms, definedVariables, context) {
87
+ let groundedEquivalences,
88
+ remainingEquivalences,
89
+ initiallyGroundedEquivalences,
90
+ implicitlyGroundedEquivalences;
56
91
 
57
- compress(types, (typeA, typeB) => {
58
- if (typeA === typeB) {
59
- return true;
60
- }
61
- });
92
+ remainingEquivalences = [];
62
93
 
63
- const equivalences = types.map((type) => {
64
- let equivalence;
94
+ initiallyGroundedEquivalences = [];
65
95
 
66
- const equivalenceA = findEquivalenceByType(equivalencesA, type, localContext),
67
- equivalenceB = findEquivalenceByType(equivalencesB, type, localContext);
96
+ separateInitiallyGroundedEquivalences(equivalences, remainingEquivalences, initiallyGroundedEquivalences, context);
68
97
 
69
- if ((equivalenceA !== null) && (equivalenceB !== null)) {
70
- const leftEquivalence = equivalenceA, ///
71
- rightEquivalence = equivalenceB; ///
98
+ const initiallyGroundedEquivalencesLength = initiallyGroundedEquivalences.length;
72
99
 
73
- equivalence = Equivalence.merge(leftEquivalence, rightEquivalence);
74
- } else if (equivalenceA !== null) {
75
- equivalence = equivalenceA; ///
76
- } else if (equivalenceB !== null) {
77
- equivalence = equivalenceB; ///
78
- }
100
+ if (initiallyGroundedEquivalencesLength > 0) {
101
+ groundedEquivalences = initiallyGroundedEquivalences; ///
79
102
 
80
- return equivalence;
81
- });
103
+ let implicitlyGroundedEquivalencesLength = 1;
82
104
 
83
- return equivalences;
84
- }
105
+ while (implicitlyGroundedEquivalencesLength > 0) {
106
+ let definedVariablesLength = 0,
107
+ previousDefinedVariablesLength = -1;
85
108
 
86
- export function separateEquivalences(equivalences, remainingEquivalences, initiallyGroundedEquivalences) {
87
- separate(equivalences, remainingEquivalences, initiallyGroundedEquivalences, (equivalence) => {
88
- const equivalenceInitiallyGrounded = equivalence.isInitiallyGrounded();
109
+ while (definedVariablesLength > previousDefinedVariablesLength) {
110
+ previousDefinedVariablesLength = definedVariablesLength; ///
89
111
 
90
- if (!equivalenceInitiallyGrounded) {
91
- return true;
92
- }
93
- });
94
- }
112
+ groundedTermsFromGroundedEquivalencesAndDefinedVariables(groundedEquivalences, definedVariables, groundedTerms, context);
95
113
 
96
- export function compressDefinedVariables(definedVariables) {
97
- compress(definedVariables, (definedVariableA, definedVariableB) => {
98
- if (definedVariableA === definedVariableB) {
99
- return true;
100
- }
101
- });
102
- }
114
+ definedVariablesFromGroundedTerms(groundedTerms, definedVariables, context);
103
115
 
104
- export function definedVariablesFromGroundedEquivalences(groundedEquivalences, definedVariables, context) {
105
- groundedEquivalences.forEach((groundedEquivalence) => {
106
- const variables = groundedEquivalence.getVariables(context);
116
+ definedVariablesLength = definedVariables.length;
117
+ }
107
118
 
108
- push(definedVariables, variables);
109
- });
110
- }
119
+ equivalences = remainingEquivalences; ///
111
120
 
112
- export function implicitlyGroundedEquivalencesFromRemainingEquivalencesAndDefinedVariables(remainingEquivalences, definedVariables) {
113
- const implicitlyGroundedEquivalences = [];
121
+ remainingEquivalences = [];
114
122
 
115
- filter(remainingEquivalences, (remainingEquivalence) => {
116
- const remainingEquivalenceImplicitlyGrounded = remainingEquivalence.isImplicitlyGrounded(definedVariables);
123
+ implicitlyGroundedEquivalences = [];
117
124
 
118
- if (remainingEquivalenceImplicitlyGrounded) {
119
- const implicitlyGroundedEquivalence = remainingEquivalence; ///
125
+ separateImplicitlyGroundedEquivalences(equivalences, remainingEquivalences, implicitlyGroundedEquivalences, definedVariables, context);
120
126
 
121
- implicitlyGroundedEquivalences.push(implicitlyGroundedEquivalence);
122
- }
127
+ push(groundedEquivalences, implicitlyGroundedEquivalences);
123
128
 
124
- if (!remainingEquivalenceImplicitlyGrounded) {
125
- return true;
129
+ implicitlyGroundedEquivalencesLength = implicitlyGroundedEquivalences.length; ///
126
130
  }
131
+ }
132
+ }
133
+
134
+ function typesFromEquivalences(equivalences, localContext) {
135
+ const types = equivalences.map((equivalence) => {
136
+ const type = equivalence.getType(localContext);
137
+
138
+ return type;
127
139
  });
128
140
 
129
- return implicitlyGroundedEquivalences;
141
+ return types;
130
142
  }
131
143
 
132
144
  function findEquivalenceByTermNodes(equivalences, termNodes) {
@@ -141,12 +153,47 @@ function findEquivalenceByTermNodes(equivalences, termNodes) {
141
153
  return equivalence;
142
154
  }
143
155
 
144
- function typesFromEquivalences(equivalences, localContext) {
145
- const types = equivalences.map((equivalence) => {
146
- const type = equivalence.getType(localContext);
156
+ function definedVariablesFromGroundedTerms(groundedTerms, definedVariables, context) {
157
+ const terms = groundedTerms, ///
158
+ variables = definedVariables; ///
147
159
 
148
- return type;
160
+ terms.forEach((term) => {
161
+ const termVariables = term.getVariables(context);
162
+
163
+ termVariables.forEach((termVariable) => {
164
+ const variablesIncludesTermVariable = variables.includes(termVariable);
165
+
166
+ if (!variablesIncludesTermVariable) {
167
+ const variable = termVariable; ///
168
+
169
+ variables.push(variable);
170
+ }
171
+ });
149
172
  });
173
+ }
150
174
 
151
- return types;
175
+ function separateInitiallyGroundedEquivalences(equivalences, remainingEquivalences, initiallyGroundedEquivalences, context) {
176
+ separate(equivalences, remainingEquivalences, initiallyGroundedEquivalences, (equivalence) => {
177
+ const equivalenceInitiallyGrounded = equivalence.isInitiallyGrounded(context);
178
+
179
+ if (!equivalenceInitiallyGrounded) {
180
+ return true;
181
+ }
182
+ });
183
+ }
184
+
185
+ function separateImplicitlyGroundedEquivalences(equivalences, remainingEquivalences, implicitlyGroundedEquivalences, definedVariables, context) {
186
+ separate(equivalences, remainingEquivalences, implicitlyGroundedEquivalences, (equivalence) => {
187
+ const equivalenceImplicitlyGrounded = equivalence.isImplicitlyGrounded(definedVariables, context);
188
+
189
+ if (!equivalenceImplicitlyGrounded) {
190
+ return true;
191
+ }
192
+ });
193
+ }
194
+
195
+ function groundedTermsFromGroundedEquivalencesAndDefinedVariables(groundedEquivalences, definedVariables, groundedTerms, context) {
196
+ groundedEquivalences.forEach((groundedEquivalence) => {
197
+ groundedEquivalence.getGroundedTerms(definedVariables, groundedTerms, context);
198
+ });
152
199
  }
@@ -1,32 +1,67 @@
1
1
  "use strict";
2
2
 
3
- import { second } from "../utilities/array";
3
+ import verifyTerm from "./term";
4
+
4
5
  import { DEFINED } from "../constants";
5
6
  import { nodeQuery } from "../utilities/query";
7
+ import { first, second } from "../utilities/array";
6
8
 
7
- const definedVariableNodeQuery = nodeQuery("/argument/term/variable!");
9
+ const termNodeQuery = nodeQuery("/argument/term!"),
10
+ variableNodeQuery = nodeQuery("/argument/term/variable!");
8
11
 
9
12
  export default function verifyDefining(argumentNode, definingNode, context) {
10
13
  let definingVerified = false;
11
14
 
12
- const definedVariableNode = definedVariableNodeQuery(argumentNode);
15
+ const defined = definedFromDefiningNode(definingNode),
16
+ termNode = termNodeQuery(argumentNode),
17
+ variableNode = variableNodeQuery(argumentNode);
18
+
19
+ if (false) {
20
+ ///
21
+ } else if (variableNode !== null) {
22
+ const variable = context.findVariableByVariableNode(variableNode);
13
23
 
14
- if (definedVariableNode !== null) {
15
- const defined = definedFromDefiningNode(definingNode),
16
- variableNode = definedVariableNode, ///
17
- variableDefined = context.isVariableDefined(variableNode);
24
+ if (variable !== null) {
25
+ const variableDefined = context.isVariableDefined(variable);
18
26
 
19
- if (defined) {
20
- if (variableDefined) {
21
- definingVerified = true;
27
+ if (defined) {
28
+ if (variableDefined) {
29
+ definingVerified = true;
30
+ }
22
31
  }
23
- }
24
32
 
25
- if (!defined) {
26
- if (!variableDefined) {
27
- definingVerified = true;
33
+ if (!defined) {
34
+ if (!variableDefined) {
35
+ definingVerified = true;
36
+ }
28
37
  }
29
38
  }
39
+ } else if (termNode !== null) {
40
+ const terms = [],
41
+ termVerified = verifyTerm(termNode, terms, context, () => {
42
+ let verifiedAhead;
43
+
44
+ const firstTerm = first(terms),
45
+ term = firstTerm, ///
46
+ termGrounded = context.isTermGrounded(term);
47
+
48
+ if (defined) {
49
+ if (termGrounded) {
50
+ verifiedAhead = true;
51
+ }
52
+ }
53
+
54
+ if (!defined) {
55
+ if (!termGrounded) {
56
+ verifiedAhead = true;
57
+ }
58
+ }
59
+
60
+ return verifiedAhead;
61
+ });
62
+
63
+ definingVerified = termVerified; ///
64
+
30
65
  }
31
66
 
32
67
  return definingVerified;