@mark1russell7/rigor-generators 0.2.3 → 0.2.5

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 CHANGED
@@ -106,6 +106,15 @@ Each table is a sample, and it does not show a general law:
106
106
 
107
107
  The npm package holds the notice of the Ptolemy II license, because the field `notice` is part of the build.
108
108
 
109
+ ### The beta and gamma functions
110
+
111
+ `logGamma(x)`, `logBeta(a, b)`, `betaCdf(x, a, b)` and `betaShares(x, y, a, b)` give the special functions of the families.
112
+
113
+ - `logBeta` keeps the digits of its value when a parameter is near 1e13. There, the sum of `logGamma` loses all of them.
114
+ - `betaShares` takes the point `x` and its distance `y = 1 - x` from 1. Thus a point near 1 keeps its digits. The function gives the shares of the law below and above the point.
115
+
116
+ The Student t law with `df` degrees of freedom has its shares between `-t` and `t` and above `|t|` in `betaShares(t^2 / (df + t^2), df / (df + t^2), 0.5, df / 2)`.
117
+
109
118
  ## Input families and designs
110
119
 
111
120
  An input family has named dimensions. Each dimension has a range from `min` to `max`. It can also have one of these:
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","names":[],"sources":["../src/hash.ts"],"mappings":";iBAkBiB;;;;;;;;;WASN;;;;;;;;;wBAgFK,UAAU,cAAc,UAAU;;iBAiEjC;;;;;;;WAON;;;;;WAKA;;;;;;;;;;;WAWA;;;;;;;;;;;;;;;;;;;;;wBA2DK,cAAc,gBAAgB,UAAU;;wBAyFxC,cAAc,gBAAgB,UAAU"}
1
+ {"version":3,"file":"hash.d.ts","names":[],"sources":["../src/hash.ts"],"mappings":";iBAkBiB;;;;;;;;;WASN;;;;;;;;;wBAgFK,UAAU,cAAc,UAAU;;iBAiEjC;;;;;;;WAON;;;;;WAKA;;;;;;;;;;;WAWA;;;;;;;;;;;;;;;;;;;;;wBA4EK,cAAc,gBAAgB,UAAU;;wBAsIxC,cAAc,gBAAgB,UAAU"}
package/build/hash.js CHANGED
@@ -221,8 +221,6 @@ const tagged = /* @__PURE__ */ new Set([
221
221
  "Map",
222
222
  "Set"
223
223
  ]);
224
- /** This function is true for an object, and false for `null` and each primitive. */
225
- const isObject = (v) => v !== null && typeof v === "object";
226
224
  /** This function gives the brand of an object: the tag of `Object.prototype.toString`. The brand is the same in each realm. */
227
225
  const brandOf = (o) => Object.prototype.toString.call(o).slice(8, -1);
228
226
  /** This function is true when `method` accepts `o` as its `this`. Thus it tests an internal slot, the same in each realm. */
@@ -246,6 +244,25 @@ function unboxed(o, brand) {
246
244
  return o;
247
245
  }
248
246
  /**
247
+ * This function sorts the keys of an object in the order of their UTF-16 code units, as `Array.prototype.sort` does with no compare function.
248
+ * The keys are different strings, so each correct sort gives the same order. For a short list, an insertion sort does less work.
249
+ */
250
+ function sortKeys(keys) {
251
+ if (keys.length > 16) {
252
+ keys.sort();
253
+ return;
254
+ }
255
+ for (let i = 1; i < keys.length; i++) {
256
+ const k = keys[i];
257
+ let j = i - 1;
258
+ while (j >= 0 && keys[j] > k) {
259
+ keys[j + 1] = keys[j];
260
+ j--;
261
+ }
262
+ keys[j + 1] = k;
263
+ }
264
+ }
265
+ /**
249
266
  * This function gives the canonical form of a value. The default form is RFC 8785 (JCS):
250
267
  *
251
268
  * - The keys of each object are in the order of their UTF-16 code units, with no whitespace.
@@ -273,7 +290,18 @@ function canonicalJson(value, options) {
273
290
  if (form !== "jcs" && form !== "json") throw new RangeError(`canonicalJson: form is "jcs" or "json", not ${String(form)}.`);
274
291
  if (bigint !== "error" && bigint !== "suffix") throw new RangeError(`canonicalJson: bigint is "error" or "suffix", not ${String(bigint)}.`);
275
292
  const jcs = form === "jcs";
276
- const open = /* @__PURE__ */ new Set();
293
+ const path = [];
294
+ const deep = /* @__PURE__ */ new Set();
295
+ const enter = (o) => {
296
+ for (let i = 0; i < path.length; i++) if (path[i] === o) throw new TypeError("canonicalJson: the value has a cycle.");
297
+ if (deep.size > 0 && deep.has(o)) throw new TypeError("canonicalJson: the value has a cycle.");
298
+ if (path.length < 32) path.push(o);
299
+ else deep.add(o);
300
+ };
301
+ const leave = (o) => {
302
+ if (deep.size > 0) deep.delete(o);
303
+ else path.pop();
304
+ };
277
305
  const text = (s) => {
278
306
  if (jcs && !s.isWellFormed()) throw new RangeError(`canonicalJson: the string ${JSON.stringify(s)} has a lone surrogate, which RFC 8785 does not allow.`);
279
307
  return JSON.stringify(s);
@@ -284,59 +312,86 @@ function canonicalJson(value, options) {
284
312
  if (brand === "RegExp" && hasSlot(sourceOf, o)) return `RegExp(${text(RegExp.prototype.toString.call(o))})`;
285
313
  const map = brand === "Map" && hasSlot(Map.prototype.has, o);
286
314
  if (!map && !(brand === "Set" && hasSlot(Set.prototype.has, o))) return void 0;
287
- if (open.has(o)) throw new TypeError("canonicalJson: the value has a cycle.");
288
- open.add(o);
315
+ enter(o);
289
316
  const parts = [];
290
317
  if (map) for (const [k, item] of Map.prototype.entries.call(o)) parts.push(`[${write(k, "")},${write(item, "")}]`);
291
318
  else for (const item of Set.prototype.values.call(o)) parts.push(write(item, ""));
292
- open.delete(o);
319
+ leave(o);
293
320
  return `${map ? "Map" : "Set"}(${parts.sort().join(",")})`;
294
321
  };
295
322
  const lost = (brand) => {
296
323
  return `canonicalJson: the type ${brand} has no JSON form. JSON.stringify keeps only its own keys, so two of them with other contents can get the same hash. ${!typed && tagged.has(brand) ? "Use the option tags: \"typed\", or give the object a method toJSON." : "Give the object a method toJSON."}`;
297
324
  };
298
- const write = (v, key) => {
299
- if (typed && isObject(v)) {
300
- const tag = tagOf(v);
301
- if (tag !== void 0) return tag;
302
- }
303
- if (isObject(v) && typeof v.toJSON === "function") {
304
- v = v.toJSON(key);
305
- if (typed && isObject(v)) {
306
- const tag = tagOf(v);
307
- if (tag !== void 0) return tag;
308
- }
309
- }
310
- let brand = "Object";
311
- if (isObject(v)) {
312
- brand = brandOf(v);
313
- if (brand !== "Object") v = unboxed(v, brand);
314
- }
325
+ const scalar = (v) => {
315
326
  if (v === void 0 || v === null) return "null";
316
327
  switch (typeof v) {
317
328
  case "boolean": return v ? "true" : "false";
318
329
  case "number":
319
- if (Number.isFinite(v)) return JSON.stringify(v);
330
+ if (Number.isFinite(v)) return String(v);
320
331
  if (jcs) throw new RangeError(`canonicalJson: ${String(v)} is not a JSON number.`);
321
332
  return "null";
322
333
  case "string": return text(v);
323
334
  case "bigint":
324
335
  if (bigint === "suffix") return `${v}n`;
325
336
  throw new TypeError(`canonicalJson: the bigint ${v}n has no JSON form. Use the option bigint: "suffix" for a key.`);
326
- case "object": break;
327
337
  default: throw new TypeError(`canonicalJson: a ${typeof v} has no JSON form.`);
328
338
  }
339
+ };
340
+ const write = (v, key) => {
341
+ let isObj = v !== null && typeof v === "object";
342
+ if (isObj) {
343
+ if (typed) {
344
+ const tag = tagOf(v);
345
+ if (tag !== void 0) return tag;
346
+ }
347
+ if (typeof v.toJSON === "function") {
348
+ v = v.toJSON(key);
349
+ isObj = v !== null && typeof v === "object";
350
+ if (typed && isObj) {
351
+ const tag = tagOf(v);
352
+ if (tag !== void 0) return tag;
353
+ }
354
+ }
355
+ }
356
+ if (!isObj) return scalar(v);
329
357
  const o = v;
330
- if (brand !== "Object" && brand !== "Arguments" && !Array.isArray(o) && typedArrayName.call(o) === void 0) throw new TypeError(lost(brand));
331
- if (open.has(o)) throw new TypeError("canonicalJson: the value has a cycle.");
332
- open.add(o);
358
+ const toStringTag = Object.prototype.toString.call(o);
359
+ let brand;
360
+ if (toStringTag === "[object Object]") brand = "Object";
361
+ else if (toStringTag === "[object Array]") brand = "Array";
362
+ else {
363
+ brand = toStringTag.slice(8, -1);
364
+ const primitive = unboxed(o, brand);
365
+ if (primitive !== o) return scalar(primitive);
366
+ }
367
+ let isArray = false;
368
+ const checked = brand !== "Object" && brand !== "Arguments";
369
+ if (checked) {
370
+ isArray = Array.isArray(o);
371
+ if (!isArray && typedArrayName.call(o) === void 0) throw new TypeError(lost(brand));
372
+ }
373
+ enter(o);
374
+ if (!checked) isArray = Array.isArray(o);
333
375
  let out;
334
- if (Array.isArray(o)) out = `[${o.map((item, i) => write(item, String(i))).join(",")}]`;
376
+ if (isArray) out = `[${o.map((item, i) => write(item, String(i))).join(",")}]`;
335
377
  else {
336
378
  const r = o;
337
- out = `{${Object.keys(r).filter((k) => r[k] !== void 0).sort().map((k) => `${text(k)}:${write(r[k], k)}`).join(",")}}`;
379
+ const keys = Object.keys(r);
380
+ let n = 0;
381
+ for (let i = 0; i < keys.length; i++) {
382
+ const k = keys[i];
383
+ if (r[k] !== void 0) keys[n++] = k;
384
+ }
385
+ keys.length = n;
386
+ sortKeys(keys);
387
+ out = "{";
388
+ for (let i = 0; i < n; i++) {
389
+ const k = keys[i];
390
+ out += `${i === 0 ? "" : ","}${text(k)}:${write(r[k], k)}`;
391
+ }
392
+ out += "}";
338
393
  }
339
- open.delete(o);
394
+ leave(o);
340
395
  return out;
341
396
  };
342
397
  return write(value, "");
package/build/hash.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","names":[],"sources":["../src/hash.ts"],"sourcesContent":["/**\n * The content hash of a document: SHA-256 of a string, and a canonical JSON form of a value.\n *\n * The hash is the same on each platform. On Node, `sha256Hex` of UTF-8 input uses `node:crypto` for speed.\n * It reads the same bytes as the portable code. The portable code runs in browsers and for the input `\"wtf8\"`.\n * `canonicalHash(value)` is `sha256Hex(canonicalJson(value))`: equal values give equal hashes, also when their keys have another order.\n */\n\n/** The round constants of SHA-256. */\nconst K: readonly number[] = [\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe,\n 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\n 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,\n 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\n];\n\n/** The options of `sha256Hex`. */\nexport interface Sha256Options {\n /**\n * The bytes that the hash reads, as in `fnv1a32`:\n *\n * - `\"utf8\"` (the default): the UTF-8 bytes. A lone surrogate becomes the bytes of U+FFFD, as `TextEncoder` writes them.\n * - `\"wtf8\"`: the UTF-8 bytes of each code point. A lone surrogate becomes its own 3 bytes (WTF-8).\n *\n * For a string without a lone surrogate, the two inputs give the same hash.\n */\n readonly input?: \"utf8\" | \"wtf8\";\n}\n\n/**\n * This function writes the bytes of a string into `out` and gives the count of the bytes. With no `out`, it only counts.\n * It reads the UTF-16 code units, so it makes no string for each character.\n */\nfunction writeBytes(text: string, wtf8: boolean, out?: Uint8Array): number {\n let n = 0;\n for (let i = 0; i < text.length; i++) {\n let c = text.charCodeAt(i);\n if (c >= 0xd800 && c < 0xe000) {\n const low = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;\n if (c < 0xdc00 && low >= 0xdc00 && low < 0xe000) {\n c = 0x10000 + ((c - 0xd800) << 10) + (low - 0xdc00);\n i++;\n } else if (!wtf8) c = 0xfffd;\n }\n if (c < 0x80) {\n if (out !== undefined) out[n] = c;\n n += 1;\n } else if (c < 0x800) {\n if (out !== undefined) {\n out[n] = 0xc0 | (c >> 6);\n out[n + 1] = 0x80 | (c & 63);\n }\n n += 2;\n } else if (c < 0x10000) {\n if (out !== undefined) {\n out[n] = 0xe0 | (c >> 12);\n out[n + 1] = 0x80 | ((c >> 6) & 63);\n out[n + 2] = 0x80 | (c & 63);\n }\n n += 3;\n } else {\n if (out !== undefined) {\n out[n] = 0xf0 | (c >> 18);\n out[n + 1] = 0x80 | ((c >> 12) & 63);\n out[n + 2] = 0x80 | ((c >> 6) & 63);\n out[n + 3] = 0x80 | (c & 63);\n }\n n += 4;\n }\n }\n return n;\n}\n\n/** The part of `node:crypto` that `sha256Hex` uses. */\ninterface NodeCrypto {\n createHash(algorithm: \"sha256\"): { update(data: string, encoding: \"utf8\"): { digest(encoding: \"hex\"): string } };\n}\n\n/** The `node:crypto` module, `null` where the platform has none, or `undefined` before the first look. */\nlet nodeCrypto: NodeCrypto | null | undefined;\n\n/**\n * This function gives `node:crypto` through `process.getBuiltinModule` (Node 22.3 and later), or `null` in a browser or on an older\n * Node. It needs no import, so the module still loads in a browser.\n */\nfunction builtinCrypto(): NodeCrypto | null {\n if (nodeCrypto === undefined) {\n nodeCrypto = null;\n try {\n const proc = (globalThis as { process?: { getBuiltinModule?: (id: string) => unknown } }).process;\n const found = typeof proc?.getBuiltinModule === \"function\" ? (proc.getBuiltinModule(\"node:crypto\") as NodeCrypto | undefined) : undefined;\n if (typeof found?.createHash === \"function\") nodeCrypto = found;\n } catch {\n nodeCrypto = null;\n }\n }\n return nodeCrypto;\n}\n\n/**\n * This function gives the SHA-256 digest of the bytes of a string, as 64 lowercase hex characters.\n * The option `input` selects the bytes of a lone surrogate. It is not for passwords: it has no salt and no cost.\n *\n * On Node, the input `\"utf8\"` goes through `node:crypto`. Node writes a lone surrogate as the bytes of U+FFFD, as `TextEncoder`\n * does, so the hash is the hash of the portable code.\n */\nexport function sha256Hex(text: string, options?: Sha256Options): string {\n const input = options?.input ?? \"utf8\";\n if (input !== \"utf8\" && input !== \"wtf8\") throw new RangeError(`sha256Hex: input is \"utf8\" or \"wtf8\", not ${String(input)}.`);\n const wtf8 = input === \"wtf8\";\n if (!wtf8) {\n const crypto = builtinCrypto();\n if (crypto !== null) return crypto.createHash(\"sha256\").update(text, \"utf8\").digest(\"hex\");\n }\n return portableSha256(text, wtf8);\n}\n\n/** This function gives the SHA-256 digest of the bytes of a string with no API of the platform. */\nfunction portableSha256(text: string, wtf8: boolean): string {\n // The bytes go straight into the padded buffer, so the digest makes one array, not a list of the bytes and a copy.\n const length = writeBytes(text, wtf8);\n const bits = length * 8;\n const total = Math.ceil((length + 9) / 64) * 64;\n const data = new Uint8Array(total);\n writeBytes(text, wtf8, data);\n data[length] = 0x80;\n const view = new DataView(data.buffer);\n view.setUint32(total - 8, Math.floor(bits / 0x100000000));\n view.setUint32(total - 4, bits >>> 0);\n const h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];\n const w = new Uint32Array(64);\n const rotr = (x: number, n: number): number => (x >>> n) | (x << (32 - n));\n for (let off = 0; off < total; off += 64) {\n for (let i = 0; i < 16; i++) w[i] = view.getUint32(off + 4 * i);\n for (let i = 16; i < 64; i++) {\n const a = w[i - 15]!;\n const b = w[i - 2]!;\n const s0 = rotr(a, 7) ^ rotr(a, 18) ^ (a >>> 3);\n const s1 = rotr(b, 17) ^ rotr(b, 19) ^ (b >>> 10);\n w[i] = (w[i - 16]! + s0 + w[i - 7]! + s1) >>> 0;\n }\n let [a, b, c, d, e, f, g, k] = h as [number, number, number, number, number, number, number, number];\n for (let i = 0; i < 64; i++) {\n const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);\n const ch = (e & f) ^ (~e & g);\n const t1 = (k + s1 + ch + K[i]! + w[i]!) >>> 0;\n const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);\n const maj = (a & b) ^ (a & c) ^ (b & c);\n const t2 = (s0 + maj) >>> 0;\n k = g;\n g = f;\n f = e;\n e = (d + t1) >>> 0;\n d = c;\n c = b;\n b = a;\n a = (t1 + t2) >>> 0;\n }\n h[0] = (h[0]! + a) >>> 0;\n h[1] = (h[1]! + b) >>> 0;\n h[2] = (h[2]! + c) >>> 0;\n h[3] = (h[3]! + d) >>> 0;\n h[4] = (h[4]! + e) >>> 0;\n h[5] = (h[5]! + f) >>> 0;\n h[6] = (h[6]! + g) >>> 0;\n h[7] = (h[7]! + k) >>> 0;\n }\n return h.map((x) => x.toString(16).padStart(8, \"0\")).join(\"\");\n}\n\n/** The options of `canonicalJson` and `canonicalHash`. */\nexport interface CanonicalOptions {\n /**\n * The form of the values that JSON does not have:\n *\n * - `\"jcs\"` (the default): RFC 8785. `NaN`, an infinite number and a string with a lone surrogate cause a `RangeError`.\n * - `\"json\"`: the form of `JSON.stringify`. `NaN` and an infinite number become `null`, and a lone surrogate becomes an escape.\n */\n readonly form?: \"jcs\" | \"json\";\n /**\n * The form of a `bigint`. `\"error\"` (the default) causes a `TypeError`, as `JSON.stringify` does.\n * `\"suffix\"` writes the digits and the letter `n`, for example `12n`. This text is not JSON, so use it only for a key.\n */\n readonly bigint?: \"error\" | \"suffix\";\n /**\n * The form of a `Date`, a `RegExp`, a `Map`, a `Set` and a `bigint`:\n *\n * - `\"none\"` (the default): a `Date` gives the text of its `toJSON`, as in `JSON.stringify`.\n * A `RegExp`, a `Map` and a `Set` cause a `TypeError`, because `JSON.stringify` writes them as `{}` and loses their content.\n * - `\"typed\"`: each value gets a tag with its type and its value, for example `Date(0)`, `RegExp(\"/a/g\")`, `Map([1,\"a\"])`, `Set(1,2)` and `12n`.\n *\n * The entries of a `Map` and the items of a `Set` are in the order of their text. Thus the order of insertion does not change the form.\n * With `\"typed\"`, the default of `bigint` is `\"suffix\"`. The text with tags is not JSON, so use it only for a key or a hash.\n */\n readonly tags?: \"none\" | \"typed\";\n}\n\n/** The getter of `RegExp.prototype.source`. It causes a `TypeError` for an object with no slot of a `RegExp`. */\nconst sourceOf = Object.getOwnPropertyDescriptor(RegExp.prototype, \"source\")!.get!;\n\n/** The getter of the `Symbol.toStringTag` of the typed arrays. It gives `undefined` for an object that is not a typed array. */\nconst typedArrayName = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype) as object, Symbol.toStringTag)!.get! as (this: object) => string | undefined;\n\n/** The types that the option `tags: \"typed\"` writes with a tag. */\nconst tagged: ReadonlySet<string> = new Set([\"Date\", \"RegExp\", \"Map\", \"Set\"]);\n\n/** This function is true for an object, and false for `null` and each primitive. */\nconst isObject = (v: unknown): v is object => v !== null && typeof v === \"object\";\n\n/** This function gives the brand of an object: the tag of `Object.prototype.toString`. The brand is the same in each realm. */\nconst brandOf = (o: object): string => Object.prototype.toString.call(o).slice(8, -1);\n\n/** This function is true when `method` accepts `o` as its `this`. Thus it tests an internal slot, the same in each realm. */\nfunction hasSlot(method: (...args: never[]) => unknown, o: object): boolean {\n try {\n Reflect.apply(method, o, []);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * This function gives the primitive value of a boxed `Number`, `String`, `Boolean` or `BigInt`, as `JSON.stringify` does.\n * For each other object, it gives the object.\n */\nfunction unboxed(o: object, brand: string): unknown {\n if (brand === \"Number\" && hasSlot(Number.prototype.valueOf, o)) return Number(o);\n if (brand === \"String\" && hasSlot(String.prototype.valueOf, o)) return String(o);\n if (brand === \"Boolean\" && hasSlot(Boolean.prototype.valueOf, o)) return Boolean.prototype.valueOf.call(o);\n if (brand === \"BigInt\" && hasSlot(BigInt.prototype.valueOf, o)) return BigInt.prototype.valueOf.call(o);\n return o;\n}\n\n/**\n * This function gives the canonical form of a value. The default form is RFC 8785 (JCS):\n *\n * - The keys of each object are in the order of their UTF-16 code units, with no whitespace.\n * - The numbers and the strings have the form of `JSON.stringify`, which is the form of RFC 8785.\n * - A key with the value `undefined` is not in the form. An `undefined` in an array, or as the value, becomes `null`.\n * - An object with a method `toJSON`, for example a `Date`, gives the form of the result of that method.\n * - A boxed `Number`, `String`, `Boolean` or `BigInt` gives the form of its primitive value, as in `JSON.stringify`.\n * - A plain object, an array, an `arguments` object and a typed array give the form of their own enumerable keys.\n * - Each other object causes a `TypeError`, because `JSON.stringify` writes it as `{}` and loses its content.\n * Examples are a `Map`, a `Set`, a `RegExp`, an `Error`, a `WeakMap` and a `Promise`.\n * - A function, a symbol and a cycle cause a `TypeError`.\n * - With the option `tags: \"typed\"`, a `Date`, a `RegExp`, a `Map` and a `Set` get a tag with their value. The option has the forms.\n *\n * The type of an object comes from `Object.prototype.toString` and from its internal slots. Thus a value from another realm gets the same form.\n * An object with its own `Symbol.toStringTag` needs a method `toJSON`. The form does not see private fields.\n *\n * `canonicalJson(JSON.parse(canonicalJson(v)))` is equal to `canonicalJson(v)`, with no tags.\n */\nexport function canonicalJson(value: unknown, options?: CanonicalOptions): string {\n const form = options?.form ?? \"jcs\";\n const tags = options?.tags ?? \"none\";\n if (tags !== \"none\" && tags !== \"typed\") throw new RangeError(`canonicalJson: tags is \"none\" or \"typed\", not ${String(tags)}.`);\n const typed = tags === \"typed\";\n const bigint = options?.bigint ?? (typed ? \"suffix\" : \"error\");\n if (form !== \"jcs\" && form !== \"json\") throw new RangeError(`canonicalJson: form is \"jcs\" or \"json\", not ${String(form)}.`);\n if (bigint !== \"error\" && bigint !== \"suffix\") throw new RangeError(`canonicalJson: bigint is \"error\" or \"suffix\", not ${String(bigint)}.`);\n const jcs = form === \"jcs\";\n const open = new Set<object>();\n const text = (s: string): string => {\n if (jcs && !(s as string & { isWellFormed(): boolean }).isWellFormed()) throw new RangeError(`canonicalJson: the string ${JSON.stringify(s)} has a lone surrogate, which RFC 8785 does not allow.`);\n return JSON.stringify(s);\n };\n // This function gives the tag of a Date, a RegExp, a Map or a Set, and undefined for each other object.\n // It tests the internal slot of each type. Thus a value from another realm gets its tag, and an object with only the name of a type does not.\n const tagOf = (o: object): string | undefined => {\n const brand = brandOf(o);\n if (brand === \"Date\" && hasSlot(Date.prototype.getTime, o)) return `Date(${Date.prototype.getTime.call(o)})`;\n if (brand === \"RegExp\" && hasSlot(sourceOf, o)) return `RegExp(${text(RegExp.prototype.toString.call(o))})`;\n const map = brand === \"Map\" && hasSlot(Map.prototype.has, o);\n if (!map && !(brand === \"Set\" && hasSlot(Set.prototype.has, o))) return undefined;\n if (open.has(o)) throw new TypeError(\"canonicalJson: the value has a cycle.\");\n open.add(o);\n const parts: string[] = [];\n if (map) for (const [k, item] of Map.prototype.entries.call(o) as Iterable<[unknown, unknown]>) parts.push(`[${write(k, \"\")},${write(item, \"\")}]`);\n else for (const item of Set.prototype.values.call(o) as Iterable<unknown>) parts.push(write(item, \"\"));\n open.delete(o);\n return `${map ? \"Map\" : \"Set\"}(${parts.sort().join(\",\")})`;\n };\n // This function gives the text of the TypeError for an object that keeps its content out of its own keys.\n const lost = (brand: string): string => {\n const fix = !typed && tagged.has(brand) ? 'Use the option tags: \"typed\", or give the object a method toJSON.' : \"Give the object a method toJSON.\";\n return `canonicalJson: the type ${brand} has no JSON form. JSON.stringify keeps only its own keys, so two of them with other contents can get the same hash. ${fix}`;\n };\n const write = (v: unknown, key: string): string => {\n if (typed && isObject(v)) {\n const tag = tagOf(v);\n if (tag !== undefined) return tag;\n }\n if (isObject(v) && typeof (v as { toJSON?: unknown }).toJSON === \"function\") {\n v = (v as { toJSON(key: string): unknown }).toJSON(key);\n // A method toJSON can give a Map or a Set. With tags, it gets its tag.\n if (typed && isObject(v)) {\n const tag = tagOf(v);\n if (tag !== undefined) return tag;\n }\n }\n let brand = \"Object\";\n if (isObject(v)) {\n brand = brandOf(v);\n if (brand !== \"Object\") v = unboxed(v, brand);\n }\n if (v === undefined || v === null) return \"null\";\n switch (typeof v) {\n case \"boolean\":\n return v ? \"true\" : \"false\";\n case \"number\":\n if (Number.isFinite(v)) return JSON.stringify(v);\n if (jcs) throw new RangeError(`canonicalJson: ${String(v)} is not a JSON number.`);\n return \"null\";\n case \"string\":\n return text(v);\n case \"bigint\":\n if (bigint === \"suffix\") return `${v}n`;\n throw new TypeError(`canonicalJson: the bigint ${v}n has no JSON form. Use the option bigint: \"suffix\" for a key.`);\n case \"object\":\n break;\n default:\n throw new TypeError(`canonicalJson: a ${typeof v} has no JSON form.`);\n }\n const o = v as object;\n if (brand !== \"Object\" && brand !== \"Arguments\" && !Array.isArray(o) && typedArrayName.call(o) === undefined) throw new TypeError(lost(brand));\n if (open.has(o)) throw new TypeError(\"canonicalJson: the value has a cycle.\");\n open.add(o);\n let out: string;\n if (Array.isArray(o)) out = `[${o.map((item: unknown, i) => write(item, String(i))).join(\",\")}]`;\n else {\n const r = o as Record<string, unknown>;\n const keys = Object.keys(r).filter((k) => r[k] !== undefined).sort();\n out = `{${keys.map((k) => `${text(k)}:${write(r[k], k)}`).join(\",\")}}`;\n }\n open.delete(o);\n return out;\n };\n return write(value, \"\");\n}\n\n/** This function gives the content hash of a value: `sha256Hex(canonicalJson(value, options))`. */\nexport function canonicalHash(value: unknown, options?: CanonicalOptions): string {\n return sha256Hex(canonicalJson(value, options));\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,IAAuB;CAC3B;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;AACtF;;;;;AAmBA,SAAS,WAAW,MAAc,MAAe,KAA0B;CACzE,IAAI,IAAI;CACR,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,IAAI,IAAI,KAAK,WAAW,CAAC;EACzB,IAAI,KAAK,SAAU,IAAI,OAAQ;GAC7B,MAAM,MAAM,IAAI,IAAI,KAAK,SAAS,KAAK,WAAW,IAAI,CAA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,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;OACzF;GACH,MAAM,IAAI;GAEV,MAAM,IADO,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,OAAO,KAAA,CAAS,CAAC,CAAC,KACjD,CAAC,CAAC,KAAK,MAAM,GAAG,KAAK,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;EACtE;EACA,KAAK,OAAO,CAAC;EACb,OAAO;CACT;CACA,OAAO,MAAM,OAAO,EAAE;AACxB;;AAGA,SAAgB,cAAc,OAAgB,SAAoC;CAChF,OAAO,UAAU,cAAc,OAAO,OAAO,CAAC;AAChD"}
1
+ {"version":3,"file":"hash.js","names":[],"sources":["../src/hash.ts"],"sourcesContent":["/**\n * The content hash of a document: SHA-256 of a string, and a canonical JSON form of a value.\n *\n * The hash is the same on each platform. On Node, `sha256Hex` of UTF-8 input uses `node:crypto` for speed.\n * It reads the same bytes as the portable code. The portable code runs in browsers and for the input `\"wtf8\"`.\n * `canonicalHash(value)` is `sha256Hex(canonicalJson(value))`: equal values give equal hashes, also when their keys have another order.\n */\n\n/** The round constants of SHA-256. */\nconst K: readonly number[] = [\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe,\n 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\n 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,\n 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\n];\n\n/** The options of `sha256Hex`. */\nexport interface Sha256Options {\n /**\n * The bytes that the hash reads, as in `fnv1a32`:\n *\n * - `\"utf8\"` (the default): the UTF-8 bytes. A lone surrogate becomes the bytes of U+FFFD, as `TextEncoder` writes them.\n * - `\"wtf8\"`: the UTF-8 bytes of each code point. A lone surrogate becomes its own 3 bytes (WTF-8).\n *\n * For a string without a lone surrogate, the two inputs give the same hash.\n */\n readonly input?: \"utf8\" | \"wtf8\";\n}\n\n/**\n * This function writes the bytes of a string into `out` and gives the count of the bytes. With no `out`, it only counts.\n * It reads the UTF-16 code units, so it makes no string for each character.\n */\nfunction writeBytes(text: string, wtf8: boolean, out?: Uint8Array): number {\n let n = 0;\n for (let i = 0; i < text.length; i++) {\n let c = text.charCodeAt(i);\n if (c >= 0xd800 && c < 0xe000) {\n const low = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;\n if (c < 0xdc00 && low >= 0xdc00 && low < 0xe000) {\n c = 0x10000 + ((c - 0xd800) << 10) + (low - 0xdc00);\n i++;\n } else if (!wtf8) c = 0xfffd;\n }\n if (c < 0x80) {\n if (out !== undefined) out[n] = c;\n n += 1;\n } else if (c < 0x800) {\n if (out !== undefined) {\n out[n] = 0xc0 | (c >> 6);\n out[n + 1] = 0x80 | (c & 63);\n }\n n += 2;\n } else if (c < 0x10000) {\n if (out !== undefined) {\n out[n] = 0xe0 | (c >> 12);\n out[n + 1] = 0x80 | ((c >> 6) & 63);\n out[n + 2] = 0x80 | (c & 63);\n }\n n += 3;\n } else {\n if (out !== undefined) {\n out[n] = 0xf0 | (c >> 18);\n out[n + 1] = 0x80 | ((c >> 12) & 63);\n out[n + 2] = 0x80 | ((c >> 6) & 63);\n out[n + 3] = 0x80 | (c & 63);\n }\n n += 4;\n }\n }\n return n;\n}\n\n/** The part of `node:crypto` that `sha256Hex` uses. */\ninterface NodeCrypto {\n createHash(algorithm: \"sha256\"): { update(data: string, encoding: \"utf8\"): { digest(encoding: \"hex\"): string } };\n}\n\n/** The `node:crypto` module, `null` where the platform has none, or `undefined` before the first look. */\nlet nodeCrypto: NodeCrypto | null | undefined;\n\n/**\n * This function gives `node:crypto` through `process.getBuiltinModule` (Node 22.3 and later), or `null` in a browser or on an older\n * Node. It needs no import, so the module still loads in a browser.\n */\nfunction builtinCrypto(): NodeCrypto | null {\n if (nodeCrypto === undefined) {\n nodeCrypto = null;\n try {\n const proc = (globalThis as { process?: { getBuiltinModule?: (id: string) => unknown } }).process;\n const found = typeof proc?.getBuiltinModule === \"function\" ? (proc.getBuiltinModule(\"node:crypto\") as NodeCrypto | undefined) : undefined;\n if (typeof found?.createHash === \"function\") nodeCrypto = found;\n } catch {\n nodeCrypto = null;\n }\n }\n return nodeCrypto;\n}\n\n/**\n * This function gives the SHA-256 digest of the bytes of a string, as 64 lowercase hex characters.\n * The option `input` selects the bytes of a lone surrogate. It is not for passwords: it has no salt and no cost.\n *\n * On Node, the input `\"utf8\"` goes through `node:crypto`. Node writes a lone surrogate as the bytes of U+FFFD, as `TextEncoder`\n * does, so the hash is the hash of the portable code.\n */\nexport function sha256Hex(text: string, options?: Sha256Options): string {\n const input = options?.input ?? \"utf8\";\n if (input !== \"utf8\" && input !== \"wtf8\") throw new RangeError(`sha256Hex: input is \"utf8\" or \"wtf8\", not ${String(input)}.`);\n const wtf8 = input === \"wtf8\";\n if (!wtf8) {\n const crypto = builtinCrypto();\n if (crypto !== null) return crypto.createHash(\"sha256\").update(text, \"utf8\").digest(\"hex\");\n }\n return portableSha256(text, wtf8);\n}\n\n/** This function gives the SHA-256 digest of the bytes of a string with no API of the platform. */\nfunction portableSha256(text: string, wtf8: boolean): string {\n // The bytes go straight into the padded buffer, so the digest makes one array, not a list of the bytes and a copy.\n const length = writeBytes(text, wtf8);\n const bits = length * 8;\n const total = Math.ceil((length + 9) / 64) * 64;\n const data = new Uint8Array(total);\n writeBytes(text, wtf8, data);\n data[length] = 0x80;\n const view = new DataView(data.buffer);\n view.setUint32(total - 8, Math.floor(bits / 0x100000000));\n view.setUint32(total - 4, bits >>> 0);\n const h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];\n const w = new Uint32Array(64);\n const rotr = (x: number, n: number): number => (x >>> n) | (x << (32 - n));\n for (let off = 0; off < total; off += 64) {\n for (let i = 0; i < 16; i++) w[i] = view.getUint32(off + 4 * i);\n for (let i = 16; i < 64; i++) {\n const a = w[i - 15]!;\n const b = w[i - 2]!;\n const s0 = rotr(a, 7) ^ rotr(a, 18) ^ (a >>> 3);\n const s1 = rotr(b, 17) ^ rotr(b, 19) ^ (b >>> 10);\n w[i] = (w[i - 16]! + s0 + w[i - 7]! + s1) >>> 0;\n }\n let [a, b, c, d, e, f, g, k] = h as [number, number, number, number, number, number, number, number];\n for (let i = 0; i < 64; i++) {\n const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);\n const ch = (e & f) ^ (~e & g);\n const t1 = (k + s1 + ch + K[i]! + w[i]!) >>> 0;\n const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);\n const maj = (a & b) ^ (a & c) ^ (b & c);\n const t2 = (s0 + maj) >>> 0;\n k = g;\n g = f;\n f = e;\n e = (d + t1) >>> 0;\n d = c;\n c = b;\n b = a;\n a = (t1 + t2) >>> 0;\n }\n h[0] = (h[0]! + a) >>> 0;\n h[1] = (h[1]! + b) >>> 0;\n h[2] = (h[2]! + c) >>> 0;\n h[3] = (h[3]! + d) >>> 0;\n h[4] = (h[4]! + e) >>> 0;\n h[5] = (h[5]! + f) >>> 0;\n h[6] = (h[6]! + g) >>> 0;\n h[7] = (h[7]! + k) >>> 0;\n }\n return h.map((x) => x.toString(16).padStart(8, \"0\")).join(\"\");\n}\n\n/** The options of `canonicalJson` and `canonicalHash`. */\nexport interface CanonicalOptions {\n /**\n * The form of the values that JSON does not have:\n *\n * - `\"jcs\"` (the default): RFC 8785. `NaN`, an infinite number and a string with a lone surrogate cause a `RangeError`.\n * - `\"json\"`: the form of `JSON.stringify`. `NaN` and an infinite number become `null`, and a lone surrogate becomes an escape.\n */\n readonly form?: \"jcs\" | \"json\";\n /**\n * The form of a `bigint`. `\"error\"` (the default) causes a `TypeError`, as `JSON.stringify` does.\n * `\"suffix\"` writes the digits and the letter `n`, for example `12n`. This text is not JSON, so use it only for a key.\n */\n readonly bigint?: \"error\" | \"suffix\";\n /**\n * The form of a `Date`, a `RegExp`, a `Map`, a `Set` and a `bigint`:\n *\n * - `\"none\"` (the default): a `Date` gives the text of its `toJSON`, as in `JSON.stringify`.\n * A `RegExp`, a `Map` and a `Set` cause a `TypeError`, because `JSON.stringify` writes them as `{}` and loses their content.\n * - `\"typed\"`: each value gets a tag with its type and its value, for example `Date(0)`, `RegExp(\"/a/g\")`, `Map([1,\"a\"])`, `Set(1,2)` and `12n`.\n *\n * The entries of a `Map` and the items of a `Set` are in the order of their text. Thus the order of insertion does not change the form.\n * With `\"typed\"`, the default of `bigint` is `\"suffix\"`. The text with tags is not JSON, so use it only for a key or a hash.\n */\n readonly tags?: \"none\" | \"typed\";\n}\n\n/** The getter of `RegExp.prototype.source`. It causes a `TypeError` for an object with no slot of a `RegExp`. */\nconst sourceOf = Object.getOwnPropertyDescriptor(RegExp.prototype, \"source\")!.get!;\n\n/** The getter of the `Symbol.toStringTag` of the typed arrays. It gives `undefined` for an object that is not a typed array. */\nconst typedArrayName = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype) as object, Symbol.toStringTag)!.get! as (this: object) => string | undefined;\n\n/** The types that the option `tags: \"typed\"` writes with a tag. */\nconst tagged: ReadonlySet<string> = new Set([\"Date\", \"RegExp\", \"Map\", \"Set\"]);\n\n/** This function gives the brand of an object: the tag of `Object.prototype.toString`. The brand is the same in each realm. */\nconst brandOf = (o: object): string => Object.prototype.toString.call(o).slice(8, -1);\n\n/** This function is true when `method` accepts `o` as its `this`. Thus it tests an internal slot, the same in each realm. */\nfunction hasSlot(method: (...args: never[]) => unknown, o: object): boolean {\n try {\n Reflect.apply(method, o, []);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * This function gives the primitive value of a boxed `Number`, `String`, `Boolean` or `BigInt`, as `JSON.stringify` does.\n * For each other object, it gives the object.\n */\nfunction unboxed(o: object, brand: string): unknown {\n if (brand === \"Number\" && hasSlot(Number.prototype.valueOf, o)) return Number(o);\n if (brand === \"String\" && hasSlot(String.prototype.valueOf, o)) return String(o);\n if (brand === \"Boolean\" && hasSlot(Boolean.prototype.valueOf, o)) return Boolean.prototype.valueOf.call(o);\n if (brand === \"BigInt\" && hasSlot(BigInt.prototype.valueOf, o)) return BigInt.prototype.valueOf.call(o);\n return o;\n}\n\n/**\n * This function sorts the keys of an object in the order of their UTF-16 code units, as `Array.prototype.sort` does with no compare function.\n * The keys are different strings, so each correct sort gives the same order. For a short list, an insertion sort does less work.\n */\nfunction sortKeys(keys: string[]): void {\n if (keys.length > 16) {\n keys.sort();\n return;\n }\n for (let i = 1; i < keys.length; i++) {\n const k = keys[i]!;\n let j = i - 1;\n while (j >= 0 && keys[j]! > k) {\n keys[j + 1] = keys[j]!;\n j--;\n }\n keys[j + 1] = k;\n }\n}\n\n/**\n * This function gives the canonical form of a value. The default form is RFC 8785 (JCS):\n *\n * - The keys of each object are in the order of their UTF-16 code units, with no whitespace.\n * - The numbers and the strings have the form of `JSON.stringify`, which is the form of RFC 8785.\n * - A key with the value `undefined` is not in the form. An `undefined` in an array, or as the value, becomes `null`.\n * - An object with a method `toJSON`, for example a `Date`, gives the form of the result of that method.\n * - A boxed `Number`, `String`, `Boolean` or `BigInt` gives the form of its primitive value, as in `JSON.stringify`.\n * - A plain object, an array, an `arguments` object and a typed array give the form of their own enumerable keys.\n * - Each other object causes a `TypeError`, because `JSON.stringify` writes it as `{}` and loses its content.\n * Examples are a `Map`, a `Set`, a `RegExp`, an `Error`, a `WeakMap` and a `Promise`.\n * - A function, a symbol and a cycle cause a `TypeError`.\n * - With the option `tags: \"typed\"`, a `Date`, a `RegExp`, a `Map` and a `Set` get a tag with their value. The option has the forms.\n *\n * The type of an object comes from `Object.prototype.toString` and from its internal slots. Thus a value from another realm gets the same form.\n * An object with its own `Symbol.toStringTag` needs a method `toJSON`. The form does not see private fields.\n *\n * `canonicalJson(JSON.parse(canonicalJson(v)))` is equal to `canonicalJson(v)`, with no tags.\n */\nexport function canonicalJson(value: unknown, options?: CanonicalOptions): string {\n const form = options?.form ?? \"jcs\";\n const tags = options?.tags ?? \"none\";\n if (tags !== \"none\" && tags !== \"typed\") throw new RangeError(`canonicalJson: tags is \"none\" or \"typed\", not ${String(tags)}.`);\n const typed = tags === \"typed\";\n const bigint = options?.bigint ?? (typed ? \"suffix\" : \"error\");\n if (form !== \"jcs\" && form !== \"json\") throw new RangeError(`canonicalJson: form is \"jcs\" or \"json\", not ${String(form)}.`);\n if (bigint !== \"error\" && bigint !== \"suffix\") throw new RangeError(`canonicalJson: bigint is \"error\" or \"suffix\", not ${String(bigint)}.`);\n const jcs = form === \"jcs\";\n // The open objects are the objects on the path from the value to the current object. An object on the path again is a cycle.\n // The first objects of the path are in an array, so that a plain object needs no hash of its identity. The deep part is in a set.\n const path: object[] = [];\n const deep = new Set<object>();\n const enter = (o: object): void => {\n for (let i = 0; i < path.length; i++) if (path[i] === o) throw new TypeError(\"canonicalJson: the value has a cycle.\");\n if (deep.size > 0 && deep.has(o)) throw new TypeError(\"canonicalJson: the value has a cycle.\");\n if (path.length < 32) path.push(o);\n else deep.add(o);\n };\n // The objects leave in the reverse order of their entry. Thus the last object is in the set when the set is not empty.\n const leave = (o: object): void => {\n if (deep.size > 0) deep.delete(o);\n else path.pop();\n };\n const text = (s: string): string => {\n if (jcs && !(s as string & { isWellFormed(): boolean }).isWellFormed()) throw new RangeError(`canonicalJson: the string ${JSON.stringify(s)} has a lone surrogate, which RFC 8785 does not allow.`);\n return JSON.stringify(s);\n };\n // This function gives the tag of a Date, a RegExp, a Map or a Set, and undefined for each other object.\n // It tests the internal slot of each type. Thus a value from another realm gets its tag, and an object with only the name of a type does not.\n const tagOf = (o: object): string | undefined => {\n const brand = brandOf(o);\n if (brand === \"Date\" && hasSlot(Date.prototype.getTime, o)) return `Date(${Date.prototype.getTime.call(o)})`;\n if (brand === \"RegExp\" && hasSlot(sourceOf, o)) return `RegExp(${text(RegExp.prototype.toString.call(o))})`;\n const map = brand === \"Map\" && hasSlot(Map.prototype.has, o);\n if (!map && !(brand === \"Set\" && hasSlot(Set.prototype.has, o))) return undefined;\n enter(o);\n const parts: string[] = [];\n if (map) for (const [k, item] of Map.prototype.entries.call(o) as Iterable<[unknown, unknown]>) parts.push(`[${write(k, \"\")},${write(item, \"\")}]`);\n else for (const item of Set.prototype.values.call(o) as Iterable<unknown>) parts.push(write(item, \"\"));\n leave(o);\n return `${map ? \"Map\" : \"Set\"}(${parts.sort().join(\",\")})`;\n };\n // This function gives the text of the TypeError for an object that keeps its content out of its own keys.\n const lost = (brand: string): string => {\n const fix = !typed && tagged.has(brand) ? 'Use the option tags: \"typed\", or give the object a method toJSON.' : \"Give the object a method toJSON.\";\n return `canonicalJson: the type ${brand} has no JSON form. JSON.stringify keeps only its own keys, so two of them with other contents can get the same hash. ${fix}`;\n };\n // This function gives the text of a value that is not an object.\n const scalar = (v: unknown): string => {\n if (v === undefined || v === null) return \"null\";\n switch (typeof v) {\n case \"boolean\":\n return v ? \"true\" : \"false\";\n case \"number\":\n // For a finite number, String gives the text of JSON.stringify, with less work.\n if (Number.isFinite(v)) return String(v);\n if (jcs) throw new RangeError(`canonicalJson: ${String(v)} is not a JSON number.`);\n return \"null\";\n case \"string\":\n return text(v);\n case \"bigint\":\n if (bigint === \"suffix\") return `${v}n`;\n throw new TypeError(`canonicalJson: the bigint ${v}n has no JSON form. Use the option bigint: \"suffix\" for a key.`);\n default:\n throw new TypeError(`canonicalJson: a ${typeof v} has no JSON form.`);\n }\n };\n const write = (v: unknown, key: string): string => {\n let isObj = v !== null && typeof v === \"object\";\n if (isObj) {\n if (typed) {\n const tag = tagOf(v as object);\n if (tag !== undefined) return tag;\n }\n if (typeof (v as { toJSON?: unknown }).toJSON === \"function\") {\n v = (v as { toJSON(key: string): unknown }).toJSON(key);\n isObj = v !== null && typeof v === \"object\";\n // A method toJSON can give a Map or a Set. With tags, it gets its tag.\n if (typed && isObj) {\n const tag = tagOf(v as object);\n if (tag !== undefined) return tag;\n }\n }\n }\n if (!isObj) return scalar(v);\n const o = v as object;\n // The brand comes from Object.prototype.toString, as in brandOf. A plain object and an array do not need the slice or unboxed.\n // The prototype does not decide the brand: a Date with the prototype Object.prototype still has the brand Date.\n const toStringTag = Object.prototype.toString.call(o);\n let brand: string;\n if (toStringTag === \"[object Object]\") brand = \"Object\";\n else if (toStringTag === \"[object Array]\") brand = \"Array\";\n else {\n brand = toStringTag.slice(8, -1);\n const primitive = unboxed(o, brand);\n if (primitive !== o) return scalar(primitive);\n }\n // The checks come in the order of version 0.2.3. Thus a proxy gets the same calls of its traps and the same errors.\n let isArray = false;\n const checked = brand !== \"Object\" && brand !== \"Arguments\";\n if (checked) {\n isArray = Array.isArray(o);\n if (!isArray && typedArrayName.call(o) === undefined) throw new TypeError(lost(brand));\n }\n enter(o);\n if (!checked) isArray = Array.isArray(o);\n let out: string;\n if (isArray) out = `[${(o as unknown[]).map((item: unknown, i) => write(item, String(i))).join(\",\")}]`;\n else {\n // The keys get the same reads as in version 0.2.3: one read for the filter, and one read for the text, in the sorted order.\n const r = o as Record<string, unknown>;\n const keys = Object.keys(r);\n let n = 0;\n for (let i = 0; i < keys.length; i++) {\n const k = keys[i]!;\n if (r[k] !== undefined) keys[n++] = k;\n }\n keys.length = n;\n sortKeys(keys);\n out = \"{\";\n for (let i = 0; i < n; i++) {\n const k = keys[i]!;\n out += `${i === 0 ? \"\" : \",\"}${text(k)}:${write(r[k], k)}`;\n }\n out += \"}\";\n }\n leave(o);\n return out;\n };\n return write(value, \"\");\n}\n\n/** This function gives the content hash of a value: `sha256Hex(canonicalJson(value, options))`. */\nexport function canonicalHash(value: unknown, options?: CanonicalOptions): string {\n return sha256Hex(canonicalJson(value, options));\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,IAAuB;CAC3B;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5J;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;AACtF;;;;;AAmBA,SAAS,WAAW,MAAc,MAAe,KAA0B;CACzE,IAAI,IAAI;CACR,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,IAAI,IAAI,KAAK,WAAW,CAAC;EACzB,IAAI,KAAK,SAAU,IAAI,OAAQ;GAC7B,MAAM,MAAM,IAAI,IAAI,KAAK,SAAS,KAAK,WAAW,IAAI,CAAC,IAAI;GAC3D,IAAI,IAAI,SAAU,OAAO,SAAU,MAAM,OAAQ;IAC/C,IAAI,SAAY,IAAI,SAAW,OAAO,MAAM;IAC5C;GACF,OAAO,IAAI,CAAC,MAAM,IAAI;EACxB;EACA,IAAI,IAAI,KAAM;GACZ,IAAI,QAAQ,KAA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GA,SAAgB,cAAc,OAAgB,SAAoC;CAChF,OAAO,UAAU,cAAc,OAAO,OAAO,CAAC;AAChD"}
package/build/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { COVERING_CANDIDATES, COVERING_LIMIT, Coverage, CoveringOptions, coveringArray, coveringRows, tupleCoverage } from "./covering.js";
2
2
  import { DistributionSpec, Param, dependsOnLibm, sampler } from "./distributions.js";
3
3
  import { normalCdf, normalQuantile } from "./normal.js";
4
- import { Distribution, betaCdf, distributionOf, logGamma } from "./quantiles.js";
4
+ import { BetaShares, Distribution, betaCdf, betaShares, distributionOf, logBeta, logGamma } from "./quantiles.js";
5
5
  import { Dimension, InputFamily, Point, SaltelliDesign, familyMap, familyPoints, latinHypercube, oneAtATimePoints, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
6
6
  import { CanonicalOptions, Sha256Options, canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
7
7
  import { SHRINK_CHECKS, SHRINK_TOLERANCE, ShrinkOptions, ShrinkStep, Shrunk, shrinkPoint, shrinkPointAsync, shrinkTarget } from "./shrink.js";
8
8
  import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, RecordedTable, recordedSpec } from "./recorded.js";
9
9
  import { Random, Source, deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
10
- export { COVERING_CANDIDATES, COVERING_LIMIT, type CanonicalOptions, type Coverage, type CoveringOptions, DIAGRAM_BOX_AREA, type Dimension, type Distribution, type DistributionSpec, GIT_BLOB_BYTES, type InputFamily, type Param, type Point, RECORDED_TABLES, type Random, type RecordedTable, SHRINK_CHECKS, SHRINK_TOLERANCE, type SaltelliDesign, type Sha256Options, type ShrinkOptions, type ShrinkStep, type Shrunk, type Source, betaCdf, canonicalHash, canonicalJson, coveringArray, coveringRows, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, logGamma, mulberry32, normalCdf, normalQuantile, oneAtATimePoints, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
10
+ export { type BetaShares, COVERING_CANDIDATES, COVERING_LIMIT, type CanonicalOptions, type Coverage, type CoveringOptions, DIAGRAM_BOX_AREA, type Dimension, type Distribution, type DistributionSpec, GIT_BLOB_BYTES, type InputFamily, type Param, type Point, RECORDED_TABLES, type Random, type RecordedTable, SHRINK_CHECKS, SHRINK_TOLERANCE, type SaltelliDesign, type Sha256Options, type ShrinkOptions, type ShrinkStep, type Shrunk, type Source, betaCdf, betaShares, canonicalHash, canonicalJson, coveringArray, coveringRows, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, logBeta, logGamma, mulberry32, normalCdf, normalQuantile, oneAtATimePoints, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
package/build/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { COVERING_CANDIDATES, COVERING_LIMIT, coveringArray, coveringRows, tupleCoverage } from "./covering.js";
2
2
  import { dependsOnLibm, sampler } from "./distributions.js";
3
3
  import { normalCdf, normalQuantile } from "./normal.js";
4
- import { betaCdf, distributionOf, logGamma } from "./quantiles.js";
4
+ import { betaCdf, betaShares, distributionOf, logBeta, logGamma } from "./quantiles.js";
5
5
  import { familyMap, familyPoints, latinHypercube, oneAtATimePoints, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
6
6
  import { canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
7
7
  import { SHRINK_CHECKS, SHRINK_TOLERANCE, shrinkPoint, shrinkPointAsync, shrinkTarget } from "./shrink.js";
8
8
  import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, recordedSpec } from "./recorded.js";
9
9
  import { deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
10
- export { COVERING_CANDIDATES, COVERING_LIMIT, DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, SHRINK_CHECKS, SHRINK_TOLERANCE, betaCdf, canonicalHash, canonicalJson, coveringArray, coveringRows, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, logGamma, mulberry32, normalCdf, normalQuantile, oneAtATimePoints, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
10
+ export { COVERING_CANDIDATES, COVERING_LIMIT, DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, SHRINK_CHECKS, SHRINK_TOLERANCE, betaCdf, betaShares, canonicalHash, canonicalJson, coveringArray, coveringRows, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, logBeta, logGamma, mulberry32, normalCdf, normalQuantile, oneAtATimePoints, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, shrinkPoint, shrinkPointAsync, shrinkTarget, stablePick, stratifiedDesign, tupleCoverage };
@@ -16,7 +16,33 @@ export interface Distribution {
16
16
  * The relative error is below 1e-14, away from the zeros at 1 and 2. Below 0.5, the reflection formula gives the value.
17
17
  */
18
18
  export declare function logGamma(x: number): number;
19
- /** This function gives the regularized incomplete beta function: the beta cumulative distribution at `x`. */
19
+ /**
20
+ * This function gives the logarithm of the beta function, `logGamma(a) + logGamma(b) - logGamma(a + b)`, for `a` and `b` above 0.
21
+ * - When an argument is 10 or more, the Stirling series gives the difference of the large terms (as `lbeta` of R).
22
+ * Thus the value is accurate also when `a + b` is near 1e13. There, the sum of `logGamma` loses all digits of the difference.
23
+ * - When both arguments are below 10, the value is the sum of `logGamma`.
24
+ */
25
+ export declare function logBeta(a: number, b: number): number;
26
+ /** The shares of a beta law below and above a point. */
27
+ export interface BetaShares {
28
+ /** The share of the law below the point: the regularized incomplete beta function. */
29
+ readonly below: number;
30
+ /** The share of the law above the point. */
31
+ readonly above: number;
32
+ }
33
+ /**
34
+ * This function gives the shares of the beta law with the parameters `a` and `b` below and above `x`.
35
+ * - The caller gives `x` and `y = 1 - x`, each with its full digits. Thus a point near 1 keeps the digits of its distance from 1.
36
+ * For example, `df / (df + t^2)` and `t^2 / (df + t^2)` give both shares of the Student t law with no rounding near 1.
37
+ * - The continued fraction gives the smaller share with its relative digits. The other share is 1 less that share.
38
+ * - The fraction loses digits when its point is near 1 and its first parameter is large. This is the share above `x` when `x` is above `(a + 1) / (a + b + 2)`.
39
+ * The tests hold the relative error of that share below `2e-16 * b`, for `b` from 5e5 to 5e8.
40
+ * - The logs of the front factor use the smaller of `x` and `y`, and the factor uses `logBeta`. Thus a parameter near 1e13 keeps the digits of the shares.
41
+ *
42
+ * @throws RangeError when `x` or `y` is not from 0 to 1, or when `x + y` is not 1
43
+ */
44
+ export declare function betaShares(x: number, y: number, a: number, b: number): BetaShares;
45
+ /** This function gives the regularized incomplete beta function: the beta cumulative distribution at `x` (`betaShares` with `1 - x`). */
20
46
  export declare function betaCdf(x: number, a: number, b: number): number;
21
47
  /**
22
48
  * This function gives one point of a family, with its `cdf` and its `quantile`. It draws the parameters from `r` in
@@ -1 +1 @@
1
- {"version":3,"file":"quantiles.d.ts","names":[],"sources":["../src/quantiles.ts"],"mappings":";;;iBAOiB;;WAEN,QAAQ;;WAER;;EAET,IAAI;;EAEJ,SAAS;;;;;;wBAYK,SAAS;;wBAwCT,QAAQ,WAAW,WAAW;;;;;;wBA+C9B,eAAe,MAAM,kBAAkB,GAAG,SAAS"}
1
+ {"version":3,"file":"quantiles.d.ts","names":[],"sources":["../src/quantiles.ts"],"mappings":";;;iBAOiB;;WAEN,QAAQ;;WAER;;EAET,IAAI;;EAEJ,SAAS;;;;;;wBAYK,SAAS;;;;;;;wBA6BT,QAAQ,WAAW;;iBA8ClB;;WAEN;;WAEA;;;;;;;;;;;;;wBAcK,WAAW,WAAW,WAAW,WAAW,YAAY;;wBAkBxD,QAAQ,WAAW,WAAW;;;;;;wBA6C9B,eAAe,MAAM,kBAAkB,GAAG,SAAS"}
@@ -23,6 +23,47 @@ function logGamma(x) {
23
23
  const t = y + 7.5;
24
24
  return .5 * Math.log(2 * Math.PI) + (y + .5) * Math.log(t) - t + Math.log(sum);
25
25
  }
26
+ /** The coefficients of the Stirling series of the log of the gamma function: B(2k) / (2k (2k - 1)) for k from 1 to 8. */
27
+ const STIRLING = [
28
+ 1 / 12,
29
+ -1 / 360,
30
+ 1 / 1260,
31
+ -1 / 1680,
32
+ 1 / 1188,
33
+ -691 / 360360,
34
+ 1 / 156,
35
+ -3617 / 122400
36
+ ];
37
+ /**
38
+ * This function gives the Stirling correction: `logGamma(x)` less `(x - 0.5) log x - x + log(2 pi) / 2`, for `x` of 10 or more.
39
+ * At 10, the first term that the series omits is below 2e-18.
40
+ */
41
+ function stirlingCorrection(x) {
42
+ const square = 1 / (x * x);
43
+ let sum = 0;
44
+ for (let i = STIRLING.length - 1; i >= 0; i--) sum = sum * square + STIRLING[i];
45
+ return sum / x;
46
+ }
47
+ /**
48
+ * This function gives the logarithm of the beta function, `logGamma(a) + logGamma(b) - logGamma(a + b)`, for `a` and `b` above 0.
49
+ * - When an argument is 10 or more, the Stirling series gives the difference of the large terms (as `lbeta` of R).
50
+ * Thus the value is accurate also when `a + b` is near 1e13. There, the sum of `logGamma` loses all digits of the difference.
51
+ * - When both arguments are below 10, the value is the sum of `logGamma`.
52
+ */
53
+ function logBeta(a, b) {
54
+ const p = Math.min(a, b);
55
+ const q = Math.max(a, b);
56
+ const share = p / (p + q);
57
+ if (p >= 10) {
58
+ const correction = stirlingCorrection(p) + stirlingCorrection(q) - stirlingCorrection(p + q);
59
+ return -.5 * Math.log(q) + .5 * Math.log(2 * Math.PI) + correction + (p - .5) * Math.log(share) + q * Math.log1p(-share);
60
+ }
61
+ if (q >= 10) {
62
+ const correction = stirlingCorrection(q) - stirlingCorrection(p + q);
63
+ return logGamma(p) + correction + p - p * Math.log(p + q) + (q - .5) * Math.log1p(-share);
64
+ }
65
+ return logGamma(p) + logGamma(q) - logGamma(p + q);
66
+ }
26
67
  /** This function gives the continued fraction of the incomplete beta function (the method of Lentz). */
27
68
  function betaFraction(a, b, x) {
28
69
  const tiny = 1e-300;
@@ -52,14 +93,49 @@ function betaFraction(a, b, x) {
52
93
  }
53
94
  return h;
54
95
  }
55
- /** This function gives the regularized incomplete beta function: the beta cumulative distribution at `x`. */
96
+ /**
97
+ * This function gives the shares of the beta law with the parameters `a` and `b` below and above `x`.
98
+ * - The caller gives `x` and `y = 1 - x`, each with its full digits. Thus a point near 1 keeps the digits of its distance from 1.
99
+ * For example, `df / (df + t^2)` and `t^2 / (df + t^2)` give both shares of the Student t law with no rounding near 1.
100
+ * - The continued fraction gives the smaller share with its relative digits. The other share is 1 less that share.
101
+ * - The fraction loses digits when its point is near 1 and its first parameter is large. This is the share above `x` when `x` is above `(a + 1) / (a + b + 2)`.
102
+ * The tests hold the relative error of that share below `2e-16 * b`, for `b` from 5e5 to 5e8.
103
+ * - The logs of the front factor use the smaller of `x` and `y`, and the factor uses `logBeta`. Thus a parameter near 1e13 keeps the digits of the shares.
104
+ *
105
+ * @throws RangeError when `x` or `y` is not from 0 to 1, or when `x + y` is not 1
106
+ */
107
+ function betaShares(x, y, a, b) {
108
+ if (!(x >= 0 && x <= 1 && y >= 0 && y <= 1 && Math.abs(x + y - 1) <= 1e-12)) throw new RangeError(`betaShares: x and y are from 0 to 1 and their sum is 1, not ${x} and ${y}.`);
109
+ if (x === 0) return {
110
+ below: 0,
111
+ above: 1
112
+ };
113
+ if (y === 0) return {
114
+ below: 1,
115
+ above: 0
116
+ };
117
+ const logX = x < .5 ? Math.log(x) : Math.log1p(-y);
118
+ const logY = y < .5 ? Math.log(y) : Math.log1p(-x);
119
+ const front = Math.exp(a * logX + b * logY - logBeta(a, b));
120
+ if (x < (a + 1) / (a + b + 2)) {
121
+ const below = front * betaFraction(a, b, x) / a;
122
+ return {
123
+ below,
124
+ above: 1 - below
125
+ };
126
+ }
127
+ const above = front * betaFraction(b, a, y) / b;
128
+ return {
129
+ below: 1 - above,
130
+ above
131
+ };
132
+ }
133
+ /** This function gives the regularized incomplete beta function: the beta cumulative distribution at `x` (`betaShares` with `1 - x`). */
56
134
  function betaCdf(x, a, b) {
57
135
  if (Number.isNaN(x)) return NaN;
58
136
  if (x <= 0) return 0;
59
137
  if (x >= 1) return 1;
60
- const front = Math.exp(logGamma(a + b) - logGamma(a) - logGamma(b) + a * Math.log(x) + b * Math.log1p(-x));
61
- if (x < (a + 1) / (a + b + 2)) return front * betaFraction(a, b, x) / a;
62
- return 1 - front * betaFraction(b, a, 1 - x) / b;
138
+ return betaShares(x, 1 - x, a, b).below;
63
139
  }
64
140
  /**
65
141
  * This function gives the smallest `x` from `lo` to `hi` whose `cdf` is `u` or more, by bisection.
@@ -216,6 +292,6 @@ function distributionOf(spec, r) {
216
292
  }
217
293
  }
218
294
  }
219
- export { betaCdf, distributionOf, logGamma };
295
+ export { betaCdf, betaShares, distributionOf, logBeta, logGamma };
220
296
 
221
297
  //# sourceMappingURL=quantiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"quantiles.js","names":[],"sources":["../src/quantiles.ts"],"sourcesContent":["// The cumulative distribution and the quantile of each family of `distributions.ts`. A design draws a uniform number u\n// in each stratum and gives the quantile of u. So the Latin hypercube and the stratified designs work with each family.\nimport type { DistributionSpec, Param } from \"./distributions.ts\";\nimport { normalCdf, normalQuantile } from \"./normal.ts\";\nimport type { Random } from \"./random.ts\";\n\n/** One point of a family: its parameters are fixed. */\nexport interface Distribution {\n /** The family of the point. */\n readonly family: DistributionSpec[\"family\"];\n /** True when the values are a finite set, as in `zipf` and `recorded`. */\n readonly discrete: boolean;\n /** This function gives the probability of a value at or below `x`. */\n cdf(x: number): number;\n /** This function gives the smallest value whose `cdf` is `u` or more. `u` is from 0 to 1. */\n quantile(u: number): number;\n}\n\nconst LANCZOS = [\n 0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012,\n 9.9843695780195716e-6, 1.5056327351493116e-7,\n];\n\n/**\n * This function gives the logarithm of the gamma function for `x` above 0 (Lanczos, g 7, 9 terms).\n * The relative error is below 1e-14, away from the zeros at 1 and 2. Below 0.5, the reflection formula gives the value.\n */\nexport function logGamma(x: number): number {\n if (x < 0.5) return Math.log(Math.PI / Math.sin(Math.PI * x)) - logGamma(1 - x);\n const y = x - 1;\n let sum = LANCZOS[0]!;\n for (let i = 1; i < 9; i++) sum += LANCZOS[i]! / (y + i);\n const t = y + 7.5;\n return 0.5 * Math.log(2 * Math.PI) + (y + 0.5) * Math.log(t) - t + Math.log(sum);\n}\n\n/** This function gives the continued fraction of the incomplete beta function (the method of Lentz). */\nfunction betaFraction(a: number, b: number, x: number): number {\n const tiny = 1e-300;\n let c = 1;\n let d = 1 - ((a + b) * x) / (a + 1);\n if (Math.abs(d) < tiny) d = tiny;\n d = 1 / d;\n let h = d;\n for (let m = 1; m <= 1000; m++) {\n const m2 = 2 * m;\n let aa = (m * (b - m) * x) / ((a + m2 - 1) * (a + m2));\n d = 1 + aa * d;\n if (Math.abs(d) < tiny) d = tiny;\n c = 1 + aa / c;\n if (Math.abs(c) < tiny) c = tiny;\n d = 1 / d;\n h *= d * c;\n aa = (-(a + m) * (a + b + m) * x) / ((a + m2) * (a + m2 + 1));\n d = 1 + aa * d;\n if (Math.abs(d) < tiny) d = tiny;\n c = 1 + aa / c;\n if (Math.abs(c) < tiny) c = tiny;\n d = 1 / d;\n const step = d * c;\n h *= step;\n if (Math.abs(step - 1) < 1e-16) break;\n }\n return h;\n}\n\n/** This function gives the regularized incomplete beta function: the beta cumulative distribution at `x`. */\nexport function betaCdf(x: number, a: number, b: number): number {\n if (Number.isNaN(x)) return Number.NaN;\n if (x <= 0) return 0;\n if (x >= 1) return 1;\n const front = Math.exp(logGamma(a + b) - logGamma(a) - logGamma(b) + a * Math.log(x) + b * Math.log1p(-x));\n if (x < (a + 1) / (a + b + 2)) return (front * betaFraction(a, b, x)) / a;\n return 1 - (front * betaFraction(b, a, 1 - x)) / b;\n}\n\n/**\n * This function gives the smallest `x` from `lo` to `hi` whose `cdf` is `u` or more, by bisection.\n * The caller makes sure that `cdf(lo)` is `u` or less and `cdf(hi)` is `u` or more.\n */\nfunction bisect(cdf: (x: number) => number, u: number, lo: number, hi: number): number {\n for (let i = 0; i < 2000 && lo < hi; i++) {\n const mid = lo + (hi - lo) / 2;\n if (mid <= lo || mid >= hi) break;\n if (cdf(mid) >= u) hi = mid;\n else lo = mid;\n }\n return cdf(lo) >= u ? lo : hi;\n}\n\n/** This function examines a parameter, as `sampler` does. Both ends of a range must pass `valid`. */\nfunction checked(family: string, name: string, param: Param, valid: (value: number) => boolean, rule: string): void {\n const ends = typeof param === \"number\" ? [param] : param;\n for (const value of ends) {\n if (!Number.isFinite(value) || !valid(value)) throw new RangeError(`${family}: ${name} is ${value}, and it must be ${rule}.`);\n }\n if (typeof param !== \"number\" && param[0] > param[1]) throw new RangeError(`${family}: the range of ${name} starts above its end.`);\n}\n\n/** This function gives the value of a parameter: the number, or one draw from the range. */\nfunction valueOf(param: Param, r: Random): number {\n return typeof param === \"number\" ? param : r.range(param[0], param[1]);\n}\n\n/** This function examines `u` of a quantile. */\nfunction unit(u: number): void {\n if (!(u >= 0 && u <= 1)) throw new RangeError(`quantile: u is ${u}, and it must be from 0 to 1.`);\n}\n\n/**\n * This function gives one point of a family, with its `cdf` and its `quantile`. It draws the parameters from `r` in\n * the order of `sampler`. Thus the same seed gives the same point of the family as `sampler`.\n * The values use `Math.exp`, `Math.log` or `Math.pow` when `dependsOnLibm` of the family is true.\n */\nexport function distributionOf(spec: DistributionSpec, r: Random): Distribution {\n switch (spec.family) {\n case \"lognormal\": {\n checked(\"lognormal\", \"sigma\", spec.sigma, (v) => v >= 0, \"0 or more\");\n checked(\"lognormal\", \"mu\", spec.mu, () => true, \"finite\");\n const mu = valueOf(spec.mu, r);\n const sigma = valueOf(spec.sigma, r);\n const median = Math.exp(mu);\n return {\n family: \"lognormal\",\n discrete: false,\n cdf: (x) => (Number.isNaN(x) ? Number.NaN : x <= 0 ? 0 : sigma === 0 ? (x >= median ? 1 : 0) : normalCdf((Math.log(x) - mu) / sigma)),\n quantile: (u) => {\n unit(u);\n return sigma === 0 ? median : Math.exp(mu + sigma * normalQuantile(u));\n },\n };\n }\n case \"pareto\": {\n checked(\"pareto\", \"scale\", spec.scale, (v) => v > 0, \"above 0\");\n checked(\"pareto\", \"shape\", spec.shape, (v) => v > 0, \"above 0\");\n const scale = valueOf(spec.scale, r);\n const shape = valueOf(spec.shape, r);\n return {\n family: \"pareto\",\n discrete: false,\n cdf: (x) => (x < scale ? 0 : 1 - Math.pow(scale / x, shape)),\n quantile: (u) => {\n unit(u);\n return scale / Math.pow(1 - u, 1 / shape);\n },\n };\n }\n case \"zipf\": {\n if (!Number.isSafeInteger(spec.n) || spec.n < 1) throw new RangeError(`zipf: n is ${spec.n}, and it must be a whole number of 1 or more.`);\n checked(\"zipf\", \"exponent\", spec.exponent, (v) => v >= 0, \"0 or more\");\n const exponent = valueOf(spec.exponent, r);\n const totals: number[] = [];\n let total = 0;\n for (let rank = 1; rank <= spec.n; rank++) {\n total += Math.pow(rank, -exponent);\n totals.push(total);\n }\n return {\n family: \"zipf\",\n discrete: true,\n cdf: (x) => (x < 1 ? 0 : x >= spec.n ? 1 : totals[Math.floor(x) - 1]! / total),\n quantile: (u) => {\n unit(u);\n const at = u * total;\n let lo = 0;\n let hi = spec.n - 1;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (totals[mid]! >= at) hi = mid;\n else lo = mid + 1;\n }\n return lo + 1;\n },\n };\n }\n case \"beta\": {\n checked(\"beta\", \"a\", spec.a, (v) => v > 0, \"above 0\");\n checked(\"beta\", \"b\", spec.b, (v) => v > 0, \"above 0\");\n const a = valueOf(spec.a, r);\n const b = valueOf(spec.b, r);\n const cdf = (x: number): number => betaCdf(x, a, b);\n return {\n family: \"beta\",\n discrete: false,\n cdf,\n quantile: (u) => {\n unit(u);\n return u === 0 ? 0 : u === 1 ? 1 : bisect(cdf, u, 0, 1);\n },\n };\n }\n case \"mixture\": {\n if (spec.parts.length === 0) throw new RangeError(\"mixture: the list of the parts is empty.\");\n for (const { weight } of spec.parts) checked(\"mixture\", \"weight\", weight, (v) => v > 0, \"above 0\");\n const parts = spec.parts.map(({ part }) => distributionOf(part, r));\n const sum = spec.parts.reduce((s, { weight }) => s + weight, 0);\n const weights = spec.parts.map(({ weight }) => weight / sum);\n const cdf = (x: number): number => Math.min(1, parts.reduce((s, part, i) => s + weights[i]! * part.cdf(x), 0));\n return {\n family: \"mixture\",\n discrete: parts.every((part) => part.discrete),\n cdf,\n quantile: (u) => {\n unit(u);\n const ends = parts.map((part) => part.quantile(u));\n const lo = Math.min(...ends);\n const hi = Math.max(...ends);\n return lo === hi || !Number.isFinite(hi) ? hi : bisect(cdf, u, lo, hi);\n },\n };\n }\n case \"recorded\": {\n if (spec.values.length === 0) throw new RangeError(\"recorded: the list of the values is empty.\");\n for (const value of spec.values) checked(\"recorded\", \"value\", value, () => true, \"finite\");\n const sorted = [...spec.values].sort((x, y) => x - y);\n const n = sorted.length;\n return {\n family: \"recorded\",\n discrete: true,\n cdf: (x) => {\n let lo = 0;\n let hi = n;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (sorted[mid]! <= x) lo = mid + 1;\n else hi = mid;\n }\n return lo / n;\n },\n quantile: (u) => {\n unit(u);\n return sorted[Math.max(0, Math.ceil(u * n) - 1)]!;\n },\n };\n }\n }\n}\n"],"mappings":";;AAkBA,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M,IAAI,OAAO;GACjB,OAAO;IACL,QAAQ;IACR,UAAU;IACV,MAAM,MAAM;KACV,IAAI,KAAK;KACT,IAAI,KAAK;KACT,OAAO,KAAK,IAAI;MACd,MAAM,MAAO,KAAK,OAAQ;MAC1B,IAAI,OAAO,QAAS,GAAG,KAAK,MAAM;WAC7B,KAAK;KACZ;KACA,OAAO,KAAK;IACd;IACA,WAAW,MAAM;KACf,KAAK,CAAC;KACN,OAAO,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC;IAChD;GACF;EACF;CACF;AACF"}
1
+ {"version":3,"file":"quantiles.js","names":[],"sources":["../src/quantiles.ts"],"sourcesContent":["// The cumulative distribution and the quantile of each family of `distributions.ts`. A design draws a uniform number u\n// in each stratum and gives the quantile of u. So the Latin hypercube and the stratified designs work with each family.\nimport type { DistributionSpec, Param } from \"./distributions.ts\";\nimport { normalCdf, normalQuantile } from \"./normal.ts\";\nimport type { Random } from \"./random.ts\";\n\n/** One point of a family: its parameters are fixed. */\nexport interface Distribution {\n /** The family of the point. */\n readonly family: DistributionSpec[\"family\"];\n /** True when the values are a finite set, as in `zipf` and `recorded`. */\n readonly discrete: boolean;\n /** This function gives the probability of a value at or below `x`. */\n cdf(x: number): number;\n /** This function gives the smallest value whose `cdf` is `u` or more. `u` is from 0 to 1. */\n quantile(u: number): number;\n}\n\nconst LANCZOS = [\n 0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012,\n 9.9843695780195716e-6, 1.5056327351493116e-7,\n];\n\n/**\n * This function gives the logarithm of the gamma function for `x` above 0 (Lanczos, g 7, 9 terms).\n * The relative error is below 1e-14, away from the zeros at 1 and 2. Below 0.5, the reflection formula gives the value.\n */\nexport function logGamma(x: number): number {\n if (x < 0.5) return Math.log(Math.PI / Math.sin(Math.PI * x)) - logGamma(1 - x);\n const y = x - 1;\n let sum = LANCZOS[0]!;\n for (let i = 1; i < 9; i++) sum += LANCZOS[i]! / (y + i);\n const t = y + 7.5;\n return 0.5 * Math.log(2 * Math.PI) + (y + 0.5) * Math.log(t) - t + Math.log(sum);\n}\n\n/** The coefficients of the Stirling series of the log of the gamma function: B(2k) / (2k (2k - 1)) for k from 1 to 8. */\nconst STIRLING = [1 / 12, -1 / 360, 1 / 1260, -1 / 1680, 1 / 1188, -691 / 360360, 1 / 156, -3617 / 122400];\n\n/**\n * This function gives the Stirling correction: `logGamma(x)` less `(x - 0.5) log x - x + log(2 pi) / 2`, for `x` of 10 or more.\n * At 10, the first term that the series omits is below 2e-18.\n */\nfunction stirlingCorrection(x: number): number {\n const square = 1 / (x * x);\n let sum = 0;\n for (let i = STIRLING.length - 1; i >= 0; i--) sum = sum * square + STIRLING[i]!;\n return sum / x;\n}\n\n/**\n * This function gives the logarithm of the beta function, `logGamma(a) + logGamma(b) - logGamma(a + b)`, for `a` and `b` above 0.\n * - When an argument is 10 or more, the Stirling series gives the difference of the large terms (as `lbeta` of R).\n * Thus the value is accurate also when `a + b` is near 1e13. There, the sum of `logGamma` loses all digits of the difference.\n * - When both arguments are below 10, the value is the sum of `logGamma`.\n */\nexport function logBeta(a: number, b: number): number {\n const p = Math.min(a, b);\n const q = Math.max(a, b);\n const share = p / (p + q);\n if (p >= 10) {\n const correction = stirlingCorrection(p) + stirlingCorrection(q) - stirlingCorrection(p + q);\n return -0.5 * Math.log(q) + 0.5 * Math.log(2 * Math.PI) + correction + (p - 0.5) * Math.log(share) + q * Math.log1p(-share);\n }\n if (q >= 10) {\n const correction = stirlingCorrection(q) - stirlingCorrection(p + q);\n return logGamma(p) + correction + p - p * Math.log(p + q) + (q - 0.5) * Math.log1p(-share);\n }\n return logGamma(p) + logGamma(q) - logGamma(p + q);\n}\n\n/** This function gives the continued fraction of the incomplete beta function (the method of Lentz). */\nfunction betaFraction(a: number, b: number, x: number): number {\n const tiny = 1e-300;\n let c = 1;\n let d = 1 - ((a + b) * x) / (a + 1);\n if (Math.abs(d) < tiny) d = tiny;\n d = 1 / d;\n let h = d;\n for (let m = 1; m <= 1000; m++) {\n const m2 = 2 * m;\n let aa = (m * (b - m) * x) / ((a + m2 - 1) * (a + m2));\n d = 1 + aa * d;\n if (Math.abs(d) < tiny) d = tiny;\n c = 1 + aa / c;\n if (Math.abs(c) < tiny) c = tiny;\n d = 1 / d;\n h *= d * c;\n aa = (-(a + m) * (a + b + m) * x) / ((a + m2) * (a + m2 + 1));\n d = 1 + aa * d;\n if (Math.abs(d) < tiny) d = tiny;\n c = 1 + aa / c;\n if (Math.abs(c) < tiny) c = tiny;\n d = 1 / d;\n const step = d * c;\n h *= step;\n if (Math.abs(step - 1) < 1e-16) break;\n }\n return h;\n}\n\n/** The shares of a beta law below and above a point. */\nexport interface BetaShares {\n /** The share of the law below the point: the regularized incomplete beta function. */\n readonly below: number;\n /** The share of the law above the point. */\n readonly above: number;\n}\n\n/**\n * This function gives the shares of the beta law with the parameters `a` and `b` below and above `x`.\n * - The caller gives `x` and `y = 1 - x`, each with its full digits. Thus a point near 1 keeps the digits of its distance from 1.\n * For example, `df / (df + t^2)` and `t^2 / (df + t^2)` give both shares of the Student t law with no rounding near 1.\n * - The continued fraction gives the smaller share with its relative digits. The other share is 1 less that share.\n * - The fraction loses digits when its point is near 1 and its first parameter is large. This is the share above `x` when `x` is above `(a + 1) / (a + b + 2)`.\n * The tests hold the relative error of that share below `2e-16 * b`, for `b` from 5e5 to 5e8.\n * - The logs of the front factor use the smaller of `x` and `y`, and the factor uses `logBeta`. Thus a parameter near 1e13 keeps the digits of the shares.\n *\n * @throws RangeError when `x` or `y` is not from 0 to 1, or when `x + y` is not 1\n */\nexport function betaShares(x: number, y: number, a: number, b: number): BetaShares {\n if (!(x >= 0 && x <= 1 && y >= 0 && y <= 1 && Math.abs(x + y - 1) <= 1e-12)) {\n throw new RangeError(`betaShares: x and y are from 0 to 1 and their sum is 1, not ${x} and ${y}.`);\n }\n if (x === 0) return { below: 0, above: 1 };\n if (y === 0) return { below: 1, above: 0 };\n const logX = x < 0.5 ? Math.log(x) : Math.log1p(-y);\n const logY = y < 0.5 ? Math.log(y) : Math.log1p(-x);\n const front = Math.exp(a * logX + b * logY - logBeta(a, b));\n if (x < (a + 1) / (a + b + 2)) {\n const below = (front * betaFraction(a, b, x)) / a;\n return { below, above: 1 - below };\n }\n const above = (front * betaFraction(b, a, y)) / b;\n return { below: 1 - above, above };\n}\n\n/** This function gives the regularized incomplete beta function: the beta cumulative distribution at `x` (`betaShares` with `1 - x`). */\nexport function betaCdf(x: number, a: number, b: number): number {\n if (Number.isNaN(x)) return Number.NaN;\n if (x <= 0) return 0;\n if (x >= 1) return 1;\n return betaShares(x, 1 - x, a, b).below;\n}\n\n/**\n * This function gives the smallest `x` from `lo` to `hi` whose `cdf` is `u` or more, by bisection.\n * The caller makes sure that `cdf(lo)` is `u` or less and `cdf(hi)` is `u` or more.\n */\nfunction bisect(cdf: (x: number) => number, u: number, lo: number, hi: number): number {\n for (let i = 0; i < 2000 && lo < hi; i++) {\n const mid = lo + (hi - lo) / 2;\n if (mid <= lo || mid >= hi) break;\n if (cdf(mid) >= u) hi = mid;\n else lo = mid;\n }\n return cdf(lo) >= u ? lo : hi;\n}\n\n/** This function examines a parameter, as `sampler` does. Both ends of a range must pass `valid`. */\nfunction checked(family: string, name: string, param: Param, valid: (value: number) => boolean, rule: string): void {\n const ends = typeof param === \"number\" ? [param] : param;\n for (const value of ends) {\n if (!Number.isFinite(value) || !valid(value)) throw new RangeError(`${family}: ${name} is ${value}, and it must be ${rule}.`);\n }\n if (typeof param !== \"number\" && param[0] > param[1]) throw new RangeError(`${family}: the range of ${name} starts above its end.`);\n}\n\n/** This function gives the value of a parameter: the number, or one draw from the range. */\nfunction valueOf(param: Param, r: Random): number {\n return typeof param === \"number\" ? param : r.range(param[0], param[1]);\n}\n\n/** This function examines `u` of a quantile. */\nfunction unit(u: number): void {\n if (!(u >= 0 && u <= 1)) throw new RangeError(`quantile: u is ${u}, and it must be from 0 to 1.`);\n}\n\n/**\n * This function gives one point of a family, with its `cdf` and its `quantile`. It draws the parameters from `r` in\n * the order of `sampler`. Thus the same seed gives the same point of the family as `sampler`.\n * The values use `Math.exp`, `Math.log` or `Math.pow` when `dependsOnLibm` of the family is true.\n */\nexport function distributionOf(spec: DistributionSpec, r: Random): Distribution {\n switch (spec.family) {\n case \"lognormal\": {\n checked(\"lognormal\", \"sigma\", spec.sigma, (v) => v >= 0, \"0 or more\");\n checked(\"lognormal\", \"mu\", spec.mu, () => true, \"finite\");\n const mu = valueOf(spec.mu, r);\n const sigma = valueOf(spec.sigma, r);\n const median = Math.exp(mu);\n return {\n family: \"lognormal\",\n discrete: false,\n cdf: (x) => (Number.isNaN(x) ? Number.NaN : x <= 0 ? 0 : sigma === 0 ? (x >= median ? 1 : 0) : normalCdf((Math.log(x) - mu) / sigma)),\n quantile: (u) => {\n unit(u);\n return sigma === 0 ? median : Math.exp(mu + sigma * normalQuantile(u));\n },\n };\n }\n case \"pareto\": {\n checked(\"pareto\", \"scale\", spec.scale, (v) => v > 0, \"above 0\");\n checked(\"pareto\", \"shape\", spec.shape, (v) => v > 0, \"above 0\");\n const scale = valueOf(spec.scale, r);\n const shape = valueOf(spec.shape, r);\n return {\n family: \"pareto\",\n discrete: false,\n cdf: (x) => (x < scale ? 0 : 1 - Math.pow(scale / x, shape)),\n quantile: (u) => {\n unit(u);\n return scale / Math.pow(1 - u, 1 / shape);\n },\n };\n }\n case \"zipf\": {\n if (!Number.isSafeInteger(spec.n) || spec.n < 1) throw new RangeError(`zipf: n is ${spec.n}, and it must be a whole number of 1 or more.`);\n checked(\"zipf\", \"exponent\", spec.exponent, (v) => v >= 0, \"0 or more\");\n const exponent = valueOf(spec.exponent, r);\n const totals: number[] = [];\n let total = 0;\n for (let rank = 1; rank <= spec.n; rank++) {\n total += Math.pow(rank, -exponent);\n totals.push(total);\n }\n return {\n family: \"zipf\",\n discrete: true,\n cdf: (x) => (x < 1 ? 0 : x >= spec.n ? 1 : totals[Math.floor(x) - 1]! / total),\n quantile: (u) => {\n unit(u);\n const at = u * total;\n let lo = 0;\n let hi = spec.n - 1;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (totals[mid]! >= at) hi = mid;\n else lo = mid + 1;\n }\n return lo + 1;\n },\n };\n }\n case \"beta\": {\n checked(\"beta\", \"a\", spec.a, (v) => v > 0, \"above 0\");\n checked(\"beta\", \"b\", spec.b, (v) => v > 0, \"above 0\");\n const a = valueOf(spec.a, r);\n const b = valueOf(spec.b, r);\n const cdf = (x: number): number => betaCdf(x, a, b);\n return {\n family: \"beta\",\n discrete: false,\n cdf,\n quantile: (u) => {\n unit(u);\n return u === 0 ? 0 : u === 1 ? 1 : bisect(cdf, u, 0, 1);\n },\n };\n }\n case \"mixture\": {\n if (spec.parts.length === 0) throw new RangeError(\"mixture: the list of the parts is empty.\");\n for (const { weight } of spec.parts) checked(\"mixture\", \"weight\", weight, (v) => v > 0, \"above 0\");\n const parts = spec.parts.map(({ part }) => distributionOf(part, r));\n const sum = spec.parts.reduce((s, { weight }) => s + weight, 0);\n const weights = spec.parts.map(({ weight }) => weight / sum);\n const cdf = (x: number): number => Math.min(1, parts.reduce((s, part, i) => s + weights[i]! * part.cdf(x), 0));\n return {\n family: \"mixture\",\n discrete: parts.every((part) => part.discrete),\n cdf,\n quantile: (u) => {\n unit(u);\n const ends = parts.map((part) => part.quantile(u));\n const lo = Math.min(...ends);\n const hi = Math.max(...ends);\n return lo === hi || !Number.isFinite(hi) ? hi : bisect(cdf, u, lo, hi);\n },\n };\n }\n case \"recorded\": {\n if (spec.values.length === 0) throw new RangeError(\"recorded: the list of the values is empty.\");\n for (const value of spec.values) checked(\"recorded\", \"value\", value, () => true, \"finite\");\n const sorted = [...spec.values].sort((x, y) => x - y);\n const n = sorted.length;\n return {\n family: \"recorded\",\n discrete: true,\n cdf: (x) => {\n let lo = 0;\n let hi = n;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (sorted[mid]! <= x) lo = m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M,OAAO,MAAM,KAAK,SAAS,KAAK,SAAS,CAAC,CAAC;KACjD,MAAM,KAAK,KAAK,IAAI,GAAG,IAAI;KAC3B,MAAM,KAAK,KAAK,IAAI,GAAG,IAAI;KAC3B,OAAO,OAAO,MAAM,CAAC,OAAO,SAAS,EAAE,IAAI,KAAK,OAAO,KAAK,GAAG,IAAI,EAAE;IACvE;GACF;EACF;EACA,KAAK,YAAY;GACf,IAAI,KAAK,OAAO,WAAW,GAAG,MAAM,IAAI,WAAW,4CAA4C;GAC/F,KAAK,MAAM,SAAS,KAAK,QAAQ,QAAQ,YAAY,SAAS,aAAa,MAAM,QAAQ;GACzF,MAAM,SAAS,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;GACpD,MAAM,IAAI,OAAO;GACjB,OAAO;IACL,QAAQ;IACR,UAAU;IACV,MAAM,MAAM;KACV,IAAI,KAAK;KACT,IAAI,KAAK;KACT,OAAO,KAAK,IAAI;MACd,MAAM,MAAO,KAAK,OAAQ;MAC1B,IAAI,OAAO,QAAS,GAAG,KAAK,MAAM;WAC7B,KAAK;KACZ;KACA,OAAO,KAAK;IACd;IACA,WAAW,MAAM;KACf,KAAK,CAAC;KACN,OAAO,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC;IAChD;GACF;EACF;CACF;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/rigor-generators",
4
- "version": "0.2.3",
4
+ "version": "0.2.5",
5
5
  "description": "A seeded random number generator (mulberry32) with the draws that tests and benchmarks make: integers, picks, weights, shuffles, samples, normal values and named streams. It also gives covering arrays (pairwise and of strength t), and a content hash: SHA-256 and canonical JSON (RFC 8785).",
6
6
  "keywords": [
7
7
  "random",