solve-engine 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BytecodeBuilder-B0xskcv5.d.cts → BytecodeBuilder-Bp9xeTmX.d.cts} +4 -0
- package/dist/{BytecodeBuilder-B0xskcv5.d.ts → BytecodeBuilder-Bp9xeTmX.d.ts} +4 -0
- package/dist/{Configuration-B-G5gTRn.d.cts → Configuration-C9W8tJv_.d.cts} +53 -1
- package/dist/{Configuration-B-G5gTRn.d.ts → Configuration-C9W8tJv_.d.ts} +53 -1
- package/dist/{EngineError-LU7W7AgI.d.cts → EngineError-B61GS1jp.d.cts} +14 -0
- package/dist/{EngineError-LU7W7AgI.d.ts → EngineError-B61GS1jp.d.ts} +14 -0
- package/dist/FormattingSettings-CJHyxcYu.d.cts +27 -0
- package/dist/FormattingSettings-CJHyxcYu.d.ts +27 -0
- package/dist/{Lexer-DpjdaQ98.d.cts → Lexer-BOs7euZe.d.cts} +28 -1
- package/dist/{Lexer-CNmWxabg.d.ts → Lexer-CSI_lwbW.d.ts} +28 -1
- package/dist/PackageCompatibility-B-7rK1TD.d.cts +76 -0
- package/dist/PackageCompatibility-Dh59eF-X.d.ts +76 -0
- package/dist/{PackageRegistry-zuzqt51V.d.cts → PackageRegistry-BHWJP83F.d.cts} +449 -11
- package/dist/{PackageRegistry-ClIFXxAe.d.ts → PackageRegistry-_8rDlvxI.d.ts} +449 -11
- package/dist/{Parselet-BaySkMV3.d.ts → Parselet-BBT8riYh.d.ts} +12 -3
- package/dist/{Parselet-DuI1Pjiq.d.cts → Parselet-BHcgK9S7.d.cts} +12 -3
- package/dist/{ScopeManager-B6GzdhVG.d.cts → ScopeManager-8vf02dwj.d.cts} +56 -5
- package/dist/{ScopeManager-udv4Twwq.d.ts → ScopeManager-CxA24W5n.d.ts} +56 -5
- package/dist/{Token-BzG5G4ja.d.cts → Token-B1hdkedD.d.cts} +9 -0
- package/dist/{Token-BzG5G4ja.d.ts → Token-B1hdkedD.d.ts} +9 -0
- package/dist/{TokenNormalizer-t_GotBxr.d.ts → TokenNormalizer-C6VzZgHa.d.ts} +1 -1
- package/dist/{TokenNormalizer-DGVa24Q-.d.cts → TokenNormalizer-DRc1Js1V.d.cts} +1 -1
- package/dist/{VMCheckpoints-DwLjivM7.d.cts → VMCheckpoints-ELYqITdF.d.cts} +3 -3
- package/dist/{VMCheckpoints-BiaIlOOY.d.ts → VMCheckpoints-MK--EBH2.d.ts} +3 -3
- package/dist/{Value-CXJqDH9J.d.cts → Value-BUi1RA3S.d.cts} +124 -5
- package/dist/{Value-CXJqDH9J.d.ts → Value-BUi1RA3S.d.ts} +124 -5
- package/dist/WorkerError-_-RkoQ5P.d.ts +75 -0
- package/dist/WorkerError-gzmaopj2.d.cts +75 -0
- package/dist/{chunk-GQCOSXMG.js → chunk-267JPOTF.js} +43 -5
- package/dist/chunk-267JPOTF.js.map +1 -0
- package/dist/{chunk-JMXUNXQS.cjs → chunk-2TZKENDH.cjs} +51 -8
- package/dist/chunk-2TZKENDH.cjs.map +1 -0
- package/dist/chunk-3OWCDIPN.js +215 -0
- package/dist/chunk-3OWCDIPN.js.map +1 -0
- package/dist/{chunk-VB37OC6I.js → chunk-4D6NIHE2.js} +40 -3
- package/dist/chunk-4D6NIHE2.js.map +1 -0
- package/dist/{chunk-TY3TLZAW.cjs → chunk-536WPM2V.cjs} +18 -2
- package/dist/chunk-536WPM2V.cjs.map +1 -0
- package/dist/chunk-5HRB36DK.js +405 -0
- package/dist/chunk-5HRB36DK.js.map +1 -0
- package/dist/chunk-5ON7PUAZ.js +12 -0
- package/dist/chunk-5ON7PUAZ.js.map +1 -0
- package/dist/{chunk-KV7UW6T6.js → chunk-7KYSUDQO.js} +12 -5
- package/dist/chunk-7KYSUDQO.js.map +1 -0
- package/dist/{chunk-6WFMPTGB.cjs → chunk-7ZX6B7SY.cjs} +774 -528
- package/dist/chunk-7ZX6B7SY.cjs.map +1 -0
- package/dist/chunk-ALYRJ72W.cjs +434 -0
- package/dist/chunk-ALYRJ72W.cjs.map +1 -0
- package/dist/{chunk-5KMIY374.cjs → chunk-B4HBEFTB.cjs} +17 -2
- package/dist/chunk-B4HBEFTB.cjs.map +1 -0
- package/dist/chunk-B7NLZMQ3.cjs +74 -0
- package/dist/chunk-B7NLZMQ3.cjs.map +1 -0
- package/dist/{chunk-UQ3UIZJC.js → chunk-BLI4NIQY.js} +6 -2
- package/dist/chunk-BLI4NIQY.js.map +1 -0
- package/dist/{chunk-T556MJDZ.cjs → chunk-C75AFGVD.cjs} +11 -11
- package/dist/{chunk-T556MJDZ.cjs.map → chunk-C75AFGVD.cjs.map} +1 -1
- package/dist/{chunk-G535KJEG.js → chunk-CCBZZQAE.js} +2 -2
- package/dist/{chunk-G535KJEG.js.map → chunk-CCBZZQAE.js.map} +1 -1
- package/dist/chunk-CKQMXMHR.cjs +219 -0
- package/dist/chunk-CKQMXMHR.cjs.map +1 -0
- package/dist/{chunk-PFUESQTW.cjs → chunk-EJ3ILXX6.cjs} +48 -2
- package/dist/chunk-EJ3ILXX6.cjs.map +1 -0
- package/dist/{chunk-526PMQOA.js → chunk-ENKKJYD3.js} +10 -4
- package/dist/chunk-ENKKJYD3.js.map +1 -0
- package/dist/{chunk-5X2PTP6F.cjs → chunk-ENRIK36Q.cjs} +2 -12
- package/dist/chunk-ENRIK36Q.cjs.map +1 -0
- package/dist/{chunk-3D7V24DG.js → chunk-ERCOHGXD.js} +17 -2
- package/dist/chunk-ERCOHGXD.js.map +1 -0
- package/dist/{chunk-IF532O7C.js → chunk-FD5ZZHEU.js} +3 -12
- package/dist/chunk-FD5ZZHEU.js.map +1 -0
- package/dist/{chunk-7FSDNNNC.js → chunk-G7Z4HJQA.js} +11 -5
- package/dist/chunk-G7Z4HJQA.js.map +1 -0
- package/dist/{chunk-FQGX2PA2.js → chunk-GQMUHVE3.js} +115 -4
- package/dist/chunk-GQMUHVE3.js.map +1 -0
- package/dist/chunk-GUG7SNSV.js +1764 -0
- package/dist/chunk-GUG7SNSV.js.map +1 -0
- package/dist/{chunk-UM6BVY2S.cjs → chunk-HIQ5HSZL.cjs} +175 -43
- package/dist/chunk-HIQ5HSZL.cjs.map +1 -0
- package/dist/{chunk-HVQFNJKE.cjs → chunk-HVRVSI2Z.cjs} +104 -86
- package/dist/chunk-HVRVSI2Z.cjs.map +1 -0
- package/dist/{chunk-3LAEG75D.js → chunk-I4GAWIPW.js} +24 -6
- package/dist/chunk-I4GAWIPW.js.map +1 -0
- package/dist/{chunk-PA4VC73I.cjs → chunk-J45BCEZ4.cjs} +33 -27
- package/dist/chunk-J45BCEZ4.cjs.map +1 -0
- package/dist/{chunk-NG2JHZHE.js → chunk-JIPATHVY.js} +1853 -2640
- package/dist/chunk-JIPATHVY.js.map +1 -0
- package/dist/{chunk-IP7ASJEW.js → chunk-JJIXHXFQ.js} +5 -5
- package/dist/{chunk-IP7ASJEW.js.map → chunk-JJIXHXFQ.js.map} +1 -1
- package/dist/chunk-L2TE7PMO.cjs +14 -0
- package/dist/chunk-L2TE7PMO.cjs.map +1 -0
- package/dist/{chunk-HBVFFBRR.cjs → chunk-MG6Q3DUO.cjs} +1962 -2748
- package/dist/chunk-MG6Q3DUO.cjs.map +1 -0
- package/dist/{chunk-R3PY4G7J.js → chunk-MVTOCRV2.js} +48 -3
- package/dist/chunk-MVTOCRV2.js.map +1 -0
- package/dist/{chunk-Y7FT4IQT.js → chunk-NKW7LKYU.js} +266 -28
- package/dist/chunk-NKW7LKYU.js.map +1 -0
- package/dist/{chunk-O3ANBHSA.js → chunk-NNQ2TYDF.js} +123 -5
- package/dist/chunk-NNQ2TYDF.js.map +1 -0
- package/dist/{chunk-AA3KTWTX.js → chunk-OADDUPT3.js} +4 -4
- package/dist/{chunk-AA3KTWTX.js.map → chunk-OADDUPT3.js.map} +1 -1
- package/dist/{chunk-SESSWASV.cjs → chunk-OTN6SZOD.cjs} +1868 -393
- package/dist/chunk-OTN6SZOD.cjs.map +1 -0
- package/dist/{chunk-5LI5EPGJ.cjs → chunk-QFTDTX6K.cjs} +40 -3
- package/dist/chunk-QFTDTX6K.cjs.map +1 -0
- package/dist/{chunk-YXCTLWOH.js → chunk-RRLHC37V.js} +1530 -57
- package/dist/chunk-RRLHC37V.js.map +1 -0
- package/dist/chunk-SNHVVOJK.cjs +1768 -0
- package/dist/chunk-SNHVVOJK.cjs.map +1 -0
- package/dist/{chunk-HDP7VK3C.cjs → chunk-SRGQ72IR.cjs} +649 -349
- package/dist/chunk-SRGQ72IR.cjs.map +1 -0
- package/dist/{chunk-4B2CNWQU.cjs → chunk-SSV46KFA.cjs} +14 -7
- package/dist/chunk-SSV46KFA.cjs.map +1 -0
- package/dist/{chunk-AJA6LUI7.js → chunk-UO6BUV6K.js} +18 -2
- package/dist/chunk-UO6BUV6K.js.map +1 -0
- package/dist/chunk-WWQEY7BV.js +67 -0
- package/dist/chunk-WWQEY7BV.js.map +1 -0
- package/dist/{chunk-5WVP4YHP.js → chunk-WXEHD6TT.js} +333 -33
- package/dist/chunk-WXEHD6TT.js.map +1 -0
- package/dist/{chunk-47LRVGOT.cjs → chunk-XA4CKRML.cjs} +2 -2
- package/dist/{chunk-47LRVGOT.cjs.map → chunk-XA4CKRML.cjs.map} +1 -1
- package/dist/{chunk-6KFYJ6TD.cjs → chunk-XIYYHA65.cjs} +6 -2
- package/dist/chunk-XIYYHA65.cjs.map +1 -0
- package/dist/{chunk-FE23VSSA.cjs → chunk-XJGJCF2R.cjs} +6 -6
- package/dist/{chunk-FE23VSSA.cjs.map → chunk-XJGJCF2R.cjs.map} +1 -1
- package/dist/{chunk-R7YVBHCV.cjs → chunk-YTIYVHL7.cjs} +184 -73
- package/dist/chunk-YTIYVHL7.cjs.map +1 -0
- package/dist/{chunk-TMA4RCEN.js → chunk-Z7XGGLI2.js} +3 -3
- package/dist/{chunk-TMA4RCEN.js.map → chunk-Z7XGGLI2.js.map} +1 -1
- package/dist/{chunk-A2N2GFCG.cjs → chunk-ZVTWQLK4.cjs} +10 -10
- package/dist/{chunk-A2N2GFCG.cjs.map → chunk-ZVTWQLK4.cjs.map} +1 -1
- package/dist/{chunk-524F3ATQ.cjs → chunk-ZXCESUJS.cjs} +15 -9
- package/dist/chunk-ZXCESUJS.cjs.map +1 -0
- package/dist/constants.cjs +5 -5
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +2 -2
- package/dist/engine.cjs +52 -35
- package/dist/engine.d.cts +13 -13
- package/dist/engine.d.ts +13 -13
- package/dist/engine.js +26 -21
- package/dist/errors.cjs +44 -19
- package/dist/errors.d.cts +3 -2
- package/dist/errors.d.ts +3 -2
- package/dist/errors.js +2 -1
- package/dist/format.cjs +19 -169
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +18 -26
- package/dist/format.d.ts +18 -26
- package/dist/format.js +7 -171
- package/dist/format.js.map +1 -1
- package/dist/index.cjs +250 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -74
- package/dist/index.d.ts +110 -74
- package/dist/index.js +228 -23
- package/dist/index.js.map +1 -1
- package/dist/language.cjs +9 -9
- package/dist/language.d.cts +12 -12
- package/dist/language.d.ts +12 -12
- package/dist/language.js +3 -3
- package/dist/lexer.cjs +16 -16
- package/dist/lexer.d.cts +3 -3
- package/dist/lexer.d.ts +3 -3
- package/dist/lexer.js +5 -5
- package/dist/normalizer.cjs +10 -10
- package/dist/normalizer.d.cts +3 -3
- package/dist/normalizer.d.ts +3 -3
- package/dist/normalizer.js +4 -4
- package/dist/packages.cjs +45 -36
- package/dist/packages.d.cts +135 -31
- package/dist/packages.d.ts +135 -31
- package/dist/packages.js +14 -13
- package/dist/parser.cjs +16 -16
- package/dist/parser.d.cts +6 -5
- package/dist/parser.d.ts +6 -5
- package/dist/parser.js +6 -6
- package/dist/{pipeline-BEb3hujr.d.cts → pipeline-CtfJtPQc.d.cts} +3 -3
- package/dist/{pipeline-B6k5lCB7.d.ts → pipeline-DCd5M6Gk.d.ts} +3 -3
- package/dist/resolvers.d.cts +3 -3
- package/dist/resolvers.d.ts +3 -3
- package/dist/testing.cjs +478 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +271 -0
- package/dist/testing.d.ts +271 -0
- package/dist/testing.js +470 -0
- package/dist/testing.js.map +1 -0
- package/dist/uom.cjs +16 -16
- package/dist/uom.d.cts +3 -3
- package/dist/uom.d.ts +3 -3
- package/dist/uom.js +6 -6
- package/dist/utilities.cjs +6 -5
- package/dist/utilities.js +2 -1
- package/dist/vm.cjs +34 -34
- package/dist/vm.d.cts +8 -8
- package/dist/vm.d.ts +8 -8
- package/dist/vm.js +9 -9
- package/dist/worker.cjs +493 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.cts +509 -0
- package/dist/worker.d.ts +509 -0
- package/dist/worker.js +484 -0
- package/dist/worker.js.map +1 -0
- package/package.json +21 -1
- package/dist/chunk-3D7V24DG.js.map +0 -1
- package/dist/chunk-3LAEG75D.js.map +0 -1
- package/dist/chunk-4B2CNWQU.cjs.map +0 -1
- package/dist/chunk-524F3ATQ.cjs.map +0 -1
- package/dist/chunk-526PMQOA.js.map +0 -1
- package/dist/chunk-5KMIY374.cjs.map +0 -1
- package/dist/chunk-5LI5EPGJ.cjs.map +0 -1
- package/dist/chunk-5WVP4YHP.js.map +0 -1
- package/dist/chunk-5X2PTP6F.cjs.map +0 -1
- package/dist/chunk-6KFYJ6TD.cjs.map +0 -1
- package/dist/chunk-6WFMPTGB.cjs.map +0 -1
- package/dist/chunk-7FSDNNNC.js.map +0 -1
- package/dist/chunk-AJA6LUI7.js.map +0 -1
- package/dist/chunk-FQGX2PA2.js.map +0 -1
- package/dist/chunk-GQCOSXMG.js.map +0 -1
- package/dist/chunk-HBVFFBRR.cjs.map +0 -1
- package/dist/chunk-HDP7VK3C.cjs.map +0 -1
- package/dist/chunk-HVQFNJKE.cjs.map +0 -1
- package/dist/chunk-IF532O7C.js.map +0 -1
- package/dist/chunk-JMXUNXQS.cjs.map +0 -1
- package/dist/chunk-KV7UW6T6.js.map +0 -1
- package/dist/chunk-NG2JHZHE.js.map +0 -1
- package/dist/chunk-O3ANBHSA.js.map +0 -1
- package/dist/chunk-PA4VC73I.cjs.map +0 -1
- package/dist/chunk-PFUESQTW.cjs.map +0 -1
- package/dist/chunk-R3PY4G7J.js.map +0 -1
- package/dist/chunk-R7YVBHCV.cjs.map +0 -1
- package/dist/chunk-SESSWASV.cjs.map +0 -1
- package/dist/chunk-TY3TLZAW.cjs.map +0 -1
- package/dist/chunk-UM6BVY2S.cjs.map +0 -1
- package/dist/chunk-UQ3UIZJC.js.map +0 -1
- package/dist/chunk-VB37OC6I.js.map +0 -1
- package/dist/chunk-Y7FT4IQT.js.map +0 -1
- package/dist/chunk-YXCTLWOH.js.map +0 -1
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkFEAIOR7N_cjs = require('./chunk-FEAIOR7N.cjs');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
4
|
+
var chunkZVTWQLK4_cjs = require('./chunk-ZVTWQLK4.cjs');
|
|
5
|
+
var chunkHIQ5HSZL_cjs = require('./chunk-HIQ5HSZL.cjs');
|
|
6
|
+
var chunk2TZKENDH_cjs = require('./chunk-2TZKENDH.cjs');
|
|
7
|
+
var chunkEJ3ILXX6_cjs = require('./chunk-EJ3ILXX6.cjs');
|
|
8
8
|
var chunkAMOJYLG2_cjs = require('./chunk-AMOJYLG2.cjs');
|
|
9
|
-
var
|
|
9
|
+
var chunkB4HBEFTB_cjs = require('./chunk-B4HBEFTB.cjs');
|
|
10
10
|
|
|
11
11
|
// src/symbolic/MultivariateFactor.ts
|
|
12
12
|
function exactRoot(value, degree) {
|
|
13
|
-
const rootOf = degree === 2 ?
|
|
13
|
+
const rootOf = degree === 2 ? chunkHIQ5HSZL_cjs.exactIntegerSqrt : chunkHIQ5HSZL_cjs.exactIntegerCbrt;
|
|
14
14
|
const numerator = rootOf(value.n);
|
|
15
15
|
const denominator = rootOf(value.d);
|
|
16
16
|
return numerator === null || denominator === null ? null : { n: numerator, d: denominator };
|
|
17
17
|
}
|
|
18
18
|
function monomialRoot(key, degree) {
|
|
19
|
-
const monomial =
|
|
19
|
+
const monomial = chunkHIQ5HSZL_cjs.monomialFromKey(key);
|
|
20
20
|
const root = /* @__PURE__ */ new Map();
|
|
21
21
|
for (const [name, exponent] of monomial) {
|
|
22
22
|
if (exponent % degree !== 0) return null;
|
|
23
23
|
root.set(name, exponent / degree);
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return chunkHIQ5HSZL_cjs.monomialToKey(root);
|
|
26
26
|
}
|
|
27
27
|
function monomialMul(a, b) {
|
|
28
|
-
const product2 =
|
|
29
|
-
for (const [name, exponent] of
|
|
28
|
+
const product2 = chunkHIQ5HSZL_cjs.monomialFromKey(a);
|
|
29
|
+
for (const [name, exponent] of chunkHIQ5HSZL_cjs.monomialFromKey(b)) {
|
|
30
30
|
product2.set(name, (product2.get(name) ?? 0) + exponent);
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return chunkHIQ5HSZL_cjs.monomialToKey(product2);
|
|
33
33
|
}
|
|
34
34
|
function monomialDiv(a, b) {
|
|
35
|
-
const quotient =
|
|
36
|
-
for (const [name, exponent] of
|
|
35
|
+
const quotient = chunkHIQ5HSZL_cjs.monomialFromKey(a);
|
|
36
|
+
for (const [name, exponent] of chunkHIQ5HSZL_cjs.monomialFromKey(b)) {
|
|
37
37
|
const remaining = (quotient.get(name) ?? 0) - exponent;
|
|
38
38
|
if (remaining <= 0) quotient.delete(name);
|
|
39
39
|
else quotient.set(name, remaining);
|
|
40
40
|
}
|
|
41
|
-
return
|
|
41
|
+
return chunkHIQ5HSZL_cjs.monomialToKey(quotient);
|
|
42
42
|
}
|
|
43
43
|
function monomialGcd(a, b) {
|
|
44
|
-
const left =
|
|
44
|
+
const left = chunkHIQ5HSZL_cjs.monomialFromKey(a);
|
|
45
45
|
const shared = /* @__PURE__ */ new Map();
|
|
46
|
-
for (const [name, exponent] of
|
|
46
|
+
for (const [name, exponent] of chunkHIQ5HSZL_cjs.monomialFromKey(b)) {
|
|
47
47
|
const other = left.get(name);
|
|
48
48
|
if (other !== void 0) shared.set(name, Math.min(other, exponent));
|
|
49
49
|
}
|
|
50
|
-
return
|
|
50
|
+
return chunkHIQ5HSZL_cjs.monomialToKey(shared);
|
|
51
51
|
}
|
|
52
52
|
function namesOf(keys) {
|
|
53
53
|
const names = /* @__PURE__ */ new Set();
|
|
54
|
-
for (const key of keys) for (const name of
|
|
54
|
+
for (const key of keys) for (const name of chunkHIQ5HSZL_cjs.monomialFromKey(key).keys()) names.add(name);
|
|
55
55
|
return [...names].sort();
|
|
56
56
|
}
|
|
57
57
|
function termsToNode(terms) {
|
|
58
58
|
const map = /* @__PURE__ */ new Map();
|
|
59
59
|
for (const term of terms) map.set(term.key, term.coefficient);
|
|
60
|
-
return
|
|
60
|
+
return chunkHIQ5HSZL_cjs.fromPolynomial({ terms: map, vars: namesOf(terms.map((term) => term.key)) });
|
|
61
61
|
}
|
|
62
62
|
function product(factors) {
|
|
63
63
|
let result = factors[0];
|
|
@@ -66,7 +66,7 @@ function product(factors) {
|
|
|
66
66
|
}
|
|
67
67
|
function orderedTerms(p) {
|
|
68
68
|
const terms = [...p.terms].map(([key, coefficient]) => ({ key, coefficient }));
|
|
69
|
-
return terms.sort((a, b) =>
|
|
69
|
+
return terms.sort((a, b) => chunkHIQ5HSZL_cjs.compareMonomials(a.key, b.key, p.vars));
|
|
70
70
|
}
|
|
71
71
|
function factorMultivariate(p) {
|
|
72
72
|
if (p.vars.length < 2) return null;
|
|
@@ -94,7 +94,7 @@ function factorBinomial(first, second) {
|
|
|
94
94
|
return product([linear, termsToNode([squareOf(cubes.a), middle, squareOf(cubes.b)])]);
|
|
95
95
|
}
|
|
96
96
|
function asPowerPair(first, second, degree) {
|
|
97
|
-
const magnitude2 = second.coefficient.n < 0n ?
|
|
97
|
+
const magnitude2 = second.coefficient.n < 0n ? chunkHIQ5HSZL_cjs.rationalNeg(second.coefficient) : second.coefficient;
|
|
98
98
|
const firstRoot = exactRoot(first.coefficient, degree);
|
|
99
99
|
const secondRoot = exactRoot(magnitude2, degree);
|
|
100
100
|
if (firstRoot === null || secondRoot === null) return null;
|
|
@@ -104,10 +104,10 @@ function asPowerPair(first, second, degree) {
|
|
|
104
104
|
return { a: { key: firstKey, coefficient: firstRoot }, b: { key: secondKey, coefficient: secondRoot } };
|
|
105
105
|
}
|
|
106
106
|
function negated(term) {
|
|
107
|
-
return { key: term.key, coefficient:
|
|
107
|
+
return { key: term.key, coefficient: chunkHIQ5HSZL_cjs.rationalNeg(term.coefficient) };
|
|
108
108
|
}
|
|
109
109
|
function multiplyTerms(a, b) {
|
|
110
|
-
return { key: monomialMul(a.key, b.key), coefficient:
|
|
110
|
+
return { key: monomialMul(a.key, b.key), coefficient: chunkHIQ5HSZL_cjs.rationalMul(a.coefficient, b.coefficient) };
|
|
111
111
|
}
|
|
112
112
|
function squareOf(term) {
|
|
113
113
|
return multiplyTerms(term, term);
|
|
@@ -119,12 +119,12 @@ function factorPerfectSquare(terms) {
|
|
|
119
119
|
if (roots === null) return null;
|
|
120
120
|
const cross = multiplyTerms(roots.a, roots.b);
|
|
121
121
|
if (cross.key !== middle.key) return null;
|
|
122
|
-
const twice =
|
|
122
|
+
const twice = chunkHIQ5HSZL_cjs.rationalMul(cross.coefficient, { n: 2n, d: 1n });
|
|
123
123
|
const negative = middle.coefficient.n < 0n;
|
|
124
|
-
const magnitude2 = negative ?
|
|
125
|
-
if (!
|
|
124
|
+
const magnitude2 = negative ? chunkHIQ5HSZL_cjs.rationalNeg(middle.coefficient) : middle.coefficient;
|
|
125
|
+
if (!chunkHIQ5HSZL_cjs.isRationalOne(chunkHIQ5HSZL_cjs.rationalDiv(magnitude2, twice))) return null;
|
|
126
126
|
const base = termsToNode([roots.a, negative ? negated(roots.b) : roots.b]);
|
|
127
|
-
return { kind: "pow", base, exponent:
|
|
127
|
+
return { kind: "pow", base, exponent: chunkHIQ5HSZL_cjs.constNode(2) };
|
|
128
128
|
}
|
|
129
129
|
function factorByGrouping(terms) {
|
|
130
130
|
const pairings = [
|
|
@@ -149,7 +149,7 @@ function splitPair(first, second) {
|
|
|
149
149
|
const common = { key: shared, coefficient: first.coefficient };
|
|
150
150
|
const cofactor = [
|
|
151
151
|
{ key: monomialDiv(first.key, shared), coefficient: { n: 1n, d: 1n } },
|
|
152
|
-
{ key: monomialDiv(second.key, shared), coefficient:
|
|
152
|
+
{ key: monomialDiv(second.key, shared), coefficient: chunkHIQ5HSZL_cjs.rationalDiv(second.coefficient, first.coefficient) }
|
|
153
153
|
];
|
|
154
154
|
return cofactor[0].key === cofactor[1].key ? null : { common, cofactor };
|
|
155
155
|
}
|
|
@@ -189,14 +189,14 @@ function divisors(value) {
|
|
|
189
189
|
return found;
|
|
190
190
|
}
|
|
191
191
|
function evaluateAt(descending, x) {
|
|
192
|
-
let total =
|
|
193
|
-
for (const coeff of descending) total =
|
|
192
|
+
let total = chunkHIQ5HSZL_cjs.RATIONAL_ZERO;
|
|
193
|
+
for (const coeff of descending) total = chunkHIQ5HSZL_cjs.rationalAdd(chunkHIQ5HSZL_cjs.rationalMul(total, x), coeff);
|
|
194
194
|
return total;
|
|
195
195
|
}
|
|
196
196
|
function divideByRoot(descending, root) {
|
|
197
197
|
const quotient = [descending[0]];
|
|
198
198
|
for (let i = 1; i < descending.length - 1; i++) {
|
|
199
|
-
quotient.push(
|
|
199
|
+
quotient.push(chunkHIQ5HSZL_cjs.rationalAdd(descending[i], chunkHIQ5HSZL_cjs.rationalMul(quotient[i - 1], root)));
|
|
200
200
|
}
|
|
201
201
|
return quotient;
|
|
202
202
|
}
|
|
@@ -211,14 +211,14 @@ function rationalRoots(descending) {
|
|
|
211
211
|
const numeratorDivisors = divisors(trailing);
|
|
212
212
|
const denominatorDivisors = divisors(leading);
|
|
213
213
|
if (numeratorDivisors === null || denominatorDivisors === null) {
|
|
214
|
-
throw
|
|
214
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.execution(
|
|
215
215
|
"SYMBOLIC_FACTOR_LIMIT_EXCEEDED",
|
|
216
216
|
"This polynomial's coefficients have too many divisors to search for rational roots.",
|
|
217
217
|
{ limit: FACTOR_MAX_ROOT_CANDIDATES }
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
if (numeratorDivisors.length * denominatorDivisors.length > FACTOR_MAX_ROOT_CANDIDATES) {
|
|
221
|
-
throw
|
|
221
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.execution(
|
|
222
222
|
"SYMBOLIC_FACTOR_LIMIT_EXCEEDED",
|
|
223
223
|
"This polynomial has too many candidate rational roots to test.",
|
|
224
224
|
{ limit: FACTOR_MAX_ROOT_CANDIDATES }
|
|
@@ -233,25 +233,25 @@ function rationalRoots(descending) {
|
|
|
233
233
|
const key = `${candidate.n}/${candidate.d}`;
|
|
234
234
|
if (seen.has(key)) continue;
|
|
235
235
|
seen.add(key);
|
|
236
|
-
if (
|
|
236
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(evaluateAt(descending, candidate))) roots.push(candidate);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
return roots;
|
|
241
241
|
}
|
|
242
242
|
function linearFactorNode(variable, root) {
|
|
243
|
-
if (
|
|
244
|
-
return root.n > 0n ? { kind: "sub", left:
|
|
243
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(root)) return chunkHIQ5HSZL_cjs.varNode(variable);
|
|
244
|
+
return root.n > 0n ? { kind: "sub", left: chunkHIQ5HSZL_cjs.varNode(variable), right: chunkHIQ5HSZL_cjs.constNode(root) } : { kind: "add", left: chunkHIQ5HSZL_cjs.varNode(variable), right: chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalNeg(root)) };
|
|
245
245
|
}
|
|
246
246
|
function coefficientsToNode(descending, variable) {
|
|
247
247
|
const degree = descending.length - 1;
|
|
248
248
|
const terms = /* @__PURE__ */ new Map();
|
|
249
249
|
descending.forEach((coeff, index) => {
|
|
250
|
-
if (
|
|
250
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(coeff)) return;
|
|
251
251
|
const power3 = degree - index;
|
|
252
252
|
terms.set(power3 === 0 ? "" : power3 === 1 ? variable : `${variable}^${power3}`, coeff);
|
|
253
253
|
});
|
|
254
|
-
return
|
|
254
|
+
return chunkHIQ5HSZL_cjs.fromPolynomial({ terms, vars: terms.size > 0 ? [variable] : [] });
|
|
255
255
|
}
|
|
256
256
|
function factorUnivariate(descending, variable) {
|
|
257
257
|
const factors = [];
|
|
@@ -260,7 +260,7 @@ function factorUnivariate(descending, variable) {
|
|
|
260
260
|
while (roots.length > 0 && remaining.length > 2) {
|
|
261
261
|
for (const root of roots) {
|
|
262
262
|
let multiplicity = 0;
|
|
263
|
-
while (remaining.length > 1 &&
|
|
263
|
+
while (remaining.length > 1 && chunkHIQ5HSZL_cjs.isRationalZero(evaluateAt(remaining, root))) {
|
|
264
264
|
remaining = divideByRoot(remaining, root);
|
|
265
265
|
multiplicity++;
|
|
266
266
|
}
|
|
@@ -271,17 +271,17 @@ function factorUnivariate(descending, variable) {
|
|
|
271
271
|
const leftoverDegree = remaining.length - 1;
|
|
272
272
|
if (leftoverDegree >= 1) {
|
|
273
273
|
factors.push({ base: coefficientsToNode(remaining, variable), power: 1 });
|
|
274
|
-
return { content:
|
|
274
|
+
return { content: chunkHIQ5HSZL_cjs.RATIONAL_ONE, factors };
|
|
275
275
|
}
|
|
276
|
-
return { content: remaining.length === 1 ? remaining[0] :
|
|
276
|
+
return { content: remaining.length === 1 ? remaining[0] : chunkHIQ5HSZL_cjs.RATIONAL_ONE, factors };
|
|
277
277
|
}
|
|
278
278
|
function factorizationToNode(factorization) {
|
|
279
279
|
const pieces = [];
|
|
280
|
-
if (!
|
|
280
|
+
if (!chunkHIQ5HSZL_cjs.isRationalOne(factorization.content)) pieces.push(chunkHIQ5HSZL_cjs.constNode(factorization.content));
|
|
281
281
|
for (const factor of factorization.factors) {
|
|
282
|
-
pieces.push(factor.power === 1 ? factor.base :
|
|
282
|
+
pieces.push(factor.power === 1 ? factor.base : chunkHIQ5HSZL_cjs.powNode(factor.base, chunkHIQ5HSZL_cjs.constNode({ n: BigInt(factor.power), d: 1n })));
|
|
283
283
|
}
|
|
284
|
-
if (pieces.length === 0) return
|
|
284
|
+
if (pieces.length === 0) return chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.RATIONAL_ONE);
|
|
285
285
|
let result = pieces[0];
|
|
286
286
|
for (let i = 1; i < pieces.length; i++) result = { kind: "mul", left: result, right: pieces[i] };
|
|
287
287
|
return result;
|
|
@@ -293,7 +293,7 @@ function contentOf(p) {
|
|
|
293
293
|
numeratorGcd = gcd(numeratorGcd, coeff.n);
|
|
294
294
|
denominatorLcm = lcm(denominatorLcm, coeff.d);
|
|
295
295
|
}
|
|
296
|
-
if (numeratorGcd === 0n) return
|
|
296
|
+
if (numeratorGcd === 0n) return chunkHIQ5HSZL_cjs.RATIONAL_ONE;
|
|
297
297
|
return { n: numeratorGcd, d: denominatorLcm };
|
|
298
298
|
}
|
|
299
299
|
function extractCommonMonomial(p) {
|
|
@@ -339,48 +339,48 @@ function monomialNode(monomial) {
|
|
|
339
339
|
let result = null;
|
|
340
340
|
for (const name of names) {
|
|
341
341
|
const exponent = monomial.get(name);
|
|
342
|
-
const factor = exponent === 1 ?
|
|
342
|
+
const factor = exponent === 1 ? chunkHIQ5HSZL_cjs.varNode(name) : chunkHIQ5HSZL_cjs.powNode(chunkHIQ5HSZL_cjs.varNode(name), chunkHIQ5HSZL_cjs.constNode({ n: BigInt(exponent), d: 1n }));
|
|
343
343
|
result = result === null ? factor : { kind: "mul", left: result, right: factor };
|
|
344
344
|
}
|
|
345
345
|
return result;
|
|
346
346
|
}
|
|
347
347
|
function factorSymbolic(node) {
|
|
348
|
-
const polynomial =
|
|
348
|
+
const polynomial = chunkHIQ5HSZL_cjs.toPolynomial(node);
|
|
349
349
|
if (polynomial === null || polynomial.terms.size === 0) return node;
|
|
350
|
-
if (
|
|
350
|
+
if (chunkHIQ5HSZL_cjs.polyDegree(polynomial) > FACTOR_MAX_DEGREE) return node;
|
|
351
351
|
if (polynomial.vars.length === 0) return node;
|
|
352
352
|
const content = contentOf(polynomial);
|
|
353
|
-
const primitive =
|
|
353
|
+
const primitive = chunkHIQ5HSZL_cjs.isRationalOne(content) ? polynomial : scaleTerms(polynomial, chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.RATIONAL_ONE, content));
|
|
354
354
|
const { monomial, reduced } = extractCommonMonomial(primitive);
|
|
355
355
|
const monomialFactor = monomialNode(monomial);
|
|
356
|
-
const variable =
|
|
356
|
+
const variable = chunkHIQ5HSZL_cjs.polyUnivariateVar(reduced);
|
|
357
357
|
if (variable === null) {
|
|
358
358
|
const patterned = factorMultivariate(reduced);
|
|
359
359
|
if (patterned !== null) return assemble(content, monomialFactor, patterned);
|
|
360
360
|
const pieces2 = buildPieces(content, monomialFactor, reduced);
|
|
361
361
|
return pieces2 ?? node;
|
|
362
362
|
}
|
|
363
|
-
const descending = [...
|
|
363
|
+
const descending = [...chunkHIQ5HSZL_cjs.polyCoefficients(reduced, variable)].reverse();
|
|
364
364
|
const factorization = factorUnivariate(descending, variable);
|
|
365
|
-
const combinedContent =
|
|
366
|
-
const isUnchanged = factorization.factors.length <= 1 && (factorization.factors[0]?.power ?? 1) === 1 && monomialFactor === null &&
|
|
365
|
+
const combinedContent = chunkHIQ5HSZL_cjs.rationalMul(content, factorization.content);
|
|
366
|
+
const isUnchanged = factorization.factors.length <= 1 && (factorization.factors[0]?.power ?? 1) === 1 && monomialFactor === null && chunkHIQ5HSZL_cjs.isRationalOne(combinedContent);
|
|
367
367
|
if (isUnchanged) return node;
|
|
368
368
|
const pieces = [];
|
|
369
|
-
if (!
|
|
369
|
+
if (!chunkHIQ5HSZL_cjs.isRationalOne(combinedContent)) pieces.push(chunkHIQ5HSZL_cjs.constNode(combinedContent));
|
|
370
370
|
if (monomialFactor !== null) pieces.push(monomialFactor);
|
|
371
|
-
pieces.push(factorizationToNode({ content:
|
|
371
|
+
pieces.push(factorizationToNode({ content: chunkHIQ5HSZL_cjs.RATIONAL_ONE, factors: factorization.factors }));
|
|
372
372
|
let result = pieces[0];
|
|
373
373
|
for (let i = 1; i < pieces.length; i++) result = { kind: "mul", left: result, right: pieces[i] };
|
|
374
374
|
return result;
|
|
375
375
|
}
|
|
376
376
|
function scaleTerms(p, k) {
|
|
377
377
|
const terms = /* @__PURE__ */ new Map();
|
|
378
|
-
for (const [key, coeff] of p.terms) terms.set(key,
|
|
378
|
+
for (const [key, coeff] of p.terms) terms.set(key, chunkHIQ5HSZL_cjs.rationalMul(coeff, k));
|
|
379
379
|
return { terms, vars: p.vars };
|
|
380
380
|
}
|
|
381
381
|
function assemble(content, monomialFactor, factored) {
|
|
382
382
|
const pieces = [];
|
|
383
|
-
if (!
|
|
383
|
+
if (!chunkHIQ5HSZL_cjs.isRationalOne(content)) pieces.push(chunkHIQ5HSZL_cjs.constNode(content));
|
|
384
384
|
if (monomialFactor !== null) pieces.push(monomialFactor);
|
|
385
385
|
pieces.push(factored);
|
|
386
386
|
let result = pieces[0];
|
|
@@ -388,11 +388,11 @@ function assemble(content, monomialFactor, factored) {
|
|
|
388
388
|
return result;
|
|
389
389
|
}
|
|
390
390
|
function buildPieces(content, monomialFactor, reduced) {
|
|
391
|
-
if (monomialFactor === null &&
|
|
391
|
+
if (monomialFactor === null && chunkHIQ5HSZL_cjs.isRationalOne(content)) return null;
|
|
392
392
|
const pieces = [];
|
|
393
|
-
if (!
|
|
393
|
+
if (!chunkHIQ5HSZL_cjs.isRationalOne(content)) pieces.push(chunkHIQ5HSZL_cjs.constNode(content));
|
|
394
394
|
if (monomialFactor !== null) pieces.push(monomialFactor);
|
|
395
|
-
pieces.push(
|
|
395
|
+
pieces.push(chunkHIQ5HSZL_cjs.fromPolynomial(reduced));
|
|
396
396
|
let result = pieces[0];
|
|
397
397
|
for (let i = 1; i < pieces.length; i++) result = { kind: "mul", left: result, right: pieces[i] };
|
|
398
398
|
return result;
|
|
@@ -403,103 +403,103 @@ var TWO = { n: 2n, d: 1n };
|
|
|
403
403
|
var THREE = { n: 3n, d: 1n };
|
|
404
404
|
var FOUR = { n: 4n, d: 1n };
|
|
405
405
|
function depressCubic(a, b, c, d) {
|
|
406
|
-
const shift =
|
|
407
|
-
const p =
|
|
408
|
-
|
|
409
|
-
|
|
406
|
+
const shift = chunkHIQ5HSZL_cjs.rationalNeg(chunkHIQ5HSZL_cjs.rationalDiv(b, chunkHIQ5HSZL_cjs.rationalMul(THREE, a)));
|
|
407
|
+
const p = chunkHIQ5HSZL_cjs.rationalDiv(
|
|
408
|
+
chunkHIQ5HSZL_cjs.rationalSub(chunkHIQ5HSZL_cjs.rationalMul(THREE, chunkHIQ5HSZL_cjs.rationalMul(a, c)), chunkHIQ5HSZL_cjs.rationalMul(b, b)),
|
|
409
|
+
chunkHIQ5HSZL_cjs.rationalMul(THREE, chunkHIQ5HSZL_cjs.rationalMul(a, a))
|
|
410
410
|
);
|
|
411
|
-
const twoBCubed =
|
|
412
|
-
const nineABC =
|
|
413
|
-
const twentySevenAAD =
|
|
414
|
-
const q =
|
|
415
|
-
|
|
416
|
-
|
|
411
|
+
const twoBCubed = chunkHIQ5HSZL_cjs.rationalMul(TWO, chunkHIQ5HSZL_cjs.rationalMul(b, chunkHIQ5HSZL_cjs.rationalMul(b, b)));
|
|
412
|
+
const nineABC = chunkHIQ5HSZL_cjs.rationalMul({ n: 9n, d: 1n }, chunkHIQ5HSZL_cjs.rationalMul(a, chunkHIQ5HSZL_cjs.rationalMul(b, c)));
|
|
413
|
+
const twentySevenAAD = chunkHIQ5HSZL_cjs.rationalMul({ n: 27n, d: 1n }, chunkHIQ5HSZL_cjs.rationalMul(chunkHIQ5HSZL_cjs.rationalMul(a, a), d));
|
|
414
|
+
const q = chunkHIQ5HSZL_cjs.rationalDiv(
|
|
415
|
+
chunkHIQ5HSZL_cjs.rationalAdd(chunkHIQ5HSZL_cjs.rationalSub(twoBCubed, nineABC), twentySevenAAD),
|
|
416
|
+
chunkHIQ5HSZL_cjs.rationalMul({ n: 27n, d: 1n }, chunkHIQ5HSZL_cjs.rationalMul(a, chunkHIQ5HSZL_cjs.rationalMul(a, a)))
|
|
417
417
|
);
|
|
418
418
|
return { p, q, shift };
|
|
419
419
|
}
|
|
420
420
|
function solveCubic(a, b, c, d) {
|
|
421
421
|
const { p, q, shift } = depressCubic(a, b, c, d);
|
|
422
|
-
const discriminant =
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
422
|
+
const discriminant = chunkHIQ5HSZL_cjs.rationalNeg(
|
|
423
|
+
chunkHIQ5HSZL_cjs.rationalAdd(
|
|
424
|
+
chunkHIQ5HSZL_cjs.rationalMul(FOUR, chunkHIQ5HSZL_cjs.rationalMul(p, chunkHIQ5HSZL_cjs.rationalMul(p, p))),
|
|
425
|
+
chunkHIQ5HSZL_cjs.rationalMul({ n: 27n, d: 1n }, chunkHIQ5HSZL_cjs.rationalMul(q, q))
|
|
426
426
|
)
|
|
427
427
|
);
|
|
428
|
-
if (
|
|
428
|
+
if (chunkHIQ5HSZL_cjs.rationalCompare(discriminant, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) > 0) {
|
|
429
429
|
return { exact: [], approximate: trigonometricRoots(p, q, shift) };
|
|
430
430
|
}
|
|
431
|
-
if (
|
|
431
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(discriminant)) return { exact: repeatedCubicRoots(p, q, shift), approximate: [] };
|
|
432
432
|
return { exact: cardanoRoots(p, q, shift), approximate: [] };
|
|
433
433
|
}
|
|
434
434
|
function repeatedCubicRoots(p, q, shift) {
|
|
435
|
-
if (
|
|
436
|
-
const simple =
|
|
437
|
-
const repeated =
|
|
438
|
-
const ordered = [simple, repeated].sort(
|
|
439
|
-
return ordered.map(
|
|
435
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(p)) return [chunkHIQ5HSZL_cjs.constNode(shift)];
|
|
436
|
+
const simple = chunkHIQ5HSZL_cjs.rationalAdd(chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(THREE, q), p), shift);
|
|
437
|
+
const repeated = chunkHIQ5HSZL_cjs.rationalAdd(chunkHIQ5HSZL_cjs.rationalNeg(chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(THREE, q), chunkHIQ5HSZL_cjs.rationalMul(TWO, p))), shift);
|
|
438
|
+
const ordered = [simple, repeated].sort(chunkHIQ5HSZL_cjs.rationalCompare);
|
|
439
|
+
return ordered.map(chunkHIQ5HSZL_cjs.constNode);
|
|
440
440
|
}
|
|
441
441
|
function cardanoRoots(p, q, shift) {
|
|
442
|
-
const half =
|
|
443
|
-
const radicand =
|
|
444
|
-
|
|
445
|
-
|
|
442
|
+
const half = chunkHIQ5HSZL_cjs.rationalNeg(chunkHIQ5HSZL_cjs.rationalDiv(q, TWO));
|
|
443
|
+
const radicand = chunkHIQ5HSZL_cjs.rationalAdd(
|
|
444
|
+
chunkHIQ5HSZL_cjs.rationalMul(chunkHIQ5HSZL_cjs.rationalDiv(q, TWO), chunkHIQ5HSZL_cjs.rationalDiv(q, TWO)),
|
|
445
|
+
chunkHIQ5HSZL_cjs.rationalMul(chunkHIQ5HSZL_cjs.rationalDiv(p, THREE), chunkHIQ5HSZL_cjs.rationalMul(chunkHIQ5HSZL_cjs.rationalDiv(p, THREE), chunkHIQ5HSZL_cjs.rationalDiv(p, THREE)))
|
|
446
446
|
);
|
|
447
|
-
const inner =
|
|
448
|
-
const u = { kind: "call", name: "cbrt", args: [{ kind: "add", left:
|
|
449
|
-
const v = { kind: "call", name: "cbrt", args: [{ kind: "sub", left:
|
|
447
|
+
const inner = chunkHIQ5HSZL_cjs.surdNode(radicand);
|
|
448
|
+
const u = { kind: "call", name: "cbrt", args: [{ kind: "add", left: chunkHIQ5HSZL_cjs.constNode(half), right: inner }] };
|
|
449
|
+
const v = { kind: "call", name: "cbrt", args: [{ kind: "sub", left: chunkHIQ5HSZL_cjs.constNode(half), right: inner }] };
|
|
450
450
|
const sum = { kind: "add", left: u, right: v };
|
|
451
451
|
const difference = { kind: "sub", left: u, right: v };
|
|
452
|
-
const real = { kind: "add", left:
|
|
452
|
+
const real = { kind: "add", left: chunkHIQ5HSZL_cjs.constNode(shift), right: { kind: "div", left: { kind: "neg", operand: sum }, right: chunkHIQ5HSZL_cjs.constNode(TWO) } };
|
|
453
453
|
const imaginary = {
|
|
454
454
|
kind: "mul",
|
|
455
|
-
left: { kind: "div", left: { kind: "mul", left: difference, right:
|
|
456
|
-
right:
|
|
455
|
+
left: { kind: "div", left: { kind: "mul", left: difference, right: chunkHIQ5HSZL_cjs.surdNode(THREE) }, right: chunkHIQ5HSZL_cjs.constNode(TWO) },
|
|
456
|
+
right: chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.COMPLEX_I)
|
|
457
457
|
};
|
|
458
458
|
return [
|
|
459
|
-
{ kind: "add", left:
|
|
459
|
+
{ kind: "add", left: chunkHIQ5HSZL_cjs.constNode(shift), right: sum },
|
|
460
460
|
{ kind: "sub", left: real, right: imaginary },
|
|
461
461
|
{ kind: "add", left: real, right: imaginary }
|
|
462
462
|
];
|
|
463
463
|
}
|
|
464
464
|
function trigonometricRoots(p, q, shift) {
|
|
465
|
-
const pNumber =
|
|
466
|
-
const qNumber =
|
|
467
|
-
const shiftNumber =
|
|
465
|
+
const pNumber = chunkHIQ5HSZL_cjs.rationalToNumber(p);
|
|
466
|
+
const qNumber = chunkHIQ5HSZL_cjs.rationalToNumber(q);
|
|
467
|
+
const shiftNumber = chunkHIQ5HSZL_cjs.rationalToNumber(shift);
|
|
468
468
|
const magnitude2 = 2 * Math.sqrt(-pNumber / 3);
|
|
469
469
|
const ratio = 3 * qNumber / (2 * pNumber) * Math.sqrt(-3 / pNumber);
|
|
470
470
|
const angle = Math.acos(Math.min(1, Math.max(-1, ratio))) / 3;
|
|
471
471
|
return [0, 1, 2].map((k) => magnitude2 * Math.cos(angle - 2 * Math.PI * k / 3) + shiftNumber).sort((left, right) => left - right);
|
|
472
472
|
}
|
|
473
473
|
function depressQuartic(b, c, d, e) {
|
|
474
|
-
const shift =
|
|
475
|
-
const bb =
|
|
476
|
-
const p =
|
|
477
|
-
const q =
|
|
478
|
-
|
|
479
|
-
|
|
474
|
+
const shift = chunkHIQ5HSZL_cjs.rationalNeg(chunkHIQ5HSZL_cjs.rationalDiv(b, FOUR));
|
|
475
|
+
const bb = chunkHIQ5HSZL_cjs.rationalMul(b, b);
|
|
476
|
+
const p = chunkHIQ5HSZL_cjs.rationalSub(c, chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(THREE, bb), { n: 8n, d: 1n }));
|
|
477
|
+
const q = chunkHIQ5HSZL_cjs.rationalAdd(
|
|
478
|
+
chunkHIQ5HSZL_cjs.rationalSub(d, chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(b, c), TWO)),
|
|
479
|
+
chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(bb, b), { n: 8n, d: 1n })
|
|
480
480
|
);
|
|
481
|
-
const r =
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
481
|
+
const r = chunkHIQ5HSZL_cjs.rationalSub(
|
|
482
|
+
chunkHIQ5HSZL_cjs.rationalAdd(
|
|
483
|
+
chunkHIQ5HSZL_cjs.rationalSub(e, chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(b, d), FOUR)),
|
|
484
|
+
chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(bb, c), { n: 16n, d: 1n })
|
|
485
485
|
),
|
|
486
|
-
|
|
486
|
+
chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalMul(THREE, chunkHIQ5HSZL_cjs.rationalMul(bb, bb)), { n: 256n, d: 1n })
|
|
487
487
|
);
|
|
488
488
|
return { p, q, r, shift };
|
|
489
489
|
}
|
|
490
490
|
function solveQuartic(a, b, c, d, e, solveQuadratic2) {
|
|
491
|
-
const monic = (value) =>
|
|
491
|
+
const monic = (value) => chunkHIQ5HSZL_cjs.rationalDiv(value, a);
|
|
492
492
|
const { p, q, r, shift } = depressQuartic(monic(b), monic(c), monic(d), monic(e));
|
|
493
|
-
const roots =
|
|
493
|
+
const roots = chunkHIQ5HSZL_cjs.isRationalZero(q) ? biquadraticRoots(p, r) : splitQuarticRoots(p, q, r, solveQuadratic2);
|
|
494
494
|
if (roots === null) return null;
|
|
495
|
-
const shifted =
|
|
495
|
+
const shifted = chunkHIQ5HSZL_cjs.isRationalZero(shift) ? roots : roots.map((root) => ({ kind: "add", left: chunkHIQ5HSZL_cjs.constNode(shift), right: root }));
|
|
496
496
|
return { exact: distinct(shifted), approximate: [] };
|
|
497
497
|
}
|
|
498
498
|
function distinct(roots) {
|
|
499
499
|
const seen = /* @__PURE__ */ new Set();
|
|
500
500
|
const unique = [];
|
|
501
501
|
for (const root of roots) {
|
|
502
|
-
const key =
|
|
502
|
+
const key = chunkHIQ5HSZL_cjs.symbolicKey(chunkHIQ5HSZL_cjs.simplifySymbolic(root));
|
|
503
503
|
if (seen.has(key)) continue;
|
|
504
504
|
seen.add(key);
|
|
505
505
|
unique.push(root);
|
|
@@ -507,51 +507,51 @@ function distinct(roots) {
|
|
|
507
507
|
return unique;
|
|
508
508
|
}
|
|
509
509
|
function biquadraticRoots(p, r) {
|
|
510
|
-
const discriminant =
|
|
511
|
-
if (
|
|
512
|
-
const root =
|
|
513
|
-
if (root !== null) return rationalSquareRoots(
|
|
510
|
+
const discriminant = chunkHIQ5HSZL_cjs.rationalSub(chunkHIQ5HSZL_cjs.rationalMul(p, p), chunkHIQ5HSZL_cjs.rationalMul(FOUR, r));
|
|
511
|
+
if (chunkHIQ5HSZL_cjs.rationalCompare(discriminant, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) < 0) return complexBiquadraticRoots(p, r);
|
|
512
|
+
const root = chunkHIQ5HSZL_cjs.exactRationalSqrt(discriminant);
|
|
513
|
+
if (root !== null) return rationalSquareRoots(chunkHIQ5HSZL_cjs.rationalNeg(p), root, chunkHIQ5HSZL_cjs.isRationalZero(discriminant));
|
|
514
514
|
return nestedSquareRoots(p, r, discriminant);
|
|
515
515
|
}
|
|
516
516
|
function rationalSquareRoots(negatedP, root, repeated) {
|
|
517
|
-
const values = repeated ? [
|
|
517
|
+
const values = repeated ? [chunkHIQ5HSZL_cjs.rationalDiv(negatedP, TWO)] : [chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalAdd(negatedP, root), TWO), chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalSub(negatedP, root), TWO)];
|
|
518
518
|
const roots = [];
|
|
519
519
|
for (const value of values) {
|
|
520
|
-
if (
|
|
521
|
-
roots.push(
|
|
520
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(value)) {
|
|
521
|
+
roots.push(chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.RATIONAL_ZERO));
|
|
522
522
|
continue;
|
|
523
523
|
}
|
|
524
|
-
const square =
|
|
524
|
+
const square = chunkHIQ5HSZL_cjs.signedSurdNode(value);
|
|
525
525
|
roots.push({ kind: "neg", operand: square }, square);
|
|
526
526
|
}
|
|
527
527
|
return roots;
|
|
528
528
|
}
|
|
529
529
|
function nestedSquareRoots(p, r, discriminant) {
|
|
530
|
-
const negatedP =
|
|
531
|
-
const surd =
|
|
532
|
-
const negativeP =
|
|
530
|
+
const negatedP = chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalNeg(p));
|
|
531
|
+
const surd = chunkHIQ5HSZL_cjs.surdNode(discriminant);
|
|
532
|
+
const negativeP = chunkHIQ5HSZL_cjs.rationalCompare(p, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) <= 0;
|
|
533
533
|
const solutions = [
|
|
534
|
-
{ node: halved({ kind: "add", left: negatedP, right: surd }), positive: negativeP ||
|
|
535
|
-
{ node: halved({ kind: "sub", left: negatedP, right: surd }), positive: negativeP &&
|
|
534
|
+
{ node: halved({ kind: "add", left: negatedP, right: surd }), positive: negativeP || chunkHIQ5HSZL_cjs.rationalCompare(r, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) <= 0 },
|
|
535
|
+
{ node: halved({ kind: "sub", left: negatedP, right: surd }), positive: negativeP && chunkHIQ5HSZL_cjs.rationalCompare(r, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) >= 0 }
|
|
536
536
|
];
|
|
537
537
|
const roots = [];
|
|
538
538
|
for (const { node, positive } of solutions) {
|
|
539
539
|
const radicand = positive ? node : { kind: "neg", operand: node };
|
|
540
540
|
const magnitude2 = { kind: "call", name: "sqrt", args: [radicand] };
|
|
541
|
-
const square = positive ? magnitude2 : { kind: "mul", left: magnitude2, right:
|
|
541
|
+
const square = positive ? magnitude2 : { kind: "mul", left: magnitude2, right: chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.COMPLEX_I) };
|
|
542
542
|
roots.push({ kind: "neg", operand: square }, square);
|
|
543
543
|
}
|
|
544
544
|
return roots;
|
|
545
545
|
}
|
|
546
546
|
function halved(node) {
|
|
547
|
-
return { kind: "div", left: node, right:
|
|
547
|
+
return { kind: "div", left: node, right: chunkHIQ5HSZL_cjs.constNode(TWO) };
|
|
548
548
|
}
|
|
549
549
|
function complexBiquadraticRoots(p, r) {
|
|
550
|
-
const centre =
|
|
551
|
-
const modulus =
|
|
552
|
-
const re = modulus === null ? nestedSurd(
|
|
553
|
-
const imaginaryMagnitude = modulus === null ? nestedSurd(
|
|
554
|
-
const im = { kind: "mul", left: imaginaryMagnitude, right:
|
|
550
|
+
const centre = chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalNeg(p), TWO);
|
|
551
|
+
const modulus = chunkHIQ5HSZL_cjs.exactRationalSqrt(r);
|
|
552
|
+
const re = modulus === null ? nestedSurd(chunkHIQ5HSZL_cjs.surdNode(r), centre) : chunkHIQ5HSZL_cjs.surdNode(chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalAdd(modulus, centre), TWO));
|
|
553
|
+
const imaginaryMagnitude = modulus === null ? nestedSurd(chunkHIQ5HSZL_cjs.surdNode(r), chunkHIQ5HSZL_cjs.rationalNeg(centre)) : chunkHIQ5HSZL_cjs.surdNode(chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalSub(modulus, centre), TWO));
|
|
554
|
+
const im = { kind: "mul", left: imaginaryMagnitude, right: chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.COMPLEX_I) };
|
|
555
555
|
const first = { kind: "add", left: re, right: im };
|
|
556
556
|
const second = { kind: "sub", left: re, right: im };
|
|
557
557
|
return [
|
|
@@ -562,28 +562,28 @@ function complexBiquadraticRoots(p, r) {
|
|
|
562
562
|
];
|
|
563
563
|
}
|
|
564
564
|
function nestedSurd(surd, offset) {
|
|
565
|
-
const shifted = offset.n >= 0n ? { kind: "add", left: surd, right:
|
|
565
|
+
const shifted = offset.n >= 0n ? { kind: "add", left: surd, right: chunkHIQ5HSZL_cjs.constNode(offset) } : { kind: "sub", left: surd, right: chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalNeg(offset)) };
|
|
566
566
|
return { kind: "call", name: "sqrt", args: [halved(shifted)] };
|
|
567
567
|
}
|
|
568
568
|
function splitQuarticRoots(p, q, r, solveQuadratic2) {
|
|
569
569
|
const resolvent = [
|
|
570
570
|
{ n: 1n, d: 1n },
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
571
|
+
chunkHIQ5HSZL_cjs.rationalMul(TWO, p),
|
|
572
|
+
chunkHIQ5HSZL_cjs.rationalSub(chunkHIQ5HSZL_cjs.rationalMul(p, p), chunkHIQ5HSZL_cjs.rationalMul(FOUR, r)),
|
|
573
|
+
chunkHIQ5HSZL_cjs.rationalNeg(chunkHIQ5HSZL_cjs.rationalMul(q, q))
|
|
574
574
|
];
|
|
575
575
|
for (const z of rationalRoots(resolvent)) {
|
|
576
|
-
if (
|
|
577
|
-
const alpha =
|
|
576
|
+
if (chunkHIQ5HSZL_cjs.rationalCompare(z, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) <= 0) continue;
|
|
577
|
+
const alpha = chunkHIQ5HSZL_cjs.exactRationalSqrt(z);
|
|
578
578
|
if (alpha === null) continue;
|
|
579
|
-
const sum =
|
|
580
|
-
const difference =
|
|
581
|
-
const beta =
|
|
582
|
-
const gamma =
|
|
579
|
+
const sum = chunkHIQ5HSZL_cjs.rationalAdd(p, z);
|
|
580
|
+
const difference = chunkHIQ5HSZL_cjs.rationalDiv(q, alpha);
|
|
581
|
+
const beta = chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalSub(sum, difference), TWO);
|
|
582
|
+
const gamma = chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalAdd(sum, difference), TWO);
|
|
583
583
|
const one2 = { n: 1n, d: 1n };
|
|
584
584
|
return [
|
|
585
585
|
...solveQuadratic2(one2, alpha, beta),
|
|
586
|
-
...solveQuadratic2(one2,
|
|
586
|
+
...solveQuadratic2(one2, chunkHIQ5HSZL_cjs.rationalNeg(alpha), gamma)
|
|
587
587
|
];
|
|
588
588
|
}
|
|
589
589
|
return null;
|
|
@@ -640,8 +640,8 @@ function differentiate(descending) {
|
|
|
640
640
|
}
|
|
641
641
|
function squareFreeDoubles(descending) {
|
|
642
642
|
const ascending = [...descending].reverse();
|
|
643
|
-
const squareFree = [...
|
|
644
|
-
const doubles = squareFree.map(
|
|
643
|
+
const squareFree = [...chunkHIQ5HSZL_cjs.squareFreePart(ascending)].reverse();
|
|
644
|
+
const doubles = squareFree.map(chunkHIQ5HSZL_cjs.rationalToNumber);
|
|
645
645
|
if (doubles.some((value) => !Number.isFinite(value))) return null;
|
|
646
646
|
return doubles;
|
|
647
647
|
}
|
|
@@ -764,59 +764,59 @@ function approximateRoots(descending) {
|
|
|
764
764
|
// src/symbolic/Solve.ts
|
|
765
765
|
var SOLVE_MAX_DEGREE = 8;
|
|
766
766
|
function evaluateRational(descending, x) {
|
|
767
|
-
let total =
|
|
768
|
-
for (const coeff of descending) total =
|
|
767
|
+
let total = chunkHIQ5HSZL_cjs.RATIONAL_ZERO;
|
|
768
|
+
for (const coeff of descending) total = chunkHIQ5HSZL_cjs.rationalAdd(chunkHIQ5HSZL_cjs.rationalMul(total, x), coeff);
|
|
769
769
|
return total;
|
|
770
770
|
}
|
|
771
771
|
function divideByRoot2(descending, root) {
|
|
772
772
|
const quotient = [descending[0]];
|
|
773
773
|
for (let i = 1; i < descending.length - 1; i++) {
|
|
774
|
-
quotient.push(
|
|
774
|
+
quotient.push(chunkHIQ5HSZL_cjs.rationalAdd(descending[i], chunkHIQ5HSZL_cjs.rationalMul(quotient[i - 1], root)));
|
|
775
775
|
}
|
|
776
776
|
return quotient;
|
|
777
777
|
}
|
|
778
778
|
function solveQuadratic(a, b, c) {
|
|
779
|
-
const discriminant =
|
|
780
|
-
const twoA =
|
|
781
|
-
if (
|
|
782
|
-
return complexQuadraticRoots(
|
|
783
|
-
}
|
|
784
|
-
if (
|
|
785
|
-
const rootN =
|
|
786
|
-
const rootD =
|
|
779
|
+
const discriminant = chunkHIQ5HSZL_cjs.rationalSub(chunkHIQ5HSZL_cjs.rationalMul(b, b), chunkHIQ5HSZL_cjs.rationalMul(rational4(), chunkHIQ5HSZL_cjs.rationalMul(a, c)));
|
|
780
|
+
const twoA = chunkHIQ5HSZL_cjs.rationalMul(rational2(), a);
|
|
781
|
+
if (chunkHIQ5HSZL_cjs.rationalCompare(discriminant, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) < 0) {
|
|
782
|
+
return complexQuadraticRoots(chunkHIQ5HSZL_cjs.rationalNeg(b), discriminant, twoA);
|
|
783
|
+
}
|
|
784
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(discriminant)) return [chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalNeg(b), twoA))];
|
|
785
|
+
const rootN = chunkHIQ5HSZL_cjs.exactIntegerSqrt(discriminant.n);
|
|
786
|
+
const rootD = chunkHIQ5HSZL_cjs.exactIntegerSqrt(discriminant.d);
|
|
787
787
|
if (rootN !== null && rootD !== null) {
|
|
788
788
|
const root = { n: rootN, d: rootD };
|
|
789
|
-
const plus =
|
|
790
|
-
const minus =
|
|
791
|
-
return
|
|
792
|
-
}
|
|
793
|
-
const surd =
|
|
794
|
-
const ascending =
|
|
795
|
-
const lower = { kind: "div", left: { kind: "sub", left:
|
|
796
|
-
const upper = { kind: "div", left: { kind: "add", left:
|
|
789
|
+
const plus = chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalAdd(chunkHIQ5HSZL_cjs.rationalNeg(b), root), twoA);
|
|
790
|
+
const minus = chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalSub(chunkHIQ5HSZL_cjs.rationalNeg(b), root), twoA);
|
|
791
|
+
return chunkHIQ5HSZL_cjs.rationalCompare(minus, plus) <= 0 ? [chunkHIQ5HSZL_cjs.constNode(minus), chunkHIQ5HSZL_cjs.constNode(plus)] : [chunkHIQ5HSZL_cjs.constNode(plus), chunkHIQ5HSZL_cjs.constNode(minus)];
|
|
792
|
+
}
|
|
793
|
+
const surd = chunkHIQ5HSZL_cjs.surdNode(discriminant);
|
|
794
|
+
const ascending = chunkHIQ5HSZL_cjs.rationalCompare(twoA, chunkHIQ5HSZL_cjs.RATIONAL_ZERO) > 0;
|
|
795
|
+
const lower = { kind: "div", left: { kind: "sub", left: chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalNeg(b)), right: surd }, right: chunkHIQ5HSZL_cjs.constNode(twoA) };
|
|
796
|
+
const upper = { kind: "div", left: { kind: "add", left: chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalNeg(b)), right: surd }, right: chunkHIQ5HSZL_cjs.constNode(twoA) };
|
|
797
797
|
return ascending ? [lower, upper] : [upper, lower];
|
|
798
798
|
}
|
|
799
799
|
function complexQuadraticRoots(negatedB, discriminant, twoA) {
|
|
800
|
-
const magnitude2 =
|
|
801
|
-
const rootN =
|
|
802
|
-
const rootD =
|
|
800
|
+
const magnitude2 = chunkHIQ5HSZL_cjs.rationalNeg(discriminant);
|
|
801
|
+
const rootN = chunkHIQ5HSZL_cjs.exactIntegerSqrt(magnitude2.n);
|
|
802
|
+
const rootD = chunkHIQ5HSZL_cjs.exactIntegerSqrt(magnitude2.d);
|
|
803
803
|
if (rootN !== null && rootD !== null) {
|
|
804
|
-
const imaginary2 =
|
|
805
|
-
const real2 =
|
|
804
|
+
const imaginary2 = chunkHIQ5HSZL_cjs.rationalDiv({ n: rootN, d: rootD }, twoA);
|
|
805
|
+
const real2 = chunkHIQ5HSZL_cjs.rationalDiv(negatedB, twoA);
|
|
806
806
|
return [
|
|
807
|
-
|
|
808
|
-
|
|
807
|
+
chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.complex(real2, chunkHIQ5HSZL_cjs.rationalNeg(imaginary2))),
|
|
808
|
+
chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.complex(real2, imaginary2))
|
|
809
809
|
];
|
|
810
810
|
}
|
|
811
|
-
const real =
|
|
812
|
-
const scaledRadicand =
|
|
813
|
-
const imaginary = { kind: "mul", left:
|
|
814
|
-
if (
|
|
811
|
+
const real = chunkHIQ5HSZL_cjs.rationalDiv(negatedB, twoA);
|
|
812
|
+
const scaledRadicand = chunkHIQ5HSZL_cjs.rationalDiv(magnitude2, chunkHIQ5HSZL_cjs.rationalMul(twoA, twoA));
|
|
813
|
+
const imaginary = { kind: "mul", left: chunkHIQ5HSZL_cjs.surdNode(scaledRadicand), right: chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.COMPLEX_I) };
|
|
814
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(real)) {
|
|
815
815
|
return [{ kind: "neg", operand: imaginary }, imaginary];
|
|
816
816
|
}
|
|
817
817
|
return [
|
|
818
|
-
{ kind: "sub", left:
|
|
819
|
-
{ kind: "add", left:
|
|
818
|
+
{ kind: "sub", left: chunkHIQ5HSZL_cjs.constNode(real), right: imaginary },
|
|
819
|
+
{ kind: "add", left: chunkHIQ5HSZL_cjs.constNode(real), right: imaginary }
|
|
820
820
|
];
|
|
821
821
|
}
|
|
822
822
|
function rational2() {
|
|
@@ -829,7 +829,7 @@ function realApproximation(value) {
|
|
|
829
829
|
return { re: value, im: 0 };
|
|
830
830
|
}
|
|
831
831
|
function solveForVariable(lhs, rhs, variable) {
|
|
832
|
-
const polynomial =
|
|
832
|
+
const polynomial = chunkHIQ5HSZL_cjs.toPolynomial({ kind: "sub", left: lhs, right: rhs });
|
|
833
833
|
if (polynomial === null) {
|
|
834
834
|
return {
|
|
835
835
|
kind: "unsupported",
|
|
@@ -837,7 +837,7 @@ function solveForVariable(lhs, rhs, variable) {
|
|
|
837
837
|
};
|
|
838
838
|
}
|
|
839
839
|
const others = polynomial.vars.filter((name) => name !== variable);
|
|
840
|
-
const degree =
|
|
840
|
+
const degree = chunkHIQ5HSZL_cjs.polyDegree(polynomial, variable);
|
|
841
841
|
if (others.length > 0) {
|
|
842
842
|
if (degree !== 1) {
|
|
843
843
|
return {
|
|
@@ -853,7 +853,7 @@ function solveForVariable(lhs, rhs, variable) {
|
|
|
853
853
|
if (degree > SOLVE_MAX_DEGREE) {
|
|
854
854
|
return { kind: "unsupported", reason: `degree ${degree} is above the supported maximum of ${SOLVE_MAX_DEGREE}` };
|
|
855
855
|
}
|
|
856
|
-
const descending = [...
|
|
856
|
+
const descending = [...chunkHIQ5HSZL_cjs.polyCoefficients(polynomial, variable)].reverse();
|
|
857
857
|
return solveUnivariate(descending);
|
|
858
858
|
}
|
|
859
859
|
function solveLinearWithOtherUnknowns(polynomial, variable) {
|
|
@@ -878,8 +878,8 @@ function solveLinearWithOtherUnknowns(polynomial, variable) {
|
|
|
878
878
|
}
|
|
879
879
|
return [...names].sort();
|
|
880
880
|
};
|
|
881
|
-
const coefficient =
|
|
882
|
-
const constant =
|
|
881
|
+
const coefficient = chunkHIQ5HSZL_cjs.fromPolynomial({ terms: coefficientTerms, vars: namesOf2(coefficientTerms) });
|
|
882
|
+
const constant = chunkHIQ5HSZL_cjs.fromPolynomial({ terms: constantTerms, vars: namesOf2(constantTerms) });
|
|
883
883
|
return {
|
|
884
884
|
kind: "roots",
|
|
885
885
|
exact: [{ kind: "div", left: { kind: "neg", operand: constant }, right: coefficient }],
|
|
@@ -899,34 +899,34 @@ function extractRationalRoots(descending) {
|
|
|
899
899
|
const roots = [];
|
|
900
900
|
let remaining = [...descending];
|
|
901
901
|
let powersOfX = 0;
|
|
902
|
-
while (remaining.length > 1 &&
|
|
902
|
+
while (remaining.length > 1 && chunkHIQ5HSZL_cjs.isRationalZero(remaining[remaining.length - 1])) {
|
|
903
903
|
remaining = remaining.slice(0, -1);
|
|
904
904
|
powersOfX++;
|
|
905
905
|
}
|
|
906
|
-
if (powersOfX > 0) roots.push(
|
|
906
|
+
if (powersOfX > 0) roots.push(chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
907
907
|
while (remaining.length > 1) {
|
|
908
908
|
const found = rationalRoots(remaining);
|
|
909
909
|
if (found.length === 0) break;
|
|
910
910
|
for (const root of found) {
|
|
911
911
|
let multiplicity = 0;
|
|
912
|
-
while (remaining.length > 1 &&
|
|
912
|
+
while (remaining.length > 1 && chunkHIQ5HSZL_cjs.isRationalZero(evaluateRational(remaining, root))) {
|
|
913
913
|
remaining = divideByRoot2(remaining, root);
|
|
914
914
|
multiplicity++;
|
|
915
915
|
}
|
|
916
916
|
if (multiplicity > 0) roots.push(root);
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
|
-
return { roots: roots.sort(
|
|
919
|
+
return { roots: roots.sort(chunkHIQ5HSZL_cjs.rationalCompare), remaining };
|
|
920
920
|
}
|
|
921
921
|
function solveUnivariate(descending) {
|
|
922
922
|
const { roots, remaining } = extractRationalRoots(descending);
|
|
923
|
-
const exact = roots.map(
|
|
923
|
+
const exact = roots.map(chunkHIQ5HSZL_cjs.constNode);
|
|
924
924
|
const approximate = [];
|
|
925
925
|
const leftoverDegree = remaining.length - 1;
|
|
926
926
|
const solvedDegree = descending.length - remaining.length;
|
|
927
927
|
if (leftoverDegree <= 0) return finish(exact, approximate, solvedDegree, 0, "");
|
|
928
928
|
if (leftoverDegree === 1) {
|
|
929
|
-
exact.push(
|
|
929
|
+
exact.push(chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalDiv(chunkHIQ5HSZL_cjs.rationalNeg(remaining[1]), remaining[0])));
|
|
930
930
|
return finish(exact, approximate, solvedDegree + 1, 0, "");
|
|
931
931
|
}
|
|
932
932
|
if (leftoverDegree === 2) {
|
|
@@ -1014,15 +1014,15 @@ function valueToSymbolic(v) {
|
|
|
1014
1014
|
if (v.type === 13 /* Error */ || v.type === 12 /* Pending */) return null;
|
|
1015
1015
|
const numeric = v.toNumber();
|
|
1016
1016
|
if (!Number.isFinite(numeric)) return null;
|
|
1017
|
-
return
|
|
1017
|
+
return chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalFromNumber(numeric));
|
|
1018
1018
|
}
|
|
1019
1019
|
function symbolicToValue(node) {
|
|
1020
|
-
const simplified =
|
|
1021
|
-
if (simplified.kind === "const") return
|
|
1022
|
-
return
|
|
1020
|
+
const simplified = chunkHIQ5HSZL_cjs.simplifySymbolic(node);
|
|
1021
|
+
if (simplified.kind === "const") return chunk2TZKENDH_cjs.numberValue(chunkHIQ5HSZL_cjs.rationalToNumber(simplified.value));
|
|
1022
|
+
return chunk2TZKENDH_cjs.symbolicValue(simplified);
|
|
1023
1023
|
}
|
|
1024
1024
|
function unsupported(what) {
|
|
1025
|
-
return
|
|
1025
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
1026
1026
|
"SYMBOLIC_UNSUPPORTED_FUNCTION",
|
|
1027
1027
|
`"${what}" cannot be applied to an expression that still contains an unknown.`
|
|
1028
1028
|
);
|
|
@@ -1031,7 +1031,7 @@ function symbolicPow(l, r) {
|
|
|
1031
1031
|
const base = valueToSymbolic(l);
|
|
1032
1032
|
const exponent = valueToSymbolic(r);
|
|
1033
1033
|
if (base === null || exponent === null) return unsupported("^");
|
|
1034
|
-
return symbolicToValue(
|
|
1034
|
+
return symbolicToValue(chunkHIQ5HSZL_cjs.powNode(base, exponent));
|
|
1035
1035
|
}
|
|
1036
1036
|
function symbolicNeg(v) {
|
|
1037
1037
|
const operand = valueToSymbolic(v);
|
|
@@ -1041,39 +1041,39 @@ function symbolicNeg(v) {
|
|
|
1041
1041
|
function symbolicBuiltin(index, args) {
|
|
1042
1042
|
const nodes = [];
|
|
1043
1043
|
for (const arg of args) {
|
|
1044
|
-
const faulted =
|
|
1044
|
+
const faulted = chunk2TZKENDH_cjs.faultedOperand(arg);
|
|
1045
1045
|
if (faulted) return faulted;
|
|
1046
1046
|
const node = valueToSymbolic(arg);
|
|
1047
1047
|
if (node === null) return unsupported(SYMBOLIC_BUILTIN_NAMES[index] ?? `builtin ${index}`);
|
|
1048
1048
|
nodes.push(node);
|
|
1049
1049
|
}
|
|
1050
1050
|
if (index === POW_BUILTIN_INDEX && nodes.length === 2) {
|
|
1051
|
-
return symbolicToValue(
|
|
1051
|
+
return symbolicToValue(chunkHIQ5HSZL_cjs.powNode(nodes[0], nodes[1]));
|
|
1052
1052
|
}
|
|
1053
1053
|
const name = SYMBOLIC_BUILTIN_NAMES[index];
|
|
1054
1054
|
if (name === void 0) return unsupported(`builtin ${index}`);
|
|
1055
|
-
return symbolicToValue(
|
|
1055
|
+
return symbolicToValue(chunkHIQ5HSZL_cjs.callNode(name, nodes));
|
|
1056
1056
|
}
|
|
1057
1057
|
function rootToValue(root) {
|
|
1058
1058
|
const value = symbolicToValue(root);
|
|
1059
|
-
if (value.type === 0 /* Number */ && !Number.isInteger(value.toNumber())) return
|
|
1059
|
+
if (value.type === 0 /* Number */ && !Number.isInteger(value.toNumber())) return chunk2TZKENDH_cjs.symbolicValue(root);
|
|
1060
1060
|
return value;
|
|
1061
1061
|
}
|
|
1062
1062
|
function approximateRootToValue(root) {
|
|
1063
|
-
if (root.im === 0) return
|
|
1064
|
-
return
|
|
1063
|
+
if (root.im === 0) return chunk2TZKENDH_cjs.numberValue(root.re);
|
|
1064
|
+
return chunk2TZKENDH_cjs.symbolicValue(chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.complex(chunkHIQ5HSZL_cjs.rationalFromNumber(root.re), chunkHIQ5HSZL_cjs.rationalFromNumber(root.im))));
|
|
1065
1065
|
}
|
|
1066
1066
|
function solveOutcomeToValue(outcome) {
|
|
1067
1067
|
switch (outcome.kind) {
|
|
1068
1068
|
case "identity":
|
|
1069
|
-
return
|
|
1069
|
+
return chunk2TZKENDH_cjs.stringValue("true for every value");
|
|
1070
1070
|
case "contradiction":
|
|
1071
|
-
return
|
|
1071
|
+
return chunk2TZKENDH_cjs.stringValue("no solution");
|
|
1072
1072
|
case "unsupported":
|
|
1073
|
-
return
|
|
1073
|
+
return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_SOLVE_UNSUPPORTED", `Cannot solve this equation: ${outcome.reason}.`);
|
|
1074
1074
|
case "incomplete": {
|
|
1075
1075
|
const found = outcome.exact.length + outcome.approximate.length;
|
|
1076
|
-
return
|
|
1076
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
1077
1077
|
"SYMBOLIC_SOLVE_INCOMPLETE",
|
|
1078
1078
|
`Only ${found} of this equation's ${found + outcome.missing} roots could be found: ${outcome.reason}.`
|
|
1079
1079
|
);
|
|
@@ -1081,9 +1081,9 @@ function solveOutcomeToValue(outcome) {
|
|
|
1081
1081
|
case "roots": {
|
|
1082
1082
|
const values = outcome.exact.map(rootToValue);
|
|
1083
1083
|
for (const approximate of outcome.approximate) values.push(approximateRootToValue(approximate));
|
|
1084
|
-
if (values.length === 0) return
|
|
1084
|
+
if (values.length === 0) return chunk2TZKENDH_cjs.stringValue("no solution");
|
|
1085
1085
|
if (values.length === 1) return values[0];
|
|
1086
|
-
return
|
|
1086
|
+
return chunk2TZKENDH_cjs.matrixValue(1, values.length, values.map((v) => v.type === 9 /* Symbolic */ ? v.value : v.toNumber()));
|
|
1087
1087
|
}
|
|
1088
1088
|
}
|
|
1089
1089
|
}
|
|
@@ -1091,7 +1091,7 @@ function solveEquationValues(lhsValue, rhsValue, variable) {
|
|
|
1091
1091
|
const lhs = valueToSymbolic(lhsValue);
|
|
1092
1092
|
const rhs = valueToSymbolic(rhsValue);
|
|
1093
1093
|
if (lhs === null || rhs === null) {
|
|
1094
|
-
return
|
|
1094
|
+
return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_NONFINITE_OPERAND", "An equation side has no exact value to solve with.");
|
|
1095
1095
|
}
|
|
1096
1096
|
return solveOutcomeToValue(solveForVariable(lhs, rhs, variable));
|
|
1097
1097
|
}
|
|
@@ -1102,15 +1102,15 @@ function unifyUom(l, r) {
|
|
|
1102
1102
|
if (l.unit === r.unit) {
|
|
1103
1103
|
return { lv: l.toNumber(), rv: r.toNumber(), unit: l.unit, sameMeasure: true };
|
|
1104
1104
|
}
|
|
1105
|
-
const lMeasure =
|
|
1106
|
-
const rMeasure =
|
|
1107
|
-
const isCurrency =
|
|
1105
|
+
const lMeasure = chunkEJ3ILXX6_cjs.getMeasure(l.unit);
|
|
1106
|
+
const rMeasure = chunkEJ3ILXX6_cjs.getMeasure(r.unit);
|
|
1107
|
+
const isCurrency = chunkZVTWQLK4_cjs.sharedCurrencyExchange.isCurrency(l.unit) && chunkZVTWQLK4_cjs.sharedCurrencyExchange.isCurrency(r.unit);
|
|
1108
1108
|
if (lMeasure && lMeasure === rMeasure) {
|
|
1109
|
-
const rvConverted =
|
|
1109
|
+
const rvConverted = chunkEJ3ILXX6_cjs.convertUnit(r.toNumber(), r.unit, l.unit);
|
|
1110
1110
|
return { lv: l.toNumber(), rv: rvConverted, unit: l.unit, sameMeasure: true };
|
|
1111
1111
|
}
|
|
1112
1112
|
if (isCurrency) {
|
|
1113
|
-
const rvConverted =
|
|
1113
|
+
const rvConverted = chunkZVTWQLK4_cjs.sharedCurrencyExchange.convertSync(r.toNumber(), r.unit, l.unit);
|
|
1114
1114
|
if (rvConverted !== null) {
|
|
1115
1115
|
return { lv: l.toNumber(), rv: rvConverted, unit: l.unit, sameMeasure: true };
|
|
1116
1116
|
}
|
|
@@ -1136,22 +1136,66 @@ function largestFiniteMagnitude(a, b, c) {
|
|
|
1136
1136
|
function compareUom(l, r) {
|
|
1137
1137
|
const { lv, rv, sameMeasure } = unifyUom(l, r);
|
|
1138
1138
|
if (!sameMeasure) return { lv, rv, equal: false, sameMeasure: false };
|
|
1139
|
+
if (l.type === 6 /* Uom */ && r.type === 6 /* Uom */ && l.unit !== void 0 && l.unit === r.unit && l.exact !== void 0 && r.exact !== void 0 && chunkZVTWQLK4_cjs.sharedCurrencyExchange.isCurrency(l.unit)) {
|
|
1140
|
+
return { lv, rv, equal: chunkHIQ5HSZL_cjs.decimalCompare(l.exact, r.exact) === 0, sameMeasure: true };
|
|
1141
|
+
}
|
|
1139
1142
|
if (lv === rv) return { lv, rv, equal: true, sameMeasure: true };
|
|
1140
1143
|
if (!Number.isFinite(lv) || !Number.isFinite(rv)) return { lv, rv, equal: false, sameMeasure: true };
|
|
1141
1144
|
const scale2 = largestFiniteMagnitude(lv, rv, r.toNumber());
|
|
1142
1145
|
return { lv, rv, equal: Math.abs(lv - rv) <= scale2 * UNIFIED_COMPARISON_TOLERANCE, sameMeasure: true };
|
|
1143
1146
|
}
|
|
1147
|
+
var MEASURE_NOUNS = {
|
|
1148
|
+
time: "duration",
|
|
1149
|
+
luminousIntensity: "luminous intensity"
|
|
1150
|
+
};
|
|
1151
|
+
var UNCOUNTABLE_MEASURES = /* @__PURE__ */ new Set(["money", "data"]);
|
|
1152
|
+
var COMBINE_VERBS = {
|
|
1153
|
+
add: "added",
|
|
1154
|
+
sub: "subtracted",
|
|
1155
|
+
mul: "multiplied",
|
|
1156
|
+
div: "divided"
|
|
1157
|
+
};
|
|
1158
|
+
function describeMeasure(unit) {
|
|
1159
|
+
if (chunkZVTWQLK4_cjs.sharedCurrencyExchange.isCurrency(unit)) return "money";
|
|
1160
|
+
const measure = chunkEJ3ILXX6_cjs.getMeasure(unit);
|
|
1161
|
+
if (measure === void 0) return void 0;
|
|
1162
|
+
return MEASURE_NOUNS[measure] ?? measure;
|
|
1163
|
+
}
|
|
1164
|
+
function withMeasureArticle(noun) {
|
|
1165
|
+
if (UNCOUNTABLE_MEASURES.has(noun)) return noun;
|
|
1166
|
+
return /^[aeiou]/.test(noun) ? `an ${noun}` : `a ${noun}`;
|
|
1167
|
+
}
|
|
1168
|
+
function describeMeasureMismatch(lUnit, rUnit, verb) {
|
|
1169
|
+
const left = lUnit === void 0 ? void 0 : describeMeasure(lUnit);
|
|
1170
|
+
const right = rUnit === void 0 ? void 0 : describeMeasure(rUnit);
|
|
1171
|
+
if (left !== void 0 && right !== void 0 && left !== right) {
|
|
1172
|
+
return `${left} and ${right} cannot be ${verb}`;
|
|
1173
|
+
}
|
|
1174
|
+
return void 0;
|
|
1175
|
+
}
|
|
1176
|
+
function combineVerb(op) {
|
|
1177
|
+
return op !== void 0 ? COMBINE_VERBS[op] ?? "combined" : "combined";
|
|
1178
|
+
}
|
|
1179
|
+
function describeConversionMismatch(fromUnit, toUnit) {
|
|
1180
|
+
const from = describeMeasure(fromUnit);
|
|
1181
|
+
const to = describeMeasure(toUnit);
|
|
1182
|
+
if (from !== void 0 && to !== void 0 && from !== to) {
|
|
1183
|
+
return `${withMeasureArticle(from)} cannot be converted to ${withMeasureArticle(to)}`;
|
|
1184
|
+
}
|
|
1185
|
+
return void 0;
|
|
1186
|
+
}
|
|
1144
1187
|
function incomparableUnitsError(l, r) {
|
|
1145
1188
|
const lUnit = l.type === 6 /* Uom */ ? l.unit : void 0;
|
|
1146
1189
|
const rUnit = r.type === 6 /* Uom */ ? r.unit : void 0;
|
|
1147
|
-
|
|
1190
|
+
const named = describeMeasureMismatch(lUnit, rUnit, "compared");
|
|
1191
|
+
return chunk2TZKENDH_cjs.errorValue("INCOMPATIBLE_UNITS", named ?? `Cannot compare incompatible units: ${lUnit ?? "?"} and ${rUnit ?? "?"}`);
|
|
1148
1192
|
}
|
|
1149
1193
|
function toBigIntOperand(v) {
|
|
1150
1194
|
if (v.type === 2 /* BigInt */) return v.value;
|
|
1151
1195
|
const n = v.toNumber();
|
|
1152
1196
|
if (!Number.isInteger(n)) {
|
|
1153
1197
|
const shown = Number.isNaN(n) ? "NaN" : String(n);
|
|
1154
|
-
throw
|
|
1198
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.execution(
|
|
1155
1199
|
"BIGINT_INEXACT_OPERAND",
|
|
1156
1200
|
`A whole-number (n) value can only be combined with another whole number, and ${shown} is not one`,
|
|
1157
1201
|
{ operand: shown }
|
|
@@ -1160,7 +1204,7 @@ function toBigIntOperand(v) {
|
|
|
1160
1204
|
return BigInt(n);
|
|
1161
1205
|
}
|
|
1162
1206
|
function bigIntDivisionByZero() {
|
|
1163
|
-
return
|
|
1207
|
+
return chunkB4HBEFTB_cjs.ErrorFactory.execution(
|
|
1164
1208
|
"BIGINT_DIVISION_BY_ZERO",
|
|
1165
1209
|
"Division by zero: a whole-number (n) division is exact integer division, which has no answer at zero, unlike 1 / 0 which is Infinity"
|
|
1166
1210
|
);
|
|
@@ -1184,6 +1228,121 @@ function power(base, exponent) {
|
|
|
1184
1228
|
if (base === -1 && !Number.isNaN(exponent)) return 1;
|
|
1185
1229
|
return Math.pow(base, exponent);
|
|
1186
1230
|
}
|
|
1231
|
+
function operandExactDecimal(v) {
|
|
1232
|
+
if (v.exact !== void 0) return v.exact;
|
|
1233
|
+
return chunkHIQ5HSZL_cjs.decimalFromNumberIfExact(v.toNumber());
|
|
1234
|
+
}
|
|
1235
|
+
function exactMoneyOp(l, r, op) {
|
|
1236
|
+
const lMoney = l.type === 6 /* Uom */ && l.unit !== void 0 && l.exact !== void 0 && chunkZVTWQLK4_cjs.sharedCurrencyExchange.isCurrency(l.unit);
|
|
1237
|
+
const rMoney = r.type === 6 /* Uom */ && r.unit !== void 0 && r.exact !== void 0 && chunkZVTWQLK4_cjs.sharedCurrencyExchange.isCurrency(r.unit);
|
|
1238
|
+
if (!lMoney && !rMoney) return null;
|
|
1239
|
+
let ld;
|
|
1240
|
+
let rd;
|
|
1241
|
+
let unit;
|
|
1242
|
+
if (lMoney && rMoney) {
|
|
1243
|
+
if (l.unit !== r.unit || op === "div") return null;
|
|
1244
|
+
ld = l.exact;
|
|
1245
|
+
rd = r.exact;
|
|
1246
|
+
unit = l.unit;
|
|
1247
|
+
} else if (lMoney && r.type !== 6 /* Uom */) {
|
|
1248
|
+
ld = l.exact;
|
|
1249
|
+
unit = l.unit;
|
|
1250
|
+
rd = operandExactDecimal(r);
|
|
1251
|
+
} else if (rMoney && l.type !== 6 /* Uom */) {
|
|
1252
|
+
rd = r.exact;
|
|
1253
|
+
unit = r.unit;
|
|
1254
|
+
ld = operandExactDecimal(l);
|
|
1255
|
+
} else {
|
|
1256
|
+
return null;
|
|
1257
|
+
}
|
|
1258
|
+
if (ld === null || rd === null) return null;
|
|
1259
|
+
let result;
|
|
1260
|
+
switch (op) {
|
|
1261
|
+
case "add":
|
|
1262
|
+
result = chunkHIQ5HSZL_cjs.decimalAdd(ld, rd);
|
|
1263
|
+
break;
|
|
1264
|
+
case "sub":
|
|
1265
|
+
result = chunkHIQ5HSZL_cjs.decimalSubtract(ld, rd);
|
|
1266
|
+
break;
|
|
1267
|
+
case "mul":
|
|
1268
|
+
result = chunkHIQ5HSZL_cjs.decimalMultiply(ld, rd);
|
|
1269
|
+
break;
|
|
1270
|
+
case "div":
|
|
1271
|
+
if (chunkHIQ5HSZL_cjs.decimalIsZero(rd)) return null;
|
|
1272
|
+
result = chunkHIQ5HSZL_cjs.decimalDivide(ld, rd);
|
|
1273
|
+
break;
|
|
1274
|
+
}
|
|
1275
|
+
return chunk2TZKENDH_cjs.uomValueExact(chunkHIQ5HSZL_cjs.decimalToNumber(result), unit, result);
|
|
1276
|
+
}
|
|
1277
|
+
function operandRational(v) {
|
|
1278
|
+
if (v.rational !== void 0) return v.rational;
|
|
1279
|
+
if ((v.type === 0 /* Number */ || v.type === 1 /* Hex */) && typeof v.value === "number" && Number.isInteger(v.value)) {
|
|
1280
|
+
return chunkHIQ5HSZL_cjs.rational(BigInt(v.value));
|
|
1281
|
+
}
|
|
1282
|
+
return null;
|
|
1283
|
+
}
|
|
1284
|
+
function exactRationalOp(l, r, op) {
|
|
1285
|
+
const lr = operandRational(l);
|
|
1286
|
+
if (lr === null) return null;
|
|
1287
|
+
const rr = operandRational(r);
|
|
1288
|
+
if (rr === null) return null;
|
|
1289
|
+
if (op === "div" && chunkHIQ5HSZL_cjs.isRationalZero(rr)) return null;
|
|
1290
|
+
let result;
|
|
1291
|
+
try {
|
|
1292
|
+
switch (op) {
|
|
1293
|
+
case "add":
|
|
1294
|
+
result = chunkHIQ5HSZL_cjs.rationalAdd(lr, rr);
|
|
1295
|
+
break;
|
|
1296
|
+
case "sub":
|
|
1297
|
+
result = chunkHIQ5HSZL_cjs.rationalSub(lr, rr);
|
|
1298
|
+
break;
|
|
1299
|
+
case "mul":
|
|
1300
|
+
result = chunkHIQ5HSZL_cjs.rationalMul(lr, rr);
|
|
1301
|
+
break;
|
|
1302
|
+
case "div":
|
|
1303
|
+
result = chunkHIQ5HSZL_cjs.rationalDiv(lr, rr);
|
|
1304
|
+
break;
|
|
1305
|
+
}
|
|
1306
|
+
} catch {
|
|
1307
|
+
return null;
|
|
1308
|
+
}
|
|
1309
|
+
return chunk2TZKENDH_cjs.numberValueRational(chunkHIQ5HSZL_cjs.rationalToNumber(result), result);
|
|
1310
|
+
}
|
|
1311
|
+
function uncertainOp(l, r, op) {
|
|
1312
|
+
if (l.type !== 0 /* Number */ || r.type !== 0 /* Number */) return null;
|
|
1313
|
+
const a = l.value;
|
|
1314
|
+
const b = r.value;
|
|
1315
|
+
const sa = l.uncertainty ?? 0;
|
|
1316
|
+
const sb = r.uncertainty ?? 0;
|
|
1317
|
+
let center;
|
|
1318
|
+
let sigma;
|
|
1319
|
+
switch (op) {
|
|
1320
|
+
case "add":
|
|
1321
|
+
center = a + b;
|
|
1322
|
+
sigma = Math.hypot(sa, sb);
|
|
1323
|
+
break;
|
|
1324
|
+
case "sub":
|
|
1325
|
+
center = a - b;
|
|
1326
|
+
sigma = Math.hypot(sa, sb);
|
|
1327
|
+
break;
|
|
1328
|
+
case "mul":
|
|
1329
|
+
center = a * b;
|
|
1330
|
+
sigma = Math.hypot(b * sa, a * sb);
|
|
1331
|
+
break;
|
|
1332
|
+
case "div":
|
|
1333
|
+
center = a / b;
|
|
1334
|
+
sigma = Math.hypot(sa / b, a * sb / (b * b));
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
return chunk2TZKENDH_cjs.numberValueUncertain(center, sigma);
|
|
1338
|
+
}
|
|
1339
|
+
function compareRationalOperands(l, r) {
|
|
1340
|
+
const lr = operandRational(l);
|
|
1341
|
+
if (lr === null) return null;
|
|
1342
|
+
const rr = operandRational(r);
|
|
1343
|
+
if (rr === null) return null;
|
|
1344
|
+
return chunkHIQ5HSZL_cjs.rationalCompare(lr, rr);
|
|
1345
|
+
}
|
|
1187
1346
|
function binaryOp(l, r, op, bigOp, symbolicOp) {
|
|
1188
1347
|
if (l.type === 13 /* Error */) return l;
|
|
1189
1348
|
if (r.type === 13 /* Error */) return r;
|
|
@@ -1193,55 +1352,60 @@ function binaryOp(l, r, op, bigOp, symbolicOp) {
|
|
|
1193
1352
|
const left = valueToSymbolic(l);
|
|
1194
1353
|
const right = valueToSymbolic(r);
|
|
1195
1354
|
if (left === null || right === null) {
|
|
1196
|
-
return
|
|
1355
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
1197
1356
|
"SYMBOLIC_NONFINITE_OPERAND",
|
|
1198
1357
|
"A symbolic expression cannot combine with a value that has no exact number (NaN or infinity)."
|
|
1199
1358
|
);
|
|
1200
1359
|
}
|
|
1201
1360
|
const node = { kind: symbolicOp, left, right };
|
|
1202
|
-
return
|
|
1361
|
+
return chunk2TZKENDH_cjs.symbolicValue(chunkHIQ5HSZL_cjs.simplifySymbolic(node));
|
|
1203
1362
|
}
|
|
1204
1363
|
if (l.type === 0 /* Number */ && r.type === 0 /* Number */) {
|
|
1205
|
-
return
|
|
1364
|
+
return chunk2TZKENDH_cjs.numberValue(op(l.value, r.value));
|
|
1206
1365
|
}
|
|
1207
1366
|
if (l.type === 2 /* BigInt */ || r.type === 2 /* BigInt */) {
|
|
1208
1367
|
const lb = toBigIntOperand(l);
|
|
1209
1368
|
const rb = toBigIntOperand(r);
|
|
1210
|
-
if (bigOp) return
|
|
1211
|
-
return
|
|
1369
|
+
if (bigOp) return chunk2TZKENDH_cjs.bigIntValue(bigOp(lb, rb));
|
|
1370
|
+
return chunk2TZKENDH_cjs.bigIntValue(lb + rb);
|
|
1212
1371
|
}
|
|
1213
1372
|
if (l.type === 6 /* Uom */ || r.type === 6 /* Uom */) {
|
|
1373
|
+
if (symbolicOp) {
|
|
1374
|
+
const exactMoney = exactMoneyOp(l, r, symbolicOp);
|
|
1375
|
+
if (exactMoney) return exactMoney;
|
|
1376
|
+
}
|
|
1214
1377
|
const { lv, rv, unit, sameMeasure } = unifyUom(l, r);
|
|
1215
1378
|
if (!sameMeasure) {
|
|
1216
1379
|
const lUnit = l.type === 6 /* Uom */ ? l.unit : void 0;
|
|
1217
1380
|
const rUnit = r.type === 6 /* Uom */ ? r.unit : void 0;
|
|
1218
|
-
|
|
1381
|
+
const named = describeMeasureMismatch(lUnit, rUnit, combineVerb(symbolicOp));
|
|
1382
|
+
return chunk2TZKENDH_cjs.errorValue("INCOMPATIBLE_UNITS", named ?? `Cannot combine incompatible units: ${lUnit ?? "?"} and ${rUnit ?? "?"}`);
|
|
1219
1383
|
}
|
|
1220
|
-
return
|
|
1384
|
+
return chunk2TZKENDH_cjs.uomValue(op(lv, rv), unit);
|
|
1221
1385
|
}
|
|
1222
1386
|
if (l.type === 7 /* Matrix */ && r.type === 7 /* Matrix */) {
|
|
1223
1387
|
const lm = l.value;
|
|
1224
1388
|
const rm = r.value;
|
|
1225
|
-
if (!
|
|
1226
|
-
return
|
|
1389
|
+
if (!chunkHIQ5HSZL_cjs.sameShape(lm, rm)) {
|
|
1390
|
+
return chunk2TZKENDH_cjs.errorValue("DIMENSION_MISMATCH", `Cannot combine matrices of different shapes: ${lm.rows}x${lm.cols} and ${rm.rows}x${rm.cols}`);
|
|
1227
1391
|
}
|
|
1228
1392
|
const result = new Array(lm.data.length);
|
|
1229
1393
|
for (let i = 0; i < lm.data.length; i++) result[i] = op(lm.data[i], rm.data[i]);
|
|
1230
|
-
return
|
|
1394
|
+
return chunk2TZKENDH_cjs.matrixValue(lm.rows, lm.cols, result);
|
|
1231
1395
|
}
|
|
1232
1396
|
if (l.type === 7 /* Matrix */) {
|
|
1233
1397
|
const lm = l.value;
|
|
1234
1398
|
const scalar = r.toNumber();
|
|
1235
1399
|
const result = lm.data.map((v) => op(v, scalar));
|
|
1236
|
-
return
|
|
1400
|
+
return chunk2TZKENDH_cjs.matrixValue(lm.rows, lm.cols, result);
|
|
1237
1401
|
}
|
|
1238
1402
|
if (r.type === 7 /* Matrix */) {
|
|
1239
1403
|
const rm = r.value;
|
|
1240
1404
|
const scalar = l.toNumber();
|
|
1241
1405
|
const result = rm.data.map((v) => op(scalar, v));
|
|
1242
|
-
return
|
|
1406
|
+
return chunk2TZKENDH_cjs.matrixValue(rm.rows, rm.cols, result);
|
|
1243
1407
|
}
|
|
1244
|
-
return
|
|
1408
|
+
return chunk2TZKENDH_cjs.numberValue(op(l.toNumber(), r.toNumber()));
|
|
1245
1409
|
}
|
|
1246
1410
|
|
|
1247
1411
|
// src/vm/OpRegistry.ts
|
|
@@ -1280,7 +1444,7 @@ var OpRegistry = class {
|
|
|
1280
1444
|
*/
|
|
1281
1445
|
allocateOpcode() {
|
|
1282
1446
|
if (this.nextOpcode > MAX_OPCODE) {
|
|
1283
|
-
throw
|
|
1447
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.config(
|
|
1284
1448
|
"OPCODE_POOL_EXHAUSTED",
|
|
1285
1449
|
`OpRegistry: dynamic opcode pool exhausted (max ${MAX_OPCODE - DYNAMIC_OPCODE_START} allocations).`
|
|
1286
1450
|
);
|
|
@@ -1290,38 +1454,89 @@ var OpRegistry = class {
|
|
|
1290
1454
|
};
|
|
1291
1455
|
var sharedOpRegistry = new OpRegistry();
|
|
1292
1456
|
|
|
1457
|
+
// src/vm/MoneyExact.ts
|
|
1458
|
+
var ONE_DECIMAL = chunkHIQ5HSZL_cjs.decimalFromInteger(1);
|
|
1459
|
+
function moneyExactMagnitude(operand, unit) {
|
|
1460
|
+
if (!chunkZVTWQLK4_cjs.sharedCurrencyExchange.isCurrency(unit)) return null;
|
|
1461
|
+
return operand.exact ?? chunkHIQ5HSZL_cjs.decimalFromNumberIfExact(operand.toNumber());
|
|
1462
|
+
}
|
|
1463
|
+
function decimalFromShortDecimal(n) {
|
|
1464
|
+
if (!Number.isFinite(n)) return null;
|
|
1465
|
+
if (Number.isInteger(n)) return chunkHIQ5HSZL_cjs.decimalFromInteger(BigInt(n));
|
|
1466
|
+
const s = String(n);
|
|
1467
|
+
if (!/^-?\d+\.\d+$/.test(s)) return null;
|
|
1468
|
+
return chunkHIQ5HSZL_cjs.decimalFromLiteral(s);
|
|
1469
|
+
}
|
|
1470
|
+
function scaleMoneyExact(amount, factor, unit) {
|
|
1471
|
+
const base = moneyExactMagnitude(amount, unit);
|
|
1472
|
+
const factorDecimal = decimalFromShortDecimal(factor);
|
|
1473
|
+
if (base !== null && factorDecimal !== null) {
|
|
1474
|
+
const result = chunkHIQ5HSZL_cjs.decimalMultiply(base, factorDecimal);
|
|
1475
|
+
return chunk2TZKENDH_cjs.uomValueExact(chunkHIQ5HSZL_cjs.decimalToNumber(result), unit, result);
|
|
1476
|
+
}
|
|
1477
|
+
return chunk2TZKENDH_cjs.uomValue(amount.toNumber() * factor, unit);
|
|
1478
|
+
}
|
|
1479
|
+
function scaleMoneyByPercent(money, unit, percent, sign) {
|
|
1480
|
+
const base = moneyExactMagnitude(money, unit);
|
|
1481
|
+
const percentDecimal = decimalFromShortDecimal(percent);
|
|
1482
|
+
if (base !== null && percentDecimal !== null) {
|
|
1483
|
+
const factor = chunkHIQ5HSZL_cjs.decimalAdd(ONE_DECIMAL, sign === 1 ? percentDecimal : chunkHIQ5HSZL_cjs.decimalNegate(percentDecimal));
|
|
1484
|
+
const result = chunkHIQ5HSZL_cjs.decimalMultiply(base, factor);
|
|
1485
|
+
return chunk2TZKENDH_cjs.uomValueExact(chunkHIQ5HSZL_cjs.decimalToNumber(result), unit, result);
|
|
1486
|
+
}
|
|
1487
|
+
return chunk2TZKENDH_cjs.uomValue(money.toNumber() * (1 + sign * percent), unit);
|
|
1488
|
+
}
|
|
1489
|
+
function onePlusRateDecimal(rate) {
|
|
1490
|
+
const rateDecimal = decimalFromShortDecimal(rate);
|
|
1491
|
+
return rateDecimal === null ? null : chunkHIQ5HSZL_cjs.decimalAdd(ONE_DECIMAL, rateDecimal);
|
|
1492
|
+
}
|
|
1493
|
+
function removeTaxExact(money, unit, rate) {
|
|
1494
|
+
const base = moneyExactMagnitude(money, unit);
|
|
1495
|
+
const divisor = onePlusRateDecimal(rate);
|
|
1496
|
+
if (base === null || divisor === null || chunkHIQ5HSZL_cjs.decimalIsZero(divisor)) return null;
|
|
1497
|
+
const quotient = chunkHIQ5HSZL_cjs.decimalDivide(base, divisor);
|
|
1498
|
+
return chunk2TZKENDH_cjs.uomValueExact(chunkHIQ5HSZL_cjs.decimalToNumber(quotient), unit, quotient);
|
|
1499
|
+
}
|
|
1500
|
+
function taxInExact(money, unit, rate) {
|
|
1501
|
+
const base = moneyExactMagnitude(money, unit);
|
|
1502
|
+
const divisor = onePlusRateDecimal(rate);
|
|
1503
|
+
if (base === null || divisor === null || chunkHIQ5HSZL_cjs.decimalIsZero(divisor)) return null;
|
|
1504
|
+
const tax = chunkHIQ5HSZL_cjs.decimalSubtract(base, chunkHIQ5HSZL_cjs.decimalDivide(base, divisor));
|
|
1505
|
+
return chunk2TZKENDH_cjs.uomValueExact(chunkHIQ5HSZL_cjs.decimalToNumber(tax), unit, tax);
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1293
1508
|
// src/symbolic/PartialFractions.ts
|
|
1294
1509
|
var APART_MAX_DEGREE = 12;
|
|
1295
1510
|
function multiply2(a, b) {
|
|
1296
1511
|
if (a.length === 0 || b.length === 0) return [];
|
|
1297
|
-
const product2 = new Array(a.length + b.length - 1).fill(
|
|
1512
|
+
const product2 = new Array(a.length + b.length - 1).fill(chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
1298
1513
|
a.forEach((left, i) => {
|
|
1299
1514
|
b.forEach((right, j) => {
|
|
1300
|
-
product2[i + j] =
|
|
1515
|
+
product2[i + j] = chunkHIQ5HSZL_cjs.rationalAdd(product2[i + j], chunkHIQ5HSZL_cjs.rationalMul(left, right));
|
|
1301
1516
|
});
|
|
1302
1517
|
});
|
|
1303
1518
|
return product2;
|
|
1304
1519
|
}
|
|
1305
1520
|
function power2(base, exponent) {
|
|
1306
|
-
let result = [
|
|
1521
|
+
let result = [chunkHIQ5HSZL_cjs.RATIONAL_ONE];
|
|
1307
1522
|
for (let i = 0; i < exponent; i++) result = multiply2(result, base);
|
|
1308
1523
|
return result;
|
|
1309
1524
|
}
|
|
1310
1525
|
function scale(coefficients, factor) {
|
|
1311
|
-
return coefficients.map((coefficient) =>
|
|
1526
|
+
return coefficients.map((coefficient) => chunkHIQ5HSZL_cjs.rationalDiv(coefficient, factor));
|
|
1312
1527
|
}
|
|
1313
1528
|
function denominatorFactors(ascending, variable) {
|
|
1314
1529
|
const factors = [];
|
|
1315
1530
|
let lowest = 0;
|
|
1316
|
-
while (lowest < ascending.length &&
|
|
1317
|
-
if (lowest > 0) factors.push({ base: [
|
|
1531
|
+
while (lowest < ascending.length && chunkHIQ5HSZL_cjs.isRationalZero(ascending[lowest])) lowest++;
|
|
1532
|
+
if (lowest > 0) factors.push({ base: [chunkHIQ5HSZL_cjs.RATIONAL_ZERO, chunkHIQ5HSZL_cjs.RATIONAL_ONE], power: lowest });
|
|
1318
1533
|
const remaining = ascending.slice(lowest);
|
|
1319
1534
|
if (remaining.length > 1) {
|
|
1320
1535
|
const factorization = factorUnivariate([...remaining].reverse(), variable);
|
|
1321
1536
|
for (const factor of factorization.factors) {
|
|
1322
|
-
const polynomial =
|
|
1537
|
+
const polynomial = chunkHIQ5HSZL_cjs.toPolynomial(factor.base);
|
|
1323
1538
|
if (polynomial === null) return null;
|
|
1324
|
-
factors.push({ base: [...
|
|
1539
|
+
factors.push({ base: [...chunkHIQ5HSZL_cjs.polyCoefficients(polynomial, variable)], power: factor.power });
|
|
1325
1540
|
}
|
|
1326
1541
|
}
|
|
1327
1542
|
return factors.length > 0 ? factors : null;
|
|
@@ -1340,10 +1555,10 @@ function enumerateUnknowns(factors) {
|
|
|
1340
1555
|
}
|
|
1341
1556
|
function unknownColumn(unknown, factors, denominator) {
|
|
1342
1557
|
const divisor = power2(factors[unknown.factor].base, unknown.power);
|
|
1343
|
-
const { quotient, remainder } =
|
|
1344
|
-
if (!
|
|
1345
|
-
const shift = new Array(unknown.degree).fill(
|
|
1346
|
-
shift.push(
|
|
1558
|
+
const { quotient, remainder } = chunkHIQ5HSZL_cjs.polynomialDivide(denominator, divisor);
|
|
1559
|
+
if (!chunkHIQ5HSZL_cjs.isZeroPolynomial(remainder)) return null;
|
|
1560
|
+
const shift = new Array(unknown.degree).fill(chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
1561
|
+
shift.push(chunkHIQ5HSZL_cjs.RATIONAL_ONE);
|
|
1347
1562
|
return multiply2(quotient, shift);
|
|
1348
1563
|
}
|
|
1349
1564
|
function solveLinearSystem(matrix, target) {
|
|
@@ -1351,7 +1566,7 @@ function solveLinearSystem(matrix, target) {
|
|
|
1351
1566
|
for (let column = 0; column < size; column++) {
|
|
1352
1567
|
let pivot = -1;
|
|
1353
1568
|
for (let row = column; row < size; row++) {
|
|
1354
|
-
if (!
|
|
1569
|
+
if (!chunkHIQ5HSZL_cjs.isRationalZero(matrix[row][column])) {
|
|
1355
1570
|
pivot = row;
|
|
1356
1571
|
break;
|
|
1357
1572
|
}
|
|
@@ -1360,21 +1575,21 @@ function solveLinearSystem(matrix, target) {
|
|
|
1360
1575
|
[matrix[column], matrix[pivot]] = [matrix[pivot], matrix[column]];
|
|
1361
1576
|
[target[column], target[pivot]] = [target[pivot], target[column]];
|
|
1362
1577
|
for (let row = 0; row < size; row++) {
|
|
1363
|
-
if (row === column ||
|
|
1364
|
-
const factor =
|
|
1578
|
+
if (row === column || chunkHIQ5HSZL_cjs.isRationalZero(matrix[row][column])) continue;
|
|
1579
|
+
const factor = chunkHIQ5HSZL_cjs.rationalDiv(matrix[row][column], matrix[column][column]);
|
|
1365
1580
|
for (let k = column; k < size; k++) {
|
|
1366
|
-
matrix[row][k] =
|
|
1581
|
+
matrix[row][k] = chunkHIQ5HSZL_cjs.rationalSub(matrix[row][k], chunkHIQ5HSZL_cjs.rationalMul(factor, matrix[column][k]));
|
|
1367
1582
|
}
|
|
1368
|
-
target[row] =
|
|
1583
|
+
target[row] = chunkHIQ5HSZL_cjs.rationalSub(target[row], chunkHIQ5HSZL_cjs.rationalMul(factor, target[column]));
|
|
1369
1584
|
}
|
|
1370
1585
|
}
|
|
1371
|
-
return target.map((value, index) =>
|
|
1586
|
+
return target.map((value, index) => chunkHIQ5HSZL_cjs.rationalDiv(value, matrix[index][index]));
|
|
1372
1587
|
}
|
|
1373
1588
|
function partialFractions(numerator, denominator, variable) {
|
|
1374
1589
|
if (denominator.length < 2 || denominator.length - 1 > APART_MAX_DEGREE) return null;
|
|
1375
|
-
const shared =
|
|
1376
|
-
const reducedNumerator = shared.length > 1 ?
|
|
1377
|
-
const reducedDenominator = shared.length > 1 ?
|
|
1590
|
+
const shared = chunkHIQ5HSZL_cjs.coefficientGcd(numerator, denominator);
|
|
1591
|
+
const reducedNumerator = shared.length > 1 ? chunkHIQ5HSZL_cjs.polynomialDivide(numerator, shared).quotient : [...numerator];
|
|
1592
|
+
const reducedDenominator = shared.length > 1 ? chunkHIQ5HSZL_cjs.polynomialDivide(denominator, shared).quotient : [...denominator];
|
|
1378
1593
|
if (reducedDenominator.length === 1) {
|
|
1379
1594
|
return { polynomial: scale(reducedNumerator, reducedDenominator[0]), terms: [] };
|
|
1380
1595
|
}
|
|
@@ -1382,8 +1597,8 @@ function partialFractions(numerator, denominator, variable) {
|
|
|
1382
1597
|
const leading = reducedDenominator[reducedDenominator.length - 1];
|
|
1383
1598
|
const monicDenominator = scale(reducedDenominator, leading);
|
|
1384
1599
|
const scaledNumerator = scale(reducedNumerator, leading);
|
|
1385
|
-
const { quotient, remainder } =
|
|
1386
|
-
if (
|
|
1600
|
+
const { quotient, remainder } = chunkHIQ5HSZL_cjs.polynomialDivide(scaledNumerator, monicDenominator);
|
|
1601
|
+
if (chunkHIQ5HSZL_cjs.isZeroPolynomial(remainder)) return { polynomial: quotient, terms: [] };
|
|
1387
1602
|
const factors = denominatorFactors(monicDenominator, variable);
|
|
1388
1603
|
if (factors === null) return null;
|
|
1389
1604
|
const terms = solveForNumerators(factors, monicDenominator, remainder);
|
|
@@ -1401,10 +1616,10 @@ function solveForNumerators(factors, denominator, remainder) {
|
|
|
1401
1616
|
}
|
|
1402
1617
|
const matrix = [];
|
|
1403
1618
|
for (let row = 0; row < size; row++) {
|
|
1404
|
-
matrix.push(columns.map((column) => column[row] ??
|
|
1619
|
+
matrix.push(columns.map((column) => column[row] ?? chunkHIQ5HSZL_cjs.RATIONAL_ZERO));
|
|
1405
1620
|
}
|
|
1406
1621
|
const target = [];
|
|
1407
|
-
for (let row = 0; row < size; row++) target.push(remainder[row] ??
|
|
1622
|
+
for (let row = 0; row < size; row++) target.push(remainder[row] ?? chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
1408
1623
|
const solution = solveLinearSystem(matrix, target);
|
|
1409
1624
|
if (solution === null) return null;
|
|
1410
1625
|
return groupSolution(unknowns, solution, factors);
|
|
@@ -1420,8 +1635,8 @@ function groupSolution(unknowns, solution, factors) {
|
|
|
1420
1635
|
const terms = [];
|
|
1421
1636
|
for (const [key, coefficients] of grouped) {
|
|
1422
1637
|
const [factorIndex, termPower] = key.split(":").map(Number);
|
|
1423
|
-
const filled = [...coefficients].map((value) => value ??
|
|
1424
|
-
if (filled.every(
|
|
1638
|
+
const filled = [...coefficients].map((value) => value ?? chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
1639
|
+
if (filled.every(chunkHIQ5HSZL_cjs.isRationalZero)) continue;
|
|
1425
1640
|
terms.push({ numerator: filled, base: factors[factorIndex].base, power: termPower });
|
|
1426
1641
|
}
|
|
1427
1642
|
return terms;
|
|
@@ -1429,11 +1644,11 @@ function groupSolution(unknowns, solution, factors) {
|
|
|
1429
1644
|
function coefficientsToNode2(coefficients, variable) {
|
|
1430
1645
|
const terms = /* @__PURE__ */ new Map();
|
|
1431
1646
|
coefficients.forEach((coefficient, exponent) => {
|
|
1432
|
-
if (
|
|
1647
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(coefficient)) return;
|
|
1433
1648
|
terms.set(exponent === 0 ? "" : exponent === 1 ? variable : `${variable}^${exponent}`, coefficient);
|
|
1434
1649
|
});
|
|
1435
|
-
if (terms.size === 0) return
|
|
1436
|
-
return
|
|
1650
|
+
if (terms.size === 0) return chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
1651
|
+
return chunkHIQ5HSZL_cjs.fromPolynomial({ terms, vars: coefficients.length > 1 ? [variable] : [] });
|
|
1437
1652
|
}
|
|
1438
1653
|
function apartSymbolic(node) {
|
|
1439
1654
|
const parts = asRationalFunction(node);
|
|
@@ -1443,9 +1658,9 @@ function apartSymbolic(node) {
|
|
|
1443
1658
|
let result = decomposition.polynomial.length > 0 ? coefficientsToNode2(decomposition.polynomial, parts.variable) : null;
|
|
1444
1659
|
for (const term of decomposition.terms) {
|
|
1445
1660
|
const base = coefficientsToNode2(term.base, parts.variable);
|
|
1446
|
-
const denominator = term.power === 1 ? base :
|
|
1661
|
+
const denominator = term.power === 1 ? base : chunkHIQ5HSZL_cjs.powNode(base, chunkHIQ5HSZL_cjs.constNode({ n: BigInt(term.power), d: 1n }));
|
|
1447
1662
|
const negative = isNegativeNumerator(term.numerator);
|
|
1448
|
-
const numerator = negative ? term.numerator.map((coefficient) =>
|
|
1663
|
+
const numerator = negative ? term.numerator.map((coefficient) => chunkHIQ5HSZL_cjs.rationalNeg(coefficient)) : term.numerator;
|
|
1449
1664
|
const piece = {
|
|
1450
1665
|
kind: "div",
|
|
1451
1666
|
left: coefficientsToNode2(numerator, parts.variable),
|
|
@@ -1454,22 +1669,22 @@ function apartSymbolic(node) {
|
|
|
1454
1669
|
if (result === null) result = negative ? { kind: "neg", operand: piece } : piece;
|
|
1455
1670
|
else result = { kind: negative ? "sub" : "add", left: result, right: piece };
|
|
1456
1671
|
}
|
|
1457
|
-
return result === null ? node :
|
|
1672
|
+
return result === null ? node : chunkHIQ5HSZL_cjs.simplifySymbolic(result);
|
|
1458
1673
|
}
|
|
1459
1674
|
function isNegativeNumerator(coefficients) {
|
|
1460
1675
|
return coefficients.some((coefficient) => coefficient.n < 0n) && coefficients.every((coefficient) => coefficient.n <= 0n);
|
|
1461
1676
|
}
|
|
1462
1677
|
function asRationalFunction(node) {
|
|
1463
1678
|
if (node.kind !== "div") return null;
|
|
1464
|
-
const numerator =
|
|
1465
|
-
const denominator =
|
|
1679
|
+
const numerator = chunkHIQ5HSZL_cjs.toPolynomial(node.left);
|
|
1680
|
+
const denominator = chunkHIQ5HSZL_cjs.toPolynomial(node.right);
|
|
1466
1681
|
if (numerator === null || denominator === null) return null;
|
|
1467
|
-
const variable =
|
|
1682
|
+
const variable = chunkHIQ5HSZL_cjs.polyUnivariateVar(denominator);
|
|
1468
1683
|
if (variable === null) return null;
|
|
1469
1684
|
if (numerator.vars.some((name) => name !== variable)) return null;
|
|
1470
1685
|
return {
|
|
1471
|
-
numerator:
|
|
1472
|
-
denominator:
|
|
1686
|
+
numerator: chunkHIQ5HSZL_cjs.polyCoefficients(numerator, variable),
|
|
1687
|
+
denominator: chunkHIQ5HSZL_cjs.polyCoefficients(denominator, variable),
|
|
1473
1688
|
variable
|
|
1474
1689
|
};
|
|
1475
1690
|
}
|
|
@@ -1477,66 +1692,66 @@ function asRationalFunction(node) {
|
|
|
1477
1692
|
// src/symbolic/Derivative.ts
|
|
1478
1693
|
var DERIVATIVE_MAX_ORDER = 16;
|
|
1479
1694
|
function zero() {
|
|
1480
|
-
return
|
|
1695
|
+
return chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
1481
1696
|
}
|
|
1482
1697
|
function one() {
|
|
1483
|
-
return
|
|
1698
|
+
return chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.RATIONAL_ONE);
|
|
1484
1699
|
}
|
|
1485
1700
|
function functionDerivative(name, argument) {
|
|
1486
1701
|
switch (name) {
|
|
1487
1702
|
case "sin":
|
|
1488
|
-
return
|
|
1703
|
+
return chunkHIQ5HSZL_cjs.callNode("cos", [argument]);
|
|
1489
1704
|
case "cos":
|
|
1490
|
-
return { kind: "neg", operand:
|
|
1705
|
+
return { kind: "neg", operand: chunkHIQ5HSZL_cjs.callNode("sin", [argument]) };
|
|
1491
1706
|
case "tan":
|
|
1492
|
-
return { kind: "div", left: one(), right:
|
|
1707
|
+
return { kind: "div", left: one(), right: chunkHIQ5HSZL_cjs.powNode(chunkHIQ5HSZL_cjs.callNode("cos", [argument]), chunkHIQ5HSZL_cjs.constNode(2)) };
|
|
1493
1708
|
case "exp":
|
|
1494
|
-
return
|
|
1709
|
+
return chunkHIQ5HSZL_cjs.callNode("exp", [argument]);
|
|
1495
1710
|
case "log":
|
|
1496
1711
|
return { kind: "div", left: one(), right: argument };
|
|
1497
1712
|
case "sqrt":
|
|
1498
1713
|
return {
|
|
1499
1714
|
kind: "div",
|
|
1500
1715
|
left: one(),
|
|
1501
|
-
right: { kind: "mul", left:
|
|
1716
|
+
right: { kind: "mul", left: chunkHIQ5HSZL_cjs.constNode(2), right: chunkHIQ5HSZL_cjs.callNode("sqrt", [argument]) }
|
|
1502
1717
|
};
|
|
1503
1718
|
case "asin":
|
|
1504
|
-
return { kind: "div", left: one(), right:
|
|
1719
|
+
return { kind: "div", left: one(), right: chunkHIQ5HSZL_cjs.callNode("sqrt", [oneMinusSquare(argument)]) };
|
|
1505
1720
|
case "acos":
|
|
1506
|
-
return { kind: "neg", operand: { kind: "div", left: one(), right:
|
|
1721
|
+
return { kind: "neg", operand: { kind: "div", left: one(), right: chunkHIQ5HSZL_cjs.callNode("sqrt", [oneMinusSquare(argument)]) } };
|
|
1507
1722
|
case "atan":
|
|
1508
1723
|
return { kind: "div", left: one(), right: onePlusSquare(argument) };
|
|
1509
1724
|
case "sinh":
|
|
1510
|
-
return
|
|
1725
|
+
return chunkHIQ5HSZL_cjs.callNode("cosh", [argument]);
|
|
1511
1726
|
case "cosh":
|
|
1512
|
-
return
|
|
1727
|
+
return chunkHIQ5HSZL_cjs.callNode("sinh", [argument]);
|
|
1513
1728
|
case "tanh":
|
|
1514
|
-
return { kind: "div", left: one(), right:
|
|
1729
|
+
return { kind: "div", left: one(), right: chunkHIQ5HSZL_cjs.powNode(chunkHIQ5HSZL_cjs.callNode("cosh", [argument]), chunkHIQ5HSZL_cjs.constNode(2)) };
|
|
1515
1730
|
case "abs":
|
|
1516
|
-
return
|
|
1731
|
+
return chunkHIQ5HSZL_cjs.callNode("sign", [argument]);
|
|
1517
1732
|
default:
|
|
1518
1733
|
return null;
|
|
1519
1734
|
}
|
|
1520
1735
|
}
|
|
1521
1736
|
function oneMinusSquare(argument) {
|
|
1522
|
-
return { kind: "sub", left: one(), right:
|
|
1737
|
+
return { kind: "sub", left: one(), right: chunkHIQ5HSZL_cjs.powNode(argument, chunkHIQ5HSZL_cjs.constNode(2)) };
|
|
1523
1738
|
}
|
|
1524
1739
|
function onePlusSquare(argument) {
|
|
1525
|
-
return { kind: "add", left: one(), right:
|
|
1740
|
+
return { kind: "add", left: one(), right: chunkHIQ5HSZL_cjs.powNode(argument, chunkHIQ5HSZL_cjs.constNode(2)) };
|
|
1526
1741
|
}
|
|
1527
1742
|
function differentiate2(node, variable, order = 1) {
|
|
1528
1743
|
if (order < 0 || !Number.isInteger(order)) {
|
|
1529
|
-
throw
|
|
1744
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.execution("SYMBOLIC_DERIVATIVE_ORDER_LIMIT", "A derivative order must be a whole number, at least zero.");
|
|
1530
1745
|
}
|
|
1531
1746
|
if (order > DERIVATIVE_MAX_ORDER) {
|
|
1532
|
-
throw
|
|
1747
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.execution(
|
|
1533
1748
|
"SYMBOLIC_DERIVATIVE_ORDER_LIMIT",
|
|
1534
1749
|
`A derivative order above ${DERIVATIVE_MAX_ORDER} is not supported.`,
|
|
1535
1750
|
{ limit: DERIVATIVE_MAX_ORDER }
|
|
1536
1751
|
);
|
|
1537
1752
|
}
|
|
1538
|
-
let result =
|
|
1539
|
-
for (let i = 0; i < order; i++) result =
|
|
1753
|
+
let result = chunkHIQ5HSZL_cjs.simplifySymbolic(node);
|
|
1754
|
+
for (let i = 0; i < order; i++) result = chunkHIQ5HSZL_cjs.simplifySymbolic(derive(result, variable));
|
|
1540
1755
|
return result;
|
|
1541
1756
|
}
|
|
1542
1757
|
function derive(node, variable) {
|
|
@@ -1566,7 +1781,7 @@ function derive(node, variable) {
|
|
|
1566
1781
|
left: { kind: "mul", left: derive(node.left, variable), right: node.right },
|
|
1567
1782
|
right: { kind: "mul", left: node.left, right: derive(node.right, variable) }
|
|
1568
1783
|
},
|
|
1569
|
-
right:
|
|
1784
|
+
right: chunkHIQ5HSZL_cjs.powNode(node.right, chunkHIQ5HSZL_cjs.constNode(2))
|
|
1570
1785
|
};
|
|
1571
1786
|
case "pow":
|
|
1572
1787
|
return derivePow(node, variable);
|
|
@@ -1580,79 +1795,79 @@ function derive(node, variable) {
|
|
|
1580
1795
|
}
|
|
1581
1796
|
function derivePow(node, variable) {
|
|
1582
1797
|
if (node.exponent.kind === "const") {
|
|
1583
|
-
const reduced =
|
|
1798
|
+
const reduced = chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalSub(node.exponent.value, chunkHIQ5HSZL_cjs.RATIONAL_ONE));
|
|
1584
1799
|
return {
|
|
1585
1800
|
kind: "mul",
|
|
1586
|
-
left: { kind: "mul", left: node.exponent, right:
|
|
1801
|
+
left: { kind: "mul", left: node.exponent, right: chunkHIQ5HSZL_cjs.powNode(node.base, reduced) },
|
|
1587
1802
|
right: derive(node.base, variable)
|
|
1588
1803
|
};
|
|
1589
1804
|
}
|
|
1590
1805
|
if (node.base.kind === "const" && node.base.value.n > 0n) {
|
|
1591
1806
|
return {
|
|
1592
1807
|
kind: "mul",
|
|
1593
|
-
left: { kind: "mul", left: node, right:
|
|
1808
|
+
left: { kind: "mul", left: node, right: chunkHIQ5HSZL_cjs.callNode("log", [node.base]) },
|
|
1594
1809
|
right: derive(node.exponent, variable)
|
|
1595
1810
|
};
|
|
1596
1811
|
}
|
|
1597
1812
|
return unevaluated(node, variable);
|
|
1598
1813
|
}
|
|
1599
1814
|
function unevaluated(node, variable) {
|
|
1600
|
-
return
|
|
1815
|
+
return chunkHIQ5HSZL_cjs.callNode("der", [node, chunkHIQ5HSZL_cjs.varNode(variable)]);
|
|
1601
1816
|
}
|
|
1602
1817
|
|
|
1603
1818
|
// src/symbolic/Integral.ts
|
|
1604
1819
|
function asLinear(node, variable) {
|
|
1605
|
-
const polynomial =
|
|
1820
|
+
const polynomial = chunkHIQ5HSZL_cjs.toPolynomial(node);
|
|
1606
1821
|
if (polynomial === null) return null;
|
|
1607
1822
|
const others = polynomial.vars.filter((name) => name !== variable);
|
|
1608
1823
|
if (others.length > 0) return null;
|
|
1609
|
-
if (
|
|
1610
|
-
const ascending =
|
|
1824
|
+
if (chunkHIQ5HSZL_cjs.polyDegree(polynomial, variable) > 1) return null;
|
|
1825
|
+
const ascending = chunkHIQ5HSZL_cjs.polyCoefficients(polynomial, variable);
|
|
1611
1826
|
const intercept = ascending[0] ?? { n: 0n, d: 1n };
|
|
1612
1827
|
const slope = ascending[1] ?? { n: 0n, d: 1n };
|
|
1613
|
-
return
|
|
1828
|
+
return chunkHIQ5HSZL_cjs.isRationalZero(slope) ? null : { slope, intercept };
|
|
1614
1829
|
}
|
|
1615
1830
|
function integratePolynomial(node, variable) {
|
|
1616
|
-
const polynomial =
|
|
1831
|
+
const polynomial = chunkHIQ5HSZL_cjs.toPolynomial(node);
|
|
1617
1832
|
if (polynomial === null) return null;
|
|
1618
1833
|
const others = polynomial.vars.filter((name) => name !== variable);
|
|
1619
1834
|
if (others.length > 0) {
|
|
1620
1835
|
return { ok: false, reason: `it involves more than one unknown (${others.join(", ")})` };
|
|
1621
1836
|
}
|
|
1622
|
-
const ascending =
|
|
1623
|
-
let result =
|
|
1837
|
+
const ascending = chunkHIQ5HSZL_cjs.polyCoefficients(polynomial, variable);
|
|
1838
|
+
let result = chunkHIQ5HSZL_cjs.constNode(0);
|
|
1624
1839
|
ascending.forEach((coeff, power3) => {
|
|
1625
|
-
if (
|
|
1840
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(coeff)) return;
|
|
1626
1841
|
const nextPower = power3 + 1;
|
|
1627
|
-
const scaled =
|
|
1842
|
+
const scaled = chunkHIQ5HSZL_cjs.rationalDiv(coeff, { n: BigInt(nextPower), d: 1n });
|
|
1628
1843
|
const term = {
|
|
1629
1844
|
kind: "mul",
|
|
1630
|
-
left:
|
|
1631
|
-
right: nextPower === 1 ?
|
|
1845
|
+
left: chunkHIQ5HSZL_cjs.constNode(scaled),
|
|
1846
|
+
right: nextPower === 1 ? chunkHIQ5HSZL_cjs.varNode(variable) : chunkHIQ5HSZL_cjs.powNode(chunkHIQ5HSZL_cjs.varNode(variable), chunkHIQ5HSZL_cjs.constNode(nextPower))
|
|
1632
1847
|
};
|
|
1633
1848
|
result = { kind: "add", left: result, right: term };
|
|
1634
1849
|
});
|
|
1635
|
-
return { ok: true, value:
|
|
1850
|
+
return { ok: true, value: chunkHIQ5HSZL_cjs.simplifySymbolic(result) };
|
|
1636
1851
|
}
|
|
1637
1852
|
function integrateStandardForm(node, variable) {
|
|
1638
1853
|
if (node.kind !== "call" || node.args.length !== 1) return null;
|
|
1639
1854
|
const linear = asLinear(node.args[0], variable);
|
|
1640
1855
|
if (linear === null) return null;
|
|
1641
1856
|
const inner = node.args[0];
|
|
1642
|
-
const divideBySlope = (value) =>
|
|
1857
|
+
const divideBySlope = (value) => chunkHIQ5HSZL_cjs.simplifySymbolic({ kind: "div", left: value, right: chunkHIQ5HSZL_cjs.constNode(linear.slope) });
|
|
1643
1858
|
switch (node.name) {
|
|
1644
1859
|
case "exp":
|
|
1645
|
-
return { ok: true, value: divideBySlope(
|
|
1860
|
+
return { ok: true, value: divideBySlope(chunkHIQ5HSZL_cjs.callNode("exp", [inner])) };
|
|
1646
1861
|
case "sin":
|
|
1647
|
-
return { ok: true, value: divideBySlope({ kind: "neg", operand:
|
|
1862
|
+
return { ok: true, value: divideBySlope({ kind: "neg", operand: chunkHIQ5HSZL_cjs.callNode("cos", [inner]) }) };
|
|
1648
1863
|
case "cos":
|
|
1649
|
-
return { ok: true, value: divideBySlope(
|
|
1864
|
+
return { ok: true, value: divideBySlope(chunkHIQ5HSZL_cjs.callNode("sin", [inner])) };
|
|
1650
1865
|
case "log":
|
|
1651
1866
|
return {
|
|
1652
1867
|
ok: true,
|
|
1653
1868
|
value: divideBySlope({
|
|
1654
1869
|
kind: "sub",
|
|
1655
|
-
left: { kind: "mul", left: inner, right:
|
|
1870
|
+
left: { kind: "mul", left: inner, right: chunkHIQ5HSZL_cjs.callNode("log", [inner]) },
|
|
1656
1871
|
right: inner
|
|
1657
1872
|
})
|
|
1658
1873
|
};
|
|
@@ -1667,18 +1882,18 @@ function integrateReciprocalForms(node, variable) {
|
|
|
1667
1882
|
if (linear !== null) {
|
|
1668
1883
|
return {
|
|
1669
1884
|
ok: true,
|
|
1670
|
-
value:
|
|
1885
|
+
value: chunkHIQ5HSZL_cjs.simplifySymbolic({
|
|
1671
1886
|
kind: "div",
|
|
1672
|
-
left:
|
|
1673
|
-
right:
|
|
1887
|
+
left: chunkHIQ5HSZL_cjs.callNode("log", [node.right]),
|
|
1888
|
+
right: chunkHIQ5HSZL_cjs.constNode(linear.slope)
|
|
1674
1889
|
})
|
|
1675
1890
|
};
|
|
1676
1891
|
}
|
|
1677
|
-
const denominator =
|
|
1892
|
+
const denominator = chunkHIQ5HSZL_cjs.toPolynomial(node.right);
|
|
1678
1893
|
if (denominator !== null && denominator.vars.length === 1 && denominator.vars[0] === variable) {
|
|
1679
|
-
const ascending =
|
|
1680
|
-
const isOnePlusSquare = ascending.length === 3 && isRationalOneNode(ascending[0]) &&
|
|
1681
|
-
if (isOnePlusSquare) return { ok: true, value:
|
|
1894
|
+
const ascending = chunkHIQ5HSZL_cjs.polyCoefficients(denominator, variable);
|
|
1895
|
+
const isOnePlusSquare = ascending.length === 3 && isRationalOneNode(ascending[0]) && chunkHIQ5HSZL_cjs.isRationalZero(ascending[1]) && isRationalOneNode(ascending[2]);
|
|
1896
|
+
if (isOnePlusSquare) return { ok: true, value: chunkHIQ5HSZL_cjs.callNode("atan", [chunkHIQ5HSZL_cjs.varNode(variable)]) };
|
|
1682
1897
|
}
|
|
1683
1898
|
return null;
|
|
1684
1899
|
}
|
|
@@ -1690,7 +1905,7 @@ function integrateRationalFunction(node, variable) {
|
|
|
1690
1905
|
if (parts === null || parts.variable !== variable) return null;
|
|
1691
1906
|
const decomposition = partialFractions(parts.numerator, parts.denominator, variable);
|
|
1692
1907
|
if (decomposition === null) return null;
|
|
1693
|
-
let result = decomposition.polynomial.length > 0 ? polynomialAntiderivative(decomposition.polynomial, variable) :
|
|
1908
|
+
let result = decomposition.polynomial.length > 0 ? polynomialAntiderivative(decomposition.polynomial, variable) : chunkHIQ5HSZL_cjs.constNode(0);
|
|
1694
1909
|
for (const term of decomposition.terms) {
|
|
1695
1910
|
const piece = integrateTerm(term, variable);
|
|
1696
1911
|
if (piece === null) {
|
|
@@ -1701,72 +1916,72 @@ function integrateRationalFunction(node, variable) {
|
|
|
1701
1916
|
}
|
|
1702
1917
|
result = { kind: "add", left: result, right: piece };
|
|
1703
1918
|
}
|
|
1704
|
-
return { ok: true, value:
|
|
1919
|
+
return { ok: true, value: chunkHIQ5HSZL_cjs.simplifySymbolic(result) };
|
|
1705
1920
|
}
|
|
1706
1921
|
function integrateTerm(term, variable) {
|
|
1707
1922
|
const baseDegree = term.base.length - 1;
|
|
1708
1923
|
const base = coefficientsToNode2(term.base, variable);
|
|
1709
1924
|
if (baseDegree === 1) {
|
|
1710
|
-
const coefficient = term.numerator[0] ??
|
|
1925
|
+
const coefficient = term.numerator[0] ?? chunkHIQ5HSZL_cjs.RATIONAL_ZERO;
|
|
1711
1926
|
if (term.power === 1) {
|
|
1712
|
-
return { kind: "mul", left:
|
|
1927
|
+
return { kind: "mul", left: chunkHIQ5HSZL_cjs.constNode(coefficient), right: chunkHIQ5HSZL_cjs.callNode("log", [base]) };
|
|
1713
1928
|
}
|
|
1714
1929
|
const reduced = term.power - 1;
|
|
1715
|
-
const scaled =
|
|
1930
|
+
const scaled = chunkHIQ5HSZL_cjs.rationalDiv(coefficient, { n: BigInt(-reduced), d: 1n });
|
|
1716
1931
|
return {
|
|
1717
1932
|
kind: "div",
|
|
1718
|
-
left:
|
|
1719
|
-
right:
|
|
1933
|
+
left: chunkHIQ5HSZL_cjs.constNode(scaled),
|
|
1934
|
+
right: chunkHIQ5HSZL_cjs.powNode(base, chunkHIQ5HSZL_cjs.constNode({ n: BigInt(reduced), d: 1n }))
|
|
1720
1935
|
};
|
|
1721
1936
|
}
|
|
1722
1937
|
if (baseDegree !== 2 || term.power !== 1) return null;
|
|
1723
1938
|
return integrateQuadraticTerm(term, variable, base);
|
|
1724
1939
|
}
|
|
1725
1940
|
function integrateQuadraticTerm(term, variable, base) {
|
|
1726
|
-
const constant = term.numerator[0] ??
|
|
1727
|
-
const linear = term.numerator[1] ??
|
|
1941
|
+
const constant = term.numerator[0] ?? chunkHIQ5HSZL_cjs.RATIONAL_ZERO;
|
|
1942
|
+
const linear = term.numerator[1] ?? chunkHIQ5HSZL_cjs.RATIONAL_ZERO;
|
|
1728
1943
|
const [q, p] = term.base;
|
|
1729
1944
|
const half = { n: 1n, d: 2n };
|
|
1730
|
-
const halfP =
|
|
1945
|
+
const halfP = chunkHIQ5HSZL_cjs.rationalMul(p, half);
|
|
1731
1946
|
const logarithm = {
|
|
1732
1947
|
kind: "mul",
|
|
1733
|
-
left:
|
|
1734
|
-
right:
|
|
1948
|
+
left: chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.rationalMul(linear, half)),
|
|
1949
|
+
right: chunkHIQ5HSZL_cjs.callNode("log", [base])
|
|
1735
1950
|
};
|
|
1736
|
-
const leftover =
|
|
1737
|
-
if (
|
|
1738
|
-
const width =
|
|
1951
|
+
const leftover = chunkHIQ5HSZL_cjs.rationalSub(constant, chunkHIQ5HSZL_cjs.rationalMul(linear, halfP));
|
|
1952
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(leftover)) return logarithm;
|
|
1953
|
+
const width = chunkHIQ5HSZL_cjs.surdNode(chunkHIQ5HSZL_cjs.rationalSub(q, chunkHIQ5HSZL_cjs.rationalMul(halfP, halfP)));
|
|
1739
1954
|
const shifted = {
|
|
1740
1955
|
kind: "add",
|
|
1741
|
-
left:
|
|
1742
|
-
right:
|
|
1956
|
+
left: chunkHIQ5HSZL_cjs.varNode(variable),
|
|
1957
|
+
right: chunkHIQ5HSZL_cjs.constNode(halfP)
|
|
1743
1958
|
};
|
|
1744
1959
|
const arctangent = {
|
|
1745
1960
|
kind: "mul",
|
|
1746
|
-
left: { kind: "div", left:
|
|
1747
|
-
right:
|
|
1961
|
+
left: { kind: "div", left: chunkHIQ5HSZL_cjs.constNode(leftover), right: width },
|
|
1962
|
+
right: chunkHIQ5HSZL_cjs.callNode("atan", [{ kind: "div", left: shifted, right: width }])
|
|
1748
1963
|
};
|
|
1749
|
-
return
|
|
1964
|
+
return chunkHIQ5HSZL_cjs.isRationalZero(linear) ? arctangent : { kind: "add", left: logarithm, right: arctangent };
|
|
1750
1965
|
}
|
|
1751
1966
|
function polynomialAntiderivative(ascending, variable) {
|
|
1752
|
-
let result =
|
|
1967
|
+
let result = chunkHIQ5HSZL_cjs.constNode(0);
|
|
1753
1968
|
ascending.forEach((coeff, exponent) => {
|
|
1754
|
-
if (
|
|
1969
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(coeff)) return;
|
|
1755
1970
|
const nextPower = exponent + 1;
|
|
1756
|
-
const scaled =
|
|
1971
|
+
const scaled = chunkHIQ5HSZL_cjs.rationalDiv(coeff, { n: BigInt(nextPower), d: 1n });
|
|
1757
1972
|
const term = {
|
|
1758
1973
|
kind: "mul",
|
|
1759
|
-
left:
|
|
1760
|
-
right: nextPower === 1 ?
|
|
1974
|
+
left: chunkHIQ5HSZL_cjs.constNode(scaled),
|
|
1975
|
+
right: nextPower === 1 ? chunkHIQ5HSZL_cjs.varNode(variable) : chunkHIQ5HSZL_cjs.powNode(chunkHIQ5HSZL_cjs.varNode(variable), chunkHIQ5HSZL_cjs.constNode(nextPower))
|
|
1761
1976
|
};
|
|
1762
1977
|
result = { kind: "add", left: result, right: term };
|
|
1763
1978
|
});
|
|
1764
1979
|
return result;
|
|
1765
1980
|
}
|
|
1766
1981
|
function integrate(node, variable) {
|
|
1767
|
-
const simplified =
|
|
1768
|
-
if (!
|
|
1769
|
-
return { ok: true, value:
|
|
1982
|
+
const simplified = chunkHIQ5HSZL_cjs.simplifySymbolic(node);
|
|
1983
|
+
if (!chunkHIQ5HSZL_cjs.freeVariables(simplified).has(variable)) {
|
|
1984
|
+
return { ok: true, value: chunkHIQ5HSZL_cjs.simplifySymbolic({ kind: "mul", left: simplified, right: chunkHIQ5HSZL_cjs.varNode(variable) }) };
|
|
1770
1985
|
}
|
|
1771
1986
|
const polynomial = integratePolynomial(simplified, variable);
|
|
1772
1987
|
if (polynomial !== null) return polynomial;
|
|
@@ -1783,13 +1998,13 @@ function integrate(node, variable) {
|
|
|
1783
1998
|
if (!right.ok) return right;
|
|
1784
1999
|
return {
|
|
1785
2000
|
ok: true,
|
|
1786
|
-
value:
|
|
2001
|
+
value: chunkHIQ5HSZL_cjs.simplifySymbolic({ kind: simplified.kind, left: left.value, right: right.value })
|
|
1787
2002
|
};
|
|
1788
2003
|
}
|
|
1789
2004
|
if (simplified.kind === "mul" && simplified.left.kind === "const") {
|
|
1790
2005
|
const inner = integrate(simplified.right, variable);
|
|
1791
2006
|
if (!inner.ok) return inner;
|
|
1792
|
-
return { ok: true, value:
|
|
2007
|
+
return { ok: true, value: chunkHIQ5HSZL_cjs.simplifySymbolic({ kind: "mul", left: simplified.left, right: inner.value }) };
|
|
1793
2008
|
}
|
|
1794
2009
|
return {
|
|
1795
2010
|
ok: false,
|
|
@@ -1801,33 +2016,33 @@ function integrate(node, variable) {
|
|
|
1801
2016
|
var TAYLOR_MAX_DEGREE = 16;
|
|
1802
2017
|
function taylorSeries(node, variable, point, degree) {
|
|
1803
2018
|
if (degree < 0 || !Number.isInteger(degree) || degree > TAYLOR_MAX_DEGREE) {
|
|
1804
|
-
throw
|
|
2019
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.execution(
|
|
1805
2020
|
"SYMBOLIC_TAYLOR_DEGREE_LIMIT",
|
|
1806
2021
|
`A Taylor degree must be a whole number from 0 to ${TAYLOR_MAX_DEGREE}.`,
|
|
1807
2022
|
{ limit: TAYLOR_MAX_DEGREE }
|
|
1808
2023
|
);
|
|
1809
2024
|
}
|
|
1810
|
-
const pointNode =
|
|
2025
|
+
const pointNode = chunkHIQ5HSZL_cjs.constNode(point);
|
|
1811
2026
|
let factorial = 1n;
|
|
1812
|
-
let result =
|
|
2027
|
+
let result = chunkHIQ5HSZL_cjs.constNode(chunkHIQ5HSZL_cjs.RATIONAL_ZERO);
|
|
1813
2028
|
for (let order = 0; order <= degree; order++) {
|
|
1814
2029
|
if (order > 0) factorial *= BigInt(order);
|
|
1815
2030
|
const derivative = differentiate2(node, variable, order);
|
|
1816
|
-
const atPoint =
|
|
2031
|
+
const atPoint = chunkHIQ5HSZL_cjs.simplifySymbolic(chunkHIQ5HSZL_cjs.substitute(derivative, variable, pointNode));
|
|
1817
2032
|
if (atPoint.kind !== "const") {
|
|
1818
|
-
throw
|
|
2033
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.execution(
|
|
1819
2034
|
"SYMBOLIC_TAYLOR_INEXACT",
|
|
1820
2035
|
`The derivative of order ${order} does not reduce to an exact number at the expansion point, so this series cannot be computed exactly.`,
|
|
1821
2036
|
{ order }
|
|
1822
2037
|
);
|
|
1823
2038
|
}
|
|
1824
|
-
const coefficient =
|
|
1825
|
-
if (
|
|
1826
|
-
const shifted =
|
|
1827
|
-
const power3 = order === 0 ?
|
|
1828
|
-
result = { kind: "add", left: result, right: { kind: "mul", left:
|
|
2039
|
+
const coefficient = chunkHIQ5HSZL_cjs.rationalDiv(atPoint.value, { n: factorial, d: 1n });
|
|
2040
|
+
if (chunkHIQ5HSZL_cjs.isRationalZero(coefficient)) continue;
|
|
2041
|
+
const shifted = chunkHIQ5HSZL_cjs.isRationalZero(point) ? chunkHIQ5HSZL_cjs.varNode(variable) : { kind: "sub", left: chunkHIQ5HSZL_cjs.varNode(variable), right: pointNode };
|
|
2042
|
+
const power3 = order === 0 ? chunkHIQ5HSZL_cjs.constNode(1) : order === 1 ? shifted : chunkHIQ5HSZL_cjs.powNode(shifted, chunkHIQ5HSZL_cjs.constNode(order));
|
|
2043
|
+
result = { kind: "add", left: result, right: { kind: "mul", left: chunkHIQ5HSZL_cjs.constNode(coefficient), right: power3 } };
|
|
1829
2044
|
}
|
|
1830
|
-
return
|
|
2045
|
+
return chunkHIQ5HSZL_cjs.simplifySymbolic(result);
|
|
1831
2046
|
}
|
|
1832
2047
|
function jacobian(functions, variables) {
|
|
1833
2048
|
return functions.map((fn) => variables.map((variable) => differentiate2(fn, variable)));
|
|
@@ -1960,25 +2175,45 @@ function extremum(args, wantLargest) {
|
|
|
1960
2175
|
if (!sameMeasure) {
|
|
1961
2176
|
const bestUnit = best.type === 6 /* Uom */ ? best.unit : void 0;
|
|
1962
2177
|
const otherUnit = a.type === 6 /* Uom */ ? a.unit : void 0;
|
|
1963
|
-
|
|
2178
|
+
const named = describeMeasureMismatch(bestUnit, otherUnit, "compared");
|
|
2179
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
1964
2180
|
"INCOMPATIBLE_UNITS",
|
|
1965
|
-
`Cannot compare incompatible units: ${bestUnit ?? "?"} and ${otherUnit ?? "?"}`
|
|
2181
|
+
named ?? `Cannot compare incompatible units: ${bestUnit ?? "?"} and ${otherUnit ?? "?"}`
|
|
1966
2182
|
);
|
|
1967
2183
|
}
|
|
1968
2184
|
if (wantLargest ? rv > lv : rv < lv) best = a;
|
|
1969
2185
|
}
|
|
1970
|
-
if (hasNaN) return
|
|
1971
|
-
if (best === void 0) return
|
|
1972
|
-
return best.type === 6 /* Uom */ ? best :
|
|
2186
|
+
if (hasNaN) return chunk2TZKENDH_cjs.numberValue(NaN);
|
|
2187
|
+
if (best === void 0) return chunk2TZKENDH_cjs.numberValue(wantLargest ? -Infinity : Infinity);
|
|
2188
|
+
return best.type === 6 /* Uom */ ? best : chunk2TZKENDH_cjs.numberValue(best.toNumber());
|
|
1973
2189
|
}
|
|
1974
2190
|
function keepUnit(operand, magnitude2) {
|
|
1975
|
-
if (operand.type === 6 /* Uom */ && operand.unit !== void 0) return
|
|
1976
|
-
return
|
|
2191
|
+
if (operand.type === 6 /* Uom */ && operand.unit !== void 0) return chunk2TZKENDH_cjs.uomValue(magnitude2, operand.unit);
|
|
2192
|
+
return chunk2TZKENDH_cjs.numberValue(magnitude2);
|
|
2193
|
+
}
|
|
2194
|
+
function roundToPlaces(source, places) {
|
|
2195
|
+
const p = Number.isFinite(places) ? Math.min(100, Math.max(0, Math.trunc(places))) : 0;
|
|
2196
|
+
if (source.exact !== void 0) {
|
|
2197
|
+
const rounded = chunkHIQ5HSZL_cjs.decimalRound(source.exact, p);
|
|
2198
|
+
return withPlaces(source, chunkHIQ5HSZL_cjs.decimalToNumber(rounded), p, rounded);
|
|
2199
|
+
}
|
|
2200
|
+
const value = source.toNumber();
|
|
2201
|
+
if (!Number.isFinite(value)) return withPlaces(source, value, p);
|
|
2202
|
+
const scale2 = Math.pow(10, p);
|
|
2203
|
+
const scaled = value * scale2;
|
|
2204
|
+
if (!Number.isFinite(scaled) || Math.abs(scaled) > Number.MAX_SAFE_INTEGER) return withPlaces(source, value, p);
|
|
2205
|
+
return withPlaces(source, Math.round(scaled) / scale2, p);
|
|
2206
|
+
}
|
|
2207
|
+
function withPlaces(source, magnitude2, places, exact) {
|
|
2208
|
+
const result = source.type === 6 /* Uom */ && source.unit !== void 0 ? chunk2TZKENDH_cjs.uomValue(magnitude2, source.unit) : chunk2TZKENDH_cjs.numberValue(magnitude2);
|
|
2209
|
+
result.decimalPlaces = places;
|
|
2210
|
+
if (exact !== void 0) result.exact = exact;
|
|
2211
|
+
return result;
|
|
1977
2212
|
}
|
|
1978
2213
|
function nonFiniteEuclidOperand(a, b, name) {
|
|
1979
2214
|
if (Number.isFinite(a) && Number.isFinite(b)) return null;
|
|
1980
2215
|
const culprit = Number.isFinite(a) ? b : a;
|
|
1981
|
-
return
|
|
2216
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
1982
2217
|
"INVALID_INTEGER_OPERAND",
|
|
1983
2218
|
`${name} needs two whole numbers, and ${Number.isNaN(culprit) ? "one of them has no value" : "one of them is infinite"}`
|
|
1984
2219
|
);
|
|
@@ -2000,51 +2235,57 @@ var builtinFunctions = {
|
|
|
2000
2235
|
// first, so sqrt(-4) is 2i rather than an approximation.
|
|
2001
2236
|
0: (args) => {
|
|
2002
2237
|
const value = args[0].toNumber();
|
|
2003
|
-
if (value >= 0) return
|
|
2004
|
-
return symbolicToValue(
|
|
2238
|
+
if (value >= 0) return chunk2TZKENDH_cjs.numberValue(Math.sqrt(value));
|
|
2239
|
+
return symbolicToValue(chunkHIQ5HSZL_cjs.callNode("sqrt", [chunkHIQ5HSZL_cjs.constNode(value)]));
|
|
2005
2240
|
},
|
|
2006
2241
|
// abs(a): for a Matrix, "|a|" (Calca's determinant-pipe notation) is a
|
|
2007
2242
|
// valid alias for det(a) (index 64), reusing the SAME implementation
|
|
2008
2243
|
// not a separate one. Plain-number abs is unaffected.
|
|
2009
|
-
1: (args) => args[0].type === 7 /* Matrix */ ?
|
|
2244
|
+
1: (args) => args[0].type === 7 /* Matrix */ ? chunkHIQ5HSZL_cjs.determinant(args[0].value) : keepUnit(args[0], Math.abs(args[0].toNumber())),
|
|
2010
2245
|
// sin/cos/tan accept an angle with a unit; see angleInRadians().
|
|
2011
|
-
2: (args) =>
|
|
2012
|
-
3: (args) =>
|
|
2013
|
-
4: (args) =>
|
|
2014
|
-
5: (args) =>
|
|
2246
|
+
2: (args) => chunk2TZKENDH_cjs.numberValue(Math.sin(angleInRadians(args[0]))),
|
|
2247
|
+
3: (args) => chunk2TZKENDH_cjs.numberValue(Math.cos(angleInRadians(args[0]))),
|
|
2248
|
+
4: (args) => chunk2TZKENDH_cjs.numberValue(Math.tan(angleInRadians(args[0]))),
|
|
2249
|
+
5: (args) => chunk2TZKENDH_cjs.numberValue(Math.log(args[0].toNumber())),
|
|
2015
2250
|
// round/ceil/floor keep a unit for the same reason abs does; see keepUnit().
|
|
2016
2251
|
6: (args) => keepUnit(args[0], Math.ceil(args[0].toNumber())),
|
|
2017
2252
|
7: (args) => keepUnit(args[0], Math.floor(args[0].toNumber())),
|
|
2018
|
-
8: (args) =>
|
|
2253
|
+
8: (args) => args.length >= 2 ? (
|
|
2254
|
+
// round(x, n): round to n decimal places and display at that precision.
|
|
2255
|
+
roundToPlaces(args[0], args[1].toNumber())
|
|
2256
|
+
) : (
|
|
2257
|
+
// round(x): nearest whole number, the way it always was.
|
|
2258
|
+
keepUnit(args[0], Math.round(args[0].toNumber()))
|
|
2259
|
+
),
|
|
2019
2260
|
// min/max: see extremum() for why the winner is carried around as a Value
|
|
2020
2261
|
// rather than as a running number.
|
|
2021
2262
|
9: (args) => extremum(args, false),
|
|
2022
2263
|
10: (args) => extremum(args, true),
|
|
2023
|
-
11: (args) =>
|
|
2024
|
-
12: (args) =>
|
|
2025
|
-
13: (args) =>
|
|
2026
|
-
14: (args) =>
|
|
2027
|
-
15: (args) =>
|
|
2028
|
-
16: (args) =>
|
|
2029
|
-
17: (args) =>
|
|
2030
|
-
18: (args) =>
|
|
2031
|
-
19: (args) =>
|
|
2032
|
-
20: (args) =>
|
|
2033
|
-
21: (args) =>
|
|
2034
|
-
22: (args) =>
|
|
2035
|
-
23: (args) =>
|
|
2036
|
-
24: (args) =>
|
|
2037
|
-
25: (args) =>
|
|
2264
|
+
11: (args) => chunk2TZKENDH_cjs.numberValue(Math.asin(args[0].toNumber())),
|
|
2265
|
+
12: (args) => chunk2TZKENDH_cjs.numberValue(Math.acos(args[0].toNumber())),
|
|
2266
|
+
13: (args) => chunk2TZKENDH_cjs.numberValue(Math.atan(args[0].toNumber())),
|
|
2267
|
+
14: (args) => chunk2TZKENDH_cjs.numberValue(Math.atan2(args[0].toNumber(), args[1].toNumber())),
|
|
2268
|
+
15: (args) => chunk2TZKENDH_cjs.numberValue(Math.sinh(args[0].toNumber())),
|
|
2269
|
+
16: (args) => chunk2TZKENDH_cjs.numberValue(Math.cosh(args[0].toNumber())),
|
|
2270
|
+
17: (args) => chunk2TZKENDH_cjs.numberValue(Math.tanh(args[0].toNumber())),
|
|
2271
|
+
18: (args) => chunk2TZKENDH_cjs.numberValue(Math.asinh(args[0].toNumber())),
|
|
2272
|
+
19: (args) => chunk2TZKENDH_cjs.numberValue(Math.acosh(args[0].toNumber())),
|
|
2273
|
+
20: (args) => chunk2TZKENDH_cjs.numberValue(Math.atanh(args[0].toNumber())),
|
|
2274
|
+
21: (args) => chunk2TZKENDH_cjs.numberValue(Math.cbrt(args[0].toNumber())),
|
|
2275
|
+
22: (args) => chunk2TZKENDH_cjs.numberValue(Math.clz32(args[0].toNumber())),
|
|
2276
|
+
23: (args) => chunk2TZKENDH_cjs.numberValue(Math.expm1(args[0].toNumber())),
|
|
2277
|
+
24: (args) => chunk2TZKENDH_cjs.numberValue(Math.exp(args[0].toNumber())),
|
|
2278
|
+
25: (args) => chunk2TZKENDH_cjs.numberValue(Math.fround(args[0].toNumber())),
|
|
2038
2279
|
// hypot: left as .map()+spread (unlike min/max above), Math.hypot uses
|
|
2039
2280
|
// a numerically-stable scaling algorithm internally to avoid overflow
|
|
2040
2281
|
// for very large/small inputs; a naive manual reimplementation risks
|
|
2041
2282
|
// silently changing results at the extremes, so the tiny array
|
|
2042
2283
|
// allocation here is the safer trade.
|
|
2043
|
-
26: (args) =>
|
|
2044
|
-
27: (args) =>
|
|
2045
|
-
28: (args) =>
|
|
2046
|
-
29: (args) =>
|
|
2047
|
-
30: (args) =>
|
|
2284
|
+
26: (args) => chunk2TZKENDH_cjs.numberValue(Math.hypot(...args.map((a) => a.toNumber()))),
|
|
2285
|
+
27: (args) => chunk2TZKENDH_cjs.numberValue(Math.imul(args[0].toNumber(), args[1].toNumber())),
|
|
2286
|
+
28: (args) => chunk2TZKENDH_cjs.numberValue(Math.log10(args[0].toNumber())),
|
|
2287
|
+
29: (args) => chunk2TZKENDH_cjs.numberValue(Math.log1p(args[0].toNumber())),
|
|
2288
|
+
30: (args) => chunk2TZKENDH_cjs.numberValue(Math.log2(args[0].toNumber())),
|
|
2048
2289
|
// pow(): the spelled-out form of `^`, so a Matrix base means the same
|
|
2049
2290
|
// repeated matrix multiplication `^` means. Without this branch
|
|
2050
2291
|
// `pow([1,2;3,4], 2)` was Math.pow of a value whose toNumber() is 0, and
|
|
@@ -2052,21 +2293,21 @@ var builtinFunctions = {
|
|
|
2052
2293
|
31: (args) => {
|
|
2053
2294
|
if (args[0].type === 7 /* Matrix */) {
|
|
2054
2295
|
if (args[1].type !== 0 /* Number */) {
|
|
2055
|
-
return
|
|
2296
|
+
return chunk2TZKENDH_cjs.errorValue("MATRIX_POWER_UNSUPPORTED", `pow: a matrix's exponent must be a whole number, as in "pow([1,2;3,4], 2)".`);
|
|
2056
2297
|
}
|
|
2057
|
-
return
|
|
2298
|
+
return chunkHIQ5HSZL_cjs.matrixPower(args[0].value, args[1].value);
|
|
2058
2299
|
}
|
|
2059
2300
|
if (args[1].type === 7 /* Matrix */) {
|
|
2060
|
-
return
|
|
2301
|
+
return chunk2TZKENDH_cjs.errorValue("MATRIX_POWER_UNSUPPORTED", `pow: a matrix may only be the base, as in "pow([1,2;3,4], 2)".`);
|
|
2061
2302
|
}
|
|
2062
|
-
return
|
|
2303
|
+
return chunk2TZKENDH_cjs.numberValue(power(args[0].toNumber(), args[1].toNumber()));
|
|
2063
2304
|
},
|
|
2064
|
-
32: () =>
|
|
2305
|
+
32: () => chunk2TZKENDH_cjs.numberValue(Math.random()),
|
|
2065
2306
|
// takes no arguments, unlike its neighbours
|
|
2066
|
-
33: (args) =>
|
|
2067
|
-
34: (args) =>
|
|
2068
|
-
35: (args) =>
|
|
2069
|
-
36: (args) =>
|
|
2307
|
+
33: (args) => chunk2TZKENDH_cjs.numberValue(Math.sign(args[0].toNumber())),
|
|
2308
|
+
34: (args) => chunk2TZKENDH_cjs.numberValue(Math.trunc(args[0].toNumber())),
|
|
2309
|
+
35: (args) => chunk2TZKENDH_cjs.numberValue(args[0].toNumber() * Math.PI / 180),
|
|
2310
|
+
36: (args) => chunk2TZKENDH_cjs.numberValue(args[0].toNumber() * 180 / Math.PI),
|
|
2070
2311
|
// 37: diceRoll(from, to), random integer in range [from, to] inclusive.
|
|
2071
2312
|
// A reversed range (from > to) used to silently produce values outside
|
|
2072
2313
|
// [to, from] via a negative-length Math.random() spread (e.g.
|
|
@@ -2076,9 +2317,9 @@ var builtinFunctions = {
|
|
|
2076
2317
|
const from = args[0].toNumber();
|
|
2077
2318
|
const to = args[1].toNumber();
|
|
2078
2319
|
if (from > to) {
|
|
2079
|
-
return
|
|
2320
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `roll: invalid range, ${from} is greater than ${to}`);
|
|
2080
2321
|
}
|
|
2081
|
-
return
|
|
2322
|
+
return chunk2TZKENDH_cjs.numberValue(Math.floor(Math.random() * (to - from + 1)) + from);
|
|
2082
2323
|
},
|
|
2083
2324
|
// gcd(a, b), Euclidean algorithm. Negative inputs are treated by
|
|
2084
2325
|
// magnitude (gcd is conventionally defined over non-negative integers).
|
|
@@ -2087,7 +2328,7 @@ var builtinFunctions = {
|
|
|
2087
2328
|
const b = Math.trunc(Math.abs(args[1].toNumber()));
|
|
2088
2329
|
const nonFinite = nonFiniteEuclidOperand(a, b, "gcd");
|
|
2089
2330
|
if (nonFinite) return nonFinite;
|
|
2090
|
-
return
|
|
2331
|
+
return chunk2TZKENDH_cjs.numberValue(euclidGcd(a, b));
|
|
2091
2332
|
},
|
|
2092
2333
|
// lcm(a, b) = |a*b| / gcd(a, b), via the same Euclidean gcd inline
|
|
2093
2334
|
// (a standalone gcd() call site, no shared helper needed for two uses).
|
|
@@ -2096,8 +2337,8 @@ var builtinFunctions = {
|
|
|
2096
2337
|
const b = Math.trunc(Math.abs(args[1].toNumber()));
|
|
2097
2338
|
const nonFinite = nonFiniteEuclidOperand(a, b, "lcm");
|
|
2098
2339
|
if (nonFinite) return nonFinite;
|
|
2099
|
-
if (a === 0 || b === 0) return
|
|
2100
|
-
return
|
|
2340
|
+
if (a === 0 || b === 0) return chunk2TZKENDH_cjs.numberValue(0);
|
|
2341
|
+
return chunk2TZKENDH_cjs.numberValue(a / euclidGcd(a, b) * b);
|
|
2101
2342
|
},
|
|
2102
2343
|
// permutation(n, r) = n! / (n-r)!, computed as a running product
|
|
2103
2344
|
// rather than two full factorials, so it stays exact for n well
|
|
@@ -2118,19 +2359,19 @@ var builtinFunctions = {
|
|
|
2118
2359
|
const n = Math.trunc(args[0].toNumber());
|
|
2119
2360
|
const r = Math.trunc(args[1].toNumber());
|
|
2120
2361
|
if (n < 0 || r < 0 || r > n) {
|
|
2121
|
-
return
|
|
2362
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `permutation: invalid n=${n}, r=${r} (require 0 <= r <= n)`);
|
|
2122
2363
|
}
|
|
2123
2364
|
let result = 1;
|
|
2124
2365
|
for (let i = 0; i < r; i++) {
|
|
2125
2366
|
result *= n - i;
|
|
2126
2367
|
if (!Number.isFinite(result)) {
|
|
2127
|
-
return
|
|
2368
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
2128
2369
|
"PERMUTATION_OVERFLOW",
|
|
2129
2370
|
`permutation: P(${n}, ${r}) exceeds the maximum representable double (it passed it after ${i + 1} of ${r} factors)`
|
|
2130
2371
|
);
|
|
2131
2372
|
}
|
|
2132
2373
|
}
|
|
2133
|
-
return
|
|
2374
|
+
return chunk2TZKENDH_cjs.numberValue(result);
|
|
2134
2375
|
},
|
|
2135
2376
|
// combination(n, r) = n! / (r! * (n-r)!), multiply-then-divide one
|
|
2136
2377
|
// step at a time (standard technique) keeps every intermediate result
|
|
@@ -2146,42 +2387,42 @@ var builtinFunctions = {
|
|
|
2146
2387
|
const n = Math.trunc(args[0].toNumber());
|
|
2147
2388
|
const r = Math.trunc(args[1].toNumber());
|
|
2148
2389
|
if (n < 0 || r < 0 || r > n) {
|
|
2149
|
-
return
|
|
2390
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `combination: invalid n=${n}, r=${r} (require 0 <= r <= n)`);
|
|
2150
2391
|
}
|
|
2151
2392
|
const k = Math.min(r, n - r);
|
|
2152
2393
|
let result = 1;
|
|
2153
2394
|
for (let i = 0; i < k; i++) {
|
|
2154
2395
|
result = result * (n - i) / (i + 1);
|
|
2155
2396
|
if (!Number.isFinite(result)) {
|
|
2156
|
-
return
|
|
2397
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
2157
2398
|
"COMBINATION_OVERFLOW",
|
|
2158
2399
|
`combination: C(${n}, ${r}) exceeds the maximum representable double (it passed it after ${i + 1} of ${k} steps)`
|
|
2159
2400
|
);
|
|
2160
2401
|
}
|
|
2161
2402
|
}
|
|
2162
|
-
return
|
|
2403
|
+
return chunk2TZKENDH_cjs.numberValue(Math.round(result));
|
|
2163
2404
|
},
|
|
2164
2405
|
// average(...), arithmetic mean of any number of arguments. Backs the
|
|
2165
2406
|
// MathPhrases package's "average of X, Y, Z" (packages/mathphrases/).
|
|
2166
2407
|
42: (args) => {
|
|
2167
|
-
if (args.length === 0) return
|
|
2408
|
+
if (args.length === 0) return chunk2TZKENDH_cjs.numberValue(0);
|
|
2168
2409
|
const sum = args.reduce((acc, a) => acc + a.toNumber(), 0);
|
|
2169
|
-
return
|
|
2410
|
+
return chunk2TZKENDH_cjs.numberValue(sum / args.length);
|
|
2170
2411
|
},
|
|
2171
2412
|
// median(...), middle value; average of the two middle values for an
|
|
2172
2413
|
// even argument count.
|
|
2173
2414
|
43: (args) => {
|
|
2174
|
-
if (args.length === 0) return
|
|
2415
|
+
if (args.length === 0) return chunk2TZKENDH_cjs.numberValue(0);
|
|
2175
2416
|
const sorted = args.map((a) => a.toNumber()).sort((a, b) => a - b);
|
|
2176
2417
|
const mid = Math.floor(sorted.length / 2);
|
|
2177
|
-
return
|
|
2418
|
+
return chunk2TZKENDH_cjs.numberValue(
|
|
2178
2419
|
sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid]
|
|
2179
2420
|
);
|
|
2180
2421
|
},
|
|
2181
2422
|
// total(...), sum of any number of arguments.
|
|
2182
|
-
44: (args) =>
|
|
2423
|
+
44: (args) => chunk2TZKENDH_cjs.numberValue(args.reduce((acc, a) => acc + a.toNumber(), 0)),
|
|
2183
2424
|
// count(...), number of arguments passed.
|
|
2184
|
-
45: (args) =>
|
|
2425
|
+
45: (args) => chunk2TZKENDH_cjs.numberValue(args.length),
|
|
2185
2426
|
// proportion(a, b, c) -> d such that a:b = c:d, i.e. d = c * (b/a)
|
|
2186
2427
|
// "A is to B as C is to what". Unit-aware via unifyUom: "5 km is to
|
|
2187
2428
|
// 500m as 5 cm is to what" unifies 5km/500m to a 10:1 ratio (500m ==
|
|
@@ -2192,10 +2433,10 @@ var builtinFunctions = {
|
|
|
2192
2433
|
const [a, b, c] = args;
|
|
2193
2434
|
const { lv: aNum, rv: bNum } = unifyUom(a, b);
|
|
2194
2435
|
if (aNum === 0) {
|
|
2195
|
-
return
|
|
2436
|
+
return chunk2TZKENDH_cjs.errorValue("PROPORTION_DIVIDE_BY_ZERO", `Cannot compute proportion: "${a.value}" is zero`);
|
|
2196
2437
|
}
|
|
2197
2438
|
const result = c.toNumber() * (bNum / aNum);
|
|
2198
|
-
return c.type === 6 /* Uom */ ?
|
|
2439
|
+
return c.type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(result, c.unit) : chunk2TZKENDH_cjs.numberValue(result);
|
|
2199
2440
|
},
|
|
2200
2441
|
// clamp(value, lo, hi), restrict value to [lo, hi]. Backs
|
|
2201
2442
|
// "clamp X between Y and Z" / "clamp X from Y to Z".
|
|
@@ -2204,9 +2445,9 @@ var builtinFunctions = {
|
|
|
2204
2445
|
const lo = args[1].toNumber();
|
|
2205
2446
|
const hi = args[2].toNumber();
|
|
2206
2447
|
if (lo > hi) {
|
|
2207
|
-
return
|
|
2448
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `clamp: invalid range, ${lo} is greater than ${hi}`);
|
|
2208
2449
|
}
|
|
2209
|
-
return
|
|
2450
|
+
return chunk2TZKENDH_cjs.numberValue(Math.min(Math.max(value, lo), hi));
|
|
2210
2451
|
},
|
|
2211
2452
|
// hex(n), Python/JS-style call-syntax hex formatting, e.g. hex(255) ->
|
|
2212
2453
|
// "0xFF". Distinct from the Converters package's `255 as hex` (see
|
|
@@ -2216,16 +2457,16 @@ var builtinFunctions = {
|
|
|
2216
2457
|
// function call that returns an ordinary String value, matching
|
|
2217
2458
|
// Python's hex()/JS convention of a function returning display text,
|
|
2218
2459
|
// not a numeric type.
|
|
2219
|
-
48: (args) =>
|
|
2460
|
+
48: (args) => chunk2TZKENDH_cjs.hexValue(args[0].toNumber()),
|
|
2220
2461
|
// bin(n). Same call-syntax shape as hex() above, e.g. bin(10) -> "0b1010".
|
|
2221
|
-
49: (args) =>
|
|
2462
|
+
49: (args) => chunk2TZKENDH_cjs.hexValue(args[0].toNumber(), "bin"),
|
|
2222
2463
|
// int(x), coerce ANY value (Number, Percentage, Uom, String, Hex, ...)
|
|
2223
2464
|
// to a plain integer Number, truncating any fractional part toward
|
|
2224
2465
|
// zero (Math.trunc semantics: int(5.7) -> 5, int(-5.7) -> -5). Distinct
|
|
2225
2466
|
// from the Converters package's `x as number` (TO_NUMBER opcode),
|
|
2226
2467
|
// which only strips a unit/percentage wrapper and keeps any decimal
|
|
2227
2468
|
// part (e.g. "5.7 as number" -> 5.7), int() additionally truncates.
|
|
2228
|
-
50: (args) =>
|
|
2469
|
+
50: (args) => chunk2TZKENDH_cjs.numberValue(Math.trunc(args[0].toNumber())),
|
|
2229
2470
|
// ── Finance (packages/finance/) ──────────────────────────────────────
|
|
2230
2471
|
// All finance builtins preserve the principal/amount argument's Uom
|
|
2231
2472
|
// unit (e.g. a currency like "$") onto the result, matching
|
|
@@ -2246,10 +2487,10 @@ var builtinFunctions = {
|
|
|
2246
2487
|
const rate = args[1].toNumber();
|
|
2247
2488
|
const years = args[2].toNumber();
|
|
2248
2489
|
if (1 + rate <= 0) {
|
|
2249
|
-
return
|
|
2490
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `compoundInterest: rate ${rate} makes (1 + rate) non-positive`);
|
|
2250
2491
|
}
|
|
2251
2492
|
const fv = principal * Math.pow(1 + rate, years);
|
|
2252
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2493
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(fv, args[0].unit) : chunk2TZKENDH_cjs.numberValue(fv);
|
|
2253
2494
|
},
|
|
2254
2495
|
// compoundInterestEarned(principal, rate, years) -> FV - principal, the
|
|
2255
2496
|
// interest-only portion. Backs "interest on $P over Y years at R%" and
|
|
@@ -2259,10 +2500,10 @@ var builtinFunctions = {
|
|
|
2259
2500
|
const rate = args[1].toNumber();
|
|
2260
2501
|
const years = args[2].toNumber();
|
|
2261
2502
|
if (1 + rate <= 0) {
|
|
2262
|
-
return
|
|
2503
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `interestEarned: rate ${rate} makes (1 + rate) non-positive`);
|
|
2263
2504
|
}
|
|
2264
2505
|
const interest = principal * (Math.pow(1 + rate, years) - 1);
|
|
2265
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2506
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(interest, args[0].unit) : chunk2TZKENDH_cjs.numberValue(interest);
|
|
2266
2507
|
},
|
|
2267
2508
|
// compoundInterestRate(principal, futureValue, years) -> the rate (as a
|
|
2268
2509
|
// decimal fraction) needed to grow principal to futureValue over years.
|
|
@@ -2274,12 +2515,12 @@ var builtinFunctions = {
|
|
|
2274
2515
|
const futureValue = args[1].toNumber();
|
|
2275
2516
|
const years = args[2].toNumber();
|
|
2276
2517
|
if (principal <= 0 || futureValue <= 0) {
|
|
2277
|
-
return
|
|
2518
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `compoundInterestRate: principal and futureValue must both be positive`);
|
|
2278
2519
|
}
|
|
2279
2520
|
if (years <= 0) {
|
|
2280
|
-
return
|
|
2521
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `compoundInterestRate: years must be greater than 0`);
|
|
2281
2522
|
}
|
|
2282
|
-
return
|
|
2523
|
+
return chunk2TZKENDH_cjs.numberValue(Math.pow(futureValue / principal, 1 / years) - 1);
|
|
2283
2524
|
},
|
|
2284
2525
|
// compoundInterestYears(principal, futureValue, rate) -> the number of
|
|
2285
2526
|
// years needed to grow principal to futureValue at a fixed rate.
|
|
@@ -2289,12 +2530,12 @@ var builtinFunctions = {
|
|
|
2289
2530
|
const futureValue = args[1].toNumber();
|
|
2290
2531
|
const rate = args[2].toNumber();
|
|
2291
2532
|
if (principal <= 0 || futureValue <= 0) {
|
|
2292
|
-
return
|
|
2533
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `compoundInterestYears: principal and futureValue must both be positive`);
|
|
2293
2534
|
}
|
|
2294
2535
|
if (1 + rate <= 0 || rate === 0) {
|
|
2295
|
-
return
|
|
2536
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `compoundInterestYears: rate ${rate} is not usable (must be > -1 and not 0)`);
|
|
2296
2537
|
}
|
|
2297
|
-
return
|
|
2538
|
+
return chunk2TZKENDH_cjs.numberValue(Math.log(futureValue / principal) / Math.log(1 + rate));
|
|
2298
2539
|
},
|
|
2299
2540
|
// loanRepayment(principal, rate, years, periodsPerYear), standard
|
|
2300
2541
|
// amortizing-loan repayment (mortgage formula), redistributed evenly
|
|
@@ -2312,13 +2553,13 @@ var builtinFunctions = {
|
|
|
2312
2553
|
const rate = args[1].toNumber();
|
|
2313
2554
|
const years = args[2].toNumber();
|
|
2314
2555
|
const periodsPerYear = args[3].toNumber();
|
|
2315
|
-
if (principal <= 0) return
|
|
2316
|
-
if (years <= 0) return
|
|
2317
|
-
if (rate < 0) return
|
|
2318
|
-
if (periodsPerYear < 0) return
|
|
2556
|
+
if (principal <= 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `loanRepayment: principal must be positive`);
|
|
2557
|
+
if (years <= 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `loanRepayment: years must be positive`);
|
|
2558
|
+
if (rate < 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `loanRepayment: rate must not be negative`);
|
|
2559
|
+
if (periodsPerYear < 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `loanRepayment: periodsPerYear must not be negative`);
|
|
2319
2560
|
const { totalRepayment } = amortizeLoan(principal, rate, years);
|
|
2320
2561
|
const result = periodsPerYear === 0 ? totalRepayment : totalRepayment / (years * periodsPerYear);
|
|
2321
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2562
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(result, args[0].unit) : chunk2TZKENDH_cjs.numberValue(result);
|
|
2322
2563
|
},
|
|
2323
2564
|
// loanInterest(principal, rate, years, periodsPerYear), the interest
|
|
2324
2565
|
// portion of index 55's repayment, same periodsPerYear convention.
|
|
@@ -2328,13 +2569,13 @@ var builtinFunctions = {
|
|
|
2328
2569
|
const rate = args[1].toNumber();
|
|
2329
2570
|
const years = args[2].toNumber();
|
|
2330
2571
|
const periodsPerYear = args[3].toNumber();
|
|
2331
|
-
if (principal <= 0) return
|
|
2332
|
-
if (years <= 0) return
|
|
2333
|
-
if (rate < 0) return
|
|
2334
|
-
if (periodsPerYear < 0) return
|
|
2572
|
+
if (principal <= 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `loanInterest: principal must be positive`);
|
|
2573
|
+
if (years <= 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `loanInterest: years must be positive`);
|
|
2574
|
+
if (rate < 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `loanInterest: rate must not be negative`);
|
|
2575
|
+
if (periodsPerYear < 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `loanInterest: periodsPerYear must not be negative`);
|
|
2335
2576
|
const { totalInterest } = amortizeLoan(principal, rate, years);
|
|
2336
2577
|
const result = periodsPerYear === 0 ? totalInterest : totalInterest / (years * periodsPerYear);
|
|
2337
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2578
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(result, args[0].unit) : chunk2TZKENDH_cjs.numberValue(result);
|
|
2338
2579
|
},
|
|
2339
2580
|
// monthlyPayment(principal, rate, years), convenience 3-arg wrapper
|
|
2340
2581
|
// around index 55's monthly case, for direct function-call use without
|
|
@@ -2343,11 +2584,11 @@ var builtinFunctions = {
|
|
|
2343
2584
|
const principal = args[0].toNumber();
|
|
2344
2585
|
const rate = args[1].toNumber();
|
|
2345
2586
|
const years = args[2].toNumber();
|
|
2346
|
-
if (principal <= 0) return
|
|
2347
|
-
if (years <= 0) return
|
|
2348
|
-
if (rate < 0) return
|
|
2587
|
+
if (principal <= 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `monthlyPayment: principal must be positive`);
|
|
2588
|
+
if (years <= 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RANGE", `monthlyPayment: years must be positive`);
|
|
2589
|
+
if (rate < 0) return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `monthlyPayment: rate must not be negative`);
|
|
2349
2590
|
const { monthlyPayment } = amortizeLoan(principal, rate, years);
|
|
2350
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2591
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(monthlyPayment, args[0].unit) : chunk2TZKENDH_cjs.numberValue(monthlyPayment);
|
|
2351
2592
|
},
|
|
2352
2593
|
// taxAdd(amount, rate) -> amount * (1 + rate), the tax-inclusive total.
|
|
2353
2594
|
// Backs the taxAdd() function-call form, whose name promises exactly this.
|
|
@@ -2359,8 +2600,8 @@ var builtinFunctions = {
|
|
|
2359
2600
|
58: (args) => {
|
|
2360
2601
|
const amount = args[0].toNumber();
|
|
2361
2602
|
const rate = args[1].toNumber();
|
|
2362
|
-
|
|
2363
|
-
return
|
|
2603
|
+
if (args[0].type === 6 /* Uom */) return scaleMoneyByPercent(args[0], args[0].unit, rate, 1);
|
|
2604
|
+
return chunk2TZKENDH_cjs.numberValue(amount * (1 + rate));
|
|
2364
2605
|
},
|
|
2365
2606
|
// taxRemove(amount, rate) -> amount / (1 + rate), extracts the
|
|
2366
2607
|
// pre-tax amount from a tax-INCLUSIVE total. Backs "tax off $X at R%" /
|
|
@@ -2369,9 +2610,12 @@ var builtinFunctions = {
|
|
|
2369
2610
|
const amount = args[0].toNumber();
|
|
2370
2611
|
const rate = args[1].toNumber();
|
|
2371
2612
|
if (1 + rate <= 0) {
|
|
2372
|
-
return
|
|
2613
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `taxRemove: rate ${rate} makes (1 + rate) non-positive`);
|
|
2614
|
+
}
|
|
2615
|
+
if (args[0].type === 6 /* Uom */) {
|
|
2616
|
+
return removeTaxExact(args[0], args[0].unit, rate) ?? chunk2TZKENDH_cjs.uomValue(amount / (1 + rate), args[0].unit);
|
|
2373
2617
|
}
|
|
2374
|
-
return
|
|
2618
|
+
return chunk2TZKENDH_cjs.numberValue(amount / (1 + rate));
|
|
2375
2619
|
},
|
|
2376
2620
|
// inflationAdjust(amount, fromYear, toYear) -- CPI-based inflation
|
|
2377
2621
|
// adjustment between two arbitrary years, using the bundled CPI-U
|
|
@@ -2391,13 +2635,13 @@ var builtinFunctions = {
|
|
|
2391
2635
|
const toYear = args[2].toNumber();
|
|
2392
2636
|
const ratio = inflationRatio(fromYear, toYear);
|
|
2393
2637
|
if (ratio === void 0) {
|
|
2394
|
-
return
|
|
2638
|
+
return chunk2TZKENDH_cjs.errorValue(
|
|
2395
2639
|
"INFLATION_YEAR_OUT_OF_RANGE",
|
|
2396
2640
|
`inflationAdjust: fromYear ${fromYear} or toYear ${toYear} is outside the bundled CPI table's range (${CPI_MIN_YEAR}-${CPI_MAX_YEAR})`
|
|
2397
2641
|
);
|
|
2398
2642
|
}
|
|
2399
2643
|
const result = amount * ratio;
|
|
2400
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2644
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(result, args[0].unit) : chunk2TZKENDH_cjs.numberValue(result);
|
|
2401
2645
|
},
|
|
2402
2646
|
// root(n, x) -- the n-th root of x (Numi's `root n (x)` phrasing maps
|
|
2403
2647
|
// to this same call-style form; see FunctionCallParselet's name map).
|
|
@@ -2408,7 +2652,7 @@ var builtinFunctions = {
|
|
|
2408
2652
|
61: (args) => {
|
|
2409
2653
|
const n = args[0].toNumber();
|
|
2410
2654
|
const x = args[1].toNumber();
|
|
2411
|
-
return
|
|
2655
|
+
return chunk2TZKENDH_cjs.numberValue(power(x, 1 / n));
|
|
2412
2656
|
},
|
|
2413
2657
|
// fact(n) / factorial(n) -- integer factorial. Deliberately rejects
|
|
2414
2658
|
// negative or non-integer input (factorial isn't defined for either
|
|
@@ -2419,14 +2663,14 @@ var builtinFunctions = {
|
|
|
2419
2663
|
62: (args) => {
|
|
2420
2664
|
const n = args[0].toNumber();
|
|
2421
2665
|
if (!Number.isInteger(n) || n < 0) {
|
|
2422
|
-
return
|
|
2666
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_FACTORIAL_INPUT", `fact: ${n} is not a non-negative integer`);
|
|
2423
2667
|
}
|
|
2424
2668
|
if (n > 170) {
|
|
2425
|
-
return
|
|
2669
|
+
return chunk2TZKENDH_cjs.errorValue("FACTORIAL_OVERFLOW", `fact: ${n}! exceeds the maximum representable double (170! is the largest finite factorial)`);
|
|
2426
2670
|
}
|
|
2427
2671
|
let result = 1;
|
|
2428
2672
|
for (let i = 2; i <= n; i++) result *= i;
|
|
2429
|
-
return
|
|
2673
|
+
return chunk2TZKENDH_cjs.numberValue(result);
|
|
2430
2674
|
},
|
|
2431
2675
|
// ── Matrix (packages/matrix/) ────────────────────────────────────────
|
|
2432
2676
|
// transpose(a)/det(a)/inv(a)/dot(a,b), reachable both via ordinary
|
|
@@ -2439,17 +2683,17 @@ var builtinFunctions = {
|
|
|
2439
2683
|
// own transpose (a 1x1 "matrix" transposed is itself), matches this
|
|
2440
2684
|
// engine's existing convention of treating a scalar as a trivial 1x1
|
|
2441
2685
|
// matrix (see Value.ts's toNumber()/isNaN() 1x1 special case).
|
|
2442
|
-
63: (args) => args[0].type === 7 /* Matrix */ ?
|
|
2686
|
+
63: (args) => args[0].type === 7 /* Matrix */ ? chunkHIQ5HSZL_cjs.transpose(args[0].value) : args[0],
|
|
2443
2687
|
// det(a), determinant. A plain Number's "determinant" is itself (the
|
|
2444
2688
|
// determinant of a 1x1 matrix [x] is x).
|
|
2445
|
-
64: (args) => args[0].type === 7 /* Matrix */ ?
|
|
2689
|
+
64: (args) => args[0].type === 7 /* Matrix */ ? chunkHIQ5HSZL_cjs.determinant(args[0].value) : chunk2TZKENDH_cjs.numberValue(args[0].toNumber()),
|
|
2446
2690
|
// inv(a), matrix inverse for a Matrix; for a plain Number, `1/x`
|
|
2447
2691
|
// (byte-identical to `Math.pow(x, -1)`, which is what `x^-1` computed
|
|
2448
2692
|
// before this feature existed. See PrecedenceParser.ts's `^-1`
|
|
2449
2693
|
// special-case doc comment for why this must stay exact).
|
|
2450
2694
|
65: (args) => {
|
|
2451
|
-
if (args[0].type === 7 /* Matrix */) return
|
|
2452
|
-
return
|
|
2695
|
+
if (args[0].type === 7 /* Matrix */) return chunkHIQ5HSZL_cjs.inverse(args[0].value);
|
|
2696
|
+
return chunk2TZKENDH_cjs.numberValue(1 / args[0].toNumber());
|
|
2453
2697
|
},
|
|
2454
2698
|
// dot(a, b), matrix product / scalar-broadcast, the SAME dispatch as
|
|
2455
2699
|
// the `*` operator between two matrices (vm/VM.ts's MUL case). Plain
|
|
@@ -2459,10 +2703,10 @@ var builtinFunctions = {
|
|
|
2459
2703
|
66: (args) => {
|
|
2460
2704
|
const [a, b] = args;
|
|
2461
2705
|
if (a.type === 0 /* Number */ && b.type === 0 /* Number */) {
|
|
2462
|
-
return
|
|
2706
|
+
return chunk2TZKENDH_cjs.numberValue(a.toNumber() * b.toNumber());
|
|
2463
2707
|
}
|
|
2464
2708
|
const toMatrix = (v) => v.type === 7 /* Matrix */ ? v.value : { rows: 1, cols: 1, data: [v.toNumber()], hasSymbolic: false };
|
|
2465
|
-
return
|
|
2709
|
+
return chunkHIQ5HSZL_cjs.matrixMultiply(toMatrix(a), toMatrix(b));
|
|
2466
2710
|
},
|
|
2467
2711
|
// ── Symbolic algebra (packages/symbolic/) ──
|
|
2468
2712
|
// expand(expr), multiplying out every product and power. Reached only
|
|
@@ -2476,7 +2720,7 @@ var builtinFunctions = {
|
|
|
2476
2720
|
67: (args) => {
|
|
2477
2721
|
const [value] = args;
|
|
2478
2722
|
if (value.type !== 9 /* Symbolic */) return value;
|
|
2479
|
-
return symbolicToValue(
|
|
2723
|
+
return symbolicToValue(chunkHIQ5HSZL_cjs.expandSymbolic(value.value));
|
|
2480
2724
|
},
|
|
2481
2725
|
// factor(expr), writing a polynomial as a product of irreducible factors
|
|
2482
2726
|
// over the RATIONALS. x^2-2 and x^2+1 come back unchanged, which is the
|
|
@@ -2493,7 +2737,7 @@ var builtinFunctions = {
|
|
|
2493
2737
|
69: (args) => {
|
|
2494
2738
|
const [lhsValue, rhsValue, variableValue] = args;
|
|
2495
2739
|
if (variableValue?.type !== 3 /* String */) {
|
|
2496
|
-
return
|
|
2740
|
+
return chunk2TZKENDH_cjs.errorValue("SOLVE_REQUIRES_VARIABLE_NAME", "solve's second argument must be the name of the unknown.");
|
|
2497
2741
|
}
|
|
2498
2742
|
return solveEquationValues(lhsValue, rhsValue, variableValue.value);
|
|
2499
2743
|
},
|
|
@@ -2504,7 +2748,7 @@ var builtinFunctions = {
|
|
|
2504
2748
|
const variable = symbolicVariableName(variableValue, "der");
|
|
2505
2749
|
if (typeof variable !== "string") return variable;
|
|
2506
2750
|
const expression = valueToSymbolic(target);
|
|
2507
|
-
if (expression === null) return
|
|
2751
|
+
if (expression === null) return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_NONFINITE_OPERAND", "der needs an expression with an exact value.");
|
|
2508
2752
|
return symbolicToValue(differentiate2(expression, variable, orderValue?.toNumber() ?? 1));
|
|
2509
2753
|
},
|
|
2510
2754
|
// integral(expr, variable), the indefinite integral without a constant of
|
|
@@ -2515,9 +2759,9 @@ var builtinFunctions = {
|
|
|
2515
2759
|
const variable = symbolicVariableName(variableValue, "integral");
|
|
2516
2760
|
if (typeof variable !== "string") return variable;
|
|
2517
2761
|
const expression = valueToSymbolic(target);
|
|
2518
|
-
if (expression === null) return
|
|
2762
|
+
if (expression === null) return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_NONFINITE_OPERAND", "integral needs an expression with an exact value.");
|
|
2519
2763
|
const result = integrate(expression, variable);
|
|
2520
|
-
if (!result.ok) return
|
|
2764
|
+
if (!result.ok) return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_INTEGRAL_UNSUPPORTED", `Cannot integrate this: ${result.reason}.`);
|
|
2521
2765
|
return symbolicToValue(result.value);
|
|
2522
2766
|
},
|
|
2523
2767
|
// taylor(expr, variable = point, degree).
|
|
@@ -2528,7 +2772,7 @@ var builtinFunctions = {
|
|
|
2528
2772
|
const expression = valueToSymbolic(target);
|
|
2529
2773
|
const point = valueToSymbolic(pointValue);
|
|
2530
2774
|
if (expression === null || point === null || point.kind !== "const") {
|
|
2531
|
-
return
|
|
2775
|
+
return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_NONFINITE_OPERAND", "taylor needs an expression and an exact expansion point.");
|
|
2532
2776
|
}
|
|
2533
2777
|
return symbolicToValue(taylorSeries(expression, variable, point.value, degreeValue.toNumber()));
|
|
2534
2778
|
},
|
|
@@ -2538,23 +2782,23 @@ var builtinFunctions = {
|
|
|
2538
2782
|
const functions = [];
|
|
2539
2783
|
for (const arg of args) {
|
|
2540
2784
|
const node = valueToSymbolic(arg);
|
|
2541
|
-
if (node === null) return
|
|
2785
|
+
if (node === null) return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_NONFINITE_OPERAND", "jacobian needs expressions with exact values.");
|
|
2542
2786
|
functions.push(node);
|
|
2543
2787
|
}
|
|
2544
2788
|
const variables = /* @__PURE__ */ new Set();
|
|
2545
|
-
for (const fn of functions) for (const name of
|
|
2789
|
+
for (const fn of functions) for (const name of chunkHIQ5HSZL_cjs.freeVariables(fn)) variables.add(name);
|
|
2546
2790
|
const sorted = [...variables].sort();
|
|
2547
|
-
if (sorted.length === 0) return
|
|
2791
|
+
if (sorted.length === 0) return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_JACOBIAN_NO_VARIABLES", "jacobian needs at least one unknown to differentiate against.");
|
|
2548
2792
|
const rows = jacobian(functions, sorted);
|
|
2549
2793
|
const rowMajor = [];
|
|
2550
2794
|
for (const row of rows) {
|
|
2551
|
-
for (const cell of row) rowMajor.push(
|
|
2795
|
+
for (const cell of row) rowMajor.push(chunkHIQ5HSZL_cjs.symbolicToEntry(cell));
|
|
2552
2796
|
}
|
|
2553
|
-
return
|
|
2797
|
+
return chunk2TZKENDH_cjs.matrixValue(rows.length, sorted.length, chunkHIQ5HSZL_cjs.rowMajorToColumnMajor(rows.length, sorted.length, rowMajor));
|
|
2554
2798
|
},
|
|
2555
2799
|
// An imaginary literal, 3i. The parselet pushes the numeric part and this
|
|
2556
2800
|
// turns it into an exact imaginary value.
|
|
2557
|
-
74: (args) => symbolicToValue(
|
|
2801
|
+
74: (args) => symbolicToValue(chunkHIQ5HSZL_cjs.complexNode(chunkHIQ5HSZL_cjs.complex(chunkHIQ5HSZL_cjs.RATIONAL_ZERO, chunkHIQ5HSZL_cjs.rationalFromNumber(args[0].toNumber())))),
|
|
2558
2802
|
// conj(z), re(z) and im(z). Each folds immediately for a literal and stays
|
|
2559
2803
|
// symbolic for anything still carrying an unknown.
|
|
2560
2804
|
75: (args) => applyComplexAccessor("conj", args[0]),
|
|
@@ -2564,7 +2808,7 @@ var builtinFunctions = {
|
|
|
2564
2808
|
78: (args) => {
|
|
2565
2809
|
const value = args[0];
|
|
2566
2810
|
if (value.type !== 9 /* Symbolic */) return value;
|
|
2567
|
-
return symbolicToValue(
|
|
2811
|
+
return symbolicToValue(chunkHIQ5HSZL_cjs.cancelSymbolic(value.value));
|
|
2568
2812
|
},
|
|
2569
2813
|
// apart(expr), the partial-fraction decomposition of a rational function.
|
|
2570
2814
|
79: (args) => {
|
|
@@ -2579,10 +2823,13 @@ var builtinFunctions = {
|
|
|
2579
2823
|
const amount = args[0].toNumber();
|
|
2580
2824
|
const rate = args[1].toNumber();
|
|
2581
2825
|
if (1 + rate <= 0) {
|
|
2582
|
-
return
|
|
2826
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `taxIn: rate ${rate} makes (1 + rate) non-positive`);
|
|
2583
2827
|
}
|
|
2584
2828
|
const tax = amount - amount / (1 + rate);
|
|
2585
|
-
|
|
2829
|
+
if (args[0].type === 6 /* Uom */) {
|
|
2830
|
+
return taxInExact(args[0], args[0].unit, rate) ?? chunk2TZKENDH_cjs.uomValue(tax, args[0].unit);
|
|
2831
|
+
}
|
|
2832
|
+
return chunk2TZKENDH_cjs.numberValue(tax);
|
|
2586
2833
|
},
|
|
2587
2834
|
// taxOn(amount, rate) -> amount * rate, the tax itself.
|
|
2588
2835
|
//
|
|
@@ -2594,22 +2841,22 @@ var builtinFunctions = {
|
|
|
2594
2841
|
86: (args) => {
|
|
2595
2842
|
const amount = args[0].toNumber();
|
|
2596
2843
|
const rate = args[1].toNumber();
|
|
2597
|
-
|
|
2598
|
-
return
|
|
2844
|
+
if (args[0].type === 6 /* Uom */) return scaleMoneyExact(args[0], rate, args[0].unit);
|
|
2845
|
+
return chunk2TZKENDH_cjs.numberValue(amount * rate);
|
|
2599
2846
|
},
|
|
2600
2847
|
// ── Degree-taking trig (sind/cosd/tand and the inverses) ──────────────
|
|
2601
2848
|
// The "d" spellings take and return degrees rather than radians, which is
|
|
2602
2849
|
// the convention every scientific calculator uses. sin(90 degrees) is the
|
|
2603
2850
|
// other way to say the same thing; both exist because both get typed.
|
|
2604
|
-
87: (args) =>
|
|
2605
|
-
88: (args) =>
|
|
2606
|
-
89: (args) =>
|
|
2607
|
-
90: (args) =>
|
|
2608
|
-
91: (args) =>
|
|
2609
|
-
92: (args) =>
|
|
2851
|
+
87: (args) => chunk2TZKENDH_cjs.numberValue(Math.sin(args[0].toNumber() * Math.PI / 180)),
|
|
2852
|
+
88: (args) => chunk2TZKENDH_cjs.numberValue(Math.cos(args[0].toNumber() * Math.PI / 180)),
|
|
2853
|
+
89: (args) => chunk2TZKENDH_cjs.numberValue(Math.tan(args[0].toNumber() * Math.PI / 180)),
|
|
2854
|
+
90: (args) => chunk2TZKENDH_cjs.numberValue(Math.asin(args[0].toNumber()) * 180 / Math.PI),
|
|
2855
|
+
91: (args) => chunk2TZKENDH_cjs.numberValue(Math.acos(args[0].toNumber()) * 180 / Math.PI),
|
|
2856
|
+
92: (args) => chunk2TZKENDH_cjs.numberValue(Math.atan(args[0].toNumber()) * 180 / Math.PI),
|
|
2610
2857
|
// daysCount(n) -> n labelled as days. "days in Q3" is a count of days
|
|
2611
2858
|
// and should say so; a bare 92 loses what was being counted.
|
|
2612
|
-
93: (args) =>
|
|
2859
|
+
93: (args) => chunk2TZKENDH_cjs.uomValue(args[0].toNumber(), "days"),
|
|
2613
2860
|
// asTwoUnits(value, majorUnit, minorUnit) -> "12 min 30 s".
|
|
2614
2861
|
//
|
|
2615
2862
|
// "12.5 minutes in minutes and seconds" asks for one quantity split
|
|
@@ -2623,25 +2870,25 @@ var builtinFunctions = {
|
|
|
2623
2870
|
const major = typeof args[1]?.value === "string" ? args[1].value : void 0;
|
|
2624
2871
|
const minor = typeof args[2]?.value === "string" ? args[2].value : void 0;
|
|
2625
2872
|
if (major === void 0 || minor === void 0) {
|
|
2626
|
-
return
|
|
2873
|
+
return chunk2TZKENDH_cjs.errorValue("UNKNOWN_UNIT", 'both units have to be named, as in "12.5 minutes in minutes and seconds"');
|
|
2627
2874
|
}
|
|
2628
2875
|
const majorEntry = chunkAMOJYLG2_cjs.UNIT_TABLE[major.toLowerCase()];
|
|
2629
2876
|
const minorEntry = chunkAMOJYLG2_cjs.UNIT_TABLE[minor.toLowerCase()];
|
|
2630
2877
|
if (majorEntry === void 0 || minorEntry === void 0) {
|
|
2631
|
-
return
|
|
2878
|
+
return chunk2TZKENDH_cjs.errorValue("UNKNOWN_UNIT", `${major} and ${minor}: one of these is not a unit`);
|
|
2632
2879
|
}
|
|
2633
2880
|
if (majorEntry[0] !== minorEntry[0]) {
|
|
2634
|
-
return
|
|
2881
|
+
return chunk2TZKENDH_cjs.errorValue("INCOMPATIBLE_UNITS", `${major} and ${minor} measure different things`);
|
|
2635
2882
|
}
|
|
2636
2883
|
if (minorEntry[1] >= majorEntry[1]) {
|
|
2637
|
-
return
|
|
2884
|
+
return chunk2TZKENDH_cjs.errorValue("INCOMPATIBLE_UNITS", `${major} and ${minor}: name the larger unit first`);
|
|
2638
2885
|
}
|
|
2639
2886
|
const source = args[0];
|
|
2640
2887
|
const sourceEntry = source.type === 6 /* Uom */ && source.unit !== void 0 ? chunkAMOJYLG2_cjs.UNIT_TABLE[source.unit.toLowerCase()] : void 0;
|
|
2641
2888
|
const inBase = source.toNumber() * (sourceEntry?.[1] ?? majorEntry[1]);
|
|
2642
2889
|
const majorCount = Math.floor(inBase / majorEntry[1]);
|
|
2643
2890
|
const minorCount = Math.round((inBase - majorCount * majorEntry[1]) / minorEntry[1] * 1e3) / 1e3;
|
|
2644
|
-
return
|
|
2891
|
+
return chunk2TZKENDH_cjs.stringValue(`${majorCount} ${major} ${minorCount} ${minor}`);
|
|
2645
2892
|
},
|
|
2646
2893
|
// makeRate(value, denominatorUnit) -> value per that unit.
|
|
2647
2894
|
//
|
|
@@ -2657,9 +2904,9 @@ var builtinFunctions = {
|
|
|
2657
2904
|
const denominator = String(args[1].value);
|
|
2658
2905
|
const numerator = source.type === 6 /* Uom */ && source.unit !== void 0 ? source.unit : "";
|
|
2659
2906
|
if (numerator.includes("/")) {
|
|
2660
|
-
return
|
|
2907
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE_UNIT", `${numerator}/${denominator}: that is already a rate`);
|
|
2661
2908
|
}
|
|
2662
|
-
return
|
|
2909
|
+
return chunk2TZKENDH_cjs.uomValue(source.toNumber(), `${numerator}/${denominator}`);
|
|
2663
2910
|
},
|
|
2664
2911
|
// atRate(quantity, rate) -> whichever of the two the question implies.
|
|
2665
2912
|
//
|
|
@@ -2674,7 +2921,7 @@ var builtinFunctions = {
|
|
|
2674
2921
|
const left = args[0];
|
|
2675
2922
|
const rate = args[1];
|
|
2676
2923
|
if (rate.type !== 6 /* Uom */ || rate.unit === void 0 || !rate.unit.includes("/")) {
|
|
2677
|
-
return
|
|
2924
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", 'at: the right-hand side has to be a rate, as in "$30/hour"');
|
|
2678
2925
|
}
|
|
2679
2926
|
const slash = rate.unit.indexOf("/");
|
|
2680
2927
|
const numerator = rate.unit.slice(0, slash);
|
|
@@ -2685,17 +2932,17 @@ var builtinFunctions = {
|
|
|
2685
2932
|
if (leftEntry !== void 0 && denominatorEntry !== void 0 && leftEntry[0] === denominatorEntry[0]) {
|
|
2686
2933
|
const inDenominator = left.toNumber() * leftEntry[1] / denominatorEntry[1];
|
|
2687
2934
|
const total = inDenominator * rate.toNumber();
|
|
2688
|
-
return numerator === "" ?
|
|
2935
|
+
return numerator === "" ? chunk2TZKENDH_cjs.numberValue(total) : chunk2TZKENDH_cjs.uomValue(total, numerator);
|
|
2689
2936
|
}
|
|
2690
2937
|
if (leftUnit !== void 0 && leftUnit === numerator) {
|
|
2691
2938
|
const count = left.toNumber() / rate.toNumber();
|
|
2692
|
-
return
|
|
2939
|
+
return chunk2TZKENDH_cjs.uomValue(count, pluraliseUnit(denominator, count));
|
|
2693
2940
|
}
|
|
2694
2941
|
if (leftUnit === void 0) {
|
|
2695
2942
|
const total = left.toNumber() * rate.toNumber();
|
|
2696
|
-
return numerator === "" ?
|
|
2943
|
+
return numerator === "" ? chunk2TZKENDH_cjs.numberValue(total) : chunk2TZKENDH_cjs.uomValue(total, numerator);
|
|
2697
2944
|
}
|
|
2698
|
-
return
|
|
2945
|
+
return chunk2TZKENDH_cjs.errorValue("INCOMPATIBLE_UNITS", `at: ${leftUnit} matches neither side of ${rate.unit}`);
|
|
2699
2946
|
},
|
|
2700
2947
|
// ── Investments (packages/finance/) ────────────────────────────────────
|
|
2701
2948
|
// compoundFutureValueEvery(principal, rate, years, periodsPerYear)
|
|
@@ -2710,13 +2957,13 @@ var builtinFunctions = {
|
|
|
2710
2957
|
const years = args[2].toNumber();
|
|
2711
2958
|
const perYear = args[3].toNumber();
|
|
2712
2959
|
if (perYear <= 0) {
|
|
2713
|
-
return
|
|
2960
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `compounding: ${perYear} periods per year is not a period`);
|
|
2714
2961
|
}
|
|
2715
2962
|
if (1 + rate / perYear <= 0) {
|
|
2716
|
-
return
|
|
2963
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `compounding: rate ${rate} makes each period non-positive`);
|
|
2717
2964
|
}
|
|
2718
2965
|
const fv = principal * Math.pow(1 + rate / perYear, perYear * years);
|
|
2719
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2966
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(fv, args[0].unit) : chunk2TZKENDH_cjs.numberValue(fv);
|
|
2720
2967
|
},
|
|
2721
2968
|
// compoundInterestEarnedEvery(principal, rate, years, periodsPerYear)
|
|
2722
2969
|
// The interest-only portion of index 80, i.e. FV - P.
|
|
@@ -2726,10 +2973,10 @@ var builtinFunctions = {
|
|
|
2726
2973
|
const years = args[2].toNumber();
|
|
2727
2974
|
const perYear = args[3].toNumber();
|
|
2728
2975
|
if (perYear <= 0 || 1 + rate / perYear <= 0) {
|
|
2729
|
-
return
|
|
2976
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `compounding: rate ${rate} over ${perYear} periods per year is not usable`);
|
|
2730
2977
|
}
|
|
2731
2978
|
const interest = principal * (Math.pow(1 + rate / perYear, perYear * years) - 1);
|
|
2732
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2979
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(interest, args[0].unit) : chunk2TZKENDH_cjs.numberValue(interest);
|
|
2733
2980
|
},
|
|
2734
2981
|
// presentValue(futureValue, rate, years) -> FV / (1 + r)^y, what a sum
|
|
2735
2982
|
// promised in the future is worth today. The inverse of index 51.
|
|
@@ -2738,10 +2985,10 @@ var builtinFunctions = {
|
|
|
2738
2985
|
const rate = args[1].toNumber();
|
|
2739
2986
|
const years = args[2].toNumber();
|
|
2740
2987
|
if (1 + rate <= 0) {
|
|
2741
|
-
return
|
|
2988
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", `presentValue: rate ${rate} makes (1 + rate) non-positive`);
|
|
2742
2989
|
}
|
|
2743
2990
|
const pv = future / Math.pow(1 + rate, years);
|
|
2744
|
-
return args[0].type === 6 /* Uom */ ?
|
|
2991
|
+
return args[0].type === 6 /* Uom */ ? chunk2TZKENDH_cjs.uomValue(pv, args[0].unit) : chunk2TZKENDH_cjs.numberValue(pv);
|
|
2745
2992
|
},
|
|
2746
2993
|
// returnOnInvestment(invested, returned) -> (returned - invested) /
|
|
2747
2994
|
// invested, the gain as a multiple of what was put in. $500 in and $1,500
|
|
@@ -2752,9 +2999,9 @@ var builtinFunctions = {
|
|
|
2752
2999
|
const invested = args[0].toNumber();
|
|
2753
3000
|
const returned = args[1].toNumber();
|
|
2754
3001
|
if (invested === 0) {
|
|
2755
|
-
return
|
|
3002
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", "roi: nothing was invested, so there is no return on it");
|
|
2756
3003
|
}
|
|
2757
|
-
return
|
|
3004
|
+
return chunk2TZKENDH_cjs.numberValue((returned - invested) / invested);
|
|
2758
3005
|
},
|
|
2759
3006
|
// annualisedReturn(invested, returned, years) -> CAGR, the constant
|
|
2760
3007
|
// yearly rate that turns `invested` into `returned` over `years`:
|
|
@@ -2765,15 +3012,15 @@ var builtinFunctions = {
|
|
|
2765
3012
|
const returned = args[1].toNumber();
|
|
2766
3013
|
const years = args[2].toNumber();
|
|
2767
3014
|
if (invested <= 0) {
|
|
2768
|
-
return
|
|
3015
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", "annual return: the amount invested must be positive");
|
|
2769
3016
|
}
|
|
2770
3017
|
if (years <= 0) {
|
|
2771
|
-
return
|
|
3018
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", "annual return: the period must be longer than zero");
|
|
2772
3019
|
}
|
|
2773
3020
|
if (returned <= 0) {
|
|
2774
|
-
return
|
|
3021
|
+
return chunk2TZKENDH_cjs.errorValue("INVALID_RATE", "annual return: nothing was returned, so there is no annual rate");
|
|
2775
3022
|
}
|
|
2776
|
-
return
|
|
3023
|
+
return chunk2TZKENDH_cjs.percentageValue(Math.pow(returned / invested, 1 / years) - 1);
|
|
2777
3024
|
},
|
|
2778
3025
|
// roundToPlaces(value, places) -> value rounded to that many decimal
|
|
2779
3026
|
// places, backing `<value> to <n> dp` (converters/parselets/
|
|
@@ -2785,25 +3032,16 @@ var builtinFunctions = {
|
|
|
2785
3032
|
// fractional part to round at all, and the round trip through 1e23 was
|
|
2786
3033
|
// pure loss. Asking for fewer decimal places than a number has cannot
|
|
2787
3034
|
// change it, so a value that is already whole is returned untouched.
|
|
2788
|
-
97: (args) =>
|
|
2789
|
-
const source = args[0];
|
|
2790
|
-
const value = source.toNumber();
|
|
2791
|
-
const places = args[1].toNumber();
|
|
2792
|
-
if (!Number.isFinite(value) || Number.isInteger(value)) return keepUnit(source, value);
|
|
2793
|
-
const scale2 = Math.pow(10, places);
|
|
2794
|
-
const scaled = value * scale2;
|
|
2795
|
-
if (!Number.isFinite(scaled) || Math.abs(scaled) > Number.MAX_SAFE_INTEGER) return keepUnit(source, value);
|
|
2796
|
-
return keepUnit(source, Math.round(scaled) / scale2);
|
|
2797
|
-
}
|
|
3035
|
+
97: (args) => roundToPlaces(args[0], args[1].toNumber())
|
|
2798
3036
|
};
|
|
2799
3037
|
function applyComplexAccessor(name, value) {
|
|
2800
3038
|
const node = valueToSymbolic(value);
|
|
2801
|
-
if (node === null) return
|
|
2802
|
-
return symbolicToValue(
|
|
3039
|
+
if (node === null) return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_NONFINITE_OPERAND", name + " needs a value with an exact number.");
|
|
3040
|
+
return symbolicToValue(chunkHIQ5HSZL_cjs.callNode(name, [node]));
|
|
2803
3041
|
}
|
|
2804
3042
|
function symbolicVariableName(value, verb) {
|
|
2805
3043
|
if (value?.type !== 3 /* String */) {
|
|
2806
|
-
return
|
|
3044
|
+
return chunk2TZKENDH_cjs.errorValue("SYMBOLIC_REQUIRES_VARIABLE_NAME", `${verb} needs the name of an unknown.`);
|
|
2807
3045
|
}
|
|
2808
3046
|
return value.value;
|
|
2809
3047
|
}
|
|
@@ -2820,7 +3058,7 @@ var MAX_PLUGIN_FUNCTION_INDEX = 255;
|
|
|
2820
3058
|
var nextPluginFunctionIndex = 0;
|
|
2821
3059
|
function allocatePluginFunctionIndex() {
|
|
2822
3060
|
if (nextPluginFunctionIndex > MAX_PLUGIN_FUNCTION_INDEX) {
|
|
2823
|
-
throw
|
|
3061
|
+
throw chunkB4HBEFTB_cjs.ErrorFactory.config(
|
|
2824
3062
|
"PLUGIN_FUNCTION_INDEX_POOL_EXHAUSTED",
|
|
2825
3063
|
`allocatePluginFunctionIndex: pool exhausted (max ${MAX_PLUGIN_FUNCTION_INDEX + 1} allocations).`
|
|
2826
3064
|
);
|
|
@@ -2955,22 +3193,30 @@ exports.bigIntDivisionByZero = bigIntDivisionByZero;
|
|
|
2955
3193
|
exports.binaryOp = binaryOp;
|
|
2956
3194
|
exports.builtinFunctions = builtinFunctions;
|
|
2957
3195
|
exports.compareBigIntOperands = compareBigIntOperands;
|
|
3196
|
+
exports.compareRationalOperands = compareRationalOperands;
|
|
2958
3197
|
exports.compareUom = compareUom;
|
|
2959
3198
|
exports.createEngineContext = createEngineContext;
|
|
2960
3199
|
exports.defaultEngineContext = defaultEngineContext;
|
|
3200
|
+
exports.describeConversionMismatch = describeConversionMismatch;
|
|
3201
|
+
exports.exactRationalOp = exactRationalOp;
|
|
2961
3202
|
exports.globalDagKey = globalDagKey;
|
|
2962
3203
|
exports.incomparableUnitsError = incomparableUnitsError;
|
|
3204
|
+
exports.moneyExactMagnitude = moneyExactMagnitude;
|
|
2963
3205
|
exports.pluginFunctionRegistry = pluginFunctionRegistry;
|
|
2964
3206
|
exports.power = power;
|
|
2965
3207
|
exports.registerAsConverter = registerAsConverter;
|
|
3208
|
+
exports.scaleMoneyByPercent = scaleMoneyByPercent;
|
|
3209
|
+
exports.scaleMoneyExact = scaleMoneyExact;
|
|
2966
3210
|
exports.sharedGlobalVariableStore = sharedGlobalVariableStore;
|
|
2967
3211
|
exports.sharedOpRegistry = sharedOpRegistry;
|
|
2968
3212
|
exports.solveEquationValues = solveEquationValues;
|
|
3213
|
+
exports.solveForVariable = solveForVariable;
|
|
2969
3214
|
exports.symbolicBuiltin = symbolicBuiltin;
|
|
2970
3215
|
exports.symbolicNeg = symbolicNeg;
|
|
2971
3216
|
exports.symbolicPow = symbolicPow;
|
|
2972
3217
|
exports.toBigIntOperand = toBigIntOperand;
|
|
3218
|
+
exports.uncertainOp = uncertainOp;
|
|
2973
3219
|
exports.unifyUom = unifyUom;
|
|
2974
3220
|
exports.unregisterAsConverter = unregisterAsConverter;
|
|
2975
|
-
//# sourceMappingURL=chunk-
|
|
2976
|
-
//# sourceMappingURL=chunk-
|
|
3221
|
+
//# sourceMappingURL=chunk-7ZX6B7SY.cjs.map
|
|
3222
|
+
//# sourceMappingURL=chunk-7ZX6B7SY.cjs.map
|