Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fractional power of units of measures in F#

Is it true to say that : there are no fractional power units in F#

like image 847
nicolas Avatar asked Jul 04 '12 17:07

nicolas


People also ask

Can units have fractional exponents?

To write a radical as a fractional exponent, the power to which the base is raised becomes the numerator and the root becomes the denominator. Any radical in the form can be written as a fractional exponent in the form . This makes sense for our unit fraction exponents as well.


3 Answers

In addition to what has already been said, the best resource for information about (not just) F# units of measure is Andrew Kennedy's PhD thesis, who actually designed F# units. He mentions fractional units:

The most important decision is whether or not to allow fractional exponents of dimensions. The argument against them is philosophical: a quantity with a dimension such as M1/2 makes no sense physically, and if such a thing arose, it would suggest revision of the set of base dimensions rather than a re-evaluation of integral exponents. The argument in favour is pragmatic: sometimes it is easier to write program code which temporarily creates a value whose dimension has fractional exponents. In this dissertation the former view prevails, and fractional exponents are not considered. However, most of the theory would apply just the same; any potential differences are highlighted as they arise.

I think this is essentially the reason why F# does not have fractional units, because the F# design quite closely follows Andrew Kennedy's work to make sure it is sound.

Update: With F# 4.0, support for fractional exponents has been implemented

like image 140
Tomas Petricek Avatar answered Sep 29 '22 07:09

Tomas Petricek


Units with fractional exponents are quite common and there is nothing special about them. Probably everyone in technology has come across a voltage noise density, which is measured per sqrt(Hz). This makes a lot of sense physically, the noise power is proportional to the bandwidth, and the noise voltage is the sqrt of the power, no strange mathematics here.

To create a new base unit every time one comes across a fractional power exponent is not the right approach.

These units are not SI units and their use breaks library compatibility. If you define the sqrtHz as a new unit and I define the rootHz, our code can't work together. Anyway, I would need to introduce quite a big set of base units to have a complete set Hz^-2, Hz^3, Hz^-5,... Just to offer rational exponents seems to be the better choice, btw. Boost.units does so.

like image 31
user1508010 Avatar answered Sep 30 '22 07:09

user1508010


Absence of literally fractional power units of measure does not anyhow discounts F# unit facility as it allows presenting seemingly fractional exponent unit relationships the other way around having smallest fraction as a base dimension:

let takeSqrt (x: float<_>) = sqrt(x)

has inferred signature of float<'u ^ 2> -> float<'u> this way avoiding introduction of imaginary "naturally fractional" float<'u> -> float<'u^1/2>.

let moreComplicated (x: float<_>) (y: float<_>) =
    sqrt(x*x + y*y*y)

has inferred signature of float<'u ^ 3> -> float<'u ^ 2> -> float<'u ^ 3>, where all unit measure conversions stay valid relative to some derived implicit base dimension float<'u>.

The fact that the piece of code below

[<Measure>]type m
let c = sqrt(1.0<m>)

does not even compile with diagnostics The unit of measure 'm' does not match the unit of measure ''u ^ 2' can be considered as a blame, or a blessing, but is a clear indication that the unit measure checks are in place.

like image 42
Gene Belitski Avatar answered Sep 30 '22 07:09

Gene Belitski