fitch-js 0.1.0
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/LICENSE +7 -0
- package/README.md +401 -0
- package/dist/cjs/index.js +131 -0
- package/dist/cjs/parser.js +211 -0
- package/dist/cjs/proof/index.js +31 -0
- package/dist/cjs/proof/textParser.js +222 -0
- package/dist/cjs/proof/types.js +117 -0
- package/dist/cjs/proofChecker.js +163 -0
- package/dist/cjs/ruleValidators.js +811 -0
- package/dist/cjs/symbols.js +85 -0
- package/dist/cjs/types.js +184 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/parser.js +204 -0
- package/dist/esm/proof/index.js +7 -0
- package/dist/esm/proof/textParser.js +217 -0
- package/dist/esm/proof/types.js +111 -0
- package/dist/esm/proofChecker.js +128 -0
- package/dist/esm/ruleValidators.js +799 -0
- package/dist/esm/symbols.js +77 -0
- package/dist/esm/types.js +178 -0
- package/package.json +45 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkProof = checkProof;
|
|
7
|
+
Object.defineProperty(exports, "formulasEqual", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _ruleValidators.formulasEqual;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports.getAvailableTerms = getAvailableTerms;
|
|
14
|
+
Object.defineProperty(exports, "isLineAvailable", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _ruleValidators.isLineAvailable;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "isValidCitation", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _ruleValidators.isValidCitation;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "occursFree", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _ruleValidators.occursFree;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "substitute", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _ruleValidators.substitute;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var _types = require("./types.js");
|
|
39
|
+
var _ruleValidators = require("./ruleValidators.js");
|
|
40
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
41
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
42
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
43
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
44
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
45
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
46
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
47
|
+
/**
|
|
48
|
+
* Gets all available terms from premises and hypotheses at the current scope
|
|
49
|
+
* @param {import('./types').ProofLine[]} previousLines
|
|
50
|
+
* @param {number[]} currentLocation
|
|
51
|
+
* @returns {Set<string>}
|
|
52
|
+
*/
|
|
53
|
+
function getAvailableTerms(previousLines, currentLocation) {
|
|
54
|
+
var terms = new Set();
|
|
55
|
+
var _iterator = _createForOfIteratorHelper(previousLines),
|
|
56
|
+
_step;
|
|
57
|
+
try {
|
|
58
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
59
|
+
var line = _step.value;
|
|
60
|
+
if ((line.rule === _types.RULES.PREMISE || line.rule === _types.RULES.HYPOTHESIS) && (0, _ruleValidators.isLineAvailable)(currentLocation, line.location)) {
|
|
61
|
+
(0, _types.getAllTerms)(line.formula).forEach(function (term) {
|
|
62
|
+
return terms.add(term);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
_iterator.e(err);
|
|
68
|
+
} finally {
|
|
69
|
+
_iterator.f();
|
|
70
|
+
}
|
|
71
|
+
return terms;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Validates a single proof line
|
|
76
|
+
* @param {import('./types').ProofLine} line
|
|
77
|
+
* @param {import('./types').ProofLine[]} previousLines
|
|
78
|
+
* @param {number} lineIndex
|
|
79
|
+
* @param {number} numPremises
|
|
80
|
+
* @returns {string[]} Array of issues found
|
|
81
|
+
*/
|
|
82
|
+
function validateLine(line, previousLines, lineIndex, numPremises) {
|
|
83
|
+
var issues = [];
|
|
84
|
+
|
|
85
|
+
// Validate premises
|
|
86
|
+
if (lineIndex < numPremises) {
|
|
87
|
+
if (line.rule !== _types.RULES.PREMISE) {
|
|
88
|
+
issues.push('Line must be marked as a premise');
|
|
89
|
+
}
|
|
90
|
+
return issues;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Check rule requirements exist
|
|
94
|
+
var requirements = _types.RULE_REQUIREMENTS[line.rule];
|
|
95
|
+
if (!requirements) {
|
|
96
|
+
issues.push("Unknown rule: ".concat(line.rule));
|
|
97
|
+
return issues;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Validate citation counts
|
|
101
|
+
if (line.citations.length !== requirements.lines) {
|
|
102
|
+
issues.push("Rule ".concat(line.rule, " requires exactly ").concat(requirements.lines, " line citations"));
|
|
103
|
+
}
|
|
104
|
+
if (line.subproofs.length !== requirements.subproofs) {
|
|
105
|
+
issues.push("Rule ".concat(line.rule, " requires exactly ").concat(requirements.subproofs, " subproof citations"));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Skip structural rules that don't need validation
|
|
109
|
+
if (line.rule === _types.RULES.PREMISE || line.rule === _types.RULES.HYPOTHESIS) {
|
|
110
|
+
return issues;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get the appropriate validator and execute it
|
|
114
|
+
var validator = _ruleValidators.RULE_VALIDATORS[line.rule];
|
|
115
|
+
if (validator) {
|
|
116
|
+
validator(line, previousLines, lineIndex, issues);
|
|
117
|
+
}
|
|
118
|
+
return issues;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Validates an entire proof
|
|
123
|
+
* @param {import('./types').Proof} proof
|
|
124
|
+
* @returns {import('./types').ValidationResult}
|
|
125
|
+
*/
|
|
126
|
+
function checkProof(proof) {
|
|
127
|
+
var result = {
|
|
128
|
+
isValid: true,
|
|
129
|
+
issues: [],
|
|
130
|
+
conclusionReached: false
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Validate each line
|
|
134
|
+
var _loop = function _loop(i) {
|
|
135
|
+
var line = proof.lines[i];
|
|
136
|
+
var previousLines = proof.lines.slice(0, i);
|
|
137
|
+
var lineIssues = validateLine(line, previousLines, i, proof.numPremises);
|
|
138
|
+
if (lineIssues.length > 0) {
|
|
139
|
+
var _result$issues;
|
|
140
|
+
result.isValid = false;
|
|
141
|
+
(_result$issues = result.issues).push.apply(_result$issues, _toConsumableArray(lineIssues.map(function (issue) {
|
|
142
|
+
return "Line ".concat(i + 1, ": ").concat(issue);
|
|
143
|
+
})));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Check if conclusion is reached
|
|
147
|
+
if ((0, _ruleValidators.formulasEqual)(line.formula, proof.conclusion)) {
|
|
148
|
+
result.conclusionReached = true;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
for (var i = 0; i < proof.lines.length; i++) {
|
|
152
|
+
_loop(i);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Verify conclusion was reached
|
|
156
|
+
if (!result.conclusionReached) {
|
|
157
|
+
result.issues.push('Conclusion not reached in proof');
|
|
158
|
+
result.isValid = false;
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Re-export utilities for external use
|