metanum 2.1.2 → 2.2.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 +124 -60
- package/format-metanum.js +54 -12
- package/metanum.js +1377 -160
- package/package.json +2 -2
- package/test_mixed.js +1754 -57
package/metanum.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//Author: dlsdl v2.
|
|
2
|
-
//v2.
|
|
1
|
+
//Author: dlsdl v2.2.0
|
|
2
|
+
//v2.2.0: Unify limit rules and fractional continuity; add iteraperiate with log/root inverses and ordinal-level root forms; fix formatting and large-base ordinal growth beyond y=100
|
|
3
3
|
//Code snippets and templates from OmegaNum.js
|
|
4
4
|
|
|
5
5
|
;(function (globalScope) {
|
|
@@ -1788,6 +1788,7 @@
|
|
|
1788
1788
|
}
|
|
1789
1789
|
return MetaNum.ZERO.clone();
|
|
1790
1790
|
}
|
|
1791
|
+
|
|
1791
1792
|
if (isSimple(x) && isSimple(base) && base.array[0][0] > 1) {
|
|
1792
1793
|
var v = x.array[0][0];
|
|
1793
1794
|
var b = base.array[0][0];
|
|
@@ -1842,12 +1843,22 @@
|
|
|
1842
1843
|
if (x.sign === -1 || x.sign === -2 || base.sign === -1 || base.sign === -2) return MetaNum.NaN.clone();
|
|
1843
1844
|
if (x.eq(MetaNum.ONE)) return MetaNum.ZERO.clone();
|
|
1844
1845
|
if (x.eq(base)) return MetaNum.ONE.clone();
|
|
1845
|
-
if (x.lt(base))
|
|
1846
|
+
if (x.lt(base)) {
|
|
1847
|
+
if (x.gt(MetaNum.ONE) && base.gt(MetaNum.ONE) && x.isFinite() && base.isFinite()) {
|
|
1848
|
+
var unifiedLowPentLog = MetaNum.hyper_log(x, base, 3);
|
|
1849
|
+
if (!unifiedLowPentLog.isNaN() && unifiedLowPentLog.isFinite()) return unifiedLowPentLog;
|
|
1850
|
+
}
|
|
1851
|
+
return MetaNum.ZERO.clone();
|
|
1852
|
+
}
|
|
1846
1853
|
var m = x.max(base);
|
|
1847
1854
|
if (m.gt(hyperLevel(4, MAX_SAFE_INTEGER))) {
|
|
1848
1855
|
if (x.gt(base)) return x.clone();
|
|
1849
1856
|
return MetaNum.ZERO.clone();
|
|
1850
1857
|
}
|
|
1858
|
+
if (x.gt(MetaNum.ONE) && base.gt(MetaNum.ONE) && x.isFinite() && base.isFinite()) {
|
|
1859
|
+
var unifiedPentLog = MetaNum.hyper_log(x, base, 3);
|
|
1860
|
+
if (!unifiedPentLog.isNaN() && unifiedPentLog.isFinite() && unifiedPentLog.isint()) return unifiedPentLog;
|
|
1861
|
+
}
|
|
1851
1862
|
if (isSimple(x) && isSimple(base) && base.array[0][0] > 1) {
|
|
1852
1863
|
var v = x.array[0][0];
|
|
1853
1864
|
var b = base.array[0][0];
|
|
@@ -1861,7 +1872,13 @@
|
|
|
1861
1872
|
return new MetaNum(count).add(slogVal);
|
|
1862
1873
|
}
|
|
1863
1874
|
}
|
|
1864
|
-
if (count > 0)
|
|
1875
|
+
if (count > 0) {
|
|
1876
|
+
if (v < 1) {
|
|
1877
|
+
if (typeof unifiedPentLog !== "undefined" && !unifiedPentLog.isNaN() && unifiedPentLog.isFinite()) return unifiedPentLog;
|
|
1878
|
+
return MetaNum.NaN.clone();
|
|
1879
|
+
}
|
|
1880
|
+
return new MetaNum(count).add(new MetaNum(v).slog(base));
|
|
1881
|
+
}
|
|
1865
1882
|
}
|
|
1866
1883
|
var r = 0;
|
|
1867
1884
|
for (var i = 0; i < 100; i++) {
|
|
@@ -1890,6 +1907,10 @@
|
|
|
1890
1907
|
return MetaNum.NaN.clone();
|
|
1891
1908
|
}
|
|
1892
1909
|
if (height.eq(MetaNum.ONE)) return x.clone();
|
|
1910
|
+
if (x.gt(MetaNum.ONE) && height.gt(MetaNum.ZERO) && x.isFinite() && height.isFinite()) {
|
|
1911
|
+
var unifiedPentRoot = MetaNum.hyper_root(x, height, 3);
|
|
1912
|
+
if (!unifiedPentRoot.isNaN() && unifiedPentRoot.isFinite()) return unifiedPentRoot;
|
|
1913
|
+
}
|
|
1893
1914
|
if (height.eq(2) && isSimple(x)) {
|
|
1894
1915
|
var v2 = x.array[0][0];
|
|
1895
1916
|
if (v2 <= 1) return MetaNum.ONE.clone();
|
|
@@ -1932,7 +1953,7 @@
|
|
|
1932
1953
|
}
|
|
1933
1954
|
return lo2.add(hi2).div(2);
|
|
1934
1955
|
}
|
|
1935
|
-
return
|
|
1956
|
+
return MetaNum.NaN.clone();
|
|
1936
1957
|
};
|
|
1937
1958
|
Q.pentate_root = Q.pent_root = function (x, height) {
|
|
1938
1959
|
return new MetaNum(x).pentate_root(height);
|
|
@@ -2287,6 +2308,30 @@
|
|
|
2287
2308
|
var subDepth = MetaNum.maxCols - 1;
|
|
2288
2309
|
var xBase = t.toNumber();
|
|
2289
2310
|
var yBase = other.toNumber();
|
|
2311
|
+
// x beyond MSI: the per-level counts (x-2) would exceed MAX_SAFE_INTEGER
|
|
2312
|
+
// and must not be clamped into fake MSI rows. The cascade is therefore
|
|
2313
|
+
// NOT expanded row-by-row — the base stays in r0 (its own E-tower form)
|
|
2314
|
+
// and the top composition (x{L-1})^(y-1)(x) is recorded as one row:
|
|
2315
|
+
// aperiote(1.5e16,1187) = (1.5e16{1186})^1186 (10^16.176…)
|
|
2316
|
+
// → [[16.176…,1],[1186,1186]].
|
|
2317
|
+
if (isFinite(xBase) && xBase > MAX_SAFE_INTEGER) {
|
|
2318
|
+
var bigRes = new MetaNum(0);
|
|
2319
|
+
bigRes.sign = 1;
|
|
2320
|
+
bigRes.layer = 0;
|
|
2321
|
+
if (t.array[0].length === 1) {
|
|
2322
|
+
// plain huge base: keep it in the E-tower form 10^log10(x)
|
|
2323
|
+
var logxB = Math.log10(xBase);
|
|
2324
|
+
bigRes.array = [[isFinite(logxB) ? logxB : xBase, 1]];
|
|
2325
|
+
} else {
|
|
2326
|
+
bigRes.array = [t.array[0].slice()];
|
|
2327
|
+
}
|
|
2328
|
+
var bigY = isFinite(yBase) ? yBase : MAX_SAFE_INTEGER;
|
|
2329
|
+
var bigTop = Math.max(bigY - 1, 1);
|
|
2330
|
+
if (bigTop > MAX_SAFE_INTEGER) bigTop = MAX_SAFE_INTEGER;
|
|
2331
|
+
bigRes.array.push([bigTop, arrowsNum - 1]);
|
|
2332
|
+
bigRes.normalize();
|
|
2333
|
+
return bigRes;
|
|
2334
|
+
}
|
|
2290
2335
|
var xCnt = isFinite(xBase) ? Math.min(Math.max(xBase - 2, 0), MAX_SAFE_INTEGER) : MAX_SAFE_INTEGER;
|
|
2291
2336
|
// Top-of-chain count: x{L}y = x{L-1}^{y-1}(x), so every level below the
|
|
2292
2337
|
// top carries (x-2) ops while level L-1 carries (y-2) ops for y>=3
|
|
@@ -2504,50 +2549,967 @@
|
|
|
2504
2549
|
}
|
|
2505
2550
|
}
|
|
2506
2551
|
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2552
|
+
var INVERSE_DEFAULTS = {
|
|
2553
|
+
tol: 1e-12,
|
|
2554
|
+
maxIterations: 200,
|
|
2555
|
+
maxBracketExpansions: 60,
|
|
2556
|
+
branch: "principal",
|
|
2557
|
+
acceleration: "auto",
|
|
2558
|
+
diagnostics: false
|
|
2559
|
+
};
|
|
2560
|
+
var INVERSE_LIMITS = { maxIterations: 10000, maxBracketExpansions: 2048 };
|
|
2561
|
+
var INVERSE_OPTION_KEYS = {
|
|
2562
|
+
tol: true, maxIterations: true, maxBracketExpansions: true,
|
|
2563
|
+
branch: true, acceleration: true, diagnostics: true
|
|
2564
|
+
};
|
|
2565
|
+
|
|
2566
|
+
function normalizeInverseOptions(input) {
|
|
2567
|
+
var options = {};
|
|
2568
|
+
var clampedOptions = {};
|
|
2569
|
+
var key;
|
|
2570
|
+
for (key in INVERSE_DEFAULTS) options[key] = INVERSE_DEFAULTS[key];
|
|
2571
|
+
if (input === undefined) return { options: options, clampedOptions: clampedOptions, error: null };
|
|
2572
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
2573
|
+
return { options: options, clampedOptions: clampedOptions, error: "options must be an object" };
|
|
2574
|
+
}
|
|
2575
|
+
for (key in input) {
|
|
2576
|
+
if (Object.prototype.hasOwnProperty.call(input, key) && !Object.prototype.hasOwnProperty.call(INVERSE_OPTION_KEYS, key)) {
|
|
2577
|
+
return { options: options, clampedOptions: clampedOptions, error: "unknown option: " + key };
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
if (input.tol !== undefined) {
|
|
2581
|
+
if (typeof input.tol !== "number" || !isFinite(input.tol) || input.tol <= 0) {
|
|
2582
|
+
return { options: options, clampedOptions: clampedOptions, error: "tol must be finite and positive" };
|
|
2583
|
+
}
|
|
2584
|
+
options.tol = input.tol;
|
|
2585
|
+
}
|
|
2586
|
+
var budgets = ["maxIterations", "maxBracketExpansions"];
|
|
2587
|
+
for (var i = 0; i < budgets.length; i++) {
|
|
2588
|
+
key = budgets[i];
|
|
2589
|
+
if (input[key] === undefined) continue;
|
|
2590
|
+
var budget = input[key];
|
|
2591
|
+
if (typeof budget !== "number" || !isFinite(budget) || budget <= 0 || Math.floor(budget) !== budget) {
|
|
2592
|
+
return { options: options, clampedOptions: clampedOptions, error: key + " must be a positive integer" };
|
|
2593
|
+
}
|
|
2594
|
+
if (budget > INVERSE_LIMITS[key]) {
|
|
2595
|
+
clampedOptions[key] = INVERSE_LIMITS[key];
|
|
2596
|
+
options[key] = INVERSE_LIMITS[key];
|
|
2597
|
+
} else options[key] = budget;
|
|
2598
|
+
}
|
|
2599
|
+
if (input.branch !== undefined) {
|
|
2600
|
+
if (input.branch !== "principal") return { options: options, clampedOptions: clampedOptions, error: "unsupported branch" };
|
|
2601
|
+
options.branch = input.branch;
|
|
2602
|
+
}
|
|
2603
|
+
if (input.acceleration !== undefined) {
|
|
2604
|
+
if (input.acceleration !== "auto" && input.acceleration !== "bisection") {
|
|
2605
|
+
return { options: options, clampedOptions: clampedOptions, error: "unsupported acceleration" };
|
|
2606
|
+
}
|
|
2607
|
+
options.acceleration = input.acceleration;
|
|
2608
|
+
}
|
|
2609
|
+
if (input.diagnostics !== undefined) {
|
|
2610
|
+
if (typeof input.diagnostics !== "boolean") {
|
|
2611
|
+
return { options: options, clampedOptions: clampedOptions, error: "diagnostics must be boolean" };
|
|
2612
|
+
}
|
|
2613
|
+
options.diagnostics = input.diagnostics;
|
|
2614
|
+
}
|
|
2615
|
+
return { options: options, clampedOptions: clampedOptions, error: null };
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
function createInverseContext(direction, descriptor, levelText, normalized) {
|
|
2619
|
+
return {
|
|
2620
|
+
direction: direction,
|
|
2621
|
+
descriptor: descriptor,
|
|
2622
|
+
levelText: levelText,
|
|
2623
|
+
options: normalized.options,
|
|
2624
|
+
clampedOptions: normalized.clampedOptions,
|
|
2625
|
+
iterations: 0,
|
|
2626
|
+
expansions: 0,
|
|
2627
|
+
forwardEvaluations: 0,
|
|
2628
|
+
fallbackCount: 0,
|
|
2629
|
+
bracket: null,
|
|
2630
|
+
environment: { maxRows: MetaNum.maxRows, maxCols: MetaNum.maxCols }
|
|
2631
|
+
};
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
function cloneInverseBracket(bracket) {
|
|
2635
|
+
if (!bracket) return null;
|
|
2636
|
+
return {
|
|
2637
|
+
lo: bracket.lo === null || bracket.lo === undefined ? null : new MetaNum(bracket.lo),
|
|
2638
|
+
hi: bracket.hi === null || bracket.hi === undefined ? null : new MetaNum(bracket.hi),
|
|
2639
|
+
loCmp: bracket.loCmp === undefined ? null : bracket.loCmp,
|
|
2640
|
+
hiCmp: bracket.hiCmp === undefined ? null : bracket.hiCmp,
|
|
2641
|
+
coordinate: bracket.coordinate
|
|
2642
|
+
};
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
function cloneInverseResidual(residual) {
|
|
2646
|
+
if (!residual) return { kind: "unavailable", absolute: null, relative: null, comparison: null, width: null, reason: "not evaluated" };
|
|
2647
|
+
var copy = {};
|
|
2648
|
+
for (var key in residual) {
|
|
2649
|
+
if (!Object.prototype.hasOwnProperty.call(residual, key)) continue;
|
|
2650
|
+
copy[key] = residual[key] instanceof MetaNum ? residual[key].clone() : residual[key];
|
|
2651
|
+
}
|
|
2652
|
+
return copy;
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
function finalizeInverseResult(ctx, fields) {
|
|
2656
|
+
fields = fields || {};
|
|
2657
|
+
var status = fields.status || "unrecoverable";
|
|
2658
|
+
var successful = status === "exact" || status === "minimal-reproducing" || status === "lower-bound" || status === "approximate";
|
|
2659
|
+
var value = fields.value instanceof MetaNum ? fields.value.clone() : MetaNum.NaN.clone();
|
|
2660
|
+
if (!successful || value.isNaN() || !value.isFinite()) value = MetaNum.NaN.clone();
|
|
2661
|
+
if (!successful) status = fields.status || "unrecoverable";
|
|
2662
|
+
var actualOptions = {};
|
|
2663
|
+
for (var key in ctx.options) actualOptions[key] = ctx.options[key];
|
|
2664
|
+
actualOptions.clampedOptions = {};
|
|
2665
|
+
for (key in ctx.clampedOptions) actualOptions.clampedOptions[key] = ctx.clampedOptions[key];
|
|
2666
|
+
return {
|
|
2667
|
+
status: status,
|
|
2668
|
+
value: value,
|
|
2669
|
+
direction: ctx.direction,
|
|
2670
|
+
operation: ctx.descriptor ? ctx.descriptor.op : "arrow",
|
|
2671
|
+
unknown: ctx.direction === "log" ? "b" : "n",
|
|
2672
|
+
level: ctx.levelText,
|
|
2673
|
+
branch: ctx.options.branch,
|
|
2674
|
+
method: fields.method || "none",
|
|
2675
|
+
iterations: ctx.iterations,
|
|
2676
|
+
expansions: ctx.expansions,
|
|
2677
|
+
forwardEvaluations: ctx.forwardEvaluations,
|
|
2678
|
+
fallbackCount: ctx.fallbackCount,
|
|
2679
|
+
bracket: cloneInverseBracket(fields.bracket === undefined ? ctx.bracket : fields.bracket),
|
|
2680
|
+
residual: cloneInverseResidual(fields.residual),
|
|
2681
|
+
termination: fields.termination || status,
|
|
2682
|
+
message: fields.message || status,
|
|
2683
|
+
evidence: fields.evidence || (status === "exact" ? "definition-guaranteed" : "numerical-experiment"),
|
|
2684
|
+
multipleSolutions: !!fields.multipleSolutions,
|
|
2685
|
+
representationLevel: !!fields.representationLevel,
|
|
2686
|
+
legacyAnchor: !!fields.legacyAnchor,
|
|
2687
|
+
minimalityAttained: fields.minimalityAttained === undefined ? null : fields.minimalityAttained,
|
|
2688
|
+
encoding: fields.encoding || null,
|
|
2689
|
+
loss: fields.loss || null,
|
|
2690
|
+
provenance: fields.provenance || null,
|
|
2691
|
+
options: actualOptions,
|
|
2692
|
+
environment: { maxRows: ctx.environment.maxRows, maxCols: ctx.environment.maxCols }
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
function inverseFailure(ctx, status, termination, message, flags) {
|
|
2697
|
+
flags = flags || {};
|
|
2698
|
+
flags.status = status;
|
|
2699
|
+
flags.termination = termination || status;
|
|
2700
|
+
flags.message = message || termination || status;
|
|
2701
|
+
return finalizeInverseResult(ctx, flags);
|
|
2702
|
+
}
|
|
2703
|
+
|
|
2704
|
+
function exposeInverseResult(result, diagnostics) {
|
|
2705
|
+
return diagnostics ? result : result.value.clone();
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
function safeInverseNumber(x) {
|
|
2709
|
+
if (!(x instanceof MetaNum) || !isNumeric(x)) return null;
|
|
2710
|
+
var value = x.toNumber();
|
|
2711
|
+
return isFinite(value) ? value : null;
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
function firstStructureDifference(a, b) {
|
|
2715
|
+
if (a.layer !== b.layer) return { field: "layer", left: a.layer, right: b.layer };
|
|
2716
|
+
var rows = Math.max(a.array.length, b.array.length);
|
|
2717
|
+
for (var i = 0; i < rows; i++) {
|
|
2718
|
+
var ar = a.array[i] || [], br = b.array[i] || [];
|
|
2719
|
+
var cols = Math.max(ar.length, br.length);
|
|
2720
|
+
for (var j = 0; j < cols; j++) {
|
|
2721
|
+
if (ar[j] !== br[j]) return { field: "array", row: i, column: j, left: ar[j], right: br[j] };
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
return null;
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
function measureInverseResidual(value, target, bracket) {
|
|
2728
|
+
var comparison = value.cmp(target);
|
|
2729
|
+
var base = {
|
|
2730
|
+
absolute: null,
|
|
2731
|
+
relative: null,
|
|
2732
|
+
comparison: typeof comparison === "number" && !isNaN(comparison) ? comparison : null,
|
|
2733
|
+
width: null,
|
|
2734
|
+
representationLevel: false
|
|
2735
|
+
};
|
|
2736
|
+
if (typeof comparison !== "number" || isNaN(comparison)) {
|
|
2737
|
+
base.kind = "unavailable";
|
|
2738
|
+
base.reason = "MetaNum comparison is unavailable";
|
|
2739
|
+
return base;
|
|
2740
|
+
}
|
|
2741
|
+
var vn = safeInverseNumber(value), cn = safeInverseNumber(target);
|
|
2742
|
+
if (vn !== null && cn !== null) {
|
|
2743
|
+
var absolute = Math.abs(vn - cn);
|
|
2744
|
+
var relative = absolute / Math.max(1, Math.abs(cn));
|
|
2745
|
+
if (isFinite(absolute) && isFinite(relative)) {
|
|
2746
|
+
base.kind = "number-absolute-relative";
|
|
2747
|
+
base.absolute = absolute;
|
|
2748
|
+
base.relative = relative;
|
|
2749
|
+
return base;
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
var structured = value.layer > 0 || target.layer > 0 || value.array.length > 1 || target.array.length > 1;
|
|
2753
|
+
base.representationLevel = comparison === 0 && (structured || vn === null || cn === null);
|
|
2754
|
+
if (!structured && value.gt(MetaNum.ZERO) && target.gt(MetaNum.ZERO)) {
|
|
2755
|
+
var lv = value.log10(), lc = target.log10();
|
|
2756
|
+
var lvn = safeInverseNumber(lv), lcn = safeInverseNumber(lc);
|
|
2757
|
+
if (lvn !== null && lcn !== null) {
|
|
2758
|
+
var logAbsolute = Math.abs(lvn - lcn);
|
|
2759
|
+
var logRelative = logAbsolute / Math.max(1, Math.abs(lcn));
|
|
2760
|
+
if (isFinite(logAbsolute) && isFinite(logRelative)) {
|
|
2761
|
+
base.kind = "log-space";
|
|
2762
|
+
base.absolute = logAbsolute;
|
|
2763
|
+
base.relative = logRelative;
|
|
2764
|
+
base.transform = "log10";
|
|
2765
|
+
return base;
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
if (structured) {
|
|
2770
|
+
base.kind = "ordinal-structure";
|
|
2771
|
+
base.structureDifference = firstStructureDifference(value, target);
|
|
2772
|
+
base.reason = comparison === 0 ? "representation-level equality; numeric residual unavailable" : "ordinal structures differ";
|
|
2773
|
+
} else if (bracket) {
|
|
2774
|
+
base.kind = "bracket-only";
|
|
2775
|
+
base.reason = "only comparison and bracket evidence are available";
|
|
2776
|
+
} else {
|
|
2777
|
+
base.kind = "meta-comparison";
|
|
2778
|
+
base.reason = "numeric residual is not faithfully representable";
|
|
2779
|
+
}
|
|
2780
|
+
return base;
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
var OPERATION_REGISTRY = Object.create(null);
|
|
2784
|
+
var OPERATION_DESCRIPTORS = [];
|
|
2785
|
+
|
|
2786
|
+
function registerOperationDescriptor(op, levelText, invShort, invCode, rootShort, rootCode, options) {
|
|
2787
|
+
options = options || {};
|
|
2788
|
+
var high = !!options.baseIndependent;
|
|
2789
|
+
var descriptor = {
|
|
2790
|
+
op: op,
|
|
2791
|
+
levelText: levelText,
|
|
2792
|
+
forwardKind: "named",
|
|
2793
|
+
logNames: ["inv_" + op, invShort, invCode].concat(options.extraLogNames || []).filter(function (name) { return !!name; }),
|
|
2794
|
+
rootNames: [op + "_root", rootShort, rootCode, "root_" + op],
|
|
2795
|
+
logDomain: { unknown: "b", lower: 1, upper: null, lowerOpen: false, upperOpen: true, direction: 1, certificate: "ordinal-recursion" },
|
|
2796
|
+
rootDomain: { unknown: "n", lower: high ? 2 : 1, upper: null, lowerOpen: false, upperOpen: true, direction: 1, certificate: high ? "base-independent-marker" : "ordinal-recursion" },
|
|
2797
|
+
initialBracket: { log: [1, 2], root: high ? [2, 4] : [1, 2] },
|
|
2798
|
+
monotonicityEvidence: high ? "representation-level ordinal marker monotonicity" : "successor/limit recursion on the principal domain",
|
|
2799
|
+
structuralDecoder: null,
|
|
2800
|
+
markerPolicy: options.markerPolicy || (high ? "base-independent-marker" : "ordinal-structure"),
|
|
2801
|
+
legacyAnchorPolicy: high ? "legacy-anchor" : "verified"
|
|
2802
|
+
};
|
|
2803
|
+
OPERATION_REGISTRY[op] = descriptor;
|
|
2804
|
+
OPERATION_DESCRIPTORS.push(descriptor);
|
|
2805
|
+
return descriptor;
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
registerOperationDescriptor("aperiote", "ω", "i_aper", "i10", "r_aper", "r10");
|
|
2809
|
+
registerOperationDescriptor("expande", "ω+1", "i_expa", "i11", "r_expa", "r11");
|
|
2810
|
+
registerOperationDescriptor("multiexpande", "ω+2", "i_muea", "i12", "r_muea", "r12");
|
|
2811
|
+
registerOperationDescriptor("powerexpande", "ω+3", "i_poea", "i13", "r_poea", "r13");
|
|
2812
|
+
registerOperationDescriptor("aperioexpande", "ω*2", "i_apea", "i20", "r_apea", "r20");
|
|
2813
|
+
registerOperationDescriptor("explode", "ω*2+1", "i_expl", "i21", "r_expl", "r21");
|
|
2814
|
+
registerOperationDescriptor("multiexplode", "ω*2+2", "i_muel", "i22", "r_muel", "r22");
|
|
2815
|
+
registerOperationDescriptor("aperioexplode", "ω*3", "i_apel", "i30", "r_apel", "r30");
|
|
2816
|
+
registerOperationDescriptor("detonate", "ω*3+1", "i_deto", "i31", "r_deto", "r31");
|
|
2817
|
+
registerOperationDescriptor("aperiodetonate", "ω*4", "i_apdt", "i40", "r_apdt", "r40");
|
|
2818
|
+
registerOperationDescriptor("aperionate", "ω^2", "i_apeo", "i100", "r_apeo", "r100");
|
|
2819
|
+
registerOperationDescriptor("megote", "ω^2+1", "i_mego", "i101", "r_mego", "r101");
|
|
2820
|
+
registerOperationDescriptor("multimegote", "ω^2+2", "i_mume", "i102", "r_mume", "r102");
|
|
2821
|
+
registerOperationDescriptor("aperimegote", "ω^2+ω", "i_apmg", "i110", "r_apmg", "r110");
|
|
2822
|
+
registerOperationDescriptor("megoexpande", "ω^2+ω+1", "i_mgea", "i111", "r_mgea", "r111");
|
|
2823
|
+
registerOperationDescriptor("aperimegoexpande", "ω^2+ω*2", "i_apme", "i120", "r_apme", "r120");
|
|
2824
|
+
registerOperationDescriptor("megoaperionate", "ω^2*2", "i_mgao", "i200", "r_mgao", "r200");
|
|
2825
|
+
registerOperationDescriptor("gigote", "ω^2*2+1", "i_gigo", "i201", "r_gigo", "r201");
|
|
2826
|
+
registerOperationDescriptor("aperigigote", "ω^2*2+ω", "i_apgg", "i210", "r_apgg", "r210");
|
|
2827
|
+
registerOperationDescriptor("gigoaperionate", "ω^2*3", "i_ggap", "i300", "r_ggap", "r300");
|
|
2828
|
+
registerOperationDescriptor("aperiatote", "ω^3", "i_apat", "i1000", "r_apat", "r1000");
|
|
2829
|
+
registerOperationDescriptor("powiainate", "ω^3+1", "i_pwan", "i1001", "r_pwan", "r1001");
|
|
2830
|
+
registerOperationDescriptor("expandainate", "ω^3+ω", "i_epan", "i1010", "r_epan", "r1010");
|
|
2831
|
+
registerOperationDescriptor("megodainate", "ω^3+ω^2", "i_mgan", "i1100", "r_mgan", "r1100");
|
|
2832
|
+
registerOperationDescriptor("powiairate", "ω^3*2", "i_pwar", "i2000", "r_pwar", "r2000");
|
|
2833
|
+
registerOperationDescriptor("aperioguate", "ω^4", "i_apgu", "i10000", "r_apgu", "r10000");
|
|
2834
|
+
registerOperationDescriptor("iterate", "ω^ω", null, "iww", "r_iter", "rww", { extraLogNames: ["inv_iter"] });
|
|
2835
|
+
registerOperationDescriptor("itermult", "ω^ω+1", "i_itmu", "iw01", "r_itmu", "rw01", { baseIndependent: true, markerPolicy: "ceil-height" });
|
|
2836
|
+
registerOperationDescriptor("iteraperiate", "ω^ω+ω", "i_itap", "iw0w", "r_itap", "rw0w", { baseIndependent: true, markerPolicy: "floor-height" });
|
|
2837
|
+
registerOperationDescriptor("cuboiter", "ω^ω*2", "i_cube", "iwx2", "r_cube", "rwx2", { baseIndependent: true });
|
|
2838
|
+
registerOperationDescriptor("expoiter", "ω^(ω+1)", "i_expo", "iwa1", "r_expo", "rwa1", { baseIndependent: true });
|
|
2839
|
+
registerOperationDescriptor("trioterate", "ω^(ω*2)", "i_tria", "iwm2", "r_tria", "rwm2", { baseIndependent: true });
|
|
2840
|
+
registerOperationDescriptor("trixxate", "ω^(ω^2)", "i_trix", "iwp2", "r_trix", "rwp2", { baseIndependent: true });
|
|
2841
|
+
registerOperationDescriptor("aperixxate", "ω^(ω^ω)", "i_apix", "iwpw", "r_apix", "rwpw", { baseIndependent: true });
|
|
2842
|
+
registerOperationDescriptor("epsilonate", "ε₀", "i_epsl", "iepsl", "r_epsl", "repsl", { baseIndependent: true, markerPolicy: "epsilon-fraction" });
|
|
2843
|
+
|
|
2844
|
+
function getOperationDescriptor(levelOrOp) {
|
|
2845
|
+
if (typeof levelOrOp === "string") return OPERATION_REGISTRY[levelOrOp] || null;
|
|
2846
|
+
return levelOrOp && levelOrOp.op ? levelOrOp : null;
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
function createArrowDescriptor(level, levelText) {
|
|
2850
|
+
return {
|
|
2851
|
+
op: "arrow",
|
|
2852
|
+
levelText: levelText,
|
|
2853
|
+
level: level,
|
|
2854
|
+
forwardKind: "arrow",
|
|
2855
|
+
logDomain: { unknown: "b", lower: 0, upper: null, lowerOpen: false, upperOpen: true, direction: 1, certificate: "successor-recursion" },
|
|
2856
|
+
rootDomain: { unknown: "n", lower: 1, upper: null, lowerOpen: false, upperOpen: true, direction: 1, certificate: "successor-recursion" },
|
|
2857
|
+
initialBracket: { log: [0, 1], root: [1, 2] },
|
|
2858
|
+
monotonicityEvidence: "finite/fractional successor recursion on the certified principal domain",
|
|
2859
|
+
structuralDecoder: null,
|
|
2860
|
+
markerPolicy: "not-applicable",
|
|
2861
|
+
legacyAnchorPolicy: "verified"
|
|
2862
|
+
};
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
function makeForwardEvaluator(descriptor, direction, fixed, ctx) {
|
|
2866
|
+
return function (x) {
|
|
2867
|
+
ctx.forwardEvaluations++;
|
|
2868
|
+
try {
|
|
2869
|
+
var n = new MetaNum(direction === "log" ? fixed : x);
|
|
2870
|
+
var b = new MetaNum(direction === "log" ? x : fixed);
|
|
2871
|
+
if (descriptor.forwardKind === "named" && isSmall(b) && isNumeric(b)) b = rawMetaNum(b.toNumber());
|
|
2872
|
+
if (descriptor.forwardKind === "arrow") return n.arrow(descriptor.level)(b);
|
|
2873
|
+
return n[descriptor.op](b);
|
|
2874
|
+
} catch (e) {
|
|
2513
2875
|
return MetaNum.NaN.clone();
|
|
2514
2876
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2877
|
+
};
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2880
|
+
function evaluateAndCompare(ctx, evaluator, x, target, direction) {
|
|
2881
|
+
var value = evaluator(x);
|
|
2882
|
+
var comparison = value.isNaN() ? NaN : value.cmp(target);
|
|
2883
|
+
var valid = !(value instanceof MetaNum) || !value.isNaN();
|
|
2884
|
+
if (typeof comparison !== "number" || isNaN(comparison)) valid = false;
|
|
2885
|
+
comparison = valid ? (comparison > 0 ? 1 : comparison < 0 ? -1 : 0) : NaN;
|
|
2886
|
+
return {
|
|
2887
|
+
x: x,
|
|
2888
|
+
value: value,
|
|
2889
|
+
cmp: comparison,
|
|
2890
|
+
side: valid ? direction * comparison : NaN,
|
|
2891
|
+
valid: valid,
|
|
2892
|
+
residual: valid ? measureInverseResidual(value, target, ctx.bracket) : null
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
function inverseBranchContains(branch, x) {
|
|
2897
|
+
if (!branch) return true;
|
|
2898
|
+
if (!(x instanceof MetaNum)) x = new MetaNum(x);
|
|
2899
|
+
if (branch.lower !== null && branch.lower !== undefined) {
|
|
2900
|
+
var lower = x.cmp(branch.lower);
|
|
2901
|
+
if (branch.lowerOpen ? lower <= 0 : lower < 0) return false;
|
|
2902
|
+
}
|
|
2903
|
+
if (branch.upper !== null && branch.upper !== undefined) {
|
|
2904
|
+
var upper = x.cmp(branch.upper);
|
|
2905
|
+
if (branch.upperOpen ? upper >= 0 : upper > 0) return false;
|
|
2906
|
+
}
|
|
2907
|
+
return true;
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
function verifyInverseCandidate(ctx, evaluator, candidate, target, details) {
|
|
2911
|
+
details = details || {};
|
|
2912
|
+
if (!(candidate instanceof MetaNum)) candidate = new MetaNum(candidate);
|
|
2913
|
+
if (candidate.isNaN() || !candidate.isFinite()) return null;
|
|
2914
|
+
if (!inverseBranchContains(details.branch === undefined ? ctx.branch : details.branch, candidate)) return null;
|
|
2915
|
+
var evaluated = evaluateAndCompare(ctx, evaluator, candidate, target, ctx.branch && ctx.branch.direction === -1 ? -1 : 1);
|
|
2916
|
+
if (!evaluated.valid) return null;
|
|
2917
|
+
var status = details.status || (details.exact ? "exact" : "approximate");
|
|
2918
|
+
var residual = evaluated.residual;
|
|
2919
|
+
var sufficientlyClose = residual && residual.kind === "number-absolute-relative" &&
|
|
2920
|
+
residual.relative !== null && residual.relative <= ctx.options.tol;
|
|
2921
|
+
if (evaluated.cmp !== 0 && !((status === "approximate") && sufficientlyClose)) return null;
|
|
2922
|
+
if ((status === "exact" || status === "minimal-reproducing" || status === "lower-bound") && evaluated.cmp !== 0) return null;
|
|
2923
|
+
var representationLevel = !!details.representationLevel || !!residual.representationLevel;
|
|
2924
|
+
var evidence = details.evidence || (representationLevel ? "representation-level" :
|
|
2925
|
+
(status === "exact" || status === "minimal-reproducing" ? "definition-guaranteed" : "numerical-experiment"));
|
|
2926
|
+
return finalizeInverseResult(ctx, {
|
|
2927
|
+
status: status,
|
|
2928
|
+
value: candidate,
|
|
2929
|
+
method: details.method || "analytic",
|
|
2930
|
+
residual: residual,
|
|
2931
|
+
termination: details.termination || (status === "approximate" ? "verified-approximation" : "verified-candidate"),
|
|
2932
|
+
message: details.message || "candidate verified by the public forward operation",
|
|
2933
|
+
evidence: evidence,
|
|
2934
|
+
multipleSolutions: details.multipleSolutions,
|
|
2935
|
+
representationLevel: representationLevel,
|
|
2936
|
+
legacyAnchor: details.legacyAnchor,
|
|
2937
|
+
minimalityAttained: details.minimalityAttained,
|
|
2938
|
+
encoding: details.encoding,
|
|
2939
|
+
loss: details.loss,
|
|
2940
|
+
provenance: details.provenance
|
|
2941
|
+
});
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
function tryVerifiedIntegerAnchor(ctx, evaluator, candidate, target) {
|
|
2945
|
+
var number = candidate instanceof MetaNum ? safeInverseNumber(candidate) : candidate;
|
|
2946
|
+
if (number === null || !isFinite(number)) return null;
|
|
2947
|
+
var nearest = Math.round(number);
|
|
2948
|
+
var radius = Math.max(ctx.options.tol * Math.max(1, Math.abs(number)), Number.EPSILON * Math.max(1, Math.abs(number)) * 4);
|
|
2949
|
+
if (Math.abs(number - nearest) > radius || !inverseBranchContains(ctx.branch, new MetaNum(nearest))) return null;
|
|
2950
|
+
var evaluated = evaluateAndCompare(ctx, evaluator, new MetaNum(nearest), target, 1);
|
|
2951
|
+
if (!evaluated.valid || evaluated.cmp !== 0) return null;
|
|
2952
|
+
var representation = !!evaluated.residual.representationLevel;
|
|
2953
|
+
var legacy = representation;
|
|
2954
|
+
return finalizeInverseResult(ctx, {
|
|
2955
|
+
status: legacy ? "approximate" : "exact",
|
|
2956
|
+
value: new MetaNum(nearest),
|
|
2957
|
+
method: "real-bracket",
|
|
2958
|
+
residual: evaluated.residual,
|
|
2959
|
+
termination: "verified-integer-anchor",
|
|
2960
|
+
message: legacy ? "verified legacy integer representative" : "verified exact integer anchor",
|
|
2961
|
+
evidence: legacy ? "representation-level" : "definition-guaranteed",
|
|
2962
|
+
multipleSolutions: representation,
|
|
2963
|
+
representationLevel: representation,
|
|
2964
|
+
legacyAnchor: legacy
|
|
2965
|
+
});
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
function analyzeInverseDomain(ctx, descriptor, direction, target, fixed, levelNumber) {
|
|
2969
|
+
var branch = direction === "log" ? descriptor.logDomain : descriptor.rootDomain;
|
|
2970
|
+
branch = {
|
|
2971
|
+
unknown: branch.unknown,
|
|
2972
|
+
lower: branch.lower,
|
|
2973
|
+
upper: branch.upper,
|
|
2974
|
+
lowerOpen: branch.lowerOpen,
|
|
2975
|
+
upperOpen: branch.upperOpen,
|
|
2976
|
+
direction: branch.direction,
|
|
2977
|
+
certificate: branch.certificate,
|
|
2978
|
+
initial: descriptor.initialBracket[direction].slice()
|
|
2979
|
+
};
|
|
2980
|
+
ctx.branch = branch;
|
|
2981
|
+
if (descriptor.forwardKind === "arrow" && (levelNumber === 0 || levelNumber === 1)) {
|
|
2982
|
+
branch.lower = null;
|
|
2983
|
+
branch.initial = null;
|
|
2984
|
+
return { branch: branch };
|
|
2985
|
+
}
|
|
2986
|
+
if (direction === "log") {
|
|
2987
|
+
if (fixed.lt(MetaNum.ONE)) {
|
|
2988
|
+
return { failure: inverseFailure(ctx, "unsupported-domain", "unsupported-base", "the principal high-level logarithm requires n > 1 or the degenerate n = 1 case") };
|
|
2989
|
+
}
|
|
2990
|
+
} else if (fixed.lt(MetaNum.ZERO)) {
|
|
2991
|
+
return { failure: inverseFailure(ctx, "unsupported-domain", "negative-height", "negative heights are outside the certified principal root branch") };
|
|
2992
|
+
}
|
|
2993
|
+
return { branch: branch };
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
function tryDegenerateInverse(ctx, descriptor, direction, target, fixed, levelNumber, evaluator) {
|
|
2997
|
+
function verified(candidate, status, flags) {
|
|
2998
|
+
flags = flags || {};
|
|
2999
|
+
flags.status = status;
|
|
3000
|
+
flags.method = "degenerate";
|
|
3001
|
+
flags.exact = status === "exact";
|
|
3002
|
+
flags.minimalityAttained = status === "minimal-reproducing" ? true : flags.minimalityAttained;
|
|
3003
|
+
var result = verifyInverseCandidate(ctx, evaluator, candidate, target, flags);
|
|
3004
|
+
return result || inverseFailure(ctx, "unrecoverable", "degenerate-verification-failed", "the degenerate candidate did not reproduce the target");
|
|
3005
|
+
}
|
|
3006
|
+
var isNamed = descriptor.forwardKind === "named";
|
|
3007
|
+
var highLevel = isNamed || levelNumber > 1;
|
|
3008
|
+
if (!isNamed && levelNumber === 0) {
|
|
3009
|
+
if ((direction === "log" && fixed.eq(MetaNum.ZERO)) || (direction === "root" && fixed.eq(MetaNum.ZERO))) {
|
|
3010
|
+
if (target.neq(MetaNum.ZERO)) return inverseFailure(ctx, "no-solution", "outside-image", "zero coefficient has a constant zero image");
|
|
3011
|
+
return inverseFailure(ctx, "unrecoverable", "unbounded-below", "all real unknowns reproduce zero; no finite minimum exists", { multipleSolutions: true });
|
|
3012
|
+
}
|
|
3013
|
+
return null;
|
|
3014
|
+
}
|
|
3015
|
+
if (!isNamed && levelNumber === 1) {
|
|
3016
|
+
if (direction === "log" && fixed.eq(MetaNum.ONE)) {
|
|
3017
|
+
if (target.neq(MetaNum.ONE)) return inverseFailure(ctx, "no-solution", "outside-image", "1^b is constantly 1");
|
|
3018
|
+
return inverseFailure(ctx, "unrecoverable", "unbounded-below", "all real heights reproduce 1; no finite minimum exists", { multipleSolutions: true });
|
|
3019
|
+
}
|
|
3020
|
+
if (direction === "root" && fixed.eq(MetaNum.ZERO)) {
|
|
3021
|
+
if (target.neq(MetaNum.ONE)) return inverseFailure(ctx, "no-solution", "outside-image", "a zero exponent has image 1 on the positive-base branch");
|
|
3022
|
+
return finalizeInverseResult(ctx, {
|
|
3023
|
+
status: "lower-bound", value: MetaNum.ZERO, method: "degenerate", termination: "open-infimum",
|
|
3024
|
+
message: "0 is the unattained infimum of positive bases", evidence: "definition-guaranteed",
|
|
3025
|
+
multipleSolutions: true, minimalityAttained: false
|
|
3026
|
+
});
|
|
3027
|
+
}
|
|
3028
|
+
return null;
|
|
3029
|
+
}
|
|
3030
|
+
if (!highLevel) return null;
|
|
3031
|
+
if (direction === "log") {
|
|
3032
|
+
if (fixed.eq(MetaNum.ONE)) {
|
|
3033
|
+
if (target.neq(MetaNum.ONE)) return inverseFailure(ctx, "no-solution", "constant-base", "base 1 has the constant image 1");
|
|
3034
|
+
return verified(isNamed ? MetaNum.ONE : MetaNum.ZERO, "minimal-reproducing", { multipleSolutions: true });
|
|
3035
|
+
}
|
|
3036
|
+
if (isNamed && descriptor.op === "aperiote" && target.eq(MetaNum.ZERO)) {
|
|
3037
|
+
return verified(MetaNum.ZERO, "exact", { branch: null });
|
|
3038
|
+
}
|
|
3039
|
+
var lowerImage = isNamed ? fixed : MetaNum.ONE;
|
|
3040
|
+
if (target.lt(lowerImage)) return inverseFailure(ctx, "no-solution", "below-branch-image", "target lies below the principal branch image");
|
|
3041
|
+
if (target.eq(MetaNum.ONE) && !isNamed) return verified(MetaNum.ZERO, "exact");
|
|
3042
|
+
if (target.eq(fixed)) return verified(MetaNum.ONE, "exact");
|
|
3043
|
+
if (fixed.eq(MetaNum.TWO) && target.eq(4)) return verified(MetaNum.TWO, "exact");
|
|
3044
|
+
} else {
|
|
3045
|
+
if (fixed.eq(MetaNum.ZERO)) {
|
|
3046
|
+
if (isNamed) return inverseFailure(ctx, "unsupported-domain", "zero-height", "zero height is outside the named principal root branch");
|
|
3047
|
+
if (target.neq(MetaNum.ONE)) return inverseFailure(ctx, "no-solution", "outside-image", "zero height has the constant image 1");
|
|
3048
|
+
return verified(MetaNum.ONE, "minimal-reproducing", { multipleSolutions: true });
|
|
3049
|
+
}
|
|
3050
|
+
if (fixed.eq(MetaNum.ONE)) {
|
|
3051
|
+
if (target.lt(MetaNum.ONE)) return inverseFailure(ctx, "no-solution", "below-branch-image", "height 1 maps the principal base branch to n >= 1");
|
|
3052
|
+
if (target.eq(MetaNum.ONE)) return verified(MetaNum.ONE, "minimal-reproducing", { multipleSolutions: true, branch: null });
|
|
3053
|
+
return verified(target, "exact", { branch: null });
|
|
3054
|
+
}
|
|
3055
|
+
if (target.lt(MetaNum.ONE)) return inverseFailure(ctx, "no-solution", "below-branch-image", "principal high-level roots are at least 1");
|
|
3056
|
+
if (target.eq(MetaNum.ONE)) return verified(MetaNum.ONE, "minimal-reproducing", { multipleSolutions: true, branch: null });
|
|
3057
|
+
if (fixed.eq(MetaNum.TWO) && target.eq(4)) return verified(MetaNum.TWO, "exact");
|
|
3058
|
+
}
|
|
3059
|
+
return null;
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
function tryAnalyticInverse(ctx, direction, target, fixed, levelNumber, evaluator) {
|
|
3063
|
+
if (levelNumber !== 0 && levelNumber !== 1) return null;
|
|
3064
|
+
var candidate;
|
|
3065
|
+
if (levelNumber === 0) {
|
|
3066
|
+
candidate = target.div(fixed);
|
|
3067
|
+
var multiplied = verifyInverseCandidate(ctx, evaluator, candidate, target, {
|
|
3068
|
+
branch: null, exact: true, method: "analytic", evidence: "definition-guaranteed"
|
|
3069
|
+
});
|
|
3070
|
+
return multiplied || inverseFailure(ctx, "unrepresentable", "analytic-verification-failed", "the multiplicative inverse candidate is not faithfully representable");
|
|
3071
|
+
}
|
|
3072
|
+
if (direction === "log") {
|
|
3073
|
+
if (fixed.lte(MetaNum.ZERO) || fixed.eq(MetaNum.ONE)) {
|
|
3074
|
+
return inverseFailure(ctx, "unsupported-domain", "invalid-log-base", "the analytic exponential logarithm requires n > 0 and n != 1");
|
|
3075
|
+
}
|
|
3076
|
+
if (target.lte(MetaNum.ZERO)) return inverseFailure(ctx, "no-solution", "outside-image", "a real exponential image is positive");
|
|
3077
|
+
candidate = target.logBase(fixed);
|
|
3078
|
+
var logarithm = verifyInverseCandidate(ctx, evaluator, candidate, target, {
|
|
3079
|
+
branch: null, exact: candidate.isint(), method: "analytic"
|
|
3080
|
+
});
|
|
3081
|
+
return logarithm || inverseFailure(ctx, "unrecoverable", "analytic-verification-failed", "the logarithm candidate failed forward verification");
|
|
3082
|
+
}
|
|
3083
|
+
var exponent = safeInverseNumber(fixed);
|
|
3084
|
+
var integerExponent = exponent !== null && Number.isInteger(exponent);
|
|
3085
|
+
if (target.lt(MetaNum.ZERO) && (!integerExponent || Math.abs(exponent) % 2 !== 1)) {
|
|
3086
|
+
return inverseFailure(ctx, "no-solution", "outside-real-image", "a negative target requires an odd integer exponent");
|
|
3087
|
+
}
|
|
3088
|
+
if (target.eq(MetaNum.ZERO)) {
|
|
3089
|
+
if (integerExponent && exponent > 0) {
|
|
3090
|
+
return verifyInverseCandidate(ctx, evaluator, MetaNum.ZERO, target, { branch: null, exact: true, method: "analytic" });
|
|
3091
|
+
}
|
|
3092
|
+
if (integerExponent && exponent < 0) {
|
|
3093
|
+
return inverseFailure(ctx, "no-solution", "zero-negative-exponent", "zero has no real negative-integer power");
|
|
3094
|
+
}
|
|
3095
|
+
if (fixed.gt(MetaNum.ZERO)) {
|
|
3096
|
+
return finalizeInverseResult(ctx, {
|
|
3097
|
+
status: "lower-bound", value: MetaNum.ZERO, method: "analytic", termination: "open-infimum",
|
|
3098
|
+
message: "0 is the unattained positive-base infimum", evidence: "definition-guaranteed", minimalityAttained: false
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
return inverseFailure(ctx, "no-solution", "outside-image", "zero is not in the image for this exponent");
|
|
3102
|
+
}
|
|
3103
|
+
if (target.gt(MetaNum.ZERO)) candidate = target.pow(fixed.rec());
|
|
3104
|
+
else candidate = target.abs().pow(fixed.rec()).neg();
|
|
3105
|
+
if (candidate.eq(MetaNum.ZERO)) {
|
|
3106
|
+
return inverseFailure(ctx, "unrepresentable", "underflow", "a nonzero analytic root underflowed to zero");
|
|
3107
|
+
}
|
|
3108
|
+
var root = verifyInverseCandidate(ctx, evaluator, candidate, target, {
|
|
3109
|
+
branch: null,
|
|
3110
|
+
exact: candidate.isint(),
|
|
3111
|
+
method: "analytic",
|
|
3112
|
+
multipleSolutions: integerExponent && exponent % 2 === 0 && target.gt(MetaNum.ZERO)
|
|
3113
|
+
});
|
|
3114
|
+
return root || inverseFailure(ctx, "unrecoverable", "analytic-verification-failed", "the power-root candidate failed forward verification");
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
function tryStructuralInverse(ctx, descriptor, target, fixed, evaluator) {
|
|
3118
|
+
if (ctx.direction !== "log" || descriptor.forwardKind !== "named") return null;
|
|
3119
|
+
if (descriptor.markerPolicy === "epsilon-fraction" && target.layer >= 1) {
|
|
3120
|
+
var matched = false;
|
|
3121
|
+
var fsOffset = 1; // old form: y = layer + 1 + fraction
|
|
3122
|
+
for (var ei = 1; ei < target.array.length; ei++) {
|
|
3123
|
+
var er = target.array[ei];
|
|
3124
|
+
if (er.length === 3 && er[0] === 1 && er[2] === 1 && (er[1] || 0) >= 2) matched = true;
|
|
3125
|
+
// 5c form: the ω³ row [1,0,0,0,1] at layer (y-2) — y = layer + 2 + fraction
|
|
3126
|
+
if (er.length === 5 && er[0] === 1 && er[1] === 0 && er[2] === 0 && er[3] === 0 && er[4] === 1) {
|
|
3127
|
+
matched = true;
|
|
3128
|
+
fsOffset = 2;
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
if (matched) {
|
|
3132
|
+
var fraction = 0;
|
|
3133
|
+
if (target.array[0].length === 1 && isFinite(target.array[0][0])) {
|
|
3134
|
+
var stored = target.array[0][0];
|
|
3135
|
+
// 5c form: the fraction sits in r0[0] ∈ [0,1) directly; the legacy
|
|
3136
|
+
// y∈(2,3) form keeps it as 10+f
|
|
3137
|
+
if (stored > 0 && stored < 1) fraction = stored;
|
|
3138
|
+
else {
|
|
3139
|
+
var storedFraction = stored - 10;
|
|
3140
|
+
if (storedFraction >= 0 && storedFraction < 1) fraction = storedFraction;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
// the forward caps the ε-tower at layer MSI-1 for every height >= MSI
|
|
3144
|
+
// (P.epsilonate: metaFiniteCount(y) <= MSI keeps m = floor(y) = MSI, and
|
|
3145
|
+
// anything larger stores the same marker), so layer+fsOffset >= MSI can
|
|
3146
|
+
// only be reported as a lower bound — never as an exact structural recovery.
|
|
3147
|
+
var capped = target.layer + fsOffset >= MAX_SAFE_INTEGER;
|
|
3148
|
+
var epsilonCandidate = new MetaNum(target.layer + fsOffset + fraction);
|
|
3149
|
+
var epsilonResult = verifyInverseCandidate(ctx, evaluator, epsilonCandidate, target, {
|
|
3150
|
+
status: capped ? "lower-bound" : fraction > 0 ? "approximate" : "exact",
|
|
3151
|
+
method: "structural",
|
|
3152
|
+
encoding: "epsilon-layer",
|
|
3153
|
+
loss: capped ? "capped" : "fraction-preserved",
|
|
3154
|
+
representationLevel: capped || fraction > 0,
|
|
3155
|
+
legacyAnchor: capped,
|
|
3156
|
+
minimalityAttained: capped ? false : null,
|
|
3157
|
+
evidence: capped || fraction > 0 ? "representation-level" : "definition-guaranteed"
|
|
3158
|
+
});
|
|
3159
|
+
if (epsilonResult) return epsilonResult;
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
if (typeof descriptor.structuralDecoder !== "function") return null;
|
|
3163
|
+
var candidate;
|
|
3164
|
+
try {
|
|
3165
|
+
candidate = descriptor.structuralDecoder.call(target.clone(), fixed.clone());
|
|
3166
|
+
} catch (e) {
|
|
3167
|
+
return null;
|
|
3168
|
+
}
|
|
3169
|
+
if (!(candidate instanceof MetaNum) || candidate.isNaN() || !candidate.isFinite()) return null;
|
|
3170
|
+
var high = descriptor.rootDomain.lower === 2;
|
|
3171
|
+
var legacy = high || candidate.eq(fixed);
|
|
3172
|
+
return verifyInverseCandidate(ctx, evaluator, candidate, target, {
|
|
3173
|
+
status: legacy ? "approximate" : "exact",
|
|
3174
|
+
method: "structural",
|
|
3175
|
+
encoding: high ? descriptor.markerPolicy : "complete",
|
|
3176
|
+
loss: high ? descriptor.markerPolicy : "none",
|
|
3177
|
+
representationLevel: legacy,
|
|
3178
|
+
legacyAnchor: legacy,
|
|
3179
|
+
evidence: legacy ? "representation-level" : "definition-guaranteed",
|
|
3180
|
+
multipleSolutions: legacy,
|
|
3181
|
+
provenance: "legacy-structural-decoder"
|
|
3182
|
+
});
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
function buildInitialBracket(ctx, evaluator, target, branch) {
|
|
3186
|
+
var lo = branch.initial[0], hi = branch.initial[1];
|
|
3187
|
+
var loEval = evaluateAndCompare(ctx, evaluator, lo, target, branch.direction);
|
|
3188
|
+
var hiEval = evaluateAndCompare(ctx, evaluator, hi, target, branch.direction);
|
|
3189
|
+
return { lo: lo, hi: hi, loEval: loEval, hiEval: hiEval, coordinate: "number" };
|
|
3190
|
+
}
|
|
3191
|
+
|
|
3192
|
+
function expandBracket(ctx, evaluator, target, branch, bracket) {
|
|
3193
|
+
var lo = bracket.lo, hi = bracket.hi;
|
|
3194
|
+
var loEval = bracket.loEval, hiEval = bracket.hiEval;
|
|
3195
|
+
if (!loEval.valid || !hiEval.valid) return { failure: "bracketing-failed", termination: "invalid-forward-point", bracket: bracket };
|
|
3196
|
+
if (loEval.cmp === 0) return { endpoint: loEval, bracket: bracket };
|
|
3197
|
+
if (hiEval.cmp === 0) return { endpoint: hiEval, bracket: bracket };
|
|
3198
|
+
for (var expansion = 0; expansion < ctx.options.maxBracketExpansions; expansion++) {
|
|
3199
|
+
bracket.lo = lo; bracket.hi = hi; bracket.loEval = loEval; bracket.hiEval = hiEval;
|
|
3200
|
+
bracket.loCmp = loEval.cmp; bracket.hiCmp = hiEval.cmp;
|
|
3201
|
+
if (loEval.side < 0 && hiEval.side > 0) return { bracket: bracket };
|
|
3202
|
+
if (loEval.side > 0 && hiEval.side > 0) {
|
|
3203
|
+
return { failure: "no-solution", termination: "below-branch-image", bracket: bracket };
|
|
3204
|
+
}
|
|
3205
|
+
if (!(loEval.side < 0 && hiEval.side < 0)) {
|
|
3206
|
+
return { failure: "bracketing-failed", termination: "non-monotone", bracket: bracket };
|
|
3207
|
+
}
|
|
3208
|
+
lo = hi; loEval = hiEval;
|
|
3209
|
+
var oldHi = hi, newHi;
|
|
3210
|
+
if (bracket.coordinate === "number") {
|
|
3211
|
+
if (oldHi > Number.MAX_VALUE / 2) {
|
|
3212
|
+
bracket.coordinate = "metanum";
|
|
3213
|
+
lo = new MetaNum(lo);
|
|
3214
|
+
hi = new MetaNum(oldHi);
|
|
3215
|
+
newHi = hi.mul(2);
|
|
3216
|
+
} else {
|
|
3217
|
+
newHi = oldHi === 0 ? 1 : oldHi * 2;
|
|
3218
|
+
if (!isFinite(newHi) || newHi <= oldHi) {
|
|
3219
|
+
return { failure: "bracketing-failed", termination: "expansion-stagnated", bracket: bracket };
|
|
3220
|
+
}
|
|
3221
|
+
hi = newHi;
|
|
3222
|
+
}
|
|
3223
|
+
} else newHi = hi.mul(2);
|
|
3224
|
+
if (bracket.coordinate === "metanum") {
|
|
3225
|
+
if (!(newHi instanceof MetaNum) || newHi.isNaN() || !newHi.isFinite() || !newHi.gt(hi)) {
|
|
3226
|
+
return { failure: "unrepresentable", termination: "representation-ceiling", bracket: bracket };
|
|
3227
|
+
}
|
|
3228
|
+
hi = newHi;
|
|
3229
|
+
}
|
|
3230
|
+
ctx.expansions++;
|
|
3231
|
+
hiEval = evaluateAndCompare(ctx, evaluator, hi, target, branch.direction);
|
|
3232
|
+
if (!hiEval.valid) return { failure: "bracketing-failed", termination: "invalid-forward-point", bracket: bracket };
|
|
3233
|
+
if (hiEval.cmp === 0) {
|
|
3234
|
+
bracket.lo = lo; bracket.hi = hi; bracket.loEval = loEval; bracket.hiEval = hiEval;
|
|
3235
|
+
bracket.loCmp = loEval.cmp; bracket.hiCmp = hiEval.cmp;
|
|
3236
|
+
return { endpoint: hiEval, bracket: bracket };
|
|
3237
|
+
}
|
|
3238
|
+
if (loEval.side < 0 && hiEval.side > 0) {
|
|
3239
|
+
bracket.lo = lo; bracket.hi = hi; bracket.loEval = loEval; bracket.hiEval = hiEval;
|
|
3240
|
+
bracket.loCmp = loEval.cmp; bracket.hiCmp = hiEval.cmp;
|
|
3241
|
+
return { bracket: bracket };
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
bracket.lo = lo; bracket.hi = hi; bracket.loEval = loEval; bracket.hiEval = hiEval;
|
|
3245
|
+
bracket.loCmp = loEval.cmp; bracket.hiCmp = hiEval.cmp;
|
|
3246
|
+
return { failure: "bracketing-failed", termination: "expansion-budget-exhausted", bracket: bracket };
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
function inverseMidpoint(lo, hi, coordinate) {
|
|
3250
|
+
if (coordinate === "metanum") return lo.add(hi).div(2);
|
|
3251
|
+
if ((lo >= 0 && hi >= 0) || (lo <= 0 && hi <= 0)) return lo + (hi - lo) / 2;
|
|
3252
|
+
return lo / 2 + hi / 2;
|
|
3253
|
+
}
|
|
3254
|
+
|
|
3255
|
+
function solveRealBracket(ctx, evaluator, target, branch) {
|
|
3256
|
+
var built = buildInitialBracket(ctx, evaluator, target, branch);
|
|
3257
|
+
var expanded = expandBracket(ctx, evaluator, target, branch, built);
|
|
3258
|
+
ctx.bracket = expanded.bracket || built;
|
|
3259
|
+
if (expanded.failure) {
|
|
3260
|
+
return inverseFailure(ctx, expanded.failure, expanded.termination, expanded.termination);
|
|
3261
|
+
}
|
|
3262
|
+
if (expanded.endpoint) {
|
|
3263
|
+
var endpointResult = tryVerifiedIntegerAnchor(ctx, evaluator, expanded.endpoint.x, target);
|
|
3264
|
+
if (endpointResult) return endpointResult;
|
|
3265
|
+
return verifyInverseCandidate(ctx, evaluator, expanded.endpoint.x, target, {
|
|
3266
|
+
status: "approximate", method: "real-bracket", representationLevel: true,
|
|
3267
|
+
termination: "reproducing-endpoint"
|
|
3268
|
+
}) || inverseFailure(ctx, "unrecoverable", "endpoint-verification-failed", "the reproducing endpoint was not accepted");
|
|
3269
|
+
}
|
|
3270
|
+
var bracket = expanded.bracket;
|
|
3271
|
+
ctx.bracket = bracket;
|
|
3272
|
+
var lo = bracket.lo, hi = bracket.hi, loEval = bracket.loEval, hiEval = bracket.hiEval;
|
|
3273
|
+
var previous = null, lastCandidate = null, slowAcceleration = 0, forceBisection = false;
|
|
3274
|
+
for (var iteration = 0; iteration < ctx.options.maxIterations; iteration++) {
|
|
3275
|
+
ctx.iterations = iteration + 1;
|
|
3276
|
+
var midpoint = inverseMidpoint(lo, hi, bracket.coordinate);
|
|
3277
|
+
var midpointInside = bracket.coordinate === "number" ? midpoint > lo && midpoint < hi : midpoint.gt(lo) && midpoint.lt(hi);
|
|
3278
|
+
if (!midpointInside) {
|
|
3279
|
+
var stagnant = loEval.cmp === 0 ? loEval : hiEval.cmp === 0 ? hiEval : null;
|
|
3280
|
+
if (stagnant) {
|
|
3281
|
+
return finalizeInverseResult(ctx, {
|
|
3282
|
+
status: "approximate", value: new MetaNum(stagnant.x), method: "real-bracket", residual: stagnant.residual,
|
|
3283
|
+
termination: "stagnated", message: "representation resolution reached with a reproducing endpoint",
|
|
3284
|
+
evidence: "representation-level", representationLevel: true
|
|
3285
|
+
});
|
|
3286
|
+
}
|
|
3287
|
+
return inverseFailure(ctx, "stagnated", "midpoint-not-interior", "the bracket midpoint reached representation resolution");
|
|
3288
|
+
}
|
|
3289
|
+
var candidate = midpoint, usedAcceleration = false, fallback = forceBisection;
|
|
3290
|
+
if (ctx.options.acceleration === "auto" && !forceBisection && bracket.coordinate === "number") {
|
|
3291
|
+
var lv = safeInverseNumber(loEval.value), hv = safeInverseNumber(hiEval.value), tv = safeInverseNumber(target);
|
|
3292
|
+
if (lv !== null && hv !== null && tv !== null && hv !== lv) {
|
|
3293
|
+
var secant = lo + (tv - lv) * (hi - lo) / (hv - lv);
|
|
3294
|
+
if (isFinite(secant) && secant > lo && secant < hi && secant !== lastCandidate) {
|
|
3295
|
+
candidate = secant;
|
|
3296
|
+
usedAcceleration = true;
|
|
3297
|
+
} else fallback = true;
|
|
3298
|
+
} else fallback = true;
|
|
3299
|
+
} else if (ctx.options.acceleration === "auto" && !forceBisection) fallback = true;
|
|
3300
|
+
if (fallback) ctx.fallbackCount++;
|
|
3301
|
+
forceBisection = false;
|
|
3302
|
+
var evaluated = evaluateAndCompare(ctx, evaluator, candidate, target, branch.direction);
|
|
3303
|
+
if (!evaluated.valid) return inverseFailure(ctx, "bracketing-failed", "invalid-forward-point", "forward evaluation produced NaN or an incomparable value");
|
|
3304
|
+
if (usedAcceleration) {
|
|
3305
|
+
var ar = safeInverseNumber(evaluated.value), lr = safeInverseNumber(loEval.value), hr = safeInverseNumber(hiEval.value), tr = safeInverseNumber(target);
|
|
3306
|
+
if (ar !== null && lr !== null && hr !== null && tr !== null &&
|
|
3307
|
+
Math.abs(ar - tr) > Math.max(Math.abs(lr - tr), Math.abs(hr - tr))) {
|
|
3308
|
+
candidate = midpoint;
|
|
3309
|
+
usedAcceleration = false;
|
|
3310
|
+
ctx.fallbackCount++;
|
|
3311
|
+
evaluated = evaluateAndCompare(ctx, evaluator, candidate, target, branch.direction);
|
|
3312
|
+
if (!evaluated.valid) return inverseFailure(ctx, "bracketing-failed", "invalid-forward-point", "fallback forward evaluation failed");
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
var anchor = tryVerifiedIntegerAnchor(ctx, evaluator, candidate, target);
|
|
3316
|
+
if (anchor) return anchor;
|
|
3317
|
+
var oldWidth = bracket.coordinate === "number" ? hi - lo : null;
|
|
3318
|
+
if (evaluated.side < 0) {
|
|
3319
|
+
lo = candidate; loEval = evaluated;
|
|
3320
|
+
} else {
|
|
3321
|
+
hi = candidate; hiEval = evaluated;
|
|
3322
|
+
}
|
|
3323
|
+
bracket.lo = lo; bracket.hi = hi; bracket.loEval = loEval; bracket.hiEval = hiEval;
|
|
3324
|
+
bracket.loCmp = loEval.cmp; bracket.hiCmp = hiEval.cmp;
|
|
3325
|
+
if (usedAcceleration && oldWidth !== null) {
|
|
3326
|
+
var newWidth = hi - lo;
|
|
3327
|
+
if (newWidth > oldWidth / 2) slowAcceleration++; else slowAcceleration = 0;
|
|
3328
|
+
if (slowAcceleration >= 2) {
|
|
3329
|
+
forceBisection = true;
|
|
3330
|
+
slowAcceleration = 0;
|
|
3331
|
+
}
|
|
3332
|
+
} else slowAcceleration = 0;
|
|
3333
|
+
var stepOk = false;
|
|
3334
|
+
if (bracket.coordinate === "number") {
|
|
3335
|
+
var width = hi - lo;
|
|
3336
|
+
var step = previous === null ? Infinity : Math.abs(candidate - previous);
|
|
3337
|
+
stepOk = step <= ctx.options.tol * Math.max(1, Math.abs(candidate)) ||
|
|
3338
|
+
width <= 2 * ctx.options.tol * Math.max(1, Math.abs(candidate));
|
|
3339
|
+
} else {
|
|
3340
|
+
var metaWidth = hi.sub(lo);
|
|
3341
|
+
var toleranceWidth = candidate.abs().max(MetaNum.ONE).mul(2 * ctx.options.tol);
|
|
3342
|
+
stepOk = metaWidth.lte(toleranceWidth);
|
|
3343
|
+
}
|
|
3344
|
+
var residualOk = evaluated.cmp === 0 || (evaluated.residual &&
|
|
3345
|
+
evaluated.residual.kind === "number-absolute-relative" &&
|
|
3346
|
+
evaluated.residual.relative !== null && evaluated.residual.relative <= ctx.options.tol);
|
|
3347
|
+
if (stepOk && residualOk) {
|
|
3348
|
+
return finalizeInverseResult(ctx, {
|
|
3349
|
+
status: "approximate", value: new MetaNum(candidate), method: "real-bracket", residual: evaluated.residual,
|
|
3350
|
+
termination: "converged", message: "solution-space and forward-residual criteria satisfied",
|
|
3351
|
+
evidence: evaluated.residual.representationLevel ? "representation-level" : "numerical-experiment",
|
|
3352
|
+
representationLevel: !!evaluated.residual.representationLevel
|
|
3353
|
+
});
|
|
3354
|
+
}
|
|
3355
|
+
previous = candidate;
|
|
3356
|
+
lastCandidate = candidate;
|
|
3357
|
+
}
|
|
3358
|
+
ctx.iterations = ctx.options.maxIterations;
|
|
3359
|
+
return inverseFailure(ctx, "non-converged", "iteration-budget-exhausted", "the real solver exhausted maxIterations without convergence evidence");
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
// The public constructor maps an unparseable token to 0 (existing behaviour,
|
|
3363
|
+
// unchanged). The inverse must not solve that silent 0 as if the caller had
|
|
3364
|
+
// passed the number 0: a non-empty string that constructs to 0 without being
|
|
3365
|
+
// a zero literal is reported as invalid-input.
|
|
3366
|
+
var INVERSE_ZERO_LITERAL = /^[+-]?(?:0+(?:\.0*)?|\.0+)(?:[eE][+-]?\d+)?$/;
|
|
3367
|
+
function inverseStringInputInvalid(input, constructed) {
|
|
3368
|
+
if (typeof input !== "string" || !(constructed instanceof MetaNum)) return false;
|
|
3369
|
+
if (constructed.isNaN()) return false;
|
|
3370
|
+
var text = input.trim();
|
|
3371
|
+
if (text === "") return true;
|
|
3372
|
+
return constructed.eq(MetaNum.ZERO) && !INVERSE_ZERO_LITERAL.test(text);
|
|
3373
|
+
}
|
|
3374
|
+
|
|
3375
|
+
function dispatchInverse(target, fixed, level, descriptor, direction, optionsInput) {
|
|
3376
|
+
var diagnostics = !!(optionsInput && optionsInput.diagnostics === true);
|
|
3377
|
+
var normalized = normalizeInverseOptions(optionsInput);
|
|
3378
|
+
var c, f, lev = null;
|
|
3379
|
+
try { c = new MetaNum(target); } catch (e) { c = MetaNum.NaN.clone(); }
|
|
3380
|
+
try { f = new MetaNum(fixed); } catch (e) { f = MetaNum.NaN.clone(); }
|
|
3381
|
+
var levelNumber = null;
|
|
3382
|
+
if (!descriptor) {
|
|
3383
|
+
try { lev = new MetaNum(level); } catch (e) { lev = MetaNum.NaN.clone(); }
|
|
3384
|
+
levelNumber = safeInverseNumber(lev);
|
|
3385
|
+
descriptor = createArrowDescriptor(lev, lev.toString());
|
|
3386
|
+
} else descriptor = getOperationDescriptor(descriptor);
|
|
3387
|
+
var levelText = descriptor ? descriptor.levelText : lev === null ? "unknown" : lev.toString();
|
|
3388
|
+
var ctx = createInverseContext(direction, descriptor, levelText, normalized);
|
|
3389
|
+
if (normalized.error) return exposeInverseResult(inverseFailure(ctx, "invalid-input", "invalid-options", normalized.error), diagnostics);
|
|
3390
|
+
if (!descriptor) return exposeInverseResult(inverseFailure(ctx, "invalid-level", "unknown-operation", "unknown operation descriptor"), diagnostics);
|
|
3391
|
+
if (c.isNaN() || f.isNaN() || (lev && lev.isNaN())) {
|
|
3392
|
+
return exposeInverseResult(inverseFailure(ctx, "invalid-input", "nan-input", "inverse inputs must not be NaN"), diagnostics);
|
|
3393
|
+
}
|
|
3394
|
+
if (inverseStringInputInvalid(target, c) || inverseStringInputInvalid(fixed, f) || (lev && inverseStringInputInvalid(level, lev))) {
|
|
3395
|
+
return exposeInverseResult(inverseFailure(ctx, "invalid-input", "unparseable-input", "a string input is not a parsable number"), diagnostics);
|
|
3396
|
+
}
|
|
3397
|
+
if (!c.isFinite() || !f.isFinite() || (lev && !lev.isFinite())) {
|
|
3398
|
+
return exposeInverseResult(inverseFailure(ctx, "non-finite-input", "infinite-input", "inverse inputs must be finite"), diagnostics);
|
|
3399
|
+
}
|
|
3400
|
+
if (!descriptor || descriptor.forwardKind !== "arrow" && !getOperationDescriptor(descriptor.op)) {
|
|
3401
|
+
return exposeInverseResult(inverseFailure(ctx, "invalid-level", "unknown-operation", "unknown operation"), diagnostics);
|
|
3402
|
+
}
|
|
3403
|
+
if (descriptor.forwardKind === "arrow") {
|
|
3404
|
+
if (levelNumber === null || levelNumber < 0 || (!Number.isInteger(levelNumber) && levelNumber < 1)) {
|
|
3405
|
+
return exposeInverseResult(inverseFailure(ctx, "invalid-level", "unsupported-level", "arrow inverse level must be a supported nonnegative finite real"), diagnostics);
|
|
3406
|
+
}
|
|
3407
|
+
descriptor.level = lev.clone();
|
|
3408
|
+
descriptor.levelText = String(levelNumber);
|
|
3409
|
+
ctx.levelText = descriptor.levelText;
|
|
3410
|
+
}
|
|
3411
|
+
var evaluator = makeForwardEvaluator(descriptor, direction, f, ctx);
|
|
3412
|
+
var domain = analyzeInverseDomain(ctx, descriptor, direction, c, f, levelNumber);
|
|
3413
|
+
if (domain.failure) return exposeInverseResult(domain.failure, diagnostics);
|
|
3414
|
+
var degenerate = tryDegenerateInverse(ctx, descriptor, direction, c, f, levelNumber, evaluator);
|
|
3415
|
+
if (degenerate) return exposeInverseResult(degenerate, diagnostics);
|
|
3416
|
+
var analytic = tryAnalyticInverse(ctx, direction, c, f, levelNumber, evaluator);
|
|
3417
|
+
if (analytic) return exposeInverseResult(analytic, diagnostics);
|
|
3418
|
+
var structural = tryStructuralInverse(ctx, descriptor, c, f, evaluator);
|
|
3419
|
+
if (structural) return exposeInverseResult(structural, diagnostics);
|
|
3420
|
+
if (descriptor.forwardKind === "named" && direction === "root" && descriptor.rootDomain.lower === 2) {
|
|
3421
|
+
var twoEvaluation = evaluateAndCompare(ctx, evaluator, MetaNum.TWO, c, 1);
|
|
3422
|
+
if (twoEvaluation.valid && twoEvaluation.cmp === 0) {
|
|
3423
|
+
return exposeInverseResult(finalizeInverseResult(ctx, {
|
|
3424
|
+
status: "minimal-reproducing", value: MetaNum.TWO, method: "degenerate", residual: twoEvaluation.residual,
|
|
3425
|
+
termination: "minimum-on-n>=2-branch", message: "2 is the minimum of the declared n >= 2 reproducing branch",
|
|
3426
|
+
evidence: "definition-guaranteed", representationLevel: true, minimalityAttained: true,
|
|
3427
|
+
multipleSolutions: true
|
|
3428
|
+
}), diagnostics);
|
|
3429
|
+
}
|
|
3430
|
+
|
|
3431
|
+
return exposeInverseResult(inverseFailure(ctx, "unrecoverable", "base-independent-marker", "the target does not carry a recoverable base on the n >= 2 branch"), diagnostics);
|
|
3432
|
+
}
|
|
3433
|
+
var result = solveRealBracket(ctx, evaluator, c, ctx.branch);
|
|
3434
|
+
return exposeInverseResult(result, diagnostics);
|
|
3435
|
+
}
|
|
3436
|
+
|
|
3437
|
+
// Static forms receive the raw target before it is constructed: an unparseable
|
|
3438
|
+
// target string is rejected here (the instance form has already lost that
|
|
3439
|
+
// information when the receiver was constructed).
|
|
3440
|
+
function inverseStaticTargetRejected(x, direction, options) {
|
|
3441
|
+
if (typeof x !== "string") return null;
|
|
3442
|
+
var constructed;
|
|
3443
|
+
try { constructed = new MetaNum(x); } catch (e) { return null; }
|
|
3444
|
+
if (!inverseStringInputInvalid(x, constructed)) return null;
|
|
3445
|
+
var ctx = createInverseContext(direction, null, "unknown", normalizeInverseOptions(options));
|
|
3446
|
+
return exposeInverseResult(inverseFailure(ctx, "invalid-input", "unparseable-input", "the target string is not a parsable number"),
|
|
3447
|
+
!!(options && options.diagnostics === true));
|
|
3448
|
+
}
|
|
3449
|
+
|
|
3450
|
+
P.hyper_log = function (a) {
|
|
3451
|
+
var d = this.clone();
|
|
3452
|
+
return function (b, options) {
|
|
3453
|
+
return dispatchInverse(d, a, b, null, "log", options);
|
|
2518
3454
|
};
|
|
2519
3455
|
};
|
|
2520
|
-
Q.hyper_log = function (d, a, b) {
|
|
2521
|
-
|
|
3456
|
+
Q.hyper_log = function (d, a, b, options) {
|
|
3457
|
+
var rejected = inverseStaticTargetRejected(d, "log", options);
|
|
3458
|
+
if (rejected) return rejected;
|
|
3459
|
+
return new MetaNum(d).hyper_log(a)(b, options);
|
|
2522
3460
|
};
|
|
2523
3461
|
|
|
2524
3462
|
P.hyper_root = function (c) {
|
|
2525
3463
|
var d = this.clone();
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
b = new MetaNum(b);
|
|
2529
|
-
if (b.lt(MetaNum.ZERO) || d.lte(MetaNum.ZERO) || c.lte(MetaNum.ZERO)) {
|
|
2530
|
-
return MetaNum.NaN.clone();
|
|
2531
|
-
}
|
|
2532
|
-
if (b.eq(MetaNum.ZERO)) return d.div(c); // a·c = d
|
|
2533
|
-
if (c.eq(MetaNum.ONE)) return d.clone(); // a{b}1 = a
|
|
2534
|
-
return hyperBisect(function (x) { return x.arrow(b)(c); }, d, 200);
|
|
3464
|
+
return function (b, options) {
|
|
3465
|
+
return dispatchInverse(d, c, b, null, "root", options);
|
|
2535
3466
|
};
|
|
2536
3467
|
};
|
|
2537
|
-
Q.hyper_root = function (d, c, b) {
|
|
2538
|
-
|
|
3468
|
+
Q.hyper_root = function (d, c, b, options) {
|
|
3469
|
+
var rejected = inverseStaticTargetRejected(d, "root", options);
|
|
3470
|
+
if (rejected) return rejected;
|
|
3471
|
+
return new MetaNum(d).hyper_root(c)(b, options);
|
|
2539
3472
|
};
|
|
2540
3473
|
Q.chain = function (x, y, arrows) {
|
|
2541
3474
|
return new MetaNum(x).arrow(arrows)(y);
|
|
2542
3475
|
};
|
|
2543
3476
|
|
|
3477
|
+
// ==================== ordinal-level root inverses ====================
|
|
3478
|
+
// Root form of the ordinal-level hyperoperations — the {α}root analogue of
|
|
3479
|
+
// the inv_* log family: if a{α}b = c then c.<op>_root(b) = a, mirroring
|
|
3480
|
+
// c.i_<op>(a) = b. E.g. (10{ω}15).aperiote_root(15) = 10 just like
|
|
3481
|
+
// (10{ω}15).i_aper(10) = 15. The base map a ↦ a{α}b is monotone
|
|
3482
|
+
// nondecreasing (README rules 1-4), so the base is recovered by the same
|
|
3483
|
+
// integer bisection hyper_root uses at the finite levels: the smallest
|
|
3484
|
+
// base a with a{α}b ≥ c. Beyond the representation budget the stored
|
|
3485
|
+
// value no longer encodes the base (y ≥ MSI anchors at the huge-argument
|
|
3486
|
+
// marker; the layer markers of the ω^ω+ levels are base-independent), so
|
|
3487
|
+
// the root returns the smallest base reproducing the stored value — the
|
|
3488
|
+
// same convention hyper_root documents for the finite levels.
|
|
3489
|
+
function ordinalHyperRoot(c, y, descriptor, options) {
|
|
3490
|
+
return dispatchInverse(c, y, null, descriptor, "root", options);
|
|
3491
|
+
}
|
|
3492
|
+
function defineHyperRoot(descriptor) {
|
|
3493
|
+
descriptor.rootNames.forEach(function (name) {
|
|
3494
|
+
P[name] = function (y, options) {
|
|
3495
|
+
return ordinalHyperRoot(this, y, descriptor, options);
|
|
3496
|
+
};
|
|
3497
|
+
Q[name] = function (x, y, options) {
|
|
3498
|
+
var rejected = inverseStaticTargetRejected(x, "root", options);
|
|
3499
|
+
if (rejected) return rejected;
|
|
3500
|
+
return new MetaNum(x)[name](y, options);
|
|
3501
|
+
};
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
OPERATION_DESCRIPTORS.forEach(defineHyperRoot);
|
|
3505
|
+
|
|
2544
3506
|
// level ω, rule 3 with the fundamental sequence ω[y] = y:
|
|
2545
|
-
// x{ω}y = x{ω[y]}
|
|
2546
|
-
// (the final operand
|
|
3507
|
+
// x{ω}y = x{ω[y]}y = x{y}y
|
|
3508
|
+
// (the final operand stays y — the unified limit rule n{λ}b = n{λ[b]}b)
|
|
2547
3509
|
// aperiote(3,0) = 3{0}3 = 9; aperiote(3,1) = 3{1}3 = 27;
|
|
2548
3510
|
// aperiote(3,2) = 3{2}3 = 3^^3 = 7625597484987; ...
|
|
2549
3511
|
P.aperiote = P.aper = P.h10 = function (y) {
|
|
2550
|
-
return this.arrow(y)(
|
|
3512
|
+
return this.arrow(y)(y);
|
|
2551
3513
|
};
|
|
2552
3514
|
Q.aperiote = Q.aper = Q.h10 = function (x, y) {
|
|
2553
3515
|
return new MetaNum(x).aperiote(y);
|
|
@@ -2581,7 +3543,7 @@
|
|
|
2581
3543
|
}
|
|
2582
3544
|
return new MetaNum(1);
|
|
2583
3545
|
}
|
|
2584
|
-
return
|
|
3546
|
+
return null;
|
|
2585
3547
|
};
|
|
2586
3548
|
Q.inv_aperiote = Q.i_aper = Q.i10 = function (x, z) {
|
|
2587
3549
|
return new MetaNum(x).inv_aperiote(z);
|
|
@@ -2632,7 +3594,7 @@
|
|
|
2632
3594
|
}
|
|
2633
3595
|
}
|
|
2634
3596
|
}
|
|
2635
|
-
return
|
|
3597
|
+
return null;
|
|
2636
3598
|
};
|
|
2637
3599
|
Q.inv_expande = Q.i_expa = Q.i11 = function (x, z) {
|
|
2638
3600
|
return new MetaNum(x).inv_expande(z);
|
|
@@ -2680,7 +3642,7 @@
|
|
|
2680
3642
|
}
|
|
2681
3643
|
}
|
|
2682
3644
|
}
|
|
2683
|
-
return
|
|
3645
|
+
return null;
|
|
2684
3646
|
};
|
|
2685
3647
|
Q.inv_multiexpande = Q.i_muea = Q.i12 = function (x, z) {
|
|
2686
3648
|
return new MetaNum(x).inv_multiexpande(z);
|
|
@@ -2728,7 +3690,7 @@
|
|
|
2728
3690
|
}
|
|
2729
3691
|
}
|
|
2730
3692
|
}
|
|
2731
|
-
return
|
|
3693
|
+
return null;
|
|
2732
3694
|
};
|
|
2733
3695
|
Q.inv_powerexpande = Q.i_poea = Q.i13 = function (x, z) {
|
|
2734
3696
|
return new MetaNum(x).inv_powerexpande(z);
|
|
@@ -2934,6 +3896,7 @@
|
|
|
2934
3896
|
var arr = [v.array[0].slice()];
|
|
2935
3897
|
for (var i = 1; i < v.array.length; i++) arr.push(v.array[i].slice());
|
|
2936
3898
|
mergeFiniteRowsIntoR0(arr);
|
|
3899
|
+
var deLayered = false;
|
|
2937
3900
|
while (L >= 2 && arr.length === 1) {
|
|
2938
3901
|
var poly = arr[0].slice();
|
|
2939
3902
|
while (poly.length > 0 && poly[poly.length - 1] === 0) poly.pop();
|
|
@@ -2942,9 +3905,15 @@
|
|
|
2942
3905
|
if (row.length > MetaNum.maxCols) break; // row would not fit
|
|
2943
3906
|
arr = [[0], row];
|
|
2944
3907
|
L--;
|
|
3908
|
+
deLayered = true;
|
|
2945
3909
|
mergeFiniteRowsIntoR0(arr);
|
|
2946
3910
|
}
|
|
2947
|
-
|
|
3911
|
+
// a de-layered tower writes the innermost base marker 10 (README convention);
|
|
3912
|
+
// caller-provided tail-CNF r0 keeps literal 0 (itap [[0,1],…], itmult [[c0],…])
|
|
3913
|
+
if (deLayered && (arr[0][0] || 0) === 0) arr[0][0] = 10;
|
|
3914
|
+
// literal 0 stays literal (维护者约定): an empty constant term is written
|
|
3915
|
+
// as 0, not rewritten to the base marker 10 — e.g. iteraperiate's
|
|
3916
|
+
// ω^ω+ω marker keeps r0 = [0, 1]
|
|
2948
3917
|
v.array = arr;
|
|
2949
3918
|
v.layer = L;
|
|
2950
3919
|
return v.normalize();
|
|
@@ -2974,8 +3943,11 @@
|
|
|
2974
3943
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
2975
3944
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
2976
3945
|
if (cf.length === 0) return x.mul(y); // rule 1: x{0}y = x*y
|
|
2977
|
-
// B2-a: base-2
|
|
2978
|
-
|
|
3946
|
+
// B2-a: base-2 collapse on the diagonal y=2 only — n{λ}b = n{λ[b]}b
|
|
3947
|
+
// keeps the operand b, so b=2 stays 2 all the way down and the cascade
|
|
3948
|
+
// bottoms out at 2{...}2 = 2{2}2 = 4 (see _hyperopFromOrdinal). y > 2
|
|
3949
|
+
// grows normally (2{ω}3 = 2{3}3 = 65536).
|
|
3950
|
+
if (x.eq(2) && y.eq(2) && coeffsHaveOmegaPart(cf)) return new MetaNum(4);
|
|
2979
3951
|
|
|
2980
3952
|
if (!coeffsHaveOmegaPart(cf)) {
|
|
2981
3953
|
// finite level: arrow() handles both small and huge operands
|
|
@@ -2996,15 +3968,28 @@
|
|
|
2996
3968
|
return Q._iterateOrdinal(x, succCoeffs(cf), x.clone(), yCnt - 1, depth);
|
|
2997
3969
|
}
|
|
2998
3970
|
// limit ordinal: fundamental sequence at y
|
|
2999
|
-
var pL = 1;
|
|
3000
|
-
while (pL < cf.length && (cf[pL] || 0) === 0) pL++;
|
|
3001
3971
|
// A fundamental sequence whose cardinal is cascade-unrepresentable would
|
|
3002
|
-
// need
|
|
3003
|
-
// the
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
//
|
|
3007
|
-
|
|
3972
|
+
// need ~y distinct ordinal levels — more rows than the array can hold.
|
|
3973
|
+
// Collapsing to the level λ itself froze the result (h20(x,101) =
|
|
3974
|
+
// h20(x,1e6) = x+[1|λ], independent of y). Instead store the FS level
|
|
3975
|
+
// λ[y] as ONE row — the exact convention the y ≤ COEFF_BOUND cascade
|
|
3976
|
+
// path produces ([1|ω+y] for ω*2, [1|ω*y] for ω^2, …) — so the result
|
|
3977
|
+
// keeps growing with y all the way to MSI. λ = ω is excluded: ω[y] = y
|
|
3978
|
+
// is a finite level the rule-3 path below evaluates exactly.
|
|
3979
|
+
var aboveOmega = (cf[1] || 0) > 1;
|
|
3980
|
+
for (var mi = 2; mi < cf.length; mi++) if ((cf[mi] || 0) > 0) aboveOmega = true;
|
|
3981
|
+
var hugeFs = yCnt > COEFF_BOUND && aboveOmega;
|
|
3982
|
+
if (hugeFs) return Q._applyOrdinalRows(x.max(y), fsCoeffs(cf, Math.floor(yCnt)), 1);
|
|
3983
|
+
// rule 3: x{λ}y = x{λ[y]}y — the operand stays y (README: n{λ}b = n{λ[b]}b)
|
|
3984
|
+
var nxt = fsCoeffs(cf, yCnt);
|
|
3985
|
+
if (coeffsHaveFraction(nxt)) {
|
|
3986
|
+
// a fractional FS index leaves the fraction in the coefficients; they
|
|
3987
|
+
// resolve against the OPERAND y — the machinery _hyperopFromOrdinalRaw
|
|
3988
|
+
// owns (recursive fsCoeffs on a fractional coefficient would corrupt
|
|
3989
|
+
// the CNF, so hand the case over instead of recursing here)
|
|
3990
|
+
return Q._hyperopFromOrdinalRaw(x, y, nxt, true);
|
|
3991
|
+
}
|
|
3992
|
+
return Q._ordinalHyperop(x, y, nxt, depth + 1);
|
|
3008
3993
|
};
|
|
3009
3994
|
|
|
3010
3995
|
Q._iterateOrdinal = function (x, beta, V0, iters, depth) {
|
|
@@ -3043,26 +4028,33 @@
|
|
|
3043
4028
|
|
|
3044
4029
|
var cf0 = trimCoeffs((coeffs || []).slice());
|
|
3045
4030
|
if (cf0.length === 0) return x.mul(y); // rule 1: x{0}y = x*y
|
|
3046
|
-
// B2-a:
|
|
3047
|
-
//
|
|
3048
|
-
|
|
4031
|
+
// B2-a: on the base-2 DIAGONAL y=2 every infinite level collapses
|
|
4032
|
+
// (n{λ}b = n{λ[b]}b keeps the operand 2; 2{...}2 = 2{2}2 = 4). Finite
|
|
4033
|
+
// levels are excluded, and y > 2 grows normally (2{ω}3 = 2{3}3).
|
|
4034
|
+
if (x.eq(2) && y.eq(2) && coeffsHaveOmegaPart(cf0)) return new MetaNum(4);
|
|
3049
4035
|
// Fractional level coefficients come from a fundamental sequence taken at a
|
|
3050
|
-
// non-integer
|
|
3051
|
-
// ω^(k-1)·(
|
|
3052
|
-
// be fractional, then raise it to a fractional
|
|
3053
|
-
//
|
|
4036
|
+
// non-integer operand b. On the FS diagonal ω reads as b, so
|
|
4037
|
+
// ω^k·(c+f) = ω^k·c + ω^(k-1)·(b·f) — resolve top-down until only the
|
|
4038
|
+
// constant term can still be fractional, then raise it to a fractional
|
|
4039
|
+
// argument one level up:
|
|
4040
|
+
// x{γ+f}b = x{γ+1}(2·(b/2)^f) (10{ω*2}2.1 = 10{ω+3}2*(2.1/2)^0.1).
|
|
3054
4041
|
if (coeffsHaveFraction(cf0)) {
|
|
3055
|
-
var
|
|
3056
|
-
if (isFinite(
|
|
3057
|
-
var rs = Q._resolveFracLevel(cf0,
|
|
4042
|
+
var ynf = y.toNumber();
|
|
4043
|
+
if (isFinite(ynf) && ynf >= 2) {
|
|
4044
|
+
var rs = Q._resolveFracLevel(cf0, ynf);
|
|
3058
4045
|
if (rs.frac > 0) {
|
|
3059
4046
|
var up = rs.ord.slice();
|
|
3060
4047
|
while (up.length < 1) up.push(0);
|
|
3061
4048
|
up[0] = (up[0] || 0) + 1;
|
|
3062
|
-
var argF = 2 * Math.pow(
|
|
4049
|
+
var argF = 2 * Math.pow(ynf / 2, rs.frac);
|
|
3063
4050
|
return Q._hyperopFromOrdinal(x, new MetaNum(argF), trimCoeffs(up));
|
|
3064
4051
|
}
|
|
3065
4052
|
cf0 = rs.ord;
|
|
4053
|
+
} else {
|
|
4054
|
+
// operand not a plain number (huge/ordinal): the fraction is below
|
|
4055
|
+
// the representable scale — keep the integer part of every coefficient
|
|
4056
|
+
for (var fi = 0; fi < cf0.length; fi++) cf0[fi] = Math.floor(cf0[fi] || 0);
|
|
4057
|
+
cf0 = trimCoeffs(cf0);
|
|
3066
4058
|
}
|
|
3067
4059
|
}
|
|
3068
4060
|
// Non-integer argument at ordinal levels (issues.md addition 3):
|
|
@@ -3116,13 +4108,14 @@
|
|
|
3116
4108
|
return Q._ordinalHyperop(x, y, cf0);
|
|
3117
4109
|
}
|
|
3118
4110
|
if (ym >= 1) {
|
|
3119
|
-
// Limit level: rule 3 with the FULL (fractional) index
|
|
3120
|
-
//
|
|
3121
|
-
//
|
|
4111
|
+
// Limit level: rule 3 with the FULL (fractional) index, and the
|
|
4112
|
+
// operand STAYS y — λ[y] can carry fractional coefficients
|
|
4113
|
+
// (10{ω*2}2.1 = 10{ω+2.1}2.1), resolved by the fractional-level rule
|
|
4114
|
+
// above against the operand, so the fraction is never dropped.
|
|
3122
4115
|
// Nested (skipFrac) the index is floored, else every application would
|
|
3123
4116
|
// take another fractional FS and recurse forever.
|
|
3124
4117
|
var fsIdx = skipFrac ? Math.floor(yFracNum) : yFracNum;
|
|
3125
|
-
return Q._hyperopFromOrdinalRaw(x,
|
|
4118
|
+
return Q._hyperopFromOrdinalRaw(x, y, fsCoeffs(cf0, fsIdx), skipFrac);
|
|
3126
4119
|
}
|
|
3127
4120
|
}
|
|
3128
4121
|
var cf = cf0;
|
|
@@ -3161,7 +4154,12 @@
|
|
|
3161
4154
|
// sequence costs nothing; the budget keeps the LARGEST rows):
|
|
3162
4155
|
// successor α = β+m: x{α}y = x{β+m-1}^(y-2)(x{β+m-1}x) — only the top row
|
|
3163
4156
|
// follows y, every row below carries x-2 (h13(10,20) → [8,0,1],[8,1,1],[18,2,1]).
|
|
3164
|
-
// limit α: rule 3
|
|
4157
|
+
// limit α: rule 3 keeps the OPERAND y (n{λ}b = n{λ[b]}b), so every
|
|
4158
|
+
// fundamental sequence before the first successor expansion is taken at
|
|
4159
|
+
// y, and the first successor row follows y too; once a successor
|
|
4160
|
+
// expansion has fired, rule 2 bottoms at x and every row below carries
|
|
4161
|
+
// x-2 with its fundamental sequences at x.
|
|
4162
|
+
// (10{ω*2}3 = 10{ω+3}3 → [1|ω+2],[8|ω+1],[8|ω], base 10{10}10.)
|
|
3165
4163
|
// Only array[0][0] may be non-integer (same contract as arrow()); a fractional
|
|
3166
4164
|
// argument enters as the outer count ceil(y)-2, the fractional start value x^f
|
|
3167
4165
|
// of the first fundamental sequence (`fsOpd`), or a leftover constant term
|
|
@@ -3172,7 +4170,7 @@
|
|
|
3172
4170
|
if (!(budget >= 1)) return rows;
|
|
3173
4171
|
var cfs = trimCoeffs((cf || []).slice());
|
|
3174
4172
|
var opd = Math.min(yn, MAX_SAFE_INTEGER);
|
|
3175
|
-
var first =
|
|
4173
|
+
var first = true; // the FIRST successor row follows y
|
|
3176
4174
|
var fracOpd = (fsOpd === undefined) ? null : fsOpd;
|
|
3177
4175
|
var baseIdx = xn;
|
|
3178
4176
|
var fracRem = 0; // fractional constant carried to the base
|
|
@@ -3208,22 +4206,28 @@
|
|
|
3208
4206
|
opd = Math.min(xn, MAX_SAFE_INTEGER); // everything below the top
|
|
3209
4207
|
continue; // row is base-operand
|
|
3210
4208
|
}
|
|
3211
|
-
// limit: fundamental sequence at the current operand (rule 3)
|
|
4209
|
+
// limit: fundamental sequence at the current operand (rule 3). Before
|
|
4210
|
+
// the first successor expansion the operand is still the ORIGINAL y
|
|
4211
|
+
// (n{λ}b = n{λ[b]}b), so every fundamental sequence here is taken at y;
|
|
4212
|
+
// afterwards rule 2 has bottomed at x and the index is x (or the
|
|
4213
|
+
// fractional start value x^f on the fractional-argument path).
|
|
3212
4214
|
var idx = (fracOpd !== null) ? fracOpd : opd;
|
|
3213
4215
|
fracOpd = null;
|
|
3214
4216
|
baseIdx = idx;
|
|
3215
4217
|
var nxt = fsCoeffs(cfs, idx);
|
|
3216
4218
|
if (coeffsHaveFraction(nxt)) {
|
|
3217
4219
|
// a fractional index makes the coefficients fractional (ω^k·(c+f)) —
|
|
3218
|
-
// resolve them against the
|
|
3219
|
-
//
|
|
3220
|
-
|
|
4220
|
+
// resolve them against the index (the operand of this application)
|
|
4221
|
+
// so every row coefficient stays an integer, carrying the leftover
|
|
4222
|
+
// constant fraction into the base
|
|
4223
|
+
var rs2 = Q._resolveFracLevel(nxt, idx);
|
|
3221
4224
|
cfs = rs2.ord;
|
|
3222
4225
|
if (rs2.frac > 0) fracRem = rs2.frac;
|
|
3223
4226
|
} else {
|
|
3224
4227
|
cfs = trimCoeffs(nxt);
|
|
3225
4228
|
}
|
|
3226
|
-
|
|
4229
|
+
// the operand only drops to x once a successor expansion has fired
|
|
4230
|
+
if (!first) opd = Math.min(xn, MAX_SAFE_INTEGER);
|
|
3227
4231
|
}
|
|
3228
4232
|
rows.baseIdx = baseIdx + fracRem; // descending by ordinal
|
|
3229
4233
|
return rows;
|
|
@@ -3248,14 +4252,26 @@
|
|
|
3248
4252
|
// carried fraction survives into the base
|
|
3249
4253
|
var baseResult = x.arrow(Math.max(baseIdx, 3))(x);
|
|
3250
4254
|
var result = baseResult.clone();
|
|
3251
|
-
|
|
4255
|
+
// the seed x{idx}x may itself carry ordinal rows (e.g. expande(1187,3)'s seed
|
|
4256
|
+
// 1187{1187}1187 truncates to [10] + 19 rows): carry them into the result
|
|
4257
|
+
// instead of discarding them — the cascade rows stack ON TOP of the seed's
|
|
4258
|
+
// rows, then the budget truncation keeps the LARGEST rows with the
|
|
4259
|
+
// first-kept count +1 marker.
|
|
4260
|
+
var baseRows = [];
|
|
4261
|
+
for (var br = 1; br < baseResult.array.length; br++) {
|
|
4262
|
+
var brow = baseResult.array[br];
|
|
4263
|
+
if (brow && brow.length >= 2 && (brow[0] || 0) > 0) baseRows.push(brow.slice());
|
|
4264
|
+
}
|
|
4265
|
+
var merged = baseRows.concat(rows);
|
|
4266
|
+
if (truncated || merged.length > budget) {
|
|
3252
4267
|
result.array = [[10]];
|
|
3253
|
-
|
|
3254
|
-
|
|
4268
|
+
merged = merged.slice(merged.length - budget); // keep the LARGEST rows
|
|
4269
|
+
merged[0][0] = (merged[0][0] || 0) + 1; // truncation marker
|
|
4270
|
+
if (merged[0][0] > MAX_SAFE_INTEGER) merged[0][0] = MAX_SAFE_INTEGER;
|
|
3255
4271
|
} else {
|
|
3256
4272
|
result.array = [baseResult.array[0].slice()];
|
|
3257
4273
|
}
|
|
3258
|
-
for (var i = 0; i <
|
|
4274
|
+
for (var i = 0; i < merged.length; i++) result.array.push(merged[i]);
|
|
3259
4275
|
result.layer = 0;
|
|
3260
4276
|
return result.normalize();
|
|
3261
4277
|
};
|
|
@@ -3328,10 +4344,16 @@
|
|
|
3328
4344
|
return steps + 1;
|
|
3329
4345
|
}
|
|
3330
4346
|
|
|
3331
|
-
// Inverse of a LIMIT level taken through the expanded cascade:
|
|
3332
|
-
//
|
|
3333
|
-
//
|
|
4347
|
+
// Inverse of a LIMIT level taken through the expanded cascade: under the
|
|
4348
|
+
// unified limit rule x{λ}y = x{λ[y]}y the rows depend on y through BOTH the
|
|
4349
|
+
// fundamental sequence and the first successor count, so instead of reading
|
|
4350
|
+
// a count row we search the (monotone) forward map.
|
|
3334
4351
|
Q._invExpandedLimit = function (base, value, coeffs) {
|
|
4352
|
+
// y=2 sits BELOW the bisection range and is a distinct value under the
|
|
4353
|
+
// unified limit rule (10{ω*2}2 = 10{ω+1}10 < 10{ω*2}3), so probe it first
|
|
4354
|
+
var v2 = Q._expandedHyperop(base, MetaNum.TWO, coeffs);
|
|
4355
|
+
if (value.lt(v2)) return base.clone();
|
|
4356
|
+
if (value.eq(v2)) return new MetaNum(2);
|
|
3335
4357
|
var lo = 3, hi = MAX_SAFE_INTEGER, best = 0;
|
|
3336
4358
|
var v3 = Q._expandedHyperop(base, new MetaNum(3), coeffs);
|
|
3337
4359
|
if (value.lt(v3)) return base.clone();
|
|
@@ -3360,7 +4382,7 @@
|
|
|
3360
4382
|
x = new MetaNum(x);
|
|
3361
4383
|
z = new MetaNum(z);
|
|
3362
4384
|
if (x.isNaN() || z.isNaN()) return MetaNum.NaN.clone();
|
|
3363
|
-
if (x.array.length <= 1) return
|
|
4385
|
+
if (x.array.length <= 1) return null;
|
|
3364
4386
|
|
|
3365
4387
|
var cf = trimCoeffs((coeffs || []).slice());
|
|
3366
4388
|
|
|
@@ -3378,13 +4400,13 @@
|
|
|
3378
4400
|
}
|
|
3379
4401
|
}
|
|
3380
4402
|
}
|
|
3381
|
-
if (cf.length === 0) return
|
|
4403
|
+
if (cf.length === 0) return null;
|
|
3382
4404
|
|
|
3383
4405
|
// expanded cascade path (base z is a small finite number ≥ 3): the forward
|
|
3384
4406
|
// operation wrote the rule-1..4 cascade rows.
|
|
3385
4407
|
// successor α: the row at α-1 carries exactly y-2 applications → +2
|
|
3386
|
-
// limit α:
|
|
3387
|
-
//
|
|
4408
|
+
// limit α: y appears in the fundamental-sequence rows AND the first
|
|
4409
|
+
// successor count, so it is recovered from the forward map
|
|
3388
4410
|
var zC = metaFiniteCount(z);
|
|
3389
4411
|
if (z.array.length === 1 && z.layer === 0 && zC >= 3 && zC <= MAX_SAFE_INTEGER) {
|
|
3390
4412
|
if ((cf[0] || 0) > 0) {
|
|
@@ -3400,7 +4422,7 @@
|
|
|
3400
4422
|
if (lastRow && lastRow.length >= 2 && (lastRow[0] || 0) > 0) {
|
|
3401
4423
|
return new MetaNum((lastRow[0] || 0) + 2);
|
|
3402
4424
|
}
|
|
3403
|
-
return
|
|
4425
|
+
return null;
|
|
3404
4426
|
}
|
|
3405
4427
|
return Q._invExpandedLimit(z, x, cf);
|
|
3406
4428
|
}
|
|
@@ -3418,7 +4440,7 @@
|
|
|
3418
4440
|
}
|
|
3419
4441
|
}
|
|
3420
4442
|
}
|
|
3421
|
-
return
|
|
4443
|
+
return null;
|
|
3422
4444
|
};
|
|
3423
4445
|
|
|
3424
4446
|
// ---------------------------------------------------------------------------
|
|
@@ -3742,13 +4764,14 @@
|
|
|
3742
4764
|
|
|
3743
4765
|
// ---------------------------------------------------------------------------
|
|
3744
4766
|
// Hyperoperations from ω^ω up to ε₀ — README rules 1-4 with the unified limit
|
|
3745
|
-
// rule n{λ}b = n{λ[b]}
|
|
4767
|
+
// rule n{λ}b = n{λ[b]}b (the final operand is b). Levels ≥ ω^ω have
|
|
3746
4768
|
// no finite CNF row, so — unless λ[y] still fits a layer-0 row — the result
|
|
3747
4769
|
// is the compact layer marker of λ[y] (Q._layerMarker).
|
|
3748
4770
|
// ---------------------------------------------------------------------------
|
|
3749
4771
|
|
|
3750
|
-
// iter (ω^ω): (ω^ω)[y] = ω^y → x{ω^ω}y = x{ω^y}
|
|
3751
|
-
// fundamental-sequence cascade as a layer-0 multi-row array
|
|
4772
|
+
// iter (ω^ω): (ω^ω)[y] = ω^y → x{ω^ω}y = x{ω^y}y — the whole
|
|
4773
|
+
// fundamental-sequence cascade as a layer-0 multi-row array (the operand
|
|
4774
|
+
// stays y: iterate(3,5) = 3{ω^5}5 = … → top row [3,4,4,4,4,4]). For y >=
|
|
3752
4775
|
// maxCols the ω^y row no longer fits → layer-1 marker [[r0],[1,y]]
|
|
3753
4776
|
// (= 10{ω^y}10); for y > MSI → the ω^ω marker row [1,0,1].
|
|
3754
4777
|
P.iterate = P.iter = P.hww = function (y) {
|
|
@@ -3757,55 +4780,56 @@
|
|
|
3757
4780
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
3758
4781
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
3759
4782
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
3760
|
-
//
|
|
3761
|
-
// every
|
|
3762
|
-
// 2{...}2 = 2{2}2 = 4 for ANY limit/successor level λ
|
|
3763
|
-
//
|
|
3764
|
-
|
|
4783
|
+
// B2-a on the diagonal only: n{λ}b = n{λ[b]}b keeps the operand b, so
|
|
4784
|
+
// b=2 stays 2 through every FS/successor step and the cascade ends at
|
|
4785
|
+
// 2{...}2 = 2{2}2 = 4 for ANY limit/successor level λ (issue #17 D07/B2-a).
|
|
4786
|
+
// y > 2 grows normally (2{ω^ω}3 = 2{ω^3}3 = …); finite levels are excluded
|
|
4787
|
+
// (2{1}3 = 8).
|
|
4788
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
3765
4789
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
3766
4790
|
|
|
3767
4791
|
// iterate(x,y) = x{ω^ω}y. Rule 3 with the fundamental sequence
|
|
3768
|
-
// (ω^ω)[y] = ω^y: x{ω^ω}y = x{ω^y}
|
|
4792
|
+
// (ω^ω)[y] = ω^y: x{ω^ω}y = x{ω^y}y — the operand stays y.
|
|
3769
4793
|
var yc = metaFiniteCount(y);
|
|
3770
4794
|
if (yc === Math.floor(yc) && yc <= MAX_SAFE_INTEGER) {
|
|
3771
4795
|
var m = Math.max(2, Math.floor(yc));
|
|
3772
4796
|
if (m < MetaNum.maxCols) {
|
|
3773
4797
|
// ω^y is a layer-0 ordinal (coeffs with 1 at index y): evaluate
|
|
3774
|
-
// x{ω^y}
|
|
3775
|
-
// iterate(3,5) = 3{ω^5}
|
|
4798
|
+
// x{ω^y}y through the unified rule-1..3 engine. E.g.
|
|
4799
|
+
// iterate(3,5) = 3{ω^5}5 = the full FS cascade (truncated when it
|
|
3776
4800
|
// overflows the row budget).
|
|
3777
4801
|
var coeffs = [];
|
|
3778
4802
|
for (var ci = 0; ci < m; ci++) coeffs.push(0);
|
|
3779
4803
|
coeffs.push(1);
|
|
3780
|
-
return Q._hyperopFromOrdinal(x,
|
|
4804
|
+
return Q._hyperopFromOrdinal(x, y, coeffs);
|
|
3781
4805
|
}
|
|
3782
4806
|
// y >= maxCols: ω^y needs a row longer than maxCols — store as the
|
|
3783
4807
|
// layer-1 compact marker 10{ω^y}10, capped at MSI
|
|
3784
4808
|
return Q._layerMarker([10], 1, [[1, m]]);
|
|
3785
4809
|
}
|
|
3786
4810
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
3787
|
-
// fractional y: (ω^ω)[y] = ω^y = ω^(m+f) = ω^m·ω^f, and on the
|
|
3788
|
-
// ω^f reads as
|
|
3789
|
-
//
|
|
3790
|
-
// Flooring y would lose the
|
|
4811
|
+
// fractional y: (ω^ω)[y] = ω^y = ω^(m+f) = ω^m·ω^f, and on the FS
|
|
4812
|
+
// diagonal ω^f reads as y^f — so the level is ω^m·(y^f), whose
|
|
4813
|
+
// coefficients carry y^f at index m (README: 10{ω^ω}2.1 =
|
|
4814
|
+
// 10{ω^2*2.1^0.1}2.1 = 10{ω^2*1.077}2.1). Flooring y would lose the
|
|
4815
|
+
// fraction and make iterate(10,2.1)=iterate(10,2).
|
|
3791
4816
|
var mf = Math.max(2, Math.floor(yc));
|
|
3792
4817
|
var ff = Number((yc - Math.floor(yc)).toPrecision(15));
|
|
3793
|
-
var
|
|
3794
|
-
var cfac = (isFinite(xnf) && xnf >= 2 && ff > 0) ? Math.pow(xnf, ff) : 1;
|
|
4818
|
+
var cfac = (yc >= 2 && ff > 0) ? Math.pow(yc, ff) : 1;
|
|
3795
4819
|
if (mf < MetaNum.maxCols) {
|
|
3796
4820
|
var cfw = [];
|
|
3797
4821
|
for (var cw = 0; cw < mf; cw++) cfw.push(0);
|
|
3798
4822
|
cfw.push(cfac);
|
|
3799
|
-
return Q._hyperopFromOrdinal(x,
|
|
4823
|
+
return Q._hyperopFromOrdinal(x, y, cfw);
|
|
3800
4824
|
}
|
|
3801
|
-
// marker form: ω^m·(
|
|
3802
|
-
// fractional part out one level down: ω^m·floor(c) + ω^(m-1)·(
|
|
4825
|
+
// marker form: ω^m·(y^f) — the count must stay an integer, so write the
|
|
4826
|
+
// fractional part out one level down: ω^m·floor(c) + ω^(m-1)·(y·frac),
|
|
3803
4827
|
// the same resolution the CNF levels use
|
|
3804
4828
|
if (mf >= MetaNum.maxCols) {
|
|
3805
4829
|
var cfFl = Math.floor(cfac), cfFr = cfac - cfFl;
|
|
3806
4830
|
var mkRows = [];
|
|
3807
4831
|
if (cfFl >= 1) mkRows.push([cfFl, mf]);
|
|
3808
|
-
if (cfFr > 1e-9 && mf >= 2) mkRows.push([Math.max(1, Math.round(
|
|
4832
|
+
if (cfFr > 1e-9 && mf >= 2) mkRows.push([Math.max(1, Math.round(yc * cfFr)), mf - 1]);
|
|
3809
4833
|
if (mkRows.length === 0) mkRows.push([1, mf]);
|
|
3810
4834
|
return Q._layerMarker([10], 1, mkRows);
|
|
3811
4835
|
}
|
|
@@ -3865,7 +4889,7 @@
|
|
|
3865
4889
|
}
|
|
3866
4890
|
}
|
|
3867
4891
|
}
|
|
3868
|
-
return
|
|
4892
|
+
return null;
|
|
3869
4893
|
};
|
|
3870
4894
|
Q.inv_iterate = Q.inv_iter = Q.iww = function (x, z) {
|
|
3871
4895
|
return new MetaNum(x).inv_iterate(z);
|
|
@@ -3873,16 +4897,26 @@
|
|
|
3873
4897
|
|
|
3874
4898
|
// itermult (ω^ω+1): successor level — x{ω^ω+1}y = x{ω^ω} applied y-1 times
|
|
3875
4899
|
// to x (rule 2). k = 2 → iterate(x,x) exactly; 1 < k < 2 → x{ω^ω}(x^(k-1)).
|
|
3876
|
-
// k
|
|
3877
|
-
//
|
|
3878
|
-
//
|
|
4900
|
+
// k ≥ 2 → the layer-1 marker [[c0],[1,0,1]] with c0 = (y-2)/8: the marker is
|
|
4901
|
+
// normalized at base 10, where 10{ω^ω+1}10 anchors c0 = 1 and the first
|
|
4902
|
+
// segment [10{ω^ω}10 ↔ 0, 10{ω^ω+1}10 ↔ 1] interpolates (y-2)/8.
|
|
4903
|
+
// itermult (ω^ω+1): the layer-1 marker encodes the level tail BELOW the ω^ω
|
|
4904
|
+
// marker row [1,0,1] as CNF coefficients r0 = [c0, c1, …] (c0 = constant term,
|
|
4905
|
+
// may be non-integer — the same fractional-r0 convention layer 0 uses for
|
|
4906
|
+
// array[0][0]). Anchors at base 10: 10{ω^ω+1}10 ↔ [[1],[1,0,1]], and the
|
|
4907
|
+
// segment up to 10{ω^ω+2}10 = 10{ω^ω+1}^9(10) grows continuously to
|
|
4908
|
+
// [[2],[1,0,1]]. Finite operands first interpolate inside the first segment
|
|
4909
|
+
// [10{ω^ω}10 ↔ 0, 10{ω^ω+1}10 ↔ 1] as (y-2)/8 (base-independent: the marker
|
|
4910
|
+
// is normalized at base 10, like the letter notation); beyond the anchor the
|
|
4911
|
+
// fraction is below marker resolution → c0 = 1. Ordinal / y > MSI keeps the
|
|
4912
|
+
// engine convention (y plus the ω^ω marker row), so huge heights still differ.
|
|
3879
4913
|
P.itermult = P.itmu = P.hw01 = function (y) {
|
|
3880
4914
|
var x = this.clone();
|
|
3881
4915
|
y = new MetaNum(y);
|
|
3882
4916
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
3883
4917
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
3884
4918
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
3885
|
-
if (x.eq(2) && y.
|
|
4919
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
3886
4920
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
3887
4921
|
var yc = metaFiniteCount(y);
|
|
3888
4922
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -3891,10 +4925,16 @@
|
|
|
3891
4925
|
var f = y.sub(MetaNum.ONE);
|
|
3892
4926
|
return f.eq(MetaNum.ZERO) ? x.iterate(x) : x.iterate(x.pow(f));
|
|
3893
4927
|
}
|
|
3894
|
-
|
|
3895
|
-
if (
|
|
3896
|
-
|
|
3897
|
-
|
|
4928
|
+
// fractional-level positions interpolate inside the first marker segment
|
|
4929
|
+
if (yc < 3) {
|
|
4930
|
+
var fracPos = (yc - 2) / 8;
|
|
4931
|
+
return Q._layerMarker([fracPos], 1, [[1, 0, 1]]);
|
|
4932
|
+
}
|
|
4933
|
+
// c0 = (y-2)/8: base-10 normalized (10{ω^ω+1}10 ↔ 1); values beyond the
|
|
4934
|
+
// anchor saturate at c0 = 1 (the next fraction is below marker resolution)
|
|
4935
|
+
var c0 = (yc - 2) / 8;
|
|
4936
|
+
if (c0 > 1) c0 = 1;
|
|
4937
|
+
return Q._layerMarker([c0], 1, [[1, 0, 1]]);
|
|
3898
4938
|
}
|
|
3899
4939
|
// ordinal / out-of-range operand: y plus one ω^ω marker row
|
|
3900
4940
|
return Q._ordinalOperandOp(y, 1, [1, 0, 1]);
|
|
@@ -3907,14 +4947,16 @@
|
|
|
3907
4947
|
var x = this.clone();
|
|
3908
4948
|
z = new MetaNum(z);
|
|
3909
4949
|
if (x.isNaN() || z.isNaN()) return MetaNum.NaN.clone();
|
|
3910
|
-
// marker [[
|
|
3911
|
-
//
|
|
4950
|
+
// marker [[c0],[1,0,1]] = the ω^ω+1 marker: c0 is the base-10 normalized
|
|
4951
|
+
// position, y = 2 + c0·8 (c0 = 1 saturates → the minimal reproducing height
|
|
4952
|
+
// 10, since beyond the anchor the fraction is below marker resolution).
|
|
3912
4953
|
if (x.layer >= 1) {
|
|
3913
4954
|
for (var i = x.array.length - 1; i >= 1; i--) {
|
|
3914
4955
|
var row = x.array[i];
|
|
3915
4956
|
if (row.length === 3 && row[1] === 0 && row[2] === 1 && row[0] === 1) {
|
|
3916
|
-
var n =
|
|
3917
|
-
|
|
4957
|
+
var n = x.array[0][0] || 0;
|
|
4958
|
+
if (n > 1) n = 1;
|
|
4959
|
+
return new MetaNum(2 + n * 8);
|
|
3918
4960
|
}
|
|
3919
4961
|
}
|
|
3920
4962
|
}
|
|
@@ -3932,13 +4974,103 @@
|
|
|
3932
4974
|
}
|
|
3933
4975
|
return result;
|
|
3934
4976
|
}
|
|
3935
|
-
return
|
|
4977
|
+
return null;
|
|
3936
4978
|
};
|
|
3937
4979
|
Q.inv_itermult = Q.i_itmu = Q.iw01 = function (x, z) {
|
|
3938
4980
|
return new MetaNum(x).inv_itermult(z);
|
|
3939
4981
|
};
|
|
3940
4982
|
|
|
3941
|
-
//
|
|
4983
|
+
// iteraperiate (ω^ω+ω): limit level — (ω^ω+ω)[y] = ω^ω + y. The layer-1
|
|
4984
|
+
// marker encodes the level tail ω as CNF r0 = [0, 1] (c0 = constant, c1 = ω
|
|
4985
|
+
// coefficient): 10{ω^ω+ω}10 ↔ [[0,1],[1,0,1]] and the segment up to
|
|
4986
|
+
// 10{ω^ω+ω+1}10 = 10{ω^ω+ω}^9(10) grows continuously to [[1,1],[1,0,1]].
|
|
4987
|
+
// For every finite height the FS tail y is below marker resolution against ω
|
|
4988
|
+
// (3{ω^ω+ω}3 ≈ 10{ω^ω+ω}10 at marker scale), so all finite y ≤ MSI share the
|
|
4989
|
+
// same marker; ordinal / y > MSI keeps the engine convention (y plus the
|
|
4990
|
+
// [1|ω] and [1|ω^ω] marker rows), so huge heights still differ.
|
|
4991
|
+
P.iteraperiate = P.itap = P.hw0w = function (y) {
|
|
4992
|
+
var x = this.clone();
|
|
4993
|
+
y = new MetaNum(y);
|
|
4994
|
+
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4995
|
+
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4996
|
+
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4997
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
4998
|
+
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4999
|
+
var yc = metaFiniteCount(y);
|
|
5000
|
+
if (yc <= MAX_SAFE_INTEGER) {
|
|
5001
|
+
return Q._layerMarker([0, 1], 1, [[1, 0, 1]]);
|
|
5002
|
+
}
|
|
5003
|
+
// ordinal / out-of-range operand: y plus the ω^ω+ω marker rows, merged
|
|
5004
|
+
// into canonical form (like terms fold: [[15,1],[1,1],[1,0,1]] →
|
|
5005
|
+
// [[15,2],[1,0,1]])
|
|
5006
|
+
var v = y.clone();
|
|
5007
|
+
if (v.layer < 1) v.layer = 1;
|
|
5008
|
+
v.array.push([1, 1]); // [1|ω]
|
|
5009
|
+
v.array.push([1, 0, 1]); // [1|ω^ω]
|
|
5010
|
+
return Q._standardizeLayerValue(v);
|
|
5011
|
+
};
|
|
5012
|
+
Q.iteraperiate = Q.itap = Q.hw0w = function (x, y) {
|
|
5013
|
+
return new MetaNum(x).iteraperiate(y);
|
|
5014
|
+
};
|
|
5015
|
+
|
|
5016
|
+
P.inv_iteraperiate = P.i_itap = P.iw0w = function (z) {
|
|
5017
|
+
var x = this.clone();
|
|
5018
|
+
z = new MetaNum(z);
|
|
5019
|
+
if (x.isNaN() || z.isNaN()) return MetaNum.NaN.clone();
|
|
5020
|
+
if (x.array.length >= 2) {
|
|
5021
|
+
// finite marker [[c0,(c1…)],[1,0,1]] = the ω^ω+ω level marker: the tail ω
|
|
5022
|
+
// is the operation's own level, identical for every finite height, so the
|
|
5023
|
+
// inverse returns the minimal reproducing height 2 (the height itself is
|
|
5024
|
+
// below marker resolution — 3{ω^ω+ω}3 ≈ 10{ω^ω+ω}10)
|
|
5025
|
+
if (x.layer >= 1 && x.array.length === 2) {
|
|
5026
|
+
var row = x.array[1];
|
|
5027
|
+
if (row.length === 3 && row[0] === 1 && row[1] === 0 && row[2] === 1) {
|
|
5028
|
+
return new MetaNum(2);
|
|
5029
|
+
}
|
|
5030
|
+
}
|
|
5031
|
+
// ordinal height: strip one [c|ω] and one [c|ω^ω] marker row and return
|
|
5032
|
+
// the remaining value (normalize merged equal-level rows, so a decrement
|
|
5033
|
+
// undoes the forward push even when the height carried its own rows)
|
|
5034
|
+
var result = x.clone();
|
|
5035
|
+
var stripped = 0;
|
|
5036
|
+
for (var k = result.array.length - 1; k >= 1 && stripped < 2; k--) {
|
|
5037
|
+
var row2 = result.array[k];
|
|
5038
|
+
if (stripped === 0 && row2.length === 3 && row2[1] === 0 && row2[2] === 1) {
|
|
5039
|
+
row2[0] -= 1; // one ω^ω
|
|
5040
|
+
stripped++;
|
|
5041
|
+
if (row2[0] <= 0) result.array.splice(k, 1);
|
|
5042
|
+
} else if (stripped === 1 && row2.length === 2 && row2[1] === 1) {
|
|
5043
|
+
row2[0] -= 1; // one ω
|
|
5044
|
+
stripped++;
|
|
5045
|
+
if (row2[0] <= 0) result.array.splice(k, 1);
|
|
5046
|
+
}
|
|
5047
|
+
}
|
|
5048
|
+
// the [1|ω] row may have been merged into r0[1] (the like-terms fold):
|
|
5049
|
+
// undo it by decrementing the ω coefficient there
|
|
5050
|
+
if (stripped === 1 && result.array[0].length >= 2 && (result.array[0][1] || 0) > 0) {
|
|
5051
|
+
result.array[0][1] -= 1;
|
|
5052
|
+
if (result.array[0][1] === 0) {
|
|
5053
|
+
result.array[0].splice(1, 1);
|
|
5054
|
+
for (var t3 = 1; t3 < result.array[0].length; t3++) {
|
|
5055
|
+
if (result.array[0][t3] !== 0) break;
|
|
5056
|
+
result.array[0].splice(t3, 1); t3--;
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
stripped = 2;
|
|
5060
|
+
}
|
|
5061
|
+
if (stripped === 2) {
|
|
5062
|
+
result.normalize();
|
|
5063
|
+
if (result.array.length <= 1) result.layer = 0;
|
|
5064
|
+
return result;
|
|
5065
|
+
}
|
|
5066
|
+
}
|
|
5067
|
+
return null;
|
|
5068
|
+
};
|
|
5069
|
+
Q.inv_iteraperiate = Q.i_itap = Q.iw0w = function (x, z) {
|
|
5070
|
+
return new MetaNum(x).inv_iteraperiate(z);
|
|
5071
|
+
};
|
|
5072
|
+
|
|
5073
|
+
// cuboiter (ω^ω*2): (ω^ω*2)[y] = ω^ω + ω^y → x{ω^ω*2}y = x{ω^ω+ω^y}y
|
|
3942
5074
|
// for k <= MSI, cube(3,k)=3{ω^ω+ω^k}3
|
|
3943
5075
|
// ≈10{ω^ω+ω^k}10 → layer=1, array=[[10],[1,k],[1,0,1]] (ω^k + ω^ω)
|
|
3944
5076
|
// for k > MSI, cube(3,k)≈10{ω^ω*2}10 → layer=1, array=[[10],[2,0,1]]
|
|
@@ -3948,7 +5080,7 @@
|
|
|
3948
5080
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
3949
5081
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
3950
5082
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
3951
|
-
if (x.eq(2) && y.
|
|
5083
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
3952
5084
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
3953
5085
|
var yc = metaFiniteCount(y);
|
|
3954
5086
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -3994,13 +5126,13 @@
|
|
|
3994
5126
|
}
|
|
3995
5127
|
}
|
|
3996
5128
|
}
|
|
3997
|
-
return
|
|
5129
|
+
return null;
|
|
3998
5130
|
};
|
|
3999
5131
|
Q.inv_cuboiter = Q.i_cube = Q.iwx2 = function (x, z) {
|
|
4000
5132
|
return new MetaNum(x).inv_cuboiter(z);
|
|
4001
5133
|
};
|
|
4002
5134
|
|
|
4003
|
-
// expoiter (ω^(ω+1)): (ω^(ω+1))[y] = ω^ω*y → x{ω^(ω+1)}y = x{ω^ω*y}
|
|
5135
|
+
// expoiter (ω^(ω+1)): (ω^(ω+1))[y] = ω^ω*y → x{ω^(ω+1)}y = x{ω^ω*y}y
|
|
4004
5136
|
// for k <= MSI, expo(3,k)=3{ω^ω*k}3
|
|
4005
5137
|
// ≈10{ω^ω*k}10 → layer=1, array=[[10],[k,0,1]]
|
|
4006
5138
|
// for k > MSI, expo(3,k)≈10{ω^(ω+1)}10 → layer=1, array=[[10],[1,1,1]]
|
|
@@ -4010,7 +5142,7 @@
|
|
|
4010
5142
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4011
5143
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4012
5144
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4013
|
-
if (x.eq(2) && y.
|
|
5145
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
4014
5146
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4015
5147
|
var yc = metaFiniteCount(y);
|
|
4016
5148
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4049,13 +5181,13 @@
|
|
|
4049
5181
|
}
|
|
4050
5182
|
}
|
|
4051
5183
|
}
|
|
4052
|
-
return
|
|
5184
|
+
return null;
|
|
4053
5185
|
};
|
|
4054
5186
|
Q.inv_expoiter = Q.i_expo = Q.iwa1 = function (x, z) {
|
|
4055
5187
|
return new MetaNum(x).inv_expoiter(z);
|
|
4056
5188
|
};
|
|
4057
5189
|
|
|
4058
|
-
// trioterate (ω^(ω*2)): (ω^(ω*2))[y] = ω^(ω+y) → x{ω^(ω*2)}y = x{ω^(ω+y)}
|
|
5190
|
+
// trioterate (ω^(ω*2)): (ω^(ω*2))[y] = ω^(ω+y) → x{ω^(ω*2)}y = x{ω^(ω+y)}y
|
|
4059
5191
|
// for k <= MSI, tria(3,k)=3{ω^(ω+k)}3
|
|
4060
5192
|
// ≈10{ω^(ω+k)}10 → layer=1, array=[[10],[1,k,1]] (ord = ω+k)
|
|
4061
5193
|
// for k > MSI, tria(3,k)≈10{ω^(ω*2)}10 → layer=1, array=[[10],[1,0,2]]
|
|
@@ -4065,7 +5197,7 @@
|
|
|
4065
5197
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4066
5198
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4067
5199
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4068
|
-
if (x.eq(2) && y.
|
|
5200
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
4069
5201
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4070
5202
|
var yc = metaFiniteCount(y);
|
|
4071
5203
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4104,13 +5236,13 @@
|
|
|
4104
5236
|
}
|
|
4105
5237
|
}
|
|
4106
5238
|
}
|
|
4107
|
-
return
|
|
5239
|
+
return null;
|
|
4108
5240
|
};
|
|
4109
5241
|
Q.inv_trioterate = Q.i_tria = Q.iwm2 = function (x, z) {
|
|
4110
5242
|
return new MetaNum(x).inv_trioterate(z);
|
|
4111
5243
|
};
|
|
4112
5244
|
|
|
4113
|
-
// trixxate (ω^(ω^2)): (ω^(ω^2))[y] = ω^(ω*y) → x{ω^(ω^2)}y = x{ω^(ω*y)}
|
|
5245
|
+
// trixxate (ω^(ω^2)): (ω^(ω^2))[y] = ω^(ω*y) → x{ω^(ω^2)}y = x{ω^(ω*y)}y
|
|
4114
5246
|
// for k <= MSI, trix(3,k)=3{ω^(ω*k)}3
|
|
4115
5247
|
// ≈10{ω^(ω*k)}10 → layer=2, array=[[10],[k,1]] (bracket = ω*k, ω^bracket)
|
|
4116
5248
|
// for k > MSI, trix(3,k)≈10{ω^(ω^2)}10 → layer=2, array=[[10],[1,2]]
|
|
@@ -4120,7 +5252,7 @@
|
|
|
4120
5252
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4121
5253
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4122
5254
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4123
|
-
if (x.eq(2) && y.
|
|
5255
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
4124
5256
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4125
5257
|
var yc = metaFiniteCount(y);
|
|
4126
5258
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4165,13 +5297,13 @@
|
|
|
4165
5297
|
}
|
|
4166
5298
|
}
|
|
4167
5299
|
}
|
|
4168
|
-
return
|
|
5300
|
+
return null;
|
|
4169
5301
|
};
|
|
4170
5302
|
Q.inv_trixxate = Q.i_trix = Q.iwp2 = function (x, z) {
|
|
4171
5303
|
return new MetaNum(x).inv_trixxate(z);
|
|
4172
5304
|
};
|
|
4173
5305
|
|
|
4174
|
-
// aperixxate (ω^(ω^ω)): (ω^(ω^ω))[y] = ω^(ω^y) → x{ω^(ω^ω)}y = x{ω^(ω^y)}
|
|
5306
|
+
// aperixxate (ω^(ω^ω)): (ω^(ω^ω))[y] = ω^(ω^y) → x{ω^(ω^ω)}y = x{ω^(ω^y)}y
|
|
4175
5307
|
// for k <= MSI, apix(3,k)=3{ω^(ω^k)}3
|
|
4176
5308
|
// ≈10{ω^(ω^k)}10 → layer=3, array=[[k]] (bracket = the constant k, so the
|
|
4177
5309
|
// ordinal reads ω^(ω^k)); layer 3 is the ω^(ω^ω) level (README).
|
|
@@ -4182,7 +5314,7 @@
|
|
|
4182
5314
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4183
5315
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4184
5316
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4185
|
-
if (x.eq(2) && y.
|
|
5317
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
4186
5318
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4187
5319
|
var yc = metaFiniteCount(y);
|
|
4188
5320
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
@@ -4239,13 +5371,13 @@
|
|
|
4239
5371
|
}
|
|
4240
5372
|
}
|
|
4241
5373
|
}
|
|
4242
|
-
return
|
|
5374
|
+
return null;
|
|
4243
5375
|
};
|
|
4244
5376
|
Q.inv_aperixxate = Q.i_apix = Q.iwpw = function (x, z) {
|
|
4245
5377
|
return new MetaNum(x).inv_aperixxate(z);
|
|
4246
5378
|
};
|
|
4247
5379
|
|
|
4248
|
-
// epsilonate (ε₀ = ω↑↑ω): ε₀[y] = ω^ω^…(y ω's) → x{ε₀}y = x{ω↑↑y}
|
|
5380
|
+
// epsilonate (ε₀ = ω↑↑ω): ε₀[y] = ω^ω^…(y ω's) → x{ε₀}y = x{ω↑↑y}y
|
|
4249
5381
|
// layer = y (README L17: layer L holds an ω-tower of height L), so
|
|
4250
5382
|
// epsl(3,k) ≈ 10{ω^ω^…^ω(k ω's)}10 → layer=k, array=[[10],[1,1]]
|
|
4251
5383
|
// (bracket = ω, (k-1) ω^'s above it → a tower of k ω's).
|
|
@@ -4256,25 +5388,35 @@
|
|
|
4256
5388
|
if (x.isNaN() || y.isNaN()) return MetaNum.NaN.clone();
|
|
4257
5389
|
if (x.eq(MetaNum.ONE)) return MetaNum.ONE.clone();
|
|
4258
5390
|
if (y.eq(MetaNum.ONE)) return x.clone();
|
|
4259
|
-
if (x.eq(2) && y.
|
|
5391
|
+
if (x.eq(2) && y.eq(2)) return new MetaNum(4);
|
|
4260
5392
|
if (y.lte(MetaNum.ZERO)) return MetaNum.NaN.clone();
|
|
4261
|
-
// ε₀[2] =
|
|
4262
|
-
//
|
|
5393
|
+
// ε₀[2] = ω^ω has no finite coefficient row, so the result takes the
|
|
5394
|
+
// λ[y]-marker convention (README): the ω^ω diagonal cascade —
|
|
5395
|
+
// x.iterate(x) = x{ω^x}x — the same value itermult(x,2) produces
|
|
5396
|
+
// (x{ω^ω+1}2 = x{ω^ω}x by the successor rule).
|
|
4263
5397
|
if (y.eq(2)) return x.iterate(x);
|
|
4264
5398
|
var yc = metaFiniteCount(y);
|
|
4265
5399
|
if (yc <= MAX_SAFE_INTEGER) {
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
5400
|
+
if (yc < 3) {
|
|
5401
|
+
// 2 ≤ y < 3: interpolate between the y=2 cascade and the y=3 marker
|
|
5402
|
+
var marker = Q._layerMarker([10], 2, [[1, 1]]);
|
|
5403
|
+
var mf0 = Number((yc - Math.floor(yc)).toPrecision(15));
|
|
5404
|
+
if (isFinite(mf0) && mf0 > 0) marker.array[0][0] = 10 + mf0;
|
|
5405
|
+
return marker;
|
|
5406
|
+
}
|
|
5407
|
+
var m = Math.min(Math.floor(yc), MAX_SAFE_INTEGER);
|
|
5408
|
+
// 5c: the FS position of x{ε₀[y]}y is ω^ω^…^ω^3 with (m-2) ω's over the
|
|
5409
|
+
// ω³ row — layer (m-2) + the ω³ row [1,0,0,0,1]: epsilonate(3,3) = the
|
|
5410
|
+
// ω^(ω³) level, the same marker aperixxate(3,3) carries. A fractional
|
|
5411
|
+
// height interpolates through r0[0] = 10+f (the v2.0.2 convention).
|
|
5412
|
+
var marker = Q._layerMarker([10], m - 2, [[1, 0, 0, 0, 1]]);
|
|
4272
5413
|
var mf = Number((yc - Math.floor(yc)).toPrecision(15));
|
|
4273
|
-
if (isFinite(mf) && mf > 0) marker.array[0][0] = 10 + mf;
|
|
5414
|
+
if (isFinite(mf) && mf > 0) marker.array[0][0] = 10 + mf;
|
|
4274
5415
|
return marker;
|
|
4275
5416
|
}
|
|
4276
|
-
// ordinal / out-of-range operand: ε₀
|
|
4277
|
-
|
|
5417
|
+
// ordinal / out-of-range operand: ε₀ passes the library ceiling → Infinity
|
|
5418
|
+
// (README: "Results > epsilonate(MSI) will return Infinity")
|
|
5419
|
+
return MetaNum.POSITIVE_INFINITY.clone();
|
|
4278
5420
|
};
|
|
4279
5421
|
Q.epsilonate = Q.epsl = Q.hepsl = function (x, y) {
|
|
4280
5422
|
return new MetaNum(x).epsilonate(y);
|
|
@@ -4313,12 +5455,29 @@
|
|
|
4313
5455
|
}
|
|
4314
5456
|
}
|
|
4315
5457
|
}
|
|
4316
|
-
return
|
|
5458
|
+
return null;
|
|
4317
5459
|
};
|
|
4318
5460
|
Q.inv_epsilonate = Q.i_epsl = Q.iepsl = function (x, z) {
|
|
4319
5461
|
return new MetaNum(x).inv_epsilonate(z);
|
|
4320
5462
|
};
|
|
4321
5463
|
|
|
5464
|
+
function installOrdinalLogAdapters() {
|
|
5465
|
+
OPERATION_DESCRIPTORS.forEach(function (descriptor) {
|
|
5466
|
+
descriptor.structuralDecoder = P["inv_" + descriptor.op] || null;
|
|
5467
|
+
descriptor.logNames.forEach(function (name) {
|
|
5468
|
+
P[name] = function (z, options) {
|
|
5469
|
+
return dispatchInverse(this, z, null, descriptor, "log", options);
|
|
5470
|
+
};
|
|
5471
|
+
Q[name] = function (x, z, options) {
|
|
5472
|
+
var rejected = inverseStaticTargetRejected(x, "log", options);
|
|
5473
|
+
if (rejected) return rejected;
|
|
5474
|
+
return new MetaNum(x)[name](z, options);
|
|
5475
|
+
};
|
|
5476
|
+
});
|
|
5477
|
+
});
|
|
5478
|
+
}
|
|
5479
|
+
installOrdinalLogAdapters();
|
|
5480
|
+
|
|
4322
5481
|
|
|
4323
5482
|
P.choose = function (other) {
|
|
4324
5483
|
var x = this.clone();
|
|
@@ -4995,14 +6154,55 @@
|
|
|
4995
6154
|
return MetaNum.arrow(a, n.sub(2), b);
|
|
4996
6155
|
};
|
|
4997
6156
|
|
|
6157
|
+
function maxAffordableSeries(resourcesAvailable, firstPrice, cost, decreasingSupremum) {
|
|
6158
|
+
if (resourcesAvailable.lt(firstPrice)) return MetaNum.ZERO.clone();
|
|
6159
|
+
var low = MetaNum.ZERO.clone();
|
|
6160
|
+
var high;
|
|
6161
|
+
if (decreasingSupremum === undefined) {
|
|
6162
|
+
high = resourcesAvailable.div(firstPrice).floor().add(MetaNum.ONE);
|
|
6163
|
+
} else {
|
|
6164
|
+
if (resourcesAvailable.gte(decreasingSupremum)) return MetaNum.POSITIVE_INFINITY.clone();
|
|
6165
|
+
high = MetaNum.ONE.clone();
|
|
6166
|
+
var expanded = false;
|
|
6167
|
+
for (var expand = 0; expand < 2048; expand++) {
|
|
6168
|
+
if (cost(high).gt(resourcesAvailable)) {
|
|
6169
|
+
expanded = true;
|
|
6170
|
+
break;
|
|
6171
|
+
}
|
|
6172
|
+
high = high.mul(2);
|
|
6173
|
+
}
|
|
6174
|
+
if (!expanded) return MetaNum.NaN.clone();
|
|
6175
|
+
}
|
|
6176
|
+
var settled = false;
|
|
6177
|
+
for (var iteration = 0; iteration < 2048; iteration++) {
|
|
6178
|
+
if (high.sub(low).lte(MetaNum.ONE)) {
|
|
6179
|
+
settled = true;
|
|
6180
|
+
break;
|
|
6181
|
+
}
|
|
6182
|
+
var mid = low.add(high).div(2).floor();
|
|
6183
|
+
if (mid.lte(low) || mid.gte(high)) return MetaNum.NaN.clone();
|
|
6184
|
+
if (cost(mid).lte(resourcesAvailable)) low = mid;
|
|
6185
|
+
else high = mid;
|
|
6186
|
+
}
|
|
6187
|
+
if (!settled && high.sub(low).gt(MetaNum.ONE)) return MetaNum.NaN.clone();
|
|
6188
|
+
if (cost(low).lte(resourcesAvailable) && cost(low.add(MetaNum.ONE)).gt(resourcesAvailable)) return low;
|
|
6189
|
+
return MetaNum.NaN.clone();
|
|
6190
|
+
}
|
|
6191
|
+
|
|
4998
6192
|
Q.affordGeometricSeries = function (resourcesAvailable, priceStart, priceRatio, currentOwned) {
|
|
4999
6193
|
resourcesAvailable = new MetaNum(resourcesAvailable);
|
|
5000
6194
|
priceStart = new MetaNum(priceStart);
|
|
5001
6195
|
priceRatio = new MetaNum(priceRatio);
|
|
5002
6196
|
currentOwned = new MetaNum(currentOwned);
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
6197
|
+
if (resourcesAvailable.isNaN() || priceStart.isNaN() || priceRatio.isNaN() || currentOwned.isNaN() ||
|
|
6198
|
+
!resourcesAvailable.isFinite() || !priceStart.isFinite() || !priceRatio.isFinite() || !currentOwned.isFinite() ||
|
|
6199
|
+
resourcesAvailable.isneg() || priceStart.lte(MetaNum.ZERO) || priceRatio.lte(MetaNum.ZERO) ||
|
|
6200
|
+
currentOwned.isneg() || !currentOwned.isint()) return MetaNum.NaN.clone();
|
|
6201
|
+
var firstPrice = priceStart.mul(priceRatio.pow(currentOwned));
|
|
6202
|
+
if (priceRatio.eq(MetaNum.ONE)) return resourcesAvailable.div(firstPrice).floor().max(MetaNum.ZERO);
|
|
6203
|
+
var cost = function (n) { return Q.sumGeometricSeries(n, firstPrice, priceRatio); };
|
|
6204
|
+
var supremum = priceRatio.lt(MetaNum.ONE) ? firstPrice.div(MetaNum.ONE.sub(priceRatio)) : undefined;
|
|
6205
|
+
return maxAffordableSeries(resourcesAvailable, firstPrice, cost, supremum);
|
|
5006
6206
|
};
|
|
5007
6207
|
|
|
5008
6208
|
Q.affordArithmeticSeries = function (resourcesAvailable, priceStart, priceAdd, currentOwned) {
|
|
@@ -5010,11 +6210,14 @@
|
|
|
5010
6210
|
priceStart = new MetaNum(priceStart);
|
|
5011
6211
|
priceAdd = new MetaNum(priceAdd);
|
|
5012
6212
|
currentOwned = new MetaNum(currentOwned);
|
|
5013
|
-
if (
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
6213
|
+
if (resourcesAvailable.isNaN() || priceStart.isNaN() || priceAdd.isNaN() || currentOwned.isNaN() ||
|
|
6214
|
+
!resourcesAvailable.isFinite() || !priceStart.isFinite() || !priceAdd.isFinite() || !currentOwned.isFinite() ||
|
|
6215
|
+
resourcesAvailable.isneg() || priceStart.lte(MetaNum.ZERO) || priceAdd.isneg() ||
|
|
6216
|
+
currentOwned.isneg() || !currentOwned.isint()) return MetaNum.NaN.clone();
|
|
6217
|
+
var firstPrice = priceStart.add(priceAdd.mul(currentOwned));
|
|
6218
|
+
if (priceAdd.eq(MetaNum.ZERO)) return resourcesAvailable.div(firstPrice).floor().max(MetaNum.ZERO);
|
|
6219
|
+
var cost = function (n) { return Q.sumArithmeticSeries(n, firstPrice, priceAdd); };
|
|
6220
|
+
return maxAffordableSeries(resourcesAvailable, firstPrice, cost);
|
|
5018
6221
|
};
|
|
5019
6222
|
|
|
5020
6223
|
Q.sumGeometricSeries = function (numItems, start, ratio, numItemsStart) {
|
|
@@ -5023,9 +6226,10 @@
|
|
|
5023
6226
|
start = new MetaNum(start);
|
|
5024
6227
|
ratio = new MetaNum(ratio);
|
|
5025
6228
|
numItemsStart = new MetaNum(numItemsStart);
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
6229
|
+
var n = numItems.sub(numItemsStart);
|
|
6230
|
+
if (n.lte(MetaNum.ZERO)) return MetaNum.ZERO.clone();
|
|
6231
|
+
if (ratio.eq(MetaNum.ONE)) return start.mul(n);
|
|
6232
|
+
return start.mul(MetaNum.ONE.sub(ratio.pow(n))).div(MetaNum.ONE.sub(ratio));
|
|
5029
6233
|
};
|
|
5030
6234
|
|
|
5031
6235
|
Q.sumArithmeticSeries = function (numItems, start, add, numItemsStart) {
|
|
@@ -5034,10 +6238,9 @@
|
|
|
5034
6238
|
start = new MetaNum(start);
|
|
5035
6239
|
add = new MetaNum(add);
|
|
5036
6240
|
numItemsStart = new MetaNum(numItemsStart);
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
return n.mul(start.add(last)).div(new MetaNum(2));
|
|
6241
|
+
var n = numItems.sub(numItemsStart);
|
|
6242
|
+
if (n.lte(MetaNum.ZERO)) return MetaNum.ZERO.clone();
|
|
6243
|
+
return n.mul(start).add(add.mul(n).mul(n.sub(MetaNum.ONE)).div(2));
|
|
5041
6244
|
};
|
|
5042
6245
|
|
|
5043
6246
|
Q.choose = function (x, y) {
|
|
@@ -5875,6 +7078,16 @@
|
|
|
5875
7078
|
}
|
|
5876
7079
|
|
|
5877
7080
|
// Handle layer symbol prefix + letter pattern + optional finOps + number (e.g., !Abcd1234, !AaE16, @Bcde500)
|
|
7081
|
+
// The finOps form may also carry the exact α mantissa ("!2.000AaE0", the
|
|
7082
|
+
// E/F/G/H marker format): strip it to the plain symPrefix shape and fold
|
|
7083
|
+
// it into r0[0] via the !αAaβ convention (!Aa(β+log₅(α/2))) after the
|
|
7084
|
+
// finOps digits are applied.
|
|
7085
|
+
var symMantVal = null;
|
|
7086
|
+
var symMantStrip = rem.match(/^([!@#\$%&~<>?])(\d+(?:\.\d+)?)((?:[A-Z][a-z]+)+)([A-Z]+)(\d+(?:\.\d+)?)\s*$/);
|
|
7087
|
+
if (symMantStrip) {
|
|
7088
|
+
symMantVal = Number(symMantStrip[2]);
|
|
7089
|
+
rem = symMantStrip[1] + symMantStrip[3] + symMantStrip[4] + symMantStrip[5];
|
|
7090
|
+
}
|
|
5878
7091
|
// Tokens may carry "^count" application counts and be space-separated —
|
|
5879
7092
|
// the toString spelling of multi-row ordinal cascades ("!Ijj^8 … 10").
|
|
5880
7093
|
var symPrefixMatch = rem.match(/^([!@#\$%&~<>?])((?:[A-Z][a-z]+(?:\^\d+)?\s*)+)([A-Z]*)((?:\d+(?:\.\d+)?(?:[Ee]\d+)?))\s*$/);
|
|
@@ -5980,6 +7193,10 @@
|
|
|
5980
7193
|
x.array[0][finLevel] = (x.array[0][finLevel] || 0) + 1;
|
|
5981
7194
|
}
|
|
5982
7195
|
}
|
|
7196
|
+
// The stripped exact-α mantissa folds into the ω^0 coefficient
|
|
7197
|
+
if (symMantVal !== null && isFinite(symMantVal) && symMantVal > 0) {
|
|
7198
|
+
x.array[0][0] = (x.array[0][0] || 0) + Math.log(symMantVal / 2) / Math.log(5);
|
|
7199
|
+
}
|
|
5983
7200
|
}
|
|
5984
7201
|
x._oaRowData = [];
|
|
5985
7202
|
for (var gi = 0; gi < oaRows.length; gi++) {
|