occam-verify-cli 0.0.1032 → 0.0.1035

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 (51) hide show
  1. package/lib/argument.js +2 -3
  2. package/lib/assertion/subproof.js +50 -11
  3. package/lib/assertion/type.js +180 -0
  4. package/lib/constructor.js +3 -2
  5. package/lib/context/file.js +32 -13
  6. package/lib/context/local.js +15 -15
  7. package/lib/context/release.js +9 -24
  8. package/lib/equality.js +5 -5
  9. package/lib/mixins/statement/verify.js +3 -3
  10. package/lib/premise.js +21 -12
  11. package/lib/substitution/termForVariable.js +15 -18
  12. package/lib/supposition.js +19 -10
  13. package/lib/term.js +21 -16
  14. package/lib/theorem.js +107 -6
  15. package/lib/unifier/intrinsicLevel.js +9 -4
  16. package/lib/unifier/metaLevel.js +10 -4
  17. package/lib/unifier/statementWithCombinator.js +2 -2
  18. package/lib/utilities/array.js +5 -2
  19. package/lib/utilities/unify.js +2 -14
  20. package/lib/variable.js +65 -13
  21. package/lib/verifier/topLevel.js +3 -3
  22. package/package.json +1 -1
  23. package/src/argument.js +1 -3
  24. package/src/assertion/subproof.js +74 -15
  25. package/src/assertion/type.js +176 -0
  26. package/src/constructor.js +3 -1
  27. package/src/context/file.js +48 -14
  28. package/src/context/local.js +17 -7
  29. package/src/context/release.js +11 -35
  30. package/src/equality.js +4 -4
  31. package/src/mixins/statement/verify.js +3 -2
  32. package/src/premise.js +29 -16
  33. package/src/substitution/termForVariable.js +21 -21
  34. package/src/supposition.js +24 -11
  35. package/src/term.js +22 -17
  36. package/src/theorem.js +87 -1
  37. package/src/unifier/intrinsicLevel.js +16 -3
  38. package/src/unifier/metaLevel.js +18 -3
  39. package/src/unifier/statementWithCombinator.js +1 -1
  40. package/src/utilities/array.js +1 -1
  41. package/src/utilities/unify.js +1 -16
  42. package/src/variable.js +88 -18
  43. package/src/verifier/topLevel.js +3 -2
  44. package/lib/unify/variableWithTerm.js +0 -39
  45. package/lib/verify/assertion/type.js +0 -99
  46. package/lib/verify/lemma.js +0 -48
  47. package/lib/verify/theorem.js +0 -47
  48. package/src/unify/variableWithTerm.js +0 -37
  49. package/src/verify/assertion/type.js +0 -139
  50. package/src/verify/lemma.js +0 -70
  51. package/src/verify/theorem.js +0 -65
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import shim from "../shim";
3
4
  import Substitution from "../substitution";
4
5
 
5
6
  import { nodeQuery } from "../utilities/query";
@@ -25,12 +26,6 @@ export default class TermForVariableSubstitution extends Substitution {
25
26
  return this.variableNode;
26
27
  }
27
28
 
28
- getNode() {
29
- const node = this.termNode; ///
30
-
31
- return node;
32
- }
33
-
34
29
  transformed(substitutions) {
35
30
  let transformedSubstitution = null;
36
31
 
@@ -88,6 +83,22 @@ export default class TermForVariableSubstitution extends Substitution {
88
83
  return unifiedWithEquivalence;
89
84
  }
90
85
 
86
+ static fromTernAndVariable(term, variable, localContext) {
87
+ let termNode = term.getNode();
88
+
89
+ termNode = stripBracketsFromTerm(termNode); ///
90
+
91
+ const { Term } = shim;
92
+
93
+ term = Term.fromTermNode(termNode, localContext)
94
+
95
+ const string = stringFromTermAndVariable(term, variable),
96
+ variableNode = variable.getNode(),
97
+ termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode);
98
+
99
+ return termForVariableSubstitution;
100
+ }
101
+
91
102
  static fromSubstitutionNode(substitutionNode) {
92
103
  let termForVariableSubstitution = null;
93
104
 
@@ -106,15 +117,6 @@ export default class TermForVariableSubstitution extends Substitution {
106
117
 
107
118
  return termForVariableSubstitution;
108
119
  }
109
-
110
- static fromTernNodeAndVariableNode(termNode, variableNode, localContextA, localContextB) {
111
- termNode = stripBracketsFromTerm(termNode); ///
112
-
113
- const string = stringFromTermNodeAndVariableNode(termNode, variableNode, localContextA, localContextB),
114
- termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode);
115
-
116
- return termForVariableSubstitution;
117
- }
118
120
  }
