comp.lang.ada
 help / color / mirror / Atom feed
* WG: SI Units - has Ada missed the boat?
@ 2007-07-09  8:55 Grein, Christoph (Fa. ESG)
  2007-07-09  9:49 ` Dmitry A. Kazakov
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Grein, Christoph (Fa. ESG) @ 2007-07-09  8:55 UTC (permalink / raw)
  To: comp.lang.ada

> One of my pet hopes for Ada2005 was that it would include some method
> of automatically checking systems of units at compilation time or with
> minimal run-time checking. Alas it was voted down due to time

I have to admit that I was the main perpetrator who killed that
proposal.

> Is anyone still working on an Ada solution to this?

I don't think so, if you mean a method to include in the Ada standard.

But there are a lot of such methods distributed in some home pages, see
Dmitry Kazakov, mine, ... (I guess there are plenty others)

I don't know C++ and so I do not know how it deals mit rad, Newton
Meters and Joule in

Work [Joule] = Torque [Newton*Meter] * Angle [rad]

Or sin x = x + x**3/3! + ... where x is in rad, sin x has dimension 1
(not rad).

Or Bq = 1/s, Hz = 1/s, but Bq /= Hz.


Eurocopter Deutschland GmbH
Sitz der Gesellschaft/Registered Office: Donauwoerth
Registergericht/Registration Court: Amtsgericht Augsburg HRB 16508
Vorsitzender des Aufsichtsrates/Chairman of the Supervisory Board: Dr. Lutz Bertling
Geschaeftsfuehrung/Board of Management:
Dr. Wolfgang Schoder, Vorsitzender/CEO; Friedrich-Wilhelm Hormel; Ralf Barnscheidt

CONFIDENTIALITY NOTICE 

This communication and the information it contains is intended for the addressee(s) named above and for no other persons or organizations. It is confidential and may be legally privileged and protected by law. The unauthorized use, copying or disclosure of this communication or any part of it is prohibited and may be unlawful. 
If you have received this communication in error, kindly notify us by return e-mail and discard and/or delete the communication. Thank you very much. 
It is possible for e-mails to be intercepted or affected by viruses. Whilst we maintain virus checks on our e-mails, we accept no liability for viruses or other material which might be introduced with this message. 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: WG: SI Units - has Ada missed the boat?
  2007-07-09  8:55 WG: SI Units - has Ada missed the boat? Grein, Christoph (Fa. ESG)
@ 2007-07-09  9:49 ` Dmitry A. Kazakov
  2007-07-10  1:26 ` Hyman Rosen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2007-07-09  9:49 UTC (permalink / raw)


On Mon, 09 Jul 2007 10:55:53 +0200, Grein, Christoph (Fa. ESG) wrote:

>> One of my pet hopes for Ada2005 was that it would include some method
>> of automatically checking systems of units at compilation time or with
>> minimal run-time checking. Alas it was voted down due to time
> 
> I have to admit that I was the main perpetrator who killed that
> proposal.

Fortunately. Be praised for that!

>> Is anyone still working on an Ada solution to this?
> 
> I don't think so, if you mean a method to include in the Ada standard.

Yes, and if we'd put together more or less obvious requirements of how an
Ada(tm) solution should look like, we would easily see a need in some
language changes. My strong impression is that these changes should go
beyond sole units support. For example, it is quite obvious that the unit
constraint should be put on the object, be it a floating-point number or a
matrix of. We just don't have any universally working mechanism for that.
Same with dimensioned literals, which would imply a user-defined literals
support, etc.

In short, units is just a use case, it should not be viewed as a language
feature.

> But there are a lot of such methods distributed in some home pages, see
> Dmitry Kazakov, mine, ... (I guess there are plenty others)

The new version of my measurement units for Ada with GTK tree view cell
renderers and combo boxes for dimensioned values is coming soon.

> I don't know C++ and so I do not know how it deals mit rad, Newton
> Meters and Joule in
> 
> Work [Joule] = Torque [Newton*Meter] * Angle [rad]
> 
> Or sin x = x + x**3/3! + ... where x is in rad, sin x has dimension 1
> (not rad).
>
> Or Bq = 1/s, Hz = 1/s, but Bq /= Hz.

Such differences should be handled outside the unit system. It cannot know
the semantics of the values. So rad = 1 SI. Or else m (of height) /= m (of
distance on a highway)

But how C++ handles (I guess it does not)

   X := Vector (I);  -- Both X and Vector are dimensioned

   Y : Unit := Ask_User_For;

   Z : Magnitude := 5 dB; -- May I have logarithmic scales?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: WG: SI Units - has Ada missed the boat?
  2007-07-09  8:55 WG: SI Units - has Ada missed the boat? Grein, Christoph (Fa. ESG)
  2007-07-09  9:49 ` Dmitry A. Kazakov
