```
from sympy import *
```


```
a1, a2, a3, a4, a5, a6, a7, a8, a9 = symbols('a1 a2 a3 a4 a5 a6 a7 a8 a9')
b1, b2, b3, b4, b5, b6, b7, b8, b9 = symbols('b1 b2 b3 b4 b5 b6 b7 b8 b9')
```


```
a1+a2
```




$\displaystyle a_{1} + a_{2}$




```
A = Matrix([[a1, a2, a3], [a4, a5, a6], [a7, a8, a9]])
B = Matrix([[b1, b2, b3], [b4, b5, b6], [b7, b8, b9]])
```


```
A
```




$\displaystyle \left[\begin{matrix}a_{1} & a_{2} & a_{3}\\a_{4} & a_{5} & a_{6}\\a_{7} & a_{8} & a_{9}\end{matrix}\right]$




```
B
```




$\displaystyle \left[\begin{matrix}b_{1} & b_{2} & b_{3}\\b_{4} & b_{5} & b_{6}\\b_{7} & b_{8} & b_{9}\end{matrix}\right]$




```
A+B
```




$\displaystyle \left[\begin{matrix}a_{1} + b_{1} & a_{2} + b_{2} & a_{3} + b_{3}\\a_{4} + b_{4} & a_{5} + b_{5} & a_{6} + b_{6}\\a_{7} + b_{7} & a_{8} + b_{8} & a_{9} + b_{9}\end{matrix}\right]$




```
(A+B).det()
```




$\displaystyle a_{1} a_{5} a_{9} + a_{1} a_{5} b_{9} - a_{1} a_{6} a_{8} - a_{1} a_{6} b_{8} - a_{1} a_{8} b_{6} + a_{1} a_{9} b_{5} + a_{1} b_{5} b_{9} - a_{1} b_{6} b_{8} - a_{2} a_{4} a_{9} - a_{2} a_{4} b_{9} + a_{2} a_{6} a_{7} + a_{2} a_{6} b_{7} + a_{2} a_{7} b_{6} - a_{2} a_{9} b_{4} - a_{2} b_{4} b_{9} + a_{2} b_{6} b_{7} + a_{3} a_{4} a_{8} + a_{3} a_{4} b_{8} - a_{3} a_{5} a_{7} - a_{3} a_{5} b_{7} - a_{3} a_{7} b_{5} + a_{3} a_{8} b_{4} + a_{3} b_{4} b_{8} - a_{3} b_{5} b_{7} + a_{4} a_{8} b_{3} - a_{4} a_{9} b_{2} - a_{4} b_{2} b_{9} + a_{4} b_{3} b_{8} - a_{5} a_{7} b_{3} + a_{5} a_{9} b_{1} + a_{5} b_{1} b_{9} - a_{5} b_{3} b_{7} + a_{6} a_{7} b_{2} - a_{6} a_{8} b_{1} - a_{6} b_{1} b_{8} + a_{6} b_{2} b_{7} + a_{7} b_{2} b_{6} - a_{7} b_{3} b_{5} - a_{8} b_{1} b_{6} + a_{8} b_{3} b_{4} + a_{9} b_{1} b_{5} - a_{9} b_{2} b_{4} + b_{1} b_{5} b_{9} - b_{1} b_{6} b_{8} - b_{2} b_{4} b_{9} + b_{2} b_{6} b_{7} + b_{3} b_{4} b_{8} - b_{3} b_{5} b_{7}$




```
simplify(A.det() +
         B.det() + 
         A.det()*(A.inv()*B).trace() +
         B.det()*(B.inv()*A).trace()
         )
```




$\displaystyle a_{1} a_{5} a_{9} - a_{1} a_{6} a_{8} + a_{1} \left(b_{5} b_{9} - b_{6} b_{8}\right) - a_{2} a_{4} a_{9} + a_{2} a_{6} a_{7} - a_{2} \left(b_{4} b_{9} - b_{6} b_{7}\right) + a_{3} a_{4} a_{8} - a_{3} a_{5} a_{7} + a_{3} \left(b_{4} b_{8} - b_{5} b_{7}\right) - a_{4} \left(b_{2} b_{9} - b_{3} b_{8}\right) + a_{5} \left(b_{1} b_{9} - b_{3} b_{7}\right) - a_{6} \left(b_{1} b_{8} - b_{2} b_{7}\right) + a_{7} \left(b_{2} b_{6} - b_{3} b_{5}\right) - a_{8} \left(b_{1} b_{6} - b_{3} b_{4}\right) + a_{9} \left(b_{1} b_{5} - b_{2} b_{4}\right) + b_{1} b_{5} b_{9} - b_{1} b_{6} b_{8} + b_{1} \left(a_{5} a_{9} - a_{6} a_{8}\right) - b_{2} b_{4} b_{9} + b_{2} b_{6} b_{7} - b_{2} \left(a_{4} a_{9} - a_{6} a_{7}\right) + b_{3} b_{4} b_{8} - b_{3} b_{5} b_{7} + b_{3} \left(a_{4} a_{8} - a_{5} a_{7}\right) - b_{4} \left(a_{2} a_{9} - a_{3} a_{8}\right) + b_{5} \left(a_{1} a_{9} - a_{3} a_{7}\right) - b_{6} \left(a_{1} a_{8} - a_{2} a_{7}\right) + b_{7} \left(a_{2} a_{6} - a_{3} a_{5}\right) - b_{8} \left(a_{1} a_{6} - a_{3} a_{4}\right) + b_{9} \left(a_{1} a_{5} - a_{2} a_{4}\right)$




```
simplify(A.det() +
         B.det() + 
         A.det()*(A.inv()*B).trace() +
         B.det()*(B.inv()*A).trace() -
         (A+B).det()
         )
```




$\displaystyle 0$




```

```

8ce3b570d03cb49b7ead345acddf1256df67cd59
ipynb
Jupyter Notebook
lab2/sympy.ipynb
ArcaneStudent/stereolabs
730c64bd3b71809cf0dd36c69748bdf032e5265a
MIT
lab2/sympy.ipynb
ArcaneStudent/stereolabs
730c64bd3b71809cf0dd36c69748bdf032e5265a
MIT
lab2/sympy.ipynb
ArcaneStudent/stereolabs
730c64bd3b71809cf0dd36c69748bdf032e5265a
MIT
Qwen/Qwen-72B
1. YES
2. YES