UncValue library released

Sep 8, 2020 • Adrià Labay

Language: en library python julia math

Today, together with Àlex Giménez Romero we have released the UncValue library for Python and Julia. This library allows to initialize a number with an uncertainty and propagate that uncertainty under all the operations performed.

For instance, imagine you measured a rectangular table whose sides measure 1.5m and 80cm with ruler with precision up to 1mm. Then, you can initialize the Value as

  • Python:
    from uncvalue import Value
    L1 = Value(1.5, 1e-3)
    L2 = Value(0.8, 1e-3)
    
  • Julia:
    using UncValue
    L1 = Value(1.5, 1e-3)
    L2 = Value(0.8, 1e-3)
    

You now want to calculate the area of the table, so you multiply both lengths

  • Python:
    A = L1 * L2
    print(A)
    
  • Julia:
    A = L1 * L2
    println(A)
    

    and obtain as outcome (1200.0 ± 1.7)·10^-3.

Of course, it is possible to perform more complex operations like

  • Python (numpy required, functions from python math will only compute the value)
    import numpy as np
    print(L1 ** L2)  # power -> (13831.6 ± 9.3)·10^-4
    print(np.sin(L1))  # sinus -> (99749.5 ± 7.1)·10^-5
    print(np.exp(L2))  # exponential -> (2225.5 ± 2.2)·10^-3
    
  • Julia
    println(L1^L2)  # power -> (13831.6 ± 9.3)·10^-4
    println(sin(L1))  # sinus -> (99749.5 ± 7.1)·10^-5
    println(exp(L2))  # exponential -> (2225.5 ± 2.2)·10^-3
    

For more information visit the original repositories: