def test_dft(): n, i, j = symbols('n i j') assert DFT(4).shape == (4, 4) assert ask(Q.unitary(DFT(4))) assert Abs(simplify(det(Matrix(DFT(4))))) == 1 assert DFT(n) * IDFT(n) == Identity(n) assert DFT(n)[i, j] == exp(-2 * S.Pi * I / n)**(i * j) / sqrt(n)
def test_dft2(): assert DFT(1).as_explicit() == Matrix([[1]]) assert DFT(2).as_explicit() == 1/sqrt(2)*Matrix([[1,1],[1,-1]]) assert DFT(4).as_explicit() == Matrix([[S.Half, S.Half, S.Half, S.Half], [S.Half, -I/2, Rational(-1,2), I/2], [S.Half, Rational(-1,2), S.Half, Rational(-1,2)], [S.Half, I/2, Rational(-1,2), -I/2]])
def test_issue_20275(): # XXX We use complex expansions because complex exponentials are not # recognized by polys.domains A = DFT(3).as_explicit().expand(complex=True) eigenvects = A.eigenvects() assert eigenvects[0] == (-1, 1, [Matrix([[1 - sqrt(3)], [1], [1]])]) assert eigenvects[1] == (1, 1, [Matrix([[1 + sqrt(3)], [1], [1]])]) assert eigenvects[2] == (-I, 1, [Matrix([[0], [-1], [1]])]) A = DFT(4).as_explicit().expand(complex=True) eigenvects = A.eigenvects() assert eigenvects[0] == (-1, 1, [Matrix([[-1], [1], [1], [1]])]) assert eigenvects[1] == (1, 2, [ Matrix([[1], [0], [1], [0]]), Matrix([[2], [1], [0], [1]]) ]) assert eigenvects[2] == (-I, 1, [Matrix([[0], [-1], [0], [1]])]) # XXX We skip test for some parts of eigenvectors which are very # complicated and fragile under expression tree changes A = DFT(5).as_explicit().expand(complex=True) eigenvects = A.eigenvects() assert eigenvects[0] == (-1, 1, [Matrix([[1 - sqrt(5)], [1], [1], [1], [1]])]) assert eigenvects[1] == (1, 2, [ Matrix([[S(1) / 2 + sqrt(5) / 2], [0], [1], [1], [0]]), Matrix([[S(1) / 2 + sqrt(5) / 2], [1], [0], [0], [1]]) ])
def test_matrix_element_sets(): X = MatrixSymbol('X', 4, 4) assert ask(Q.real(X[1, 2]), Q.real_elements(X)) assert ask(Q.integer(X[1, 2]), Q.integer_elements(X)) assert ask(Q.complex(X[1, 2]), Q.complex_elements(X)) assert ask(Q.integer_elements(Identity(3))) assert ask(Q.integer_elements(ZeroMatrix(3, 3))) from sympy.matrices.expressions.fourier import DFT assert ask(Q.complex_elements(DFT(3)))
def mdft(n): r""" .. deprecated:: 1.9 Use DFT from sympy.matrices.expressions.fourier instead. To get identical behavior to ``mdft(n)``, use ``DFT(n).as_explicit()``. """ from sympy.matrices.expressions.fourier import DFT return DFT(n).as_mutable()
def test_dft_creation(): assert DFT(2) assert DFT(0) raises(ValueError, lambda: DFT(-1)) raises(ValueError, lambda: DFT(2.0)) raises(ValueError, lambda: DFT(2 + 1j)) n = symbols('n') assert DFT(n) n = symbols('n', integer=False) raises(ValueError, lambda: DFT(n)) n = symbols('n', negative=True) raises(ValueError, lambda: DFT(n))
from sympy.physics.quantum import TensorProduct from sympy.physics.quantum.constants import hbar # %% # Remeber this to have LaTeX rendered output in Jupyter init_printing() # %% [markdown] # ## Computation # %% Omega = Symbol(r'\Omega') omega = Symbol(r'\omega', real=True) # %% F = DFT(2).as_mutable() # %% Omega = I * omega * Matrix([[0, 1], [-1, 0]]) # %% Omega.eigenvects() # %% T = (pi / (2 * omega)**2) * F.adjoint() * Omega * F # %% T # %% T.eigenvects()
delta = Symbol(r'\delta', real=True) Omega = Symbol(r'\Omega') omega = Symbol(r'\omega', real=True) # %% hbar = 1 # %% Delta = Rational(1,2) # 1/N, N=dimension of H_T # %% delta = 0.0001 # %% # F = mdft(2) # deprecation F = DFT(2).as_mutable() # %% T = (pi/omega) * Matrix([ [delta, 0], [0, Delta+delta] ]) # %% T # %% Omega = (omega**2/(pi*Delta**2))*F*T*(F.adjoint()) # %% Omega
N = Integer(4) # %% deltaT = Rational(1, 1) # %% DeltaT = N * deltaT # %% T = diag(*Range(N)) # %% T # %% F = DFT(N) # %% F.as_explicit() # %% Dagger(F).as_explicit() # %% Omega = (Dagger(F) @ T @ F).as_explicit() # %% Omega # %% T @ Omega - Omega @ T