using Measurements

d(a_in, a_out) = (1 - a_in*a_in) / (1 - a_in*a_out) * a_out - a_in
d̃(a_in, a_out) = a_out - a_in

# Au(111)
# a_in, a_out...

# a = [ 0.0   -0.31
#      -0.22  -0.35
#       0.22  -0.29 ]

# σ = [ 0.05  0.04
#       0.05  0.03
#       0.05  0.03 ]

# Polycrystalline
# a_in, a_out...

a = [
     0.020  -0.380  -0.355  -0.572
     0.063  -0.351  -0.315  -0.545
    -0.041  -0.401  -0.388  -0.608
]

σ = [
    0.058  0.065  0.055  0.059
    0.044  0.083  0.057  0.070
    0.063  0.055  0.059  0.058
]

ā = a .± σ

D = d.(ā[:, 1], ā[:, 2:end])
D̃ = d̃.(ā[:, 1], ā[:, 2:end])

Δ = D[1, :] .- (D[2, :] .+ D[3, :]) ./ 2
Δ̃ = D̃[1, :] .- (D̃[2, :] .+ D̃[3, :]) ./ 2
