Write a package that defines a function $\operatorname{diff}[\operatorname{expr}$, var $]$ to differentiate expressions symbolically.
The derivative of an arithmetic expression $U$ with respect to $x$, $\left(\frac{d U}{d x}\right)$, is defined recursively by differentiation rules that are applied to $U$. From a handbook, we take the following rules ( $U$ and $V$ are arbitrary arithmetic expressions, and $c$ is a constant):
$$
\begin{array}{ll}
\frac{d c}{d x} & \rightarrow 0 \\
\frac{d x}{d x} & \rightarrow 1 \\
\frac{d-U}{d x} & \rightarrow-\frac{d U}{d x} \\
\frac{d U+V}{d x} & \rightarrow \frac{d U}{d x}+\frac{d V}{d x} \\
\frac{d U V}{d x} & \rightarrow \frac{d U}{d x} V+U \frac{d V}{d x} \\
\frac{d U^c}{d x} & \rightarrow c U^{c-1} \frac{d U}{d x} \\
\frac{d \exp (U)}{d x} & \rightarrow \exp (U) \frac{d U}{d x} \\
\frac{d \ln (U)}{d x} & \rightarrow \frac{1}{U} \frac{d U}{d x} \\
\frac{d U^V}{d x} & \rightarrow U^V \frac{d V \ln (U)}{d x}
\end{array}
$$
1. Write these rules as definitions for $\operatorname{diff}[]$. Not all of these rules are strictly necessary. Which ones are sufficient to differentiate all the functions given?
2. These definitions can be augmented by rules for special functions, such as sine, cosine, and so on. The function diff [] becomes more powerful in this way. Implement a few of these rules.