Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-01-14 07:14:13

"Kevin Lynch" <krlynch_at_[hidden]> wrote in message
> Andy Little wrote:


> discussions we had on this issue back in October/November of 2001. Many
> of the questions being discussed now have, not surprisingly, come up

I have tried to read up on boost-quantities-history. One observation is that
most of the resulting libraries appear to have been abandoned. I suspect
that the reason for that is partly the level of criticism, and 'feature
requests' :-). And possibly the shadow of SIUnits. From the current
discussion should come some flavour of the complexities/'interests'
involved... not all positive...some politics. A (physical )quantity does not
fit at all well into the 'flat' world of computing, which is based around
numeric types. Therefore those that have an 'interest' in numeric types will
not be positive. Compiler technology (and compile-speed) has evolved, new
techniques (metaprogramming) have been developed and are becoming
understood( me:-) ). . A 'second look' helps etc.and I have my own
'Walled garden' where I can experiment.


> > OK... you smash atoms and then try to figure out what the bits are made
> Yup.

The 'type' (bits of atom) is an(The) unknown? Ideally you want a 'type'
flexible enough so that you can keep trying to find one (type) that best
fits the input data?. The type *might* have physical dimensions. It would be
nice to be able to play with them? IOW What use is a physical-quantity type
in your work? In reality you have a lot of other more important problems...
(say) raw data accuracy? In fact Most problems are raw data accuracy? A wild
guess at what you really do.. :-)

> > (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).

Monte Carlo == gambling ? From this I assume that you are not trying to use
the 'atom smasher' data direct as an input, but are creating various models
which you can then compare with your raw 'atom smasher' data picture. (I
use 'picture' in the sense that you must make educated guess on important
features of the raw data) A wild guess at what you really do.. :-)


> 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

Personally I am very grateful to those guys. I have been using SI for my
calcs for years without actually realising. To me any chance I get I now say
Of the 7 length,mass,time,current,temperature... and light are 'everyday'
concepts to me:
Length -->ruler
mass --> scales (implicit g calibrated)
time --> watch
current --> ammeter
temperature --> thermometer
light --> eyes

They also extend into my 'schoolboy' physics. What is important about SI to
me is not the selection of a particular set of
dimensions, nor the units but that they can be combined in a coherent way.
(and communicated around the world)

For example:

(a force in N) / (a mass in kg) --> an acceleration in (metres per

What if I take units of kilograms-force:

    (a force in kilograms-force) / (a mass in kg) --> what units ?

It may be possible to extract the logic (SI is a 'retrofit' to ad-hoc units
systems) even clean it up, or define ones own.
You personally need total control of a dimension (what it is) and its units
and some logic to combine them (a quantity)Your
view of reality is not at the same scale as the general public. Your work is
very specialised.

> > 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.

(Understating) I find this remark slightly odd. Deane has several times
asked myself and others to explain the concepts of physical quantities. In
much of his writing he confuses quantities,dimensions and units. (Like Deane
you would like to 'make up' your own dimension/units system....this may be
what you are saying.)
If there is something in Deanes work I would like to see a more
comprehensive paper, ideally written for a 'simple guy' like myself.
(Diagrams help).
Heres mine(needs updating):

 I am to old to be impressed by big words and 'peer review'. Though Deane
tries to explain what dimensional analysis is in one paragraph, In the next
he says he doesnt understand it. This doesnt give me confidence. I like Math
and physics because they (ideally) place emphasis on proof. Finance places
most emphasis on self interest. Transposing physical models to 'prove'
financial ones... its too easy, no requirement for proof. (Psychologists do
the same thing)
(end diatribe)

>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.

One observation.. when you say 2m I know exactly what you mean. When I want
to fit a shelf , I'd rather take out a tape measure than think "What system
shall I
design that is suited to do this job and then argue with you about the best
for the next three months". If we all went around defining our own
(same point I made above)

> > I assume that by non-dimensionalised calculations you mean you use a
> > 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 "non-dimensionalized", 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,

Whoa.. my lib actually would do much better than you might think here.

    q_time::us t(1); // unit 1e -6 .. stored in the
template param as -6
    q_frequency::MHz w(1); //units 1 e6 ... stored in template
param as
    os << w * t; // add exponents at compile time 6
- -6 --> 0
 NO runtime division or multiplication at unit layer here, (fast and
BTW with my lib the value_type is at the scale of
the unit. hence 1 us is stored as 1.
Units are a whole new ballgame for me :-)

>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 "non-dimensionalized" equation
> exp(-T)*(1+cos(W*T))

although the original ones (t/tau), (w*t) are dimensionless:
exp and cos would give different(unit dependent) results if used with
dimensioned quantities.

Dimensioned constants are handy:
q_capacitance::uF const C(0.47); //capacitor
    q_voltage::V const V0(5); //starting voltage across capacitor
    q_resistance::kR const R(4.7); // resistance between terminals

    for ( q_time::ms t(0) ; t <= q_time::ms(50); t += q_time::ms(1) ){
        q_voltage::V const Vt = V0 * std::exp(-t /(C * R));

(-t/(C*R) ) is dimensionless.

time t;
 exp(t) is (Almost) Definitely an error in my unit system too.
(some 'rules of thumb' do this type of thing... but Very Explicit about

> 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),

Although you have had to divide(somehere along the line) to get T ?
But presumably a lot of nice cancellations occur behind the scenes?
OK OK The reality Is much more complicated :-)

> 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.

Basically you are avoiding creating a unit system.... but therefore can only
use dimensionless quantities.
Maybe you dont need dimensioned-quantities (which must have units)


> > Current practise then is to fit the calculations to the limitations of
> > 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 :-)

