@lapxo/obligations 0.2.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 +21 -0
- package/README.md +169 -0
- package/dist/debit/debit.d.ts +3 -0
- package/dist/debit/debit.js +19 -0
- package/dist/debit/graph.d.ts +10 -0
- package/dist/debit/graph.js +57 -0
- package/dist/debit/ideal.d.ts +20 -0
- package/dist/debit/ideal.js +80 -0
- package/dist/debit/masks.d.ts +16 -0
- package/dist/debit/masks.js +95 -0
- package/dist/debit/packed.d.ts +30 -0
- package/dist/debit/packed.js +114 -0
- package/dist/debit/provenance.d.ts +3 -0
- package/dist/debit/provenance.js +8 -0
- package/dist/debit/register.d.ts +7 -0
- package/dist/debit/register.js +17 -0
- package/dist/debit/shuffle.d.ts +3 -0
- package/dist/debit/shuffle.js +30 -0
- package/dist/debit/standing.d.ts +3 -0
- package/dist/debit/standing.js +12 -0
- package/dist/debit/unit-span.d.ts +8 -0
- package/dist/debit/unit-span.js +63 -0
- package/dist/debit/unit.d.ts +22 -0
- package/dist/debit/unit.js +110 -0
- package/dist/debit/vector-move.d.ts +12 -0
- package/dist/debit/vector-move.js +48 -0
- package/dist/debit/vector.d.ts +26 -0
- package/dist/debit/vector.js +68 -0
- package/dist/field/encounter.d.ts +9 -0
- package/dist/field/encounter.js +36 -0
- package/dist/field/field.d.ts +39 -0
- package/dist/field/field.js +79 -0
- package/dist/field/frontier.d.ts +20 -0
- package/dist/field/frontier.js +16 -0
- package/dist/field/motion.d.ts +14 -0
- package/dist/field/motion.js +38 -0
- package/dist/field/present.d.ts +8 -0
- package/dist/field/present.js +18 -0
- package/dist/field/signatures.d.ts +6 -0
- package/dist/field/signatures.js +19 -0
- package/dist/field/yield.d.ts +15 -0
- package/dist/field/yield.js +16 -0
- package/dist/lattice/axioms.d.ts +14 -0
- package/dist/lattice/axioms.js +140 -0
- package/dist/lattice/declaration.d.ts +9 -0
- package/dist/lattice/declaration.js +12 -0
- package/dist/lattice/errors.d.ts +6 -0
- package/dist/lattice/errors.js +11 -0
- package/dist/lattice/forms.d.ts +38 -0
- package/dist/lattice/forms.js +198 -0
- package/dist/lattice/index.d.ts +45 -0
- package/dist/lattice/index.js +29 -0
- package/dist/lattice/lattice.d.ts +18 -0
- package/dist/lattice/lattice.js +14 -0
- package/dist/lattice/obligatory.d.ts +27 -0
- package/dist/lattice/obligatory.js +33 -0
- package/dist/lattice/order.d.ts +6 -0
- package/dist/lattice/order.js +150 -0
- package/dist/lattice/price/attainable.d.ts +22 -0
- package/dist/lattice/price/attainable.js +37 -0
- package/dist/lattice/price/blocks.d.ts +2 -0
- package/dist/lattice/price/blocks.js +26 -0
- package/dist/lattice/price/index.d.ts +7 -0
- package/dist/lattice/price/index.js +5 -0
- package/dist/lattice/price/premium.d.ts +18 -0
- package/dist/lattice/price/premium.js +80 -0
- package/dist/lattice/price/quote.d.ts +30 -0
- package/dist/lattice/price/quote.js +53 -0
- package/dist/lattice/scale-lattice.d.ts +5 -0
- package/dist/lattice/scale-lattice.js +35 -0
- package/dist/lattice/types.d.ts +40 -0
- package/dist/lattice/types.js +1 -0
- package/dist/lattice/vacuity.d.ts +22 -0
- package/dist/lattice/vacuity.js +55 -0
- package/dist/replay.d.ts +2 -0
- package/dist/replay.js +4 -0
- package/dist/views/chain.d.ts +5 -0
- package/dist/views/chain.js +5 -0
- package/dist/views/complement.d.ts +2 -0
- package/dist/views/complement.js +2 -0
- package/dist/views/dual.d.ts +1 -0
- package/dist/views/dual.js +1 -0
- package/dist/views/field/physics.d.ts +13 -0
- package/dist/views/field/physics.js +64 -0
- package/dist/views/field/policy.d.ts +20 -0
- package/dist/views/field/policy.js +68 -0
- package/dist/views/field/self.d.ts +8 -0
- package/dist/views/field/self.js +14 -0
- package/dist/views/field/wave.d.ts +16 -0
- package/dist/views/field/wave.js +34 -0
- package/dist/views/field.d.ts +12 -0
- package/dist/views/field.js +9 -0
- package/dist/views/galois.d.ts +2 -0
- package/dist/views/galois.js +2 -0
- package/dist/views/ideal.d.ts +10 -0
- package/dist/views/ideal.js +10 -0
- package/dist/views/product/design.d.ts +13 -0
- package/dist/views/product/design.js +66 -0
- package/dist/views/product/mould.d.ts +14 -0
- package/dist/views/product/mould.js +55 -0
- package/dist/views/product/polygon.d.ts +10 -0
- package/dist/views/product/polygon.js +65 -0
- package/dist/views/product/reach.d.ts +14 -0
- package/dist/views/product/reach.js +106 -0
- package/dist/views/product/resolution.d.ts +8 -0
- package/dist/views/product/resolution.js +34 -0
- package/dist/views/product.d.ts +12 -0
- package/dist/views/product.js +10 -0
- package/dist/views/quotient.d.ts +2 -0
- package/dist/views/quotient.js +2 -0
- package/dist/views/spectrum.d.ts +4 -0
- package/dist/views/spectrum.js +4 -0
- package/dist/views/valuation.d.ts +9 -0
- package/dist/views/valuation.js +9 -0
- package/package.json +91 -0
- package/receipts.bound +491 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isDistributive } from "../lattice/order.js";
|
|
2
|
+
import { isSupermodular, premium } from "../lattice/price/premium.js";
|
|
3
|
+
import { state, unit } from "../debit/unit.js";
|
|
4
|
+
import { statesPerDebit } from "../debit/unit-span.js";
|
|
5
|
+
import { STATES } from "../debit/vector.js";
|
|
6
|
+
export function declarationOf(c, place) {
|
|
7
|
+
return place.seen.reduce((held, s) => ({ demand: c.higher(held.demand, s.span.lo), limit: c.lower(held.limit, s.span.hi) }), { demand: c.bottomIx, limit: c.topIx });
|
|
8
|
+
}
|
|
9
|
+
export function unitOf(c, place) {
|
|
10
|
+
const { demand, limit } = declarationOf(c, place);
|
|
11
|
+
return unit(place.at.join('/'), { floor: c.levels[demand] ?? c.bottom, ceiling: c.levels[limit] ?? c.top });
|
|
12
|
+
}
|
|
13
|
+
export function stateOf(c, place) {
|
|
14
|
+
return state(c, unitOf(c, place));
|
|
15
|
+
}
|
|
16
|
+
export function registerOf(c, place) {
|
|
17
|
+
return statesPerDebit(c, unitOf(c, place));
|
|
18
|
+
}
|
|
19
|
+
export function premiumOf(c, value, place) {
|
|
20
|
+
const { demand, limit } = declarationOf(c, place);
|
|
21
|
+
return premium(c, value, demand, limit);
|
|
22
|
+
}
|
|
23
|
+
export function degenerate(c, value) {
|
|
24
|
+
return isSupermodular(c, value);
|
|
25
|
+
}
|
|
26
|
+
export function withdrawsExactly(c) {
|
|
27
|
+
return isDistributive(c);
|
|
28
|
+
}
|
|
29
|
+
export function movesOf(c, before, after) {
|
|
30
|
+
const moves = Object.fromEntries(STATES.map((a) => [a, Object.fromEntries(STATES.map((b) => [b, 0]))]));
|
|
31
|
+
const was = new Map(registerOf(c, before));
|
|
32
|
+
for (const [debit, now] of registerOf(c, after)) {
|
|
33
|
+
const then = was.get(debit);
|
|
34
|
+
if (then)
|
|
35
|
+
moves[then][now] += 1;
|
|
36
|
+
}
|
|
37
|
+
return moves;
|
|
38
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Point } from './field.ts';
|
|
2
|
+
import type { Interval } from '../lattice/forms.ts';
|
|
3
|
+
export declare function present(place: Point): Interval | 'potential' | null;
|
|
4
|
+
export declare function converge(width: number, maturation: number, forgetting: number, epochs: number): {
|
|
5
|
+
readonly width: number;
|
|
6
|
+
readonly trend: 'widens' | 'narrows' | 'holds' | 'zero';
|
|
7
|
+
};
|
|
8
|
+
export declare function endsBeforeNow(now: number, leading: readonly (readonly [number, number])[], lagging: readonly (readonly [number, number])[]): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { meetAt, potential } from "./encounter.js";
|
|
2
|
+
export function present(place) {
|
|
3
|
+
if (potential(place))
|
|
4
|
+
return 'potential';
|
|
5
|
+
const held = meetAt(place);
|
|
6
|
+
return held.lo > held.hi ? null : held;
|
|
7
|
+
}
|
|
8
|
+
export function converge(width, maturation, forgetting, epochs) {
|
|
9
|
+
let at = width;
|
|
10
|
+
for (let epoch = 0; epoch < epochs; epoch += 1)
|
|
11
|
+
at = Math.max(0, at + maturation - forgetting);
|
|
12
|
+
return { width: at, trend: at === 0 && width > 0 ? 'zero' : at > width ? 'widens' : at < width ? 'narrows' : 'holds' };
|
|
13
|
+
}
|
|
14
|
+
export function endsBeforeNow(now, leading, lagging) {
|
|
15
|
+
const ends = [...leading, ...lagging].map(([, hi]) => hi);
|
|
16
|
+
const end = ends.length ? Math.max(...ends) : 0;
|
|
17
|
+
return leading.length === 0 && end < now;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { relate } from "../lattice/lattice.js";
|
|
2
|
+
export function foldSigned(L, values) {
|
|
3
|
+
const classes = [];
|
|
4
|
+
for (let i = 0; i < values.length; i++) {
|
|
5
|
+
const home = classes.find((c) => relate(L, values[c[0]], values[i]) === 'equal');
|
|
6
|
+
if (home)
|
|
7
|
+
home.push(i);
|
|
8
|
+
else
|
|
9
|
+
classes.push([i]);
|
|
10
|
+
}
|
|
11
|
+
const standing = [];
|
|
12
|
+
for (let c = 0; c < classes.length; c++) {
|
|
13
|
+
const mine = values[classes[c][0]];
|
|
14
|
+
const beaten = classes.some((other, o) => o !== c && relate(L, values[other[0]], mine) === 'narrower');
|
|
15
|
+
if (!beaten)
|
|
16
|
+
standing.push(c);
|
|
17
|
+
}
|
|
18
|
+
return { classes, standing, fork: standing.length > 1 };
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Scale, Unit } from '../lattice/types.ts';
|
|
2
|
+
export interface Act {
|
|
3
|
+
readonly by: string;
|
|
4
|
+
readonly epoch: number;
|
|
5
|
+
readonly before: Unit;
|
|
6
|
+
readonly after: Unit;
|
|
7
|
+
}
|
|
8
|
+
export interface Yield {
|
|
9
|
+
readonly by: string;
|
|
10
|
+
readonly epoch: number;
|
|
11
|
+
readonly closed: number;
|
|
12
|
+
readonly reopened: number;
|
|
13
|
+
readonly acts: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function yieldOf(c: Scale, acts: readonly Act[]): readonly Yield[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { freedom } from "../debit/ideal.js";
|
|
2
|
+
export function yieldOf(c, acts) {
|
|
3
|
+
const by = new Map();
|
|
4
|
+
for (const act of acts) {
|
|
5
|
+
const moved = freedom(c, act.before) - freedom(c, act.after);
|
|
6
|
+
const key = `${act.by} ${act.epoch}`;
|
|
7
|
+
const held = by.get(key) ?? { by: act.by, epoch: act.epoch, closed: 0, reopened: 0, acts: 0 };
|
|
8
|
+
by.set(key, {
|
|
9
|
+
...held,
|
|
10
|
+
closed: held.closed + Math.max(moved, 0),
|
|
11
|
+
reopened: held.reopened + Math.max(-moved, 0),
|
|
12
|
+
acts: held.acts + 1,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return [...by.values()].sort((a, b) => (a.by === b.by ? a.epoch - b.epoch : a.by < b.by ? -1 : 1));
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Lattice, MeetSemilattice, Poset } from './lattice.ts';
|
|
2
|
+
import type { IdealDebit } from '../debit/ideal.ts';
|
|
3
|
+
import type { Scale } from './types.ts';
|
|
4
|
+
export declare const POSET_LAW_NAMES: readonly ["transitivity", "antisymmetry"];
|
|
5
|
+
export declare const MEET_LAW_NAMES: readonly ["idempotence.meet", "unit.top", "top.greatest", "commutativity.meet", "consistency.meet", "associativity.meet"];
|
|
6
|
+
export declare const JOIN_LAW_NAMES: readonly ["idempotence.join", "unit.bottom", "bottom.least", "commutativity.join", "consistency.join", "associativity.join"];
|
|
7
|
+
export declare const BOTH_LAW_NAMES: readonly ["absorption.meet", "absorption.join"];
|
|
8
|
+
export declare const CLOSURE_LAW_NAMES: readonly ["closure.demand", "closure.permit", "closure.meet", "closure.join"];
|
|
9
|
+
export declare const LATTICE_LAW_NAMES: readonly ["transitivity", "antisymmetry", "idempotence.meet", "unit.top", "top.greatest", "commutativity.meet", "consistency.meet", "associativity.meet", "idempotence.join", "unit.bottom", "bottom.least", "commutativity.join", "consistency.join", "associativity.join", "absorption.meet", "absorption.join"];
|
|
10
|
+
export type LatticeLawName = (typeof LATTICE_LAW_NAMES)[number];
|
|
11
|
+
export declare function posetViolationsIn<T>(L: Poset<T>, xs: readonly T[]): readonly string[];
|
|
12
|
+
export declare function meetViolationsIn<T>(L: MeetSemilattice<T>, xs: readonly T[]): readonly string[];
|
|
13
|
+
export declare function violationsIn<T>(L: Lattice<T>, xs: readonly T[]): readonly string[];
|
|
14
|
+
export declare function closureViolationsIn(c: Scale, xs: readonly IdealDebit[]): readonly string[];
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { eq } from "./lattice.js";
|
|
2
|
+
import { isDownset, isUpset, idealJoin, idealMeet } from "../debit/ideal.js";
|
|
3
|
+
export const POSET_LAW_NAMES = [
|
|
4
|
+
'transitivity',
|
|
5
|
+
'antisymmetry',
|
|
6
|
+
];
|
|
7
|
+
export const MEET_LAW_NAMES = [
|
|
8
|
+
'idempotence.meet',
|
|
9
|
+
'unit.top',
|
|
10
|
+
'top.greatest',
|
|
11
|
+
'commutativity.meet',
|
|
12
|
+
'consistency.meet',
|
|
13
|
+
'associativity.meet',
|
|
14
|
+
];
|
|
15
|
+
export const JOIN_LAW_NAMES = [
|
|
16
|
+
'idempotence.join',
|
|
17
|
+
'unit.bottom',
|
|
18
|
+
'bottom.least',
|
|
19
|
+
'commutativity.join',
|
|
20
|
+
'consistency.join',
|
|
21
|
+
'associativity.join',
|
|
22
|
+
];
|
|
23
|
+
export const BOTH_LAW_NAMES = [
|
|
24
|
+
'absorption.meet',
|
|
25
|
+
'absorption.join',
|
|
26
|
+
];
|
|
27
|
+
export const CLOSURE_LAW_NAMES = [
|
|
28
|
+
'closure.demand',
|
|
29
|
+
'closure.permit',
|
|
30
|
+
'closure.meet',
|
|
31
|
+
'closure.join',
|
|
32
|
+
];
|
|
33
|
+
export const LATTICE_LAW_NAMES = [
|
|
34
|
+
...POSET_LAW_NAMES,
|
|
35
|
+
...MEET_LAW_NAMES,
|
|
36
|
+
...JOIN_LAW_NAMES,
|
|
37
|
+
...BOTH_LAW_NAMES,
|
|
38
|
+
];
|
|
39
|
+
const sayAt = (L, law, at) => `${law}: ${at.map((x) => L.show(x)).join(' , ')}`;
|
|
40
|
+
export function posetViolationsIn(L, xs) {
|
|
41
|
+
const out = [];
|
|
42
|
+
const same = (a, b) => eq(L, a, b);
|
|
43
|
+
for (const a of xs) {
|
|
44
|
+
for (const b of xs) {
|
|
45
|
+
if (L.leq(a, b) && L.leq(b, a) && !same(a, b)) {
|
|
46
|
+
out.push(sayAt(L, 'antisymmetry', [a, b]));
|
|
47
|
+
}
|
|
48
|
+
for (const d of xs) {
|
|
49
|
+
if (L.leq(a, b) && L.leq(b, d) && !L.leq(a, d)) {
|
|
50
|
+
out.push(sayAt(L, 'transitivity', [a, b, d]));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
export function meetViolationsIn(L, xs) {
|
|
58
|
+
const out = [...posetViolationsIn(L, xs)];
|
|
59
|
+
const same = (a, b) => eq(L, a, b);
|
|
60
|
+
const say = (law, ...at) => {
|
|
61
|
+
out.push(sayAt(L, law, at));
|
|
62
|
+
};
|
|
63
|
+
for (const a of xs) {
|
|
64
|
+
if (!same(L.meet(a, a), a))
|
|
65
|
+
say('idempotence.meet', a);
|
|
66
|
+
if (!same(L.meet(a, L.top), a))
|
|
67
|
+
say('unit.top', a);
|
|
68
|
+
if (!L.leq(a, L.top))
|
|
69
|
+
say('top.greatest', a);
|
|
70
|
+
for (const b of xs) {
|
|
71
|
+
if (!same(L.meet(a, b), L.meet(b, a)))
|
|
72
|
+
say('commutativity.meet', a, b);
|
|
73
|
+
const le = L.leq(a, b);
|
|
74
|
+
if (le !== same(L.meet(a, b), a))
|
|
75
|
+
say('consistency.meet', a, b);
|
|
76
|
+
for (const d of xs) {
|
|
77
|
+
if (!same(L.meet(L.meet(a, b), d), L.meet(a, L.meet(b, d)))) {
|
|
78
|
+
say('associativity.meet', a, b, d);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
export function violationsIn(L, xs) {
|
|
86
|
+
const out = [...meetViolationsIn(L, xs)];
|
|
87
|
+
const same = (a, b) => eq(L, a, b);
|
|
88
|
+
const say = (law, ...at) => {
|
|
89
|
+
out.push(sayAt(L, law, at));
|
|
90
|
+
};
|
|
91
|
+
for (const a of xs) {
|
|
92
|
+
if (!same(L.join(a, a), a))
|
|
93
|
+
say('idempotence.join', a);
|
|
94
|
+
if (!same(L.join(a, L.bottom), a))
|
|
95
|
+
say('unit.bottom', a);
|
|
96
|
+
if (!L.leq(L.bottom, a))
|
|
97
|
+
say('bottom.least', a);
|
|
98
|
+
for (const b of xs) {
|
|
99
|
+
if (!same(L.join(a, b), L.join(b, a)))
|
|
100
|
+
say('commutativity.join', a, b);
|
|
101
|
+
if (!same(L.meet(a, L.join(a, b)), a))
|
|
102
|
+
say('absorption.meet', a, b);
|
|
103
|
+
if (!same(L.join(a, L.meet(a, b)), a))
|
|
104
|
+
say('absorption.join', a, b);
|
|
105
|
+
const le = L.leq(a, b);
|
|
106
|
+
if (le !== same(L.join(a, b), b))
|
|
107
|
+
say('consistency.join', a, b);
|
|
108
|
+
for (const d of xs) {
|
|
109
|
+
if (!same(L.join(L.join(a, b), d), L.join(a, L.join(b, d)))) {
|
|
110
|
+
say('associativity.join', a, b, d);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
export function closureViolationsIn(c, xs) {
|
|
118
|
+
const out = [];
|
|
119
|
+
const say = (law, at) => {
|
|
120
|
+
out.push(`${law}: ${at}`);
|
|
121
|
+
};
|
|
122
|
+
const shown = (d) => `{${d.demand.join(',')}}/{${d.permit.join(',')}}`;
|
|
123
|
+
for (const a of xs) {
|
|
124
|
+
if (!isUpset(c, a.demand))
|
|
125
|
+
say('closure.demand', shown(a));
|
|
126
|
+
if (!isDownset(c, a.permit))
|
|
127
|
+
say('closure.permit', shown(a));
|
|
128
|
+
for (const b of xs) {
|
|
129
|
+
const m = idealMeet(a, b);
|
|
130
|
+
const j = idealJoin(a, b);
|
|
131
|
+
if (!isUpset(c, m.demand) || !isDownset(c, m.permit)) {
|
|
132
|
+
say('closure.meet', `${shown(a)} , ${shown(b)}`);
|
|
133
|
+
}
|
|
134
|
+
if (!isUpset(c, j.demand) || !isDownset(c, j.permit)) {
|
|
135
|
+
say('closure.join', `${shown(a)} , ${shown(b)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Level, Scale, Unit } from './types.ts';
|
|
2
|
+
export interface Declaration {
|
|
3
|
+
readonly demand: Level;
|
|
4
|
+
readonly limit: Level;
|
|
5
|
+
}
|
|
6
|
+
export declare function declaration(c: Scale, u: Unit): Declaration;
|
|
7
|
+
export declare function asUnit(c: Scale, d: Declaration, subject?: string): Unit;
|
|
8
|
+
export declare function conj(c: Scale, a: Declaration, b: Declaration): Declaration;
|
|
9
|
+
export declare function disj(c: Scale, a: Declaration, b: Declaration): Declaration;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function declaration(c, u) {
|
|
2
|
+
return { demand: c.rank(u.floor), limit: c.rank(u.ceiling) };
|
|
3
|
+
}
|
|
4
|
+
export function asUnit(c, d, subject = '') {
|
|
5
|
+
return { subject, floor: c.levels[d.demand], ceiling: c.levels[d.limit] };
|
|
6
|
+
}
|
|
7
|
+
export function conj(c, a, b) {
|
|
8
|
+
return { demand: c.higher(a.demand, b.demand), limit: c.lower(a.limit, b.limit) };
|
|
9
|
+
}
|
|
10
|
+
export function disj(c, a, b) {
|
|
11
|
+
return { demand: c.lower(a.demand, b.demand), limit: c.higher(a.limit, b.limit) };
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type UnitErrorCode = 'UNKNOWN_LEVEL' | 'MALFORMED' | 'EMPTY_CHAIN' | 'DUPLICATE_LEVEL' | 'NOT_FINITE' | 'UNKNOWN_ROW';
|
|
2
|
+
export declare class UnitError extends Error {
|
|
3
|
+
readonly code: UnitErrorCode;
|
|
4
|
+
readonly detail: Readonly<Record<string, unknown>>;
|
|
5
|
+
constructor(code: UnitErrorCode, message: string, detail?: Record<string, unknown>);
|
|
6
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class UnitError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
detail;
|
|
4
|
+
constructor(code, message, detail = {}) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'UnitError';
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.detail = Object.freeze({ ...detail });
|
|
9
|
+
Object.setPrototypeOf(this, UnitError.prototype);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Lattice, Poset } from './lattice.ts';
|
|
2
|
+
import { WideMask } from '../debit/masks.ts';
|
|
3
|
+
import type { Unit } from './types.ts';
|
|
4
|
+
export interface Interval {
|
|
5
|
+
readonly lo: number;
|
|
6
|
+
readonly hi: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function intervals(lo: number, hi: number): Lattice<Interval>;
|
|
9
|
+
export interface Alphabet {
|
|
10
|
+
readonly polarity: 'permit' | 'forbid';
|
|
11
|
+
readonly values: ReadonlySet<string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function alphabets(): Poset<Alphabet>;
|
|
14
|
+
export type FormCount = {
|
|
15
|
+
readonly kind: 'finite';
|
|
16
|
+
readonly n: number;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'refused';
|
|
19
|
+
readonly why: string;
|
|
20
|
+
};
|
|
21
|
+
export interface Form<T = unknown> {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
lattice(params: unknown): Lattice<T>;
|
|
24
|
+
parse(params: unknown, demand: unknown): T;
|
|
25
|
+
emit(params: unknown, value: T): unknown;
|
|
26
|
+
count(folded: T, params?: unknown): FormCount;
|
|
27
|
+
show(value: T): string;
|
|
28
|
+
points(params: unknown, seed: number, n: number): readonly T[];
|
|
29
|
+
}
|
|
30
|
+
export declare const ladderForm: Form<Unit>;
|
|
31
|
+
export declare const alphabetForm: Form<WideMask>;
|
|
32
|
+
export declare const continuousForm: Form<{
|
|
33
|
+
lo: number;
|
|
34
|
+
hi: number;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const latticeForm: Form<Unit>;
|
|
37
|
+
export declare const FORM_IMPLEMENTATIONS: ReadonlyArray<Form>;
|
|
38
|
+
export declare const FORMS: Form<unknown>[];
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { WideMask } from "../debit/masks.js";
|
|
2
|
+
import { fromScale, subsets } from "./scale-lattice.js";
|
|
3
|
+
import { chain, order } from "./order.js";
|
|
4
|
+
export function intervals(lo, hi) {
|
|
5
|
+
const low = Math.min(lo, hi);
|
|
6
|
+
const high = Math.max(lo, hi);
|
|
7
|
+
return {
|
|
8
|
+
bottom: { lo: high, hi: low },
|
|
9
|
+
top: { lo: low, hi: high },
|
|
10
|
+
leq(a, b) {
|
|
11
|
+
if (a.lo > a.hi)
|
|
12
|
+
return true;
|
|
13
|
+
if (b.lo > b.hi)
|
|
14
|
+
return false;
|
|
15
|
+
return b.lo <= a.lo && a.hi <= b.hi;
|
|
16
|
+
},
|
|
17
|
+
meet(a, b) {
|
|
18
|
+
return { lo: Math.max(a.lo, b.lo), hi: Math.min(a.hi, b.hi) };
|
|
19
|
+
},
|
|
20
|
+
join(a, b) {
|
|
21
|
+
if (a.lo > a.hi)
|
|
22
|
+
return b;
|
|
23
|
+
if (b.lo > b.hi)
|
|
24
|
+
return a;
|
|
25
|
+
return { lo: Math.min(a.lo, b.lo), hi: Math.max(a.hi, b.hi) };
|
|
26
|
+
},
|
|
27
|
+
show(x) {
|
|
28
|
+
return x.lo > x.hi ? 'empty' : `${x.lo}..${x.hi}`;
|
|
29
|
+
},
|
|
30
|
+
inhabited(x) {
|
|
31
|
+
return x.lo <= x.hi;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function alphabets() {
|
|
36
|
+
const within = (x, y) => [...x].every((v) => y.has(v));
|
|
37
|
+
return {
|
|
38
|
+
leq(a, b) {
|
|
39
|
+
if (a.polarity === 'permit' && b.polarity === 'permit')
|
|
40
|
+
return within(a.values, b.values);
|
|
41
|
+
if (a.polarity === 'forbid' && b.polarity === 'forbid')
|
|
42
|
+
return within(b.values, a.values);
|
|
43
|
+
if (a.polarity === 'permit')
|
|
44
|
+
return [...a.values].every((v) => !b.values.has(v));
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
show(x) {
|
|
48
|
+
return `${x.polarity === 'forbid' ? 'not:' : ''}${[...x.values].sort().join('|')}`;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function form(f) {
|
|
53
|
+
const held = { lattice: f.lattice, parse: f.parse, emit: f.emit, count: f.count, show: f.show, points: f.points };
|
|
54
|
+
const lacking = Object.entries(held).find(([, fn]) => typeof fn !== 'function');
|
|
55
|
+
if (lacking)
|
|
56
|
+
throw new Error(`form \`${f.id}\` declared no ${lacking[0]}`);
|
|
57
|
+
return f;
|
|
58
|
+
}
|
|
59
|
+
const rec = (x) => x !== null && typeof x === 'object' ? x : {};
|
|
60
|
+
function strings(x) {
|
|
61
|
+
return Array.isArray(x) ? x.map(String) : [];
|
|
62
|
+
}
|
|
63
|
+
const drawn = (seed) => {
|
|
64
|
+
let s = seed >>> 0;
|
|
65
|
+
return () => {
|
|
66
|
+
s = (s + 0x6d2b79f5) >>> 0;
|
|
67
|
+
let t = Math.imul(s ^ (s >>> 15), s | 1);
|
|
68
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
69
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const picked = (draw, xs) => xs[Math.floor(draw() * xs.length)];
|
|
73
|
+
function bandCount(levels, folded) {
|
|
74
|
+
if (levels.length === 0)
|
|
75
|
+
return { kind: 'refused', why: 'a ladder with no levels cannot be counted' };
|
|
76
|
+
const c = chain(levels);
|
|
77
|
+
const f = c.rank(folded.floor);
|
|
78
|
+
const cl = c.rank(folded.ceiling);
|
|
79
|
+
if (!c.leq(f, cl))
|
|
80
|
+
return { kind: 'finite', n: 0 };
|
|
81
|
+
const n = levels.filter((_, i) => c.leq(f, i) && c.leq(i, cl)).length;
|
|
82
|
+
return { kind: 'finite', n };
|
|
83
|
+
}
|
|
84
|
+
const BAND = {
|
|
85
|
+
parse(params, demand) {
|
|
86
|
+
const L = this.lattice(params);
|
|
87
|
+
const d = rec(demand);
|
|
88
|
+
return {
|
|
89
|
+
subject: String(d.subject ?? ''),
|
|
90
|
+
floor: String(d.floor ?? L.top.floor),
|
|
91
|
+
ceiling: String(d.ceiling ?? L.top.ceiling),
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
emit(_params, value) {
|
|
95
|
+
return { subject: value.subject, floor: value.floor, ceiling: value.ceiling };
|
|
96
|
+
},
|
|
97
|
+
count(folded, params) {
|
|
98
|
+
return bandCount(strings(rec(params).levels), folded);
|
|
99
|
+
},
|
|
100
|
+
points(params, seed, n) {
|
|
101
|
+
const L = this.lattice(params);
|
|
102
|
+
const levels = strings(rec(params).levels);
|
|
103
|
+
const draw = drawn(seed);
|
|
104
|
+
const band = (floor, ceiling) => ({ subject: '', floor, ceiling });
|
|
105
|
+
return Array.from({ length: n }, () => {
|
|
106
|
+
const [a, b] = [picked(draw, levels), picked(draw, levels)];
|
|
107
|
+
return [band(a, b), band(b, a)].find((x) => L.inhabited(x)) ?? band(a, a);
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
export const ladderForm = form({
|
|
112
|
+
id: 'ladder',
|
|
113
|
+
lattice(params) {
|
|
114
|
+
const levels = strings(rec(params).levels);
|
|
115
|
+
if (levels.length === 0)
|
|
116
|
+
throw new Error('ladder needs levels');
|
|
117
|
+
return fromScale(chain(levels));
|
|
118
|
+
},
|
|
119
|
+
...BAND,
|
|
120
|
+
show(value) {
|
|
121
|
+
return value.floor === value.ceiling ? value.floor : `${value.floor}..${value.ceiling}`;
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
export const alphabetForm = form({
|
|
125
|
+
id: 'alphabet',
|
|
126
|
+
lattice(params) {
|
|
127
|
+
return subsets(strings(rec(params).tokens));
|
|
128
|
+
},
|
|
129
|
+
parse(params, demand) {
|
|
130
|
+
const tokens = strings(rec(params).tokens);
|
|
131
|
+
const d = rec(demand);
|
|
132
|
+
const want = d.want !== undefined ? strings(d.want) : tokens;
|
|
133
|
+
return WideMask.fromTokens(tokens, new Set(want));
|
|
134
|
+
},
|
|
135
|
+
emit(params, value) {
|
|
136
|
+
return { want: value.members(strings(rec(params).tokens)) };
|
|
137
|
+
},
|
|
138
|
+
count(folded) {
|
|
139
|
+
return { kind: 'finite', n: folded.size() };
|
|
140
|
+
},
|
|
141
|
+
show(value) {
|
|
142
|
+
return `${value.size()}`;
|
|
143
|
+
},
|
|
144
|
+
points(params, seed, n) {
|
|
145
|
+
const tokens = strings(rec(params).tokens);
|
|
146
|
+
const draw = drawn(seed);
|
|
147
|
+
return Array.from({ length: n }, () => WideMask.fromTokens(tokens, new Set(tokens.filter(() => draw() < 0.5))));
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
export const continuousForm = form({
|
|
151
|
+
id: 'continuous',
|
|
152
|
+
lattice(params) {
|
|
153
|
+
const p = rec(params);
|
|
154
|
+
return intervals(Number(p.lo ?? 0), Number(p.hi ?? 1));
|
|
155
|
+
},
|
|
156
|
+
parse(params, demand) {
|
|
157
|
+
const L = this.lattice(params);
|
|
158
|
+
const d = rec(demand);
|
|
159
|
+
return {
|
|
160
|
+
lo: d.lo === undefined ? L.top.lo : Number(d.lo),
|
|
161
|
+
hi: d.hi === undefined ? L.top.hi : Number(d.hi),
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
emit(_params, value) {
|
|
165
|
+
return { lo: value.lo, hi: value.hi };
|
|
166
|
+
},
|
|
167
|
+
count() {
|
|
168
|
+
return { kind: 'refused', why: 'a continuous band has no count; prefer not to exist over inventing one' };
|
|
169
|
+
},
|
|
170
|
+
show(value) {
|
|
171
|
+
return value.lo > value.hi ? 'empty' : `${value.lo}..${value.hi}`;
|
|
172
|
+
},
|
|
173
|
+
points(params, seed, n) {
|
|
174
|
+
const p = rec(params);
|
|
175
|
+
const lo = Number(p.lo ?? 0);
|
|
176
|
+
const hi = Number(p.hi ?? 1);
|
|
177
|
+
const draw = drawn(seed);
|
|
178
|
+
const at = () => lo + Math.round(draw() * (hi - lo));
|
|
179
|
+
return Array.from({ length: n }, () => ({ lo: at(), hi: at() }));
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
export const latticeForm = form({
|
|
183
|
+
id: 'lattice',
|
|
184
|
+
lattice(params) {
|
|
185
|
+
const p = rec(params);
|
|
186
|
+
const levels = strings(p.levels);
|
|
187
|
+
const leq = p.leq;
|
|
188
|
+
if (levels.length && leq)
|
|
189
|
+
return fromScale(order(levels, leq));
|
|
190
|
+
throw new Error('lattice needs levels+leq');
|
|
191
|
+
},
|
|
192
|
+
...BAND,
|
|
193
|
+
show(value) {
|
|
194
|
+
return `${value.floor}..${value.ceiling}`;
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
export const FORM_IMPLEMENTATIONS = [ladderForm, alphabetForm, continuousForm, latticeForm];
|
|
198
|
+
export const FORMS = [...FORM_IMPLEMENTATIONS];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export { UnitError } from './errors.ts';
|
|
2
|
+
export type { UnitErrorCode } from './errors.ts';
|
|
3
|
+
export { BOOLEAN, chain, height, isDistributive, order } from './order.ts';
|
|
4
|
+
export { asBoolean, bitLoss, compose, composeState, fuse, widen, conflictDebits, anyOf, missing, entails, permitAll, state, statesPerDebit, table, unit } from '../debit/unit.ts';
|
|
5
|
+
export { WIDTH, and, or, canonical } from '../debit/packed.ts';
|
|
6
|
+
export type { Packed, Packer } from '../debit/packed.ts';
|
|
7
|
+
export { WideMask, chunkCount } from '../debit/masks.ts';
|
|
8
|
+
export { rebuild, register } from '../debit/register.ts';
|
|
9
|
+
export type { Register } from '../debit/register.ts';
|
|
10
|
+
export { DANGEROUS, STATES, dangerous, moved, quadrants, runQuadrants, sizes, stateAt, transitions } from '../debit/vector.ts';
|
|
11
|
+
export type { Matrix, Quadrants, Run, Span } from '../debit/vector.ts';
|
|
12
|
+
export { METHODS, weakest } from '../debit/provenance.ts';
|
|
13
|
+
export { touches, holds } from '../debit/standing.ts';
|
|
14
|
+
export { declaration, asUnit, conj, disj } from './declaration.ts';
|
|
15
|
+
export type { Declaration } from './declaration.ts';
|
|
16
|
+
export { relate } from './lattice.ts';
|
|
17
|
+
export type { Poset, MeetSemilattice, JoinSemilattice, Lattice, Relation } from './lattice.ts';
|
|
18
|
+
export { intervals, alphabets } from './forms.ts';
|
|
19
|
+
export type { Interval, Alphabet } from './forms.ts';
|
|
20
|
+
export { foldIn, witnessesIn } from '../debit/debit.ts';
|
|
21
|
+
export { foldSigned } from '../field/signatures.ts';
|
|
22
|
+
export { size, sufficientResolution } from '../field/field.ts';
|
|
23
|
+
export { present, converge, endsBeforeNow } from '../field/present.ts';
|
|
24
|
+
export { yieldOf } from '../field/yield.ts';
|
|
25
|
+
export type { Act, Yield } from '../field/yield.ts';
|
|
26
|
+
export { frontier } from '../field/frontier.ts';
|
|
27
|
+
export type { Asked, Open } from '../field/frontier.ts';
|
|
28
|
+
export { declarationOf, unitOf, stateOf, registerOf, premiumOf, degenerate, withdrawsExactly, movesOf } from '../field/motion.ts';
|
|
29
|
+
export { violationsIn, meetViolationsIn, posetViolationsIn, closureViolationsIn, LATTICE_LAW_NAMES, POSET_LAW_NAMES, MEET_LAW_NAMES, JOIN_LAW_NAMES, BOTH_LAW_NAMES, CLOSURE_LAW_NAMES, } from './axioms.ts';
|
|
30
|
+
export type { LatticeLawName } from './axioms.ts';
|
|
31
|
+
export { fromScale, subsets } from './scale-lattice.ts';
|
|
32
|
+
export { downset, freedom, fromIdeals, idealComplexity, idealDebit, idealEntails, idealJoin, idealMeet, isDownset, isIdealPair, isUpset, unitToIdeal, upset } from '../debit/ideal.ts';
|
|
33
|
+
export type { IdealDebit } from '../debit/ideal.ts';
|
|
34
|
+
export { FORM_IMPLEMENTATIONS, FORMS, ladderForm, alphabetForm, continuousForm, latticeForm } from './forms.ts';
|
|
35
|
+
export type { Form, FormCount } from './forms.ts';
|
|
36
|
+
export { buildGraph, reachIds } from '../debit/graph.ts';
|
|
37
|
+
export type { Graph } from '../debit/graph.ts';
|
|
38
|
+
export { isMonotone, vacuityOf } from './vacuity.ts';
|
|
39
|
+
export type { Verdict, VacuityOptions } from './vacuity.ts';
|
|
40
|
+
export { permute, permutationBlind, unitStream } from '../debit/shuffle.ts';
|
|
41
|
+
export type { BoolView, Scale, Edge, Level, Method, MeasureForm, DebitOutcome, State, Unit, } from './types.ts';
|
|
42
|
+
export { answers, coarsen, coordinate, contracts, covers, exclusive, foldRegion, key, outranks, passes, point, region, resolution, retracted, verified, within } from '../field/field.ts';
|
|
43
|
+
export { disagree, latest, meetAt, origins, potential, turned } from '../field/encounter.ts';
|
|
44
|
+
export type { Fold, Point, Region, Sighting } from '../field/field.ts';
|
|
45
|
+
export { replay } from '../replay.ts';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { UnitError } from "./errors.js";
|
|
2
|
+
export { BOOLEAN, chain, height, isDistributive, order } from "./order.js";
|
|
3
|
+
export { asBoolean, bitLoss, compose, composeState, fuse, widen, conflictDebits, anyOf, missing, entails, permitAll, state, statesPerDebit, table, unit } from "../debit/unit.js";
|
|
4
|
+
export { WIDTH, and, or, canonical } from "../debit/packed.js";
|
|
5
|
+
export { WideMask, chunkCount } from "../debit/masks.js";
|
|
6
|
+
export { rebuild, register } from "../debit/register.js";
|
|
7
|
+
export { DANGEROUS, STATES, dangerous, moved, quadrants, runQuadrants, sizes, stateAt, transitions } from "../debit/vector.js";
|
|
8
|
+
export { METHODS, weakest } from "../debit/provenance.js";
|
|
9
|
+
export { touches, holds } from "../debit/standing.js";
|
|
10
|
+
export { declaration, asUnit, conj, disj } from "./declaration.js";
|
|
11
|
+
export { relate } from "./lattice.js";
|
|
12
|
+
export { intervals, alphabets } from "./forms.js";
|
|
13
|
+
export { foldIn, witnessesIn } from "../debit/debit.js";
|
|
14
|
+
export { foldSigned } from "../field/signatures.js";
|
|
15
|
+
export { size, sufficientResolution } from "../field/field.js";
|
|
16
|
+
export { present, converge, endsBeforeNow } from "../field/present.js";
|
|
17
|
+
export { yieldOf } from "../field/yield.js";
|
|
18
|
+
export { frontier } from "../field/frontier.js";
|
|
19
|
+
export { declarationOf, unitOf, stateOf, registerOf, premiumOf, degenerate, withdrawsExactly, movesOf } from "../field/motion.js";
|
|
20
|
+
export { violationsIn, meetViolationsIn, posetViolationsIn, closureViolationsIn, LATTICE_LAW_NAMES, POSET_LAW_NAMES, MEET_LAW_NAMES, JOIN_LAW_NAMES, BOTH_LAW_NAMES, CLOSURE_LAW_NAMES, } from "./axioms.js";
|
|
21
|
+
export { fromScale, subsets } from "./scale-lattice.js";
|
|
22
|
+
export { downset, freedom, fromIdeals, idealComplexity, idealDebit, idealEntails, idealJoin, idealMeet, isDownset, isIdealPair, isUpset, unitToIdeal, upset } from "../debit/ideal.js";
|
|
23
|
+
export { FORM_IMPLEMENTATIONS, FORMS, ladderForm, alphabetForm, continuousForm, latticeForm } from "./forms.js";
|
|
24
|
+
export { buildGraph, reachIds } from "../debit/graph.js";
|
|
25
|
+
export { isMonotone, vacuityOf } from "./vacuity.js";
|
|
26
|
+
export { permute, permutationBlind, unitStream } from "../debit/shuffle.js";
|
|
27
|
+
export { answers, coarsen, coordinate, contracts, covers, exclusive, foldRegion, key, outranks, passes, point, region, resolution, retracted, verified, within } from "../field/field.js";
|
|
28
|
+
export { disagree, latest, meetAt, origins, potential, turned } from "../field/encounter.js";
|
|
29
|
+
export { replay } from "../replay.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Poset<T> {
|
|
2
|
+
leq(a: T, b: T): boolean;
|
|
3
|
+
show(x: T): string;
|
|
4
|
+
}
|
|
5
|
+
export interface MeetSemilattice<T> extends Poset<T> {
|
|
6
|
+
readonly top: T;
|
|
7
|
+
meet(a: T, b: T): T;
|
|
8
|
+
inhabited(x: T): boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface JoinSemilattice<T> extends Poset<T> {
|
|
11
|
+
readonly bottom: T;
|
|
12
|
+
join(a: T, b: T): T;
|
|
13
|
+
}
|
|
14
|
+
export interface Lattice<T> extends MeetSemilattice<T>, JoinSemilattice<T> {
|
|
15
|
+
}
|
|
16
|
+
export declare function eq<T>(L: Poset<T>, a: T, b: T): boolean;
|
|
17
|
+
export type Relation = 'equal' | 'narrower' | 'wider' | 'incomparable';
|
|
18
|
+
export declare function relate<T>(L: Poset<T>, a: T, b: T): Relation;
|