
Boost : 
From: Kevin Lynch (krlynch_at_[hidden])
Date: 20040113 11:26:47
Andy Little wrote:
>>>1) What is your knowledge of C++?
>>
>>That's sort of an open ended question, but for what it's worth :)
>
>
> Yes odd in retrospect .. slightly impertinent ..apologies.
> BTW my views/questions are my own and should not be taken as representative
> of others working on similar libs or boost in general.
>
No offense taken .... while I'm thinking about it, since I haven't seen
it mentioned, you might want to take a glance back at one of the first
discussions we had on this issue back in October/November of 2001. Many
of the questions being discussed now have, not surprisingly, come up before.
> I should come clean and say my physics is 'schoolboy stuff'
> OK... you smash atoms and then try to figure out what the bits are made of?
Yup.
> (Don't know what MC modelling is..probably should).
Sorry ... MC = Monte Carlo. I use it in the more general sense here,
meaning a large simulation that uses random numbers to make certain
choices (like whether a particle decays in this time step or not).
>
> In standard C++ one use of templates is to allow the user to specify the
> details they require from a generic framework or algorithm. Stipulate a 'no
> templates' requirement and we would find it quite difficult to do much
> anything these days.If it was possible to provide details of your operating
> system(s)/ compiler(s), they probably wouldnt mean much to me but might to
> someone else on boost.
>
Sorry, I did not intend to imply a "no templates" requirement for the
units library .... I (and most others in the field) use gcc/icc on
ia32/linux for our code. The "no templates" thing was specific to a
certain analysis framework (the ROOT framework ... root.cern.ch) that we
use in the field for interactive analysis of data; it is based on a
dialect of C++ that is prestandard and whose interpreter (CINT ... yes,
you can interpret C++, Virginia... ) doesn't currently play well with
templates. But that is neither here nor there. Templates are obviously
the correct way to go in implementing the type of library being
discussed here.
> Ok The SI system has an underlying logic to it. To use dimensional analysis
> there is some similar logic that is applied or you would like to apply to
> the framework you are using?
Actually, the SI system is a really nasty :) Well, it is not so much
the units (there isn't anything inherently wrong with the selection of
units, names, and the physical unit definitions), but the understanding
and description of the underlying mathematics of dimensional analysis
that is inherent in the defining documents is really wacko ... it is
almost as if the SI was political document than a scientific document
:) For example, SI states that there "ARE SEVEN FUNDAMENTAL
DIMENSIONS", which is at best an overstatement. They should have said
"YOU CAN LOGICALLY CHOOSE THE NUMBER OF DIMENSIONS TO SUIT YOUR NEEDS
AND WE CHOOSE THESE SEVEN BECAUSE...."
> If we could figure out how to represent the
> 'logic'(s) of SI,CGS and 'natural' units, then that would (possibly)be
> something we could allow the user to customise (usually via templates)
>
The "logic" of dimensional analysis has been quite cogently described by
Deane Yang. In the context of a proper understanding of dimensional
analysis, a chosen system of units does nothing more than define a set
of fundamental objects against which you can describe measurements as
ratios. "this board is 2m long" is the statement that "Within the
context of SI, I am measuring this board by its length dimension, and I
find that it is twice as large as the fundamental meter", which is a
very well defined, but completely arbitrarily chosen, length.
> I assume that by nondimensionalised calculations you mean you use a 'real'
> type to represent a dimensioned quantity. Any dimensional analysis is
> done(and checked) manually. Do you require a C++ framework that catches
> errors in dimensional analysis, or is that a triviality?
By "nondimensionalized", I mean that you recast your equations directly
in terms of dimensionless ratios instead of in terms of the division of
two identically dimensioned quantities (usually, you then have to
multiply by an overall dimensioned constant to maintain the proper
units). This is a long winded aside, but here goes:
Here's an example ... in the experiment I'm working on right now, we
have a collection of particles that decay over time, and we measure that
decay time. All sorts of interesting physics go into calculating the
number of particles that will be observed to decay during a given time
interval in a given direction. Greatly simplified, it looks something
like this:
exp(t/tau)*(1+cos(w*t))
Where t is the time, tau is the lifetime of the particle, and w is a
precession frequency. Now, tau is of the order 2.2 micro s, w is of the
order of a few megahertz, so t will be in the range of a few tens of
microseconds. Now, since you don't want to be doing all of those
divisions at runtime, and for other reasons both technical (roundoff
errors in the real equations, etc.) and aesthetic (you think about these
things in reference to "how many lifetimes after the collection of
particles"), you are only ever interested in t/tau anyway. So, you
create a new variable T = t/tau, and recast the equation in terms of
this. Everything else gets recast as well: W = w*tau. Now, you have
the "nondimensionalized" equation
exp(T)*(1+cos(W*T))
and you see that the new form of the equation is completely in terms of
dimensionless quantities; it isn't obvious from this example that doing
such a thing is a win (although even in this case, you've eliminated a
multiply), but in complicated situations, it can simplify the equations
and make the physical content more obvious (the values of T of interest
are now centered about 1, for instance.
You've heard of nondimensionalized numbers before, such as Mach numbers,
the ratio of a given velocity through a medium to the local velocity of
sound. It is the Mach number, and not the absolute velocity, which
tells you about the physics of motion (sonic booms, turbulence, etc.)
Long winded aside over......
> Current practise then is to fit the calculations to the limitations of the
> framework? Would you do it differently in an ideal world?
>
Current practice is to do just that, because the frameworks are old and
huge (in fact, some are still written in Fortran 77, because that was
the dominant language when their first punch cards were, well, punched).
The newer frameworks that are written in C++ are still old enough
that they were started before the Standard was finalized and compilers
began to allow portable "advanced" behavior (templates, RTTI, etc.)
These are frameworks that, for instance, calculate real world effects in
particle interactions with matter, and contain hundreds of thousands or
millions of lines code, and hundreds of lookup tables of real world
data. The code works extremely well, is very well debugged, and well
understood ... you don't lightly go about modifying such code to add
unit support :) Would I do it differently in an ideal world? Sure would.
This is similar to the fact that most of us use C++, despite the known
"mistakes" in the language design, or use the STL despite its drawbacks,
or .... They aren't perfect, but they work better than the alternatives.
> What would help most is the sort of thing that shows the current problems
> and frustrations. ie "If I could only do This...". I dont see that it has
> to be related to D.A./units. Anything which is a C++ problem or could be
> fixed by C++ would be useful.
Oh, don't get me started .... give me a real array language, a generic,
extensible interface to special functions, real floating point support,
rational standard conversion rules, etc. etc. We've discussed many of
these issues on boost as well; Fernando Cacciola's Numeric Conversions
Library; the Random, Quaternions and Special Functions libraries are others.
>
> Oh and anything with non integer powers of dimension...preferably
> irrational.
I've never seen such a thing; and noninteger powers themselves are
actually fairly rare. You obviously need to be able to take rational
powers of things, but final results are almost universally integer
powers of units ... eg. given the volume of a sphere, what is its
radius? You need to take a cube root in three dimensions, but the
result is going to be a length. I've never seen an equation that
requires or results in, for example, the "cube root of length".
So, I don't know if any of that means anything or even answers your
questions ... I've been flooded out of my office by a burst standpipe,
and I've got nothing better to do than answer email from home while they
dry it out. So I'm in longwinded mode :)
  Kevin Lynch voice: (617) 3536025 Physics Department Fax: (617) 3539393 Boston University office: PRB361 590 Commonwealth Ave. email: krlynch_at_[hidden] Boston, MA 02215 USA http://budoe.bu.edu/~krlynch 
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk