feat: add cis and fix indistinguishable
All checks were successful
/ test (pull_request) Successful in 16s

This commit is contained in:
Glen Whitney 2025-04-24 20:52:43 -07:00
parent 7daa621571
commit 7903a46118
3 changed files with 10 additions and 3 deletions

View file

@ -32,4 +32,8 @@ describe('complex type operations', () => {
assert(!assoc(b, cplx(false, true)))
assert(!assoc(cplx(0, 1), b))
})
it('computes cis of an angle', () => {
assert(math.equal(math.cis(0), 1))
assert(math.equal(math.cis(Math.PI/3), cplx(0.5, Math.sqrt(3)/2)))
})
})

View file

@ -13,11 +13,11 @@ export const indistinguishable = match(
return Returns(
BooleanT, (w, z) => same(w.re, z.re) && same(w.im, z.im))
}
const [RT, AT] = T
const [[RT, AT]] = T
const same = math.indistinguishable.resolve([WComp, ZComp, RT, AT])
return Returns(
BooleanT,
(w, z, [rT, aT]) => {
(w, z, [[rT, aT]]) => {
return same(w.re, z.re, rT, aT) && same(w.im, z.im, rT, aT)
})
})

View file

@ -49,4 +49,7 @@ export const associate = match([Complex, Complex], (math, [W, Z]) => {
const iz = mult(iZ, z)
return eqM(w, iz) || eqNM(w, negM(iz))
})
})
})
export const cis = match(NumberT, Returns(Complex(NumberT), t => ({
re: Math.cos(t), im: Math.sin(t)})))