@polintpro/proposit-core 0.1.1
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/README.md +521 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/core/ArgumentEngine.d.ts +41 -0
- package/dist/lib/core/ArgumentEngine.d.ts.map +1 -0
- package/dist/lib/core/ArgumentEngine.js +408 -0
- package/dist/lib/core/ArgumentEngine.js.map +1 -0
- package/dist/lib/core/ExpressionManager.d.ts +19 -0
- package/dist/lib/core/ExpressionManager.d.ts.map +1 -0
- package/dist/lib/core/ExpressionManager.js +352 -0
- package/dist/lib/core/ExpressionManager.js.map +1 -0
- package/dist/lib/core/PremiseManager.d.ts +110 -0
- package/dist/lib/core/PremiseManager.d.ts.map +1 -0
- package/dist/lib/core/PremiseManager.js +541 -0
- package/dist/lib/core/PremiseManager.js.map +1 -0
- package/dist/lib/core/VariableManager.d.ts +17 -0
- package/dist/lib/core/VariableManager.d.ts.map +1 -0
- package/dist/lib/core/VariableManager.js +40 -0
- package/dist/lib/core/VariableManager.js.map +1 -0
- package/dist/lib/core/evaluation/shared.d.ts +6 -0
- package/dist/lib/core/evaluation/shared.d.ts.map +1 -0
- package/dist/lib/core/evaluation/shared.js +23 -0
- package/dist/lib/core/evaluation/shared.js.map +1 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +4 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/schemata/argument.d.ts +9 -0
- package/dist/lib/schemata/argument.d.ts.map +1 -0
- package/dist/lib/schemata/argument.js +9 -0
- package/dist/lib/schemata/argument.js.map +1 -0
- package/dist/lib/schemata/index.d.ts +4 -0
- package/dist/lib/schemata/index.d.ts.map +1 -0
- package/dist/lib/schemata/index.js +4 -0
- package/dist/lib/schemata/index.js.map +1 -0
- package/dist/lib/schemata/propositional.d.ts +107 -0
- package/dist/lib/schemata/propositional.d.ts.map +1 -0
- package/dist/lib/schemata/propositional.js +77 -0
- package/dist/lib/schemata/propositional.js.map +1 -0
- package/dist/lib/schemata/shared.d.ts +4 -0
- package/dist/lib/schemata/shared.d.ts.map +1 -0
- package/dist/lib/schemata/shared.js +6 -0
- package/dist/lib/schemata/shared.js.map +1 -0
- package/dist/lib/types/evaluation.d.ts +108 -0
- package/dist/lib/types/evaluation.d.ts.map +1 -0
- package/dist/lib/types/evaluation.js +2 -0
- package/dist/lib/types/evaluation.js.map +1 -0
- package/dist/lib/utils/collections.d.ts +6 -0
- package/dist/lib/utils/collections.d.ts.map +1 -0
- package/dist/lib/utils/collections.js +18 -0
- package/dist/lib/utils/collections.js.map +1 -0
- package/dist/lib/utils.d.ts +10 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +31 -0
- package/dist/lib/utils.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
# proposit-core
|
|
2
|
+
|
|
3
|
+
Core engine for building, evaluating, and checking the logical validity of propositional-logic arguments. Manages typed trees of variables and expressions across one or more **premises**, with strict structural invariants, automatic operator collapse, a display renderer, and a truth-table validity checker.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
This package is hosted on GitHub Packages. Add the following to your project's `.npmrc` (replace `polintpro` with your GitHub org):
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
@polintpro:registry=https://npm.pkg.github.com
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then install:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @polintpro/proposit-core
|
|
17
|
+
# or
|
|
18
|
+
npm install @polintpro/proposit-core
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Concepts
|
|
22
|
+
|
|
23
|
+
### Argument
|
|
24
|
+
|
|
25
|
+
An `ArgumentEngine` is scoped to a single **argument** — a record with an `id`, `version`, `title`, and `description`. Every variable and expression carries a matching `argumentId` and `argumentVersion`; the engine rejects entities that belong to a different argument.
|
|
26
|
+
|
|
27
|
+
### Premises
|
|
28
|
+
|
|
29
|
+
An argument is composed of one or more **premises**, each managed by a `PremiseManager`. Premises come in two types derived from their root expression:
|
|
30
|
+
|
|
31
|
+
- **Inference premise** (`"inference"`) — root is `implies` or `iff`. Used as a supporting premise or the conclusion of the argument.
|
|
32
|
+
- **Constraint premise** (`"constraint"`) — root is anything else. Restricts which variable assignments are considered admissible without contributing to the inference chain.
|
|
33
|
+
|
|
34
|
+
### Variables
|
|
35
|
+
|
|
36
|
+
A **propositional variable** (e.g. `P`, `Q`, `Rain`) is a named atomic proposition. Variables are registered with a `PremiseManager` before they can be referenced by expressions in that premise. Each variable must have a unique `id` and a unique `symbol` within the premise.
|
|
37
|
+
|
|
38
|
+
### Expressions
|
|
39
|
+
|
|
40
|
+
An **expression** is a node in the rooted expression tree managed by a `PremiseManager`. There are three kinds:
|
|
41
|
+
|
|
42
|
+
- **Variable expression** (`"variable"`) — a leaf node that references a registered variable.
|
|
43
|
+
- **Operator expression** (`"operator"`) — an interior node that applies a logical operator to its children.
|
|
44
|
+
- **Formula expression** (`"formula"`) — a transparent unary wrapper, equivalent to parentheses around its single child.
|
|
45
|
+
|
|
46
|
+
The five supported operators and their arities are:
|
|
47
|
+
|
|
48
|
+
| Operator | Symbol | Arity |
|
|
49
|
+
| --------- | ------ | -------------- |
|
|
50
|
+
| `not` | ¬ | unary (= 1) |
|
|
51
|
+
| `and` | ∧ | variadic (≥ 2) |
|
|
52
|
+
| `or` | ∨ | variadic (≥ 2) |
|
|
53
|
+
| `implies` | → | binary (= 2) |
|
|
54
|
+
| `iff` | ↔ | binary (= 2) |
|
|
55
|
+
|
|
56
|
+
`implies` and `iff` are **root-only**: they must have `parentId: null` and cannot be nested inside another expression.
|
|
57
|
+
|
|
58
|
+
### Argument roles
|
|
59
|
+
|
|
60
|
+
To evaluate or check an argument, premises must be assigned roles:
|
|
61
|
+
|
|
62
|
+
- **Conclusion** — the single premise whose truth is being argued for. Set with `ArgumentEngine.setConclusionPremise()`.
|
|
63
|
+
- **Supporting** — premises whose combined truth is supposed to entail the conclusion. Added with `ArgumentEngine.addSupportingPremise()`.
|
|
64
|
+
|
|
65
|
+
A premise that is neither supporting nor the conclusion and whose type is `"constraint"` is automatically used to filter admissible variable assignments during validity checking.
|
|
66
|
+
|
|
67
|
+
Each expression carries:
|
|
68
|
+
|
|
69
|
+
| Field | Type | Description |
|
|
70
|
+
| ----------------- | ---------------- | ---------------------------------------------------- |
|
|
71
|
+
| `id` | `string` | Unique identifier. |
|
|
72
|
+
| `argumentId` | `string` | Must match the engine's argument. |
|
|
73
|
+
| `argumentVersion` | `number` | Must match the engine's argument version. |
|
|
74
|
+
| `parentId` | `string \| null` | ID of the parent operator, or `null` for root nodes. |
|
|
75
|
+
| `position` | `number \| null` | Ordered index among siblings under the same parent. |
|
|
76
|
+
|
|
77
|
+
## Usage
|
|
78
|
+
|
|
79
|
+
### Creating an engine and premises
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { ArgumentEngine } from "@polintpro/proposit-core"
|
|
83
|
+
import type {
|
|
84
|
+
TArgument,
|
|
85
|
+
TPropositionalVariable,
|
|
86
|
+
TPropositionalExpression,
|
|
87
|
+
} from "@polintpro/proposit-core"
|
|
88
|
+
|
|
89
|
+
const argument: TArgument = {
|
|
90
|
+
id: "arg-1",
|
|
91
|
+
version: 1,
|
|
92
|
+
title: "Modus Ponens",
|
|
93
|
+
description: "",
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const eng = new ArgumentEngine(argument)
|
|
97
|
+
|
|
98
|
+
const premise1 = eng.createPremise("P implies Q")
|
|
99
|
+
const premise2 = eng.createPremise("P")
|
|
100
|
+
const conclusion = eng.createPremise("Q")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Adding variables and expressions
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const varP: TPropositionalVariable = {
|
|
107
|
+
id: "var-p",
|
|
108
|
+
argumentId: "arg-1",
|
|
109
|
+
argumentVersion: 1,
|
|
110
|
+
symbol: "P",
|
|
111
|
+
}
|
|
112
|
+
const varQ: TPropositionalVariable = {
|
|
113
|
+
id: "var-q",
|
|
114
|
+
argumentId: "arg-1",
|
|
115
|
+
argumentVersion: 1,
|
|
116
|
+
symbol: "Q",
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Premise 1: P → Q
|
|
120
|
+
premise1.addVariable(varP)
|
|
121
|
+
premise1.addVariable(varQ)
|
|
122
|
+
premise1.addExpression({
|
|
123
|
+
id: "op-implies",
|
|
124
|
+
argumentId: "arg-1",
|
|
125
|
+
argumentVersion: 1,
|
|
126
|
+
type: "operator",
|
|
127
|
+
operator: "implies",
|
|
128
|
+
parentId: null,
|
|
129
|
+
position: null,
|
|
130
|
+
})
|
|
131
|
+
premise1.addExpression({
|
|
132
|
+
id: "expr-p1",
|
|
133
|
+
argumentId: "arg-1",
|
|
134
|
+
argumentVersion: 1,
|
|
135
|
+
type: "variable",
|
|
136
|
+
variableId: "var-p",
|
|
137
|
+
parentId: "op-implies",
|
|
138
|
+
position: 0,
|
|
139
|
+
})
|
|
140
|
+
premise1.addExpression({
|
|
141
|
+
id: "expr-q",
|
|
142
|
+
argumentId: "arg-1",
|
|
143
|
+
argumentVersion: 1,
|
|
144
|
+
type: "variable",
|
|
145
|
+
variableId: "var-q",
|
|
146
|
+
parentId: "op-implies",
|
|
147
|
+
position: 1,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
console.log(premise1.toDisplayString()) // (P → Q)
|
|
151
|
+
|
|
152
|
+
// Premise 2: P
|
|
153
|
+
premise2.addVariable(varP)
|
|
154
|
+
premise2.addExpression({
|
|
155
|
+
id: "expr-p2",
|
|
156
|
+
argumentId: "arg-1",
|
|
157
|
+
argumentVersion: 1,
|
|
158
|
+
type: "variable",
|
|
159
|
+
variableId: "var-p",
|
|
160
|
+
parentId: null,
|
|
161
|
+
position: null,
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
// Conclusion: Q
|
|
165
|
+
conclusion.addVariable(varQ)
|
|
166
|
+
conclusion.addExpression({
|
|
167
|
+
id: "expr-q2",
|
|
168
|
+
argumentId: "arg-1",
|
|
169
|
+
argumentVersion: 1,
|
|
170
|
+
type: "variable",
|
|
171
|
+
variableId: "var-q",
|
|
172
|
+
parentId: null,
|
|
173
|
+
position: null,
|
|
174
|
+
})
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Setting roles
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
eng.addSupportingPremise(premise1.getId())
|
|
181
|
+
eng.addSupportingPremise(premise2.getId())
|
|
182
|
+
eng.setConclusionPremise(conclusion.getId())
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Evaluating an argument
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const result = eng.evaluate({ "var-p": true, "var-q": true })
|
|
189
|
+
if (result.ok) {
|
|
190
|
+
console.log(result.conclusionTrue) // true
|
|
191
|
+
console.log(result.allSupportingPremisesTrue) // true
|
|
192
|
+
console.log(result.isCounterexample) // false
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Checking validity
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const validity = eng.checkValidity()
|
|
200
|
+
if (validity.ok) {
|
|
201
|
+
console.log(validity.isValid) // true (Modus Ponens is valid)
|
|
202
|
+
console.log(validity.counterexamples) // []
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Inserting an expression into the tree
|
|
207
|
+
|
|
208
|
+
`insertExpression` splices a new node between existing nodes. The new expression inherits the **anchor** node's current slot in the tree (`leftNodeId ?? rightNodeId`).
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// Extend P → Q into (P ∧ R) → Q by inserting an `and` above expr-p1.
|
|
212
|
+
const varR: TPropositionalVariable = {
|
|
213
|
+
id: "var-r",
|
|
214
|
+
argumentId: "arg-1",
|
|
215
|
+
argumentVersion: 1,
|
|
216
|
+
symbol: "R",
|
|
217
|
+
}
|
|
218
|
+
premise1.addVariable(varR)
|
|
219
|
+
premise1.addExpression({
|
|
220
|
+
id: "expr-r",
|
|
221
|
+
argumentId: "arg-1",
|
|
222
|
+
argumentVersion: 1,
|
|
223
|
+
type: "variable",
|
|
224
|
+
variableId: "var-r",
|
|
225
|
+
parentId: null,
|
|
226
|
+
position: null,
|
|
227
|
+
})
|
|
228
|
+
premise1.insertExpression(
|
|
229
|
+
{
|
|
230
|
+
id: "op-and",
|
|
231
|
+
argumentId: "arg-1",
|
|
232
|
+
argumentVersion: 1,
|
|
233
|
+
type: "operator",
|
|
234
|
+
operator: "and",
|
|
235
|
+
parentId: null, // overwritten by insertExpression
|
|
236
|
+
position: null,
|
|
237
|
+
},
|
|
238
|
+
"expr-p1", // becomes child at position 0
|
|
239
|
+
"expr-r" // becomes child at position 1
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
console.log(premise1.toDisplayString()) // ((P ∧ R) → Q)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Removing expressions
|
|
246
|
+
|
|
247
|
+
Removing an expression also removes its entire descendant subtree. After the subtree is gone, ancestor operators left with fewer than two children are automatically collapsed:
|
|
248
|
+
|
|
249
|
+
- **0 children remaining** — the operator is deleted; the check recurses upward.
|
|
250
|
+
- **1 child remaining** — the operator is deleted and that child is promoted into the operator's former slot.
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
// Remove expr-r from the and-cluster.
|
|
254
|
+
// op-and now has only expr-p1 → op-and is deleted, expr-p1 is promoted back
|
|
255
|
+
// to position 0 under op-implies.
|
|
256
|
+
premise1.removeExpression("expr-r")
|
|
257
|
+
|
|
258
|
+
console.log(premise1.toDisplayString()) // (P → Q)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## API Reference
|
|
262
|
+
|
|
263
|
+
### `ArgumentEngine`
|
|
264
|
+
|
|
265
|
+
#### `new ArgumentEngine(argument)`
|
|
266
|
+
|
|
267
|
+
Creates an engine scoped to `argument` (`{ id, version, title, description }`).
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
#### `createPremise(title?)` → `PremiseManager`
|
|
272
|
+
|
|
273
|
+
Creates a new `PremiseManager`, registers it with the engine, and returns it.
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
#### `removePremise(premiseId)`
|
|
278
|
+
|
|
279
|
+
Removes a premise and clears its role assignments.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
#### `getPremise(premiseId)` → `PremiseManager | undefined`
|
|
284
|
+
|
|
285
|
+
Returns the `PremiseManager` for the given ID, or `undefined`.
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
#### `hasPremise(premiseId)` → `boolean`
|
|
290
|
+
|
|
291
|
+
Returns `true` if a premise with the given ID exists.
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
#### `listPremises()` → `PremiseManager[]`
|
|
296
|
+
|
|
297
|
+
Returns all premises sorted by ID.
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
#### `listPremiseIds()` → `string[]`
|
|
302
|
+
|
|
303
|
+
Returns all premise IDs sorted alphabetically.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
#### `setConclusionPremise(premiseId)`
|
|
308
|
+
|
|
309
|
+
Designates a premise as the conclusion. Throws if the premise does not exist or is already a supporting premise.
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
#### `clearConclusionPremise()`
|
|
314
|
+
|
|
315
|
+
Removes the conclusion role assignment.
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
#### `getConclusionPremise()` → `PremiseManager | undefined`
|
|
320
|
+
|
|
321
|
+
Returns the conclusion `PremiseManager`, if one has been set.
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
#### `addSupportingPremise(premiseId)`
|
|
326
|
+
|
|
327
|
+
Adds a premise to the set of supporting premises. Throws if it is already the conclusion.
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
#### `removeSupportingPremise(premiseId)`
|
|
332
|
+
|
|
333
|
+
Removes a premise from the supporting set.
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
#### `listSupportingPremises()` → `PremiseManager[]`
|
|
338
|
+
|
|
339
|
+
Returns all supporting premises sorted by ID.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
#### `getRoleState()` → `TArgumentRoleState`
|
|
344
|
+
|
|
345
|
+
Returns `{ supportingPremiseIds, conclusionPremiseId }`.
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
#### `collectReferencedVariables()`
|
|
350
|
+
|
|
351
|
+
Returns a cross-premise summary of every variable referenced by expressions, keyed by `id` and `symbol`.
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
#### `validateEvaluability()` → `TValidationResult`
|
|
356
|
+
|
|
357
|
+
Checks whether the argument is structurally ready to evaluate. Returns `{ ok, issues }`.
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
#### `evaluate(assignment, options?)` → `TArgumentEvaluationResult`
|
|
362
|
+
|
|
363
|
+
Evaluates all relevant premises under the given variable assignment (`Record<string, boolean>`). Returns per-premise truth values, counterexample status, and an admissibility flag.
|
|
364
|
+
|
|
365
|
+
Options:
|
|
366
|
+
|
|
367
|
+
- `validateFirst` (default `true`) — run validation before evaluating.
|
|
368
|
+
- `includeExpressionValues` (default `true`) — include per-expression truth maps.
|
|
369
|
+
- `includeDiagnostics` (default `true`) — include inference diagnostics.
|
|
370
|
+
- `strictUnknownAssignmentKeys` (default `false`) — reject assignment keys not referenced by evaluated premises.
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
#### `checkValidity(options?)` → `TValidityCheckResult`
|
|
375
|
+
|
|
376
|
+
Runs a truth-table search over all 2ⁿ assignments (n = distinct referenced variable count). Returns `isValid` (`true`, `false`, or `undefined` if truncated), counterexamples, and statistics.
|
|
377
|
+
|
|
378
|
+
Options:
|
|
379
|
+
|
|
380
|
+
- `mode` (`"firstCounterexample"` | `"exhaustive"`, default `"firstCounterexample"`) — stop at first counterexample or continue exhaustively.
|
|
381
|
+
- `maxVariables` — safety limit on the number of variables.
|
|
382
|
+
- `maxAssignmentsChecked` — safety limit on the number of assignments evaluated.
|
|
383
|
+
- `includeCounterexampleEvaluations` (default `false`) — attach full evaluation payloads to counterexamples.
|
|
384
|
+
- `validateFirst` (default `true`) — run validation before the search.
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
#### `toData()` / `exportState()` → `TArgumentEngineData`
|
|
389
|
+
|
|
390
|
+
Returns a serialisable snapshot of the engine state (`{ argument, premises, roles }`).
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
### `PremiseManager`
|
|
395
|
+
|
|
396
|
+
#### `addVariable(variable)`
|
|
397
|
+
|
|
398
|
+
Registers a variable for use in this premise. Throws if the `id` or `symbol` is already in use, or if the variable does not belong to this argument.
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
#### `removeVariable(variableId)` → `TPropositionalVariable | undefined`
|
|
403
|
+
|
|
404
|
+
Removes and returns a variable. Throws if any expression still references it.
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
#### `addExpression(expression)`
|
|
409
|
+
|
|
410
|
+
Adds an expression to the tree. Validates argument membership, variable references, root uniqueness, and structural constraints (operator type, child limits, position uniqueness).
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
#### `removeExpression(expressionId)` → `TPropositionalExpression | undefined`
|
|
415
|
+
|
|
416
|
+
Removes an expression and its subtree, then collapses degenerate ancestor operators. Returns the removed root expression, or `undefined` if not found.
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
#### `insertExpression(expression, leftNodeId?, rightNodeId?)`
|
|
421
|
+
|
|
422
|
+
Splices `expression` into the tree. At least one of `leftNodeId` / `rightNodeId` must be provided. `leftNodeId` becomes position 0 and `rightNodeId` position 1 under the new expression.
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
#### `getExpression(id)` → `TPropositionalExpression | undefined`
|
|
427
|
+
|
|
428
|
+
Returns an expression by ID.
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
#### `getExpressions()` → `TPropositionalExpression[]`
|
|
433
|
+
|
|
434
|
+
Returns all expressions sorted by ID.
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
#### `getVariables()` → `TPropositionalVariable[]`
|
|
439
|
+
|
|
440
|
+
Returns all registered variables sorted by ID.
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
#### `getChildExpressions(parentId)` → `TPropositionalExpression[]`
|
|
445
|
+
|
|
446
|
+
Returns children of `parentId` sorted by position.
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
#### `getRootExpression()` → `TPropositionalExpression | undefined`
|
|
451
|
+
|
|
452
|
+
Returns the root expression, if one exists.
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
#### `getRootExpressionId()` → `string | undefined`
|
|
457
|
+
|
|
458
|
+
Returns the root expression ID.
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
#### `getPremiseType()` → `"inference" | "constraint"`
|
|
463
|
+
|
|
464
|
+
Derived from the root expression.
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
#### `getId()` → `string`
|
|
469
|
+
|
|
470
|
+
Returns this premise's ID.
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
#### `getTitle()` → `string | undefined`
|
|
475
|
+
|
|
476
|
+
Returns this premise's optional title.
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
480
|
+
#### `validateEvaluability()` → `TValidationResult`
|
|
481
|
+
|
|
482
|
+
Validates the premise structure (root presence, child counts, variable declarations, binary positions).
|
|
483
|
+
|
|
484
|
+
---
|
|
485
|
+
|
|
486
|
+
#### `evaluate(assignment, options?)` → `TPremiseEvaluationResult`
|
|
487
|
+
|
|
488
|
+
Evaluates the expression tree under the given assignment. Throws if the premise is not valid. Returns `{ rootValue, expressionValues, variableValues, inferenceDiagnostic }`.
|
|
489
|
+
|
|
490
|
+
---
|
|
491
|
+
|
|
492
|
+
#### `toDisplayString()` → `string`
|
|
493
|
+
|
|
494
|
+
Returns the expression tree rendered with standard logical notation (¬ ∧ ∨ → ↔). Missing operands render as `(?)`.
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
#### `toData()` → `TPremise`
|
|
499
|
+
|
|
500
|
+
Returns a serialisable snapshot of this premise (`{ id, title, type, rootExpressionId, variables, expressions }`).
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## Development
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
pnpm install
|
|
508
|
+
pnpm run typecheck # type-check without emitting
|
|
509
|
+
pnpm run lint # Prettier + ESLint
|
|
510
|
+
pnpm run test # Vitest
|
|
511
|
+
pnpm run build # compile to dist/
|
|
512
|
+
pnpm run check # all of the above in sequence
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
## Publishing
|
|
516
|
+
|
|
517
|
+
Releases are published to GitHub Packages automatically. To publish a new version:
|
|
518
|
+
|
|
519
|
+
1. Bump `version` in `package.json`.
|
|
520
|
+
2. Create a GitHub Release with a tag matching the version (e.g. `v0.2.0`).
|
|
521
|
+
3. The [Publish workflow](.github/workflows/publish.yml) will build and publish the package.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5D,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5D,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TArgument } from "../schemata";
|
|
2
|
+
import type { TArgumentEngineData, TArgumentEvaluationOptions, TArgumentEvaluationResult, TArgumentRoleState, TValidationResult, TValidityCheckOptions, TValidityCheckResult, TVariableAssignment } from "../types/evaluation";
|
|
3
|
+
import { PremiseManager } from "./PremiseManager";
|
|
4
|
+
export declare class ArgumentEngine {
|
|
5
|
+
private argument;
|
|
6
|
+
private premises;
|
|
7
|
+
private supportingPremiseIds;
|
|
8
|
+
private conclusionPremiseId;
|
|
9
|
+
constructor(argument: TArgument);
|
|
10
|
+
getArgument(): TArgument;
|
|
11
|
+
createPremise(title?: string): PremiseManager;
|
|
12
|
+
removePremise(premiseId: string): void;
|
|
13
|
+
getPremise(premiseId: string): PremiseManager | undefined;
|
|
14
|
+
hasPremise(premiseId: string): boolean;
|
|
15
|
+
listPremiseIds(): string[];
|
|
16
|
+
listPremises(): PremiseManager[];
|
|
17
|
+
getRoleState(): TArgumentRoleState;
|
|
18
|
+
setConclusionPremise(premiseId: string): void;
|
|
19
|
+
clearConclusionPremise(): void;
|
|
20
|
+
getConclusionPremise(): PremiseManager | undefined;
|
|
21
|
+
addSupportingPremise(premiseId: string): void;
|
|
22
|
+
removeSupportingPremise(premiseId: string): void;
|
|
23
|
+
listSupportingPremises(): PremiseManager[];
|
|
24
|
+
toData(): TArgumentEngineData;
|
|
25
|
+
exportState(): TArgumentEngineData;
|
|
26
|
+
collectReferencedVariables(): {
|
|
27
|
+
variableIds: string[];
|
|
28
|
+
byId: Record<string, {
|
|
29
|
+
symbol: string;
|
|
30
|
+
premiseIds: string[];
|
|
31
|
+
}>;
|
|
32
|
+
bySymbol: Record<string, {
|
|
33
|
+
variableIds: string[];
|
|
34
|
+
premiseIds: string[];
|
|
35
|
+
}>;
|
|
36
|
+
};
|
|
37
|
+
validateEvaluability(): TValidationResult;
|
|
38
|
+
evaluate(assignment: TVariableAssignment, options?: TArgumentEvaluationOptions): TArgumentEvaluationResult;
|
|
39
|
+
checkValidity(options?: TValidityCheckOptions): TValidityCheckResult;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=ArgumentEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArgumentEngine.d.ts","sourceRoot":"","sources":["../../../src/lib/core/ArgumentEngine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,aAAa,CAAA;AACtE,OAAO,KAAK,EACR,mBAAmB,EACnB,0BAA0B,EAC1B,yBAAyB,EACzB,kBAAkB,EAIlB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACtB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,oBAAoB,CAAa;IACzC,OAAO,CAAC,mBAAmB,CAAoB;gBAEnC,QAAQ,EAAE,SAAS;IAOxB,WAAW,IAAI,SAAS;IAIxB,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,cAAc;IAO7C,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAQtC,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIzD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAItC,cAAc,IAAI,MAAM,EAAE;IAM1B,YAAY,IAAI,cAAc,EAAE;IAMhC,YAAY,IAAI,kBAAkB;IAOlC,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAY7C,sBAAsB,IAAI,IAAI;IAI9B,oBAAoB,IAAI,cAAc,GAAG,SAAS;IAOlD,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAY7C,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIhD,sBAAsB,IAAI,cAAc,EAAE;IAM1C,MAAM,IAAI,mBAAmB;IAQ7B,WAAW,IAAI,mBAAmB;IAIlC,0BAA0B,IAAI;QACjC,WAAW,EAAE,MAAM,EAAE,CAAA;QACrB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;QAC9D,QAAQ,EAAE,MAAM,CACZ,MAAM,EACN;YAAE,WAAW,EAAE,MAAM,EAAE,CAAC;YAAC,UAAU,EAAE,MAAM,EAAE,CAAA;SAAE,CAClD,CAAA;KACJ;IAuEM,oBAAoB,IAAI,iBAAiB;IA+FzC,QAAQ,CACX,UAAU,EAAE,mBAAmB,EAC/B,OAAO,CAAC,EAAE,0BAA0B,GACrC,yBAAyB;IA6HrB,aAAa,CAChB,OAAO,CAAC,EAAE,qBAAqB,GAChC,oBAAoB;CA4I1B"}
|