Ejemplo n.º 1
0
def hadamard_matrix_paleyII(n):
    N = ZZ(n/2)
    if is_prime(N-1) and (N-1)%4==1:
        p = N-1
    else:
        raise ValueError, "The order %s is not covered by the Paley type II construction."%n
    S = matrix(ZZ,[[H2(i,j,p) for i in range(N)] for j in range(N)])
    return block_matrix([[S+1,S-1],[S-1,-S-1]])
Ejemplo n.º 2
0
def hadamard_matrix(n):
    if not(n%4==0) and not(n==2):
        raise ValueError, "The Hadamard matrix of order %s does not exist"%n
    if n==2:
        return matrix([[1,1],[1,-1]])
    if is_even(n):
        N = ZZ(n/2)
    elif n==1:
        return matrix([1])
    if is_prime(N-1) and (N-1)%4==1:
        return hadamard_matrix_paleyII(n)
    elif n==4 or n%8==0:
        had = hadamard_matrix(ZZ(n/2))
        chad1 = matrix([list(r)+list(r) for r in had.rows()])
        mhad = (-1)*had
        R = len(had.rows())
        chad2 = matrix([list(had.rows()[i])+list(mhad.rows()[i]) for i in range(R)]) 
        return chad1.stack(chad2)
    elif is_prime(N-1) and (N-1)%4==3:
        return hadamard_matrix_paleyI(n)
    else: 
        raise ValueError, "The Hadamard matrix of order %s is not yet implemented."%n
Ejemplo n.º 3
0
def hadamard_matrix_paleyI(n):
    if is_prime(n-1) and (n-1)%4==3:
        p = n-1
    else:
        raise ValueError, "The order %s is not covered by the Paley type I construction."%n
    return matrix(ZZ,[[H1(i,j,p) for i in range(n)] for j in range(n)])