diff --git a/src/Complex/arithmetic.ts b/src/Complex/arithmetic.ts index 0d403f4..90c8eab 100644 --- a/src/Complex/arithmetic.ts +++ b/src/Complex/arithmetic.ts @@ -5,10 +5,6 @@ import type { declare module "../interfaces/type" { interface Signatures { - // TODO: Make Dispatcher collapse operations that match - // after removing any `_...` suffixes; the following should be - // additional dispatches for add and divide, not separate - // operations, in the final mathjs bundle. addReal: AliasOf<'add', (a: T, b: RealType) => T> divideReal: AliasOf<'divide', (a: T, b: RealType) => T> } @@ -18,7 +14,7 @@ export const add = (dep: Dependencies<'add' | 'complex', T>): Signature<'add', Complex> => (w, z) => dep.complex(dep.add(w.re, z.re), dep.add(w.im, z.im)) -export const add_real = +export const addReal = (dep: Dependencies<'addReal' | 'complex', T>): Signature<'addReal', Complex> => (z, r) => dep.complex(dep.addReal(z.re, r), z.im) @@ -57,7 +53,7 @@ export const absquare = Signature<'absquare', Complex> => z => dep.add(dep.absquare(z.re), dep.absquare(z.im)) -export const divideByReal = +export const divideReal = (dep: Dependencies<'divideReal' | 'complex', T>): Signature<'divideReal', Complex> => (z, r) => dep.complex(dep.divideReal(z.re, r), dep.divideReal(z.im, r)) @@ -75,16 +71,16 @@ export const divide = // The dependencies are slightly tricky here, because there are three types // involved: Complex, T, and RealType, all of which might be different, // and we have to get it straight which operations we need on each type, and -// in fact, we need `add_real` on both T and Complex, hence the dependency +// in fact, we need `addReal` on both T and Complex, hence the dependency // with a custom name, not generated via Dependencies<...> export const sqrt = (dep: Dependencies<'equal' | 'conservativeSqrt' | 'unaryMinus', RealType> & Dependencies<'zero' | 'complex', T> & Dependencies<'absquare' | 're' | 'divideReal', Complex> & { - addNumber: Signature<'addReal', T>, // TODO: should use Signature<'add'> here - addReal: Signature<'add', RealType>, - addComplex: Signature<'addReal', Complex> // TODO: should use Signature<'add'> here + addTR: Signature<'addReal', T>, + addRR: Signature<'add', RealType>, + addCR: Signature<'addReal', Complex> }): Signature<'sqrt', Complex> => z => { @@ -94,10 +90,10 @@ export const sqrt = if (dep.equal(myabs, negr)) { // pure imaginary square root; z.im already zero return dep.complex( - dep.zero(z.re), dep.addNumber(z.im, dep.conservativeSqrt(negr))) + dep.zero(z.re), dep.addTR(z.im, dep.conservativeSqrt(negr))) } - const num = dep.addComplex(z, myabs) - const denomsq = dep.addReal(dep.addReal(myabs, myabs), dep.addReal(r, r)) + const num = dep.addCR(z, myabs) + const denomsq = dep.addRR(dep.addRR(myabs, myabs), dep.addRR(r, r)) const denom = dep.conservativeSqrt(denomsq) return dep.divideReal(num, denom) }