```python
import numpy as np 
import math 
from sympy import *
```
General formula for computing error: 
error^2 = sum of [(partial derivative of f in respect to var)^2*(error of var)^2 for each var]
# Derivation of error for basic operators


```python
a,b, a_error, b_error = symbols ('a b a_error b_error')
```


```python
print("sum")
expr_sum = a+b
error_sum = sqrt(diff(expr_sum, a)**2 * a_error**2 + diff(expr_sum, b)**2 * b_error**2)
error_sum
```

    sum





$\displaystyle \sqrt{a_{error}^{2} + b_{error}^{2}}$




```python
print("subtraction")
expr_subtraction = a-b
error_subtraction = sqrt(diff(expr_subtraction, a)**2 * a_error**2 + diff(expr_subtraction, b)**2 * b_error**2)
error_subtraction
```

    subtraction





$\displaystyle \sqrt{a_{error}^{2} + b_{error}^{2}}$




```python
print("multiplication")
expr_multiplication = a*b
error_multiplication = sqrt(diff(expr_multiplication, a)**2 * a_error**2 + diff(expr_multiplication, b)**2 * b_error**2)
error_multiplication
```

    multiplication





$\displaystyle \sqrt{a^{2} b_{error}^{2} + a_{error}^{2} b^{2}}$




```python
print("division")
expr_division = a/b
error_division = sqrt(diff(expr_division, a)**2 * a_error**2 + diff(expr_division, b)**2 * b_error**2)
error_division
```

    division





$\displaystyle \sqrt{\frac{a^{2} b_{error}^{2}}{b^{4}} + \frac{a_{error}^{2}}{b^{2}}}$




```python
print("power")
expr_power = a**b
error_power = sqrt(diff(expr_power, a)**2 * a_error**2 + diff(expr_power, b)**2 * b_error**2)
error_power
```

    power





$\displaystyle \sqrt{a^{2 b} b_{error}^{2} \log{\left(a \right)}^{2} + \frac{a^{2 b} a_{error}^{2} b^{2}}{a^{2}}}$




```python
print("log")
expr_log = log(a,b)
error_log = sqrt(diff(expr_log, a)**2 * a_error**2 + diff(expr_log, b)**2 * b_error**2)
error_log
```

    log





$\displaystyle \sqrt{\frac{b_{error}^{2} \log{\left(a \right)}^{2}}{b^{2} \log{\left(b \right)}^{4}} + \frac{a_{error}^{2}}{a^{2} \log{\left(b \right)}^{2}}}$




```python
print("sin")
expr_sin = sin(a)
error_sin = sqrt(diff(expr_sin, a)**2 * a_error**2)
error_sin
```

    sin





$\displaystyle \sqrt{a_{error}^{2} \cos^{2}{\left(a \right)}}$




```python
print("cos")
expr_cos = cos(a)
error_cos = sqrt(diff(expr_cos, a)**2 * a_error**2)
error_cos
```

    cos





$\displaystyle \sqrt{a_{error}^{2} \sin^{2}{\left(a \right)}}$




```python
print("tan")
expr_tan = tan(a)
error_tan = sqrt(diff(expr_tan, a)**2 * a_error**2)
error_tan
```

    tan





$\displaystyle \sqrt{a_{error}^{2} \left(\tan^{2}{\left(a \right)} + 1\right)^{2}}$



# Derivation of more complex formulas


