Automatically propagate the error in an expression symbolically
Project description
Automatic Error Propagation
When there are uncertainties in physics, you might need to deal with error propagation, which gets really annoying really really fast as the equation gets longer, especially if you need to write down the expression using variables for a school test or something. This package automates the process of propagating the error.
Installation
$ pip install errorpp
Function and Scope
As this is still being developed, the error propagation only supports expanding addition, multiplication, division and power of a real number. If you input anything else such as sin(x)
, it will throw an error. If you want see more functions implemented, open an issue, or better yet, make a pull request!
Usage
In its core, it uses sympy
to process the expression. the errorpp.propagate
function will take a sympy
expression as the argument return the sympy
expression with the error propagated. If your variables are all positive, you can pass in absolute=False
to prevent the program from wrapping variables in absolute signs, which makes a cleaner output as sympy
can cancel variables more easily.
You can also use the counterpart errorpp.propagate_latex
which takes a string of latex expression as the argument and output the latex expression with the error propagated.
Alternatively, you directly call this module from the terminal, which takes an latex equation as its first argument and print the latex expression with the error propagated to standard output. Use --no-absolute
to prevent the program from wrapping variables in absolute sign.
Since the code base is quite small, I won't make a website with the documentation, but instead I will write the explanation in the docstring in the source code.
Code Example
You can use this directly in terminal
$ errorpp '\\frac{- c_{w} m_{1} \\left(- T_{1} + T_{f}\\right) + c_{w} m_{2} \\left(T_{2} - T_{f}\\right)}{- T_{1} + T_{f}}' --no-absolute
# output
# \frac{\sqrt{\frac{c_{w}^{2} m_{1}^{2} \left(- T_{1} + T_{f}\right)^{2} \left(\frac{\Delta^{2}{\left(T_{1} \right)} + \Delta^{2}{\left(T_{f} \right)}}{\left(- T_{1} + T_{f}\right)^{2}} + \frac{\Delta^{2}{\left(m_{1} \right)}}{m_{1}^{2}} + \frac{\Delta^{2}{\left(c_{w} \right)}}{c_{w}^{2}}\right) + c_{w}^{2} m_{2}^{2} \left(T_{2} - T_{f}\right)^{2} \left(\frac{\Delta^{2}{\left(T_{2} \right)} + \Delta^{2}{\left(T_{f} \right)}}{\left(T_{2} - T_{f}\right)^{2}} + \frac{\Delta^{2}{\left(m_{2} \right)}}{m_{2}^{2}} + \frac{\Delta^{2}{\left(c_{w} \right)}}{c_{w}^{2}}\right)}{\left(- c_{w} m_{1} \left(- T_{1} + T_{f}\right) + c_{w} m_{2} \left(T_{2} - T_{f}\right)\right)^{2}} + \frac{\Delta^{2}{\left(T_{1} \right)} + \Delta^{2}{\left(T_{f} \right)}}{\left(- T_{1} + T_{f}\right)^{2}}} \left(- c_{w} m_{1} \left(- T_{1} + T_{f}\right) + c_{w} m_{2} \left(T_{2} - T_{f}\right)\right)}{- T_{1} + T_{f}}
Or import this as a module
import errorpp
import sympy
eq = sympy.parse_latex('\\frac{- c_{w} m_{1} \\left(- T_{1} + T_{f}\\right) + c_{w} m_{2} \\left(T_{2} - T_{f}\\right)}{- T_{1} + T_{f}}')
p = errorpp.propagate(eq, absolute=False)
print(pretty(eq, use_unicode=False))
# Output
# _____________________________________________________________________
# / / 2 2 2
# / 2 2 2 |Delta (T_1) + Delta (T_f) Delta (m_1) D
# / c_w *m_1 *(-T_1 + T_f) *|------------------------- + ----------- + -
# / | 2 2
# / \ (-T_1 + T_f) m_1
# / --------------------------------------------------------------------
# /
# \/ (-c_w*m_1*(
# ------------------------------------------------------------------------------
#
#
# ______________________________________________________________________________
# 2 \ / 2 2 2
# elta (c_w)| 2 2 2 |Delta (T_2) + Delta (T_f) Delta (m_2)
# ----------| + c_w *m_2 *(T_2 - T_f) *|------------------------- + -----------
# 2 | | 2 2
# c_w / \ (T_2 - T_f) m_2
# ------------------------------------------------------------------------------
# 2
# -T_1 + T_f) + c_w*m_2*(T_2 - T_f))
# ------------------------------------------------------------------------------
# -T_1 + T_f
#
# ___________________________________________
# 2 \
# Delta (c_w)|
# + -----------|
# 2 | 2 2
# c_w / Delta (T_1) + Delta (T_f)
# -------------- + ------------------------- *(-c_w*m_1*(-T_1 + T_f) + c_w*m_2*(
# 2
# (-T_1 + T_f)
# ------------------------------------------------------------------------------
#
#
#
#
#
#
#
#
# T_2 - T_f))
#
#
# -----------
#
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file errorpp-0.0.7.tar.gz
.
File metadata
- Download URL: errorpp-0.0.7.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5828847af530c7a7885a65789e375a44869486c86c07cd84849c2433fb72ea7d |
|
MD5 | bc6a0e2697cbb71ba7e285ff3ef49f9b |
|
BLAKE2b-256 | 2186407398ceece642765a0592c8786b3753c51aa6806a6da4c038e355779598 |
File details
Details for the file errorpp-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: errorpp-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74fecf8db2af9bbc567e63eb7fcd2f181b29ffaa1a81b01c0999f16d04797b23 |
|
MD5 | 2b8c36bb87987c3fc890675f476010c7 |
|
BLAKE2b-256 | 2d90f4dfc4e2052f08012eab2b3725d475078a6b5e388f65321a4809f10661f6 |