```python
%pylab inline
from sympy import symbols, Matrix
from sympy.parsing.sympy_parser import parse_expr
```

    Populating the interactive namespace from numpy and matplotlib



```python
expr = parse_expr("x*y")
expr
```




    x*y




```python
type(expr)
```




    sympy.core.mul.Mul




```python
type(parse_expr("Matrix([[1,2],[3,4]]) * t"))
```




    sympy.matrices.dense.MutableDenseMatrix




```python
type(parse_expr("cos(x)"))
```




    cos




```python
type(parse_expr("Eq(10,a)"))
```




    sympy.core.relational.Equality




```python
type(parse_expr("10>a"))
```




    sympy.core.relational.StrictGreaterThan




```python
type(parse_expr("10>=a"))
```




    sympy.core.relational.GreaterThan




```python
type(parse_expr("10<a"))
```




    sympy.core.relational.StrictLessThan




```python
type(parse_expr("10<=a"))
```




    sympy.core.relational.LessThan




```python
type(parse_expr("Eq(x^2 + x, x)"))
```




    sympy.core.relational.Equality




```python
type(parse_expr("10!"))
```




    sympy.core.numbers.Integer




```python
type(parse_expr("2*pi"))
```




    sympy.core.mul.Mul




```python
type(parse_expr("1/4"))
```




    sympy.core.numbers.Rational




```python
type(parse_expr("2.11"))
```




    sympy.core.numbers.Float




```python
def detect(expr):
    return {
        'is_constant':   'Integer' in str(type(expr)) 
                      or 'Float' in str(type(expr))
                      or 'Rational' in str(type(expr)),
        'is_equality':   'Equality' in str(type(expr)),
        'is_inequality': 'Inequality' in str(type(expr)) 
                      or 'Greater' in str(type(expr)) 
                      or 'Less' in str(type(expr)),
        'is_matrix':     'Matrix' in str(type(expr)),
        'dimension':     list(expr.shape) if 'Matrix' in str(type(expr)) else [0, 0]
    }
```


```python
detect(parse_expr('10!'))
```




    {'is_constant': True,
     'is_equality': False,
     'is_inequality': False,
     'is_matrix': False,
     'dimension': [0, 0]}




```python
L = ['Matrix([[1,2],[3,4]]) * t', '10>a', '10<a', '2.11', 'Eq(x^2 + x, x)']
for e in L:
    print(e)
    print(detect(parse_expr(e)))
    print()
```

    Matrix([[1,2],[3,4]]) * t
    {'is_constant': False, 'is_equality': False, 'is_inequality': False, 'is_matrix': True, 'dimension': [2, 2]}
    
    10>a
    {'is_constant': False, 'is_equality': False, 'is_inequality': True, 'is_matrix': False, 'dimension': [0, 0]}
    
    10<a
    {'is_constant': False, 'is_equality': False, 'is_inequality': True, 'is_matrix': False, 'dimension': [0, 0]}
    
    2.11
    {'is_constant': True, 'is_equality': False, 'is_inequality': False, 'is_matrix': False, 'dimension': [0, 0]}
    
    Eq(x^2 + x, x)
    {'is_constant': False, 'is_equality': True, 'is_inequality': False, 'is_matrix': False, 'dimension': [0, 0]}
    



```python
M = Matrix([[1,2],[3,4]])
N = Matrix([1,2,3,4])
O = Matrix([[1],[2],[3]])
P = Matrix([[1,2],[3,4],[5,6]])
M, N, O, P
```




    (Matrix([
     [1, 2],
     [3, 4]]), Matrix([
     [1],
     [2],
     [3],
     [4]]), Matrix([
     [1],
     [2],
     [3]]), Matrix([
     [1, 2],
     [3, 4],
     [5, 6]]))




```python
M.det() # requires a square matrix
```




    -2




```python
M.inv() # requires a square matrix
```




    Matrix([
    [ -2,    1],
    [3/2, -1/2]])




```python
M.QRdecomposition(), N.QRdecomposition(), O.QRdecomposition(), P.QRdecomposition()
```




    ((Matrix([
      [  sqrt(10)/10, 3*sqrt(10)/10],
      [3*sqrt(10)/10,  -sqrt(10)/10]]), Matrix([
      [sqrt(10), 7*sqrt(10)/5],
      [       0,   sqrt(10)/5]])), (Matrix([
      [  sqrt(30)/30],
      [  sqrt(30)/15],
      [  sqrt(30)/10],
      [2*sqrt(30)/15]]), Matrix([[sqrt(30)]])), (Matrix([
      [  sqrt(14)/14],
      [   sqrt(14)/7],
      [3*sqrt(14)/14]]), Matrix([[sqrt(14)]])), (Matrix([
      [  sqrt(35)/35, 13*sqrt(210)/210],
      [3*sqrt(35)/35,  2*sqrt(210)/105],
      [   sqrt(35)/7,    -sqrt(210)/42]]), Matrix([
      [sqrt(35), 44*sqrt(35)/35],
      [       0, 2*sqrt(210)/35]])))




```python
Q, R = M.QRdecomposition()
Q * R
```




    Matrix([
    [1, 2],
    [3, 4]])




```python
Q.T, P.T
```




    (Matrix([
     [  sqrt(10)/10, 3*sqrt(10)/10],
     [3*sqrt(10)/10,  -sqrt(10)/10]]), Matrix([
     [1, 3, 5],
     [2, 4, 6]]))




```python
Q.eigenvals() # requires square matrix
```




    {-1: 1, 1: 1}




```python
Q.eigenvects() # requires square matrix
```




    [(-1, 1, [Matrix([
       [-3*sqrt(10)/(10*(sqrt(10)/10 + 1))],
       [                                 1]])]), (1, 1, [Matrix([
       [-3*sqrt(10)/(10*(-1 + sqrt(10)/10))],
       [                                  1]])])]




```python
def splat(*s): return [a for a in s]
[v[2][0][0] for v in Q.eigenvects()]
```




    [-3*sqrt(10)/(10*(sqrt(10)/10 + 1)), -3*sqrt(10)/(10*(-1 + sqrt(10)/10))]




```python

```

63652d1dfa0b037b39649428295be856f119fd33
ipynb
Jupyter Notebook
Calcupy/expression detection.ipynb
darkeclipz/jupyter-notebooks
5de784244ad9db12cfacbbec3053b11f10456d7e
Unlicense
2018-08-28T12:16:12.000Z
2018-08-28T12:16:12.000Z
Calcupy/expression detection.ipynb
darkeclipz/jupyter-notebooks
5de784244ad9db12cfacbbec3053b11f10456d7e
Unlicense
Calcupy/expression detection.ipynb
darkeclipz/jupyter-notebooks
5de784244ad9db12cfacbbec3053b11f10456d7e
Unlicense
Qwen/Qwen-72B
1. YES
2. YES