```python
print("acos")
exp = acos(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    acos





$\displaystyle \sqrt{\frac{a_{error}^{2}}{1 - a^{2}}}$




```python
print("acosh")
exp = acosh(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    acosh





$\displaystyle \sqrt{\frac{a_{error}^{2}}{a^{2} - 1}}$




```python
print("acot")
exp = acot(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    acot





$\displaystyle \sqrt{\frac{a_{error}^{2}}{\left(a^{2} + 1\right)^{2}}}$




```python
print("acoth")
exp = acoth(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    acoth





$\displaystyle \sqrt{\frac{a_{error}^{2}}{\left(1 - a^{2}\right)^{2}}}$




```python
print("asin")
exp = asin(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    asin





$\displaystyle \sqrt{\frac{a_{error}^{2}}{1 - a^{2}}}$




```python
print("asin")
exp = asinh(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    asin





$\displaystyle \sqrt{\frac{a_{error}^{2}}{a^{2} + 1}}$




```python
print("atan")
exp = atan(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    atan





$\displaystyle \sqrt{\frac{a_{error}^{2}}{\left(a^{2} + 1\right)^{2}}}$




```python
print("atanh")
exp = atanh(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    atanh





$\displaystyle \sqrt{\frac{a_{error}^{2}}{\left(1 - a^{2}\right)^{2}}}$




```python
print("cosh")
exp = cosh(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    cosh





$\displaystyle \sqrt{a_{error}^{2} \sinh^{2}{\left(a \right)}}$




```python
print("cot")
exp = cot(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    cot





$\displaystyle \sqrt{a_{error}^{2} \left(- \cot^{2}{\left(a \right)} - 1\right)^{2}}$




```python
print("coth")
exp = coth(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    coth





$\displaystyle \sqrt{\frac{a_{error}^{2}}{\sinh^{4}{\left(a \right)}}}$




```python
print("csc")
exp = csc(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    csc





$\displaystyle \sqrt{a_{error}^{2} \cot^{2}{\left(a \right)} \csc^{2}{\left(a \right)}}$




```python
print("csch")
exp = csch(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    csch





$\displaystyle \sqrt{a_{error}^{2} \coth^{2}{\left(a \right)} \operatorname{csch}^{2}{\left(a \right)}}$




```python
print("factorial")
exp = factorial(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    factorial





$\displaystyle \sqrt{a_{error}^{2} \Gamma^{2}\left(a + 1\right) \operatorname{polygamma}^{2}{\left(0,a + 1 \right)}}$




```python
print("sec")
exp = sec(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    sec





$\displaystyle \sqrt{a_{error}^{2} \tan^{2}{\left(a \right)} \sec^{2}{\left(a \right)}}$




```python
print("sec")
exp = sech(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    sec





$\displaystyle \sqrt{a_{error}^{2} \tanh^{2}{\left(a \right)} \operatorname{sech}^{2}{\left(a \right)}}$




```python
print("sinh")
exp = sinh(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    sinh





$\displaystyle \sqrt{a_{error}^{2} \cosh^{2}{\left(a \right)}}$




```python
print("tanh")
exp = tanh(a)
error = sqrt(diff(exp, a)**2 * a_error**2)
error
```

    tanh





$\displaystyle \sqrt{a_{error}^{2} \left(1 - \tanh^{2}{\left(a \right)}\right)^{2}}$




```python

```


```python

```

# Creating functions


```python
def sum_error(a, b, a_error, b_error):
    return np.sqrt(a_error**2 + b_error**2)

def subtraction_error(a, b, a_error, b_error):
    return sum_error(a, b, a_error, b_error)

def multiplication_error(a, b, a_error, b_error):
    return np.sqrt((a**2 * b_error**2) + (b**2 * a_error **2))

def division_error(a, b, a_error, b_error):
    return np.sqrt(((a**2 * b_error**2)/ (b**4)) + (a_error**2/b**2))

def power_error(a, b, a_error, b_error):
    return np.sqrt((a**(2*b) * b_error**2 * np.log(a)**2) + ((a**(2*b) * a_error**2 * b**2)/a**2))

def log_error(a, b, a_error, b_error):
    return np.sqrt((b_error**2 * np.log(a)**2)/(b**2 * np.log(b)**4) + a_error**2/(a**2 * np.log(b)**2))

def sin_error(a, b, a_error, b_error):
    return np.sqrt(a_error**2 * np.cos(a)**2)

def cos_error(a, b, a_error, b_error):
    return np.sqrt(a_error**2 * np.sin(a)**2)

def tan_error(a, b, a_error, b_error):
    return np.sqrt(a_error**2 * (np.tan(a)**2 + 1)**2)
```

# Testing of error formulas for basic operators


```python
values = {a: 10, a_error:5, b:8, b_error:3}
```

Derived errors


```python
print("sum =", error_sum.evalf(subs=values))
print("subtraction =", error_subtraction.evalf(subs=values))
print("multiplication =", error_multiplication.evalf(subs=values))
print("division =", error_division.evalf(subs=values))
print("power =", error_power.evalf(subs=values))
print("log =", error_log.evalf(subs=values))
print("sin =", error_sin.evalf(subs=values))
print("cos =", error_cos.evalf(subs=values))
print("tan =", error_tan.evalf(subs=values))
```

    sum = 5.83095189484530
    subtraction = 5.83095189484530
    multiplication = 50.0000000000000
    division = 0.781250000000000
    power = 798229810.232026
    log = 0.312556216389312
    sin = 4.19535764538226
    cos = 2.72010555444685
    tan = 7.10185881291716


Errors from functions


```python
a = 10
b = 8
a_error = 5
b_error = 3
```


```python
print("sum =", sum_error(a, b, a_error, b_error))
print("subtraction =", subtraction_error(a, b, a_error, b_error))
print("multiplication =", multiplication_error(a, b, a_error, b_error))
print("division =", division_error(a, b, a_error, b_error))
print("power =", power_error(a, b, a_error, b_error))
print("log =", log_error(a, b, a_error, b_error))
print("sin =", sin_error(a, b, a_error, b_error))
print("cos =", cos_error(a, b, a_error, b_error))
print("tan =", tan_error(a, b, a_error, b_error))
```

    sum = 5.830951894845301
    subtraction = 5.830951894845301
    multiplication = 50.0
    division = 0.78125
    power = 798229810.2320257
    log = 0.3125562163893125
    sin = 4.195357645382262
    cos = 2.7201055544468495
    tan = 7.101858812917159



```python

```

e71e84036cfaa21553770395f28f2fc753d88f7a
ipynb
Jupyter Notebook
docs/derivations.ipynb
davidreissmello/error_propagation
ce6600498dabfcf494243edd3a40557dbe8dc709
MIT
2021-09-14T02:21:06.000Z
2021-11-11T15:33:08.000Z
docs/derivations.ipynb
davidreissmello/error_propagation
ce6600498dabfcf494243edd3a40557dbe8dc709
MIT
docs/derivations.ipynb
davidreissmello/error_propagation
ce6600498dabfcf494243edd3a40557dbe8dc709
MIT
Qwen/Qwen-72B
1. YES
2. YES