# buckingham 1.0

Massimo Di Pierro mdipierro at cs.depaul.edu
Mon Oct 18 02:11:22 CEST 2010

Dimensional Analysis / Formula Validation/ Units Conversion / Error Propagation
In one single small file without dependencies

buckingham.py

based on the Buckingham Theorem

How to use

start Python
import the module:
>>> from buckingham import Number, sin, cos, exp, log, allunits, pm
Example of dimensional analysis and conversions

>>> a = Number(10,dims='meter/second')
>>> b = Number(2,dims='yard/minute')
>>> c = a + b
>>> print c.convert('kilometer/hour')
(36.109728 ± 0)
>>> Number(1,dims='joule').convert('eV').value
6.2415096471204178e+18
>>> print c.value, c.error, c.units()
10.03048 0.0 meter*second^-1
Without conversion results are always in:

meters, seconds, grams, ampere, kelvin, currency (and combination)
The error is the standard deviation assuming the true value is Normal distributed

Error propagation assumes independence

>>> a = Number(1,dims='decimeter^3')
>>> b = Number(2,dims='liter')
>>> c = Number(5,dims='gram/centimeter^3')
>>> d = (a + b)*c
>>> print d.convert('kilogram')
(15.000000 ± 0)
Simplified syntax

>>> globals().update(allunits())
>>> length = (4+pm(0.5)) * meter
>>> velocity = 5 * meter/second
>>> time = length/velocity
>>> print time
(8.00 ± 1.00)/10
Example of formula validation

>>> a = Number(10,dims='meter/second')
>>> b = Number(2,dims='yard^3')
>>> c = a + b
Traceback (most recent call last):
...
RuntimeError: Incompatible Dimensions
Examples of error propagation

>>> a = Number(10,error=2,dims='meter/second') # (10±2)m/s
>>> b = Number(5,error=1,dims='hour')  # (5±1)h
>>> c = a*b
>>> print c.convert('kilometer')
(1.800 ± 0.509)x10^2
>>> print c.convert('lightyear')
(1.903 ± 0.538)/10^11
>>> print c.convert('kilometer').value
180.0
>>> print c.convert('kilometer').error
50.9116882454
Examples of more complex formulas

>>> c = a**4/(7*b)
>>> print '%s %s' % (c,c.units())
(7.94 ± 6.54)/10^2 meter^4*second^-5
For pure numbers sin, cos, exp, log are also defined. You can use a.is_pure() to check if a number is pure.
Financial application example

>>> coupon = Number(200,error=1,dims="dollar/day")
>>> expiration = Number(1,error=0,dims="year")
>>> payoff = coupon*expiration
>>> print payoff.convert('dollar')
(7.3048 ± 0.0365)x10^4
I.e. $73048 dollars with$365 dollars of one sigma uncertainly

Latex Output

>>> print payoff.as_latex()
(7.3048 \pm 0.0365)\times 10^{4}
Rouding

Notice the output as a string always uses scientific notation and value is automatically rounded compatibly with error/uncertainty in result.

Supported units and combination of