@ 2007-07-10  1:26 ` Hyman Rosen
  2007-07-10  9:14   ` Martin
  2007-07-10  9:22 ` Martin
  2007-07-12  1:27 ` none
  3 siblings, 1 reply; 8+ messages in thread
From: Hyman Rosen @ 2007-07-10  1:26 UTC (permalink / raw)


Grein, Christoph (Fa. ESG) wrote:
> I don't know C++ and so I do not know how it deals mit rad, Newton
> Meters and Joule in
> 
> Work [Joule] = Torque [Newton*Meter] * Angle [rad]
> 
> Or sin x = x + x**3/3! + ... where x is in rad, sin x has dimension 1
> (not rad).
> 
> Or Bq = 1/s, Hz = 1/s, but Bq /= Hz.

Here's a description of implementing units using the
Boost Metaprogramming Library.

<http://www.boost.org/libs/mpl/doc/tutorial/dimensional-analysis.html>

I expect that most C++ implementations will follow the rule that
90% of the way is enough, and not bother with radians or trying to
distinguish between becquerel and hertz or Fahrenheit, Celsius, and
Kelvin. But if someone wants to go the whole way, they can do it.
It's just a matter of writing more complicated combining rules for
the templates. And none of it has any runtime overhead at all -
objects of dimensioned types take no more space than plain numbers.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: WG: SI Units - has Ada missed the boat?
  2007-07-10  1:26 ` Hyman Rosen
@ 2007-07-10  9:14   ` Martin
  0 siblings, 0 replies; 8+ messages in thread
From: Martin @ 2007-07-10  9:14 UTC (permalink / raw)


On Jul 10, 2:26 am, Hyman Rosen <hyro...@mail.com> wrote:
[snip]
> I expect that most C++ implementations will follow the rule that
> 90% of the way is enough, and not bother with radians or trying to
> distinguish between becquerel and hertz or Fahrenheit, Celsius, and
> Kelvin. But if someone wants to go the whole way, they can do it.
> It's just a matter of writing more complicated combining rules for
> the templates. And none of it has any runtime overhead at all -
> objects of dimensioned types take no more space than plain numbers.

There's no runtime overhead when optimisation is switched on. Without
optimisation there is quite a bit of overhead. Or at least that's my
experience when using this library with VC++2005.

Cheers
-- Martin






^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: WG: SI Units - has Ada missed the boat?
  2007-07-09  8:55 WG: SI Units - has Ada missed the boat? Grein, Christoph (Fa. ESG)
  2007-07-09  9:49 ` Dmitry A. Kazakov
  2007-07-10  1:26 ` Hyman Rosen
@ 2007-07-10  9:22 ` Martin
  2007-07-12  1:27 ` none
  3 siblings, 0 replies; 8+ messages in thread
From: Martin @ 2007-07-10  9:22 UTC (permalink / raw)


On Jul 9, 9:55 am, "Grein, Christoph (Fa. ESG)"
<Christoph.Gr...@eurocopter.com> wrote:
> I have to admit that I was the main perpetrator who killed that
> proposal.

And I'm ok with that - it clearly wasn't going to be solved in time.
Shame though.


> I don't know C++ and so I do not know how it deals mit rad, Newton
> Meters and Joule in
>
> Work [Joule] = Torque [Newton*Meter] * Angle [rad]

Certainly Nm is covered. I've never seen a Nmrad before, so no idea!


> Or sin x = x + x**3/3! + ... where x is in rad, sin x has dimension 1
> (not rad).

Doubtful... This one seems like a real corner case and I'm not sure it
would be worth covering in any languages implementation. Seems like
we'd be letter "best" be the evil of "good enough" here.


> Or Bq = 1/s, Hz = 1/s, but Bq /= Hz.

Certainly the reference implementation has Bq and Hz defined
separately.


Cheers
-- Martin




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: WG: SI Units - has Ada missed the boat?
  2007-07-09  8:55 WG: SI Units - has Ada missed the boat? Grein, Christoph (Fa. ESG)
                   ` (2 preceding siblings ...)
  2007-07-10  9:22 ` Martin
@ 2007-07-12  1:27 ` none
  2007-07-12 10:39   ` Colin Paul Gloster
  2007-07-13 22:20   ` Dr. Adrian Wrigley
  3 siblings, 2 replies; 8+ messages in thread
From: none @ 2007-07-12  1:27 UTC (permalink / raw)


Grein, Christoph (Fa. ESG) wrote:
>>One of my pet hopes for Ada2005 was that it would include some method
>>of automatically checking systems of units at compilation time or with
>>minimal run-time checking. Alas it was voted down due to time
> 
> 
> I have to admit that I was the main perpetrator who killed that
> proposal.
> 
> 
>>Is anyone still working on an Ada solution to this?
> 
> 
> I don't think so, if you mean a method to include in the Ada standard.
> 

Back in the 80's I was working on a simulator, where we the software 
people wrote the infrastucture and the various subject area specialists 
wrote the code for the things they wanted to simulate.

We (software weenies) created a package (wish I could remember the name 
of it) that provided basic types LENGTH_UNITS, TIME_UNITS, SPEED_UNITS,
DISTANCE_UNITS, TEMPERATURE_UNITS, ANGLE_UNTIS, etc. and then defined 
all of the overloaded operators to convert between those.

The upshot of this was the convers stuff got so large and complec that 
we wrote a program that would read a text file that would define the 
conversions i.e. LENGTH_UNITS = SPEED_UNITS * TIME_UNITS... etc, the 
program then was able to define the base conversion and the related 
conversions ( SPEED_UNITS = LENGTH_UNITS / TIME_UNITS ), etc.
  I don't remember the details but there was also a way to define the 
conversion from various units into the generic _UNITS. For instance for 
LENGTH_UNITS, METERS would = 1, feet would be whatever the conversion 
from feet to meters is, furlongs would be defined similarly.

This program would then write the ADA specs and bodies for the conversion.


Down side :

This was in 1986ish. The "UNITS" package took about 4 hours to compile 
(on a VAX using VAX ADA) and every component took a long time to compile 
because every expression had to be compared to the myriad of overloads 
to determine if the expression was valid.
If a conversion didn't exist, you added the appropriate info to the 
conversion file (and hope you did it right), checked it back into CM, 
and the build ran overnight. The next morning you could compile your 
expression.

Up side :
We NEVER had unit conversion issues, as the unit analysis was done by 
the compiler.

This enabled the subject matter experts to write code that
defined a value of type say mytime : TIME_UNITS, and myspeed : 
SPEED_UNITS, mydistance : LENGTH_UNITS (sorry rusty ADA syntax) and then
mytime  := FROM_FOTNIGHTS ( 10.0 ) ;
myspeed := FROM_METERS_PER_SECOND ( 100.0 ) ;
mydistance = myspeed * mytime ;

PRINTLN ( TO_FURLONGS ( mydistance ) ) ;

and
myint : INTEGER ;

myint = 10 ;
mydistance = myspeed * myint ; would not compile.

You can see why the conversion package got so big... it had to defein 
ALL valid conversions.

Sorry this was so long. Wish I could remember more of the details
It was one of the most fun ADA jobs I worked on.

Joe Simon
WB2JQT









^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: WG: SI Units - has Ada missed the boat?
  2007-07-12  1:27 ` none
@ 2007-07-12 10:39   ` Colin Paul Gloster
  2007-07-13 22:20   ` Dr. Adrian Wrigley
  1 sibling, 0 replies; 8+ messages in thread
