```python
from IPython.display import Image
from IPython.core.display import HTML 
Image(url= "https://i.imgur.com/NLtIf3P.png")
```









```python
# Start with a coordinate system
from sympy.vector import CoordSys3D, Del
delop = Del()
C = CoordSys3D('C')
```


```python
C
```




$\displaystyle CoordSys3D\left(C, \left( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \  \mathbf{\hat{0}}\right)\right)$




```python
delop
```




$\displaystyle Del\left(\right)$




```python
from sympy import symbols, Function
v1, v2, v3, f = symbols('v1 v2 v3 f', cls=Function)
```


```python
# Define the vector field as vfield and the scalar field as sfield.
vfield = v1(C.x, C.y, C.z)*C.i + v2(C.x, C.y, C.z)*C.j + v3(C.x, C.y, C.z)*C.k
ffield = f(C.x, C.y, C.z)
```


```python
vfield
```




$\displaystyle (\operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)})\mathbf{\hat{i}_{C}} + (\operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)})\mathbf{\hat{j}_{C}} + (\operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)})\mathbf{\hat{k}_{C}}$




```python
ffield
```




$\displaystyle f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)}$




```python
# Construct the expression for the LHS of the equation using Del()
lhs = (delop.dot(ffield * vfield)).doit()
```


```python
lhs
```




$\displaystyle f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{x}_{C}}} \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{y}_{C}}} \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{z}_{C}}} \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{x}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{y}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{z}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)}$




```python
# Similarly, the RHS would be defined.
rhs = ((vfield.dot(delop(ffield))) + (ffield * (delop.dot(vfield)))).doit()
```


```python
rhs
```




$\displaystyle \left(\frac{\partial}{\partial \mathbf{{x}_{C}}} \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \frac{\partial}{\partial \mathbf{{y}_{C}}} \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \frac{\partial}{\partial \mathbf{{z}_{C}}} \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)}\right) f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{x}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{y}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{z}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)}$




```python
# Now, to prove the product rule, we would just need to equate the expanded and simplified versions of the lhs and the rhs,
# so that the SymPy expressions match.
lhs.expand().simplify() == rhs.expand().doit().simplify()
```




    True




```python
lhs.expand().simplify()
```




$\displaystyle f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{x}_{C}}} \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{y}_{C}}} \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{z}_{C}}} \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{x}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{y}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{z}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)}$




```python
rhs.expand().doit().simplify()
```




$\displaystyle f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{x}_{C}}} \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{y}_{C}}} \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{z}_{C}}} \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{1}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{x}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{2}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{y}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} + \operatorname{v_{3}}{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)} \frac{\partial}{\partial \mathbf{{z}_{C}}} f{\left(\mathbf{{x}_{C}},\mathbf{{y}_{C}},\mathbf{{z}_{C}} \right)}$




```python
# Thus, the general form of the third product rule mentioned above can be proven using sympy.vector.

# source: https://docs.sympy.org/latest/modules/vector/examples.html
```

cb0a4e6782b05dd69cf953c419f0f053e8ab6dbc
ipynb
Jupyter Notebook
Personal_Projects/vector math calculus 2.ipynb
NSC9/Sample_of_Work
8f8160fbf0aa4fd514d4a5046668a194997aade6
MIT
Personal_Projects/vector math calculus 2.ipynb
NSC9/Sample_of_Work
8f8160fbf0aa4fd514d4a5046668a194997aade6
MIT
Personal_Projects/vector math calculus 2.ipynb
NSC9/Sample_of_Work
8f8160fbf0aa4fd514d4a5046668a194997aade6
MIT
Qwen/Qwen-72B
1. YES
2. YES