Boost logo

Boost :

From: Oleg Abrosimov (beholder_at_[hidden])
Date: 2006-06-19 13:23:37


Gerhard Wesp wrote:
> On Mon, Jun 19, 2006 at 10:04:21AM +0200, Matthias Troyer wrote:
>> As a physicist I am completely baffled and confused. What do you mean
>> by rank of a quantity? Do you mean the size of a vector/matrix? If
>
> I understood Olegs post about rank such that it was something that would
> allow to distinguish energy from torque, e.g. Is there such a thing?
> Off the top of my head, I cannot think of a situation where you might
> want to add energy to torque, even if in the SI system they have the
> same dimension (Nm).
>
> Same thing for angular velocity [rad/s] and frequency (1/s). You
> probably don't want to add both, even if in SI they're both in s^-1. Is
> this maybe a deficiency of SI? Would it make sense to add the unit
> "radians" that is used colloquially anyway, to the system?

You are almost right, but in the end you've chosen a wrong direction.

There is a very good article in wikipedia about tensors in which tensor
rank is also described:
http://en.wikipedia.org/wiki/Tensor

The wrong direction is about deficiency in SI. The SI is all about
units, rank is absolutely orthogonal concept to units (of course it
deals not only with units, but also with dimensions, but it is natural
because units are just scales in multidimensional space defined by
dimensions). The truth is that angular velocity is (surprise!) a
pseudovector. Its direction is the same as a direction of rotation axis.
it is known to be involved in the following equation:
velocity_vector = crossproduct(angular_velocity_pseudovector, radius_vector)

On the other hand, frequency is simply a scalar. So, here is the same
situation as we have in energy vs torque "paradox" ;-)

Roots of such a problems lies in existence of two operations that
produce the same dimension from given ones:
1) dot-product (results in a scalar, like energy)
2) cross-product (results in a vector or a pseudovector, like torque)

This problem can not be solved only inside dimensional analysis. I hope
that it is clear from this post.
The solution is to take into account the rank of quantity (rank is 0 ->
scalar; rank is 1 -> vector, ...)

It can be implemented absolutely in the same manner as dimensional
analysis: rank would be a compile time constant that is bound to
quantity and all operations would be defined with respect to quantities'
rank. It means, in particular, that dimensional vector _must_ be defined as:
1) length< vector<double> > l;

and not as:
2) vector< length<double> > l;

reason is simple - we should define operations for vectors (rank is one)
that respect rank of it's results. For example:
dot(v1, v2) -> scalar (rank is 0) of dim = dim1 * dim2
cross(v1, v2) -> vector (rank is 1) of dim = dim1 * dim2

in implementation of these functions results would be a linear
combination of multiplications of vectors' coordinates, like:
v1.x * v2.x or v1.x * v2.y. if approach (2) is chosen then there is no
way for operator* defined for quantity to chose the right rank of the
resulting quantity. But it must be 0 for dot and 1 for cross.

To fix it library that implements vector<> should be aware of
dimensions. It means that PQS should have it's own copy of all linear
algebra code, but tuned for dimensions. There were a long discussion
about it in this list. In case of
length< vector<double> > l;
this limitation vanishes.
length here knows that it is a vector and defines its operations with
dimension _and_ rank awareness. One time for all linear algebra libs.

I'm envision something like boost::operators that can be used to define
quantities like length or torque (it can be used to define new system of
units/dimensions). something like:
struct length : boost::pqs::quantity<1/*rank*/> {...};

Hope this post would be helpful for units/dimensions subcommunity in
this list ;-)

Best regards,
Oleg Abrosimov.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk