def test_fftw_inverse(): c = FFTW(y) with assuming(Q.complex(y)): f = build(c, [y], [DFT(y)], modname='fftw2', filename='tmp/fftw2.f90') c = IFFTW(y) with assuming(Q.complex(y)): fi = build(c, [y], [DFT(y).T], modname='ifftw', filename='tmp/ifftw.f90') x = np.random.random_sample((8,)) + 1j * np.random.random_sample((8,)) expected = x f(x) fi(x) assert np.allclose(expected, x)
def test_pow1(): assert refine((-1)**x, Q.even(x)) == 1 assert refine((-1)**x, Q.odd(x)) == -1 assert refine((-2)**x, Q.even(x)) == 2**x # nested powers assert refine(sqrt(x**2)) != Abs(x) assert refine(sqrt(x**2), Q.complex(x)) != Abs(x) assert refine(sqrt(x**2), Q.real(x)) == Abs(x) assert refine(sqrt(x**2), Q.positive(x)) == x assert refine((x**3)**Rational(1, 3)) != x assert refine((x**3)**Rational(1, 3), Q.real(x)) != x assert refine((x**3)**Rational(1, 3), Q.positive(x)) == x assert refine(sqrt(1/x), Q.real(x)) != 1/sqrt(x) assert refine(sqrt(1/x), Q.positive(x)) == 1/sqrt(x) # powers of (-1) assert refine((-1)**(x + y), Q.even(x)) == (-1)**y assert refine((-1)**(x + y + z), Q.odd(x) & Q.odd(z)) == (-1)**y assert refine((-1)**(x + y + 1), Q.odd(x)) == (-1)**y assert refine((-1)**(x + y + 2), Q.odd(x)) == (-1)**(y + 1) assert refine((-1)**(x + 3)) == (-1)**(x + 1) # continuation assert refine((-1)**((-1)**x/2 - S.Half), Q.integer(x)) == (-1)**x assert refine((-1)**((-1)**x/2 + S.Half), Q.integer(x)) == (-1)**(x + 1) assert refine((-1)**((-1)**x/2 + 5*S.Half), Q.integer(x)) == (-1)**(x + 1)
def test_pow(): assert refine((-1) ** x, Q.even(x)) == 1 assert refine((-1) ** x, Q.odd(x)) == -1 assert refine((-2) ** x, Q.even(x)) == 2 ** x # nested powers assert refine(sqrt(x ** 2)) != Abs(x) assert refine(sqrt(x ** 2), Q.complex(x)) != Abs(x) assert refine(sqrt(x ** 2), Q.real(x)) == Abs(x) assert refine(sqrt(x ** 2), Q.positive(x)) == x assert refine((x ** 3) ** (S(1) / 3)) != x assert refine((x ** 3) ** (S(1) / 3), Q.real(x)) != x assert refine((x ** 3) ** (S(1) / 3), Q.positive(x)) == x assert refine(sqrt(1 / x), Q.real(x)) != 1 / sqrt(x) assert refine(sqrt(1 / x), Q.positive(x)) == 1 / sqrt(x) # powers of (-1) assert refine((-1) ** (x + y), Q.even(x)) == (-1) ** y assert refine((-1) ** (x + y + z), Q.odd(x) & Q.odd(z)) == (-1) ** y assert refine((-1) ** (x + y + 1), Q.odd(x)) == (-1) ** y assert refine((-1) ** (x + y + 2), Q.odd(x)) == (-1) ** (y + 1) assert refine((-1) ** (x + 3)) == (-1) ** (x + 1) assert refine((-1) ** ((-1) ** x / 2 - S.Half), Q.integer(x)) == (-1) ** x assert refine((-1) ** ((-1) ** x / 2 + S.Half), Q.integer(x)) == (-1) ** (x + 1) assert refine((-1) ** ((-1) ** x / 2 + 5 * S.Half), Q.integer(x)) == (-1) ** (x + 1) assert refine((-1) ** ((-1) ** x / 2 - 7 * S.Half), Q.integer(x)) == (-1) ** (x + 1) assert refine((-1) ** ((-1) ** x / 2 - 9 * S.Half), Q.integer(x)) == (-1) ** x # powers of Abs assert refine(Abs(x) ** 2, Q.real(x)) == x ** 2 assert refine(Abs(x) ** 3, Q.real(x)) == Abs(x) ** 3 assert refine(Abs(x) ** 2) == Abs(x) ** 2
def test_pow(): x, y, z = symbols('x,y,z') assert refine((-1)**x, Q.even(x)) == 1 assert refine((-1)**x, Q.odd(x)) == -1 assert refine((-2)**x, Q.even(x)) == 2**x # nested powers assert refine(sqrt(x**2)) != Abs(x) assert refine(sqrt(x**2), Q.complex(x)) != Abs(x) assert refine(sqrt(x**2), Q.real(x)) == Abs(x) assert refine(sqrt(x**2), Q.positive(x)) == x assert refine((x**3)**(S(1)/3)) != x assert refine((x**3)**(S(1)/3), Q.real(x)) != x assert refine((x**3)**(S(1)/3), Q.positive(x)) == x assert refine(sqrt(1/x), Q.real(x)) != 1/sqrt(x) assert refine(sqrt(1/x), Q.positive(x)) == 1/sqrt(x) # powers of (-1) assert refine((-1)**(x+y), Q.even(x)) == (-1)**y assert refine((-1)**(x+y+z), Q.odd(x) & Q.odd(z))==(-1)**y assert refine((-1)**(x+y+1), Q.odd(x))==(-1)**y assert refine((-1)**(x+y+2), Q.odd(x))==(-1)**(y+1) assert refine((-1)**(x+3)) == (-1)**(x+1)
def test_pow(): x, y, z = symbols('x,y,z') assert refine((-1)**x, Q.even(x)) == 1 assert refine((-1)**x, Q.odd(x)) == -1 assert refine((-2)**x, Q.even(x)) == 2**x # nested powers assert refine(sqrt(x**2)) != Abs(x) assert refine(sqrt(x**2), Q.complex(x)) != Abs(x) assert refine(sqrt(x**2), Q.real(x)) == Abs(x) assert refine(sqrt(x**2), Q.positive(x)) == x assert refine((x**3)**(S(1) / 3)) != x assert refine((x**3)**(S(1) / 3), Q.real(x)) != x assert refine((x**3)**(S(1) / 3), Q.positive(x)) == x assert refine(sqrt(1 / x), Q.real(x)) != 1 / sqrt(x) assert refine(sqrt(1 / x), Q.positive(x)) == 1 / sqrt(x) # powers of (-1) assert refine((-1)**(x + y), Q.even(x)) == (-1)**y assert refine((-1)**(x + y + z), Q.odd(x) & Q.odd(z)) == (-1)**y assert refine((-1)**(x + y + 1), Q.odd(x)) == (-1)**y assert refine((-1)**(x + y + 2), Q.odd(x)) == (-1)**(y + 1) assert refine((-1)**(x + 3)) == (-1)**(x + 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 dtype_of(expr, *assumptions): if hasattr(expr, 'fortran_type'): return expr.fortran_type() with assuming(*assumptions): if ask(Q.integer(expr) | Q.integer_elements(expr)) or expr.is_integer: result = 'integer' elif ask(Q.real(expr) | Q.real_elements(expr)) or expr.is_real: result = 'real(kind=8)' elif ask(Q.complex(expr) | Q.complex_elements(expr)) or expr.is_complex: result = 'complex(kind=8)' else: raise TypeError('Could not infer type of %s'%str(expr)) return result
def test_pow1(): assert refine((-1)**x, Q.even(x)) == 1 assert refine((-1)**x, Q.odd(x)) == -1 assert refine((-2)**x, Q.even(x)) == 2**x # nested powers assert refine(sqrt(x**2)) != Abs(x) assert refine(sqrt(x**2), Q.complex(x)) != Abs(x) assert refine(sqrt(x**2), Q.real(x)) == Abs(x) assert refine(sqrt(x**2), Q.positive(x)) == x assert refine((x**3)**(S(1)/3)) != x assert refine((x**3)**(S(1)/3), Q.real(x)) != x assert refine((x**3)**(S(1)/3), Q.positive(x)) == x assert refine(sqrt(1/x), Q.real(x)) != 1/sqrt(x) assert refine(sqrt(1/x), Q.positive(x)) == 1/sqrt(x)
def test_pow(): assert refine((-1)**x, Q.even(x)) == 1 assert refine((-1)**x, Q.odd(x)) == -1 assert refine((-2)**x, Q.even(x)) == 2**x # nested powers assert refine(sqrt(x**2)) != Abs(x) assert refine(sqrt(x**2), Q.complex(x)) != Abs(x) assert refine(sqrt(x**2), Q.real(x)) == Abs(x) assert refine(sqrt(x**2), Q.positive(x)) == x assert refine((x**3)**(S(1) / 3)) != x assert refine((x**3)**(S(1) / 3), Q.real(x)) != x assert refine((x**3)**(S(1) / 3), Q.positive(x)) == x assert refine(sqrt(1 / x), Q.real(x)) != 1 / sqrt(x) assert refine(sqrt(1 / x), Q.positive(x)) == 1 / sqrt(x) # powers of (-1) assert refine((-1)**(x + y), Q.even(x)) == (-1)**y assert refine((-1)**(x + y + z), Q.odd(x) & Q.odd(z)) == (-1)**y assert refine((-1)**(x + y + 1), Q.odd(x)) == (-1)**y assert refine((-1)**(x + y + 2), Q.odd(x)) == (-1)**(y + 1) assert refine((-1)**(x + 3)) == (-1)**(x + 1) assert refine((-1)**((-1)**x / 2 - S.Half), Q.integer(x)) == (-1)**x assert refine((-1)**((-1)**x / 2 + S.Half), Q.integer(x)) == (-1)**(x + 1) assert refine((-1)**((-1)**x / 2 + 5 * S.Half), Q.integer(x)) == (-1)**(x + 1) assert refine((-1)**((-1)**x / 2 - 7 * S.Half), Q.integer(x)) == (-1)**(x + 1) assert refine((-1)**((-1)**x / 2 - 9 * S.Half), Q.integer(x)) == (-1)**x # powers of Abs assert refine(Abs(x)**2, Q.real(x)) == x**2 assert refine(Abs(x)**3, Q.real(x)) == Abs(x)**3 assert refine(Abs(x)**2) == Abs(x)**2