occam-verify-cli 1.0.448 → 1.0.472
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/lib/constants.js +13 -5
- package/lib/context/ephemeral.js +270 -0
- package/lib/context/file.js +136 -128
- package/lib/context/liminal.js +120 -0
- package/lib/context/literal.js +92 -0
- package/lib/context/nominal.js +15 -1
- package/lib/context/release.js +68 -9
- package/lib/context/scoped.js +322 -0
- package/lib/context/synthetic.js +133 -0
- package/lib/element/assertion/contained.js +66 -66
- package/lib/element/assertion/defined.js +32 -32
- package/lib/element/assertion/property.js +39 -39
- package/lib/element/assertion/satisfies.js +22 -22
- package/lib/element/assumption.js +71 -87
- package/lib/element/combinator/bracketed.js +1 -10
- package/lib/element/conclusion.js +19 -15
- package/lib/element/constructor/bracketed.js +1 -10
- package/lib/element/constructor.js +2 -2
- package/lib/element/declaration/combinator.js +1 -2
- package/lib/element/declaration/metavariable.js +3 -3
- package/lib/element/declaration/variable.js +3 -3
- package/lib/element/deduction.js +26 -20
- package/lib/element/derivation.js +3 -3
- package/lib/element/equality.js +5 -5
- package/lib/element/equivalence.js +112 -107
- package/lib/element/equivalences.js +24 -10
- package/lib/element/error.js +3 -3
- package/lib/element/frame.js +73 -62
- package/lib/element/hypothesis.js +2 -2
- package/lib/element/judgement.js +40 -60
- package/lib/element/metaType.js +4 -4
- package/lib/element/metavariable.js +49 -38
- package/lib/element/parameter.js +13 -5
- package/lib/element/procedureCall.js +16 -16
- package/lib/element/proof.js +14 -13
- package/lib/element/proofAssertion/premise.js +319 -0
- package/lib/element/proofAssertion/step.js +309 -0
- package/lib/element/proofAssertion/supposition.js +333 -0
- package/lib/element/proofAssertion.js +20 -10
- package/lib/element/propertyRelation.js +2 -2
- package/lib/element/reference.js +72 -30
- package/lib/element/rule.js +26 -28
- package/lib/element/section.js +5 -5
- package/lib/element/signature.js +9 -6
- package/lib/element/statement.js +44 -36
- package/lib/element/subproof.js +18 -17
- package/lib/element/substitution/frame.js +86 -49
- package/lib/element/substitution/reference.js +101 -19
- package/lib/element/substitution/statement.js +128 -105
- package/lib/element/substitution/term.js +93 -57
- package/lib/element/substitution.js +20 -69
- package/lib/element/substitutions.js +49 -34
- package/lib/element/term.js +41 -30
- package/lib/element/topLevelAssertion/axiom.js +331 -0
- package/lib/element/{conjecture.js → topLevelAssertion/conjecture.js} +10 -10
- package/lib/element/{lemma.js → topLevelAssertion/lemma.js} +9 -9
- package/lib/element/{theorem.js → topLevelAssertion/theorem.js} +8 -8
- package/lib/element/topLevelAssertion.js +434 -0
- package/lib/element/{metaLemma.js → topLevelMetaAssertion/metaLemma.js} +8 -8
- package/lib/element/{metatheorem.js → topLevelMetaAssertion/metatheorem.js} +8 -8
- package/lib/element/topLevelMetaAssertion.js +293 -0
- package/lib/element/type.js +4 -4
- package/lib/element/variable.js +48 -40
- package/lib/index.js +3 -3
- package/lib/main.js +3 -3
- package/lib/metaTypes.js +18 -15
- package/lib/node/frame.js +2 -2
- package/lib/node/metavariable.js +4 -4
- package/lib/node/parameter.js +28 -7
- package/lib/node/proofAssertion/premise.js +116 -0
- package/lib/node/proofAssertion/step.js +152 -0
- package/lib/node/proofAssertion/supposition.js +116 -0
- package/lib/node/{premise.js → proofAssertion.js} +11 -18
- package/lib/node/statement.js +2 -2
- package/lib/node/substitution/frame.js +9 -31
- package/lib/node/substitution/reference.js +137 -0
- package/lib/node/substitution/statement.js +9 -31
- package/lib/node/substitution/term.js +9 -23
- package/lib/node/{axiom.js → topLevelAssertion/axiom.js} +7 -7
- package/lib/node/{conjecture.js → topLevelAssertion/conjecture.js} +7 -7
- package/lib/node/{lemma.js → topLevelAssertion/lemma.js} +7 -7
- package/lib/node/{theorem.js → topLevelAssertion/theorem.js} +7 -7
- package/lib/node/{axiomLemmaTheoremConjecture.js → topLevelAssertion.js} +9 -9
- package/lib/node/{metaLemma.js → topLevelMetaAssertion/metaLemma.js} +7 -7
- package/lib/node/{metatheorem.js → topLevelMetaAssertion/metatheorem.js} +7 -7
- package/lib/node/{metaLemmaMetaTheorem.js → topLevelMetaAssertion.js} +9 -9
- package/lib/nonTerminalNodeMap.js +15 -14
- package/lib/preamble.js +10 -10
- package/lib/process/instantiate.js +6 -21
- package/lib/process/unify.js +11 -10
- package/lib/tokenTypes.js +22 -0
- package/lib/types.js +3 -3
- package/lib/utilities/bnf.js +5 -5
- package/lib/utilities/context.js +63 -0
- package/lib/utilities/element.js +235 -408
- package/lib/utilities/instance.js +12 -34
- package/lib/utilities/json.js +3 -2
- package/lib/utilities/string.js +56 -21
- package/lib/utilities/unification.js +38 -32
- package/lib/utilities/validation.js +47 -50
- package/package.json +2 -2
- package/src/constants.js +12 -1
- package/src/context/ephemeral.js +257 -0
- package/src/context/file.js +108 -116
- package/src/context/liminal.js +67 -0
- package/src/context/literal.js +51 -0
- package/src/context/nominal.js +12 -0
- package/src/context/release.js +48 -8
- package/src/context/{local.js → scoped.js} +43 -125
- package/src/context/synthetic.js +60 -0
- package/src/element/assertion/contained.js +49 -47
- package/src/element/assertion/defined.js +29 -27
- package/src/element/assertion/property.js +35 -35
- package/src/element/assertion/satisfies.js +19 -18
- package/src/element/assumption.js +71 -93
- package/src/element/combinator/bracketed.js +0 -7
- package/src/element/conclusion.js +25 -24
- package/src/element/constructor/bracketed.js +0 -7
- package/src/element/constructor.js +1 -1
- package/src/element/declaration/combinator.js +0 -1
- package/src/element/declaration/metavariable.js +2 -2
- package/src/element/declaration/variable.js +5 -5
- package/src/element/deduction.js +33 -31
- package/src/element/derivation.js +2 -2
- package/src/element/equality.js +4 -4
- package/src/element/equivalence.js +115 -135
- package/src/element/equivalences.js +9 -7
- package/src/element/error.js +4 -2
- package/src/element/frame.js +80 -65
- package/src/element/hypothesis.js +1 -1
- package/src/element/judgement.js +42 -62
- package/src/element/metaType.js +3 -4
- package/src/element/metavariable.js +59 -56
- package/src/element/parameter.js +10 -5
- package/src/element/procedureCall.js +20 -18
- package/src/element/proof.js +14 -16
- package/src/element/{premise.js → proofAssertion/premise.js} +57 -53
- package/src/element/{step.js → proofAssertion/step.js} +59 -62
- package/src/element/{supposition.js → proofAssertion/supposition.js} +67 -56
- package/src/element/proofAssertion.js +24 -13
- package/src/element/propertyRelation.js +1 -1
- package/src/element/reference.js +87 -37
- package/src/element/rule.js +31 -37
- package/src/element/section.js +5 -5
- package/src/element/signature.js +8 -8
- package/src/element/statement.js +52 -48
- package/src/element/subproof.js +16 -18
- package/src/element/substitution/frame.js +104 -50
- package/src/element/substitution/reference.js +120 -20
- package/src/element/substitution/statement.js +169 -130
- package/src/element/substitution/term.js +104 -63
- package/src/element/substitution.js +16 -58
- package/src/element/substitutions.js +43 -41
- package/src/element/term.js +47 -41
- package/src/element/{axiom.js → topLevelAssertion/axiom.js} +22 -20
- package/src/element/{conjecture.js → topLevelAssertion/conjecture.js} +5 -6
- package/src/element/{lemma.js → topLevelAssertion/lemma.js} +5 -6
- package/src/element/{theorem.js → topLevelAssertion/theorem.js} +5 -5
- package/src/element/{axiomLemmaTheoremConjecture.js → topLevelAssertion.js} +37 -33
- package/src/element/{metaLemma.js → topLevelMetaAssertion/metaLemma.js} +5 -6
- package/src/element/{metatheorem.js → topLevelMetaAssertion/metatheorem.js} +5 -6
- package/src/element/{metaLemmaMetatheorem.js → topLevelMetaAssertion.js} +19 -17
- package/src/element/type.js +2 -4
- package/src/element/variable.js +47 -48
- package/src/index.js +2 -1
- package/src/main.js +2 -1
- package/src/metaTypes.js +25 -9
- package/src/node/frame.js +1 -1
- package/src/node/metavariable.js +3 -3
- package/src/node/parameter.js +32 -5
- package/src/node/proofAssertion/premise.js +16 -0
- package/src/node/{step.js → proofAssertion/step.js} +4 -18
- package/src/node/proofAssertion/supposition.js +16 -0
- package/src/node/proofAssertion.js +23 -0
- package/src/node/statement.js +1 -1
- package/src/node/substitution/frame.js +6 -32
- package/src/node/substitution/reference.js +38 -0
- package/src/node/substitution/statement.js +6 -32
- package/src/node/substitution/term.js +6 -22
- package/src/node/topLevelAssertion/axiom.js +13 -0
- package/src/node/topLevelAssertion/conjecture.js +13 -0
- package/src/node/topLevelAssertion/lemma.js +13 -0
- package/src/node/topLevelAssertion/theorem.js +13 -0
- package/src/node/{axiomLemmaTheoremConjecture.js → topLevelAssertion.js} +1 -1
- package/src/node/topLevelMetaAssertion/metaLemma.js +13 -0
- package/src/node/topLevelMetaAssertion/metatheorem.js +13 -0
- package/src/node/{metaLemmaMetaTheorem.js → topLevelMetaAssertion.js} +1 -1
- package/src/nonTerminalNodeMap.js +15 -12
- package/src/preamble.js +9 -9
- package/src/process/instantiate.js +27 -36
- package/src/process/unify.js +10 -9
- package/src/tokenTypes.js +4 -0
- package/src/types.js +4 -2
- package/src/utilities/bnf.js +3 -2
- package/src/utilities/context.js +46 -0
- package/src/utilities/element.js +302 -509
- package/src/utilities/instance.js +19 -42
- package/src/utilities/json.js +3 -1
- package/src/utilities/string.js +69 -28
- package/src/utilities/unification.js +41 -38
- package/src/utilities/validation.js +66 -75
- package/lib/context/local.js +0 -605
- package/lib/context/temporary.js +0 -752
- package/lib/element/axiom.js +0 -329
- package/lib/element/axiomLemmaTheoremConjecture.js +0 -427
- package/lib/element/metaLemmaMetatheorem.js +0 -289
- package/lib/element/premise.js +0 -307
- package/lib/element/step.js +0 -311
- package/lib/element/supposition.js +0 -320
- package/lib/log.js +0 -150
- package/lib/node/step.js +0 -166
- package/lib/node/supposition.js +0 -130
- package/src/context/temporary.js +0 -476
- package/src/log.js +0 -118
- package/src/node/axiom.js +0 -13
- package/src/node/conjecture.js +0 -13
- package/src/node/lemma.js +0 -13
- package/src/node/metaLemma.js +0 -13
- package/src/node/metatheorem.js +0 -13
- package/src/node/premise.js +0 -30
- package/src/node/supposition.js +0 -30
- package/src/node/theorem.js +0 -13
|
@@ -4,100 +4,190 @@ import elements from "../../elements";
|
|
|
4
4
|
import Substitution from "../substitution";
|
|
5
5
|
|
|
6
6
|
import { define } from "../../elements";
|
|
7
|
+
import { literally } from "../../utilities/context";
|
|
7
8
|
import { unifySubstitution } from "../../process/unify";
|
|
8
9
|
import { stripBracketsFromStatement } from "../../utilities/brackets";
|
|
9
10
|
import { instantiateStatementSubstitution } from "../../process/instantiate";
|
|
10
11
|
import { statementSubstitutionFromStatementSubstitutionNode } from "../../utilities/element";
|
|
11
|
-
import {
|
|
12
|
+
import { statementToStatementJSON, metavariableToMetavariableJSON } from "../../utilities/json";
|
|
13
|
+
import { statementSubstitutionStringFromStatementAndMetavariable, statementSubstitutionStringFromStatementMetavariableAndSubstitution } from "../../utilities/string";
|
|
12
14
|
|
|
13
15
|
export default define(class StatementSubstitution extends Substitution {
|
|
14
|
-
constructor(context, string, node, resolved,
|
|
16
|
+
constructor(context, string, node, resolved, substitution, targetStatement, replacementStatement) {
|
|
15
17
|
super(context, string, node);
|
|
16
18
|
|
|
17
19
|
this.resolved = resolved;
|
|
18
|
-
this.statement = statement;
|
|
19
|
-
this.metavariable = metavariable;
|
|
20
20
|
this.substitution = substitution;
|
|
21
|
+
this.targetStatement = targetStatement;
|
|
22
|
+
this.replacementStatement = replacementStatement;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
isResolved() {
|
|
24
26
|
return this.resolved;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
return this.
|
|
29
|
+
getSubstitution() {
|
|
30
|
+
return this.substitution;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
return this.
|
|
33
|
+
getTargetStatement() {
|
|
34
|
+
return this.targetStatement;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
return this.
|
|
37
|
+
getReplacementStatement() {
|
|
38
|
+
return this.replacementStatement;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getTargetNode() {
|
|
42
|
+
const targetStatementNode = this.targetStatement.getNode(),
|
|
43
|
+
targetNode = targetStatementNode; ///
|
|
44
|
+
|
|
45
|
+
return targetNode;
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
getReplacementNode() {
|
|
40
|
-
const
|
|
41
|
-
replacementNode =
|
|
49
|
+
const replacementStatementNode = this.replacementStatement.getNode(),
|
|
50
|
+
replacementNode = replacementStatementNode; ///
|
|
42
51
|
|
|
43
52
|
return replacementNode;
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
|
|
47
|
-
this.
|
|
55
|
+
isSimple() {
|
|
56
|
+
const simple = (this.substitution === null);
|
|
57
|
+
|
|
58
|
+
return simple;
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
compareStatement(statement, context) {
|
|
62
|
+
statement = stripBracketsFromStatement(statement, context); ///
|
|
63
|
+
|
|
64
|
+
const replacementStatementEqualToStatement = this.replacementStatement.isEqualTo(statement),
|
|
65
|
+
comparesToStatement = replacementStatementEqualToStatement; ///
|
|
66
|
+
|
|
67
|
+
return comparesToStatement;
|
|
52
68
|
}
|
|
53
69
|
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
compareParameter(parameter) {
|
|
71
|
+
const targetStatementComparesToParameter = this.targetStatement.compareParameter(parameter),
|
|
72
|
+
comparesToParameter = targetStatementComparesToParameter; ///
|
|
73
|
+
|
|
74
|
+
return comparesToParameter;
|
|
56
75
|
}
|
|
57
76
|
|
|
58
|
-
|
|
77
|
+
compareSubstitution(substitution) {
|
|
78
|
+
let comparesToSubstitution = false;
|
|
59
79
|
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
if (false) {
|
|
81
|
+
///
|
|
82
|
+
} else if ((this.substitution === null) && (substitution === null)){
|
|
83
|
+
comparesToSubstitution = true;
|
|
84
|
+
} else if ((this.substitution !== null) && (substitution !== null)){
|
|
85
|
+
const substitutionEqualToSubstituion = this.substitution.isEqualTo(substitution);
|
|
62
86
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} else {
|
|
66
|
-
if (substitution === null) {
|
|
67
|
-
substitutionEqualToSubstitution = false;
|
|
68
|
-
} else {
|
|
69
|
-
substitutionEqualToSubstitution = this.substitution.isEqualTo(substitution);
|
|
87
|
+
if (substitutionEqualToSubstituion) {
|
|
88
|
+
comparesToSubstitution = true;
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
91
|
|
|
73
|
-
return
|
|
92
|
+
return comparesToSubstitution;
|
|
74
93
|
}
|
|
75
94
|
|
|
76
|
-
|
|
77
|
-
|
|
95
|
+
validate(context) {
|
|
96
|
+
let validates = false;
|
|
97
|
+
|
|
98
|
+
const statementSubstitutionString = this.getString(); ///
|
|
99
|
+
|
|
100
|
+
context.trace(`Validating the '${statementSubstitutionString}' statement substitution...`);
|
|
101
|
+
|
|
102
|
+
const targetStatementValidates = this.validateTargetStatement(context);
|
|
78
103
|
|
|
79
|
-
|
|
104
|
+
if (targetStatementValidates) {
|
|
105
|
+
const replacementStatementValidates = this.validateReplacementStatement(context);
|
|
80
106
|
|
|
81
|
-
|
|
107
|
+
if (replacementStatementValidates) {
|
|
108
|
+
validates = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (validates) {
|
|
113
|
+
const substititoin = this; ///
|
|
114
|
+
|
|
115
|
+
context.addSubstitution(substititoin);
|
|
116
|
+
|
|
117
|
+
context.debug(`...validated the '${statementSubstitutionString}' statement substitution.`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return validates;
|
|
82
121
|
}
|
|
83
122
|
|
|
84
|
-
|
|
85
|
-
|
|
123
|
+
validateTargetStatement(context) {
|
|
124
|
+
let targetStatementValidates = false;
|
|
86
125
|
|
|
87
|
-
|
|
126
|
+
const targetStatementString = this.targetStatement.getString(),
|
|
127
|
+
statementSubstitutionString = this.getString(); ///
|
|
128
|
+
|
|
129
|
+
context.trace(`Validating the '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement...`);
|
|
130
|
+
|
|
131
|
+
const targetStatementSingular = this.targetStatement.isSingular();
|
|
132
|
+
|
|
133
|
+
if (targetStatementSingular) {
|
|
134
|
+
const stated = true,
|
|
135
|
+
assignments = null;
|
|
136
|
+
|
|
137
|
+
targetStatementValidates = this.targetStatement.validate(assignments, stated, context);
|
|
138
|
+
} else {
|
|
139
|
+
context.debug(`The '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement is not singular.`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (targetStatementValidates) {
|
|
143
|
+
context.debug(`...validated the '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement...`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return targetStatementValidates;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
validateReplacementStatement(context) {
|
|
150
|
+
let replacementStatementValidates;
|
|
151
|
+
|
|
152
|
+
const replacementStatementString = this.replacementStatement.getString(),
|
|
153
|
+
statementSubstitutionString = this.getString(); ///
|
|
154
|
+
|
|
155
|
+
context.trace(`Validating the '${statementSubstitutionString}' statement subtitution's '${replacementStatementString}' replacement statement...`);
|
|
156
|
+
|
|
157
|
+
const stated = true,
|
|
158
|
+
assignments = null;
|
|
159
|
+
|
|
160
|
+
replacementStatementValidates = this.replacementStatement.validate(assignments, stated, context);
|
|
161
|
+
|
|
162
|
+
if (replacementStatementValidates) {
|
|
163
|
+
context.debug(`...validated the '${statementSubstitutionString}' statement subtitution's '${replacementStatementString}' replacement statement...`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return replacementStatementValidates;
|
|
88
167
|
}
|
|
89
168
|
|
|
90
169
|
unifyStatement(statement, context) {
|
|
91
|
-
let
|
|
170
|
+
let statementUnifies = false;
|
|
92
171
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
172
|
+
const statementString = statement.getString(),
|
|
173
|
+
statementSubstitutionString = this.getString();
|
|
174
|
+
|
|
175
|
+
context.trace(`Unifying the '${statementString}' statement with the '${statementSubstitutionString}' statement substiution's statement...`);
|
|
176
|
+
|
|
177
|
+
const specificContext = context; ///
|
|
96
178
|
|
|
97
179
|
context = this.getContext();
|
|
98
180
|
|
|
99
|
-
const generalContext = context
|
|
100
|
-
|
|
181
|
+
const generalContext = context; ///
|
|
182
|
+
|
|
183
|
+
context = specificContext; ///
|
|
184
|
+
|
|
185
|
+
const { Substitutions } = elements,
|
|
186
|
+
substitutions = Substitutions.fromNothing(context);
|
|
187
|
+
|
|
188
|
+
statementUnifies = this.replacementStatement.unifyStatement(statement, substitutions, generalContext, specificContext);
|
|
189
|
+
|
|
190
|
+
let substitution = null;
|
|
101
191
|
|
|
102
192
|
if (statementUnifies) {
|
|
103
193
|
const substitutionsNonTrivialLength = substitutions.getNonTrivialLength();
|
|
@@ -106,9 +196,15 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
106
196
|
const firstSubstitution = substitutions.getFirstSubstitution();
|
|
107
197
|
|
|
108
198
|
substitution = firstSubstitution; ///
|
|
199
|
+
} else {
|
|
200
|
+
statementUnifies = false;
|
|
109
201
|
}
|
|
110
202
|
}
|
|
111
203
|
|
|
204
|
+
if (statementUnifies) {
|
|
205
|
+
context.trace(`...unified the '${statementString}' statement with the '${statementSubstitutionString}' statement substiution's statement.`);
|
|
206
|
+
}
|
|
207
|
+
|
|
112
208
|
return substitution;
|
|
113
209
|
}
|
|
114
210
|
|
|
@@ -139,41 +235,28 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
139
235
|
}
|
|
140
236
|
|
|
141
237
|
resolve(substitutions, context) {
|
|
142
|
-
|
|
238
|
+
context = this.getContext();
|
|
239
|
+
|
|
240
|
+
const substitutionString = this.getString(); ///
|
|
143
241
|
|
|
144
242
|
context.trace(`Resolving the ${substitutionString} substitution...`);
|
|
145
243
|
|
|
146
|
-
substitutions.snapshot();
|
|
244
|
+
substitutions.snapshot(context);
|
|
147
245
|
|
|
148
246
|
const metavariable = this.getMetavariable(),
|
|
149
|
-
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable)
|
|
247
|
+
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable),
|
|
248
|
+
substitution = simpleSubstitution.unifyStatement(this.replacementStatement, context);
|
|
150
249
|
|
|
151
|
-
if (
|
|
152
|
-
|
|
250
|
+
if (substitution !== null) {
|
|
251
|
+
const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
|
|
153
252
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const substitution = simpleSubstitution.unifyStatement(this.statement, context);
|
|
157
|
-
|
|
158
|
-
if (substitution !== null) {
|
|
159
|
-
context = simpleSubstitution.getContext();
|
|
160
|
-
|
|
161
|
-
const simpleContext = context; ///
|
|
162
|
-
|
|
163
|
-
context = substitution.getContext();
|
|
164
|
-
|
|
165
|
-
context.merge(simpleContext);
|
|
166
|
-
|
|
167
|
-
const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
|
|
168
|
-
|
|
169
|
-
if (substitutionUnifies) {
|
|
170
|
-
this.resolved = true;
|
|
171
|
-
}
|
|
253
|
+
if (substitutionUnifies) {
|
|
254
|
+
this.resolved = true;
|
|
172
255
|
}
|
|
173
256
|
}
|
|
174
257
|
|
|
175
258
|
this.resolved ?
|
|
176
|
-
substitutions.continue() :
|
|
259
|
+
substitutions.continue(context) :
|
|
177
260
|
substitutions.rollback(context);
|
|
178
261
|
|
|
179
262
|
if (this.resolved) {
|
|
@@ -182,11 +265,11 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
182
265
|
}
|
|
183
266
|
|
|
184
267
|
toJSON() {
|
|
185
|
-
const metavariableJSON = metavariableToMetavariableJSON(this.
|
|
186
|
-
statementJSON = statementToStatementJSON(this.
|
|
268
|
+
const metavariableJSON = metavariableToMetavariableJSON(this.targetStatement),
|
|
269
|
+
statementJSON = statementToStatementJSON(this.replacementStatement),
|
|
187
270
|
metavariable = metavariableJSON, ///
|
|
188
271
|
statement = statementJSON, ///
|
|
189
|
-
string = this.
|
|
272
|
+
string = this.getString(), ///
|
|
190
273
|
json = {
|
|
191
274
|
string,
|
|
192
275
|
statement,
|
|
@@ -199,80 +282,36 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
199
282
|
static name = "StatementSubstitution";
|
|
200
283
|
|
|
201
284
|
static fromJSON(json, context) {
|
|
202
|
-
|
|
203
|
-
statementSubstitutionNode = instantiateStatementSubstitution(string, context),
|
|
204
|
-
node = statementSubstitutionNode,
|
|
205
|
-
resolved = true,
|
|
206
|
-
statement = statementFromJSON(json, context),
|
|
207
|
-
metavariable = metavariableFromJSON(json, context),
|
|
208
|
-
substitution = null, ///
|
|
209
|
-
statementSubstitution = new StatementSubstitution(context, string, node, resolved, statement, metavariable, substitution);
|
|
210
|
-
|
|
211
|
-
return statementSubstitution;
|
|
285
|
+
///
|
|
212
286
|
}
|
|
213
287
|
|
|
214
288
|
static fromStatementAndMetavariable(statement, metavariable, context) {
|
|
215
289
|
statement = stripBracketsFromStatement(statement, context); ///
|
|
216
290
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
const statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context);
|
|
291
|
+
return literally((context) => {
|
|
292
|
+
const statementSubstitutionString = statementSubstitutionStringFromStatementAndMetavariable(statement, metavariable, context),
|
|
293
|
+
string = statementSubstitutionString, ///
|
|
294
|
+
statementSubstitutionNode = instantiateStatementSubstitution(string, context),
|
|
295
|
+
statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context);
|
|
225
296
|
|
|
226
|
-
|
|
297
|
+
statementSubstitution.validate(context);
|
|
227
298
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return statementSubstitution;
|
|
299
|
+
return statementSubstitution;
|
|
300
|
+
}, context);
|
|
231
301
|
}
|
|
232
302
|
|
|
233
303
|
static fromStatementMetavariableAndSubstitution(statement, metavariable, substitution, context) {
|
|
234
304
|
statement = stripBracketsFromStatement(statement, context); ///
|
|
235
305
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
};
|
|
306
|
+
return literally((context) => {
|
|
307
|
+
const statementSubstitutionString = statementSubstitutionStringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution),
|
|
308
|
+
string = statementSubstitutionString, ///
|
|
309
|
+
statementSubstitutionNode = instantiateStatementSubstitution(string, context),
|
|
310
|
+
statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, substitution, context);
|
|
242
311
|
|
|
243
|
-
|
|
312
|
+
statementSubstitution.validate(context);
|
|
244
313
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
statementSubstitution.setMetavariable(metavariable);
|
|
248
|
-
|
|
249
|
-
statementSubstitution.setSubstitution(substitution);
|
|
250
|
-
|
|
251
|
-
return statementSubstitution;
|
|
314
|
+
return statementSubstitution;
|
|
315
|
+
}, context);
|
|
252
316
|
}
|
|
253
317
|
});
|
|
254
|
-
|
|
255
|
-
function stringFromStatementAndMetavariable(statement, metavariable) {
|
|
256
|
-
const statementString = statement.getString(),
|
|
257
|
-
metavariableString = metavariable.getString(),
|
|
258
|
-
string = `[${statementString} for ${metavariableString}]`;
|
|
259
|
-
|
|
260
|
-
return string;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution) {
|
|
264
|
-
let string;
|
|
265
|
-
|
|
266
|
-
const statementString = statement.getString(),
|
|
267
|
-
metavariableString = metavariable.getString();
|
|
268
|
-
|
|
269
|
-
if (substitution === null) {
|
|
270
|
-
string = `[${statementString} for ${metavariableString}]`;
|
|
271
|
-
} else {
|
|
272
|
-
const substitutionString = substitution.getString();
|
|
273
|
-
|
|
274
|
-
string = `[${statementString} for ${metavariableString}${substitutionString}]`;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return string;
|
|
278
|
-
}
|
|
@@ -3,97 +3,139 @@
|
|
|
3
3
|
import Substitution from "../substitution";
|
|
4
4
|
|
|
5
5
|
import { define } from "../../elements";
|
|
6
|
+
import { literally } from "../../utilities/context";
|
|
6
7
|
import { stripBracketsFromTerm } from "../../utilities/brackets";
|
|
7
8
|
import { instantiateTermSubstitution } from "../../process/instantiate";
|
|
9
|
+
import { termSubstitutionStringFromTermAndVariable } from "../../utilities/string";
|
|
8
10
|
import { termSubstitutionFromStatementNode, termSubstitutionFromTermSubstitutionNode } from "../../utilities/element";
|
|
9
11
|
|
|
10
12
|
export default define(class TermSubstitution extends Substitution {
|
|
11
|
-
constructor(context, string, node,
|
|
13
|
+
constructor(context, string, node, targetTerm, replacementTerm) {
|
|
12
14
|
super(context, string, node);
|
|
13
15
|
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
+
this.targetTerm = targetTerm;
|
|
17
|
+
this.replacementTerm = replacementTerm;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
return this.
|
|
20
|
+
getTargetTerm() {
|
|
21
|
+
return this.targetTerm;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
return this.
|
|
24
|
+
getReplacementTerm() {
|
|
25
|
+
return this.replacementTerm;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getTargetNode() {
|
|
29
|
+
const targetTermNode = this.targetTerm.getNode(),
|
|
30
|
+
tergetNode = targetTermNode; ///
|
|
31
|
+
|
|
32
|
+
return tergetNode;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
getReplacementNode() {
|
|
27
|
-
const
|
|
28
|
-
replacementNode =
|
|
36
|
+
const replacementTermNode = this.replacementTerm.getNode(),
|
|
37
|
+
replacementNode = replacementTermNode; ///
|
|
29
38
|
|
|
30
39
|
return replacementNode;
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
isTrivial() {
|
|
43
|
+
const targetTermEqualToReplacementTerm = this.targetTerm.isEqualTo(this.replacementTerm),
|
|
44
|
+
trivial = targetTermEqualToReplacementTerm; ///
|
|
45
|
+
|
|
46
|
+
return trivial;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
compareTerm(term, context) {
|
|
34
50
|
term = stripBracketsFromTerm(term, context); ///
|
|
35
51
|
|
|
36
|
-
const
|
|
52
|
+
const termEqualToReplacementTerm = this.replacementTerm.isEqualTo(term),
|
|
53
|
+
comparedToTerm = termEqualToReplacementTerm; ///
|
|
37
54
|
|
|
38
|
-
return
|
|
55
|
+
return comparedToTerm;
|
|
39
56
|
}
|
|
40
57
|
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
compareParameter(parameter) {
|
|
59
|
+
const targetTermComparesToParameter = this.targetTerm.compareParameter(parameter),
|
|
60
|
+
comparesToParameter = targetTermComparesToParameter; ///
|
|
61
|
+
|
|
62
|
+
return comparesToParameter;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
validate(context) {
|
|
66
|
+
let validates = false;
|
|
67
|
+
|
|
68
|
+
const termSubstitutionString = this.getString(); ///
|
|
69
|
+
|
|
70
|
+
context.trace(`Validating the '${termSubstitutionString}' term substitution...`);
|
|
71
|
+
|
|
72
|
+
const targetTermValidates = this.validateTargetTerm(context);
|
|
43
73
|
|
|
44
|
-
|
|
74
|
+
if (targetTermValidates) {
|
|
75
|
+
const replacementTermValidates = this.validateReplacementTerm(context);
|
|
45
76
|
|
|
46
|
-
|
|
47
|
-
|
|
77
|
+
if (replacementTermValidates) {
|
|
78
|
+
validates = true;
|
|
79
|
+
}
|
|
48
80
|
}
|
|
49
81
|
|
|
50
|
-
|
|
51
|
-
|
|
82
|
+
if (validates) {
|
|
83
|
+
const substititoin = this; ///
|
|
84
|
+
|
|
85
|
+
context.addSubstitution(substititoin);
|
|
52
86
|
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
context.debug(`...validated the '${termSubstitutionString}' term substitution.`);
|
|
88
|
+
}
|
|
55
89
|
|
|
56
|
-
|
|
90
|
+
return validates;
|
|
91
|
+
}
|
|
57
92
|
|
|
58
|
-
|
|
93
|
+
validateTargetTerm(context) {
|
|
94
|
+
let targetTermValidates = false;
|
|
59
95
|
|
|
60
|
-
const
|
|
96
|
+
const targetTermString = this.targetTerm.getString(),
|
|
97
|
+
termSubstitutionString = this.getString(); ///
|
|
61
98
|
|
|
62
|
-
|
|
63
|
-
if (this.variable !== null) {
|
|
64
|
-
const variableIdentifier = this.variable.getIdentifier(),
|
|
65
|
-
variablePresent = context.isVariablePresentByVariableIdentifier(variableIdentifier);
|
|
99
|
+
context.trace(`Validating the '${termSubstitutionString}' term subtitution's '${targetTermString}' target term...`);
|
|
66
100
|
|
|
67
|
-
|
|
68
|
-
const termNode = this.term.getNode(),
|
|
69
|
-
variableIdentifier = termNode.getVariableIdentifier(),
|
|
70
|
-
termVariableIdentifier = variableIdentifier, ///
|
|
71
|
-
termVariablePresent = context.isVariablePresentByVariableIdentifier(termVariableIdentifier);
|
|
101
|
+
const targetTermSingular = this.targetTerm.isSingular();
|
|
72
102
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
context.debug(`The '${termSubstitutionString}' term substitution's specific term's variable is not present.`);
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
context.debug(`The '${termSubstitutionString}' term substitution's general term is not singular.`);
|
|
83
|
-
}
|
|
103
|
+
if (targetTermSingular) {
|
|
104
|
+
targetTermValidates = this.targetTerm.validate(context, () => {
|
|
105
|
+
const verifiesAhead = true;
|
|
106
|
+
|
|
107
|
+
return verifiesAhead;
|
|
108
|
+
});
|
|
84
109
|
} else {
|
|
85
|
-
context.debug(`The '${termSubstitutionString}' term
|
|
110
|
+
context.debug(`The '${termSubstitutionString}' term subtitution's '${targetTermString}' target term is not singular.`);
|
|
86
111
|
}
|
|
87
112
|
|
|
88
|
-
if (
|
|
89
|
-
|
|
113
|
+
if (targetTermValidates) {
|
|
114
|
+
context.debug(`...validated the '${termSubstitutionString}' term subtitution's '${targetTermString}' target term...`);
|
|
115
|
+
}
|
|
90
116
|
|
|
91
|
-
|
|
117
|
+
return targetTermValidates;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
validateReplacementTerm(context) {
|
|
121
|
+
let replacementTermValidates;
|
|
92
122
|
|
|
93
|
-
|
|
123
|
+
const replacementTermString = this.replacementTerm.getString(),
|
|
124
|
+
termSubstitutionString = this.getString(); ///
|
|
125
|
+
|
|
126
|
+
context.trace(`Validating the '${termSubstitutionString}' term subtitution's '${replacementTermString}' replacement term...`);
|
|
127
|
+
|
|
128
|
+
replacementTermValidates = this.replacementTerm.validate(context, () => {
|
|
129
|
+
const validatesAhead = true;
|
|
130
|
+
|
|
131
|
+
return validatesAhead;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (replacementTermValidates) {
|
|
135
|
+
context.debug(`...validated the '${termSubstitutionString}' term subtitution's '${replacementTermString}' replacement term...`);
|
|
94
136
|
}
|
|
95
137
|
|
|
96
|
-
return
|
|
138
|
+
return replacementTermValidates;
|
|
97
139
|
}
|
|
98
140
|
|
|
99
141
|
static name = "TermSubstitution";
|
|
@@ -105,19 +147,18 @@ export default define(class TermSubstitution extends Substitution {
|
|
|
105
147
|
return termSubstitution;
|
|
106
148
|
}
|
|
107
149
|
|
|
108
|
-
static
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
150
|
+
static fromTermAndVariable(term, variable, context) {
|
|
151
|
+
term = stripBracketsFromTerm(term, context); ///
|
|
152
|
+
|
|
153
|
+
return literally((context) => {
|
|
154
|
+
const termSubstitutionString = termSubstitutionStringFromTermAndVariable(term, variable),
|
|
155
|
+
string = termSubstitutionString, ///
|
|
156
|
+
termSubstitutionNode = instantiateTermSubstitution(string, context),
|
|
157
|
+
termSubstitution = termSubstitutionFromTermSubstitutionNode(termSubstitutionNode, context);
|
|
112
158
|
|
|
113
|
-
|
|
159
|
+
termSubstitution.validate(context);
|
|
160
|
+
|
|
161
|
+
return termSubstitution;
|
|
162
|
+
}, context);
|
|
114
163
|
}
|
|
115
164
|
});
|
|
116
|
-
|
|
117
|
-
function stringFromTermAndVariable(term, variable) {
|
|
118
|
-
const termString = term.getString(),
|
|
119
|
-
variableString = variable.getString(),
|
|
120
|
-
string = `[${termString} for ${variableString}]`;
|
|
121
|
-
|
|
122
|
-
return string;
|
|
123
|
-
}
|