119
121
 
120
122
  function transformTermNode(termNode, substitutions) {
@@ -162,12 +164,10 @@ function transformVariableNode(variableNode, substitutions) {
162
164
  return transformedVariableNode;
163
165
  }
164
166
 
165
- function stringFromTermNodeAndVariableNode(termNode, variableNode, localContextA, localContextB) {
166
- const termNodeB = termNode, ///
167
- termStringB = localContextB.nodeAsString(termNodeB),
168
- variableNodeA = variableNode, ///
169
- variableStringA = localContextA.nodeAsString(variableNodeA),
170
- string = `[${termStringB} for ${variableStringA}]`;
167
+ function stringFromTermAndVariable(term, variable) {
168
+ const termString = term.getString(),
169
+ variableString = variable.getString(),
170
+ string = `[${termString} for ${variableString}]`;
171
171
 
172
172
  return string;
173
173
  }
@@ -12,8 +12,9 @@ import { assignAssignments } from "./utilities/assignments";
12
12
  const unqualifiedStatementNodeQuery = nodeQuery("/supposition/unqualifiedStatement");
13
13
 
14
14
  export default class Supposition {
15
- constructor(fileContext, unqualifiedStatement) {
15
+ constructor(fileContext, subproofAssertion, unqualifiedStatement) {
16
16
  this.fileContext = fileContext;
17
+ this.subproofAssertion = subproofAssertion;
17
18
  this.unqualifiedStatement = unqualifiedStatement;
18
19
  }
19
20
 
@@ -21,6 +22,10 @@ export default class Supposition {
21
22
  return this.fileContext;
22
23
  }
23
24
 
25
+ getSubproofAssertion() {
26
+ return this.subproofAssertion;
27
+ }
28
+
24
29
  getUnqualifiedStatement() {
25
30
  return this.unqualifiedStatement;
26
31
  }
@@ -90,12 +95,8 @@ export default class Supposition {
90
95
 
91
96
  localContext.trace(`Unifying the '${subproofString}' subproof with the supposition's '${suppositionStatementString}' statement...`);
92
97
 
93
- const statement = this.unqualifiedStatement.getStatement(),
94
- statementNode = statement.getNode(),
95
- subproofAssertion = SubproofAssertion.fromStatementNode(statementNode, this.fileContext);
96
-
97
- if (subproofAssertion !== null) {
98
- subproofUnified = subproofAssertion.unifySubproof(subproof, substitutions, localContext);
98
+ if (this.subproofAssertion !== null) {
99
+ subproofUnified = this.subproofAssertion.unifySubproof(subproof, substitutions, localContext);
99
100
  }
100
101
 
101
102
  if (subproofUnified) {
@@ -142,22 +143,33 @@ export default class Supposition {
142
143
 
143
144
  toJSON() {
144
145
  const unqualifiedStatementJSON = this.unqualifiedStatement.toJSON(),
146
+ subproofAssertionJSON = (this.subproofAssertion !== null) ?
147
+ this.subproofAssertion.toJSON() :
148
+ null,
145
149
  unqualifiedStatement = unqualifiedStatementJSON, ///
150
+ subproofAssertion = subproofAssertionJSON, ///
146
151
  json = {
147
- unqualifiedStatement
152
+ unqualifiedStatement,
153
+ subproofAssertion
148
154
  };
149
155
 
150
156
  return json;
151
157
  }
152
158
 
153
159
  static fromJSON(json, fileContext) {
154
- let { unqualifiedStatement } = json;
160
+ let { subproofAssertion, unqualifiedStatement } = json;
155
161
 
156
162
  json = unqualifiedStatement; ///
157
163
 
158
164
  unqualifiedStatement = UnqualifiedStatement.fromJSON(json, fileContext);
159
165
 
160
- const supposition = new Supposition(fileContext, unqualifiedStatement);
166
+ json = subproofAssertion; ///
167
+
168
+ subproofAssertion = (json !== null) ?
169
+ SubproofAssertion.fromJSON(json, fileContext) :
170
+ null;
171
+
172
+ const supposition = new Supposition(fileContext, subproofAssertion, unqualifiedStatement);
161
173
 
162
174
  return supposition;
163
175
  }
@@ -165,7 +177,8 @@ export default class Supposition {
165
177
  static fromSuppositionNode(suppositionNode, fileContext) {
166
178
  const unqualifiedStatementNode = unqualifiedStatementNodeQuery(suppositionNode),
167
179
  unqualifiedStatement = UnqualifiedStatement.fromUnqualifiedStatementNode(unqualifiedStatementNode, fileContext),
168
- supposition = new Supposition(fileContext, unqualifiedStatement);
180
+ subproofAssertion = SubproofAssertion.fromUnqualifiedStatementNode(unqualifiedStatementNode, fileContext),
181
+ supposition = new Supposition(fileContext, subproofAssertion, unqualifiedStatement);
169
182
 
170
183
  return supposition
171
184
  }
package/src/term.js CHANGED
@@ -8,6 +8,7 @@ import termAsConstructorVerifier from "./verifier/termAsConstructor";
8
8
  import { filter } from "./utilities/array";
9
9
  import { nodesQuery } from "./utilities/query"
10
10
  import { termNodeFromTermString } from "./utilities/node";
11
+ import {objectType} from "./type";
11
12
 
12
13
  const variableNodesQuery = nodesQuery("//variable");
13
14
 
@@ -136,22 +137,26 @@ class Term {
136
137
  verifyType(fileContext) {
137
138
  let typeVerified;
138
139
 
139
- const typeName = this.type.getName();
140
+ if (this.type === objectType) {
141
+ typeVerified = true;
142
+ } else {
143
+ const typeName = this.type.getName();
140
144
 
141
- fileContext.trace(`Verifying the '${typeName}' type...`);
145
+ fileContext.trace(`Verifying the '${typeName}' type...`);
142
146
 
143
- const type = fileContext.findTypeByTypeName(typeName);
147
+ const type = fileContext.findTypeByTypeName(typeName);
144
148
 
145
- if (type === null) {
146
- fileContext.debug(`The '${typeName}' type is missing.`);
147
- } else {
148
- this.type = type; ///
149
+ if (type === null) {
150
+ fileContext.debug(`The '${typeName}' type is missing.`);
151
+ } else {
152
+ this.type = type; ///
149
153
 
150
- typeVerified = true;
151
- }
154
+ typeVerified = true;
155
+ }
152
156
 
153
- if (typeVerified) {
154
- fileContext.debug(`...verified the '${typeName}' type.`);
157
+ if (typeVerified) {
158
+ fileContext.debug(`...verified the '${typeName}' type.`);
159
+ }
155
160
  }
156
161
 
157
162
  return typeVerified;
@@ -160,10 +165,10 @@ class Term {
160
165
  verifyGivenType(type, localContext) {
161
166
  let verifiedGivenType;
162
167
 
163
- const termString = this.getString(),
164
- typeString = type.getString();
168
+ const typeName = type.getName(),
169
+ termString = this.getString();
165
170
 
166
- localContext.trace(`Verifying the '${termString}' term given the '${typeString}' type...`);
171
+ localContext.trace(`Verifying the '${termString}' term given the '${typeName}' type...`);
167
172
 
168
173
  const verified = this.verify(localContext, () => {
169
174
  let verifiedAhead;
@@ -180,7 +185,7 @@ class Term {
180
185
  verifiedGivenType = verified; ///
181
186
 
182
187
  if (verifiedGivenType) {
183
- localContext.debug(`...verified the '${termString}' term given the '${typeString}' type.`);
188
+ localContext.debug(`...verified the '${termString}' term given the '${typeName}' type.`);
184
189
  }
185
190
 
186
191
  return verifiedGivenType;
@@ -243,9 +248,9 @@ class Term {
243
248
  return term;
244
249
  }
245
250
 
246
- static fromTermNodeAndType(termNode, type, fileContext) {
251
+ static fromTermNodeAndType(termNode, type, localContext) {
247
252
  const node = termNode, ///
248
- string = fileContext.nodeAsString(node),
253
+ string = localContext.nodeAsString(node),
249
254
  term = new Term(string, node, type);
250
255
 
251
256
  return term;
package/src/theorem.js CHANGED
@@ -1,7 +1,93 @@
1
1
  "use strict";
2
2
 
3
+ import Label from "./label";
4
+ import Proof from "./proof";
5
+ import Consequent from "./consequent";
6
+ import Supposition from "./supposition";
7
+ import LocalContext from "./context/local";
8
+ import Substitutions from "./substitutions";
3
9
  import TopLevelAssertion from "./topLevelAssertion";
4
10
 
11
+ import { nodeQuery, nodesQuery } from "./utilities/query";
12
+ import { labelsStringFromLabels } from "./topLevelAssertion";
13
+
14
+ const proofNodeQuery = nodeQuery("/theorem/proof"),
15
+ labelNodesQuery = nodesQuery("/theorem/label"),
16
+ consequentNodeQuery = nodeQuery("/theorem/consequent"),
17
+ suppositionNodesQuery = nodesQuery("/theorem/supposition");
18
+
5
19
  export default class Theorem extends TopLevelAssertion {
6
- static fromLabelsSuppositionsConsequentSubstitutionsAndFileContext(labels, suppositions, consequent, substitutions, fileContext) { return TopLevelAssertion.fromLabelsSuppositionsConsequentSubstitutionsAndFileContext(Theorem, labels, suppositions, consequent, substitutions, fileContext); }
20
+ verify() {
21
+ let verified = false;
22
+
23
+ const labelsString = labelsStringFromLabels(this.labels);
24
+
25
+ this.fileContext.trace(`Verifying the '${labelsString}' theorem...`);
26
+
27
+ const labelsVerifiedAtTopLevel = this.labels.every((label) => {
28
+ const labelVVerifiedAtTopLevel = label.verifyAtTopLevel(this.fileContext);
29
+
30
+ if (labelVVerifiedAtTopLevel) {
31
+ return true;
32
+ }
33
+ });
34
+
35
+ if (labelsVerifiedAtTopLevel) {
36
+ const localContext = LocalContext.fromFileContext(this.fileContext),
37
+ suppositionsVerified = this.suppositions.every((supposition) => {
38
+ const suppositionVerified = supposition.verify(localContext);
39
+
40
+ if (suppositionVerified) {
41
+ return true;
42
+ }
43
+ });
44
+
45
+ if (suppositionsVerified) {
46
+ const consequentVerified = this.consequent.verify(localContext);
47
+
48
+ if (consequentVerified) {
49
+ const substitutions = Substitutions.fromNothing(),
50
+ proofVerified = this.proof.verify(substitutions, this.consequent, localContext);
51
+
52
+ if (proofVerified) {
53
+ const theorem = this; ///
54
+
55
+ this.fileContext.addTheorem(theorem);
56
+
57
+ verified = true;
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ if (verified) {
64
+ this.fileContext.debug(`...verified the '${labelsString}' theorem.`);
65
+ }
66
+
67
+ return verified;
68
+ }
69
+
70
+ static fromJSON(json, fileContext) { return TopLevelAssertion.fromJSON(Theorem, json, fileContext); }
71
+
72
+ static fromTheoremNode(theoremNode, fileContext) {
73
+ const proofNode = proofNodeQuery(theoremNode),
74
+ labelNodes = labelNodesQuery(theoremNode),
75
+ consequentNode = consequentNodeQuery(theoremNode),
76
+ suppositionNodes = suppositionNodesQuery(theoremNode),
77
+ labels = labelNodes.map((labelNode) => {
78
+ const label = Label.fromLabelNode(labelNode, fileContext);
79
+
80
+ return label;
81
+ }),
82
+ suppositions = suppositionNodes.map((suppositionNode) => {
83
+ const supposition = Supposition.fromSuppositionNode(suppositionNode, fileContext);
84
+
85
+ return supposition;
86
+ }),
87
+ consequent = Consequent.fromConsequentNode(consequentNode, fileContext),
88
+ proof = Proof.fromProofNode(proofNode, fileContext),
89
+ theorem = new Theorem(fileContext, labels, suppositions, consequent, proof);
90
+
91
+ return theorem;
92
+ }
7
93
  }
@@ -2,9 +2,9 @@
2
2
 
3
3
  import shim from "../shim";
4
4
  import Unifier from "../unifier";
5
- import unifyVariableWithTerm from "../unify/variableWithTerm";
6
5
 
7
6
  import { nodeQuery } from "../utilities/query";
7
+ import { variableNameFromVariableNode } from "../utilities/name";
8
8
 
9
9
  const termNodeQuery = nodeQuery("/term!"),
10
10
  termVariableNodeQuery = nodeQuery("/term/variable!");
@@ -27,10 +27,23 @@ class IntrinsicLevelUnifier extends Unifier {
27
27
  nodeQueryA: termVariableNodeQuery,
28
28
  nodeQueryB: termNodeQuery,
29
29
  unify: (termVariableNodeA, termNodeB, substitutions, localContextA, localContextB) => {
30
+ let termUnified = false;
31
+
30
32
  const variableNodeA = termVariableNodeA, ///
31
- variableUnifiedWithTerm = unifyVariableWithTerm(variableNodeA, termNodeB, substitutions, localContextA, localContextB);
33
+ variableNameA = variableNameFromVariableNode(variableNodeA),
34
+ variableA = localContextA.findVariableByVariableName(variableNameA);
35
+
36
+ if (variableA !== null) {
37
+ const { Term } = shim,
38
+ termB = Term.fromTermNode(termNodeB, localContextB),
39
+ localContext = localContextB, ///
40
+ variable = variableA, ///
41
+ term = termB; ///
42
+
43
+ termUnified = variable.unifyTerm(term, substitutions, localContext);
44
+ }
32
45
 
33
- return variableUnifiedWithTerm;
46
+ return termUnified;
34
47
  }
35
48
  }
36
49
  ];
@@ -2,12 +2,12 @@
2
2
 
3
3
  import shim from "../shim";
4
4
  import Unifier from "../unifier";
5
- import unifyVariableWithTerm from "../unify/variableWithTerm";
6
5
  import unifyMetavariableWithFrame from "../unify/metavariableWithFrame";
7
6
  import unifyMetavariableWithStatement from "../unify/metavariableWithStatement";
8
7
  import unifyMetavariableWithStatementGivenSubstitution from "../unify/metavariableWithStatementGivenSubstitution";
9
8
 
10
9
  import { nodeQuery } from "../utilities/query";
10
+ import { variableNameFromVariableNode } from "../utilities/name";
11
11
 
12
12
  const termNodeQuery = nodeQuery("/term!"),
13
13
  frameNodeQuery = nodeQuery("/frame!"),
@@ -70,6 +70,8 @@ class MetaLevelUnifier extends Unifier {
70
70
  nodeQueryA: frameMetavariableNodeQuery,
71
71
  nodeQueryB: frameNodeQuery,
72
72
  unify: (frameMetavariableNodeA, frameNodeB, substitutions, localContextA, localContextB) => {
73
+ debugger
74
+
73
75
  const metavariableNodeA = frameMetavariableNodeA, ///
74
76
  metavariableUnifiedWithFrame = unifyMetavariableWithFrame(metavariableNodeA, frameNodeB, substitutions, localContextA, localContextB);
75
77
 
@@ -80,10 +82,23 @@ class MetaLevelUnifier extends Unifier {
80
82
  nodeQueryA: termVariableNodeQuery,
81
83
  nodeQueryB: termNodeQuery,
82
84
  unify: (termVariableNodeA, termNodeB, substitutions, localContextA, localContextB) => {
85
+ let termUnified = false;
86
+
83
87
  const variableNodeA = termVariableNodeA, ///
84
- variableUnifiedWithTerm = unifyVariableWithTerm(variableNodeA, termNodeB, substitutions, localContextA, localContextB);
88
+ variableNameA = variableNameFromVariableNode(variableNodeA),
89
+ variableA = localContextA.findVariableByVariableName(variableNameA);
90
+
91
+ if (variableA !== null) {
92
+ const { Term } = shim,
93
+ termB = Term.fromTermNode(termNodeB, localContextB),
94
+ localContext = localContextB, ///
95
+ variable = variableA, ///
96
+ term = termB; ///
97
+
98
+ termUnified = variable.unifyTerm(term, substitutions, localContext);
99
+ }
85
100
 
86
- return variableUnifiedWithTerm;
101
+ return termUnified;
87
102
  }
88
103
  }
89
104
  ];
@@ -55,7 +55,7 @@ class StatementWithCombinatorUnifier extends Unifier {
55
55
  metaTypeNode = metaTypeNodeB, ///
56
56
  frameNode = frameNodeA, ///
57
57
  metaType = MetaType.fromMetaTypeNode(metaTypeNode, localContext),
58
- frame = Frame.fromTermNode(frameNode, localContext),
58
+ frame = Frame.fromFrameNode(frameNode, localContext),
59
59
  frameVerifiedGivenType = frame.verifyGivenMetaType(metaType, localContext);
60
60
 
61
61
  unified = frameVerifiedGivenType;
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { arrayUtilities } from "necessary";
4
4
 
5
- export const { first, last, extract, tail, push, find, clear, match, prune, filter, compress, separate } = arrayUtilities;
5
+ export const { first, last, front, tail, push, find, match, clear, prune, extract, filter, compress, separate } = arrayUtilities;
6
6
 
7
7
  export function reverse(array) {
8
8
  array = [ ///
@@ -3,24 +3,9 @@
3
3
  import { nodeQuery } from "../utilities/query";
4
4
  import { metavariableNameFromMetavariableNode} from "../utilities/name";
5
5
 
6
- const termVariableNodeQuery = nodeQuery("/term/variable"),
7
- frameMetavariableNodeQuery = nodeQuery("/frame/metavariable"),
6
+ const frameMetavariableNodeQuery = nodeQuery("/frame/metavariable"),
8
7
  statementMetavariableNodeQuery = nodeQuery("/statement/metavariable");
9
8
 
10
- export function variableFromTermNode(termNode, localContext) {
11
- let variable = null;
12
-
13
- const termVariableNode = termVariableNodeQuery(termNode);
14
-
15
- if (termVariableNode !== null) {
16
- const variableNode = termVariableNode; ///
17
-
18
- variable = localContext.findVariableByVariableNode(variableNode);
19
- }
20
-
21
- return variable;
22
- }
23
-
24
9
  export function metavariableFromFrameNode(frameNode, localContext) {
25
10
  let metavariable = null;
26
11
 
package/src/variable.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import shim from "./shim";
4
4
  import LocalContext from "./context/local";
5
+ import TermForVariableSubstitution from "./substitution/termForVariable";
5
6
 
6
7
  import { nodeQuery } from "./utilities/query";
7
8
  import { objectType } from "./type";
@@ -9,7 +10,8 @@ import { variableNameFromVariableNode} from "./utilities/name";
9
10
  import { variableNodeFromVariableString } from "./utilities/node";
10
11
 
11
12
  const typeNodeQuery = nodeQuery("/variableDeclaration/type"),
12
- variableNodeQuery = nodeQuery("/variableDeclaration/variable");
13
+ variableNodeQuery = nodeQuery("/variableDeclaration/variable"),
14
+ termVariableNodeQuery = nodeQuery("/term/variable");
13
15
 
14
16
  export default class Variable {
15
17
  constructor(string, node, name, type) {
@@ -35,6 +37,10 @@ export default class Variable {
35
37
  return this.type;
36
38
  }
37
39
 
40
+ setType(type) {
41
+ this.type = type;
42
+ }
43
+
38
44
  matchNode(node) {
39
45
  const nodeMatches = this.node.match(node);
40
46
 
@@ -78,22 +84,26 @@ export default class Variable {
78
84
  verifyType(fileContext) {
79
85
  let typeVerified;
80
86
 
81
- const typeName = this.type.getName();
87
+ if (this.type === objectType) {
88
+ typeVerified = true;
89
+ } else {
90
+ const typeName = this.type.getName();
82
91
 
83
- fileContext.trace(`Verifying the '${typeName}' type...`);
92
+ fileContext.trace(`Verifying the '${typeName}' type...`);
84
93
 
85
- const type = fileContext.findTypeByTypeName(typeName);
94
+ const type = fileContext.findTypeByTypeName(typeName);
86
95
 
87
- if (type === null) {
88
- fileContext.debug(`The '${typeName}' type is missing.`);
89
- } else {
90
- this.type = type; ///
96
+ if (type === null) {
97
+ fileContext.debug(`The '${typeName}' type is missing.`);
98
+ } else {
99
+ this.type = type; ///
91
100
 
92
- typeVerified = true;
93
- }
101
+ typeVerified = true;
102
+ }
94
103
 
95
- if (typeVerified) {
96
- fileContext.debug(`...verified the '${typeName}' type.`);
104
+ if (typeVerified) {
105
+ fileContext.debug(`...verified the '${typeName}' type.`);
106
+ }
97
107
  }
98
108
 
99
109
  return typeVerified;
@@ -125,6 +135,47 @@ export default class Variable {
125
135
  return verifiedAtTopLevel;
126
136
  }
127
137
 
138
+ unifyTerm(term, substitutions, localContext) {
139
+ let termUnified = false;
140
+
141
+ const termString = term.getString(),
142
+ variableString = this.string; ///
143
+
144
+ localContext.trace(`Unifying the '${termString}' term with the '${variableString}' variable...`);
145
+
146
+ const termNode = term.getNode(),
147
+ variableNode = this.node, ///
148
+ substitution = substitutions.findSubstitutionByVariableNode(variableNode);
149
+
150
+ if (substitution !== null) {
151
+ const termNodeMatches = substitution.matchTermNode(termNode);
152
+
153
+ if (termNodeMatches) {
154
+ termUnified = true;
155
+ }
156
+ } else {
157
+ const variable = this, ///
158
+ termVariable = termVariableFromTermNode(termNode, localContext);
159
+
160
+ if (termVariable === variable) {
161
+ termUnified = true;
162
+ } else {
163
+ const termForVariableSubstitution = TermForVariableSubstitution.fromTernAndVariable(term, variable, localContext),
164
+ substitution = termForVariableSubstitution; ///
165
+
166
+ substitutions.addSubstitution(substitution, localContext);
167
+
168
+ termUnified = true;
169
+ }
170
+ }
171
+
172
+ if (termUnified) {
173
+ localContext.trace(`...unified the '${termString}' term with the '${variableString}' variable.`);
174
+ }
175
+
176
+ return termUnified;
177
+ }
178
+
128
179
  toJSON() {
129
180
  const typeJSON = this.type.toJSON(),
130
181
  string = this.string,
@@ -153,12 +204,17 @@ export default class Variable {
153
204
  }
154
205
 
155
206
  static fromVariableNode(variableNode, localContext) {
156
- const node = variableNode, ///
157
- variableName = variableNameFromVariableNode(variableNode),
158
- string = localContext.nodeAsString(node),
159
- name = variableName, ///
160
- type = null,
161
- variable = new Variable(string, node, name, type);
207
+ let variable = null;
208
+
209
+ if (variableNode !== null) {
210
+ const node = variableNode, ///
211
+ variableName = variableNameFromVariableNode(variableNode),
212
+ string = localContext.nodeAsString(node),
213
+ name = variableName, ///
214
+ type = null;
215
+
216
+ variable = new Variable(string, node, name, type);
217
+ }
162
218
 
163
219
  return variable;
164
220
  }
@@ -200,3 +256,17 @@ function typeFromJSON(json, fileContext) {
200
256
 
201
257
  return type;
202
258
  }
259
+
260
+ function termVariableFromTermNode(termNode, localContext) {
261
+ let termVariable = null;
262
+
263
+ const termVariableNode = termVariableNodeQuery(termNode);
264
+
265
+ if (termVariableNode !== null) {
266
+ const termVariableName = variableNameFromVariableNode(termVariableNode);
267
+
268
+ termVariable = localContext.findVariableByVariableName(termVariableName);
269
+ }
270
+
271
+ return termVariable;
272
+ }
@@ -4,6 +4,7 @@ import Rule from "../rule";
4
4
  import Error from "../error";
5
5
  import Axiom from "../axiom";
6
6
  import Lemma from "../lemma";
7
+ import Theorem from "../theorem";
7
8
  import TypeDeclaration from "../declaration/type";
8
9
  import VariableDeclaration from "../declaration/variable";
9
10
  import CombinatorDeclaration from "../declaration/combinator";
@@ -11,7 +12,6 @@ import ConstructorDeclaration from "../declaration/constructor";
11
12
  import MetavariableDeclaration from "../declaration/metavariable";
12
13
 
13
14
  import Verifier from "../verifier";
14
- import verifyTheorem from "../verify/theorem";
15
15
  import verifyMetaLemma from "../verify/metaLemma";
16
16
  import verifyConjecture from "../verify/conjecture";
17
17
  import verifyMetatheorem from "../verify/metatheorem";
@@ -84,7 +84,8 @@ class TopLevelVerifier extends Verifier {
84
84
  {
85
85
  nodeQuery: theoremNodeQuery,
86
86
  verify: (theoremNode, fileContext) => {
87
- const theoremVerified = verifyTheorem(theoremNode, fileContext);
87
+ const theorem = Theorem.fromTheoremNode(theoremNode, fileContext),
88
+ theoremVerified = theorem.verify();
88
89
 
89
90
  return theoremVerified;
90
91
  }