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/metanum.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//Author: dlsdl v2.
|
|
2
|
-
//v2.
|
|
1
|
+
//Author: dlsdl v2.1
|
|
2
|
+
//v2.1
|
|
3
3
|
//Code snippets and templates from OmegaNum.js
|
|
4
4
|
|
|
5
5
|
;(function (globalScope) {
|
|
@@ -228,6 +228,33 @@
|
|
|
228
228
|
return Math.log10(Number(str.substring(0, LONG_STRING_MIN_LENGTH))) + (str.length - LONG_STRING_MIN_LENGTH);
|
|
229
229
|
};
|
|
230
230
|
|
|
231
|
+
// Sub-unit canonical form: 0 < |v| < 1 is stored as the RECIPROCAL with
|
|
232
|
+
// sign 2 / -2 (README: sign 2 / -2 == 0~1 / -1~0). _skipCanon lets rec()
|
|
233
|
+
// produce that reciprocal without this rule turning it back.
|
|
234
|
+
var _skipCanon = 0;
|
|
235
|
+
function canonicalizeSubUnit(x) {
|
|
236
|
+
if (_skipCanon) return x;
|
|
237
|
+
if (x.layer !== 0 || x.array.length !== 1) return x;
|
|
238
|
+
var r = x.array[0];
|
|
239
|
+
if (x.sign !== 1 && x.sign !== -1) return x; // already reciprocal-encoded
|
|
240
|
+
if (r.length === 1) {
|
|
241
|
+
var v = r[0];
|
|
242
|
+
if (!(typeof v === 'number') || !isFinite(v) || v <= 0 || v >= 1) return x;
|
|
243
|
+
r[0] = 1 / v;
|
|
244
|
+
x.sign = x.sign === -1 ? -2 : 2;
|
|
245
|
+
return x;
|
|
246
|
+
}
|
|
247
|
+
if (r.length === 2 && r[1] === 1) {
|
|
248
|
+
// 10^e with a negative exponent is sub-unit: store 10^(-e) as reciprocal
|
|
249
|
+
var e = r[0];
|
|
250
|
+
if (!(typeof e === 'number') || !isFinite(e) || e >= 0) return x;
|
|
251
|
+
r[0] = -e;
|
|
252
|
+
x.sign = x.sign === -1 ? -2 : 2;
|
|
253
|
+
return x;
|
|
254
|
+
}
|
|
255
|
+
return x;
|
|
256
|
+
}
|
|
257
|
+
|
|
231
258
|
P.normalize = function () {
|
|
232
259
|
var b;
|
|
233
260
|
var x = this;
|
|
@@ -469,6 +496,34 @@
|
|
|
469
496
|
return x;
|
|
470
497
|
};
|
|
471
498
|
|
|
499
|
+
// Apply the sub-unit canonical form to a PUBLIC result (constructor input,
|
|
500
|
+
// basic arithmetic). Deliberately not part of normalize(): internal
|
|
501
|
+
// intermediates (transcendentals, slog, gamma, hardy's coefficients) read r0
|
|
502
|
+
// structurally, so canonicalizing there broke them.
|
|
503
|
+
function canonicalizeResult(x) {
|
|
504
|
+
if (x instanceof MetaNum) canonicalizeSubUnit(x);
|
|
505
|
+
return x;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// Constructor that never applies the sub-unit canonical form — for engine
|
|
509
|
+
// internals whose values are consumed STRUCTURALLY (transcendentals' results
|
|
510
|
+
// like log10(2) = 0.301, slog, gamma, pent_log, hardy's fractional
|
|
511
|
+
// coefficients); canonicalizing them turned r0[0] from 0.301 into 3.32.
|
|
512
|
+
function rawMetaNum(v) {
|
|
513
|
+
_skipCanon++;
|
|
514
|
+
try { return new MetaNum(v); } finally { _skipCanon--; }
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// Run fn with the sub-unit canonical form suppressed — for the engine
|
|
518
|
+
// functions that CONSUME sub-unit magnitudes structurally (gamma's series,
|
|
519
|
+
// slog's log10 chain, layeradd/pentate inverses): a canonicalized
|
|
520
|
+
// intermediate (log10(2) → r0 [3.32] instead of [0.301]) produced garbage.
|
|
521
|
+
// The PRODUCERS stay canonicalized, so the public contract holds.
|
|
522
|
+
function rawBody(fn, self, args) {
|
|
523
|
+
_skipCanon++;
|
|
524
|
+
try { return fn.apply(self, args || []); } finally { _skipCanon--; }
|
|
525
|
+
}
|
|
526
|
+
|
|
472
527
|
var standardizeMessageSent = false;
|
|
473
528
|
P.standardize = function () {
|
|
474
529
|
if (!standardizeMessageSent) console.warn(metaNumError + "'standardize' method is being deprecated in favor of 'normalize' and will be removed in the future!"), standardizeMessageSent = true;
|
|
@@ -501,6 +556,19 @@
|
|
|
501
556
|
if (this.array[0] && isNaN(this.array[0][0])) return NaN;
|
|
502
557
|
if (other.array[0] && isNaN(other.array[0][0])) return NaN;
|
|
503
558
|
|
|
559
|
+
// Plain finite numerics (any sign, including the sub-unit encoding 2/-2)
|
|
560
|
+
// compare as real numbers. The structural path below reads r0 as the
|
|
561
|
+
// magnitude and only inverts at the very end, so a sign-2 value like 0.2
|
|
562
|
+
// (stored as r0 = [5]) used to compare as 5 — every `lt`/`gt`/`eq` against a
|
|
563
|
+
// sub-unit value was wrong.
|
|
564
|
+
var tNum = plainNumericValue(this);
|
|
565
|
+
var oNum = plainNumericValue(other);
|
|
566
|
+
if (tNum !== null && oNum !== null) {
|
|
567
|
+
if (tNum < oNum) return -1;
|
|
568
|
+
if (tNum > oNum) return 1;
|
|
569
|
+
return 0;
|
|
570
|
+
}
|
|
571
|
+
|
|
504
572
|
var tInf = this.array[0] && this.array[0][0] === Infinity;
|
|
505
573
|
var oInf = other.array[0] && other.array[0][0] === Infinity;
|
|
506
574
|
|
|
@@ -547,14 +615,11 @@
|
|
|
547
615
|
while (tRows > 1 && isZeroArr(this.array[tRows - 1])) tRows--;
|
|
548
616
|
while (oRows > 1 && isZeroArr(other.array[oRows - 1])) oRows--;
|
|
549
617
|
|
|
550
|
-
// Compare ordinal rows (index >= 1) as
|
|
551
|
-
//
|
|
552
|
-
//
|
|
553
|
-
//
|
|
554
|
-
//
|
|
555
|
-
// alone would wrongly rank 99 finite-level rows above 1 ω-level row, so we
|
|
556
|
-
// descend from the top, cancelling equal leading rows, and decide at the
|
|
557
|
-
// first row whose level/count differs (cmpArr encodes level then count).
|
|
618
|
+
// Compare ordinal rows (index >= 1) as CNF: rows are sorted by level
|
|
619
|
+
// ascending, so the leading (highest-level) term is last and dominates — one
|
|
620
|
+
// ω-level row ([1,0,1]) beats any number of finite-level rows. Descend from
|
|
621
|
+
// the top, cancel equal leading rows, decide at the first differing
|
|
622
|
+
// level/count (cmpArr encodes level then count).
|
|
558
623
|
var i = tRows - 1;
|
|
559
624
|
var j = oRows - 1;
|
|
560
625
|
while (i >= 1 || j >= 1) {
|
|
@@ -796,6 +861,30 @@
|
|
|
796
861
|
return x.sign === 2 || x.sign === -2;
|
|
797
862
|
}
|
|
798
863
|
|
|
864
|
+
// The plain r0 magnitude as the engine's own numeric routines expect it:
|
|
865
|
+
// for a sub-unit value (sign 2/-2) r0 holds the RECIPROCAL, so unwrap it.
|
|
866
|
+
// Use this wherever a function does `isSimple(x) ? x.array[0][0] : …` to feed
|
|
867
|
+
// a float routine — otherwise 0.5 (r0 [2]) is read as 2.
|
|
868
|
+
function magnitudeOf(x) {
|
|
869
|
+
if (!isSmall(x)) return x.array[0][0];
|
|
870
|
+
return 1 / x.array[0][0];
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// Real value of a plain finite numeric MetaNum, or null when the value is
|
|
874
|
+
// structured (layer > 0, ordinal rows, E/power-tower r0) and must go through
|
|
875
|
+
// the structural comparison. sign 2/-2 is the sub-unit encoding: r0 holds
|
|
876
|
+
// the reciprocal, so the value is 1/r0 (negated for -2).
|
|
877
|
+
function plainNumericValue(x) {
|
|
878
|
+
if (x.layer !== 0 || x.array.length !== 1) return null;
|
|
879
|
+
var r0 = x.array[0];
|
|
880
|
+
if (r0.length !== 1) return null;
|
|
881
|
+
var v = r0[0];
|
|
882
|
+
if (typeof v !== 'number' || !isFinite(v) || v === 0) return null;
|
|
883
|
+
if (x.sign === 2) return 1 / v;
|
|
884
|
+
if (x.sign === -2) return -1 / v;
|
|
885
|
+
return x.sign === -1 ? -v : v;
|
|
886
|
+
}
|
|
887
|
+
|
|
799
888
|
function isNumeric(x) {
|
|
800
889
|
return x.layer === 0 && x.array.length === 1 &&
|
|
801
890
|
x.array[0].length === 1 && isFinite(x.array[0][0]);
|
|
@@ -857,15 +946,11 @@
|
|
|
857
946
|
return x;
|
|
858
947
|
}
|
|
859
948
|
|
|
860
|
-
// Like toNumber(), but returns the
|
|
861
|
-
//
|
|
862
|
-
//
|
|
863
|
-
//
|
|
864
|
-
//
|
|
865
|
-
// array has ordinal rows, which is too conservative for count extraction:
|
|
866
|
-
// 10^16 is a perfectly finite JS number. We only return Infinity for genuine
|
|
867
|
-
// ordinals (layer>0 or array.length>1) or values too large for any JS number
|
|
868
|
-
// (tetration+ or 10^(>=309)); the caller falls back to the ordinal branch.
|
|
949
|
+
// Like toNumber(), but returns the finite JS value for E-notation numbers
|
|
950
|
+
// (10^16 = [[16,1]]) instead of Infinity — used to extract iteration counts
|
|
951
|
+
// (count = y-2) in expande/multiexpande/powerexpande. Infinity only for
|
|
952
|
+
// genuine ordinals (layer>0 or array.length>1) or values beyond double range
|
|
953
|
+
// (tetration+, 10^(>=309)); the caller then takes the ordinal branch.
|
|
869
954
|
function metaFiniteCount(y) {
|
|
870
955
|
if (y.isNaN()) return NaN;
|
|
871
956
|
if (y.layer > 0) return Infinity; // ω^ω^... tower
|
|
@@ -1011,9 +1096,11 @@
|
|
|
1011
1096
|
var domMul = layerDominant(x, other);
|
|
1012
1097
|
if (domMul !== null) return domMul.clone().normalize();
|
|
1013
1098
|
|
|
1014
|
-
if (isSimple(x) && isSimple(other)
|
|
1015
|
-
|
|
1016
|
-
|
|
1099
|
+
if (isSimple(x) && isSimple(other)) {
|
|
1100
|
+
// magnitudeOf: sub-unit operands (sign 2/-2) store the reciprocal, so
|
|
1101
|
+
// read the real values — otherwise 0.5·0.5 multiplied 2·2 = 4.
|
|
1102
|
+
var nx = magnitudeOf(x);
|
|
1103
|
+
var ny = magnitudeOf(other);
|
|
1017
1104
|
var n = nx * ny;
|
|
1018
1105
|
if (isFinite(n) && n !== 0 && Math.abs(n) <= MAX_SAFE_INTEGER) {
|
|
1019
1106
|
if (Math.abs(n) < 1) return new MetaNum(1 / Math.abs(n)).rec();
|
|
@@ -1066,9 +1153,11 @@
|
|
|
1066
1153
|
}
|
|
1067
1154
|
|
|
1068
1155
|
if (x.eq(MetaNum.ZERO)) return MetaNum.ZERO.clone();
|
|
1069
|
-
if (isSimple(x) && isSimple(other)
|
|
1070
|
-
|
|
1071
|
-
|
|
1156
|
+
if (isSimple(x) && isSimple(other)) {
|
|
1157
|
+
// magnitudeOf: sub-unit operands store the reciprocal — 0.5 / 0.25 must
|
|
1158
|
+
// read 0.5 and 0.25, not 2 and 4.
|
|
1159
|
+
var nx = magnitudeOf(x);
|
|
1160
|
+
var ny = magnitudeOf(other);
|
|
1072
1161
|
var n = nx / ny;
|
|
1073
1162
|
if (isFinite(n) && n !== 0 && Math.abs(n) <= MAX_SAFE_INTEGER) {
|
|
1074
1163
|
if (Math.abs(n) < 1) return new MetaNum(1 / Math.abs(n)).rec();
|
|
@@ -1111,7 +1200,10 @@
|
|
|
1111
1200
|
var x = this.clone();
|
|
1112
1201
|
// Toggle between large and small: 1↔2, -1↔-2
|
|
1113
1202
|
x.sign = x.sign === 1 ? 2 : x.sign === 2 ? 1 : x.sign === -1 ? -2 : -1;
|
|
1114
|
-
|
|
1203
|
+
// _skipCanon: the reciprocal of a sub-unit value is a NORMAL value (rec(0.5)
|
|
1204
|
+
// = 2) — canonicalizeSubUnit would otherwise flip it straight back.
|
|
1205
|
+
_skipCanon++;
|
|
1206
|
+
try { return x.normalize(); } finally { _skipCanon--; }
|
|
1115
1207
|
};
|
|
1116
1208
|
Q.reciprocate = Q.rec = function (x) {
|
|
1117
1209
|
return new MetaNum(x).rec();
|
|
@@ -1137,7 +1229,12 @@
|
|
|
1137
1229
|
var powVal = Math.pow(x.toNumber(), other.toNumber());
|
|
1138
1230
|
if (Number.isFinite(powVal) && Math.abs(powVal) <= MAX_SAFE_INTEGER && powVal !== 0) return new MetaNum(powVal);
|
|
1139
1231
|
}
|
|
1140
|
-
|
|
1232
|
+
// 10^e fast path. Only for POSITIVE exponents: `other` stores its
|
|
1233
|
+
// magnitude in r0 with the sign held separately, so a negative exponent
|
|
1234
|
+
// (-324 → array [[324]], sign -1) must NOT be turned into 10^(+324) here.
|
|
1235
|
+
// Negative exponents fall through to the log/normalise path below, which
|
|
1236
|
+
// yields the sub-unit encoding (sign 2 / -2).
|
|
1237
|
+
if (x.eq(MetaNum.TEN) && !isSmall(other) && other.sign === 1) {
|
|
1141
1238
|
if (other.layer > 0 || other.array.length > 1) return other;
|
|
1142
1239
|
var newRow0 = other.array[0].slice(0);
|
|
1143
1240
|
newRow0[1] = (newRow0[1] || 0) + 1;
|
|
@@ -1202,7 +1299,11 @@
|
|
|
1202
1299
|
if (other.mod(2).eq(MetaNum.ONE)) return x.abs().root(other).neg();
|
|
1203
1300
|
return MetaNum.NaN.clone();
|
|
1204
1301
|
}
|
|
1205
|
-
if (isNumeric(x) && isNumeric(other))
|
|
1302
|
+
if (isNumeric(x) && isNumeric(other)) {
|
|
1303
|
+
// magnitudeOf: a sub-unit x (sign 2) stores the reciprocal in r0, so
|
|
1304
|
+
// sqrt(0.25) must read 0.25, not the stored 4 (which gave 2).
|
|
1305
|
+
return new MetaNum(Math.pow(magnitudeOf(x), 1 / magnitudeOf(other)));
|
|
1306
|
+
}
|
|
1206
1307
|
// Handle E^m format (iterated exponentiation levels)
|
|
1207
1308
|
if (x.layer === 0 && x.array.length === 1 && x.array[0].length > 1 && isNumeric(other)) {
|
|
1208
1309
|
var r0 = x.array[0];
|
|
@@ -1260,21 +1361,21 @@
|
|
|
1260
1361
|
P.generalLogarithm = P.log10 = function () {
|
|
1261
1362
|
if (this.isNaN() || this.sign === -1 || this.sign === -2) return MetaNum.NaN.clone();
|
|
1262
1363
|
if (this.isInfinite()) return this;
|
|
1263
|
-
if (isSmall(this)) {
|
|
1264
|
-
// Small value: log10 is negative of what it would be for the normal value
|
|
1265
|
-
var n = this.clone();
|
|
1266
|
-
n.sign = 1; // Convert to normal positive for computation
|
|
1267
|
-
var result = n.log10();
|
|
1268
|
-
// Result should be negative (because log10 of a small number is negative)
|
|
1269
|
-
// Need to handle this carefully - after conversion, the result is the magnitude
|
|
1270
|
-
// which we need to negate
|
|
1271
|
-
return result.neg();
|
|
1272
|
-
}
|
|
1273
1364
|
if (this.eq(MetaNum.ZERO)) return MetaNum.NEGATIVE_INFINITY.clone();
|
|
1274
1365
|
if (isNumeric(this)) {
|
|
1275
|
-
|
|
1366
|
+
// magnitudeOf: a sub-unit operand stores the reciprocal in r0, so
|
|
1367
|
+
// log10(0.5) must read 0.5, not the stored 2.
|
|
1368
|
+
var lv = Math.log10(magnitudeOf(this));
|
|
1276
1369
|
if (Number.isFinite(lv)) return new MetaNum(lv);
|
|
1277
1370
|
}
|
|
1371
|
+
// Sub-unit E-form: sign 2/-2 with an r0 longer than 1 stores the
|
|
1372
|
+
// RECIPROCAL (e.g. 10^-324 → [[324,1]] sign 2). log10(1/|x|) = -log10(|x|),
|
|
1373
|
+
// and rec() unwraps the reciprocal back to the magnitude. Without this,
|
|
1374
|
+
// log10(10^-324) returned +324, so 10^-324 · 10^324 became 10^648.
|
|
1375
|
+
if (this.sign === 2 &&
|
|
1376
|
+
this.layer === 0 && this.array.length === 1 && this.array[0].length > 1) {
|
|
1377
|
+
return this.rec().log10().neg();
|
|
1378
|
+
}
|
|
1278
1379
|
if (this.layer === 0 && this.array.length === 1 && this.array[0].length > 1) {
|
|
1279
1380
|
var r0 = this.array[0];
|
|
1280
1381
|
if (r0[1] > 0) {
|
|
@@ -1298,7 +1399,7 @@
|
|
|
1298
1399
|
if (x.eq(MetaNum.ZERO)) return MetaNum.NEGATIVE_INFINITY.clone();
|
|
1299
1400
|
if (x.eq(MetaNum.ONE)) return MetaNum.ZERO.clone();
|
|
1300
1401
|
if (isNumeric(x) && isNumeric(base)) {
|
|
1301
|
-
var lv = Math.log(x
|
|
1402
|
+
var lv = Math.log(magnitudeOf(x)) / Math.log(magnitudeOf(base));
|
|
1302
1403
|
if (Number.isFinite(lv)) return new MetaNum(lv);
|
|
1303
1404
|
}
|
|
1304
1405
|
return x.log10().div(base.log10());
|
|
@@ -1308,11 +1409,14 @@
|
|
|
1308
1409
|
};
|
|
1309
1410
|
|
|
1310
1411
|
P.naturalLogarithm = P.ln = function () {
|
|
1311
|
-
if (this.
|
|
1412
|
+
if (this.sign === -1 || this.sign === -2) return MetaNum.NaN.clone();
|
|
1413
|
+
if (this.isNaN()) return MetaNum.NaN.clone();
|
|
1312
1414
|
if (this.eq(MetaNum.ZERO)) return MetaNum.NEGATIVE_INFINITY.clone();
|
|
1313
1415
|
if (this.isInfinite()) return this;
|
|
1314
1416
|
if (isNumeric(this)) {
|
|
1315
|
-
|
|
1417
|
+
// magnitudeOf: a sub-unit operand stores the reciprocal in r0, so
|
|
1418
|
+
// ln(0.5) must read 0.5, not the stored 2.
|
|
1419
|
+
var lv = Math.log(magnitudeOf(this));
|
|
1316
1420
|
if (Number.isFinite(lv)) return new MetaNum(lv);
|
|
1317
1421
|
}
|
|
1318
1422
|
return this.log10().div(new MetaNum(Math.LOG10E));
|
|
@@ -1354,7 +1458,7 @@
|
|
|
1354
1458
|
if (this.sign === -1 || this.sign === -2) return MetaNum.NaN.clone();
|
|
1355
1459
|
if (this.isNaN() || this.isInfinite()) return this.clone();
|
|
1356
1460
|
if (isSimple(this)) {
|
|
1357
|
-
var n = this
|
|
1461
|
+
var n = magnitudeOf(this); // sub-unit r0 holds the reciprocal
|
|
1358
1462
|
if (Number.isInteger(n) && n >= 0 && n <= 100) {
|
|
1359
1463
|
var f = 1;
|
|
1360
1464
|
for (var i = 2; i < n; i++) f *= i;
|
|
@@ -1377,7 +1481,7 @@
|
|
|
1377
1481
|
if (this.isNaN() || this.isInfinite()) return this;
|
|
1378
1482
|
if (this.sign === -1 || this.sign === -2) return this.abs().fact().neg();
|
|
1379
1483
|
if (isSimple(this)) {
|
|
1380
|
-
var n = this
|
|
1484
|
+
var n = magnitudeOf(this); // sub-unit r0 holds the reciprocal
|
|
1381
1485
|
if (Number.isInteger(n) && n >= 0 && n <= 20) {
|
|
1382
1486
|
var f = 1;
|
|
1383
1487
|
for (var i = 2; i <= n; i++) f *= i;
|
|
@@ -1415,7 +1519,7 @@
|
|
|
1415
1519
|
if (this.gt(MetaNum.E_MAX_SAFE_INTEGER)) return d_lambertw(this, tol, principal);
|
|
1416
1520
|
if (isNumeric(this)) {
|
|
1417
1521
|
try {
|
|
1418
|
-
return new MetaNum(f_lambertw(this
|
|
1522
|
+
return new MetaNum(f_lambertw(magnitudeOf(this), tol, principal));
|
|
1419
1523
|
} catch (e) {
|
|
1420
1524
|
return MetaNum.NaN.clone();
|
|
1421
1525
|
}
|
|
@@ -1428,7 +1532,8 @@
|
|
|
1428
1532
|
if (this.abs().gt(MetaNum.E_MAX_SAFE_INTEGER)) return d_lambertw(this, tol, principal);
|
|
1429
1533
|
if (isNumeric(this)) {
|
|
1430
1534
|
try {
|
|
1431
|
-
return new MetaNum(f_lambertw(
|
|
1535
|
+
return new MetaNum(f_lambertw(
|
|
1536
|
+
(this.sign === -2 ? -1 : this.sign) * magnitudeOf(this.abs()), tol, principal));
|
|
1432
1537
|
} catch (e) {
|
|
1433
1538
|
return MetaNum.NaN.clone();
|
|
1434
1539
|
}
|
|
@@ -1594,7 +1699,7 @@
|
|
|
1594
1699
|
if (this.eq(MetaNum.ZERO)) return MetaNum.ZERO.clone();
|
|
1595
1700
|
if (this.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
1596
1701
|
if (isSimple(this)) {
|
|
1597
|
-
var v = this
|
|
1702
|
+
var v = magnitudeOf(this);
|
|
1598
1703
|
if (v > 0 && v < 1) return new MetaNum(v);
|
|
1599
1704
|
try {
|
|
1600
1705
|
var w = f_lambertw(Math.log(v));
|
|
@@ -1846,13 +1951,9 @@
|
|
|
1846
1951
|
}
|
|
1847
1952
|
|
|
1848
1953
|
// Fast construction of the diagonal chain D(L) = t{L}t for a plain finite
|
|
1849
|
-
// integer base t.
|
|
1850
|
-
//
|
|
1851
|
-
//
|
|
1852
|
-
// once builds the identical normalized array bottom-up:
|
|
1853
|
-
// D(1) = t{1}t ; D(n+1) = t{n}^{t-1}(t) = t{n}^{t-2}(D(n))
|
|
1854
|
-
// Each t{n}(D(n)) step is the engine's own structured-value fast path, so
|
|
1855
|
-
// the result is array-identical to the recursive evaluation, in O(L^2).
|
|
1954
|
+
// integer base t. The generic recursion is ~O(n^3) (3{99}3 took ~5.5s);
|
|
1955
|
+
// unrolling rule 2 once builds the identical array bottom-up in O(L^2):
|
|
1956
|
+
// D(1) = t{1}t ; D(n+1) = t{n}^{t-2}(D(n))
|
|
1856
1957
|
function canFastDiagonal(t) {
|
|
1857
1958
|
if (t.layer !== 0 || t.array.length !== 1) return false;
|
|
1858
1959
|
var n = t.toNumber();
|
|
@@ -1885,19 +1986,13 @@
|
|
|
1885
1986
|
return r;
|
|
1886
1987
|
}
|
|
1887
1988
|
|
|
1888
|
-
// Convert a structured raw-application COUNT C at finite
|
|
1889
|
-
//
|
|
1890
|
-
//
|
|
1891
|
-
//
|
|
1892
|
-
//
|
|
1893
|
-
//
|
|
1894
|
-
//
|
|
1895
|
-
// Raw application COUNT C at operation level n ({n}^C(10)) -> the dlsdl
|
|
1896
|
-
// diagonal-letter smooth argument α in [2,10) with v = 10{n+2}(α).
|
|
1897
|
-
// Start from C=10{level}(t) (polarize: a scalar C starts at level 1 with
|
|
1898
|
-
// t=log10(C)), then each level promotion is the geometric smooth-log step
|
|
1899
|
-
// t → 1+log10(t) (exact t=10 rewrites to the α-anchor 2). The final value
|
|
1900
|
-
// lands in [1,2); the diagonal mantissa is α=1+t (2 at the anchor).
|
|
1989
|
+
// Convert a structured raw-application COUNT C at finite level n ({n}^C(10))
|
|
1990
|
+
// to the dlsdl Aa-band smooth argument α (v = 10{n+2}(α)), α ∈ [2,10).
|
|
1991
|
+
// Polarize C to 10{level}(t) (a scalar C starts at level 1, t=log10(C)); each
|
|
1992
|
+
// level promotion is the smooth-log step t → 1+log10(t), and the exact anchor
|
|
1993
|
+
// t=10 rewrites to mantissa 2 one level up (10{k}10 = 10{k+1}2). The final
|
|
1994
|
+
// value lands in [1,2); the mantissa is α = 1+t. Matches dlsdl rule
|
|
1995
|
+
// (iii)-(v): {99}^{10{93}10}(10) = 10{101}(2.001607…).
|
|
1901
1996
|
function countToDiagonalAlpha(C, n, r0OfC, rowsOfC) {
|
|
1902
1997
|
var t, level;
|
|
1903
1998
|
if (r0OfC === undefined || r0OfC === null) {
|
|
@@ -2029,12 +2124,10 @@
|
|
|
2029
2124
|
return { bottom: b(), repeation: array[ptr][1], arrows: array[ptr][0] };
|
|
2030
2125
|
}
|
|
2031
2126
|
|
|
2032
|
-
// Canonical compact form of the smooth diagonal
|
|
2033
|
-
//
|
|
2034
|
-
//
|
|
2035
|
-
//
|
|
2036
|
-
// mantissa is preserved at arbitrary finite levels (used where the iterated
|
|
2037
|
-
// arrow loop would MSI-dump the fraction away).
|
|
2127
|
+
// Canonical compact form of the smooth diagonal 10{L}(α), α numeric in
|
|
2128
|
+
// [1,10): r0=[1] plus one finite row [α, L-1]. The fractional row count
|
|
2129
|
+
// survives normalization and polarize climbs it back to t=α at level L-1, so
|
|
2130
|
+
// the smooth mantissa survives at arbitrary finite levels.
|
|
2038
2131
|
function compactSmoothValue(L, alpha) {
|
|
2039
2132
|
var m = new MetaNum({ sign: 1, layer: 0, array: [[1], [alpha, L - 1]] });
|
|
2040
2133
|
return m.normalize();
|
|
@@ -2046,13 +2139,10 @@
|
|
|
2046
2139
|
arrows = new MetaNum(arrows);
|
|
2047
2140
|
if (arrows.sign === -1 || arrows.sign === -2) return function () { return MetaNum.NaN.clone(); };
|
|
2048
2141
|
if (!arrows.isint()) {
|
|
2049
|
-
// Fractional hyperoperation level
|
|
2050
|
-
//
|
|
2051
|
-
//
|
|
2052
|
-
// diagonal 10{n+f}10 = 10{n+1}(2·5^f).
|
|
2053
|
-
// x{n+1}θ0 = x{n}y (recovered via hyper_log), θ1 = y, θf = θ0·(y/θ0)^f,
|
|
2054
|
-
// so x{n+f}y = x{n+1}(θf), continuous in f with
|
|
2055
|
-
// x{n}y at f=0 and x{n+1}y at f=1.
|
|
2142
|
+
// Fractional hyperoperation level — geometric interpolation (README
|
|
2143
|
+
// rule (i)): level n+f is the (n+1)-level op on the interpolated argument
|
|
2144
|
+
// θf = θ0·(y/θ0)^f, where θ0 solves x{n+1}θ0 = x{n}y (via hyper_log) and
|
|
2145
|
+
// θ1 = y; the canonical diagonal 10{n+f}10 = 10{n+1}(2·5^f).
|
|
2056
2146
|
if (arrows.gte(MetaNum.ONE)) {
|
|
2057
2147
|
var nLev = arrows.floor();
|
|
2058
2148
|
var frac = arrows.sub(nLev);
|
|
@@ -2147,16 +2237,12 @@
|
|
|
2147
2237
|
if (alphaC !== null && alphaC >= 2) return compactSmoothValue(arrowsNum + 1, alphaC);
|
|
2148
2238
|
}
|
|
2149
2239
|
if (arrowsNum >= MetaNum.maxCols) {
|
|
2150
|
-
// Finite arrow level beyond r0 capacity:
|
|
2151
|
-
//
|
|
2152
|
-
//
|
|
2153
|
-
//
|
|
2154
|
-
//
|
|
2155
|
-
//
|
|
2156
|
-
// and approximate beyond the budget: keep the LARGEST maxRows-1
|
|
2157
|
-
// ordinal rows, the ARRAY's second row (first-kept ordinal row) first column +1,
|
|
2158
|
-
// first row [10].
|
|
2159
|
-
// Swallowing: a finite level sits below any existing ω-level row.
|
|
2240
|
+
// Finite arrow level beyond r0 capacity: expand exactly as far as the
|
|
2241
|
+
// budget allows (r0 to maxCols + [count, level] rows for the rest; the
|
|
2242
|
+
// top level L is the 10{L}2 = 10{L-1}10 anchor and takes no row), then
|
|
2243
|
+
// approximate — keep the LARGEST maxRows-1 rows, bump the first kept
|
|
2244
|
+
// row's count by 1 (truncation marker), base [10]. A finite level sits
|
|
2245
|
+
// below any existing ω-level row (swallowing).
|
|
2160
2246
|
var j = t.max(other).clone();
|
|
2161
2247
|
if (j.layer > 0) return j; // ω^ω-tower swallows any finite level
|
|
2162
2248
|
var idx = -1;
|
|
@@ -2193,14 +2279,11 @@
|
|
|
2193
2279
|
j.normalize();
|
|
2194
2280
|
return j;
|
|
2195
2281
|
}
|
|
2196
|
-
//
|
|
2197
|
-
//
|
|
2198
|
-
//
|
|
2199
|
-
//
|
|
2200
|
-
//
|
|
2201
|
-
// 3{9}3 → 1 op/level, 4{9}4 → 2, 10{25}10 → 8 ops/level (the
|
|
2202
|
-
// canonical all-8s form). The top level L itself is the
|
|
2203
|
-
// 10{L}2 = 10{L-1}10 anchor and takes no row.
|
|
2282
|
+
// Plain finite base: expand the diagonal chain bottom-up —
|
|
2283
|
+
// x{L}y = x{L-1}^{y-2}(x{L-1}x), so the top level L-1 carries (y-2) ops
|
|
2284
|
+
// and every level below (the x{L-1}x tail) carries (x-2): 3{9}3 → 1
|
|
2285
|
+
// op/level, 10{25}10 → 8 (the canonical all-8s form). The top level L
|
|
2286
|
+
// is the 10{L}2 = 10{L-1}10 anchor and takes no row.
|
|
2204
2287
|
var subDepth = MetaNum.maxCols - 1;
|
|
2205
2288
|
var xBase = t.toNumber();
|
|
2206
2289
|
var yBase = other.toNumber();
|
|
@@ -2318,11 +2401,9 @@
|
|
|
2318
2401
|
var fastDiag = isFinite(y) && Math.floor(y) === y && canFastDiagonal(t);
|
|
2319
2402
|
if (arrowsNum >= 23 && y !== Math.floor(y) && Math.floor(y) > 2) {
|
|
2320
2403
|
// Large integer part with a fractional tail at a high level: the tail
|
|
2321
|
-
// would be amplified by the many iterations (
|
|
2322
|
-
//
|
|
2323
|
-
//
|
|
2324
|
-
// bottoms out numerically and carries the smooth Aa-diagonal mantissa
|
|
2325
|
-
// (e.g. 10{101}(2.001607)).
|
|
2404
|
+
// would be amplified by the many iterations (10{69}69.6 ≈ 10{69}10), so
|
|
2405
|
+
// use the discrete 10 anchor. y with floor ≤ 2 keeps the smooth path
|
|
2406
|
+
// (carries the Aa-diagonal mantissa, e.g. 10{101}(2.001607)).
|
|
2326
2407
|
y = 10;
|
|
2327
2408
|
fastDiag = false;
|
|
2328
2409
|
}
|
|
@@ -2376,14 +2457,11 @@
|
|
|
2376
2457
|
};
|
|
2377
2458
|
|
|
2378
2459
|
// ==================== hyper_log / hyper_root ====================
|
|
2379
|
-
// Inverses of
|
|
2380
|
-
//
|
|
2381
|
-
//
|
|
2382
|
-
//
|
|
2383
|
-
//
|
|
2384
|
-
// maxCols the forward arrow diagonalizes into one [1|b] marker row and the
|
|
2385
|
-
// argument is no longer recoverable — the bisection then returns the
|
|
2386
|
-
// smallest argument that reproduces d.
|
|
2460
|
+
// Inverses of a{b}c = d: d.hyper_log(a)(b) = c, d.hyper_root(c)(b) = a.
|
|
2461
|
+
// b = 0/1 use exact division and logarithms; b ≥ 2 bisects on the monotone
|
|
2462
|
+
// arrow engine. For levels b beyond maxCols the forward arrow diagonalizes
|
|
2463
|
+
// into one [1|b] row and the argument is not recoverable — the bisection
|
|
2464
|
+
// returns the smallest argument reproducing d.
|
|
2387
2465
|
function hyperBisect(f, target, bound) {
|
|
2388
2466
|
// smallest integer x ≥ 1 with f(x) ≥ target (f monotone nondecreasing)
|
|
2389
2467
|
var lo = MetaNum.ONE.clone();
|
|
@@ -2405,13 +2483,11 @@
|
|
|
2405
2483
|
return hi;
|
|
2406
2484
|
}
|
|
2407
2485
|
|
|
2408
|
-
// Continuous inverse
|
|
2409
|
-
//
|
|
2410
|
-
//
|
|
2411
|
-
//
|
|
2412
|
-
//
|
|
2413
|
-
// breaks the monotonicity of x{y}y — arrow(10,1.5,1.5) came out smaller than
|
|
2414
|
-
// arrow(10,1.1,1.1). Returns null when d cannot be bracketed.
|
|
2486
|
+
// Continuous inverse — the interpolation ANCHOR of a fractional level: the
|
|
2487
|
+
// real c with a{b}c = d, bisected on doubles. hyperBisect only searches
|
|
2488
|
+
// integers and overshoots (θ0 = 2 where the truth is 1.0414), which made the
|
|
2489
|
+
// geometric interpolation run BACKWARDS and broke the monotonicity of x{y}y
|
|
2490
|
+
// (arrow(10,1.5,1.5) < arrow(10,1.1,1.1)). null when d cannot be bracketed.
|
|
2415
2491
|
function hyperAnchorReal(a, b, d) {
|
|
2416
2492
|
try {
|
|
2417
2493
|
var lo = 0, hi = 1, it = 0;
|
|
@@ -2659,19 +2735,16 @@
|
|
|
2659
2735
|
};
|
|
2660
2736
|
|
|
2661
2737
|
// ---------------------------------------------------------------------------
|
|
2662
|
-
// Unified ordinal hyperoperation engine —
|
|
2738
|
+
// Unified ordinal hyperoperation engine — README rules 1-4:
|
|
2663
2739
|
// rule 1: x{0}y = x*y
|
|
2664
2740
|
// rule 2: x{α}1 = x; x{α}y = (x{α-1}) iterated (y-1) times from x
|
|
2665
2741
|
// rule 3: x{λ}y = x{λ[y]}y (fundamental sequence at y)
|
|
2666
2742
|
// rule 4: operations compose right-to-left
|
|
2667
|
-
//
|
|
2668
|
-
//
|
|
2669
|
-
//
|
|
2670
|
-
//
|
|
2671
|
-
//
|
|
2672
|
-
// whose top ordinal row level is γ:
|
|
2673
|
-
// β > γ → push a new [k|β] row ; β = γ → top count += k ; β < γ → no change
|
|
2674
|
-
// (e.g. 10{ω}10{ω+2}10 = 10{ω+2}10). Counts are always capped at MSI.
|
|
2743
|
+
// y > MSI: x{α}y ≈ 10{α}y — y plus one row [1|α] (the count diagonalizes to
|
|
2744
|
+
// a single α-level marker, the supremum of count-limited iterations).
|
|
2745
|
+
// Swallowing: applying level β on top of row level γ — β > γ pushes [k|β],
|
|
2746
|
+
// β = γ adds to the top count, β < γ is swallowed (10{ω}10{ω+2}10 =
|
|
2747
|
+
// 10{ω+2}10). Counts are capped at MSI.
|
|
2675
2748
|
// ---------------------------------------------------------------------------
|
|
2676
2749
|
|
|
2677
2750
|
var COEFF_BOUND = 100; // cascade bound: larger coefficients supremum-collapse
|
|
@@ -2795,17 +2868,12 @@
|
|
|
2795
2868
|
|
|
2796
2869
|
// ---------------------------------------------------------------------------
|
|
2797
2870
|
// Compact "layer marker" values for levels at or above ω^ω (README L17).
|
|
2798
|
-
//
|
|
2799
|
-
//
|
|
2800
|
-
//
|
|
2801
|
-
//
|
|
2802
|
-
//
|
|
2803
|
-
//
|
|
2804
|
-
// 10{ω^ω·y}10 = L1 [[0],[y,0,1]]; 10{ω^(ω+y)}10 = L1 [[0],[1,y,1]];
|
|
2805
|
-
// 10{ω^(ω·y)}10 = L2 [[0],[y,1]]; 10{ω^(ω^y)}10 = L3 [[y]];
|
|
2806
|
-
// 10{ω^ω^…^ω(y ω's)}10 = L_y [[0],[1,1]].
|
|
2807
|
-
// A marker is always stored in STANDARD FORM (Q._standardizeLayerValue):
|
|
2808
|
-
// finite-level rows merge into r0 and the layer drops as far as it can.
|
|
2871
|
+
// layer L >= 1 with rows [count, a1..ap] (ord_i = ω^(p-1)·ap+…+a1) encodes
|
|
2872
|
+
// 10{ ω^ω^…((L-1) ω^'s)…^( Σ_i ω^(ord_i)·count_i + Σ_j ω^j·r_j ) }10
|
|
2873
|
+
// e.g. 10{ω^y}10 = L1 [[0],[1,y]]; 10{ω^ω}10 = L1 [[0],[1,0,1]];
|
|
2874
|
+
// 10{ω^ω·y}10 = L1 [[0],[y,0,1]]; 10{ω^(ω·y)}10 = L2 [[0],[y,1]];
|
|
2875
|
+
// 10{ω^(ω^y)}10 = L3 [[y]]; 10{ω^ω^…^ω(y ω's)}10 = L_y [[0],[1,1]].
|
|
2876
|
+
// Markers are stored in STANDARD FORM (Q._standardizeLayerValue).
|
|
2809
2877
|
// ---------------------------------------------------------------------------
|
|
2810
2878
|
Q._layerMarker = function (r0, layer, rows) {
|
|
2811
2879
|
var v = new MetaNum(0);
|
|
@@ -2817,21 +2885,15 @@
|
|
|
2817
2885
|
return Q._standardizeLayerValue(v);
|
|
2818
2886
|
};
|
|
2819
2887
|
|
|
2820
|
-
// Standard form of a layer >= 1 value (README L17)
|
|
2821
|
-
//
|
|
2822
|
-
// (a) merge:
|
|
2823
|
-
//
|
|
2824
|
-
//
|
|
2825
|
-
//
|
|
2826
|
-
//
|
|
2827
|
-
//
|
|
2828
|
-
//
|
|
2829
|
-
// layer2 [[5],[3,1]] → layer2 [[5,3]] → layer1 [[10],[1,5,3]]
|
|
2830
|
-
// = 10{ω^(ω*3+5)}10;
|
|
2831
|
-
// layer3 [[3]] → layer2 [[0,0,0,1]] → layer1 [[10],[1,0,0,0,1]]
|
|
2832
|
-
// = 10{ω^ω^3}10.
|
|
2833
|
-
// Each de-layer step strictly lowers `layer`, so the loop terminates; the
|
|
2834
|
-
// innermost base is written as 10 (the 10{…}10 diagonal marker).
|
|
2888
|
+
// Standard form of a layer >= 1 value (README L17) — two ordinal-preserving
|
|
2889
|
+
// rewrites, applied until neither fires:
|
|
2890
|
+
// (a) merge: a row [count, k] with finite k < maxCols folds into r0[k]
|
|
2891
|
+
// (cube(10,3): [[10],[1,3],[1,0,1]] → [[10,0,0,1],[1,0,1]]).
|
|
2892
|
+
// (b) de-layer: a bracket that is a finite ω-polynomial β (no row above ω)
|
|
2893
|
+
// equals the layer-(L-1) value with the single row [1|β] (layer2
|
|
2894
|
+
// [[5],[3,1]] → layer1 [[10],[1,5,3]] = 10{ω^(ω*3+5)}10).
|
|
2895
|
+
// Each de-layer lowers `layer`, so the loop terminates; the innermost base
|
|
2896
|
+
// is written as 10.
|
|
2835
2897
|
function mergeFiniteRowsIntoR0(arr) {
|
|
2836
2898
|
var r0 = arr[0];
|
|
2837
2899
|
var keep = [];
|
|
@@ -2865,6 +2927,7 @@
|
|
|
2865
2927
|
return v;
|
|
2866
2928
|
};
|
|
2867
2929
|
|
|
2930
|
+
|
|
2868
2931
|
Q._standardizeLayerValue = function (v) {
|
|
2869
2932
|
if (!v || v.layer < 1) return v.normalize();
|
|
2870
2933
|
var L = v.layer;
|
|
@@ -2911,6 +2974,8 @@
|
|
|
2911
2974
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
2912
2975
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
2913
2976
|
if (cf.length === 0) return x.mul(y); // rule 1: x{0}y = x*y
|
|
2977
|
+
// B2-a: base-2 infinite-level collapse (see _hyperopFromOrdinal).
|
|
2978
|
+
if (x.eq(2) && y.isint() && y.gte(2) && coeffsHaveOmegaPart(cf)) return new MetaNum(4);
|
|
2914
2979
|
|
|
2915
2980
|
if (!coeffsHaveOmegaPart(cf)) {
|
|
2916
2981
|
// finite level: arrow() handles both small and huge operands
|
|
@@ -2963,14 +3028,10 @@
|
|
|
2963
3028
|
return V;
|
|
2964
3029
|
};
|
|
2965
3030
|
|
|
2966
|
-
// Helper: generic hyperoperation from ordinal level
|
|
2967
|
-
//
|
|
2968
|
-
//
|
|
2969
|
-
//
|
|
2970
|
-
// ordinals below α with coefficients < y fits into maxRows): legacy
|
|
2971
|
-
// enumeration representation (one row per ordinal below α, count = y-2)
|
|
2972
|
-
// - everything else (any operand beyond MSI, x = 2, or enumeration too large):
|
|
2973
|
-
// unified ordinal engine (README rules 1-4)
|
|
3031
|
+
// Helper: generic hyperoperation from ordinal level. coeffs are the CNF
|
|
3032
|
+
// coefficients [c0..ck] (ordinal = ω^k*ck+…+ω*c1+c0). Two paths: small
|
|
3033
|
+
// finite operands in [3, MSI] use the legacy enumeration (one row per ordinal
|
|
3034
|
+
// below α, count = y-2); everything else the unified engine (rules 1-4).
|
|
2974
3035
|
Q._hyperopFromOrdinalRaw = function (x, y, coeffs, skipFrac) {
|
|
2975
3036
|
x = new MetaNum(x);
|
|
2976
3037
|
y = new MetaNum(y);
|
|
@@ -2982,12 +3043,14 @@
|
|
|
2982
3043
|
|
|
2983
3044
|
var cf0 = trimCoeffs((coeffs || []).slice());
|
|
2984
3045
|
if (cf0.length === 0) return x.mul(y); // rule 1: x{0}y = x*y
|
|
3046
|
+
// B2-a: for base 2 every infinite level collapses (rule 3 turns the
|
|
3047
|
+
// argument into 2; 2{...}2 = 2{2}2 = 4). Finite levels are excluded.
|
|
3048
|
+
if (x.eq(2) && y.isint() && y.gte(2) && coeffsHaveOmegaPart(cf0)) return new MetaNum(4);
|
|
2985
3049
|
// Fractional level coefficients come from a fundamental sequence taken at a
|
|
2986
|
-
// non-integer index. On the diagonal ω = x, so ω^
|
|
2987
|
-
// ω^(k-1)·(x·f) — resolve top-down until only the constant term can still
|
|
2988
|
-
// fractional, then
|
|
2989
|
-
//
|
|
2990
|
-
// 10{ω+3}2·5^0.1; continuous at f=0 since x{γ+1}2 = x{γ}x).
|
|
3050
|
+
// non-integer index. On the diagonal ω = x, so ω^k·(c+f) = ω^k·c +
|
|
3051
|
+
// ω^(k-1)·(x·f) — resolve top-down until only the constant term can still
|
|
3052
|
+
// be fractional, then raise it to a fractional argument one level up:
|
|
3053
|
+
// x{γ+f}x = x{γ+1}(2·(x/2)^f) (10{ω*2}2.1 = 10{ω+3}2·5^0.1).
|
|
2991
3054
|
if (coeffsHaveFraction(cf0)) {
|
|
2992
3055
|
var xnf = x.toNumber();
|
|
2993
3056
|
if (isFinite(xnf) && xnf >= 2) {
|
|
@@ -3029,13 +3092,12 @@
|
|
|
3029
3092
|
var bigLevel = (pred[1] || 0) >= 2;
|
|
3030
3093
|
for (var bi = 2; bi < pred.length; bi++) if ((pred[bi] || 0) > 0) bigLevel = true;
|
|
3031
3094
|
if (xOkS && bigLevel && ym <= 100000) {
|
|
3032
|
-
//
|
|
3033
|
-
//
|
|
3095
|
+
// Successor rule in the EXPANDED form (the generator the integer
|
|
3096
|
+
// arguments use): the α-1 row carries the m applications as the
|
|
3034
3097
|
// integer count ceil(y)-2 = m-1, and the fraction lives in the cascade
|
|
3035
|
-
// depth — the first
|
|
3036
|
-
//
|
|
3037
|
-
//
|
|
3038
|
-
// over lands in the base, i.e. in array[0][0].
|
|
3098
|
+
// depth — the first FS starts at the fractional value x^f
|
|
3099
|
+
// (x{α}(m+f) = x{α-1}^m(x^f), as 10{3}2.1 starts from 10^0.1). Any
|
|
3100
|
+
// leftover fraction lands in array[0][0].
|
|
3039
3101
|
return Q._expandedHyperop(x, new MetaNum(ym + 1), cf0,
|
|
3040
3102
|
Math.pow(xnfS, Number((yFracNum - ym).toPrecision(15))));
|
|
3041
3103
|
}
|
|
@@ -3054,14 +3116,11 @@
|
|
|
3054
3116
|
return Q._ordinalHyperop(x, y, cf0);
|
|
3055
3117
|
}
|
|
3056
3118
|
if (ym >= 1) {
|
|
3057
|
-
//
|
|
3058
|
-
//
|
|
3059
|
-
//
|
|
3060
|
-
//
|
|
3061
|
-
//
|
|
3062
|
-
// Nested (skipFrac: the successor rule is already iterating a fractional
|
|
3063
|
-
// start value) the index is floored — otherwise every application would
|
|
3064
|
-
// take another fractional fundamental sequence and recurse forever.
|
|
3119
|
+
// Limit level: rule 3 with the FULL (fractional) index — λ[y] can
|
|
3120
|
+
// carry fractional coefficients (10{ω*2}2.1 = 10{ω+2.1}10), resolved by
|
|
3121
|
+
// the fractional-level rule above, so the fraction is never dropped.
|
|
3122
|
+
// Nested (skipFrac) the index is floored, else every application would
|
|
3123
|
+
// take another fractional FS and recurse forever.
|
|
3065
3124
|
var fsIdx = skipFrac ? Math.floor(yFracNum) : yFracNum;
|
|
3066
3125
|
return Q._hyperopFromOrdinalRaw(x, x, fsCoeffs(cf0, fsIdx), skipFrac);
|
|
3067
3126
|
}
|
|
@@ -3098,29 +3157,16 @@
|
|
|
3098
3157
|
|
|
3099
3158
|
// ---------------------------------------------------------------------------
|
|
3100
3159
|
// Expanded (cascade) form of x{α}y for FINITE operands in [3, MSI] — README
|
|
3101
|
-
// rules 1-4
|
|
3102
|
-
//
|
|
3103
|
-
//
|
|
3104
|
-
//
|
|
3105
|
-
//
|
|
3106
|
-
//
|
|
3107
|
-
//
|
|
3108
|
-
//
|
|
3109
|
-
//
|
|
3110
|
-
// limit α (c0 = 0): rule 3 gives x{α}opd = x{α[opd]}x, so the operand turns
|
|
3111
|
-
// into the base x and every row carries x-2 — including for 100 < y ≤ MSI
|
|
3112
|
-
// (h20(10,1000) stays an expanded cascade, not a one-row marker).
|
|
3160
|
+
// rules 1-4 row by row. Rows are generated TOP-DOWN (a huge fundamental
|
|
3161
|
+
// sequence costs nothing; the budget keeps the LARGEST rows):
|
|
3162
|
+
// successor α = β+m: x{α}y = x{β+m-1}^(y-2)(x{β+m-1}x) — only the top row
|
|
3163
|
+
// follows y, every row below carries x-2 (h13(10,20) → [8,0,1],[8,1,1],[18,2,1]).
|
|
3164
|
+
// limit α: rule 3 turns the operand into the base x, so every row carries x-2.
|
|
3165
|
+
// Only array[0][0] may be non-integer (same contract as arrow()); a fractional
|
|
3166
|
+
// argument enters as the outer count ceil(y)-2, the fractional start value x^f
|
|
3167
|
+
// of the first fundamental sequence (`fsOpd`), or a leftover constant term
|
|
3168
|
+
// carried into the base's finite level index (`.baseIdx`).
|
|
3113
3169
|
// ---------------------------------------------------------------------------
|
|
3114
|
-
// Only array[0][0] (the base's value slot) may ever be non-integer — the same
|
|
3115
|
-
// contract as arrow(): every row count and every row coefficient is an integer.
|
|
3116
|
-
// A fractional argument therefore enters in two integer-safe places:
|
|
3117
|
-
// - the outer count is `yn - 2` with yn = ceil(y) (an integer);
|
|
3118
|
-
// - the rest of the fraction sits in the CASCADE DEPTH: the first
|
|
3119
|
-
// fundamental sequence is taken at the fractional start value x^f
|
|
3120
|
-
// (x{α}(m+f) = x{α-1}^m(x^f)), and any fractional constant term left over
|
|
3121
|
-
// is carried into the base's finite level index (x{10.16}x), so it ends up
|
|
3122
|
-
// as the fractional array[0][0] exactly like arrow() does.
|
|
3123
|
-
// `fsOpd` is that fractional start value; `.baseIdx` returns the base index.
|
|
3124
3170
|
Q._cascadeRows = function (xn, cf, yn, budget, fsOpd) {
|
|
3125
3171
|
var rows = [];
|
|
3126
3172
|
if (!(budget >= 1)) return rows;
|
|
@@ -3695,25 +3741,27 @@
|
|
|
3695
3741
|
// ---------------------------------------------------------------------------
|
|
3696
3742
|
|
|
3697
3743
|
// ---------------------------------------------------------------------------
|
|
3698
|
-
// Hyperoperations from ω^ω up to ε₀ — README rules 1-4 with the unified
|
|
3699
|
-
//
|
|
3700
|
-
//
|
|
3701
|
-
//
|
|
3702
|
-
// as the compact layer marker of λ[y] (see Q._layerMarker).
|
|
3744
|
+
// Hyperoperations from ω^ω up to ε₀ — README rules 1-4 with the unified limit
|
|
3745
|
+
// rule n{λ}b = n{λ[b]}n (the final operand is the BASE n). Levels ≥ ω^ω have
|
|
3746
|
+
// no finite CNF row, so — unless λ[y] still fits a layer-0 row — the result
|
|
3747
|
+
// is the compact layer marker of λ[y] (Q._layerMarker).
|
|
3703
3748
|
// ---------------------------------------------------------------------------
|
|
3704
3749
|
|
|
3705
|
-
// iter (ω^ω): (ω^ω)[y] = ω^y → x{ω^ω}y = x{ω^y}x
|
|
3706
|
-
//
|
|
3707
|
-
//
|
|
3708
|
-
//
|
|
3709
|
-
// (= 10{ω^y}10), and for y > MSI the operand is unrepresentable → the
|
|
3710
|
-
// ω^ω marker row [1,0,1] (= 10{ω^ω}10).
|
|
3750
|
+
// iter (ω^ω): (ω^ω)[y] = ω^y → x{ω^ω}y = x{ω^y}x — the whole
|
|
3751
|
+
// fundamental-sequence cascade as a layer-0 multi-row array. For y >=
|
|
3752
|
+
// maxCols the ω^y row no longer fits → layer-1 marker [[r0],[1,y]]
|
|
3753
|
+
// (= 10{ω^y}10); for y > MSI → the ω^ω marker row [1,0,1].
|
|
3711
3754
|
P.iterate = P.iter = P.hww = function (y) {
|
|
3712
3755
|
var x = this.clone();
|
|
3713
3756
|
y = new MetaNum(y);
|
|
3714
3757
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
3715
3758
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
3716
3759
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
3760
|
+
// rule 3 collapses x{λ}y to x{λ[y]}x; for x=2 the argument becomes 2 and
|
|
3761
|
+
// every further FS/successor step keeps it there, so the cascade ends at
|
|
3762
|
+
// 2{...}2 = 2{2}2 = 4 for ANY limit/successor level λ and integer y >= 2
|
|
3763
|
+
// (issue #17 D07/B2-a). Finite levels are excluded (2{1}3 = 8).
|
|
3764
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
3717
3765
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
3718
3766
|
|
|
3719
3767
|
// iterate(x,y) = x{ω^ω}y. Rule 3 with the fundamental sequence
|
|
@@ -3824,18 +3872,17 @@
|
|
|
3824
3872
|
};
|
|
3825
3873
|
|
|
3826
3874
|
// itermult (ω^ω+1): successor level — x{ω^ω+1}y = x{ω^ω} applied y-1 times
|
|
3827
|
-
// to x (rule 2)
|
|
3828
|
-
//
|
|
3829
|
-
//
|
|
3830
|
-
//
|
|
3831
|
-
// lives in the constant term (ω^ω + n) — monotone in k and still below
|
|
3832
|
-
// cuboiter's ω^ω+ω^k.
|
|
3875
|
+
// to x (rule 2). k = 2 → iterate(x,x) exactly; 1 < k < 2 → x{ω^ω}(x^(k-1)).
|
|
3876
|
+
// k > 2 → layer-1 marker [[k-1],[1,0,1]] = 10{ω^ω+(k-1)}10: finitely many
|
|
3877
|
+
// ω^ω applications stay below ω^ω·2, so the count lives in the constant term
|
|
3878
|
+
// (monotone in k, still below cuboiter's ω^ω+ω^k).
|
|
3833
3879
|
P.itermult = P.itmu = P.hw01 = function (y) {
|
|
3834
3880
|
var x = this.clone();
|
|
3835
3881
|
y = new MetaNum(y);
|
|
3836
3882
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
3837
3883
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
3838
3884
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
3885
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
3839
3886
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
3840
3887
|
var yc = metaFiniteCount(y);
|
|
3841
3888
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -3901,6 +3948,7 @@
|
|
|
3901
3948
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
3902
3949
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
3903
3950
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
3951
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
3904
3952
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
3905
3953
|
var yc = metaFiniteCount(y);
|
|
3906
3954
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -3962,6 +4010,7 @@
|
|
|
3962
4010
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
3963
4011
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
3964
4012
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4013
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
3965
4014
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
3966
4015
|
var yc = metaFiniteCount(y);
|
|
3967
4016
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4016,6 +4065,7 @@
|
|
|
4016
4065
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4017
4066
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4018
4067
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4068
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
4019
4069
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4020
4070
|
var yc = metaFiniteCount(y);
|
|
4021
4071
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4070,6 +4120,7 @@
|
|
|
4070
4120
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4071
4121
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4072
4122
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4123
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
4073
4124
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4074
4125
|
var yc = metaFiniteCount(y);
|
|
4075
4126
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4131,6 +4182,7 @@
|
|
|
4131
4182
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4132
4183
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4133
4184
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4185
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
4134
4186
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4135
4187
|
var yc = metaFiniteCount(y);
|
|
4136
4188
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4204,6 +4256,7 @@
|
|
|
4204
4256
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4205
4257
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4206
4258
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4259
|
+
if (x.eq(2) && y.isint() && y.gte(2)) return new MetaNum(4);
|
|
4207
4260
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4208
4261
|
// ε₀[2] = ω^ω, so epsilonate(x,2) = x{ω^ω}x = iterate(x,x) exactly (the
|
|
4209
4262
|
// same value itermult(x,2) produces — x{ε₀}2 = x{ω^ω+1}2).
|
|
@@ -4568,9 +4621,22 @@
|
|
|
4568
4621
|
}
|
|
4569
4622
|
// Always include layer symbol for layers 1-10
|
|
4570
4623
|
if (this.layer >= 1 && finOps === "" && baseStr !== "") {
|
|
4571
|
-
|
|
4624
|
+
// "^count" tokens are space-separated (see the layer-0 path)
|
|
4625
|
+
var hasPowS = false;
|
|
4626
|
+
for (var ps = 0; ps < ordTokens.length; ps++) {
|
|
4627
|
+
if (ordTokens[ps].indexOf("^") !== -1) { hasPowS = true; break; }
|
|
4628
|
+
}
|
|
4629
|
+
return sym + ordTokens.join(hasPowS ? " " : "") + (hasPowS ? " " : "") + baseStr;
|
|
4630
|
+
}
|
|
4631
|
+
// "^count" tokens are space-separated so the parser can split the
|
|
4632
|
+
// count from the trailing base digits (see the layer-0 path).
|
|
4633
|
+
var hasPowL = false;
|
|
4634
|
+
for (var pl = 0; pl < ordTokens.length; pl++) {
|
|
4635
|
+
if (ordTokens[pl].indexOf("^") !== -1) { hasPowL = true; break; }
|
|
4572
4636
|
}
|
|
4573
|
-
|
|
4637
|
+
var bodyL = ordTokens.join(hasPowL ? " " : "");
|
|
4638
|
+
if (hasPowL && (finOps || baseStr)) bodyL += " ";
|
|
4639
|
+
return sym + bodyL + (finOps ? finOps : "") + baseStr;
|
|
4574
4640
|
}
|
|
4575
4641
|
}
|
|
4576
4642
|
|
|
@@ -4728,7 +4794,16 @@
|
|
|
4728
4794
|
var hasAa = finOps && finOps.indexOf("Aa") !== -1;
|
|
4729
4795
|
var prefix = useExclaim ? "!" : "";
|
|
4730
4796
|
var baseNum = (useExclaim || hasAa) ? "" : decimalPlaces(this.array[0][0], 6);
|
|
4731
|
-
|
|
4797
|
+
// Tokens carrying an explicit "^count" are space-separated (same rule
|
|
4798
|
+
// as formatFiniteOps) so the parser can tell the count from the
|
|
4799
|
+
// trailing base digits: "Ijj^8 Iji^8 … Iib^8 10", not "Iib^810".
|
|
4800
|
+
var hasPow = false;
|
|
4801
|
+
for (var pi = 0; pi < ordTokens.length; pi++) {
|
|
4802
|
+
if (ordTokens[pi].indexOf("^") !== -1) { hasPow = true; break; }
|
|
4803
|
+
}
|
|
4804
|
+
var body = ordTokens.join(hasPow ? " " : "");
|
|
4805
|
+
if (hasPow && (finOps || baseNum)) body += " ";
|
|
4806
|
+
return prefix + body + (finOps ? finOps : "") + baseNum;
|
|
4732
4807
|
}
|
|
4733
4808
|
}
|
|
4734
4809
|
|
|
@@ -4763,7 +4838,7 @@
|
|
|
4763
4838
|
if (this.isNaN()) return "NaN";
|
|
4764
4839
|
if (this.isInfinite()) return "Infinity";
|
|
4765
4840
|
if (isSimple(this)) {
|
|
4766
|
-
var v = decimalPlaces(this
|
|
4841
|
+
var v = decimalPlaces(magnitudeOf(this), places); // sub-unit r0 = reciprocal
|
|
4767
4842
|
if (Number.isFinite(v)) return v.toString();
|
|
4768
4843
|
}
|
|
4769
4844
|
return this.toString();
|
|
@@ -4779,7 +4854,14 @@
|
|
|
4779
4854
|
if (typeof require == 'function') {
|
|
4780
4855
|
try { formatter = require('./format-metanum.js').format; } catch (e) { formatter = null; }
|
|
4781
4856
|
}
|
|
4782
|
-
|
|
4857
|
+
if (!formatter && typeof format === 'function') formatter = format; // browser bundle
|
|
4858
|
+
if (!formatter) {
|
|
4859
|
+
// No formatter available (bare browser include): fall back to the plain
|
|
4860
|
+
// decimal expansion rather than throwing ReferenceError.
|
|
4861
|
+
var plain = this.toNumber();
|
|
4862
|
+
return isFinite(plain) ? String(plain) : this.toString();
|
|
4863
|
+
}
|
|
4864
|
+
return formatter(this, precision, small);
|
|
4783
4865
|
};
|
|
4784
4866
|
|
|
4785
4867
|
P.toExponential = function (places) {
|
|
@@ -4811,7 +4893,7 @@
|
|
|
4811
4893
|
if (this.isNaN()) return "NaN";
|
|
4812
4894
|
if (this.isInfinite()) return "Infinity";
|
|
4813
4895
|
if (isSimple(this)) {
|
|
4814
|
-
var v = this
|
|
4896
|
+
var v = magnitudeOf(this); // sub-unit r0 holds the reciprocal
|
|
4815
4897
|
if (v < 10) return String(v);
|
|
4816
4898
|
return "E" + Math.log10(v).toFixed(6);
|
|
4817
4899
|
}
|
|
@@ -5015,6 +5097,10 @@
|
|
|
5015
5097
|
x.layer = 0;
|
|
5016
5098
|
|
|
5017
5099
|
var s = input.trim();
|
|
5100
|
+
// Displays group digits with commas ("29,657", "1,000,000") — strip them
|
|
5101
|
+
// so every format() output parses back (digit-comma-digit only, so BEAF
|
|
5102
|
+
// strings like "{10, 16}" and JSON payloads are untouched).
|
|
5103
|
+
s = s.replace(/(\d),(?=\d)/g, "$1");
|
|
5018
5104
|
if (s === "" || s === "0") {
|
|
5019
5105
|
return x;
|
|
5020
5106
|
}
|
|
@@ -5436,11 +5522,10 @@
|
|
|
5436
5522
|
|
|
5437
5523
|
// Parse spaced letter-chain notation (round-trip of toString output):
|
|
5438
5524
|
// "M^7 L^8 K^8 ... E^8 10000000000" finite levels with ^counts
|
|
5439
|
-
// "GF^2 E^3 123" letters + ^counts (last
|
|
5525
|
+
// "GF^2 E^3 123" letters + ^counts (last gets count)
|
|
5440
5526
|
// "3Aa25 100" high finite level (> 22) with base
|
|
5441
|
-
// "AaAa E^8 100"
|
|
5442
|
-
//
|
|
5443
|
-
// Must come before aaMatch so "3Aa25 100" keeps its trailing base value.
|
|
5527
|
+
// "AaAa E^8 100" / "F^9 EE100" compact tokens + spaced chain
|
|
5528
|
+
// Must come before aaMatch so "3Aa25 100" keeps its trailing base.
|
|
5444
5529
|
var chainMatch = rem.match(/^((?:[A-Z][a-z]+)*)((?:(?:[A-Z]+\^\d+|\d+Aa\d+)\s+)+)([A-Z]*)(\d+(?:\.\d+)?)\s*$/);
|
|
5445
5530
|
if (chainMatch) {
|
|
5446
5531
|
var chainOk = true;
|
|
@@ -5543,19 +5628,34 @@
|
|
|
5543
5628
|
}
|
|
5544
5629
|
}
|
|
5545
5630
|
|
|
5546
|
-
|
|
5631
|
+
// #19 — the Aa diagonal (README: Aaα = 10{α}10, so the bare Aaα and the
|
|
5632
|
+
// binary 2Aaα coincide; the general binary form is αAaβ = 10{β+1}α).
|
|
5633
|
+
// The old path stored the raw coefficient row [10,0,…,0,count] — that is
|
|
5634
|
+
// 10{β+1}(count+1), one application too many: 2Aa3 came out as
|
|
5635
|
+
// [[10^10,8,8,1]] (= 10{4}3) instead of 10{3}10 = [[10^10,8,8]].
|
|
5636
|
+
var aaMatch = rem.match(/^(\d+)Aa(\d+(?:\.\d+)?)$/i);
|
|
5547
5637
|
if (aaMatch) {
|
|
5548
|
-
var aaCount =
|
|
5638
|
+
var aaCount = Number(aaMatch[1]);
|
|
5549
5639
|
var aaN = Number(aaMatch[2]);
|
|
5550
|
-
if (!isNaN(aaN) && isFinite(aaN) && aaN >=
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5640
|
+
if (!isNaN(aaN) && isFinite(aaN) && aaN >= 0 && isFinite(aaCount) && aaCount >= 1) {
|
|
5641
|
+
var aaVal = MetaNum.TEN.clone().arrow(aaN + 1)(aaCount); // 10{β+1}α
|
|
5642
|
+
if (negateIt) aaVal.sign = -1;
|
|
5643
|
+
return aaVal;
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5646
|
+
|
|
5647
|
+
// Bare Aa<n> (no mantissa): the diagonal itself — Aaα = 10{α}10 for
|
|
5648
|
+
// every real α (README "Defining Aa"). A level below 1 has no engine
|
|
5649
|
+
// arrow, so apply rule (iii): 10{α}10 = 10{1}(2·5^α).
|
|
5650
|
+
var aaBareMatch = rem.match(/^Aa(\d+(?:\.\d+)?)$/i);
|
|
5651
|
+
if (aaBareMatch) {
|
|
5652
|
+
var abN = Number(aaBareMatch[1]);
|
|
5653
|
+
if (isFinite(abN) && abN >= 0) {
|
|
5654
|
+
var abVal;
|
|
5655
|
+
if (abN < 1) abVal = MetaNum.TEN.clone().arrow(1)(2 * Math.pow(5, abN));
|
|
5656
|
+
else abVal = MetaNum.TEN.clone().arrow(abN)(MetaNum.TEN.clone());
|
|
5657
|
+
if (negateIt) abVal.sign = -1;
|
|
5658
|
+
return abVal;
|
|
5559
5659
|
}
|
|
5560
5660
|
}
|
|
5561
5661
|
|
|
@@ -5571,13 +5671,70 @@
|
|
|
5571
5671
|
return innerS.normalize();
|
|
5572
5672
|
}
|
|
5573
5673
|
|
|
5574
|
-
//
|
|
5575
|
-
//
|
|
5576
|
-
//
|
|
5577
|
-
//
|
|
5578
|
-
//
|
|
5579
|
-
|
|
5580
|
-
|
|
5674
|
+
// !Aaα with a real (non-integer) α — decision 1B: !Aaα ≡ A(a×⌊α⌋)(α),
|
|
5675
|
+
// the letter token with ⌊α⌋ lowercase a's applied at argument α. Keeps
|
|
5676
|
+
// the integer anchors and extends them continuously inside each unit
|
|
5677
|
+
// interval (!Aa1.5 = Aa1.5, !Aa2.5 = Aaa2.5). Must run before
|
|
5678
|
+
// diagBinMatch: "!Aa1.5" has no mantissa in front.
|
|
5679
|
+
var bangAaMatch = rem.match(/^!Aa(\d+\.\d+)$/);
|
|
5680
|
+
if (bangAaMatch) {
|
|
5681
|
+
var baA = Number(bangAaMatch[1]);
|
|
5682
|
+
if (isFinite(baA) && baA > 0) {
|
|
5683
|
+
var baN = Math.max(1, Math.floor(baA));
|
|
5684
|
+
var baTok = "A" + new Array(baN + 1).join("a");
|
|
5685
|
+
var baVal = Q.fromString(baTok + String(baA));
|
|
5686
|
+
if (negateIt) baVal.sign = -1;
|
|
5687
|
+
return baVal;
|
|
5688
|
+
}
|
|
5689
|
+
}
|
|
5690
|
+
|
|
5691
|
+
// !αAaβ binary diagonal (notation-semantics §2, decision 1B):
|
|
5692
|
+
// !αAaβ = !Aa(β + log₅(α/2))
|
|
5693
|
+
// Built as the de-layered instance A(a×⌊x⌋)(x) when the row fits maxCols,
|
|
5694
|
+
// else the layer-1 marker. Must run before diagBinMatch so the α≠2 case
|
|
5695
|
+
// stops using the lossy compact row. α = 1.000 (legacy "no mantissa") is
|
|
5696
|
+
// left to the 1.0+-strip below; α = 1 without decimals follows the
|
|
5697
|
+
// formula.
|
|
5698
|
+
var aaBinMatch = rem.match(/^!(\d+(?:\.\d+)?)Aa(\d+(?:\.\d+)?(?:[Ee]\d+)?)$/);
|
|
5699
|
+
if (aaBinMatch) {
|
|
5700
|
+
var aaMant = Number(aaBinMatch[1]);
|
|
5701
|
+
var aaBeta = Number(aaBinMatch[2]);
|
|
5702
|
+
var aaSkipLegacy = (aaMant === 1 && aaBinMatch[1].indexOf('.') >= 0);
|
|
5703
|
+
if (!aaSkipLegacy && isFinite(aaMant) && aaMant > 0 &&
|
|
5704
|
+
isFinite(aaBeta) && aaBeta >= 0) {
|
|
5705
|
+
var aaX = aaBeta + Math.log(aaMant / 2) / Math.log(5);
|
|
5706
|
+
if (aaX >= 1 && aaX === Math.floor(aaX)) {
|
|
5707
|
+
// #19: an INTEGER !Aa<n> is the full rule-3 cascade of 10{ω^n}10
|
|
5708
|
+
// (layer 0) — "!" adds one ω^ to the level. Past the row budget
|
|
5709
|
+
// bangAaInteger goes one layer up with the de-!-ed compact.
|
|
5710
|
+
var anVal = bangAaInteger(aaX, 0);
|
|
5711
|
+
anVal.sign = 1;
|
|
5712
|
+
if (negateIt) anVal.sign = -1;
|
|
5713
|
+
return anVal;
|
|
5714
|
+
}
|
|
5715
|
+
var aaK = Math.max(1, Math.floor(aaX));
|
|
5716
|
+
var aaVal = new MetaNum();
|
|
5717
|
+
if (aaX >= 1 && aaK + 2 <= MetaNum.maxCols) {
|
|
5718
|
+
var aaRow = [1];
|
|
5719
|
+
for (var ai = 0; ai < aaK; ai++) aaRow.push(0);
|
|
5720
|
+
aaRow.push(1);
|
|
5721
|
+
aaVal.array = [[aaX], aaRow];
|
|
5722
|
+
aaVal.layer = 0;
|
|
5723
|
+
} else {
|
|
5724
|
+
aaVal.array = [[aaX], [1, 0, 1]];
|
|
5725
|
+
aaVal.layer = (aaX >= 1) ? 1 : 0;
|
|
5726
|
+
}
|
|
5727
|
+
aaVal.sign = 1;
|
|
5728
|
+
aaVal.normalize();
|
|
5729
|
+
if (negateIt) aaVal.sign = -1;
|
|
5730
|
+
return aaVal;
|
|
5731
|
+
}
|
|
5732
|
+
}
|
|
5733
|
+
|
|
5734
|
+
// Canonical diagonal-letter output "mantissa LETTER β" (LETTER any
|
|
5735
|
+
// multi-letter token ending in 'a'), with the dlsdl diagonal mantissa
|
|
5736
|
+
// α ∈ [2,10): the exact anchor α=2.000 gives the plain letter application
|
|
5737
|
+
// LETTER(β); a fractional α gives the compact smooth row [α, β] (r0=[1]).
|
|
5581
5738
|
var diagBinMatch = rem.match(/^([!@#\$%&~<>?]?)(\d+\.\d+)([A-Z][a-z]+)(\d[\d,]*)\s*$/);
|
|
5582
5739
|
if (diagBinMatch) {
|
|
5583
5740
|
var dbSym = diagBinMatch[1];
|
|
@@ -5609,8 +5766,27 @@
|
|
|
5609
5766
|
// the fractional-argument machinery and is not accepted here.
|
|
5610
5767
|
rem = rem.replace(/^([!@#\$%&~<>?]?)1\.0+(?=[A-Z])/, '$1');
|
|
5611
5768
|
|
|
5769
|
+
// #19 — the symbol layers of the Aa diagonal: every symbol adds one ω^
|
|
5770
|
+
// (!Aa<n> = 10{ω^n}10 layer 0, @Aa<n> layer 1, #Aa<n> layer 2, …), so the
|
|
5771
|
+
// same rule-3 cascade is stored and `layer` carries the extra ω^'s.
|
|
5772
|
+
// Mantissa 2 (or 2.000) is the diagonal anchor (2·5^0 = 2); other
|
|
5773
|
+
// mantissas keep the smooth decision-1B path below.
|
|
5774
|
+
var aaSymMatch = rem.match(/^([!@#\$%&~<>?])(2(?:\.0+)?)?Aa(\d+)$/);
|
|
5775
|
+
if (aaSymMatch) {
|
|
5776
|
+
var asIdx = "!@#$%&~<>?".indexOf(aaSymMatch[1]);
|
|
5777
|
+
var asN = Number(aaSymMatch[3]);
|
|
5778
|
+
if (asIdx >= 0 && isFinite(asN) && asN >= 1 && asN === Math.floor(asN)) {
|
|
5779
|
+
var asVal = bangAaInteger(asN, asIdx); // "!" → layer 0, "@" → 1, …
|
|
5780
|
+
asVal.sign = 1;
|
|
5781
|
+
if (negateIt) asVal.sign = -1;
|
|
5782
|
+
return asVal;
|
|
5783
|
+
}
|
|
5784
|
+
}
|
|
5785
|
+
|
|
5612
5786
|
// Handle layer symbol prefix + letter pattern + optional finOps + number (e.g., !Abcd1234, !AaE16, @Bcde500)
|
|
5613
|
-
|
|
5787
|
+
// Tokens may carry "^count" application counts and be space-separated —
|
|
5788
|
+
// the toString spelling of multi-row ordinal cascades ("!Ijj^8 … 10").
|
|
5789
|
+
var symPrefixMatch = rem.match(/^([!@#\$%&~<>?])((?:[A-Z][a-z]+(?:\^\d+)?\s*)+)([A-Z]*)((?:\d+(?:\.\d+)?(?:[Ee]\d+)?))\s*$/);
|
|
5614
5790
|
if (symPrefixMatch) {
|
|
5615
5791
|
var SYMBOL_LAYERS_P = {'!': 1, '@': 2, '#': 3, '$': 4, '%': 5, '&': 6, '~': 7, '<': 8, '>': 9, '?': 10};
|
|
5616
5792
|
x.layer = SYMBOL_LAYERS_P[symPrefixMatch[1]] || 1;
|
|
@@ -5618,30 +5794,32 @@
|
|
|
5618
5794
|
rem = symPrefixMatch[2] + (symPrefixMatch[3] || '') + symPrefixMatch[4];
|
|
5619
5795
|
}
|
|
5620
5796
|
|
|
5621
|
-
// Ordinal-prefix chain with a full number argument —
|
|
5622
|
-
//
|
|
5623
|
-
// (
|
|
5624
|
-
//
|
|
5625
|
-
//
|
|
5626
|
-
|
|
5797
|
+
// Ordinal-prefix chain with a full number argument — plain integer
|
|
5798
|
+
// ("AaG5"), decimal ("AaG5.5") or sci-notation ("AaGF7.626E12"); the old
|
|
5799
|
+
// (\d+) regex ate only "7" and dropped ".626E12". Each token may carry
|
|
5800
|
+
// an explicit count ("Ijj^8", the toString spelling of a row whose count
|
|
5801
|
+
// reached the ^n form) and tokens may be space-separated (keeping "^8"
|
|
5802
|
+
// apart from the trailing base digits).
|
|
5803
|
+
var oaMatch = rem.match(/^((?:[A-Z][a-z]+(?:\^\d+)?\s*)+)([A-Z]*)((?:\d+(?:\.\d+)?(?:[Ee]\d+)?))$/);
|
|
5627
5804
|
if (oaMatch) {
|
|
5628
5805
|
var oaFullPrefix = oaMatch[1];
|
|
5629
5806
|
var oaFinOps = oaMatch[2];
|
|
5630
5807
|
var oaN = Number(oaMatch[3]);
|
|
5631
5808
|
if (!isNaN(oaN) && isFinite(oaN) && oaN >= 0) {
|
|
5632
5809
|
var oaTokens = [];
|
|
5633
|
-
var oaTokenRegex = /[A-Z][a-z]
|
|
5810
|
+
var oaTokenRegex = /[A-Z][a-z]+(?:\^(\d+))?/g;
|
|
5634
5811
|
var oaTm;
|
|
5635
5812
|
while ((oaTm = oaTokenRegex.exec(oaFullPrefix)) !== null) {
|
|
5636
|
-
oaTokens.push(oaTm[0]);
|
|
5813
|
+
oaTokens.push({ token: oaTm[0].split("^")[0], rep: oaTm[1] ? Number(oaTm[1]) : 1 });
|
|
5637
5814
|
}
|
|
5638
5815
|
|
|
5639
5816
|
var oaGroups = [];
|
|
5640
5817
|
for (var ti = 0; ti < oaTokens.length; ti++) {
|
|
5641
|
-
|
|
5642
|
-
|
|
5818
|
+
var ot = oaTokens[ti];
|
|
5819
|
+
if (oaGroups.length > 0 && oaGroups[oaGroups.length - 1].token === ot.token) {
|
|
5820
|
+
oaGroups[oaGroups.length - 1].count += ot.rep;
|
|
5643
5821
|
} else {
|
|
5644
|
-
oaGroups.push({token:
|
|
5822
|
+
oaGroups.push({token: ot.token, count: ot.rep});
|
|
5645
5823
|
}
|
|
5646
5824
|
}
|
|
5647
5825
|
|
|
@@ -5772,6 +5950,39 @@
|
|
|
5772
5950
|
if (negateIt) x.sign = -1;
|
|
5773
5951
|
return x.normalize();
|
|
5774
5952
|
}
|
|
5953
|
+
// The remainder may be a sci-notation number beyond the double range
|
|
5954
|
+
// ("1.537E924") — Number() overflows to Infinity and the letter counts
|
|
5955
|
+
// above were skipped, so the display "EE1.537E924" (the format of
|
|
5956
|
+
// [[924.19,3]]) used to lose BOTH E's on parse. Convert to the log
|
|
5957
|
+
// form and apply the counts on top: E^k(10^L) = [L, k+1].
|
|
5958
|
+
var sciRest = rem.match(/^([\d.]+)[Ee](-?\d+)\s*$/);
|
|
5959
|
+
if (sciRest) {
|
|
5960
|
+
var sciMantR = Number(sciRest[1]);
|
|
5961
|
+
var sciExpR = Number(sciRest[2]);
|
|
5962
|
+
if (!isNaN(sciMantR) && isFinite(sciMantR) && isFinite(sciExpR) && sciMantR > 0) {
|
|
5963
|
+
var logValR = Math.log10(sciMantR) + sciExpR;
|
|
5964
|
+
var countsR = {};
|
|
5965
|
+
var maxIdxR = 0;
|
|
5966
|
+
for (var ri = 0; ri < prefix.length; ri++) {
|
|
5967
|
+
var letterPosR = prefix.charCodeAt(ri) - 64;
|
|
5968
|
+
if (letterPosR >= 5) {
|
|
5969
|
+
var idxR = letterPosR - 4;
|
|
5970
|
+
countsR[idxR] = (countsR[idxR] || 0) + 1;
|
|
5971
|
+
maxIdxR = Math.max(maxIdxR, idxR);
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
if (maxIdxR === 1) {
|
|
5975
|
+
x.array[0] = [logValR, (countsR[1] || 0) + 1];
|
|
5976
|
+
} else {
|
|
5977
|
+
x.array[0] = [logValR, 1];
|
|
5978
|
+
for (var idx3 = 1; idx3 <= maxIdxR; idx3++) {
|
|
5979
|
+
x.array[0][idx3] = (x.array[0][idx3] || 0) + (countsR[idx3] || 0);
|
|
5980
|
+
}
|
|
5981
|
+
}
|
|
5982
|
+
if (negateIt) x.sign = -1;
|
|
5983
|
+
return x.normalize();
|
|
5984
|
+
}
|
|
5985
|
+
}
|
|
5775
5986
|
}
|
|
5776
5987
|
|
|
5777
5988
|
// Parse scientific notation with extreme exponents (e.g., 1E-1000000, 1E1000000)
|
|
@@ -5811,15 +6022,11 @@
|
|
|
5811
6022
|
|
|
5812
6023
|
|
|
5813
6024
|
// ==================== BEAF Ordinal Helpers ====================
|
|
5814
|
-
//
|
|
5815
|
-
//
|
|
5816
|
-
//
|
|
5817
|
-
//
|
|
5818
|
-
//
|
|
5819
|
-
// coeffs[3] = f-1 (ω^3 coefficient)
|
|
5820
|
-
// An argument whose value exceeds MSI (or carries ordinal structure) cannot
|
|
5821
|
-
// serve as an exact coefficient: it is reported in hugeArgs and the caller
|
|
5822
|
-
// supremum-collapses it (ω^i*HUGE ≈ ω^(i+1)).
|
|
6025
|
+
// BEAF(a,b,c,d,e,f,...) = a{...+ω^3*(f-1)+ω^2*(e-1)+ω*(d-1)+c}b, so
|
|
6026
|
+
// coeffs = [c, d-1, e-1, f-1, …] (the constant term is not decremented).
|
|
6027
|
+
// An argument beyond MSI (or with ordinal structure) cannot be an exact
|
|
6028
|
+
// coefficient: it is reported in hugeArgs and supremum-collapsed
|
|
6029
|
+
// (ω^i*HUGE ≈ ω^(i+1)).
|
|
5823
6030
|
Q._buildOrdinalCoeffs = function(args) {
|
|
5824
6031
|
var coeffs = [];
|
|
5825
6032
|
var hugeArgs = [];
|
|
@@ -5840,13 +6047,11 @@
|
|
|
5840
6047
|
return { coeffs: coeffs, hugeArgs: hugeArgs };
|
|
5841
6048
|
};
|
|
5842
6049
|
|
|
5843
|
-
// Ordinal BEAF computation for 4+ arguments:
|
|
5844
|
-
//
|
|
5845
|
-
//
|
|
5846
|
-
//
|
|
5847
|
-
//
|
|
5848
|
-
// 4{ω*X+3}2 = 4{ω^2}X → X plus one ω^2 row.
|
|
5849
|
-
// The result anchors at the largest operand (the huge argument's value).
|
|
6050
|
+
// Ordinal BEAF computation for 4+ arguments: BEAF(a,b,c,d,...) =
|
|
6051
|
+
// a{...+ω*d+c}b via the unified ordinal engine. Huge coefficients (> MSI /
|
|
6052
|
+
// ordinal args) supremum-collapse (ω^i*HUGE ≈ ω^(i+1), lower coefficients
|
|
6053
|
+
// swallowed): 4{ω*5+X}2 = 4{ω*6}X, 4{ω*X+3}2 = 4{ω^2}X. The result anchors
|
|
6054
|
+
// at the largest operand.
|
|
5850
6055
|
Q._beafOrdinal = function(a, b, coeffs, hugeArgs) {
|
|
5851
6056
|
a = new MetaNum(a);
|
|
5852
6057
|
b = new MetaNum(b);
|
|
@@ -5874,23 +6079,23 @@
|
|
|
5874
6079
|
};
|
|
5875
6080
|
|
|
5876
6081
|
// ==================== Hardy Hierarchy ====================
|
|
5877
|
-
// H_α(n)
|
|
5878
|
-
//
|
|
5879
|
-
//
|
|
5880
|
-
// H_
|
|
5881
|
-
//
|
|
5882
|
-
//
|
|
5883
|
-
// H_{β+c}(n) = H_β(n+c) (c successor steps)
|
|
5884
|
-
// H_{β+ω·c}(n) = H_β(n·2^c) (c ω-level limit steps)
|
|
5885
|
-
// For ω^j·c segments with c beyond the exact-iteration bound (j ≥ 2) the
|
|
5886
|
-
// value collapses into the hyperoperation engine, mirroring the classic
|
|
5887
|
-
// identity F_j = H^{ω^j} (F_2(n)=n·2^n, F_3(n)≈2↑↑n, …):
|
|
5888
|
-
// H_{β+ω^j·c}(n) ≈ H_β(2{c}^j) i.e. 2.arrow(j)(c)
|
|
6082
|
+
// H_α(n) by transfinite recursion: H_0(n)=n, H_{α+1}(n)=H_α(n+1),
|
|
6083
|
+
// H_λ(n)=H_{λ[n]}(n), where λ[n] hits the lowest limit term
|
|
6084
|
+
// (…+ω^j·c_j)[n] = …+ω^j·(c_j−1)+ω^{j−1}·n. Closed forms keep it finite:
|
|
6085
|
+
// H_{β+c}(n) = H_β(n+c); H_{β+ω·c}(n) = H_β(n·2^c).
|
|
6086
|
+
// Beyond the exact-iteration bound (j ≥ 2) an ω^j·c segment collapses into
|
|
6087
|
+
// the hyperoperation engine (F_j = H^{ω^j}): H_{β+ω^j·c}(n) ≈ H_β(2{c}^j).
|
|
5889
6088
|
var HARDY_EXACT_BOUND = 50;
|
|
5890
6089
|
// H_α(n) — ITERATIVE (the original tail recursion grew hundreds of frames
|
|
5891
6090
|
// deep for inputs like hardy(1e10+20) where n1≈40 makes every ω^j segment
|
|
5892
6091
|
// take the exact branch: Maximum call stack size exceeded).
|
|
5893
6092
|
Q._hardyH = function (coeffs, nArg) {
|
|
6093
|
+
// Coefficients are read/written STRUCTURALLY below (c[j] -= 1, c[j-1] = n,
|
|
6094
|
+
// c_j compared against HARDY_EXACT_BOUND) and a fractional coefficient is
|
|
6095
|
+
// the normal case once the running base is 10+f — the sub-unit canonical
|
|
6096
|
+
// form must not rewrite them into reciprocals.
|
|
6097
|
+
_skipCanon++;
|
|
6098
|
+
try {
|
|
5894
6099
|
function MN(v) { return (v instanceof MetaNum) ? v.clone() : new MetaNum(v || 0); }
|
|
5895
6100
|
var c = [];
|
|
5896
6101
|
for (var i0 = 0; i0 < coeffs.length; i0++) c.push(MN(coeffs[i0]));
|
|
@@ -5926,12 +6131,11 @@
|
|
|
5926
6131
|
continue;
|
|
5927
6132
|
}
|
|
5928
6133
|
if (j >= c.length) return n; // no positive term left (safety net)
|
|
5929
|
-
// A coefficient can turn FRACTIONAL because the
|
|
5930
|
-
//
|
|
5931
|
-
//
|
|
5932
|
-
//
|
|
5933
|
-
//
|
|
5934
|
-
// ω^(j-1)·n step of the integer recursion, f→0 contributes nothing)
|
|
6134
|
+
// A coefficient can turn FRACTIONAL because the FS step writes the
|
|
6135
|
+
// running base n (n = 10+f for a fractional hardy input). For
|
|
6136
|
+
// 0 < c_j < 1 the "-1" step would go negative, so take the PARTIAL step:
|
|
6137
|
+
// ω^j·f contributes ω^(j-1)·(n·f) — continuous, f→1 is the full
|
|
6138
|
+
// ω^(j-1)·n step and f→0 contributes nothing.
|
|
5935
6139
|
var cjN = c[j].toNumber();
|
|
5936
6140
|
if (isFinite(cjN) && cjN > 0 && cjN < 1 && j >= 2) {
|
|
5937
6141
|
c[j] = MetaNum.ZERO.clone();
|
|
@@ -5954,19 +6158,16 @@
|
|
|
5954
6158
|
}
|
|
5955
6159
|
// budget exhausted: keep whatever was accumulated (monotone)
|
|
5956
6160
|
return n;
|
|
6161
|
+
} finally { _skipCanon--; }
|
|
5957
6162
|
};
|
|
5958
6163
|
|
|
5959
|
-
// H_{ω^k}(n)
|
|
5960
|
-
//
|
|
5961
|
-
//
|
|
5962
|
-
//
|
|
5963
|
-
//
|
|
5964
|
-
//
|
|
5965
|
-
//
|
|
5966
|
-
// destroyed base with a bogus row — and hardy(1e16+1e13) (k = 28) likewise.
|
|
5967
|
-
// There the from-below value is taken from the engine instead: 10{k-1}(n+1)
|
|
5968
|
-
// is exactly the lower bound the exact expansion stays strictly above, so
|
|
5969
|
-
// hardy stays monotone and keeps its "strictly below the engine" property.
|
|
6164
|
+
// H_{ω^k}(n), the from-below base of hardy (n ≥ 1e10). The exact expansion
|
|
6165
|
+
// writes a tower of level k-1 (H_{ω^10}(10) = 10{9}(11…21)), so array[0]
|
|
6166
|
+
// holds k entries and only fits while k ≤ maxCols. Above that the running
|
|
6167
|
+
// base and the coefficients the limit steps write from it turn structured and
|
|
6168
|
+
// every later comparison/collapse is meaningless (hardy(1e10+11) collapsed to
|
|
6169
|
+
// [[1],[2,20]]), so the value is taken from the engine instead:
|
|
6170
|
+
// 10{k-1}(n+1) is exactly the lower bound the exact expansion stays above.
|
|
5970
6171
|
Q._hardyOmegaPower = function (n1) {
|
|
5971
6172
|
var n1Num = (n1.layer === 0 && n1.array.length === 1 && n1.array[0].length === 1) ? n1.toNumber() : Infinity;
|
|
5972
6173
|
if (isFinite(n1Num) && n1Num >= 2) {
|
|
@@ -5982,14 +6183,11 @@
|
|
|
5982
6183
|
ec.push(1);
|
|
5983
6184
|
return Q._hardyH(ec, n1);
|
|
5984
6185
|
}
|
|
5985
|
-
// n1 > maxCols+1: the exact tower [c0, (n1-1)×(n1-2)] no longer fits
|
|
5986
|
-
//
|
|
5987
|
-
//
|
|
5988
|
-
//
|
|
5989
|
-
// [
|
|
5990
|
-
// strictly above hardy("1e10+10")'s exact [6313063, 19×18] (the level 21
|
|
5991
|
-
// dominates the level 19) and still far below the matching engine
|
|
5992
|
-
// ordinal op 10{ω^ω+ω+1}10.
|
|
6186
|
+
// n1 > maxCols+1: the exact tower [c0, (n1-1)×(n1-2)] no longer fits
|
|
6187
|
+
// (22 entries for n1 = 22). Keep the TRUNCATED cascade (level n1-1 over
|
|
6188
|
+
// the definitional base) instead of 10{n1-1}(n1+1): hardy("1e10+11") =
|
|
6189
|
+
// [3086.036…, 21×19] — strictly above hardy("1e10+10")'s exact
|
|
6190
|
+
// [6313063, 19×18] and far below 10{ω^ω+ω+1}10.
|
|
5993
6191
|
var lv = Math.floor(n1Num) - 1;
|
|
5994
6192
|
var depth = Math.min(Math.floor(n1Num) - 2, MetaNum.maxCols - 1);
|
|
5995
6193
|
var r0 = Q._hardyBaseR0();
|
|
@@ -6003,12 +6201,10 @@
|
|
|
6003
6201
|
return Q._applyOrdinalRows(n1, [0, 1], 1);
|
|
6004
6202
|
};
|
|
6005
6203
|
|
|
6006
|
-
// Decimal digit string of a plain number stored as r0 = [v, 1] (= 10^v),
|
|
6007
|
-
//
|
|
6008
|
-
//
|
|
6009
|
-
//
|
|
6010
|
-
// keeps the ordinary digit path — the old guard rejected exponents above
|
|
6011
|
-
// 1e5 and pushed hardy("1e100000") into the tower branch (layer 1).
|
|
6204
|
+
// Decimal digit string of a plain number stored as r0 = [v, 1] (= 10^v), or
|
|
6205
|
+
// null when the value is not in that form. Only an actual POWER TOWER is
|
|
6206
|
+
// excluded (10^^k has the same shape but v ≥ 1e10), so "1e100000" keeps the
|
|
6207
|
+
// ordinary digit path — the old guard pushed it into the tower branch.
|
|
6012
6208
|
Q._hardyDigitsOfPowForm = function (r0) {
|
|
6013
6209
|
if (!r0 || r0.length !== 2 || r0[1] !== 1 || !isFinite(r0[0])) return null;
|
|
6014
6210
|
if (r0[0] >= 1e10) return null; // power tower → slog branch
|
|
@@ -6046,11 +6242,123 @@
|
|
|
6046
6242
|
return v;
|
|
6047
6243
|
};
|
|
6048
6244
|
|
|
6049
|
-
//
|
|
6245
|
+
// hardy(n, base): H_α(base), where α is built from the base-`base` digits of
|
|
6246
|
+
// n (hardy(1234) = H_{ω³+ω²·2+ω·3+4}(10); hardy(10,8) = H_{ω+2}(8) = 20
|
|
6247
|
+
// because "10" reads as "12" in base 8). base defaults to 10 and must be an
|
|
6248
|
+
// integer in [2, 1000]. The base-10 path is the historical implementation;
|
|
6249
|
+
// other bases read the same ordinal off their own digit expansion.
|
|
6250
|
+
Q.hardy = function (n, base) {
|
|
6251
|
+
var b = hardyBase(base);
|
|
6252
|
+
if (b === 10) return Q._hardyDecimal(n);
|
|
6253
|
+
return Q._hardyBased(n, b);
|
|
6254
|
+
};
|
|
6255
|
+
|
|
6256
|
+
// Base argument validation (undefined → the default 10).
|
|
6257
|
+
function hardyBase(base) {
|
|
6258
|
+
if (base === undefined || base === null) return 10;
|
|
6259
|
+
var b = (base instanceof MetaNum) ? base.toNumber() : base;
|
|
6260
|
+
if (typeof b !== 'number' || !isFinite(b) || b !== Math.floor(b) || b < 2 || b > 1000) {
|
|
6261
|
+
throw Error(metaNumError + 'hardy: base must be an integer in [2, 1000]');
|
|
6262
|
+
}
|
|
6263
|
+
return b;
|
|
6264
|
+
}
|
|
6265
|
+
|
|
6266
|
+
// FGH(x, y) = H_{y^x}(y): the fast-growing hierarchy entry, defined through
|
|
6267
|
+
// hardy (f_x(y) with the hereditary base-y reading of y^x).
|
|
6268
|
+
Q.fgh = function (x, y) {
|
|
6269
|
+
var b = hardyBase(y);
|
|
6270
|
+
x = new MetaNum(x);
|
|
6271
|
+
if (x.isNaN()) return MetaNum.NaN.clone();
|
|
6272
|
+
var arg = new MetaNum(b).pow(x);
|
|
6273
|
+
return Q._hardyBased(arg, b);
|
|
6274
|
+
};
|
|
6275
|
+
|
|
6276
|
+
// Little-endian CNF coefficients of the base-b expansion of a decimal digit
|
|
6277
|
+
// string (most significant first), or null past the digit budget. Repeated
|
|
6278
|
+
// division on the digit string keeps values beyond the double range exact.
|
|
6279
|
+
function hardyBaseCoeffs(decStr, b) {
|
|
6280
|
+
if (b === 10) {
|
|
6281
|
+
var c10 = [];
|
|
6282
|
+
for (var i = decStr.length - 1; i >= 0; i--) c10.push(decStr.charCodeAt(i) - 48);
|
|
6283
|
+
return c10;
|
|
6284
|
+
}
|
|
6285
|
+
var coeffs = [];
|
|
6286
|
+
var cur = decStr.replace(/^0+/, '');
|
|
6287
|
+
if (cur === '') cur = '0';
|
|
6288
|
+
var guard = 0;
|
|
6289
|
+
while (cur !== '0') {
|
|
6290
|
+
if (++guard > 100000 || coeffs.length > 100000) return null;
|
|
6291
|
+
var q = '';
|
|
6292
|
+
var rem = 0;
|
|
6293
|
+
for (var i = 0; i < cur.length; i++) {
|
|
6294
|
+
var acc = rem * 10 + (cur.charCodeAt(i) - 48);
|
|
6295
|
+
var d = Math.floor(acc / b);
|
|
6296
|
+
rem = acc - d * b;
|
|
6297
|
+
q += String.fromCharCode(48 + d);
|
|
6298
|
+
}
|
|
6299
|
+
cur = q.replace(/^0+/, '') || '0';
|
|
6300
|
+
coeffs.push(rem);
|
|
6301
|
+
}
|
|
6302
|
+
return coeffs;
|
|
6303
|
+
}
|
|
6304
|
+
|
|
6305
|
+
// hardy(n, base) for base ≠ 10: the ordinal is read off the base-`base`
|
|
6306
|
+
// digits of n and evaluated on the argument `base` (+ any fraction of n).
|
|
6307
|
+
// Plain finite inputs only — structured / tower inputs keep the base-10
|
|
6308
|
+
// shadowing, which is decimal-specific.
|
|
6309
|
+
Q._hardyBased = function (n, b) {
|
|
6310
|
+
var rawNum = (typeof n === 'number') ? n
|
|
6311
|
+
: (typeof n === 'string' ? Number(n) : null);
|
|
6312
|
+
if (typeof n === 'string' && n.indexOf('+') > 0) {
|
|
6313
|
+
var plusParts = n.split('+');
|
|
6314
|
+
if (plusParts.length === 2 && plusParts[0] !== '' && plusParts[1] !== '' &&
|
|
6315
|
+
!/[eE]$/.test(plusParts[0]) && !/[eE]$/.test(plusParts[1])) {
|
|
6316
|
+
var pvA = new MetaNum(plusParts[0].trim());
|
|
6317
|
+
var pvB = new MetaNum(plusParts[1].trim());
|
|
6318
|
+
if (!pvA.isNaN() && !pvB.isNaN()) { n = pvA.add(pvB); rawNum = null; }
|
|
6319
|
+
}
|
|
6320
|
+
}
|
|
6321
|
+
if (rawNum !== null && !isFinite(rawNum)) rawNum = null;
|
|
6322
|
+
n = new MetaNum(n);
|
|
6323
|
+
if (n.sign !== 1) {
|
|
6324
|
+
throw Error(metaNumError + 'hardy: n must be a non-negative integer');
|
|
6325
|
+
}
|
|
6326
|
+
var num = (rawNum !== null) ? rawNum
|
|
6327
|
+
: ((n.layer === 0 && n.array.length === 1) ? n.toNumber() : Infinity);
|
|
6328
|
+
var hStr = (rawNum === null && n.layer === 0 && n.array.length === 1)
|
|
6329
|
+
? Q._hardyDigitsOfPowForm(n.array[0]) : null;
|
|
6330
|
+
if (!isFinite(num)) {
|
|
6331
|
+
if (n.layer === 0 && n.array.length === 1 && hStr !== null) {
|
|
6332
|
+
// a plain number beyond the double range: its exact digits
|
|
6333
|
+
} else {
|
|
6334
|
+
throw Error(metaNumError + 'hardy: base != 10 supports plain finite inputs only');
|
|
6335
|
+
}
|
|
6336
|
+
}
|
|
6337
|
+
var s = (hStr !== null) ? hStr : String(num);
|
|
6338
|
+
var eMatch = s.match(/^(\d)(?:\.(\d+))?e\+?(\d+)$/);
|
|
6339
|
+
if (eMatch) {
|
|
6340
|
+
var eFrac = eMatch[2] || '';
|
|
6341
|
+
var eZeros = Number(eMatch[3]) - eFrac.length;
|
|
6342
|
+
if (eZeros > 0) s = eMatch[1] + eFrac + '0'.repeat(eZeros);
|
|
6343
|
+
}
|
|
6344
|
+
var hFrac = 0;
|
|
6345
|
+
var hDot = s.indexOf('.');
|
|
6346
|
+
if (hDot >= 0) {
|
|
6347
|
+
hFrac = Number('0.' + s.slice(hDot + 1));
|
|
6348
|
+
s = s.slice(0, hDot);
|
|
6349
|
+
}
|
|
6350
|
+
var coeffs = hardyBaseCoeffs(s, b);
|
|
6351
|
+
if (coeffs === null) {
|
|
6352
|
+
throw Error(metaNumError + 'hardy: base expansion exceeds the digit budget');
|
|
6353
|
+
}
|
|
6354
|
+
return Q._hardyH(coeffs, new MetaNum(b + hFrac));
|
|
6355
|
+
};
|
|
6356
|
+
|
|
6357
|
+
// MetaNum.hardy(n): the Hardy level of n (base 10).
|
|
6050
6358
|
// n < 10 → 10 + n; otherwise the decimal digits of n become the CNF
|
|
6051
6359
|
// coefficients of an ordinal α (hardy(1234) = H_{ω³+ω²·2+ω·3+4}(10)) and
|
|
6052
6360
|
// the result is H_α(10).
|
|
6053
|
-
Q.
|
|
6361
|
+
Q._hardyDecimal = function (n) {
|
|
6054
6362
|
// A plain JS number / numeric string keeps its own decimal expansion: from
|
|
6055
6363
|
// 1e16 on the library stores the value as 10^v (r0 = [v,1]) and the way
|
|
6056
6364
|
// back through the double loses the low digits — hardy(1e16+1e13) =
|
|
@@ -6109,25 +6417,18 @@
|
|
|
6109
6417
|
var hNum = hVal.toNumber();
|
|
6110
6418
|
if (isFinite(hNum) && hNum >= 2 && hNum <= Number.MAX_SAFE_INTEGER) {
|
|
6111
6419
|
// k ≤ MSI: the tower fits the engine limit (f_ε₀); k > MSI is
|
|
6112
|
-
// beyond
|
|
6113
|
-
// The ordinal is read off the value itself
|
|
6114
|
-
// α = ω^ord(W)
|
|
6115
|
-
//
|
|
6116
|
-
//
|
|
6117
|
-
//
|
|
6118
|
-
// Above that the level no longer fits into ordinal rows and the
|
|
6119
|
-
// value becomes a layer marker whose layer is ceil(k) - 3:
|
|
6120
|
-
// ee10 < 10^(1e10+1) < ee20 … eee10 → layer 1
|
|
6121
|
-
// eee20 … eeee10 → layer 2, and so on
|
|
6420
|
+
// beyond ε₀, where the Hardy hierarchy is undefined → Infinity.
|
|
6421
|
+
// The ordinal is read off the value itself (V = 10^W gives
|
|
6422
|
+
// α = ω^ord(W)): while the height leaves a readable exponent the
|
|
6423
|
+
// result is the ordinary cascade on the from-below base (hardy(ee10)
|
|
6424
|
+
// = the ω^ω cascade, layer 0); above that it becomes a layer marker
|
|
6425
|
+
// of layer ceil(k)-3 (ee20 … eee10 → 1, eee20 … → 2, …).
|
|
6122
6426
|
var r0T = n.array[0];
|
|
6123
|
-
//
|
|
6124
|
-
//
|
|
6125
|
-
//
|
|
6126
|
-
//
|
|
6127
|
-
//
|
|
6128
|
-
// hardy("ee1e308") = the same rows at layer 2, and so on.
|
|
6129
|
-
// The stored tower r0 = [v, k] is (k-1) further 10^ levels over
|
|
6130
|
-
// 10^v; a layer-L input adds L more levels on top.
|
|
6427
|
+
// Clean power towers: every extra 10^ level in the input raises
|
|
6428
|
+
// hardy's layer by ONE, the rows stay those of the innermost
|
|
6429
|
+
// readable expansion (hardy("1e308") = the layer-0 cascade,
|
|
6430
|
+
// hardy("e1e308") = the same rows at layer 1, …). The stored tower
|
|
6431
|
+
// r0 = [v, k] is (k-1) levels over 10^v; layer L adds L more.
|
|
6131
6432
|
if (r0T && r0T.length === 2 && r0T[1] >= 1 &&
|
|
6132
6433
|
r0T[1] === Math.floor(r0T[1]) &&
|
|
6133
6434
|
isFinite(r0T[0]) && r0T[0] >= 10 &&
|
|
@@ -6206,30 +6507,31 @@
|
|
|
6206
6507
|
}
|
|
6207
6508
|
var hArg = hFrac > 0 ? new MetaNum(10 + hFrac) : MetaNum.TEN.clone();
|
|
6208
6509
|
if (s.length >= 11) {
|
|
6209
|
-
// n ≥ 1e10
|
|
6210
|
-
//
|
|
6211
|
-
//
|
|
6212
|
-
//
|
|
6213
|
-
//
|
|
6214
|
-
//
|
|
6215
|
-
//
|
|
6216
|
-
// kExp = 10 (ord = ω): H_{ω^ω·dk}(n1) = H_{ω^n1}(n1) exact (first
|
|
6217
|
-
// segment), the remaining dk−1 ω^ω-segments each add one ω-row —
|
|
6218
|
-
// hardy(1e10) = H_{ω^10}(10) = [3086.036065328153, 9×8] EXACTLY,
|
|
6219
|
-
// strictly below 10{10}10 (issues.md);
|
|
6220
|
-
// kExp ≥ 11 (ord = ω+c): mirror the engine's own ordinal rows for
|
|
6221
|
-
// 10{ω+c}(9+dk) on the from-below base H_{ω^n1}(n1) — hardy(1e11)
|
|
6222
|
-
// = H_{ω^(ω+1)}(10) keeps expande(10,10)'s row structure with the
|
|
6223
|
-
// strictly smaller definitional base, so hardy(1e11) < 10{ω+1}10
|
|
6224
|
-
// (issues.md).
|
|
6510
|
+
// n ≥ 1e10: n = dk·10^kExp + rest → α = ω^ord(kExp)·dk + ord(rest), and
|
|
6511
|
+
// H_α(10) = H_{ω^ord(kExp)·dk}(H_ord(rest)(10)) — the lower part acts
|
|
6512
|
+
// first (n1 = H_rest(10), recursive for rest < 1e10) and then becomes the
|
|
6513
|
+
// fundamental-sequence argument of the leading term. kExp = 10 (ord ω):
|
|
6514
|
+
// hardy(1e10) = H_{ω^10}(10) = [3086.036065328153, 9×8] exactly; kExp ≥ 11
|
|
6515
|
+
// mirrors the engine's 10{ω+c}(9+dk) rows on the smaller definitional
|
|
6516
|
+
// base, so hardy(1e11) < 10{ω+1}10.
|
|
6225
6517
|
var kExp = s.length - 1;
|
|
6226
6518
|
var dk = s.charCodeAt(0) - 48;
|
|
6227
|
-
var
|
|
6519
|
+
var restStr = s.slice(1);
|
|
6520
|
+
var restNum = Number(restStr);
|
|
6228
6521
|
var n1 = hArg.clone();
|
|
6229
6522
|
// the fractional part flows into the rest part too: hardy("1e10+1.5")
|
|
6230
6523
|
// = H_{ω^10}(hardy(1.5)) = H_{ω^10}(11.5) — dropping the fraction here
|
|
6231
6524
|
// made every 1e10+k.f input behave like 1e10+k
|
|
6232
|
-
if (restNum > 0) n1 = Q.hardy(restNum + hFrac);
|
|
6525
|
+
if (isFinite(restNum) && restNum > 0) n1 = Q.hardy(restNum + hFrac);
|
|
6526
|
+
else if (/[1-9]/.test(restStr)) {
|
|
6527
|
+
// issue #17: the rest itself can exceed the double range — hardy("1.5e309")
|
|
6528
|
+
// has rest = 5e308 > Number.MAX_VALUE, so Number() overflowed to Infinity
|
|
6529
|
+
// and hardy(Infinity) collapsed the whole value to Infinity (integer
|
|
6530
|
+
// mantissas like hardy("1e309") kept working because their rest is 0).
|
|
6531
|
+
// Recurse on the EXACT digit string instead: MetaNum parses it into the
|
|
6532
|
+
// 10^v form and the digit path below reads it back exactly.
|
|
6533
|
+
n1 = Q.hardy(new MetaNum(restStr));
|
|
6534
|
+
}
|
|
6233
6535
|
return Q._hardyLeading(kExp, dk, n1);
|
|
6234
6536
|
}
|
|
6235
6537
|
if (num < 10) return new MetaNum(10 + num);
|
|
@@ -6238,8 +6540,8 @@
|
|
|
6238
6540
|
return Q._hardyH(coeffs, hArg);
|
|
6239
6541
|
};
|
|
6240
6542
|
|
|
6241
|
-
// The leading term ω^ord(kExp)·dk of hardy's ordinal, evaluated from below
|
|
6242
|
-
//
|
|
6543
|
+
// The leading term ω^ord(kExp)·dk of hardy's ordinal, evaluated from below on
|
|
6544
|
+
// the already-computed lower part n1 = H_ord(rest)(10).
|
|
6243
6545
|
Q._hardyLeading = function (kExp, dk, n1) {
|
|
6244
6546
|
// a plain operand still has a single plain number as its whole array[0]
|
|
6245
6547
|
var nPlain = (n1.layer === 0 && n1.array.length === 1 && n1.array[0].length === 1);
|
|
@@ -6250,24 +6552,25 @@
|
|
|
6250
6552
|
return Q._hardyKeepBase(
|
|
6251
6553
|
Q._applyOrdinalRows(Q._hardyOmegaPower(n1), [0, 1], dk - 1)).normalize();
|
|
6252
6554
|
}
|
|
6253
|
-
// kExp ≥ 11
|
|
6254
|
-
//
|
|
6255
|
-
//
|
|
6256
|
-
//
|
|
6257
|
-
//
|
|
6258
|
-
//
|
|
6259
|
-
//
|
|
6260
|
-
//
|
|
6261
|
-
// (
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
var ks = String(kExp);
|
|
6555
|
+
// kExp ≥ 11: β = ord(kExp) and ω^β·dk is dk APPLICATIONS of H_{ω^β}, one
|
|
6556
|
+
// row [1, β] each (hardy(1.1e11) = [3086.036,9×8] [1,1,1]). The first
|
|
6557
|
+
// application on a plain operand expands from below (base H_{ω^n1}(n1)
|
|
6558
|
+
// plus the 10{β}10 cascade), strictly below 10{ω+1}10.
|
|
6559
|
+
// kExp may be non-integer (the tower branch passes 10^9.05 = 1122018454.3):
|
|
6560
|
+
// only the integer digits spell the ordinal, the fraction raises the
|
|
6561
|
+
// from-below base — reading String(kExp) verbatim put the decimal POINT
|
|
6562
|
+
// into the row (charCode('.')-48 = -2) and inflated it to one column per
|
|
6563
|
+
// character (issue #15: hardy("ee9.05")).
|
|
6564
|
+
var kInt = Math.floor(kExp);
|
|
6565
|
+
var kFracH = kExp - kInt;
|
|
6566
|
+
var ks = String(kInt);
|
|
6266
6567
|
var ordCoeffs = [];
|
|
6267
6568
|
for (var oi = ks.length - 1; oi >= 0; oi--) ordCoeffs.push(ks.charCodeAt(oi) - 48);
|
|
6268
6569
|
var out, extra;
|
|
6269
6570
|
if (nPlain && isFinite(n1Num) && n1Num >= 2) {
|
|
6270
|
-
|
|
6571
|
+
// the fractional part of kExp raises the from-below base (10+f)
|
|
6572
|
+
var baseN1 = (kFracH > 1e-12) ? n1.add(new MetaNum(Number(kFracH.toPrecision(15)))) : n1;
|
|
6573
|
+
out = Q._hardyOmegaPower(baseN1);
|
|
6271
6574
|
var mir = Q._hyperopFromOrdinalRaw(MetaNum.TEN.clone(), MetaNum.TEN.clone(), ordCoeffs);
|
|
6272
6575
|
for (var ri = 1; ri < mir.array.length; ri++) {
|
|
6273
6576
|
out = Q._applyOrdinalRows(out, mir.array[ri].slice(1), mir.array[ri][0]);
|
|
@@ -6284,8 +6587,7 @@
|
|
|
6284
6587
|
};
|
|
6285
6588
|
|
|
6286
6589
|
// ==================== BEAF Array Notation ====================
|
|
6287
|
-
// Bowers' Exploding Array Function
|
|
6288
|
-
// Rules:
|
|
6590
|
+
// Bowers' Exploding Array Function (googology.fandom.com/wiki/Array_notation):
|
|
6289
6591
|
// 1. {a} = a, {a,b} = a^b
|
|
6290
6592
|
// 2. {a,b,c,...,n,1} = {a,b,c,...,n}
|
|
6291
6593
|
// 3. {a,1,b,c,...,n} = a
|
|
@@ -6374,14 +6676,20 @@
|
|
|
6374
6676
|
};
|
|
6375
6677
|
|
|
6376
6678
|
// Parse BEAF string: {a,b,c,...}
|
|
6679
|
+
// Also accepts the sign/reciprocal spellings toBeaf() emits (issue #21):
|
|
6680
|
+
// "-{5}" (negative) and "{10,320}⁻¹" (sub-unit).
|
|
6377
6681
|
Q.fromBeaf = function(str) {
|
|
6378
6682
|
if (typeof str !== 'string') return MetaNum.NaN.clone();
|
|
6379
6683
|
var s = str.trim();
|
|
6684
|
+
var negate = false;
|
|
6685
|
+
if (s.charAt(0) === '-') { negate = true; s = s.slice(1).trim(); }
|
|
6686
|
+
var reciprocal = false;
|
|
6687
|
+
if (s.slice(-2) === '\u207B\u00B9') { reciprocal = true; s = s.slice(0, -2).trim(); }
|
|
6380
6688
|
if (s.charAt(0) !== '{' || s.charAt(s.length - 1) !== '}') {
|
|
6381
6689
|
return MetaNum.NaN.clone();
|
|
6382
6690
|
}
|
|
6383
6691
|
var inner = s.slice(1, -1).trim();
|
|
6384
|
-
if (inner === '') return MetaNum.
|
|
6692
|
+
if (inner === '') return MetaNum.NaN.clone();
|
|
6385
6693
|
var parts = inner.split(',');
|
|
6386
6694
|
var args = [];
|
|
6387
6695
|
for (var i = 0; i < parts.length; i++) {
|
|
@@ -6389,44 +6697,82 @@
|
|
|
6389
6697
|
if (!isFinite(val) || val < 1) return MetaNum.NaN.clone();
|
|
6390
6698
|
args.push(val);
|
|
6391
6699
|
}
|
|
6392
|
-
|
|
6393
|
-
|
|
6700
|
+
var out = Q.BEAF.apply(null, args);
|
|
6701
|
+
if (reciprocal) out = out.rec();
|
|
6702
|
+
if (negate) out = out.neg();
|
|
6703
|
+
return out;
|
|
6704
|
+
};
|
|
6705
|
+
|
|
6706
|
+
// The integer !Aa<n> = 10{ω^n}10 (issue #19: "!" adds one ω^ to the level).
|
|
6707
|
+
// While the ω^n expansion fits the row budget — the cascade's top row
|
|
6708
|
+
// [8, 9×n] needs n+1 ≤ maxCols columns — store the full rule-3 cascade at
|
|
6709
|
+
// `layer` (0 for "!", 1 for "@", …). Past the budget the cascade would
|
|
6710
|
+
// silently truncate ω^n down to ω^(maxCols-1), so instead go ONE LAYER UP
|
|
6711
|
+
// and keep the de-!-ed compact [[n],[1,0,1]] — the de-layer rule's
|
|
6712
|
+
// over-budget form, which preserves n in r0 (e.g. !Aa300).
|
|
6713
|
+
function bangAaInteger(n, layer) {
|
|
6714
|
+
if (n + 1 <= MetaNum.maxCols) {
|
|
6715
|
+
var coeffs = [];
|
|
6716
|
+
for (var i = 0; i < n; i++) coeffs.push(0);
|
|
6717
|
+
coeffs.push(1);
|
|
6718
|
+
var v = Q._hyperopFromOrdinalRaw(MetaNum.TEN.clone(), MetaNum.TEN.clone(), coeffs);
|
|
6719
|
+
v.layer = layer || 0;
|
|
6720
|
+
return v;
|
|
6721
|
+
}
|
|
6722
|
+
return new MetaNum({ sign: 1, layer: (layer || 0) + 1, array: [[n], [1, 0, 1]] });
|
|
6723
|
+
}
|
|
6724
|
+
|
|
6725
|
+
// Build the error thrown when a value has no faithful BEAF text form.
|
|
6726
|
+
function unrepresentableToBeaf(x) { var err = new Error(metaNumError + 'toBeaf: value has no BEAF representation ' +
|
|
6727
|
+
'(multi-row / layered internal form cannot be encoded as {a,b,...})');
|
|
6728
|
+
err.name = 'MetaNumUnrepresentableError';
|
|
6729
|
+
err.code = 'METANUM_UNREPRESENTABLE';
|
|
6730
|
+
return err;
|
|
6731
|
+
}
|
|
6394
6732
|
|
|
6395
6733
|
// Convert to BEAF string: {a,b,c,...}
|
|
6396
6734
|
P.toBeaf = function() {
|
|
6397
6735
|
var x = this.clone().normalize();
|
|
6398
6736
|
if (x.isNaN()) return 'NaN';
|
|
6737
|
+
// issue #21: a negative value keeps its sign — "-" prefixed to the BEAF of
|
|
6738
|
+
// its magnitude — instead of silently dropping it (MetaNum(-5) used to
|
|
6739
|
+
// come back as "{5}"). sign -2 is the negative sub-unit case, which the
|
|
6740
|
+
// recursive call spells as "-{…}⁻¹".
|
|
6741
|
+
if (x.sign === -1 || x.sign === -2) {
|
|
6742
|
+
var pos = x.clone();
|
|
6743
|
+
pos.sign = (x.sign === -1) ? 1 : 2;
|
|
6744
|
+
return '-' + pos.toBeaf();
|
|
6745
|
+
}
|
|
6746
|
+
// issue #21: a sub-unit value (sign 2 — r0 holds the RECIPROCAL) spells the
|
|
6747
|
+
// BEAF of the value it represents with a "⁻¹" suffix:
|
|
6748
|
+
// MetaNum("1e-320") → "{10,320}⁻¹" (reciprocal 10^320 = {10,320})
|
|
6749
|
+
// MetaNum("0.001") → "{1000}⁻¹" (reciprocal 1000 < MSI)
|
|
6750
|
+
// instead of dropping the sign and printing the bare reciprocal.
|
|
6751
|
+
var suffix = '';
|
|
6752
|
+
if (x.sign === 2) {
|
|
6753
|
+
if (!(x.layer === 0 && x.array.length === 1)) throw unrepresentableToBeaf(x);
|
|
6754
|
+
suffix = '\u207B\u00B9';
|
|
6755
|
+
x = x.rec();
|
|
6756
|
+
}
|
|
6399
6757
|
if (x.layer === 0 && x.array.length === 1) {
|
|
6400
6758
|
if (x.eq(MetaNum.ZERO)) return '{0}';
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
for (var i = 0; i < vals.length; i++) {
|
|
6411
|
-
if (vals[i] < 0) { allNonNegative = false; break; }
|
|
6412
|
-
}
|
|
6413
|
-
if (allNonNegative) {
|
|
6414
|
-
var a = decimalPlaces(x.array[0][0], 6);
|
|
6415
|
-
// Reconstruct BEAF: {a, ?, c, d, e, ...} from ordinal row [1, c, d, e, ..., 1]
|
|
6416
|
-
// (issues.md convention: BEAF(a,b,c,d,...) = a{...+ω*(d-1)+c}b)
|
|
6417
|
-
var beafParts = [a, '?'];
|
|
6418
|
-
for (var i = 0; i < vals.length; i++) {
|
|
6419
|
-
beafParts.push(String(vals[i]));
|
|
6420
|
-
}
|
|
6421
|
-
beafParts.push(String(diag));
|
|
6422
|
-
return '{' + beafParts.join(', ') + '}';
|
|
6423
|
-
}
|
|
6424
|
-
}
|
|
6759
|
+
var r0 = x.array[0];
|
|
6760
|
+
// [e, 1] is exactly 10^e = BEAF {10, e}. Keep the base instead of
|
|
6761
|
+
// dropping it and emitting the bare exponent (issue #17 D02:
|
|
6762
|
+
// BEAF(10,16) used to come back as "{16}"). Only a positive value with a
|
|
6763
|
+
// round-trippable argument (e >= 1) is encoded this way; everything else
|
|
6764
|
+
// keeps the historical decimal approximation of the leading term.
|
|
6765
|
+
if (x.sign === 1 && r0.length === 2 && r0[1] === 1 &&
|
|
6766
|
+
typeof r0[0] === 'number' && isFinite(r0[0]) && r0[0] >= 1) {
|
|
6767
|
+
return '{10,' + decimalPlaces(r0[0], 6) + '}' + suffix;
|
|
6425
6768
|
}
|
|
6769
|
+
return '{' + decimalPlaces(r0[0], 6) + '}' + suffix;
|
|
6426
6770
|
}
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6771
|
+
// A multi-row / layered value has no faithful BEAF text: the ordinal-row
|
|
6772
|
+
// form does not determine the BEAF iteration count `b`, and dumping the
|
|
6773
|
+
// internal rows is never acceptable output (issue #17 D03). Fail loudly
|
|
6774
|
+
// instead of emitting `[...]` literals or a placeholder `?` argument.
|
|
6775
|
+
throw unrepresentableToBeaf(x);
|
|
6430
6776
|
};
|
|
6431
6777
|
|
|
6432
6778
|
|
|
@@ -6470,7 +6816,12 @@
|
|
|
6470
6816
|
}
|
|
6471
6817
|
|
|
6472
6818
|
var temp;
|
|
6819
|
+
// Public primitive input: a numeric literal / decimal string in (0,1) or
|
|
6820
|
+
// (-1,0) is stored as the reciprocal with sign 2 / -2. Array/object input
|
|
6821
|
+
// (engine internals, JSON, parsers) is left exactly as given.
|
|
6822
|
+
var publicInput = false;
|
|
6473
6823
|
if (typeof input === "number" && input2 === undefined) {
|
|
6824
|
+
publicInput = true;
|
|
6474
6825
|
temp = objectCreate();
|
|
6475
6826
|
temp.array = [[Math.abs(input)]];
|
|
6476
6827
|
temp.sign = input < 0 ? -1 : 1;
|
|
@@ -6480,6 +6831,7 @@
|
|
|
6480
6831
|
} else if (parsedObject) {
|
|
6481
6832
|
temp = Q.fromObject(parsedObject);
|
|
6482
6833
|
} else if (typeof input === "string") {
|
|
6834
|
+
publicInput = true;
|
|
6483
6835
|
temp = Q.fromString(input);
|
|
6484
6836
|
} else if (Array.isArray(input)) {
|
|
6485
6837
|
temp = Q.fromArray(input, input2, input3);
|
|
@@ -6488,6 +6840,7 @@
|
|
|
6488
6840
|
} else if (typeof input === "object" && input !== null) {
|
|
6489
6841
|
temp = Q.fromObject(input);
|
|
6490
6842
|
} else {
|
|
6843
|
+
publicInput = true;
|
|
6491
6844
|
temp = objectCreate();
|
|
6492
6845
|
var num = Number(input);
|
|
6493
6846
|
if (!isNaN(num) && isFinite(num)) {
|
|
@@ -6503,6 +6856,7 @@
|
|
|
6503
6856
|
temp.sign = num < 0 ? -1 : 1;
|
|
6504
6857
|
}
|
|
6505
6858
|
}
|
|
6859
|
+
if (publicInput) canonicalizeSubUnit(temp);
|
|
6506
6860
|
|
|
6507
6861
|
x.array = deepCloneArray(temp.array);
|
|
6508
6862
|
x.sign = temp.sign;
|
|
@@ -6682,6 +7036,60 @@
|
|
|
6682
7036
|
|
|
6683
7037
|
MetaNum = clone(MetaNum);
|
|
6684
7038
|
MetaNum = defineConstants(MetaNum);
|
|
7039
|
+
|
|
7040
|
+
// Sub-unit canonical form: the engine's structural CONSUMERS (gamma, slog,
|
|
7041
|
+
// layeradd, pentate_log, …) read r0 as a plain magnitude, so they run with it
|
|
7042
|
+
// off — otherwise they saw reciprocals where they expected values (gamma(0.5)
|
|
7043
|
+
// read r0 [2] as 2). The PRODUCERS (constructor, arithmetic, log10/ln/exp,
|
|
7044
|
+
// root, neg) stay canonicalized, so MetaNum(0.5).sign === 2.
|
|
7045
|
+
(function () {
|
|
7046
|
+
var rawConsumers = [
|
|
7047
|
+
'gamma', 'lambertw', 'slog', 'layeradd', 'layeradd10',
|
|
7048
|
+
'pentate', 'pentate_log', 'pentate_root', 'ssrt', 'linear_sroot',
|
|
7049
|
+
'hyper_log', 'hyper_root', 'tetrate', 'expande', 'explode',
|
|
7050
|
+
'expandainate', 'expoiter', 'slayer', 'fastest_hypergrow',
|
|
7051
|
+
'logBase', 'mod', 'arrow'
|
|
7052
|
+
];
|
|
7053
|
+
for (var ri = 0; ri < rawConsumers.length; ri++) {
|
|
7054
|
+
var name = rawConsumers[ri];
|
|
7055
|
+
var fn = P[name];
|
|
7056
|
+
if (typeof fn !== 'function') continue;
|
|
7057
|
+
P[name] = (function (orig) {
|
|
7058
|
+
return function () {
|
|
7059
|
+
_skipCanon++;
|
|
7060
|
+
var out;
|
|
7061
|
+
try { out = orig.apply(this, arguments); }
|
|
7062
|
+
finally { _skipCanon--; }
|
|
7063
|
+
// The hyper-op builders (arrow, tetrate, expande, …) return a
|
|
7064
|
+
// CLOSURE that carries out the real computation — the guard is gone
|
|
7065
|
+
// by then, so the chain ran canonicalized and drifted by an ULP
|
|
7066
|
+
// (4{25}4 → 153.906997547968 instead of …802). Re-arm around it.
|
|
7067
|
+
if (typeof out === 'function') {
|
|
7068
|
+
return function () {
|
|
7069
|
+
_skipCanon++;
|
|
7070
|
+
try { return out.apply(this, arguments); }
|
|
7071
|
+
finally { _skipCanon--; }
|
|
7072
|
+
};
|
|
7073
|
+
}
|
|
7074
|
+
return out;
|
|
7075
|
+
};
|
|
7076
|
+
})(fn);
|
|
7077
|
+
}
|
|
7078
|
+
// Q-level entry points that drive the same structural machinery
|
|
7079
|
+
var rawStatics = ['BEAF', '_beafRecursive', 'arrow', 'beaf'];
|
|
7080
|
+
for (var si = 0; si < rawStatics.length; si++) {
|
|
7081
|
+
var sfn = Q[rawStatics[si]];
|
|
7082
|
+
if (typeof sfn !== 'function') continue;
|
|
7083
|
+
Q[rawStatics[si]] = (function (orig) {
|
|
7084
|
+
return function () {
|
|
7085
|
+
_skipCanon++;
|
|
7086
|
+
try { return orig.apply(this, arguments); }
|
|
7087
|
+
finally { _skipCanon--; }
|
|
7088
|
+
};
|
|
7089
|
+
})(sfn);
|
|
7090
|
+
}
|
|
7091
|
+
})();
|
|
7092
|
+
|
|
6685
7093
|
MetaNum['default'] = MetaNum.MetaNum = MetaNum;
|
|
6686
7094
|
|
|
6687
7095
|
if (typeof define == 'function' && define.amd) {
|