metanum 2.0.2 → 2.1.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/package.json CHANGED
@@ -1,32 +1,30 @@
1
- {
2
- "name": "metanum",
3
- "version": "2.0.2",
4
- "description": "A javascript library that handles numbers as large as f_ε₀(9e15)",
5
- "main": "metanum.js",
6
- "files": [
7
- "metanum.js",
8
- "format-metanum.js",
9
- "test-interface.html",
10
- "test_mixed.js",
11
- "README.md",
12
- "LICENSE"
13
- ],
14
- "scripts": {
15
- "test": "node test.js",
16
- "example": "node basic-usage.js"
17
- },
18
- "keywords": [
19
- "large-numbers",
20
- "hardy-hierarchy",
21
- "ordinal-arithmetic",
22
- "hyper-operations",
23
- "mathematics"
24
- ],
25
- "author": "dlsdl",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/dlsdl/metanum/issues"
29
- },
30
- "homepage": "https://github.com/dlsdl/metanum"
31
- }
32
-
1
+ {
2
+ "name": "metanum",
3
+ "version": "2.1.0",
4
+ "description": "A javascript library that handles numbers as large as f_ε₀(9e15)",
5
+ "main": "metanum.js",
6
+ "files": [
7
+ "metanum.js",
8
+ "format-metanum.js",
9
+ "test-interface.html",
10
+ "test_mixed.js",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "test": "node test_mixed.js"
16
+ },
17
+ "keywords": [
18
+ "large-numbers",
19
+ "hardy-hierarchy",
20
+ "ordinal-arithmetic",
21
+ "hyper-operations",
22
+ "mathematics"
23
+ ],
24
+ "author": "dlsdl",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/dlsdl/metanum/issues"
28
+ },
29
+ "homepage": "https://github.com/dlsdl/metanum"
30
+ }
package/test_mixed.js CHANGED
@@ -1967,7 +1967,7 @@ checkFormat("Abc100", "Abc100", "1.000Abc100");
1967
1967
  checkFormat("Defg200", "Defg200", "1.000Defg200");
1968
1968
 
1969
1969
  // Symbols and ε:
1970
- checkFormat("!Aa300", "!Aa300", "!2.000Aa300");
1970
+ checkFormat("!Aa300 → !2.000Aa300 (over-budget: layer 1 + de-!-ed compact)", "!Aa300", "!2.000Aa300");
1971
1971
  checkFormat("@Bb400", "@Bb400", "@1.000Bb400");
1972
1972
  checkFormat("1ε500", "1ε500", "1.000000ε500"); // epsilonSignificantDigits = 6
1973
1973
 
@@ -2103,18 +2103,24 @@ MetaNum.maxCols = _savedCols; MetaNum.maxRows = _savedRows;
2103
2103
  // ─────────────────────────────────────
2104
2104
  console.log("\n=== symbol layer semantics ===");
