```python
import sympy as sp
sp.init_printing()
```


```python
a, b, c, w, x, y, z = sp.symbols("a b c w x y z")
```

a few amateurish experiments based on the paper "Teaching Quaternions is not Complex" by J. McDonald (http://dx.doi.org/10.1111/j.1467-8659.2010.01756.x)


```python
A = sp.Matrix([[a, 0], [0, a]])
A
```


```python
B = sp.Matrix([[b, 0], [0, b]])
B
```


```python
A + B
```


```python
A - B
```


```python
A * B
```


```python
# TODO: division?
```


```python
A**2
```


```python
A.inv()
```


```python
A.det()
```


```python
re = sp.Matrix([[1, 0], [0, 1]])
im = sp.Matrix([[0, -1], [1, 0]])
```


```python
im ** 2
```


```python
a * re + b * im
```


```python
theta = sp.symbols("theta")
theta
```


```python
n = sp.cos(theta) * re + sp.sin(theta) * im
n
```


```python
n * sp.Matrix([x, y])
```


```python
n * (x * re + y * im)
```

quaternions ...

Note: quaternions could also be represented as complex 2x2 matrices, see https://gitlab.com/certik/ijk/blob/master/mul.py.


```python
qw = sp.eye(4)
qw
```


```python
qi = sp.zeros(4, 4)
qi[0, 3] = qi[2, 1] = 1
qi[1, 2] = qi[3, 0] = -1
qi
```


```python
qj = sp.zeros(4, 4)
qj[0, 2] = qj[1, 3] = 1
qj[2, 0] = qj[3, 1] = -1
qj
```


```python
qk = sp.zeros(4, 4)
qk[1, 0] = qk[2, 3] = 1
qk[0, 1] = qk[3, 2] = -1
qk
```


```python
qi ** 2
```


```python
qj ** 2
```


```python
qk ** 2
```


```python
qi * qj == qk
```




    True




```python
qj * qk == qi
```




    True




```python
qk * qi == qj
```




    True




```python
qi**2 == qj**2 == qk**2 == -1 * qw
```




    True




```python
q = w * qw + x * qi + y * qj + z * qk
q
```


```python
q_conj = w * qw - x * qi - y * qj - z * qk
q_conj
```


```python
q.transpose() == q_conj
```




    True



<p xmlns:dct="http://purl.org/dc/terms/">
  <a rel="license"
     href="http://creativecommons.org/publicdomain/zero/1.0/">
    
  </a>
  <br />
  To the extent possible under law,
  <span rel="dct:publisher" resource="[_:publisher]">the person who associated CC0</span>
  with this work has waived all copyright and related or neighboring
  rights to this work.
</p>

f571a7cd1d2e958bd27bd402e35fe3c5317f54e1
ipynb
Jupyter Notebook
sympy/sympy_quaternions.ipynb
mgeier/python-audio
70d4d62b148c08c50ec0057f8d4fd9876ce67a13
CC0-1.0
2015-04-14T20:13:25.000Z
2022-03-26T20:00:27.000Z
sympy/sympy_quaternions.ipynb
mgeier/python-audio
70d4d62b148c08c50ec0057f8d4fd9876ce67a13
CC0-1.0
2017-05-02T13:22:41.000Z
2017-05-03T13:17:15.000Z
sympy/sympy_quaternions.ipynb
mgeier/python-audio
70d4d62b148c08c50ec0057f8d4fd9876ce67a13
CC0-1.0
2015-04-19T14:08:37.000Z
2021-04-21T14:24:37.000Z
Qwen/Qwen-72B
1. YES
2. YES