<s> from sympy import Q , ask , Symbol <EOL> from sympy . matrices . expressions import ( MatrixSymbol , Identity , ZeroMatrix , <EOL> Trace , MatrixSlice , Determinant ) <EOL> from sympy . matrices . expressions . factorizations import LofLU <EOL> from sympy . utilities . pytest import XFAIL <EOL> X = MatrixSymbol ( '<STR_LIT:X>' , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> Y = MatrixSymbol ( '<STR_LIT:Y>' , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> Z = MatrixSymbol ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> def test_square ( ) : <EOL> assert ask ( Q . square ( X ) ) <EOL> assert not ask ( Q . square ( Y ) ) <EOL> assert ask ( Q . square ( Y * Y . T ) ) <EOL> def test_invertible ( ) : <EOL> assert ask ( Q . invertible ( X ) , Q . invertible ( X ) ) <EOL> assert ask ( Q . invertible ( Y ) ) is False <EOL> assert ask ( Q . invertible ( X * Y ) , Q . invertible ( X ) ) is False <EOL> assert ask ( Q . invertible ( X * Z ) , Q . invertible ( X ) ) is None <EOL> assert ask ( Q . invertible ( X * Z ) , Q . invertible ( X ) & Q . invertible ( Z ) ) is True <EOL> assert ask ( Q . invertible ( X . T ) ) is None <EOL> assert ask ( Q . invertible ( X . T ) , Q . invertible ( X ) ) is True <EOL> assert ask ( Q . invertible ( X . I ) ) is True <EOL> assert ask ( Q . invertible ( Identity ( <NUM_LIT:3> ) ) ) is True <EOL> assert ask ( Q . invertible ( ZeroMatrix ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) is False <EOL> assert ask ( Q . invertible ( X ) , Q . fullrank ( X ) & Q . square ( X ) ) <EOL> def test_singular ( ) : <EOL> assert ask ( Q . singular ( X ) ) is None <EOL> assert ask ( Q . singular ( X ) , Q . invertible ( X ) ) is False <EOL> assert ask ( Q . singular ( X ) , ~ Q . invertible ( X ) ) is True <EOL> @ XFAIL <EOL> def test_invertible_fullrank ( ) : <EOL> assert ask ( Q . invertible ( X ) , Q . fullrank ( X ) ) <EOL> def test_symmetric ( ) : <EOL> assert ask ( Q . symmetric ( X ) , Q . symmetric ( X ) ) <EOL> assert ask ( Q . symmetric ( X * Z ) , Q . symmetric ( X ) ) is None <EOL> assert ask ( Q . symmetric ( X * Z ) , Q . symmetric ( X ) & Q . symmetric ( Z ) ) is True <EOL> assert ask ( Q . symmetric ( X + Z ) , Q . symmetric ( X ) & Q . symmetric ( Z ) ) is True <EOL> assert ask ( Q . symmetric ( Y ) ) is False <EOL> assert ask ( Q . symmetric ( Y * Y . T ) ) is True <EOL> assert ask ( Q . symmetric ( Y . T * X * Y ) ) is None <EOL> assert ask ( Q . symmetric ( Y . T * X * Y ) , Q . symmetric ( X ) ) is True <EOL> assert ask ( Q . symmetric ( X * X * X * X * X * X * X * X * X * X ) , Q . symmetric ( X ) ) is True <EOL> def _test_orthogonal_unitary ( predicate ) : <EOL> assert ask ( predicate ( X ) , predicate ( X ) ) <EOL> assert ask ( predicate ( X . T ) , predicate ( X ) ) is True <EOL> assert ask ( predicate ( X . I ) , predicate ( X ) ) is True <EOL> assert ask ( predicate ( Y ) ) is False <EOL> assert ask ( predicate ( X ) ) is None <EOL> assert ask ( predicate ( X * Z * X ) , predicate ( X ) & predicate ( Z ) ) is True <EOL> assert ask ( predicate ( Identity ( <NUM_LIT:3> ) ) ) is True <EOL> assert ask ( predicate ( ZeroMatrix ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) is False <EOL> assert ask ( Q . invertible ( X ) , predicate ( X ) ) <EOL> assert not ask ( predicate ( X + Z ) , predicate ( X ) & predicate ( Z ) ) <EOL> def test_orthogonal ( ) : <EOL> _test_orthogonal_unitary ( Q . orthogonal ) <EOL> def test_unitary ( ) : <EOL> _test_orthogonal_unitary ( Q . unitary ) <EOL> assert ask ( Q . unitary ( X ) , Q . orthogonal ( X ) ) <EOL> def test_fullrank ( ) : <EOL> assert ask ( Q . fullrank ( X ) , Q . fullrank ( X ) ) <EOL> assert ask ( Q . fullrank ( X . T ) , Q . fullrank ( X ) ) is True <EOL> assert ask ( Q . fullrank ( X ) ) is None <EOL> assert ask ( Q . fullrank ( Y ) ) is None <EOL> assert ask ( Q . fullrank ( X * Z ) , Q . fullrank ( X ) & Q . fullrank ( Z ) ) is True <EOL> assert ask ( Q . fullrank ( Identity ( <NUM_LIT:3> ) ) ) is True <EOL> assert ask ( Q . fullrank ( ZeroMatrix ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) is False <EOL> assert ask ( Q . invertible ( X ) , ~ Q . fullrank ( X ) ) == False <EOL> def test_positive_definite ( ) : <EOL> assert ask ( Q . positive_definite ( X ) , Q . positive_definite ( X ) ) <EOL> assert ask ( Q . positive_definite ( X . T ) , Q . positive_definite ( X ) ) is True <EOL> assert ask ( Q . positive_definite ( X . I ) , Q . positive_definite ( X ) ) is True <EOL> assert ask ( Q . positive_definite ( Y ) ) is False <EOL> assert ask ( Q . positive_definite ( X ) ) is None <EOL> assert ask ( Q . positive_definite ( X * Z * X ) , <EOL> Q . positive_definite ( X ) & Q . positive_definite ( Z ) ) is True <EOL> assert ask ( Q . positive_definite ( X ) , Q . orthogonal ( X ) ) <EOL> assert ask ( Q . positive_definite ( Y . T * X * Y ) , <EOL> Q . positive_definite ( X ) & Q . fullrank ( Y ) ) is True <EOL> assert not ask ( Q . positive_definite ( Y . T * X * Y ) , Q . positive_definite ( X ) ) <EOL> assert ask ( Q . positive_definite ( Identity ( <NUM_LIT:3> ) ) ) is True <EOL> assert ask ( Q . positive_definite ( ZeroMatrix ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) is False <EOL> assert ask ( Q . positive_definite ( X + Z ) , Q . positive_definite ( X ) & <EOL> Q . positive_definite ( Z ) ) is True <EOL> assert not ask ( Q . positive_definite ( - X ) , Q . positive_definite ( X ) ) <EOL> assert ask ( Q . positive ( X [ <NUM_LIT:1> , <NUM_LIT:1> ] ) , Q . positive_definite ( X ) ) <EOL> def test_triangular ( ) : <EOL> assert ask ( Q . upper_triangular ( X + Z . T + Identity ( <NUM_LIT:2> ) ) , Q . upper_triangular ( X ) & <EOL> Q . lower_triangular ( Z ) ) is True <EOL> assert ask ( Q . upper_triangular ( X * Z . T ) , Q . upper_triangular ( X ) & <EOL> Q . lower_triangular ( Z ) ) is True <EOL> assert ask ( Q . lower_triangular ( Identity ( <NUM_LIT:3> ) ) ) is True <EOL> assert ask ( Q . lower_triangular ( ZeroMatrix ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) is True <EOL> assert ask ( Q . triangular ( X ) , Q . unit_triangular ( X ) ) <EOL> def test_diagonal ( ) : <EOL> assert ask ( Q . diagonal ( X + Z . T + Identity ( <NUM_LIT:2> ) ) , Q . diagonal ( X ) & <EOL> Q . diagonal ( Z ) ) is True <EOL> assert ask ( Q . diagonal ( ZeroMatrix ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> assert ask ( Q . lower_triangular ( X ) & Q . upper_triangular ( X ) , Q . diagonal ( X ) ) <EOL> assert ask ( Q . diagonal ( X ) , Q . lower_triangular ( X ) & Q . upper_triangular ( X ) ) <EOL> assert ask ( Q . symmetric ( X ) , Q . diagonal ( X ) ) <EOL> assert ask ( Q . triangular ( X ) , Q . diagonal ( X ) ) <EOL> def test_non_atoms ( ) : <EOL> assert ask ( Q . real ( Trace ( X ) ) , Q . positive ( Trace ( X ) ) ) <EOL> @ XFAIL <EOL> def test_non_trivial_implies ( ) : <EOL> X = MatrixSymbol ( '<STR_LIT:X>' , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> Y = MatrixSymbol ( '<STR_LIT:Y>' , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> assert ask ( Q . lower_triangular ( X + Y ) , Q . lower_triangular ( X ) & <EOL> Q . lower_triangular ( Y ) ) <EOL> assert ask ( Q . triangular ( X ) , Q . lower_triangular ( X ) ) <EOL> assert ask ( Q . triangular ( X + Y ) , Q . lower_triangular ( X ) & <EOL> Q . lower_triangular ( Y ) ) <EOL> def test_MatrixSlice ( ) : <EOL> X = MatrixSymbol ( '<STR_LIT:X>' , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> B = MatrixSlice ( X , ( <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> C = MatrixSlice ( X , ( <NUM_LIT:0> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> assert ask ( Q . symmetric ( B ) , Q . symmetric ( X ) ) <EOL> assert ask ( Q . invertible ( B ) , Q . invertible ( X ) ) <EOL> assert ask ( Q . diagonal ( B ) , Q . diagonal ( X ) ) <EOL> assert ask ( Q . orthogonal ( B ) , Q . orthogonal ( X ) ) <EOL> assert ask ( Q . upper_triangular ( B ) , Q . upper_triangular ( X ) ) <EOL> assert not ask ( Q . symmetric ( C ) , Q . symmetric ( X ) ) <EOL> assert not ask ( Q . invertible ( C ) , Q . invertible ( X ) ) <EOL> assert not ask ( Q . diagonal ( C ) , Q . diagonal ( X ) ) <EOL> assert not ask ( Q . orthogonal ( C ) , Q . orthogonal ( X ) ) <EOL> assert not ask ( Q . upper_triangular ( C ) , Q . upper_triangular ( X ) ) <EOL> def test_det_trace_positive ( ) : <EOL> X = MatrixSymbol ( '<STR_LIT:X>' , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> assert ask ( Q . positive ( Trace ( X ) ) , Q . positive_definite ( X ) ) <EOL> assert ask ( Q . positive ( Determinant ( X ) ) , Q . positive_definite ( X ) ) <EOL> def test_field_assumptions ( ) : <EOL> X = MatrixSymbol ( '<STR_LIT:X>' , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> Y = MatrixSymbol ( '<STR_LIT:Y>' , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> assert ask ( Q . real_elements ( X ) , Q . real_elements ( X ) ) <EOL> assert not ask ( Q . integer_elements ( X ) , Q . real_elements ( X ) ) <EOL> assert ask ( Q . complex_elements ( X ) , Q . real_elements ( X ) ) <EOL> assert ask ( Q . real_elements ( X + Y ) , Q . real_elements ( X ) ) is None <EOL> assert ask ( Q . real_elements ( X + Y ) , Q . real_elements ( X ) & Q . real_elements ( Y ) ) <EOL> from sympy . matrices . expressions . hadamard import HadamardProduct <EOL> assert ask ( Q . real_elements ( HadamardProduct ( X , Y ) ) , <EOL> Q . real_elements ( X ) & Q . real_elements ( Y ) ) <EOL> assert ask ( Q . complex_elements ( X + Y ) , Q . real_elements ( X ) & Q . complex_elements ( Y ) ) <EOL> assert ask ( Q . real_elements ( X . T ) , Q . real_elements ( X ) ) <EOL> assert ask ( Q . real_elements ( X . I ) , Q . real_elements ( X ) & Q . invertible ( X ) ) <EOL> assert ask ( Q . real_elements ( Trace ( X ) ) , Q . real_elements ( X ) ) <EOL> assert ask ( Q . integer_elements ( Determinant ( X ) ) , Q . integer_elements ( X ) ) <EOL> assert not ask ( Q . integer_elements ( X . I ) , Q . integer_elements ( X ) ) <EOL> alpha = Symbol ( '<STR_LIT>' ) <EOL> assert ask ( Q . real_elements ( alpha * X ) , Q . real_elements ( X ) & Q . real ( alpha ) ) <EOL> assert ask ( Q . real_elements ( LofLU ( X ) ) , Q . real_elements ( X ) ) <EOL> def test_matrix_element_sets ( ) : <EOL> X = MatrixSymbol ( '<STR_LIT:X>' , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> assert ask ( Q . real ( X [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , Q . real_elements ( X ) ) <EOL> assert ask ( Q . integer ( X [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , Q . integer_elements ( X ) ) <EOL> assert ask ( Q . complex ( X [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , Q . complex_elements ( X ) ) <EOL> assert ask ( Q . integer_elements ( Identity ( <NUM_LIT:3> ) ) ) <EOL> assert ask ( Q . integer_elements ( ZeroMatrix ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> from sympy . matrices . expressions . fourier import DFT <EOL> assert ask ( Q . complex_elements ( DFT ( <NUM_LIT:3> ) ) ) <EOL> def test_matrix_element_sets_slices_blocks ( ) : <EOL> from sympy . matrices . expressions import BlockMatrix <EOL> X = MatrixSymbol ( '<STR_LIT:X>' , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> assert ask ( Q . integer_elements ( X [ : , <NUM_LIT:3> ] ) , Q . integer_elements ( X ) ) <EOL> assert ask ( Q . integer_elements ( BlockMatrix ( [ [ X ] , [ X ] ] ) ) , <EOL> Q . integer_elements ( X ) ) <EOL> def test_matrix_element_sets_determinant_trace ( ) : <EOL> assert ask ( Q . integer ( Determinant ( X ) ) , Q . integer_elements ( X ) ) <EOL> assert ask ( Q . integer ( Trace ( X ) ) , Q . integer_elements ( X ) ) </s>
