@cortex-js/compute-engine 0.57.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/compile.esm.js +2376 -501
- package/dist/compile.min.esm.js +316 -68
- package/dist/compile.min.umd.cjs +316 -68
- package/dist/compile.umd.cjs +2376 -501
- package/dist/compute-engine.esm.js +15717 -12444
- package/dist/compute-engine.min.esm.js +331 -83
- package/dist/compute-engine.min.umd.cjs +330 -82
- package/dist/compute-engine.umd.cjs +15717 -12444
- package/dist/core.esm.js +15716 -12443
- package/dist/core.min.esm.js +329 -81
- package/dist/core.min.umd.cjs +329 -81
- package/dist/core.umd.cjs +15716 -12443
- package/dist/identities.esm.js +1921 -0
- package/dist/identities.min.esm.js +2 -0
- package/dist/identities.min.umd.cjs +4 -0
- package/dist/identities.umd.cjs +1946 -0
- package/dist/interval.esm.js +779 -339
- package/dist/interval.min.esm.js +8 -8
- package/dist/interval.min.umd.cjs +8 -8
- package/dist/interval.umd.cjs +779 -339
- package/dist/latex-syntax.esm.js +971 -608
- package/dist/latex-syntax.min.esm.js +7 -7
- package/dist/latex-syntax.min.umd.cjs +7 -7
- package/dist/latex-syntax.umd.cjs +971 -608
- package/dist/math-json.esm.js +8 -12
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.umd.cjs +2 -2
- package/dist/math-json.umd.cjs +8 -12
- package/dist/numerics.esm.js +1382 -226
- package/dist/numerics.min.esm.js +16 -5
- package/dist/numerics.min.umd.cjs +16 -5
- package/dist/numerics.umd.cjs +1382 -226
- package/dist/types/big-decimal/big-decimal.d.ts +1 -1
- package/dist/types/big-decimal/index.d.ts +1 -1
- package/dist/types/big-decimal/transcendentals.d.ts +1 -1
- package/dist/types/big-decimal/utils.d.ts +1 -1
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/configuration-change.d.ts +1 -1
- package/dist/types/common/fuzzy-string-match.d.ts +1 -1
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/interruptible.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/type/ast-nodes.d.ts +1 -1
- package/dist/types/common/type/boxed-type.d.ts +1 -1
- package/dist/types/common/type/lexer.d.ts +1 -1
- package/dist/types/common/type/parse.d.ts +1 -208
- package/dist/types/common/type/parser.d.ts +124 -2
- package/dist/types/common/type/primitive.d.ts +5 -1
- package/dist/types/common/type/reduce.d.ts +1 -1
- package/dist/types/common/type/serialize.d.ts +1 -1
- package/dist/types/common/type/subtype.d.ts +18 -1
- package/dist/types/common/type/type-builder.d.ts +1 -1
- package/dist/types/common/type/types.d.ts +1 -1
- package/dist/types/common/type/utils.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compile.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +13 -6
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -1
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +7 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +140 -0
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +34 -12
- package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/rule-index.d.ts +112 -0
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +2 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compilation/base-compiler.d.ts +8 -1
- package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
- package/dist/types/compute-engine/compilation/constant-folding.d.ts +16 -1
- package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/gpu-target.d.ts +58 -5
- package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +4 -4
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/types.d.ts +1 -1
- package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
- package/dist/types/compute-engine/engine-cache.d.ts +1 -1
- package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
- package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
- package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
- package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
- package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
- package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
- package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
- package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
- package/dist/types/compute-engine/engine-runtime-state.d.ts +4 -1
- package/dist/types/compute-engine/engine-scope.d.ts +1 -1
- package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
- package/dist/types/compute-engine/engine-simplification-rules.d.ts +10 -2
- package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
- package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
- package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
- package/dist/types/compute-engine/free-functions.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/fungrim/loader.d.ts +13 -0
- package/dist/types/compute-engine/fungrim/types.d.ts +160 -0
- package/dist/types/compute-engine/global-types.d.ts +1 -1
- package/dist/types/compute-engine/index.d.ts +63 -2
- package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
- package/dist/types/compute-engine/interval/elementary.d.ts +10 -2
- package/dist/types/compute-engine/interval/index.d.ts +2 -2
- package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
- package/dist/types/compute-engine/interval/types.d.ts +1 -1
- package/dist/types/compute-engine/interval/util.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-colors.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +4 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +3 -2
- package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -11
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/colors.d.ts +1 -1
- package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
- package/dist/types/compute-engine/library/complex.d.ts +13 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/fractals.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +27 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
- package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
- package/dist/types/compute-engine/library/units.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +7 -1
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bernoulli.d.ts +39 -0
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
- package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
- package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +12 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/random.d.ts +23 -0
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +78 -10
- package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/numerics/types.d.ts +1 -1
- package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
- package/dist/types/compute-engine/oeis.d.ts +1 -1
- package/dist/types/compute-engine/sequence.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensors.d.ts +3 -3
- package/dist/types/compute-engine/types-definitions.d.ts +1 -1
- package/dist/types/compute-engine/types-engine.d.ts +52 -3
- package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
- package/dist/types/compute-engine/types-expression.d.ts +85 -14
- package/dist/types/compute-engine/types-kernel-evaluation.d.ts +32 -1
- package/dist/types/compute-engine/types-kernel-serialization.d.ts +45 -3
- package/dist/types/compute-engine/types-serialization.d.ts +1 -1
- package/dist/types/compute-engine/types.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +1 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/identities.d.ts +3 -0
- package/dist/types/interval.d.ts +1 -1
- package/dist/types/latex-syntax.d.ts +2 -2
- package/dist/types/math-json/symbols.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/dist/types/numerics.d.ts +1 -1
- package/package.json +9 -3
package/dist/numerics.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Numerics 0.
|
|
1
|
+
/** Numerics 0.59.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Numerics = {}));})(this, (function (exports) { 'use strict';
|
|
3
3
|
var Numerics = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -317,6 +317,7 @@ var Numerics = (() => {
|
|
|
317
317
|
return sum;
|
|
318
318
|
}
|
|
319
319
|
function fpln(x, scale) {
|
|
320
|
+
if (x <= 0n) throw new RangeError("fpln: input must be positive");
|
|
320
321
|
if (x === scale) return 0n;
|
|
321
322
|
const xNum = Number(x);
|
|
322
323
|
const scaleNum = Number(scale);
|
|
@@ -966,9 +967,11 @@ var Numerics = (() => {
|
|
|
966
967
|
if (Number.isFinite(thisExp) && Number.isFinite(otherExp)) {
|
|
967
968
|
if (other.significand === 0n) return _BigDecimal.NAN;
|
|
968
969
|
if (this.significand === 0n) return fromRaw(0n, 0);
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
);
|
|
970
|
+
const ediff = thisExp - otherExp;
|
|
971
|
+
const num = ediff >= 0 ? this.significand * pow10(ediff) : this.significand;
|
|
972
|
+
const den = ediff >= 0 ? other.significand : other.significand * pow10(-ediff);
|
|
973
|
+
const q = num / den;
|
|
974
|
+
return this.sub(fromRaw(q, 0).mul(other));
|
|
972
975
|
}
|
|
973
976
|
if (thisExp !== thisExp || otherExp !== otherExp) return _BigDecimal.NAN;
|
|
974
977
|
if (!Number.isFinite(thisExp)) return _BigDecimal.NAN;
|
|
@@ -1013,7 +1016,10 @@ var Numerics = (() => {
|
|
|
1013
1016
|
return this.pow(n.neg()).inv();
|
|
1014
1017
|
}
|
|
1015
1018
|
const absSig = this.significand < 0n ? -this.significand : this.significand;
|
|
1016
|
-
const
|
|
1019
|
+
const sigDigits = bigintDigits(absSig);
|
|
1020
|
+
const dropped = sigDigits > 15 ? sigDigits - 15 : 0;
|
|
1021
|
+
const lead = dropped > 0 ? Number(absSig / 10n ** BigInt(dropped)) : Number(absSig);
|
|
1022
|
+
const thisLog10 = Math.log10(lead) + dropped + this.exponent;
|
|
1017
1023
|
const resultLog10 = Number(expValue) * thisLog10;
|
|
1018
1024
|
if (resultLog10 > 9e15) {
|
|
1019
1025
|
return this.significand < 0n && expValue % 2n !== 0n ? _BigDecimal.NEGATIVE_INFINITY : _BigDecimal.POSITIVE_INFINITY;
|
|
@@ -1046,7 +1052,19 @@ var Numerics = (() => {
|
|
|
1046
1052
|
return _BigDecimal.POSITIVE_INFINITY;
|
|
1047
1053
|
}
|
|
1048
1054
|
if (this.significand < 0n) return _BigDecimal.NAN;
|
|
1049
|
-
|
|
1055
|
+
const baseSig = this.significand;
|
|
1056
|
+
const decExpBase = this.exponent + bigintDigits(baseSig) - 1;
|
|
1057
|
+
const nSig = n.significand < 0n ? -n.significand : n.significand;
|
|
1058
|
+
const decExpN = n.exponent + bigintDigits(nSig) - 1;
|
|
1059
|
+
const argMag = decExpN + Math.log10(Math.abs(decExpBase) * 2.303 + 3) + 1;
|
|
1060
|
+
const extra = Math.min(20, Math.max(2, Math.ceil(argMag) + 2));
|
|
1061
|
+
const savedPrec = _BigDecimal.precision;
|
|
1062
|
+
_BigDecimal.precision = savedPrec + extra;
|
|
1063
|
+
try {
|
|
1064
|
+
return n.mul(this.ln()).exp().toPrecision(savedPrec);
|
|
1065
|
+
} finally {
|
|
1066
|
+
_BigDecimal.precision = savedPrec;
|
|
1067
|
+
}
|
|
1050
1068
|
}
|
|
1051
1069
|
// ---------- Conversion methods ----------
|
|
1052
1070
|
/** Convert to a JavaScript number. May lose precision for large values. */
|
|
@@ -1287,6 +1305,20 @@ var Numerics = (() => {
|
|
|
1287
1305
|
const sig = negative ? -absFp : absFp;
|
|
1288
1306
|
return fromRaw(sig, resultExp);
|
|
1289
1307
|
}
|
|
1308
|
+
function decimalExponent(x) {
|
|
1309
|
+
const sig = x.significand < 0n ? -x.significand : x.significand;
|
|
1310
|
+
return x.exponent + bigintDigits(sig) - 1;
|
|
1311
|
+
}
|
|
1312
|
+
var MAX_SAFE_EXPONENT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
1313
|
+
var _ln10Fp = null;
|
|
1314
|
+
var _ln10Scale = null;
|
|
1315
|
+
function ln10Fixed(scale) {
|
|
1316
|
+
if (_ln10Scale !== scale) {
|
|
1317
|
+
_ln10Fp = fpln(10n * scale, scale);
|
|
1318
|
+
_ln10Scale = scale;
|
|
1319
|
+
}
|
|
1320
|
+
return _ln10Fp;
|
|
1321
|
+
}
|
|
1290
1322
|
BigDecimal.prototype.sqrt = function() {
|
|
1291
1323
|
if (this.isNaN()) return BigDecimal.NAN;
|
|
1292
1324
|
if (this.isZero()) return BigDecimal.ZERO;
|
|
@@ -1297,9 +1329,13 @@ var Numerics = (() => {
|
|
|
1297
1329
|
if (this.significand < 0n) return BigDecimal.NAN;
|
|
1298
1330
|
const targetPrec = BigDecimal.precision;
|
|
1299
1331
|
const workingPrec = targetPrec + 10;
|
|
1300
|
-
const
|
|
1332
|
+
const e = decimalExponent(this);
|
|
1333
|
+
const k = Math.floor(e / 2);
|
|
1334
|
+
const m = fromRaw(this.significand, this.exponent - 2 * k);
|
|
1335
|
+
const [fp, scale] = toFixedPoint(m, workingPrec);
|
|
1301
1336
|
const sqrtFp = fpsqrt(fp, scale);
|
|
1302
|
-
|
|
1337
|
+
const root = fromFixedPoint(sqrtFp, scale, targetPrec);
|
|
1338
|
+
return fromRaw(root.significand, root.exponent + k);
|
|
1303
1339
|
};
|
|
1304
1340
|
BigDecimal.prototype.cbrt = function() {
|
|
1305
1341
|
if (this.isNaN()) return BigDecimal.NAN;
|
|
@@ -1313,10 +1349,13 @@ var Numerics = (() => {
|
|
|
1313
1349
|
}
|
|
1314
1350
|
const targetPrec = BigDecimal.precision;
|
|
1315
1351
|
const workingPrec = targetPrec + 10;
|
|
1316
|
-
const
|
|
1352
|
+
const e = decimalExponent(this);
|
|
1353
|
+
const k = Math.floor(e / 3);
|
|
1354
|
+
const m = fromRaw(this.significand, this.exponent - 3 * k);
|
|
1355
|
+
const [fp, scale] = toFixedPoint(m, workingPrec);
|
|
1317
1356
|
const C = fp * scale * scale;
|
|
1318
1357
|
let x;
|
|
1319
|
-
const numVal =
|
|
1358
|
+
const numVal = m.toNumber();
|
|
1320
1359
|
const scaleNum = Number(scale);
|
|
1321
1360
|
if (Number.isFinite(numVal) && numVal > 0 && Number.isFinite(scaleNum)) {
|
|
1322
1361
|
const approx = Math.cbrt(numVal);
|
|
@@ -1345,7 +1384,8 @@ var Numerics = (() => {
|
|
|
1345
1384
|
const diffNext = bigintAbs(next * next * next - C);
|
|
1346
1385
|
if (diffNext < diffX) x = next;
|
|
1347
1386
|
}
|
|
1348
|
-
|
|
1387
|
+
const root = fromFixedPoint(x, scale, targetPrec);
|
|
1388
|
+
return fromRaw(root.significand, root.exponent + k);
|
|
1349
1389
|
};
|
|
1350
1390
|
BigDecimal.sqrt = function(x) {
|
|
1351
1391
|
return x.sqrt();
|
|
@@ -1360,11 +1400,27 @@ var Numerics = (() => {
|
|
|
1360
1400
|
return BigDecimal.ZERO;
|
|
1361
1401
|
}
|
|
1362
1402
|
if (this.isZero()) return BigDecimal.ONE;
|
|
1403
|
+
if (decimalExponent(this) >= 17)
|
|
1404
|
+
return this.significand > 0n ? BigDecimal.POSITIVE_INFINITY : BigDecimal.ZERO;
|
|
1363
1405
|
const targetPrec = BigDecimal.precision;
|
|
1364
|
-
const
|
|
1365
|
-
const
|
|
1366
|
-
const
|
|
1367
|
-
|
|
1406
|
+
const absSig = this.significand < 0n ? -this.significand : this.significand;
|
|
1407
|
+
const magnitude = Math.max(0, this.exponent + bigintDigits(absSig));
|
|
1408
|
+
const workingPrec = targetPrec + 20 + magnitude;
|
|
1409
|
+
const [xFp, scale] = toFixedPoint(this, workingPrec);
|
|
1410
|
+
const l10 = ln10Fixed(scale);
|
|
1411
|
+
let k = xFp / l10;
|
|
1412
|
+
let rFp = xFp - k * l10;
|
|
1413
|
+
if (rFp < 0n) {
|
|
1414
|
+
k -= 1n;
|
|
1415
|
+
rFp += l10;
|
|
1416
|
+
}
|
|
1417
|
+
if (k > MAX_SAFE_EXPONENT || k < -MAX_SAFE_EXPONENT)
|
|
1418
|
+
return k > 0n ? BigDecimal.POSITIVE_INFINITY : BigDecimal.ZERO;
|
|
1419
|
+
const expR = fromFixedPoint(fpexp(rFp, scale), scale, targetPrec);
|
|
1420
|
+
const newExp = expR.exponent + Number(k);
|
|
1421
|
+
if (!Number.isSafeInteger(newExp))
|
|
1422
|
+
return k > 0n ? BigDecimal.POSITIVE_INFINITY : BigDecimal.ZERO;
|
|
1423
|
+
return fromRaw(expR.significand, newExp);
|
|
1368
1424
|
};
|
|
1369
1425
|
BigDecimal.prototype.ln = function() {
|
|
1370
1426
|
if (this.isNaN()) return BigDecimal.NAN;
|
|
@@ -1376,10 +1432,16 @@ var Numerics = (() => {
|
|
|
1376
1432
|
if (this.significand < 0n) return BigDecimal.NAN;
|
|
1377
1433
|
if (this.eq(1)) return BigDecimal.ZERO;
|
|
1378
1434
|
const targetPrec = BigDecimal.precision;
|
|
1379
|
-
const
|
|
1380
|
-
const
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1435
|
+
const sig = this.significand;
|
|
1436
|
+
const digits = bigintDigits(sig);
|
|
1437
|
+
const e = this.exponent + digits - 1;
|
|
1438
|
+
const m = fromRaw(sig, -(digits - 1));
|
|
1439
|
+
const eDigits = Math.abs(e).toString().length;
|
|
1440
|
+
const workingPrec = targetPrec + 20 + eDigits;
|
|
1441
|
+
const [mFp, scale] = toFixedPoint(m, workingPrec);
|
|
1442
|
+
const l10 = ln10Fixed(scale);
|
|
1443
|
+
const resultFp = fpln(mFp, scale) + BigInt(e) * l10;
|
|
1444
|
+
return fromFixedPoint(resultFp, scale, targetPrec);
|
|
1383
1445
|
};
|
|
1384
1446
|
BigDecimal.prototype.log = function(base) {
|
|
1385
1447
|
const b = base instanceof BigDecimal ? base : new BigDecimal(base);
|
|
@@ -1399,7 +1461,10 @@ var Numerics = (() => {
|
|
|
1399
1461
|
if (!this.isFinite()) return BigDecimal.NAN;
|
|
1400
1462
|
if (this.isZero()) return BigDecimal.ZERO;
|
|
1401
1463
|
const targetPrec = BigDecimal.precision;
|
|
1402
|
-
const
|
|
1464
|
+
const e = decimalExponent(this);
|
|
1465
|
+
if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
|
|
1466
|
+
const workingPrec = targetPrec + 15 + (e < 0 ? -e : 0);
|
|
1467
|
+
if (e > PI_DIGITS.length - workingPrec - 30) return BigDecimal.NAN;
|
|
1403
1468
|
const [fp, scale] = toFixedPoint(this, workingPrec);
|
|
1404
1469
|
const [sinFp] = fpsincos(fp, scale);
|
|
1405
1470
|
return fromFixedPoint(sinFp, scale, targetPrec);
|
|
@@ -1410,6 +1475,8 @@ var Numerics = (() => {
|
|
|
1410
1475
|
if (this.isZero()) return BigDecimal.ONE;
|
|
1411
1476
|
const targetPrec = BigDecimal.precision;
|
|
1412
1477
|
const workingPrec = targetPrec + 15;
|
|
1478
|
+
const e = decimalExponent(this);
|
|
1479
|
+
if (e > PI_DIGITS.length - workingPrec - 30) return BigDecimal.NAN;
|
|
1413
1480
|
const [fp, scale] = toFixedPoint(this, workingPrec);
|
|
1414
1481
|
const [, cosFp] = fpsincos(fp, scale);
|
|
1415
1482
|
return fromFixedPoint(cosFp, scale, targetPrec);
|
|
@@ -1419,7 +1486,10 @@ var Numerics = (() => {
|
|
|
1419
1486
|
if (!this.isFinite()) return BigDecimal.NAN;
|
|
1420
1487
|
if (this.isZero()) return BigDecimal.ZERO;
|
|
1421
1488
|
const targetPrec = BigDecimal.precision;
|
|
1422
|
-
const
|
|
1489
|
+
const e = decimalExponent(this);
|
|
1490
|
+
if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
|
|
1491
|
+
const workingPrec = targetPrec + 15 + (e < 0 ? -e : 0);
|
|
1492
|
+
if (e > PI_DIGITS.length - workingPrec - 30) return BigDecimal.NAN;
|
|
1423
1493
|
const [fp, scale] = toFixedPoint(this, workingPrec);
|
|
1424
1494
|
const [sinFp, cosFp] = fpsincos(fp, scale);
|
|
1425
1495
|
if (cosFp === 0n) {
|
|
@@ -1437,7 +1507,9 @@ var Numerics = (() => {
|
|
|
1437
1507
|
return piHalf.neg();
|
|
1438
1508
|
}
|
|
1439
1509
|
const targetPrec = BigDecimal.precision;
|
|
1440
|
-
const
|
|
1510
|
+
const e = decimalExponent(this);
|
|
1511
|
+
if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
|
|
1512
|
+
const workingPrec = targetPrec + 15 + (e < 0 ? -e : 0);
|
|
1441
1513
|
const [fp, scale] = toFixedPoint(this, workingPrec);
|
|
1442
1514
|
const atanFp = fpatan(fp, scale);
|
|
1443
1515
|
return fromFixedPoint(atanFp, scale, targetPrec);
|
|
@@ -1454,7 +1526,9 @@ var Numerics = (() => {
|
|
|
1454
1526
|
return this.significand > 0n ? piHalf : piHalf.neg();
|
|
1455
1527
|
}
|
|
1456
1528
|
const targetPrec = BigDecimal.precision;
|
|
1457
|
-
const
|
|
1529
|
+
const e = decimalExponent(this);
|
|
1530
|
+
if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
|
|
1531
|
+
const workingPrec = targetPrec + 20 + (e < 0 ? -e : 0);
|
|
1458
1532
|
const [xFp, scale] = toFixedPoint(this, workingPrec);
|
|
1459
1533
|
const x2 = fpmul(xFp, xFp, scale);
|
|
1460
1534
|
const oneMinusX2 = scale - x2;
|
|
@@ -1517,6 +1591,23 @@ var Numerics = (() => {
|
|
|
1517
1591
|
if (this.significand > 0n) return BigDecimal.POSITIVE_INFINITY;
|
|
1518
1592
|
return BigDecimal.NEGATIVE_INFINITY;
|
|
1519
1593
|
}
|
|
1594
|
+
const targetPrec = BigDecimal.precision;
|
|
1595
|
+
const e = decimalExponent(this);
|
|
1596
|
+
if (e < 0) {
|
|
1597
|
+
if (-2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
|
|
1598
|
+
const saved = BigDecimal.precision;
|
|
1599
|
+
BigDecimal.precision = targetPrec - e + 5;
|
|
1600
|
+
try {
|
|
1601
|
+
const expX2 = this.exp();
|
|
1602
|
+
return expX2.sub(expX2.inv()).div(BigDecimal.TWO).toPrecision(targetPrec);
|
|
1603
|
+
} finally {
|
|
1604
|
+
BigDecimal.precision = saved;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
if (Math.abs(this.toNumber()) > 1.16 * (targetPrec + 3)) {
|
|
1608
|
+
const h = this.abs().exp().div(BigDecimal.TWO);
|
|
1609
|
+
return this.significand > 0n ? h : h.neg();
|
|
1610
|
+
}
|
|
1520
1611
|
const expX = this.exp();
|
|
1521
1612
|
const expNegX = expX.inv();
|
|
1522
1613
|
return expX.sub(expNegX).div(BigDecimal.TWO);
|
|
@@ -1527,6 +1618,9 @@ var Numerics = (() => {
|
|
|
1527
1618
|
if (!this.isFinite()) {
|
|
1528
1619
|
return BigDecimal.POSITIVE_INFINITY;
|
|
1529
1620
|
}
|
|
1621
|
+
const targetPrec = BigDecimal.precision;
|
|
1622
|
+
if (Math.abs(this.toNumber()) > 1.16 * (targetPrec + 3))
|
|
1623
|
+
return this.abs().exp().div(BigDecimal.TWO);
|
|
1530
1624
|
const expX = this.exp();
|
|
1531
1625
|
const expNegX = expX.inv();
|
|
1532
1626
|
return expX.add(expNegX).div(BigDecimal.TWO);
|
|
@@ -1538,6 +1632,21 @@ var Numerics = (() => {
|
|
|
1538
1632
|
if (this.significand > 0n) return BigDecimal.ONE;
|
|
1539
1633
|
return BigDecimal.NEGATIVE_ONE;
|
|
1540
1634
|
}
|
|
1635
|
+
const targetPrec = BigDecimal.precision;
|
|
1636
|
+
const e = decimalExponent(this);
|
|
1637
|
+
if (e < 0) {
|
|
1638
|
+
if (-2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
|
|
1639
|
+
const saved = BigDecimal.precision;
|
|
1640
|
+
BigDecimal.precision = targetPrec - e + 5;
|
|
1641
|
+
try {
|
|
1642
|
+
const exp2x2 = this.mul(BigDecimal.TWO).exp();
|
|
1643
|
+
return exp2x2.sub(BigDecimal.ONE).div(exp2x2.add(BigDecimal.ONE)).toPrecision(targetPrec);
|
|
1644
|
+
} finally {
|
|
1645
|
+
BigDecimal.precision = saved;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
if (Math.abs(this.toNumber()) > 1.16 * (targetPrec + 3))
|
|
1649
|
+
return this.significand > 0n ? BigDecimal.ONE : BigDecimal.NEGATIVE_ONE;
|
|
1541
1650
|
const exp2x = this.mul(BigDecimal.TWO).exp();
|
|
1542
1651
|
return exp2x.sub(BigDecimal.ONE).div(exp2x.add(BigDecimal.ONE));
|
|
1543
1652
|
};
|
|
@@ -1624,9 +1733,7 @@ var Numerics = (() => {
|
|
|
1624
1733
|
if (typeof a === "bigint") return a;
|
|
1625
1734
|
if (typeof a === "number") {
|
|
1626
1735
|
if (!Number.isInteger(a)) return null;
|
|
1627
|
-
|
|
1628
|
-
return BigInt(a);
|
|
1629
|
-
return bigint(a.toString());
|
|
1736
|
+
return BigInt(a);
|
|
1630
1737
|
}
|
|
1631
1738
|
if (a instanceof BigDecimal) {
|
|
1632
1739
|
if (!a.isInteger()) return null;
|
|
@@ -2907,7 +3014,8 @@ var Numerics = (() => {
|
|
|
2907
3014
|
[1, 5],
|
|
2908
3015
|
[1, 6],
|
|
2909
3016
|
[1, 7],
|
|
2910
|
-
[
|
|
3017
|
+
[2, 2],
|
|
3018
|
+
// √8 = 2√2
|
|
2911
3019
|
[3, 1],
|
|
2912
3020
|
[1, 10],
|
|
2913
3021
|
[1, 11],
|
|
@@ -2919,7 +3027,8 @@ var Numerics = (() => {
|
|
|
2919
3027
|
[1, 17],
|
|
2920
3028
|
[3, 2],
|
|
2921
3029
|
[1, 19],
|
|
2922
|
-
[
|
|
3030
|
+
[2, 5]
|
|
3031
|
+
// √20 = 2√5
|
|
2923
3032
|
][n];
|
|
2924
3033
|
if (result) return result;
|
|
2925
3034
|
}
|
|
@@ -2944,7 +3053,8 @@ var Numerics = (() => {
|
|
|
2944
3053
|
}
|
|
2945
3054
|
function lcm(a, b) {
|
|
2946
3055
|
if (a === 0 || b === 0) return 0;
|
|
2947
|
-
|
|
3056
|
+
let res = BigInt(a) * BigInt(b) / BigInt(gcd(a, b));
|
|
3057
|
+
if (res < 0n) res = -res;
|
|
2948
3058
|
return Number(res);
|
|
2949
3059
|
}
|
|
2950
3060
|
function factorial(n) {
|
|
@@ -3499,12 +3609,23 @@ var Numerics = (() => {
|
|
|
3499
3609
|
"error",
|
|
3500
3610
|
...EXPRESSION_TYPES
|
|
3501
3611
|
];
|
|
3612
|
+
var NUMERIC_TYPES_SET = new Set(
|
|
3613
|
+
NUMERIC_TYPES
|
|
3614
|
+
);
|
|
3615
|
+
var COLLECTION_TYPES_SET = new Set(
|
|
3616
|
+
COLLECTION_TYPES
|
|
3617
|
+
);
|
|
3618
|
+
var SCALAR_TYPES_SET = new Set(
|
|
3619
|
+
SCALAR_TYPES
|
|
3620
|
+
);
|
|
3621
|
+
var PRIMITIVE_TYPES_SET = new Set(
|
|
3622
|
+
PRIMITIVE_TYPES
|
|
3623
|
+
);
|
|
3502
3624
|
function isValidType(t) {
|
|
3503
|
-
if (typeof t === "string")
|
|
3504
|
-
return PRIMITIVE_TYPES.includes(t);
|
|
3625
|
+
if (typeof t === "string") return PRIMITIVE_TYPES_SET.has(t);
|
|
3505
3626
|
if (typeof t !== "object") return false;
|
|
3506
3627
|
if (!("kind" in t)) return false;
|
|
3507
|
-
return t.kind === "signature" || t.kind === "union" || t.kind === "intersection" || t.kind === "negation" || t.kind === "tuple" || t.kind === "list" || t.kind === "record" || t.kind === "dictionary" || t.kind === "set" || t.kind === "
|
|
3628
|
+
return t.kind === "signature" || t.kind === "union" || t.kind === "intersection" || t.kind === "negation" || t.kind === "value" || t.kind === "tuple" || t.kind === "list" || t.kind === "record" || t.kind === "dictionary" || t.kind === "set" || t.kind === "symbol" || t.kind === "expression" || t.kind === "numeric" || t.kind === "collection" || t.kind === "indexed_collection" || t.kind === "reference";
|
|
3508
3629
|
}
|
|
3509
3630
|
|
|
3510
3631
|
// src/common/type/lexer.ts
|
|
@@ -4214,19 +4335,13 @@ var Numerics = (() => {
|
|
|
4214
4335
|
);
|
|
4215
4336
|
let dimensions;
|
|
4216
4337
|
if (this.match("<")) {
|
|
4217
|
-
dimensions = this.
|
|
4218
|
-
if (!dimensions) {
|
|
4219
|
-
dimensions = this.parseDimensions();
|
|
4220
|
-
}
|
|
4338
|
+
dimensions = this.parseDimensions();
|
|
4221
4339
|
if (!dimensions) {
|
|
4222
4340
|
const type = this.parseUnionType();
|
|
4223
4341
|
if (type) {
|
|
4224
4342
|
elementType = type;
|
|
4225
4343
|
if (this.match("^")) {
|
|
4226
|
-
dimensions = this.
|
|
4227
|
-
if (!dimensions) {
|
|
4228
|
-
dimensions = this.parseDimensions();
|
|
4229
|
-
}
|
|
4344
|
+
dimensions = this.parseCaretDimensions();
|
|
4230
4345
|
}
|
|
4231
4346
|
}
|
|
4232
4347
|
}
|
|
@@ -4267,19 +4382,13 @@ var Numerics = (() => {
|
|
|
4267
4382
|
);
|
|
4268
4383
|
let dimensions;
|
|
4269
4384
|
if (this.match("<")) {
|
|
4270
|
-
dimensions = this.
|
|
4271
|
-
if (!dimensions) {
|
|
4272
|
-
dimensions = this.parseDimensions();
|
|
4273
|
-
}
|
|
4385
|
+
dimensions = this.parseDimensions();
|
|
4274
4386
|
if (!dimensions) {
|
|
4275
4387
|
const type = this.parseUnionType();
|
|
4276
4388
|
if (type) {
|
|
4277
4389
|
elementType = type;
|
|
4278
4390
|
if (this.match("^")) {
|
|
4279
|
-
dimensions = this.
|
|
4280
|
-
if (!dimensions) {
|
|
4281
|
-
dimensions = this.parseDimensions();
|
|
4282
|
-
}
|
|
4391
|
+
dimensions = this.parseCaretDimensions();
|
|
4283
4392
|
}
|
|
4284
4393
|
}
|
|
4285
4394
|
}
|
|
@@ -4310,16 +4419,30 @@ var Numerics = (() => {
|
|
|
4310
4419
|
return this.createNode("tensor", { elementType });
|
|
4311
4420
|
}
|
|
4312
4421
|
parseDimensions() {
|
|
4313
|
-
const dimensions = [];
|
|
4314
4422
|
const firstDim = this.parseDimension();
|
|
4315
4423
|
if (!firstDim) return void 0;
|
|
4316
|
-
dimensions
|
|
4317
|
-
|
|
4318
|
-
const
|
|
4319
|
-
if (
|
|
4320
|
-
this.
|
|
4424
|
+
const dimensions = [firstDim];
|
|
4425
|
+
for (; ; ) {
|
|
4426
|
+
const tok = this.current;
|
|
4427
|
+
if (tok.type === "IDENTIFIER" && /^(x\d+)+$/.test(tok.value)) {
|
|
4428
|
+
this.advance();
|
|
4429
|
+
for (const m of tok.value.match(/x(\d+)/g))
|
|
4430
|
+
dimensions.push(
|
|
4431
|
+
this.createNode("dimension", {
|
|
4432
|
+
size: parseInt(m.slice(1))
|
|
4433
|
+
})
|
|
4434
|
+
);
|
|
4435
|
+
} else if (tok.type === "IDENTIFIER" && tok.value === "x") {
|
|
4436
|
+
const next = this.lexer.peekToken();
|
|
4437
|
+
if (next.type !== "NUMBER_LITERAL" && next.type !== "?")
|
|
4438
|
+
this.error(
|
|
4439
|
+
"Expected a positive integer literal or `?` after x. For example: `2x3` or `2x?`"
|
|
4440
|
+
);
|
|
4441
|
+
this.advance();
|
|
4442
|
+
dimensions.push(this.parseDimension());
|
|
4443
|
+
} else {
|
|
4444
|
+
break;
|
|
4321
4445
|
}
|
|
4322
|
-
dimensions.push(dim);
|
|
4323
4446
|
}
|
|
4324
4447
|
return dimensions;
|
|
4325
4448
|
}
|
|
@@ -4333,35 +4456,11 @@ var Numerics = (() => {
|
|
|
4333
4456
|
}
|
|
4334
4457
|
return void 0;
|
|
4335
4458
|
}
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
this.createNode("dimension", { size: firstDim })
|
|
4342
|
-
);
|
|
4343
|
-
if (this.current.type === "IDENTIFIER" && this.current.value.startsWith("x")) {
|
|
4344
|
-
const dimString = this.current.value;
|
|
4345
|
-
const matches = dimString.match(/x(\d+)/g);
|
|
4346
|
-
if (matches && matches.join("") === dimString) {
|
|
4347
|
-
this.advance();
|
|
4348
|
-
for (const match of matches) {
|
|
4349
|
-
const dimValue = parseInt(match.substring(1));
|
|
4350
|
-
dimensions.push(
|
|
4351
|
-
this.createNode("dimension", { size: dimValue })
|
|
4352
|
-
);
|
|
4353
|
-
}
|
|
4354
|
-
} else if (dimString === "x" || dimString.startsWith("x")) {
|
|
4355
|
-
this.error(
|
|
4356
|
-
"Expected a positive integer literal or `?` after x. For example: `2x3` or `2x?`"
|
|
4357
|
-
);
|
|
4358
|
-
}
|
|
4359
|
-
}
|
|
4360
|
-
if (dimensions.length > 1) {
|
|
4361
|
-
return dimensions;
|
|
4362
|
-
}
|
|
4363
|
-
}
|
|
4364
|
-
return void 0;
|
|
4459
|
+
parseCaretDimensions() {
|
|
4460
|
+
const paren = this.match("(");
|
|
4461
|
+
const dimensions = this.parseDimensions();
|
|
4462
|
+
if (paren) this.expect(")");
|
|
4463
|
+
return dimensions;
|
|
4365
4464
|
}
|
|
4366
4465
|
parseTupleType() {
|
|
4367
4466
|
if (this.current.type === "IDENTIFIER" && this.current.value === "tuple") {
|
|
@@ -4546,6 +4645,18 @@ var Numerics = (() => {
|
|
|
4546
4645
|
this.expect("..");
|
|
4547
4646
|
const upperBound = this.parseValue();
|
|
4548
4647
|
this.expect(">");
|
|
4648
|
+
const lower = lowerBound?.value ?? -Infinity;
|
|
4649
|
+
const upper = upperBound?.value ?? Infinity;
|
|
4650
|
+
if (Number.isNaN(lower) || Number.isNaN(upper))
|
|
4651
|
+
this.error(
|
|
4652
|
+
"Invalid numeric type",
|
|
4653
|
+
"Lower and upper bounds must be valid numbers"
|
|
4654
|
+
);
|
|
4655
|
+
if (lower > upper)
|
|
4656
|
+
this.error(
|
|
4657
|
+
`Invalid range: ${lower}..${upper}`,
|
|
4658
|
+
"The lower bound must be less than the upper bound"
|
|
4659
|
+
);
|
|
4549
4660
|
return this.createNode("numeric", {
|
|
4550
4661
|
baseType,
|
|
4551
4662
|
lowerBound,
|
|
@@ -4560,7 +4671,7 @@ var Numerics = (() => {
|
|
|
4560
4671
|
parsePrimitiveType() {
|
|
4561
4672
|
if (this.current.type === "IDENTIFIER") {
|
|
4562
4673
|
const name = this.current.value;
|
|
4563
|
-
if (
|
|
4674
|
+
if (PRIMITIVE_TYPES_SET.has(name)) {
|
|
4564
4675
|
this.advance();
|
|
4565
4676
|
return this.createNode("primitive", { name });
|
|
4566
4677
|
}
|
|
@@ -4894,14 +5005,32 @@ var Numerics = (() => {
|
|
|
4894
5005
|
}
|
|
4895
5006
|
|
|
4896
5007
|
// src/common/type/parse.ts
|
|
5008
|
+
var TYPE_CACHE = /* @__PURE__ */ new Map();
|
|
5009
|
+
var TYPE_CACHE_MAX_SIZE = 2048;
|
|
5010
|
+
function deepFreeze(obj) {
|
|
5011
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
5012
|
+
if (Object.isFrozen(obj)) return obj;
|
|
5013
|
+
Object.freeze(obj);
|
|
5014
|
+
for (const value of Object.values(obj)) deepFreeze(value);
|
|
5015
|
+
return obj;
|
|
5016
|
+
}
|
|
4897
5017
|
function parseType(s, typeResolver) {
|
|
4898
5018
|
if (s === void 0) return void 0;
|
|
4899
5019
|
if (isValidType(s)) return s;
|
|
4900
5020
|
if (typeof s !== "string") return void 0;
|
|
5021
|
+
const cacheable = typeResolver === void 0;
|
|
5022
|
+
if (cacheable) {
|
|
5023
|
+
const cached = TYPE_CACHE.get(s);
|
|
5024
|
+
if (cached !== void 0) return cached;
|
|
5025
|
+
}
|
|
4901
5026
|
try {
|
|
4902
5027
|
const parser = new Parser(s, { typeResolver });
|
|
4903
5028
|
const ast = parser.parseType();
|
|
4904
5029
|
const type = buildTypeFromAST(ast, typeResolver);
|
|
5030
|
+
if (cacheable) {
|
|
5031
|
+
if (TYPE_CACHE.size >= TYPE_CACHE_MAX_SIZE) TYPE_CACHE.clear();
|
|
5032
|
+
TYPE_CACHE.set(s, deepFreeze(type));
|
|
5033
|
+
}
|
|
4905
5034
|
return type;
|
|
4906
5035
|
} catch (error) {
|
|
4907
5036
|
throw new Error(
|
|
@@ -4976,19 +5105,36 @@ var Numerics = (() => {
|
|
|
4976
5105
|
color: [],
|
|
4977
5106
|
expression: EXPRESSION_TYPES
|
|
4978
5107
|
};
|
|
5108
|
+
var PRIMITIVE_SUBTYPES_CLOSURE = (() => {
|
|
5109
|
+
const closure = {};
|
|
5110
|
+
const closeOver = (t) => {
|
|
5111
|
+
if (closure[t]) return closure[t];
|
|
5112
|
+
const result = /* @__PURE__ */ new Set([t]);
|
|
5113
|
+
closure[t] = result;
|
|
5114
|
+
for (const sub of PRIMITIVE_SUBTYPES[t]) {
|
|
5115
|
+
if (sub === t) continue;
|
|
5116
|
+
for (const s of closeOver(sub)) result.add(s);
|
|
5117
|
+
}
|
|
5118
|
+
return result;
|
|
5119
|
+
};
|
|
5120
|
+
for (const t of Object.keys(PRIMITIVE_SUBTYPES))
|
|
5121
|
+
closeOver(t);
|
|
5122
|
+
return closure;
|
|
5123
|
+
})();
|
|
4979
5124
|
function isPrimitiveSubtype(lhs, rhs) {
|
|
4980
5125
|
if (rhs === "any") return true;
|
|
4981
5126
|
if (lhs === "never") return true;
|
|
4982
5127
|
if (lhs === "unknown" || rhs === "unknown") return false;
|
|
4983
5128
|
if (lhs === rhs) return true;
|
|
4984
|
-
return
|
|
5129
|
+
return PRIMITIVE_SUBTYPES_CLOSURE[rhs].has(lhs);
|
|
4985
5130
|
}
|
|
4986
5131
|
function isSubtype(lhs, rhs) {
|
|
4987
|
-
if (typeof lhs === "string" && !
|
|
5132
|
+
if (typeof lhs === "string" && !PRIMITIVE_TYPES_SET.has(lhs))
|
|
4988
5133
|
lhs = parseType(lhs);
|
|
4989
|
-
if (typeof rhs === "string" && !
|
|
5134
|
+
if (typeof rhs === "string" && !PRIMITIVE_TYPES_SET.has(rhs))
|
|
4990
5135
|
rhs = parseType(rhs);
|
|
4991
5136
|
if (rhs === "any") return true;
|
|
5137
|
+
if (lhs === "never") return true;
|
|
4992
5138
|
if (rhs === "never") return false;
|
|
4993
5139
|
if (rhs === "error") return lhs === "error";
|
|
4994
5140
|
if (rhs === "nothing") return lhs === "nothing";
|
|
@@ -5003,7 +5149,7 @@ var Numerics = (() => {
|
|
|
5003
5149
|
if (typeof lhs.value === "number") {
|
|
5004
5150
|
if (Number.isInteger(lhs.value))
|
|
5005
5151
|
return isPrimitiveSubtype("integer", rhs);
|
|
5006
|
-
return isPrimitiveSubtype("
|
|
5152
|
+
return isPrimitiveSubtype("real", rhs);
|
|
5007
5153
|
}
|
|
5008
5154
|
if (typeof lhs.value === "boolean")
|
|
5009
5155
|
return isPrimitiveSubtype("boolean", rhs);
|
|
@@ -5233,7 +5379,7 @@ var Numerics = (() => {
|
|
|
5233
5379
|
}
|
|
5234
5380
|
function isNumeric(type) {
|
|
5235
5381
|
if (typeof type === "string")
|
|
5236
|
-
return
|
|
5382
|
+
return NUMERIC_TYPES_SET.has(type);
|
|
5237
5383
|
if (type.kind === "value") return typeof type.value === "number";
|
|
5238
5384
|
if (type.kind === "numeric") return true;
|
|
5239
5385
|
return false;
|
|
@@ -5241,7 +5387,7 @@ var Numerics = (() => {
|
|
|
5241
5387
|
function isScalar(type) {
|
|
5242
5388
|
if (isNumeric(type)) return true;
|
|
5243
5389
|
if (typeof type === "string")
|
|
5244
|
-
return
|
|
5390
|
+
return SCALAR_TYPES_SET.has(type);
|
|
5245
5391
|
if (type.kind === "value")
|
|
5246
5392
|
return ["string", "boolean", "number"].includes(typeof type.value);
|
|
5247
5393
|
return false;
|
|
@@ -5249,7 +5395,7 @@ var Numerics = (() => {
|
|
|
5249
5395
|
function isCollection(type) {
|
|
5250
5396
|
if (isIndexedCollection(type)) return true;
|
|
5251
5397
|
if (typeof type === "string")
|
|
5252
|
-
return
|
|
5398
|
+
return COLLECTION_TYPES_SET.has(type);
|
|
5253
5399
|
return ["collection", "set", "record", "dictionary"].includes(type.kind);
|
|
5254
5400
|
}
|
|
5255
5401
|
function isIndexedCollection(type) {
|
|
@@ -5288,13 +5434,75 @@ var Numerics = (() => {
|
|
|
5288
5434
|
if (b === "nothing") return a;
|
|
5289
5435
|
if (isSubtype(a, b)) return b;
|
|
5290
5436
|
if (isSubtype(b, a)) return a;
|
|
5291
|
-
|
|
5437
|
+
const sup = superType(a, b);
|
|
5438
|
+
if (LOSSY_SUPERTYPE.has(sup)) return unionTypes(a, b);
|
|
5439
|
+
return sup;
|
|
5440
|
+
}
|
|
5441
|
+
var LOSSY_SUPERTYPE = /* @__PURE__ */ new Set([
|
|
5442
|
+
"scalar",
|
|
5443
|
+
"value",
|
|
5444
|
+
"function",
|
|
5445
|
+
"expression",
|
|
5446
|
+
"collection",
|
|
5447
|
+
"indexed_collection",
|
|
5448
|
+
"list",
|
|
5449
|
+
"set",
|
|
5450
|
+
"tuple",
|
|
5451
|
+
"record",
|
|
5452
|
+
"dictionary",
|
|
5453
|
+
"map",
|
|
5454
|
+
"any"
|
|
5455
|
+
]);
|
|
5456
|
+
function unionTypes(a, b) {
|
|
5457
|
+
const members = [];
|
|
5458
|
+
const keys = /* @__PURE__ */ new Set();
|
|
5459
|
+
const push = (t) => {
|
|
5460
|
+
if (typeof t === "object" && t.kind === "union") {
|
|
5461
|
+
for (const m of t.types) push(m);
|
|
5462
|
+
return;
|
|
5463
|
+
}
|
|
5464
|
+
const key = typeof t === "string" ? t : JSON.stringify(t);
|
|
5465
|
+
if (!keys.has(key)) {
|
|
5466
|
+
keys.add(key);
|
|
5467
|
+
members.push(t);
|
|
5468
|
+
}
|
|
5469
|
+
};
|
|
5470
|
+
push(a);
|
|
5471
|
+
push(b);
|
|
5472
|
+
if (members.length === 1) return members[0];
|
|
5473
|
+
return { kind: "union", types: members };
|
|
5292
5474
|
}
|
|
5293
5475
|
function widen(...types) {
|
|
5294
5476
|
if (types.length === 0) return "nothing";
|
|
5295
5477
|
if (types.length === 1) return types[0];
|
|
5296
5478
|
return types.reduce((a, b) => widen2(a, b));
|
|
5297
5479
|
}
|
|
5480
|
+
var SUPERTYPE_PROBE_ORDER = [
|
|
5481
|
+
"non_finite_number",
|
|
5482
|
+
"finite_integer",
|
|
5483
|
+
"integer",
|
|
5484
|
+
"finite_rational",
|
|
5485
|
+
"rational",
|
|
5486
|
+
"finite_real",
|
|
5487
|
+
"real",
|
|
5488
|
+
"imaginary",
|
|
5489
|
+
"finite_complex",
|
|
5490
|
+
"complex",
|
|
5491
|
+
"finite_number",
|
|
5492
|
+
"number",
|
|
5493
|
+
"list",
|
|
5494
|
+
"record",
|
|
5495
|
+
"dictionary",
|
|
5496
|
+
"set",
|
|
5497
|
+
"tuple",
|
|
5498
|
+
"indexed_collection",
|
|
5499
|
+
"collection",
|
|
5500
|
+
"scalar",
|
|
5501
|
+
"value",
|
|
5502
|
+
"function",
|
|
5503
|
+
"expression"
|
|
5504
|
+
];
|
|
5505
|
+
var PRIMITIVE_SUPERTYPE_CACHE = /* @__PURE__ */ new Map();
|
|
5298
5506
|
function superType(a, b) {
|
|
5299
5507
|
if (a === b) return a;
|
|
5300
5508
|
if (a === "any" || b === "any") return "any";
|
|
@@ -5304,35 +5512,26 @@ var Numerics = (() => {
|
|
|
5304
5512
|
if (b === "unknown") return a;
|
|
5305
5513
|
if (a === "nothing") return b;
|
|
5306
5514
|
if (b === "nothing") return a;
|
|
5307
|
-
if (
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
if (commonSupertype(a, b, "collection")) return "collection";
|
|
5326
|
-
if (commonSupertype(a, b, "scalar")) return "scalar";
|
|
5327
|
-
if (commonSupertype(a, b, "value")) return "value";
|
|
5328
|
-
if (commonSupertype(a, b, "function")) return "function";
|
|
5329
|
-
if (commonSupertype(a, b, "expression")) return "expression";
|
|
5515
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
5516
|
+
const key = a < b ? `${a}|${b}` : `${b}|${a}`;
|
|
5517
|
+
let result = PRIMITIVE_SUPERTYPE_CACHE.get(key);
|
|
5518
|
+
if (result === void 0) {
|
|
5519
|
+
result = "any";
|
|
5520
|
+
for (const ancestor of SUPERTYPE_PROBE_ORDER) {
|
|
5521
|
+
const subtypes = PRIMITIVE_SUBTYPES_CLOSURE[ancestor];
|
|
5522
|
+
if (subtypes.has(a) && subtypes.has(b)) {
|
|
5523
|
+
result = ancestor;
|
|
5524
|
+
break;
|
|
5525
|
+
}
|
|
5526
|
+
}
|
|
5527
|
+
PRIMITIVE_SUPERTYPE_CACHE.set(key, result);
|
|
5528
|
+
}
|
|
5529
|
+
return result;
|
|
5530
|
+
}
|
|
5531
|
+
for (const ancestor of SUPERTYPE_PROBE_ORDER)
|
|
5532
|
+
if (isSubtype(a, ancestor) && isSubtype(b, ancestor)) return ancestor;
|
|
5330
5533
|
return "any";
|
|
5331
5534
|
}
|
|
5332
|
-
function commonSupertype(a, b, ancestor) {
|
|
5333
|
-
if (isSubtype(a, ancestor) && isSubtype(b, ancestor)) return true;
|
|
5334
|
-
return false;
|
|
5335
|
-
}
|
|
5336
5535
|
|
|
5337
5536
|
// src/compute-engine/numeric-value/exact-numeric-value.ts
|
|
5338
5537
|
var ExactNumericValue = class _ExactNumericValue extends NumericValue {
|
|
@@ -5550,6 +5749,10 @@ var Numerics = (() => {
|
|
|
5550
5749
|
});
|
|
5551
5750
|
}
|
|
5552
5751
|
inv() {
|
|
5752
|
+
if (this.isNaN) return this;
|
|
5753
|
+
if (this.isPositiveInfinity || this.isNegativeInfinity)
|
|
5754
|
+
return this.clone(0);
|
|
5755
|
+
if (this.isZero) return this.clone(Infinity);
|
|
5553
5756
|
if (this.isOne) return this;
|
|
5554
5757
|
if (this.isNegativeOne) return this;
|
|
5555
5758
|
return this.clone({
|
|
@@ -5668,7 +5871,7 @@ var Numerics = (() => {
|
|
|
5668
5871
|
} else {
|
|
5669
5872
|
if (exponent instanceof _ExactNumericValue) {
|
|
5670
5873
|
if (exponent.radical === 1 && exponent.rational[0] == 1)
|
|
5671
|
-
return this.root(exponent.rational[
|
|
5874
|
+
return this.root(Number(exponent.rational[1]));
|
|
5672
5875
|
}
|
|
5673
5876
|
exponent = exponent.re;
|
|
5674
5877
|
}
|
|
@@ -5803,19 +6006,52 @@ var Numerics = (() => {
|
|
|
5803
6006
|
if (this.isPositiveInfinity) return this.clone(Infinity);
|
|
5804
6007
|
return this.factory(this.bignumRe).exp();
|
|
5805
6008
|
}
|
|
6009
|
+
/**
|
|
6010
|
+
* Floor/ceil/round of a pure rational (`radical === 1`) computed exactly with
|
|
6011
|
+
* bigints. Routing through `this.re` (a float) would lose digits for
|
|
6012
|
+
* integers/rationals larger than 2^53.
|
|
6013
|
+
*/
|
|
6014
|
+
_integerPart(mode2) {
|
|
6015
|
+
let n = BigInt(this.rational[0]);
|
|
6016
|
+
let d = BigInt(this.rational[1]);
|
|
6017
|
+
if (d < 0n) {
|
|
6018
|
+
n = -n;
|
|
6019
|
+
d = -d;
|
|
6020
|
+
}
|
|
6021
|
+
let q;
|
|
6022
|
+
if (mode2 === "round") {
|
|
6023
|
+
const m = 2n * n + d;
|
|
6024
|
+
const dd = 2n * d;
|
|
6025
|
+
q = m / dd;
|
|
6026
|
+
if (m % dd !== 0n && m < 0n) q -= 1n;
|
|
6027
|
+
} else {
|
|
6028
|
+
q = n / d;
|
|
6029
|
+
const r = n % d;
|
|
6030
|
+
if (r !== 0n) {
|
|
6031
|
+
if (mode2 === "floor" && n < 0n) q -= 1n;
|
|
6032
|
+
if (mode2 === "ceil" && n > 0n) q += 1n;
|
|
6033
|
+
}
|
|
6034
|
+
}
|
|
6035
|
+
return this.clone({ rational: [q, BigInt(1)], radical: 1 });
|
|
6036
|
+
}
|
|
6037
|
+
// An exact value is an integer iff it has no radical part and a unit
|
|
6038
|
+
// denominator. (`this.type` returns `'finite_integer'`, never `'integer'`.)
|
|
5806
6039
|
floor() {
|
|
5807
6040
|
if (this.isNaN) return this.clone(NaN);
|
|
5808
|
-
if (this.
|
|
6041
|
+
if (this.radical === 1 && isInteger(this.rational)) return this;
|
|
6042
|
+
if (this.radical === 1) return this._integerPart("floor");
|
|
5809
6043
|
return this.clone(Math.floor(this.re));
|
|
5810
6044
|
}
|
|
5811
6045
|
ceil() {
|
|
5812
6046
|
if (this.isNaN) return this.clone(NaN);
|
|
5813
|
-
if (this.
|
|
6047
|
+
if (this.radical === 1 && isInteger(this.rational)) return this;
|
|
6048
|
+
if (this.radical === 1) return this._integerPart("ceil");
|
|
5814
6049
|
return this.clone(Math.ceil(this.re));
|
|
5815
6050
|
}
|
|
5816
6051
|
round() {
|
|
5817
6052
|
if (this.isNaN) return this.clone(NaN);
|
|
5818
|
-
if (this.
|
|
6053
|
+
if (this.radical === 1 && isInteger(this.rational)) return this;
|
|
6054
|
+
if (this.radical === 1) return this._integerPart("round");
|
|
5819
6055
|
return this.clone(Math.round(this.re));
|
|
5820
6056
|
}
|
|
5821
6057
|
eq(other) {
|
|
@@ -5914,7 +6150,7 @@ var Numerics = (() => {
|
|
|
5914
6150
|
return a.abs();
|
|
5915
6151
|
}
|
|
5916
6152
|
function lcm3(a, b) {
|
|
5917
|
-
return a.mul(b).div(gcd3(a, b));
|
|
6153
|
+
return a.mul(b).div(gcd3(a, b)).abs();
|
|
5918
6154
|
}
|
|
5919
6155
|
function* factorial22(n) {
|
|
5920
6156
|
if (!n.isInteger() || n.isNegative()) return BigDecimal.NAN;
|
|
@@ -6094,8 +6330,8 @@ var Numerics = (() => {
|
|
|
6094
6330
|
if (this.isOne) return this;
|
|
6095
6331
|
if (this.isNegativeOne) return this;
|
|
6096
6332
|
if (this.im === 0) return this.clone(this.decimal.inv());
|
|
6097
|
-
const d =
|
|
6098
|
-
const bigD = this.decimal.mul(this.decimal).add(this.im * this.im)
|
|
6333
|
+
const d = this.re * this.re + this.im * this.im;
|
|
6334
|
+
const bigD = this.decimal.mul(this.decimal).add(this.im * this.im);
|
|
6099
6335
|
return this.clone({ re: this.decimal.div(bigD), im: -this.im / d });
|
|
6100
6336
|
}
|
|
6101
6337
|
add(other) {
|
|
@@ -6122,7 +6358,7 @@ var Numerics = (() => {
|
|
|
6122
6358
|
if (other === 1) return this;
|
|
6123
6359
|
if (other === -1) return this.neg();
|
|
6124
6360
|
if (other === 0) {
|
|
6125
|
-
if (this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
|
|
6361
|
+
if (this.isNaN || this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
|
|
6126
6362
|
return this._makeExact(NaN);
|
|
6127
6363
|
return this.clone(0);
|
|
6128
6364
|
}
|
|
@@ -6152,7 +6388,7 @@ var Numerics = (() => {
|
|
|
6152
6388
|
if (other.isOne) return this;
|
|
6153
6389
|
if (other.isNegativeOne) return this.neg();
|
|
6154
6390
|
if (other.isZero) {
|
|
6155
|
-
if (this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
|
|
6391
|
+
if (this.isNaN || this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
|
|
6156
6392
|
return this._makeExact(NaN);
|
|
6157
6393
|
return this.clone(0);
|
|
6158
6394
|
}
|
|
@@ -6175,7 +6411,11 @@ var Numerics = (() => {
|
|
|
6175
6411
|
}
|
|
6176
6412
|
if (other.isOne) return this;
|
|
6177
6413
|
if (other.isNegativeOne) return this.neg();
|
|
6178
|
-
if (other.isZero)
|
|
6414
|
+
if (other.isZero) {
|
|
6415
|
+
if (this.isZero || this.isNaN) return this.clone(NaN);
|
|
6416
|
+
if (this.im !== 0) return this.clone({ im: Infinity });
|
|
6417
|
+
return this.clone(this.decimal.isNegative() ? -Infinity : Infinity);
|
|
6418
|
+
}
|
|
6179
6419
|
if (this.im === 0 && other.im === 0)
|
|
6180
6420
|
return this.clone(this.decimal.div(other.bignumRe ?? other.re));
|
|
6181
6421
|
const [a, b] = [this.re, this.im];
|
|
@@ -6209,13 +6449,18 @@ var Numerics = (() => {
|
|
|
6209
6449
|
if (this.im === Infinity) return this.clone(NaN);
|
|
6210
6450
|
if (this.isNegativeInfinity) return this.clone(0);
|
|
6211
6451
|
if (this.isPositiveInfinity) return this.clone({ im: Infinity });
|
|
6212
|
-
|
|
6213
|
-
const
|
|
6214
|
-
const
|
|
6215
|
-
|
|
6216
|
-
|
|
6452
|
+
if (this.isZero) return re > 0 ? this.clone(0) : this.clone(NaN);
|
|
6453
|
+
const a2 = this.decimal;
|
|
6454
|
+
const b2 = this.im;
|
|
6455
|
+
const lnMod = a2.mul(a2).add(b2 * b2).sqrt().ln();
|
|
6456
|
+
const arg = BigDecimal.atan2(b2, a2);
|
|
6457
|
+
const realExp = lnMod.mul(re).sub(arg.mul(im));
|
|
6458
|
+
const imagExp = arg.mul(re).add(lnMod.mul(im));
|
|
6459
|
+
const mag = realExp.exp();
|
|
6460
|
+
return this.clone({
|
|
6461
|
+
re: mag.mul(imagExp.cos()),
|
|
6462
|
+
im: chop2(mag.mul(imagExp.sin()).toNumber())
|
|
6217
6463
|
});
|
|
6218
|
-
return zRe.mul(zIm);
|
|
6219
6464
|
}
|
|
6220
6465
|
}
|
|
6221
6466
|
if (this.isPositiveInfinity) {
|
|
@@ -6259,13 +6504,13 @@ var Numerics = (() => {
|
|
|
6259
6504
|
if (this.decimal.isNegative()) return this._makeExact(NaN);
|
|
6260
6505
|
if (exp === 2) return this.clone(this.decimal.sqrt());
|
|
6261
6506
|
if (exp === 3) return this.clone(this.decimal.cbrt());
|
|
6262
|
-
return this.clone(this.decimal.
|
|
6507
|
+
return this.clone(this.decimal.ln().div(exp).exp());
|
|
6263
6508
|
}
|
|
6264
6509
|
const a = this.decimal;
|
|
6265
6510
|
const b = this.im;
|
|
6266
6511
|
const modulus = a.mul(a).add(b * b).sqrt();
|
|
6267
6512
|
const argument = BigDecimal.atan2(b, a);
|
|
6268
|
-
const newModulus = modulus.
|
|
6513
|
+
const newModulus = modulus.ln().div(exp).exp();
|
|
6269
6514
|
const newArgument = argument.div(exp);
|
|
6270
6515
|
return this.clone({
|
|
6271
6516
|
re: newModulus.mul(newArgument.cos()),
|
|
@@ -6531,7 +6776,7 @@ var Numerics = (() => {
|
|
|
6531
6776
|
if (this.isOne) return this;
|
|
6532
6777
|
if (this.isNegativeOne) return this;
|
|
6533
6778
|
if (this.im === 0) return this.clone(1 / this.decimal);
|
|
6534
|
-
const d =
|
|
6779
|
+
const d = this.re * this.re + this.im * this.im;
|
|
6535
6780
|
return this.clone({ re: this.decimal / d, im: -this.im / d });
|
|
6536
6781
|
}
|
|
6537
6782
|
add(other) {
|
|
@@ -6641,11 +6886,17 @@ var Numerics = (() => {
|
|
|
6641
6886
|
if (this.im === Infinity) return this.clone(NaN);
|
|
6642
6887
|
if (this.isNegativeInfinity) return this.clone(0);
|
|
6643
6888
|
if (this.isPositiveInfinity) return this.clone({ im: Infinity });
|
|
6644
|
-
|
|
6645
|
-
const
|
|
6889
|
+
if (this.isZero) return re > 0 ? this.clone(0) : this.clone(NaN);
|
|
6890
|
+
const a2 = this.decimal;
|
|
6891
|
+
const b2 = this.im;
|
|
6892
|
+
const lnMod = 0.5 * Math.log(a2 * a2 + b2 * b2);
|
|
6893
|
+
const arg = Math.atan2(b2, a2);
|
|
6894
|
+
const realExp = re * lnMod - im * arg;
|
|
6895
|
+
const imagExp = re * arg + im * lnMod;
|
|
6896
|
+
const mag = Math.exp(realExp);
|
|
6646
6897
|
return this.clone({
|
|
6647
|
-
re: chop3(
|
|
6648
|
-
im: chop3(
|
|
6898
|
+
re: chop3(mag * Math.cos(imagExp)),
|
|
6899
|
+
im: chop3(mag * Math.sin(imagExp))
|
|
6649
6900
|
});
|
|
6650
6901
|
}
|
|
6651
6902
|
}
|
|
@@ -6664,14 +6915,15 @@ var Numerics = (() => {
|
|
|
6664
6915
|
if (exponent > 0) return this;
|
|
6665
6916
|
if (exponent < 0) return this.clone({ im: Infinity });
|
|
6666
6917
|
}
|
|
6667
|
-
if (exponent < 0
|
|
6918
|
+
if (exponent < 0 && this.im === 0)
|
|
6919
|
+
return this.clone(1 / this.decimal ** -exponent);
|
|
6668
6920
|
if (this.im === 0) return this.clone(this.decimal ** exponent);
|
|
6669
6921
|
const a = this.decimal;
|
|
6670
6922
|
const b = this.im;
|
|
6671
6923
|
const modulus = Math.sqrt(a * a + b * b);
|
|
6672
6924
|
const argument = Math.atan2(b, a);
|
|
6673
6925
|
const newModulus = modulus ** exponent;
|
|
6674
|
-
const newArgument = argument
|
|
6926
|
+
const newArgument = argument * exponent;
|
|
6675
6927
|
return this.clone({
|
|
6676
6928
|
re: newModulus * Math.cos(newArgument),
|
|
6677
6929
|
im: newModulus * Math.sin(newArgument)
|
|
@@ -6792,10 +7044,10 @@ var Numerics = (() => {
|
|
|
6792
7044
|
eq(other) {
|
|
6793
7045
|
if (this.isNaN) return false;
|
|
6794
7046
|
if (typeof other === "number")
|
|
6795
|
-
return this.im === 0 && this.decimal
|
|
7047
|
+
return this.im === 0 && this.decimal === other;
|
|
6796
7048
|
if (other.isNaN) return false;
|
|
6797
7049
|
if (!Number.isFinite(this.im)) return !Number.isFinite(other.im);
|
|
6798
|
-
return this.decimal
|
|
7050
|
+
return this.decimal === other.re && this.im === other.im;
|
|
6799
7051
|
}
|
|
6800
7052
|
lt(other) {
|
|
6801
7053
|
if (this.im !== 0) return void 0;
|
|
@@ -6877,42 +7129,20 @@ var Numerics = (() => {
|
|
|
6877
7129
|
return void 0;
|
|
6878
7130
|
}
|
|
6879
7131
|
function intervalContains(int, val) {
|
|
6880
|
-
if (int.openStart)
|
|
6881
|
-
|
|
6882
|
-
}
|
|
6883
|
-
if (int.start < val) return false;
|
|
6884
|
-
if (int.openEnd) {
|
|
6885
|
-
if (int.end >= val) return false;
|
|
6886
|
-
}
|
|
6887
|
-
if (int.end > val) return false;
|
|
7132
|
+
if (int.openStart ? val <= int.start : val < int.start) return false;
|
|
7133
|
+
if (int.openEnd ? val >= int.end : val > int.end) return false;
|
|
6888
7134
|
return true;
|
|
6889
7135
|
}
|
|
6890
7136
|
function intervalSubset(int1, int2) {
|
|
6891
|
-
if (int1.openStart) {
|
|
6892
|
-
if (int2.
|
|
6893
|
-
if (int1.start <= int2.start) return false;
|
|
6894
|
-
} else {
|
|
6895
|
-
if (int1.start < int2.start) return false;
|
|
6896
|
-
}
|
|
7137
|
+
if (!int1.openStart && int2.openStart) {
|
|
7138
|
+
if (int1.start <= int2.start) return false;
|
|
6897
7139
|
} else {
|
|
6898
|
-
if (int2.
|
|
6899
|
-
if (int1.start <= int2.start) return false;
|
|
6900
|
-
} else {
|
|
6901
|
-
if (int1.start < int2.start) return false;
|
|
6902
|
-
}
|
|
7140
|
+
if (int1.start < int2.start) return false;
|
|
6903
7141
|
}
|
|
6904
|
-
if (int1.openEnd) {
|
|
6905
|
-
if (int2.
|
|
6906
|
-
if (int1.end >= int2.end) return false;
|
|
6907
|
-
} else {
|
|
6908
|
-
if (int1.end > int2.end) return false;
|
|
6909
|
-
}
|
|
7142
|
+
if (!int1.openEnd && int2.openEnd) {
|
|
7143
|
+
if (int1.end >= int2.end) return false;
|
|
6910
7144
|
} else {
|
|
6911
|
-
if (int2.
|
|
6912
|
-
if (int1.end >= int2.end) return false;
|
|
6913
|
-
} else {
|
|
6914
|
-
if (int1.end > int2.end) return false;
|
|
6915
|
-
}
|
|
7145
|
+
if (int1.end > int2.end) return false;
|
|
6916
7146
|
}
|
|
6917
7147
|
return true;
|
|
6918
7148
|
}
|
|
@@ -7095,6 +7325,7 @@ var Numerics = (() => {
|
|
|
7095
7325
|
function kurtosis(values) {
|
|
7096
7326
|
let sum = 0;
|
|
7097
7327
|
let sum2 = 0;
|
|
7328
|
+
let sum3 = 0;
|
|
7098
7329
|
let sum4 = 0;
|
|
7099
7330
|
let count = 0;
|
|
7100
7331
|
for (const op of values) {
|
|
@@ -7102,16 +7333,21 @@ var Numerics = (() => {
|
|
|
7102
7333
|
if (!Number.isFinite(v)) return NaN;
|
|
7103
7334
|
sum += v;
|
|
7104
7335
|
sum2 += v * v;
|
|
7336
|
+
sum3 += v * v * v;
|
|
7105
7337
|
sum4 += v * v * v * v;
|
|
7106
7338
|
count++;
|
|
7107
7339
|
}
|
|
7108
7340
|
if (count === 0) return NaN;
|
|
7109
|
-
const
|
|
7110
|
-
|
|
7341
|
+
const n = count;
|
|
7342
|
+
const m = sum / n;
|
|
7343
|
+
const m2 = (sum2 - sum * sum / n) / n;
|
|
7344
|
+
const m4 = (sum4 - 4 * m * sum3 + 6 * m * m * sum2 - 4 * m * m * m * sum + n * m * m * m * m) / n;
|
|
7345
|
+
return m4 / (m2 * m2);
|
|
7111
7346
|
}
|
|
7112
7347
|
function bigKurtosis(values) {
|
|
7113
7348
|
let sum = BigDecimal.ZERO;
|
|
7114
7349
|
let sum2 = BigDecimal.ZERO;
|
|
7350
|
+
let sum3 = BigDecimal.ZERO;
|
|
7115
7351
|
let sum4 = BigDecimal.ZERO;
|
|
7116
7352
|
let count = 0;
|
|
7117
7353
|
for (const op of values) {
|
|
@@ -7119,15 +7355,15 @@ var Numerics = (() => {
|
|
|
7119
7355
|
if (!v.isFinite()) return BigDecimal.NAN;
|
|
7120
7356
|
sum = sum.add(v);
|
|
7121
7357
|
sum2 = sum2.add(v.mul(v));
|
|
7358
|
+
sum3 = sum3.add(v.mul(v).mul(v));
|
|
7122
7359
|
sum4 = sum4.add(v.mul(v).mul(v).mul(v));
|
|
7123
7360
|
count++;
|
|
7124
7361
|
}
|
|
7125
7362
|
if (count === 0) return BigDecimal.NAN;
|
|
7126
|
-
const
|
|
7127
|
-
const
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
).div(s2.mul(s2));
|
|
7363
|
+
const m = sum.div(count);
|
|
7364
|
+
const m2 = sum2.sub(sum.mul(sum).div(count)).div(count);
|
|
7365
|
+
const m4 = sum4.sub(m.mul(sum3).mul(4)).add(m.mul(m).mul(sum2).mul(6)).sub(m.mul(m).mul(m).mul(sum).mul(4)).add(m.mul(m).mul(m).mul(m).mul(count)).div(count);
|
|
7366
|
+
return m4.div(m2.mul(m2));
|
|
7131
7367
|
}
|
|
7132
7368
|
function skewness(values) {
|
|
7133
7369
|
let sum = 0;
|
|
@@ -7143,9 +7379,11 @@ var Numerics = (() => {
|
|
|
7143
7379
|
count++;
|
|
7144
7380
|
}
|
|
7145
7381
|
if (count === 0) return NaN;
|
|
7146
|
-
const
|
|
7147
|
-
const
|
|
7148
|
-
|
|
7382
|
+
const n = count;
|
|
7383
|
+
const m = sum / n;
|
|
7384
|
+
const m2 = (sum2 - sum * sum / n) / n;
|
|
7385
|
+
const m3 = (sum3 - 3 * m * sum2 + 3 * m * m * sum - n * m * m * m) / n;
|
|
7386
|
+
return m3 / Math.pow(m2, 3 / 2);
|
|
7149
7387
|
}
|
|
7150
7388
|
function bigSkewness(values) {
|
|
7151
7389
|
let sum = BigDecimal.ZERO;
|
|
@@ -7161,10 +7399,10 @@ var Numerics = (() => {
|
|
|
7161
7399
|
count++;
|
|
7162
7400
|
}
|
|
7163
7401
|
if (count === 0) return BigDecimal.NAN;
|
|
7164
|
-
const
|
|
7165
|
-
const
|
|
7166
|
-
const
|
|
7167
|
-
return
|
|
7402
|
+
const m = sum.div(count);
|
|
7403
|
+
const m2 = sum2.sub(sum.mul(sum).div(count)).div(count);
|
|
7404
|
+
const m3 = sum3.sub(m.mul(sum2).mul(3)).add(m.mul(m).mul(sum).mul(3)).sub(m.mul(m).mul(m).mul(count)).div(count);
|
|
7405
|
+
return m3.div(m2.mul(m2.sqrt()));
|
|
7168
7406
|
}
|
|
7169
7407
|
function mode(values) {
|
|
7170
7408
|
const counts = {};
|
|
@@ -7215,18 +7453,12 @@ var Numerics = (() => {
|
|
|
7215
7453
|
return [q1, q2, q3];
|
|
7216
7454
|
}
|
|
7217
7455
|
function interquartileRange(values) {
|
|
7218
|
-
const
|
|
7219
|
-
|
|
7220
|
-
const lower = sorted.slice(0, mid);
|
|
7221
|
-
const upper = sorted.slice(mid + 1);
|
|
7222
|
-
return median(upper) - median(lower);
|
|
7456
|
+
const [q1, , q3] = quartiles(values);
|
|
7457
|
+
return q3 - q1;
|
|
7223
7458
|
}
|
|
7224
7459
|
function bigInterquartileRange(values) {
|
|
7225
|
-
const
|
|
7226
|
-
|
|
7227
|
-
const lower = sorted.slice(0, mid);
|
|
7228
|
-
const upper = sorted.slice(mid + 1);
|
|
7229
|
-
return bigMedian(upper).sub(bigMedian(lower));
|
|
7460
|
+
const [q1, , q3] = bigQuartiles(values);
|
|
7461
|
+
return q3.sub(q1);
|
|
7230
7462
|
}
|
|
7231
7463
|
|
|
7232
7464
|
// src/compute-engine/numerics/unit-data.ts
|
|
@@ -7601,9 +7833,14 @@ var Numerics = (() => {
|
|
|
7601
7833
|
];
|
|
7602
7834
|
function gammaln(z) {
|
|
7603
7835
|
if (z < 0) return NaN;
|
|
7836
|
+
let shift = 0;
|
|
7837
|
+
while (z < 10) {
|
|
7838
|
+
shift += Math.log(z);
|
|
7839
|
+
z += 1;
|
|
7840
|
+
}
|
|
7604
7841
|
const pi = Math.PI;
|
|
7605
7842
|
const z3 = z * z * z;
|
|
7606
|
-
return z * Math.log(z) - z - 0.5 * Math.log(z) + 0.5 * Math.log(2 * pi) + 1 / (12 * z) - 1 / (360 * z3) + 1 / (1260 * z3 * z * z);
|
|
7843
|
+
return z * Math.log(z) - z - 0.5 * Math.log(z) + 0.5 * Math.log(2 * pi) + 1 / (12 * z) - 1 / (360 * z3) + 1 / (1260 * z3 * z * z) - shift;
|
|
7607
7844
|
}
|
|
7608
7845
|
function gamma(z) {
|
|
7609
7846
|
if (z < 0.5) return Math.PI / (Math.sin(Math.PI * z) * gamma(1 - z));
|
|
@@ -7614,31 +7851,62 @@ var Numerics = (() => {
|
|
|
7614
7851
|
const t = z + gammaG + 0.5;
|
|
7615
7852
|
return Math.sqrt(2 * Math.PI) * Math.pow(t, z + 0.5) * Math.exp(-t) * x;
|
|
7616
7853
|
}
|
|
7854
|
+
function erfInvApprox(x) {
|
|
7855
|
+
const a = 0.147;
|
|
7856
|
+
const ln1mx2 = Math.log(1 - x * x);
|
|
7857
|
+
const b = 2 / (Math.PI * a) + ln1mx2 / 2;
|
|
7858
|
+
return Math.sign(x) * Math.sqrt(Math.sqrt(b * b - ln1mx2 / a) - b);
|
|
7859
|
+
}
|
|
7617
7860
|
function erfInv(x) {
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
const
|
|
7623
|
-
const
|
|
7624
|
-
|
|
7625
|
-
|
|
7861
|
+
if (Number.isNaN(x) || x < -1 || x > 1) return NaN;
|
|
7862
|
+
if (x === 0) return 0;
|
|
7863
|
+
if (x === 1) return Infinity;
|
|
7864
|
+
if (x === -1) return -Infinity;
|
|
7865
|
+
const sign = x < 0 ? -1 : 1;
|
|
7866
|
+
const ax = Math.abs(x);
|
|
7867
|
+
let y = erfInvApprox(ax);
|
|
7868
|
+
const c = Math.sqrt(Math.PI) / 2;
|
|
7869
|
+
for (let i = 0; i < 4; i++) y -= (erf(y) - ax) * c * Math.exp(y * y);
|
|
7870
|
+
return sign * y;
|
|
7626
7871
|
}
|
|
7627
7872
|
function erfc(x) {
|
|
7628
|
-
|
|
7873
|
+
if (Number.isNaN(x)) return NaN;
|
|
7874
|
+
if (!Number.isFinite(x)) return x > 0 ? 0 : 2;
|
|
7875
|
+
if (x < 0) return 2 - erfc(-x);
|
|
7876
|
+
if (x < 2) return 1 - erf(x);
|
|
7877
|
+
const tiny = 1e-300;
|
|
7878
|
+
let f = x === 0 ? tiny : x;
|
|
7879
|
+
let c = f;
|
|
7880
|
+
let d = 0;
|
|
7881
|
+
for (let k = 1; k <= 500; k++) {
|
|
7882
|
+
const a = k / 2;
|
|
7883
|
+
d = x + a * d;
|
|
7884
|
+
if (d === 0) d = tiny;
|
|
7885
|
+
d = 1 / d;
|
|
7886
|
+
c = x + a / c;
|
|
7887
|
+
if (c === 0) c = tiny;
|
|
7888
|
+
const delta = c * d;
|
|
7889
|
+
f *= delta;
|
|
7890
|
+
if (Math.abs(delta - 1) < 1e-17) break;
|
|
7891
|
+
}
|
|
7892
|
+
return Math.exp(-x * x) / (Math.sqrt(Math.PI) * f);
|
|
7629
7893
|
}
|
|
7630
7894
|
function erf(x) {
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
const a4 = -1.453152027;
|
|
7635
|
-
const a5 = 1.061405429;
|
|
7636
|
-
const p = 0.3275911;
|
|
7895
|
+
if (Number.isNaN(x)) return NaN;
|
|
7896
|
+
if (x === 0) return 0;
|
|
7897
|
+
if (!Number.isFinite(x)) return x > 0 ? 1 : -1;
|
|
7637
7898
|
const sign = x < 0 ? -1 : 1;
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
const
|
|
7641
|
-
|
|
7899
|
+
const ax = Math.abs(x);
|
|
7900
|
+
if (ax >= 6) return sign;
|
|
7901
|
+
const x2 = ax * ax;
|
|
7902
|
+
let term = ax;
|
|
7903
|
+
let sum = ax;
|
|
7904
|
+
for (let n = 1; n < 200; n++) {
|
|
7905
|
+
term *= 2 * x2 / (2 * n + 1);
|
|
7906
|
+
sum += term;
|
|
7907
|
+
if (term < sum * 1e-18) break;
|
|
7908
|
+
}
|
|
7909
|
+
return sign * (2 / Math.sqrt(Math.PI)) * Math.exp(-x2) * sum;
|
|
7642
7910
|
}
|
|
7643
7911
|
function bigGammaln(ce, z) {
|
|
7644
7912
|
if (!z.isFinite()) return BigDecimal.NAN;
|
|
@@ -8588,7 +8856,7 @@ var Numerics = (() => {
|
|
|
8588
8856
|
const t = x2 * x2;
|
|
8589
8857
|
return sign * x * x2 * polevl(t, SN) / polevl(t, SD);
|
|
8590
8858
|
}
|
|
8591
|
-
if (x <
|
|
8859
|
+
if (x < 36974) {
|
|
8592
8860
|
const x2 = x * x;
|
|
8593
8861
|
const t = Math.PI * x2;
|
|
8594
8862
|
const u = 1 / (t * t);
|
|
@@ -8613,7 +8881,7 @@ var Numerics = (() => {
|
|
|
8613
8881
|
const t = x2 * x2;
|
|
8614
8882
|
return sign * x * polevl(t, CN) / polevl(t, CD);
|
|
8615
8883
|
}
|
|
8616
|
-
if (x <
|
|
8884
|
+
if (x < 36974) {
|
|
8617
8885
|
const x2 = x * x;
|
|
8618
8886
|
const t = Math.PI * x2;
|
|
8619
8887
|
const u = 1 / (t * t);
|
|
@@ -8630,16 +8898,904 @@ var Numerics = (() => {
|
|
|
8630
8898
|
return x === 0 ? 1 : Math.sin(x) / x;
|
|
8631
8899
|
}
|
|
8632
8900
|
|
|
8901
|
+
// node_modules/complex-esm/dist/src/complex.js
|
|
8902
|
+
var cosh = Math.cosh || function(x) {
|
|
8903
|
+
return Math.abs(x) < 1e-9 ? 1 - x : (Math.exp(x) + Math.exp(-x)) * 0.5;
|
|
8904
|
+
};
|
|
8905
|
+
var sinh = Math.sinh || function(x) {
|
|
8906
|
+
return Math.abs(x) < 1e-9 ? x : (Math.exp(x) - Math.exp(-x)) * 0.5;
|
|
8907
|
+
};
|
|
8908
|
+
var cosm1 = function(x) {
|
|
8909
|
+
var b = Math.PI / 4;
|
|
8910
|
+
if (-b > x || x > b) {
|
|
8911
|
+
return Math.cos(x) - 1;
|
|
8912
|
+
}
|
|
8913
|
+
var xx = x * x;
|
|
8914
|
+
return xx * (xx * (xx * (xx * (xx * (xx * (xx * (xx / 20922789888e3 - 1 / 87178291200) + 1 / 479001600) - 1 / 3628800) + 1 / 40320) - 1 / 720) + 1 / 24) - 1 / 2);
|
|
8915
|
+
};
|
|
8916
|
+
var hypot = function(x, y) {
|
|
8917
|
+
var a = Math.abs(x);
|
|
8918
|
+
var b = Math.abs(y);
|
|
8919
|
+
if (a < 3e3 && b < 3e3) {
|
|
8920
|
+
return Math.sqrt(a * a + b * b);
|
|
8921
|
+
}
|
|
8922
|
+
if (a < b) {
|
|
8923
|
+
a = b;
|
|
8924
|
+
b = x / y;
|
|
8925
|
+
} else {
|
|
8926
|
+
b = y / x;
|
|
8927
|
+
}
|
|
8928
|
+
return a * Math.sqrt(1 + b * b);
|
|
8929
|
+
};
|
|
8930
|
+
var parser_exit = function() {
|
|
8931
|
+
throw SyntaxError("Invalid Param");
|
|
8932
|
+
};
|
|
8933
|
+
function logHypot(a, b) {
|
|
8934
|
+
var _a = Math.abs(a);
|
|
8935
|
+
var _b = Math.abs(b);
|
|
8936
|
+
if (a === 0) {
|
|
8937
|
+
return Math.log(_b);
|
|
8938
|
+
}
|
|
8939
|
+
if (b === 0) {
|
|
8940
|
+
return Math.log(_a);
|
|
8941
|
+
}
|
|
8942
|
+
if (_a < 3e3 && _b < 3e3) {
|
|
8943
|
+
return Math.log(a * a + b * b) * 0.5;
|
|
8944
|
+
}
|
|
8945
|
+
a = a / 2;
|
|
8946
|
+
b = b / 2;
|
|
8947
|
+
return 0.5 * Math.log(a * a + b * b) + Math.LN2;
|
|
8948
|
+
}
|
|
8949
|
+
var parse = function(a, b) {
|
|
8950
|
+
var z = { "re": 0, "im": 0 };
|
|
8951
|
+
if (a === void 0 || a === null) {
|
|
8952
|
+
z["re"] = z["im"] = 0;
|
|
8953
|
+
} else if (b !== void 0) {
|
|
8954
|
+
z["re"] = a;
|
|
8955
|
+
z["im"] = b;
|
|
8956
|
+
} else
|
|
8957
|
+
switch (typeof a) {
|
|
8958
|
+
case "object":
|
|
8959
|
+
if ("im" in a && "re" in a) {
|
|
8960
|
+
z["re"] = a["re"];
|
|
8961
|
+
z["im"] = a["im"];
|
|
8962
|
+
} else if ("abs" in a && "arg" in a) {
|
|
8963
|
+
if (!Number.isFinite(a["abs"]) && Number.isFinite(a["arg"])) {
|
|
8964
|
+
return Complex["INFINITY"];
|
|
8965
|
+
}
|
|
8966
|
+
z["re"] = a["abs"] * Math.cos(a["arg"]);
|
|
8967
|
+
z["im"] = a["abs"] * Math.sin(a["arg"]);
|
|
8968
|
+
} else if ("r" in a && "phi" in a) {
|
|
8969
|
+
if (!Number.isFinite(a["r"]) && Number.isFinite(a["phi"])) {
|
|
8970
|
+
return Complex["INFINITY"];
|
|
8971
|
+
}
|
|
8972
|
+
z["re"] = a["r"] * Math.cos(a["phi"]);
|
|
8973
|
+
z["im"] = a["r"] * Math.sin(a["phi"]);
|
|
8974
|
+
} else if (a.length === 2) {
|
|
8975
|
+
z["re"] = a[0];
|
|
8976
|
+
z["im"] = a[1];
|
|
8977
|
+
} else {
|
|
8978
|
+
parser_exit();
|
|
8979
|
+
}
|
|
8980
|
+
break;
|
|
8981
|
+
case "string":
|
|
8982
|
+
z["im"] = /* void */
|
|
8983
|
+
z["re"] = 0;
|
|
8984
|
+
var tokens = a.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);
|
|
8985
|
+
var plus = 1;
|
|
8986
|
+
var minus = 0;
|
|
8987
|
+
if (tokens === null) {
|
|
8988
|
+
parser_exit();
|
|
8989
|
+
}
|
|
8990
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
8991
|
+
var c = tokens[i];
|
|
8992
|
+
if (c === " " || c === " " || c === "\n") {
|
|
8993
|
+
} else if (c === "+") {
|
|
8994
|
+
plus++;
|
|
8995
|
+
} else if (c === "-") {
|
|
8996
|
+
minus++;
|
|
8997
|
+
} else if (c === "i" || c === "I") {
|
|
8998
|
+
if (plus + minus === 0) {
|
|
8999
|
+
parser_exit();
|
|
9000
|
+
}
|
|
9001
|
+
if (tokens[i + 1] !== " " && !isNaN(Number(tokens[i + 1]))) {
|
|
9002
|
+
z["im"] += parseFloat((minus % 2 ? "-" : "") + tokens[i + 1]);
|
|
9003
|
+
i++;
|
|
9004
|
+
} else {
|
|
9005
|
+
z["im"] += parseFloat((minus % 2 ? "-" : "") + "1");
|
|
9006
|
+
}
|
|
9007
|
+
plus = minus = 0;
|
|
9008
|
+
} else {
|
|
9009
|
+
if (plus + minus === 0 || isNaN(Number(c))) {
|
|
9010
|
+
parser_exit();
|
|
9011
|
+
}
|
|
9012
|
+
if (tokens[i + 1] === "i" || tokens[i + 1] === "I") {
|
|
9013
|
+
z["im"] += parseFloat((minus % 2 ? "-" : "") + c);
|
|
9014
|
+
i++;
|
|
9015
|
+
} else {
|
|
9016
|
+
z["re"] += parseFloat((minus % 2 ? "-" : "") + c);
|
|
9017
|
+
}
|
|
9018
|
+
plus = minus = 0;
|
|
9019
|
+
}
|
|
9020
|
+
}
|
|
9021
|
+
if (plus + minus > 0) {
|
|
9022
|
+
parser_exit();
|
|
9023
|
+
}
|
|
9024
|
+
break;
|
|
9025
|
+
case "number":
|
|
9026
|
+
z["im"] = 0;
|
|
9027
|
+
z["re"] = a;
|
|
9028
|
+
break;
|
|
9029
|
+
default:
|
|
9030
|
+
parser_exit();
|
|
9031
|
+
}
|
|
9032
|
+
if (isNaN(z["re"]) || isNaN(z["im"])) {
|
|
9033
|
+
}
|
|
9034
|
+
return z;
|
|
9035
|
+
};
|
|
9036
|
+
var Complex = class _Complex {
|
|
9037
|
+
constructor(a, b) {
|
|
9038
|
+
this.re = 0;
|
|
9039
|
+
this.im = 0;
|
|
9040
|
+
var z = parse(a, b);
|
|
9041
|
+
this["re"] = z["re"];
|
|
9042
|
+
this["im"] = z["im"];
|
|
9043
|
+
}
|
|
9044
|
+
/**
|
|
9045
|
+
* Calculates the sign of a complex number, which is a normalized complex
|
|
9046
|
+
*
|
|
9047
|
+
* @returns {Complex}
|
|
9048
|
+
*/
|
|
9049
|
+
sign() {
|
|
9050
|
+
var abs = this["abs"]();
|
|
9051
|
+
return new _Complex(this["re"] / abs, this["im"] / abs);
|
|
9052
|
+
}
|
|
9053
|
+
/**
|
|
9054
|
+
* Adds two complex numbers
|
|
9055
|
+
*
|
|
9056
|
+
* @returns {Complex}
|
|
9057
|
+
*/
|
|
9058
|
+
add(a, b) {
|
|
9059
|
+
var z = new _Complex(a, b);
|
|
9060
|
+
if (this["isInfinite"]() && z["isInfinite"]()) {
|
|
9061
|
+
return _Complex["NAN"];
|
|
9062
|
+
}
|
|
9063
|
+
if (this["isInfinite"]() || z["isInfinite"]()) {
|
|
9064
|
+
return _Complex["INFINITY"];
|
|
9065
|
+
}
|
|
9066
|
+
return new _Complex(this["re"] + z["re"], this["im"] + z["im"]);
|
|
9067
|
+
}
|
|
9068
|
+
/**
|
|
9069
|
+
* Subtracts two complex numbers
|
|
9070
|
+
*
|
|
9071
|
+
* @returns {Complex}
|
|
9072
|
+
*/
|
|
9073
|
+
sub(a, b) {
|
|
9074
|
+
var z = new _Complex(a, b);
|
|
9075
|
+
if (this["isInfinite"]() && z["isInfinite"]()) {
|
|
9076
|
+
return _Complex["NAN"];
|
|
9077
|
+
}
|
|
9078
|
+
if (this["isInfinite"]() || z["isInfinite"]()) {
|
|
9079
|
+
return _Complex["INFINITY"];
|
|
9080
|
+
}
|
|
9081
|
+
return new _Complex(this["re"] - z["re"], this["im"] - z["im"]);
|
|
9082
|
+
}
|
|
9083
|
+
/**
|
|
9084
|
+
* Multiplies two complex numbers
|
|
9085
|
+
*
|
|
9086
|
+
* @returns {Complex}
|
|
9087
|
+
*/
|
|
9088
|
+
mul(a, b) {
|
|
9089
|
+
var z = new _Complex(a, b);
|
|
9090
|
+
if (this["isInfinite"]() && z["isZero"]() || this["isZero"]() && z["isInfinite"]()) {
|
|
9091
|
+
return _Complex["NAN"];
|
|
9092
|
+
}
|
|
9093
|
+
if (this["isInfinite"]() || z["isInfinite"]()) {
|
|
9094
|
+
return _Complex["INFINITY"];
|
|
9095
|
+
}
|
|
9096
|
+
if (z["im"] === 0 && this["im"] === 0) {
|
|
9097
|
+
return new _Complex(this["re"] * z["re"], 0);
|
|
9098
|
+
}
|
|
9099
|
+
return new _Complex(this["re"] * z["re"] - this["im"] * z["im"], this["re"] * z["im"] + this["im"] * z["re"]);
|
|
9100
|
+
}
|
|
9101
|
+
/**
|
|
9102
|
+
* Divides two complex numbers
|
|
9103
|
+
*
|
|
9104
|
+
* @returns {Complex}
|
|
9105
|
+
*/
|
|
9106
|
+
div(a, b) {
|
|
9107
|
+
var z = new _Complex(a, b);
|
|
9108
|
+
if (this["isZero"]() && z["isZero"]() || this["isInfinite"]() && z["isInfinite"]()) {
|
|
9109
|
+
return _Complex["NAN"];
|
|
9110
|
+
}
|
|
9111
|
+
if (this["isInfinite"]() || z["isZero"]()) {
|
|
9112
|
+
return _Complex["INFINITY"];
|
|
9113
|
+
}
|
|
9114
|
+
if (this["isZero"]() || z["isInfinite"]()) {
|
|
9115
|
+
return _Complex["ZERO"];
|
|
9116
|
+
}
|
|
9117
|
+
a = this["re"];
|
|
9118
|
+
b = this["im"];
|
|
9119
|
+
var c = z["re"];
|
|
9120
|
+
var d = z["im"];
|
|
9121
|
+
var t, x;
|
|
9122
|
+
if (0 === d) {
|
|
9123
|
+
return new _Complex(a / c, b / c);
|
|
9124
|
+
}
|
|
9125
|
+
if (Math.abs(c) < Math.abs(d)) {
|
|
9126
|
+
x = c / d;
|
|
9127
|
+
t = c * x + d;
|
|
9128
|
+
return new _Complex((a * x + b) / t, (b * x - a) / t);
|
|
9129
|
+
} else {
|
|
9130
|
+
x = d / c;
|
|
9131
|
+
t = d * x + c;
|
|
9132
|
+
return new _Complex((a + b * x) / t, (b - a * x) / t);
|
|
9133
|
+
}
|
|
9134
|
+
}
|
|
9135
|
+
/**
|
|
9136
|
+
* Calculate the power of two complex numbers
|
|
9137
|
+
*
|
|
9138
|
+
* @returns {Complex}
|
|
9139
|
+
*/
|
|
9140
|
+
pow(a, b) {
|
|
9141
|
+
var z = new _Complex(a, b);
|
|
9142
|
+
a = this["re"];
|
|
9143
|
+
b = this["im"];
|
|
9144
|
+
if (z["isZero"]()) {
|
|
9145
|
+
return _Complex["ONE"];
|
|
9146
|
+
}
|
|
9147
|
+
if (z["im"] === 0) {
|
|
9148
|
+
if (b === 0 && a > 0) {
|
|
9149
|
+
return new _Complex(Math.pow(a, z["re"]), 0);
|
|
9150
|
+
} else if (a === 0) {
|
|
9151
|
+
switch ((z["re"] % 4 + 4) % 4) {
|
|
9152
|
+
case 0:
|
|
9153
|
+
return new _Complex(Math.pow(b, z["re"]), 0);
|
|
9154
|
+
case 1:
|
|
9155
|
+
return new _Complex(0, Math.pow(b, z["re"]));
|
|
9156
|
+
case 2:
|
|
9157
|
+
return new _Complex(-Math.pow(b, z["re"]), 0);
|
|
9158
|
+
case 3:
|
|
9159
|
+
return new _Complex(0, -Math.pow(b, z["re"]));
|
|
9160
|
+
}
|
|
9161
|
+
}
|
|
9162
|
+
}
|
|
9163
|
+
if (a === 0 && b === 0 && z["re"] > 0 && z["im"] >= 0) {
|
|
9164
|
+
return _Complex["ZERO"];
|
|
9165
|
+
}
|
|
9166
|
+
var arg = Math.atan2(b, a);
|
|
9167
|
+
var loh = logHypot(a, b);
|
|
9168
|
+
a = Math.exp(z["re"] * loh - z["im"] * arg);
|
|
9169
|
+
b = z["im"] * loh + z["re"] * arg;
|
|
9170
|
+
return new _Complex(a * Math.cos(b), a * Math.sin(b));
|
|
9171
|
+
}
|
|
9172
|
+
/**
|
|
9173
|
+
* Calculate the complex square root
|
|
9174
|
+
*
|
|
9175
|
+
* @returns {Complex}
|
|
9176
|
+
*/
|
|
9177
|
+
sqrt() {
|
|
9178
|
+
var a = this["re"];
|
|
9179
|
+
var b = this["im"];
|
|
9180
|
+
var r = this["abs"]();
|
|
9181
|
+
var re, im;
|
|
9182
|
+
if (a >= 0) {
|
|
9183
|
+
if (b === 0) {
|
|
9184
|
+
return new _Complex(Math.sqrt(a), 0);
|
|
9185
|
+
}
|
|
9186
|
+
re = 0.5 * Math.sqrt(2 * (r + a));
|
|
9187
|
+
} else {
|
|
9188
|
+
re = Math.abs(b) / Math.sqrt(2 * (r - a));
|
|
9189
|
+
}
|
|
9190
|
+
if (a <= 0) {
|
|
9191
|
+
im = 0.5 * Math.sqrt(2 * (r - a));
|
|
9192
|
+
} else {
|
|
9193
|
+
im = Math.abs(b) / Math.sqrt(2 * (r + a));
|
|
9194
|
+
}
|
|
9195
|
+
return new _Complex(re, b < 0 ? -im : im);
|
|
9196
|
+
}
|
|
9197
|
+
/**
|
|
9198
|
+
* Calculate the complex exponent
|
|
9199
|
+
*
|
|
9200
|
+
* @returns {Complex}
|
|
9201
|
+
*/
|
|
9202
|
+
exp() {
|
|
9203
|
+
var tmp = Math.exp(this["re"]);
|
|
9204
|
+
if (this["im"] === 0) {
|
|
9205
|
+
}
|
|
9206
|
+
return new _Complex(tmp * Math.cos(this["im"]), tmp * Math.sin(this["im"]));
|
|
9207
|
+
}
|
|
9208
|
+
/**
|
|
9209
|
+
* Calculate the complex exponent and subtracts one.
|
|
9210
|
+
*
|
|
9211
|
+
* This may be more accurate than `Complex(x).exp().sub(1)` if
|
|
9212
|
+
* `x` is small.
|
|
9213
|
+
*
|
|
9214
|
+
* @returns {Complex}
|
|
9215
|
+
*/
|
|
9216
|
+
expm1() {
|
|
9217
|
+
var a = this["re"];
|
|
9218
|
+
var b = this["im"];
|
|
9219
|
+
return new _Complex(Math.expm1(a) * Math.cos(b) + cosm1(b), Math.exp(a) * Math.sin(b));
|
|
9220
|
+
}
|
|
9221
|
+
/**
|
|
9222
|
+
* Calculate the natural log
|
|
9223
|
+
*
|
|
9224
|
+
* @returns {Complex}
|
|
9225
|
+
*/
|
|
9226
|
+
log() {
|
|
9227
|
+
var a = this["re"];
|
|
9228
|
+
var b = this["im"];
|
|
9229
|
+
if (b === 0 && a > 0) {
|
|
9230
|
+
}
|
|
9231
|
+
return new _Complex(logHypot(a, b), Math.atan2(b, a));
|
|
9232
|
+
}
|
|
9233
|
+
/**
|
|
9234
|
+
* Calculate the magnitude of the complex number
|
|
9235
|
+
*
|
|
9236
|
+
* @returns {number}
|
|
9237
|
+
*/
|
|
9238
|
+
abs() {
|
|
9239
|
+
return hypot(this["re"], this["im"]);
|
|
9240
|
+
}
|
|
9241
|
+
/**
|
|
9242
|
+
* Calculate the angle of the complex number
|
|
9243
|
+
*
|
|
9244
|
+
* @returns {number}
|
|
9245
|
+
*/
|
|
9246
|
+
arg() {
|
|
9247
|
+
return Math.atan2(this["im"], this["re"]);
|
|
9248
|
+
}
|
|
9249
|
+
/**
|
|
9250
|
+
* Calculate the sine of the complex number
|
|
9251
|
+
*
|
|
9252
|
+
* @returns {Complex}
|
|
9253
|
+
*/
|
|
9254
|
+
sin() {
|
|
9255
|
+
var a = this["re"];
|
|
9256
|
+
var b = this["im"];
|
|
9257
|
+
return new _Complex(Math.sin(a) * cosh(b), Math.cos(a) * sinh(b));
|
|
9258
|
+
}
|
|
9259
|
+
/**
|
|
9260
|
+
* Calculate the cosine
|
|
9261
|
+
*
|
|
9262
|
+
* @returns {Complex}
|
|
9263
|
+
*/
|
|
9264
|
+
cos() {
|
|
9265
|
+
var a = this["re"];
|
|
9266
|
+
var b = this["im"];
|
|
9267
|
+
return new _Complex(Math.cos(a) * cosh(b), -Math.sin(a) * sinh(b));
|
|
9268
|
+
}
|
|
9269
|
+
/**
|
|
9270
|
+
* Calculate the tangent
|
|
9271
|
+
*
|
|
9272
|
+
* @returns {Complex}
|
|
9273
|
+
*/
|
|
9274
|
+
tan() {
|
|
9275
|
+
var a = 2 * this["re"];
|
|
9276
|
+
var b = 2 * this["im"];
|
|
9277
|
+
var d = Math.cos(a) + cosh(b);
|
|
9278
|
+
return new _Complex(Math.sin(a) / d, sinh(b) / d);
|
|
9279
|
+
}
|
|
9280
|
+
/**
|
|
9281
|
+
* Calculate the cotangent
|
|
9282
|
+
*
|
|
9283
|
+
* @returns {Complex}
|
|
9284
|
+
*/
|
|
9285
|
+
cot() {
|
|
9286
|
+
var a = 2 * this["re"];
|
|
9287
|
+
var b = 2 * this["im"];
|
|
9288
|
+
var d = Math.cos(a) - cosh(b);
|
|
9289
|
+
return new _Complex(-Math.sin(a) / d, sinh(b) / d);
|
|
9290
|
+
}
|
|
9291
|
+
/**
|
|
9292
|
+
* Calculate the secant
|
|
9293
|
+
*
|
|
9294
|
+
* @returns {Complex}
|
|
9295
|
+
*/
|
|
9296
|
+
sec() {
|
|
9297
|
+
var a = this["re"];
|
|
9298
|
+
var b = this["im"];
|
|
9299
|
+
var d = 0.5 * cosh(2 * b) + 0.5 * Math.cos(2 * a);
|
|
9300
|
+
return new _Complex(Math.cos(a) * cosh(b) / d, Math.sin(a) * sinh(b) / d);
|
|
9301
|
+
}
|
|
9302
|
+
/**
|
|
9303
|
+
* Calculate the cosecans
|
|
9304
|
+
*
|
|
9305
|
+
* @returns {Complex}
|
|
9306
|
+
*/
|
|
9307
|
+
csc() {
|
|
9308
|
+
var a = this["re"];
|
|
9309
|
+
var b = this["im"];
|
|
9310
|
+
var d = 0.5 * cosh(2 * b) - 0.5 * Math.cos(2 * a);
|
|
9311
|
+
return new _Complex(Math.sin(a) * cosh(b) / d, -Math.cos(a) * sinh(b) / d);
|
|
9312
|
+
}
|
|
9313
|
+
/**
|
|
9314
|
+
* Calculate the complex arcus sinus
|
|
9315
|
+
*
|
|
9316
|
+
* @returns {Complex}
|
|
9317
|
+
*/
|
|
9318
|
+
asin() {
|
|
9319
|
+
var a = this["re"];
|
|
9320
|
+
var b = this["im"];
|
|
9321
|
+
var t1 = new _Complex(b * b - a * a + 1, -2 * a * b)["sqrt"]();
|
|
9322
|
+
var t2 = new _Complex(t1["re"] - b, t1["im"] + a)["log"]();
|
|
9323
|
+
return new _Complex(t2["im"], -t2["re"]);
|
|
9324
|
+
}
|
|
9325
|
+
/**
|
|
9326
|
+
* Calculate the complex arcus cosinus
|
|
9327
|
+
*
|
|
9328
|
+
* @returns {Complex}
|
|
9329
|
+
*/
|
|
9330
|
+
acos() {
|
|
9331
|
+
var a = this["re"];
|
|
9332
|
+
var b = this["im"];
|
|
9333
|
+
var t1 = new _Complex(b * b - a * a + 1, -2 * a * b)["sqrt"]();
|
|
9334
|
+
var t2 = new _Complex(t1["re"] - b, t1["im"] + a)["log"]();
|
|
9335
|
+
return new _Complex(Math.PI / 2 - t2["im"], t2["re"]);
|
|
9336
|
+
}
|
|
9337
|
+
/**
|
|
9338
|
+
* Calculate the complex arcus tangent
|
|
9339
|
+
*
|
|
9340
|
+
* @returns {Complex}
|
|
9341
|
+
*/
|
|
9342
|
+
atan() {
|
|
9343
|
+
var a = this["re"];
|
|
9344
|
+
var b = this["im"];
|
|
9345
|
+
if (a === 0) {
|
|
9346
|
+
if (b === 1) {
|
|
9347
|
+
return new _Complex(0, Infinity);
|
|
9348
|
+
}
|
|
9349
|
+
if (b === -1) {
|
|
9350
|
+
return new _Complex(0, -Infinity);
|
|
9351
|
+
}
|
|
9352
|
+
}
|
|
9353
|
+
var d = a * a + (1 - b) * (1 - b);
|
|
9354
|
+
var t1 = new _Complex((1 - b * b - a * a) / d, -2 * a / d).log();
|
|
9355
|
+
return new _Complex(-0.5 * t1["im"], 0.5 * t1["re"]);
|
|
9356
|
+
}
|
|
9357
|
+
/**
|
|
9358
|
+
* Calculate the complex arcus cotangent
|
|
9359
|
+
*
|
|
9360
|
+
* @returns {Complex}
|
|
9361
|
+
*/
|
|
9362
|
+
acot() {
|
|
9363
|
+
var a = this["re"];
|
|
9364
|
+
var b = this["im"];
|
|
9365
|
+
if (b === 0) {
|
|
9366
|
+
return new _Complex(Math.atan2(1, a), 0);
|
|
9367
|
+
}
|
|
9368
|
+
var d = a * a + b * b;
|
|
9369
|
+
return d !== 0 ? new _Complex(a / d, -b / d).atan() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).atan();
|
|
9370
|
+
}
|
|
9371
|
+
/**
|
|
9372
|
+
* Calculate the complex arcus secant
|
|
9373
|
+
*
|
|
9374
|
+
* @returns {Complex}
|
|
9375
|
+
*/
|
|
9376
|
+
asec() {
|
|
9377
|
+
var a = this["re"];
|
|
9378
|
+
var b = this["im"];
|
|
9379
|
+
if (a === 0 && b === 0) {
|
|
9380
|
+
return new _Complex(0, Infinity);
|
|
9381
|
+
}
|
|
9382
|
+
var d = a * a + b * b;
|
|
9383
|
+
return d !== 0 ? new _Complex(a / d, -b / d).acos() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).acos();
|
|
9384
|
+
}
|
|
9385
|
+
/**
|
|
9386
|
+
* Calculate the complex arcus cosecans
|
|
9387
|
+
*
|
|
9388
|
+
* @returns {Complex}
|
|
9389
|
+
*/
|
|
9390
|
+
acsc() {
|
|
9391
|
+
var a = this["re"];
|
|
9392
|
+
var b = this["im"];
|
|
9393
|
+
if (a === 0 && b === 0) {
|
|
9394
|
+
return new _Complex(Math.PI / 2, Infinity);
|
|
9395
|
+
}
|
|
9396
|
+
var d = a * a + b * b;
|
|
9397
|
+
return d !== 0 ? new _Complex(a / d, -b / d).asin() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).asin();
|
|
9398
|
+
}
|
|
9399
|
+
/**
|
|
9400
|
+
* Calculate the complex sinh
|
|
9401
|
+
*
|
|
9402
|
+
* @returns {Complex}
|
|
9403
|
+
*/
|
|
9404
|
+
sinh() {
|
|
9405
|
+
var a = this["re"];
|
|
9406
|
+
var b = this["im"];
|
|
9407
|
+
return new _Complex(sinh(a) * Math.cos(b), cosh(a) * Math.sin(b));
|
|
9408
|
+
}
|
|
9409
|
+
/**
|
|
9410
|
+
* Calculate the complex cosh
|
|
9411
|
+
*
|
|
9412
|
+
* @returns {Complex}
|
|
9413
|
+
*/
|
|
9414
|
+
cosh() {
|
|
9415
|
+
var a = this["re"];
|
|
9416
|
+
var b = this["im"];
|
|
9417
|
+
return new _Complex(cosh(a) * Math.cos(b), sinh(a) * Math.sin(b));
|
|
9418
|
+
}
|
|
9419
|
+
/**
|
|
9420
|
+
* Calculate the complex tanh
|
|
9421
|
+
*
|
|
9422
|
+
* @returns {Complex}
|
|
9423
|
+
*/
|
|
9424
|
+
tanh() {
|
|
9425
|
+
var a = 2 * this["re"];
|
|
9426
|
+
var b = 2 * this["im"];
|
|
9427
|
+
var d = cosh(a) + Math.cos(b);
|
|
9428
|
+
return new _Complex(sinh(a) / d, Math.sin(b) / d);
|
|
9429
|
+
}
|
|
9430
|
+
/**
|
|
9431
|
+
* Calculate the complex coth
|
|
9432
|
+
*
|
|
9433
|
+
* @returns {Complex}
|
|
9434
|
+
*/
|
|
9435
|
+
coth() {
|
|
9436
|
+
var a = 2 * this["re"];
|
|
9437
|
+
var b = 2 * this["im"];
|
|
9438
|
+
var d = cosh(a) - Math.cos(b);
|
|
9439
|
+
return new _Complex(sinh(a) / d, -Math.sin(b) / d);
|
|
9440
|
+
}
|
|
9441
|
+
/**
|
|
9442
|
+
* Calculate the complex coth
|
|
9443
|
+
*
|
|
9444
|
+
* @returns {Complex}
|
|
9445
|
+
*/
|
|
9446
|
+
csch() {
|
|
9447
|
+
var a = this["re"];
|
|
9448
|
+
var b = this["im"];
|
|
9449
|
+
var d = Math.cos(2 * b) - cosh(2 * a);
|
|
9450
|
+
return new _Complex(-2 * sinh(a) * Math.cos(b) / d, 2 * cosh(a) * Math.sin(b) / d);
|
|
9451
|
+
}
|
|
9452
|
+
/**
|
|
9453
|
+
* Calculate the complex sech
|
|
9454
|
+
*
|
|
9455
|
+
* @returns {Complex}
|
|
9456
|
+
*/
|
|
9457
|
+
sech() {
|
|
9458
|
+
var a = this["re"];
|
|
9459
|
+
var b = this["im"];
|
|
9460
|
+
var d = Math.cos(2 * b) + cosh(2 * a);
|
|
9461
|
+
return new _Complex(2 * cosh(a) * Math.cos(b) / d, -2 * sinh(a) * Math.sin(b) / d);
|
|
9462
|
+
}
|
|
9463
|
+
/**
|
|
9464
|
+
* Calculate the complex asinh
|
|
9465
|
+
*
|
|
9466
|
+
* @returns {Complex}
|
|
9467
|
+
*/
|
|
9468
|
+
asinh() {
|
|
9469
|
+
var tmp = this["im"];
|
|
9470
|
+
this["im"] = -this["re"];
|
|
9471
|
+
this["re"] = tmp;
|
|
9472
|
+
var res = this["asin"]();
|
|
9473
|
+
this["re"] = -this["im"];
|
|
9474
|
+
this["im"] = tmp;
|
|
9475
|
+
tmp = res["re"];
|
|
9476
|
+
res["re"] = -res["im"];
|
|
9477
|
+
res["im"] = tmp;
|
|
9478
|
+
return res;
|
|
9479
|
+
}
|
|
9480
|
+
/**
|
|
9481
|
+
* Calculate the complex acosh
|
|
9482
|
+
*
|
|
9483
|
+
* @returns {Complex}
|
|
9484
|
+
*/
|
|
9485
|
+
acosh() {
|
|
9486
|
+
var res = this["acos"]();
|
|
9487
|
+
if (res["im"] <= 0) {
|
|
9488
|
+
var tmp = res["re"];
|
|
9489
|
+
res["re"] = -res["im"];
|
|
9490
|
+
res["im"] = tmp;
|
|
9491
|
+
} else {
|
|
9492
|
+
var tmp = res["im"];
|
|
9493
|
+
res["im"] = -res["re"];
|
|
9494
|
+
res["re"] = tmp;
|
|
9495
|
+
}
|
|
9496
|
+
return res;
|
|
9497
|
+
}
|
|
9498
|
+
/**
|
|
9499
|
+
* Calculate the complex atanh
|
|
9500
|
+
*
|
|
9501
|
+
* @returns {Complex}
|
|
9502
|
+
*/
|
|
9503
|
+
atanh() {
|
|
9504
|
+
var a = this["re"];
|
|
9505
|
+
var b = this["im"];
|
|
9506
|
+
var noIM = a > 1 && b === 0;
|
|
9507
|
+
var oneMinus = 1 - a;
|
|
9508
|
+
var onePlus = 1 + a;
|
|
9509
|
+
var d = oneMinus * oneMinus + b * b;
|
|
9510
|
+
var x = d !== 0 ? new _Complex((onePlus * oneMinus - b * b) / d, (b * oneMinus + onePlus * b) / d) : new _Complex(a !== -1 ? a / 0 : 0, b !== 0 ? b / 0 : 0);
|
|
9511
|
+
var temp = x["re"];
|
|
9512
|
+
x["re"] = logHypot(x["re"], x["im"]) / 2;
|
|
9513
|
+
x["im"] = Math.atan2(x["im"], temp) / 2;
|
|
9514
|
+
if (noIM) {
|
|
9515
|
+
x["im"] = -x["im"];
|
|
9516
|
+
}
|
|
9517
|
+
return x;
|
|
9518
|
+
}
|
|
9519
|
+
/**
|
|
9520
|
+
* Calculate the complex acoth
|
|
9521
|
+
*
|
|
9522
|
+
* @returns {Complex}
|
|
9523
|
+
*/
|
|
9524
|
+
acoth() {
|
|
9525
|
+
var a = this["re"];
|
|
9526
|
+
var b = this["im"];
|
|
9527
|
+
if (a === 0 && b === 0) {
|
|
9528
|
+
return new _Complex(0, Math.PI / 2);
|
|
9529
|
+
}
|
|
9530
|
+
var d = a * a + b * b;
|
|
9531
|
+
return d !== 0 ? new _Complex(a / d, -b / d).atanh() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).atanh();
|
|
9532
|
+
}
|
|
9533
|
+
/**
|
|
9534
|
+
* Calculate the complex acsch
|
|
9535
|
+
*
|
|
9536
|
+
* @returns {Complex}
|
|
9537
|
+
*/
|
|
9538
|
+
acsch() {
|
|
9539
|
+
var a = this["re"];
|
|
9540
|
+
var b = this["im"];
|
|
9541
|
+
if (b === 0) {
|
|
9542
|
+
return new _Complex(a !== 0 ? Math.log(a + Math.sqrt(a * a + 1)) : Infinity, 0);
|
|
9543
|
+
}
|
|
9544
|
+
var d = a * a + b * b;
|
|
9545
|
+
return d !== 0 ? new _Complex(a / d, -b / d).asinh() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).asinh();
|
|
9546
|
+
}
|
|
9547
|
+
/**
|
|
9548
|
+
* Calculate the complex asech
|
|
9549
|
+
*
|
|
9550
|
+
* @returns {Complex}
|
|
9551
|
+
*/
|
|
9552
|
+
asech() {
|
|
9553
|
+
var a = this["re"];
|
|
9554
|
+
var b = this["im"];
|
|
9555
|
+
if (this["isZero"]()) {
|
|
9556
|
+
return _Complex["INFINITY"];
|
|
9557
|
+
}
|
|
9558
|
+
var d = a * a + b * b;
|
|
9559
|
+
return d !== 0 ? new _Complex(a / d, -b / d).acosh() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).acosh();
|
|
9560
|
+
}
|
|
9561
|
+
/**
|
|
9562
|
+
* Calculate the complex inverse 1/z
|
|
9563
|
+
*
|
|
9564
|
+
* @returns {Complex}
|
|
9565
|
+
*/
|
|
9566
|
+
inverse() {
|
|
9567
|
+
if (this["isZero"]()) {
|
|
9568
|
+
return _Complex["INFINITY"];
|
|
9569
|
+
}
|
|
9570
|
+
if (this["isInfinite"]()) {
|
|
9571
|
+
return _Complex["ZERO"];
|
|
9572
|
+
}
|
|
9573
|
+
var a = this["re"];
|
|
9574
|
+
var b = this["im"];
|
|
9575
|
+
var d = a * a + b * b;
|
|
9576
|
+
return new _Complex(a / d, -b / d);
|
|
9577
|
+
}
|
|
9578
|
+
/**
|
|
9579
|
+
* Returns the complex conjugate
|
|
9580
|
+
*
|
|
9581
|
+
* @returns {Complex}
|
|
9582
|
+
*/
|
|
9583
|
+
conjugate() {
|
|
9584
|
+
return new _Complex(this["re"], -this["im"]);
|
|
9585
|
+
}
|
|
9586
|
+
/**
|
|
9587
|
+
* Gets the negated complex number
|
|
9588
|
+
*
|
|
9589
|
+
* @returns {Complex}
|
|
9590
|
+
*/
|
|
9591
|
+
neg() {
|
|
9592
|
+
return new _Complex(-this["re"], -this["im"]);
|
|
9593
|
+
}
|
|
9594
|
+
/**
|
|
9595
|
+
* Ceils the actual complex number
|
|
9596
|
+
*
|
|
9597
|
+
* @returns {Complex}
|
|
9598
|
+
*/
|
|
9599
|
+
ceil(places) {
|
|
9600
|
+
places = Math.pow(10, places || 0);
|
|
9601
|
+
return new _Complex(Math.ceil(this["re"] * places) / places, Math.ceil(this["im"] * places) / places);
|
|
9602
|
+
}
|
|
9603
|
+
/**
|
|
9604
|
+
* Floors the actual complex number
|
|
9605
|
+
*
|
|
9606
|
+
* @returns {Complex}
|
|
9607
|
+
*/
|
|
9608
|
+
floor(places) {
|
|
9609
|
+
places = Math.pow(10, places || 0);
|
|
9610
|
+
return new _Complex(Math.floor(this["re"] * places) / places, Math.floor(this["im"] * places) / places);
|
|
9611
|
+
}
|
|
9612
|
+
/**
|
|
9613
|
+
* Ceils the actual complex number
|
|
9614
|
+
*
|
|
9615
|
+
* @returns {Complex}
|
|
9616
|
+
*/
|
|
9617
|
+
round(places) {
|
|
9618
|
+
places = Math.pow(10, places || 0);
|
|
9619
|
+
return new _Complex(Math.round(this["re"] * places) / places, Math.round(this["im"] * places) / places);
|
|
9620
|
+
}
|
|
9621
|
+
/**
|
|
9622
|
+
* Compares two complex numbers
|
|
9623
|
+
*
|
|
9624
|
+
* **Note:** new Complex(Infinity).equals(Infinity) === false
|
|
9625
|
+
*
|
|
9626
|
+
* @returns {boolean}
|
|
9627
|
+
*/
|
|
9628
|
+
equals(a, b) {
|
|
9629
|
+
var z = new _Complex(a, b);
|
|
9630
|
+
return Math.abs(z["re"] - this["re"]) <= _Complex["EPSILON"] && Math.abs(z["im"] - this["im"]) <= _Complex["EPSILON"];
|
|
9631
|
+
}
|
|
9632
|
+
/**
|
|
9633
|
+
* Clones the actual object
|
|
9634
|
+
*
|
|
9635
|
+
* @returns {Complex}
|
|
9636
|
+
*/
|
|
9637
|
+
clone() {
|
|
9638
|
+
return new _Complex(this["re"], this["im"]);
|
|
9639
|
+
}
|
|
9640
|
+
/**
|
|
9641
|
+
* Gets a string of the actual complex number
|
|
9642
|
+
*
|
|
9643
|
+
* @returns {string}
|
|
9644
|
+
*/
|
|
9645
|
+
toString() {
|
|
9646
|
+
var a = this["re"];
|
|
9647
|
+
var b = this["im"];
|
|
9648
|
+
var ret = "";
|
|
9649
|
+
if (this["isNaN"]()) {
|
|
9650
|
+
return "NaN";
|
|
9651
|
+
}
|
|
9652
|
+
if (this["isInfinite"]()) {
|
|
9653
|
+
return "Infinity";
|
|
9654
|
+
}
|
|
9655
|
+
if (Math.abs(a) < _Complex["EPSILON"]) {
|
|
9656
|
+
a = 0;
|
|
9657
|
+
}
|
|
9658
|
+
if (Math.abs(b) < _Complex["EPSILON"]) {
|
|
9659
|
+
b = 0;
|
|
9660
|
+
}
|
|
9661
|
+
if (b === 0) {
|
|
9662
|
+
return ret + a;
|
|
9663
|
+
}
|
|
9664
|
+
if (a !== 0) {
|
|
9665
|
+
ret += a;
|
|
9666
|
+
ret += " ";
|
|
9667
|
+
if (b < 0) {
|
|
9668
|
+
b = -b;
|
|
9669
|
+
ret += "-";
|
|
9670
|
+
} else {
|
|
9671
|
+
ret += "+";
|
|
9672
|
+
}
|
|
9673
|
+
ret += " ";
|
|
9674
|
+
} else if (b < 0) {
|
|
9675
|
+
b = -b;
|
|
9676
|
+
ret += "-";
|
|
9677
|
+
}
|
|
9678
|
+
if (1 !== b) {
|
|
9679
|
+
ret += b;
|
|
9680
|
+
}
|
|
9681
|
+
return ret + "i";
|
|
9682
|
+
}
|
|
9683
|
+
/**
|
|
9684
|
+
* Returns the actual number as a vector
|
|
9685
|
+
*
|
|
9686
|
+
* @returns {Array}
|
|
9687
|
+
*/
|
|
9688
|
+
toVector() {
|
|
9689
|
+
return [this["re"], this["im"]];
|
|
9690
|
+
}
|
|
9691
|
+
/**
|
|
9692
|
+
* Returns the actual real value of the current object
|
|
9693
|
+
*
|
|
9694
|
+
* @returns {number|null}
|
|
9695
|
+
*/
|
|
9696
|
+
valueOf() {
|
|
9697
|
+
if (this["im"] === 0) {
|
|
9698
|
+
return this["re"];
|
|
9699
|
+
}
|
|
9700
|
+
return null;
|
|
9701
|
+
}
|
|
9702
|
+
/**
|
|
9703
|
+
* Determines whether a complex number is not on the Riemann sphere.
|
|
9704
|
+
*
|
|
9705
|
+
* @returns {boolean}
|
|
9706
|
+
*/
|
|
9707
|
+
isNaN() {
|
|
9708
|
+
return isNaN(this["re"]) || isNaN(this["im"]);
|
|
9709
|
+
}
|
|
9710
|
+
/**
|
|
9711
|
+
* Determines whether or not a complex number is at the zero pole of the
|
|
9712
|
+
* Riemann sphere.
|
|
9713
|
+
*
|
|
9714
|
+
* @returns {boolean}
|
|
9715
|
+
*/
|
|
9716
|
+
isZero() {
|
|
9717
|
+
return this["im"] === 0 && this["re"] === 0;
|
|
9718
|
+
}
|
|
9719
|
+
/**
|
|
9720
|
+
* Determines whether a complex number is not at the infinity pole of the
|
|
9721
|
+
* Riemann sphere.
|
|
9722
|
+
*
|
|
9723
|
+
* @returns {boolean}
|
|
9724
|
+
*/
|
|
9725
|
+
isFinite() {
|
|
9726
|
+
return isFinite(this["re"]) && isFinite(this["im"]);
|
|
9727
|
+
}
|
|
9728
|
+
/**
|
|
9729
|
+
* Determines whether or not a complex number is at the infinity pole of the
|
|
9730
|
+
* Riemann sphere.
|
|
9731
|
+
*
|
|
9732
|
+
* @returns {boolean}
|
|
9733
|
+
*/
|
|
9734
|
+
isInfinite() {
|
|
9735
|
+
return !(this["isNaN"]() || this["isFinite"]());
|
|
9736
|
+
}
|
|
9737
|
+
};
|
|
9738
|
+
Complex["ZERO"] = new Complex(0, 0);
|
|
9739
|
+
Complex["ONE"] = new Complex(1, 0);
|
|
9740
|
+
Complex["I"] = new Complex(0, 1);
|
|
9741
|
+
Complex["PI"] = new Complex(Math.PI, 0);
|
|
9742
|
+
Complex["E"] = new Complex(Math.E, 0);
|
|
9743
|
+
Complex["INFINITY"] = new Complex(Infinity, Infinity);
|
|
9744
|
+
Complex["NAN"] = new Complex(NaN, NaN);
|
|
9745
|
+
Complex["EPSILON"] = 1e-15;
|
|
9746
|
+
|
|
8633
9747
|
// src/compute-engine/numerics/numeric-complex.ts
|
|
9748
|
+
var LANCZOS_G = 7;
|
|
9749
|
+
var LANCZOS_P = [
|
|
9750
|
+
0.9999999999998099,
|
|
9751
|
+
676.5203681218851,
|
|
9752
|
+
-1259.1392167224028,
|
|
9753
|
+
771.3234287776531,
|
|
9754
|
+
-176.6150291621406,
|
|
9755
|
+
12.507343278686905,
|
|
9756
|
+
-0.13857109526572012,
|
|
9757
|
+
9984369578019572e-21,
|
|
9758
|
+
15056327351493116e-23
|
|
9759
|
+
];
|
|
9760
|
+
var SQRT_2PI = Math.sqrt(2 * Math.PI);
|
|
9761
|
+
var HALF_LOG_2PI = 0.5 * Math.log(2 * Math.PI);
|
|
8634
9762
|
function gamma2(c) {
|
|
8635
|
-
|
|
9763
|
+
if (c.re < 0.5) {
|
|
9764
|
+
const sinPiZ = c.mul(Math.PI).sin();
|
|
9765
|
+
return new Complex(Math.PI, 0).div(sinPiZ.mul(gamma2(new Complex(1, 0).sub(c))));
|
|
9766
|
+
}
|
|
9767
|
+
const z = c.sub(1);
|
|
9768
|
+
let x = new Complex(LANCZOS_P[0], 0);
|
|
9769
|
+
for (let i = 1; i < LANCZOS_G + 2; i++)
|
|
9770
|
+
x = x.add(new Complex(LANCZOS_P[i], 0).div(z.add(i)));
|
|
9771
|
+
const t = z.add(LANCZOS_G + 0.5);
|
|
9772
|
+
return new Complex(SQRT_2PI, 0).mul(t.pow(z.add(0.5))).mul(t.neg().exp()).mul(x);
|
|
8636
9773
|
}
|
|
8637
9774
|
function gammaln2(c) {
|
|
8638
|
-
|
|
9775
|
+
if (c.re < 0.5) {
|
|
9776
|
+
const sinPiZ = c.mul(Math.PI).sin();
|
|
9777
|
+
return new Complex(Math.PI, 0).div(sinPiZ).log().sub(gammaln2(new Complex(1, 0).sub(c)));
|
|
9778
|
+
}
|
|
9779
|
+
const z = c.sub(1);
|
|
9780
|
+
let x = new Complex(LANCZOS_P[0], 0);
|
|
9781
|
+
for (let i = 1; i < LANCZOS_G + 2; i++)
|
|
9782
|
+
x = x.add(new Complex(LANCZOS_P[i], 0).div(z.add(i)));
|
|
9783
|
+
const t = z.add(LANCZOS_G + 0.5);
|
|
9784
|
+
return new Complex(HALF_LOG_2PI, 0).add(z.add(0.5).mul(t.log())).sub(t).add(x.log());
|
|
8639
9785
|
}
|
|
8640
9786
|
|
|
8641
9787
|
// src/numerics.ts
|
|
8642
|
-
var version = "0.
|
|
9788
|
+
var version = "0.59.0";
|
|
8643
9789
|
return __toCommonJS(numerics_exports);
|
|
8644
9790
|
})();
|
|
9791
|
+
/*! Bundled license information:
|
|
9792
|
+
|
|
9793
|
+
complex-esm/dist/src/complex.js:
|
|
9794
|
+
(**
|
|
9795
|
+
* @license Complex.js v2.1.1 12/05/2020
|
|
9796
|
+
*
|
|
9797
|
+
* Copyright (c) 2020, Robert Eisele (robert@xarg.org)
|
|
9798
|
+
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
9799
|
+
**)
|
|
9800
|
+
*/
|
|
8645
9801
|
Object.assign(exports, Numerics); Object.defineProperty(exports, '__esModule', { value: true });}));
|