bjornbm / dimensional

Dimensional library variant built on Data Kinds, Closed Type Families, TypeNats (GHC 7.8+).
BSD 3-Clause "New" or "Revised" License
102 stars 15 forks source link

Percent as a dimensionless unit? #190

Closed dmcclean closed 5 years ago

dmcclean commented 6 years ago

Would it be desirable for presentation control purposes to ship the following definition:

percent :: (Fractional a) => Unit 'NonMetric DOne a
percent = mkUnitQ (ucum "%" "%" "percent") (1 Prelude./ 100) one

If so, should there be a space between a value and the printed name of this unit, or not? https://en.wikipedia.org/wiki/Percent_sign#Spacing says that most English style guides say no, but ISO 31-0 says yes.

bjornbm commented 6 years ago

Yes, I think so. I like the space, as recommended in the NIST SP811 (section 7.10.2).

On 3 Jun 2018, at 04:53, Douglas McClean notifications@github.com wrote:

Would it be desirable for presentation control purposes to ship the following definition:

percent :: (Fractional a) => Unit 'NonMetric DOne a percent = mkUnitQ (ucum "%" "%" "percent") (1 Prelude./ 100) one If so, should there be a space between a value and the printed name of this unit, or not? https://en.wikipedia.org/wiki/Percent_sign#Spacing says that most English style guides say no, but ISO 31-0 says yes.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

dmcclean commented 5 years ago

Some compound units formed from this are suspicious.

Things like percent / kelvin you can sort of see as something that might be useful as a gain in a heater control loop.

But things like percent * percent seem very strange indeed.

dmcclean commented 5 years ago

Overall I think I am still in support, but I'd like input from @bjornbm.

Perhaps a "linter" for Units that scores them for desirability/standards compliance by scrutinizing the structure of their names is a potential solution to this and other dilemmas, especially some that have come up in dimensional-parsers / dimensional-th development. That could get us to a point where questionable uses are allowed for when you need them but can still be detected and possibly generate warnings?

bjornbm commented 5 years ago

I don't think I see much problems with percent. Since, as noted in the SP811 section on %, “the symbol % represents simply a number” (0.01) I don't think very much can go wrong too badly. Of course, since it is a number there are a number of ways it should not be used in writing that you will run into in the wild (see link above), but in code these are exactly what dimensional prevents.

Regarding percent * percent, is the concern that someone might write that? While I agree percent * percent looks strange in writing (perhaps the basis point ‱ is appropriate?) I wouldn't think writing a linter to prevent it would be worthwhile. If you have enough other reasons for a linter that would make adding this case trivial it may be another matter.

dmcclean commented 5 years ago

I think my concern is that they say it represents a number (a dimensionless quantity), but we are intending to make it a dimensionless unit. It has a name, so at a glance that seems fine. But that name doesn't seem to compose quite as well as the other unit names.

The SP811 section, in my reading, doesn't address this point. They say "it is acceptable to use the internationally recognized symbol % (percent) for the number 0.01 with the SI and thus to express the values of quantities of dimension one (see Sec. 7.14) with its aid." But if permitted as a unit, it can also be part of a composite unit that ultimately has some other dimension. The section contains no examples of that type, nor any commentary advising against them. For example, is a usage like "The bacterial population increased at a rate of 3.2 % / h" acceptable or unacceptable?

bjornbm commented 5 years ago

If we consider % to be the number 0.01 we could take either the approach of pi and define it as 0.01 *~ one, or take the approach of one and define it as a unit as you propose above. (Of course, one mainly exists because I needed a unit of dimension one; not much thought has been put into it.) The former avoids some questions like yours above, but makes it cumbersome to use, e.g., 25 *~ one * percent. Actually, the way I read the text you quote

it is acceptable to use the internationally recognized symbol % (percent) for the number 0.01 with the SI and thus to express the values of quantities of dimension one (see Sec. 7.14) with its aid.

is that it is indeed appropriate to define and use percent analogously to one.

For example, is a usage like "The bacterial population increased at a rate of 3.2 % / h" acceptable or unacceptable?

If considering % strictly as 0.01 I would think the above is strictly speaking acceptable, but not have the meaning you likely intended. It seems the strict interpretation would be that the population increased by 0.032 bacteria per hour.

See also the Check List for Reviewing Manuscripts:

(5) Statements such as "the length l1 exceeds the length l2 by 0.2 %" are avoided because it is recognized that the symbol % represents simply the number 0.01.

I think this is a special case of "fractions" (see mass fraction, volume fraction, amount-of-substance fraction examples) with the unit 1 (or "bacteria").

Perhaps § 7.10.3 spreads some more light? Does it make sense to write "The bacterial population increased at a rate of 0.032 (1/1)/h"? If so perhaps it is also acceptable to write "The bacterial population increased at a rate of 3.2 (%/1)/h". In text I guess one could write "The bacterial population increased at a rate of 0.032 (bacteria/bacteria)/h" (where bacteria is implicitly a count and thus == one)?

Not very pretty perhaps and certainly your example is what one is more likely to encounter in the wild.

Not sure where this leads us?