9

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

nicolas
  • 9,549
  • 3
  • 39
  • 83
  • 2
    Yes, it is. So what? Could you describe a use case when you need *fractional power*? – pad Jul 04 '12 at 17:13
  • yes. I have a matrix of type 'u. I need to to a QR decomposition. the type should be 'u^1/2 – nicolas Jul 04 '12 at 17:19
  • I dont understand how one could do a unit system without fractional power. This is absolutely fundamental. – nicolas Jul 04 '12 at 17:20
  • @pad do you have code with units of measure in production ? – nicolas Jul 04 '12 at 17:26
  • In the decomposition wouldn't Q be dimensionless (no unit) and R have the same unit as the original matrix? – MiMo Jul 04 '12 at 17:36
  • @MiMo actually your decomposition would make more sense indeed as Q is in most case a rotation matrix if i remember well. so let's say Cholesky – nicolas Jul 04 '12 at 17:41

5 Answers5

11

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

rmunn
  • 34,942
  • 10
  • 74
  • 105
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • it has no physical sense indeed. but when abstracting out algorithm, one is confronted to such cases. of course, since it has no physical sense, such fractional power unit will eventually be called with a unit that is raised to the corresponding power. so it really makes sense to have fractional unit if one intends to use them for general purposes, including general algorithm – nicolas Jul 05 '12 at 06:55
  • I really wonder what would be the computational costs to the compiler. I imagine it would be negligible (so the question is really one of philosophy) – nicolas Jul 05 '12 at 07:05
  • that is very interesting link. I will argue with Mr Kennedy then – after reading his thesis – nicolas Jul 05 '12 at 07:18
  • Actually, I already suggested him through his webpage (hope it went through) to add *symbolic power* to the UoM. That would have the immense advantage to handle both the (immense in my pov) case of matrix operation dimensions check **and** the fractional power issue. – nicolas Jul 05 '12 at 07:23
  • I stand by my previous remark that "the correct notion is that everything **starts** with physical units, and **ends** with physical units, but in the meantime, if multiplication is allowed, one has to close the ring, and add fractional units... ". until I grow some more neurons may be. – nicolas Aug 22 '12 at 17:59
6

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.

user1508010
  • 91
  • 1
  • 6
  • 1
    I'd even add symbolic powers, because I dont see why not. Practically it was too much effort for the reward, so I removed them from my code. I would have loved to add them unobstrusively, but this might require a deeper framework integration. Right now I see a practical usage for them in short range codebase, in simple cases. that is, where they dont quite shine. – nicolas Aug 22 '12 at 17:51
2

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.

Gene Belitski
  • 10,270
  • 1
  • 34
  • 54
  • 2
    I agree with you, but note that this means that you can't call `takeSqrt 1.0` because the return type wouldn't have an integral power. It's conceivable that in some applications having a fractional power of a concrete unit type would be useful. – kvb Jul 04 '12 at 19:00
  • @kvb: Either it has physical meaning and deserves a **derived UoM** defined, or there's no such meaning and no sense for a variable/binding. – Be Brave Be Like Ukraine Jul 04 '12 at 19:27
  • 4
    @bytebuster - See e.g. http://en.wikipedia.org/wiki/Fracture_toughness for one example requiring `m^1/2`. Sure, you can create a derived unit, but the inability to express it in base units is a real limitation, even if it's one that's relatively rare in practice. – kvb Jul 04 '12 at 20:14
  • @kvb I understand the scope, but this works fine for me (sorry for absent formatting): `[]type KIc []type Pa []type m = KIc^2/Pa^2 let pa:float = 50.0 / sqrt 0.5` – Be Brave Be Like Ukraine Jul 04 '12 at 21:18
  • @bytebuster - that works if you're defining a new derived `m` unit, but doesn't work with the built-in `SI.m`, which would naturally be desirable. – kvb Jul 05 '12 at 01:42
  • @bytebuster this argument about 'physical' things is specious from my pov. in that light, negative number have no physical meaning : it gets it by saying it is the quantity by which a positive number decrease when adding it. well ditto for fractional power unit : it is the unit that raised to an exponent, give a physical unit. the correct notion is that everything **starts** with physical units, and **ends** with physical units, but in the meantime, if multiplication is allowed, one has to close the ring, and add fractional units... – nicolas Jul 05 '12 at 07:11
  • @Gene your example does not work with a single class, say, matrix, that should work with different units. then you can not correctly assume that the base type is always a nth power of another. – nicolas Jul 05 '12 at 07:13
  • Gene your example does not work where a single class parameterized with unit, say, matrix<'u>, has function that yields with various fractional power. then you can not correctly assume that the base type 'u is always a nth power of the smallest common multiple of all operation of another type 'v. i mean you can, but your class will be more and more useless as you add functionality to it – nicolas Jul 05 '12 at 08:09
0

EDIT: After reading OP's comment and the except from Andrew Kennedy's paper, it appears @nicolas is correct -- F# doesn't support units of measure with fractional exponents.

Jack P.
  • 11,487
  • 1
  • 29
  • 34
  • 1
    'u^1/2 units is not 'u^-2. I still might want to do a general matrix class of type 'u and have some common methods spitting out units 'u^1/2, yet no constraint my type to have 'u = 'v^2 for some 'v – nicolas Jul 10 '12 at 06:50
-3

Shouldn't the answer be as easy as saying, yes, hertz are measured in s^-2 which is the same as s^(1/2)? There ya' go. Also, I like the philosophical idea of using , say m^(1/2) if it came up in calculations and perhaps one day understanding what that unit means in the literal sense.

Jeff
  • 3
  • 1