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

Function powers

src/compute-engine/boxed-expression/expand.ts:49–57  ·  view source on GitHub ↗
(n: number, exp: number)

Source from the content-addressed store, hash-verified

47}
48
49// Return all the combinations of n non-negative integers that sum to exp.
50function* powers(n: number, exp: number): Generator<number[]> {
51 if (n === 1) {
52 yield [exp];
53 return;
54 }
55
56 for (let i = 0; i <= exp; i += 1)
57 for (const p of powers(n - 1, exp - i)) yield [i, ...p];
58}
59
60/** Use the multinomial theorem (https://en.wikipedia.org/wiki/Multinomial_theorem) to expand the expression.

Callers 1

expandPowerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected