Is it possible for MMA to convert natural unit (particle physics), for example, $1 eV^{-1}$ wavelength, to about $2\times 10^{-7}m$? I think the key is to tell MMA it's a length unit but I don't see how.
1 Answer
A few months ago I wrote a function that converts from SI to natural units. A quick way to achieve the inverse conversion is to convert your target units, meters, to natural units to get about 5e6 1/eV. Then divide your wavelength in 1/eV by 5.07e6 to get the number of meters. Of course, it has to work with other units besides 1/eV and meters.
Conversion from SI to natural units
Here is a function that takes a SI quantity and converts it to natural units, which are always eV to some power.
ClearAll[toNaturalUnits]
toNaturalUnits[q_Quantity] :=
Block[{α, β, γ, δ, ϕ, χ,
c2 = Quantity["SpeedOfLight"]^2,
ℏ = Quantity["ReducedPlanckConstant"],
ℏc = Quantity["ReducedPlanckConstant"] Quantity["SpeedOfLight"],
kB = Quantity["BoltzmannConstant"],
ϵ0 = Quantity["ElectricConstant"]},
χ = UnitDimensions[q];
{α, β, γ, δ, ϕ} = \
{FirstCase[χ, {"LengthUnit", α_} -> α],
FirstCase[χ, {"MassUnit", β_} -> β],
FirstCase[χ, {"TemperatureUnit", γ_} -> γ],
FirstCase[χ, {"TimeUnit", δ_} -> δ],
FirstCase[χ, {"ElectricCurrentUnit", ϕ_} -> ϕ]};
{α, β, γ, δ, ϕ} = {α, β, γ, δ, ϕ} /. Missing[_] -> 0;
UnitConvert[
q ℏc^(-α + ϕ/2) ℏ^-δ c2^(β - ϕ/2) kB^γ (4 π ϵ0)^(-ϕ/2) ,
"Electronvolts"^(-α - δ + β + γ + ϕ)]
]
toNaturalUnits[q_List] := Map[toNaturalUnits, q]
Here are some common test cases. In each case, the result should be about 1 eV raised to the appropriate power.
{Quantity[389.4 10^12, "Barns"],
Quantity[0.19733, "Micrometers"],
Quantity[0.6582, "Femptoseconds"],
Quantity[1.78266 10^-36, "Kilograms"],
Quantity[85.43, "Millivolts"],
Quantity[1519.27, "Terahertz"],
Quantity[8.12 10^-13, "Newtons"],
Quantity[432.9, "Volts"/"Millimeters"],
Quantity[7.318 10^10, "Amperes"/("Meters")^2]} // toNaturalUnits //
Round[#, 0.001] & // Column
Conversion from natural units to SI units
This is a rough draft/prototype of a function that takes a quantity q
and some target SI unit
and returns a quantity in those SI units. The first quantity is assumed to be in units of energy to some power. The second argument is assumed to be a string, like "Meters", or a product of units, like "Newtons"/"Meters". The second argument of fromNaturalUnits
will be used as the second argument of the Quantity
function, so whatever Quantity
recognizes as a valid unit and is compatible with the first argument should be okay. Here is the function that converts from natural units to your target units,
ClearAll[fromNaturalUnits]
fromNaturalUnits[q_Quantity, unit_] := Block[{
natTarget, natQ, ratio},
natTarget = toNaturalUnits[Quantity[1, unit]];
natQ = toNaturalUnits[q];
ratio = natQ/natTarget;
If[TrueQ[QuantityUnit[ratio] == "DimensionlessUnit"],
Quantity[ratio, unit],
"error message"]
]
fromNaturalUnits[q_?NumericQ, unit_] := Block[{
natTarget, ratio}, {
natTarget = toNaturalUnits[Quantity[1.0, unit]],
ratio = q/natTarget,
If[TrueQ[QuantityUnit[ratio] == "DimensionlessUnit"],
Quantity[ratio, unit],
"error message"]
}
]
Two versions of fromNaturalUnits
were necessary because sometimes the natural unit is dimensionless. This function has not be extensively tested, but here is an example of how it works with MMA quantities:
m = Quantity["ElectronMass"];
nat = toNaturalUnits[m]
fromNaturalUnits[nat, "Kilograms"]
(* 510998.9 eV
9.109384*10^-31 kg *)
Here is the speed of light:
fromNaturalUnits[1.0, "Meters"/"Seconds"]
(* 2.99792*10^8 m/s *)
Here are conversions from various powers of an eV. Notice that sometimes Quantity
will accept abbreviations like eV
and MeV
, but not powers of the abbreviations
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^-2], "Barns"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^-1], "Micrometers"]
fromNaturalUnits[
Quantity[1.0, ("Electronvolts")^-1], "Femptoseconds"]
fromNaturalUnits[Quantity[1.0, "MeV"], "Kilograms"]
fromNaturalUnits[Quantity[1.0, "eV"], "Millivolts"]
fromNaturalUnits[Quantity[1.0, "Electronvolts"], "Terahertz"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^2], "Newtons"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^2],
"Volts"/"Millimeters"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^3],
"Amperes"/("Meters")^2]
Finally, what's up with that "error message"? Well, if the arguments are incompatible, we get the error message. For example, try to convert 1 eV to seconds.
hbar*c
. I.e.q / (Quantity[1, "ReducedPlanckConstant"*"SpeedOfLight"])
$\endgroup$