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/README.md +29 -4
- package/format-metanum.js +226 -177
- package/metanum.js +812 -404
- package/package.json +30 -32
- package/test_mixed.js +316 -12
package/format-metanum.js
CHANGED
|
@@ -8,7 +8,7 @@ let FORMAT_DEBUG = 0
|
|
|
8
8
|
// ─── Configuration Options ────────────────────────────────────────
|
|
9
9
|
const FORMAT_OPTIONS = {
|
|
10
10
|
smallNotationUseE: true, //true/false
|
|
11
|
-
smallNotationThreshold:
|
|
11
|
+
smallNotationThreshold: 3, //0~9
|
|
12
12
|
decimalPlaces: 3, //0~9
|
|
13
13
|
decimalThreshold: 3, //0~15
|
|
14
14
|
useCommas: true, //true/false
|
|
@@ -63,17 +63,10 @@ function regularFormat(num, precision) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// ─── MetaNum-Specific Polarize ───────────────────────────────────
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
// r0[3] = count of G operations (level 3), etc.
|
|
71
|
-
//
|
|
72
|
-
// In binary form αΓβ:
|
|
73
|
-
// bottom = α (mantissa in [1, 10))
|
|
74
|
-
// top = β (integer exponent)
|
|
75
|
-
// height = Γ level (1=E, 2=F, 3=G, ..., 22=Z)
|
|
76
|
-
// repeat = count of repeated operations at the highest level (>1 means repeated letters)
|
|
66
|
+
// r0 is [base, e, f, g, ...]: r0[0] is the argument, r0[1..] count the E/F/G…
|
|
67
|
+
// operations (levels 1, 2, 3, …). Binary form αΓβ: bottom = α (mantissa in
|
|
68
|
+
// [1,10)), top = β, height = Γ (1=E … 22=Z), repeat = count of repeated
|
|
69
|
+
// operations at the highest level (>1 means repeated letters).
|
|
77
70
|
function metaPolarize(r0, num) {
|
|
78
71
|
if (FORMAT_DEBUG >= 1) console.log("metaPolarize input:", JSON.stringify(r0))
|
|
79
72
|
if (r0.length === 0) r0 = [0]
|
|
@@ -289,25 +282,20 @@ function letterName(height) {
|
|
|
289
282
|
}
|
|
290
283
|
|
|
291
284
|
// ─── Letter token with the multiLetterLimit symbol carry ──────────
|
|
292
|
-
// A k-letter combination (Aa, Aaa,
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
// ω-exponent (k-1) and α's digits are the CNF coefficients — exactly the
|
|
297
|
-
// digits of the letter itself (uppercase index, then the lowercase indices),
|
|
298
|
-
// which keeps the diagonal mantissa inside [2,10) for the cascades.
|
|
285
|
+
// A k-letter combination (Aa, Aaa, …) sits at level ω^(k-1). Past
|
|
286
|
+
// FORMAT_OPTIONS.multiLetterLimit the notation switches to the symbol form
|
|
287
|
+
// !αAaβ: β is the top ω-exponent (k-1), α's digits are the CNF coefficients
|
|
288
|
+
// (the letter's own digits), keeping the diagonal mantissa inside [2,10).
|
|
299
289
|
function letterTokenOf(height) {
|
|
300
290
|
let plain = letterName(height)
|
|
301
291
|
let limit = Math.max(2, FORMAT_OPTIONS.multiLetterLimit | 0)
|
|
302
292
|
if (plain.length <= limit) return { sym: "", letter: plain, arg: 0, mant: null }
|
|
303
|
-
// The carried form is "!" + the
|
|
304
|
-
//
|
|
305
|
-
//
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
// exhausted (!ZZZYYY{maxSafeInteger}) does the notation fall back to the
|
|
310
|
-
// coarser !αAaβ form.
|
|
293
|
+
// The carried form is "!" + the single-letter αΓβ: "!" adds one ω^ layer
|
|
294
|
+
// on top of Γ, so a diagonal Aaa…a (= ω^k, too long for multiLetterLimit)
|
|
295
|
+
// becomes !αHβ with H = the finite level k (!2.000Aa4 = !1H10 = 10{ω^4}10
|
|
296
|
+
// vs 2.000Aa4 = 1H10 = 10{4}10); β is the argument (ω³*50/100/200 stay
|
|
297
|
+
// apart as !1H51/!1H101/!1H201). Only when the single-letter chain is
|
|
298
|
+
// exhausted does it fall back to the coarser !αAaβ form.
|
|
311
299
|
let expo = plain.length - 1
|
|
312
300
|
if (expo >= 1 && expo <= 22) {
|
|
313
301
|
return { sym: "!", letter: letterName(expo), arg: expo, mant: 1, useBeta: true }
|
|
@@ -343,22 +331,15 @@ function symbolName(layer) {
|
|
|
343
331
|
}
|
|
344
332
|
|
|
345
333
|
// ─── Ordinal Letter: Extract letter name from ordinal rows ───────
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
//
|
|
354
|
-
//
|
|
355
|
-
|
|
356
|
-
// Snap CNF coefficients (little-endian [a1, a2, …, ak], ordinal
|
|
357
|
-
// ω^(k-1)·ak + … + ω·a2 + a1) to the ones the letter grid can name:
|
|
358
|
-
// every ai must satisfy 0 ≤ ai ≤ 25 and the top ak ≤ 26. Larger
|
|
359
|
-
// coefficients carry UP — ω*2+96 → ω*3 (Ca), ω*99 → ω² (Aaa),
|
|
360
|
-
// ω²*100 → ω³ (Aaaa) — so an unnamed ordinal displays as the next
|
|
361
|
-
// nameable one above it, never as a lower/wrong letter.
|
|
334
|
+
// Format A (3+ elements): [count, v1..vN, diag] — diag 1-26 (A-Z, uppercase),
|
|
335
|
+
// v1..vN 0-25 (a-z, lowercase), count = repetition count.
|
|
336
|
+
// Format B (2 elements): [count, value] — count at ω-level, value the
|
|
337
|
+
// ordinal level number (901 means ω*901); letter is always "Aa".
|
|
338
|
+
|
|
339
|
+
// Snap CNF coefficients (little-endian [a1..ak], ordinal ω^(k-1)·ak+…+a1) to
|
|
340
|
+
// the ones the letter grid can name: 0 ≤ ai ≤ 25, top ak ≤ 26. Larger
|
|
341
|
+
// coefficients carry UP (ω*2+96 → ω*3 (Ca), ω*99 → ω² (Aaa), ω²*100 → ω³
|
|
342
|
+
// (Aaaa)), so an unnamed ordinal displays as the next nameable one above it.
|
|
362
343
|
function snapCoeffsToGrid(coeffs) {
|
|
363
344
|
let r = (coeffs || []).slice()
|
|
364
345
|
// little-endian ORDINAL carry: index 0 is the constant term. A term above
|
|
@@ -420,11 +401,10 @@ function getOrdinalLetter(ordRows) {
|
|
|
420
401
|
|
|
421
402
|
// ─── Reference Polarize (verbatim port of PowiainaNum's myPolarize) ──
|
|
422
403
|
// Recovers the display α ("bottom") and the diagonal level ("arrows") of an
|
|
423
|
-
// r0 chain STRUCTURALLY,
|
|
424
|
-
//
|
|
425
|
-
//
|
|
426
|
-
//
|
|
427
|
-
// ours: r0 = [base, cnt1, cnt2, ...] where cnt_i = count at level i
|
|
404
|
+
// r0 chain STRUCTURALLY, climbing log10 level by level — the only method that
|
|
405
|
+
// stays exact at high levels where the engine's fractional-arg bisect
|
|
406
|
+
// quantizes (level ≥ 20). Ground truth: format-powiainanum.js. Their array
|
|
407
|
+
// [base, [level, count, 1, 1], …] maps to our r0 = [base, cnt1, cnt2, …].
|
|
428
408
|
function refPolarizeArraySort(array) {
|
|
429
409
|
array.sort(function (a, b) {
|
|
430
410
|
if (typeof a == 'number') return
|
|
@@ -544,21 +524,16 @@ function refPolarize(array, hasOperationRepeat = true) {
|
|
|
544
524
|
}
|
|
545
525
|
}
|
|
546
526
|
// Convert a finite-chain polarize triple (bottom, repeation, arrows) into the
|
|
547
|
-
//
|
|
548
|
-
// (
|
|
549
|
-
//
|
|
550
|
-
//
|
|
551
|
-
// t
|
|
552
|
-
//
|
|
553
|
-
// t
|
|
554
|
-
//
|
|
555
|
-
//
|
|
556
|
-
//
|
|
557
|
-
// Truncation-marker normalization for finite rows: when the engine truncated
|
|
558
|
-
// an overflow cascade it reset r0 to [10] and bumped the LOWEST kept row's
|
|
559
|
-
// count by 1 over the uniform per-level fill (xCnt). That +1 marks the
|
|
560
|
-
// dropped tail, not a real operation — read the row as carrying xCnt so
|
|
561
|
-
// truncated displays match the untruncated anchor (cross-config stability).
|
|
527
|
+
// diagonal-letter display pair (mantissa, β). The value behaves as
|
|
528
|
+
// 10{arrows+1}(t), t = log10(bottom)+repeation; the diagonal convention is
|
|
529
|
+
// α = 2·5^f ∈ [2,10):
|
|
530
|
+
// t ∈ [2,10) -> mantissa t, β = arrows (3{100}3 -> 2.376Aa99)
|
|
531
|
+
// t ≥ 10 -> one level per smooth-log step f → 1+log10(f); the anchor
|
|
532
|
+
// t=10 is mantissa 2 at β=arrows+1 (10{100}10 -> 2.000Aa100)
|
|
533
|
+
// t ∈ [1,2) -> mantissa 2·5^(t-1), β = arrows-1
|
|
534
|
+
// Truncation marker: a truncated cascade resets r0 to [10] and bumps the
|
|
535
|
+
// lowest kept row's count by 1 over the uniform fill (xCnt) — read it as xCnt
|
|
536
|
+
// so truncated displays match the untruncated anchor.
|
|
562
537
|
function normalizedFiniteRows(r0, finiteRows) {
|
|
563
538
|
if (!finiteRows || finiteRows.length === 0 || r0[0] !== 10) return finiteRows
|
|
564
539
|
let sorted = finiteRows.slice().sort((a, b) => a[1] - b[1])
|
|
@@ -630,6 +605,57 @@ function formatR0ArgStr(argStr) {
|
|
|
630
605
|
return null
|
|
631
606
|
}
|
|
632
607
|
|
|
608
|
+
// De-layered !Aa x instance (decision 1B): the shape [[x],[1,0×k,1]] with
|
|
609
|
+
// k = max(1, floor(x)), x >= 1. Per the README the display is the APPROXIMATE
|
|
610
|
+
// binary form !α'Aa'β' (β' = floor(x), α' = 2·5^(x−β') ∈ [2,10)) — the
|
|
611
|
+
// mantissa carries only FORMAT_OPTIONS digits, so the round-trip recovers x
|
|
612
|
+
// to that precision (issue #20: tolerance-based assertion). An INTEGER x has
|
|
613
|
+
// α' = 2 exactly, and the binary spelling now denotes the ω^n diagonal
|
|
614
|
+
// cascade (issue #19), so it shows the exact letter token A(a×k)x instead.
|
|
615
|
+
// Returns null for every other shape (x < 2 included — the no-"!" binary form
|
|
616
|
+
// comes from formatOrdinal).
|
|
617
|
+
function formatBangAaValue(num, precision) {
|
|
618
|
+
if (num.sign !== 1 || num.layer !== 0) return null
|
|
619
|
+
let a = num.array
|
|
620
|
+
if (a.length !== 2 || a[0].length !== 1) return null
|
|
621
|
+
let x = a[0][0]
|
|
622
|
+
if (typeof x !== 'number' || !isFinite(x) || x < 2) return null
|
|
623
|
+
let row = a[1]
|
|
624
|
+
if (row.length < 3 || row[0] !== 1 || row[row.length - 1] !== 1) return null
|
|
625
|
+
for (let i = 1; i < row.length - 1; i++) if (row[i] !== 0) return null
|
|
626
|
+
let k = row.length - 2
|
|
627
|
+
if (k !== Math.max(1, Math.floor(x))) return null
|
|
628
|
+
if (x === Math.floor(x)) {
|
|
629
|
+
// integer anchor: the letter token A(a×k)x is the exact spelling
|
|
630
|
+
return "A" + "a".repeat(k) + formatR0Arg(x, precision)
|
|
631
|
+
}
|
|
632
|
+
let beta = Math.floor(x)
|
|
633
|
+
let mant = 2 * Math.pow(5, x - beta)
|
|
634
|
+
return "!" + regularFormat(mant, precision) + "Aa" + formatR0Arg(beta, precision)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// The full rule-3 cascade of 10{ω^n}10 (n ≥ 2) — the stored form of !Aa<n>
|
|
638
|
+
// (issue #19: "!" adds one ω^, so !Aa3 = 10{ω^3}10). A cheap shape pre-filter
|
|
639
|
+
// (base [10], full row budget, top row [8, 9×n]) plus an exact comparison
|
|
640
|
+
// against the engine's own cascade, so nothing else matches. Displayed as the
|
|
641
|
+
// binary diagonal !2.000Aa<n>, which parses back to the same cascade.
|
|
642
|
+
function formatAaCascade(num, precision) {
|
|
643
|
+
if (num.sign !== 1 || num.layer !== 0) return null
|
|
644
|
+
let a = num.array
|
|
645
|
+
if (a.length !== MetaNum.maxRows || a.length < 3) return null
|
|
646
|
+
if (a[0].length !== 1 || a[0][0] !== 10) return null
|
|
647
|
+
let last = a[a.length - 1]
|
|
648
|
+
let n = last.length - 1
|
|
649
|
+
if (n < 2 || last[0] !== 8) return null
|
|
650
|
+
for (let i = 1; i < last.length; i++) if (last[i] !== 9) return null
|
|
651
|
+
let coeffs = []
|
|
652
|
+
for (let i = 0; i < n; i++) coeffs.push(0)
|
|
653
|
+
coeffs.push(1)
|
|
654
|
+
let ref = MetaNum._hyperopFromOrdinalRaw(MetaNum.TEN, MetaNum.TEN, coeffs)
|
|
655
|
+
if (!ref.eq(num)) return null
|
|
656
|
+
return "!" + regularFormat(2, precision) + "Aa" + formatR0Arg(n, precision)
|
|
657
|
+
}
|
|
658
|
+
|
|
633
659
|
function format(num, precision=3, small=false) {
|
|
634
660
|
if (MetaNum.isNaN(num)) return "NaN"
|
|
635
661
|
let sciSigDigits = FORMAT_OPTIONS.sciSignificantDigits // for E notation
|
|
@@ -645,6 +671,23 @@ function format(num, precision=3, small=false) {
|
|
|
645
671
|
if (num.sign < 0) return "-" + format(num.neg(), precision, small)
|
|
646
672
|
if (num.isInfinite()) return "Infinity"
|
|
647
673
|
|
|
674
|
+
// Sub-unit values (sign 2 / -2, 0 < |v| < 1): a plain finite r0 stores the
|
|
675
|
+
// RECIPROCAL, so the real value is 1/r0 — format that number (decimals at
|
|
676
|
+
// or above 10^-smallNotationThreshold, αE-β below). Reading the raw r0
|
|
677
|
+
// printed the reciprocal (MetaNum(1).div(2000) → "2.000E-3"). Structured
|
|
678
|
+
// sign-2 forms keep the letter-law path below.
|
|
679
|
+
if ((num.sign === 2 || num.sign === -2) && num.layer === 0 &&
|
|
680
|
+
num.array.length === 1 && num.array[0].length === 1 &&
|
|
681
|
+
isFinite(num.array[0][0]) && num.array[0][0] !== 0) {
|
|
682
|
+
let realVal = 1 / num.array[0][0]
|
|
683
|
+
if (isFinite(realVal) && realVal > 0) {
|
|
684
|
+
let asNormal = num.clone()
|
|
685
|
+
asNormal.sign = 1
|
|
686
|
+
asNormal.array = [[realVal]]
|
|
687
|
+
num = asNormal
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
648
691
|
// Small value handling (e.g., 0.0000000001 → 1.000E-10 or 1.000E10⁻¹)
|
|
649
692
|
let smallThreshold = Math.pow(10, -FORMAT_OPTIONS.smallNotationThreshold)
|
|
650
693
|
if (num.lt(smallThreshold)) {
|
|
@@ -668,16 +711,12 @@ function format(num, precision=3, small=false) {
|
|
|
668
711
|
return prefix + regularFormat(mant, sciMantissaPrecision(expPart)) + "E-" + commaFormat(expPart)
|
|
669
712
|
}
|
|
670
713
|
}
|
|
671
|
-
// Tier 2: mag is large → "E-" + letter-law form of mag
|
|
672
|
-
// log10 of the reciprocal base.
|
|
673
|
-
//
|
|
674
|
-
//
|
|
675
|
-
//
|
|
676
|
-
//
|
|
677
|
-
// Γ ≥ G (G200): log10 = G200 (Γβ−1+1 = Γβ: the leading
|
|
678
|
-
// F(G(β−1)) collapses back to G(β))
|
|
679
|
-
// Roundtrip exact: "E-1.000G200" parses back to 1/G200,
|
|
680
|
-
// "E-1.000F499" to 1/F500 (test_mixed format block)
|
|
714
|
+
// Tier 2: mag is large → "E-" + the letter-law form of mag
|
|
715
|
+
// (= log10 of the reciprocal base). A chain of n same-level
|
|
716
|
+
// ops collapses to ONE next-level op with arg+n, so log10
|
|
717
|
+
// shifts only the OUTERMOST letter (EE1000 → E1000, F500 →
|
|
718
|
+
// F499, G200 → G200). Roundtrip exact: "E-1.000G200" parses
|
|
719
|
+
// back to 1/G200.
|
|
681
720
|
var recipStr = format(recipFmt, precision, small)
|
|
682
721
|
var magStr = recipStr
|
|
683
722
|
// leading run of E letters (e.g. "EE1.000E1,000"): strip one E
|
|
@@ -775,6 +814,12 @@ function format(num, precision=3, small=false) {
|
|
|
775
814
|
// ── Handle ordinal rows (Aa, Ab, ..., Aaa, ... range) ──
|
|
776
815
|
let hasOrdinalRows = array.length > 1
|
|
777
816
|
if (hasOrdinalRows) {
|
|
817
|
+
let bang = formatBangAaValue(num, multiPrecision)
|
|
818
|
+
if (bang !== null) return bang
|
|
819
|
+
// issue #19: the full 10{ω^n}10 cascade (stored !Aa<n>) — display the
|
|
820
|
+
// binary diagonal so the parser round-trips it
|
|
821
|
+
let cascade = formatAaCascade(num, multiPrecision)
|
|
822
|
+
if (cascade !== null) return cascade
|
|
778
823
|
return formatOrdinal(num, precision, multiPrecision)
|
|
779
824
|
}
|
|
780
825
|
|
|
@@ -867,17 +912,24 @@ function formatLayer(num, precision, precision2, precision3, precision4) {
|
|
|
867
912
|
return innerStr + "ε" + commaFormat(num.layer)
|
|
868
913
|
}
|
|
869
914
|
|
|
915
|
+
// issue #19: the 10{ω^n}10 cascade at a symbol layer — the stored form of
|
|
916
|
+
// @Aa<n> (layer 1), #Aa<n> (layer 2), … ONE symbol per value: the symbol
|
|
917
|
+
// index is the total ω^-layer count (layer 0 → "!", 1 → "@", 2 → "#"),
|
|
918
|
+
// never a stack ("@!…" is invalid). The body is the same binary diagonal
|
|
919
|
+
// the layer-0 form uses, so the display stays isomorphic to !Aa<n>.
|
|
920
|
+
let cascadeStr = formatAaCascade(inner, precision4)
|
|
921
|
+
if (cascadeStr !== null) {
|
|
922
|
+
let body = cascadeStr.slice(1) // strip the layer-0 "!"
|
|
923
|
+
if (num.layer < SYMBOLS.length) return SYMBOLS[num.layer] + body
|
|
924
|
+
return body + "ε" + commaFormat(num.layer + 1)
|
|
925
|
+
}
|
|
926
|
+
|
|
870
927
|
// Compact diagonal: the symbol row [1,0…0,1] with m=compactBase zeros is
|
|
871
|
-
// 10{ω^m}10 — a DIAGONAL letter (A + m a's) at argument 10
|
|
872
|
-
//
|
|
873
|
-
//
|
|
874
|
-
//
|
|
875
|
-
//
|
|
876
|
-
// multiLetterLimit symbol carry: once the diagonal letter would be longer
|
|
877
|
-
// than the limit (m+1 letters) it switches to one more symbol and the Aa
|
|
878
|
-
// argument takes over the exponent — 10{ω^10}10 → !2.000Aa10, and layer 1
|
|
879
|
-
// on top stacks the symbols (no-symbol → ! → @ → # …):
|
|
880
|
-
// apix(3,10) = 10{ω^(ω^10)}10 → @2.000Aa10.
|
|
928
|
+
// 10{ω^m}10 — a DIAGONAL letter (A + m a's) at argument 10, with the pure
|
|
929
|
+
// dlsdl α=2·5^f ∈ [2,10) convention (integer m anchors mantissa 2). For
|
|
930
|
+
// layers above ! the symbol of the layer below prefixes the same inner
|
|
931
|
+
// form (!Aa3 = 2.000Aaaa10, @Aa3 = !2.000Aaaa10); past multiLetterLimit the
|
|
932
|
+
// Aa argument takes over the exponent (10{ω^10}10 → !2.000Aa10).
|
|
881
933
|
if (canCompact && compactBase >= 2) {
|
|
882
934
|
let mInt = Math.floor(compactBase)
|
|
883
935
|
let frac = compactBase - mInt
|
|
@@ -894,11 +946,11 @@ function formatLayer(num, precision, precision2, precision3, precision4) {
|
|
|
894
946
|
if (total <= SYMBOLS.length) return SYMBOLS[total - 1] + body
|
|
895
947
|
return body + "ε" + commaFormat(total)
|
|
896
948
|
}
|
|
897
|
-
// Stored layer L
|
|
898
|
-
//
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
return
|
|
949
|
+
// Stored layer L: exactly ONE symbol per ω^ layer (symbolName(L));
|
|
950
|
+
// stacking symbols ("@!…") is invalid (issue #19). The body is the
|
|
951
|
+
// diagonal letter A(a×m)10 at the smooth mantissa. (Layers past the
|
|
952
|
+
// symbol list already returned through the ε branch above.)
|
|
953
|
+
return symbolName(num.layer) + regularFormat(mant, precision4) +
|
|
902
954
|
"A" + "a".repeat(mInt) + "10"
|
|
903
955
|
}
|
|
904
956
|
|
|
@@ -952,10 +1004,9 @@ function formatR0Arg(value, precision) {
|
|
|
952
1004
|
|
|
953
1005
|
// ─── Gamma-Arg Recovery ─────────────────────────────────────────
|
|
954
1006
|
// Recover the real argument x with 10{level}x = v (the Γ-canonical argument of
|
|
955
|
-
// v at letter `level`)
|
|
956
|
-
//
|
|
957
|
-
//
|
|
958
|
-
// ~45 doublings before the bracket closes.
|
|
1007
|
+
// v at letter `level`) by bisection on the engine's smooth arrow curve. null
|
|
1008
|
+
// when x exceeds the double-precision bisect range; the doubling guard runs to
|
|
1009
|
+
// 200 (hardy(1120)'s F-arg ≈ 4.4e13 needs ~45 doublings).
|
|
959
1010
|
function gammaArgOf(v, level, iters) {
|
|
960
1011
|
if (iters === undefined) iters = 60
|
|
961
1012
|
let G = function (x) { return MetaNum(10).arrow(level)(x) }
|
|
@@ -1014,14 +1065,11 @@ function distinctLetterTypes(str) {
|
|
|
1014
1065
|
}
|
|
1015
1066
|
|
|
1016
1067
|
// ─── Format r0 as Chain ────────────────────────────────────────
|
|
1017
|
-
// Formats r0 = [base, e, f, g, ...] as a dlsdl
|
|
1018
|
-
//
|
|
1019
|
-
//
|
|
1020
|
-
//
|
|
1021
|
-
//
|
|
1022
|
-
// diagonal letter (Aa = ω, Ba = ω·2, Aaa = ω², …) and its binary form has
|
|
1023
|
-
// α = 2·5^f ∈ [2,10) — the diagonal 10{23}10 reads "2.000Aa23", never
|
|
1024
|
-
// "1.000Aa23". Every other letter keeps the ordinary [1,10) mantissa.
|
|
1068
|
+
// Formats r0 = [base, e, f, g, ...] as a dlsdl chain: outerLetters + α +
|
|
1069
|
+
// lastLetter + β, with α = 10^(base-floor(base)) and β = floor(base)
|
|
1070
|
+
// (EE200 → "E1.000E200", FE400 → "F1.000E400"). A letter ending in "a" is a
|
|
1071
|
+
// diagonal letter (Aa = ω, Ba = ω·2, Aaa = ω², …) and its binary form uses
|
|
1072
|
+
// α = 2·5^f ∈ [2,10) — 10{23}10 reads "2.000Aa23", never "1.000Aa23".
|
|
1025
1073
|
function diagonalMantissa(letter, mantissa) {
|
|
1026
1074
|
if (letter && letter.charAt(letter.length - 1) === 'a') {
|
|
1027
1075
|
let f = mantissa - Math.floor(mantissa)
|
|
@@ -1064,17 +1112,14 @@ function formatR0AsChain(r0, precision, used) {
|
|
|
1064
1112
|
}
|
|
1065
1113
|
|
|
1066
1114
|
// ── ≤2-letter-types rule ──
|
|
1067
|
-
// When the full
|
|
1068
|
-
//
|
|
1069
|
-
//
|
|
1070
|
-
//
|
|
1071
|
-
//
|
|
1072
|
-
//
|
|
1073
|
-
//
|
|
1074
|
-
//
|
|
1075
|
-
// 5{9}5 → "LLLKK4.669K4" (user: "LLLKK…K…")
|
|
1076
|
-
// A top count ≥ repeatLetterThreshold+1 carries to the next single
|
|
1077
|
-
// letter instead (6{9}6 → "5.760M5" via the collapse paths below).
|
|
1115
|
+
// When the full spelling would use MORE than two letter types, spell only
|
|
1116
|
+
// the top two levels' letters and compress everything below into the
|
|
1117
|
+
// second letter's binary-canonical form "bottom Γ₂ repeation" (the
|
|
1118
|
+
// polarize triple; bisect fails there — the arg exceeds double range):
|
|
1119
|
+
// 3{9}3 → "L2.376K2", 3{10}3 → "M2.376L2",
|
|
1120
|
+
// 4{9}4 → "LLK3.550K3", 5{9}5 → "LLLKK4.669K4".
|
|
1121
|
+
// A top count ≥ repeatLetterThreshold+1 carries to the next single letter
|
|
1122
|
+
// (6{9}6 → "5.760M5").
|
|
1078
1123
|
if (maxLevel >= 2 && maxLevel <= 22 && count <= effThreshold) {
|
|
1079
1124
|
let spellTypes = 0
|
|
1080
1125
|
for (let s = 2; s <= maxLevel; s++) {
|
|
@@ -1189,17 +1234,14 @@ function formatR0AsChain(r0, precision, used) {
|
|
|
1189
1234
|
}
|
|
1190
1235
|
|
|
1191
1236
|
// ── Γ-canonical recovery (2-letter rule) ──
|
|
1192
|
-
// Two rules, both driven by the engine's own smooth arrow curve:
|
|
1193
1237
|
// (a) structural top count < threshold AND inner top < maxLevel: keep
|
|
1194
|
-
// the
|
|
1195
|
-
//
|
|
1196
|
-
// VαEβ → VαFβ → … → VαVβ, never a mixed "VFαEβ").
|
|
1238
|
+
// the top letter Γᵀ bare and format the inner chain recursively (at
|
|
1239
|
+
// most 2 letter types: VαEβ → VαFβ → … → VαVβ, never "VFαEβ").
|
|
1197
1240
|
// (b) otherwise: collapse to the single letter Γ = the HIGHEST level L
|
|
1198
|
-
// whose recovered argument
|
|
1199
|
-
//
|
|
1200
|
-
//
|
|
1201
|
-
//
|
|
1202
|
-
// to ONE Γ^{L+1} with arg+n (F^4(G(1.3796)) = G(5.3796) — bisect-exact).
|
|
1241
|
+
// whose recovered argument (bisect 10{L}x = v) is ≥ 2, in binary form
|
|
1242
|
+
// αΓβ (hardy(4166) → "2.397G5", arrow(3,4.3,3) → "1.285H8").
|
|
1243
|
+
// Verified law: n ops of level L on a Γ^{L+1}-structured value collapse to
|
|
1244
|
+
// ONE Γ^{L+1} with arg+n (F^4(G(1.3796)) = G(5.3796)).
|
|
1203
1245
|
let r0Num = new MetaNum({ sign: 1, layer: 0, array: [r0.slice(0)] })
|
|
1204
1246
|
|
|
1205
1247
|
if (count < effThreshold && maxLevel >= 2 && runLen <= effThreshold) {
|
|
@@ -1228,12 +1270,11 @@ function formatR0AsChain(r0, precision, used) {
|
|
|
1228
1270
|
if (innerR0[it] > 0) { innerTop = it; break }
|
|
1229
1271
|
}
|
|
1230
1272
|
if (innerTop < maxLevel) {
|
|
1231
|
-
// ≤2 letter types rule: count the distinct letter
|
|
1232
|
-
//
|
|
1233
|
-
//
|
|
1234
|
-
//
|
|
1235
|
-
// "
|
|
1236
|
-
// spells only L and K, the M..J part collapses into K's arg).
|
|
1273
|
+
// ≤2 letter types rule: count the distinct letter types the
|
|
1274
|
+
// peeled prefix + innerStr would use. If the inner chain spells a
|
|
1275
|
+
// THIRD type, collapse it to the binary form at maxLevel-1 —
|
|
1276
|
+
// VαEβ → VαFβ → … → VαVβ, never a mixed "VFαEβ" (arrow(3,9,3) →
|
|
1277
|
+
// "L2.376K2": the M..J part collapses into K's arg).
|
|
1237
1278
|
let topLetter = letterName(maxLevel)
|
|
1238
1279
|
let innerTypes = distinctLetterTypes(innerStr)
|
|
1239
1280
|
if (innerTypes.length >= 2
|
|
@@ -1270,12 +1311,11 @@ function formatR0AsChain(r0, precision, used) {
|
|
|
1270
1311
|
}
|
|
1271
1312
|
}
|
|
1272
1313
|
|
|
1273
|
-
// (b) collapse: the structural chain (n repeats of the top letter Γᵀ on
|
|
1274
|
-
//
|
|
1275
|
-
// compresses to ONE Γᵀ⁺¹ with arg+n — bisect at the
|
|
1276
|
-
//
|
|
1277
|
-
//
|
|
1278
|
-
// arrow(3,4.3,3) → "1.285H8")
|
|
1314
|
+
// (b) collapse: the structural chain (n repeats of the top letter Γᵀ on an
|
|
1315
|
+
// inner value whose canonical letter is Γᵀ⁺¹, e.g. F^895(G(2.06)))
|
|
1316
|
+
// compresses to ONE Γᵀ⁺¹ with arg+n — bisect at the structural next letter
|
|
1317
|
+
// first (maxLevel+1); if its arg falls below 2, search upward for the
|
|
1318
|
+
// highest level whose arg ≥ 2 (hardy(4166) → "2.397G5").
|
|
1279
1319
|
let structuralNext = Math.min(maxLevel + 1, 22)
|
|
1280
1320
|
let sx = gammaArgOf(r0Num, structuralNext, 40)
|
|
1281
1321
|
if (sx !== null && isFinite(sx) && sx >= 2) {
|
|
@@ -1314,12 +1354,11 @@ function formatR0AsChain(r0, precision, used) {
|
|
|
1314
1354
|
// bare letter + canonical argument (single α at the innermost value)
|
|
1315
1355
|
return newLetter + formatR0Arg(newTop + Math.log10(bottom < 1 ? Math.pow(10, bottom) : bottom), precision)
|
|
1316
1356
|
}
|
|
1317
|
-
// Format: α + letter + β.
|
|
1318
|
-
//
|
|
1319
|
-
//
|
|
1320
|
-
//
|
|
1321
|
-
//
|
|
1322
|
-
// (issues.md: hardy(4150) → "2.300G5", not "1.000G5")
|
|
1357
|
+
// Format: α + letter + β. Canonical all-8s arrays (from the 10^10
|
|
1358
|
+
// base: G600, ZZ10, …) carry no recoverable mantissa below 10^10, so
|
|
1359
|
+
// α = 1.000 by construction; every other value recovers its real α by
|
|
1360
|
+
// stripping newTop slog's — the residue in [1,10) is exactly the α of
|
|
1361
|
+
// αΓβ = Γ(β+log α) (hardy(4150) → "2.300G5").
|
|
1323
1362
|
let alpha = 1.0
|
|
1324
1363
|
let all8s = (r0[0] === 10000000000)
|
|
1325
1364
|
for (let ai = 2; ai < pol.height && all8s; ai++) {
|
|
@@ -1386,15 +1425,14 @@ function formatR0AsChain(r0, precision, used) {
|
|
|
1386
1425
|
|
|
1387
1426
|
// ─── Format with Ordinal Rows ────────────────────────────────────
|
|
1388
1427
|
|
|
1389
|
-
// finite-row chain display (≤2-letter-types rule):
|
|
1390
|
-
//
|
|
1391
|
-
// top level ≥ 23 (Aa region): the αAaβ diagonal
|
|
1392
|
-
//
|
|
1393
|
-
//
|
|
1394
|
-
// 10{10000}10 → "1.000Aa10,000" (bottom 1, repeation 10 carries).
|
|
1428
|
+
// finite-row chain display (≤2-letter-types rule): r0 cols + [count, level]
|
|
1429
|
+
// rows form one hyperoperation cascade.
|
|
1430
|
+
// top level ≥ 23 (Aa region): the αAaβ diagonal from polarizeFiniteChain,
|
|
1431
|
+
// mantissa normalized into [1,10) carrying decades into β:
|
|
1432
|
+
// 3{24}3 → "2.376Aa23", 3{100}3 → "2.376Aa99", 10{10000}10 → "1.000Aa10,000".
|
|
1395
1433
|
// top level ≤ 22 (single letters): the structural two-letter form
|
|
1396
1434
|
// Γ_top×c₁ + Γ_second×(c₂−1) + bottom + Γ_second + repeation:
|
|
1397
|
-
// 3{22}3 → "Y2.376X2", 3{23}3 → "Z2.376Y2"
|
|
1435
|
+
// 3{22}3 → "Y2.376X2", 3{23}3 → "Z2.376Y2".
|
|
1398
1436
|
// c₁ ≥ repeatLetterThreshold+1 carries to the next single letter.
|
|
1399
1437
|
function formatFiniteRowChain(r0, finiteRows, precision) {
|
|
1400
1438
|
function levelCount(lv) {
|
|
@@ -1475,6 +1513,25 @@ function formatFiniteRowChain(r0, finiteRows, precision) {
|
|
|
1475
1513
|
}
|
|
1476
1514
|
}
|
|
1477
1515
|
|
|
1516
|
+
// ── Repeated top letter over a dominant lower level ──
|
|
1517
|
+
// When the top row is only a prefix (count ≤ threshold) but a lower row
|
|
1518
|
+
// holds the real argument, polarizeFiniteChain collapses the chain and the
|
|
1519
|
+
// top argument degenerates (ZZ152416 read "1.000Z3"). Spell the top row as
|
|
1520
|
+
// prefix letters and format the remaining chain on its own, keeping the
|
|
1521
|
+
// real argument (ZZ152416 → "Z1.000Z152,416").
|
|
1522
|
+
let topRow = finiteRows[finiteRows.length - 1]
|
|
1523
|
+
if (finiteRows.length >= 2 && topRow && topRow[1] === topLv &&
|
|
1524
|
+
Number.isInteger(topRow[0]) && topRow[0] >= 1 && topRow[0] <= effThreshold) {
|
|
1525
|
+
let restR0 = r0.slice(0)
|
|
1526
|
+
for (let i = 0; i < finiteRows.length - 1; i++) {
|
|
1527
|
+
let r = finiteRows[i]
|
|
1528
|
+
while (restR0.length <= r[1]) restR0.push(0)
|
|
1529
|
+
restR0[r[1]] = r[0]
|
|
1530
|
+
}
|
|
1531
|
+
let innerStr = formatR0AsChain(restR0, precision)
|
|
1532
|
+
if (innerStr) return letterName(topLv).repeat(topRow[0]) + innerStr
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1478
1535
|
// fallback: single binary at the top letter
|
|
1479
1536
|
let polF = polarizeFiniteChain(r0, finiteRows)
|
|
1480
1537
|
if (polF && isFinite(polF.bottom) && polF.bottom >= 1) {
|
|
@@ -1526,13 +1583,9 @@ function formatOrdinal(num, precision, precision4) {
|
|
|
1526
1583
|
totalAaCount += row[0] || 1
|
|
1527
1584
|
}
|
|
1528
1585
|
if (allAaOnly && totalAaCount > 0) {
|
|
1529
|
-
// Build the
|
|
1530
|
-
//
|
|
1531
|
-
//
|
|
1532
|
-
// 2-letter (Aa): aaZeroCount=1, height=23
|
|
1533
|
-
// 3-letter (Aaa): aaZeroCount=2, height=699
|
|
1534
|
-
// 4-letter (Aaaa): aaZeroCount=3, height=...
|
|
1535
|
-
// Calculate the correct baseHeight for this letter:
|
|
1586
|
+
// Build the letter "A" + "a".repeat(aaZeroCount) (Aa, Aaa, Aaaa, …):
|
|
1587
|
+
// for ordinal rows diag=1 → "A" and each val 0 → "a", so
|
|
1588
|
+
// aaZeroCount = vals length (Aa → 1, height 23; Aaa → 2, height 699).
|
|
1536
1589
|
let baseHeight
|
|
1537
1590
|
if (aaZeroCount === 1) {
|
|
1538
1591
|
baseHeight = 23 // Aa
|
|
@@ -1630,13 +1683,11 @@ function formatOrdinal(num, precision, precision4) {
|
|
|
1630
1683
|
} else {
|
|
1631
1684
|
// Single DIAGONAL letter (the row ends in 'a': Aa, Aaa,
|
|
1632
1685
|
// Ba, …): pure dlsdl convention α=2·5^f ∈ [2,10).
|
|
1633
|
-
//
|
|
1634
|
-
//
|
|
1635
|
-
//
|
|
1636
|
-
// - ordinary letter application: base is the argument β
|
|
1637
|
-
// (Aa100 -> 2.000Aa100)
|
|
1686
|
+
// Decision 1B: the base is the ARGUMENT β (the row zero count
|
|
1687
|
+
// encodes the letter level). !Aa3 = Aaaa3 therefore reads
|
|
1688
|
+
// "2.000Aaaa3" — not the historical anchor-A "2.000Aaaa10".
|
|
1638
1689
|
let diagMant = 2 * Math.pow(5, base - Math.floor(base))
|
|
1639
|
-
let diagBeta =
|
|
1690
|
+
let diagBeta = top
|
|
1640
1691
|
// multiLetterLimit symbol carry: A + aaZeroCount a's is
|
|
1641
1692
|
// aaZeroCount+1 letters — past the limit the diagonal reads as
|
|
1642
1693
|
// one more symbol with the SINGLE letter of the finite level
|
|
@@ -1652,11 +1703,10 @@ function formatOrdinal(num, precision, precision4) {
|
|
|
1652
1703
|
|
|
1653
1704
|
// ── Unnamed-level display (v2.0.2) ──
|
|
1654
1705
|
// The letter grid only names ordinals with coefficients ≤ 25 (top ≤ 26).
|
|
1655
|
-
// When the TOP row's ordinal is above that (ω*2+96, ω*99, ω²*100, …)
|
|
1656
|
-
// row
|
|
1657
|
-
//
|
|
1658
|
-
//
|
|
1659
|
-
// as level-arg: the snapped level with the operation's own argument —
|
|
1706
|
+
// When the TOP row's ordinal is above that (ω*2+96, ω*99, ω²*100, …) every
|
|
1707
|
+
// row snaps up to the SAME next nameable level, and summing their counts
|
|
1708
|
+
// would collapse the letter further (243 Ca's → Cb(244)) — overstating the
|
|
1709
|
+
// level and hiding the argument. Instead the value reads as level-arg:
|
|
1660
1710
|
// 10{ω*2+100}100 → "1.000Ca100", 10{ω*100}100 → "1.000Aaa100",
|
|
1661
1711
|
// 10{ω²*100+ω*100+100}1000 → "1.000Aaaa1,000".
|
|
1662
1712
|
let gapStr = null
|
|
@@ -1683,15 +1733,15 @@ function formatOrdinal(num, precision, precision4) {
|
|
|
1683
1733
|
for (let gj = 0; gj < gvals.length; gj++) gn += gvals[gj] * Math.pow(26, gj)
|
|
1684
1734
|
gh = 23 + goffset + gn
|
|
1685
1735
|
}
|
|
1686
|
-
// β = the fundamental-sequence index
|
|
1687
|
-
// from the snapped level.
|
|
1688
|
-
//
|
|
1736
|
+
// β = the fundamental-sequence index recovering the ordinal
|
|
1737
|
+
// from the snapped level. Carry in the TOP coefficient
|
|
1738
|
+
// (ω^p·c → ω^(p+1)): the index is c+1 —
|
|
1689
1739
|
// 10{ω²·50+ω·100+100}100 → "2.000Aaaa51"
|
|
1690
1740
|
// 10{ω²·100+ω·100+100}100 → "2.000Aaaa101"
|
|
1691
1741
|
// 10{ω²·200+…}100 → "2.000Aaaa201"
|
|
1692
|
-
// (
|
|
1693
|
-
//
|
|
1694
|
-
//
|
|
1742
|
+
// (the largest coefficient collapsed all three into one
|
|
1743
|
+
// string). Carry BELOW the top (ω·2+100 → ω·3): the index is
|
|
1744
|
+
// the operation's argument.
|
|
1695
1745
|
let gbeta = (topRow[0] || 1) + 2
|
|
1696
1746
|
for (let g2 = oc.length - 1; g2 >= 0; g2--) {
|
|
1697
1747
|
let gc2 = Math.round(oc[g2])
|
|
@@ -1926,15 +1976,14 @@ function formatOrdinal(num, precision, precision4) {
|
|
|
1926
1976
|
|
|
1927
1977
|
if (heights.length >= 1) {
|
|
1928
1978
|
// ── Display rules (README "format-metanum rules (v2.0)") ──
|
|
1929
|
-
// * the rows are a COMPOSITION: the top row
|
|
1930
|
-
//
|
|
1931
|
-
//
|
|
1932
|
-
// every lower row compresses into that inner argument);
|
|
1979
|
+
// * the rows are a COMPOSITION: the top row leads and the row
|
|
1980
|
+
// below supplies the single α and β (at most TWO letter
|
|
1981
|
+
// types — lower rows compress into that inner argument);
|
|
1933
1982
|
// * "+count collapse": count >= multiLetterRepeatThreshold+1
|
|
1934
|
-
// repeats
|
|
1935
|
-
//
|
|
1936
|
-
// * stacking the same function
|
|
1937
|
-
// poea(10,poea(10,100))
|
|
1983
|
+
// repeats collapse to ONE next letter with arg count+1
|
|
1984
|
+
// (F⁴(G(1.3796)) = G(5.3796));
|
|
1985
|
+
// * stacking the same function nests the letter:
|
|
1986
|
+
// poea(10,poea(10,100)) → "Ad1.000Ad99";
|
|
1938
1987
|
// * a combination longer than multiLetterLimit carries to the
|
|
1939
1988
|
// symbol notation !αAaβ.
|
|
1940
1989
|
let effTh = Math.max(2, FORMAT_OPTIONS.multiLetterRepeatThreshold)
|