MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / reduceCollection

Function reduceCollection

src/compute-engine/library/arithmetic.ts:2650–2661  ·  view source on GitHub ↗

Generator-based reducer over a finite collection. Yields between * iterations so callers can wrap it with `run`/`runAsync` for timeout * and cancellation. Caller is responsible for finiteness checks.

(
  collection: Expression,
  init: Expression,
  combine: (acc: Expression, x: Expression) => Expression
)

Source from the content-addressed store, hash-verified

2648 type: ([base, exp]) => {
2649 if (base.isNaN || exp.isNaN) return 'number';
2650 // Root(x, n) = x^(1/n). A non-finite base or index makes the result
2651 // indeterminate: Root(±∞, n) ∈ {0, ±∞, complex}, Root(x, ±∞) = x^0
2652 // (often 1 but 0^0/∞^0 are NaN). Widen to the top type.
2653 if (base.isFinite === false || exp.isFinite === false) return 'number';
2654 // Root(x, 0) = x^(1/0): a pole (the old `finite_integer` was wrong —
2655 // Root(2,0), Root(0,0), Root(−2,0) all evaluate to NaN).
2656 if (exp.isSame(0)) return 'number';
2657 if (exp.isSame(1)) return base.type;
2658 // Root(0, n): 0 for n>0, a pole (±∞) for n≤0, NaN for a complex index.
2659 if (base.isSame(0))
2660 return exp.isPositive === true ? 'finite_integer' : 'number';
2661 if (base.isReal && exp.isReal) {
2662 // A positive base always gives a positive real root.
2663 if (base.isPositive === true) return 'finite_real';
2664 // A negative real base with a provably *even* degree has no real

Callers 1

arithmetic.tsFile · 0.70

Calls 2

combineFunction · 0.70
eachMethod · 0.65

Tested by

no test coverage detected