# Issues arising when using UnitSimplify for getting a dimensionless expression

I am having some difficulties when using  UnitSimplify in manipulating expressions for obtaining dimensionless quantities in Mathematica 12.0.0. Here is a minimal example showing the difficulty:

UnitSimplify[
Quantity[10, "Joules"^(-1)]
(Quantity[20, "Joules"] r^2 +
Quantity[30, "Gigapascals" ("Picometers")^(3/2)] Sqrt[d^2 Quantity[40, "Liters"] +
f^2 Quantity[50, "Liters"]])]


The  UnitSimplify appears to do nothing above. To solve this difficulty, I have worked out the unit conversion factor for turning "Gigapascals" ("Picometers")^(3/2) into "Joules"^(1) "Liters"^(-1/2). Then I applied a rule.

% /. Quantity[x_, "Gigapascals" ("Picometers")^(3/2)] ->
UnitConvert[
Quantity[x, "Gigapascals" ("Picometers")^(3/2)],
"Joules"^(1) "Liters"^(-1/2)]


Now that I can see that the units cancel, I can just take the magnitudes and find the dimensionless expression.

My question is: can this replacement rule be made more general to avoid working out unit conversion factors every time I come up with a dimensionless expression?

Mathematica is assuming that your variables r, d and f are quantities with dimensions, and so it gives up. If you tell Mathematica that they are unitless quantities, then it will work:

UnitSimplify[
Quantity[10,"Joules"^(-1)] *
(
Quantity[20,"Joules"] Quantity[r,"Unities"]^2 +
Quantity[30,"Gigapascals" ("Picometers")^(3/2)] *
Sqrt[
Quantity[d,"Unities"]^2Quantity[40,"Liters"] +
Quantity[f,"Unities"]^2 Quantity[50,"Liters"]
]
)
]


10 ((3 Sqrt[40 d^2 + 50 f^2])/(1000000000 Sqrt[10]) + 20 r^2)

• Thanks! I take it that "Unities" is the unit for dimensionless quantities. Jun 24, 2020 at 17:49
• I think you can also use "DimensionlessUnit".
– chuy
Jun 24, 2020 at 18:25