From: Andy Little (andy_at_[hidden])
Date: 2006-08-24 14:02:23


"Matthias Troyer" <troyer_at_[hidden]> wrote
> Andy Little wrote
<...>

>> For matrices my tests have been limited to homogeneous
>> transformation matrices.
>> In this case the matrix elements for a *simple/obvious*
>> implementation of a
>> matrix for a physical quantity are comprised of various types,
>> comprising of the
>> quantity type, the reciprocal of the quantity and numeric types. It
>> may be
>> possible to somehow 'tag' a numeric matrix as a quantity matrix,
>> but I havent
>> invetigated that.
>
> Just use a quantity as value type? What's the problem with that?

Assume a 2D homogeneous transform matrix intended to transform 2d points. With 9
elements it is possible for the matrix to contain up to 9 separate types T0 - T9

( T1 , T2, T3)
( T4, T5, T6 )
( T7, T8, T9)

In the transform matrix T1, T2, T4 and T5 are concerned with rotation. IOW to
rotate a point through an angle alpha

(cos(alpha), sin(alpha), T3
(-sin(alpha), cos(alpha), T6)
( T7, T8, T9)

Therefore T1, T2, T4, T5 must be numeric.

T7 and T8 represent translation. To translate a homogeneous point [ X Y h],
assuming h is a numeric and X and Y are some quantity, T7 and T8 must have the
dimensionally equivalent quantity type ( but not necesarily same unit) as X and
Y. (In fact in this case T3 and T6 have the reciprocal quantity type of X and
Y and T9 is always a numeric representing scaling)

Concatenating two matrices of the above type yields another matrix of the same
type and multiplying by the point yields a point of the same type. Other matrix
operations that I have tried also work from the point of view of dimensional
analysis too.

Another alternative is to make all the elements of the matrix numeric. In this
case h in the homogeneous coordinate [X Y h] would have the same type as X and
Y. That isnt as neat though as you have then lost the unit information in T7 and
T8 regarding the translation and applying the matrix to a point in different
units would give different results.

>> I havent looked into other use cases for linear algebra in
>> association with Quan
>> however. It may be that in the general case ( for large matrices)
>> that it is
>> impractical ( IOW the costs outweigh any possible benefits) to use
>> non-numeric
>> types as the elements, but that remains to be investigated.
>
> Why? What should be the problem? Your quantity is just a number, and
> the rest is compile time type information? Or is a quantity heavier
> than just a floating point number?

I hope I have demonstrated some of the issues in the above example. However I
have only limited my experiments to transform matrices. I should probably look
at other matrix calculations to see what happens in other cases too.

regards
Andy Little