refactor: rename absquare to normsq and add norm

This commit is contained in:
Glen Whitney 2025-05-02 21:20:45 -07:00
parent edfba089e3
commit ec97b0e20a
7 changed files with 32 additions and 20 deletions

View file

@ -7,11 +7,11 @@ import {ReturnsAs} from '#generic/helpers.js'
const {conservative, full, free} = ReturnTyping
export const absquare = match(Complex, (math, C, strategy) => {
const compAbsq = math.absquare.resolve(C.Component, full)
const R = compAbsq.returns
export const normsq = match(Complex, (math, C, strategy) => {
const compNormsq = math.normsq.resolve(C.Component, full)
const R = compNormsq.returns
const add = math.add.resolve([R,R], strategy)
return ReturnsAs(add, z => add(compAbsq(z.re), compAbsq(z.im)))
return ReturnsAs(add, z => add(compNormsq(z.re), compNormsq(z.im)))
})
export const add = promoteBinary('add')
@ -38,12 +38,12 @@ export const divide = [
export const invert = match(Complex, (math, C, strategy) => {
const conj = math.conj.resolve(C, full)
const norm = math.absquare.resolve(C, full)
const div = math.divide.resolve([C.Component, norm.returns], full)
const normsq = math.normsq.resolve(C, full)
const div = math.divide.resolve([C.Component, normsq.returns], full)
const cplx = maybeComplex(math, strategy, div.returns, div.returns)
return ReturnsAs(cplx, z => {
const c = conj(z)
const d = norm(z)
const d = normsq(z)
return cplx(div(c.re, d), div(c.im, d))
})
})