From: Colin Paul Gloster @ 2007-07-12 10:39 UTC (permalink / raw)


In news:46958287$0$8946$4c368faf@roadrunner.com timestamped Wed, 11
Jul 2007 21:27:30 -0400, none <""knoppix\"@(none)"> posted:
|--------------------------------------------------------------------------|
|"[..]                                                                     |
|                                                                          |
|We (software weenies) created a package (wish I could remember the name   |
|of it) that provided basic types LENGTH_UNITS, TIME_UNITS, SPEED_UNITS,   |
|DISTANCE_UNITS, TEMPERATURE_UNITS, ANGLE_UNTIS, etc. and then defined     |
|all of the overloaded operators to convert between those.                 |
|                                                                          |
|[..]                                                                      |
|                                                                          |
|Up side :                                                                 |
|We NEVER had unit conversion issues, as the unit analysis was done by     |
|the compiler.                                                             |
|                                                                          |
|[..]                                                                      |
|mydistance = myspeed * myint ; would not compile.                         |
|                                                                          |
|You can see why the conversion package got so big... it had to defein     |
|ALL valid conversions.                                                    |
|                                                                          |
|Sorry this was so long. Wish I could remember more of the details         |
|It was one of the most fun ADA jobs I worked on.                          |
|                                                                          |
|Joe Simon                                                                 |
|WB2JQT"                                                                   |
|--------------------------------------------------------------------------|

Thank you Joe Simon, that newsgroup post was inspiring.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: WG: SI Units - has Ada missed the boat?
  2007-07-12  1:27 ` none
  2007-07-12 10:39   ` Colin Paul Gloster
@ 2007-07-13 22:20   ` Dr. Adrian Wrigley
  1 sibling, 0 replies; 8+ messages in thread
From: Dr. Adrian Wrigley @ 2007-07-13 22:20 UTC (permalink / raw)


On Wed, 11 Jul 2007 21:27:30 -0400, none wrote:

<stuff deleted>

> You can see why the conversion package got so big... it had to defein 
> ALL valid conversions.

Interesting.

I tried out something similar a while back, and the method was to
add the overloaded functions only when they were needed.  I found that
there were rather few overloaded functions needed in practise.  This is
because expressions tend to be rather stereotypical - exotic combinations
of dimensional expressions never arise.  I think my solution used generic
instantiations, in the end, cutting the amount of source.

An interesting project which does include full units and dimensions
support is Sun's Fortress:

http://research.sun.com/projects/plrg/Fortress/overview.html

This is very ambitious and complete in scope - at least for
parallel, concurrent scientific codes.

What do people here think of their efforts?  I don't see Ada
mentioned in their white papers, even although there's a lot
of overlap in requirements.

One interesting feature of Fortress is that "for" loops
execute in any order (or none), by default.  This gives the
very fine grain parallelism opportunities I was talking about
here a while a go.

I think any general purpose language should come with proper
physical types - I'm surprised that it's normally left out.
(VHDL was the first language I used which had them)

As regards Ada and units/dimensions, I think the way forward
for most users is to put the units/physical types into a package
and add overloadings by hand when needed.  More intensive use
warrants the use of generic packages.  It's easy and the incremental
effort is low.

If you want a comprehensive approach, write an Ada preprocessor
to extend the language with a new syntax for dimensional types.
Use something like ASIS as a front end, and spit out standard Ada.
One way would be to check dimensional consistency and then generate
the necessary package(s) with the particular types and functions needed,
adding "with" clauses where necessary.
--
Dr. Adrian Wrigley, Cambridge, UK.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-07-13 22:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-09  8:55 WG: SI Units - has Ada missed the boat? Grein, Christoph (Fa. ESG)
2007-07-09  9:49 ` Dmitry A. Kazakov
2007-07-10  1:26 ` Hyman Rosen
2007-07-10  9:14   ` Martin
2007-07-10  9:22 ` Martin
2007-07-12  1:27 ` none
2007-07-12 10:39   ` Colin Paul Gloster
2007-07-13 22:20   ` Dr. Adrian Wrigley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox