Dimensional analysis with fundeps (some physics comments)
Fergus Henderson
fjh@cs.mu.oz.au
Wed, 11 Apr 2001 11:02:04 +1000
On 10-Apr-2001, Jerzy Karczmarczuk <karczma@info.unicaen.fr> wrote:
> Tom Pledger wrote:
> //about dimensions, units...//
>
> > If you clearly make the type system deal with dimensions rather than
> > units, there's no problem with plugging in multiple unit systems. You
> > just have to pick a scale for the representation.
> >
> > newtype Dimensioned mass length time rep = Dimensioned rep
> >
> > type Mass rep = Dimensioned One Zero Zero rep
> >
> > kg, lb :: Num a => Mass a
> > kg = dm 1
> > lb = dm 0.4535924
> >
> > Angles are dimensionless. (Think of the Taylor series for trig
> > functions.)
> >
> > radian, degree :: Unit
> > radian = dm 1
> > degree = dm (pi/180)
>
> The distinction between dimensions and units may seem for some of
> you utterly trivial. Mass is a mass, kg -> lb, etc. are just conversion
> factors. Angles are dimensionless.
>
> It was not so trivial for the authors of SI, and for some speculative
> physicists, who are not all dead yet. The problem is: what is a
> *fundamental*, *universal* constant?
>
> You see, those constants establish our unit systems!
>
> Many, really many among my friends don't hesitate to work in a frame
> where the speed of light is equal to 1. Yes, ONE, dimensionless. Then,
> passing from length to time is just a unit conversion, and all
> velocities are dimensionless.
...
> one should not forget that all that is *conventional*.
Right. So, from a programming perspective, the question is this:
which conventions are most useful?
If we treat angles as dimensionless, then the type system won't give us much
help in detecting errors when we have e.g. confused radians with degrees.
But this kind of error is a common programming error -- for example,
we (the Mercury team) made that mistake while writing our ICFP competition
entry this year, and from discussion with the Haskell team that came 3rd,
I think they did too, IIRC.
So from a programming perspective, I think it may be a good idea to
treat angles as a separate dimension. Note that you can still express
things like Taylor series expansions easily enough, you just have to
divide by the appropriate unit first.
Actually in the system proposed in this thread, I suppose the type system
does give you some help in detecting or avoiding those kinds of errors,
even if angles are not a separate unit, because in this system ordinary
numbers are not the same as dimensionless units, and so you have to insert
an explicit conversion to convert between numbers and dimensionless units,
and that gives you the opportunity to consider whether the right expression
to convert `angle' from a number to a Unit is `toUnit angle', `angle * radian',
or `angle * degree'. Still, the need to insert explicit `toUnits' is
annoying, and it would be nice to have a system where every number was
already a dimensionless unit. In that case, the argument for making
angles a separate dimension would be stronger.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.