2105
2105
  (function () {
2106
- var om5row = JSON.stringify([1, 0, 0, 0, 0, 0, 1]); // [1 | ω^5] marker row
2106
+ // issue #19: an INTEGER !Aa<n> is the full rule-3 cascade of 10{ω^n}10
2107
+ // ("!" adds one ω^ to the level) — base [10] + (maxRows−1) ordinal rows,
2108
+ // top row [8, 9×n], layer 0. @Aa<n> keeps the same array at layer 1 and
2109
+ // #Aa<n> at layer 2 (one ω^ per symbol).
2107
2110
  var x = MetaNum("!Aa5");
2108
- checkBool("!Aa5 = 10{ω^5}5 marker row", JSON.stringify(x.array[1]) === om5row && x.array.length === 2, true);
2109
- checkBool("!Aa5 de-layers to Aaaaaa5", x.eq(MetaNum("Aaaaaa5")), true);
2111
+ checkBool("!Aa5 = 10{ω^5}10 cascade (19 ordinal rows)",
2112
+ x.array.length === MetaNum.maxRows && x.array[0].length === 1 && x.array[0][0] === 10 &&
2113
+ JSON.stringify(x.array[x.array.length - 1]) === JSON.stringify([8, 9, 9, 9, 9, 9]) && x.layer === 0, true);
2114
+ checkBool("!Aa5 === engine 10{ω^5}10",
2115
+ x.eq(MetaNum._hyperopFromOrdinalRaw(MetaNum.TEN.clone(), MetaNum.TEN.clone(), [0, 0, 0, 0, 0, 1])), true);
2110
2116
  checkBool("!1.000Aa5 = !Aa5 (binary form α=1)", MetaNum("!1.000Aa5").eq(x), true);
2111
2117
  var y = MetaNum("@Aa5");
2112
- checkBool("@Aa5 = !Aaaaaa5 (two ω^ layers)", y.eq(MetaNum("!Aaaaaa5")), true);
2113
- checkBool("@Aa5 layer=1 with ω^5 row", y.layer === 1 && JSON.stringify(y.array[1]) === om5row, true);
2118
+ checkBool("@Aa5 = !Aa5 array at layer 1 (two ω^ layers)",
2119
+ JSON.stringify(y.array) === JSON.stringify(x.array) && y.layer === 1, true);
2114
2120
  checkBool("@1.000Aa5 = @Aa5", MetaNum("@1.000Aa5").eq(y), true);
2115
2121
  var z = MetaNum("#Aa5");
2116
- checkBool("#Aa5 = @Aaaaaa5 (three ω^ layers)", z.eq(MetaNum("@Aaaaaa5")), true);
2117
- checkBool("#Aa5 layer=2", z.layer === 2, true);
2122
+ checkBool("#Aa5 = !Aa5 array at layer 2 (three ω^ layers)",
2123
+ JSON.stringify(z.array) === JSON.stringify(x.array) && z.layer === 2, true);
2118
2124
  var ab = MetaNum("!Ab5");
2119
2125
  checkBool("!Ab5 = 10{ω^(ω+1)}5 (layer 1, row [1,1,1])",
2120
2126
  ab.layer === 1 && JSON.stringify(ab.array[1]) === JSON.stringify([1, 1, 1]), true);
@@ -2227,9 +2233,10 @@ checkFormat("10{100}(10{93}10) → 2.002Aa100",
2227
2233
  MetaNum.arrow(10, 100, MetaNum.arrow(10, 93, 10)), "2.002Aa100");
2228
2234
  // non-diagonal letters keep the [1,10) convention
2229
2235
  checkFormat("Ab100 → 1.000Ab100", MetaNum("Ab100"), "1.000Ab100");
2230
- // symbol de-layering
2231
- checkFormat("!Aa3 → 2.000Aaaa10", MetaNum("!Aa3"), "2.000Aaaa10");
2232
- checkFormat("@Aa3 → !2.000Aaaa10", MetaNum("@Aa3"), "!2.000Aaaa10");
2236
+ // symbol de-layering (decision 1B: base is the argument, display is the
2237
+ // binary form !αAaβ; !Aa3 = Aaaa3 = 10{ω³}3)
2238
+ checkFormat("!Aa3 → !2.000Aa3", MetaNum("!Aa3"), "!2.000Aa3");
2239
+ checkFormat("@Aa3 → @2.000Aa3 (one symbol per ω^ layer, isomorphic to !Aa3)", MetaNum("@Aa3"), "@2.000Aa3");
2233
2240
  // parser roundtrip of the new canonical forms
2234
2241
  checkBool("parse 2.000Aaaa10", MetaNum("2.000Aaaa10").format() === "2.000Aaaa10", true);
2235
2242
  checkBool("parse !2.000Aaaa10", MetaNum("!2.000Aaaa10").format() === "!2.000Aaaa10", true);
@@ -2390,7 +2397,7 @@ console.log("\n=== FORMAT_OPTIONS take effect ===");
2390
2397
  return a && b;
2391
2398
  });
2392
2399
  after("opt epsilonSignificantDigits: 6 → 1.000000ε12, 0 → 1ε12", function () {
2393
- var v = MetaNum("!!!!!!!!!!!!2.000Aa10");
2400
+ var v = MetaNum("1ε12");
2394
2401
  set("epsilonSignificantDigits", 6); var a = format(v) === "1.000000ε12";
2395
2402
  set("epsilonSignificantDigits", 0); var b = format(v) === "1ε12";
2396
2403
  return a && b;
@@ -2400,3 +2407,300 @@ console.log("\n=== FORMAT_OPTIONS take effect ===");
2400
2407
  console.log("\n=== format tests Done ===");
2401
2408
 
2402
2409
 
2410
+
2411
+
2412
+ // ─────────────────────────────────────────────────────────────
2413
+ // issue-17 regression vectors (merged from test.js)
2414
+ // ─────────────────────────────────────────────────────────────
2415
+ function ok(name, cond, extra) { checkBool(name + (extra !== undefined ? " => " + extra : ""), !!cond, true); }
2416
+ function eq(name, got, want) { checkBool(name, got === want, true); }
2417
+
2418
+ // ─────────────────────────────────────────────────────────────
2419
+ // D01 · pow(10, α) must not flip sign below the double subnormal floor
2420
+ // ─────────────────────────────────────────────────────────────
2421
+ console.log("\n=== D01 pow(10, negative alpha) sign ===");
2422
+ [-320, -323, -324, -325, -350, -400].forEach(function (a) {
2423
+ ok("pow(10," + a + ").lt(1)", MetaNum.pow(10, a).lt(1), MetaNum.pow(10, a).toString());
2424
+ });
2425
+ ok("pow(10,-324).mul(1e324).eq(1)",
2426
+ MetaNum.pow(10, -324).mul(MetaNum.fromString("1e324")).eq(1),
2427
+ MetaNum.pow(10, -324).mul(MetaNum.fromString("1e324")).toString());
2428
+ (function monotone() {
2429
+ var prev = MetaNum.pow(10, -320), all = true;
2430
+ for (var a = -321; a >= -400; a--) {
2431
+ var v = MetaNum.pow(10, a);
2432
+ if (!v.lt(prev)) { all = false; break; }
2433
+ prev = v;
2434
+ }
2435
+ ok("pow(10,α) strictly decreasing over α ∈ [-320,-400]", all);
2436
+ })();
2437
+ eq("log10(10^-324) === -324", MetaNum.pow(10, -324).log10().toString(), "-324");
2438
+ ok("pow(10,-320) still < 1 (no regression)", MetaNum.pow(10, -320).lt(1));
2439
+
2440
+ // ─────────────────────────────────────────────────────────────
2441
+ // D02 · toBeaf() must keep the base for 10^e (was "{16}")
2442
+ // ─────────────────────────────────────────────────────────────
2443
+ console.log("\n=== D02 toBeaf base preservation ===");
2444
+ (function () {
2445
+ var v16 = MetaNum.BEAF(10, 16);
2446
+ var s16 = v16.toBeaf();
2447
+ ok("BEAF(10,16).toBeaf() !== '{16}'", s16 !== "{16}", s16);
2448
+ eq("BEAF(10,16).toBeaf()", s16, "{10,16}");
2449
+ ok("fromBeaf(BEAF(10,16).toBeaf()).eq(BEAF(10,16))", MetaNum.fromBeaf(s16).eq(v16), s16);
2450
+ var s100 = MetaNum.BEAF(10, 100).toBeaf();
2451
+ ok("BEAF(10,100) round-trip", MetaNum.fromBeaf(s100).eq(MetaNum.BEAF(10, 100)), s100);
2452
+ eq("fromBeaf('{10,16}').toBeaf()", MetaNum.fromBeaf("{10,16}").toBeaf(), "{10,16}");
2453
+ // documented (< MSI) behavior must not regress
2454
+ eq("BEAF(10,15).toBeaf()", MetaNum.BEAF(10, 15).toBeaf(), "{1000000000000000}");
2455
+ // README examples
2456
+ eq("7625597484987.toBeaf()", new MetaNum(7625597484987).toBeaf(), "{7625597484987}");
2457
+ eq("BEAF(3,3,3).toBeaf()", MetaNum.BEAF(3, 3, 3).toBeaf(), "{3638334640023.7783}");
2458
+ // issue #21 (FU-03): negatives and sub-units keep their semantics
2459
+ eq("(-5).toBeaf()", new MetaNum(-5).toBeaf(), "-{5}");
2460
+ ok("fromBeaf('-{5}').eq(-5)", MetaNum.fromBeaf("-{5}").eq(new MetaNum(-5)));
2461
+ eq("1e-320.toBeaf()", MetaNum("1e-320").toBeaf(), "{10,320}⁻¹");
2462
+ ok("fromBeaf('{10,320}⁻¹').eq(1e-320)", MetaNum.fromBeaf("{10,320}⁻¹").eq(MetaNum("1e-320")));
2463
+ eq("0.001.toBeaf()", MetaNum("0.001").toBeaf(), "{1000}⁻¹");
2464
+ ok("fromBeaf('{1000}⁻¹').eq(0.001)", MetaNum.fromBeaf("{1000}⁻¹").eq(MetaNum("0.001")));
2465
+ eq("(-1e-320).toBeaf()", MetaNum("-1e-320").toBeaf(), "-{10,320}⁻¹");
2466
+ ok("fromBeaf('-{10,320}⁻¹').eq(-1e-320)", MetaNum.fromBeaf("-{10,320}⁻¹").eq(MetaNum("-1e-320")));
2467
+ })();
2468
+
2469
+ // ─────────────────────────────────────────────────────────────
2470
+ // D03 · toBeaf() must never dump internal rows; it fails loudly instead
2471
+ // ─────────────────────────────────────────────────────────────
2472
+ console.log("\n=== D03 toBeaf unrepresentable behavior ===");
2473
+ [["BEAF(10,2,1,1,2)", MetaNum.BEAF(10, 2, 1, 1, 2)],
2474
+ ["BEAF(4,5,6,7,8,9)", MetaNum.BEAF(4, 5, 6, 7, 8, 9)],
2475
+ ["fromArray([[10],[1,2,1]])", MetaNum.fromArray([[10], [1, 2, 1]])]
2476
+ ].forEach(function (p) {
2477
+ var name = p[0], m = p[1], threw = null, out = null;
2478
+ try { out = m.toBeaf(); } catch (e) { threw = e; }
2479
+ ok(name + ".toBeaf() throws a typed error", threw && threw.name === "MetaNumUnrepresentableError" &&
2480
+ threw.code === "METANUM_UNREPRESENTABLE", threw ? threw.name : out);
2481
+ if (out !== null) ok(name + ".toBeaf() has no internal '[' literals", out.indexOf("[") === -1, out);
2482
+ });
2483
+
2484
+ // ─────────────────────────────────────────────────────────────
2485
+ // D04 · format() repeated single-letter chains must not fold to a tiny count
2486
+ // ─────────────────────────────────────────────────────────────
2487
+ console.log("\n=== D04 format repeated-letter chains ===");
2488
+ (function () {
2489
+ eq("format(Z152416) unchanged", format(MetaNum("Z152416")), "1.000Z152,416");
2490
+ var z = format(MetaNum("ZZ152416"));
2491
+ var zz = format(MetaNum("ZZZ152416"));
2492
+ ok("format(ZZ152416) !== '1.000Z3'", z !== "1.000Z3", z);
2493
+ eq("format(ZZ152416)", z, "Z1.000Z152,416");
2494
+ eq("format(ZZZ152416)", zz, "ZZ1.000Z152,416");
2495
+ ok("Z/ZZ/ZZZ values strictly increasing",
2496
+ MetaNum("Z152416").lt(MetaNum("ZZ152416")) &&
2497
+ MetaNum("ZZ152416").lt(MetaNum("ZZZ152416")));
2498
+ // canonical same-letter law: AaAa300 → Aa1.000Aa300 (unchanged)
2499
+ eq("format(AaAa300) law intact", format(MetaNum("AaAa300")), "Aa1.000Aa300");
2500
+ // the buggy family (prefix top row over a dominant lower row)
2501
+ eq("format(YY10)", format(MetaNum("YY10")), "Y1.000Y10");
2502
+ eq("format(ZY10)", format(MetaNum("ZY10")), "Z1.000Y10");
2503
+ eq("format(ZZ10)", format(MetaNum("ZZ10")), "Z1.000Z10");
2504
+ })();
2505
+
2506
+ // ─────────────────────────────────────────────────────────────
2507
+ // D05 · !Aaα with real α (notation-semantics decision 1B)
2508
+ // ─────────────────────────────────────────────────────────────
2509
+ console.log("\n=== D05 !Aa(real alpha) ===");
2510
+ (function () {
2511
+ ok("!Aa0.5 != 0", MetaNum("!Aa0.5").neq(0), MetaNum("!Aa0.5").toString());
2512
+ ok("!Aa1.5 != 0", MetaNum("!Aa1.5").neq(0), MetaNum("!Aa1.5").toString());
2513
+ ok("!Aa2.5 != 0", MetaNum("!Aa2.5").neq(0), MetaNum("!Aa2.5").toString());
2514
+ ok("!Aa1.5 === Aa1.5", MetaNum("!Aa1.5").eq(MetaNum("Aa1.5")));
2515
+ ok("!Aa2.5 === Aaa2.5", MetaNum("!Aa2.5").eq(MetaNum("Aaa2.5")));
2516
+ // issue #19: an INTEGER !Aa<n> is the diagonal 10{ω^n}10 ("!" adds one ω^
2517
+ // to the level), stored as the full rule-3 cascade — the README's original
2518
+ // letter-law anchors (!Aa1 = Aa10, !Aa2 = Aaa10-equivalent engine value).
2519
+ ok("!Aa1 < !Aa2 < !Aa3 < !Aa5 (integer diagonal anchors)",
2520
+ MetaNum("!Aa1").lt(MetaNum("!Aa2")) && MetaNum("!Aa2").lt(MetaNum("!Aa3")) &&
2521
+ MetaNum("!Aa3").lt(MetaNum("!Aa5")));
2522
+ ok("!Aa1.5 < !Aa2.5 (smooth curve below the diagonal)",
2523
+ MetaNum("!Aa1.5").lt(MetaNum("!Aa2.5")));
2524
+ // past the row budget (n ≥ maxCols) the cascade would silently truncate
2525
+ // ω^n down to ω^(maxCols−1): go ONE LAYER UP with the de-!-ed compact
2526
+ // [[n],[1,0,1]] instead (the 300 stays in r0 and the display round-trips)
2527
+ var ob = MetaNum("!Aa300");
2528
+ ok("!Aa300 = [[300],[1,0,1]] at layer 1 (over-budget)",
2529
+ ob.layer === 1 && ob.array.length === 2 &&
2530
+ JSON.stringify(ob.array[0]) === "[300]" && JSON.stringify(ob.array[1]) === "[1,0,1]");
2531
+ ok("!Aa300 > !Aa19 (no truncation to ω^19)",
2532
+ ob.gt(MetaNum("!Aa19")));
2533
+ ok("!Aa300 format/parse round-trip",
2534
+ MetaNum.fromString(format(ob)).eq(ob) && format(ob) === "!2.000Aa300");
2535
+ ok("!Aa20 is the first over-budget case (maxCols = 20)",
2536
+ MetaNum("!Aa20").layer === 1 && MetaNum("!Aa19").layer === 0);
2537
+ ok("@Aa300 / #Aa300 keep the compact one layer higher",
2538
+ MetaNum("@Aa300").layer === 2 && MetaNum("#Aa300").layer === 3 &&
2539
+ MetaNum("@Aa300").gt(MetaNum("!Aa300")) && MetaNum("#Aa300").gt(MetaNum("@Aa300")));
2540
+ ok("!2Aa300 / !2.000Aa300 agree with !Aa300",
2541
+ MetaNum("!2Aa300").eq(ob) && MetaNum("!2.000Aa300").eq(ob));
2542
+ function omegaPow(n) {
2543
+ var c = []; for (var i = 0; i < n; i++) c.push(0); c.push(1);
2544
+ return MetaNum._hyperopFromOrdinalRaw(MetaNum.TEN.clone(), MetaNum.TEN.clone(), c);
2545
+ }
2546
+ ok("!Aa1 === Aa10 (10{ω}10 = 10{10}10)", MetaNum("!Aa1").eq(MetaNum("Aa10")));
2547
+ ok("!Aa2 === 10{ω^2}10", MetaNum("!Aa2").eq(omegaPow(2)));
2548
+ ok("!Aa5 === 10{ω^5}10", MetaNum("!Aa5").eq(omegaPow(5)));
2549
+ ok("!Aa10 === 10{ω^10}10", MetaNum("!Aa10").eq(omegaPow(10)));
2550
+ // array shape: [[10]] + (maxRows-1) ordinal rows, top row [8, 9×n], layer 0
2551
+ var a3 = MetaNum("!Aa3");
2552
+ ok("!Aa3 is the full 10{ω^3}10 cascade (19 ordinal rows)",
2553
+ a3.array.length === MetaNum.maxRows && a3.array[0].length === 1 && a3.array[0][0] === 10 &&
2554
+ JSON.stringify(a3.array[a3.array.length - 1]) === "[8,9,9,9]" && a3.layer === 0);
2555
+ ok("@Aa3 = !Aa3 array at layer 1, #Aa3 at layer 2",
2556
+ JSON.stringify(MetaNum("@Aa3").array) === JSON.stringify(a3.array) && MetaNum("@Aa3").layer === 1 &&
2557
+ JSON.stringify(MetaNum("#Aa3").array) === JSON.stringify(a3.array) && MetaNum("#Aa3").layer === 2);
2558
+ ok("Aa3 = 2Aa3 = 10{3}10 → [[10^10,8,8]]",
2559
+ JSON.stringify(MetaNum("Aa3").array) === "[[10000000000,8,8]]" &&
2560
+ JSON.stringify(MetaNum("2Aa3").array) === "[[10000000000,8,8]]");
2561
+ })();
2562
+
2563
+ // ─────────────────────────────────────────────────────────────
2564
+ // D06 · !αAaβ = !Aa(β + log₅(α/2)) (notation-semantics §2, A1)
2565
+ // ─────────────────────────────────────────────────────────────
2566
+ console.log("\n=== D06 !alpha Aa beta ===");
2567
+ (function () {
2568
+ function log5(x) { return Math.log(x) / Math.log(5); }
2569
+ function buildAa(x) {
2570
+ var k = Math.max(1, Math.floor(x));
2571
+ var row = [1];
2572
+ for (var i = 0; i < k; i++) row.push(0);
2573
+ row.push(1);
2574
+ return MetaNum.fromArray([[x], row]);
2575
+ }
2576
+ ok("!2.5Aa4 != 0", MetaNum("!2.5Aa4").neq(0), MetaNum("!2.5Aa4").toString());
2577
+ ok("!1.5Aa4 != 0", MetaNum("!1.5Aa4").neq(0), MetaNum("!1.5Aa4").toString());
2578
+ ok("!1Aa1.5 != 0", MetaNum("!1Aa1.5").neq(0), MetaNum("!1Aa1.5").toString());
2579
+ // formula: !αAaβ == !Aa(β + log5(α/2))
2580
+ ok("!2.5Aa4 == !Aa(4+log5(2.5/2))",
2581
+ MetaNum("!2.5Aa4").eq(buildAa(4 + log5(2.5 / 2))));
2582
+ ok("!1.5Aa4 == !Aa(4+log5(1.5/2))",
2583
+ MetaNum("!1.5Aa4").eq(buildAa(4 + log5(1.5 / 2))));
2584
+ // no regression on the documented anchor (α=2 → log5(1)=0)
2585
+ ok("!2.0000Aa4 === !Aa4", MetaNum("!2.0000Aa4").eq(MetaNum("!Aa4")));
2586
+ // legacy 1.0+ spelling still means "no mantissa"
2587
+ ok("!1.000Aa5 === !Aa5 (legacy)", MetaNum("!1.000Aa5").eq(MetaNum("!Aa5")));
2588
+ // formatter round-trips the true value as the approximate binary form
2589
+ // (issue #20: the README convention α'Aaβ' with α' = 2·5^(x−β'); the
2590
+ // mantissa carries FORMAT_OPTIONS digits, so the round-trip is exact only
2591
+ // when α' is exactly representable — otherwise use rtApprox below)
2592
+ eq("format(!2.5Aa4)", format(MetaNum("!2.5Aa4")), "!2.500Aa4");
2593
+ ok("round-trip !2.5Aa4", MetaNum(format(MetaNum("!2.5Aa4"))).eq(MetaNum("!2.5Aa4")));
2594
+ ok("round-trip !2.376Aa999", MetaNum(format(MetaNum("!2.376Aa999"))).eq(MetaNum("!2.376Aa999")));
2595
+ // issue #20 vectors: the diagonal letters follow the README — Aaα = 10{α}10
2596
+ // (Aa1.5 = 10{2}4.472 = [[924.19,3]], between Aa1 and Aa2), and format is
2597
+ // the APPROXIMATE form α'Aaβ' (α' decimal, β' integer), which the single-
2598
+ // letter machinery then carries to its final display.
2599
+ eq("format(Aa1.5)", format(MetaNum("Aa1.5")), "EE1.537E924");
2600
+ eq("format(Aa2.5)", format(MetaNum("Aa2.5")), "FFFE1.745E9");
2601
+ ok("Aa1.5 = 10{2}(2·5^0.5) → [[924.19,3]]",
2602
+ MetaNum("Aa1.5").eq(MetaNum(10).arrow(2)(2 * Math.pow(5, 0.5))) &&
2603
+ MetaNum("Aa1.5").array.length === 1 && MetaNum("Aa1.5").array[0].length === 2 &&
2604
+ Math.abs(MetaNum("Aa1.5").array[0][0] - 924.1866041055171) < 1e-9 &&
2605
+ MetaNum("Aa1.5").array[0][1] === 3);
2606
+ ok("Aa1 < Aa1.5 < Aa2 (README ordering)",
2607
+ MetaNum("Aa1").lt(MetaNum("Aa1.5")) && MetaNum("Aa1.5").lt(MetaNum("Aa2")));
2608
+ // approximate round-trip: the display carries only FORMAT_OPTIONS digits
2609
+ function rtApprox(s, tol) {
2610
+ var v = MetaNum(s);
2611
+ var m2 = MetaNum.fromString(format(v));
2612
+ if (v.eq(m2)) return true;
2613
+ if (v.cmp_tolerance(m2, tol) === 0) return true;
2614
+ // !Aa compact markers compare structurally — compare the smooth argument
2615
+ // x ([[x],[1,0×k,1]] = 10{ω^k}(x); [[1],[α,β]] = 10{β+1}(α))
2616
+ function smoothArg(m) {
2617
+ if (m.layer === 0 && m.array.length === 2 && m.array[0].length === 1 &&
2618
+ m.array[1].length >= 3 && m.array[1][0] === 1 &&
2619
+ m.array[1][m.array[1].length - 1] === 1) {
2620
+ for (var i = 1; i < m.array[1].length - 1; i++) if (m.array[1][i] !== 0) return null;
2621
+ return m.array[0][0];
2622
+ }
2623
+ if (m.layer === 0 && m.array.length === 2 && m.array[0].length === 1 &&
2624
+ m.array[0][0] === 1 && m.array[1].length === 2) {
2625
+ return m.array[1][1] + log5(m.array[1][0] / 2);
2626
+ }
2627
+ return null;
2628
+ }
2629
+ var av = smoothArg(v), am = smoothArg(m2);
2630
+ if (av !== null && am !== null) {
2631
+ return Math.abs(av - am) <= tol * Math.max(Math.abs(av), Math.abs(am));
2632
+ }
2633
+ return false;
2634
+ }
2635
+ ok("round-trip Aa1.5 (approx)", rtApprox("Aa1.5", 1e-3));
2636
+ ok("round-trip Aa2.5 (approx)", rtApprox("Aa2.5", 1e-3));
2637
+ ok("round-trip !Aa2.5 (approx)", rtApprox("!Aa2.5", 1e-2));
2638
+ ok("round-trip !1Aa1.5 (approx)", rtApprox("!1Aa1.5", 1e-2));
2639
+ ok("round-trip !Aa0.5 (approx)", rtApprox("!Aa0.5", 1e-2));
2640
+ // smooth (non-integer) family stays monotone inside the compact forms
2641
+ ok("!Aa1.5 < !Aa2.5 < !Aa3.5",
2642
+ MetaNum("!Aa1.5").lt(MetaNum("!Aa2.5")) && MetaNum("!Aa2.5").lt(MetaNum("!Aa3.5")));
2643
+ })();
2644
+
2645
+ // ─────────────────────────────────────────────────────────────
2646
+ // D07 · 2{λ}2 = 4 (notation-semantics §3, rule 3)
2647
+ // ─────────────────────────────────────────────────────────────
2648
+ console.log("\n=== D07 2{lambda}2 ===");
2649
+ (function () {
2650
+ var ops = ["aperiote", "aperionate", "iter", "itermult", "cuboiter", "expoiter",
2651
+ "trioterate", "trixxate", "aperixxate", "epsilonate"];
2652
+ // B2-a: for base 2 every infinite/successor level collapses to 4 for any
2653
+ // integer y >= 2 (rule 3 turns the argument into 2).
2654
+ [2, 3, 5, 1000].forEach(function (y) {
2655
+ ops.forEach(function (op) {
2656
+ var v = new MetaNum(2)[op](y);
2657
+ ok("2{" + op + "}" + y + " === 4", v.eq(4), v.toString());
2658
+ });
2659
+ });
2660
+ // finite levels must NOT collapse (2{1}3 = 8, 2{2}3 = 16)
2661
+ ok("2{1}3 === 8 (finite unaffected)", new MetaNum(2).arrow(1)(3).eq(8));
2662
+ ok("2{2}3 === 16 (finite unaffected)", new MetaNum(2).arrow(2)(3).eq(16));
2663
+ ok("3{ω²}1 === 3 (y=1)", new MetaNum(3).aperionate(1).eq(3));
2664
+ ok("3{ω^ω}1 === 3 (y=1)", new MetaNum(3).trixxate(1).eq(3));
2665
+ })();
2666
+
2667
+ // ─────────────────────────────────────────────────────────────
2668
+
2669
+ console.log("\n=== merged issue-17 regression Done ===");
2670
+
2671
+ // ─────────────────────────────────────────────────────────────
2672
+ // v2.1.0: hardy(x, base) / FGH(x, y)
2673
+ // ─────────────────────────────────────────────────────────────
2674
+ console.log("\n=== hardy base extension ===");
2675
+ (function () {
2676
+ // the base-10 path is the historical behaviour (hardy(n) = H_n(10))
2677
+ ok("hardy(0) = 10", MetaNum.hardy(0).eq(10));
2678
+ ok("hardy(9) = 19", MetaNum.hardy(9).eq(19));
2679
+ ok("hardy(10) = 20", MetaNum.hardy(10).eq(20));
2680
+ ok("hardy(100) = 10240", MetaNum.hardy(100).eq(10240));
2681
+ // the second argument is the base: the digits of x are read in that base
2682
+ eq("hardy(10,8) = H_{ω+2}(8) = 20", MetaNum.hardy(10, 8).toString(), "20");
2683
+ eq("hardy(10,4) = H_{ω*2+2}(4) = 24", MetaNum.hardy(10, 4).toString(), "24");
2684
+ eq("hardy(5,8) = H_5(8) = 13", MetaNum.hardy(5, 8).toString(), "13");
2685
+ eq("hardy(9,10) = 19 (default base)", MetaNum.hardy(9, 10).toString(), "19");
2686
+ ok("hardy(64,8) = H_{ω^2}(8) = 2048 (64 = 100 base 8)", MetaNum.hardy(64, 8).eq(2048));
2687
+ ok("hardy(1000,2) huge but finite", MetaNum.hardy(1000, 2).isFinite());
2688
+ ok("hardy monotone in x: hardy(10,8) < hardy(11,8)",
2689
+ MetaNum.hardy(10, 8).lt(MetaNum.hardy(11, 8)));
2690
+ // validation: integer base in [2, 1000]
2691
+ var threw = 0;
2692
+ [1, 1001, 2.5, "x"].forEach(function (b) {
2693
+ try { MetaNum.hardy(10, b); } catch (e) { threw++; }
2694
+ });
2695
+ ok("hardy rejects bases outside [2,1000] / non-integers", threw === 4);
2696
+ // FGH(x, y) = hardy(y^x, y)
2697
+ ok("FGH(3,10) = hardy(1000,10)", MetaNum.fgh(3, 10).eq(MetaNum.hardy(1000, 10)));
2698
+ ok("FGH(2,8) = hardy(64,8) = 2048", MetaNum.fgh(2, 8).eq(2048));
2699
+ ok("FGH(0,10) = hardy(1,10) = 11", MetaNum.fgh(0, 10).eq(11));
2700
+ ok("FGH monotone in x", MetaNum.fgh(2, 10).lt(MetaNum.fgh(3, 10)));
2701
+ ok("FGH validates the base too", (function () {
2702
+ try { MetaNum.fgh(2, 1); return false; } catch (e) { return true; }
2703
+ })());
2704
+ })();
2705
+
2706
+ console.log("\n=== hardy/FGH tests Done ===");