IOW pay your programmers well. Smile at them.. If they ever quit your
<expletive deleted>!

I accept this point (unit-support) absolutely. To me the physical-quantities
type is just for fun. It will not fit into real systems.. What I do like is
that it models what it represents in a satisfying way. When you build a
model in one situation you try to make it as close to the real thing as you
can. In another a great simplification maybe better. From what you say a
physical-quantities type is rather a triviality in your work. It would
create more problems than it solves.

> Would I do it differently in an ideal world? Sure
> 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.

I may be wrong but I think that I could only do this (physical-quantities
type) in any expressive way in C++. I love C++. It has evolved rather than
been designed by grammar experts (Pascal). Its bottom up not top down. AFAIK
Bjarne Stroustrup originally designed it for simulations. Appears that some
of those 'bare bones' are proving very useful in my particular lib.

> > What would help most is the sort of thing that shows the current
> > and frustrations. ie "If I could only do This...". I dont see that it
> > 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

I am pretty sure I shall incorporate the converter. I hope to work with
some day. FEM I think its called? Again something that works, not 'raw

> >
> > Oh and anything with non integer powers of dimension...preferably
> > irrational.
> I've never seen such a thing; and non-integer 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".

Err .. hmm I know that but you have to humour these guys ;-). I have
optimised on int powers then this was pulled out... nV.Hz^-.5 ...
trivia.... but
reviewing my code I may be able to squiggle in rational-powers (for their
benefit), while keeping the optimisation. :-)

> 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 long-winded mode :-)

Thanks for the information.... and time. It has been interesting and useful.
I will try to look further into 'user definability'.Its not every day I can
say, "sorry I'm busy talking to a particle phycisist." :-)

Andy Little

begin 666 Yangisms.txt
M#0HQ+61I;65N<VEO;F%L(&%N86QY<VES('-E<G9E<R Y,"4@;V8@=&AE(&YE
M"B(-"CX_at_5VAA="!I<R!T:&4@<F5S=6QT(&]F#0H^("!T;W)Q=64H,2XP*2 O
M('=O<FLH,2XP*0T*/B _("!)(&%S<W5M92!I="!H87,@9&EM96YS:6]N86QI
M='D@(G1O<G%U95XQ+'=O<FM>+3$B+B @3W(@9&]E<R!I="!H879E(&YO#0H^
M92!D:6UE;G-I;VYS(&9O<F-E(&%N9" -"FQE;F=T:"!A;F0_at_86QL;W<@=&]R
M="X_at_0F5C875S92!)(')E86QL>2!D;R!N965D('1O(&1O('1H92 -"FUU;'1I
M<V\@87!P;&EC86)L92!T;R!S;R!M86YY( T*/B!A<F5A<R!P<F5S96YT<R!A
M( T*#0I997,A#0HB#0H-"B(-"D%L<V\L($D@<F5A;&QY+"!R96%L;'D_at_9&\@
M<F5S('1I;64@:6YT97)N86QL>2!I;B!T:&5S92 -"G5N:71S+B!)="!W;W5L

Boost list run by bdawes at, gregod at, cpdaniel at, john at