Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
94
Task/Conjugate-transpose/11l/conjugate-transpose.11l
Normal file
94
Task/Conjugate-transpose/11l/conjugate-transpose.11l
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
-V eps = 1e-10
|
||||
|
||||
F to_str(m)
|
||||
V r = ‘’
|
||||
L(row) m
|
||||
V i = L.index
|
||||
r ‘’= I i == 0 {‘[’} E ‘ ’
|
||||
L(val) row
|
||||
V j = L.index
|
||||
I j != 0
|
||||
r ‘’= ‘ ’
|
||||
r ‘’= ‘(#2.4, #2.4)’.format(val.real, val.imag)
|
||||
r ‘’= I i == m.len - 1 {‘]’} E "\n"
|
||||
R r
|
||||
|
||||
F conjugateTransposed(m)
|
||||
V r = [[0i] * m.len] * m.len
|
||||
L(i) 0 .< m.len
|
||||
L(j) 0 .< m.len
|
||||
r[j][i] = conjugate(m[i][j])
|
||||
R r
|
||||
|
||||
F mmul(m1, m2)
|
||||
V r = [[0i] * m1.len] * m1.len
|
||||
L(i) 0 .< m1.len
|
||||
L(j) 0 .< m1.len
|
||||
L(k) 0 .< m1.len
|
||||
r[i][j] += m1[i][k] * m2[k][j]
|
||||
R r
|
||||
|
||||
F isHermitian(m)
|
||||
L(i) 0 .< m.len
|
||||
L(j) 0 .< m.len
|
||||
I m[i][j] != conjugate(m[j][i])
|
||||
R 0B
|
||||
R 1B
|
||||
|
||||
F isEqual(m1, m2)
|
||||
L(i) 0 .< m1.len
|
||||
L(j) 0 .< m1.len
|
||||
I m1[i][j] != m2[i][j]
|
||||
R 0B
|
||||
R 1B
|
||||
|
||||
F isNormal(m)
|
||||
V h = conjugateTransposed(m)
|
||||
R isEqual(mmul(m, h), mmul(h, m))
|
||||
|
||||
F isIdentity(m)
|
||||
L(i) 0 .< m.len
|
||||
L(j) 0 .< m.len
|
||||
I i == j
|
||||
I abs(m[i][j] - 1.0) > :eps
|
||||
R 0B
|
||||
E
|
||||
I abs(m[i][j]) > :eps
|
||||
R 0B
|
||||
R 1B
|
||||
|
||||
F isUnitary(m)
|
||||
V h = conjugateTransposed(m)
|
||||
R isIdentity(mmul(m, h)) & isIdentity(mmul(h, m))
|
||||
|
||||
F test(m)
|
||||
print(‘Matrix’)
|
||||
print(‘------’)
|
||||
print(to_str(m))
|
||||
print(‘’)
|
||||
print(‘Conjugate transposed’)
|
||||
print(‘--------------------’)
|
||||
print(to_str(conjugateTransposed(m)))
|
||||
print(‘’)
|
||||
print(‘Hermitian: ’(I isHermitian(m) {‘true’} E ‘false’))
|
||||
print(‘Normal: ’(I isNormal(m) {‘true’} E ‘false’))
|
||||
print(‘Unitary: ’(I isUnitary(m) {‘true’} E ‘false’))
|
||||
|
||||
V M2 = [[3.0 + 0.0i, 2.0 + 1.0i],
|
||||
[2.0 - 1.0i, 1.0 + 0.0i]]
|
||||
|
||||
V M3 = [[1.0 + 0.0i, 1.0 + 0.0i, 0.0 + 0.0i],
|
||||
[0.0 + 0.0i, 1.0 + 0.0i, 1.0 + 0.0i],
|
||||
[1.0 + 0.0i, 0.0 + 0.0i, 1.0 + 0.0i]]
|
||||
|
||||
V SR2 = 1 / sqrt(2.0)
|
||||
V SR2i = SR2 * 1i
|
||||
V M4 = [[SR2 + 0.0i, SR2 + 0.0i, 0.0 + 0.0i],
|
||||
[0.0 + SR2i, 0.0 - SR2i, 0.0 + 0.0i],
|
||||
[0.0 + 0.0i, 0.0 + 0.0i, 0.0 + 1.0i]]
|
||||
|
||||
test(M2)
|
||||
print("\n")
|
||||
test(M3)
|
||||
print("\n")
|
||||
test(M4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue