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
6 ! https://rosettacode.org/wiki/Conjugate_transpose
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.
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
16 ! In the next list, M must also be a square matrix.
18 ! A Hermitian matrix equals its own conjugate transpose: MH = M.
20 ! A normal matrix is commutative in multiplication with its
21 ! conjugate transpose: MHM = MMH.
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.
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.
31 : conj-t ( matrix -- conjugate-transpose )
32 flip [ [ conjugate ] map ] map ;
34 : hermitian-matrix? ( matrix -- ? )
37 : normal-matrix? ( matrix -- ? )
38 dup conj-t [ mdot ] [ swap mdot ] 2bi = ;
40 : unitary-matrix? ( matrix -- ? )
41 [ dup conj-t mdot ] [ length <identity-matrix> ] bi = ;