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 16 forks source link

Negative roots #132

Closed dmcclean closed 8 years ago

dmcclean commented 8 years ago

What are the intended semantics of

let x = 3.7 *~ square meter
nroot neg2 x

I'd suggest that there probably are none, and that the Root type family may need to be changed to not define negative roots of Dimensions.

bjornbm commented 8 years ago

I think the appropriate semantics are:

nroot (-n) x = nroot n (recip x)

which is consistent with (**) (by definition of nroot) and dimensionally sound, no? What is the problem you see with this?

dmcclean commented 8 years ago

At first I was concerned that it allowed a zeroth root, but I was wrong about that, it doesn't.

Then I left the question anyway, because I couldn't find any sources anywhere talking about negative roots of things (hard to find with all the noise about roots of negative things).

That is consistent with (**) and with the implementation we have. I'm not sure if it is dimensionally sound or not because I can't think of anything to compare it to.

I think we can safely keep those semantics, but add a documentation note explaining them?

dmcclean commented 8 years ago

OK, this agrees with what wolfram alpha does.

http://www.wolframalpha.com/input/?i=surd%2813.69%2C+-2%29