@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,55 @@
|
|
|
1
|
+
import { unitStream } from "../debit/shuffle.js";
|
|
2
|
+
export function isMonotone(c, value) {
|
|
3
|
+
for (let a = 0; a < c.levels.length; a++) {
|
|
4
|
+
for (let b = 0; b < c.levels.length; b++) {
|
|
5
|
+
if (c.leq(a, b) && value(a) > value(b) + 1e-12)
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
export function vacuityOf(predicate, structure, c, test, opts = {}) {
|
|
12
|
+
const samples = opts.samples ?? 2000;
|
|
13
|
+
const spread = opts.spread ?? 20;
|
|
14
|
+
const next = unitStream(1);
|
|
15
|
+
const n = c.levels.length;
|
|
16
|
+
let yes = 0;
|
|
17
|
+
let no = 0;
|
|
18
|
+
let sawYes;
|
|
19
|
+
let sawNo;
|
|
20
|
+
let read = false;
|
|
21
|
+
for (let i = 0; i < samples; i++) {
|
|
22
|
+
const v = [];
|
|
23
|
+
for (let k = 0; k < n; k++)
|
|
24
|
+
v.push(Math.round(next() * spread));
|
|
25
|
+
if (opts.monotone) {
|
|
26
|
+
v.sort((a, b) => a - b);
|
|
27
|
+
if (!isMonotone(c, (x) => v[x]))
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const probe = (x) => {
|
|
31
|
+
read = true;
|
|
32
|
+
return v[x];
|
|
33
|
+
};
|
|
34
|
+
if (test(c, probe)) {
|
|
35
|
+
yes += 1;
|
|
36
|
+
if (!sawYes)
|
|
37
|
+
sawYes = [...v];
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
no += 1;
|
|
41
|
+
if (!sawNo)
|
|
42
|
+
sawNo = [...v];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const both = yes > 0 && no > 0;
|
|
46
|
+
return {
|
|
47
|
+
predicate,
|
|
48
|
+
structure,
|
|
49
|
+
samples: yes + no,
|
|
50
|
+
yes,
|
|
51
|
+
no,
|
|
52
|
+
verdict: both ? 'DISCRIMINATES' : read ? 'CONSTANT' : 'INDEPENDENT',
|
|
53
|
+
...(both ? { witnesses: { yes: sawYes, no: sawNo } } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
package/dist/replay.d.ts
ADDED
package/dist/replay.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { downset, freedom, unitToIdeal, upset } from '../debit/ideal.ts';
|
|
2
|
+
export { weakest } from '../debit/provenance.ts';
|
|
3
|
+
export { anyOf, missing } from '../debit/unit-span.ts';
|
|
4
|
+
export { composeState, conflictDebits, entails, unit } from '../debit/unit.ts';
|
|
5
|
+
export { coarsen, foldRegion, size, sufficientResolution } from '../field/field.ts';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { downset, freedom, unitToIdeal, upset } from "../debit/ideal.js";
|
|
2
|
+
export { weakest } from "../debit/provenance.js";
|
|
3
|
+
export { anyOf, missing } from "../debit/unit-span.js";
|
|
4
|
+
export { composeState, conflictDebits, entails, unit } from "../debit/unit.js";
|
|
5
|
+
export { coarsen, foldRegion, size, sufficientResolution } from "../field/field.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Lattice } from '../../lattice/lattice.ts';
|
|
2
|
+
import type { Claim, Obligatory } from '../../lattice/obligatory.ts';
|
|
3
|
+
type Band = {
|
|
4
|
+
readonly lo: number;
|
|
5
|
+
readonly hi: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function disturbance(lattice: Lattice<Band>, one: Obligatory<Band>, claim: Claim<Band>): number;
|
|
8
|
+
export declare function budget(cells: number, resolution: number): number;
|
|
9
|
+
export declare function sameObject(lattice: Lattice<Band>, a: Obligatory<Band>, b: Obligatory<Band>, width: number): boolean;
|
|
10
|
+
export declare function distinct(lattice: Lattice<Band>, world: readonly Obligatory<Band>[], width: number): number;
|
|
11
|
+
export declare function evolve(world: readonly Obligatory<Band>[], epochs: number, budget_: number, seed: number): readonly (readonly Obligatory<Band>[])[];
|
|
12
|
+
export declare function decohere(claims: readonly Claim<Band>[], environment: number, period: number): number;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { meet } from "../../lattice/obligatory.js";
|
|
2
|
+
import { coherence } from "./wave.js";
|
|
3
|
+
export function disturbance(lattice, one, claim) {
|
|
4
|
+
const was = meet(lattice, one);
|
|
5
|
+
const now = meet(lattice, { ...one, seen: [...one.seen, claim] });
|
|
6
|
+
const width = (span) => Math.max(0, span.hi - span.lo);
|
|
7
|
+
return width(was) - width(now);
|
|
8
|
+
}
|
|
9
|
+
export function budget(cells, resolution) {
|
|
10
|
+
if (resolution <= 0)
|
|
11
|
+
throw new Error('obligations: REFUSE·budget a region read at no resolution has no budget to take');
|
|
12
|
+
return Math.ceil((2 * cells) / resolution);
|
|
13
|
+
}
|
|
14
|
+
export function sameObject(lattice, a, b, width) {
|
|
15
|
+
const bin = (one) => {
|
|
16
|
+
const held = meet(lattice, one);
|
|
17
|
+
return width <= 0 ? held.lo : Math.round(held.lo / width);
|
|
18
|
+
};
|
|
19
|
+
return bin(a) === bin(b);
|
|
20
|
+
}
|
|
21
|
+
export function distinct(lattice, world, width) {
|
|
22
|
+
const seen = new Set();
|
|
23
|
+
for (const one of world) {
|
|
24
|
+
const held = meet(lattice, one);
|
|
25
|
+
seen.add(width <= 0 ? held.lo : Math.round(held.lo / width));
|
|
26
|
+
}
|
|
27
|
+
return seen.size;
|
|
28
|
+
}
|
|
29
|
+
export function evolve(world, epochs, budget_, seed) {
|
|
30
|
+
let held = seed;
|
|
31
|
+
const next = () => { held = (held * 1103515245 + 12345) % 2147483648; return held / 2147483648; };
|
|
32
|
+
const out = [];
|
|
33
|
+
let now = world;
|
|
34
|
+
for (let epoch = 1; epoch <= epochs; epoch += 1) {
|
|
35
|
+
for (let k = 0; k < budget_; k += 1) {
|
|
36
|
+
const weight = now.map((one) => 1 + 20 * one.seen.length);
|
|
37
|
+
const total = weight.reduce((sum, w) => sum + w, 0);
|
|
38
|
+
const where = () => {
|
|
39
|
+
let pick = next() * total;
|
|
40
|
+
let at = 0;
|
|
41
|
+
while (pick > weight[at] && at < now.length - 1) {
|
|
42
|
+
pick -= weight[at];
|
|
43
|
+
at += 1;
|
|
44
|
+
}
|
|
45
|
+
return at;
|
|
46
|
+
};
|
|
47
|
+
const i = where();
|
|
48
|
+
let j = where();
|
|
49
|
+
if (j === i)
|
|
50
|
+
j = (j + 1) % now.length;
|
|
51
|
+
const name = `e${epoch}-${k}`;
|
|
52
|
+
now = now.map((one, at) => (at === i || at === j ? { ...one, epoch, seen: [...one.seen, { id: `${name}-${at}`, origin: name, at: epoch, span: { lo: 0, hi: 100 } }] } : one));
|
|
53
|
+
}
|
|
54
|
+
out.push(now);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
export function decohere(claims, environment, period) {
|
|
59
|
+
const about = claims.map((claim, i) => ({ ...claim, epoch: claim.at ?? 0, origin: claim.origin || `o${i}` }));
|
|
60
|
+
const noise = Array.from({ length: environment }, (_, i) => ({
|
|
61
|
+
origin: `n${i}`, span: { lo: 0, hi: 1 }, epoch: i % Math.max(1, period), at: i % Math.max(1, period),
|
|
62
|
+
}));
|
|
63
|
+
return coherence([...about, ...noise].map((claim) => ({ origin: claim.origin, epoch: claim.epoch, span: claim.span })), period);
|
|
64
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Lattice } from '../../lattice/lattice.ts';
|
|
2
|
+
import type { Obligatory } from '../../lattice/obligatory.ts';
|
|
3
|
+
type Band = {
|
|
4
|
+
readonly lo: number;
|
|
5
|
+
readonly hi: number;
|
|
6
|
+
};
|
|
7
|
+
export interface Weights {
|
|
8
|
+
readonly reach: number;
|
|
9
|
+
readonly coherence: number;
|
|
10
|
+
readonly rank: number;
|
|
11
|
+
readonly bits: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function choose(lattice: Lattice<Band>, world: readonly Obligatory<Band>[], weights: Weights, held: ReadonlySet<string>): string;
|
|
14
|
+
export declare function play(lattice: Lattice<Band>, world: readonly Obligatory<Band>[], weights: Weights, epochs: number, seed: number, spread: number): {
|
|
15
|
+
readonly closed: number;
|
|
16
|
+
readonly forks: number;
|
|
17
|
+
readonly reopened: number;
|
|
18
|
+
readonly coverage: number;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { encounter, meet } from "../../lattice/obligatory.js";
|
|
2
|
+
import { coherence } from "./wave.js";
|
|
3
|
+
import { neighbours, reach } from "../product/reach.js";
|
|
4
|
+
const at = (cell) => cell.at.join('/');
|
|
5
|
+
const said = (lattice, cell) => {
|
|
6
|
+
const held = meet(lattice, cell);
|
|
7
|
+
if (encounter(lattice, cell).origins < 2)
|
|
8
|
+
return 'one';
|
|
9
|
+
return held.lo > held.hi ? 'apart' : 'together';
|
|
10
|
+
};
|
|
11
|
+
const widthOf = (lattice, cell) => {
|
|
12
|
+
const held = meet(lattice, cell);
|
|
13
|
+
return Math.max(0, held.hi - held.lo);
|
|
14
|
+
};
|
|
15
|
+
export function choose(lattice, world, weights, held) {
|
|
16
|
+
let best = '';
|
|
17
|
+
let top;
|
|
18
|
+
for (const cell of world) {
|
|
19
|
+
const name = at(cell);
|
|
20
|
+
if (held.has(name))
|
|
21
|
+
continue;
|
|
22
|
+
const said = cell.seen.map((claim, i) => ({ origin: claim.origin, epoch: claim.at ?? i, span: claim.span }));
|
|
23
|
+
const score = weights.reach * reach(world, name)
|
|
24
|
+
+ weights.coherence * coherence(said, 8)
|
|
25
|
+
+ weights.rank * (neighbours(world).get(name) ?? []).length
|
|
26
|
+
+ weights.bits * Math.log2(1 + widthOf(lattice, cell));
|
|
27
|
+
if (top === undefined || score > top) {
|
|
28
|
+
top = score;
|
|
29
|
+
best = name;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return best;
|
|
33
|
+
}
|
|
34
|
+
export function play(lattice, world, weights, epochs, seed, spread) {
|
|
35
|
+
let held = seed;
|
|
36
|
+
const next = () => { held = (held * 1103515245 + 12345) % 2147483648; return held / 2147483648; };
|
|
37
|
+
let now = [...world];
|
|
38
|
+
const closed = new Set();
|
|
39
|
+
const forked = new Set();
|
|
40
|
+
let reopened = 0;
|
|
41
|
+
for (let epoch = 1; epoch <= epochs; epoch += 1) {
|
|
42
|
+
const name = choose(lattice, now, weights, new Set());
|
|
43
|
+
if (!name)
|
|
44
|
+
break;
|
|
45
|
+
now = now.map((cell) => {
|
|
46
|
+
if (at(cell) !== name)
|
|
47
|
+
return cell;
|
|
48
|
+
const was = said(lattice, cell);
|
|
49
|
+
const held = meet(lattice, cell);
|
|
50
|
+
const centre = (held.lo + held.hi) / 2 + (next() * 2 - 1) * spread;
|
|
51
|
+
const one = { id: `p${epoch}`, origin: `p${epoch}`, at: epoch, span: { lo: centre - 5, hi: centre + 5 } };
|
|
52
|
+
const after = { ...cell, epoch, seen: [...cell.seen, one] };
|
|
53
|
+
const verdict = said(lattice, after);
|
|
54
|
+
if (verdict === 'together' && was !== 'together')
|
|
55
|
+
closed.add(name);
|
|
56
|
+
if (verdict === 'apart') {
|
|
57
|
+
forked.add(name);
|
|
58
|
+
if (closed.has(name)) {
|
|
59
|
+
reopened += 1;
|
|
60
|
+
closed.delete(name);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return after;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const covered = now.filter((cell) => encounter(lattice, cell).origins > 1).length;
|
|
67
|
+
return { closed: closed.size, forks: forked.size, reopened, coverage: Math.round((100 * covered) / now.length) };
|
|
68
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Obligatory } from '../../lattice/obligatory.ts';
|
|
2
|
+
import type { Lattice } from '../../lattice/lattice.ts';
|
|
3
|
+
type Band = {
|
|
4
|
+
readonly lo: number;
|
|
5
|
+
readonly hi: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function selfFold(lattice: Lattice<Band>, one: Obligatory<Band>, epochs: number, width: number, spread: number, seed: number): readonly Obligatory<Band>[];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { meet, observe } from "../../lattice/obligatory.js";
|
|
2
|
+
export function selfFold(lattice, one, epochs, width, spread, seed) {
|
|
3
|
+
let held = seed;
|
|
4
|
+
const next = () => { held = (held * 1103515245 + 12345) % 2147483648; return held / 2147483648; };
|
|
5
|
+
const out = [];
|
|
6
|
+
let now = one;
|
|
7
|
+
for (let epoch = 1; epoch <= epochs; epoch += 1) {
|
|
8
|
+
const at = meet(lattice, now);
|
|
9
|
+
const centre = (at.lo + at.hi) / 2 + (next() * 2 - 1) * spread;
|
|
10
|
+
now = observe(now, { origin: `self${epoch}`, at: epoch, span: { lo: centre - width / 2, hi: centre + width / 2 } });
|
|
11
|
+
out.push(now);
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Point } from '../../field/field.ts';
|
|
2
|
+
export interface Claim {
|
|
3
|
+
readonly origin: string;
|
|
4
|
+
readonly epoch: number;
|
|
5
|
+
readonly span: {
|
|
6
|
+
readonly lo: number;
|
|
7
|
+
readonly hi: number;
|
|
8
|
+
};
|
|
9
|
+
readonly withdraws?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function amplitude(claim: Claim): number;
|
|
12
|
+
export declare function phase(claim: Claim, period: number): number;
|
|
13
|
+
export declare function coherence(claims: readonly Claim[], period: number): number;
|
|
14
|
+
export declare function interfere(claims: readonly Claim[], period: number): number;
|
|
15
|
+
export declare function fringes(claims: readonly Claim[], period: number, delays: readonly number[]): readonly number[];
|
|
16
|
+
export declare const seenAs: (cell: Point, period: number) => readonly Claim[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function amplitude(claim) {
|
|
2
|
+
const size = claim.span.hi - claim.span.lo;
|
|
3
|
+
const width = Number.isFinite(size) ? 1 / (1 + Math.max(size, 0)) : 0;
|
|
4
|
+
return claim.withdraws ? -width : width;
|
|
5
|
+
}
|
|
6
|
+
export function phase(claim, period) {
|
|
7
|
+
return period <= 0 ? 0 : ((claim.epoch % period) + period) % period;
|
|
8
|
+
}
|
|
9
|
+
export function coherence(claims, period) {
|
|
10
|
+
if (!claims.length)
|
|
11
|
+
return 0;
|
|
12
|
+
let x = 0;
|
|
13
|
+
let y = 0;
|
|
14
|
+
for (const claim of claims) {
|
|
15
|
+
const turn = (2 * Math.PI * phase(claim, period)) / period;
|
|
16
|
+
x += Math.cos(turn);
|
|
17
|
+
y += Math.sin(turn);
|
|
18
|
+
}
|
|
19
|
+
return Math.sqrt(x * x + y * y) / claims.length;
|
|
20
|
+
}
|
|
21
|
+
export function interfere(claims, period) {
|
|
22
|
+
let x = 0;
|
|
23
|
+
let y = 0;
|
|
24
|
+
for (const claim of claims) {
|
|
25
|
+
const turn = (2 * Math.PI * phase(claim, period)) / period;
|
|
26
|
+
x += amplitude(claim) * Math.cos(turn);
|
|
27
|
+
y += amplitude(claim) * Math.sin(turn);
|
|
28
|
+
}
|
|
29
|
+
return Math.sqrt(x * x + y * y) ** 2;
|
|
30
|
+
}
|
|
31
|
+
export function fringes(claims, period, delays) {
|
|
32
|
+
return delays.map((delay) => interfere(claims.map((claim, i) => (i % 2 === 0 ? claim : { ...claim, epoch: claim.epoch + delay })), period));
|
|
33
|
+
}
|
|
34
|
+
export const seenAs = (cell, period) => cell.seen.map((s) => ({ origin: s.origin, epoch: cell.epoch, span: s.span }));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { foldIn, witnessesIn } from '../debit/debit.ts';
|
|
2
|
+
export { disagree, latest, meetAt, origins, potential, turned } from '../field/encounter.ts';
|
|
3
|
+
export { contracts, coordinate, covers, exclusive, key, passes, point, region, resolution, within } from '../field/field.ts';
|
|
4
|
+
export { converge, endsBeforeNow, present } from '../field/present.ts';
|
|
5
|
+
export { amplitude, coherence, fringes, interfere, phase, seenAs } from './field/wave.ts';
|
|
6
|
+
export type { Claim } from './field/wave.ts';
|
|
7
|
+
export { cell, encounter, join, meet, observe, refine, sign } from '../lattice/obligatory.ts';
|
|
8
|
+
export type { Obligatory } from '../lattice/obligatory.ts';
|
|
9
|
+
export { budget, decohere, disturbance, distinct, evolve, sameObject } from './field/physics.ts';
|
|
10
|
+
export { choose, play } from './field/policy.ts';
|
|
11
|
+
export { selfFold } from './field/self.ts';
|
|
12
|
+
export type { Weights } from './field/policy.ts';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { foldIn, witnessesIn } from "../debit/debit.js";
|
|
2
|
+
export { disagree, latest, meetAt, origins, potential, turned } from "../field/encounter.js";
|
|
3
|
+
export { contracts, coordinate, covers, exclusive, key, passes, point, region, resolution, within } from "../field/field.js";
|
|
4
|
+
export { converge, endsBeforeNow, present } from "../field/present.js";
|
|
5
|
+
export { amplitude, coherence, fringes, interfere, phase, seenAs } from "./field/wave.js";
|
|
6
|
+
export { cell, encounter, join, meet, observe, refine, sign } from "../lattice/obligatory.js";
|
|
7
|
+
export { budget, decohere, disturbance, distinct, evolve, sameObject } from "./field/physics.js";
|
|
8
|
+
export { choose, play } from "./field/policy.js";
|
|
9
|
+
export { selfFold } from "./field/self.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { fromIdeals, idealComplexity, idealDebit, idealEntails, idealJoin, idealMeet, isDownset, isIdealPair, isUpset, unitComplexity } from '../debit/ideal.ts';
|
|
2
|
+
export { packer } from '../debit/packed.ts';
|
|
3
|
+
export { rebuild, register } from '../debit/register.ts';
|
|
4
|
+
export { holds, touches } from '../debit/standing.ts';
|
|
5
|
+
export { complexity, statesPerDebit } from '../debit/unit-span.ts';
|
|
6
|
+
export { permitAll, state, table, widen } from '../debit/unit.ts';
|
|
7
|
+
export { dangerous, moved, transitions } from '../debit/vector-move.ts';
|
|
8
|
+
export { quadrants, runQuadrants, stateAt } from '../debit/vector.ts';
|
|
9
|
+
export { closureViolationsIn } from '../lattice/axioms.ts';
|
|
10
|
+
export { isDistributive } from '../lattice/order.ts';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { fromIdeals, idealComplexity, idealDebit, idealEntails, idealJoin, idealMeet, isDownset, isIdealPair, isUpset, unitComplexity } from "../debit/ideal.js";
|
|
2
|
+
export { packer } from "../debit/packed.js";
|
|
3
|
+
export { rebuild, register } from "../debit/register.js";
|
|
4
|
+
export { holds, touches } from "../debit/standing.js";
|
|
5
|
+
export { complexity, statesPerDebit } from "../debit/unit-span.js";
|
|
6
|
+
export { permitAll, state, table, widen } from "../debit/unit.js";
|
|
7
|
+
export { dangerous, moved, transitions } from "../debit/vector-move.js";
|
|
8
|
+
export { quadrants, runQuadrants, stateAt } from "../debit/vector.js";
|
|
9
|
+
export { closureViolationsIn } from "../lattice/axioms.js";
|
|
10
|
+
export { isDistributive } from "../lattice/order.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Obligatory } from '../../lattice/obligatory.ts';
|
|
2
|
+
type Band = {
|
|
3
|
+
readonly lo: number;
|
|
4
|
+
readonly hi: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function horizonTotal(world: readonly Obligatory<Band>[], bounds?: readonly string[]): number;
|
|
7
|
+
export declare function design(world: readonly Obligatory<Band>[], budget: number, bounds?: readonly string[]): readonly (readonly [string, string])[];
|
|
8
|
+
export declare function loom(world: readonly Obligatory<Band>[], epochs: number, budget: number, bounds?: readonly string[]): readonly number[];
|
|
9
|
+
export declare const apart: (world: readonly Obligatory<Band>[], a: string, b: string, bounds?: readonly string[]) => boolean;
|
|
10
|
+
export declare function rank(world: readonly Obligatory<Band>[], bound: string): number;
|
|
11
|
+
export declare const sited: (world: readonly Obligatory<Band>[], sites: readonly (readonly [string, string])[], epoch?: number) => readonly Obligatory<Band>[];
|
|
12
|
+
export declare const lone: (name: string, epoch?: number) => Obligatory<Band>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { neighbours } from "./reach.js";
|
|
2
|
+
import { cell } from "../../lattice/obligatory.js";
|
|
3
|
+
const at = (one) => one.at.join('/');
|
|
4
|
+
const BAND = { lo: 0, hi: 100 };
|
|
5
|
+
function components(world, bounds = []) {
|
|
6
|
+
const graph = neighbours(world, bounds);
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
const out = [];
|
|
9
|
+
for (const one of world.map(at)) {
|
|
10
|
+
if (seen.has(one))
|
|
11
|
+
continue;
|
|
12
|
+
const edge = [one];
|
|
13
|
+
const held = [];
|
|
14
|
+
seen.add(one);
|
|
15
|
+
while (edge.length) {
|
|
16
|
+
const here = edge.pop();
|
|
17
|
+
held.push(here);
|
|
18
|
+
for (const there of graph.get(here) ?? [])
|
|
19
|
+
if (!seen.has(there)) {
|
|
20
|
+
seen.add(there);
|
|
21
|
+
edge.push(there);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
out.push(held);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
export function horizonTotal(world, bounds = []) {
|
|
29
|
+
const sizes = components(world, bounds).map((part) => part.length);
|
|
30
|
+
const all = sizes.reduce((sum, n) => sum + n, 0);
|
|
31
|
+
return sizes.reduce((sum, n) => sum + n * (all - n), 0) / 2;
|
|
32
|
+
}
|
|
33
|
+
export function design(world, budget, bounds = []) {
|
|
34
|
+
const parts = [...components(world, bounds)].sort((a, b) => b.length - a.length);
|
|
35
|
+
const out = [];
|
|
36
|
+
for (let k = 0; k < budget && k + 1 < parts.length; k += 1)
|
|
37
|
+
out.push([parts[0][0], parts[k + 1][0]]);
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const landed = (world, sites, epoch) => {
|
|
41
|
+
const named = new Map();
|
|
42
|
+
for (const [k, [a, b]] of sites.entries()) {
|
|
43
|
+
const name = `d${epoch}-${k}`;
|
|
44
|
+
named.set(a, [...(named.get(a) ?? []), name]);
|
|
45
|
+
named.set(b, [...(named.get(b) ?? []), name]);
|
|
46
|
+
}
|
|
47
|
+
return world.map((one) => {
|
|
48
|
+
const mine = named.get(at(one));
|
|
49
|
+
return mine === undefined ? one : { ...one, epoch, seen: [...one.seen, ...mine.map((origin) => ({ id: `${origin}-${at(one)}`, origin, at: epoch, span: BAND }))] };
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export function loom(world, epochs, budget, bounds = []) {
|
|
53
|
+
let held = world;
|
|
54
|
+
const out = [horizonTotal(held, bounds)];
|
|
55
|
+
for (let epoch = 1; epoch <= epochs; epoch += 1) {
|
|
56
|
+
held = landed(held, design(held, budget, bounds), epoch);
|
|
57
|
+
out.push(horizonTotal(held, bounds));
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
export const apart = (world, a, b, bounds = []) => !components(world, bounds).some((part) => part.includes(a) && part.includes(b));
|
|
62
|
+
export function rank(world, bound) {
|
|
63
|
+
return world.filter((one) => one.seen.some((claim) => claim.origin === bound)).length;
|
|
64
|
+
}
|
|
65
|
+
export const sited = (world, sites, epoch = 1) => landed(world, sites, epoch);
|
|
66
|
+
export const lone = (name, epoch = 0) => cell(name, epoch, [{ id: `own-${name}`, origin: `own-${name}`, at: epoch, span: BAND }]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Interval } from '../../lattice/forms.ts';
|
|
2
|
+
import type { Point } from '../../field/field.ts';
|
|
3
|
+
export type Lock = ReadonlyMap<string, Interval>;
|
|
4
|
+
export declare function stretch(lock: Lock, k: number): Lock;
|
|
5
|
+
export declare function red(world: readonly Point[], lock: Lock): readonly string[];
|
|
6
|
+
export declare function pour(world: readonly Point[], lock: Lock): {
|
|
7
|
+
readonly filled: number;
|
|
8
|
+
readonly of: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function tense(lock: Lock, world: readonly Point[], rate: number): Lock;
|
|
11
|
+
export declare function tighter(before: Lock, after: Lock): {
|
|
12
|
+
readonly tightened: number;
|
|
13
|
+
readonly loosened: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { meetAt } from "../../field/encounter.js";
|
|
2
|
+
const at = (cell) => cell.at.join('/');
|
|
3
|
+
const holds = (bound, held) => held.hi >= held.lo && held.lo >= bound.lo - 1e-12 && held.hi <= bound.hi + 1e-12;
|
|
4
|
+
export function stretch(lock, k) {
|
|
5
|
+
const out = new Map();
|
|
6
|
+
for (const [place, bound] of lock) {
|
|
7
|
+
const middle = (bound.lo + bound.hi) / 2;
|
|
8
|
+
const half = ((bound.hi - bound.lo) / 2) * k;
|
|
9
|
+
out.set(place, { lo: middle - half, hi: middle + half });
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
export function red(world, lock) {
|
|
14
|
+
return world.filter((cell) => {
|
|
15
|
+
const bound = lock.get(at(cell));
|
|
16
|
+
return bound !== undefined && !holds(bound, meetAt(cell));
|
|
17
|
+
}).map(at);
|
|
18
|
+
}
|
|
19
|
+
export function pour(world, lock) {
|
|
20
|
+
const reached = new Set(world.map(at));
|
|
21
|
+
return { filled: [...lock.keys()].filter((place) => reached.has(place)).length, of: lock.size };
|
|
22
|
+
}
|
|
23
|
+
export function tense(lock, world, rate) {
|
|
24
|
+
const seen = new Map();
|
|
25
|
+
for (const cell of world)
|
|
26
|
+
seen.set(at(cell), meetAt(cell));
|
|
27
|
+
const out = new Map();
|
|
28
|
+
for (const [place, bound] of lock) {
|
|
29
|
+
const held = seen.get(place);
|
|
30
|
+
if (held === undefined || held.hi < held.lo) {
|
|
31
|
+
const half = ((bound.hi - bound.lo) / 2) * (1 + rate);
|
|
32
|
+
const middle = (bound.lo + bound.hi) / 2;
|
|
33
|
+
out.set(place, { lo: middle - half, hi: middle + half });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
out.set(place, { lo: bound.lo + (held.lo - bound.lo) * rate, hi: bound.hi - (bound.hi - held.hi) * rate });
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
export function tighter(before, after) {
|
|
41
|
+
let tightened = 0;
|
|
42
|
+
let loosened = 0;
|
|
43
|
+
for (const [place, bound] of before) {
|
|
44
|
+
const now = after.get(place);
|
|
45
|
+
if (now === undefined)
|
|
46
|
+
continue;
|
|
47
|
+
const was = bound.hi - bound.lo;
|
|
48
|
+
const is = now.hi - now.lo;
|
|
49
|
+
if (is < was - 1e-12)
|
|
50
|
+
tightened += 1;
|
|
51
|
+
if (is > was + 1e-12)
|
|
52
|
+
loosened += 1;
|
|
53
|
+
}
|
|
54
|
+
return { tightened, loosened };
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Point } from '../../field/field.ts';
|
|
2
|
+
export type Vertex = readonly [number, number];
|
|
3
|
+
export declare function vertices(cell: Point): readonly Vertex[];
|
|
4
|
+
export declare function hull(cell: Point): readonly Vertex[];
|
|
5
|
+
export declare function area(cell: Point): number;
|
|
6
|
+
export declare function centre(cell: Point): Vertex;
|
|
7
|
+
export declare function outliers(cell: Point): readonly string[];
|
|
8
|
+
export declare function steady(cell: Point): boolean;
|
|
9
|
+
export declare function width(cell: Point): number;
|
|
10
|
+
export declare function density(cell: Point): number;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { disagree, meetAt, origins, potential } from "../../field/encounter.js";
|
|
2
|
+
export function vertices(cell) {
|
|
3
|
+
const held = new Map();
|
|
4
|
+
for (const seen of cell.seen)
|
|
5
|
+
held.set(seen.origin, [seen.span.lo, seen.span.hi]);
|
|
6
|
+
return [...held.values()];
|
|
7
|
+
}
|
|
8
|
+
export function hull(cell) {
|
|
9
|
+
const said = [...vertices(cell)].sort((a, b) => (a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]));
|
|
10
|
+
if (said.length < 3)
|
|
11
|
+
return said;
|
|
12
|
+
const turn = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
13
|
+
const side = (order) => {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const one of order) {
|
|
16
|
+
while (out.length > 1 && turn(out[out.length - 2], out[out.length - 1], one) <= 0)
|
|
17
|
+
out.pop();
|
|
18
|
+
out.push(one);
|
|
19
|
+
}
|
|
20
|
+
out.pop();
|
|
21
|
+
return out;
|
|
22
|
+
};
|
|
23
|
+
return [...side(said), ...side([...said].reverse())];
|
|
24
|
+
}
|
|
25
|
+
export function area(cell) {
|
|
26
|
+
const ring = hull(cell);
|
|
27
|
+
if (ring.length < 3)
|
|
28
|
+
return 0;
|
|
29
|
+
let twice = 0;
|
|
30
|
+
for (let i = 0; i < ring.length; i += 1) {
|
|
31
|
+
const [x1, y1] = ring[i];
|
|
32
|
+
const [x2, y2] = ring[(i + 1) % ring.length];
|
|
33
|
+
twice += x1 * y2 - x2 * y1;
|
|
34
|
+
}
|
|
35
|
+
return Math.abs(twice) / 2;
|
|
36
|
+
}
|
|
37
|
+
export function centre(cell) {
|
|
38
|
+
const said = vertices(cell);
|
|
39
|
+
if (!said.length)
|
|
40
|
+
return [0, 0];
|
|
41
|
+
return [said.reduce((s, v) => s + v[0], 0) / said.length, said.reduce((s, v) => s + v[1], 0) / said.length];
|
|
42
|
+
}
|
|
43
|
+
const without = (cell, origin) => ({ ...cell, seen: cell.seen.filter((s) => s.origin !== origin) });
|
|
44
|
+
export function outliers(cell) {
|
|
45
|
+
if (origins(cell) < 4)
|
|
46
|
+
throw new Error('REFUSE·outliers fewer than four origins enclose no figure a leaving one could shrink');
|
|
47
|
+
const whole = area(cell);
|
|
48
|
+
if (whole === 0)
|
|
49
|
+
throw new Error('REFUSE·outliers the origins lie on one line: the figure has no interior, so none of them is outside it');
|
|
50
|
+
return [...new Set(cell.seen.map((s) => s.origin))].filter((origin) => area(without(cell, origin)) < whole - 1e-12);
|
|
51
|
+
}
|
|
52
|
+
export function steady(cell) {
|
|
53
|
+
if (origins(cell) < 5)
|
|
54
|
+
return false;
|
|
55
|
+
const said = (one) => (potential(one) ? 'one' : disagree(one) ? 'apart' : 'together');
|
|
56
|
+
const held = said(cell);
|
|
57
|
+
return [...new Set(cell.seen.map((s) => s.origin))].every((origin) => said(without(cell, origin)) === held);
|
|
58
|
+
}
|
|
59
|
+
export function width(cell) {
|
|
60
|
+
const held = meetAt(cell);
|
|
61
|
+
return held.hi < held.lo ? 0 : held.hi - held.lo;
|
|
62
|
+
}
|
|
63
|
+
export function density(cell) {
|
|
64
|
+
return origins(cell) === 0 ? 0 : area(cell) / origins(cell);
|
|
65
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Interval } from '../../lattice/forms.ts';
|
|
2
|
+
import type { Point } from '../../field/field.ts';
|
|
3
|
+
export declare function neighbours(world: readonly Point[], bounds?: readonly string[]): ReadonlyMap<string, readonly string[]>;
|
|
4
|
+
export declare function distance(world: readonly Point[], from: string, to: string, bounds?: readonly string[]): number;
|
|
5
|
+
export declare function horizon(world: readonly Point[], from: string, bounds?: readonly string[]): readonly string[];
|
|
6
|
+
export declare function reach(world: readonly Point[], from: string, bounds?: readonly string[]): number;
|
|
7
|
+
export declare function tunnel(world: readonly Point[], places: readonly string[], bounds?: readonly string[]): readonly (readonly [string, string])[];
|
|
8
|
+
export declare function curvature(world: readonly Point[]): number;
|
|
9
|
+
export declare function grow(walls: readonly number[], placed: readonly number[]): readonly {
|
|
10
|
+
readonly at: number;
|
|
11
|
+
readonly width: number;
|
|
12
|
+
}[];
|
|
13
|
+
export declare function entangled(world: readonly Point[], bound: string): readonly string[];
|
|
14
|
+
export declare function resting(world: readonly Point[], bound: string, was: Interval, now: Interval): readonly string[];
|