@toiroakr/chisel 0.0.0-stage → 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/README.md +693 -2
- package/dist/absence.d.ts +27 -0
- package/dist/absence.js +228 -0
- package/dist/absence.js.map +1 -0
- package/dist/behavior.d.ts +193 -0
- package/dist/behavior.js +589 -0
- package/dist/behavior.js.map +1 -0
- package/dist/beside.d.ts +27 -0
- package/dist/beside.js +88 -0
- package/dist/beside.js.map +1 -0
- package/dist/border.d.ts +61 -0
- package/dist/border.js +434 -0
- package/dist/border.js.map +1 -0
- package/dist/bounds.d.ts +1 -0
- package/dist/bounds.js +26 -0
- package/dist/bounds.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +835 -0
- package/dist/cli.js.map +1 -0
- package/dist/codec.d.ts +6 -0
- package/dist/codec.js +86 -0
- package/dist/codec.js.map +1 -0
- package/dist/codegen.d.ts +2 -0
- package/dist/codegen.js +61 -0
- package/dist/codegen.js.map +1 -0
- package/dist/composition.d.ts +38 -0
- package/dist/composition.js +242 -0
- package/dist/composition.js.map +1 -0
- package/dist/data.d.ts +17 -0
- package/dist/data.js +51 -0
- package/dist/data.js.map +1 -0
- package/dist/dependency.d.ts +101 -0
- package/dist/dependency.js +161 -0
- package/dist/dependency.js.map +1 -0
- package/dist/domain.d.ts +12 -0
- package/dist/domain.js +217 -0
- package/dist/domain.js.map +1 -0
- package/dist/ensures.d.ts +15 -0
- package/dist/ensures.js +88 -0
- package/dist/ensures.js.map +1 -0
- package/dist/equal.d.ts +1 -0
- package/dist/equal.js +135 -0
- package/dist/equal.js.map +1 -0
- package/dist/exact.d.ts +21 -0
- package/dist/exact.js +80 -0
- package/dist/exact.js.map +1 -0
- package/dist/feasibility.d.ts +63 -0
- package/dist/feasibility.js +1053 -0
- package/dist/feasibility.js.map +1 -0
- package/dist/guard-borders.d.ts +57 -0
- package/dist/guard-borders.js +760 -0
- package/dist/guard-borders.js.map +1 -0
- package/dist/guard-scope.d.ts +61 -0
- package/dist/guard-scope.js +364 -0
- package/dist/guard-scope.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/interleave.d.ts +31 -0
- package/dist/interleave.js +202 -0
- package/dist/interleave.js.map +1 -0
- package/dist/interval.d.ts +10 -0
- package/dist/interval.js +311 -0
- package/dist/interval.js.map +1 -0
- package/dist/isolated.d.ts +9 -0
- package/dist/isolated.js +41 -0
- package/dist/isolated.js.map +1 -0
- package/dist/machine-check.d.ts +73 -0
- package/dist/machine-check.js +215 -0
- package/dist/machine-check.js.map +1 -0
- package/dist/machine.d.ts +97 -0
- package/dist/machine.js +200 -0
- package/dist/machine.js.map +1 -0
- package/dist/model.d.ts +160 -0
- package/dist/model.js +778 -0
- package/dist/model.js.map +1 -0
- package/dist/outcomes.d.ts +7 -0
- package/dist/outcomes.js +38 -0
- package/dist/outcomes.js.map +1 -0
- package/dist/pairs.d.ts +26 -0
- package/dist/pairs.js +115 -0
- package/dist/pairs.js.map +1 -0
- package/dist/partition.d.ts +45 -0
- package/dist/partition.js +354 -0
- package/dist/partition.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +556 -0
- package/dist/proof.js.map +1 -0
- package/dist/replay.d.ts +45 -0
- package/dist/replay.js +157 -0
- package/dist/replay.js.map +1 -0
- package/dist/report-json.d.ts +11 -0
- package/dist/report-json.js +94 -0
- package/dist/report-json.js.map +1 -0
- package/dist/rule.d.ts +186 -0
- package/dist/rule.js +866 -0
- package/dist/rule.js.map +1 -0
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.js +8 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +163 -0
- package/dist/schema.js +528 -0
- package/dist/schema.js.map +1 -0
- package/dist/specification.d.ts +266 -0
- package/dist/specification.js +2123 -0
- package/dist/specification.js.map +1 -0
- package/dist/temporal-global.d.ts +4 -0
- package/dist/temporal-global.js +11 -0
- package/dist/temporal-global.js.map +1 -0
- package/dist/temporal.d.ts +22 -0
- package/dist/temporal.js +113 -0
- package/dist/temporal.js.map +1 -0
- package/dist/text.d.ts +1 -0
- package/dist/text.js +11 -0
- package/dist/text.js.map +1 -0
- package/dist/tla.d.ts +54 -0
- package/dist/tla.js +579 -0
- package/dist/tla.js.map +1 -0
- package/dist/verification.d.ts +7 -0
- package/dist/verification.js +5 -0
- package/dist/verification.js.map +1 -0
- package/dist/ways.d.ts +28 -0
- package/dist/ways.js +86 -0
- package/dist/ways.js.map +1 -0
- package/dist/world.d.ts +98 -0
- package/dist/world.js +467 -0
- package/dist/world.js.map +1 -0
- package/package.json +76 -4
- package/schema/report.schema.json +1062 -0
package/dist/beside.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type Beside = {
|
|
2
|
+
readonly status: "told";
|
|
3
|
+
} | {
|
|
4
|
+
readonly status: "not told";
|
|
5
|
+
readonly another: string;
|
|
6
|
+
readonly input?: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly status: "undecided";
|
|
9
|
+
readonly reason: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const allOnOneSide = "\u5883\u754C\u306B\u5C4A\u3044\u305F\u884C\u304C\u3059\u3079\u3066\u5883\u754C\u306E\u5916\u5074\u306B\u3042\u308B";
|
|
12
|
+
export interface LineBeside {
|
|
13
|
+
readonly weights: readonly number[];
|
|
14
|
+
readonly cut: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function linesBeside(weights: readonly number[]): readonly (readonly number[])[];
|
|
17
|
+
export declare function lineTheRowsAllow(weights: readonly number[], keptBelow: boolean, kept: readonly (readonly number[])[], refused: readonly (readonly number[])[]): LineBeside | undefined;
|
|
18
|
+
export interface Parting {
|
|
19
|
+
readonly from: number;
|
|
20
|
+
readonly values: readonly number[];
|
|
21
|
+
readonly steps: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function partingsOf(weights: readonly number[], line: LineBeside, keptBelow: boolean, rows: readonly {
|
|
24
|
+
readonly values: readonly number[];
|
|
25
|
+
readonly kept: boolean;
|
|
26
|
+
}[]): readonly Parting[];
|
|
27
|
+
export declare function spelled(paths: readonly string[], line: LineBeside): string;
|
package/dist/beside.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Souther's E1938: a border every point of which has a row may still be the
|
|
2
|
+
// wrong line, turned about its points; a row on the other side of a line beside
|
|
3
|
+
// it tells the two apart.
|
|
4
|
+
export const allOnOneSide = "境界に届いた行がすべて境界の外側にある";
|
|
5
|
+
// The lines one weight away from the border's, each part's weight moved by +1
|
|
6
|
+
// and then -1 in the order of the parts, and reduced by their common divisor.
|
|
7
|
+
export function linesBeside(weights) {
|
|
8
|
+
const seen = [reduced(weights)];
|
|
9
|
+
const lines = [];
|
|
10
|
+
weights.forEach((_, index) => {
|
|
11
|
+
for (const step of [1, -1]) {
|
|
12
|
+
const moved = reduced(weights.map((weight, other) => (other === index ? weight + step : weight)));
|
|
13
|
+
if (moved.every(weight => weight === 0) || seen.some(line => same(line, moved))) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
seen.push(moved);
|
|
17
|
+
lines.push(moved);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return lines;
|
|
21
|
+
}
|
|
22
|
+
// The first line beside the border on which a cut keeps every row the border
|
|
23
|
+
// keeps and refuses every row it refuses.
|
|
24
|
+
export function lineTheRowsAllow(weights, keptBelow, kept, refused) {
|
|
25
|
+
for (const line of linesBeside(weights)) {
|
|
26
|
+
const at = (values) => line.reduce((total, weight, index) => total + weight * values[index], 0);
|
|
27
|
+
const cut = keptBelow ? Math.max(...kept.map(at)) : Math.min(...kept.map(at));
|
|
28
|
+
if (refused.every(values => (keptBelow ? at(values) > cut : at(values) < cut))) {
|
|
29
|
+
return { weights: line, cut };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
// Inputs one or more steps along the border from a row, where the border
|
|
35
|
+
// answers as at the row and the line beside it does not: the rows the border
|
|
36
|
+
// keeps first, each from the step nearest the line's cut.
|
|
37
|
+
export function partingsOf(weights, line, keptBelow, rows) {
|
|
38
|
+
const along = alongTheBorder(weights, line.weights);
|
|
39
|
+
if (along === undefined) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const at = (values) => line.weights.reduce((total, weight, index) => total + weight * values[index], 0);
|
|
43
|
+
const moves = at(along);
|
|
44
|
+
const keeps = (values) => (keptBelow ? at(values) <= line.cut : at(values) >= line.cut);
|
|
45
|
+
const ordered = [...rows.entries()].sort(([, left], [, right]) => Number(right.kept) - Number(left.kept));
|
|
46
|
+
return ordered.flatMap(([from, row]) => {
|
|
47
|
+
const crossing = Math.trunc((line.cut - at(row.values)) / moves);
|
|
48
|
+
return [0, -1, 1, -2, 2]
|
|
49
|
+
.map(away => crossing + away)
|
|
50
|
+
.filter(steps => steps !== 0)
|
|
51
|
+
.map(steps => ({ from, steps, values: row.values.map((value, index) => value + steps * along[index]) }))
|
|
52
|
+
.filter(parting => keeps(parting.values) !== row.kept);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// A step the border weighs to nothing and the line beside it does not.
|
|
56
|
+
function alongTheBorder(weights, line) {
|
|
57
|
+
for (let first = 0; first < weights.length; first++) {
|
|
58
|
+
for (let second = first + 1; second < weights.length; second++) {
|
|
59
|
+
const step = weights.map((_, index) => index === first ? weights[second] : index === second ? -weights[first] : 0);
|
|
60
|
+
if (step.reduce((total, move, index) => total + move * line[index], 0) !== 0) {
|
|
61
|
+
return step;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
export function spelled(paths, line) {
|
|
68
|
+
const terms = line.weights.flatMap((weight, index) => (weight === 0 ? [] : [{ weight, path: paths[index] }]));
|
|
69
|
+
const written = terms
|
|
70
|
+
.map(({ weight, path }, index) => {
|
|
71
|
+
const size = Math.abs(weight);
|
|
72
|
+
const body = size === 1 ? path : `${size} * ${path}`;
|
|
73
|
+
return index === 0 ? (weight < 0 ? `-${body}` : body) : `${weight < 0 ? "-" : "+"} ${body}`;
|
|
74
|
+
})
|
|
75
|
+
.join(" ");
|
|
76
|
+
return `${written} = ${line.cut}`;
|
|
77
|
+
}
|
|
78
|
+
function reduced(weights) {
|
|
79
|
+
const divisor = weights.reduce((common, weight) => gcd(common, Math.abs(weight)), 0);
|
|
80
|
+
return divisor <= 1 ? [...weights] : weights.map(weight => weight / divisor);
|
|
81
|
+
}
|
|
82
|
+
function gcd(left, right) {
|
|
83
|
+
return right === 0 ? left : gcd(right, left % right);
|
|
84
|
+
}
|
|
85
|
+
function same(left, right) {
|
|
86
|
+
return left.length === right.length && left.every((weight, index) => weight === right[index]);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=beside.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beside.js","sourceRoot":"","sources":["../src/beside.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,gFAAgF;AAChF,0BAA0B;AAO1B,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAOlD,8EAA8E;AAC9E,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CAAC,OAA0B;IACpD,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAChC,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QAC3B,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG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ACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,OAAO,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;AACpC,CAAC;AAED,SAAS,OAAO,CAAC,OAA0B;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrF,OAAO,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,GAAG,CAAC,IAAY,EAAE,KAAa;IACtC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,IAAI,CAAC,IAAuB,EAAE,KAAwB;IAC7D,OAAO,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAChG,CAAC"}
|
package/dist/border.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Measure, Operator, Rule } from "./rule.js";
|
|
2
|
+
export { normalize } from "./rule.js";
|
|
3
|
+
export type PointRole = "ON" | "OFF" | "IN" | "OUT";
|
|
4
|
+
export type PointStatus = "owed" | "excluded" | "not named" | "no point";
|
|
5
|
+
export interface BorderPoint {
|
|
6
|
+
readonly role: PointRole;
|
|
7
|
+
readonly relation: string;
|
|
8
|
+
readonly status: PointStatus;
|
|
9
|
+
readonly witness?: unknown;
|
|
10
|
+
readonly region?: {
|
|
11
|
+
readonly operator: Operator;
|
|
12
|
+
readonly bound: unknown;
|
|
13
|
+
};
|
|
14
|
+
contains(coordinate: unknown): boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface Border {
|
|
17
|
+
readonly source: "invariant" | "guard" | "ensures";
|
|
18
|
+
readonly measure: Measure;
|
|
19
|
+
readonly rule: string;
|
|
20
|
+
readonly closed: boolean;
|
|
21
|
+
readonly points: readonly BorderPoint[];
|
|
22
|
+
}
|
|
23
|
+
export interface Carrier {
|
|
24
|
+
readonly compare: (left: unknown, right: unknown) => number;
|
|
25
|
+
readonly step?: (value: unknown, direction: 1 | -1) => unknown;
|
|
26
|
+
readonly past?: (value: unknown, direction: 1 | -1) => unknown;
|
|
27
|
+
readonly format: (value: unknown) => string;
|
|
28
|
+
readonly floor?: {
|
|
29
|
+
readonly value: unknown;
|
|
30
|
+
readonly reason: string;
|
|
31
|
+
};
|
|
32
|
+
readonly ceiling?: {
|
|
33
|
+
readonly value: unknown;
|
|
34
|
+
readonly reason: string;
|
|
35
|
+
};
|
|
36
|
+
readonly snap?: (bound: unknown, operator: Operator) => {
|
|
37
|
+
readonly operator: Operator;
|
|
38
|
+
readonly bound: unknown;
|
|
39
|
+
};
|
|
40
|
+
readonly produces?: (value: unknown) => boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare const integerCarrier: Carrier;
|
|
43
|
+
export declare const int64Carrier: Carrier;
|
|
44
|
+
export declare const rationalCarrier: Carrier;
|
|
45
|
+
export declare const lengthCarrier: Carrier;
|
|
46
|
+
export declare function decimalCarrier(scale: number): Carrier;
|
|
47
|
+
export declare function decimalUnitsCarrier(scale: number): Carrier;
|
|
48
|
+
export declare const numberCarrier: Carrier;
|
|
49
|
+
export declare const instantCarrier: Carrier;
|
|
50
|
+
export declare const dateCarrier: Carrier;
|
|
51
|
+
export declare const dateTimeCarrier: Carrier;
|
|
52
|
+
export declare const timeCarrier: Carrier;
|
|
53
|
+
export declare const nanosecondCarrier: Carrier;
|
|
54
|
+
export declare const stringCarrier: Carrier;
|
|
55
|
+
export declare function bordersOf(rules: readonly Rule[], carrierFor: (measure: Border["measure"]) => Carrier | undefined, drawing?: Drawing): Border[];
|
|
56
|
+
export declare function emptiedBy(borders: readonly Border[]): readonly Border[] | undefined;
|
|
57
|
+
export interface Drawing {
|
|
58
|
+
readonly source: Border["source"];
|
|
59
|
+
readonly describe: (rule: Rule) => string;
|
|
60
|
+
readonly admits: (coordinate: unknown) => boolean;
|
|
61
|
+
}
|
package/dist/border.js
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { requireTemporal } from "./temporal-global.js";
|
|
2
|
+
import { temporalNeighbor } from "./temporal.js";
|
|
3
|
+
import { Rational, INT64_MIN, INT64_MAX } from "./exact.js";
|
|
4
|
+
import { compareText } from "./text.js";
|
|
5
|
+
import { Decimal } from "decimal.js";
|
|
6
|
+
import { decimalStep, describeRule, isDecimal, isTerm, normalize, termData, positionData } from "./rule.js";
|
|
7
|
+
export { normalize } from "./rule.js";
|
|
8
|
+
export const integerCarrier = {
|
|
9
|
+
compare: (left, right) => left - right,
|
|
10
|
+
step: (value, direction) => value + direction,
|
|
11
|
+
format: String,
|
|
12
|
+
};
|
|
13
|
+
export const int64Carrier = {
|
|
14
|
+
compare: (left, right) => left < right ? -1 : left > right ? 1 : 0,
|
|
15
|
+
step: (value, direction) => { const next = value + BigInt(direction); return next < INT64_MIN || next > INT64_MAX ? undefined : next; },
|
|
16
|
+
floor: { value: INT64_MIN, reason: "signed 64-bit minimum" }, ceiling: { value: INT64_MAX, reason: "signed 64-bit maximum" }, format: String,
|
|
17
|
+
};
|
|
18
|
+
export const rationalCarrier = {
|
|
19
|
+
compare: (left, right) => left.comparedTo(right),
|
|
20
|
+
past: (value, direction) => value.plus(new Rational(BigInt(direction))), format: String,
|
|
21
|
+
};
|
|
22
|
+
export const lengthCarrier = {
|
|
23
|
+
...integerCarrier,
|
|
24
|
+
floor: { value: 0, reason: "a length is never negative" },
|
|
25
|
+
};
|
|
26
|
+
// Steps by one unit of the last digit and compares exactly. A bound written off
|
|
27
|
+
// that grid is moved onto it first, so `>= 0.004` in cents draws the border of
|
|
28
|
+
// `>= 0.01`, whose points are values a row can hold.
|
|
29
|
+
export function decimalCarrier(scale) {
|
|
30
|
+
const asDecimal = (value) => isDecimal(value) ? value : new Decimal(value);
|
|
31
|
+
const next = decimalStep(scale);
|
|
32
|
+
const step = (value, direction) => next(asDecimal(value), direction);
|
|
33
|
+
return {
|
|
34
|
+
compare: (left, right) => asDecimal(left).comparedTo(right),
|
|
35
|
+
step,
|
|
36
|
+
format: String,
|
|
37
|
+
snap: (bound, operator) => {
|
|
38
|
+
bound = asDecimal(bound);
|
|
39
|
+
if (isDecimal(bound) && bound.decimalPlaces() <= scale) {
|
|
40
|
+
return { operator, bound };
|
|
41
|
+
}
|
|
42
|
+
switch (operator) {
|
|
43
|
+
case ">":
|
|
44
|
+
case ">=":
|
|
45
|
+
return { operator: ">=", bound: step(bound, 1) };
|
|
46
|
+
case "<":
|
|
47
|
+
case "<=":
|
|
48
|
+
return { operator: "<=", bound: step(bound, -1) };
|
|
49
|
+
default:
|
|
50
|
+
return { operator, bound };
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// A difference between two decimals, or a decimal and an integer, counted in
|
|
56
|
+
// units of the finer scale as a bigint, and written as the decimal it stands for.
|
|
57
|
+
export function decimalUnitsCarrier(scale) {
|
|
58
|
+
return {
|
|
59
|
+
...nanosecondCarrier,
|
|
60
|
+
format: value => {
|
|
61
|
+
const units = value;
|
|
62
|
+
const negative = units < 0n;
|
|
63
|
+
const digits = (negative ? -units : units).toString().padStart(scale + 1, "0");
|
|
64
|
+
const text = scale === 0 ? digits : `${digits.slice(0, -scale)}.${digits.slice(-scale)}`;
|
|
65
|
+
return negative ? `-${text}` : text;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export const numberCarrier = {
|
|
70
|
+
compare: (left, right) => left - right,
|
|
71
|
+
past: (value, direction) => value + direction,
|
|
72
|
+
format: String,
|
|
73
|
+
};
|
|
74
|
+
export const instantCarrier = {
|
|
75
|
+
compare: (left, right) => {
|
|
76
|
+
const difference = epochNanoseconds(left) - epochNanoseconds(right);
|
|
77
|
+
return difference < 0n ? -1 : difference > 0n ? 1 : 0;
|
|
78
|
+
},
|
|
79
|
+
step: (value, direction) => temporalNeighbor(value, { nanoseconds: direction }),
|
|
80
|
+
get floor() { return { value: temporalValue("Instant", "-271821-04-20T00:00Z"), reason: "an instant lies within Temporal's range" }; },
|
|
81
|
+
get ceiling() { return { value: temporalValue("Instant", "+275760-09-13T00:00Z"), reason: "an instant lies within Temporal's range" }; },
|
|
82
|
+
format: String,
|
|
83
|
+
};
|
|
84
|
+
const comparePlain = (left, right) => left.constructor.compare(left, right);
|
|
85
|
+
export const dateCarrier = {
|
|
86
|
+
compare: comparePlain,
|
|
87
|
+
step: (value, direction) => temporalNeighbor(value, { days: direction }),
|
|
88
|
+
get floor() { return { value: temporalValue("PlainDate", "-271821-04-19"), reason: "a date lies within Temporal's range" }; },
|
|
89
|
+
get ceiling() { return { value: temporalValue("PlainDate", "+275760-09-13"), reason: "a date lies within Temporal's range" }; },
|
|
90
|
+
format: String,
|
|
91
|
+
};
|
|
92
|
+
export const dateTimeCarrier = {
|
|
93
|
+
compare: comparePlain,
|
|
94
|
+
step: (value, direction) => temporalNeighbor(value, { nanoseconds: direction }),
|
|
95
|
+
get floor() { return { value: temporalValue("PlainDateTime", "-271821-04-19T00:00:00.000000001"), reason: "a date-time lies within Temporal's range" }; },
|
|
96
|
+
get ceiling() { return { value: temporalValue("PlainDateTime", "+275760-09-13T23:59:59.999999999"), reason: "a date-time lies within Temporal's range" }; },
|
|
97
|
+
format: String,
|
|
98
|
+
};
|
|
99
|
+
const withinOneDay = "a time of day lies within one day";
|
|
100
|
+
// A plain time wraps past midnight when stepped, so the step stops at either end
|
|
101
|
+
// of the day instead, and the ends are named so a point beyond them is "no point".
|
|
102
|
+
export const timeCarrier = {
|
|
103
|
+
compare: comparePlain,
|
|
104
|
+
step: (value, direction) => {
|
|
105
|
+
const end = direction === 1 ? timeCarrier.ceiling : timeCarrier.floor;
|
|
106
|
+
return comparePlain(value, end.value) === 0 ? undefined : value.add({ nanoseconds: direction });
|
|
107
|
+
},
|
|
108
|
+
format: String,
|
|
109
|
+
get floor() {
|
|
110
|
+
return { value: plainTime("00:00"), reason: withinOneDay };
|
|
111
|
+
},
|
|
112
|
+
get ceiling() {
|
|
113
|
+
return { value: plainTime("23:59:59.999999999"), reason: withinOneDay };
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
function plainTime(text) {
|
|
117
|
+
return temporalValue("PlainTime", text);
|
|
118
|
+
}
|
|
119
|
+
function temporalValue(kind, text) {
|
|
120
|
+
return requireTemporal()[kind].from(text);
|
|
121
|
+
}
|
|
122
|
+
function epochNanoseconds(value) {
|
|
123
|
+
return value.epochNanoseconds;
|
|
124
|
+
}
|
|
125
|
+
export const nanosecondCarrier = {
|
|
126
|
+
compare: (left, right) => {
|
|
127
|
+
const difference = left - right;
|
|
128
|
+
return difference < 0n ? -1 : difference > 0n ? 1 : 0;
|
|
129
|
+
},
|
|
130
|
+
step: (value, direction) => value + BigInt(direction),
|
|
131
|
+
format: String,
|
|
132
|
+
};
|
|
133
|
+
export const stringCarrier = {
|
|
134
|
+
compare: (left, right) => compareText(left, right),
|
|
135
|
+
past: (value, direction) => direction === 1
|
|
136
|
+
? `${value}a`
|
|
137
|
+
: value.length > 0
|
|
138
|
+
? [...value.normalize("NFC")].slice(0, -1).join("")
|
|
139
|
+
: undefined,
|
|
140
|
+
format: value => JSON.stringify(value),
|
|
141
|
+
};
|
|
142
|
+
export function bordersOf(rules, carrierFor, drawing = invariantDrawing) {
|
|
143
|
+
const drawn = rules.flatMap(rule => {
|
|
144
|
+
const border = borderOf(rule, carrierFor, drawing);
|
|
145
|
+
return border === undefined ? [] : [border];
|
|
146
|
+
});
|
|
147
|
+
return drawn.map(current => {
|
|
148
|
+
const sameMeasure = drawn.filter(other => other !== current && other.border.measure === current.border.measure);
|
|
149
|
+
if (current.namesValue === true) {
|
|
150
|
+
return withoutRefusedPoints(current.border, sameMeasure);
|
|
151
|
+
}
|
|
152
|
+
const others = sameMeasure.filter(other => other.namesValue !== true);
|
|
153
|
+
const border = oneValueWide(current, others)
|
|
154
|
+
? withoutInPoint(current.border)
|
|
155
|
+
: withAdmittedInWitness(current, others);
|
|
156
|
+
return withoutRefusedPoints(border, sameMeasure);
|
|
157
|
+
}).map(border => ({
|
|
158
|
+
...border,
|
|
159
|
+
points: border.points.map(point => ({ ...point, contains: value => value !== undefined && point.contains(value) })),
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
function withoutRefusedPoints(border, others) {
|
|
163
|
+
return {
|
|
164
|
+
...border,
|
|
165
|
+
points: border.points.map(point => point.status === "owed" &&
|
|
166
|
+
point.witness !== undefined &&
|
|
167
|
+
!others.every(other => other.admits(point.witness))
|
|
168
|
+
? { ...point, status: "excluded" }
|
|
169
|
+
: point),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export function emptiedBy(borders) {
|
|
173
|
+
// The value and its length first, as before transforms, then each transformed measure.
|
|
174
|
+
for (const measure of new Set(["value", "length", ...borders.map(border => border.measure)])) {
|
|
175
|
+
const invariants = borders.filter(border => border.source === "invariant" && border.measure === measure);
|
|
176
|
+
if (invariants.length > 0 &&
|
|
177
|
+
invariants.every(border => border.points.every(point => point.status !== "owed"))) {
|
|
178
|
+
return invariants;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
function withAdmittedInWitness(current, others) {
|
|
184
|
+
const inPoint = current.border.points.find(point => point.role === "IN");
|
|
185
|
+
const witness = inPoint?.witness;
|
|
186
|
+
if (witness === undefined || others.every(other => other.admits(witness))) {
|
|
187
|
+
return current.border;
|
|
188
|
+
}
|
|
189
|
+
const facing = others.find(other => other.lower !== current.lower);
|
|
190
|
+
const between = typeof current.on === "number" && typeof facing?.on === "number"
|
|
191
|
+
? (current.on + facing.on) / 2
|
|
192
|
+
: undefined;
|
|
193
|
+
return {
|
|
194
|
+
...current.border,
|
|
195
|
+
points: current.border.points.map(point => point.role === "IN" ? { ...point, witness: between } : point),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function oneValueWide(current, others) {
|
|
199
|
+
const { carrier, on, lower } = current;
|
|
200
|
+
const next = carrier.step?.(on, lower ? 1 : -1);
|
|
201
|
+
if (next === undefined) {
|
|
202
|
+
return others.some(other => other.lower !== lower && other.border.closed && carrier.compare(other.on, on) === 0);
|
|
203
|
+
}
|
|
204
|
+
return !others.every(other => other.admits(next));
|
|
205
|
+
}
|
|
206
|
+
function withoutInPoint(border) {
|
|
207
|
+
return {
|
|
208
|
+
...border,
|
|
209
|
+
points: border.points.map(point => point.role === "IN" ? { ...point, status: "excluded" } : point),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const invariantDrawing = {
|
|
213
|
+
source: "invariant",
|
|
214
|
+
describe: rule => describeRule(rule),
|
|
215
|
+
admits: () => true,
|
|
216
|
+
};
|
|
217
|
+
function borderOf(rule, carrierFor, drawing) {
|
|
218
|
+
const normalized = normalize(rule);
|
|
219
|
+
if (normalized === undefined) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
const { measure } = normalized;
|
|
223
|
+
const carrier = carrierFor(measure);
|
|
224
|
+
if (carrier === undefined) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
const { operator, bound } = carrier.snap === undefined ? normalized : carrier.snap(normalized.bound, normalized.operator);
|
|
228
|
+
if (operator === "==" || operator === "!=") {
|
|
229
|
+
return namedValueBorder(rule, operator, bound, measure, carrier, drawing);
|
|
230
|
+
}
|
|
231
|
+
const lower = operator === ">" || operator === ">=";
|
|
232
|
+
const closed = operator === ">=" || operator === "<=";
|
|
233
|
+
const inward = lower ? 1 : -1;
|
|
234
|
+
const outward = lower ? -1 : 1;
|
|
235
|
+
const { step } = carrier;
|
|
236
|
+
const on = closed ? bound : step?.(bound, inward);
|
|
237
|
+
const off = closed ? step?.(bound, outward) : bound;
|
|
238
|
+
const guarded = drawing.source !== "invariant";
|
|
239
|
+
const floored = belowFloor(carrier);
|
|
240
|
+
const ceiled = aboveCeiling(carrier);
|
|
241
|
+
const pastEnd = (edge, direction) => direction === -1 ? floored.under(edge) : ceiled.over(edge);
|
|
242
|
+
if (on === undefined && !guarded && !pastEnd(bound, inward)) {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
const inner = on ?? bound;
|
|
246
|
+
const outer = off ?? bound;
|
|
247
|
+
const beyond = (value) => (lower ? ">" : "<") + " " + carrier.format(value);
|
|
248
|
+
const before = (value) => (lower ? "<" : ">") + " " + carrier.format(value);
|
|
249
|
+
const inside = (edge) => (value) => lower ? carrier.compare(value, edge) > 0 : carrier.compare(value, edge) < 0;
|
|
250
|
+
const outside = (edge) => (value) => lower ? carrier.compare(value, edge) < 0 : carrier.compare(value, edge) > 0;
|
|
251
|
+
const at = (edge) => (value) => carrier.compare(value, edge) === 0;
|
|
252
|
+
const past = (value, direction) => step?.(value, direction) ?? carrier.past?.(value, direction);
|
|
253
|
+
const owedUnlessRefused = (witness) => witness === undefined || !drawing.admits(witness) ? "excluded" : "owed";
|
|
254
|
+
const outsideStatus = (witness) => guarded ? owedUnlessRefused(witness) : "excluded";
|
|
255
|
+
const outWitness = past(outer, outward);
|
|
256
|
+
const points = [
|
|
257
|
+
on === undefined
|
|
258
|
+
? { role: "ON", relation: "neighbour not named", status: "not named", contains: () => false }
|
|
259
|
+
: {
|
|
260
|
+
role: "ON",
|
|
261
|
+
relation: `= ${carrier.format(on)}`,
|
|
262
|
+
status: owedUnlessRefused(on),
|
|
263
|
+
witness: on,
|
|
264
|
+
region: { operator: "==", bound: on },
|
|
265
|
+
contains: at(on),
|
|
266
|
+
},
|
|
267
|
+
off === undefined
|
|
268
|
+
? { role: "OFF", relation: "neighbour not named", status: "not named", contains: () => false }
|
|
269
|
+
: {
|
|
270
|
+
role: "OFF",
|
|
271
|
+
relation: `= ${carrier.format(off)}`,
|
|
272
|
+
status: outsideStatus(off),
|
|
273
|
+
witness: off,
|
|
274
|
+
region: { operator: "==", bound: off },
|
|
275
|
+
contains: at(off),
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
...inPoint(beyond(inner), past(inner, inward), inside(inner)),
|
|
279
|
+
region: { operator: lower ? ">" : "<", bound: inner },
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
role: "OUT",
|
|
283
|
+
relation: before(outer),
|
|
284
|
+
status: outsideStatus(outWitness),
|
|
285
|
+
witness: outWitness,
|
|
286
|
+
region: { operator: lower ? "<" : ">", bound: outer },
|
|
287
|
+
contains: outside(outer),
|
|
288
|
+
},
|
|
289
|
+
];
|
|
290
|
+
const reaching = [
|
|
291
|
+
on === undefined ? pastEnd(bound, inward) : floored.at(on),
|
|
292
|
+
off === undefined ? closed && pastEnd(bound, outward) : floored.at(off),
|
|
293
|
+
lower ? ceiled.over(inner) : floored.under(inner),
|
|
294
|
+
lower ? floored.under(outer) : ceiled.over(outer),
|
|
295
|
+
];
|
|
296
|
+
return {
|
|
297
|
+
border: {
|
|
298
|
+
source: drawing.source,
|
|
299
|
+
measure,
|
|
300
|
+
rule: `${drawing.source} ${rule.name === undefined ? "" : `${rule.name}: `}${drawing.describe(rule)}`,
|
|
301
|
+
closed,
|
|
302
|
+
points: points.map((point, index) => reaching[index] === true ? noPointBelow(point.role, carrier) : unread(point, carrier)),
|
|
303
|
+
},
|
|
304
|
+
carrier,
|
|
305
|
+
on: inner,
|
|
306
|
+
lower,
|
|
307
|
+
admits: value => at(inner)(value) || inside(inner)(value),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function namedValueBorder(rule, operator, bound, measure, carrier, drawing) {
|
|
311
|
+
const keeps = operator === "==";
|
|
312
|
+
const guarded = drawing.source !== "invariant";
|
|
313
|
+
const at = (edge) => (value) => carrier.compare(value, edge) === 0;
|
|
314
|
+
const below = carrier.step?.(bound, -1);
|
|
315
|
+
const above = carrier.step?.(bound, 1);
|
|
316
|
+
const beyond = (edge, direction) => carrier.step?.(edge, direction) ?? carrier.past?.(edge, direction);
|
|
317
|
+
const statusFor = (witness, inside) => witness === undefined || !drawing.admits(witness)
|
|
318
|
+
? "excluded"
|
|
319
|
+
: inside || guarded
|
|
320
|
+
? "owed"
|
|
321
|
+
: "excluded";
|
|
322
|
+
const neighbour = (role, edge, inside) => edge === undefined
|
|
323
|
+
? { role, relation: "neighbour not named", status: "not named", contains: () => false }
|
|
324
|
+
: {
|
|
325
|
+
role,
|
|
326
|
+
relation: `= ${carrier.format(edge)}`,
|
|
327
|
+
status: statusFor(edge, inside),
|
|
328
|
+
witness: edge,
|
|
329
|
+
region: { operator: "==", bound: edge },
|
|
330
|
+
contains: at(edge),
|
|
331
|
+
};
|
|
332
|
+
const run = (role, direction, inside) => {
|
|
333
|
+
const edge = (direction === 1 ? above : below) ?? bound;
|
|
334
|
+
const witness = beyond(edge, direction);
|
|
335
|
+
return {
|
|
336
|
+
role,
|
|
337
|
+
relation: `${direction === 1 ? ">" : "<"} ${carrier.format(edge)}`,
|
|
338
|
+
status: statusFor(witness, inside),
|
|
339
|
+
witness,
|
|
340
|
+
region: { operator: direction === 1 ? ">" : "<", bound: edge },
|
|
341
|
+
contains: value => carrier.compare(value, edge) * direction > 0,
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
const floored = belowFloor(carrier);
|
|
345
|
+
const ceiled = aboveCeiling(carrier);
|
|
346
|
+
const neighbourOrNone = (role, edge, direction, inside) => (edge !== undefined && floored.at(edge)) ||
|
|
347
|
+
(edge === undefined && direction !== 0 && (direction === -1 ? floored.under(bound) : ceiled.over(bound)))
|
|
348
|
+
? noPointBelow(role, carrier)
|
|
349
|
+
: unread(neighbour(role, edge, inside), carrier);
|
|
350
|
+
const runOrNone = (role, direction, inside) => direction === -1 ? (floored.under(below ?? bound) ? noPointBelow(role, carrier) : run(role, direction, inside))
|
|
351
|
+
: ceiled.over(above ?? bound) ? noPointBelow(role, carrier) : run(role, direction, inside);
|
|
352
|
+
const points = keeps
|
|
353
|
+
? [
|
|
354
|
+
neighbourOrNone("ON", bound, 0, true),
|
|
355
|
+
neighbourOrNone("OFF", below, -1, false),
|
|
356
|
+
neighbourOrNone("OFF", above, 1, false),
|
|
357
|
+
{
|
|
358
|
+
role: "IN",
|
|
359
|
+
relation: "none: the rule keeps a single value",
|
|
360
|
+
status: "no point",
|
|
361
|
+
contains: () => false,
|
|
362
|
+
},
|
|
363
|
+
runOrNone("OUT", -1, false),
|
|
364
|
+
runOrNone("OUT", 1, false),
|
|
365
|
+
]
|
|
366
|
+
: [
|
|
367
|
+
neighbourOrNone("ON", below, -1, true),
|
|
368
|
+
neighbourOrNone("ON", above, 1, true),
|
|
369
|
+
neighbourOrNone("OFF", bound, 0, false),
|
|
370
|
+
runOrNone("IN", -1, true),
|
|
371
|
+
runOrNone("IN", 1, true),
|
|
372
|
+
{
|
|
373
|
+
role: "OUT",
|
|
374
|
+
relation: "none: the rule leaves out a single value",
|
|
375
|
+
status: "no point",
|
|
376
|
+
contains: () => false,
|
|
377
|
+
},
|
|
378
|
+
];
|
|
379
|
+
return {
|
|
380
|
+
border: {
|
|
381
|
+
source: drawing.source,
|
|
382
|
+
measure,
|
|
383
|
+
rule: `${drawing.source} ${rule.name === undefined ? "" : `${rule.name}: `}${drawing.describe(rule)}`,
|
|
384
|
+
closed: keeps,
|
|
385
|
+
points,
|
|
386
|
+
},
|
|
387
|
+
carrier,
|
|
388
|
+
on: bound,
|
|
389
|
+
lower: true,
|
|
390
|
+
namesValue: true,
|
|
391
|
+
admits: value => at(bound)(value) === keeps,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function belowFloor(carrier) {
|
|
395
|
+
const { floor } = carrier;
|
|
396
|
+
if (floor === undefined) {
|
|
397
|
+
return { at: () => false, under: () => false };
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
at: value => carrier.compare(value, floor.value) < 0,
|
|
401
|
+
under: edge => carrier.compare(edge, floor.value) <= 0,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function aboveCeiling(carrier) {
|
|
405
|
+
const { ceiling } = carrier;
|
|
406
|
+
return ceiling === undefined
|
|
407
|
+
? { over: () => false }
|
|
408
|
+
: { over: edge => carrier.compare(edge, ceiling.value) >= 0 };
|
|
409
|
+
}
|
|
410
|
+
function noPointBelow(role, carrier) {
|
|
411
|
+
return {
|
|
412
|
+
role,
|
|
413
|
+
relation: `none: ${carrier.floor?.reason ?? carrier.ceiling?.reason ?? "no value lies there"}`,
|
|
414
|
+
status: "no point",
|
|
415
|
+
contains: () => false,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
// A point placed exactly at a value nothing reads as has no row to stand at it.
|
|
419
|
+
function unread(point, carrier) {
|
|
420
|
+
return point.region?.operator === "==" && carrier.produces?.(point.witness) === false
|
|
421
|
+
? {
|
|
422
|
+
role: point.role,
|
|
423
|
+
relation: `none: no value reads as ${carrier.format(point.witness)}`,
|
|
424
|
+
status: "no point",
|
|
425
|
+
contains: () => false,
|
|
426
|
+
}
|
|
427
|
+
: point;
|
|
428
|
+
}
|
|
429
|
+
function inPoint(relation, witness, contains) {
|
|
430
|
+
return witness === undefined
|
|
431
|
+
? { role: "IN", relation, status: "excluded", contains }
|
|
432
|
+
: { role: "IN", relation, status: "owed", witness, contains };
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=border.js.map
|