Re: [boost] [Review][PQS] Review deadline

Gerhard Wesp wrote:
This could lead to errors (re: Mars lander) if people forget that they are working in one unit (SI meters) when they should be working in another (e.g. miles). For example, it would be easy to write: std::cout << "You need " << flour << " pounds of flour\n"; and not realise that flour is not in pounds!
Ok, but if you are working in atomic/theoretical physics, you have: // pseodo C++ for plank's constant (h) const physics::units::J plank_J = 6.62607554e-34 ± 3.97565e-40; const physics::unit::eV plank_eV = 4.135669212e-15 ± 1.2407e-21; so, which value is correct? The one in Joules (sp?) or the one in electron volts? It all depends on which units you are working with. Converting between the J and eV values for the sole purpose of using SI units, where you *need* eV would introduce (1) rounding errors due to the inaccuracies of floating point math and (2) the errors introduced when you take the intervals into account. So having 2h and converting from eV -> J -> eV will not give you 2h! As well as this, if you are working on the level of plank length: const si::units::meters plank_length = 1.616051e-35 ± 1.03427e-39; (and yes, plank length is in meters!) it would be easier, faster, more acurate ... to do the calculations with plank_length as the base unit so you do not use interval arithmetic! Is it not easier to say: const physics::units::l_p plank( 2 ); // 2 * plank length std::cout << plank << std::endl; // output: 2.l_p rather than: const si::units::meters plank_length = 1.616051e-35 ± 1.03427e-39; const si::units::meters plank = 2 * plank_length; std::cout << plank << std::endl; // 3.2... +/- ... std::cout << ( plank / plank_length ) << std::endl; // 2.0 +/- ... Q: Would the last one give 2.0 +/- 2.0?! I don't know that much about interval arithmetic. Another thought: if you are loading/saving data to/from a database that keeps say the fundamental particle masses as eV, will these not degrade over time due to rounding errors when converting to/from SI units? What happens as the value of the eV changes as physical constants do?! What happens with the interval value that you need to convert back to a float? Do you take the average, where you *will* have greater value precision degredation!! Using eV as a base unit for these calculations will ease most of these and lessen others. The disadvantage to your idea of doing value / unit_desired when you need to output it is that: (1) it complicates matters -- doing that should only be required when conversions are needed (making the places where those conversions are explicit); (2) people are lazy and can get distracted, so they will not always use the above where needed; (3) it will have greater runtime penalties, especially if used in a loop; (4) can have inacuracies when dealing with large or small physical constant-based values; (5) is bad if those constants are changing! (6) can penalize you if intervals come into play. - Reece _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

On Wed, Jun 07, 2006 at 10:04:20PM +0100, Reece Dunn wrote:
No. Because I would either not define operator<< for a dimensional quantity OR have it output the unit together with the value. Then it should be obvious as soon as you see your program's output for the first time: You need 0.815 lbs pounds of flour
so, which value is correct? The one in Joules (sp?) or the one in
Well, both are probably correct. :) Now I'm not a theoretical physicist, but I'm pretty sure that even there all but the most trivial calculations become cleaner once you use SI units. Seems as if I'd want to mildly encourage even those folks to use SI. As to your rounding error concerns, I can reassure you, multiplication and division is very well-behaved in floating point.
(3) it will have greater runtime penalties, especially if used in a loop; I fail to see this.
(6) can penalize you if intervals come into play. I fail to see this, too.
Regards -Gerhard -- Gerhard Wesp ZRH office voice: +41 (0)44 668 1878 ZRH office fax: +41 (0)44 200 1818 For the rest I claim that raw pointers must be abolished.

Gerhard Wesp wrote:
Not attempting to sound snooty, but I am a theoretial physicist (astrophysics and cosmology, to be complete) and you are incorrect in thinking that SI units make everything simpler. The whole point of any of the specialized unit systems is to reduce complexity. If I want to talk about the energy of a fast moving sub-atomic particle using SI units, I have to carry around multiplicative factors that hold the scales of the speed of light, the strength of the electromagnetic interactions and the mass of the particle, among other things. If I use eV based unts instead, some of these constants become 1, and so I never need to remember to write them, and I never have to pay clock ticks in the calculation to compute them. In the inner loops of intense calculations, losing those extra multiplications can make hours or days of difference in how long the calculation takes to complete. So, the code becomes both less likely to contain errors and faster by using non-SI units. For research simulations, a restriction to SI only is a game breaker for the library. Also, moving to a well chosen set of non-SI units can frequently reduce the chance of round-off errors and make a calculation more stable. In some cases, it can even change a calculation from floating point to integer, and so remove all round off concerns. To go with that, most human beings are far more likely to be able to interpret numbers in the range of about 0.01 to 100 instead of numbers far away from one. I could calculate the age of the universe in seconds (the SI unit of time), but it is far more menaingful to most people when reported as ~14Gyr. (To get seconds from that, multiply by ~3.15*10^7.)
Very few physical constants are actually constant. First, most physical constants are measured values, so as our ability to measure them improves, the accepted value changes. In some cases, these changes are frequent enough and important enough that a system without the ability to accomidate them is not useful. Second, and less intuitive, some physical constants change based on the environment in which they are measured. For example, the strength of the electromagnetic interaction is not actually constant, though in your day to day life you never see it change. It depends on the energies of the interacting particles. If you leave this out of a particle physics calculation, you will be very wrong. The gravitational constant is also expected to have an energy dependence (though it is harder to measure), by the way.
For me, coming from my background, forcing SI units is a very bad idea. I understand that many people can work their entire careers and never run into any of these problems, but they are every day things for me, so I would like to see a design that supports what I need to do. John Phillips

On Thu, Jun 08, 2006 at 06:04:17PM -0400, John Phillips wrote:
(astrophysics and cosmology, to be complete) and you are incorrect in thinking that SI units make everything simpler. The whole point of any
Point taken. I've been known to change my mind in the past. I guess I'll have to check up on high energy physics before I make further comments :). I still think that *numerically* the unit system cannot make much of a difference (but feel free to convince me otherwise here as well), but I can see that having the speed of light at 1 might simplify matters. Regards -Gerhard -- Gerhard Wesp ZRH office voice: +41 (0)44 668 1878 ZRH office fax: +41 (0)44 200 1818 For the rest I claim that raw pointers must be abolished.
participants (4)
-
Gerhard Wesp
-
John Phillips
-
Oleg Abrosimov
-
Reece Dunn