
--- Michael Fawcett <michael.fawcett@gmail.com> wrote:
I was under the impression that the vector<3, free_quantity> syntax was just one alternative to the lengthier one,
That was my understanding too. I see no reason to preclude the type parameter from being free_quantity, and this would automatically allow mixed vectors - and automatically ensure they're only used in ways that make sense. Operations on these vectors will call operations on their elements, and those individual operations on free_quantity will still check for consistency of dimensions and produce errors if the mathematics doesn't make sense. An example may help. Consider these vector declarations: vector<2,free_quantity> v1; v1[0] = 1 * meter(); v1[1] = 2 * meter() / second(); vector<2,free_quantity> v2; v2[0] = 3 * gram(); v2[1] = 4 * gram(); vector<2,free_quantity> v3; v3[0] = 5 / second(); v3[1] = 6; Then v1.magnitude() will produce an error, because it involves adding (1 m)^2 + (2 m/s)^2, and the + operator on free_quantity should complain that the dimensions are not consistent. On the other hand, v2.magnitude() could be allowed - it's a straightforward computation; the result is 5 g. Likewise, the dot product v1.dot(v3) can be done: v1.dot(v3) = (1 m)*(5/s) + (2 m/s)*6 = 5 m/s + 12 m/s = 17 m/s Here the computation succeeds because both terms in the sum have the same dimensions (velocity).
in fact, I got the impression that Leland Brown currently uses mixed type vectors and matrices with success.
Yes. In fact my dot product example above is exactly the kind of thing that occurs in my algorithm many, many times (except that it more often involves matrices as well and not just vectors). My application involves a set of input quantities of different dimensions, which influence the output of a process. We need to find the best set of inputs to get the right outputs. If there are N inputs and M outputs, then it involves MxN matrices. The same kind of problem comes up in a variety of engineering disciplines. The math is the same regardless of whether the input (or output) quantities have equal dimensions. In my case, they do not, so I need mixed vectors and matrices. Another example is a covariance matrix, describing the statistical relationships between quantities of different dimensions. In this case, the elements of the matrix will have many different dimensions. And a common computation called "propagation of errors" requires this matrix to be multiplied by other matrices of mixed dimensions. But a key point is: always, as in my dot product example, the individual addition operations will end up having consistent dimensions if the matrices have been designed correctly. And if they haven't - well, that's exactly where using PQS with a matrix library is really useful to spot the error! -- Leland __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com