]> gitweb.factorcode.org Git - factor.git/blob - extra/rosetta-code/conjugate-transpose/conjugate-transpose.factor
Switch to https urls
[factor.git] / extra / rosetta-code / conjugate-transpose / conjugate-transpose.factor
1 ! Copyright (c) 2012 Anonymous
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: kernel math.functions math.matrices sequences ;
4 IN: rosetta-code.conjugate-transpose
5
6 ! https://rosettacode.org/wiki/Conjugate_transpose
7
8 ! Suppose that a matrix M contains complex numbers. Then the
9 ! conjugate transpose of M is a matrix MH containing the complex
10 ! conjugates of the matrix transposition of M.
11
12 ! This means that row j, column i of the conjugate transpose
13 ! equals the complex conjugate of row i, column j of the original
14 ! matrix.
15
16 ! In the next list, M must also be a square matrix.
17
18 ! A Hermitian matrix equals its own conjugate transpose: MH = M.
19
20 ! A normal matrix is commutative in multiplication with its
21 ! conjugate transpose: MHM = MMH.
22
23 ! A unitary matrix has its inverse equal to its conjugate
24 ! transpose: MH = M − 1. This is true iff MHM = In and iff MMH =
25 ! In, where In is the identity matrix.
26
27 ! Given some matrix of complex numbers, find its conjugate
28 ! transpose. Also determine if it is a Hermitian matrix, normal
29 ! matrix, or a unitary matrix.
30
31 : conj-t ( matrix -- conjugate-transpose )
32     flip [ [ conjugate ] map ] map ;
33
34 : hermitian-matrix? ( matrix -- ? )
35     dup conj-t = ;
36
37 : normal-matrix? ( matrix -- ? )
38     dup conj-t [ mdot ] [ swap mdot ] 2bi = ;
39
40 : unitary-matrix? ( matrix -- ? )
41     [ dup conj-t mdot ] [ length <identity-matrix> ] bi = ;