I have an accrual calculation that I would like to preserve the units even though they are of the same dimension (e.g. time). For example, I would like the following
Quantity[5, "Days"] / Quantity[52, "Weeks"]
to return in units of days per week
instead of a unitless number. Later in the process I would like to multiply the result by some number of weeks (Quantity[_, "Week"]
) and have the result in day units.
I know about IndependentUnit
but prefer that the units in the result still be known to Mathematica (KnownUnitQ
true) for other purposes.
I have tried this with UpValues
(my first UpValues
attempt) with the following but I get an error.
Quantity /:
op : (Alternatives @@ (Symbol /@
WolframLanguageData[
EntityClass["WolframLanguageSymbol",
{"FunctionalityArea", "MathOperationFunctions"}], "Name"]))[
Quantity[v1_, u1_],
Quantity[v2_, u2_]
] :=
Quantity[op[v1, v2], op[u1, u2]]
Is it possible to do this or force a unit hold in quantity calculations?
I am expecting
Quantity[5, "Days"] / Quantity[52, "Weeks"]
to give the result that the following gives
Quantity[5/52, "Days"/"Weeks"]
(* Quantity[5/52, ("Days")/("Weeks")] *)
IndependentUnit
are actuallyKnownUnitQ
. Wouldn't that be enough for your purpose? $\endgroup$CompatibleUnitQ
notKnownUnitQ
. Else I will not be able to use it with other conversions later on. $\endgroup$