```python
from sympy import *
from calc import Symbol
init_printing()
```

## Simple Addition


```python
a = Symbol('a', val=1, err=0.01)
b = Symbol('b', val=2, err=0.01)
r1 = a + b
r1.simp()
r1.display(name="r1")
```


$\displaystyle 
        \begin{align*}
            \textbf{Numeric: } \\
                              r1 &= \ 3.00000000000000 \pm 0.0141421356237310 \\
            \textbf{Symbolic: }& \\
            \text{Value: } r1 &= a + b \\
                                  &= 3 \\
            \text{Error: } \sigma_{r1}&= \sqrt{\sigma_{a}^{2} + \sigma_{b}^{2}} \\
                                  &= 0.014142135623731 \\
        \end{align*}
            $


## Multiplication


```python
r1 = a * b
r1.simp()
r1.display(name="r1")
```


$\displaystyle 
        \begin{align*}
            \textbf{Numeric: } \\
                              r1 &= \ 2.00000000000000 \pm 0.0223606797749979 \\
            \textbf{Symbolic: }& \\
            \text{Value: } r1 &= a b \\
                                  &= 2 \\
            \text{Error: } \sigma_{r1}&= a b \sqrt{\frac{\sigma_{b}^{2}}{b^{2}} + \frac{\sigma_{a}^{2}}{a^{2}}} \\
                                  &= 0.0223606797749979 \\
        \end{align*}
            $


## Exponentiation


```python
r1 = a ** (1/2)
r1.simp()
r1.display(name="r1")
```


$\displaystyle 
        \begin{align*}
            \textbf{Numeric: } \\
                              r1 &= \ 1.00000000000000 \pm 0.00500000000000000 \\
            \textbf{Symbolic: }& \\
            \text{Value: } r1 &= \sqrt{a} \\
                                  &= 1 \\
            \text{Error: } \sigma_{r1}&= \frac{a \sigma_{a}}{2} \\
                                  &= 0.005 \\
        \end{align*}
            $


## Standard error of the mean


```python
mean, err = Symbol.std_err_of_mean(1.3, 1.5, 1.7)
mean, err
```

## Miscellaneous


```python
r1 = a / b + a
r1.simp()
r1.display(name="r1")
```


$\displaystyle 
        \begin{align*}
            \textbf{Numeric: } \\
                              r1 &= \ 1.50000000000000 \pm 0.0114564392373896 \\
            \textbf{Symbolic: }& \\
            \text{Value: } r1 &= a + \frac{a}{b} \\
                                  &= \frac{3}{2} \\
            \text{Error: } \sigma_{r1}&= \sqrt{\frac{a^{2} \sigma_{b}^{2}}{b^{4}} + \sigma_{a}^{2} + \frac{\sigma_{a}^{2}}{b^{2}}} \\
                                  &= 0.0114564392373896 \\
        \end{align*}
            $


## A more complex example


```python
U1 = Symbol('U_1', val=0.888, err=0.007)
U2 = Symbol('U_2', val=0.203, err=0.002)
V = Symbol('V', val=5.637, err=0.001)

C1 = (U1 - (U1**2 - 4*U1*U2)**0.5) / (V**2)
C2 = (U1 + (U1**2 - 4*U1*U2)**0.5) / (V**2)

C1.simp()
C2.simp()
```


```python
C1.display(name="C_1")
C2.display(name="C_2")
```


$\displaystyle 
        \begin{align*}
            \textbf{Numeric: } \\
                              C_1 &= \ 0.0197702681531304 \pm 0.000221011614823886 \\
            \textbf{Symbolic: }& \\
            \text{Value: } C_1 &= \frac{U_{1} - \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}}{V^{2}} \\
                                  &= 0.0197702681531304 \\
            \text{Error: } \sigma_{C_1}&= \frac{\sqrt{\frac{V^{2} \left(U_{1}^{2} \left(U_{1} - 4 U_{2}\right)^{2} \left(U_{1}^{2} \sigma_{U 1}^{2} + 4 U_{1}^{2} \sigma_{U 2}^{2} + 4 U_{2}^{2} \sigma_{U 1}^{2}\right) + \sigma_{U 1}^{2}\right) + 4 \sigma_{V}^{2} \left(U_{1} - \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}\right)^{2}}{V^{2} \left(U_{1} - \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}\right)^{2}}} \left(U_{1} - \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}\right)}{V^{2}} \\
                                  &= 0.000221011614823886 \\
        \end{align*}
            $



$\displaystyle 
        \begin{align*}
            \textbf{Numeric: } \\
                              C_2 &= \ 0.0361213768295607 \pm 0.000221271725056850 \\
            \textbf{Symbolic: }& \\
            \text{Value: } C_2 &= \frac{U_{1} + \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}}{V^{2}} \\
                                  &= 0.0361213768295607 \\
            \text{Error: } \sigma_{C_2}&= \frac{\sqrt{\frac{V^{2} \left(U_{1}^{2} \left(U_{1} - 4 U_{2}\right)^{2} \left(U_{1}^{2} \sigma_{U 1}^{2} + 4 U_{1}^{2} \sigma_{U 2}^{2} + 4 U_{2}^{2} \sigma_{U 1}^{2}\right) + \sigma_{U 1}^{2}\right) + 4 \sigma_{V}^{2} \left(U_{1} + \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}\right)^{2}}{V^{2} \left(U_{1} + \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}\right)^{2}}} \left(U_{1} + \sqrt{U_{1} \left(U_{1} - 4 U_{2}\right)}\right)}{V^{2}} \\
                                  &= 0.00022127172505685 \\
        \end{align*}
            $



```python

```

ba7b4a88ad8264032193f37ab0069cf4a1bf9aa7
ipynb
Jupyter Notebook
example.ipynb
hanzhi713/uncertainty
2d301f53242e5a94b61f589e8c0fdef8c9bb055d
MIT
example.ipynb
hanzhi713/uncertainty
2d301f53242e5a94b61f589e8c0fdef8c9bb055d
MIT
example.ipynb
hanzhi713/uncertainty
2d301f53242e5a94b61f589e8c0fdef8c9bb055d
MIT
Qwen/Qwen-72B
1. YES
2. YES