metanum 2.0.3 → 2.1.1
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 +47 -18
- package/format-metanum.js +247 -204
- package/metanum.js +684 -408
- package/package.json +30 -32
- package/test-interface.html +1 -1
- package/test_mixed.js +367 -14
package/package.json
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "metanum",
|
|
3
|
-
"version": "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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "metanum",
|
|
3
|
+
"version": "2.1.1",
|
|
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-interface.html
CHANGED
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
|
|
|
@@ -2023,8 +2023,12 @@ checkFormat("20-row cascade compresses to two letter types", MetaNum.h10000(3, 1
|
|
|
2023
2023
|
// SINGLE-letter form !αΓβ — "!" adds one ω^ layer on top of the level Γ names
|
|
2024
2024
|
checkFormat("10-letter level carries to !1.000M9", MetaNum.iter(3, 10), "!1.000M9");
|
|
2025
2025
|
checkFormat("5-letter level carries to !1.000H4", m3.iter(5), "!1.000H4");
|
|
2026
|
-
|
|
2027
|
-
|
|
2026
|
+
// #28: past multiLetterLimit the pure diagonal keeps the exact token instead
|
|
2027
|
+
// of the old single-letter carry (which did not round-trip).
|
|
2028
|
+
checkFormat("apix(3,10) → exact !2.000A(a×10)10", m3.aperixxate(10), "!2.000A" + "a".repeat(10) + "10");
|
|
2029
|
+
ok("apix(3,10) format round-trip", MetaNum(format(m3.aperixxate(10))).eq(m3.aperixxate(10)));
|
|
2030
|
+
checkFormat("apix(3,5) → exact !A(a×5)10", m3.aperixxate(5), "!A" + "a".repeat(5) + "10");
|
|
2031
|
+
ok("apix(3,5) format round-trip", MetaNum(format(m3.aperixxate(5))).eq(m3.aperixxate(5)));
|
|
2028
2032
|
checkFormat("short diagonal keeps the letter form", m3.aperixxate(3), "!2.000Aaaa10");
|
|
2029
2033
|
checkFormat("cascade inner α stays [1,10) (AbAa600)", "AbAa600", "Ab1.000Aa600");
|
|
2030
2034
|
|
|
@@ -2103,18 +2107,24 @@ MetaNum.maxCols = _savedCols; MetaNum.maxRows = _savedRows;
|
|
|
2103
2107
|
// ─────────────────────────────────────
|
|
2104
2108
|
console.log("\n=== symbol layer semantics ===");
|
|
2105
2109
|
(function () {
|
|
2106
|
-
|
|
2110
|
+
// issue #19: an INTEGER !Aa<n> is the full rule-3 cascade of 10{ω^n}10
|
|
2111
|
+
// ("!" adds one ω^ to the level) — base [10] + (maxRows−1) ordinal rows,
|
|
2112
|
+
// top row [8, 9×n], layer 0. @Aa<n> keeps the same array at layer 1 and
|
|
2113
|
+
// #Aa<n> at layer 2 (one ω^ per symbol).
|
|
2107
2114
|
var x = MetaNum("!Aa5");
|
|
2108
|
-
checkBool("!Aa5 = 10{ω^5}
|
|
2109
|
-
|
|
2115
|
+
checkBool("!Aa5 = 10{ω^5}10 cascade (19 ordinal rows)",
|
|
2116
|
+
x.array.length === MetaNum.maxRows && x.array[0].length === 1 && x.array[0][0] === 10 &&
|
|
2117
|
+
JSON.stringify(x.array[x.array.length - 1]) === JSON.stringify([8, 9, 9, 9, 9, 9]) && x.layer === 0, true);
|
|
2118
|
+
checkBool("!Aa5 === engine 10{ω^5}10",
|
|
2119
|
+
x.eq(MetaNum._hyperopFromOrdinalRaw(MetaNum.TEN.clone(), MetaNum.TEN.clone(), [0, 0, 0, 0, 0, 1])), true);
|
|
2110
2120
|
checkBool("!1.000Aa5 = !Aa5 (binary form α=1)", MetaNum("!1.000Aa5").eq(x), true);
|
|
2111
2121
|
var y = MetaNum("@Aa5");
|
|
2112
|
-
checkBool("@Aa5 = !
|
|
2113
|
-
|
|
2122
|
+
checkBool("@Aa5 = !Aa5 array at layer 1 (two ω^ layers)",
|
|
2123
|
+
JSON.stringify(y.array) === JSON.stringify(x.array) && y.layer === 1, true);
|
|
2114
2124
|
checkBool("@1.000Aa5 = @Aa5", MetaNum("@1.000Aa5").eq(y), true);
|
|
2115
2125
|
var z = MetaNum("#Aa5");
|
|
2116
|
-
checkBool("#Aa5 =
|
|
2117
|
-
|
|
2126
|
+
checkBool("#Aa5 = !Aa5 array at layer 2 (three ω^ layers)",
|
|
2127
|
+
JSON.stringify(z.array) === JSON.stringify(x.array) && z.layer === 2, true);
|
|
2118
2128
|
var ab = MetaNum("!Ab5");
|
|
2119
2129
|
checkBool("!Ab5 = 10{ω^(ω+1)}5 (layer 1, row [1,1,1])",
|
|
2120
2130
|
ab.layer === 1 && JSON.stringify(ab.array[1]) === JSON.stringify([1, 1, 1]), true);
|
|
@@ -2127,6 +2137,29 @@ console.log("\n=== symbol layer semantics ===");
|
|
|
2127
2137
|
checkRT("@Aa5", "@Aa5");
|
|
2128
2138
|
checkRT("#Aa5", "#Aa5");
|
|
2129
2139
|
checkRT("!Ab5", "!Ab5");
|
|
2140
|
+
|
|
2141
|
+
// issue #19 residual: n=1 carries to the single-letter N10 spelling. The
|
|
2142
|
+
// layer prefix must survive (format → parse → eq), not parse to 0.
|
|
2143
|
+
function fmtRT(input) {
|
|
2144
|
+
var v = MetaNum(input);
|
|
2145
|
+
return v.eq(MetaNum(format(v)));
|
|
2146
|
+
}
|
|
2147
|
+
ok("format round-trip @Aa1 (!1.000N10)", fmtRT("@Aa1"), format(MetaNum("@Aa1")));
|
|
2148
|
+
ok("format round-trip #Aa1 (@1.000N10)", fmtRT("#Aa1"), format(MetaNum("#Aa1")));
|
|
2149
|
+
|
|
2150
|
+
// issue #26: non-integer multi-a markers use the exact token spelling
|
|
2151
|
+
// (Aaa1.5) instead of the rounded αAaaβ form (4.472Aaa1).
|
|
2152
|
+
ok("format round-trip @Aa1.5 (!Aaa1.5)", fmtRT("@Aa1.5"), format(MetaNum("@Aa1.5")));
|
|
2153
|
+
ok("format round-trip @Aa2.5 (!Aaaa2.5)", fmtRT("@Aa2.5"), format(MetaNum("@Aa2.5")));
|
|
2154
|
+
ok("format round-trip #Aa2.5 (@Aaaa2.5)", fmtRT("#Aa2.5"), format(MetaNum("#Aa2.5")));
|
|
2155
|
+
|
|
2156
|
+
// issue #28: past multiLetterLimit the pure diagonal keeps the exact token
|
|
2157
|
+
// (the old carry !1.000H10 hard-coded 10 and added a layer).
|
|
2158
|
+
ok("format round-trip Aaaaa3.5", fmtRT("Aaaaa3.5"), format(MetaNum("Aaaaa3.5")));
|
|
2159
|
+
ok("format round-trip Aaaaa5", fmtRT("Aaaaa5"), format(MetaNum("Aaaaa5")));
|
|
2160
|
+
ok("format round-trip Aaaaa10", fmtRT("Aaaaa10"), format(MetaNum("Aaaaa10")));
|
|
2161
|
+
ok("format round-trip @Aa3.5", fmtRT("@Aa3.5"), format(MetaNum("@Aa3.5")));
|
|
2162
|
+
ok("format round-trip #Aa3.5", fmtRT("#Aa3.5"), format(MetaNum("#Aa3.5")));
|
|
2130
2163
|
})();
|
|
2131
2164
|
|
|
2132
2165
|
console.log("\n=== two-letter rule ===");
|
|
@@ -2227,9 +2260,10 @@ checkFormat("10{100}(10{93}10) → 2.002Aa100",
|
|
|
2227
2260
|
MetaNum.arrow(10, 100, MetaNum.arrow(10, 93, 10)), "2.002Aa100");
|
|
2228
2261
|
// non-diagonal letters keep the [1,10) convention
|
|
2229
2262
|
checkFormat("Ab100 → 1.000Ab100", MetaNum("Ab100"), "1.000Ab100");
|
|
2230
|
-
// symbol de-layering
|
|
2231
|
-
|
|
2232
|
-
checkFormat("
|
|
2263
|
+
// symbol de-layering (decision 1B: base is the argument, display is the
|
|
2264
|
+
// binary form !αAaβ; !Aa3 = Aaaa3 = 10{ω³}3)
|
|
2265
|
+
checkFormat("!Aa3 → !2.000Aa3", MetaNum("!Aa3"), "!2.000Aa3");
|
|
2266
|
+
checkFormat("@Aa3 → @2.000Aa3 (one symbol per ω^ layer, isomorphic to !Aa3)", MetaNum("@Aa3"), "@2.000Aa3");
|
|
2233
2267
|
// parser roundtrip of the new canonical forms
|
|
2234
2268
|
checkBool("parse 2.000Aaaa10", MetaNum("2.000Aaaa10").format() === "2.000Aaaa10", true);
|
|
2235
2269
|
checkBool("parse !2.000Aaaa10", MetaNum("!2.000Aaaa10").format() === "!2.000Aaaa10", true);
|
|
@@ -2390,7 +2424,7 @@ console.log("\n=== FORMAT_OPTIONS take effect ===");
|
|
|
2390
2424
|
return a && b;
|
|
2391
2425
|
});
|
|
2392
2426
|
after("opt epsilonSignificantDigits: 6 → 1.000000ε12, 0 → 1ε12", function () {
|
|
2393
|
-
var v = MetaNum("
|
|
2427
|
+
var v = MetaNum("1ε12");
|
|
2394
2428
|
set("epsilonSignificantDigits", 6); var a = format(v) === "1.000000ε12";
|
|
2395
2429
|
set("epsilonSignificantDigits", 0); var b = format(v) === "1ε12";
|
|
2396
2430
|
return a && b;
|
|
@@ -2400,3 +2434,322 @@ console.log("\n=== FORMAT_OPTIONS take effect ===");
|
|
|
2400
2434
|
console.log("\n=== format tests Done ===");
|
|
2401
2435
|
|
|
2402
2436
|
|
|
2437
|
+
|
|
2438
|
+
|
|
2439
|
+
// ─────────────────────────────────────────────────────────────
|
|
2440
|
+
// issue-17 regression vectors (merged from test.js)
|
|
2441
|
+
// ─────────────────────────────────────────────────────────────
|
|
2442
|
+
function ok(name, cond, extra) { checkBool(name + (extra !== undefined ? " => " + extra : ""), !!cond, true); }
|
|
2443
|
+
function eq(name, got, want) { checkBool(name, got === want, true); }
|
|
2444
|
+
|
|
2445
|
+
// ─────────────────────────────────────────────────────────────
|
|
2446
|
+
// D01 · pow(10, α) must not flip sign below the double subnormal floor
|
|
2447
|
+
// ─────────────────────────────────────────────────────────────
|
|
2448
|
+
console.log("\n=== D01 pow(10, negative alpha) sign ===");
|
|
2449
|
+
[-320, -323, -324, -325, -350, -400].forEach(function (a) {
|
|
2450
|
+
ok("pow(10," + a + ").lt(1)", MetaNum.pow(10, a).lt(1), MetaNum.pow(10, a).toString());
|
|
2451
|
+
});
|
|
2452
|
+
ok("pow(10,-324).mul(1e324).eq(1)",
|
|
2453
|
+
MetaNum.pow(10, -324).mul(MetaNum.fromString("1e324")).eq(1),
|
|
2454
|
+
MetaNum.pow(10, -324).mul(MetaNum.fromString("1e324")).toString());
|
|
2455
|
+
(function monotone() {
|
|
2456
|
+
var prev = MetaNum.pow(10, -320), all = true;
|
|
2457
|
+
for (var a = -321; a >= -400; a--) {
|
|
2458
|
+
var v = MetaNum.pow(10, a);
|
|
2459
|
+
if (!v.lt(prev)) { all = false; break; }
|
|
2460
|
+
prev = v;
|
|
2461
|
+
}
|
|
2462
|
+
ok("pow(10,α) strictly decreasing over α ∈ [-320,-400]", all);
|
|
2463
|
+
})();
|
|
2464
|
+
eq("log10(10^-324) === -324", MetaNum.pow(10, -324).log10().toString(), "-324");
|
|
2465
|
+
ok("pow(10,-320) still < 1 (no regression)", MetaNum.pow(10, -320).lt(1));
|
|
2466
|
+
|
|
2467
|
+
// ─────────────────────────────────────────────────────────────
|
|
2468
|
+
// D02 · toBeaf() must keep the base for 10^e (was "{16}")
|
|
2469
|
+
// ─────────────────────────────────────────────────────────────
|
|
2470
|
+
console.log("\n=== D02 toBeaf base preservation ===");
|
|
2471
|
+
(function () {
|
|
2472
|
+
var v16 = MetaNum.BEAF(10, 16);
|
|
2473
|
+
var s16 = v16.toBeaf();
|
|
2474
|
+
ok("BEAF(10,16).toBeaf() !== '{16}'", s16 !== "{16}", s16);
|
|
2475
|
+
eq("BEAF(10,16).toBeaf()", s16, "{10,16}");
|
|
2476
|
+
ok("fromBeaf(BEAF(10,16).toBeaf()).eq(BEAF(10,16))", MetaNum.fromBeaf(s16).eq(v16), s16);
|
|
2477
|
+
var s100 = MetaNum.BEAF(10, 100).toBeaf();
|
|
2478
|
+
ok("BEAF(10,100) round-trip", MetaNum.fromBeaf(s100).eq(MetaNum.BEAF(10, 100)), s100);
|
|
2479
|
+
eq("fromBeaf('{10,16}').toBeaf()", MetaNum.fromBeaf("{10,16}").toBeaf(), "{10,16}");
|
|
2480
|
+
// documented (< MSI) behavior must not regress
|
|
2481
|
+
eq("BEAF(10,15).toBeaf()", MetaNum.BEAF(10, 15).toBeaf(), "{1000000000000000}");
|
|
2482
|
+
// README examples
|
|
2483
|
+
eq("7625597484987.toBeaf()", new MetaNum(7625597484987).toBeaf(), "{7625597484987}");
|
|
2484
|
+
eq("BEAF(3,3,3).toBeaf()", MetaNum.BEAF(3, 3, 3).toBeaf(), "{3638334640023.7783}");
|
|
2485
|
+
// issue #21 (FU-03): negatives and sub-units keep their semantics
|
|
2486
|
+
eq("(-5).toBeaf()", new MetaNum(-5).toBeaf(), "-{5}");
|
|
2487
|
+
ok("fromBeaf('-{5}').eq(-5)", MetaNum.fromBeaf("-{5}").eq(new MetaNum(-5)));
|
|
2488
|
+
eq("1e-320.toBeaf()", MetaNum("1e-320").toBeaf(), "{10,320}⁻¹");
|
|
2489
|
+
ok("fromBeaf('{10,320}⁻¹').eq(1e-320)", MetaNum.fromBeaf("{10,320}⁻¹").eq(MetaNum("1e-320")));
|
|
2490
|
+
eq("0.001.toBeaf()", MetaNum("0.001").toBeaf(), "{1000}⁻¹");
|
|
2491
|
+
ok("fromBeaf('{1000}⁻¹').eq(0.001)", MetaNum.fromBeaf("{1000}⁻¹").eq(MetaNum("0.001")));
|
|
2492
|
+
eq("(-1e-320).toBeaf()", MetaNum("-1e-320").toBeaf(), "-{10,320}⁻¹");
|
|
2493
|
+
ok("fromBeaf('-{10,320}⁻¹').eq(-1e-320)", MetaNum.fromBeaf("-{10,320}⁻¹").eq(MetaNum("-1e-320")));
|
|
2494
|
+
})();
|
|
2495
|
+
|
|
2496
|
+
// ─────────────────────────────────────────────────────────────
|
|
2497
|
+
// D03 · toBeaf() must never dump internal rows; it fails loudly instead
|
|
2498
|
+
// ─────────────────────────────────────────────────────────────
|
|
2499
|
+
console.log("\n=== D03 toBeaf unrepresentable behavior ===");
|
|
2500
|
+
[["BEAF(10,2,1,1,2)", MetaNum.BEAF(10, 2, 1, 1, 2)],
|
|
2501
|
+
["BEAF(4,5,6,7,8,9)", MetaNum.BEAF(4, 5, 6, 7, 8, 9)],
|
|
2502
|
+
["fromArray([[10],[1,2,1]])", MetaNum.fromArray([[10], [1, 2, 1]])]
|
|
2503
|
+
].forEach(function (p) {
|
|
2504
|
+
var name = p[0], m = p[1], threw = null, out = null;
|
|
2505
|
+
try { out = m.toBeaf(); } catch (e) { threw = e; }
|
|
2506
|
+
ok(name + ".toBeaf() throws a typed error", threw && threw.name === "MetaNumUnrepresentableError" &&
|
|
2507
|
+
threw.code === "METANUM_UNREPRESENTABLE", threw ? threw.name : out);
|
|
2508
|
+
if (out !== null) ok(name + ".toBeaf() has no internal '[' literals", out.indexOf("[") === -1, out);
|
|
2509
|
+
});
|
|
2510
|
+
|
|
2511
|
+
// ─────────────────────────────────────────────────────────────
|
|
2512
|
+
// D04 · format() repeated single-letter chains must not fold to a tiny count
|
|
2513
|
+
// ─────────────────────────────────────────────────────────────
|
|
2514
|
+
console.log("\n=== D04 format repeated-letter chains ===");
|
|
2515
|
+
(function () {
|
|
2516
|
+
eq("format(Z152416) unchanged", format(MetaNum("Z152416")), "1.000Z152,416");
|
|
2517
|
+
var z = format(MetaNum("ZZ152416"));
|
|
2518
|
+
var zz = format(MetaNum("ZZZ152416"));
|
|
2519
|
+
ok("format(ZZ152416) !== '1.000Z3'", z !== "1.000Z3", z);
|
|
2520
|
+
eq("format(ZZ152416)", z, "Z1.000Z152,416");
|
|
2521
|
+
eq("format(ZZZ152416)", zz, "ZZ1.000Z152,416");
|
|
2522
|
+
ok("Z/ZZ/ZZZ values strictly increasing",
|
|
2523
|
+
MetaNum("Z152416").lt(MetaNum("ZZ152416")) &&
|
|
2524
|
+
MetaNum("ZZ152416").lt(MetaNum("ZZZ152416")));
|
|
2525
|
+
// canonical same-letter law: AaAa300 → Aa1.000Aa300 (unchanged)
|
|
2526
|
+
eq("format(AaAa300) law intact", format(MetaNum("AaAa300")), "Aa1.000Aa300");
|
|
2527
|
+
// the buggy family (prefix top row over a dominant lower row)
|
|
2528
|
+
eq("format(YY10)", format(MetaNum("YY10")), "Y1.000Y10");
|
|
2529
|
+
eq("format(ZY10)", format(MetaNum("ZY10")), "Z1.000Y10");
|
|
2530
|
+
eq("format(ZZ10)", format(MetaNum("ZZ10")), "Z1.000Z10");
|
|
2531
|
+
})();
|
|
2532
|
+
|
|
2533
|
+
// ─────────────────────────────────────────────────────────────
|
|
2534
|
+
// D05 · !Aaα with real α (notation-semantics decision 1B)
|
|
2535
|
+
// ─────────────────────────────────────────────────────────────
|
|
2536
|
+
console.log("\n=== D05 !Aa(real alpha) ===");
|
|
2537
|
+
(function () {
|
|
2538
|
+
ok("!Aa0.5 != 0", MetaNum("!Aa0.5").neq(0), MetaNum("!Aa0.5").toString());
|
|
2539
|
+
ok("!Aa1.5 != 0", MetaNum("!Aa1.5").neq(0), MetaNum("!Aa1.5").toString());
|
|
2540
|
+
ok("!Aa2.5 != 0", MetaNum("!Aa2.5").neq(0), MetaNum("!Aa2.5").toString());
|
|
2541
|
+
ok("!Aa1.5 === Aa1.5", MetaNum("!Aa1.5").eq(MetaNum("Aa1.5")));
|
|
2542
|
+
ok("!Aa2.5 === Aaa2.5", MetaNum("!Aa2.5").eq(MetaNum("Aaa2.5")));
|
|
2543
|
+
// issue #19: an INTEGER !Aa<n> is the diagonal 10{ω^n}10 ("!" adds one ω^
|
|
2544
|
+
// to the level), stored as the full rule-3 cascade — the README's original
|
|
2545
|
+
// letter-law anchors (!Aa1 = Aa10, !Aa2 = Aaa10-equivalent engine value).
|
|
2546
|
+
ok("!Aa1 < !Aa2 < !Aa3 < !Aa5 (integer diagonal anchors)",
|
|
2547
|
+
MetaNum("!Aa1").lt(MetaNum("!Aa2")) && MetaNum("!Aa2").lt(MetaNum("!Aa3")) &&
|
|
2548
|
+
MetaNum("!Aa3").lt(MetaNum("!Aa5")));
|
|
2549
|
+
ok("!Aa1.5 < !Aa2.5 (smooth curve below the diagonal)",
|
|
2550
|
+
MetaNum("!Aa1.5").lt(MetaNum("!Aa2.5")));
|
|
2551
|
+
// past the row budget (n ≥ maxCols) the cascade would silently truncate
|
|
2552
|
+
// ω^n down to ω^(maxCols−1): go ONE LAYER UP with the de-!-ed compact
|
|
2553
|
+
// [[n],[1,0,1]] instead (the 300 stays in r0 and the display round-trips)
|
|
2554
|
+
var ob = MetaNum("!Aa300");
|
|
2555
|
+
ok("!Aa300 = [[300],[1,0,1]] at layer 1 (over-budget)",
|
|
2556
|
+
ob.layer === 1 && ob.array.length === 2 &&
|
|
2557
|
+
JSON.stringify(ob.array[0]) === "[300]" && JSON.stringify(ob.array[1]) === "[1,0,1]");
|
|
2558
|
+
ok("!Aa300 > !Aa19 (no truncation to ω^19)",
|
|
2559
|
+
ob.gt(MetaNum("!Aa19")));
|
|
2560
|
+
ok("!Aa300 format/parse round-trip",
|
|
2561
|
+
MetaNum.fromString(format(ob)).eq(ob) && format(ob) === "!2.000Aa300");
|
|
2562
|
+
ok("!Aa20 is the first over-budget case (maxCols = 20)",
|
|
2563
|
+
MetaNum("!Aa20").layer === 1 && MetaNum("!Aa19").layer === 0);
|
|
2564
|
+
ok("@Aa300 / #Aa300 keep the compact one layer higher",
|
|
2565
|
+
MetaNum("@Aa300").layer === 2 && MetaNum("#Aa300").layer === 3 &&
|
|
2566
|
+
MetaNum("@Aa300").gt(MetaNum("!Aa300")) && MetaNum("#Aa300").gt(MetaNum("@Aa300")));
|
|
2567
|
+
ok("!2Aa300 / !2.000Aa300 agree with !Aa300",
|
|
2568
|
+
MetaNum("!2Aa300").eq(ob) && MetaNum("!2.000Aa300").eq(ob));
|
|
2569
|
+
function omegaPow(n) {
|
|
2570
|
+
var c = []; for (var i = 0; i < n; i++) c.push(0); c.push(1);
|
|
2571
|
+
return MetaNum._hyperopFromOrdinalRaw(MetaNum.TEN.clone(), MetaNum.TEN.clone(), c);
|
|
2572
|
+
}
|
|
2573
|
+
ok("!Aa1 === Aa10 (10{ω}10 = 10{10}10)", MetaNum("!Aa1").eq(MetaNum("Aa10")));
|
|
2574
|
+
ok("!Aa2 === 10{ω^2}10", MetaNum("!Aa2").eq(omegaPow(2)));
|
|
2575
|
+
ok("!Aa5 === 10{ω^5}10", MetaNum("!Aa5").eq(omegaPow(5)));
|
|
2576
|
+
ok("!Aa10 === 10{ω^10}10", MetaNum("!Aa10").eq(omegaPow(10)));
|
|
2577
|
+
// array shape: [[10]] + (maxRows-1) ordinal rows, top row [8, 9×n], layer 0
|
|
2578
|
+
var a3 = MetaNum("!Aa3");
|
|
2579
|
+
ok("!Aa3 is the full 10{ω^3}10 cascade (19 ordinal rows)",
|
|
2580
|
+
a3.array.length === MetaNum.maxRows && a3.array[0].length === 1 && a3.array[0][0] === 10 &&
|
|
2581
|
+
JSON.stringify(a3.array[a3.array.length - 1]) === "[8,9,9,9]" && a3.layer === 0);
|
|
2582
|
+
ok("@Aa3 = !Aa3 array at layer 1, #Aa3 at layer 2",
|
|
2583
|
+
JSON.stringify(MetaNum("@Aa3").array) === JSON.stringify(a3.array) && MetaNum("@Aa3").layer === 1 &&
|
|
2584
|
+
JSON.stringify(MetaNum("#Aa3").array) === JSON.stringify(a3.array) && MetaNum("#Aa3").layer === 2);
|
|
2585
|
+
ok("Aa3 = 2Aa3 = 10{3}10 → [[10^10,8,8]]",
|
|
2586
|
+
JSON.stringify(MetaNum("Aa3").array) === "[[10000000000,8,8]]" &&
|
|
2587
|
+
JSON.stringify(MetaNum("2Aa3").array) === "[[10000000000,8,8]]");
|
|
2588
|
+
})();
|
|
2589
|
+
|
|
2590
|
+
// ─────────────────────────────────────────────────────────────
|
|
2591
|
+
// D06 · !αAaβ = !Aa(β + log₅(α/2)) (notation-semantics §2, A1)
|
|
2592
|
+
// ─────────────────────────────────────────────────────────────
|
|
2593
|
+
console.log("\n=== D06 !alpha Aa beta ===");
|
|
2594
|
+
(function () {
|
|
2595
|
+
function log5(x) { return Math.log(x) / Math.log(5); }
|
|
2596
|
+
function buildAa(x) {
|
|
2597
|
+
var k = Math.max(1, Math.floor(x));
|
|
2598
|
+
var row = [1];
|
|
2599
|
+
for (var i = 0; i < k; i++) row.push(0);
|
|
2600
|
+
row.push(1);
|
|
2601
|
+
return MetaNum.fromArray([[x], row]);
|
|
2602
|
+
}
|
|
2603
|
+
ok("!2.5Aa4 != 0", MetaNum("!2.5Aa4").neq(0), MetaNum("!2.5Aa4").toString());
|
|
2604
|
+
ok("!1.5Aa4 != 0", MetaNum("!1.5Aa4").neq(0), MetaNum("!1.5Aa4").toString());
|
|
2605
|
+
ok("!1Aa1.5 != 0", MetaNum("!1Aa1.5").neq(0), MetaNum("!1Aa1.5").toString());
|
|
2606
|
+
// formula: !αAaβ == !Aa(β + log5(α/2))
|
|
2607
|
+
ok("!2.5Aa4 == !Aa(4+log5(2.5/2))",
|
|
2608
|
+
MetaNum("!2.5Aa4").eq(buildAa(4 + log5(2.5 / 2))));
|
|
2609
|
+
ok("!1.5Aa4 == !Aa(4+log5(1.5/2))",
|
|
2610
|
+
MetaNum("!1.5Aa4").eq(buildAa(4 + log5(1.5 / 2))));
|
|
2611
|
+
// no regression on the documented anchor (α=2 → log5(1)=0)
|
|
2612
|
+
ok("!2.0000Aa4 === !Aa4", MetaNum("!2.0000Aa4").eq(MetaNum("!Aa4")));
|
|
2613
|
+
// legacy 1.0+ spelling still means "no mantissa"
|
|
2614
|
+
ok("!1.000Aa5 === !Aa5 (legacy)", MetaNum("!1.000Aa5").eq(MetaNum("!Aa5")));
|
|
2615
|
+
// formatter round-trips the true value as the approximate binary form
|
|
2616
|
+
// (issue #20: the README convention α'Aaβ' with α' = 2·5^(x−β'); the
|
|
2617
|
+
// mantissa carries FORMAT_OPTIONS digits, so the round-trip is exact only
|
|
2618
|
+
// when α' is exactly representable — otherwise use rtApprox below)
|
|
2619
|
+
eq("format(!2.5Aa4)", format(MetaNum("!2.5Aa4")), "!2.500Aa4");
|
|
2620
|
+
ok("round-trip !2.5Aa4", MetaNum(format(MetaNum("!2.5Aa4"))).eq(MetaNum("!2.5Aa4")));
|
|
2621
|
+
ok("round-trip !2.376Aa999", MetaNum(format(MetaNum("!2.376Aa999"))).eq(MetaNum("!2.376Aa999")));
|
|
2622
|
+
// issue #20 vectors: the diagonal letters follow the README — Aaα = 10{α}10
|
|
2623
|
+
// (Aa1.5 = 10{2}4.472 = [[924.19,3]], between Aa1 and Aa2), and format is
|
|
2624
|
+
// the APPROXIMATE form α'Aaβ' (α' decimal, β' integer), which the single-
|
|
2625
|
+
// letter machinery then carries to its final display.
|
|
2626
|
+
eq("format(Aa1.5)", format(MetaNum("Aa1.5")), "EE1.537E924");
|
|
2627
|
+
eq("format(Aa2.5)", format(MetaNum("Aa2.5")), "FFFE1.745E9");
|
|
2628
|
+
ok("Aa1.5 = 10{2}(2·5^0.5) → [[924.19,3]]",
|
|
2629
|
+
MetaNum("Aa1.5").eq(MetaNum(10).arrow(2)(2 * Math.pow(5, 0.5))) &&
|
|
2630
|
+
MetaNum("Aa1.5").array.length === 1 && MetaNum("Aa1.5").array[0].length === 2 &&
|
|
2631
|
+
Math.abs(MetaNum("Aa1.5").array[0][0] - 924.1866041055171) < 1e-9 &&
|
|
2632
|
+
MetaNum("Aa1.5").array[0][1] === 3);
|
|
2633
|
+
ok("Aa1 < Aa1.5 < Aa2 (README ordering)",
|
|
2634
|
+
MetaNum("Aa1").lt(MetaNum("Aa1.5")) && MetaNum("Aa1.5").lt(MetaNum("Aa2")));
|
|
2635
|
+
// approximate round-trip: the display carries only FORMAT_OPTIONS digits
|
|
2636
|
+
function rtApprox(s, tol) {
|
|
2637
|
+
var v = MetaNum(s);
|
|
2638
|
+
var m2 = MetaNum.fromString(format(v));
|
|
2639
|
+
if (v.eq(m2)) return true;
|
|
2640
|
+
if (v.cmp_tolerance(m2, tol) === 0) return true;
|
|
2641
|
+
// !Aa compact markers compare structurally — compare the smooth argument
|
|
2642
|
+
// x ([[x],[1,0×k,1]] = 10{ω^k}(x); [[1],[α,β]] = 10{β+1}(α))
|
|
2643
|
+
function smoothArg(m) {
|
|
2644
|
+
if (m.layer === 0 && m.array.length === 2 && m.array[0].length === 1 &&
|
|
2645
|
+
m.array[1].length >= 3 && m.array[1][0] === 1 &&
|
|
2646
|
+
m.array[1][m.array[1].length - 1] === 1) {
|
|
2647
|
+
for (var i = 1; i < m.array[1].length - 1; i++) if (m.array[1][i] !== 0) return null;
|
|
2648
|
+
return m.array[0][0];
|
|
2649
|
+
}
|
|
2650
|
+
if (m.layer === 0 && m.array.length === 2 && m.array[0].length === 1 &&
|
|
2651
|
+
m.array[0][0] === 1 && m.array[1].length === 2) {
|
|
2652
|
+
return m.array[1][1] + log5(m.array[1][0] / 2);
|
|
2653
|
+
}
|
|
2654
|
+
return null;
|
|
2655
|
+
}
|
|
2656
|
+
var av = smoothArg(v), am = smoothArg(m2);
|
|
2657
|
+
if (av !== null && am !== null) {
|
|
2658
|
+
return Math.abs(av - am) <= tol * Math.max(Math.abs(av), Math.abs(am));
|
|
2659
|
+
}
|
|
2660
|
+
return false;
|
|
2661
|
+
}
|
|
2662
|
+
ok("round-trip Aa1.5 (approx)", rtApprox("Aa1.5", 1e-3));
|
|
2663
|
+
ok("round-trip Aa2.5 (approx)", rtApprox("Aa2.5", 1e-3));
|
|
2664
|
+
ok("round-trip !Aa2.5 (approx)", rtApprox("!Aa2.5", 1e-2));
|
|
2665
|
+
ok("round-trip !1Aa1.5 (approx)", rtApprox("!1Aa1.5", 1e-2));
|
|
2666
|
+
ok("round-trip !Aa0.5 (approx)", rtApprox("!Aa0.5", 1e-2));
|
|
2667
|
+
// issue #20 residual: x∈[1,2) sometimes formats as αΓβ with a single
|
|
2668
|
+
// letter F..Z (Aa1.65 → 4.935F5). Those used to parse to 0; the αΓβ
|
|
2669
|
+
// branch now reads them back, and the 4-digit mantissa is checked in slog
|
|
2670
|
+
// space (equivalent to the tolerance allowed by the acceptance criteria).
|
|
2671
|
+
function slogClose(input, tol) {
|
|
2672
|
+
var v = MetaNum(input);
|
|
2673
|
+
var back = MetaNum(format(v));
|
|
2674
|
+
var d = Number(v.slog(10).toString()) - Number(back.slog(10).toString());
|
|
2675
|
+
return Math.abs(d) <= tol;
|
|
2676
|
+
}
|
|
2677
|
+
ok("format(Aa1.65) = 4.935F5, slog round-trip",
|
|
2678
|
+
format(MetaNum("Aa1.65")) === "4.935F5" && slogClose("Aa1.65", 1e-3), format(MetaNum("Aa1.65")));
|
|
2679
|
+
ok("format(Aa1.95) = 1.686F9, slog round-trip",
|
|
2680
|
+
format(MetaNum("Aa1.95")) === "1.686F9" && slogClose("Aa1.95", 1e-3), format(MetaNum("Aa1.95")));
|
|
2681
|
+
ok("3.261F8 parses (not 0)", MetaNum("3.261F8").neq(0), MetaNum("3.261F8").toString());
|
|
2682
|
+
var bad20 = [];
|
|
2683
|
+
for (var xi = 105; xi <= 195; xi += 10) {
|
|
2684
|
+
var s20 = "Aa" + (xi / 100).toFixed(2);
|
|
2685
|
+
if (!slogClose(s20, 1e-3)) bad20.push(s20);
|
|
2686
|
+
}
|
|
2687
|
+
ok("Aa1.05..Aa1.95 all format round-trip in slog space",
|
|
2688
|
+
bad20.length === 0, bad20.join(","));
|
|
2689
|
+
// smooth (non-integer) family stays monotone inside the compact forms
|
|
2690
|
+
ok("!Aa1.5 < !Aa2.5 < !Aa3.5",
|
|
2691
|
+
MetaNum("!Aa1.5").lt(MetaNum("!Aa2.5")) && MetaNum("!Aa2.5").lt(MetaNum("!Aa3.5")));
|
|
2692
|
+
})();
|
|
2693
|
+
|
|
2694
|
+
// ─────────────────────────────────────────────────────────────
|
|
2695
|
+
// D07 · 2{λ}2 = 4 (notation-semantics §3, rule 3)
|
|
2696
|
+
// ─────────────────────────────────────────────────────────────
|
|
2697
|
+
console.log("\n=== D07 2{lambda}2 ===");
|
|
2698
|
+
(function () {
|
|
2699
|
+
var ops = ["aperiote", "aperionate", "iter", "itermult", "cuboiter", "expoiter",
|
|
2700
|
+
"trioterate", "trixxate", "aperixxate", "epsilonate"];
|
|
2701
|
+
// B2-a: for base 2 every infinite/successor level collapses to 4 for any
|
|
2702
|
+
// integer y >= 2 (rule 3 turns the argument into 2).
|
|
2703
|
+
[2, 3, 5, 1000].forEach(function (y) {
|
|
2704
|
+
ops.forEach(function (op) {
|
|
2705
|
+
var v = new MetaNum(2)[op](y);
|
|
2706
|
+
ok("2{" + op + "}" + y + " === 4", v.eq(4), v.toString());
|
|
2707
|
+
});
|
|
2708
|
+
});
|
|
2709
|
+
// finite levels must NOT collapse (2{1}3 = 8, 2{2}3 = 16)
|
|
2710
|
+
ok("2{1}3 === 8 (finite unaffected)", new MetaNum(2).arrow(1)(3).eq(8));
|
|
2711
|
+
ok("2{2}3 === 16 (finite unaffected)", new MetaNum(2).arrow(2)(3).eq(16));
|
|
2712
|
+
ok("3{ω²}1 === 3 (y=1)", new MetaNum(3).aperionate(1).eq(3));
|
|
2713
|
+
ok("3{ω^ω}1 === 3 (y=1)", new MetaNum(3).trixxate(1).eq(3));
|
|
2714
|
+
})();
|
|
2715
|
+
|
|
2716
|
+
// ─────────────────────────────────────────────────────────────
|
|
2717
|
+
|
|
2718
|
+
console.log("\n=== merged issue-17 regression Done ===");
|
|
2719
|
+
|
|
2720
|
+
// ─────────────────────────────────────────────────────────────
|
|
2721
|
+
// v2.1.0: hardy(x, base) / FGH(x, y)
|
|
2722
|
+
// ─────────────────────────────────────────────────────────────
|
|
2723
|
+
console.log("\n=== hardy base extension ===");
|
|
2724
|
+
(function () {
|
|
2725
|
+
// the base-10 path is the historical behaviour (hardy(n) = H_n(10))
|
|
2726
|
+
ok("hardy(0) = 10", MetaNum.hardy(0).eq(10));
|
|
2727
|
+
ok("hardy(9) = 19", MetaNum.hardy(9).eq(19));
|
|
2728
|
+
ok("hardy(10) = 20", MetaNum.hardy(10).eq(20));
|
|
2729
|
+
ok("hardy(100) = 10240", MetaNum.hardy(100).eq(10240));
|
|
2730
|
+
// the second argument is the base: the digits of x are read in that base
|
|
2731
|
+
eq("hardy(10,8) = H_{ω+2}(8) = 20", MetaNum.hardy(10, 8).toString(), "20");
|
|
2732
|
+
eq("hardy(10,4) = H_{ω*2+2}(4) = 24", MetaNum.hardy(10, 4).toString(), "24");
|
|
2733
|
+
eq("hardy(5,8) = H_5(8) = 13", MetaNum.hardy(5, 8).toString(), "13");
|
|
2734
|
+
eq("hardy(9,10) = 19 (default base)", MetaNum.hardy(9, 10).toString(), "19");
|
|
2735
|
+
ok("hardy(64,8) = H_{ω^2}(8) = 2048 (64 = 100 base 8)", MetaNum.hardy(64, 8).eq(2048));
|
|
2736
|
+
ok("hardy(1000,2) huge but finite", MetaNum.hardy(1000, 2).isFinite());
|
|
2737
|
+
ok("hardy monotone in x: hardy(10,8) < hardy(11,8)",
|
|
2738
|
+
MetaNum.hardy(10, 8).lt(MetaNum.hardy(11, 8)));
|
|
2739
|
+
// validation: integer base in [2, 1000]
|
|
2740
|
+
var threw = 0;
|
|
2741
|
+
[1, 1001, 2.5, "x"].forEach(function (b) {
|
|
2742
|
+
try { MetaNum.hardy(10, b); } catch (e) { threw++; }
|
|
2743
|
+
});
|
|
2744
|
+
ok("hardy rejects bases outside [2,1000] / non-integers", threw === 4);
|
|
2745
|
+
// FGH(x, y) = hardy(y^x, y)
|
|
2746
|
+
ok("FGH(3,10) = hardy(1000,10)", MetaNum.fgh(3, 10).eq(MetaNum.hardy(1000, 10)));
|
|
2747
|
+
ok("FGH(2,8) = hardy(64,8) = 2048", MetaNum.fgh(2, 8).eq(2048));
|
|
2748
|
+
ok("FGH(0,10) = hardy(1,10) = 11", MetaNum.fgh(0, 10).eq(11));
|
|
2749
|
+
ok("FGH monotone in x", MetaNum.fgh(2, 10).lt(MetaNum.fgh(3, 10)));
|
|
2750
|
+
ok("FGH validates the base too", (function () {
|
|
2751
|
+
try { MetaNum.fgh(2, 1); return false; } catch (e) { return true; }
|
|
2752
|
+
})());
|
|
2753
|
+
})();
|
|
2754
|
+
|
|
2755
|
+
console.log("\n=== hardy/FGH tests Done ===");
|