Open jonniediegelman opened 1 year ago
julia> uconvert(u"rad", 1.0)
1.0 rad
So the incorrect conversion is between unitless and radians?
"Incorrect" for some definition of "correctness", yes, but the point is that radians are dimensionless
Yes, but this version of "correctness" is the one that most people use and will be expecting from a unitful package, even if it's not strictly the most correct.
The author of the Frink programming language has a lot of opinionated commentary on units. Here he is on hertz and radians.
His summary conclusion:
// In summary: Frink grudgingly follows the SI's ridiculous, broken definition
// of "Hz". You should not use "Hz". The SI's definition of Hz should be
// considered harmful and broken. Instead, if you're talking about circular
// or sinusoidal motion, use terms like "cycles/sec" "revolutions/s",
// "rpm", "circle/min", etc. and Frink will do the right thing because it
// doesn't involve the stupid SI definition that doesn't match what any
// human knows about sinusoidal motion. Use of "Hz" will cause communication
// problems, errors, and make one party or another look insane in the eyes
// of the other.
Thanks @jariji. That whole rant was actually really helpful for understanding the issue. I would be in favor of printing this snippet from it out as a warning whenever someone uses Hz
in Unitful (because it's almost never going to be what they intended it to be):
If you follow the rules of the SI,
1 Hz = 1/s = 1 radian/s which is simply inconsistent and violates basic
ideas of sinusoidal motion, and is simply a stupid definition.
The entire rest of the world, up until that point, knew that 1 Hz needs to
be equal to *2 pi* radians/s or be changed to mean *cycles/second* for
these to be reconcilable. If you use "Hz" to mean cycles/second, say,
in sinusoidal motion, as the world has done for a century, know that the SI
made all your calculations wrong.
Instead of Hz
, you can use the units rps
or Hz2π
:
julia> uconvert(u"rad/s", 1.0u"rps")
6.283185307179586 rad s^-1
julia> uconvert(u"rad/s", 1.0u"Hz2π")
6.283185307179586 rad s^-1
I would be in favor of printing this snippet from it out as a warning whenever someone uses Hz in Unitful
Printing something every time a specific unit is used is simply impractical. I would guess that some people use the Hz
unit successfully. If we implement this proposal, we make their code slower by several orders of magnitude for no good reason. Just imagine some calculation involving loops. One day you update Unitful, and now your code runs forever because every loop iteration which used to do some simple arithmetics now also prints a paragraph of text. Your terminal is filled with millions of lines of the same three sentences, calling the definition of Hz
you used in your code “stupid”. Why punish everyone who uses Hz
successfully?
(because it's almost never going to be what they intended it to be)
This might be true in the context of sinusoidal/circular motion, but in general I don’t agree with it. The unit Hz
is used in many contexts, not just sinusoidal motion.
The problem only arises in sinusoidal/circular motion, because rad/s
is used for angular frequency and, in the context of sinusoidal motion, Hz
is (usually) only used for frequency, not angular frequency. In order to convert from frequency to angular frequency, I have to multiply by 2π
, not just change units. If I’m not dealing with sinusoidal motion, I never run into this problem.
Maybe we could add a FAQ section in the manual. We could also add warnings to the docstrings of Hz
and rad
(because the reason for the behavior of Hz
is really that 1 rad == 1
instead of 2π rad == 1
).
Printing something every time a specific unit is used is simply impractical
That was mostly hyperbole. I don't think we should actually print out a wall of text whenever someone uses the unit. But honestly even doing that would be better than the current situation of silently giving an unexpected result.
The problem only arises in sinusoidal/circular motion
Okay, but sinusoidal motion is where Hz
is mostly being used in physics contexts. It's usually not describing literal physical angular motion (the only angular motion is happening in the complex plane), but it often is converted to rad/s
for making other calculations more convenient. Frequency response functions are a good example where the system you're studying the frequency response of is generally not a rotational system, but will still often be analyzed in terms of angular frequency.
Maybe we could add a FAQ section in the manual. We could also add warnings to the docstrings of Hz and rad (because the reason for the behavior of Hz is really that 1 rad == 1 instead of 2π rad == 1).
I don't think a docstring would be sufficient here because people wouldn't usually check the docstring of a physical unit if they have no reason to believe they might be misunderstanding it.
I can't emphasize enough that the common understanding and practical usage of a hertz is that of a cycle per second, not of an unqualified "one per second". Even the NIST page on SI time units describes one hertz as "one cycle per second".
https://github.com/PainterQubits/Unitful.jl/issues/531#issuecomment-1114132359 nailed it, IMO:
[...] ω and f are not the same quantity in different units... What I want is really a change of variables, not a unit transformation. :upside_down_face: [...]
I can't emphasize enough that the common understanding and practical usage of a hertz is that of a cycle per second, not of an unqualified "one per second". Even the NIST page on SI time units describes one hertz as "one cycle per second".
NIST page writes:
The number of periods or cycles per second is called frequency. The SI unit for frequency is the hertz (
Hz
). One hertz is the same as one cycle per second.
Thus "period" and "cycle" are used synonymously there, I'd also add "event" as a further synonym. Though "cycle" might suggest sinusoidal/circular motion, "period" doesn't. Hz
is a universal unit for all kind of periodic processes. I happily use Hz
to measure the pulse frequency of a step motor controller.
Related publication:
I would expect this to give
6.2831853 rad s⁻¹