 # Boost :

From: Jan Langer (jan_at_[hidden])
Date: 2003-10-16 14:37:55

Deane Yang wrote:
> First, I agree with what Jan Langer wrote in his message about the
> design of the library.
>
> Jan Langer wrote:
>> i think you confuse something here: quantities and units (maybe i am
>> confusing the name ;-))
>
> I am under the impression that the standard terminology is "dimensions"
> (refers to things like mass, length, and time without any particular
> units) and "units" (things like meters, grams, seconds).

thanks. i also browsed a little through wikipedia.org
(http://en.wikipedia.org/wiki/Dimensional_analysis) and maybe i'll get
it right now.

>> in an abstract sense this should be like points in an n-dimensional
>> space.
>
> (I apologize for behaving like a pedantic mathematician here going way
> off-topic, but I've always wondered what the right abstract description
> of dimensional analysis was and I'm very happy to have figured it out.)
>
> For what it's worth, although your description of what a dimension
> library should be is quite good, it's not really points in an
> n-dimensional space.
>
> Here is a precise mathematical description of dimensional analysis. The
> thing to notice about dimensional analysis is that all of the things
> being measured are 1-dimensional. Doing dimensional analysis properly
> for higher dimensions (for example, dealing with position in 3-space and
> force vectors) is somewhat more complicated (I do sometimes dream of a
> library that
> properly joins dimensional analysis with linear algebra.).

can't this be done by specifying a proper value type for the quantities
like:

typedef some_vector_type vector;
typedef double scalar;
typedef list_c <int, 1, 1, -3, -1>::type electrical_field_strength
typedef quantity <vector, electrical_field_strength>::type vector_E;
typedef quantity <vector, ...>::type vector_D;
typedef quantity <scalar, ...>::type permittivity;

vector_E e = ...;
permittivity const perm_0 = ...;
vector_D d = perm_0 * e;

this will work when

vector e = ...;
double const perm_0 = ...;
vector v = perm_0 * e;

works. but this will required some pretty good type promotion and so on.

> Each basic dimension corresponds to a different 1-dimensional real
> vector space (i.e., the real line without the co-ordinate labeling).
> Each possible "derived" dimension (which consists of a product of
> fundamental dimensions raised to integer or even rational powers)
> corresponds to
> a tensor product of the appropriate number of the basic 1-dimensional
> vector spaces or their duals (if the corresponding exponent is
> negative). Rational powers are a little harder to describe, but also
> have a natural mathematical description.
>
> Defining units for a given dimension corresponds to choosing a basis
> for the corresponding 1-dimensional vector space (all you need to do
> is choose a single vector and declare it to be a unit vector). A fancy
> way to say this is to choose an invertible linear map from the vector
> space to the real line. You can do this for any of the dimensions,
> whether they are fundamental or derived. However, if you choose units
> for each of the fundamental dimensions, then they naturally induce units
> for each of the derived dimensions. Mathematically, this corresponds to
> saying that if you choose linear maps from each fundamental vector space
> to the real line, then there is a naturally induced linear maps from a
> derived vector space (i.e., a tensor product involving the fundamental
> vector spaces and their duals) to the real line.
>
> None of this helps anyone do anything; nobody really needs to know any
> of this. But one way to distinguish between dimensions and units is that
> dimensions corresponds to doing abstract linear algebra and units
> corresponds to doing linear algebra with respect to fixed bases.
> Changing units (like from meters to feet) corresponds to changing the
> basis of the corresponding vector space.

ok. thanks for the explanation. although i couldnt follow it all the
way, i think i got the idea.

so basically we need to do compile-time dimensional analysis.

then we tag each fundamental dimension with a nice name (eg length,
mass) for a certain system. also the derived dimensions (you called it:
product of fundamental dimensions raised to integer or even rational
powers) can be tagged with nice names (energy, volume).

a quantity type represents one of your 1-dimensional-spaces. it connects
a dimension to the "real line" (or integer or rational line probably).

units are objects of quantities and tag points on the "real line" with a
name.
if the "real line" is always real or has the some type for all
computations its easy. if not the type promotion is needed.

this would make up some nice layers to structure the library.
jan

```--
jan langer ... jan_at_[hidden]
"pi ist genau drei"
```