feat: add cis and fix indistinguishable
All checks were successful
/ test (pull_request) Successful in 16s
All checks were successful
/ test (pull_request) Successful in 16s
This commit is contained in:
parent
7daa621571
commit
7903a46118
3 changed files with 10 additions and 3 deletions
|
@ -32,4 +32,8 @@ describe('complex type operations', () => {
|
||||||
assert(!assoc(b, cplx(false, true)))
|
assert(!assoc(b, cplx(false, true)))
|
||||||
assert(!assoc(cplx(0, 1), b))
|
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)))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,11 +13,11 @@ export const indistinguishable = match(
|
||||||
return Returns(
|
return Returns(
|
||||||
BooleanT, (w, z) => same(w.re, z.re) && same(w.im, z.im))
|
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])
|
const same = math.indistinguishable.resolve([WComp, ZComp, RT, AT])
|
||||||
return Returns(
|
return Returns(
|
||||||
BooleanT,
|
BooleanT,
|
||||||
(w, z, [rT, aT]) => {
|
(w, z, [[rT, aT]]) => {
|
||||||
return same(w.re, z.re, rT, aT) && same(w.im, z.im, rT, aT)
|
return same(w.re, z.re, rT, aT) && same(w.im, z.im, rT, aT)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -49,4 +49,7 @@ export const associate = match([Complex, Complex], (math, [W, Z]) => {
|
||||||
const iz = mult(iZ, z)
|
const iz = mult(iZ, z)
|
||||||
return eqM(w, iz) || eqNM(w, negM(iz))
|
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)})))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue